OpenTTD Source: src/company_gui.cpp Source File

OpenTTD Source 14.0-RC3

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 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1115 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1116 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1117 EndContainer(),
1118 NWidget(NWID_HORIZONTAL),
1119 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_GENERAL), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_COMPANY_GENERAL, STR_LIVERY_GENERAL_TOOLTIP),
1120 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_RAIL), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRAINLIST, STR_LIVERY_TRAIN_TOOLTIP),
1121 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_ROAD), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRUCKLIST, STR_LIVERY_ROAD_VEHICLE_TOOLTIP),
1122 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_SHIP), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SHIPLIST, STR_LIVERY_SHIP_TOOLTIP),
1123 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCL_CLASS_AIRCRAFT), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_AIRPLANESLIST, STR_LIVERY_AIRCRAFT_TOOLTIP),
1124 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),
1125 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),
1126 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),
1127 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),
1128 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 0), EndContainer(),
1129 EndContainer(),
1130 NWidget(NWID_HORIZONTAL),
1131 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),
1132 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SCL_MATRIX_SCROLLBAR),
1133 EndContainer(),
1134 NWidget(NWID_HORIZONTAL),
1135 NWidget(WWT_PANEL, COLOUR_GREY, WID_SCL_SPACER_DROPDOWN), SetFill(1, 1), SetResize(1, 0), EndContainer(),
1136 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SCL_PRI_COL_DROPDOWN), SetFill(0, 1), SetDataTip(STR_JUST_STRING, STR_LIVERY_PRIMARY_TOOLTIP),
1137 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SCL_SEC_COL_DROPDOWN), SetFill(0, 1), SetDataTip(STR_JUST_STRING, STR_LIVERY_SECONDARY_TOOLTIP),
1138 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1139 EndContainer(),
1140 };
1141
1142 static WindowDesc _select_company_livery_desc(__FILE__, __LINE__,
1143 WDP_AUTO, "company_color_scheme", 0, 0,
1144 WC_COMPANY_COLOUR, WC_NONE,
1145 0,
1146 std::begin(_nested_select_company_livery_widgets), std::end(_nested_select_company_livery_widgets)
1147 );
1148
1149 void ShowCompanyLiveryWindow(CompanyID company, GroupID group)
1150 {
1151 SelectCompanyLiveryWindow *w = (SelectCompanyLiveryWindow *)BringWindowToFrontById(WC_COMPANY_COLOUR, company);
1152 if (w == nullptr) {
1153 new SelectCompanyLiveryWindow(&_select_company_livery_desc, company, group);
1154 } else if (group != INVALID_GROUP) {
1155 w->SetSelectedGroup(company, group);
1156 }
1157 }
1158
1165 void DrawCompanyManagerFace(CompanyManagerFace cmf, Colours colour, const Rect &r)
1166 {
1167 GenderEthnicity ge = (GenderEthnicity)GetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN, GE_WM);
1168
1169 /* Determine offset from centre of drawing rect. */
1170 Dimension d = GetSpriteSize(SPR_GRADIENT);
1171 int x = CenterBounds(r.left, r.right, d.width);
1172 int y = CenterBounds(r.top, r.bottom, d.height);
1173
1174 bool has_moustache = !HasBit(ge, GENDER_FEMALE) && GetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge) != 0;
1175 bool has_tie_earring = !HasBit(ge, GENDER_FEMALE) || GetCompanyManagerFaceBits(cmf, CMFV_HAS_TIE_EARRING, ge) != 0;
1176 bool has_glasses = GetCompanyManagerFaceBits(cmf, CMFV_HAS_GLASSES, ge) != 0;
1177 PaletteID pal;
1178
1179 /* Modify eye colour palette only if 2 or more valid values exist */
1180 if (_cmf_info[CMFV_EYE_COLOUR].valid_values[ge] < 2) {
1181 pal = PAL_NONE;
1182 } else {
1183 switch (GetCompanyManagerFaceBits(cmf, CMFV_EYE_COLOUR, ge)) {
1184 default: NOT_REACHED();
1185 case 0: pal = PALETTE_TO_BROWN; break;
1186 case 1: pal = PALETTE_TO_BLUE; break;
1187 case 2: pal = PALETTE_TO_GREEN; break;
1188 }
1189 }
1190
1191 /* Draw the gradient (background) */
1192 DrawSprite(SPR_GRADIENT, GENERAL_SPRITE_COLOUR(colour), x, y);
1193
1194 for (CompanyManagerFaceVariable cmfv = CMFV_CHEEKS; cmfv < CMFV_END; cmfv++) {
1195 switch (cmfv) {
1196 case CMFV_MOUSTACHE: if (!has_moustache) continue; break;
1197 case CMFV_LIPS:
1198 case CMFV_NOSE: if (has_moustache) continue; break;
1199 case CMFV_TIE_EARRING: if (!has_tie_earring) continue; break;
1200 case CMFV_GLASSES: if (!has_glasses) continue; break;
1201 default: break;
1202 }
1203 DrawSprite(GetCompanyManagerFaceSprite(cmf, cmfv, ge), (cmfv == CMFV_EYEBROWS) ? pal : PAL_NONE, x, y);
1204 }
1205 }
1206
1208 static constexpr NWidgetPart _nested_select_company_manager_face_widgets[] = {
1209 NWidget(NWID_HORIZONTAL),
1210 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1211 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SCMF_CAPTION), SetDataTip(STR_FACE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1212 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_SCMF_TOGGLE_LARGE_SMALL), SetDataTip(SPR_LARGE_SMALL_WINDOW, STR_FACE_ADVANCED_TOOLTIP),
1213 EndContainer(),
1214 NWidget(WWT_PANEL, COLOUR_GREY, WID_SCMF_SELECT_FACE),
1215 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), SetPadding(2),
1216 /* Left side */
1217 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1218 NWidget(NWID_HORIZONTAL), SetPIPRatio(1, 0, 1),
1219 NWidget(WWT_EMPTY, COLOUR_GREY, WID_SCMF_FACE), SetMinimalSize(92, 119), SetFill(1, 0),
1220 EndContainer(),
1221 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_RANDOM_NEW_FACE), SetFill(1, 0), SetDataTip(STR_FACE_NEW_FACE_BUTTON, STR_FACE_NEW_FACE_TOOLTIP),
1222 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCMF_SEL_LOADSAVE), // Load/number/save buttons under the portrait in the advanced view.
1223 NWidget(NWID_VERTICAL), SetPIP(0, 0, 0), SetPIPRatio(1, 0, 1),
1224 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_LOAD), SetFill(1, 0), SetDataTip(STR_FACE_LOAD, STR_FACE_LOAD_TOOLTIP),
1225 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_FACECODE), SetFill(1, 0), SetDataTip(STR_FACE_FACECODE, STR_FACE_FACECODE_TOOLTIP),
1226 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_SAVE), SetFill(1, 0), SetDataTip(STR_FACE_SAVE, STR_FACE_SAVE_TOOLTIP),
1227 EndContainer(),
1228 EndContainer(),
1229 EndContainer(),
1230 /* Right side */
1231 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1232 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON), SetFill(1, 0), SetDataTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP),
1233 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCMF_SEL_MALEFEMALE), // Simple male/female face setting.
1234 NWidget(NWID_VERTICAL), SetPIPRatio(1, 0, 1),
1235 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCMF_MALE), SetFill(1, 0), SetDataTip(STR_FACE_MALE_BUTTON, STR_FACE_MALE_TOOLTIP),
1236 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCMF_FEMALE), SetFill(1, 0), SetDataTip(STR_FACE_FEMALE_BUTTON, STR_FACE_FEMALE_TOOLTIP),
1237 EndContainer(),
1238 EndContainer(),
1239 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCMF_SEL_PARTS), // Advanced face parts setting.
1240 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1241 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1242 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCMF_MALE2), SetFill(1, 0), SetDataTip(STR_FACE_MALE_BUTTON, STR_FACE_MALE_TOOLTIP),
1243 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCMF_FEMALE2), SetFill(1, 0), SetDataTip(STR_FACE_FEMALE_BUTTON, STR_FACE_FEMALE_TOOLTIP),
1244 EndContainer(),
1245 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1246 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCMF_ETHNICITY_EUR), SetFill(1, 0), SetDataTip(STR_FACE_EUROPEAN, STR_FACE_SELECT_EUROPEAN),
1247 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCMF_ETHNICITY_AFR), SetFill(1, 0), SetDataTip(STR_FACE_AFRICAN, STR_FACE_SELECT_AFRICAN),
1248 EndContainer(),
1249 NWidget(NWID_VERTICAL),
1250 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1251 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT), SetFill(1, 0),
1252 SetDataTip(STR_FACE_EYECOLOUR, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1253 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_HAS_MOUSTACHE_EARRING), SetDataTip(STR_JUST_STRING1, STR_FACE_MOUSTACHE_EARRING_TOOLTIP), SetTextStyle(TC_WHITE),
1254 EndContainer(),
1255 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1256 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_HAS_GLASSES_TEXT), SetFill(1, 0),
1257 SetDataTip(STR_FACE_GLASSES, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1258 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_HAS_GLASSES), SetDataTip(STR_JUST_STRING1, STR_FACE_GLASSES_TOOLTIP), SetTextStyle(TC_WHITE),
1259 EndContainer(),
1260 EndContainer(),
1261 NWidget(NWID_VERTICAL),
1262 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1263 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_HAIR_TEXT), SetFill(1, 0),
1264 SetDataTip(STR_FACE_HAIR, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1265 NWidget(NWID_HORIZONTAL),
1266 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_HAIR_L), SetDataTip(AWV_DECREASE, STR_FACE_HAIR_TOOLTIP),
1267 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_HAIR), SetDataTip(STR_JUST_STRING1, STR_FACE_HAIR_TOOLTIP), SetTextStyle(TC_WHITE),
1268 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_HAIR_R), SetDataTip(AWV_INCREASE, STR_FACE_HAIR_TOOLTIP),
1269 EndContainer(),
1270 EndContainer(),
1271 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1272 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_EYEBROWS_TEXT), SetFill(1, 0),
1273 SetDataTip(STR_FACE_EYEBROWS, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1274 NWidget(NWID_HORIZONTAL),
1275 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_EYEBROWS_L), SetDataTip(AWV_DECREASE, STR_FACE_EYEBROWS_TOOLTIP),
1276 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_EYEBROWS), SetDataTip(STR_JUST_STRING1, STR_FACE_EYEBROWS_TOOLTIP), SetTextStyle(TC_WHITE),
1277 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_EYEBROWS_R), SetDataTip(AWV_INCREASE, STR_FACE_EYEBROWS_TOOLTIP),
1278 EndContainer(),
1279 EndContainer(),
1280 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1281 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_EYECOLOUR_TEXT), SetFill(1, 0),
1282 SetDataTip(STR_FACE_EYECOLOUR, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1283 NWidget(NWID_HORIZONTAL),
1284 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_EYECOLOUR_L), SetDataTip(AWV_DECREASE, STR_FACE_EYECOLOUR_TOOLTIP),
1285 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_EYECOLOUR), SetDataTip(STR_JUST_STRING1, STR_FACE_EYECOLOUR_TOOLTIP), SetTextStyle(TC_WHITE),
1286 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_EYECOLOUR_R), SetDataTip(AWV_INCREASE, STR_FACE_EYECOLOUR_TOOLTIP),
1287 EndContainer(),
1288 EndContainer(),
1289 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1290 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_GLASSES_TEXT), SetFill(1, 0),
1291 SetDataTip(STR_FACE_GLASSES, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1292 NWidget(NWID_HORIZONTAL),
1293 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_GLASSES_L), SetDataTip(AWV_DECREASE, STR_FACE_GLASSES_TOOLTIP_2),
1294 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_GLASSES), SetDataTip(STR_JUST_STRING1, STR_FACE_GLASSES_TOOLTIP_2), SetTextStyle(TC_WHITE),
1295 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_GLASSES_R), SetDataTip(AWV_INCREASE, STR_FACE_GLASSES_TOOLTIP_2),
1296 EndContainer(),
1297 EndContainer(),
1298 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1299 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_NOSE_TEXT), SetFill(1, 0),
1300 SetDataTip(STR_FACE_NOSE, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1301 NWidget(NWID_HORIZONTAL),
1302 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_NOSE_L), SetDataTip(AWV_DECREASE, STR_FACE_NOSE_TOOLTIP),
1303 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_NOSE), SetDataTip(STR_JUST_STRING1, STR_FACE_NOSE_TOOLTIP), SetTextStyle(TC_WHITE),
1304 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_NOSE_R), SetDataTip(AWV_INCREASE, STR_FACE_NOSE_TOOLTIP),
1305 EndContainer(),
1306 EndContainer(),
1307 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1308 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_LIPS_MOUSTACHE_TEXT), SetFill(1, 0),
1309 SetDataTip(STR_FACE_MOUSTACHE, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1310 NWidget(NWID_HORIZONTAL),
1311 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_LIPS_MOUSTACHE_L), SetDataTip(AWV_DECREASE, STR_FACE_LIPS_MOUSTACHE_TOOLTIP),
1312 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_LIPS_MOUSTACHE), SetDataTip(STR_JUST_STRING1, STR_FACE_LIPS_MOUSTACHE_TOOLTIP), SetTextStyle(TC_WHITE),
1313 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_LIPS_MOUSTACHE_R), SetDataTip(AWV_INCREASE, STR_FACE_LIPS_MOUSTACHE_TOOLTIP),
1314 EndContainer(),
1315 EndContainer(),
1316 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1317 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_CHIN_TEXT), SetFill(1, 0),
1318 SetDataTip(STR_FACE_CHIN, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1319 NWidget(NWID_HORIZONTAL),
1320 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_CHIN_L), SetDataTip(AWV_DECREASE, STR_FACE_CHIN_TOOLTIP),
1321 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_CHIN), SetDataTip(STR_JUST_STRING1, STR_FACE_CHIN_TOOLTIP), SetTextStyle(TC_WHITE),
1322 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_CHIN_R), SetDataTip(AWV_INCREASE, STR_FACE_CHIN_TOOLTIP),
1323 EndContainer(),
1324 EndContainer(),
1325 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1326 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_JACKET_TEXT), SetFill(1, 0),
1327 SetDataTip(STR_FACE_JACKET, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1328 NWidget(NWID_HORIZONTAL),
1329 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_JACKET_L), SetDataTip(AWV_DECREASE, STR_FACE_JACKET_TOOLTIP),
1330 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_JACKET), SetDataTip(STR_JUST_STRING1, STR_FACE_JACKET_TOOLTIP), SetTextStyle(TC_WHITE),
1331 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_JACKET_R), SetDataTip(AWV_INCREASE, STR_FACE_JACKET_TOOLTIP),
1332 EndContainer(),
1333 EndContainer(),
1334 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1335 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_COLLAR_TEXT), SetFill(1, 0),
1336 SetDataTip(STR_FACE_COLLAR, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1337 NWidget(NWID_HORIZONTAL),
1338 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_COLLAR_L), SetDataTip(AWV_DECREASE, STR_FACE_COLLAR_TOOLTIP),
1339 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_COLLAR), SetDataTip(STR_JUST_STRING1, STR_FACE_COLLAR_TOOLTIP), SetTextStyle(TC_WHITE),
1340 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_COLLAR_R), SetDataTip(AWV_INCREASE, STR_FACE_COLLAR_TOOLTIP),
1341 EndContainer(),
1342 EndContainer(),
1343 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1344 NWidget(WWT_TEXT, INVALID_COLOUR, WID_SCMF_TIE_EARRING_TEXT), SetFill(1, 0),
1345 SetDataTip(STR_FACE_EARRING, STR_NULL), SetTextStyle(TC_GOLD), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1346 NWidget(NWID_HORIZONTAL),
1347 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_TIE_EARRING_L), SetDataTip(AWV_DECREASE, STR_FACE_TIE_EARRING_TOOLTIP),
1348 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_TIE_EARRING), SetDataTip(STR_JUST_STRING1, STR_FACE_TIE_EARRING_TOOLTIP), SetTextStyle(TC_WHITE),
1349 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_SCMF_TIE_EARRING_R), SetDataTip(AWV_INCREASE, STR_FACE_TIE_EARRING_TOOLTIP),
1350 EndContainer(),
1351 EndContainer(),
1352 EndContainer(),
1353 EndContainer(),
1354 EndContainer(),
1355 EndContainer(),
1356 EndContainer(),
1357 EndContainer(),
1358 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1359 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_CANCEL), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL, STR_FACE_CANCEL_TOOLTIP),
1360 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCMF_ACCEPT), SetFill(1, 0), SetDataTip(STR_BUTTON_OK, STR_FACE_OK_TOOLTIP),
1361 EndContainer(),
1362 };
1363
1365 class SelectCompanyManagerFaceWindow : public Window
1366 {
1367 CompanyManagerFace face;
1368 bool advanced;
1369
1370 GenderEthnicity ge;
1371 bool is_female;
1372 bool is_moust_male;
1373
1374 Dimension yesno_dim;
1375 Dimension number_dim;
1376
1384 void SetFaceStringParameters(WidgetID widget_index, uint8_t val, bool is_bool_widget) const
1385 {
1386 const NWidgetCore *nwi_widget = this->GetWidget<NWidgetCore>(widget_index);
1387 if (nwi_widget->IsDisabled()) {
1388 SetDParam(0, STR_EMPTY);
1389 } else {
1390 if (is_bool_widget) {
1391 /* if it a bool button write yes or no */
1392 SetDParam(0, (val != 0) ? STR_FACE_YES : STR_FACE_NO);
1393 } else {
1394 /* else write the value + 1 */
1395 SetDParam(0, STR_JUST_INT);
1396 SetDParam(1, val + 1);
1397 }
1398 }
1399 }
1400
1401 void UpdateData()
1402 {
1403 this->ge = (GenderEthnicity)GB(this->face, _cmf_info[CMFV_GEN_ETHN].offset, _cmf_info[CMFV_GEN_ETHN].length); // get the gender and ethnicity
1404 this->is_female = HasBit(this->ge, GENDER_FEMALE); // get the gender: 0 == male and 1 == female
1405 this->is_moust_male = !is_female && GetCompanyManagerFaceBits(this->face, CMFV_HAS_MOUSTACHE, this->ge) != 0; // is a male face with moustache
1406
1407 this->GetWidget<NWidgetCore>(WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT)->widget_data = this->is_female ? STR_FACE_EARRING : STR_FACE_MOUSTACHE;
1408 this->GetWidget<NWidgetCore>(WID_SCMF_TIE_EARRING_TEXT)->widget_data = this->is_female ? STR_FACE_EARRING : STR_FACE_TIE;
1409 this->GetWidget<NWidgetCore>(WID_SCMF_LIPS_MOUSTACHE_TEXT)->widget_data = this->is_moust_male ? STR_FACE_MOUSTACHE : STR_FACE_LIPS;
1410 }
1411
1412 public:
1413 SelectCompanyManagerFaceWindow(WindowDesc *desc, Window *parent) : Window(desc)
1414 {
1415 this->advanced = false;
1416 this->CreateNestedTree();
1417 this->SelectDisplayPlanes(this->advanced);
1418 this->FinishInitNested(parent->window_number);
1419 this->parent = parent;
1420 this->owner = (Owner)this->window_number;
1421 this->face = Company::Get((CompanyID)this->window_number)->face;
1422
1423 this->UpdateData();
1424 }
1425
1430 void SelectDisplayPlanes(bool advanced)
1431 {
1432 this->GetWidget<NWidgetStacked>(WID_SCMF_SEL_LOADSAVE)->SetDisplayedPlane(advanced ? 0 : SZSP_NONE);
1433 this->GetWidget<NWidgetStacked>(WID_SCMF_SEL_PARTS)->SetDisplayedPlane(advanced ? 0 : SZSP_NONE);
1434 this->GetWidget<NWidgetStacked>(WID_SCMF_SEL_MALEFEMALE)->SetDisplayedPlane(advanced ? SZSP_NONE : 0);
1435 this->GetWidget<NWidgetCore>(WID_SCMF_RANDOM_NEW_FACE)->widget_data = advanced ? STR_FACE_RANDOM : STR_FACE_NEW_FACE_BUTTON;
1436
1437 NWidgetCore *wi = this->GetWidget<NWidgetCore>(WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON);
1438 if (advanced) {
1439 wi->SetDataTip(STR_FACE_SIMPLE, STR_FACE_SIMPLE_TOOLTIP);
1440 } else {
1441 wi->SetDataTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP);
1442 }
1443 }
1444
1445 void OnInit() override
1446 {
1447 /* Size of the boolean yes/no button. */
1448 Dimension yesno_dim = maxdim(GetStringBoundingBox(STR_FACE_YES), GetStringBoundingBox(STR_FACE_NO));
1449 yesno_dim.width += WidgetDimensions::scaled.framerect.Horizontal();
1450 yesno_dim.height += WidgetDimensions::scaled.framerect.Vertical();
1451 /* Size of the number button + arrows. */
1452 Dimension number_dim = {0, 0};
1453 for (int val = 1; val <= 12; val++) {
1454 SetDParam(0, val);
1455 number_dim = maxdim(number_dim, GetStringBoundingBox(STR_JUST_INT));
1456 }
1457 uint arrows_width = GetSpriteSize(SPR_ARROW_LEFT).width + GetSpriteSize(SPR_ARROW_RIGHT).width + 2 * (WidgetDimensions::scaled.imgbtn.Horizontal());
1458 number_dim.width += WidgetDimensions::scaled.framerect.Horizontal() + arrows_width;
1459 number_dim.height += WidgetDimensions::scaled.framerect.Vertical();
1460 /* Compute width of both buttons. */
1461 yesno_dim.width = std::max(yesno_dim.width, number_dim.width);
1462 number_dim.width = yesno_dim.width - arrows_width;
1463
1464 this->yesno_dim = yesno_dim;
1465 this->number_dim = number_dim;
1466 }
1467
1468 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
1469 {
1470 switch (widget) {
1471 case WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT:
1472 *size = maxdim(*size, GetStringBoundingBox(STR_FACE_EARRING));
1473 *size = maxdim(*size, GetStringBoundingBox(STR_FACE_MOUSTACHE));
1474 break;
1475
1476 case WID_SCMF_TIE_EARRING_TEXT:
1477 *size = maxdim(*size, GetStringBoundingBox(STR_FACE_EARRING));
1478 *size = maxdim(*size, GetStringBoundingBox(STR_FACE_TIE));
1479 break;
1480
1481 case WID_SCMF_LIPS_MOUSTACHE_TEXT:
1482 *size = maxdim(*size, GetStringBoundingBox(STR_FACE_LIPS));
1483 *size = maxdim(*size, GetStringBoundingBox(STR_FACE_MOUSTACHE));
1484 break;
1485
1486 case WID_SCMF_FACE:
1487 *size = maxdim(*size, GetScaledSpriteSize(SPR_GRADIENT));
1488 break;
1489
1490 case WID_SCMF_HAS_MOUSTACHE_EARRING:
1491 case WID_SCMF_HAS_GLASSES:
1492 *size = this->yesno_dim;
1493 break;
1494
1495 case WID_SCMF_EYECOLOUR:
1496 case WID_SCMF_CHIN:
1497 case WID_SCMF_EYEBROWS:
1498 case WID_SCMF_LIPS_MOUSTACHE:
1499 case WID_SCMF_NOSE:
1500 case WID_SCMF_HAIR:
1501 case WID_SCMF_JACKET:
1502 case WID_SCMF_COLLAR:
1503 case WID_SCMF_TIE_EARRING:
1504 case WID_SCMF_GLASSES:
1505 *size = this->number_dim;
1506 break;
1507 }
1508 }
1509
1510 void OnPaint() override
1511 {
1512 /* lower the non-selected gender button */
1513 this->SetWidgetsLoweredState(!this->is_female, WID_SCMF_MALE, WID_SCMF_MALE2);
1514 this->SetWidgetsLoweredState( this->is_female, WID_SCMF_FEMALE, WID_SCMF_FEMALE2);
1515
1516 /* advanced company manager face selection window */
1517
1518 /* lower the non-selected ethnicity button */
1519 this->SetWidgetLoweredState(WID_SCMF_ETHNICITY_EUR, !HasBit(this->ge, ETHNICITY_BLACK));
1520 this->SetWidgetLoweredState(WID_SCMF_ETHNICITY_AFR, HasBit(this->ge, ETHNICITY_BLACK));
1521
1522
1523 /* Disable dynamically the widgets which CompanyManagerFaceVariable has less than 2 options
1524 * (or in other words you haven't any choice).
1525 * If the widgets depend on a HAS-variable and this is false the widgets will be disabled, too. */
1526
1527 /* Eye colour buttons */
1528 this->SetWidgetsDisabledState(_cmf_info[CMFV_EYE_COLOUR].valid_values[this->ge] < 2,
1529 WID_SCMF_EYECOLOUR, WID_SCMF_EYECOLOUR_L, WID_SCMF_EYECOLOUR_R);
1530
1531 /* Chin buttons */
1532 this->SetWidgetsDisabledState(_cmf_info[CMFV_CHIN].valid_values[this->ge] < 2,
1533 WID_SCMF_CHIN, WID_SCMF_CHIN_L, WID_SCMF_CHIN_R);
1534
1535 /* Eyebrows buttons */
1536 this->SetWidgetsDisabledState(_cmf_info[CMFV_EYEBROWS].valid_values[this->ge] < 2,
1537 WID_SCMF_EYEBROWS, WID_SCMF_EYEBROWS_L, WID_SCMF_EYEBROWS_R);
1538
1539 /* Lips or (if it a male face with a moustache) moustache buttons */
1540 this->SetWidgetsDisabledState(_cmf_info[this->is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS].valid_values[this->ge] < 2,
1541 WID_SCMF_LIPS_MOUSTACHE, WID_SCMF_LIPS_MOUSTACHE_L, WID_SCMF_LIPS_MOUSTACHE_R);
1542
1543 /* Nose buttons | male faces with moustache haven't any nose options */
1544 this->SetWidgetsDisabledState(_cmf_info[CMFV_NOSE].valid_values[this->ge] < 2 || this->is_moust_male,
1545 WID_SCMF_NOSE, WID_SCMF_NOSE_L, WID_SCMF_NOSE_R);
1546
1547 /* Hair buttons */
1548 this->SetWidgetsDisabledState(_cmf_info[CMFV_HAIR].valid_values[this->ge] < 2,
1549 WID_SCMF_HAIR, WID_SCMF_HAIR_L, WID_SCMF_HAIR_R);
1550
1551 /* Jacket buttons */
1552 this->SetWidgetsDisabledState(_cmf_info[CMFV_JACKET].valid_values[this->ge] < 2,
1553 WID_SCMF_JACKET, WID_SCMF_JACKET_L, WID_SCMF_JACKET_R);
1554
1555 /* Collar buttons */
1556 this->SetWidgetsDisabledState(_cmf_info[CMFV_COLLAR].valid_values[this->ge] < 2,
1557 WID_SCMF_COLLAR, WID_SCMF_COLLAR_L, WID_SCMF_COLLAR_R);
1558
1559 /* Tie/earring buttons | female faces without earring haven't any earring options */
1560 this->SetWidgetsDisabledState(_cmf_info[CMFV_TIE_EARRING].valid_values[this->ge] < 2 ||
1561 (this->is_female && GetCompanyManagerFaceBits(this->face, CMFV_HAS_TIE_EARRING, this->ge) == 0),
1562 WID_SCMF_TIE_EARRING, WID_SCMF_TIE_EARRING_L, WID_SCMF_TIE_EARRING_R);
1563
1564 /* Glasses buttons | faces without glasses haven't any glasses options */
1565 this->SetWidgetsDisabledState(_cmf_info[CMFV_GLASSES].valid_values[this->ge] < 2 || GetCompanyManagerFaceBits(this->face, CMFV_HAS_GLASSES, this->ge) == 0,
1566 WID_SCMF_GLASSES, WID_SCMF_GLASSES_L, WID_SCMF_GLASSES_R);
1567
1568 this->DrawWidgets();
1569 }
1570
1571 void SetStringParameters(WidgetID widget) const override
1572 {
1573 switch (widget) {
1574 case WID_SCMF_HAS_MOUSTACHE_EARRING:
1575 if (this->is_female) { // Only for female faces
1576 this->SetFaceStringParameters(WID_SCMF_HAS_MOUSTACHE_EARRING, GetCompanyManagerFaceBits(this->face, CMFV_HAS_TIE_EARRING, this->ge), true);
1577 } else { // Only for male faces
1578 this->SetFaceStringParameters(WID_SCMF_HAS_MOUSTACHE_EARRING, GetCompanyManagerFaceBits(this->face, CMFV_HAS_MOUSTACHE, this->ge), true);
1579 }
1580 break;
1581
1582 case WID_SCMF_TIE_EARRING:
1583 this->SetFaceStringParameters(WID_SCMF_TIE_EARRING, GetCompanyManagerFaceBits(this->face, CMFV_TIE_EARRING, this->ge), false);
1584 break;
1585
1586 case WID_SCMF_LIPS_MOUSTACHE:
1587 if (this->is_moust_male) { // Only for male faces with moustache
1588 this->SetFaceStringParameters(WID_SCMF_LIPS_MOUSTACHE, GetCompanyManagerFaceBits(this->face, CMFV_MOUSTACHE, this->ge), false);
1589 } else { // Only for female faces or male faces without moustache
1590 this->SetFaceStringParameters(WID_SCMF_LIPS_MOUSTACHE, GetCompanyManagerFaceBits(this->face, CMFV_LIPS, this->ge), false);
1591 }
1592 break;
1593
1594 case WID_SCMF_HAS_GLASSES:
1595 this->SetFaceStringParameters(WID_SCMF_HAS_GLASSES, GetCompanyManagerFaceBits(this->face, CMFV_HAS_GLASSES, this->ge), true );
1596 break;
1597
1598 case WID_SCMF_HAIR:
1599 this->SetFaceStringParameters(WID_SCMF_HAIR, GetCompanyManagerFaceBits(this->face, CMFV_HAIR, this->ge), false);
1600 break;
1601
1602 case WID_SCMF_EYEBROWS:
1603 this->SetFaceStringParameters(WID_SCMF_EYEBROWS, GetCompanyManagerFaceBits(this->face, CMFV_EYEBROWS, this->ge), false);
1604 break;
1605
1606 case WID_SCMF_EYECOLOUR:
1607 this->SetFaceStringParameters(WID_SCMF_EYECOLOUR, GetCompanyManagerFaceBits(this->face, CMFV_EYE_COLOUR, this->ge), false);
1608 break;
1609
1610 case WID_SCMF_GLASSES:
1611 this->SetFaceStringParameters(WID_SCMF_GLASSES, GetCompanyManagerFaceBits(this->face, CMFV_GLASSES, this->ge), false);
1612 break;
1613
1614 case WID_SCMF_NOSE:
1615 this->SetFaceStringParameters(WID_SCMF_NOSE, GetCompanyManagerFaceBits(this->face, CMFV_NOSE, this->ge), false);
1616 break;
1617
1618 case WID_SCMF_CHIN:
1619 this->SetFaceStringParameters(WID_SCMF_CHIN, GetCompanyManagerFaceBits(this->face, CMFV_CHIN, this->ge), false);
1620 break;
1621
1622 case WID_SCMF_JACKET:
1623 this->SetFaceStringParameters(WID_SCMF_JACKET, GetCompanyManagerFaceBits(this->face, CMFV_JACKET, this->ge), false);
1624 break;
1625
1626 case WID_SCMF_COLLAR:
1627 this->SetFaceStringParameters(WID_SCMF_COLLAR, GetCompanyManagerFaceBits(this->face, CMFV_COLLAR, this->ge), false);
1628 break;
1629 }
1630 }
1631
1632 void DrawWidget(const Rect &r, WidgetID widget) const override
1633 {
1634 switch (widget) {
1635 case WID_SCMF_FACE:
1636 DrawCompanyManagerFace(this->face, Company::Get((CompanyID)this->window_number)->colour, r);
1637 break;
1638 }
1639 }
1640
1641 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1642 {
1643 switch (widget) {
1644 /* Toggle size, advanced/simple face selection */
1645 case WID_SCMF_TOGGLE_LARGE_SMALL:
1646 case WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON:
1647 this->advanced = !this->advanced;
1648 this->SelectDisplayPlanes(this->advanced);
1649 this->ReInit();
1650 break;
1651
1652 /* OK button */
1653 case WID_SCMF_ACCEPT:
1654 Command<CMD_SET_COMPANY_MANAGER_FACE>::Post(this->face);
1655 [[fallthrough]];
1656
1657 /* Cancel button */
1658 case WID_SCMF_CANCEL:
1659 this->Close();
1660 break;
1661
1662 /* Load button */
1663 case WID_SCMF_LOAD:
1664 this->face = _company_manager_face;
1665 ScaleAllCompanyManagerFaceBits(this->face);
1666 ShowErrorMessage(STR_FACE_LOAD_DONE, INVALID_STRING_ID, WL_INFO);
1667 this->UpdateData();
1668 this->SetDirty();
1669 break;
1670
1671 /* 'Company manager face number' button, view and/or set company manager face number */
1672 case WID_SCMF_FACECODE:
1673 SetDParam(0, this->face);
1674 ShowQueryString(STR_JUST_INT, STR_FACE_FACECODE_CAPTION, 10 + 1, this, CS_NUMERAL, QSF_NONE);
1675 break;
1676
1677 /* Save button */
1678 case WID_SCMF_SAVE:
1679 _company_manager_face = this->face;
1680 ShowErrorMessage(STR_FACE_SAVE_DONE, INVALID_STRING_ID, WL_INFO);
1681 break;
1682
1683 /* Toggle gender (male/female) button */
1684 case WID_SCMF_MALE:
1685 case WID_SCMF_FEMALE:
1686 case WID_SCMF_MALE2:
1687 case WID_SCMF_FEMALE2:
1688 SetCompanyManagerFaceBits(this->face, CMFV_GENDER, this->ge, (widget == WID_SCMF_FEMALE || widget == WID_SCMF_FEMALE2));
1689 ScaleAllCompanyManagerFaceBits(this->face);
1690 this->UpdateData();
1691 this->SetDirty();
1692 break;
1693
1694 /* Randomize face button */
1695 case WID_SCMF_RANDOM_NEW_FACE:
1696 RandomCompanyManagerFaceBits(this->face, this->ge, this->advanced, _interactive_random);
1697 this->UpdateData();
1698 this->SetDirty();
1699 break;
1700
1701 /* Toggle ethnicity (european/african) button */
1702 case WID_SCMF_ETHNICITY_EUR:
1703 case WID_SCMF_ETHNICITY_AFR:
1704 SetCompanyManagerFaceBits(this->face, CMFV_ETHNICITY, this->ge, widget - WID_SCMF_ETHNICITY_EUR);
1705 ScaleAllCompanyManagerFaceBits(this->face);
1706 this->UpdateData();
1707 this->SetDirty();
1708 break;
1709
1710 default:
1711 /* Here all buttons from WID_SCMF_HAS_MOUSTACHE_EARRING to WID_SCMF_GLASSES_R are handled.
1712 * First it checks which CompanyManagerFaceVariable is being changed, and then either
1713 * a: invert the value for boolean variables, or
1714 * b: it checks inside of IncreaseCompanyManagerFaceBits() if a left (_L) butten is pressed and then decrease else increase the variable */
1715 if (widget >= WID_SCMF_HAS_MOUSTACHE_EARRING && widget <= WID_SCMF_GLASSES_R) {
1716 CompanyManagerFaceVariable cmfv; // which CompanyManagerFaceVariable shall be edited
1717
1718 if (widget < WID_SCMF_EYECOLOUR_L) { // Bool buttons
1719 switch (widget - WID_SCMF_HAS_MOUSTACHE_EARRING) {
1720 default: NOT_REACHED();
1721 case 0: cmfv = this->is_female ? CMFV_HAS_TIE_EARRING : CMFV_HAS_MOUSTACHE; break; // Has earring/moustache button
1722 case 1: cmfv = CMFV_HAS_GLASSES; break; // Has glasses button
1723 }
1724 SetCompanyManagerFaceBits(this->face, cmfv, this->ge, !GetCompanyManagerFaceBits(this->face, cmfv, this->ge));
1725 ScaleAllCompanyManagerFaceBits(this->face);
1726 } else { // Value buttons
1727 switch ((widget - WID_SCMF_EYECOLOUR_L) / 3) {
1728 default: NOT_REACHED();
1729 case 0: cmfv = CMFV_EYE_COLOUR; break; // Eye colour buttons
1730 case 1: cmfv = CMFV_CHIN; break; // Chin buttons
1731 case 2: cmfv = CMFV_EYEBROWS; break; // Eyebrows buttons
1732 case 3: cmfv = this->is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS; break; // Moustache or lips buttons
1733 case 4: cmfv = CMFV_NOSE; break; // Nose buttons
1734 case 5: cmfv = CMFV_HAIR; break; // Hair buttons
1735 case 6: cmfv = CMFV_JACKET; break; // Jacket buttons
1736 case 7: cmfv = CMFV_COLLAR; break; // Collar buttons
1737 case 8: cmfv = CMFV_TIE_EARRING; break; // Tie/earring buttons
1738 case 9: cmfv = CMFV_GLASSES; break; // Glasses buttons
1739 }
1740 /* 0 == left (_L), 1 == middle or 2 == right (_R) - button click */
1741 IncreaseCompanyManagerFaceBits(this->face, cmfv, this->ge, (((widget - WID_SCMF_EYECOLOUR_L) % 3) != 0) ? 1 : -1);
1742 }
1743 this->UpdateData();
1744 this->SetDirty();
1745 }
1746 break;
1747 }
1748 }
1749
1750 void OnQueryTextFinished(char *str) override
1751 {
1752 if (str == nullptr) return;
1753 /* Set a new company manager face number */
1754 if (!StrEmpty(str)) {
1755 this->face = std::strtoul(str, nullptr, 10);
1756 ScaleAllCompanyManagerFaceBits(this->face);
1757 ShowErrorMessage(STR_FACE_FACECODE_SET, INVALID_STRING_ID, WL_INFO);
1758 this->UpdateData();
1759 this->SetDirty();
1760 } else {
1761 ShowErrorMessage(STR_FACE_FACECODE_ERR, INVALID_STRING_ID, WL_INFO);
1762 }
1763 }
1764 };
1765
1767 static WindowDesc _select_company_manager_face_desc(__FILE__, __LINE__,
1768 WDP_AUTO, nullptr, 0, 0,
1769 WC_COMPANY_MANAGER_FACE, WC_NONE,
1770 WDF_CONSTRUCTION,
1771 std::begin(_nested_select_company_manager_face_widgets), std::end(_nested_select_company_manager_face_widgets)
1772 );
1773
1779 static void DoSelectCompanyManagerFace(Window *parent)
1780 {
1781 if (!Company::IsValidID((CompanyID)parent->window_number)) return;
1782
1783 if (BringWindowToFrontById(WC_COMPANY_MANAGER_FACE, parent->window_number)) return;
1784 new SelectCompanyManagerFaceWindow(&_select_company_manager_face_desc, parent);
1785 }
1786
1787 static constexpr NWidgetPart _nested_company_infrastructure_widgets[] = {
1788 NWidget(NWID_HORIZONTAL),
1789 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1790 NWidget(WWT_CAPTION, COLOUR_GREY, WID_CI_CAPTION), SetDataTip(STR_COMPANY_INFRASTRUCTURE_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1791 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1792 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1793 EndContainer(),
1794 NWidget(WWT_PANEL, COLOUR_GREY),
1795 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.framerect), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1796 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1797 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_RAIL_DESC), SetMinimalTextLines(2, 0), SetFill(1, 0),
1798 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_RAIL_COUNT), SetMinimalTextLines(2, 0), SetFill(0, 1),
1799 EndContainer(),
1800 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1801 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_ROAD_DESC), SetMinimalTextLines(2, 0), SetFill(1, 0),
1802 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_ROAD_COUNT), SetMinimalTextLines(2, 0), SetFill(0, 1),
1803 EndContainer(),
1804 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1805 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_TRAM_DESC), SetMinimalTextLines(2, 0), SetFill(1, 0),
1806 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_TRAM_COUNT), SetMinimalTextLines(2, 0), SetFill(0, 1),
1807 EndContainer(),
1808 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1809 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_WATER_DESC), SetMinimalTextLines(2, 0), SetFill(1, 0),
1810 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_WATER_COUNT), SetMinimalTextLines(2, 0), SetFill(0, 1),
1811 EndContainer(),
1812 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1813 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_STATION_DESC), SetMinimalTextLines(3, 0), SetFill(1, 0),
1814 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_STATION_COUNT), SetMinimalTextLines(3, 0), SetFill(0, 1),
1815 EndContainer(),
1816 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1817 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_TOTAL_DESC), SetFill(1, 0),
1818 NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_TOTAL), SetFill(0, 1),
1819 EndContainer(),
1820 EndContainer(),
1821 EndContainer(),
1822 };
1823
1827 struct CompanyInfrastructureWindow : Window
1828 {
1829 RailTypes railtypes;
1830 RoadTypes roadtypes;
1831
1832 uint total_width;
1833
1834 CompanyInfrastructureWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
1835 {
1836 this->UpdateRailRoadTypes();
1837
1838 this->InitNested(window_number);
1839 this->owner = (Owner)this->window_number;
1840 }
1841
1842 void UpdateRailRoadTypes()
1843 {
1844 this->railtypes = RAILTYPES_NONE;
1845 this->roadtypes = ROADTYPES_NONE;
1846
1847 /* Find the used railtypes. */
1848 for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
1849 if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
1850
1851 this->railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
1852 }
1853
1854 /* Get the date introduced railtypes as well. */
1855 this->railtypes = AddDateIntroducedRailTypes(this->railtypes, CalendarTime::MAX_DATE);
1856
1857 /* Find the used roadtypes. */
1858 for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
1859 if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
1860
1861 this->roadtypes |= GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes;
1862 }
1863
1864 /* Get the date introduced roadtypes as well. */
1865 this->roadtypes = AddDateIntroducedRoadTypes(this->roadtypes, CalendarTime::MAX_DATE);
1866 this->roadtypes &= ~_roadtypes_hidden_mask;
1867 }
1868
1870 Money GetTotalMaintenanceCost() const
1871 {
1872 const Company *c = Company::Get((CompanyID)this->window_number);
1873 Money total;
1874
1875 uint32_t rail_total = c->infrastructure.GetRailTotal();
1876 for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
1877 if (HasBit(this->railtypes, rt)) total += RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total);
1878 }
1879 total += SignalMaintenanceCost(c->infrastructure.signal);
1880
1881 uint32_t road_total = c->infrastructure.GetRoadTotal();
1882 uint32_t tram_total = c->infrastructure.GetTramTotal();
1883 for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
1884 if (HasBit(this->roadtypes, rt)) total += RoadMaintenanceCost(rt, c->infrastructure.road[rt], RoadTypeIsRoad(rt) ? road_total : tram_total);
1885 }
1886
1887 total += CanalMaintenanceCost(c->infrastructure.water);
1888 total += StationMaintenanceCost(c->infrastructure.station);
1889 total += AirportMaintenanceCost(c->index);
1890
1891 return total;
1892 }
1893
1894 void SetStringParameters(WidgetID widget) const override
1895 {
1896 switch (widget) {
1897 case WID_CI_CAPTION:
1898 SetDParam(0, (CompanyID)this->window_number);
1899 break;
1900 }
1901 }
1902
1903 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
1904 {
1905 const Company *c = Company::Get((CompanyID)this->window_number);
1906
1907 switch (widget) {
1908 case WID_CI_RAIL_DESC: {
1909 uint lines = 1; // Starts at 1 because a line is also required for the section title
1910
1911 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT).width + padding.width);
1912
1913 for (const auto &rt : _sorted_railtypes) {
1914 if (HasBit(this->railtypes, rt)) {
1915 lines++;
1916 size->width = std::max(size->width, GetStringBoundingBox(GetRailTypeInfo(rt)->strings.name).width + padding.width + WidgetDimensions::scaled.hsep_indent);
1917 }
1918 }
1919 if (this->railtypes != RAILTYPES_NONE) {
1920 lines++;
1921 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS).width + padding.width + WidgetDimensions::scaled.hsep_indent);
1922 }
1923
1924 size->height = std::max(size->height, lines * GetCharacterHeight(FS_NORMAL));
1925 break;
1926 }
1927
1928 case WID_CI_ROAD_DESC:
1929 case WID_CI_TRAM_DESC: {
1930 uint lines = 1; // Starts at 1 because a line is also required for the section title
1931
1932 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);
1933
1934 for (const auto &rt : _sorted_roadtypes) {
1935 if (HasBit(this->roadtypes, rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_DESC)) {
1936 lines++;
1937 size->width = std::max(size->width, GetStringBoundingBox(GetRoadTypeInfo(rt)->strings.name).width + padding.width + WidgetDimensions::scaled.hsep_indent);
1938 }
1939 }
1940
1941 size->height = std::max(size->height, lines * GetCharacterHeight(FS_NORMAL));
1942 break;
1943 }
1944
1945 case WID_CI_WATER_DESC:
1946 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT).width + padding.width);
1947 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS).width + padding.width + WidgetDimensions::scaled.hsep_indent);
1948 break;
1949
1950 case WID_CI_STATION_DESC:
1951 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT).width + padding.width);
1952 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS).width + padding.width + WidgetDimensions::scaled.hsep_indent);
1953 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS).width + padding.width + WidgetDimensions::scaled.hsep_indent);
1954 break;
1955
1956 case WID_CI_RAIL_COUNT:
1957 case WID_CI_ROAD_COUNT:
1958 case WID_CI_TRAM_COUNT:
1959 case WID_CI_WATER_COUNT:
1960 case WID_CI_STATION_COUNT:
1961 case WID_CI_TOTAL: {
1962 /* Find the maximum count that is displayed. */
1963 uint32_t max_val = 1000; // Some random number to reserve enough space.
1964 Money max_cost = 10000; // Some random number to reserve enough space.
1965 uint32_t rail_total = c->infrastructure.GetRailTotal();
1966 for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) {
1967 max_val = std::max(max_val, c->infrastructure.rail[rt]);
1968 max_cost = std::max(max_cost, RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total));
1969 }
1970 max_val = std::max(max_val, c->infrastructure.signal);
1971 max_cost = std::max(max_cost, SignalMaintenanceCost(c->infrastructure.signal));
1972 uint32_t road_total = c->infrastructure.GetRoadTotal();
1973 uint32_t tram_total = c->infrastructure.GetTramTotal();
1974 for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) {
1975 max_val = std::max(max_val, c->infrastructure.road[rt]);
1976 max_cost = std::max(max_cost, RoadMaintenanceCost(rt, c->infrastructure.road[rt], RoadTypeIsRoad(rt) ? road_total : tram_total));
1977
1978 }
1979 max_val = std::max(max_val, c->infrastructure.water);
1980 max_cost = std::max(max_cost, CanalMaintenanceCost(c->infrastructure.water));
1981 max_val = std::max(max_val, c->infrastructure.station);
1982 max_cost = std::max(max_cost, StationMaintenanceCost(c->infrastructure.station));
1983 max_val = std::max(max_val, c->infrastructure.airport);
1984 max_cost = std::max(max_cost, AirportMaintenanceCost(c->index));
1985
1986 SetDParamMaxValue(0, max_val);
1987 uint count_width = GetStringBoundingBox(STR_JUST_COMMA).width + WidgetDimensions::scaled.hsep_indent; // Reserve some wiggle room
1988
1989 if (_settings_game.economy.infrastructure_maintenance) {
1990 StringID str_total = TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR;
1991 SetDParamMaxValue(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
1992 this->total_width = GetStringBoundingBox(str_total).width + WidgetDimensions::scaled.hsep_indent * 2;
1993 size->width = std::max(size->width, this->total_width);
1994
1995 SetDParamMaxValue(0, max_cost * 12); // Convert to per year
1996 count_width += std::max(this->total_width, GetStringBoundingBox(str_total).width);
1997 }
1998
1999 size->width = std::max(size->width, count_width);
2000
2001 /* Set height of the total line. */
2002 if (widget == WID_CI_TOTAL) {
2003 size->height = _settings_game.economy.infrastructure_maintenance ? std::max<uint>(size->height, WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL)) : 0;
2004 }
2005 break;
2006 }
2007 }
2008 }
2009
2017 void DrawCountLine(const Rect &r, int &y, int count, Money monthly_cost) const
2018 {
2019 SetDParam(0, count);
2020 DrawString(r.left, r.right, y += GetCharacterHeight(FS_NORMAL), STR_JUST_COMMA, TC_WHITE, SA_RIGHT);
2021
2022 if (_settings_game.economy.infrastructure_maintenance) {
2023 SetDParam(0, monthly_cost * 12); // Convert to per year
2024 Rect tr = r.WithWidth(this->total_width, _current_text_dir == TD_RTL);
2025 DrawString(tr.left, tr.right, y,
2026 TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR,
2027 TC_FROMSTRING, SA_RIGHT);
2028 }
2029 }
2030
2031 void DrawWidget(const Rect &r, WidgetID widget) const override
2032 {
2033 const Company *c = Company::Get((CompanyID)this->window_number);
2034
2035 int y = r.top;
2036
2037 Rect ir = r.Indent(WidgetDimensions::scaled.hsep_indent, _current_text_dir == TD_RTL);
2038 switch (widget) {
2039 case WID_CI_RAIL_DESC:
2040 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT);
2041
2042 if (this->railtypes != RAILTYPES_NONE) {
2043 /* Draw name of each valid railtype. */
2044 for (const auto &rt : _sorted_railtypes) {
2045 if (HasBit(this->railtypes, rt)) {
2046 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), GetRailTypeInfo(rt)->strings.name, TC_WHITE);
2047 }
2048 }
2049 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS);
2050 } else {
2051 /* No valid railtype. */
2052 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
2053 }
2054
2055 break;
2056
2057 case WID_CI_RAIL_COUNT: {
2058 /* Draw infrastructure count for each valid railtype. */
2059 uint32_t rail_total = c->infrastructure.GetRailTotal();
2060 for (const auto &rt : _sorted_railtypes) {
2061 if (HasBit(this->railtypes, rt)) {
2062 this->DrawCountLine(r, y, c->infrastructure.rail[rt], RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total));
2063 }
2064 }
2065 if (this->railtypes != RAILTYPES_NONE) {
2066 this->DrawCountLine(r, y, c->infrastructure.signal, SignalMaintenanceCost(c->infrastructure.signal));
2067 }
2068 break;
2069 }
2070
2071 case WID_CI_ROAD_DESC:
2072 case WID_CI_TRAM_DESC: {
2073 DrawString(r.left, r.right, y, widget == WID_CI_ROAD_DESC ? STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT : STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT);
2074
2075 /* Draw name of each valid roadtype. */
2076 for (const auto &rt : _sorted_roadtypes) {
2077 if (HasBit(this->roadtypes, rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_DESC)) {
2078 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), GetRoadTypeInfo(rt)->strings.name, TC_WHITE);
2079 }
2080 }
2081
2082 break;
2083 }
2084
2085 case WID_CI_ROAD_COUNT:
2086 case WID_CI_TRAM_COUNT: {
2087 uint32_t road_tram_total = widget == WID_CI_ROAD_COUNT ? c->infrastructure.GetRoadTotal() : c->infrastructure.GetTramTotal();
2088 for (const auto &rt : _sorted_roadtypes) {
2089 if (HasBit(this->roadtypes, rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_COUNT)) {
2090 this->DrawCountLine(r, y, c->infrastructure.road[rt], RoadMaintenanceCost(rt, c->infrastructure.road[rt], road_tram_total));
2091 }
2092 }
2093 break;
2094 }
2095
2096 case WID_CI_WATER_DESC:
2097 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT);
2098 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS);
2099 break;
2100
2101 case WID_CI_WATER_COUNT:
2102 this->DrawCountLine(r, y, c->infrastructure.water, CanalMaintenanceCost(c->infrastructure.water));
2103 break;
2104
2105 case WID_CI_TOTAL:
2106 if (_settings_game.economy.infrastructure_maintenance) {
2107 Rect tr = r.WithWidth(this->total_width, _current_text_dir == TD_RTL);
2108 GfxFillRect(tr.left, y, tr.right, y + WidgetDimensions::scaled.bevel.top - 1, PC_WHITE);
2109 y += WidgetDimensions::scaled.vsep_normal;
2110 SetDParam(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
2111 DrawString(tr.left, tr.right, y,
2112 TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR,
2113 TC_FROMSTRING, SA_RIGHT);
2114 }
2115 break;
2116
2117 case WID_CI_STATION_DESC:
2118 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT);
2119 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS);
2120 DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS);
2121 break;
2122
2123 case WID_CI_STATION_COUNT:
2124 this->DrawCountLine(r, y, c->infrastructure.station, StationMaintenanceCost(c->infrastructure.station));
2125 this->DrawCountLine(r, y, c->infrastructure.airport, AirportMaintenanceCost(c->index));
2126 break;
2127 }
2128 }
2129
2135 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2136 {
2137 if (!gui_scope) return;
2138
2139 this->UpdateRailRoadTypes();
2140 this->ReInit();
2141 }
2142 };
2143
2144 static WindowDesc _company_infrastructure_desc(__FILE__, __LINE__,
2145 WDP_AUTO, "company_infrastructure", 0, 0,
2146 WC_COMPANY_INFRASTRUCTURE, WC_NONE,
2147 0,
2148 std::begin(_nested_company_infrastructure_widgets), std::end(_nested_company_infrastructure_widgets)
2149 );
2150
2155 static void ShowCompanyInfrastructure(CompanyID company)
2156 {
2157 if (!Company::IsValidID(company)) return;
2158 AllocateWindowDescFront<CompanyInfrastructureWindow>(&_company_infrastructure_desc, company);
2159 }
2160
2161 static constexpr NWidgetPart _nested_company_widgets[] = {
2162 NWidget(NWID_HORIZONTAL),
2163 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2164 NWidget(WWT_CAPTION, COLOUR_GREY, WID_C_CAPTION), SetDataTip(STR_COMPANY_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2165 NWidget(WWT_SHADEBOX, COLOUR_GREY),
2166 NWidget(WWT_STICKYBOX, COLOUR_GREY),
2167 EndContainer(),
2168 NWidget(WWT_PANEL, COLOUR_GREY),
2169 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0), SetPadding(4),
2170 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
2171 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_FACE), SetMinimalSize(92, 119), SetFill(1, 0),
2172 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_FACE_TITLE), SetFill(1, 1), SetMinimalTextLines(2, 0),
2173 EndContainer(),
2174 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
2175 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
2176 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
2177 NWidget(WWT_TEXT, COLOUR_GREY, WID_C_DESC_INAUGURATION), SetDataTip(STR_COMPANY_VIEW_INAUGURATED_TITLE, STR_NULL), SetFill(1, 0),
2178 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
2179 NWidget(WWT_LABEL, COLOUR_GREY, WID_C_DESC_COLOUR_SCHEME), SetDataTip(STR_COMPANY_VIEW_COLOUR_SCHEME_TITLE, STR_NULL),
2180 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_DESC_COLOUR_SCHEME_EXAMPLE), SetMinimalSize(30, 0), SetFill(1, 1),
2181 EndContainer(),
2182 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
2183 NWidget(WWT_TEXT, COLOUR_GREY, WID_C_DESC_VEHICLE), SetDataTip(STR_COMPANY_VIEW_VEHICLES_TITLE, STR_NULL), SetAlignment(SA_LEFT | SA_TOP),
2184 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_DESC_VEHICLE_COUNTS), SetMinimalTextLines(4, 0), SetFill(1, 1),
2185 EndContainer(),
2186 EndContainer(),
2187 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
2188 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_VIEW_BUILD_HQ),
2189 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_VIEW_HQ), SetDataTip(STR_COMPANY_VIEW_VIEW_HQ_BUTTON, STR_COMPANY_VIEW_VIEW_HQ_TOOLTIP),
2190 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_C_BUILD_HQ), SetDataTip(STR_COMPANY_VIEW_BUILD_HQ_BUTTON, STR_COMPANY_VIEW_BUILD_HQ_TOOLTIP),
2191 EndContainer(),
2192 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_RELOCATE),
2193 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_C_RELOCATE_HQ), SetDataTip(STR_COMPANY_VIEW_RELOCATE_HQ, STR_COMPANY_VIEW_RELOCATE_COMPANY_HEADQUARTERS),
2194 NWidget(NWID_SPACER),
2195 EndContainer(),
2196 EndContainer(),
2197 EndContainer(),
2198
2199 NWidget(WWT_TEXT, COLOUR_GREY, WID_C_DESC_COMPANY_VALUE), SetDataTip(STR_COMPANY_VIEW_COMPANY_VALUE, STR_NULL), SetFill(1, 0),
2200
2201 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
2202 NWidget(WWT_TEXT, COLOUR_GREY, WID_C_DESC_INFRASTRUCTURE), SetDataTip(STR_COMPANY_VIEW_INFRASTRUCTURE, STR_NULL), SetAlignment(SA_LEFT | SA_TOP),
2203 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_DESC_INFRASTRUCTURE_COUNTS), SetMinimalTextLines(5, 0), SetFill(1, 0),
2204 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1),
2205 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_VIEW_INFRASTRUCTURE), SetDataTip(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP),
2206 EndContainer(),
2207 EndContainer(),
2208
2209 /* Multi player buttons. */
2210 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), SetPIPRatio(1, 0, 0),
2211 NWidget(NWID_VERTICAL), SetPIPRatio(1, 0, 0),
2212 NWidget(WWT_EMPTY, COLOUR_GREY, WID_C_HAS_PASSWORD), SetFill(0, 0),
2213 EndContainer(),
2214 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
2215 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_HOSTILE_TAKEOVER),
2216 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_HOSTILE_TAKEOVER), SetDataTip(STR_COMPANY_VIEW_HOSTILE_TAKEOVER_BUTTON, STR_COMPANY_VIEW_HOSTILE_TAKEOVER_TOOLTIP),
2217 EndContainer(),
2218 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_GIVE_MONEY),
2219 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_GIVE_MONEY), SetDataTip(STR_COMPANY_VIEW_GIVE_MONEY_BUTTON, STR_COMPANY_VIEW_GIVE_MONEY_TOOLTIP),
2220 EndContainer(),
2221 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_MULTIPLAYER),
2222 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_COMPANY_PASSWORD), SetDataTip(STR_COMPANY_VIEW_PASSWORD, STR_COMPANY_VIEW_PASSWORD_TOOLTIP),
2223 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_C_COMPANY_JOIN), SetDataTip(STR_COMPANY_VIEW_JOIN, STR_COMPANY_VIEW_JOIN_TOOLTIP),
2224 EndContainer(),
2225 EndContainer(),
2226 EndContainer(),
2227 EndContainer(),
2228 EndContainer(),
2229 EndContainer(),
2230 /* Button bars at the bottom. */
2231 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_C_SELECT_BUTTONS),
2232 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
2233 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),
2234 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),
2235 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),
2236 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),
2237 EndContainer(),
2238 EndContainer(),
2239 };
2240
2242 static const StringID _company_view_vehicle_count_strings[] = {
2243 STR_COMPANY_VIEW_TRAINS, STR_COMPANY_VIEW_ROAD_VEHICLES, STR_COMPANY_VIEW_SHIPS, STR_COMPANY_VIEW_AIRCRAFT
2244 };
2245
2249 struct CompanyWindow : Window
2250 {
2251 CompanyWidgets query_widget;
2252
2254 enum CompanyWindowPlanes {
2255 /* Display planes of the #WID_C_SELECT_MULTIPLAYER selection widget. */
2256 CWP_MP_C_PWD = 0,
2257 CWP_MP_C_JOIN,
2258
2259 /* Display planes of the #WID_C_SELECT_VIEW_BUILD_HQ selection widget. */
2260 CWP_VB_VIEW = 0,
2261 CWP_VB_BUILD,
2262
2263 /* Display planes of the #WID_C_SELECT_RELOCATE selection widget. */
2264 CWP_RELOCATE_SHOW = 0,
2265 CWP_RELOCATE_HIDE,
2266 };
2267
2268 CompanyWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
2269 {
2270 this->InitNested(window_number);
2271 this->owner = (Owner)this->window_number;
2272 this->OnInvalidateData();
2273 }
2274
2275 void OnPaint() override
2276 {
2277 const Company *c = Company::Get((CompanyID)this->window_number);
2278 bool local = this->window_number == _local_company;
2279
2280 if (!this->IsShaded()) {
2281 bool reinit = false;
2282
2283 /* Button bar selection. */
2284 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_BUTTONS)->SetDisplayedPlane(local ? 0 : SZSP_NONE);
2285
2286 /* Build HQ button handling. */
2287 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_VIEW_BUILD_HQ)->SetDisplayedPlane((local && c->location_of_HQ == INVALID_TILE) ? CWP_VB_BUILD : CWP_VB_VIEW);
2288
2289 this->SetWidgetDisabledState(WID_C_VIEW_HQ, c->location_of_HQ == INVALID_TILE);
2290
2291 /* Enable/disable 'Relocate HQ' button. */
2292 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_RELOCATE)->SetDisplayedPlane((!local || c->location_of_HQ == INVALID_TILE) ? CWP_RELOCATE_HIDE : CWP_RELOCATE_SHOW);
2293 /* Enable/disable 'Give money' button. */
2294 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_GIVE_MONEY)->SetDisplayedPlane((local || _local_company == COMPANY_SPECTATOR || !_settings_game.economy.give_money) ? SZSP_NONE : 0);
2295 /* Enable/disable 'Hostile Takeover' button. */
2296 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_HOSTILE_TAKEOVER)->SetDisplayedPlane((local || _local_company == COMPANY_SPECTATOR || !c->is_ai || _networking) ? SZSP_NONE : 0);
2297
2298 /* Multiplayer buttons. */
2299 reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_MULTIPLAYER)->SetDisplayedPlane((!_networking) ? (int)SZSP_NONE : (int)(local ? CWP_MP_C_PWD : CWP_MP_C_JOIN));
2300
2301 this->SetWidgetDisabledState(WID_C_COMPANY_JOIN, c->is_ai);
2302
2303 if (reinit) {
2304 this->ReInit();
2305 return;
2306 }
2307 }
2308
2309 this->DrawWidgets();
2310 }
2311
2312 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
2313 {
2314 switch (widget) {
2315 case WID_C_FACE:
2316 *size = maxdim(*size, GetScaledSpriteSize(SPR_GRADIENT));
2317 break;
2318
2319 case WID_C_DESC_COLOUR_SCHEME_EXAMPLE: {
2320 Point offset;
2321 Dimension d = GetSpriteSize(SPR_VEH_BUS_SW_VIEW, &offset);
2322 d.width -= offset.x;
2323 d.height -= offset.y;
2324 *size = maxdim(*size, d);
2325 break;
2326 }
2327
2328 case WID_C_DESC_COMPANY_VALUE:
2329 SetDParam(0, INT64_MAX); // Arguably the maximum company value
2330 size->width = GetStringBoundingBox(STR_COMPANY_VIEW_COMPANY_VALUE).width;
2331 break;
2332
2333 case WID_C_DESC_VEHICLE_COUNTS:
2334 SetDParamMaxValue(0, 5000); // Maximum number of vehicles
2335 for (uint i = 0; i < lengthof(_company_view_vehicle_count_strings); i++) {
2336 size->width = std::max(size->width, GetStringBoundingBox(_company_view_vehicle_count_strings[i]).width + padding.width);
2337 }
2338 break;
2339
2340 case WID_C_DESC_INFRASTRUCTURE_COUNTS:
2341 SetDParamMaxValue(0, UINT_MAX);
2342 size->width = GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL).width;
2343 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD).width);
2344 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_WATER).width);
2345 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_STATION).width);
2346 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT).width);
2347 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_NONE).width);
2348 size->width += padding.width;
2349 break;
2350
2351 case WID_C_VIEW_HQ:
2352 case WID_C_BUILD_HQ:
2353 case WID_C_RELOCATE_HQ:
2354 case WID_C_VIEW_INFRASTRUCTURE:
2355 case WID_C_GIVE_MONEY:
2356 case WID_C_HOSTILE_TAKEOVER:
2357 case WID_C_COMPANY_PASSWORD:
2358 case WID_C_COMPANY_JOIN:
2359 size->width = GetStringBoundingBox(STR_COMPANY_VIEW_VIEW_HQ_BUTTON).width;
2360 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_BUILD_HQ_BUTTON).width);
2361 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_RELOCATE_HQ).width);
2362 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON).width);
2363 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_GIVE_MONEY_BUTTON).width);
2364 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_HOSTILE_TAKEOVER_BUTTON).width);
2365 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_PASSWORD).width);
2366 size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_JOIN).width);
2367 size->width += padding.width;
2368 break;
2369
2370 case WID_C_HAS_PASSWORD:
2371 if (_networking) *size = maxdim(*size, GetSpriteSize(SPR_LOCK));
2372 break;
2373 }
2374 }
2375
2376 void DrawVehicleCountsWidget(const Rect &r, const Company *c) const
2377 {
2378 static_assert(VEH_COMPANY_END == lengthof(_company_view_vehicle_count_strings));
2379
2380 int y = r.top;
2381 for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
2382 uint amount = c->group_all[type].num_vehicle;
2383 if (amount != 0) {
2384 SetDParam(0, amount);
2385 DrawString(r.left, r.right, y, _company_view_vehicle_count_strings[type]);
2386 y += GetCharacterHeight(FS_NORMAL);
2387 }
2388 }
2389
2390 if (y == r.top) {
2391 /* No String was emited before, so there must be no vehicles at all. */
2392 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
2393 }
2394 }
2395
2396 void DrawInfrastructureCountsWidget(const Rect &r, const Company *c) const
2397 {
2398 int y = r.top;
2399
2400 uint rail_pieces = c->infrastructure.signal;
2401 for (uint i = 0; i < lengthof(c->infrastructure.rail); i++) rail_pieces += c->infrastructure.rail[i];
2402 if (rail_pieces != 0) {
2403 SetDParam(0, rail_pieces);
2404 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL);
2405 y += GetCharacterHeight(FS_NORMAL);
2406 }
2407
2408 uint road_pieces = 0;
2409 for (uint i = 0; i < lengthof(c->infrastructure.road); i++) road_pieces += c->infrastructure.road[i];
2410 if (road_pieces != 0) {
2411 SetDParam(0, road_pieces);
2412 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD);
2413 y += GetCharacterHeight(FS_NORMAL);
2414 }
2415
2416 if (c->infrastructure.water != 0) {
2417 SetDParam(0, c->infrastructure.water);
2418 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_WATER);
2419 y += GetCharacterHeight(FS_NORMAL);
2420 }
2421
2422 if (c->infrastructure.station != 0) {
2423 SetDParam(0, c->infrastructure.station);
2424 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_STATION);
2425 y += GetCharacterHeight(FS_NORMAL);
2426 }
2427
2428 if (c->infrastructure.airport != 0) {
2429 SetDParam(0, c->infrastructure.airport);
2430 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT);
2431 y += GetCharacterHeight(FS_NORMAL);
2432 }
2433
2434 if (y == r.top) {
2435 /* No String was emited before, so there must be no infrastructure at all. */
2436 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
2437 }
2438 }
2439
2440 void DrawWidget(const Rect &r, WidgetID widget) const override
2441 {
2442 const Company *c = Company::Get((CompanyID)this->window_number);
2443 switch (widget) {
2444 case WID_C_FACE:
2445 DrawCompanyManagerFace(c->face, c->colour, r);
2446 break;
2447
2448 case WID_C_FACE_TITLE:
2449 SetDParam(0, c->index);
2450 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
2451 break;
2452
2453 case WID_C_DESC_COLOUR_SCHEME_EXAMPLE: {
2454 Point offset;
2455 Dimension d = GetSpriteSize(SPR_VEH_BUS_SW_VIEW, &offset);
2456 d.height -= offset.y;
2457 DrawSprite(SPR_VEH_BUS_SW_VIEW, COMPANY_SPRITE_COLOUR(c->index), r.left - offset.x, CenterBounds(r.top, r.bottom, d.height) - offset.y);
2458 break;
2459 }
2460
2461 case WID_C_DESC_VEHICLE_COUNTS:
2462 DrawVehicleCountsWidget(r, c);
2463 break;
2464
2465 case WID_C_DESC_INFRASTRUCTURE_COUNTS:
2466 DrawInfrastructureCountsWidget(r, c);
2467 break;
2468
2469 case WID_C_HAS_PASSWORD:
2470 if (_networking && NetworkCompanyIsPassworded(c->index)) {
2471 DrawSprite(SPR_LOCK, PAL_NONE, r.left, r.top);
2472 }
2473 break;
2474 }
2475 }
2476
2477 void SetStringParameters(WidgetID widget) const override
2478 {
2479 switch (widget) {
2480 case WID_C_CAPTION:
2481 SetDParam(0, (CompanyID)this->window_number);
2482 SetDParam(1, (CompanyID)this->window_number);
2483 break;
2484
2485 case WID_C_DESC_INAUGURATION:
2486 SetDParam(0, Company::Get((CompanyID)this->window_number)->inaugurated_year);
2487 break;
2488
2489 case WID_C_DESC_COMPANY_VALUE:
2490 SetDParam(0, CalculateCompanyValue(Company::Get((CompanyID)this->window_number)));
2491 break;
2492 }
2493 }
2494
2495 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2496 {
2497 switch (widget) {
2498 case WID_C_NEW_FACE: DoSelectCompanyManagerFace(this); break;
2499
2500 case WID_C_COLOUR_SCHEME:
2501 ShowCompanyLiveryWindow((CompanyID)this->window_number, INVALID_GROUP);
2502 break;
2503
2504 case WID_C_PRESIDENT_NAME:
2505 this->query_widget = WID_C_PRESIDENT_NAME;
2506 SetDParam(0, this->window_number);
2507 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);
2508 break;
2509
2510 case WID_C_COMPANY_NAME:
2511 this->query_widget = WID_C_COMPANY_NAME;
2512 SetDParam(0, this->window_number);
2513 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);
2514 break;
2515
2516 case WID_C_VIEW_HQ: {
2517 TileIndex tile = Company::Get((CompanyID)this->window_number)->location_of_HQ;
2518 if (_ctrl_pressed) {
2519 ShowExtraViewportWindow(tile);
2520 } else {
2521 ScrollMainWindowToTile(tile);
2522 }
2523 break;
2524 }
2525
2526 case WID_C_BUILD_HQ:
2527 if ((byte)this->window_number != _local_company) return;
2528 if (this->IsWidgetLowered(WID_C_BUILD_HQ)) {
2529 ResetObjectToPlace();
2530 this->RaiseButtons();
2531 break;
2532 }
2533 SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, HT_RECT, this);
2534 SetTileSelectSize(2, 2);
2535 this->LowerWidget(WID_C_BUILD_HQ);
2536 this->SetWidgetDirty(WID_C_BUILD_HQ);
2537 break;
2538
2539 case WID_C_RELOCATE_HQ:
2540 if (this->IsWidgetLowered(WID_C_RELOCATE_HQ)) {
2541 ResetObjectToPlace();
2542 this->RaiseButtons();
2543 break;
2544 }
2545 SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, HT_RECT, this);
2546 SetTileSelectSize(2, 2);
2547 this->LowerWidget(WID_C_RELOCATE_HQ);
2548 this->SetWidgetDirty(WID_C_RELOCATE_HQ);
2549 break;
2550
2551 case WID_C_VIEW_INFRASTRUCTURE:
2552 ShowCompanyInfrastructure((CompanyID)this->window_number);
2553 break;
2554
2555 case WID_C_GIVE_MONEY:
2556 this->query_widget = WID_C_GIVE_MONEY;
2557 ShowQueryString(STR_EMPTY, STR_COMPANY_VIEW_GIVE_MONEY_QUERY_CAPTION, 30, this, CS_NUMERAL, QSF_NONE);
2558 break;
2559
2560 case WID_C_HOSTILE_TAKEOVER:
2561 ShowBuyCompanyDialog((CompanyID)this->window_number, true);
2562 break;
2563
2564 case WID_C_COMPANY_PASSWORD:
2565 if (this->window_number == _local_company) ShowNetworkCompanyPasswordWindow(this);
2566 break;
2567
2568 case WID_C_COMPANY_JOIN: {
2569 this->query_widget = WID_C_COMPANY_JOIN;
2570 CompanyID company = (CompanyID)this->window_number;
2571 if (_network_server) {
2572 NetworkServerDoMove(CLIENT_ID_SERVER, company);
2573 MarkWholeScreenDirty();
2574 } else if (NetworkCompanyIsPassworded(company)) {
2575 /* ask for the password */
2576 ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION, NETWORK_PASSWORD_LENGTH, this, CS_ALPHANUMERAL, QSF_PASSWORD);
2577 } else {
2578 /* just send the join command */
2579 NetworkClientRequestMove(company);
2580 }
2581 break;
2582 }
2583 }
2584 }
2585
2587 IntervalTimer<TimerWindow> redraw_interval = {std::chrono::seconds(3), [this](auto) {
2588 this->SetDirty();
2589 }};
2590
2591 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
2592 {
2593 if (Command<CMD_BUILD_OBJECT>::Post(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS, tile, OBJECT_HQ, 0) && !_shift_pressed) {
2594 ResetObjectToPlace();
2595 this->RaiseButtons();
2596 }
2597 }
2598
2599 void OnPlaceObjectAbort() override
2600 {
2601 this->RaiseButtons();
2602 }
2603
2604 void OnQueryTextFinished(char *str) override
2605 {
2606 if (str == nullptr) return;
2607
2608 switch (this->query_widget) {
2609 default: NOT_REACHED();
2610
2611 case WID_C_GIVE_MONEY: {
2612 Money money = std::strtoull(str, nullptr, 10) / _currency->rate;
2613 Command<CMD_GIVE_MONEY>::Post(STR_ERROR_CAN_T_GIVE_MONEY, money, (CompanyID)this->window_number);
2614 break;
2615 }
2616
2617 case WID_C_PRESIDENT_NAME:
2618 Command<CMD_RENAME_PRESIDENT>::Post(STR_ERROR_CAN_T_CHANGE_PRESIDENT, str);
2619 break;
2620
2621 case WID_C_COMPANY_NAME:
2622 Command<CMD_RENAME_COMPANY>::Post(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME, str);
2623 break;
2624
2625 case WID_C_COMPANY_JOIN:
2626 NetworkClientRequestMove((CompanyID)this->window_number, str);
2627 break;
2628 }
2629 }
2630 };
2631
2632 static WindowDesc _company_desc(__FILE__, __LINE__,
2633 WDP_AUTO, "company", 0, 0,
2634 WC_COMPANY, WC_NONE,
2635 0,
2636 std::begin(_nested_company_widgets), std::end(_nested_company_widgets)
2637 );
2638
2643 void ShowCompany(CompanyID company)
2644 {
2645 if (!Company::IsValidID(company)) return;
2646
2647 AllocateWindowDescFront<CompanyWindow>(&_company_desc, company);
2648 }
2649
2654 void DirtyCompanyInfrastructureWindows(CompanyID company)
2655 {
2656 SetWindowDirty(WC_COMPANY, company);
2657 SetWindowDirty(WC_COMPANY_INFRASTRUCTURE, company);
2658 }
2659
2660 struct BuyCompanyWindow : Window {
2661 BuyCompanyWindow(WindowDesc *desc, WindowNumber window_number, bool hostile_takeover) : Window(desc), hostile_takeover(hostile_takeover)
2662 {
2663 this->InitNested(window_number);
2664
2665 const Company *c = Company::Get((CompanyID)this->window_number);
2666 this->company_value = hostile_takeover ? CalculateHostileTakeoverValue(c) : c->bankrupt_value;
2667 }
2668
2669 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
2670 {
2671 switch (widget) {
2672 case WID_BC_FACE:
2673 *size = GetScaledSpriteSize(SPR_GRADIENT);
2674 break;
2675
2676 case WID_BC_QUESTION:
2677 const Company *c = Company::Get((CompanyID)this->window_number);
2678 SetDParam(0, c->index);
2679 SetDParam(1, this->company_value);
2680 size->height = GetStringHeight(this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, size->width);
2681 break;
2682 }
2683 }
2684
2685 void SetStringParameters(WidgetID widget) const override
2686 {
2687 switch (widget) {
2688 case WID_BC_CAPTION:
2689 SetDParam(0, STR_COMPANY_NAME);
2690 SetDParam(1, Company::Get((CompanyID)this->window_number)->index);
2691 break;
2692 }
2693 }
2694
2695 void DrawWidget(const Rect &r, WidgetID widget) const override
2696 {
2697 switch (widget) {
2698 case WID_BC_FACE: {
2699 const Company *c = Company::Get((CompanyID)this->window_number);
2700 DrawCompanyManagerFace(c->face, c->colour, r);
2701 break;
2702 }
2703
2704 case WID_BC_QUESTION: {
2705 const Company *c = Company::Get((CompanyID)this->window_number);
2706 SetDParam(0, c->index);
2707 SetDParam(1, this->company_value);
2708 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);
2709 break;
2710 }
2711 }
2712 }
2713
2714 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2715 {
2716 switch (widget) {
2717 case WID_BC_NO:
2718 this->Close();
2719 break;
2720
2721 case WID_BC_YES:
2722 Command<CMD_BUY_COMPANY>::Post(STR_ERROR_CAN_T_BUY_COMPANY, (CompanyID)this->window_number, this->hostile_takeover);
2723 break;
2724 }
2725 }
2726
2730 IntervalTimer<TimerWindow> rescale_interval = {std::chrono::seconds(3), [this](auto) {
2731 /* Value can't change when in bankruptcy. */
2732 if (!this->hostile_takeover) return;
2733
2734 const Company *c = Company::Get((CompanyID)this->window_number);
2735 auto new_value = CalculateHostileTakeoverValue(c);
2736 if (new_value != this->company_value) {
2737 this->company_value = new_value;
2738 this->ReInit();
2739 }
2740 }};
2741
2742 private:
2743 bool hostile_takeover;
2744 Money company_value;
2745 };
2746
2747 static constexpr NWidgetPart _nested_buy_company_widgets[] = {
2748 NWidget(NWID_HORIZONTAL),
2749 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
2750 NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_BC_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2751 EndContainer(),
2752 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
2753 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
2754 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
2755 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BC_FACE), SetFill(0, 1),
2756 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BC_QUESTION), SetMinimalSize(240, 0), SetFill(1, 1),
2757 EndContainer(),
2758 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(100, WidgetDimensions::unscaled.hsep_wide, 100),
2759 NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_BC_NO), SetMinimalSize(60, 12), SetDataTip(STR_QUIT_NO, STR_NULL), SetFill(1, 0),
2760 NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_BC_YES), SetMinimalSize(60, 12), SetDataTip(STR_QUIT_YES, STR_NULL), SetFill(1, 0),
2761 EndContainer(),
2762 EndContainer(),
2763 EndContainer(),
2764 };
2765
2766 static WindowDesc _buy_company_desc(__FILE__, __LINE__,
2767 WDP_AUTO, nullptr, 0, 0,
2768 WC_BUY_COMPANY, WC_NONE,
2769 WDF_CONSTRUCTION,
2770 std::begin(_nested_buy_company_widgets), std::end(_nested_buy_company_widgets)
2771 );
2772
2778 void ShowBuyCompanyDialog(CompanyID company, bool hostile_takeover)
2779 {
2780 auto window = BringWindowToFrontById(WC_BUY_COMPANY, company);
2781 if (window == nullptr) {
2782 new BuyCompanyWindow(&_buy_company_desc, company, hostile_takeover);
2783 }
2784 }
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:546
SelectCompanyManagerFaceWindow::ge
GenderEthnicity ge
Gender and ethnicity.
Definition: company_gui.cpp:1370
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:1143
SelectCompanyManagerFaceWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: company_gui.cpp:1510
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:108
CompanyWindow::CWP_RELOCATE_SHOW
@ CWP_RELOCATE_SHOW
Show the relocate HQ button.
Definition: company_gui.cpp:2264
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:339
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:3086
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:2660
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:140
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:2257
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:1368
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:355
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:1132
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:1277
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
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
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:1367
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:238
_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:1208
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:617
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:1153
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:2028
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:1176
_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:2341
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:143
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:78
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:680
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:1365
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:1040
_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:82
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:722
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:2256
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:704
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:618
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:510
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:1190
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:1832
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:1088
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:1246
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:2654
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:1779
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:1384
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:2155
CompanyProperties::colour
Colours colour
Company colour.
Definition: company_base.h:85
CompanyProperties::money
Money money
Money owned by the company.
Definition: company_base.h:80
BuyCompanyWindow::rescale_interval
IntervalTimer< TimerWindow > rescale_interval
Check on a regular interval if the company value has changed.
Definition: company_gui.cpp:2730
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:1830
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:713
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:627
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:1260
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:50
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:1087
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:701
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:89
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:1003
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:703
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:103
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:3144
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:2267
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:937
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:559
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:92
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:771
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:388
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
CompanyInfrastructure::GetTramTotal
uint32_t GetTramTotal() const
Get total sum of all owned tram bits.
Definition: company_cmd.cpp:1226
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:557
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:2744
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:1445
CompanyProperties::yearly_expenses
std::array< Expenses, 3 > yearly_expenses
Expenses of the company for the last three years.
Definition: company_base.h:110
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:1222
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:53
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:2254
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:780
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:1372
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:2275
newgrf.h
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:762
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:1213
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:1371
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:55
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Definition: dropdown.cpp:369
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:2599
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:1165
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:1099
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1548
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:1234
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:2242
CompanyWindow::CWP_VB_BUILD
@ CWP_VB_BUILD
Display the build button.
Definition: company_gui.cpp:2261
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:2135
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:654
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:1374
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:2017
BuyCompanyWindow::hostile_takeover
bool hostile_takeover
Whether the window is showing a hostile takeover.
Definition: company_gui.cpp:2743
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:328
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:1870
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:1164
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:1111
CompanyInfrastructureWindow
Window with detailed information about the company's infrastructure.
Definition: company_gui.cpp:1827
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:1375
ShowCompany
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
Definition: company_gui.cpp:2643
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:129
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:1430
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:2587
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:1122
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:2260
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:848
object_type.h
timer_game_economy.h
CompanyInfrastructureWindow::railtypes
RailTypes railtypes
Valid railtypes.
Definition: company_gui.cpp:1829
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:635
Scrollbar::SetPosition
bool SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:792
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:2778
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:2265
CompanyWindow
Window with general information about a company.
Definition: company_gui.cpp:2249
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