Add support for deleted functions
[openttd/fttd.git] / src / order_gui.cpp
blob1646ee580cbd42b86e136a013aa981f589618e8d
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 "roadveh.h"
16 #include "timetable.h"
17 #include "strings_func.h"
18 #include "company_func.h"
19 #include "widgets/dropdown_type.h"
20 #include "widgets/dropdown_func.h"
21 #include "textbuf_gui.h"
22 #include "string_func.h"
23 #include "tilehighlight_func.h"
24 #include "network/network.h"
25 #include "station_base.h"
26 #include "waypoint_base.h"
27 #include "core/geometry_func.hpp"
28 #include "hotkeys.h"
29 #include "aircraft.h"
30 #include "engine_func.h"
32 #include "widgets/order_widget.h"
35 /** Order load types that could be given to station orders. */
36 static const StringID _station_load_types[][5][5] = {
38 /* No refitting. */
40 STR_EMPTY,
41 INVALID_STRING_ID,
42 STR_ORDER_FULL_LOAD,
43 STR_ORDER_FULL_LOAD_ANY,
44 STR_ORDER_NO_LOAD,
45 }, {
46 STR_ORDER_UNLOAD,
47 INVALID_STRING_ID,
48 STR_ORDER_UNLOAD_FULL_LOAD,
49 STR_ORDER_UNLOAD_FULL_LOAD_ANY,
50 STR_ORDER_UNLOAD_NO_LOAD,
51 }, {
52 STR_ORDER_TRANSFER,
53 INVALID_STRING_ID,
54 STR_ORDER_TRANSFER_FULL_LOAD,
55 STR_ORDER_TRANSFER_FULL_LOAD_ANY,
56 STR_ORDER_TRANSFER_NO_LOAD,
57 }, {
58 /* Unload and transfer do not work together. */
59 INVALID_STRING_ID,
60 INVALID_STRING_ID,
61 INVALID_STRING_ID,
62 INVALID_STRING_ID,
63 }, {
64 STR_ORDER_NO_UNLOAD,
65 INVALID_STRING_ID,
66 STR_ORDER_NO_UNLOAD_FULL_LOAD,
67 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
68 STR_ORDER_NO_UNLOAD_NO_LOAD,
70 }, {
71 /* With auto-refitting. No loading and auto-refitting do not work together. */
73 STR_ORDER_AUTO_REFIT,
74 INVALID_STRING_ID,
75 STR_ORDER_FULL_LOAD_REFIT,
76 STR_ORDER_FULL_LOAD_ANY_REFIT,
77 INVALID_STRING_ID,
78 }, {
79 STR_ORDER_UNLOAD_REFIT,
80 INVALID_STRING_ID,
81 STR_ORDER_UNLOAD_FULL_LOAD_REFIT,
82 STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT,
83 INVALID_STRING_ID,
84 }, {
85 STR_ORDER_TRANSFER_REFIT,
86 INVALID_STRING_ID,
87 STR_ORDER_TRANSFER_FULL_LOAD_REFIT,
88 STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT,
89 INVALID_STRING_ID,
90 }, {
91 /* Unload and transfer do not work together. */
92 INVALID_STRING_ID,
93 INVALID_STRING_ID,
94 INVALID_STRING_ID,
95 INVALID_STRING_ID,
96 }, {
97 STR_ORDER_NO_UNLOAD_REFIT,
98 INVALID_STRING_ID,
99 STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT,
100 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT,
101 INVALID_STRING_ID,
106 static const StringID _order_non_stop_drowdown[] = {
107 STR_ORDER_GO_TO,
108 STR_ORDER_GO_NON_STOP_TO,
109 STR_ORDER_GO_VIA,
110 STR_ORDER_GO_NON_STOP_VIA,
111 INVALID_STRING_ID
114 static const StringID _order_full_load_drowdown[] = {
115 STR_ORDER_DROP_LOAD_IF_POSSIBLE,
116 STR_EMPTY,
117 STR_ORDER_DROP_FULL_LOAD_ALL,
118 STR_ORDER_DROP_FULL_LOAD_ANY,
119 STR_ORDER_DROP_NO_LOADING,
120 INVALID_STRING_ID
123 static const StringID _order_unload_drowdown[] = {
124 STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
125 STR_ORDER_DROP_UNLOAD,
126 STR_ORDER_DROP_TRANSFER,
127 STR_EMPTY,
128 STR_ORDER_DROP_NO_UNLOADING,
129 INVALID_STRING_ID
132 static const StringID _order_goto_dropdown[] = {
133 STR_ORDER_GO_TO,
134 STR_ORDER_GO_TO_NEAREST_DEPOT,
135 STR_ORDER_CONDITIONAL,
136 STR_ORDER_SHARE,
137 INVALID_STRING_ID
140 static const StringID _order_goto_dropdown_aircraft[] = {
141 STR_ORDER_GO_TO,
142 STR_ORDER_GO_TO_NEAREST_HANGAR,
143 STR_ORDER_CONDITIONAL,
144 STR_ORDER_SHARE,
145 INVALID_STRING_ID
148 /** Variables for conditional orders; this defines the order of appearance in the dropdown box */
149 static const OrderConditionVariable _order_conditional_variable[] = {
150 OCV_LOAD_PERCENTAGE,
151 OCV_RELIABILITY,
152 OCV_MAX_SPEED,
153 OCV_AGE,
154 OCV_REMAINING_LIFETIME,
155 OCV_REQUIRES_SERVICE,
156 OCV_UNCONDITIONALLY,
159 static const StringID _order_conditional_condition[] = {
160 STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
161 STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
162 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
163 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
164 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
165 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
166 STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
167 STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
168 INVALID_STRING_ID,
171 extern uint ConvertSpeedToDisplaySpeed(uint speed);
172 extern uint ConvertDisplaySpeedToSpeed(uint speed);
174 static const StringID _order_depot_action_dropdown[] = {
175 STR_ORDER_DROP_GO_ALWAYS_DEPOT,
176 STR_ORDER_DROP_SERVICE_DEPOT,
177 STR_ORDER_DROP_HALT_DEPOT,
178 INVALID_STRING_ID
181 static int DepotActionStringIndex(const Order *order)
183 if (order->GetDepotActionType() & ODATFB_HALT) {
184 return DA_STOP;
185 } else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
186 return DA_SERVICE;
187 } else {
188 return DA_ALWAYS_GO;
192 static const StringID _order_refit_action_dropdown[] = {
193 STR_ORDER_DROP_REFIT_AUTO,
194 STR_ORDER_DROP_REFIT_AUTO_ANY,
195 INVALID_STRING_ID
199 * Draws an order in order or timetable GUI
200 * @param v Vehicle the order belongs to
201 * @param order The order to draw
202 * @param order_index Index of the order in the orders of the vehicle
203 * @param y Y position for drawing
204 * @param selected True, if the order is selected
205 * @param timetable True, when drawing in the timetable GUI
206 * @param left Left border for text drawing
207 * @param middle X position between order index and order text
208 * @param right Right border for text drawing
210 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
212 bool rtl = _current_text_dir == TD_RTL;
214 SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT;
215 Dimension sprite_size = GetSpriteSize(sprite);
216 if (v->cur_real_order_index == order_index) {
217 DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
218 DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
219 } else if (v->cur_implicit_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);
223 TextColour colour = TC_BLACK;
224 if (order->IsType(OT_IMPLICIT)) {
225 colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
226 } else if (selected) {
227 colour = TC_WHITE;
230 SetDParam(0, order_index + 1);
231 DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, STR_ORDER_INDEX, colour, SA_RIGHT | SA_FORCE);
233 SetDParam(5, STR_EMPTY);
234 SetDParam(8, STR_EMPTY);
236 /* Check range for aircraft. */
237 if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
238 const Order *next = order->next != NULL ? order->next : v->GetFirstOrder();
239 if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) SetDParam(8, STR_ORDER_OUT_OF_RANGE);
242 switch (order->GetType()) {
243 case OT_DUMMY:
244 SetDParam(0, STR_INVALID_ORDER);
245 SetDParam(1, order->GetDestination());
246 break;
248 case OT_IMPLICIT:
249 SetDParam(0, STR_ORDER_GO_TO_STATION);
250 SetDParam(1, STR_ORDER_GO_TO);
251 SetDParam(2, order->GetDestination());
252 SetDParam(3, timetable ? STR_EMPTY : STR_ORDER_IMPLICIT);
253 break;
255 case OT_GOTO_STATION: {
256 OrderLoadFlags load = order->GetLoadType();
257 OrderUnloadFlags unload = order->GetUnloadType();
259 SetDParam(0, STR_ORDER_GO_TO_STATION);
260 SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
261 SetDParam(2, order->GetDestination());
263 if (timetable) {
264 SetDParam(3, STR_EMPTY);
266 if (order->wait_time > 0) {
267 SetDParam(5, STR_TIMETABLE_STAY_FOR);
268 SetTimetableParams(6, 7, order->wait_time);
270 } else {
271 SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]);
272 if (order->IsRefit()) {
273 SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
275 if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
276 SetDParam(5, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
279 break;
282 case OT_GOTO_DEPOT:
283 if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
284 SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
285 if (v->type == VEH_AIRCRAFT) {
286 SetDParam(2, STR_ORDER_NEAREST_HANGAR);
287 SetDParam(3, STR_EMPTY);
288 } else {
289 SetDParam(2, STR_ORDER_NEAREST_DEPOT);
290 SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type);
292 } else {
293 SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT);
294 SetDParam(2, v->type);
295 SetDParam(3, order->GetDestination());
298 if (order->GetDepotOrderType() & ODTFB_SERVICE) {
299 SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
300 } else {
301 SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
304 if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
305 SetDParam(5, STR_ORDER_STOP_ORDER);
308 if (!timetable && order->IsRefit()) {
309 SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER);
310 SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name);
312 break;
314 case OT_GOTO_WAYPOINT:
315 SetDParam(0, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT);
316 SetDParam(1, order->GetDestination());
317 break;
319 case OT_CONDITIONAL:
320 SetDParam(1, order->GetConditionSkipToOrder() + 1);
321 if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
322 SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
323 } else {
324 OrderConditionComparator occ = order->GetConditionComparator();
325 SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM);
326 SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
327 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
329 uint value = order->GetConditionValue();
330 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
331 SetDParam(4, value);
334 if (timetable && order->wait_time > 0) {
335 SetDParam(5, STR_TIMETABLE_AND_TRAVEL_FOR);
336 SetTimetableParams(6, 7, order->wait_time);
337 } else {
338 SetDParam(5, STR_EMPTY);
340 break;
342 default: NOT_REACHED();
345 DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
349 static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
351 /* Hack-ish; unpack order 0, so everything gets initialised with either zero
352 * or a suitable default value for the variable. Then also override the index
353 * as it is not coming from a pool, so would be initialised. */
354 Order order(0);
355 order.index = 0;
357 /* check depot first */
358 switch (GetTileType(tile)) {
359 case TT_MISC:
360 if (!IsTileSubtype(tile, TT_MISC_DEPOT)) break;
362 if (v->type == (IsRailDepot(tile) ? VEH_TRAIN : VEH_ROAD) && IsTileOwner(tile, _local_company)) {
363 order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS,
364 _settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
365 if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
366 return order;
368 break;
370 case TT_STATION:
371 if (v->type != VEH_AIRCRAFT) break;
372 if (IsHangar(tile) && IsTileOwner(tile, _local_company)) {
373 order.MakeGoToDepot(GetStationIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
374 if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
375 return order;
377 break;
379 case TT_WATER:
380 if (v->type != VEH_SHIP) break;
381 if (IsShipDepot(tile) && IsTileOwner(tile, _local_company)) {
382 order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
383 if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
384 return order;
386 break;
388 default:
389 break;
392 /* check waypoint */
393 if (IsRailWaypointTile(tile) &&
394 v->type == VEH_TRAIN &&
395 IsTileOwner(tile, _local_company)) {
396 order.MakeGoToWaypoint(Waypoint::GetByTile(tile)->index);
397 if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
398 return order;
401 if ((IsBuoyTile(tile) && v->type == VEH_SHIP) || (IsRailWaypointTile(tile) && v->type == VEH_TRAIN)) {
402 order.MakeGoToWaypoint(GetStationIndex(tile));
403 return order;
406 if (IsStationTile(tile)) {
407 StationID st_index = GetStationIndex(tile);
408 const Station *st = Station::Get(st_index);
410 if (st->owner == _local_company || st->owner == OWNER_NONE) {
411 byte facil;
412 (facil = FACIL_DOCK, v->type == VEH_SHIP) ||
413 (facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
414 (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
415 (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
416 (facil = FACIL_TRUCK_STOP, 1);
417 if (st->facilities & facil) {
418 order.MakeGoToStation(st_index);
419 if (_ctrl_pressed) order.SetLoadType(OLF_FULL_LOAD_ANY);
420 if (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
421 order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OSL_PLATFORM_FAR_END);
422 return order;
427 /* not found */
428 order.Free();
429 return order;
432 /** Hotkeys for order window. */
433 enum {
434 OHK_SKIP,
435 OHK_DELETE,
436 OHK_GOTO,
437 OHK_NONSTOP,
438 OHK_FULLLOAD,
439 OHK_UNLOAD,
440 OHK_NEAREST_DEPOT,
441 OHK_ALWAYS_SERVICE,
442 OHK_TRANSFER,
443 OHK_NO_UNLOAD,
444 OHK_NO_LOAD,
448 * %Order window code for all vehicles.
450 * At the bottom of the window two button rows are located for changing the orders of the vehicle.
452 * \section top-row Top row
453 * 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.
455 * The top-row buttons of one of your trains or road vehicles is one of the following three cases:
456 * \verbatim
457 * +-----------------+-----------------+-----------------+-----------------+
458 * | NON-STOP | FULL_LOAD | UNLOAD | REFIT | (normal)
459 * +-----------------+-----+-----------+-----------+-----+-----------------+
460 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
461 * +-----------------+-----+-----------+-----------+-----+-----------------+
462 * | NON-STOP | REFIT | SERVICE | (empty) | (for depot orders)
463 * +-----------------+-----------------+-----------------+-----------------+
464 * \endverbatim
466 * Airplanes and ships have one of the following three top-row button rows:
467 * \verbatim
468 * +-----------------+-----------------+-----------------+
469 * | FULL_LOAD | UNLOAD | REFIT | (normal)
470 * +-----------------+-----------------+-----------------+
471 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
472 * +-----------------+--------+--------+-----------------+
473 * | REFIT | SERVICE | (for depot order)
474 * +--------------------------+--------------------------+
475 * \endverbatim
477 * \section bottom-row Bottom row
478 * The second row (the bottom row) is for manipulating the list of orders:
479 * \verbatim
480 * +-----------------+-----------------+-----------------+
481 * | SKIP | DELETE | GOTO |
482 * +-----------------+-----------------+-----------------+
483 * \endverbatim
485 * For vehicles of other companies, both button rows are not displayed.
487 struct OrdersWindow : public Window {
488 private:
489 /** Under what reason are we using the PlaceObject functionality? */
490 enum OrderPlaceObjectState {
491 OPOS_NONE,
492 OPOS_GOTO,
493 OPOS_CONDITIONAL,
494 OPOS_SHARE,
495 OPOS_END,
498 /** Displayed planes of the #NWID_SELECTION widgets. */
499 enum DisplayPane {
500 /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
501 DP_GROUNDVEHICLE_ROW_NORMAL = 0, ///< Display the row for normal/depot orders in the top row of the train/rv order window.
502 DP_GROUNDVEHICLE_ROW_CONDITIONAL = 1, ///< Display the row for conditional orders in the top row of the train/rv order window.
504 /* WID_O_SEL_TOP_LEFT */
505 DP_LEFT_LOAD = 0, ///< Display 'load' in the left button of the top row of the train/rv order window.
506 DP_LEFT_REFIT = 1, ///< Display 'refit' in the left button of the top row of the train/rv order window.
508 /* WID_O_SEL_TOP_MIDDLE */
509 DP_MIDDLE_UNLOAD = 0, ///< Display 'unload' in the middle button of the top row of the train/rv order window.
510 DP_MIDDLE_SERVICE = 1, ///< Display 'service' in the middle button of the top row of the train/rv order window.
512 /* WID_O_SEL_TOP_RIGHT */
513 DP_RIGHT_EMPTY = 0, ///< Display an empty panel in the right button of the top row of the train/rv order window.
514 DP_RIGHT_REFIT = 1, ///< Display 'refit' in the right button of the top row of the train/rv order window.
516 /* WID_O_SEL_TOP_ROW */
517 DP_ROW_LOAD = 0, ///< Display 'load' / 'unload' / 'refit' buttons in the top row of the ship/airplane order window.
518 DP_ROW_DEPOT = 1, ///< Display 'refit' / 'service' buttons in the top row of the ship/airplane order window.
519 DP_ROW_CONDITIONAL = 2, ///< Display the conditional order buttons in the top row of the ship/airplane order window.
521 /* WID_O_SEL_BOTTOM_MIDDLE */
522 DP_BOTTOM_MIDDLE_DELETE = 0, ///< Display 'delete' in the middle button of the bottom row of the vehicle order window.
523 DP_BOTTOM_MIDDLE_STOP_SHARING = 1, ///< Display 'stop sharing' in the middle button of the bottom row of the vehicle order window.
526 int selected_order;
527 VehicleOrderID order_over; ///< Order over which another order is dragged, \c INVALID_VEH_ORDER_ID if none.
528 OrderPlaceObjectState goto_type;
529 const Vehicle *vehicle; ///< Vehicle owning the orders being displayed and manipulated.
530 Scrollbar *vscroll;
531 bool can_do_refit; ///< Vehicle chain can be refitted in depot.
532 bool can_do_autorefit; ///< Vehicle chain can be auto-refitted.
535 * Return the memorised selected order.
536 * @return the memorised order if it is a valid one
537 * else return the number of orders
539 VehicleOrderID OrderGetSel() const
541 int num = this->selected_order;
542 return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
546 * Calculate the selected order.
547 * The calculation is based on the relative (to the window) y click position and
548 * the position of the scrollbar.
550 * @param y Y-value of the click relative to the window origin
551 * @return The selected order if the order is valid, else return \c INVALID_VEH_ORDER_ID.
553 VehicleOrderID GetOrderFromPt(int y)
555 NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST);
556 int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
558 if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID;
560 sel += this->vscroll->GetPosition();
562 return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID;
566 * Handle the click on the goto button.
568 void OrderClick_Goto(OrderPlaceObjectState type)
570 assert(type > OPOS_NONE && type < OPOS_END);
572 static const HighLightStyle goto_place_style[OPOS_END - 1] = {
573 HT_RECT | HT_VEHICLE, // OPOS_GOTO
574 HT_NONE, // OPOS_CONDITIONAL
575 HT_VEHICLE, // OPOS_SHARE
577 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, goto_place_style[type - 1], this);
578 this->goto_type = type;
579 this->SetWidgetDirty(WID_O_GOTO);
583 * Handle the click on the full load button.
584 * @param load_type the way to load.
586 void OrderClick_FullLoad(int load_type)
588 VehicleOrderID sel_ord = this->OrderGetSel();
589 const Order *order = this->vehicle->GetOrder(sel_ord);
591 if (order == NULL || order->GetLoadType() == load_type) return;
593 if (load_type < 0) {
594 load_type = order->GetLoadType() == OLF_LOAD_IF_POSSIBLE ? OLF_FULL_LOAD_ANY : OLF_LOAD_IF_POSSIBLE;
596 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));
600 * Handle the 'no loading' hotkey
602 void OrderHotkey_NoLoad()
604 this->OrderClick_FullLoad(OLFB_NO_LOAD);
608 * Handle the click on the service.
610 void OrderClick_Service(int i)
612 VehicleOrderID sel_ord = this->OrderGetSel();
614 if (i < 0) {
615 const Order *order = this->vehicle->GetOrder(sel_ord);
616 if (order == NULL) return;
617 i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
619 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));
623 * Handle the click on the service in nearest depot button.
625 void OrderClick_NearestDepot()
627 Order order;
628 order.next = NULL;
629 order.index = 0;
630 order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS,
631 _settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
632 order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
634 DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
638 * Handle the click on the unload button.
640 void OrderClick_Unload(int unload_type)
642 VehicleOrderID sel_ord = this->OrderGetSel();
643 const Order *order = this->vehicle->GetOrder(sel_ord);
645 if (order == NULL || order->GetUnloadType() == unload_type) return;
647 if (unload_type < 0) {
648 unload_type = order->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE ? OUFB_UNLOAD : OUF_UNLOAD_IF_POSSIBLE;
651 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));
653 /* Transfer orders with leave empty as default */
654 if (unload_type == OUFB_TRANSFER) {
655 DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), CMD_MODIFY_ORDER);
656 this->SetWidgetDirty(WID_O_FULL_LOAD);
661 * Handle the transfer hotkey
663 void OrderHotkey_Transfer()
665 this->OrderClick_Unload(OUFB_TRANSFER);
669 * Handle the 'no unload' hotkey
671 void OrderHotkey_NoUnload()
673 this->OrderClick_Unload(OUFB_NO_UNLOAD);
677 * Handle the click on the nonstop button.
678 * @param non_stop what non-stop type to use; -1 to use the 'next' one.
680 void OrderClick_Nonstop(int non_stop)
682 if (!this->vehicle->IsGroundVehicle()) return;
684 VehicleOrderID sel_ord = this->OrderGetSel();
685 const Order *order = this->vehicle->GetOrder(sel_ord);
687 if (order == NULL || order->GetNonStopType() == non_stop) return;
689 /* Keypress if negative, so 'toggle' to the next */
690 if (non_stop < 0) {
691 non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
694 this->SetWidgetDirty(WID_O_NON_STOP);
695 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));
699 * Handle the click on the skip button.
700 * If ctrl is pressed, skip to selected order, else skip to current order + 1
702 void OrderClick_Skip()
704 /* Don't skip when there's nothing to skip */
705 if (_ctrl_pressed && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
706 if (this->vehicle->GetNumOrders() <= 1) return;
708 DoCommandP(this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()),
709 CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
713 * Handle the click on the delete button.
715 void OrderClick_Delete()
717 /* When networking, move one order lower */
718 int selected = this->selected_order + (int)_networking;
720 if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
721 this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
722 this->UpdateButtonState();
727 * Handle the click on the 'stop sharing' button.
728 * If 'End of Shared Orders' isn't selected, do nothing. If Ctrl is pressed, call OrderClick_Delete and exit.
729 * To stop sharing this vehicle order list, we copy the orders of a vehicle that share this order list. That way we
730 * exit the group of shared vehicles while keeping the same order list.
732 void OrderClick_StopSharing()
734 /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
735 if (!this->vehicle->IsOrderListShared() || this->selected_order != this->vehicle->GetNumOrders()) return;
736 /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
737 if (_ctrl_pressed) {
738 this->OrderClick_Delete();
739 return;
742 /* Get another vehicle that share orders with this vehicle. */
743 Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
744 /* Copy the order list of the other vehicle. */
745 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))) {
746 this->UpdateButtonState();
751 * Handle the click on the refit button.
752 * If ctrl is pressed, cancel refitting, else show the refit window.
753 * @param i Selected refit command.
754 * @param auto_refit Select refit for auto-refitting.
756 void OrderClick_Refit(int i, bool auto_refit)
758 if (_ctrl_pressed) {
759 /* Cancel refitting */
760 DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
761 } else {
762 if (i == 1) { // Auto-refit to available cargo type.
763 DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | CT_AUTO_REFIT, CMD_ORDER_REFIT);
764 } else {
765 ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
770 /** Cache auto-refittability of the vehicle chain. */
771 void UpdateAutoRefitState()
773 this->can_do_refit = false;
774 this->can_do_autorefit = false;
775 for (const Vehicle *w = this->vehicle; w != NULL; w = w->IsGroundVehicle() ? w->Next() : NULL) {
776 if (IsEngineRefittable(w->engine_type)) this->can_do_refit = true;
777 if (HasBit(Engine::Get(w->engine_type)->info.misc_flags, EF_AUTO_REFIT)) this->can_do_autorefit = true;
781 public:
782 OrdersWindow(WindowDesc *desc, const Vehicle *v) : Window(desc)
784 this->vehicle = v;
786 this->CreateNestedTree();
787 this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
788 this->FinishInitNested(v->index);
789 if (v->owner == _local_company) {
790 this->DisableWidget(WID_O_EMPTY);
793 this->selected_order = -1;
794 this->order_over = INVALID_VEH_ORDER_ID;
795 this->goto_type = OPOS_NONE;
796 this->owner = v->owner;
798 this->UpdateAutoRefitState();
800 if (_settings_client.gui.quick_goto && v->owner == _local_company) {
801 /* If there are less than 2 station, make Go To active. */
802 int station_orders = 0;
803 const Order *order;
804 FOR_VEHICLE_ORDERS(v, order) {
805 if (order->IsType(OT_GOTO_STATION)) station_orders++;
808 if (station_orders < 2) this->OrderClick_Goto(OPOS_GOTO);
810 this->OnInvalidateData(VIWD_MODIFY_ORDERS);
813 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
815 switch (widget) {
816 case WID_O_ORDER_LIST:
817 resize->height = FONT_HEIGHT_NORMAL;
818 size->height = 6 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
819 break;
821 case WID_O_COND_VARIABLE: {
822 Dimension d = {0, 0};
823 for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
824 d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i]));
826 d.width += padding.width;
827 d.height += padding.height;
828 *size = maxdim(*size, d);
829 break;
832 case WID_O_COND_COMPARATOR: {
833 Dimension d = {0, 0};
834 for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
835 d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
837 d.width += padding.width;
838 d.height += padding.height;
839 *size = maxdim(*size, d);
840 break;
846 * Some data on this window has become invalid.
847 * @param data Information about the changed data.
848 * @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.
850 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
852 VehicleOrderID from = INVALID_VEH_ORDER_ID;
853 VehicleOrderID to = INVALID_VEH_ORDER_ID;
855 switch (data) {
856 case VIWD_AUTOREPLACE:
857 /* Autoreplace replaced the vehicle */
858 this->vehicle = Vehicle::Get(this->window_number);
859 /* FALL THROUGH */
861 case VIWD_CONSIST_CHANGED:
862 /* Vehicle composition was changed. */
863 this->UpdateAutoRefitState();
864 break;
866 case VIWD_REMOVE_ALL_ORDERS:
867 /* Removed / replaced all orders (after deleting / sharing) */
868 if (this->selected_order == -1) break;
870 this->DeleteChildWindows();
871 HideDropDownMenu(this);
872 this->selected_order = -1;
873 break;
875 case VIWD_MODIFY_ORDERS:
876 /* Some other order changes */
877 break;
879 default:
880 if (data < 0) break;
882 if (gui_scope) break; // only do this once; from command scope
883 from = GB(data, 0, 8);
884 to = GB(data, 8, 8);
885 /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
886 * the order is being created / removed */
887 if (this->selected_order == -1) break;
889 if (from == to) break; // no need to change anything
891 if (from != this->selected_order) {
892 /* Moving from preceding order? */
893 this->selected_order -= (int)(from <= this->selected_order);
894 /* Moving to preceding order? */
895 this->selected_order += (int)(to <= this->selected_order);
896 break;
899 /* Now we are modifying the selected order */
900 if (to == INVALID_VEH_ORDER_ID) {
901 /* Deleting selected order */
902 this->DeleteChildWindows();
903 HideDropDownMenu(this);
904 this->selected_order = -1;
905 break;
908 /* Moving selected order */
909 this->selected_order = to;
910 break;
913 this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
914 if (gui_scope) this->UpdateButtonState();
916 /* Scroll to the new order. */
917 if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {
918 this->vscroll->ScrollTowards(to);
922 void UpdateButtonState()
924 if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
926 bool shared_orders = this->vehicle->IsOrderListShared();
927 VehicleOrderID sel = this->OrderGetSel();
928 const Order *order = this->vehicle->GetOrder(sel);
930 /* Second row. */
931 /* skip */
932 this->SetWidgetDisabledState(WID_O_SKIP, this->vehicle->GetNumOrders() <= 1);
934 /* delete / stop sharing */
935 NWidgetStacked *delete_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_BOTTOM_MIDDLE);
936 if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
937 /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
938 delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_STOP_SHARING);
939 } else {
940 /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
941 delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE);
942 this->SetWidgetDisabledState(WID_O_DELETE,
943 (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
945 /* Set the tooltip of the 'delete' button depending on whether the
946 * 'End of Orders' order or a regular order is selected. */
947 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
948 if (this->selected_order == this->vehicle->GetNumOrders()) {
949 nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
950 } else {
951 nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
955 /* First row. */
956 this->RaiseWidget(WID_O_FULL_LOAD);
957 this->RaiseWidget(WID_O_UNLOAD);
958 this->RaiseWidget(WID_O_SERVICE);
960 /* Selection widgets. */
961 /* Train or road vehicle. */
962 NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
963 NWidgetStacked *left_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
964 NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
965 NWidgetStacked *right_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
966 /* Ship or airplane. */
967 NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
968 assert(row_sel != NULL || (train_row_sel != NULL && left_sel != NULL && middle_sel != NULL && right_sel != NULL));
971 if (order == NULL) {
972 if (row_sel != NULL) {
973 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
974 } else {
975 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
976 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
977 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
978 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
979 this->DisableWidget(WID_O_NON_STOP);
980 this->RaiseWidget(WID_O_NON_STOP);
982 this->DisableWidget(WID_O_FULL_LOAD);
983 this->DisableWidget(WID_O_UNLOAD);
984 this->DisableWidget(WID_O_REFIT_DROPDOWN);
985 } else {
986 this->SetWidgetDisabledState(WID_O_FULL_LOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
987 this->SetWidgetDisabledState(WID_O_UNLOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
989 switch (order->GetType()) {
990 case OT_GOTO_STATION:
991 if (row_sel != NULL) {
992 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
993 } else {
994 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
995 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
996 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
997 right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
998 this->EnableWidget(WID_O_NON_STOP);
999 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1001 this->SetWidgetLoweredState(WID_O_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
1002 this->SetWidgetLoweredState(WID_O_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
1004 /* Can only do refitting when stopping at the destination and loading cargo.
1005 * Also enable the button if a refit is already set to allow clearing it. */
1006 this->SetWidgetDisabledState(WID_O_REFIT_DROPDOWN,
1007 order->GetLoadType() == OLFB_NO_LOAD || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ||
1008 ((!this->can_do_refit || !this->can_do_autorefit) && !order->IsRefit()));
1010 break;
1012 case OT_GOTO_WAYPOINT:
1013 if (row_sel != NULL) {
1014 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1015 } else {
1016 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1017 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1018 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1019 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1020 this->EnableWidget(WID_O_NON_STOP);
1021 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1023 this->DisableWidget(WID_O_FULL_LOAD);
1024 this->DisableWidget(WID_O_UNLOAD);
1025 this->DisableWidget(WID_O_REFIT_DROPDOWN);
1026 break;
1028 case OT_GOTO_DEPOT:
1029 if (row_sel != NULL) {
1030 row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
1031 } else {
1032 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1033 left_sel->SetDisplayedPlane(DP_LEFT_REFIT);
1034 middle_sel->SetDisplayedPlane(DP_MIDDLE_SERVICE);
1035 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1036 this->EnableWidget(WID_O_NON_STOP);
1037 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1039 /* Disable refit button if the order is no 'always go' order.
1040 * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
1041 this->SetWidgetDisabledState(WID_O_REFIT,
1042 (order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT) ||
1043 (!this->can_do_refit && !order->IsRefit()));
1044 this->SetWidgetLoweredState(WID_O_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
1045 break;
1047 case OT_CONDITIONAL: {
1048 if (row_sel != NULL) {
1049 row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
1050 } else {
1051 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_CONDITIONAL);
1053 OrderConditionVariable ocv = order->GetConditionVariable();
1054 /* Set the strings for the dropdown boxes. */
1055 this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv;
1056 this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order->GetConditionComparator()];
1057 this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
1058 this->SetWidgetDisabledState(WID_O_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
1059 break;
1062 default: // every other order
1063 if (row_sel != NULL) {
1064 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1065 } else {
1066 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1067 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1068 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1069 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1070 this->DisableWidget(WID_O_NON_STOP);
1072 this->DisableWidget(WID_O_FULL_LOAD);
1073 this->DisableWidget(WID_O_UNLOAD);
1074 this->DisableWidget(WID_O_REFIT_DROPDOWN);
1075 break;
1079 /* Disable list of vehicles with the same shared orders if there is no list */
1080 this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders);
1082 this->SetDirty();
1085 virtual void OnPaint()
1087 if (this->vehicle->owner != _local_company) {
1088 this->selected_order = -1; // Disable selection any selected row at a competitor order window.
1089 } else {
1090 this->SetWidgetLoweredState(WID_O_GOTO, this->goto_type != OPOS_NONE);
1092 this->DrawWidgets();
1095 virtual void DrawWidget(const Rect &r, int widget) const
1097 if (widget != WID_O_ORDER_LIST) return;
1099 bool rtl = _current_text_dir == TD_RTL;
1100 SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
1101 int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
1102 int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
1104 int y = r.top + WD_FRAMERECT_TOP;
1105 int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
1107 int i = this->vscroll->GetPosition();
1108 const Order *order = this->vehicle->GetOrder(i);
1109 /* First draw the highlighting underground if it exists. */
1110 if (this->order_over != INVALID_VEH_ORDER_ID) {
1111 while (order != NULL) {
1112 /* Don't draw anything if it extends past the end of the window. */
1113 if (!this->vscroll->IsVisible(i)) break;
1115 if (i != this->selected_order && i == this->order_over) {
1116 /* Highlight dragged order destination. */
1117 int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
1118 int bottom = min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM);
1119 top = max(top - 3, r.top + WD_FRAMERECT_TOP);
1120 GfxFillRect(r.left + WD_FRAMETEXT_LEFT, top, r.right - WD_FRAMETEXT_RIGHT, bottom, _colour_gradient[COLOUR_GREY][7]);
1121 break;
1123 y += line_height;
1125 i++;
1126 order = order->next;
1129 /* Reset counters for drawing the orders. */
1130 y = r.top + WD_FRAMERECT_TOP;
1131 i = this->vscroll->GetPosition();
1132 order = this->vehicle->GetOrder(i);
1135 /* Draw the orders. */
1136 while (order != NULL) {
1137 /* Don't draw anything if it extends past the end of the window. */
1138 if (!this->vscroll->IsVisible(i)) break;
1140 DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
1141 y += line_height;
1143 i++;
1144 order = order->next;
1147 if (this->vscroll->IsVisible(i)) {
1148 StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
1149 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);
1153 virtual void SetStringParameters(int widget) const
1155 switch (widget) {
1156 case WID_O_COND_VALUE: {
1157 VehicleOrderID sel = this->OrderGetSel();
1158 const Order *order = this->vehicle->GetOrder(sel);
1160 if (order != NULL && order->IsType(OT_CONDITIONAL)) {
1161 uint value = order->GetConditionValue();
1162 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1163 SetDParam(0, value);
1165 break;
1168 case WID_O_CAPTION:
1169 SetDParam(0, this->vehicle->index);
1170 break;
1174 virtual void OnClick(Point pt, int widget, int click_count)
1176 switch (widget) {
1177 case WID_O_ORDER_LIST: {
1178 if (this->goto_type == OPOS_CONDITIONAL) {
1179 VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
1180 if (order_id != INVALID_VEH_ORDER_ID) {
1181 Order order;
1182 order.next = NULL;
1183 order.index = 0;
1184 order.MakeConditional(order_id);
1186 DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
1188 ResetObjectToPlace();
1189 break;
1192 VehicleOrderID sel = this->GetOrderFromPt(pt.y);
1194 if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
1195 TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
1196 if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
1197 return;
1200 /* This order won't be selected any more, close all child windows and dropdowns */
1201 this->DeleteChildWindows();
1202 HideDropDownMenu(this);
1204 if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
1205 /* Deselect clicked order */
1206 this->selected_order = -1;
1207 } else if (sel == this->selected_order) {
1208 if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
1209 DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20),
1210 MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
1211 CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1213 } else {
1214 /* Select clicked order */
1215 this->selected_order = sel;
1217 if (this->vehicle->owner == _local_company) {
1218 /* Activate drag and drop */
1219 SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1223 this->UpdateButtonState();
1224 break;
1227 case WID_O_SKIP:
1228 this->OrderClick_Skip();
1229 break;
1231 case WID_O_DELETE:
1232 this->OrderClick_Delete();
1233 break;
1235 case WID_O_STOP_SHARING:
1236 this->OrderClick_StopSharing();
1237 break;
1239 case WID_O_NON_STOP:
1240 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1241 this->OrderClick_Nonstop(-1);
1242 } else {
1243 const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1244 ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
1245 o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
1247 break;
1249 case WID_O_GOTO:
1250 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1251 if (this->goto_type != OPOS_NONE) {
1252 ResetObjectToPlace();
1253 } else {
1254 this->OrderClick_Goto(OPOS_GOTO);
1256 } else {
1257 int sel;
1258 switch (this->goto_type) {
1259 case OPOS_NONE: sel = -1; break;
1260 case OPOS_GOTO: sel = 0; break;
1261 case OPOS_CONDITIONAL: sel = 2; break;
1262 case OPOS_SHARE: sel = 3; break;
1263 default: NOT_REACHED();
1265 ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
1267 break;
1269 case WID_O_FULL_LOAD:
1270 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1271 this->OrderClick_FullLoad(-1);
1272 } else {
1273 ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
1275 break;
1277 case WID_O_UNLOAD:
1278 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1279 this->OrderClick_Unload(-1);
1280 } else {
1281 ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
1283 break;
1285 case WID_O_REFIT:
1286 this->OrderClick_Refit(0, false);
1287 break;
1289 case WID_O_SERVICE:
1290 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1291 this->OrderClick_Service(-1);
1292 } else {
1293 ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_SERVICE, 0, 0);
1295 break;
1297 case WID_O_REFIT_DROPDOWN:
1298 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1299 this->OrderClick_Refit(0, true);
1300 } else {
1301 ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
1303 break;
1305 case WID_O_TIMETABLE_VIEW:
1306 ShowTimetableWindow(this->vehicle);
1307 break;
1309 case WID_O_COND_VARIABLE: {
1310 DropDownList *list = new DropDownList();
1311 for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
1312 *list->Append() = new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false);
1314 ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
1315 break;
1318 case WID_O_COND_COMPARATOR: {
1319 const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1320 ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
1321 break;
1324 case WID_O_COND_VALUE: {
1325 const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
1326 uint value = order->GetConditionValue();
1327 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1328 SetDParam(0, value);
1329 ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE);
1330 break;
1333 case WID_O_SHARED_ORDER_LIST:
1334 ShowVehicleListWindow(this->vehicle);
1335 break;
1339 virtual void OnQueryTextFinished(char *str)
1341 if (!StrEmpty(str)) {
1342 VehicleOrderID sel = this->OrderGetSel();
1343 uint value = atoi(str);
1345 switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
1346 case OCV_MAX_SPEED:
1347 value = ConvertDisplaySpeedToSpeed(value);
1348 break;
1350 case OCV_RELIABILITY:
1351 case OCV_LOAD_PERCENTAGE:
1352 value = Clamp(value, 0, 100);
1353 break;
1355 default:
1356 break;
1358 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));
1362 virtual void OnDropdownSelect(int widget, int index)
1364 switch (widget) {
1365 case WID_O_NON_STOP:
1366 this->OrderClick_Nonstop(index);
1367 break;
1369 case WID_O_FULL_LOAD:
1370 this->OrderClick_FullLoad(index);
1371 break;
1373 case WID_O_UNLOAD:
1374 this->OrderClick_Unload(index);
1375 break;
1377 case WID_O_GOTO:
1378 switch (index) {
1379 case 0: this->OrderClick_Goto(OPOS_GOTO); break;
1380 case 1: this->OrderClick_NearestDepot(); break;
1381 case 2: this->OrderClick_Goto(OPOS_CONDITIONAL); break;
1382 case 3: this->OrderClick_Goto(OPOS_SHARE); break;
1383 default: NOT_REACHED();
1385 break;
1387 case WID_O_SERVICE:
1388 this->OrderClick_Service(index);
1389 break;
1391 case WID_O_REFIT_DROPDOWN:
1392 this->OrderClick_Refit(index, true);
1393 break;
1395 case WID_O_COND_VARIABLE:
1396 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));
1397 break;
1399 case WID_O_COND_COMPARATOR:
1400 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));
1401 break;
1405 virtual void OnDragDrop(Point pt, int widget)
1407 switch (widget) {
1408 case WID_O_ORDER_LIST: {
1409 VehicleOrderID from_order = this->OrderGetSel();
1410 VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1412 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()) &&
1413 DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
1414 this->selected_order = -1;
1415 this->UpdateButtonState();
1417 break;
1420 case WID_O_DELETE:
1421 this->OrderClick_Delete();
1422 break;
1424 case WID_O_STOP_SHARING:
1425 this->OrderClick_StopSharing();
1426 break;
1429 ResetObjectToPlace();
1431 if (this->order_over != INVALID_VEH_ORDER_ID) {
1432 /* End of drag-and-drop, hide dragged order destination highlight. */
1433 this->order_over = INVALID_VEH_ORDER_ID;
1434 this->SetWidgetDirty(WID_O_ORDER_LIST);
1438 virtual EventState OnHotkey(int hotkey)
1440 if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
1442 switch (hotkey) {
1443 case OHK_SKIP: this->OrderClick_Skip(); break;
1444 case OHK_DELETE: this->OrderClick_Delete(); break;
1445 case OHK_GOTO: this->OrderClick_Goto(OPOS_GOTO); break;
1446 case OHK_NONSTOP: this->OrderClick_Nonstop(-1); break;
1447 case OHK_FULLLOAD: this->OrderClick_FullLoad(-1); break;
1448 case OHK_UNLOAD: this->OrderClick_Unload(-1); break;
1449 case OHK_NEAREST_DEPOT: this->OrderClick_NearestDepot(); break;
1450 case OHK_ALWAYS_SERVICE: this->OrderClick_Service(-1); break;
1451 case OHK_TRANSFER: this->OrderHotkey_Transfer(); break;
1452 case OHK_NO_UNLOAD: this->OrderHotkey_NoUnload(); break;
1453 case OHK_NO_LOAD: this->OrderHotkey_NoLoad(); break;
1454 default: return ES_NOT_HANDLED;
1456 return ES_HANDLED;
1459 virtual void OnPlaceObject(Point pt, TileIndex tile)
1461 if (this->goto_type == OPOS_GOTO) {
1462 const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
1463 if (cmd.IsType(OT_NOTHING)) return;
1465 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))) {
1466 /* With quick goto the Go To button stays active */
1467 if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
1472 virtual bool OnVehicleSelect(const Vehicle *v)
1474 /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
1475 * We disallow copying orders of other vehicles if we already have at least one order entry
1476 * ourself as it easily copies orders of vehicles within a station when we mean the station.
1477 * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
1478 * TODO: give a warning message */
1479 bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
1480 if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
1482 if (DoCommandP(this->vehicle->tile, this->vehicle->index | (share_order ? CO_SHARE : CO_COPY) << 30, v->index,
1483 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))) {
1484 this->selected_order = -1;
1485 ResetObjectToPlace();
1487 return true;
1490 virtual void OnPlaceObjectAbort()
1492 this->goto_type = OPOS_NONE;
1493 this->SetWidgetDirty(WID_O_GOTO);
1495 /* Remove drag highlighting if it exists. */
1496 if (this->order_over != INVALID_VEH_ORDER_ID) {
1497 this->order_over = INVALID_VEH_ORDER_ID;
1498 this->SetWidgetDirty(WID_O_ORDER_LIST);
1502 virtual void OnMouseDrag(Point pt, int widget)
1504 if (this->selected_order != -1 && widget == WID_O_ORDER_LIST) {
1505 /* An order is dragged.. */
1506 VehicleOrderID from_order = this->OrderGetSel();
1507 VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1508 uint num_orders = this->vehicle->GetNumOrders();
1510 if (from_order != INVALID_VEH_ORDER_ID && from_order <= num_orders) {
1511 if (to_order != INVALID_VEH_ORDER_ID && to_order <= num_orders) { // ..over an existing order.
1512 this->order_over = to_order;
1513 this->SetWidgetDirty(widget);
1514 } else if (from_order != to_order && this->order_over != INVALID_VEH_ORDER_ID) { // ..outside of the order list.
1515 this->order_over = INVALID_VEH_ORDER_ID;
1516 this->SetWidgetDirty(widget);
1522 virtual void OnResize()
1524 /* Update the scroll bar */
1525 this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
1528 static HotkeyList hotkeys;
1531 static Hotkey order_hotkeys[] = {
1532 Hotkey('D', "skip", OHK_SKIP),
1533 Hotkey('F', "delete", OHK_DELETE),
1534 Hotkey('G', "goto", OHK_GOTO),
1535 Hotkey('H', "nonstop", OHK_NONSTOP),
1536 Hotkey('J', "fullload", OHK_FULLLOAD),
1537 Hotkey('K', "unload", OHK_UNLOAD),
1538 Hotkey((uint16)0, "nearest_depot", OHK_NEAREST_DEPOT),
1539 Hotkey((uint16)0, "always_service", OHK_ALWAYS_SERVICE),
1540 Hotkey((uint16)0, "transfer", OHK_TRANSFER),
1541 Hotkey((uint16)0, "no_unload", OHK_NO_UNLOAD),
1542 Hotkey((uint16)0, "no_load", OHK_NO_LOAD),
1543 HOTKEY_LIST_END
1545 HotkeyList OrdersWindow::hotkeys("order", order_hotkeys);
1547 /** Nested widget definition for "your" train orders. */
1548 static const NWidgetPart _nested_orders_train_widgets[] = {
1549 NWidget(NWID_HORIZONTAL),
1550 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1551 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1552 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1553 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1554 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1555 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1556 EndContainer(),
1557 NWidget(NWID_HORIZONTAL),
1558 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(),
1559 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1560 EndContainer(),
1562 /* First button row. */
1563 NWidget(NWID_HORIZONTAL),
1564 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW_GROUNDVEHICLE),
1565 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1566 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_NON_STOP), SetMinimalSize(93, 12), SetFill(1, 0),
1567 SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
1568 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_LEFT),
1569 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1570 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1571 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(93, 12), SetFill(1, 0),
1572 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1573 EndContainer(),
1574 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_MIDDLE),
1575 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1576 SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1577 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(93, 12), SetFill(1, 0),
1578 SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1579 EndContainer(),
1580 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_RIGHT),
1581 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_O_EMPTY), SetMinimalSize(93, 12), SetFill(1, 0),
1582 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1583 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(93, 12), SetFill(1, 0),
1584 SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1585 EndContainer(),
1586 EndContainer(),
1587 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1588 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1589 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1590 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1591 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1592 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1593 SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1594 EndContainer(),
1595 EndContainer(),
1596 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),
1597 EndContainer(),
1599 /* Second button row. */
1600 NWidget(NWID_HORIZONTAL),
1601 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1602 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1603 SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1604 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
1605 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1606 SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1607 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1608 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1609 EndContainer(),
1610 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1611 SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1612 EndContainer(),
1613 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1614 EndContainer(),
1617 static WindowDesc _orders_train_desc(
1618 WDP_AUTO, "view_vehicle_orders_train", 384, 100,
1619 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
1620 WDF_CONSTRUCTION,
1621 _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets),
1622 &OrdersWindow::hotkeys
1625 /** Nested widget definition for "your" orders (non-train). */
1626 static const NWidgetPart _nested_orders_widgets[] = {
1627 NWidget(NWID_HORIZONTAL),
1628 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1629 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1630 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1631 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1632 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1633 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1634 EndContainer(),
1635 NWidget(NWID_HORIZONTAL),
1636 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(),
1637 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1638 EndContainer(),
1640 /* First button row. */
1641 NWidget(NWID_HORIZONTAL),
1642 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW),
1643 /* Load + unload + refit buttons. */
1644 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1645 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1646 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1647 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1648 SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1649 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(124, 12), SetFill(1, 0),
1650 SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1651 EndContainer(),
1652 /* Refit + service buttons. */
1653 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1654 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
1655 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1656 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
1657 SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1658 EndContainer(),
1660 /* Buttons for setting a condition. */
1661 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1662 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1663 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1664 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1665 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1666 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1667 SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1668 EndContainer(),
1669 EndContainer(),
1671 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),
1672 EndContainer(),
1674 /* Second button row. */
1675 NWidget(NWID_HORIZONTAL),
1676 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1677 SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1678 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
1679 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1680 SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1681 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1682 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1683 EndContainer(),
1684 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1685 SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1686 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1687 EndContainer(),
1690 static WindowDesc _orders_desc(
1691 WDP_AUTO, "view_vehicle_orders", 384, 100,
1692 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
1693 WDF_CONSTRUCTION,
1694 _nested_orders_widgets, lengthof(_nested_orders_widgets),
1695 &OrdersWindow::hotkeys
1698 /** Nested widget definition for competitor orders. */
1699 static const NWidgetPart _nested_other_orders_widgets[] = {
1700 NWidget(NWID_HORIZONTAL),
1701 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1702 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1703 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1704 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1705 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1706 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1707 EndContainer(),
1708 NWidget(NWID_HORIZONTAL),
1709 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(),
1710 NWidget(NWID_VERTICAL),
1711 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1712 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1713 EndContainer(),
1714 EndContainer(),
1717 static WindowDesc _other_orders_desc(
1718 WDP_AUTO, "view_vehicle_orders_competitor", 384, 86,
1719 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
1720 WDF_CONSTRUCTION,
1721 _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets),
1722 &OrdersWindow::hotkeys
1725 void ShowOrdersWindow(const Vehicle *v)
1727 DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
1728 DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
1729 if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
1731 if (v->owner != _local_company) {
1732 new OrdersWindow(&_other_orders_desc, v);
1733 } else {
1734 new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);