Translations update
[openttd/fttd.git] / src / order_gui.cpp
blob9bd0aa2a0a95a1f79d8ac5396a7606041865f2ac
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 Order order;
352 order.next = NULL;
353 order.index = 0;
355 /* check depot first */
356 switch (GetTileType(tile)) {
357 case TT_MISC:
358 if (!IsTileSubtype(tile, TT_MISC_DEPOT)) break;
360 if (v->type == (IsRailDepot(tile) ? VEH_TRAIN : VEH_ROAD) && IsTileOwner(tile, _local_company)) {
361 order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS,
362 _settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
363 if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
364 return order;
366 break;
368 case TT_STATION:
369 if (v->type != VEH_AIRCRAFT) break;
370 if (IsHangar(tile) && IsTileOwner(tile, _local_company)) {
371 order.MakeGoToDepot(GetStationIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
372 if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
373 return order;
375 break;
377 case TT_WATER:
378 if (v->type != VEH_SHIP) break;
379 if (IsShipDepot(tile) && IsTileOwner(tile, _local_company)) {
380 order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
381 if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
382 return order;
384 break;
386 default:
387 break;
390 /* check waypoint */
391 if (IsRailWaypointTile(tile) &&
392 v->type == VEH_TRAIN &&
393 IsTileOwner(tile, _local_company)) {
394 order.MakeGoToWaypoint(Waypoint::GetByTile(tile)->index);
395 if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
396 return order;
399 if ((IsBuoyTile(tile) && v->type == VEH_SHIP) || (IsRailWaypointTile(tile) && v->type == VEH_TRAIN)) {
400 order.MakeGoToWaypoint(GetStationIndex(tile));
401 return order;
404 if (IsStationTile(tile)) {
405 StationID st_index = GetStationIndex(tile);
406 const Station *st = Station::Get(st_index);
408 if (st->owner == _local_company || st->owner == OWNER_NONE) {
409 byte facil;
410 (facil = FACIL_DOCK, v->type == VEH_SHIP) ||
411 (facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
412 (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
413 (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
414 (facil = FACIL_TRUCK_STOP, 1);
415 if (st->facilities & facil) {
416 order.MakeGoToStation(st_index);
417 if (_ctrl_pressed) order.SetLoadType(OLF_FULL_LOAD_ANY);
418 if (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
419 order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OSL_PLATFORM_FAR_END);
420 return order;
425 /* not found */
426 order.Free();
427 return order;
430 /** Hotkeys for order window. */
431 enum {
432 OHK_SKIP,
433 OHK_DELETE,
434 OHK_GOTO,
435 OHK_NONSTOP,
436 OHK_FULLLOAD,
437 OHK_UNLOAD,
438 OHK_NEAREST_DEPOT,
439 OHK_ALWAYS_SERVICE,
440 OHK_TRANSFER,
441 OHK_NO_UNLOAD,
442 OHK_NO_LOAD,
446 * %Order window code for all vehicles.
448 * At the bottom of the window two button rows are located for changing the orders of the vehicle.
450 * \section top-row Top row
451 * 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.
453 * The top-row buttons of one of your trains or road vehicles is one of the following three cases:
454 * \verbatim
455 * +-----------------+-----------------+-----------------+-----------------+
456 * | NON-STOP | FULL_LOAD | UNLOAD | REFIT | (normal)
457 * +-----------------+-----+-----------+-----------+-----+-----------------+
458 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
459 * +-----------------+-----+-----------+-----------+-----+-----------------+
460 * | NON-STOP | REFIT | SERVICE | (empty) | (for depot orders)
461 * +-----------------+-----------------+-----------------+-----------------+
462 * \endverbatim
464 * Airplanes and ships have one of the following three top-row button rows:
465 * \verbatim
466 * +-----------------+-----------------+-----------------+
467 * | FULL_LOAD | UNLOAD | REFIT | (normal)
468 * +-----------------+-----------------+-----------------+
469 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
470 * +-----------------+--------+--------+-----------------+
471 * | REFIT | SERVICE | (for depot order)
472 * +--------------------------+--------------------------+
473 * \endverbatim
475 * \section bottom-row Bottom row
476 * The second row (the bottom row) is for manipulating the list of orders:
477 * \verbatim
478 * +-----------------+-----------------+-----------------+
479 * | SKIP | DELETE | GOTO |
480 * +-----------------+-----------------+-----------------+
481 * \endverbatim
483 * For vehicles of other companies, both button rows are not displayed.
485 struct OrdersWindow : public Window {
486 private:
487 /** Under what reason are we using the PlaceObject functionality? */
488 enum OrderPlaceObjectState {
489 OPOS_NONE,
490 OPOS_GOTO,
491 OPOS_CONDITIONAL,
492 OPOS_SHARE,
493 OPOS_END,
496 /** Displayed planes of the #NWID_SELECTION widgets. */
497 enum DisplayPane {
498 /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
499 DP_GROUNDVEHICLE_ROW_NORMAL = 0, ///< Display the row for normal/depot orders in the top row of the train/rv order window.
500 DP_GROUNDVEHICLE_ROW_CONDITIONAL = 1, ///< Display the row for conditional orders in the top row of the train/rv order window.
502 /* WID_O_SEL_TOP_LEFT */
503 DP_LEFT_LOAD = 0, ///< Display 'load' in the left button of the top row of the train/rv order window.
504 DP_LEFT_REFIT = 1, ///< Display 'refit' in the left button of the top row of the train/rv order window.
506 /* WID_O_SEL_TOP_MIDDLE */
507 DP_MIDDLE_UNLOAD = 0, ///< Display 'unload' in the middle button of the top row of the train/rv order window.
508 DP_MIDDLE_SERVICE = 1, ///< Display 'service' in the middle button of the top row of the train/rv order window.
510 /* WID_O_SEL_TOP_RIGHT */
511 DP_RIGHT_EMPTY = 0, ///< Display an empty panel in the right button of the top row of the train/rv order window.
512 DP_RIGHT_REFIT = 1, ///< Display 'refit' in the right button of the top row of the train/rv order window.
514 /* WID_O_SEL_TOP_ROW */
515 DP_ROW_LOAD = 0, ///< Display 'load' / 'unload' / 'refit' buttons in the top row of the ship/airplane order window.
516 DP_ROW_DEPOT = 1, ///< Display 'refit' / 'service' buttons in the top row of the ship/airplane order window.
517 DP_ROW_CONDITIONAL = 2, ///< Display the conditional order buttons in the top row of the ship/airplane order window.
519 /* WID_O_SEL_BOTTOM_MIDDLE */
520 DP_BOTTOM_MIDDLE_DELETE = 0, ///< Display 'delete' in the middle button of the bottom row of the vehicle order window.
521 DP_BOTTOM_MIDDLE_STOP_SHARING = 1, ///< Display 'stop sharing' in the middle button of the bottom row of the vehicle order window.
524 int selected_order;
525 VehicleOrderID order_over; ///< Order over which another order is dragged, \c INVALID_VEH_ORDER_ID if none.
526 OrderPlaceObjectState goto_type;
527 const Vehicle *vehicle; ///< Vehicle owning the orders being displayed and manipulated.
528 Scrollbar *vscroll;
529 bool can_do_refit; ///< Vehicle chain can be refitted in depot.
530 bool can_do_autorefit; ///< Vehicle chain can be auto-refitted.
533 * Return the memorised selected order.
534 * @return the memorised order if it is a valid one
535 * else return the number of orders
537 VehicleOrderID OrderGetSel() const
539 int num = this->selected_order;
540 return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
544 * Calculate the selected order.
545 * The calculation is based on the relative (to the window) y click position and
546 * the position of the scrollbar.
548 * @param y Y-value of the click relative to the window origin
549 * @return The selected order if the order is valid, else return \c INVALID_VEH_ORDER_ID.
551 VehicleOrderID GetOrderFromPt(int y)
553 NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST);
554 int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
556 if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID;
558 sel += this->vscroll->GetPosition();
560 return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID;
564 * Handle the click on the goto button.
566 void OrderClick_Goto(OrderPlaceObjectState type)
568 assert(type > OPOS_NONE && type < OPOS_END);
570 static const HighLightStyle goto_place_style[OPOS_END - 1] = {
571 HT_RECT | HT_VEHICLE, // OPOS_GOTO
572 HT_NONE, // OPOS_CONDITIONAL
573 HT_VEHICLE, // OPOS_SHARE
575 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, goto_place_style[type - 1], this);
576 this->goto_type = type;
577 this->SetWidgetDirty(WID_O_GOTO);
581 * Handle the click on the full load button.
582 * @param load_type the way to load.
584 void OrderClick_FullLoad(int load_type)
586 VehicleOrderID sel_ord = this->OrderGetSel();
587 const Order *order = this->vehicle->GetOrder(sel_ord);
589 if (order == NULL || order->GetLoadType() == load_type) return;
591 if (load_type < 0) {
592 load_type = order->GetLoadType() == OLF_LOAD_IF_POSSIBLE ? OLF_FULL_LOAD_ANY : OLF_LOAD_IF_POSSIBLE;
594 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));
598 * Handle the 'no loading' hotkey
600 void OrderHotkey_NoLoad()
602 this->OrderClick_FullLoad(OLFB_NO_LOAD);
606 * Handle the click on the service.
608 void OrderClick_Service(int i)
610 VehicleOrderID sel_ord = this->OrderGetSel();
612 if (i < 0) {
613 const Order *order = this->vehicle->GetOrder(sel_ord);
614 if (order == NULL) return;
615 i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
617 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));
621 * Handle the click on the service in nearest depot button.
623 void OrderClick_NearestDepot()
625 Order order;
626 order.next = NULL;
627 order.index = 0;
628 order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS,
629 _settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
630 order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
632 DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
636 * Handle the click on the unload button.
638 void OrderClick_Unload(int unload_type)
640 VehicleOrderID sel_ord = this->OrderGetSel();
641 const Order *order = this->vehicle->GetOrder(sel_ord);
643 if (order == NULL || order->GetUnloadType() == unload_type) return;
645 if (unload_type < 0) {
646 unload_type = order->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE ? OUFB_UNLOAD : OUF_UNLOAD_IF_POSSIBLE;
649 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));
651 /* Transfer orders with leave empty as default */
652 if (unload_type == OUFB_TRANSFER) {
653 DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), CMD_MODIFY_ORDER);
654 this->SetWidgetDirty(WID_O_FULL_LOAD);
659 * Handle the transfer hotkey
661 void OrderHotkey_Transfer()
663 this->OrderClick_Unload(OUFB_TRANSFER);
667 * Handle the 'no unload' hotkey
669 void OrderHotkey_NoUnload()
671 this->OrderClick_Unload(OUFB_NO_UNLOAD);
675 * Handle the click on the nonstop button.
676 * @param non_stop what non-stop type to use; -1 to use the 'next' one.
678 void OrderClick_Nonstop(int non_stop)
680 if (!this->vehicle->IsGroundVehicle()) return;
682 VehicleOrderID sel_ord = this->OrderGetSel();
683 const Order *order = this->vehicle->GetOrder(sel_ord);
685 if (order == NULL || order->GetNonStopType() == non_stop) return;
687 /* Keypress if negative, so 'toggle' to the next */
688 if (non_stop < 0) {
689 non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
692 this->SetWidgetDirty(WID_O_NON_STOP);
693 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));
697 * Handle the click on the skip button.
698 * If ctrl is pressed, skip to selected order, else skip to current order + 1
700 void OrderClick_Skip()
702 /* Don't skip when there's nothing to skip */
703 if (_ctrl_pressed && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
704 if (this->vehicle->GetNumOrders() <= 1) return;
706 DoCommandP(this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()),
707 CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
711 * Handle the click on the delete button.
713 void OrderClick_Delete()
715 /* When networking, move one order lower */
716 int selected = this->selected_order + (int)_networking;
718 if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
719 this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
720 this->UpdateButtonState();
725 * Handle the click on the 'stop sharing' button.
726 * If 'End of Shared Orders' isn't selected, do nothing. If Ctrl is pressed, call OrderClick_Delete and exit.
727 * To stop sharing this vehicle order list, we copy the orders of a vehicle that share this order list. That way we
728 * exit the group of shared vehicles while keeping the same order list.
730 void OrderClick_StopSharing()
732 /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
733 if (!this->vehicle->IsOrderListShared() || this->selected_order != this->vehicle->GetNumOrders()) return;
734 /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
735 if (_ctrl_pressed) {
736 this->OrderClick_Delete();
737 return;
740 /* Get another vehicle that share orders with this vehicle. */
741 Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
742 /* Copy the order list of the other vehicle. */
743 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))) {
744 this->UpdateButtonState();
749 * Handle the click on the refit button.
750 * If ctrl is pressed, cancel refitting, else show the refit window.
751 * @param i Selected refit command.
752 * @param auto_refit Select refit for auto-refitting.
754 void OrderClick_Refit(int i, bool auto_refit)
756 if (_ctrl_pressed) {
757 /* Cancel refitting */
758 DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
759 } else {
760 if (i == 1) { // Auto-refit to available cargo type.
761 DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | CT_AUTO_REFIT, CMD_ORDER_REFIT);
762 } else {
763 ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
768 /** Cache auto-refittability of the vehicle chain. */
769 void UpdateAutoRefitState()
771 this->can_do_refit = false;
772 this->can_do_autorefit = false;
773 for (const Vehicle *w = this->vehicle; w != NULL; w = w->IsGroundVehicle() ? w->Next() : NULL) {
774 if (IsEngineRefittable(w->engine_type)) this->can_do_refit = true;
775 if (HasBit(Engine::Get(w->engine_type)->info.misc_flags, EF_AUTO_REFIT)) this->can_do_autorefit = true;
779 public:
780 OrdersWindow(WindowDesc *desc, const Vehicle *v) : Window(desc)
782 this->vehicle = v;
784 this->CreateNestedTree();
785 this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
786 this->FinishInitNested(v->index);
787 if (v->owner == _local_company) {
788 this->DisableWidget(WID_O_EMPTY);
791 this->selected_order = -1;
792 this->order_over = INVALID_VEH_ORDER_ID;
793 this->goto_type = OPOS_NONE;
794 this->owner = v->owner;
796 this->UpdateAutoRefitState();
798 if (_settings_client.gui.quick_goto && v->owner == _local_company) {
799 /* If there are less than 2 station, make Go To active. */
800 int station_orders = 0;
801 const Order *order;
802 FOR_VEHICLE_ORDERS(v, order) {
803 if (order->IsType(OT_GOTO_STATION)) station_orders++;
806 if (station_orders < 2) this->OrderClick_Goto(OPOS_GOTO);
808 this->OnInvalidateData(VIWD_MODIFY_ORDERS);
811 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
813 switch (widget) {
814 case WID_O_ORDER_LIST:
815 resize->height = FONT_HEIGHT_NORMAL;
816 size->height = 6 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
817 break;
819 case WID_O_COND_VARIABLE: {
820 Dimension d = {0, 0};
821 for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
822 d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i]));
824 d.width += padding.width;
825 d.height += padding.height;
826 *size = maxdim(*size, d);
827 break;
830 case WID_O_COND_COMPARATOR: {
831 Dimension d = {0, 0};
832 for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
833 d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
835 d.width += padding.width;
836 d.height += padding.height;
837 *size = maxdim(*size, d);
838 break;
844 * Some data on this window has become invalid.
845 * @param data Information about the changed data.
846 * @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.
848 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
850 VehicleOrderID from = INVALID_VEH_ORDER_ID;
851 VehicleOrderID to = INVALID_VEH_ORDER_ID;
853 switch (data) {
854 case VIWD_AUTOREPLACE:
855 /* Autoreplace replaced the vehicle */
856 this->vehicle = Vehicle::Get(this->window_number);
857 /* FALL THROUGH */
859 case VIWD_CONSIST_CHANGED:
860 /* Vehicle composition was changed. */
861 this->UpdateAutoRefitState();
862 break;
864 case VIWD_REMOVE_ALL_ORDERS:
865 /* Removed / replaced all orders (after deleting / sharing) */
866 if (this->selected_order == -1) break;
868 this->DeleteChildWindows();
869 HideDropDownMenu(this);
870 this->selected_order = -1;
871 break;
873 case VIWD_MODIFY_ORDERS:
874 /* Some other order changes */
875 break;
877 default:
878 if (data < 0) break;
880 if (gui_scope) break; // only do this once; from command scope
881 from = GB(data, 0, 8);
882 to = GB(data, 8, 8);
883 /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
884 * the order is being created / removed */
885 if (this->selected_order == -1) break;
887 if (from == to) break; // no need to change anything
889 if (from != this->selected_order) {
890 /* Moving from preceding order? */
891 this->selected_order -= (int)(from <= this->selected_order);
892 /* Moving to preceding order? */
893 this->selected_order += (int)(to <= this->selected_order);
894 break;
897 /* Now we are modifying the selected order */
898 if (to == INVALID_VEH_ORDER_ID) {
899 /* Deleting selected order */
900 this->DeleteChildWindows();
901 HideDropDownMenu(this);
902 this->selected_order = -1;
903 break;
906 /* Moving selected order */
907 this->selected_order = to;
908 break;
911 this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
912 if (gui_scope) this->UpdateButtonState();
914 /* Scroll to the new order. */
915 if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {
916 this->vscroll->ScrollTowards(to);
920 void UpdateButtonState()
922 if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
924 bool shared_orders = this->vehicle->IsOrderListShared();
925 VehicleOrderID sel = this->OrderGetSel();
926 const Order *order = this->vehicle->GetOrder(sel);
928 /* Second row. */
929 /* skip */
930 this->SetWidgetDisabledState(WID_O_SKIP, this->vehicle->GetNumOrders() <= 1);
932 /* delete / stop sharing */
933 NWidgetStacked *delete_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_BOTTOM_MIDDLE);
934 if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
935 /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
936 delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_STOP_SHARING);
937 } else {
938 /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
939 delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE);
940 this->SetWidgetDisabledState(WID_O_DELETE,
941 (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
943 /* Set the tooltip of the 'delete' button depending on whether the
944 * 'End of Orders' order or a regular order is selected. */
945 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
946 if (this->selected_order == this->vehicle->GetNumOrders()) {
947 nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
948 } else {
949 nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
953 /* First row. */
954 this->RaiseWidget(WID_O_FULL_LOAD);
955 this->RaiseWidget(WID_O_UNLOAD);
956 this->RaiseWidget(WID_O_SERVICE);
958 /* Selection widgets. */
959 /* Train or road vehicle. */
960 NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
961 NWidgetStacked *left_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
962 NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
963 NWidgetStacked *right_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
964 /* Ship or airplane. */
965 NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
966 assert(row_sel != NULL || (train_row_sel != NULL && left_sel != NULL && middle_sel != NULL && right_sel != NULL));
969 if (order == NULL) {
970 if (row_sel != NULL) {
971 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
972 } else {
973 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
974 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
975 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
976 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
977 this->DisableWidget(WID_O_NON_STOP);
978 this->RaiseWidget(WID_O_NON_STOP);
980 this->DisableWidget(WID_O_FULL_LOAD);
981 this->DisableWidget(WID_O_UNLOAD);
982 this->DisableWidget(WID_O_REFIT_DROPDOWN);
983 } else {
984 this->SetWidgetDisabledState(WID_O_FULL_LOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
985 this->SetWidgetDisabledState(WID_O_UNLOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
987 switch (order->GetType()) {
988 case OT_GOTO_STATION:
989 if (row_sel != NULL) {
990 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
991 } else {
992 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
993 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
994 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
995 right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
996 this->EnableWidget(WID_O_NON_STOP);
997 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
999 this->SetWidgetLoweredState(WID_O_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
1000 this->SetWidgetLoweredState(WID_O_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
1002 /* Can only do refitting when stopping at the destination and loading cargo.
1003 * Also enable the button if a refit is already set to allow clearing it. */
1004 this->SetWidgetDisabledState(WID_O_REFIT_DROPDOWN,
1005 order->GetLoadType() == OLFB_NO_LOAD || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ||
1006 ((!this->can_do_refit || !this->can_do_autorefit) && !order->IsRefit()));
1008 break;
1010 case OT_GOTO_WAYPOINT:
1011 if (row_sel != NULL) {
1012 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1013 } else {
1014 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1015 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1016 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1017 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1018 this->EnableWidget(WID_O_NON_STOP);
1019 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1021 this->DisableWidget(WID_O_FULL_LOAD);
1022 this->DisableWidget(WID_O_UNLOAD);
1023 this->DisableWidget(WID_O_REFIT_DROPDOWN);
1024 break;
1026 case OT_GOTO_DEPOT:
1027 if (row_sel != NULL) {
1028 row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
1029 } else {
1030 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1031 left_sel->SetDisplayedPlane(DP_LEFT_REFIT);
1032 middle_sel->SetDisplayedPlane(DP_MIDDLE_SERVICE);
1033 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1034 this->EnableWidget(WID_O_NON_STOP);
1035 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1037 /* Disable refit button if the order is no 'always go' order.
1038 * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
1039 this->SetWidgetDisabledState(WID_O_REFIT,
1040 (order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT) ||
1041 (!this->can_do_refit && !order->IsRefit()));
1042 this->SetWidgetLoweredState(WID_O_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
1043 break;
1045 case OT_CONDITIONAL: {
1046 if (row_sel != NULL) {
1047 row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
1048 } else {
1049 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_CONDITIONAL);
1051 OrderConditionVariable ocv = order->GetConditionVariable();
1052 /* Set the strings for the dropdown boxes. */
1053 this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + (order == NULL ? 0 : ocv);
1054 this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
1055 this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
1056 this->SetWidgetDisabledState(WID_O_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
1057 break;
1060 default: // every other order
1061 if (row_sel != NULL) {
1062 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1063 } else {
1064 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1065 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1066 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1067 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1068 this->DisableWidget(WID_O_NON_STOP);
1070 this->DisableWidget(WID_O_FULL_LOAD);
1071 this->DisableWidget(WID_O_UNLOAD);
1072 this->DisableWidget(WID_O_REFIT_DROPDOWN);
1073 break;
1077 /* Disable list of vehicles with the same shared orders if there is no list */
1078 this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders);
1080 this->SetDirty();
1083 virtual void OnPaint()
1085 if (this->vehicle->owner != _local_company) {
1086 this->selected_order = -1; // Disable selection any selected row at a competitor order window.
1087 } else {
1088 this->SetWidgetLoweredState(WID_O_GOTO, this->goto_type != OPOS_NONE);
1090 this->DrawWidgets();
1093 virtual void DrawWidget(const Rect &r, int widget) const
1095 if (widget != WID_O_ORDER_LIST) return;
1097 bool rtl = _current_text_dir == TD_RTL;
1098 SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
1099 int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
1100 int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
1102 int y = r.top + WD_FRAMERECT_TOP;
1103 int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
1105 int i = this->vscroll->GetPosition();
1106 const Order *order = this->vehicle->GetOrder(i);
1107 /* First draw the highlighting underground if it exists. */
1108 if (this->order_over != INVALID_VEH_ORDER_ID) {
1109 while (order != NULL) {
1110 /* Don't draw anything if it extends past the end of the window. */
1111 if (!this->vscroll->IsVisible(i)) break;
1113 if (i != this->selected_order && i == this->order_over) {
1114 /* Highlight dragged order destination. */
1115 int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
1116 int bottom = min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM);
1117 top = max(top - 3, r.top + WD_FRAMERECT_TOP);
1118 GfxFillRect(r.left + WD_FRAMETEXT_LEFT, top, r.right - WD_FRAMETEXT_RIGHT, bottom, _colour_gradient[COLOUR_GREY][7]);
1119 break;
1121 y += line_height;
1123 i++;
1124 order = order->next;
1127 /* Reset counters for drawing the orders. */
1128 y = r.top + WD_FRAMERECT_TOP;
1129 i = this->vscroll->GetPosition();
1130 order = this->vehicle->GetOrder(i);
1133 /* Draw the orders. */
1134 while (order != NULL) {
1135 /* Don't draw anything if it extends past the end of the window. */
1136 if (!this->vscroll->IsVisible(i)) break;
1138 DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
1139 y += line_height;
1141 i++;
1142 order = order->next;
1145 if (this->vscroll->IsVisible(i)) {
1146 StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
1147 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);
1151 virtual void SetStringParameters(int widget) const
1153 switch (widget) {
1154 case WID_O_COND_VALUE: {
1155 VehicleOrderID sel = this->OrderGetSel();
1156 const Order *order = this->vehicle->GetOrder(sel);
1158 if (order != NULL && order->IsType(OT_CONDITIONAL)) {
1159 uint value = order->GetConditionValue();
1160 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1161 SetDParam(0, value);
1163 break;
1166 case WID_O_CAPTION:
1167 SetDParam(0, this->vehicle->index);
1168 break;
1172 virtual void OnClick(Point pt, int widget, int click_count)
1174 switch (widget) {
1175 case WID_O_ORDER_LIST: {
1176 if (this->goto_type == OPOS_CONDITIONAL) {
1177 VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
1178 if (order_id != INVALID_VEH_ORDER_ID) {
1179 Order order;
1180 order.next = NULL;
1181 order.index = 0;
1182 order.MakeConditional(order_id);
1184 DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
1186 ResetObjectToPlace();
1187 break;
1190 VehicleOrderID sel = this->GetOrderFromPt(pt.y);
1192 if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
1193 TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
1194 if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
1195 return;
1198 /* This order won't be selected any more, close all child windows and dropdowns */
1199 this->DeleteChildWindows();
1200 HideDropDownMenu(this);
1202 if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
1203 /* Deselect clicked order */
1204 this->selected_order = -1;
1205 } else if (sel == this->selected_order) {
1206 if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
1207 DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20),
1208 MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
1209 CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1211 } else {
1212 /* Select clicked order */
1213 this->selected_order = sel;
1215 if (this->vehicle->owner == _local_company) {
1216 /* Activate drag and drop */
1217 SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1221 this->UpdateButtonState();
1222 break;
1225 case WID_O_SKIP:
1226 this->OrderClick_Skip();
1227 break;
1229 case WID_O_DELETE:
1230 this->OrderClick_Delete();
1231 break;
1233 case WID_O_STOP_SHARING:
1234 this->OrderClick_StopSharing();
1235 break;
1237 case WID_O_NON_STOP:
1238 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1239 this->OrderClick_Nonstop(-1);
1240 } else {
1241 const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1242 ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
1243 o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
1245 break;
1247 case WID_O_GOTO:
1248 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1249 if (this->goto_type != OPOS_NONE) {
1250 ResetObjectToPlace();
1251 } else {
1252 this->OrderClick_Goto(OPOS_GOTO);
1254 } else {
1255 int sel;
1256 switch (this->goto_type) {
1257 case OPOS_NONE: sel = -1; break;
1258 case OPOS_GOTO: sel = 0; break;
1259 case OPOS_CONDITIONAL: sel = 2; break;
1260 case OPOS_SHARE: sel = 3; break;
1261 default: NOT_REACHED();
1263 ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
1265 break;
1267 case WID_O_FULL_LOAD:
1268 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1269 this->OrderClick_FullLoad(-1);
1270 } else {
1271 ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
1273 break;
1275 case WID_O_UNLOAD:
1276 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1277 this->OrderClick_Unload(-1);
1278 } else {
1279 ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
1281 break;
1283 case WID_O_REFIT:
1284 this->OrderClick_Refit(0, false);
1285 break;
1287 case WID_O_SERVICE:
1288 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1289 this->OrderClick_Service(-1);
1290 } else {
1291 ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_SERVICE, 0, 0);
1293 break;
1295 case WID_O_REFIT_DROPDOWN:
1296 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1297 this->OrderClick_Refit(0, true);
1298 } else {
1299 ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
1301 break;
1303 case WID_O_TIMETABLE_VIEW:
1304 ShowTimetableWindow(this->vehicle);
1305 break;
1307 case WID_O_COND_VARIABLE: {
1308 DropDownList *list = new DropDownList();
1309 for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
1310 list->push_back(new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false));
1312 ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
1313 break;
1316 case WID_O_COND_COMPARATOR: {
1317 const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1318 ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
1319 break;
1322 case WID_O_COND_VALUE: {
1323 const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
1324 uint value = order->GetConditionValue();
1325 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1326 SetDParam(0, value);
1327 ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE);
1328 break;
1331 case WID_O_SHARED_ORDER_LIST:
1332 ShowVehicleListWindow(this->vehicle);
1333 break;
1337 virtual void OnQueryTextFinished(char *str)
1339 if (!StrEmpty(str)) {
1340 VehicleOrderID sel = this->OrderGetSel();
1341 uint value = atoi(str);
1343 switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
1344 case OCV_MAX_SPEED:
1345 value = ConvertDisplaySpeedToSpeed(value);
1346 break;
1348 case OCV_RELIABILITY:
1349 case OCV_LOAD_PERCENTAGE:
1350 value = Clamp(value, 0, 100);
1351 break;
1353 default:
1354 break;
1356 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));
1360 virtual void OnDropdownSelect(int widget, int index)
1362 switch (widget) {
1363 case WID_O_NON_STOP:
1364 this->OrderClick_Nonstop(index);
1365 break;
1367 case WID_O_FULL_LOAD:
1368 this->OrderClick_FullLoad(index);
1369 break;
1371 case WID_O_UNLOAD:
1372 this->OrderClick_Unload(index);
1373 break;
1375 case WID_O_GOTO:
1376 switch (index) {
1377 case 0: this->OrderClick_Goto(OPOS_GOTO); break;
1378 case 1: this->OrderClick_NearestDepot(); break;
1379 case 2: this->OrderClick_Goto(OPOS_CONDITIONAL); break;
1380 case 3: this->OrderClick_Goto(OPOS_SHARE); break;
1381 default: NOT_REACHED();
1383 break;
1385 case WID_O_SERVICE:
1386 this->OrderClick_Service(index);
1387 break;
1389 case WID_O_REFIT_DROPDOWN:
1390 this->OrderClick_Refit(index, true);
1391 break;
1393 case WID_O_COND_VARIABLE:
1394 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));
1395 break;
1397 case WID_O_COND_COMPARATOR:
1398 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));
1399 break;
1403 virtual void OnDragDrop(Point pt, int widget)
1405 switch (widget) {
1406 case WID_O_ORDER_LIST: {
1407 VehicleOrderID from_order = this->OrderGetSel();
1408 VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1410 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()) &&
1411 DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
1412 this->selected_order = -1;
1413 this->UpdateButtonState();
1415 break;
1418 case WID_O_DELETE:
1419 this->OrderClick_Delete();
1420 break;
1422 case WID_O_STOP_SHARING:
1423 this->OrderClick_StopSharing();
1424 break;
1427 ResetObjectToPlace();
1429 if (this->order_over != INVALID_VEH_ORDER_ID) {
1430 /* End of drag-and-drop, hide dragged order destination highlight. */
1431 this->order_over = INVALID_VEH_ORDER_ID;
1432 this->SetWidgetDirty(WID_O_ORDER_LIST);
1436 virtual EventState OnHotkey(int hotkey)
1438 if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
1440 switch (hotkey) {
1441 case OHK_SKIP: this->OrderClick_Skip(); break;
1442 case OHK_DELETE: this->OrderClick_Delete(); break;
1443 case OHK_GOTO: this->OrderClick_Goto(OPOS_GOTO); break;
1444 case OHK_NONSTOP: this->OrderClick_Nonstop(-1); break;
1445 case OHK_FULLLOAD: this->OrderClick_FullLoad(-1); break;
1446 case OHK_UNLOAD: this->OrderClick_Unload(-1); break;
1447 case OHK_NEAREST_DEPOT: this->OrderClick_NearestDepot(); break;
1448 case OHK_ALWAYS_SERVICE: this->OrderClick_Service(-1); break;
1449 case OHK_TRANSFER: this->OrderHotkey_Transfer(); break;
1450 case OHK_NO_UNLOAD: this->OrderHotkey_NoUnload(); break;
1451 case OHK_NO_LOAD: this->OrderHotkey_NoLoad(); break;
1452 default: return ES_NOT_HANDLED;
1454 return ES_HANDLED;
1457 virtual void OnPlaceObject(Point pt, TileIndex tile)
1459 if (this->goto_type == OPOS_GOTO) {
1460 const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
1461 if (cmd.IsType(OT_NOTHING)) return;
1463 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))) {
1464 /* With quick goto the Go To button stays active */
1465 if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
1470 virtual bool OnVehicleSelect(const Vehicle *v)
1472 /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
1473 * We disallow copying orders of other vehicles if we already have at least one order entry
1474 * ourself as it easily copies orders of vehicles within a station when we mean the station.
1475 * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
1476 * TODO: give a warning message */
1477 bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
1478 if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
1480 if (DoCommandP(this->vehicle->tile, this->vehicle->index | (share_order ? CO_SHARE : CO_COPY) << 30, v->index,
1481 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))) {
1482 this->selected_order = -1;
1483 ResetObjectToPlace();
1485 return true;
1488 virtual void OnPlaceObjectAbort()
1490 this->goto_type = OPOS_NONE;
1491 this->SetWidgetDirty(WID_O_GOTO);
1493 /* Remove drag highlighting if it exists. */
1494 if (this->order_over != INVALID_VEH_ORDER_ID) {
1495 this->order_over = INVALID_VEH_ORDER_ID;
1496 this->SetWidgetDirty(WID_O_ORDER_LIST);
1500 virtual void OnMouseDrag(Point pt, int widget)
1502 if (this->selected_order != -1 && widget == WID_O_ORDER_LIST) {
1503 /* An order is dragged.. */
1504 VehicleOrderID from_order = this->OrderGetSel();
1505 VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1506 uint num_orders = this->vehicle->GetNumOrders();
1508 if (from_order != INVALID_VEH_ORDER_ID && from_order <= num_orders) {
1509 if (to_order != INVALID_VEH_ORDER_ID && to_order <= num_orders) { // ..over an existing order.
1510 this->order_over = to_order;
1511 this->SetWidgetDirty(widget);
1512 } else if (from_order != to_order && this->order_over != INVALID_VEH_ORDER_ID) { // ..outside of the order list.
1513 this->order_over = INVALID_VEH_ORDER_ID;
1514 this->SetWidgetDirty(widget);
1520 virtual void OnResize()
1522 /* Update the scroll bar */
1523 this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
1526 static HotkeyList hotkeys;
1529 static Hotkey order_hotkeys[] = {
1530 Hotkey('D', "skip", OHK_SKIP),
1531 Hotkey('F', "delete", OHK_DELETE),
1532 Hotkey('G', "goto", OHK_GOTO),
1533 Hotkey('H', "nonstop", OHK_NONSTOP),
1534 Hotkey('J', "fullload", OHK_FULLLOAD),
1535 Hotkey('K', "unload", OHK_UNLOAD),
1536 Hotkey((uint16)0, "nearest_depot", OHK_NEAREST_DEPOT),
1537 Hotkey((uint16)0, "always_service", OHK_ALWAYS_SERVICE),
1538 Hotkey((uint16)0, "transfer", OHK_TRANSFER),
1539 Hotkey((uint16)0, "no_unload", OHK_NO_UNLOAD),
1540 Hotkey((uint16)0, "no_load", OHK_NO_LOAD),
1541 HOTKEY_LIST_END
1543 HotkeyList OrdersWindow::hotkeys("order", order_hotkeys);
1545 /** Nested widget definition for "your" train orders. */
1546 static const NWidgetPart _nested_orders_train_widgets[] = {
1547 NWidget(NWID_HORIZONTAL),
1548 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1549 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1550 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1551 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1552 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1553 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1554 EndContainer(),
1555 NWidget(NWID_HORIZONTAL),
1556 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(),
1557 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1558 EndContainer(),
1560 /* First button row. */
1561 NWidget(NWID_HORIZONTAL),
1562 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW_GROUNDVEHICLE),
1563 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1564 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_NON_STOP), SetMinimalSize(93, 12), SetFill(1, 0),
1565 SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
1566 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_LEFT),
1567 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1568 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1569 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(93, 12), SetFill(1, 0),
1570 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1571 EndContainer(),
1572 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_MIDDLE),
1573 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1574 SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1575 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(93, 12), SetFill(1, 0),
1576 SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1577 EndContainer(),
1578 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_RIGHT),
1579 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_O_EMPTY), SetMinimalSize(93, 12), SetFill(1, 0),
1580 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1581 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(93, 12), SetFill(1, 0),
1582 SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1583 EndContainer(),
1584 EndContainer(),
1585 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1586 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1587 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1588 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1589 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1590 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1591 SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1592 EndContainer(),
1593 EndContainer(),
1594 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),
1595 EndContainer(),
1597 /* Second button row. */
1598 NWidget(NWID_HORIZONTAL),
1599 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1600 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1601 SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1602 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
1603 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1604 SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1605 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1606 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1607 EndContainer(),
1608 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1609 SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1610 EndContainer(),
1611 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1612 EndContainer(),
1615 static WindowDesc _orders_train_desc(
1616 WDP_AUTO, "view_vehicle_orders_train", 384, 100,
1617 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
1618 WDF_CONSTRUCTION,
1619 _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets),
1620 &OrdersWindow::hotkeys
1623 /** Nested widget definition for "your" orders (non-train). */
1624 static const NWidgetPart _nested_orders_widgets[] = {
1625 NWidget(NWID_HORIZONTAL),
1626 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1627 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1628 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1629 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1630 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1631 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1632 EndContainer(),
1633 NWidget(NWID_HORIZONTAL),
1634 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(),
1635 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1636 EndContainer(),
1638 /* First button row. */
1639 NWidget(NWID_HORIZONTAL),
1640 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW),
1641 /* Load + unload + refit buttons. */
1642 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1643 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1644 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1645 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1646 SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1647 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(124, 12), SetFill(1, 0),
1648 SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1649 EndContainer(),
1650 /* Refit + service buttons. */
1651 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1652 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
1653 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1654 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
1655 SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1656 EndContainer(),
1658 /* Buttons for setting a condition. */
1659 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1660 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1661 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1662 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1663 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1664 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1665 SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1666 EndContainer(),
1667 EndContainer(),
1669 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),
1670 EndContainer(),
1672 /* Second button row. */
1673 NWidget(NWID_HORIZONTAL),
1674 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1675 SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1676 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
1677 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1678 SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1679 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1680 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1681 EndContainer(),
1682 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1683 SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1684 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1685 EndContainer(),
1688 static WindowDesc _orders_desc(
1689 WDP_AUTO, "view_vehicle_orders", 384, 100,
1690 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
1691 WDF_CONSTRUCTION,
1692 _nested_orders_widgets, lengthof(_nested_orders_widgets),
1693 &OrdersWindow::hotkeys
1696 /** Nested widget definition for competitor orders. */
1697 static const NWidgetPart _nested_other_orders_widgets[] = {
1698 NWidget(NWID_HORIZONTAL),
1699 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1700 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1701 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1702 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1703 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1704 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1705 EndContainer(),
1706 NWidget(NWID_HORIZONTAL),
1707 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(),
1708 NWidget(NWID_VERTICAL),
1709 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1710 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1711 EndContainer(),
1712 EndContainer(),
1715 static WindowDesc _other_orders_desc(
1716 WDP_AUTO, "view_vehicle_orders_competitor", 384, 86,
1717 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
1718 WDF_CONSTRUCTION,
1719 _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets),
1720 &OrdersWindow::hotkeys
1723 void ShowOrdersWindow(const Vehicle *v)
1725 DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
1726 DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
1727 if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
1729 if (v->owner != _local_company) {
1730 new OrdersWindow(&_other_orders_desc, v);
1731 } else {
1732 new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);