Mercurial > hg > openttd
changeset 19900:b4c4f1c24136 draft
(svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
author | michi_cc <michi_cc@openttd.org> |
---|---|
date | Thu, 20 Dec 2012 19:44:02 +0000 |
parents | 4f44e1c86f9c |
children | 9edbe277d872 |
files | src/order_cmd.cpp src/order_gui.cpp src/settings.cpp src/timetable_gui.cpp src/train_cmd.cpp src/vehicle_gui.cpp src/vehicle_gui.h |
diffstat | 7 files changed, 32 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -915,7 +915,7 @@ { 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 @@ 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 @@ u->current_order.GetLoadType() != order->GetLoadType()) { u->current_order.SetLoadType(order->GetLoadType()); } - InvalidateVehicleOrder(u, -2); + InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS); } } @@ -1503,8 +1503,8 @@ /* 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 @@ 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 @@ 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 @@ /* 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();
--- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -820,7 +820,7 @@ 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 @@ 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 @@ this->selected_order = -1; break; - case -2: + case VIWD_MODIFY_ORDERS: /* Some other order changes */ break;
--- a/src/settings.cpp +++ b/src/settings.cpp @@ -960,7 +960,7 @@ static bool InvalidateVehTimetableWindow(int32 p1) { - InvalidateWindowClassesData(WC_VEHICLE_TIMETABLE, -2); + InvalidateWindowClassesData(WC_VEHICLE_TIMETABLE, VIWD_MODIFY_ORDERS); return true; }
--- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -236,12 +236,12 @@ 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 @@ this->sel_index = -1; break; - case -2: + case VIWD_MODIFY_ORDERS: if (!gui_scope) break; this->UpdateSelectionStates(); this->ReInit();
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -241,7 +241,7 @@ 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 @@ 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. */
--- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -534,7 +534,7 @@ 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 @@ 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 @@ } /* Notify the window. */ - w->InvalidateData(-666, false); + w->InvalidateData(VIWD_AUTOREPLACE, false); } } @@ -1760,7 +1760,7 @@ */ 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 @@ */ 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;
--- a/src/vehicle_gui.h +++ b/src/vehicle_gui.h @@ -29,6 +29,14 @@ 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);