Fix incorrect tile and trackdir in reserve through program execution
[openttd-joker.git] / src / order_gui.cpp
blobc25aecd9d625b58ba364d5cacb257e85c4f50346
1 /* $Id$ */
3 /*
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/>.
8 */
10 /** @file order_gui.cpp GUI related to orders. */
12 #include "stdafx.h"
13 #include "command_func.h"
14 #include "viewport_func.h"
15 #include "depot_map.h"
16 #include "roadveh.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"
29 #include "hotkeys.h"
30 #include "aircraft.h"
31 #include "engine_func.h"
33 #include "widgets/order_widget.h"
35 #include "safeguards.h"
37 enum CargoTypeOrdersWindowVariant {
38 CTOWV_LOAD = 0,
39 CTOWV_UNLOAD = 1,
42 /** Cargo type orders strings for load dropdowns. */
43 static const StringID _cargo_type_load_order_drowdown[] = {
44 STR_ORDER_DROP_LOAD_IF_POSSIBLE, // OLF_LOAD_IF_POSSIBLE
45 STR_EMPTY,
46 STR_CARGO_TYPE_ORDERS_DROP_FULL_LOAD, // OLFB_FULL_LOAD
47 STR_EMPTY,
48 STR_ORDER_DROP_NO_LOADING, // OLFB_NO_LOAD
49 INVALID_STRING_ID
51 static const uint32 _cargo_type_load_order_drowdown_hidden_mask = 0xA; // 01010
53 /** Cargo type orders strings for unload dropdowns. */
54 static const StringID _cargo_type_unload_order_drowdown[] = {
55 STR_ORDER_DROP_UNLOAD_IF_ACCEPTED, // OUF_UNLOAD_IF_POSSIBLE
56 STR_ORDER_DROP_UNLOAD, // OUFB_UNLOAD
57 STR_ORDER_DROP_TRANSFER, // OUFB_TRANSFER
58 STR_EMPTY,
59 STR_ORDER_DROP_NO_UNLOADING, // OUFB_NO_UNLOAD
60 INVALID_STRING_ID
62 static const uint32 _cargo_type_unload_order_drowdown_hidden_mask = 0x8; // 01000
64 struct CargoTypeOrdersWindow : public Window {
65 private:
66 CargoTypeOrdersWindowVariant variant;
68 const Vehicle *vehicle; ///< Vehicle owning the orders being displayed and manipulated.
69 VehicleOrderID order_id; ///< Index of the order concerned by this window.
71 VehicleOrderID order_count; ///< Count of the orders of the vehicle owning this window
72 const Order *order; ///< Order pointer at construction time;
74 static const uint8 CARGO_ICON_WIDTH = 12;
75 static const uint8 CARGO_ICON_HEIGHT = 8;
77 const StringID *cargo_type_order_dropdown; ///< Strings used to populate order dropdowns.
78 uint32 cargo_type_order_dropdown_hmask; ///< Hidden mask for order dropdowns.
80 uint max_cargo_name_width; ///< Greatest width of cargo names.
81 uint max_cargo_dropdown_width; ///< Greatest width of order names.
83 uint set_to_all_dropdown_sel; ///< Selected entry for the 'set to all' dropdown
85 /**
86 * Initialize \c max_cargo_name_width and \c max_cargo_dropdown_width.
87 * @post \c max_cargo_name_width
88 * @post \c max_cargo_dropdown_width
90 void InitMaxWidgetWidth()
92 this->max_cargo_name_width = 0;
93 for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
94 SetDParam(0, _sorted_cargo_specs[i]->name);
95 this->max_cargo_name_width = max(this->max_cargo_name_width, GetStringBoundingBox(STR_JUST_STRING).width);
97 this->max_cargo_dropdown_width = 0;
98 for (int i = 0; this->cargo_type_order_dropdown[i] != INVALID_STRING_ID; i++) {
99 SetDParam(0, this->cargo_type_order_dropdown[i]);
100 this->max_cargo_dropdown_width = max(this->max_cargo_dropdown_width, GetStringBoundingBox(STR_JUST_STRING).width);
104 /** Populate the selected entry of order dropdowns. */
105 void InitDropdownSelectedTypes()
107 StringID tooltip = STR_CARGO_TYPE_LOAD_ORDERS_DROP_TOOLTIP + this->variant;
108 const Order *order = this->vehicle->GetOrder(this->order_id);
109 for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
110 const CargoSpec *cs = _sorted_cargo_specs[i];
111 CargoID cargo_id = GetCargoIDByBitnum(cs->bitnum);
112 uint8 order_type = (this->variant == CTOWV_LOAD) ? (uint8)order->GetCargoLoadTypeRaw(cargo_id) : (uint8)order->GetCargoUnloadTypeRaw(cargo_id);
113 this->GetWidget<NWidgetCore>(WID_CTO_CARGO_DROPDOWN_FIRST + i)->SetDataTip(this->cargo_type_order_dropdown[order_type], tooltip);
115 this->set_to_all_dropdown_sel = 0;
116 this->GetWidget<NWidgetCore>(WID_CTO_SET_TO_ALL_DROPDOWN)->widget_data = this->cargo_type_order_dropdown[this->set_to_all_dropdown_sel];
120 * Returns the load/unload type of this order for the specified cargo.
121 * @param cargo_id The cargo index for wich we want the load/unload type.
122 * @return an OrderLoadFlags if \c load_variant = true, an OrderUnloadFlags otherwise.
124 uint8 GetOrderActionTypeForCargo(CargoID cargo_id)
126 const Order *order = this->vehicle->GetOrder(this->order_id);
127 return (this->variant == CTOWV_LOAD) ? (uint8)order->GetCargoLoadTypeRaw(cargo_id) : (uint8)order->GetCargoUnloadTypeRaw(cargo_id);
130 bool CheckOrderStillValid() const
132 if (this->vehicle->GetNumOrders() != this->order_count) return false;
133 if (this->vehicle->GetOrder(this->order_id) != this->order) return false;
134 return true;
137 public:
139 * Instantiate a new CargoTypeOrdersWindow.
140 * @param desc The window description.
141 * @param v The vehicle the order belongs to.
142 * @param order_id Which order to display/edit.
143 * @param variant Which aspect of the order to display/edit: load or unload.
144 * @pre \c v != NULL
146 CargoTypeOrdersWindow(WindowDesc *desc, const Vehicle *v, VehicleOrderID order_id, CargoTypeOrdersWindowVariant variant) : Window(desc)
148 this->variant = variant;
149 this->cargo_type_order_dropdown = (this->variant == CTOWV_LOAD) ? _cargo_type_load_order_drowdown : _cargo_type_unload_order_drowdown;
150 this->cargo_type_order_dropdown_hmask = (this->variant == CTOWV_LOAD) ? _cargo_type_load_order_drowdown_hidden_mask : _cargo_type_unload_order_drowdown_hidden_mask;
151 this->InitMaxWidgetWidth();
153 this->vehicle = v;
154 this->order_id = order_id;
155 this->order_count = v->GetNumOrders();
156 this->order = v->GetOrder(order_id);
158 this->CreateNestedTree(desc);
159 this->GetWidget<NWidgetCore>(WID_CTO_CAPTION)->SetDataTip(STR_CARGO_TYPE_ORDERS_LOAD_CAPTION + this->variant, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
160 this->GetWidget<NWidgetCore>(WID_CTO_HEADER)->SetDataTip(STR_CARGO_TYPE_ORDERS_LOAD_TITLE + this->variant, STR_NULL);
161 this->InitDropdownSelectedTypes();
162 this->FinishInitNested(v->index);
164 this->owner = v->owner;
167 ~CargoTypeOrdersWindow()
169 if (!FocusWindowById(WC_VEHICLE_ORDERS, this->window_number)) {
170 MarkAllRouteStepsDirty(this->vehicle);
174 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
176 if (widget == WID_CTO_HEADER) {
177 (*size).height = max((*size).height, (uint) WD_FRAMERECT_TOP + FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM);
178 } else if (WID_CTO_CARGO_LABEL_FIRST <= widget && widget <= WID_CTO_CARGO_LABEL_LAST) {
179 (*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);
180 (*size).height = max((*size).height, (uint) WD_FRAMERECT_TOP + FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM);
181 } else if ((WID_CTO_CARGO_DROPDOWN_FIRST <= widget && widget <= WID_CTO_CARGO_DROPDOWN_LAST) || widget == WID_CTO_SET_TO_ALL_DROPDOWN) {
182 (*size).width = max((*size).width, WD_DROPDOWNTEXT_LEFT + this->max_cargo_dropdown_width + WD_DROPDOWNTEXT_RIGHT + NWidgetLeaf::dropdown_dimension.width);
183 (*size).height = max((*size).height, (uint) WD_DROPDOWNTEXT_TOP + FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_BOTTOM);
184 } else if (widget == WID_CTO_SET_TO_ALL_LABEL) {
185 (*size).width = max((*size).width, this->max_cargo_name_width + WD_FRAMETEXT_RIGHT + padding.width);
186 (*size).height = max((*size).height, (uint) WD_FRAMERECT_TOP + FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM);
190 virtual void DrawWidget(const Rect &r, int widget) const override
192 if (WID_CTO_CARGO_LABEL_FIRST <= widget && widget <= WID_CTO_CARGO_LABEL_LAST) {
193 const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CTO_CARGO_LABEL_FIRST];
194 bool rtl = (_current_text_dir == TD_RTL);
196 /* Draw cargo icon. */
197 int rect_left = rtl ? r.right - WD_FRAMETEXT_RIGHT - this->CARGO_ICON_WIDTH : r.left + WD_FRAMERECT_LEFT;
198 int rect_right = rect_left + this->CARGO_ICON_WIDTH;
199 int rect_top = r.top + WD_FRAMERECT_TOP + ((r.bottom - WD_FRAMERECT_BOTTOM - r.top - WD_FRAMERECT_TOP) - this->CARGO_ICON_HEIGHT) / 2;
200 int rect_bottom = rect_top + this->CARGO_ICON_HEIGHT;
201 GfxFillRect(rect_left, rect_top, rect_right, rect_bottom, PC_BLACK);
202 GfxFillRect(rect_left + 1, rect_top + 1, rect_right - 1, rect_bottom - 1, cs->legend_colour);
204 /* Draw cargo name */
205 int text_left = rtl ? r.left + WD_FRAMETEXT_LEFT : rect_right + WD_FRAMETEXT_LEFT;
206 int text_right = rtl ? rect_left - WD_FRAMETEXT_LEFT : r.right - WD_FRAMETEXT_RIGHT;
207 int text_top = r.top + WD_FRAMERECT_TOP;
208 SetDParam(0, cs->name);
209 DrawString(text_left, text_right, text_top, STR_BLACK_STRING);
213 virtual void OnClick(Point pt, int widget, int click_count) override
215 if (!this->CheckOrderStillValid()) {
216 delete this;
217 return;
219 if (widget == WID_CTO_CLOSEBTN) {
220 delete this;
221 } else if (WID_CTO_CARGO_DROPDOWN_FIRST <= widget && widget <= WID_CTO_CARGO_DROPDOWN_LAST) {
222 const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CTO_CARGO_DROPDOWN_FIRST];
223 CargoID cargo_id = GetCargoIDByBitnum(cs->bitnum);
225 ShowDropDownMenu(this, this->cargo_type_order_dropdown, this->GetOrderActionTypeForCargo(cargo_id), widget, 0, this->cargo_type_order_dropdown_hmask);
226 } else if (widget == WID_CTO_SET_TO_ALL_DROPDOWN) {
227 ShowDropDownMenu(this, this->cargo_type_order_dropdown, this->set_to_all_dropdown_sel, widget, 0, this->cargo_type_order_dropdown_hmask);
231 virtual void OnDropdownSelect(int widget, int action_type) override
233 if (!this->CheckOrderStillValid()) {
234 delete this;
235 return;
237 if (WID_CTO_CARGO_DROPDOWN_FIRST <= widget && widget <= WID_CTO_CARGO_DROPDOWN_LAST) {
238 const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CTO_CARGO_DROPDOWN_FIRST];
239 CargoID cargo_id = GetCargoIDByBitnum(cs->bitnum);
240 uint8 order_action_type = this->GetOrderActionTypeForCargo(cargo_id);
242 if (action_type == order_action_type) return;
244 ModifyOrderFlags mof = (this->variant == CTOWV_LOAD) ? MOF_CARGO_TYPE_LOAD : MOF_CARGO_TYPE_UNLOAD;
245 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));
247 this->GetWidget<NWidgetCore>(widget)->SetDataTip(this->cargo_type_order_dropdown[this->GetOrderActionTypeForCargo(cargo_id)], STR_CARGO_TYPE_LOAD_ORDERS_DROP_TOOLTIP + this->variant);
248 this->SetWidgetDirty(widget);
249 } else if (widget == WID_CTO_SET_TO_ALL_DROPDOWN) {
250 for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
251 this->OnDropdownSelect(i + WID_CTO_CARGO_DROPDOWN_FIRST, action_type);
254 if (action_type != (int) this->set_to_all_dropdown_sel) {
255 this->set_to_all_dropdown_sel = action_type;
256 this->GetWidget<NWidgetCore>(widget)->widget_data = this->cargo_type_order_dropdown[this->set_to_all_dropdown_sel];
257 this->SetWidgetDirty(widget);
262 virtual void SetStringParameters(int widget) const override
264 if (!this->CheckOrderStillValid()) {
265 return;
267 if (widget == WID_CTO_CAPTION) {
268 SetDParam(0, this->vehicle->index);
269 SetDParam(1, this->order_id + 1);
270 SetDParam(2, this->vehicle->GetOrder(this->order_id)->GetDestination());
274 virtual void OnFocus(Window *previously_focused_window) override
276 if (HasFocusedVehicleChanged(this->window_number, previously_focused_window)) {
277 MarkAllRoutePathsDirty(this->vehicle);
278 MarkAllRouteStepsDirty(this->vehicle);
282 virtual void OnFocusLost(Window *newly_focused_window) override
284 if (HasFocusedVehicleChanged(this->window_number, newly_focused_window)) {
285 MarkAllRoutePathsDirty(this->vehicle);
286 MarkAllRouteStepsDirty(this->vehicle);
291 * Some data on this window has become invalid.
292 * @param data Information about the changed data.
293 * @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.
295 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
297 if (!this->CheckOrderStillValid()) {
298 delete this;
299 return;
301 if (gui_scope) {
302 this->InitDropdownSelectedTypes();
303 this->SetDirty();
309 * Make a list of panel for each available cargo type.
310 * Each panel contains a label to display the cargo name.
311 * @param biggest_index Storage for collecting the biggest index used in the returned tree
312 * @return A vertical container of cargo type orders rows.
313 * @post \c *biggest_index contains the largest used index in the tree.
315 static NWidgetBase *MakeCargoTypeOrdersRows(int *biggest_index)
317 NWidgetVertical *ver = new NWidgetVertical;
319 for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
320 /* Cargo row */
321 NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, WID_CTO_CARGO_ROW_FIRST + i);
322 ver->Add(panel);
323 NWidgetHorizontal *horiz = new NWidgetHorizontal;
324 panel->Add(horiz);
325 /* Cargo label */
326 NWidgetBackground *label = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, WID_CTO_CARGO_LABEL_FIRST + i);
327 label->SetFill(1, 0);
328 label->SetResize(1, 0);
329 horiz->Add(label);
330 /* Orders dropdown */
331 NWidgetLeaf *dropdown = new NWidgetLeaf(WWT_DROPDOWN, COLOUR_GREY, WID_CTO_CARGO_DROPDOWN_FIRST + i, STR_NULL, STR_EMPTY);
332 dropdown->SetFill(1, 0);
333 dropdown->SetResize(1, 0);
334 horiz->Add(dropdown);
337 *biggest_index = WID_CTO_CARGO_DROPDOWN_LAST;
338 return ver;
341 /** Widgets definition of CargoTypeOrdersWindow. */
342 static const NWidgetPart _nested_cargo_type_orders_widgets[] = {
343 NWidget(NWID_HORIZONTAL),
344 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
345 NWidget(WWT_CAPTION, COLOUR_GREY, WID_CTO_CAPTION), SetDataTip(STR_NULL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
346 EndContainer(),
347 NWidget(WWT_PANEL, COLOUR_GREY),
348 NWidget(WWT_LABEL, COLOUR_GREY, WID_CTO_HEADER), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_NULL, STR_NULL),
349 EndContainer(),
350 NWidgetFunction(MakeCargoTypeOrdersRows),
351 NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(1, 4), SetFill(1, 0), SetResize(1, 0), EndContainer(), // SPACER
352 NWidget(NWID_HORIZONTAL),
353 NWidget(WWT_PANEL, COLOUR_GREY),
354 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),
355 EndContainer(),
356 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),
357 EndContainer(),
358 NWidget(NWID_HORIZONTAL),
359 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),
360 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
361 EndContainer(),
364 /** Window description for the 'load' variant of CargoTypeOrdersWindow. */
365 static WindowDesc _cargo_type_load_orders_widgets (
366 WDP_AUTO, "view_cargo_type_load_order", 195, 186,
367 WC_VEHICLE_CARGO_TYPE_LOAD_ORDERS, WC_VEHICLE_ORDERS,
368 WDF_CONSTRUCTION,
369 _nested_cargo_type_orders_widgets, lengthof(_nested_cargo_type_orders_widgets)
372 /** Window description for the 'unload' variant of CargoTypeOrdersWindow. */
373 static WindowDesc _cargo_type_unload_orders_widgets (
374 WDP_AUTO, "view_cargo_type_unload_order", 195, 186,
375 WC_VEHICLE_CARGO_TYPE_UNLOAD_ORDERS, WC_VEHICLE_ORDERS,
376 WDF_CONSTRUCTION,
377 _nested_cargo_type_orders_widgets, lengthof(_nested_cargo_type_orders_widgets)
381 * Show the CargoTypeOrdersWindow for an order.
382 * @param v The vehicle the order belongs to.
383 * @param parent The parent window.
384 * @param order_id Which order to display/edit.
385 * @param variant Which aspect of the order to display/edit: load or unload.
386 * @pre \c v != NULL
388 void ShowCargoTypeOrdersWindow(const Vehicle *v, Window *parent, VehicleOrderID order_id, CargoTypeOrdersWindowVariant variant)
390 WindowDesc &desc = (variant == CTOWV_LOAD) ? _cargo_type_load_orders_widgets : _cargo_type_unload_orders_widgets;
391 DeleteWindowById(desc.cls, v->index);
392 CargoTypeOrdersWindow *w = new CargoTypeOrdersWindow(&desc, v, order_id, variant);
393 w->parent = parent;
397 /** Order load types that could be given to station orders. */
398 static const StringID _station_load_types[][9][9] = {
400 /* No refitting. */
402 STR_EMPTY,
403 INVALID_STRING_ID,
404 STR_ORDER_FULL_LOAD,
405 STR_ORDER_FULL_LOAD_ANY,
406 STR_ORDER_NO_LOAD,
407 INVALID_STRING_ID,
408 INVALID_STRING_ID,
409 INVALID_STRING_ID,
410 STR_ORDER_CARGO_TYPE_LOAD,
411 }, {
412 STR_ORDER_UNLOAD,
413 INVALID_STRING_ID,
414 STR_ORDER_UNLOAD_FULL_LOAD,
415 STR_ORDER_UNLOAD_FULL_LOAD_ANY,
416 STR_ORDER_UNLOAD_NO_LOAD,
417 INVALID_STRING_ID,
418 INVALID_STRING_ID,
419 INVALID_STRING_ID,
420 STR_ORDER_UNLOAD_CARGO_TYPE_LOAD,
421 }, {
422 STR_ORDER_TRANSFER,
423 INVALID_STRING_ID,
424 STR_ORDER_TRANSFER_FULL_LOAD,
425 STR_ORDER_TRANSFER_FULL_LOAD_ANY,
426 STR_ORDER_TRANSFER_NO_LOAD,
427 INVALID_STRING_ID,
428 INVALID_STRING_ID,
429 INVALID_STRING_ID,
430 STR_ORDER_TRANSFER_CARGO_TYPE_LOAD,
431 }, {
432 /* Unload and transfer do not work together. */
433 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
434 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
435 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
436 }, {
437 STR_ORDER_NO_UNLOAD,
438 INVALID_STRING_ID,
439 STR_ORDER_NO_UNLOAD_FULL_LOAD,
440 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
441 STR_ORDER_NO_UNLOAD_NO_LOAD,
442 INVALID_STRING_ID,
443 INVALID_STRING_ID,
444 INVALID_STRING_ID,
445 STR_ORDER_NO_UNLOAD_CARGO_TYPE_LOAD,
446 }, {
447 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
448 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
449 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
450 }, {
451 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
452 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
453 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
454 }, {
455 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
456 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
457 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
458 }, {
459 STR_ORDER_CARGO_TYPE_UNLOAD,
460 INVALID_STRING_ID,
461 STR_ORDER_CARGO_TYPE_UNLOAD_FULL_LOAD,
462 STR_ORDER_CARGO_TYPE_UNLOAD_FULL_LOAD_ANY,
463 STR_ORDER_CARGO_TYPE_UNLOAD_NO_LOAD,
464 INVALID_STRING_ID,
465 INVALID_STRING_ID,
466 INVALID_STRING_ID,
467 STR_ORDER_CARGO_TYPE_UNLOAD_CARGO_TYPE_LOAD,
469 }, {
470 /* With auto-refitting. No loading and auto-refitting do not work together. */
472 STR_ORDER_AUTO_REFIT,
473 INVALID_STRING_ID,
474 STR_ORDER_FULL_LOAD_REFIT,
475 STR_ORDER_FULL_LOAD_ANY_REFIT,
476 INVALID_STRING_ID,
477 INVALID_STRING_ID,
478 INVALID_STRING_ID,
479 INVALID_STRING_ID,
480 STR_ORDER_CARGO_TYPE_LOAD_REFIT,
481 }, {
482 STR_ORDER_UNLOAD_REFIT,
483 INVALID_STRING_ID,
484 STR_ORDER_UNLOAD_FULL_LOAD_REFIT,
485 STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT,
486 INVALID_STRING_ID,
487 INVALID_STRING_ID,
488 INVALID_STRING_ID,
489 INVALID_STRING_ID,
490 STR_ORDER_UNLOAD_CARGO_TYPE_LOAD_REFIT,
491 }, {
492 STR_ORDER_TRANSFER_REFIT,
493 INVALID_STRING_ID,
494 STR_ORDER_TRANSFER_FULL_LOAD_REFIT,
495 STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT,
496 INVALID_STRING_ID,
497 INVALID_STRING_ID,
498 INVALID_STRING_ID,
499 INVALID_STRING_ID,
500 STR_ORDER_TRANSFER_CARGO_TYPE_LOAD_REFIT,
501 }, {
502 /* Unload and transfer do not work together. */
503 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
504 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
505 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
506 }, {
507 STR_ORDER_NO_UNLOAD_REFIT,
508 INVALID_STRING_ID,
509 STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT,
510 STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT,
511 INVALID_STRING_ID,
512 INVALID_STRING_ID,
513 INVALID_STRING_ID,
514 INVALID_STRING_ID,
515 STR_ORDER_NO_UNLOAD_CARGO_TYPE_LOAD_REFIT,
516 }, {
517 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
518 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
519 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
520 }, {
521 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
522 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
523 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
524 }, {
525 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
526 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
527 INVALID_STRING_ID, INVALID_STRING_ID, INVALID_STRING_ID,
528 }, {
529 STR_ORDER_CARGO_TYPE_UNLOAD_REFIT,
530 INVALID_STRING_ID,
531 STR_ORDER_CARGO_TYPE_UNLOAD_FULL_LOAD_REFIT,
532 STR_ORDER_CARGO_TYPE_UNLOAD_FULL_LOAD_ANY_REFIT,
533 INVALID_STRING_ID,
534 INVALID_STRING_ID,
535 INVALID_STRING_ID,
536 INVALID_STRING_ID,
537 STR_ORDER_CARGO_TYPE_UNLOAD_CARGO_TYPE_LOAD_REFIT,
542 static const StringID _order_non_stop_drowdown[] = {
543 STR_ORDER_GO_TO,
544 STR_ORDER_GO_NON_STOP_TO,
545 STR_ORDER_GO_VIA,
546 STR_ORDER_GO_NON_STOP_VIA,
547 INVALID_STRING_ID
550 static const StringID _order_full_load_drowdown[] = {
551 STR_ORDER_DROP_LOAD_IF_POSSIBLE,
552 STR_EMPTY,
553 STR_ORDER_DROP_FULL_LOAD_ALL,
554 STR_ORDER_DROP_FULL_LOAD_ANY,
555 STR_ORDER_DROP_NO_LOADING,
556 STR_EMPTY,
557 STR_EMPTY,
558 STR_EMPTY,
559 STR_ORDER_DROP_CARGO_TYPE_LOAD,
560 INVALID_STRING_ID
563 static const StringID _order_unload_drowdown[] = {
564 STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
565 STR_ORDER_DROP_UNLOAD,
566 STR_ORDER_DROP_TRANSFER,
567 STR_EMPTY,
568 STR_ORDER_DROP_NO_UNLOADING,
569 STR_EMPTY,
570 STR_EMPTY,
571 STR_EMPTY,
572 STR_ORDER_DROP_CARGO_TYPE_UNLOAD,
573 INVALID_STRING_ID
576 static const StringID _order_goto_dropdown[] = {
577 STR_ORDER_GO_TO,
578 STR_ORDER_GO_TO_NEAREST_DEPOT,
579 STR_ORDER_CONDITIONAL,
580 STR_ORDER_SHARE,
581 INVALID_STRING_ID
584 static const StringID _order_goto_dropdown_aircraft[] = {
585 STR_ORDER_GO_TO,
586 STR_ORDER_GO_TO_NEAREST_HANGAR,
587 STR_ORDER_CONDITIONAL,
588 STR_ORDER_SHARE,
589 INVALID_STRING_ID
592 /** Variables for conditional orders; this defines the order of appearance in the dropdown box */
593 static const OrderConditionVariable _order_conditional_variable[] = {
594 OCV_LOAD_PERCENTAGE,
595 OCV_RELIABILITY,
596 OCV_MAX_SPEED,
597 OCV_AGE,
598 OCV_REMAINING_LIFETIME,
599 OCV_REQUIRES_SERVICE,
600 OCV_CARGO_WAITING,
601 OCV_CARGO_ACCEPTANCE,
602 OCV_FREE_PLATFORMS,
603 OCV_PERCENT,
604 OCV_UNCONDITIONALLY,
607 static const StringID _order_conditional_condition[] = {
608 STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
609 STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
610 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
611 STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
612 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
613 STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
614 STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
615 STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
616 INVALID_STRING_ID,
619 static const StringID _order_conditional_condition_has[] = {
620 STR_ORDER_CONDITIONAL_COMPARATOR_HAS,
621 STR_ORDER_CONDITIONAL_COMPARATOR_HAS_NO,
622 STR_ORDER_CONDITIONAL_COMPARATOR_HAS_LESS_THAN,
623 STR_ORDER_CONDITIONAL_COMPARATOR_HAS_LESS_EQUALS,
624 STR_ORDER_CONDITIONAL_COMPARATOR_HAS_MORE_THAN,
625 STR_ORDER_CONDITIONAL_COMPARATOR_HAS_MORE_EQUALS,
626 STR_ORDER_CONDITIONAL_COMPARATOR_HAS,
627 STR_ORDER_CONDITIONAL_COMPARATOR_HAS_NO,
628 INVALID_STRING_ID,
631 static const StringID _order_conditional_condition_accepts[] = {
632 STR_NULL,
633 STR_NULL,
634 STR_NULL,
635 STR_NULL,
636 STR_NULL,
637 STR_NULL,
638 STR_ORDER_CONDITIONAL_COMPARATOR_ACCEPTS,
639 STR_ORDER_CONDITIONAL_COMPARATOR_DOES_NOT_ACCEPT,
640 INVALID_STRING_ID,
643 extern uint ConvertSpeedToDisplaySpeed(uint speed);
644 extern uint ConvertDisplaySpeedToSpeed(uint speed);
646 static const StringID _order_depot_action_dropdown[] = {
647 STR_ORDER_DROP_GO_ALWAYS_DEPOT,
648 STR_ORDER_DROP_SERVICE_DEPOT,
649 STR_ORDER_DROP_HALT_DEPOT,
650 INVALID_STRING_ID
653 static int DepotActionStringIndex(const Order *order)
655 if (order->GetDepotActionType() & ODATFB_HALT) {
656 return DA_STOP;
657 } else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
658 return DA_SERVICE;
659 } else {
660 return DA_ALWAYS_GO;
664 static const StringID _order_refit_action_dropdown[] = {
665 STR_ORDER_DROP_REFIT_AUTO,
666 STR_ORDER_DROP_REFIT_AUTO_ANY,
667 INVALID_STRING_ID
671 * Draws an order in order or timetable GUI
672 * @param v Vehicle the order belongs to
673 * @param order The order to draw
674 * @param order_index Index of the order in the orders of the vehicle
675 * @param y Y position for drawing
676 * @param selected True, if the order is selected
677 * @param timetable True, when drawing in the timetable GUI
678 * @param left Left border for text drawing
679 * @param middle X position between order index and order text
680 * @param right Right border for text drawing
682 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
684 bool rtl = _current_text_dir == TD_RTL;
686 SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT;
687 Dimension sprite_size = GetSpriteSize(sprite);
688 if (v->cur_real_order_index == order_index) {
689 DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
690 DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
691 } else if (v->cur_implicit_order_index == order_index) {
692 DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
695 TextColour colour = TC_BLACK;
696 if (order->IsType(OT_IMPLICIT)) {
697 colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
698 } else if (selected) {
699 colour = TC_WHITE;
702 SetDParam(0, order_index + 1);
703 DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, STR_ORDER_INDEX, colour, SA_RIGHT | SA_FORCE);
705 SetDParam(5, STR_EMPTY);
706 SetDParam(8, STR_EMPTY);
708 /* Check range for aircraft. */
709 if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
710 const Order *next = order->next != NULL ? order->next : v->GetFirstOrder();
711 if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) SetDParam(8, STR_ORDER_OUT_OF_RANGE);
714 switch (order->GetType()) {
715 case OT_DUMMY:
716 SetDParam(0, STR_INVALID_ORDER);
717 SetDParam(1, order->GetDestination());
718 break;
720 case OT_IMPLICIT:
721 SetDParam(0, STR_ORDER_GO_TO_STATION);
722 SetDParam(1, STR_ORDER_GO_TO);
723 SetDParam(2, order->GetDestination());
724 SetDParam(3, timetable ? STR_EMPTY : STR_ORDER_IMPLICIT);
725 break;
727 case OT_GOTO_STATION: {
728 OrderLoadFlags load = order->GetLoadType();
729 OrderUnloadFlags unload = order->GetUnloadType();
731 SetDParam(0, STR_ORDER_GO_TO_STATION);
732 SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
733 SetDParam(2, order->GetDestination());
735 if (timetable) {
736 SetDParam(3, STR_EMPTY);
738 if (order->GetWaitTime() > 0) {
739 SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR : STR_TIMETABLE_STAY_FOR_ESTIMATED);
740 SetTimetableParams(6, 7, order->GetWaitTime());
742 } else {
743 SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]);
744 if (order->IsRefit()) {
745 SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
747 if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
748 SetDParam(5, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
751 break;
754 case OT_GOTO_DEPOT:
755 if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
756 SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
757 if (v->type == VEH_AIRCRAFT) {
758 SetDParam(2, STR_ORDER_NEAREST_HANGAR);
759 SetDParam(3, STR_EMPTY);
760 } else {
761 SetDParam(2, STR_ORDER_NEAREST_DEPOT);
762 SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type);
764 } else {
765 SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT);
766 SetDParam(2, v->type);
767 SetDParam(3, order->GetDestination());
770 if (order->GetDepotOrderType() & ODTFB_SERVICE) {
771 SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
772 } else {
773 SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
776 if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
777 SetDParam(5, STR_ORDER_STOP_ORDER);
780 if (!timetable && order->IsRefit()) {
781 SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER);
782 SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name);
785 if (timetable) {
786 if (order->GetWaitTime() > 0) {
787 SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR : STR_TIMETABLE_STAY_FOR_ESTIMATED);
788 SetTimetableParams(6, 7, order->GetWaitTime());
791 break;
793 case OT_GOTO_WAYPOINT: {
794 StringID str = (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT;
795 if (order->GetWaypointFlags() & OWF_REVERSE) str += STR_ORDER_GO_TO_WAYPOINT_REVERSE - STR_ORDER_GO_TO_WAYPOINT;
796 SetDParam(0, str);
797 SetDParam(1, order->GetDestination());
798 break;
801 case OT_CONDITIONAL: {
802 SetDParam(1, order->GetConditionSkipToOrder() + 1);
803 const OrderConditionVariable ocv = order->GetConditionVariable();
804 /* handle some non-ordinary cases seperately */
805 if (ocv == OCV_UNCONDITIONALLY) {
806 SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
808 else if (ocv == OCV_PERCENT) {
809 SetDParam(0, STR_CONDITIONAL_PERCENT);
810 SetDParam(2, order->GetConditionValue());
812 else if (ocv == OCV_FREE_PLATFORMS) {
813 SetDParam(0, STR_CONDITIONAL_FREE_PLATFORMS);
814 SetDParam(2, STR_ORDER_CONDITIONAL_COMPARATOR_HAS + order->GetConditionComparator());
815 SetDParam(3, order->GetConditionValue());
817 else {
818 OrderConditionComparator occ = order->GetConditionComparator();
819 bool is_cargo = ocv == OCV_CARGO_ACCEPTANCE || ocv == OCV_CARGO_WAITING;
820 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);
821 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);
823 uint value = order->GetConditionValue();
824 switch (ocv) {
825 case OCV_CARGO_ACCEPTANCE:
826 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_ACCEPTS + occ - OCC_IS_TRUE);
827 SetDParam(4, CargoSpec::Get(value)->name);
828 break;
829 case OCV_CARGO_WAITING:
830 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_HAS + occ - OCC_IS_TRUE);
831 SetDParam(4, CargoSpec::Get(value)->name);
832 break;
833 case OCV_REQUIRES_SERVICE:
834 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
835 break;
836 case OCV_MAX_SPEED:
837 value = ConvertSpeedToDisplaySpeed(value);
838 /* FALL THROUGH */
839 default:
840 SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
841 SetDParam(4, value);
845 if (timetable && order->GetWaitTime() > 0) {
846 SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_AND_TRAVEL_FOR : STR_TIMETABLE_AND_TRAVEL_FOR_ESTIMATED);
847 SetTimetableParams(6, 7, order->GetWaitTime());
849 else {
850 SetDParam(5, STR_EMPTY);
852 break;
855 default: NOT_REACHED();
858 DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
862 * Get the order command a vehicle can do in a given tile.
863 * @param v Vehicle involved.
864 * @param tile Tile being queried.
865 * @return The order associated to vehicle v in given tile (or empty order if vehicle can do nothing in the tile).
867 static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
869 /* Hack-ish; unpack order 0, so everything gets initialised with either zero
870 * or a suitable default value for the variable. Then also override the index
871 * as it is not coming from a pool, so would be initialised. */
872 Order order(0);
873 order.index = 0;
875 /* check depot first */
876 if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) {
877 order.MakeGoToDepot(v->type == VEH_AIRCRAFT ? GetStationIndex(tile) : GetDepotIndex(tile),
878 ODTFB_PART_OF_ORDERS,
879 (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
881 if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
883 return order;
886 /* check rail waypoint */
887 if (IsRailWaypointTile(tile) &&
888 v->type == VEH_TRAIN &&
889 IsTileOwner(tile, _local_company)) {
890 order.MakeGoToWaypoint(GetStationIndex(tile));
891 if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
892 return order;
895 /* check buoy (no ownership) */
896 if (IsBuoyTile(tile) && v->type == VEH_SHIP) {
897 order.MakeGoToWaypoint(GetStationIndex(tile));
898 return order;
901 if (IsTileType(tile, MP_STATION)) {
902 StationID st_index = GetStationIndex(tile);
903 const Station *st = Station::Get(st_index);
905 if (st->owner == _local_company || st->owner == OWNER_NONE) {
906 byte facil;
907 (facil = FACIL_DOCK, v->type == VEH_SHIP) ||
908 (facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
909 (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
910 (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
911 (facil = FACIL_TRUCK_STOP, 1);
912 if (st->facilities & facil) {
913 order.MakeGoToStation(st_index);
915 if (_ctrl_pressed && !_shift_pressed) {
916 order.SetLoadType(OLF_FULL_LOAD_ANY);
917 order.SetUnloadType(OUFB_NO_UNLOAD);
918 } else if (!_ctrl_pressed && _shift_pressed) {
919 order.SetLoadType(OLFB_NO_LOAD);
920 order.SetUnloadType(OUFB_UNLOAD);
921 } else if (_ctrl_pressed && _shift_pressed) {
922 order.SetLoadType(OLFB_NO_LOAD);
923 order.SetUnloadType(OUFB_TRANSFER);
926 if (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) {
927 if (order.GetNonStopType() == ONSF_NO_STOP_AT_DESTINATION_STATION) {
928 order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
929 } else {
930 order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
934 order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OSL_PLATFORM_FAR_END);
935 return order;
940 /* not found */
941 order.Free();
942 return order;
945 /** Hotkeys for order window. */
946 enum {
947 OHK_SKIP,
948 OHK_DELETE,
949 OHK_GOTO,
950 OHK_NONSTOP,
951 OHK_FULLLOAD,
952 OHK_UNLOAD,
953 OHK_NEAREST_DEPOT,
954 OHK_ALWAYS_SERVICE,
955 OHK_TRANSFER,
956 OHK_NO_UNLOAD,
957 OHK_NO_LOAD,
962 /** Confirm replacement of the existing orders with shared orders
963 * @param w parent Window
964 * @param confirmed true if confirmed, false otherwise
966 void AskShareOrdersCallback(Window *w, bool confirmed);
971 * %Order window code for all vehicles.
973 * At the bottom of the window two button rows are located for changing the orders of the vehicle.
975 * \section top-row Top row
976 * 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.
978 * The top-row buttons of one of your trains or road vehicles is one of the following three cases:
979 * \verbatim
980 * +-----------------+-----------------+-----------------+-----------------+
981 * | NON-STOP | FULL_LOAD | UNLOAD | REFIT | (normal)
982 * +-----------------+-----+-----------+-----------+-----+-----------------+
983 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
984 * +-----------------+-----+-----------+-----------+-----+-----------------+
985 * | NON-STOP | REFIT | SERVICE | (empty) | (for depot orders)
986 * +-----------------+-----------------+-----------------+-----------------+
987 * \endverbatim
989 * Airplanes and ships have one of the following three top-row button rows:
990 * \verbatim
991 * +-----------------+-----------------+-----------------+
992 * | FULL_LOAD | UNLOAD | REFIT | (normal)
993 * +-----------------+-----------------+-----------------+
994 * | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
995 * +-----------------+--------+--------+-----------------+
996 * | REFIT | SERVICE | (for depot order)
997 * +--------------------------+--------------------------+
998 * \endverbatim
1000 * \section bottom-row Bottom row
1001 * The second row (the bottom row) is for manipulating the list of orders:
1002 * \verbatim
1003 * +-----------------+-----------------+-----------------+
1004 * | SKIP | DELETE | GOTO |
1005 * +-----------------+-----------------+-----------------+
1006 * \endverbatim
1008 * For vehicles of other companies, both button rows are not displayed.
1010 struct OrdersWindow : public Window {
1011 private:
1012 /** Under what reason are we using the PlaceObject functionality? */
1013 enum OrderPlaceObjectState {
1014 OPOS_NONE,
1015 OPOS_GOTO,
1016 OPOS_CONDITIONAL,
1017 OPOS_SHARE,
1018 OPOS_END,
1021 /** Displayed planes of the #NWID_SELECTION widgets. */
1022 enum DisplayPane {
1023 /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
1024 DP_GROUNDVEHICLE_ROW_NORMAL = 0, ///< Display the row for normal/depot orders in the top row of the train/rv order window.
1025 DP_GROUNDVEHICLE_ROW_CONDITIONAL = 1, ///< Display the row for conditional orders in the top row of the train/rv order window.
1027 /* WID_O_SEL_TOP_LEFT */
1028 DP_LEFT_LOAD = 0, ///< Display 'load' in the left button of the top row of the train/rv order window.
1029 DP_LEFT_REFIT = 1, ///< Display 'refit' in the left button of the top row of the train/rv order window.
1030 DP_LEFT_REVERSE = 2, ///< Display 'reverse' in the left button of the top row of the train/rv order window.
1032 /* WID_O_SEL_TOP_MIDDLE */
1033 DP_MIDDLE_UNLOAD = 0, ///< Display 'unload' in the middle button of the top row of the train/rv order window.
1034 DP_MIDDLE_SERVICE = 1, ///< Display 'service' in the middle button of the top row of the train/rv order window.
1036 /* WID_O_SEL_TOP_RIGHT */
1037 DP_RIGHT_EMPTY = 0, ///< Display an empty panel in the right button of the top row of the train/rv order window.
1038 DP_RIGHT_REFIT = 1, ///< Display 'refit' in the right button of the top row of the train/rv order window.
1040 /* WID_O_SEL_TOP_ROW */
1041 DP_ROW_LOAD = 0, ///< Display 'load' / 'unload' / 'refit' buttons in the top row of the ship/airplane order window.
1042 DP_ROW_DEPOT = 1, ///< Display 'refit' / 'service' buttons in the top row of the ship/airplane order window.
1043 DP_ROW_CONDITIONAL = 2, ///< Display the conditional order buttons in the top row of the ship/airplane order window.
1045 /* WID_O_SEL_COND_VALUE */
1046 DP_COND_VALUE_NUMBER = 0, ///< Display number widget
1047 DP_COND_VALUE_CARGO = 1, ///< Display dropdown widget cargo types
1049 /* WID_O_SEL_BOTTOM_MIDDLE */
1050 DP_BOTTOM_MIDDLE_DELETE = 0, ///< Display 'delete' in the middle button of the bottom row of the vehicle order window.
1051 DP_BOTTOM_MIDDLE_STOP_SHARING = 1, ///< Display 'stop sharing' in the middle button of the bottom row of the vehicle order window.
1054 int selected_order;
1055 VehicleOrderID order_over; ///< Order over which another order is dragged, \c INVALID_VEH_ORDER_ID if none.
1056 OrderPlaceObjectState goto_type;
1057 const Vehicle *vehicle; ///< Vehicle owning the orders being displayed and manipulated.
1058 Scrollbar *vscroll;
1059 bool can_do_refit; ///< Vehicle chain can be refitted in depot.
1060 bool can_do_autorefit; ///< Vehicle chain can be auto-refitted.
1061 uint32 index_vehicle_share; ///< index of vehicle to share
1064 * Return the memorised selected order.///
1065 * @return the memorised order if it is a valid one
1066 * else return the number of orders
1068 VehicleOrderID OrderGetSel() const
1070 int num = this->selected_order;
1071 return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
1075 * Calculate the selected order.
1076 * The calculation is based on the relative (to the window) y click position and
1077 * the position of the scrollbar.
1079 * @param y Y-value of the click relative to the window origin
1080 * @return The selected order if the order is valid, else return \c INVALID_VEH_ORDER_ID.
1082 VehicleOrderID GetOrderFromPt(int y)
1084 NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST);
1085 int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
1087 if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID;
1089 sel += this->vscroll->GetPosition();
1091 return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID;
1095 * Determine which strings should be displayed in the conditional comparator dropdown
1097 * @param order the order to evaluate
1098 * @return the StringIDs to display
1100 static const StringID *GetComparatorStrings(const Order *order)
1102 if (order == NULL) return _order_conditional_condition;
1103 switch (order->GetConditionVariable()) {
1104 case OCV_FREE_PLATFORMS: //fall through
1105 case OCV_CARGO_WAITING: return _order_conditional_condition_has; break;
1106 case OCV_CARGO_ACCEPTANCE: return _order_conditional_condition_accepts; break;
1107 default: return _order_conditional_condition; break;
1112 * Handle the click on the goto button.
1114 void OrderClick_Goto(OrderPlaceObjectState type)
1116 assert(type > OPOS_NONE && type < OPOS_END);
1118 static const HighLightStyle goto_place_style[OPOS_END - 1] = {
1119 HT_RECT | HT_VEHICLE, // OPOS_GOTO
1120 HT_NONE, // OPOS_CONDITIONAL
1121 HT_VEHICLE, // OPOS_SHARE
1123 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, goto_place_style[type - 1], this);
1124 this->goto_type = type;
1125 this->SetWidgetDirty(WID_O_GOTO);
1129 * Handle the click on the full load button.
1130 * @param load_type the way to load.
1132 void OrderClick_FullLoad(int load_type)
1134 VehicleOrderID sel_ord = this->OrderGetSel();
1135 const Order *order = this->vehicle->GetOrder(sel_ord);
1137 if (order == NULL || (order->GetLoadType() == load_type && load_type != OLFB_CARGO_TYPE_LOAD)) return;
1139 if (load_type < 0) {
1140 load_type = order->GetLoadType() == OLF_LOAD_IF_POSSIBLE ? OLF_FULL_LOAD_ANY : OLF_LOAD_IF_POSSIBLE;
1142 if (order->GetLoadType() != load_type) {
1143 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));
1146 if (load_type == OLFB_CARGO_TYPE_LOAD) ShowCargoTypeOrdersWindow(this->vehicle, this, sel_ord, CTOWV_LOAD);
1150 * Handle the 'no loading' hotkey
1152 void OrderHotkey_NoLoad()
1154 this->OrderClick_FullLoad(OLFB_NO_LOAD);
1158 * Handle the click on the service.
1160 void OrderClick_Service(int i)
1162 VehicleOrderID sel_ord = this->OrderGetSel();
1164 if (i < 0) {
1165 const Order *order = this->vehicle->GetOrder(sel_ord);
1166 if (order == NULL) return;
1167 i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
1169 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));
1173 * Handle the click on the service in nearest depot button.
1175 void OrderClick_NearestDepot()
1177 Order order;
1178 order.next = NULL;
1179 order.index = 0;
1180 order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS,
1181 _settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
1182 order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
1184 DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
1188 * Handle the click on the unload button.
1190 void OrderClick_Unload(int unload_type)
1192 VehicleOrderID sel_ord = this->OrderGetSel();
1193 const Order *order = this->vehicle->GetOrder(sel_ord);
1195 if (order == NULL || (order->GetUnloadType() == unload_type && unload_type != OUFB_CARGO_TYPE_UNLOAD)) return;
1197 if (unload_type < 0) {
1198 unload_type = order->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE ? OUFB_UNLOAD : OUF_UNLOAD_IF_POSSIBLE;
1201 if (order->GetUnloadType() != unload_type) {
1202 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));
1205 if (unload_type == OUFB_TRANSFER) {
1206 /* Transfer orders with leave empty as default */
1207 DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), CMD_MODIFY_ORDER);
1208 this->SetWidgetDirty(WID_O_FULL_LOAD);
1209 } else if(unload_type == OUFB_CARGO_TYPE_UNLOAD) {
1210 ShowCargoTypeOrdersWindow(this->vehicle, this, sel_ord, CTOWV_UNLOAD);
1215 * Handle the transfer hotkey
1217 void OrderHotkey_Transfer()
1219 this->OrderClick_Unload(OUFB_TRANSFER);
1223 * Handle the 'no unload' hotkey
1225 void OrderHotkey_NoUnload()
1227 this->OrderClick_Unload(OUFB_NO_UNLOAD);
1231 * Handle the click on the nonstop button.
1232 * @param non_stop what non-stop type to use; -1 to use the 'next' one.
1234 void OrderClick_Nonstop(int non_stop)
1236 if (!this->vehicle->IsGroundVehicle()) return;
1238 VehicleOrderID sel_ord = this->OrderGetSel();
1239 const Order *order = this->vehicle->GetOrder(sel_ord);
1241 if (order == NULL || order->GetNonStopType() == non_stop) return;
1243 /* Keypress if negative, so 'toggle' to the next */
1244 if (non_stop < 0) {
1245 non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
1248 this->SetWidgetDirty(WID_O_NON_STOP);
1249 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));
1253 * Handle the click on the skip button.
1254 * If ctrl is pressed, skip to selected order, else skip to current order + 1
1256 void OrderClick_Skip()
1258 /* Don't skip when there's nothing to skip */
1259 if (_ctrl_pressed && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
1260 if (this->vehicle->GetNumOrders() <= 1) return;
1262 DoCommandP(this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()),
1263 CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
1267 * Handle the click on the delete button.
1269 void OrderClick_Delete()
1271 /* When networking, move one order lower */
1272 int selected = this->selected_order + (int)_networking;
1274 if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
1275 this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
1276 this->UpdateButtonState();
1281 * Handle the click on the 'stop sharing' button.
1282 * If 'End of Shared Orders' isn't selected, do nothing. If Ctrl is pressed, call OrderClick_Delete and exit.
1283 * To stop sharing this vehicle order list, we copy the orders of a vehicle that share this order list. That way we
1284 * exit the group of shared vehicles while keeping the same order list.
1286 void OrderClick_StopSharing()
1288 /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
1289 if (!this->vehicle->IsOrderListShared() || this->selected_order != this->vehicle->GetNumOrders()) return;
1290 /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
1291 if (_ctrl_pressed) {
1292 this->OrderClick_Delete();
1293 return;
1296 /* Get another vehicle that share orders with this vehicle. */
1297 Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
1298 /* Copy the order list of the other vehicle. */
1299 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))) {
1300 this->UpdateButtonState();
1305 * Handle the click on the refit button.
1306 * If ctrl is pressed, cancel refitting, else show the refit window.
1307 * @param i Selected refit command.
1308 * @param auto_refit Select refit for auto-refitting.
1310 void OrderClick_Refit(int i, bool auto_refit)
1312 if (_ctrl_pressed) {
1313 /* Cancel refitting */
1314 DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
1315 } else {
1316 if (i == 1) { // Auto-refit to available cargo type.
1317 DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | CT_AUTO_REFIT, CMD_ORDER_REFIT);
1318 } else {
1319 ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
1324 /** Cache auto-refittability of the vehicle chain. */
1325 void UpdateAutoRefitState()
1327 this->can_do_refit = false;
1328 this->can_do_autorefit = false;
1329 for (const Vehicle *w = this->vehicle; w != NULL; w = w->IsGroundVehicle() ? w->Next() : NULL) {
1330 if (IsEngineRefittable(w->engine_type)) this->can_do_refit = true;
1331 if (HasBit(Engine::Get(w->engine_type)->info.misc_flags, EF_AUTO_REFIT)) this->can_do_autorefit = true;
1335 public:
1336 OrdersWindow(WindowDesc *desc, const Vehicle *v) : Window(desc)
1338 this->vehicle = v;
1340 this->CreateNestedTree();
1341 this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
1342 this->FinishInitNested(v->index);
1343 if (v->owner == _local_company) {
1344 this->DisableWidget(WID_O_EMPTY);
1347 this->selected_order = -1;
1348 this->order_over = INVALID_VEH_ORDER_ID;
1349 this->goto_type = OPOS_NONE;
1350 this->owner = v->owner;
1352 this->UpdateAutoRefitState();
1354 if (_settings_client.gui.quick_goto && v->owner == _local_company) {
1355 /* If there are less than 2 station, make Go To active. */
1356 int station_orders = 0;
1357 const Order *order;
1358 FOR_VEHICLE_ORDERS(v, order) {
1359 if (order->IsType(OT_GOTO_STATION)) station_orders++;
1362 if (station_orders < 2) this->OrderClick_Goto(OPOS_GOTO);
1364 this->OnInvalidateData(VIWD_MODIFY_ORDERS);
1367 ~OrdersWindow()
1369 DeleteWindowById(WC_VEHICLE_CARGO_TYPE_LOAD_ORDERS, this->window_number, false);
1370 DeleteWindowById(WC_VEHICLE_CARGO_TYPE_UNLOAD_ORDERS, this->window_number, false);
1371 if (!FocusWindowById(WC_VEHICLE_VIEW, this->window_number)) {
1372 MarkAllRouteStepsDirty(this->vehicle);
1376 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1378 switch (widget) {
1379 case WID_O_ORDER_LIST:
1380 resize->height = FONT_HEIGHT_NORMAL;
1381 size->height = 6 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
1382 break;
1384 case WID_O_COND_VARIABLE: {
1385 Dimension d = {0, 0};
1386 for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
1387 d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i]));
1389 d.width += padding.width;
1390 d.height += padding.height;
1391 *size = maxdim(*size, d);
1392 break;
1395 case WID_O_COND_COMPARATOR: {
1396 Dimension d = {0, 0};
1397 for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
1398 d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
1400 d.width += padding.width;
1401 d.height += padding.height;
1402 *size = maxdim(*size, d);
1403 break;
1409 * Some data on this window has become invalid.
1410 * @param data Information about the changed data.
1411 * @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.
1413 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
1415 VehicleOrderID from = INVALID_VEH_ORDER_ID;
1416 VehicleOrderID to = INVALID_VEH_ORDER_ID;
1418 switch (data) {
1419 case VIWD_AUTOREPLACE:
1420 /* Autoreplace replaced the vehicle */
1421 this->vehicle = Vehicle::Get(this->window_number);
1422 FALLTHROUGH;
1424 case VIWD_CONSIST_CHANGED:
1425 /* Vehicle composition was changed. */
1426 this->UpdateAutoRefitState();
1427 break;
1429 case VIWD_REMOVE_ALL_ORDERS:
1430 /* Removed / replaced all orders (after deleting / sharing) */
1431 if (this->selected_order == -1) break;
1433 this->DeleteChildWindows();
1434 HideDropDownMenu(this);
1435 this->selected_order = -1;
1436 break;
1438 case VIWD_MODIFY_ORDERS:
1439 /* Some other order changes */
1440 break;
1442 default:
1443 if (data < 0) break;
1445 if (gui_scope) break; // only do this once; from command scope
1446 from = GB(data, 0, 8);
1447 to = GB(data, 8, 8);
1448 /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
1449 * the order is being created / removed */
1450 if (this->selected_order == -1) break;
1452 if (from == to) break; // no need to change anything
1454 if (from != this->selected_order) {
1455 /* Moving from preceding order? */
1456 this->selected_order -= (int)(from <= this->selected_order);
1457 /* Moving to preceding order? */
1458 this->selected_order += (int)(to <= this->selected_order);
1459 break;
1462 /* Now we are modifying the selected order */
1463 if (to == INVALID_VEH_ORDER_ID) {
1464 /* Deleting selected order */
1465 this->DeleteChildWindows();
1466 HideDropDownMenu(this);
1467 this->selected_order = -1;
1468 break;
1471 /* Moving selected order */
1472 this->selected_order = to;
1473 break;
1476 this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
1477 if (gui_scope) {
1478 this->UpdateButtonState();
1479 InvalidateWindowClassesData(WC_VEHICLE_CARGO_TYPE_LOAD_ORDERS, 0);
1480 InvalidateWindowClassesData(WC_VEHICLE_CARGO_TYPE_UNLOAD_ORDERS, 0);
1483 /* Scroll to the new order. */
1484 if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {
1485 this->vscroll->ScrollTowards(to);
1489 void UpdateButtonState()
1491 if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
1493 bool shared_orders = this->vehicle->IsOrderListShared();
1494 VehicleOrderID sel = this->OrderGetSel();
1495 const Order *order = this->vehicle->GetOrder(sel);
1497 /* Second row. */
1498 /* skip */
1499 this->SetWidgetDisabledState(WID_O_SKIP, this->vehicle->GetNumOrders() <= 1);
1501 /* delete / stop sharing */
1502 NWidgetStacked *delete_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_BOTTOM_MIDDLE);
1503 if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
1504 /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
1505 delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_STOP_SHARING);
1506 } else {
1507 /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
1508 delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE);
1509 this->SetWidgetDisabledState(WID_O_DELETE,
1510 (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
1512 /* Set the tooltip of the 'delete' button depending on whether the
1513 * 'End of Orders' order or a regular order is selected. */
1514 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
1515 if (this->selected_order == this->vehicle->GetNumOrders()) {
1516 nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
1517 } else {
1518 nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
1522 /* First row. */
1523 this->RaiseWidget(WID_O_FULL_LOAD);
1524 this->RaiseWidget(WID_O_UNLOAD);
1525 this->RaiseWidget(WID_O_SERVICE);
1527 /* Selection widgets. */
1528 /* Train or road vehicle. */
1529 NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
1530 NWidgetStacked *left_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
1531 NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
1532 NWidgetStacked *right_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
1533 /* Ship or airplane. */
1534 NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
1535 assert(row_sel != NULL || (train_row_sel != NULL && left_sel != NULL && middle_sel != NULL && right_sel != NULL));
1538 if (order == NULL) {
1539 if (row_sel != NULL) {
1540 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1541 } else {
1542 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1543 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1544 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1545 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1546 this->DisableWidget(WID_O_NON_STOP);
1547 this->RaiseWidget(WID_O_NON_STOP);
1549 this->DisableWidget(WID_O_FULL_LOAD);
1550 this->DisableWidget(WID_O_UNLOAD);
1551 this->DisableWidget(WID_O_REFIT_DROPDOWN);
1552 } else {
1553 this->SetWidgetDisabledState(WID_O_FULL_LOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
1554 this->SetWidgetDisabledState(WID_O_UNLOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
1556 switch (order->GetType()) {
1557 case OT_GOTO_STATION:
1558 if (row_sel != NULL) {
1559 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1560 } else {
1561 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1562 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1563 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1564 right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
1565 this->EnableWidget(WID_O_NON_STOP);
1566 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1568 this->SetWidgetLoweredState(WID_O_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
1569 this->SetWidgetLoweredState(WID_O_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
1571 /* Can only do refitting when stopping at the destination and loading cargo.
1572 * Also enable the button if a refit is already set to allow clearing it. */
1573 this->SetWidgetDisabledState(WID_O_REFIT_DROPDOWN,
1574 order->GetLoadType() == OLFB_NO_LOAD || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ||
1575 ((!this->can_do_refit || !this->can_do_autorefit) && !order->IsRefit()));
1577 break;
1579 case OT_GOTO_WAYPOINT:
1580 if (row_sel != NULL) {
1581 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1582 } else {
1583 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1584 left_sel->SetDisplayedPlane(DP_LEFT_REVERSE);
1585 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1586 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1587 this->EnableWidget(WID_O_NON_STOP);
1588 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1589 this->EnableWidget(WID_O_REVERSE);
1590 this->SetWidgetLoweredState(WID_O_REVERSE, (order->GetWaypointFlags() & OWF_REVERSE) != 0);
1592 this->DisableWidget(WID_O_UNLOAD);
1593 this->DisableWidget(WID_O_REFIT_DROPDOWN);
1594 break;
1596 case OT_GOTO_DEPOT:
1597 if (row_sel != NULL) {
1598 row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
1599 } else {
1600 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1601 left_sel->SetDisplayedPlane(DP_LEFT_REFIT);
1602 middle_sel->SetDisplayedPlane(DP_MIDDLE_SERVICE);
1603 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1604 this->EnableWidget(WID_O_NON_STOP);
1605 this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
1607 /* Disable refit button if the order is no 'always go' order.
1608 * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
1609 this->SetWidgetDisabledState(WID_O_REFIT,
1610 (order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT) ||
1611 (!this->can_do_refit && !order->IsRefit()));
1612 this->SetWidgetLoweredState(WID_O_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
1613 break;
1615 case OT_CONDITIONAL: {
1616 if (row_sel != nullptr) {
1617 row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
1618 } else {
1619 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_CONDITIONAL);
1622 OrderConditionVariable ocv = (order == nullptr) ? OCV_LOAD_PERCENTAGE : order->GetConditionVariable();
1623 bool is_cargo = ocv == OCV_CARGO_ACCEPTANCE || ocv == OCV_CARGO_WAITING;
1625 if (is_cargo) {
1626 CargoSpec* cargo_spec = CargoSpec::Get(order != nullptr ? order->GetConditionValue() : 0);
1627 this->GetWidget<NWidgetCore>(WID_O_COND_CARGO)->widget_data = cargo_spec->name;
1628 this->GetWidget<NWidgetStacked>(WID_O_SEL_COND_VALUE)->SetDisplayedPlane(DP_COND_VALUE_CARGO);
1630 else {
1631 this->GetWidget<NWidgetStacked>(WID_O_SEL_COND_VALUE)->SetDisplayedPlane(DP_COND_VALUE_NUMBER);
1634 /* Set the strings for the dropdown boxes. */
1635 this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv;
1636 this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = GetComparatorStrings(order)[order == NULL ? 0 : order->GetConditionComparator()];
1637 this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY || ocv == OCV_PERCENT);
1638 this->SetWidgetDisabledState(WID_O_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
1639 break;
1642 default: // every other order
1643 if (row_sel != NULL) {
1644 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1645 } else {
1646 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
1647 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1648 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1649 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1650 this->DisableWidget(WID_O_NON_STOP);
1652 this->DisableWidget(WID_O_FULL_LOAD);
1653 this->DisableWidget(WID_O_UNLOAD);
1654 this->DisableWidget(WID_O_REFIT_DROPDOWN);
1655 break;
1659 /* Disable list of vehicles with the same shared orders if there is no list */
1660 this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders);
1662 this->SetDirty();
1665 virtual void OnPaint() override
1667 if (this->vehicle->owner != _local_company) {
1668 this->selected_order = -1; // Disable selection any selected row at a competitor order window.
1669 } else {
1670 this->SetWidgetLoweredState(WID_O_GOTO, this->goto_type != OPOS_NONE);
1672 this->DrawWidgets();
1675 virtual void DrawWidget(const Rect &r, int widget) const override
1677 if (widget != WID_O_ORDER_LIST) return;
1679 bool rtl = _current_text_dir == TD_RTL;
1680 SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
1681 int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
1682 int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
1684 int y = r.top + WD_FRAMERECT_TOP;
1685 int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
1687 int i = this->vscroll->GetPosition();
1688 const Order *order = this->vehicle->GetOrder(i);
1689 /* First draw the highlighting underground if it exists. */
1690 if (this->order_over != INVALID_VEH_ORDER_ID) {
1691 while (order != NULL) {
1692 /* Don't draw anything if it extends past the end of the window. */
1693 if (!this->vscroll->IsVisible(i)) break;
1695 if (i != this->selected_order && i == this->order_over) {
1696 /* Highlight dragged order destination. */
1697 int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
1698 int bottom = min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM);
1699 top = max(top - 3, r.top + WD_FRAMERECT_TOP);
1700 GfxFillRect(r.left + WD_FRAMETEXT_LEFT, top, r.right - WD_FRAMETEXT_RIGHT, bottom, _colour_gradient[COLOUR_GREY][7]);
1701 break;
1703 y += line_height;
1705 i++;
1706 order = order->next;
1709 /* Reset counters for drawing the orders. */
1710 y = r.top + WD_FRAMERECT_TOP;
1711 i = this->vscroll->GetPosition();
1712 order = this->vehicle->GetOrder(i);
1715 /* Draw the orders. */
1716 while (order != NULL) {
1717 /* Don't draw anything if it extends past the end of the window. */
1718 if (!this->vscroll->IsVisible(i)) break;
1720 DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
1721 y += line_height;
1723 i++;
1724 order = order->next;
1727 if (this->vscroll->IsVisible(i)) {
1728 StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
1729 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);
1733 virtual void SetStringParameters(int widget) const override
1735 switch (widget) {
1736 case WID_O_COND_VALUE: {
1737 VehicleOrderID sel = this->OrderGetSel();
1738 const Order *order = this->vehicle->GetOrder(sel);
1740 if (order != NULL && order->IsType(OT_CONDITIONAL)) {
1741 uint value = order->GetConditionValue();
1742 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1743 SetDParam(0, value);
1745 break;
1748 case WID_O_CAPTION:
1749 SetDParam(0, this->vehicle->index);
1750 break;
1754 virtual void OnClick(Point pt, int widget, int click_count) override
1756 switch (widget) {
1757 case WID_O_ORDER_LIST: {
1758 if (this->goto_type == OPOS_CONDITIONAL) {
1759 VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
1760 if (order_id != INVALID_VEH_ORDER_ID) {
1761 Order order;
1762 order.next = NULL;
1763 order.index = 0;
1764 order.MakeConditional(order_id);
1766 DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
1768 ResetObjectToPlace();
1769 break;
1772 if (_ctrl_pressed && _shift_pressed) {
1773 const Order* selected_order = this->vehicle->GetOrder(this->selected_order);
1775 if (selected_order != NULL && selected_order->IsType(OrderType::OT_CONDITIONAL)) {
1776 VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
1777 if (order_id != INVALID_VEH_ORDER_ID) {
1778 DoCommandP(this->vehicle->tile, this->vehicle->index | (this->selected_order << 20),
1779 MOF_COND_DESTINATION | (order_id << 4),
1780 CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1781 MarkAllRoutePathsDirty(this->vehicle);
1782 MarkAllRouteStepsDirty(this->vehicle);
1785 break;
1788 VehicleOrderID sel = this->GetOrderFromPt(pt.y);
1790 if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
1791 TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
1792 if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
1793 return;
1796 /* This order won't be selected any more, close all child windows and dropdowns */
1797 this->DeleteChildWindows();
1798 HideDropDownMenu(this);
1800 if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
1801 /* Deselect clicked order */
1802 this->selected_order = -1;
1803 } else if (sel == this->selected_order) {
1804 if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
1805 DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20),
1806 MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
1807 CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1809 } else {
1810 /* Select clicked order */
1811 this->selected_order = sel;
1813 if (this->vehicle->owner == _local_company) {
1814 /* Activate drag and drop */
1815 SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1819 this->UpdateButtonState();
1820 break;
1823 case WID_O_SKIP:
1824 this->OrderClick_Skip();
1825 break;
1827 case WID_O_DELETE:
1828 this->OrderClick_Delete();
1829 break;
1831 case WID_O_STOP_SHARING:
1832 this->OrderClick_StopSharing();
1833 break;
1835 case WID_O_NON_STOP:
1836 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1837 this->OrderClick_Nonstop(-1);
1838 } else {
1839 const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1840 ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
1841 o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12), 0, DDSF_LOST_FOCUS);
1843 break;
1845 case WID_O_GOTO:
1846 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1847 if (this->goto_type != OPOS_NONE) {
1848 ResetObjectToPlace();
1849 } else {
1850 this->OrderClick_Goto(OPOS_GOTO);
1852 } else {
1853 int sel;
1854 switch (this->goto_type) {
1855 case OPOS_NONE: sel = -1; break;
1856 case OPOS_GOTO: sel = 0; break;
1857 case OPOS_CONDITIONAL: sel = 2; break;
1858 case OPOS_SHARE: sel = 3; break;
1859 default: NOT_REACHED();
1861 ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0, 0, DDSF_LOST_FOCUS);
1863 break;
1865 case WID_O_FULL_LOAD:
1866 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1867 this->OrderClick_FullLoad(-1);
1868 } else {
1869 ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 0xE2 /* 1110 0010 */, 0, DDSF_LOST_FOCUS);
1871 break;
1873 case WID_O_UNLOAD:
1874 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1875 this->OrderClick_Unload(-1);
1876 } else {
1877 ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 0xE8 /* 1110 1000 */, 0, DDSF_LOST_FOCUS);
1879 break;
1881 case WID_O_REFIT:
1882 this->OrderClick_Refit(0, false);
1883 break;
1885 case WID_O_SERVICE:
1886 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1887 this->OrderClick_Service(-1);
1888 } else {
1889 ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_SERVICE, 0, 0, 0, DDSF_LOST_FOCUS);
1891 break;
1893 case WID_O_REFIT_DROPDOWN:
1894 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1895 this->OrderClick_Refit(0, true);
1896 } else {
1897 ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0, 0, DDSF_LOST_FOCUS);
1899 break;
1901 case WID_O_COND_CARGO: {
1902 DropDownList *lst = new DropDownList();
1903 const CargoSpec *cs;
1904 FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
1905 *lst->Append() = new DropDownListStringItem(cs->name, cs->Index(), false);
1907 if (lst->Length() == 0) {
1908 delete lst;
1909 break;
1912 uint value = this->vehicle->GetOrder(this->OrderGetSel())->GetConditionValue();
1913 ShowDropDownList(this, lst, value, WID_O_COND_CARGO, 0, true);
1914 break;
1917 case WID_O_REVERSE: {
1918 VehicleOrderID sel_ord = this->OrderGetSel();
1919 const Order *order = this->vehicle->GetOrder(sel_ord);
1921 if (order == NULL) break;
1923 DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_WAYPOINT_FLAGS | (order->GetWaypointFlags() ^ OWF_REVERSE) << 4,
1924 CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1925 break;
1928 case WID_O_TIMETABLE_VIEW:
1929 ShowTimetableWindow(this->vehicle);
1930 break;
1932 case WID_O_COND_VARIABLE: {
1933 DropDownList *list = new DropDownList();
1934 for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
1935 *list->Append() = new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false);
1937 ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
1938 break;
1941 case WID_O_COND_COMPARATOR: {
1942 const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1943 OrderConditionVariable cond_var = o->GetConditionVariable();
1944 ShowDropDownMenu(this, GetComparatorStrings(o), o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0,
1945 (cond_var == OCV_REQUIRES_SERVICE ||
1946 cond_var == OCV_CARGO_ACCEPTANCE ||
1947 cond_var == OCV_CARGO_WAITING) ? 0x3F : 0xC0);
1948 break;
1951 case WID_O_COND_VALUE: {
1952 const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
1953 uint value = order->GetConditionValue();
1954 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1955 SetDParam(0, value);
1956 ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE);
1957 break;
1960 case WID_O_SHARED_ORDER_LIST:
1961 ShowVehicleListWindow(this->vehicle);
1962 break;
1966 virtual void OnQueryTextFinished(char *str) override
1968 if (!StrEmpty(str)) {
1969 VehicleOrderID sel = this->OrderGetSel();
1970 uint value = atoi(str);
1972 switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
1973 case OCV_MAX_SPEED:
1974 value = ConvertDisplaySpeedToSpeed(value);
1975 break;
1977 case OCV_PERCENT:
1978 case OCV_RELIABILITY:
1979 case OCV_LOAD_PERCENTAGE:
1980 value = Clamp(value, 0, 100);
1981 break;
1983 default:
1984 break;
1986 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));
1990 virtual void OnDropdownSelect(int widget, int index) override
1992 switch (widget) {
1993 case WID_O_NON_STOP:
1994 this->OrderClick_Nonstop(index);
1995 break;
1997 case WID_O_FULL_LOAD:
1998 this->OrderClick_FullLoad(index);
1999 break;
2001 case WID_O_UNLOAD:
2002 this->OrderClick_Unload(index);
2003 break;
2005 case WID_O_GOTO:
2006 switch (index) {
2007 case 0: this->OrderClick_Goto(OPOS_GOTO); break;
2008 case 1: this->OrderClick_NearestDepot(); break;
2009 case 2: this->OrderClick_Goto(OPOS_CONDITIONAL); break;
2010 case 3: this->OrderClick_Goto(OPOS_SHARE); break;
2011 default: NOT_REACHED();
2013 break;
2015 case WID_O_SERVICE:
2016 this->OrderClick_Service(index);
2017 break;
2019 case WID_O_REFIT_DROPDOWN:
2020 this->OrderClick_Refit(index, true);
2021 break;
2023 case WID_O_COND_VARIABLE:
2024 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));
2025 break;
2027 case WID_O_COND_COMPARATOR:
2028 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));
2029 break;
2031 case WID_O_COND_CARGO:
2032 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));
2033 break;
2037 virtual void OnDragDrop(Point pt, int widget) override
2039 switch (widget) {
2040 case WID_O_ORDER_LIST: {
2041 VehicleOrderID from_order = this->OrderGetSel();
2042 VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
2044 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()) &&
2045 DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
2046 this->selected_order = -1;
2047 this->UpdateButtonState();
2049 break;
2052 case WID_O_DELETE:
2053 this->OrderClick_Delete();
2054 break;
2056 case WID_O_STOP_SHARING:
2057 this->OrderClick_StopSharing();
2058 break;
2061 ResetObjectToPlace();
2063 if (this->order_over != INVALID_VEH_ORDER_ID) {
2064 /* End of drag-and-drop, hide dragged order destination highlight. */
2065 this->order_over = INVALID_VEH_ORDER_ID;
2066 this->SetWidgetDirty(WID_O_ORDER_LIST);
2070 virtual EventState OnHotkey(int hotkey) override
2072 if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
2074 switch (hotkey) {
2075 case OHK_SKIP: this->OrderClick_Skip(); break;
2076 case OHK_DELETE: this->OrderClick_Delete(); break;
2077 case OHK_GOTO: this->OrderClick_Goto(OPOS_GOTO); break;
2078 case OHK_NONSTOP: this->OrderClick_Nonstop(-1); break;
2079 case OHK_FULLLOAD: this->OrderClick_FullLoad(-1); break;
2080 case OHK_UNLOAD: this->OrderClick_Unload(-1); break;
2081 case OHK_NEAREST_DEPOT: this->OrderClick_NearestDepot(); break;
2082 case OHK_ALWAYS_SERVICE: this->OrderClick_Service(-1); break;
2083 case OHK_TRANSFER: this->OrderHotkey_Transfer(); break;
2084 case OHK_NO_UNLOAD: this->OrderHotkey_NoUnload(); break;
2085 case OHK_NO_LOAD: this->OrderHotkey_NoLoad(); break;
2086 default: return ES_NOT_HANDLED;
2088 return ES_HANDLED;
2091 virtual void OnPlaceObject(Point pt, TileIndex tile) override
2093 if (this->goto_type == OPOS_GOTO) {
2094 const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
2095 if (cmd.IsType(OT_NOTHING)) return;
2097 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))) {
2098 /* With quick goto the Go To button stays active */
2099 if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
2104 virtual bool OnVehicleSelect(const Vehicle *v) override
2106 /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
2107 * We disallow copying orders of other vehicles if we already have at least one order entry
2108 * ourself as it easily copies orders of vehicles within a station when we mean the station.
2109 * If you press CTRL on a non-empty orders vehicle a warning message will appear to confirm */
2110 bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
2111 index_vehicle_share = v->index;
2113 if (this->vehicle->GetNumOrders() != 0) {
2114 if(!share_order) {
2115 return false;
2116 } else {
2117 ShowQuery(
2118 STR_SHARE_ORDERS_CAPTION,
2119 STR_SHARE_ORDERS_QUERY,
2120 this,
2121 AskShareOrdersCallback
2123 return true;
2127 CopyShareOrders(share_order);
2128 return true;
2131 /** Copy or Share the orders of a vehicle
2132 * @param share_order true for sharing, false for copying
2134 void CopyShareOrders(bool share_order)
2136 if (DoCommandP(this->vehicle->tile, this->vehicle->index | (share_order ? CO_SHARE : CO_COPY) << 30, index_vehicle_share,
2137 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))) {
2138 this->selected_order = -1;
2139 ResetObjectToPlace();
2143 virtual void OnPlaceObjectAbort() override
2145 this->goto_type = OPOS_NONE;
2146 this->SetWidgetDirty(WID_O_GOTO);
2148 /* Remove drag highlighting if it exists. */
2149 if (this->order_over != INVALID_VEH_ORDER_ID) {
2150 this->order_over = INVALID_VEH_ORDER_ID;
2151 this->SetWidgetDirty(WID_O_ORDER_LIST);
2155 virtual void OnMouseDrag(Point pt, int widget) override
2157 if (this->selected_order != -1 && widget == WID_O_ORDER_LIST) {
2158 /* An order is dragged.. */
2159 VehicleOrderID from_order = this->OrderGetSel();
2160 VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
2161 uint num_orders = this->vehicle->GetNumOrders();
2163 if (from_order != INVALID_VEH_ORDER_ID && from_order <= num_orders) {
2164 if (to_order != INVALID_VEH_ORDER_ID && to_order <= num_orders) { // ..over an existing order.
2165 this->order_over = to_order;
2166 this->SetWidgetDirty(widget);
2167 } else if (from_order != to_order && this->order_over != INVALID_VEH_ORDER_ID) { // ..outside of the order list.
2168 this->order_over = INVALID_VEH_ORDER_ID;
2169 this->SetWidgetDirty(widget);
2175 virtual void OnResize() override
2177 /* Update the scroll bar */
2178 this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
2181 virtual void OnFocus(Window *previously_focused_window) override
2183 if (HasFocusedVehicleChanged(this->window_number, previously_focused_window)) {
2184 MarkAllRoutePathsDirty(this->vehicle);
2185 MarkAllRouteStepsDirty(this->vehicle);
2189 virtual void OnFocusLost(Window *newly_focused_window) override
2191 if (HasFocusedVehicleChanged(this->window_number, newly_focused_window)) {
2192 MarkAllRoutePathsDirty(this->vehicle);
2193 MarkAllRouteStepsDirty(this->vehicle);
2197 const Vehicle *GetVehicle()
2199 return this->vehicle;
2202 static HotkeyList hotkeys;
2206 void AskShareOrdersCallback(Window *w, bool confirmed)
2208 OrdersWindow *ow = static_cast<OrdersWindow *>(w);
2210 if (confirmed) {
2211 ow->CopyShareOrders(true);
2216 static Hotkey order_hotkeys[] = {
2217 Hotkey('D', "skip", OHK_SKIP),
2218 Hotkey('F', "delete", OHK_DELETE),
2219 Hotkey('G', "goto", OHK_GOTO),
2220 Hotkey('H', "nonstop", OHK_NONSTOP),
2221 Hotkey('J', "fullload", OHK_FULLLOAD),
2222 Hotkey('K', "unload", OHK_UNLOAD),
2223 Hotkey((uint16)0, "nearest_depot", OHK_NEAREST_DEPOT),
2224 Hotkey((uint16)0, "always_service", OHK_ALWAYS_SERVICE),
2225 Hotkey((uint16)0, "transfer", OHK_TRANSFER),
2226 Hotkey((uint16)0, "no_unload", OHK_NO_UNLOAD),
2227 Hotkey((uint16)0, "no_load", OHK_NO_LOAD),
2228 HOTKEY_LIST_END
2230 HotkeyList OrdersWindow::hotkeys("order", order_hotkeys);
2232 /** Nested widget definition for "your" train orders. */
2233 static const NWidgetPart _nested_orders_train_widgets[] = {
2234 NWidget(NWID_HORIZONTAL),
2235 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2236 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2237 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
2238 NWidget(WWT_SHADEBOX, COLOUR_GREY),
2239 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
2240 NWidget(WWT_STICKYBOX, COLOUR_GREY),
2241 EndContainer(),
2242 NWidget(NWID_HORIZONTAL),
2243 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(),
2244 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
2245 EndContainer(),
2247 /* First button row. */
2248 NWidget(NWID_HORIZONTAL),
2249 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW_GROUNDVEHICLE),
2250 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
2251 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_NON_STOP), SetMinimalSize(93, 12), SetFill(1, 0),
2252 SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
2253 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_LEFT),
2254 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(93, 12), SetFill(1, 0),
2255 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
2256 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(93, 12), SetFill(1, 0),
2257 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
2258 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_O_REVERSE), SetMinimalSize(93, 12), SetFill(1, 0),
2259 SetDataTip(STR_ORDER_REVERSE, STR_ORDER_REVERSE_TOOLTIP), SetResize(1, 0),
2260 EndContainer(),
2261 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_MIDDLE),
2262 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(93, 12), SetFill(1, 0),
2263 SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
2264 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(93, 12), SetFill(1, 0),
2265 SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
2266 EndContainer(),
2267 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_RIGHT),
2268 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_O_EMPTY), SetMinimalSize(93, 12), SetFill(1, 0),
2269 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
2270 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(93, 12), SetFill(1, 0),
2271 SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
2272 EndContainer(),
2273 EndContainer(),
2274 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
2275 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
2276 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
2277 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
2278 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
2279 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_COND_VALUE),
2280 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
2281 SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
2282 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_CARGO), SetMinimalSize(124, 12), SetFill(1, 0),
2283 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_CARGO_TOOLTIP), SetResize(1, 0),
2284 EndContainer(),
2285 EndContainer(),
2286 EndContainer(),
2287 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),
2288 EndContainer(),
2290 /* Second button row. */
2291 NWidget(NWID_HORIZONTAL),
2292 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
2293 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
2294 SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
2295 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
2296 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
2297 SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
2298 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
2299 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
2300 EndContainer(),
2301 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
2302 SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
2303 EndContainer(),
2304 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
2305 EndContainer(),
2308 static WindowDesc _orders_train_desc(
2309 WDP_AUTO, "view_vehicle_orders_train", 384, 100,
2310 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
2311 WDF_CONSTRUCTION,
2312 _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets),
2313 &OrdersWindow::hotkeys
2316 /** Nested widget definition for "your" orders (non-train). */
2317 static const NWidgetPart _nested_orders_widgets[] = {
2318 NWidget(NWID_HORIZONTAL),
2319 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2320 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2321 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
2322 NWidget(WWT_SHADEBOX, COLOUR_GREY),
2323 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
2324 NWidget(WWT_STICKYBOX, COLOUR_GREY),
2325 EndContainer(),
2326 NWidget(NWID_HORIZONTAL),
2327 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(),
2328 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
2329 EndContainer(),
2331 /* First button row. */
2332 NWidget(NWID_HORIZONTAL),
2333 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW),
2334 /* Load + unload + refit buttons. */
2335 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
2336 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
2337 SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
2338 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
2339 SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
2340 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(124, 12), SetFill(1, 0),
2341 SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
2342 EndContainer(),
2343 /* Refit + service buttons. */
2344 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
2345 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
2346 SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
2347 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
2348 SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
2349 EndContainer(),
2351 /* Buttons for setting a condition. */
2352 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
2353 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
2354 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
2355 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
2356 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
2357 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_COND_VALUE),
2358 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
2359 SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
2360 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_CARGO), SetMinimalSize(124, 12), SetFill(1, 0),
2361 SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_CARGO_TOOLTIP), SetResize(1, 0),
2362 EndContainer(),
2363 EndContainer(),
2364 EndContainer(),
2366 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),
2367 EndContainer(),
2369 /* Second button row. */
2370 NWidget(NWID_HORIZONTAL),
2371 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
2372 SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
2373 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
2374 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
2375 SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
2376 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
2377 SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
2378 EndContainer(),
2379 NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
2380 SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
2381 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
2382 EndContainer(),
2385 static WindowDesc _orders_desc(
2386 WDP_AUTO, "view_vehicle_orders", 384, 100,
2387 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
2388 WDF_CONSTRUCTION,
2389 _nested_orders_widgets, lengthof(_nested_orders_widgets),
2390 &OrdersWindow::hotkeys
2393 /** Nested widget definition for competitor orders. */
2394 static const NWidgetPart _nested_other_orders_widgets[] = {
2395 NWidget(NWID_HORIZONTAL),
2396 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2397 NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2398 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
2399 NWidget(WWT_SHADEBOX, COLOUR_GREY),
2400 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
2401 NWidget(WWT_STICKYBOX, COLOUR_GREY),
2402 EndContainer(),
2403 NWidget(NWID_HORIZONTAL),
2404 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(),
2405 NWidget(NWID_VERTICAL),
2406 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
2407 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
2408 EndContainer(),
2409 EndContainer(),
2412 static WindowDesc _other_orders_desc(
2413 WDP_AUTO, "view_vehicle_orders_competitor", 384, 86,
2414 WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
2415 WDF_CONSTRUCTION,
2416 _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets),
2417 &OrdersWindow::hotkeys
2420 void ShowOrdersWindow(const Vehicle *v)
2422 DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
2423 DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
2424 if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
2426 /* Using a different WindowDescs for _local_company causes problems.
2427 * Due to this we have to close order windows in ChangeWindowOwner/DeleteCompanyWindows,
2428 * because we cannot change switch the WindowDescs and keeping the old WindowDesc results
2429 * in crashed due to missing widges.
2430 * TODO Rewrite the order GUI to not use different WindowDescs.
2432 if (v->owner != _local_company) {
2433 new OrdersWindow(&_other_orders_desc, v);
2434 } else {
2435 new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);