OpenTTD Source 20250312-master-gcdcc6b491d
league_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 "league_gui.h"
12#include "company_base.h"
13#include "company_gui.h"
14#include "gui.h"
15#include "industry.h"
16#include "league_base.h"
17#include "sortlist_type.h"
18#include "story_base.h"
19#include "strings_func.h"
20#include "tile_map.h"
21#include "town.h"
22#include "viewport_func.h"
23#include "window_gui.h"
24
26
27#include "table/strings.h"
28#include "table/sprites.h"
29
30#include "safeguards.h"
31
32
33static const StringID _performance_titles[] = {
34 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER,
35 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER,
36 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER,
37 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER,
38 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR,
39 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR,
40 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR,
41 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR,
42 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR,
43 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR,
44 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE,
45 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE,
46 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN,
47 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN,
48 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_PRESIDENT,
49 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TYCOON,
50};
51
52static inline StringID GetPerformanceTitleFromValue(uint value)
53{
54 return _performance_titles[std::min(value, 1000u) >> 6];
55}
56
58private:
59 GUIList<const Company *> companies{};
60 uint ordinal_width = 0;
61 uint text_width = 0;
62 int line_height = 0;
64
69 {
70 if (!this->companies.NeedRebuild()) return;
71
72 this->companies.clear();
73 this->companies.reserve(Company::GetNumItems());
74
75 for (const Company *c : Company::Iterate()) {
76 this->companies.push_back(c);
77 }
78
79 this->companies.RebuildDone();
80 }
81
83 static bool PerformanceSorter(const Company * const &c1, const Company * const &c2)
84 {
85 return c2->old_economy[0].performance_history < c1->old_economy[0].performance_history;
86 }
87
88public:
90 {
91 this->InitNested(window_number);
92 this->companies.ForceRebuild();
93 this->companies.NeedResort();
94 }
95
96 void OnPaint() override
97 {
98 this->BuildCompanyList();
99 this->companies.Sort(&PerformanceSorter);
100
101 this->DrawWidgets();
102 }
103
104 void DrawWidget(const Rect &r, WidgetID widget) const override
105 {
106 if (widget != WID_PLT_BACKGROUND) return;
107
108 Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
109 int icon_y_offset = (this->line_height - this->icon.height) / 2;
110 int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
111
112 bool rtl = _current_text_dir == TD_RTL;
113 Rect ordinal = ir.WithWidth(this->ordinal_width, rtl);
114 uint icon_left = ir.Indent(rtl ? this->text_width : this->ordinal_width, rtl).left;
115 Rect text = ir.WithWidth(this->text_width, !rtl);
116
117 for (uint i = 0; i != this->companies.size(); i++) {
118 const Company *c = this->companies[i];
120
122
123 DrawString(text.left, text.right, ir.top + text_y_offset, GetString(STR_COMPANY_LEAGUE_COMPANY_NAME, c->index, c->index, GetPerformanceTitleFromValue(c->old_economy[0].performance_history)));
124 ir.top += this->line_height;
125 }
126 }
127
129 {
130 if (widget != WID_PLT_BACKGROUND) return;
131
132 this->ordinal_width = 0;
133 for (uint i = 0; i < MAX_COMPANIES; i++) {
134 this->ordinal_width = std::max(this->ordinal_width, GetStringBoundingBox(GetString(STR_COMPANY_LEAGUE_COMPANY_RANK, i + 1)).width);
135 }
136 this->ordinal_width += WidgetDimensions::scaled.hsep_wide; // Keep some extra spacing
137
138 uint widest_width = 0;
140 for (auto title : _performance_titles) {
141 uint width = GetStringBoundingBox(title).width;
142 if (width > widest_width) {
143 widest_title = title;
145 }
146 }
147
148 this->icon = GetSpriteSize(SPR_COMPANY_ICON);
149 this->line_height = std::max<int>(this->icon.height + WidgetDimensions::scaled.vsep_normal, GetCharacterHeight(FS_NORMAL));
150
151 for (const Company *c : Company::Iterate()) {
153 }
154
155 this->text_width = widest_width + WidgetDimensions::scaled.hsep_indent * 3; // Keep some extra spacing
156
157 size.width = WidgetDimensions::scaled.framerect.Horizontal() + this->ordinal_width + this->icon.width + this->text_width + WidgetDimensions::scaled.hsep_wide;
158 size.height = this->line_height * MAX_COMPANIES + WidgetDimensions::scaled.framerect.Vertical();
159 }
160
161 void OnGameTick() override
162 {
163 if (this->companies.NeedResort()) {
164 this->SetDirty();
165 }
166 }
167
173 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
174 {
175 if (data == 0) {
176 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
177 this->companies.ForceRebuild();
178 } else {
179 this->companies.ForceResort();
180 }
181 }
182};
183
184static constexpr NWidgetPart _nested_performance_league_widgets[] = {
186 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
187 NWidget(WWT_CAPTION, COLOUR_BROWN), SetStringTip(STR_COMPANY_LEAGUE_TABLE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
188 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
189 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
190 EndContainer(),
191 NWidget(WWT_PANEL, COLOUR_BROWN, WID_PLT_BACKGROUND), SetMinimalSize(400, 0), SetMinimalTextLines(15, WidgetDimensions::unscaled.framerect.Vertical()),
192 EndContainer(),
193};
194
195static WindowDesc _performance_league_desc(
196 WDP_AUTO, "performance_league", 0, 0,
198 {},
199 _nested_performance_league_widgets
200);
201
202void ShowPerformanceLeagueTable()
203{
204 AllocateWindowDescFront<PerformanceLeagueWindow>(_performance_league_desc, 0);
205}
206
207static void HandleLinkClick(Link link)
208{
209 TileIndex xy;
210 switch (link.type) {
211 case LT_NONE: return;
212
213 case LT_TILE:
214 if (!IsValidTile(link.target)) return;
215 xy = TileIndex{link.target};
216 break;
217
218 case LT_INDUSTRY:
219 if (!Industry::IsValidID(link.target)) return;
220 xy = Industry::Get(link.target)->location.tile;
221 break;
222
223 case LT_TOWN:
224 if (!Town::IsValidID(link.target)) return;
225 xy = Town::Get(link.target)->xy;
226 break;
227
228 case LT_COMPANY:
229 ShowCompany((CompanyID)link.target);
230 return;
231
232 case LT_STORY_PAGE: {
233 if (!StoryPage::IsValidID(link.target)) return;
234 CompanyID story_company = StoryPage::Get(link.target)->company;
235 ShowStoryBook(story_company, static_cast<StoryPageID>(link.target));
236 return;
237 }
238
239 default: NOT_REACHED();
240 }
241
242 if (_ctrl_pressed) {
244 } else {
246 }
247}
248
249
251private:
252 LeagueTableID table{};
253 std::vector<std::pair<uint, const LeagueTableElement *>> rows{};
254 uint rank_width = 0;
255 uint text_width = 0;
256 uint score_width = 0;
257 uint header_height = 0;
258 int line_height = 0;
260 EncodedString title{};
261
266 {
267 this->rows.clear();
268 this->title = {};
269
270 const LeagueTable *lt = LeagueTable::GetIfValid(this->table);
271 if (lt == nullptr) return;
272
273 /* We store title in the window class so we can safely reference the string later */
274 this->title = lt->title;
275
276 std::vector<const LeagueTableElement *> elements;
278 if (lte->table != this->table) continue;
279 elements.push_back(lte);
280 }
281 std::ranges::sort(elements, [](const LeagueTableElement *a, const LeagueTableElement *b) { return a->rating > b->rating; });
282
283 /* Calculate rank, companies with the same rating share the ranks */
284 uint rank = 0;
285 for (uint i = 0; i != elements.size(); i++) {
286 const LeagueTableElement *lte = elements[i];
287 if (i > 0 && elements[i - 1]->rating != lte->rating) rank = i;
288 this->rows.emplace_back(rank, lte);
289 }
290 }
291
292public:
293 ScriptLeagueWindow(WindowDesc &desc, WindowNumber table) : Window(desc), table(table)
294 {
295 this->BuildTable();
296 this->InitNested(table);
297 }
298
299 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
300 {
301 if (widget != WID_SLT_CAPTION) return this->Window::GetWidgetString(widget, stringid);
302
303 return this->title.GetDecodedString();
304 }
305
306 void OnPaint() override
307 {
308 this->DrawWidgets();
309 }
310
311 void DrawWidget(const Rect &r, WidgetID widget) const override
312 {
313 if (widget != WID_SLT_BACKGROUND) return;
314
315 const LeagueTable *lt = LeagueTable::GetIfValid(this->table);
316 if (lt == nullptr) return;
317
318 Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
319
320 if (!lt->header.empty()) {
322 }
323
324 int icon_y_offset = (this->line_height - this->icon_size.height) / 2;
325 int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
326
327 /* Calculate positions.of the columns */
328 bool rtl = _current_text_dir == TD_RTL;
330 Rect rank_rect = ir.WithWidth(this->rank_width, rtl);
331 Rect icon_rect = ir.Indent(this->rank_width + (rtl ? 0 : spacer), rtl).WithWidth(this->icon_size.width, rtl);
332 Rect text_rect = ir.Indent(this->rank_width + spacer + this->icon_size.width, rtl).WithWidth(this->text_width, rtl);
333 Rect score_rect = ir.Indent(this->rank_width + 2 * spacer + this->icon_size.width + this->text_width, rtl).WithWidth(this->score_width, rtl);
334
335 for (const auto &[rank, lte] : this->rows) {
337 if (this->icon_size.width > 0 && lte->company != CompanyID::Invalid()) DrawCompanyIcon(lte->company, icon_rect.left, ir.top + icon_y_offset);
338 DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset, lte->text.GetDecodedString(), TC_BLACK);
339 DrawString(score_rect.left, score_rect.right, ir.top + text_y_offset, lte->score.GetDecodedString(), TC_BLACK, SA_RIGHT);
340 ir.top += this->line_height;
341 }
342
343 if (!lt->footer.empty()) {
345 ir.top = DrawStringMultiLine(ir, lt->footer.GetDecodedString(), TC_BLACK);
346 }
347 }
348
350 {
351 if (widget != WID_SLT_BACKGROUND) return;
352
353 const LeagueTable *lt = LeagueTable::GetIfValid(this->table);
354 if (lt == nullptr) return;
355
356 this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
357 this->line_height = std::max<int>(this->icon_size.height + WidgetDimensions::scaled.fullbevel.Vertical(), GetCharacterHeight(FS_NORMAL));
358
359 /* Calculate maximum width of every column */
360 this->rank_width = this->text_width = this->score_width = 0;
361 bool show_icon_column = false;
362 for (const auto &[rank, lte] : this->rows) {
363 this->rank_width = std::max(this->rank_width, GetStringBoundingBox(GetString(STR_COMPANY_LEAGUE_COMPANY_RANK, rank + 1)).width);
364 this->text_width = std::max(this->text_width, GetStringBoundingBox(lte->text.GetDecodedString()).width);
365 this->score_width = std::max(this->score_width, GetStringBoundingBox(lte->score.GetDecodedString()).width);
366 if (lte->company != CompanyID::Invalid()) show_icon_column = true;
367 }
368
369 if (!show_icon_column) {
370 this->icon_size.width = 0;
371 } else {
373 }
374
375 uint non_text_width = this->rank_width + this->icon_size.width + this->score_width + WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.hsep_wide * 2;
376 size.width = std::max(size.width, non_text_width + this->text_width);
377 size.height = std::max(size.height, this->line_height * std::max<uint>(3u, static_cast<uint>(this->rows.size())) + WidgetDimensions::scaled.framerect.Vertical());
378
379 /* Adjust text_width to fill any space left over if the preset minimal width is larger than our calculated width. */
380 this->text_width = size.width - non_text_width;
381
382 if (!lt->header.empty()) {
384 size.height += header_height;
385 } else {
386 this->header_height = 0;
387 }
388
389 if (!lt->footer.empty()) {
391 }
392 }
393
394 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
395 {
396 if (widget != WID_SLT_BACKGROUND) return;
397
399 int index = (pt.y - WidgetDimensions::scaled.framerect.top - wid->pos_y - this->header_height) / this->line_height;
400 if (index >= 0 && static_cast<uint>(index) < this->rows.size()) {
401 const LeagueTableElement *lte = this->rows[index].second;
402 HandleLinkClick(lte->link);
403 }
404 }
405
411 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
412 {
413 this->BuildTable();
414 this->ReInit();
415 }
416};
417
418static constexpr NWidgetPart _nested_script_league_widgets[] = {
420 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
421 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SLT_CAPTION),
422 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
423 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
424 EndContainer(),
425 NWidget(WWT_PANEL, COLOUR_BROWN, WID_SLT_BACKGROUND), SetMinimalSize(400, 0), SetMinimalTextLines(15, WidgetDimensions::unscaled.framerect.Vertical()),
426 EndContainer(),
427};
428
429static WindowDesc _script_league_desc(
430 WDP_AUTO, "script_league", 0, 0,
432 {},
433 _nested_script_league_widgets
434);
435
436void ShowScriptLeagueTable(LeagueTableID table)
437{
438 if (!LeagueTable::IsValidID(table)) return;
439 AllocateWindowDescFront<ScriptLeagueWindow>(_script_league_desc, table);
440}
441
442void ShowFirstLeagueTable()
443{
444 auto it = LeagueTable::Iterate();
445 if (!it.empty()) {
446 ShowScriptLeagueTable((*it.begin())->index);
447 } else {
448 ShowPerformanceLeagueTable();
449 }
450}
Container for an encoded string, created by GetEncodedString.
std::string GetDecodedString() const
Decode the encoded string.
Definition strings.cpp:219
List template of 'things' T to sort in a GUI.
void RebuildDone()
Notify the sortlist that the rebuild is done.
bool NeedRebuild() const
Check if a rebuild is needed.
void ForceRebuild()
Force that a rebuild is needed.
bool Sort(Comp compare)
Sort the list.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
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 DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
int line_height
Height of the text lines.
void BuildCompanyList()
(Re)Build the company league list
void OnPaint() override
The window must be repainted.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
uint ordinal_width
The width of the ordinal number.
Dimension icon
Dimension of the company icon.
void OnGameTick() override
Called once per (game) tick.
uint text_width
The width of the actual text.
static bool PerformanceSorter(const Company *const &c1, const Company *const &c2)
Sort the company league by performance history.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
int line_height
Height of the text lines.
uint header_height
Height of the table header.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
uint text_width
The width of the actual text.
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 OnPaint() override
The window must be repainted.
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.
uint score_width
The width of the score text.
uint rank_width
The width of the rank ordinal.
Dimension icon_size
Dimension of the company icon.
void BuildTable()
Rebuild the company league list.
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:40
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:29
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
int vsep_wide
Wide vertical spacing.
Definition window_gui.h:60
int hsep_wide
Wide horizontal spacing.
Definition window_gui.h:62
RectPadding fullbevel
Always-scaled bevel thickness.
Definition window_gui.h:39
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
int hsep_indent
Width of indentation for tree layouts.
Definition window_gui.h:63
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.
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
GUI Functions related to companies.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:705
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:923
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:852
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
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
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.
Definition gfx.cpp:775
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:243
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:377
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:943
GUI functions that shouldn't be here.
void ShowStoryBook(CompanyID company, StoryPageID page_id=StoryPageID::Invalid(), bool centered=false)
Raise or create the story book window for company, at page page_id.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Base of all industries.
LeagueTable base class.
League table GUI functions.
@ LT_COMPANY
Link a company.
Definition league_type.h:21
@ LT_STORY_PAGE
Link a story page.
Definition league_type.h:22
@ LT_TILE
Link a tile.
Definition league_type.h:18
@ LT_NONE
No link.
Definition league_type.h:17
@ LT_INDUSTRY
Link an industry.
Definition league_type.h:19
@ LT_TOWN
Link a town.
Definition league_type.h:20
Types related to the graph widgets.
@ WID_PLT_BACKGROUND
Background of the window.
@ WID_SLT_BACKGROUND
Background of the window.
@ WID_SLT_CAPTION
Caption of the window.
A number of safeguards to prevent using unsafe methods.
Base types for having sorted lists in GUIs.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
StoryPage base class.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:426
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
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.
std::array< CompanyEconomyEntry, MAX_HISTORY_QUARTERS > old_economy
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Dimensions (a width and height) of a rectangle in 2D.
Struct about league table elements.
Definition league_base.h:32
int64_t rating
Value that determines ordering of elements in the table (higher=better)
Definition league_base.h:34
Struct about custom league tables.
Definition league_base.h:55
EncodedString header
Text to show above the table.
Definition league_base.h:57
EncodedString title
Title of the table.
Definition league_base.h:56
EncodedString footer
Text to show below the table.
Definition league_base.h:58
Partial widget specification to allow NWidgets to be written nested.
Coordinates of a point in 2D.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * Get(auto index)
Returns Titem with given index.
static size_t GetNumItems()
Returns number of valid items in the pool.
Tindex index
Index of this pool item.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * GetIfValid(auto index)
Returns Titem with given index.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
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.
High level window description.
Definition window_gui.h:168
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:274
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:955
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:744
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:502
ResizeInfo resize
Resize information.
Definition window_gui.h:315
int left
x position of left edge of the window
Definition window_gui.h:310
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:973
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1749
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:312
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
Map writing/reading functions for tiles.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
Base of the town class.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:65
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:56
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:54
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:51
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:59
Functions, definitions and such used only by the GUI.
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:20
@ WC_COMPANY_LEAGUE
Company league window; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47