OpenTTD Source: src/order_gui.cpp Source File

OpenTTD Source 14.0-RC3

order_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "command_func.h"
12 #include "viewport_func.h"
13 #include "depot_map.h"
14 #include "roadveh.h"
15 #include "timetable.h"
16 #include "strings_func.h"
17 #include "company_func.h"
18 #include "widgets/dropdown_type.h"
19 #include "widgets/dropdown_func.h"
20 #include "textbuf_gui.h"
21 #include "string_func.h"
22 #include "tilehighlight_func.h"
23 #include "network/network.h"
24 #include "station_base.h"
25 #include "industry.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"
31 #include "vehicle_func.h"
32 #include "vehiclelist.h"
33 #include "vehicle_func.h"
34 #include "error.h"
35 #include "order_cmd.h"
36 #include "company_cmd.h"
37
38 #include "widgets/order_widget.h"
39
40 #include "safeguards.h"
41
42
44 static const StringID _station_load_types[][5][5] = {
45 {
46 /* No refitting. */
47 {
48 STR_EMPTY,
49 INVALID_STRING_ID,
50 STR_ORDER_FULL_LOAD,
51 STR_ORDER_FULL_LOAD_ANY,
52 STR_ORDER_NO_LOAD,
53 }, {
54 STR_ORDER_UNLOAD,
55 INVALID_STRING_ID,
56 STR_ORDER_UNLOAD_FULL_LOAD,
57 STR_ORDER_UNLOAD_FULL_LOAD_ANY,
58 STR_ORDER_UNLOAD_NO_LOAD,
59 }, {
60 STR_ORDER_TRANSFER,
61 INVALID_STRING_ID,
62 STR_ORDER_TRANSFER_FULL_LOAD,
63 STR_ORDER_TRANSFER_FULL_LOAD_ANY,
64 STR_ORDER_TRANSFER_NO_LOAD,
65 }, {
66 /* Unload and transfer do not work together. */
67 INVALID_STRING_ID,
68 INVALID_STRING_ID,
69 INVALID_STRING_ID,
70 INVALID_STRING_ID,
71 }, {
72 STR_ORDER_NO_UNLOAD,
73 INVALID_STRING_ID,
74 STR_ORDER_NO_UNLOAD_FULL_LOAD,
75 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
76 STR_ORDER_NO_UNLOAD_NO_LOAD,
77 }
78 }, {
79 /* With auto-refitting. No loading and auto-refitting do not work together. */
80 {
81 STR_ORDER_AUTO_REFIT,
82 INVALID_STRING_ID,
83 STR_ORDER_FULL_LOAD_REFIT,
84 STR_ORDER_FULL_LOAD_ANY_REFIT,
85 INVALID_STRING_ID,
86 }, {
87 STR_ORDER_UNLOAD_REFIT,
88 INVALID_STRING_ID,
89 STR_ORDER_UNLOAD_FULL_LOAD_REFIT,
90 STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT,
91 INVALID_STRING_ID,
92 }, {
93 STR_ORDER_TRANSFER_REFIT,
94 INVALID_STRING_ID,
95 STR_ORDER_TRANSFER_FULL_LOAD_REFIT,
96 STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT,
97 INVALID_STRING_ID,
98 }, {
99 /* Unload and transfer do not work together. */
100 INVALID_STRING_ID,
101 INVALID_STRING_ID,
102 INVALID_STRING_ID,
103 INVALID_STRING_ID,
104 }, {
105 STR_ORDER_NO_UNLOAD_REFIT,
106 INVALID_STRING_ID,
107 STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT,
108 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT,
109 INVALID_STRING_ID,
110 }
111 }
112 };
113
114 static const StringID _order_non_stop_drowdown[] = {
115 STR_ORDER_GO_TO,
116 STR_ORDER_GO_NON_STOP_TO,
117 STR_ORDER_GO_VIA,
118 STR_ORDER_GO_NON_STOP_VIA,
119 INVALID_STRING_ID
120 };
121
122 static const StringID _order_full_load_drowdown[] = {
123 STR_ORDER_DROP_LOAD_IF_POSSIBLE,
124 STR_EMPTY,
125 STR_ORDER_DROP_FULL_LOAD_ALL,
126 STR_ORDER_DROP_FULL_LOAD_ANY,
127 STR_ORDER_DROP_NO_LOADING,
128 INVALID_STRING_ID
129 };
130
131 static const StringID _order_unload_drowdown[] = {
132 STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
133 STR_ORDER_DROP_UNLOAD,
134 STR_ORDER_DROP_TRANSFER,
135 STR_EMPTY,
136 STR_ORDER_DROP_NO_UNLOADING,
137 INVALID_STRING_ID
138 };
139
140 static const StringID _order_goto_dropdown[] = {
141 STR_ORDER_GO_TO,
142 STR_ORDER_GO_TO_NEAREST_DEPOT,
143 STR_ORDER_CONDITIONAL,
144 STR_ORDER_SHARE,
145 INVALID_STRING_ID
146 };
147
148 static const StringID _order_goto_dropdown_aircraft[] = {
149 STR_ORDER_GO_TO,
150 STR_ORDER_GO_TO_NEAREST_HANGAR,
151 STR_ORDER_CONDITIONAL,
152 STR_ORDER_SHARE,
153 INVALID_STRING_ID
154 };
155
157 static const OrderConditionVariable _order_conditional_variable[] = {
158 OCV_LOAD_PERCENTAGE,
159 OCV_RELIABILITY,
160 OCV_MAX_RELIABILITY,
161 OCV_MAX_SPEED,
162 OCV_AGE,
163 OCV_REMAINING_LIFETIME,
164 OCV_REQUIRES_SERVICE,
165 OCV_UNCONDITIONALLY,
166 };
167
168 static const StringID _order_conditional_condition[] = {
169 STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
170 STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
171 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
172 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
173 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
174 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
175 STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
176 STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
177 INVALID_STRING_ID,
178 };
179
180 extern uint ConvertSpeedToDisplaySpeed(uint speed, VehicleType type);
181 extern uint ConvertDisplaySpeedToSpeed(uint speed, VehicleType type);
182
183 static const StringID _order_depot_action_dropdown[] = {
184 STR_ORDER_DROP_GO_ALWAYS_DEPOT,
185 STR_ORDER_DROP_SERVICE_DEPOT,
186 STR_ORDER_DROP_HALT_DEPOT,
187 STR_ORDER_DROP_UNBUNCH,
188 INVALID_STRING_ID
189 };
190
191 static int DepotActionStringIndex(const Order *order)
192 {
193 if (order->GetDepotActionType() & ODATFB_HALT) {
194 return DA_STOP;
195 } else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
196 return DA_SERVICE;
197 } else if (order->GetDepotActionType() & ODATFB_UNBUNCH) {
198 return DA_UNBUNCH;
199 } else {
200 return DA_ALWAYS_GO;
201 }
202 }
203
204 static const StringID _order_refit_action_dropdown[] = {
205 STR_ORDER_DROP_REFIT_AUTO,
206 STR_ORDER_DROP_REFIT_AUTO_ANY,
207 INVALID_STRING_ID
208 };
209
222 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
223 {
224 bool rtl = _current_text_dir == TD_RTL;
225
226 SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT;
227 Dimension sprite_size = GetSpriteSize(sprite);
228 if (v->cur_real_order_index == order_index) {
229 /* Draw two arrows before the next real order. */
230 DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)GetCharacterHeight(FS_NORMAL) - (int)sprite_size.height) / 2);
231 DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)GetCharacterHeight(FS_NORMAL) - (int)sprite_size.height) / 2);
232 } else if (v->cur_implicit_order_index == order_index) {
233 /* Draw one arrow before the next implicit order; the next real order will still get two arrows. */
234 DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)GetCharacterHeight(FS_NORMAL) - (int)sprite_size.height) / 2);
235 }
236
237 TextColour colour = TC_BLACK;
238 if (order->IsType(OT_IMPLICIT)) {
239 colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
240 } else if (selected) {
241 colour = TC_WHITE;
242 }
243
244 SetDParam(0, order_index + 1);
245 DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, STR_ORDER_INDEX, colour, SA_RIGHT | SA_FORCE);
246
247 SetDParam(5, STR_EMPTY);
248 SetDParam(8, STR_EMPTY);
249 SetDParam(9, STR_EMPTY);
250
251 /* Check range for aircraft. */
252 if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
253 const Order *next = order->next != nullptr ? order->next : v->GetFirstOrder();
254 if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) SetDParam(9, STR_ORDER_OUT_OF_RANGE);
255 }
256
257 switch (order->GetType()) {
258 case OT_DUMMY:
259 SetDParam(0, STR_INVALID_ORDER);
260 SetDParam(1, order->GetDestination());
261 break;
262
263 case OT_IMPLICIT:
264 SetDParam(0, STR_ORDER_GO_TO_STATION);
265 SetDParam(1, STR_ORDER_GO_TO);
266 SetDParam(2, order->GetDestination());
267 SetDParam(3, timetable ? STR_EMPTY : STR_ORDER_IMPLICIT);
268 break;
269
270 case OT_GOTO_STATION: {
271 OrderLoadFlags load = order->GetLoadType();
272 OrderUnloadFlags unload = order->GetUnloadType();
273 bool valid_station = CanVehicleUseStation(v, Station::Get(order->GetDestination()));
274
275 SetDParam(0, valid_station ? STR_ORDER_GO_TO_STATION : STR_ORDER_GO_TO_STATION_CAN_T_USE_STATION);
276 SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
277 SetDParam(2, order->GetDestination());
278
279 if (timetable) {
280 /* Show only wait time in the timetable window. */
281 SetDParam(3, STR_EMPTY);
282
283 if (order->GetWaitTime() > 0) {
284 SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR : STR_TIMETABLE_STAY_FOR_ESTIMATED);
285 SetTimetableParams(6, 7, order->GetWaitTime());
286 }
287 } else {
288 /* Show non-stop, refit and stop location only in the order window. */
289 SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]);
290 if (order->IsRefit()) {
291 SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
292 }
293 if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
294 /* Only show the stopping location if other than the default chosen by the player. */
295 if (order->GetStopLocation() != (OrderStopLocation)(_settings_client.gui.stop_location)) {
296 SetDParam(5, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
297 } else {
298 SetDParam(5, STR_EMPTY);
299 }
300 }
301 }
302 break;
303 }
304
305 case OT_GOTO_DEPOT:
306 if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
307 /* Going to the nearest depot. */
308 SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
309 if (v->type == VEH_AIRCRAFT) {
310 SetDParam(2, STR_ORDER_NEAREST_HANGAR);
311 SetDParam(3, STR_EMPTY);
312 } else {
313 SetDParam(2, STR_ORDER_NEAREST_DEPOT);
314 SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type);
315 }
316 } else {
317 /* Going to a specific depot. */
318 SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT);
319 SetDParam(2, v->type);
320 SetDParam(3, order->GetDestination());
321 }
322
323 if (order->GetDepotOrderType() & ODTFB_SERVICE) {
324 SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
325 } else {
326 SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
327 }
328
329 /* Do not show stopping in the depot in the timetable window. */
330 if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
331 SetDParam(5, STR_ORDER_STOP_ORDER);
332 }
333
334 /* Do not show refitting in the depot in the timetable window. */
335 if (!timetable && order->IsRefit()) {
336 SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER);
337 SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name);
338 }
339
340 /* Show unbunching depot in both order and timetable windows. */
341 if (order->GetDepotActionType() & ODATFB_UNBUNCH) {
342 SetDParam(8, STR_ORDER_WAIT_TO_UNBUNCH);
343 }
344
345 break;
346
347 case OT_GOTO_WAYPOINT:
348 SetDParam(0, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT);
349 SetDParam(1, order->GetDestination());
350 break;
351
352 case OT_CONDITIONAL:
353 SetDParam(1, order->GetConditionSkipToOrder() + 1);
354 if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
355 SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
356 } else {
357 OrderConditionComparator occ = order->GetConditionComparator();
358 SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM);
359 SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
360 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
361
362 uint value = order->GetConditionValue();
363 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value, v->type);
364 SetDParam(4, value);
365 }
366
367 if (timetable && order->GetWaitTime() > 0) {
368 SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_AND_TRAVEL_FOR : STR_TIMETABLE_AND_TRAVEL_FOR_ESTIMATED);
369 SetTimetableParams(6, 7, order->GetWaitTime());
370 } else {
371 SetDParam(5, STR_EMPTY);
372 }
373 break;
374
375 default: NOT_REACHED();
376 }
377
378 DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
379 }
380
387 static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
388 {
389 /* Hack-ish; unpack order 0, so everything gets initialised with either zero
390 * or a suitable default value for the variable. Then also override the index
391 * as it is not coming from a pool, so would be initialised. */
392 Order order(0);
393 order.index = 0;
394
395 /* check depot first */
396 if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) {
397 order.MakeGoToDepot(v->type == VEH_AIRCRAFT ? GetStationIndex(tile) : GetDepotIndex(tile),
398 ODTFB_PART_OF_ORDERS,
399 (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
400
401 if (_ctrl_pressed) {
402 /* Check to see if we are allowed to make this an unbunching order. */
403 bool failed = false;
404 if (v->HasFullLoadOrder()) {
405 /* We don't allow unbunching if the vehicle has a full load order. */
406 ShowErrorMessage(STR_ERROR_CAN_T_INSERT_NEW_ORDER, STR_ERROR_UNBUNCHING_NO_UNBUNCHING_FULL_LOAD, WL_INFO);
407 failed = true;
408 } else if (v->HasUnbunchingOrder()) {
409 /* Don't allow a new unbunching order if we already have one. */
410 ShowErrorMessage(STR_ERROR_CAN_T_INSERT_NEW_ORDER, STR_ERROR_UNBUNCHING_ONLY_ONE_ALLOWED, WL_INFO);
411 failed = true;
412 } else if (v->HasConditionalOrder()) {
413 /* We don't allow unbunching if the vehicle has a conditional order. */
414 ShowErrorMessage(STR_ERROR_CAN_T_INSERT_NEW_ORDER, STR_ERROR_UNBUNCHING_NO_UNBUNCHING_CONDITIONAL, WL_INFO);
415 failed = true;
416 }
417
418 /* Return an empty order to bail out. */
419 if (failed) {
420 order.Free();
421 return order;
422 }
423
424 /* Now we are allowed to set the action type. */
425 order.SetDepotActionType(ODATFB_UNBUNCH);
426 }
427
428 return order;
429 }
430
431 /* check rail waypoint */
432 if (IsRailWaypointTile(tile) &&
433 v->type == VEH_TRAIN &&
434 IsTileOwner(tile, _local_company)) {
435 order.MakeGoToWaypoint(GetStationIndex(tile));
436 if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
437 return order;
438 }
439
440 /* check buoy (no ownership) */
441 if (IsBuoyTile(tile) && v->type == VEH_SHIP) {
442 order.MakeGoToWaypoint(GetStationIndex(tile));
443 return order;
444 }
445
446 /* check for station or industry with neutral station */
447 if (IsTileType(tile, MP_STATION) || IsTileType(tile, MP_INDUSTRY)) {
448 const Station *st = nullptr;
449
450 if (IsTileType(tile, MP_STATION)) {
451 st = Station::GetByTile(tile);
452 } else {
453 const Industry *in = Industry::GetByTile(tile);
454 st = in->neutral_station;
455 }
456 if (st != nullptr && (st->owner == _local_company || st->owner == OWNER_NONE)) {
457 byte facil;
458 switch (v->type) {
459 case VEH_SHIP: facil = FACIL_DOCK; break;
460 case VEH_TRAIN: facil = FACIL_TRAIN; break;
461 case VEH_AIRCRAFT: facil = FACIL_AIRPORT; break;
462 case VEH_ROAD: facil = FACIL_BUS_STOP | FACIL_TRUCK_STOP; break;
463 default: NOT_REACHED();
464 }
465 if (st->facilities & facil) {
466 order.MakeGoToStation(st->index);
467 if (_ctrl_pressed) order.SetLoadType(OLF_FULL_LOAD_ANY);
468 if (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
469 order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OSL_PLATFORM_FAR_END);
470 return order;
471 }
472 }
473 }
474
475 /* not found */
476 order.Free();
477 return order;
478 }
479
481 enum {
482 OHK_SKIP,
483 OHK_DELETE,
484 OHK_GOTO,
485 OHK_NONSTOP,
486 OHK_FULLLOAD,
487 OHK_UNLOAD,
488 OHK_NEAREST_DEPOT,
489 OHK_ALWAYS_SERVICE,
490 OHK_TRANSFER,
491 OHK_NO_UNLOAD,
492 OHK_NO_LOAD,
493 };
494
535 struct OrdersWindow : public Window {
536 private:
538 enum OrderPlaceObjectState {
539 OPOS_NONE,
540 OPOS_GOTO,
541 OPOS_CONDITIONAL,
542 OPOS_SHARE,
543 OPOS_END,
544 };
545
547 enum DisplayPane {
548 /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
549 DP_GROUNDVEHICLE_ROW_NORMAL = 0,
550 DP_GROUNDVEHICLE_ROW_CONDITIONAL = 1,
551
552 /* WID_O_SEL_TOP_LEFT */
553 DP_LEFT_LOAD = 0,
554 DP_LEFT_REFIT = 1,
555
556 /* WID_O_SEL_TOP_MIDDLE */
557 DP_MIDDLE_UNLOAD = 0,
558 DP_MIDDLE_SERVICE = 1,
559
560 /* WID_O_SEL_TOP_RIGHT */
561 DP_RIGHT_EMPTY = 0,
562 DP_RIGHT_REFIT = 1,
563
564 /* WID_O_SEL_TOP_ROW */
565 DP_ROW_LOAD = 0,
566 DP_ROW_DEPOT = 1,
567 DP_ROW_CONDITIONAL = 2,
568
569 /* WID_O_SEL_BOTTOM_MIDDLE */
570 DP_BOTTOM_MIDDLE_DELETE = 0,
571 DP_BOTTOM_MIDDLE_STOP_SHARING = 1,
572 };
573
574 int selected_order;
575 VehicleOrderID order_over;
576 OrderPlaceObjectState goto_type;
577 const Vehicle *vehicle;
578 Scrollbar *vscroll;
579 bool can_do_refit;
580 bool can_do_autorefit;
581
587 VehicleOrderID OrderGetSel() const
588 {
589 int num = this->selected_order;
590 return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
591 }
592
601 VehicleOrderID GetOrderFromPt(int y)
602 {
603 int sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_O_ORDER_LIST, WidgetDimensions::scaled.framerect.top);
604 if (sel == INT_MAX) return INVALID_VEH_ORDER_ID;
605 /* One past the orders is the 'End of Orders' line. */
606 assert(IsInsideBS(sel, 0, vehicle->GetNumOrders() + 1));
607 return sel;
608 }
609
613 void OrderClick_Goto(OrderPlaceObjectState type)
614 {
615 assert(type > OPOS_NONE && type < OPOS_END);
616
617 static const HighLightStyle goto_place_style[OPOS_END - 1] = {
618 HT_RECT | HT_VEHICLE, // OPOS_GOTO
619 HT_NONE, // OPOS_CONDITIONAL
620 HT_VEHICLE, // OPOS_SHARE
621 };
622 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, goto_place_style[type - 1], this);
623 this->goto_type = type;
624 this->SetWidgetDirty(WID_O_GOTO);
625 }
626
632 void OrderClick_FullLoad(OrderLoadFlags load_type, bool toggle = false)
633 {
634 VehicleOrderID sel_ord = this->OrderGetSel();
635 const Order *order = this->vehicle->GetOrder(sel_ord);
636
637 if (order == nullptr) return;
638
639 if (toggle && order->GetLoadType() == load_type) {
640 load_type = OLF_LOAD_IF_POSSIBLE; // reset to 'default'
641 }
642 if (order->GetLoadType() == load_type) return; // If we still match, do nothing
643
644 Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_LOAD, load_type);
645 }
646
650 void OrderClick_Service(int i)
651 {
652 VehicleOrderID sel_ord = this->OrderGetSel();
653
654 if (i < 0) {
655 const Order *order = this->vehicle->GetOrder(sel_ord);
656 if (order == nullptr) return;
657 i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
658 }
659 Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_DEPOT_ACTION, i);
660 }
661
665 void OrderClick_NearestDepot()
666 {
667 Order order;
668 order.next = nullptr;
669 order.index = 0;
670 order.MakeGoToDepot(INVALID_DEPOT, ODTFB_PART_OF_ORDERS,
671 _settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
672 order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
673
674 Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order);
675 }
676
682 void OrderClick_Unload(OrderUnloadFlags unload_type, bool toggle = false)
683 {
684 VehicleOrderID sel_ord = this->OrderGetSel();
685 const Order *order = this->vehicle->GetOrder(sel_ord);
686
687 if (order == nullptr) return;
688
689 if (toggle && order->GetUnloadType() == unload_type) {
690 unload_type = OUF_UNLOAD_IF_POSSIBLE;
691 }
692 if (order->GetUnloadType() == unload_type) return; // If we still match, do nothing
693
694 Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_UNLOAD, unload_type);
695
696 /* Transfer and unload orders with leave empty as default */
697 if (unload_type == OUFB_TRANSFER || unload_type == OUFB_UNLOAD) {
698 Command<CMD_MODIFY_ORDER>::Post(this->vehicle->tile, this->vehicle->index, sel_ord, MOF_LOAD, OLFB_NO_LOAD);
699 this->SetWidgetDirty(WID_O_FULL_LOAD);
700 }
701 }
702
707 void OrderClick_Nonstop(int non_stop)
708 {
709 if (!this->vehicle->IsGroundVehicle()) return;
710
711 VehicleOrderID sel_ord = this->OrderGetSel();
712 const Order *order = this->vehicle->GetOrder(sel_ord);
713
714 if (order == nullptr || order->GetNonStopType() == non_stop) return;
715
716 /* Keypress if negative, so 'toggle' to the next */
717 if (non_stop < 0) {
718 non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
719 }
720
721 this->SetWidgetDirty(WID_O_NON_STOP);
722 Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_NON_STOP, non_stop);
723 }
724
729 void OrderClick_Skip()
730 {
731 /* Don't skip when there's nothing to skip */
732 if (_ctrl_pressed && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
733 if (this->vehicle->GetNumOrders() <= 1) return;
734
735 Command<CMD_SKIP_TO_ORDER>::Post(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER,
736 this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()));
737 }
738
742 void OrderClick_Delete()
743 {
744 /* When networking, move one order lower */
745 int selected = this->selected_order + (int)_networking;
746
747 if (Command<CMD_DELETE_ORDER>::Post(STR_ERROR_CAN_T_DELETE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel())) {
748 this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
749 this->UpdateButtonState();
750 }
751 }
752
759 void OrderClick_StopSharing()
760 {
761 /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
762 if (!this->vehicle->IsOrderListShared() || this->selected_order != this->vehicle->GetNumOrders()) return;
763 /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
764 if (_ctrl_pressed) {
765 this->OrderClick_Delete();
766 return;
767 }
768
769 /* Get another vehicle that share orders with this vehicle. */
770 Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
771 /* Copy the order list of the other vehicle. */
772 if (Command<CMD_CLONE_ORDER>::Post(STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST, this->vehicle->tile, CO_COPY, this->vehicle->index, other_shared->index)) {
773 this->UpdateButtonState();
774 }
775 }
776
783 void OrderClick_Refit(int i, bool auto_refit)
784 {
785 if (_ctrl_pressed) {
786 /* Cancel refitting */
787 Command<CMD_ORDER_REFIT>::Post(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CARGO_NO_REFIT);
788 } else {
789 if (i == 1) { // Auto-refit to available cargo type.
790 Command<CMD_ORDER_REFIT>::Post(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CARGO_AUTO_REFIT);
791 } else {
792 ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
793 }
794 }
795 }
796
798 void UpdateAutoRefitState()
799 {
800 this->can_do_refit = false;
801 this->can_do_autorefit = false;
802 for (const Vehicle *w = this->vehicle; w != nullptr; w = w->IsGroundVehicle() ? w->Next() : nullptr) {
803 if (IsEngineRefittable(w->engine_type)) this->can_do_refit = true;
804 if (HasBit(Engine::Get(w->engine_type)->info.misc_flags, EF_AUTO_REFIT)) this->can_do_autorefit = true;
805 }
806 }
807
808 public:
809 OrdersWindow(WindowDesc *desc, const Vehicle *v) : Window(desc)
810 {
811 this->vehicle = v;
812
813 this->CreateNestedTree();
814 this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
815 if (NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_O_DEPOT_ACTION); nwid != nullptr) {
816 nwid->tool_tip = STR_ORDER_TRAIN_DEPOT_ACTION_TOOLTIP + v->type;
817 }
818 this->FinishInitNested(v->index);
819
820 this->selected_order = -1;
821 this->order_over = INVALID_VEH_ORDER_ID;
822 this->goto_type = OPOS_NONE;
823 this->owner = v->owner;
824
825 this->UpdateAutoRefitState();
826
827 if (_settings_client.gui.quick_goto && v->owner == _local_company) {
828 /* If there are less than 2 station, make Go To active. */
829 int station_orders = 0;
830 for (const Order *order : v->Orders()) {
831 if (order->IsType(OT_GOTO_STATION)) station_orders++;
832 }
833
834 if (station_orders < 2) this->OrderClick_Goto(OPOS_GOTO);
835 }
836 this->OnInvalidateData(VIWD_MODIFY_ORDERS);
837 }
838
839 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
840 {
841 switch (widget) {
842 case WID_O_ORDER_LIST:
843 resize->height = GetCharacterHeight(FS_NORMAL);
844 size->height = 6 * resize->height + padding.height;
845 break;
846
847 case WID_O_COND_VARIABLE: {
848 Dimension d = {0, 0};
849 for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
850 d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i]));
851 }
852 d.width += padding.width;
853 d.height += padding.height;
854 *size = maxdim(*size, d);
855 break;
856 }
857
858 case WID_O_COND_COMPARATOR: {
859 Dimension d = {0, 0};
860 for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
861 d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
862 }
863 d.width += padding.width;
864 d.height += padding.height;
865 *size = maxdim(*size, d);
866 break;
867 }
868 }
869 }
870
876 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
877 {
878 VehicleOrderID from = INVALID_VEH_ORDER_ID;
879 VehicleOrderID to = INVALID_VEH_ORDER_ID;
880
881 switch (data) {
882 case VIWD_AUTOREPLACE:
883 /* Autoreplace replaced the vehicle */
884 this->vehicle = Vehicle::Get(this->window_number);
885 [[fallthrough]];
886
887 case VIWD_CONSIST_CHANGED:
888 /* Vehicle composition was changed. */
889 this->UpdateAutoRefitState();
890 break;
891
892 case VIWD_REMOVE_ALL_ORDERS:
893 /* Removed / replaced all orders (after deleting / sharing) */
894 if (this->selected_order == -1) break;
895
896 this->CloseChildWindows();
897 this->selected_order = -1;
898 break;
899
900 case VIWD_MODIFY_ORDERS:
901 /* Some other order changes */
902 break;
903
904 default:
905 if (data < 0) break;
906
907 if (gui_scope) break; // only do this once; from command scope
908 from = GB(data, 0, 8);
909 to = GB(data, 8, 8);
910 /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
911 * the order is being created / removed */
912 if (this->selected_order == -1) break;
913
914 if (from == to) break; // no need to change anything
915
916 if (from != this->selected_order) {
917 /* Moving from preceding order? */
918 this->selected_order -= (int)(from <= this->selected_order);
919 /* Moving to preceding order? */
920 this->selected_order += (int)(to <= this->selected_order);
921 break;
922 }
923
924 /* Now we are modifying the selected order */
925 if (to == INVALID_VEH_ORDER_ID) {
926 /* Deleting selected order */
927 this->CloseChildWindows();
928 this->selected_order = -1;
929 break;
930 }
931
932 /* Moving selected order */
933 this->selected_order = to;
934 break;
935 }
936
937 this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
938 if (gui_scope) this->UpdateButtonState();
939
940 /* Scroll to the new order. */
941 if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {
942 this->vscroll->ScrollTowards(to);
943 }
944 }
945
946 void UpdateButtonState()
947 {
948 if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
949
950 bool shared_orders = this->vehicle->IsOrderListShared();
951 VehicleOrderID sel = this->OrderGetSel();
952 const Order *order = this->vehicle->GetOrder(sel);
953
954 /* Second row. */
955 /* skip */
956 this->SetWidgetDisabledState(WID_O_SKIP, this->vehicle->GetNumOrders() <= 1);
957
958 /* delete / stop sharing */
959 NWidgetStacked *delete_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_BOTTOM_MIDDLE);
960 if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
961 /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
962 delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_STOP_SHARING);
963 } else {
964 /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
965 delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE);
966 this->SetWidgetDisabledState(WID_O_DELETE,
967 (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
968
969 /* Set the tooltip of the 'delete' button depending on whether the
970 * 'End of Orders' order or a regular order is selected. */
971 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
972 if (this->selected_order == this->vehicle->GetNumOrders()) {
973 nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
974 } else {
975 nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
976 }
977 }
978
979 /* First row. */
980 this->RaiseWidget(WID_O_FULL_LOAD);
981 this->RaiseWidget(WID_O_UNLOAD);
982
983 /* Selection widgets. */
984 /* Train or road vehicle. */
985 NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
986 NWidgetStacked *left_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
987 NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
988 NWidgetStacked *right_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
989 /* Ship or airplane. */
990 NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
991 assert(row_sel != nullptr || (train_row_sel != nullptr && left_sel != nullptr && middle_sel != nullptr && right_sel != nullptr));
992
993
994 if (order == nullptr) {
995 if (row_sel != nullptr) {
996 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
997 } else {
998 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
999 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1000 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1001 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1002 this->DisableWidget(WID_O_NON_STOP);
1003 this->RaiseWidget(WID_O_NON_STOP);
1004 }
1005 this->DisableWidget(WID_O_FULL_LOAD);
1006 this->DisableWidget(WID_O_UNLOAD);
1007 this->DisableWidget(WID_O_REFIT_DROPDOWN);
1008 } else {
1009 this->SetWidgetDisabledState(WID_O_FULL_LOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
1010 this->SetWidgetDisabledState(WID_O_UNLOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
1011
1012 switch (order->GetType()) {
1013 case OT_GOTO_STATION:
1014 if (row_sel != nullptr) {
1015 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1016 } else {
1017 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1018 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1019 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1020 right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
1021 this->EnableWidget(WID_O_NON_STOP);
1022 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1023 }
1024 this->SetWidgetLoweredState(WID_O_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
1025 this->SetWidgetLoweredState(WID_O_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
1026
1027 /* Can only do refitting when stopping at the destination and loading cargo.
1028 * Also enable the button if a refit is already set to allow clearing it. */
1029 this->SetWidgetDisabledState(WID_O_REFIT_DROPDOWN,
1030 order->GetLoadType() == OLFB_NO_LOAD || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ||
1031 ((!this->can_do_refit || !this->can_do_autorefit) && !order->IsRefit()));
1032
1033 break;
1034
1035 case OT_GOTO_WAYPOINT:
1036 if (row_sel != nullptr) {
1037 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1038 } else {
1039 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1040 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1041 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1042 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1043 this->EnableWidget(WID_O_NON_STOP);
1044 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1045 }
1046 this->DisableWidget(WID_O_FULL_LOAD);
1047 this->DisableWidget(WID_O_UNLOAD);
1048 this->DisableWidget(WID_O_REFIT_DROPDOWN);
1049 break;
1050
1051 case OT_GOTO_DEPOT:
1052 if (row_sel != nullptr) {
1053 row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
1054 } else {
1055 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1056 left_sel->SetDisplayedPlane(DP_LEFT_REFIT);
1057 middle_sel->SetDisplayedPlane(DP_MIDDLE_SERVICE);
1058 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1059 this->EnableWidget(WID_O_NON_STOP);
1060 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1061 }
1062 /* Disable refit button if the order is no 'always go' order.
1063 * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
1064 this->SetWidgetDisabledState(WID_O_REFIT,
1065 (order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT) ||
1066 (!this->can_do_refit && !order->IsRefit()));
1067 break;
1068
1069 case OT_CONDITIONAL: {
1070 if (row_sel != nullptr) {
1071 row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
1072 } else {
1073 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_CONDITIONAL);
1074 }
1075 OrderConditionVariable ocv = order->GetConditionVariable();
1076 /* Set the strings for the dropdown boxes. */
1077 this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv;
1078 this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order->GetConditionComparator()];
1079 this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
1080 this->SetWidgetDisabledState(WID_O_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
1081 break;
1082 }
1083
1084 default: // every other order
1085 if (row_sel != nullptr) {
1086 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1087 } else {
1088 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1089 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1090 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1091 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1092 this->DisableWidget(WID_O_NON_STOP);
1093 }
1094 this->DisableWidget(WID_O_FULL_LOAD);
1095 this->DisableWidget(WID_O_UNLOAD);
1096 this->DisableWidget(WID_O_REFIT_DROPDOWN);
1097 break;
1098 }
1099 }
1100
1101 /* Disable list of vehicles with the same shared orders if there is no list */
1102 this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders);
1103
1104 this->SetDirty();
1105 }
1106
1107 void OnPaint() override
1108 {
1109 if (this->vehicle->owner != _local_company) {
1110 this->selected_order = -1; // Disable selection any selected row at a competitor order window.
1111 } else {
1112 this->SetWidgetLoweredState(WID_O_GOTO, this->goto_type != OPOS_NONE);
1113 }
1114 this->DrawWidgets();
1115 }
1116
1117 void DrawWidget(const Rect &r, WidgetID widget) const override
1118 {
1119 if (widget != WID_O_ORDER_LIST) return;
1120
1121 Rect ir = r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
1122 bool rtl = _current_text_dir == TD_RTL;
1123 SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
1124 int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + WidgetDimensions::scaled.hsep_normal;
1125 int middle = rtl ? ir.right - index_column_width : ir.left + index_column_width;
1126
1127 int y = ir.top;
1128 int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
1129
1130 int i = this->vscroll->GetPosition();
1131 const Order *order = this->vehicle->GetOrder(i);
1132 /* First draw the highlighting underground if it exists. */
1133 if (this->order_over != INVALID_VEH_ORDER_ID) {
1134 while (order != nullptr) {
1135 /* Don't draw anything if it extends past the end of the window. */
1136 if (!this->vscroll->IsVisible(i)) break;
1137
1138 if (i != this->selected_order && i == this->order_over) {
1139 /* Highlight dragged order destination. */
1140 int top = (this->order_over < this->selected_order ? y : y + line_height) - WidgetDimensions::scaled.framerect.top;
1141 int bottom = std::min(top + 2, ir.bottom);
1142 top = std::max(top - 3, ir.top);
1143 GfxFillRect(ir.left, top, ir.right, bottom, _colour_gradient[COLOUR_GREY][7]);
1144 break;
1145 }
1146 y += line_height;
1147
1148 i++;
1149 order = order->next;
1150 }
1151
1152 /* Reset counters for drawing the orders. */
1153 y = ir.top;
1154 i = this->vscroll->GetPosition();
1155 order = this->vehicle->GetOrder(i);
1156 }
1157
1158 /* Draw the orders. */
1159 while (order != nullptr) {
1160 /* Don't draw anything if it extends past the end of the window. */
1161 if (!this->vscroll->IsVisible(i)) break;
1162
1163 DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, ir.left, middle, ir.right);
1164 y += line_height;
1165
1166 i++;
1167 order = order->next;
1168 }
1169
1170 if (this->vscroll->IsVisible(i)) {
1171 StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
1172 DrawString(rtl ? ir.left : middle, rtl ? middle : ir.right, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK);
1173 }
1174 }
1175
1176 void SetStringParameters(WidgetID widget) const override
1177 {
1178 switch (widget) {
1179 case WID_O_COND_VALUE: {
1180 VehicleOrderID sel = this->OrderGetSel();
1181 const Order *order = this->vehicle->GetOrder(sel);
1182
1183 if (order != nullptr && order->IsType(OT_CONDITIONAL)) {
1184 uint value = order->GetConditionValue();
1185 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value, this->vehicle->type);
1186 SetDParam(0, value);
1187 }
1188 break;
1189 }
1190
1191 case WID_O_CAPTION:
1192 SetDParam(0, this->vehicle->index);
1193 break;
1194
1195 case WID_O_DEPOT_ACTION: {
1196 VehicleOrderID sel = this->OrderGetSel();
1197 const Order *order = this->vehicle->GetOrder(sel);
1198 if (order == nullptr || !order->IsType(OT_GOTO_DEPOT)) {
1199 /* We can't leave this param unset or the undefined behavior can cause a crash. */
1200 SetDParam(0, STR_EMPTY);
1201 break;
1202 };
1203
1204 /* Select the current action selected in the dropdown. The flags don't match the dropdown so we can't just use an index. */
1205 if (order->GetDepotOrderType() & ODTFB_SERVICE) {
1206 SetDParam(0, STR_ORDER_DROP_SERVICE_DEPOT);
1207 } else if (order->GetDepotActionType() & ODATFB_HALT) {
1208 SetDParam(0, STR_ORDER_DROP_HALT_DEPOT);
1209 } else if (order->GetDepotActionType() & ODATFB_UNBUNCH) {
1210 SetDParam(0, STR_ORDER_DROP_UNBUNCH);
1211 } else {
1212 SetDParam(0, STR_ORDER_DROP_GO_ALWAYS_DEPOT);
1213 }
1214 break;
1215 }
1216 }
1217 }
1218
1219 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1220 {
1221 switch (widget) {
1222 case WID_O_ORDER_LIST: {
1223 if (this->goto_type == OPOS_CONDITIONAL) {
1224 VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
1225 if (order_id != INVALID_VEH_ORDER_ID) {
1226 Order order;
1227 order.next = nullptr;
1228 order.index = 0;
1229 order.MakeConditional(order_id);
1230
1231 Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order);
1232 }
1233 ResetObjectToPlace();
1234 break;
1235 }
1236
1237 VehicleOrderID sel = this->GetOrderFromPt(pt.y);
1238
1239 if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
1240 TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
1241 if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
1242 return;
1243 }
1244
1245 /* This order won't be selected any more, close all child windows and dropdowns */
1246 this->CloseChildWindows();
1247
1248 if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
1249 /* Deselect clicked order */
1250 this->selected_order = -1;
1251 } else if (sel == this->selected_order) {
1252 if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
1253 Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER,
1254 this->vehicle->tile, this->vehicle->index, sel,
1255 MOF_STOP_LOCATION, (this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END);
1256 }
1257 } else {
1258 /* Select clicked order */
1259 this->selected_order = sel;
1260
1261 if (this->vehicle->owner == _local_company) {
1262 /* Activate drag and drop */
1263 SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1264 }
1265 }
1266
1267 this->UpdateButtonState();
1268 break;
1269 }
1270
1271 case WID_O_SKIP:
1272 this->OrderClick_Skip();
1273 break;
1274
1275 case WID_O_DELETE:
1276 this->OrderClick_Delete();
1277 break;
1278
1279 case WID_O_STOP_SHARING:
1280 this->OrderClick_StopSharing();
1281 break;
1282
1283 case WID_O_NON_STOP:
1284 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1285 this->OrderClick_Nonstop(-1);
1286 } else {
1287 const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1288 assert(o != nullptr);
1289 ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
1290 o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
1291 }
1292 break;
1293
1294 case WID_O_GOTO:
1295 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1296 if (this->goto_type != OPOS_NONE) {
1297 ResetObjectToPlace();
1298 } else {
1299 this->OrderClick_Goto(OPOS_GOTO);
1300 }
1301 } else {
1302 int sel;
1303 switch (this->goto_type) {
1304 case OPOS_NONE: sel = -1; break;
1305 case OPOS_GOTO: sel = 0; break;
1306 case OPOS_CONDITIONAL: sel = 2; break;
1307 case OPOS_SHARE: sel = 3; break;
1308 default: NOT_REACHED();
1309 }
1310 ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
1311 }
1312 break;
1313
1314 case WID_O_FULL_LOAD:
1315 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1316 this->OrderClick_FullLoad(OLF_FULL_LOAD_ANY, true);
1317 } else {
1318 ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
1319 }
1320 break;
1321
1322 case WID_O_UNLOAD:
1323 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1324 this->OrderClick_Unload(OUFB_UNLOAD, true);
1325 } else {
1326 ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
1327 }
1328 break;
1329
1330 case WID_O_REFIT:
1331 this->OrderClick_Refit(0, false);
1332 break;
1333
1334 case WID_O_DEPOT_ACTION:
1335 ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_DEPOT_ACTION, 0, 0);
1336 break;
1337
1338 case WID_O_REFIT_DROPDOWN:
1339 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1340 this->OrderClick_Refit(0, true);
1341 } else {
1342 ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
1343 }
1344 break;
1345
1346 case WID_O_TIMETABLE_VIEW:
1347 ShowTimetableWindow(this->vehicle);
1348 break;
1349
1350 case WID_O_COND_VARIABLE: {
1351 DropDownList list;
1352 for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
1353 list.push_back(std::make_unique<DropDownListStringItem>(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false));
1354 }
1355 ShowDropDownList(this, std::move(list), this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
1356 break;
1357 }
1358
1359 case WID_O_COND_COMPARATOR: {
1360 const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1361 assert(o != nullptr);
1362 ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
1363 break;
1364 }
1365
1366 case WID_O_COND_VALUE: {
1367 const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
1368 assert(order != nullptr);
1369 uint value = order->GetConditionValue();
1370 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value, this->vehicle->type);
1371 SetDParam(0, value);
1372 ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE);
1373 break;
1374 }
1375
1376 case WID_O_SHARED_ORDER_LIST:
1377 ShowVehicleListWindow(this->vehicle);
1378 break;
1379 }
1380 }
1381
1382 void OnQueryTextFinished(char *str) override
1383 {
1384 if (!StrEmpty(str)) {
1385 VehicleOrderID sel = this->OrderGetSel();
1386 uint value = atoi(str);
1387
1388 switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
1389 case OCV_MAX_SPEED:
1390 value = ConvertDisplaySpeedToSpeed(value, this->vehicle->type);
1391 break;
1392
1393 case OCV_RELIABILITY:
1394 case OCV_LOAD_PERCENTAGE:
1395 value = Clamp(value, 0, 100);
1396 break;
1397
1398 default:
1399 break;
1400 }
1401 Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel, MOF_COND_VALUE, Clamp(value, 0, 2047));
1402 }
1403 }
1404
1405 void OnDropdownSelect(WidgetID widget, int index) override
1406 {
1407 switch (widget) {
1408 case WID_O_NON_STOP:
1409 this->OrderClick_Nonstop(index);
1410 break;
1411
1412 case WID_O_FULL_LOAD:
1413 this->OrderClick_FullLoad((OrderLoadFlags)index);
1414 break;
1415
1416 case WID_O_UNLOAD:
1417 this->OrderClick_Unload((OrderUnloadFlags)index);
1418 break;
1419
1420 case WID_O_GOTO:
1421 switch (index) {
1422 case 0: this->OrderClick_Goto(OPOS_GOTO); break;
1423 case 1: this->OrderClick_NearestDepot(); break;
1424 case 2: this->OrderClick_Goto(OPOS_CONDITIONAL); break;
1425 case 3: this->OrderClick_Goto(OPOS_SHARE); break;
1426 default: NOT_REACHED();
1427 }
1428 break;
1429
1430 case WID_O_DEPOT_ACTION:
1431 this->OrderClick_Service(index);
1432 break;
1433
1434 case WID_O_REFIT_DROPDOWN:
1435 this->OrderClick_Refit(index, true);
1436 break;
1437
1438 case WID_O_COND_VARIABLE:
1439 Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), MOF_COND_VARIABLE, index);
1440 break;
1441
1442 case WID_O_COND_COMPARATOR:
1443 Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), MOF_COND_COMPARATOR, index);
1444 break;
1445 }
1446 }
1447
1448 void OnDragDrop(Point pt, WidgetID widget) override
1449 {
1450 switch (widget) {
1451 case WID_O_ORDER_LIST: {
1452 VehicleOrderID from_order = this->OrderGetSel();
1453 VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1454
1455 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()) &&
1456 Command<CMD_MOVE_ORDER>::Post(STR_ERROR_CAN_T_MOVE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, from_order, to_order)) {
1457 this->selected_order = -1;
1458 this->UpdateButtonState();
1459 }
1460 break;
1461 }
1462
1463 case WID_O_DELETE:
1464 this->OrderClick_Delete();
1465 break;
1466
1467 case WID_O_STOP_SHARING:
1468 this->OrderClick_StopSharing();
1469 break;
1470 }
1471
1472 ResetObjectToPlace();
1473
1474 if (this->order_over != INVALID_VEH_ORDER_ID) {
1475 /* End of drag-and-drop, hide dragged order destination highlight. */
1476 this->order_over = INVALID_VEH_ORDER_ID;
1477 this->SetWidgetDirty(WID_O_ORDER_LIST);
1478 }
1479 }
1480
1481 EventState OnHotkey(int hotkey) override
1482 {
1483 if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
1484
1485 switch (hotkey) {
1486 case OHK_SKIP: this->OrderClick_Skip(); break;
1487 case OHK_DELETE: this->OrderClick_Delete(); break;
1488 case OHK_GOTO: this->OrderClick_Goto(OPOS_GOTO); break;
1489 case OHK_NONSTOP: this->OrderClick_Nonstop(-1); break;
1490 case OHK_FULLLOAD: this->OrderClick_FullLoad(OLF_FULL_LOAD_ANY, true); break;
1491 case OHK_UNLOAD: this->OrderClick_Unload(OUFB_UNLOAD, true); break;
1492 case OHK_NEAREST_DEPOT: this->OrderClick_NearestDepot(); break;
1493 case OHK_ALWAYS_SERVICE: this->OrderClick_Service(-1); break;
1494 case OHK_TRANSFER: this->OrderClick_Unload(OUFB_TRANSFER, true); break;
1495 case OHK_NO_UNLOAD: this->OrderClick_Unload(OUFB_NO_UNLOAD, true); break;
1496 case OHK_NO_LOAD: this->OrderClick_FullLoad(OLFB_NO_LOAD, true); break;
1497 default: return ES_NOT_HANDLED;
1498 }
1499 return ES_HANDLED;
1500 }
1501
1502 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
1503 {
1504 if (this->goto_type == OPOS_GOTO) {
1505 const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
1506 if (cmd.IsType(OT_NOTHING)) return;
1507
1508 if (Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), cmd)) {
1509 /* With quick goto the Go To button stays active */
1510 if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
1511 }
1512 }
1513 }
1514
1515 bool OnVehicleSelect(const Vehicle *v) override
1516 {
1517 /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
1518 * We disallow copying orders of other vehicles if we already have at least one order entry
1519 * ourself as it easily copies orders of vehicles within a station when we mean the station.
1520 * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
1521 * TODO: give a warning message */
1522 bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
1523 if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
1524
1525 if (Command<CMD_CLONE_ORDER>::Post(share_order ? STR_ERROR_CAN_T_SHARE_ORDER_LIST : STR_ERROR_CAN_T_COPY_ORDER_LIST,
1526 this->vehicle->tile, share_order ? CO_SHARE : CO_COPY, this->vehicle->index, v->index)) {
1527 this->selected_order = -1;
1528 ResetObjectToPlace();
1529 }
1530 return true;
1531 }
1532
1539 bool OnVehicleSelect(VehicleList::const_iterator begin, VehicleList::const_iterator end) override
1540 {
1541 bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
1542 if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
1543
1544 if (!share_order) {
1545 /* If CTRL is not pressed: If all the vehicles in this list have the same orders, then copy orders */
1546 if (AllEqual(begin, end, [](const Vehicle *v1, const Vehicle *v2) {
1547 return VehiclesHaveSameOrderList(v1, v2);
1548 })) {
1549 OnVehicleSelect(*begin);
1550 } else {
1551 ShowErrorMessage(STR_ERROR_CAN_T_COPY_ORDER_LIST, STR_ERROR_CAN_T_COPY_ORDER_VEHICLE_LIST, WL_INFO);
1552 }
1553 } else {
1554 /* If CTRL is pressed: If all the vehicles in this list share orders, then copy orders */
1555 if (AllEqual(begin, end, [](const Vehicle *v1, const Vehicle *v2) {
1556 return v1->FirstShared() == v2->FirstShared();
1557 })) {
1558 OnVehicleSelect(*begin);
1559 } else {
1560 ShowErrorMessage(STR_ERROR_CAN_T_SHARE_ORDER_LIST, STR_ERROR_CAN_T_SHARE_ORDER_VEHICLE_LIST, WL_INFO);
1561 }
1562 }
1563
1564 return true;
1565 }
1566
1567 void OnPlaceObjectAbort() override
1568 {
1569 this->goto_type = OPOS_NONE;
1570 this->SetWidgetDirty(WID_O_GOTO);
1571
1572 /* Remove drag highlighting if it exists. */
1573 if (this->order_over != INVALID_VEH_ORDER_ID) {
1574 this->order_over = INVALID_VEH_ORDER_ID;
1575 this->SetWidgetDirty(WID_O_ORDER_LIST);
1576 }
1577 }
1578
1579 void OnMouseDrag(Point pt, WidgetID widget) override
1580 {
1581 if (this->selected_order != -1 && widget == WID_O_ORDER_LIST) {
1582 /* An order is dragged.. */
1583 VehicleOrderID from_order = this->OrderGetSel();
1584 VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1585 uint num_orders = this->vehicle->GetNumOrders();
1586
1587 if (from_order != INVALID_VEH_ORDER_ID && from_order <= num_orders) {
1588 if (to_order != INVALID_VEH_ORDER_ID && to_order <= num_orders) { // ..over an existing order.
1589 this->order_over = to_order;
1590 this->SetWidgetDirty(widget);
1591 } else if (from_order != to_order && this->order_over != INVALID_VEH_ORDER_ID) { // ..outside of the order list.
1592 this->order_over = INVALID_VEH_ORDER_ID;
1593 this->SetWidgetDirty(widget);
1594 }
1595 }
1596 }
1597 }
1598
1599 void OnResize() override
1600 {
1601 /* Update the scroll bar */
1602 this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
1603 }
1604
1605 static inline HotkeyList hotkeys{"order", {
1606 Hotkey('D', "skip", OHK_SKIP),
1607 Hotkey('F', "delete", OHK_DELETE),
1608 Hotkey('G', "goto", OHK_GOTO),
1609 Hotkey('H', "nonstop", OHK_NONSTOP),
1610 Hotkey('J', "fullload", OHK_FULLLOAD),
1611 Hotkey('K', "unload", OHK_UNLOAD),
1612 Hotkey(0, "nearest_depot", OHK_NEAREST_DEPOT),
1613 Hotkey(0, "always_service", OHK_ALWAYS_SERVICE),
1614 Hotkey(0, "transfer", OHK_TRANSFER),
1615 Hotkey(0, "no_unload", OHK_NO_UNLOAD),
1616 Hotkey(0, "no_load", OHK_NO_LOAD),
1617 }};
1618 };
1619
1621 static constexpr NWidgetPart _nested_orders_train_widgets[] = {
1622 NWidget(NWID_HORIZONTAL),
1623 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1624 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1625 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1626 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1627 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1628 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1629 EndContainer(),
1630 NWidget(NWID_HORIZONTAL),
1631 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(),
1632 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1633 EndContainer(),
1634
1635 /* First button row. */
1636 NWidget(NWID_HORIZONTAL),
1637 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW_GROUNDVEHICLE),
1638 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1639 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_NON_STOP), SetMinimalSize(93, 12), SetFill(1, 0),
1640 SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
1641 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_LEFT),
1642 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1643 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1644 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(93, 12), SetFill(1, 0),
1645 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1646 EndContainer(),
1647 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_MIDDLE),
1648 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1649 SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1650 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_DEPOT_ACTION), SetMinimalSize(93, 12), SetFill(1, 0),
1651 SetDataTip(STR_JUST_STRING, STR_NULL), SetResize(1, 0),
1652 EndContainer(),
1653 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_RIGHT),
1654 NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(93, 12), SetFill(1, 0), SetResize(1, 0), EndContainer(),
1655 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(93, 12), SetFill(1, 0),
1656 SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1657 EndContainer(),
1658 EndContainer(),
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_JUST_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1666 EndContainer(),
1667 EndContainer(),
1668 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),
1669 EndContainer(),
1670
1671 /* Second button row. */
1672 NWidget(NWID_HORIZONTAL),
1673 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
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 EndContainer(),
1685 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1686 EndContainer(),
1687 };
1688
1689 static WindowDesc _orders_train_desc(__FILE__, __LINE__,
1690 WDP_AUTO, "view_vehicle_orders_train", 384, 100,
1691 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
1692 WDF_CONSTRUCTION,
1693 std::begin(_nested_orders_train_widgets), std::end(_nested_orders_train_widgets),
1694 &OrdersWindow::hotkeys
1695 );
1696
1698 static constexpr NWidgetPart _nested_orders_widgets[] = {
1699 NWidget(NWID_HORIZONTAL),
1700 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1701 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1702 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1703 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1704 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1705 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1706 EndContainer(),
1707 NWidget(NWID_HORIZONTAL),
1708 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(),
1709 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1710 EndContainer(),
1711
1712 /* First button row. */
1713 NWidget(NWID_HORIZONTAL),
1714 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW),
1715 /* Load + unload + refit buttons. */
1716 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1717 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1718 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1719 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1720 SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1721 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(124, 12), SetFill(1, 0),
1722 SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1723 EndContainer(),
1724 /* Refit + service buttons. */
1725 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1726 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
1727 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1728 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_DEPOT_ACTION), SetMinimalSize(124, 12), SetFill(1, 0),
1729 SetDataTip(STR_JUST_STRING, STR_NULL), SetResize(1, 0),
1730 EndContainer(),
1731
1732 /* Buttons for setting a condition. */
1733 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1734 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1735 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1736 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1737 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1738 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1739 SetDataTip(STR_JUST_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1740 EndContainer(),
1741 EndContainer(),
1742
1743 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),
1744 EndContainer(),
1745
1746 /* Second button row. */
1747 NWidget(NWID_HORIZONTAL),
1748 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1749 SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1750 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
1751 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1752 SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1753 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1754 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1755 EndContainer(),
1756 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1757 SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1758 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1759 EndContainer(),
1760 };
1761
1762 static WindowDesc _orders_desc(__FILE__, __LINE__,
1763 WDP_AUTO, "view_vehicle_orders", 384, 100,
1764 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
1765 WDF_CONSTRUCTION,
1766 std::begin(_nested_orders_widgets), std::end(_nested_orders_widgets),
1767 &OrdersWindow::hotkeys
1768 );
1769
1771 static constexpr NWidgetPart _nested_other_orders_widgets[] = {
1772 NWidget(NWID_HORIZONTAL),
1773 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1774 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1775 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1776 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1777 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1778 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1779 EndContainer(),
1780 NWidget(NWID_HORIZONTAL),
1781 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(),
1782 NWidget(NWID_VERTICAL),
1783 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1784 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1785 EndContainer(),
1786 EndContainer(),
1787 };
1788
1789 static WindowDesc _other_orders_desc(__FILE__, __LINE__,
1790 WDP_AUTO, "view_vehicle_orders_competitor", 384, 86,
1791 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
1792 WDF_CONSTRUCTION,
1793 std::begin(_nested_other_orders_widgets), std::end(_nested_other_orders_widgets),
1794 &OrdersWindow::hotkeys
1795 );
1796
1797 void ShowOrdersWindow(const Vehicle *v)
1798 {
1799 CloseWindowById(WC_VEHICLE_DETAILS, v->index, false);
1800 CloseWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
1801 if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != nullptr) return;
1802
1803 /* Using a different WindowDescs for _local_company causes problems.
1804 * Due to this we have to close order windows in ChangeWindowOwner/CloseCompanyWindows,
1805 * because we cannot change switch the WindowDescs and keeping the old WindowDesc results
1806 * in crashed due to missing widges.
1807 * TODO Rewrite the order GUI to not use different WindowDescs.
1808 */
1809 if (v->owner != _local_company) {
1810 new OrdersWindow(&_other_orders_desc, v);
1811 } else {
1812 new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);
1813 }
1814 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:739
DA_STOP
@ DA_STOP
Go to the depot and stop there.
Definition: order_type.h:163
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1143
BaseStation::facilities
StationFacility facilities
The facilities that this station has.
Definition: base_station_base.h:75
BaseConsist::cur_implicit_order_index
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
Definition: base_consist.h:32
VehicleOrderID
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:15
Order::IsRefit
bool IsRefit() const
Is this order a refit order.
Definition: order_base.h:118
OUFB_UNLOAD
@ OUFB_UNLOAD
Force unloading all cargo onto the platform, possibly not getting paid.
Definition: order_type.h:54
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:71
order_cmd.h
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2509
OrdersWindow::OrderClick_Delete
void OrderClick_Delete()
Handle the click on the delete button.
Definition: order_gui.cpp:742
Vehicle::PreviousShared
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
Definition: vehicle_base.h:716
Order::SetLoadType
void SetLoadType(OrderLoadFlags load_type)
Set how the consist must be loaded.
Definition: order_base.h:158
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:37
CARGO_NO_REFIT
static const CargoID CARGO_NO_REFIT
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-renew).
Definition: cargo_type.h:78
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
command_func.h
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
WID_O_SKIP
@ WID_O_SKIP
Skip current order.
Definition: order_widget.h:19
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
ODTFB_SERVICE
@ ODTFB_SERVICE
This depot order is because of the servicing limit.
Definition: order_type.h:95
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:197
dropdown_func.h
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
MOF_COND_VARIABLE
@ MOF_COND_VARIABLE
A conditional variable changes.
Definition: order_type.h:150
NWidgetCore::SetDataTip
void SetDataTip(uint32_t widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:1094
OrderLoadFlags
OrderLoadFlags
Flags related to the loading order.
Definition: order_type.h:62
OrdersWindow::OrderClick_StopSharing
void OrderClick_StopSharing()
Handle the click on the 'stop sharing' button.
Definition: order_gui.cpp:759
OrdersWindow::order_over
VehicleOrderID order_over
Order over which another order is dragged, INVALID_VEH_ORDER_ID if none.
Definition: order_gui.cpp:575
OUFB_TRANSFER
@ OUFB_TRANSFER
Transfer all cargo onto the platform.
Definition: order_type.h:55
OrdersWindow::DisplayPane
DisplayPane
Displayed planes of the NWID_SELECTION widgets.
Definition: order_gui.cpp:547
FACIL_TRUCK_STOP
@ FACIL_TRUCK_STOP
Station with truck stops.
Definition: station_type.h:53
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
Scrollbar::ScrollTowards
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:823
Station
Station data structure.
Definition: station_base.h:442
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:104
OrdersWindow::OrderClick_Skip
void OrderClick_Skip()
Handle the click on the skip button.
Definition: order_gui.cpp:729
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:552
OrdersWindow::DP_ROW_LOAD
@ DP_ROW_LOAD
Display 'load' / 'unload' / 'refit' buttons in the top row of the ship/airplane order window.
Definition: order_gui.cpp:565
Order::GetConditionValue
uint16_t GetConditionValue() const
Get the value to base the skip on.
Definition: order_base.h:155
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
DrawOrderString
void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
Draws an order in order or timetable GUI.
Definition: order_gui.cpp:222
OrdersWindow::DP_ROW_CONDITIONAL
@ DP_ROW_CONDITIONAL
Display the conditional order buttons in the top row of the ship/airplane order window.
Definition: order_gui.cpp:567
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1141
vehiclelist.h
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:210
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
GUISettings::new_nonstop
bool new_nonstop
ttdpatch compatible nonstop handling
Definition: settings_type.h:137
VehiclesHaveSameOrderList
bool VehiclesHaveSameOrderList(const Vehicle *v1, const Vehicle *v2)
Checks if two vehicles have the same list of orders.
Definition: vehicle.cpp:3265
OrdersWindow::OrderClick_NearestDepot
void OrderClick_NearestDepot()
Handle the click on the service in nearest depot button.
Definition: order_gui.cpp:665
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:238
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:131
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
Order::Free
void Free()
'Free' the order
Definition: order_cmd.cpp:63
Window::EnableWidget
void EnableWidget(WidgetID widget_index)
Sets a widget to Enabled.
Definition: window_gui.h:400
MOF_STOP_LOCATION
@ MOF_STOP_LOCATION
Passes an OrderStopLocation.
Definition: order_type.h:146
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1153
Order::GetUnloadType
OrderUnloadFlags GetUnloadType() const
How must the consist be unloaded?
Definition: order_base.h:139
WID_O_SEL_TOP_ROW
@ WID_O_SEL_TOP_ROW
NWID_SELECTION widget for the top row of the 'your non-trains' order window.
Definition: order_widget.h:37
_nested_other_orders_widgets
static constexpr NWidgetPart _nested_other_orders_widgets[]
Nested widget definition for competitor orders.
Definition: order_gui.cpp:1771
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
aircraft.h
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2341
OrdersWindow::UpdateAutoRefitState
void UpdateAutoRefitState()
Cache auto-refittability of the vehicle chain.
Definition: order_gui.cpp:798
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:259
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
WC_VEHICLE_TIMETABLE
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
Definition: window_type.h:224
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:56
_nested_orders_widgets
static constexpr NWidgetPart _nested_orders_widgets[]
Nested widget definition for "your" orders (non-train).
Definition: order_gui.cpp:1698
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:310
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:340
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
WID_O_DEPOT_ACTION
@ WID_O_DEPOT_ACTION
Dropdown to select the depot action (stop, service if needed, unbunch).
Definition: order_widget.h:28
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
Industry
Defines the internal data of a functional industry.
Definition: industry.h:68
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:305
_station_load_types
static const StringID _station_load_types[][5][5]
Order load types that could be given to station orders.
Definition: order_gui.cpp:44
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:680
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
StrEmpty
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:56
WID_O_REFIT_DROPDOWN
@ WID_O_REFIT_DROPDOWN
Open refit options.
Definition: order_widget.h:29
BaseStation::owner
Owner owner
The owner of this station.
Definition: base_station_base.h:74
ShowTimetableWindow
void ShowTimetableWindow(const Vehicle *v)
Show the timetable for a given vehicle.
Definition: timetable_gui.cpp:866
MOF_NON_STOP
@ MOF_NON_STOP
Passes an OrderNonStopFlags.
Definition: order_type.h:145
Vehicle::IsGroundVehicle
debug_inline bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:511
OrderStopLocation
OrderStopLocation
Where to stop the trains.
Definition: order_type.h:83
IsRailWaypointTile
bool IsRailWaypointTile(Tile t)
Is this tile a station tile and a rail waypoint?
Definition: station_map.h:123
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1040
OrdersWindow::OrderClick_Goto
void OrderClick_Goto(OrderPlaceObjectState type)
Handle the click on the goto button.
Definition: order_gui.cpp:613
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:722
ODATFB_UNBUNCH
@ ODATFB_UNBUNCH
Service the vehicle and then unbunch it.
Definition: order_type.h:106
OrdersWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: order_gui.cpp:1599
Industry::neutral_station
Station * neutral_station
Associated neutral station.
Definition: industry.h:98
OrdersWindow::OrderClick_Nonstop
void OrderClick_Nonstop(int non_stop)
Handle the click on the nonstop button.
Definition: order_gui.cpp:707
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: palette.cpp:26
textbuf_gui.h
WID_O_NON_STOP
@ WID_O_NON_STOP
Goto non-stop to destination.
Definition: order_widget.h:22
Order::GetType
OrderType GetType() const
Get the type of order of this order.
Definition: order_base.h:77
Order::GetStopLocation
OrderStopLocation GetStopLocation() const
Where must we stop at the platform?
Definition: order_base.h:143
ONSF_NO_STOP_AT_ANY_STATION
@ ONSF_NO_STOP_AT_ANY_STATION
The vehicle will not stop at any stations it passes including the destination.
Definition: order_type.h:76
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
GetOrderDistance
uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth)
Get the distance between two orders of a vehicle.
Definition: order_cmd.cpp:685
company_cmd.h
ANIMCURSOR_PICKSTATION
static const CursorID ANIMCURSOR_PICKSTATION
716 - 718 - goto-order icon
Definition: sprites.h:1503
ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
@ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
The vehicle will not stop at any stations it passes except the destination.
Definition: order_type.h:74
Order::GetNonStopType
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition: order_base.h:141
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:510
Vehicle::Orders
IterateWrapper Orders() const
Returns an iterable ensemble of orders of a vehicle.
Definition: vehicle_base.h:1075
FACIL_BUS_STOP
@ FACIL_BUS_STOP
Station with bus stops.
Definition: station_type.h:54
IsInsideBS
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:252
OLF_FULL_LOAD_ANY
@ OLF_FULL_LOAD_ANY
Full load a single cargo of the consist.
Definition: order_type.h:65
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1088
EF_AUTO_REFIT
@ EF_AUTO_REFIT
Automatic refitting is allowed.
Definition: engine_type.h:173
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
Order::GetRefitCargo
CargoID GetRefitCargo() const
Get the cargo to to refit to.
Definition: order_base.h:132
timetable.h
WID_O_COND_VARIABLE
@ WID_O_COND_VARIABLE
Choose condition variable.
Definition: order_widget.h:30
OrdersWindow::can_do_autorefit
bool can_do_autorefit
Vehicle chain can be auto-refitted.
Definition: order_gui.cpp:580
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
WID_O_SEL_TOP_LEFT
@ WID_O_SEL_TOP_LEFT
NWID_SELECTION widget for left part of the top row of the 'your train' order window.
Definition: order_widget.h:33
ONSF_STOP_EVERYWHERE
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
Definition: order_type.h:73
WC_VEHICLE_VIEW
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
Definition: window_type.h:339
tilehighlight_func.h
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
INVALID_VEH_ORDER_ID
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
Definition: order_type.h:21
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:207
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1246
SetTimetableParams
void SetTimetableParams(int param1, int param2, TimerGameTick::Ticks ticks)
Set the timetable parameters in the format as described by the setting.
Definition: timetable_gui.cpp:50
_order_conditional_variable
static const OrderConditionVariable _order_conditional_variable[]
Variables for conditional orders; this defines the order of appearance in the dropdown box.
Definition: order_gui.cpp:157
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:260
MOF_COND_COMPARATOR
@ MOF_COND_COMPARATOR
A comparator changes.
Definition: order_type.h:151
Order::MakeGoToWaypoint
void MakeGoToWaypoint(StationID destination)
Makes this order a Go To Waypoint order.
Definition: order_cmd.cpp:104
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
ConvertDisplaySpeedToSpeed
uint ConvertDisplaySpeedToSpeed(uint speed, VehicleType type)
Convert the given display speed to the (internal) speed.
Definition: strings.cpp:878
OrdersWindow::OrderClick_Service
void OrderClick_Service(int i)
Handle the click on the service.
Definition: order_gui.cpp:650
OUF_UNLOAD_IF_POSSIBLE
@ OUF_UNLOAD_IF_POSSIBLE
Unload all cargo that the station accepts.
Definition: order_type.h:53
WID_O_SEL_TOP_MIDDLE
@ WID_O_SEL_TOP_MIDDLE
NWID_SELECTION widget for middle part of the top row of the 'your train' order window.
Definition: order_widget.h:34
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
OrdersWindow::DP_MIDDLE_SERVICE
@ DP_MIDDLE_SERVICE
Display 'service' in the middle button of the top row of the train/rv order window.
Definition: order_gui.cpp:558
WID_O_ORDER_LIST
@ WID_O_ORDER_LIST
Order list panel.
Definition: order_widget.h:17
dropdown_type.h
WID_O_STOP_SHARING
@ WID_O_STOP_SHARING
Stop sharing orders.
Definition: order_widget.h:21
ODATFB_NEAREST_DEPOT
@ ODATFB_NEAREST_DEPOT
Send the vehicle to the nearest depot.
Definition: order_type.h:105
OrdersWindow::OrderClick_FullLoad
void OrderClick_FullLoad(OrderLoadFlags load_type, bool toggle=false)
Handle the click on the full load button.
Definition: order_gui.cpp:632
OrdersWindow::DP_GROUNDVEHICLE_ROW_NORMAL
@ DP_GROUNDVEHICLE_ROW_NORMAL
Display the row for normal/depot orders in the top row of the train/rv order window.
Definition: order_gui.cpp:549
OrdersWindow::OrderGetSel
VehicleOrderID OrderGetSel() const
Return the memorised selected order.
Definition: order_gui.cpp:587
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:350
IsBuoyTile
bool IsBuoyTile(Tile t)
Is tile t a buoy tile?
Definition: station_map.h:317
WC_VEHICLE_DETAILS
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Definition: window_type.h:200
OCC_IS_TRUE
@ OCC_IS_TRUE
Skip if the variable is true.
Definition: order_type.h:135
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:24
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1260
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:50
industry.h
safeguards.h
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1087
DA_ALWAYS_GO
@ DA_ALWAYS_GO
Always go to the depot.
Definition: order_type.h:161
OrdersWindow::GetOrderFromPt
VehicleOrderID GetOrderFromPt(int y)
Calculate the selected order.
Definition: order_gui.cpp:601
ODTFB_PART_OF_ORDERS
@ ODTFB_PART_OF_ORDERS
This depot order is because of a regular order.
Definition: order_type.h:96
Order::IsGotoOrder
bool IsGotoOrder() const
Is this a 'goto' order with a real destination?
Definition: order_base.h:94
Order::GetConditionComparator
OrderConditionComparator GetConditionComparator() const
What is the comparator to use?
Definition: order_base.h:151
WID_O_REFIT
@ WID_O_REFIT
Select refit.
Definition: order_widget.h:27
TC_NO_SHADE
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition: gfx_type.h:277
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:59
OrdersWindow::DP_MIDDLE_UNLOAD
@ DP_MIDDLE_UNLOAD
Display 'unload' in the middle button of the top row of the train/rv order window.
Definition: order_gui.cpp:557
HT_NONE
@ HT_NONE
default
Definition: tilehighlight_type.h:20
IsDepotTypeTile
bool IsDepotTypeTile(Tile tile, TransportType type)
Check if a tile is a depot and it is a depot of the given type.
Definition: depot_map.h:18
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1003
OrdersWindow::OrderPlaceObjectState
OrderPlaceObjectState
Under what reason are we using the PlaceObject functionality?
Definition: order_gui.cpp:538
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
error.h
FACIL_DOCK
@ FACIL_DOCK
Station with a dock.
Definition: station_type.h:56
Order::MakeGoToStation
void MakeGoToStation(StationID destination)
Makes this order a Go To Station order.
Definition: order_cmd.cpp:75
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:406
Order::GetConditionSkipToOrder
VehicleOrderID GetConditionSkipToOrder() const
Get the order to skip to.
Definition: order_base.h:153
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
OrdersWindow::DP_RIGHT_EMPTY
@ DP_RIGHT_EMPTY
Display an empty panel in the right button of the top row of the train/rv order window.
Definition: order_gui.cpp:561
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:113
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
GetDepotIndex
DepotID GetDepotIndex(Tile t)
Get the index of which depot is attached to the tile.
Definition: depot_map.h:52
Vehicle::IsOrderListShared
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Definition: vehicle_base.h:728
OLF_LOAD_IF_POSSIBLE
@ OLF_LOAD_IF_POSSIBLE
Load as long as there is cargo that fits in the train.
Definition: order_type.h:63
Order::SetStopLocation
void SetStopLocation(OrderStopLocation stop_location)
Set where we must stop at the platform.
Definition: order_base.h:164
viewport_func.h
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:484
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:441
ODATFB_HALT
@ ODATFB_HALT
Service the vehicle and then halt it.
Definition: order_type.h:104
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
HT_VEHICLE
@ HT_VEHICLE
vehicle is accepted as target as well (bitmask)
Definition: tilehighlight_type.h:27
OrdersWindow::DP_RIGHT_REFIT
@ DP_RIGHT_REFIT
Display 'refit' in the right button of the top row of the train/rv order window.
Definition: order_gui.cpp:562
HT_DRAG
@ HT_DRAG
dragging items in the depot windows
Definition: tilehighlight_type.h:24
VIWD_CONSIST_CHANGED
@ VIWD_CONSIST_CHANGED
Vehicle composition was changed.
Definition: vehicle_gui.h:37
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2267
_nested_orders_train_widgets
static constexpr NWidgetPart _nested_orders_train_widgets[]
Nested widget definition for "your" train orders.
Definition: order_gui.cpp:1621
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:937
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
OrdersWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: order_gui.cpp:1567
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:31
WID_O_SEL_TOP_ROW_GROUNDVEHICLE
@ WID_O_SEL_TOP_ROW_GROUNDVEHICLE
NWID_SELECTION widget for the top row of the 'your train' order window.
Definition: order_widget.h:36
ONSF_NO_STOP_AT_DESTINATION_STATION
@ ONSF_NO_STOP_AT_DESTINATION_STATION
The vehicle will stop at any station it passes except the destination.
Definition: order_type.h:75
CARGO_AUTO_REFIT
static const CargoID CARGO_AUTO_REFIT
Automatically choose cargo type when doing auto refitting.
Definition: cargo_type.h:77
Order::GetWaitTime
uint16_t GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
Definition: order_base.h:193
string_func.h
Vehicle::FirstShared
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:722
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:111
OrderUnloadFlags
OrderUnloadFlags
Flags related to the unloading order.
Definition: order_type.h:52
GUISettings::quick_goto
bool quick_goto
Allow quick access to 'goto button' in vehicle orders window.
Definition: settings_type.h:179
vehicle_func.h
OrdersWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: order_gui.cpp:1481
station_base.h
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
OCV_MAX_SPEED
@ OCV_MAX_SPEED
Skip based on the maximum speed.
Definition: order_type.h:116
OSL_PLATFORM_FAR_END
@ OSL_PLATFORM_FAR_END
Stop at the far end of the platform.
Definition: order_type.h:86
MOF_UNLOAD
@ MOF_UNLOAD
Passes an OrderUnloadType.
Definition: order_type.h:147
WID_O_SCROLLBAR
@ WID_O_SCROLLBAR
Order list scrollbar.
Definition: order_widget.h:18
OCV_RELIABILITY
@ OCV_RELIABILITY
Skip based on the reliability.
Definition: order_type.h:115
FACIL_TRAIN
@ FACIL_TRAIN
Station with train station.
Definition: station_type.h:52
Scrollbar::IsVisible
bool IsVisible(uint16_t item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:732
Window::DisableWidget
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition: window_gui.h:391
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1036
Vehicle::GetFirstOrder
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
Definition: vehicle_base.h:701
ConvertSpeedToDisplaySpeed
uint ConvertSpeedToDisplaySpeed(uint speed, VehicleType type)
Convert the given (internal) speed to the display speed.
Definition: strings.cpp:865
SetDParamMaxValue
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:127
SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1206
WID_O_UNLOAD
@ WID_O_UNLOAD
Select unload.
Definition: order_widget.h:26
VIWD_AUTOREPLACE
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
Definition: vehicle_gui.h:38
GetOrderCmdFromTile
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
Get the order command a vehicle can do in a given tile.
Definition: order_gui.cpp:387
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
WID_O_GOTO
@ WID_O_GOTO
Goto destination.
Definition: order_widget.h:24
GetStationIndex
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition: station_map.h:28
OCV_REMAINING_LIFETIME
@ OCV_REMAINING_LIFETIME
Skip based on the remaining lifetime.
Definition: order_type.h:120
Aircraft::GetRange
uint16_t GetRange() const
Get the range of this aircraft.
Definition: aircraft.h:134
geometry_func.hpp
OUFB_NO_UNLOAD
@ OUFB_NO_UNLOAD
Totally no unloading will be done.
Definition: order_type.h:56
order_widget.h
Vehicle::HasFullLoadOrder
bool HasFullLoadOrder() const
Check if the current vehicle has a full load order.
Definition: vehicle.cpp:2442
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
Vehicle::NextShared
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition: vehicle_base.h:710
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
NWidgetStacked::SetDisplayedPlane
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1304
MOF_COND_VALUE
@ MOF_COND_VALUE
The value to set the condition to.
Definition: order_type.h:152
OrdersWindow::DP_ROW_DEPOT
@ DP_ROW_DEPOT
Display 'refit' / 'service' buttons in the top row of the ship/airplane order window.
Definition: order_gui.cpp:566
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:762
SpecializedStation< Station, false >::GetByTile
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Definition: base_station_base.h:278
waypoint_base.h
EventState
EventState
State of handling an event.
Definition: window_type.h:738
HT_RECT
@ HT_RECT
rectangle (stations, depots, ...)
Definition: tilehighlight_type.h:21
GUISettings::stop_location
uint8_t stop_location
what is the default stop location of trains?
Definition: settings_type.h:138
WID_O_COND_VALUE
@ WID_O_COND_VALUE
Choose condition value.
Definition: order_widget.h:32
OrdersWindow
Order window code for all vehicles.
Definition: order_gui.cpp:535
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:85
Order::IsAutoRefit
bool IsAutoRefit() const
Is this order a auto-refit order.
Definition: order_base.h:125
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Definition: dropdown.cpp:369
depot_map.h
OrdersWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: order_gui.cpp:1107
Vehicle::HasUnbunchingOrder
bool HasUnbunchingOrder() const
Check if the current vehicle has an unbunching order.
Definition: vehicle.cpp:2466
Order::SetDepotActionType
void SetDepotActionType(OrderDepotActionFlags depot_service_type)
Set what we are going to do in the depot.
Definition: order_base.h:168
company_func.h
OCV_LOAD_PERCENTAGE
@ OCV_LOAD_PERCENTAGE
Skip based on the amount of load.
Definition: order_type.h:114
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:304
WID_O_FULL_LOAD
@ WID_O_FULL_LOAD
Select full load.
Definition: order_widget.h:25
Order::MakeConditional
void MakeConditional(VehicleOrderID order)
Makes this order an conditional order.
Definition: order_cmd.cpp:143
Window::RaiseWidget
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition: window_gui.h:469
HighLightStyle
HighLightStyle
Highlighting draw styles.
Definition: tilehighlight_type.h:19
Order::GetDepotOrderType
OrderDepotTypeFlags GetDepotOrderType() const
What caused us going to the depot?
Definition: order_base.h:145
network.h
WID_O_COND_COMPARATOR
@ WID_O_COND_COMPARATOR
Choose condition type.
Definition: order_widget.h:31
CommandHelper
Definition: command_func.h:93
Order::GetConditionVariable
OrderConditionVariable GetConditionVariable() const
What variable do we have to compare?
Definition: order_base.h:149
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
WID_O_CAPTION
@ WID_O_CAPTION
Caption of the window.
Definition: order_widget.h:15
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1099
WID_O_SEL_TOP_RIGHT
@ WID_O_SEL_TOP_RIGHT
NWID_SELECTION widget for right part of the top row of the 'your train' order window.
Definition: order_widget.h:35
Vehicle::HasConditionalOrder
bool HasConditionalOrder() const
Check if the current vehicle has a conditional order.
Definition: vehicle.cpp:2454
OrdersWindow::OnVehicleSelect
bool OnVehicleSelect(VehicleList::const_iterator begin, VehicleList::const_iterator end) override
Clones an order list from a vehicle list.
Definition: order_gui.cpp:1539
OrderConditionVariable
OrderConditionVariable
Variables (of a vehicle) to 'cause' skipping on.
Definition: order_type.h:113
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:654
SetObjectToPlaceWnd
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
Definition: viewport.cpp:3420
OrdersWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: order_gui.cpp:876
OrdersWindow::can_do_refit
bool can_do_refit
Vehicle chain can be refitted in depot.
Definition: order_gui.cpp:579
DA_UNBUNCH
@ DA_UNBUNCH
Go to the depot and unbunch.
Definition: order_type.h:164
Order::GetLocation
TileIndex GetLocation(const Vehicle *v, bool airport=false) const
Returns a tile somewhat representing the order destination (not suitable for pathfinding).
Definition: order_cmd.cpp:658
SPR_CURSOR_MOUSE
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1382
WID_O_SHARED_ORDER_LIST
@ WID_O_SHARED_ORDER_LIST
Open list of shared vehicles.
Definition: order_widget.h:39
WID_O_TIMETABLE_VIEW
@ WID_O_TIMETABLE_VIEW
Toggle timetable view.
Definition: order_widget.h:16
IsEngineRefittable
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Definition: engine.cpp:1259
OCV_REQUIRES_SERVICE
@ OCV_REQUIRES_SERVICE
Skip when the vehicle requires service.
Definition: order_type.h:118
Window
Data structure for an opened window.
Definition: window_gui.h:267
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
Vehicle::GetOrder
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
Definition: vehicle_base.h:913
OrdersWindow::DP_LEFT_REFIT
@ DP_LEFT_REFIT
Display 'refit' in the left button of the top row of the train/rv order window.
Definition: order_gui.cpp:554
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:51
OrdersWindow::OrderClick_Refit
void OrderClick_Refit(int i, bool auto_refit)
Handle the click on the refit button.
Definition: order_gui.cpp:783
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
AllEqual
bool AllEqual(It begin, It end, Pred pred)
Generic helper function that checks if all elements of the range are equal with respect to the given ...
Definition: window_gui.h:934
FACIL_AIRPORT
@ FACIL_AIRPORT
Station with an airport.
Definition: station_type.h:55
OrdersWindow::DP_LEFT_LOAD
@ DP_LEFT_LOAD
Display 'load' in the left button of the top row of the train/rv order window.
Definition: order_gui.cpp:553
VIWD_MODIFY_ORDERS
@ VIWD_MODIFY_ORDERS
Other order modifications.
Definition: vehicle_gui.h:36
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1164
CanVehicleUseStation
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Definition: vehicle.cpp:3034
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
OCV_MAX_RELIABILITY
@ OCV_MAX_RELIABILITY
Skip based on the maximum reliability.
Definition: order_type.h:121
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
OrdersWindow::DP_GROUNDVEHICLE_ROW_CONDITIONAL
@ DP_GROUNDVEHICLE_ROW_CONDITIONAL
Display the row for conditional orders in the top row of the train/rv order window.
Definition: order_gui.cpp:550
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1224
MOF_LOAD
@ MOF_LOAD
Passes an OrderLoadType.
Definition: order_type.h:148
OCC_IS_FALSE
@ OCC_IS_FALSE
Skip if the variable is false.
Definition: order_type.h:136
Vehicle::GetNumOrders
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:734
VIWD_REMOVE_ALL_ORDERS
@ VIWD_REMOVE_ALL_ORDERS
Removed / replaced all orders (after deleting / sharing).
Definition: vehicle_gui.h:35
IsTileOwner
bool IsTileOwner(Tile tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:214
Order::GetDepotActionType
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
Definition: order_base.h:147
Order::MakeGoToDepot
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CARGO_NO_REFIT)
Makes this order a Go To Depot order.
Definition: order_cmd.cpp:90
ShowVehicleRefitWindow
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
Show the refit window for a vehicle.
Definition: vehicle_gui.cpp:1288
OrdersWindow::OrderClick_Unload
void OrderClick_Unload(OrderUnloadFlags unload_type, bool toggle=false)
Handle the click on the unload button.
Definition: order_gui.cpp:682
Order::next
Order * next
Pointer to next order. If nullptr, end of list.
Definition: order_base.h:59
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
MOF_DEPOT_ACTION
@ MOF_DEPOT_ACTION
Selects the OrderDepotAction.
Definition: order_type.h:149
Order
Definition: order_base.h:36
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3483
DA_SERVICE
@ DA_SERVICE
Service only if needed.
Definition: order_type.h:162
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition: string_type.h:26
OCV_AGE
@ OCV_AGE
Skip based on the age.
Definition: order_type.h:117
Order::IsWaitTimetabled
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Definition: order_base.h:184
Order::SetNonStopType
void SetNonStopType(OrderNonStopFlags non_stop_type)
Set whether we must stop at stations or not.
Definition: order_base.h:162
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:848
OrderConditionComparator
OrderConditionComparator
Comparator for the skip reasoning.
Definition: order_type.h:128
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
WC_VEHICLE_ORDERS
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
Definition: window_type.h:212
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:635
NWID_BUTTON_DROPDOWN
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition: widget_type.h:84
OCV_UNCONDITIONALLY
@ OCV_UNCONDITIONALLY
Always skip.
Definition: order_type.h:119
OLFB_NO_LOAD
@ OLFB_NO_LOAD
Do not load anything.
Definition: order_type.h:66
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:72
WID_O_DELETE
@ WID_O_DELETE
Delete selected order.
Definition: order_widget.h:20
Order::GetLoadType
OrderLoadFlags GetLoadType() const
How must the consist be loaded?
Definition: order_base.h:137
engine_func.h
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:21
hotkeys.h
roadveh.h
OrdersWindow::DP_BOTTOM_MIDDLE_STOP_SHARING
@ DP_BOTTOM_MIDDLE_STOP_SHARING
Display 'stop sharing' in the middle button of the bottom row of the vehicle order window.
Definition: order_gui.cpp:571
WID_O_SEL_BOTTOM_MIDDLE
@ WID_O_SEL_BOTTOM_MIDDLE
NWID_SELECTION widget for the middle part of the bottom row of the 'your train' order window.
Definition: order_widget.h:38
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
OrdersWindow::vehicle
const Vehicle * vehicle
Vehicle owning the orders being displayed and manipulated.
Definition: order_gui.cpp:577
OrdersWindow::DP_BOTTOM_MIDDLE_DELETE
@ DP_BOTTOM_MIDDLE_DELETE
Display 'delete' in the middle button of the bottom row of the vehicle order window.
Definition: order_gui.cpp:570
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103