OpenTTD Source: src/company_gui.cpp Source File

OpenTTD Source 15.0-RC2

company_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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "currency.h"
12#include "error.h"
13#include "gui.h"
14#include "settings_gui.h"
15#include "window_gui.h"
16#include "textbuf_gui.h"
17#include "viewport_func.h"
18#include "company_func.h"
19#include "command_func.h"
20#include "network/network.h"
21#include "network/network_gui.h"
22#include "network/network_func.h"
23#include "newgrf.h"
24#include "company_manager_face.h"
25#include "strings_func.h"
26#include "timer/timer_game_economy.h"
27#include "dropdown_type.h"
28#include "tilehighlight_func.h"
29#include "company_base.h"
30#include "core/geometry_func.hpp"
31#include "object_type.h"
32#include "rail.h"
33#include "road.h"
34#include "engine_base.h"
35#include "window_func.h"
36#include "road_func.h"
37#include "water.h"
38#include "station_func.h"
39#include "zoom_func.h"
40#include "sortlist_type.h"
41#include "company_cmd.h"
42#include "economy_cmd.h"
43#include "group_cmd.h"
44#include "group_gui.h"
45#include "misc_cmd.h"
46#include "object_cmd.h"
47#include "timer/timer.h"
48#include "timer/timer_window.h"
49#include "core/string_consumer.hpp"
50
51#include "widgets/company_widget.h"
52
53#include "table/strings.h"
54
55#include "dropdown_common_type.h"
56
57#include "safeguards.h"
58
59
61static void DoSelectCompanyManagerFace(Window *parent);
62static void ShowCompanyInfrastructure(CompanyID company);
63
65 static const std::initializer_list<ExpensesType> _expenses_list_revenue = {
66 EXPENSES_TRAIN_REVENUE,
67 EXPENSES_ROADVEH_REVENUE,
68 EXPENSES_AIRCRAFT_REVENUE,
69 EXPENSES_SHIP_REVENUE,
70};
71
73 static const std::initializer_list<ExpensesType> _expenses_list_operating_costs = {
74 EXPENSES_TRAIN_RUN,
75 EXPENSES_ROADVEH_RUN,
76 EXPENSES_AIRCRAFT_RUN,
77 EXPENSES_SHIP_RUN,
78 EXPENSES_PROPERTY,
79 EXPENSES_LOAN_INTEREST,
80};
81
83 static const std::initializer_list<ExpensesType> _expenses_list_capital_costs = {
84 EXPENSES_CONSTRUCTION,
85 EXPENSES_NEW_VEHICLES,
86 EXPENSES_OTHER,
87};
88
90 struct ExpensesList {
91 const StringID title;
92 const std::initializer_list<ExpensesType> &items;
93
94 ExpensesList(StringID title, const std::initializer_list<ExpensesType> &list) : title(title), items(list)
95 {
96 }
97
98 uint GetHeight() const
99 {
100 /* Add up the height of all the lines. */
101 return static_cast<uint>(this->items.size()) * GetCharacterHeight(FS_NORMAL);
102 }
103
105 uint GetListWidth() const
106 {
107 uint width = 0;
108 for (const ExpensesType &et : this->items) {
109 width = std::max(width, GetStringBoundingBox(STR_FINANCES_SECTION_CONSTRUCTION + et).width);
110 }
111 return width;
112 }
113};
114
116 static const std::initializer_list<ExpensesList> _expenses_list_types = {
117 { STR_FINANCES_REVENUE_TITLE, _expenses_list_revenue },
118 { STR_FINANCES_OPERATING_EXPENSES_TITLE, _expenses_list_operating_costs },
119 { STR_FINANCES_CAPITAL_EXPENSES_TITLE, _expenses_list_capital_costs },
120};
121
126 static uint GetTotalCategoriesHeight()
127{
128 /* There's an empty line and blockspace on the year row */
129 uint total_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
130
131 for (const ExpensesList &list : _expenses_list_types) {
132 /* Title + expense list + total line + total + blockspace after category */
133 total_height += GetCharacterHeight(FS_NORMAL) + list.GetHeight() + WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
134 }
135
136 /* Total income */
137 total_height += WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
138
139 return total_height;
140}
141
146 static uint GetMaxCategoriesWidth()
147{
148 uint max_width = GetStringBoundingBox(TimerGameEconomy::UsingWallclockUnits() ? STR_FINANCES_PERIOD_CAPTION : STR_FINANCES_YEAR_CAPTION).width;
149
150 /* Loop through categories to check max widths. */
151 for (const ExpensesList &list : _expenses_list_types) {
152 /* Title of category */
153 max_width = std::max(max_width, GetStringBoundingBox(list.title).width);
154 /* Entries in category */
155 max_width = std::max(max_width, list.GetListWidth() + WidgetDimensions::scaled.hsep_indent);
156 }
157
158 return max_width;
159}
160
164 static void DrawCategory(const Rect &r, int start_y, const ExpensesList &list)
165{
166 Rect tr = r.Indent(WidgetDimensions::scaled.hsep_indent, _current_text_dir == TD_RTL);
167
168 tr.top = start_y;
169
170 for (const ExpensesType &et : list.items) {
171 DrawString(tr, STR_FINANCES_SECTION_CONSTRUCTION + et);
172 tr.top += GetCharacterHeight(FS_NORMAL);
173 }
174}
175
181 static void DrawCategories(const Rect &r)
182{
183 int y = r.top;
184 /* Draw description of 12-minute economic period. */
185 DrawString(r.left, r.right, y, (TimerGameEconomy::UsingWallclockUnits() ? STR_FINANCES_PERIOD_CAPTION : STR_FINANCES_YEAR_CAPTION), TC_FROMSTRING, SA_LEFT, true);
186 y += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
187
188 for (const ExpensesList &list : _expenses_list_types) {
189 /* Draw category title and advance y */
190 DrawString(r.left, r.right, y, list.title, TC_FROMSTRING, SA_LEFT);
191 y += GetCharacterHeight(FS_NORMAL);
192
193 /* Draw category items and advance y */
194 DrawCategory(r, y, list);
195 y += list.GetHeight();
196
197 /* Advance y by the height of the horizontal line between amounts and subtotal */
198 y += WidgetDimensions::scaled.vsep_normal;
199
200 /* Draw category total and advance y */
201 DrawString(r.left, r.right, y, STR_FINANCES_TOTAL_CAPTION, TC_FROMSTRING, SA_RIGHT);
202 y += GetCharacterHeight(FS_NORMAL);
203
204 /* Advance y by a blockspace after this category block */
205 y += WidgetDimensions::scaled.vsep_wide;
206 }
207
208 /* Draw total profit/loss */
209 y += WidgetDimensions::scaled.vsep_normal;
210 DrawString(r.left, r.right, y, STR_FINANCES_PROFIT, TC_FROMSTRING, SA_LEFT);
211}
212
221 static void DrawPrice(Money amount, int left, int right, int top, TextColour colour)
222{
223 StringID str = STR_FINANCES_NEGATIVE_INCOME;
224 if (amount == 0) {
225 str = STR_FINANCES_ZERO_INCOME;
226 } else if (amount < 0) {
227 amount = -amount;
228 str = STR_FINANCES_POSITIVE_INCOME;
229 }
230 DrawString(left, right, top, GetString(str, amount), colour, SA_RIGHT | SA_FORCE);
231}
232
237 static Money DrawYearCategory(const Rect &r, int start_y, const ExpensesList &list, const Expenses &tbl)
238{
239 int y = start_y;
240 Money sum = 0;
241
242 for (const ExpensesType &et : list.items) {
243 Money cost = tbl[et];
244 sum += cost;
245 if (cost != 0) DrawPrice(cost, r.left, r.right, y, TC_BLACK);
246 y += GetCharacterHeight(FS_NORMAL);
247 }
248
249 /* Draw the total at the bottom of the category. */
250 GfxFillRect(r.left, y, r.right, y + WidgetDimensions::scaled.bevel.top - 1, PC_BLACK);
251 y += WidgetDimensions::scaled.vsep_normal;
252 if (sum != 0) DrawPrice(sum, r.left, r.right, y, TC_WHITE);
253
254 /* Return the sum for the yearly total. */
255 return sum;
256}
257
258
266 static void DrawYearColumn(const Rect &r, TimerGameEconomy::Year year, const Expenses &tbl)
267{
268 int y = r.top;
269 Money sum;
270
271 /* Year header */
272 DrawString(r.left, r.right, y, GetString(STR_FINANCES_YEAR, year), TC_FROMSTRING, SA_RIGHT | SA_FORCE, true);
273 y += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
274
275 /* Categories */
276 for (const ExpensesList &list : _expenses_list_types) {
277 y += GetCharacterHeight(FS_NORMAL);
278 sum += DrawYearCategory(r, y, list, tbl);
279 /* Expense list + expense category title + expense category total + blockspace after category */
280 y += list.GetHeight() + WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
281 }
282
283 /* Total income. */
284 GfxFillRect(r.left, y, r.right, y + WidgetDimensions::scaled.bevel.top - 1, PC_BLACK);
285 y += WidgetDimensions::scaled.vsep_normal;
286 DrawPrice(sum, r.left, r.right, y, TC_WHITE);
287}
288
289static constexpr std::initializer_list<NWidgetPart> _nested_company_finances_widgets = {
290 NWidget(NWID_HORIZONTAL),
291 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
292 NWidget(WWT_CAPTION, COLOUR_GREY, WID_CF_CAPTION),
293 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_CF_TOGGLE_SIZE), SetSpriteTip(SPR_LARGE_SMALL_WINDOW, STR_TOOLTIP_TOGGLE_LARGE_SMALL_WINDOW), SetAspect(WidgetDimensions::ASPECT_TOGGLE_SIZE),
294 NWidget(WWT_SHADEBOX, COLOUR_GREY),
295 NWidget(WWT_STICKYBOX, COLOUR_GREY),
296 EndContainer(),
297 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_CF_SEL_PANEL),
298 NWidget(WWT_PANEL, COLOUR_GREY),
299 NWidget(NWID_HORIZONTAL), SetPadding(WidgetDimensions::unscaled.framerect), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
300 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_CF_EXPS_CATEGORY), SetMinimalSize(120, 0), SetFill(0, 0),
301 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_CF_EXPS_PRICE1), SetMinimalSize(86, 0), SetFill(0, 0),
302 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_CF_EXPS_PRICE2), SetMinimalSize(86, 0), SetFill(0, 0),
303 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_CF_EXPS_PRICE3), SetMinimalSize(86, 0), SetFill(0, 0),
304 EndContainer(),
305 EndContainer(),
306 EndContainer(),
307 NWidget(WWT_PANEL, COLOUR_GREY),
308 NWidget(NWID_HORIZONTAL), SetPadding(WidgetDimensions::unscaled.framerect), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0), SetPIPRatio(0, 1, 2),
309 NWidget(NWID_VERTICAL), // Vertical column with 'bank balance', 'loan'
310 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_FINANCES_OWN_FUNDS_TITLE),
311 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_FINANCES_LOAN_TITLE),
312 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_FINANCES_BANK_BALANCE_TITLE), SetPadding(WidgetDimensions::unscaled.vsep_normal, 0, 0, 0),
313 EndContainer(),
314 NWidget(NWID_VERTICAL), // Vertical column with bank balance amount, loan amount, and total.
315 NWidget(WWT_TEXT, INVALID_COLOUR, WID_CF_OWN_VALUE), SetAlignment(SA_VERT_CENTER | SA_RIGHT | SA_FORCE),
316 NWidget(WWT_TEXT, INVALID_COLOUR, WID_CF_LOAN_VALUE), SetAlignment(SA_VERT_CENTER | SA_RIGHT | SA_FORCE),
317 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_CF_BALANCE_LINE), SetMinimalSize(0, WidgetDimensions::unscaled.vsep_normal),
318 NWidget(WWT_TEXT, INVALID_COLOUR, WID_CF_BALANCE_VALUE), SetAlignment(SA_VERT_CENTER | SA_RIGHT | SA_FORCE),
319 EndContainer(),
320 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_CF_SEL_MAXLOAN),
321 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1), // Max loan information
322 NWidget(WWT_TEXT, INVALID_COLOUR, WID_CF_INTEREST_RATE),
323 NWidget(WWT_TEXT, INVALID_COLOUR, WID_CF_MAXLOAN_VALUE),
324 EndContainer(),
325 EndContainer(),
326 EndContainer(),
327 EndContainer(),
328 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_CF_SEL_BUTTONS),
329 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
330 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CF_INCREASE_LOAN), SetFill(1, 0), SetToolTip(STR_FINANCES_BORROW_TOOLTIP),
331 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CF_REPAY_LOAN), SetFill(1, 0), SetToolTip(STR_FINANCES_REPAY_TOOLTIP),
332 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CF_INFRASTRUCTURE), SetFill(1, 0), SetStringTip(STR_FINANCES_INFRASTRUCTURE_BUTTON, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP),
333 EndContainer(),
334 EndContainer(),
335};
336
338 struct CompanyFinancesWindow : Window {
339 static constexpr int NUM_PERIODS = WID_CF_EXPS_PRICE3 - WID_CF_EXPS_PRICE1 + 1;
340
341 static Money max_money;
342 bool small = false;
343 uint8_t first_visible = NUM_PERIODS - 1;
344
345 CompanyFinancesWindow(WindowDesc &desc, CompanyID company) : Window(desc)
346 {
347 this->CreateNestedTree();
348 this->SetupWidgets();
349 this->FinishInitNested(company);
350
351 this->owner = this->window_number;
352 this->InvalidateData();
353 }
354
355 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
356 {
357 switch (widget) {
358 case WID_CF_CAPTION:
359 return GetString(STR_FINANCES_CAPTION, this->window_number, this->window_number);
360
361 case WID_CF_BALANCE_VALUE: {
362 const Company *c = Company::Get(this->window_number);
363 return GetString(STR_FINANCES_BANK_BALANCE, c->money);
364 }
365
366 case WID_CF_LOAN_VALUE: {
367 const Company *c = Company::Get(this->window_number);
368 return GetString(STR_FINANCES_TOTAL_CURRENCY, c->current_loan);
369 }
370
371 case WID_CF_OWN_VALUE: {
372 const Company *c = Company::Get(this->window_number);
373 return GetString(STR_FINANCES_TOTAL_CURRENCY, c->money - c->current_loan);
374 }
375
376 case WID_CF_INTEREST_RATE:
377 return GetString(STR_FINANCES_INTEREST_RATE, _settings_game.difficulty.initial_interest);
378
379 case WID_CF_MAXLOAN_VALUE: {
380 const Company *c = Company::Get(this->window_number);
381 return GetString(STR_FINANCES_MAX_LOAN, c->GetMaxLoan());
382 }
383
384 case WID_CF_INCREASE_LOAN:
385 return GetString(STR_FINANCES_BORROW_BUTTON, LOAN_INTERVAL);
386
387 case WID_CF_REPAY_LOAN:
388 return GetString(STR_FINANCES_REPAY_BUTTON, LOAN_INTERVAL);
389
390 default:
391 return this->Window::GetWidgetString(widget, stringid);
392 }
393 }
394
395 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
396 {
397 switch (widget) {
398 case WID_CF_EXPS_CATEGORY:
399 size.width = GetMaxCategoriesWidth();
400 size.height = GetTotalCategoriesHeight();
401 break;
402
403 case WID_CF_EXPS_PRICE1:
404 case WID_CF_EXPS_PRICE2:
405 case WID_CF_EXPS_PRICE3:
406 size.height = GetTotalCategoriesHeight();
407 [[fallthrough]];
408
409 case WID_CF_BALANCE_VALUE:
410 case WID_CF_LOAN_VALUE:
411 case WID_CF_OWN_VALUE: {
412 uint64_t max_value = GetParamMaxValue(CompanyFinancesWindow::max_money);
413 size.width = std::max(GetStringBoundingBox(GetString(STR_FINANCES_NEGATIVE_INCOME, max_value)).width, GetStringBoundingBox(GetString(STR_FINANCES_POSITIVE_INCOME, max_value)).width);
414 size.width += padding.width;
415 break;
416 }
417
418 case WID_CF_INTEREST_RATE:
419 size.height = GetCharacterHeight(FS_NORMAL);
420 break;
421 }
422 }
423
424 void DrawWidget(const Rect &r, WidgetID widget) const override
425 {
426 switch (widget) {
427 case WID_CF_EXPS_CATEGORY:
428 DrawCategories(r);
429 break;
430
431 case WID_CF_EXPS_PRICE1:
432 case WID_CF_EXPS_PRICE2:
433 case WID_CF_EXPS_PRICE3: {
434 int period = widget - WID_CF_EXPS_PRICE1;
435 if (period < this->first_visible) break;
436
437 const Company *c = Company::Get(this->window_number);
438 const auto &expenses = c->yearly_expenses[NUM_PERIODS - period - 1];
439 DrawYearColumn(r, TimerGameEconomy::year - (NUM_PERIODS - period - 1), expenses);
440 break;
441 }
442
443 case WID_CF_BALANCE_LINE:
444 GfxFillRect(r.left, r.top, r.right, r.top + WidgetDimensions::scaled.bevel.top - 1, PC_BLACK);
445 break;
446 }
447 }
448
453 void SetupWidgets()
454 {
455 int plane = this->small ? SZSP_NONE : 0;
456 this->GetWidget<NWidgetStacked>(WID_CF_SEL_PANEL)->SetDisplayedPlane(plane);
457 this->GetWidget<NWidgetStacked>(WID_CF_SEL_MAXLOAN)->SetDisplayedPlane(plane);
458
459 CompanyID company = this->window_number;
460 plane = (company != _local_company) ? SZSP_NONE : 0;
461 this->GetWidget<NWidgetStacked>(WID_CF_SEL_BUTTONS)->SetDisplayedPlane(plane);
462 }
463
464 void OnPaint() override
465 {
466 if (!this->IsShaded()) {
467 if (!this->small) {
468 /* Check that the expenses panel height matches the height needed for the layout. */
469 if (GetTotalCategoriesHeight() != this->GetWidget<NWidgetBase>(WID_CF_EXPS_CATEGORY)->current_y) {
470 this->SetupWidgets();
471 this->ReInit();
472 return;
473 }
474 }
475
476 /* Check that the loan buttons are shown only when the user owns the company. */
477 CompanyID company = this->window_number;
478 int req_plane = (company != _local_company) ? SZSP_NONE : 0;
479 if (req_plane != this->GetWidget<NWidgetStacked>(WID_CF_SEL_BUTTONS)->shown_plane) {
480 this->SetupWidgets();
481 this->ReInit();
482 return;
483 }
484
485 const Company *c = Company::Get(company);
486 this->SetWidgetDisabledState(WID_CF_INCREASE_LOAN, c->current_loan >= c->GetMaxLoan()); // Borrow button only shows when there is any more money to loan.
487 this->SetWidgetDisabledState(WID_CF_REPAY_LOAN, company != _local_company || c->current_loan == 0); // Repay button only shows when there is any more money to repay.
488 }
489
490 this->DrawWidgets();
491 }
492
493 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
494 {
495 switch (widget) {
496 case WID_CF_TOGGLE_SIZE: // toggle size
497 this->small = !this->small;
498 this->SetupWidgets();
499 if (this->IsShaded()) {
500 /* Finances window is not resizable, so size hints given during unshading have no effect
501 * on the changed appearance of the window. */
502 this->SetShaded(false);
503 } else {
504 this->ReInit();
505 }
506 break;
507
508 case WID_CF_INCREASE_LOAN: // increase loan
509 Command<CMD_INCREASE_LOAN>::Post(STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY, _ctrl_pressed ? LoanCommand::Max : LoanCommand::Interval, 0);
510 break;
511
512 case WID_CF_REPAY_LOAN: // repay loan
513 Command<CMD_DECREASE_LOAN>::Post(STR_ERROR_CAN_T_REPAY_LOAN, _ctrl_pressed ? LoanCommand::Max : LoanCommand::Interval, 0);
514 break;
515
516 case WID_CF_INFRASTRUCTURE: // show infrastructure details
517 ShowCompanyInfrastructure(this->window_number);
518 break;
519 }
520 }
521
522 void RefreshVisibleColumns()
523 {
524 for (uint period = 0; period < this->first_visible; ++period) {
525 const Company *c = Company::Get(this->window_number);
526 const Expenses &expenses = c->yearly_expenses[NUM_PERIODS - period - 1];
527 /* Show expenses column if it has any non-zero value in it. */
528 if (std::ranges::any_of(expenses, [](const Money &value) { return value != 0; })) {
529 this->first_visible = period;
530 break;
531 }
532 }
533 }
534
535 void OnInvalidateData(int, bool) override
536 {
537 this->RefreshVisibleColumns();
538 }
539
544 const IntervalTimer<TimerWindow> rescale_interval = {std::chrono::seconds(3), [this](auto) {
545 const Company *c = Company::Get(this->window_number);
546 if (c->money > CompanyFinancesWindow::max_money) {
547 CompanyFinancesWindow::max_money = std::max(c->money * 2, CompanyFinancesWindow::max_money * 4);
548 this->SetupWidgets();
549 this->ReInit();
550 }
551 }};
552};
553
555 Money CompanyFinancesWindow::max_money = INT32_MAX;
556
557static WindowDesc _company_finances_desc(
558 WDP_AUTO, "company_finances", 0, 0,
559 WC_FINANCES, WC_NONE,
560 {},
561 _nested_company_finances_widgets
562);
563
569 void ShowCompanyFinances(CompanyID company)
570{
571 if (!Company::IsValidID(company)) return;
572 if (BringWindowToFrontById(WC_FINANCES, company)) return;
573
574 new CompanyFinancesWindow(_company_finances_desc, company);
575}
576
577/* Association of liveries to livery classes */
578static const LiveryClass _livery_class[LS_END] = {
579 LC_OTHER,
580 LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL,
581 LC_ROAD, LC_ROAD,
582 LC_SHIP, LC_SHIP,
583 LC_AIRCRAFT, LC_AIRCRAFT, LC_AIRCRAFT,
584 LC_ROAD, LC_ROAD,
585};
586
591template <SpriteID TSprite = SPR_SQUARE>
592 class DropDownListColourItem : public DropDownIcon<DropDownString<DropDownListItem>> {
593public:
594 DropDownListColourItem(int colour, bool masked) :
595 DropDownIcon<DropDownString<DropDownListItem>>(TSprite, GetColourPalette(static_cast<Colours>(colour % COLOUR_END)), GetString(colour < COLOUR_END ? (STR_COLOUR_DARK_BLUE + colour) : STR_COLOUR_DEFAULT), colour, masked)
596 {
597 }
598};
599
601 struct SelectCompanyLiveryWindow : public Window {
602private:
603 uint32_t sel = 0;
604 LiveryClass livery_class{};
605 Dimension square{};
606 uint rows = 0;
607 uint line_height = 0;
608 GUIGroupList groups{};
609 Scrollbar *vscroll = nullptr;
610
611 void ShowColourDropDownMenu(uint32_t widget)
612 {
613 uint32_t used_colours = 0;
614 const Livery *livery, *default_livery = nullptr;
615 bool primary = widget == WID_SCL_PRI_COL_DROPDOWN;
616 uint8_t default_col = 0;
617
618 /* Disallow other company colours for the primary colour */
619 if (this->livery_class < LC_GROUP_RAIL && HasBit(this->sel, LS_DEFAULT) && primary) {
620 for (const Company *c : Company::Iterate()) {
621 if (c->index != _local_company) SetBit(used_colours, c->colour);
622 }
623 }
624
625 const Company *c = Company::Get(this->window_number);
626
627 if (this->livery_class < LC_GROUP_RAIL) {
628 /* Get the first selected livery to use as the default dropdown item */
629 LiveryScheme scheme;
630 for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
631 if (HasBit(this->sel, scheme)) break;
632 }
633 if (scheme == LS_END) scheme = LS_DEFAULT;
634 livery = &c->livery[scheme];
635 if (scheme != LS_DEFAULT) default_livery = &c->livery[LS_DEFAULT];
636 } else {
637 const Group *g = Group::Get(this->sel);
638 livery = &g->livery;
639 if (g->parent == GroupID::Invalid()) {
640 default_livery = &c->livery[LS_DEFAULT];
641 } else {
642 const Group *pg = Group::Get(g->parent);
643 default_livery = &pg->livery;
644 }
645 }
646
647 DropDownList list;
648 if (default_livery != nullptr) {
649 /* Add COLOUR_END to put the colour out of range, but also allow us to show what the default is */
650 default_col = (primary ? default_livery->colour1 : default_livery->colour2) + COLOUR_END;
651 list.push_back(std::make_unique<DropDownListColourItem<>>(default_col, false));
652 }
653 for (Colours colour = COLOUR_BEGIN; colour != COLOUR_END; colour++) {
654 list.push_back(std::make_unique<DropDownListColourItem<>>(colour, HasBit(used_colours, colour)));
655 }
656
657 uint8_t sel;
658 if (default_livery == nullptr || livery->in_use.Test(primary ? Livery::Flag::Primary : Livery::Flag::Secondary)) {
659 sel = primary ? livery->colour1 : livery->colour2;
660 } else {
661 sel = default_col;
662 }
663 ShowDropDownList(this, std::move(list), sel, widget);
664 }
665
666 void BuildGroupList(CompanyID owner)
667 {
668 if (!this->groups.NeedRebuild()) return;
669
670 this->groups.clear();
671
672 if (this->livery_class >= LC_GROUP_RAIL) {
673 VehicleType vtype = (VehicleType)(this->livery_class - LC_GROUP_RAIL);
674 BuildGuiGroupList(this->groups, false, owner, vtype);
675 }
676
677 this->groups.RebuildDone();
678 }
679
680 void SetRows()
681 {
682 if (this->livery_class < LC_GROUP_RAIL) {
683 this->rows = 0;
684 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
685 if (_livery_class[scheme] == this->livery_class && HasBit(_loaded_newgrf_features.used_liveries, scheme)) {
686 this->rows++;
687 }
688 }
689 } else {
690 this->rows = (uint)this->groups.size();
691 }
692
693 this->vscroll->SetCount(this->rows);
694 }
695
696public:
697 SelectCompanyLiveryWindow(WindowDesc &desc, CompanyID company, GroupID group) : Window(desc)
698 {
699 this->CreateNestedTree();
700 this->GetWidget<NWidgetStacked>(WID_SCL_SEC_COL_DROP_SEL)->SetDisplayedPlane(_loaded_newgrf_features.has_2CC ? 0 : SZSP_NONE);
701 this->vscroll = this->GetScrollbar(WID_SCL_MATRIX_SCROLLBAR);
702
703 if (group == GroupID::Invalid()) {
704 this->livery_class = LC_OTHER;
705 this->sel = 1;
706 this->LowerWidget(WID_SCL_CLASS_GENERAL);
707 this->BuildGroupList(company);
708 this->SetRows();
709 } else {
710 this->SetSelectedGroup(company, group);
711 }
712
713 this->FinishInitNested(company);
714 this->owner = company;
715 this->InvalidateData(1);
716 }
717
718 void SetSelectedGroup(CompanyID company, GroupID group)
719 {
720 this->RaiseWidget(WID_SCL_CLASS_GENERAL + this->livery_class);
721 const Group *g = Group::Get(group);
722 switch (g->vehicle_type) {
723 case VEH_TRAIN: this->livery_class = LC_GROUP_RAIL; break;
724 case VEH_ROAD: this->livery_class = LC_GROUP_ROAD; break;
725 case VEH_SHIP: this->livery_class = LC_GROUP_SHIP; break;
726 case VEH_AIRCRAFT: this->livery_class = LC_GROUP_AIRCRAFT; break;
727 default: NOT_REACHED();
728 }
729 this->sel = group.base();
730 this->LowerWidget(WID_SCL_CLASS_GENERAL + this->livery_class);
731
732 this->groups.ForceRebuild();
733 this->BuildGroupList(company);
734 this->SetRows();
735
736 /* Position scrollbar to selected group */
737 for (uint i = 0; i < this->rows; i++) {
738 if (this->groups[i].group->index == sel) {
739 this->vscroll->SetPosition(i - this->vscroll->GetCapacity() / 2);
740 break;
741 }
742 }
743 }
744
745 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
746 {
747 switch (widget) {
748 case WID_SCL_SPACER_DROPDOWN: {
749 /* The matrix widget below needs enough room to print all the schemes. */
750 Dimension d = {0, 0};
751 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
752 d = maxdim(d, GetStringBoundingBox(STR_LIVERY_DEFAULT + scheme));
753 }
754
755 size.width = std::max(size.width, 5 + d.width + padding.width);
756 break;
757 }
758
759 case WID_SCL_MATRIX: {
760 /* 11 items in the default rail class */
761 this->square = GetSpriteSize(SPR_SQUARE);
762 this->line_height = std::max(this->square.height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height;
763
764 size.height = 5 * this->line_height;
765 resize.width = 1;
766 fill.height = resize.height = this->line_height;
767 break;
768 }
769
770 case WID_SCL_SEC_COL_DROPDOWN:
771 if (!_loaded_newgrf_features.has_2CC) break;
772 [[fallthrough]];
773
774 case WID_SCL_PRI_COL_DROPDOWN: {
775 this->square = GetSpriteSize(SPR_SQUARE);
776 int string_padding = this->square.width + WidgetDimensions::scaled.hsep_normal + padding.width;
777 for (Colours colour = COLOUR_BEGIN; colour != COLOUR_END; colour++) {
778 size.width = std::max(size.width, GetStringBoundingBox(STR_COLOUR_DARK_BLUE + colour).width + string_padding);
779 }
780 size.width = std::max(size.width, GetStringBoundingBox(STR_COLOUR_DEFAULT).width + string_padding);
781 break;
782 }
783 }
784 }
785
786 void OnPaint() override
787 {
788 bool local = this->window_number == _local_company;
789
790 /* Disable dropdown controls if no scheme is selected */
791 bool disabled = this->livery_class < LC_GROUP_RAIL ? (this->sel == 0) : (this->sel == GroupID::Invalid());
792 this->SetWidgetDisabledState(WID_SCL_PRI_COL_DROPDOWN, !local || disabled);
793 this->SetWidgetDisabledState(WID_SCL_SEC_COL_DROPDOWN, !local || disabled);
794
795 this->BuildGroupList(this->window_number);
796
797 this->DrawWidgets();
798 }
799
800 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
801 {
802 switch (widget) {
803 case WID_SCL_CAPTION:
804 return GetString(STR_LIVERY_CAPTION, this->window_number);
805
806 case WID_SCL_PRI_COL_DROPDOWN:
807 case WID_SCL_SEC_COL_DROPDOWN: {
808 const Company *c = Company::Get(this->window_number);
809 bool primary = widget == WID_SCL_PRI_COL_DROPDOWN;
810 StringID colour = STR_COLOUR_DEFAULT;
811
812 if (this->livery_class < LC_GROUP_RAIL) {
813 if (this->sel != 0) {
814 LiveryScheme scheme = LS_DEFAULT;
815 for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
816 if (HasBit(this->sel, scheme)) break;
817 }
818 if (scheme == LS_END) scheme = LS_DEFAULT;
819 const Livery *livery = &c->livery[scheme];
820 if (scheme == LS_DEFAULT || livery->in_use.Test(primary ? Livery::Flag::Primary : Livery::Flag::Secondary)) {
821 colour = STR_COLOUR_DARK_BLUE + (primary ? livery->colour1 : livery->colour2);
822 }
823 }
824 } else {
825 if (this->sel != GroupID::Invalid()) {
826 const Group *g = Group::Get(this->sel);
827 const Livery *livery = &g->livery;
828 if (livery->in_use.Test(primary ? Livery::Flag::Primary : Livery::Flag::Secondary)) {
829 colour = STR_COLOUR_DARK_BLUE + (primary ? livery->colour1 : livery->colour2);
830 }
831 }
832 }
833 return GetString(colour);
834 }
835
836 default:
837 return this->Window::GetWidgetString(widget, stringid);
838 }
839 }
840
841 void DrawWidget(const Rect &r, WidgetID widget) const override
842 {
843 if (widget != WID_SCL_MATRIX) return;
844
845 bool rtl = _current_text_dir == TD_RTL;
846
847 /* Coordinates of scheme name column. */
848 const NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_SCL_SPACER_DROPDOWN);
849 Rect sch = nwi->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
850 /* Coordinates of first dropdown. */
851 nwi = this->GetWidget<NWidgetBase>(WID_SCL_PRI_COL_DROPDOWN);
852 Rect pri = nwi->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
853 /* Coordinates of second dropdown. */
854 nwi = this->GetWidget<NWidgetBase>(WID_SCL_SEC_COL_DROPDOWN);
855 Rect sec = nwi->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
856
857 Rect pri_squ = pri.WithWidth(this->square.width, rtl);
858 Rect sec_squ = sec.WithWidth(this->square.width, rtl);
859
860 pri = pri.Indent(this->square.width + WidgetDimensions::scaled.hsep_normal, rtl);
861 sec = sec.Indent(this->square.width + WidgetDimensions::scaled.hsep_normal, rtl);
862
863 Rect ir = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
864 int square_offs = (ir.Height() - this->square.height) / 2;
865 int text_offs = (ir.Height() - GetCharacterHeight(FS_NORMAL)) / 2;
866
867 int y = ir.top;
868
869 /* Helper function to draw livery info. */
870 auto draw_livery = [&](std::string_view str, const Livery &livery, bool is_selected, bool is_default_scheme, int indent) {
871 /* Livery Label. */
872 DrawString(sch.left + (rtl ? 0 : indent), sch.right - (rtl ? indent : 0), y + text_offs, str, is_selected ? TC_WHITE : TC_BLACK);
873
874 /* Text below the first dropdown. */
875 DrawSprite(SPR_SQUARE, GetColourPalette(livery.colour1), pri_squ.left, y + square_offs);
876 DrawString(pri.left, pri.right, y + text_offs, (is_default_scheme || livery.in_use.Test(Livery::Flag::Primary)) ? STR_COLOUR_DARK_BLUE + livery.colour1 : STR_COLOUR_DEFAULT, is_selected ? TC_WHITE : TC_GOLD);
877
878 /* Text below the second dropdown. */
879 if (sec.right > sec.left) { // Second dropdown has non-zero size.
880 DrawSprite(SPR_SQUARE, GetColourPalette(livery.colour2), sec_squ.left, y + square_offs);
881 DrawString(sec.left, sec.right, y + text_offs, (is_default_scheme || livery.in_use.Test(Livery::Flag::Secondary)) ? STR_COLOUR_DARK_BLUE + livery.colour2 : STR_COLOUR_DEFAULT, is_selected ? TC_WHITE : TC_GOLD);
882 }
883
884 y += this->line_height;
885 };
886
887 const Company *c = Company::Get(this->window_number);
888
889 if (livery_class < LC_GROUP_RAIL) {
890 int pos = this->vscroll->GetPosition();
891 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
892 if (_livery_class[scheme] == this->livery_class && HasBit(_loaded_newgrf_features.used_liveries, scheme)) {
893 if (pos-- > 0) continue;
894 draw_livery(GetString(STR_LIVERY_DEFAULT + scheme), c->livery[scheme], HasBit(this->sel, scheme), scheme == LS_DEFAULT, 0);
895 }
896 }
897 } else {
898 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->groups);
899 for (auto it = first; it != last; ++it) {
900 const Group *g = it->group;
901 draw_livery(GetString(STR_GROUP_NAME, g->index), g->livery, this->sel == g->index, false, it->indent * WidgetDimensions::scaled.hsep_indent);
902 }
903
904 if (this->vscroll->GetCount() == 0) {
905 const StringID empty_labels[] = { STR_LIVERY_TRAIN_GROUP_EMPTY, STR_LIVERY_ROAD_VEHICLE_GROUP_EMPTY, STR_LIVERY_SHIP_GROUP_EMPTY, STR_LIVERY_AIRCRAFT_GROUP_EMPTY };
906 VehicleType vtype = (VehicleType)(this->livery_class - LC_GROUP_RAIL);
907 DrawString(ir.left, ir.right, y + text_offs, empty_labels[vtype], TC_BLACK);
908 }
909 }
910 }
911
912 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
913 {
914 switch (widget) {
915 /* Livery Class buttons */
916 case WID_SCL_CLASS_GENERAL:
917 case WID_SCL_CLASS_RAIL:
918 case WID_SCL_CLASS_ROAD:
919 case WID_SCL_CLASS_SHIP:
920 case WID_SCL_CLASS_AIRCRAFT:
921 case WID_SCL_GROUPS_RAIL:
922 case WID_SCL_GROUPS_ROAD:
923 case WID_SCL_GROUPS_SHIP:
924 case WID_SCL_GROUPS_AIRCRAFT:
925 this->RaiseWidget(WID_SCL_CLASS_GENERAL + this->livery_class);
926 this->livery_class = (LiveryClass)(widget - WID_SCL_CLASS_GENERAL);
927 this->LowerWidget(WID_SCL_CLASS_GENERAL + this->livery_class);
928
929 /* Select the first item in the list */
930 if (this->livery_class < LC_GROUP_RAIL) {
931 this->sel = 0;
932 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
933 if (_livery_class[scheme] == this->livery_class && HasBit(_loaded_newgrf_features.used_liveries, scheme)) {
934 this->sel = 1 << scheme;
935 break;
936 }
937 }
938 } else {
939 this->sel = GroupID::Invalid().base();
940 this->groups.ForceRebuild();
941 this->BuildGroupList(this->window_number);
942
943 if (!this->groups.empty()) {
944 this->sel = this->groups[0].group->index.base();
945 }
946 }
947
948 this->SetRows();
949 this->SetDirty();
950 break;
951
952 case WID_SCL_PRI_COL_DROPDOWN: // First colour dropdown
953 ShowColourDropDownMenu(WID_SCL_PRI_COL_DROPDOWN);
954 break;
955
956 case WID_SCL_SEC_COL_DROPDOWN: // Second colour dropdown
957 ShowColourDropDownMenu(WID_SCL_SEC_COL_DROPDOWN);
958 break;
959
960 case WID_SCL_MATRIX: {
961 if (this->livery_class < LC_GROUP_RAIL) {
962 uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget);
963 if (row >= this->rows) return;
964
965 LiveryScheme j = (LiveryScheme)row;
966
967 for (LiveryScheme scheme = LS_BEGIN; scheme <= j && scheme < LS_END; scheme++) {
968 if (_livery_class[scheme] != this->livery_class || !HasBit(_loaded_newgrf_features.used_liveries, scheme)) j++;
969 }
970 assert(j < LS_END);
971
972 if (_ctrl_pressed) {
973 ToggleBit(this->sel, j);
974 } else {
975 this->sel = 1 << j;
976 }
977 } else {
978 auto it = this->vscroll->GetScrolledItemFromWidget(this->groups, pt.y, this, widget);
979 if (it == std::end(this->groups)) return;
980
981 this->sel = it->group->index.base();
982 }
983 this->SetDirty();
984 break;
985 }
986 }
987 }
988
989 void OnResize() override
990 {
991 this->vscroll->SetCapacityFromWidget(this, WID_SCL_MATRIX);
992 }
993
994 void OnDropdownSelect(WidgetID widget, int index, int) override
995 {
996 bool local = this->window_number == _local_company;
997 if (!local) return;
998
999 Colours colour = static_cast<Colours>(index);
1000 if (colour >= COLOUR_END) colour = INVALID_COLOUR;
1001
1002 if (this->livery_class < LC_GROUP_RAIL) {
1003 /* Set company colour livery */
1004 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1005 /* Changed colour for the selected scheme, or all visible schemes if CTRL is pressed. */
1006 if (HasBit(this->sel, scheme) || (_ctrl_pressed && _livery_class[scheme] == this->livery_class && HasBit(_loaded_newgrf_features.used_liveries, scheme))) {
1007 Command<CMD_SET_COMPANY_COLOUR>::Post(scheme, widget == WID_SCL_PRI_COL_DROPDOWN, colour);
1008 }
1009 }
1010 } else {
1011 /* Setting group livery */
1012 Command<CMD_SET_GROUP_LIVERY>::Post(static_cast<GroupID>(this->sel), widget == WID_SCL_PRI_COL_DROPDOWN, colour);
1013 }
1014 }
1015
1021 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1022 {
1023 if (!gui_scope) return;
1024
1025 if (data != -1) {
1026 /* data contains a VehicleType, rebuild list if it displayed */
1027 if (this->livery_class == data + LC_GROUP_RAIL) {
1028 this->groups.ForceRebuild();
1029 this->BuildGroupList(this->window_number);
1030 this->SetRows();
1031
1032 if (!Group::IsValidID(this->sel)) {
1033 this->sel = GroupID::Invalid().base();
1034 if (!this->groups.empty()) this->sel = this->groups[0].group->index.base();
1035 }
1036
1037 this->SetDirty();
1038 }
1039 return;
1040 }
1041
1042 this->SetWidgetsDisabledState(true, WID_SCL_CLASS_RAIL, WID_SCL_CLASS_ROAD, WID_SCL_CLASS_SHIP, WID_SCL_CLASS_AIRCRAFT);
1043
1044 bool current_class_valid = this->livery_class == LC_OTHER || this->livery_class >= LC_GROUP_RAIL;
1045 if (_settings_client.gui.liveries == LIT_ALL || (_settings_client.gui.liveries == LIT_COMPANY && this->window_number == _local_company)) {
1046 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1047 if (HasBit(_loaded_newgrf_features.used_liveries, scheme)) {
1048 if (_livery_class[scheme] == this->livery_class) current_class_valid = true;
1049 this->EnableWidget(WID_SCL_CLASS_GENERAL + _livery_class[scheme]);
1050 } else if (this->livery_class < LC_GROUP_RAIL) {
1051 ClrBit(this->sel, scheme);
1052 }
1053 }
1054 }
1055
1056 if (!current_class_valid) {
1057 Point pt = {0, 0};
1058 this->OnClick(pt, WID_SCL_CLASS_GENERAL, 1);
1059 }
1060 }
1061};
1062
1063static constexpr std::initializer_list<NWidgetPart> _nested_select_company_livery_widgets = {
1064 NWidget(NWID_HORIZONTAL),
1065 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1066 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SCL_CAPTION),
1067 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1068 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1069 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1070 EndContainer(),
1071 NWidget(NWID_HORIZONTAL),
1072 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_GENERAL), SetToolbarMinimalSize(1), SetFill(0, 1), SetSpriteTip(SPR_IMG_COMPANY_GENERAL, STR_LIVERY_GENERAL_TOOLTIP),
1073 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_RAIL), SetToolbarMinimalSize(1), SetFill(0, 1), SetSpriteTip(SPR_IMG_TRAINLIST, STR_LIVERY_TRAIN_TOOLTIP),
1074 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_ROAD), SetToolbarMinimalSize(1), SetFill(0, 1), SetSpriteTip(SPR_IMG_TRUCKLIST, STR_LIVERY_ROAD_VEHICLE_TOOLTIP),
1075 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_SHIP), SetToolbarMinimalSize(1), SetFill(0, 1), SetSpriteTip(SPR_IMG_SHIPLIST, STR_LIVERY_SHIP_TOOLTIP),
1076 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_AIRCRAFT), SetToolbarMinimalSize(1), SetFill(0, 1), SetSpriteTip(SPR_IMG_AIRPLANESLIST, STR_LIVERY_AIRCRAFT_TOOLTIP),
1077 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_GROUPS_RAIL), SetToolbarMinimalSize(1), SetFill(0, 1), SetSpriteTip(SPR_GROUP_LIVERY_TRAIN, STR_LIVERY_TRAIN_GROUP_TOOLTIP),
1078 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_GROUPS_ROAD), SetToolbarMinimalSize(1), SetFill(0, 1), SetSpriteTip(SPR_GROUP_LIVERY_ROADVEH, STR_LIVERY_ROAD_VEHICLE_GROUP_TOOLTIP),
1079 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_GROUPS_SHIP), SetToolbarMinimalSize(1), SetFill(0, 1), SetSpriteTip(SPR_GROUP_LIVERY_SHIP, STR_LIVERY_SHIP_GROUP_TOOLTIP),
1080 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_GROUPS_AIRCRAFT), SetToolbarMinimalSize(1), SetFill(0, 1), SetSpriteTip(SPR_GROUP_LIVERY_AIRCRAFT, STR_LIVERY_AIRCRAFT_GROUP_TOOLTIP),
1081 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 0), EndContainer(),
1082 EndContainer(),
1083 NWidget(NWID_HORIZONTAL),
1084 NWidget(WWT_MATRIX, COLOUR_GREY, WID_SCL_MATRIX), SetMinimalSize(275, 0), SetResize(1, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_LIVERY_PANEL_TOOLTIP), SetScrollbar(WID_SCL_MATRIX_SCROLLBAR),
1085 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SCL_MATRIX_SCROLLBAR),
1086 EndContainer(),
1087 NWidget(NWID_HORIZONTAL),
1088 NWidget(WWT_PANEL, COLOUR_GREY, WID_SCL_SPACER_DROPDOWN), SetFill(1, 1), SetResize(1, 0), EndContainer(),
1089 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SCL_PRI_COL_DROPDOWN), SetFill(0, 1), SetToolTip(STR_LIVERY_PRIMARY_TOOLTIP),
1090 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCL_SEC_COL_DROP_SEL),
1091 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SCL_SEC_COL_DROPDOWN), SetFill(0, 1), SetToolTip(STR_LIVERY_SECONDARY_TOOLTIP),
1092 EndContainer(),
1093 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1094 EndContainer(),
1095};
1096
1097static WindowDesc _select_company_livery_desc(
1098 WDP_AUTO, "company_colour_scheme", 0, 0,
1099 WC_COMPANY_COLOUR, WC_NONE,
1100 {},
1101 _nested_select_company_livery_widgets
1102);
1103
1104void ShowCompanyLiveryWindow(CompanyID company, GroupID group)
1105{
1106 SelectCompanyLiveryWindow *w = (SelectCompanyLiveryWindow *)BringWindowToFrontById(WC_COMPANY_COLOUR, company);
1107 if (w == nullptr) {
1108 new SelectCompanyLiveryWindow(_select_company_livery_desc, company, group);
1109 } else if (group != GroupID::Invalid()) {
1110 w->SetSelectedGroup(company, group);
1111 }
1112}
1113
1120 void DrawCompanyManagerFace(const CompanyManagerFace &cmf, Colours colour, const Rect &r)
1121{
1122 /* Determine offset from centre of drawing rect. */
1123 Dimension d = GetSpriteSize(SPR_GRADIENT);
1124 int x = CentreBounds(r.left, r.right, d.width);
1125 int y = CentreBounds(r.top, r.bottom, d.height);
1126
1127 FaceVars vars = GetCompanyManagerFaceVars(cmf.style);
1128
1129 /* First determine which parts are enabled. */
1130 uint64_t active_vars = GetActiveFaceVars(cmf, vars);
1131
1132 std::unordered_map<uint8_t, PaletteID> palettes;
1133
1134 /* Second, get palettes. */
1135 for (auto var : SetBitIterator(active_vars)) {
1136 if (vars[var].type != FaceVarType::Palette) continue;
1137
1138 PaletteID pal = PAL_NONE;
1139 switch (vars[var].GetBits(cmf)) {
1140 default: NOT_REACHED();
1141 case 0: pal = PALETTE_TO_BROWN; break;
1142 case 1: pal = PALETTE_TO_BLUE; break;
1143 case 2: pal = PALETTE_TO_GREEN; break;
1144 }
1145 for (uint8_t affected_var : SetBitIterator(std::get<uint64_t>(vars[var].data))) {
1146 palettes[affected_var] = pal;
1147 }
1148 }
1149
1150 /* Draw the gradient (background) */
1151 DrawSprite(SPR_GRADIENT, GetColourPalette(colour), x, y);
1152
1153 /* Thirdly, draw sprites. */
1154 for (auto var : SetBitIterator(active_vars)) {
1155 if (vars[var].type != FaceVarType::Sprite) continue;
1156
1157 auto it = palettes.find(var);
1158 PaletteID pal = (it == std::end(palettes)) ? PAL_NONE : it->second;
1159 DrawSprite(vars[var].GetSprite(cmf), pal, x, y);
1160 }
1161}
1162
1164 static constexpr std::initializer_list<NWidgetPart> _nested_select_company_manager_face_widgets = {
1165 NWidget(NWID_HORIZONTAL),
1166 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1167 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SCMF_CAPTION), SetStringTip(STR_FACE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1168 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCMF_TOGGLE_LARGE_SMALL), SetSpriteTip(SPR_LARGE_SMALL_WINDOW, STR_FACE_ADVANCED_TOOLTIP), SetAspect(WidgetDimensions::ASPECT_TOGGLE_SIZE),
1169 EndContainer(),
1170 NWidget(NWID_HORIZONTAL),
1171 NWidget(WWT_PANEL, COLOUR_GREY, WID_SCMF_SELECT_FACE),
1172 /* Left side */
1173 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0), SetPadding(4),
1174 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SCMF_FACE), SetMinimalSize(92, 119), SetFill(1, 0),
1175 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_RANDOM_NEW_FACE), SetFill(1, 0), SetStringTip(STR_FACE_NEW_FACE_BUTTON, STR_FACE_NEW_FACE_TOOLTIP),
1176 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON), SetFill(1, 0), SetStringTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP),
1177 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCMF_SEL_LOADSAVE), // Load/number/save buttons under the portrait in the advanced view.
1178 NWidget(NWID_VERTICAL),
1179 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(0, 1),
1180 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_LOAD), SetFill(1, 0), SetStringTip(STR_FACE_LOAD, STR_FACE_LOAD_TOOLTIP),
1181 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_FACECODE), SetFill(1, 0), SetStringTip(STR_FACE_FACECODE, STR_FACE_FACECODE_TOOLTIP),
1182 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_SAVE), SetFill(1, 0), SetStringTip(STR_FACE_SAVE, STR_FACE_SAVE_TOOLTIP),
1183 EndContainer(),
1184 EndContainer(),
1185 EndContainer(),
1186 EndContainer(),
1187 /* Right side */
1188 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCMF_SEL_PARTS), // Advanced face parts setting.
1189 NWidget(NWID_VERTICAL),
1190 NWidget(WWT_MATRIX, COLOUR_GREY, WID_SCMF_STYLE), SetResize(1, 0), SetFill(1, 0), SetMatrixDataTip(1, 1),
1191 NWidget(NWID_HORIZONTAL),
1192 NWidget(WWT_MATRIX, COLOUR_GREY, WID_SCMF_PARTS), SetResize(1, 1), SetFill(1, 1), SetMatrixDataTip(1, 0), SetScrollbar(WID_SCMF_PARTS_SCROLLBAR),
1193 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SCMF_PARTS_SCROLLBAR),
1194 EndContainer(),
1195 EndContainer(),
1196 EndContainer(),
1197 EndContainer(),
1198 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
1199 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_CANCEL), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_BUTTON_CANCEL, STR_FACE_CANCEL_TOOLTIP),
1200 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_ACCEPT), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_BUTTON_OK, STR_FACE_OK_TOOLTIP),
1201 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCMF_SEL_RESIZE),
1202 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1203 EndContainer(),
1204 EndContainer(),
1205};
1206
1208 class SelectCompanyManagerFaceWindow : public Window
1209{
1210 CompanyManagerFace face{};
1211 bool advanced = false;
1212 uint selected_var = UINT_MAX;
1213 uint click_state = 0;
1214 int line_height = 0;
1215
1216 std::vector<const FaceVar *> face_vars;
1217
1221 void UpdateData()
1222 {
1223 FaceVars vars = GetCompanyManagerFaceVars(this->face.style);
1224 ScaleAllCompanyManagerFaceBits(this->face, vars);
1225
1226 uint64_t active_vars = GetActiveFaceVars(this->face, vars);
1227 /* Exclude active parts which have no string. */
1228 for (auto var : SetBitIterator(active_vars)) {
1229 if (vars[var].name == STR_NULL) ClrBit(active_vars, var);
1230 }
1231
1232 /* Rebuild the sorted list of face variable pointers. */
1233 this->face_vars.clear();
1234 for (auto var : SetBitIterator(active_vars)) {
1235 this->face_vars.emplace_back(&vars[var]);
1236 }
1237 std::ranges::sort(this->face_vars, std::less{}, &FaceVar::position);
1238
1239 this->GetScrollbar(WID_SCMF_PARTS_SCROLLBAR)->SetCount(std::size(this->face_vars));
1240 }
1241
1242public:
1243 SelectCompanyManagerFaceWindow(WindowDesc &desc, Window *parent) : Window(desc)
1244 {
1245 this->CreateNestedTree();
1246 this->SelectDisplayPlanes(this->advanced);
1247 this->FinishInitNested(parent->window_number);
1248 this->parent = parent;
1249 this->owner = this->window_number;
1250 this->face = Company::Get(this->window_number)->face;
1251
1252 this->UpdateData();
1253 }
1254
1255 void OnInit() override
1256 {
1257 this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)) + WidgetDimensions::scaled.matrix.Vertical();
1258 }
1259
1264 void SelectDisplayPlanes(bool advanced)
1265 {
1266 this->GetWidget<NWidgetStacked>(WID_SCMF_SEL_LOADSAVE)->SetDisplayedPlane(advanced ? 0 : SZSP_HORIZONTAL);
1267 this->GetWidget<NWidgetStacked>(WID_SCMF_SEL_PARTS)->SetDisplayedPlane(advanced ? 0 : SZSP_NONE);
1268 this->GetWidget<NWidgetStacked>(WID_SCMF_SEL_RESIZE)->SetDisplayedPlane(advanced ? 0 : SZSP_NONE);
1269
1270 NWidgetCore *wi = this->GetWidget<NWidgetCore>(WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON);
1271 if (advanced) {
1272 wi->SetStringTip(STR_FACE_SIMPLE, STR_FACE_SIMPLE_TOOLTIP);
1273 } else {
1274 wi->SetStringTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP);
1275 }
1276 }
1277
1278 static StringID GetLongestString(StringID a, StringID b)
1279 {
1280 return GetStringBoundingBox(a).width > GetStringBoundingBox(b).width ? a : b;
1281 }
1282
1283 static uint GetMaximumFacePartsWidth()
1284 {
1285 StringID yes_no = GetLongestString(STR_FACE_YES, STR_FACE_NO);
1286
1287 uint width = 0;
1288 for (uint style_index = 0; style_index != GetNumCompanyManagerFaceStyles(); ++style_index) {
1289 FaceVars vars = GetCompanyManagerFaceVars(style_index);
1290 for (const auto &info : vars) {
1291 if (info.name == STR_NULL) continue;
1292 if (info.type == FaceVarType::Toggle) {
1293 width = std::max(width, GetStringBoundingBox(GetString(STR_FACE_SETTING_TOGGLE, info.name, yes_no)).width);
1294 } else {
1295 uint64_t max_digits = GetParamMaxValue(info.valid_values);
1296 width = std::max(width, GetStringBoundingBox(GetString(STR_FACE_SETTING_NUMERIC, info.name, max_digits, max_digits)).width);
1297 }
1298 }
1299 }
1300
1301 /* Include width of button and spacing. */
1302 width += SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide + WidgetDimensions::scaled.frametext.Horizontal();
1303 return width;
1304 }
1305
1306 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1307 {
1308 switch (widget) {
1309 case WID_SCMF_FACE:
1310 size = maxdim(size, GetScaledSpriteSize(SPR_GRADIENT));
1311 break;
1312
1313 case WID_SCMF_STYLE:
1314 size.height = this->line_height;
1315 break;
1316
1317 case WID_SCMF_PARTS:
1318 fill.height = resize.height = this->line_height;
1319 size.width = GetMaximumFacePartsWidth();
1320 size.height = resize.height * 5;
1321 break;
1322 }
1323 }
1324
1325 void DrawWidget(const Rect &r, WidgetID widget) const override
1326 {
1327 switch (widget) {
1328 case WID_SCMF_FACE:
1329 DrawCompanyManagerFace(this->face, Company::Get(this->window_number)->colour, r);
1330 break;
1331
1332 case WID_SCMF_STYLE: {
1333 Rect ir = r.Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero).WithHeight(this->line_height);
1334 bool rtl = _current_text_dir == TD_RTL;
1335
1336 Rect br = ir.CentreToHeight(SETTING_BUTTON_HEIGHT).WithWidth(SETTING_BUTTON_WIDTH, rtl);
1337 Rect tr = ir.Shrink(RectPadding::zero, WidgetDimensions::scaled.matrix).CentreToHeight(GetCharacterHeight(FS_NORMAL)).Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide, rtl);
1338
1339 DrawArrowButtons(br.left, br.top, COLOUR_YELLOW, this->selected_var == UINT_MAX - 1 ? this->click_state : 0, true, true);
1340 DrawString(tr, GetString(STR_FACE_SETTING_NUMERIC, STR_FACE_STYLE, this->face.style + 1, GetNumCompanyManagerFaceStyles()), TC_WHITE);
1341 break;
1342 }
1343
1344 case WID_SCMF_PARTS: {
1345 Rect ir = r.Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero).WithHeight(this->line_height);
1346 bool rtl = _current_text_dir == TD_RTL;
1347
1348 FaceVars vars = GetCompanyManagerFaceVars(this->face.style);
1349
1350 auto [first, last] = this->GetScrollbar(WID_SCMF_PARTS_SCROLLBAR)->GetVisibleRangeIterators(this->face_vars);
1351 for (auto it = first; it != last; ++it) {
1352 const uint8_t var = static_cast<uint8_t>(*it - vars.data());
1353 const FaceVar &facevar = **it;
1354
1355 Rect br = ir.CentreToHeight(SETTING_BUTTON_HEIGHT).WithWidth(SETTING_BUTTON_WIDTH, rtl);
1356 Rect tr = ir.Shrink(RectPadding::zero, WidgetDimensions::scaled.matrix).CentreToHeight(GetCharacterHeight(FS_NORMAL)).Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide, rtl);
1357
1358 uint val = vars[var].GetBits(this->face);
1359 if (facevar.type == FaceVarType::Toggle) {
1360 DrawBoolButton(br.left, br.top, COLOUR_YELLOW, COLOUR_GREY, val == 1, true);
1361 DrawString(tr, GetString(STR_FACE_SETTING_TOGGLE, facevar.name, val == 1 ? STR_FACE_YES : STR_FACE_NO), TC_WHITE);
1362 } else {
1363 DrawArrowButtons(br.left, br.top, COLOUR_YELLOW, this->selected_var == var ? this->click_state : 0, true, true);
1364 DrawString(tr, GetString(STR_FACE_SETTING_NUMERIC, facevar.name, val + 1, facevar.valid_values), TC_WHITE);
1365 }
1366
1367 ir = ir.Translate(0, this->line_height);
1368 }
1369 break;
1370 }
1371 }
1372 }
1373
1374 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1375 {
1376 switch (widget) {
1377 /* Toggle size, advanced/simple face selection */
1378 case WID_SCMF_TOGGLE_LARGE_SMALL:
1379 case WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON:
1380 this->advanced = !this->advanced;
1381 this->SelectDisplayPlanes(this->advanced);
1382 this->ReInit();
1383 break;
1384
1385 /* OK button */
1386 case WID_SCMF_ACCEPT:
1387 Command<CMD_SET_COMPANY_MANAGER_FACE>::Post(this->face.style, this->face.bits);
1388 [[fallthrough]];
1389
1390 /* Cancel button */
1391 case WID_SCMF_CANCEL:
1392 this->Close();
1393 break;
1394
1395 /* Load button */
1396 case WID_SCMF_LOAD: {
1397 auto cmf = ParseCompanyManagerFaceCode(_company_manager_face);
1398 if (cmf.has_value()) this->face = *cmf;
1399 ShowErrorMessage(GetEncodedString(STR_FACE_LOAD_DONE), {}, WL_INFO);
1400 this->UpdateData();
1401 this->SetDirty();
1402 break;
1403 }
1404
1405 /* 'Company manager face number' button, view and/or set company manager face number */
1406 case WID_SCMF_FACECODE:
1407 ShowQueryString(FormatCompanyManagerFaceCode(this->face), STR_FACE_FACECODE_CAPTION, 128, this, CS_ALPHANUMERAL, {});
1408 break;
1409
1410 /* Save button */
1411 case WID_SCMF_SAVE:
1412 _company_manager_face = FormatCompanyManagerFaceCode(this->face);
1413 ShowErrorMessage(GetEncodedString(STR_FACE_SAVE_DONE), {}, WL_INFO);
1414 break;
1415
1416 /* Randomize face button */
1417 case WID_SCMF_RANDOM_NEW_FACE:
1418 RandomiseCompanyManagerFace(this->face, _interactive_random);
1419 this->UpdateData();
1420 this->SetDirty();
1421 break;
1422
1423 case WID_SCMF_STYLE: {
1424 bool rtl = _current_text_dir == TD_RTL;
1425 Rect ir = this->GetWidget<NWidgetCore>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero);
1426 Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
1427
1428 uint num_styles = GetNumCompanyManagerFaceStyles();
1429 this->selected_var = UINT_MAX - 1;
1430 if (IsInsideBS(pt.x, br.left, SETTING_BUTTON_WIDTH / 2)) {
1431 SetCompanyManagerFaceStyle(this->face, (this->face.style + num_styles - 1) % num_styles);
1432 this->click_state = 1;
1433 } else if (IsInsideBS(pt.x, br.left + SETTING_BUTTON_WIDTH / 2, SETTING_BUTTON_WIDTH / 2)) {
1434 SetCompanyManagerFaceStyle(this->face, (this->face.style + 1) % num_styles);
1435 this->click_state = 2;
1436 }
1437
1438 this->UpdateData();
1439 this->SetTimeout();
1440 this->SetDirty();
1441 break;
1442 }
1443
1444 case WID_SCMF_PARTS: {
1445 bool rtl = _current_text_dir == TD_RTL;
1446 Rect ir = this->GetWidget<NWidgetCore>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero);
1447 Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
1448
1449 this->selected_var = UINT_MAX;
1450
1451 FaceVars vars = GetCompanyManagerFaceVars(this->face.style);
1452 auto it = this->GetScrollbar(WID_SCMF_PARTS_SCROLLBAR)->GetScrolledItemFromWidget(this->face_vars, pt.y, this, widget, 0, this->line_height);
1453 if (it == std::end(this->face_vars)) break;
1454
1455 this->selected_var = static_cast<uint8_t>(*it - vars.data());
1456 const auto &facevar = **it;
1457
1458 if (facevar.type == FaceVarType::Toggle) {
1459 if (!IsInsideBS(pt.x, br.left, SETTING_BUTTON_WIDTH)) break;
1460 facevar.ChangeBits(this->face, 1);
1461 this->UpdateData();
1462 } else {
1463 if (IsInsideBS(pt.x, br.left, SETTING_BUTTON_WIDTH / 2)) {
1464 facevar.ChangeBits(this->face, -1);
1465 this->click_state = 1;
1466 } else if (IsInsideBS(pt.x, br.left + SETTING_BUTTON_WIDTH / 2, SETTING_BUTTON_WIDTH / 2)) {
1467 facevar.ChangeBits(this->face, 1);
1468 this->click_state = 2;
1469 } else {
1470 break;
1471 }
1472 }
1473
1474 this->SetTimeout();
1475 this->SetDirty();
1476 break;
1477 }
1478 }
1479 }
1480
1481 void OnResize() override
1482 {
1483 if (auto *wid = this->GetWidget<NWidgetResizeBase>(WID_SCMF_PARTS); wid != nullptr) {
1484 /* Workaround for automatic widget sizing ignoring resize steps. Manually ensure parts matrix is a
1485 * multiple of its resize step. This trick only works here as the window itself is not resizable. */
1486 if (wid->UpdateVerticalSize((wid->current_y + wid->resize_y - 1) / wid->resize_y * wid->resize_y)) {
1487 this->ReInit();
1488 return;
1489 }
1490 }
1491
1492 this->GetScrollbar(WID_SCMF_PARTS_SCROLLBAR)->SetCapacityFromWidget(this, WID_SCMF_PARTS);
1493 }
1494
1495 void OnTimeout() override
1496 {
1497 this->click_state = 0;
1498 this->selected_var = UINT_MAX;
1499 this->SetDirty();
1500 }
1501
1502 void OnQueryTextFinished(std::optional<std::string> str) override
1503 {
1504 if (!str.has_value()) return;
1505 /* Parse new company manager face number */
1506 auto cmf = ParseCompanyManagerFaceCode(*str);
1507 if (cmf.has_value()) {
1508 this->face = *cmf;
1509 ShowErrorMessage(GetEncodedString(STR_FACE_FACECODE_SET), {}, WL_INFO);
1510 this->UpdateData();
1511 this->SetDirty();
1512 } else {
1513 ShowErrorMessage(GetEncodedString(STR_FACE_FACECODE_ERR), {}, WL_INFO);
1514 }
1515 }
1516};
1517
1519 static WindowDesc _select_company_manager_face_desc(
1520 WDP_AUTO, {}, 0, 0,
1521 WC_COMPANY_MANAGER_FACE, WC_NONE,
1522 WindowDefaultFlag::Construction,
1523 _nested_select_company_manager_face_widgets
1524);
1525
1531 static void DoSelectCompanyManagerFace(Window *parent)
1532{
1533 if (!Company::IsValidID(parent->window_number)) return;
1534
1535 if (BringWindowToFrontById(WC_COMPANY_MANAGER_FACE, parent->window_number)) return;
1536 new SelectCompanyManagerFaceWindow(_select_company_manager_face_desc, parent);
1537}
1538
1539static constexpr std::initializer_list<NWidgetPart> _nested_company_infrastructure_widgets = {
1540 NWidget(NWID_HORIZONTAL),
1541 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1542 NWidget(WWT_CAPTION, COLOUR_GREY, WID_CI_CAPTION),
1543 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1544 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1545 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1546 EndContainer(),
1547 NWidget(NWID_HORIZONTAL),
1548 NWidget(WWT_PANEL, COLOUR_GREY, WID_CI_LIST), SetFill(1, 1), SetResize(0, 1),
1549 SetMinimalTextLines(5, WidgetDimensions::unscaled.framerect.Vertical()), SetScrollbar(WID_CI_SCROLLBAR),
1550 EndContainer(),
1551 NWidget(NWID_VERTICAL),
1552 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_CI_SCROLLBAR),
1553 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1554 EndContainer(),
1555 EndContainer(),
1556};
1557
1561 struct CompanyInfrastructureWindow : Window
1562{
1563 enum class InfrastructureItemType : uint8_t {
1564 Header,
1565 Spacer,
1566 Value,
1567 Total,
1568 };
1569
1570 struct InfrastructureItem {
1571 InfrastructureItemType type;
1572 StringID label;
1573 uint count;
1574 Money cost;
1575 };
1576
1577 uint count_width = 0;
1578 uint cost_width = 0;
1579
1580 mutable std::vector<InfrastructureItem> list;
1581
1582 CompanyInfrastructureWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
1583 {
1584 this->InitNested(window_number);
1585 this->owner = this->window_number;
1586 }
1587
1588 void OnInit() override
1589 {
1590 this->UpdateInfrastructureList();
1591 }
1592
1593 void UpdateInfrastructureList()
1594 {
1595 this->list.clear();
1596
1597 const Company *c = Company::GetIfValid(this->window_number);
1598 if (c == nullptr) return;
1599
1600 Money total_monthly_cost = 0;
1601
1602 if (uint32_t rail_total = c->infrastructure.GetRailTotal(); rail_total > 0) {
1603 /* Rail types and signals. */
1604 this->list.emplace_back(InfrastructureItemType::Header, STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT);
1605
1606 for (const RailType &rt : _sorted_railtypes) {
1607 if (c->infrastructure.rail[rt] == 0) continue;
1608 Money monthly_cost = RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total);
1609 total_monthly_cost += monthly_cost;
1610 this->list.emplace_back(InfrastructureItemType::Value, GetRailTypeInfo(rt)->strings.name, c->infrastructure.rail[rt], monthly_cost);
1611 }
1612
1613 if (c->infrastructure.signal > 0) {
1614 Money monthly_cost = SignalMaintenanceCost(c->infrastructure.signal);
1615 total_monthly_cost += monthly_cost;
1616 this->list.emplace_back(InfrastructureItemType::Value, STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS, c->infrastructure.signal, monthly_cost);
1617 }
1618 }
1619
1620 if (uint32_t road_total = c->infrastructure.GetRoadTotal(); road_total > 0) {
1621 /* Road types. */
1622 if (!this->list.empty()) this->list.emplace_back(InfrastructureItemType::Spacer);
1623 this->list.emplace_back(InfrastructureItemType::Header, STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT);
1624
1625 for (const RoadType &rt : _sorted_roadtypes) {
1626 if (!RoadTypeIsRoad(rt)) continue;
1627 if (c->infrastructure.road[rt] == 0) continue;
1628 Money monthly_cost = RoadMaintenanceCost(rt, c->infrastructure.road[rt], road_total);
1629 total_monthly_cost += monthly_cost;
1630 this->list.emplace_back(InfrastructureItemType::Value, GetRoadTypeInfo(rt)->strings.name, c->infrastructure.road[rt], monthly_cost);
1631 }
1632 }
1633
1634 if (uint32_t tram_total = c->infrastructure.GetTramTotal(); tram_total > 0) {
1635 /* Tram types. */
1636 if (!this->list.empty()) this->list.emplace_back(InfrastructureItemType::Spacer);
1637 this->list.emplace_back(InfrastructureItemType::Header, STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT);
1638
1639 for (const RoadType &rt : _sorted_roadtypes) {
1640 if (!RoadTypeIsTram(rt)) continue;
1641 if (c->infrastructure.road[rt] == 0) continue;
1642 Money monthly_cost = RoadMaintenanceCost(rt, c->infrastructure.road[rt], tram_total);
1643 total_monthly_cost += monthly_cost;
1644 this->list.emplace_back(InfrastructureItemType::Value, GetRoadTypeInfo(rt)->strings.name, c->infrastructure.road[rt], monthly_cost);
1645 }
1646 }
1647
1648 if (c->infrastructure.water > 0) {
1649 /* Canals, locks, and ship depots (docks are counted as stations). */
1650 if (!this->list.empty()) this->list.emplace_back(InfrastructureItemType::Spacer);
1651 this->list.emplace_back(InfrastructureItemType::Header, STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT);
1652
1653 Money monthly_cost = CanalMaintenanceCost(c->infrastructure.water);
1654 total_monthly_cost += monthly_cost;
1655 this->list.emplace_back(InfrastructureItemType::Value, STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS, c->infrastructure.water, monthly_cost);
1656 }
1657
1658 if (Money airport_cost = AirportMaintenanceCost(c->index); airport_cost > 0 || c->infrastructure.station > 0) {
1659 /* Stations and airports. */
1660 if (!this->list.empty()) this->list.emplace_back(InfrastructureItemType::Spacer);
1661 this->list.emplace_back(InfrastructureItemType::Header, STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT);
1662
1663 if (c->infrastructure.station > 0) {
1664 Money monthly_cost = StationMaintenanceCost(c->infrastructure.station);
1665 total_monthly_cost += monthly_cost;
1666 this->list.emplace_back(InfrastructureItemType::Value, STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS, c->infrastructure.station, monthly_cost);
1667 }
1668
1669 if (airport_cost > 0) {
1670 Money monthly_cost = airport_cost;
1671 total_monthly_cost += monthly_cost;
1672 this->list.emplace_back(InfrastructureItemType::Value, STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS, c->infrastructure.airport, monthly_cost);
1673 }
1674 }
1675
1676 if (_settings_game.economy.infrastructure_maintenance) {
1677 /* Total monthly maintenance cost. */
1678 this->list.emplace_back(InfrastructureItemType::Spacer);
1679 this->list.emplace_back(InfrastructureItemType::Total, STR_NULL, 0, total_monthly_cost);
1680 }
1681
1682 /* Update scrollbar. */
1683 this->GetScrollbar(WID_CI_SCROLLBAR)->SetCount(std::size(list));
1684 }
1685
1686 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
1687 {
1688 switch (widget) {
1689 case WID_CI_CAPTION:
1690 return GetString(STR_COMPANY_INFRASTRUCTURE_VIEW_CAPTION, this->window_number);
1691
1692 default:
1693 return this->Window::GetWidgetString(widget, stringid);
1694 }
1695 }
1696
1697 void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize) override
1698 {
1699 if (def_height == 0) {
1700 /* Try to open the window with the exact required rows, but clamp to a reasonable limit. */
1701 int rows = (this->GetWidget<NWidgetBase>(WID_CI_LIST)->current_y - WidgetDimensions::scaled.framerect.Vertical()) / GetCharacterHeight(FS_NORMAL);
1702 int delta = std::min(20, static_cast<int>(std::size(this->list))) - rows;
1703 def_height = this->height + delta * GetCharacterHeight(FS_NORMAL);
1704 }
1705
1706 this->Window::FindWindowPlacementAndResize(def_width, def_height, allow_resize);
1707 }
1708
1709 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1710 {
1711 if (widget != WID_CI_LIST) return;
1712
1713 uint max_count = 1000; // Some random number to reserve minimum space.
1714 Money max_cost = 1000000; // Some random number to reserve minimum space.
1715
1716 /* List of headers that might be used. */
1717 static constexpr StringID header_strings[] = {
1718 STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT,
1719 STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT,
1720 STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT,
1721 STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT,
1722 STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT,
1723 };
1724 /* List of labels that might be used. */
1725 static constexpr StringID label_strings[] = {
1726 STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS,
1727 STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS,
1728 STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS,
1729 STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS,
1730 };
1731
1732 uint max_header_width = GetStringListWidth(header_strings);
1733 uint max_label_width = GetStringListWidth(label_strings);
1734
1735 /* Include width of all possible rail and road types. */
1736 for (const RailType &rt : _sorted_railtypes) max_label_width = std::max(max_label_width, GetStringBoundingBox(GetRailTypeInfo(rt)->strings.name).width);
1737 for (const RoadType &rt : _sorted_roadtypes) max_label_width = std::max(max_label_width, GetStringBoundingBox(GetRoadTypeInfo(rt)->strings.name).width);
1738
1739 for (const InfrastructureItem &entry : this->list) {
1740 max_count = std::max(max_count, entry.count);
1741 max_cost = std::max(max_cost, entry.cost * 12);
1742 }
1743
1744 max_label_width += WidgetDimensions::scaled.hsep_indent;
1745 this->count_width = GetStringBoundingBox(GetString(STR_JUST_COMMA, max_count)).width;
1746
1747 if (_settings_game.economy.infrastructure_maintenance) {
1748 this->cost_width = GetStringBoundingBox(GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR, max_cost)).width;
1749 } else {
1750 this->cost_width = 0;
1751 }
1752
1753 size.width = max_label_width + WidgetDimensions::scaled.hsep_wide + this->count_width + WidgetDimensions::scaled.hsep_wide + this->cost_width;
1754 size.width = std::max(size.width, max_header_width) + WidgetDimensions::scaled.framerect.Horizontal();
1755
1756 fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
1757 }
1758
1759 void DrawWidget(const Rect &r, WidgetID widget) const override
1760 {
1761 if (widget != WID_CI_LIST) return;
1762
1763 bool rtl = _current_text_dir == TD_RTL; // We allocate space from end-to-start so the label fills.
1764 int line_height = GetCharacterHeight(FS_NORMAL);
1765
1766 Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
1767 Rect countr = ir.WithWidth(this->count_width, !rtl);
1768 Rect costr = ir.Indent(this->count_width + WidgetDimensions::scaled.hsep_wide, !rtl).WithWidth(this->cost_width, !rtl);
1769 Rect labelr = ir.Indent(this->count_width + WidgetDimensions::scaled.hsep_wide + this->cost_width + WidgetDimensions::scaled.hsep_wide, !rtl);
1770
1771 auto [first, last] = this->GetScrollbar(WID_CI_SCROLLBAR)->GetVisibleRangeIterators(this->list);
1772 for (auto it = first; it != last; ++it) {
1773 switch (it->type) {
1774 case InfrastructureItemType::Header:
1775 /* Header is allowed to fill the window's width. */
1776 DrawString(ir.left, ir.right, labelr.top, GetString(it->label), TC_ORANGE);
1777 break;
1778
1779 case InfrastructureItemType::Spacer:
1780 break;
1781
1782 case InfrastructureItemType::Total:
1783 /* Draw line in the spacer above the total. */
1784 GfxFillRect(costr.Translate(0, -WidgetDimensions::scaled.vsep_normal).WithHeight(WidgetDimensions::scaled.fullbevel.top), PC_WHITE);
1785 DrawString(costr, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR, it->cost * 12), TC_BLACK, SA_RIGHT | SA_FORCE);
1786 break;
1787
1788 case InfrastructureItemType::Value:
1789 DrawString(labelr.Indent(WidgetDimensions::scaled.hsep_indent, rtl), GetString(it->label), TC_WHITE);
1790 DrawString(countr, GetString(STR_JUST_COMMA, it->count), TC_WHITE, SA_RIGHT | SA_FORCE);
1791 if (_settings_game.economy.infrastructure_maintenance) {
1792 DrawString(costr, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR, it->cost * 12), TC_BLACK, SA_RIGHT | SA_FORCE);
1793 }
1794 break;
1795 }
1796
1797 labelr.top += line_height;
1798 countr.top += line_height;
1799 costr.top += line_height;
1800 }
1801 }
1802
1803 const IntervalTimer<TimerWindow> redraw_interval = {std::chrono::seconds(1), [this](auto) {
1804 this->UpdateInfrastructureList();
1805 this->SetWidgetDirty(WID_CI_LIST);
1806 }};
1807
1808 void OnResize() override
1809 {
1810 this->GetScrollbar(WID_CI_SCROLLBAR)->SetCapacityFromWidget(this, WID_CI_LIST, WidgetDimensions::scaled.framerect.top);
1811 }
1812
1818 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1819 {
1820 if (!gui_scope) return;
1821
1822 this->ReInit();
1823 }
1824};
1825
1826static WindowDesc _company_infrastructure_desc(
1827 WDP_AUTO, "company_infrastructure", 0, 0,
1828 WC_COMPANY_INFRASTRUCTURE, WC_NONE,
1829 {},
1830 _nested_company_infrastructure_widgets
1831);
1832
1837 static void ShowCompanyInfrastructure(CompanyID company)
1838{
1839 if (!Company::IsValidID(company)) return;
1840 AllocateWindowDescFront<CompanyInfrastructureWindow>(_company_infrastructure_desc, company);
1841}
1842
1843static constexpr std::initializer_list<NWidgetPart> _nested_company_widgets = {
1844 NWidget(NWID_HORIZONTAL),
1845 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1846 NWidget(WWT_CAPTION, COLOUR_GREY, WID_C_CAPTION),
1847 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1848 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1849 EndContainer(),
1850 NWidget(WWT_PANEL, COLOUR_GREY),
1851 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0), SetPadding(4),
1852 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1853 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_FACE), SetMinimalSize(92, 119), SetFill(1, 0),
1854 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_FACE_TITLE), SetFill(1, 1), SetMinimalTextLines(2, 0),
1855 EndContainer(),
1856 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1857 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1858 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1859 NWidget(WWT_TEXT, INVALID_COLOUR, WID_C_DESC_INAUGURATION), SetFill(1, 0),
1860 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1861 NWidget(WWT_LABEL, INVALID_COLOUR, WID_C_DESC_COLOUR_SCHEME), SetStringTip(STR_COMPANY_VIEW_COLOUR_SCHEME_TITLE),
1862 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_DESC_COLOUR_SCHEME_EXAMPLE), SetMinimalSize(30, 0), SetFill(1, 1),
1863 EndContainer(),
1864 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1865 NWidget(WWT_TEXT, INVALID_COLOUR, WID_C_DESC_VEHICLE), SetStringTip(STR_COMPANY_VIEW_VEHICLES_TITLE), SetAlignment(SA_LEFT | SA_TOP),
1866 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_DESC_VEHICLE_COUNTS), SetMinimalTextLines(4, 0), SetFill(1, 1),
1867 EndContainer(),
1868 EndContainer(),
1869 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1870 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_VIEW_BUILD_HQ),
1871 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_VIEW_HQ), SetStringTip(STR_COMPANY_VIEW_VIEW_HQ_BUTTON, STR_COMPANY_VIEW_VIEW_HQ_TOOLTIP),
1872 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_C_BUILD_HQ), SetStringTip(STR_COMPANY_VIEW_BUILD_HQ_BUTTON, STR_COMPANY_VIEW_BUILD_HQ_TOOLTIP),
1873 EndContainer(),
1874 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_RELOCATE),
1875 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_C_RELOCATE_HQ), SetStringTip(STR_COMPANY_VIEW_RELOCATE_HQ, STR_COMPANY_VIEW_RELOCATE_HQ_TOOLTIP),
1876 NWidget(NWID_SPACER),
1877 EndContainer(),
1878 EndContainer(),
1879 EndContainer(),
1880
1881 NWidget(WWT_TEXT, INVALID_COLOUR, WID_C_DESC_COMPANY_VALUE), SetFill(1, 0),
1882
1883 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1884 NWidget(WWT_TEXT, INVALID_COLOUR, WID_C_DESC_INFRASTRUCTURE), SetStringTip(STR_COMPANY_VIEW_INFRASTRUCTURE), SetAlignment(SA_LEFT | SA_TOP),
1885 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_DESC_INFRASTRUCTURE_COUNTS), SetMinimalTextLines(5, 0), SetFill(1, 0),
1886 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1),
1887 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_VIEW_INFRASTRUCTURE), SetStringTip(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP),
1888 EndContainer(),
1889 EndContainer(),
1890
1891 /* Multi player buttons. */
1892 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), SetPIPRatio(1, 0, 0),
1893 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1894 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_HOSTILE_TAKEOVER),
1895 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_HOSTILE_TAKEOVER), SetStringTip(STR_COMPANY_VIEW_HOSTILE_TAKEOVER_BUTTON, STR_COMPANY_VIEW_HOSTILE_TAKEOVER_TOOLTIP),
1896 EndContainer(),
1897 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_GIVE_MONEY),
1898 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_GIVE_MONEY), SetStringTip(STR_COMPANY_VIEW_GIVE_MONEY_BUTTON, STR_COMPANY_VIEW_GIVE_MONEY_TOOLTIP),
1899 EndContainer(),
1900 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_MULTIPLAYER),
1901 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_COMPANY_JOIN), SetStringTip(STR_COMPANY_VIEW_JOIN, STR_COMPANY_VIEW_JOIN_TOOLTIP),
1902 EndContainer(),
1903 EndContainer(),
1904 EndContainer(),
1905 EndContainer(),
1906 EndContainer(),
1907 EndContainer(),
1908 /* Button bars at the bottom. */
1909 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_BUTTONS),
1910 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
1911 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_NEW_FACE), SetFill(1, 0), SetStringTip(STR_COMPANY_VIEW_NEW_FACE_BUTTON, STR_COMPANY_VIEW_NEW_FACE_TOOLTIP),
1912 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_COLOUR_SCHEME), SetFill(1, 0), SetStringTip(STR_COMPANY_VIEW_COLOUR_SCHEME_BUTTON, STR_COMPANY_VIEW_COLOUR_SCHEME_TOOLTIP),
1913 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_PRESIDENT_NAME), SetFill(1, 0), SetStringTip(STR_COMPANY_VIEW_PRESIDENT_NAME_BUTTON, STR_COMPANY_VIEW_PRESIDENT_NAME_TOOLTIP),
1914 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_COMPANY_NAME), SetFill(1, 0), SetStringTip(STR_COMPANY_VIEW_COMPANY_NAME_BUTTON, STR_COMPANY_VIEW_COMPANY_NAME_TOOLTIP),
1915 EndContainer(),
1916 EndContainer(),
1917};
1918
1920 static const StringID _company_view_vehicle_count_strings[] = {
1921 STR_COMPANY_VIEW_TRAINS, STR_COMPANY_VIEW_ROAD_VEHICLES, STR_COMPANY_VIEW_SHIPS, STR_COMPANY_VIEW_AIRCRAFT
1922};
1923
1927 struct CompanyWindow : Window
1928{
1929 CompanyWidgets query_widget{};
1930
1932 enum CompanyWindowPlanes : uint8_t {
1933 /* Display planes of the #WID_C_SELECT_VIEW_BUILD_HQ selection widget. */
1934 CWP_VB_VIEW = 0,
1935 CWP_VB_BUILD,
1936
1937 /* Display planes of the #WID_C_SELECT_RELOCATE selection widget. */
1938 CWP_RELOCATE_SHOW = 0,
1939 CWP_RELOCATE_HIDE,
1940 };
1941
1942 CompanyWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
1943 {
1944 this->InitNested(window_number);
1945 this->owner = this->window_number;
1946 this->OnInvalidateData();
1947 }
1948
1949 void OnPaint() override
1950 {
1951 const Company *c = Company::Get(this->window_number);
1952 bool local = this->window_number == _local_company;
1953
1954 if (!this->IsShaded()) {
1955 bool reinit = false;
1956
1957 /* Button bar selection. */
1958 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_BUTTONS)->SetDisplayedPlane(local ? 0 : SZSP_NONE);
1959
1960 /* Build HQ button handling. */
1961 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_VIEW_BUILD_HQ)->SetDisplayedPlane((local && c->location_of_HQ == INVALID_TILE) ? CWP_VB_BUILD : CWP_VB_VIEW);
1962
1963 this->SetWidgetDisabledState(WID_C_VIEW_HQ, c->location_of_HQ == INVALID_TILE);
1964
1965 /* Enable/disable 'Relocate HQ' button. */
1966 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_RELOCATE)->SetDisplayedPlane((!local || c->location_of_HQ == INVALID_TILE) ? CWP_RELOCATE_HIDE : CWP_RELOCATE_SHOW);
1967 /* Enable/disable 'Give money' button. */
1968 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_GIVE_MONEY)->SetDisplayedPlane((local || _local_company == COMPANY_SPECTATOR || !_settings_game.economy.give_money) ? SZSP_NONE : 0);
1969 /* Enable/disable 'Hostile Takeover' button. */
1970 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_HOSTILE_TAKEOVER)->SetDisplayedPlane((local || _local_company == COMPANY_SPECTATOR || !c->is_ai || _networking) ? SZSP_NONE : 0);
1971
1972 /* Multiplayer buttons. */
1973 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_MULTIPLAYER)->SetDisplayedPlane((!_networking || !NetworkCanJoinCompany(c->index) || _local_company == c->index) ? (int)SZSP_NONE : 0);
1974
1975 this->SetWidgetDisabledState(WID_C_COMPANY_JOIN, c->is_ai);
1976
1977 if (reinit) {
1978 this->ReInit();
1979 return;
1980 }
1981 }
1982
1983 this->DrawWidgets();
1984 }
1985
1986 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1987 {
1988 switch (widget) {
1989 case WID_C_FACE:
1990 size = maxdim(size, GetScaledSpriteSize(SPR_GRADIENT));
1991 break;
1992
1993 case WID_C_DESC_COLOUR_SCHEME_EXAMPLE: {
1994 Point offset;
1995 Dimension d = GetSpriteSize(SPR_VEH_BUS_SW_VIEW, &offset);
1996 d.width -= offset.x;
1997 d.height -= offset.y;
1998 size = maxdim(size, d);
1999 break;
2000 }
2001
2002 case WID_C_DESC_COMPANY_VALUE:
2003 /* INT64_MAX is arguably the maximum company value */
2004 size.width = GetStringBoundingBox(GetString(STR_COMPANY_VIEW_COMPANY_VALUE, INT64_MAX)).width;
2005 break;
2006
2007 case WID_C_DESC_VEHICLE_COUNTS: {
2008 uint64_t max_value = GetParamMaxValue(5000); // Maximum number of vehicles
2009 for (const auto &count_string : _company_view_vehicle_count_strings) {
2010 size.width = std::max(size.width, GetStringBoundingBox(GetString(count_string, max_value)).width + padding.width);
2011 }
2012 break;
2013 }
2014
2015 case WID_C_DESC_INFRASTRUCTURE_COUNTS: {
2016 uint64_t max_value = GetParamMaxValue(UINT_MAX);
2017 size.width = GetStringBoundingBox(GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL, max_value)).width;
2018 size.width = std::max(size.width, GetStringBoundingBox(GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD, max_value)).width);
2019 size.width = std::max(size.width, GetStringBoundingBox(GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_WATER, max_value)).width);
2020 size.width = std::max(size.width, GetStringBoundingBox(GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_STATION, max_value)).width);
2021 size.width = std::max(size.width, GetStringBoundingBox(GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT, max_value)).width);
2022 size.width = std::max(size.width, GetStringBoundingBox(GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_NONE, max_value)).width);
2023 size.width += padding.width;
2024 break;
2025 }
2026
2027 case WID_C_VIEW_HQ:
2028 case WID_C_BUILD_HQ:
2029 case WID_C_RELOCATE_HQ:
2030 case WID_C_VIEW_INFRASTRUCTURE:
2031 case WID_C_GIVE_MONEY:
2032 case WID_C_HOSTILE_TAKEOVER:
2033 case WID_C_COMPANY_JOIN:
2034 size.width = GetStringBoundingBox(STR_COMPANY_VIEW_VIEW_HQ_BUTTON).width;
2035 size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_BUILD_HQ_BUTTON).width);
2036 size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_RELOCATE_HQ).width);
2037 size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON).width);
2038 size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_GIVE_MONEY_BUTTON).width);
2039 size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_HOSTILE_TAKEOVER_BUTTON).width);
2040 size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_JOIN).width);
2041 size.width += padding.width;
2042 break;
2043 }
2044 }
2045
2046 void DrawVehicleCountsWidget(const Rect &r, const Company *c) const
2047 {
2048 static_assert(VEH_COMPANY_END == lengthof(_company_view_vehicle_count_strings));
2049
2050 int y = r.top;
2051 for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
2052 uint amount = c->group_all[type].num_vehicle;
2053 if (amount != 0) {
2054 DrawString(r.left, r.right, y, GetString(_company_view_vehicle_count_strings[type], amount));
2055 y += GetCharacterHeight(FS_NORMAL);
2056 }
2057 }
2058
2059 if (y == r.top) {
2060 /* No String was emitted before, so there must be no vehicles at all. */
2061 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
2062 }
2063 }
2064
2065 void DrawInfrastructureCountsWidget(const Rect &r, const Company *c) const
2066 {
2067 int y = r.top;
2068
2069 uint rail_pieces = c->infrastructure.signal + c->infrastructure.GetRailTotal();
2070 if (rail_pieces != 0) {
2071 DrawString(r.left, r.right, y, GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL, rail_pieces));
2072 y += GetCharacterHeight(FS_NORMAL);
2073 }
2074
2075 /* GetRoadTotal() skips tram pieces, but we actually want road and tram here. */
2076 uint road_pieces = std::accumulate(std::begin(c->infrastructure.road), std::end(c->infrastructure.road), 0U);
2077 if (road_pieces != 0) {
2078 DrawString(r.left, r.right, y, GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD, road_pieces));
2079 y += GetCharacterHeight(FS_NORMAL);
2080 }
2081
2082 if (c->infrastructure.water != 0) {
2083 DrawString(r.left, r.right, y, GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_WATER, c->infrastructure.water));
2084 y += GetCharacterHeight(FS_NORMAL);
2085 }
2086
2087 if (c->infrastructure.station != 0) {
2088 DrawString(r.left, r.right, y, GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_STATION, c->infrastructure.station));
2089 y += GetCharacterHeight(FS_NORMAL);
2090 }
2091
2092 if (c->infrastructure.airport != 0) {
2093 DrawString(r.left, r.right, y, GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT, c->infrastructure.airport));
2094 y += GetCharacterHeight(FS_NORMAL);
2095 }
2096
2097 if (y == r.top) {
2098 /* No String was emitted before, so there must be no infrastructure at all. */
2099 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
2100 }
2101 }
2102
2103 void DrawWidget(const Rect &r, WidgetID widget) const override
2104 {
2105 const Company *c = Company::Get(this->window_number);
2106 switch (widget) {
2107 case WID_C_FACE:
2108 DrawCompanyManagerFace(c->face, c->colour, r);
2109 break;
2110
2111 case WID_C_FACE_TITLE:
2112 DrawStringMultiLine(r, GetString(STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE, c->index), TC_FROMSTRING, SA_HOR_CENTER);
2113 break;
2114
2115 case WID_C_DESC_COLOUR_SCHEME_EXAMPLE: {
2116 Point offset;
2117 Dimension d = GetSpriteSize(SPR_VEH_BUS_SW_VIEW, &offset);
2118 d.height -= offset.y;
2119 DrawSprite(SPR_VEH_BUS_SW_VIEW, GetCompanyPalette(c->index), r.left - offset.x, CentreBounds(r.top, r.bottom, d.height) - offset.y);
2120 break;
2121 }
2122
2123 case WID_C_DESC_VEHICLE_COUNTS:
2124 DrawVehicleCountsWidget(r, c);
2125 break;
2126
2127 case WID_C_DESC_INFRASTRUCTURE_COUNTS:
2128 DrawInfrastructureCountsWidget(r, c);
2129 break;
2130 }
2131 }
2132
2133 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
2134 {
2135 switch (widget) {
2136 case WID_C_CAPTION:
2137 return GetString(STR_COMPANY_VIEW_CAPTION, this->window_number, this->window_number);
2138
2139 case WID_C_DESC_INAUGURATION: {
2140 const Company &c = *Company::Get(this->window_number);
2141 if (TimerGameEconomy::UsingWallclockUnits()) {
2142 return GetString(STR_COMPANY_VIEW_INAUGURATED_TITLE_WALLCLOCK, c.inaugurated_year_calendar, c.inaugurated_year);
2143 }
2144 return GetString(STR_COMPANY_VIEW_INAUGURATED_TITLE, c.inaugurated_year);
2145 }
2146
2147 case WID_C_DESC_COMPANY_VALUE:
2148 return GetString(STR_COMPANY_VIEW_COMPANY_VALUE, CalculateCompanyValue(Company::Get(this->window_number)));
2149
2150 default:
2151 return this->Window::GetWidgetString(widget, stringid);
2152 }
2153 }
2154
2155 void OnResize() override
2156 {
2157 NWidgetResizeBase *wid = this->GetWidget<NWidgetResizeBase>(WID_C_FACE_TITLE);
2158 int y = GetStringHeight(GetString(STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE, this->owner), wid->current_x);
2159 if (wid->UpdateVerticalSize(y)) this->ReInit(0, 0);
2160 }
2161
2162 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2163 {
2164 switch (widget) {
2165 case WID_C_NEW_FACE: DoSelectCompanyManagerFace(this); break;
2166
2167 case WID_C_COLOUR_SCHEME:
2168 ShowCompanyLiveryWindow(this->window_number, GroupID::Invalid());
2169 break;
2170
2171 case WID_C_PRESIDENT_NAME:
2172 this->query_widget = WID_C_PRESIDENT_NAME;
2173 ShowQueryString(GetString(STR_PRESIDENT_NAME, this->window_number), STR_COMPANY_VIEW_PRESIDENT_S_NAME_QUERY_CAPTION, MAX_LENGTH_PRESIDENT_NAME_CHARS, this, CS_ALPHANUMERAL, {QueryStringFlag::EnableDefault, QueryStringFlag::LengthIsInChars});
2174 break;
2175
2176 case WID_C_COMPANY_NAME:
2177 this->query_widget = WID_C_COMPANY_NAME;
2178 ShowQueryString(GetString(STR_COMPANY_NAME, this->window_number), STR_COMPANY_VIEW_COMPANY_NAME_QUERY_CAPTION, MAX_LENGTH_COMPANY_NAME_CHARS, this, CS_ALPHANUMERAL, {QueryStringFlag::EnableDefault, QueryStringFlag::LengthIsInChars});
2179 break;
2180
2181 case WID_C_VIEW_HQ: {
2182 TileIndex tile = Company::Get(this->window_number)->location_of_HQ;
2183 if (_ctrl_pressed) {
2184 ShowExtraViewportWindow(tile);
2185 } else {
2186 ScrollMainWindowToTile(tile);
2187 }
2188 break;
2189 }
2190
2191 case WID_C_BUILD_HQ:
2192 if (this->window_number != _local_company) return;
2193 if (this->IsWidgetLowered(WID_C_BUILD_HQ)) {
2194 ResetObjectToPlace();
2195 this->RaiseButtons();
2196 break;
2197 }
2198 SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, HT_RECT, this);
2199 SetTileSelectSize(2, 2);
2200 this->LowerWidget(WID_C_BUILD_HQ);
2201 this->SetWidgetDirty(WID_C_BUILD_HQ);
2202 break;
2203
2204 case WID_C_RELOCATE_HQ:
2205 if (this->IsWidgetLowered(WID_C_RELOCATE_HQ)) {
2206 ResetObjectToPlace();
2207 this->RaiseButtons();
2208 break;
2209 }
2210 SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, HT_RECT, this);
2211 SetTileSelectSize(2, 2);
2212 this->LowerWidget(WID_C_RELOCATE_HQ);
2213 this->SetWidgetDirty(WID_C_RELOCATE_HQ);
2214 break;
2215
2216 case WID_C_VIEW_INFRASTRUCTURE:
2217 ShowCompanyInfrastructure(this->window_number);
2218 break;
2219
2220 case WID_C_GIVE_MONEY:
2221 this->query_widget = WID_C_GIVE_MONEY;
2222 ShowQueryString({}, STR_COMPANY_VIEW_GIVE_MONEY_QUERY_CAPTION, 30, this, CS_NUMERAL, {});
2223 break;
2224
2225 case WID_C_HOSTILE_TAKEOVER:
2226 ShowBuyCompanyDialog(this->window_number, true);
2227 break;
2228
2229 case WID_C_COMPANY_JOIN: {
2230 this->query_widget = WID_C_COMPANY_JOIN;
2231 CompanyID company = this->window_number;
2232 if (_network_server) {
2233 NetworkServerDoMove(CLIENT_ID_SERVER, company);
2234 MarkWholeScreenDirty();
2235 } else {
2236 /* just send the join command */
2237 NetworkClientRequestMove(company);
2238 }
2239 break;
2240 }
2241 }
2242 }
2243
2245 const IntervalTimer<TimerWindow> redraw_interval = {std::chrono::seconds(3), [this](auto) {
2246 this->SetDirty();
2247 }};
2248
2249 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
2250 {
2251 if (Command<CMD_BUILD_OBJECT>::Post(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS, tile, OBJECT_HQ, 0) && !_shift_pressed) {
2252 ResetObjectToPlace();
2253 this->RaiseButtons();
2254 }
2255 }
2256
2257 void OnPlaceObjectAbort() override
2258 {
2259 this->RaiseButtons();
2260 }
2261
2262 void OnQueryTextFinished(std::optional<std::string> str) override
2263 {
2264 if (!str.has_value()) return;
2265
2266 switch (this->query_widget) {
2267 default: NOT_REACHED();
2268
2269 case WID_C_GIVE_MONEY: {
2270 auto value = ParseInteger<uint64_t>(*str, 10, true);
2271 if (!value.has_value()) return;
2272 Money money = *value / GetCurrency().rate;
2273 Command<CMD_GIVE_MONEY>::Post(STR_ERROR_CAN_T_GIVE_MONEY, money, this->window_number);
2274 break;
2275 }
2276
2277 case WID_C_PRESIDENT_NAME:
2278 Command<CMD_RENAME_PRESIDENT>::Post(STR_ERROR_CAN_T_CHANGE_PRESIDENT, *str);
2279 break;
2280
2281 case WID_C_COMPANY_NAME:
2282 Command<CMD_RENAME_COMPANY>::Post(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME, *str);
2283 break;
2284 }
2285 }
2286
2287 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2288 {
2289 if (gui_scope && data == 1) {
2290 /* Manually call OnResize to adjust minimum height of president name widget. */
2291 OnResize();
2292 }
2293 }
2294};
2295
2296static WindowDesc _company_desc(
2297 WDP_AUTO, "company", 0, 0,
2298 WC_COMPANY, WC_NONE,
2299 {},
2300 _nested_company_widgets
2301);
2302
2307 void ShowCompany(CompanyID company)
2308{
2309 if (!Company::IsValidID(company)) return;
2310
2311 AllocateWindowDescFront<CompanyWindow>(_company_desc, company);
2312}
2313
2318 void DirtyCompanyInfrastructureWindows(CompanyID company)
2319{
2320 SetWindowDirty(WC_COMPANY, company);
2321 SetWindowDirty(WC_COMPANY_INFRASTRUCTURE, company);
2322}
2323
2324 struct BuyCompanyWindow : Window {
2325 BuyCompanyWindow(WindowDesc &desc, WindowNumber window_number, bool hostile_takeover) : Window(desc), hostile_takeover(hostile_takeover)
2326 {
2327 this->InitNested(window_number);
2328
2329 const Company *c = Company::Get(this->window_number);
2330 this->company_value = hostile_takeover ? CalculateHostileTakeoverValue(c) : c->bankrupt_value;
2331 }
2332
2333 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
2334 {
2335 switch (widget) {
2336 case WID_BC_FACE:
2337 size = GetScaledSpriteSize(SPR_GRADIENT);
2338 break;
2339
2340 case WID_BC_QUESTION:
2341 const Company *c = Company::Get(this->window_number);
2342 size.height = GetStringHeight(GetString(this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, c->index, this->company_value), size.width);
2343 break;
2344 }
2345 }
2346
2347 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
2348 {
2349 switch (widget) {
2350 case WID_BC_CAPTION:
2351 return GetString(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY, Company::Get(this->window_number)->index);
2352
2353 default:
2354 return this->Window::GetWidgetString(widget, stringid);
2355 }
2356 }
2357
2358 void DrawWidget(const Rect &r, WidgetID widget) const override
2359 {
2360 switch (widget) {
2361 case WID_BC_FACE: {
2362 const Company *c = Company::Get(this->window_number);
2363 DrawCompanyManagerFace(c->face, c->colour, r);
2364 break;
2365 }
2366
2367 case WID_BC_QUESTION: {
2368 const Company *c = Company::Get(this->window_number);
2369 DrawStringMultiLine(r, GetString(this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, c->index, this->company_value), TC_FROMSTRING, SA_CENTER);
2370 break;
2371 }
2372 }
2373 }
2374
2375 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2376 {
2377 switch (widget) {
2378 case WID_BC_NO:
2379 this->Close();
2380 break;
2381
2382 case WID_BC_YES:
2383 Command<CMD_BUY_COMPANY>::Post(STR_ERROR_CAN_T_BUY_COMPANY, this->window_number, this->hostile_takeover);
2384 break;
2385 }
2386 }
2387
2391 const IntervalTimer<TimerWindow> rescale_interval = {std::chrono::seconds(3), [this](auto) {
2392 /* Value can't change when in bankruptcy. */
2393 if (!this->hostile_takeover) return;
2394
2395 const Company *c = Company::Get(this->window_number);
2396 auto new_value = CalculateHostileTakeoverValue(c);
2397 if (new_value != this->company_value) {
2398 this->company_value = new_value;
2399 this->ReInit();
2400 }
2401 }};
2402
2403private:
2404 bool hostile_takeover = false;
2405 Money company_value{};
2406};
2407
2408static constexpr std::initializer_list<NWidgetPart> _nested_buy_company_widgets = {
2409 NWidget(NWID_HORIZONTAL),
2410 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
2411 NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_BC_CAPTION),
2412 EndContainer(),
2413 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
2414 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
2415 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
2416 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BC_FACE), SetFill(0, 1),
2417 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BC_QUESTION), SetMinimalSize(240, 0), SetFill(1, 1),
2418 EndContainer(),
2419 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), SetPIP(100, WidgetDimensions::unscaled.hsep_wide, 100),
2420 NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_BC_NO), SetMinimalSize(60, 12), SetStringTip(STR_QUIT_NO), SetFill(1, 0),
2421 NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_BC_YES), SetMinimalSize(60, 12), SetStringTip(STR_QUIT_YES), SetFill(1, 0),
2422 EndContainer(),
2423 EndContainer(),
2424 EndContainer(),
2425};
2426
2427static WindowDesc _buy_company_desc(
2428 WDP_AUTO, {}, 0, 0,
2429 WC_BUY_COMPANY, WC_NONE,
2430 WindowDefaultFlag::Construction,
2431 _nested_buy_company_widgets
2432);
2433
2439 void ShowBuyCompanyDialog(CompanyID company, bool hostile_takeover)
2440{
2441 auto window = BringWindowToFrontById(WC_BUY_COMPANY, company);
2442 if (window == nullptr) {
2443 new BuyCompanyWindow(_buy_company_desc, company, hostile_takeover);
2444 }
2445}
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
ToggleBit
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Definition bitmath_func.hpp:157
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition bitmath_func.hpp:139
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
DropDownIcon
Drop down icon component.
Definition dropdown_common_type.h:113
DropDownListColourItem
Colour selection list item, with icon and string components.
Definition company_gui.cpp:592
DropDownListItem::masked
bool masked
Masked and unselectable item.
Definition dropdown_type.h:26
GUIList< GUIGroupListItem >
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition sortlist_type.h:405
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition sortlist_type.h:387
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition sortlist_type.h:395
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
NWidgetBase
Baseclass for nested widgets.
Definition widget_type.h:136
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition widget_type.h:237
NWidgetCore
Base class for a 'real' widget.
Definition widget_type.h:368
NWidgetCore::SetStringTip
void SetStringTip(StringID string, StringID tool_tip)
Set string and tool tip of the nested widget.
Definition widget.cpp:1164
NWidgetResizeBase
Base class for a resizable nested widget.
Definition widget_type.h:299
NWidgetResizeBase::UpdateVerticalSize
bool UpdateVerticalSize(uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition widget.cpp:1120
OverflowSafeInt< int64_t >
RailTypeInfo::name
StringID name
Name of this rail type.
Definition rail.h:165
RoadTypeInfo::name
StringID name
Name of this rail type.
Definition road.h:77
Scrollbar
Scrollbar data structure.
Definition widget_type.h:708
Scrollbar::GetCapacity
size_type GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition widget_type.h:743
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:792
Scrollbar::GetScrolledItemFromWidget
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition widget_type.h:891
Scrollbar::GetScrolledRowFromWidget
size_type GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition widget.cpp:2425
Scrollbar::SetPosition
bool SetPosition(size_type position)
Sets the position of the first visible element.
Definition widget_type.h:822
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2499
Scrollbar::GetCount
size_type GetCount() const
Gets the number of elements in the list.
Definition widget_type.h:734
Scrollbar::GetVisibleRangeIterators
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition widget_type.h:872
Scrollbar::GetPosition
size_type GetPosition() const
Gets the position of the first visible element in the list.
Definition widget_type.h:752
SelectCompanyManagerFaceWindow
Management class for customizing the face of the company manager.
Definition company_gui.cpp:1209
SelectCompanyManagerFaceWindow::SelectDisplayPlanes
void SelectDisplayPlanes(bool advanced)
Select planes to display to the user with the NWID_SELECTION widgets WID_SCMF_SEL_LOADSAVE,...
Definition company_gui.cpp:1264
SelectCompanyManagerFaceWindow::click_state
uint click_state
Click state on selected face variable.
Definition company_gui.cpp:1213
SelectCompanyManagerFaceWindow::UpdateWidgetSize
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.
Definition company_gui.cpp:1306
SelectCompanyManagerFaceWindow::face_vars
std::vector< const FaceVar * > face_vars
Visible face variables.
Definition company_gui.cpp:1216
SelectCompanyManagerFaceWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition company_gui.cpp:1481
SelectCompanyManagerFaceWindow::advanced
bool advanced
advanced company manager face selection window
Definition company_gui.cpp:1211
SelectCompanyManagerFaceWindow::selected_var
uint selected_var
Currently selected face variable. UINT_MAX for none, UINT_MAX - 1 means style is clicked instead.
Definition company_gui.cpp:1212
SelectCompanyManagerFaceWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition company_gui.cpp:1325
SelectCompanyManagerFaceWindow::face
CompanyManagerFace face
company manager face bits
Definition company_gui.cpp:1210
SelectCompanyManagerFaceWindow::line_height
int line_height
Height of each face variable row.
Definition company_gui.cpp:1214
SelectCompanyManagerFaceWindow::UpdateData
void UpdateData()
Make face bits valid and update visible face variables.
Definition company_gui.cpp:1221
SelectCompanyManagerFaceWindow::OnQueryTextFinished
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Definition company_gui.cpp:1502
SelectCompanyManagerFaceWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition company_gui.cpp:1374
SelectCompanyManagerFaceWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition company_gui.cpp:1495
SelectCompanyManagerFaceWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition company_gui.cpp:1255
TimerGameEconomy::year
static Year year
Current year, starting at 0.
Definition timer_game_economy.h:36
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition timer_game_economy.cpp:98
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:40
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition window_gui.h:41
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition window_gui.h:60
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition window_gui.h:62
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel thickness.
Definition window_gui.h:39
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
WidgetDimensions::matrix
RectPadding matrix
Padding of WWT_MATRIX items.
Definition window_gui.h:42
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:61
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition window_gui.h:38
WidgetDimensions::hsep_indent
int hsep_indent
Width of indentation for tree layouts.
Definition window_gui.h:63
command_func.h
Functions related to commands.
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
CalculateHostileTakeoverValue
Money CalculateHostileTakeoverValue(const Company *c)
Calculate what you have to pay to take over a company.
Definition economy.cpp:177
CalculateCompanyValue
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
Definition economy.cpp:150
ParseCompanyManagerFaceCode
std::optional< CompanyManagerFace > ParseCompanyManagerFaceCode(std::string_view str)
Parse a face code into a company manager face.
Definition company_cmd.cpp:1490
GetCompanyManagerFaceVars
FaceVars GetCompanyManagerFaceVars(uint style)
Get the face variables for a face style.
Definition company_cmd.cpp:1422
RandomiseCompanyManagerFace
void RandomiseCompanyManagerFace(CompanyManagerFace &cmf, Randomizer &randomizer)
Completely randomise a company manager face, including style.
Definition company_cmd.cpp:1450
_company_manager_face
std::string _company_manager_face
for company manager face storage in openttd.cfg
Definition company_cmd.cpp:58
GetCompanyPalette
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
Definition company_cmd.cpp:164
SetCompanyManagerFaceStyle
void SetCompanyManagerFaceStyle(CompanyManagerFace &cmf, uint style)
Set a company face style.
Definition company_cmd.cpp:1435
GetNumCompanyManagerFaceStyles
uint GetNumCompanyManagerFaceStyles()
Get the number of company manager face styles.
Definition company_cmd.cpp:1388
FormatCompanyManagerFaceCode
std::string FormatCompanyManagerFaceCode(const CompanyManagerFace &cmf)
Get a face code representation of a company manager face.
Definition company_cmd.cpp:1479
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:55
company_cmd.h
Command definitions related to companies.
company_func.h
Functions related to companies.
ShowCompanyFinances
void ShowCompanyFinances(CompanyID company)
Open the finances window of a company.
Definition company_gui.cpp:569
DrawYearCategory
static Money DrawYearCategory(const Rect &r, int start_y, const ExpensesList &list, const Expenses &tbl)
Draw a category of expenses/revenues in the year column.
Definition company_gui.cpp:237
GetMaxCategoriesWidth
static uint GetMaxCategoriesWidth()
Get the required width of the "categories" column, equal to the widest element.
Definition company_gui.cpp:146
_select_company_manager_face_desc
static WindowDesc _select_company_manager_face_desc(WDP_AUTO, {}, 0, 0, WC_COMPANY_MANAGER_FACE, WC_NONE, WindowDefaultFlag::Construction, _nested_select_company_manager_face_widgets)
Company manager face selection window description.
DrawYearColumn
static void DrawYearColumn(const Rect &r, TimerGameEconomy::Year year, const Expenses &tbl)
Draw a column with prices.
Definition company_gui.cpp:266
_expenses_list_capital_costs
static const std::initializer_list< ExpensesType > _expenses_list_capital_costs
List of capital expenses.
Definition company_gui.cpp:83
ShowBuyCompanyDialog
void ShowBuyCompanyDialog(CompanyID company, bool hostile_takeover)
Show the query to buy another company.
Definition company_gui.cpp:2439
_company_view_vehicle_count_strings
static const StringID _company_view_vehicle_count_strings[]
Strings for the company vehicle counts.
Definition company_gui.cpp:1920
_expenses_list_types
static const std::initializer_list< ExpensesList > _expenses_list_types
Types of expense lists.
Definition company_gui.cpp:116
DrawPrice
static void DrawPrice(Money amount, int left, int right, int top, TextColour colour)
Draw an amount of money.
Definition company_gui.cpp:221
ShowCompanyInfrastructure
static void ShowCompanyInfrastructure(CompanyID company)
Open the infrastructure window of a company.
Definition company_gui.cpp:1837
DrawCategories
static void DrawCategories(const Rect &r)
Draw the expenses categories.
Definition company_gui.cpp:181
DoSelectCompanyManagerFace
static void DoSelectCompanyManagerFace(Window *parent)
Company GUI constants.
Definition company_gui.cpp:1531
ShowCompany
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
Definition company_gui.cpp:2307
_expenses_list_operating_costs
static const std::initializer_list< ExpensesType > _expenses_list_operating_costs
List of operating expenses.
Definition company_gui.cpp:73
GetTotalCategoriesHeight
static uint GetTotalCategoriesHeight()
Get the total height of the "categories" column.
Definition company_gui.cpp:126
_nested_select_company_manager_face_widgets
static constexpr std::initializer_list< NWidgetPart > _nested_select_company_manager_face_widgets
Nested widget description for the company manager face selection dialog.
Definition company_gui.cpp:1164
_expenses_list_revenue
static const std::initializer_list< ExpensesType > _expenses_list_revenue
List of revenues.
Definition company_gui.cpp:65
DirtyCompanyInfrastructureWindows
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Definition company_gui.cpp:2318
DrawCompanyManagerFace
void DrawCompanyManagerFace(const CompanyManagerFace &cmf, Colours colour, const Rect &r)
Draws the face of a company manager's face.
Definition company_gui.cpp:1120
DrawCategory
static void DrawCategory(const Rect &r, int start_y, const ExpensesList &list)
Draw a category of expenses (revenue, operating expenses, capital expenses).
Definition company_gui.cpp:164
company_manager_face.h
Functionality related to the company manager's face.
GetActiveFaceVars
uint64_t GetActiveFaceVars(const CompanyManagerFace &cmf, FaceVars vars)
Get a bitmask of currently active face variables.
Definition company_manager_face.h:140
ScaleAllCompanyManagerFaceBits
void ScaleAllCompanyManagerFaceBits(CompanyManagerFace &cmf, FaceVars vars)
Scales all company manager's face bits to the correct scope.
Definition company_manager_face.h:158
MAX_LENGTH_PRESIDENT_NAME_CHARS
static const uint MAX_LENGTH_PRESIDENT_NAME_CHARS
The maximum length of a president name in characters including '\0'.
Definition company_type.h:33
MAX_LENGTH_COMPANY_NAME_CHARS
static const uint MAX_LENGTH_COMPANY_NAME_CHARS
The maximum length of a company name in characters including '\0'.
Definition company_type.h:34
COMPANY_SPECTATOR
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
Definition company_type.h:21
company_widget.h
Types related to the company widgets.
WID_CF_CAPTION
@ WID_CF_CAPTION
Caption of the window.
Definition company_widget.h:56
WID_CF_SEL_BUTTONS
@ WID_CF_SEL_BUTTONS
Selection of buttons.
Definition company_widget.h:71
WID_CF_SEL_PANEL
@ WID_CF_SEL_PANEL
Select panel or nothing.
Definition company_widget.h:58
WID_CF_EXPS_CATEGORY
@ WID_CF_EXPS_CATEGORY
Column for expenses category strings.
Definition company_widget.h:59
WID_CF_EXPS_PRICE1
@ WID_CF_EXPS_PRICE1
Column for year Y-2 expenses.
Definition company_widget.h:60
WID_CF_INFRASTRUCTURE
@ WID_CF_INFRASTRUCTURE
View company infrastructure.
Definition company_widget.h:74
WID_CF_TOGGLE_SIZE
@ WID_CF_TOGGLE_SIZE
Toggle windows size.
Definition company_widget.h:57
WID_CF_EXPS_PRICE2
@ WID_CF_EXPS_PRICE2
Column for year Y-1 expenses.
Definition company_widget.h:61
WID_CF_OWN_VALUE
@ WID_CF_OWN_VALUE
Own funds, not including loan.
Definition company_widget.h:68
WID_CF_LOAN_VALUE
@ WID_CF_LOAN_VALUE
Loan.
Definition company_widget.h:66
WID_CF_INCREASE_LOAN
@ WID_CF_INCREASE_LOAN
Increase loan.
Definition company_widget.h:72
WID_CF_INTEREST_RATE
@ WID_CF_INTEREST_RATE
Loan interest rate.
Definition company_widget.h:69
WID_CF_BALANCE_VALUE
@ WID_CF_BALANCE_VALUE
Bank balance value.
Definition company_widget.h:65
WID_CF_EXPS_PRICE3
@ WID_CF_EXPS_PRICE3
Column for year Y expenses.
Definition company_widget.h:62
WID_CF_BALANCE_LINE
@ WID_CF_BALANCE_LINE
Available cash.
Definition company_widget.h:67
WID_CF_REPAY_LOAN
@ WID_CF_REPAY_LOAN
Decrease loan..
Definition company_widget.h:73
WID_CF_SEL_MAXLOAN
@ WID_CF_SEL_MAXLOAN
Selection of maxloan column.
Definition company_widget.h:64
WID_CF_MAXLOAN_VALUE
@ WID_CF_MAXLOAN_VALUE
Max loan widget.
Definition company_widget.h:70
WID_BC_NO
@ WID_BC_NO
No button.
Definition company_widget.h:134
WID_BC_YES
@ WID_BC_YES
Yes button.
Definition company_widget.h:135
WID_BC_QUESTION
@ WID_BC_QUESTION
Question text.
Definition company_widget.h:133
WID_BC_CAPTION
@ WID_BC_CAPTION
Caption of window.
Definition company_widget.h:131
WID_BC_FACE
@ WID_BC_FACE
Face button.
Definition company_widget.h:132
WID_SCMF_CAPTION
@ WID_SCMF_CAPTION
Caption of window.
Definition company_widget.h:103
WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
@ WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
Toggle for large or small.
Definition company_widget.h:112
WID_SCMF_STYLE
@ WID_SCMF_STYLE
Style selector widget.
Definition company_widget.h:117
WID_SCMF_SEL_RESIZE
@ WID_SCMF_SEL_RESIZE
Selection to display the resize button.
Definition company_widget.h:110
WID_SCMF_SELECT_FACE
@ WID_SCMF_SELECT_FACE
Select face.
Definition company_widget.h:105
WID_SCMF_RANDOM_NEW_FACE
@ WID_SCMF_RANDOM_NEW_FACE
Create random new face.
Definition company_widget.h:111
WID_SCMF_SEL_PARTS
@ WID_SCMF_SEL_PARTS
Selection to display the buttons for setting each part of the face in the advanced view.
Definition company_widget.h:109
WID_SCMF_PARTS_SCROLLBAR
@ WID_SCMF_PARTS_SCROLLBAR
Scrollbar for configuration parts widget.
Definition company_widget.h:119
WID_SCMF_CANCEL
@ WID_SCMF_CANCEL
Cancel.
Definition company_widget.h:106
WID_SCMF_SAVE
@ WID_SCMF_SAVE
Save face.
Definition company_widget.h:116
WID_SCMF_SEL_LOADSAVE
@ WID_SCMF_SEL_LOADSAVE
Selection to display the load/save/number buttons in the advanced view.
Definition company_widget.h:108
WID_SCMF_FACE
@ WID_SCMF_FACE
Current face.
Definition company_widget.h:113
WID_SCMF_LOAD
@ WID_SCMF_LOAD
Load face.
Definition company_widget.h:114
WID_SCMF_ACCEPT
@ WID_SCMF_ACCEPT
Accept.
Definition company_widget.h:107
WID_SCMF_TOGGLE_LARGE_SMALL
@ WID_SCMF_TOGGLE_LARGE_SMALL
Toggle for large or small.
Definition company_widget.h:104
WID_SCMF_FACECODE
@ WID_SCMF_FACECODE
Get the face code.
Definition company_widget.h:115
WID_SCMF_PARTS
@ WID_SCMF_PARTS
Face configuration parts widget.
Definition company_widget.h:118
WID_SCL_CLASS_AIRCRAFT
@ WID_SCL_CLASS_AIRCRAFT
Class aircraft.
Definition company_widget.h:85
WID_SCL_MATRIX_SCROLLBAR
@ WID_SCL_MATRIX_SCROLLBAR
Matrix scrollbar.
Definition company_widget.h:95
WID_SCL_CLASS_SHIP
@ WID_SCL_CLASS_SHIP
Class ship.
Definition company_widget.h:84
WID_SCL_SEC_COL_DROP_SEL
@ WID_SCL_SEC_COL_DROP_SEL
Container for secondary color dropdown, which can be hidden.
Definition company_widget.h:93
WID_SCL_GROUPS_SHIP
@ WID_SCL_GROUPS_SHIP
Ship groups.
Definition company_widget.h:88
WID_SCL_GROUPS_ROAD
@ WID_SCL_GROUPS_ROAD
Road groups.
Definition company_widget.h:87
WID_SCL_CLASS_ROAD
@ WID_SCL_CLASS_ROAD
Class road.
Definition company_widget.h:83
WID_SCL_GROUPS_AIRCRAFT
@ WID_SCL_GROUPS_AIRCRAFT
Aircraft groups.
Definition company_widget.h:89
WID_SCL_SEC_COL_DROPDOWN
@ WID_SCL_SEC_COL_DROPDOWN
Dropdown for secondary colour.
Definition company_widget.h:92
WID_SCL_SPACER_DROPDOWN
@ WID_SCL_SPACER_DROPDOWN
Spacer for dropdown.
Definition company_widget.h:90
WID_SCL_GROUPS_RAIL
@ WID_SCL_GROUPS_RAIL
Rail groups.
Definition company_widget.h:86
WID_SCL_PRI_COL_DROPDOWN
@ WID_SCL_PRI_COL_DROPDOWN
Dropdown for primary colour.
Definition company_widget.h:91
WID_SCL_CLASS_RAIL
@ WID_SCL_CLASS_RAIL
Class rail.
Definition company_widget.h:82
WID_SCL_MATRIX
@ WID_SCL_MATRIX
Matrix.
Definition company_widget.h:94
WID_SCL_CAPTION
@ WID_SCL_CAPTION
Caption of window.
Definition company_widget.h:80
WID_SCL_CLASS_GENERAL
@ WID_SCL_CLASS_GENERAL
Class general.
Definition company_widget.h:81
WID_CI_SCROLLBAR
@ WID_CI_SCROLLBAR
Infrastructure list scrollbar.
Definition company_widget.h:126
WID_CI_CAPTION
@ WID_CI_CAPTION
Caption of window.
Definition company_widget.h:124
WID_CI_LIST
@ WID_CI_LIST
Infrastructure list.
Definition company_widget.h:125
CompanyWidgets
CompanyWidgets
Widgets of the CompanyWindow class.
Definition company_widget.h:14
WID_C_SELECT_VIEW_BUILD_HQ
@ WID_C_SELECT_VIEW_BUILD_HQ
Panel about HQ.
Definition company_widget.h:35
WID_C_DESC_INFRASTRUCTURE_COUNTS
@ WID_C_DESC_INFRASTRUCTURE_COUNTS
Infrastructure count.
Definition company_widget.h:27
WID_C_DESC_VEHICLE
@ WID_C_DESC_VEHICLE
Vehicles.
Definition company_widget.h:23
WID_C_COLOUR_SCHEME
@ WID_C_COLOUR_SCHEME
Button to change colour scheme.
Definition company_widget.h:31
WID_C_CAPTION
@ WID_C_CAPTION
Caption of the window.
Definition company_widget.h:15
WID_C_VIEW_HQ
@ WID_C_VIEW_HQ
Button to view the HQ.
Definition company_widget.h:36
WID_C_SELECT_RELOCATE
@ WID_C_SELECT_RELOCATE
Panel about 'Relocate HQ'.
Definition company_widget.h:39
WID_C_SELECT_BUTTONS
@ WID_C_SELECT_BUTTONS
Selection widget for the button bar.
Definition company_widget.h:29
WID_C_VIEW_INFRASTRUCTURE
@ WID_C_VIEW_INFRASTRUCTURE
Panel about infrastructure.
Definition company_widget.h:42
WID_C_SELECT_HOSTILE_TAKEOVER
@ WID_C_SELECT_HOSTILE_TAKEOVER
Selection widget for the hostile takeover button.
Definition company_widget.h:47
WID_C_SELECT_GIVE_MONEY
@ WID_C_SELECT_GIVE_MONEY
Selection widget for the give money button.
Definition company_widget.h:44
WID_C_DESC_COLOUR_SCHEME
@ WID_C_DESC_COLOUR_SCHEME
Colour scheme.
Definition company_widget.h:21
WID_C_GIVE_MONEY
@ WID_C_GIVE_MONEY
Button to give money.
Definition company_widget.h:45
WID_C_SELECT_MULTIPLAYER
@ WID_C_SELECT_MULTIPLAYER
Multiplayer selection panel.
Definition company_widget.h:50
WID_C_DESC_INAUGURATION
@ WID_C_DESC_INAUGURATION
Inauguration.
Definition company_widget.h:20
WID_C_DESC_COLOUR_SCHEME_EXAMPLE
@ WID_C_DESC_COLOUR_SCHEME_EXAMPLE
Colour scheme example.
Definition company_widget.h:22
WID_C_BUILD_HQ
@ WID_C_BUILD_HQ
Button to build the HQ.
Definition company_widget.h:37
WID_C_HOSTILE_TAKEOVER
@ WID_C_HOSTILE_TAKEOVER
Button to hostile takeover another company.
Definition company_widget.h:48
WID_C_DESC_INFRASTRUCTURE
@ WID_C_DESC_INFRASTRUCTURE
Infrastructure.
Definition company_widget.h:26
WID_C_FACE_TITLE
@ WID_C_FACE_TITLE
Title for the face.
Definition company_widget.h:18
WID_C_DESC_COMPANY_VALUE
@ WID_C_DESC_COMPANY_VALUE
Company value.
Definition company_widget.h:25
WID_C_COMPANY_JOIN
@ WID_C_COMPANY_JOIN
Button to join company.
Definition company_widget.h:51
WID_C_PRESIDENT_NAME
@ WID_C_PRESIDENT_NAME
Button to change president name.
Definition company_widget.h:32
WID_C_DESC_VEHICLE_COUNTS
@ WID_C_DESC_VEHICLE_COUNTS
Vehicle count.
Definition company_widget.h:24
WID_C_NEW_FACE
@ WID_C_NEW_FACE
Button to make new face.
Definition company_widget.h:30
WID_C_FACE
@ WID_C_FACE
View of the face.
Definition company_widget.h:17
WID_C_RELOCATE_HQ
@ WID_C_RELOCATE_HQ
Button to relocate the HQ.
Definition company_widget.h:40
WID_C_COMPANY_NAME
@ WID_C_COMPANY_NAME
Button to change company name.
Definition company_widget.h:33
currency.h
Functions to handle different currencies.
GetCurrency
const CurrencySpec & GetCurrency()
Get the currently selected currency.
Definition currency.h:119
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options)
Show a drop down list.
Definition dropdown.cpp:418
dropdown_common_type.h
Common drop down list components.
dropdown_type.h
Types related to the drop down widget.
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition dropdown_type.h:56
economy_cmd.h
Command definitions related to the economy.
Expenses
std::array< Money, EXPENSES_END > Expenses
Data type for storage of Money for each ExpensesType category.
Definition economy_type.h:199
ExpensesType
ExpensesType
Types of expenses.
Definition economy_type.h:178
EXPENSES_ROADVEH_RUN
@ EXPENSES_ROADVEH_RUN
Running costs road vehicles.
Definition economy_type.h:182
EXPENSES_TRAIN_RUN
@ EXPENSES_TRAIN_RUN
Running costs trains.
Definition economy_type.h:181
EXPENSES_AIRCRAFT_REVENUE
@ EXPENSES_AIRCRAFT_REVENUE
Revenue from aircraft.
Definition economy_type.h:188
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition economy_type.h:179
EXPENSES_AIRCRAFT_RUN
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
Definition economy_type.h:183
EXPENSES_ROADVEH_REVENUE
@ EXPENSES_ROADVEH_REVENUE
Revenue from road vehicles.
Definition economy_type.h:187
EXPENSES_PROPERTY
@ EXPENSES_PROPERTY
Property costs.
Definition economy_type.h:185
EXPENSES_OTHER
@ EXPENSES_OTHER
Other expenses.
Definition economy_type.h:191
EXPENSES_SHIP_REVENUE
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
Definition economy_type.h:189
EXPENSES_LOAN_INTEREST
@ EXPENSES_LOAN_INTEREST
Interest payments over the loan.
Definition economy_type.h:190
EXPENSES_TRAIN_REVENUE
@ EXPENSES_TRAIN_REVENUE
Revenue from trains.
Definition economy_type.h:186
EXPENSES_SHIP_RUN
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition economy_type.h:184
EXPENSES_NEW_VEHICLES
@ EXPENSES_NEW_VEHICLES
New vehicles.
Definition economy_type.h:180
LOAN_INTERVAL
static const int LOAN_INTERVAL
The "steps" in loan size, in British Pounds!
Definition economy_type.h:211
engine_base.h
Base class for engines.
error.h
Functions related to errors.
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition error.h:24
ShowErrorMessage
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Definition error_gui.cpp:290
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
geometry_func.hpp
Geometry functions.
CentreBounds
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Definition geometry_type.hpp:26
GetStringHeight
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:712
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:965
_shift_pressed
bool _shift_pressed
Is Shift pressed?
Definition gfx.cpp:39
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
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:665
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
GetStringListWidth
uint GetStringListWidth(std::span< const StringID > list, FontSize fontsize)
Get maximum width of a list of strings.
Definition gfx.cpp:917
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition gfx.cpp:1031
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:782
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:115
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition widget.cpp:68
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
SA_TOP
@ SA_TOP
Top align the text.
Definition gfx_type.h:393
SA_LEFT
@ SA_LEFT
Left align the text.
Definition gfx_type.h:388
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:390
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:389
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition gfx_type.h:400
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition gfx_type.h:394
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition widget_type.h:1308
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
SetSpriteTip
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
Definition widget_type.h:1251
SetToolbarMinimalSize
constexpr NWidgetPart SetToolbarMinimalSize(int width)
Widget part function to setting the minimal size for a toolbar button.
Definition widget_type.h:1175
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1375
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1399
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition widget_type.h:1332
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1240
SetAspect
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
Definition widget_type.h:1410
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1156
SetToolTip
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
Definition widget_type.h:1318
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
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:1187
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition widget_type.h:1208
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1145
SetPIPRatio
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
Definition widget_type.h:1387
group_cmd.h
Command definitions related to engine groups.
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:966
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1546
BuildGuiGroupList
void BuildGuiGroupList(GUIGroupList &list, bool fold, Owner owner, VehicleType veh_type)
Build GUI group list, a sorted hierarchical list of groups for owner and vehicle type.
Definition group_gui.cpp:167
group_gui.h
Functions/definitions that have something to do with groups.
gui.h
GUI functions that shouldn't be here.
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition viewport_gui.cpp:159
LIT_ALL
static const uint8_t LIT_ALL
Show the liveries of all companies.
Definition livery.h:19
LiveryScheme
LiveryScheme
List of different livery schemes.
Definition livery.h:22
LIT_COMPANY
static const uint8_t LIT_COMPANY
Show the liveries of your own company.
Definition livery.h:18
LiveryClass
LiveryClass
List of different livery classes, used only by the livery GUI.
Definition livery.h:64
IsInsideBS
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition math_func.hpp:252
misc_cmd.h
Miscellaneous command definitions.
ShowQueryString
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition misc_gui.cpp:1062
_networking
bool _networking
are we in networking mode?
Definition network.cpp:66
_network_server
bool _network_server
network-server is active
Definition network.cpp:67
NetworkCanJoinCompany
bool NetworkCanJoinCompany(CompanyID company_id)
Returns whether the given company can be joined by this client.
Definition network.cpp:142
network.h
Basic functions/variables used all over the place.
NetworkClientRequestMove
void NetworkClientRequestMove(CompanyID company_id)
Notify the server of this client wanting to be moved to another company.
Definition network_client.cpp:1214
network_func.h
Network functions used by other parts of OpenTTD.
NetworkServerDoMove
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
Definition network_server.cpp:1976
network_gui.h
GUIs related to networking.
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition network_type.h:45
_loaded_newgrf_features
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
Definition newgrf.cpp:74
newgrf.h
Base for the NewGRF implementation.
object_cmd.h
Command definitions related to objects.
object_type.h
Types related to object tiles.
OBJECT_HQ
static const ObjectType OBJECT_HQ
HeadQuarter of a player.
Definition object_type.h:22
PC_BLACK
static constexpr PixelColour PC_BLACK
Black palette colour.
Definition palette_func.h:96
PC_WHITE
static constexpr PixelColour PC_WHITE
White palette colour.
Definition palette_func.h:99
rail.h
Rail specific functions.
_sorted_railtypes
std::vector< RailType > _sorted_railtypes
Sorted list of rail types.
Definition rail_cmd.cpp:47
RailMaintenanceCost
Money RailMaintenanceCost(RailType railtype, uint32_t num, uint32_t total_num)
Calculates the maintenance cost of a number of track bits.
Definition rail.h:483
SignalMaintenanceCost
Money SignalMaintenanceCost(uint32_t num)
Calculates the maintenance cost of a number of signals.
Definition rail.h:494
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:300
RailType
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
_interactive_random
Randomizer _interactive_random
Random used everywhere else, where it does not (directly) influence the game state.
Definition random_func.cpp:36
road.h
Road specific functions.
GetRoadTypeInfo
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:215
_sorted_roadtypes
std::vector< RoadType > _sorted_roadtypes
Sorted list of road types.
Definition road_cmd.cpp:55
road_func.h
Functions related to roads.
RoadMaintenanceCost
Money RoadMaintenanceCost(RoadType roadtype, uint32_t num, uint32_t total_num)
Calculates the maintenance cost of a number of road bits.
Definition road_func.h:125
RoadType
RoadType
The different roadtypes we support.
Definition road_type.h:23
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition settings_gui.cpp:1866
DrawBoolButton
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
Draw a toggle button.
Definition settings_gui.cpp:1947
settings_gui.h
Functions for setting GUIs.
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition settings_gui.h:17
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition settings_gui.h:19
sortlist_type.h
Base types for having sorted lists in GUIs.
GetColourPalette
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Definition sprite.h:188
AirportMaintenanceCost
Money AirportMaintenanceCost(Owner owner)
Calculates the maintenance cost of all airports of a company.
Definition station.cpp:713
station_func.h
Functions related to stations.
StationMaintenanceCost
Money StationMaintenanceCost(uint32_t num)
Calculates the maintenance cost of a number of station tiles.
Definition station_func.h:60
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:271
string_consumer.hpp
Parse strings.
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition string_type.h:26
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition string_type.h:25
GetParamMaxValue
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
Get some number that is suitable for string size computations.
Definition strings.cpp:236
GetEncodedString
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
strings_func.h
Functions related to OTTD's strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:27
BuyCompanyWindow
Definition company_gui.cpp:2324
BuyCompanyWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition company_gui.cpp:2358
BuyCompanyWindow::company_value
Money company_value
The value of the company for which the user can buy it.
Definition company_gui.cpp:2405
BuyCompanyWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition company_gui.cpp:2347
BuyCompanyWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition company_gui.cpp:2375
BuyCompanyWindow::UpdateWidgetSize
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.
Definition company_gui.cpp:2333
BuyCompanyWindow::hostile_takeover
bool hostile_takeover
Whether the window is showing a hostile takeover.
Definition company_gui.cpp:2404
BuyCompanyWindow::rescale_interval
const IntervalTimer< TimerWindow > rescale_interval
Check on a regular interval if the company value has changed.
Definition company_gui.cpp:2391
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:650
CommandHelper
Definition command_func.h:83
CompanyFinancesWindow
Window class displaying the company finances.
Definition company_gui.cpp:338
CompanyFinancesWindow::rescale_interval
const IntervalTimer< TimerWindow > rescale_interval
Check on a regular interval if the maximum amount of money has changed.
Definition company_gui.cpp:544
CompanyFinancesWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition company_gui.cpp:424
CompanyFinancesWindow::UpdateWidgetSize
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.
Definition company_gui.cpp:395
CompanyFinancesWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition company_gui.cpp:493
CompanyFinancesWindow::OnInvalidateData
void OnInvalidateData(int, bool) override
Some data on this window has become invalid.
Definition company_gui.cpp:535
CompanyFinancesWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition company_gui.cpp:355
CompanyFinancesWindow::small
bool small
Window is toggled to 'small'.
Definition company_gui.cpp:342
CompanyFinancesWindow::max_money
static Money max_money
The maximum amount of money a company has had this 'run'.
Definition company_gui.cpp:341
CompanyFinancesWindow::first_visible
uint8_t first_visible
First visible expenses column. The last column (current) is always visible.
Definition company_gui.cpp:343
CompanyFinancesWindow::SetupWidgets
void SetupWidgets()
Setup the widgets in the nested tree, such that the finances window is displayed properly.
Definition company_gui.cpp:453
CompanyFinancesWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition company_gui.cpp:464
CompanyInfrastructureWindow::InfrastructureItem
Definition company_gui.cpp:1570
CompanyInfrastructureWindow
Window with detailed information about the company's infrastructure.
Definition company_gui.cpp:1562
CompanyInfrastructureWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition company_gui.cpp:1588
CompanyInfrastructureWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition company_gui.cpp:1818
CompanyInfrastructureWindow::UpdateWidgetSize
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.
Definition company_gui.cpp:1709
CompanyInfrastructureWindow::InfrastructureItemType
InfrastructureItemType
Definition company_gui.cpp:1563
CompanyInfrastructureWindow::InfrastructureItemType::Value
@ Value
Label with values.
CompanyInfrastructureWindow::InfrastructureItemType::Spacer
@ Spacer
Spacer.
CompanyInfrastructureWindow::InfrastructureItemType::Total
@ Total
Total cost.
CompanyInfrastructureWindow::InfrastructureItemType::Header
@ Header
Section header.
CompanyInfrastructureWindow::FindWindowPlacementAndResize
void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize) override
Resize window towards the default size.
Definition company_gui.cpp:1697
CompanyInfrastructureWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition company_gui.cpp:1759
CompanyInfrastructureWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition company_gui.cpp:1686
CompanyInfrastructureWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition company_gui.cpp:1808
CompanyInfrastructure::road
std::array< uint32_t, ROADTYPE_END > road
Count of company owned track bits for each road type.
Definition company_base.h:34
CompanyInfrastructure::GetRailTotal
uint32_t GetRailTotal() const
Get total sum of all owned track bits.
Definition company_base.h:43
CompanyInfrastructure::station
uint32_t station
Count of company owned station tiles.
Definition company_base.h:37
CompanyInfrastructure::signal
uint32_t signal
Count of company owned signals.
Definition company_base.h:35
CompanyInfrastructure::rail
std::array< uint32_t, RAILTYPE_END > rail
Count of company owned track bits for each rail type.
Definition company_base.h:33
CompanyInfrastructure::airport
uint32_t airport
Count of company owned airports.
Definition company_base.h:38
CompanyInfrastructure::water
uint32_t water
Count of company owned track bits for canals.
Definition company_base.h:36
CompanyManagerFace
Definition company_type.h:53
CompanyManagerFace::style
uint style
Company manager face style.
Definition company_type.h:54
CompanyProperties::location_of_HQ
TileIndex location_of_HQ
Northern tile of HQ; INVALID_TILE when there is none.
Definition company_base.h:93
CompanyProperties::is_ai
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition company_base.h:114
CompanyProperties::current_loan
Money current_loan
Amount of money borrowed from the bank.
Definition company_base.h:86
CompanyProperties::inaugurated_year_calendar
TimerGameCalendar::Year inaugurated_year_calendar
Calendar year of starting the company. Used to display proper Inauguration year while in wallclock mo...
Definition company_base.h:97
CompanyProperties::inaugurated_year
TimerGameEconomy::Year inaugurated_year
Economy year of starting the company.
Definition company_base.h:96
CompanyProperties::colour
Colours colour
Company colour.
Definition company_base.h:89
CompanyProperties::face
CompanyManagerFace face
Face description of the president.
Definition company_base.h:82
CompanyProperties::yearly_expenses
std::array< Expenses, 3 > yearly_expenses
Expenses of the company for the last three years.
Definition company_base.h:116
CompanyProperties::money
Money money
Money owned by the company.
Definition company_base.h:84
CompanyWindow
Window with general information about a company.
Definition company_gui.cpp:1928
CompanyWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition company_gui.cpp:2155
CompanyWindow::redraw_interval
const IntervalTimer< TimerWindow > redraw_interval
Redraw the window on a regular interval.
Definition company_gui.cpp:2245
CompanyWindow::UpdateWidgetSize
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.
Definition company_gui.cpp:1986
CompanyWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition company_gui.cpp:2162
CompanyWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition company_gui.cpp:2257
CompanyWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition company_gui.cpp:2133
CompanyWindow::OnPlaceObject
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition company_gui.cpp:2249
CompanyWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition company_gui.cpp:2103
CompanyWindow::OnQueryTextFinished
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Definition company_gui.cpp:2262
CompanyWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition company_gui.cpp:2287
CompanyWindow::CompanyWindowPlanes
CompanyWindowPlanes
Display planes in the company window.
Definition company_gui.cpp:1932
CompanyWindow::CWP_RELOCATE_SHOW
@ CWP_RELOCATE_SHOW
Show the relocate HQ button.
Definition company_gui.cpp:1938
CompanyWindow::CWP_RELOCATE_HIDE
@ CWP_RELOCATE_HIDE
Hide the relocate HQ button.
Definition company_gui.cpp:1939
CompanyWindow::CWP_VB_BUILD
@ CWP_VB_BUILD
Display the build button.
Definition company_gui.cpp:1935
CompanyWindow::CWP_VB_VIEW
@ CWP_VB_VIEW
Display the view button.
Definition company_gui.cpp:1934
CompanyWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition company_gui.cpp:1949
Company
Definition company_base.h:127
Company::GetMaxLoan
Money GetMaxLoan() const
Calculate the max allowed loan for this company.
Definition company_cmd.cpp:107
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition company_base.h:141
Company::group_all
std::array< GroupStatistics, VEH_COMPANY_END > group_all
NOSAVE: Statistics for the ALL_GROUP group.
Definition company_base.h:138
Coord2D< int >
Coord2D::y
T y
Y coordinate.
Definition geometry_type.hpp:35
Coord2D::x
T x
X coordinate.
Definition geometry_type.hpp:34
CurrencySpec::rate
uint16_t rate
The conversion rate compared to the base currency.
Definition currency.h:78
DifficultySettings::initial_interest
uint8_t initial_interest
amount of interest (to pay over the loan)
Definition settings_type.h:130
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
EconomySettings::infrastructure_maintenance
bool infrastructure_maintenance
enable monthly maintenance fee for owner infrastructure
Definition settings_type.h:563
EconomySettings::give_money
bool give_money
allow giving other companies money
Definition settings_type.h:549
ExpensesList
Expense list container.
Definition company_gui.cpp:90
ExpensesList::GetListWidth
uint GetListWidth() const
Compute width of the expenses categories in pixels.
Definition company_gui.cpp:105
ExpensesList::items
const std::initializer_list< ExpensesType > & items
List of expenses types.
Definition company_gui.cpp:92
ExpensesList::title
const StringID title
StringID of list title.
Definition company_gui.cpp:91
FaceVar
Information about the valid values of CompanyManagerFace bitgroups as well as the sprites to draw.
Definition company_manager_face.h:28
FaceVar::position
uint8_t position
Position in UI.
Definition company_manager_face.h:30
FaceVar::valid_values
uint8_t valid_values
The number of valid values.
Definition company_manager_face.h:33
GRFLoadedFeatures::has_2CC
bool has_2CC
Set if any vehicle is loaded which uses 2cc (two company colours).
Definition newgrf.h:188
GRFLoadedFeatures::used_liveries
uint64_t used_liveries
Bitmask of LiveryScheme used by the defined engines.
Definition newgrf.h:189
GUISettings::liveries
uint8_t liveries
options for displaying company liveries, 0=none, 1=self, 2=all
Definition settings_type.h:182
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition settings_type.h:642
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition settings_type.h:633
Group
Group data.
Definition group.h:73
Group::livery
Livery livery
Custom colour scheme for vehicles in this group.
Definition group.h:79
Group::parent
GroupID parent
Parent group.
Definition group.h:85
Group::vehicle_type
VehicleType vehicle_type
Vehicle type of the group.
Definition group.h:76
Livery
Information about a particular livery.
Definition livery.h:79
Livery::in_use
Flags in_use
Livery flags.
Definition livery.h:86
Livery::colour2
Colours colour2
Second colour, for vehicles with 2CC support.
Definition livery.h:88
Livery::colour1
Colours colour1
First colour, for all vehicles.
Definition livery.h:87
Livery::Flag::Primary
@ Primary
Primary colour is set.
Livery::Flag::Secondary
@ Secondary
Secondary colour is set.
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
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:436
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:376
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(auto index)
Returns Titem with given index.
Definition pool_type.hpp:398
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition geometry_type.hpp:89
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition geometry_type.hpp:95
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition geometry_type.hpp:211
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:124
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition geometry_type.hpp:237
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition geometry_type.hpp:224
Rect::CentreToHeight
Rect CentreToHeight(int height) const
Centre a vertical dimension within this Rect.
Definition geometry_type.hpp:260
Rect::Height
int Height() const
Get height of Rect.
Definition geometry_type.hpp:117
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition geometry_type.hpp:200
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition window_gui.h:213
SelectCompanyLiveryWindow
Company livery colour scheme window.
Definition company_gui.cpp:601
SelectCompanyLiveryWindow::OnDropdownSelect
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
Definition company_gui.cpp:994
SelectCompanyLiveryWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition company_gui.cpp:1021
SelectCompanyLiveryWindow::UpdateWidgetSize
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.
Definition company_gui.cpp:745
SelectCompanyLiveryWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition company_gui.cpp:786
SelectCompanyLiveryWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition company_gui.cpp:841
SelectCompanyLiveryWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition company_gui.cpp:912
SelectCompanyLiveryWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition company_gui.cpp:800
SelectCompanyLiveryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition company_gui.cpp:989
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition bitmath_func.hpp:277
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130
WindowDesc
High level window description.
Definition window_gui.h:168
WindowNumber
Number to differentiate different windows of the same class.
Definition window_type.h:760
Window
Data structure for an opened window.
Definition window_gui.h:274
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:978
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1102
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1807
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:766
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3234
Window::parent
Window * parent
Parent window.
Definition window_gui.h:329
Window::RaiseWidget
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:470
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:556
Window::GetWidgetString
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:504
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::SetShaded
void SetShaded(bool make_shaded)
Set the shaded state of the window to make_shaded.
Definition window.cpp:1021
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:516
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1797
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:492
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:530
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:317
Window::EnableWidget
void EnableWidget(WidgetID widget_index)
Sets a widget to Enabled.
Definition window_gui.h:401
Window::FindWindowPlacementAndResize
virtual void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize)
Resize window towards the default size.
Definition window.cpp:1474
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:560
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition window_gui.h:356
Window::LowerWidget
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:461
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1820
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition window_gui.h:313
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:312
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
textbuf_gui.h
Stuff related to the text buffer GUI.
QueryStringFlag::EnableDefault
@ EnableDefault
enable the 'Default' button ("\0" is returned)
QueryStringFlag::LengthIsInChars
@ LengthIsInChars
the length of the string is counted in characters
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
tilehighlight_func.h
Functions related to tile highlights.
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition viewport.cpp:3573
SetObjectToPlaceWnd
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
Definition viewport.cpp:3510
HT_RECT
@ HT_RECT
rectangle (stations, depots, ...)
Definition tilehighlight_type.h:21
timer.h
Definition of Interval and OneShot timers.
timer_game_economy.h
Definition of the game-economy-timer.
timer_window.h
Definition of the Window system.
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition vehicle_type.h:26
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition vehicle_type.h:28
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition vehicle_type.h:27
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:25
VEH_COMPANY_END
@ VEH_COMPANY_END
Last company-ownable type.
Definition vehicle_type.h:30
SetTileSelectSize
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition viewport.cpp:2619
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition viewport.cpp:2592
viewport_func.h
Functions related to (drawing on) viewports.
water.h
Functions related to water (management)
CanalMaintenanceCost
Money CanalMaintenanceCost(uint32_t num)
Calculates the maintenance cost of a number of canal tiles.
Definition water.h:53
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:104
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:70
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:57
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:55
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:59
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:56
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition widget_type.h:505
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition widget_type.h:506
EqualSize
@ EqualSize
Containers should keep all their (resizing) children equally large.
Definition widget_type.h:541
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1276
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition window.cpp:3176
window_func.h
Window functions not directly related to making/drawing windows.
window_gui.h
Functions, definitions and such used only by the GUI.
WindowDefaultFlag::Construction
@ Construction
This window is used for construction; close it whenever changing company.
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
WC_BUY_COMPANY
@ WC_BUY_COMPANY
Buyout company (merger); Window numbers:
Definition window_type.h:605
WC_COMPANY_INFRASTRUCTURE
@ WC_COMPANY_INFRASTRUCTURE
Company infrastructure overview; Window numbers:
Definition window_type.h:598
WC_COMPANY_COLOUR
@ WC_COMPANY_COLOUR
Company colour selection; Window numbers:
Definition window_type.h:235
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
WC_FINANCES
@ WC_FINANCES
Finances of a company; Window numbers:
Definition window_type.h:532
WC_COMPANY_MANAGER_FACE
@ WC_COMPANY_MANAGER_FACE
Alter company face window; Window numbers:
Definition window_type.h:241
WC_COMPANY
@ WC_COMPANY
Company view; Window numbers:
Definition window_type.h:374
zoom_func.h
Functions related to zooming.