summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernard Teo <btzy1996@hotmail.com>2020-12-17 20:27:29 +0800
committerPatric Stout <github@truebrain.nl>2020-12-21 23:15:53 +0100
commit4af1acfe926db39965f3cff2a41ecf0da32b4137 (patch)
tree53433492d3f10b6f1d1d1f0e2c6371a24580cd6a /src
parenta5047b7566ffdc430e6753a76d1381959275f259 (diff)
downloadopenttd-4af1acfe926db39965f3cff2a41ecf0da32b4137.tar.xz
Feature: Drag-and-drop vehicles in group GUI for shared order groups
Diffstat (limited to 'src')
-rw-r--r--src/group_gui.cpp61
1 files changed, 39 insertions, 22 deletions
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index f1b1d4ef8..121008795 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -726,34 +726,43 @@ public:
if (id_v >= this->vehgroups.size()) return; // click out of list bound
const GUIVehicleGroup &vehgroup = this->vehgroups[id_v];
- switch (this->grouping) {
- case GB_NONE: {
- const Vehicle *v = vehgroup.GetSingleVehicle();
- if (VehicleClicked(v)) break;
-
- this->vehicle_sel = v->index;
-
- if (_ctrl_pressed) {
- this->SelectGroup(v->group_id);
- }
- SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
- SetMouseCursorVehicle(v, EIT_IN_LIST);
- _cursor.vehchain = true;
+ const Vehicle *v = nullptr;
- this->SetDirty();
+ switch (this->grouping) {
+ case GB_NONE: {
+ const Vehicle *v2 = vehgroup.GetSingleVehicle();
+ if (VehicleClicked(v2)) break;
+ v = v2;
break;
}
- case GB_SHARED_ORDERS:
+ case GB_SHARED_ORDERS: {
assert(vehgroup.NumVehicles() > 0);
- /* No drag-and-drop support for shared order grouping; we immediately open the shared orders window */
- ShowVehicleListWindow(vehgroup.vehicles_begin[0]);
+ v = vehgroup.vehicles_begin[0];
+ /*
+ No VehicleClicked(v) support for now, because don't want
+ to enable any contextual actions except perhaps clicking/ctrl-clicking to clone orders.
+ */
break;
+ }
default:
NOT_REACHED();
}
+ if (v) {
+ this->vehicle_sel = v->index;
+
+ if (_ctrl_pressed) {
+ this->SelectGroup(v->group_id);
+ }
+
+ SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
+ SetMouseCursorVehicle(v, EIT_IN_LIST);
+ _cursor.vehchain = true;
+
+ this->SetDirty();
+ }
break;
}
@@ -838,7 +847,7 @@ public:
{
switch (widget) {
case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
- DoCommandP(0, DEFAULT_GROUP, this->vehicle_sel | (_ctrl_pressed ? 1 << 31 : 0), CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE));
+ DoCommandP(0, DEFAULT_GROUP, this->vehicle_sel | (_ctrl_pressed || this->grouping == GB_SHARED_ORDERS ? 1 << 31 : 0), CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE));
this->vehicle_sel = INVALID_VEHICLE;
this->group_over = INVALID_GROUP;
@@ -855,7 +864,7 @@ public:
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
GroupID new_g = id_g >= this->groups.size() ? NEW_GROUP : this->groups[id_g]->index;
- DoCommandP(0, new_g, vindex | (_ctrl_pressed ? 1 << 31 : 0), CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE), new_g == NEW_GROUP ? CcAddVehicleNewGroup : nullptr);
+ DoCommandP(0, new_g, vindex | (_ctrl_pressed || this->grouping == GB_SHARED_ORDERS ? 1 << 31 : 0), CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE), new_g == NEW_GROUP ? CcAddVehicleNewGroup : nullptr);
break;
}
@@ -877,9 +886,17 @@ public:
}
break;
}
- case GB_SHARED_ORDERS:
- /* Currently no drag-and-drop support when grouped by shared orders. Modify this if we want to support some drag-drop behaviour for shared order list items. */
- NOT_REACHED();
+
+ case GB_SHARED_ORDERS: {
+ const Vehicle *v = vehgroup.vehicles_begin[0];
+ /* We do not support VehicleClicked() here since the contextual action may only make sense for individual vehicles */
+
+ if (vindex == v->index) {
+ ShowVehicleListWindow(v);
+ }
+ break;
+ }
+
default:
NOT_REACHED();
}