OpenTTD Source  13.2.1
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 
57 private:
58  GUIList<const Company *> companies;
60  uint text_width;
63 
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  {
85  }
86 
87 public:
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, int 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 - FONT_HEIGHT_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  DrawString(ordinal.left, ordinal.right, ir.top + text_y_offset, i + STR_ORDINAL_NUMBER_1ST, i == 0 ? TC_WHITE : TC_YELLOW);
119 
120  DrawCompanyIcon(c->index, icon_left, ir.top + icon_y_offset);
121 
122  SetDParam(0, c->index);
123  SetDParam(1, c->index);
124  SetDParam(2, GetPerformanceTitleFromValue(c->old_economy[0].performance_history));
125  DrawString(text.left, text.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_NAME);
126  ir.top += this->line_height;
127  }
128  }
129 
130  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
131  {
132  if (widget != WID_PLT_BACKGROUND) return;
133 
134  this->ordinal_width = 0;
135  for (uint i = 0; i < MAX_COMPANIES; i++) {
136  this->ordinal_width = std::max(this->ordinal_width, GetStringBoundingBox(STR_ORDINAL_NUMBER_1ST + i).width);
137  }
138  this->ordinal_width += WidgetDimensions::scaled.hsep_wide; // Keep some extra spacing
139 
140  uint widest_width = 0;
141  uint widest_title = 0;
142  for (uint i = 0; i < lengthof(_performance_titles); i++) {
143  uint width = GetStringBoundingBox(_performance_titles[i]).width;
144  if (width > widest_width) {
145  widest_title = i;
146  widest_width = width;
147  }
148  }
149 
150  this->icon = GetSpriteSize(SPR_COMPANY_ICON);
151  this->line_height = std::max<int>(this->icon.height + WidgetDimensions::scaled.vsep_normal, FONT_HEIGHT_NORMAL);
152 
153  for (const Company *c : Company::Iterate()) {
154  SetDParam(0, c->index);
155  SetDParam(1, c->index);
156  SetDParam(2, _performance_titles[widest_title]);
157  widest_width = std::max(widest_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_NAME).width);
158  }
159 
160  this->text_width = widest_width + WidgetDimensions::scaled.hsep_indent * 3; // Keep some extra spacing
161 
162  size->width = WidgetDimensions::scaled.framerect.Horizontal() + this->ordinal_width + this->icon.width + this->text_width + WidgetDimensions::scaled.hsep_wide;
163  size->height = this->line_height * MAX_COMPANIES + WidgetDimensions::scaled.framerect.Vertical();
164  }
165 
166  void OnGameTick() override
167  {
168  if (this->companies.NeedResort()) {
169  this->SetDirty();
170  }
171  }
172 
178  void OnInvalidateData(int data = 0, bool gui_scope = true) override
179  {
180  if (data == 0) {
181  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
182  this->companies.ForceRebuild();
183  } else {
184  this->companies.ForceResort();
185  }
186  }
187 };
188 
189 static const NWidgetPart _nested_performance_league_widgets[] = {
191  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
192  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_COMPANY_LEAGUE_TABLE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
193  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
194  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
195  EndContainer(),
196  NWidget(WWT_PANEL, COLOUR_BROWN, WID_PLT_BACKGROUND), SetMinimalSize(400, 0), SetMinimalTextLines(15, WidgetDimensions::unscaled.framerect.Vertical()),
197 };
198 
199 static WindowDesc _performance_league_desc(
200  WDP_AUTO, "league", 0, 0,
202  0,
203  _nested_performance_league_widgets, lengthof(_nested_performance_league_widgets)
204 );
205 
206 void ShowPerformanceLeagueTable()
207 {
208  AllocateWindowDescFront<PerformanceLeagueWindow>(&_performance_league_desc, 0);
209 }
210 
211 static void HandleLinkClick(Link link)
212 {
213  TileIndex xy;
214  switch (link.type) {
215  case LT_NONE: return;
216 
217  case LT_TILE:
218  if (!IsValidTile(link.target)) return;
219  xy = link.target;
220  break;
221 
222  case LT_INDUSTRY:
223  if (!Industry::IsValidID(link.target)) return;
224  xy = Industry::Get(link.target)->location.tile;
225  break;
226 
227  case LT_TOWN:
228  if (!Town::IsValidID(link.target)) return;
229  xy = Town::Get(link.target)->xy;
230  break;
231 
232  case LT_COMPANY:
233  ShowCompany((CompanyID)link.target);
234  return;
235 
236  case LT_STORY_PAGE: {
237  if (!StoryPage::IsValidID(link.target)) return;
238  CompanyID story_company = StoryPage::Get(link.target)->company;
239  ShowStoryBook(story_company, link.target);
240  return;
241  }
242 
243  default: NOT_REACHED();
244  }
245 
246  if (_ctrl_pressed) {
248  } else {
250  }
251 }
252 
253 
254 class ScriptLeagueWindow : public Window {
255 private:
256  LeagueTableID table;
257  std::vector<std::pair<uint, const LeagueTableElement *>> rows;
258  uint rank_width;
259  uint text_width;
260  uint score_width;
264  std::string title;
265 
269  void BuildTable()
270  {
271  this->rows.clear();
272  this->title = std::string{};
273  auto lt = LeagueTable::GetIfValid(this->table);
274  if (lt == nullptr) return;
275 
276  /* We store title in the window class so we can safely reference the string later */
277  this->title = lt->title;
278 
279  std::vector<const LeagueTableElement *> elements;
281  if (lte->table == this->table) {
282  elements.push_back(lte);
283  }
284  }
285  std::sort(elements.begin(), elements.end(), [](auto a, auto b) { return a->rating > b->rating; });
286 
287  /* Calculate rank, companies with the same rating share the ranks */
288  uint rank = 0;
289  for (uint i = 0; i != elements.size(); i++) {
290  auto *lte = elements[i];
291  if (i > 0 && elements[i - 1]->rating != lte->rating) rank = i;
292  this->rows.emplace_back(std::make_pair(rank, lte));
293  }
294  }
295 
296 public:
297  ScriptLeagueWindow(WindowDesc *desc, LeagueTableID table) : Window(desc)
298  {
299  this->table = table;
300  this->BuildTable();
301  this->InitNested(table);
302  }
303 
304  void SetStringParameters(int widget) const override
305  {
306  if (widget != WID_SLT_CAPTION) return;
307  SetDParamStr(0, this->title);
308  }
309 
310  void OnPaint() override
311  {
312  this->DrawWidgets();
313  }
314 
315  void DrawWidget(const Rect &r, int widget) const override
316  {
317  if (widget != WID_SLT_BACKGROUND) return;
318 
319  auto lt = LeagueTable::GetIfValid(this->table);
320  if (lt == nullptr) return;
321 
322  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
323 
324  if (!lt->header.empty()) {
325  SetDParamStr(0, lt->header);
326  ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK) + WidgetDimensions::scaled.vsep_wide;
327  }
328 
329  int icon_y_offset = (this->line_height - this->icon_size.height) / 2;
330  int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
331 
332  /* Calculate positions.of the columns */
333  bool rtl = _current_text_dir == TD_RTL;
334  int spacer = WidgetDimensions::scaled.hsep_wide;
335  Rect rank_rect = ir.WithWidth(this->rank_width, rtl);
336  Rect icon_rect = ir.Indent(this->rank_width + (rtl ? 0 : spacer), rtl).WithWidth(this->icon_size.width, rtl);
337  Rect text_rect = ir.Indent(this->rank_width + spacer + this->icon_size.width, rtl).WithWidth(this->text_width, rtl);
338  Rect score_rect = ir.Indent(this->rank_width + 2 * spacer + this->icon_size.width + this->text_width, rtl).WithWidth(this->score_width, rtl);
339 
340  for (auto [rank, lte] : this->rows) {
341  DrawString(rank_rect.left, rank_rect.right, ir.top + text_y_offset, rank + STR_ORDINAL_NUMBER_1ST, rank == 0 ? TC_WHITE : TC_YELLOW);
342  if (this->icon_size.width > 0 && lte->company != INVALID_COMPANY) DrawCompanyIcon(lte->company, icon_rect.left, ir.top + icon_y_offset);
343  SetDParamStr(0, lte->text);
344  DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK);
345  SetDParamStr(0, lte->score);
346  DrawString(score_rect.left, score_rect.right, ir.top + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK, SA_RIGHT);
347  ir.top += this->line_height;
348  }
349 
350  if (!lt->footer.empty()) {
352  SetDParamStr(0, lt->footer);
353  ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
354  }
355  }
356 
357  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
358  {
359  if (widget != WID_SLT_BACKGROUND) return;
360 
361  auto lt = LeagueTable::GetIfValid(this->table);
362  if (lt == nullptr) return;
363 
364  this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
365  this->line_height = std::max<int>(this->icon_size.height + WidgetDimensions::scaled.fullbevel.Vertical(), FONT_HEIGHT_NORMAL);
366 
367  /* Calculate maximum width of every column */
368  this->rank_width = this->text_width = this->score_width = 0;
369  bool show_icon_column = false;
370  for (auto [rank, lte] : this->rows) {
371  this->rank_width = std::max(this->rank_width, GetStringBoundingBox(STR_ORDINAL_NUMBER_1ST + rank).width);
372  SetDParamStr(0, lte->text);
373  this->text_width = std::max(this->text_width, GetStringBoundingBox(STR_JUST_RAW_STRING).width);
374  SetDParamStr(0, lte->score);
375  this->score_width = std::max(this->score_width, GetStringBoundingBox(STR_JUST_RAW_STRING).width);
376  if (lte->company != INVALID_COMPANY) show_icon_column = true;
377  }
378 
379  if (!show_icon_column) this->icon_size.width = 0;
380  else this->icon_size.width += WidgetDimensions::scaled.hsep_wide;
381 
382  size->width = this->rank_width + this->icon_size.width + this->text_width + this->score_width + WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.hsep_wide * 2;
383  size->height = this->line_height * std::max<uint>(3u, (unsigned)this->rows.size()) + WidgetDimensions::scaled.framerect.Vertical();
384 
385  if (!lt->header.empty()) {
386  SetDParamStr(0, lt->header);
387  this->header_height = GetStringHeight(STR_JUST_RAW_STRING, size->width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide;
388  size->height += header_height;
389  } else this->header_height = 0;
390 
391  if (!lt->footer.empty()) {
392  SetDParamStr(0, lt->footer);
393  size->height += GetStringHeight(STR_JUST_RAW_STRING, size->width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide;
394  }
395  }
396 
397  void OnClick(Point pt, int widget, int click_count) override
398  {
399  if (widget != WID_SLT_BACKGROUND) return;
400 
401  auto *wid = this->GetWidget<NWidgetResizeBase>(WID_SLT_BACKGROUND);
402  int index = (pt.y - WidgetDimensions::scaled.framerect.top - wid->pos_y - this->header_height) / this->line_height;
403  if (index >= 0 && (uint)index < this->rows.size()) {
404  auto lte = this->rows[index].second;
405  HandleLinkClick(lte->link);
406  }
407  }
408 
414  void OnInvalidateData(int data = 0, bool gui_scope = true) override
415  {
416  this->BuildTable();
417  this->ReInit();
418  }
419 };
420 
421 static const NWidgetPart _nested_script_league_widgets[] = {
423  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
424  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SLT_CAPTION), SetDataTip(STR_BLACK_RAW_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
425  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
426  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
427  EndContainer(),
428  NWidget(WWT_PANEL, COLOUR_BROWN, WID_SLT_BACKGROUND), SetMinimalSize(400, 0), SetMinimalTextLines(15, WidgetDimensions::scaled.framerect.Vertical()),
429 };
430 
431 static WindowDesc _script_league_desc(
432  WDP_AUTO, "league", 0, 0,
434  0,
435  _nested_script_league_widgets, lengthof(_nested_script_league_widgets)
436 );
437 
438 void ShowScriptLeagueTable(LeagueTableID table)
439 {
440  if (!LeagueTable::IsValidID(table)) return;
441  AllocateWindowDescFront<ScriptLeagueWindow>(&_script_league_desc, table);
442 }
443 
444 void ShowFirstLeagueTable()
445 {
446  auto it = LeagueTable::Iterate();
447  if (!it.empty()) {
448  ShowScriptLeagueTable((*it.begin())->index);
449  } else {
450  ShowPerformanceLeagueTable();
451  }
452 }
PerformanceLeagueWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: league_gui.cpp:178
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2456
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:168
PerformanceLeagueWindow
Definition: league_gui.cpp:56
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
Pool::PoolItem<&_league_table_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:247
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
ShowStoryBook
void ShowStoryBook(CompanyID company, uint16 page_id=INVALID_STORY_PAGE)
Raise or create the story book window for company, at page page_id.
Definition: story_gui.cpp:1057
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:1019
company_base.h
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
company_gui.h
GUIList< const Company * >
league_gui.h
ScriptLeagueWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: league_gui.cpp:397
ScriptLeagueWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: league_gui.cpp:310
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
PerformanceLeagueWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: league_gui.cpp:95
PerformanceLeagueWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: league_gui.cpp:103
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
ScriptLeagueWindow::rank_width
uint rank_width
The width of the rank ordinal.
Definition: league_gui.cpp:258
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:644
town.h
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:713
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:336
ScriptLeagueWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: league_gui.cpp:315
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:551
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
ScriptLeagueWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: league_gui.cpp:304
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
PerformanceLeagueWindow::BuildCompanyList
void BuildCompanyList()
(Re)Build the company league list
Definition: league_gui.cpp:67
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:789
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:102
PerformanceLeagueWindow::icon
Dimension icon
Dimension of the company icon.
Definition: league_gui.cpp:62
ScriptLeagueWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: league_gui.cpp:414
window_gui.h
ScriptLeagueWindow::icon_size
Dimension icon_size
Dimenion of the company icon.
Definition: league_gui.cpp:263
tile_map.h
LT_STORY_PAGE
@ LT_STORY_PAGE
Link a story page.
Definition: league_type.h:20
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
CompanyEconomyEntry::performance_history
int32 performance_history
Company score (scale 0-1000)
Definition: company_base.h:27
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1804
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1008
RectPadding::Horizontal
uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:59
ScriptLeagueWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: league_gui.cpp:357
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
PerformanceLeagueWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: league_gui.cpp:130
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
industry.h
safeguards.h
sortlist_type.h
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:192
ScriptLeagueWindow::line_height
int line_height
Height of the text lines.
Definition: league_gui.cpp:262
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:179
LeagueTableID
uint8 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:241
RectPadding::Vertical
uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:65
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:199
PerformanceLeagueWindow::text_width
uint text_width
The width of the actual text.
Definition: league_gui.cpp:60
WID_PLT_BACKGROUND
@ WID_PLT_BACKGROUND
Background of the window.
Definition: league_widget.h:15
viewport_func.h
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:147
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:715
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:993
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
PerformanceLeagueWindow::line_height
int line_height
Height of the text lines.
Definition: league_gui.cpp:61
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
LT_TOWN
@ LT_TOWN
Link a town.
Definition: league_type.h:18
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
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:386
strings_func.h
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
ScriptLeagueWindow::score_width
uint score_width
The width of the score text.
Definition: league_gui.cpp:260
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel border.
Definition: window_gui.h:46
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1014
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
ScriptLeagueWindow::text_width
uint text_width
The width of the actual text.
Definition: league_gui.cpp:259
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:213
WidgetDimensions::framerect
RectPadding framerect
Offsets within frame area.
Definition: window_gui.h:47
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:248
PerformanceLeagueWindow::ordinal_width
uint ordinal_width
The width of the ordinal number.
Definition: league_gui.cpp:59
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
WID_SLT_CAPTION
@ WID_SLT_CAPTION
Caption of the window.
Definition: league_widget.h:20
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
gui.h
WID_SLT_BACKGROUND
@ WID_SLT_BACKGROUND
Background of the window.
Definition: league_widget.h:21
Window
Data structure for an opened window.
Definition: window_gui.h:213
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
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:326
ScriptLeagueWindow::header_height
uint header_height
Height of the table header.
Definition: league_gui.cpp:261
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
ScriptLeagueWindow::BuildTable
void BuildTable()
Rebuild the company league list.
Definition: league_gui.cpp:269
story_base.h
ShowCompany
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
Definition: company_gui.cpp:2763
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
Company
Definition: company_base.h:117
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
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:100
PerformanceLeagueWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: league_gui.cpp:166
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:49
LT_COMPANY
@ LT_COMPANY
Link a company.
Definition: league_type.h:19
league_widget.h
ScriptLeagueWindow
Definition: league_gui.cpp:254
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:297
SetMinimalTextLines
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1032
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:61