OpenTTD Source  20241120-master-g6d3adc6169
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 
25 #include "widgets/league_widget.h"
26 
27 #include "table/strings.h"
28 #include "table/sprites.h"
29 
30 #include "safeguards.h"
31 
32 
33 static 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 
52 static inline StringID GetPerformanceTitleFromValue(uint value)
53 {
54  return _performance_titles[std::min(value, 1000u) >> 6];
55 }
56 
58 private:
59  GUIList<const Company *> companies;
61  uint text_width;
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  {
86  }
87 
88 public:
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];
119  SetDParam(0, i + 1);
120  DrawString(ordinal.left, ordinal.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_RANK);
121 
122  DrawCompanyIcon(c->index, icon_left, ir.top + icon_y_offset);
123 
124  SetDParam(0, c->index);
125  SetDParam(1, c->index);
126  SetDParam(2, GetPerformanceTitleFromValue(c->old_economy[0].performance_history));
127  DrawString(text.left, text.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_NAME);
128  ir.top += this->line_height;
129  }
130  }
131 
132  void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
133  {
134  if (widget != WID_PLT_BACKGROUND) return;
135 
136  this->ordinal_width = 0;
137  for (uint i = 0; i < MAX_COMPANIES; i++) {
138  SetDParam(0, i + 1);
139  this->ordinal_width = std::max(this->ordinal_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_RANK).width);
140  }
141  this->ordinal_width += WidgetDimensions::scaled.hsep_wide; // Keep some extra spacing
142 
143  uint widest_width = 0;
144  StringID widest_title = STR_NULL;
145  for (auto title : _performance_titles) {
146  uint width = GetStringBoundingBox(title).width;
147  if (width > widest_width) {
148  widest_title = title;
149  widest_width = width;
150  }
151  }
152 
153  this->icon = GetSpriteSize(SPR_COMPANY_ICON);
154  this->line_height = std::max<int>(this->icon.height + WidgetDimensions::scaled.vsep_normal, GetCharacterHeight(FS_NORMAL));
155 
156  for (const Company *c : Company::Iterate()) {
157  SetDParam(0, c->index);
158  SetDParam(1, c->index);
159  SetDParam(2, widest_title);
160  widest_width = std::max(widest_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_NAME).width);
161  }
162 
163  this->text_width = widest_width + WidgetDimensions::scaled.hsep_indent * 3; // Keep some extra spacing
164 
165  size.width = WidgetDimensions::scaled.framerect.Horizontal() + this->ordinal_width + this->icon.width + this->text_width + WidgetDimensions::scaled.hsep_wide;
166  size.height = this->line_height * MAX_COMPANIES + WidgetDimensions::scaled.framerect.Vertical();
167  }
168 
169  void OnGameTick() override
170  {
171  if (this->companies.NeedResort()) {
172  this->SetDirty();
173  }
174  }
175 
181  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
182  {
183  if (data == 0) {
184  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
185  this->companies.ForceRebuild();
186  } else {
187  this->companies.ForceResort();
188  }
189  }
190 };
191 
192 static constexpr NWidgetPart _nested_performance_league_widgets[] = {
194  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
195  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_COMPANY_LEAGUE_TABLE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
196  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
197  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
198  EndContainer(),
199  NWidget(WWT_PANEL, COLOUR_BROWN, WID_PLT_BACKGROUND), SetMinimalSize(400, 0), SetMinimalTextLines(15, WidgetDimensions::unscaled.framerect.Vertical()),
200  EndContainer(),
201 };
202 
203 static WindowDesc _performance_league_desc(
204  WDP_AUTO, "performance_league", 0, 0,
206  0,
207  _nested_performance_league_widgets
208 );
209 
210 void ShowPerformanceLeagueTable()
211 {
212  AllocateWindowDescFront<PerformanceLeagueWindow>(_performance_league_desc, 0);
213 }
214 
215 static void HandleLinkClick(Link link)
216 {
217  TileIndex xy;
218  switch (link.type) {
219  case LT_NONE: return;
220 
221  case LT_TILE:
222  if (!IsValidTile(link.target)) return;
223  xy = link.target;
224  break;
225 
226  case LT_INDUSTRY:
227  if (!Industry::IsValidID(link.target)) return;
228  xy = Industry::Get(link.target)->location.tile;
229  break;
230 
231  case LT_TOWN:
232  if (!Town::IsValidID(link.target)) return;
233  xy = Town::Get(link.target)->xy;
234  break;
235 
236  case LT_COMPANY:
237  ShowCompany((CompanyID)link.target);
238  return;
239 
240  case LT_STORY_PAGE: {
241  if (!StoryPage::IsValidID(link.target)) return;
242  CompanyID story_company = StoryPage::Get(link.target)->company;
243  ShowStoryBook(story_company, link.target);
244  return;
245  }
246 
247  default: NOT_REACHED();
248  }
249 
250  if (_ctrl_pressed) {
252  } else {
254  }
255 }
256 
257 
258 class ScriptLeagueWindow : public Window {
259 private:
260  LeagueTableID table;
261  std::vector<std::pair<uint, const LeagueTableElement *>> rows;
262  uint rank_width;
263  uint text_width;
264  uint score_width;
268  std::string title;
269 
273  void BuildTable()
274  {
275  this->rows.clear();
276  this->title = std::string{};
277  auto lt = LeagueTable::GetIfValid(this->table);
278  if (lt == nullptr) return;
279 
280  /* We store title in the window class so we can safely reference the string later */
281  this->title = lt->title;
282 
283  std::vector<const LeagueTableElement *> elements;
285  if (lte->table == this->table) {
286  elements.push_back(lte);
287  }
288  }
289  std::sort(elements.begin(), elements.end(), [](auto a, auto b) { return a->rating > b->rating; });
290 
291  /* Calculate rank, companies with the same rating share the ranks */
292  uint rank = 0;
293  for (uint i = 0; i != elements.size(); i++) {
294  auto *lte = elements[i];
295  if (i > 0 && elements[i - 1]->rating != lte->rating) rank = i;
296  this->rows.emplace_back(rank, lte);
297  }
298  }
299 
300 public:
301  ScriptLeagueWindow(WindowDesc &desc, LeagueTableID table) : Window(desc)
302  {
303  this->table = table;
304  this->BuildTable();
305  this->InitNested(table);
306  }
307 
308  void SetStringParameters(WidgetID widget) const override
309  {
310  if (widget != WID_SLT_CAPTION) return;
311  SetDParamStr(0, this->title);
312  }
313 
314  void OnPaint() override
315  {
316  this->DrawWidgets();
317  }
318 
319  void DrawWidget(const Rect &r, WidgetID widget) const override
320  {
321  if (widget != WID_SLT_BACKGROUND) return;
322 
323  auto lt = LeagueTable::GetIfValid(this->table);
324  if (lt == nullptr) return;
325 
326  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
327 
328  if (!lt->header.empty()) {
329  SetDParamStr(0, lt->header);
330  ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK) + WidgetDimensions::scaled.vsep_wide;
331  }
332 
333  int icon_y_offset = (this->line_height - this->icon_size.height) / 2;
334  int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
335 
336  /* Calculate positions.of the columns */
337  bool rtl = _current_text_dir == TD_RTL;
338  int spacer = WidgetDimensions::scaled.hsep_wide;
339  Rect rank_rect = ir.WithWidth(this->rank_width, rtl);
340  Rect icon_rect = ir.Indent(this->rank_width + (rtl ? 0 : spacer), rtl).WithWidth(this->icon_size.width, rtl);
341  Rect text_rect = ir.Indent(this->rank_width + spacer + this->icon_size.width, rtl).WithWidth(this->text_width, rtl);
342  Rect score_rect = ir.Indent(this->rank_width + 2 * spacer + this->icon_size.width + this->text_width, rtl).WithWidth(this->score_width, rtl);
343 
344  for (auto [rank, lte] : this->rows) {
345  SetDParam(0, rank + 1);
346  DrawString(rank_rect.left, rank_rect.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_RANK);
347  if (this->icon_size.width > 0 && lte->company != INVALID_COMPANY) DrawCompanyIcon(lte->company, icon_rect.left, ir.top + icon_y_offset);
348  SetDParamStr(0, lte->text);
349  DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK);
350  SetDParamStr(0, lte->score);
351  DrawString(score_rect.left, score_rect.right, ir.top + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK, SA_RIGHT);
352  ir.top += this->line_height;
353  }
354 
355  if (!lt->footer.empty()) {
357  SetDParamStr(0, lt->footer);
358  ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
359  }
360  }
361 
362  void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
363  {
364  if (widget != WID_SLT_BACKGROUND) return;
365 
366  auto lt = LeagueTable::GetIfValid(this->table);
367  if (lt == nullptr) return;
368 
369  this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
370  this->line_height = std::max<int>(this->icon_size.height + WidgetDimensions::scaled.fullbevel.Vertical(), GetCharacterHeight(FS_NORMAL));
371 
372  /* Calculate maximum width of every column */
373  this->rank_width = this->text_width = this->score_width = 0;
374  bool show_icon_column = false;
375  for (auto [rank, lte] : this->rows) {
376  SetDParam(0, rank + 1);
377  this->rank_width = std::max(this->rank_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_RANK).width);
378  SetDParamStr(0, lte->text);
379  this->text_width = std::max(this->text_width, GetStringBoundingBox(STR_JUST_RAW_STRING).width);
380  SetDParamStr(0, lte->score);
381  this->score_width = std::max(this->score_width, GetStringBoundingBox(STR_JUST_RAW_STRING).width);
382  if (lte->company != INVALID_COMPANY) show_icon_column = true;
383  }
384 
385  if (!show_icon_column) this->icon_size.width = 0;
386  else this->icon_size.width += WidgetDimensions::scaled.hsep_wide;
387 
388  size.width = this->rank_width + this->icon_size.width + this->text_width + this->score_width + WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.hsep_wide * 2;
389  size.height = this->line_height * std::max<uint>(3u, (unsigned)this->rows.size()) + WidgetDimensions::scaled.framerect.Vertical();
390 
391  if (!lt->header.empty()) {
392  SetDParamStr(0, lt->header);
393  this->header_height = GetStringHeight(STR_JUST_RAW_STRING, size.width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide;
394  size.height += header_height;
395  } else this->header_height = 0;
396 
397  if (!lt->footer.empty()) {
398  SetDParamStr(0, lt->footer);
399  size.height += GetStringHeight(STR_JUST_RAW_STRING, size.width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide;
400  }
401  }
402 
403  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
404  {
405  if (widget != WID_SLT_BACKGROUND) return;
406 
407  auto *wid = this->GetWidget<NWidgetResizeBase>(WID_SLT_BACKGROUND);
408  int index = (pt.y - WidgetDimensions::scaled.framerect.top - wid->pos_y - this->header_height) / this->line_height;
409  if (index >= 0 && (uint)index < this->rows.size()) {
410  auto lte = this->rows[index].second;
411  HandleLinkClick(lte->link);
412  }
413  }
414 
420  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
421  {
422  this->BuildTable();
423  this->ReInit();
424  }
425 };
426 
427 static constexpr NWidgetPart _nested_script_league_widgets[] = {
429  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
430  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SLT_CAPTION), SetDataTip(STR_JUST_RAW_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
431  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
432  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
433  EndContainer(),
434  NWidget(WWT_PANEL, COLOUR_BROWN, WID_SLT_BACKGROUND), SetMinimalSize(400, 0), SetMinimalTextLines(15, WidgetDimensions::unscaled.framerect.Vertical()),
435  EndContainer(),
436 };
437 
438 static WindowDesc _script_league_desc(
439  WDP_AUTO, "script_league", 0, 0,
441  0,
442  _nested_script_league_widgets
443 );
444 
445 void ShowScriptLeagueTable(LeagueTableID table)
446 {
447  if (!LeagueTable::IsValidID(table)) return;
448  AllocateWindowDescFront<ScriptLeagueWindow>(_script_league_desc, table);
449 }
450 
451 void ShowFirstLeagueTable()
452 {
453  auto it = LeagueTable::Iterate();
454  if (!it.empty()) {
455  ShowScriptLeagueTable((*it.begin())->index);
456  } else {
457  ShowPerformanceLeagueTable();
458  }
459 }
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 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:181
int line_height
Height of the text lines.
Definition: league_gui.cpp:62
void BuildCompanyList()
(Re)Build the company league list
Definition: league_gui.cpp:68
void OnPaint() override
The window must be repainted.
Definition: league_gui.cpp:96
uint ordinal_width
The width of the ordinal number.
Definition: league_gui.cpp:60
Dimension icon
Dimension of the company icon.
Definition: league_gui.cpp:63
void OnGameTick() override
Called once per (game) tick.
Definition: league_gui.cpp:169
uint text_width
The width of the actual text.
Definition: league_gui.cpp:61
static bool PerformanceSorter(const Company *const &c1, const Company *const &c2)
Sort the company league by performance history.
Definition: league_gui.cpp:83
int line_height
Height of the text lines.
Definition: league_gui.cpp:266
uint header_height
Height of the table header.
Definition: league_gui.cpp:265
uint text_width
The width of the actual text.
Definition: league_gui.cpp:263
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:420
void OnPaint() override
The window must be repainted.
Definition: league_gui.cpp:314
uint score_width
The width of the score text.
Definition: league_gui.cpp:264
uint rank_width
The width of the rank ordinal.
Definition: league_gui.cpp:262
Dimension icon_size
Dimenion of the company icon.
Definition: league_gui.cpp:267
void BuildTable()
Rebuild the company league list.
Definition: league_gui.cpp:273
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
RectPadding fullbevel
Always-scaled bevel thickness.
Definition: window_gui.h:41
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
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.
Owner
Enum for all companies/owners.
Definition: company_type.h:18
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
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:704
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:922
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:851
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:657
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:774
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:345
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:209
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1202
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1137
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1309
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1191
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:1149
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:940
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
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:1051
Base of all industries.
LeagueTable base class.
League table GUI functions.
uint8_t LeagueTableID
ID of a league table.
Definition: league_type.h:32
@ LT_COMPANY
Link a company.
Definition: league_type.h:19
@ LT_STORY_PAGE
Link a story page.
Definition: league_type.h:20
@ LT_TILE
Link a tile.
Definition: league_type.h:16
@ LT_NONE
No link.
Definition: league_type.h:15
@ LT_INDUSTRY
Link an industry.
Definition: league_type.h:17
@ LT_TOWN
Link a town.
Definition: league_type.h:18
Types related to the graph widgets.
@ WID_PLT_BACKGROUND
Background of the window.
Definition: league_widget.h:15
@ WID_SLT_BACKGROUND
Background of the window.
Definition: league_widget.h:21
@ WID_SLT_CAPTION
Caption of the window.
Definition: league_widget.h:20
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.
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
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
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:357
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
int32_t performance_history
Company score (scale 0-1000)
Definition: company_base.h:28
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Definition: company_base.h:116
Dimensions (a width and height) of a rectangle in 2D.
Struct about league table elements.
Definition: league_base.h:31
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1075
Coordinates of a point in 2D.
Tindex index
Index of this pool item.
Definition: pool_type.hpp:238
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:369
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:328
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:350
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:388
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:159
Data structure for an opened window.
Definition: window_gui.h:273
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:952
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
ResizeInfo resize
Resize information.
Definition: window_gui.h:314
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1746
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:311
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:302
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.
Definition: viewport.cpp:2515
Functions related to (drawing on) viewports.
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
Functions, definitions and such used only by the GUI.
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:147
int WidgetID
Widget ID.
Definition: window_type.h:18
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:737
@ WC_COMPANY_LEAGUE
Company league window; Window numbers:
Definition: window_type.h:563
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45