OpenTTD Source  14.0-beta1
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 "../widgets/dropdown_func.h"
18 #include "../timer/timer.h"
19 #include "../timer/timer_window.h"
20 
21 #include "game.hpp"
22 #include "game_gui.hpp"
23 #include "game_config.hpp"
24 #include "game_info.hpp"
25 #include "../script/script_gui.h"
26 #include "../script_config.hpp"
27 #include "../table/strings.h"
28 
29 #include "../safeguards.h"
30 
31 
33 static constexpr NWidgetPart _nested_gs_config_widgets[] = {
35  NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
36  NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_CAPTION_GAMESCRIPT, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
37  NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
38  EndContainer(),
39  NWidget(WWT_PANEL, COLOUR_MAUVE, WID_GSC_BACKGROUND),
41  NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_GAMESCRIPT, STR_NULL), SetFill(1, 0), SetResize(1, 0),
42  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),
43  EndContainer(),
44  NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_GAMESCRIPT_PARAM, STR_NULL), SetFill(1, 1), SetResize(1, 0), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
46  NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_GSC_SETTINGS), SetFill(1, 0), SetResize(1, 1), SetMinimalSize(188, 182), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_GSC_SCROLLBAR),
48  EndContainer(),
49  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_RESET), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_AI_SETTINGS_RESET, STR_NULL),
50  EndContainer(),
53  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_CHANGE), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_AI_CONFIG_CHANGE_GAMESCRIPT, STR_AI_CONFIG_CHANGE_TOOLTIP),
54  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_CONTENT_DOWNLOAD), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
55  EndContainer(),
58  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
59  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_TEXTFILE + TFT_README), SetFill(1, 1), SetResize(1, 0), SetMinimalSize(93, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
60  EndContainer(),
62  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
63  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_TEXTFILE + TFT_LICENSE), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
64  EndContainer(),
65  EndContainer(),
66  EndContainer(),
67  EndContainer(),
69  NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
70  NWidget(WWT_RESIZEBOX, COLOUR_MAUVE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
71  EndContainer(),
72  EndContainer(),
73 };
74 
76 static WindowDesc _gs_config_desc(__FILE__, __LINE__,
77  WDP_CENTER, "settings_gs_config", 500, 350,
79  0,
81 );
82 
86 struct GSConfigWindow : public Window {
95  typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
97 
99  clicked_button(-1),
100  clicked_dropdown(false),
101  closing_dropdown(false)
102  {
103  this->gs_config = GameConfig::GetConfig();
104 
105  this->CreateNestedTree(); // Initializes 'this->line_height' as a side effect.
106  this->vscroll = this->GetScrollbar(WID_GSC_SCROLLBAR);
108  this->OnInvalidateData(0);
109 
110  this->RebuildVisibleSettings();
111  }
112 
113  void Close([[maybe_unused]] int data = 0) override
114  {
116  this->Window::Close();
117  }
118 
125  {
126  visible_settings.clear();
127 
128  for (const auto &item : *this->gs_config->GetConfigList()) {
129  bool no_hide = (item.flags & SCRIPTCONFIG_DEVELOPER) == 0;
130  if (no_hide || _settings_client.gui.ai_developer_tools) {
131  visible_settings.push_back(&item);
132  }
133  }
134 
135  this->vscroll->SetCount(this->visible_settings.size());
136  }
137 
138  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
139  {
140  switch (widget) {
141  case WID_GSC_SETTINGS:
142  this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)) + padding.height;
143  resize->width = 1;
144  resize->height = this->line_height;
145  size->height = 5 * this->line_height;
146  break;
147 
148  case WID_GSC_GSLIST:
149  this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
150  size->height = 1 * this->line_height;
151  break;
152  }
153  }
154 
159  static bool IsEditable()
160  {
161  return _game_mode != GM_NORMAL || Game::GetInstance() != nullptr;
162  }
163 
164  void DrawWidget(const Rect &r, WidgetID widget) const override
165  {
166  switch (widget) {
167  case WID_GSC_GSLIST: {
168  StringID text = STR_AI_CONFIG_NONE;
169 
170  if (GameConfig::GetConfig()->GetInfo() != nullptr) {
171  SetDParamStr(0, GameConfig::GetConfig()->GetInfo()->GetName());
172  text = STR_JUST_RAW_STRING;
173  }
174 
175  /* There is only one slot, unlike with the GS GUI, so it should never be white */
176  DrawString(r.Shrink(WidgetDimensions::scaled.matrix), text, (IsEditable() ? TC_ORANGE : TC_SILVER));
177  break;
178  }
179  case WID_GSC_SETTINGS: {
180  ScriptConfig *config = this->gs_config;
181  VisibleSettingsList::const_iterator it = this->visible_settings.begin();
182  int i = 0;
183  for (; !this->vscroll->IsVisible(i); i++) it++;
184 
185  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
186  bool rtl = _current_text_dir == TD_RTL;
187  Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
188  Rect tr = ir.Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide, 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(FS_NORMAL)) / 2;
193  for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
194  const ScriptConfigItem &config_item = **it;
195  int current_value = config->GetSetting((config_item).name);
196  bool editable = this->IsEditableItem(config_item);
197 
198  StringID str;
199  TextColour colour;
200  uint idx = 0;
201  if (config_item.description.empty()) {
202  if (Game::GetInstance() == nullptr && config_item.random_deviation != 0) {
203  str = STR_AI_SETTINGS_JUST_DEVIATION;
204  } else {
205  str = STR_JUST_STRING1;
206  }
207  colour = TC_ORANGE;
208  } else {
209  if (Game::GetInstance() == nullptr && config_item.random_deviation != 0) {
210  str = STR_AI_SETTINGS_SETTING_DEVIATION;
211  } else {
212  str = STR_AI_SETTINGS_SETTING;
213  }
214  colour = TC_LIGHT_BLUE;
215  SetDParamStr(idx++, config_item.description);
216  }
217 
218  if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
219  DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
220  SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
221  } else {
222  if (config_item.complete_labels) {
223  DrawDropDownButton(br.left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable);
224  } else {
225  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);
226  }
227 
228  if (Game::GetInstance() != nullptr || config_item.random_deviation == 0) {
229  auto config_iterator = config_item.labels.find(current_value);
230  if (config_iterator != config_item.labels.end()) {
231  SetDParam(idx++, STR_JUST_RAW_STRING);
232  SetDParamStr(idx++, config_iterator->second);
233  } else {
234  SetDParam(idx++, STR_JUST_INT);
235  SetDParam(idx++, current_value);
236  }
237  } else {
238  int min_deviated = std::max(config_item.min_value, current_value - config_item.random_deviation);
239  auto config_iterator = config_item.labels.find(min_deviated);
240  if (config_iterator != config_item.labels.end()) {
241  SetDParam(idx++, STR_JUST_RAW_STRING);
242  SetDParamStr(idx++, config_iterator->second);
243  } else {
244  SetDParam(idx++, STR_JUST_INT);
245  SetDParam(idx++, min_deviated);
246  }
247 
248  int max_deviated = std::min(config_item.max_value, current_value + config_item.random_deviation);
249  config_iterator = config_item.labels.find(max_deviated);
250  if (config_iterator != config_item.labels.end()) {
251  SetDParam(idx++, STR_JUST_RAW_STRING);
252  SetDParamStr(idx++, config_iterator->second);
253  } else {
254  SetDParam(idx++, STR_JUST_INT);
255  SetDParam(idx++, max_deviated);
256  }
257  }
258  }
259 
260  DrawString(tr.left, tr.right, y + text_y_offset, str, colour);
261  y += this->line_height;
262  }
263  break;
264  }
265  }
266  }
267 
268  void OnPaint() override
269  {
270  if (this->closing_dropdown) {
271  this->closing_dropdown = false;
272  this->clicked_dropdown = false;
273  }
274  this->DrawWidgets();
275  }
276 
277  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
278  {
279  if (widget >= WID_GSC_TEXTFILE && widget < WID_GSC_TEXTFILE + TFT_CONTENT_END) {
280  if (GameConfig::GetConfig() == nullptr) return;
281 
283  return;
284  }
285 
286  switch (widget) {
287  case WID_GSC_GSLIST: {
288  this->InvalidateData();
289  if (click_count > 1 && _game_mode != GM_NORMAL) ShowScriptListWindow((CompanyID)OWNER_DEITY, _ctrl_pressed);
290  break;
291  }
292 
293  case WID_GSC_CHANGE: // choose other Game Script
295  break;
296 
298  if (!_network_available) {
299  ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
300  } else {
302  }
303  break;
304 
305  case WID_GSC_SETTINGS: {
306  auto it = this->vscroll->GetScrolledItemFromWidget(this->visible_settings, pt.y, this, widget);
307  if (it == this->visible_settings.end()) break;
308 
309  const ScriptConfigItem &config_item = **it;
310  if (!this->IsEditableItem(config_item)) return;
311 
312  int num = it - this->visible_settings.begin();
313  if (this->clicked_row != num) {
316  this->clicked_row = num;
317  this->clicked_dropdown = false;
318  }
319 
320  bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
321 
322  Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix, RectPadding::zero);
323  int x = pt.x - r.left;
324  if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;
325 
326  /* One of the arrows is clicked (or green/red rect in case of bool value) */
327  int old_val = this->gs_config->GetSetting(config_item.name);
328  if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
329  if (this->clicked_dropdown) {
330  /* unclick the dropdown */
332  this->clicked_dropdown = false;
333  this->closing_dropdown = false;
334  } else {
335  int rel_y = (pt.y - r.top) % this->line_height;
336 
337  Rect wi_rect;
338  wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
339  wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
340  wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
341  wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
342 
343  /* If the mouse is still held but dragged outside of the dropdown list, keep the dropdown open */
344  if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
345  this->clicked_dropdown = true;
346  this->closing_dropdown = false;
347 
348  DropDownList list;
349  for (int i = config_item.min_value; i <= config_item.max_value; i++) {
350  list.push_back(std::make_unique<DropDownListStringItem>(config_item.labels.find(i)->second, i, false));
351  }
352 
353  ShowDropDownListAt(this, std::move(list), old_val, WID_GSC_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE);
354  }
355  }
356  } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
357  int new_val = old_val;
358  if (bool_item) {
359  new_val = !new_val;
360  } else if (x >= SETTING_BUTTON_WIDTH / 2) {
361  /* Increase button clicked */
362  new_val += config_item.step_size;
363  if (new_val > config_item.max_value) new_val = config_item.max_value;
364  this->clicked_increase = true;
365  } else {
366  /* Decrease button clicked */
367  new_val -= config_item.step_size;
368  if (new_val < config_item.min_value) new_val = config_item.min_value;
369  this->clicked_increase = false;
370  }
371 
372  if (new_val != old_val) {
373  this->gs_config->SetSetting(config_item.name, new_val);
374  this->clicked_button = num;
375  this->unclick_timeout.Reset();
376  }
377  } else if (!bool_item && !config_item.complete_labels) {
378  /* Display a query box so users can enter a custom value. */
379  SetDParam(0, old_val);
380  ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, QSF_NONE);
381  }
382  this->SetDirty();
383  break;
384  }
385 
386  case WID_GSC_OPEN_URL: {
387  const GameConfig *config = GameConfig::GetConfig();
388  if (config == nullptr || config->GetInfo() == nullptr) return;
389  OpenBrowser(config->GetInfo()->GetURL());
390  break;
391  }
392 
393  case WID_GSC_RESET:
394  this->gs_config->ResetEditableSettings(_game_mode == GM_MENU);
395  this->SetDirty();
396  break;
397  }
398  }
399 
400  void OnQueryTextFinished(char *str) override
401  {
402  if (StrEmpty(str)) return;
403  int32_t value = atoi(str);
404  SetValue(value);
405  }
406 
407  void OnDropdownSelect(WidgetID widget, int index) override
408  {
409  if (widget != WID_GSC_SETTING_DROPDOWN) return;
410  assert(this->clicked_dropdown);
411  SetValue(index);
412  }
413 
414  void OnDropdownClose(Point, WidgetID widget, int, bool) override
415  {
416  if (widget != WID_GSC_SETTING_DROPDOWN) return;
417  /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
418  * the same dropdown button was clicked again, and then not open the dropdown again.
419  * So, we only remember that it was closed, and process it on the next OnPaint, which is
420  * after OnClick. */
421  assert(this->clicked_dropdown);
422  this->closing_dropdown = true;
423  this->SetDirty();
424  }
425 
426  void OnResize() override
427  {
428  this->vscroll->SetCapacityFromWidget(this, WID_GSC_SETTINGS);
429  }
430 
432  TimeoutTimer<TimerWindow> unclick_timeout = {std::chrono::milliseconds(150), [this]() {
433  this->clicked_button = -1;
434  this->SetDirty();
435  }};
436 
442  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
443  {
444  if (!gui_scope) return;
445 
446  this->SetWidgetDisabledState(WID_GSC_CHANGE, (_game_mode == GM_NORMAL) || !IsEditable());
447 
448  const GameConfig *config = GameConfig::GetConfig();
449  this->SetWidgetDisabledState(WID_GSC_OPEN_URL, config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty());
450  for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
451  this->SetWidgetDisabledState(WID_GSC_TEXTFILE + tft, !config->GetTextfile(tft, (CompanyID)OWNER_DEITY).has_value());
452  }
453  this->RebuildVisibleSettings();
456  }
457 private:
458  bool IsEditableItem(const ScriptConfigItem &config_item) const
459  {
460  return _game_mode == GM_MENU
461  || _game_mode == GM_EDITOR
462  || (config_item.flags & SCRIPTCONFIG_INGAME) != 0
464  }
465 
466  void SetValue(int value)
467  {
468  const ScriptConfigItem &config_item = *this->visible_settings[this->clicked_row];
469  if (_game_mode == GM_NORMAL && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
470  this->gs_config->SetSetting(config_item.name, value);
471  this->SetDirty();
472  }
473 };
474 
477 {
479  new GSConfigWindow();
480 }
game.hpp
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
GSConfigWindow::VisibleSettingsList
std::vector< const ScriptConfigItem * > VisibleSettingsList
typdef for a vector of script settings
Definition: game_gui.cpp:95
GSConfigWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: game_gui.cpp:442
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition: window.cpp:1153
INT32_DIGITS_WITH_SIGN_AND_TERMINATION
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'.
Definition: script_config.hpp:18
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:268
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
game_info.hpp
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
ScriptConfigItem::step_size
int step_size
The step size in the gui.
Definition: script_config.hpp:39
ShowScriptListWindow
void ShowScriptListWindow(CompanyID slot, bool show_all)
Open the Script list window to chose a script for the given company slot.
Definition: script_gui.cpp:276
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
ScriptConfigItem::name
std::string name
The name of the configuration setting.
Definition: script_config.hpp:33
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:210
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
RWV_HIDE_BEVEL
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition: widget_type.h:42
WID_GSC_SETTINGS
@ WID_GSC_SETTINGS
Panel to draw the Game Script settings on.
Definition: game_widget.h:19
ShowNetworkContentListWindow
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.
Definition: network_content_gui.cpp:1130
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1174
GSConfigWindow::IsEditable
static bool IsEditable()
Can the GS config be edited?
Definition: game_gui.cpp:159
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
WID_GSC_TEXTFILE
@ WID_GSC_TEXTFILE
Open GS readme, changelog (+1) or license (+2).
Definition: game_widget.h:23
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
Scrollbar::SetCapacityFromWidget
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:2334
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
WID_GSC_SETTING_DROPDOWN
@ WID_GSC_SETTING_DROPDOWN
Dynamically created dropdown for changing setting value.
Definition: game_widget.h:27
WID_GSC_OPEN_URL
@ WID_GSC_OPEN_URL
Open GS URL.
Definition: game_widget.h:22
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
StrEmpty
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:56
TFT_CHANGELOG
@ TFT_CHANGELOG
Content changelog.
Definition: textfile_type.h:18
ScriptConfig::ResetEditableSettings
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
Definition: script_config.cpp:109
GSConfigWindow::OnDropdownClose
void OnDropdownClose(Point, WidgetID widget, int, bool) override
A dropdown window associated to this window has been closed.
Definition: game_gui.cpp:414
GSConfigWindow
Window to configure which GSs will start.
Definition: game_gui.cpp:86
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
SCRIPTCONFIG_BOOLEAN
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
Definition: script_config.hpp:24
ScriptConfigItem::min_value
int min_value
The minimal value this configuration setting can have.
Definition: script_config.hpp:35
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
TimeoutTimer::Reset
void Reset()
Reset the timer, so it will fire again after the timeout.
Definition: timer.h:140
ScriptConfigItem::complete_labels
bool complete_labels
True if all values have a label.
Definition: script_config.hpp:42
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:508
SetPadding
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.
Definition: widget_type.h:1188
CONTENT_TYPE_GAME
@ CONTENT_TYPE_GAME
The content consists of a game script.
Definition: tcp_content_type.h:28
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:123
GUISettings::ai_developer_tools
bool ai_developer_tools
activate AI/GS developer tools
Definition: settings_type.h:217
ScriptConfigItem::max_value
int max_value
The maximal value this configuration setting can have.
Definition: script_config.hpp:36
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
DrawDropDownButton
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Definition: settings_gui.cpp:2940
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
WidgetDimensions::matrix
RectPadding matrix
Padding of WWT_MATRIX items.
Definition: window_gui.h:44
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
GSConfigWindow::RebuildVisibleSettings
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
Definition: game_gui.cpp:124
ScriptInfo::GetURL
const std::string & GetURL() const
Get the website for this script.
Definition: script_info.hpp:76
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
game_gui.hpp
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
GameConfig
Definition: game_config.hpp:15
_gs_config_desc
static WindowDesc _gs_config_desc(__FILE__, __LINE__, WDP_CENTER, "settings_gs_config", 500, 350, WC_GAME_OPTIONS, WC_NONE, 0, std::begin(_nested_gs_config_widgets), std::end(_nested_gs_config_widgets))
Window definition for the configure GS window.
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
GSConfigWindow::unclick_timeout
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
Definition: game_gui.cpp:432
SCRIPTCONFIG_INGAME
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
Definition: script_config.hpp:25
WID_GSC_GSLIST
@ WID_GSC_GSLIST
List with current selected Game Script.
Definition: game_widget.h:18
SCRIPTCONFIG_DEVELOPER
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
Definition: script_config.hpp:26
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1083
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
GSConfigWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: game_gui.cpp:268
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
WWT_FRAME
@ WWT_FRAME
Frame.
Definition: widget_type.h:62
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator 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.
Definition: widget_type.h:845
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition: settings_gui.h:17
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2909
GSConfigWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: game_gui.cpp:94
TFT_README
@ TFT_README
Content readme.
Definition: textfile_type.h:17
ShowGSConfigWindow
void ShowGSConfigWindow()
Open the GS config window.
Definition: game_gui.cpp:476
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3140
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
WID_GSC_CONTENT_DOWNLOAD
@ WID_GSC_CONTENT_DOWNLOAD
Download content button.
Definition: game_widget.h:24
WID_GSC_CHANGE
@ WID_GSC_CHANGE
Select another Game Script button.
Definition: game_widget.h:21
TFT_LICENSE
@ TFT_LICENSE
Content license.
Definition: textfile_type.h:19
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:619
WID_GSC_BACKGROUND
@ WID_GSC_BACKGROUND
Window background.
Definition: game_widget.h:17
TimeoutTimer< TimerWindow >
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
Scrollbar::IsVisible
bool IsVisible(uint16_t item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:730
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1036
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1220
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
GameConfig::GetConfig
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: game_config.cpp:18
ScriptConfig
Script settings.
Definition: script_config.hpp:50
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
WN_GAME_OPTIONS_GS
@ WN_GAME_OPTIONS_GS
GS settings.
Definition: window_type.h:23
ScriptConfig::GetSetting
int GetSetting(const std::string &name) const
Get the value of a setting for this config.
Definition: script_config.cpp:84
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:352
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:81
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:26
ScriptConfig::GetTextfile
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
Definition: script_config.cpp:193
CS_NUMERAL_SIGNED
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
Definition: string_type.h:28
GSConfigWindow::closing_dropdown
bool closing_dropdown
True, if the dropdown list is currently closing.
Definition: game_gui.cpp:92
WID_GSC_SCROLLBAR
@ WID_GSC_SCROLLBAR
Scrollbar to scroll through the selected AIs.
Definition: game_widget.h:20
GSConfigWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: game_gui.cpp:426
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
ScriptConfigItem::description
std::string description
The description of the configuration setting.
Definition: script_config.hpp:34
ScriptConfigItem::flags
ScriptConfigFlags flags
Flags for the configuration setting.
Definition: script_config.hpp:40
DrawString
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
GSConfigWindow::clicked_row
int clicked_row
The clicked row of settings.
Definition: game_gui.cpp:93
ScriptConfig::GetConfigList
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
Definition: script_config.cpp:61
GSConfigWindow::clicked_button
int clicked_button
The button we clicked.
Definition: game_gui.cpp:89
Window
Data structure for an opened window.
Definition: window_gui.h:267
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
ScriptConfigItem::labels
LabelMapping labels
Text labels for the integer values.
Definition: script_config.hpp:41
GSConfigWindow::visible_settings
VisibleSettingsList visible_settings
List of visible GS settings.
Definition: game_gui.cpp:96
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
ShowScriptTextfileWindow
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
Definition: script_gui.cpp:692
DrawBoolButton
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
Definition: settings_gui.cpp:2961
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
_network_available
bool _network_available
is network mode available?
Definition: network.cpp:61
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
WC_SCRIPT_LIST
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
Definition: window_type.h:284
Game::GetInstance
static class GameInstance * GetInstance()
Get the current active instance.
Definition: game.hpp:102
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition: window_type.h:156
game_config.hpp
ScriptConfigItem
Info about a single Script setting.
Definition: script_config.hpp:32
ScriptConfigItem::random_deviation
int random_deviation
The maximum random deviation from the default value.
Definition: script_config.hpp:38
ScriptConfig::SetSetting
void SetSetting(const std::string_view name, int value)
Set the value of a setting for this config.
Definition: script_config.cpp:91
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:142
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition: settings_gui.h:19
GSConfigWindow::clicked_dropdown
bool clicked_dropdown
Whether the dropdown is open.
Definition: game_gui.cpp:91
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
_nested_gs_config_widgets
static constexpr NWidgetPart _nested_gs_config_widgets[]
Widgets for the configure GS window.
Definition: game_gui.cpp:33
GSConfigWindow::clicked_increase
bool clicked_increase
Whether we clicked the increase or decrease button.
Definition: game_gui.cpp:90
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
WID_GSC_RESET
@ WID_GSC_RESET
Reset button.
Definition: game_widget.h:25
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:332
GSConfigWindow::gs_config
ScriptConfig * gs_config
The configuration we're modifying.
Definition: game_gui.cpp:87
GSConfigWindow::line_height
int line_height
Height of a single GS-name line.
Definition: game_gui.cpp:88