27#include "table/strings.h"
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,
52static inline StringID GetPerformanceTitleFromValue(uint value)
54 return _performance_titles[std::min(value, 1000u) >> 6];
72 this->companies.clear();
76 this->companies.push_back(c);
109 int icon_y_offset = (this->line_height - this->
icon.height) / 2;
117 for (uint i = 0; i != this->companies.size(); i++) {
118 const Company *c = this->companies[i];
119 DrawString(rank_rect.left, rank_rect.right, ir.top + text_y_offset,
GetString(STR_COMPANY_LEAGUE_COMPANY_RANK, i + 1));
123 DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset,
GetString(STR_COMPANY_LEAGUE_COMPANY_NAME, c->
index, c->
index, GetPerformanceTitleFromValue(c->
old_economy[0].performance_history)));
132 this->rank_width = 0;
133 for (uint i = 0; i < MAX_COMPANIES; i++) {
137 uint widest_width = 0;
139 for (
auto title : _performance_titles) {
141 if (
width > widest_width) {
142 widest_title = title;
143 widest_width =
width;
151 widest_width = std::max(widest_width,
GetStringBoundingBox(
GetString(STR_COMPANY_LEAGUE_COMPANY_NAME, c->index, c->index, widest_title)).width);
172 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
183static constexpr NWidgetPart _nested_performance_league_widgets[] = {
195 WDP_AUTO,
"performance_league", 0, 0,
198 _nested_performance_league_widgets
201void ShowPerformanceLeagueTable()
203 AllocateWindowDescFront<PerformanceLeagueWindow>(_performance_league_desc, 0);
206static void HandleLinkClick(
Link link)
238 default: NOT_REACHED();
252 std::vector<std::pair<uint, const LeagueTableElement *>> rows{};
270 if (lt ==
nullptr)
return;
273 this->title = lt->
title;
275 std::vector<const LeagueTableElement *> elements;
277 if (lte->table != this->table)
continue;
278 elements.push_back(lte);
284 for (uint i = 0; i != elements.size(); i++) {
286 if (i > 0 && elements[i - 1]->rating != lte->
rating) rank = i;
287 this->rows.emplace_back(rank, lte);
315 if (lt ==
nullptr)
return;
319 if (!lt->
header.empty()) {
323 int icon_y_offset = (this->line_height - this->
icon_size.height) / 2;
332 Rect score_rect = ir.
Indent(this->rank_width + 2 * spacer + this->
icon_size.width + this->text_width, rtl).
WithWidth(this->score_width, rtl);
334 for (
const auto &[rank, lte] : this->rows) {
335 DrawString(rank_rect.left, rank_rect.right, ir.top + text_y_offset,
GetString(STR_COMPANY_LEAGUE_COMPANY_RANK, rank + 1));
336 if (this->
icon_size.width > 0 && lte->company != CompanyID::Invalid())
DrawCompanyIcon(lte->company, icon_rect.left, ir.top + icon_y_offset);
337 DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset, lte->text.GetDecodedString(), TC_BLACK);
338 DrawString(score_rect.left, score_rect.right, ir.top + text_y_offset, lte->score.GetDecodedString(), TC_BLACK,
SA_RIGHT |
SA_FORCE);
342 if (!lt->
footer.empty()) {
353 if (lt ==
nullptr)
return;
359 this->rank_width = this->text_width = this->score_width = 0;
360 bool show_icon_column =
false;
361 for (
const auto &[rank, lte] : this->rows) {
363 this->text_width = std::max(this->text_width,
GetStringBoundingBox(lte->text.GetDecodedString()).width);
364 this->score_width = std::max(this->score_width,
GetStringBoundingBox(lte->score.GetDecodedString()).width);
365 if (lte->company != CompanyID::Invalid()) show_icon_column =
true;
368 if (!show_icon_column) {
375 size.width = std::max(size.width, non_text_width + this->text_width);
379 this->text_width = size.width - non_text_width;
381 if (!lt->
header.empty()) {
384 this->header_height = 0;
388 if (!lt->
footer.empty()) {
392 size.height = std::max(size.height, used_height);
401 if (index >= 0 &&
static_cast<uint
>(index) < this->rows.size()) {
403 HandleLinkClick(lte->
link);
412 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
419static constexpr NWidgetPart _nested_script_league_widgets[] = {
434 _nested_script_league_widgets
440 AllocateWindowDescFront<ScriptLeagueWindow>(_script_league_desc, table);
443void ShowFirstLeagueTable()
447 ShowScriptLeagueTable((*it.begin())->index);
449 ShowPerformanceLeagueTable();
Container for an encoded string, created by GetEncodedString.
std::string GetDecodedString() const
Decode the encoded string.
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 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.
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.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
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.
bool _ctrl_pressed
Is Ctrl pressed?
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.
@ FS_NORMAL
Index of the normal font in the font tables.
@ SA_RIGHT
Right align the text (must be a single bit).
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
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.
League table GUI functions.
@ LT_COMPANY
Link a company.
@ LT_STORY_PAGE
Link a story page.
@ LT_INDUSTRY
Link an industry.
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.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
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.
int64_t rating
Value that determines ordering of elements in the table (higher=better)
Link link
What opens when element is clicked.
Struct about custom league tables.
EncodedString header
Text to show above the table.
EncodedString title
Title of the table.
EncodedString footer
Text to show below the table.
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.
Number to differentiate different windows of the same class.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
void DrawWidgets() const
Paint all widgets of a window.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
ResizeInfo resize
Resize information.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
int width
width of the window (number of pixels to the right in x direction)
WindowNumber window_number
Window number within the window class.
Map writing/reading functions for tiles.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
Functions, definitions and such used only by the GUI.
@ WDP_AUTO
Find a place automatically.
@ WC_COMPANY_LEAGUE
Company league window; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.