OpenTTD Source 20261112-master-gbcbec5e63f
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 "../strings_func.h"
14#include "../textbuf_gui.h"
15#include "../window_func.h"
16#include "../network/network.h"
18#include "../dropdown_type.h"
19#include "../dropdown_func.h"
20#include "../timer/timer.h"
23
24#include "game.hpp"
25#include "game_gui.hpp"
26#include "game_config.hpp"
27#include "game_info.hpp"
29#include "../script_config.hpp"
30
32
33#include "table/strings.h"
34
35#include "../safeguards.h"
36
37
39static constexpr std::initializer_list<NWidgetPart> _nested_gs_config_widgets = {
42 NWidget(WWT_CAPTION, Colours::Mauve), SetStringTip(STR_AI_CONFIG_CAPTION_GAMESCRIPT, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
47 NWidget(WWT_FRAME, Colours::Mauve), SetStringTip(STR_AI_CONFIG_GAMESCRIPT), SetFill(1, 0), SetResize(1, 0),
48 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),
50 NWidget(WWT_FRAME, Colours::Mauve), SetStringTip(STR_AI_CONFIG_GAMESCRIPT_PARAM), SetFill(1, 1), SetResize(1, 0), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
55 NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_RESET), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_AI_SETTINGS_RESET),
59 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),
60 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),
64 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),
65 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),
68 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),
69 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),
75 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
79};
80
83 WindowPosition::Center, "settings_gs_config", 500, 350,
84 WindowClass::GameOptions, WindowClass::None,
85 {},
87);
88
92struct GSConfigWindow : public Window {
94 int line_height = 0;
95 int clicked_button = -1;
96 bool clicked_increase = false;
97 bool clicked_dropdown = false;
98 bool closing_dropdown = false;
99 int clicked_row = 0;
100 Scrollbar *vscroll = nullptr;
101 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
103
105 {
106 this->gs_config = GameConfig::GetConfig();
107
108 this->CreateNestedTree(); // Initializes 'this->line_height' as a side effect.
109 this->vscroll = this->GetScrollbar(WID_GSC_SCROLLBAR);
111 this->OnInvalidateData(0);
112
114 }
115
116 void Close([[maybe_unused]] int data = 0) override
117 {
118 CloseWindowByClass(WindowClass::ScriptList);
119 this->Window::Close();
120 }
121
128 {
129 this->visible_settings.clear();
130
131 for (const auto &item : *this->gs_config->GetConfigList()) {
132 bool no_hide = !item.flags.Test(ScriptConfigFlag::Developer);
133 if (no_hide || _settings_client.gui.ai_developer_tools) {
134 this->visible_settings.push_back(&item);
135 }
136 }
137
138 this->vscroll->SetCount(this->visible_settings.size());
139 }
140
141 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
142 {
143 switch (widget) {
144 case WID_GSC_SETTINGS:
145 this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FontSize::Normal)) + padding.height;
146 resize.width = 1;
147 fill.height = resize.height = this->line_height;
148 size.height = 5 * this->line_height;
149 break;
150
151 case WID_GSC_GSLIST:
152 this->line_height = GetCharacterHeight(FontSize::Normal) + padding.height;
153 size.height = 1 * this->line_height;
154 break;
155 }
156 }
157
162 static bool IsEditable()
163 {
164 return _game_mode != GameMode::Normal || Game::GetInstance() != nullptr;
165 }
166
171 std::string GetText() const
172 {
173 if (const GameInfo *info = GameConfig::GetConfig()->GetInfo(); info != nullptr) return info->GetName();
174 return GetString(STR_AI_CONFIG_NONE);
175 }
176
177 void DrawWidget(const Rect &r, WidgetID widget) const override
178 {
179 switch (widget) {
180 case WID_GSC_GSLIST: {
181 /* There is only one slot, unlike with the GS GUI, so it should never be white */
183 break;
184 }
185 case WID_GSC_SETTINGS: {
186 Rect ir = r.Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero);
187 bool rtl = _current_text_dir == TD_RTL;
188 Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
190
191 int y = r.top;
192 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
193 int text_y_offset = (this->line_height - GetCharacterHeight(FontSize::Normal)) / 2;
194
195 const auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->visible_settings);
196 for (auto it = first; it != last; ++it) {
197 const ScriptConfigItem &config_item = **it;
198 int current_value = this->gs_config->GetSetting(config_item.name);
199 bool editable = this->IsEditableItem(config_item);
200
201 if (config_item.flags.Test(ScriptConfigFlag::Boolean)) {
202 DrawBoolButton(br.left, y + button_y_offset, Colours::Yellow, Colours::Mauve, current_value != 0, editable);
203 } else {
204 int i = static_cast<int>(std::distance(std::begin(this->visible_settings), it));
205 if (config_item.complete_labels) {
206 DrawDropDownButton(br.left, y + button_y_offset, Colours::Yellow, this->clicked_row == i && this->clicked_dropdown, editable);
207 } else {
208 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);
209 }
210 }
211
212 DrawString(tr.left, tr.right, y + text_y_offset, config_item.GetString(current_value), config_item.GetColour());
213 y += this->line_height;
214 }
215 break;
216 }
217 }
218 }
219
220 void OnPaint() override
221 {
222 if (this->closing_dropdown) {
223 this->closing_dropdown = false;
224 this->clicked_dropdown = false;
225 }
226 this->DrawWidgets();
227 }
228
229 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
230 {
231 if (widget >= WID_GSC_TEXTFILE && widget < WID_GSC_TEXTFILE + TextfileType::ContentEnd) {
232 if (GameConfig::GetConfig() == nullptr) return;
233
235 return;
236 }
237
238 switch (widget) {
239 case WID_GSC_GSLIST: {
240 this->InvalidateData();
241 if (click_count > 1 && _game_mode != GameMode::Normal) ShowScriptListWindow(OWNER_DEITY, IsCtrlPressed());
242 break;
243 }
244
245 case WID_GSC_CHANGE: // choose other Game Script
247 break;
248
250 if (!_network_available) {
251 ShowErrorMessage(GetEncodedString(STR_NETWORK_ERROR_NOTAVAILABLE), {}, WarningLevel::Error);
252 } else {
254 }
255 break;
256
257 case WID_GSC_SETTINGS: {
258 auto it = this->vscroll->GetScrolledItemFromWidget(this->visible_settings, pt.y, this, widget);
259 if (it == this->visible_settings.end()) break;
260
261 const ScriptConfigItem &config_item = **it;
262 if (!this->IsEditableItem(config_item)) return;
263
264 int num = it - this->visible_settings.begin();
265 if (this->clicked_row != num) {
266 this->CloseChildWindows(WindowClass::QueryString);
267 this->CloseChildWindows(WindowClass::DropdownMenu);
268 this->clicked_row = num;
269 this->clicked_dropdown = false;
270 }
271
272 bool bool_item = config_item.flags.Test(ScriptConfigFlag::Boolean);
273
274 Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero);
275 int x = pt.x - r.left;
276 if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;
277
278 /* One of the arrows is clicked (or green/red rect in case of bool value) */
279 int old_val = this->gs_config->GetSetting(config_item.name);
280 if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
281 if (this->clicked_dropdown) {
282 /* unclick the dropdown */
283 this->CloseChildWindows(WindowClass::DropdownMenu);
284 this->clicked_dropdown = false;
285 this->closing_dropdown = false;
286 } else {
287 int rel_y = (pt.y - r.top) % this->line_height;
288
289 Rect wi_rect;
290 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
291 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
292 wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
293 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
294
295 /* If the mouse is still held but dragged outside of the dropdown list, keep the dropdown open */
296 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
297 this->clicked_dropdown = true;
298 this->closing_dropdown = false;
299
300 DropDownList list;
301 for (int i = config_item.min_value; i <= config_item.max_value; i++) {
302 list.push_back(MakeDropDownListStringItem(GetString(STR_JUST_RAW_STRING, config_item.labels.find(i)->second), i));
303 }
304
305 ShowDropDownListAt(this, std::move(list), old_val, WID_GSC_SETTING_DROPDOWN, wi_rect, Colours::Orange);
306 }
307 }
308 } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
309 int new_val = old_val;
310 if (bool_item) {
311 new_val = !new_val;
312 } else if (x >= SETTING_BUTTON_WIDTH / 2) {
313 /* Increase button clicked */
314 new_val += config_item.step_size;
315 if (new_val > config_item.max_value) new_val = config_item.max_value;
316 this->clicked_increase = true;
317 } else {
318 /* Decrease button clicked */
319 new_val -= config_item.step_size;
320 if (new_val < config_item.min_value) new_val = config_item.min_value;
321 this->clicked_increase = false;
322 }
323
324 if (new_val != old_val) {
325 this->gs_config->SetSetting(config_item.name, new_val);
326 this->clicked_button = num;
327 this->unclick_timeout.Reset();
328 }
329 } else if (!bool_item && !config_item.complete_labels) {
330 /* Display a query box so users can enter a custom value. */
331 ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, {});
332 }
333 this->SetDirty();
334 break;
335 }
336
337 case WID_GSC_OPEN_URL: {
338 const GameConfig *config = GameConfig::GetConfig();
339 if (config == nullptr || config->GetInfo() == nullptr) return;
340 OpenBrowser(config->GetInfo()->GetURL());
341 break;
342 }
343
344 case WID_GSC_RESET:
345 this->gs_config->ResetEditableSettings(_game_mode == GameMode::Menu);
346 this->SetDirty();
347 break;
348 }
349 }
350
351 void OnQueryTextFinished(std::optional<std::string> str) override
352 {
353 if (!str.has_value()) return;
354 auto value = ParseInteger<int32_t>(*str, 10, true);
355 if (!value.has_value()) return;
356 this->SetValue(*value);
357 }
358
359 void OnDropdownSelect(WidgetID widget, int index, int) override
360 {
361 if (widget != WID_GSC_SETTING_DROPDOWN) return;
362 assert(this->clicked_dropdown);
363 this->SetValue(index);
364 }
365
366 void OnDropdownClose(Point, WidgetID widget, int, int, bool) override
367 {
368 if (widget != WID_GSC_SETTING_DROPDOWN) return;
369 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
370 * the same dropdown button was clicked again, and then not open the dropdown again.
371 * So, we only remember that it was closed, and process it on the next OnPaint, which is
372 * after OnClick. */
373 assert(this->clicked_dropdown);
374 this->closing_dropdown = true;
375 this->SetDirty();
376 }
377
378 void OnResize() override
379 {
380 this->vscroll->SetCapacityFromWidget(this, WID_GSC_SETTINGS);
381 }
382
384 TimeoutTimer<TimerWindow> unclick_timeout = {std::chrono::milliseconds(150), [this]() {
385 this->clicked_button = -1;
386 this->SetDirty();
387 }};
388
394 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
395 {
396 if (!gui_scope) return;
397
399
400 const GameConfig *config = GameConfig::GetConfig();
401 this->SetWidgetDisabledState(WID_GSC_OPEN_URL, config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty());
403 this->SetWidgetDisabledState(WID_GSC_TEXTFILE + tft, !config->GetTextfile(tft, OWNER_DEITY).has_value());
404 }
406 this->CloseChildWindows(WindowClass::DropdownMenu);
407 this->CloseChildWindows(WindowClass::QueryString);
408 }
409private:
410 bool IsEditableItem(const ScriptConfigItem &config_item) const
411 {
412 return _game_mode == GameMode::Menu
413 || _game_mode == GameMode::Editor
414 || config_item.flags.Test(ScriptConfigFlag::InGame)
415 || _settings_client.gui.ai_developer_tools;
416 }
417
418 void SetValue(int value)
419 {
420 const ScriptConfigItem &config_item = *this->visible_settings[this->clicked_row];
421 if (_game_mode == GameMode::Normal && !config_item.flags.Test(ScriptConfigFlag::InGame)) return;
422 this->gs_config->SetSetting(config_item.name, value);
423 this->SetDirty();
424 }
425};
426
429{
430 CloseWindowByClass(WindowClass::GameOptions);
431 new GSConfigWindow();
432}
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:94
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:574
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:24
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:39
void ShowGSConfigWindow()
Open the GS config window.
Definition game_gui.cpp:428
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
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:663
bool IsCtrlPressed()
Test if the ctrl key is pressed.
Definition gfx_func.h:82
@ 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:1013
#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:65
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
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:89
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:423
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:55
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
Window to configure which GSs will start.
Definition game_gui.cpp:92
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition game_gui.cpp:394
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:116
void OnResize() override
Called after the window got resized.
Definition game_gui.cpp:378
void OnPaint() override
The window must be repainted.
Definition game_gui.cpp:220
VisibleSettingsList visible_settings
List of visible GS settings.
Definition game_gui.cpp:102
bool closing_dropdown
True, if the dropdown list is currently closing.
Definition game_gui.cpp:98
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
Definition game_gui.cpp:359
std::vector< const ScriptConfigItem * > VisibleSettingsList
typedef for a vector of script settings
Definition game_gui.cpp:101
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Definition game_gui.cpp:351
int line_height
Height of a single GS-name line.
Definition game_gui.cpp:94
void OnDropdownClose(Point, WidgetID widget, int, int, bool) override
A dropdown window associated to this window has been closed.
Definition game_gui.cpp:366
int clicked_button
The button we clicked.
Definition game_gui.cpp:95
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
Definition game_gui.cpp:127
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition game_gui.cpp:100
ScriptConfig * gs_config
The configuration we're modifying.
Definition game_gui.cpp:93
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
Definition game_gui.cpp:384
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:141
bool clicked_increase
Whether we clicked the increase or decrease button.
Definition game_gui.cpp:96
static bool IsEditable()
Can the GS config be edited?
Definition game_gui.cpp:162
int clicked_row
The clicked row of settings.
Definition game_gui.cpp:99
bool clicked_dropdown
Whether the dropdown is open.
Definition game_gui.cpp:97
std::string GetText() const
Get text to display for game script name.
Definition game_gui.cpp:171
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition game_gui.cpp:177
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:229
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:171
Data structure for an opened window.
Definition window_gui.h:272
void CloseChildWindows(WindowClass wc=WindowClass::Invalid) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1122
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1150
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1855
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:3317
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1845
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
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:380
@ Gs
The content consists of a game script.
Stuff related to the text buffer GUI.
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:1255
Window functions not directly related to making/drawing windows.
@ Center
Center the window.
Definition window_gui.h:146
int WidgetID
Widget ID.
Definition window_type.h:21