Go to the documentation of this file.
26 #include "table/strings.h"
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,
51 static inline StringID GetPerformanceTitleFromValue(uint value)
53 return _performance_titles[std::min(value, 1000u) >> 6];
71 this->companies.clear();
74 this->companies.push_back(c);
77 this->companies.shrink_to_fit();
108 int icon_y_offset = (this->line_height - this->icon.height) / 2;
113 uint icon_left = ir.
Indent(rtl ? this->text_width : this->ordinal_width, rtl).left;
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);
125 DrawString(text.left, text.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_NAME);
134 this->ordinal_width = 0;
140 uint widest_width = 0;
141 uint widest_title = 0;
142 for (uint i = 0; i <
lengthof(_performance_titles); i++) {
144 if (
width > widest_width) {
146 widest_width =
width;
156 SetDParam(2, _performance_titles[widest_title]);
189 static const NWidgetPart _nested_performance_league_widgets[] = {
203 _nested_performance_league_widgets,
lengthof(_nested_performance_league_widgets)
206 void ShowPerformanceLeagueTable()
208 AllocateWindowDescFront<PerformanceLeagueWindow>(&_performance_league_desc, 0);
211 static void HandleLinkClick(
Link link)
243 default: NOT_REACHED();
257 std::vector<std::pair<uint, const LeagueTableElement *>> rows;
272 this->title = std::string{};
274 if (lt ==
nullptr)
return;
277 this->title = lt->title;
279 std::vector<const LeagueTableElement *> elements;
281 if (lte->table == this->table) {
282 elements.push_back(lte);
285 std::sort(elements.begin(), elements.end(), [](
auto a,
auto b) { return a->rating > b->rating; });
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));
320 if (lt ==
nullptr)
return;
324 if (!lt->header.empty()) {
329 int icon_y_offset = (this->line_height - this->icon_size.height) / 2;
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);
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);
344 DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK);
346 DrawString(score_rect.left, score_rect.right, ir.top + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK,
SA_RIGHT);
350 if (!lt->footer.empty()) {
353 ir.top =
DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
362 if (lt ==
nullptr)
return;
368 this->rank_width = this->text_width = this->score_width = 0;
369 bool show_icon_column =
false;
370 for (
auto [rank, lte] : this->rows) {
379 if (!show_icon_column) this->icon_size.width = 0;
385 if (!lt->header.empty()) {
389 }
else this->header_height = 0;
391 if (!lt->footer.empty()) {
403 if (index >= 0 && (uint)index < this->rows.size()) {
404 auto lte = this->rows[index].second;
405 HandleLinkClick(lte->link);
421 static const NWidgetPart _nested_script_league_widgets[] = {
435 _nested_script_league_widgets,
lengthof(_nested_script_league_widgets)
441 AllocateWindowDescFront<ScriptLeagueWindow>(&_script_league_desc, table);
444 void ShowFirstLeagueTable()
448 ShowScriptLeagueTable((*it.begin())->index);
450 ShowPerformanceLeagueTable();
static Titem * Get(size_t index)
Returns Titem with given index.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Struct about league table elements.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Dimensions (a width and height) of a rectangle in 2D.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
bool Sort(Comp compare)
Sort the list.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
void ShowStoryBook(CompanyID company, uint16 page_id=INVALID_STORY_PAGE)
Raise or create the story book window for company, at page page_id.
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnPaint() override
The window must be repainted.
Tindex index
Index of this pool item.
bool _ctrl_pressed
Is Ctrl pressed?
uint rank_width
The width of the rank ordinal.
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.
int32 WindowNumber
Number to differentiate different windows of the same class.
@ SA_RIGHT
Right align the text (must be a single bit).
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Owner
Enum for all companies/owners.
@ WC_COMPANY_LEAGUE
Company league window; Window numbers:
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
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.
@ LT_INDUSTRY
Link an industry.
High level window description.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Dimension icon_size
Dimenion of the company icon.
@ LT_STORY_PAGE
Link a story page.
@ WDP_AUTO
Find a place automatically.
ResizeInfo resize
Resize information.
int32 performance_history
Company score (scale 0-1000)
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
uint Horizontal() const
Get total horizontal padding of RectPadding.
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.
@ MAX_COMPANIES
Maximum number of companies.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
int line_height
Height of the text lines.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
uint8 LeagueTableID
ID of a league table.
Coordinates of a point in 2D.
WindowNumber window_number
Window number within the window class.
uint Vertical() const
Get total vertical padding of RectPadding.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
int GetStringHeight(const char *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.
bool NeedRebuild() const
Check if a rebuild is needed.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
uint score_width
The width of the score text.
uint text_width
The width of the actual text.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
void ForceRebuild()
Force that a rebuild is needed.
#define lengthof(x)
Return the length of an fixed size array.
int width
width of the window (number of pixels to the right in x direction)
@ INVALID_COMPANY
An invalid company.
Data structure for an opened window.
void RebuildDone()
Notify the sortlist that the rebuild is done.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
uint header_height
Height of the table header.
void DrawWidgets() const
Paint all widgets of a window.
void BuildTable()
Rebuild the company league list.
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
Specification of a rectangle with absolute coordinates of all edges.
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
@ LT_COMPANY
Link a company.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.