OpenTTD Source 15.0-beta2
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 <http://www.gnu.org/licenses/>.
6 */
7
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"
16#include "../network/network_content.h"
17#include "../dropdown_type.h"
18#include "../dropdown_func.h"
19#include "../timer/timer.h"
20#include "../timer/timer_window.h"
21
22#include "game.hpp"
23#include "game_gui.hpp"
24#include "game_config.hpp"
25#include "game_info.hpp"
26#include "../script/script_gui.h"
27#include "../script_config.hpp"
28
29#include "table/strings.h"
30
31#include "../safeguards.h"
32
33
37 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
38 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetStringTip(STR_AI_CONFIG_CAPTION_GAMESCRIPT, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
39 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
41 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_GSC_BACKGROUND),
43 NWidget(WWT_FRAME, COLOUR_MAUVE), SetStringTip(STR_AI_CONFIG_GAMESCRIPT), SetFill(1, 0), SetResize(1, 0),
44 NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_GSC_GSLIST), SetMinimalSize(288, 14), SetFill(1, 1), SetResize(1, 0), SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP),
46 NWidget(WWT_FRAME, COLOUR_MAUVE), SetStringTip(STR_AI_CONFIG_GAMESCRIPT_PARAM), SetFill(1, 1), SetResize(1, 0), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
51 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_RESET), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_AI_SETTINGS_RESET),
55 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_CHANGE), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_AI_CONFIG_CHANGE_GAMESCRIPT, STR_AI_CONFIG_CHANGE_TOOLTIP),
56 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_CONTENT_DOWNLOAD), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
60 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
61 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_TEXTFILE + TFT_README), SetFill(1, 1), SetResize(1, 0), SetMinimalSize(93, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
64 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
65 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_TEXTFILE + TFT_LICENSE), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
71 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
72 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE), SetResizeWidgetTypeTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
75};
76
79 WDP_CENTER, "settings_gs_config", 500, 350,
81 {},
83);
84
88struct GSConfigWindow : public Window {
90 int line_height = 0;
91 int clicked_button = -1;
92 bool clicked_increase = false;
93 bool clicked_dropdown = false;
94 bool closing_dropdown = false;
95 int clicked_row = 0;
96 Scrollbar *vscroll = nullptr;
97 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
99
101 {
102 this->gs_config = GameConfig::GetConfig();
103
104 this->CreateNestedTree(); // Initializes 'this->line_height' as a side effect.
105 this->vscroll = this->GetScrollbar(WID_GSC_SCROLLBAR);
107 this->OnInvalidateData(0);
108
110 }
111
112 void Close([[maybe_unused]] int data = 0) override
113 {
115 this->Window::Close();
116 }
117
124 {
125 visible_settings.clear();
126
127 for (const auto &item : *this->gs_config->GetConfigList()) {
128 bool no_hide = !item.flags.Test(ScriptConfigFlag::Developer);
129 if (no_hide || _settings_client.gui.ai_developer_tools) {
130 visible_settings.push_back(&item);
131 }
132 }
133
134 this->vscroll->SetCount(this->visible_settings.size());
135 }
136
137 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
138 {
139 switch (widget) {
140 case WID_GSC_SETTINGS:
141 this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)) + padding.height;
142 resize.width = 1;
143 resize.height = this->line_height;
144 size.height = 5 * this->line_height;
145 break;
146
147 case WID_GSC_GSLIST:
148 this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
149 size.height = 1 * this->line_height;
150 break;
151 }
152 }
153
158 static bool IsEditable()
159 {
160 return _game_mode != GM_NORMAL || Game::GetInstance() != nullptr;
161 }
162
167 std::string GetText() const
168 {
169 if (const GameInfo *info = GameConfig::GetConfig()->GetInfo(); info != nullptr) return info->GetName();
170 return GetString(STR_AI_CONFIG_NONE);
171 }
172
173 void DrawWidget(const Rect &r, WidgetID widget) const override
174 {
175 switch (widget) {
176 case WID_GSC_GSLIST: {
177 /* There is only one slot, unlike with the GS GUI, so it should never be white */
178 DrawString(r.Shrink(WidgetDimensions::scaled.matrix), this->GetText(), (IsEditable() ? TC_ORANGE : TC_SILVER));
179 break;
180 }
181 case WID_GSC_SETTINGS: {
182 Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
183 bool rtl = _current_text_dir == TD_RTL;
184 Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
186
187 int y = r.top;
188 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
189 int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
190
191 const auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->visible_settings);
192 for (auto it = first; it != last; ++it) {
193 const ScriptConfigItem &config_item = **it;
194 int current_value = this->gs_config->GetSetting(config_item.name);
195 bool editable = this->IsEditableItem(config_item);
196
197 if (config_item.flags.Test(ScriptConfigFlag::Boolean)) {
198 DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
199 } else {
200 int i = static_cast<int>(std::distance(std::begin(this->visible_settings), it));
201 if (config_item.complete_labels) {
202 DrawDropDownButton(br.left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable);
203 } else {
204 DrawArrowButtons(br.left, y + button_y_offset, COLOUR_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);
205 }
206 }
207
208 DrawString(tr.left, tr.right, y + text_y_offset, config_item.GetString(current_value), config_item.GetColour());
209 y += this->line_height;
210 }
211 break;
212 }
213 }
214 }
215
216 void OnPaint() override
217 {
218 if (this->closing_dropdown) {
219 this->closing_dropdown = false;
220 this->clicked_dropdown = false;
221 }
222 this->DrawWidgets();
223 }
224
225 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
226 {
227 if (widget >= WID_GSC_TEXTFILE && widget < WID_GSC_TEXTFILE + TFT_CONTENT_END) {
228 if (GameConfig::GetConfig() == nullptr) return;
229
231 return;
232 }
233
234 switch (widget) {
235 case WID_GSC_GSLIST: {
236 this->InvalidateData();
237 if (click_count > 1 && _game_mode != GM_NORMAL) ShowScriptListWindow((CompanyID)OWNER_DEITY, _ctrl_pressed);
238 break;
239 }
240
241 case WID_GSC_CHANGE: // choose other Game Script
243 break;
244
246 if (!_network_available) {
247 ShowErrorMessage(GetEncodedString(STR_NETWORK_ERROR_NOTAVAILABLE), {}, WL_ERROR);
248 } else {
250 }
251 break;
252
253 case WID_GSC_SETTINGS: {
254 auto it = this->vscroll->GetScrolledItemFromWidget(this->visible_settings, pt.y, this, widget);
255 if (it == this->visible_settings.end()) break;
256
257 const ScriptConfigItem &config_item = **it;
258 if (!this->IsEditableItem(config_item)) return;
259
260 int num = it - this->visible_settings.begin();
261 if (this->clicked_row != num) {
264 this->clicked_row = num;
265 this->clicked_dropdown = false;
266 }
267
268 bool bool_item = config_item.flags.Test(ScriptConfigFlag::Boolean);
269
270 Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix, RectPadding::zero);
271 int x = pt.x - r.left;
272 if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;
273
274 /* One of the arrows is clicked (or green/red rect in case of bool value) */
275 int old_val = this->gs_config->GetSetting(config_item.name);
276 if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
277 if (this->clicked_dropdown) {
278 /* unclick the dropdown */
280 this->clicked_dropdown = false;
281 this->closing_dropdown = false;
282 } else {
283 int rel_y = (pt.y - r.top) % this->line_height;
284
285 Rect wi_rect;
286 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
287 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
288 wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
289 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
290
291 /* If the mouse is still held but dragged outside of the dropdown list, keep the dropdown open */
292 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
293 this->clicked_dropdown = true;
294 this->closing_dropdown = false;
295
296 DropDownList list;
297 for (int i = config_item.min_value; i <= config_item.max_value; i++) {
298 list.push_back(MakeDropDownListStringItem(GetString(STR_JUST_RAW_STRING, config_item.labels.find(i)->second), i));
299 }
300
301 ShowDropDownListAt(this, std::move(list), old_val, WID_GSC_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE);
302 }
303 }
304 } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
305 int new_val = old_val;
306 if (bool_item) {
307 new_val = !new_val;
308 } else if (x >= SETTING_BUTTON_WIDTH / 2) {
309 /* Increase button clicked */
310 new_val += config_item.step_size;
311 if (new_val > config_item.max_value) new_val = config_item.max_value;
312 this->clicked_increase = true;
313 } else {
314 /* Decrease button clicked */
315 new_val -= config_item.step_size;
316 if (new_val < config_item.min_value) new_val = config_item.min_value;
317 this->clicked_increase = false;
318 }
319
320 if (new_val != old_val) {
321 this->gs_config->SetSetting(config_item.name, new_val);
322 this->clicked_button = num;
323 this->unclick_timeout.Reset();
324 }
325 } else if (!bool_item && !config_item.complete_labels) {
326 /* Display a query box so users can enter a custom value. */
327 ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, {});
328 }
329 this->SetDirty();
330 break;
331 }
332
333 case WID_GSC_OPEN_URL: {
334 const GameConfig *config = GameConfig::GetConfig();
335 if (config == nullptr || config->GetInfo() == nullptr) return;
336 OpenBrowser(config->GetInfo()->GetURL());
337 break;
338 }
339
340 case WID_GSC_RESET:
341 this->gs_config->ResetEditableSettings(_game_mode == GM_MENU);
342 this->SetDirty();
343 break;
344 }
345 }
346
347 void OnQueryTextFinished(std::optional<std::string> str) override
348 {
349 if (!str.has_value() || str->empty()) return;
350 int32_t value = atoi(str->c_str());
351 SetValue(value);
352 }
353
354 void OnDropdownSelect(WidgetID widget, int index) override
355 {
356 if (widget != WID_GSC_SETTING_DROPDOWN) return;
357 assert(this->clicked_dropdown);
358 SetValue(index);
359 }
360
361 void OnDropdownClose(Point, WidgetID widget, int, bool) override
362 {
363 if (widget != WID_GSC_SETTING_DROPDOWN) return;
364 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
365 * the same dropdown button was clicked again, and then not open the dropdown again.
366 * So, we only remember that it was closed, and process it on the next OnPaint, which is
367 * after OnClick. */
368 assert(this->clicked_dropdown);
369 this->closing_dropdown = true;
370 this->SetDirty();
371 }
372
373 void OnResize() override
374 {
375 this->vscroll->SetCapacityFromWidget(this, WID_GSC_SETTINGS);
376 }
377
379 TimeoutTimer<TimerWindow> unclick_timeout = {std::chrono::milliseconds(150), [this]() {
380 this->clicked_button = -1;
381 this->SetDirty();
382 }};
383
389 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
390 {
391 if (!gui_scope) return;
392
393 this->SetWidgetDisabledState(WID_GSC_CHANGE, (_game_mode == GM_NORMAL) || !IsEditable());
394
395 const GameConfig *config = GameConfig::GetConfig();
396 this->SetWidgetDisabledState(WID_GSC_OPEN_URL, config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty());
397 for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
398 this->SetWidgetDisabledState(WID_GSC_TEXTFILE + tft, !config->GetTextfile(tft, (CompanyID)OWNER_DEITY).has_value());
399 }
403 }
404private:
405 bool IsEditableItem(const ScriptConfigItem &config_item) const
406 {
407 return _game_mode == GM_MENU
408 || _game_mode == GM_EDITOR
409 || config_item.flags.Test(ScriptConfigFlag::InGame)
411 }
412
413 void SetValue(int value)
414 {
415 const ScriptConfigItem &config_item = *this->visible_settings[this->clicked_row];
416 if (_game_mode == GM_NORMAL && !config_item.flags.Test(ScriptConfigFlag::InGame)) return;
417 this->gs_config->SetSetting(config_item.name, value);
418 this->SetDirty();
419 }
420};
421
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
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:96
Script settings.
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
void SetSetting(const 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:2523
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
void Reset()
Reset the timer, so it will fire again after the timeout.
Definition timer.h:140
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:29
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
RectPadding matrix
Padding of WWT_MATRIX items.
Definition window_gui.h:42
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, bool instant_close, bool persist)
Show a drop down list.
Definition dropdown.cpp:389
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
@ WL_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:77
Base functions for all Games.
GameConfig stores the configuration settings of every Game.
static constexpr NWidgetPart _nested_gs_config_widgets[]
Widgets for the configure GS window.
Definition game_gui.cpp:35
void ShowGSConfigWindow()
Open the GS config window.
Definition game_gui.cpp:423
static WindowDesc _gs_config_desc(WDP_CENTER, "settings_gs_config", 500, 350, WC_GAME_OPTIONS, WC_NONE, {}, _nested_gs_config_widgets)
Window definition for the configure GS window.
Window for configuring the Games
GameInfo keeps track of all information of an Game, like Author, Description, ...
@ 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
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:658
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:245
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 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 SetResizeWidgetTypeTip(ResizeWidgetValues widget_type, StringID tip)
Widget part function for setting the resize widget type and tooltip.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
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:945
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:68
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=CONTENT_TYPE_END, ContentType type2=CONTENT_TYPE_END)
Show the content list window with a given set of content.
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(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.
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:58
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
@ 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:91
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:57
@ TD_RTL
Text is written right-to-left by default.
GUISettings gui
settings related to the GUI
Dimensions (a width and height) of a rectangle in 2D.
Window to configure which GSs will start.
Definition game_gui.cpp:88
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition game_gui.cpp:389
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
Definition game_gui.cpp:354
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:112
void OnResize() override
Called after the window got resized.
Definition game_gui.cpp:373
void OnPaint() override
The window must be repainted.
Definition game_gui.cpp:216
VisibleSettingsList visible_settings
List of visible GS settings.
Definition game_gui.cpp:98
bool closing_dropdown
True, if the dropdown list is currently closing.
Definition game_gui.cpp:94
std::vector< const ScriptConfigItem * > VisibleSettingsList
typdef for a vector of script settings
Definition game_gui.cpp:97
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Definition game_gui.cpp:347
int line_height
Height of a single GS-name line.
Definition game_gui.cpp:90
int clicked_button
The button we clicked.
Definition game_gui.cpp:91
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
Definition game_gui.cpp:123
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition game_gui.cpp:96
ScriptConfig * gs_config
The configuration we're modifying.
Definition game_gui.cpp:89
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
Definition game_gui.cpp:379
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:137
bool clicked_increase
Whether we clicked the increase or decrease button.
Definition game_gui.cpp:92
static bool IsEditable()
Can the GS config be edited?
Definition game_gui.cpp:158
int clicked_row
The clicked row of settings.
Definition game_gui.cpp:95
bool clicked_dropdown
Whether the dropdown is open.
Definition game_gui.cpp:93
std::string GetText() const
Get text to display for game script name.
Definition game_gui.cpp:167
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition game_gui.cpp:173
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:225
void OnDropdownClose(Point, WidgetID widget, int, bool) override
A dropdown window associated to this window has been closed.
Definition game_gui.cpp:361
bool ai_developer_tools
activate AI/GS developer tools
Partial widget specification to allow NWidgets to be written nested.
Coordinates of a point in 2D.
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:168
Data structure for an opened window.
Definition window_gui.h:274
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1052
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1736
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:744
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3164
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1040
ResizeInfo resize
Resize information.
Definition window_gui.h:315
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1726
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
@ CONTENT_TYPE_GAME
The content consists of a game script.
TextfileType
Additional text files accompanying Tar archives.
@ TFT_LICENSE
Content license.
@ TFT_README
Content readme.
@ TFT_CHANGELOG
Content changelog.
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:69
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:65
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:49
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:51
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:75
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:67
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:59
@ WWT_FRAME
Frame.
Definition widget_type.h:50
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:58
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:55
@ EqualSize
Containers should keep all their (resizing) children equally large.
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition widget_type.h:30
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1155
@ WDP_CENTER
Center the window.
Definition window_gui.h:146
int WidgetID
Widget ID.
Definition window_type.h:20
@ WN_GAME_OPTIONS_GS
GS settings.
Definition window_type.h:25
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
@ WC_GAME_OPTIONS
Game options window; Window numbers:
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
@ WC_QUERY_STRING
Query string window; Window numbers: