93 uint GetHeight()
const
103 for (uint i = 0; i < this->
length; i++) {
168 for (uint i = 0; i < list.
length; i++) {
170 DrawString(r.left + offs_left, r.right - offs_right, y, STR_FINANCES_SECTION_CONSTRUCTION + et);
187 DrawString(r.left, r.right, y, (STR_FINANCES_REVENUE_TITLE + i), TC_FROMSTRING,
SA_LEFT);
216 StringID str = STR_FINANCES_NEGATIVE_INCOME;
218 str = STR_FINANCES_ZERO_INCOME;
219 }
else if (amount < 0) {
221 str = STR_FINANCES_POSITIVE_INCOME;
237 for (uint i = 0; i < list.
length; i++) {
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 const NWidgetPart _nested_company_finances_widgets[] = {
438 if (wid_offset <= age) {
457 this->GetWidget<NWidgetStacked>(
WID_CF_SEL_PANEL)->SetDisplayedPlane(plane);
498 this->small = !this->
small;
541 _nested_company_finances_widgets,
lengthof(_nested_company_finances_widgets)
558 static const StringID _colour_dropdown[] = {
559 STR_COLOUR_DARK_BLUE,
560 STR_COLOUR_PALE_GREEN,
564 STR_COLOUR_LIGHT_BLUE,
566 STR_COLOUR_DARK_GREEN,
580 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,
583 LC_AIRCRAFT, LC_AIRCRAFT, LC_AIRCRAFT,
593 return this->result >= COLOUR_END ? STR_COLOUR_DEFAULT : _colour_dropdown[this->
result];
596 uint Height(uint width)
const override
601 bool Selectable()
const override
606 void Draw(
int left,
int right,
int top,
int bottom,
bool sel, Colours bg_colour)
const override
609 int height = bottom - top;
610 int icon_y_offset = height / 2;
614 top + icon_y_offset);
617 top + text_y_offset, this->String(), sel ? TC_WHITE : TC_BLACK);
634 std::vector<int> indents;
637 void ShowColourDropDownMenu(uint32 widget)
639 uint32 used_colours = 0;
641 const Livery *livery, *default_livery =
nullptr;
646 if (this->livery_class < LC_GROUP_RAIL &&
HasBit(this->sel, LS_DEFAULT) && primary) {
654 if (this->livery_class < LC_GROUP_RAIL) {
657 for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
658 if (
HasBit(this->sel, scheme))
break;
660 if (scheme == LS_END) scheme = LS_DEFAULT;
661 livery = &c->livery[scheme];
662 if (scheme != LS_DEFAULT) default_livery = &c->livery[LS_DEFAULT];
667 default_livery = &c->livery[LS_DEFAULT];
670 default_livery = &pg->
livery;
675 if (default_livery !=
nullptr) {
677 default_col = (primary ? default_livery->
colour1 : default_livery->
colour2) + COLOUR_END;
680 for (uint i = 0; i <
lengthof(_colour_dropdown); i++) {
684 byte sel = (default_livery ==
nullptr ||
HasBit(livery->
in_use, primary ? 0 : 1)) ? (primary ? livery->
colour1 : livery->
colour2) : default_col;
690 for (
const Group *g : *source) {
691 if (g->parent !=
parent)
continue;
692 this->groups.push_back(g);
693 this->indents.push_back(indent);
694 AddChildren(source, g->index, indent + 1);
702 this->groups.clear();
703 this->indents.clear();
705 if (this->livery_class >= LC_GROUP_RAIL) {
710 if (g->owner ==
owner && g->vehicle_type == vtype) {
718 const Group *last_group[2] = {
nullptr,
nullptr };
719 char last_name[2][64] = {
"",
"" };
720 list.
Sort([&](
const Group *
const &a,
const Group *
const &b) ->
bool {
721 if (a != last_group[0]) {
724 GetString(last_name[0], STR_GROUP_NAME,
lastof(last_name[0]));
727 if (b != last_group[1]) {
730 GetString(last_name[1], STR_GROUP_NAME,
lastof(last_name[1]));
733 int r =
strnatcmp(last_name[0], last_name[1]);
741 this->groups.shrink_to_fit();
747 if (this->livery_class < LC_GROUP_RAIL) {
749 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
755 this->rows = (uint)this->groups.size();
758 this->vscroll->
SetCount(this->rows);
768 this->livery_class = LC_OTHER;
771 this->BuildGroupList(company);
774 this->SetSelectedGroup(company, group);
778 this->owner = company;
787 case VEH_TRAIN: this->livery_class = LC_GROUP_RAIL;
break;
788 case VEH_ROAD: this->livery_class = LC_GROUP_ROAD;
break;
789 case VEH_SHIP: this->livery_class = LC_GROUP_SHIP;
break;
790 case VEH_AIRCRAFT: this->livery_class = LC_GROUP_AIRCRAFT;
break;
791 default: NOT_REACHED();
797 this->BuildGroupList(company);
801 for (uint i = 0; i < this->rows; i++) {
802 if (this->groups[i]->index == sel) {
803 this->vscroll->
SetPosition(
Clamp(i - this->vscroll->
GetCapacity() / 2, 0, std::max(this->vscroll->GetCount() - this->vscroll->GetCapacity(), 0)));
815 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
821 if (g->owner == (
CompanyID)this->window_number) {
836 size->height = 11 * this->line_height;
838 resize->height = this->line_height;
851 int string_padding = this->square.width + NWidgetScrollbar::GetVerticalDimension().width + 10;
852 for (
const StringID *
id = _colour_dropdown;
id !=
endof(_colour_dropdown);
id++) {
866 bool disabled = this->livery_class < LC_GROUP_RAIL ? (this->sel == 0) : (this->sel ==
INVALID_GROUP);
886 StringID colour = STR_COLOUR_DEFAULT;
888 if (this->livery_class < LC_GROUP_RAIL) {
889 if (this->sel != 0) {
891 for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
892 if (
HasBit(this->sel, scheme))
break;
894 if (scheme == LS_END) scheme = LS_DEFAULT;
895 const Livery *livery = &c->livery[scheme];
896 if (scheme == LS_DEFAULT ||
HasBit(livery->
in_use, primary ? 0 : 1)) {
897 colour = STR_COLOUR_DARK_BLUE + (primary ? livery->
colour1 : livery->
colour2);
905 colour = STR_COLOUR_DARK_BLUE + (primary ? livery->
colour1 : livery->
colour2);
923 int sch_left = nwi->
pos_x;
924 int sch_right = sch_left + nwi->
current_x - 1;
927 int pri_left = nwi->
pos_x;
928 int pri_right = pri_left + nwi->
current_x - 1;
931 int sec_left = nwi->
pos_x;
932 int sec_right = sec_left + nwi->
current_x - 1;
937 int square_offs = (this->line_height - this->square.height) / 2 + 1;
943 auto draw_livery = [&](
StringID str,
const Livery &liv,
bool sel,
bool def,
int indent) {
949 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);
952 if (sec_right > sec_left) {
954 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);
957 y += this->line_height;
960 if (livery_class < LC_GROUP_RAIL) {
963 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
965 if (pos-- > 0)
continue;
966 draw_livery(STR_LIVERY_DEFAULT + scheme, c->livery[scheme],
HasBit(this->sel, scheme), scheme == LS_DEFAULT, 0);
970 uint max =
static_cast<uint
>(std::min<size_t>(this->vscroll->
GetPosition() + this->vscroll->GetCapacity(), this->groups.size()));
971 for (uint i = this->vscroll->
GetPosition(); i < max; ++i) {
972 const Group *g = this->groups[i];
997 if (this->livery_class < LC_GROUP_RAIL) {
999 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1001 this->sel = 1 << scheme;
1010 if (this->groups.size() > 0) {
1011 this->sel = this->groups[0]->index;
1029 if (row >= this->rows)
return;
1031 if (this->livery_class < LC_GROUP_RAIL) {
1034 for (
LiveryScheme scheme = LS_BEGIN; scheme <= j && scheme < LS_END; scheme++) {
1045 this->sel = this->groups[row]->index;
1063 if (index >= COLOUR_END) index = INVALID_COLOUR;
1065 if (this->livery_class < LC_GROUP_RAIL) {
1067 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1086 if (!gui_scope)
return;
1090 if (this->livery_class == data + LC_GROUP_RAIL) {
1097 if (this->groups.size() > 0) this->sel = this->groups[0]->index;
1107 bool current_class_valid = this->livery_class == LC_OTHER || this->livery_class >= LC_GROUP_RAIL;
1109 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1111 if (_livery_class[scheme] == this->livery_class) current_class_valid =
true;
1113 }
else if (this->livery_class < LC_GROUP_RAIL) {
1114 ClrBit(this->sel, scheme);
1119 if (!current_class_valid) {
1126 static const NWidgetPart _nested_select_company_livery_widgets [] = {
1147 SetDataTip(STR_BLACK_STRING, STR_LIVERY_SECONDARY_TOOLTIP),
1150 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),
1158 static WindowDesc _select_company_livery_desc(
1162 _nested_select_company_livery_widgets,
lengthof(_nested_select_company_livery_widgets)
1171 w->SetSelectedGroup(company, group);
1192 if (
_cmf_info[CMFV_EYE_COLOUR].valid_values[ge] < 2) {
1196 default: NOT_REACHED();
1197 case 0: pal = PALETTE_TO_BROWN;
break;
1198 case 1: pal = PALETTE_TO_BLUE;
break;
1199 case 2: pal = PALETTE_TO_GREEN;
break;
1204 DrawSprite(SPR_GRADIENT, GENERAL_SPRITE_COLOUR(colour), x, y);
1206 for (CompanyManagerFaceVariable cmfv = CMFV_CHEEKS; cmfv < CMFV_END; cmfv++) {
1208 case CMFV_MOUSTACHE:
if (!has_moustache)
continue;
break;
1210 case CMFV_NOSE:
if (has_moustache)
continue;
break;
1211 case CMFV_TIE_EARRING:
if (!has_tie_earring)
continue;
break;
1212 case CMFV_GLASSES:
if (!has_glasses)
continue;
break;
1387 const NWidgetCore *nwi_widget = this->GetWidget<NWidgetCore>(widget_index);
1391 if (is_bool_widget) {
1393 SetDParam(0, (val != 0) ? STR_FACE_YES : STR_FACE_NO);
1409 this->GetWidget<NWidgetCore>(
WID_SCMF_TIE_EARRING_TEXT)->widget_data = this->is_female ? STR_FACE_EARRING : STR_FACE_TIE;
1416 this->advanced =
false;
1440 wi->
SetDataTip(STR_FACE_SIMPLE, STR_FACE_SIMPLE_TOOLTIP);
1442 wi->
SetDataTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP);
1454 for (
int val = 1; val <= 12; val++) {
1489 size->width = std::max(size->width, face_size.width);
1490 size->height = std::max(size->height, face_size.height);
1579 if (this->is_female) {
1591 if (this->is_moust_male) {
1720 CompanyManagerFaceVariable cmfv;
1724 default: NOT_REACHED();
1725 case 0: cmfv = this->is_female ? CMFV_HAS_TIE_EARRING : CMFV_HAS_MOUSTACHE;
break;
1726 case 1: cmfv = CMFV_HAS_GLASSES;
break;
1732 default: NOT_REACHED();
1733 case 0: cmfv = CMFV_EYE_COLOUR;
break;
1734 case 1: cmfv = CMFV_CHIN;
break;
1735 case 2: cmfv = CMFV_EYEBROWS;
break;
1736 case 3: cmfv = this->is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS;
break;
1737 case 4: cmfv = CMFV_NOSE;
break;
1738 case 5: cmfv = CMFV_HAIR;
break;
1739 case 6: cmfv = CMFV_JACKET;
break;
1740 case 7: cmfv = CMFV_COLLAR;
break;
1741 case 8: cmfv = CMFV_TIE_EARRING;
break;
1742 case 9: cmfv = CMFV_GLASSES;
break;
1756 if (str ==
nullptr)
return;
1759 this->face = strtoul(str,
nullptr, 10);
1791 static const NWidgetPart _nested_company_infrastructure_widgets[] = {
1840 this->UpdateRailRoadTypes();
1846 void UpdateRailRoadTypes()
1870 this->roadtypes &= ~_roadtypes_hidden_mask;
1917 for (
const auto &rt : _sorted_railtypes) {
1918 if (
HasBit(this->railtypes, rt)) {
1939 for (
const auto &rt : _sorted_roadtypes) {
1969 uint32 max_val = 1000;
1970 Money max_cost = 10000;
1998 size->width = std::max(size->width, this->total_width);
2004 size->width = std::max(size->width, count_width);
2044 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT);
2048 for (
const auto &rt : _sorted_railtypes) {
2049 if (
HasBit(this->railtypes, rt)) {
2065 for (
const auto &rt : _sorted_railtypes) {
2066 if (
HasBit(this->railtypes, rt)) {
2078 DrawString(r.left, r.right, y, widget ==
WID_CI_ROAD_DESC ? STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT : STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT);
2081 for (
const auto &rt : _sorted_roadtypes) {
2094 for (
const auto &rt : _sorted_roadtypes) {
2103 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT);
2117 DrawString(left,
left + this->total_width, y, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL, TC_FROMSTRING,
SA_RIGHT);
2122 DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT);
2141 if (!gui_scope)
return;
2143 this->UpdateRailRoadTypes();
2148 static WindowDesc _company_infrastructure_desc(
2149 WDP_AUTO,
"company_infrastructure", 0, 0,
2152 _nested_company_infrastructure_widgets,
lengthof(_nested_company_infrastructure_widgets)
2162 AllocateWindowDescFront<CompanyInfrastructureWindow>(&_company_infrastructure_desc, company);
2165 static const NWidgetPart _nested_company_widgets[] = {
2267 auto share_owned_by = [owner](
auto share_owner) {
return share_owner == owner; };
2273 STR_COMPANY_VIEW_TRAINS, STR_COMPANY_VIEW_ROAD_VEHICLES, STR_COMPANY_VIEW_SHIPS, STR_COMPANY_VIEW_AIRCRAFT
2315 bool reinit =
false;
2384 size->width = std::max(size->width, face_size.width);
2385 size->height = std::max(size->height, face_size.height);
2392 d.width -= offset.x;
2393 d.height -= offset.y;
2394 *size =
maxdim(*size, d);
2468 d.height -= offset.y;
2469 DrawSprite(SPR_VEH_BUS_SW_VIEW, COMPANY_SPRITE_COLOUR(c->
index), r.left - offset.x, (r.top + r.bottom - d.height) / 2 - offset.y);
2481 if (amounts[0] + amounts[1] + amounts[2] + amounts[3] == 0) {
2482 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
2486 for (uint i = 0; i <
lengthof(amounts); i++) {
2487 if (amounts[i] != 0) {
2502 uint road_pieces = 0;
2507 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
2509 if (rail_pieces != 0) {
2511 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL);
2514 if (road_pieces != 0) {
2516 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD);
2521 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_WATER);
2526 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_STATION);
2531 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT);
2542 uint amt = GetAmountOwnedBy(c, c2->
index);
2547 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_SHARES_OWNED_BY);
2556 DrawSprite(SPR_LOCK, PAL_NONE, r.left, r.top);
2654 if (this->window_number ==
_local_company) ShowNetworkCompanyPasswordWindow(
this);
2696 if (str ==
nullptr)
return;
2698 switch (this->query_widget) {
2699 default: NOT_REACHED();
2702 Money money = (
Money)(strtoull(str,
nullptr, 10) / _currency->rate);
2758 _nested_company_widgets,
lengthof(_nested_company_widgets)
2769 AllocateWindowDescFront<CompanyWindow>(&_company_desc, company);
2847 static const NWidgetPart _nested_buy_company_widgets[] = {
2870 _nested_buy_company_widgets,
lengthof(_nested_buy_company_widgets)
2879 AllocateWindowDescFront<BuyCompanyWindow>(&_buy_company_desc, company);