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