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 "../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 "../timer/timer.h"
26 #include "../timer/timer_window.h"
28 #include "script_gui.h"
29 #include "script_log.hpp"
32 #include "../ai/ai.hpp"
33 #include "../ai/ai_config.hpp"
34 #include "../ai/ai_info.hpp"
35 #include "../ai/ai_instance.hpp"
36 #include "../game/game.hpp"
37 #include "../game/game_config.hpp"
38 #include "../game/game_info.hpp"
39 #include "../game/game_instance.hpp"
40 #include "table/strings.h"
42 #include "../safeguards.h"
81 this->vscroll->
SetCount(this->info_list->size() + 1);
85 if (GetConfig(
slot)->HasScript()) {
88 for (
const auto &item : *this->info_list) {
89 if (item.second == info) {
99 void SetStringParameters(
WidgetID widget)
const override
103 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
117 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
125 DrawString(tr, this->slot ==
OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
128 StringID str = this->show_all ? STR_AI_CONFIG_NAME_VERSION : STR_JUST_RAW_STRING;
130 for (
const auto &item : *this->info_list) {
135 DrawString(tr, str, (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
144 for (
const auto &item : *this->info_list) {
146 if (this->selected == i - 1) selected_info =
static_cast<ScriptInfo *
>(item.second);
149 if (selected_info !=
nullptr) {
157 if (!selected_info->
GetURL().empty()) {
175 if (this->selected == -1) {
178 ScriptInfoList::const_iterator it = this->info_list->cbegin();
179 std::advance(it, this->selected);
180 GetConfig(
slot)->
Change(it->second->GetName(), it->second->GetVersion());
188 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
193 if (sel < (
int)this->info_list->size()) {
194 this->selected = sel;
196 if (click_count > 1) {
226 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
233 if (!gui_scope)
return;
235 this->vscroll->
SetCount(this->info_list->size() + 1);
238 this->selected = std::min(this->selected, this->vscroll->
GetCount() - 2);
250 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),
325 visible_settings.clear();
327 for (
const auto &item : *this->script_config->
GetConfigList()) {
334 this->vscroll->
SetCount(this->visible_settings.size());
337 void SetStringParameters(
WidgetID widget)
const override
341 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
355 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
369 for (
auto it = first; it != last; ++it) {
371 int current_value = this->script_config->
GetSetting(config_item.
name);
372 bool editable = this->IsEditableItem(config_item);
378 str = STR_JUST_STRING1;
381 str = STR_AI_SETTINGS_SETTING;
382 colour = TC_LIGHT_BLUE;
387 DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
388 SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
390 int i =
static_cast<int>(std::distance(std::begin(this->visible_settings), it));
394 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);
397 auto config_iterator = config_item.
labels.find(current_value);
398 if (config_iterator != config_item.
labels.end()) {
407 DrawString(tr.left, tr.right, y + text_y_offset, str, colour);
414 if (this->closing_dropdown) {
415 this->closing_dropdown =
false;
416 this->clicked_dropdown =
false;
421 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
426 if (it == this->visible_settings.end())
break;
429 if (!this->IsEditableItem(config_item))
return;
431 int num = it - this->visible_settings.begin();
432 if (this->clicked_row != num) {
435 this->clicked_row = num;
436 this->clicked_dropdown =
false;
442 int x = pt.x - r.left;
448 if (this->clicked_dropdown) {
451 this->clicked_dropdown =
false;
452 this->closing_dropdown =
false;
454 int rel_y = (pt.y - r.top) % this->line_height;
463 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
464 this->clicked_dropdown =
true;
465 this->closing_dropdown =
false;
469 list.push_back(MakeDropDownListStringItem(config_item.
labels.find(i)->second, i));
476 int new_val = old_val;
483 this->clicked_increase =
true;
488 this->clicked_increase =
false;
491 if (new_val != old_val) {
493 this->clicked_button = num;
516 void OnQueryTextFinished(std::optional<std::string> str)
override
518 if (!str.has_value() || str->empty())
return;
519 int32_t value = atoi(str->c_str());
524 void OnDropdownSelect(
WidgetID widget,
int index)
override
527 assert(this->clicked_dropdown);
538 assert(this->clicked_dropdown);
539 this->closing_dropdown =
true;
550 this->clicked_button = -1;
559 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
561 this->script_config = GetConfig(this->slot);
571 return _game_mode == GM_MENU
572 || _game_mode == GM_EDITOR
578 void SetValue(
int value)
595 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_SCRS_BACKGROUND),
SetMinimalSize(188, 182),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_SCRS_SCROLLBAR),
633 this->ConstructWindow();
637 void SetStringParameters(
WidgetID widget)
const override
645 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
648 if (!textfile.has_value()) {
680 Colours colour = dead ? COLOUR_RED :
681 (paused ? COLOUR_YELLOW : COLOUR_GREY);
682 if (button.
colour != colour) {
720 ScriptLogTypes::LogData &GetLogData()
const
734 return game ==
nullptr || game->
IsDead();
782 this->filter = ScriptDebugWindow::initial_state;
790 this->last_vscroll_pos = 0;
791 this->autoscroll =
true;
792 this->highlight_row = -1;
821 ScriptDebugWindow::initial_state = this->filter;
841 void SetStringParameters(
WidgetID widget)
const override
847 assert(info !=
nullptr);
848 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
855 assert(info !=
nullptr);
856 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
862 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
899 const ScriptLogTypes::LogData &log = this->GetLogData();
900 if (log.empty())
return;
908 tmp_dpi.left += fr.left;
909 tmp_dpi.top += fr.top;
916 for (
auto it = first; it != last; ++it) {
917 const ScriptLogTypes::LogLine &line = *it;
921 case ScriptLogTypes::LOG_SQ_INFO: colour = TC_BLACK;
break;
922 case ScriptLogTypes::LOG_SQ_ERROR: colour = TC_WHITE;
break;
923 case ScriptLogTypes::LOG_INFO: colour = TC_BLACK;
break;
924 case ScriptLogTypes::LOG_WARNING: colour = TC_YELLOW;
break;
925 case ScriptLogTypes::LOG_ERROR: colour = TC_RED;
break;
926 default: colour = TC_BLACK;
break;
930 if (std::distance(std::begin(log), it) == this->highlight_row) {
931 fr.bottom = fr.top + this->resize.step_height - 1;
933 if (colour == TC_BLACK) colour = TC_WHITE;
937 fr.top += this->resize.step_height;
949 ScriptLogTypes::LogData &log = this->GetLogData();
951 int scroll_count = (int)log.size();
952 if (this->vscroll->
GetCount() != scroll_count) {
953 this->vscroll->
SetCount(scroll_count);
959 if (log.empty())
return;
962 if (this->last_vscroll_pos != this->vscroll->
GetPosition()) {
966 if (this->autoscroll && this->vscroll->
SetPosition((
int)log.size())) {
972 this->last_vscroll_pos = this->vscroll->
GetPosition();
1000 bool valid = game !=
nullptr;
1020 ScriptDebugWindow::initial_state = this->filter;
1027 this->highlight_row = -1;
1034 this->autoscroll =
true;
1035 this->last_vscroll_pos = this->vscroll->
GetPosition();
1038 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1090 all_unpaused =
false;
1101 this->highlight_row = -1;
1107 void OnEditboxChanged(
WidgetID wid)
override
1122 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1129 this->IsValidDebugCompany(this->filter.script_debug_company) &&
1130 this->filter.break_check_enabled && !this->break_string_filter.IsEmpty()) {
1132 ScriptLogTypes::LogData &log = this->GetLogData();
1136 this->break_string_filter.
AddLine(log.back().text);
1137 if (this->break_string_filter.
GetState()) {
1153 this->highlight_row = (int)(log.size() - 1);
1158 if (!gui_scope)
return;
1164 for (
auto &line : this->GetLogData()) {
1166 max_width = std::max(max_width, line.width);
1184 this->filter.script_debug_company ==
OWNER_DEITY ||
1209 static inline HotkeyList hotkeys{
"aidebug", {
1273 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_SCRD_BREAK_STR_EDIT_BOX),
SetFill(1, 1),
SetResize(1, 0),
SetPadding(2, 2, 2, 2),
SetDataTip(STR_AI_DEBUG_BREAK_STR_OSKTITLE, STR_AI_DEBUG_BREAK_STR_TOOLTIP),
1291 WDP_AUTO,
"script_debug", 600, 450,
1295 &ScriptDebugWindow::hotkeys
1349 if (c->is_ai && c->ai_instance->IsDead()) {
1356 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 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.
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 class GameInstance * GetGameInstance()
Get the current GameScript instance.
static void Unpause()
Resume execution of the Game Script.
static bool IsPaused()
Checks if the Game Script is paused.
static class GameInstance * GetInstance()
Get 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 GameInfo * GetInfo()
Get the current GameInfo.
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 Change(std::optional< const std::string > 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.
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.
All static information from an Script like name, version, etc.
const std::string & GetAuthor() const
Get the Author of the script.
int GetVersion() const
Get the version of the script.
const std::string & GetName() const
Get the Name of the script.
const std::string & GetDescription() const
Get the description of the script.
const std::string & GetURL() const
Get the website for this 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.
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.
@ CCA_NEW_AI
Create a new AI company.
@ CCA_DELETE
Delete a company.
Owner
Enum for all companies/owners.
@ INVALID_COMPANY
An invalid company.
@ COMPANY_FIRST
First company, same as owner.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
@ MAX_COMPANIES
Maximum number of companies.
@ 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.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
@ 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.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
PauseMode _pause_mode
The current pause mode.
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.
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.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
@ SA_LEFT
Left align the text.
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
@ 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 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 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 _networking
are we in networking mode?
bool _network_server
network-server is active
@ INVALID_CLIENT_ID
Client is not part of anything.
uint8_t valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
@ PM_UNPAUSED
A normal unpaused game.
@ PM_PAUSED_NORMAL
A game normally paused.
static const uint8_t PC_BLACK
Black palette colour.
ScriptConfig stores the configuration settings of every Script.
@ 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 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.
static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
Set the widget colour of a button based on the state of the script.
static WindowDesc _script_list_desc(WDP_CENTER, "settings_script_list", 200, 234, WC_SCRIPT_LIST, WC_NONE, 0, _nested_script_list_widgets)
Window definition for the ai list window.
static constexpr NWidgetPart _nested_script_debug_widgets[]
Widgets for the Script debug window.
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
static WindowDesc _script_debug_desc(WDP_AUTO, "script_debug", 600, 450, WC_SCRIPT_DEBUG, WC_NONE, 0, _nested_script_debug_widgets, &ScriptDebugWindow::hotkeys)
Window definition for the Script debug window.
void ShowScriptSettingsWindow(CompanyID slot)
Open the Script settings window to change the Script settings for a Script.
Window * ShowScriptDebugWindow(CompanyID show_company, bool new_window)
Open the Script debug window and select the given company.
std::unique_ptr< NWidgetBase > MakeCompanyButtonRowsScriptDebug()
Make a number of rows with buttons for each company for the Script debug window.
static constexpr NWidgetPart _nested_script_settings_widgets[]
Widgets for the Script settings window.
static WindowDesc _script_settings_desc(WDP_CENTER, "settings_script", 500, 208, WC_SCRIPT_SETTINGS, WC_NONE, 0, _nested_script_settings_widgets)
Window definition for the Script settings 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 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)
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(size_t 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 Titem * Get(size_t index)
Returns Titem with given index.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
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.
Info about a single Script setting.
ScriptConfigFlags flags
Flags for the configuration setting.
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.
std::string description
The description of the configuration setting.
bool complete_labels
True if all values have a label.
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 OnInit() override
Notification that the nested widget tree gets initialized.
int redraw_timer
Timer for redrawing the window, otherwise it'll happen every tick.
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 INVALID_COMPANY.
int last_vscroll_pos
Last position of the scrolling.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
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 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.
void UpdateLogScroll()
Update the scrollbar and scroll position of the log panel.
StringFilter break_string_filter
Log filter for break.
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.
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.
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.
void ChangeScript()
Changes the Script of the current slot.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
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 OnDropdownClose(Point, WidgetID widget, int, bool) override
A dropdown window associated to this window has been closed.
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.
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
bool clicked_increase
Whether we clicked the increase or decrease button.
ScriptConfig * script_config
The configuration we're modifying.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
VisibleSettingsList visible_settings
List of visible AI settings.
bool closing_dropdown
True, if the dropdown list is currently closing.
Scrollbar * vscroll
Cache of the vertical scrollbar.
Window for displaying the textfile of a AI.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
CompanyID slot
View the textfile of this CompanyID slot.
void SetFilterTerm(const char *str)
Set the term to filter on.
void ResetState()
Reset the matching state to process a new item.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
bool GetState() const
Get the matching state of the current item.
void Assign(StringID string)
Render a string into the textbuffer.
char *const buf
buffer in which text is saved
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.
Iterable ensemble of all valid Windows.
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)
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
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.
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.
WindowNumber window_number
Window number within the window class.
TextfileType
Additional text files accompanying Tar archives.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
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.
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-...
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.
int32_t WindowNumber
Number to differentiate different windows of the same class.
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: