OpenTTD Source: src/ai/ai_gui.cpp Source File

OpenTTD Source 14.0-beta1

ai_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "../stdafx.h"
11 #include "../error.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"
18
19 #include "ai.hpp"
20 #include "ai_gui.hpp"
21 #include "ai_config.hpp"
22 #include "ai_info.hpp"
23 #include "../script/script_gui.h"
24 #include "table/strings.h"
25
26 #include "../safeguards.h"
27
28
30 static constexpr NWidgetPart _nested_ai_config_widgets[] = {
31 NWidget(NWID_HORIZONTAL),
32 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
33 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_CAPTION_AI, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
34 EndContainer(),
35 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_AIC_BACKGROUND),
36 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.sparse),
37 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
38 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
39 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
40 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_DECREASE_NUMBER), SetDataTip(AWV_DECREASE, STR_NULL),
41 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_INCREASE_NUMBER), SetDataTip(AWV_INCREASE, STR_NULL),
42 EndContainer(),
43 NWidget(WWT_TEXT, COLOUR_MAUVE, WID_AIC_NUMBER), SetDataTip(STR_AI_CONFIG_MAX_COMPETITORS, STR_NULL), SetFill(1, 0),
44 EndContainer(),
45 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
46 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
47 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_DECREASE_INTERVAL), SetDataTip(AWV_DECREASE, STR_NULL),
48 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_INCREASE_INTERVAL), SetDataTip(AWV_INCREASE, STR_NULL),
49 EndContainer(),
50 NWidget(WWT_TEXT, COLOUR_MAUVE, WID_AIC_INTERVAL), SetDataTip(STR_AI_CONFIG_COMPETITORS_INTERVAL, STR_NULL), SetFill(1, 0),
51 EndContainer(),
52 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
53 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_MOVE_UP), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_CONFIG_MOVE_UP, STR_AI_CONFIG_MOVE_UP_TOOLTIP),
54 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_MOVE_DOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_CONFIG_MOVE_DOWN, STR_AI_CONFIG_MOVE_DOWN_TOOLTIP),
55 EndContainer(),
56 EndContainer(),
57 NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_AI, STR_NULL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
58 NWidget(NWID_HORIZONTAL),
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),
60 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIC_SCROLLBAR),
61 EndContainer(),
62 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONFIGURE), SetFill(1, 0), SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP),
63 EndContainer(),
64 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
65 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
66 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CHANGE), SetFill(1, 1), SetDataTip(STR_AI_CONFIG_CHANGE_AI, STR_AI_CONFIG_CHANGE_TOOLTIP),
67 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONTENT_DOWNLOAD), SetFill(1, 1), SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
68 EndContainer(),
69 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
70 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
71 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
72 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_README), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
73 EndContainer(),
74 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
75 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
76 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_LICENSE), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
77 EndContainer(),
78 EndContainer(),
79 EndContainer(),
80 EndContainer(),
81 EndContainer(),
82 };
83
85 static WindowDesc _ai_config_desc(__FILE__, __LINE__,
86 WDP_CENTER, nullptr, 0, 0,
87 WC_GAME_OPTIONS, WC_NONE,
88 0,
89 std::begin(_nested_ai_config_widgets), std::end(_nested_ai_config_widgets)
90 );
91
95 struct AIConfigWindow : public Window {
96 CompanyID selected_slot;
97 int line_height;
98 Scrollbar *vscroll;
99
100 AIConfigWindow() : Window(&_ai_config_desc)
101 {
102 this->InitNested(WN_GAME_OPTIONS_AI); // Initializes 'this->line_height' as a side effect.
103 this->vscroll = this->GetScrollbar(WID_AIC_SCROLLBAR);
104 this->selected_slot = INVALID_COMPANY;
105 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_AIC_LIST);
106 this->vscroll->SetCapacity(nwi->current_y / this->line_height);
107 this->vscroll->SetCount(MAX_COMPANIES);
108 this->OnInvalidateData(0);
109 }
110
111 void Close([[maybe_unused]] int data = 0) override
112 {
113 CloseWindowByClass(WC_SCRIPT_LIST);
114 CloseWindowByClass(WC_SCRIPT_SETTINGS);
115 this->Window::Close();
116 }
117
118 void SetStringParameters(WidgetID widget) const override
119 {
120 switch (widget) {
121 case WID_AIC_NUMBER:
122 SetDParam(0, GetGameSettings().difficulty.max_no_competitors);
123 break;
124
125 case WID_AIC_INTERVAL:
126 SetDParam(0, GetGameSettings().difficulty.competitors_interval);
127 break;
128 }
129 }
130
131 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
132 {
133 switch (widget) {
134 case WID_AIC_DECREASE_NUMBER:
135 case WID_AIC_INCREASE_NUMBER:
136 case WID_AIC_DECREASE_INTERVAL:
137 case WID_AIC_INCREASE_INTERVAL:
138 *size = maxdim(*size, NWidgetScrollbar::GetHorizontalDimension());
139 break;
140
141 case WID_AIC_LIST:
142 this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
143 resize->height = this->line_height;
144 size->height = 8 * this->line_height;
145 break;
146 }
147 }
148
154 static bool IsEditable(CompanyID slot)
155 {
156 if (_game_mode != GM_NORMAL) {
157 return slot > 0 && slot < MAX_COMPANIES;
158 }
159 return slot < MAX_COMPANIES && !Company::IsValidID(slot);
160 }
161
162 void DrawWidget(const Rect &r, WidgetID widget) const override
163 {
164 switch (widget) {
165 case WID_AIC_LIST: {
166 Rect tr = r.Shrink(WidgetDimensions::scaled.matrix);
167 for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
168 StringID text;
169
170 if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
171 text = STR_AI_CONFIG_HUMAN_PLAYER;
172 } else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != nullptr) {
173 SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
174 text = STR_JUST_RAW_STRING;
175 } else {
176 text = STR_AI_CONFIG_RANDOM_AI;
177 }
178
179 TextColour tc = TC_SILVER;
180 if (this->selected_slot == i) {
181 tc = TC_WHITE;
182 } else if (IsEditable((CompanyID)i)) {
183 int max_slot = GetGameSettings().difficulty.max_no_competitors;
184 for (const Company *c : Company::Iterate()) {
185 if (c->is_ai) max_slot--;
186 }
187 for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
188 if (Company::IsValidHumanID(cid)) max_slot++;
189 }
190 if (i < max_slot) tc = TC_ORANGE;
191 } else if (Company::IsValidAiID(i)) {
192 tc = TC_GREEN;
193 }
194 DrawString(tr, text, tc);
195 tr.top += this->line_height;
196 }
197 break;
198 }
199 }
200 }
201
202 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
203 {
204 if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_CONTENT_END) {
205 if (this->selected_slot == INVALID_COMPANY || AIConfig::GetConfig(this->selected_slot) == nullptr) return;
206
207 ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
208 return;
209 }
210
211 switch (widget) {
212 case WID_AIC_DECREASE_NUMBER:
213 case WID_AIC_INCREASE_NUMBER: {
214 int new_value;
215 if (widget == WID_AIC_DECREASE_NUMBER) {
216 new_value = std::max(0, GetGameSettings().difficulty.max_no_competitors - 1);
217 } else {
218 new_value = std::min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
219 }
220 IConsoleSetSetting("difficulty.max_no_competitors", new_value);
221 this->InvalidateData();
222 break;
223 }
224
225 case WID_AIC_DECREASE_INTERVAL:
226 case WID_AIC_INCREASE_INTERVAL: {
227 int new_value;
228 if (widget == WID_AIC_DECREASE_INTERVAL) {
229 new_value = std::max(static_cast<int>(MIN_COMPETITORS_INTERVAL), GetGameSettings().difficulty.competitors_interval - 1);
230 } else {
231 new_value = std::min(static_cast<int>(MAX_COMPETITORS_INTERVAL), GetGameSettings().difficulty.competitors_interval + 1);
232 }
233 IConsoleSetSetting("difficulty.competitors_interval", new_value);
234 this->InvalidateData();
235 break;
236 }
237
238 case WID_AIC_LIST: { // Select a slot
239 this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget);
240 this->InvalidateData();
241 if (click_count > 1 && IsEditable(this->selected_slot)) ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed);
242 break;
243 }
244
245 case WID_AIC_MOVE_UP:
246 if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
247 Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
248 this->selected_slot--;
249 this->vscroll->ScrollTowards(this->selected_slot);
250 this->InvalidateData();
251 }
252 break;
253
254 case WID_AIC_MOVE_DOWN:
255 if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) {
256 Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
257 this->selected_slot++;
258 this->vscroll->ScrollTowards(this->selected_slot);
259 this->InvalidateData();
260 }
261 break;
262
263 case WID_AIC_OPEN_URL: {
264 const AIConfig *config = AIConfig::GetConfig(this->selected_slot);
265 if (this->selected_slot == INVALID_COMPANY || config == nullptr || config->GetInfo() == nullptr) return;
266 OpenBrowser(config->GetInfo()->GetURL());
267 break;
268 }
269
270 case WID_AIC_CHANGE: // choose other AI
271 if (IsEditable(this->selected_slot)) ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed);
272 break;
273
274 case WID_AIC_CONFIGURE: // change the settings for an AI
275 ShowScriptSettingsWindow((CompanyID)this->selected_slot);
276 break;
277
278 case WID_AIC_CONTENT_DOWNLOAD:
279 if (!_network_available) {
280 ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
281 } else {
282 ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_AI);
283 }
284 break;
285 }
286 }
287
293 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
294 {
295 if (!IsEditable(this->selected_slot) && !Company::IsValidAiID(this->selected_slot)) {
296 this->selected_slot = INVALID_COMPANY;
297 }
298
299 if (!gui_scope) return;
300
301 AIConfig *config = this->selected_slot == INVALID_COMPANY ? nullptr : AIConfig::GetConfig(this->selected_slot);
302
303 this->SetWidgetDisabledState(WID_AIC_DECREASE_NUMBER, GetGameSettings().difficulty.max_no_competitors == 0);
304 this->SetWidgetDisabledState(WID_AIC_INCREASE_NUMBER, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
305 this->SetWidgetDisabledState(WID_AIC_DECREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MIN_COMPETITORS_INTERVAL);
306 this->SetWidgetDisabledState(WID_AIC_INCREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MAX_COMPETITORS_INTERVAL);
307 this->SetWidgetDisabledState(WID_AIC_CHANGE, !IsEditable(this->selected_slot));
308 this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || config->GetConfigList()->empty());
309 this->SetWidgetDisabledState(WID_AIC_MOVE_UP, !IsEditable(this->selected_slot) || !IsEditable((CompanyID)(this->selected_slot - 1)));
310 this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, !IsEditable(this->selected_slot) || !IsEditable((CompanyID)(this->selected_slot + 1)));
311
312 this->SetWidgetDisabledState(WID_AIC_OPEN_URL, this->selected_slot == INVALID_COMPANY || config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty());
313 for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
314 this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || !config->GetTextfile(tft, this->selected_slot).has_value());
315 }
316 }
317 };
318
320 void ShowAIConfigWindow()
321 {
322 CloseWindowByClass(WC_GAME_OPTIONS);
323 new AIConfigWindow();
324 }
325
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition: window.cpp:1153
WID_AIC_OPEN_URL
@ WID_AIC_OPEN_URL
Open AI URL.
Definition: ai_widget.h:30
AIConfig
Definition: ai_config.hpp:16
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
Swap
constexpr void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:283
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
WID_AIC_CONTENT_DOWNLOAD
@ WID_AIC_CONTENT_DOWNLOAD
Download content button.
Definition: ai_widget.h:32
ShowScriptListWindow
void ShowScriptListWindow(CompanyID slot, bool show_all)
Open the Script list window to chose a script for the given company slot.
Definition: script_gui.cpp:276
Scrollbar::ScrollTowards
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:821
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
ShowNetworkContentListWindow
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.
Definition: network_content_gui.cpp:1130
WID_AIC_DECREASE_NUMBER
@ WID_AIC_DECREASE_NUMBER
Decrease the number of AIs.
Definition: ai_widget.h:18
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:618
ai_gui.hpp
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1174
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
WID_AIC_TEXTFILE
@ WID_AIC_TEXTFILE
Open AI readme, changelog (+1) or license (+2).
Definition: ai_widget.h:31
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
Company::IsValidHumanID
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
Definition: company_base.h:150
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:112
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
TFT_CHANGELOG
@ TFT_CHANGELOG
Content changelog.
Definition: textfile_type.h:18
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
WID_AIC_INTERVAL
@ WID_AIC_INTERVAL
Interval between time AIs start.
Definition: ai_widget.h:23
ai.hpp
ai_info.hpp
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
COMPANY_FIRST
@ COMPANY_FIRST
First company, same as owner.
Definition: company_type.h:22
AIConfigWindow::IsEditable
static bool IsEditable(CompanyID slot)
Can the AI config in the given company slot be edited?
Definition: ai_gui.cpp:154
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:508
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1188
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
ScriptInfo::GetURL
const std::string & GetURL() const
Get the website for this script.
Definition: script_info.hpp:76
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1747
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
AIConfig::GetConfig
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: ai_config.cpp:19
AIConfigWindow::line_height
int line_height
Height of a single AI-name line.
Definition: ai_gui.cpp:97
WID_AIC_NUMBER
@ WID_AIC_NUMBER
Number of AIs.
Definition: ai_widget.h:20
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
Company::IsValidAiID
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Definition: company_base.h:138
ShowScriptSettingsWindow
void ShowScriptSettingsWindow(CompanyID slot)
Open the Script settings window to change the Script settings for a Script.
Definition: script_gui.cpp:650
WID_AIC_LIST
@ WID_AIC_LIST
List with currently selected AIs.
Definition: ai_widget.h:24
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
Scrollbar::SetCapacity
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
Definition: widget_type.h:774
WWT_FRAME
@ WWT_FRAME
Frame.
Definition: widget_type.h:62
TFT_README
@ TFT_README
Content readme.
Definition: textfile_type.h:17
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3140
AIConfigWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: ai_gui.cpp:98
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:234
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
WID_AIC_DECREASE_INTERVAL
@ WID_AIC_DECREASE_INTERVAL
Decrease the interval.
Definition: ai_widget.h:21
_nested_ai_config_widgets
static constexpr NWidgetPart _nested_ai_config_widgets[]
Widgets for the configure AI window.
Definition: ai_gui.cpp:30
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2260
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
CONTENT_TYPE_AI
@ CONTENT_TYPE_AI
The content consists of an AI.
Definition: tcp_content_type.h:22
TFT_LICENSE
@ TFT_LICENSE
Content license.
Definition: textfile_type.h:19
WID_AIC_INCREASE_NUMBER
@ WID_AIC_INCREASE_NUMBER
Increase the number of AIs.
Definition: ai_widget.h:19
WID_AIC_MOVE_UP
@ WID_AIC_MOVE_UP
Move up button.
Definition: ai_widget.h:26
MIN_COMPETITORS_INTERVAL
static const uint MIN_COMPETITORS_INTERVAL
The minimum interval (in minutes) between competitors.
Definition: company_type.h:45
AIConfigWindow
Window to configure which AIs will start.
Definition: ai_gui.cpp:95
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:619
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:384
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
WID_AIC_SCROLLBAR
@ WID_AIC_SCROLLBAR
Scrollbar to scroll through the selected AIs.
Definition: ai_widget.h:25
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:60
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1220
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
WID_AIC_MOVE_DOWN
@ WID_AIC_MOVE_DOWN
Move down button.
Definition: ai_widget.h:27
WID_AIC_CONFIGURE
@ WID_AIC_CONFIGURE
Change AI settings button.
Definition: ai_widget.h:29
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:352
DifficultySettings::max_no_competitors
byte max_no_competitors
the number of competitors (AIs)
Definition: settings_type.h:99
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:26
ScriptConfig::GetTextfile
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
Definition: script_config.cpp:193
AIConfigWindow::selected_slot
CompanyID selected_slot
The currently selected AI slot or INVALID_COMPANY.
Definition: ai_gui.cpp:96
WN_GAME_OPTIONS_AI
@ WN_GAME_OPTIONS_AI
AI settings.
Definition: window_type.h:22
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
_ai_config_desc
static WindowDesc _ai_config_desc(__FILE__, __LINE__, WDP_CENTER, nullptr, 0, 0, WC_GAME_OPTIONS, WC_NONE, 0, std::begin(_nested_ai_config_widgets), std::end(_nested_ai_config_widgets))
Window definition for the configure AI window.
DrawString
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.
Definition: gfx.cpp:658
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
ScriptConfig::GetConfigList
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
Definition: script_config.cpp:61
GetGameSettings
GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
Definition: settings_type.h:660
Window
Data structure for an opened window.
Definition: window_gui.h:267
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
MAX_COMPETITORS_INTERVAL
static const uint MAX_COMPETITORS_INTERVAL
The maximum interval (in minutes) between competitors.
Definition: company_type.h:46
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:324
ShowScriptTextfileWindow
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
Definition: script_gui.cpp:692
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
_network_available
bool _network_available
is network mode available?
Definition: network.cpp:61
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
WC_SCRIPT_SETTINGS
@ WC_SCRIPT_SETTINGS
Script settings; Window numbers:
Definition: window_type.h:175
ShowAIConfigWindow
void ShowAIConfigWindow()
Open the AI config window.
Definition: ai_gui.cpp:320
WC_SCRIPT_LIST
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
Definition: window_type.h:284
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
Company
Definition: company_base.h:116
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:34
WID_AIC_INCREASE_INTERVAL
@ WID_AIC_INCREASE_INTERVAL
Increase the interval.
Definition: ai_widget.h:22
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:142
WID_AIC_BACKGROUND
@ WID_AIC_BACKGROUND
Window background.
Definition: ai_widget.h:17
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:33
AIConfigWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: ai_gui.cpp:293
ai_config.hpp
WID_AIC_CHANGE
@ WID_AIC_CHANGE
Select another AI button.
Definition: ai_widget.h:28