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