mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-08 01:10:28 +00:00
(svn r12699) -Codechange: Unify the order drawing code for orders and timetables.
This commit is contained in:
parent
760a57867f
commit
b0629b31fa
@ -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
|
||||
|
@ -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);
|
||||
/* Don't draw anything if it extends past the end of the window. */
|
||||
if (i - w->vscroll.pos >= w->vscroll.cap) break;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user