summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2008-08-06 18:57:37 +0000
committerfrosch <frosch@openttd.org>2008-08-06 18:57:37 +0000
commitcffd5d17de75a48ca7ce226069da20499158cba2 (patch)
tree9325aabbcb8aaaf05e5d47d1ff5c46e153ef5e06
parent0eade71bde0f70a3cedf36558ff2cf6804966ff8 (diff)
downloadopenttd-cffd5d17de75a48ca7ce226069da20499158cba2.tar.xz
(svn r14006) -Codechange: Deduplicate some code.
-rw-r--r--src/vehicle_gui.cpp55
1 files changed, 22 insertions, 33 deletions
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index fda939d35..5170ce9f7 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -630,47 +630,36 @@ void InitializeGUI()
MemSetT(&_sorting, 0);
}
-/** Assigns an already open vehicle window to a new vehicle.
- * Assigns an already open vehicle window to a new vehicle. If the vehicle got
- * any sub window open (orders and so on) it will change owner too.
- * @param from_index the current owner of the window
- * @param to_index the new owner of the window
+/**
+ * Assign a vehicle window a new vehicle
+ * @param window_class WindowClass to search for
+ * @param from_index the old vehicle ID
+ * @param to_index the new vehicle ID
*/
-void ChangeVehicleViewWindow(VehicleID from_index, VehicleID to_index)
+static inline void ChangeVehicleWindow(WindowClass window_class, VehicleID from_index, VehicleID to_index)
{
- Window *w = FindWindowById(WC_VEHICLE_VIEW, from_index);
-
+ Window *w = FindWindowById(window_class, from_index);
if (w != NULL) {
w->window_number = to_index;
- w->viewport->follow_vehicle = to_index;
+ if (w->viewport != NULL) w->viewport->follow_vehicle = to_index;
w->SetDirty();
-
- w = FindWindowById(WC_VEHICLE_ORDERS, from_index);
- if (w != NULL) {
- w->window_number = to_index;
- w->SetDirty();
- }
-
- w = FindWindowById(WC_VEHICLE_REFIT, from_index);
- if (w != NULL) {
- w->window_number = to_index;
- w->SetDirty();
- }
-
- w = FindWindowById(WC_VEHICLE_DETAILS, from_index);
- if (w != NULL) {
- w->window_number = to_index;
- w->SetDirty();
- }
-
- w = FindWindowById(WC_VEHICLE_TIMETABLE, from_index);
- if (w != NULL) {
- w->window_number = to_index;
- w->SetDirty();
- }
}
}
+/**
+ * Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows.
+ * @param from_index the old vehicle ID
+ * @param to_index the new vehicle ID
+ */
+void ChangeVehicleViewWindow(VehicleID from_index, VehicleID to_index)
+{
+ ChangeVehicleWindow(WC_VEHICLE_VIEW, from_index, to_index);
+ ChangeVehicleWindow(WC_VEHICLE_ORDERS, from_index, to_index);
+ ChangeVehicleWindow(WC_VEHICLE_REFIT, from_index, to_index);
+ ChangeVehicleWindow(WC_VEHICLE_DETAILS, from_index, to_index);
+ ChangeVehicleWindow(WC_VEHICLE_TIMETABLE, from_index, to_index);
+}
+
enum VehicleListWindowWidgets {
VLW_WIDGET_CLOSEBOX = 0,
VLW_WIDGET_CAPTION,