100 uint GetHeight()
const
110 bool invalid_expenses_measured =
false;
111 for (uint i = 0; i < this->
length; i++) {
114 if (!invalid_expenses_measured) {
116 invalid_expenses_measured =
true;
144 for (uint i = 0; i < _expenses_list_types[type].
length; i++) {
151 DrawString(r.left, r.right, y, STR_FINANCES_SECTION_CONSTRUCTION + et);
168 StringID str = STR_FINANCES_NEGATIVE_INCOME;
195 for (uint i = 0; i < _expenses_list_types[type].
length; i++) {
198 Money cost = subtotal;
205 Money cost = (*tbl)[et];
208 if (cost != 0)
DrawPrice(cost, r.left, r.right, y);
218 static const NWidgetPart _nested_company_finances_widgets[] = {
330 size->height = _expenses_list_types[type].GetHeight();
336 size->height = _expenses_list_types[type].GetHeight();
365 if (wid_offset <= age) {
384 this->GetWidget<NWidgetStacked>(
WID_CF_SEL_PANEL)->SetDisplayedPlane(plane);
398 if (_expenses_list_types[type].GetHeight() != this->GetWidget<NWidgetBase>(
WID_CF_EXPS_CATEGORY)->current_y) {
426 this->small = !this->
small;
469 _nested_company_finances_widgets,
lengthof(_nested_company_finances_widgets)
486 static const StringID _colour_dropdown[] = {
487 STR_COLOUR_DARK_BLUE,
488 STR_COLOUR_PALE_GREEN,
492 STR_COLOUR_LIGHT_BLUE,
494 STR_COLOUR_DARK_GREEN,
508 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,
511 LC_AIRCRAFT, LC_AIRCRAFT, LC_AIRCRAFT,
521 return this->result >= COLOUR_END ? STR_COLOUR_DEFAULT : _colour_dropdown[this->
result];
524 uint Height(uint width)
const override
529 bool Selectable()
const override
534 void Draw(
int left,
int right,
int top,
int bottom,
bool sel, Colours bg_colour)
const override
537 int height = bottom - top;
538 int icon_y_offset = height / 2;
542 top + icon_y_offset);
545 top + text_y_offset, this->String(), sel ? TC_WHITE : TC_BLACK);
562 std::vector<int> indents;
565 void ShowColourDropDownMenu(uint32 widget)
567 uint32 used_colours = 0;
569 const Livery *livery, *default_livery =
nullptr;
574 if (this->livery_class < LC_GROUP_RAIL &&
HasBit(this->sel, LS_DEFAULT) && primary) {
582 if (this->livery_class < LC_GROUP_RAIL) {
585 for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
586 if (
HasBit(this->sel, scheme))
break;
588 if (scheme == LS_END) scheme = LS_DEFAULT;
589 livery = &c->livery[scheme];
590 if (scheme != LS_DEFAULT) default_livery = &c->livery[LS_DEFAULT];
595 default_livery = &c->livery[LS_DEFAULT];
598 default_livery = &pg->
livery;
603 if (default_livery !=
nullptr) {
605 default_col = (primary ? default_livery->
colour1 : default_livery->
colour2) + COLOUR_END;
608 for (uint i = 0; i <
lengthof(_colour_dropdown); i++) {
612 byte sel = (default_livery ==
nullptr ||
HasBit(livery->
in_use, primary ? 0 : 1)) ? (primary ? livery->
colour1 : livery->
colour2) : default_col;
618 for (
const Group *g : *source) {
619 if (g->parent !=
parent)
continue;
620 this->groups.push_back(g);
621 this->indents.push_back(indent);
622 AddChildren(source, g->index, indent + 1);
630 this->groups.clear();
631 this->indents.clear();
633 if (this->livery_class >= LC_GROUP_RAIL) {
638 if (g->owner ==
owner && g->vehicle_type == vtype) {
646 const Group *last_group[2] = {
nullptr,
nullptr };
647 char last_name[2][64] = {
"",
"" };
648 list.
Sort([&](
const Group *
const &a,
const Group *
const &b) ->
bool {
649 if (a != last_group[0]) {
652 GetString(last_name[0], STR_GROUP_NAME,
lastof(last_name[0]));
655 if (b != last_group[1]) {
658 GetString(last_name[1], STR_GROUP_NAME,
lastof(last_name[1]));
661 int r =
strnatcmp(last_name[0], last_name[1]);
669 this->groups.shrink_to_fit();
675 if (this->livery_class < LC_GROUP_RAIL) {
677 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
683 this->rows = (uint)this->groups.size();
686 this->vscroll->
SetCount(this->rows);
696 this->livery_class = LC_OTHER;
699 this->BuildGroupList(company);
702 this->SetSelectedGroup(company, group);
706 this->owner = company;
715 case VEH_TRAIN: this->livery_class = LC_GROUP_RAIL;
break;
716 case VEH_ROAD: this->livery_class = LC_GROUP_ROAD;
break;
717 case VEH_SHIP: this->livery_class = LC_GROUP_SHIP;
break;
718 case VEH_AIRCRAFT: this->livery_class = LC_GROUP_AIRCRAFT;
break;
719 default: NOT_REACHED();
725 this->BuildGroupList(company);
729 for (uint i = 0; i < this->rows; i++) {
730 if (this->groups[i]->index == sel) {
731 this->vscroll->
SetPosition(
Clamp(i - this->vscroll->
GetCapacity() / 2, 0, std::max(this->vscroll->GetCount() - this->vscroll->GetCapacity(), 0)));
743 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
749 if (g->owner == (
CompanyID)this->window_number) {
764 size->height = 11 * this->line_height;
766 resize->height = this->line_height;
779 int string_padding = this->square.width + NWidgetScrollbar::GetVerticalDimension().width + 10;
780 for (
const StringID *
id = _colour_dropdown;
id !=
endof(_colour_dropdown);
id++) {
794 bool disabled = this->livery_class < LC_GROUP_RAIL ? (this->sel == 0) : (this->sel ==
INVALID_GROUP);
814 StringID colour = STR_COLOUR_DEFAULT;
816 if (this->livery_class < LC_GROUP_RAIL) {
817 if (this->sel != 0) {
819 for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
820 if (
HasBit(this->sel, scheme))
break;
822 if (scheme == LS_END) scheme = LS_DEFAULT;
823 const Livery *livery = &c->livery[scheme];
824 if (scheme == LS_DEFAULT ||
HasBit(livery->
in_use, primary ? 0 : 1)) {
825 colour = STR_COLOUR_DARK_BLUE + (primary ? livery->
colour1 : livery->
colour2);
833 colour = STR_COLOUR_DARK_BLUE + (primary ? livery->
colour1 : livery->
colour2);
851 int sch_left = nwi->
pos_x;
852 int sch_right = sch_left + nwi->
current_x - 1;
855 int pri_left = nwi->
pos_x;
856 int pri_right = pri_left + nwi->
current_x - 1;
859 int sec_left = nwi->
pos_x;
860 int sec_right = sec_left + nwi->
current_x - 1;
865 int square_offs = (this->line_height - this->square.height) / 2 + 1;
871 auto draw_livery = [&](
StringID str,
const Livery &liv,
bool sel,
bool def,
int indent) {
877 DrawString(pri_left + text_left, pri_right - text_right, y + text_offs, (def ||
HasBit(liv.in_use, 0)) ? STR_COLOUR_DARK_BLUE + liv.colour1 : STR_COLOUR_DEFAULT, sel ? TC_WHITE : TC_GOLD);
880 if (sec_right > sec_left) {
882 DrawString(sec_left + text_left, sec_right - text_right, y + text_offs, (def ||
HasBit(liv.in_use, 1)) ? STR_COLOUR_DARK_BLUE + liv.colour2 : STR_COLOUR_DEFAULT, sel ? TC_WHITE : TC_GOLD);
885 y += this->line_height;
888 if (livery_class < LC_GROUP_RAIL) {
891 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
893 if (pos-- > 0)
continue;
894 draw_livery(STR_LIVERY_DEFAULT + scheme, c->livery[scheme],
HasBit(this->sel, scheme), scheme == LS_DEFAULT, 0);
898 uint max =
static_cast<uint
>(std::min<size_t>(this->vscroll->
GetPosition() + this->vscroll->GetCapacity(), this->groups.size()));
899 for (uint i = this->vscroll->
GetPosition(); i < max; ++i) {
900 const Group *g = this->groups[i];
925 if (this->livery_class < LC_GROUP_RAIL) {
927 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
929 this->sel = 1 << scheme;
938 if (this->groups.size() > 0) {
939 this->sel = this->groups[0]->index;
957 if (row >= this->rows)
return;
959 if (this->livery_class < LC_GROUP_RAIL) {
962 for (
LiveryScheme scheme = LS_BEGIN; scheme <= j && scheme < LS_END; scheme++) {
973 this->sel = this->groups[row]->index;
991 if (index >= COLOUR_END) index = INVALID_COLOUR;
993 if (this->livery_class < LC_GROUP_RAIL) {
995 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1014 if (!gui_scope)
return;
1018 if (this->livery_class == data + LC_GROUP_RAIL) {
1025 if (this->groups.size() > 0) this->sel = this->groups[0]->index;
1035 bool current_class_valid = this->livery_class == LC_OTHER || this->livery_class >= LC_GROUP_RAIL;
1037 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1039 if (_livery_class[scheme] == this->livery_class) current_class_valid =
true;
1041 }
else if (this->livery_class < LC_GROUP_RAIL) {
1042 ClrBit(this->sel, scheme);
1047 if (!current_class_valid) {
1054 static const NWidgetPart _nested_select_company_livery_widgets [] = {
1075 SetDataTip(STR_BLACK_STRING, STR_LIVERY_SECONDARY_TOOLTIP),
1078 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),
1086 static WindowDesc _select_company_livery_desc(
1090 _nested_select_company_livery_widgets,
lengthof(_nested_select_company_livery_widgets)
1099 w->SetSelectedGroup(company, group);
1120 if (
_cmf_info[CMFV_EYE_COLOUR].valid_values[ge] < 2) {
1124 default: NOT_REACHED();
1125 case 0: pal = PALETTE_TO_BROWN;
break;
1126 case 1: pal = PALETTE_TO_BLUE;
break;
1127 case 2: pal = PALETTE_TO_GREEN;
break;
1132 DrawSprite(SPR_GRADIENT, GENERAL_SPRITE_COLOUR(colour), x, y);
1134 for (CompanyManagerFaceVariable cmfv = CMFV_CHEEKS; cmfv < CMFV_END; cmfv++) {
1136 case CMFV_MOUSTACHE:
if (!has_moustache)
continue;
break;
1138 case CMFV_NOSE:
if (has_moustache)
continue;
break;
1139 case CMFV_TIE_EARRING:
if (!has_tie_earring)
continue;
break;
1140 case CMFV_GLASSES:
if (!has_glasses)
continue;
break;
1316 const NWidgetCore *nwi_widget = this->GetWidget<NWidgetCore>(widget_index);
1318 if (is_bool_widget) {
1320 str = (val != 0) ? STR_FACE_YES : STR_FACE_NO;
1340 this->GetWidget<NWidgetCore>(
WID_SCMF_TIE_EARRING_TEXT)->widget_data = this->is_female ? STR_FACE_EARRING : STR_FACE_TIE;
1347 this->advanced =
false;
1371 wi->
SetDataTip(STR_FACE_SIMPLE, STR_FACE_SIMPLE_TOOLTIP);
1373 wi->
SetDataTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP);
1385 for (
int val = 1; val <= 12; val++) {
1420 size->width = std::max(size->width, face_size.width);
1421 size->height = std::max(size->height, face_size.height);
1510 if (this->is_female) {
1522 if (this->is_moust_male) {
1646 CompanyManagerFaceVariable cmfv;
1650 default: NOT_REACHED();
1651 case 0: cmfv = this->is_female ? CMFV_HAS_TIE_EARRING : CMFV_HAS_MOUSTACHE;
break;
1652 case 1: cmfv = CMFV_HAS_GLASSES;
break;
1658 default: NOT_REACHED();
1659 case 0: cmfv = CMFV_EYE_COLOUR;
break;
1660 case 1: cmfv = CMFV_CHIN;
break;
1661 case 2: cmfv = CMFV_EYEBROWS;
break;
1662 case 3: cmfv = this->is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS;
break;
1663 case 4: cmfv = CMFV_NOSE;
break;
1664 case 5: cmfv = CMFV_HAIR;
break;
1665 case 6: cmfv = CMFV_JACKET;
break;
1666 case 7: cmfv = CMFV_COLLAR;
break;
1667 case 8: cmfv = CMFV_TIE_EARRING;
break;
1668 case 9: cmfv = CMFV_GLASSES;
break;
1682 if (str ==
nullptr)
return;
1685 this->face = strtoul(str,
nullptr, 10);
1717 static const NWidgetPart _nested_company_infrastructure_widgets[] = {
1766 this->UpdateRailRoadTypes();
1772 void UpdateRailRoadTypes()
1796 this->roadtypes &= ~_roadtypes_hidden_mask;
1843 for (
const auto &rt : _sorted_railtypes) {
1844 if (
HasBit(this->railtypes, rt)) {
1865 for (
const auto &rt : _sorted_roadtypes) {
1895 uint32 max_val = 1000;
1896 Money max_cost = 10000;
1924 size->width = std::max(size->width, this->total_width);
1930 size->width = std::max(size->width, count_width);
1970 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT);
1974 for (
const auto &rt : _sorted_railtypes) {
1975 if (
HasBit(this->railtypes, rt)) {
1991 for (
const auto &rt : _sorted_railtypes) {
1992 if (
HasBit(this->railtypes, rt)) {
2004 DrawString(r.left, r.right, y, widget ==
WID_CI_ROAD_DESC ? STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT : STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT);
2007 for (
const auto &rt : _sorted_roadtypes) {
2020 for (
const auto &rt : _sorted_roadtypes) {
2029 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT);
2043 DrawString(left,
left + this->total_width, y, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL, TC_FROMSTRING,
SA_RIGHT);
2048 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT);
2067 if (!gui_scope)
return;
2069 this->UpdateRailRoadTypes();
2074 static WindowDesc _company_infrastructure_desc(
2075 WDP_AUTO,
"company_infrastructure", 0, 0,
2078 _nested_company_infrastructure_widgets,
lengthof(_nested_company_infrastructure_widgets)
2088 AllocateWindowDescFront<CompanyInfrastructureWindow>(&_company_infrastructure_desc, company);
2091 static const NWidgetPart _nested_company_widgets[] = {
2201 STR_COMPANY_VIEW_TRAINS, STR_COMPANY_VIEW_ROAD_VEHICLES, STR_COMPANY_VIEW_SHIPS, STR_COMPANY_VIEW_AIRCRAFT
2233 this->owner = (
Owner)this->window_number;
2243 bool reinit =
false;
2317 size->width = std::max(size->width, face_size.width);
2318 size->height = std::max(size->height, face_size.height);
2325 d.width -= offset.x;
2326 d.height -= offset.y;
2327 *size =
maxdim(*size, d);
2401 d.height -= offset.y;
2402 DrawSprite(SPR_VEH_BUS_SW_VIEW, COMPANY_SPRITE_COLOUR(c->
index), r.left - offset.x, (r.top + r.bottom - d.height) / 2 - offset.y);
2414 if (amounts[0] + amounts[1] + amounts[2] + amounts[3] == 0) {
2415 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
2419 for (uint i = 0; i <
lengthof(amounts); i++) {
2420 if (amounts[i] != 0) {
2435 uint road_pieces = 0;
2440 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
2442 if (rail_pieces != 0) {
2444 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL);
2447 if (road_pieces != 0) {
2449 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD);
2454 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_WATER);
2459 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_STATION);
2464 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT);
2475 uint amt = GetAmountOwnedBy(c, c2->
index);
2480 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_SHARES_OWNED_BY);
2489 DrawSprite(SPR_LOCK, PAL_NONE, r.left, r.top);
2587 if (this->window_number ==
_local_company) ShowNetworkCompanyPasswordWindow(
this);
2629 if (str ==
nullptr)
return;
2631 switch (this->query_widget) {
2632 default: NOT_REACHED();
2635 Money money = (
Money)(strtoull(str,
nullptr, 10) / _currency->rate);
2691 _nested_company_widgets,
lengthof(_nested_company_widgets)
2702 AllocateWindowDescFront<CompanyWindow>(&_company_desc, company);
2780 static const NWidgetPart _nested_buy_company_widgets[] = {
2803 _nested_buy_company_widgets,
lengthof(_nested_buy_company_widgets)
2812 AllocateWindowDescFront<BuyCompanyWindow>(&_buy_company_desc, company);