OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
10 #include "../stdafx.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 "../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),
114 void Close([[maybe_unused]]
int data = 0)
override
127 visible_settings.clear();
136 this->vscroll->
SetCount(this->visible_settings.size());
165 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
173 text = STR_JUST_RAW_STRING;
191 for (
auto it = first; it != last; ++it) {
193 int current_value = this->gs_config->
GetSetting(config_item.
name);
194 bool editable = this->IsEditableItem(config_item);
200 str = STR_JUST_STRING1;
203 str = STR_AI_SETTINGS_SETTING;
204 colour = TC_LIGHT_BLUE;
209 DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
210 SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
212 int i =
static_cast<int>(std::distance(std::begin(this->visible_settings), it));
216 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);
219 auto config_iterator = config_item.
labels.find(current_value);
220 if (config_iterator != config_item.
labels.end()) {
229 DrawString(tr.left, tr.right, y + text_y_offset, str, colour);
239 if (this->closing_dropdown) {
240 this->closing_dropdown =
false;
241 this->clicked_dropdown =
false;
246 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
276 if (it == this->visible_settings.end())
break;
279 if (!this->IsEditableItem(config_item))
return;
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));
326 int new_val = old_val;
333 this->clicked_increase =
true;
338 this->clicked_increase =
false;
341 if (new_val != old_val) {
343 this->clicked_button = num;
357 if (config ==
nullptr || config->GetInfo() ==
nullptr)
return;
358 OpenBrowser(config->GetInfo()->
GetURL());
369 void OnQueryTextFinished(std::optional<std::string> str)
override
371 if (!str.has_value() || str->empty())
return;
372 int32_t value = atoi(str->c_str());
376 void OnDropdownSelect(
WidgetID widget,
int index)
override
379 assert(this->clicked_dropdown);
390 assert(this->clicked_dropdown);
391 this->closing_dropdown =
true;
402 this->clicked_button = -1;
411 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
413 if (!gui_scope)
return;
419 for (
TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
429 return _game_mode == GM_MENU
430 || _game_mode == GM_EDITOR
435 void SetValue(
int value)
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
std::vector< const ScriptConfigItem * > VisibleSettingsList
typdef for a vector of script settings
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
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.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
int step_size
The step size in the gui.
void ShowScriptListWindow(CompanyID slot, bool show_all)
Open the Script list window to chose a script for the given company slot.
std::string name
The name of the configuration setting.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Owner
Enum for all companies/owners.
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.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
static bool IsEditable()
Can the GS config be edited?
bool _ctrl_pressed
Is Ctrl pressed?
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.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
@ TFT_CHANGELOG
Content changelog.
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
void OnDropdownClose(Point, WidgetID widget, int, bool) override
A dropdown window associated to this window has been closed.
Window to configure which GSs will start.
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
int min_value
The minimal value this configuration setting can have.
High level window description.
void Reset()
Reset the timer, so it will fire again after the timeout.
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.
ResizeInfo resize
Resize information.
@ FS_NORMAL
Index of the normal font in the font tables.
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
const std::string & GetURL() const
Get the website for this script.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
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.
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
@ 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.
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.
Scrollbar * vscroll
Cache of the vertical scrollbar.
@ TFT_README
Content 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.
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 SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
@ TFT_LICENSE
Content license.
@ WC_GAME_OPTIONS
Game options window; Window numbers:
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
@ WN_GAME_OPTIONS_GS
GS settings.
int GetSetting(const std::string &name) const
Get the value of a setting for this config.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
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)
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
bool closing_dropdown
True, if the dropdown list is currently closing.
void OnResize() override
Called after the window got resized.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
std::string description
The description of the configuration setting.
ScriptConfigFlags flags
Flags for the configuration setting.
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.
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.
LabelMapping labels
Text labels for the integer values.
VisibleSettingsList visible_settings
List of visible GS settings.
void DrawWidgets() const
Paint all widgets of a window.
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the Script version of the textfile 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.
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
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.
void SetSetting(const std::string_view name, int value)
Set the value of a setting for this config.
@ 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.
static constexpr NWidgetPart _nested_gs_config_widgets[]
Widgets for the configure GS window.
bool clicked_increase
Whether we clicked the increase or decrease button.
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
ScriptConfig * gs_config
The configuration we're modifying.
int line_height
Height of a single GS-name line.