1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 09:22:42 +01:00

Codechange: read VLI.index through wrapper to get the right type

This commit is contained in:
Rubidium
2025-02-02 08:49:38 +01:00
committed by rubidium42
parent d61b376998
commit 4e84d032b8
4 changed files with 53 additions and 42 deletions

View File

@@ -293,7 +293,7 @@ private:
if (g_id == NEW_GROUP) return;
/* draw the selected group in white, else we draw it in black */
TextColour colour = g_id == this->vli.index ? TC_WHITE : TC_BLACK;
TextColour colour = g_id == this->vli.ToGroupID() ? TC_WHITE : TC_BLACK;
const GroupStatistics &stats = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype);
bool rtl = _current_text_dir == TD_RTL;
@@ -503,7 +503,8 @@ public:
this->group_rename = INVALID_GROUP;
}
if (!(IsAllGroupID(this->vli.index) || IsDefaultGroupID(this->vli.index) || Group::IsValidID(this->vli.index))) {
GroupID group = this->vli.ToGroupID();
if (!(IsAllGroupID(group) || IsDefaultGroupID(group) || Group::IsValidID(group))) {
this->vli.index = ALL_GROUP;
this->CloseChildWindows(WC_DROPDOWN_MENU);
}
@@ -524,16 +525,16 @@ public:
case WID_GL_CAPTION:
/* If selected_group == DEFAULT_GROUP || ALL_GROUP, draw the standard caption
* We list all vehicles or ungrouped vehicles */
if (IsDefaultGroupID(this->vli.index) || IsAllGroupID(this->vli.index)) {
if (IsDefaultGroupID(this->vli.ToGroupID()) || IsAllGroupID(this->vli.ToGroupID())) {
SetDParam(0, STR_COMPANY_NAME);
SetDParam(1, this->vli.company);
SetDParam(2, this->vehicles.size());
SetDParam(3, this->vehicles.size());
} else {
uint num_vehicle = GetGroupNumVehicle(this->vli.company, this->vli.index, this->vli.vtype);
uint num_vehicle = GetGroupNumVehicle(this->vli.company, this->vli.ToGroupID(), this->vli.vtype);
SetDParam(0, STR_GROUP_NAME);
SetDParam(1, this->vli.index);
SetDParam(1, this->vli.ToGroupID());
SetDParam(2, num_vehicle);
SetDParam(3, num_vehicle);
}
@@ -566,7 +567,8 @@ public:
WID_GL_MANAGE_VEHICLES_DROPDOWN);
/* Disable the group specific function when we select the default group or all vehicles */
this->SetWidgetsDisabledState(IsDefaultGroupID(this->vli.index) || IsAllGroupID(this->vli.index) || _local_company != this->vli.company,
GroupID group = this->vli.ToGroupID();
this->SetWidgetsDisabledState(IsDefaultGroupID(group) || IsAllGroupID(group) || _local_company != this->vli.company,
WID_GL_DELETE_GROUP,
WID_GL_RENAME_GROUP,
WID_GL_LIVERY_GROUP,
@@ -584,7 +586,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(this->vli.index) && !IsAllGroupID(this->vli.index) && Group::Get(this->vli.index)->flags.Test(GroupFlag::ReplaceProtection)) protect_sprite = SPR_GROUP_REPLACE_ON_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);
/* Set text of "group by" dropdown widget. */
@@ -665,13 +667,13 @@ public:
break;
case WID_GL_LIST_VEHICLE:
if (this->vli.index != ALL_GROUP && this->grouping == GB_NONE) {
if (this->vli.ToGroupID() != ALL_GROUP && this->grouping == GB_NONE) {
/* Mark vehicles which are in sub-groups (only if we are not using shared order coalescing) */
Rect mr = r.WithHeight(this->resize.step_height);
auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->vehgroups);
for (auto it = first; it != last; ++it) {
const Vehicle *v = it->GetSingleVehicle();
if (v->group_id != this->vli.index) {
if (v->group_id != this->vli.ToGroupID()) {
GfxFillRect(mr.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(COLOUR_GREY, SHADE_DARK), FILLRECT_CHECKER);
}
mr = mr.Translate(0, this->resize.step_height);
@@ -722,7 +724,7 @@ public:
break;
case WID_GL_ALL_VEHICLES: // All vehicles button
if (!IsAllGroupID(this->vli.index)) {
if (!IsAllGroupID(this->vli.ToGroupID())) {
this->vli.index = ALL_GROUP;
this->vehgroups.ForceRebuild();
this->SetDirty();
@@ -730,7 +732,7 @@ public:
break;
case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles button
if (!IsDefaultGroupID(this->vli.index)) {
if (!IsDefaultGroupID(this->vli.ToGroupID())) {
this->vli.index = DEFAULT_GROUP;
this->vehgroups.ForceRebuild();
this->SetDirty();
@@ -749,7 +751,7 @@ public:
group_display->pos_x + WidgetDimensions::scaled.framerect.left + it->indent * WidgetDimensions::scaled.hsep_indent;
if (click_count > 1 || (pt.x >= x && pt.x < (int)(x + this->column_size[VGC_FOLD].width))) {
GroupID g = this->vli.index;
GroupID g = this->vli.ToGroupID();
if (!IsAllGroupID(g) && !IsDefaultGroupID(g)) {
do {
g = Group::Get(g)->parent;
@@ -832,22 +834,22 @@ public:
}
case WID_GL_CREATE_GROUP: { // Create a new group
Command<CMD_CREATE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_CREATE, CcCreateGroup, this->vli.vtype, this->vli.index);
Command<CMD_CREATE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_CREATE, CcCreateGroup, this->vli.vtype, this->vli.ToGroupID());
break;
}
case WID_GL_DELETE_GROUP: { // Delete the selected group
this->group_confirm = this->vli.index;
this->group_confirm = this->vli.ToGroupID();
ShowQuery(STR_QUERY_GROUP_DELETE_CAPTION, STR_GROUP_DELETE_QUERY_TEXT, this, DeleteGroupCallback);
break;
}
case WID_GL_RENAME_GROUP: // Rename the selected roup
this->ShowRenameGroupWindow(this->vli.index, false);
this->ShowRenameGroupWindow(this->vli.ToGroupID(), false);
break;
case WID_GL_LIVERY_GROUP: // Set group livery
ShowCompanyLiveryWindow(this->owner, this->vli.index);
ShowCompanyLiveryWindow(this->owner, this->vli.ToGroupID());
break;
case WID_GL_AVAILABLE_VEHICLES:
@@ -855,7 +857,7 @@ public:
break;
case WID_GL_MANAGE_VEHICLES_DROPDOWN: {
ShowDropDownList(this, this->BuildActionDropdownList(true, Group::IsValidID(this->vli.index), IsDefaultGroupID(this->vli.index)), -1, WID_GL_MANAGE_VEHICLES_DROPDOWN);
ShowDropDownList(this, this->BuildActionDropdownList(true, Group::IsValidID(this->vli.ToGroupID()), IsDefaultGroupID(this->vli.ToGroupID())), -1, WID_GL_MANAGE_VEHICLES_DROPDOWN);
break;
}
@@ -866,9 +868,9 @@ public:
}
case WID_GL_REPLACE_PROTECTION: {
const Group *g = Group::GetIfValid(this->vli.index);
const Group *g = Group::GetIfValid(this->vli.ToGroupID());
if (g != nullptr) {
Command<CMD_SET_GROUP_FLAG>::Post(this->vli.index, GroupFlag::ReplaceProtection, !g->flags.Test(GroupFlag::ReplaceProtection), _ctrl_pressed);
Command<CMD_SET_GROUP_FLAG>::Post(this->vli.ToGroupID(), GroupFlag::ReplaceProtection, !g->flags.Test(GroupFlag::ReplaceProtection), _ctrl_pressed);
}
break;
}
@@ -1013,7 +1015,7 @@ public:
switch (index) {
case ADI_REPLACE: // Replace window
ShowReplaceGroupVehicleWindow(this->vli.index, this->vli.vtype);
ShowReplaceGroupVehicleWindow(this->vli.ToGroupID(), this->vli.vtype);
break;
case ADI_SERVICE: // Send for servicing
case ADI_DEPOT: { // Send to Depots
@@ -1026,14 +1028,14 @@ public:
break;
case ADI_ADD_SHARED: // Add shared Vehicles
assert(Group::IsValidID(this->vli.index));
assert(Group::IsValidID(this->vli.ToGroupID()));
Command<CMD_ADD_SHARED_VEHICLE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_ADD_SHARED_VEHICLE, this->vli.index, this->vli.vtype);
Command<CMD_ADD_SHARED_VEHICLE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_ADD_SHARED_VEHICLE, this->vli.ToGroupID(), this->vli.vtype);
break;
case ADI_REMOVE_ALL: // Remove all Vehicles from the selected group
assert(Group::IsValidID(this->vli.index));
assert(Group::IsValidID(this->vli.ToGroupID()));
Command<CMD_REMOVE_ALL_VEHICLES_GROUP>::Post(STR_ERROR_GROUP_CAN_T_REMOVE_ALL_VEHICLES, this->vli.index);
Command<CMD_REMOVE_ALL_VEHICLES_GROUP>::Post(STR_ERROR_GROUP_CAN_T_REMOVE_ALL_VEHICLES, this->vli.ToGroupID());
break;
default: NOT_REACHED();
}
@@ -1124,7 +1126,7 @@ public:
*/
void SelectGroup(const GroupID g_id)
{
if (g_id == INVALID_GROUP || g_id == this->vli.index) return;
if (g_id == INVALID_GROUP || g_id == this->vli.ToGroupID()) return;
this->vli.index = g_id;
if (g_id != ALL_GROUP && g_id != DEFAULT_GROUP) {