OpenTTD Source: src/league_gui.cpp Source File

OpenTTD Source 14.0-RC3

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
13 #include "company_base.h"
14 #include "company_gui.h"
15 #include "gui.h"
16 #include "industry.h"
17 #include "league_base.h"
18 #include "sortlist_type.h"
19 #include "story_base.h"
20 #include "strings_func.h"
21 #include "tile_map.h"
22 #include "town.h"
23 #include "viewport_func.h"
24 #include "window_gui.h"
25 #include "widgets/league_widget.h"
26 #include "table/strings.h"
27 #include "table/sprites.h"
28
29 #include "safeguards.h"
30
31
32 static const StringID _performance_titles[] = {
33 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER,
34 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER,
35 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER,
36 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER,
37 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR,
38 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR,
39 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR,
40 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR,
41 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR,
42 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR,
43 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE,
44 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE,
45 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN,
46 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN,
47 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_PRESIDENT,
48 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TYCOON,
49 };
50
51 static inline StringID GetPerformanceTitleFromValue(uint value)
52 {
53 return _performance_titles[std::min(value, 1000u) >> 6];
54 }
55
56 class PerformanceLeagueWindow : public Window {
57 private:
58 GUIList<const Company *> companies;
59 uint ordinal_width;
60 uint text_width;
61 int line_height;
62 Dimension icon;
63
67 void BuildCompanyList()
68 {
69 if (!this->companies.NeedRebuild()) return;
70
71 this->companies.clear();
72
73 for (const Company *c : Company::Iterate()) {
74 this->companies.push_back(c);
75 }
76
77 this->companies.shrink_to_fit();
78 this->companies.RebuildDone();
79 }
80
82 static bool PerformanceSorter(const Company * const &c1, const Company * const &c2)
83 {
84 return c2->old_economy[0].performance_history < c1->old_economy[0].performance_history;
85 }
86
87 public:
88 PerformanceLeagueWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
89 {
90 this->InitNested(window_number);
91 this->companies.ForceRebuild();
92 this->companies.NeedResort();
93 }
94
95 void OnPaint() override
96 {
97 this->BuildCompanyList();
98 this->companies.Sort(&PerformanceSorter);
99
100 this->DrawWidgets();
101 }
102
103 void DrawWidget(const Rect &r, WidgetID widget) const override
104 {
105 if (widget != WID_PLT_BACKGROUND) return;
106
107 Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
108 int icon_y_offset = (this->line_height - this->icon.height) / 2;
109 int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
110
111 bool rtl = _current_text_dir == TD_RTL;
112 Rect ordinal = ir.WithWidth(this->ordinal_width, rtl);
113 uint icon_left = ir.Indent(rtl ? this->text_width : this->ordinal_width, rtl).left;
114 Rect text = ir.WithWidth(this->text_width, !rtl);
115
116 for (uint i = 0; i != this->companies.size(); i++) {
117 const Company *c = this->companies[i];
118 SetDParam(0, i + 1);
119 DrawString(ordinal.left, ordinal.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_RANK);
120
121 DrawCompanyIcon(c->index, icon_left, ir.top + icon_y_offset);
122
123 SetDParam(0, c->index);
124 SetDParam(1, c->index);
125 SetDParam(2, GetPerformanceTitleFromValue(c->old_economy[0].performance_history));
126 DrawString(text.left, text.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_NAME);
127 ir.top += this->line_height;
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 if (widget != WID_PLT_BACKGROUND) return;
134
135 this->ordinal_width = 0;
136 for (uint i = 0; i < MAX_COMPANIES; i++) {
137 SetDParam(0, i + 1);
138 this->ordinal_width = std::max(this->ordinal_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_RANK).width);
139 }
140 this->ordinal_width += WidgetDimensions::scaled.hsep_wide; // Keep some extra spacing
141
142 uint widest_width = 0;
143 uint widest_title = 0;
144 for (uint i = 0; i < lengthof(_performance_titles); i++) {
145 uint width = GetStringBoundingBox(_performance_titles[i]).width;
146 if (width > widest_width) {
147 widest_title = i;
148 widest_width = width;
149 }
150 }
151
152 this->icon = GetSpriteSize(SPR_COMPANY_ICON);
153 this->line_height = std::max<int>(this->icon.height + WidgetDimensions::scaled.vsep_normal, GetCharacterHeight(FS_NORMAL));
154
155 for (const Company *c : Company::Iterate()) {
156 SetDParam(0, c->index);
157 SetDParam(1, c->index);
158 SetDParam(2, _performance_titles[widest_title]);
159 widest_width = std::max(widest_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_NAME).width);
160 }
161
162 this->text_width = widest_width + WidgetDimensions::scaled.hsep_indent * 3; // Keep some extra spacing
163
164 size->width = WidgetDimensions::scaled.framerect.Horizontal() + this->ordinal_width + this->icon.width + this->text_width + WidgetDimensions::scaled.hsep_wide;
165 size->height = this->line_height * MAX_COMPANIES + WidgetDimensions::scaled.framerect.Vertical();
166 }
167
168 void OnGameTick() override
169 {
170 if (this->companies.NeedResort()) {
171 this->SetDirty();
172 }
173 }
174
180 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
181 {
182 if (data == 0) {
183 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
184 this->companies.ForceRebuild();
185 } else {
186 this->companies.ForceResort();
187 }
188 }
189 };
190
191 static constexpr NWidgetPart _nested_performance_league_widgets[] = {
192 NWidget(NWID_HORIZONTAL),
193 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
194 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_COMPANY_LEAGUE_TABLE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
195 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
196 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
197 EndContainer(),
198 NWidget(WWT_PANEL, COLOUR_BROWN, WID_PLT_BACKGROUND), SetMinimalSize(400, 0), SetMinimalTextLines(15, WidgetDimensions::unscaled.framerect.Vertical()),
199 EndContainer(),
200 };
201
202 static WindowDesc _performance_league_desc(__FILE__, __LINE__,
203 WDP_AUTO, "performance_league", 0, 0,
204 WC_COMPANY_LEAGUE, WC_NONE,
205 0,
206 std::begin(_nested_performance_league_widgets), std::end(_nested_performance_league_widgets)
207 );
208
209 void ShowPerformanceLeagueTable()
210 {
211 AllocateWindowDescFront<PerformanceLeagueWindow>(&_performance_league_desc, 0);
212 }
213
214 static void HandleLinkClick(Link link)
215 {
216 TileIndex xy;
217 switch (link.type) {
218 case LT_NONE: return;
219
220 case LT_TILE:
221 if (!IsValidTile(link.target)) return;
222 xy = link.target;
223 break;
224
225 case LT_INDUSTRY:
226 if (!Industry::IsValidID(link.target)) return;
227 xy = Industry::Get(link.target)->location.tile;
228 break;
229
230 case LT_TOWN:
231 if (!Town::IsValidID(link.target)) return;
232 xy = Town::Get(link.target)->xy;
233 break;
234
235 case LT_COMPANY:
236 ShowCompany((CompanyID)link.target);
237 return;
238
239 case LT_STORY_PAGE: {
240 if (!StoryPage::IsValidID(link.target)) return;
241 CompanyID story_company = StoryPage::Get(link.target)->company;
242 ShowStoryBook(story_company, link.target);
243 return;
244 }
245
246 default: NOT_REACHED();
247 }
248
249 if (_ctrl_pressed) {
250 ShowExtraViewportWindow(xy);
251 } else {
252 ScrollMainWindowToTile(xy);
253 }
254 }
255
256
257 class ScriptLeagueWindow : public Window {
258 private:
259 LeagueTableID table;
260 std::vector<std::pair<uint, const LeagueTableElement *>> rows;
261 uint rank_width;
262 uint text_width;
263 uint score_width;
264 uint header_height;
265 int line_height;
266 Dimension icon_size;
267 std::string title;
268
272 void BuildTable()
273 {
274 this->rows.clear();
275 this->title = std::string{};
276 auto lt = LeagueTable::GetIfValid(this->table);
277 if (lt == nullptr) return;
278
279 /* We store title in the window class so we can safely reference the string later */
280 this->title = lt->title;
281
282 std::vector<const LeagueTableElement *> elements;
283 for (LeagueTableElement *lte : LeagueTableElement::Iterate()) {
284 if (lte->table == this->table) {
285 elements.push_back(lte);
286 }
287 }
288 std::sort(elements.begin(), elements.end(), [](auto a, auto b) { return a->rating > b->rating; });
289
290 /* Calculate rank, companies with the same rating share the ranks */
291 uint rank = 0;
292 for (uint i = 0; i != elements.size(); i++) {
293 auto *lte = elements[i];
294 if (i > 0 && elements[i - 1]->rating != lte->rating) rank = i;
295 this->rows.emplace_back(std::make_pair(rank, lte));
296 }
297 }
298
299 public:
300 ScriptLeagueWindow(WindowDesc *desc, LeagueTableID table) : Window(desc)
301 {
302 this->table = table;
303 this->BuildTable();
304 this->InitNested(table);
305 }
306
307 void SetStringParameters(WidgetID widget) const override
308 {
309 if (widget != WID_SLT_CAPTION) return;
310 SetDParamStr(0, this->title);
311 }
312
313 void OnPaint() override
314 {
315 this->DrawWidgets();
316 }
317
318 void DrawWidget(const Rect &r, WidgetID widget) const override
319 {
320 if (widget != WID_SLT_BACKGROUND) return;
321
322 auto lt = LeagueTable::GetIfValid(this->table);
323 if (lt == nullptr) return;
324
325 Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
326
327 if (!lt->header.empty()) {
328 SetDParamStr(0, lt->header);
329 ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK) + WidgetDimensions::scaled.vsep_wide;
330 }
331
332 int icon_y_offset = (this->line_height - this->icon_size.height) / 2;
333 int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
334
335 /* Calculate positions.of the columns */
336 bool rtl = _current_text_dir == TD_RTL;
337 int spacer = WidgetDimensions::scaled.hsep_wide;
338 Rect rank_rect = ir.WithWidth(this->rank_width, rtl);
339 Rect icon_rect = ir.Indent(this->rank_width + (rtl ? 0 : spacer), rtl).WithWidth(this->icon_size.width, rtl);
340 Rect text_rect = ir.Indent(this->rank_width + spacer + this->icon_size.width, rtl).WithWidth(this->text_width, rtl);
341 Rect score_rect = ir.Indent(this->rank_width + 2 * spacer + this->icon_size.width + this->text_width, rtl).WithWidth(this->score_width, rtl);
342
343 for (auto [rank, lte] : this->rows) {
344 SetDParam(0, rank + 1);
345 DrawString(rank_rect.left, rank_rect.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_RANK);
346 if (this->icon_size.width > 0 && lte->company != INVALID_COMPANY) DrawCompanyIcon(lte->company, icon_rect.left, ir.top + icon_y_offset);
347 SetDParamStr(0, lte->text);
348 DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK);
349 SetDParamStr(0, lte->score);
350 DrawString(score_rect.left, score_rect.right, ir.top + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK, SA_RIGHT);
351 ir.top += this->line_height;
352 }
353
354 if (!lt->footer.empty()) {
355 ir.top += WidgetDimensions::scaled.vsep_wide;
356 SetDParamStr(0, lt->footer);
357 ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
358 }
359 }
360
361 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
362 {
363 if (widget != WID_SLT_BACKGROUND) return;
364
365 auto lt = LeagueTable::GetIfValid(this->table);
366 if (lt == nullptr) return;
367
368 this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
369 this->line_height = std::max<int>(this->icon_size.height + WidgetDimensions::scaled.fullbevel.Vertical(), GetCharacterHeight(FS_NORMAL));
370
371 /* Calculate maximum width of every column */
372 this->rank_width = this->text_width = this->score_width = 0;
373 bool show_icon_column = false;
374 for (auto [rank, lte] : this->rows) {
375 SetDParam(0, rank + 1);
376 this->rank_width = std::max(this->rank_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_RANK).width);
377 SetDParamStr(0, lte->text);
378 this->text_width = std::max(this->text_width, GetStringBoundingBox(STR_JUST_RAW_STRING).width);
379 SetDParamStr(0, lte->score);
380 this->score_width = std::max(this->score_width, GetStringBoundingBox(STR_JUST_RAW_STRING).width);
381 if (lte->company != INVALID_COMPANY) show_icon_column = true;
382 }
383
384 if (!show_icon_column) this->icon_size.width = 0;
385 else this->icon_size.width += WidgetDimensions::scaled.hsep_wide;
386
387 size->width = this->rank_width + this->icon_size.width + this->text_width + this->score_width + WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.hsep_wide * 2;
388 size->height = this->line_height * std::max<uint>(3u, (unsigned)this->rows.size()) + WidgetDimensions::scaled.framerect.Vertical();
389
390 if (!lt->header.empty()) {
391 SetDParamStr(0, lt->header);
392 this->header_height = GetStringHeight(STR_JUST_RAW_STRING, size->width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide;
393 size->height += header_height;
394 } else this->header_height = 0;
395
396 if (!lt->footer.empty()) {
397 SetDParamStr(0, lt->footer);
398 size->height += GetStringHeight(STR_JUST_RAW_STRING, size->width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide;
399 }
400 }
401
402 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
403 {
404 if (widget != WID_SLT_BACKGROUND) return;
405
406 auto *wid = this->GetWidget<NWidgetResizeBase>(WID_SLT_BACKGROUND);
407 int index = (pt.y - WidgetDimensions::scaled.framerect.top - wid->pos_y - this->header_height) / this->line_height;
408 if (index >= 0 && (uint)index < this->rows.size()) {
409 auto lte = this->rows[index].second;
410 HandleLinkClick(lte->link);
411 }
412 }
413
419 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
420 {
421 this->BuildTable();
422 this->ReInit();
423 }
424 };
425
426 static constexpr NWidgetPart _nested_script_league_widgets[] = {
427 NWidget(NWID_HORIZONTAL),
428 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
429 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SLT_CAPTION), SetDataTip(STR_JUST_RAW_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
430 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
431 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
432 EndContainer(),
433 NWidget(WWT_PANEL, COLOUR_BROWN, WID_SLT_BACKGROUND), SetMinimalSize(400, 0), SetMinimalTextLines(15, WidgetDimensions::unscaled.framerect.Vertical()),
434 EndContainer(),
435 };
436
437 static WindowDesc _script_league_desc(__FILE__, __LINE__,
438 WDP_AUTO, "script_league", 0, 0,
439 WC_COMPANY_LEAGUE, WC_NONE,
440 0,
441 std::begin(_nested_script_league_widgets), std::end(_nested_script_league_widgets)
442 );
443
444 void ShowScriptLeagueTable(LeagueTableID table)
445 {
446 if (!LeagueTable::IsValidID(table)) return;
447 AllocateWindowDescFront<ScriptLeagueWindow>(&_script_league_desc, table);
448 }
449
450 void ShowFirstLeagueTable()
451 {
452 auto it = LeagueTable::Iterate();
453 if (!it.empty()) {
454 ShowScriptLeagueTable((*it.begin())->index);
455 } else {
456 ShowPerformanceLeagueTable();
457 }
458 }
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2509
LeagueTableElement
Struct about league table elements.
Definition: league_base.h:31
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:156
PerformanceLeagueWindow
Definition: league_gui.cpp:56
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
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
Pool::PoolItem<&_league_table_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:350
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
company_base.h
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
company_gui.h
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
GUIList< const Company * >
league_gui.h
ScriptLeagueWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: league_gui.cpp:313
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:238
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
PerformanceLeagueWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: league_gui.cpp:95
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1153
ScriptLeagueWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: league_gui.cpp:419
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
ScriptLeagueWindow::rank_width
uint rank_width
The width of the rank ordinal.
Definition: league_gui.cpp:261
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
town.h
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:340
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
WC_COMPANY_LEAGUE
@ WC_COMPANY_LEAGUE
Company league window; Window numbers:
Definition: window_type.h:564
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1040
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:387
PerformanceLeagueWindow::BuildCompanyList
void BuildCompanyList()
(Re)Build the company league list
Definition: league_gui.cpp:67
LT_INDUSTRY
@ LT_INDUSTRY
Link an industry.
Definition: league_type.h:17
LT_NONE
@ LT_NONE
No link.
Definition: league_type.h:15
WindowDesc
High level window description.
Definition: window_gui.h:153
PerformanceLeagueWindow::icon
Dimension icon
Dimension of the company icon.
Definition: league_gui.cpp:62
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:63
window_gui.h
ScriptLeagueWindow::icon_size
Dimension icon_size
Dimenion of the company icon.
Definition: league_gui.cpp:266
tile_map.h
LT_STORY_PAGE
@ LT_STORY_PAGE
Link a story page.
Definition: league_type.h:20
GUIList::NeedResort
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
Definition: sortlist_type.h:220
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:732
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1747
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:234
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:953
WID_SLT_BACKGROUND
@ WID_SLT_BACKGROUND
Background of the window.
Definition: league_widget.h:21
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1260
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
industry.h
safeguards.h
sortlist_type.h
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
GetStringHeight
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:701
ScriptLeagueWindow::line_height
int line_height
Height of the text lines.
Definition: league_gui.cpp:265
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
LeagueTableID
uint8_t LeagueTableID
ID of a league table.
Definition: league_type.h:32
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
league_base.h
LT_TILE
@ LT_TILE
Link a tile.
Definition: league_type.h:16
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
PerformanceLeagueWindow::text_width
uint text_width
The width of the actual text.
Definition: league_gui.cpp:60
viewport_func.h
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
WID_PLT_BACKGROUND
@ WID_PLT_BACKGROUND
Background of the window.
Definition: league_widget.h:15
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:159
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition: tile_map.h:161
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:937
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:395
PerformanceLeagueWindow::line_height
int line_height
Height of the text lines.
Definition: league_gui.cpp:61
PerformanceLeagueWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: league_gui.cpp:180
DrawStringMultiLine
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:771
LT_TOWN
@ LT_TOWN
Link a town.
Definition: league_type.h:18
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:388
strings_func.h
CompanyEconomyEntry::performance_history
int32_t performance_history
Company score (scale 0-1000)
Definition: company_base.h:28
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
ScriptLeagueWindow::score_width
uint score_width
The width of the score text.
Definition: league_gui.cpp:263
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
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
ScriptLeagueWindow::text_width
uint text_width
The width of the actual text.
Definition: league_gui.cpp:262
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
ShowStoryBook
void ShowStoryBook(CompanyID company, uint16_t page_id=INVALID_STORY_PAGE, bool centered=false)
Raise or create the story book window for company, at page page_id.
Definition: story_gui.cpp:1053
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel thickness.
Definition: window_gui.h:41
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
WID_SLT_CAPTION
@ WID_SLT_CAPTION
Caption of the window.
Definition: league_widget.h:20
PerformanceLeagueWindow::ordinal_width
uint ordinal_width
The width of the ordinal number.
Definition: league_gui.cpp:59
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1099
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:405
PerformanceLeagueWindow::PerformanceSorter
static bool PerformanceSorter(const Company *const &c1, const Company *const &c2)
Sort the company league by performance history.
Definition: league_gui.cpp:82
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:654
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
Link
Definition: league_type.h:25
gui.h
Window
Data structure for an opened window.
Definition: window_gui.h:267
Pool::PoolItem<&_industry_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:328
ScriptLeagueWindow::header_height
uint header_height
Height of the table header.
Definition: league_gui.cpp:264
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1164
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1111
ScriptLeagueWindow::BuildTable
void BuildTable()
Rebuild the company league list.
Definition: league_gui.cpp:272
story_base.h
ShowCompany
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
Definition: company_gui.cpp:2643
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
Company
Definition: company_base.h:129
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:268
CompanyProperties::old_economy
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Definition: company_base.h:112
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
PerformanceLeagueWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: league_gui.cpp:168
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
LT_COMPANY
@ LT_COMPANY
Link a company.
Definition: league_type.h:19
league_widget.h
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:848
ScriptLeagueWindow
Definition: league_gui.cpp:257
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66