Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../table/sprites.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"
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"
45 #include "../safeguards.h"
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),
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),
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),
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),
139 visible_settings.clear();
148 this->vscroll->
SetCount((
int)this->visible_settings.size());
154 case WID_GSC_SETTINGS:
180 case WID_GSC_GSLIST: {
185 text = STR_JUST_RAW_STRING;
192 case WID_GSC_SETTINGS: {
194 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
196 for (; !this->vscroll->
IsVisible(i); i++) it++;
208 int current_value = config->
GetSetting((config_item).name);
209 bool editable = this->IsEditableItem(config_item);
215 if (!strcmp(config_item.
name,
"start_date")) {
217 str = STR_AI_SETTINGS_START_DELAY;
218 colour = TC_LIGHT_BLUE;
220 str = STR_JUST_STRING;
224 str = STR_AI_SETTINGS_SETTING;
225 colour = TC_LIGHT_BLUE;
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);
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);
247 DrawString(tr.left, tr.right, y + text_y_offset, str, colour);
257 if (this->closing_dropdown) {
258 this->closing_dropdown =
false;
259 this->clicked_dropdown =
false;
266 if (widget >= WID_GSC_TEXTFILE && widget < WID_GSC_TEXTFILE + TFT_END) {
274 case WID_GSC_GSLIST: {
284 case WID_GSC_CONTENT_DOWNLOAD:
292 case WID_GSC_SETTINGS: {
294 int num = (pt.y - r.top) / this->line_height + this->vscroll->
GetPosition();
295 if (num >= (
int)this->visible_settings.size())
break;
297 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
298 for (
int i = 0; i < num; i++) it++;
300 if (!this->IsEditableItem(config_item))
return;
302 if (this->clicked_row != num) {
305 this->clicked_row = num;
306 this->clicked_dropdown =
false;
311 int x = pt.x - r.left;
317 if (this->clicked_dropdown) {
320 this->clicked_dropdown =
false;
321 this->closing_dropdown =
false;
323 int rel_y = (pt.y - r.top) % this->line_height;
332 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
333 this->clicked_dropdown =
true;
334 this->closing_dropdown =
false;
345 int new_val = old_val;
352 this->clicked_increase =
true;
357 this->clicked_increase =
false;
360 if (new_val != old_val) {
362 this->clicked_button = num;
363 this->timeout.SetInterval(150);
388 int32 value = atoi(str);
394 assert(this->clicked_dropdown);
404 assert(this->clicked_dropdown);
405 this->closing_dropdown =
true;
416 if (this->timeout.
Elapsed(delta_ms)) {
417 this->clicked_button = -1;
429 if (!gui_scope)
return;
433 for (
TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
443 return _game_mode == GM_MENU
444 || _game_mode == GM_EDITOR
449 void SetValue(
int value)
451 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
A dropdown window associated to this window has been closed.
static constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
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'.
Dimensions (a width and height) of a rectangle in 2D.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
int step_size
The step size in the gui.
static const NWidgetPart _nested_gs_config_widgets[]
Widgets for the configure GS window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
LabelMapping * labels
Text labels for the integer values.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
List item containing a C char string.
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=CONTENT_TYPE_END, ContentType type2=CONTENT_TYPE_END)
Show the content list window with a given set of content.
static bool IsEditable()
Can the GS config be edited?
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
ClientSettings _settings_client
The current settings for this game.
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.
Owner
Enum for all companies/owners.
@ TFT_CHANGELOG
NewGRF changelog.
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
Window to configure which GSs will start.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
int min_value
The minimal value this configuration setting can have.
std::vector< const ScriptConfigItem * > VisibleSettingsList
typdef for a vector of script settings
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.
High level window description.
bool complete_labels
True if all values have a label.
@ CONTENT_TYPE_GAME
The content consists of a game script.
@ WC_QUERY_STRING
Query string window; Window numbers:
bool ai_developer_tools
activate AI/GS developer tools
int max_value
The maximal value this configuration setting can have.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
void ShowAIListWindow(CompanyID slot)
Open the AI list window to chose an AI for the given company slot.
ResizeInfo resize
Resize information.
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
virtual void SetSetting(const char *name, int value)
Set the value of a setting for this config.
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.
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
GUITimer timeout
Timeout for unclicking the button.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
void OnPaint() override
The window must be repainted.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Coordinates of a point in 2D.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Scrollbar * vscroll
Cache of the vertical scrollbar.
@ TFT_README
NewGRF readme.
void ShowGSConfigWindow()
Open the GS config window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ TFT_LICENSE
NewGRF license.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
@ WC_GAME_OPTIONS
Game options window; Window numbers:
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
const char * description
The description of the configuration setting.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
@ WC_AI_LIST
AI list; Window numbers:
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
virtual int GetSetting(const char *name) const
Get the value of a setting for this config.
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
@ WN_GAME_OPTIONS_GS
GS settings.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
@ WL_ERROR
Errors (eg. saving/loading failed)
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
bool Elapsed(uint delta)
Test if a timer has elapsed.
bool closing_dropdown
True, if the dropdown list is currently closing.
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
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.
void OnResize() override
Called after the window got resized.
#define lengthof(x)
Return the length of an fixed size array.
ScriptConfigFlags flags
Flags for the configuration setting.
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the AI version of the textfile window.
int clicked_row
The clicked row of settings.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
int clicked_button
The button we clicked.
Data structure for an opened window.
TextfileType
Additional text files accompanying Tar archives.
VisibleSettingsList visible_settings
List of visible GS settings.
void DrawWidgets() const
Paint all widgets of a window.
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
bool _network_available
is network mode available?
int Width() const
Get width of Rect.
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
static class GameInstance * GetInstance()
Get the current active instance.
Specification of a rectangle with absolute coordinates of all edges.
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Info about a single Script setting.
const char * name
The name of the configuration setting.
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
Center the window.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
bool clicked_dropdown
Whether the dropdown is open.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
bool clicked_increase
Whether we clicked the increase or decrease button.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
GUISettings gui
settings related to the GUI
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
ScriptConfig * gs_config
The configuration we're modifying.
int line_height
Height of a single GS-name line.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.