Mercurial > hg > openttd
changeset 8929:2b6a37a13245 draft
(svn r12699) -Codechange: Unify the order drawing code for orders and timetables.
author | maedhros <maedhros@openttd.org> |
---|---|
date | Mon, 14 Apr 2008 12:40:09 +0000 |
parents | f256fabe6441 |
children | 2651776f9e1d |
files | src/order_func.h src/order_gui.cpp src/timetable.h src/timetable_gui.cpp |
diffstat | 4 files changed, 110 insertions(+), 173 deletions(-) [+] |
line wrap: on
line diff
--- a/src/order_func.h +++ b/src/order_func.h @@ -37,6 +37,8 @@ void DeleteVehicleOrders(Vehicle *v); bool ProcessOrders(Vehicle *v); +void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable); + #define MIN_SERVINT_PERCENT 5 #define MAX_SERVINT_PERCENT 90 #define MIN_SERVINT_DAYS 30
--- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -211,6 +211,105 @@ extern uint ConvertDisplaySpeedToSpeed(uint speed); +void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable) +{ + StringID str = (v->cur_order_index == order_index) ? STR_8805 : STR_8804; + SetDParam(6, STR_EMPTY); + + switch (order->GetType()) { + case OT_DUMMY: + SetDParam(1, STR_INVALID_ORDER); + SetDParam(2, order->GetDestination()); + break; + + case OT_GOTO_STATION: { + OrderLoadFlags load = order->GetLoadType(); + OrderUnloadFlags unload = order->GetUnloadType(); + + SetDParam(1, STR_GO_TO_STATION); + SetDParam(2, STR_ORDER_GO_TO + ((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? order->GetNonStopType() : 0)); + SetDParam(3, order->GetDestination()); + + if (timetable) { + SetDParam(4, STR_EMPTY); + + if (order->wait_time > 0) { + SetDParam(6, STR_TIMETABLE_STAY_FOR); + SetTimetableParams(7, 8, order->wait_time); + } + } else { + SetDParam(4, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[unload][load]); + } + } break; + + case OT_GOTO_DEPOT: + if (v->type == VEH_AIRCRAFT) { + if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) { + SetDParam(1, STR_GO_TO_NEAREST_DEPOT); + SetDParam(3, STR_ORDER_NEAREST_HANGAR); + } else { + SetDParam(1, STR_GO_TO_HANGAR); + SetDParam(3, order->GetDestination()); + } + SetDParam(4, STR_EMPTY); + } else { + if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) { + SetDParam(1, STR_GO_TO_NEAREST_DEPOT); + SetDParam(3, STR_ORDER_NEAREST_DEPOT); + } else { + SetDParam(1, STR_GO_TO_DEPOT); + SetDParam(3, GetDepot(order->GetDestination())->town_index); + } + + switch (v->type) { + case VEH_TRAIN: SetDParam(4, STR_ORDER_TRAIN_DEPOT); break; + case VEH_ROAD: SetDParam(4, STR_ORDER_ROAD_DEPOT); break; + case VEH_SHIP: SetDParam(4, STR_ORDER_SHIP_DEPOT); break; + default: NOT_REACHED(); + } + } + + if (order->GetDepotOrderType() & ODTFB_SERVICE) { + SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT); + } else { + SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO); + } + + if (!timetable && order->IsRefit()) { + SetDParam(6, STR_REFIT_ORDER); + SetDParam(7, GetCargo(order->GetRefitCargo())->name); + } + break; + + case OT_GOTO_WAYPOINT: + SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT); + SetDParam(2, order->GetDestination()); + break; + + case OT_CONDITIONAL: + SetDParam(2, order->GetConditionSkipToOrder() + 1); + if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) { + SetDParam(1, STR_CONDITIONAL_UNCONDITIONAL); + } else { + OrderConditionComparator occ = order->GetConditionComparator(); + SetDParam(1, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_CONDITIONAL_TRUE_FALSE : STR_CONDITIONAL_NUM); + SetDParam(3, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable()); + SetDParam(4, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ); + + uint value = order->GetConditionValue(); + if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value); + SetDParam(5, value); + } + break; + + default: NOT_REACHED(); + } + + SetDParam(0, order_index + 1); + DrawString(2, y, str, selected ? TC_WHITE : TC_BLACK); +} + + static void DrawOrdersWindow(Window *w) { const Vehicle *v = GetVehicle(w->window_number); @@ -310,94 +409,11 @@ order = GetVehicleOrder(v, i); StringID str; while (order != NULL) { - str = (v->cur_order_index == i) ? STR_8805 : STR_8804; - SetDParam(6, STR_EMPTY); - - if (i - w->vscroll.pos < w->vscroll.cap) { - switch (order->GetType()) { - case OT_DUMMY: - SetDParam(1, STR_INVALID_ORDER); - SetDParam(2, order->GetDestination()); - break; - - case OT_GOTO_STATION: { - OrderLoadFlags load = order->GetLoadType(); - OrderUnloadFlags unload = order->GetUnloadType(); - - SetDParam(1, STR_GO_TO_STATION); - SetDParam(2, STR_ORDER_GO_TO + ((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? order->GetNonStopType() : 0)); - SetDParam(3, order->GetDestination()); - SetDParam(4, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[unload][load]); - } break; - - case OT_GOTO_DEPOT: - if (v->type == VEH_AIRCRAFT) { - if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) { - SetDParam(1, STR_GO_TO_NEAREST_DEPOT); - SetDParam(3, STR_ORDER_NEAREST_HANGAR); - } else { - SetDParam(1, STR_GO_TO_HANGAR); - SetDParam(3, order->GetDestination()); - } - SetDParam(4, STR_EMPTY); - } else { - if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) { - SetDParam(1, STR_GO_TO_NEAREST_DEPOT); - SetDParam(3, STR_ORDER_NEAREST_DEPOT); - } else { - SetDParam(1, STR_GO_TO_DEPOT); - SetDParam(3, GetDepot(order->GetDestination())->town_index); - } + /* Don't draw anything if it extends past the end of the window. */ + if (i - w->vscroll.pos >= w->vscroll.cap) break; - switch (v->type) { - case VEH_TRAIN: SetDParam(4, STR_ORDER_TRAIN_DEPOT); break; - case VEH_ROAD: SetDParam(4, STR_ORDER_ROAD_DEPOT); break; - case VEH_SHIP: SetDParam(4, STR_ORDER_SHIP_DEPOT); break; - default: NOT_REACHED(); - } - } - - if (order->GetDepotOrderType() & ODTFB_SERVICE) { - SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT); - } else { - SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO); - } - - if (order->IsRefit()) { - SetDParam(6, STR_REFIT_ORDER); - SetDParam(7, GetCargo(order->GetRefitCargo())->name); - } - break; - - case OT_GOTO_WAYPOINT: - SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT); - SetDParam(2, order->GetDestination()); - break; - - case OT_CONDITIONAL: - SetDParam(2, order->GetConditionSkipToOrder() + 1); - if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) { - SetDParam(1, STR_CONDITIONAL_UNCONDITIONAL); - } else { - OrderConditionComparator occ = order->GetConditionComparator(); - SetDParam(1, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_CONDITIONAL_TRUE_FALSE : STR_CONDITIONAL_NUM); - SetDParam(3, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable()); - SetDParam(4, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ); - - uint value = order->GetConditionValue(); - if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value); - SetDParam(5, value); - } - break; - - default: NOT_REACHED(); - } - - SetDParam(0, i + 1); - DrawString(2, y, str, (i == WP(w, order_d).sel) ? TC_WHITE : TC_BLACK); - - y += 10; - } + DrawOrderString(v, order, i, y, i == WP(w, order_d).sel, false); + y += 10; i++; order = order->next;
--- a/src/timetable.h +++ b/src/timetable.h @@ -7,5 +7,6 @@ void ShowTimetableWindow(const Vehicle *v); void UpdateVehicleTimetable(Vehicle *v, bool travelling); +void SetTimetableParams(int param1, int param2, uint32 time); #endif /* TIMETABLE_H */
--- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -16,6 +16,7 @@ #include "string_func.h" #include "gfx_func.h" #include "player_func.h" +#include "order_func.h" #include "settings_type.h" #include "table/strings.h" @@ -57,7 +58,7 @@ return (sel <= v->num_orders * 2 && sel >= 0) ? sel : INVALID_ORDER; } -static inline void SetTimetableParams(int param1, int param2, uint32 time) +void SetTimetableParams(int param1, int param2, uint32 time) { if (_patches.timetable_in_ticks) { SetDParam(param1, STR_TIMETABLE_TICKS); @@ -116,90 +117,7 @@ if (i - w->vscroll.pos >= w->vscroll.cap) break; if (i % 2 == 0) { - SetDParam(5, STR_EMPTY); - - switch (order->GetType()) { - case OT_DUMMY: - SetDParam(0, STR_INVALID_ORDER); - break; - - case OT_GOTO_STATION: - SetDParam(0, STR_GO_TO_STATION); - SetDParam(1, STR_ORDER_GO_TO + order->GetNonStopType()); - SetDParam(2, order->GetDestination()); - SetDParam(3, STR_EMPTY); - - if (order->wait_time > 0) { - SetDParam(5, STR_TIMETABLE_STAY_FOR); - SetTimetableParams(6, 7, order->wait_time); - } else { - SetDParam(4, STR_EMPTY); - } - - break; - - case OT_GOTO_DEPOT: - SetDParam(4, STR_EMPTY); - if (v->type == VEH_AIRCRAFT) { - if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) { - SetDParam(0, STR_GO_TO_NEAREST_DEPOT); - SetDParam(2, STR_ORDER_NEAREST_HANGAR); - } else { - SetDParam(0, STR_GO_TO_HANGAR); - SetDParam(2, order->GetDestination()); - } - SetDParam(3, STR_EMPTY); - } else { - if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) { - SetDParam(0, STR_GO_TO_NEAREST_DEPOT); - SetDParam(2, STR_ORDER_NEAREST_DEPOT); - } else { - SetDParam(0, STR_GO_TO_DEPOT); - SetDParam(2, GetDepot(order->GetDestination())->town_index); - } - - switch (v->type) { - case VEH_TRAIN: SetDParam(3, STR_ORDER_TRAIN_DEPOT); break; - case VEH_ROAD: SetDParam(3, STR_ORDER_ROAD_DEPOT); break; - case VEH_SHIP: SetDParam(3, STR_ORDER_SHIP_DEPOT); break; - default: NOT_REACHED(); - } - } - - if (order->GetDepotOrderType() & ODTFB_SERVICE) { - SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT); - } else { - SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO); - } - break; - - case OT_GOTO_WAYPOINT: - SetDParam(0, (order->GetNonStopType() != ONSF_STOP_EVERYWHERE) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT); - SetDParam(1, order->GetDestination()); - break; - - - case OT_CONDITIONAL: - SetDParam(1, order->GetConditionSkipToOrder() + 1); - if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) { - SetDParam(0, STR_CONDITIONAL_UNCONDITIONAL); - } else { - extern uint ConvertSpeedToDisplaySpeed(uint speed); - OrderConditionComparator occ = order->GetConditionComparator(); - SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_CONDITIONAL_TRUE_FALSE : STR_CONDITIONAL_NUM); - SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable()); - SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ); - - uint value = order->GetConditionValue(); - if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value); - SetDParam(4, value); - } - break; - - default: break; - } - - DrawString(2, y, STR_TIMETABLE_GO_TO, (i == selected) ? TC_WHITE : TC_BLACK); + DrawOrderString(v, order, order_id, y, i == selected, true); order_id++; @@ -219,7 +137,7 @@ string = STR_TIMETABLE_TRAVEL_FOR; } - DrawString(12, y, string, (i == selected) ? TC_WHITE : TC_BLACK); + DrawString(22, y, string, (i == selected) ? TC_WHITE : TC_BLACK); if (final_order) break; }