Codechange: Add enum items for dynmically created setting dropdowns.

pull/615/head
frosch 8 months ago committed by frosch
parent 39e67b6f4c
commit f40816503f

@ -314,7 +314,7 @@ struct GSConfigWindow : public Window {
list.emplace_back(new DropDownListStringItem(config_item.labels.find(i)->second, i, false));
}
ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE);
ShowDropDownListAt(this, std::move(list), old_val, WID_GSC_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE);
}
}
} else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
@ -367,14 +367,14 @@ struct GSConfigWindow : public Window {
void OnDropdownSelect(int widget, int index) override
{
if (widget >= 0) return;
if (widget != WID_GSC_SETTING_DROPDOWN) return;
assert(this->clicked_dropdown);
SetValue(index);
}
void OnDropdownClose(Point, int widget, int, bool) override
{
if (widget >= 0) return;
if (widget != WID_GSC_SETTING_DROPDOWN) return;
/* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
* the same dropdown button was clicked again, and then not open the dropdown again.
* So, we only remember that it was closed, and process it on the next OnPaint, which is

@ -395,7 +395,7 @@ struct NewGRFParametersWindow : public Window {
list.emplace_back(new DropDownListStringItem(GetGRFStringFromGRFText(par_info.value_names.find(i)->second), i, false));
}
ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE);
ShowDropDownListAt(this, std::move(list), old_val, WID_NP_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE);
}
}
} else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
@ -453,7 +453,7 @@ struct NewGRFParametersWindow : public Window {
void OnDropdownSelect(int widget, int index) override
{
if (widget >= 0) return;
if (widget != WID_NP_SETTING_DROPDOWN) return;
assert(this->clicked_dropdown);
GRFParameterInfo &par_info = this->GetParameterInfo(this->clicked_row);
par_info.SetValue(this->grf_config, index);
@ -462,7 +462,7 @@ struct NewGRFParametersWindow : public Window {
void OnDropdownClose(Point, int widget, int, bool) override
{
if (widget >= 0) return;
if (widget != WID_NP_SETTING_DROPDOWN) return;
/* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
* the same dropdown button was clicked again, and then not open the dropdown again.
* So, we only remember that it was closed, and process it on the next OnPaint, which is

@ -472,7 +472,7 @@ struct ScriptSettingsWindow : public Window {
list.emplace_back(new DropDownListStringItem(config_item.labels.find(i)->second, i, false));
}
ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE);
ShowDropDownListAt(this, std::move(list), old_val, WID_SCRS_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE);
}
}
} else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
@ -526,14 +526,14 @@ struct ScriptSettingsWindow : public Window {
void OnDropdownSelect(int widget, int index) override
{
if (widget >= 0) return;
if (widget != WID_SCRS_SETTING_DROPDOWN) return;
assert(this->clicked_dropdown);
SetValue(index);
}
void OnDropdownClose(Point, int widget, int, bool) override
{
if (widget >= 0) return;
if (widget != WID_SCRS_SETTING_DROPDOWN) return;
/* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
* the same dropdown button was clicked again, and then not open the dropdown again.
* So, we only remember that it was closed, and process it on the next OnPaint, which is

@ -2394,7 +2394,7 @@ struct GameSettingsWindow : Window {
list.emplace_back(new DropDownListStringItem(sd->str_val + i - sd->min, i, false));
}
ShowDropDownListAt(this, std::move(list), value, -1, wi_rect, COLOUR_ORANGE);
ShowDropDownListAt(this, std::move(list), value, WID_GS_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE);
}
}
this->SetDirty();
@ -2526,23 +2526,21 @@ struct GameSettingsWindow : Window {
this->InvalidateData();
break;
default:
if (widget < 0) {
/* Deal with drop down boxes on the panel. */
assert(this->valuedropdown_entry != nullptr);
const IntSettingDesc *sd = this->valuedropdown_entry->setting;
assert(sd->flags & SF_GUI_DROPDOWN);
case WID_GS_SETTING_DROPDOWN:
/* Deal with drop down boxes on the panel. */
assert(this->valuedropdown_entry != nullptr);
const IntSettingDesc *sd = this->valuedropdown_entry->setting;
assert(sd->flags & SF_GUI_DROPDOWN);
SetSettingValue(sd, index);
this->SetDirty();
}
SetSettingValue(sd, index);
this->SetDirty();
break;
}
}
void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
{
if (widget >= 0) {
if (widget != WID_GS_SETTING_DROPDOWN) {
/* Normally the default implementation of OnDropdownClose() takes care of
* a few things. We want that behaviour here too, but only for
* "normal" dropdown boxes. The special dropdown boxes added for every

@ -23,6 +23,8 @@ enum GSConfigWidgets {
WID_GSC_CONTENT_DOWNLOAD = WID_GSC_TEXTFILE + TFT_CONTENT_END, ///< Download content button.
WID_GSC_ACCEPT, ///< Accept ("Close") button
WID_GSC_RESET, ///< Reset button.
WID_GSC_SETTING_DROPDOWN = -1, ///< Dynamically created dropdown for changing setting value.
};
#endif /* WIDGETS_GS_WIDGET_H */

@ -26,6 +26,8 @@ enum NewGRFParametersWidgets {
WID_NP_RESET, ///< Reset button.
WID_NP_SHOW_DESCRIPTION, ///< #NWID_SELECTION to optionally display parameter descriptions.
WID_NP_DESCRIPTION, ///< Multi-line description of a parameter.
WID_NP_SETTING_DROPDOWN = -1, ///< Dynamically created dropdown for changing setting value.
};
/** Widgets of the #NewGRFWindow class. */

@ -29,6 +29,8 @@ enum ScriptSettingsWidgets {
WID_SCRS_SCROLLBAR, ///< Scrollbar to scroll through all settings.
WID_SCRS_ACCEPT, ///< Accept button.
WID_SCRS_RESET, ///< Reset button.
WID_SCRS_SETTING_DROPDOWN = -1, ///< Dynamically created dropdown for changing setting value.
};
/** Widgets of the #ScriptDebugWindow class. */

@ -64,6 +64,8 @@ enum GameSettingsWidgets {
WID_GS_RESTRICT_TYPE, ///< Label upfront to the type drop-down box to restrict the list of settings to show
WID_GS_RESTRICT_DROPDOWN, ///< The drop down box to restrict the list of settings
WID_GS_TYPE_DROPDOWN, ///< The drop down box to choose client/game/company/all settings
WID_GS_SETTING_DROPDOWN = -1, ///< Dynamically created dropdown for changing setting value.
};
/** Widgets of the #CustomCurrencyWindow class. */

Loading…
Cancel
Save