OpenTTD Source 20260731-master-g77ba2b244a
game_gui.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "../stdafx.h"
11#include "../error.h"
12#include "../settings_gui.h"
13#include "../querystring_gui.h"
14#include "../window_func.h"
15#include "../network/network.h"
17#include "../dropdown_type.h"
18#include "../dropdown_func.h"
19#include "../timer/timer.h"
22
23#include "game.hpp"
24#include "game_gui.hpp"
25#include "game_config.hpp"
26#include "game_info.hpp"
28#include "../script_config.hpp"
29
31
32#include "table/strings.h"
33
34#include "../safeguards.h"
35
36
38static constexpr std::initializer_list<NWidgetPart> _nested_gs_config_widgets = {
41 NWidget(WWT_CAPTION, Colours::Mauve), SetStringTip(STR_AI_CONFIG_CAPTION_GAMESCRIPT, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
46 NWidget(WWT_FRAME, Colours::Mauve), SetStringTip(STR_AI_CONFIG_GAMESCRIPT), SetFill(1, 0), SetResize(1, 0),
47 NWidget(WWT_MATRIX, Colours::Mauve, WID_GSC_GSLIST), SetMinimalSize(288, 14), SetFill(1, 1), SetResize(1, 0), SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP),
49 NWidget(WWT_FRAME, Colours::Mauve), SetStringTip(STR_AI_CONFIG_GAMESCRIPT_PARAM), SetFill(1, 1), SetResize(1, 0), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
54 NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_RESET), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_AI_SETTINGS_RESET),
58 NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_CHANGE), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_AI_CONFIG_CHANGE_GAMESCRIPT, STR_AI_CONFIG_CHANGE_TOOLTIP),
59 NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_CONTENT_DOWNLOAD), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
63 NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
64 NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_TEXTFILE + TextfileType::Readme), SetFill(1, 1), SetResize(1, 0), SetMinimalSize(93, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
67 NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_TEXTFILE + TextfileType::Changelog), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
68 NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_TEXTFILE + TextfileType::License), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
74 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
78};
79
82 WindowPosition::Center, "settings_gs_config", 500, 350,
83 WindowClass::GameOptions, WindowClass::None,
84 {},
86);
87
91struct GSConfigWindow : public Window {
93 int line_height = 0;
94 int clicked_button = -1;
95 bool clicked_increase = false;
96 bool clicked_dropdown = false;
97 bool closing_dropdown = false;
98 int clicked_row = 0;
99 Scrollbar *vscroll = nullptr;
100 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
102
104 {
105 this->gs_config = GameConfig::GetConfig();
106
107 this->CreateNestedTree(); // Initializes 'this->line_height' as a side effect.
108 this->vscroll = this->GetScrollbar(WID_GSC_SCROLLBAR);
110 this->OnInvalidateData(0);
111
113 }
114
115 void Close([[maybe_unused]] int data = 0) override
116 {
117 CloseWindowByClass(WindowClass::ScriptList);
118 this->Window::Close();
119 }
120
127 {
128 this->visible_settings.clear();
129
130 for (const auto &item : *this->gs_config->GetConfigList()) {
131 bool no_hide = !item.flags.Test(ScriptConfigFlag::Developer);
132 if (no_hide || _settings_client.gui.ai_developer_tools) {
133 this->visible_settings.push_back(&item);
134 }
135 }
136
137 this->vscroll->SetCount(this->visible_settings.size());
138 }
139
140 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
141 {
142 switch (widget) {
143 case WID_GSC_SETTINGS:
144 this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FontSize::Normal)) + padding.height;
145 resize.width = 1;
146 fill.height = resize.height = this->line_height;
147 size.height = 5 * this->line_height;
148 break;
149
150 case WID_GSC_GSLIST:
151 this->line_height = GetCharacterHeight(FontSize::Normal) + padding.height;
152 size.height = 1 * this->line_height;
153 break;
154 }
155 }
156
161 static bool IsEditable()
162 {
163 return _game_mode != GameMode::Normal || Game::GetInstance() != nullptr;
164 }
165
170 std::string GetText() const
171 {
172 if (const GameInfo *info = GameConfig::GetConfig()->GetInfo(); info != nullptr) return info->GetName();
173 return GetString(STR_AI_CONFIG_NONE);
174 }
175
176 void DrawWidget(const Rect &r, WidgetID widget) const override
177 {
178 switch (widget) {
179 case WID_GSC_GSLIST: {
180 /* There is only one slot, unlike with the GS GUI, so it should never be white */
182 break;
183 }
184 case WID_GSC_SETTINGS: {
185 Rect ir = r.Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero);
186 bool rtl = _current_text_dir == TD_RTL;
187 Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
189
190 int y = r.top;
191 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
192 int text_y_offset = (this->line_height - GetCharacterHeight(FontSize::Normal)) / 2;
193
194 const auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->visible_settings);
195 for (auto it = first; it != last; ++it) {
196 const ScriptConfigItem &config_item = **it;
197 int current_value = this->gs_config->GetSetting(config_item.name);
198 bool editable = this->IsEditableItem(config_item);
199
200 if (config_item.flags.Test(ScriptConfigFlag::Boolean)) {
201 DrawBoolButton(br.left, y + button_y_offset, Colours::Yellow, Colours::Mauve, current_value != 0, editable);
202 } else {
203 int i = static_cast<int>(std::distance(std::begin(this->visible_settings), it));
204 if (config_item.complete_labels) {
205 DrawDropDownButton(br.left, y + button_y_offset, Colours::Yellow, this->clicked_row == i && this->clicked_dropdown, editable);
206 } else {
207 DrawArrowButtons(br.left, y + button_y_offset, Colours::Yellow, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
208 }
209 }
210
211 DrawString(tr.left, tr.right, y + text_y_offset, config_item.GetString(current_value), config_item.GetColour());
212 y += this->line_height;
213 }
214 break;
215 }
216 }
217 }
218
219 void OnPaint() override
220 {
221 if (this->closing_dropdown) {
222 this->closing_dropdown = false;
223 this->clicked_dropdown = false;
224 }
225 this->DrawWidgets();
226 }
227
228 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
229 {
230 if (widget >= WID_GSC_TEXTFILE && widget < WID_GSC_TEXTFILE + TextfileType::ContentEnd) {
231 if (GameConfig::GetConfig() == nullptr) return;
232
234 return;
235 }
236
237 switch (widget) {
238 case WID_GSC_GSLIST: {
239 this->InvalidateData();
240 if (click_count > 1 && _game_mode != GameMode::Normal) ShowScriptListWindow(OWNER_DEITY, _ctrl_pressed);
241 break;
242 }
243
244 case WID_GSC_CHANGE: // choose other Game Script
246 break;
247
249 if (!_network_available) {
250 ShowErrorMessage(GetEncodedString(STR_NETWORK_ERROR_NOTAVAILABLE), {}, WarningLevel::Error);
251 } else {
253 }
254 break;
255
256 case WID_GSC_SETTINGS: {
257 auto it = this->vscroll->GetScrolledItemFromWidget(this->visible_settings, pt.y, this, widget);
258 if (it == this->visible_settings.end()) break;
259
260 const ScriptConfigItem &config_item = **it;
261 if (!this->IsEditableItem(config_item)) return;
262
263 int num = it - this->visible_settings.begin();
264 if (this->clicked_row != num) {
265 this->CloseChildWindows(WindowClass::QueryString);
266 this->CloseChildWindows(WindowClass::DropdownMenu);
267 this->clicked_row = num;
268 this->clicked_dropdown = false;
269 }
270
271 bool bool_item = config_item.flags.Test(ScriptConfigFlag::Boolean);
272
273 Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero);
274 int x = pt.x - r.left;
275 if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;
276
277 /* One of the arrows is clicked (or green/red rect in case of bool value) */
278 int old_val = this->gs_config->GetSetting(config_item.name);
279 if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
280 if (this->clicked_dropdown) {
281 /* unclick the dropdown */
282 this->CloseChildWindows(WindowClass::DropdownMenu);
283 this->clicked_dropdown = false;
284 this->closing_dropdown = false;
285 } else {
286 int rel_y = (pt.y - r.top) % this->line_height;
287
288 Rect wi_rect;
289 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
290 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
291 wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
292 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
293
294 /* If the mouse is still held but dragged outside of the dropdown list, keep the dropdown open */
295 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
296 this->clicked_dropdown = true;
297 this->closing_dropdown = false;
298
299 DropDownList list;
300 for (int i = config_item.min_value; i <= config_item.max_value; i++) {
301 list.push_back(MakeDropDownListStringItem(GetString(STR_JUST_RAW_STRING, config_item.labels.find(i)->second), i));
302 }
303
304 ShowDropDownListAt(this, std::move(list), old_val, WID_GSC_SETTING_DROPDOWN, wi_rect, Colours::Orange);
305 }
306 }
307 } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
308 int new_val = old_val;
309 if (bool_item) {
310 new_val = !new_val;
311 } else if (x >= SETTING_BUTTON_WIDTH / 2) {
312 /* Increase button clicked */
313 new_val += config_item.step_size;
314 if (new_val > config_item.max_value) new_val = config_item.max_value;
315 this->clicked_increase = true;
316 } else {
317 /* Decrease button clicked */
318 new_val -= config_item.step_size;
319 if (new_val < config_item.min_value) new_val = config_item.min_value;
320 this->clicked_increase = false;
321 }
322
323 if (new_val != old_val) {
324 this->gs_config->SetSetting(config_item.name, new_val);
325 this->clicked_button = num;
326 this->unclick_timeout.Reset();
327 }
328 } else if (!bool_item && !config_item.complete_labels) {
329 /* Display a query box so users can enter a custom value. */
330 ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, {});
331 }
332 this->SetDirty();
333 break;
334 }
335
336 case WID_GSC_OPEN_URL: {
337 const GameConfig *config = GameConfig::GetConfig();
338 if (config == nullptr || config->GetInfo() == nullptr) return;
339 OpenBrowser(config->GetInfo()->GetURL());
340 break;
341 }
342
343 case WID_GSC_RESET:
344 this->gs_config->ResetEditableSettings(_game_mode == GameMode::Menu);
345 this->SetDirty();
346 break;
347 }
348 }
349
350 void OnQueryTextFinished(std::optional<std::string> str) override
351 {
352 if (!str.has_value()) return;
353 auto value = ParseInteger<int32_t>(*str, 10, true);
354 if (!value.has_value()) return;
355 this->SetValue(*value);
356 }
357
358 void OnDropdownSelect(WidgetID widget, int index, int) override
359 {
360 if (widget != WID_GSC_SETTING_DROPDOWN) return;
361 assert(this->clicked_dropdown);
362 this->SetValue(index);
363 }
364
365 void OnDropdownClose(Point, WidgetID widget, int, int, bool) override
366 {
367 if (widget != WID_GSC_SETTING_DROPDOWN) return;
368 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
369 * the same dropdown button was clicked again, and then not open the dropdown again.
370 * So, we only remember that it was closed, and process it on the next OnPaint, which is
371 * after OnClick. */
372 assert(this->clicked_dropdown);
373 this->closing_dropdown = true;
374 this->SetDirty();
375 }
376
377 void OnResize() override
378 {
379 this->vscroll->SetCapacityFromWidget(this, WID_GSC_SETTINGS);
380 }
381
383 TimeoutTimer<TimerWindow> unclick_timeout = {std::chrono::milliseconds(150), [this]() {
384 this->clicked_button = -1;
385 this->SetDirty();
386 }};
387
393 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
394 {
395 if (!gui_scope) return;
396
398
399 const GameConfig *config = GameConfig::GetConfig();
400 this->SetWidgetDisabledState(WID_GSC_OPEN_URL, config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty());
402 this->SetWidgetDisabledState(WID_GSC_TEXTFILE + tft, !config->GetTextfile(tft, OWNER_DEITY).has_value());
403 }
405 this->CloseChildWindows(WindowClass::DropdownMenu);
406 this->CloseChildWindows(WindowClass::QueryString);
407 }
408private:
409 bool IsEditableItem(const ScriptConfigItem &config_item) const
410 {
411 return _game_mode == GameMode::Menu
412 || _game_mode == GameMode::Editor
413 || config_item.flags.Test(ScriptConfigFlag::InGame)
414 || _settings_client.gui.ai_developer_tools;
415 }
416
417 void SetValue(int value)
418 {
419 const ScriptConfigItem &config_item = *this->visible_settings[this->clicked_row];
420 if (_game_mode == GameMode::Normal && !config_item.flags.Test(ScriptConfigFlag::InGame)) return;
421 this->gs_config->SetSetting(config_item.name, value);
422 this->SetDirty();
423 }
424};
425
428{
429 CloseWindowByClass(WindowClass::GameOptions);
430 new GSConfigWindow();
431}
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Iterate a range of enum values.
Game script instantion of script configuration.
class GameInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
static GameConfig * GetConfig(ScriptSettingSource source=ScriptSettingSource::Default)
Get the script configuration.
All static information from an Game like name, version, etc.
Definition game_info.hpp:16
static class GameInstance * GetInstance()
Get the current active instance.
Definition game.hpp:108
Script settings.
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
void SetSetting(std::string_view name, int value)
Set the value of a setting for this config.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
int GetSetting(const std::string &name) const
Get the value of a setting for this config.
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
const std::string & GetURL() const
Get the website for this script.
Scrollbar data structure.
void SetCount(size_t num)
Sets the number of elements in the list.
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2548
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
A timeout timer will fire once after the interval.
Definition timer.h:116
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:95
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Definition dropdown.cpp:570
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Functions related to errors.
@ Error
Errors (eg. saving/loading failed).
Definition error.h:26
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Base functions for all Games.
GameConfig stores the configuration settings of every Game.
static constexpr std::initializer_list< NWidgetPart > _nested_gs_config_widgets
Widgets for the configure GS window.
Definition game_gui.cpp:38
void ShowGSConfigWindow()
Open the GS config window.
Definition game_gui.cpp:427
static WindowDesc _gs_config_desc(WindowPosition::Center, "settings_gs_config", 500, 350, WindowClass::GameOptions, WindowClass::None, {}, _nested_gs_config_widgets)
Window definition for the configure GS window.
Window for configuring GS.
GameInfo keeps track of all information of an Game, like Author, Description, ...
Types related to the GS widgets.
@ WID_GSC_GSLIST
List with current selected Game Script.
Definition game_widget.h:18
@ WID_GSC_SETTING_DROPDOWN
Dynamically created dropdown for changing setting value.
Definition game_widget.h:27
@ WID_GSC_SETTINGS
Panel to draw the Game Script settings on.
Definition game_widget.h:19
@ WID_GSC_CONTENT_DOWNLOAD
Download content button.
Definition game_widget.h:24
@ WID_GSC_OPEN_URL
Open GS URL.
Definition game_widget.h:22
@ WID_GSC_SCROLLBAR
Scrollbar to scroll through the selected AIs.
Definition game_widget.h:20
@ WID_GSC_CHANGE
Select another Game Script button.
Definition game_widget.h:21
@ WID_GSC_BACKGROUND
Window background.
Definition game_widget.h:17
@ WID_GSC_TEXTFILE
Open GS readme, changelog (+1) or license (+2).
Definition game_widget.h:23
@ WID_GSC_RESET
Reset button.
Definition game_widget.h:25
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:39
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:668
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ Mauve
Mauve.
Definition gfx_type.h:295
@ Yellow
Yellow.
Definition gfx_type.h:288
@ Orange
Orange.
Definition gfx_type.h:297
@ Orange
Orange colour.
Definition gfx_type.h:324
@ Silver
Silver colour.
Definition gfx_type.h:319
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetResizeWidgetTypeTip(ResizeWidgetType widget_type, StringID tip)
Widget part function for setting the resize widget type and tooltip.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:975
#define Point
Macro that prevents name conflicts between included headers.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
bool _network_available
is network mode available?
Definition network.cpp:69
Basic functions/variables used all over the place.
Part of the network protocol handling content distribution.
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=ContentType::End, ContentType type2=ContentType::End)
Show the content list window with a given set of content.
@ Editor
In the scenario editor.
Definition openttd.h:21
@ Normal
Playing a game.
Definition openttd.h:20
@ Menu
In the main menu.
Definition openttd.h:19
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
static const int INT32_DIGITS_WITH_SIGN_AND_TERMINATION
Maximum of 10 digits for MIN / MAX_INT32, 1 for the sign and 1 for '\0'.
@ Boolean
This value is a boolean (either 0 (false) or 1 (true) ).
@ Developer
This setting will only be visible when the Script development tools are active.
@ InGame
This setting can be changed while the Script is running.
void ShowScriptTextfileWindow(Window *parent, TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
void ShowScriptListWindow(CompanyID slot, bool show_all)
Open the Script list window to chose a script for the given company slot.
Window for configuring the scripts.
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
Draw a toggle button.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Functions for setting GUIs.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition of base types and functions in a cross-platform compatible way.
Parse strings.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
Definition string_type.h:28
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
@ TD_RTL
Text is written right-to-left by default.
Dimensions (a width and height) of a rectangle in 2D.
Window to configure which GSs will start.
Definition game_gui.cpp:91
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition game_gui.cpp:393
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition game_gui.cpp:115
void OnResize() override
Called after the window got resized.
Definition game_gui.cpp:377
void OnPaint() override
The window must be repainted.
Definition game_gui.cpp:219
VisibleSettingsList visible_settings
List of visible GS settings.
Definition game_gui.cpp:101
bool closing_dropdown
True, if the dropdown list is currently closing.
Definition game_gui.cpp:97
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
Definition game_gui.cpp:358
std::vector< const ScriptConfigItem * > VisibleSettingsList
typedef for a vector of script settings
Definition game_gui.cpp:100
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Definition game_gui.cpp:350
int line_height
Height of a single GS-name line.
Definition game_gui.cpp:93
void OnDropdownClose(Point, WidgetID widget, int, int, bool) override
A dropdown window associated to this window has been closed.
Definition game_gui.cpp:365
int clicked_button
The button we clicked.
Definition game_gui.cpp:94
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
Definition game_gui.cpp:126
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition game_gui.cpp:99
ScriptConfig * gs_config
The configuration we're modifying.
Definition game_gui.cpp:92
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
Definition game_gui.cpp:383
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition game_gui.cpp:140
bool clicked_increase
Whether we clicked the increase or decrease button.
Definition game_gui.cpp:95
static bool IsEditable()
Can the GS config be edited?
Definition game_gui.cpp:161
int clicked_row
The clicked row of settings.
Definition game_gui.cpp:98
bool clicked_dropdown
Whether the dropdown is open.
Definition game_gui.cpp:96
std::string GetText() const
Get text to display for game script name.
Definition game_gui.cpp:170
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition game_gui.cpp:176
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition game_gui.cpp:228
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Info about a single Script setting.
ScriptConfigFlags flags
Flags for the configuration setting.
std::string GetString(int value) const
Get string to display this setting in the configuration interface.
LabelMapping labels
Text labels for the integer values.
std::string name
The name of the configuration setting.
int min_value
The minimal value this configuration setting can have.
int max_value
The maximal value this configuration setting can have.
int step_size
The step size in the gui.
bool complete_labels
True if all values have a label.
TextColour GetColour() const
Get text colour to display this setting in the configuration interface.
High level window description.
Definition window_gui.h:172
Data structure for an opened window.
Definition window_gui.h:273
void CloseChildWindows(WindowClass wc=WindowClass::Invalid) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1084
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1112
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1817
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Definition window.cpp:3258
ResizeInfo resize
Resize information.
Definition window_gui.h:314
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1807
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1841
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:989
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:322
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:381
@ Gs
The content consists of a game script.
TextfileType
Additional text files accompanying Tar archives.
@ Readme
Content readme.
@ ContentBegin
This marker is used to generate the below three buttons in sequence by various of places in the code.
@ ContentEnd
This marker is used to generate the above three buttons in sequence by various of places in the code.
@ License
Content license.
@ Changelog
Content changelog.
Definition of Interval and OneShot timers.
Definition of the Window system.
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:70
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_FRAME
Frame.
Definition widget_type.h:51
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window).
Definition widget_type.h:59
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX).
Definition widget_type.h:56
@ EqualSize
Containers should keep all their (resizing) children equally large.
@ HideBevel
Bevel of resize box is hidden.
Definition widget_type.h:29
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1217
Window functions not directly related to making/drawing windows.
@ Center
Center the window.
Definition window_gui.h:147
int WidgetID
Widget ID.
Definition window_type.h:21