OpenTTD Source 20261112-master-gbcbec5e63f
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
9
10#include "stdafx.h"
11#include "command_func.h"
12#include "viewport_func.h"
13#include "depot_map.h"
14#include "timetable.h"
15#include "strings_func.h"
16#include "company_func.h"
17#include "dropdown_type.h"
18#include "dropdown_func.h"
19#include "textbuf_gui.h"
20#include "tilehighlight_func.h"
21#include "network/network.h"
22#include "station_base.h"
23#include "industry.h"
25#include "hotkeys.h"
26#include "aircraft.h"
27#include "engine_base.h"
28#include "engine_func.h"
29#include "vehicle_func.h"
30#include "vehicle_gui.h"
31#include "vehiclelist.h"
32#include "error.h"
33#include "order_cmd.h"
34#include "company_cmd.h"
36#include "window_func.h"
37
39
40#include "table/strings.h"
41
42#include "safeguards.h"
43
44
46static const StringID _station_load_types[][5][5] = {
47 {
48 /* No refitting. */
49 {
52 STR_ORDER_FULL_LOAD,
53 STR_ORDER_FULL_LOAD_ANY,
54 STR_ORDER_NO_LOAD,
55 }, {
56 STR_ORDER_UNLOAD,
58 STR_ORDER_UNLOAD_FULL_LOAD,
59 STR_ORDER_UNLOAD_FULL_LOAD_ANY,
60 STR_ORDER_UNLOAD_NO_LOAD,
61 }, {
62 STR_ORDER_TRANSFER,
64 STR_ORDER_TRANSFER_FULL_LOAD,
65 STR_ORDER_TRANSFER_FULL_LOAD_ANY,
66 STR_ORDER_TRANSFER_NO_LOAD,
67 }, {
68 /* Unload and transfer do not work together. */
74 }, {
75 STR_ORDER_NO_UNLOAD,
77 STR_ORDER_NO_UNLOAD_FULL_LOAD,
78 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
79 STR_ORDER_NO_UNLOAD_NO_LOAD,
80 }
81 }, {
82 /* With auto-refitting. No loading and auto-refitting do not work together. */
83 {
84 STR_ORDER_AUTO_REFIT,
86 STR_ORDER_FULL_LOAD_REFIT,
87 STR_ORDER_FULL_LOAD_ANY_REFIT,
89 }, {
90 STR_ORDER_UNLOAD_REFIT,
92 STR_ORDER_UNLOAD_FULL_LOAD_REFIT,
93 STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT,
95 }, {
96 STR_ORDER_TRANSFER_REFIT,
98 STR_ORDER_TRANSFER_FULL_LOAD_REFIT,
99 STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT,
101 }, {
102 /* Unload and transfer do not work together. */
108 }, {
109 STR_ORDER_NO_UNLOAD_REFIT,
111 STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT,
112 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT,
114 }
115 }
116};
117
118static const StringID _order_non_stop_dropdown[] = {
119 STR_ORDER_GO_TO,
120 STR_ORDER_GO_NON_STOP_TO,
121 STR_ORDER_GO_VIA,
122 STR_ORDER_GO_NON_STOP_VIA,
123};
124
125static const StringID _order_full_load_dropdown[] = {
126 STR_ORDER_DROP_LOAD_IF_POSSIBLE,
127 STR_EMPTY,
128 STR_ORDER_DROP_FULL_LOAD_ALL,
129 STR_ORDER_DROP_FULL_LOAD_ANY,
130 STR_ORDER_DROP_NO_LOADING,
131};
132
133static const StringID _order_unload_dropdown[] = {
134 STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
135 STR_ORDER_DROP_UNLOAD,
136 STR_ORDER_DROP_TRANSFER,
137 STR_EMPTY,
138 STR_ORDER_DROP_NO_UNLOADING,
139};
140
141static const StringID _order_goto_dropdown[] = {
142 STR_ORDER_GO_TO,
143 STR_ORDER_GO_TO_NEAREST_DEPOT,
144 STR_ORDER_CONDITIONAL,
145 STR_ORDER_SHARE,
146};
147
148static const StringID _order_goto_dropdown_aircraft[] = {
149 STR_ORDER_GO_TO,
150 STR_ORDER_GO_TO_NEAREST_HANGAR,
151 STR_ORDER_CONDITIONAL,
152 STR_ORDER_SHARE,
153};
154
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{
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{
205 return order.GetNonStopType().Test(OrderNonStopFlag::NonStop) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT;
206 } else {
207 return order.GetNonStopType().Test(OrderNonStopFlag::NonStop) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO;
208 }
209}
210
223void 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(FontSize::Normal) - (int)sprite_size.height) / 2);
232 DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)GetCharacterHeight(FontSize::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(FontSize::Normal) - (int)sprite_size.height) / 2);
236 }
237
239 if (order->IsType(OT_IMPLICIT)) {
241 } else if (selected) {
242 colour = TextColour::White;
243 }
244
245 DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, GetString(STR_ORDER_INDEX, order_index + 1), colour, AlignmentH::ForceRight);
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. */
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
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:
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 == VehicleType::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 + to_underlying(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. */
318 line += GetString(STR_ORDER_WAIT_TO_UNBUNCH);
319 }
320 break;
321
322 case OT_GOTO_WAYPOINT:
323 line = GetString(order->GetNonStopType().Test(OrderNonStopFlag::NonStop) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT, order->GetDestination());
324 break;
325
326 case OT_CONDITIONAL:
328 line = GetString(STR_ORDER_CONDITIONAL_UNCONDITIONAL, order->GetConditionSkipToOrder() + 1);
329 } else {
331
332 uint value = order->GetConditionValue();
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 == VehicleType::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
368{
369 Order order{};
370
371 /* check depot first */
372 if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) {
376
377 if (IsCtrlPressed()) {
378 /* Now we are allowed to set the action type. */
380 }
381
382 return order;
383 }
384
385 /* check rail waypoint */
386 if (IsRailWaypointTile(tile) &&
387 v->type == VehicleType::Train &&
391 return order;
392 }
393
394 /* check road waypoint */
395 if (IsRoadWaypointTile(tile) &&
396 v->type == VehicleType::Road &&
400 return order;
401 }
402
403 /* check buoy (no ownership) */
404 if (IsBuoyTile(tile) && v->type == VehicleType::Ship) {
406 return order;
407 }
408
409 /* check for station or industry with neutral station */
411 const Station *st = nullptr;
412
413 if (IsTileType(tile, TileType::Station)) {
414 st = Station::GetByTile(tile);
415 } else {
416 const Industry *in = Industry::GetByTile(tile);
417 st = in->neutral_station;
418 }
419 if (st != nullptr && (st->owner == _local_company || st->owner == OWNER_NONE)) {
420 StationFacilities facil;
421 switch (v->type) {
422 case VehicleType::Ship: facil = StationFacility::Dock; break;
423 case VehicleType::Train: facil = StationFacility::Train; break;
426 default: NOT_REACHED();
427 }
428 if (st->facilities.Any(facil)) {
429 order.MakeGoToStation(st->index);
433 return order;
434 }
435 }
436 }
437
438 /* not found */
439 order.Free();
440 return order;
441}
442
444enum OrderHotKeys : int32_t {
445 OHK_SKIP,
446 OHK_DELETE,
447 OHK_GOTO,
448 OHK_NONSTOP,
449 OHK_FULLLOAD,
450 OHK_UNLOAD,
451 OHK_NEAREST_DEPOT,
452 OHK_ALWAYS_SERVICE,
453 OHK_TRANSFER,
454 OHK_NO_UNLOAD,
455 OHK_NO_LOAD,
456};
457
498struct OrdersWindow : public Window {
499private:
501 enum OrderPlaceObjectState : uint8_t {
502 OPOS_NONE,
503 OPOS_GOTO,
504 OPOS_CONDITIONAL,
505 OPOS_SHARE,
506 OPOS_END,
507 };
508
510 enum DisplayPane : uint8_t {
511 /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
514
515 /* WID_O_SEL_TOP_LEFT */
518
519 /* WID_O_SEL_TOP_MIDDLE */
522
523 /* WID_O_SEL_TOP_RIGHT */
526
527 /* WID_O_SEL_TOP_ROW */
531
532 /* WID_O_SEL_BOTTOM_MIDDLE */
535 };
536
537 int selected_order = -1;
539 OrderPlaceObjectState goto_type = OPOS_NONE;
540 const Vehicle *vehicle = nullptr;
541 Scrollbar *vscroll = nullptr;
542 bool can_do_refit = false;
543 bool can_do_autorefit = false;
544
551 {
552 int num = this->selected_order;
553 return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
554 }
555
565 {
566 int32_t sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_O_ORDER_LIST, WidgetDimensions::scaled.framerect.top);
567 if (sel == INT32_MAX) return INVALID_VEH_ORDER_ID;
568 /* One past the orders is the 'End of Orders' line. */
569 assert(IsInsideBS(sel, 0, vehicle->GetNumOrders() + 1));
570 return sel;
571 }
572
578 {
579 assert(type > OPOS_NONE && type < OPOS_END);
580
581 static const HighLightStyle goto_place_style[OPOS_END - 1] = {
582 HT_RECT | HT_VEHICLE, // OPOS_GOTO
583 HT_NONE, // OPOS_CONDITIONAL
584 HT_VEHICLE, // OPOS_SHARE
585 };
586 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, goto_place_style[type - 1], this);
587 this->goto_type = type;
589 }
590
596 void OrderClick_FullLoad(OrderLoadType load_type, bool toggle = false)
597 {
598 VehicleOrderID sel_ord = this->OrderGetSel();
599 const Order *order = this->vehicle->GetOrder(sel_ord);
600
601 if (order == nullptr) return;
602
603 if (toggle && order->GetLoadType() == load_type) {
604 load_type = OrderLoadType::LoadIfPossible; // reset to 'default'
605 }
606 if (order->GetLoadType() == load_type) return; // If we still match, do nothing
607
608 Command<Commands::ModifyOrder>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_LOAD, to_underlying(load_type));
609 }
610
615 void OrderClick_Service(std::optional<OrderDepotAction> i)
616 {
617 VehicleOrderID sel_ord = this->OrderGetSel();
618
619 if (!i.has_value()) {
620 const Order *order = this->vehicle->GetOrder(sel_ord);
621 if (order == nullptr) return;
623 }
624 Command<Commands::ModifyOrder>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_DEPOT_ACTION, to_underlying(i.value()));
625 }
626
631 {
632 Order order{};
633 order.MakeGoToDepot(DepotID::Invalid(), OrderDepotTypeFlag::PartOfOrders,
634 _settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? OrderNonStopFlag::NonStop : OrderNonStopFlags{});
636
637 Command<Commands::InsertOrder>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order);
638 }
639
645 void OrderClick_Unload(OrderUnloadType unload_type, bool toggle = false)
646 {
647 VehicleOrderID sel_ord = this->OrderGetSel();
648 const Order *order = this->vehicle->GetOrder(sel_ord);
649
650 if (order == nullptr) return;
651
652 if (toggle && order->GetUnloadType() == unload_type) {
654 }
655 if (order->GetUnloadType() == unload_type) return; // If we still match, do nothing
656
657 Command<Commands::ModifyOrder>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_UNLOAD, to_underlying(unload_type));
658
659 /* Transfer and unload orders with leave empty as default */
660 if (unload_type == OrderUnloadType::Transfer || unload_type == OrderUnloadType::Unload) {
661 Command<Commands::ModifyOrder>::Post(this->vehicle->tile, this->vehicle->index, sel_ord, MOF_LOAD, to_underlying(OrderLoadType::NoLoad));
663 }
664 }
665
670 void OrderClick_Nonstop(std::optional<OrderNonStopFlags> non_stop)
671 {
672 if (!this->vehicle->IsGroundVehicle()) return;
673
674 VehicleOrderID sel_ord = this->OrderGetSel();
675 const Order *order = this->vehicle->GetOrder(sel_ord);
676
677 if (order == nullptr || order->GetNonStopType() == non_stop) return;
678
679 /* Keypress if no value, so 'toggle' to the next */
680 if (!non_stop.has_value()) {
681 non_stop = order->GetNonStopType().Flip(OrderNonStopFlag::NonStop);
682 }
683
685 Command<Commands::ModifyOrder>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_NON_STOP, non_stop.value().base());
686 }
687
693 {
694 /* Don't skip when there's nothing to skip */
695 if (IsCtrlPressed() && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
696 if (this->vehicle->GetNumOrders() <= 1) return;
697
698 Command<Commands::SkipToOrder>::Post(IsCtrlPressed() ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER,
699 this->vehicle->tile, this->vehicle->index, IsCtrlPressed() ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()));
700 }
701
706 {
707 /* When networking, move one order lower */
708 int selected = this->selected_order + (int)_networking;
709
710 if (Command<Commands::DeleteOrder>::Post(STR_ERROR_CAN_T_DELETE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel())) {
711 this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
712 this->UpdateButtonState();
713 }
714 }
715
723 {
724 /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
725 if (!this->vehicle->IsOrderListShared() || this->selected_order != this->vehicle->GetNumOrders()) return;
726 /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
727 if (IsCtrlPressed()) {
728 this->OrderClick_Delete();
729 return;
730 }
731
732 /* Get another vehicle that share orders with this vehicle. */
733 Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
734 /* Copy the order list of the other vehicle. */
735 if (Command<Commands::CloneOrder>::Post(STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST, this->vehicle->tile, CO_COPY, this->vehicle->index, other_shared->index)) {
736 this->UpdateButtonState();
737 }
738 }
739
746 void OrderClick_Refit(int i, bool auto_refit)
747 {
748 if (IsCtrlPressed()) {
749 /* Cancel refitting */
750 Command<Commands::OrderRefit>::Post(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CARGO_NO_REFIT);
751 } else {
752 if (i == 1) { // Auto-refit to available cargo type.
753 Command<Commands::OrderRefit>::Post(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CARGO_AUTO_REFIT);
754 } else {
755 ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
756 }
757 }
758 }
759
762 {
763 this->can_do_refit = false;
764 this->can_do_autorefit = false;
765 for (const Vehicle *w = this->vehicle; w != nullptr; w = w->IsGroundVehicle() ? w->Next() : nullptr) {
766 if (IsEngineRefittable(w->engine_type)) this->can_do_refit = true;
767 if (Engine::Get(w->engine_type)->info.misc_flags.Test(EngineMiscFlag::AutoRefit)) this->can_do_autorefit = true;
768 }
769 }
770
771public:
772 OrdersWindow(WindowDesc &desc, const Vehicle *v) : Window(desc)
773 {
774 this->vehicle = v;
775
776 this->CreateNestedTree();
777 this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
778 if (NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_O_DEPOT_ACTION); nwid != nullptr) {
779 nwid->SetToolTip(STR_ORDER_TRAIN_DEPOT_ACTION_TOOLTIP + to_underlying(v->type));
780 }
781 this->FinishInitNested(v->index);
782
783 this->owner = v->owner;
784
785 this->UpdateAutoRefitState();
786
788 /* If there are less than 2 station, make Go To active. */
789 int station_orders = std::ranges::count_if(v->Orders(), [](const Order &order) { return order.IsType(OT_GOTO_STATION); });
790
791 if (station_orders < 2) this->OrderClick_Goto(OPOS_GOTO);
792 }
794 }
795
796 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
797 {
798 switch (widget) {
799 case WID_O_ORDER_LIST:
800 fill.height = resize.height = GetCharacterHeight(FontSize::Normal);
801 size.height = 6 * resize.height + padding.height;
802 break;
803
804 case WID_O_COND_VARIABLE: {
805 Dimension d = {0, 0};
806 for (const auto &ocv : _order_conditional_variable) {
807 d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + to_underlying(ocv)));
808 }
809 d.width += padding.width;
810 d.height += padding.height;
811 size = maxdim(size, d);
812 break;
813 }
814
816 Dimension d = GetStringListBoundingBox(_order_conditional_condition);
817 d.width += padding.width;
818 d.height += padding.height;
819 size = maxdim(size, d);
820 break;
821 }
822
823 case WID_O_DELETE: {
824 Dimension d = maxdim(GetStringBoundingBox(STR_ORDERS_DELETE_BUTTON), GetStringBoundingBox(STR_ORDERS_DELETE_ALL_BUTTON));
825 d.width += padding.width;
826 d.height += padding.height;
827 size = maxdim(size, d);
828 break;
829 }
830 }
831 }
832
838 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
839 {
842
843 switch (data) {
844 case VIWD_AUTOREPLACE:
845 /* Autoreplace replaced the vehicle */
846 this->vehicle = Vehicle::Get(this->window_number);
847 [[fallthrough]];
848
850 /* Vehicle composition was changed. */
851 this->UpdateAutoRefitState();
852 break;
853
855 /* Removed / replaced all orders (after deleting / sharing) */
856 if (this->selected_order == -1) break;
857
858 this->CloseChildWindows();
859 this->selected_order = -1;
860 break;
861
863 /* Some other order changes */
864 break;
865
866 default:
867 if (data < 0) break;
868
869 if (gui_scope) break; // only do this once; from command scope
870 from = GB(data, 0, 8);
871 to = GB(data, 8, 8);
872 /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
873 * the order is being created / removed */
874 if (this->selected_order == -1) break;
875
876 if (from == to) break; // no need to change anything
877
878 if (from != this->selected_order) {
879 /* Moving from preceding order? */
880 this->selected_order -= (int)(from <= this->selected_order);
881 /* Moving to preceding order? */
882 this->selected_order += (int)(to <= this->selected_order);
883 break;
884 }
885
886 /* Now we are modifying the selected order */
887 if (to == INVALID_VEH_ORDER_ID) {
888 /* Deleting selected order */
889 this->CloseChildWindows();
890 this->selected_order = -1;
891 break;
892 }
893
894 /* Moving selected order */
895 this->selected_order = to;
896 break;
897 }
898
899 this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
900 if (gui_scope) this->UpdateButtonState();
901
902 /* Scroll to the new order. */
903 if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {
904 this->vscroll->ScrollTowards(to);
905 }
906 }
907
908 void UpdateButtonState()
909 {
910 if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
911
912 bool shared_orders = this->vehicle->IsOrderListShared();
913 VehicleOrderID sel = this->OrderGetSel();
914 const Order *order = this->vehicle->GetOrder(sel);
915
916 /* Second row. */
917 /* skip */
918 this->SetWidgetDisabledState(WID_O_SKIP, this->vehicle->GetNumOrders() <= 1);
919
920 /* delete / stop sharing */
922 if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
923 /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
925 } else {
926 /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
929 (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
930
931 /* Set the tooltip of the 'delete' button depending on whether the
932 * 'End of Orders' order or a regular order is selected. */
933 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
934 if (this->selected_order == this->vehicle->GetNumOrders()) {
935 nwi->SetStringTip(STR_ORDERS_DELETE_ALL_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
936 } else {
937 nwi->SetStringTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
938 }
939 }
940
941 /* First row. */
944
945 /* Selection widgets. */
946 /* Train or road vehicle. */
947 NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
948 NWidgetStacked *left_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
949 NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
950 NWidgetStacked *right_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
951 /* Ship or airplane. */
952 NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
953 assert(row_sel != nullptr || (train_row_sel != nullptr && left_sel != nullptr && middle_sel != nullptr && right_sel != nullptr));
954
955
956 if (order == nullptr) {
957 if (row_sel != nullptr) {
959 } else {
966 }
970 } else {
973
974 switch (order->GetType()) {
975 case OT_GOTO_STATION:
976 if (row_sel != nullptr) {
978 } else {
985 }
988
989 /* Can only do refitting when stopping at the destination and loading cargo.
990 * Also enable the button if a refit is already set to allow clearing it. */
993 ((!this->can_do_refit || !this->can_do_autorefit) && !order->IsRefit()));
994
995 break;
996
997 case OT_GOTO_WAYPOINT:
998 if (row_sel != nullptr) {
1000 } else {
1007 }
1011 break;
1012
1013 case OT_GOTO_DEPOT:
1014 if (row_sel != nullptr) {
1016 } else {
1023 }
1024 /* Disable refit button if the order is no 'always go' order.
1025 * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
1028 (!this->can_do_refit && !order->IsRefit()));
1029 break;
1030
1031 case OT_CONDITIONAL: {
1032 if (row_sel != nullptr) {
1034 } else {
1036 }
1038 /* Set the strings for the dropdown boxes. */
1039 this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->SetString(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + to_underlying(ocv));
1040 this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->SetString(_order_conditional_condition[to_underlying(order->GetConditionComparator())]);
1043 break;
1044 }
1045
1046 default: // every other order
1047 if (row_sel != nullptr) {
1049 } else {
1055 }
1059 break;
1060 }
1061 }
1062
1063 /* Disable list of vehicles with the same shared orders if there is no list */
1064 this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders);
1065
1066 this->SetDirty();
1067 }
1068
1069 void OnPaint() override
1070 {
1071 if (this->vehicle->owner != _local_company) {
1072 this->selected_order = -1; // Disable selection any selected row at a competitor order window.
1073 } else {
1074 this->SetWidgetLoweredState(WID_O_GOTO, this->goto_type != OPOS_NONE);
1075 }
1076 this->DrawWidgets();
1077 }
1078
1079 void DrawWidget(const Rect &r, WidgetID widget) const override
1080 {
1081 if (widget != WID_O_ORDER_LIST) return;
1082
1083 Rect ir = r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
1084 bool rtl = _current_text_dir == TD_RTL;
1085 uint64_t max_value = GetParamMaxValue(this->vehicle->GetNumOrders(), 2);
1086 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;
1087 int middle = rtl ? ir.right - index_column_width : ir.left + index_column_width;
1088
1089 int y = ir.top;
1090 int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
1091
1092 VehicleOrderID i = this->vscroll->GetPosition();
1093 VehicleOrderID num_orders = this->vehicle->GetNumOrders();
1094
1095 /* First draw the highlighting underground if it exists. */
1096 if (this->order_over != INVALID_VEH_ORDER_ID) {
1097 while (i < num_orders) {
1098 /* Don't draw anything if it extends past the end of the window. */
1099 if (!this->vscroll->IsVisible(i)) break;
1100
1101 if (i != this->selected_order && i == this->order_over) {
1102 /* Highlight dragged order destination. */
1103 int top = (this->order_over < this->selected_order ? y : y + line_height) - WidgetDimensions::scaled.framerect.top;
1104 int bottom = std::min(top + 2, ir.bottom);
1105 top = std::max(top - 3, ir.top);
1106 GfxFillRect(ir.left, top, ir.right, bottom, GetColourGradient(Colours::Grey, Shade::Lightest));
1107 break;
1108 }
1109 y += line_height;
1110
1111 i++;
1112 }
1113
1114 /* Reset counters for drawing the orders. */
1115 y = ir.top;
1116 i = this->vscroll->GetPosition();
1117 }
1118
1119 /* Draw the orders. */
1120 while (i < num_orders) {
1121 /* Don't draw anything if it extends past the end of the window. */
1122 if (!this->vscroll->IsVisible(i)) break;
1123
1124 DrawOrderString(this->vehicle, this->vehicle->GetOrder(i), i, y, i == this->selected_order, false, ir.left, middle, ir.right);
1125 y += line_height;
1126
1127 i++;
1128 }
1129
1130 if (this->vscroll->IsVisible(i)) {
1131 StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
1132 DrawString(rtl ? ir.left : middle, rtl ? middle : ir.right, y, str, (i == this->selected_order) ? TextColour::White : TextColour::Black);
1133 }
1134 }
1135
1136 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
1137 {
1138 switch (widget) {
1139 case WID_O_COND_VALUE: {
1140 VehicleOrderID sel = this->OrderGetSel();
1141 const Order *order = this->vehicle->GetOrder(sel);
1142
1143 if (order != nullptr && order->IsType(OT_CONDITIONAL)) {
1144 uint value = order->GetConditionValue();
1145 if (order->GetConditionVariable() == OrderConditionVariable::MaxSpeed) value = ConvertSpeedToDisplaySpeed(value, this->vehicle->type);
1146 return GetString(STR_JUST_COMMA, value);
1147 }
1148 return {};
1149 }
1150
1151 case WID_O_CAPTION:
1152 return GetString(STR_ORDERS_CAPTION, this->vehicle->index);
1153
1154 case WID_O_DEPOT_ACTION: {
1155 VehicleOrderID sel = this->OrderGetSel();
1156 const Order *order = this->vehicle->GetOrder(sel);
1157 if (order == nullptr || !order->IsType(OT_GOTO_DEPOT)) return {};
1158
1159 /* Select the current action selected in the dropdown. The flags don't match the dropdown so we can't just use an index. */
1160 if (order->GetDepotOrderType().Test(OrderDepotTypeFlag::Service)) return GetString(STR_ORDER_DROP_SERVICE_DEPOT);
1161 if (order->GetDepotActionType().Test(OrderDepotActionFlag::Halt)) return GetString(STR_ORDER_DROP_HALT_DEPOT);
1162 if (order->GetDepotActionType().Test(OrderDepotActionFlag::Unbunch)) return GetString(STR_ORDER_DROP_UNBUNCH);
1163
1164 return GetString(STR_ORDER_DROP_GO_ALWAYS_DEPOT);
1165 }
1166
1167 default:
1168 return this->Window::GetWidgetString(widget, stringid);
1169 }
1170 }
1171
1172 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1173 {
1174 switch (widget) {
1175 case WID_O_ORDER_LIST: {
1176 if (this->goto_type == OPOS_CONDITIONAL) {
1177 VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
1178 if (order_id != INVALID_VEH_ORDER_ID) {
1179 Order order{};
1180 order.MakeConditional(order_id);
1181
1182 Command<Commands::InsertOrder>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order);
1183 }
1185 break;
1186 }
1187
1188 VehicleOrderID sel = this->GetOrderFromPt(pt.y);
1189
1190 if (IsCtrlPressed() && sel < this->vehicle->GetNumOrders()) {
1191 TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
1192 if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
1193 return;
1194 }
1195
1196 /* This order won't be selected any more, close all child windows and dropdowns */
1197 this->CloseChildWindows();
1198
1199 if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
1200 /* Deselect clicked order */
1201 this->selected_order = -1;
1202 } else if (sel == this->selected_order && click_count > 1) {
1203 if (this->vehicle->type == VehicleType::Train && sel < this->vehicle->GetNumOrders() && this->vehicle->GetOrder(sel)->GetType() == OT_GOTO_STATION) {
1204 Command<Commands::ModifyOrder>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER,
1205 this->vehicle->tile, this->vehicle->index, sel,
1207 }
1208 } else {
1209 /* Select clicked order */
1210 this->selected_order = sel;
1211
1212 if (this->vehicle->owner == _local_company) {
1213 /* Activate drag and drop */
1215 }
1216 }
1217
1218 this->UpdateButtonState();
1219 break;
1220 }
1221
1222 case WID_O_SKIP:
1223 this->OrderClick_Skip();
1224 break;
1225
1226 case WID_O_DELETE:
1227 this->OrderClick_Delete();
1228 break;
1229
1230 case WID_O_STOP_SHARING:
1231 this->OrderClick_StopSharing();
1232 break;
1233
1234 case WID_O_NON_STOP:
1235 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1236 this->OrderClick_Nonstop(std::nullopt);
1237 } else {
1238 const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1239 assert(o != nullptr);
1240 ShowDropDownMenu(this, _order_non_stop_dropdown, o->GetNonStopType().base(), WID_O_NON_STOP, 0,
1241 o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
1242 }
1243 break;
1244
1245 case WID_O_GOTO:
1246 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1247 if (this->goto_type != OPOS_NONE) {
1249 } else {
1250 this->OrderClick_Goto(OPOS_GOTO);
1251 }
1252 } else {
1253 int sel;
1254 switch (this->goto_type) {
1255 case OPOS_NONE: sel = -1; break;
1256 case OPOS_GOTO: sel = 0; break;
1257 case OPOS_CONDITIONAL: sel = 2; break;
1258 case OPOS_SHARE: sel = 3; break;
1259 default: NOT_REACHED();
1260 }
1261 ShowDropDownMenu(this, this->vehicle->type == VehicleType::Aircraft ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
1262 }
1263 break;
1264
1265 case WID_O_FULL_LOAD:
1266 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1268 } else {
1269 ShowDropDownMenu(this, _order_full_load_dropdown, to_underlying(this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType()), WID_O_FULL_LOAD, 0, 2);
1270 }
1271 break;
1272
1273 case WID_O_UNLOAD:
1274 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1276 } else {
1277 ShowDropDownMenu(this, _order_unload_dropdown, to_underlying(this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType()), WID_O_UNLOAD, 0, 8);
1278 }
1279 break;
1280
1281 case WID_O_REFIT:
1282 this->OrderClick_Refit(0, false);
1283 break;
1284
1285 case WID_O_DEPOT_ACTION:
1286 ShowDropDownMenu(this, _order_depot_action_dropdown, to_underlying(DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel()))), WID_O_DEPOT_ACTION, 0, 0);
1287 break;
1288
1290 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1291 this->OrderClick_Refit(0, true);
1292 } else {
1293 ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
1294 }
1295 break;
1296
1298 ShowTimetableWindow(this->vehicle);
1299 break;
1300
1301 case WID_O_COND_VARIABLE: {
1302 DropDownList list;
1303 for (const auto &ocv : _order_conditional_variable) {
1304 if (ocv == OrderConditionVariable::DrivingBackwards && this->vehicle->type != VehicleType::Train) continue;
1305 list.push_back(MakeDropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + to_underlying(ocv), to_underlying(ocv)));
1306 }
1307 ShowDropDownList(this, std::move(list), to_underlying(this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable()), WID_O_COND_VARIABLE);
1308 break;
1309 }
1310
1311 case WID_O_COND_COMPARATOR: {
1312 const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1313 assert(o != nullptr);
1315 break;
1316 }
1317
1318 case WID_O_COND_VALUE: {
1319 const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
1320 assert(order != nullptr);
1321 uint value = order->GetConditionValue();
1322 if (order->GetConditionVariable() == OrderConditionVariable::MaxSpeed) value = ConvertSpeedToDisplaySpeed(value, this->vehicle->type);
1323 ShowQueryString(GetString(STR_JUST_INT, value), STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, {});
1324 break;
1325 }
1326
1328 ShowVehicleListWindow(this->vehicle);
1329 break;
1330 }
1331 }
1332
1333 void OnQueryTextFinished(std::optional<std::string> str) override
1334 {
1335 if (!str.has_value() || str->empty()) return;
1336
1337 VehicleOrderID sel = this->OrderGetSel();
1338 auto value = ParseInteger(*str, 10, true);
1339 if (!value.has_value()) return;
1340
1341 switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
1343 value = ConvertDisplaySpeedToSpeed(*value, this->vehicle->type);
1344 break;
1345
1349 value = Clamp(*value, 0, 100);
1350 break;
1351
1352 default:
1353 break;
1354 }
1355 Command<Commands::ModifyOrder>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel, MOF_COND_VALUE, Clamp(*value, 0, 2047));
1356 }
1357
1358 void OnDropdownSelect(WidgetID widget, int index, int) override
1359 {
1360 switch (widget) {
1361 case WID_O_NON_STOP:
1362 this->OrderClick_Nonstop(static_cast<OrderNonStopFlags>(index));
1363 break;
1364
1365 case WID_O_FULL_LOAD:
1366 this->OrderClick_FullLoad(static_cast<OrderLoadType>(index));
1367 break;
1368
1369 case WID_O_UNLOAD:
1370 this->OrderClick_Unload(static_cast<OrderUnloadType>(index));
1371 break;
1372
1373 case WID_O_GOTO:
1374 switch (index) {
1375 case 0: this->OrderClick_Goto(OPOS_GOTO); break;
1376 case 1: this->OrderClick_NearestDepot(); break;
1377 case 2: this->OrderClick_Goto(OPOS_CONDITIONAL); break;
1378 case 3: this->OrderClick_Goto(OPOS_SHARE); break;
1379 default: NOT_REACHED();
1380 }
1381 break;
1382
1383 case WID_O_DEPOT_ACTION:
1384 this->OrderClick_Service(static_cast<OrderDepotAction>(index));
1385 break;
1386
1388 this->OrderClick_Refit(index, true);
1389 break;
1390
1392 Command<Commands::ModifyOrder>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), MOF_COND_VARIABLE, index);
1393 break;
1394
1396 Command<Commands::ModifyOrder>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), MOF_COND_COMPARATOR, index);
1397 break;
1398 }
1399 }
1400
1401 void OnDragDrop(Point pt, WidgetID widget) override
1402 {
1403 switch (widget) {
1404 case WID_O_ORDER_LIST: {
1405 VehicleOrderID from_order = this->OrderGetSel();
1406 VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1407
1408 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()) &&
1409 Command<Commands::MoveOrder>::Post(STR_ERROR_CAN_T_MOVE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, from_order, to_order)) {
1410 this->selected_order = -1;
1411 this->UpdateButtonState();
1412 }
1413 break;
1414 }
1415
1416 case WID_O_DELETE:
1417 this->OrderClick_Delete();
1418 break;
1419
1420 case WID_O_STOP_SHARING:
1421 this->OrderClick_StopSharing();
1422 break;
1423 }
1424
1426
1427 if (this->order_over != INVALID_VEH_ORDER_ID) {
1428 /* End of drag-and-drop, hide dragged order destination highlight. */
1429 this->order_over = INVALID_VEH_ORDER_ID;
1431 }
1432 }
1433
1434 EventState OnHotkey(int hotkey) override
1435 {
1436 if (this->vehicle->owner != _local_company) return EventState::NotHandled;
1437
1438 switch (hotkey) {
1439 case OHK_SKIP: this->OrderClick_Skip(); break;
1440 case OHK_DELETE: this->OrderClick_Delete(); break;
1441 case OHK_GOTO: this->OrderClick_Goto(OPOS_GOTO); break;
1442 case OHK_NONSTOP: this->OrderClick_Nonstop(std::nullopt); break;
1443 case OHK_FULLLOAD: this->OrderClick_FullLoad(OrderLoadType::FullLoadAny, true); break;
1444 case OHK_UNLOAD: this->OrderClick_Unload(OrderUnloadType::Unload, true); break;
1445 case OHK_NEAREST_DEPOT: this->OrderClick_NearestDepot(); break;
1446 case OHK_ALWAYS_SERVICE: this->OrderClick_Service(std::nullopt); break;
1447 case OHK_TRANSFER: this->OrderClick_Unload(OrderUnloadType::Transfer, true); break;
1448 case OHK_NO_UNLOAD: this->OrderClick_Unload(OrderUnloadType::NoUnload, true); break;
1449 case OHK_NO_LOAD: this->OrderClick_FullLoad(OrderLoadType::NoLoad, true); break;
1450 default: return EventState::NotHandled;
1451 }
1452 return EventState::Handled;
1453 }
1454
1455 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
1456 {
1457 if (this->goto_type == OPOS_GOTO) {
1458 const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
1459 if (cmd.IsType(OT_NOTHING)) return;
1460
1461 if (Command<Commands::InsertOrder>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), cmd)) {
1462 /* With quick goto the Go To button stays active */
1463 if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
1464 }
1465 }
1466 }
1467
1468 bool OnVehicleSelect(const Vehicle *v) override
1469 {
1470 /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
1471 * We disallow copying orders of other vehicles if we already have at least one order entry
1472 * ourself as it easily copies orders of vehicles within a station when we mean the station.
1473 * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
1474 * TODO: give a warning message */
1475 bool share_order = IsCtrlPressed() || this->goto_type == OPOS_SHARE;
1476 if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
1477
1478 if (Command<Commands::CloneOrder>::Post(share_order ? STR_ERROR_CAN_T_SHARE_ORDER_LIST : STR_ERROR_CAN_T_COPY_ORDER_LIST,
1479 this->vehicle->tile, share_order ? CO_SHARE : CO_COPY, this->vehicle->index, v->index)) {
1480 this->selected_order = -1;
1482 }
1483 return true;
1484 }
1485
1494 bool OnVehicleSelect(VehicleList::const_iterator begin, VehicleList::const_iterator end) override
1495 {
1496 bool share_order = IsCtrlPressed() || this->goto_type == OPOS_SHARE;
1497 if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
1498
1499 if (!share_order) {
1500 /* If CTRL is not pressed: If all the vehicles in this list have the same orders, then copy orders */
1501 if (AllEqual(begin, end, VehiclesHaveSameOrderList)) {
1502 OnVehicleSelect(*begin);
1503 } else {
1504 ShowErrorMessage(GetEncodedString(STR_ERROR_CAN_T_COPY_ORDER_LIST), GetEncodedString(STR_ERROR_CAN_T_COPY_ORDER_VEHICLE_LIST), WarningLevel::Info);
1505 }
1506 } else {
1507 /* If CTRL is pressed: If all the vehicles in this list share orders, then copy orders */
1508 if (AllEqual(begin, end, VehiclesHaveSameSharedOrderList)) {
1509 OnVehicleSelect(*begin);
1510 } else {
1511 ShowErrorMessage(GetEncodedString(STR_ERROR_CAN_T_SHARE_ORDER_LIST), GetEncodedString(STR_ERROR_CAN_T_SHARE_ORDER_VEHICLE_LIST), WarningLevel::Info);
1512 }
1513 }
1514
1515 return true;
1516 }
1517
1518 void OnPlaceObjectAbort() override
1519 {
1520 this->goto_type = OPOS_NONE;
1522
1523 /* Remove drag highlighting if it exists. */
1524 if (this->order_over != INVALID_VEH_ORDER_ID) {
1525 this->order_over = INVALID_VEH_ORDER_ID;
1527 }
1528 }
1529
1530 void OnMouseDrag(Point pt, WidgetID widget) override
1531 {
1532 if (this->selected_order != -1 && widget == WID_O_ORDER_LIST) {
1533 /* An order is dragged.. */
1534 VehicleOrderID from_order = this->OrderGetSel();
1535 VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1536 uint num_orders = this->vehicle->GetNumOrders();
1537
1538 if (from_order != INVALID_VEH_ORDER_ID && from_order <= num_orders) {
1539 if (to_order != INVALID_VEH_ORDER_ID && to_order <= num_orders) { // ..over an existing order.
1540 this->order_over = to_order;
1541 this->SetWidgetDirty(widget);
1542 } else if (from_order != to_order && this->order_over != INVALID_VEH_ORDER_ID) { // ..outside of the order list.
1543 this->order_over = INVALID_VEH_ORDER_ID;
1544 this->SetWidgetDirty(widget);
1545 }
1546 }
1547 }
1548 }
1549
1550 void OnResize() override
1551 {
1552 /* Update the scroll bar */
1553 this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST, WidgetDimensions::scaled.framerect.Vertical());
1554 }
1555
1556 static inline HotkeyList hotkeys{"order", {
1557 Hotkey('D', "skip", OHK_SKIP),
1558 Hotkey('F', "delete", OHK_DELETE),
1559 Hotkey('G', "goto", OHK_GOTO),
1560 Hotkey('H', "nonstop", OHK_NONSTOP),
1561 Hotkey('J', "fullload", OHK_FULLLOAD),
1562 Hotkey('K', "unload", OHK_UNLOAD),
1563 Hotkey(0, "nearest_depot", OHK_NEAREST_DEPOT),
1564 Hotkey(0, "always_service", OHK_ALWAYS_SERVICE),
1565 Hotkey(0, "transfer", OHK_TRANSFER),
1566 Hotkey(0, "no_unload", OHK_NO_UNLOAD),
1567 Hotkey(0, "no_load", OHK_NO_LOAD),
1568 }};
1569};
1570
1572static constexpr std::initializer_list<NWidgetPart> _nested_orders_train_widgets = {
1576 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_O_TIMETABLE_VIEW), SetStringTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1580 EndContainer(),
1583 EndContainer(),
1585 EndContainer(),
1586
1587 /* First button row. */
1592 SetStringTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
1595 SetStringTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1597 SetStringTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1598 EndContainer(),
1601 SetStringTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1603 SetStringTip(STR_JUST_STRING), SetResize(1, 0),
1604 EndContainer(),
1607 EndContainer(),
1609 SetStringTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1610 EndContainer(),
1611 EndContainer(),
1614 SetToolTip(STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1616 SetToolTip(STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1618 SetToolTip(STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1619 EndContainer(),
1620 EndContainer(),
1621 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_O_SHARED_ORDER_LIST), SetAspect(1), SetSpriteTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
1622 EndContainer(),
1623
1624 /* Second button row. */
1628 SetStringTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1631 SetStringTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1633 SetStringTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1634 EndContainer(),
1636 SetStringTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1637 EndContainer(),
1639 EndContainer(),
1640};
1641
1644 WindowPosition::Automatic, "view_vehicle_orders_train", 384, 100,
1645 WindowClass::VehicleOrders, WindowClass::VehicleView,
1648 &OrdersWindow::hotkeys
1649);
1650
1652static constexpr std::initializer_list<NWidgetPart> _nested_orders_widgets = {
1655 NWidget(WWT_CAPTION, Colours::Grey, WID_O_CAPTION), SetStringTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1656 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_O_TIMETABLE_VIEW), SetStringTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1660 EndContainer(),
1663 EndContainer(),
1665 EndContainer(),
1666
1667 /* First button row. */
1670 /* Load + unload + refit buttons. */
1673 SetStringTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1675 SetStringTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1677 SetStringTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1678 EndContainer(),
1679 /* Refit + service buttons. */
1682 SetStringTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1684 SetResize(1, 0),
1685 EndContainer(),
1686
1687 /* Buttons for setting a condition. */
1690 SetToolTip(STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1692 SetToolTip(STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1694 SetStringTip(STR_JUST_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1695 EndContainer(),
1696 EndContainer(),
1697
1698 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_O_SHARED_ORDER_LIST), SetAspect(1), SetSpriteTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
1699 EndContainer(),
1700
1701 /* Second button row. */
1704 SetStringTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1707 SetStringTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1709 SetStringTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1710 EndContainer(),
1712 SetStringTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1714 EndContainer(),
1715};
1716
1719 WindowPosition::Automatic, "view_vehicle_orders", 384, 100,
1720 WindowClass::VehicleOrders, WindowClass::VehicleView,
1723 &OrdersWindow::hotkeys
1724);
1725
1727static constexpr std::initializer_list<NWidgetPart> _nested_other_orders_widgets = {
1730 NWidget(WWT_CAPTION, Colours::Grey, WID_O_CAPTION), SetStringTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1731 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_O_TIMETABLE_VIEW), SetStringTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1735 EndContainer(),
1738 EndContainer(),
1742 EndContainer(),
1743 EndContainer(),
1744};
1745
1748 WindowPosition::Automatic, "view_vehicle_orders_competitor", 384, 86,
1749 WindowClass::VehicleOrders, WindowClass::VehicleView,
1752 &OrdersWindow::hotkeys
1753);
1754
1755void ShowOrdersWindow(const Vehicle *v)
1756{
1757 CloseWindowById(WindowClass::VehicleDetails, v->index, false);
1758 CloseWindowById(WindowClass::VehicleTimetable, v->index, false);
1759 if (BringWindowToFrontById(WindowClass::VehicleOrders, v->index) != nullptr) return;
1760
1761 /* Using a different WindowDescs for _local_company causes problems.
1762 * Due to this we have to close order windows in ChangeWindowOwner/CloseCompanyWindows,
1763 * because we cannot change switch the WindowDescs and keeping the old WindowDesc results
1764 * in crashed due to missing widget.
1765 * TODO Rewrite the order GUI to not use different WindowDescs.
1766 */
1767 if (v->owner != _local_company) {
1769 } else {
1771 }
1772}
Base for aircraft.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
static constexpr CargoType CARGO_AUTO_REFIT
Automatically choose cargo type when doing auto refitting.
Definition cargo_type.h:80
static constexpr CargoType CARGO_NO_REFIT
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-renew).
Definition cargo_type.h:81
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
constexpr Timpl & Flip()
Flip all bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Base class for a 'real' widget.
void SetStringTip(StringID string, StringID tool_tip)
Set string and tool tip of the nested widget.
Definition widget.cpp:1200
Stacked widgets, widgets all occupying the same space in the window.
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition widget.cpp:1458
Scrollbar data structure.
bool IsVisible(size_type item) const
Checks whether given current item is visible in the list.
void SetCount(size_t num)
Sets the number of elements in the list.
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:2474
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:2548
void ScrollTowards(size_type position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
size_type GetPosition() const
Gets the position of the first visible element in the list.
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
Functions related to commands.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Command definitions related to companies.
Functions related to companies.
static constexpr Owner OWNER_NONE
The tile has no ownership.
Map related accessors for depots.
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:22
DestinationID GetDepotDestinationIndex(Tile t)
Get the destination index of a 'depot'.
Definition depot_map.h:69
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a dropdown menu window near a widget of the parent window.
Definition dropdown.cpp:633
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Definition dropdown.cpp:591
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Definition engine.cpp:1327
Base class for engines.
Functions related to engines.
@ AutoRefit
Automatic refitting is allowed.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
Functions related to errors.
@ Info
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition error.h:22
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
@ ForceRight
Force align to the right.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:966
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
Definition gfx.cpp:933
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:1032
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:111
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:663
bool IsCtrlPressed()
Test if the ctrl key is pressed.
Definition gfx_func.h:82
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Grey
Grey.
Definition gfx_type.h:299
@ NoShade
Do not add shading to this text colour.
Definition gfx_type.h:342
@ White
White colour.
Definition gfx_type.h:330
@ Grey
Grey colour.
Definition gfx_type.h:332
@ Black
Black colour.
Definition gfx_type.h:334
@ Silver
Silver colour.
Definition gfx_type.h:319
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
static const CursorID ANIMCURSOR_PICKSTATION
716 - 718 - goto-order icon
Definition sprites.h:1697
static const CursorID SPR_CURSOR_MOUSE
Definition sprites.h:1568
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:1013
Hotkey related functions.
Base of all industries.
#define Point
Macro that prevents name conflicts between included headers.
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.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
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.
bool _networking
are we in networking mode?
Definition network.cpp:63
Basic functions/variables used all over the place.
@ Order
Something wrong with the order, e.g. invalid or duplicate entries, too few entries.
Definition news_type.h:57
uint GetOrderDistance(VehicleOrderID prev, VehicleOrderID cur, const Vehicle *v, int conditional_depth)
Get the distance between two orders of a vehicle.
Command definitions related to orders.
static constexpr std::initializer_list< NWidgetPart > _nested_orders_widgets
Nested widget definition for "your" orders (non-train).
static constexpr std::initializer_list< NWidgetPart > _nested_other_orders_widgets
Nested widget definition for competitor orders.
uint ConvertSpeedToDisplaySpeed(uint speed, VehicleType type)
Convert the given (internal) speed to the display speed.
Definition strings.cpp:964
static WindowDesc _orders_train_desc(WindowPosition::Automatic, "view_vehicle_orders_train", 384, 100, WindowClass::VehicleOrders, WindowClass::VehicleView, WindowDefaultFlag::Construction, _nested_orders_train_widgets, &OrdersWindow::hotkeys)
Window definition for the train orders window.
static WindowDesc _other_orders_desc(WindowPosition::Automatic, "view_vehicle_orders_competitor", 384, 86, WindowClass::VehicleOrders, WindowClass::VehicleView, WindowDefaultFlag::Construction, _nested_other_orders_widgets, &OrdersWindow::hotkeys)
Window definition for the orders window for other companies.
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
Get the order command a vehicle can do in a given tile.
static const OrderConditionVariable _order_conditional_variable[]
Variables for conditional orders; this defines the order of appearance in the dropdown box.
OrderHotKeys
Hotkeys for order window.
static const StringID _station_load_types[][5][5]
Order load types that could be given to station orders.
Definition order_gui.cpp:46
static constexpr std::initializer_list< NWidgetPart > _nested_orders_train_widgets
Nested widget definition for "your" train orders.
static WindowDesc _orders_desc(WindowPosition::Automatic, "view_vehicle_orders", 384, 100, WindowClass::VehicleOrders, WindowClass::VehicleView, WindowDefaultFlag::Construction, _nested_orders_widgets, &OrdersWindow::hotkeys)
Window definition for the orders window for road vehicles, ships and aircraft.
uint ConvertDisplaySpeedToSpeed(uint speed, VehicleType type)
Convert the given display speed to the (internal) speed.
Definition strings.cpp:978
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.
OrderUnloadType
Unloading order types.
Definition order_type.h:67
@ Transfer
Transfer all cargo onto the platform.
Definition order_type.h:70
@ UnloadIfPossible
Unload all cargo that the station accepts.
Definition order_type.h:68
@ NoUnload
Totally no unloading will be done.
Definition order_type.h:71
@ Unload
Force unloading all cargo onto the platform, possibly not getting paid.
Definition order_type.h:69
OrderConditionVariable
Variables (of a vehicle) to 'cause' skipping on.
Definition order_type.h:131
@ Unconditionally
Always skip.
Definition order_type.h:137
@ MaxSpeed
Skip based on the maximum speed.
Definition order_type.h:134
@ Reliability
Skip based on the reliability.
Definition order_type.h:133
@ MaxReliability
Skip based on the maximum reliability.
Definition order_type.h:139
@ RequiresService
Skip when the vehicle requires service.
Definition order_type.h:136
@ LoadPercentage
Skip based on the amount of load.
Definition order_type.h:132
@ Age
Skip based on the age.
Definition order_type.h:135
@ DrivingBackwards
Skip when the train is driving backwards.
Definition order_type.h:140
@ RemainingLifetime
Skip based on the remaining lifetime.
Definition order_type.h:138
OrderStopLocation
Where to stop the trains.
Definition order_type.h:98
@ End
End marker.
Definition order_type.h:102
@ FarEnd
Stop at the far end of the platform.
Definition order_type.h:101
@ MOF_COND_VARIABLE
A conditional variable changes.
Definition order_type.h:169
@ MOF_LOAD
Passes an OrderLoadType.
Definition order_type.h:167
@ MOF_UNLOAD
Passes an OrderUnloadType.
Definition order_type.h:166
@ MOF_STOP_LOCATION
Passes an OrderStopLocation.
Definition order_type.h:165
@ MOF_COND_COMPARATOR
A comparator changes.
Definition order_type.h:170
@ MOF_COND_VALUE
The value to set the condition to.
Definition order_type.h:171
@ MOF_DEPOT_ACTION
Selects the OrderDepotAction.
Definition order_type.h:168
@ MOF_NON_STOP
Passes an OrderNonStopFlags.
Definition order_type.h:164
OrderDepotAction
Depot action to switch to when doing a MOF_DEPOT_ACTION.
Definition order_type.h:179
@ Stop
Go to the depot and stop there.
Definition order_type.h:182
@ AlwaysGo
Always go to the depot.
Definition order_type.h:180
@ Service
Service only if needed.
Definition order_type.h:181
@ Unbunch
Go to the depot and unbunch.
Definition order_type.h:183
EnumBitSet< OrderNonStopFlag, uint8_t > OrderNonStopFlags
Bitset of OrderNonStopFlag elements.
Definition order_type.h:93
@ NonStop
The vehicle will not stop at any stations it passes except the destination, aka non-stop.
Definition order_type.h:88
@ GoVia
The vehicle will stop at any station it passes except the destination, aka via.
Definition order_type.h:89
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related).
Definition order_type.h:18
OrderLoadType
Loading order types.
Definition order_type.h:77
@ NoLoad
Do not load anything.
Definition order_type.h:81
@ FullLoadAny
Full load a single cargo of the consist.
Definition order_type.h:80
@ LoadIfPossible
Load as long as there is cargo that fits in the train.
Definition order_type.h:78
@ Halt
Service the vehicle and then halt it.
Definition order_type.h:120
@ NearestDepot
Send the vehicle to the nearest depot.
Definition order_type.h:121
@ Unbunch
Service the vehicle and then unbunch it.
Definition order_type.h:122
@ PartOfOrders
This depot order is because of a regular order.
Definition order_type.h:110
@ Service
This depot order is because of the servicing limit.
Definition order_type.h:109
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel).
Definition order_type.h:39
OrderConditionComparator
Comparator for the skip reasoning.
Definition order_type.h:147
@ IsTrue
Skip if the variable is true.
Definition order_type.h:154
@ IsFalse
Skip if the variable is false.
Definition order_type.h:155
Types related to the order widgets.
@ WID_O_TIMETABLE_VIEW
Toggle timetable view.
@ WID_O_SHARED_ORDER_LIST
Open list of shared vehicles.
@ WID_O_SKIP
Skip current order.
@ WID_O_SCROLLBAR
Order list scrollbar.
@ WID_O_SEL_TOP_MIDDLE
NWID_SELECTION widget for middle part of the top row of the 'your train' order window.
@ WID_O_SEL_BOTTOM_MIDDLE
NWID_SELECTION widget for the middle part of the bottom row of the 'your train' order window.
@ WID_O_REFIT
Select refit.
@ WID_O_ORDER_LIST
Order list panel.
@ WID_O_COND_VARIABLE
Choose condition variable.
@ WID_O_SEL_TOP_ROW
NWID_SELECTION widget for the top row of the 'your non-trains' order window.
@ WID_O_DELETE
Delete selected order.
@ WID_O_STOP_SHARING
Stop sharing orders.
@ WID_O_COND_COMPARATOR
Choose condition type.
@ WID_O_CAPTION
Caption of the window.
@ WID_O_UNLOAD
Select unload.
@ WID_O_SEL_TOP_LEFT
NWID_SELECTION widget for left part of the top row of the 'your train' order window.
@ WID_O_DEPOT_ACTION
Dropdown to select the depot action (stop, service if needed, unbunch).
@ WID_O_REFIT_DROPDOWN
Open refit options.
@ WID_O_SEL_TOP_RIGHT
NWID_SELECTION widget for right part of the top row of the 'your train' order window.
@ WID_O_NON_STOP
Goto non-stop to destination.
@ WID_O_COND_VALUE
Choose condition value.
@ WID_O_FULL_LOAD
Select full load.
@ WID_O_SEL_TOP_ROW_GROUNDVEHICLE
NWID_SELECTION widget for the top row of the 'your train' order window.
@ WID_O_GOTO
Goto destination.
PixelColour GetColourGradient(Colours colour, Shade shade)
Get colour gradient palette index.
Definition palette.cpp:393
@ Lightest
Lightest colour shade.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
static const SpriteID SPR_ARROW_RIGHT
Definition sprites.h:88
static const SpriteID SPR_ARROW_LEFT
Definition sprites.h:87
Base classes/functions for stations.
bool IsRailWaypointTile(Tile t)
Is this tile a station tile and a rail waypoint?
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition station_map.h:26
bool IsRoadWaypointTile(Tile t)
Is this tile a station tile and a road waypoint?
bool IsBuoyTile(Tile t)
Is tile t a buoy tile?
@ Dock
Station with a dock.
@ TruckStop
Station with truck stops.
@ Train
Station with train station.
@ Airport
Station with an airport.
@ BusStop
Station with bus stops.
EnumBitSet< StationFacility, uint8_t > StationFacilities
Bitset of StationFacility elements.
Definition of base types and functions in a cross-platform compatible way.
Parse strings.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
@ CS_NUMERAL
Only numeric ones.
Definition string_type.h:26
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:235
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:89
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:423
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:55
Functions related to OTTD's strings.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
static constexpr StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames).
@ TD_RTL
Text is written right-to-left by default.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
StationFacilities facilities
The facilities that this station has.
Owner owner
The owner of this station.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
VehicleType type
Type of vehicle.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
Definition cargotype.h:140
GUISettings gui
settings related to the GUI
T y
Y coordinate.
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
Container for the text colour and some text colour related flags for drawing.
Definition gfx_type.h:349
bool quick_goto
Allow quick access to 'goto button' in vehicle orders window.
List of hotkeys for a window.
Definition hotkeys.h:44
All data for a single hotkey.
Definition hotkeys.h:20
Defines the internal data of a functional industry.
Definition industry.h:64
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition industry.h:253
Station * neutral_station
Associated neutral station.
Definition industry.h:110
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:472
If you change this, keep in mind that it is also saved in 2 other places:
Definition order_base.h:33
TileIndex GetLocation(const Vehicle *v, bool airport=false) const
Returns a tile somewhat representing the order destination (not suitable for pathfinding).
bool IsGotoOrder() const
Is this a 'goto' order with a real destination?
Definition order_base.h:89
OrderDepotTypeFlags GetDepotOrderType() const
What caused us going to the depot?
Definition order_base.h:169
OrderConditionVariable GetConditionVariable() const
What variable do we have to compare?
Definition order_base.h:181
DestinationID GetDestination() const
Gets the destination of this order.
Definition order_base.h:99
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition order_base.h:66
void SetNonStopType(OrderNonStopFlags non_stop_type)
Set whether we must stop at stations or not.
Definition order_base.h:217
VehicleOrderID GetConditionSkipToOrder() const
Get the order to skip to.
Definition order_base.h:193
OrderStopLocation GetStopLocation() const
Where must we stop at the platform?
Definition order_base.h:163
uint16_t GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
Definition order_base.h:293
CargoType GetRefitCargo() const
Get the cargo to to refit to.
Definition order_base.h:127
OrderType GetType() const
Get the type of order of this order.
Definition order_base.h:72
void MakeGoToStation(StationID destination)
Makes this order a Go To Station order.
Definition order_cmd.cpp:59
void SetStopLocation(OrderStopLocation stop_location)
Set where we must stop at the platform.
Definition order_base.h:223
void MakeGoToWaypoint(StationID destination)
Makes this order a Go To Waypoint order.
Definition order_cmd.cpp:88
OrderUnloadType GetUnloadType() const
How must the consist be unloaded?
Definition order_base.h:151
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Definition order_base.h:270
void MakeConditional(VehicleOrderID order)
Makes this order an conditional order.
void SetDepotActionType(OrderDepotActionFlags depot_service_type)
Set what we are going to do in the depot.
Definition order_base.h:235
OrderLoadType GetLoadType() const
How must the consist be loaded?
Definition order_base.h:145
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
Definition order_base.h:175
void Free()
'Free' the order
Definition order_cmd.cpp:48
void SetLoadType(OrderLoadType load_type)
Set how the consist must be loaded.
Definition order_base.h:205
bool IsAutoRefit() const
Is this order a auto-refit order.
Definition order_base.h:120
void MakeGoToDepot(DestinationID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=OrderNonStopFlag::NonStop, OrderDepotActionFlags action={}, CargoType cargo=CARGO_NO_REFIT)
Makes this order a Go To Depot order.
Definition order_cmd.cpp:74
OrderConditionComparator GetConditionComparator() const
What is the comparator to use?
Definition order_base.h:187
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition order_base.h:157
bool IsRefit() const
Is this order a refit order.
Definition order_base.h:113
uint16_t GetConditionValue() const
Get the value to base the skip on.
Definition order_base.h:199
Order window code for all vehicles.
void OrderClick_Refit(int i, bool auto_refit)
Handle the click on the refit button.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void OrderClick_Delete()
Handle the click on the delete button.
void OnResize() override
Called after the window got resized.
void OrderClick_Skip()
Handle the click on the skip button.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
bool OnVehicleSelect(VehicleList::const_iterator begin, VehicleList::const_iterator end) override
Clones an order list from a vehicle list.
void OrderClick_FullLoad(OrderLoadType load_type, bool toggle=false)
Handle the click on the full load button.
const Vehicle * vehicle
Vehicle owning the orders being displayed and manipulated.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
bool can_do_refit
Vehicle chain can be refitted in depot.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
DisplayPane
Displayed planes of the NWID_SELECTION widgets.
@ DP_BOTTOM_MIDDLE_DELETE
Display 'delete' in the middle button of the bottom row of the vehicle order window.
@ DP_ROW_CONDITIONAL
Display the conditional order buttons in the top row of the ship/airplane order window.
@ DP_ROW_DEPOT
Display 'refit' / 'service' buttons in the top row of the ship/airplane order window.
@ DP_BOTTOM_MIDDLE_STOP_SHARING
Display 'stop sharing' in the middle button of the bottom row of the vehicle order window.
@ DP_MIDDLE_UNLOAD
Display 'unload' in the middle button of the top row of the train/rv order window.
@ DP_LEFT_LOAD
Display 'load' in the left button of the top row of the train/rv order window.
@ DP_RIGHT_EMPTY
Display an empty panel in the right button of the top row of the train/rv order window.
@ DP_RIGHT_REFIT
Display 'refit' in the right button of the top row of the train/rv order window.
@ DP_ROW_LOAD
Display 'load' / 'unload' / 'refit' buttons in the top row of the ship/airplane order window.
@ DP_MIDDLE_SERVICE
Display 'service' in the middle button of the top row of the train/rv order window.
@ DP_GROUNDVEHICLE_ROW_CONDITIONAL
Display the row for conditional orders in the top row of the train/rv order window.
@ DP_LEFT_REFIT
Display 'refit' in the left button of the top row of the train/rv order window.
@ DP_GROUNDVEHICLE_ROW_NORMAL
Display the row for normal/depot orders in the top row of the train/rv order window.
void OrderClick_NearestDepot()
Handle the click on the service in nearest depot button.
void OrderClick_StopSharing()
Handle the click on the 'stop sharing' button.
VehicleOrderID OrderGetSel() const
Return the memorised selected order.
void UpdateAutoRefitState()
Cache auto-refittability of the vehicle chain.
void OnPaint() override
The window must be repainted.
void OnDragDrop(Point pt, WidgetID widget) override
A dragged 'object' has been released.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnMouseDrag(Point pt, WidgetID widget) override
An 'object' is being dragged at the provided position, highlight the target if possible.
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.
OrderPlaceObjectState
Under what reason are we using the PlaceObject functionality?
void OrderClick_Unload(OrderUnloadType unload_type, bool toggle=false)
Handle the click on the unload button.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
VehicleOrderID GetOrderFromPt(int y)
Calculate the selected order.
void OrderClick_Service(std::optional< OrderDepotAction > i)
Handle the click on the service.
bool can_do_autorefit
Vehicle chain can be auto-refitted.
void OrderClick_Nonstop(std::optional< OrderNonStopFlags > non_stop)
Handle the click on the nonstop button.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OrderClick_Goto(OrderPlaceObjectState type)
Handle the click on the goto button.
VehicleOrderID order_over
Order over which another order is dragged, INVALID_VEH_ORDER_ID if none.
static Engine * Get(auto index)
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
static Station * Get(auto index)
Station data structure.
Vehicle data structure.
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
OrderList * orders
Pointer to the order list for this vehicle.
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
TileIndex tile
Current tile index.
Owner owner
Which company owns the vehicle?
High level window description.
Definition window_gui.h:171
Data structure for an opened window.
Definition window_gui.h:272
void CloseChildWindows(WindowClass wc=WindowClass::Invalid) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1122
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1855
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:468
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:565
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:513
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:390
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1845
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:315
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:440
void EnableWidget(WidgetID widget_index)
Sets a widget to Enabled.
Definition window_gui.h:399
int top
y position of top edge of the window
Definition window_gui.h:309
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:322
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:380
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:301
Stuff related to the text buffer GUI.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
bool IsTileOwner(Tile tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition tile_map.h:214
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
@ Station
A tile of a station or airport.
Definition tile_type.h:54
@ Industry
Part of an industry.
Definition tile_type.h:57
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
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...
HighLightStyle
Highlighting draw styles.
@ HT_DRAG
dragging items in the depot windows
@ HT_NONE
default
@ HT_RECT
rectangle (stations, depots, ...)
@ HT_VEHICLE
vehicle is accepted as target as well (bitmask)
Functions related to time tabling.
void ShowTimetableWindow(const Vehicle *v)
Show the timetable for a given vehicle.
std::pair< StringParameter, StringParameter > GetTimetableParameters(TimerGameTick::Ticks ticks)
Get parameters to format timetable time.
TransportType
Available types of transport.
bool VehiclesHaveSameOrderList(const Vehicle *v1, const Vehicle *v2)
Checks if two vehicles have the same list of orders.
Definition vehicle.cpp:3346
bool VehiclesHaveSameSharedOrderList(const Vehicle *v1, const Vehicle *v2)
Checks if two vehicles have the same shared list of orders.
Definition vehicle.cpp:3357
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Definition vehicle.cpp:3115
Functions related to vehicles.
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
Show the refit window for a vehicle.
Functions related to the vehicle's GUIs.
@ VIWD_CONSIST_CHANGED
Vehicle composition was changed.
Definition vehicle_gui.h:36
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
Definition vehicle_gui.h:37
@ VIWD_MODIFY_ORDERS
Other order modifications.
Definition vehicle_gui.h:35
@ VIWD_REMOVE_ALL_ORDERS
Removed / replaced all orders (after deleting / sharing).
Definition vehicle_gui.h:34
VehicleType
Available vehicle types.
@ Ship
Ship vehicle type.
@ Aircraft
Aircraft vehicle type.
@ Road
Road vehicle type.
@ Train
Train vehicle type.
Functions and type for generating vehicle lists.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition widget_type.h:74
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX).
Definition widget_type.h:57
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX).
Definition widget_type.h:55
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window).
Definition widget_type.h:59
@ 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
Drop down list.
Definition widget_type.h:61
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
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:1242
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1326
Window functions not directly related to making/drawing windows.
@ Construction
This window is used for construction; close it whenever changing company.
Definition window_gui.h:154
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:972
@ Automatic
Find a place automatically.
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:21
EventState
State of handling an event.
@ Handled
The passed event is handled.
@ NotHandled
The passed event is not handled.