Codechange: Make vehicle lists internally support grouping of vehicles
This is in preparation for the new UI feature that allows grouping by shared orders.
This commit is contained in:

committed by
Patric Stout

parent
86e08aa8ef
commit
584df548f1
@@ -341,24 +341,12 @@ public:
|
||||
this->vscroll = this->GetScrollbar(WID_GL_LIST_VEHICLE_SCROLLBAR);
|
||||
this->group_sb = this->GetScrollbar(WID_GL_LIST_GROUP_SCROLLBAR);
|
||||
|
||||
switch (this->vli.vtype) {
|
||||
default: NOT_REACHED();
|
||||
case VEH_TRAIN: this->sorting = &_sorting.train; break;
|
||||
case VEH_ROAD: this->sorting = &_sorting.roadveh; break;
|
||||
case VEH_SHIP: this->sorting = &_sorting.ship; break;
|
||||
case VEH_AIRCRAFT: this->sorting = &_sorting.aircraft; break;
|
||||
}
|
||||
|
||||
this->vli.index = ALL_GROUP;
|
||||
this->vehicle_sel = INVALID_VEHICLE;
|
||||
this->group_sel = INVALID_GROUP;
|
||||
this->group_rename = INVALID_GROUP;
|
||||
this->group_over = INVALID_GROUP;
|
||||
|
||||
this->vehicles.SetListing(*this->sorting);
|
||||
this->vehicles.ForceRebuild();
|
||||
this->vehicles.NeedResort();
|
||||
|
||||
this->BuildVehicleList();
|
||||
this->SortVehicleList();
|
||||
|
||||
@@ -382,7 +370,7 @@ public:
|
||||
|
||||
~VehicleGroupWindow()
|
||||
{
|
||||
*this->sorting = this->vehicles.GetListing();
|
||||
*this->sorting = this->vehgroups.GetListing();
|
||||
}
|
||||
|
||||
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
|
||||
@@ -453,10 +441,10 @@ public:
|
||||
{
|
||||
if (data == 0) {
|
||||
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
|
||||
this->vehicles.ForceRebuild();
|
||||
this->vehgroups.ForceRebuild();
|
||||
this->groups.ForceRebuild();
|
||||
} else {
|
||||
this->vehicles.ForceResort();
|
||||
this->vehgroups.ForceResort();
|
||||
this->groups.ForceResort();
|
||||
}
|
||||
|
||||
@@ -509,8 +497,8 @@ public:
|
||||
|
||||
this->BuildGroupList(this->owner);
|
||||
|
||||
this->group_sb->SetCount((uint)this->groups.size());
|
||||
this->vscroll->SetCount((uint)this->vehicles.size());
|
||||
this->group_sb->SetCount(static_cast<int>(this->groups.size()));
|
||||
this->vscroll->SetCount(static_cast<int>(this->vehgroups.size()));
|
||||
|
||||
/* The drop down menu is out, *but* it may not be used, retract it. */
|
||||
if (this->vehicles.size() == 0 && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) {
|
||||
@@ -550,7 +538,7 @@ public:
|
||||
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data = protect_sprite + this->vli.vtype;
|
||||
|
||||
/* Set text of sort by dropdown */
|
||||
this->GetWidget<NWidgetCore>(WID_GL_SORT_BY_DROPDOWN)->widget_data = this->vehicle_sorter_names[this->vehicles.SortType()];
|
||||
this->GetWidget<NWidgetCore>(WID_GL_SORT_BY_DROPDOWN)->widget_data = this->vehicle_group_none_sorter_names[this->vehgroups.SortType()];
|
||||
|
||||
this->DrawWidgets();
|
||||
}
|
||||
@@ -623,16 +611,16 @@ public:
|
||||
}
|
||||
|
||||
case WID_GL_SORT_BY_ORDER:
|
||||
this->DrawSortButtonState(WID_GL_SORT_BY_ORDER, this->vehicles.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
|
||||
this->DrawSortButtonState(WID_GL_SORT_BY_ORDER, this->vehgroups.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
|
||||
break;
|
||||
|
||||
case WID_GL_LIST_VEHICLE:
|
||||
if (this->vli.index != ALL_GROUP) {
|
||||
/* Mark vehicles which are in sub-groups */
|
||||
if (this->vli.index != ALL_GROUP && this->grouping == GB_NONE) {
|
||||
/* Mark vehicles which are in sub-groups (only if we are not using shared order coalescing) */
|
||||
int y = r.top;
|
||||
uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (uint)this->vehicles.size());
|
||||
uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), static_cast<uint>(this->vehgroups.size()));
|
||||
for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
|
||||
const Vehicle *v = this->vehicles[i];
|
||||
const Vehicle *v = this->vehgroups[i].GetSingleVehicle();
|
||||
if (v->group_id != this->vli.index) {
|
||||
GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->resize.step_height - 2, _colour_gradient[COLOUR_GREY][3], FILLRECT_CHECKER);
|
||||
}
|
||||
@@ -658,18 +646,18 @@ public:
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_GL_SORT_BY_ORDER: // Flip sorting method ascending/descending
|
||||
this->vehicles.ToggleSortOrder();
|
||||
this->vehgroups.ToggleSortOrder();
|
||||
this->SetDirty();
|
||||
break;
|
||||
|
||||
case WID_GL_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
|
||||
ShowDropDownMenu(this, this->vehicle_sorter_names, this->vehicles.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 == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10));
|
||||
return;
|
||||
|
||||
case WID_GL_ALL_VEHICLES: // All vehicles button
|
||||
if (!IsAllGroupID(this->vli.index)) {
|
||||
this->vli.index = ALL_GROUP;
|
||||
this->vehicles.ForceRebuild();
|
||||
this->vehgroups.ForceRebuild();
|
||||
this->SetDirty();
|
||||
}
|
||||
break;
|
||||
@@ -677,7 +665,7 @@ public:
|
||||
case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles button
|
||||
if (!IsDefaultGroupID(this->vli.index)) {
|
||||
this->vli.index = DEFAULT_GROUP;
|
||||
this->vehicles.ForceRebuild();
|
||||
this->vehgroups.ForceRebuild();
|
||||
this->SetDirty();
|
||||
}
|
||||
break;
|
||||
@@ -717,17 +705,17 @@ public:
|
||||
|
||||
SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
|
||||
|
||||
this->vehicles.ForceRebuild();
|
||||
this->vehgroups.ForceRebuild();
|
||||
this->SetDirty();
|
||||
break;
|
||||
}
|
||||
|
||||
case WID_GL_LIST_VEHICLE: { // Matrix Vehicle
|
||||
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_VEHICLE);
|
||||
if (id_v >= this->vehicles.size()) return; // click out of list bound
|
||||
if (id_v >= this->vehgroups.size()) return; // click out of list bound
|
||||
|
||||
const Vehicle *v = this->vehicles[id_v];
|
||||
if (VehicleClicked(v)) break;
|
||||
const GUIVehicleGroup &vehgroup = this->vehgroups[id_v];
|
||||
const Vehicle * const v = vehgroup.GetSingleVehicle();
|
||||
|
||||
this->vehicle_sel = v->index;
|
||||
|
||||
@@ -851,13 +839,13 @@ public:
|
||||
this->SetDirty();
|
||||
|
||||
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_VEHICLE);
|
||||
if (id_v >= this->vehicles.size()) return; // click out of list bound
|
||||
if (id_v >= this->vehgroups.size()) return; // click out of list bound
|
||||
|
||||
const Vehicle *v = this->vehicles[id_v];
|
||||
const GUIVehicleGroup &vehgroup = this->vehgroups[id_v];
|
||||
const Vehicle *v = vehgroup.GetSingleVehicle();
|
||||
if (!VehicleClicked(v) && vindex == v->index) {
|
||||
ShowVehicleViewWindow(v);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -886,7 +874,7 @@ public:
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_GL_SORT_BY_DROPDOWN:
|
||||
this->vehicles.SetSortType(index);
|
||||
this->vehgroups.SetSortType(index);
|
||||
break;
|
||||
|
||||
case WID_GL_MANAGE_VEHICLES_DROPDOWN:
|
||||
@@ -924,7 +912,7 @@ public:
|
||||
|
||||
void OnGameTick() override
|
||||
{
|
||||
if (this->groups.NeedResort() || this->vehicles.NeedResort()) {
|
||||
if (this->groups.NeedResort() || this->vehgroups.NeedResort()) {
|
||||
this->SetDirty();
|
||||
}
|
||||
}
|
||||
@@ -1019,7 +1007,7 @@ public:
|
||||
}
|
||||
this->group_sb->ScrollTowards(id_g);
|
||||
}
|
||||
this->vehicles.ForceRebuild();
|
||||
this->vehgroups.ForceRebuild();
|
||||
this->SetDirty();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user