OpenTTD
order_gui.cpp
Go to the documentation of this file.
1 /* $Id: order_gui.cpp 27893 2017-08-13 18:38:42Z frosch $ */
2 
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  */
9 
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"
32 
33 #include "widgets/order_widget.h"
34 
35 #include "safeguards.h"
36 
37 
39 static const StringID _station_load_types[][5][5] = {
40  {
41  /* No refitting. */
42  {
43  STR_EMPTY,
45  STR_ORDER_FULL_LOAD,
46  STR_ORDER_FULL_LOAD_ANY,
47  STR_ORDER_NO_LOAD,
48  }, {
49  STR_ORDER_UNLOAD,
51  STR_ORDER_UNLOAD_FULL_LOAD,
52  STR_ORDER_UNLOAD_FULL_LOAD_ANY,
53  STR_ORDER_UNLOAD_NO_LOAD,
54  }, {
55  STR_ORDER_TRANSFER,
57  STR_ORDER_TRANSFER_FULL_LOAD,
58  STR_ORDER_TRANSFER_FULL_LOAD_ANY,
59  STR_ORDER_TRANSFER_NO_LOAD,
60  }, {
61  /* Unload and transfer do not work together. */
66  }, {
67  STR_ORDER_NO_UNLOAD,
69  STR_ORDER_NO_UNLOAD_FULL_LOAD,
70  STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
71  STR_ORDER_NO_UNLOAD_NO_LOAD,
72  }
73  }, {
74  /* With auto-refitting. No loading and auto-refitting do not work together. */
75  {
76  STR_ORDER_AUTO_REFIT,
78  STR_ORDER_FULL_LOAD_REFIT,
79  STR_ORDER_FULL_LOAD_ANY_REFIT,
81  }, {
82  STR_ORDER_UNLOAD_REFIT,
84  STR_ORDER_UNLOAD_FULL_LOAD_REFIT,
85  STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT,
87  }, {
88  STR_ORDER_TRANSFER_REFIT,
90  STR_ORDER_TRANSFER_FULL_LOAD_REFIT,
91  STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT,
93  }, {
94  /* Unload and transfer do not work together. */
99  }, {
100  STR_ORDER_NO_UNLOAD_REFIT,
102  STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT,
103  STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT,
105  }
106  }
107 };
108 
109 static const StringID _order_non_stop_drowdown[] = {
110  STR_ORDER_GO_TO,
111  STR_ORDER_GO_NON_STOP_TO,
112  STR_ORDER_GO_VIA,
113  STR_ORDER_GO_NON_STOP_VIA,
115 };
116 
117 static const StringID _order_full_load_drowdown[] = {
118  STR_ORDER_DROP_LOAD_IF_POSSIBLE,
119  STR_EMPTY,
120  STR_ORDER_DROP_FULL_LOAD_ALL,
121  STR_ORDER_DROP_FULL_LOAD_ANY,
122  STR_ORDER_DROP_NO_LOADING,
124 };
125 
126 static const StringID _order_unload_drowdown[] = {
127  STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
128  STR_ORDER_DROP_UNLOAD,
129  STR_ORDER_DROP_TRANSFER,
130  STR_EMPTY,
131  STR_ORDER_DROP_NO_UNLOADING,
133 };
134 
135 static const StringID _order_goto_dropdown[] = {
136  STR_ORDER_GO_TO,
137  STR_ORDER_GO_TO_NEAREST_DEPOT,
138  STR_ORDER_CONDITIONAL,
139  STR_ORDER_SHARE,
141 };
142 
143 static const StringID _order_goto_dropdown_aircraft[] = {
144  STR_ORDER_GO_TO,
145  STR_ORDER_GO_TO_NEAREST_HANGAR,
146  STR_ORDER_CONDITIONAL,
147  STR_ORDER_SHARE,
149 };
150 
156  OCV_AGE,
160 };
161 
162 static const StringID _order_conditional_condition[] = {
163  STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
164  STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
165  STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
166  STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
167  STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
168  STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
169  STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
170  STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
172 };
173 
174 extern uint ConvertSpeedToDisplaySpeed(uint speed);
175 extern uint ConvertDisplaySpeedToSpeed(uint speed);
176 
177 static const StringID _order_depot_action_dropdown[] = {
178  STR_ORDER_DROP_GO_ALWAYS_DEPOT,
179  STR_ORDER_DROP_SERVICE_DEPOT,
180  STR_ORDER_DROP_HALT_DEPOT,
182 };
183 
184 static int DepotActionStringIndex(const Order *order)
185 {
186  if (order->GetDepotActionType() & ODATFB_HALT) {
187  return DA_STOP;
188  } else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
189  return DA_SERVICE;
190  } else {
191  return DA_ALWAYS_GO;
192  }
193 }
194 
195 static const StringID _order_refit_action_dropdown[] = {
196  STR_ORDER_DROP_REFIT_AUTO,
197  STR_ORDER_DROP_REFIT_AUTO_ANY,
199 };
200 
213 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
214 {
215  bool rtl = _current_text_dir == TD_RTL;
216 
217  SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT;
218  Dimension sprite_size = GetSpriteSize(sprite);
219  if (v->cur_real_order_index == order_index) {
220  DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
221  DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
222  } else if (v->cur_implicit_order_index == order_index) {
223  DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
224  }
225 
226  TextColour colour = TC_BLACK;
227  if (order->IsType(OT_IMPLICIT)) {
228  colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
229  } else if (selected) {
230  colour = TC_WHITE;
231  }
232 
233  SetDParam(0, order_index + 1);
234  DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, STR_ORDER_INDEX, colour, SA_RIGHT | SA_FORCE);
235 
236  SetDParam(5, STR_EMPTY);
237  SetDParam(8, STR_EMPTY);
238 
239  /* Check range for aircraft. */
240  if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
241  const Order *next = order->next != NULL ? order->next : v->GetFirstOrder();
242  if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) SetDParam(8, STR_ORDER_OUT_OF_RANGE);
243  }
244 
245  switch (order->GetType()) {
246  case OT_DUMMY:
247  SetDParam(0, STR_INVALID_ORDER);
248  SetDParam(1, order->GetDestination());
249  break;
250 
251  case OT_IMPLICIT:
252  SetDParam(0, STR_ORDER_GO_TO_STATION);
253  SetDParam(1, STR_ORDER_GO_TO);
254  SetDParam(2, order->GetDestination());
255  SetDParam(3, timetable ? STR_EMPTY : STR_ORDER_IMPLICIT);
256  break;
257 
258  case OT_GOTO_STATION: {
259  OrderLoadFlags load = order->GetLoadType();
260  OrderUnloadFlags unload = order->GetUnloadType();
261 
262  SetDParam(0, STR_ORDER_GO_TO_STATION);
263  SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
264  SetDParam(2, order->GetDestination());
265 
266  if (timetable) {
267  SetDParam(3, STR_EMPTY);
268 
269  if (order->GetWaitTime() > 0) {
270  SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR : STR_TIMETABLE_STAY_FOR_ESTIMATED);
271  SetTimetableParams(6, 7, order->GetWaitTime());
272  }
273  } else {
274  SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]);
275  if (order->IsRefit()) {
276  SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
277  }
278  if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
279  SetDParam(5, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
280  }
281  }
282  break;
283  }
284 
285  case OT_GOTO_DEPOT:
286  if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
287  SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
288  if (v->type == VEH_AIRCRAFT) {
289  SetDParam(2, STR_ORDER_NEAREST_HANGAR);
290  SetDParam(3, STR_EMPTY);
291  } else {
292  SetDParam(2, STR_ORDER_NEAREST_DEPOT);
293  SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type);
294  }
295  } else {
296  SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT);
297  SetDParam(2, v->type);
298  SetDParam(3, order->GetDestination());
299  }
300 
301  if (order->GetDepotOrderType() & ODTFB_SERVICE) {
302  SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
303  } else {
304  SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
305  }
306 
307  if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
308  SetDParam(5, STR_ORDER_STOP_ORDER);
309  }
310 
311  if (!timetable && order->IsRefit()) {
312  SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER);
313  SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name);
314  }
315  break;
316 
317  case OT_GOTO_WAYPOINT:
318  SetDParam(0, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT);
319  SetDParam(1, order->GetDestination());
320  break;
321 
322  case OT_CONDITIONAL:
323  SetDParam(1, order->GetConditionSkipToOrder() + 1);
324  if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
325  SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
326  } else {
328  SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM);
329  SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
330  SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
331 
332  uint value = order->GetConditionValue();
333  if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
334  SetDParam(4, value);
335  }
336 
337  if (timetable && order->GetWaitTime() > 0) {
338  SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_AND_TRAVEL_FOR : STR_TIMETABLE_AND_TRAVEL_FOR_ESTIMATED);
339  SetTimetableParams(6, 7, order->GetWaitTime());
340  } else {
341  SetDParam(5, STR_EMPTY);
342  }
343  break;
344 
345  default: NOT_REACHED();
346  }
347 
348  DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
349 }
350 
358 {
359  /* Hack-ish; unpack order 0, so everything gets initialised with either zero
360  * or a suitable default value for the variable. Then also override the index
361  * as it is not coming from a pool, so would be initialised. */
362  Order order(0);
363  order.index = 0;
364 
365  /* check depot first */
366  if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) {
367  order.MakeGoToDepot(v->type == VEH_AIRCRAFT ? GetStationIndex(tile) : GetDepotIndex(tile),
370 
372 
373  return order;
374  }
375 
376  /* check rail waypoint */
377  if (IsRailWaypointTile(tile) &&
378  v->type == VEH_TRAIN &&
379  IsTileOwner(tile, _local_company)) {
380  order.MakeGoToWaypoint(GetStationIndex(tile));
382  return order;
383  }
384 
385  /* check buoy (no ownership) */
386  if (IsBuoyTile(tile) && v->type == VEH_SHIP) {
387  order.MakeGoToWaypoint(GetStationIndex(tile));
388  return order;
389  }
390 
391  if (IsTileType(tile, MP_STATION)) {
392  StationID st_index = GetStationIndex(tile);
393  const Station *st = Station::Get(st_index);
394 
395  if (st->owner == _local_company || st->owner == OWNER_NONE) {
396  byte facil;
397  (facil = FACIL_DOCK, v->type == VEH_SHIP) ||
398  (facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
399  (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
400  (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
401  (facil = FACIL_TRUCK_STOP, 1);
402  if (st->facilities & facil) {
403  order.MakeGoToStation(st_index);
407  return order;
408  }
409  }
410  }
411 
412  /* not found */
413  order.Free();
414  return order;
415 }
416 
418 enum {
419  OHK_SKIP,
420  OHK_DELETE,
421  OHK_GOTO,
422  OHK_NONSTOP,
423  OHK_FULLLOAD,
424  OHK_UNLOAD,
425  OHK_NEAREST_DEPOT,
426  OHK_ALWAYS_SERVICE,
427  OHK_TRANSFER,
428  OHK_NO_UNLOAD,
429  OHK_NO_LOAD,
430 };
431 
472 struct OrdersWindow : public Window {
473 private:
476  OPOS_NONE,
477  OPOS_GOTO,
478  OPOS_CONDITIONAL,
479  OPOS_SHARE,
480  OPOS_END,
481  };
482 
484  enum DisplayPane {
485  /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
488 
489  /* WID_O_SEL_TOP_LEFT */
492 
493  /* WID_O_SEL_TOP_MIDDLE */
496 
497  /* WID_O_SEL_TOP_RIGHT */
500 
501  /* WID_O_SEL_TOP_ROW */
505 
506  /* WID_O_SEL_BOTTOM_MIDDLE */
509  };
510 
511  int selected_order;
513  OrderPlaceObjectState goto_type;
514  const Vehicle *vehicle;
515  Scrollbar *vscroll;
518 
525  {
526  int num = this->selected_order;
527  return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
528  }
529 
539  {
540  NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST);
541  int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
542 
543  if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID;
544 
545  sel += this->vscroll->GetPosition();
546 
547  return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID;
548  }
549 
554  {
555  assert(type > OPOS_NONE && type < OPOS_END);
556 
557  static const HighLightStyle goto_place_style[OPOS_END - 1] = {
558  HT_RECT | HT_VEHICLE, // OPOS_GOTO
559  HT_NONE, // OPOS_CONDITIONAL
560  HT_VEHICLE, // OPOS_SHARE
561  };
562  SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, goto_place_style[type - 1], this);
563  this->goto_type = type;
564  this->SetWidgetDirty(WID_O_GOTO);
565  }
566 
571  void OrderClick_FullLoad(int load_type)
572  {
573  VehicleOrderID sel_ord = this->OrderGetSel();
574  const Order *order = this->vehicle->GetOrder(sel_ord);
575 
576  if (order == NULL || order->GetLoadType() == load_type) return;
577 
578  if (load_type < 0) {
580  }
581  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));
582  }
583 
588  {
590  }
591 
595  void OrderClick_Service(int i)
596  {
597  VehicleOrderID sel_ord = this->OrderGetSel();
598 
599  if (i < 0) {
600  const Order *order = this->vehicle->GetOrder(sel_ord);
601  if (order == NULL) return;
603  }
604  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));
605  }
606 
611  {
612  Order order;
613  order.next = NULL;
614  order.index = 0;
618 
619  DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
620  }
621 
625  void OrderClick_Unload(int unload_type)
626  {
627  VehicleOrderID sel_ord = this->OrderGetSel();
628  const Order *order = this->vehicle->GetOrder(sel_ord);
629 
630  if (order == NULL || order->GetUnloadType() == unload_type) return;
631 
632  if (unload_type < 0) {
634  }
635 
636  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));
637 
638  /* Transfer orders with leave empty as default */
639  if (unload_type == OUFB_TRANSFER) {
640  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), CMD_MODIFY_ORDER);
642  }
643  }
644 
649  {
651  }
652 
657  {
659  }
660 
665  void OrderClick_Nonstop(int non_stop)
666  {
667  if (!this->vehicle->IsGroundVehicle()) return;
668 
669  VehicleOrderID sel_ord = this->OrderGetSel();
670  const Order *order = this->vehicle->GetOrder(sel_ord);
671 
672  if (order == NULL || order->GetNonStopType() == non_stop) return;
673 
674  /* Keypress if negative, so 'toggle' to the next */
675  if (non_stop < 0) {
677  }
678 
680  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));
681  }
682 
688  {
689  /* Don't skip when there's nothing to skip */
690  if (_ctrl_pressed && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
691  if (this->vehicle->GetNumOrders() <= 1) return;
692 
693  DoCommandP(this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()),
694  CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
695  }
696 
701  {
702  /* When networking, move one order lower */
703  int selected = this->selected_order + (int)_networking;
704 
705  if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
706  this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
707  this->UpdateButtonState();
708  }
709  }
710 
718  {
719  /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
720  if (!this->vehicle->IsOrderListShared() || this->selected_order != this->vehicle->GetNumOrders()) return;
721  /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
722  if (_ctrl_pressed) {
723  this->OrderClick_Delete();
724  return;
725  }
726 
727  /* Get another vehicle that share orders with this vehicle. */
728  Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
729  /* Copy the order list of the other vehicle. */
730  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))) {
731  this->UpdateButtonState();
732  }
733  }
734 
741  void OrderClick_Refit(int i, bool auto_refit)
742  {
743  if (_ctrl_pressed) {
744  /* Cancel refitting */
745  DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
746  } else {
747  if (i == 1) { // Auto-refit to available cargo type.
748  DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | CT_AUTO_REFIT, CMD_ORDER_REFIT);
749  } else {
750  ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
751  }
752  }
753  }
754 
757  {
758  this->can_do_refit = false;
759  this->can_do_autorefit = false;
760  for (const Vehicle *w = this->vehicle; w != NULL; w = w->IsGroundVehicle() ? w->Next() : NULL) {
761  if (IsEngineRefittable(w->engine_type)) this->can_do_refit = true;
762  if (HasBit(Engine::Get(w->engine_type)->info.misc_flags, EF_AUTO_REFIT)) this->can_do_autorefit = true;
763  }
764  }
765 
766 public:
767  OrdersWindow(WindowDesc *desc, const Vehicle *v) : Window(desc)
768  {
769  this->vehicle = v;
770 
771  this->CreateNestedTree();
772  this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
773  this->FinishInitNested(v->index);
774  if (v->owner == _local_company) {
775  this->DisableWidget(WID_O_EMPTY);
776  }
777 
778  this->selected_order = -1;
779  this->order_over = INVALID_VEH_ORDER_ID;
780  this->goto_type = OPOS_NONE;
781  this->owner = v->owner;
782 
783  this->UpdateAutoRefitState();
784 
786  /* If there are less than 2 station, make Go To active. */
787  int station_orders = 0;
788  const Order *order;
789  FOR_VEHICLE_ORDERS(v, order) {
790  if (order->IsType(OT_GOTO_STATION)) station_orders++;
791  }
792 
793  if (station_orders < 2) this->OrderClick_Goto(OPOS_GOTO);
794  }
796  }
797 
798  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
799  {
800  switch (widget) {
801  case WID_O_ORDER_LIST:
802  resize->height = FONT_HEIGHT_NORMAL;
803  size->height = 6 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
804  break;
805 
806  case WID_O_COND_VARIABLE: {
807  Dimension d = {0, 0};
808  for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
809  d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i]));
810  }
811  d.width += padding.width;
812  d.height += padding.height;
813  *size = maxdim(*size, d);
814  break;
815  }
816 
817  case WID_O_COND_COMPARATOR: {
818  Dimension d = {0, 0};
819  for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
820  d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
821  }
822  d.width += padding.width;
823  d.height += padding.height;
824  *size = maxdim(*size, d);
825  break;
826  }
827  }
828  }
829 
835  virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
836  {
839 
840  switch (data) {
841  case VIWD_AUTOREPLACE:
842  /* Autoreplace replaced the vehicle */
843  this->vehicle = Vehicle::Get(this->window_number);
844  FALLTHROUGH;
845 
847  /* Vehicle composition was changed. */
848  this->UpdateAutoRefitState();
849  break;
850 
852  /* Removed / replaced all orders (after deleting / sharing) */
853  if (this->selected_order == -1) break;
854 
855  this->DeleteChildWindows();
856  HideDropDownMenu(this);
857  this->selected_order = -1;
858  break;
859 
860  case VIWD_MODIFY_ORDERS:
861  /* Some other order changes */
862  break;
863 
864  default:
865  if (data < 0) break;
866 
867  if (gui_scope) break; // only do this once; from command scope
868  from = GB(data, 0, 8);
869  to = GB(data, 8, 8);
870  /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
871  * the order is being created / removed */
872  if (this->selected_order == -1) break;
873 
874  if (from == to) break; // no need to change anything
875 
876  if (from != this->selected_order) {
877  /* Moving from preceding order? */
878  this->selected_order -= (int)(from <= this->selected_order);
879  /* Moving to preceding order? */
880  this->selected_order += (int)(to <= this->selected_order);
881  break;
882  }
883 
884  /* Now we are modifying the selected order */
885  if (to == INVALID_VEH_ORDER_ID) {
886  /* Deleting selected order */
887  this->DeleteChildWindows();
888  HideDropDownMenu(this);
889  this->selected_order = -1;
890  break;
891  }
892 
893  /* Moving selected order */
894  this->selected_order = to;
895  break;
896  }
897 
898  this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
899  if (gui_scope) this->UpdateButtonState();
900 
901  /* Scroll to the new order. */
902  if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {
903  this->vscroll->ScrollTowards(to);
904  }
905  }
906 
907  void UpdateButtonState()
908  {
909  if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
910 
911  bool shared_orders = this->vehicle->IsOrderListShared();
912  VehicleOrderID sel = this->OrderGetSel();
913  const Order *order = this->vehicle->GetOrder(sel);
914 
915  /* Second row. */
916  /* skip */
917  this->SetWidgetDisabledState(WID_O_SKIP, this->vehicle->GetNumOrders() <= 1);
918 
919  /* delete / stop sharing */
920  NWidgetStacked *delete_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_BOTTOM_MIDDLE);
921  if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
922  /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
924  } else {
925  /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
926  delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE);
928  (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
929 
930  /* Set the tooltip of the 'delete' button depending on whether the
931  * 'End of Orders' order or a regular order is selected. */
932  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
933  if (this->selected_order == this->vehicle->GetNumOrders()) {
934  nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
935  } else {
936  nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
937  }
938  }
939 
940  /* First row. */
942  this->RaiseWidget(WID_O_UNLOAD);
943  this->RaiseWidget(WID_O_SERVICE);
944 
945  /* Selection widgets. */
946  /* Train or road vehicle. */
947  NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
948  NWidgetStacked *left_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
949  NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
950  NWidgetStacked *right_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
951  /* Ship or airplane. */
952  NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
953  assert(row_sel != NULL || (train_row_sel != NULL && left_sel != NULL && middle_sel != NULL && right_sel != NULL));
954 
955 
956  if (order == NULL) {
957  if (row_sel != NULL) {
958  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
959  } else {
961  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
962  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
963  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
966  }
970  } else {
973 
974  switch (order->GetType()) {
975  case OT_GOTO_STATION:
976  if (row_sel != NULL) {
977  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
978  } else {
980  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
981  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
982  right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
985  }
988 
989  /* Can only do refitting when stopping at the destination and loading cargo.
990  * Also enable the button if a refit is already set to allow clearing it. */
993  ((!this->can_do_refit || !this->can_do_autorefit) && !order->IsRefit()));
994 
995  break;
996 
997  case OT_GOTO_WAYPOINT:
998  if (row_sel != NULL) {
999  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1000  } else {
1002  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1003  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1004  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1007  }
1009  this->DisableWidget(WID_O_UNLOAD);
1011  break;
1012 
1013  case OT_GOTO_DEPOT:
1014  if (row_sel != NULL) {
1015  row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
1016  } else {
1018  left_sel->SetDisplayedPlane(DP_LEFT_REFIT);
1019  middle_sel->SetDisplayedPlane(DP_MIDDLE_SERVICE);
1020  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1023  }
1024  /* Disable refit button if the order is no 'always go' order.
1025  * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
1027  (order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT) ||
1028  (!this->can_do_refit && !order->IsRefit()));
1030  break;
1031 
1032  case OT_CONDITIONAL: {
1033  if (row_sel != NULL) {
1034  row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
1035  } else {
1037  }
1039  /* Set the strings for the dropdown boxes. */
1040  this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv;
1041  this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order->GetConditionComparator()];
1044  break;
1045  }
1046 
1047  default: // every other order
1048  if (row_sel != NULL) {
1049  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1050  } else {
1052  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1053  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1054  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1056  }
1058  this->DisableWidget(WID_O_UNLOAD);
1060  break;
1061  }
1062  }
1063 
1064  /* Disable list of vehicles with the same shared orders if there is no list */
1065  this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders);
1066 
1067  this->SetDirty();
1068  }
1069 
1070  virtual void OnPaint()
1071  {
1072  if (this->vehicle->owner != _local_company) {
1073  this->selected_order = -1; // Disable selection any selected row at a competitor order window.
1074  } else {
1075  this->SetWidgetLoweredState(WID_O_GOTO, this->goto_type != OPOS_NONE);
1076  }
1077  this->DrawWidgets();
1078  }
1079 
1080  virtual void DrawWidget(const Rect &r, int widget) const
1081  {
1082  if (widget != WID_O_ORDER_LIST) return;
1083 
1084  bool rtl = _current_text_dir == TD_RTL;
1085  SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
1086  int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
1087  int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
1088 
1089  int y = r.top + WD_FRAMERECT_TOP;
1090  int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
1091 
1092  int i = this->vscroll->GetPosition();
1093  const Order *order = this->vehicle->GetOrder(i);
1094  /* First draw the highlighting underground if it exists. */
1095  if (this->order_over != INVALID_VEH_ORDER_ID) {
1096  while (order != NULL) {
1097  /* Don't draw anything if it extends past the end of the window. */
1098  if (!this->vscroll->IsVisible(i)) break;
1099 
1100  if (i != this->selected_order && i == this->order_over) {
1101  /* Highlight dragged order destination. */
1102  int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
1103  int bottom = min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM);
1104  top = max(top - 3, r.top + WD_FRAMERECT_TOP);
1105  GfxFillRect(r.left + WD_FRAMETEXT_LEFT, top, r.right - WD_FRAMETEXT_RIGHT, bottom, _colour_gradient[COLOUR_GREY][7]);
1106  break;
1107  }
1108  y += line_height;
1109 
1110  i++;
1111  order = order->next;
1112  }
1113 
1114  /* Reset counters for drawing the orders. */
1115  y = r.top + WD_FRAMERECT_TOP;
1116  i = this->vscroll->GetPosition();
1117  order = this->vehicle->GetOrder(i);
1118  }
1119 
1120  /* Draw the orders. */
1121  while (order != NULL) {
1122  /* Don't draw anything if it extends past the end of the window. */
1123  if (!this->vscroll->IsVisible(i)) break;
1124 
1125  DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
1126  y += line_height;
1127 
1128  i++;
1129  order = order->next;
1130  }
1131 
1132  if (this->vscroll->IsVisible(i)) {
1133  StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
1134  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);
1135  }
1136  }
1137 
1138  virtual void SetStringParameters(int widget) const
1139  {
1140  switch (widget) {
1141  case WID_O_COND_VALUE: {
1142  VehicleOrderID sel = this->OrderGetSel();
1143  const Order *order = this->vehicle->GetOrder(sel);
1144 
1145  if (order != NULL && order->IsType(OT_CONDITIONAL)) {
1146  uint value = order->GetConditionValue();
1147  if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1148  SetDParam(0, value);
1149  }
1150  break;
1151  }
1152 
1153  case WID_O_CAPTION:
1154  SetDParam(0, this->vehicle->index);
1155  break;
1156  }
1157  }
1158 
1159  virtual void OnClick(Point pt, int widget, int click_count)
1160  {
1161  switch (widget) {
1162  case WID_O_ORDER_LIST: {
1163  if (this->goto_type == OPOS_CONDITIONAL) {
1164  VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
1165  if (order_id != INVALID_VEH_ORDER_ID) {
1166  Order order;
1167  order.next = NULL;
1168  order.index = 0;
1169  order.MakeConditional(order_id);
1170 
1171  DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
1172  }
1174  break;
1175  }
1176 
1177  VehicleOrderID sel = this->GetOrderFromPt(pt.y);
1178 
1179  if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
1180  TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
1181  if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
1182  return;
1183  }
1184 
1185  /* This order won't be selected any more, close all child windows and dropdowns */
1186  this->DeleteChildWindows();
1187  HideDropDownMenu(this);
1188 
1189  if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
1190  /* Deselect clicked order */
1191  this->selected_order = -1;
1192  } else if (sel == this->selected_order) {
1193  if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
1194  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20),
1195  MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
1196  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1197  }
1198  } else {
1199  /* Select clicked order */
1200  this->selected_order = sel;
1201 
1202  if (this->vehicle->owner == _local_company) {
1203  /* Activate drag and drop */
1204  SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1205  }
1206  }
1207 
1208  this->UpdateButtonState();
1209  break;
1210  }
1211 
1212  case WID_O_SKIP:
1213  this->OrderClick_Skip();
1214  break;
1215 
1216  case WID_O_DELETE:
1217  this->OrderClick_Delete();
1218  break;
1219 
1220  case WID_O_STOP_SHARING:
1221  this->OrderClick_StopSharing();
1222  break;
1223 
1224  case WID_O_NON_STOP:
1225  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1226  this->OrderClick_Nonstop(-1);
1227  } else {
1228  const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1229  ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
1230  o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
1231  }
1232  break;
1233 
1234  case WID_O_GOTO:
1235  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1236  if (this->goto_type != OPOS_NONE) {
1238  } else {
1239  this->OrderClick_Goto(OPOS_GOTO);
1240  }
1241  } else {
1242  int sel;
1243  switch (this->goto_type) {
1244  case OPOS_NONE: sel = -1; break;
1245  case OPOS_GOTO: sel = 0; break;
1246  case OPOS_CONDITIONAL: sel = 2; break;
1247  case OPOS_SHARE: sel = 3; break;
1248  default: NOT_REACHED();
1249  }
1250  ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
1251  }
1252  break;
1253 
1254  case WID_O_FULL_LOAD:
1255  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1256  this->OrderClick_FullLoad(-1);
1257  } else {
1258  ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
1259  }
1260  break;
1261 
1262  case WID_O_UNLOAD:
1263  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1264  this->OrderClick_Unload(-1);
1265  } else {
1266  ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
1267  }
1268  break;
1269 
1270  case WID_O_REFIT:
1271  this->OrderClick_Refit(0, false);
1272  break;
1273 
1274  case WID_O_SERVICE:
1275  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1276  this->OrderClick_Service(-1);
1277  } else {
1278  ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_SERVICE, 0, 0);
1279  }
1280  break;
1281 
1282  case WID_O_REFIT_DROPDOWN:
1283  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1284  this->OrderClick_Refit(0, true);
1285  } else {
1286  ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
1287  }
1288  break;
1289 
1290  case WID_O_TIMETABLE_VIEW:
1291  ShowTimetableWindow(this->vehicle);
1292  break;
1293 
1294  case WID_O_COND_VARIABLE: {
1295  DropDownList *list = new DropDownList();
1296  for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
1297  *list->Append() = new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false);
1298  }
1299  ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
1300  break;
1301  }
1302 
1303  case WID_O_COND_COMPARATOR: {
1304  const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1305  ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
1306  break;
1307  }
1308 
1309  case WID_O_COND_VALUE: {
1310  const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
1311  uint value = order->GetConditionValue();
1312  if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1313  SetDParam(0, value);
1314  ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE);
1315  break;
1316  }
1317 
1319  ShowVehicleListWindow(this->vehicle);
1320  break;
1321  }
1322  }
1323 
1324  virtual void OnQueryTextFinished(char *str)
1325  {
1326  if (!StrEmpty(str)) {
1327  VehicleOrderID sel = this->OrderGetSel();
1328  uint value = atoi(str);
1329 
1330  switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
1331  case OCV_MAX_SPEED:
1332  value = ConvertDisplaySpeedToSpeed(value);
1333  break;
1334 
1335  case OCV_RELIABILITY:
1336  case OCV_LOAD_PERCENTAGE:
1337  value = Clamp(value, 0, 100);
1338  break;
1339 
1340  default:
1341  break;
1342  }
1343  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));
1344  }
1345  }
1346 
1347  virtual void OnDropdownSelect(int widget, int index)
1348  {
1349  switch (widget) {
1350  case WID_O_NON_STOP:
1351  this->OrderClick_Nonstop(index);
1352  break;
1353 
1354  case WID_O_FULL_LOAD:
1355  this->OrderClick_FullLoad(index);
1356  break;
1357 
1358  case WID_O_UNLOAD:
1359  this->OrderClick_Unload(index);
1360  break;
1361 
1362  case WID_O_GOTO:
1363  switch (index) {
1364  case 0: this->OrderClick_Goto(OPOS_GOTO); break;
1365  case 1: this->OrderClick_NearestDepot(); break;
1366  case 2: this->OrderClick_Goto(OPOS_CONDITIONAL); break;
1367  case 3: this->OrderClick_Goto(OPOS_SHARE); break;
1368  default: NOT_REACHED();
1369  }
1370  break;
1371 
1372  case WID_O_SERVICE:
1373  this->OrderClick_Service(index);
1374  break;
1375 
1376  case WID_O_REFIT_DROPDOWN:
1377  this->OrderClick_Refit(index, true);
1378  break;
1379 
1380  case WID_O_COND_VARIABLE:
1381  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));
1382  break;
1383 
1384  case WID_O_COND_COMPARATOR:
1385  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));
1386  break;
1387  }
1388  }
1389 
1390  virtual void OnDragDrop(Point pt, int widget)
1391  {
1392  switch (widget) {
1393  case WID_O_ORDER_LIST: {
1394  VehicleOrderID from_order = this->OrderGetSel();
1395  VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1396 
1397  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()) &&
1398  DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
1399  this->selected_order = -1;
1400  this->UpdateButtonState();
1401  }
1402  break;
1403  }
1404 
1405  case WID_O_DELETE:
1406  this->OrderClick_Delete();
1407  break;
1408 
1409  case WID_O_STOP_SHARING:
1410  this->OrderClick_StopSharing();
1411  break;
1412  }
1413 
1415 
1416  if (this->order_over != INVALID_VEH_ORDER_ID) {
1417  /* End of drag-and-drop, hide dragged order destination highlight. */
1418  this->order_over = INVALID_VEH_ORDER_ID;
1420  }
1421  }
1422 
1423  virtual EventState OnHotkey(int hotkey)
1424  {
1425  if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
1426 
1427  switch (hotkey) {
1428  case OHK_SKIP: this->OrderClick_Skip(); break;
1429  case OHK_DELETE: this->OrderClick_Delete(); break;
1430  case OHK_GOTO: this->OrderClick_Goto(OPOS_GOTO); break;
1431  case OHK_NONSTOP: this->OrderClick_Nonstop(-1); break;
1432  case OHK_FULLLOAD: this->OrderClick_FullLoad(-1); break;
1433  case OHK_UNLOAD: this->OrderClick_Unload(-1); break;
1434  case OHK_NEAREST_DEPOT: this->OrderClick_NearestDepot(); break;
1435  case OHK_ALWAYS_SERVICE: this->OrderClick_Service(-1); break;
1436  case OHK_TRANSFER: this->OrderHotkey_Transfer(); break;
1437  case OHK_NO_UNLOAD: this->OrderHotkey_NoUnload(); break;
1438  case OHK_NO_LOAD: this->OrderHotkey_NoLoad(); break;
1439  default: return ES_NOT_HANDLED;
1440  }
1441  return ES_HANDLED;
1442  }
1443 
1444  virtual void OnPlaceObject(Point pt, TileIndex tile)
1445  {
1446  if (this->goto_type == OPOS_GOTO) {
1447  const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
1448  if (cmd.IsType(OT_NOTHING)) return;
1449 
1450  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))) {
1451  /* With quick goto the Go To button stays active */
1453  }
1454  }
1455  }
1456 
1457  virtual bool OnVehicleSelect(const Vehicle *v)
1458  {
1459  /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
1460  * We disallow copying orders of other vehicles if we already have at least one order entry
1461  * ourself as it easily copies orders of vehicles within a station when we mean the station.
1462  * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
1463  * TODO: give a warning message */
1464  bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
1465  if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
1466 
1467  if (DoCommandP(this->vehicle->tile, this->vehicle->index | (share_order ? CO_SHARE : CO_COPY) << 30, v->index,
1468  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))) {
1469  this->selected_order = -1;
1471  }
1472  return true;
1473  }
1474 
1475  virtual void OnPlaceObjectAbort()
1476  {
1477  this->goto_type = OPOS_NONE;
1478  this->SetWidgetDirty(WID_O_GOTO);
1479 
1480  /* Remove drag highlighting if it exists. */
1481  if (this->order_over != INVALID_VEH_ORDER_ID) {
1482  this->order_over = INVALID_VEH_ORDER_ID;
1484  }
1485  }
1486 
1487  virtual void OnMouseDrag(Point pt, int widget)
1488  {
1489  if (this->selected_order != -1 && widget == WID_O_ORDER_LIST) {
1490  /* An order is dragged.. */
1491  VehicleOrderID from_order = this->OrderGetSel();
1492  VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1493  uint num_orders = this->vehicle->GetNumOrders();
1494 
1495  if (from_order != INVALID_VEH_ORDER_ID && from_order <= num_orders) {
1496  if (to_order != INVALID_VEH_ORDER_ID && to_order <= num_orders) { // ..over an existing order.
1497  this->order_over = to_order;
1498  this->SetWidgetDirty(widget);
1499  } else if (from_order != to_order && this->order_over != INVALID_VEH_ORDER_ID) { // ..outside of the order list.
1500  this->order_over = INVALID_VEH_ORDER_ID;
1501  this->SetWidgetDirty(widget);
1502  }
1503  }
1504  }
1505  }
1506 
1507  virtual void OnResize()
1508  {
1509  /* Update the scroll bar */
1510  this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
1511  }
1512 
1513  static HotkeyList hotkeys;
1514 };
1515 
1516 static Hotkey order_hotkeys[] = {
1517  Hotkey('D', "skip", OHK_SKIP),
1518  Hotkey('F', "delete", OHK_DELETE),
1519  Hotkey('G', "goto", OHK_GOTO),
1520  Hotkey('H', "nonstop", OHK_NONSTOP),
1521  Hotkey('J', "fullload", OHK_FULLLOAD),
1522  Hotkey('K', "unload", OHK_UNLOAD),
1523  Hotkey((uint16)0, "nearest_depot", OHK_NEAREST_DEPOT),
1524  Hotkey((uint16)0, "always_service", OHK_ALWAYS_SERVICE),
1525  Hotkey((uint16)0, "transfer", OHK_TRANSFER),
1526  Hotkey((uint16)0, "no_unload", OHK_NO_UNLOAD),
1527  Hotkey((uint16)0, "no_load", OHK_NO_LOAD),
1528  HOTKEY_LIST_END
1529 };
1530 HotkeyList OrdersWindow::hotkeys("order", order_hotkeys);
1531 
1535  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1536  NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1537  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1538  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1539  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1540  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1541  EndContainer(),
1543  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(),
1544  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1545  EndContainer(),
1546 
1547  /* First button row. */
1551  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_NON_STOP), SetMinimalSize(93, 12), SetFill(1, 0),
1552  SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
1553  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_LEFT),
1554  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1555  SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1556  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(93, 12), SetFill(1, 0),
1557  SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1558  EndContainer(),
1559  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_MIDDLE),
1560  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1561  SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1562  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(93, 12), SetFill(1, 0),
1563  SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1564  EndContainer(),
1565  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_RIGHT),
1566  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_O_EMPTY), SetMinimalSize(93, 12), SetFill(1, 0),
1567  SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1569  SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1570  EndContainer(),
1571  EndContainer(),
1573  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1574  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1575  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1576  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1577  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1578  SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1579  EndContainer(),
1580  EndContainer(),
1581  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),
1582  EndContainer(),
1583 
1584  /* Second button row. */
1587  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1588  SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1590  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1591  SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1592  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1593  SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1594  EndContainer(),
1595  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1596  SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1597  EndContainer(),
1598  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1599  EndContainer(),
1600 };
1601 
1602 static WindowDesc _orders_train_desc(
1603  WDP_AUTO, "view_vehicle_orders_train", 384, 100,
1606  _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets),
1607  &OrdersWindow::hotkeys
1608 );
1609 
1613  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1614  NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1615  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1616  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1617  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1618  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1619  EndContainer(),
1621  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(),
1622  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1623  EndContainer(),
1624 
1625  /* First button row. */
1627  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW),
1628  /* Load + unload + refit buttons. */
1630  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1631  SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1632  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1633  SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1635  SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1636  EndContainer(),
1637  /* Refit + service buttons. */
1639  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
1640  SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1641  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
1642  SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1643  EndContainer(),
1644 
1645  /* Buttons for setting a condition. */
1647  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1648  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1649  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1650  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1651  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1652  SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1653  EndContainer(),
1654  EndContainer(),
1655 
1656  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),
1657  EndContainer(),
1658 
1659  /* Second button row. */
1661  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1662  SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1664  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1665  SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1666  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1667  SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1668  EndContainer(),
1669  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1670  SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1671  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1672  EndContainer(),
1673 };
1674 
1675 static WindowDesc _orders_desc(
1676  WDP_AUTO, "view_vehicle_orders", 384, 100,
1679  _nested_orders_widgets, lengthof(_nested_orders_widgets),
1680  &OrdersWindow::hotkeys
1681 );
1682 
1686  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1687  NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1688  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1689  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1690  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1691  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1692  EndContainer(),
1694  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(),
1696  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1697  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1698  EndContainer(),
1699  EndContainer(),
1700 };
1701 
1702 static WindowDesc _other_orders_desc(
1703  WDP_AUTO, "view_vehicle_orders_competitor", 384, 86,
1706  _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets),
1707  &OrdersWindow::hotkeys
1708 );
1709 
1710 void ShowOrdersWindow(const Vehicle *v)
1711 {
1714  if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
1715 
1716  /* Using a different WindowDescs for _local_company causes problems.
1717  * Due to this we have to close order windows in ChangeWindowOwner/DeleteCompanyWindows,
1718  * because we cannot change switch the WindowDescs and keeping the old WindowDesc results
1719  * in crashed due to missing widges.
1720  * TODO Rewrite the order GUI to not use different WindowDescs.
1721  */
1722  if (v->owner != _local_company) {
1723  new OrdersWindow(&_other_orders_desc, v);
1724  } else {
1725  new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);
1726  }
1727 }
OrderConditionVariable
Variables (of a vehicle) to &#39;cause&#39; skipping on.
Definition: order_type.h:118
EventState
State of handling an event.
Definition: window_type.h:701
void OrderClick_NearestDepot()
Handle the click on the service in nearest depot button.
Definition: order_gui.cpp:610
NWID_SELECTION widget for the top row of the &#39;your train&#39; order window.
Definition: order_widget.h:38
Functions related to OTTD&#39;s strings.
Display the row for normal/depot orders in the top row of the train/rv order window.
Definition: order_gui.cpp:486
Road vehicle states.
static const StringID _station_load_types[][5][5]
Order load types that could be given to station orders.
Definition: order_gui.cpp:39
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
uint ConvertSpeedToDisplaySpeed(uint speed)
Convert the given (internal) speed to the display speed.
Definition: strings.cpp:722
bool _networking
are we in networking mode?
Definition: network.cpp:56
Passes an OrderUnloadType.
Definition: order_type.h:151
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
void OrderClick_StopSharing()
Handle the click on the &#39;stop sharing&#39; button.
Definition: order_gui.cpp:717
bool quick_goto
Allow quick access to &#39;goto button&#39; in vehicle orders window.
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:731
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Goto non-stop to destination.
Definition: order_widget.h:24
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1843
Automatically choose cargo type when doing auto refitting.
Definition: cargo_type.h:68
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
Definition: gfx.cpp:112
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:387
Point pos
logical mouse position
Definition: gfx_type.h:119
Stop sharing orders.
Definition: order_widget.h:23
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:448
Load as long as there is cargo that fits in the train.
Definition: order_type.h:69
void OrderClick_Skip()
Handle the click on the skip button.
Definition: order_gui.cpp:687
Delete selected order.
Definition: order_widget.h:22
bool IsGotoOrder() const
Is this a &#39;goto&#39; order with a real destination?
Definition: order_base.h:86
OrderConditionComparator GetConditionComparator() const
What is the comparator to use?
Definition: order_base.h:143
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: order_gui.cpp:835
All data for a single hotkey.
Definition: hotkeys.h:24
High level window description.
Definition: window_gui.h:168
Open list of shared vehicles.
Definition: order_widget.h:41
Functions related to time tabling.
static const NWidgetPart _nested_other_orders_widgets[]
Nested widget definition for competitor orders.
Definition: order_gui.cpp:1684
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:604
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
Hotkey related functions.
static const NWidgetPart _nested_orders_widgets[]
Nested widget definition for "your" orders (non-train).
Definition: order_gui.cpp:1611
void OrderClick_Refit(int i, bool auto_refit)
Handle the click on the refit button.
Definition: order_gui.cpp:741
Scrollbar data structure.
Definition: widget_type.h:589
Vehicle composition was changed.
Definition: vehicle_gui.h:36
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:405
VehicleOrderID GetConditionSkipToOrder() const
Get the order to skip to.
Definition: order_base.h:145
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:577
virtual void OnDragDrop(Point pt, int widget)
A dragged &#39;object&#39; has been released.
Definition: order_gui.cpp:1390
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
Definition: order_type.h:23
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
Other order modifications.
Definition: vehicle_gui.h:35
Horizontal container.
Definition: widget_type.h:75
The passed event is not handled.
Definition: window_type.h:703
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:53
void SetDepotOrderType(OrderDepotTypeFlags depot_order_type)
Set the cause to go to the depot.
Definition: order_base.h:158
void OrderClick_Unload(int unload_type)
Handle the click on the unload button.
Definition: order_gui.cpp:625
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1065
NWID_SELECTION widget for right part of the top row of the &#39;your train&#39; order window.
Definition: order_widget.h:37
void SetDepotActionType(OrderDepotActionFlags depot_service_type)
Set what we are going to do in the depot.
Definition: order_base.h:160
uint8 stop_location
what is the default stop location of trains?
Definition: settings_type.h:83
Select service (at depot).
Definition: order_widget.h:29
const Vehicle * vehicle
Vehicle owning the orders being displayed and manipulated.
Definition: order_gui.cpp:514
Placeholder for refit dropdown when not owner.
Definition: order_widget.h:30
Selects the OrderDepotAction.
Definition: order_type.h:153
Skip if the variable is true.
Definition: order_type.h:139
Skip based on the reliability.
Definition: order_type.h:120
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
A comparator changes.
Definition: order_type.h:155
Vehicle data structure.
Definition: vehicle_base.h:212
int top
y position of top edge of the window
Definition: window_gui.h:313
Unload all cargo that the station accepts.
Definition: order_type.h:59
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
Close box (at top-left of a window)
Definition: widget_type.h:69
bool can_do_autorefit
Vehicle chain can be auto-refitted.
Definition: order_gui.cpp:517
Display &#39;refit&#39; in the left button of the top row of the train/rv order window.
Definition: order_gui.cpp:491
Base for aircraft.
static bool IsRailWaypointTile(TileIndex t)
Is this tile a station tile and a rail waypoint?
Definition: station_map.h:124
void OrderClick_Nonstop(int non_stop)
Handle the click on the nonstop button.
Definition: order_gui.cpp:665
clone (and share) an order
Definition: command_type.h:271
Stuff related to the text buffer GUI.
void UpdateAutoRefitState()
Cache auto-refittability of the vehicle chain.
Definition: order_gui.cpp:756
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:397
void OrderClick_Goto(OrderPlaceObjectState type)
Handle the click on the goto button.
Definition: order_gui.cpp:553
Display &#39;refit&#39; / &#39;service&#39; buttons in the top row of the ship/airplane order window.
Definition: order_gui.cpp:503
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
Skip based on the age.
Definition: order_type.h:122
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:478
TileIndex GetLocation(const Vehicle *v, bool airport=false) const
Returns a tile somewhat representing the order destination (not suitable for pathfinding).
Definition: order_cmd.cpp:670
Common string list item.
Definition: dropdown_type.h:41
NWID_SELECTION widget for the middle part of the bottom row of the &#39;your train&#39; order window...
Definition: order_widget.h:40
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1804
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
Definition: order_base.h:139
skip an order to the next of specific one
Definition: command_type.h:227
The vehicle will stop at any station it passes except the destination.
Definition: order_type.h:81
virtual void OnPlaceObject(Point pt, TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
Definition: order_gui.cpp:1444
uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth)
Get the distance between two orders of a vehicle.
Definition: order_cmd.cpp:697
T * Append(uint to_add=1)
Append an item and return it.
Order * next
Pointer to next order. If NULL, end of list.
Definition: order_base.h:51
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:676
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
Force the alignment, i.e. don&#39;t swap for RTL languages.
Definition: gfx_func.h:110
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
bool IsAutoRefit() const
Is this order a auto-refit order.
Definition: order_base.h:117
Functions related to (drawing on) viewports.
Select refit.
Definition: order_widget.h:28
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
Definition: order_gui.cpp:1347
Display &#39;load&#39; in the left button of the top row of the train/rv order window.
Definition: order_gui.cpp:490
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Definition: engine.cpp:1102
Data structure for an opened window.
Definition: window_gui.h:271
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:36
Stop at the far end of the platform.
Definition: order_type.h:92
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1820
The vehicle will stop at any station it passes and the destination.
Definition: order_type.h:79
Autoreplace replaced the vehicle.
Definition: vehicle_gui.h:37
virtual void OnResize()
Called after the window got resized.
Definition: order_gui.cpp:1507
Types related to the order widgets.
void MakeConditional(VehicleOrderID order)
Makes this order an conditional order.
Definition: order_cmd.cpp:144
dragging items in the depot windows
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:207
Passes an OrderStopLocation.
Definition: order_type.h:150
OrderDepotTypeFlags GetDepotOrderType() const
What caused us going to the depot?
Definition: order_base.h:137
Vehicle orders; Window numbers:
Definition: window_type.h:207
Aircraft vehicle type.
Definition: vehicle_type.h:27
DisplayPane
Displayed planes of the NWID_SELECTION widgets.
Definition: order_gui.cpp:484
Map related accessors for depots.
Functions related to low-level strings.
OrderConditionVariable GetConditionVariable() const
What variable do we have to compare?
Definition: order_base.h:141
Display the row for conditional orders in the top row of the train/rv order window.
Definition: order_gui.cpp:487
Caption of the window.
Definition: order_widget.h:17
Only numeric ones.
Definition: string_type.h:28
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
void SetNonStopType(OrderNonStopFlags non_stop_type)
Set whether we must stop at stations or not.
Definition: order_base.h:154
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
Draws an order in order or timetable GUI.
Definition: order_gui.cpp:213
uint pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:178
void OrderClick_Service(int i)
Handle the click on the service.
Definition: order_gui.cpp:595
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
void SetDataTip(uint32 widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:894
bool IsRefit() const
Is this order a refit order.
Definition: order_base.h:110
The vehicle will not stop at any stations it passes including the destination.
Definition: order_type.h:82
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
Definition: cargo_type.h:69
Functions related to engines.
bool can_do_refit
Vehicle chain can be refitted in depot.
Definition: order_gui.cpp:516
static bool IsDepotTypeTile(TileIndex tile, TransportType type)
Check if a tile is a depot and it is a depot of the given type.
Definition: depot_map.h:20
Do not load anything.
Definition: order_type.h:72
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
Show the refit window for a vehicle.
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:63
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:180
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
Simple vector template class, with automatic delete.
Station with truck stops.
Definition: station_type.h:56
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:76
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
Definition of base types and functions in a cross-platform compatible way.
Select unload.
Definition: order_widget.h:27
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: order_gui.cpp:1080
NWID_SELECTION widget for middle part of the top row of the &#39;your train&#39; order window.
Definition: order_widget.h:36
Removed / replaced all orders (after deleting / sharing).
Definition: vehicle_gui.h:34
A number of safeguards to prevent using unsafe methods.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:247
List of hotkeys for a window.
Definition: hotkeys.h:42
static const CursorID ANIMCURSOR_PICKSTATION
716 - 718 - goto-order icon
Definition: sprites.h:1470
Always skip.
Definition: order_type.h:124
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
Base of waypoints.
Geometry functions.
rectangle (stations, depots, ...)
Simple depressed panel.
Definition: widget_type.h:50
Order list panel.
Definition: order_widget.h:19
void DeleteChildWindows(WindowClass wc=WC_INVALID) const
Delete all children a window might have in a head-recursive manner.
Definition: window.cpp:1047
VehicleOrderID OrderGetSel() const
Return the memorised selected order.
Definition: order_gui.cpp:524
void OrderHotkey_Transfer()
Handle the transfer hotkey.
Definition: order_gui.cpp:648
insert a new order
Definition: command_type.h:229
OrderPlaceObjectState
Under what reason are we using the PlaceObject functionality?
Definition: order_gui.cpp:475
static bool IsBuoyTile(TileIndex t)
Is tile t a buoy tile?
Definition: station_map.h:317
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:307
uint16 GetRange() const
Get the range of this aircraft.
Definition: aircraft.h:133
Vehicle view; Window numbers:
Definition: window_type.h:334
Order window code for all vehicles.
Definition: order_gui.cpp:472
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Definition: order_base.h:176
virtual void OnMouseDrag(Point pt, int widget)
An &#39;object&#39; is being dragged at the provided position, highlight the target if possible.
Definition: order_gui.cpp:1487
TileIndex tile
Current tile index.
Definition: vehicle_base.h:230
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
Definition: order_gui.cpp:1475
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
Display &#39;stop sharing&#39; in the middle button of the bottom row of the vehicle order window...
Definition: order_gui.cpp:508
The tile has no ownership.
Definition: company_type.h:27
Vehicle timetable; Window numbers:
Definition: window_type.h:219
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
OrderConditionComparator
Comparator for the skip reasoning.
Definition: order_type.h:132
Baseclass for nested widgets.
Definition: widget_type.h:126
Button with a drop-down.
Definition: widget_type.h:82
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:499
Always go to the depot.
Definition: order_type.h:166
OrderLoadFlags GetLoadType() const
How must the consist be loaded?
Definition: order_base.h:129
static const OrderConditionVariable _order_conditional_variable[]
Variables for conditional orders; this defines the order of appearance in the dropdown box...
Definition: order_gui.cpp:152
Skip current order.
Definition: order_widget.h:21
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
Definition: order_gui.cpp:1324
Basic functions/variables used all over the place.
Service the vehicle and then halt it.
Definition: order_type.h:110
StationFacilityByte facilities
The facilities that this station has.
Right offset of the text of the frame.
Definition: window_gui.h:73
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:527
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
Road vehicle type.
Definition: vehicle_type.h:25
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:167
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
Service only if needed.
Definition: order_type.h:167
Left offset of the text of the frame.
Definition: window_gui.h:72
Station with a dock.
Definition: station_type.h:59
Display the conditional order buttons in the top row of the ship/airplane order window.
Definition: order_gui.cpp:504
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
Definition: vehicle_base.h:655
The value to set the condition to.
Definition: order_type.h:156
Skip based on the remaining lifetime.
Definition: order_type.h:125
static DepotID GetDepotIndex(TileIndex t)
Get the index of which depot is attached to the tile.
Definition: depot_map.h:54
NWID_SELECTION widget for left part of the top row of the &#39;your train&#39; order window.
Definition: order_widget.h:35
Transfer all cargo onto the platform.
Definition: order_type.h:61
Ship vehicle type.
Definition: vehicle_type.h:26
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:139
OrderUnloadFlags GetUnloadType() const
How must the consist be unloaded?
Definition: order_base.h:131
VehicleOrderID GetOrderFromPt(int y)
Calculate the selected order.
Definition: order_gui.cpp:538
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:959
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:641
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: order_gui.cpp:798
void SetLoadType(OrderLoadFlags load_type)
Set how the consist must be loaded.
Definition: order_base.h:150
Skip when the vehicle requires service.
Definition: order_type.h:123
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:699
OwnerByte owner
The owner of this station.
OrderUnloadFlags
Flags related to the unloading order.
Definition: order_type.h:58
uint16 GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not)...
Definition: order_base.h:185
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1137
Open refit options.
Definition: order_widget.h:31
Display &#39;delete&#39; in the middle button of the bottom row of the vehicle order window.
Definition: order_gui.cpp:507
void OrderClick_FullLoad(int load_type)
Handle the click on the full load button.
Definition: order_gui.cpp:571
A conditional variable changes.
Definition: order_type.h:154
Functions related to companies.
default
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:29
OrderStopLocation
Where to stop the trains.
Definition: order_type.h:89
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
Definition: viewport.cpp:3151
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:80
Goto destination.
Definition: order_widget.h:25
Passes an OrderNonStopFlags.
Definition: order_type.h:149
Automatic refitting is allowed.
Definition: engine_type.h:158
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: order_gui.cpp:1138
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:472
VehicleOrderID order_over
Order over which another order is dragged, INVALID_VEH_ORDER_ID if none.
Definition: order_gui.cpp:512
GUISettings gui
settings related to the GUI
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:96
void ShowTimetableWindow(const Vehicle *v)
Show the timetable for a given vehicle.
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CT_NO_REFIT)
Makes this order a Go To Depot order.
Definition: order_cmd.cpp:91
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
Toggle timetable view.
Definition: order_widget.h:18
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
OrderStopLocation GetStopLocation() const
Where must we stop at the platform?
Definition: order_base.h:135
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:118
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
OrderLoadFlags
Flags related to the loading order.
Definition: order_type.h:68
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: order_gui.cpp:1159
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:52
void OrderHotkey_NoLoad()
Handle the &#39;no loading&#39; hotkey.
Definition: order_gui.cpp:587
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
Definition: vehicle_base.h:670
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:105
Send the vehicle to the nearest depot.
Definition: order_type.h:111
void Free()
&#39;Free&#39; the order
Definition: order_cmd.cpp:64
Vertical container.
Definition: widget_type.h:77
OwnerByte owner
Which company owns the vehicle?
Definition: vehicle_base.h:273
uint16 GetConditionValue() const
Get the value to base the skip on.
Definition: order_base.h:147
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Do not add shading to this text colour.
Definition: gfx_type.h:271
A tile of a station.
Definition: tile_type.h:48
Skip based on the amount of load.
Definition: order_type.h:119
void SetTimetableParams(int param1, int param2, Ticks ticks)
Set the timetable parameters in the format as described by the setting.
change the refit information of an order (for "goto depot" )
Definition: command_type.h:270
uint ConvertDisplaySpeedToSpeed(uint speed)
Convert the given display speed to the (internal) speed.
Definition: strings.cpp:735
Display &#39;load&#39; / &#39;unload&#39; / &#39;refit&#39; buttons in the top row of the ship/airplane order window...
Definition: order_gui.cpp:502
Station with train station.
Definition: station_type.h:55
Totally no unloading will be done.
Definition: order_type.h:62
The vehicle will not stop at any stations it passes except the destination.
Definition: order_type.h:80
Skip based on the maximum speed.
Definition: order_type.h:121
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2268
Vehicle details; Window numbers:
Definition: window_type.h:195
Display &#39;service&#39; in the middle button of the top row of the train/rv order window.
Definition: order_gui.cpp:495
Functions related to commands.
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:768
Passes an OrderLoadType.
Definition: order_type.h:152
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1084
Drop down list.
Definition: widget_type.h:70
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:622
Station with bus stops.
Definition: station_type.h:57
Order * GetOrder(int index) const
Returns order &#39;index&#39; of a vehicle or NULL when it doesn&#39;t exists.
Definition: vehicle_base.h:859
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:19
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
Definition: window_gui.h:319
HighLightStyle
Highlighting draw styles.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:688
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Definition: vehicle_base.h:682
void MakeGoToWaypoint(StationID destination)
Makes this order a Go To Waypoint order.
Definition: order_cmd.cpp:105
vehicle is accepted as target as well (bitmask)
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
virtual void OnPaint()
The window must be repainted.
Definition: order_gui.cpp:1070
Choose condition variable.
Definition: order_widget.h:32
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:17
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Select full load.
Definition: order_widget.h:26
Order list scrollbar.
Definition: order_widget.h:20
Choose condition value.
Definition: order_widget.h:34
uint32 Pack() const
Pack this order into a 32 bits integer, or actually only the type, flags and destination.
Definition: order_cmd.cpp:199
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:366
OrderType GetType() const
Get the type of order of this order.
Definition: order_base.h:69
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget. ...
Definition: widget.cpp:1973
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Definition: viewport.cpp:3211
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:84
bool new_nonstop
ttdpatch compatible nonstop handling
Definition: settings_type.h:82
The passed event is handled.
Definition: window_type.h:702
Text is written right-to-left by default.
Definition: strings_type.h:26
Right align the text (must be a single bit).
Definition: gfx_func.h:100
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition: vehicle_base.h:664
Functions related to tile highlights.
Find a place automatically.
Definition: window_gui.h:156
Force unloading all cargo onto the platform, possibly not getting paid.
Definition: order_type.h:60
static const NWidgetPart _nested_orders_train_widgets[]
Nested widget definition for "your" train orders.
Definition: order_gui.cpp:1533
Display an empty panel in the right button of the top row of the train/rv order window.
Definition: order_gui.cpp:498
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:80
This depot order is because of a regular order.
Definition: order_type.h:102
Go to the depot and stop there.
Definition: order_type.h:168
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1349
Base classes/functions for stations.
static Station * Get(size_t index)
Gets station with given index.
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
Get the order command a vehicle can do in a given tile.
Definition: order_gui.cpp:357
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
Definition: base_consist.h:30
move an order
Definition: command_type.h:324
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
Full load a single cargo of the consist.
Definition: order_type.h:71
This depot order is because of the servicing limit.
Definition: order_type.h:101
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:29
VehicleTypeByte type
Type of vehicle.
Definition: vehicle_type.h:54
Skip if the variable is false.
Definition: order_type.h:140
Dimensions (a width and height) of a rectangle in 2D.
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:429
void SetStopLocation(OrderStopLocation stop_location)
Set where we must stop at the platform.
Definition: order_base.h:156
Station data structure.
Definition: station_base.h:446
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1234
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition: order_base.h:133
Display &#39;refit&#39; in the right button of the top row of the train/rv order window.
Definition: order_gui.cpp:499
NWID_SELECTION widget for the top row of the &#39;your non-trains&#39; order window.
Definition: order_widget.h:39
modify an order (like set full-load)
Definition: command_type.h:226
Station with an airport.
Definition: station_type.h:58
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:833
delete an order
Definition: command_type.h:228
Choose condition type.
Definition: order_widget.h:33
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: order_gui.cpp:1423
Display &#39;unload&#39; in the middle button of the top row of the train/rv order window.
Definition: order_gui.cpp:494
void MakeGoToStation(StationID destination)
Makes this order a Go To Station order.
Definition: order_cmd.cpp:76
OrderDepotTypeFlags
Reasons that could cause us to go to the depot.
Definition: order_type.h:99
void EnableWidget(byte widget_index)
Sets a widget to Enabled.
Definition: window_gui.h:406
CargoID GetRefitCargo() const
Get the cargo to to refit to.
Definition: order_base.h:124
(Toggle) Button with text
Definition: widget_type.h:55
void OrderHotkey_NoUnload()
Handle the &#39;no unload&#39; hotkey.
Definition: order_gui.cpp:656
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:631
Train vehicle type.
Definition: vehicle_type.h:24
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:201
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:284
void OrderClick_Delete()
Handle the click on the delete button.
Definition: order_gui.cpp:700