From 1c9f5da779323a67f3468ba97a7ab5585ade8983 Mon Sep 17 00:00:00 2001 From: Tyler Trahan Date: Thu, 1 Feb 2024 11:10:54 -0500 Subject: [PATCH] Add: Set and show unbunching behavior in order and vehicle GUIs --- src/lang/english.txt | 10 +++++--- src/order_cmd.cpp | 8 +++++++ src/order_gui.cpp | 48 +++++++++++++++++++++++++++----------- src/order_type.h | 1 + src/vehicle_gui.cpp | 6 ++++- src/widgets/order_widget.h | 3 ++- 6 files changed, 57 insertions(+), 19 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 3d5aa502a1..883caba627 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -4400,6 +4400,7 @@ STR_VEHICLE_VIEW_AIRCRAFT_STATUS_START_STOP_TOOLTIP :{BLACK}Current # Messages in the start stop button in the vehicle view STR_VEHICLE_STATUS_LOADING_UNLOADING :{LTBLUE}Loading / Unloading STR_VEHICLE_STATUS_LEAVING :{LTBLUE}Leaving +STR_VEHICLE_STATUS_WAITING_UNBUNCHING :{LTBLUE}Waiting to unbunch STR_VEHICLE_STATUS_CRASHED :{RED}Crashed! STR_VEHICLE_STATUS_BROKEN_DOWN :{RED}Broken down STR_VEHICLE_STATUS_STOPPED :{RED}Stopped @@ -4413,6 +4414,7 @@ STR_VEHICLE_STATUS_NO_ORDERS_VEL :{LTBLUE}No orde STR_VEHICLE_STATUS_HEADING_FOR_WAYPOINT_VEL :{LTBLUE}Heading for {WAYPOINT}, {VELOCITY} STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_VEL :{ORANGE}Heading for {DEPOT}, {VELOCITY} STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_SERVICE_VEL :{LTBLUE}Service at {DEPOT}, {VELOCITY} +STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_UNBUNCH_VEL :{LTBLUE}Unbunch and service at {DEPOT}, {VELOCITY} STR_VEHICLE_STATUS_CANNOT_REACH_STATION_VEL :{LTBLUE}Cannot reach {STATION}, {VELOCITY} STR_VEHICLE_STATUS_CANNOT_REACH_WAYPOINT_VEL :{LTBLUE}Cannot reach {WAYPOINT}, {VELOCITY} @@ -4543,7 +4545,7 @@ STR_ORDERS_TIMETABLE_VIEW_TOOLTIP :{BLACK}Switch t STR_ORDERS_LIST_TOOLTIP :{BLACK}Order list - click on an order to highlight it. Ctrl+Click to scroll to the order's destination STR_ORDER_INDEX :{COMMA}:{NBSP} -STR_ORDER_TEXT :{STRING4} {STRING2} {STRING} +STR_ORDER_TEXT :{STRING4} {STRING2} {STRING} {STRING} STR_ORDERS_END_OF_ORDERS :- - End of Orders - - STR_ORDERS_END_OF_SHARED_ORDERS :- - End of Shared Orders - - @@ -4577,11 +4579,11 @@ STR_ORDER_REFIT_AUTO_TOOLTIP :{BLACK}Select w STR_ORDER_DROP_REFIT_AUTO :Fixed cargo STR_ORDER_DROP_REFIT_AUTO_ANY :Available cargo -STR_ORDER_SERVICE :{BLACK}Service STR_ORDER_DROP_GO_ALWAYS_DEPOT :Always go STR_ORDER_DROP_SERVICE_DEPOT :Service if needed STR_ORDER_DROP_HALT_DEPOT :Stop -STR_ORDER_SERVICE_TOOLTIP :{BLACK}Skip this order unless a service is needed +STR_ORDER_DROP_UNBUNCH :Unbunch +STR_ORDER_DEPOT_ACTION_TOOLTIP :{BLACK}Select the action to take at this depot STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP :{BLACK}Vehicle data to base jumping on @@ -4650,6 +4652,8 @@ STR_ORDER_REFIT_ORDER :(Refit to {STRI STR_ORDER_REFIT_STOP_ORDER :(Refit to {STRING} and stop) STR_ORDER_STOP_ORDER :(Stop) +STR_ORDER_WAIT_TO_UNBUNCH :(wait to unbunch) + STR_ORDER_GO_TO_STATION :{STRING} {STATION} {STRING1} STR_ORDER_GO_TO_STATION_CAN_T_USE_STATION :{PUSH_COLOUR}{RED}(Can't use station){POP_COLOUR} {STRING} {STATION} {STRING1} diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 914e52de66..7e434f49a5 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1361,6 +1361,7 @@ CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se case DA_ALWAYS_GO: order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE)); order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT)); + order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_UNBUNCH)); break; case DA_SERVICE: @@ -1371,10 +1372,17 @@ CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se case DA_STOP: order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE)); + order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_UNBUNCH)); order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() | ODATFB_HALT)); order->SetRefit(CARGO_NO_REFIT); break; + case DA_UNBUNCH: + order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE)); + order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT)); + order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() | ODATFB_UNBUNCH)); + break; + default: NOT_REACHED(); } diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 62780c4850..0342b0deef 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -184,6 +184,7 @@ static const StringID _order_depot_action_dropdown[] = { STR_ORDER_DROP_GO_ALWAYS_DEPOT, STR_ORDER_DROP_SERVICE_DEPOT, STR_ORDER_DROP_HALT_DEPOT, + STR_ORDER_DROP_UNBUNCH, INVALID_STRING_ID }; @@ -243,11 +244,12 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int 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(8, STR_ORDER_OUT_OF_RANGE); + if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) SetDParam(9, STR_ORDER_OUT_OF_RANGE); } switch (order->GetType()) { @@ -332,6 +334,12 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER); SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name); } + + /* Do not show unbunching in the depot in the timetable window. */ + if (!timetable && (order->GetDepotActionType() & ODATFB_UNBUNCH)) { + SetDParam(8, STR_ORDER_WAIT_TO_UNBUNCH); + } + break; case OT_GOTO_WAYPOINT: @@ -941,7 +949,6 @@ public: /* First row. */ this->RaiseWidget(WID_O_FULL_LOAD); this->RaiseWidget(WID_O_UNLOAD); - this->RaiseWidget(WID_O_SERVICE); /* Selection widgets. */ /* Train or road vehicle. */ @@ -1027,7 +1034,6 @@ public: this->SetWidgetDisabledState(WID_O_REFIT, (order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT) || (!this->can_do_refit && !order->IsRefit())); - this->SetWidgetLoweredState(WID_O_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE); break; case OT_CONDITIONAL: { @@ -1155,6 +1161,24 @@ public: case WID_O_CAPTION: SetDParam(0, this->vehicle->index); break; + + case WID_O_DEPOT_ACTION: { + VehicleOrderID sel = this->OrderGetSel(); + const Order *order = this->vehicle->GetOrder(sel); + if (order == nullptr || !order->IsType(OT_GOTO_DEPOT)) break; + + /* Select the current action selected in the dropdown. The flags don't match the dropdown so we can't just use an index. */ + if (order->GetDepotOrderType() & ODTFB_SERVICE) { + SetDParam(0, STR_ORDER_DROP_SERVICE_DEPOT); + } else if (order->GetDepotActionType() & ODATFB_HALT) { + SetDParam(0, STR_ORDER_DROP_HALT_DEPOT); + } else if (order->GetDepotActionType() & ODATFB_UNBUNCH) { + SetDParam(0, STR_ORDER_DROP_UNBUNCH); + } else { + SetDParam(0, STR_ORDER_DROP_GO_ALWAYS_DEPOT); + } + break; + } } } @@ -1273,12 +1297,8 @@ public: this->OrderClick_Refit(0, false); break; - case WID_O_SERVICE: - if (this->GetWidget(widget)->ButtonHit(pt)) { - this->OrderClick_Service(-1); - } else { - ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_SERVICE, 0, 0); - } + case WID_O_DEPOT_ACTION: + ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_DEPOT_ACTION, 0, 0); break; case WID_O_REFIT_DROPDOWN: @@ -1373,7 +1393,7 @@ public: } break; - case WID_O_SERVICE: + case WID_O_DEPOT_ACTION: this->OrderClick_Service(index); break; @@ -1593,8 +1613,8 @@ static constexpr NWidgetPart _nested_orders_train_widgets[] = { NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_MIDDLE), NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(93, 12), SetFill(1, 0), SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0), - NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(93, 12), SetFill(1, 0), - SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0), + NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_DEPOT_ACTION), SetMinimalSize(93, 12), SetFill(1, 0), + SetDataTip(STR_JUST_STRING, STR_ORDER_DEPOT_ACTION_TOOLTIP), SetResize(1, 0), EndContainer(), NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_RIGHT), NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(93, 12), SetFill(1, 0), SetResize(1, 0), EndContainer(), @@ -1671,8 +1691,8 @@ static constexpr NWidgetPart _nested_orders_widgets[] = { NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(186, 12), SetFill(1, 0), SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0), - NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0), - SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0), + NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_DEPOT_ACTION), SetMinimalSize(124, 12), SetFill(1, 0), + SetDataTip(STR_JUST_STRING, STR_ORDER_DEPOT_ACTION_TOOLTIP), SetResize(1, 0), EndContainer(), /* Buttons for setting a condition. */ diff --git a/src/order_type.h b/src/order_type.h index b9963704c8..99a2467d26 100644 --- a/src/order_type.h +++ b/src/order_type.h @@ -161,6 +161,7 @@ enum OrderDepotAction { DA_ALWAYS_GO, ///< Always go to the depot DA_SERVICE, ///< Service only if needed DA_STOP, ///< Go to the depot and stop there + DA_UNBUNCH, ///< Go to the depot and unbunch DA_END }; diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index de0a11f11d..6c066e787f 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -3087,7 +3087,7 @@ public: { if (widget != WID_VV_START_STOP) return; - const Vehicle *v = Vehicle::Get(this->window_number); + Vehicle *v = Vehicle::Get(this->window_number); StringID str; TextColour text_colour = TC_FROMSTRING; if (v->vehstatus & VS_CRASHED) { @@ -3113,6 +3113,8 @@ public: str = STR_VEHICLE_STATUS_TRAIN_STUCK; } else if (v->type == VEH_AIRCRAFT && HasBit(Aircraft::From(v)->flags, VAF_DEST_TOO_FAR) && !v->current_order.IsType(OT_LOADING)) { str = STR_VEHICLE_STATUS_AIRCRAFT_TOO_FAR; + } else if (v->IsInDepot() && v->IsWaitingForUnbunching()) { + str = STR_VEHICLE_STATUS_WAITING_UNBUNCHING; } else { // vehicle is in a "normal" state, show current order if (mouse_over_start_stop) { if (v->vehstatus & VS_STOPPED) { @@ -3143,6 +3145,8 @@ public: str = STR_EMPTY; } else if (v->current_order.GetDepotActionType() & ODATFB_HALT) { str = HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_VEL; + } else if (v->current_order.GetDepotActionType() & ODATFB_UNBUNCH) { + str = HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_SERVICE_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_UNBUNCH_VEL; } else { str = HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_SERVICE_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_SERVICE_VEL; } diff --git a/src/widgets/order_widget.h b/src/widgets/order_widget.h index 1a427ab4d5..b0399ebda6 100644 --- a/src/widgets/order_widget.h +++ b/src/widgets/order_widget.h @@ -20,11 +20,12 @@ enum OrderWidgets : WidgetID { WID_O_DELETE, ///< Delete selected order. WID_O_STOP_SHARING, ///< Stop sharing orders. WID_O_NON_STOP, ///< Goto non-stop to destination. + WID_O_DEPOT_UNBUNCHING, ///< Toggle unbunching. WID_O_GOTO, ///< Goto destination. WID_O_FULL_LOAD, ///< Select full load. WID_O_UNLOAD, ///< Select unload. WID_O_REFIT, ///< Select refit. - WID_O_SERVICE, ///< Select service (at depot). + WID_O_DEPOT_ACTION, ///< Dropdown to select the depot action (stop, service if needed, unbunch). WID_O_REFIT_DROPDOWN, ///< Open refit options. WID_O_COND_VARIABLE, ///< Choose condition variable. WID_O_COND_COMPARATOR, ///< Choose condition type.