OpenTTD Source: src/company_gui.cpp Source File

OpenTTD Source 14.0-beta3

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 <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "currency.h"
12 #include "error.h"
13 #include "gui.h"
14 #include "window_gui.h"
15 #include "textbuf_gui.h"
16 #include "viewport_func.h"
17 #include "company_func.h"
18 #include "command_func.h"
19 #include "network/network.h"
20 #include "network/network_gui.h"
21 #include "network/network_func.h"
22 #include "newgrf.h"
23 #include "company_manager_face.h"
24 #include "strings_func.h"
25 #include "timer/timer_game_economy.h"
26 #include "widgets/dropdown_type.h"
27 #include "tilehighlight_func.h"
28 #include "company_base.h"
29 #include "core/geometry_func.hpp"
30 #include "object_type.h"
31 #include "rail.h"
32 #include "road.h"
33 #include "engine_base.h"
34 #include "window_func.h"
35 #include "road_func.h"
36 #include "water.h"
37 #include "station_func.h"
38 #include "zoom_func.h"
39 #include "sortlist_type.h"
40 #include "company_cmd.h"
41 #include "economy_cmd.h"
42 #include "group_cmd.h"
43 #include "misc_cmd.h"
44 #include "object_cmd.h"
45 #include "timer/timer.h"
46 #include "timer/timer_window.h"
47
48 #include "widgets/company_widget.h"
49
50 #include "safeguards.h"
51
52
54 static void DoSelectCompanyManagerFace(Window *parent);
55 static void ShowCompanyInfrastructure(CompanyID company);
56
58 static const std::initializer_list<ExpensesType> _expenses_list_revenue = {
59 EXPENSES_TRAIN_REVENUE,
60 EXPENSES_ROADVEH_REVENUE,
61 EXPENSES_AIRCRAFT_REVENUE,
62 EXPENSES_SHIP_REVENUE,
63 };
64
66 static const std::initializer_list<ExpensesType> _expenses_list_operating_costs = {
67 EXPENSES_TRAIN_RUN,
68 EXPENSES_ROADVEH_RUN,
69 EXPENSES_AIRCRAFT_RUN,
70 EXPENSES_SHIP_RUN,
71 EXPENSES_PROPERTY,
72 EXPENSES_LOAN_INTEREST,
73 };
74
76 static const std::initializer_list<ExpensesType> _expenses_list_capital_costs = {
77 EXPENSES_CONSTRUCTION,
78 EXPENSES_NEW_VEHICLES,
79 EXPENSES_OTHER,
80 };
81
83 struct ExpensesList {
84 const StringID title;
85 const std::initializer_list<ExpensesType> &items;
86
87 ExpensesList(StringID title, const std::initializer_list<ExpensesType> &list) : title(title), items(list)
88 {
89 }
90
91 uint GetHeight() const
92 {
93 /* Add up the height of all the lines. */
94 return static_cast<uint>(this->items.size()) * GetCharacterHeight(FS_NORMAL);
95 }
96
98 uint GetListWidth() const
99 {
100 uint width = 0;
101 for (const ExpensesType &et : this->items) {
102 width = std::max(width, GetStringBoundingBox(STR_FINANCES_SECTION_CONSTRUCTION + et).width);
103 }
104 return width;
105 }
106 };
107
109 static const std::initializer_list<ExpensesList> _expenses_list_types = {
110 { STR_FINANCES_REVENUE_TITLE, _expenses_list_revenue },
111 { STR_FINANCES_OPERATING_EXPENSES_TITLE, _expenses_list_operating_costs },
112 { STR_FINANCES_CAPITAL_EXPENSES_TITLE, _expenses_list_capital_costs },
113 };
114
119 static uint GetTotalCategoriesHeight()
120 {
121 /* There's an empty line and blockspace on the year row */
122 uint total_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
123
124 for (const ExpensesList &list : _expenses_list_types) {
125 /* Title + expense list + total line + total + blockspace after category */
126 total_height += GetCharacterHeight(FS_NORMAL) + list.GetHeight() + WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
127 }
128
129 /* Total income */
130 total_height += WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
131
132 return total_height;
133 }
134
139 static uint GetMaxCategoriesWidth()
140 {
141 uint max_width = GetStringBoundingBox(TimerGameEconomy::UsingWallclockUnits() ? STR_FINANCES_PERIOD_CAPTION : STR_FINANCES_YEAR_CAPTION).width;
142
143 /* Loop through categories to check max widths. */
144 for (const ExpensesList &list : _expenses_list_types) {
145 /* Title of category */
146 max_width = std::max(max_width, GetStringBoundingBox(list.title).width);
147 /* Entries in category */
148 max_width = std::max(max_width, list.GetListWidth() + WidgetDimensions::scaled.hsep_indent);
149 }
150
151 return max_width;
152 }
153
157 static void DrawCategory(const Rect &r, int start_y, const ExpensesList &list)
158 {
159 Rect tr = r.Indent(WidgetDimensions::scaled.hsep_indent, _current_text_dir == TD_RTL);
160
161 tr.top = start_y;
162
163 for (const ExpensesType &et : list.items) {
164 DrawString(tr, STR_FINANCES_SECTION_CONSTRUCTION + et);
165 tr.top += GetCharacterHeight(FS_NORMAL);
166 }
167 }
168
174 static void DrawCategories(const Rect &r)
175 {
176 int y = r.top;
177 /* Draw description of 12-minute economic period. */
178 DrawString(r.left, r.right, y, (TimerGameEconomy::UsingWallclockUnits() ? STR_FINANCES_PERIOD_CAPTION : STR_FINANCES_YEAR_CAPTION), TC_FROMSTRING, SA_LEFT, true);
179 y += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
180
181 for (const ExpensesList &list : _expenses_list_types) {
182 /* Draw category title and advance y */
183 DrawString(r.left, r.right, y, list.title, TC_FROMSTRING, SA_LEFT);
184 y += GetCharacterHeight(FS_NORMAL);
185
186 /* Draw category items and advance y */
187 DrawCategory(r, y, list);
188 y += list.GetHeight();
189
190 /* Advance y by the height of the horizontal line between amounts and subtotal */
191 y += WidgetDimensions::scaled.vsep_normal;
192
193 /* Draw category total and advance y */
194 DrawString(r.left, r.right, y, STR_FINANCES_TOTAL_CAPTION, TC_FROMSTRING, SA_RIGHT);
195 y += GetCharacterHeight(FS_NORMAL);
196
197 /* Advance y by a blockspace after this category block */
198 y += WidgetDimensions::scaled.vsep_wide;
199 }
200
201 /* Draw total profit/loss */
202 y += WidgetDimensions::scaled.vsep_normal;
203 DrawString(r.left, r.right, y, STR_FINANCES_PROFIT, TC_FROMSTRING, SA_LEFT);
204 }
205
214 static void DrawPrice(Money amount, int left, int right, int top, TextColour colour)
215 {
216 StringID str = STR_FINANCES_NEGATIVE_INCOME;
217 if (amount == 0) {
218 str = STR_FINANCES_ZERO_INCOME;
219 } else if (amount < 0) {
220 amount = -amount;
221 str = STR_FINANCES_POSITIVE_INCOME;
222 }
223 SetDParam(0, amount);
224 DrawString(left, right, top, str, colour, SA_RIGHT);
225 }
226
231 static Money DrawYearCategory(const Rect &r, int start_y, const ExpensesList &list, const Expenses &tbl)
232 {
233 int y = start_y;
234 Money sum = 0;
235
236 for (const ExpensesType &et : list.items) {
237 Money cost = tbl[et];
238 sum += cost;
239 if (cost != 0) DrawPrice(cost, r.left, r.right, y, TC_BLACK);
240 y += GetCharacterHeight(FS_NORMAL);
241 }
242
243 /* Draw the total at the bottom of the category. */
244 GfxFillRect(r.left, y, r.right, y + WidgetDimensions::scaled.bevel.top - 1, PC_BLACK);
245 y += WidgetDimensions::scaled.vsep_normal;
246 if (sum != 0) DrawPrice(sum, r.left, r.right, y, TC_WHITE);
247
248 /* Return the sum for the yearly total. */
249 return sum;
250 }
251
252
260 static void DrawYearColumn(const Rect &r, TimerGameEconomy::Year year, const Expenses &tbl)
261 {
262 int y = r.top;
263 Money sum;
264
265 /* Year header */
266 SetDParam(0, year);
267 DrawString(r.left, r.right, y, STR_FINANCES_YEAR, TC_FROMSTRING, SA_RIGHT, true);
268 y += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
269
270 /* Categories */
271 for (const ExpensesList &list : _expenses_list_types) {
272 y += GetCharacterHeight(FS_NORMAL);
273 sum += DrawYearCategory(r, y, list, tbl);
274 /* Expense list + expense category title + expense category total + blockspace after category */
275 y += list.GetHeight() + WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
276 }
277
278 /* Total income. */
279 GfxFillRect(r.left, y, r.right, y + WidgetDimensions::scaled.bevel.top - 1, PC_BLACK);
280 y += WidgetDimensions::scaled.vsep_normal;
281 DrawPrice(sum, r.left, r.right, y, TC_WHITE);
282 }
283
284 static constexpr NWidgetPart _nested_company_finances_widgets[] = {
285 NWidget(NWID_HORIZONTAL),
286 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
287 NWidget(WWT_CAPTION, COLOUR_GREY, WID_CF_CAPTION), SetDataTip(STR_FINANCES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
288 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_CF_TOGGLE_SIZE), SetDataTip(SPR_LARGE_SMALL_WINDOW, STR_TOOLTIP_TOGGLE_LARGE_SMALL_WINDOW),
289 NWidget(WWT_SHADEBOX, COLOUR_GREY),
290 NWidget(WWT_STICKYBOX, COLOUR_GREY),
291 EndContainer(),
292 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_CF_SEL_PANEL),
293 NWidget(WWT_PANEL, COLOUR_GREY),
294 NWidget(NWID_HORIZONTAL), SetPadding(WidgetDimensions::unscaled.framerect), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
295 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CF_EXPS_CATEGORY), SetMinimalSize(120, 0), SetFill(0, 0),
296 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CF_EXPS_PRICE1), SetMinimalSize(86, 0), SetFill(0, 0),
297 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CF_EXPS_PRICE2), SetMinimalSize(86, 0), SetFill(0, 0),
298 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CF_EXPS_PRICE3), SetMinimalSize(86, 0), SetFill(0, 0),
299 EndContainer(),
300 EndContainer(),
301 EndContainer(),
302 NWidget(WWT_PANEL, COLOUR_GREY),
303 NWidget(NWID_HORIZONTAL), SetPadding(WidgetDimensions::unscaled.framerect), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0), SetPIPRatio(0, 1, 2),
304 NWidget(NWID_VERTICAL), // Vertical column with 'bank balance', 'loan'
305 NWidget(WWT_TEXT, COLOUR_GREY), SetDataTip(STR_FINANCES_OWN_FUNDS_TITLE, STR_NULL),
306 NWidget(WWT_TEXT, COLOUR_GREY), SetDataTip(STR_FINANCES_LOAN_TITLE, STR_NULL),
307 NWidget(WWT_TEXT, COLOUR_GREY), SetDataTip(STR_FINANCES_BANK_BALANCE_TITLE, STR_NULL), SetPadding(WidgetDimensions::unscaled.vsep_normal, 0, 0, 0),
308 EndContainer(),
309 NWidget(NWID_VERTICAL), // Vertical column with bank balance amount, loan amount, and total.
310 NWidget(WWT_TEXT, COLOUR_GREY, WID_CF_OWN_VALUE), SetDataTip(STR_FINANCES_TOTAL_CURRENCY, STR_NULL), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
311 NWidget(WWT_TEXT, COLOUR_GREY, WID_CF_LOAN_VALUE), SetDataTip(STR_FINANCES_TOTAL_CURRENCY, STR_NULL), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
312 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CF_BALANCE_LINE), SetMinimalSize(0, WidgetDimensions::unscaled.vsep_normal),
313 NWidget(WWT_TEXT, COLOUR_GREY, WID_CF_BALANCE_VALUE), SetDataTip(STR_FINANCES_BANK_BALANCE, STR_NULL), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
314 EndContainer(),
315 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_CF_SEL_MAXLOAN),
316 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1), // Max loan information
317 NWidget(WWT_TEXT, COLOUR_GREY, WID_CF_INTEREST_RATE), SetDataTip(STR_FINANCES_INTEREST_RATE, STR_NULL),
318 NWidget(WWT_TEXT, COLOUR_GREY, WID_CF_MAXLOAN_VALUE), SetDataTip(STR_FINANCES_MAX_LOAN, STR_NULL),
319 EndContainer(),
320 EndContainer(),
321 EndContainer(),
322 EndContainer(),
323 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_CF_SEL_BUTTONS),
324 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
325 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CF_INCREASE_LOAN), SetFill(1, 0), SetDataTip(STR_FINANCES_BORROW_BUTTON, STR_FINANCES_BORROW_TOOLTIP),
326 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CF_REPAY_LOAN), SetFill(1, 0), SetDataTip(STR_FINANCES_REPAY_BUTTON, STR_FINANCES_REPAY_TOOLTIP),
327 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CF_INFRASTRUCTURE), SetFill(1, 0), SetDataTip(STR_FINANCES_INFRASTRUCTURE_BUTTON, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP),
328 EndContainer(),
329 EndContainer(),
330 };
331
333 struct CompanyFinancesWindow : Window {
334 static Money max_money;
335 bool small;
336
337 CompanyFinancesWindow(WindowDesc *desc, CompanyID company) : Window(desc)
338 {
339 this->small = false;
340 this->CreateNestedTree();
341 this->SetupWidgets();
342 this->FinishInitNested(company);
343
344 this->owner = (Owner)this->window_number;
345 }
346
347 void SetStringParameters(WidgetID widget) const override
348 {
349 switch (widget) {
350 case WID_CF_CAPTION:
351 SetDParam(0, (CompanyID)this->window_number);
352 SetDParam(1, (CompanyID)this->window_number);
353 break;
354
355 case WID_CF_BALANCE_VALUE: {
356 const Company *c = Company::Get((CompanyID)this->window_number);
357 SetDParam(0, c->money);
358 break;
359 }
360
361 case WID_CF_LOAN_VALUE: {
362 const Company *c = Company::Get((CompanyID)this->window_number);
363 SetDParam(0, c->current_loan);
364 break;
365 }
366
367 case WID_CF_OWN_VALUE: {
368 const Company *c = Company::Get((CompanyID)this->window_number);
369 SetDParam(0, c->money - c->current_loan);
370 break;
371 }
372
373 case WID_CF_INTEREST_RATE:
374 SetDParam(0, _settings_game.difficulty.initial_interest);
375 break;
376
377 case WID_CF_MAXLOAN_VALUE: {
378 const Company *c = Company::Get((CompanyID)this->window_number);
379 SetDParam(0, c->GetMaxLoan());
380 break;
381 }
382
383 case WID_CF_INCREASE_LOAN:
384 case WID_CF_REPAY_LOAN:
385 SetDParam(0, LOAN_INTERVAL);
386 break;
387 }
388 }
389
390 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
391 {
392 switch (widget) {
393 case WID_CF_EXPS_CATEGORY:
394 size->width = GetMaxCategoriesWidth();
395 size->height = GetTotalCategoriesHeight();
396 break;
397
398 case WID_CF_EXPS_PRICE1:
399 case WID_CF_EXPS_PRICE2:
400 case WID_CF_EXPS_PRICE3:
401 size->height = GetTotalCategoriesHeight();
402 [[fallthrough]];
403
404 case WID_CF_BALANCE_VALUE:
405 case WID_CF_LOAN_VALUE:
406 case WID_CF_OWN_VALUE:
407 SetDParamMaxValue(0, CompanyFinancesWindow::max_money);
408 size->width = std::max(GetStringBoundingBox(STR_FINANCES_NEGATIVE_INCOME).width, GetStringBoundingBox(STR_FINANCES_POSITIVE_INCOME).width) + padding.width;
409 break;
410
411 case WID_CF_INTEREST_RATE:
412 size->height = GetCharacterHeight(FS_NORMAL);
413 break;
414 }
415 }
416
417 void DrawWidget(const Rect &r, WidgetID widget) const override
418 {
419 switch (widget) {
420 case WID_CF_EXPS_CATEGORY:
421 DrawCategories(r);
422 break;
423
424 case WID_CF_EXPS_PRICE1:
425 case WID_CF_EXPS_PRICE2:
426 case WID_CF_EXPS_PRICE3: {
427 const Company *c = Company::Get((CompanyID)this->window_number);
428 auto age = std::min(TimerGameEconomy::year - c->inaugurated_year, TimerGameEconomy::Year(2));
429 int wid_offset = widget - WID_CF_EXPS_PRICE1;
430 if (wid_offset <= age) {
431 DrawYearColumn(r, TimerGameEconomy::year - (age - wid_offset), c->yearly_expenses[(age - wid_offset).base()]);
432 }
433 break;
434 }
435
436 case WID_CF_BALANCE_LINE:
437 GfxFillRect(r.left, r.top, r.right, r.top + WidgetDimensions::scaled.bevel.top - 1, PC_BLACK);
438 break;
439 }
440 }
441
446 void SetupWidgets()
447 {
448 int plane = this->small ? SZSP_NONE : 0;
449 this->GetWidget<NWidgetStacked>(WID_CF_SEL_PANEL)->SetDisplayedPlane(plane);
450 this->GetWidget<NWidgetStacked>(WID_CF_SEL_MAXLOAN)->SetDisplayedPlane(plane);
451
452 CompanyID company = (CompanyID)this->window_number;
453 plane = (company != _local_company) ? SZSP_NONE : 0;
454 this->GetWidget<NWidgetStacked>(WID_CF_SEL_BUTTONS)->SetDisplayedPlane(plane);
455 }
456
457 void OnPaint() override
458 {
459 if (!this->IsShaded()) {
460 if (!this->small) {
461 /* Check that the expenses panel height matches the height needed for the layout. */
462 if (GetTotalCategoriesHeight() != this->GetWidget<NWidgetBase>(WID_CF_EXPS_CATEGORY)->current_y) {
463 this->SetupWidgets();
464 this->ReInit();
465 return;
466 }
467 }
468
469 /* Check that the loan buttons are shown only when the user owns the company. */
470 CompanyID company = (CompanyID)this->window_number;
471 int req_plane = (company != _local_company) ? SZSP_NONE : 0;
472 if (req_plane != this->GetWidget<NWidgetStacked>(WID_CF_SEL_BUTTONS)->shown_plane) {
473 this->SetupWidgets();
474 this->ReInit();
475 return;
476 }
477
478 const Company *c = Company::Get(company);
479 this->SetWidgetDisabledState(WID_CF_INCREASE_LOAN, c->current_loan >= c->GetMaxLoan()); // Borrow button only shows when there is any more money to loan.
480 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.
481 }
482
483 this->DrawWidgets();
484 }
485
486 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
487 {
488 switch (widget) {
489 case WID_CF_TOGGLE_SIZE: // toggle size
490 this->small = !this->small;
491 this->SetupWidgets();
492 if (this->IsShaded()) {
493 /* Finances window is not resizable, so size hints given during unshading have no effect
494 * on the changed appearance of the window. */
495 this->SetShaded(false);
496 } else {
497 this->ReInit();
498 }
499 break;
500
501 case WID_CF_INCREASE_LOAN: // increase loan
502 Command<CMD_INCREASE_LOAN>::Post(STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY, _ctrl_pressed ? LoanCommand::Max : LoanCommand::Interval, 0);
503 break;
504
505 case WID_CF_REPAY_LOAN: // repay loan
506 Command<CMD_DECREASE_LOAN>::Post(STR_ERROR_CAN_T_REPAY_LOAN, _ctrl_pressed ? LoanCommand::Max : LoanCommand::Interval, 0);
507 break;
508
509 case WID_CF_INFRASTRUCTURE: // show infrastructure details
510 ShowCompanyInfrastructure((CompanyID)this->window_number);
511 break;
512 }
513 }
514
519 IntervalTimer<TimerWindow> rescale_interval = {std::chrono::seconds(3), [this](auto) {
520 const Company *c = Company::Get((CompanyID)this->window_number);
521 if (c->money > CompanyFinancesWindow::max_money) {
522 CompanyFinancesWindow::max_money = std::max(c->money * 2, CompanyFinancesWindow::max_money * 4);
523 this->SetupWidgets();
524 this->ReInit();
525 }
526 }};
527 };
528
530 Money CompanyFinancesWindow::max_money = INT32_MAX;
531
532 static WindowDesc _company_finances_desc(__FILE__, __LINE__,
533 WDP_AUTO, "company_finances", 0, 0,
534 WC_FINANCES, WC_NONE,
535 0,
536 std::begin(_nested_company_finances_widgets), std::end(_nested_company_finances_widgets)
537 );
538
544 void ShowCompanyFinances(CompanyID company)
545 {
546 if (!Company::IsValidID(company)) return;
547 if (BringWindowToFrontById(WC_FINANCES, company)) return;
548
549 new CompanyFinancesWindow(&_company_finances_desc, company);
550 }
551
552 /* List of colours for the livery window */
553 static const StringID _colour_dropdown[] = {
554 STR_COLOUR_DARK_BLUE,
555 STR_COLOUR_PALE_GREEN,
556 STR_COLOUR_PINK,
557 STR_COLOUR_YELLOW,
558 STR_COLOUR_RED,
559 STR_COLOUR_LIGHT_BLUE,
560 STR_COLOUR_GREEN,
561 STR_COLOUR_DARK_GREEN,
562 STR_COLOUR_BLUE,
563 STR_COLOUR_CREAM,
564 STR_COLOUR_MAUVE,
565 STR_COLOUR_PURPLE,
566 STR_COLOUR_ORANGE,
567 STR_COLOUR_BROWN,
568 STR_COLOUR_GREY,
569 STR_COLOUR_WHITE,
570 };
571
572 /* Association of liveries to livery classes */
573 static const LiveryClass _livery_class[LS_END] = {
574 LC_OTHER,
575 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,
576 LC_ROAD, LC_ROAD,
577 LC_SHIP, LC_SHIP,
578 LC_AIRCRAFT, LC_AIRCRAFT, LC_AIRCRAFT,
579 LC_ROAD, LC_ROAD,
580 };
581
586 template <SpriteID TSprite = SPR_SQUARE>
587 class DropDownListColourItem : public DropDownIcon<DropDownString<DropDownListItem>> {
588 public:
589 DropDownListColourItem(int colour, bool masked) : DropDownIcon<DropDownString<DropDownListItem>>(TSprite, GENERAL_SPRITE_COLOUR(colour % COLOUR_END), colour < COLOUR_END ? _colour_dropdown[colour] : STR_COLOUR_DEFAULT, colour, masked)
590 {
591 }
592 };
593
594 typedef GUIList<const Group*> GUIGroupList;
595
597 struct SelectCompanyLiveryWindow : public Window {
598 private:
599 uint32_t sel;
600 LiveryClass livery_class;
601 Dimension square;
602 uint rows;
603 uint line_height;
604 GUIGroupList groups;
605 std::vector<int> indents;
606 Scrollbar *vscroll;
607
608 void ShowColourDropDownMenu(uint32_t widget)
609 {
610 uint32_t used_colours = 0;
611 const Livery *livery, *default_livery = nullptr;
612 bool primary = widget == WID_SCL_PRI_COL_DROPDOWN;
613 byte default_col = 0;
614
615 /* Disallow other company colours for the primary colour */
616 if (this->livery_class < LC_GROUP_RAIL && HasBit(this->sel, LS_DEFAULT) && primary) {
617 for (const Company *c : Company::Iterate()) {
618 if (c->index != _local_company) SetBit(used_colours, c->colour);
619 }
620 }
621
622 const Company *c = Company::Get((CompanyID)this->window_number);
623
624 if (this->livery_class < LC_GROUP_RAIL) {
625 /* Get the first selected livery to use as the default dropdown item */
626 LiveryScheme scheme;
627 for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
628 if (HasBit(this->sel, scheme)) break;
629 }
630 if (scheme == LS_END) scheme = LS_DEFAULT;
631 livery = &c->livery[scheme];
632 if (scheme != LS_DEFAULT) default_livery = &c->livery[LS_DEFAULT];
633 } else {
634 const Group *g = Group::Get(this->sel);
635 livery = &g->livery;
636 if (g->parent == INVALID_GROUP) {
637 default_livery = &c->livery[LS_DEFAULT];
638 } else {
639 const Group *pg = Group::Get(g->parent);
640 default_livery = &pg->livery;
641 }
642 }
643
644 DropDownList list;
645 if (default_livery != nullptr) {
646 /* Add COLOUR_END to put the colour out of range, but also allow us to show what the default is */
647 default_col = (primary ? default_livery->colour1 : default_livery->colour2) + COLOUR_END;
648 list.push_back(std::make_unique<DropDownListColourItem<>>(default_col, false));
649 }
650 for (uint i = 0; i < lengthof(_colour_dropdown); i++) {
651 list.push_back(std::make_unique<DropDownListColourItem<>>(i, HasBit(used_colours, i)));
652 }
653
654 byte sel;
655 if (default_livery == nullptr || HasBit(livery->in_use, primary ? 0 : 1)) {
656 sel = primary ? livery->colour1 : livery->colour2;
657 } else {
658 sel = default_col;
659 }
660 ShowDropDownList(this, std::move(list), sel, widget);
661 }
662
663 void AddChildren(GUIGroupList &source, GroupID parent, int indent)
664 {
665 for (const Group *g : source) {
666 if (g->parent != parent) continue;
667 this->groups.push_back(g);
668 this->indents.push_back(indent);
669 AddChildren(source, g->index, indent + 1);
670 }
671 }
672
673 void BuildGroupList(CompanyID owner)
674 {
675 if (!this->groups.NeedRebuild()) return;
676
677 this->groups.clear();
678 this->indents.clear();
679
680 if (this->livery_class >= LC_GROUP_RAIL) {
681 GUIGroupList list;
682 VehicleType vtype = (VehicleType)(this->livery_class - LC_GROUP_RAIL);
683
684 for (const Group *g : Group::Iterate()) {
685 if (g->owner == owner && g->vehicle_type == vtype) {
686 list.push_back(g);
687 }
688 }
689
690 list.ForceResort();
691
692 /* Sort the groups by their name */
693 const Group *last_group[2] = { nullptr, nullptr };
694 std::string last_name[2] = { {}, {} };
695 list.Sort([&](const Group * const &a, const Group * const &b) -> bool {
696 if (a != last_group[0]) {
697 last_group[0] = a;
698 SetDParam(0, a->index);
699 last_name[0] = GetString(STR_GROUP_NAME);
700 }
701
702 if (b != last_group[1]) {
703 last_group[1] = b;
704 SetDParam(0, b->index);
705 last_name[1] = GetString(STR_GROUP_NAME);
706 }
707
708 int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
709 if (r == 0) return a->index < b->index;
710 return r < 0;
711 });
712
713 AddChildren(list, INVALID_GROUP, 0);
714 }
715
716 this->groups.shrink_to_fit();
717 this->groups.RebuildDone();
718 }
719
720 void SetRows()
721 {
722 if (this->livery_class < LC_GROUP_RAIL) {
723 this->rows = 0;
724 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
725 if (_livery_class[scheme] == this->livery_class && HasBit(_loaded_newgrf_features.used_liveries, scheme)) {
726 this->rows++;
727 }
728 }
729 } else {
730 this->rows = (uint)this->groups.size();
731 }
732
733 this->vscroll->SetCount(this->rows);
734 }
735
736 public:
737 SelectCompanyLiveryWindow(WindowDesc *desc, CompanyID company, GroupID group) : Window(desc)
738 {
739 this->CreateNestedTree();
740 this->vscroll = this->GetScrollbar(WID_SCL_MATRIX_SCROLLBAR);
741
742 if (group == INVALID_GROUP) {
743 this->livery_class = LC_OTHER;
744 this->sel = 1;
745 this->LowerWidget(WID_SCL_CLASS_GENERAL);
746 this->BuildGroupList(company);
747 this->SetRows();
748 } else {
749 this->SetSelectedGroup(company, group);
750 }
751
752 this->FinishInitNested(company);
753 this->owner = company;
754 this->InvalidateData(1);
755 }
756
757 void SetSelectedGroup(CompanyID company, GroupID group)
758 {
759 this->RaiseWidget(WID_SCL_CLASS_GENERAL + this->livery_class);
760 const Group *g = Group::Get(group);
761 switch (g->vehicle_type) {
762 case VEH_TRAIN: this->livery_class = LC_GROUP_RAIL; break;
763 case VEH_ROAD: this->livery_class = LC_GROUP_ROAD; break;
764 case VEH_SHIP: this->livery_class = LC_GROUP_SHIP; break;
765 case VEH_AIRCRAFT: this->livery_class = LC_GROUP_AIRCRAFT; break;
766 default: NOT_REACHED();
767 }
768 this->sel = group;
769 this->LowerWidget(WID_SCL_CLASS_GENERAL + this->livery_class);
770
771 this->groups.ForceRebuild();
772 this->BuildGroupList(company);
773 this->SetRows();
774
775 /* Position scrollbar to selected group */
776 for (uint i = 0; i < this->rows; i++) {
777 if (this->groups[i]->index == sel) {
778 this->vscroll->SetPosition(i - this->vscroll->GetCapacity() / 2);
779 break;
780 }
781 }
782 }
783
784 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
785 {
786 switch (widget) {
787 case WID_SCL_SPACER_DROPDOWN: {
788 /* The matrix widget below needs enough room to print all the schemes. */
789 Dimension d = {0, 0};
790 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
791 d = maxdim(d, GetStringBoundingBox(STR_LIVERY_DEFAULT + scheme));
792 }
793
794 /* And group names */
795 for (const Group *g : Group::Iterate()) {
796 if (g->owner == (CompanyID)this->window_number) {
797 SetDParam(0, g->index);
798 d = maxdim(d, GetStringBoundingBox(STR_GROUP_NAME));
799 }
800 }
801
802 size->width = std::max(size->width, 5 + d.width + padding.width);
803 break;
804 }
805
806 case WID_SCL_MATRIX: {
807 /* 11 items in the default rail class */
808 this->square = GetSpriteSize(SPR_SQUARE);
809 this->line_height = std::max(this->square.height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height;
810
811 size->height = 5 * this->line_height;
812 resize->width = 1;
813 resize->height = this->line_height;
814 break;
815 }
816
817 case WID_SCL_SEC_COL_DROPDOWN:
818 if (!_loaded_newgrf_features.has_2CC) {
819 size->width = 0;
820 break;
821 }
822 [[fallthrough]];
823
824 case WID_SCL_PRI_COL_DROPDOWN: {
825 this->square = GetSpriteSize(SPR_SQUARE);
826 int string_padding = this->square.width + WidgetDimensions::scaled.hsep_normal + padding.width;
827 for (const StringID *id = _colour_dropdown; id != endof(_colour_dropdown); id++) {
828 size->width = std::max(size->width, GetStringBoundingBox(*id).width + string_padding);
829 }
830 size->width = std::max(size->width, GetStringBoundingBox(STR_COLOUR_DEFAULT).width + string_padding);
831 break;
832 }
833 }
834 }
835
836 void OnPaint() override
837 {
838 bool local = (CompanyID)this->window_number == _local_company;
839
840 /* Disable dropdown controls if no scheme is selected */
841 bool disabled = this->livery_class < LC_GROUP_RAIL ? (this->sel == 0) : (this->sel == INVALID_GROUP);
842 this->SetWidgetDisabledState(WID_SCL_PRI_COL_DROPDOWN, !local || disabled);
843 this->SetWidgetDisabledState(WID_SCL_SEC_COL_DROPDOWN, !local || disabled);
844
845 this->BuildGroupList((CompanyID)this->window_number);
846
847 this->DrawWidgets();
848 }
849
850 void SetStringParameters(WidgetID widget) const override
851 {
852 switch (widget) {
853 case WID_SCL_CAPTION:
854 SetDParam(0, (CompanyID)this->window_number);
855 break;
856
857 case WID_SCL_PRI_COL_DROPDOWN:
858 case WID_SCL_SEC_COL_DROPDOWN: {
859 const Company *c = Company::Get((CompanyID)this->window_number);
860 bool primary = widget == WID_SCL_PRI_COL_DROPDOWN;
861 StringID colour = STR_COLOUR_DEFAULT;
862
863 if (this->livery_class < LC_GROUP_RAIL) {
864 if (this->sel != 0) {
865 LiveryScheme scheme = LS_DEFAULT;
866 for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
867 if (HasBit(this->sel, scheme)) break;
868 }
869 if (scheme == LS_END) scheme = LS_DEFAULT;
870 const Livery *livery = &c->livery[scheme];
871 if (scheme == LS_DEFAULT || HasBit(livery->in_use, primary ? 0 : 1)) {
872 colour = STR_COLOUR_DARK_BLUE + (primary ? livery->colour1 : livery->colour2);
873 }
874 }
875 } else {
876 if (this->sel != INVALID_GROUP) {
877 const Group *g = Group::Get(this->sel);
878 const Livery *livery = &g->livery;
879 if (HasBit(livery->in_use, primary ? 0 : 1)) {
880 colour = STR_COLOUR_DARK_BLUE + (primary ? livery->colour1 : livery->colour2);
881 }
882 }
883 }
884 SetDParam(0, colour);
885 break;
886 }
887 }
888 }
889
890 void DrawWidget(const Rect &r, WidgetID widget) const override
891 {
892 if (widget != WID_SCL_MATRIX) return;
893
894 bool rtl = _current_text_dir == TD_RTL;
895
896 /* Coordinates of scheme name column. */
897 const NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_SCL_SPACER_DROPDOWN);
898 Rect sch = nwi->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
899 /* Coordinates of first dropdown. */
900 nwi = this->GetWidget<NWidgetBase>(WID_SCL_PRI_COL_DROPDOWN);
901 Rect pri = nwi->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
902 /* Coordinates of second dropdown. */
903 nwi = this->GetWidget<NWidgetBase>(WID_SCL_SEC_COL_DROPDOWN);
904 Rect sec = nwi->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
905
906 Rect pri_squ = pri.WithWidth(this->square.width, rtl);
907 Rect sec_squ = sec.WithWidth(this->square.width, rtl);
908
909 pri = pri.Indent(this->square.width + WidgetDimensions::scaled.hsep_normal, rtl);
910 sec = sec.Indent(this->square.width + WidgetDimensions::scaled.hsep_normal, rtl);
911
912 Rect ir = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
913 int square_offs = (ir.Height() - this->square.height) / 2;
914 int text_offs = (ir.Height() - GetCharacterHeight(FS_NORMAL)) / 2;
915
916 int y = ir.top;
917
918 /* Helper function to draw livery info. */
919 auto draw_livery = [&](StringID str, const Livery &livery, bool is_selected, bool is_default_scheme, int indent) {
920 /* Livery Label. */
921 DrawString(sch.left + (rtl ? 0 : indent), sch.right - (rtl ? indent : 0), y + text_offs, str, is_selected ? TC_WHITE : TC_BLACK);
922
923 /* Text below the first dropdown. */
924 DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOUR(livery.colour1), pri_squ.left, y + square_offs);
925 DrawString(pri.left, pri.right, y + text_offs, (is_default_scheme || HasBit(livery.in_use, 0)) ? STR_COLOUR_DARK_BLUE + livery.colour1 : STR_COLOUR_DEFAULT, is_selected ? TC_WHITE : TC_GOLD);
926
927 /* Text below the second dropdown. */
928 if (sec.right > sec.left) { // Second dropdown has non-zero size.
929 DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOUR(livery.colour2), sec_squ.left, y + square_offs);
930 DrawString(sec.left, sec.right, y + text_offs, (is_default_scheme || HasBit(livery.in_use, 1)) ? STR_COLOUR_DARK_BLUE + livery.colour2 : STR_COLOUR_DEFAULT, is_selected ? TC_WHITE : TC_GOLD);
931 }
932
933 y += this->line_height;
934 };
935
936 const Company *c = Company::Get((CompanyID)this->window_number);
937
938 if (livery_class < LC_GROUP_RAIL) {
939 int pos = this->vscroll->GetPosition();
940 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
941 if (_livery_class[scheme] == this->livery_class && HasBit(_loaded_newgrf_features.used_liveries, scheme)) {
942 if (pos-- > 0) continue;
943 draw_livery(STR_LIVERY_DEFAULT + scheme, c->livery[scheme], HasBit(this->sel, scheme), scheme == LS_DEFAULT, 0);
944 }
945 }
946 } else {
947 uint max = static_cast<uint>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->groups.size()));
948 for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
949 const Group *g = this->groups[i];
950 SetDParam(0, g->index);
951 draw_livery(STR_GROUP_NAME, g->livery, this->sel == g->index, false, this->indents[i] * WidgetDimensions::scaled.hsep_indent);
952 }
953
954 if (this->vscroll->GetCount() == 0) {
955 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 };
956 VehicleType vtype = (VehicleType)(this->livery_class - LC_GROUP_RAIL);
957 DrawString(ir.left, ir.right, y + text_offs, empty_labels[vtype], TC_BLACK);
958 }
959 }
960 }
961
962 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
963 {
964 switch (widget) {
965 /* Livery Class buttons */
966 case WID_SCL_CLASS_GENERAL:
967 case WID_SCL_CLASS_RAIL:
968 case WID_SCL_CLASS_ROAD:
969 case WID_SCL_CLASS_SHIP:
970 case WID_SCL_CLASS_AIRCRAFT:
971 case WID_SCL_GROUPS_RAIL:
972 case WID_SCL_GROUPS_ROAD:
973 case WID_SCL_GROUPS_SHIP:
974 case WID_SCL_GROUPS_AIRCRAFT:
975 this->RaiseWidget(WID_SCL_CLASS_GENERAL + this->livery_class);
976 this->livery_class = (LiveryClass)(widget - WID_SCL_CLASS_GENERAL);
977 this->LowerWidget(WID_SCL_CLASS_GENERAL + this->livery_class);
978
979 /* Select the first item in the list */
980 if (this->livery_class < LC_GROUP_RAIL) {
981 this->sel = 0;
982 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
983 if (_livery_class[scheme] == this->livery_class && HasBit(_loaded_newgrf_features.used_liveries, scheme)) {
984 this->sel = 1 << scheme;
985 break;
986 }
987 }
988 } else {
989 this->sel = INVALID_GROUP;
990 this->groups.ForceRebuild();
991 this->BuildGroupList((CompanyID)this->window_number);
992
993 if (!this->groups.empty()) {
994 this->sel = this->groups[0]->index;
995 }
996 }
997
998 this->SetRows();
999 this->SetDirty();
1000 break;
1001
1002 case WID_SCL_PRI_COL_DROPDOWN: // First colour dropdown
1003 ShowColourDropDownMenu(WID_SCL_PRI_COL_DROPDOWN);
1004 break;
1005
1006 case WID_SCL_SEC_COL_DROPDOWN: // Second colour dropdown
1007 ShowColourDropDownMenu(WID_SCL_SEC_COL_DROPDOWN);
1008 break;
1009
1010 case WID_SCL_MATRIX: {
1011 uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SCL_MATRIX);
1012 if (row >= this->rows) return;
1013
1014 if (this->livery_class < LC_GROUP_RAIL) {
1015 LiveryScheme j = (LiveryScheme)row;
1016
1017 for (LiveryScheme scheme = LS_BEGIN; scheme <= j && scheme < LS_END; scheme++) {
1018 if (_livery_class[scheme] != this->livery_class || !HasBit(_loaded_newgrf_features.used_liveries, scheme)) j++;
1019 }
1020 assert(j < LS_END);
1021
1022 if (_ctrl_pressed) {
1023 ToggleBit(this->sel, j);
1024 } else {
1025 this->sel = 1 << j;
1026 }
1027 } else {
1028 this->sel = this->groups[row]->index;
1029 }
1030 this->SetDirty();
1031 break;
1032 }
1033 }
1034 }
1035
1036 void OnResize() override
1037 {
1038 this->vscroll->SetCapacityFromWidget(this, WID_SCL_MATRIX);
1039 }
1040
1041 void OnDropdownSelect(WidgetID widget, int index) override
1042 {
1043 bool local = (CompanyID)this->window_number == _local_company;
1044 if (!local) return;
1045
1046 Colours colour = static_cast<Colours>(index);
1047 if (colour >= COLOUR_END) colour = INVALID_COLOUR;
1048
1049 if (this->livery_class < LC_GROUP_RAIL) {
1050 /* Set company colour livery */
1051 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1052 /* Changed colour for the selected scheme, or all visible schemes if CTRL is pressed. */
1053 if (HasBit(this->sel, scheme) || (_ctrl_pressed && _livery_class[scheme] == this->livery_class && HasBit(_loaded_newgrf_features.used_liveries, scheme))) {
1054 Command<CMD_SET_COMPANY_COLOUR>::Post(scheme, widget == WID_SCL_PRI_COL_DROPDOWN, colour);
1055 }
1056 }
1057 } else {
1058 /* Setting group livery */
1059 Command<CMD_SET_GROUP_LIVERY>::Post(this->sel, widget == WID_SCL_PRI_COL_DROPDOWN, colour);
1060 }
1061 }
1062
1068 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1069 {
1070 if (!gui_scope) return;
1071
1072 if (data != -1) {
1073 /* data contains a VehicleType, rebuild list if it displayed */
1074 if (this->livery_class == data + LC_GROUP_RAIL) {
1075 this->groups.ForceRebuild();
1076 this->BuildGroupList((CompanyID)this->window_number);
1077 this->SetRows();
1078
1079 if (!Group::IsValidID(this->sel)) {
1080 this->sel = INVALID_GROUP;
1081 if (!this->groups.empty()) this->sel = this->groups[0]->index;
1082 }
1083
1084 this->SetDirty();
1085 }
1086 return;
1087 }
1088
1089 this->SetWidgetsDisabledState(true, WID_SCL_CLASS_RAIL, WID_SCL_CLASS_ROAD, WID_SCL_CLASS_SHIP, WID_SCL_CLASS_AIRCRAFT);
1090
1091 bool current_class_valid = this->livery_class == LC_OTHER || this->livery_class >= LC_GROUP_RAIL;
1092 if (_settings_client.gui.liveries == LIT_ALL || (_settings_client.gui.liveries == LIT_COMPANY && this->window_number == _local_company)) {
1093 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1094 if (HasBit(_loaded_newgrf_features.used_liveries, scheme)) {
1095 if (_livery_class[scheme] == this->livery_class) current_class_valid = true;
1096 this->EnableWidget(WID_SCL_CLASS_GENERAL + _livery_class[scheme]);
1097 } else if (this->livery_class < LC_GROUP_RAIL) {
1098 ClrBit(this->sel, scheme);
1099 }
1100 }
1101 }
1102
1103 if (!current_class_valid) {
1104 Point pt = {0, 0};
1105 this->OnClick(pt, WID_SCL_CLASS_GENERAL, 1);
1106 }
1107 }
1108 };
1109
1110 static constexpr NWidgetPart _nested_select_company_livery_widgets[] = {
1111 NWidget(NWID_HORIZONTAL),
1112 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1113 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SCL_CAPTION), SetDataTip(STR_LIVERY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1114 EndContainer(),
1115 NWidget(NWID_HORIZONTAL),
1116 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_GENERAL), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_COMPANY_GENERAL, STR_LIVERY_GENERAL_TOOLTIP),
1117 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_RAIL), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRAINLIST, STR_LIVERY_TRAIN_TOOLTIP),
1118 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_ROAD), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRUCKLIST, STR_LIVERY_ROAD_VEHICLE_TOOLTIP),
1119 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_SHIP), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SHIPLIST, STR_LIVERY_SHIP_TOOLTIP),
1120 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_AIRCRAFT), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_AIRPLANESLIST, STR_LIVERY_AIRCRAFT_TOOLTIP),
1121 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_GROUPS_RAIL), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_GROUP_LIVERY_TRAIN, STR_LIVERY_TRAIN_GROUP_TOOLTIP),
1122 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_GROUPS_ROAD), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_GROUP_LIVERY_ROADVEH, STR_LIVERY_ROAD_VEHICLE_GROUP_TOOLTIP),
1123 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_GROUPS_SHIP), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_GROUP_LIVERY_SHIP, STR_LIVERY_SHIP_GROUP_TOOLTIP),
1124 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_GROUPS_AIRCRAFT), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_GROUP_LIVERY_AIRCRAFT, STR_LIVERY_AIRCRAFT_GROUP_TOOLTIP),
1125 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 0), EndContainer(),
1126 EndContainer(),
1127 NWidget(NWID_HORIZONTAL),
1128 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),
1129 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SCL_MATRIX_SCROLLBAR),
1130 EndContainer(),
1131 NWidget(NWID_HORIZONTAL),
1132 NWidget(WWT_PANEL, COLOUR_GREY, WID_SCL_SPACER_DROPDOWN), SetFill(1, 1), SetResize(1, 0), EndContainer(),
1133 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SCL_PRI_COL_DROPDOWN), SetFill(0, 1), SetDataTip(STR_JUST_STRING, STR_LIVERY_PRIMARY_TOOLTIP),
1134 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SCL_SEC_COL_DROPDOWN), SetFill(0, 1), SetDataTip(STR_JUST_STRING, STR_LIVERY_SECONDARY_TOOLTIP),
1135 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1136 EndContainer(),
1137 };
1138
1139 static WindowDesc _select_company_livery_desc(__FILE__, __LINE__,
1140 WDP_AUTO, nullptr, 0, 0,
1141 WC_COMPANY_COLOUR, WC_NONE,
1142 0,
1143 std::begin(_nested_select_company_livery_widgets), std::end(_nested_select_company_livery_widgets)
1144 );
1145
1146 void ShowCompanyLiveryWindow(CompanyID company, GroupID group)
1147 {
1148 SelectCompanyLiveryWindow *w = (SelectCompanyLiveryWindow *)BringWindowToFrontById(WC_COMPANY_COLOUR, company);
1149 if (w == nullptr) {
1150 new SelectCompanyLiveryWindow(&_select_company_livery_desc, company, group);
1151 } else if (group != INVALID_GROUP) {
1152 w->SetSelectedGroup(company, group);
1153 }
1154 }
1155
1162 void DrawCompanyManagerFace(CompanyManagerFace cmf, Colours colour, const Rect &r)
1163 {
1164 GenderEthnicity ge = (GenderEthnicity)GetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN, GE_WM);
1165
1166 /* Determine offset from centre of drawing rect. */
1167 Dimension d = GetSpriteSize(SPR_GRADIENT);
1168 int x = CenterBounds(r.left, r.right, d.width);
1169 int y = CenterBounds(r.top, r.bottom, d.height);
1170
1171 bool has_moustache = !HasBit(ge, GENDER_FEMALE) && GetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge) != 0;
1172 bool has_tie_earring = !HasBit(ge, GENDER_FEMALE) || GetCompanyManagerFaceBits(cmf, CMFV_HAS_TIE_EARRING, ge) != 0;
1173 bool has_glasses = GetCompanyManagerFaceBits(cmf, CMFV_HAS_GLASSES, ge) != 0;
1174 PaletteID pal;
1175
1176 /* Modify eye colour palette only if 2 or more valid values exist */
1177 if (_cmf_info[CMFV_EYE_COLOUR].valid_values[ge] < 2) {
1178 pal = PAL_NONE;
1179 } else {
1180 switch (GetCompanyManagerFaceBits(cmf, CMFV_EYE_COLOUR, ge)) {
1181 default: NOT_REACHED();
1182 case 0: pal = PALETTE_TO_BROWN; break;
1183 case 1: pal = PALETTE_TO_BLUE; break;
1184 case 2: pal = PALETTE_TO_GREEN; break;
1185 }
1186 }
1187
1188 /* Draw the gradient (background) */
1189 DrawSprite(SPR_GRADIENT, GENERAL_SPRITE_COLOUR(colour), x, y);
1190
1191 for (CompanyManagerFaceVariable cmfv = CMFV_CHEEKS; cmfv < CMFV_END; cmfv++) {
1192 switch (cmfv) {
1193 case CMFV_MOUSTACHE: if (!has_moustache) continue; break;
1194 case CMFV_LIPS:
1195 case CMFV_NOSE: if (has_moustache) continue; break;
1196 case CMFV_TIE_EARRING: if (!has_tie_earring) continue; break;
1197 case CMFV_GLASSES: if (!has_glasses) continue; break;
1198 default: break;
1199 }
1200 DrawSprite(GetCompanyManagerFaceSprite(cmf, cmfv, ge), (cmfv == CMFV_EYEBROWS) ? pal : PAL_NONE, x, y);
1201 }
1202 }
1203
1205 static constexpr NWidgetPart _nested_select_company_manager_face_widgets[] = {
1206 NWidget(NWID_HORIZONTAL),
1207 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1208 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SCMF_CAPTION), SetDataTip(STR_FACE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1209 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCMF_TOGGLE_LARGE_SMALL), SetDataTip(SPR_LARGE_SMALL_WINDOW, STR_FACE_ADVANCED_TOOLTIP),
1210 EndContainer(),
1211 NWidget(WWT_PANEL, COLOUR_GREY, WID_SCMF_SELECT_FACE),
1212 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), SetPadding(2),
1213 /* Left side */
1214 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1215 NWidget(NWID_HORIZONTAL), SetPIPRatio(1, 0, 1),
1216 NWidget(WWT_EMPTY, COLOUR_GREY, WID_SCMF_FACE), SetMinimalSize(92, 119), SetFill(1, 0),
1217 EndContainer(),
1218 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_RANDOM_NEW_FACE), SetFill(1, 0), SetDataTip(STR_FACE_NEW_FACE_BUTTON, STR_FACE_NEW_FACE_TOOLTIP),
1219 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCMF_SEL_LOADSAVE), // Load/number/save buttons under the portrait in the advanced view.
1220 NWidget(NWID_VERTICAL), SetPIP(0, 0, 0), SetPIPRatio(1, 0, 1),
1221 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_LOAD), SetFill(1, 0), SetDataTip(STR_FACE_LOAD, STR_FACE_LOAD_TOOLTIP),
1222 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_FACECODE), SetFill(1, 0), SetDataTip(STR_FACE_FACECODE, STR_FACE_FACECODE_TOOLTIP),
1223 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_SAVE), SetFill(1, 0), SetDataTip(STR_FACE_SAVE, STR_FACE_SAVE_TOOLTIP),
1224 EndContainer(),
1225 EndContainer(),
1226 EndContainer(),
1227 /* Right side */
1228 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1229 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON), SetFill(1, 0), SetDataTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP),
1230 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCMF_SEL_MALEFEMALE), // Simple male/female face setting.
1231 NWidget(NWID_VERTICAL), SetPIPRatio(1, 0, 1),
1232 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCMF_MALE), SetFill(1, 0), SetDataTip(STR_FACE_MALE_BUTTON, STR_FACE_MALE_TOOLTIP),
1233 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCMF_FEMALE), SetFill(1, 0), SetDataTip(STR_FACE_FEMALE_BUTTON, STR_FACE_FEMALE_TOOLTIP),
1234 EndContainer(),
1235 EndContainer(),
1236 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCMF_SEL_PARTS), // Advanced face parts setting.
1237 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1238 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1239 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCMF_MALE2), SetFill(1, 0), SetDataTip(STR_FACE_MALE_BUTTON, STR_FACE_MALE_TOOLTIP),
1240 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCMF_FEMALE2), SetFill(1, 0), SetDataTip(STR_FACE_FEMALE_BUTTON, STR_FACE_FEMALE_TOOLTIP),
1241 EndContainer(),
1242 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1243 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCMF_ETHNICITY_EUR), SetFill(1, 0), SetDataTip(STR_FACE_EUROPEAN, STR_FACE_SELECT_EUROPEAN),
1244 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCMF_ETHNICITY_AFR), SetFill(1, 0), SetDataTip(STR_FACE_AFRICAN, STR_FACE_SELECT_AFRICAN),
1245 EndContainer(),
1246 NWidget(NWID_VERTICAL),
1247 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1248 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT), SetFill(1, 0),
1249 SetDataTip(STR_FACE_EYECOLOUR, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1250 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_HAS_MOUSTACHE_EARRING), SetDataTip(STR_JUST_STRING1, STR_FACE_MOUSTACHE_EARRING_TOOLTIP), SetTextStyle(TC_WHITE),
1251 EndContainer(),
1252 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1253 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_HAS_GLASSES_TEXT), SetFill(1, 0),
1254 SetDataTip(STR_FACE_GLASSES, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1255 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_HAS_GLASSES), SetDataTip(STR_JUST_STRING1, STR_FACE_GLASSES_TOOLTIP), SetTextStyle(TC_WHITE),
1256 EndContainer(),
1257 EndContainer(),
1258 NWidget(NWID_VERTICAL),
1259 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1260 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_HAIR_TEXT), SetFill(1, 0),
1261 SetDataTip(STR_FACE_HAIR, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1262 NWidget(NWID_HORIZONTAL),
1263 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_HAIR_L), SetDataTip(AWV_DECREASE, STR_FACE_HAIR_TOOLTIP),
1264 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_HAIR), SetDataTip(STR_JUST_STRING1, STR_FACE_HAIR_TOOLTIP), SetTextStyle(TC_WHITE),
1265 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_HAIR_R), SetDataTip(AWV_INCREASE, STR_FACE_HAIR_TOOLTIP),
1266 EndContainer(),
1267 EndContainer(),
1268 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1269 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_EYEBROWS_TEXT), SetFill(1, 0),
1270 SetDataTip(STR_FACE_EYEBROWS, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1271 NWidget(NWID_HORIZONTAL),
1272 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_EYEBROWS_L), SetDataTip(AWV_DECREASE, STR_FACE_EYEBROWS_TOOLTIP),
1273 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_EYEBROWS), SetDataTip(STR_JUST_STRING1, STR_FACE_EYEBROWS_TOOLTIP), SetTextStyle(TC_WHITE),
1274 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_EYEBROWS_R), SetDataTip(AWV_INCREASE, STR_FACE_EYEBROWS_TOOLTIP),
1275 EndContainer(),
1276 EndContainer(),
1277 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1278 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_EYECOLOUR_TEXT), SetFill(1, 0),
1279 SetDataTip(STR_FACE_EYECOLOUR, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1280 NWidget(NWID_HORIZONTAL),
1281 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_EYECOLOUR_L), SetDataTip(AWV_DECREASE, STR_FACE_EYECOLOUR_TOOLTIP),
1282 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_EYECOLOUR), SetDataTip(STR_JUST_STRING1, STR_FACE_EYECOLOUR_TOOLTIP), SetTextStyle(TC_WHITE),
1283 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_EYECOLOUR_R), SetDataTip(AWV_INCREASE, STR_FACE_EYECOLOUR_TOOLTIP),
1284 EndContainer(),
1285 EndContainer(),
1286 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1287 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_GLASSES_TEXT), SetFill(1, 0),
1288 SetDataTip(STR_FACE_GLASSES, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1289 NWidget(NWID_HORIZONTAL),
1290 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_GLASSES_L), SetDataTip(AWV_DECREASE, STR_FACE_GLASSES_TOOLTIP_2),
1291 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_GLASSES), SetDataTip(STR_JUST_STRING1, STR_FACE_GLASSES_TOOLTIP_2), SetTextStyle(TC_WHITE),
1292 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_GLASSES_R), SetDataTip(AWV_INCREASE, STR_FACE_GLASSES_TOOLTIP_2),
1293 EndContainer(),
1294 EndContainer(),
1295 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1296 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_NOSE_TEXT), SetFill(1, 0),
1297 SetDataTip(STR_FACE_NOSE, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1298 NWidget(NWID_HORIZONTAL),
1299 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_NOSE_L), SetDataTip(AWV_DECREASE, STR_FACE_NOSE_TOOLTIP),
1300 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_NOSE), SetDataTip(STR_JUST_STRING1, STR_FACE_NOSE_TOOLTIP), SetTextStyle(TC_WHITE),
1301 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_NOSE_R), SetDataTip(AWV_INCREASE, STR_FACE_NOSE_TOOLTIP),
1302 EndContainer(),
1303 EndContainer(),
1304 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1305 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_LIPS_MOUSTACHE_TEXT), SetFill(1, 0),
1306 SetDataTip(STR_FACE_MOUSTACHE, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1307 NWidget(NWID_HORIZONTAL),
1308 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_LIPS_MOUSTACHE_L), SetDataTip(AWV_DECREASE, STR_FACE_LIPS_MOUSTACHE_TOOLTIP),
1309 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_LIPS_MOUSTACHE), SetDataTip(STR_JUST_STRING1, STR_FACE_LIPS_MOUSTACHE_TOOLTIP), SetTextStyle(TC_WHITE),
1310 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_LIPS_MOUSTACHE_R), SetDataTip(AWV_INCREASE, STR_FACE_LIPS_MOUSTACHE_TOOLTIP),
1311 EndContainer(),
1312 EndContainer(),
1313 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1314 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_CHIN_TEXT), SetFill(1, 0),
1315 SetDataTip(STR_FACE_CHIN, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1316 NWidget(NWID_HORIZONTAL),
1317 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_CHIN_L), SetDataTip(AWV_DECREASE, STR_FACE_CHIN_TOOLTIP),
1318 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_CHIN), SetDataTip(STR_JUST_STRING1, STR_FACE_CHIN_TOOLTIP), SetTextStyle(TC_WHITE),
1319 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_CHIN_R), SetDataTip(AWV_INCREASE, STR_FACE_CHIN_TOOLTIP),
1320 EndContainer(),
1321 EndContainer(),
1322 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1323 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_JACKET_TEXT), SetFill(1, 0),
1324 SetDataTip(STR_FACE_JACKET, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1325 NWidget(NWID_HORIZONTAL),
1326 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_JACKET_L), SetDataTip(AWV_DECREASE, STR_FACE_JACKET_TOOLTIP),
1327 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_JACKET), SetDataTip(STR_JUST_STRING1, STR_FACE_JACKET_TOOLTIP), SetTextStyle(TC_WHITE),
1328 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_JACKET_R), SetDataTip(AWV_INCREASE, STR_FACE_JACKET_TOOLTIP),
1329 EndContainer(),
1330 EndContainer(),
1331 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1332 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_COLLAR_TEXT), SetFill(1, 0),
1333 SetDataTip(STR_FACE_COLLAR, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1334 NWidget(NWID_HORIZONTAL),
1335 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_COLLAR_L), SetDataTip(AWV_DECREASE, STR_FACE_COLLAR_TOOLTIP),
1336 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_COLLAR), SetDataTip(STR_JUST_STRING1, STR_FACE_COLLAR_TOOLTIP), SetTextStyle(TC_WHITE),
1337 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_COLLAR_R), SetDataTip(AWV_INCREASE, STR_FACE_COLLAR_TOOLTIP),
1338 EndContainer(),
1339 EndContainer(),
1340 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1341 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_TIE_EARRING_TEXT), SetFill(1, 0),
1342 SetDataTip(STR_FACE_EARRING, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1343 NWidget(NWID_HORIZONTAL),
1344 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_TIE_EARRING_L), SetDataTip(AWV_DECREASE, STR_FACE_TIE_EARRING_TOOLTIP),
1345 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_TIE_EARRING), SetDataTip(STR_JUST_STRING1, STR_FACE_TIE_EARRING_TOOLTIP), SetTextStyle(TC_WHITE),
1346 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_TIE_EARRING_R), SetDataTip(AWV_INCREASE, STR_FACE_TIE_EARRING_TOOLTIP),
1347 EndContainer(),
1348 EndContainer(),
1349 EndContainer(),
1350 EndContainer(),
1351 EndContainer(),
1352 EndContainer(),
1353 EndContainer(),
1354 EndContainer(),
1355 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1356 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_CANCEL), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL, STR_FACE_CANCEL_TOOLTIP),
1357 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_ACCEPT), SetFill(1, 0), SetDataTip(STR_BUTTON_OK, STR_FACE_OK_TOOLTIP),
1358 EndContainer(),
1359 };
1360
1362 class SelectCompanyManagerFaceWindow : public Window
1363 {
1364 CompanyManagerFace face;
1365 bool advanced;
1366
1367 GenderEthnicity ge;
1368 bool is_female;
1369 bool is_moust_male;
1370
1371 Dimension yesno_dim;
1372 Dimension number_dim;
1373
1381 void SetFaceStringParameters(WidgetID widget_index, uint8_t val, bool is_bool_widget) const
1382 {
1383 const NWidgetCore *nwi_widget = this->GetWidget<NWidgetCore>(widget_index);
1384 if (nwi_widget->IsDisabled()) {
1385 SetDParam(0, STR_EMPTY);
1386 } else {
1387 if (is_bool_widget) {
1388 /* if it a bool button write yes or no */
1389 SetDParam(0, (val != 0) ? STR_FACE_YES : STR_FACE_NO);
1390 } else {
1391 /* else write the value + 1 */
1392 SetDParam(0, STR_JUST_INT);
1393 SetDParam(1, val + 1);
1394 }
1395 }
1396 }
1397
1398 void UpdateData()
1399 {
1400 this->ge = (GenderEthnicity)GB(this->face, _cmf_info[CMFV_GEN_ETHN].offset, _cmf_info[CMFV_GEN_ETHN].length); // get the gender and ethnicity
1401 this->is_female = HasBit(this->ge, GENDER_FEMALE); // get the gender: 0 == male and 1 == female
1402 this->is_moust_male = !is_female && GetCompanyManagerFaceBits(this->face, CMFV_HAS_MOUSTACHE, this->ge) != 0; // is a male face with moustache
1403
1404 this->GetWidget<NWidgetCore>(WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT)->widget_data = this->is_female ? STR_FACE_EARRING : STR_FACE_MOUSTACHE;
1405 this->GetWidget<NWidgetCore>(WID_SCMF_TIE_EARRING_TEXT)->widget_data = this->is_female ? STR_FACE_EARRING : STR_FACE_TIE;
1406 this->GetWidget<NWidgetCore>(WID_SCMF_LIPS_MOUSTACHE_TEXT)->widget_data = this->is_moust_male ? STR_FACE_MOUSTACHE : STR_FACE_LIPS;
1407 }
1408
1409 public:
1410 SelectCompanyManagerFaceWindow(WindowDesc *desc, Window *parent) : Window(desc)
1411 {
1412 this->advanced = false;
1413 this->CreateNestedTree();
1414 this->SelectDisplayPlanes(this->advanced);
1415 this->FinishInitNested(parent->window_number);
1416 this->parent = parent;
1417 this->owner = (Owner)this->window_number;
1418 this->face = Company::Get((CompanyID)this->window_number)->face;
1419
1420 this->UpdateData();
1421 }
1422
1427 void SelectDisplayPlanes(bool advanced)
1428 {
1429 this->GetWidget<NWidgetStacked>(WID_SCMF_SEL_LOADSAVE)->SetDisplayedPlane(advanced ? 0 : SZSP_NONE);
1430 this->GetWidget<NWidgetStacked>(WID_SCMF_SEL_PARTS)->SetDisplayedPlane(advanced ? 0 : SZSP_NONE);
1431 this->GetWidget<NWidgetStacked>(WID_SCMF_SEL_MALEFEMALE)->SetDisplayedPlane(advanced ? SZSP_NONE : 0);
1432 this->GetWidget<NWidgetCore>(WID_SCMF_RANDOM_NEW_FACE)->widget_data = advanced ? STR_FACE_RANDOM : STR_FACE_NEW_FACE_BUTTON;
1433
1434 NWidgetCore *wi = this->GetWidget<NWidgetCore>(WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON);
1435 if (advanced) {
1436 wi->SetDataTip(STR_FACE_SIMPLE, STR_FACE_SIMPLE_TOOLTIP);
1437 } else {
1438 wi->SetDataTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP);
1439 }
1440 }
1441
1442 void OnInit() override
1443 {
1444 /* Size of the boolean yes/no button. */
1445 Dimension yesno_dim = maxdim(GetStringBoundingBox(STR_FACE_YES), GetStringBoundingBox(STR_FACE_NO));
1446 yesno_dim.width += WidgetDimensions::scaled.framerect.Horizontal();
1447 yesno_dim.height += WidgetDimensions::scaled.framerect.Vertical();
1448 /* Size of the number button + arrows. */
1449 Dimension number_dim = {0, 0};
1450 for (int val = 1; val <= 12; val++) {
1451 SetDParam(0, val);
1452 number_dim = maxdim(number_dim, GetStringBoundingBox(STR_JUST_INT));
1453 }
1454 uint arrows_width = GetSpriteSize(SPR_ARROW_LEFT).width + GetSpriteSize(SPR_ARROW_RIGHT).width + 2 * (WidgetDimensions::scaled.imgbtn.Horizontal());
1455 number_dim.width += WidgetDimensions::scaled.framerect.Horizontal() + arrows_width;
1456 number_dim.height += WidgetDimensions::scaled.framerect.Vertical();
1457 /* Compute width of both buttons. */
1458 yesno_dim.width = std::max(yesno_dim.width, number_dim.width);
1459 number_dim.width = yesno_dim.width - arrows_width;
1460
1461 this->yesno_dim = yesno_dim;
1462 this->number_dim = number_dim;
1463 }
1464
1465 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
1466 {
1467 switch (widget) {
1468 case WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT:
1469 *size = maxdim(*size, GetStringBoundingBox(STR_FACE_EARRING));
1470 *size = maxdim(*size, GetStringBoundingBox(STR_FACE_MOUSTACHE));
1471 break;
1472
1473 case WID_SCMF_TIE_EARRING_TEXT:
1474 *size = maxdim(*size, GetStringBoundingBox(STR_FACE_EARRING));
1475 *size = maxdim(*size, GetStringBoundingBox(STR_FACE_TIE));
1476 break;
1477
1478 case WID_SCMF_LIPS_MOUSTACHE_TEXT:
1479 *size = maxdim(*size, GetStringBoundingBox(STR_FACE_LIPS));
1480 *size = maxdim(*size, GetStringBoundingBox(STR_FACE_MOUSTACHE));
1481 break;
1482
1483 case WID_SCMF_FACE:
1484 *size = maxdim(*size, GetScaledSpriteSize(SPR_GRADIENT));
1485 break;
1486
1487 case WID_SCMF_HAS_MOUSTACHE_EARRING:
1488 case WID_SCMF_HAS_GLASSES:
1489 *size = this->yesno_dim;
1490 break;
1491
1492 case WID_SCMF_EYECOLOUR:
1493 case WID_SCMF_CHIN:
1494 case WID_SCMF_EYEBROWS:
1495 case WID_SCMF_LIPS_MOUSTACHE:
1496 case WID_SCMF_NOSE:
1497 case WID_SCMF_HAIR:
1498 case WID_SCMF_JACKET:
1499 case WID_SCMF_COLLAR:
1500 case WID_SCMF_TIE_EARRING:
1501 case WID_SCMF_GLASSES:
1502 *size = this->number_dim;
1503 break;
1504 }
1505 }
1506
1507 void OnPaint() override
1508 {
1509 /* lower the non-selected gender button */
1510 this->SetWidgetsLoweredState(!this->is_female, WID_SCMF_MALE, WID_SCMF_MALE2);
1511 this->SetWidgetsLoweredState( this->is_female, WID_SCMF_FEMALE, WID_SCMF_FEMALE2);
1512
1513 /* advanced company manager face selection window */
1514
1515 /* lower the non-selected ethnicity button */
1516 this->SetWidgetLoweredState(WID_SCMF_ETHNICITY_EUR, !HasBit(this->ge, ETHNICITY_BLACK));
1517 this->SetWidgetLoweredState(WID_SCMF_ETHNICITY_AFR, HasBit(this->ge, ETHNICITY_BLACK));
1518
1519
1520 /* Disable dynamically the widgets which CompanyManagerFaceVariable has less than 2 options
1521 * (or in other words you haven't any choice).
1522 * If the widgets depend on a HAS-variable and this is false the widgets will be disabled, too. */
1523
1524 /* Eye colour buttons */
1525 this->SetWidgetsDisabledState(_cmf_info[CMFV_EYE_COLOUR].valid_values[this->ge] < 2,
1526 WID_SCMF_EYECOLOUR, WID_SCMF_EYECOLOUR_L, WID_SCMF_EYECOLOUR_R);
1527
1528 /* Chin buttons */
1529 this->SetWidgetsDisabledState(_cmf_info[CMFV_CHIN].valid_values[this->ge] < 2,
1530 WID_SCMF_CHIN, WID_SCMF_CHIN_L, WID_SCMF_CHIN_R);
1531
1532 /* Eyebrows buttons */
1533 this->SetWidgetsDisabledState(_cmf_info[CMFV_EYEBROWS].valid_values[this->ge] < 2,
1534 WID_SCMF_EYEBROWS, WID_SCMF_EYEBROWS_L, WID_SCMF_EYEBROWS_R);
1535
1536 /* Lips or (if it a male face with a moustache) moustache buttons */
1537 this->SetWidgetsDisabledState(_cmf_info[this->is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS].valid_values[this->ge] < 2,
1538 WID_SCMF_LIPS_MOUSTACHE, WID_SCMF_LIPS_MOUSTACHE_L, WID_SCMF_LIPS_MOUSTACHE_R);
1539
1540 /* Nose buttons | male faces with moustache haven't any nose options */
1541 this->SetWidgetsDisabledState(_cmf_info[CMFV_NOSE].valid_values[this->ge] < 2 || this->is_moust_male,
1542 WID_SCMF_NOSE, WID_SCMF_NOSE_L, WID_SCMF_NOSE_R);
1543
1544 /* Hair buttons */
1545 this->SetWidgetsDisabledState(_cmf_info[CMFV_HAIR].valid_values[this->ge] < 2,
1546 WID_SCMF_HAIR, WID_SCMF_HAIR_L, WID_SCMF_HAIR_R);
1547
1548 /* Jacket buttons */
1549 this->SetWidgetsDisabledState(_cmf_info[CMFV_JACKET].valid_values[this->ge] < 2,
1550 WID_SCMF_JACKET, WID_SCMF_JACKET_L, WID_SCMF_JACKET_R);
1551
1552 /* Collar buttons */
1553 this->SetWidgetsDisabledState(_cmf_info[CMFV_COLLAR].valid_values[this->ge] < 2,
1554 WID_SCMF_COLLAR, WID_SCMF_COLLAR_L, WID_SCMF_COLLAR_R);
1555
1556 /* Tie/earring buttons | female faces without earring haven't any earring options */
1557 this->SetWidgetsDisabledState(_cmf_info[CMFV_TIE_EARRING].valid_values[this->ge] < 2 ||
1558 (this->is_female && GetCompanyManagerFaceBits(this->face, CMFV_HAS_TIE_EARRING, this->ge) == 0),
1559 WID_SCMF_TIE_EARRING, WID_SCMF_TIE_EARRING_L, WID_SCMF_TIE_EARRING_R);
1560
1561 /* Glasses buttons | faces without glasses haven't any glasses options */
1562 this->SetWidgetsDisabledState(_cmf_info[CMFV_GLASSES].valid_values[this->ge] < 2 || GetCompanyManagerFaceBits(this->face, CMFV_HAS_GLASSES, this->ge) == 0,
1563 WID_SCMF_GLASSES, WID_SCMF_GLASSES_L, WID_SCMF_GLASSES_R);
1564
1565 this->DrawWidgets();
1566 }
1567
1568 void SetStringParameters(WidgetID widget) const override
1569 {
1570 switch (widget) {
1571 case WID_SCMF_HAS_MOUSTACHE_EARRING:
1572 if (this->is_female) { // Only for female faces
1573 this->SetFaceStringParameters(WID_SCMF_HAS_MOUSTACHE_EARRING, GetCompanyManagerFaceBits(this->face, CMFV_HAS_TIE_EARRING, this->ge), true);
1574 } else { // Only for male faces
1575 this->SetFaceStringParameters(WID_SCMF_HAS_MOUSTACHE_EARRING, GetCompanyManagerFaceBits(this->face, CMFV_HAS_MOUSTACHE, this->ge), true);
1576 }
1577 break;
1578
1579 case WID_SCMF_TIE_EARRING:
1580 this->SetFaceStringParameters(WID_SCMF_TIE_EARRING, GetCompanyManagerFaceBits(this->face, CMFV_TIE_EARRING, this->ge), false);
1581 break;
1582
1583 case WID_SCMF_LIPS_MOUSTACHE:
1584 if (this->is_moust_male) { // Only for male faces with moustache
1585 this->SetFaceStringParameters(WID_SCMF_LIPS_MOUSTACHE, GetCompanyManagerFaceBits(this->face, CMFV_MOUSTACHE, this->ge), false);
1586 } else { // Only for female faces or male faces without moustache
1587 this->SetFaceStringParameters(WID_SCMF_LIPS_MOUSTACHE, GetCompanyManagerFaceBits(this->face, CMFV_LIPS, this->ge), false);
1588 }
1589 break;
1590
1591 case WID_SCMF_HAS_GLASSES:
1592 this->SetFaceStringParameters(WID_SCMF_HAS_GLASSES, GetCompanyManagerFaceBits(this->face, CMFV_HAS_GLASSES, this->ge), true );
1593 break;
1594
1595 case WID_SCMF_HAIR:
1596 this->SetFaceStringParameters(WID_SCMF_HAIR, GetCompanyManagerFaceBits(this->face, CMFV_HAIR, this->ge), false);
1597 break;
1598
1599 case WID_SCMF_EYEBROWS:
1600 this->SetFaceStringParameters(WID_SCMF_EYEBROWS, GetCompanyManagerFaceBits(this->face, CMFV_EYEBROWS, this->ge), false);
1601 break;
1602
1603 case WID_SCMF_EYECOLOUR:
1604 this->SetFaceStringParameters(WID_SCMF_EYECOLOUR, GetCompanyManagerFaceBits(this->face, CMFV_EYE_COLOUR, this->ge), false);
1605 break;
1606
1607 case WID_SCMF_GLASSES:
1608 this->SetFaceStringParameters(WID_SCMF_GLASSES, GetCompanyManagerFaceBits(this->face, CMFV_GLASSES, this->ge), false);
1609 break;
1610
1611 case WID_SCMF_NOSE:
1612 this->SetFaceStringParameters(WID_SCMF_NOSE, GetCompanyManagerFaceBits(this->face, CMFV_NOSE, this->ge), false);
1613 break;
1614
1615 case WID_SCMF_CHIN:
1616 this->SetFaceStringParameters(WID_SCMF_CHIN, GetCompanyManagerFaceBits(this->face, CMFV_CHIN, this->ge), false);
1617 break;
1618
1619 case WID_SCMF_JACKET:
1620 this->SetFaceStringParameters(WID_SCMF_JACKET, GetCompanyManagerFaceBits(this->face, CMFV_JACKET, this->ge), false);
1621 break;
1622
1623 case WID_SCMF_COLLAR:
1624 this->SetFaceStringParameters(WID_SCMF_COLLAR, GetCompanyManagerFaceBits(this->face, CMFV_COLLAR, this->ge), false);
1625 break;
1626 }
1627 }
1628
1629 void DrawWidget(const Rect &r, WidgetID widget) const override
1630 {
1631 switch (widget) {
1632 case WID_SCMF_FACE:
1633 DrawCompanyManagerFace(this->face, Company::Get((CompanyID)this->window_number)->colour, r);
1634 break;
1635 }
1636 }
1637
1638 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1639 {
1640 switch (widget) {
1641 /* Toggle size, advanced/simple face selection */
1642 case WID_SCMF_TOGGLE_LARGE_SMALL:
1643 case WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON:
1644 this->advanced = !this->advanced;
1645 this->SelectDisplayPlanes(this->advanced);
1646 this->ReInit();
1647 break;
1648
1649 /* OK button */
1650 case WID_SCMF_ACCEPT:
1651 Command<CMD_SET_COMPANY_MANAGER_FACE>::Post(this->face);
1652 [[fallthrough]];
1653
1654 /* Cancel button */
1655 case WID_SCMF_CANCEL:
1656 this->Close();
1657 break;
1658
1659 /* Load button */
1660 case WID_SCMF_LOAD:
1661 this->face = _company_manager_face;
1662 ScaleAllCompanyManagerFaceBits(this->face);
1663 ShowErrorMessage(STR_FACE_LOAD_DONE, INVALID_STRING_ID, WL_INFO);
1664 this->UpdateData();
1665 this->SetDirty();
1666 break;
1667
1668 /* 'Company manager face number' button, view and/or set company manager face number */
1669 case WID_SCMF_FACECODE:
1670 SetDParam(0, this->face);
1671 ShowQueryString(STR_JUST_INT, STR_FACE_FACECODE_CAPTION, 10 + 1, this, CS_NUMERAL, QSF_NONE);
1672 break;
1673
1674 /* Save button */
1675 case WID_SCMF_SAVE:
1676 _company_manager_face = this->face;
1677 ShowErrorMessage(STR_FACE_SAVE_DONE, INVALID_STRING_ID, WL_INFO);
1678 break;
1679
1680 /* Toggle gender (male/female) button */
1681 case WID_SCMF_MALE:
1682 case WID_SCMF_FEMALE:
1683 case WID_SCMF_MALE2:
1684 case WID_SCMF_FEMALE2:
1685 SetCompanyManagerFaceBits(this->face, CMFV_GENDER, this->ge, (widget == WID_SCMF_FEMALE || widget == WID_SCMF_FEMALE2));
1686 ScaleAllCompanyManagerFaceBits(this->face);
1687 this->UpdateData();
1688 this->SetDirty();
1689 break;
1690
1691 /* Randomize face button */
1692 case WID_SCMF_RANDOM_NEW_FACE:
1693 RandomCompanyManagerFaceBits(this->face, this->ge, this->advanced, _interactive_random);
1694 this->UpdateData();
1695 this->SetDirty();
1696 break;
1697
1698 /* Toggle ethnicity (european/african) button */
1699 case WID_SCMF_ETHNICITY_EUR:
1700 case WID_SCMF_ETHNICITY_AFR:
1701 SetCompanyManagerFaceBits(this->face, CMFV_ETHNICITY, this->ge, widget - WID_SCMF_ETHNICITY_EUR);
1702 ScaleAllCompanyManagerFaceBits(this->face);
1703 this->UpdateData();
1704 this->SetDirty();
1705 break;
1706
1707 default:
1708 /* Here all buttons from WID_SCMF_HAS_MOUSTACHE_EARRING to WID_SCMF_GLASSES_R are handled.
1709 * First it checks which CompanyManagerFaceVariable is being changed, and then either
1710 * a: invert the value for boolean variables, or
1711 * b: it checks inside of IncreaseCompanyManagerFaceBits() if a left (_L) butten is pressed and then decrease else increase the variable */
1712 if (widget >= WID_SCMF_HAS_MOUSTACHE_EARRING && widget <= WID_SCMF_GLASSES_R) {
1713 CompanyManagerFaceVariable cmfv; // which CompanyManagerFaceVariable shall be edited
1714
1715 if (widget < WID_SCMF_EYECOLOUR_L) { // Bool buttons
1716 switch (widget - WID_SCMF_HAS_MOUSTACHE_EARRING) {
1717 default: NOT_REACHED();
1718 case 0: cmfv = this->is_female ? CMFV_HAS_TIE_EARRING : CMFV_HAS_MOUSTACHE; break; // Has earring/moustache button
1719 case 1: cmfv = CMFV_HAS_GLASSES; break; // Has glasses button
1720 }
1721 SetCompanyManagerFaceBits(this->face, cmfv, this->ge, !GetCompanyManagerFaceBits(this->face, cmfv, this->ge));
1722 ScaleAllCompanyManagerFaceBits(this->face);
1723 } else { // Value buttons
1724 switch ((widget - WID_SCMF_EYECOLOUR_L) / 3) {
1725 default: NOT_REACHED();
1726 case 0: cmfv = CMFV_EYE_COLOUR; break; // Eye colour buttons
1727 case 1: cmfv = CMFV_CHIN; break; // Chin buttons
1728 case 2: cmfv = CMFV_EYEBROWS; break; // Eyebrows buttons
1729 case 3: cmfv = this->is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS; break; // Moustache or lips buttons
1730 case 4: cmfv = CMFV_NOSE; break; // Nose buttons
1731 case 5: cmfv = CMFV_HAIR; break; // Hair buttons
1732 case 6: cmfv = CMFV_JACKET; break; // Jacket buttons
1733 case 7: cmfv = CMFV_COLLAR; break; // Collar buttons
1734 case 8: cmfv = CMFV_TIE_EARRING; break; // Tie/earring buttons
1735 case 9: cmfv = CMFV_GLASSES; break; // Glasses buttons
1736 }
1737 /* 0 == left (_L), 1 == middle or 2 == right (_R) - button click */
1738 IncreaseCompanyManagerFaceBits(this->face, cmfv, this->ge, (((widget - WID_SCMF_EYECOLOUR_L) % 3) != 0) ? 1 : -1);
1739 }
1740 this->UpdateData();
1741 this->SetDirty();
1742 }
1743 break;
1744 }
1745 }
1746
1747 void OnQueryTextFinished(char *str) override
1748 {
1749 if (str == nullptr) return;
1750 /* Set a new company manager face number */
1751 if (!StrEmpty(str)) {
1752 this->face = std::strtoul(str, nullptr, 10);
1753 ScaleAllCompanyManagerFaceBits(this->face);
1754 ShowErrorMessage(STR_FACE_FACECODE_SET, INVALID_STRING_ID, WL_INFO);
1755 this->UpdateData();
1756 this->SetDirty();
1757 } else {
1758 ShowErrorMessage(STR_FACE_FACECODE_ERR, INVALID_STRING_ID, WL_INFO);
1759 }
1760 }
1761 };
1762
1764 static WindowDesc _select_company_manager_face_desc(__FILE__, __LINE__,
1765 WDP_AUTO, nullptr, 0, 0,
1766 WC_COMPANY_MANAGER_FACE, WC_NONE,
1767 WDF_CONSTRUCTION,
1768 std::begin(_nested_select_company_manager_face_widgets), std::end(_nested_select_company_manager_face_widgets)
1769 );
1770
1776 static void DoSelectCompanyManagerFace(Window *parent)
1777 {
1778 if (!Company::IsValidID((CompanyID)parent->window_number)) return;
1779
1780 if (BringWindowToFrontById(WC_COMPANY_MANAGER_FACE, parent->window_number)) return;
1781 new SelectCompanyManagerFaceWindow(&_select_company_manager_face_desc, parent);
1782 }
1783
1784 static constexpr NWidgetPart _nested_company_infrastructure_widgets[] = {
1785 NWidget(NWID_HORIZONTAL),
1786 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1787 NWidget(WWT_CAPTION, COLOUR_GREY, WID_CI_CAPTION), SetDataTip(STR_COMPANY_INFRASTRUCTURE_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1788 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1789 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1790 EndContainer(),
1791 NWidget(WWT_PANEL, COLOUR_GREY),
1792 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.framerect), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1793 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1794 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_RAIL_DESC), SetMinimalTextLines(2, 0), SetFill(1, 0),
1795 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_RAIL_COUNT), SetMinimalTextLines(2, 0), SetFill(0, 1),
1796 EndContainer(),
1797 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1798 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_ROAD_DESC), SetMinimalTextLines(2, 0), SetFill(1, 0),
1799 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_ROAD_COUNT), SetMinimalTextLines(2, 0), SetFill(0, 1),
1800 EndContainer(),
1801 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1802 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_TRAM_DESC), SetMinimalTextLines(2, 0), SetFill(1, 0),
1803 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_TRAM_COUNT), SetMinimalTextLines(2, 0), SetFill(0, 1),
1804 EndContainer(),
1805 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1806 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_WATER_DESC), SetMinimalTextLines(2, 0), SetFill(1, 0),
1807 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_WATER_COUNT), SetMinimalTextLines(2, 0), SetFill(0, 1),
1808 EndContainer(),
1809 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1810 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_STATION_DESC), SetMinimalTextLines(3, 0), SetFill(1, 0),
1811 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_STATION_COUNT), SetMinimalTextLines(3, 0), SetFill(0, 1),
1812 EndContainer(),
1813 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1814 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_TOTAL_DESC), SetFill(1, 0),
1815 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_TOTAL), SetFill(0, 1),
1816 EndContainer(),
1817 EndContainer(),
1818 EndContainer(),
1819 };
1820
1824 struct CompanyInfrastructureWindow : Window
1825 {
1826 RailTypes railtypes;
1827 RoadTypes roadtypes;
1828
1829 uint total_width;
1830
1831 CompanyInfrastructureWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
1832 {
1833 this->UpdateRailRoadTypes();
1834
1835 this->InitNested(window_number);
1836 this->owner = (Owner)this->window_number;
1837 }
1838
1839 void UpdateRailRoadTypes()
1840 {
1841 this->railtypes = RAILTYPES_NONE;
1842 this->roadtypes = ROADTYPES_NONE;
1843
1844 /* Find the used railtypes. */
1845 for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
1846 if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
1847
1848 this->railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
1849 }
1850
1851 /* Get the date introduced railtypes as well. */
1852 this->railtypes = AddDateIntroducedRailTypes(this->railtypes, CalendarTime::MAX_DATE);
1853
1854 /* Find the used roadtypes. */
1855 for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
1856 if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
1857
1858 this->roadtypes |= GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes;
1859 }
1860
1861 /* Get the date introduced roadtypes as well. */
1862 this->roadtypes = AddDateIntroducedRoadTypes(this->roadtypes, CalendarTime::MAX_DATE);
1863 this->roadtypes &= ~_roadtypes_hidden_mask;
1864 }
1865
1867 Money GetTotalMaintenanceCost() const
1868 {
1869 const Company *c = Company::Get((CompanyID)this->window_number);
1870 Money total;
1871
1872 uint32_t rail_total = c->infrastructure.GetRailTotal();
1873 for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
1874 if (HasBit(this->railtypes, rt)) total += RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total);
1875 }
1876 total += SignalMaintenanceCost(c->infrastructure.signal);
1877
1878 uint32_t road_total = c->infrastructure.GetRoadTotal();
1879 uint32_t tram_total = c->infrastructure.GetTramTotal();
1880 for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
1881 if (HasBit(this->roadtypes, rt)) total += RoadMaintenanceCost(rt, c->infrastructure.road[rt], RoadTypeIsRoad(rt) ? road_total : tram_total);
1882 }
1883
1884 total += CanalMaintenanceCost(c->infrastructure.water);
1885 total += StationMaintenanceCost(c->infrastructure.station);
1886 total += AirportMaintenanceCost(c->index);
1887
1888 return total;
1889 }
1890
1891 void SetStringParameters(WidgetID widget) const override
1892 {
1893 switch (widget) {
1894 case WID_CI_CAPTION:
1895 SetDParam(0, (CompanyID)this->window_number);
1896 break;
1897 }
1898 }
1899
1900 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
1901 {
1902 const Company *c = Company::Get((CompanyID)this->window_number);
1903
1904 switch (widget) {
1905 case WID_CI_RAIL_DESC: {
1906 uint lines = 1; // Starts at 1 because a line is also required for the section title
1907
1908 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT).width + padding.width);
1909
1910 for (const auto &rt : _sorted_railtypes) {
1911 if (HasBit(this->railtypes, rt)) {
1912 lines++;
1913 size->width = std::max(size->width, GetStringBoundingBox(GetRailTypeInfo(rt)->strings.name).width + padding.width + WidgetDimensions::scaled.hsep_indent);
1914 }
1915 }
1916 if (this->railtypes != RAILTYPES_NONE) {
1917 lines++;
1918 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS).width + padding.width + WidgetDimensions::scaled.hsep_indent);
1919 }
1920
1921 size->height = std::max(size->height, lines * GetCharacterHeight(FS_NORMAL));
1922 break;
1923 }
1924
1925 case WID_CI_ROAD_DESC:
1926 case WID_CI_TRAM_DESC: {
1927 uint lines = 1; // Starts at 1 because a line is also required for the section title
1928
1929 size->width = std::max(size->width, GetStringBoundingBox(widget == WID_CI_ROAD_DESC ? STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT : STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT).width + padding.width);
1930
1931 for (const auto &rt : _sorted_roadtypes) {
1932 if (HasBit(this->roadtypes, rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_DESC)) {
1933 lines++;
1934 size->width = std::max(size->width, GetStringBoundingBox(GetRoadTypeInfo(rt)->strings.name).width + padding.width + WidgetDimensions::scaled.hsep_indent);
1935 }
1936 }
1937
1938 size->height = std::max(size->height, lines * GetCharacterHeight(FS_NORMAL));
1939 break;
1940 }
1941
1942 case WID_CI_WATER_DESC:
1943 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT).width + padding.width);
1944 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS).width + padding.width + WidgetDimensions::scaled.hsep_indent);
1945 break;
1946
1947 case WID_CI_STATION_DESC:
1948 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT).width + padding.width);
1949 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS).width + padding.width + WidgetDimensions::scaled.hsep_indent);
1950 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS).width + padding.width + WidgetDimensions::scaled.hsep_indent);
1951 break;
1952
1953 case WID_CI_RAIL_COUNT:
1954 case WID_CI_ROAD_COUNT:
1955 case WID_CI_TRAM_COUNT:
1956 case WID_CI_WATER_COUNT:
1957 case WID_CI_STATION_COUNT:
1958 case WID_CI_TOTAL: {
1959 /* Find the maximum count that is displayed. */
1960 uint32_t max_val = 1000; // Some random number to reserve enough space.
1961 Money max_cost = 10000; // Some random number to reserve enough space.
1962 uint32_t rail_total = c->infrastructure.GetRailTotal();
1963 for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) {
1964 max_val = std::max(max_val, c->infrastructure.rail[rt]);
1965 max_cost = std::max(max_cost, RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total));
1966 }
1967 max_val = std::max(max_val, c->infrastructure.signal);
1968 max_cost = std::max(max_cost, SignalMaintenanceCost(c->infrastructure.signal));
1969 uint32_t road_total = c->infrastructure.GetRoadTotal();
1970 uint32_t tram_total = c->infrastructure.GetTramTotal();
1971 for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) {
1972 max_val = std::max(max_val, c->infrastructure.road[rt]);
1973 max_cost = std::max(max_cost, RoadMaintenanceCost(rt, c->infrastructure.road[rt], RoadTypeIsRoad(rt) ? road_total : tram_total));
1974
1975 }
1976 max_val = std::max(max_val, c->infrastructure.water);
1977 max_cost = std::max(max_cost, CanalMaintenanceCost(c->infrastructure.water));
1978 max_val = std::max(max_val, c->infrastructure.station);
1979 max_cost = std::max(max_cost, StationMaintenanceCost(c->infrastructure.station));
1980 max_val = std::max(max_val, c->infrastructure.airport);
1981 max_cost = std::max(max_cost, AirportMaintenanceCost(c->index));
1982
1983 SetDParamMaxValue(0, max_val);
1984 uint count_width = GetStringBoundingBox(STR_JUST_COMMA).width + WidgetDimensions::scaled.hsep_indent; // Reserve some wiggle room
1985
1986 if (_settings_game.economy.infrastructure_maintenance) {
1987 StringID str_total = TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR;
1988 SetDParamMaxValue(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
1989 this->total_width = GetStringBoundingBox(str_total).width + WidgetDimensions::scaled.hsep_indent * 2;
1990 size->width = std::max(size->width, this->total_width);
1991
1992 SetDParamMaxValue(0, max_cost * 12); // Convert to per year
1993 count_width += std::max(this->total_width, GetStringBoundingBox(str_total).width);
1994 }
1995
1996 size->width = std::max(size->width, count_width);
1997
1998 /* Set height of the total line. */
1999 if (widget == WID_CI_TOTAL) {
2000 size->height = _settings_game.economy.infrastructure_maintenance ? std::max<uint>(size->height, WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL)) : 0;
2001 }
2002 break;
2003 }
2004 }
2005 }
2006
2014 void DrawCountLine(const Rect &r, int &y, int count, Money monthly_cost) const
2015 {
2016 SetDParam(0, count);
2017 DrawString(r.left, r.right, y += GetCharacterHeight(FS_NORMAL), STR_JUST_COMMA, TC_WHITE, SA_RIGHT);
2018
2019 if (_settings_game.economy.infrastructure_maintenance) {
2020 SetDParam(0, monthly_cost * 12); // Convert to per year
2021 Rect tr = r.WithWidth(this->total_width, _current_text_dir == TD_RTL);
2022 DrawString(tr.left, tr.right, y,
2023 TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR,
2024 TC_FROMSTRING, SA_RIGHT);
2025 }
2026 }
2027
2028 void DrawWidget(const Rect &r, WidgetID widget) const override
2029 {
2030 const Company *c = Company::Get((CompanyID)this->window_number);
2031
2032 int y = r.top;
2033
2034 Rect ir = r.Indent(WidgetDimensions::scaled.hsep_indent, _current_text_dir == TD_RTL);
2035 switch (widget) {
2036 case WID_CI_RAIL_DESC:
2037 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT);
2038
2039 if (this->railtypes != RAILTYPES_NONE) {
2040 /* Draw name of each valid railtype. */
2041 for (const auto &rt : _sorted_railtypes) {
2042 if (HasBit(this->railtypes, rt)) {
2043 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), GetRailTypeInfo(rt)->strings.name, TC_WHITE);
2044 }
2045 }
2046 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS);
2047 } else {
2048 /* No valid railtype. */
2049 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
2050 }
2051
2052 break;
2053
2054 case WID_CI_RAIL_COUNT: {
2055 /* Draw infrastructure count for each valid railtype. */
2056 uint32_t rail_total = c->infrastructure.GetRailTotal();
2057 for (const auto &rt : _sorted_railtypes) {
2058 if (HasBit(this->railtypes, rt)) {
2059 this->DrawCountLine(r, y, c->infrastructure.rail[rt], RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total));
2060 }
2061 }
2062 if (this->railtypes != RAILTYPES_NONE) {
2063 this->DrawCountLine(r, y, c->infrastructure.signal, SignalMaintenanceCost(c->infrastructure.signal));
2064 }
2065 break;
2066 }
2067
2068 case WID_CI_ROAD_DESC:
2069 case WID_CI_TRAM_DESC: {
2070 DrawString(r.left, r.right, y, widget == WID_CI_ROAD_DESC ? STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT : STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT);
2071
2072 /* Draw name of each valid roadtype. */
2073 for (const auto &rt : _sorted_roadtypes) {
2074 if (HasBit(this->roadtypes, rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_DESC)) {
2075 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), GetRoadTypeInfo(rt)->strings.name, TC_WHITE);
2076 }
2077 }
2078
2079 break;
2080 }
2081
2082 case WID_CI_ROAD_COUNT:
2083 case WID_CI_TRAM_COUNT: {
2084 uint32_t road_tram_total = widget == WID_CI_ROAD_COUNT ? c->infrastructure.GetRoadTotal() : c->infrastructure.GetTramTotal();
2085 for (const auto &rt : _sorted_roadtypes) {
2086 if (HasBit(this->roadtypes, rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_COUNT)) {
2087 this->DrawCountLine(r, y, c->infrastructure.road[rt], RoadMaintenanceCost(rt, c->infrastructure.road[rt], road_tram_total));
2088 }
2089 }
2090 break;
2091 }
2092
2093 case WID_CI_WATER_DESC:
2094 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT);
2095 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS);
2096 break;
2097
2098 case WID_CI_WATER_COUNT:
2099 this->DrawCountLine(r, y, c->infrastructure.water, CanalMaintenanceCost(c->infrastructure.water));
2100 break;
2101
2102 case WID_CI_TOTAL:
2103 if (_settings_game.economy.infrastructure_maintenance) {
2104 Rect tr = r.WithWidth(this->total_width, _current_text_dir == TD_RTL);
2105 GfxFillRect(tr.left, y, tr.right, y + WidgetDimensions::scaled.bevel.top - 1, PC_WHITE);
2106 y += WidgetDimensions::scaled.vsep_normal;
2107 SetDParam(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
2108 DrawString(tr.left, tr.right, y,
2109 TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR,
2110 TC_FROMSTRING, SA_RIGHT);
2111 }
2112 break;
2113
2114 case WID_CI_STATION_DESC:
2115 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT);
2116 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS);
2117 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS);
2118 break;
2119
2120 case WID_CI_STATION_COUNT:
2121 this->DrawCountLine(r, y, c->infrastructure.station, StationMaintenanceCost(c->infrastructure.station));
2122 this->DrawCountLine(r, y, c->infrastructure.airport, AirportMaintenanceCost(c->index));
2123 break;
2124 }
2125 }
2126
2132 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2133 {
2134 if (!gui_scope) return;
2135
2136 this->UpdateRailRoadTypes();
2137 this->ReInit();
2138 }
2139 };
2140
2141 static WindowDesc _company_infrastructure_desc(__FILE__, __LINE__,
2142 WDP_AUTO, "company_infrastructure", 0, 0,
2143 WC_COMPANY_INFRASTRUCTURE, WC_NONE,
2144 0,
2145 std::begin(_nested_company_infrastructure_widgets), std::end(_nested_company_infrastructure_widgets)
2146 );
2147
2152 static void ShowCompanyInfrastructure(CompanyID company)
2153 {
2154 if (!Company::IsValidID(company)) return;
2155 AllocateWindowDescFront<CompanyInfrastructureWindow>(&_company_infrastructure_desc, company);
2156 }
2157
2158 static constexpr NWidgetPart _nested_company_widgets[] = {
2159 NWidget(NWID_HORIZONTAL),
2160 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2161 NWidget(WWT_CAPTION, COLOUR_GREY, WID_C_CAPTION), SetDataTip(STR_COMPANY_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2162 NWidget(WWT_SHADEBOX, COLOUR_GREY),
2163 NWidget(WWT_STICKYBOX, COLOUR_GREY),
2164 EndContainer(),
2165 NWidget(WWT_PANEL, COLOUR_GREY),
2166 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0), SetPadding(4),
2167 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
2168 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_FACE), SetMinimalSize(92, 119), SetFill(1, 0),
2169 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_FACE_TITLE), SetFill(1, 1), SetMinimalTextLines(2, 0),
2170 EndContainer(),
2171 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
2172 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
2173 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
2174 NWidget(WWT_TEXT, COLOUR_GREY, WID_C_DESC_INAUGURATION), SetDataTip(STR_COMPANY_VIEW_INAUGURATED_TITLE, STR_NULL), SetFill(1, 0),
2175 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
2176 NWidget(WWT_LABEL, COLOUR_GREY, WID_C_DESC_COLOUR_SCHEME), SetDataTip(STR_COMPANY_VIEW_COLOUR_SCHEME_TITLE, STR_NULL),
2177 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_DESC_COLOUR_SCHEME_EXAMPLE), SetMinimalSize(30, 0), SetFill(1, 1),
2178 EndContainer(),
2179 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
2180 NWidget(WWT_TEXT, COLOUR_GREY, WID_C_DESC_VEHICLE), SetDataTip(STR_COMPANY_VIEW_VEHICLES_TITLE, STR_NULL), SetAlignment(SA_LEFT | SA_TOP),
2181 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_DESC_VEHICLE_COUNTS), SetMinimalTextLines(4, 0), SetFill(1, 1),
2182 EndContainer(),
2183 EndContainer(),
2184 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
2185 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_VIEW_BUILD_HQ),
2186 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_VIEW_HQ), SetDataTip(STR_COMPANY_VIEW_VIEW_HQ_BUTTON, STR_COMPANY_VIEW_VIEW_HQ_TOOLTIP),
2187 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_C_BUILD_HQ), SetDataTip(STR_COMPANY_VIEW_BUILD_HQ_BUTTON, STR_COMPANY_VIEW_BUILD_HQ_TOOLTIP),
2188 EndContainer(),
2189 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_RELOCATE),
2190 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_C_RELOCATE_HQ), SetDataTip(STR_COMPANY_VIEW_RELOCATE_HQ, STR_COMPANY_VIEW_RELOCATE_COMPANY_HEADQUARTERS),
2191 NWidget(NWID_SPACER),
2192 EndContainer(),
2193 EndContainer(),
2194 EndContainer(),
2195
2196 NWidget(WWT_TEXT, COLOUR_GREY, WID_C_DESC_COMPANY_VALUE), SetDataTip(STR_COMPANY_VIEW_COMPANY_VALUE, STR_NULL), SetFill(1, 0),
2197
2198 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
2199 NWidget(WWT_TEXT, COLOUR_GREY, WID_C_DESC_INFRASTRUCTURE), SetDataTip(STR_COMPANY_VIEW_INFRASTRUCTURE, STR_NULL), SetAlignment(SA_LEFT | SA_TOP),
2200 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_DESC_INFRASTRUCTURE_COUNTS), SetMinimalTextLines(5, 0), SetFill(1, 0),
2201 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1),
2202 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_VIEW_INFRASTRUCTURE), SetDataTip(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP),
2203 EndContainer(),
2204 EndContainer(),
2205
2206 /* Multi player buttons. */
2207 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), SetPIPRatio(1, 0, 0),
2208 NWidget(NWID_VERTICAL), SetPIPRatio(1, 0, 0),
2209 NWidget(WWT_EMPTY, COLOUR_GREY, WID_C_HAS_PASSWORD), SetFill(0, 0),
2210 EndContainer(),
2211 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
2212 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_HOSTILE_TAKEOVER),
2213 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_HOSTILE_TAKEOVER), SetDataTip(STR_COMPANY_VIEW_HOSTILE_TAKEOVER_BUTTON, STR_COMPANY_VIEW_HOSTILE_TAKEOVER_TOOLTIP),
2214 EndContainer(),
2215 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_GIVE_MONEY),
2216 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_GIVE_MONEY), SetDataTip(STR_COMPANY_VIEW_GIVE_MONEY_BUTTON, STR_COMPANY_VIEW_GIVE_MONEY_TOOLTIP),
2217 EndContainer(),
2218 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_MULTIPLAYER),
2219 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_COMPANY_PASSWORD), SetDataTip(STR_COMPANY_VIEW_PASSWORD, STR_COMPANY_VIEW_PASSWORD_TOOLTIP),
2220 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_COMPANY_JOIN), SetDataTip(STR_COMPANY_VIEW_JOIN, STR_COMPANY_VIEW_JOIN_TOOLTIP),
2221 EndContainer(),
2222 EndContainer(),
2223 EndContainer(),
2224 EndContainer(),
2225 EndContainer(),
2226 EndContainer(),
2227 /* Button bars at the bottom. */
2228 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_BUTTONS),
2229 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
2230 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_NEW_FACE), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_NEW_FACE_BUTTON, STR_COMPANY_VIEW_NEW_FACE_TOOLTIP),
2231 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_COLOUR_SCHEME), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_COLOUR_SCHEME_BUTTON, STR_COMPANY_VIEW_COLOUR_SCHEME_TOOLTIP),
2232 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_PRESIDENT_NAME), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_PRESIDENT_NAME_BUTTON, STR_COMPANY_VIEW_PRESIDENT_NAME_TOOLTIP),
2233 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_COMPANY_NAME), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_COMPANY_NAME_BUTTON, STR_COMPANY_VIEW_COMPANY_NAME_TOOLTIP),
2234 EndContainer(),
2235 EndContainer(),
2236 };
2237
2239 static const StringID _company_view_vehicle_count_strings[] = {
2240 STR_COMPANY_VIEW_TRAINS, STR_COMPANY_VIEW_ROAD_VEHICLES, STR_COMPANY_VIEW_SHIPS, STR_COMPANY_VIEW_AIRCRAFT
2241 };
2242
2246 struct CompanyWindow : Window
2247 {
2248 CompanyWidgets query_widget;
2249
2251 enum CompanyWindowPlanes {
2252 /* Display planes of the #WID_C_SELECT_MULTIPLAYER selection widget. */
2253 CWP_MP_C_PWD = 0,
2254 CWP_MP_C_JOIN,
2255
2256 /* Display planes of the #WID_C_SELECT_VIEW_BUILD_HQ selection widget. */
2257 CWP_VB_VIEW = 0,
2258 CWP_VB_BUILD,
2259
2260 /* Display planes of the #WID_C_SELECT_RELOCATE selection widget. */
2261 CWP_RELOCATE_SHOW = 0,
2262 CWP_RELOCATE_HIDE,
2263 };
2264
2265 CompanyWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
2266 {
2267 this->InitNested(window_number);
2268 this->owner = (Owner)this->window_number;
2269 this->OnInvalidateData();
2270 }
2271
2272 void OnPaint() override
2273 {
2274 const Company *c = Company::Get((CompanyID)this->window_number);
2275 bool local = this->window_number == _local_company;
2276
2277 if (!this->IsShaded()) {
2278 bool reinit = false;
2279
2280 /* Button bar selection. */
2281 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_BUTTONS)->SetDisplayedPlane(local ? 0 : SZSP_NONE);
2282
2283 /* Build HQ button handling. */
2284 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_VIEW_BUILD_HQ)->SetDisplayedPlane((local && c->location_of_HQ == INVALID_TILE) ? CWP_VB_BUILD : CWP_VB_VIEW);
2285
2286 this->SetWidgetDisabledState(WID_C_VIEW_HQ, c->location_of_HQ == INVALID_TILE);
2287
2288 /* Enable/disable 'Relocate HQ' button. */
2289 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_RELOCATE)->SetDisplayedPlane((!local || c->location_of_HQ == INVALID_TILE) ? CWP_RELOCATE_HIDE : CWP_RELOCATE_SHOW);
2290 /* Enable/disable 'Give money' button. */
2291 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_GIVE_MONEY)->SetDisplayedPlane((local || _local_company == COMPANY_SPECTATOR || !_settings_game.economy.give_money) ? SZSP_NONE : 0);
2292 /* Enable/disable 'Hostile Takeover' button. */
2293 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_HOSTILE_TAKEOVER)->SetDisplayedPlane((local || _local_company == COMPANY_SPECTATOR || !c->is_ai || _networking) ? SZSP_NONE : 0);
2294
2295 /* Multiplayer buttons. */
2296 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_MULTIPLAYER)->SetDisplayedPlane((!_networking) ? (int)SZSP_NONE : (int)(local ? CWP_MP_C_PWD : CWP_MP_C_JOIN));
2297
2298 this->SetWidgetDisabledState(WID_C_COMPANY_JOIN, c->is_ai);
2299
2300 if (reinit) {
2301 this->ReInit();
2302 return;
2303 }
2304 }
2305
2306 this->DrawWidgets();
2307 }
2308
2309 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
2310 {
2311 switch (widget) {
2312 case WID_C_FACE:
2313 *size = maxdim(*size, GetScaledSpriteSize(SPR_GRADIENT));
2314 break;
2315
2316 case WID_C_DESC_COLOUR_SCHEME_EXAMPLE: {
2317 Point offset;
2318 Dimension d = GetSpriteSize(SPR_VEH_BUS_SW_VIEW, &offset);
2319 d.width -= offset.x;
2320 d.height -= offset.y;
2321 *size = maxdim(*size, d);
2322 break;
2323 }
2324
2325 case WID_C_DESC_COMPANY_VALUE:
2326 SetDParam(0, INT64_MAX); // Arguably the maximum company value
2327 size->width = GetStringBoundingBox(STR_COMPANY_VIEW_COMPANY_VALUE).width;
2328 break;
2329
2330 case WID_C_DESC_VEHICLE_COUNTS:
2331 SetDParamMaxValue(0, 5000); // Maximum number of vehicles
2332 for (uint i = 0; i < lengthof(_company_view_vehicle_count_strings); i++) {
2333 size->width = std::max(size->width, GetStringBoundingBox(_company_view_vehicle_count_strings[i]).width + padding.width);
2334 }
2335 break;
2336
2337 case WID_C_DESC_INFRASTRUCTURE_COUNTS:
2338 SetDParamMaxValue(0, UINT_MAX);
2339 size->width = GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL).width;
2340 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD).width);
2341 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_WATER).width);
2342 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_STATION).width);
2343 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT).width);
2344 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_NONE).width);
2345 size->width += padding.width;
2346 break;
2347
2348 case WID_C_VIEW_HQ:
2349 case WID_C_BUILD_HQ:
2350 case WID_C_RELOCATE_HQ:
2351 case WID_C_VIEW_INFRASTRUCTURE:
2352 case WID_C_GIVE_MONEY:
2353 case WID_C_HOSTILE_TAKEOVER:
2354 case WID_C_COMPANY_PASSWORD:
2355 case WID_C_COMPANY_JOIN:
2356 size->width = GetStringBoundingBox(STR_COMPANY_VIEW_VIEW_HQ_BUTTON).width;
2357 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_BUILD_HQ_BUTTON).width);
2358 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_RELOCATE_HQ).width);
2359 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON).width);
2360 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_GIVE_MONEY_BUTTON).width);
2361 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_HOSTILE_TAKEOVER_BUTTON).width);
2362 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_PASSWORD).width);
2363 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_JOIN).width);
2364 size->width += padding.width;
2365 break;
2366
2367 case WID_C_HAS_PASSWORD:
2368 if (_networking) *size = maxdim(*size, GetSpriteSize(SPR_LOCK));
2369 break;
2370 }
2371 }
2372
2373 void DrawVehicleCountsWidget(const Rect &r, const Company *c) const
2374 {
2375 static_assert(VEH_COMPANY_END == lengthof(_company_view_vehicle_count_strings));
2376
2377 int y = r.top;
2378 for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
2379 uint amount = c->group_all[type].num_vehicle;
2380 if (amount != 0) {
2381 SetDParam(0, amount);
2382 DrawString(r.left, r.right, y, _company_view_vehicle_count_strings[type]);
2383 y += GetCharacterHeight(FS_NORMAL);
2384 }
2385 }
2386
2387 if (y == r.top) {
2388 /* No String was emited before, so there must be no vehicles at all. */
2389 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
2390 }
2391 }
2392
2393 void DrawInfrastructureCountsWidget(const Rect &r, const Company *c) const
2394 {
2395 int y = r.top;
2396
2397 uint rail_pieces = c->infrastructure.signal;
2398 for (uint i = 0; i < lengthof(c->infrastructure.rail); i++) rail_pieces += c->infrastructure.rail[i];
2399 if (rail_pieces != 0) {
2400 SetDParam(0, rail_pieces);
2401 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL);
2402 y += GetCharacterHeight(FS_NORMAL);
2403 }
2404
2405 uint road_pieces = 0;
2406 for (uint i = 0; i < lengthof(c->infrastructure.road); i++) road_pieces += c->infrastructure.road[i];
2407 if (road_pieces != 0) {
2408 SetDParam(0, road_pieces);
2409 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD);
2410 y += GetCharacterHeight(FS_NORMAL);
2411 }
2412
2413 if (c->infrastructure.water != 0) {
2414 SetDParam(0, c->infrastructure.water);
2415 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_WATER);
2416 y += GetCharacterHeight(FS_NORMAL);
2417 }
2418
2419 if (c->infrastructure.station != 0) {
2420 SetDParam(0, c->infrastructure.station);
2421 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_STATION);
2422 y += GetCharacterHeight(FS_NORMAL);
2423 }
2424
2425 if (c->infrastructure.airport != 0) {
2426 SetDParam(0, c->infrastructure.airport);
2427 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT);
2428 y += GetCharacterHeight(FS_NORMAL);
2429 }
2430
2431 if (y == r.top) {
2432 /* No String was emited before, so there must be no infrastructure at all. */
2433 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
2434 }
2435 }
2436
2437 void DrawWidget(const Rect &r, WidgetID widget) const override
2438 {
2439 const Company *c = Company::Get((CompanyID)this->window_number);
2440 switch (widget) {
2441 case WID_C_FACE:
2442 DrawCompanyManagerFace(c->face, c->colour, r);
2443 break;
2444
2445 case WID_C_FACE_TITLE:
2446 SetDParam(0, c->index);
2447 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
2448 break;
2449
2450 case WID_C_DESC_COLOUR_SCHEME_EXAMPLE: {
2451 Point offset;
2452 Dimension d = GetSpriteSize(SPR_VEH_BUS_SW_VIEW, &offset);
2453 d.height -= offset.y;
2454 DrawSprite(SPR_VEH_BUS_SW_VIEW, COMPANY_SPRITE_COLOUR(c->index), r.left - offset.x, CenterBounds(r.top, r.bottom, d.height) - offset.y);
2455 break;
2456 }
2457
2458 case WID_C_DESC_VEHICLE_COUNTS:
2459 DrawVehicleCountsWidget(r, c);
2460 break;
2461
2462 case WID_C_DESC_INFRASTRUCTURE_COUNTS:
2463 DrawInfrastructureCountsWidget(r, c);
2464 break;
2465
2466 case WID_C_HAS_PASSWORD:
2467 if (_networking && NetworkCompanyIsPassworded(c->index)) {
2468 DrawSprite(SPR_LOCK, PAL_NONE, r.left, r.top);
2469 }
2470 break;
2471 }
2472 }
2473
2474 void SetStringParameters(WidgetID widget) const override
2475 {
2476 switch (widget) {
2477 case WID_C_CAPTION:
2478 SetDParam(0, (CompanyID)this->window_number);
2479 SetDParam(1, (CompanyID)this->window_number);
2480 break;
2481
2482 case WID_C_DESC_INAUGURATION:
2483 SetDParam(0, Company::Get((CompanyID)this->window_number)->inaugurated_year);
2484 break;
2485
2486 case WID_C_DESC_COMPANY_VALUE:
2487 SetDParam(0, CalculateCompanyValue(Company::Get((CompanyID)this->window_number)));
2488 break;
2489 }
2490 }
2491
2492 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2493 {
2494 switch (widget) {
2495 case WID_C_NEW_FACE: DoSelectCompanyManagerFace(this); break;
2496
2497 case WID_C_COLOUR_SCHEME:
2498 ShowCompanyLiveryWindow((CompanyID)this->window_number, INVALID_GROUP);
2499 break;
2500
2501 case WID_C_PRESIDENT_NAME:
2502 this->query_widget = WID_C_PRESIDENT_NAME;
2503 SetDParam(0, this->window_number);
2504 ShowQueryString(STR_PRESIDENT_NAME, STR_COMPANY_VIEW_PRESIDENT_S_NAME_QUERY_CAPTION, MAX_LENGTH_PRESIDENT_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
2505 break;
2506
2507 case WID_C_COMPANY_NAME:
2508 this->query_widget = WID_C_COMPANY_NAME;
2509 SetDParam(0, this->window_number);
2510 ShowQueryString(STR_COMPANY_NAME, STR_COMPANY_VIEW_COMPANY_NAME_QUERY_CAPTION, MAX_LENGTH_COMPANY_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
2511 break;
2512
2513 case WID_C_VIEW_HQ: {
2514 TileIndex tile = Company::Get((CompanyID)this->window_number)->location_of_HQ;
2515 if (_ctrl_pressed) {
2516 ShowExtraViewportWindow(tile);
2517 } else {
2518 ScrollMainWindowToTile(tile);
2519 }
2520 break;
2521 }
2522
2523 case WID_C_BUILD_HQ:
2524 if ((byte)this->window_number != _local_company) return;
2525 if (this->IsWidgetLowered(WID_C_BUILD_HQ)) {
2526 ResetObjectToPlace();
2527 this->RaiseButtons();
2528 break;
2529 }
2530 SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, HT_RECT, this);
2531 SetTileSelectSize(2, 2);
2532 this->LowerWidget(WID_C_BUILD_HQ);
2533 this->SetWidgetDirty(WID_C_BUILD_HQ);
2534 break;
2535
2536 case WID_C_RELOCATE_HQ:
2537 if (this->IsWidgetLowered(WID_C_RELOCATE_HQ)) {
2538 ResetObjectToPlace();
2539 this->RaiseButtons();
2540 break;
2541 }
2542 SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, HT_RECT, this);
2543 SetTileSelectSize(2, 2);
2544 this->LowerWidget(WID_C_RELOCATE_HQ);
2545 this->SetWidgetDirty(WID_C_RELOCATE_HQ);
2546 break;
2547
2548 case WID_C_VIEW_INFRASTRUCTURE:
2549 ShowCompanyInfrastructure((CompanyID)this->window_number);
2550 break;
2551
2552 case WID_C_GIVE_MONEY:
2553 this->query_widget = WID_C_GIVE_MONEY;
2554 ShowQueryString(STR_EMPTY, STR_COMPANY_VIEW_GIVE_MONEY_QUERY_CAPTION, 30, this, CS_NUMERAL, QSF_NONE);
2555 break;
2556
2557 case WID_C_HOSTILE_TAKEOVER:
2558 ShowBuyCompanyDialog((CompanyID)this->window_number, true);
2559 break;
2560
2561 case WID_C_COMPANY_PASSWORD:
2562 if (this->window_number == _local_company) ShowNetworkCompanyPasswordWindow(this);
2563 break;
2564
2565 case WID_C_COMPANY_JOIN: {
2566 this->query_widget = WID_C_COMPANY_JOIN;
2567 CompanyID company = (CompanyID)this->window_number;
2568 if (_network_server) {
2569 NetworkServerDoMove(CLIENT_ID_SERVER, company);
2570 MarkWholeScreenDirty();
2571 } else if (NetworkCompanyIsPassworded(company)) {
2572 /* ask for the password */
2573 ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION, NETWORK_PASSWORD_LENGTH, this, CS_ALPHANUMERAL, QSF_PASSWORD);
2574 } else {
2575 /* just send the join command */
2576 NetworkClientRequestMove(company);
2577 }
2578 break;
2579 }
2580 }
2581 }
2582
2584 IntervalTimer<TimerWindow> redraw_interval = {std::chrono::seconds(3), [this](auto) {
2585 this->SetDirty();
2586 }};
2587
2588 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
2589 {
2590 if (Command<CMD_BUILD_OBJECT>::Post(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS, tile, OBJECT_HQ, 0) && !_shift_pressed) {
2591 ResetObjectToPlace();
2592 this->RaiseButtons();
2593 }
2594 }
2595
2596 void OnPlaceObjectAbort() override
2597 {
2598 this->RaiseButtons();
2599 }
2600
2601 void OnQueryTextFinished(char *str) override
2602 {
2603 if (str == nullptr) return;
2604
2605 switch (this->query_widget) {
2606 default: NOT_REACHED();
2607
2608 case WID_C_GIVE_MONEY: {
2609 Money money = std::strtoull(str, nullptr, 10) / _currency->rate;
2610 Command<CMD_GIVE_MONEY>::Post(STR_ERROR_CAN_T_GIVE_MONEY, money, (CompanyID)this->window_number);
2611 break;
2612 }
2613
2614 case WID_C_PRESIDENT_NAME:
2615 Command<CMD_RENAME_PRESIDENT>::Post(STR_ERROR_CAN_T_CHANGE_PRESIDENT, str);
2616 break;
2617
2618 case WID_C_COMPANY_NAME:
2619 Command<CMD_RENAME_COMPANY>::Post(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME, str);
2620 break;
2621
2622 case WID_C_COMPANY_JOIN:
2623 NetworkClientRequestMove((CompanyID)this->window_number, str);
2624 break;
2625 }
2626 }
2627 };
2628
2629 static WindowDesc _company_desc(__FILE__, __LINE__,
2630 WDP_AUTO, "company", 0, 0,
2631 WC_COMPANY, WC_NONE,
2632 0,
2633 std::begin(_nested_company_widgets), std::end(_nested_company_widgets)
2634 );
2635
2640 void ShowCompany(CompanyID company)
2641 {
2642 if (!Company::IsValidID(company)) return;
2643
2644 AllocateWindowDescFront<CompanyWindow>(&_company_desc, company);
2645 }
2646
2651 void DirtyCompanyInfrastructureWindows(CompanyID company)
2652 {
2653 SetWindowDirty(WC_COMPANY, company);
2654 SetWindowDirty(WC_COMPANY_INFRASTRUCTURE, company);
2655 }
2656
2657 struct BuyCompanyWindow : Window {
2658 BuyCompanyWindow(WindowDesc *desc, WindowNumber window_number, bool hostile_takeover) : Window(desc), hostile_takeover(hostile_takeover)
2659 {
2660 this->InitNested(window_number);
2661
2662 const Company *c = Company::Get((CompanyID)this->window_number);
2663 this->company_value = hostile_takeover ? CalculateHostileTakeoverValue(c) : c->bankrupt_value;
2664 }
2665
2666 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
2667 {
2668 switch (widget) {
2669 case WID_BC_FACE:
2670 *size = GetScaledSpriteSize(SPR_GRADIENT);
2671 break;
2672
2673 case WID_BC_QUESTION:
2674 const Company *c = Company::Get((CompanyID)this->window_number);
2675 SetDParam(0, c->index);
2676 SetDParam(1, this->company_value);
2677 size->height = GetStringHeight(this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, size->width);
2678 break;
2679 }
2680 }
2681
2682 void SetStringParameters(WidgetID widget) const override
2683 {
2684 switch (widget) {
2685 case WID_BC_CAPTION:
2686 SetDParam(0, STR_COMPANY_NAME);
2687 SetDParam(1, Company::Get((CompanyID)this->window_number)->index);
2688 break;
2689 }
2690 }
2691
2692 void DrawWidget(const Rect &r, WidgetID widget) const override
2693 {
2694 switch (widget) {
2695 case WID_BC_FACE: {
2696 const Company *c = Company::Get((CompanyID)this->window_number);
2697 DrawCompanyManagerFace(c->face, c->colour, r);
2698 break;
2699 }
2700
2701 case WID_BC_QUESTION: {
2702 const Company *c = Company::Get((CompanyID)this->window_number);
2703 SetDParam(0, c->index);
2704 SetDParam(1, this->company_value);
2705 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, TC_FROMSTRING, SA_CENTER);
2706 break;
2707 }
2708 }
2709 }
2710
2711 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2712 {
2713 switch (widget) {
2714 case WID_BC_NO:
2715 this->Close();
2716 break;
2717
2718 case WID_BC_YES:
2719 Command<CMD_BUY_COMPANY>::Post(STR_ERROR_CAN_T_BUY_COMPANY, (CompanyID)this->window_number, this->hostile_takeover);
2720 break;
2721 }
2722 }
2723
2727 IntervalTimer<TimerWindow> rescale_interval = {std::chrono::seconds(3), [this](auto) {
2728 /* Value can't change when in bankruptcy. */
2729 if (!this->hostile_takeover) return;
2730
2731 const Company *c = Company::Get((CompanyID)this->window_number);
2732 auto new_value = CalculateHostileTakeoverValue(c);
2733 if (new_value != this->company_value) {
2734 this->company_value = new_value;
2735 this->ReInit();
2736 }
2737 }};
2738
2739 private:
2740 bool hostile_takeover;
2741 Money company_value;
2742 };
2743
2744 static constexpr NWidgetPart _nested_buy_company_widgets[] = {
2745 NWidget(NWID_HORIZONTAL),
2746 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
2747 NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_BC_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2748 EndContainer(),
2749 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
2750 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
2751 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
2752 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BC_FACE), SetFill(0, 1),
2753 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BC_QUESTION), SetMinimalSize(240, 0), SetFill(1, 1),
2754 EndContainer(),
2755 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(100, WidgetDimensions::unscaled.hsep_wide, 100),
2756 NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_BC_NO), SetMinimalSize(60, 12), SetDataTip(STR_QUIT_NO, STR_NULL), SetFill(1, 0),
2757 NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_BC_YES), SetMinimalSize(60, 12), SetDataTip(STR_QUIT_YES, STR_NULL), SetFill(1, 0),
2758 EndContainer(),
2759 EndContainer(),
2760 EndContainer(),
2761 };
2762
2763 static WindowDesc _buy_company_desc(__FILE__, __LINE__,
2764 WDP_AUTO, nullptr, 0, 0,
2765 WC_BUY_COMPANY, WC_NONE,
2766 WDF_CONSTRUCTION,
2767 std::begin(_nested_buy_company_widgets), std::end(_nested_buy_company_widgets)
2768 );
2769
2775 void ShowBuyCompanyDialog(CompanyID company, bool hostile_takeover)
2776 {
2777 auto window = BringWindowToFrontById(WC_BUY_COMPANY, company);
2778 if (window == nullptr) {
2779 new BuyCompanyWindow(&_buy_company_desc, company, hostile_takeover);
2780 }
2781 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:469
EconomySettings::give_money
bool give_money
allow giving other companies money
Definition: settings_type.h:547
SelectCompanyManagerFaceWindow::ge
GenderEthnicity ge
Gender and ethnicity.
Definition: company_gui.cpp:1367
WID_SCMF_JACKET_R
@ WID_SCMF_JACKET_R
Jacket right.
Definition: company_widget.h:160
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
SelectCompanyManagerFaceWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: company_gui.cpp:1507
ExpensesList::GetListWidth
uint GetListWidth() const
Compute width of the expenses categories in pixels.
Definition: company_gui.cpp:98
SetTileSelectSize
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition: viewport.cpp:2536
CompanyProperties::is_ai
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:95
CompanyWindow::CWP_RELOCATE_SHOW
@ CWP_RELOCATE_SHOW
Show the relocate HQ button.
Definition: company_gui.cpp:2261
WID_CF_TOGGLE_SIZE
@ WID_CF_TOGGLE_SIZE
Toggle windows size.
Definition: company_widget.h:59
WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
@ WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
Toggle for large or small.
Definition: company_widget.h:119
WID_SCMF_ACCEPT
@ WID_SCMF_ACCEPT
Accept.
Definition: company_widget.h:110
WID_SCMF_HAS_GLASSES_TEXT
@ WID_SCMF_HAS_GLASSES_TEXT
Text about glasses.
Definition: company_widget.h:127
EXPENSES_ROADVEH_RUN
@ EXPENSES_ROADVEH_RUN
Running costs road vehicles.
Definition: economy_type.h:176
ROADTYPE_END
@ ROADTYPE_END
Used for iterations.
Definition: road_type.h:29
NWidgetCore::IsDisabled
bool IsDisabled() const
Return whether the widget is disabled.
Definition: widget_type.h:435
Engine::IterateType
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
Definition: engine_base.h:186
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
economy_cmd.h
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:91
WidgetDimensions::imgbtn
RectPadding imgbtn
Padding around image button image.
Definition: window_gui.h:36
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
WID_CF_INFRASTRUCTURE
@ WID_CF_INFRASTRUCTURE
View company infrastructure.
Definition: company_widget.h:76
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2509
WID_SCMF_GLASSES_L
@ WID_SCMF_GLASSES_L
Glasses left.
Definition: company_widget.h:167
DropDownListColourItem
Colour selection list item, with icon and string components.
Definition: company_gui.cpp:587
WID_CF_MAXLOAN_VALUE
@ WID_CF_MAXLOAN_VALUE
Max loan widget.
Definition: company_widget.h:72
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3082
water.h
WID_SCL_MATRIX
@ WID_SCL_MATRIX
Matrix.
Definition: company_widget.h:95
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:156
BuyCompanyWindow
Definition: company_gui.cpp:2657
WID_C_NEW_FACE
@ WID_C_NEW_FACE
Button to make new face.
Definition: company_widget.h:30
WID_SCL_GROUPS_AIRCRAFT
@ WID_SCL_GROUPS_AIRCRAFT
Aircraft groups.
Definition: company_widget.h:91
Company::group_all
GroupStatistics group_all[VEH_COMPANY_END]
NOSAVE: Statistics for the ALL_GROUP group.
Definition: company_base.h:126
WID_C_GIVE_MONEY
@ WID_C_GIVE_MONEY
Button to give money.
Definition: company_widget.h:45
WID_SCMF_HAIR_R
@ WID_SCMF_HAIR_R
Hair right.
Definition: company_widget.h:157
QSF_PASSWORD
@ QSF_PASSWORD
password entry box, show warning about password security
Definition: textbuf_gui.h:23
WID_CI_RAIL_DESC
@ WID_CI_RAIL_DESC
Description of rail.
Definition: company_widget.h:175
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
WID_BC_YES
@ WID_BC_YES
Yes button.
Definition: company_widget.h:195
command_func.h
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
WID_SCMF_CHIN
@ WID_SCMF_CHIN
Chin.
Definition: company_widget.h:144
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:197
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:307
CompanyWindow::CWP_MP_C_JOIN
@ CWP_MP_C_JOIN
Display the join company button.
Definition: company_gui.cpp:2254
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
SelectCompanyManagerFaceWindow::advanced
bool advanced
advanced company manager face selection window
Definition: company_gui.cpp:1365
WID_SCMF_TIE_EARRING_L
@ WID_SCMF_TIE_EARRING_L
Tie / Earring left.
Definition: company_widget.h:164
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:356
NWidgetCore::SetDataTip
void SetDataTip(uint32_t widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:1094
WID_CF_SEL_BUTTONS
@ WID_CF_SEL_BUTTONS
Selection of buttons.
Definition: company_widget.h:73
RoadTypeInfo::introduces_roadtypes
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced.
Definition: road.h:177
WID_SCL_SEC_COL_DROPDOWN
@ WID_SCL_SEC_COL_DROPDOWN
Dropdown for secondary colour.
Definition: company_widget.h:94
company_base.h
CanalMaintenanceCost
Money CanalMaintenanceCost(uint32_t num)
Calculates the maintenance cost of a number of canal tiles.
Definition: water.h:52
WID_SCMF_LIPS_MOUSTACHE_R
@ WID_SCMF_LIPS_MOUSTACHE_R
Lips / Moustache right.
Definition: company_widget.h:151
EXPENSES_OTHER
@ EXPENSES_OTHER
Other expenses.
Definition: economy_type.h:185
CompanyFinancesWindow::SetupWidgets
void SetupWidgets()
Setup the widgets in the nested tree, such that the finances window is displayed properly.
Definition: company_gui.cpp:446
LOAN_INTERVAL
static const int LOAN_INTERVAL
The "steps" in loan size, in British Pounds!
Definition: economy_type.h:215
WC_COMPANY_COLOUR
@ WC_COMPANY_COLOUR
Company colour selection; Window numbers:
Definition: window_type.h:230
WID_CI_ROAD_DESC
@ WID_CI_ROAD_DESC
Description of road.
Definition: company_widget.h:177
WID_SCL_CLASS_GENERAL
@ WID_SCL_CLASS_GENERAL
Class general.
Definition: company_widget.h:83
SelectCompanyLiveryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: company_gui.cpp:1036
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:552
currency.h
WID_SCMF_JACKET_TEXT
@ WID_SCMF_JACKET_TEXT
Text about jacket.
Definition: company_widget.h:134
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition: widget_type.h:1130
NetworkClientRequestMove
void NetworkClientRequestMove(CompanyID company_id, const std::string &pass)
Notify the server of this client wanting to be moved to another company.
Definition: network_client.cpp:1273
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition: widget_type.h:54
GUIList< const Group * >
PC_WHITE
static const uint8_t PC_WHITE
White palette colour.
Definition: palette_func.h:58
_network_server
bool _network_server
network-server is active
Definition: network.cpp:60
EXPENSES_TRAIN_REVENUE
@ EXPENSES_TRAIN_REVENUE
Revenue from trains.
Definition: economy_type.h:180
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:59
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:210
WID_BC_NO
@ WID_BC_NO
No button.
Definition: company_widget.h:194
GetCompanyManagerFaceBits
uint GetCompanyManagerFaceBits(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, [[maybe_unused]] GenderEthnicity ge)
Make sure the table's size is right.
Definition: company_manager_face.h:96
road_func.h
IntervalTimer< TimerWindow >
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
SelectCompanyManagerFaceWindow::face
CompanyManagerFace face
company manager face bits
Definition: company_gui.cpp:1364
company_manager_face.h
Group::parent
GroupID parent
Parent group.
Definition: group.h:83
WID_SCMF_FEMALE
@ WID_SCMF_FEMALE
Female button in the simple view.
Definition: company_widget.h:112
GenderEthnicity
GenderEthnicity
The gender/race combinations that we have faces for.
Definition: company_manager_face.h:19
WID_SCMF_MALE2
@ WID_SCMF_MALE2
Male button in the advanced view.
Definition: company_widget.h:113
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
_nested_select_company_manager_face_widgets
static constexpr NWidgetPart _nested_select_company_manager_face_widgets[]
Nested widget description for the company manager face selection dialog.
Definition: company_gui.cpp:1205
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
WID_SCMF_ETHNICITY_EUR
@ WID_SCMF_ETHNICITY_EUR
Text about ethnicity european.
Definition: company_widget.h:136
WC_COMPANY_MANAGER_FACE
@ WC_COMPANY_MANAGER_FACE
Alter company face window; Window numbers:
Definition: window_type.h:236
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
DrawPrice
static void DrawPrice(Money amount, int left, int right, int top, TextColour colour)
Draw an amount of money.
Definition: company_gui.cpp:214
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:1048
WID_CF_INCREASE_LOAN
@ WID_CF_INCREASE_LOAN
Increase loan.
Definition: company_widget.h:74
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
Window::EnableWidget
void EnableWidget(WidgetID widget_index)
Sets a widget to Enabled.
Definition: window_gui.h:400
misc_cmd.h
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:618
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
WID_SCMF_EYECOLOUR_L
@ WID_SCMF_EYECOLOUR_L
Eyecolour left.
Definition: company_widget.h:140
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:2029
WID_CF_EXPS_PRICE2
@ WID_CF_EXPS_PRICE2
Column for year Y-1 expenses.
Definition: company_widget.h:63
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1174
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
WID_CI_RAIL_COUNT
@ WID_CI_RAIL_COUNT
Count of rail.
Definition: company_widget.h:176
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
EXPENSES_AIRCRAFT_RUN
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
Definition: economy_type.h:177
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
zoom_func.h
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:2334
Group::livery
Livery livery
Custom colour scheme for vehicles in this group.
Definition: group.h:78
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition: window.cpp:526
StrNaturalCompare
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:585
WID_SCMF_COLLAR_TEXT
@ WID_SCMF_COLLAR_TEXT
Text about collar.
Definition: company_widget.h:135
SelectCompanyLiveryWindow
Company livery colour scheme window.
Definition: company_gui.cpp:597
WID_SCMF_LIPS_MOUSTACHE_L
@ WID_SCMF_LIPS_MOUSTACHE_L
Lips / Moustache left.
Definition: company_widget.h:149
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
WID_SCMF_HAIR_TEXT
@ WID_SCMF_HAIR_TEXT
Text about hair.
Definition: company_widget.h:128
LiveryScheme
LiveryScheme
List of different livery schemes.
Definition: livery.h:21
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition: timer_game_economy.cpp:97
DrawYearColumn
static void DrawYearColumn(const Rect &r, TimerGameEconomy::Year year, const Expenses &tbl)
Draw a column with prices.
Definition: company_gui.cpp:260
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:310
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:112
WID_SCMF_SEL_MALEFEMALE
@ WID_SCMF_SEL_MALEFEMALE
Selection to display the male/female buttons in the simple view.
Definition: company_widget.h:116
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:129
network_gui.h
GRFLoadedFeatures::used_liveries
uint64_t used_liveries
Bitmask of LiveryScheme used by the defined engines.
Definition: newgrf.h:179
WC_COMPANY
@ WC_COMPANY
Company view; Window numbers:
Definition: window_type.h:369
CompanyInfrastructure::road
uint32_t road[ROADTYPE_END]
Count of company owned track bits for each road type.
Definition: company_base.h:33
CompanyProperties::face
CompanyManagerFace face
Face description of the president.
Definition: company_base.h:65
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:340
WID_CF_CAPTION
@ WID_CF_CAPTION
Caption of the window.
Definition: company_widget.h:58
Engine
Definition: engine_base.h:37
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition: gfx_type.h:344
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
SelectCompanyLiveryWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: company_gui.cpp:1068
WID_SCMF_EYEBROWS_TEXT
@ WID_SCMF_EYEBROWS_TEXT
Text about eyebrows.
Definition: company_widget.h:129
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
CalculateCompanyValue
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
Definition: economy.cpp:149
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
WID_SCL_CLASS_ROAD
@ WID_SCL_CLASS_ROAD
Class road.
Definition: company_widget.h:85
WID_SCL_CAPTION
@ WID_SCL_CAPTION
Caption of window.
Definition: company_widget.h:82
StrEmpty
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:56
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:18
Group::vehicle_type
VehicleType vehicle_type
Vehicle type of the group.
Definition: group.h:75
RailTypes
RailTypes
Allow incrementing of Track variables.
Definition: rail_type.h:44
WID_C_DESC_COLOUR_SCHEME_EXAMPLE
@ WID_C_DESC_COLOUR_SCHEME_EXAMPLE
Colour scheme example.
Definition: company_widget.h:22
SelectCompanyManagerFaceWindow
Management class for customizing the face of the company manager.
Definition: company_gui.cpp:1362
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:211
WID_SCMF_TIE_EARRING_TEXT
@ WID_SCMF_TIE_EARRING_TEXT
Text about tie and earring.
Definition: company_widget.h:125
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1757
DifficultySettings::initial_interest
byte initial_interest
amount of interest (to pay over the loan)
Definition: settings_type.h:104
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
_expenses_list_operating_costs
static const std::initializer_list< ExpensesType > _expenses_list_operating_costs
List of operating expenses.
Definition: company_gui.cpp:66
CompanyProperties::current_loan
Money current_loan
Amount of money borrowed from the bank.
Definition: company_base.h:69
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:387
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
CompanyInfrastructure::station
uint32_t station
Count of company owned station tiles.
Definition: company_base.h:37
WID_C_COMPANY_JOIN
@ WID_C_COMPANY_JOIN
Button to join company.
Definition: company_widget.h:53
WID_SCMF_NOSE
@ WID_SCMF_NOSE
Nose.
Definition: company_widget.h:153
DropDownIcon
Drop down icon component.
Definition: dropdown_type.h:140
textbuf_gui.h
WID_SCMF_EYECOLOUR
@ WID_SCMF_EYECOLOUR
Eyecolour.
Definition: company_widget.h:141
ExpensesList
Expense list container.
Definition: company_gui.cpp:83
CompanyWindow::CWP_MP_C_PWD
@ CWP_MP_C_PWD
Display the company password button.
Definition: company_gui.cpp:2253
WID_SCMF_NOSE_TEXT
@ WID_SCMF_NOSE_TEXT
Text about nose.
Definition: company_widget.h:132
WID_C_VIEW_INFRASTRUCTURE
@ WID_C_VIEW_INFRASTRUCTURE
Panel about infrastructure.
Definition: company_widget.h:42
_interactive_random
Randomizer _interactive_random
Random used everywhere else, where it does not (directly) influence the game state.
Definition: random_func.cpp:37
Scrollbar::GetCount
uint16_t GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:702
WID_CF_EXPS_CATEGORY
@ WID_CF_EXPS_CATEGORY
Column for expenses category strings.
Definition: company_widget.h:61
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:619
QSF_LEN_IN_CHARS
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
Definition: textbuf_gui.h:22
CompanyFinancesWindow::rescale_interval
IntervalTimer< TimerWindow > rescale_interval
Check on a regular interval if the maximum amount of money has changed.
Definition: company_gui.cpp:519
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:41
WID_CF_REPAY_LOAN
@ WID_CF_REPAY_LOAN
Decrease loan..
Definition: company_widget.h:75
GENDER_FEMALE
@ GENDER_FEMALE
This bit set means a female, otherwise male.
Definition: company_manager_face.h:20
WID_SCMF_TIE_EARRING_R
@ WID_SCMF_TIE_EARRING_R
Tie / Earring right.
Definition: company_widget.h:166
TimerGameConst< struct Calendar >::MAX_DATE
static constexpr TimerGame< struct Calendar >::Date MAX_DATE
The date of the last day of the max year.
Definition: timer_game_common.h:187
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:63
WID_SCMF_JACKET_L
@ WID_SCMF_JACKET_L
Jacket left.
Definition: company_widget.h:158
WID_CI_WATER_COUNT
@ WID_CI_WATER_COUNT
Count of water.
Definition: company_widget.h:182
CompanyFinancesWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: company_gui.cpp:457
Group
Group data.
Definition: group.h:72
WID_C_DESC_COLOUR_SCHEME
@ WID_C_DESC_COLOUR_SCHEME
Colour scheme.
Definition: company_widget.h:21
company_cmd.h
window_gui.h
RailTypeInfo::name
StringID name
Name of this rail type.
Definition: rail.h:176
StationMaintenanceCost
Money StationMaintenanceCost(uint32_t num)
Calculates the maintenance cost of a number of station tiles.
Definition: station_func.h:59
Window::SetShaded
void SetShaded(bool make_shaded)
Set the shaded state of the window to make_shaded.
Definition: window.cpp:996
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:508
ShowCompanyFinances
void ShowCompanyFinances(CompanyID company)
Open the finances window of a company.
Definition: company_gui.cpp:544
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:1188
WID_SCMF_HAIR_L
@ WID_SCMF_HAIR_L
Hair left.
Definition: company_widget.h:155
CompanyInfrastructureWindow::total_width
uint total_width
String width of the total cost line.
Definition: company_gui.cpp:1829
ROADTYPES_NONE
@ ROADTYPES_NONE
No roadtypes.
Definition: road_type.h:39
GRFLoadedFeatures::has_2CC
bool has_2CC
Set if any vehicle is loaded which uses 2cc (two company colours).
Definition: newgrf.h:178
WID_CI_WATER_DESC
@ WID_CI_WATER_DESC
Description of water.
Definition: company_widget.h:181
ExpensesList::title
const StringID title
StringID of list title.
Definition: company_gui.cpp:84
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
WID_CF_BALANCE_LINE
@ WID_CF_BALANCE_LINE
Available cash.
Definition: company_widget.h:69
WID_C_RELOCATE_HQ
@ WID_C_RELOCATE_HQ
Button to relocate the HQ.
Definition: company_widget.h:40
INVALID_GROUP
static const GroupID INVALID_GROUP
Sentinel for invalid groups.
Definition: group_type.h:18
WID_SCMF_LIPS_MOUSTACHE_TEXT
@ WID_SCMF_LIPS_MOUSTACHE_TEXT
Text about lips and moustache.
Definition: company_widget.h:126
WID_C_CAPTION
@ WID_C_CAPTION
Caption of the window.
Definition: company_widget.h:15
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:173
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
WID_C_PRESIDENT_NAME
@ WID_C_PRESIDENT_NAME
Button to change president name.
Definition: company_widget.h:32
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
DrawCategories
static void DrawCategories(const Rect &r)
Draw the expenses categories.
Definition: company_gui.cpp:174
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:40
CompanyInfrastructure::GetRailTotal
uint32_t GetRailTotal() const
Get total sum of all owned track bits.
Definition: company_base.h:41
WID_C_COMPANY_NAME
@ WID_C_COMPANY_NAME
Button to change company name.
Definition: company_widget.h:33
tilehighlight_func.h
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:732
SignalMaintenanceCost
Money SignalMaintenanceCost(uint32_t num)
Calculates the maintenance cost of a number of signals.
Definition: rail.h:441
WC_BUY_COMPANY
@ WC_BUY_COMPANY
Buyout company (merger); Window numbers:
Definition: window_type.h:589
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
_expenses_list_capital_costs
static const std::initializer_list< ExpensesType > _expenses_list_capital_costs
List of capital expenses.
Definition: company_gui.cpp:76
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:343
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1747
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
LIT_ALL
static const byte LIT_ALL
Show the liveries of all companies.
Definition: livery.h:18
VEH_COMPANY_END
@ VEH_COMPANY_END
Last company-ownable type.
Definition: vehicle_type.h:29
DirtyCompanyInfrastructureWindows
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Definition: company_gui.cpp:2651
WID_SCMF_CAPTION
@ WID_SCMF_CAPTION
Caption of window.
Definition: company_widget.h:106
WID_SCMF_LIPS_MOUSTACHE
@ WID_SCMF_LIPS_MOUSTACHE
Lips / Moustache.
Definition: company_widget.h:150
DoSelectCompanyManagerFace
static void DoSelectCompanyManagerFace(Window *parent)
Company GUI constants.
Definition: company_gui.cpp:1776
RoadTypes
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:38
AddDateIntroducedRailTypes
RailTypes AddDateIntroducedRailTypes(RailTypes current, TimerGameCalendar::Date date)
Add the rail types that are to be introduced at the given date.
Definition: rail.cpp:218
SelectCompanyManagerFaceWindow::SetFaceStringParameters
void SetFaceStringParameters(WidgetID widget_index, uint8_t val, bool is_bool_widget) const
Set parameters for value of face control buttons.
Definition: company_gui.cpp:1381
WID_SCMF_GLASSES
@ WID_SCMF_GLASSES
Glasses.
Definition: company_widget.h:168
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
WID_SCL_PRI_COL_DROPDOWN
@ WID_SCL_PRI_COL_DROPDOWN
Dropdown for primary colour.
Definition: company_widget.h:93
WID_C_SELECT_HOSTILE_TAKEOVER
@ WID_C_SELECT_HOSTILE_TAKEOVER
Selection widget for the hostile takeover button.
Definition: company_widget.h:47
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:234
ShowCompanyInfrastructure
static void ShowCompanyInfrastructure(CompanyID company)
Open the infrastructure window of a company.
Definition: company_gui.cpp:2152
CompanyProperties::colour
Colours colour
Company colour.
Definition: company_base.h:72
CompanyProperties::money
Money money
Money owned by the company.
Definition: company_base.h:67
BuyCompanyWindow::rescale_interval
IntervalTimer< TimerWindow > rescale_interval
Check on a regular interval if the company value has changed.
Definition: company_gui.cpp:2727
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
CompanyInfrastructureWindow::roadtypes
RoadTypes roadtypes
Valid roadtypes.
Definition: company_gui.cpp:1827
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:135
station_func.h
WID_SCMF_HAS_GLASSES
@ WID_SCMF_HAS_GLASSES
Has glasses.
Definition: company_widget.h:139
WID_SCMF_SAVE
@ WID_SCMF_SAVE
Save face.
Definition: company_widget.h:123
CompanyFinancesWindow::small
bool small
Window is toggled to 'small'.
Definition: company_gui.cpp:335
WID_SCMF_COLLAR
@ WID_SCMF_COLLAR
Collar.
Definition: company_widget.h:162
Scrollbar::GetCapacity
uint16_t GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:711
LIT_COMPANY
static const byte LIT_COMPANY
Show the liveries of your own company.
Definition: livery.h:17
WID_C_SELECT_VIEW_BUILD_HQ
@ WID_C_SELECT_VIEW_BUILD_HQ
Panel about HQ.
Definition: company_widget.h:35
WID_SCMF_CHIN_R
@ WID_SCMF_CHIN_R
Chin right.
Definition: company_widget.h:145
dropdown_type.h
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
Livery::in_use
byte in_use
Bit 0 set if this livery should override the default livery first colour, Bit 1 for the second colour...
Definition: livery.h:79
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:953
WID_SCMF_TIE_EARRING
@ WID_SCMF_TIE_EARRING
Tie / Earring.
Definition: company_widget.h:165
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition: settings_type.h:628
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:322
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:24
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
WID_SCMF_JACKET
@ WID_SCMF_JACKET
Jacket.
Definition: company_widget.h:159
GetTotalCategoriesHeight
static uint GetTotalCategoriesHeight()
Get the total height of the "categories" column.
Definition: company_gui.cpp:119
safeguards.h
sortlist_type.h
ShowQueryString
void ShowQueryString(StringID 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:1086
WID_SCL_CLASS_AIRCRAFT
@ WID_SCL_CLASS_AIRCRAFT
Class aircraft.
Definition: company_widget.h:87
Window::LowerWidget
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition: window_gui.h:460
timer.h
WID_SCL_CLASS_SHIP
@ WID_SCL_CLASS_SHIP
Class ship.
Definition: company_widget.h:86
WID_SCMF_RANDOM_NEW_FACE
@ WID_SCMF_RANDOM_NEW_FACE
Create random new face.
Definition: company_widget.h:118
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
GetStringHeight
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:705
WID_SCL_GROUPS_SHIP
@ WID_SCL_GROUPS_SHIP
Ship groups.
Definition: company_widget.h:90
WID_CF_LOAN_VALUE
@ WID_CF_LOAN_VALUE
Loan.
Definition: company_widget.h:68
WID_CI_CAPTION
@ WID_CI_CAPTION
Caption of window.
Definition: company_widget.h:174
CompanyProperties::location_of_HQ
TileIndex location_of_HQ
Northern tile of HQ; INVALID_TILE when there is none.
Definition: company_base.h:76
WID_SCL_GROUPS_RAIL
@ WID_SCL_GROUPS_RAIL
Rail groups.
Definition: company_widget.h:88
CompanyManagerFace
uint32_t CompanyManagerFace
Company manager face bits, info see in company_manager_face.h.
Definition: company_type.h:52
WID_C_DESC_INFRASTRUCTURE_COUNTS
@ WID_C_DESC_INFRASTRUCTURE_COUNTS
Infrastructure count.
Definition: company_widget.h:27
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:59
rail.h
_shift_pressed
bool _shift_pressed
Is Shift pressed?
Definition: gfx.cpp:38
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:1007
CompanyFinancesWindow::max_money
static Money max_money
The maximum amount of money a company has had this 'run'.
Definition: company_gui.cpp:334
road.h
AirportMaintenanceCost
Money AirportMaintenanceCost(Owner owner)
Calculates the maintenance cost of all airports of a company.
Definition: station.cpp:702
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
RoadTypeInfo::name
StringID name
Name of this rail type.
Definition: road.h:103
error.h
Company::GetMaxLoan
Money GetMaxLoan() const
Calculate the max allowed loan for this company.
Definition: company_cmd.cpp:102
WID_BC_CAPTION
@ WID_BC_CAPTION
Caption of window.
Definition: company_widget.h:191
WID_CI_TRAM_DESC
@ WID_CI_TRAM_DESC
Description of tram.
Definition: company_widget.h:179
WID_C_HAS_PASSWORD
@ WID_C_HAS_PASSWORD
Has company password lock.
Definition: company_widget.h:50
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:166
_loaded_newgrf_features
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
Definition: newgrf.cpp:82
_expenses_list_revenue
static const std::initializer_list< ExpensesType > _expenses_list_revenue
List of revenues.
Definition: company_gui.cpp:58
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
WID_CF_EXPS_PRICE3
@ WID_CF_EXPS_PRICE3
Column for year Y expenses.
Definition: company_widget.h:64
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:113
GroupStatistics::num_vehicle
uint16_t num_vehicle
Number of vehicles.
Definition: group.h:28
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:3140
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:25
viewport_func.h
NetworkCompanyIsPassworded
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
Definition: network.cpp:209
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:339
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:441
object_cmd.h
WID_C_FACE_TITLE
@ WID_C_FACE_TITLE
Title for the face.
Definition: company_widget.h:18
NETWORK_PASSWORD_LENGTH
static const uint NETWORK_PASSWORD_LENGTH
The maximum length of the password, in bytes including '\0' (must be >= NETWORK_SERVER_ID_LENGTH)
Definition: config.h:59
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
WID_SCL_GROUPS_ROAD
@ WID_SCL_GROUPS_ROAD
Road groups.
Definition: company_widget.h:89
WID_C_DESC_COMPANY_VALUE
@ WID_C_DESC_COMPANY_VALUE
Company value.
Definition: company_widget.h:25
Scrollbar::GetScrolledRowFromWidget
int 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:2260
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
GetRoadTypeInfo
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:227
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
group_cmd.h
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:941
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
WID_BC_FACE
@ WID_BC_FACE
Face button.
Definition: company_widget.h:192
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:430
WID_CF_SEL_PANEL
@ WID_CF_SEL_PANEL
Select panel or nothing.
Definition: company_widget.h:60
WID_SCMF_EYECOLOUR_TEXT
@ WID_SCMF_EYECOLOUR_TEXT
Text about eyecolour.
Definition: company_widget.h:130
WID_C_SELECT_BUTTONS
@ WID_C_SELECT_BUTTONS
Selection widget for the button bar.
Definition: company_widget.h:29
WID_BC_QUESTION
@ WID_BC_QUESTION
Question text.
Definition: company_widget.h:193
AddDateIntroducedRoadTypes
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date date)
Add the road types that are to be introduced at the given date.
Definition: road.cpp:166
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:395
WID_SCMF_EYECOLOUR_R
@ WID_SCMF_EYECOLOUR_R
Eyecolour right.
Definition: company_widget.h:142
EconomySettings::infrastructure_maintenance
bool infrastructure_maintenance
enable monthly maintenance fee for owner infrastructure
Definition: settings_type.h:560
WID_SCMF_FEMALE2
@ WID_SCMF_FEMALE2
Female button in the advanced view.
Definition: company_widget.h:114
WID_SCMF_NOSE_L
@ WID_SCMF_NOSE_L
Nose left.
Definition: company_widget.h:152
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:491
CompanyProperties::inaugurated_year
TimerGameEconomy::Year inaugurated_year
Economy year of starting the company.
Definition: company_base.h:79
LiveryClass
LiveryClass
List of different livery classes, used only by the livery GUI.
Definition: livery.h:63
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:775
WID_SCMF_NOSE_R
@ WID_SCMF_NOSE_R
Nose right.
Definition: company_widget.h:154
WID_SCMF_HAIR
@ WID_SCMF_HAIR
Hair.
Definition: company_widget.h:156
WID_SCMF_CHIN_L
@ WID_SCMF_CHIN_L
Chin left.
Definition: company_widget.h:143
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:231
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:384
WID_SCMF_FACE
@ WID_SCMF_FACE
Current face.
Definition: company_widget.h:120
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
TimerGameEconomy::year
static Year year
Current year, starting at 0.
Definition: timer_game_economy.h:35
WID_SCL_MATRIX_SCROLLBAR
@ WID_SCL_MATRIX_SCROLLBAR
Matrix scrollbar.
Definition: company_widget.h:96
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:349
CompanyInfrastructure::GetTramTotal
uint32_t GetTramTotal() const
Get total sum of all owned tram bits.
Definition: company_cmd.cpp:1219
WID_CI_STATION_COUNT
@ WID_CI_STATION_COUNT
Count of station.
Definition: company_widget.h:184
WID_SCMF_EYEBROWS_R
@ WID_SCMF_EYEBROWS_R
Eyebrows right.
Definition: company_widget.h:148
WID_SCMF_FACECODE
@ WID_SCMF_FACECODE
Get the face code.
Definition: company_widget.h:122
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:556
WID_C_DESC_INAUGURATION
@ WID_C_DESC_INAUGURATION
Inauguration.
Definition: company_widget.h:20
CompanyInfrastructure::airport
uint32_t airport
Count of company owned airports.
Definition: company_base.h:38
WID_C_COMPANY_PASSWORD
@ WID_C_COMPANY_PASSWORD
Button to set company password.
Definition: company_widget.h:52
WID_SCMF_HAS_MOUSTACHE_EARRING
@ WID_SCMF_HAS_MOUSTACHE_EARRING
Has moustache or earring.
Definition: company_widget.h:138
BuyCompanyWindow::company_value
Money company_value
The value of the company for which the user can buy it.
Definition: company_gui.cpp:2741
WID_CI_STATION_DESC
@ WID_CI_STATION_DESC
Description of station.
Definition: company_widget.h:183
SelectCompanyLiveryWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: company_gui.cpp:836
GetCompanyManagerFaceSprite
SpriteID GetCompanyManagerFaceSprite(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
Gets the sprite to draw for the given company manager's face variable.
Definition: company_manager_face.h:232
CompanyWidgets
CompanyWidgets
Widgets of the CompanyWindow class.
Definition: company_widget.h:14
WID_CF_INTEREST_RATE
@ WID_CF_INTEREST_RATE
Loan interest rate.
Definition: company_widget.h:71
CompanyInfrastructure::signal
uint32_t signal
Count of company owned signals.
Definition: company_base.h:34
SelectCompanyManagerFaceWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: company_gui.cpp:1442
CompanyProperties::yearly_expenses
std::array< Expenses, 3 > yearly_expenses
Expenses of the company for the last three years.
Definition: company_base.h:97
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:60
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:1220
WID_SCL_CLASS_RAIL
@ WID_SCL_CLASS_RAIL
Class rail.
Definition: company_widget.h:84
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
SetDParamMaxValue
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:127
WID_C_VIEW_HQ
@ WID_C_VIEW_HQ
Button to view the HQ.
Definition: company_widget.h:36
CompanyFinancesWindow
Window class displaying the company finances.
Definition: company_gui.cpp:333
WID_C_COLOUR_SCHEME
@ WID_C_COLOUR_SCHEME
Button to change colour scheme.
Definition: company_widget.h:31
company_widget.h
_company_manager_face
CompanyManagerFace _company_manager_face
for company manager face storage in openttd.cfg
Definition: company_cmd.cpp:52
WID_SCMF_COLLAR_R
@ WID_SCMF_COLLAR_R
Collar right.
Definition: company_widget.h:163
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
RAILTYPE_END
@ RAILTYPE_END
Used for iterations.
Definition: rail_type.h:33
CompanyWindow::CompanyWindowPlanes
CompanyWindowPlanes
Display planes in the company window.
Definition: company_gui.cpp:2251
geometry_func.hpp
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:308
WID_SCMF_ETHNICITY_AFR
@ WID_SCMF_ETHNICITY_AFR
Text about ethnicity african.
Definition: company_widget.h:137
Livery::colour1
Colours colour1
First colour, for all vehicles.
Definition: livery.h:80
Window::OnInvalidateData
virtual void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true)
Some data on this window has become invalid.
Definition: window_gui.h:779
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
@ WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
Text about moustache and earring.
Definition: company_widget.h:124
WID_CI_TOTAL_DESC
@ WID_CI_TOTAL_DESC
Description of total.
Definition: company_widget.h:185
SelectCompanyManagerFaceWindow::is_moust_male
bool is_moust_male
Male face with a moustache.
Definition: company_gui.cpp:1369
WID_CF_OWN_VALUE
@ WID_CF_OWN_VALUE
Own funds, not including loan.
Definition: company_widget.h:70
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
WID_C_DESC_INFRASTRUCTURE
@ WID_C_DESC_INFRASTRUCTURE
Infrastructure.
Definition: company_widget.h:26
CompanyWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: company_gui.cpp:2272
newgrf.h
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:327
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:117
WC_COMPANY_INFRASTRUCTURE
@ WC_COMPANY_INFRASTRUCTURE
Company infrastructure overview; Window numbers:
Definition: window_type.h:582
CompanyInfrastructure::GetRoadTotal
uint32_t GetRoadTotal() const
Get total sum of all owned road bits.
Definition: company_cmd.cpp:1206
HT_RECT
@ HT_RECT
rectangle (stations, depots, ...)
Definition: tilehighlight_type.h:21
ExpensesList::items
const std::initializer_list< ExpensesType > & items
List of expenses types.
Definition: company_gui.cpp:85
WID_SCMF_LOAD
@ WID_SCMF_LOAD
Load face.
Definition: company_widget.h:121
_select_company_manager_face_desc
static WindowDesc _select_company_manager_face_desc(__FILE__, __LINE__, WDP_AUTO, nullptr, 0, 0, WC_COMPANY_MANAGER_FACE, WC_NONE, WDF_CONSTRUCTION, std::begin(_nested_select_company_manager_face_widgets), std::end(_nested_select_company_manager_face_widgets))
Company manager face selection window description.
WID_SCMF_CANCEL
@ WID_SCMF_CANCEL
Cancel.
Definition: company_widget.h:109
WID_CI_ROAD_COUNT
@ WID_CI_ROAD_COUNT
Count of road.
Definition: company_widget.h:178
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:25
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
GroupID
uint16_t GroupID
Type for all group identifiers.
Definition: group_type.h:13
SelectCompanyManagerFaceWindow::is_female
bool is_female
Female face.
Definition: company_gui.cpp:1368
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:55
EXPENSES_PROPERTY
@ EXPENSES_PROPERTY
Property costs.
Definition: economy_type.h:179
CompanyWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: company_gui.cpp:2596
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:81
company_func.h
EXPENSES_NEW_VEHICLES
@ EXPENSES_NEW_VEHICLES
New vehicles.
Definition: economy_type.h:174
WID_CF_SEL_MAXLOAN
@ WID_CF_SEL_MAXLOAN
Selection of maxloan column.
Definition: company_widget.h:66
WID_C_BUILD_HQ
@ WID_C_BUILD_HQ
Button to build the HQ.
Definition: company_widget.h:37
WID_C_DESC_VEHICLE_COUNTS
@ WID_C_DESC_VEHICLE_COUNTS
Vehicle count.
Definition: company_widget.h:24
Window::SetWidgetsLoweredState
void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
Sets the lowered/raised status of a list of widgets.
Definition: window_gui.h:526
Window::RaiseWidget
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition: window_gui.h:469
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:338
RailTypeInfo::introduces_railtypes
RailTypes introduces_railtypes
Bitmask of which other railtypes are introduced when this railtype is introduced.
Definition: rail.h:266
SetCompanyManagerFaceBits
void SetCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, [[maybe_unused]] GenderEthnicity ge, uint val)
Sets the company manager's face bits for the given company manager's face variable.
Definition: company_manager_face.h:111
network.h
CommandHelper
Definition: command_func.h:93
DrawCompanyManagerFace
void DrawCompanyManagerFace(CompanyManagerFace cmf, Colours colour, const Rect &r)
Draws the face of a company manager's face.
Definition: company_gui.cpp:1162
window_func.h
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:348
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1552
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:1232
EXPENSES_TRAIN_RUN
@ EXPENSES_TRAIN_RUN
Running costs trains.
Definition: economy_type.h:175
IncreaseCompanyManagerFaceBits
void IncreaseCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, int8_t amount)
Increase/Decrease the company manager's face variable by the given amount.
Definition: company_manager_face.h:130
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:405
WID_C_SELECT_MULTIPLAYER
@ WID_C_SELECT_MULTIPLAYER
Multiplayer selection panel.
Definition: company_widget.h:51
OverflowSafeInt< int64_t >
_company_view_vehicle_count_strings
static const StringID _company_view_vehicle_count_strings[]
Strings for the company vehicle counts.
Definition: company_gui.cpp:2239
CompanyWindow::CWP_VB_BUILD
@ CWP_VB_BUILD
Display the build button.
Definition: company_gui.cpp:2258
CompanyInfrastructureWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: company_gui.cpp:2132
WID_SCMF_GLASSES_TEXT
@ WID_SCMF_GLASSES_TEXT
Text about glasses.
Definition: company_widget.h:131
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:658
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:3420
timer_window.h
engine_base.h
WID_C_FACE
@ WID_C_FACE
View of the face.
Definition: company_widget.h:17
WID_SCMF_EYEBROWS_L
@ WID_SCMF_EYEBROWS_L
Eyebrows left.
Definition: company_widget.h:146
SelectCompanyManagerFaceWindow::yesno_dim
Dimension yesno_dim
Dimension of a yes/no button of a part in the advanced face window.
Definition: company_gui.cpp:1371
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition: window_gui.h:40
WID_SCMF_CHIN_TEXT
@ WID_SCMF_CHIN_TEXT
Text about chin.
Definition: company_widget.h:133
gui.h
CompanyInfrastructureWindow::DrawCountLine
void DrawCountLine(const Rect &r, int &y, int count, Money monthly_cost) const
Helper for drawing the counts line.
Definition: company_gui.cpp:2014
BuyCompanyWindow::hostile_takeover
bool hostile_takeover
Whether the window is showing a hostile takeover.
Definition: company_gui.cpp:2740
WID_SCMF_COLLAR_L
@ WID_SCMF_COLLAR_L
Collar left.
Definition: company_widget.h:161
Window
Data structure for an opened window.
Definition: window_gui.h:267
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:324
Expenses
std::array< Money, EXPENSES_END > Expenses
Data type for storage of Money for each ExpensesType category.
Definition: economy_type.h:193
GE_WM
@ GE_WM
A male of Caucasian origin (white)
Definition: company_manager_face.h:23
WID_SCMF_SELECT_FACE
@ WID_SCMF_SELECT_FACE
Select face.
Definition: company_widget.h:108
WID_SCMF_SEL_LOADSAVE
@ WID_SCMF_SEL_LOADSAVE
Selection to display the load/save/number buttons in the advanced view.
Definition: company_widget.h:115
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
WID_SCL_SPACER_DROPDOWN
@ WID_SCL_SPACER_DROPDOWN
Spacer for dropdown.
Definition: company_widget.h:92
CompanyInfrastructureWindow::GetTotalMaintenanceCost
Money GetTotalMaintenanceCost() const
Get total infrastructure maintenance cost.
Definition: company_gui.cpp:1867
WC_FINANCES
@ WC_FINANCES
Finances of a company; Window numbers:
Definition: window_type.h:528
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
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:1109
CompanyInfrastructureWindow
Window with detailed information about the company's infrastructure.
Definition: company_gui.cpp:1824
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
ExpensesType
ExpensesType
Types of expenses.
Definition: economy_type.h:172
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition: widget.cpp:54
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
OBJECT_HQ
static const ObjectType OBJECT_HQ
HeadQuarter of a player.
Definition: object_type.h:20
SelectCompanyManagerFaceWindow::number_dim
Dimension number_dim
Dimension of a number widget of a part in the advanced face window.
Definition: company_gui.cpp:1372
ShowCompany
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
Definition: company_gui.cpp:2640
GUISettings::liveries
byte liveries
options for displaying company liveries, 0=none, 1=self, 2=all
Definition: settings_type.h:148
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
Company
Definition: company_base.h:116
WID_SCMF_EYEBROWS
@ WID_SCMF_EYEBROWS
Eyebrows.
Definition: company_widget.h:147
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1224
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:1427
Livery::colour2
Colours colour2
Second colour, for vehicles with 2CC support.
Definition: livery.h:81
RandomCompanyManagerFaceBits
void RandomCompanyManagerFaceBits(CompanyManagerFace &cmf, GenderEthnicity ge, bool adv, Randomizer &randomizer)
Make a random new face.
Definition: company_manager_face.h:206
_cmf_info
static const CompanyManagerFaceBitsInfo _cmf_info[]
Lookup table for indices into the CompanyManagerFace, valid ranges and sprites.
Definition: company_manager_face.h:64
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:268
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:34
CompanyWindow::redraw_interval
IntervalTimer< TimerWindow > redraw_interval
Redraw the window on a regular interval.
Definition: company_gui.cpp:2584
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition: window_gui.h:515
WID_CI_TOTAL
@ WID_CI_TOTAL
Count of total.
Definition: company_widget.h:186
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
ETHNICITY_BLACK
@ ETHNICITY_BLACK
This bit set means black, otherwise white.
Definition: company_manager_face.h:21
EXPENSES_ROADVEH_REVENUE
@ EXPENSES_ROADVEH_REVENUE
Revenue from road vehicles.
Definition: economy_type.h:181
ROADTYPE_BEGIN
@ ROADTYPE_BEGIN
Used for iterations.
Definition: road_type.h:26
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
DropDownListItem::masked
bool masked
Masked and unselectable item.
Definition: dropdown_type.h:28
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition: network_type.h:51
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
CalculateHostileTakeoverValue
Money CalculateHostileTakeoverValue(const Company *c)
Calculate what you have to pay to take over a company.
Definition: economy.cpp:176
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3483
Livery
Information about a particular livery.
Definition: livery.h:78
GetMaxCategoriesWidth
static uint GetMaxCategoriesWidth()
Get the required width of the "categories" column, equal to the widest element.
Definition: company_gui.cpp:139
ScaleAllCompanyManagerFaceBits
void ScaleAllCompanyManagerFaceBits(CompanyManagerFace &cmf)
Scales all company manager's face bits to the correct scope.
Definition: company_manager_face.h:176
WID_C_SELECT_GIVE_MONEY
@ WID_C_SELECT_GIVE_MONEY
Selection widget for the give money button.
Definition: company_widget.h:44
CompanyInfrastructure::water
uint32_t water
Count of company owned track bits for canals.
Definition: company_base.h:36
EXPENSES_AIRCRAFT_REVENUE
@ EXPENSES_AIRCRAFT_REVENUE
Revenue from aircraft.
Definition: economy_type.h:182
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
network_func.h
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition: widget_type.h:1120
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition: string_type.h:26
WID_SCMF_GLASSES_R
@ WID_SCMF_GLASSES_R
Glasses right.
Definition: company_widget.h:169
WID_SCMF_TOGGLE_LARGE_SMALL
@ WID_SCMF_TOGGLE_LARGE_SMALL
Toggle for large or small.
Definition: company_widget.h:107
ToggleBit
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Definition: bitmath_func.hpp:181
EXPENSES_SHIP_RUN
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition: economy_type.h:178
WID_C_SELECT_RELOCATE
@ WID_C_SELECT_RELOCATE
Panel about 'Relocate HQ'.
Definition: company_widget.h:39
EXPENSES_LOAN_INTEREST
@ EXPENSES_LOAN_INTEREST
Interest payments over the loan.
Definition: economy_type.h:184
CompanyWindow::CWP_VB_VIEW
@ CWP_VB_VIEW
Display the view button.
Definition: company_gui.cpp:2257
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
object_type.h
timer_game_economy.h
CompanyInfrastructureWindow::railtypes
RailTypes railtypes
Valid railtypes.
Definition: company_gui.cpp:1826
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
_expenses_list_types
static const std::initializer_list< ExpensesList > _expenses_list_types
Types of expense lists.
Definition: company_gui.cpp:109
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
WID_SCMF_MALE
@ WID_SCMF_MALE
Male button in the simple view.
Definition: company_widget.h:111
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
Scrollbar::SetPosition
bool SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:790
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:33
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:72
WID_C_HOSTILE_TAKEOVER
@ WID_C_HOSTILE_TAKEOVER
Button to hostile takeover another company.
Definition: company_widget.h:48
CompanyInfrastructure::rail
uint32_t rail[RAILTYPE_END]
Count of company owned track bits for each rail type.
Definition: company_base.h:35
WID_C_DESC_VEHICLE
@ WID_C_DESC_VEHICLE
Vehicles.
Definition: company_widget.h:23
WID_CI_TRAM_COUNT
@ WID_CI_TRAM_COUNT
Count of tram.
Definition: company_widget.h:180
WID_CF_BALANCE_VALUE
@ WID_CF_BALANCE_VALUE
Bank balance value.
Definition: company_widget.h:67
WID_CF_EXPS_PRICE1
@ WID_CF_EXPS_PRICE1
Column for year Y-2 expenses.
Definition: company_widget.h:62
EXPENSES_SHIP_REVENUE
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
Definition: economy_type.h:183
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:157
ShowBuyCompanyDialog
void ShowBuyCompanyDialog(CompanyID company, bool hostile_takeover)
Show the query to buy another company.
Definition: company_gui.cpp:2775
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
RAILTYPE_BEGIN
@ RAILTYPE_BEGIN
Used for iterations.
Definition: rail_type.h:28
CompanyWindow::CWP_RELOCATE_HIDE
@ CWP_RELOCATE_HIDE
Hide the relocate HQ button.
Definition: company_gui.cpp:2262
CompanyWindow
Window with general information about a company.
Definition: company_gui.cpp:2246
RAILTYPES_NONE
@ RAILTYPES_NONE
No rail types.
Definition: rail_type.h:45
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103