12#include "../settings_gui.h"
13#include "../querystring_gui.h"
14#include "../window_func.h"
15#include "../network/network.h"
16#include "../network/network_content.h"
17#include "../dropdown_type.h"
18#include "../dropdown_func.h"
19#include "../timer/timer.h"
20#include "../timer/timer_window.h"
26#include "../script/script_gui.h"
27#include "../script_config.hpp"
28#include "../table/strings.h"
30#include "../safeguards.h"
43 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),
45 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),
47 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),
60 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),
127 visible_settings.clear();
136 this->vscroll->
SetCount(this->visible_settings.size());
191 for (
auto it = first; it !=
last; ++it) {
204 colour = TC_LIGHT_BLUE;
212 int i =
static_cast<int>(std::distance(std::begin(this->visible_settings), it));
239 if (this->closing_dropdown) {
240 this->closing_dropdown =
false;
241 this->clicked_dropdown =
false;
276 if (it == this->visible_settings.end())
break;
281 int num = it - this->visible_settings.begin();
282 if (this->clicked_row != num) {
285 this->clicked_row = num;
286 this->clicked_dropdown =
false;
292 int x =
pt.x - r.left;
298 if (this->clicked_dropdown) {
301 this->clicked_dropdown =
false;
302 this->closing_dropdown =
false;
304 int rel_y = (
pt.y - r.top) % this->line_height;
313 if (
pt.y >= wi_rect.top &&
pt.y <= wi_rect.bottom) {
314 this->clicked_dropdown =
true;
315 this->closing_dropdown =
false;
319 list.push_back(MakeDropDownListStringItem(
config_item.labels.find(i)->second, i));
333 this->clicked_increase =
true;
338 this->clicked_increase =
false;
343 this->clicked_button = num;
346 }
else if (!bool_item && !
config_item.complete_labels) {
357 if (
config ==
nullptr ||
config->GetInfo() ==
nullptr)
return;
358 OpenBrowser(
config->GetInfo()->GetURL());
371 if (!str.has_value() || str->empty())
return;
379 assert(this->clicked_dropdown);
390 assert(this->clicked_dropdown);
391 this->closing_dropdown =
true;
402 this->clicked_button = -1;
429 return _game_mode == GM_MENU
430 || _game_mode == GM_EDITOR
435 void SetValue(
int value)
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
static class GameInstance * GetInstance()
Get the current active instance.
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
void SetSetting(const std::string_view name, int value)
Set the value of a setting for this config.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
int GetSetting(const std::string &name) const
Get the value of a setting for this config.
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
const std::string & GetURL() const
Get the website for this script.
A timeout timer will fire once after the interval.
void Reset()
Reset the timer, so it will fire again after the timeout.
Owner
Enum for all companies/owners.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close, bool persist)
Show a drop down list.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ WL_ERROR
Errors (eg. saving/loading failed)
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Base functions for all Games.
GameConfig stores the configuration settings of every Game.
static constexpr NWidgetPart _nested_gs_config_widgets[]
Widgets for the configure GS window.
static WindowDesc _gs_config_desc(WDP_CENTER, "settings_gs_config", 500, 350, WC_GAME_OPTIONS, WC_NONE, 0, _nested_gs_config_widgets)
Window definition for the configure GS window.
void ShowGSConfigWindow()
Open the GS config window.
Window for configuring the Games
GameInfo keeps track of all information of an Game, like Author, Description, ...
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.
bool _ctrl_pressed
Is Ctrl pressed?
@ FS_NORMAL
Index of the normal font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
void ShowQueryString(StringID 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?
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.
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
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'.
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
void ShowScriptListWindow(CompanyID slot, bool show_all)
Open the Script list window to chose a script for the given company slot.
ClientSettings _settings_client
The current settings for this game.
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
TextDirection _current_text_dir
Text direction of the currently selected language.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
@ TD_RTL
Text is written right-to-left by default.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
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
Dimensions (a width and height) of a rectangle in 2D.
Window to configure which GSs will start.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void OnResize() override
Called after the window got resized.
void OnPaint() override
The window must be repainted.
VisibleSettingsList visible_settings
List of visible GS settings.
bool closing_dropdown
True, if the dropdown list is currently closing.
std::vector< const ScriptConfigItem * > VisibleSettingsList
typdef for a vector of script settings
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
int line_height
Height of a single GS-name line.
int clicked_button
The button we clicked.
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
Scrollbar * vscroll
Cache of the vertical scrollbar.
ScriptConfig * gs_config
The configuration we're modifying.
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
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.
bool clicked_increase
Whether we clicked the increase or decrease button.
static bool IsEditable()
Can the GS config be edited?
int clicked_row
The clicked row of settings.
bool clicked_dropdown
Whether the dropdown is open.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnDropdownClose(Point, WidgetID widget, int, bool) override
A dropdown window associated to this window has been closed.
bool ai_developer_tools
activate AI/GS developer tools
Coordinates of a point in 2D.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Info about a single Script setting.
std::string name
The name of the configuration setting.
High level window description.
Data structure for an opened window.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
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.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
@ CONTENT_TYPE_GAME
The content consists of a game script.
TextfileType
Additional text files accompanying Tar archives.
@ TFT_LICENSE
Content license.
@ TFT_README
Content readme.
@ TFT_CHANGELOG
Content changelog.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
@ WDP_CENTER
Center the window.
@ WN_GAME_OPTIONS_GS
GS settings.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
@ WC_GAME_OPTIONS
Game options window; Window numbers:
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
@ WC_QUERY_STRING
Query string window; Window numbers: