87 const std::initializer_list<ExpensesType> &
items;
93 uint GetHeight()
const
166 DrawString(tr, STR_FINANCES_SECTION_CONSTRUCTION + et);
190 y += list.GetHeight();
218 StringID str = STR_FINANCES_NEGATIVE_INCOME;
220 str = STR_FINANCES_ZERO_INCOME;
221 }
else if (amount < 0) {
223 str = STR_FINANCES_POSITIVE_INCOME;
239 Money cost = tbl[et];
241 if (cost != 0)
DrawPrice(cost, r.left, r.right, y, TC_BLACK);
248 if (sum != 0)
DrawPrice(sum, r.left, r.right, y, TC_WHITE);
283 DrawPrice(sum, r.left, r.right, y, TC_WHITE);
286 static constexpr
NWidgetPart _nested_company_finances_widgets[] = {
349 void SetStringParameters(
WidgetID widget)
const override
419 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
432 if (wid_offset <= age) {
451 this->GetWidget<NWidgetStacked>(
WID_CF_SEL_PANEL)->SetDisplayedPlane(plane);
488 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
492 this->small = !this->
small;
538 _nested_company_finances_widgets
557 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,
560 LC_AIRCRAFT, LC_AIRCRAFT, LC_AIRCRAFT,
568 template <SpriteID TSprite = SPR_SQUARE>
587 void ShowColourDropDownMenu(uint32_t widget)
589 uint32_t used_colours = 0;
590 const Livery *livery, *default_livery =
nullptr;
592 uint8_t default_col = 0;
595 if (this->livery_class < LC_GROUP_RAIL &&
HasBit(this->sel, LS_DEFAULT) && primary) {
603 if (this->livery_class < LC_GROUP_RAIL) {
606 for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
607 if (
HasBit(this->sel, scheme))
break;
609 if (scheme == LS_END) scheme = LS_DEFAULT;
610 livery = &c->livery[scheme];
611 if (scheme != LS_DEFAULT) default_livery = &c->livery[LS_DEFAULT];
616 default_livery = &c->livery[LS_DEFAULT];
619 default_livery = &pg->
livery;
624 if (default_livery !=
nullptr) {
626 default_col = (primary ? default_livery->
colour1 : default_livery->
colour2) + COLOUR_END;
629 for (Colours colour = COLOUR_BEGIN; colour != COLOUR_END; colour++) {
634 if (default_livery ==
nullptr ||
HasBit(livery->
in_use, primary ? 0 : 1)) {
646 this->groups.clear();
648 if (this->livery_class >= LC_GROUP_RAIL) {
658 if (this->livery_class < LC_GROUP_RAIL) {
660 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
666 this->rows = (uint)this->groups.size();
669 this->vscroll->
SetCount(this->rows);
679 this->livery_class = LC_OTHER;
682 this->BuildGroupList(company);
685 this->SetSelectedGroup(company, group);
689 this->owner = company;
698 case VEH_TRAIN: this->livery_class = LC_GROUP_RAIL;
break;
699 case VEH_ROAD: this->livery_class = LC_GROUP_ROAD;
break;
700 case VEH_SHIP: this->livery_class = LC_GROUP_SHIP;
break;
701 case VEH_AIRCRAFT: this->livery_class = LC_GROUP_AIRCRAFT;
break;
702 default: NOT_REACHED();
708 this->BuildGroupList(company);
712 for (uint i = 0; i < this->rows; i++) {
713 if (this->groups[i].group->index == sel) {
726 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
732 if (g->owner == (
CompanyID)this->window_number) {
738 size.width = std::max(size.width, 5 + d.width + padding.width);
747 size.height = 5 * this->line_height;
749 resize.height = this->line_height;
763 for (Colours colour = COLOUR_BEGIN; colour != COLOUR_END; colour++) {
777 bool disabled = this->livery_class < LC_GROUP_RAIL ? (this->sel == 0) : (this->sel ==
INVALID_GROUP);
786 void SetStringParameters(
WidgetID widget)
const override
797 StringID colour = STR_COLOUR_DEFAULT;
799 if (this->livery_class < LC_GROUP_RAIL) {
800 if (this->sel != 0) {
802 for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
803 if (
HasBit(this->sel, scheme))
break;
805 if (scheme == LS_END) scheme = LS_DEFAULT;
806 const Livery *livery = &c->livery[scheme];
807 if (scheme == LS_DEFAULT ||
HasBit(livery->
in_use, primary ? 0 : 1)) {
808 colour = STR_COLOUR_DARK_BLUE + (primary ? livery->
colour1 : livery->
colour2);
816 colour = STR_COLOUR_DARK_BLUE + (primary ? livery->
colour1 : livery->
colour2);
826 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
849 int square_offs = (ir.
Height() - this->square.height) / 2;
855 auto draw_livery = [&](
StringID str,
const Livery &livery,
bool is_selected,
bool is_default_scheme,
int indent) {
857 DrawString(sch.left + (rtl ? 0 : indent), sch.right - (rtl ? indent : 0), y + text_offs, str, is_selected ? TC_WHITE : TC_BLACK);
860 DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOUR(livery.colour1), pri_squ.left, y + square_offs);
861 DrawString(pri.left, pri.right, y + text_offs, (is_default_scheme ||
HasBit(livery.in_use, 0)) ? STR_COLOUR_DARK_BLUE + livery.colour1 : STR_COLOUR_DEFAULT, is_selected ? TC_WHITE : TC_GOLD);
864 if (sec.right > sec.left) {
865 DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOUR(livery.colour2), sec_squ.left, y + square_offs);
866 DrawString(sec.left, sec.right, y + text_offs, (is_default_scheme ||
HasBit(livery.in_use, 1)) ? STR_COLOUR_DARK_BLUE + livery.colour2 : STR_COLOUR_DEFAULT, is_selected ? TC_WHITE : TC_GOLD);
869 y += this->line_height;
874 if (livery_class < LC_GROUP_RAIL) {
876 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
878 if (pos-- > 0)
continue;
879 draw_livery(STR_LIVERY_DEFAULT + scheme, c->livery[scheme],
HasBit(this->sel, scheme), scheme == LS_DEFAULT, 0);
884 for (
auto it = first; it != last; ++it) {
885 const Group *g = it->group;
890 if (this->vscroll->
GetCount() == 0) {
891 const StringID empty_labels[] = { STR_LIVERY_TRAIN_GROUP_EMPTY, STR_LIVERY_ROAD_VEHICLE_GROUP_EMPTY, STR_LIVERY_SHIP_GROUP_EMPTY, STR_LIVERY_AIRCRAFT_GROUP_EMPTY };
893 DrawString(ir.left, ir.right, y + text_offs, empty_labels[vtype], TC_BLACK);
898 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
916 if (this->livery_class < LC_GROUP_RAIL) {
918 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
920 this->sel = 1 << scheme;
929 if (!this->groups.empty()) {
930 this->sel = this->groups[0].group->index;
947 if (this->livery_class < LC_GROUP_RAIL) {
949 if (row >= this->rows)
return;
953 for (
LiveryScheme scheme = LS_BEGIN; scheme <= j && scheme < LS_END; scheme++) {
965 if (it == std::end(this->groups))
return;
967 this->sel = it->group->index;
980 void OnDropdownSelect(
WidgetID widget,
int index)
override
985 Colours colour =
static_cast<Colours
>(index);
986 if (colour >= COLOUR_END) colour = INVALID_COLOUR;
988 if (this->livery_class < LC_GROUP_RAIL) {
990 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1007 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1009 if (!gui_scope)
return;
1013 if (this->livery_class == data + LC_GROUP_RAIL) {
1020 if (!this->groups.empty()) this->sel = this->groups[0].group->index;
1030 bool current_class_valid = this->livery_class == LC_OTHER || this->livery_class >= LC_GROUP_RAIL;
1032 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1034 if (_livery_class[scheme] == this->livery_class) current_class_valid =
true;
1036 }
else if (this->livery_class < LC_GROUP_RAIL) {
1037 ClrBit(this->sel, scheme);
1042 if (!current_class_valid) {
1049 static constexpr
NWidgetPart _nested_select_company_livery_widgets[] = {
1070 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),
1081 static WindowDesc _select_company_livery_desc(
1082 WDP_AUTO,
"company_color_scheme", 0, 0,
1085 _nested_select_company_livery_widgets
1094 w->SetSelectedGroup(company, group);
1119 if (
_cmf_info[CMFV_EYE_COLOUR].valid_values[ge] < 2) {
1123 default: NOT_REACHED();
1124 case 0: pal = PALETTE_TO_BROWN;
break;
1125 case 1: pal = PALETTE_TO_BLUE;
break;
1126 case 2: pal = PALETTE_TO_GREEN;
break;
1131 DrawSprite(SPR_GRADIENT, GENERAL_SPRITE_COLOUR(colour), x, y);
1133 for (CompanyManagerFaceVariable cmfv = CMFV_CHEEKS; cmfv < CMFV_END; cmfv++) {
1135 case CMFV_MOUSTACHE:
if (!has_moustache)
continue;
break;
1137 case CMFV_NOSE:
if (has_moustache)
continue;
break;
1138 case CMFV_TIE_EARRING:
if (!has_tie_earring)
continue;
break;
1139 case CMFV_GLASSES:
if (!has_glasses)
continue;
break;
1325 const NWidgetCore *nwi_widget = this->GetWidget<NWidgetCore>(widget_index);
1329 if (is_bool_widget) {
1331 SetDParam(0, (val != 0) ? STR_FACE_YES : STR_FACE_NO);
1347 this->GetWidget<NWidgetCore>(
WID_SCMF_TIE_EARRING_TEXT)->widget_data = this->is_female ? STR_FACE_EARRING : STR_FACE_TIE;
1354 this->advanced =
false;
1378 wi->
SetDataTip(STR_FACE_SIMPLE, STR_FACE_SIMPLE_TOOLTIP);
1380 wi->
SetDataTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP);
1392 for (
int val = 1; val <= 12; val++) {
1510 void SetStringParameters(
WidgetID widget)
const override
1514 if (this->is_female) {
1526 if (this->is_moust_male) {
1571 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
1580 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1655 CompanyManagerFaceVariable cmfv;
1659 default: NOT_REACHED();
1660 case 0: cmfv = this->is_female ? CMFV_HAS_TIE_EARRING : CMFV_HAS_MOUSTACHE;
break;
1661 case 1: cmfv = CMFV_HAS_GLASSES;
break;
1667 default: NOT_REACHED();
1668 case 0: cmfv = CMFV_EYE_COLOUR;
break;
1669 case 1: cmfv = CMFV_CHIN;
break;
1670 case 2: cmfv = CMFV_EYEBROWS;
break;
1671 case 3: cmfv = this->is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS;
break;
1672 case 4: cmfv = CMFV_NOSE;
break;
1673 case 5: cmfv = CMFV_HAIR;
break;
1674 case 6: cmfv = CMFV_JACKET;
break;
1675 case 7: cmfv = CMFV_COLLAR;
break;
1676 case 8: cmfv = CMFV_TIE_EARRING;
break;
1677 case 9: cmfv = CMFV_GLASSES;
break;
1689 void OnQueryTextFinished(std::optional<std::string> str)
override
1691 if (!str.has_value())
return;
1693 if (!str->empty()) {
1694 this->face = std::strtoul(str->c_str(),
nullptr, 10);
1726 static constexpr
NWidgetPart _nested_company_infrastructure_widgets[] = {
1775 this->UpdateRailRoadTypes();
1778 this->owner = (
Owner)this->window_number;
1781 void UpdateRailRoadTypes()
1805 this->roadtypes &= ~_roadtypes_hidden_mask;
1833 void SetStringParameters(
WidgetID widget)
const override
1850 size.width = std::max(size.width,
GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT).
width + padding.width);
1852 for (
const auto &rt : _sorted_railtypes) {
1853 if (
HasBit(this->railtypes, rt)) {
1873 for (
const auto &rt : _sorted_roadtypes) {
1885 size.width = std::max(size.width,
GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT).
width + padding.width);
1890 size.width = std::max(size.width,
GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT).
width + padding.width);
1902 uint32_t max_val = 1000;
1903 Money max_cost = 10000;
1932 size.width = std::max(size.width, this->total_width);
1938 size.width = std::max(size.width, count_width);
1970 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
1979 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT);
1983 for (
const auto &rt : _sorted_railtypes) {
1984 if (
HasBit(this->railtypes, rt)) {
1999 for (
const auto &rt : _sorted_railtypes) {
2000 if (
HasBit(this->railtypes, rt)) {
2012 DrawString(r.left, r.right, y, widget ==
WID_CI_ROAD_DESC ? STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT : STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT);
2015 for (
const auto &rt : _sorted_roadtypes) {
2027 for (
const auto &rt : _sorted_roadtypes) {
2036 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT);
2057 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT);
2074 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2076 if (!gui_scope)
return;
2078 this->UpdateRailRoadTypes();
2083 static WindowDesc _company_infrastructure_desc(
2084 WDP_AUTO,
"company_infrastructure", 0, 0,
2087 _nested_company_infrastructure_widgets
2097 AllocateWindowDescFront<CompanyInfrastructureWindow>(_company_infrastructure_desc, company);
2100 static constexpr
NWidgetPart _nested_company_widgets[] = {
2178 STR_COMPANY_VIEW_TRAINS, STR_COMPANY_VIEW_ROAD_VEHICLES, STR_COMPANY_VIEW_SHIPS, STR_COMPANY_VIEW_AIRCRAFT
2202 this->owner = (
Owner)this->window_number;
2212 bool reinit =
false;
2253 d.width -= offset.x;
2254 d.height -= offset.y;
2279 size.width += padding.width;
2296 size.width += padding.width;
2301 void DrawVehicleCountsWidget(
const Rect &r,
const Company *c)
const
2317 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
2321 void DrawInfrastructureCountsWidget(
const Rect &r,
const Company *c)
const
2326 if (rail_pieces != 0) {
2328 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL);
2334 if (road_pieces != 0) {
2336 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD);
2342 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_WATER);
2348 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_STATION);
2354 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT);
2360 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
2364 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
2380 d.height -= offset.y;
2381 DrawSprite(SPR_VEH_BUS_SW_VIEW, COMPANY_SPRITE_COLOUR(c->
index), r.left - offset.x,
CenterBounds(r.top, r.bottom, d.height) - offset.y);
2386 DrawVehicleCountsWidget(r, c);
2390 DrawInfrastructureCountsWidget(r, c);
2395 void SetStringParameters(
WidgetID widget)
const override
2405 SetDParam(0, STR_COMPANY_VIEW_INAUGURATED_TITLE_WALLCLOCK);
2409 SetDParam(0, STR_COMPANY_VIEW_INAUGURATED_TITLE);
2428 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
2517 void OnPlaceObject([[maybe_unused]]
Point pt,
TileIndex tile)
override
2530 void OnQueryTextFinished(std::optional<std::string> str)
override
2532 if (!str.has_value())
return;
2534 switch (this->query_widget) {
2535 default: NOT_REACHED();
2553 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2555 if (gui_scope && data == 1) {
2566 _nested_company_widgets
2577 AllocateWindowDescFront<CompanyWindow>(_company_desc, company);
2610 size.height =
GetStringHeight(this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, size.width);
2615 void SetStringParameters(
WidgetID widget)
const override
2625 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
2638 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, TC_FROMSTRING,
SA_CENTER);
2644 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
2662 if (!this->hostile_takeover)
return;
2677 static constexpr
NWidgetPart _nested_buy_company_widgets[] = {
2700 _nested_buy_company_widgets
2711 if (window ==
nullptr) {