Changeset - r27957:daca5caf938b
[Not reviewed]
master
0 8 0
frosch - 9 months ago 2023-09-20 19:26:42
frosch@openttd.org
Codechange: Add enum items for dynmically created setting dropdowns.
8 files changed with 27 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/game/game_gui.cpp
Show inline comments
 
@@ -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
src/newgrf_gui.cpp
Show inline comments
 
@@ -395,7 +395,7 @@ struct NewGRFParametersWindow : public W
 
								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 W
 

	
 
	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 W
 

	
 
	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
src/script/script_gui.cpp
Show inline comments
 
@@ -472,7 +472,7 @@ struct ScriptSettingsWindow : public Win
 
								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 Win
 

	
 
	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
src/settings_gui.cpp
Show inline comments
 
@@ -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);
 

	
 
					SetSettingValue(sd, index);
 
					this->SetDirty();
 
				}
 
			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();
 
				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
src/widgets/game_widget.h
Show inline comments
 
@@ -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 */
src/widgets/newgrf_widget.h
Show inline comments
 
@@ -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. */
src/widgets/script_widget.h
Show inline comments
 
@@ -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. */
src/widgets/settings_widget.h
Show inline comments
 
@@ -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. */
0 comments (0 inline, 0 general)