OpenTTD Source: src/order_gui.cpp Source File

OpenTTD Source 15.0-RC2

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