OpenTTD Source  13.2.1
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 "../table/sprites.h"
12 #include "../error.h"
13 #include "../settings_gui.h"
14 #include "../querystring_gui.h"
15 #include "../stringfilter_type.h"
16 #include "../company_base.h"
17 #include "../company_gui.h"
18 #include "../strings_func.h"
19 #include "../window_func.h"
20 #include "../window_type.h"
21 #include "../gfx_func.h"
22 #include "../command_func.h"
23 #include "../network/network.h"
24 #include "../settings_func.h"
25 #include "../network/network_content.h"
26 #include "../textfile_gui.h"
27 #include "../widgets/dropdown_type.h"
28 #include "../widgets/dropdown_func.h"
29 #include "../hotkeys.h"
30 #include "../core/geometry_func.hpp"
31 #include "../guitimer_func.h"
32 #include "../company_cmd.h"
33 #include "../misc_cmd.h"
34 
35 #include "game_gui.hpp"
36 #include "../ai/ai_config.hpp"
37 #include "../ai/ai_gui.hpp"
38 #include "../widgets/game_widget.h"
39 #include "../table/strings.h"
40 #include "../game/game.hpp"
41 #include "../game/game_config.hpp"
42 #include "../game/game_info.hpp"
43 #include "../game/game_instance.hpp"
44 
45 #include "../safeguards.h"
46 
47 
51  NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
52  NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_CAPTION_GAMESCRIPT, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
53  NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
54  EndContainer(),
55  NWidget(WWT_PANEL, COLOUR_MAUVE, WID_GSC_BACKGROUND), SetFill(1, 0), SetResize(1, 0),
56  NWidget(NWID_SPACER), SetMinimalSize(0, 3), SetFill(1, 0), SetResize(1, 0),
57  NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_GAMESCRIPT, STR_NULL), SetFill(1, 0), SetResize(1, 0), SetPadding(0, 5, 4, 5),
58  NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_GSC_GSLIST), SetMinimalSize(288, 14), SetFill(1, 0), SetResize(1, 0), SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP),
59  EndContainer(),
60  NWidget(NWID_SPACER), SetMinimalSize(0, 6), SetFill(1, 0), SetResize(1, 0),
61  NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_GAMESCRIPT_PARAM, STR_NULL), SetFill(1, 0), SetResize(1, 0), SetPadding(0, 5, 4, 5),
63  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),
64  NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_GSC_SCROLLBAR),
65  EndContainer(),
66  EndContainer(),
68  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_CHANGE), SetFill(1, 0), SetResize(1, 0), SetMinimalSize(93, 0), SetDataTip(STR_AI_CONFIG_CHANGE_GAMESCRIPT, STR_AI_CONFIG_CHANGE_TOOLTIP),
69  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetMinimalSize(93, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
70  EndContainer(),
72  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
73  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
74  EndContainer(),
75  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GSC_CONTENT_DOWNLOAD), SetFill(1, 0), SetResize(1, 0), SetMinimalSize(279, 0), SetPadding(0, 7, 9, 7), SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
76  EndContainer(),
79  NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GSC_ACCEPT), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
80  NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GSC_RESET), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_AI_SETTINGS_RESET, STR_NULL),
81  EndContainer(),
82  NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
83  EndContainer(),
84 };
85 
88  WDP_CENTER, "settings_gs_config", 500, 350,
90  0,
92 );
93 
97 struct GSConfigWindow : public Window {
107  typedef std::vector<const ScriptConfigItem*> VisibleSettingsList;
109 
111  clicked_button(-1),
112  clicked_dropdown(false),
113  closing_dropdown(false),
114  timeout(0)
115  {
116  this->gs_config = GameConfig::GetConfig();
117 
118  this->CreateNestedTree(); // Initializes 'this->line_height' as a side effect.
119  this->vscroll = this->GetScrollbar(WID_GSC_SCROLLBAR);
121  this->OnInvalidateData(0);
122 
123  this->RebuildVisibleSettings();
124  }
125 
126  void Close() override
127  {
129  this->Window::Close();
130  }
131 
138  {
139  visible_settings.clear();
140 
141  for (const auto& item : *this->gs_config->GetConfigList()) {
142  bool no_hide = (item.flags & SCRIPTCONFIG_DEVELOPER) == 0;
143  if (no_hide || _settings_client.gui.ai_developer_tools) {
144  visible_settings.push_back(&item);
145  }
146  }
147 
148  this->vscroll->SetCount((int)this->visible_settings.size());
149  }
150 
151  void UpdateWidgetSize(int widget, Dimension* size, const Dimension& padding, Dimension* fill, Dimension* resize) override
152  {
153  switch (widget) {
154  case WID_GSC_SETTINGS:
155  this->line_height = std::max(SETTING_BUTTON_HEIGHT, FONT_HEIGHT_NORMAL) + padding.height;
156  resize->width = 1;
157  resize->height = this->line_height;
158  size->height = 5 * this->line_height;
159  break;
160 
161  case WID_GSC_GSLIST:
162  this->line_height = FONT_HEIGHT_NORMAL + padding.height;
163  size->height = 1 * this->line_height;
164  break;
165  }
166  }
167 
172  static bool IsEditable()
173  {
174  return _game_mode != GM_NORMAL || Game::GetInstance() != nullptr;
175  }
176 
177  void DrawWidget(const Rect& r, int widget) const override
178  {
179  switch (widget) {
180  case WID_GSC_GSLIST: {
181  StringID text = STR_AI_CONFIG_NONE;
182 
183  if (GameConfig::GetConfig()->GetInfo() != nullptr) {
184  SetDParamStr(0, GameConfig::GetConfig()->GetInfo()->GetName());
185  text = STR_JUST_RAW_STRING;
186  }
187 
188  /* There is only one slot, unlike with the GS GUI, so it should never be white */
189  DrawString(r.Shrink(WidgetDimensions::scaled.matrix), text, (IsEditable() ? TC_ORANGE : TC_SILVER));
190  break;
191  }
192  case WID_GSC_SETTINGS: {
193  ScriptConfig* config = this->gs_config;
194  VisibleSettingsList::const_iterator it = this->visible_settings.begin();
195  int i = 0;
196  for (; !this->vscroll->IsVisible(i); i++) it++;
197 
198  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
199  bool rtl = _current_text_dir == TD_RTL;
200  Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
201  Rect tr = ir.Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide, rtl);
202 
203  int y = r.top;
204  int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
205  int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
206  for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
207  const ScriptConfigItem& config_item = **it;
208  int current_value = config->GetSetting((config_item).name);
209  bool editable = this->IsEditableItem(config_item);
210 
211  StringID str;
212  TextColour colour;
213  uint idx = 0;
214  if (StrEmpty(config_item.description)) {
215  if (!strcmp(config_item.name, "start_date")) {
216  /* Build-in translation */
217  str = STR_AI_SETTINGS_START_DELAY;
218  colour = TC_LIGHT_BLUE;
219  } else {
220  str = STR_JUST_STRING;
221  colour = TC_ORANGE;
222  }
223  } else {
224  str = STR_AI_SETTINGS_SETTING;
225  colour = TC_LIGHT_BLUE;
226  SetDParamStr(idx++, config_item.description);
227  }
228 
229  if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
230  DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
231  SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
232  } else {
233  if (config_item.complete_labels) {
234  DrawDropDownButton(br.left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable);
235  } else {
236  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);
237  }
238  if (config_item.labels != nullptr && config_item.labels->Contains(current_value)) {
239  SetDParam(idx++, STR_JUST_RAW_STRING);
240  SetDParamStr(idx++, config_item.labels->Find(current_value)->second);
241  } else {
242  SetDParam(idx++, STR_JUST_INT);
243  SetDParam(idx++, current_value);
244  }
245  }
246 
247  DrawString(tr.left, tr.right, y + text_y_offset, str, colour);
248  y += this->line_height;
249  }
250  break;
251  }
252  }
253  }
254 
255  void OnPaint() override
256  {
257  if (this->closing_dropdown) {
258  this->closing_dropdown = false;
259  this->clicked_dropdown = false;
260  }
261  this->DrawWidgets();
262  }
263 
264  void OnClick(Point pt, int widget, int click_count) override
265  {
266  if (widget >= WID_GSC_TEXTFILE && widget < WID_GSC_TEXTFILE + TFT_END) {
267  if (GameConfig::GetConfig() == nullptr) return;
268 
269  ShowScriptTextfileWindow((TextfileType)(widget - WID_GSC_TEXTFILE), (CompanyID)OWNER_DEITY);
270  return;
271  }
272 
273  switch (widget) {
274  case WID_GSC_GSLIST: {
275  this->InvalidateData();
276  if (click_count > 1 && _game_mode != GM_NORMAL) ShowAIListWindow((CompanyID)OWNER_DEITY);
277  break;
278  }
279 
280  case WID_GSC_CHANGE: // choose other Game Script
282  break;
283 
284  case WID_GSC_CONTENT_DOWNLOAD:
285  if (!_network_available) {
286  ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
287  } else {
289  }
290  break;
291 
292  case WID_GSC_SETTINGS: {
293  Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix, RectPadding::zero);
294  int num = (pt.y - r.top) / this->line_height + this->vscroll->GetPosition();
295  if (num >= (int)this->visible_settings.size()) break;
296 
297  VisibleSettingsList::const_iterator it = this->visible_settings.begin();
298  for (int i = 0; i < num; i++) it++;
299  const ScriptConfigItem config_item = **it;
300  if (!this->IsEditableItem(config_item)) return;
301 
302  if (this->clicked_row != num) {
305  this->clicked_row = num;
306  this->clicked_dropdown = false;
307  }
308 
309  bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
310 
311  int x = pt.x - r.left;
312  if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;
313 
314  /* One of the arrows is clicked (or green/red rect in case of bool value) */
315  int old_val = this->gs_config->GetSetting(config_item.name);
316  if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
317  if (this->clicked_dropdown) {
318  /* unclick the dropdown */
320  this->clicked_dropdown = false;
321  this->closing_dropdown = false;
322  } else {
323  int rel_y = (pt.y - r.top) % this->line_height;
324 
325  Rect wi_rect;
326  wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
327  wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
328  wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
329  wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
330 
331  /* If the mouse is still held but dragged outside of the dropdown list, keep the dropdown open */
332  if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
333  this->clicked_dropdown = true;
334  this->closing_dropdown = false;
335 
336  DropDownList list;
337  for (int i = config_item.min_value; i <= config_item.max_value; i++) {
338  list.emplace_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false));
339  }
340 
341  ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE, true);
342  }
343  }
344  } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
345  int new_val = old_val;
346  if (bool_item) {
347  new_val = !new_val;
348  } else if (x >= SETTING_BUTTON_WIDTH / 2) {
349  /* Increase button clicked */
350  new_val += config_item.step_size;
351  if (new_val > config_item.max_value) new_val = config_item.max_value;
352  this->clicked_increase = true;
353  } else {
354  /* Decrease button clicked */
355  new_val -= config_item.step_size;
356  if (new_val < config_item.min_value) new_val = config_item.min_value;
357  this->clicked_increase = false;
358  }
359 
360  if (new_val != old_val) {
361  this->gs_config->SetSetting(config_item.name, new_val);
362  this->clicked_button = num;
363  this->timeout.SetInterval(150);
364  }
365  } else if (!bool_item && !config_item.complete_labels) {
366  /* Display a query box so users can enter a custom value. */
367  SetDParam(0, old_val);
368  ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, QSF_NONE);
369  }
370  this->SetDirty();
371  break;
372  }
373 
374  case WID_GSC_ACCEPT:
375  this->Close();
376  break;
377 
378  case WID_GSC_RESET:
379  this->gs_config->ResetEditableSettings(_game_mode == GM_MENU);
380  this->SetDirty();
381  break;
382  }
383  }
384 
385  void OnQueryTextFinished(char* str) override
386  {
387  if (StrEmpty(str)) return;
388  int32 value = atoi(str);
389  SetValue(value);
390  }
391 
392  void OnDropdownSelect(int widget, int index) override
393  {
394  assert(this->clicked_dropdown);
395  SetValue(index);
396  }
397 
398  void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
399  {
400  /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
401  * the same dropdown button was clicked again, and then not open the dropdown again.
402  * So, we only remember that it was closed, and process it on the next OnPaint, which is
403  * after OnClick. */
404  assert(this->clicked_dropdown);
405  this->closing_dropdown = true;
406  this->SetDirty();
407  }
408 
409  void OnResize() override
410  {
411  this->vscroll->SetCapacityFromWidget(this, WID_GSC_SETTINGS);
412  }
413 
414  void OnRealtimeTick(uint delta_ms) override
415  {
416  if (this->timeout.Elapsed(delta_ms)) {
417  this->clicked_button = -1;
418  this->SetDirty();
419  }
420  }
421 
427  void OnInvalidateData(int data = 0, bool gui_scope = true) override
428  {
429  if (!gui_scope) return;
430 
431  this->SetWidgetDisabledState(WID_GSC_CHANGE, (_game_mode == GM_NORMAL) || !IsEditable());
432 
433  for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
434  this->SetWidgetDisabledState(WID_GSC_TEXTFILE + tft, GameConfig::GetConfig()->GetTextfile(tft, (CompanyID)OWNER_DEITY) == nullptr);
435  }
436  this->RebuildVisibleSettings();
439  }
440 private:
441  bool IsEditableItem(const ScriptConfigItem &config_item) const
442  {
443  return _game_mode == GM_MENU
444  || _game_mode == GM_EDITOR
445  || (config_item.flags & SCRIPTCONFIG_INGAME) != 0
447  }
448 
449  void SetValue(int value)
450  {
451  VisibleSettingsList::const_iterator it = this->visible_settings.begin();
452  for (int i = 0; i < this->clicked_row; i++) it++;
453  const ScriptConfigItem config_item = **it;
454  if (_game_mode == GM_NORMAL && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
455  this->gs_config->SetSetting(config_item.name, value);
456  this->SetDirty();
457  }
458 };
459 
462 {
464  new GSConfigWindow();
465 }
GSConfigWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: game_gui.cpp:385
GSConfigWindow::OnDropdownClose
void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
A dropdown window associated to this window has been closed.
Definition: game_gui.cpp:398
IsInsideMM
static 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:230
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1210
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:22
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1143
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:319
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
ScriptConfigItem::step_size
int step_size
The step size in the gui.
Definition: script_config.hpp:46
_nested_gs_config_widgets
static const NWidgetPart _nested_gs_config_widgets[]
Widgets for the configure GS window.
Definition: game_gui.cpp:49
GSConfigWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: game_gui.cpp:427
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
ScriptConfigItem::labels
LabelMapping * labels
Text labels for the integer values.
Definition: script_config.hpp:48
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:99
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1775
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
DropDownListCharStringItem
List item containing a C char string.
Definition: dropdown_type.h:70
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:1126
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:57
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:717
GSConfigWindow::IsEditable
static bool IsEditable()
Can the GS config be edited?
Definition: game_gui.cpp:172
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:997
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:644
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:636
TFT_CHANGELOG
@ TFT_CHANGELOG
NewGRF 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:136
GSConfigWindow
Window to configure which GSs will start.
Definition: game_gui.cpp:97
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
SCRIPTCONFIG_BOOLEAN
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
Definition: script_config.hpp:28
ScriptConfigItem::min_value
int min_value
The minimal value this configuration setting can have.
Definition: script_config.hpp:39
GSConfigWindow::VisibleSettingsList
std::vector< const ScriptConfigItem * > VisibleSettingsList
typdef for a vector of script settings
Definition: game_gui.cpp:107
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:377
WindowDesc
High level window description.
Definition: window_gui.h:102
ScriptConfigItem::complete_labels
bool complete_labels
True if all values have a label.
Definition: script_config.hpp:49
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:469
CONTENT_TYPE_GAME
@ CONTENT_TYPE_GAME
The content consists of a game script.
Definition: tcp_content_type.h:26
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:116
GUISettings::ai_developer_tools
bool ai_developer_tools
activate AI/GS developer tools
Definition: settings_type.h:193
ScriptConfigItem::max_value
int max_value
The maximal value this configuration setting can have.
Definition: script_config.hpp:40
GUITimer
Definition: guitimer_func.h:13
DrawDropDownButton
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Definition: settings_gui.cpp:2570
ShowAIListWindow
void ShowAIListWindow(CompanyID slot)
Open the AI list window to chose an AI for the given company slot.
Definition: ai_gui.cpp:279
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
GSConfigWindow::RebuildVisibleSettings
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
Definition: game_gui.cpp:137
game_gui.hpp
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1008
WidgetDimensions::matrix
RectPadding matrix
Offsets within a matrix cell.
Definition: window_gui.h:49
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
SetMatrixDataTip
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1129
ScriptConfig::SetSetting
virtual void SetSetting(const char *name, int value)
Set the value of a setting for this config.
Definition: script_config.cpp:110
GSConfigWindow::UpdateWidgetSize
void UpdateWidgetSize(int 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:151
SCRIPTCONFIG_INGAME
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
Definition: script_config.hpp:29
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
SCRIPTCONFIG_DEVELOPER
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
Definition: script_config.hpp:30
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:1115
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:192
GSConfigWindow::timeout
GUITimer timeout
Timeout for unclicking the button.
Definition: game_gui.cpp:104
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:67
GSConfigWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: game_gui.cpp:255
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:179
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
WWT_FRAME
@ WWT_FRAME
Frame.
Definition: widget_type.h:58
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition: settings_gui.h:17
GSConfigWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: game_gui.cpp:414
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2539
GSConfigWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: game_gui.cpp:106
TFT_README
@ TFT_README
NewGRF readme.
Definition: textfile_type.h:17
ShowGSConfigWindow
void ShowGSConfigWindow()
Open the GS config window.
Definition: game_gui.cpp:461
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:3194
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
TFT_LICENSE
@ TFT_LICENSE
NewGRF license.
Definition: textfile_type.h:19
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
GSConfigWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: game_gui.cpp:392
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:606
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
GetTextfile
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
Definition: textfile_gui.cpp:414
GSConfigWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: game_gui.cpp:177
ScriptConfigItem::description
const char * description
The description of the configuration setting.
Definition: script_config.hpp:38
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1095
WC_AI_LIST
@ WC_AI_LIST
AI list; Window numbers:
Definition: window_type.h:277
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
ScriptConfig::GetSetting
virtual int GetSetting(const char *name) const
Get the value of a setting for this config.
Definition: script_config.cpp:103
Scrollbar::IsVisible
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:688
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1203
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1014
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:59
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
WN_GAME_OPTIONS_GS
@ WN_GAME_OPTIONS_GS
GS settings.
Definition: window_type.h:16
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:678
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:1791
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:24
CS_NUMERAL_SIGNED
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
Definition: string_type.h:30
GUITimer::Elapsed
bool Elapsed(uint delta)
Test if a timer has elapsed.
Definition: guitimer_func.h:55
GSConfigWindow::closing_dropdown
bool closing_dropdown
True, if the dropdown list is currently closing.
Definition: game_gui.cpp:103
SmallMap::Find
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
Definition: smallmap_type.hpp:41
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:358
GSConfigWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: game_gui.cpp:409
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2427
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1191
ScriptConfigItem::flags
ScriptConfigFlags flags
Flags for the configuration setting.
Definition: script_config.hpp:47
ShowScriptTextfileWindow
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the AI version of the textfile window.
Definition: ai_gui.cpp:665
GSConfigWindow::clicked_row
int clicked_row
The clicked row of settings.
Definition: game_gui.cpp:105
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1080
ScriptConfig::GetConfigList
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
Definition: script_config.cpp:76
GSConfigWindow::clicked_button
int clicked_button
The button we clicked.
Definition: game_gui.cpp:100
Window
Data structure for an opened window.
Definition: window_gui.h:213
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
GSConfigWindow::visible_settings
VisibleSettingsList visible_settings
List of visible GS settings.
Definition: game_gui.cpp:108
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
DrawBoolButton
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
Definition: settings_gui.cpp:2591
_network_available
bool _network_available
is network mode available?
Definition: network.cpp:60
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:79
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
GSConfigWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: game_gui.cpp:126
Game::GetInstance
static class GameInstance * GetInstance()
Get the current active instance.
Definition: game.hpp:106
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition: window_type.h:149
ScriptConfigItem
Info about a single Script setting.
Definition: script_config.hpp:36
ScriptConfigItem::name
const char * name
The name of the configuration setting.
Definition: script_config.hpp:37
_gs_config_desc
static WindowDesc _gs_config_desc(WDP_CENTER, "settings_gs_config", 500, 350, WC_GAME_OPTIONS, WC_NONE, 0, _nested_gs_config_widgets, lengthof(_nested_gs_config_widgets))
Window definition for the configure GS window.
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:91
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:102
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:49
GSConfigWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: game_gui.cpp:264
GSConfigWindow::clicked_increase
bool clicked_increase
Whether we clicked the increase or decrease button.
Definition: game_gui.cpp:101
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:297
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
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1107
GSConfigWindow::gs_config
ScriptConfig * gs_config
The configuration we're modifying.
Definition: game_gui.cpp:98
GSConfigWindow::line_height
int line_height
Height of a single GS-name line.
Definition: game_gui.cpp:99
SmallMap::Contains
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
Definition: smallmap_type.hpp:79