31#include "script_log.hpp"
43#include "table/strings.h"
84 this->vscroll->
SetCount(this->info_list->size() + 1);
87 if (GetConfig(this->slot)->HasScript()) {
88 ScriptInfo *info = GetConfig(this->slot)->GetInfo();
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);
115 fill.height =
resize.height = this->line_height;
116 size.height = 5 * this->line_height;
127 DrawString(tr, this->slot ==
OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
128 tr.top += this->line_height;
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);
135 tr.top += this->line_height;
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) {
171 GetConfig(this->slot)->Change(std::nullopt);
173 ScriptInfoList::const_iterator it = this->info_list->cbegin();
174 std::advance(it, this->selected);
175 GetConfig(this->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 <
static_cast<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);
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),
322 this->visible_settings.clear();
324 for (
const auto &item : *this->script_config->
GetConfigList()) {
327 this->visible_settings.push_back(&item);
331 this->vscroll->
SetCount(this->visible_settings.size());
338 return GetString((this->slot ==
OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
348 fill.height =
resize.height = this->line_height;
349 size.height = 5 * this->line_height;
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));
376 DrawDropDownButton(br.left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, editable);
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);
383 y += this->line_height;
389 if (this->closing_dropdown) {
390 this->closing_dropdown =
false;
391 this->clicked_dropdown =
false;
401 if (it == this->visible_settings.end())
break;
404 if (!this->IsEditableItem(config_item))
return;
406 int num = it - this->visible_settings.begin();
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;
490 if (!value.has_value())
return;
491 this->SetValue(*value);
497 assert(this->clicked_dropdown);
498 this->SetValue(index);
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);
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),
597struct ScriptTextfileWindow :
public TextfileWindow {
602 this->ConstructWindow();
609 return GetString(stringid, (this->slot ==
OWNER_DEITY) ? STR_CONTENT_TYPE_GAME_SCRIPT : STR_CONTENT_TYPE_AI, GetConfig(this->slot)->GetInfo()->GetName());
615 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
617 auto textfile = GetConfig(this->slot)->GetTextfile(
file_type, this->slot);
618 if (!textfile.has_value()) {
651 Colours colour = dead ? COLOUR_RED :
652 (paused ? COLOUR_YELLOW : COLOUR_GREY);
653 if (button.
colour != colour) {
675 CompanyID::Invalid(),
690 ScriptLogTypes::LogData &GetLogData()
const
704 return game ==
nullptr || game->
IsDead();
716 switch (company.base()) {
717 case CompanyID::Invalid().base():
return false;
753 this->filter = ScriptDebugWindow::initial_state;
769 if (show_company == CompanyID::Invalid()) {
788 ScriptDebugWindow::initial_state = this->filter;
814 assert(info !=
nullptr);
849 CompanyID cid =
static_cast<CompanyID
>(widget - start);
862 const ScriptLogTypes::LogData &log = this->GetLogData();
863 if (log.empty())
return;
871 tmp_dpi.left += fr.left;
872 tmp_dpi.top += fr.top;
879 for (
auto it = first; it != last; ++it) {
880 const ScriptLogTypes::LogLine &line = *it;
884 case ScriptLogTypes::LOG_SQ_INFO: colour = TC_BLACK;
break;
885 case ScriptLogTypes::LOG_SQ_ERROR: colour = TC_WHITE;
break;
886 case ScriptLogTypes::LOG_INFO: colour = TC_BLACK;
break;
887 case ScriptLogTypes::LOG_WARNING: colour = TC_YELLOW;
break;
888 case ScriptLogTypes::LOG_ERROR: colour = TC_RED;
break;
889 default: colour = TC_BLACK;
break;
893 if (std::distance(std::begin(log), it) == this->highlight_row) {
894 fr.bottom = fr.top + this->
resize.step_height - 1;
896 if (colour == TC_BLACK) colour = TC_WHITE;
900 fr.top += this->
resize.step_height;
912 ScriptLogTypes::LogData &log = this->GetLogData();
914 int scroll_count =
static_cast<int>(log.size());
915 if (this->vscroll->
GetCount() != scroll_count) {
916 this->vscroll->
SetCount(scroll_count);
922 if (log.empty())
return;
925 if (this->last_vscroll_pos != this->vscroll->
GetPosition()) {
926 this->autoscroll = this->vscroll->
GetPosition() + this->vscroll->
GetCapacity() >=
static_cast<int>(log.size());
929 if (this->autoscroll && this->vscroll->
SetPosition(
static_cast<int>(log.size()))) {
935 this->last_vscroll_pos = this->vscroll->
GetPosition();
944 for (CompanyID i = CompanyID::Begin(); i < MAX_COMPANIES; ++i) {
947 bool dead = valid &&
Company::Get(i)->ai_instance->IsDead();
948 bool paused = valid &&
Company::Get(i)->ai_instance->IsPaused();
963 bool valid = game !=
nullptr;
964 bool dead = valid && game->
IsDead();
965 bool paused = valid && game->
IsPaused();
983 ScriptDebugWindow::initial_state = this->filter;
990 this->highlight_row = -1;
997 this->autoscroll =
true;
998 this->last_vscroll_pos = this->vscroll->
GetPosition();
1053 all_unpaused =
false;
1064 this->highlight_row = -1;
1085 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1092 this->IsValidDebugCompany(this->filter.script_debug_company) &&
1093 this->filter.break_check_enabled && !this->break_string_filter.IsEmpty()) {
1095 ScriptLogTypes::LogData &log = this->GetLogData();
1099 this->break_string_filter.AddLine(log.back().text);
1100 if (this->break_string_filter.
GetState()) {
1116 this->highlight_row =
static_cast<int>(log.size() - 1);
1121 if (!gui_scope)
return;
1127 for (
auto &line : this->GetLogData()) {
1129 max_width = std::max(max_width, line.width);
1147 this->filter.script_debug_company ==
OWNER_DEITY ||
1172 static inline HotkeyList hotkeys{
"aidebug", {
1236 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),
1254 WDP_AUTO,
"script_debug", 600, 450,
1258 &ScriptDebugWindow::hotkeys
1302 ScriptDebugWindow::initial_state.script_debug_company = CompanyID::Invalid();
1312 if (c->is_ai && c->ai_instance->IsDead()) {
1319 if (g !=
nullptr && g->
IsDead()) {
Base functions for all AIs.
AIConfig stores the configuration settings of every AI.
AIInfo keeps track of all information of an AI, like Author, Description, ...
The AIInstance tracks an AI.
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.
void SetSetting(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 & 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.
Definition of stuff that is very close to a company, like the company struct itself.
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.
Command definitions related to companies.
GUI Functions related to companies.
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, DropDownOptions options)
Show a drop down list.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Functions related to errors.
@ 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.
Base functions for all Games.
GameConfig stores the configuration settings of every Game.
GameInfo keeps track of all information of an Game, like Author, Description, ...
The GameInstance tracks games.
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?
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.
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
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).
Hotkey related functions.
#define Point
Macro that prevents name conflicts between included headers.
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.
Miscellaneous command definitions.
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
Basic functions/variables used all over the place.
@ INVALID_CLIENT_ID
Client is not part of anything.
@ Normal
A game normally paused.
static constexpr PixelColour PC_BLACK
Black palette colour.
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
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.
static constexpr std::initializer_list< NWidgetPart > _nested_script_list_widgets
Widgets for the AI list window.
void ShowScriptDebugWindowIfScriptError()
Open the AI debug window if one of the AI scripts has crashed.
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 std::initializer_list< 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.
void ShowScriptTextfileWindow(Window *parent, TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
static constexpr std::initializer_list< NWidgetPart > _nested_script_settings_widgets
Widgets 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.
Window for configuring the scripts.
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.
Functions for setting GUIs.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
Searching and filtering using a stringterm.
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.
Functions related to OTTD's strings.
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...
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.
List of hotkeys for a window.
All data for a single hotkey.
static Pool::IterateWrapper< Company > Iterate(size_t from=0)
static Company * Get(auto index)
static bool IsValidID(auto index)
static Company * GetIfValid(auto index)
Data stored about a string that can be modified in the GUI.
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.
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.
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
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.
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.
Definition of Interval and OneShot timers.
Definition of the Window system.
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...
Window functions not directly related to making/drawing windows.
@ 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: