diff options
author | rubidium <rubidium@openttd.org> | 2010-09-09 14:40:39 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-09-09 14:40:39 +0000 |
commit | 7f8b490a21b22418e6a1e1450a6e6e635e79086a (patch) | |
tree | be2d798e85fcfd2f84df74fe8de166bc8ba98cfe /src | |
parent | 3ebf8a297e6320d3cdf771fdf7393c1fb1e79fc9 (diff) | |
download | openttd-7f8b490a21b22418e6a1e1450a6e6e635e79086a.tar.xz |
(svn r20777) -Codechange: make VehicleListIdentifier a variable of BaseVehicleList and use that instead of "dereferencing" the window number and storing some information twice
Diffstat (limited to 'src')
-rw-r--r-- | src/group_gui.cpp | 116 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 78 | ||||
-rw-r--r-- | src/vehicle_gui_base.h | 6 |
3 files changed, 88 insertions, 112 deletions
diff --git a/src/group_gui.cpp b/src/group_gui.cpp index eb94488a5..906ca5c4e 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -113,7 +113,6 @@ static const NWidgetPart _nested_group_widgets[] = { class VehicleGroupWindow : public BaseVehicleListWindow { private: - GroupID group_sel; ///< Selected group VehicleID vehicle_sel; ///< Selected vehicle GroupID group_rename; ///< Group being renamed, INVALID_GROUP if none GUIGroupList groups; ///< List of groups @@ -133,7 +132,7 @@ private: const Group *g; FOR_ALL_GROUPS(g) { - if (g->owner == owner && g->vehicle_type == this->vehicle_type) { + if (g->owner == owner && g->vehicle_type == this->vli.vtype) { *this->groups.Append() = g; } } @@ -166,16 +165,14 @@ private: } public: - VehicleGroupWindow(const WindowDesc *desc, WindowNumber window_number) : BaseVehicleListWindow() + VehicleGroupWindow(const WindowDesc *desc, WindowNumber window_number) : BaseVehicleListWindow(window_number) { this->CreateNestedTree(desc); this->vscroll = this->GetScrollbar(GRP_WIDGET_LIST_VEHICLE_SCROLLBAR); this->group_sb = this->GetScrollbar(GRP_WIDGET_LIST_GROUP_SCROLLBAR); - VehicleListIdentifier vli(window_number); - this->vehicle_type = vli.vtype; - switch (this->vehicle_type) { + switch (this->vli.vtype) { default: NOT_REACHED(); case VEH_TRAIN: this->sorting = &_sorting.train; break; case VEH_ROAD: this->sorting = &_sorting.roadveh; break; @@ -183,7 +180,7 @@ public: case VEH_AIRCRAFT: this->sorting = &_sorting.aircraft; break; } - this->group_sel = ALL_GROUP; + this->vli.index = ALL_GROUP; this->vehicle_sel = INVALID_VEHICLE; this->group_rename = INVALID_GROUP; @@ -191,9 +188,7 @@ public: this->vehicles.ForceRebuild(); this->vehicles.NeedResort(); - vli.type = IsAllGroupID(this->group_sel) ? VL_STANDARD : VL_GROUP_LIST; - vli.index = group_sel; - this->BuildVehicleList(vli); + this->BuildVehicleList(); this->SortVehicleList(); this->groups.ForceRebuild(); @@ -201,13 +196,13 @@ public: this->BuildGroupList(owner); this->groups.Sort(&GroupNameSorter); - this->GetWidget<NWidgetCore>(GRP_WIDGET_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vehicle_type; - this->GetWidget<NWidgetCore>(GRP_WIDGET_LIST_VEHICLE)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vehicle_type; + this->GetWidget<NWidgetCore>(GRP_WIDGET_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype; + this->GetWidget<NWidgetCore>(GRP_WIDGET_LIST_VEHICLE)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype; - this->GetWidget<NWidgetCore>(GRP_WIDGET_CREATE_GROUP)->widget_data += this->vehicle_type; - this->GetWidget<NWidgetCore>(GRP_WIDGET_RENAME_GROUP)->widget_data += this->vehicle_type; - this->GetWidget<NWidgetCore>(GRP_WIDGET_DELETE_GROUP)->widget_data += this->vehicle_type; - this->GetWidget<NWidgetCore>(GRP_WIDGET_REPLACE_PROTECTION)->widget_data += this->vehicle_type; + this->GetWidget<NWidgetCore>(GRP_WIDGET_CREATE_GROUP)->widget_data += this->vli.vtype; + this->GetWidget<NWidgetCore>(GRP_WIDGET_RENAME_GROUP)->widget_data += this->vli.vtype; + this->GetWidget<NWidgetCore>(GRP_WIDGET_DELETE_GROUP)->widget_data += this->vli.vtype; + this->GetWidget<NWidgetCore>(GRP_WIDGET_REPLACE_PROTECTION)->widget_data += this->vli.vtype; this->FinishInitNested(desc, window_number); this->owner = vli.company; @@ -225,18 +220,18 @@ public: this->tiny_step_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP; resize->height = this->tiny_step_height; /* Minimum height is the height of the list widget minus all and default vehicles and a bit for the bottom bar */ - size->height = 4 * GetVehicleListHeight(this->vehicle_type, this->tiny_step_height) - (this->tiny_step_height > 25 ? 2 : 3) * this->tiny_step_height; + size->height = 4 * GetVehicleListHeight(this->vli.vtype, this->tiny_step_height) - (this->tiny_step_height > 25 ? 2 : 3) * this->tiny_step_height; break; case GRP_WIDGET_ALL_VEHICLES: case GRP_WIDGET_DEFAULT_VEHICLES: size->height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP; - size->width = max(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + this->vehicle_type).width, GetStringBoundingBox(STR_GROUP_ALL_TRAINS + this->vehicle_type).width); + size->width = max(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + this->vli.vtype).width, GetStringBoundingBox(STR_GROUP_ALL_TRAINS + this->vli.vtype).width); size->width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + 8 + 8; break; case GRP_WIDGET_LIST_VEHICLE: - resize->height = GetVehicleListHeight(this->vehicle_type, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP); + resize->height = GetVehicleListHeight(this->vli.vtype, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP); size->height = 4 * resize->height; break; @@ -265,8 +260,8 @@ public: this->group_rename = INVALID_GROUP; } - if (!(IsAllGroupID(this->group_sel) || IsDefaultGroupID(this->group_sel) || Group::IsValidID(this->group_sel))) { - this->group_sel = ALL_GROUP; + if (!(IsAllGroupID(this->vli.index) || IsDefaultGroupID(this->vli.index) || Group::IsValidID(this->vli.index))) { + this->vli.index = ALL_GROUP; HideDropDownMenu(this); } this->SetDirty(); @@ -276,19 +271,19 @@ public: { switch (widget) { case GRP_WIDGET_AVAILABLE_VEHICLES: - SetDParam(0, STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vehicle_type); + SetDParam(0, STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vli.vtype); break; case GRP_WIDGET_CAPTION: /* If selected_group == DEFAULT_GROUP || ALL_GROUP, draw the standard caption * We list all vehicles or ungrouped vehicles */ - if (IsDefaultGroupID(this->group_sel) || IsAllGroupID(this->group_sel)) { + if (IsDefaultGroupID(this->vli.index) || IsAllGroupID(this->vli.index)) { SetDParam(0, STR_COMPANY_NAME); SetDParam(1, GB(this->window_number, 0, 8)); SetDParam(2, this->vehicles.Length()); SetDParam(3, this->vehicles.Length()); } else { - const Group *g = Group::Get(this->group_sel); + const Group *g = Group::Get(this->vli.index); SetDParam(0, STR_GROUP_NAME); SetDParam(1, g->index); @@ -301,14 +296,9 @@ public: virtual void OnPaint() { - VehicleListIdentifier vli(this->window_number); - const Owner owner = vli.company; - /* If we select the all vehicles, this->list will contain all vehicles of the owner * else this->list will contain all vehicles which belong to the selected group */ - vli.type = IsAllGroupID(this->group_sel) ? VL_STANDARD : VL_GROUP_LIST; - vli.index = group_sel; - this->BuildVehicleList(vli); + this->BuildVehicleList(); this->SortVehicleList(); this->BuildGroupList(owner); @@ -324,14 +314,14 @@ public: } /* Disable all lists management button when the list is empty */ - this->SetWidgetsDisabledState(this->vehicles.Length() == 0 || _local_company != owner, + this->SetWidgetsDisabledState(this->vehicles.Length() == 0 || _local_company != this->vli.company, GRP_WIDGET_STOP_ALL, GRP_WIDGET_START_ALL, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN, WIDGET_LIST_END); /* Disable the group specific function when we select the default group or all vehicles */ - this->SetWidgetsDisabledState(IsDefaultGroupID(this->group_sel) || IsAllGroupID(this->group_sel) || _local_company != owner, + this->SetWidgetsDisabledState(IsDefaultGroupID(this->vli.index) || IsAllGroupID(this->vli.index) || _local_company != this->vli.company, GRP_WIDGET_DELETE_GROUP, GRP_WIDGET_RENAME_GROUP, GRP_WIDGET_REPLACE_PROTECTION, @@ -343,15 +333,15 @@ public: * verify, whether you are the owner of the vehicle, * so it doesn't have to be disabled */ - this->SetWidgetsDisabledState(_local_company != owner, + this->SetWidgetsDisabledState(_local_company != this->vli.company, GRP_WIDGET_CREATE_GROUP, GRP_WIDGET_AVAILABLE_VEHICLES, WIDGET_LIST_END); /* If not a default group and the group has replace protection, show an enabled replace sprite. */ uint16 protect_sprite = SPR_GROUP_REPLACE_OFF_TRAIN; - if (!IsDefaultGroupID(this->group_sel) && !IsAllGroupID(this->group_sel) && Group::Get(this->group_sel)->replace_protection) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN; - this->GetWidget<NWidgetCore>(GRP_WIDGET_REPLACE_PROTECTION)->widget_data = protect_sprite + this->vehicle_type; + if (!IsDefaultGroupID(this->vli.index) && !IsAllGroupID(this->vli.index) && Group::Get(this->vli.index)->replace_protection) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN; + this->GetWidget<NWidgetCore>(GRP_WIDGET_REPLACE_PROTECTION)->widget_data = protect_sprite + this->vli.vtype; /* Set text of sort by dropdown */ this->GetWidget<NWidgetCore>(GRP_WIDGET_SORT_BY_DROPDOWN)->widget_data = this->vehicle_sorter_names[this->vehicles.SortType()]; @@ -364,12 +354,12 @@ public: switch (widget) { case GRP_WIDGET_ALL_VEHICLES: DrawString(r.left + WD_FRAMERECT_LEFT + 8, r.right - WD_FRAMERECT_RIGHT - 8, r.top + WD_FRAMERECT_TOP + 1, - STR_GROUP_ALL_TRAINS + this->vehicle_type, IsAllGroupID(this->group_sel) ? TC_WHITE : TC_BLACK); + STR_GROUP_ALL_TRAINS + this->vli.vtype, IsAllGroupID(this->vli.index) ? TC_WHITE : TC_BLACK); break; case GRP_WIDGET_DEFAULT_VEHICLES: DrawString(r.left + WD_FRAMERECT_LEFT + 8, r.right - WD_FRAMERECT_RIGHT - 8, r.top + WD_FRAMERECT_TOP + 1, - STR_GROUP_DEFAULT_TRAINS + this->vehicle_type, IsDefaultGroupID(this->group_sel) ? TC_WHITE : TC_BLACK); + STR_GROUP_DEFAULT_TRAINS + this->vli.vtype, IsDefaultGroupID(this->vli.index) ? TC_WHITE : TC_BLACK); break; case GRP_WIDGET_LIST_GROUP: { @@ -382,11 +372,11 @@ public: /* draw the selected group in white, else we draw it in black */ SetDParam(0, g->index); - DrawString(r.left + WD_FRAMERECT_LEFT + 8, r.right - WD_FRAMERECT_RIGHT - 8, y1, STR_GROUP_NAME, (this->group_sel == g->index) ? TC_WHITE : TC_BLACK); + DrawString(r.left + WD_FRAMERECT_LEFT + 8, r.right - WD_FRAMERECT_RIGHT - 8, y1, STR_GROUP_NAME, (this->vli.index == g->index) ? TC_WHITE : TC_BLACK); /* draw the number of vehicles of the group */ SetDParam(0, g->num_vehicle); - DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y1 + 1, STR_TINY_COMMA, (this->group_sel == g->index) ? TC_WHITE : TC_BLACK, SA_RIGHT); + DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y1 + 1, STR_TINY_COMMA, (this->vli.index == g->index) ? TC_WHITE : TC_BLACK, SA_RIGHT); y1 += this->tiny_step_height; } @@ -412,20 +402,20 @@ public: break; case GRP_WIDGET_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu - ShowDropDownMenu(this, this->vehicle_sorter_names, this->vehicles.SortType(), GRP_WIDGET_SORT_BY_DROPDOWN, 0, (this->vehicle_type == VEH_TRAIN || this->vehicle_type == VEH_ROAD) ? 0 : (1 << 10)); + ShowDropDownMenu(this, this->vehicle_sorter_names, this->vehicles.SortType(), GRP_WIDGET_SORT_BY_DROPDOWN, 0, (this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10)); return; case GRP_WIDGET_ALL_VEHICLES: // All vehicles button - if (!IsAllGroupID(this->group_sel)) { - this->group_sel = ALL_GROUP; + if (!IsAllGroupID(this->vli.index)) { + this->vli.index = ALL_GROUP; this->vehicles.ForceRebuild(); this->SetDirty(); } break; case GRP_WIDGET_DEFAULT_VEHICLES: // Ungrouped vehicles button - if (!IsDefaultGroupID(this->group_sel)) { - this->group_sel = DEFAULT_GROUP; + if (!IsDefaultGroupID(this->vli.index)) { + this->vli.index = DEFAULT_GROUP; this->vehicles.ForceRebuild(); this->SetDirty(); } @@ -435,7 +425,7 @@ public: uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_GROUP, 0, this->tiny_step_height); if (id_g >= this->groups.Length()) return; - this->group_sel = this->groups[id_g]->index; + this->vli.index = this->groups[id_g]->index; this->vehicles.ForceRebuild(); this->SetDirty(); @@ -459,45 +449,42 @@ public: } case GRP_WIDGET_CREATE_GROUP: { // Create a new group - DoCommandP(0, this->vehicle_type, 0, CMD_CREATE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE), CcCreateGroup); + DoCommandP(0, this->vli.vtype, 0, CMD_CREATE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE), CcCreateGroup); break; } case GRP_WIDGET_DELETE_GROUP: { // Delete the selected group - GroupID group = this->group_sel; - this->group_sel = ALL_GROUP; + GroupID group = this->vli.index; + this->vli.index = ALL_GROUP; DoCommandP(0, group, 0, CMD_DELETE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_DELETE)); break; } case GRP_WIDGET_RENAME_GROUP: // Rename the selected roup - this->ShowRenameGroupWindow(this->group_sel, false); + this->ShowRenameGroupWindow(this->vli.index, false); break; case GRP_WIDGET_AVAILABLE_VEHICLES: - ShowBuildVehicleWindow(INVALID_TILE, this->vehicle_type); + ShowBuildVehicleWindow(INVALID_TILE, this->vli.vtype); break; case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN: { - DropDownList *list = this->BuildActionDropdownList(true, Group::IsValidID(this->group_sel)); + DropDownList *list = this->BuildActionDropdownList(true, Group::IsValidID(this->vli.index)); ShowDropDownList(this, list, 0, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN); break; } case GRP_WIDGET_START_ALL: case GRP_WIDGET_STOP_ALL: { // Start/stop all vehicles of the list - VehicleListIdentifier vli(this->window_number); - vli.type = IsAllGroupID(this->group_sel) ? VL_STANDARD : VL_GROUP_LIST; - vli.index = this->group_sel; - DoCommandP(0, (1 << 1) | (widget == GRP_WIDGET_START_ALL ? (1 << 0) : 0), vli.Pack(), CMD_MASS_START_STOP); + DoCommandP(0, (1 << 1) | (widget == GRP_WIDGET_START_ALL ? (1 << 0) : 0), this->vli.Pack(), CMD_MASS_START_STOP); break; } case GRP_WIDGET_REPLACE_PROTECTION: { - const Group *g = Group::GetIfValid(this->group_sel); + const Group *g = Group::GetIfValid(this->vli.index); if (g != NULL) { - DoCommandP(0, this->group_sel, !g->replace_protection, CMD_SET_GROUP_REPLACE_PROTECTION); + DoCommandP(0, this->vli.index, !g->replace_protection, CMD_SET_GROUP_REPLACE_PROTECTION); } break; } @@ -575,26 +562,23 @@ public: switch (index) { case ADI_REPLACE: // Replace window - ShowReplaceGroupVehicleWindow(this->group_sel, this->vehicle_type); + ShowReplaceGroupVehicleWindow(this->vli.index, this->vli.vtype); break; case ADI_SERVICE: // Send for servicing case ADI_DEPOT: { // Send to Depots - VehicleListIdentifier vli(this->window_number); - vli.type = IsAllGroupID(this->group_sel) ? VL_STANDARD : VL_GROUP_LIST; - vli.index = this->group_sel; - DoCommandP(0, DEPOT_MASS_SEND | (index == ADI_SERVICE ? DEPOT_SERVICE : 0U), vli.Pack(), GetCmdSendToDepot(this->vehicle_type)); + DoCommandP(0, DEPOT_MASS_SEND | (index == ADI_SERVICE ? DEPOT_SERVICE : 0U), this->vli.Pack(), GetCmdSendToDepot(this->vli.vtype)); break; } case ADI_ADD_SHARED: // Add shared Vehicles - assert(Group::IsValidID(this->group_sel)); + assert(Group::IsValidID(this->vli.index)); - DoCommandP(0, this->group_sel, this->vehicle_type, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_SHARED_VEHICLE)); + DoCommandP(0, this->vli.index, this->vli.vtype, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_SHARED_VEHICLE)); break; case ADI_REMOVE_ALL: // Remove all Vehicles from the selected group - assert(Group::IsValidID(this->group_sel)); + assert(Group::IsValidID(this->vli.index)); - DoCommandP(0, this->group_sel, this->vehicle_type, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_REMOVE_ALL_VEHICLES)); + DoCommandP(0, this->vli.index, this->vli.vtype, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_REMOVE_ALL_VEHICLES)); break; default: NOT_REACHED(); } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index eaed32c24..3361f8797 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -99,13 +99,13 @@ const StringID BaseVehicleListWindow::vehicle_depot_name[] = { STR_VEHICLE_LIST_SEND_AIRCRAFT_TO_HANGAR }; -void BaseVehicleListWindow::BuildVehicleList(const VehicleListIdentifier &vli) +void BaseVehicleListWindow::BuildVehicleList() { if (!this->vehicles.NeedRebuild()) return; - DEBUG(misc, 3, "Building vehicle list for company %d at station %d", vli.company, vli.index); + DEBUG(misc, 3, "Building vehicle list type %d for company %d given index %d", this->vli.type, this->vli.company, this->vli.index); - GenerateVehicleSortList(&this->vehicles, vli); + GenerateVehicleSortList(&this->vehicles, this->vli); uint unitnumber = 0; for (const Vehicle **v = this->vehicles.Begin(); v != this->vehicles.End(); v++) { @@ -139,7 +139,7 @@ Dimension BaseVehicleListWindow::GetActionDropdownSize(bool show_autoreplace, bo if (show_autoreplace) d = maxdim(d, GetStringBoundingBox(STR_VEHICLE_LIST_REPLACE_VEHICLES)); d = maxdim(d, GetStringBoundingBox(STR_VEHICLE_LIST_SEND_FOR_SERVICING)); - d = maxdim(d, GetStringBoundingBox(this->vehicle_depot_name[this->vehicle_type])); + d = maxdim(d, GetStringBoundingBox(this->vehicle_depot_name[this->vli.vtype])); if (show_group) { d = maxdim(d, GetStringBoundingBox(STR_GROUP_ADD_SHARED_VEHICLE)); @@ -161,7 +161,7 @@ DropDownList *BaseVehicleListWindow::BuildActionDropdownList(bool show_autorepla if (show_autoreplace) list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_REPLACE_VEHICLES, ADI_REPLACE, false)); list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, ADI_SERVICE, false)); - list->push_back(new DropDownListStringItem(this->vehicle_depot_name[this->vehicle_type], ADI_DEPOT, false)); + list->push_back(new DropDownListStringItem(this->vehicle_depot_name[this->vli.vtype], ADI_DEPOT, false)); if (show_group) { list->push_back(new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED, false)); @@ -1017,7 +1017,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int int text_left = left + (rtl ? 0 : text_offset); int text_right = right - (rtl ? text_offset : 0); - bool show_orderlist = vehicle_type >= VEH_SHIP; + bool show_orderlist = this->vli.vtype >= VEH_SHIP; int orderlist_left = left + (rtl ? 0 : max(100 + text_offset, width / 2)); int orderlist_right = right - (rtl ? max(100 + text_offset, width / 2) : 0); @@ -1083,15 +1083,12 @@ private: }; public: - VehicleListWindow(const WindowDesc *desc, WindowNumber window_number) : BaseVehicleListWindow() + VehicleListWindow(const WindowDesc *desc, WindowNumber window_number) : BaseVehicleListWindow(window_number) { - VehicleListIdentifier vli(window_number); - this->vehicle_type = vli.vtype; - /* Set up sorting. Make the window-specific _sorting variable * point to the correct global _sorting struct so we are freed * from having conditionals during window operation */ - switch (this->vehicle_type) { + switch (this->vli.vtype) { case VEH_TRAIN: this->sorting = &_sorting.train; break; case VEH_ROAD: this->sorting = &_sorting.roadveh; break; case VEH_SHIP: this->sorting = &_sorting.ship; break; @@ -1106,22 +1103,22 @@ public: this->vehicles.SetListing(*this->sorting); this->vehicles.ForceRebuild(); this->vehicles.NeedResort(); - this->BuildVehicleList(vli); + this->BuildVehicleList(); this->SortVehicleList(); /* Set up the window widgets */ - this->GetWidget<NWidgetCore>(VLW_WIDGET_LIST)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vehicle_type; + this->GetWidget<NWidgetCore>(VLW_WIDGET_LIST)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype; - if (vli.type == VL_SHARED_ORDERS) { + if (this->vli.type == VL_SHARED_ORDERS) { this->GetWidget<NWidgetCore>(VLW_WIDGET_CAPTION)->widget_data = STR_VEHICLE_LIST_SHARED_ORDERS_LIST_CAPTION; } else { - this->GetWidget<NWidgetCore>(VLW_WIDGET_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vehicle_type; + this->GetWidget<NWidgetCore>(VLW_WIDGET_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype; } this->FinishInitNested(desc, window_number); - this->owner = vli.company; + this->owner = this->vli.company; - if (this->vehicle_type == VEH_TRAIN) ResizeWindow(this, 65, 0); + if (this->vli.vtype == VEH_TRAIN) ResizeWindow(this, 65, 0); } ~VehicleListWindow() @@ -1133,9 +1130,9 @@ public: { switch (widget) { case VLW_WIDGET_LIST: - resize->height = GetVehicleListHeight(this->vehicle_type, 1); + resize->height = GetVehicleListHeight(this->vli.vtype, 1); - switch (this->vehicle_type) { + switch (this->vli.vtype) { case VEH_TRAIN: case VEH_ROAD: size->height = 6 * resize->height; @@ -1149,7 +1146,7 @@ public: break; case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN: { - Dimension d = this->GetActionDropdownSize(VehicleListIdentifier(this->window_number).type == VL_STANDARD, false); + Dimension d = this->GetActionDropdownSize(this->vli.type == VL_STANDARD, false); d.height += padding.height; d.width += padding.width; *size = maxdim(*size, d); @@ -1162,12 +1159,11 @@ public: { switch (widget) { case VLW_WIDGET_AVAILABLE_VEHICLES: - SetDParam(0, STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vehicle_type); + SetDParam(0, STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vli.vtype); break; case VLW_WIDGET_CAPTION: { - VehicleListIdentifier vli(this->window_number); - switch (vli.type) { + switch (this->vli.type) { case VL_SHARED_ORDERS: // Shared Orders if (this->vehicles.Length() == 0) { /* We can't open this window without vehicles using this order @@ -1179,20 +1175,20 @@ public: case VL_STANDARD: // Company Name SetDParam(0, STR_COMPANY_NAME); - SetDParam(1, vli.index); + SetDParam(1, this->vli.index); SetDParam(3, this->vscroll->GetCount()); break; case VL_STATION_LIST: // Station/Waypoint Name - SetDParam(0, Station::IsExpected(BaseStation::Get(vli.index)) ? STR_STATION_NAME : STR_WAYPOINT_NAME); - SetDParam(1, vli.index); + SetDParam(0, Station::IsExpected(BaseStation::Get(this->vli.index)) ? STR_STATION_NAME : STR_WAYPOINT_NAME); + SetDParam(1, this->vli.index); SetDParam(3, this->vscroll->GetCount()); break; case VL_DEPOT_LIST: SetDParam(0, STR_DEPOT_CAPTION); - SetDParam(1, this->vehicle_type); - SetDParam(2, vli.index); + SetDParam(1, this->vli.vtype); + SetDParam(2, this->vli.index); SetDParam(3, this->vscroll->GetCount()); break; default: NOT_REACHED(); @@ -1218,9 +1214,7 @@ public: virtual void OnPaint() { - VehicleListIdentifier vli(this->window_number); - - this->BuildVehicleList(vli); + this->BuildVehicleList(); this->SortVehicleList(); if (this->vehicles.Length() == 0 && this->IsWidgetLowered(VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN)) { @@ -1236,7 +1230,7 @@ public: nwi->SetDirty(this); } if (this->owner == _local_company) { - this->SetWidgetDisabledState(VLW_WIDGET_AVAILABLE_VEHICLES, vli.type != VL_STANDARD); + this->SetWidgetDisabledState(VLW_WIDGET_AVAILABLE_VEHICLES, this->vli.type != VL_STANDARD); this->SetWidgetsDisabledState(this->vehicles.Length() == 0, VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN, VLW_WIDGET_STOP_ALL, @@ -1260,7 +1254,7 @@ public: case VLW_WIDGET_SORT_BY_PULLDOWN:// Select sorting criteria dropdown menu ShowDropDownMenu(this, this->vehicle_sorter_names, this->vehicles.SortType(), VLW_WIDGET_SORT_BY_PULLDOWN, 0, - (this->vehicle_type == VEH_TRAIN || this->vehicle_type == VEH_ROAD) ? 0 : (1 << 10)); + (this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10)); return; case VLW_WIDGET_LIST: { // Matrix to show vehicles @@ -1273,7 +1267,7 @@ public: } case VLW_WIDGET_AVAILABLE_VEHICLES: - ShowBuildVehicleWindow(INVALID_TILE, this->vehicle_type); + ShowBuildVehicleWindow(INVALID_TILE, this->vli.vtype); break; case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN: { @@ -1300,11 +1294,11 @@ public: switch (index) { case ADI_REPLACE: // Replace window - ShowReplaceGroupVehicleWindow(DEFAULT_GROUP, this->vehicle_type); + ShowReplaceGroupVehicleWindow(DEFAULT_GROUP, this->vli.vtype); break; case ADI_SERVICE: // Send for servicing case ADI_DEPOT: // Send to Depots - DoCommandP(0, DEPOT_MASS_SEND | (index == ADI_SERVICE ? DEPOT_SERVICE : (DepotCommand)0), this->window_number, GetCmdSendToDepot(this->vehicle_type)); + DoCommandP(0, DEPOT_MASS_SEND | (index == ADI_SERVICE ? DEPOT_SERVICE : (DepotCommand)0), this->window_number, GetCmdSendToDepot(this->vli.vtype)); break; default: NOT_REACHED(); @@ -1319,10 +1313,9 @@ public: { if (_pause_mode != PM_UNPAUSED) return; if (this->vehicles.NeedResort()) { - VehicleListIdentifier vli(this->window_number); - StationID station = (vli.type == VL_STATION_LIST) ? vli.index : INVALID_STATION; + StationID station = (this->vli.type == VL_STATION_LIST) ? this->vli.index : INVALID_STATION; - DEBUG(misc, 3, "Periodic resort %d list company %d at station %d", this->vehicle_type, this->owner, station); + DEBUG(misc, 3, "Periodic resort %d list company %d at station %d", this->vli.vtype, this->owner, station); this->SetDirty(); } } @@ -1335,10 +1328,9 @@ public: virtual void OnInvalidateData(int data) { - VehicleListIdentifier vli(this->window_number); - if (HasBit(data, 31) && vli.type == VL_SHARED_ORDERS) { - vli.index = GB(data, 0, 20); - this->window_number = vli.Pack(); + if (HasBit(data, 31) && this->vli.type == VL_SHARED_ORDERS) { + this->vli.index = GB(data, 0, 20); + this->window_number = this->vli.Pack(); this->vehicles.ForceRebuild(); return; } diff --git a/src/vehicle_gui_base.h b/src/vehicle_gui_base.h index 6f7e4004f..e4f6ccc76 100644 --- a/src/vehicle_gui_base.h +++ b/src/vehicle_gui_base.h @@ -22,9 +22,9 @@ typedef GUIList<const Vehicle*> GUIVehicleList; struct BaseVehicleListWindow : public Window { GUIVehicleList vehicles; ///< The list of vehicles Listing *sorting; ///< Pointer to the vehicle type related sorting. - VehicleType vehicle_type; ///< The vehicle type that is sorted byte unitnumber_digits; ///< The number of digits of the highest unit number Scrollbar *vscroll; + VehicleListIdentifier vli; ///< Identifier of the vehicle list we want to currently show. enum ActionDropdownItem { ADI_REPLACE, @@ -38,14 +38,14 @@ struct BaseVehicleListWindow : public Window { static const StringID vehicle_sorter_names[]; static GUIVehicleList::SortFunction * const vehicle_sorter_funcs[]; - BaseVehicleListWindow() : Window() + BaseVehicleListWindow(WindowNumber wno) : Window(), vli(wno) { this->vehicles.SetSortFuncs(this->vehicle_sorter_funcs); } void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const; void SortVehicleList(); - void BuildVehicleList(const VehicleListIdentifier &identifier); + void BuildVehicleList(); Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group); DropDownList *BuildActionDropdownList(bool show_autoreplace, bool show_group); }; |