Skip to content

Commit

Permalink
Change OpenTTD#9115: [NewGRF] Errors with severity ERROR give a pop-u…
Browse files Browse the repository at this point in the history
…p window now.

Fixed issue OpenTTD#9115 by also creating an error pop-up for errors with the severity ERROR, instead of just FATAL. Also added a string for it, STR_NEWGRF_ERROR_POPUP, which is the string STR_NEWGRF_ERROR_FATAL_POPUP, but without the word "fatal". This makes ERROR functionally distinct from WARNING.
  • Loading branch information
EratoNysiad committed Apr 27, 2021
1 parent 8ea0612 commit ff5be1d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 44 deletions.
1 change: 1 addition & 0 deletions src/lang/english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3079,6 +3079,7 @@ STR_NEWGRF_ERROR_MSG_WARNING :{RED}Warning: {
STR_NEWGRF_ERROR_MSG_ERROR :{RED}Error: {SILVER}{RAW_STRING}
STR_NEWGRF_ERROR_MSG_FATAL :{RED}Fatal: {SILVER}{RAW_STRING}
STR_NEWGRF_ERROR_FATAL_POPUP :{WHITE}A fatal NewGRF error has occurred: {}{STRING5}
STR_NEWGRF_ERROR_POPUP :{WHITE}A NewGRF error has occurred: {}{STRING5}
STR_NEWGRF_ERROR_VERSION_NUMBER :{1:RAW_STRING} will not work with the TTDPatch version reported by OpenTTD
STR_NEWGRF_ERROR_DOS_OR_WINDOWS :{1:RAW_STRING} is for the {RAW_STRING} version of TTD
STR_NEWGRF_ERROR_UNSET_SWITCH :{1:RAW_STRING} is designed to be used with {RAW_STRING}
Expand Down
100 changes: 56 additions & 44 deletions src/newgrf_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -612,7 +616,6 @@ 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;
Expand Down Expand Up @@ -655,7 +658,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
this->avails.SetFilterFuncs(this->filter_funcs);
this->avails.ForceRebuild();

this->OnInvalidateData(GOID_NEWGRF_CURRENT_LOADED);
this->OnInvalidateData(GOID_NEWGRF_LIST_EDITED);
}

~NewGRFWindow()
Expand All @@ -664,7 +667,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
DeleteWindowByClass(WC_TEXTFILE);
DeleteWindowByClass(WC_SAVE_PRESET);

if (this->editable && this->modified && !this->execute && !_exit_game) {
if (this->editable && !this->execute) {
CopyGRFConfigList(this->orig_list, this->actives, true);
ResetGRFConfig(false);
ReloadNewGRFData();
Expand Down Expand Up @@ -971,7 +974,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
}
this->vscroll->ScrollTowards(pos);
this->preset = -1;
this->InvalidateData(GOID_NEWGRF_LIST_EDITED);
this->InvalidateData();
break;
}

Expand All @@ -990,7 +993,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
}
this->vscroll->ScrollTowards(pos);
this->preset = -1;
this->InvalidateData(GOID_NEWGRF_LIST_EDITED);
this->InvalidateData();
break;
}

Expand Down Expand Up @@ -1096,7 +1099,6 @@ 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;
Expand All @@ -1106,15 +1108,13 @@ 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;
}

case WID_NS_TOGGLE_PALETTE:
if (this->active_sel != nullptr && this->editable) {
this->active_sel->palette ^= GRFP_USE_MASK;
this->SetDirty();
this->InvalidateData(GOID_NEWGRF_CHANGES_MADE);
}
break;

Expand All @@ -1131,7 +1131,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {

case WID_NS_RESCAN_FILES:
case WID_NS_RESCAN_FILES2:
RequestNewGRFScan(this);
ScanNewGRFFiles(this);
break;
}
}
Expand Down Expand Up @@ -1161,7 +1161,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
DeleteWindowByClass(WC_GRF_PARAMETERS);
DeleteWindowByClass(WC_TEXTFILE);
this->active_sel = nullptr;
this->InvalidateData(GOID_NEWGRF_CHANGES_MADE);
this->InvalidateData(GOID_NEWGRF_PRESET_LOADED);
}

void OnQueryTextFinished(char *str) override
Expand All @@ -1182,20 +1182,6 @@ 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
Expand Down Expand Up @@ -1230,34 +1216,27 @@ 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_CHANGES_MADE:
UpdateScrollBars();

/* Changes have been made to the list of active NewGRFs */
this->modified = true;
case GOID_NEWGRF_PRESET_LOADED: {
/* Update scrollbars */
int i = 0;
for (const GRFConfig *c = this->actives; c != nullptr; c = c->next, i++) {}

break;
this->vscroll->SetCount(i + 1); // Reserve empty space for drag and drop handling.

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;
if (this->avail_pos >= 0) this->vscroll2->ScrollTowards(this->avail_pos);
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
);
Expand Down Expand Up @@ -1318,8 +1297,42 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
{
if (!this->editable) return ES_NOT_HANDLED;

if (this->vscroll2->UpdateListPositionOnKeyPress(this->avail_pos, keycode) == ES_NOT_HANDLED) return ES_NOT_HANDLED;
switch (keycode) {
case WKC_UP:
/* scroll up by one */
if (this->avail_pos > 0) this->avail_pos--;
break;

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);
Expand Down Expand Up @@ -1964,7 +1977,6 @@ 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();

Expand Down

0 comments on commit ff5be1d

Please sign in to comment.