4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have/// received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file order_gui.cpp GUI related to orders. */
13 #include "command_func.h"
14 #include "viewport_func.h"
15 #include "depot_map.h"
17 #include "timetable.h"
18 #include "strings_func.h"
19 #include "company_func.h"
20 #include "widgets/dropdown_type.h"
21 #include "widgets/dropdown_func.h"
22 #include "textbuf_gui.h"
23 #include "string_func.h"
24 #include "tilehighlight_func.h"
25 #include "network/network.h"
26 #include "station_base.h"
27 #include "waypoint_base.h"
28 #include "core/geometry_func.hpp"
31 #include "engine_func.h"
32 #include "tracerestrict.h"
34 #include "widgets/order_widget.h"
36 #include "safeguards.h"
38 enum CargoTypeOrdersWindowVariant
{
43 /** Cargo type orders strings for load dropdowns. */
44 static const StringID _cargo_type_load_order_drowdown
[] = {
45 STR_ORDER_DROP_LOAD_IF_POSSIBLE
, // OLF_LOAD_IF_POSSIBLE
47 STR_CARGO_TYPE_ORDERS_DROP_FULL_LOAD
, // OLFB_FULL_LOAD
49 STR_ORDER_DROP_NO_LOADING
, // OLFB_NO_LOAD
52 static const uint32 _cargo_type_load_order_drowdown_hidden_mask
= 0xA; // 01010
54 /** Cargo type orders strings for unload dropdowns. */
55 static const StringID _cargo_type_unload_order_drowdown
[] = {
56 STR_ORDER_DROP_UNLOAD_IF_ACCEPTED
, // OUF_UNLOAD_IF_POSSIBLE
57 STR_ORDER_DROP_UNLOAD
, // OUFB_UNLOAD
58 STR_ORDER_DROP_TRANSFER
, // OUFB_TRANSFER
60 STR_ORDER_DROP_NO_UNLOADING
, // OUFB_NO_UNLOAD
63 static const uint32 _cargo_type_unload_order_drowdown_hidden_mask
= 0x8; // 01000
65 DropDownList
* GetSlotDropDownList(Owner owner
, TraceRestrictSlotID slot_id
, int &selected
);
67 struct CargoTypeOrdersWindow
: public Window
{
69 CargoTypeOrdersWindowVariant variant
;
71 const Vehicle
*vehicle
; ///< Vehicle owning the orders being displayed and manipulated.
72 VehicleOrderID order_id
; ///< Index of the order concerned by this window.
74 VehicleOrderID order_count
; ///< Count of the orders of the vehicle owning this window
75 const Order
*order
; ///< Order pointer at construction time;
77 static const uint8 CARGO_ICON_WIDTH
= 12;
78 static const uint8 CARGO_ICON_HEIGHT
= 8;
80 const StringID
*cargo_type_order_dropdown
; ///< Strings used to populate order dropdowns.
81 uint32 cargo_type_order_dropdown_hmask
; ///< Hidden mask for order dropdowns.
83 uint max_cargo_name_width
; ///< Greatest width of cargo names.
84 uint max_cargo_dropdown_width
; ///< Greatest width of order names.
86 uint set_to_all_dropdown_sel
; ///< Selected entry for the 'set to all' dropdown
89 * Initialize \c max_cargo_name_width and \c max_cargo_dropdown_width.
90 * @post \c max_cargo_name_width
91 * @post \c max_cargo_dropdown_width
93 void InitMaxWidgetWidth()
95 this->max_cargo_name_width
= 0;
96 for (int i
= 0; i
< _sorted_standard_cargo_specs_size
; i
++) {
97 SetDParam(0, _sorted_cargo_specs
[i
]->name
);
98 this->max_cargo_name_width
= max(this->max_cargo_name_width
, GetStringBoundingBox(STR_JUST_STRING
).width
);
100 this->max_cargo_dropdown_width
= 0;
101 for (int i
= 0; this->cargo_type_order_dropdown
[i
] != INVALID_STRING_ID
; i
++) {
102 SetDParam(0, this->cargo_type_order_dropdown
[i
]);
103 this->max_cargo_dropdown_width
= max(this->max_cargo_dropdown_width
, GetStringBoundingBox(STR_JUST_STRING
).width
);
107 /** Populate the selected entry of order dropdowns. */
108 void InitDropdownSelectedTypes()
110 StringID tooltip
= STR_CARGO_TYPE_LOAD_ORDERS_DROP_TOOLTIP
+ this->variant
;
111 const Order
*order
= this->vehicle
->GetOrder(this->order_id
);
112 for (int i
= 0; i
< _sorted_standard_cargo_specs_size
; i
++) {
113 const CargoSpec
*cs
= _sorted_cargo_specs
[i
];
114 CargoID cargo_id
= GetCargoIDByBitnum(cs
->bitnum
);
115 uint8 order_type
= (this->variant
== CTOWV_LOAD
) ? (uint8
)order
->GetCargoLoadTypeRaw(cargo_id
) : (uint8
)order
->GetCargoUnloadTypeRaw(cargo_id
);
116 this->GetWidget
<NWidgetCore
>(WID_CTO_CARGO_DROPDOWN_FIRST
+ i
)->SetDataTip(this->cargo_type_order_dropdown
[order_type
], tooltip
);
118 this->set_to_all_dropdown_sel
= 0;
119 this->GetWidget
<NWidgetCore
>(WID_CTO_SET_TO_ALL_DROPDOWN
)->widget_data
= this->cargo_type_order_dropdown
[this->set_to_all_dropdown_sel
];
123 * Returns the load/unload type of this order for the specified cargo.
124 * @param cargo_id The cargo index for wich we want the load/unload type.
125 * @return an OrderLoadFlags if \c load_variant = true, an OrderUnloadFlags otherwise.
127 uint8
GetOrderActionTypeForCargo(CargoID cargo_id
)
129 const Order
*order
= this->vehicle
->GetOrder(this->order_id
);
130 return (this->variant
== CTOWV_LOAD
) ? (uint8
)order
->GetCargoLoadTypeRaw(cargo_id
) : (uint8
)order
->GetCargoUnloadTypeRaw(cargo_id
);
133 bool CheckOrderStillValid() const
135 if (this->vehicle
->GetNumOrders() != this->order_count
) return false;
136 if (this->vehicle
->GetOrder(this->order_id
) != this->order
) return false;
142 * Instantiate a new CargoTypeOrdersWindow.
143 * @param desc The window description.
144 * @param v The vehicle the order belongs to.
145 * @param order_id Which order to display/edit.
146 * @param variant Which aspect of the order to display/edit: load or unload.
149 CargoTypeOrdersWindow(WindowDesc
*desc
, const Vehicle
*v
, VehicleOrderID order_id
, CargoTypeOrdersWindowVariant variant
) : Window(desc
)
151 this->variant
= variant
;
152 this->cargo_type_order_dropdown
= (this->variant
== CTOWV_LOAD
) ? _cargo_type_load_order_drowdown
: _cargo_type_unload_order_drowdown
;
153 this->cargo_type_order_dropdown_hmask
= (this->variant
== CTOWV_LOAD
) ? _cargo_type_load_order_drowdown_hidden_mask
: _cargo_type_unload_order_drowdown_hidden_mask
;
154 this->InitMaxWidgetWidth();
157 this->order_id
= order_id
;
158 this->order_count
= v
->GetNumOrders();
159 this->order
= v
->GetOrder(order_id
);
161 this->CreateNestedTree(desc
);
162 this->GetWidget
<NWidgetCore
>(WID_CTO_CAPTION
)->SetDataTip(STR_CARGO_TYPE_ORDERS_LOAD_CAPTION
+ this->variant
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
);
163 this->GetWidget
<NWidgetCore
>(WID_CTO_HEADER
)->SetDataTip(STR_CARGO_TYPE_ORDERS_LOAD_TITLE
+ this->variant
, STR_NULL
);
164 this->InitDropdownSelectedTypes();
165 this->FinishInitNested(v
->index
);
167 this->owner
= v
->owner
;
170 ~CargoTypeOrdersWindow()
172 if (!FocusWindowById(WC_VEHICLE_ORDERS
, this->window_number
)) {
173 MarkAllRouteStepsDirty(this->vehicle
);
177 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
179 if (widget
== WID_CTO_HEADER
) {
180 (*size
).height
= max((*size
).height
, (uint
) WD_FRAMERECT_TOP
+ FONT_HEIGHT_NORMAL
+ WD_FRAMERECT_BOTTOM
);
181 } else if (WID_CTO_CARGO_LABEL_FIRST
<= widget
&& widget
<= WID_CTO_CARGO_LABEL_LAST
) {
182 (*size
).width
= max((*size
).width
, WD_FRAMERECT_LEFT
+ this->CARGO_ICON_WIDTH
+ WD_FRAMETEXT_LEFT
+ this->max_cargo_name_width
+ WD_FRAMETEXT_RIGHT
+ padding
.width
);
183 (*size
).height
= max((*size
).height
, (uint
) WD_FRAMERECT_TOP
+ FONT_HEIGHT_NORMAL
+ WD_FRAMERECT_BOTTOM
);
184 } else if ((WID_CTO_CARGO_DROPDOWN_FIRST
<= widget
&& widget
<= WID_CTO_CARGO_DROPDOWN_LAST
) || widget
== WID_CTO_SET_TO_ALL_DROPDOWN
) {
185 (*size
).width
= max((*size
).width
, WD_DROPDOWNTEXT_LEFT
+ this->max_cargo_dropdown_width
+ WD_DROPDOWNTEXT_RIGHT
+ NWidgetLeaf::dropdown_dimension
.width
);
186 (*size
).height
= max((*size
).height
, (uint
) WD_DROPDOWNTEXT_TOP
+ FONT_HEIGHT_NORMAL
+ WD_DROPDOWNTEXT_BOTTOM
);
187 } else if (widget
== WID_CTO_SET_TO_ALL_LABEL
) {
188 (*size
).width
= max((*size
).width
, this->max_cargo_name_width
+ WD_FRAMETEXT_RIGHT
+ padding
.width
);
189 (*size
).height
= max((*size
).height
, (uint
) WD_FRAMERECT_TOP
+ FONT_HEIGHT_NORMAL
+ WD_FRAMERECT_BOTTOM
);
193 virtual void DrawWidget(const Rect
&r
, int widget
) const override
195 if (WID_CTO_CARGO_LABEL_FIRST
<= widget
&& widget
<= WID_CTO_CARGO_LABEL_LAST
) {
196 const CargoSpec
*cs
= _sorted_cargo_specs
[widget
- WID_CTO_CARGO_LABEL_FIRST
];
197 bool rtl
= (_current_text_dir
== TD_RTL
);
199 /* Draw cargo icon. */
200 int rect_left
= rtl
? r
.right
- WD_FRAMETEXT_RIGHT
- this->CARGO_ICON_WIDTH
: r
.left
+ WD_FRAMERECT_LEFT
;
201 int rect_right
= rect_left
+ this->CARGO_ICON_WIDTH
;
202 int rect_top
= r
.top
+ WD_FRAMERECT_TOP
+ ((r
.bottom
- WD_FRAMERECT_BOTTOM
- r
.top
- WD_FRAMERECT_TOP
) - this->CARGO_ICON_HEIGHT
) / 2;
203 int rect_bottom
= rect_top
+ this->CARGO_ICON_HEIGHT
;
204 GfxFillRect(rect_left
, rect_top
, rect_right
, rect_bottom
, PC_BLACK
);
205 GfxFillRect(rect_left
+ 1, rect_top
+ 1, rect_right
- 1, rect_bottom
- 1, cs
->legend_colour
);
207 /* Draw cargo name */
208 int text_left
= rtl
? r
.left
+ WD_FRAMETEXT_LEFT
: rect_right
+ WD_FRAMETEXT_LEFT
;
209 int text_right
= rtl
? rect_left
- WD_FRAMETEXT_LEFT
: r
.right
- WD_FRAMETEXT_RIGHT
;
210 int text_top
= r
.top
+ WD_FRAMERECT_TOP
;
211 SetDParam(0, cs
->name
);
212 DrawString(text_left
, text_right
, text_top
, STR_BLACK_STRING
);
216 virtual void OnClick(Point pt
, int widget
, int click_count
) override
218 if (!this->CheckOrderStillValid()) {
222 if (widget
== WID_CTO_CLOSEBTN
) {
224 } else if (WID_CTO_CARGO_DROPDOWN_FIRST
<= widget
&& widget
<= WID_CTO_CARGO_DROPDOWN_LAST
) {
225 const CargoSpec
*cs
= _sorted_cargo_specs
[widget
- WID_CTO_CARGO_DROPDOWN_FIRST
];
226 CargoID cargo_id
= GetCargoIDByBitnum(cs
->bitnum
);
228 ShowDropDownMenu(this, this->cargo_type_order_dropdown
, this->GetOrderActionTypeForCargo(cargo_id
), widget
, 0, this->cargo_type_order_dropdown_hmask
);
229 } else if (widget
== WID_CTO_SET_TO_ALL_DROPDOWN
) {
230 ShowDropDownMenu(this, this->cargo_type_order_dropdown
, this->set_to_all_dropdown_sel
, widget
, 0, this->cargo_type_order_dropdown_hmask
);
234 virtual void OnDropdownSelect(int widget
, int action_type
) override
236 if (!this->CheckOrderStillValid()) {
240 if (WID_CTO_CARGO_DROPDOWN_FIRST
<= widget
&& widget
<= WID_CTO_CARGO_DROPDOWN_LAST
) {
241 const CargoSpec
*cs
= _sorted_cargo_specs
[widget
- WID_CTO_CARGO_DROPDOWN_FIRST
];
242 CargoID cargo_id
= GetCargoIDByBitnum(cs
->bitnum
);
243 uint8 order_action_type
= this->GetOrderActionTypeForCargo(cargo_id
);
245 if (action_type
== order_action_type
) return;
247 ModifyOrderFlags mof
= (this->variant
== CTOWV_LOAD
) ? MOF_CARGO_TYPE_LOAD
: MOF_CARGO_TYPE_UNLOAD
;
248 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->order_id
<< 20), mof
| (action_type
<< 4) | (cargo_id
<< 16), CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
250 this->GetWidget
<NWidgetCore
>(widget
)->SetDataTip(this->cargo_type_order_dropdown
[this->GetOrderActionTypeForCargo(cargo_id
)], STR_CARGO_TYPE_LOAD_ORDERS_DROP_TOOLTIP
+ this->variant
);
251 this->SetWidgetDirty(widget
);
252 } else if (widget
== WID_CTO_SET_TO_ALL_DROPDOWN
) {
253 for (int i
= 0; i
< _sorted_standard_cargo_specs_size
; i
++) {
254 this->OnDropdownSelect(i
+ WID_CTO_CARGO_DROPDOWN_FIRST
, action_type
);
257 if (action_type
!= (int) this->set_to_all_dropdown_sel
) {
258 this->set_to_all_dropdown_sel
= action_type
;
259 this->GetWidget
<NWidgetCore
>(widget
)->widget_data
= this->cargo_type_order_dropdown
[this->set_to_all_dropdown_sel
];
260 this->SetWidgetDirty(widget
);
265 virtual void SetStringParameters(int widget
) const override
267 if (!this->CheckOrderStillValid()) {
270 if (widget
== WID_CTO_CAPTION
) {
271 SetDParam(0, this->vehicle
->index
);
272 SetDParam(1, this->order_id
+ 1);
273 SetDParam(2, this->vehicle
->GetOrder(this->order_id
)->GetDestination());
277 virtual void OnFocus(Window
*previously_focused_window
) override
279 if (HasFocusedVehicleChanged(this->window_number
, previously_focused_window
)) {
280 MarkAllRoutePathsDirty(this->vehicle
);
281 MarkAllRouteStepsDirty(this->vehicle
);
285 virtual void OnFocusLost(Window
*newly_focused_window
) override
287 if (HasFocusedVehicleChanged(this->window_number
, newly_focused_window
)) {
288 MarkAllRoutePathsDirty(this->vehicle
);
289 MarkAllRouteStepsDirty(this->vehicle
);
294 * Some data on this window has become invalid.
295 * @param data Information about the changed data.
296 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
298 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
300 if (!this->CheckOrderStillValid()) {
305 this->InitDropdownSelectedTypes();
312 * Make a list of panel for each available cargo type.
313 * Each panel contains a label to display the cargo name.
314 * @param biggest_index Storage for collecting the biggest index used in the returned tree
315 * @return A vertical container of cargo type orders rows.
316 * @post \c *biggest_index contains the largest used index in the tree.
318 static NWidgetBase
*MakeCargoTypeOrdersRows(int *biggest_index
)
320 NWidgetVertical
*ver
= new NWidgetVertical
;
322 for (int i
= 0; i
< _sorted_standard_cargo_specs_size
; i
++) {
324 NWidgetBackground
*panel
= new NWidgetBackground(WWT_PANEL
, COLOUR_GREY
, WID_CTO_CARGO_ROW_FIRST
+ i
);
326 NWidgetHorizontal
*horiz
= new NWidgetHorizontal
;
329 NWidgetBackground
*label
= new NWidgetBackground(WWT_PANEL
, COLOUR_GREY
, WID_CTO_CARGO_LABEL_FIRST
+ i
);
330 label
->SetFill(1, 0);
331 label
->SetResize(1, 0);
333 /* Orders dropdown */
334 NWidgetLeaf
*dropdown
= new NWidgetLeaf(WWT_DROPDOWN
, COLOUR_GREY
, WID_CTO_CARGO_DROPDOWN_FIRST
+ i
, STR_NULL
, STR_EMPTY
);
335 dropdown
->SetFill(1, 0);
336 dropdown
->SetResize(1, 0);
337 horiz
->Add(dropdown
);
340 *biggest_index
= WID_CTO_CARGO_DROPDOWN_LAST
;
344 /** Widgets definition of CargoTypeOrdersWindow. */
345 static const NWidgetPart _nested_cargo_type_orders_widgets
[] = {
346 NWidget(NWID_HORIZONTAL
),
347 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
348 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_CTO_CAPTION
), SetDataTip(STR_NULL
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
350 NWidget(WWT_PANEL
, COLOUR_GREY
),
351 NWidget(WWT_LABEL
, COLOUR_GREY
, WID_CTO_HEADER
), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_NULL
, STR_NULL
),
353 NWidgetFunction(MakeCargoTypeOrdersRows
),
354 NWidget(WWT_PANEL
, COLOUR_GREY
), SetMinimalSize(1, 4), SetFill(1, 0), SetResize(1, 0), EndContainer(), // SPACER
355 NWidget(NWID_HORIZONTAL
),
356 NWidget(WWT_PANEL
, COLOUR_GREY
),
357 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_CTO_SET_TO_ALL_LABEL
), SetPadding(0, 0, 0, WD_FRAMERECT_LEFT
+ 12 + WD_FRAMETEXT_LEFT
), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_CARGO_TYPE_ORDERS_SET_TO_ALL_LABEL
, STR_CARGO_TYPE_ORDERS_SET_TO_ALL_TOOLTIP
),
359 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_CTO_SET_TO_ALL_DROPDOWN
), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_NULL
, STR_CARGO_TYPE_ORDERS_SET_TO_ALL_TOOLTIP
),
361 NWidget(NWID_HORIZONTAL
),
362 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_CTO_CLOSEBTN
), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_CARGO_TYPE_ORDERS_CLOSE_BUTTON
, STR_TOOLTIP_CLOSE_WINDOW
),
363 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
367 /** Window description for the 'load' variant of CargoTypeOrdersWindow. */
368 static WindowDesc
_cargo_type_load_orders_widgets (
369 WDP_AUTO
, "view_cargo_type_load_order", 195, 186,
370 WC_VEHICLE_CARGO_TYPE_LOAD_ORDERS
, WC_VEHICLE_ORDERS
,
372 _nested_cargo_type_orders_widgets
, lengthof(_nested_cargo_type_orders_widgets
)
375 /** Window description for the 'unload' variant of CargoTypeOrdersWindow. */
376 static WindowDesc
_cargo_type_unload_orders_widgets (
377 WDP_AUTO
, "view_cargo_type_unload_order", 195, 186,
378 WC_VEHICLE_CARGO_TYPE_UNLOAD_ORDERS
, WC_VEHICLE_ORDERS
,
380 _nested_cargo_type_orders_widgets
, lengthof(_nested_cargo_type_orders_widgets
)
384 * Show the CargoTypeOrdersWindow for an order.
385 * @param v The vehicle the order belongs to.
386 * @param parent The parent window.
387 * @param order_id Which order to display/edit.
388 * @param variant Which aspect of the order to display/edit: load or unload.
391 void ShowCargoTypeOrdersWindow(const Vehicle
*v
, Window
*parent
, VehicleOrderID order_id
, CargoTypeOrdersWindowVariant variant
)
393 WindowDesc
&desc
= (variant
== CTOWV_LOAD
) ? _cargo_type_load_orders_widgets
: _cargo_type_unload_orders_widgets
;
394 DeleteWindowById(desc
.cls
, v
->index
);
395 CargoTypeOrdersWindow
*w
= new CargoTypeOrdersWindow(&desc
, v
, order_id
, variant
);
400 /** Order load types that could be given to station orders. */
401 static const StringID _station_load_types
[][9][9] = {
408 STR_ORDER_FULL_LOAD_ANY
,
413 STR_ORDER_CARGO_TYPE_LOAD
,
417 STR_ORDER_UNLOAD_FULL_LOAD
,
418 STR_ORDER_UNLOAD_FULL_LOAD_ANY
,
419 STR_ORDER_UNLOAD_NO_LOAD
,
423 STR_ORDER_UNLOAD_CARGO_TYPE_LOAD
,
427 STR_ORDER_TRANSFER_FULL_LOAD
,
428 STR_ORDER_TRANSFER_FULL_LOAD_ANY
,
429 STR_ORDER_TRANSFER_NO_LOAD
,
433 STR_ORDER_TRANSFER_CARGO_TYPE_LOAD
,
435 /* Unload and transfer do not work together. */
436 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
437 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
438 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
442 STR_ORDER_NO_UNLOAD_FULL_LOAD
,
443 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY
,
444 STR_ORDER_NO_UNLOAD_NO_LOAD
,
448 STR_ORDER_NO_UNLOAD_CARGO_TYPE_LOAD
,
450 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
451 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
452 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
454 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
455 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
456 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
458 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
459 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
460 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
462 STR_ORDER_CARGO_TYPE_UNLOAD
,
464 STR_ORDER_CARGO_TYPE_UNLOAD_FULL_LOAD
,
465 STR_ORDER_CARGO_TYPE_UNLOAD_FULL_LOAD_ANY
,
466 STR_ORDER_CARGO_TYPE_UNLOAD_NO_LOAD
,
470 STR_ORDER_CARGO_TYPE_UNLOAD_CARGO_TYPE_LOAD
,
473 /* With auto-refitting. No loading and auto-refitting do not work together. */
475 STR_ORDER_AUTO_REFIT
,
477 STR_ORDER_FULL_LOAD_REFIT
,
478 STR_ORDER_FULL_LOAD_ANY_REFIT
,
483 STR_ORDER_CARGO_TYPE_LOAD_REFIT
,
485 STR_ORDER_UNLOAD_REFIT
,
487 STR_ORDER_UNLOAD_FULL_LOAD_REFIT
,
488 STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT
,
493 STR_ORDER_UNLOAD_CARGO_TYPE_LOAD_REFIT
,
495 STR_ORDER_TRANSFER_REFIT
,
497 STR_ORDER_TRANSFER_FULL_LOAD_REFIT
,
498 STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT
,
503 STR_ORDER_TRANSFER_CARGO_TYPE_LOAD_REFIT
,
505 /* Unload and transfer do not work together. */
506 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
507 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
508 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
510 STR_ORDER_NO_UNLOAD_REFIT
,
512 STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT
,
513 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT
,
518 STR_ORDER_NO_UNLOAD_CARGO_TYPE_LOAD_REFIT
,
520 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
521 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
522 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
524 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
525 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
526 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
528 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
529 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
530 INVALID_STRING_ID
, INVALID_STRING_ID
, INVALID_STRING_ID
,
532 STR_ORDER_CARGO_TYPE_UNLOAD_REFIT
,
534 STR_ORDER_CARGO_TYPE_UNLOAD_FULL_LOAD_REFIT
,
535 STR_ORDER_CARGO_TYPE_UNLOAD_FULL_LOAD_ANY_REFIT
,
540 STR_ORDER_CARGO_TYPE_UNLOAD_CARGO_TYPE_LOAD_REFIT
,
545 static const StringID _order_non_stop_drowdown
[] = {
547 STR_ORDER_GO_NON_STOP_TO
,
549 STR_ORDER_GO_NON_STOP_VIA
,
553 static const StringID _order_full_load_drowdown
[] = {
554 STR_ORDER_DROP_LOAD_IF_POSSIBLE
,
556 STR_ORDER_DROP_FULL_LOAD_ALL
,
557 STR_ORDER_DROP_FULL_LOAD_ANY
,
558 STR_ORDER_DROP_NO_LOADING
,
562 STR_ORDER_DROP_CARGO_TYPE_LOAD
,
566 static const StringID _order_unload_drowdown
[] = {
567 STR_ORDER_DROP_UNLOAD_IF_ACCEPTED
,
568 STR_ORDER_DROP_UNLOAD
,
569 STR_ORDER_DROP_TRANSFER
,
571 STR_ORDER_DROP_NO_UNLOADING
,
575 STR_ORDER_DROP_CARGO_TYPE_UNLOAD
,
579 static const StringID _order_goto_dropdown
[] = {
581 STR_ORDER_GO_TO_NEAREST_DEPOT
,
582 STR_ORDER_CONDITIONAL
,
587 static const StringID _order_goto_dropdown_aircraft
[] = {
589 STR_ORDER_GO_TO_NEAREST_HANGAR
,
590 STR_ORDER_CONDITIONAL
,
595 /** Variables for conditional orders; this defines the order of appearance in the dropdown box */
596 static const OrderConditionVariable _order_conditional_variable
[] = {
601 OCV_REMAINING_LIFETIME
,
602 OCV_REQUIRES_SERVICE
,
604 OCV_CARGO_ACCEPTANCE
,
611 static const StringID _order_conditional_condition
[] = {
612 STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS
,
613 STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS
,
614 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN
,
615 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS
,
616 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN
,
617 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS
,
618 STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE
,
619 STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE
,
623 static const StringID _order_conditional_condition_has
[] = {
624 STR_ORDER_CONDITIONAL_COMPARATOR_HAS
,
625 STR_ORDER_CONDITIONAL_COMPARATOR_HAS_NO
,
626 STR_ORDER_CONDITIONAL_COMPARATOR_HAS_LESS_THAN
,
627 STR_ORDER_CONDITIONAL_COMPARATOR_HAS_LESS_EQUALS
,
628 STR_ORDER_CONDITIONAL_COMPARATOR_HAS_MORE_THAN
,
629 STR_ORDER_CONDITIONAL_COMPARATOR_HAS_MORE_EQUALS
,
630 STR_ORDER_CONDITIONAL_COMPARATOR_HAS
,
631 STR_ORDER_CONDITIONAL_COMPARATOR_HAS_NO
,
635 static const StringID _order_conditional_condition_accepts
[] = {
642 STR_ORDER_CONDITIONAL_COMPARATOR_ACCEPTS
,
643 STR_ORDER_CONDITIONAL_COMPARATOR_DOES_NOT_ACCEPT
,
647 static const StringID _order_conditional_condition_is_fully_occupied
[] = {
654 STR_ORDER_CONDITIONAL_COMPARATOR_FULLY_OCCUPIED
,
655 STR_ORDER_CONDITIONAL_COMPARATOR_NOT_YET_FULLY_OCCUPIED
,
659 extern uint
ConvertSpeedToDisplaySpeed(uint speed
);
660 extern uint
ConvertDisplaySpeedToSpeed(uint speed
);
662 static const StringID _order_depot_action_dropdown
[] = {
663 STR_ORDER_DROP_GO_ALWAYS_DEPOT
,
664 STR_ORDER_DROP_SERVICE_DEPOT
,
665 STR_ORDER_DROP_HALT_DEPOT
,
669 static int DepotActionStringIndex(const Order
*order
)
671 if (order
->GetDepotActionType() & ODATFB_HALT
) {
673 } else if (order
->GetDepotOrderType() & ODTFB_SERVICE
) {
680 static const StringID _order_refit_action_dropdown
[] = {
681 STR_ORDER_DROP_REFIT_AUTO
,
682 STR_ORDER_DROP_REFIT_AUTO_ANY
,
687 * Draws an order in order or timetable GUI
688 * @param v Vehicle the order belongs to
689 * @param order The order to draw
690 * @param order_index Index of the order in the orders of the vehicle
691 * @param y Y position for drawing
692 * @param selected True, if the order is selected
693 * @param timetable True, when drawing in the timetable GUI
694 * @param left Left border for text drawing
695 * @param middle X position between order index and order text
696 * @param right Right border for text drawing
698 void DrawOrderString(const Vehicle
*v
, const Order
*order
, int order_index
, int y
, bool selected
, bool timetable
, int left
, int middle
, int right
)
700 bool rtl
= _current_text_dir
== TD_RTL
;
702 SpriteID sprite
= rtl
? SPR_ARROW_LEFT
: SPR_ARROW_RIGHT
;
703 Dimension sprite_size
= GetSpriteSize(sprite
);
704 if (v
->cur_real_order_index
== order_index
) {
705 DrawSprite(sprite
, PAL_NONE
, rtl
? right
- sprite_size
.width
: left
, y
+ ((int)FONT_HEIGHT_NORMAL
- (int)sprite_size
.height
) / 2);
706 DrawSprite(sprite
, PAL_NONE
, rtl
? right
- 2 * sprite_size
.width
: left
+ sprite_size
.width
, y
+ ((int)FONT_HEIGHT_NORMAL
- (int)sprite_size
.height
) / 2);
707 } else if (v
->cur_implicit_order_index
== order_index
) {
708 DrawSprite(sprite
, PAL_NONE
, rtl
? right
- sprite_size
.width
: left
, y
+ ((int)FONT_HEIGHT_NORMAL
- (int)sprite_size
.height
) / 2);
711 TextColour colour
= TC_BLACK
;
712 if (order
->IsType(OT_IMPLICIT
)) {
713 colour
= (selected
? TC_SILVER
: TC_GREY
) | TC_NO_SHADE
;
714 } else if (selected
) {
718 SetDParam(0, order_index
+ 1);
719 DrawString(left
, rtl
? right
- 2 * sprite_size
.width
- 3 : middle
, y
, STR_ORDER_INDEX
, colour
, SA_RIGHT
| SA_FORCE
);
721 SetDParam(5, STR_EMPTY
);
723 /* Check range for aircraft. */
724 if (v
->type
== VEH_AIRCRAFT
&& Aircraft::From(v
)->GetRange() > 0 && order
->IsGotoOrder()) {
725 const Order
*next
= order
->next
!= NULL
? order
->next
: v
->GetFirstOrder();
726 if (GetOrderDistance(order
, next
, v
) > Aircraft::From(v
)->acache
.cached_max_range_sqr
) SetDParam(8, STR_ORDER_OUT_OF_RANGE
);
729 switch (order
->GetType()) {
731 SetDParam(0, STR_INVALID_ORDER
);
732 SetDParam(1, order
->GetDestination());
736 SetDParam(0, STR_ORDER_GO_TO_STATION
);
737 SetDParam(1, STR_ORDER_GO_TO
);
738 SetDParam(2, order
->GetDestination());
739 SetDParam(3, timetable
? STR_EMPTY
: STR_ORDER_IMPLICIT
);
742 case OT_GOTO_STATION
: {
743 OrderLoadFlags load
= order
->GetLoadType();
744 OrderUnloadFlags unload
= order
->GetUnloadType();
746 SetDParam(0, STR_ORDER_GO_TO_STATION
);
747 SetDParam(1, STR_ORDER_GO_TO
+ (v
->IsGroundVehicle() ? order
->GetNonStopType() : 0));
748 SetDParam(2, order
->GetDestination());
751 SetDParam(3, STR_EMPTY
);
753 if (order
->GetWaitTime() > 0) {
754 SetDParam(5, order
->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR_MINUTES
: STR_TIMETABLE_STAY_FOR_MINUTES_ESTIMATED
);
755 SetTimetableParams(order
->GetWaitTime(), 6);
758 SetDParam(3, (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) ? STR_EMPTY
: _station_load_types
[order
->IsRefit()][unload
][load
]);
759 if (order
->IsRefit()) {
760 SetDParam(4, order
->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY
: CargoSpec::Get(order
->GetRefitCargo())->name
);
762 if (v
->type
== VEH_TRAIN
&& (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) == 0) {
763 SetDParam(5, order
->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END
);
770 if (order
->GetDepotActionType() & ODATFB_NEAREST_DEPOT
) {
771 SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT
);
772 if (v
->type
== VEH_AIRCRAFT
) {
773 SetDParam(2, STR_ORDER_NEAREST_HANGAR
);
774 SetDParam(3, STR_EMPTY
);
776 SetDParam(2, STR_ORDER_NEAREST_DEPOT
);
777 SetDParam(3, STR_ORDER_TRAIN_DEPOT
+ v
->type
);
780 SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT
);
781 SetDParam(2, v
->type
);
782 SetDParam(3, order
->GetDestination());
785 if (order
->GetDepotOrderType() & ODTFB_SERVICE
) {
786 SetDParam(1, (order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
) ? STR_ORDER_SERVICE_NON_STOP_AT
: STR_ORDER_SERVICE_AT
);
788 SetDParam(1, (order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
) ? STR_ORDER_GO_NON_STOP_TO
: STR_ORDER_GO_TO
);
791 if (!timetable
&& (order
->GetDepotActionType() & ODATFB_HALT
)) {
792 SetDParam(5, STR_ORDER_STOP_ORDER
);
795 if (!timetable
&& order
->IsRefit()) {
796 SetDParam(5, (order
->GetDepotActionType() & ODATFB_HALT
) ? STR_ORDER_REFIT_STOP_ORDER
: STR_ORDER_REFIT_ORDER
);
797 SetDParam(6, CargoSpec::Get(order
->GetRefitCargo())->name
);
801 if (order
->GetWaitTime() > 0) {
802 SetDParam(5, order
->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR_MINUTES
: STR_TIMETABLE_STAY_FOR_MINUTES_ESTIMATED
);
803 SetTimetableParams(order
->GetWaitTime(), 6);
808 case OT_GOTO_WAYPOINT
: {
809 StringID str
= (order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT
: STR_ORDER_GO_TO_WAYPOINT
;
810 if (order
->GetWaypointFlags() & OWF_REVERSE
) str
+= STR_ORDER_GO_TO_WAYPOINT_REVERSE
- STR_ORDER_GO_TO_WAYPOINT
;
812 SetDParam(1, order
->GetDestination());
816 case OT_CONDITIONAL
: {
817 SetDParam(1, order
->GetConditionSkipToOrder() + 1);
818 const OrderConditionVariable ocv
= order
->GetConditionVariable();
819 /* handle some non-ordinary cases seperately */
820 if (ocv
== OCV_UNCONDITIONALLY
) {
821 SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL
);
823 else if (ocv
== OCV_PERCENT
) {
824 SetDParam(0, STR_CONDITIONAL_PERCENT
);
825 SetDParam(2, order
->GetConditionValue());
827 else if (ocv
== OCV_FREE_PLATFORMS
) {
828 SetDParam(0, STR_CONDITIONAL_FREE_PLATFORMS
);
829 SetDParam(2, STR_ORDER_CONDITIONAL_COMPARATOR_HAS
+ order
->GetConditionComparator());
830 SetDParam(3, order
->GetConditionValue());
832 else if (ocv
== OCV_SLOT_OCCUPANCY
) {
833 if (TraceRestrictSlot::IsValidID(order
->GetConditionValue()))
835 SetDParam(0, STR_ORDER_CONDITIONAL_SLOT
);
836 SetDParam(2, order
->GetConditionValue());
839 SetDParam(0, STR_ORDER_CONDITIONAL_INVALID_SLOT
);
840 SetDParam(2, STR_TRACE_RESTRICT_VARIABLE_UNDEFINED
);
842 SetDParam(3, order
->GetConditionComparator() == OCC_IS_TRUE
? STR_ORDER_CONDITIONAL_COMPARATOR_FULLY_OCCUPIED
: STR_ORDER_CONDITIONAL_COMPARATOR_NOT_YET_FULLY_OCCUPIED
);
845 OrderConditionComparator occ
= order
->GetConditionComparator();
846 bool is_cargo
= ocv
== OCV_CARGO_ACCEPTANCE
|| ocv
== OCV_CARGO_WAITING
;
847 SetDParam(0, is_cargo
? STR_ORDER_CONDITIONAL_CARGO
: (occ
== OCC_IS_TRUE
|| occ
== OCC_IS_FALSE
) ? STR_ORDER_CONDITIONAL_TRUE_FALSE
: STR_ORDER_CONDITIONAL_NUM
);
848 SetDParam(2, (ocv
== OCV_CARGO_ACCEPTANCE
|| ocv
== OCV_CARGO_WAITING
|| ocv
== OCV_FREE_PLATFORMS
) ? STR_ORDER_CONDITIONAL_NEXT_STATION
: STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE
+ ocv
);
850 uint value
= order
->GetConditionValue();
852 case OCV_CARGO_ACCEPTANCE
:
853 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_ACCEPTS
+ occ
- OCC_IS_TRUE
);
854 SetDParam(4, CargoSpec::Get(value
)->name
);
856 case OCV_CARGO_WAITING
:
857 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_HAS
+ occ
- OCC_IS_TRUE
);
858 SetDParam(4, CargoSpec::Get(value
)->name
);
860 case OCV_REQUIRES_SERVICE
:
861 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS
+ occ
);
864 value
= ConvertSpeedToDisplaySpeed(value
);
867 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS
+ occ
);
872 if (timetable
&& order
->GetWaitTime() > 0) {
873 SetDParam(5, order
->IsWaitTimetabled() ? STR_TIMETABLE_AND_TRAVEL_FOR_MINUTES
: STR_TIMETABLE_AND_TRAVEL_FOR_MINUTES_ESTIMATED
);
874 SetTimetableParams(order
->GetWaitTime(), 6);
877 SetDParam(5, STR_EMPTY
);
882 default: NOT_REACHED();
885 DrawString(rtl
? left
: middle
, rtl
? middle
: right
, y
, STR_ORDER_TEXT_MINUTES
, colour
);
889 * Get the order command a vehicle can do in a given tile.
890 * @param v Vehicle involved.
891 * @param tile Tile being queried.
892 * @return The order associated to vehicle v in given tile (or empty order if vehicle can do nothing in the tile).
894 static Order
GetOrderCmdFromTile(const Vehicle
*v
, TileIndex tile
)
896 /* Hack-ish; unpack order 0, so everything gets initialised with either zero
897 * or a suitable default value for the variable. Then also override the index
898 * as it is not coming from a pool, so would be initialised. */
902 /* check depot first */
903 if (IsDepotTypeTile(tile
, (TransportType
)(uint
)v
->type
) && IsTileOwner(tile
, _local_company
)) {
904 order
.MakeGoToDepot(v
->type
== VEH_AIRCRAFT
? GetStationIndex(tile
) : GetDepotIndex(tile
),
905 ODTFB_PART_OF_ORDERS
,
906 (_settings_client
.gui
.new_nonstop
&& v
->IsGroundVehicle()) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
: ONSF_STOP_EVERYWHERE
);
908 if (_ctrl_pressed
) order
.SetDepotOrderType((OrderDepotTypeFlags
)(order
.GetDepotOrderType() ^ ODTFB_SERVICE
));
913 /* check rail waypoint */
914 if (IsRailWaypointTile(tile
) &&
915 v
->type
== VEH_TRAIN
&&
916 IsTileOwner(tile
, _local_company
)) {
917 order
.MakeGoToWaypoint(GetStationIndex(tile
));
918 if (_settings_client
.gui
.new_nonstop
!= _ctrl_pressed
) order
.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION
);
922 /* check buoy (no ownership) */
923 if (IsBuoyTile(tile
) && v
->type
== VEH_SHIP
) {
924 order
.MakeGoToWaypoint(GetStationIndex(tile
));
928 if (IsTileType(tile
, MP_STATION
)) {
929 StationID st_index
= GetStationIndex(tile
);
930 const Station
*st
= Station::Get(st_index
);
932 if (st
->owner
== _local_company
|| st
->owner
== OWNER_NONE
) {
934 (facil
= FACIL_DOCK
, v
->type
== VEH_SHIP
) ||
935 (facil
= FACIL_TRAIN
, v
->type
== VEH_TRAIN
) ||
936 (facil
= FACIL_AIRPORT
, v
->type
== VEH_AIRCRAFT
) ||
937 (facil
= FACIL_BUS_STOP
, v
->type
== VEH_ROAD
&& RoadVehicle::From(v
)->IsBus()) ||
938 (facil
= FACIL_TRUCK_STOP
, 1);
939 if (st
->facilities
& facil
) {
940 order
.MakeGoToStation(st_index
);
942 if (_ctrl_pressed
&& !_shift_pressed
) {
943 order
.SetLoadType(OLF_FULL_LOAD_ANY
);
944 order
.SetUnloadType(OUFB_NO_UNLOAD
);
945 } else if (!_ctrl_pressed
&& _shift_pressed
) {
946 order
.SetLoadType(OLFB_NO_LOAD
);
947 order
.SetUnloadType(OUFB_UNLOAD
);
948 } else if (_ctrl_pressed
&& _shift_pressed
) {
949 order
.SetLoadType(OLFB_NO_LOAD
);
950 order
.SetUnloadType(OUFB_TRANSFER
);
953 if (_settings_client
.gui
.new_nonstop
&& v
->IsGroundVehicle()) {
954 if (order
.GetNonStopType() == ONSF_NO_STOP_AT_DESTINATION_STATION
) {
955 order
.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION
);
957 order
.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
);
961 order
.SetStopLocation(v
->type
== VEH_TRAIN
? (OrderStopLocation
)(_settings_client
.gui
.stop_location
) : OSL_PLATFORM_FAR_END
);
972 /** Hotkeys for order window. */
989 /** Confirm replacement of the existing orders with shared orders
990 * @param w parent Window
991 * @param confirmed true if confirmed, false otherwise
993 void AskShareOrdersCallback(Window
*w
, bool confirmed
);
998 * %Order window code for all vehicles.
1000 * At the bottom of the window two button rows are located for changing the orders of the vehicle.
1002 * \section top-row Top row
1003 * The top-row is for manipulating an individual order. What row is displayed depends on the type of vehicle, and whether or not you are the owner of the vehicle.
1005 * The top-row buttons of one of your trains or road vehicles is one of the following three cases:
1007 * +-----------------+-----------------+-----------------+-----------------+
1008 * | NON-STOP | FULL_LOAD | UNLOAD | REFIT | (normal)
1009 * +-----------------+-----+-----------+-----------+-----+-----------------+
1010 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
1011 * +-----------------+-----+-----------+-----------+-----+-----------------+
1012 * | NON-STOP | REFIT | SERVICE | (empty) | (for depot orders)
1013 * +-----------------+-----------------+-----------------+-----------------+
1016 * Airplanes and ships have one of the following three top-row button rows:
1018 * +-----------------+-----------------+-----------------+
1019 * | FULL_LOAD | UNLOAD | REFIT | (normal)
1020 * +-----------------+-----------------+-----------------+
1021 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
1022 * +-----------------+--------+--------+-----------------+
1023 * | REFIT | SERVICE | (for depot order)
1024 * +--------------------------+--------------------------+
1027 * \section bottom-row Bottom row
1028 * The second row (the bottom row) is for manipulating the list of orders:
1030 * +-----------------+-----------------+-----------------+
1031 * | SKIP | DELETE | GOTO |
1032 * +-----------------+-----------------+-----------------+
1035 * For vehicles of other companies, both button rows are not displayed.
1037 struct OrdersWindow
: public Window
{
1039 /** Under what reason are we using the PlaceObject functionality? */
1040 enum OrderPlaceObjectState
{
1048 /** Displayed planes of the #NWID_SELECTION widgets. */
1050 /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
1051 DP_GROUNDVEHICLE_ROW_NORMAL
= 0, ///< Display the row for normal/depot orders in the top row of the train/rv order window.
1052 DP_GROUNDVEHICLE_ROW_CONDITIONAL
= 1, ///< Display the row for conditional orders in the top row of the train/rv order window.
1054 /* WID_O_SEL_TOP_LEFT */
1055 DP_LEFT_LOAD
= 0, ///< Display 'load' in the left button of the top row of the train/rv order window.
1056 DP_LEFT_REFIT
= 1, ///< Display 'refit' in the left button of the top row of the train/rv order window.
1057 DP_LEFT_REVERSE
= 2, ///< Display 'reverse' in the left button of the top row of the train/rv order window.
1059 /* WID_O_SEL_TOP_MIDDLE */
1060 DP_MIDDLE_UNLOAD
= 0, ///< Display 'unload' in the middle button of the top row of the train/rv order window.
1061 DP_MIDDLE_SERVICE
= 1, ///< Display 'service' in the middle button of the top row of the train/rv order window.
1063 /* WID_O_SEL_TOP_RIGHT */
1064 DP_RIGHT_EMPTY
= 0, ///< Display an empty panel in the right button of the top row of the train/rv order window.
1065 DP_RIGHT_REFIT
= 1, ///< Display 'refit' in the right button of the top row of the train/rv order window.
1067 /* WID_O_SEL_TOP_ROW */
1068 DP_ROW_LOAD
= 0, ///< Display 'load' / 'unload' / 'refit' buttons in the top row of the ship/airplane order window.
1069 DP_ROW_DEPOT
= 1, ///< Display 'refit' / 'service' buttons in the top row of the ship/airplane order window.
1070 DP_ROW_CONDITIONAL
= 2, ///< Display the conditional order buttons in the top row of the ship/airplane order window.
1072 /* WID_O_SEL_COND_VALUE */
1073 DP_COND_VALUE_NUMBER
= 0, ///< Display number widget
1074 DP_COND_VALUE_CARGO
= 1, ///< Display dropdown widget cargo types
1075 DP_COND_VALUE_SLOT
= 2, ///< Display dropdown widget tracerestrict slots
1077 /* WID_O_SEL_BOTTOM_MIDDLE */
1078 DP_BOTTOM_MIDDLE_DELETE
= 0, ///< Display 'delete' in the middle button of the bottom row of the vehicle order window.
1079 DP_BOTTOM_MIDDLE_STOP_SHARING
= 1, ///< Display 'stop sharing' in the middle button of the bottom row of the vehicle order window.
1083 VehicleOrderID order_over
; ///< Order over which another order is dragged, \c INVALID_VEH_ORDER_ID if none.
1084 OrderPlaceObjectState goto_type
;
1085 const Vehicle
*vehicle
; ///< Vehicle owning the orders being displayed and manipulated.
1087 bool can_do_refit
; ///< Vehicle chain can be refitted in depot.
1088 bool can_do_autorefit
; ///< Vehicle chain can be auto-refitted.
1089 uint32 index_vehicle_share
; ///< index of vehicle to share
1092 * Return the memorised selected order.///
1093 * @return the memorised order if it is a valid one
1094 * else return the number of orders
1096 VehicleOrderID
OrderGetSel() const
1098 int num
= this->selected_order
;
1099 return (num
>= 0 && num
< vehicle
->GetNumOrders()) ? num
: vehicle
->GetNumOrders();
1103 * Calculate the selected order.
1104 * The calculation is based on the relative (to the window) y click position and
1105 * the position of the scrollbar.
1107 * @param y Y-value of the click relative to the window origin
1108 * @return The selected order if the order is valid, else return \c INVALID_VEH_ORDER_ID.
1110 VehicleOrderID
GetOrderFromPt(int y
)
1112 NWidgetBase
*nwid
= this->GetWidget
<NWidgetBase
>(WID_O_ORDER_LIST
);
1113 int sel
= (y
- nwid
->pos_y
- WD_FRAMERECT_TOP
) / nwid
->resize_y
; // Selected line in the WID_O_ORDER_LIST panel.
1115 if ((uint
)sel
>= this->vscroll
->GetCapacity()) return INVALID_VEH_ORDER_ID
;
1117 sel
+= this->vscroll
->GetPosition();
1119 return (sel
<= vehicle
->GetNumOrders() && sel
>= 0) ? sel
: INVALID_VEH_ORDER_ID
;
1123 * Determine which strings should be displayed in the conditional comparator dropdown
1125 * @param order the order to evaluate
1126 * @return the StringIDs to display
1128 static const StringID
*GetComparatorStrings(const Order
*order
)
1130 if (order
== NULL
) return _order_conditional_condition
;
1131 switch (order
->GetConditionVariable()) {
1132 case OCV_FREE_PLATFORMS
: //fall through
1133 case OCV_CARGO_WAITING
: return _order_conditional_condition_has
; break;
1134 case OCV_CARGO_ACCEPTANCE
: return _order_conditional_condition_accepts
; break;
1135 case OCV_SLOT_OCCUPANCY
: return _order_conditional_condition_is_fully_occupied
; break;
1136 default: return _order_conditional_condition
; break;
1141 * Handle the click on the goto button.
1143 void OrderClick_Goto(OrderPlaceObjectState type
)
1145 assert(type
> OPOS_NONE
&& type
< OPOS_END
);
1147 static const HighLightStyle goto_place_style
[OPOS_END
- 1] = {
1148 HT_RECT
| HT_VEHICLE
, // OPOS_GOTO
1149 HT_NONE
, // OPOS_CONDITIONAL
1150 HT_VEHICLE
, // OPOS_SHARE
1152 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION
, PAL_NONE
, goto_place_style
[type
- 1], this);
1153 this->goto_type
= type
;
1154 this->SetWidgetDirty(WID_O_GOTO
);
1158 * Handle the click on the full load button.
1159 * @param load_type the way to load.
1161 void OrderClick_FullLoad(int load_type
)
1163 VehicleOrderID sel_ord
= this->OrderGetSel();
1164 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
1166 if (order
== NULL
|| (order
->GetLoadType() == load_type
&& load_type
!= OLFB_CARGO_TYPE_LOAD
)) return;
1168 if (load_type
< 0) {
1169 load_type
= order
->GetLoadType() == OLF_LOAD_IF_POSSIBLE
? OLF_FULL_LOAD_ANY
: OLF_LOAD_IF_POSSIBLE
;
1171 if (order
->GetLoadType() != load_type
) {
1172 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel_ord
<< 20), MOF_LOAD
| (load_type
<< 4), CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
1175 if (load_type
== OLFB_CARGO_TYPE_LOAD
) ShowCargoTypeOrdersWindow(this->vehicle
, this, sel_ord
, CTOWV_LOAD
);
1179 * Handle the 'no loading' hotkey
1181 void OrderHotkey_NoLoad()
1183 this->OrderClick_FullLoad(OLFB_NO_LOAD
);
1187 * Handle the click on the service.
1189 void OrderClick_Service(int i
)
1191 VehicleOrderID sel_ord
= this->OrderGetSel();
1194 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
1195 if (order
== NULL
) return;
1196 i
= (order
->GetDepotOrderType() & ODTFB_SERVICE
) ? DA_ALWAYS_GO
: DA_SERVICE
;
1198 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel_ord
<< 20), MOF_DEPOT_ACTION
| (i
<< 4), CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
1202 * Handle the click on the service in nearest depot button.
1204 void OrderClick_NearestDepot()
1209 order
.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS
,
1210 _settings_client
.gui
.new_nonstop
&& this->vehicle
->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
: ONSF_STOP_EVERYWHERE
);
1211 order
.SetDepotActionType(ODATFB_NEAREST_DEPOT
);
1213 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->OrderGetSel() << 20), order
.Pack(), CMD_INSERT_ORDER
| CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER
));
1217 * Handle the click on the unload button.
1219 void OrderClick_Unload(int unload_type
)
1221 VehicleOrderID sel_ord
= this->OrderGetSel();
1222 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
1224 if (order
== NULL
|| (order
->GetUnloadType() == unload_type
&& unload_type
!= OUFB_CARGO_TYPE_UNLOAD
)) return;
1226 if (unload_type
< 0) {
1227 unload_type
= order
->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE
? OUFB_UNLOAD
: OUF_UNLOAD_IF_POSSIBLE
;
1230 if (order
->GetUnloadType() != unload_type
) {
1231 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel_ord
<< 20), MOF_UNLOAD
| (unload_type
<< 4), CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
1234 if (unload_type
== OUFB_TRANSFER
) {
1235 /* Transfer orders with leave empty as default */
1236 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel_ord
<< 20), MOF_LOAD
| (OLFB_NO_LOAD
<< 4), CMD_MODIFY_ORDER
);
1237 this->SetWidgetDirty(WID_O_FULL_LOAD
);
1238 } else if(unload_type
== OUFB_CARGO_TYPE_UNLOAD
) {
1239 ShowCargoTypeOrdersWindow(this->vehicle
, this, sel_ord
, CTOWV_UNLOAD
);
1244 * Handle the transfer hotkey
1246 void OrderHotkey_Transfer()
1248 this->OrderClick_Unload(OUFB_TRANSFER
);
1252 * Handle the 'no unload' hotkey
1254 void OrderHotkey_NoUnload()
1256 this->OrderClick_Unload(OUFB_NO_UNLOAD
);
1260 * Handle the click on the nonstop button.
1261 * @param non_stop what non-stop type to use; -1 to use the 'next' one.
1263 void OrderClick_Nonstop(int non_stop
)
1265 if (!this->vehicle
->IsGroundVehicle()) return;
1267 VehicleOrderID sel_ord
= this->OrderGetSel();
1268 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
1270 if (order
== NULL
|| order
->GetNonStopType() == non_stop
) return;
1272 /* Keypress if negative, so 'toggle' to the next */
1274 non_stop
= order
->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
;
1277 this->SetWidgetDirty(WID_O_NON_STOP
);
1278 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel_ord
<< 20), MOF_NON_STOP
| non_stop
<< 4, CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
1282 * Handle the click on the skip button.
1283 * If ctrl is pressed, skip to selected order, else skip to current order + 1
1285 void OrderClick_Skip()
1287 /* Don't skip when there's nothing to skip */
1288 if (_ctrl_pressed
&& this->vehicle
->cur_implicit_order_index
== this->OrderGetSel()) return;
1289 if (this->vehicle
->GetNumOrders() <= 1) return;
1291 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
, _ctrl_pressed
? this->OrderGetSel() : ((this->vehicle
->cur_implicit_order_index
+ 1) % this->vehicle
->GetNumOrders()),
1292 CMD_SKIP_TO_ORDER
| CMD_MSG(_ctrl_pressed
? STR_ERROR_CAN_T_SKIP_TO_ORDER
: STR_ERROR_CAN_T_SKIP_ORDER
));
1296 * Handle the click on the delete button.
1298 void OrderClick_Delete()
1300 /* When networking, move one order lower */
1301 int selected
= this->selected_order
+ (int)_networking
;
1303 if (DoCommandP(this->vehicle
->tile
, this->vehicle
->index
, this->OrderGetSel(), CMD_DELETE_ORDER
| CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER
))) {
1304 this->selected_order
= selected
>= this->vehicle
->GetNumOrders() ? -1 : selected
;
1305 this->UpdateButtonState();
1310 * Handle the click on the 'stop sharing' button.
1311 * If 'End of Shared Orders' isn't selected, do nothing. If Ctrl is pressed, call OrderClick_Delete and exit.
1312 * To stop sharing this vehicle order list, we copy the orders of a vehicle that share this order list. That way we
1313 * exit the group of shared vehicles while keeping the same order list.
1315 void OrderClick_StopSharing()
1317 /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
1318 if (!this->vehicle
->HasSharedOrdersList() || this->selected_order
!= this->vehicle
->GetNumOrders()) return;
1319 /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
1320 if (_ctrl_pressed
) {
1321 this->OrderClick_Delete();
1325 /* Get another vehicle that share orders with this vehicle. */
1326 Vehicle
*other_shared
= (this->vehicle
->FirstShared() == this->vehicle
) ? this->vehicle
->NextShared() : this->vehicle
->PreviousShared();
1327 /* Copy the order list of the other vehicle. */
1328 if (DoCommandP(this->vehicle
->tile
, this->vehicle
->index
| CO_COPY
<< 30, other_shared
->index
, CMD_CLONE_ORDER
| CMD_MSG(STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST
))) {
1329 this->UpdateButtonState();
1334 * Handle the click on the refit button.
1335 * If ctrl is pressed, cancel refitting, else show the refit window.
1336 * @param i Selected refit command.
1337 * @param auto_refit Select refit for auto-refitting.
1339 void OrderClick_Refit(int i
, bool auto_refit
)
1341 if (_ctrl_pressed
) {
1342 /* Cancel refitting */
1343 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
, (this->OrderGetSel() << 16) | (CT_NO_REFIT
<< 8) | CT_NO_REFIT
, CMD_ORDER_REFIT
);
1345 if (i
== 1) { // Auto-refit to available cargo type.
1346 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
, (this->OrderGetSel() << 16) | CT_AUTO_REFIT
, CMD_ORDER_REFIT
);
1348 ShowVehicleRefitWindow(this->vehicle
, this->OrderGetSel(), this, auto_refit
);
1353 /** Cache auto-refittability of the vehicle chain. */
1354 void UpdateAutoRefitState()
1356 this->can_do_refit
= false;
1357 this->can_do_autorefit
= false;
1358 for (const Vehicle
*w
= this->vehicle
; w
!= NULL
; w
= w
->IsGroundVehicle() ? w
->Next() : NULL
) {
1359 if (IsEngineRefittable(w
->engine_type
)) this->can_do_refit
= true;
1360 if (HasBit(Engine::Get(w
->engine_type
)->info
.misc_flags
, EF_AUTO_REFIT
)) this->can_do_autorefit
= true;
1365 OrdersWindow(WindowDesc
*desc
, const Vehicle
*v
) : Window(desc
)
1369 this->CreateNestedTree();
1370 this->vscroll
= this->GetScrollbar(WID_O_SCROLLBAR
);
1371 this->FinishInitNested(v
->index
);
1372 if (v
->owner
== _local_company
) {
1373 this->DisableWidget(WID_O_EMPTY
);
1376 this->selected_order
= -1;
1377 this->order_over
= INVALID_VEH_ORDER_ID
;
1378 this->goto_type
= OPOS_NONE
;
1379 this->owner
= v
->owner
;
1381 this->UpdateAutoRefitState();
1383 if (_settings_client
.gui
.quick_goto
&& v
->owner
== _local_company
) {
1384 /* If there are less than 2 station, make Go To active. */
1385 int station_orders
= 0;
1387 FOR_VEHICLE_ORDERS(v
, order
) {
1388 if (order
->IsType(OT_GOTO_STATION
)) station_orders
++;
1391 if (station_orders
< 2) this->OrderClick_Goto(OPOS_GOTO
);
1393 this->OnInvalidateData(VIWD_MODIFY_ORDERS
);
1398 DeleteWindowById(WC_VEHICLE_CARGO_TYPE_LOAD_ORDERS
, this->window_number
, false);
1399 DeleteWindowById(WC_VEHICLE_CARGO_TYPE_UNLOAD_ORDERS
, this->window_number
, false);
1400 if (!FocusWindowById(WC_VEHICLE_VIEW
, this->window_number
)) {
1401 MarkAllRouteStepsDirty(this->vehicle
);
1405 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
1408 case WID_O_ORDER_LIST
:
1409 resize
->height
= FONT_HEIGHT_NORMAL
;
1410 size
->height
= 6 * resize
->height
+ WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1413 case WID_O_COND_VARIABLE
: {
1414 Dimension d
= {0, 0};
1415 for (uint i
= 0; i
< lengthof(_order_conditional_variable
); i
++) {
1416 d
= maxdim(d
, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE
+ _order_conditional_variable
[i
]));
1418 d
.width
+= padding
.width
;
1419 d
.height
+= padding
.height
;
1420 *size
= maxdim(*size
, d
);
1424 case WID_O_COND_COMPARATOR
: {
1425 Dimension d
= {0, 0};
1426 for (int i
= 0; _order_conditional_condition
[i
] != INVALID_STRING_ID
; i
++) {
1427 d
= maxdim(d
, GetStringBoundingBox(_order_conditional_condition
[i
]));
1429 d
.width
+= padding
.width
;
1430 d
.height
+= padding
.height
;
1431 *size
= maxdim(*size
, d
);
1438 * Some data on this window has become invalid.
1439 * @param data Information about the changed data.
1440 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
1442 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
1444 VehicleOrderID from
= INVALID_VEH_ORDER_ID
;
1445 VehicleOrderID to
= INVALID_VEH_ORDER_ID
;
1448 case VIWD_AUTOREPLACE
:
1449 /* Autoreplace replaced the vehicle */
1450 this->vehicle
= Vehicle::Get(this->window_number
);
1453 case VIWD_CONSIST_CHANGED
:
1454 /* Vehicle composition was changed. */
1455 this->UpdateAutoRefitState();
1458 case VIWD_REMOVE_ALL_ORDERS
:
1459 /* Removed / replaced all orders (after deleting / sharing) */
1460 if (this->selected_order
== -1) break;
1462 this->DeleteChildWindows();
1463 HideDropDownMenu(this);
1464 this->selected_order
= -1;
1467 case VIWD_MODIFY_ORDERS
:
1468 /* Some other order changes */
1472 if (data
< 0) break;
1474 if (gui_scope
) break; // only do this once; from command scope
1475 from
= GB(data
, 0, 8);
1476 to
= GB(data
, 8, 8);
1477 /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
1478 * the order is being created / removed */
1479 if (this->selected_order
== -1) break;
1481 if (from
== to
) break; // no need to change anything
1483 if (from
!= this->selected_order
) {
1484 /* Moving from preceding order? */
1485 this->selected_order
-= (int)(from
<= this->selected_order
);
1486 /* Moving to preceding order? */
1487 this->selected_order
+= (int)(to
<= this->selected_order
);
1491 /* Now we are modifying the selected order */
1492 if (to
== INVALID_VEH_ORDER_ID
) {
1493 /* Deleting selected order */
1494 this->DeleteChildWindows();
1495 HideDropDownMenu(this);
1496 this->selected_order
= -1;
1500 /* Moving selected order */
1501 this->selected_order
= to
;
1505 this->vscroll
->SetCount(this->vehicle
->GetNumOrders() + 1);
1507 this->UpdateButtonState();
1508 InvalidateWindowClassesData(WC_VEHICLE_CARGO_TYPE_LOAD_ORDERS
, 0);
1509 InvalidateWindowClassesData(WC_VEHICLE_CARGO_TYPE_UNLOAD_ORDERS
, 0);
1512 /* Scroll to the new order. */
1513 if (from
== INVALID_VEH_ORDER_ID
&& to
!= INVALID_VEH_ORDER_ID
&& !this->vscroll
->IsVisible(to
)) {
1514 this->vscroll
->ScrollTowards(to
);
1518 void UpdateButtonState()
1520 if (this->vehicle
->owner
!= _local_company
) return; // No buttons are displayed with competitor order windows.
1522 bool shared_orders
= this->vehicle
->HasSharedOrdersList();
1523 VehicleOrderID sel
= this->OrderGetSel();
1524 const Order
*order
= this->vehicle
->GetOrder(sel
);
1528 this->SetWidgetDisabledState(WID_O_SKIP
, this->vehicle
->GetNumOrders() <= 1);
1530 /* delete / stop sharing */
1531 NWidgetStacked
*delete_sel
= this->GetWidget
<NWidgetStacked
>(WID_O_SEL_BOTTOM_MIDDLE
);
1532 if (shared_orders
&& this->selected_order
== this->vehicle
->GetNumOrders()) {
1533 /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
1534 delete_sel
->SetDisplayedPlane(DP_BOTTOM_MIDDLE_STOP_SHARING
);
1536 /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
1537 delete_sel
->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE
);
1538 this->SetWidgetDisabledState(WID_O_DELETE
,
1539 (uint
)this->vehicle
->GetNumOrders() + ((shared_orders
|| this->vehicle
->GetNumOrders() != 0) ? 1 : 0) <= (uint
)this->selected_order
);
1541 /* Set the tooltip of the 'delete' button depending on whether the
1542 * 'End of Orders' order or a regular order is selected. */
1543 NWidgetCore
*nwi
= this->GetWidget
<NWidgetCore
>(WID_O_DELETE
);
1544 if (this->selected_order
== this->vehicle
->GetNumOrders()) {
1545 nwi
->SetDataTip(STR_ORDERS_DELETE_BUTTON
, STR_ORDERS_DELETE_ALL_TOOLTIP
);
1547 nwi
->SetDataTip(STR_ORDERS_DELETE_BUTTON
, STR_ORDERS_DELETE_TOOLTIP
);
1552 this->RaiseWidget(WID_O_FULL_LOAD
);
1553 this->RaiseWidget(WID_O_UNLOAD
);
1554 this->RaiseWidget(WID_O_SERVICE
);
1556 /* Selection widgets. */
1557 /* Train or road vehicle. */
1558 NWidgetStacked
*train_row_sel
= this->GetWidget
<NWidgetStacked
>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE
);
1559 NWidgetStacked
*left_sel
= this->GetWidget
<NWidgetStacked
>(WID_O_SEL_TOP_LEFT
);
1560 NWidgetStacked
*middle_sel
= this->GetWidget
<NWidgetStacked
>(WID_O_SEL_TOP_MIDDLE
);
1561 NWidgetStacked
*right_sel
= this->GetWidget
<NWidgetStacked
>(WID_O_SEL_TOP_RIGHT
);
1562 /* Ship or airplane. */
1563 NWidgetStacked
*row_sel
= this->GetWidget
<NWidgetStacked
>(WID_O_SEL_TOP_ROW
);
1564 assert(row_sel
!= NULL
|| (train_row_sel
!= NULL
&& left_sel
!= NULL
&& middle_sel
!= NULL
&& right_sel
!= NULL
));
1567 if (order
== NULL
) {
1568 if (row_sel
!= NULL
) {
1569 row_sel
->SetDisplayedPlane(DP_ROW_LOAD
);
1571 train_row_sel
->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL
);
1572 left_sel
->SetDisplayedPlane(DP_LEFT_LOAD
);
1573 middle_sel
->SetDisplayedPlane(DP_MIDDLE_UNLOAD
);
1574 right_sel
->SetDisplayedPlane(DP_RIGHT_EMPTY
);
1575 this->DisableWidget(WID_O_NON_STOP
);
1576 this->RaiseWidget(WID_O_NON_STOP
);
1578 this->DisableWidget(WID_O_FULL_LOAD
);
1579 this->DisableWidget(WID_O_UNLOAD
);
1580 this->DisableWidget(WID_O_REFIT_DROPDOWN
);
1582 this->SetWidgetDisabledState(WID_O_FULL_LOAD
, (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) != 0); // full load
1583 this->SetWidgetDisabledState(WID_O_UNLOAD
, (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) != 0); // unload
1585 switch (order
->GetType()) {
1586 case OT_GOTO_STATION
:
1587 if (row_sel
!= NULL
) {
1588 row_sel
->SetDisplayedPlane(DP_ROW_LOAD
);
1590 train_row_sel
->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL
);
1591 left_sel
->SetDisplayedPlane(DP_LEFT_LOAD
);
1592 middle_sel
->SetDisplayedPlane(DP_MIDDLE_UNLOAD
);
1593 right_sel
->SetDisplayedPlane(DP_RIGHT_REFIT
);
1594 this->EnableWidget(WID_O_NON_STOP
);
1595 this->SetWidgetLoweredState(WID_O_NON_STOP
, order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
);
1597 this->SetWidgetLoweredState(WID_O_FULL_LOAD
, order
->GetLoadType() == OLF_FULL_LOAD_ANY
);
1598 this->SetWidgetLoweredState(WID_O_UNLOAD
, order
->GetUnloadType() == OUFB_UNLOAD
);
1600 /* Can only do refitting when stopping at the destination and loading cargo.
1601 * Also enable the button if a refit is already set to allow clearing it. */
1602 this->SetWidgetDisabledState(WID_O_REFIT_DROPDOWN
,
1603 order
->GetLoadType() == OLFB_NO_LOAD
|| (order
->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION
) ||
1604 ((!this->can_do_refit
|| !this->can_do_autorefit
) && !order
->IsRefit()));
1608 case OT_GOTO_WAYPOINT
:
1609 if (row_sel
!= NULL
) {
1610 row_sel
->SetDisplayedPlane(DP_ROW_LOAD
);
1612 train_row_sel
->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL
);
1613 left_sel
->SetDisplayedPlane(DP_LEFT_REVERSE
);
1614 middle_sel
->SetDisplayedPlane(DP_MIDDLE_UNLOAD
);
1615 right_sel
->SetDisplayedPlane(DP_RIGHT_EMPTY
);
1616 this->EnableWidget(WID_O_NON_STOP
);
1617 this->SetWidgetLoweredState(WID_O_NON_STOP
, order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
);
1618 this->EnableWidget(WID_O_REVERSE
);
1619 this->SetWidgetLoweredState(WID_O_REVERSE
, (order
->GetWaypointFlags() & OWF_REVERSE
) != 0);
1621 this->DisableWidget(WID_O_UNLOAD
);
1622 this->DisableWidget(WID_O_REFIT_DROPDOWN
);
1626 if (row_sel
!= NULL
) {
1627 row_sel
->SetDisplayedPlane(DP_ROW_DEPOT
);
1629 train_row_sel
->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL
);
1630 left_sel
->SetDisplayedPlane(DP_LEFT_REFIT
);
1631 middle_sel
->SetDisplayedPlane(DP_MIDDLE_SERVICE
);
1632 right_sel
->SetDisplayedPlane(DP_RIGHT_EMPTY
);
1633 this->EnableWidget(WID_O_NON_STOP
);
1634 this->SetWidgetLoweredState(WID_O_NON_STOP
, order
->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
);
1636 /* Disable refit button if the order is no 'always go' order.
1637 * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
1638 this->SetWidgetDisabledState(WID_O_REFIT
,
1639 (order
->GetDepotOrderType() & ODTFB_SERVICE
) || (order
->GetDepotActionType() & ODATFB_HALT
) ||
1640 (!this->can_do_refit
&& !order
->IsRefit()));
1641 this->SetWidgetLoweredState(WID_O_SERVICE
, order
->GetDepotOrderType() & ODTFB_SERVICE
);
1644 case OT_CONDITIONAL
: {
1645 if (row_sel
!= nullptr) {
1646 row_sel
->SetDisplayedPlane(DP_ROW_CONDITIONAL
);
1648 train_row_sel
->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_CONDITIONAL
);
1651 OrderConditionVariable ocv
= (order
== nullptr) ? OCV_LOAD_PERCENTAGE
: order
->GetConditionVariable();
1652 bool is_cargo
= ocv
== OCV_CARGO_ACCEPTANCE
|| ocv
== OCV_CARGO_WAITING
;
1653 bool is_slot_occupancy
= ocv
== OCV_SLOT_OCCUPANCY
;
1656 CargoSpec
* cargo_spec
= CargoSpec::Get(order
!= nullptr ? order
->GetConditionValue() : 0);
1657 this->GetWidget
<NWidgetCore
>(WID_O_COND_CARGO
)->widget_data
= cargo_spec
->name
;
1658 this->GetWidget
<NWidgetStacked
>(WID_O_SEL_COND_VALUE
)->SetDisplayedPlane(DP_COND_VALUE_CARGO
);
1660 else if (is_slot_occupancy
) {
1661 TraceRestrictSlotID slot_id
= (order
!= nullptr && TraceRestrictSlot::IsValidID(order
->GetConditionValue()) ? order
->GetConditionValue() : INVALID_TRACE_RESTRICT_SLOT_ID
);
1663 this->GetWidget
<NWidgetCore
>(WID_O_COND_SLOT
)->widget_data
= slot_id
!= INVALID_TRACE_RESTRICT_SLOT_ID
? STR_TRACE_RESTRICT_SLOT_NAME
: STR_TRACE_RESTRICT_VARIABLE_UNDEFINED
;
1664 this->GetWidget
<NWidgetStacked
>(WID_O_SEL_COND_VALUE
)->SetDisplayedPlane(DP_COND_VALUE_SLOT
);
1667 this->GetWidget
<NWidgetStacked
>(WID_O_SEL_COND_VALUE
)->SetDisplayedPlane(DP_COND_VALUE_NUMBER
);
1670 /* Set the strings for the dropdown boxes. */
1671 this->GetWidget
<NWidgetCore
>(WID_O_COND_VARIABLE
)->widget_data
= STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE
+ ocv
;
1672 this->GetWidget
<NWidgetCore
>(WID_O_COND_COMPARATOR
)->widget_data
= GetComparatorStrings(order
)[order
== NULL
? 0 : order
->GetConditionComparator()];
1673 this->SetWidgetDisabledState(WID_O_COND_COMPARATOR
, ocv
== OCV_UNCONDITIONALLY
|| ocv
== OCV_PERCENT
);
1674 this->SetWidgetDisabledState(WID_O_COND_VALUE
, ocv
== OCV_REQUIRES_SERVICE
|| ocv
== OCV_UNCONDITIONALLY
);
1678 default: // every other order
1679 if (row_sel
!= NULL
) {
1680 row_sel
->SetDisplayedPlane(DP_ROW_LOAD
);
1682 train_row_sel
->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL
);
1683 left_sel
->SetDisplayedPlane(DP_LEFT_LOAD
);
1684 middle_sel
->SetDisplayedPlane(DP_MIDDLE_UNLOAD
);
1685 right_sel
->SetDisplayedPlane(DP_RIGHT_EMPTY
);
1686 this->DisableWidget(WID_O_NON_STOP
);
1688 this->DisableWidget(WID_O_FULL_LOAD
);
1689 this->DisableWidget(WID_O_UNLOAD
);
1690 this->DisableWidget(WID_O_REFIT_DROPDOWN
);
1695 /* Disable list of vehicles with the same shared orders if there is no list */
1696 this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST
, !shared_orders
);
1701 virtual void OnPaint() override
1703 if (this->vehicle
->owner
!= _local_company
) {
1704 this->selected_order
= -1; // Disable selection any selected row at a competitor order window.
1706 this->SetWidgetLoweredState(WID_O_GOTO
, this->goto_type
!= OPOS_NONE
);
1708 this->DrawWidgets();
1711 virtual void DrawWidget(const Rect
&r
, int widget
) const override
1713 if (widget
!= WID_O_ORDER_LIST
) return;
1715 bool rtl
= _current_text_dir
== TD_RTL
;
1716 SetDParamMaxValue(0, this->vehicle
->GetNumOrders(), 2);
1717 int index_column_width
= GetStringBoundingBox(STR_ORDER_INDEX
).width
+ 2 * GetSpriteSize(rtl
? SPR_ARROW_RIGHT
: SPR_ARROW_LEFT
).width
+ 3;
1718 int middle
= rtl
? r
.right
- WD_FRAMETEXT_RIGHT
- index_column_width
: r
.left
+ WD_FRAMETEXT_LEFT
+ index_column_width
;
1720 int y
= r
.top
+ WD_FRAMERECT_TOP
;
1721 int line_height
= this->GetWidget
<NWidgetBase
>(WID_O_ORDER_LIST
)->resize_y
;
1723 int i
= this->vscroll
->GetPosition();
1724 const Order
*order
= this->vehicle
->GetOrder(i
);
1725 /* First draw the highlighting underground if it exists. */
1726 if (this->order_over
!= INVALID_VEH_ORDER_ID
) {
1727 while (order
!= NULL
) {
1728 /* Don't draw anything if it extends past the end of the window. */
1729 if (!this->vscroll
->IsVisible(i
)) break;
1731 if (i
!= this->selected_order
&& i
== this->order_over
) {
1732 /* Highlight dragged order destination. */
1733 int top
= (this->order_over
< this->selected_order
? y
: y
+ line_height
) - WD_FRAMERECT_TOP
;
1734 int bottom
= min(top
+ 2, r
.bottom
- WD_FRAMERECT_BOTTOM
);
1735 top
= max(top
- 3, r
.top
+ WD_FRAMERECT_TOP
);
1736 GfxFillRect(r
.left
+ WD_FRAMETEXT_LEFT
, top
, r
.right
- WD_FRAMETEXT_RIGHT
, bottom
, _colour_gradient
[COLOUR_GREY
][7]);
1742 order
= order
->next
;
1745 /* Reset counters for drawing the orders. */
1746 y
= r
.top
+ WD_FRAMERECT_TOP
;
1747 i
= this->vscroll
->GetPosition();
1748 order
= this->vehicle
->GetOrder(i
);
1751 /* Draw the orders. */
1752 while (order
!= NULL
) {
1753 /* Don't draw anything if it extends past the end of the window. */
1754 if (!this->vscroll
->IsVisible(i
)) break;
1756 DrawOrderString(this->vehicle
, order
, i
, y
, i
== this->selected_order
, false, r
.left
+ WD_FRAMETEXT_LEFT
, middle
, r
.right
- WD_FRAMETEXT_RIGHT
);
1760 order
= order
->next
;
1763 if (this->vscroll
->IsVisible(i
)) {
1764 StringID str
= this->vehicle
->HasSharedOrdersList() ? STR_ORDERS_END_OF_SHARED_ORDERS
: STR_ORDERS_END_OF_ORDERS
;
1765 DrawString(rtl
? r
.left
+ WD_FRAMETEXT_LEFT
: middle
, rtl
? middle
: r
.right
- WD_FRAMETEXT_RIGHT
, y
, str
, (i
== this->selected_order
) ? TC_WHITE
: TC_BLACK
);
1769 virtual void SetStringParameters(int widget
) const override
1772 case WID_O_COND_VALUE
: {
1773 VehicleOrderID sel
= this->OrderGetSel();
1774 const Order
*order
= this->vehicle
->GetOrder(sel
);
1776 if (order
!= NULL
&& order
->IsType(OT_CONDITIONAL
)) {
1777 uint value
= order
->GetConditionValue();
1778 if (order
->GetConditionVariable() == OCV_MAX_SPEED
) value
= ConvertSpeedToDisplaySpeed(value
);
1779 SetDParam(0, value
);
1784 case WID_O_COND_SLOT
: {
1785 VehicleOrderID sel
= this->OrderGetSel();
1786 const Order
*order
= this->vehicle
->GetOrder(sel
);
1788 if (order
!= nullptr && order
->IsType(OT_CONDITIONAL
)) {
1789 TraceRestrictSlotID value
= order
->GetConditionValue();
1790 SetDParam(0, value
);
1796 SetDParam(0, this->vehicle
->index
);
1801 virtual void OnClick(Point pt
, int widget
, int click_count
) override
1804 case WID_O_ORDER_LIST
: {
1805 if (this->goto_type
== OPOS_CONDITIONAL
) {
1806 VehicleOrderID order_id
= this->GetOrderFromPt(_cursor
.pos
.y
- this->top
);
1807 if (order_id
!= INVALID_VEH_ORDER_ID
) {
1811 order
.MakeConditional(order_id
);
1813 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->OrderGetSel() << 20), order
.Pack(), CMD_INSERT_ORDER
| CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER
));
1815 ResetObjectToPlace();
1819 if (_ctrl_pressed
&& _shift_pressed
) {
1820 const Order
* selected_order
= this->vehicle
->GetOrder(this->selected_order
);
1822 if (selected_order
!= NULL
&& selected_order
->IsType(OrderType::OT_CONDITIONAL
)) {
1823 VehicleOrderID order_id
= this->GetOrderFromPt(_cursor
.pos
.y
- this->top
);
1824 if (order_id
!= INVALID_VEH_ORDER_ID
) {
1825 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
| (this->selected_order
<< 20),
1826 MOF_COND_DESTINATION
| (order_id
<< 4),
1827 CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
1828 MarkAllRoutePathsDirty(this->vehicle
);
1829 MarkAllRouteStepsDirty(this->vehicle
);
1835 VehicleOrderID sel
= this->GetOrderFromPt(pt
.y
);
1837 if (_ctrl_pressed
&& sel
< this->vehicle
->GetNumOrders()) {
1838 TileIndex xy
= this->vehicle
->GetOrder(sel
)->GetLocation(this->vehicle
);
1839 if (xy
!= INVALID_TILE
) ScrollMainWindowToTile(xy
);
1843 /* This order won't be selected any more, close all child windows and dropdowns */
1844 this->DeleteChildWindows();
1845 HideDropDownMenu(this);
1847 if (sel
== INVALID_VEH_ORDER_ID
|| this->vehicle
->owner
!= _local_company
) {
1848 /* Deselect clicked order */
1849 this->selected_order
= -1;
1850 } else if (sel
== this->selected_order
) {
1851 if (this->vehicle
->type
== VEH_TRAIN
&& sel
< this->vehicle
->GetNumOrders()) {
1852 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel
<< 20),
1853 MOF_STOP_LOCATION
| ((this->vehicle
->GetOrder(sel
)->GetStopLocation() + 1) % OSL_END
) << 4,
1854 CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
1857 /* Select clicked order */
1858 this->selected_order
= sel
;
1860 if (this->vehicle
->owner
== _local_company
) {
1861 /* Activate drag and drop */
1862 SetObjectToPlaceWnd(SPR_CURSOR_MOUSE
, PAL_NONE
, HT_DRAG
, this);
1866 this->UpdateButtonState();
1871 this->OrderClick_Skip();
1875 this->OrderClick_Delete();
1878 case WID_O_STOP_SHARING
:
1879 this->OrderClick_StopSharing();
1882 case WID_O_NON_STOP
:
1883 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1884 this->OrderClick_Nonstop(-1);
1886 const Order
*o
= this->vehicle
->GetOrder(this->OrderGetSel());
1887 ShowDropDownMenu(this, _order_non_stop_drowdown
, o
->GetNonStopType(), WID_O_NON_STOP
, 0,
1888 o
->IsType(OT_GOTO_STATION
) ? 0 : (o
->IsType(OT_GOTO_WAYPOINT
) ? 3 : 12), 0, DDSF_LOST_FOCUS
);
1893 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1894 if (this->goto_type
!= OPOS_NONE
) {
1895 ResetObjectToPlace();
1897 this->OrderClick_Goto(OPOS_GOTO
);
1901 switch (this->goto_type
) {
1902 case OPOS_NONE
: sel
= -1; break;
1903 case OPOS_GOTO
: sel
= 0; break;
1904 case OPOS_CONDITIONAL
: sel
= 2; break;
1905 case OPOS_SHARE
: sel
= 3; break;
1906 default: NOT_REACHED();
1908 ShowDropDownMenu(this, this->vehicle
->type
== VEH_AIRCRAFT
? _order_goto_dropdown_aircraft
: _order_goto_dropdown
, sel
, WID_O_GOTO
, 0, 0, 0, DDSF_LOST_FOCUS
);
1912 case WID_O_FULL_LOAD
:
1913 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1914 this->OrderClick_FullLoad(-1);
1916 ShowDropDownMenu(this, _order_full_load_drowdown
, this->vehicle
->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD
, 0, 0xE2 /* 1110 0010 */, 0, DDSF_LOST_FOCUS
);
1921 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1922 this->OrderClick_Unload(-1);
1924 ShowDropDownMenu(this, _order_unload_drowdown
, this->vehicle
->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD
, 0, 0xE8 /* 1110 1000 */, 0, DDSF_LOST_FOCUS
);
1929 this->OrderClick_Refit(0, false);
1933 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1934 this->OrderClick_Service(-1);
1936 ShowDropDownMenu(this, _order_depot_action_dropdown
, DepotActionStringIndex(this->vehicle
->GetOrder(this->OrderGetSel())), WID_O_SERVICE
, 0, 0, 0, DDSF_LOST_FOCUS
);
1940 case WID_O_REFIT_DROPDOWN
:
1941 if (this->GetWidget
<NWidgetLeaf
>(widget
)->ButtonHit(pt
)) {
1942 this->OrderClick_Refit(0, true);
1944 ShowDropDownMenu(this, _order_refit_action_dropdown
, 0, WID_O_REFIT_DROPDOWN
, 0, 0, 0, DDSF_LOST_FOCUS
);
1948 case WID_O_COND_CARGO
: {
1949 DropDownList
*lst
= new DropDownList();
1950 const CargoSpec
*cs
;
1951 FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs
) {
1952 *lst
->Append() = new DropDownListStringItem(cs
->name
, cs
->Index(), false);
1954 if (lst
->Length() == 0) {
1959 uint value
= this->vehicle
->GetOrder(this->OrderGetSel())->GetConditionValue();
1960 ShowDropDownList(this, lst
, value
, WID_O_COND_CARGO
, 0, true);
1964 case WID_O_COND_SLOT
: {
1966 TraceRestrictSlotID value
= this->vehicle
->GetOrder(this->OrderGetSel())->GetConditionValue();
1967 DropDownList
*list
= GetSlotDropDownList(this->vehicle
->owner
, value
, selected
);
1968 if (list
!= nullptr) ShowDropDownList(this, list
, selected
, WID_O_COND_SLOT
, 0, true);
1972 case WID_O_REVERSE
: {
1973 VehicleOrderID sel_ord
= this->OrderGetSel();
1974 const Order
*order
= this->vehicle
->GetOrder(sel_ord
);
1976 if (order
== NULL
) break;
1978 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel_ord
<< 20), MOF_WAYPOINT_FLAGS
| (order
->GetWaypointFlags() ^ OWF_REVERSE
) << 4,
1979 CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
1983 case WID_O_TIMETABLE_VIEW
:
1984 ShowTimetableWindow(this->vehicle
);
1987 case WID_O_COND_VARIABLE
: {
1988 DropDownList
*list
= new DropDownList();
1989 for (uint i
= 0; i
< lengthof(_order_conditional_variable
); i
++) {
1990 *list
->Append() = new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE
+ _order_conditional_variable
[i
], _order_conditional_variable
[i
], false);
1992 ShowDropDownList(this, list
, this->vehicle
->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE
);
1996 case WID_O_COND_COMPARATOR
: {
1997 const Order
*o
= this->vehicle
->GetOrder(this->OrderGetSel());
1998 OrderConditionVariable cond_var
= o
->GetConditionVariable();
1999 ShowDropDownMenu(this, GetComparatorStrings(o
), o
->GetConditionComparator(), WID_O_COND_COMPARATOR
, 0,
2000 (cond_var
== OCV_REQUIRES_SERVICE
||
2001 cond_var
== OCV_CARGO_ACCEPTANCE
||
2002 cond_var
== OCV_CARGO_WAITING
||
2003 cond_var
== OCV_SLOT_OCCUPANCY
) ? 0x3F : 0xC0);
2007 case WID_O_COND_VALUE
: {
2008 const Order
*order
= this->vehicle
->GetOrder(this->OrderGetSel());
2009 uint value
= order
->GetConditionValue();
2010 if (order
->GetConditionVariable() == OCV_MAX_SPEED
) value
= ConvertSpeedToDisplaySpeed(value
);
2011 SetDParam(0, value
);
2012 ShowQueryString(STR_JUST_INT
, STR_ORDER_CONDITIONAL_VALUE_CAPT
, 5, this, CS_NUMERAL
, QSF_NONE
);
2016 case WID_O_SHARED_ORDER_LIST
:
2017 ShowVehicleListWindow(this->vehicle
);
2022 virtual void OnQueryTextFinished(char *str
) override
2024 if (!StrEmpty(str
)) {
2025 VehicleOrderID sel
= this->OrderGetSel();
2026 uint value
= atoi(str
);
2028 switch (this->vehicle
->GetOrder(sel
)->GetConditionVariable()) {
2030 value
= ConvertDisplaySpeedToSpeed(value
);
2034 case OCV_RELIABILITY
:
2035 case OCV_LOAD_PERCENTAGE
:
2036 value
= Clamp(value
, 0, 100);
2042 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (sel
<< 20), MOF_COND_VALUE
| Clamp(value
, 0, 2047) << 4, CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
2046 virtual void OnDropdownSelect(int widget
, int index
) override
2049 case WID_O_NON_STOP
:
2050 this->OrderClick_Nonstop(index
);
2053 case WID_O_FULL_LOAD
:
2054 this->OrderClick_FullLoad(index
);
2058 this->OrderClick_Unload(index
);
2063 case 0: this->OrderClick_Goto(OPOS_GOTO
); break;
2064 case 1: this->OrderClick_NearestDepot(); break;
2065 case 2: this->OrderClick_Goto(OPOS_CONDITIONAL
); break;
2066 case 3: this->OrderClick_Goto(OPOS_SHARE
); break;
2067 default: NOT_REACHED();
2072 this->OrderClick_Service(index
);
2075 case WID_O_REFIT_DROPDOWN
:
2076 this->OrderClick_Refit(index
, true);
2079 case WID_O_COND_VARIABLE
:
2080 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->OrderGetSel() << 20), MOF_COND_VARIABLE
| index
<< 4, CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
2083 case WID_O_COND_COMPARATOR
:
2084 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->OrderGetSel() << 20), MOF_COND_COMPARATOR
| index
<< 4, CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
2087 case WID_O_COND_CARGO
:
2088 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->OrderGetSel() << 20), MOF_COND_VALUE
| index
<< 4, CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
2091 case WID_O_COND_SLOT
:
2092 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->OrderGetSel() << 20), MOF_COND_VALUE
| index
<< 4, CMD_MODIFY_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER
));
2097 virtual void OnDragDrop(Point pt
, int widget
) override
2100 case WID_O_ORDER_LIST
: {
2101 VehicleOrderID from_order
= this->OrderGetSel();
2102 VehicleOrderID to_order
= this->GetOrderFromPt(pt
.y
);
2104 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()) &&
2105 DoCommandP(this->vehicle
->tile
, this->vehicle
->index
, from_order
| (to_order
<< 16), CMD_MOVE_ORDER
| CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER
))) {
2106 this->selected_order
= -1;
2107 this->UpdateButtonState();
2113 this->OrderClick_Delete();
2116 case WID_O_STOP_SHARING
:
2117 this->OrderClick_StopSharing();
2121 ResetObjectToPlace();
2123 if (this->order_over
!= INVALID_VEH_ORDER_ID
) {
2124 /* End of drag-and-drop, hide dragged order destination highlight. */
2125 this->order_over
= INVALID_VEH_ORDER_ID
;
2126 this->SetWidgetDirty(WID_O_ORDER_LIST
);
2130 virtual EventState
OnHotkey(int hotkey
) override
2132 if (this->vehicle
->owner
!= _local_company
) return ES_NOT_HANDLED
;
2135 case OHK_SKIP
: this->OrderClick_Skip(); break;
2136 case OHK_DELETE
: this->OrderClick_Delete(); break;
2137 case OHK_GOTO
: this->OrderClick_Goto(OPOS_GOTO
); break;
2138 case OHK_NONSTOP
: this->OrderClick_Nonstop(-1); break;
2139 case OHK_FULLLOAD
: this->OrderClick_FullLoad(-1); break;
2140 case OHK_UNLOAD
: this->OrderClick_Unload(-1); break;
2141 case OHK_NEAREST_DEPOT
: this->OrderClick_NearestDepot(); break;
2142 case OHK_ALWAYS_SERVICE
: this->OrderClick_Service(-1); break;
2143 case OHK_TRANSFER
: this->OrderHotkey_Transfer(); break;
2144 case OHK_NO_UNLOAD
: this->OrderHotkey_NoUnload(); break;
2145 case OHK_NO_LOAD
: this->OrderHotkey_NoLoad(); break;
2146 default: return ES_NOT_HANDLED
;
2151 virtual void OnPlaceObject(Point pt
, TileIndex tile
) override
2153 if (this->goto_type
== OPOS_GOTO
) {
2154 const Order cmd
= GetOrderCmdFromTile(this->vehicle
, tile
);
2155 if (cmd
.IsType(OT_NOTHING
)) return;
2157 if (DoCommandP(this->vehicle
->tile
, this->vehicle
->index
+ (this->OrderGetSel() << 20), cmd
.Pack(), CMD_INSERT_ORDER
| CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER
))) {
2158 /* With quick goto the Go To button stays active */
2159 if (!_settings_client
.gui
.quick_goto
) ResetObjectToPlace();
2164 virtual bool OnVehicleSelect(const Vehicle
*v
) override
2166 /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
2167 * We disallow copying orders of other vehicles if we already have at least one order entry
2168 * ourself as it easily copies orders of vehicles within a station when we mean the station.
2169 * If you press CTRL on a non-empty orders vehicle a warning message will appear to confirm */
2170 bool share_order
= _ctrl_pressed
|| this->goto_type
== OPOS_SHARE
;
2171 index_vehicle_share
= v
->index
;
2173 if (this->vehicle
->GetNumOrders() != 0) {
2178 STR_SHARE_ORDERS_CAPTION
,
2179 STR_SHARE_ORDERS_QUERY
,
2181 AskShareOrdersCallback
2187 CopyShareOrders(share_order
);
2191 /** Copy or Share the orders of a vehicle
2192 * @param share_order true for sharing, false for copying
2194 void CopyShareOrders(bool share_order
)
2196 if (DoCommandP(this->vehicle
->tile
, this->vehicle
->index
| (share_order
? CO_SHARE
: CO_COPY
) << 30, index_vehicle_share
,
2197 share_order
? CMD_CLONE_ORDER
| CMD_MSG(STR_ERROR_CAN_T_SHARE_ORDER_LIST
) : CMD_CLONE_ORDER
| CMD_MSG(STR_ERROR_CAN_T_COPY_ORDER_LIST
))) {
2198 this->selected_order
= -1;
2199 ResetObjectToPlace();
2203 virtual void OnPlaceObjectAbort() override
2205 this->goto_type
= OPOS_NONE
;
2206 this->SetWidgetDirty(WID_O_GOTO
);
2208 /* Remove drag highlighting if it exists. */
2209 if (this->order_over
!= INVALID_VEH_ORDER_ID
) {
2210 this->order_over
= INVALID_VEH_ORDER_ID
;
2211 this->SetWidgetDirty(WID_O_ORDER_LIST
);
2215 virtual void OnMouseDrag(Point pt
, int widget
) override
2217 if (this->selected_order
!= -1 && widget
== WID_O_ORDER_LIST
) {
2218 /* An order is dragged.. */
2219 VehicleOrderID from_order
= this->OrderGetSel();
2220 VehicleOrderID to_order
= this->GetOrderFromPt(pt
.y
);
2221 uint num_orders
= this->vehicle
->GetNumOrders();
2223 if (from_order
!= INVALID_VEH_ORDER_ID
&& from_order
<= num_orders
) {
2224 if (to_order
!= INVALID_VEH_ORDER_ID
&& to_order
<= num_orders
) { // ..over an existing order.
2225 this->order_over
= to_order
;
2226 this->SetWidgetDirty(widget
);
2227 } else if (from_order
!= to_order
&& this->order_over
!= INVALID_VEH_ORDER_ID
) { // ..outside of the order list.
2228 this->order_over
= INVALID_VEH_ORDER_ID
;
2229 this->SetWidgetDirty(widget
);
2235 virtual void OnResize() override
2237 /* Update the scroll bar */
2238 this->vscroll
->SetCapacityFromWidget(this, WID_O_ORDER_LIST
);
2241 virtual void OnFocus(Window
*previously_focused_window
) override
2243 if (HasFocusedVehicleChanged(this->window_number
, previously_focused_window
)) {
2244 MarkAllRoutePathsDirty(this->vehicle
);
2245 MarkAllRouteStepsDirty(this->vehicle
);
2249 virtual void OnFocusLost(Window
*newly_focused_window
) override
2251 if (HasFocusedVehicleChanged(this->window_number
, newly_focused_window
)) {
2252 MarkAllRoutePathsDirty(this->vehicle
);
2253 MarkAllRouteStepsDirty(this->vehicle
);
2257 const Vehicle
*GetVehicle()
2259 return this->vehicle
;
2262 static HotkeyList hotkeys
;
2266 void AskShareOrdersCallback(Window
*w
, bool confirmed
)
2268 OrdersWindow
*ow
= static_cast<OrdersWindow
*>(w
);
2271 ow
->CopyShareOrders(true);
2276 static Hotkey order_hotkeys
[] = {
2277 Hotkey('D', "skip", OHK_SKIP
),
2278 Hotkey('F', "delete", OHK_DELETE
),
2279 Hotkey('G', "goto", OHK_GOTO
),
2280 Hotkey('H', "nonstop", OHK_NONSTOP
),
2281 Hotkey('J', "fullload", OHK_FULLLOAD
),
2282 Hotkey('K', "unload", OHK_UNLOAD
),
2283 Hotkey((uint16
)0, "nearest_depot", OHK_NEAREST_DEPOT
),
2284 Hotkey((uint16
)0, "always_service", OHK_ALWAYS_SERVICE
),
2285 Hotkey((uint16
)0, "transfer", OHK_TRANSFER
),
2286 Hotkey((uint16
)0, "no_unload", OHK_NO_UNLOAD
),
2287 Hotkey((uint16
)0, "no_load", OHK_NO_LOAD
),
2290 HotkeyList
OrdersWindow::hotkeys("order", order_hotkeys
);
2292 /** Nested widget definition for "your" train orders. */
2293 static const NWidgetPart _nested_orders_train_widgets
[] = {
2294 NWidget(NWID_HORIZONTAL
),
2295 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
2296 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_O_CAPTION
), SetDataTip(STR_ORDERS_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2297 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_TIMETABLE_VIEW
), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW
, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP
),
2298 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
2299 NWidget(WWT_DEFSIZEBOX
, COLOUR_GREY
),
2300 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
2302 NWidget(NWID_HORIZONTAL
),
2303 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_O_ORDER_LIST
), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP
), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR
), EndContainer(),
2304 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_O_SCROLLBAR
),
2307 /* First button row. */
2308 NWidget(NWID_HORIZONTAL
),
2309 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_TOP_ROW_GROUNDVEHICLE
),
2310 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
2311 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_NON_STOP
), SetMinimalSize(93, 12), SetFill(1, 0),
2312 SetDataTip(STR_ORDER_NON_STOP
, STR_ORDER_TOOLTIP_NON_STOP
), SetResize(1, 0),
2313 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_TOP_LEFT
),
2314 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_FULL_LOAD
), SetMinimalSize(93, 12), SetFill(1, 0),
2315 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD
, STR_ORDER_TOOLTIP_FULL_LOAD
), SetResize(1, 0),
2316 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_REFIT
), SetMinimalSize(93, 12), SetFill(1, 0),
2317 SetDataTip(STR_ORDER_REFIT
, STR_ORDER_REFIT_TOOLTIP
), SetResize(1, 0),
2318 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_O_REVERSE
), SetMinimalSize(93, 12), SetFill(1, 0),
2319 SetDataTip(STR_ORDER_REVERSE
, STR_ORDER_REVERSE_TOOLTIP
), SetResize(1, 0),
2321 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_TOP_MIDDLE
),
2322 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_UNLOAD
), SetMinimalSize(93, 12), SetFill(1, 0),
2323 SetDataTip(STR_ORDER_TOGGLE_UNLOAD
, STR_ORDER_TOOLTIP_UNLOAD
), SetResize(1, 0),
2324 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_SERVICE
), SetMinimalSize(93, 12), SetFill(1, 0),
2325 SetDataTip(STR_ORDER_SERVICE
, STR_ORDER_SERVICE_TOOLTIP
), SetResize(1, 0),
2327 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_TOP_RIGHT
),
2328 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_O_EMPTY
), SetMinimalSize(93, 12), SetFill(1, 0),
2329 SetDataTip(STR_ORDER_REFIT
, STR_ORDER_REFIT_TOOLTIP
), SetResize(1, 0),
2330 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_REFIT_DROPDOWN
), SetMinimalSize(93, 12), SetFill(1, 0),
2331 SetDataTip(STR_ORDER_REFIT_AUTO
, STR_ORDER_REFIT_AUTO_TOOLTIP
), SetResize(1, 0),
2334 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
2335 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_O_COND_VARIABLE
), SetMinimalSize(124, 12), SetFill(1, 0),
2336 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP
), SetResize(1, 0),
2337 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_O_COND_COMPARATOR
), SetMinimalSize(124, 12), SetFill(1, 0),
2338 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP
), SetResize(1, 0),
2339 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_COND_VALUE
),
2340 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_COND_VALUE
), SetMinimalSize(124, 12), SetFill(1, 0),
2341 SetDataTip(STR_BLACK_COMMA
, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP
), SetResize(1, 0),
2342 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_O_COND_CARGO
), SetMinimalSize(124, 12), SetFill(1, 0),
2343 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_CARGO_TOOLTIP
), SetResize(1, 0),
2344 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_O_COND_SLOT
), SetMinimalSize(124, 12), SetFill(1, 0),
2345 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_SLOT_TOOLTIP
), SetResize(1, 0),
2349 NWidget(WWT_PUSHIMGBTN
, COLOUR_GREY
, WID_O_SHARED_ORDER_LIST
), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON
, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP
),
2352 /* Second button row. */
2353 NWidget(NWID_HORIZONTAL
),
2354 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
2355 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_SKIP
), SetMinimalSize(124, 12), SetFill(1, 0),
2356 SetDataTip(STR_ORDERS_SKIP_BUTTON
, STR_ORDERS_SKIP_TOOLTIP
), SetResize(1, 0),
2357 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_BOTTOM_MIDDLE
),
2358 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_DELETE
), SetMinimalSize(124, 12), SetFill(1, 0),
2359 SetDataTip(STR_ORDERS_DELETE_BUTTON
, STR_ORDERS_DELETE_TOOLTIP
), SetResize(1, 0),
2360 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_STOP_SHARING
), SetMinimalSize(124, 12), SetFill(1, 0),
2361 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON
, STR_ORDERS_STOP_SHARING_TOOLTIP
), SetResize(1, 0),
2363 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_GOTO
), SetMinimalSize(124, 12), SetFill(1, 0),
2364 SetDataTip(STR_ORDERS_GO_TO_BUTTON
, STR_ORDERS_GO_TO_TOOLTIP
), SetResize(1, 0),
2366 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
2370 static WindowDesc
_orders_train_desc(
2371 WDP_AUTO
, "view_vehicle_orders_train", 384, 100,
2372 WC_VEHICLE_ORDERS
, WC_VEHICLE_VIEW
,
2374 _nested_orders_train_widgets
, lengthof(_nested_orders_train_widgets
),
2375 &OrdersWindow::hotkeys
2378 /** Nested widget definition for "your" orders (non-train). */
2379 static const NWidgetPart _nested_orders_widgets
[] = {
2380 NWidget(NWID_HORIZONTAL
),
2381 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
2382 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_O_CAPTION
), SetDataTip(STR_ORDERS_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2383 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_TIMETABLE_VIEW
), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW
, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP
),
2384 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
2385 NWidget(WWT_DEFSIZEBOX
, COLOUR_GREY
),
2386 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
2388 NWidget(NWID_HORIZONTAL
),
2389 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_O_ORDER_LIST
), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP
), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR
), EndContainer(),
2390 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_O_SCROLLBAR
),
2393 /* First button row. */
2394 NWidget(NWID_HORIZONTAL
),
2395 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_TOP_ROW
),
2396 /* Load + unload + refit buttons. */
2397 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
2398 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_FULL_LOAD
), SetMinimalSize(124, 12), SetFill(1, 0),
2399 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD
, STR_ORDER_TOOLTIP_FULL_LOAD
), SetResize(1, 0),
2400 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_UNLOAD
), SetMinimalSize(124, 12), SetFill(1, 0),
2401 SetDataTip(STR_ORDER_TOGGLE_UNLOAD
, STR_ORDER_TOOLTIP_UNLOAD
), SetResize(1, 0),
2402 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_REFIT_DROPDOWN
), SetMinimalSize(124, 12), SetFill(1, 0),
2403 SetDataTip(STR_ORDER_REFIT_AUTO
, STR_ORDER_REFIT_AUTO_TOOLTIP
), SetResize(1, 0),
2405 /* Refit + service buttons. */
2406 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
2407 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_REFIT
), SetMinimalSize(186, 12), SetFill(1, 0),
2408 SetDataTip(STR_ORDER_REFIT
, STR_ORDER_REFIT_TOOLTIP
), SetResize(1, 0),
2409 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_SERVICE
), SetMinimalSize(124, 12), SetFill(1, 0),
2410 SetDataTip(STR_ORDER_SERVICE
, STR_ORDER_SERVICE_TOOLTIP
), SetResize(1, 0),
2413 /* Buttons for setting a condition. */
2414 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
2415 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_O_COND_VARIABLE
), SetMinimalSize(124, 12), SetFill(1, 0),
2416 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP
), SetResize(1, 0),
2417 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_O_COND_COMPARATOR
), SetMinimalSize(124, 12), SetFill(1, 0),
2418 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP
), SetResize(1, 0),
2419 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_COND_VALUE
),
2420 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_COND_VALUE
), SetMinimalSize(124, 12), SetFill(1, 0),
2421 SetDataTip(STR_BLACK_COMMA
, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP
), SetResize(1, 0),
2422 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_O_COND_CARGO
), SetMinimalSize(124, 12), SetFill(1, 0),
2423 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_CARGO_TOOLTIP
), SetResize(1, 0),
2424 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_O_COND_SLOT
), SetMinimalSize(124, 12), SetFill(1, 0),
2425 SetDataTip(STR_NULL
, STR_ORDER_CONDITIONAL_SLOT_TOOLTIP
), SetResize(1, 0),
2430 NWidget(WWT_PUSHIMGBTN
, COLOUR_GREY
, WID_O_SHARED_ORDER_LIST
), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON
, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP
),
2433 /* Second button row. */
2434 NWidget(NWID_HORIZONTAL
),
2435 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_SKIP
), SetMinimalSize(124, 12), SetFill(1, 0),
2436 SetDataTip(STR_ORDERS_SKIP_BUTTON
, STR_ORDERS_SKIP_TOOLTIP
), SetResize(1, 0),
2437 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_O_SEL_BOTTOM_MIDDLE
),
2438 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_DELETE
), SetMinimalSize(124, 12), SetFill(1, 0),
2439 SetDataTip(STR_ORDERS_DELETE_BUTTON
, STR_ORDERS_DELETE_TOOLTIP
), SetResize(1, 0),
2440 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_STOP_SHARING
), SetMinimalSize(124, 12), SetFill(1, 0),
2441 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON
, STR_ORDERS_STOP_SHARING_TOOLTIP
), SetResize(1, 0),
2443 NWidget(NWID_BUTTON_DROPDOWN
, COLOUR_GREY
, WID_O_GOTO
), SetMinimalSize(124, 12), SetFill(1, 0),
2444 SetDataTip(STR_ORDERS_GO_TO_BUTTON
, STR_ORDERS_GO_TO_TOOLTIP
), SetResize(1, 0),
2445 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
2449 static WindowDesc
_orders_desc(
2450 WDP_AUTO
, "view_vehicle_orders", 384, 100,
2451 WC_VEHICLE_ORDERS
, WC_VEHICLE_VIEW
,
2453 _nested_orders_widgets
, lengthof(_nested_orders_widgets
),
2454 &OrdersWindow::hotkeys
2457 /** Nested widget definition for competitor orders. */
2458 static const NWidgetPart _nested_other_orders_widgets
[] = {
2459 NWidget(NWID_HORIZONTAL
),
2460 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
2461 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_O_CAPTION
), SetDataTip(STR_ORDERS_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2462 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_O_TIMETABLE_VIEW
), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW
, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP
),
2463 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
2464 NWidget(WWT_DEFSIZEBOX
, COLOUR_GREY
),
2465 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
2467 NWidget(NWID_HORIZONTAL
),
2468 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_O_ORDER_LIST
), SetMinimalSize(372, 72), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP
), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR
), EndContainer(),
2469 NWidget(NWID_VERTICAL
),
2470 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_O_SCROLLBAR
),
2471 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
2476 static WindowDesc
_other_orders_desc(
2477 WDP_AUTO
, "view_vehicle_orders_competitor", 384, 86,
2478 WC_VEHICLE_ORDERS
, WC_VEHICLE_VIEW
,
2480 _nested_other_orders_widgets
, lengthof(_nested_other_orders_widgets
),
2481 &OrdersWindow::hotkeys
2484 void ShowOrdersWindow(const Vehicle
*v
)
2486 DeleteWindowById(WC_VEHICLE_DETAILS
, v
->index
, false);
2487 DeleteWindowById(WC_VEHICLE_TIMETABLE
, v
->index
, false);
2488 if (BringWindowToFrontById(WC_VEHICLE_ORDERS
, v
->index
) != NULL
) return;
2490 /* Using a different WindowDescs for _local_company causes problems.
2491 * Due to this we have to close order windows in ChangeWindowOwner/DeleteCompanyWindows,
2492 * because we cannot change switch the WindowDescs and keeping the old WindowDesc results
2493 * in crashed due to missing widges.
2494 * TODO Rewrite the order GUI to not use different WindowDescs.
2496 if (v
->owner
!= _local_company
) {
2497 new OrdersWindow(&_other_orders_desc
, v
);
2499 new OrdersWindow(v
->IsGroundVehicle() ? &_orders_train_desc
: &_orders_desc
, v
);