Codechange: Use local string parameters for order and timetable windows.

Order display is now composed of concatenated strings instead of a complex 10-parameter format string, which simplifies things and fixes duplicate spaces.
This commit is contained in:
Peter Nelson
2025-02-23 09:18:14 +00:00
committed by Peter Nelson
parent 23ba18ada7
commit 7fd0e6c27d
4 changed files with 185 additions and 187 deletions

View File

@@ -45,7 +45,7 @@ static const StringID _station_load_types[][5][5] = {
{
/* No refitting. */
{
STR_EMPTY,
INVALID_STRING_ID,
INVALID_STRING_ID,
STR_ORDER_FULL_LOAD,
STR_ORDER_FULL_LOAD_ANY,
@@ -68,6 +68,7 @@ static const StringID _station_load_types[][5][5] = {
INVALID_STRING_ID,
INVALID_STRING_ID,
INVALID_STRING_ID,
INVALID_STRING_ID,
}, {
STR_ORDER_NO_UNLOAD,
INVALID_STRING_ID,
@@ -101,6 +102,7 @@ static const StringID _station_load_types[][5][5] = {
INVALID_STRING_ID,
INVALID_STRING_ID,
INVALID_STRING_ID,
INVALID_STRING_ID,
}, {
STR_ORDER_NO_UNLOAD_REFIT,
INVALID_STRING_ID,
@@ -199,6 +201,15 @@ static const StringID _order_refit_action_dropdown[] = {
STR_ORDER_DROP_REFIT_AUTO_ANY,
};
static StringID GetOrderGoToString(const Order &order)
{
if (order.GetDepotOrderType() & ODTFB_SERVICE) {
return (order.GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT;
} else {
return (order.GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO;
}
}
/**
* Draws an order in order or timetable GUI
* @param v Vehicle the order belongs to
@@ -233,30 +244,18 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
colour = TC_WHITE;
}
SetDParam(0, order_index + 1);
DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, STR_ORDER_INDEX, colour, SA_RIGHT | SA_FORCE);
DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, GetString(STR_ORDER_INDEX, order_index + 1), colour, SA_RIGHT | SA_FORCE);
SetDParam(5, STR_EMPTY);
SetDParam(8, STR_EMPTY);
SetDParam(9, STR_EMPTY);
/* Check range for aircraft. */
if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
const Order *next = order->next != nullptr ? order->next : v->GetFirstOrder();
if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) SetDParam(9, STR_ORDER_OUT_OF_RANGE);
}
std::string line;
switch (order->GetType()) {
case OT_DUMMY:
SetDParam(0, STR_INVALID_ORDER);
SetDParam(1, order->GetDestination());
line = GetString(STR_INVALID_ORDER);
break;
case OT_IMPLICIT:
SetDParam(0, STR_ORDER_GO_TO_STATION);
SetDParam(1, STR_ORDER_GO_TO);
SetDParam(2, order->GetDestination());
SetDParam(3, timetable ? STR_EMPTY : STR_ORDER_IMPLICIT);
line = GetString(STR_ORDER_GO_TO_STATION, STR_ORDER_GO_TO, order->GetDestination());
if (!timetable) line += GetString(STR_ORDER_IMPLICIT);
break;
case OT_GOTO_STATION: {
@@ -264,30 +263,30 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
OrderUnloadFlags unload = order->GetUnloadType();
bool valid_station = CanVehicleUseStation(v, Station::Get(order->GetDestination().ToStationID()));
SetDParam(0, valid_station ? STR_ORDER_GO_TO_STATION : STR_ORDER_GO_TO_STATION_CAN_T_USE_STATION);
SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
SetDParam(2, order->GetDestination());
line = GetString(valid_station ? STR_ORDER_GO_TO_STATION : STR_ORDER_GO_TO_STATION_CAN_T_USE_STATION, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0), order->GetDestination());
if (timetable) {
/* Show only wait time in the timetable window. */
SetDParam(3, STR_EMPTY);
if (order->GetWaitTime() > 0) {
SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR : STR_TIMETABLE_STAY_FOR_ESTIMATED);
SetTimetableParams(6, 7, order->GetWaitTime());
auto [str, value] = GetTimetableParameters(order->GetWaitTime());
line += GetString(order->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR : STR_TIMETABLE_STAY_FOR_ESTIMATED, str, value);
}
} else {
/* Show non-stop, refit and stop location only in the order window. */
SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]);
if (order->IsRefit()) {
SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
if (!(order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) {
StringID str = _station_load_types[order->IsRefit()][unload][load];
if (str != INVALID_STRING_ID) {
if (order->IsRefit()) {
line += GetString(str, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
} else {
line += GetString(str);
}
}
}
if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
/* Only show the stopping location if other than the default chosen by the player. */
if (order->GetStopLocation() != (OrderStopLocation)(_settings_client.gui.stop_location)) {
SetDParam(5, STR_ORDER_STOP_LOCATION_NEAR_END + order->GetStopLocation());
} else {
SetDParam(5, STR_EMPTY);
line += GetString(STR_ORDER_STOP_LOCATION_NEAR_END + order->GetStopLocation());
}
}
}
@@ -295,79 +294,71 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
}
case OT_GOTO_DEPOT:
if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
/* Going to the nearest depot. */
SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
if (v->type == VEH_AIRCRAFT) {
SetDParam(2, STR_ORDER_NEAREST_HANGAR);
SetDParam(3, STR_EMPTY);
} else {
SetDParam(2, STR_ORDER_NEAREST_DEPOT);
SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type);
}
} else {
if (!(order->GetDepotActionType() & ODATFB_NEAREST_DEPOT)) {
/* Going to a specific depot. */
SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT);
SetDParam(2, v->type);
SetDParam(3, order->GetDestination());
}
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);
line = GetString(STR_ORDER_GO_TO_DEPOT_FORMAT, GetOrderGoToString(*order), v->type, order->GetDestination());
} else if (v->type == VEH_AIRCRAFT) {
/* Going to the nearest hangar. */
line = GetString(STR_ORDER_GO_TO_NEAREST_HANGAR_FORMAT, GetOrderGoToString(*order));
} else {
SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
/* Going to the nearest depot. */
line = GetString(STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT, GetOrderGoToString(*order), STR_ORDER_TRAIN_DEPOT + v->type);
}
/* Do not show stopping in the depot in the timetable window. */
if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
SetDParam(5, STR_ORDER_STOP_ORDER);
line += GetString(STR_ORDER_STOP_ORDER);
}
/* Do not show refitting in the depot in the timetable window. */
if (!timetable && order->IsRefit()) {
SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER);
SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name);
line += GetString((order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER, CargoSpec::Get(order->GetRefitCargo())->name);
}
/* Show unbunching depot in both order and timetable windows. */
if (order->GetDepotActionType() & ODATFB_UNBUNCH) {
SetDParam(8, STR_ORDER_WAIT_TO_UNBUNCH);
line += GetString(STR_ORDER_WAIT_TO_UNBUNCH);
}
break;
case OT_GOTO_WAYPOINT:
SetDParam(0, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT);
SetDParam(1, order->GetDestination());
line = GetString((order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT, order->GetDestination());
break;
case OT_CONDITIONAL:
SetDParam(1, order->GetConditionSkipToOrder() + 1);
if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
line = GetString(STR_ORDER_CONDITIONAL_UNCONDITIONAL, order->GetConditionSkipToOrder() + 1);
} else {
OrderConditionComparator occ = order->GetConditionComparator();
SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_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, v->type);
SetDParam(4, value);
line = GetString((occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM,
order->GetConditionSkipToOrder() + 1,
STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable(),
STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ,
value);
}
if (timetable && order->GetWaitTime() > 0) {
SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_AND_TRAVEL_FOR : STR_TIMETABLE_AND_TRAVEL_FOR_ESTIMATED);
SetTimetableParams(6, 7, order->GetWaitTime());
} else {
SetDParam(5, STR_EMPTY);
auto [str, value] = GetTimetableParameters(order->GetWaitTime());
line += GetString(order->IsWaitTimetabled() ? STR_TIMETABLE_AND_TRAVEL_FOR : STR_TIMETABLE_AND_TRAVEL_FOR_ESTIMATED, str, value);
}
break;
default: NOT_REACHED();
}
DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
/* Check range for aircraft. */
if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
const Order *next = order->next != nullptr ? order->next : v->GetFirstOrder();
if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) {
line += GetString(STR_ORDER_OUT_OF_RANGE);
}
}
DrawString(rtl ? left : middle, rtl ? middle : right, y, line, colour);
}
/**
@@ -1116,8 +1107,8 @@ public:
Rect ir = r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
bool rtl = _current_text_dir == TD_RTL;
SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + WidgetDimensions::scaled.hsep_normal;
uint64_t max_value = GetParamMaxValue(this->vehicle->GetNumOrders(), 2);
int index_column_width = GetStringBoundingBox(GetString(STR_ORDER_INDEX, max_value)).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + WidgetDimensions::scaled.hsep_normal;
int middle = rtl ? ir.right - index_column_width : ir.left + index_column_width;
int y = ir.top;