4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file order_gui.cpp GUI related to orders. */
13 #include "command_func.h"
14 #include "viewport_func.h"
15 #include "depot_map.h"
16 #include "vehicle_gui.h"
18 #include "timetable.h"
19 #include "strings_func.h"
20 #include "window_func.h"
21 #include "company_func.h"
22 #include "widgets/dropdown_type.h"
23 #include "widgets/dropdown_func.h"
24 #include "textbuf_gui.h"
25 #include "string_func.h"
26 #include "tilehighlight_func.h"
27 #include "network/network.h"
28 #include "station_base.h"
29 #include "waypoint_base.h"
30 #include "core/geometry_func.hpp"
33 #include "table/strings.h"
35 /** Widget numbers of the order window. */
36 enum OrderWindowWidgets
{
38 ORDER_WIDGET_TIMETABLE_VIEW
,
39 ORDER_WIDGET_ORDER_LIST
,
40 ORDER_WIDGET_SCROLLBAR
,
43 ORDER_WIDGET_STOP_SHARING
,
44 ORDER_WIDGET_NON_STOP
,
46 ORDER_WIDGET_FULL_LOAD
,
50 ORDER_WIDGET_COND_VARIABLE
,
51 ORDER_WIDGET_COND_COMPARATOR
,
52 ORDER_WIDGET_COND_VALUE
,
53 ORDER_WIDGET_SEL_TOP_LEFT
, ///< #NWID_SELECTION widget for left part of the top row of the 'your train' order window.
54 ORDER_WIDGET_SEL_TOP_MIDDLE
, ///< #NWID_SELECTION widget for middle part of the top row of the 'your train' order window.
55 ORDER_WIDGET_SEL_TOP_RIGHT
, ///< #NWID_SELECTION widget for right part of the top row of the 'your train' order window.
56 ORDER_WIDGET_SEL_TOP_ROW
, ///< #NWID_SELECTION widget for the top row of the 'your non-trains' order window.
57 ORDER_WIDGET_SEL_BOTTOM_MIDDLE
, ///< #NWID_SELECTION widget for the middle part of the bottom row of the 'your train' order window.
58 ORDER_WIDGET_SHARED_ORDER_LIST
,
61 /** Order load types that could be given to station orders. */
62 static const StringID _station_load_types
[][5] = {
67 STR_ORDER_FULL_LOAD_ANY
,
72 STR_ORDER_UNLOAD_FULL_LOAD
,
73 STR_ORDER_UNLOAD_FULL_LOAD_ANY
,
74 STR_ORDER_UNLOAD_NO_LOAD
,
78 STR_ORDER_TRANSFER_FULL_LOAD
,
79 STR_ORDER_TRANSFER_FULL_LOAD_ANY
,
80 STR_ORDER_TRANSFER_NO_LOAD
,
82 /* Unload and transfer do not work together. */
90 STR_ORDER_NO_UNLOAD_FULL_LOAD
,
91 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY
,
92 STR_ORDER_NO_UNLOAD_NO_LOAD
,
96 static const StringID _order_non_stop_drowdown
[] = {
98 STR_ORDER_GO_NON_STOP_TO
,
100 STR_ORDER_GO_NON_STOP_VIA
,
104 static const StringID _order_full_load_drowdown
[] = {
105 STR_ORDER_DROP_LOAD_IF_POSSIBLE
,
107 STR_ORDER_DROP_FULL_LOAD_ALL
,
108 STR_ORDER_DROP_FULL_LOAD_ANY
,
109 STR_ORDER_DROP_NO_LOADING
,
113 static const StringID _order_unload_drowdown
[] = {
114 STR_ORDER_DROP_UNLOAD_IF_ACCEPTED
,
115 STR_ORDER_DROP_UNLOAD
,
116 STR_ORDER_DROP_TRANSFER
,
118 STR_ORDER_DROP_NO_UNLOADING
,
122 static const StringID _order_goto_dropdown
[] = {
124 STR_ORDER_GO_TO_NEAREST_DEPOT
,
125 STR_ORDER_CONDITIONAL
,
130 static const StringID _order_goto_dropdown_aircraft
[] = {
132 STR_ORDER_GO_TO_NEAREST_HANGAR
,
133 STR_ORDER_CONDITIONAL
,
138 /** Variables for conditional orders; this defines the order of appearance in the dropdown box */
139 static const OrderConditionVariable _order_conditional_variable
[] = {
144 OCV_REMAINING_LIFETIME
,
145 OCV_REQUIRES_SERVICE
,
149 static const StringID _order_conditional_condition
[] = {
150 STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS
,
151 STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS
,
152 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN
,
153 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS
,
154 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN
,
155 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS
,
156 STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE
,
157 STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE
,
161 extern uint
ConvertSpeedToDisplaySpeed(uint speed
);
162 extern uint
ConvertDisplaySpeedToSpeed(uint speed
);
164 static const StringID _order_depot_action_dropdown
[] = {
165 STR_ORDER_DROP_GO_ALWAYS_DEPOT
,
166 STR_ORDER_DROP_SERVICE_DEPOT
,
167 STR_ORDER_DROP_HALT_DEPOT
,
171 static int DepotActionStringIndex(const Order
*order
)
173 if (order
->GetDepotActionType() & ODATFB_HALT
) {
175 } else if (order
->GetDepotOrderType() & ODTFB_SERVICE
) {
183 * Draws an order in order or timetable GUI
184 * @param v Vehicle the order belongs to
185 * @param order The order to draw
186 * @param order_index Index of the order in the orders of the vehicle
187 * @param y Y position for drawing
188 * @param selected True, if the order is selected
189 * @param timetable True, when drawing in the timetable GUI
190 * @param left Left border for text drawing
191 * @param middle X position between order index and order text
192 * @param right Right border for text drawing
194 void DrawOrderString(const Vehicle
*v
, const Order
*order
, int order_index
, int y
, bool selected
, bool timetable
, int left
, int middle
, int right
)
196 bool rtl
= _current_text_dir
== TD_RTL
;
198 SpriteID sprite
= rtl
? SPR_ARROW_LEFT
: SPR_ARROW_RIGHT
;
199 Dimension sprite_size
= GetSpriteSize(sprite
);
200 if (v
->cur_real_order_index
== order_index
) {
201 DrawSprite(sprite
, PAL_NONE
, rtl
? right
- sprite_size
.width
: left
, y
+ ((int)FONT_HEIGHT_NORMAL
- (int)sprite_size
.height
) / 2);
202 DrawSprite(sprite
, PAL_NONE
, rtl
? right
- 2 * sprite_size
.width
: left
+ sprite_size
.width
, y
+ ((int)FONT_HEIGHT_NORMAL
- (int)sprite_size
.height
) / 2);
203 } else if (v
->cur_implicit_order_index
== order_index
) {
204 DrawSprite(sprite
, PAL_NONE
, rtl
? right
- sprite_size
.width
: left
, y
+ ((int)FONT_HEIGHT_NORMAL
- (int)sprite_size
.height
) / 2);
207 TextColour colour
= TC_BLACK
;
208 if (order
->IsType(OT_IMPLICIT
)) {
209 colour
= (selected
? TC_SILVER
: TC_GREY
) | TC_NO_SHADE
;
210 } else if (selected
) {
214 SetDParam(0, order_index
+ 1);
215 DrawString(left
, rtl
? right
- 2 * sprite_size
.width
- 3 : middle
, y
, STR_ORDER_INDEX
, colour
, SA_RIGHT
| SA_FORCE
);
217 SetDParam(5, STR_EMPTY
);
219 switch (order
->GetType()) {
221 SetDParam(0, STR_INVALID_ORDER
);
222 SetDParam(1, order
->GetDestination());
226 SetDParam(0, STR_ORDER_GO_TO_STATION
);
227 SetDParam(1, STR_ORDER_GO_TO
);
228 SetDParam(2, order
->GetDestination());
229 SetDParam(3, timetable
? STR_EMPTY
: STR_ORDER_IMPLICIT
);
232 case OT_GOTO_STATION
: {
233 OrderLoadFlags load
= order
->GetLoadType();
234 OrderUnloadFlags unload
= order
->GetUnloadType();
236 SetDParam(0, STR_ORDER_GO_TO_STATION
);
237 SetDParam(1, STR_ORDER_GO_TO
+ (v
->IsGroundVehicle() ? order
->GetNonStopType() : 0));
238 SetDParam(2, order
->GetDestination());
241 SetDParam(3, STR_EMPTY
);
243 if (order
->wait_time
> 0) {
244 SetDParam(5, STR_TIMETABLE_STAY_FOR
);
245 SetTimetableParams(6, 7, order
->wait_time
);
248 SetDParam(3, (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) ? STR_EMPTY
: _station_load_types
[unload
][load
]);
249 if (v
->type
== VEH_TRAIN
&& (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) == 0) {
250 SetDParam(5, order
->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END
);
257 if (order
->GetDepotActionType() & ODATFB_NEAREST_DEPOT
) {
258 SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT
);
259 if (v
->type
== VEH_AIRCRAFT
) {
260 SetDParam(2, STR_ORDER_NEAREST_HANGAR
);
261 SetDParam(3, STR_EMPTY
);
263 SetDParam(2, STR_ORDER_NEAREST_DEPOT
);
264 SetDParam(3, STR_ORDER_TRAIN_DEPOT
+ v
->type
);
267 SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT
);
268 SetDParam(2, v
->type
);
269 SetDParam(3, order
->GetDestination());
272 if (order
->GetDepotOrderType() & ODTFB_SERVICE
) {
273 SetDParam(1, (order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
) ? STR_ORDER_SERVICE_NON_STOP_AT
: STR_ORDER_SERVICE_AT
);
275 SetDParam(1, (order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
) ? STR_ORDER_GO_NON_STOP_TO
: STR_ORDER_GO_TO
);
278 if (!timetable
&& (order
->GetDepotActionType() & ODATFB_HALT
)) {
279 SetDParam(5, STR_ORDER_STOP_ORDER
);
282 if (!timetable
&& order
->IsRefit()) {
283 SetDParam(5, (order
->GetDepotActionType() & ODATFB_HALT
) ? STR_ORDER_REFIT_STOP_ORDER
: STR_ORDER_REFIT_ORDER
);
284 SetDParam(6, CargoSpec::Get(order
->GetRefitCargo())->name
);
288 case OT_GOTO_WAYPOINT
:
289 SetDParam(0, (order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT
: STR_ORDER_GO_TO_WAYPOINT
);
290 SetDParam(1, order
->GetDestination());
294 SetDParam(1, order
->GetConditionSkipToOrder() + 1);
295 if (order
->GetConditionVariable() == OCV_UNCONDITIONALLY
) {
296 SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL
);
298 OrderConditionComparator occ
= order
->GetConditionComparator();
299 SetDParam(0, (occ
== OCC_IS_TRUE
|| occ
== OCC_IS_FALSE
) ? STR_ORDER_CONDITIONAL_TRUE_FALSE
: STR_ORDER_CONDITIONAL_NUM
);
300 SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE
+ order
->GetConditionVariable());
301 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS
+ occ
);
303 uint value
= order
->GetConditionValue();
304 if (order
->GetConditionVariable() == OCV_MAX_SPEED
) value
= ConvertSpeedToDisplaySpeed(value
);
308 if (timetable
&& order
->wait_time
> 0) {
309 SetDParam(5, STR_TIMETABLE_AND_TRAVEL_FOR
);
310 SetTimetableParams(6, 7, order
->wait_time
);
312 SetDParam(5, STR_EMPTY
);
316 default: NOT_REACHED();
319 DrawString(rtl
? left
: middle
, rtl
? middle
: right
, y
, STR_ORDER_TEXT
, colour
);
323 static Order
GetOrderCmdFromTile(const Vehicle
*v
, TileIndex tile
)
329 /* check depot first */
330 switch (GetTileType(tile
)) {
332 if (v
->type
== VEH_TRAIN
&& IsTileOwner(tile
, _local_company
)) {
333 if (IsRailDepot(tile
)) {
334 order
.MakeGoToDepot(GetDepotIndex(tile
), ODTFB_PART_OF_ORDERS
,
335 _settings_client
.gui
.new_nonstop
? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
: ONSF_STOP_EVERYWHERE
);
336 if (_ctrl_pressed
) order
.SetDepotOrderType((OrderDepotTypeFlags
)(order
.GetDepotOrderType() ^ ODTFB_SERVICE
));
343 if (IsRoadDepot(tile
) && v
->type
== VEH_ROAD
&& IsTileOwner(tile
, _local_company
)) {
344 order
.MakeGoToDepot(GetDepotIndex(tile
), ODTFB_PART_OF_ORDERS
,
345 _settings_client
.gui
.new_nonstop
? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
: ONSF_STOP_EVERYWHERE
);
346 if (_ctrl_pressed
) order
.SetDepotOrderType((OrderDepotTypeFlags
)(order
.GetDepotOrderType() ^ ODTFB_SERVICE
));
352 if (v
->type
!= VEH_AIRCRAFT
) break;
353 if (IsHangar(tile
) && IsTileOwner(tile
, _local_company
)) {
354 order
.MakeGoToDepot(GetStationIndex(tile
), ODTFB_PART_OF_ORDERS
, ONSF_STOP_EVERYWHERE
);
355 if (_ctrl_pressed
) order
.SetDepotOrderType((OrderDepotTypeFlags
)(order
.GetDepotOrderType() ^ ODTFB_SERVICE
));
361 if (v
->type
!= VEH_SHIP
) break;
362 if (IsShipDepot(tile
) && IsTileOwner(tile
, _local_company
)) {
363 order
.MakeGoToDepot(GetDepotIndex(tile
), ODTFB_PART_OF_ORDERS
, ONSF_STOP_EVERYWHERE
);
364 if (_ctrl_pressed
) order
.SetDepotOrderType((OrderDepotTypeFlags
)(order
.GetDepotOrderType() ^ ODTFB_SERVICE
));
374 if (IsRailWaypointTile(tile
) &&
375 v
->type
== VEH_TRAIN
&&
376 IsTileOwner(tile
, _local_company
)) {
377 order
.MakeGoToWaypoint(Waypoint::GetByTile(tile
)->index
);
378 if (_settings_client
.gui
.new_nonstop
!= _ctrl_pressed
) order
.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION
);
382 if ((IsBuoyTile(tile
) && v
->type
== VEH_SHIP
) || (IsRailWaypointTile(tile
) && v
->type
== VEH_TRAIN
)) {
383 order
.MakeGoToWaypoint(GetStationIndex(tile
));
387 if (IsTileType(tile
, MP_STATION
)) {
388 StationID st_index
= GetStationIndex(tile
);
389 const Station
*st
= Station::Get(st_index
);
391 if (st
->owner
== _local_company
|| st
->owner
== OWNER_NONE
) {
393 (facil
= FACIL_DOCK
, v
->type
== VEH_SHIP
) ||
394 (facil
= FACIL_TRAIN
, v
->type
== VEH_TRAIN
) ||
395 (facil
= FACIL_AIRPORT
, v
->type
== VEH_AIRCRAFT
) ||
396 (facil
= FACIL_BUS_STOP
, v
->type
== VEH_ROAD
&& RoadVehicle::From(v
)->IsBus()) ||
397 (facil
= FACIL_TRUCK_STOP
, 1);
398 if (st
->facilities
& facil
) {
399 order
.MakeGoToStation(st_index
);
400 if (_ctrl_pressed
) order
.SetLoadType(OLF_FULL_LOAD_ANY
);
401 if (_settings_client
.gui
.new_nonstop
&& v
->IsGroundVehicle()) order
.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
);
402 order
.SetStopLocation(v
->type
== VEH_TRAIN
? (OrderStopLocation
)(_settings_client
.gui
.stop_location
) : OSL_PLATFORM_FAR_END
);
414 * %Order window code for all vehicles.
416 * At the bottom of the window two button rows are located for changing the orders of the vehicle.
418 * \section top-row Top row
419 * 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.
421 * The top-row buttons of one of your trains or road vehicles is one of the following three cases:
423 * +-----------------+-----------------+-----------------+
424 * | NON-STOP | FULL_LOAD | UNLOAD | (normal)
425 * +-----------------+-----------------+-----------------+
426 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
427 * +-----------------+-----------------+-----------------+
428 * | NON-STOP | REFIT | SERVICE | (for depot orders)
429 * +-----------------+-----------------+-----------------+
432 * Airplanes and ships have one of the following three top-row button rows:
434 * +--------------------------+--------------------------+
435 * | FULL_LOAD | UNLOAD | (normal)
436 * +-----------------+--------+--------+-----------------+
437 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
438 * +-----------------+--------+--------+-----------------+
439 * | REFIT | SERVICE | (for depot order)
440 * +--------------------------+--------------------------+
443 * \section bottom-row Bottom row
444 * The second row (the bottom row) is for manipulating the list of orders:
446 * +-----------------+-----------------+-----------------+
447 * | SKIP | DELETE | GOTO |
448 * +-----------------+-----------------+-----------------+
451 * For vehicles of other companies, both button rows are not displayed.
453 struct OrdersWindow
: public Window
{
455 /** Under what reason are we using the PlaceObject functionality? */
456 enum OrderPlaceObjectState
{
462 /** Displayed planes of the #NWID_SELECTION widgets. */
464 /* ORDER_WIDGET_SEL_TOP_LEFT */
465 DP_LEFT_NONSTOP
= 0, ///< Display 'non stop' in the left button of the top row of the train/rv order window.
466 DP_LEFT_CONDVAR
= 1, ///< Display condition variable in the left button of the top row of the train/rv order window.
468 /* ORDER_WIDGET_SEL_TOP_MIDDLE */
469 DP_MIDDLE_LOAD
= 0, ///< Display 'load' in the middle button of the top row of the train/rv order window.
470 DP_MIDDLE_REFIT
= 1, ///< Display 'refit' in the middle button of the top row of the train/rv order window.
471 DP_MIDDLE_COMPARE
= 2, ///< Display compare operator in the middle button of the top row of the train/rv order window.
473 /* ORDER_WIDGET_SEL_TOP_RIGHT */
474 DP_RIGHT_UNLOAD
= 0, ///< Display 'unload' in the right button of the top row of the train/rv order window.
475 DP_RIGHT_SERVICE
= 1, ///< Display 'service' in the right button of the top row of the train/rv order window.
476 DP_RIGHT_CONDVAL
= 2, ///< Display condition value in the right button of the top row of the train/rv order window.
478 /* ORDER_WIDGET_SEL_TOP_ROW */
479 DP_ROW_LOAD
= 0, ///< Display 'load' / 'unload' buttons in the top row of the ship/airplane order window.
480 DP_ROW_DEPOT
= 1, ///< Display 'refit' / 'service' buttons in the top row of the ship/airplane order window.
481 DP_ROW_CONDITIONAL
= 2, ///< Display the conditional order buttons in the top row of the ship/airplane order window.
483 /* ORDER_WIDGET_SEL_BOTTOM_MIDDLE */
484 DP_BOTTOM_MIDDLE_DELETE
= 0, ///< Display 'delete' in the middle button of the bottom row of the vehicle order window.
485 DP_BOTTOM_MIDDLE_STOP_SHARING
= 1, ///< Display 'stop sharing' in the middle button of the bottom row of the vehicle order window.
489 VehicleOrderID order_over
; ///< Order over which another order is dragged, \c INVALID_VEH_ORDER_ID if none.
490 OrderPlaceObjectState goto_type
;
491 const Vehicle
*vehicle
; ///< Vehicle owning the orders being displayed and manipulated.
495 * Return the memorised selected order.
496 * @return the memorised order if it is a vaild one
497 * else return the number of orders
499 VehicleOrderID
OrderGetSel() const
501 int num
= this->selected_order
;
502 return (num
>= 0 && num
< vehicle
->GetNumOrders()) ? num
: vehicle
->GetNumOrders();
506 * Calculate the selected order.
507 * The calculation is based on the relative (to the window) y click position and
508 * the position of the scrollbar.
510 * @param y Y-value of the click relative to the window origin
511 * @return The selected order if the order is valid, else return \c INVALID_VEH_ORDER_ID.
513 VehicleOrderID
GetOrderFromPt(int y
)
515 NWidgetBase
*nwid
= this->GetWidget
<NWidgetBase
>(ORDER_WIDGET_ORDER_LIST
);
516 int sel
= (y
- nwid
->pos_y
- WD_FRAMERECT_TOP
) / nwid
->resize_y
; // Selected line in the ORDER_WIDGET_ORDER_LIST panel.
518 if ((uint
)sel
>= this->vscroll
->GetCapacity()) return INVALID_VEH_ORDER_ID
;
520 sel
+= this->vscroll
->GetPosition();
522 return (sel
<= vehicle
->GetNumOrders() && sel
>= 0) ? sel
: INVALID_VEH_ORDER_ID
;
526 * Handle the click on the goto button.
527 * @param i Dummy parameter.
529 void OrderClick_Goto(int i
)
531 this->SetWidgetDirty(ORDER_WIDGET_GOTO
);
532 this->ToggleWidgetLoweredState(ORDER_WIDGET_GOTO
);
533 if (this->IsWidgetLowered(ORDER_WIDGET_GOTO
)) {
534 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION
, PAL_NONE
, HT_RECT
| HT_VEHICLE
, this);
535 this->goto_type
= OPOS_GOTO
;
537 ResetObjectToPlace();
542 * Handle the click on the full load button.
543 * @param load_type the way to load.
545 void OrderClick_FullLoad(int load_type
)
547 VehicleOrderID sel_ord
= this->OrderGetSel();
548 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
550 if (order
== NULL
|| order
->GetLoadType() == load_type
) return;
553 load_type
= order
->GetLoadType() == OLF_LOAD_IF_POSSIBLE
? OLF_FULL_LOAD_ANY
: OLF_LOAD_IF_POSSIBLE
;
555 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel_ord
<< 20), MOF_LOAD
| (load_type
<< 4), CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
559 * Handle the 'no loading' hotkey
561 void OrderHotkey_NoLoad(int i
)
563 this->OrderClick_FullLoad(OLFB_NO_LOAD
);
567 * Handle the click on the service.
569 void OrderClick_Service(int i
)
571 VehicleOrderID sel_ord
= this->OrderGetSel();
574 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
575 if (order
== NULL
) return;
576 i
= (order
->GetDepotOrderType() & ODTFB_SERVICE
) ? DA_ALWAYS_GO
: DA_SERVICE
;
578 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel_ord
<< 20), MOF_DEPOT_ACTION
| (i
<< 4), CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
582 * Handle the click on the service in nearest depot button.
583 * @param i Dummy parameter.
585 void OrderClick_NearestDepot(int i
)
590 order
.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS
,
591 _settings_client
.gui
.new_nonstop
&& this->vehicle
->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
: ONSF_STOP_EVERYWHERE
);
592 order
.SetDepotActionType(ODATFB_NEAREST_DEPOT
);
594 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->OrderGetSel() << 20), order
.Pack(), CMD_INSERT_ORDER
| CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER
));
598 * Handle the click on the conditional order button.
599 * @param i Dummy parameter.
601 void OrderClick_Conditional(int i
)
603 this->LowerWidget(ORDER_WIDGET_GOTO
);
604 this->SetWidgetDirty(ORDER_WIDGET_GOTO
);
605 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION
, PAL_NONE
, HT_NONE
, this);
606 this->goto_type
= OPOS_CONDITIONAL
;
610 * Handle the click on the share button.
611 * @param i Dummy parameter.
613 void OrderClick_Share(int i
)
615 this->LowerWidget(ORDER_WIDGET_GOTO
);
616 this->SetWidgetDirty(ORDER_WIDGET_GOTO
);
617 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION
, PAL_NONE
, HT_VEHICLE
, this);
618 this->goto_type
= OPOS_SHARE
;
622 * Handle the click on the unload button.
624 void OrderClick_Unload(int unload_type
)
626 VehicleOrderID sel_ord
= this->OrderGetSel();
627 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
629 if (order
== NULL
|| order
->GetUnloadType() == unload_type
) return;
631 if (unload_type
< 0) {
632 unload_type
= order
->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE
? OUFB_UNLOAD
: OUF_UNLOAD_IF_POSSIBLE
;
635 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel_ord
<< 20), MOF_UNLOAD
| (unload_type
<< 4), CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
637 /* Transfer orders with leave empty as default */
638 if (unload_type
== OUFB_TRANSFER
) {
639 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel_ord
<< 20), MOF_LOAD
| (OLFB_NO_LOAD
<< 4), CMD_MODIFY_ORDER
);
640 this->SetWidgetDirty(ORDER_WIDGET_FULL_LOAD
);
645 * Handle the transfer hotkey
647 void OrderHotkey_Transfer(int i
)
649 this->OrderClick_Unload(OUFB_TRANSFER
);
653 * Handle the 'no unload' hotkey
655 void OrderHotkey_NoUnload(int i
)
657 this->OrderClick_Unload(OUFB_NO_UNLOAD
);
661 * Handle the click on the nonstop button.
662 * @param non_stop what non-stop type to use; -1 to use the 'next' one.
664 void OrderClick_Nonstop(int non_stop
)
666 if (!this->vehicle
->IsGroundVehicle()) return;
668 VehicleOrderID sel_ord
= this->OrderGetSel();
669 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
671 if (order
== NULL
|| order
->GetNonStopType() == non_stop
) return;
673 /* Keypress if negative, so 'toggle' to the next */
675 non_stop
= order
->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
;
678 this->SetWidgetDirty(ORDER_WIDGET_NON_STOP
);
679 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel_ord
<< 20), MOF_NON_STOP
| non_stop
<< 4, CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
683 * Handle the click on the skip button.
684 * If ctrl is pressed, skip to selected order, else skip to current order + 1
685 * @param i Dummy parameter.
687 void OrderClick_Skip(int i
)
689 /* Don't skip when there's nothing to skip */
690 if (_ctrl_pressed
&& this->vehicle
->cur_implicit_order_index
== this->OrderGetSel()) return;
691 if (this->vehicle
->GetNumOrders() <= 1) return;
693 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
, _ctrl_pressed
? this->OrderGetSel() : ((this->vehicle
->cur_implicit_order_index
+ 1) % this->vehicle
->GetNumOrders()),
694 CMD_SKIP_TO_ORDER
| CMD_MSG(_ctrl_pressed
? STR_ERROR_CAN_T_SKIP_TO_ORDER
: STR_ERROR_CAN_T_SKIP_ORDER
));
698 * Handle the click on the delete button.
699 * @param i Dummy parameter.
701 void OrderClick_Delete(int i
)
703 /* When networking, move one order lower */
704 int selected
= this->selected_order
+ (int)_networking
;
706 if (DoCommandP(this->vehicle
->tile
, this->vehicle
->index
, this->OrderGetSel(), CMD_DELETE_ORDER
| CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER
))) {
707 this->selected_order
= selected
>= this->vehicle
->GetNumOrders() ? -1 : selected
;
708 this->UpdateButtonState();
713 * Handle the click on the 'stop sharing' button.
714 * If 'End of Shared Orders' isn't selected, do nothing. If Ctrl is pressed, call OrderClick_Delete and exit.
715 * To stop sharing this vehicle order list, we copy the orders of a vehicle that share this order list. That way we
716 * exit the group of shared vehicles while keeping the same order list.
717 * @param i Dummy parameter.
719 void OrderClick_StopSharing(int i
)
721 /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
722 if (!this->vehicle
->IsOrderListShared() || this->selected_order
!= this->vehicle
->GetNumOrders()) return;
723 /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
725 this->OrderClick_Delete(0);
729 /* Get another vehicle that share orders with this vehicle. */
730 Vehicle
*other_shared
= (this->vehicle
->FirstShared() == this->vehicle
) ? this->vehicle
->NextShared() : this->vehicle
->PreviousShared();
731 /* Copy the order list of the other vehicle. */
732 if (DoCommandP(this->vehicle
->tile
, this->vehicle
->index
| CO_COPY
<< 30, other_shared
->index
, CMD_CLONE_ORDER
| CMD_MSG(STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST
))) {
733 this->UpdateButtonState();
738 * Handle the click on the refit button.
739 * If ctrl is pressed, cancel refitting, else show the refit window.
740 * @param i Dummy parameter.
742 void OrderClick_Refit(int i
)
745 /* Cancel refitting */
746 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
, (this->OrderGetSel() << 16) | (CT_NO_REFIT
<< 8) | CT_NO_REFIT
, CMD_ORDER_REFIT
);
748 ShowVehicleRefitWindow(this->vehicle
, this->OrderGetSel(), this);
753 OrdersWindow(const WindowDesc
*desc
, const Vehicle
*v
) : Window()
757 this->CreateNestedTree(desc
);
758 this->vscroll
= this->GetScrollbar(ORDER_WIDGET_SCROLLBAR
);
759 this->FinishInitNested(desc
, v
->index
);
761 this->selected_order
= -1;
762 this->order_over
= INVALID_VEH_ORDER_ID
;
763 this->owner
= v
->owner
;
765 if (_settings_client
.gui
.quick_goto
&& v
->owner
== _local_company
) {
766 /* If there are less than 2 station, make Go To active. */
767 int station_orders
= 0;
769 FOR_VEHICLE_ORDERS(v
, order
) {
770 if (order
->IsType(OT_GOTO_STATION
)) station_orders
++;
773 if (station_orders
< 2) this->OrderClick_Goto(0);
775 this->OnInvalidateData(-2);
778 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
781 case ORDER_WIDGET_ORDER_LIST
:
782 resize
->height
= FONT_HEIGHT_NORMAL
;
783 size
->height
= 6 * resize
->height
+ WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
786 case ORDER_WIDGET_COND_VARIABLE
: {
787 Dimension d
= {0, 0};
788 for (uint i
= 0; i
< lengthof(_order_conditional_variable
); i
++) {
789 d
= maxdim(d
, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE
+ _order_conditional_variable
[i
]));
791 d
.width
+= padding
.width
;
792 d
.height
+= padding
.height
;
793 *size
= maxdim(*size
, d
);
797 case ORDER_WIDGET_COND_COMPARATOR
: {
798 Dimension d
= {0, 0};
799 for (int i
= 0; _order_conditional_condition
[i
] != INVALID_STRING_ID
; i
++) {
800 d
= maxdim(d
, GetStringBoundingBox(_order_conditional_condition
[i
]));
802 d
.width
+= padding
.width
;
803 d
.height
+= padding
.height
;
804 *size
= maxdim(*size
, d
);
811 * Some data on this window has become invalid.
812 * @param data Information about the changed data.
813 * @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.
815 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
817 VehicleOrderID from
= INVALID_VEH_ORDER_ID
;
818 VehicleOrderID to
= INVALID_VEH_ORDER_ID
;
822 /* Autoreplace replaced the vehicle */
823 this->vehicle
= Vehicle::Get(this->window_number
);
827 /* Removed / replaced all orders (after deleting / sharing) */
828 if (this->selected_order
== -1) break;
830 this->DeleteChildWindows();
831 HideDropDownMenu(this);
832 this->selected_order
= -1;
836 /* Some other order changes */
842 if (gui_scope
) break; // only do this once; from command scope
843 from
= GB(data
, 0, 8);
845 /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
846 * the order is being created / removed */
847 if (this->selected_order
== -1) break;
849 if (from
== to
) break; // no need to change anything
851 if (from
!= this->selected_order
) {
852 /* Moving from preceding order? */
853 this->selected_order
-= (int)(from
<= this->selected_order
);
854 /* Moving to preceding order? */
855 this->selected_order
+= (int)(to
<= this->selected_order
);
859 /* Now we are modifying the selected order */
860 if (to
== INVALID_VEH_ORDER_ID
) {
861 /* Deleting selected order */
862 this->DeleteChildWindows();
863 HideDropDownMenu(this);
864 this->selected_order
= -1;
868 /* Moving selected order */
869 this->selected_order
= to
;
873 this->vscroll
->SetCount(this->vehicle
->GetNumOrders() + 1);
874 if (gui_scope
) this->UpdateButtonState();
876 /* Scroll to the new order. */
877 if (from
== INVALID_VEH_ORDER_ID
&& to
!= INVALID_VEH_ORDER_ID
&& !this->vscroll
->IsVisible(to
)) {
878 this->vscroll
->ScrollTowards(to
);
882 void UpdateButtonState()
884 if (this->vehicle
->owner
!= _local_company
) return; // No buttons are displayed with competitor order windows.
886 bool shared_orders
= this->vehicle
->IsOrderListShared();
887 VehicleOrderID sel
= this->OrderGetSel();
888 const Order
*order
= this->vehicle
->GetOrder(sel
);
892 this->SetWidgetDisabledState(ORDER_WIDGET_SKIP
, this->vehicle
->GetNumOrders() <= 1);
894 /* delete / stop sharing */
895 NWidgetStacked
*delete_sel
= this->GetWidget
<NWidgetStacked
>(ORDER_WIDGET_SEL_BOTTOM_MIDDLE
);
896 if (shared_orders
&& this->selected_order
== this->vehicle
->GetNumOrders()) {
897 /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
898 delete_sel
->SetDisplayedPlane(DP_BOTTOM_MIDDLE_STOP_SHARING
);
900 /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
901 delete_sel
->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE
);
902 this->SetWidgetDisabledState(ORDER_WIDGET_DELETE
,
903 (uint
)this->vehicle
->GetNumOrders() + ((shared_orders
|| this->vehicle
->GetNumOrders() != 0) ? 1 : 0) <= (uint
)this->selected_order
);
905 /* Set the tooltip of the 'delete' button depending on whether the
906 * 'End of Orders' order or a regular order is selected. */
907 NWidgetCore
*nwi
= this->GetWidget
<NWidgetCore
>(ORDER_WIDGET_DELETE
);
908 if (this->selected_order
== this->vehicle
->GetNumOrders()) {
909 nwi
->SetDataTip(STR_ORDERS_DELETE_BUTTON
, STR_ORDERS_DELETE_ALL_TOOLTIP
);
911 nwi
->SetDataTip(STR_ORDERS_DELETE_BUTTON
, STR_ORDERS_DELETE_TOOLTIP
);
916 this->RaiseWidget(ORDER_WIDGET_FULL_LOAD
);
917 this->RaiseWidget(ORDER_WIDGET_UNLOAD
);
918 this->RaiseWidget(ORDER_WIDGET_SERVICE
);
920 /* Selection widgets. */
921 /* Train or road vehicle. */
922 NWidgetStacked
*left_sel
= this->GetWidget
<NWidgetStacked
>(ORDER_WIDGET_SEL_TOP_LEFT
);
923 NWidgetStacked
*middle_sel
= this->GetWidget
<NWidgetStacked
>(ORDER_WIDGET_SEL_TOP_MIDDLE
);
924 NWidgetStacked
*right_sel
= this->GetWidget
<NWidgetStacked
>(ORDER_WIDGET_SEL_TOP_RIGHT
);
925 /* Ship or airplane. */
926 NWidgetStacked
*row_sel
= this->GetWidget
<NWidgetStacked
>(ORDER_WIDGET_SEL_TOP_ROW
);
927 assert(row_sel
!= NULL
|| (left_sel
!= NULL
&& middle_sel
!= NULL
&& right_sel
!= NULL
));
931 if (row_sel
!= NULL
) {
932 row_sel
->SetDisplayedPlane(DP_ROW_LOAD
);
934 left_sel
->SetDisplayedPlane(DP_LEFT_NONSTOP
);
935 middle_sel
->SetDisplayedPlane(DP_MIDDLE_LOAD
);
936 right_sel
->SetDisplayedPlane(DP_RIGHT_UNLOAD
);
937 this->DisableWidget(ORDER_WIDGET_NON_STOP
);
938 this->RaiseWidget(ORDER_WIDGET_NON_STOP
);
940 this->DisableWidget(ORDER_WIDGET_FULL_LOAD
);
941 this->DisableWidget(ORDER_WIDGET_UNLOAD
);
943 this->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD
, (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) != 0); // full load
944 this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD
, (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) != 0); // unload
946 switch (order
->GetType()) {
947 case OT_GOTO_STATION
:
948 if (row_sel
!= NULL
) {
949 row_sel
->SetDisplayedPlane(DP_ROW_LOAD
);
951 left_sel
->SetDisplayedPlane(DP_LEFT_NONSTOP
);
952 middle_sel
->SetDisplayedPlane(DP_MIDDLE_LOAD
);
953 right_sel
->SetDisplayedPlane(DP_RIGHT_UNLOAD
);
954 this->EnableWidget(ORDER_WIDGET_NON_STOP
);
955 this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP
, order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
);
957 this->SetWidgetLoweredState(ORDER_WIDGET_FULL_LOAD
, order
->GetLoadType() == OLF_FULL_LOAD_ANY
);
958 this->SetWidgetLoweredState(ORDER_WIDGET_UNLOAD
, order
->GetUnloadType() == OUFB_UNLOAD
);
961 case OT_GOTO_WAYPOINT
:
962 if (row_sel
!= NULL
) {
963 row_sel
->SetDisplayedPlane(DP_ROW_LOAD
);
965 left_sel
->SetDisplayedPlane(DP_LEFT_NONSTOP
);
966 middle_sel
->SetDisplayedPlane(DP_MIDDLE_LOAD
);
967 right_sel
->SetDisplayedPlane(DP_RIGHT_UNLOAD
);
968 this->EnableWidget(ORDER_WIDGET_NON_STOP
);
969 this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP
, order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
);
971 this->DisableWidget(ORDER_WIDGET_FULL_LOAD
);
972 this->DisableWidget(ORDER_WIDGET_UNLOAD
);
976 if (row_sel
!= NULL
) {
977 row_sel
->SetDisplayedPlane(DP_ROW_DEPOT
);
979 left_sel
->SetDisplayedPlane(DP_LEFT_NONSTOP
);
980 middle_sel
->SetDisplayedPlane(DP_MIDDLE_REFIT
);
981 right_sel
->SetDisplayedPlane(DP_RIGHT_SERVICE
);
982 this->EnableWidget(ORDER_WIDGET_NON_STOP
);
983 this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP
, order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
);
985 /* Disable refit button if the order is no 'always go' order.
986 * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
987 this->SetWidgetDisabledState(ORDER_WIDGET_REFIT
, (order
->GetDepotOrderType() & ODTFB_SERVICE
) || (order
->GetDepotActionType() & ODATFB_HALT
));
988 this->SetWidgetLoweredState(ORDER_WIDGET_SERVICE
, order
->GetDepotOrderType() & ODTFB_SERVICE
);
991 case OT_CONDITIONAL
: {
992 if (row_sel
!= NULL
) {
993 row_sel
->SetDisplayedPlane(DP_ROW_CONDITIONAL
);
995 left_sel
->SetDisplayedPlane(DP_LEFT_CONDVAR
);
996 middle_sel
->SetDisplayedPlane(DP_MIDDLE_COMPARE
);
997 right_sel
->SetDisplayedPlane(DP_RIGHT_CONDVAL
);
999 OrderConditionVariable ocv
= order
->GetConditionVariable();
1000 /* Set the strings for the dropdown boxes. */
1001 this->GetWidget
<NWidgetCore
>(ORDER_WIDGET_COND_VARIABLE
)->widget_data
= STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE
+ (order
== NULL
? 0 : ocv
);
1002 this->GetWidget
<NWidgetCore
>(ORDER_WIDGET_COND_COMPARATOR
)->widget_data
= _order_conditional_condition
[order
== NULL
? 0 : order
->GetConditionComparator()];
1003 this->SetWidgetDisabledState(ORDER_WIDGET_COND_COMPARATOR
, ocv
== OCV_UNCONDITIONALLY
);
1004 this->SetWidgetDisabledState(ORDER_WIDGET_COND_VALUE
, ocv
== OCV_REQUIRES_SERVICE
|| ocv
== OCV_UNCONDITIONALLY
);
1008 default: // every other order
1009 if (row_sel
!= NULL
) {
1010 row_sel
->SetDisplayedPlane(DP_ROW_LOAD
);
1012 left_sel
->SetDisplayedPlane(DP_LEFT_NONSTOP
);
1013 middle_sel
->SetDisplayedPlane(DP_MIDDLE_LOAD
);
1014 right_sel
->SetDisplayedPlane(DP_RIGHT_UNLOAD
);
1015 this->DisableWidget(ORDER_WIDGET_NON_STOP
);
1017 this->DisableWidget(ORDER_WIDGET_FULL_LOAD
);
1018 this->DisableWidget(ORDER_WIDGET_UNLOAD
);
1023 /* Disable list of vehicles with the same shared orders if there is no list */
1024 this->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST
, !shared_orders
);
1029 virtual void OnPaint()
1031 if (this->vehicle
->owner
!= _local_company
) this->selected_order
= -1; // Disable selection any selected row at a competitor order window.
1032 this->DrawWidgets();
1035 virtual void DrawWidget(const Rect
&r
, int widget
) const
1037 if (widget
!= ORDER_WIDGET_ORDER_LIST
) return;
1039 bool rtl
= _current_text_dir
== TD_RTL
;
1041 int index_column_width
= GetStringBoundingBox(STR_ORDER_INDEX
).width
+ 2 * GetSpriteSize(rtl
? SPR_ARROW_RIGHT
: SPR_ARROW_LEFT
).width
+ 3;
1042 int middle
= rtl
? r
.right
- WD_FRAMETEXT_RIGHT
- index_column_width
: r
.left
+ WD_FRAMETEXT_LEFT
+ index_column_width
;
1044 int y
= r
.top
+ WD_FRAMERECT_TOP
;
1045 int line_height
= this->GetWidget
<NWidgetBase
>(ORDER_WIDGET_ORDER_LIST
)->resize_y
;
1047 int i
= this->vscroll
->GetPosition();
1048 const Order
*order
= this->vehicle
->GetOrder(i
);
1049 /* First draw the highlighting underground if it exists. */
1050 if (this->order_over
!= INVALID_VEH_ORDER_ID
) {
1051 while (order
!= NULL
) {
1052 /* Don't draw anything if it extends past the end of the window. */
1053 if (!this->vscroll
->IsVisible(i
)) break;
1055 if (i
!= this->selected_order
&& i
== this->order_over
) {
1056 /* Highlight dragged order destination. */
1057 int top
= (this->order_over
< this->selected_order
? y
: y
+ line_height
) - WD_FRAMERECT_TOP
;
1058 int bottom
= min(top
+ 2, r
.bottom
- WD_FRAMERECT_BOTTOM
);
1059 top
= max(top
- 3, r
.top
+ WD_FRAMERECT_TOP
);
1060 GfxFillRect(r
.left
+ WD_FRAMETEXT_LEFT
, top
, r
.right
- WD_FRAMETEXT_RIGHT
, bottom
, _colour_gradient
[COLOUR_GREY
][7]);
1066 order
= order
->next
;
1069 /* Reset counters for drawing the orders. */
1070 y
= r
.top
+ WD_FRAMERECT_TOP
;
1071 i
= this->vscroll
->GetPosition();
1072 order
= this->vehicle
->GetOrder(i
);
1075 /* Draw the orders. */
1076 while (order
!= NULL
) {
1077 /* Don't draw anything if it extends past the end of the window. */
1078 if (!this->vscroll
->IsVisible(i
)) break;
1080 DrawOrderString(this->vehicle
, order
, i
, y
, i
== this->selected_order
, false, r
.left
+ WD_FRAMETEXT_LEFT
, middle
, r
.right
- WD_FRAMETEXT_RIGHT
);
1084 order
= order
->next
;
1087 if (this->vscroll
->IsVisible(i
)) {
1088 StringID str
= this->vehicle
->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS
: STR_ORDERS_END_OF_ORDERS
;
1089 DrawString(rtl
? r
.left
+ WD_FRAMETEXT_LEFT
: middle
, rtl
? middle
: r
.right
- WD_FRAMETEXT_RIGHT
, y
, str
, (i
== this->selected_order
) ? TC_WHITE
: TC_BLACK
);
1093 virtual void SetStringParameters(int widget
) const
1096 case ORDER_WIDGET_COND_VALUE
: {
1097 VehicleOrderID sel
= this->OrderGetSel();
1098 const Order
*order
= this->vehicle
->GetOrder(sel
);
1100 if (order
!= NULL
&& order
->IsType(OT_CONDITIONAL
)) {
1101 uint value
= order
->GetConditionValue();
1102 if (order
->GetConditionVariable() == OCV_MAX_SPEED
) value
= ConvertSpeedToDisplaySpeed(value
);
1103 SetDParam(0, value
);
1108 case ORDER_WIDGET_CAPTION
:
1109 SetDParam(0, this->vehicle
->index
);
1114 virtual void OnClick(Point pt
, int widget
, int click_count
)
1117 case ORDER_WIDGET_ORDER_LIST
: {
1118 if (this->goto_type
== OPOS_CONDITIONAL
) {
1119 this->goto_type
= OPOS_GOTO
;
1120 VehicleOrderID order_id
= this->GetOrderFromPt(_cursor
.pos
.y
- this->top
);
1121 if (order_id
!= INVALID_VEH_ORDER_ID
) {
1125 order
.MakeConditional(order_id
);
1127 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->OrderGetSel() << 20), order
.Pack(), CMD_INSERT_ORDER
| CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER
));
1129 ResetObjectToPlace();
1133 VehicleOrderID sel
= this->GetOrderFromPt(pt
.y
);
1135 if (_ctrl_pressed
&& sel
< this->vehicle
->GetNumOrders()) {
1136 TileIndex xy
= this->vehicle
->GetOrder(sel
)->GetLocation(this->vehicle
);
1137 if (xy
!= INVALID_TILE
) ScrollMainWindowToTile(xy
);
1141 /* This order won't be selected any more, close all child windows and dropdowns */
1142 this->DeleteChildWindows();
1143 HideDropDownMenu(this);
1145 if (sel
== INVALID_VEH_ORDER_ID
|| this->vehicle
->owner
!= _local_company
) {
1146 /* Deselect clicked order */
1147 this->selected_order
= -1;
1148 } else if (sel
== this->selected_order
) {
1149 if (this->vehicle
->type
== VEH_TRAIN
&& sel
< this->vehicle
->GetNumOrders()) {
1150 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel
<< 20),
1151 MOF_STOP_LOCATION
| ((this->vehicle
->GetOrder(sel
)->GetStopLocation() + 1) % OSL_END
) << 4,
1152 CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
1155 /* Select clicked order */
1156 this->selected_order
= sel
;
1158 if (this->vehicle
->owner
== _local_company
) {
1159 /* Activate drag and drop */
1160 SetObjectToPlaceWnd(SPR_CURSOR_MOUSE
, PAL_NONE
, HT_DRAG
, this);
1164 this->UpdateButtonState();
1168 case ORDER_WIDGET_SKIP
:
1169 this->OrderClick_Skip(0);
1172 case ORDER_WIDGET_DELETE
:
1173 this->OrderClick_Delete(0);
1176 case ORDER_WIDGET_STOP_SHARING
:
1177 this->OrderClick_StopSharing(0);
1180 case ORDER_WIDGET_NON_STOP
:
1181 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1182 this->OrderClick_Nonstop(-1);
1184 const Order
*o
= this->vehicle
->GetOrder(this->OrderGetSel());
1185 ShowDropDownMenu(this, _order_non_stop_drowdown
, o
->GetNonStopType(), ORDER_WIDGET_NON_STOP
, 0,
1186 o
->IsType(OT_GOTO_STATION
) ? 0 : (o
->IsType(OT_GOTO_WAYPOINT
) ? 3 : 12));
1190 case ORDER_WIDGET_GOTO
:
1191 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1192 this->OrderClick_Goto(0);
1194 ShowDropDownMenu(this, this->vehicle
->type
== VEH_AIRCRAFT
? _order_goto_dropdown_aircraft
: _order_goto_dropdown
, 0, ORDER_WIDGET_GOTO
, 0, 0);
1198 case ORDER_WIDGET_FULL_LOAD
:
1199 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1200 this->OrderClick_FullLoad(-1);
1202 ShowDropDownMenu(this, _order_full_load_drowdown
, this->vehicle
->GetOrder(this->OrderGetSel())->GetLoadType(), ORDER_WIDGET_FULL_LOAD
, 0, 2);
1206 case ORDER_WIDGET_UNLOAD
:
1207 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1208 this->OrderClick_Unload(-1);
1210 ShowDropDownMenu(this, _order_unload_drowdown
, this->vehicle
->GetOrder(this->OrderGetSel())->GetUnloadType(), ORDER_WIDGET_UNLOAD
, 0, 8);
1214 case ORDER_WIDGET_REFIT
:
1215 this->OrderClick_Refit(0);
1218 case ORDER_WIDGET_SERVICE
:
1219 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1220 this->OrderClick_Service(-1);
1222 ShowDropDownMenu(this, _order_depot_action_dropdown
, DepotActionStringIndex(this->vehicle
->GetOrder(this->OrderGetSel())), ORDER_WIDGET_SERVICE
, 0, 0);
1226 case ORDER_WIDGET_TIMETABLE_VIEW
:
1227 ShowTimetableWindow(this->vehicle
);
1230 case ORDER_WIDGET_COND_VARIABLE
: {
1231 DropDownList
*list
= new DropDownList();
1232 for (uint i
= 0; i
< lengthof(_order_conditional_variable
); i
++) {
1233 list
->push_back(new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE
+ _order_conditional_variable
[i
], _order_conditional_variable
[i
], false));
1235 ShowDropDownList(this, list
, this->vehicle
->GetOrder(this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE
);
1239 case ORDER_WIDGET_COND_COMPARATOR
: {
1240 const Order
*o
= this->vehicle
->GetOrder(this->OrderGetSel());
1241 ShowDropDownMenu(this, _order_conditional_condition
, o
->GetConditionComparator(), ORDER_WIDGET_COND_COMPARATOR
, 0, (o
->GetConditionVariable() == OCV_REQUIRES_SERVICE
) ? 0x3F : 0xC0);
1245 case ORDER_WIDGET_COND_VALUE
: {
1246 const Order
*order
= this->vehicle
->GetOrder(this->OrderGetSel());
1247 uint value
= order
->GetConditionValue();
1248 if (order
->GetConditionVariable() == OCV_MAX_SPEED
) value
= ConvertSpeedToDisplaySpeed(value
);
1249 SetDParam(0, value
);
1250 ShowQueryString(STR_JUST_INT
, STR_ORDER_CONDITIONAL_VALUE_CAPT
, 5, this, CS_NUMERAL
, QSF_NONE
);
1254 case ORDER_WIDGET_SHARED_ORDER_LIST
:
1255 ShowVehicleListWindow(this->vehicle
);
1260 virtual void OnQueryTextFinished(char *str
)
1262 if (!StrEmpty(str
)) {
1263 VehicleOrderID sel
= this->OrderGetSel();
1264 uint value
= atoi(str
);
1266 switch (this->vehicle
->GetOrder(sel
)->GetConditionVariable()) {
1268 value
= ConvertDisplaySpeedToSpeed(value
);
1271 case OCV_RELIABILITY
:
1272 case OCV_LOAD_PERCENTAGE
:
1273 value
= Clamp(value
, 0, 100);
1279 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel
<< 20), MOF_COND_VALUE
| Clamp(value
, 0, 2047) << 4, CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
1283 virtual void OnDropdownSelect(int widget
, int index
)
1286 case ORDER_WIDGET_NON_STOP
:
1287 this->OrderClick_Nonstop(index
);
1290 case ORDER_WIDGET_FULL_LOAD
:
1291 this->OrderClick_FullLoad(index
);
1294 case ORDER_WIDGET_UNLOAD
:
1295 this->OrderClick_Unload(index
);
1298 case ORDER_WIDGET_GOTO
:
1300 case 0: this->OrderClick_Goto(0); break;
1301 case 1: this->OrderClick_NearestDepot(0); break;
1302 case 2: this->OrderClick_Conditional(0); break;
1303 case 3: this->OrderClick_Share(0); break;
1304 default: NOT_REACHED();
1308 case ORDER_WIDGET_SERVICE
:
1309 this->OrderClick_Service(index
);
1312 case ORDER_WIDGET_COND_VARIABLE
:
1313 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->OrderGetSel() << 20), MOF_COND_VARIABLE
| index
<< 4, CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
1316 case ORDER_WIDGET_COND_COMPARATOR
:
1317 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->OrderGetSel() << 20), MOF_COND_COMPARATOR
| index
<< 4, CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
1322 virtual void OnDragDrop(Point pt
, int widget
)
1325 case ORDER_WIDGET_ORDER_LIST
: {
1326 VehicleOrderID from_order
= this->OrderGetSel();
1327 VehicleOrderID to_order
= this->GetOrderFromPt(pt
.y
);
1329 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()) &&
1330 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
, from_order
| (to_order
<< 16), CMD_MOVE_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER
))) {
1331 this->selected_order
= -1;
1332 this->UpdateButtonState();
1337 case ORDER_WIDGET_DELETE
:
1338 this->OrderClick_Delete(0);
1341 case ORDER_WIDGET_STOP_SHARING
:
1342 this->OrderClick_StopSharing(0);
1346 ResetObjectToPlace();
1348 if (this->order_over
!= INVALID_VEH_ORDER_ID
) {
1349 /* End of drag-and-drop, hide dragged order destination highlight. */
1350 this->order_over
= INVALID_VEH_ORDER_ID
;
1351 this->SetWidgetDirty(ORDER_WIDGET_ORDER_LIST
);
1355 virtual EventState
OnKeyPress(uint16 key
, uint16 keycode
)
1357 if (this->vehicle
->owner
!= _local_company
) return ES_NOT_HANDLED
;
1359 return CheckHotkeyMatch
<OrdersWindow
>(order_hotkeys
, keycode
, this) != -1 ? ES_HANDLED
: ES_NOT_HANDLED
;
1362 virtual void OnPlaceObject(Point pt
, TileIndex tile
)
1364 if (this->goto_type
== OPOS_GOTO
) {
1365 const Order cmd
= GetOrderCmdFromTile(this->vehicle
, tile
);
1366 if (cmd
.IsType(OT_NOTHING
)) return;
1368 if (DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->OrderGetSel() << 20), cmd
.Pack(), CMD_INSERT_ORDER
| CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER
))) {
1369 /* With quick goto the Go To button stays active */
1370 if (!_settings_client
.gui
.quick_goto
) ResetObjectToPlace();
1375 virtual void OnVehicleSelect(const Vehicle
*v
)
1377 /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
1378 * We disallow copying orders of other vehicles if we already have at least one order entry
1379 * ourself as it easily copies orders of vehicles within a station when we mean the station.
1380 * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
1381 * TODO: give a warning message */
1382 bool share_order
= _ctrl_pressed
|| this->goto_type
== OPOS_SHARE
;
1383 if (this->vehicle
->GetNumOrders() != 0 && !share_order
) return;
1385 if (DoCommandP(this->vehicle
->tile
, this->vehicle
->index
| (share_order
? CO_SHARE
: CO_COPY
) << 30, v
->index
,
1386 share_order
? CMD_CLONE_ORDER
| CMD_MSG(STR_ERROR_CAN_T_SHARE_ORDER_LIST
) : CMD_CLONE_ORDER
| CMD_MSG(STR_ERROR_CAN_T_COPY_ORDER_LIST
))) {
1387 this->selected_order
= -1;
1388 ResetObjectToPlace();
1392 virtual void OnPlaceObjectAbort()
1394 this->RaiseWidget(ORDER_WIDGET_GOTO
);
1395 this->SetWidgetDirty(ORDER_WIDGET_GOTO
);
1397 /* Remove drag highlighting if it exists. */
1398 if (this->order_over
!= INVALID_VEH_ORDER_ID
) {
1399 this->order_over
= INVALID_VEH_ORDER_ID
;
1400 this->SetWidgetDirty(ORDER_WIDGET_ORDER_LIST
);
1404 virtual void OnMouseDrag(Point pt
, int widget
)
1406 if (this->selected_order
!= -1 && widget
== ORDER_WIDGET_ORDER_LIST
) {
1407 /* An order is dragged.. */
1408 VehicleOrderID from_order
= this->OrderGetSel();
1409 VehicleOrderID to_order
= this->GetOrderFromPt(pt
.y
);
1410 uint num_orders
= this->vehicle
->GetNumOrders();
1412 if (from_order
!= INVALID_VEH_ORDER_ID
&& from_order
<= num_orders
) {
1413 if (to_order
!= INVALID_VEH_ORDER_ID
&& to_order
<= num_orders
) { // ..over an existing order.
1414 this->order_over
= to_order
;
1415 this->SetWidgetDirty(widget
);
1416 } else if (from_order
!= to_order
&& this->order_over
!= INVALID_VEH_ORDER_ID
) { // ..outside of the order list.
1417 this->order_over
= INVALID_VEH_ORDER_ID
;
1418 this->SetWidgetDirty(widget
);
1424 virtual void OnResize()
1426 /* Update the scroll bar */
1427 this->vscroll
->SetCapacityFromWidget(this, ORDER_WIDGET_ORDER_LIST
);
1430 virtual void OnTimeout()
1432 static const int raise_widgets
[] = {
1433 ORDER_WIDGET_TIMETABLE_VIEW
, ORDER_WIDGET_SKIP
, ORDER_WIDGET_DELETE
, ORDER_WIDGET_STOP_SHARING
, ORDER_WIDGET_REFIT
, ORDER_WIDGET_SHARED_ORDER_LIST
, WIDGET_LIST_END
,
1436 /* Unclick all buttons in raise_widgets[]. */
1437 for (const int *widnum
= raise_widgets
; *widnum
!= WIDGET_LIST_END
; widnum
++) {
1438 if (this->IsWidgetLowered(*widnum
)) {
1439 this->RaiseWidget(*widnum
);
1440 this->SetWidgetDirty(*widnum
);
1445 static Hotkey
<OrdersWindow
> order_hotkeys
[];
1448 Hotkey
<OrdersWindow
> OrdersWindow::order_hotkeys
[] = {
1449 Hotkey
<OrdersWindow
>('D', "skip", 0, &OrdersWindow::OrderClick_Skip
),
1450 Hotkey
<OrdersWindow
>('F', "delete", 0, &OrdersWindow::OrderClick_Delete
),
1451 Hotkey
<OrdersWindow
>('G', "goto", 0, &OrdersWindow::OrderClick_Goto
),
1452 Hotkey
<OrdersWindow
>('H', "nonstop", 0, &OrdersWindow::OrderClick_Nonstop
),
1453 Hotkey
<OrdersWindow
>('J', "fullload", 0, &OrdersWindow::OrderClick_FullLoad
),
1454 Hotkey
<OrdersWindow
>('K', "unload", 0, &OrdersWindow::OrderClick_Unload
),
1455 Hotkey
<OrdersWindow
>((uint16
)0, "nearest_depot", 0, &OrdersWindow::OrderClick_NearestDepot
),
1456 Hotkey
<OrdersWindow
>((uint16
)0, "always_service", 0, &OrdersWindow::OrderClick_Service
),
1457 Hotkey
<OrdersWindow
>((uint16
)0, "force_unload", 0, &OrdersWindow::OrderClick_Unload
),
1458 Hotkey
<OrdersWindow
>((uint16
)0, "transfer", 0, &OrdersWindow::OrderHotkey_Transfer
),
1459 Hotkey
<OrdersWindow
>((uint16
)0, "no_unload", 0, &OrdersWindow::OrderHotkey_NoUnload
),
1460 Hotkey
<OrdersWindow
>((uint16
)0, "no_load", 0, &OrdersWindow::OrderHotkey_NoLoad
),
1461 HOTKEY_LIST_END(OrdersWindow
)
1463 Hotkey
<OrdersWindow
> *_order_hotkeys
= OrdersWindow::order_hotkeys
;
1465 /** Nested widget definition for "your" train orders. */
1466 static const NWidgetPart _nested_orders_train_widgets
[] = {
1467 NWidget(NWID_HORIZONTAL
),
1468 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1469 NWidget(WWT_CAPTION
, COLOUR_GREY
, ORDER_WIDGET_CAPTION
), SetDataTip(STR_ORDERS_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1470 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_TIMETABLE_VIEW
), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW
, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP
),
1471 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
1472 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
1474 NWidget(NWID_HORIZONTAL
),
1475 NWidget(WWT_PANEL
, COLOUR_GREY
, ORDER_WIDGET_ORDER_LIST
), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP
), SetResize(1, 1), SetScrollbar(ORDER_WIDGET_SCROLLBAR
), EndContainer(),
1476 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, ORDER_WIDGET_SCROLLBAR
),
1479 /* First button row. */
1480 NWidget(NWID_HORIZONTAL
),
1481 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1482 NWidget(NWID_SELECTION
, INVALID_COLOUR
, ORDER_WIDGET_SEL_TOP_LEFT
),
1483 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_NON_STOP
), SetMinimalSize(124, 12), SetFill(1, 0),
1484 SetDataTip(STR_ORDER_NON_STOP
, STR_ORDER_TOOLTIP_NON_STOP
), SetResize(1, 0),
1485 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_COND_VARIABLE
), SetMinimalSize(124, 12), SetFill(1, 0),
1486 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP
), SetResize(1, 0),
1488 NWidget(NWID_SELECTION
, INVALID_COLOUR
, ORDER_WIDGET_SEL_TOP_MIDDLE
),
1489 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_FULL_LOAD
), SetMinimalSize(124, 12), SetFill(1, 0),
1490 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD
, STR_ORDER_TOOLTIP_FULL_LOAD
), SetResize(1, 0),
1491 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_REFIT
), SetMinimalSize(124, 12), SetFill(1, 0),
1492 SetDataTip(STR_ORDER_REFIT
, STR_ORDER_REFIT_TOOLTIP
), SetResize(1, 0),
1493 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_COND_COMPARATOR
), SetMinimalSize(124, 12), SetFill(1, 0),
1494 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP
), SetResize(1, 0),
1496 NWidget(NWID_SELECTION
, INVALID_COLOUR
, ORDER_WIDGET_SEL_TOP_RIGHT
),
1497 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_UNLOAD
), SetMinimalSize(124, 12), SetFill(1, 0),
1498 SetDataTip(STR_ORDER_TOGGLE_UNLOAD
, STR_ORDER_TOOLTIP_UNLOAD
), SetResize(1, 0),
1499 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_SERVICE
), SetMinimalSize(124, 12), SetFill(1, 0),
1500 SetDataTip(STR_ORDER_SERVICE
, STR_ORDER_SERVICE_TOOLTIP
), SetResize(1, 0),
1501 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_COND_VALUE
), SetMinimalSize(124, 12), SetFill(1, 0),
1502 SetDataTip(STR_BLACK_COMMA
, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP
), SetResize(1, 0),
1505 NWidget(WWT_PUSHIMGBTN
, COLOUR_GREY
, ORDER_WIDGET_SHARED_ORDER_LIST
), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON
, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP
),
1508 /* Second button row. */
1509 NWidget(NWID_HORIZONTAL
),
1510 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1511 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_SKIP
), SetMinimalSize(124, 12), SetFill(1, 0),
1512 SetDataTip(STR_ORDERS_SKIP_BUTTON
, STR_ORDERS_SKIP_TOOLTIP
), SetResize(1, 0),
1513 NWidget(NWID_SELECTION
, INVALID_COLOUR
, ORDER_WIDGET_SEL_BOTTOM_MIDDLE
),
1514 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_DELETE
), SetMinimalSize(124, 12), SetFill(1, 0),
1515 SetDataTip(STR_ORDERS_DELETE_BUTTON
, STR_ORDERS_DELETE_TOOLTIP
), SetResize(1, 0),
1516 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_STOP_SHARING
), SetMinimalSize(124, 12), SetFill(1, 0),
1517 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON
, STR_ORDERS_STOP_SHARING_TOOLTIP
), SetResize(1, 0),
1519 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_GOTO
), SetMinimalSize(124, 12), SetFill(1, 0),
1520 SetDataTip(STR_ORDERS_GO_TO_BUTTON
, STR_ORDERS_GO_TO_TOOLTIP
), SetResize(1, 0),
1522 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
1526 static const WindowDesc
_orders_train_desc(
1528 WC_VEHICLE_ORDERS
, WC_VEHICLE_VIEW
,
1530 _nested_orders_train_widgets
, lengthof(_nested_orders_train_widgets
)
1533 /** Nested widget definition for "your" orders (non-train). */
1534 static const NWidgetPart _nested_orders_widgets
[] = {
1535 NWidget(NWID_HORIZONTAL
),
1536 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1537 NWidget(WWT_CAPTION
, COLOUR_GREY
, ORDER_WIDGET_CAPTION
), SetDataTip(STR_ORDERS_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1538 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_TIMETABLE_VIEW
), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW
, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP
),
1539 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
1540 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
1542 NWidget(NWID_HORIZONTAL
),
1543 NWidget(WWT_PANEL
, COLOUR_GREY
, ORDER_WIDGET_ORDER_LIST
), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP
), SetResize(1, 1), SetScrollbar(ORDER_WIDGET_SCROLLBAR
), EndContainer(),
1544 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, ORDER_WIDGET_SCROLLBAR
),
1547 /* First button row. */
1548 NWidget(NWID_HORIZONTAL
),
1549 NWidget(NWID_SELECTION
, INVALID_COLOUR
, ORDER_WIDGET_SEL_TOP_ROW
),
1550 /* load + unload buttons. */
1551 NWidget(NWID_HORIZONTAL
),
1552 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_FULL_LOAD
), SetMinimalSize(186, 12), SetFill(1, 0),
1553 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD
, STR_ORDER_TOOLTIP_FULL_LOAD
), SetResize(1, 0),
1554 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_UNLOAD
), SetMinimalSize(186, 12), SetFill(1, 0),
1555 SetDataTip(STR_ORDER_TOGGLE_UNLOAD
, STR_ORDER_TOOLTIP_UNLOAD
), SetResize(1, 0),
1557 /* Refit + service buttons. */
1558 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1559 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_REFIT
), SetMinimalSize(186, 12), SetFill(1, 0),
1560 SetDataTip(STR_ORDER_REFIT
, STR_ORDER_REFIT_TOOLTIP
), SetResize(1, 0),
1561 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_SERVICE
), SetMinimalSize(124, 12), SetFill(1, 0),
1562 SetDataTip(STR_ORDER_SERVICE
, STR_ORDER_SERVICE_TOOLTIP
), SetResize(1, 0),
1565 /* Buttons for setting a condition. */
1566 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1567 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_COND_VARIABLE
), SetMinimalSize(124, 12), SetFill(1, 0),
1568 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP
), SetResize(1, 0),
1569 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_COND_COMPARATOR
), SetMinimalSize(124, 12), SetFill(1, 0),
1570 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP
), SetResize(1, 0),
1571 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_COND_VALUE
), SetMinimalSize(124, 12), SetFill(1, 0),
1572 SetDataTip(STR_BLACK_COMMA
, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP
), SetResize(1, 0),
1576 NWidget(WWT_PUSHIMGBTN
, COLOUR_GREY
, ORDER_WIDGET_SHARED_ORDER_LIST
), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON
, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP
),
1579 /* Second button row. */
1580 NWidget(NWID_HORIZONTAL
),
1581 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_SKIP
), SetMinimalSize(124, 12), SetFill(1, 0),
1582 SetDataTip(STR_ORDERS_SKIP_BUTTON
, STR_ORDERS_SKIP_TOOLTIP
), SetResize(1, 0),
1583 NWidget(NWID_SELECTION
, INVALID_COLOUR
, ORDER_WIDGET_SEL_BOTTOM_MIDDLE
),
1584 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_DELETE
), SetMinimalSize(124, 12), SetFill(1, 0),
1585 SetDataTip(STR_ORDERS_DELETE_BUTTON
, STR_ORDERS_DELETE_TOOLTIP
), SetResize(1, 0),
1586 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_STOP_SHARING
), SetMinimalSize(124, 12), SetFill(1, 0),
1587 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON
, STR_ORDERS_STOP_SHARING_TOOLTIP
), SetResize(1, 0),
1589 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, ORDER_WIDGET_GOTO
), SetMinimalSize(124, 12), SetFill(1, 0),
1590 SetDataTip(STR_ORDERS_GO_TO_BUTTON
, STR_ORDERS_GO_TO_TOOLTIP
), SetResize(1, 0),
1591 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
1595 static const WindowDesc
_orders_desc(
1597 WC_VEHICLE_ORDERS
, WC_VEHICLE_VIEW
,
1599 _nested_orders_widgets
, lengthof(_nested_orders_widgets
)
1602 /** Nested widget definition for competitor orders. */
1603 static const NWidgetPart _nested_other_orders_widgets
[] = {
1604 NWidget(NWID_HORIZONTAL
),
1605 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1606 NWidget(WWT_CAPTION
, COLOUR_GREY
, ORDER_WIDGET_CAPTION
), SetDataTip(STR_ORDERS_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1607 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, ORDER_WIDGET_TIMETABLE_VIEW
), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW
, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP
),
1608 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
1609 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
1611 NWidget(NWID_HORIZONTAL
),
1612 NWidget(WWT_PANEL
, COLOUR_GREY
, ORDER_WIDGET_ORDER_LIST
), SetMinimalSize(372, 72), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP
), SetResize(1, 1), SetScrollbar(ORDER_WIDGET_SCROLLBAR
), EndContainer(),
1613 NWidget(NWID_VERTICAL
),
1614 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, ORDER_WIDGET_SCROLLBAR
),
1615 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
1620 static const WindowDesc
_other_orders_desc(
1622 WC_VEHICLE_ORDERS
, WC_VEHICLE_VIEW
,
1623 WDF_UNCLICK_BUTTONS
| WDF_CONSTRUCTION
,
1624 _nested_other_orders_widgets
, lengthof(_nested_other_orders_widgets
)
1627 void ShowOrdersWindow(const Vehicle
*v
)
1629 DeleteWindowById(WC_VEHICLE_DETAILS
, v
->index
, false);
1630 DeleteWindowById(WC_VEHICLE_TIMETABLE
, v
->index
, false);
1631 if (BringWindowToFrontById(WC_VEHICLE_ORDERS
, v
->index
) != NULL
) return;
1633 if (v
->owner
!= _local_company
) {
1634 new OrdersWindow(&_other_orders_desc
, v
);
1636 new OrdersWindow(v
->IsGroundVehicle() ? &_orders_train_desc
: &_orders_desc
, v
);