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 "../dropdown_type.h"
19#include "../dropdown_func.h"
20#include "../window_func.h"
21#include "../network/network.h"
22#include "../hotkeys.h"
23#include "../company_cmd.h"
24#include "../misc_cmd.h"
25#include "../strings_func.h"
26#include "../timer/timer.h"
27#include "../timer/timer_window.h"
28#include "../core/string_consumer.hpp"
30#include "script_gui.h"
31#include "script_log.hpp"
34#include "../ai/ai.hpp"
35#include "../ai/ai_config.hpp"
36#include "../ai/ai_info.hpp"
37#include "../ai/ai_instance.hpp"
38#include "../game/game.hpp"
39#include "../game/game_config.hpp"
40#include "../game/game_info.hpp"
41#include "../game/game_instance.hpp"
43#include "table/strings.h"
45#include "../safeguards.h"
84 this->vscroll->
SetCount(this->info_list->size() + 1);
87 if (GetConfig(
slot)->HasScript()) {
90 for (
const auto &item : *this->
info_list) {
91 if (item.second == info) {
105 return GetString(STR_AI_LIST_CAPTION, (this->slot ==
OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
127 DrawString(tr, this->slot ==
OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
131 for (
const auto &item : *this->
info_list) {
134 DrawString(tr, this->show_all ?
GetString(STR_AI_CONFIG_NAME_VERSION, item.second->GetName(), item.second->GetVersion()) : item.second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
143 for (
const auto &item : *this->
info_list) {
145 if (this->selected == i - 1) selected_info =
static_cast<ScriptInfo *
>(item.second);
148 if (selected_info !=
nullptr) {
154 if (!selected_info->
GetURL().empty()) {
170 if (this->selected == -1) {
173 ScriptInfoList::const_iterator it = this->info_list->cbegin();
174 std::advance(it, this->selected);
175 GetConfig(
slot)->
Change(it->second->GetName(), it->second->GetVersion());
177 if (_game_mode == GM_EDITOR) {
183 if (c !=
nullptr && c->ai_instance !=
nullptr) {
184 c->ai_instance.reset();
201 if (sel < (
int)this->info_list->size()) {
202 this->selected = sel;
204 if (click_count > 1) {
230 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
237 if (!gui_scope)
return;
239 this->vscroll->
SetCount(this->info_list->size() + 1);
242 this->selected = std::min(this->selected, this->vscroll->
GetCount() - 2);
230 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override {
…}
254 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_SCRL_LIST),
SetMinimalSize(188, 112),
SetFill(1, 1),
SetResize(1, 1),
SetMatrixDataTip(1, 0, STR_AI_LIST_TOOLTIP),
SetScrollbar(
WID_SCRL_SCROLLBAR),
324 for (
const auto &item : *this->script_config->
GetConfigList()) {
338 return GetString((this->slot ==
OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
366 for (
auto it = first; it != last; ++it) {
368 int current_value = this->script_config->
GetSetting(config_item.
name);
369 bool editable = this->IsEditableItem(config_item);
372 DrawBoolButton(br.left, y + button_y_offset, COLOUR_YELLOW, COLOUR_MAUVE, current_value != 0, editable);
374 int i =
static_cast<int>(std::distance(std::begin(this->
visible_settings), it));
378 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);
389 if (this->closing_dropdown) {
390 this->closing_dropdown =
false;
391 this->clicked_dropdown =
false;
404 if (!this->IsEditableItem(config_item))
return;
407 if (this->clicked_row != num) {
410 this->clicked_row = num;
411 this->clicked_dropdown =
false;
417 int x = pt.x - r.left;
423 if (this->clicked_dropdown) {
426 this->clicked_dropdown =
false;
427 this->closing_dropdown =
false;
429 int rel_y = (pt.y - r.top) % this->line_height;
438 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
439 this->clicked_dropdown =
true;
440 this->closing_dropdown =
false;
444 list.push_back(MakeDropDownListStringItem(
GetString(STR_JUST_RAW_STRING, config_item.
labels.find(i)->second), i));
451 int new_val = old_val;
458 this->clicked_increase =
true;
463 this->clicked_increase =
false;
466 if (new_val != old_val) {
468 this->clicked_button = num;
488 if (!str.has_value())
return;
489 auto value = ParseInteger<int32_t>(*str, 10,
true);
490 if (!value.has_value())
return;
497 assert(this->clicked_dropdown);
508 assert(this->clicked_dropdown);
509 this->closing_dropdown =
true;
520 this->clicked_button = -1;
529 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
531 this->script_config = GetConfig(this->slot);
529 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override {
…}
541 return _game_mode == GM_MENU
542 || _game_mode == GM_EDITOR
548 void SetValue(
int value)
565 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_SCRS_BACKGROUND),
SetMinimalSize(188, 182),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0),
SetScrollbar(
WID_SCRS_SCROLLBAR),
602 this->ConstructWindow();
615 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
618 if (!textfile.has_value()) {
615 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override {
…}
650 Colours colour = dead ? COLOUR_RED :
651 (paused ? COLOUR_YELLOW : COLOUR_GREY);
652 if (button.
colour != colour) {
674 CompanyID::Invalid(),
689 ScriptLogTypes::LogData &GetLogData()
const
703 return game ==
nullptr || game->
IsDead();
715 switch (company.base()) {
716 case CompanyID::Invalid().base():
return false;
751 this->filter = ScriptDebugWindow::initial_state;
767 if (show_company == CompanyID::Invalid()) {
786 ScriptDebugWindow::initial_state = this->filter;
812 assert(info !=
nullptr);
860 const ScriptLogTypes::LogData &log = this->GetLogData();
861 if (log.empty())
return;
869 tmp_dpi.left += fr.left;
870 tmp_dpi.top += fr.top;
877 for (
auto it = first; it != last; ++it) {
878 const ScriptLogTypes::LogLine &line = *it;
882 case ScriptLogTypes::LOG_SQ_INFO: colour = TC_BLACK;
break;
883 case ScriptLogTypes::LOG_SQ_ERROR: colour = TC_WHITE;
break;
884 case ScriptLogTypes::LOG_INFO: colour = TC_BLACK;
break;
885 case ScriptLogTypes::LOG_WARNING: colour = TC_YELLOW;
break;
886 case ScriptLogTypes::LOG_ERROR: colour = TC_RED;
break;
887 default: colour = TC_BLACK;
break;
891 if (std::distance(std::begin(log), it) == this->highlight_row) {
894 if (colour == TC_BLACK) colour = TC_WHITE;
910 ScriptLogTypes::LogData &log = this->GetLogData();
912 int scroll_count = (int)log.size();
913 if (this->vscroll->
GetCount() != scroll_count) {
914 this->vscroll->
SetCount(scroll_count);
920 if (log.empty())
return;
923 if (this->last_vscroll_pos != this->vscroll->
GetPosition()) {
927 if (this->autoscroll && this->vscroll->
SetPosition((
int)log.size())) {
933 this->last_vscroll_pos = this->vscroll->
GetPosition();
942 for (
CompanyID i = CompanyID::Begin(); i < MAX_COMPANIES; ++i) {
945 bool dead = valid &&
Company::Get(i)->ai_instance->IsDead();
946 bool paused = valid &&
Company::Get(i)->ai_instance->IsPaused();
961 bool valid = game !=
nullptr;
962 bool dead = valid && game->
IsDead();
963 bool paused = valid && game->
IsPaused();
981 ScriptDebugWindow::initial_state = this->filter;
988 this->highlight_row = -1;
995 this->autoscroll =
true;
996 this->last_vscroll_pos = this->vscroll->
GetPosition();
1051 all_unpaused =
false;
1062 this->highlight_row = -1;
1083 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1090 this->IsValidDebugCompany(this->filter.script_debug_company) &&
1091 this->filter.break_check_enabled && !this->break_string_filter.IsEmpty()) {
1093 ScriptLogTypes::LogData &log = this->GetLogData();
1114 this->highlight_row = (int)(log.size() - 1);
1119 if (!gui_scope)
return;
1125 for (
auto &line : this->GetLogData()) {
1127 max_width = std::max(max_width, line.width);
1145 this->filter.script_debug_company ==
OWNER_DEITY ||
1170 static inline HotkeyList hotkeys{
"aidebug", {
1234 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_SCRD_BREAK_STR_EDIT_BOX),
SetFill(1, 1),
SetResize(1, 0),
SetPadding(2, 2, 2, 2),
SetStringTip(STR_AI_DEBUG_BREAK_STR_OSKTITLE, STR_AI_DEBUG_BREAK_STR_TOOLTIP),
1252 WDP_AUTO,
"script_debug", 600, 450,
1256 &ScriptDebugWindow::hotkeys
1310 if (c->is_ai && c->ai_instance->IsDead()) {
1317 if (g !=
nullptr && g->
IsDead()) {
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
All static information from an AI like name, version, etc.
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
static void StartNew(CompanyID company)
Start a new AI company.
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
static void Unpause(CompanyID company)
Resume execution of the AI.
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
All static information from an Game like name, version, etc.
Runtime information about a game script like a pointer to the squirrel vm and the current state.
static void StartNew()
Start up a new GameScript.
static class GameInfo * GetInfo()
Get the current GameInfo.
static void Unpause()
Resume execution of the Game Script.
static bool IsPaused()
Checks if the Game Script is paused.
static void ResetInstance()
Reset the current active instance.
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for GameScanner::GetUniqueInfoList.
static void Pause()
Suspends the Game Script and then pause the execution of the script.
static class GameInstance * GetInstance()
Get the current active instance.
static const ScriptInfoList * GetInfoList()
Wrapper function for GameScanner::GetInfoList.
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
void SetSetting(std::string_view name, int value)
Set the value of a setting for this config.
void Change(std::optional< std::string_view > name, int version=-1, bool force_exact_match=false)
Set another Script to be loaded in this slot.
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
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.
All static information from an Script like name, version, etc.
const std::string & GetName() const
Get the Name of the script.
const std::string & GetAuthor() const
Get the Author of the script.
const std::string & GetURL() const
Get the website for this script.
int GetVersion() const
Get the version of the script.
const std::string & GetDescription() const
Get the description of the script.
bool IsPaused()
Checks if the script is paused.
ScriptLogTypes::LogData & GetLogData()
Get the log pointer of this script.
bool IsDead() const
Return the "this script died" value.
A timeout timer will fire once after the interval.
void Reset()
Reset the timer, so it will fire again after the timeout.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
@ CCA_NEW_AI
Create a new AI company.
@ CCA_DELETE
Delete a company.
@ CRR_NONE
Dummy reason for actions that don't need one.
@ CRR_MANUAL
The company is manually removed.
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_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
@ AI_DIR
Subdirectory for all AI files.
@ GAME_DIR
Subdirectory for all game scripts.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
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?
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
PauseModes _pause_mode
The current pause mode.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
@ FS_NORMAL
Index of the normal font in the font tables.
@ SA_LEFT
Left align the text.
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
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 IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
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 _networking
are we in networking mode?
bool _network_server
network-server is active
@ INVALID_CLIENT_ID
Client is not part of anything.
@ Normal
A game normally paused.
static const uint8_t PC_BLACK
Black palette colour.
ScriptConfig stores the configuration settings of every Script.
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 ShowScriptDebugWindowIfScriptError()
Open the AI debug window if one of the AI scripts has crashed.
static constexpr NWidgetPart _nested_script_list_widgets[]
Widgets for the AI list window.
Window * ShowScriptDebugWindow(CompanyID show_company, bool new_window)
Open the Script debug window and select the given company.
static WindowDesc _script_debug_desc(WDP_AUTO, "script_debug", 600, 450, WC_SCRIPT_DEBUG, WC_NONE, {}, _nested_script_debug_widgets, &ScriptDebugWindow::hotkeys)
Window definition for the Script debug window.
std::unique_ptr< NWidgetBase > MakeCompanyButtonRowsScriptDebug()
Make a number of rows with buttons for each company for the Script debug window.
static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
Set the widget colour of a button based on the state of the script.
static constexpr NWidgetPart _nested_script_debug_widgets[]
Widgets for the Script debug window.
static WindowDesc _script_list_desc(WDP_CENTER, "settings_script_list", 200, 234, WC_SCRIPT_LIST, WC_NONE, {}, _nested_script_list_widgets)
Window definition for the ai list window.
void ShowScriptSettingsWindow(CompanyID slot)
Open the Script settings window to change the Script settings for a Script.
static WindowDesc _script_settings_desc(WDP_CENTER, "settings_script", 500, 208, WC_SCRIPT_SETTINGS, WC_NONE, {}, _nested_script_settings_widgets)
Window definition for the Script settings window.
static constexpr NWidgetPart _nested_script_settings_widgets[]
Widgets for the Script settings window.
void ShowScriptTextfileWindow(Window *parent, 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.
void InitializeScriptGui()
Reset the Script windows to their initial state.
Declarations of the class for the script scanner.
std::map< std::string, class ScriptInfo *, CaseInsensitiveComparator > ScriptInfoList
Type for the list of scripts.
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 DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
Draw a toggle button.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown 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.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
GUISettings gui
settings related to the GUI
static bool IsValidAiID(auto index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Dimensions (a width and height) of a rectangle in 2D.
Data about how and where to blit pixels.
bool ai_developer_tools
activate AI/GS developer tools
List of hotkeys for a window.
All data for a single hotkey.
Coordinates of a point in 2D.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * Get(auto index)
Returns Titem with given index.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * GetIfValid(auto index)
Returns Titem with given index.
Data stored about a string that can be modified in the GUI.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
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.
uint step_height
Step-size of height resize changes.
Info about a single Script setting.
ScriptConfigFlags flags
Flags for the configuration setting.
std::string GetString(int value) const
Get string to display this setting in the configuration interface.
LabelMapping labels
Text labels for the integer values.
std::string name
The name of the configuration setting.
int min_value
The minimal value this configuration setting can have.
int max_value
The maximal value this configuration setting can have.
int step_size
The step size in the gui.
bool complete_labels
True if all values have a label.
TextColour GetColour() const
Get text colour to display this setting in the configuration interface.
bool break_check_enabled
Stop an AI when it prints a matching string.
bool case_sensitive_break_check
Is the matching done case-sensitive.
std::string break_string
The string to match to the AI output.
CompanyID script_debug_company
The AI that is (was last) being debugged.
Window with everything an AI prints via ScriptLog.
void UpdateAIButtonsState()
Update state of all Company (AI) buttons.
void DrawWidgetLog(const Rect &r) const
Draw the AI/GS log.
void UpdateGSButtonState()
Update state of game script button.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnInit() override
Notification that the nested widget tree gets initialized.
static EventState ScriptDebugGlobalHotkeys(int hotkey)
Handler for global hotkeys of the ScriptDebugWindow.
void SelectValidDebugCompany()
Ensure that script_debug_company refers to a valid AI company or GS, or is set to CompanyID::Invalid(...
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
int last_vscroll_pos
Last position of the scrolling.
void DrawWidgetCompanyButton(const Rect &r, WidgetID widget, int start) const
Draw a company button icon.
static const uint MAX_BREAK_STR_STRING_LENGTH
Maximum length of the break string.
QueryString break_editbox
Break editbox.
void OnPaint() override
The window must be repainted.
Scrollbar * hscroll
Cache of the horizontal scrollbar.
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.
void OnResize() override
Called after the window got resized.
int highlight_row
The output row that matches the given string, or -1.
ScriptDebugWindow(WindowDesc &desc, WindowNumber number, Owner show_company)
Constructor for the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void UpdateLogScroll()
Update the scrollbar and scroll position of the log panel.
StringFilter break_string_filter
Log filter for break.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
bool autoscroll
Whether automatically scrolling should be enabled or not.
bool IsDead() const
Check whether the currently selected AI/GS is dead.
bool IsValidDebugCompany(CompanyID company) const
Check whether a company is a valid AI company or GS.
void ChangeToScript(CompanyID show_script, bool new_window=false)
Change all settings to select another Script.
Scrollbar * vscroll
Cache of the vertical scrollbar.
bool show_break_box
Whether the break/debug box is visible.
Window that let you choose an available Script.
int line_height
Height of a row in the matrix widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
bool show_all
Whether to show all available versions.
void OnResize() override
Called after the window got resized.
CompanyID slot
The company we're selecting a new Script for.
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.
int selected
The currently selected Script.
Scrollbar * vscroll
Cache of the vertical scrollbar.
ScriptListWindow(WindowDesc &desc, CompanyID slot, bool show_all)
Constructor for the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void ChangeScript()
Changes the Script of the current slot.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
const ScriptInfoList * info_list
The list of Scripts.
Window for settings the parameters of an AI.
int clicked_row
The clicked row of settings.
void OnPaint() override
The window must be repainted.
std::vector< const ScriptConfigItem * > VisibleSettingsList
typdef for a vector of script settings
int clicked_button
The button we clicked.
void OnResize() override
Called after the window got resized.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
CompanyID slot
The currently show company's setting.
int line_height
Height of a row in the matrix widget.
ScriptSettingsWindow(WindowDesc &desc, CompanyID slot)
Constructor for the window.
bool clicked_dropdown
Whether the dropdown is open.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
bool clicked_increase
Whether we clicked the increase or decrease button.
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.
ScriptConfig * script_config
The configuration we're modifying.
VisibleSettingsList visible_settings
List of visible AI settings.
void OnDropdownClose(Point, WidgetID widget, int, int, bool) override
A dropdown window associated to this window has been closed.
bool closing_dropdown
True, if the dropdown list is currently closing.
Scrollbar * vscroll
Cache of the vertical scrollbar.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Window for displaying the textfile of a AI.
CompanyID slot
View the textfile of this CompanyID slot.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void SetFilterTerm(std::string_view str)
Set the term to filter on.
void ResetState()
Reset the matching state to process a new item.
bool GetState() const
Get the matching state of the current item.
std::string_view GetText() const
Get the current text.
void Assign(std::string_view text)
Copy a string into the textbuffer.
Window for displaying a textfile.
TextfileType file_type
Type of textfile to view.
virtual void LoadTextfile(const std::string &textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
High level window description.
Number to differentiate different windows of the same class.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
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.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
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)
Window * parent
Parent window.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
ResizeInfo resize
Resize information.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
WindowClass window_class
Window class.
void CloseChildWindowById(WindowClass wc, WindowNumber number) const
Close all children a window might have in a head-recursive manner.
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
AllWindows< false > Iterate
Iterate all windows in whatever order is easiest.
WindowNumber window_number
Window number within the window class.
TextfileType
Additional text files accompanying Tar archives.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
@ WDP_CENTER
Center the window.
@ WDP_AUTO
Find a place automatically.
@ WN_GAME_OPTIONS_GS
GS settings.
@ WN_GAME_OPTIONS_AI
AI settings.
EventState
State of handling an event.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_SCRIPT_SETTINGS
Script settings; Window numbers:
@ 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_SCRIPT_DEBUG
Script debug window; Window numbers:
@ WC_TEXTFILE
textfile; Window numbers:
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
@ WC_QUERY_STRING
Query string window; Window numbers: