Merge branch upstream/master

This commit is contained in:
Sergii Pylypenko
2021-11-28 03:16:36 +02:00
326 changed files with 9186 additions and 8099 deletions

View File

@@ -47,8 +47,8 @@ void ShowNewGRFError()
if (_game_mode == GM_MENU) return;
for (const GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
/* We only want to show fatal errors */
if (c->error == nullptr || c->error->severity != STR_NEWGRF_ERROR_MSG_FATAL) continue;
/* Only show Fatal and Error level messages */
if (c->error == nullptr || (c->error->severity != STR_NEWGRF_ERROR_MSG_FATAL && c->error->severity != STR_NEWGRF_ERROR_MSG_ERROR)) continue;
SetDParam (0, c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING);
SetDParamStr(1, c->error->custom_message.c_str());
@@ -57,7 +57,11 @@ void ShowNewGRFError()
for (uint i = 0; i < lengthof(c->error->param_value); i++) {
SetDParam(4 + i, c->error->param_value[i]);
}
ShowErrorMessage(STR_NEWGRF_ERROR_FATAL_POPUP, INVALID_STRING_ID, WL_CRITICAL);
if (c->error->severity == STR_NEWGRF_ERROR_MSG_FATAL) {
ShowErrorMessage(STR_NEWGRF_ERROR_FATAL_POPUP, INVALID_STRING_ID, WL_CRITICAL);
} else {
ShowErrorMessage(STR_NEWGRF_ERROR_POPUP, INVALID_STRING_ID, WL_ERROR);
}
break;
}
}
@@ -612,6 +616,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
bool execute; ///< On pressing 'apply changes' are grf changes applied immediately, or only list is updated.
int preset; ///< Selected preset or \c -1 if none selected.
int active_over; ///< Active GRF item over which another one is dragged, \c -1 if none.
bool modified; ///< The list of active NewGRFs has been modified since the last time they got saved.
Scrollbar *vscroll;
Scrollbar *vscroll2;
@@ -653,7 +658,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
this->avails.SetFilterFuncs(this->filter_funcs);
this->avails.ForceRebuild();
this->OnInvalidateData(GOID_NEWGRF_LIST_EDITED);
this->OnInvalidateData(GOID_NEWGRF_CURRENT_LOADED);
}
~NewGRFWindow()
@@ -662,7 +667,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
DeleteWindowByClass(WC_TEXTFILE);
DeleteWindowByClass(WC_SAVE_PRESET);
if (this->editable && !this->execute && !_exit_game) {
if (this->editable && this->modified && !this->execute && !_exit_game) {
CopyGRFConfigList(this->orig_list, this->actives, true);
ResetGRFConfig(false);
ReloadNewGRFData();
@@ -973,7 +978,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
}
this->vscroll->ScrollTowards(pos);
this->preset = -1;
this->InvalidateData();
this->InvalidateData(GOID_NEWGRF_LIST_EDITED);
break;
}
@@ -992,7 +997,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
}
this->vscroll->ScrollTowards(pos);
this->preset = -1;
this->InvalidateData();
this->InvalidateData(GOID_NEWGRF_LIST_EDITED);
break;
}
@@ -1098,6 +1103,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
CopyGRFConfigList(this->orig_list, this->actives, true);
ResetGRFConfig(false);
ReloadNewGRFData();
this->InvalidateData(GOID_NEWGRF_CHANGES_APPLIED);
}
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
break;
@@ -1107,6 +1113,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
if (this->active_sel == nullptr || !this->show_params || this->active_sel->num_valid_params == 0) break;
OpenGRFParameterWindow(this->active_sel, this->editable);
this->InvalidateData(GOID_NEWGRF_CHANGES_MADE);
break;
}
@@ -1114,6 +1121,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
if (this->active_sel != nullptr && this->editable) {
this->active_sel->palette ^= GRFP_USE_MASK;
this->SetDirty();
this->InvalidateData(GOID_NEWGRF_CHANGES_MADE);
}
break;
@@ -1160,7 +1168,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
DeleteWindowByClass(WC_GRF_PARAMETERS);
DeleteWindowByClass(WC_TEXTFILE);
this->active_sel = nullptr;
this->InvalidateData(GOID_NEWGRF_PRESET_LOADED);
this->InvalidateData(GOID_NEWGRF_CHANGES_MADE);
}
void OnQueryTextFinished(char *str) override
@@ -1181,6 +1189,20 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
this->InvalidateData();
}
/**
* Updates the scroll bars for the active and inactive NewGRF lists.
*/
void UpdateScrollBars()
{
/* Update scrollbars */
int i = 0;
for (const GRFConfig *c = this->actives; c != nullptr; c = c->next, i++) {}
this->vscroll->SetCount(i + 1); // Reserve empty space for drag and drop handling.
if (this->avail_pos >= 0) this->vscroll2->ScrollTowards(this->avail_pos);
}
/**
* Some data on this window has become invalid.
* @param data Information about the changed data. @see GameOptionsInvalidationData
@@ -1215,27 +1237,34 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
this->avails.ForceRebuild();
FALLTHROUGH;
case GOID_NEWGRF_CURRENT_LOADED:
this->modified = false;
UpdateScrollBars();
break;
case GOID_NEWGRF_LIST_EDITED:
this->preset = -1;
FALLTHROUGH;
case GOID_NEWGRF_PRESET_LOADED: {
/* Update scrollbars */
int i = 0;
for (const GRFConfig *c = this->actives; c != nullptr; c = c->next, i++) {}
case GOID_NEWGRF_CHANGES_MADE:
UpdateScrollBars();
this->vscroll->SetCount(i + 1); // Reserve empty space for drag and drop handling.
/* Changes have been made to the list of active NewGRFs */
this->modified = true;
if (this->avail_pos >= 0) this->vscroll2->ScrollTowards(this->avail_pos);
break;
}
case GOID_NEWGRF_CHANGES_APPLIED:
/* No changes have been made to the list of active NewGRFs since the last time the changes got applied */
this->modified = false;
break;
}
this->BuildAvailables();
this->SetWidgetDisabledState(WID_NS_APPLY_CHANGES, !((this->editable && this->modified) || _settings_client.gui.newgrf_developer_tools));
this->SetWidgetsDisabledState(!this->editable,
WID_NS_PRESET_LIST,
WID_NS_APPLY_CHANGES,
WID_NS_TOGGLE_PALETTE,
WIDGET_LIST_END
);
@@ -1296,42 +1325,8 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
{
if (!this->editable) return ES_NOT_HANDLED;
switch (keycode) {
case WKC_UP:
/* scroll up by one */
if (this->avail_pos > 0) this->avail_pos--;
break;
if (this->vscroll2->UpdateListPositionOnKeyPress(this->avail_pos, keycode) == ES_NOT_HANDLED) return ES_NOT_HANDLED;
case WKC_DOWN:
/* scroll down by one */
if (this->avail_pos < (int)this->avails.size() - 1) this->avail_pos++;
break;
case WKC_PAGEUP:
/* scroll up a page */
this->avail_pos = (this->avail_pos < this->vscroll2->GetCapacity()) ? 0 : this->avail_pos - this->vscroll2->GetCapacity();
break;
case WKC_PAGEDOWN:
/* scroll down a page */
this->avail_pos = std::min(this->avail_pos + this->vscroll2->GetCapacity(), (int)this->avails.size() - 1);
break;
case WKC_HOME:
/* jump to beginning */
this->avail_pos = 0;
break;
case WKC_END:
/* jump to end */
this->avail_pos = (uint)this->avails.size() - 1;
break;
default:
return ES_NOT_HANDLED;
}
if (this->avails.size() == 0) this->avail_pos = -1;
if (this->avail_pos >= 0) {
this->active_sel = nullptr;
DeleteWindowByClass(WC_GRF_PARAMETERS);
@@ -1974,10 +1969,11 @@ static void NewGRFConfirmationCallback(Window *w, bool confirmed)
for (c = nw->actives; c != nullptr && i > 0; c = c->next, i--) {}
nw->active_sel = c;
nw->avails.ForceRebuild();
nw->modified = false;
w->InvalidateData();
ReInitAllWindows();
ReInitAllWindows(false);
DeleteWindowByClass(WC_BUILD_OBJECT);
}
}