diff options
author | michi_cc <michi_cc@openttd.org> | 2012-12-20 19:44:02 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2012-12-20 19:44:02 +0000 |
commit | c75962e04c0999c0c458b2ee54519f094d7c6543 (patch) | |
tree | 77dfc5b80771380cba34acf3f6ed564ce8be0657 | |
parent | 8eb1cb4ebbfa2b00ca27f860555f5397fe5a1c9e (diff) | |
download | openttd-c75962e04c0999c0c458b2ee54519f094d7c6543.tar.xz |
(svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
-rw-r--r-- | src/order_cmd.cpp | 16 | ||||
-rw-r--r-- | src/order_gui.cpp | 8 | ||||
-rw-r--r-- | src/settings.cpp | 2 | ||||
-rw-r--r-- | src/timetable_gui.cpp | 6 | ||||
-rw-r--r-- | src/train_cmd.cpp | 4 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 12 | ||||
-rw-r--r-- | src/vehicle_gui.h | 8 |
7 files changed, 32 insertions, 24 deletions
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 0ce3059c9..9fe0a4c3f 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -915,7 +915,7 @@ static CommandCost DecloneOrder(Vehicle *dst, DoCommandFlag flags) { if (flags & DC_EXEC) { DeleteVehicleOrders(dst); - InvalidateVehicleOrder(dst, -1); + InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS); InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0); } return CommandCost(); @@ -1054,7 +1054,7 @@ CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 if (v->current_order.IsType(OT_LOADING)) v->LeaveStation(); - InvalidateVehicleOrder(v, -2); + InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS); } /* We have an aircraft/ship, they have a mini-schedule, so update them all */ @@ -1393,7 +1393,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 u->current_order.GetLoadType() != order->GetLoadType()) { u->current_order.SetLoadType(order->GetLoadType()); } - InvalidateVehicleOrder(u, -2); + InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS); } } @@ -1503,8 +1503,8 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 /* Link this vehicle in the shared-list */ dst->AddToShared(src); - InvalidateVehicleOrder(dst, -1); - InvalidateVehicleOrder(src, -2); + InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS); + InvalidateVehicleOrder(src, VIWD_MODIFY_ORDERS); InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0); } @@ -1566,7 +1566,7 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 dst->orders.list = new OrderList(first, dst); } - InvalidateVehicleOrder(dst, -1); + InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS); InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0); } @@ -1624,7 +1624,7 @@ CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 for (Vehicle *u = v->FirstShared(); u != NULL; u = u->NextShared()) { /* Update any possible open window of the vehicle */ - InvalidateVehicleOrder(u, -2); + InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS); /* If the vehicle already got the current depot set as current order, then update current order as well */ if (u->cur_real_order_index == order_number && (u->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) { @@ -2093,7 +2093,7 @@ bool ProcessOrders(Vehicle *v) /* Otherwise set it, and determine the destination tile. */ v->current_order = *order; - InvalidateVehicleOrder(v, -2); + InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS); switch (v->type) { default: NOT_REACHED(); diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 85bd196ef..52f5c8c16 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -820,7 +820,7 @@ public: if (station_orders < 2) this->OrderClick_Goto(0); } - this->OnInvalidateData(-2); + this->OnInvalidateData(VIWD_MODIFY_ORDERS); } virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) @@ -866,13 +866,13 @@ public: VehicleOrderID to = INVALID_VEH_ORDER_ID; switch (data) { - case -666: + case VIWD_AUTOREPLACE: /* Autoreplace replaced the vehicle */ this->vehicle = Vehicle::Get(this->window_number); this->UpdateAutoRefitState(); break; - case -1: + case VIWD_REMOVE_ALL_ORDERS: /* Removed / replaced all orders (after deleting / sharing) */ if (this->selected_order == -1) break; @@ -881,7 +881,7 @@ public: this->selected_order = -1; break; - case -2: + case VIWD_MODIFY_ORDERS: /* Some other order changes */ break; diff --git a/src/settings.cpp b/src/settings.cpp index e9f190ede..27a68785d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -960,7 +960,7 @@ static bool TownFoundingChanged(int32 p1) static bool InvalidateVehTimetableWindow(int32 p1) { - InvalidateWindowClassesData(WC_VEHICLE_TIMETABLE, -2); + InvalidateWindowClassesData(WC_VEHICLE_TIMETABLE, VIWD_MODIFY_ORDERS); return true; } diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 6533e351d..7fc8da483 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -236,12 +236,12 @@ struct TimetableWindow : Window { virtual void OnInvalidateData(int data = 0, bool gui_scope = true) { switch (data) { - case -666: + case VIWD_AUTOREPLACE: /* Autoreplace replaced the vehicle */ this->vehicle = Vehicle::Get(this->window_number); break; - case -1: + case VIWD_REMOVE_ALL_ORDERS: /* Removed / replaced all orders (after deleting / sharing) */ if (this->sel_index == -1) break; @@ -249,7 +249,7 @@ struct TimetableWindow : Window { this->sel_index = -1; break; - case -2: + case VIWD_MODIFY_ORDERS: if (!gui_scope) break; this->UpdateSelectionStates(); this->ReInit(); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 58dd17163..032ed2bdb 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -241,7 +241,7 @@ void Train::ConsistChanged(bool same_length) if (this->IsFrontEngine()) { this->UpdateAcceleration(); SetWindowDirty(WC_VEHICLE_DETAILS, this->index); - InvalidateWindowData(WC_VEHICLE_REFIT, this->index); + InvalidateWindowData(WC_VEHICLE_REFIT, this->index, VIWD_CONSIST_CHANGED); } } @@ -1076,7 +1076,7 @@ static void NormaliseTrainHead(Train *head) if (!head->IsFrontEngine()) return; /* Update the refit button and window */ - InvalidateWindowData(WC_VEHICLE_REFIT, head->index); + InvalidateWindowData(WC_VEHICLE_REFIT, head->index, VIWD_CONSIST_CHANGED); SetWindowWidgetDirty(WC_VEHICLE_VIEW, head->index, WID_VV_REFIT); /* If we don't have a unit number yet, set one. */ diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 19cc7d217..554745e1d 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -534,7 +534,7 @@ struct RefitWindow : public Window { if (this->sel == -1) this->vscroll->ScrollTowards(0); } else { /* Rebuild the refit list */ - this->OnInvalidateData(0); + this->OnInvalidateData(VIWD_CONSIST_CHANGED); } } @@ -707,8 +707,8 @@ struct RefitWindow : public Window { virtual void OnInvalidateData(int data = 0, bool gui_scope = true) { switch (data) { - case -666: // Autoreplace replaced the vehicle; selected_vehicle became invalid. - case 0: { // The consist has changed; rebuild the entire list. + case VIWD_AUTOREPLACE: // Autoreplace replaced the vehicle; selected_vehicle became invalid. + case VIWD_CONSIST_CHANGED: { // The consist has changed; rebuild the entire list. /* Clear the selection. */ Vehicle *v = Vehicle::Get(this->window_number); this->selected_vehicle = v->index; @@ -1127,7 +1127,7 @@ static inline void ChangeVehicleWindow(WindowClass window_class, VehicleID from_ } /* Notify the window. */ - w->InvalidateData(-666, false); + w->InvalidateData(VIWD_AUTOREPLACE, false); } } @@ -1760,7 +1760,7 @@ struct VehicleDetailsWindow : Window { */ virtual void OnInvalidateData(int data = 0, bool gui_scope = true) { - if (data == -666) { + if (data == VIWD_AUTOREPLACE) { /* Autoreplace replaced the vehicle. * Nothing to do for this window. */ return; @@ -2585,7 +2585,7 @@ public: */ virtual void OnInvalidateData(int data = 0, bool gui_scope = true) { - if (data == -666) { + if (data == VIWD_AUTOREPLACE) { /* Autoreplace replaced the vehicle. * Nothing to do for this window. */ return; diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h index 846a86490..99155464b 100644 --- a/src/vehicle_gui.h +++ b/src/vehicle_gui.h @@ -29,6 +29,14 @@ enum TrainDetailsWindowTabs { TDW_TAB_TOTALS, ///< Tab with sum of total cargo transported }; +/** Special values for vehicle-related windows for the data parameter of #InvalidateWindowData. */ +enum VehicleInvalidateWindowData { + VIWD_REMOVE_ALL_ORDERS = -1, ///< Removed / replaced all orders (after deleting / sharing). + VIWD_MODIFY_ORDERS = -2, ///< Other order modifications. + VIWD_CONSIST_CHANGED = -3, ///< Vehicle composition was changed. + VIWD_AUTOREPLACE = -4, ///< Autoreplace replaced the vehicle. +}; + int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number); void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest = INVALID_VEHICLE); |