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

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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
25#include "table/strings.h"
26
27#include "../safeguards.h"
28
29
31 static constexpr std::initializer_list<NWidgetPart> _nested_ai_config_widgets = {
32 NWidget(NWID_HORIZONTAL),
33 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
34 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetStringTip(STR_AI_CONFIG_CAPTION_AI, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
35 EndContainer(),
36 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_AIC_BACKGROUND),
37 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.sparse),
38 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
39 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
40 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
41 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_DECREASE_NUMBER), SetArrowWidgetTypeTip(AWV_DECREASE),
42 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_INCREASE_NUMBER), SetArrowWidgetTypeTip(AWV_INCREASE),
43 EndContainer(),
44 NWidget(WWT_TEXT, INVALID_COLOUR, WID_AIC_NUMBER), SetFill(1, 0),
45 EndContainer(),
46 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
47 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
48 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_DECREASE_INTERVAL), SetArrowWidgetTypeTip(AWV_DECREASE),
49 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_INCREASE_INTERVAL), SetArrowWidgetTypeTip(AWV_INCREASE),
50 EndContainer(),
51 NWidget(WWT_TEXT, INVALID_COLOUR, WID_AIC_INTERVAL), SetFill(1, 0),
52 EndContainer(),
53 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
54 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_MOVE_UP), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_AI_CONFIG_MOVE_UP, STR_AI_CONFIG_MOVE_UP_TOOLTIP),
55 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_MOVE_DOWN), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_AI_CONFIG_MOVE_DOWN, STR_AI_CONFIG_MOVE_DOWN_TOOLTIP),
56 EndContainer(),
57 EndContainer(),
58 NWidget(WWT_FRAME, COLOUR_MAUVE), SetStringTip(STR_AI_CONFIG_AI), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
59 NWidget(NWID_HORIZONTAL),
60 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),
61 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIC_SCROLLBAR),
62 EndContainer(),
63 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONFIGURE), SetFill(1, 0), SetStringTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP),
64 EndContainer(),
65 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
66 NWidget(NWID_VERTICAL, NWidContainerFlag::EqualSize),
67 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CHANGE), SetFill(1, 1), SetStringTip(STR_AI_CONFIG_CHANGE_AI, STR_AI_CONFIG_CHANGE_TOOLTIP),
68 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONTENT_DOWNLOAD), SetFill(1, 1), SetStringTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
69 EndContainer(),
70 NWidget(NWID_VERTICAL, NWidContainerFlag::EqualSize),
71 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
72 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
73 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_README), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
74 EndContainer(),
75 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
76 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
77 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_LICENSE), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
78 EndContainer(),
79 EndContainer(),
80 EndContainer(),
81 EndContainer(),
82 EndContainer(),
83};
84
86 static WindowDesc _ai_config_desc(
87 WDP_CENTER, {}, 0, 0,
88 WC_GAME_OPTIONS, WC_NONE,
89 {},
90 _nested_ai_config_widgets
91);
92
96 struct AIConfigWindow : public Window {
97 CompanyID selected_slot = CompanyID::Invalid();
98 int line_height = 0;
99 Scrollbar *vscroll = nullptr;
100
101 AIConfigWindow() : Window(_ai_config_desc)
102 {
103 this->InitNested(WN_GAME_OPTIONS_AI); // Initializes 'this->line_height' as a side effect.
104 this->vscroll = this->GetScrollbar(WID_AIC_SCROLLBAR);
105 this->selected_slot = CompanyID::Invalid();
106 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_AIC_LIST);
107 this->vscroll->SetCapacity(nwi->current_y / this->line_height);
108 this->vscroll->SetCount(MAX_COMPANIES);
109 this->OnInvalidateData(0);
110 }
111
112 void Close([[maybe_unused]] int data = 0) override
113 {
114 CloseWindowByClass(WC_SCRIPT_LIST);
115 CloseWindowByClass(WC_SCRIPT_SETTINGS);
116 this->Window::Close();
117 }
118
119 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
120 {
121 switch (widget) {
122 case WID_AIC_NUMBER:
123 return GetString(STR_AI_CONFIG_MAX_COMPETITORS, GetGameSettings().difficulty.max_no_competitors);
124
125 case WID_AIC_INTERVAL:
126 return GetString(STR_AI_CONFIG_COMPETITORS_INTERVAL, GetGameSettings().difficulty.competitors_interval);
127
128 default:
129 return this->Window::GetWidgetString(widget, stringid);
130 }
131 }
132
133 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
134 {
135 switch (widget) {
136 case WID_AIC_DECREASE_NUMBER:
137 case WID_AIC_INCREASE_NUMBER:
138 case WID_AIC_DECREASE_INTERVAL:
139 case WID_AIC_INCREASE_INTERVAL:
140 size = maxdim(size, NWidgetScrollbar::GetHorizontalDimension());
141 break;
142
143 case WID_AIC_LIST:
144 this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
145 fill.height = resize.height = this->line_height;
146 size.height = 8 * this->line_height;
147 break;
148 }
149 }
150
156 static bool IsEditable(CompanyID slot)
157 {
158 if (_game_mode != GM_NORMAL) {
159 return slot > 0 && slot < MAX_COMPANIES;
160 }
161 return slot < MAX_COMPANIES && !Company::IsValidID(slot);
162 }
163
169 std::string GetSlotText(CompanyID cid) const
170 {
171 if ((_game_mode != GM_NORMAL && cid == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(cid))) return GetString(STR_AI_CONFIG_HUMAN_PLAYER);
172 if (const AIInfo *info = AIConfig::GetConfig(cid)->GetInfo(); info != nullptr) return info->GetName();
173 return GetString(STR_AI_CONFIG_RANDOM_AI);
174 }
175
182 TextColour GetSlotColour(CompanyID cid, CompanyID max_slot) const
183 {
184 if (this->selected_slot == cid) return TC_WHITE;
185 if (IsEditable(cid)) return cid < max_slot ? TC_ORANGE : TC_SILVER;
186 if (Company::IsValidAiID(cid)) return TC_GREEN;
187 return TC_SILVER;
188 }
189
190 void DrawWidget(const Rect &r, WidgetID widget) const override
191 {
192 switch (widget) {
193 case WID_AIC_LIST: {
194 Rect tr = r.Shrink(WidgetDimensions::scaled.matrix);
195 int max_slot = GetGameSettings().difficulty.max_no_competitors;
196 if (_game_mode == GM_NORMAL) {
197 for (const Company *c : Company::Iterate()) {
198 if (c->is_ai) max_slot--;
199 }
200 for (CompanyID cid = CompanyID::Begin(); cid < max_slot && cid < MAX_COMPANIES; ++cid) {
201 if (Company::IsValidID(cid)) max_slot++;
202 }
203 } else {
204 max_slot++; // Slot 0 is human
205 }
206 for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
207 CompanyID cid = static_cast<CompanyID>(i);
208 DrawString(tr, this->GetSlotText(cid), this->GetSlotColour(cid, static_cast<CompanyID>(max_slot)));
209 tr.top += this->line_height;
210 }
211 break;
212 }
213 }
214 }
215
216 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
217 {
218 if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_CONTENT_END) {
219 if (this->selected_slot == CompanyID::Invalid() || AIConfig::GetConfig(this->selected_slot) == nullptr) return;
220
221 ShowScriptTextfileWindow(this, static_cast<TextfileType>(widget - WID_AIC_TEXTFILE), this->selected_slot);
222 return;
223 }
224
225 switch (widget) {
226 case WID_AIC_DECREASE_NUMBER:
227 case WID_AIC_INCREASE_NUMBER: {
228 int new_value;
229 if (widget == WID_AIC_DECREASE_NUMBER) {
230 new_value = std::max(0, GetGameSettings().difficulty.max_no_competitors - 1);
231 } else {
232 new_value = std::min<int>(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
233 }
234 IConsoleSetSetting("difficulty.max_no_competitors", new_value);
235 this->InvalidateData();
236 break;
237 }
238
239 case WID_AIC_DECREASE_INTERVAL:
240 case WID_AIC_INCREASE_INTERVAL: {
241 int new_value;
242 if (widget == WID_AIC_DECREASE_INTERVAL) {
243 new_value = std::max(static_cast<int>(MIN_COMPETITORS_INTERVAL), GetGameSettings().difficulty.competitors_interval - 1);
244 } else {
245 new_value = std::min(static_cast<int>(MAX_COMPETITORS_INTERVAL), GetGameSettings().difficulty.competitors_interval + 1);
246 }
247 IConsoleSetSetting("difficulty.competitors_interval", new_value);
248 this->InvalidateData();
249 break;
250 }
251
252 case WID_AIC_LIST: { // Select a slot
253 this->selected_slot = static_cast<CompanyID>(this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget));
254 this->InvalidateData();
255 if (click_count > 1 && IsEditable(this->selected_slot)) ShowScriptListWindow(this->selected_slot, _ctrl_pressed);
256 break;
257 }
258
259 case WID_AIC_MOVE_UP:
260 if (IsEditable(this->selected_slot) && IsEditable(static_cast<CompanyID>(this->selected_slot - 1))) {
261 std::swap(GetGameSettings().script_config.ai[this->selected_slot], GetGameSettings().script_config.ai[this->selected_slot - 1]);
262 this->selected_slot = static_cast<CompanyID>(this->selected_slot - 1);
263 this->vscroll->ScrollTowards(this->selected_slot.base());
264 this->InvalidateData();
265 }
266 break;
267
268 case WID_AIC_MOVE_DOWN:
269 if (IsEditable(this->selected_slot) && IsEditable(static_cast<CompanyID>(this->selected_slot + 1))) {
270 std::swap(GetGameSettings().script_config.ai[this->selected_slot], GetGameSettings().script_config.ai[this->selected_slot + 1]);
271 ++this->selected_slot;
272 this->vscroll->ScrollTowards(this->selected_slot.base());
273 this->InvalidateData();
274 }
275 break;
276
277 case WID_AIC_OPEN_URL: {
278 const AIConfig *config = AIConfig::GetConfig(this->selected_slot);
279 if (this->selected_slot == CompanyID::Invalid() || config == nullptr || config->GetInfo() == nullptr) return;
280 OpenBrowser(config->GetInfo()->GetURL());
281 break;
282 }
283
284 case WID_AIC_CHANGE: // choose other AI
285 if (IsEditable(this->selected_slot)) ShowScriptListWindow(this->selected_slot, _ctrl_pressed);
286 break;
287
288 case WID_AIC_CONFIGURE: // change the settings for an AI
289 ShowScriptSettingsWindow(this->selected_slot);
290 break;
291
292 case WID_AIC_CONTENT_DOWNLOAD:
293 if (!_network_available) {
294 ShowErrorMessage(GetEncodedString(STR_NETWORK_ERROR_NOTAVAILABLE), {}, WL_ERROR);
295 } else {
296 ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_AI);
297 }
298 break;
299 }
300 }
301
307 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
308 {
309 if (!IsEditable(this->selected_slot) && !Company::IsValidAiID(this->selected_slot)) {
310 this->selected_slot = CompanyID::Invalid();
311 }
312
313 if (!gui_scope) return;
314
315 AIConfig *config = this->selected_slot == CompanyID::Invalid() ? nullptr : AIConfig::GetConfig(this->selected_slot);
316
317 this->SetWidgetDisabledState(WID_AIC_DECREASE_NUMBER, GetGameSettings().difficulty.max_no_competitors == 0);
318 this->SetWidgetDisabledState(WID_AIC_INCREASE_NUMBER, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
319 this->SetWidgetDisabledState(WID_AIC_DECREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MIN_COMPETITORS_INTERVAL);
320 this->SetWidgetDisabledState(WID_AIC_INCREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MAX_COMPETITORS_INTERVAL);
321 this->SetWidgetDisabledState(WID_AIC_CHANGE, !IsEditable(this->selected_slot));
322 this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == CompanyID::Invalid() || config->GetConfigList()->empty());
323 this->SetWidgetDisabledState(WID_AIC_MOVE_UP, !IsEditable(this->selected_slot) || !IsEditable(static_cast<CompanyID>(this->selected_slot - 1)));
324 this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, !IsEditable(this->selected_slot) || !IsEditable(static_cast<CompanyID>(this->selected_slot + 1)));
325
326 this->SetWidgetDisabledState(WID_AIC_OPEN_URL, this->selected_slot == CompanyID::Invalid() || config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty());
327 for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
328 this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == CompanyID::Invalid() || !config->GetTextfile(tft, this->selected_slot).has_value());
329 }
330 }
331};
332
334 void ShowAIConfigWindow()
335{
336 CloseWindowByClass(WC_GAME_OPTIONS);
337 new AIConfigWindow();
338}
339
ai.hpp
Base functions for all AIs.
ai_config.hpp
AIConfig stores the configuration settings of every AI.
_ai_config_desc
static WindowDesc _ai_config_desc(WDP_CENTER, {}, 0, 0, WC_GAME_OPTIONS, WC_NONE, {}, _nested_ai_config_widgets)
Window definition for the configure AI window.
ShowAIConfigWindow
void ShowAIConfigWindow()
Open the AI config window.
Definition ai_gui.cpp:334
_nested_ai_config_widgets
static constexpr std::initializer_list< NWidgetPart > _nested_ai_config_widgets
Widgets for the configure AI window.
Definition ai_gui.cpp:31
ai_gui.hpp
Window for configuring the AIs
ai_info.hpp
AIInfo keeps track of all information of an AI, like Author, Description, ...
WID_AIC_CONFIGURE
@ WID_AIC_CONFIGURE
Change AI settings button.
Definition ai_widget.h:29
WID_AIC_NUMBER
@ WID_AIC_NUMBER
Number of AIs.
Definition ai_widget.h:20
WID_AIC_INTERVAL
@ WID_AIC_INTERVAL
Interval between time AIs start.
Definition ai_widget.h:23
WID_AIC_TEXTFILE
@ WID_AIC_TEXTFILE
Open AI readme, changelog (+1) or license (+2).
Definition ai_widget.h:31
WID_AIC_MOVE_DOWN
@ WID_AIC_MOVE_DOWN
Move down button.
Definition ai_widget.h:27
WID_AIC_BACKGROUND
@ WID_AIC_BACKGROUND
Window background.
Definition ai_widget.h:17
WID_AIC_LIST
@ WID_AIC_LIST
List with currently selected AIs.
Definition ai_widget.h:24
WID_AIC_CONTENT_DOWNLOAD
@ WID_AIC_CONTENT_DOWNLOAD
Download content button.
Definition ai_widget.h:32
WID_AIC_INCREASE_INTERVAL
@ WID_AIC_INCREASE_INTERVAL
Increase the interval.
Definition ai_widget.h:22
WID_AIC_OPEN_URL
@ WID_AIC_OPEN_URL
Open AI URL.
Definition ai_widget.h:30
WID_AIC_DECREASE_INTERVAL
@ WID_AIC_DECREASE_INTERVAL
Decrease the interval.
Definition ai_widget.h:21
WID_AIC_SCROLLBAR
@ WID_AIC_SCROLLBAR
Scrollbar to scroll through the selected AIs.
Definition ai_widget.h:25
WID_AIC_DECREASE_NUMBER
@ WID_AIC_DECREASE_NUMBER
Decrease the number of AIs.
Definition ai_widget.h:18
WID_AIC_CHANGE
@ WID_AIC_CHANGE
Select another AI button.
Definition ai_widget.h:28
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
AIConfig
Definition ai_config.hpp:16
AIConfig::GetConfig
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition ai_config.cpp:20
AIInfo
All static information from an AI like name, version, etc.
Definition ai_info.hpp:16
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition widget_type.h:238
NWidgetCore
Base class for a 'real' widget.
Definition widget_type.h:368
ScriptConfig::GetTextfile
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
Definition script_config.cpp:178
ScriptConfig::GetConfigList
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
Definition script_config.cpp:60
ScriptInfo::GetURL
const std::string & GetURL() const
Get the website for this script.
Definition script_info.hpp:70
Scrollbar
Scrollbar data structure.
Definition widget_type.h:708
Scrollbar::IsVisible
bool IsVisible(size_type item) const
Checks whether given current item is visible in the list.
Definition widget_type.h:762
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:792
Scrollbar::SetCapacity
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
Definition widget_type.h:806
Scrollbar::GetScrolledRowFromWidget
size_type 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:2425
Scrollbar::ScrollTowards
void ScrollTowards(size_type position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition widget_type.h:853
Scrollbar::GetPosition
size_type GetPosition() const
Gets the position of the first visible element in the list.
Definition widget_type.h:752
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
MIN_COMPETITORS_INTERVAL
static const uint MIN_COMPETITORS_INTERVAL
The minimum interval (in minutes) between competitors.
Definition company_type.h:38
MAX_COMPETITORS_INTERVAL
static const uint MAX_COMPETITORS_INTERVAL
The maximum interval (in minutes) between competitors.
Definition company_type.h:39
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition error.h:26
ShowErrorMessage
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Definition error_gui.cpp:290
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
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:665
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition widget_type.h:1308
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
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:1375
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1399
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:1332
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1240
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1156
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
SetArrowWidgetTypeTip
constexpr NWidgetPart SetArrowWidgetTypeTip(ArrowWidgetValues widget_type, StringID tip={})
Widget part function for setting the arrow widget type and tooltip.
Definition widget_type.h:1274
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1145
_network_available
bool _network_available
is network mode available?
Definition network.cpp:68
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:1117
ShowScriptSettingsWindow
void ShowScriptSettingsWindow(CompanyID slot)
Open the Script settings window to change the Script settings for a Script.
Definition script_gui.cpp:588
ShowScriptTextfileWindow
void ShowScriptTextfileWindow(Window *parent, TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
Definition script_gui.cpp:631
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:278
GetGameSettings
GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
Definition settings_type.h:674
GetEncodedString
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
AIConfigWindow
Window to configure which AIs will start.
Definition ai_gui.cpp:96
AIConfigWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition ai_gui.cpp:119
AIConfigWindow::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition ai_gui.cpp:112
AIConfigWindow::UpdateWidgetSize
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.
Definition ai_gui.cpp:133
AIConfigWindow::GetSlotText
std::string GetSlotText(CompanyID cid) const
Get text to display for a given company slot.
Definition ai_gui.cpp:169
AIConfigWindow::GetSlotColour
TextColour GetSlotColour(CompanyID cid, CompanyID max_slot) const
Get colour to display text in for a given company slot.
Definition ai_gui.cpp:182
AIConfigWindow::selected_slot
CompanyID selected_slot
The currently selected AI slot or CompanyID::Invalid().
Definition ai_gui.cpp:97
AIConfigWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition ai_gui.cpp:190
AIConfigWindow::IsEditable
static bool IsEditable(CompanyID slot)
Can the AI config in the given company slot be edited?
Definition ai_gui.cpp:156
AIConfigWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition ai_gui.cpp:99
AIConfigWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition ai_gui.cpp:216
AIConfigWindow::line_height
int line_height
Height of a single AI-name line.
Definition ai_gui.cpp:98
AIConfigWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition ai_gui.cpp:307
Company
Definition company_base.h:127
Company::IsValidAiID
static bool IsValidAiID(auto index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Definition company_base.h:153
Company::IsValidHumanID
static bool IsValidHumanID(auto index)
Is this company a valid company, not controlled by a NoAI program?
Definition company_base.h:165
Coord2D< int >
DifficultySettings::max_no_competitors
uint8_t max_no_competitors
the number of competitors (AIs)
Definition settings_type.h:125
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
GameSettings::ai
AISettings ai
what may the AI do?
Definition settings_type.h:636
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition settings_type.h:633
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
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:436
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:376
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:124
WindowDesc
High level window description.
Definition window_gui.h:168
Window
Data structure for an opened window.
Definition window_gui.h:274
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:1102
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:3234
Window::GetWidgetString
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:504
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1820
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
CONTENT_TYPE_AI
@ CONTENT_TYPE_AI
The content consists of an AI.
Definition tcp_content_type.h:25
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition textfile_type.h:14
TFT_LICENSE
@ TFT_LICENSE
Content license.
Definition textfile_type.h:19
TFT_README
@ TFT_README
Content readme.
Definition textfile_type.h:17
TFT_CHANGELOG
@ TFT_CHANGELOG
Content changelog.
Definition textfile_type.h:18
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:104
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition widget_type.h:106
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
WWT_FRAME
@ WWT_FRAME
Frame.
Definition widget_type.h:51
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49
EqualSize
@ EqualSize
Containers should keep all their (resizing) children equally large.
Definition widget_type.h:541
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition widget_type.h:20
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition widget_type.h:21
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1205
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition window_gui.h:145
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
WN_GAME_OPTIONS_AI
@ WN_GAME_OPTIONS_AI
AI settings.
Definition window_type.h:27
WC_SCRIPT_SETTINGS
@ WC_SCRIPT_SETTINGS
Script settings; Window numbers:
Definition window_type.h:180
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
WC_SCRIPT_LIST
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
Definition window_type.h:289
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition window_type.h:635