mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-24 03:56:43 +00:00
Codechange: make VehicleType a scoped enum
This commit is contained in:
committed by
Peter Nelson
parent
b90aefbf49
commit
77403627a8
+21
-21
@@ -244,7 +244,7 @@ private:
|
||||
this->column_size[VGC_FOLD] = maxdim(GetScaledSpriteSize(SPR_CIRCLE_FOLDED), GetScaledSpriteSize(SPR_CIRCLE_UNFOLDED));
|
||||
this->tiny_step_height = this->column_size[VGC_FOLD].height;
|
||||
|
||||
this->column_size[VGC_NAME] = maxdim(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + this->vli.vtype), GetStringBoundingBox(STR_GROUP_ALL_TRAINS + this->vli.vtype));
|
||||
this->column_size[VGC_NAME] = maxdim(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + to_underlying(this->vli.vtype)), GetStringBoundingBox(STR_GROUP_ALL_TRAINS + to_underlying(this->vli.vtype)));
|
||||
this->column_size[VGC_NAME].width = std::max(170u, this->column_size[VGC_NAME].width) + WidgetDimensions::scaled.hsep_indent;
|
||||
this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_NAME].height);
|
||||
|
||||
@@ -309,8 +309,8 @@ private:
|
||||
*/
|
||||
std::string GetGroupNameString(GroupID g_id) const
|
||||
{
|
||||
if (IsAllGroupID(g_id)) return GetString(STR_GROUP_ALL_TRAINS + this->vli.vtype);
|
||||
if (IsDefaultGroupID(g_id)) return GetString(STR_GROUP_DEFAULT_TRAINS + this->vli.vtype);
|
||||
if (IsAllGroupID(g_id)) return GetString(STR_GROUP_ALL_TRAINS + to_underlying(this->vli.vtype));
|
||||
if (IsDefaultGroupID(g_id)) return GetString(STR_GROUP_DEFAULT_TRAINS + to_underlying(this->vli.vtype));
|
||||
return GetString(STR_GROUP_NAME, g_id);
|
||||
}
|
||||
|
||||
@@ -433,14 +433,14 @@ public:
|
||||
this->BuildGroupList(vli.company);
|
||||
this->group_sb->SetCount(this->groups.size());
|
||||
|
||||
this->GetWidget<NWidgetCore>(WID_GL_CAPTION)->SetString(STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype);
|
||||
this->GetWidget<NWidgetCore>(WID_GL_LIST_VEHICLE)->SetToolTip(STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype);
|
||||
this->GetWidget<NWidgetCore>(WID_GL_CAPTION)->SetString(STR_VEHICLE_LIST_TRAIN_CAPTION + to_underlying(this->vli.vtype));
|
||||
this->GetWidget<NWidgetCore>(WID_GL_LIST_VEHICLE)->SetToolTip(STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + to_underlying(this->vli.vtype));
|
||||
|
||||
this->GetWidget<NWidgetCore>(WID_GL_CREATE_GROUP)->SetSprite(SPR_GROUP_CREATE_TRAIN + this->vli.vtype);
|
||||
this->GetWidget<NWidgetCore>(WID_GL_RENAME_GROUP)->SetSprite(SPR_GROUP_RENAME_TRAIN + this->vli.vtype);
|
||||
this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->SetSprite(SPR_GROUP_DELETE_TRAIN + this->vli.vtype);
|
||||
this->GetWidget<NWidgetCore>(WID_GL_LIVERY_GROUP)->SetSprite(SPR_GROUP_LIVERY_TRAIN + this->vli.vtype);
|
||||
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->SetSprite(SPR_GROUP_REPLACE_OFF_TRAIN + this->vli.vtype);
|
||||
this->GetWidget<NWidgetCore>(WID_GL_CREATE_GROUP)->SetSprite(SPR_GROUP_CREATE_TRAIN + to_underlying(this->vli.vtype));
|
||||
this->GetWidget<NWidgetCore>(WID_GL_RENAME_GROUP)->SetSprite(SPR_GROUP_RENAME_TRAIN + to_underlying(this->vli.vtype));
|
||||
this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->SetSprite(SPR_GROUP_DELETE_TRAIN + to_underlying(this->vli.vtype));
|
||||
this->GetWidget<NWidgetCore>(WID_GL_LIVERY_GROUP)->SetSprite(SPR_GROUP_LIVERY_TRAIN + to_underlying(this->vli.vtype));
|
||||
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->SetSprite(SPR_GROUP_REPLACE_OFF_TRAIN + to_underlying(this->vli.vtype));
|
||||
|
||||
this->FinishInitNested(window_number);
|
||||
this->owner = vli.company;
|
||||
@@ -562,7 +562,7 @@ public:
|
||||
return GetString(this->GetCargoFilterLabel(this->cargo_filter_criteria));
|
||||
|
||||
case WID_GL_AVAILABLE_VEHICLES:
|
||||
return GetString(STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vli.vtype);
|
||||
return GetString(STR_VEHICLE_LIST_AVAILABLE_TRAINS + to_underlying(this->vli.vtype));
|
||||
|
||||
case WID_GL_CAPTION:
|
||||
/* If selected_group == DEFAULT_GROUP || ALL_GROUP, draw the standard caption
|
||||
@@ -625,7 +625,7 @@ public:
|
||||
/* If not a default group and the group has replace protection, show an enabled replace sprite. */
|
||||
uint16_t protect_sprite = SPR_GROUP_REPLACE_OFF_TRAIN;
|
||||
if (!IsDefaultGroupID(group) && !IsAllGroupID(group) && Group::Get(group)->flags.Test(GroupFlag::ReplaceProtection)) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN;
|
||||
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->SetSprite(protect_sprite + this->vli.vtype);
|
||||
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->SetSprite(protect_sprite + to_underlying(this->vli.vtype));
|
||||
|
||||
/* Set text of "group by" dropdown widget. */
|
||||
this->GetWidget<NWidgetCore>(WID_GL_GROUP_BY_DROPDOWN)->SetString(std::data(this->vehicle_group_by_names)[this->grouping]);
|
||||
@@ -749,7 +749,7 @@ public:
|
||||
return;
|
||||
|
||||
case WID_GL_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
|
||||
ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_GL_SORT_BY_DROPDOWN, 0, (this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10));
|
||||
ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_GL_SORT_BY_DROPDOWN, 0, (this->vli.vtype == VehicleType::Train || this->vli.vtype == VehicleType::Road) ? 0 : (1 << 10));
|
||||
return;
|
||||
|
||||
case WID_GL_FILTER_BY_CARGO: { // Select filtering criteria dropdown menu
|
||||
@@ -1191,32 +1191,32 @@ public:
|
||||
};
|
||||
|
||||
/** Window definitions for the vehicle group windows. */
|
||||
static WindowDesc _vehicle_group_desc[] = {
|
||||
{
|
||||
static VehicleTypeIndexArray<WindowDesc> _vehicle_group_desc = {{
|
||||
WindowDesc{
|
||||
WindowPosition::Automatic, "list_groups_train", 525, 246,
|
||||
WC_TRAINS_LIST, WC_NONE,
|
||||
{},
|
||||
_nested_group_widgets
|
||||
},
|
||||
{
|
||||
WindowDesc{
|
||||
WindowPosition::Automatic, "list_groups_roadveh", 460, 246,
|
||||
WC_ROADVEH_LIST, WC_NONE,
|
||||
{},
|
||||
_nested_group_widgets
|
||||
},
|
||||
{
|
||||
WindowDesc{
|
||||
WindowPosition::Automatic, "list_groups_ship", 460, 246,
|
||||
WC_SHIPS_LIST, WC_NONE,
|
||||
{},
|
||||
_nested_group_widgets
|
||||
},
|
||||
{
|
||||
WindowDesc{
|
||||
WindowPosition::Automatic, "list_groups_aircraft", 460, 246,
|
||||
WC_AIRCRAFT_LIST, WC_NONE,
|
||||
{},
|
||||
_nested_group_widgets
|
||||
},
|
||||
};
|
||||
}};
|
||||
|
||||
/**
|
||||
* Show the group window for the given company and vehicle type.
|
||||
@@ -1230,7 +1230,7 @@ static void ShowCompanyGroupInternal(CompanyID company, VehicleType vehicle_type
|
||||
{
|
||||
if (!Company::IsValidID(company)) return;
|
||||
|
||||
assert(vehicle_type < std::size(_vehicle_group_desc));
|
||||
assert(to_underlying(vehicle_type) < std::size(_vehicle_group_desc));
|
||||
VehicleListIdentifier vli(VL_GROUP_LIST, vehicle_type, company);
|
||||
VehicleGroupWindow *w = AllocateWindowDescFront<VehicleGroupWindow, Tneed_existing_window>(_vehicle_group_desc[vehicle_type], vli.ToWindowNumber(), vli);
|
||||
if (w != nullptr) w->SelectGroup(group);
|
||||
@@ -1289,7 +1289,7 @@ void CcCreateGroup(Commands, const CommandCost &result, GroupID new_group, Vehic
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
assert(vt <= VEH_AIRCRAFT);
|
||||
assert(IsCompanyBuildableVehicleType(vt));
|
||||
CcCreateGroup(new_group, vt);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user