summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormaedhros <maedhros@openttd.org>2008-04-14 12:40:09 +0000
committermaedhros <maedhros@openttd.org>2008-04-14 12:40:09 +0000
commit1f59821020389478b6bde28639e916e646c53cb7 (patch)
treefbb54fac086bb8d399862e631036ec3df0c3bd4d /src
parent14b307a621432dae325c2783422387843871e86b (diff)
downloadopenttd-1f59821020389478b6bde28639e916e646c53cb7.tar.xz
(svn r12699) -Codechange: Unify the order drawing code for orders and timetables.
Diffstat (limited to 'src')
-rw-r--r--src/order_func.h2
-rw-r--r--src/order_gui.cpp190
-rw-r--r--src/timetable.h1
-rw-r--r--src/timetable_gui.cpp90
4 files changed, 110 insertions, 173 deletions
diff --git a/src/order_func.h b/src/order_func.h
index 16fc5309c..eec917b4f 100644
--- a/src/order_func.h
+++ b/src/order_func.h
@@ -37,6 +37,8 @@ void CheckOrders(const Vehicle*);
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
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index 56350f5e2..782de13ba 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -211,6 +211,105 @@ extern uint ConvertSpeedToDisplaySpeed(uint speed);
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 @@ static void DrawOrdersWindow(Window *w)
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);
- }
-
- 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;
+ /* Don't draw anything if it extends past the end of the window. */
+ if (i - w->vscroll.pos >= w->vscroll.cap) 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;
diff --git a/src/timetable.h b/src/timetable.h
index b48805417..1e0f57fa9 100644
--- 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 */
diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp
index 75ed54a65..7fa33a239 100644
--- 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 @@ static int GetOrderFromTimetableWndPt(Window *w, int y, const Vehicle *v)
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 @@ static void DrawTimetableWindow(Window *w)
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 @@ static void DrawTimetableWindow(Window *w)
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;
}