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),
SetStringTip(STR_AI_CONFIG_GAMESCRIPT_PARAM),
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),
SetScrollbar(
WID_GSC_SCROLLBAR),
60 NWidget(
WWT_PUSHTXTBTN, COLOUR_YELLOW,
WID_GSC_TEXTFILE +
TFT_README),
SetFill(1, 1),
SetResize(1, 0),
SetMinimalSize(93, 0),
SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
191 for (
auto it = first; it !=
last; ++it) {
199 int i =
static_cast<int>(std::distance(std::begin(this->
visible_settings), it));
217 if (this->closing_dropdown) {
218 this->closing_dropdown =
false;
219 this->clicked_dropdown =
false;
260 if (this->clicked_row != num) {
263 this->clicked_row = num;
264 this->clicked_dropdown =
false;
270 int x =
pt.x - r.left;
276 if (this->clicked_dropdown) {
279 this->clicked_dropdown =
false;
280 this->closing_dropdown =
false;
282 int rel_y = (
pt.y - r.top) % this->line_height;
291 if (
pt.y >= wi_rect.top &&
pt.y <= wi_rect.bottom) {
292 this->clicked_dropdown =
true;
293 this->closing_dropdown =
false;
311 this->clicked_increase =
true;
316 this->clicked_increase =
false;
321 this->clicked_button = num;
324 }
else if (!bool_item && !
config_item.complete_labels) {
334 if (
config ==
nullptr ||
config->GetInfo() ==
nullptr)
return;
335 OpenBrowser(
config->GetInfo()->GetURL());
348 if (!str.has_value() || str->empty())
return;
356 assert(this->clicked_dropdown);
367 assert(this->clicked_dropdown);
368 this->closing_dropdown =
true;
379 this->clicked_button = -1;
406 return _game_mode == GM_MENU
407 || _game_mode == GM_EDITOR
412 void SetValue(
int value)
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
All static information from an Game like name, version, etc.
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.
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, 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.
@ WL_ERROR
Errors (eg. saving/loading failed)
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, const CommandCost &cc)
Display an error message in a window.
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.
void ShowGSConfigWindow()
Open the GS config window.
static WindowDesc _gs_config_desc(WDP_CENTER, "settings_gs_config", 500, 350, WC_GAME_OPTIONS, WC_NONE, {}, _nested_gs_config_widgets)
Window definition for the configure GS 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.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
bool _network_available
is network mode available?
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 const int INT32_DIGITS_WITH_SIGN_AND_TERMINATION
Maximum of 10 digits for MIN / MAX_INT32, 1 for the sign and 1 for '\0'.
@ Boolean
This value is a boolean (either 0 (false) or 1 (true) ).
@ Developer
This setting will only be visible when the Script development tools are active.
@ InGame
This setting can be changed while the Script is running.
void ShowScriptTextfileWindow(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.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
@ TD_RTL
Text is written right-to-left by default.
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.
std::string GetText() const
Get text to display for game script name.
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.
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: