2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file order_gui.cpp GUI related to orders. */
11 #include "command_func.h"
12 #include "viewport_func.h"
13 #include "depot_map.h"
15 #include "timetable.h"
16 #include "strings_func.h"
17 #include "company_func.h"
18 #include "dropdown_type.h"
19 #include "dropdown_func.h"
20 #include "textbuf_gui.h"
21 #include "string_func.h"
22 #include "tilehighlight_func.h"
23 #include "network/network.h"
24 #include "station_base.h"
26 #include "waypoint_base.h"
27 #include "core/geometry_func.hpp"
30 #include "engine_func.h"
31 #include "vehicle_func.h"
32 #include "vehiclelist.h"
33 #include "vehicle_func.h"
35 #include "order_cmd.h"
36 #include "company_cmd.h"
38 #include "widgets/order_widget.h"
40 #include "safeguards.h"
43 /** Order load types that could be given to station orders. */
44 static const StringID _station_load_types
[][5][5] = {
51 STR_ORDER_FULL_LOAD_ANY
,
56 STR_ORDER_UNLOAD_FULL_LOAD
,
57 STR_ORDER_UNLOAD_FULL_LOAD_ANY
,
58 STR_ORDER_UNLOAD_NO_LOAD
,
62 STR_ORDER_TRANSFER_FULL_LOAD
,
63 STR_ORDER_TRANSFER_FULL_LOAD_ANY
,
64 STR_ORDER_TRANSFER_NO_LOAD
,
66 /* Unload and transfer do not work together. */
74 STR_ORDER_NO_UNLOAD_FULL_LOAD
,
75 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY
,
76 STR_ORDER_NO_UNLOAD_NO_LOAD
,
79 /* With auto-refitting. No loading and auto-refitting do not work together. */
83 STR_ORDER_FULL_LOAD_REFIT
,
84 STR_ORDER_FULL_LOAD_ANY_REFIT
,
87 STR_ORDER_UNLOAD_REFIT
,
89 STR_ORDER_UNLOAD_FULL_LOAD_REFIT
,
90 STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT
,
93 STR_ORDER_TRANSFER_REFIT
,
95 STR_ORDER_TRANSFER_FULL_LOAD_REFIT
,
96 STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT
,
99 /* Unload and transfer do not work together. */
105 STR_ORDER_NO_UNLOAD_REFIT
,
107 STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT
,
108 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT
,
114 static const StringID _order_non_stop_drowdown
[] = {
116 STR_ORDER_GO_NON_STOP_TO
,
118 STR_ORDER_GO_NON_STOP_VIA
,
121 static const StringID _order_full_load_drowdown
[] = {
122 STR_ORDER_DROP_LOAD_IF_POSSIBLE
,
124 STR_ORDER_DROP_FULL_LOAD_ALL
,
125 STR_ORDER_DROP_FULL_LOAD_ANY
,
126 STR_ORDER_DROP_NO_LOADING
,
129 static const StringID _order_unload_drowdown
[] = {
130 STR_ORDER_DROP_UNLOAD_IF_ACCEPTED
,
131 STR_ORDER_DROP_UNLOAD
,
132 STR_ORDER_DROP_TRANSFER
,
134 STR_ORDER_DROP_NO_UNLOADING
,
137 static const StringID _order_goto_dropdown
[] = {
139 STR_ORDER_GO_TO_NEAREST_DEPOT
,
140 STR_ORDER_CONDITIONAL
,
144 static const StringID _order_goto_dropdown_aircraft
[] = {
146 STR_ORDER_GO_TO_NEAREST_HANGAR
,
147 STR_ORDER_CONDITIONAL
,
151 /** Variables for conditional orders; this defines the order of appearance in the dropdown box */
152 static const OrderConditionVariable _order_conditional_variable
[] = {
158 OCV_REMAINING_LIFETIME
,
159 OCV_REQUIRES_SERVICE
,
163 static const StringID _order_conditional_condition
[] = {
164 STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS
,
165 STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS
,
166 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN
,
167 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS
,
168 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN
,
169 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS
,
170 STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE
,
171 STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE
,
174 extern uint
ConvertSpeedToDisplaySpeed(uint speed
, VehicleType type
);
175 extern uint
ConvertDisplaySpeedToSpeed(uint speed
, VehicleType type
);
177 static const StringID _order_depot_action_dropdown
[] = {
178 STR_ORDER_DROP_GO_ALWAYS_DEPOT
,
179 STR_ORDER_DROP_SERVICE_DEPOT
,
180 STR_ORDER_DROP_HALT_DEPOT
,
181 STR_ORDER_DROP_UNBUNCH
,
184 static int DepotActionStringIndex(const Order
*order
)
186 if (order
->GetDepotActionType() & ODATFB_HALT
) {
188 } else if (order
->GetDepotOrderType() & ODTFB_SERVICE
) {
190 } else if (order
->GetDepotActionType() & ODATFB_UNBUNCH
) {
197 static const StringID _order_refit_action_dropdown
[] = {
198 STR_ORDER_DROP_REFIT_AUTO
,
199 STR_ORDER_DROP_REFIT_AUTO_ANY
,
203 * Draws an order in order or timetable GUI
204 * @param v Vehicle the order belongs to
205 * @param order The order to draw
206 * @param order_index Index of the order in the orders of the vehicle
207 * @param y Y position for drawing
208 * @param selected True, if the order is selected
209 * @param timetable True, when drawing in the timetable GUI
210 * @param left Left border for text drawing
211 * @param middle X position between order index and order text
212 * @param right Right border for text drawing
214 void DrawOrderString(const Vehicle
*v
, const Order
*order
, int order_index
, int y
, bool selected
, bool timetable
, int left
, int middle
, int right
)
216 bool rtl
= _current_text_dir
== TD_RTL
;
218 SpriteID sprite
= rtl
? SPR_ARROW_LEFT
: SPR_ARROW_RIGHT
;
219 Dimension sprite_size
= GetSpriteSize(sprite
);
220 if (v
->cur_real_order_index
== order_index
) {
221 /* Draw two arrows before the next real order. */
222 DrawSprite(sprite
, PAL_NONE
, rtl
? right
- sprite_size
.width
: left
, y
+ ((int)GetCharacterHeight(FS_NORMAL
) - (int)sprite_size
.height
) / 2);
223 DrawSprite(sprite
, PAL_NONE
, rtl
? right
- 2 * sprite_size
.width
: left
+ sprite_size
.width
, y
+ ((int)GetCharacterHeight(FS_NORMAL
) - (int)sprite_size
.height
) / 2);
224 } else if (v
->cur_implicit_order_index
== order_index
) {
225 /* Draw one arrow before the next implicit order; the next real order will still get two arrows. */
226 DrawSprite(sprite
, PAL_NONE
, rtl
? right
- sprite_size
.width
: left
, y
+ ((int)GetCharacterHeight(FS_NORMAL
) - (int)sprite_size
.height
) / 2);
229 TextColour colour
= TC_BLACK
;
230 if (order
->IsType(OT_IMPLICIT
)) {
231 colour
= (selected
? TC_SILVER
: TC_GREY
) | TC_NO_SHADE
;
232 } else if (selected
) {
236 SetDParam(0, order_index
+ 1);
237 DrawString(left
, rtl
? right
- 2 * sprite_size
.width
- 3 : middle
, y
, STR_ORDER_INDEX
, colour
, SA_RIGHT
| SA_FORCE
);
239 SetDParam(5, STR_EMPTY
);
240 SetDParam(8, STR_EMPTY
);
241 SetDParam(9, STR_EMPTY
);
243 /* Check range for aircraft. */
244 if (v
->type
== VEH_AIRCRAFT
&& Aircraft::From(v
)->GetRange() > 0 && order
->IsGotoOrder()) {
245 const Order
*next
= order
->next
!= nullptr ? order
->next
: v
->GetFirstOrder();
246 if (GetOrderDistance(order
, next
, v
) > Aircraft::From(v
)->acache
.cached_max_range_sqr
) SetDParam(9, STR_ORDER_OUT_OF_RANGE
);
249 switch (order
->GetType()) {
251 SetDParam(0, STR_INVALID_ORDER
);
252 SetDParam(1, order
->GetDestination());
256 SetDParam(0, STR_ORDER_GO_TO_STATION
);
257 SetDParam(1, STR_ORDER_GO_TO
);
258 SetDParam(2, order
->GetDestination());
259 SetDParam(3, timetable
? STR_EMPTY
: STR_ORDER_IMPLICIT
);
262 case OT_GOTO_STATION
: {
263 OrderLoadFlags load
= order
->GetLoadType();
264 OrderUnloadFlags unload
= order
->GetUnloadType();
265 bool valid_station
= CanVehicleUseStation(v
, Station::Get(order
->GetDestination()));
267 SetDParam(0, valid_station
? STR_ORDER_GO_TO_STATION
: STR_ORDER_GO_TO_STATION_CAN_T_USE_STATION
);
268 SetDParam(1, STR_ORDER_GO_TO
+ (v
->IsGroundVehicle() ? order
->GetNonStopType() : 0));
269 SetDParam(2, order
->GetDestination());
272 /* Show only wait time in the timetable window. */
273 SetDParam(3, STR_EMPTY
);
275 if (order
->GetWaitTime() > 0) {
276 SetDParam(5, order
->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR
: STR_TIMETABLE_STAY_FOR_ESTIMATED
);
277 SetTimetableParams(6, 7, order
->GetWaitTime());
280 /* Show non-stop, refit and stop location only in the order window. */
281 SetDParam(3, (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) ? STR_EMPTY
: _station_load_types
[order
->IsRefit()][unload
][load
]);
282 if (order
->IsRefit()) {
283 SetDParam(4, order
->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY
: CargoSpec::Get(order
->GetRefitCargo())->name
);
285 if (v
->type
== VEH_TRAIN
&& (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) == 0) {
286 /* Only show the stopping location if other than the default chosen by the player. */
287 if (order
->GetStopLocation() != (OrderStopLocation
)(_settings_client
.gui
.stop_location
)) {
288 SetDParam(5, order
->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END
);
290 SetDParam(5, STR_EMPTY
);
298 if (order
->GetDepotActionType() & ODATFB_NEAREST_DEPOT
) {
299 /* Going to the nearest depot. */
300 SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT
);
301 if (v
->type
== VEH_AIRCRAFT
) {
302 SetDParam(2, STR_ORDER_NEAREST_HANGAR
);
303 SetDParam(3, STR_EMPTY
);
305 SetDParam(2, STR_ORDER_NEAREST_DEPOT
);
306 SetDParam(3, STR_ORDER_TRAIN_DEPOT
+ v
->type
);
309 /* Going to a specific depot. */
310 SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT
);
311 SetDParam(2, v
->type
);
312 SetDParam(3, order
->GetDestination());
315 if (order
->GetDepotOrderType() & ODTFB_SERVICE
) {
316 SetDParam(1, (order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
) ? STR_ORDER_SERVICE_NON_STOP_AT
: STR_ORDER_SERVICE_AT
);
318 SetDParam(1, (order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
) ? STR_ORDER_GO_NON_STOP_TO
: STR_ORDER_GO_TO
);
321 /* Do not show stopping in the depot in the timetable window. */
322 if (!timetable
&& (order
->GetDepotActionType() & ODATFB_HALT
)) {
323 SetDParam(5, STR_ORDER_STOP_ORDER
);
326 /* Do not show refitting in the depot in the timetable window. */
327 if (!timetable
&& order
->IsRefit()) {
328 SetDParam(5, (order
->GetDepotActionType() & ODATFB_HALT
) ? STR_ORDER_REFIT_STOP_ORDER
: STR_ORDER_REFIT_ORDER
);
329 SetDParam(6, CargoSpec::Get(order
->GetRefitCargo())->name
);
332 /* Show unbunching depot in both order and timetable windows. */
333 if (order
->GetDepotActionType() & ODATFB_UNBUNCH
) {
334 SetDParam(8, STR_ORDER_WAIT_TO_UNBUNCH
);
339 case OT_GOTO_WAYPOINT
:
340 SetDParam(0, (order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT
: STR_ORDER_GO_TO_WAYPOINT
);
341 SetDParam(1, order
->GetDestination());
345 SetDParam(1, order
->GetConditionSkipToOrder() + 1);
346 if (order
->GetConditionVariable() == OCV_UNCONDITIONALLY
) {
347 SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL
);
349 OrderConditionComparator occ
= order
->GetConditionComparator();
350 SetDParam(0, (occ
== OCC_IS_TRUE
|| occ
== OCC_IS_FALSE
) ? STR_ORDER_CONDITIONAL_TRUE_FALSE
: STR_ORDER_CONDITIONAL_NUM
);
351 SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE
+ order
->GetConditionVariable());
352 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS
+ occ
);
354 uint value
= order
->GetConditionValue();
355 if (order
->GetConditionVariable() == OCV_MAX_SPEED
) value
= ConvertSpeedToDisplaySpeed(value
, v
->type
);
359 if (timetable
&& order
->GetWaitTime() > 0) {
360 SetDParam(5, order
->IsWaitTimetabled() ? STR_TIMETABLE_AND_TRAVEL_FOR
: STR_TIMETABLE_AND_TRAVEL_FOR_ESTIMATED
);
361 SetTimetableParams(6, 7, order
->GetWaitTime());
363 SetDParam(5, STR_EMPTY
);
367 default: NOT_REACHED();
370 DrawString(rtl
? left
: middle
, rtl
? middle
: right
, y
, STR_ORDER_TEXT
, colour
);
374 * Get the order command a vehicle can do in a given tile.
375 * @param v Vehicle involved.
376 * @param tile Tile being queried.
377 * @return The order associated to vehicle v in given tile (or empty order if vehicle can do nothing in the tile).
379 static Order
GetOrderCmdFromTile(const Vehicle
*v
, TileIndex tile
)
381 /* Override the index as it is not coming from a pool, so would not be initialised correctly. */
385 /* check depot first */
386 if (IsDepotTypeTile(tile
, (TransportType
)(uint
)v
->type
) && IsTileOwner(tile
, _local_company
)) {
387 order
.MakeGoToDepot(v
->type
== VEH_AIRCRAFT
? GetStationIndex(tile
) : GetDepotIndex(tile
),
388 ODTFB_PART_OF_ORDERS
,
389 (_settings_client
.gui
.new_nonstop
&& v
->IsGroundVehicle()) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
: ONSF_STOP_EVERYWHERE
);
392 /* Check to see if we are allowed to make this an unbunching order. */
394 if (v
->HasFullLoadOrder()) {
395 /* We don't allow unbunching if the vehicle has a full load order. */
396 ShowErrorMessage(STR_ERROR_CAN_T_INSERT_NEW_ORDER
, STR_ERROR_UNBUNCHING_NO_UNBUNCHING_FULL_LOAD
, WL_INFO
);
398 } else if (v
->HasUnbunchingOrder()) {
399 /* Don't allow a new unbunching order if we already have one. */
400 ShowErrorMessage(STR_ERROR_CAN_T_INSERT_NEW_ORDER
, STR_ERROR_UNBUNCHING_ONLY_ONE_ALLOWED
, WL_INFO
);
402 } else if (v
->HasConditionalOrder()) {
403 /* We don't allow unbunching if the vehicle has a conditional order. */
404 ShowErrorMessage(STR_ERROR_CAN_T_INSERT_NEW_ORDER
, STR_ERROR_UNBUNCHING_NO_UNBUNCHING_CONDITIONAL
, WL_INFO
);
408 /* Return an empty order to bail out. */
414 /* Now we are allowed to set the action type. */
415 order
.SetDepotActionType(ODATFB_UNBUNCH
);
421 /* check rail waypoint */
422 if (IsRailWaypointTile(tile
) &&
423 v
->type
== VEH_TRAIN
&&
424 IsTileOwner(tile
, _local_company
)) {
425 order
.MakeGoToWaypoint(GetStationIndex(tile
));
426 if (_settings_client
.gui
.new_nonstop
!= _ctrl_pressed
) order
.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION
);
430 /* check road waypoint */
431 if (IsRoadWaypointTile(tile
) &&
432 v
->type
== VEH_ROAD
&&
433 IsTileOwner(tile
, _local_company
)) {
434 order
.MakeGoToWaypoint(GetStationIndex(tile
));
435 if (_settings_client
.gui
.new_nonstop
!= _ctrl_pressed
) order
.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION
);
439 /* check buoy (no ownership) */
440 if (IsBuoyTile(tile
) && v
->type
== VEH_SHIP
) {
441 order
.MakeGoToWaypoint(GetStationIndex(tile
));
445 /* check for station or industry with neutral station */
446 if (IsTileType(tile
, MP_STATION
) || IsTileType(tile
, MP_INDUSTRY
)) {
447 const Station
*st
= nullptr;
449 if (IsTileType(tile
, MP_STATION
)) {
450 st
= Station::GetByTile(tile
);
452 const Industry
*in
= Industry::GetByTile(tile
);
453 st
= in
->neutral_station
;
455 if (st
!= nullptr && (st
->owner
== _local_company
|| st
->owner
== OWNER_NONE
)) {
458 case VEH_SHIP
: facil
= FACIL_DOCK
; break;
459 case VEH_TRAIN
: facil
= FACIL_TRAIN
; break;
460 case VEH_AIRCRAFT
: facil
= FACIL_AIRPORT
; break;
461 case VEH_ROAD
: facil
= FACIL_BUS_STOP
| FACIL_TRUCK_STOP
; break;
462 default: NOT_REACHED();
464 if (st
->facilities
& facil
) {
465 order
.MakeGoToStation(st
->index
);
466 if (_ctrl_pressed
) order
.SetLoadType(OLF_FULL_LOAD_ANY
);
467 if (_settings_client
.gui
.new_nonstop
&& v
->IsGroundVehicle()) order
.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
);
468 order
.SetStopLocation(v
->type
== VEH_TRAIN
? (OrderStopLocation
)(_settings_client
.gui
.stop_location
) : OSL_PLATFORM_FAR_END
);
479 /** Hotkeys for order window. */
495 * %Order window code for all vehicles.
497 * At the bottom of the window two button rows are located for changing the orders of the vehicle.
499 * \section top-row Top row
500 * The top-row is for manipulating an individual order. What row is displayed depends on the type of vehicle, and whether or not you are the owner of the vehicle.
502 * The top-row buttons of one of your trains or road vehicles is one of the following three cases:
504 * +-----------------+-----------------+-----------------+-----------------+
505 * | NON-STOP | FULL_LOAD | UNLOAD | REFIT | (normal)
506 * +-----------------+-----+-----------+-----------+-----+-----------------+
507 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
508 * +-----------------+-----+-----------+-----------+-----+-----------------+
509 * | NON-STOP | REFIT | SERVICE | (empty) | (for depot orders)
510 * +-----------------+-----------------+-----------------+-----------------+
513 * Airplanes and ships have one of the following three top-row button rows:
515 * +-----------------+-----------------+-----------------+
516 * | FULL_LOAD | UNLOAD | REFIT | (normal)
517 * +-----------------+-----------------+-----------------+
518 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
519 * +-----------------+--------+--------+-----------------+
520 * | REFIT | SERVICE | (for depot order)
521 * +--------------------------+--------------------------+
524 * \section bottom-row Bottom row
525 * The second row (the bottom row) is for manipulating the list of orders:
527 * +-----------------+-----------------+-----------------+
528 * | SKIP | DELETE | GOTO |
529 * +-----------------+-----------------+-----------------+
532 * For vehicles of other companies, both button rows are not displayed.
534 struct OrdersWindow
: public Window
{
536 /** Under what reason are we using the PlaceObject functionality? */
537 enum OrderPlaceObjectState
{
545 /** Displayed planes of the #NWID_SELECTION widgets. */
547 /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
548 DP_GROUNDVEHICLE_ROW_NORMAL
= 0, ///< Display the row for normal/depot orders in the top row of the train/rv order window.
549 DP_GROUNDVEHICLE_ROW_CONDITIONAL
= 1, ///< Display the row for conditional orders in the top row of the train/rv order window.
551 /* WID_O_SEL_TOP_LEFT */
552 DP_LEFT_LOAD
= 0, ///< Display 'load' in the left button of the top row of the train/rv order window.
553 DP_LEFT_REFIT
= 1, ///< Display 'refit' in the left button of the top row of the train/rv order window.
555 /* WID_O_SEL_TOP_MIDDLE */
556 DP_MIDDLE_UNLOAD
= 0, ///< Display 'unload' in the middle button of the top row of the train/rv order window.
557 DP_MIDDLE_SERVICE
= 1, ///< Display 'service' in the middle button of the top row of the train/rv order window.
559 /* WID_O_SEL_TOP_RIGHT */
560 DP_RIGHT_EMPTY
= 0, ///< Display an empty panel in the right button of the top row of the train/rv order window.
561 DP_RIGHT_REFIT
= 1, ///< Display 'refit' in the right button of the top row of the train/rv order window.
563 /* WID_O_SEL_TOP_ROW */
564 DP_ROW_LOAD
= 0, ///< Display 'load' / 'unload' / 'refit' buttons in the top row of the ship/airplane order window.
565 DP_ROW_DEPOT
= 1, ///< Display 'refit' / 'service' buttons in the top row of the ship/airplane order window.
566 DP_ROW_CONDITIONAL
= 2, ///< Display the conditional order buttons in the top row of the ship/airplane order window.
568 /* WID_O_SEL_BOTTOM_MIDDLE */
569 DP_BOTTOM_MIDDLE_DELETE
= 0, ///< Display 'delete' in the middle button of the bottom row of the vehicle order window.
570 DP_BOTTOM_MIDDLE_STOP_SHARING
= 1, ///< Display 'stop sharing' in the middle button of the bottom row of the vehicle order window.
574 VehicleOrderID order_over
; ///< Order over which another order is dragged, \c INVALID_VEH_ORDER_ID if none.
575 OrderPlaceObjectState goto_type
;
576 const Vehicle
*vehicle
; ///< Vehicle owning the orders being displayed and manipulated.
578 bool can_do_refit
; ///< Vehicle chain can be refitted in depot.
579 bool can_do_autorefit
; ///< Vehicle chain can be auto-refitted.
582 * Return the memorised selected order.
583 * @return the memorised order if it is a valid one
584 * else return the number of orders
586 VehicleOrderID
OrderGetSel() const
588 int num
= this->selected_order
;
589 return (num
>= 0 && num
< vehicle
->GetNumOrders()) ? num
: vehicle
->GetNumOrders();
593 * Calculate the selected order.
594 * The calculation is based on the relative (to the window) y click position and
595 * the position of the scrollbar.
597 * @param y Y-value of the click relative to the window origin
598 * @return The selected order if the order is valid, else return \c INVALID_VEH_ORDER_ID.
600 VehicleOrderID
GetOrderFromPt(int y
)
602 int32_t sel
= this->vscroll
->GetScrolledRowFromWidget(y
, this, WID_O_ORDER_LIST
, WidgetDimensions::scaled
.framerect
.top
);
603 if (sel
== INT32_MAX
) return INVALID_VEH_ORDER_ID
;
604 /* One past the orders is the 'End of Orders' line. */
605 assert(IsInsideBS(sel
, 0, vehicle
->GetNumOrders() + 1));
610 * Handle the click on the goto button.
612 void OrderClick_Goto(OrderPlaceObjectState type
)
614 assert(type
> OPOS_NONE
&& type
< OPOS_END
);
616 static const HighLightStyle goto_place_style
[OPOS_END
- 1] = {
617 HT_RECT
| HT_VEHICLE
, // OPOS_GOTO
618 HT_NONE
, // OPOS_CONDITIONAL
619 HT_VEHICLE
, // OPOS_SHARE
621 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION
, PAL_NONE
, goto_place_style
[type
- 1], this);
622 this->goto_type
= type
;
623 this->SetWidgetDirty(WID_O_GOTO
);
627 * Handle the click on the full load button.
628 * @param load_type Load flag to apply. If matches existing load type, toggles to default of 'load if possible'.
629 * @param toggle If we toggle or not (used for hotkey behavior)
631 void OrderClick_FullLoad(OrderLoadFlags load_type
, bool toggle
= false)
633 VehicleOrderID sel_ord
= this->OrderGetSel();
634 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
636 if (order
== nullptr) return;
638 if (toggle
&& order
->GetLoadType() == load_type
) {
639 load_type
= OLF_LOAD_IF_POSSIBLE
; // reset to 'default'
641 if (order
->GetLoadType() == load_type
) return; // If we still match, do nothing
643 Command
<CMD_MODIFY_ORDER
>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
, this->vehicle
->tile
, this->vehicle
->index
, sel_ord
, MOF_LOAD
, load_type
);
647 * Handle the click on the service.
649 void OrderClick_Service(int i
)
651 VehicleOrderID sel_ord
= this->OrderGetSel();
654 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
655 if (order
== nullptr) return;
656 i
= (order
->GetDepotOrderType() & ODTFB_SERVICE
) ? DA_ALWAYS_GO
: DA_SERVICE
;
658 Command
<CMD_MODIFY_ORDER
>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
, this->vehicle
->tile
, this->vehicle
->index
, sel_ord
, MOF_DEPOT_ACTION
, i
);
662 * Handle the click on the service in nearest depot button.
664 void OrderClick_NearestDepot()
667 order
.next
= nullptr;
669 order
.MakeGoToDepot(INVALID_DEPOT
, ODTFB_PART_OF_ORDERS
,
670 _settings_client
.gui
.new_nonstop
&& this->vehicle
->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
: ONSF_STOP_EVERYWHERE
);
671 order
.SetDepotActionType(ODATFB_NEAREST_DEPOT
);
673 Command
<CMD_INSERT_ORDER
>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER
, this->vehicle
->tile
, this->vehicle
->index
, this->OrderGetSel(), order
);
677 * Handle the click on the unload button.
678 * @param unload_type Unload flag to apply. If matches existing unload type, toggles to default of 'unload if possible'.
679 * @param toggle If we toggle or not (used for hotkey behavior)
681 void OrderClick_Unload(OrderUnloadFlags unload_type
, bool toggle
= false)
683 VehicleOrderID sel_ord
= this->OrderGetSel();
684 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
686 if (order
== nullptr) return;
688 if (toggle
&& order
->GetUnloadType() == unload_type
) {
689 unload_type
= OUF_UNLOAD_IF_POSSIBLE
;
691 if (order
->GetUnloadType() == unload_type
) return; // If we still match, do nothing
693 Command
<CMD_MODIFY_ORDER
>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
, this->vehicle
->tile
, this->vehicle
->index
, sel_ord
, MOF_UNLOAD
, unload_type
);
695 /* Transfer and unload orders with leave empty as default */
696 if (unload_type
== OUFB_TRANSFER
|| unload_type
== OUFB_UNLOAD
) {
697 Command
<CMD_MODIFY_ORDER
>::Post(this->vehicle
->tile
, this->vehicle
->index
, sel_ord
, MOF_LOAD
, OLFB_NO_LOAD
);
698 this->SetWidgetDirty(WID_O_FULL_LOAD
);
703 * Handle the click on the nonstop button.
704 * @param non_stop what non-stop type to use; -1 to use the 'next' one.
706 void OrderClick_Nonstop(int non_stop
)
708 if (!this->vehicle
->IsGroundVehicle()) return;
710 VehicleOrderID sel_ord
= this->OrderGetSel();
711 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
713 if (order
== nullptr || order
->GetNonStopType() == non_stop
) return;
715 /* Keypress if negative, so 'toggle' to the next */
717 non_stop
= order
->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
;
720 this->SetWidgetDirty(WID_O_NON_STOP
);
721 Command
<CMD_MODIFY_ORDER
>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
, this->vehicle
->tile
, this->vehicle
->index
, sel_ord
, MOF_NON_STOP
, non_stop
);
725 * Handle the click on the skip button.
726 * If ctrl is pressed, skip to selected order, else skip to current order + 1
728 void OrderClick_Skip()
730 /* Don't skip when there's nothing to skip */
731 if (_ctrl_pressed
&& this->vehicle
->cur_implicit_order_index
== this->OrderGetSel()) return;
732 if (this->vehicle
->GetNumOrders() <= 1) return;
734 Command
<CMD_SKIP_TO_ORDER
>::Post(_ctrl_pressed
? STR_ERROR_CAN_T_SKIP_TO_ORDER
: STR_ERROR_CAN_T_SKIP_ORDER
,
735 this->vehicle
->tile
, this->vehicle
->index
, _ctrl_pressed
? this->OrderGetSel() : ((this->vehicle
->cur_implicit_order_index
+ 1) % this->vehicle
->GetNumOrders()));
739 * Handle the click on the delete button.
741 void OrderClick_Delete()
743 /* When networking, move one order lower */
744 int selected
= this->selected_order
+ (int)_networking
;
746 if (Command
<CMD_DELETE_ORDER
>::Post(STR_ERROR_CAN_T_DELETE_THIS_ORDER
, this->vehicle
->tile
, this->vehicle
->index
, this->OrderGetSel())) {
747 this->selected_order
= selected
>= this->vehicle
->GetNumOrders() ? -1 : selected
;
748 this->UpdateButtonState();
753 * Handle the click on the 'stop sharing' button.
754 * If 'End of Shared Orders' isn't selected, do nothing. If Ctrl is pressed, call OrderClick_Delete and exit.
755 * To stop sharing this vehicle order list, we copy the orders of a vehicle that share this order list. That way we
756 * exit the group of shared vehicles while keeping the same order list.
758 void OrderClick_StopSharing()
760 /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
761 if (!this->vehicle
->IsOrderListShared() || this->selected_order
!= this->vehicle
->GetNumOrders()) return;
762 /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
764 this->OrderClick_Delete();
768 /* Get another vehicle that share orders with this vehicle. */
769 Vehicle
*other_shared
= (this->vehicle
->FirstShared() == this->vehicle
) ? this->vehicle
->NextShared() : this->vehicle
->PreviousShared();
770 /* Copy the order list of the other vehicle. */
771 if (Command
<CMD_CLONE_ORDER
>::Post(STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST
, this->vehicle
->tile
, CO_COPY
, this->vehicle
->index
, other_shared
->index
)) {
772 this->UpdateButtonState();
777 * Handle the click on the refit button.
778 * If ctrl is pressed, cancel refitting, else show the refit window.
779 * @param i Selected refit command.
780 * @param auto_refit Select refit for auto-refitting.
782 void OrderClick_Refit(int i
, bool auto_refit
)
785 /* Cancel refitting */
786 Command
<CMD_ORDER_REFIT
>::Post(this->vehicle
->tile
, this->vehicle
->index
, this->OrderGetSel(), CARGO_NO_REFIT
);
788 if (i
== 1) { // Auto-refit to available cargo type.
789 Command
<CMD_ORDER_REFIT
>::Post(this->vehicle
->tile
, this->vehicle
->index
, this->OrderGetSel(), CARGO_AUTO_REFIT
);
791 ShowVehicleRefitWindow(this->vehicle
, this->OrderGetSel(), this, auto_refit
);
796 /** Cache auto-refittability of the vehicle chain. */
797 void UpdateAutoRefitState()
799 this->can_do_refit
= false;
800 this->can_do_autorefit
= false;
801 for (const Vehicle
*w
= this->vehicle
; w
!= nullptr; w
= w
->IsGroundVehicle() ? w
->Next() : nullptr) {
802 if (IsEngineRefittable(w
->engine_type
)) this->can_do_refit
= true;
803 if (HasBit(Engine::Get(w
->engine_type
)->info
.misc_flags
, EF_AUTO_REFIT
)) this->can_do_autorefit
= true;
808 OrdersWindow(WindowDesc
&desc
, const Vehicle
*v
) : Window(desc
)
812 this->CreateNestedTree();
813 this->vscroll
= this->GetScrollbar(WID_O_SCROLLBAR
);
814 if (NWidgetCore
*nwid
= this->GetWidget
<NWidgetCore
>(WID_O_DEPOT_ACTION
); nwid
!= nullptr) {
815 nwid
->tool_tip
= STR_ORDER_TRAIN_DEPOT_ACTION_TOOLTIP
+ v
->type
;
817 this->FinishInitNested(v
->index
);
819 this->selected_order
= -1;
820 this->order_over
= INVALID_VEH_ORDER_ID
;
821 this->goto_type
= OPOS_NONE
;
822 this->owner
= v
->owner
;
824 this->UpdateAutoRefitState();
826 if (_settings_client
.gui
.quick_goto
&& v
->owner
== _local_company
) {
827 /* If there are less than 2 station, make Go To active. */
828 int station_orders
= 0;
829 for (const Order
*order
: v
->Orders()) {
830 if (order
->IsType(OT_GOTO_STATION
)) station_orders
++;
833 if (station_orders
< 2) this->OrderClick_Goto(OPOS_GOTO
);
835 this->OnInvalidateData(VIWD_MODIFY_ORDERS
);
838 void UpdateWidgetSize(WidgetID widget
, Dimension
&size
, [[maybe_unused
]] const Dimension
&padding
, [[maybe_unused
]] Dimension
&fill
, [[maybe_unused
]] Dimension
&resize
) override
841 case WID_O_ORDER_LIST
:
842 resize
.height
= GetCharacterHeight(FS_NORMAL
);
843 size
.height
= 6 * resize
.height
+ padding
.height
;
846 case WID_O_COND_VARIABLE
: {
847 Dimension d
= {0, 0};
848 for (const auto &ocv
: _order_conditional_variable
) {
849 d
= maxdim(d
, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE
+ ocv
));
851 d
.width
+= padding
.width
;
852 d
.height
+= padding
.height
;
853 size
= maxdim(size
, d
);
857 case WID_O_COND_COMPARATOR
: {
858 Dimension d
= GetStringListBoundingBox(_order_conditional_condition
);
859 d
.width
+= padding
.width
;
860 d
.height
+= padding
.height
;
861 size
= maxdim(size
, d
);
868 * Some data on this window has become invalid.
869 * @param data Information about the changed data.
870 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
872 void OnInvalidateData([[maybe_unused
]] int data
= 0, [[maybe_unused
]] bool gui_scope
= true) override
874 VehicleOrderID from
= INVALID_VEH_ORDER_ID
;
875 VehicleOrderID to
= INVALID_VEH_ORDER_ID
;
878 case VIWD_AUTOREPLACE
:
879 /* Autoreplace replaced the vehicle */
880 this->vehicle
= Vehicle::Get(this->window_number
);
883 case VIWD_CONSIST_CHANGED
:
884 /* Vehicle composition was changed. */
885 this->UpdateAutoRefitState();
888 case VIWD_REMOVE_ALL_ORDERS
:
889 /* Removed / replaced all orders (after deleting / sharing) */
890 if (this->selected_order
== -1) break;
892 this->CloseChildWindows();
893 this->selected_order
= -1;
896 case VIWD_MODIFY_ORDERS
:
897 /* Some other order changes */
903 if (gui_scope
) break; // only do this once; from command scope
904 from
= GB(data
, 0, 8);
906 /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
907 * the order is being created / removed */
908 if (this->selected_order
== -1) break;
910 if (from
== to
) break; // no need to change anything
912 if (from
!= this->selected_order
) {
913 /* Moving from preceding order? */
914 this->selected_order
-= (int)(from
<= this->selected_order
);
915 /* Moving to preceding order? */
916 this->selected_order
+= (int)(to
<= this->selected_order
);
920 /* Now we are modifying the selected order */
921 if (to
== INVALID_VEH_ORDER_ID
) {
922 /* Deleting selected order */
923 this->CloseChildWindows();
924 this->selected_order
= -1;
928 /* Moving selected order */
929 this->selected_order
= to
;
933 this->vscroll
->SetCount(this->vehicle
->GetNumOrders() + 1);
934 if (gui_scope
) this->UpdateButtonState();
936 /* Scroll to the new order. */
937 if (from
== INVALID_VEH_ORDER_ID
&& to
!= INVALID_VEH_ORDER_ID
&& !this->vscroll
->IsVisible(to
)) {
938 this->vscroll
->ScrollTowards(to
);
942 void UpdateButtonState()
944 if (this->vehicle
->owner
!= _local_company
) return; // No buttons are displayed with competitor order windows.
946 bool shared_orders
= this->vehicle
->IsOrderListShared();
947 VehicleOrderID sel
= this->OrderGetSel();
948 const Order
*order
= this->vehicle
->GetOrder(sel
);
952 this->SetWidgetDisabledState(WID_O_SKIP
, this->vehicle
->GetNumOrders() <= 1);
954 /* delete / stop sharing */
955 NWidgetStacked
*delete_sel
= this->GetWidget
<NWidgetStacked
>(WID_O_SEL_BOTTOM_MIDDLE
);
956 if (shared_orders
&& this->selected_order
== this->vehicle
->GetNumOrders()) {
957 /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
958 delete_sel
->SetDisplayedPlane(DP_BOTTOM_MIDDLE_STOP_SHARING
);
960 /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
961 delete_sel
->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE
);
962 this->SetWidgetDisabledState(WID_O_DELETE
,
963 (uint
)this->vehicle
->GetNumOrders() + ((shared_orders
|| this->vehicle
->GetNumOrders() != 0) ? 1 : 0) <= (uint
)this->selected_order
);
965 /* Set the tooltip of the 'delete' button depending on whether the
966 * 'End of Orders' order or a regular order is selected. */
967 NWidgetCore
*nwi
= this->GetWidget
<NWidgetCore
>(WID_O_DELETE
);
968 if (this->selected_order
== this->vehicle
->GetNumOrders()) {
969 nwi
->SetDataTip(STR_ORDERS_DELETE_BUTTON
, STR_ORDERS_DELETE_ALL_TOOLTIP
);
971 nwi
->SetDataTip(STR_ORDERS_DELETE_BUTTON
, STR_ORDERS_DELETE_TOOLTIP
);
976 this->RaiseWidget(WID_O_FULL_LOAD
);
977 this->RaiseWidget(WID_O_UNLOAD
);
979 /* Selection widgets. */
980 /* Train or road vehicle. */
981 NWidgetStacked
*train_row_sel
= this->GetWidget
<NWidgetStacked
>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE
);
982 NWidgetStacked
*left_sel
= this->GetWidget
<NWidgetStacked
>(WID_O_SEL_TOP_LEFT
);
983 NWidgetStacked
*middle_sel
= this->GetWidget
<NWidgetStacked
>(WID_O_SEL_TOP_MIDDLE
);
984 NWidgetStacked
*right_sel
= this->GetWidget
<NWidgetStacked
>(WID_O_SEL_TOP_RIGHT
);
985 /* Ship or airplane. */
986 NWidgetStacked
*row_sel
= this->GetWidget
<NWidgetStacked
>(WID_O_SEL_TOP_ROW
);
987 assert(row_sel
!= nullptr || (train_row_sel
!= nullptr && left_sel
!= nullptr && middle_sel
!= nullptr && right_sel
!= nullptr));
990 if (order
== nullptr) {
991 if (row_sel
!= nullptr) {
992 row_sel
->SetDisplayedPlane(DP_ROW_LOAD
);
994 train_row_sel
->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL
);
995 left_sel
->SetDisplayedPlane(DP_LEFT_LOAD
);
996 middle_sel
->SetDisplayedPlane(DP_MIDDLE_UNLOAD
);
997 right_sel
->SetDisplayedPlane(DP_RIGHT_EMPTY
);
998 this->DisableWidget(WID_O_NON_STOP
);
999 this->RaiseWidget(WID_O_NON_STOP
);
1001 this->DisableWidget(WID_O_FULL_LOAD
);
1002 this->DisableWidget(WID_O_UNLOAD
);
1003 this->DisableWidget(WID_O_REFIT_DROPDOWN
);
1005 this->SetWidgetDisabledState(WID_O_FULL_LOAD
, (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) != 0); // full load
1006 this->SetWidgetDisabledState(WID_O_UNLOAD
, (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) != 0); // unload
1008 switch (order
->GetType()) {
1009 case OT_GOTO_STATION
:
1010 if (row_sel
!= nullptr) {
1011 row_sel
->SetDisplayedPlane(DP_ROW_LOAD
);
1013 train_row_sel
->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL
);
1014 left_sel
->SetDisplayedPlane(DP_LEFT_LOAD
);
1015 middle_sel
->SetDisplayedPlane(DP_MIDDLE_UNLOAD
);
1016 right_sel
->SetDisplayedPlane(DP_RIGHT_REFIT
);
1017 this->EnableWidget(WID_O_NON_STOP
);
1018 this->SetWidgetLoweredState(WID_O_NON_STOP
, order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
);
1020 this->SetWidgetLoweredState(WID_O_FULL_LOAD
, order
->GetLoadType() == OLF_FULL_LOAD_ANY
);
1021 this->SetWidgetLoweredState(WID_O_UNLOAD
, order
->GetUnloadType() == OUFB_UNLOAD
);
1023 /* Can only do refitting when stopping at the destination and loading cargo.
1024 * Also enable the button if a refit is already set to allow clearing it. */
1025 this->SetWidgetDisabledState(WID_O_REFIT_DROPDOWN
,
1026 order
->GetLoadType() == OLFB_NO_LOAD
|| (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) ||
1027 ((!this->can_do_refit
|| !this->can_do_autorefit
) && !order
->IsRefit()));
1031 case OT_GOTO_WAYPOINT
:
1032 if (row_sel
!= nullptr) {
1033 row_sel
->SetDisplayedPlane(DP_ROW_LOAD
);
1035 train_row_sel
->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL
);
1036 left_sel
->SetDisplayedPlane(DP_LEFT_LOAD
);
1037 middle_sel
->SetDisplayedPlane(DP_MIDDLE_UNLOAD
);
1038 right_sel
->SetDisplayedPlane(DP_RIGHT_EMPTY
);
1039 this->EnableWidget(WID_O_NON_STOP
);
1040 this->SetWidgetLoweredState(WID_O_NON_STOP
, order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
);
1042 this->DisableWidget(WID_O_FULL_LOAD
);
1043 this->DisableWidget(WID_O_UNLOAD
);
1044 this->DisableWidget(WID_O_REFIT_DROPDOWN
);
1048 if (row_sel
!= nullptr) {
1049 row_sel
->SetDisplayedPlane(DP_ROW_DEPOT
);
1051 train_row_sel
->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL
);
1052 left_sel
->SetDisplayedPlane(DP_LEFT_REFIT
);
1053 middle_sel
->SetDisplayedPlane(DP_MIDDLE_SERVICE
);
1054 right_sel
->SetDisplayedPlane(DP_RIGHT_EMPTY
);
1055 this->EnableWidget(WID_O_NON_STOP
);
1056 this->SetWidgetLoweredState(WID_O_NON_STOP
, order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
);
1058 /* Disable refit button if the order is no 'always go' order.
1059 * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
1060 this->SetWidgetDisabledState(WID_O_REFIT
,
1061 (order
->GetDepotOrderType() & ODTFB_SERVICE
) || (order
->GetDepotActionType() & ODATFB_HALT
) ||
1062 (!this->can_do_refit
&& !order
->IsRefit()));
1065 case OT_CONDITIONAL
: {
1066 if (row_sel
!= nullptr) {
1067 row_sel
->SetDisplayedPlane(DP_ROW_CONDITIONAL
);
1069 train_row_sel
->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_CONDITIONAL
);
1071 OrderConditionVariable ocv
= order
->GetConditionVariable();
1072 /* Set the strings for the dropdown boxes. */
1073 this->GetWidget
<NWidgetCore
>(WID_O_COND_VARIABLE
)->widget_data
= STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE
+ ocv
;
1074 this->GetWidget
<NWidgetCore
>(WID_O_COND_COMPARATOR
)->widget_data
= _order_conditional_condition
[order
->GetConditionComparator()];
1075 this->SetWidgetDisabledState(WID_O_COND_COMPARATOR
, ocv
== OCV_UNCONDITIONALLY
);
1076 this->SetWidgetDisabledState(WID_O_COND_VALUE
, ocv
== OCV_REQUIRES_SERVICE
|| ocv
== OCV_UNCONDITIONALLY
);
1080 default: // every other order
1081 if (row_sel
!= nullptr) {
1082 row_sel
->SetDisplayedPlane(DP_ROW_LOAD
);
1084 train_row_sel
->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL
);
1085 left_sel
->SetDisplayedPlane(DP_LEFT_LOAD
);
1086 middle_sel
->SetDisplayedPlane(DP_MIDDLE_UNLOAD
);
1087 right_sel
->SetDisplayedPlane(DP_RIGHT_EMPTY
);
1088 this->DisableWidget(WID_O_NON_STOP
);
1090 this->DisableWidget(WID_O_FULL_LOAD
);
1091 this->DisableWidget(WID_O_UNLOAD
);
1092 this->DisableWidget(WID_O_REFIT_DROPDOWN
);
1097 /* Disable list of vehicles with the same shared orders if there is no list */
1098 this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST
, !shared_orders
);
1103 void OnPaint() override
1105 if (this->vehicle
->owner
!= _local_company
) {
1106 this->selected_order
= -1; // Disable selection any selected row at a competitor order window.
1108 this->SetWidgetLoweredState(WID_O_GOTO
, this->goto_type
!= OPOS_NONE
);
1110 this->DrawWidgets();
1113 void DrawWidget(const Rect
&r
, WidgetID widget
) const override
1115 if (widget
!= WID_O_ORDER_LIST
) return;
1117 Rect ir
= r
.Shrink(WidgetDimensions::scaled
.frametext
, WidgetDimensions::scaled
.framerect
);
1118 bool rtl
= _current_text_dir
== TD_RTL
;
1119 SetDParamMaxValue(0, this->vehicle
->GetNumOrders(), 2);
1120 int index_column_width
= GetStringBoundingBox(STR_ORDER_INDEX
).width
+ 2 * GetSpriteSize(rtl
? SPR_ARROW_RIGHT
: SPR_ARROW_LEFT
).width
+ WidgetDimensions::scaled
.hsep_normal
;
1121 int middle
= rtl
? ir
.right
- index_column_width
: ir
.left
+ index_column_width
;
1124 int line_height
= this->GetWidget
<NWidgetBase
>(WID_O_ORDER_LIST
)->resize_y
;
1126 int i
= this->vscroll
->GetPosition();
1127 const Order
*order
= this->vehicle
->GetOrder(i
);
1128 /* First draw the highlighting underground if it exists. */
1129 if (this->order_over
!= INVALID_VEH_ORDER_ID
) {
1130 while (order
!= nullptr) {
1131 /* Don't draw anything if it extends past the end of the window. */
1132 if (!this->vscroll
->IsVisible(i
)) break;
1134 if (i
!= this->selected_order
&& i
== this->order_over
) {
1135 /* Highlight dragged order destination. */
1136 int top
= (this->order_over
< this->selected_order
? y
: y
+ line_height
) - WidgetDimensions::scaled
.framerect
.top
;
1137 int bottom
= std::min(top
+ 2, ir
.bottom
);
1138 top
= std::max(top
- 3, ir
.top
);
1139 GfxFillRect(ir
.left
, top
, ir
.right
, bottom
, GetColourGradient(COLOUR_GREY
, SHADE_LIGHTEST
));
1145 order
= order
->next
;
1148 /* Reset counters for drawing the orders. */
1150 i
= this->vscroll
->GetPosition();
1151 order
= this->vehicle
->GetOrder(i
);
1154 /* Draw the orders. */
1155 while (order
!= nullptr) {
1156 /* Don't draw anything if it extends past the end of the window. */
1157 if (!this->vscroll
->IsVisible(i
)) break;
1159 DrawOrderString(this->vehicle
, order
, i
, y
, i
== this->selected_order
, false, ir
.left
, middle
, ir
.right
);
1163 order
= order
->next
;
1166 if (this->vscroll
->IsVisible(i
)) {
1167 StringID str
= this->vehicle
->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS
: STR_ORDERS_END_OF_ORDERS
;
1168 DrawString(rtl
? ir
.left
: middle
, rtl
? middle
: ir
.right
, y
, str
, (i
== this->selected_order
) ? TC_WHITE
: TC_BLACK
);
1172 void SetStringParameters(WidgetID widget
) const override
1175 case WID_O_COND_VALUE
: {
1176 VehicleOrderID sel
= this->OrderGetSel();
1177 const Order
*order
= this->vehicle
->GetOrder(sel
);
1179 if (order
!= nullptr && order
->IsType(OT_CONDITIONAL
)) {
1180 uint value
= order
->GetConditionValue();
1181 if (order
->GetConditionVariable() == OCV_MAX_SPEED
) value
= ConvertSpeedToDisplaySpeed(value
, this->vehicle
->type
);
1182 SetDParam(0, value
);
1188 SetDParam(0, this->vehicle
->index
);
1191 case WID_O_DEPOT_ACTION
: {
1192 VehicleOrderID sel
= this->OrderGetSel();
1193 const Order
*order
= this->vehicle
->GetOrder(sel
);
1194 if (order
== nullptr || !order
->IsType(OT_GOTO_DEPOT
)) {
1195 /* We can't leave this param unset or the undefined behavior can cause a crash. */
1196 SetDParam(0, STR_EMPTY
);
1200 /* Select the current action selected in the dropdown. The flags don't match the dropdown so we can't just use an index. */
1201 if (order
->GetDepotOrderType() & ODTFB_SERVICE
) {
1202 SetDParam(0, STR_ORDER_DROP_SERVICE_DEPOT
);
1203 } else if (order
->GetDepotActionType() & ODATFB_HALT
) {
1204 SetDParam(0, STR_ORDER_DROP_HALT_DEPOT
);
1205 } else if (order
->GetDepotActionType() & ODATFB_UNBUNCH
) {
1206 SetDParam(0, STR_ORDER_DROP_UNBUNCH
);
1208 SetDParam(0, STR_ORDER_DROP_GO_ALWAYS_DEPOT
);
1215 void OnClick([[maybe_unused
]] Point pt
, WidgetID widget
, [[maybe_unused
]] int click_count
) override
1218 case WID_O_ORDER_LIST
: {
1219 if (this->goto_type
== OPOS_CONDITIONAL
) {
1220 VehicleOrderID order_id
= this->GetOrderFromPt(_cursor
.pos
.y
- this->top
);
1221 if (order_id
!= INVALID_VEH_ORDER_ID
) {
1223 order
.next
= nullptr;
1225 order
.MakeConditional(order_id
);
1227 Command
<CMD_INSERT_ORDER
>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER
, this->vehicle
->tile
, this->vehicle
->index
, this->OrderGetSel(), order
);
1229 ResetObjectToPlace();
1233 VehicleOrderID sel
= this->GetOrderFromPt(pt
.y
);
1235 if (_ctrl_pressed
&& sel
< this->vehicle
->GetNumOrders()) {
1236 TileIndex xy
= this->vehicle
->GetOrder(sel
)->GetLocation(this->vehicle
);
1237 if (xy
!= INVALID_TILE
) ScrollMainWindowToTile(xy
);
1241 /* This order won't be selected any more, close all child windows and dropdowns */
1242 this->CloseChildWindows();
1244 if (sel
== INVALID_VEH_ORDER_ID
|| this->vehicle
->owner
!= _local_company
) {
1245 /* Deselect clicked order */
1246 this->selected_order
= -1;
1247 } else if (sel
== this->selected_order
) {
1248 if (this->vehicle
->type
== VEH_TRAIN
&& sel
< this->vehicle
->GetNumOrders()) {
1249 Command
<CMD_MODIFY_ORDER
>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
,
1250 this->vehicle
->tile
, this->vehicle
->index
, sel
,
1251 MOF_STOP_LOCATION
, (this->vehicle
->GetOrder(sel
)->GetStopLocation() + 1) % OSL_END
);
1254 /* Select clicked order */
1255 this->selected_order
= sel
;
1257 if (this->vehicle
->owner
== _local_company
) {
1258 /* Activate drag and drop */
1259 SetObjectToPlaceWnd(SPR_CURSOR_MOUSE
, PAL_NONE
, HT_DRAG
, this);
1263 this->UpdateButtonState();
1268 this->OrderClick_Skip();
1272 this->OrderClick_Delete();
1275 case WID_O_STOP_SHARING
:
1276 this->OrderClick_StopSharing();
1279 case WID_O_NON_STOP
:
1280 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1281 this->OrderClick_Nonstop(-1);
1283 const Order
*o
= this->vehicle
->GetOrder(this->OrderGetSel());
1284 assert(o
!= nullptr);
1285 ShowDropDownMenu(this, _order_non_stop_drowdown
, o
->GetNonStopType(), WID_O_NON_STOP
, 0,
1286 o
->IsType(OT_GOTO_STATION
) ? 0 : (o
->IsType(OT_GOTO_WAYPOINT
) ? 3 : 12));
1291 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1292 if (this->goto_type
!= OPOS_NONE
) {
1293 ResetObjectToPlace();
1295 this->OrderClick_Goto(OPOS_GOTO
);
1299 switch (this->goto_type
) {
1300 case OPOS_NONE
: sel
= -1; break;
1301 case OPOS_GOTO
: sel
= 0; break;
1302 case OPOS_CONDITIONAL
: sel
= 2; break;
1303 case OPOS_SHARE
: sel
= 3; break;
1304 default: NOT_REACHED();
1306 ShowDropDownMenu(this, this->vehicle
->type
== VEH_AIRCRAFT
? _order_goto_dropdown_aircraft
: _order_goto_dropdown
, sel
, WID_O_GOTO
, 0, 0);
1310 case WID_O_FULL_LOAD
:
1311 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1312 this->OrderClick_FullLoad(OLF_FULL_LOAD_ANY
, true);
1314 ShowDropDownMenu(this, _order_full_load_drowdown
, this->vehicle
->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD
, 0, 2);
1319 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1320 this->OrderClick_Unload(OUFB_UNLOAD
, true);
1322 ShowDropDownMenu(this, _order_unload_drowdown
, this->vehicle
->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD
, 0, 8);
1327 this->OrderClick_Refit(0, false);
1330 case WID_O_DEPOT_ACTION
:
1331 ShowDropDownMenu(this, _order_depot_action_dropdown
, DepotActionStringIndex(this->vehicle
->GetOrder(this->OrderGetSel())), WID_O_DEPOT_ACTION
, 0, 0);
1334 case WID_O_REFIT_DROPDOWN
:
1335 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1336 this->OrderClick_Refit(0, true);
1338 ShowDropDownMenu(this, _order_refit_action_dropdown
, 0, WID_O_REFIT_DROPDOWN
, 0, 0);
1342 case WID_O_TIMETABLE_VIEW
:
1343 ShowTimetableWindow(this->vehicle
);
1346 case WID_O_COND_VARIABLE
: {
1348 for (const auto &ocv
: _order_conditional_variable
) {
1349 list
.push_back(MakeDropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE
+ ocv
, ocv
));
1351 ShowDropDownList(this, std::move(list
), this->vehicle
->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE
);
1355 case WID_O_COND_COMPARATOR
: {
1356 const Order
*o
= this->vehicle
->GetOrder(this->OrderGetSel());
1357 assert(o
!= nullptr);
1358 ShowDropDownMenu(this, _order_conditional_condition
, o
->GetConditionComparator(), WID_O_COND_COMPARATOR
, 0, (o
->GetConditionVariable() == OCV_REQUIRES_SERVICE
) ? 0x3F : 0xC0);
1362 case WID_O_COND_VALUE
: {
1363 const Order
*order
= this->vehicle
->GetOrder(this->OrderGetSel());
1364 assert(order
!= nullptr);
1365 uint value
= order
->GetConditionValue();
1366 if (order
->GetConditionVariable() == OCV_MAX_SPEED
) value
= ConvertSpeedToDisplaySpeed(value
, this->vehicle
->type
);
1367 SetDParam(0, value
);
1368 ShowQueryString(STR_JUST_INT
, STR_ORDER_CONDITIONAL_VALUE_CAPT
, 5, this, CS_NUMERAL
, QSF_NONE
);
1372 case WID_O_SHARED_ORDER_LIST
:
1373 ShowVehicleListWindow(this->vehicle
);
1378 void OnQueryTextFinished(std::optional
<std::string
> str
) override
1380 if (!str
.has_value() || str
->empty()) return;
1382 VehicleOrderID sel
= this->OrderGetSel();
1383 uint value
= atoi(str
->c_str());
1385 switch (this->vehicle
->GetOrder(sel
)->GetConditionVariable()) {
1387 value
= ConvertDisplaySpeedToSpeed(value
, this->vehicle
->type
);
1390 case OCV_RELIABILITY
:
1391 case OCV_LOAD_PERCENTAGE
:
1392 value
= Clamp(value
, 0, 100);
1398 Command
<CMD_MODIFY_ORDER
>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
, this->vehicle
->tile
, this->vehicle
->index
, sel
, MOF_COND_VALUE
, Clamp(value
, 0, 2047));
1401 void OnDropdownSelect(WidgetID widget
, int index
) override
1404 case WID_O_NON_STOP
:
1405 this->OrderClick_Nonstop(index
);
1408 case WID_O_FULL_LOAD
:
1409 this->OrderClick_FullLoad((OrderLoadFlags
)index
);
1413 this->OrderClick_Unload((OrderUnloadFlags
)index
);
1418 case 0: this->OrderClick_Goto(OPOS_GOTO
); break;
1419 case 1: this->OrderClick_NearestDepot(); break;
1420 case 2: this->OrderClick_Goto(OPOS_CONDITIONAL
); break;
1421 case 3: this->OrderClick_Goto(OPOS_SHARE
); break;
1422 default: NOT_REACHED();
1426 case WID_O_DEPOT_ACTION
:
1427 this->OrderClick_Service(index
);
1430 case WID_O_REFIT_DROPDOWN
:
1431 this->OrderClick_Refit(index
, true);
1434 case WID_O_COND_VARIABLE
:
1435 Command
<CMD_MODIFY_ORDER
>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
, this->vehicle
->tile
, this->vehicle
->index
, this->OrderGetSel(), MOF_COND_VARIABLE
, index
);
1438 case WID_O_COND_COMPARATOR
:
1439 Command
<CMD_MODIFY_ORDER
>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
, this->vehicle
->tile
, this->vehicle
->index
, this->OrderGetSel(), MOF_COND_COMPARATOR
, index
);
1444 void OnDragDrop(Point pt
, WidgetID widget
) override
1447 case WID_O_ORDER_LIST
: {
1448 VehicleOrderID from_order
= this->OrderGetSel();
1449 VehicleOrderID to_order
= this->GetOrderFromPt(pt
.y
);
1451 if (!(from_order
== to_order
|| from_order
== INVALID_VEH_ORDER_ID
|| from_order
> this->vehicle
->GetNumOrders() || to_order
== INVALID_VEH_ORDER_ID
|| to_order
> this->vehicle
->GetNumOrders()) &&
1452 Command
<CMD_MOVE_ORDER
>::Post(STR_ERROR_CAN_T_MOVE_THIS_ORDER
, this->vehicle
->tile
, this->vehicle
->index
, from_order
, to_order
)) {
1453 this->selected_order
= -1;
1454 this->UpdateButtonState();
1460 this->OrderClick_Delete();
1463 case WID_O_STOP_SHARING
:
1464 this->OrderClick_StopSharing();
1468 ResetObjectToPlace();
1470 if (this->order_over
!= INVALID_VEH_ORDER_ID
) {
1471 /* End of drag-and-drop, hide dragged order destination highlight. */
1472 this->order_over
= INVALID_VEH_ORDER_ID
;
1473 this->SetWidgetDirty(WID_O_ORDER_LIST
);
1477 EventState
OnHotkey(int hotkey
) override
1479 if (this->vehicle
->owner
!= _local_company
) return ES_NOT_HANDLED
;
1482 case OHK_SKIP
: this->OrderClick_Skip(); break;
1483 case OHK_DELETE
: this->OrderClick_Delete(); break;
1484 case OHK_GOTO
: this->OrderClick_Goto(OPOS_GOTO
); break;
1485 case OHK_NONSTOP
: this->OrderClick_Nonstop(-1); break;
1486 case OHK_FULLLOAD
: this->OrderClick_FullLoad(OLF_FULL_LOAD_ANY
, true); break;
1487 case OHK_UNLOAD
: this->OrderClick_Unload(OUFB_UNLOAD
, true); break;
1488 case OHK_NEAREST_DEPOT
: this->OrderClick_NearestDepot(); break;
1489 case OHK_ALWAYS_SERVICE
: this->OrderClick_Service(-1); break;
1490 case OHK_TRANSFER
: this->OrderClick_Unload(OUFB_TRANSFER
, true); break;
1491 case OHK_NO_UNLOAD
: this->OrderClick_Unload(OUFB_NO_UNLOAD
, true); break;
1492 case OHK_NO_LOAD
: this->OrderClick_FullLoad(OLFB_NO_LOAD
, true); break;
1493 default: return ES_NOT_HANDLED
;
1498 void OnPlaceObject([[maybe_unused
]] Point pt
, TileIndex tile
) override
1500 if (this->goto_type
== OPOS_GOTO
) {
1501 const Order cmd
= GetOrderCmdFromTile(this->vehicle
, tile
);
1502 if (cmd
.IsType(OT_NOTHING
)) return;
1504 if (Command
<CMD_INSERT_ORDER
>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER
, this->vehicle
->tile
, this->vehicle
->index
, this->OrderGetSel(), cmd
)) {
1505 /* With quick goto the Go To button stays active */
1506 if (!_settings_client
.gui
.quick_goto
) ResetObjectToPlace();
1511 bool OnVehicleSelect(const Vehicle
*v
) override
1513 /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
1514 * We disallow copying orders of other vehicles if we already have at least one order entry
1515 * ourself as it easily copies orders of vehicles within a station when we mean the station.
1516 * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
1517 * TODO: give a warning message */
1518 bool share_order
= _ctrl_pressed
|| this->goto_type
== OPOS_SHARE
;
1519 if (this->vehicle
->GetNumOrders() != 0 && !share_order
) return false;
1521 if (Command
<CMD_CLONE_ORDER
>::Post(share_order
? STR_ERROR_CAN_T_SHARE_ORDER_LIST
: STR_ERROR_CAN_T_COPY_ORDER_LIST
,
1522 this->vehicle
->tile
, share_order
? CO_SHARE
: CO_COPY
, this->vehicle
->index
, v
->index
)) {
1523 this->selected_order
= -1;
1524 ResetObjectToPlace();
1530 * Clones an order list from a vehicle list. If this doesn't make sense (because not all vehicles in the list have the same orders), then it displays an error.
1531 * @return This always returns true, which indicates that the contextual action handled the mouse click.
1532 * Note that it's correct behaviour to always handle the click even though an error is displayed,
1533 * because users aren't going to expect the default action to be performed just because they overlooked that cloning doesn't make sense.
1535 bool OnVehicleSelect(VehicleList::const_iterator begin
, VehicleList::const_iterator end
) override
1537 bool share_order
= _ctrl_pressed
|| this->goto_type
== OPOS_SHARE
;
1538 if (this->vehicle
->GetNumOrders() != 0 && !share_order
) return false;
1541 /* If CTRL is not pressed: If all the vehicles in this list have the same orders, then copy orders */
1542 if (AllEqual(begin
, end
, [](const Vehicle
*v1
, const Vehicle
*v2
) {
1543 return VehiclesHaveSameOrderList(v1
, v2
);
1545 OnVehicleSelect(*begin
);
1547 ShowErrorMessage(STR_ERROR_CAN_T_COPY_ORDER_LIST
, STR_ERROR_CAN_T_COPY_ORDER_VEHICLE_LIST
, WL_INFO
);
1550 /* If CTRL is pressed: If all the vehicles in this list share orders, then copy orders */
1551 if (AllEqual(begin
, end
, [](const Vehicle
*v1
, const Vehicle
*v2
) {
1552 return v1
->FirstShared() == v2
->FirstShared();
1554 OnVehicleSelect(*begin
);
1556 ShowErrorMessage(STR_ERROR_CAN_T_SHARE_ORDER_LIST
, STR_ERROR_CAN_T_SHARE_ORDER_VEHICLE_LIST
, WL_INFO
);
1563 void OnPlaceObjectAbort() override
1565 this->goto_type
= OPOS_NONE
;
1566 this->SetWidgetDirty(WID_O_GOTO
);
1568 /* Remove drag highlighting if it exists. */
1569 if (this->order_over
!= INVALID_VEH_ORDER_ID
) {
1570 this->order_over
= INVALID_VEH_ORDER_ID
;
1571 this->SetWidgetDirty(WID_O_ORDER_LIST
);
1575 void OnMouseDrag(Point pt
, WidgetID widget
) override
1577 if (this->selected_order
!= -1 && widget
== WID_O_ORDER_LIST
) {
1578 /* An order is dragged.. */
1579 VehicleOrderID from_order
= this->OrderGetSel();
1580 VehicleOrderID to_order
= this->GetOrderFromPt(pt
.y
);
1581 uint num_orders
= this->vehicle
->GetNumOrders();
1583 if (from_order
!= INVALID_VEH_ORDER_ID
&& from_order
<= num_orders
) {
1584 if (to_order
!= INVALID_VEH_ORDER_ID
&& to_order
<= num_orders
) { // ..over an existing order.
1585 this->order_over
= to_order
;
1586 this->SetWidgetDirty(widget
);
1587 } else if (from_order
!= to_order
&& this->order_over
!= INVALID_VEH_ORDER_ID
) { // ..outside of the order list.
1588 this->order_over
= INVALID_VEH_ORDER_ID
;
1589 this->SetWidgetDirty(widget
);
1595 void OnResize() override
1597 /* Update the scroll bar */
1598 this->vscroll
->SetCapacityFromWidget(this, WID_O_ORDER_LIST
, WidgetDimensions::scaled
.framerect
.Vertical());
1601 static inline HotkeyList hotkeys
{"order", {
1602 Hotkey('D', "skip", OHK_SKIP
),
1603 Hotkey('F', "delete", OHK_DELETE
),
1604 Hotkey('G', "goto", OHK_GOTO
),
1605 Hotkey('H', "nonstop", OHK_NONSTOP
),
1606 Hotkey('J', "fullload", OHK_FULLLOAD
),
1607 Hotkey('K', "unload", OHK_UNLOAD
),
1608 Hotkey(0, "nearest_depot", OHK_NEAREST_DEPOT
),
1609 Hotkey(0, "always_service", OHK_ALWAYS_SERVICE
),
1610 Hotkey(0, "transfer", OHK_TRANSFER
),
1611 Hotkey(0, "no_unload", OHK_NO_UNLOAD
),
1612 Hotkey(0, "no_load", OHK_NO_LOAD
),
1616 /** Nested widget definition for "your" train orders. */
1617 static constexpr NWidgetPart _nested_orders_train_widgets
[] = {
1618 NWidget(NWID_HORIZONTAL
),
1619 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1620 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_O_CAPTION
), SetDataTip(STR_ORDERS_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1621 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_TIMETABLE_VIEW
), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW
, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP
),
1622 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
1623 NWidget(WWT_DEFSIZEBOX
, COLOUR_GREY
),
1624 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
1626 NWidget(NWID_HORIZONTAL
),
1627 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_O_ORDER_LIST
), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP
), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR
), EndContainer(),
1628 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_O_SCROLLBAR
),
1631 /* First button row. */
1632 NWidget(NWID_HORIZONTAL
),
1633 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_TOP_ROW_GROUNDVEHICLE
),
1634 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1635 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_NON_STOP
), SetMinimalSize(93, 12), SetFill(1, 0),
1636 SetDataTip(STR_ORDER_NON_STOP
, STR_ORDER_TOOLTIP_NON_STOP
), SetResize(1, 0),
1637 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_TOP_LEFT
),
1638 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_FULL_LOAD
), SetMinimalSize(93, 12), SetFill(1, 0),
1639 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD
, STR_ORDER_TOOLTIP_FULL_LOAD
), SetResize(1, 0),
1640 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_REFIT
), SetMinimalSize(93, 12), SetFill(1, 0),
1641 SetDataTip(STR_ORDER_REFIT
, STR_ORDER_REFIT_TOOLTIP
), SetResize(1, 0),
1643 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_TOP_MIDDLE
),
1644 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_UNLOAD
), SetMinimalSize(93, 12), SetFill(1, 0),
1645 SetDataTip(STR_ORDER_TOGGLE_UNLOAD
, STR_ORDER_TOOLTIP_UNLOAD
), SetResize(1, 0),
1646 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_DEPOT_ACTION
), SetMinimalSize(93, 12), SetFill(1, 0),
1647 SetDataTip(STR_JUST_STRING
, STR_NULL
), SetResize(1, 0),
1649 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_TOP_RIGHT
),
1650 NWidget(WWT_PANEL
, COLOUR_GREY
), SetMinimalSize(93, 12), SetFill(1, 0), SetResize(1, 0), EndContainer(),
1651 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_REFIT_DROPDOWN
), SetMinimalSize(93, 12), SetFill(1, 0),
1652 SetDataTip(STR_ORDER_REFIT_AUTO
, STR_ORDER_REFIT_AUTO_TOOLTIP
), SetResize(1, 0),
1655 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1656 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_O_COND_VARIABLE
), SetMinimalSize(124, 12), SetFill(1, 0),
1657 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP
), SetResize(1, 0),
1658 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_O_COND_COMPARATOR
), SetMinimalSize(124, 12), SetFill(1, 0),
1659 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP
), SetResize(1, 0),
1660 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_COND_VALUE
), SetMinimalSize(124, 12), SetFill(1, 0),
1661 SetDataTip(STR_JUST_COMMA
, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP
), SetResize(1, 0),
1664 NWidget(WWT_PUSHIMGBTN
, COLOUR_GREY
, WID_O_SHARED_ORDER_LIST
), SetAspect(1), SetDataTip(SPR_SHARED_ORDERS_ICON
, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP
),
1667 /* Second button row. */
1668 NWidget(NWID_HORIZONTAL
),
1669 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1670 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_SKIP
), SetMinimalSize(124, 12), SetFill(1, 0),
1671 SetDataTip(STR_ORDERS_SKIP_BUTTON
, STR_ORDERS_SKIP_TOOLTIP
), SetResize(1, 0),
1672 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_BOTTOM_MIDDLE
),
1673 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_DELETE
), SetMinimalSize(124, 12), SetFill(1, 0),
1674 SetDataTip(STR_ORDERS_DELETE_BUTTON
, STR_ORDERS_DELETE_TOOLTIP
), SetResize(1, 0),
1675 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_STOP_SHARING
), SetMinimalSize(124, 12), SetFill(1, 0),
1676 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON
, STR_ORDERS_STOP_SHARING_TOOLTIP
), SetResize(1, 0),
1678 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_GOTO
), SetMinimalSize(124, 12), SetFill(1, 0),
1679 SetDataTip(STR_ORDERS_GO_TO_BUTTON
, STR_ORDERS_GO_TO_TOOLTIP
), SetResize(1, 0),
1681 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
1685 static WindowDesc
_orders_train_desc(
1686 WDP_AUTO
, "view_vehicle_orders_train", 384, 100,
1687 WC_VEHICLE_ORDERS
, WC_VEHICLE_VIEW
,
1689 _nested_orders_train_widgets
,
1690 &OrdersWindow::hotkeys
1693 /** Nested widget definition for "your" orders (non-train). */
1694 static constexpr NWidgetPart _nested_orders_widgets
[] = {
1695 NWidget(NWID_HORIZONTAL
),
1696 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1697 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_O_CAPTION
), SetDataTip(STR_ORDERS_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1698 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_TIMETABLE_VIEW
), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW
, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP
),
1699 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
1700 NWidget(WWT_DEFSIZEBOX
, COLOUR_GREY
),
1701 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
1703 NWidget(NWID_HORIZONTAL
),
1704 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_O_ORDER_LIST
), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP
), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR
), EndContainer(),
1705 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_O_SCROLLBAR
),
1708 /* First button row. */
1709 NWidget(NWID_HORIZONTAL
),
1710 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_TOP_ROW
),
1711 /* Load + unload + refit buttons. */
1712 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1713 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_FULL_LOAD
), SetMinimalSize(124, 12), SetFill(1, 0),
1714 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD
, STR_ORDER_TOOLTIP_FULL_LOAD
), SetResize(1, 0),
1715 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_UNLOAD
), SetMinimalSize(124, 12), SetFill(1, 0),
1716 SetDataTip(STR_ORDER_TOGGLE_UNLOAD
, STR_ORDER_TOOLTIP_UNLOAD
), SetResize(1, 0),
1717 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_REFIT_DROPDOWN
), SetMinimalSize(124, 12), SetFill(1, 0),
1718 SetDataTip(STR_ORDER_REFIT_AUTO
, STR_ORDER_REFIT_AUTO_TOOLTIP
), SetResize(1, 0),
1720 /* Refit + service buttons. */
1721 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1722 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_REFIT
), SetMinimalSize(186, 12), SetFill(1, 0),
1723 SetDataTip(STR_ORDER_REFIT
, STR_ORDER_REFIT_TOOLTIP
), SetResize(1, 0),
1724 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_DEPOT_ACTION
), SetMinimalSize(124, 12), SetFill(1, 0),
1725 SetDataTip(STR_JUST_STRING
, STR_NULL
), SetResize(1, 0),
1728 /* Buttons for setting a condition. */
1729 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1730 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_O_COND_VARIABLE
), SetMinimalSize(124, 12), SetFill(1, 0),
1731 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP
), SetResize(1, 0),
1732 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_O_COND_COMPARATOR
), SetMinimalSize(124, 12), SetFill(1, 0),
1733 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP
), SetResize(1, 0),
1734 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_COND_VALUE
), SetMinimalSize(124, 12), SetFill(1, 0),
1735 SetDataTip(STR_JUST_COMMA
, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP
), SetResize(1, 0),
1739 NWidget(WWT_PUSHIMGBTN
, COLOUR_GREY
, WID_O_SHARED_ORDER_LIST
), SetAspect(1), SetDataTip(SPR_SHARED_ORDERS_ICON
, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP
),
1742 /* Second button row. */
1743 NWidget(NWID_HORIZONTAL
),
1744 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_SKIP
), SetMinimalSize(124, 12), SetFill(1, 0),
1745 SetDataTip(STR_ORDERS_SKIP_BUTTON
, STR_ORDERS_SKIP_TOOLTIP
), SetResize(1, 0),
1746 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_BOTTOM_MIDDLE
),
1747 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_DELETE
), SetMinimalSize(124, 12), SetFill(1, 0),
1748 SetDataTip(STR_ORDERS_DELETE_BUTTON
, STR_ORDERS_DELETE_TOOLTIP
), SetResize(1, 0),
1749 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_STOP_SHARING
), SetMinimalSize(124, 12), SetFill(1, 0),
1750 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON
, STR_ORDERS_STOP_SHARING_TOOLTIP
), SetResize(1, 0),
1752 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_GOTO
), SetMinimalSize(124, 12), SetFill(1, 0),
1753 SetDataTip(STR_ORDERS_GO_TO_BUTTON
, STR_ORDERS_GO_TO_TOOLTIP
), SetResize(1, 0),
1754 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
1758 static WindowDesc
_orders_desc(
1759 WDP_AUTO
, "view_vehicle_orders", 384, 100,
1760 WC_VEHICLE_ORDERS
, WC_VEHICLE_VIEW
,
1762 _nested_orders_widgets
,
1763 &OrdersWindow::hotkeys
1766 /** Nested widget definition for competitor orders. */
1767 static constexpr NWidgetPart _nested_other_orders_widgets
[] = {
1768 NWidget(NWID_HORIZONTAL
),
1769 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1770 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_O_CAPTION
), SetDataTip(STR_ORDERS_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1771 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_TIMETABLE_VIEW
), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW
, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP
),
1772 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
1773 NWidget(WWT_DEFSIZEBOX
, COLOUR_GREY
),
1774 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
1776 NWidget(NWID_HORIZONTAL
),
1777 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_O_ORDER_LIST
), SetMinimalSize(372, 72), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP
), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR
), EndContainer(),
1778 NWidget(NWID_VERTICAL
),
1779 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_O_SCROLLBAR
),
1780 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
1785 static WindowDesc
_other_orders_desc(
1786 WDP_AUTO
, "view_vehicle_orders_competitor", 384, 86,
1787 WC_VEHICLE_ORDERS
, WC_VEHICLE_VIEW
,
1789 _nested_other_orders_widgets
,
1790 &OrdersWindow::hotkeys
1793 void ShowOrdersWindow(const Vehicle
*v
)
1795 CloseWindowById(WC_VEHICLE_DETAILS
, v
->index
, false);
1796 CloseWindowById(WC_VEHICLE_TIMETABLE
, v
->index
, false);
1797 if (BringWindowToFrontById(WC_VEHICLE_ORDERS
, v
->index
) != nullptr) return;
1799 /* Using a different WindowDescs for _local_company causes problems.
1800 * Due to this we have to close order windows in ChangeWindowOwner/CloseCompanyWindows,
1801 * because we cannot change switch the WindowDescs and keeping the old WindowDesc results
1802 * in crashed due to missing widges.
1803 * TODO Rewrite the order GUI to not use different WindowDescs.
1805 if (v
->owner
!= _local_company
) {
1806 new OrdersWindow(_other_orders_desc
, v
);
1808 new OrdersWindow(v
->IsGroundVehicle() ? _orders_train_desc
: _orders_desc
, v
);