(svn r27950) -Merge: Documentation updates from 1.7 branch
[openttd.git] / src / order_gui.cpp
blob9045fac6b54ce7ba984cb58b23fc9a76dc835164
1 /* $Id$ */
3 /*
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/>.
8 */
10 /** @file order_gui.cpp GUI related to orders. */
12 #include "stdafx.h"
13 #include "command_func.h"
14 #include "viewport_func.h"
15 #include "depot_map.h"
16 #include "roadveh.h"
17 #include "timetable.h"
18 #include "strings_func.h"
19 #include "company_func.h"
20 #include "widgets/dropdown_type.h"
21 #include "widgets/dropdown_func.h"
22 #include "textbuf_gui.h"
23 #include "string_func.h"
24 #include "tilehighlight_func.h"
25 #include "network/network.h"
26 #include "station_base.h"
27 #include "waypoint_base.h"
28 #include "core/geometry_func.hpp"
29 #include "hotkeys.h"
30 #include "aircraft.h"
31 #include "engine_func.h"
33 #include "widgets/order_widget.h"
35 #include "safeguards.h"
38 /** Order load types that could be given to station orders. */
39 static const StringID _station_load_types[][5][5] = {
41 /* No refitting. */
43 STR_EMPTY,
44 INVALID_STRING_ID,
45 STR_ORDER_FULL_LOAD,
46 STR_ORDER_FULL_LOAD_ANY,
47 STR_ORDER_NO_LOAD,
48 }, {
49 STR_ORDER_UNLOAD,
50 INVALID_STRING_ID,
51 STR_ORDER_UNLOAD_FULL_LOAD,
52 STR_ORDER_UNLOAD_FULL_LOAD_ANY,
53 STR_ORDER_UNLOAD_NO_LOAD,
54 }, {
55 STR_ORDER_TRANSFER,
56 INVALID_STRING_ID,
57 STR_ORDER_TRANSFER_FULL_LOAD,
58 STR_ORDER_TRANSFER_FULL_LOAD_ANY,
59 STR_ORDER_TRANSFER_NO_LOAD,
60 }, {
61 /* Unload and transfer do not work together. */
62 INVALID_STRING_ID,
63 INVALID_STRING_ID,
64 INVALID_STRING_ID,
65 INVALID_STRING_ID,
66 }, {
67 STR_ORDER_NO_UNLOAD,
68 INVALID_STRING_ID,
69 STR_ORDER_NO_UNLOAD_FULL_LOAD,
70 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
71 STR_ORDER_NO_UNLOAD_NO_LOAD,
73 }, {
74 /* With auto-refitting. No loading and auto-refitting do not work together. */
76 STR_ORDER_AUTO_REFIT,
77 INVALID_STRING_ID,
78 STR_ORDER_FULL_LOAD_REFIT,
79 STR_ORDER_FULL_LOAD_ANY_REFIT,
80 INVALID_STRING_ID,
81 }, {
82 STR_ORDER_UNLOAD_REFIT,
83 INVALID_STRING_ID,
84 STR_ORDER_UNLOAD_FULL_LOAD_REFIT,
85 STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT,
86 INVALID_STRING_ID,
87 }, {
88 STR_ORDER_TRANSFER_REFIT,
89 INVALID_STRING_ID,
90 STR_ORDER_TRANSFER_FULL_LOAD_REFIT,
91 STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT,
92 INVALID_STRING_ID,
93 }, {
94 /* Unload and transfer do not work together. */
95 INVALID_STRING_ID,
96 INVALID_STRING_ID,
97 INVALID_STRING_ID,
98 INVALID_STRING_ID,
99 }, {
100 STR_ORDER_NO_UNLOAD_REFIT,
101 INVALID_STRING_ID,
102 STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT,
103 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT,
104 INVALID_STRING_ID,
109 static const StringID _order_non_stop_drowdown[] = {
110 STR_ORDER_GO_TO,
111 STR_ORDER_GO_NON_STOP_TO,
112 STR_ORDER_GO_VIA,
113 STR_ORDER_GO_NON_STOP_VIA,
114 INVALID_STRING_ID
117 static const StringID _order_full_load_drowdown[] = {
118 STR_ORDER_DROP_LOAD_IF_POSSIBLE,
119 STR_EMPTY,
120 STR_ORDER_DROP_FULL_LOAD_ALL,
121 STR_ORDER_DROP_FULL_LOAD_ANY,
122 STR_ORDER_DROP_NO_LOADING,
123 INVALID_STRING_ID
126 static const StringID _order_unload_drowdown[] = {
127 STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
128 STR_ORDER_DROP_UNLOAD,
129 STR_ORDER_DROP_TRANSFER,
130 STR_EMPTY,
131 STR_ORDER_DROP_NO_UNLOADING,
132 INVALID_STRING_ID
135 static const StringID _order_goto_dropdown[] = {
136 STR_ORDER_GO_TO,
137 STR_ORDER_GO_TO_NEAREST_DEPOT,
138 STR_ORDER_CONDITIONAL,
139 STR_ORDER_SHARE,
140 INVALID_STRING_ID
143 static const StringID _order_goto_dropdown_aircraft[] = {
144 STR_ORDER_GO_TO,
145 STR_ORDER_GO_TO_NEAREST_HANGAR,
146 STR_ORDER_CONDITIONAL,
147 STR_ORDER_SHARE,
148 INVALID_STRING_ID
151 /** Variables for conditional orders; this defines the order of appearance in the dropdown box */
152 static const OrderConditionVariable _order_conditional_variable[] = {
153 OCV_LOAD_PERCENTAGE,
154 OCV_RELIABILITY,
155 OCV_MAX_SPEED,
156 OCV_AGE,
157 OCV_REMAINING_LIFETIME,
158 OCV_REQUIRES_SERVICE,
159 OCV_UNCONDITIONALLY,
162 static const StringID _order_conditional_condition[] = {
163 STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
164 STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
165 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
166 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
167 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
168 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
169 STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
170 STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
171 INVALID_STRING_ID,
174 extern uint ConvertSpeedToDisplaySpeed(uint speed);
175 extern uint ConvertDisplaySpeedToSpeed(uint speed);
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 INVALID_STRING_ID
184 static int DepotActionStringIndex(const Order *order)
186 if (order->GetDepotActionType() & ODATFB_HALT) {
187 return DA_STOP;
188 } else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
189 return DA_SERVICE;
190 } else {
191 return DA_ALWAYS_GO;
195 static const StringID _order_refit_action_dropdown[] = {
196 STR_ORDER_DROP_REFIT_AUTO,
197 STR_ORDER_DROP_REFIT_AUTO_ANY,
198 INVALID_STRING_ID
202 * Draws an order in order or timetable GUI
203 * @param v Vehicle the order belongs to
204 * @param order The order to draw
205 * @param order_index Index of the order in the orders of the vehicle
206 * @param y Y position for drawing
207 * @param selected True, if the order is selected
208 * @param timetable True, when drawing in the timetable GUI
209 * @param left Left border for text drawing
210 * @param middle X position between order index and order text
211 * @param right Right border for text drawing
213 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
215 bool rtl = _current_text_dir == TD_RTL;
217 SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT;
218 Dimension sprite_size = GetSpriteSize(sprite);
219 if (v->cur_real_order_index == order_index) {
220 DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
221 DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
222 } else if (v->cur_implicit_order_index == order_index) {
223 DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
226 TextColour colour = TC_BLACK;
227 if (order->IsType(OT_IMPLICIT)) {
228 colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
229 } else if (selected) {
230 colour = TC_WHITE;
233 SetDParam(0, order_index + 1);
234 DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, STR_ORDER_INDEX, colour, SA_RIGHT | SA_FORCE);
236 SetDParam(5, STR_EMPTY);
237 SetDParam(8, STR_EMPTY);
239 /* Check range for aircraft. */
240 if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
241 const Order *next = order->next != NULL ? order->next : v->GetFirstOrder();
242 if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) SetDParam(8, STR_ORDER_OUT_OF_RANGE);
245 switch (order->GetType()) {
246 case OT_DUMMY:
247 SetDParam(0, STR_INVALID_ORDER);
248 SetDParam(1, order->GetDestination());
249 break;
251 case OT_IMPLICIT:
252 SetDParam(0, STR_ORDER_GO_TO_STATION);
253 SetDParam(1, STR_ORDER_GO_TO);
254 SetDParam(2, order->GetDestination());
255 SetDParam(3, timetable ? STR_EMPTY : STR_ORDER_IMPLICIT);
256 break;
258 case OT_GOTO_STATION: {
259 OrderLoadFlags load = order->GetLoadType();
260 OrderUnloadFlags unload = order->GetUnloadType();
262 SetDParam(0, STR_ORDER_GO_TO_STATION);
263 SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
264 SetDParam(2, order->GetDestination());
266 if (timetable) {
267 SetDParam(3, STR_EMPTY);
269 if (order->GetWaitTime() > 0) {
270 SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR : STR_TIMETABLE_STAY_FOR_ESTIMATED);
271 SetTimetableParams(6, 7, order->GetWaitTime());
273 } else {
274 SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]);
275 if (order->IsRefit()) {
276 SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
278 if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
279 SetDParam(5, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
282 break;
285 case OT_GOTO_DEPOT:
286 if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
287 SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
288 if (v->type == VEH_AIRCRAFT) {
289 SetDParam(2, STR_ORDER_NEAREST_HANGAR);
290 SetDParam(3, STR_EMPTY);
291 } else {
292 SetDParam(2, STR_ORDER_NEAREST_DEPOT);
293 SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type);
295 } else {
296 SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT);
297 SetDParam(2, v->type);
298 SetDParam(3, order->GetDestination());
301 if (order->GetDepotOrderType() & ODTFB_SERVICE) {
302 SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
303 } else {
304 SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
307 if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
308 SetDParam(5, STR_ORDER_STOP_ORDER);
311 if (!timetable && order->IsRefit()) {
312 SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER);
313 SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name);
315 break;
317 case OT_GOTO_WAYPOINT:
318 SetDParam(0, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT);
319 SetDParam(1, order->GetDestination());
320 break;
322 case OT_CONDITIONAL:
323 SetDParam(1, order->GetConditionSkipToOrder() + 1);
324 if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
325 SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
326 } else {
327 OrderConditionComparator occ = order->GetConditionComparator();
328 SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM);
329 SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
330 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
332 uint value = order->GetConditionValue();
333 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
334 SetDParam(4, value);
337 if (timetable && order->GetWaitTime() > 0) {
338 SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_AND_TRAVEL_FOR : STR_TIMETABLE_AND_TRAVEL_FOR_ESTIMATED);
339 SetTimetableParams(6, 7, order->GetWaitTime());
340 } else {
341 SetDParam(5, STR_EMPTY);
343 break;
345 default: NOT_REACHED();
348 DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
352 * Get the order command a vehicle can do in a given tile.
353 * @param v Vehicle involved.
354 * @param tile Tile being queried.
355 * @return The order associated to vehicle v in given tile (or empty order if vehicle can do nothing in the tile).
357 static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
359 /* Hack-ish; unpack order 0, so everything gets initialised with either zero
360 * or a suitable default value for the variable. Then also override the index
361 * as it is not coming from a pool, so would be initialised. */
362 Order order(0);
363 order.index = 0;
365 /* check depot first */
366 if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) {
367 order.MakeGoToDepot(v->type == VEH_AIRCRAFT ? GetStationIndex(tile) : GetDepotIndex(tile),
368 ODTFB_PART_OF_ORDERS,
369 (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
371 if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
373 return order;
376 /* check rail waypoint */
377 if (IsRailWaypointTile(tile) &&
378 v->type == VEH_TRAIN &&
379 IsTileOwner(tile, _local_company)) {
380 order.MakeGoToWaypoint(GetStationIndex(tile));
381 if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
382 return order;
385 /* check buoy (no ownership) */
386 if (IsBuoyTile(tile) && v->type == VEH_SHIP) {
387 order.MakeGoToWaypoint(GetStationIndex(tile));
388 return order;
391 if (IsTileType(tile, MP_STATION)) {
392 StationID st_index = GetStationIndex(tile);
393 const Station *st = Station::Get(st_index);
395 if (st->owner == _local_company || st->owner == OWNER_NONE) {
396 byte facil;
397 (facil = FACIL_DOCK, v->type == VEH_SHIP) ||
398 (facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
399 (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
400 (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
401 (facil = FACIL_TRUCK_STOP, 1);
402 if (st->facilities & facil) {
403 order.MakeGoToStation(st_index);
404 if (_ctrl_pressed) order.SetLoadType(OLF_FULL_LOAD_ANY);
405 if (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
406 order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OSL_PLATFORM_FAR_END);
407 return order;
412 /* not found */
413 order.Free();
414 return order;
417 /** Hotkeys for order window. */
418 enum {
419 OHK_SKIP,
420 OHK_DELETE,
421 OHK_GOTO,
422 OHK_NONSTOP,
423 OHK_FULLLOAD,
424 OHK_UNLOAD,
425 OHK_NEAREST_DEPOT,
426 OHK_ALWAYS_SERVICE,
427 OHK_TRANSFER,
428 OHK_NO_UNLOAD,
429 OHK_NO_LOAD,
433 * %Order window code for all vehicles.
435 * At the bottom of the window two button rows are located for changing the orders of the vehicle.
437 * \section top-row Top row
438 * 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.
440 * The top-row buttons of one of your trains or road vehicles is one of the following three cases:
441 * \verbatim
442 * +-----------------+-----------------+-----------------+-----------------+
443 * | NON-STOP | FULL_LOAD | UNLOAD | REFIT | (normal)
444 * +-----------------+-----+-----------+-----------+-----+-----------------+
445 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
446 * +-----------------+-----+-----------+-----------+-----+-----------------+
447 * | NON-STOP | REFIT | SERVICE | (empty) | (for depot orders)
448 * +-----------------+-----------------+-----------------+-----------------+
449 * \endverbatim
451 * Airplanes and ships have one of the following three top-row button rows:
452 * \verbatim
453 * +-----------------+-----------------+-----------------+
454 * | FULL_LOAD | UNLOAD | REFIT | (normal)
455 * +-----------------+-----------------+-----------------+
456 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
457 * +-----------------+--------+--------+-----------------+
458 * | REFIT | SERVICE | (for depot order)
459 * +--------------------------+--------------------------+
460 * \endverbatim
462 * \section bottom-row Bottom row
463 * The second row (the bottom row) is for manipulating the list of orders:
464 * \verbatim
465 * +-----------------+-----------------+-----------------+
466 * | SKIP | DELETE | GOTO |
467 * +-----------------+-----------------+-----------------+
468 * \endverbatim
470 * For vehicles of other companies, both button rows are not displayed.
472 struct OrdersWindow : public Window {
473 private:
474 /** Under what reason are we using the PlaceObject functionality? */
475 enum OrderPlaceObjectState {
476 OPOS_NONE,
477 OPOS_GOTO,
478 OPOS_CONDITIONAL,
479 OPOS_SHARE,
480 OPOS_END,
483 /** Displayed planes of the #NWID_SELECTION widgets. */
484 enum DisplayPane {
485 /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
486 DP_GROUNDVEHICLE_ROW_NORMAL = 0, ///< Display the row for normal/depot orders in the top row of the train/rv order window.
487 DP_GROUNDVEHICLE_ROW_CONDITIONAL = 1, ///< Display the row for conditional orders in the top row of the train/rv order window.
489 /* WID_O_SEL_TOP_LEFT */
490 DP_LEFT_LOAD = 0, ///< Display 'load' in the left button of the top row of the train/rv order window.
491 DP_LEFT_REFIT = 1, ///< Display 'refit' in the left button of the top row of the train/rv order window.
493 /* WID_O_SEL_TOP_MIDDLE */
494 DP_MIDDLE_UNLOAD = 0, ///< Display 'unload' in the middle button of the top row of the train/rv order window.
495 DP_MIDDLE_SERVICE = 1, ///< Display 'service' in the middle button of the top row of the train/rv order window.
497 /* WID_O_SEL_TOP_RIGHT */
498 DP_RIGHT_EMPTY = 0, ///< Display an empty panel in the right button of the top row of the train/rv order window.
499 DP_RIGHT_REFIT = 1, ///< Display 'refit' in the right button of the top row of the train/rv order window.
501 /* WID_O_SEL_TOP_ROW */
502 DP_ROW_LOAD = 0, ///< Display 'load' / 'unload' / 'refit' buttons in the top row of the ship/airplane order window.
503 DP_ROW_DEPOT = 1, ///< Display 'refit' / 'service' buttons in the top row of the ship/airplane order window.
504 DP_ROW_CONDITIONAL = 2, ///< Display the conditional order buttons in the top row of the ship/airplane order window.
506 /* WID_O_SEL_BOTTOM_MIDDLE */
507 DP_BOTTOM_MIDDLE_DELETE = 0, ///< Display 'delete' in the middle button of the bottom row of the vehicle order window.
508 DP_BOTTOM_MIDDLE_STOP_SHARING = 1, ///< Display 'stop sharing' in the middle button of the bottom row of the vehicle order window.
511 int selected_order;
512 VehicleOrderID order_over; ///< Order over which another order is dragged, \c INVALID_VEH_ORDER_ID if none.
513 OrderPlaceObjectState goto_type;
514 const Vehicle *vehicle; ///< Vehicle owning the orders being displayed and manipulated.
515 Scrollbar *vscroll;
516 bool can_do_refit; ///< Vehicle chain can be refitted in depot.
517 bool can_do_autorefit; ///< Vehicle chain can be auto-refitted.
520 * Return the memorised selected order.
521 * @return the memorised order if it is a valid one
522 * else return the number of orders
524 VehicleOrderID OrderGetSel() const
526 int num = this->selected_order;
527 return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
531 * Calculate the selected order.
532 * The calculation is based on the relative (to the window) y click position and
533 * the position of the scrollbar.
535 * @param y Y-value of the click relative to the window origin
536 * @return The selected order if the order is valid, else return \c INVALID_VEH_ORDER_ID.
538 VehicleOrderID GetOrderFromPt(int y)
540 NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST);
541 int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
543 if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID;
545 sel += this->vscroll->GetPosition();
547 return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID;
551 * Handle the click on the goto button.
553 void OrderClick_Goto(OrderPlaceObjectState type)
555 assert(type > OPOS_NONE && type < OPOS_END);
557 static const HighLightStyle goto_place_style[OPOS_END - 1] = {
558 HT_RECT | HT_VEHICLE, // OPOS_GOTO
559 HT_NONE, // OPOS_CONDITIONAL
560 HT_VEHICLE, // OPOS_SHARE
562 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, goto_place_style[type - 1], this);
563 this->goto_type = type;
564 this->SetWidgetDirty(WID_O_GOTO);
568 * Handle the click on the full load button.
569 * @param load_type the way to load.
571 void OrderClick_FullLoad(int load_type)
573 VehicleOrderID sel_ord = this->OrderGetSel();
574 const Order *order = this->vehicle->GetOrder(sel_ord);
576 if (order == NULL || order->GetLoadType() == load_type) return;
578 if (load_type < 0) {
579 load_type = order->GetLoadType() == OLF_LOAD_IF_POSSIBLE ? OLF_FULL_LOAD_ANY : OLF_LOAD_IF_POSSIBLE;
581 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));
585 * Handle the 'no loading' hotkey
587 void OrderHotkey_NoLoad()
589 this->OrderClick_FullLoad(OLFB_NO_LOAD);
593 * Handle the click on the service.
595 void OrderClick_Service(int i)
597 VehicleOrderID sel_ord = this->OrderGetSel();
599 if (i < 0) {
600 const Order *order = this->vehicle->GetOrder(sel_ord);
601 if (order == NULL) return;
602 i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
604 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));
608 * Handle the click on the service in nearest depot button.
610 void OrderClick_NearestDepot()
612 Order order;
613 order.next = NULL;
614 order.index = 0;
615 order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS,
616 _settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
617 order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
619 DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
623 * Handle the click on the unload button.
625 void OrderClick_Unload(int unload_type)
627 VehicleOrderID sel_ord = this->OrderGetSel();
628 const Order *order = this->vehicle->GetOrder(sel_ord);
630 if (order == NULL || order->GetUnloadType() == unload_type) return;
632 if (unload_type < 0) {
633 unload_type = order->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE ? OUFB_UNLOAD : OUF_UNLOAD_IF_POSSIBLE;
636 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));
638 /* Transfer orders with leave empty as default */
639 if (unload_type == OUFB_TRANSFER) {
640 DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), CMD_MODIFY_ORDER);
641 this->SetWidgetDirty(WID_O_FULL_LOAD);
646 * Handle the transfer hotkey
648 void OrderHotkey_Transfer()
650 this->OrderClick_Unload(OUFB_TRANSFER);
654 * Handle the 'no unload' hotkey
656 void OrderHotkey_NoUnload()
658 this->OrderClick_Unload(OUFB_NO_UNLOAD);
662 * Handle the click on the nonstop button.
663 * @param non_stop what non-stop type to use; -1 to use the 'next' one.
665 void OrderClick_Nonstop(int non_stop)
667 if (!this->vehicle->IsGroundVehicle()) return;
669 VehicleOrderID sel_ord = this->OrderGetSel();
670 const Order *order = this->vehicle->GetOrder(sel_ord);
672 if (order == NULL || order->GetNonStopType() == non_stop) return;
674 /* Keypress if negative, so 'toggle' to the next */
675 if (non_stop < 0) {
676 non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
679 this->SetWidgetDirty(WID_O_NON_STOP);
680 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));
684 * Handle the click on the skip button.
685 * If ctrl is pressed, skip to selected order, else skip to current order + 1
687 void OrderClick_Skip()
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.
700 void OrderClick_Delete()
702 /* When networking, move one order lower */
703 int selected = this->selected_order + (int)_networking;
705 if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
706 this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
707 this->UpdateButtonState();
712 * Handle the click on the 'stop sharing' button.
713 * If 'End of Shared Orders' isn't selected, do nothing. If Ctrl is pressed, call OrderClick_Delete and exit.
714 * To stop sharing this vehicle order list, we copy the orders of a vehicle that share this order list. That way we
715 * exit the group of shared vehicles while keeping the same order list.
717 void OrderClick_StopSharing()
719 /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
720 if (!this->vehicle->IsOrderListShared() || this->selected_order != this->vehicle->GetNumOrders()) return;
721 /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
722 if (_ctrl_pressed) {
723 this->OrderClick_Delete();
724 return;
727 /* Get another vehicle that share orders with this vehicle. */
728 Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
729 /* Copy the order list of the other vehicle. */
730 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))) {
731 this->UpdateButtonState();
736 * Handle the click on the refit button.
737 * If ctrl is pressed, cancel refitting, else show the refit window.
738 * @param i Selected refit command.
739 * @param auto_refit Select refit for auto-refitting.
741 void OrderClick_Refit(int i, bool auto_refit)
743 if (_ctrl_pressed) {
744 /* Cancel refitting */
745 DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
746 } else {
747 if (i == 1) { // Auto-refit to available cargo type.
748 DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | CT_AUTO_REFIT, CMD_ORDER_REFIT);
749 } else {
750 ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
755 /** Cache auto-refittability of the vehicle chain. */
756 void UpdateAutoRefitState()
758 this->can_do_refit = false;
759 this->can_do_autorefit = false;
760 for (const Vehicle *w = this->vehicle; w != NULL; w = w->IsGroundVehicle() ? w->Next() : NULL) {
761 if (IsEngineRefittable(w->engine_type)) this->can_do_refit = true;
762 if (HasBit(Engine::Get(w->engine_type)->info.misc_flags, EF_AUTO_REFIT)) this->can_do_autorefit = true;
766 public:
767 OrdersWindow(WindowDesc *desc, const Vehicle *v) : Window(desc)
769 this->vehicle = v;
771 this->CreateNestedTree();
772 this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
773 this->FinishInitNested(v->index);
774 if (v->owner == _local_company) {
775 this->DisableWidget(WID_O_EMPTY);
778 this->selected_order = -1;
779 this->order_over = INVALID_VEH_ORDER_ID;
780 this->goto_type = OPOS_NONE;
781 this->owner = v->owner;
783 this->UpdateAutoRefitState();
785 if (_settings_client.gui.quick_goto && v->owner == _local_company) {
786 /* If there are less than 2 station, make Go To active. */
787 int station_orders = 0;
788 const Order *order;
789 FOR_VEHICLE_ORDERS(v, order) {
790 if (order->IsType(OT_GOTO_STATION)) station_orders++;
793 if (station_orders < 2) this->OrderClick_Goto(OPOS_GOTO);
795 this->OnInvalidateData(VIWD_MODIFY_ORDERS);
798 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
800 switch (widget) {
801 case WID_O_ORDER_LIST:
802 resize->height = FONT_HEIGHT_NORMAL;
803 size->height = 6 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
804 break;
806 case WID_O_COND_VARIABLE: {
807 Dimension d = {0, 0};
808 for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
809 d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i]));
811 d.width += padding.width;
812 d.height += padding.height;
813 *size = maxdim(*size, d);
814 break;
817 case WID_O_COND_COMPARATOR: {
818 Dimension d = {0, 0};
819 for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
820 d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
822 d.width += padding.width;
823 d.height += padding.height;
824 *size = maxdim(*size, d);
825 break;
831 * Some data on this window has become invalid.
832 * @param data Information about the changed data.
833 * @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.
835 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
837 VehicleOrderID from = INVALID_VEH_ORDER_ID;
838 VehicleOrderID to = INVALID_VEH_ORDER_ID;
840 switch (data) {
841 case VIWD_AUTOREPLACE:
842 /* Autoreplace replaced the vehicle */
843 this->vehicle = Vehicle::Get(this->window_number);
844 FALLTHROUGH;
846 case VIWD_CONSIST_CHANGED:
847 /* Vehicle composition was changed. */
848 this->UpdateAutoRefitState();
849 break;
851 case VIWD_REMOVE_ALL_ORDERS:
852 /* Removed / replaced all orders (after deleting / sharing) */
853 if (this->selected_order == -1) break;
855 this->DeleteChildWindows();
856 HideDropDownMenu(this);
857 this->selected_order = -1;
858 break;
860 case VIWD_MODIFY_ORDERS:
861 /* Some other order changes */
862 break;
864 default:
865 if (data < 0) break;
867 if (gui_scope) break; // only do this once; from command scope
868 from = GB(data, 0, 8);
869 to = GB(data, 8, 8);
870 /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
871 * the order is being created / removed */
872 if (this->selected_order == -1) break;
874 if (from == to) break; // no need to change anything
876 if (from != this->selected_order) {
877 /* Moving from preceding order? */
878 this->selected_order -= (int)(from <= this->selected_order);
879 /* Moving to preceding order? */
880 this->selected_order += (int)(to <= this->selected_order);
881 break;
884 /* Now we are modifying the selected order */
885 if (to == INVALID_VEH_ORDER_ID) {
886 /* Deleting selected order */
887 this->DeleteChildWindows();
888 HideDropDownMenu(this);
889 this->selected_order = -1;
890 break;
893 /* Moving selected order */
894 this->selected_order = to;
895 break;
898 this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
899 if (gui_scope) this->UpdateButtonState();
901 /* Scroll to the new order. */
902 if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {
903 this->vscroll->ScrollTowards(to);
907 void UpdateButtonState()
909 if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
911 bool shared_orders = this->vehicle->IsOrderListShared();
912 VehicleOrderID sel = this->OrderGetSel();
913 const Order *order = this->vehicle->GetOrder(sel);
915 /* Second row. */
916 /* skip */
917 this->SetWidgetDisabledState(WID_O_SKIP, this->vehicle->GetNumOrders() <= 1);
919 /* delete / stop sharing */
920 NWidgetStacked *delete_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_BOTTOM_MIDDLE);
921 if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
922 /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
923 delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_STOP_SHARING);
924 } else {
925 /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
926 delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE);
927 this->SetWidgetDisabledState(WID_O_DELETE,
928 (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
930 /* Set the tooltip of the 'delete' button depending on whether the
931 * 'End of Orders' order or a regular order is selected. */
932 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
933 if (this->selected_order == this->vehicle->GetNumOrders()) {
934 nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
935 } else {
936 nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
940 /* First row. */
941 this->RaiseWidget(WID_O_FULL_LOAD);
942 this->RaiseWidget(WID_O_UNLOAD);
943 this->RaiseWidget(WID_O_SERVICE);
945 /* Selection widgets. */
946 /* Train or road vehicle. */
947 NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
948 NWidgetStacked *left_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
949 NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
950 NWidgetStacked *right_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
951 /* Ship or airplane. */
952 NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
953 assert(row_sel != NULL || (train_row_sel != NULL && left_sel != NULL && middle_sel != NULL && right_sel != NULL));
956 if (order == NULL) {
957 if (row_sel != NULL) {
958 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
959 } else {
960 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
961 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
962 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
963 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
964 this->DisableWidget(WID_O_NON_STOP);
965 this->RaiseWidget(WID_O_NON_STOP);
967 this->DisableWidget(WID_O_FULL_LOAD);
968 this->DisableWidget(WID_O_UNLOAD);
969 this->DisableWidget(WID_O_REFIT_DROPDOWN);
970 } else {
971 this->SetWidgetDisabledState(WID_O_FULL_LOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
972 this->SetWidgetDisabledState(WID_O_UNLOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
974 switch (order->GetType()) {
975 case OT_GOTO_STATION:
976 if (row_sel != NULL) {
977 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
978 } else {
979 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
980 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
981 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
982 right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
983 this->EnableWidget(WID_O_NON_STOP);
984 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
986 this->SetWidgetLoweredState(WID_O_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
987 this->SetWidgetLoweredState(WID_O_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
989 /* Can only do refitting when stopping at the destination and loading cargo.
990 * Also enable the button if a refit is already set to allow clearing it. */
991 this->SetWidgetDisabledState(WID_O_REFIT_DROPDOWN,
992 order->GetLoadType() == OLFB_NO_LOAD || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ||
993 ((!this->can_do_refit || !this->can_do_autorefit) && !order->IsRefit()));
995 break;
997 case OT_GOTO_WAYPOINT:
998 if (row_sel != NULL) {
999 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1000 } else {
1001 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1002 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1003 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1004 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1005 this->EnableWidget(WID_O_NON_STOP);
1006 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1008 this->DisableWidget(WID_O_FULL_LOAD);
1009 this->DisableWidget(WID_O_UNLOAD);
1010 this->DisableWidget(WID_O_REFIT_DROPDOWN);
1011 break;
1013 case OT_GOTO_DEPOT:
1014 if (row_sel != NULL) {
1015 row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
1016 } else {
1017 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1018 left_sel->SetDisplayedPlane(DP_LEFT_REFIT);
1019 middle_sel->SetDisplayedPlane(DP_MIDDLE_SERVICE);
1020 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1021 this->EnableWidget(WID_O_NON_STOP);
1022 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1024 /* Disable refit button if the order is no 'always go' order.
1025 * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
1026 this->SetWidgetDisabledState(WID_O_REFIT,
1027 (order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT) ||
1028 (!this->can_do_refit && !order->IsRefit()));
1029 this->SetWidgetLoweredState(WID_O_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
1030 break;
1032 case OT_CONDITIONAL: {
1033 if (row_sel != NULL) {
1034 row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
1035 } else {
1036 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_CONDITIONAL);
1038 OrderConditionVariable ocv = order->GetConditionVariable();
1039 /* Set the strings for the dropdown boxes. */
1040 this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv;
1041 this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order->GetConditionComparator()];
1042 this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
1043 this->SetWidgetDisabledState(WID_O_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
1044 break;
1047 default: // every other order
1048 if (row_sel != NULL) {
1049 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1050 } else {
1051 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1052 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1053 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1054 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1055 this->DisableWidget(WID_O_NON_STOP);
1057 this->DisableWidget(WID_O_FULL_LOAD);
1058 this->DisableWidget(WID_O_UNLOAD);
1059 this->DisableWidget(WID_O_REFIT_DROPDOWN);
1060 break;
1064 /* Disable list of vehicles with the same shared orders if there is no list */
1065 this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders);
1067 this->SetDirty();
1070 virtual void OnPaint()
1072 if (this->vehicle->owner != _local_company) {
1073 this->selected_order = -1; // Disable selection any selected row at a competitor order window.
1074 } else {
1075 this->SetWidgetLoweredState(WID_O_GOTO, this->goto_type != OPOS_NONE);
1077 this->DrawWidgets();
1080 virtual void DrawWidget(const Rect &r, int widget) const
1082 if (widget != WID_O_ORDER_LIST) return;
1084 bool rtl = _current_text_dir == TD_RTL;
1085 SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
1086 int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
1087 int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
1089 int y = r.top + WD_FRAMERECT_TOP;
1090 int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
1092 int i = this->vscroll->GetPosition();
1093 const Order *order = this->vehicle->GetOrder(i);
1094 /* First draw the highlighting underground if it exists. */
1095 if (this->order_over != INVALID_VEH_ORDER_ID) {
1096 while (order != NULL) {
1097 /* Don't draw anything if it extends past the end of the window. */
1098 if (!this->vscroll->IsVisible(i)) break;
1100 if (i != this->selected_order && i == this->order_over) {
1101 /* Highlight dragged order destination. */
1102 int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
1103 int bottom = min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM);
1104 top = max(top - 3, r.top + WD_FRAMERECT_TOP);
1105 GfxFillRect(r.left + WD_FRAMETEXT_LEFT, top, r.right - WD_FRAMETEXT_RIGHT, bottom, _colour_gradient[COLOUR_GREY][7]);
1106 break;
1108 y += line_height;
1110 i++;
1111 order = order->next;
1114 /* Reset counters for drawing the orders. */
1115 y = r.top + WD_FRAMERECT_TOP;
1116 i = this->vscroll->GetPosition();
1117 order = this->vehicle->GetOrder(i);
1120 /* Draw the orders. */
1121 while (order != NULL) {
1122 /* Don't draw anything if it extends past the end of the window. */
1123 if (!this->vscroll->IsVisible(i)) break;
1125 DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
1126 y += line_height;
1128 i++;
1129 order = order->next;
1132 if (this->vscroll->IsVisible(i)) {
1133 StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
1134 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);
1138 virtual void SetStringParameters(int widget) const
1140 switch (widget) {
1141 case WID_O_COND_VALUE: {
1142 VehicleOrderID sel = this->OrderGetSel();
1143 const Order *order = this->vehicle->GetOrder(sel);
1145 if (order != NULL && order->IsType(OT_CONDITIONAL)) {
1146 uint value = order->GetConditionValue();
1147 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1148 SetDParam(0, value);
1150 break;
1153 case WID_O_CAPTION:
1154 SetDParam(0, this->vehicle->index);
1155 break;
1159 virtual void OnClick(Point pt, int widget, int click_count)
1161 switch (widget) {
1162 case WID_O_ORDER_LIST: {
1163 if (this->goto_type == OPOS_CONDITIONAL) {
1164 VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
1165 if (order_id != INVALID_VEH_ORDER_ID) {
1166 Order order;
1167 order.next = NULL;
1168 order.index = 0;
1169 order.MakeConditional(order_id);
1171 DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
1173 ResetObjectToPlace();
1174 break;
1177 VehicleOrderID sel = this->GetOrderFromPt(pt.y);
1179 if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
1180 TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
1181 if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
1182 return;
1185 /* This order won't be selected any more, close all child windows and dropdowns */
1186 this->DeleteChildWindows();
1187 HideDropDownMenu(this);
1189 if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
1190 /* Deselect clicked order */
1191 this->selected_order = -1;
1192 } else if (sel == this->selected_order) {
1193 if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
1194 DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20),
1195 MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
1196 CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1198 } else {
1199 /* Select clicked order */
1200 this->selected_order = sel;
1202 if (this->vehicle->owner == _local_company) {
1203 /* Activate drag and drop */
1204 SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1208 this->UpdateButtonState();
1209 break;
1212 case WID_O_SKIP:
1213 this->OrderClick_Skip();
1214 break;
1216 case WID_O_DELETE:
1217 this->OrderClick_Delete();
1218 break;
1220 case WID_O_STOP_SHARING:
1221 this->OrderClick_StopSharing();
1222 break;
1224 case WID_O_NON_STOP:
1225 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1226 this->OrderClick_Nonstop(-1);
1227 } else {
1228 const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1229 ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
1230 o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
1232 break;
1234 case WID_O_GOTO:
1235 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1236 if (this->goto_type != OPOS_NONE) {
1237 ResetObjectToPlace();
1238 } else {
1239 this->OrderClick_Goto(OPOS_GOTO);
1241 } else {
1242 int sel;
1243 switch (this->goto_type) {
1244 case OPOS_NONE: sel = -1; break;
1245 case OPOS_GOTO: sel = 0; break;
1246 case OPOS_CONDITIONAL: sel = 2; break;
1247 case OPOS_SHARE: sel = 3; break;
1248 default: NOT_REACHED();
1250 ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
1252 break;
1254 case WID_O_FULL_LOAD:
1255 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1256 this->OrderClick_FullLoad(-1);
1257 } else {
1258 ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
1260 break;
1262 case WID_O_UNLOAD:
1263 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1264 this->OrderClick_Unload(-1);
1265 } else {
1266 ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
1268 break;
1270 case WID_O_REFIT:
1271 this->OrderClick_Refit(0, false);
1272 break;
1274 case WID_O_SERVICE:
1275 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1276 this->OrderClick_Service(-1);
1277 } else {
1278 ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_SERVICE, 0, 0);
1280 break;
1282 case WID_O_REFIT_DROPDOWN:
1283 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1284 this->OrderClick_Refit(0, true);
1285 } else {
1286 ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
1288 break;
1290 case WID_O_TIMETABLE_VIEW:
1291 ShowTimetableWindow(this->vehicle);
1292 break;
1294 case WID_O_COND_VARIABLE: {
1295 DropDownList *list = new DropDownList();
1296 for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
1297 *list->Append() = new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false);
1299 ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
1300 break;
1303 case WID_O_COND_COMPARATOR: {
1304 const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1305 ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
1306 break;
1309 case WID_O_COND_VALUE: {
1310 const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
1311 uint value = order->GetConditionValue();
1312 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1313 SetDParam(0, value);
1314 ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE);
1315 break;
1318 case WID_O_SHARED_ORDER_LIST:
1319 ShowVehicleListWindow(this->vehicle);
1320 break;
1324 virtual void OnQueryTextFinished(char *str)
1326 if (!StrEmpty(str)) {
1327 VehicleOrderID sel = this->OrderGetSel();
1328 uint value = atoi(str);
1330 switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
1331 case OCV_MAX_SPEED:
1332 value = ConvertDisplaySpeedToSpeed(value);
1333 break;
1335 case OCV_RELIABILITY:
1336 case OCV_LOAD_PERCENTAGE:
1337 value = Clamp(value, 0, 100);
1338 break;
1340 default:
1341 break;
1343 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));
1347 virtual void OnDropdownSelect(int widget, int index)
1349 switch (widget) {
1350 case WID_O_NON_STOP:
1351 this->OrderClick_Nonstop(index);
1352 break;
1354 case WID_O_FULL_LOAD:
1355 this->OrderClick_FullLoad(index);
1356 break;
1358 case WID_O_UNLOAD:
1359 this->OrderClick_Unload(index);
1360 break;
1362 case WID_O_GOTO:
1363 switch (index) {
1364 case 0: this->OrderClick_Goto(OPOS_GOTO); break;
1365 case 1: this->OrderClick_NearestDepot(); break;
1366 case 2: this->OrderClick_Goto(OPOS_CONDITIONAL); break;
1367 case 3: this->OrderClick_Goto(OPOS_SHARE); break;
1368 default: NOT_REACHED();
1370 break;
1372 case WID_O_SERVICE:
1373 this->OrderClick_Service(index);
1374 break;
1376 case WID_O_REFIT_DROPDOWN:
1377 this->OrderClick_Refit(index, true);
1378 break;
1380 case WID_O_COND_VARIABLE:
1381 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));
1382 break;
1384 case WID_O_COND_COMPARATOR:
1385 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));
1386 break;
1390 virtual void OnDragDrop(Point pt, int widget)
1392 switch (widget) {
1393 case WID_O_ORDER_LIST: {
1394 VehicleOrderID from_order = this->OrderGetSel();
1395 VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1397 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()) &&
1398 DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
1399 this->selected_order = -1;
1400 this->UpdateButtonState();
1402 break;
1405 case WID_O_DELETE:
1406 this->OrderClick_Delete();
1407 break;
1409 case WID_O_STOP_SHARING:
1410 this->OrderClick_StopSharing();
1411 break;
1414 ResetObjectToPlace();
1416 if (this->order_over != INVALID_VEH_ORDER_ID) {
1417 /* End of drag-and-drop, hide dragged order destination highlight. */
1418 this->order_over = INVALID_VEH_ORDER_ID;
1419 this->SetWidgetDirty(WID_O_ORDER_LIST);
1423 virtual EventState OnHotkey(int hotkey)
1425 if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
1427 switch (hotkey) {
1428 case OHK_SKIP: this->OrderClick_Skip(); break;
1429 case OHK_DELETE: this->OrderClick_Delete(); break;
1430 case OHK_GOTO: this->OrderClick_Goto(OPOS_GOTO); break;
1431 case OHK_NONSTOP: this->OrderClick_Nonstop(-1); break;
1432 case OHK_FULLLOAD: this->OrderClick_FullLoad(-1); break;
1433 case OHK_UNLOAD: this->OrderClick_Unload(-1); break;
1434 case OHK_NEAREST_DEPOT: this->OrderClick_NearestDepot(); break;
1435 case OHK_ALWAYS_SERVICE: this->OrderClick_Service(-1); break;
1436 case OHK_TRANSFER: this->OrderHotkey_Transfer(); break;
1437 case OHK_NO_UNLOAD: this->OrderHotkey_NoUnload(); break;
1438 case OHK_NO_LOAD: this->OrderHotkey_NoLoad(); break;
1439 default: return ES_NOT_HANDLED;
1441 return ES_HANDLED;
1444 virtual void OnPlaceObject(Point pt, TileIndex tile)
1446 if (this->goto_type == OPOS_GOTO) {
1447 const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
1448 if (cmd.IsType(OT_NOTHING)) return;
1450 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))) {
1451 /* With quick goto the Go To button stays active */
1452 if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
1457 virtual bool OnVehicleSelect(const Vehicle *v)
1459 /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
1460 * We disallow copying orders of other vehicles if we already have at least one order entry
1461 * ourself as it easily copies orders of vehicles within a station when we mean the station.
1462 * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
1463 * TODO: give a warning message */
1464 bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
1465 if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
1467 if (DoCommandP(this->vehicle->tile, this->vehicle->index | (share_order ? CO_SHARE : CO_COPY) << 30, v->index,
1468 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))) {
1469 this->selected_order = -1;
1470 ResetObjectToPlace();
1472 return true;
1475 virtual void OnPlaceObjectAbort()
1477 this->goto_type = OPOS_NONE;
1478 this->SetWidgetDirty(WID_O_GOTO);
1480 /* Remove drag highlighting if it exists. */
1481 if (this->order_over != INVALID_VEH_ORDER_ID) {
1482 this->order_over = INVALID_VEH_ORDER_ID;
1483 this->SetWidgetDirty(WID_O_ORDER_LIST);
1487 virtual void OnMouseDrag(Point pt, int widget)
1489 if (this->selected_order != -1 && widget == WID_O_ORDER_LIST) {
1490 /* An order is dragged.. */
1491 VehicleOrderID from_order = this->OrderGetSel();
1492 VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1493 uint num_orders = this->vehicle->GetNumOrders();
1495 if (from_order != INVALID_VEH_ORDER_ID && from_order <= num_orders) {
1496 if (to_order != INVALID_VEH_ORDER_ID && to_order <= num_orders) { // ..over an existing order.
1497 this->order_over = to_order;
1498 this->SetWidgetDirty(widget);
1499 } else if (from_order != to_order && this->order_over != INVALID_VEH_ORDER_ID) { // ..outside of the order list.
1500 this->order_over = INVALID_VEH_ORDER_ID;
1501 this->SetWidgetDirty(widget);
1507 virtual void OnResize()
1509 /* Update the scroll bar */
1510 this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
1513 static HotkeyList hotkeys;
1516 static Hotkey order_hotkeys[] = {
1517 Hotkey('D', "skip", OHK_SKIP),
1518 Hotkey('F', "delete", OHK_DELETE),
1519 Hotkey('G', "goto", OHK_GOTO),
1520 Hotkey('H', "nonstop", OHK_NONSTOP),
1521 Hotkey('J', "fullload", OHK_FULLLOAD),
1522 Hotkey('K', "unload", OHK_UNLOAD),
1523 Hotkey((uint16)0, "nearest_depot", OHK_NEAREST_DEPOT),
1524 Hotkey((uint16)0, "always_service", OHK_ALWAYS_SERVICE),
1525 Hotkey((uint16)0, "transfer", OHK_TRANSFER),
1526 Hotkey((uint16)0, "no_unload", OHK_NO_UNLOAD),
1527 Hotkey((uint16)0, "no_load", OHK_NO_LOAD),
1528 HOTKEY_LIST_END
1530 HotkeyList OrdersWindow::hotkeys("order", order_hotkeys);
1532 /** Nested widget definition for "your" train orders. */
1533 static const NWidgetPart _nested_orders_train_widgets[] = {
1534 NWidget(NWID_HORIZONTAL),
1535 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1536 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1537 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1538 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1539 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1540 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1541 EndContainer(),
1542 NWidget(NWID_HORIZONTAL),
1543 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(),
1544 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1545 EndContainer(),
1547 /* First button row. */
1548 NWidget(NWID_HORIZONTAL),
1549 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW_GROUNDVEHICLE),
1550 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1551 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_NON_STOP), SetMinimalSize(93, 12), SetFill(1, 0),
1552 SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
1553 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_LEFT),
1554 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1555 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1556 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(93, 12), SetFill(1, 0),
1557 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1558 EndContainer(),
1559 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_MIDDLE),
1560 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1561 SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1562 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(93, 12), SetFill(1, 0),
1563 SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1564 EndContainer(),
1565 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_RIGHT),
1566 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_O_EMPTY), SetMinimalSize(93, 12), SetFill(1, 0),
1567 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1568 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(93, 12), SetFill(1, 0),
1569 SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1570 EndContainer(),
1571 EndContainer(),
1572 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1573 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1574 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1575 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1576 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1577 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1578 SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1579 EndContainer(),
1580 EndContainer(),
1581 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_O_SHARED_ORDER_LIST), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
1582 EndContainer(),
1584 /* Second button row. */
1585 NWidget(NWID_HORIZONTAL),
1586 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1587 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1588 SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1589 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
1590 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1591 SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1592 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1593 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1594 EndContainer(),
1595 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1596 SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1597 EndContainer(),
1598 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1599 EndContainer(),
1602 static WindowDesc _orders_train_desc(
1603 WDP_AUTO, "view_vehicle_orders_train", 384, 100,
1604 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
1605 WDF_CONSTRUCTION,
1606 _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets),
1607 &OrdersWindow::hotkeys
1610 /** Nested widget definition for "your" orders (non-train). */
1611 static const NWidgetPart _nested_orders_widgets[] = {
1612 NWidget(NWID_HORIZONTAL),
1613 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1614 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1615 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1616 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1617 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1618 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1619 EndContainer(),
1620 NWidget(NWID_HORIZONTAL),
1621 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(),
1622 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1623 EndContainer(),
1625 /* First button row. */
1626 NWidget(NWID_HORIZONTAL),
1627 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW),
1628 /* Load + unload + refit buttons. */
1629 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1630 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1631 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1632 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1633 SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1634 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(124, 12), SetFill(1, 0),
1635 SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1636 EndContainer(),
1637 /* Refit + service buttons. */
1638 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1639 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
1640 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1641 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
1642 SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1643 EndContainer(),
1645 /* Buttons for setting a condition. */
1646 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1647 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1648 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1649 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1650 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1651 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1652 SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1653 EndContainer(),
1654 EndContainer(),
1656 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_O_SHARED_ORDER_LIST), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
1657 EndContainer(),
1659 /* Second button row. */
1660 NWidget(NWID_HORIZONTAL),
1661 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1662 SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1663 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
1664 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1665 SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1666 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1667 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1668 EndContainer(),
1669 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1670 SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1671 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1672 EndContainer(),
1675 static WindowDesc _orders_desc(
1676 WDP_AUTO, "view_vehicle_orders", 384, 100,
1677 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
1678 WDF_CONSTRUCTION,
1679 _nested_orders_widgets, lengthof(_nested_orders_widgets),
1680 &OrdersWindow::hotkeys
1683 /** Nested widget definition for competitor orders. */
1684 static const NWidgetPart _nested_other_orders_widgets[] = {
1685 NWidget(NWID_HORIZONTAL),
1686 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1687 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1688 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1689 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1690 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1691 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1692 EndContainer(),
1693 NWidget(NWID_HORIZONTAL),
1694 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(),
1695 NWidget(NWID_VERTICAL),
1696 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1697 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1698 EndContainer(),
1699 EndContainer(),
1702 static WindowDesc _other_orders_desc(
1703 WDP_AUTO, "view_vehicle_orders_competitor", 384, 86,
1704 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
1705 WDF_CONSTRUCTION,
1706 _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets),
1707 &OrdersWindow::hotkeys
1710 void ShowOrdersWindow(const Vehicle *v)
1712 DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
1713 DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
1714 if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
1716 /* Using a different WindowDescs for _local_company causes problems.
1717 * Due to this we have to close order windows in ChangeWindowOwner/DeleteCompanyWindows,
1718 * because we cannot change switch the WindowDescs and keeping the old WindowDesc results
1719 * in crashed due to missing widges.
1720 * TODO Rewrite the order GUI to not use different WindowDescs.
1722 if (v->owner != _local_company) {
1723 new OrdersWindow(&_other_orders_desc, v);
1724 } else {
1725 new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);