10 #include "../stdafx.h"
12 #include "../company_base.h"
13 #include "../window_func.h"
14 #include "../network/network.h"
15 #include "../settings_func.h"
16 #include "../network/network_content.h"
17 #include "../core/geometry_func.hpp"
23 #include "../script/script_gui.h"
24 #include "table/strings.h"
26 #include "../safeguards.h"
59 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIC_LIST),
SetMinimalSize(288, 112),
SetFill(1, 0),
SetMatrixDataTip(1, 8, STR_AI_CONFIG_AILIST_TOOLTIP),
SetScrollbar(
WID_AIC_SCROLLBAR),
111 void Close([[maybe_unused]]
int data = 0)
override
118 void SetStringParameters(
WidgetID widget)
const override
138 size =
maxdim(size, NWidgetScrollbar::GetHorizontalDimension());
156 if (_game_mode != GM_NORMAL) {
162 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
168 if (_game_mode == GM_NORMAL) {
170 if (c->is_ai) max_slot--;
182 text = STR_AI_CONFIG_HUMAN_PLAYER;
185 text = STR_JUST_RAW_STRING;
187 text = STR_AI_CONFIG_RANDOM_AI;
191 if (this->selected_slot == i) {
194 if (i < max_slot) tc = TC_ORANGE;
206 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
220 new_value = std::max(0,
GetGameSettings().difficulty.max_no_competitors - 1);
224 IConsoleSetSetting(
"difficulty.max_no_competitors", new_value);
237 IConsoleSetSetting(
"difficulty.competitors_interval", new_value);
252 this->selected_slot--;
261 this->selected_slot++;
269 if (this->selected_slot ==
INVALID_COMPANY || config ==
nullptr || config->GetInfo() ==
nullptr)
return;
270 OpenBrowser(config->GetInfo()->
GetURL());
297 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
303 if (!gui_scope)
return;
317 for (
TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
Base functions for all AIs.
AIConfig stores the configuration settings of every AI.
static WindowDesc _ai_config_desc(WDP_CENTER, nullptr, 0, 0, WC_GAME_OPTIONS, WC_NONE, 0, _nested_ai_config_widgets)
Window definition for the configure AI window.
void ShowAIConfigWindow()
Open the AI config window.
static constexpr NWidgetPart _nested_ai_config_widgets[]
Widgets for the configure AI window.
Window for configuring the AIs
AIInfo keeps track of all information of an AI, like Author, Description, ...
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
const std::string & GetURL() const
Get the website for this script.
static const uint MIN_COMPETITORS_INTERVAL
The minimum interval (in minutes) between competitors.
Owner
Enum for all companies/owners.
@ INVALID_COMPANY
An invalid company.
@ COMPANY_FIRST
First company, same as owner.
@ MAX_COMPANIES
Maximum number of companies.
static const uint MAX_COMPETITORS_INTERVAL
The maximum interval (in minutes) between competitors.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ WL_ERROR
Errors (eg. saving/loading failed)
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
bool _ctrl_pressed
Is Ctrl pressed?
@ FS_NORMAL
Index of the normal font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
constexpr void Swap(T &a, T &b)
Type safe swap operation.
bool _network_available
is network mode available?
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=CONTENT_TYPE_END, ContentType type2=CONTENT_TYPE_END)
Show the content list window with a given set of content.
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
void ShowScriptSettingsWindow(CompanyID slot)
Open the Script settings window to change the Script settings for a Script.
void ShowScriptListWindow(CompanyID slot, bool show_all)
Open the Script list window to chose a script for the given company slot.
GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
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)
Window to configure which AIs will start.
CompanyID selected_slot
The currently selected AI slot or INVALID_COMPANY.
static bool IsEditable(CompanyID slot)
Can the AI config in the given company slot be edited?
Scrollbar * vscroll
Cache of the vertical scrollbar.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
int line_height
Height of a single AI-name line.
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
uint8_t max_no_competitors
the number of competitors (AIs)
Dimensions (a width and height) of a rectangle in 2D.
DifficultySettings difficulty
settings related to the difficulty
Coordinates of a point in 2D.
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.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
High level window description.
Data structure for an opened window.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
ResizeInfo resize
Resize information.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
@ CONTENT_TYPE_AI
The content consists of an AI.
TextfileType
Additional text files accompanying Tar archives.
@ TFT_LICENSE
Content license.
@ TFT_README
Content readme.
@ TFT_CHANGELOG
Content changelog.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
@ WDP_CENTER
Center the window.
@ WN_GAME_OPTIONS_AI
AI settings.
@ 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: