OpenTTD Source  1.11.2
vehicle_gui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "debug.h"
12 #include "company_func.h"
13 #include "gui.h"
14 #include "textbuf_gui.h"
15 #include "command_func.h"
16 #include "vehicle_gui_base.h"
17 #include "viewport_func.h"
18 #include "newgrf_text.h"
19 #include "newgrf_debug.h"
20 #include "roadveh.h"
21 #include "train.h"
22 #include "aircraft.h"
23 #include "depot_map.h"
24 #include "group_gui.h"
25 #include "strings_func.h"
26 #include "vehicle_func.h"
27 #include "autoreplace_gui.h"
28 #include "string_func.h"
29 #include "widgets/dropdown_func.h"
30 #include "timetable.h"
31 #include "articulated_vehicles.h"
32 #include "spritecache.h"
33 #include "core/geometry_func.hpp"
34 #include "company_base.h"
35 #include "engine_func.h"
36 #include "station_base.h"
37 #include "tilehighlight_func.h"
38 #include "zoom_func.h"
39 
40 #include "safeguards.h"
41 
42 
43 BaseVehicleListWindow::GroupBy _grouping[VLT_END][VEH_COMPANY_END];
44 Sorting _sorting[BaseVehicleListWindow::GB_END];
45 
46 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleNumberSorter;
47 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleNameSorter;
48 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleAgeSorter;
49 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleProfitThisYearSorter;
50 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleProfitLastYearSorter;
51 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleCargoSorter;
52 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleReliabilitySorter;
53 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleMaxSpeedSorter;
54 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleModelSorter;
55 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleValueSorter;
56 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleLengthSorter;
57 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleTimeToLiveSorter;
58 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleTimetableDelaySorter;
59 static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupLengthSorter;
60 static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupTotalProfitThisYearSorter;
61 static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupTotalProfitLastYearSorter;
62 static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupAverageProfitThisYearSorter;
63 static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupAverageProfitLastYearSorter;
64 
66 template <BaseVehicleListWindow::VehicleIndividualSortFunction func>
68 {
69  return func(*(a.vehicles_begin), *(b.vehicles_begin));
70 }
71 
72 BaseVehicleListWindow::VehicleGroupSortFunction * const BaseVehicleListWindow::vehicle_group_none_sorter_funcs[] = {
73  &VehicleIndividualToGroupSorterWrapper<VehicleNumberSorter>,
74  &VehicleIndividualToGroupSorterWrapper<VehicleNameSorter>,
75  &VehicleIndividualToGroupSorterWrapper<VehicleAgeSorter>,
76  &VehicleIndividualToGroupSorterWrapper<VehicleProfitThisYearSorter>,
77  &VehicleIndividualToGroupSorterWrapper<VehicleProfitLastYearSorter>,
78  &VehicleIndividualToGroupSorterWrapper<VehicleCargoSorter>,
79  &VehicleIndividualToGroupSorterWrapper<VehicleReliabilitySorter>,
80  &VehicleIndividualToGroupSorterWrapper<VehicleMaxSpeedSorter>,
81  &VehicleIndividualToGroupSorterWrapper<VehicleModelSorter>,
82  &VehicleIndividualToGroupSorterWrapper<VehicleValueSorter>,
83  &VehicleIndividualToGroupSorterWrapper<VehicleLengthSorter>,
84  &VehicleIndividualToGroupSorterWrapper<VehicleTimeToLiveSorter>,
85  &VehicleIndividualToGroupSorterWrapper<VehicleTimetableDelaySorter>,
86 };
87 
88 const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names[] = {
89  STR_SORT_BY_NUMBER,
90  STR_SORT_BY_NAME,
91  STR_SORT_BY_AGE,
92  STR_SORT_BY_PROFIT_THIS_YEAR,
93  STR_SORT_BY_PROFIT_LAST_YEAR,
94  STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE,
95  STR_SORT_BY_RELIABILITY,
96  STR_SORT_BY_MAX_SPEED,
97  STR_SORT_BY_MODEL,
98  STR_SORT_BY_VALUE,
99  STR_SORT_BY_LENGTH,
100  STR_SORT_BY_LIFE_TIME,
101  STR_SORT_BY_TIMETABLE_DELAY,
103 };
104 
105 BaseVehicleListWindow::VehicleGroupSortFunction * const BaseVehicleListWindow::vehicle_group_shared_orders_sorter_funcs[] = {
111 };
112 
113 const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names[] = {
114  STR_SORT_BY_NUM_VEHICLES,
115  STR_SORT_BY_TOTAL_PROFIT_THIS_YEAR,
116  STR_SORT_BY_TOTAL_PROFIT_LAST_YEAR,
117  STR_SORT_BY_AVERAGE_PROFIT_THIS_YEAR,
118  STR_SORT_BY_AVERAGE_PROFIT_LAST_YEAR,
120 };
121 
122 const StringID BaseVehicleListWindow::vehicle_group_by_names[] = {
123  STR_GROUP_BY_NONE,
124  STR_GROUP_BY_SHARED_ORDERS,
126 };
127 
128 const StringID BaseVehicleListWindow::vehicle_depot_name[] = {
129  STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT,
130  STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT,
131  STR_VEHICLE_LIST_SEND_SHIP_TO_DEPOT,
132  STR_VEHICLE_LIST_SEND_AIRCRAFT_TO_HANGAR
133 };
134 
135 BaseVehicleListWindow::BaseVehicleListWindow(WindowDesc *desc, WindowNumber wno) : Window(desc), vli(VehicleListIdentifier::UnPack(wno))
136 {
137  this->grouping = _grouping[vli.type][vli.vtype];
138  this->UpdateSortingFromGrouping();
139 }
140 
147 {
148  if (number >= 10000) return 5;
149  if (number >= 1000) return 4;
150  if (number >= 100) return 3;
151 
152  /*
153  * When the smallest unit number is less than 10, it is
154  * quite likely that it will expand to become more than
155  * 10 quite soon.
156  */
157  return 2;
158 }
159 
166 {
167  uint unitnumber = 0;
168  for (const Vehicle *v : vehicles) {
169  unitnumber = std::max<uint>(unitnumber, v->unitnumber);
170  }
171 
172  return CountDigitsForAllocatingSpace(unitnumber);
173 }
174 
175 void BaseVehicleListWindow::BuildVehicleList()
176 {
177  if (!this->vehgroups.NeedRebuild()) return;
178 
179  DEBUG(misc, 3, "Building vehicle list type %d for company %d given index %d", this->vli.type, this->vli.company, this->vli.index);
180 
181  this->vehgroups.clear();
182 
183  GenerateVehicleSortList(&this->vehicles, this->vli);
184 
185  if (this->grouping == GB_NONE) {
186  uint max_unitnumber = 0;
187  for (auto it = this->vehicles.begin(); it != this->vehicles.end(); ++it) {
188  this->vehgroups.emplace_back(it, it + 1);
189 
190  max_unitnumber = std::max<uint>(max_unitnumber, (*it)->unitnumber);
191  }
192  this->unitnumber_digits = CountDigitsForAllocatingSpace(max_unitnumber);
193  } else {
194  /* Sort by the primary vehicle; we just want all vehicles that share the same orders to form a contiguous range. */
195  std::stable_sort(this->vehicles.begin(), this->vehicles.end(), [](const Vehicle * const &u, const Vehicle * const &v) {
196  return u->FirstShared() < v->FirstShared();
197  });
198 
199  uint max_num_vehicles = 0;
200 
201  VehicleList::const_iterator begin = this->vehicles.begin();
202  while (begin != this->vehicles.end()) {
203  VehicleList::const_iterator end = std::find_if_not(begin, this->vehicles.cend(), [first_shared = (*begin)->FirstShared()](const Vehicle * const &v) {
204  return v->FirstShared() == first_shared;
205  });
206 
207  this->vehgroups.emplace_back(begin, end);
208 
209  max_num_vehicles = std::max<uint>(max_num_vehicles, static_cast<uint>(end - begin));
210 
211  begin = end;
212  }
213 
214  this->unitnumber_digits = CountDigitsForAllocatingSpace(max_num_vehicles);
215  }
216 
217  this->vehgroups.RebuildDone();
218  this->vscroll->SetCount(static_cast<int>(this->vehgroups.size()));
219 }
220 
227 Dimension BaseVehicleListWindow::GetActionDropdownSize(bool show_autoreplace, bool show_group)
228 {
229  Dimension d = {0, 0};
230 
231  if (show_autoreplace) d = maxdim(d, GetStringBoundingBox(STR_VEHICLE_LIST_REPLACE_VEHICLES));
232  d = maxdim(d, GetStringBoundingBox(STR_VEHICLE_LIST_SEND_FOR_SERVICING));
233  d = maxdim(d, GetStringBoundingBox(this->vehicle_depot_name[this->vli.vtype]));
234 
235  if (show_group) {
236  d = maxdim(d, GetStringBoundingBox(STR_GROUP_ADD_SHARED_VEHICLE));
237  d = maxdim(d, GetStringBoundingBox(STR_GROUP_REMOVE_ALL_VEHICLES));
238  }
239 
240  return d;
241 }
242 
244 {
245  this->order_arrow_width = GetStringBoundingBox(STR_TINY_RIGHT_ARROW).width;
246 }
247 
254 DropDownList BaseVehicleListWindow::BuildActionDropdownList(bool show_autoreplace, bool show_group)
255 {
256  DropDownList list;
257 
258  if (show_autoreplace) list.emplace_back(new DropDownListStringItem(STR_VEHICLE_LIST_REPLACE_VEHICLES, ADI_REPLACE, false));
259  list.emplace_back(new DropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, ADI_SERVICE, false));
260  list.emplace_back(new DropDownListStringItem(this->vehicle_depot_name[this->vli.vtype], ADI_DEPOT, false));
261 
262  if (show_group) {
263  list.emplace_back(new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED, false));
264  list.emplace_back(new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, ADI_REMOVE_ALL, false));
265  }
266 
267  return list;
268 }
269 
270 /* cached values for VehicleNameSorter to spare many GetString() calls */
271 static const Vehicle *_last_vehicle[2] = { nullptr, nullptr };
272 
273 void BaseVehicleListWindow::SortVehicleList()
274 {
275  if (this->vehgroups.Sort()) return;
276 
277  /* invalidate cached values for name sorter - vehicle names could change */
278  _last_vehicle[0] = _last_vehicle[1] = nullptr;
279 }
280 
281 void DepotSortList(VehicleList *list)
282 {
283  if (list->size() < 2) return;
284  std::sort(list->begin(), list->end(), &VehicleNumberSorter);
285 }
286 
288 static void DrawVehicleProfitButton(Date age, Money display_profit_last_year, uint num_vehicles, int x, int y)
289 {
290  SpriteID spr;
291 
292  /* draw profit-based coloured icons */
293  if (age <= VEHICLE_PROFIT_MIN_AGE) {
294  spr = SPR_PROFIT_NA;
295  } else if (display_profit_last_year < 0) {
296  spr = SPR_PROFIT_NEGATIVE;
297  } else if (display_profit_last_year < VEHICLE_PROFIT_THRESHOLD * num_vehicles) {
298  spr = SPR_PROFIT_SOME;
299  } else {
300  spr = SPR_PROFIT_LOT;
301  }
302  DrawSprite(spr, PAL_NONE, x, y);
303 }
304 
306 static const uint MAX_REFIT_CYCLE = 256;
307 
317 byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type)
318 {
319  v_from = v_from->GetFirstEnginePart();
320  v_for = v_for->GetFirstEnginePart();
321 
322  /* Create a list of subtypes used by the various parts of v_for */
323  static std::vector<StringID> subtypes;
324  subtypes.clear();
325  for (; v_from != nullptr; v_from = v_from->HasArticulatedPart() ? v_from->GetNextArticulatedPart() : nullptr) {
326  const Engine *e_from = v_from->GetEngine();
327  if (!e_from->CanCarryCargo() || !HasBit(e_from->info.callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) continue;
328  include(subtypes, GetCargoSubtypeText(v_from));
329  }
330 
331  byte ret_refit_cyc = 0;
332  bool success = false;
333  if (subtypes.size() > 0) {
334  /* Check whether any articulated part is refittable to 'dest_cargo_type' with a subtype listed in 'subtypes' */
335  for (Vehicle *v = v_for; v != nullptr; v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr) {
336  const Engine *e = v->GetEngine();
337  if (!e->CanCarryCargo() || !HasBit(e->info.callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) continue;
338  if (!HasBit(e->info.refit_mask, dest_cargo_type) && v->cargo_type != dest_cargo_type) continue;
339 
340  CargoID old_cargo_type = v->cargo_type;
341  byte old_cargo_subtype = v->cargo_subtype;
342 
343  /* Set the 'destination' cargo */
344  v->cargo_type = dest_cargo_type;
345 
346  /* Cycle through the refits */
347  for (uint refit_cyc = 0; refit_cyc < MAX_REFIT_CYCLE; refit_cyc++) {
348  v->cargo_subtype = refit_cyc;
349 
350  /* Make sure we don't pick up anything cached. */
351  v->First()->InvalidateNewGRFCache();
352  v->InvalidateNewGRFCache();
353 
354  StringID subtype = GetCargoSubtypeText(v);
355  if (subtype == STR_EMPTY) break;
356 
357  if (std::find(subtypes.begin(), subtypes.end(), subtype) == subtypes.end()) continue;
358 
359  /* We found something matching. */
360  ret_refit_cyc = refit_cyc;
361  success = true;
362  break;
363  }
364 
365  /* Reset the vehicle's cargo type */
366  v->cargo_type = old_cargo_type;
367  v->cargo_subtype = old_cargo_subtype;
368 
369  /* Make sure we don't taint the vehicle. */
370  v->First()->InvalidateNewGRFCache();
371  v->InvalidateNewGRFCache();
372 
373  if (success) break;
374  }
375  }
376 
377  return ret_refit_cyc;
378 }
379 
381 struct RefitOption {
383  byte subtype;
385 
391  inline bool operator != (const RefitOption &other) const
392  {
393  return other.cargo != this->cargo || other.string != this->string;
394  }
395 
401  inline bool operator == (const RefitOption &other) const
402  {
403  return other.cargo == this->cargo && other.string == this->string;
404  }
405 };
406 
407 typedef std::vector<RefitOption> SubtypeList;
408 
418 static void DrawVehicleRefitWindow(const SubtypeList list[NUM_CARGO], const int sel[2], uint pos, uint rows, uint delta, const Rect &r)
419 {
420  uint y = r.top + WD_MATRIX_TOP;
421  uint current = 0;
422 
423  bool rtl = _current_text_dir == TD_RTL;
424  uint iconwidth = std::max(GetSpriteSize(SPR_CIRCLE_FOLDED).width, GetSpriteSize(SPR_CIRCLE_UNFOLDED).width);
425  uint iconheight = GetSpriteSize(SPR_CIRCLE_FOLDED).height;
426  int linecolour = _colour_gradient[COLOUR_ORANGE][4];
427 
428  int iconleft = rtl ? r.right - WD_MATRIX_RIGHT - iconwidth : r.left + WD_MATRIX_LEFT;
429  int iconcenter = rtl ? r.right - WD_MATRIX_RIGHT - iconwidth / 2 : r.left + WD_MATRIX_LEFT + iconwidth / 2;
430  int iconinner = rtl ? r.right - WD_MATRIX_RIGHT - iconwidth : r.left + WD_MATRIX_LEFT + iconwidth;
431 
432  int textleft = r.left + WD_MATRIX_LEFT + (rtl ? 0 : iconwidth + 4);
433  int textright = r.right - WD_MATRIX_RIGHT - (rtl ? iconwidth + 4 : 0);
434 
435  /* Draw the list of subtypes for each cargo, and find the selected refit option (by its position). */
436  for (uint i = 0; current < pos + rows && i < NUM_CARGO; i++) {
437  for (uint j = 0; current < pos + rows && j < list[i].size(); j++) {
438  const RefitOption &refit = list[i][j];
439 
440  /* Hide subtypes if sel[0] does not match */
441  if (sel[0] != (int)i && refit.subtype != 0xFF) continue;
442 
443  /* Refit options with a position smaller than pos don't have to be drawn. */
444  if (current < pos) {
445  current++;
446  continue;
447  }
448 
449  if (list[i].size() > 1) {
450  if (refit.subtype != 0xFF) {
451  /* Draw tree lines */
452  int ycenter = y + FONT_HEIGHT_NORMAL / 2;
453  GfxDrawLine(iconcenter, y - WD_MATRIX_TOP, iconcenter, j == list[i].size() - 1 ? ycenter : y - WD_MATRIX_TOP + delta - 1, linecolour);
454  GfxDrawLine(iconcenter, ycenter, iconinner, ycenter, linecolour);
455  } else {
456  /* Draw expand/collapse icon */
457  DrawSprite(sel[0] == (int)i ? SPR_CIRCLE_UNFOLDED : SPR_CIRCLE_FOLDED, PAL_NONE, iconleft, y + (FONT_HEIGHT_NORMAL - iconheight) / 2);
458  }
459  }
460 
461  TextColour colour = (sel[0] == (int)i && (uint)sel[1] == j) ? TC_WHITE : TC_BLACK;
462  /* Get the cargo name. */
463  SetDParam(0, CargoSpec::Get(refit.cargo)->name);
464  SetDParam(1, refit.string);
465  DrawString(textleft, textright, y, STR_JUST_STRING_STRING, colour);
466 
467  y += delta;
468  current++;
469  }
470  }
471 }
472 
474 struct RefitWindow : public Window {
475  int sel[2];
486  int click_x;
488  uint8 num_vehicles;
489  bool auto_refit;
490 
495  {
496  for (uint i = 0; i < NUM_CARGO; i++) this->list[i].clear();
497  Vehicle *v = Vehicle::Get(this->window_number);
498 
499  /* Check only the selected vehicles. */
500  VehicleSet vehicles_to_refit;
501  GetVehicleSet(vehicles_to_refit, Vehicle::Get(this->selected_vehicle), this->num_vehicles);
502 
503  do {
504  if (v->type == VEH_TRAIN && std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), v->index) == vehicles_to_refit.end()) continue;
505  const Engine *e = v->GetEngine();
506  CargoTypes cmask = e->info.refit_mask;
507  byte callback_mask = e->info.callback_mask;
508 
509  /* Skip this engine if it does not carry anything */
510  if (!e->CanCarryCargo()) continue;
511  /* Skip this engine if we build the list for auto-refitting and engine doesn't allow it. */
512  if (this->auto_refit && !HasBit(e->info.misc_flags, EF_AUTO_REFIT)) continue;
513 
514  /* Loop through all cargoes in the refit mask */
515  int current_index = 0;
516  const CargoSpec *cs;
518  CargoID cid = cs->Index();
519  /* Skip cargo type if it's not listed */
520  if (!HasBit(cmask, cid)) {
521  current_index++;
522  continue;
523  }
524 
525  bool first_vehicle = this->list[current_index].size() == 0;
526  if (first_vehicle) {
527  /* Keeping the current subtype is always an option. It also serves as the option in case of no subtypes */
528  this->list[current_index].push_back({cid, 0xFF, STR_EMPTY});
529  }
530 
531  /* Check the vehicle's callback mask for cargo suffixes.
532  * This is not supported for ordered refits, since subtypes only have a meaning
533  * for a specific vehicle at a specific point in time, which conflicts with shared orders,
534  * autoreplace, autorenew, clone, order restoration, ... */
535  if (this->order == INVALID_VEH_ORDER_ID && HasBit(callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) {
536  /* Make a note of the original cargo type. It has to be
537  * changed to test the cargo & subtype... */
538  CargoID temp_cargo = v->cargo_type;
539  byte temp_subtype = v->cargo_subtype;
540 
541  v->cargo_type = cid;
542 
543  for (uint refit_cyc = 0; refit_cyc < MAX_REFIT_CYCLE; refit_cyc++) {
544  v->cargo_subtype = refit_cyc;
545 
546  /* Make sure we don't pick up anything cached. */
549 
550  StringID subtype = GetCargoSubtypeText(v);
551 
552  if (first_vehicle) {
553  /* Append new subtype (don't add duplicates though) */
554  if (subtype == STR_EMPTY) break;
555 
556  RefitOption option;
557  option.cargo = cid;
558  option.subtype = refit_cyc;
559  option.string = subtype;
560  include(this->list[current_index], option);
561  } else {
562  /* Intersect the subtypes of earlier vehicles with the subtypes of this vehicle */
563  if (subtype == STR_EMPTY) {
564  /* No more subtypes for this vehicle, delete all subtypes >= refit_cyc */
565  SubtypeList &l = this->list[current_index];
566  /* 0xFF item is in front, other subtypes are sorted. So just truncate the list in the right spot */
567  for (uint i = 1; i < l.size(); i++) {
568  if (l[i].subtype >= refit_cyc) {
569  l.resize(i);
570  break;
571  }
572  }
573  break;
574  } else {
575  /* Check whether the subtype matches with the subtype of earlier vehicles. */
576  uint pos = 1;
577  SubtypeList &l = this->list[current_index];
578  while (pos < l.size() && l[pos].subtype != refit_cyc) pos++;
579  if (pos < l.size() && l[pos].string != subtype) {
580  /* String mismatch, remove item keeping the order */
581  l.erase(l.begin() + pos);
582  }
583  }
584  }
585  }
586 
587  /* Reset the vehicle's cargo type */
588  v->cargo_type = temp_cargo;
589  v->cargo_subtype = temp_subtype;
590 
591  /* And make sure we haven't tainted the cache */
594  }
595  current_index++;
596  }
597  } while (v->IsGroundVehicle() && (v = v->Next()) != nullptr);
598  }
599 
604  {
605  uint scroll_row = 0;
606  uint row = 0;
607 
608  for (uint i = 0; i < NUM_CARGO; i++) {
609  for (uint j = 0; j < this->list[i].size(); j++) {
610  const RefitOption &refit = this->list[i][j];
611 
612  /* Hide subtypes if sel[0] does not match */
613  if (this->sel[0] != (int)i && refit.subtype != 0xFF) continue;
614 
615  if (this->sel[0] == (int)i && (uint)this->sel[1] == j) scroll_row = row;
616 
617  row++;
618  }
619  }
620 
621  this->vscroll->SetCount(row);
622  if (scroll_row < row) this->vscroll->ScrollTowards(scroll_row);
623  }
624 
629  void SetSelection(uint click_row)
630  {
631  uint row = 0;
632 
633  for (uint i = 0; i < NUM_CARGO; i++) {
634  for (uint j = 0; j < this->list[i].size(); j++) {
635  const RefitOption &refit = this->list[i][j];
636 
637  /* Hide subtypes if sel[0] does not match */
638  if (this->sel[0] != (int)i && refit.subtype != 0xFF) continue;
639 
640  if (row == click_row) {
641  this->sel[0] = i;
642  this->sel[1] = j;
643  return;
644  }
645 
646  row++;
647  }
648  }
649 
650  this->sel[0] = -1;
651  this->sel[1] = 0;
652  }
653 
659  {
660  if (this->sel[0] < 0) return nullptr;
661 
662  SubtypeList &l = this->list[this->sel[0]];
663  if ((uint)this->sel[1] >= l.size()) return nullptr;
664 
665  return &l[this->sel[1]];
666  }
667 
668  RefitWindow(WindowDesc *desc, const Vehicle *v, VehicleOrderID order, bool auto_refit) : Window(desc)
669  {
670  this->sel[0] = -1;
671  this->sel[1] = 0;
672  this->auto_refit = auto_refit;
673  this->order = order;
674  this->CreateNestedTree();
675 
676  this->vscroll = this->GetScrollbar(WID_VR_SCROLLBAR);
677  this->hscroll = (v->IsGroundVehicle() ? this->GetScrollbar(WID_VR_HSCROLLBAR) : nullptr);
678  this->GetWidget<NWidgetCore>(WID_VR_SELECT_HEADER)->tool_tip = STR_REFIT_TRAIN_LIST_TOOLTIP + v->type;
679  this->GetWidget<NWidgetCore>(WID_VR_MATRIX)->tool_tip = STR_REFIT_TRAIN_LIST_TOOLTIP + v->type;
680  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_VR_REFIT);
681  nwi->widget_data = STR_REFIT_TRAIN_REFIT_BUTTON + v->type;
682  nwi->tool_tip = STR_REFIT_TRAIN_REFIT_TOOLTIP + v->type;
683  this->GetWidget<NWidgetStacked>(WID_VR_SHOW_HSCROLLBAR)->SetDisplayedPlane(v->IsGroundVehicle() ? 0 : SZSP_HORIZONTAL);
684  this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY)->tool_tip = (v->type == VEH_TRAIN) ? STR_REFIT_SELECT_VEHICLES_TOOLTIP : STR_NULL;
685 
686  this->FinishInitNested(v->index);
687  this->owner = v->owner;
688 
689  this->SetWidgetDisabledState(WID_VR_REFIT, this->sel[0] < 0);
690  }
691 
692  void OnInit() override
693  {
694  if (this->cargo != nullptr) {
695  /* Store the RefitOption currently in use. */
696  RefitOption current_refit_option = *(this->cargo);
697 
698  /* Rebuild the refit list */
699  this->BuildRefitList();
700  this->sel[0] = -1;
701  this->sel[1] = 0;
702  this->cargo = nullptr;
703  for (uint i = 0; this->cargo == nullptr && i < NUM_CARGO; i++) {
704  for (uint j = 0; j < list[i].size(); j++) {
705  if (list[i][j] == current_refit_option) {
706  this->sel[0] = i;
707  this->sel[1] = j;
708  this->cargo = &list[i][j];
709  break;
710  }
711  }
712  }
713 
714  this->SetWidgetDisabledState(WID_VR_REFIT, this->sel[0] < 0);
715  this->RefreshScrollbar();
716  } else {
717  /* Rebuild the refit list */
719  }
720  }
721 
722  void OnPaint() override
723  {
724  /* Determine amount of items for scroller. */
725  if (this->hscroll != nullptr) this->hscroll->SetCount(this->vehicle_width);
726 
727  /* Calculate sprite position. */
728  NWidgetCore *vehicle_panel_display = this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY);
729  int sprite_width = std::max(0, ((int)vehicle_panel_display->current_x - this->vehicle_width) / 2);
730  this->sprite_left = vehicle_panel_display->pos_x;
731  this->sprite_right = vehicle_panel_display->pos_x + vehicle_panel_display->current_x - 1;
732  if (_current_text_dir == TD_RTL) {
733  this->sprite_right -= sprite_width;
734  this->vehicle_margin = vehicle_panel_display->current_x - sprite_right;
735  } else {
736  this->sprite_left += sprite_width;
737  this->vehicle_margin = sprite_left;
738  }
739 
740  this->DrawWidgets();
741  }
742 
743  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
744  {
745  switch (widget) {
746  case WID_VR_MATRIX:
748  size->height = resize->height * 8;
749  break;
750 
752  size->height = ScaleGUITrad(GetVehicleHeight(Vehicle::Get(this->window_number)->type));
753  break;
754 
755  case WID_VR_INFO:
756  size->width = WD_FRAMERECT_LEFT + this->information_width + WD_FRAMERECT_RIGHT;
757  break;
758  }
759  }
760 
761  void SetStringParameters(int widget) const override
762  {
763  if (widget == WID_VR_CAPTION) SetDParam(0, Vehicle::Get(this->window_number)->index);
764  }
765 
773  {
774  assert(_current_company == _local_company);
775  Vehicle *v = Vehicle::Get(this->window_number);
776  CommandCost cost = DoCommand(v->tile, this->selected_vehicle, option->cargo | option->subtype << 8 | this->num_vehicles << 16 |
777  (int)this->auto_refit << 24, DC_QUERY_COST, GetCmdRefitVeh(v->type));
778 
779  if (cost.Failed()) return INVALID_STRING_ID;
780 
781  SetDParam(0, option->cargo);
783 
784  Money money = cost.GetCost();
786  SetDParam(2, CT_MAIL);
788  if (this->order != INVALID_VEH_ORDER_ID) {
789  /* No predictable cost */
790  return STR_PURCHASE_INFO_AIRCRAFT_CAPACITY;
791  } else if (money <= 0) {
792  SetDParam(4, -money);
793  return STR_REFIT_NEW_CAPACITY_INCOME_FROM_AIRCRAFT_REFIT;
794  } else {
795  SetDParam(4, money);
796  return STR_REFIT_NEW_CAPACITY_COST_OF_AIRCRAFT_REFIT;
797  }
798  } else {
799  if (this->order != INVALID_VEH_ORDER_ID) {
800  /* No predictable cost */
801  SetDParam(2, STR_EMPTY);
802  return STR_PURCHASE_INFO_CAPACITY;
803  } else if (money <= 0) {
804  SetDParam(2, -money);
805  return STR_REFIT_NEW_CAPACITY_INCOME_FROM_REFIT;
806  } else {
807  SetDParam(2, money);
808  return STR_REFIT_NEW_CAPACITY_COST_OF_REFIT;
809  }
810  }
811  }
812 
813  void DrawWidget(const Rect &r, int widget) const override
814  {
815  switch (widget) {
817  Vehicle *v = Vehicle::Get(this->window_number);
818  DrawVehicleImage(v, this->sprite_left + WD_FRAMERECT_LEFT, this->sprite_right - WD_FRAMERECT_RIGHT,
819  r.top + WD_FRAMERECT_TOP, INVALID_VEHICLE, EIT_IN_DETAILS, this->hscroll != nullptr ? this->hscroll->GetPosition() : 0);
820 
821  /* Highlight selected vehicles. */
822  if (this->order != INVALID_VEH_ORDER_ID) break;
823  int x = 0;
824  switch (v->type) {
825  case VEH_TRAIN: {
826  VehicleSet vehicles_to_refit;
827  GetVehicleSet(vehicles_to_refit, Vehicle::Get(this->selected_vehicle), this->num_vehicles);
828 
829  int left = INT32_MIN;
830  int width = 0;
831 
832  for (Train *u = Train::From(v); u != nullptr; u = u->Next()) {
833  /* Start checking. */
834  const bool contained = std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), u->index) != vehicles_to_refit.end();
835  if (contained && left == INT32_MIN) {
836  left = x - this->hscroll->GetPosition() + r.left + this->vehicle_margin;
837  width = 0;
838  }
839 
840  /* Draw a selection. */
841  if ((!contained || u->Next() == nullptr) && left != INT32_MIN) {
842  if (u->Next() == nullptr && contained) {
843  int current_width = u->GetDisplayImageWidth();
844  width += current_width;
845  x += current_width;
846  }
847 
848  int right = Clamp(left + width, 0, r.right);
849  left = std::max(0, left);
850 
851  if (_current_text_dir == TD_RTL) {
852  right = this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY)->current_x - left;
853  left = right - width;
854  }
855 
856  if (left != right) {
857  DrawFrameRect(left, r.top + WD_FRAMERECT_TOP, right, r.top + WD_FRAMERECT_TOP + ScaleGUITrad(14) - 1, COLOUR_WHITE, FR_BORDERONLY);
858  }
859 
860  left = INT32_MIN;
861  }
862 
863  int current_width = u->GetDisplayImageWidth();
864  width += current_width;
865  x += current_width;
866  }
867  break;
868  }
869 
870  default: break;
871  }
872  break;
873  }
874 
875  case WID_VR_MATRIX:
876  DrawVehicleRefitWindow(this->list, this->sel, this->vscroll->GetPosition(), this->vscroll->GetCapacity(), this->resize.step_height, r);
877  break;
878 
879  case WID_VR_INFO:
880  if (this->cargo != nullptr) {
881  StringID string = this->GetCapacityString(this->cargo);
882  if (string != INVALID_STRING_ID) {
884  r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, string);
885  }
886  }
887  break;
888  }
889  }
890 
896  void OnInvalidateData(int data = 0, bool gui_scope = true) override
897  {
898  switch (data) {
899  case VIWD_AUTOREPLACE: // Autoreplace replaced the vehicle; selected_vehicle became invalid.
900  case VIWD_CONSIST_CHANGED: { // The consist has changed; rebuild the entire list.
901  /* Clear the selection. */
902  Vehicle *v = Vehicle::Get(this->window_number);
903  this->selected_vehicle = v->index;
904  this->num_vehicles = UINT8_MAX;
905  FALLTHROUGH;
906  }
907 
908  case 2: { // The vehicle selection has changed; rebuild the entire list.
909  if (!gui_scope) break;
910  this->BuildRefitList();
911 
912  /* The vehicle width has changed too. */
913  this->vehicle_width = GetVehicleWidth(Vehicle::Get(this->window_number), EIT_IN_DETAILS);
914  uint max_width = 0;
915 
916  /* Check the width of all cargo information strings. */
917  for (uint i = 0; i < NUM_CARGO; i++) {
918  for (uint j = 0; j < this->list[i].size(); j++) {
919  StringID string = this->GetCapacityString(&list[i][j]);
920  if (string != INVALID_STRING_ID) {
921  Dimension dim = GetStringBoundingBox(string);
922  max_width = std::max(dim.width, max_width);
923  }
924  }
925  }
926 
927  if (this->information_width < max_width) {
928  this->information_width = max_width;
929  this->ReInit();
930  }
931  FALLTHROUGH;
932  }
933 
934  case 1: // A new cargo has been selected.
935  if (!gui_scope) break;
936  this->cargo = GetRefitOption();
937  this->RefreshScrollbar();
938  break;
939  }
940  }
941 
942  int GetClickPosition(int click_x)
943  {
944  const NWidgetCore *matrix_widget = this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY);
945  if (_current_text_dir == TD_RTL) click_x = matrix_widget->current_x - click_x;
946  click_x -= this->vehicle_margin;
947  if (this->hscroll != nullptr) click_x += this->hscroll->GetPosition();
948 
949  return click_x;
950  }
951 
952  void SetSelectedVehicles(int drag_x)
953  {
954  drag_x = GetClickPosition(drag_x);
955 
956  int left_x = std::min(this->click_x, drag_x);
957  int right_x = std::max(this->click_x, drag_x);
958  this->num_vehicles = 0;
959 
960  Vehicle *v = Vehicle::Get(this->window_number);
961  /* Find the vehicle part that was clicked. */
962  switch (v->type) {
963  case VEH_TRAIN: {
964  /* Don't select anything if we are not clicking in the vehicle. */
965  if (left_x >= 0) {
966  const Train *u = Train::From(v);
967  bool start_counting = false;
968  for (; u != nullptr; u = u->Next()) {
969  int current_width = u->GetDisplayImageWidth();
970  left_x -= current_width;
971  right_x -= current_width;
972 
973  if (left_x < 0 && !start_counting) {
974  this->selected_vehicle = u->index;
975  start_counting = true;
976 
977  /* Count the first vehicle, even if articulated part */
978  this->num_vehicles++;
979  } else if (start_counting && !u->IsArticulatedPart()) {
980  /* Do not count articulated parts */
981  this->num_vehicles++;
982  }
983 
984  if (right_x < 0) break;
985  }
986  }
987 
988  /* If the selection is not correct, clear it. */
989  if (this->num_vehicles != 0) {
990  if (_ctrl_pressed) this->num_vehicles = UINT8_MAX;
991  break;
992  }
993  FALLTHROUGH;
994  }
995 
996  default:
997  /* Clear the selection. */
998  this->selected_vehicle = v->index;
999  this->num_vehicles = UINT8_MAX;
1000  break;
1001  }
1002  }
1003 
1004  void OnClick(Point pt, int widget, int click_count) override
1005  {
1006  switch (widget) {
1007  case WID_VR_VEHICLE_PANEL_DISPLAY: { // Vehicle image.
1008  if (this->order != INVALID_VEH_ORDER_ID) break;
1009  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_VR_VEHICLE_PANEL_DISPLAY);
1010  this->click_x = GetClickPosition(pt.x - nwi->pos_x);
1011  this->SetSelectedVehicles(pt.x - nwi->pos_x);
1013  if (!_ctrl_pressed) {
1014  SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1015  } else {
1016  /* The vehicle selection has changed. */
1017  this->InvalidateData(2);
1018  }
1019  break;
1020  }
1021 
1022  case WID_VR_MATRIX: { // listbox
1023  this->SetSelection(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_VR_MATRIX));
1024  this->SetWidgetDisabledState(WID_VR_REFIT, this->sel[0] < 0);
1025  this->InvalidateData(1);
1026 
1027  if (click_count == 1) break;
1028  FALLTHROUGH;
1029  }
1030 
1031  case WID_VR_REFIT: // refit button
1032  if (this->cargo != nullptr) {
1033  const Vehicle *v = Vehicle::Get(this->window_number);
1034 
1035  if (this->order == INVALID_VEH_ORDER_ID) {
1036  bool delete_window = this->selected_vehicle == v->index && this->num_vehicles == UINT8_MAX;
1037  if (DoCommandP(v->tile, this->selected_vehicle, this->cargo->cargo | this->cargo->subtype << 8 | this->num_vehicles << 16, GetCmdRefitVeh(v)) && delete_window) delete this;
1038  } else {
1039  if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->order << 16, CMD_ORDER_REFIT)) delete this;
1040  }
1041  }
1042  break;
1043  }
1044  }
1045 
1046  void OnMouseDrag(Point pt, int widget) override
1047  {
1048  switch (widget) {
1049  case WID_VR_VEHICLE_PANEL_DISPLAY: { // Vehicle image.
1050  if (this->order != INVALID_VEH_ORDER_ID) break;
1051  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_VR_VEHICLE_PANEL_DISPLAY);
1052  this->SetSelectedVehicles(pt.x - nwi->pos_x);
1054  break;
1055  }
1056  }
1057  }
1058 
1059  void OnDragDrop(Point pt, int widget) override
1060  {
1061  switch (widget) {
1062  case WID_VR_VEHICLE_PANEL_DISPLAY: { // Vehicle image.
1063  if (this->order != INVALID_VEH_ORDER_ID) break;
1064  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_VR_VEHICLE_PANEL_DISPLAY);
1065  this->SetSelectedVehicles(pt.x - nwi->pos_x);
1066  this->InvalidateData(2);
1067  break;
1068  }
1069  }
1070  }
1071 
1072  void OnResize() override
1073  {
1074  this->vehicle_width = GetVehicleWidth(Vehicle::Get(this->window_number), EIT_IN_DETAILS);
1075  this->vscroll->SetCapacityFromWidget(this, WID_VR_MATRIX);
1076  if (this->hscroll != nullptr) this->hscroll->SetCapacityFromWidget(this, WID_VR_VEHICLE_PANEL_DISPLAY);
1077  }
1078 };
1079 
1080 static const NWidgetPart _nested_vehicle_refit_widgets[] = {
1082  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1083  NWidget(WWT_CAPTION, COLOUR_GREY, WID_VR_CAPTION), SetDataTip(STR_REFIT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1084  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1085  EndContainer(),
1086  /* Vehicle display + scrollbar. */
1089  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VR_SHOW_HSCROLLBAR),
1090  NWidget(NWID_HSCROLLBAR, COLOUR_GREY, WID_VR_HSCROLLBAR),
1091  EndContainer(),
1092  EndContainer(),
1093  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_VR_SELECT_HEADER), SetDataTip(STR_REFIT_TITLE, STR_NULL), SetResize(1, 0),
1094  /* Matrix + scrollbar. */
1096  NWidget(WWT_MATRIX, COLOUR_GREY, WID_VR_MATRIX), SetMinimalSize(228, 112), SetResize(1, 14), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_VR_SCROLLBAR),
1097  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_VR_SCROLLBAR),
1098  EndContainer(),
1101  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VR_REFIT), SetFill(1, 0), SetResize(1, 0),
1102  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1103  EndContainer(),
1104 };
1105 
1106 static WindowDesc _vehicle_refit_desc(
1107  WDP_AUTO, "view_vehicle_refit", 240, 174,
1110  _nested_vehicle_refit_widgets, lengthof(_nested_vehicle_refit_widgets)
1111 );
1112 
1120 void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
1121 {
1123  RefitWindow *w = new RefitWindow(&_vehicle_refit_desc, v, order, auto_refit);
1124  w->parent = parent;
1125 }
1126 
1128 uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
1129 {
1130  /* List of cargo types of this engine */
1131  CargoTypes cmask = GetUnionOfArticulatedRefitMasks(engine, false);
1132  /* List of cargo types available in this climate */
1133  CargoTypes lmask = _cargo_mask;
1134 
1135  /* Draw nothing if the engine is not refittable */
1136  if (HasAtMostOneBit(cmask)) return y;
1137 
1138  if (cmask == lmask) {
1139  /* Engine can be refitted to all types in this climate */
1140  SetDParam(0, STR_PURCHASE_INFO_ALL_TYPES);
1141  } else {
1142  /* Check if we are able to refit to more cargo types and unable to. If
1143  * so, invert the cargo types to list those that we can't refit to. */
1144  if (CountBits(cmask ^ lmask) < CountBits(cmask) && CountBits(cmask ^ lmask) <= 7) {
1145  cmask ^= lmask;
1146  SetDParam(0, STR_PURCHASE_INFO_ALL_BUT);
1147  } else {
1148  SetDParam(0, STR_JUST_CARGO_LIST);
1149  }
1150  SetDParam(1, cmask);
1151  }
1152 
1153  return DrawStringMultiLine(left, right, y, INT32_MAX, STR_PURCHASE_INFO_REFITTABLE_TO);
1154 }
1155 
1158 {
1159  if (HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) {
1160  uint16 cb = GetVehicleCallback(CBID_VEHICLE_CARGO_SUFFIX, 0, 0, v->engine_type, v);
1161  if (cb != CALLBACK_FAILED) {
1163  if (cb >= 0x400 || (v->GetGRF()->grf_version < 8 && cb == 0xFF)) cb = CALLBACK_FAILED;
1164  }
1165  if (cb != CALLBACK_FAILED) {
1166  return GetGRFStringID(v->GetGRFID(), 0xD000 + cb);
1167  }
1168  }
1169  return STR_EMPTY;
1170 }
1171 
1174 {
1175  return a.NumVehicles() < b.NumVehicles();
1176 }
1177 
1180 {
1181  return a.GetDisplayProfitThisYear() < b.GetDisplayProfitThisYear();
1182 }
1183 
1186 {
1187  return a.GetDisplayProfitLastYear() < b.GetDisplayProfitLastYear();
1188 }
1189 
1192 {
1193  return a.GetDisplayProfitThisYear() * static_cast<uint>(b.NumVehicles()) < b.GetDisplayProfitThisYear() * static_cast<uint>(a.NumVehicles());
1194 }
1195 
1198 {
1199  return a.GetDisplayProfitLastYear() * static_cast<uint>(b.NumVehicles()) < b.GetDisplayProfitLastYear() * static_cast<uint>(a.NumVehicles());
1200 }
1201 
1203 static bool VehicleNumberSorter(const Vehicle * const &a, const Vehicle * const &b)
1204 {
1205  return a->unitnumber < b->unitnumber;
1206 }
1207 
1209 static bool VehicleNameSorter(const Vehicle * const &a, const Vehicle * const &b)
1210 {
1211  static char last_name[2][64];
1212 
1213  if (a != _last_vehicle[0]) {
1214  _last_vehicle[0] = a;
1215  SetDParam(0, a->index);
1216  GetString(last_name[0], STR_VEHICLE_NAME, lastof(last_name[0]));
1217  }
1218 
1219  if (b != _last_vehicle[1]) {
1220  _last_vehicle[1] = b;
1221  SetDParam(0, b->index);
1222  GetString(last_name[1], STR_VEHICLE_NAME, lastof(last_name[1]));
1223  }
1224 
1225  int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
1226  return (r != 0) ? r < 0: VehicleNumberSorter(a, b);
1227 }
1228 
1230 static bool VehicleAgeSorter(const Vehicle * const &a, const Vehicle * const &b)
1231 {
1232  int r = a->age - b->age;
1233  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1234 }
1235 
1237 static bool VehicleProfitThisYearSorter(const Vehicle * const &a, const Vehicle * const &b)
1238 {
1240  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1241 }
1242 
1244 static bool VehicleProfitLastYearSorter(const Vehicle * const &a, const Vehicle * const &b)
1245 {
1247  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1248 }
1249 
1251 static bool VehicleCargoSorter(const Vehicle * const &a, const Vehicle * const &b)
1252 {
1253  const Vehicle *v;
1254  CargoArray diff;
1255 
1256  /* Append the cargo of the connected waggons */
1257  for (v = a; v != nullptr; v = v->Next()) diff[v->cargo_type] += v->cargo_cap;
1258  for (v = b; v != nullptr; v = v->Next()) diff[v->cargo_type] -= v->cargo_cap;
1259 
1260  int r = 0;
1261  for (CargoID i = 0; i < NUM_CARGO; i++) {
1262  r = diff[i];
1263  if (r != 0) break;
1264  }
1265 
1266  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1267 }
1268 
1270 static bool VehicleReliabilitySorter(const Vehicle * const &a, const Vehicle * const &b)
1271 {
1272  int r = a->reliability - b->reliability;
1273  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1274 }
1275 
1277 static bool VehicleMaxSpeedSorter(const Vehicle * const &a, const Vehicle * const &b)
1278 {
1280  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1281 }
1282 
1284 static bool VehicleModelSorter(const Vehicle * const &a, const Vehicle * const &b)
1285 {
1286  int r = a->engine_type - b->engine_type;
1287  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1288 }
1289 
1291 static bool VehicleValueSorter(const Vehicle * const &a, const Vehicle * const &b)
1292 {
1293  const Vehicle *u;
1294  Money diff = 0;
1295 
1296  for (u = a; u != nullptr; u = u->Next()) diff += u->value;
1297  for (u = b; u != nullptr; u = u->Next()) diff -= u->value;
1298 
1299  int r = ClampToI32(diff);
1300  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1301 }
1302 
1304 static bool VehicleLengthSorter(const Vehicle * const &a, const Vehicle * const &b)
1305 {
1307  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1308 }
1309 
1311 static bool VehicleTimeToLiveSorter(const Vehicle * const &a, const Vehicle * const &b)
1312 {
1313  int r = ClampToI32((a->max_age - a->age) - (b->max_age - b->age));
1314  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1315 }
1316 
1318 static bool VehicleTimetableDelaySorter(const Vehicle * const &a, const Vehicle * const &b)
1319 {
1320  int r = a->lateness_counter - b->lateness_counter;
1321  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1322 }
1323 
1324 void InitializeGUI()
1325 {
1326  MemSetT(&_grouping, 0);
1327  MemSetT(&_sorting, 0);
1328 }
1329 
1336 static inline void ChangeVehicleWindow(WindowClass window_class, VehicleID from_index, VehicleID to_index)
1337 {
1338  Window *w = FindWindowById(window_class, from_index);
1339  if (w != nullptr) {
1340  /* Update window_number */
1341  w->window_number = to_index;
1342  if (w->viewport != nullptr) w->viewport->follow_vehicle = to_index;
1343 
1344  /* Update vehicle drag data */
1345  if (_thd.window_class == window_class && _thd.window_number == (WindowNumber)from_index) {
1346  _thd.window_number = to_index;
1347  }
1348 
1349  /* Notify the window. */
1350  w->InvalidateData(VIWD_AUTOREPLACE, false);
1351  }
1352 }
1353 
1359 void ChangeVehicleViewWindow(VehicleID from_index, VehicleID to_index)
1360 {
1361  ChangeVehicleWindow(WC_VEHICLE_VIEW, from_index, to_index);
1362  ChangeVehicleWindow(WC_VEHICLE_ORDERS, from_index, to_index);
1363  ChangeVehicleWindow(WC_VEHICLE_REFIT, from_index, to_index);
1364  ChangeVehicleWindow(WC_VEHICLE_DETAILS, from_index, to_index);
1365  ChangeVehicleWindow(WC_VEHICLE_TIMETABLE, from_index, to_index);
1366 }
1367 
1368 static const NWidgetPart _nested_vehicle_list[] = {
1370  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1371  NWidget(WWT_CAPTION, COLOUR_GREY, WID_VL_CAPTION),
1372  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1373  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1374  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1375  EndContainer(),
1376 
1378  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_VL_GROUP_ORDER), SetMinimalSize(81, 12), SetFill(0, 1), SetDataTip(STR_STATION_VIEW_GROUP, STR_TOOLTIP_GROUP_ORDER),
1379  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_VL_GROUP_BY_PULLDOWN), SetMinimalSize(167, 12), SetFill(0, 1), SetDataTip(0x0, STR_TOOLTIP_GROUP_ORDER),
1380  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(12, 12), SetFill(1, 1), SetResize(1, 0), EndContainer(),
1381  EndContainer(),
1382 
1384  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VL_SORT_ORDER), SetMinimalSize(81, 12), SetFill(0, 1), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
1385  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_VL_SORT_BY_PULLDOWN), SetMinimalSize(167, 12), SetFill(0, 1), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
1386  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(12, 12), SetFill(1, 1), SetResize(1, 0), EndContainer(),
1387  EndContainer(),
1388 
1390  NWidget(WWT_MATRIX, COLOUR_GREY, WID_VL_LIST), SetMinimalSize(248, 0), SetFill(1, 0), SetResize(1, 1), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_VL_SCROLLBAR),
1391  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_VL_SCROLLBAR),
1392  EndContainer(),
1393 
1395  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VL_HIDE_BUTTONS),
1397  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VL_AVAILABLE_VEHICLES), SetMinimalSize(106, 12), SetFill(0, 1),
1398  SetDataTip(STR_BLACK_STRING, STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP),
1399  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetResize(1, 0), SetFill(1, 1), EndContainer(),
1401  SetDataTip(STR_VEHICLE_LIST_MANAGE_LIST, STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP),
1402  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VL_STOP_ALL), SetMinimalSize(12, 12), SetFill(0, 1),
1403  SetDataTip(SPR_FLAG_VEH_STOPPED, STR_VEHICLE_LIST_MASS_STOP_LIST_TOOLTIP),
1404  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VL_START_ALL), SetMinimalSize(12, 12), SetFill(0, 1),
1405  SetDataTip(SPR_FLAG_VEH_RUNNING, STR_VEHICLE_LIST_MASS_START_LIST_TOOLTIP),
1406  EndContainer(),
1407  /* Widget to be shown for other companies hiding the previous 5 widgets. */
1408  NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 0), EndContainer(),
1409  EndContainer(),
1410  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1411  EndContainer(),
1412 };
1413 
1414 static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, uint order_arrow_width, VehicleOrderID start)
1415 {
1416  const Order *order = v->GetOrder(start);
1417  if (order == nullptr) return;
1418 
1419  bool rtl = _current_text_dir == TD_RTL;
1420  int l_offset = rtl ? 0 : order_arrow_width;
1421  int r_offset = rtl ? order_arrow_width : 0;
1422  int i = 0;
1423  VehicleOrderID oid = start;
1424 
1425  do {
1426  if (oid == v->cur_real_order_index) DrawString(left, right, y, STR_TINY_RIGHT_ARROW, TC_BLACK);
1427 
1428  if (order->IsType(OT_GOTO_STATION)) {
1429  SetDParam(0, order->GetDestination());
1430  DrawString(left + l_offset, right - r_offset, y, STR_TINY_BLACK_STATION);
1431 
1432  y += FONT_HEIGHT_SMALL;
1433  if (++i == 4) break;
1434  }
1435 
1436  oid++;
1437  order = order->next;
1438  if (order == nullptr) {
1439  order = v->orders.list->GetFirstOrder();
1440  oid = 0;
1441  }
1442  } while (oid != start);
1443 }
1444 
1446 static void DrawSmallOrderList(const Order *order, int left, int right, int y, uint order_arrow_width)
1447 {
1448  bool rtl = _current_text_dir == TD_RTL;
1449  int l_offset = rtl ? 0 : order_arrow_width;
1450  int r_offset = rtl ? order_arrow_width : 0;
1451  int i = 0;
1452  while (order != nullptr) {
1453  if (order->IsType(OT_GOTO_STATION)) {
1454  SetDParam(0, order->GetDestination());
1455  DrawString(left + l_offset, right - r_offset, y, STR_TINY_BLACK_STATION);
1456 
1457  y += FONT_HEIGHT_SMALL;
1458  if (++i == 4) break;
1459  }
1460  order = order->next;
1461  }
1462 }
1463 
1473 void DrawVehicleImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip)
1474 {
1475  switch (v->type) {
1476  case VEH_TRAIN: DrawTrainImage(Train::From(v), left, right, y, selection, image_type, skip); break;
1477  case VEH_ROAD: DrawRoadVehImage(v, left, right, y, selection, image_type, skip); break;
1478  case VEH_SHIP: DrawShipImage(v, left, right, y, selection, image_type); break;
1479  case VEH_AIRCRAFT: DrawAircraftImage(v, left, right, y, selection, image_type); break;
1480  default: NOT_REACHED();
1481  }
1482 }
1483 
1490 uint GetVehicleListHeight(VehicleType type, uint divisor)
1491 {
1492  /* Name + vehicle + profit */
1493  uint base = ScaleGUITrad(GetVehicleHeight(type)) + 2 * FONT_HEIGHT_SMALL;
1494  /* Drawing of the 4 small orders + profit*/
1495  if (type >= VEH_SHIP) base = std::max(base, 5U * FONT_HEIGHT_SMALL);
1496 
1497  if (divisor == 1) return base;
1498 
1499  /* Make sure the height is dividable by divisor */
1500  uint rem = base % divisor;
1501  return base + (rem == 0 ? 0 : divisor - rem);
1502 }
1503 
1510 void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const
1511 {
1512  int left = r.left + WD_MATRIX_LEFT;
1513  int right = r.right - WD_MATRIX_RIGHT;
1514  int width = right - left;
1515  bool rtl = _current_text_dir == TD_RTL;
1516 
1517  int text_offset = std::max<int>(GetSpriteSize(SPR_PROFIT_LOT).width, GetDigitWidth() * this->unitnumber_digits) + WD_FRAMERECT_RIGHT;
1518  int text_left = left + (rtl ? 0 : text_offset);
1519  int text_right = right - (rtl ? text_offset : 0);
1520 
1521  bool show_orderlist = this->vli.vtype >= VEH_SHIP;
1522  int orderlist_left = left + (rtl ? 0 : std::max(ScaleGUITrad(100) + text_offset, width / 2));
1523  int orderlist_right = right - (rtl ? std::max(ScaleGUITrad(100) + text_offset, width / 2) : 0);
1524 
1525  int image_left = (rtl && show_orderlist) ? orderlist_right : text_left;
1526  int image_right = (!rtl && show_orderlist) ? orderlist_left : text_right;
1527 
1528  int vehicle_button_x = rtl ? right - GetSpriteSize(SPR_PROFIT_LOT).width : left;
1529 
1530  int y = r.top;
1531  uint max = static_cast<uint>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehgroups.size()));
1532  for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
1533 
1534  const GUIVehicleGroup &vehgroup = this->vehgroups[i];
1535 
1536  SetDParam(0, vehgroup.GetDisplayProfitThisYear());
1537  SetDParam(1, vehgroup.GetDisplayProfitLastYear());
1538  DrawString(text_left, text_right, y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1, STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR);
1539 
1540  DrawVehicleProfitButton(vehgroup.GetOldestVehicleAge(), vehgroup.GetDisplayProfitLastYear(), vehgroup.NumVehicles(), vehicle_button_x, y + FONT_HEIGHT_NORMAL + 3);
1541 
1542  switch (this->grouping) {
1543  case GB_NONE: {
1544  const Vehicle *v = vehgroup.GetSingleVehicle();
1545 
1546  DrawVehicleImage(v, image_left, image_right, y + FONT_HEIGHT_SMALL - 1, selected_vehicle, EIT_IN_LIST, 0);
1547 
1548  if (!v->name.empty()) {
1549  /* The vehicle got a name so we will print it */
1550  SetDParam(0, v->index);
1551  DrawString(text_left, text_right, y, STR_TINY_BLACK_VEHICLE);
1552  } else if (v->group_id != DEFAULT_GROUP) {
1553  /* The vehicle has no name, but is member of a group, so print group name */
1554  SetDParam(0, v->group_id);
1555  DrawString(text_left, text_right, y, STR_TINY_GROUP, TC_BLACK);
1556  }
1557 
1558  if (show_orderlist) DrawSmallOrderList(v, orderlist_left, orderlist_right, y, this->order_arrow_width, v->cur_real_order_index);
1559 
1560  StringID str;
1561  if (v->IsChainInDepot()) {
1562  str = STR_BLUE_COMMA;
1563  } else {
1564  str = (v->age > v->max_age - DAYS_IN_LEAP_YEAR) ? STR_RED_COMMA : STR_BLACK_COMMA;
1565  }
1566 
1567  SetDParam(0, v->unitnumber);
1568  DrawString(left, right, y + 2, str);
1569  break;
1570  }
1571 
1572  case GB_SHARED_ORDERS:
1573  assert(vehgroup.NumVehicles() > 0);
1574 
1575  for (int i = 0; i < static_cast<int>(vehgroup.NumVehicles()); ++i) {
1576  if (image_left + 8 * i >= image_right) break; // Break if there is no more space to draw any more vehicles anyway.
1577  DrawVehicleImage(vehgroup.vehicles_begin[i], image_left + 8 * i, image_right, y + FONT_HEIGHT_SMALL - 1, selected_vehicle, EIT_IN_LIST, 0);
1578  }
1579 
1580  if (show_orderlist) DrawSmallOrderList((vehgroup.vehicles_begin[0])->GetFirstOrder(), orderlist_left, orderlist_right, y, this->order_arrow_width);
1581 
1582  SetDParam(0, vehgroup.NumVehicles());
1583  DrawString(left, right, y + 2, STR_BLACK_COMMA);
1584  break;
1585 
1586  default:
1587  NOT_REACHED();
1588  }
1589 
1590  y += line_height;
1591  }
1592 }
1593 
1594 void BaseVehicleListWindow::UpdateSortingFromGrouping()
1595 {
1596  /* Set up sorting. Make the window-specific _sorting variable
1597  * point to the correct global _sorting struct so we are freed
1598  * from having conditionals during window operation */
1599  switch (this->vli.vtype) {
1600  case VEH_TRAIN: this->sorting = &_sorting[this->grouping].train; break;
1601  case VEH_ROAD: this->sorting = &_sorting[this->grouping].roadveh; break;
1602  case VEH_SHIP: this->sorting = &_sorting[this->grouping].ship; break;
1603  case VEH_AIRCRAFT: this->sorting = &_sorting[this->grouping].aircraft; break;
1604  default: NOT_REACHED();
1605  }
1606  this->vehgroups.SetSortFuncs(this->GetVehicleSorterFuncs());
1607  this->vehgroups.SetListing(*this->sorting);
1608  this->vehgroups.ForceRebuild();
1609  this->vehgroups.NeedResort();
1610 }
1611 
1612 void BaseVehicleListWindow::UpdateVehicleGroupBy(GroupBy group_by)
1613 {
1614  if (this->grouping != group_by) {
1615  /* Save the old sorting option, so that if we change the grouping option back later on,
1616  * UpdateSortingFromGrouping() will automatically restore the saved sorting option. */
1617  *this->sorting = this->vehgroups.GetListing();
1618 
1619  this->grouping = group_by;
1620  _grouping[this->vli.type][this->vli.vtype] = group_by;
1621  this->UpdateSortingFromGrouping();
1622  }
1623 }
1624 
1635 private:
1640  };
1641 
1642 public:
1644  {
1645  this->CreateNestedTree();
1646 
1647  this->vscroll = this->GetScrollbar(WID_VL_SCROLLBAR);
1648 
1649  this->BuildVehicleList();
1650  this->SortVehicleList();
1651 
1652  /* Set up the window widgets */
1653  this->GetWidget<NWidgetCore>(WID_VL_LIST)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype;
1654 
1655  if (this->vli.type == VL_SHARED_ORDERS) {
1656  this->GetWidget<NWidgetCore>(WID_VL_CAPTION)->widget_data = STR_VEHICLE_LIST_SHARED_ORDERS_LIST_CAPTION;
1657  /* If we are in the shared orders window, then disable the group-by dropdown menu.
1658  * Remove this when the group-by dropdown menu has another option apart from grouping by shared orders. */
1661  } else {
1662  this->GetWidget<NWidgetCore>(WID_VL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype;
1663  }
1664 
1665  this->FinishInitNested(window_number);
1666  if (this->vli.company != OWNER_NONE) this->owner = this->vli.company;
1667  }
1668 
1670  {
1671  *this->sorting = this->vehgroups.GetListing();
1672  }
1673 
1674  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1675  {
1676  switch (widget) {
1677  case WID_VL_LIST:
1678  resize->height = GetVehicleListHeight(this->vli.vtype, 1);
1679 
1680  switch (this->vli.vtype) {
1681  case VEH_TRAIN:
1682  case VEH_ROAD:
1683  size->height = 6 * resize->height;
1684  break;
1685  case VEH_SHIP:
1686  case VEH_AIRCRAFT:
1687  size->height = 4 * resize->height;
1688  break;
1689  default: NOT_REACHED();
1690  }
1691  break;
1692 
1693  case WID_VL_SORT_ORDER: {
1694  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
1695  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
1696  d.height += padding.height;
1697  *size = maxdim(*size, d);
1698  break;
1699  }
1700 
1702  Dimension d = this->GetActionDropdownSize(this->vli.type == VL_STANDARD, false);
1703  d.height += padding.height;
1704  d.width += padding.width;
1705  *size = maxdim(*size, d);
1706  break;
1707  }
1708  }
1709  }
1710 
1711  void SetStringParameters(int widget) const override
1712  {
1713  switch (widget) {
1715  SetDParam(0, STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vli.vtype);
1716  break;
1717 
1718  case WID_VL_CAPTION: {
1719  switch (this->vli.type) {
1720  case VL_SHARED_ORDERS: // Shared Orders
1721  if (this->vehicles.size() == 0) {
1722  /* We can't open this window without vehicles using this order
1723  * and we should close the window when deleting the order. */
1724  NOT_REACHED();
1725  }
1726  SetDParam(0, this->vehicles.size());
1727  break;
1728 
1729  case VL_STANDARD: // Company Name
1730  SetDParam(0, STR_COMPANY_NAME);
1731  SetDParam(1, this->vli.index);
1732  SetDParam(3, this->vehicles.size());
1733  break;
1734 
1735  case VL_STATION_LIST: // Station/Waypoint Name
1736  SetDParam(0, Station::IsExpected(BaseStation::Get(this->vli.index)) ? STR_STATION_NAME : STR_WAYPOINT_NAME);
1737  SetDParam(1, this->vli.index);
1738  SetDParam(3, this->vehicles.size());
1739  break;
1740 
1741  case VL_DEPOT_LIST:
1742  SetDParam(0, STR_DEPOT_CAPTION);
1743  SetDParam(1, this->vli.vtype);
1744  SetDParam(2, this->vli.index);
1745  SetDParam(3, this->vehicles.size());
1746  break;
1747  default: NOT_REACHED();
1748  }
1749  break;
1750  }
1751  }
1752  }
1753 
1754  void DrawWidget(const Rect &r, int widget) const override
1755  {
1756  switch (widget) {
1757  case WID_VL_SORT_ORDER:
1758  /* draw arrow pointing up/down for ascending/descending sorting */
1759  this->DrawSortButtonState(widget, this->vehgroups.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
1760  break;
1761 
1762  case WID_VL_LIST:
1764  break;
1765  }
1766  }
1767 
1768  void OnPaint() override
1769  {
1770  this->BuildVehicleList();
1771  this->SortVehicleList();
1772 
1773  if (this->vehicles.size() == 0 && this->IsWidgetLowered(WID_VL_MANAGE_VEHICLES_DROPDOWN)) {
1774  HideDropDownMenu(this);
1775  }
1776 
1777  /* Hide the widgets that we will not use in this window
1778  * Some windows contains actions only fit for the owner */
1779  int plane_to_show = (this->owner == _local_company) ? BP_SHOW_BUTTONS : BP_HIDE_BUTTONS;
1780  NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(WID_VL_HIDE_BUTTONS);
1781  if (plane_to_show != nwi->shown_plane) {
1782  nwi->SetDisplayedPlane(plane_to_show);
1783  nwi->SetDirty(this);
1784  }
1785  if (this->owner == _local_company) {
1786  this->SetWidgetDisabledState(WID_VL_AVAILABLE_VEHICLES, this->vli.type != VL_STANDARD);
1787  this->SetWidgetsDisabledState(this->vehicles.size() == 0,
1791  WIDGET_LIST_END);
1792  }
1793 
1794  /* Set text of group by dropdown widget. */
1795  this->GetWidget<NWidgetCore>(WID_VL_GROUP_BY_PULLDOWN)->widget_data = this->vehicle_group_by_names[this->grouping];
1796 
1797  /* Set text of sort by dropdown widget. */
1798  this->GetWidget<NWidgetCore>(WID_VL_SORT_BY_PULLDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()];
1799 
1800  this->DrawWidgets();
1801  }
1802 
1803  void OnClick(Point pt, int widget, int click_count) override
1804  {
1805  switch (widget) {
1806  case WID_VL_SORT_ORDER: // Flip sorting method ascending/descending
1807  this->vehgroups.ToggleSortOrder();
1808  this->SetDirty();
1809  break;
1810 
1811  case WID_VL_GROUP_BY_PULLDOWN: // Select sorting criteria dropdown menu
1812  ShowDropDownMenu(this, this->vehicle_group_by_names, this->grouping, WID_VL_GROUP_BY_PULLDOWN, 0, 0);
1813  return;
1814 
1815  case WID_VL_SORT_BY_PULLDOWN: // Select sorting criteria dropdown menu
1816  ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_VL_SORT_BY_PULLDOWN, 0,
1817  (this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10));
1818  return;
1819 
1820  case WID_VL_LIST: { // Matrix to show vehicles
1821  uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_VL_LIST);
1822  if (id_v >= this->vehgroups.size()) return; // click out of list bound
1823 
1824  const GUIVehicleGroup &vehgroup = this->vehgroups[id_v];
1825  switch (this->grouping) {
1826  case GB_NONE: {
1827  const Vehicle *v = vehgroup.GetSingleVehicle();
1828  if (!VehicleClicked(v)) {
1829  if (_ctrl_pressed) {
1831  } else {
1833  }
1834  }
1835  break;
1836  }
1837 
1838  case GB_SHARED_ORDERS: {
1839  assert(vehgroup.NumVehicles() > 0);
1840  const Vehicle *v = vehgroup.vehicles_begin[0];
1841  /* We do not support VehicleClicked() here since the contextual action may only make sense for individual vehicles */
1842 
1843  if (vehgroup.NumVehicles() == 1) {
1845  } else {
1846  ShowVehicleListWindow(v);
1847  }
1848  break;
1849  }
1850 
1851  default: NOT_REACHED();
1852  }
1853 
1854  break;
1855  }
1856 
1858  ShowBuildVehicleWindow(INVALID_TILE, this->vli.vtype);
1859  break;
1860 
1862  ShowDropDownList(this, this->BuildActionDropdownList(VehicleListIdentifier::UnPack(this->window_number).type == VL_STANDARD, false), 0, WID_VL_MANAGE_VEHICLES_DROPDOWN);
1863  break;
1864  }
1865 
1866  case WID_VL_STOP_ALL:
1867  case WID_VL_START_ALL:
1868  DoCommandP(0, (1 << 1) | (widget == WID_VL_START_ALL ? (1 << 0) : 0), this->window_number, CMD_MASS_START_STOP);
1869  break;
1870  }
1871  }
1872 
1873  void OnDropdownSelect(int widget, int index) override
1874  {
1875  switch (widget) {
1877  this->UpdateVehicleGroupBy(static_cast<GroupBy>(index));
1878  break;
1879 
1881  this->vehgroups.SetSortType(index);
1882  break;
1883 
1885  assert(this->vehicles.size() != 0);
1886 
1887  switch (index) {
1888  case ADI_REPLACE: // Replace window
1890  break;
1891  case ADI_SERVICE: // Send for servicing
1892  case ADI_DEPOT: // Send to Depots
1893  DoCommandP(0, DEPOT_MASS_SEND | (index == ADI_SERVICE ? DEPOT_SERVICE : (DepotCommand)0), this->window_number, GetCmdSendToDepot(this->vli.vtype));
1894  break;
1895 
1896  default: NOT_REACHED();
1897  }
1898  break;
1899 
1900  default: NOT_REACHED();
1901  }
1902  this->SetDirty();
1903  }
1904 
1905  void OnGameTick() override
1906  {
1907  if (this->vehgroups.NeedResort()) {
1908  StationID station = (this->vli.type == VL_STATION_LIST) ? this->vli.index : INVALID_STATION;
1909 
1910  DEBUG(misc, 3, "Periodic resort %d list company %d at station %d", this->vli.vtype, this->owner, station);
1911  this->SetDirty();
1912  }
1913  }
1914 
1915  void OnResize() override
1916  {
1917  this->vscroll->SetCapacityFromWidget(this, WID_VL_LIST);
1918  }
1919 
1925  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1926  {
1927  if (!gui_scope && HasBit(data, 31) && this->vli.type == VL_SHARED_ORDERS) {
1928  /* Needs to be done in command-scope, so everything stays valid */
1929  this->vli.index = GB(data, 0, 20);
1930  this->window_number = this->vli.Pack();
1931  this->vehgroups.ForceRebuild();
1932  return;
1933  }
1934 
1935  if (data == 0) {
1936  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
1937  this->vehgroups.ForceRebuild();
1938  } else {
1939  this->vehgroups.ForceResort();
1940  }
1941  }
1942 };
1943 
1944 static WindowDesc _vehicle_list_other_desc(
1945  WDP_AUTO, "list_vehicles", 260, 246,
1947  0,
1948  _nested_vehicle_list, lengthof(_nested_vehicle_list)
1949 );
1950 
1951 static WindowDesc _vehicle_list_train_desc(
1952  WDP_AUTO, "list_vehicles_train", 325, 246,
1954  0,
1955  _nested_vehicle_list, lengthof(_nested_vehicle_list)
1956 );
1957 
1958 static void ShowVehicleListWindowLocal(CompanyID company, VehicleListType vlt, VehicleType vehicle_type, uint32 unique_number)
1959 {
1960  if (!Company::IsValidID(company) && company != OWNER_NONE) return;
1961 
1962  WindowNumber num = VehicleListIdentifier(vlt, vehicle_type, company, unique_number).Pack();
1963  if (vehicle_type == VEH_TRAIN) {
1964  AllocateWindowDescFront<VehicleListWindow>(&_vehicle_list_train_desc, num);
1965  } else {
1966  _vehicle_list_other_desc.cls = GetWindowClassForVehicleType(vehicle_type);
1967  AllocateWindowDescFront<VehicleListWindow>(&_vehicle_list_other_desc, num);
1968  }
1969 }
1970 
1971 void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type)
1972 {
1973  /* If _settings_client.gui.advanced_vehicle_list > 1, display the Advanced list
1974  * if _settings_client.gui.advanced_vehicle_list == 1, display Advanced list only for local company
1975  * if _ctrl_pressed, do the opposite action (Advanced list x Normal list)
1976  */
1977 
1978  if ((_settings_client.gui.advanced_vehicle_list > (uint)(company != _local_company)) != _ctrl_pressed) {
1979  ShowCompanyGroup(company, vehicle_type);
1980  } else {
1981  ShowVehicleListWindowLocal(company, VL_STANDARD, vehicle_type, company);
1982  }
1983 }
1984 
1985 void ShowVehicleListWindow(const Vehicle *v)
1986 {
1987  ShowVehicleListWindowLocal(v->owner, VL_SHARED_ORDERS, v->type, v->FirstShared()->index);
1988 }
1989 
1990 void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, StationID station)
1991 {
1992  ShowVehicleListWindowLocal(company, VL_STATION_LIST, vehicle_type, station);
1993 }
1994 
1995 void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, TileIndex depot_tile)
1996 {
1997  uint16 depot_airport_index;
1998 
1999  if (vehicle_type == VEH_AIRCRAFT) {
2000  depot_airport_index = GetStationIndex(depot_tile);
2001  } else {
2002  depot_airport_index = GetDepotIndex(depot_tile);
2003  }
2004  ShowVehicleListWindowLocal(company, VL_DEPOT_LIST, vehicle_type, depot_airport_index);
2005 }
2006 
2007 
2008 /* Unified vehicle GUI - Vehicle Details Window */
2009 
2014 
2018  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2019  NWidget(WWT_CAPTION, COLOUR_GREY, WID_VD_CAPTION), SetDataTip(STR_VEHICLE_DETAILS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2020  NWidget(WWT_SHADEBOX, COLOUR_GREY),
2021  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
2022  NWidget(WWT_STICKYBOX, COLOUR_GREY),
2023  EndContainer(),
2024  NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_TOP_DETAILS), SetMinimalSize(405, 42), SetResize(1, 0), EndContainer(),
2025  NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_MIDDLE_DETAILS), SetMinimalSize(405, 45), SetResize(1, 0), EndContainer(),
2028  SetDataTip(AWV_DECREASE, STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP),
2030  SetDataTip(AWV_INCREASE, STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP),
2032  SetDataTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
2033  NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_SERVICING_INTERVAL), SetFill(1, 1), SetResize(1, 0), EndContainer(),
2034  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
2035  EndContainer(),
2036 };
2037 
2041  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2042  NWidget(WWT_CAPTION, COLOUR_GREY, WID_VD_CAPTION), SetDataTip(STR_VEHICLE_DETAILS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2043  NWidget(WWT_SHADEBOX, COLOUR_GREY),
2044  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
2045  NWidget(WWT_STICKYBOX, COLOUR_GREY),
2046  EndContainer(),
2047  NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_TOP_DETAILS), SetResize(1, 0), SetMinimalSize(405, 42), EndContainer(),
2049  NWidget(WWT_MATRIX, COLOUR_GREY, WID_VD_MATRIX), SetResize(1, 1), SetMinimalSize(393, 45), SetMatrixDataTip(1, 0, STR_NULL), SetFill(1, 0), SetScrollbar(WID_VD_SCROLLBAR),
2050  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_VD_SCROLLBAR),
2051  EndContainer(),
2054  SetDataTip(AWV_DECREASE, STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP),
2056  SetDataTip(AWV_INCREASE, STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP),
2058  SetDataTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
2059  NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_SERVICING_INTERVAL), SetFill(1, 1), SetResize(1, 0), EndContainer(),
2060  EndContainer(),
2063  SetDataTip(STR_VEHICLE_DETAIL_TAB_CARGO, STR_VEHICLE_DETAILS_TRAIN_CARGO_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
2065  SetDataTip(STR_VEHICLE_DETAIL_TAB_INFORMATION, STR_VEHICLE_DETAILS_TRAIN_INFORMATION_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
2067  SetDataTip(STR_VEHICLE_DETAIL_TAB_CAPACITIES, STR_VEHICLE_DETAILS_TRAIN_CAPACITIES_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
2069  SetDataTip(STR_VEHICLE_DETAIL_TAB_TOTAL_CARGO, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CARGO_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
2070  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
2071  EndContainer(),
2072 };
2073 
2074 
2075 extern int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab);
2076 extern void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab);
2077 extern void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y);
2078 extern void DrawShipDetails(const Vehicle *v, int left, int right, int y);
2079 extern void DrawAircraftDetails(const Aircraft *v, int left, int right, int y);
2080 
2081 static StringID _service_interval_dropdown[] = {
2082  STR_VEHICLE_DETAILS_DEFAULT,
2083  STR_VEHICLE_DETAILS_DAYS,
2084  STR_VEHICLE_DETAILS_PERCENT,
2086 };
2087 
2091  Scrollbar *vscroll;
2092 
2095  {
2096  const Vehicle *v = Vehicle::Get(window_number);
2097 
2098  this->CreateNestedTree();
2099  this->vscroll = (v->type == VEH_TRAIN ? this->GetScrollbar(WID_VD_SCROLLBAR) : nullptr);
2100  this->FinishInitNested(window_number);
2101 
2102  this->owner = v->owner;
2103  this->tab = TDW_TAB_CARGO;
2104  }
2105 
2111  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2112  {
2113  if (data == VIWD_AUTOREPLACE) {
2114  /* Autoreplace replaced the vehicle.
2115  * Nothing to do for this window. */
2116  return;
2117  }
2118  if (!gui_scope) return;
2119  const Vehicle *v = Vehicle::Get(this->window_number);
2120  if (v->type == VEH_ROAD) {
2121  const NWidgetBase *nwid_info = this->GetWidget<NWidgetBase>(WID_VD_MIDDLE_DETAILS);
2122  uint aimed_height = this->GetRoadVehDetailsHeight(v);
2123  /* If the number of articulated parts changes, the size of the window must change too. */
2124  if (aimed_height != nwid_info->current_y) {
2125  this->ReInit();
2126  }
2127  }
2128  }
2129 
2136  {
2137  uint desired_height;
2138  if (v->HasArticulatedPart()) {
2139  /* An articulated RV has its text drawn under the sprite instead of after it, hence 15 pixels extra. */
2140  desired_height = WD_FRAMERECT_TOP + ScaleGUITrad(15) + 3 * FONT_HEIGHT_NORMAL + 2 + WD_FRAMERECT_BOTTOM;
2141  /* Add space for the cargo amount for each part. */
2142  for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
2143  if (u->cargo_cap != 0) desired_height += FONT_HEIGHT_NORMAL + 1;
2144  }
2145  } else {
2146  desired_height = WD_FRAMERECT_TOP + 4 * FONT_HEIGHT_NORMAL + 3 + WD_FRAMERECT_BOTTOM;
2147  }
2148  return desired_height;
2149  }
2150 
2151  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2152  {
2153  switch (widget) {
2154  case WID_VD_TOP_DETAILS: {
2155  Dimension dim = { 0, 0 };
2157 
2158  for (uint i = 0; i < 4; i++) SetDParamMaxValue(i, INT16_MAX);
2159  static const StringID info_strings[] = {
2160  STR_VEHICLE_INFO_MAX_SPEED,
2161  STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED,
2162  STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE,
2163  STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR,
2164  STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS
2165  };
2166  for (uint i = 0; i < lengthof(info_strings); i++) {
2167  dim = maxdim(dim, GetStringBoundingBox(info_strings[i]));
2168  }
2169  SetDParam(0, STR_VEHICLE_INFO_AGE);
2170  dim = maxdim(dim, GetStringBoundingBox(STR_VEHICLE_INFO_AGE_RUNNING_COST_YR));
2171  size->width = dim.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
2172  break;
2173  }
2174 
2175  case WID_VD_MIDDLE_DETAILS: {
2176  const Vehicle *v = Vehicle::Get(this->window_number);
2177  switch (v->type) {
2178  case VEH_ROAD:
2179  size->height = this->GetRoadVehDetailsHeight(v);
2180  break;
2181 
2182  case VEH_SHIP:
2183  size->height = WD_FRAMERECT_TOP + 4 * FONT_HEIGHT_NORMAL + 3 + WD_FRAMERECT_BOTTOM;
2184  break;
2185 
2186  case VEH_AIRCRAFT:
2187  size->height = WD_FRAMERECT_TOP + 5 * FONT_HEIGHT_NORMAL + 4 + WD_FRAMERECT_BOTTOM;
2188  break;
2189 
2190  default:
2191  NOT_REACHED(); // Train uses WID_VD_MATRIX instead.
2192  }
2193  break;
2194  }
2195 
2196  case WID_VD_MATRIX:
2198  size->height = 4 * resize->height;
2199  break;
2200 
2202  StringID *strs = _service_interval_dropdown;
2203  while (*strs != INVALID_STRING_ID) {
2204  *size = maxdim(*size, GetStringBoundingBox(*strs++));
2205  }
2206  size->width += padding.width;
2208  break;
2209  }
2210 
2212  SetDParamMaxValue(0, MAX_SERVINT_DAYS); // Roughly the maximum interval
2213  SetDParamMaxValue(1, MAX_YEAR * DAYS_IN_YEAR); // Roughly the maximum year
2214  size->width = std::max(
2215  GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT).width,
2216  GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS).width
2219  break;
2220  }
2221  }
2222 
2224  static bool IsVehicleServiceIntervalEnabled(const VehicleType vehicle_type, CompanyID company_id)
2225  {
2226  const VehicleDefaultSettings *vds = &Company::Get(company_id)->settings.vehicle;
2227  switch (vehicle_type) {
2228  default: NOT_REACHED();
2229  case VEH_TRAIN: return vds->servint_trains != 0;
2230  case VEH_ROAD: return vds->servint_roadveh != 0;
2231  case VEH_SHIP: return vds->servint_ships != 0;
2232  case VEH_AIRCRAFT: return vds->servint_aircraft != 0;
2233  }
2234  }
2235 
2247  static void DrawVehicleDetails(const Vehicle *v, int left, int right, int y, int vscroll_pos, uint vscroll_cap, TrainDetailsWindowTabs det_tab)
2248  {
2249  switch (v->type) {
2250  case VEH_TRAIN: DrawTrainDetails(Train::From(v), left, right, y, vscroll_pos, vscroll_cap, det_tab); break;
2251  case VEH_ROAD: DrawRoadVehDetails(v, left, right, y); break;
2252  case VEH_SHIP: DrawShipDetails(v, left, right, y); break;
2253  case VEH_AIRCRAFT: DrawAircraftDetails(Aircraft::From(v), left, right, y); break;
2254  default: NOT_REACHED();
2255  }
2256  }
2257 
2258  void SetStringParameters(int widget) const override
2259  {
2260  if (widget == WID_VD_CAPTION) SetDParam(0, Vehicle::Get(this->window_number)->index);
2261  }
2262 
2263  void DrawWidget(const Rect &r, int widget) const override
2264  {
2265  const Vehicle *v = Vehicle::Get(this->window_number);
2266 
2267  switch (widget) {
2268  case WID_VD_TOP_DETAILS: {
2269  int y = r.top + WD_FRAMERECT_TOP;
2270 
2271  /* Draw running cost */
2272  SetDParam(1, v->age / DAYS_IN_LEAP_YEAR);
2273  SetDParam(0, (v->age + DAYS_IN_YEAR < v->max_age) ? STR_VEHICLE_INFO_AGE : STR_VEHICLE_INFO_AGE_RED);
2276  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_AGE_RUNNING_COST_YR);
2277  y += FONT_HEIGHT_NORMAL;
2278 
2279  /* Draw max speed */
2280  StringID string;
2281  if (v->type == VEH_TRAIN ||
2282  (v->type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL)) {
2283  const GroundVehicleCache *gcache = v->GetGroundVehicleCache();
2284  SetDParam(2, v->GetDisplayMaxSpeed());
2285  SetDParam(1, gcache->cached_power);
2286  SetDParam(0, gcache->cached_weight);
2287  SetDParam(3, gcache->cached_max_te / 1000);
2288  if (v->type == VEH_TRAIN && (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL ||
2289  GetRailTypeInfo(Train::From(v)->railtype)->acceleration_type == 2)) {
2290  string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED;
2291  } else {
2292  string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE;
2293  }
2294  } else {
2295  SetDParam(0, v->GetDisplayMaxSpeed());
2296  if (v->type == VEH_AIRCRAFT) {
2298  if (Aircraft::From(v)->GetRange() > 0) {
2299  SetDParam(2, Aircraft::From(v)->GetRange());
2300  string = STR_VEHICLE_INFO_MAX_SPEED_TYPE_RANGE;
2301  } else {
2302  string = STR_VEHICLE_INFO_MAX_SPEED_TYPE;
2303  }
2304  } else {
2305  string = STR_VEHICLE_INFO_MAX_SPEED;
2306  }
2307  }
2308  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, string);
2309  y += FONT_HEIGHT_NORMAL;
2310 
2311  /* Draw profit */
2314  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR);
2315  y += FONT_HEIGHT_NORMAL;
2316 
2317  /* Draw breakdown & reliability */
2320  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS);
2321  break;
2322  }
2323 
2324  case WID_VD_MATRIX:
2325  /* For trains only. */
2326  DrawVehicleDetails(v, r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, r.top + WD_MATRIX_TOP, this->vscroll->GetPosition(), this->vscroll->GetCapacity(), this->tab);
2327  break;
2328 
2329  case WID_VD_MIDDLE_DETAILS: {
2330  /* For other vehicles, at the place of the matrix. */
2331  bool rtl = _current_text_dir == TD_RTL;
2333 
2334  uint text_left = r.left + (rtl ? 0 : sprite_width);
2335  uint text_right = r.right - (rtl ? sprite_width : 0);
2336 
2337  /* Articulated road vehicles use a complete line. */
2338  if (v->type == VEH_ROAD && v->HasArticulatedPart()) {
2340  } else {
2341  uint sprite_left = rtl ? text_right : r.left;
2342  uint sprite_right = rtl ? r.right : text_left;
2343 
2345  }
2346  DrawVehicleDetails(v, text_left + WD_FRAMERECT_LEFT, text_right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, 0, 0, this->tab);
2347  break;
2348  }
2349 
2351  /* Draw service interval text */
2352  SetDParam(0, v->GetServiceInterval());
2354  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + (r.bottom - r.top + 1 - FONT_HEIGHT_NORMAL) / 2,
2355  v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS);
2356  break;
2357  }
2358  }
2359 
2361  void OnPaint() override
2362  {
2363  const Vehicle *v = Vehicle::Get(this->window_number);
2364 
2365  if (v->type == VEH_TRAIN) {
2366  this->DisableWidget(this->tab + WID_VD_DETAILS_CARGO_CARRIED);
2367  this->vscroll->SetCount(GetTrainDetailsWndVScroll(v->index, this->tab));
2368  }
2369 
2370  /* Disable service-scroller when interval is set to disabled */
2374  WIDGET_LIST_END);
2375 
2376  StringID str = v->ServiceIntervalIsCustom() ?
2377  (v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_PERCENT : STR_VEHICLE_DETAILS_DAYS) :
2378  STR_VEHICLE_DETAILS_DEFAULT;
2379  this->GetWidget<NWidgetCore>(WID_VD_SERVICE_INTERVAL_DROPDOWN)->widget_data = str;
2380 
2381  this->DrawWidgets();
2382  }
2383 
2384  void OnClick(Point pt, int widget, int click_count) override
2385  {
2386  switch (widget) {
2387  case WID_VD_INCREASE_SERVICING_INTERVAL: // increase int
2388  case WID_VD_DECREASE_SERVICING_INTERVAL: { // decrease int
2389  int mod = _ctrl_pressed ? 5 : 10;
2390  const Vehicle *v = Vehicle::Get(this->window_number);
2391 
2392  mod = (widget == WID_VD_DECREASE_SERVICING_INTERVAL) ? -mod : mod;
2393  mod = GetServiceIntervalClamped(mod + v->GetServiceInterval(), v->ServiceIntervalIsPercent());
2394  if (mod == v->GetServiceInterval()) return;
2395 
2396  DoCommandP(v->tile, v->index, mod | (1 << 16) | (v->ServiceIntervalIsPercent() << 17), CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_ERROR_CAN_T_CHANGE_SERVICING));
2397  break;
2398  }
2399 
2401  const Vehicle *v = Vehicle::Get(this->window_number);
2402  ShowDropDownMenu(this, _service_interval_dropdown, v->ServiceIntervalIsCustom() ? (v->ServiceIntervalIsPercent() ? 2 : 1) : 0, widget, 0, 0);
2403  break;
2404  }
2405 
2410  this->SetWidgetsDisabledState(false,
2415  widget,
2416  WIDGET_LIST_END);
2417 
2418  this->tab = (TrainDetailsWindowTabs)(widget - WID_VD_DETAILS_CARGO_CARRIED);
2419  this->SetDirty();
2420  break;
2421  }
2422  }
2423 
2424  void OnDropdownSelect(int widget, int index) override
2425  {
2426  switch (widget) {
2428  const Vehicle *v = Vehicle::Get(this->window_number);
2429  bool iscustom = index != 0;
2430  bool ispercent = iscustom ? (index == 2) : Company::Get(v->owner)->settings.vehicle.servint_ispercent;
2431  uint16 interval = GetServiceIntervalClamped(v->GetServiceInterval(), ispercent);
2432  DoCommandP(v->tile, v->index, interval | (iscustom << 16) | (ispercent << 17), CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_ERROR_CAN_T_CHANGE_SERVICING));
2433  break;
2434  }
2435  }
2436  }
2437 
2438  void OnResize() override
2439  {
2440  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_VD_MATRIX);
2441  if (nwi != nullptr) {
2442  this->vscroll->SetCapacityFromWidget(this, WID_VD_MATRIX);
2443  }
2444  }
2445 };
2446 
2449  WDP_AUTO, "view_vehicle_details_train", 405, 178,
2451  0,
2453 );
2454 
2457  WDP_AUTO, "view_vehicle_details", 405, 113,
2459  0,
2461 );
2462 
2464 static void ShowVehicleDetailsWindow(const Vehicle *v)
2465 {
2468  AllocateWindowDescFront<VehicleDetailsWindow>((v->type == VEH_TRAIN) ? &_train_vehicle_details_desc : &_nontrain_vehicle_details_desc, v->index);
2469 }
2470 
2471 
2472 /* Unified vehicle GUI - Vehicle View Window */
2473 
2477  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2478  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_RENAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_NULL /* filled in later */),
2479  NWidget(WWT_CAPTION, COLOUR_GREY, WID_VV_CAPTION), SetDataTip(STR_VEHICLE_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2480  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_NULL /* filled in later */),
2481  NWidget(WWT_DEBUGBOX, COLOUR_GREY),
2482  NWidget(WWT_SHADEBOX, COLOUR_GREY),
2483  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
2484  NWidget(WWT_STICKYBOX, COLOUR_GREY),
2485  EndContainer(),
2487  NWidget(WWT_PANEL, COLOUR_GREY),
2488  NWidget(WWT_INSET, COLOUR_GREY), SetPadding(2, 2, 2, 2),
2489  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_VV_VIEWPORT), SetMinimalSize(226, 84), SetResize(1, 1), SetPadding(1, 1, 1, 1),
2490  EndContainer(),
2491  EndContainer(),
2494  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_GOTO_DEPOT), SetMinimalSize(18, 18), SetDataTip(0x0 /* filled later */, 0x0 /* filled later */),
2495  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_CLONE), SetMinimalSize(18, 18), SetDataTip(0x0 /* filled later */, 0x0 /* filled later */),
2496  EndContainer(),
2497  /* For trains only, 'ignore signal' button. */
2499  SetDataTip(SPR_IGNORE_SIGNALS, STR_VEHICLE_VIEW_TRAIN_IGNORE_SIGNAL_TOOLTIP),
2501  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_REFIT), SetMinimalSize(18, 18), SetDataTip(SPR_REFIT_VEHICLE, 0x0 /* filled later */),
2502  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_TURN_AROUND), SetMinimalSize(18, 18),
2503  SetDataTip(SPR_FORCE_VEHICLE_TURN, STR_VEHICLE_VIEW_ROAD_VEHICLE_REVERSE_TOOLTIP),
2504  EndContainer(),
2505  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_SHOW_ORDERS), SetMinimalSize(18, 18), SetDataTip(SPR_SHOW_ORDERS, 0x0 /* filled later */),
2506  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_SHOW_DETAILS), SetMinimalSize(18, 18), SetDataTip(SPR_SHOW_VEHICLE_DETAILS, 0x0 /* filled later */),
2507  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(18, 0), SetResize(0, 1), EndContainer(),
2508  EndContainer(),
2509  EndContainer(),
2512  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_ORDER_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_VEHICLE_VIEW_ORDER_LOCATION_TOOLTIP),
2513  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
2514  EndContainer(),
2515 };
2516 
2519  WDP_AUTO, "view_vehicle", 250, 116,
2521  0,
2523 );
2524 
2530  WDP_AUTO, "view_vehicle_train", 250, 134,
2532  0,
2534 );
2535 
2536 
2537 /* Just to make sure, nobody has changed the vehicle type constants, as we are
2538  using them for array indexing in a number of places here. */
2539 static_assert(VEH_TRAIN == 0);
2540 static_assert(VEH_ROAD == 1);
2541 static_assert(VEH_SHIP == 2);
2542 static_assert(VEH_AIRCRAFT == 3);
2543 
2548  ZOOM_LVL_SHIP,
2550 };
2551 
2552 /* Constants for geometry of vehicle view viewport */
2553 static const int VV_INITIAL_VIEWPORT_WIDTH = 226;
2554 static const int VV_INITIAL_VIEWPORT_HEIGHT = 84;
2555 static const int VV_INITIAL_VIEWPORT_HEIGHT_TRAIN = 102;
2556 
2559  VCT_CMD_START_STOP = 0,
2560  VCT_CMD_CLONE_VEH,
2561  VCT_CMD_TURN_AROUND,
2562 };
2563 
2565 static const uint32 _vehicle_command_translation_table[][4] = {
2566  { // VCT_CMD_START_STOP
2567  CMD_START_STOP_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_STOP_START_TRAIN),
2568  CMD_START_STOP_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_STOP_START_ROAD_VEHICLE),
2569  CMD_START_STOP_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_STOP_START_SHIP),
2570  CMD_START_STOP_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_STOP_START_AIRCRAFT)
2571  },
2572  { // VCT_CMD_CLONE_VEH
2573  CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN),
2574  CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_ROAD_VEHICLE),
2575  CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_SHIP),
2576  CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_AIRCRAFT)
2577  },
2578  { // VCT_CMD_TURN_AROUND
2579  CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_ERROR_CAN_T_REVERSE_DIRECTION_TRAIN),
2580  CMD_TURN_ROADVEH | CMD_MSG(STR_ERROR_CAN_T_MAKE_ROAD_VEHICLE_TURN),
2581  0xffffffff, // invalid for ships
2582  0xffffffff // invalid for aircraft
2583  },
2584 };
2585 
2593 void CcStartStopVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
2594 {
2595  if (result.Failed()) return;
2596 
2597  const Vehicle *v = Vehicle::GetIfValid(p1);
2598  if (v == nullptr || !v->IsPrimaryVehicle() || v->owner != _local_company) return;
2599 
2600  StringID msg = (v->vehstatus & VS_STOPPED) ? STR_VEHICLE_COMMAND_STOPPED : STR_VEHICLE_COMMAND_STARTED;
2601  Point pt = RemapCoords(v->x_pos, v->y_pos, v->z_pos);
2602  AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
2603 }
2604 
2610 void StartStopVehicle(const Vehicle *v, bool texteffect)
2611 {
2612  assert(v->IsPrimaryVehicle());
2613  DoCommandP(v->tile, v->index, 0, _vehicle_command_translation_table[VCT_CMD_START_STOP][v->type], texteffect ? CcStartStopVehicle : nullptr);
2614 }
2615 
2617 static bool IsVehicleRefitable(const Vehicle *v)
2618 {
2619  if (!v->IsStoppedInDepot()) return false;
2620 
2621  do {
2622  if (IsEngineRefittable(v->engine_type)) return true;
2623  } while (v->IsGroundVehicle() && (v = v->Next()) != nullptr);
2624 
2625  return false;
2626 }
2627 
2630 private:
2635 
2638 
2641  };
2642  bool mouse_over_start_stop = false;
2643 
2649  {
2650  switch (plane) {
2651  case SEL_DC_GOTO_DEPOT:
2652  case SEL_DC_CLONE:
2653  this->GetWidget<NWidgetStacked>(WID_VV_SELECT_DEPOT_CLONE)->SetDisplayedPlane(plane - SEL_DC_BASEPLANE);
2654  break;
2655 
2656  case SEL_RT_REFIT:
2657  case SEL_RT_TURN_AROUND:
2658  this->GetWidget<NWidgetStacked>(WID_VV_SELECT_REFIT_TURN)->SetDisplayedPlane(plane - SEL_RT_BASEPLANE);
2659  break;
2660 
2661  default:
2662  NOT_REACHED();
2663  }
2664  }
2665 
2666 public:
2668  {
2669  this->flags |= WF_DISABLE_VP_SCROLL;
2670  this->CreateNestedTree();
2671 
2672  /* Sprites for the 'send to depot' button indexed by vehicle type. */
2673  static const SpriteID vehicle_view_goto_depot_sprites[] = {
2674  SPR_SEND_TRAIN_TODEPOT,
2675  SPR_SEND_ROADVEH_TODEPOT,
2676  SPR_SEND_SHIP_TODEPOT,
2677  SPR_SEND_AIRCRAFT_TODEPOT,
2678  };
2679  const Vehicle *v = Vehicle::Get(window_number);
2680  this->GetWidget<NWidgetCore>(WID_VV_GOTO_DEPOT)->widget_data = vehicle_view_goto_depot_sprites[v->type];
2681 
2682  /* Sprites for the 'clone vehicle' button indexed by vehicle type. */
2683  static const SpriteID vehicle_view_clone_sprites[] = {
2685  SPR_CLONE_ROADVEH,
2686  SPR_CLONE_SHIP,
2687  SPR_CLONE_AIRCRAFT,
2688  };
2689  this->GetWidget<NWidgetCore>(WID_VV_CLONE)->widget_data = vehicle_view_clone_sprites[v->type];
2690 
2691  switch (v->type) {
2692  case VEH_TRAIN:
2693  this->GetWidget<NWidgetCore>(WID_VV_TURN_AROUND)->tool_tip = STR_VEHICLE_VIEW_TRAIN_REVERSE_TOOLTIP;
2694  break;
2695 
2696  case VEH_ROAD:
2697  break;
2698 
2699  case VEH_SHIP:
2700  case VEH_AIRCRAFT:
2701  this->SelectPlane(SEL_RT_REFIT);
2702  break;
2703 
2704  default: NOT_REACHED();
2705  }
2706  this->FinishInitNested(window_number);
2707  this->owner = v->owner;
2708  this->GetWidget<NWidgetViewport>(WID_VV_VIEWPORT)->InitializeViewport(this, this->window_number | (1 << 31), _vehicle_view_zoom_levels[v->type]);
2709 
2710  this->GetWidget<NWidgetCore>(WID_VV_START_STOP)->tool_tip = STR_VEHICLE_VIEW_TRAIN_STATUS_START_STOP_TOOLTIP + v->type;
2711  this->GetWidget<NWidgetCore>(WID_VV_RENAME)->tool_tip = STR_VEHICLE_DETAILS_TRAIN_RENAME + v->type;
2712  this->GetWidget<NWidgetCore>(WID_VV_LOCATION)->tool_tip = STR_VEHICLE_VIEW_TRAIN_CENTER_TOOLTIP + v->type;
2713  this->GetWidget<NWidgetCore>(WID_VV_REFIT)->tool_tip = STR_VEHICLE_VIEW_TRAIN_REFIT_TOOLTIP + v->type;
2714  this->GetWidget<NWidgetCore>(WID_VV_GOTO_DEPOT)->tool_tip = STR_VEHICLE_VIEW_TRAIN_SEND_TO_DEPOT_TOOLTIP + v->type;
2715  this->GetWidget<NWidgetCore>(WID_VV_SHOW_ORDERS)->tool_tip = STR_VEHICLE_VIEW_TRAIN_ORDERS_TOOLTIP + v->type;
2716  this->GetWidget<NWidgetCore>(WID_VV_SHOW_DETAILS)->tool_tip = STR_VEHICLE_VIEW_TRAIN_SHOW_DETAILS_TOOLTIP + v->type;
2717  this->GetWidget<NWidgetCore>(WID_VV_CLONE)->tool_tip = STR_VEHICLE_VIEW_CLONE_TRAIN_INFO + v->type;
2718 
2719  this->UpdateButtonStatus();
2720  }
2721 
2723  {
2724  DeleteWindowById(WC_VEHICLE_ORDERS, this->window_number, false);
2725  DeleteWindowById(WC_VEHICLE_REFIT, this->window_number, false);
2726  DeleteWindowById(WC_VEHICLE_DETAILS, this->window_number, false);
2727  DeleteWindowById(WC_VEHICLE_TIMETABLE, this->window_number, false);
2728  }
2729 
2730  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2731  {
2732  const Vehicle *v = Vehicle::Get(this->window_number);
2733  switch (widget) {
2734  case WID_VV_START_STOP:
2735  size->height = std::max(size->height, std::max(GetSpriteSize(SPR_FLAG_VEH_STOPPED).height, GetSpriteSize(SPR_FLAG_VEH_RUNNING).height) + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM);
2736  break;
2737 
2738  case WID_VV_FORCE_PROCEED:
2739  if (v->type != VEH_TRAIN) {
2740  size->height = 0;
2741  size->width = 0;
2742  }
2743  break;
2744 
2745  case WID_VV_VIEWPORT:
2746  size->width = VV_INITIAL_VIEWPORT_WIDTH;
2747  size->height = (v->type == VEH_TRAIN) ? VV_INITIAL_VIEWPORT_HEIGHT_TRAIN : VV_INITIAL_VIEWPORT_HEIGHT;
2748  break;
2749  }
2750  }
2751 
2752  void OnPaint() override
2753  {
2754  const Vehicle *v = Vehicle::Get(this->window_number);
2755  bool is_localcompany = v->owner == _local_company;
2756  bool refitable_and_stopped_in_depot = IsVehicleRefitable(v);
2757 
2758  this->SetWidgetDisabledState(WID_VV_RENAME, !is_localcompany);
2759  this->SetWidgetDisabledState(WID_VV_GOTO_DEPOT, !is_localcompany);
2760  this->SetWidgetDisabledState(WID_VV_REFIT, !refitable_and_stopped_in_depot || !is_localcompany);
2761  this->SetWidgetDisabledState(WID_VV_CLONE, !is_localcompany);
2762 
2763  if (v->type == VEH_TRAIN) {
2765  this->SetWidgetDisabledState(WID_VV_FORCE_PROCEED, !is_localcompany);
2766  this->SetWidgetDisabledState(WID_VV_TURN_AROUND, !is_localcompany);
2767  }
2768 
2770 
2771  this->DrawWidgets();
2772  }
2773 
2774  void SetStringParameters(int widget) const override
2775  {
2776  if (widget != WID_VV_CAPTION) return;
2777 
2778  const Vehicle *v = Vehicle::Get(this->window_number);
2779  SetDParam(0, v->index);
2780  }
2781 
2782  void DrawWidget(const Rect &r, int widget) const override
2783  {
2784  if (widget != WID_VV_START_STOP) return;
2785 
2786  const Vehicle *v = Vehicle::Get(this->window_number);
2787  StringID str;
2788  TextColour text_colour = TC_FROMSTRING;
2789  if (v->vehstatus & VS_CRASHED) {
2790  str = STR_VEHICLE_STATUS_CRASHED;
2791  } else if (v->type != VEH_AIRCRAFT && v->breakdown_ctr == 1) { // check for aircraft necessary?
2792  str = STR_VEHICLE_STATUS_BROKEN_DOWN;
2793  } else if (v->vehstatus & VS_STOPPED && (!mouse_over_start_stop || v->IsStoppedInDepot())) {
2794  if (v->type == VEH_TRAIN) {
2795  if (v->cur_speed == 0) {
2796  if (Train::From(v)->gcache.cached_power == 0) {
2797  str = STR_VEHICLE_STATUS_TRAIN_NO_POWER;
2798  } else {
2799  str = STR_VEHICLE_STATUS_STOPPED;
2800  }
2801  } else {
2802  SetDParam(0, v->GetDisplaySpeed());
2803  str = STR_VEHICLE_STATUS_TRAIN_STOPPING_VEL;
2804  }
2805  } else { // no train
2806  str = STR_VEHICLE_STATUS_STOPPED;
2807  }
2808  } else if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_TRAIN_STUCK) && !v->current_order.IsType(OT_LOADING)) {
2809  str = STR_VEHICLE_STATUS_TRAIN_STUCK;
2810  } else if (v->type == VEH_AIRCRAFT && HasBit(Aircraft::From(v)->flags, VAF_DEST_TOO_FAR) && !v->current_order.IsType(OT_LOADING)) {
2811  str = STR_VEHICLE_STATUS_AIRCRAFT_TOO_FAR;
2812  } else { // vehicle is in a "normal" state, show current order
2813  if (mouse_over_start_stop) {
2814  if (v->vehstatus & VS_STOPPED) {
2815  text_colour = TC_RED | TC_FORCED;
2816  } else if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_TRAIN_STUCK) && !v->current_order.IsType(OT_LOADING)) {
2817  text_colour = TC_ORANGE | TC_FORCED;
2818  }
2819  }
2820  switch (v->current_order.GetType()) {
2821  case OT_GOTO_STATION: {
2823  SetDParam(1, v->GetDisplaySpeed());
2824  str = STR_VEHICLE_STATUS_HEADING_FOR_STATION_VEL;
2825  break;
2826  }
2827 
2828  case OT_GOTO_DEPOT: {
2829  SetDParam(0, v->type);
2831  SetDParam(2, v->GetDisplaySpeed());
2833  /* This case *only* happens when multiple nearest depot orders
2834  * follow each other (including an order list only one order: a
2835  * nearest depot order) and there are no reachable depots.
2836  * It is primarily to guard for the case that there is no
2837  * depot with index 0, which would be used as fallback for
2838  * evaluating the string in the status bar. */
2839  str = STR_EMPTY;
2840  } else if (v->current_order.GetDepotActionType() & ODATFB_HALT) {
2841  str = STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_VEL;
2842  } else {
2843  str = STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_SERVICE_VEL;
2844  }
2845  break;
2846  }
2847 
2848  case OT_LOADING:
2849  str = STR_VEHICLE_STATUS_LOADING_UNLOADING;
2850  break;
2851 
2852  case OT_GOTO_WAYPOINT: {
2853  assert(v->type == VEH_TRAIN || v->type == VEH_SHIP);
2855  str = STR_VEHICLE_STATUS_HEADING_FOR_WAYPOINT_VEL;
2856  SetDParam(1, v->GetDisplaySpeed());
2857  break;
2858  }
2859 
2860  case OT_LEAVESTATION:
2861  if (v->type != VEH_AIRCRAFT) {
2862  str = STR_VEHICLE_STATUS_LEAVING;
2863  break;
2864  }
2865  FALLTHROUGH;
2866  default:
2867  if (v->GetNumManualOrders() == 0) {
2868  str = STR_VEHICLE_STATUS_NO_ORDERS_VEL;
2869  SetDParam(0, v->GetDisplaySpeed());
2870  } else {
2871  str = STR_EMPTY;
2872  }
2873  break;
2874  }
2875  }
2876 
2877  /* Draw the flag plus orders. */
2878  bool rtl = (_current_text_dir == TD_RTL);
2879  uint text_offset = std::max(GetSpriteSize(SPR_FLAG_VEH_STOPPED).width, GetSpriteSize(SPR_FLAG_VEH_RUNNING).width) + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
2880  int height = r.bottom - r.top;
2881  int text_left = r.left + (rtl ? (uint)WD_FRAMERECT_LEFT : text_offset);
2882  int text_right = r.right - (rtl ? text_offset : (uint)WD_FRAMERECT_RIGHT);
2883  int text_top = r.top + WD_FRAMERECT_TOP + (height - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM - FONT_HEIGHT_NORMAL) / 2;
2884  int image = ((v->vehstatus & VS_STOPPED) != 0) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING;
2885  int image_left = (rtl ? text_right + 1 : r.left) + WD_IMGBTN_LEFT;
2886  int image_top = r.top + WD_IMGBTN_TOP + (height - WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM - GetSpriteSize(image).height) / 2;
2887  int lowered = this->IsWidgetLowered(WID_VV_START_STOP) ? 1 : 0;
2888  DrawSprite(image, PAL_NONE, image_left + lowered, image_top + lowered);
2889  DrawString(text_left + lowered, text_right + lowered, text_top + lowered, str, text_colour, SA_HOR_CENTER);
2890  }
2891 
2892  void OnClick(Point pt, int widget, int click_count) override
2893  {
2894  const Vehicle *v = Vehicle::Get(this->window_number);
2895 
2896  switch (widget) {
2897  case WID_VV_RENAME: { // rename
2898  SetDParam(0, v->index);
2899  ShowQueryString(STR_VEHICLE_NAME, STR_QUERY_RENAME_TRAIN_CAPTION + v->type,
2901  break;
2902  }
2903 
2904  case WID_VV_START_STOP: // start stop
2905  StartStopVehicle(v, false);
2906  break;
2907 
2908  case WID_VV_ORDER_LOCATION: {
2909  /* Scroll to current order destination */
2910  TileIndex tile = v->current_order.GetLocation(v);
2911  if (tile == INVALID_TILE) break;
2912 
2913  if (_ctrl_pressed) {
2915  } else {
2916  ScrollMainWindowToTile(tile);
2917  }
2918  break;
2919  }
2920 
2921  case WID_VV_LOCATION: // center main view
2922  if (_ctrl_pressed) {
2924  } else {
2925  const Window *mainwindow = FindWindowById(WC_MAIN_WINDOW, 0);
2926  if (click_count > 1 && mainwindow->viewport->zoom <= ZOOM_LVL_OUT_4X) {
2927  /* main window 'follows' vehicle */
2928  mainwindow->viewport->follow_vehicle = v->index;
2929  } else {
2930  ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
2931  }
2932  }
2933  break;
2934 
2935  case WID_VV_GOTO_DEPOT: // goto hangar
2936  DoCommandP(v->tile, v->index | (_ctrl_pressed ? DEPOT_SERVICE : 0U), 0, GetCmdSendToDepot(v));
2937  break;
2938  case WID_VV_REFIT: // refit
2940  break;
2941  case WID_VV_SHOW_ORDERS: // show orders
2942  if (_ctrl_pressed) {
2944  } else {
2945  ShowOrdersWindow(v);
2946  }
2947  break;
2948  case WID_VV_SHOW_DETAILS: // show details
2949  if (_ctrl_pressed) {
2951  } else {
2953  }
2954  break;
2955  case WID_VV_CLONE: // clone vehicle
2956  /* Suppress the vehicle GUI when share-cloning.
2957  * There is no point to it except for starting the vehicle.
2958  * For starting the vehicle the player has to open the depot GUI, which is
2959  * most likely already open, but is also visible in the vehicle viewport. */
2960  DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0,
2961  _vehicle_command_translation_table[VCT_CMD_CLONE_VEH][v->type],
2962  _ctrl_pressed ? nullptr : CcCloneVehicle);
2963  break;
2964  case WID_VV_TURN_AROUND: // turn around
2965  assert(v->IsGroundVehicle());
2966  DoCommandP(v->tile, v->index, 0,
2967  _vehicle_command_translation_table[VCT_CMD_TURN_AROUND][v->type]);
2968  break;
2969  case WID_VV_FORCE_PROCEED: // force proceed
2970  assert(v->type == VEH_TRAIN);
2971  DoCommandP(v->tile, v->index, 0, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_ERROR_CAN_T_MAKE_TRAIN_PASS_SIGNAL));
2972  break;
2973  }
2974  }
2975 
2976  void OnQueryTextFinished(char *str) override
2977  {
2978  if (str == nullptr) return;
2979 
2980  DoCommandP(0, this->window_number, 0, CMD_RENAME_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type), nullptr, str);
2981  }
2982 
2983  void OnMouseOver(Point pt, int widget) override
2984  {
2985  bool start_stop = widget == WID_VV_START_STOP;
2986  if (start_stop != mouse_over_start_stop) {
2987  mouse_over_start_stop = start_stop;
2989  }
2990  }
2991 
2992  void OnResize() override
2993  {
2994  if (this->viewport != nullptr) {
2995  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_VV_VIEWPORT);
2996  nvp->UpdateViewportCoordinates(this);
2997  }
2998  }
2999 
3000  void UpdateButtonStatus()
3001  {
3002  const Vehicle *v = Vehicle::Get(this->window_number);
3003  bool veh_stopped = v->IsStoppedInDepot();
3004 
3005  /* Widget WID_VV_GOTO_DEPOT must be hidden if the vehicle is already stopped in depot.
3006  * Widget WID_VV_CLONE_VEH should then be shown, since cloning is allowed only while in depot and stopped.
3007  */
3008  PlaneSelections plane = veh_stopped ? SEL_DC_CLONE : SEL_DC_GOTO_DEPOT;
3009  NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(WID_VV_SELECT_DEPOT_CLONE); // Selection widget 'send to depot' / 'clone'.
3010  if (nwi->shown_plane + SEL_DC_BASEPLANE != plane) {
3011  this->SelectPlane(plane);
3013  }
3014  /* The same system applies to widget WID_VV_REFIT_VEH and VVW_WIDGET_TURN_AROUND.*/
3015  if (v->IsGroundVehicle()) {
3016  PlaneSelections plane = veh_stopped ? SEL_RT_REFIT : SEL_RT_TURN_AROUND;
3017  NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(WID_VV_SELECT_REFIT_TURN);
3018  if (nwi->shown_plane + SEL_RT_BASEPLANE != plane) {
3019  this->SelectPlane(plane);
3021  }
3022  }
3023  }
3024 
3030  void OnInvalidateData(int data = 0, bool gui_scope = true) override
3031  {
3032  if (data == VIWD_AUTOREPLACE) {
3033  /* Autoreplace replaced the vehicle.
3034  * Nothing to do for this window. */
3035  return;
3036  }
3037 
3038  this->UpdateButtonStatus();
3039  }
3040 
3041  bool IsNewGRFInspectable() const override
3042  {
3043  return ::IsNewGRFInspectable(GetGrfSpecFeature(Vehicle::Get(this->window_number)->type), this->window_number);
3044  }
3045 
3046  void ShowNewGRFInspectWindow() const override
3047  {
3048  ::ShowNewGRFInspectWindow(GetGrfSpecFeature(Vehicle::Get(this->window_number)->type), this->window_number);
3049  }
3050 };
3051 
3052 
3055 {
3056  AllocateWindowDescFront<VehicleViewWindow>((v->type == VEH_TRAIN) ? &_train_view_desc : &_vehicle_view_desc, v->index);
3057 }
3058 
3064 bool VehicleClicked(const Vehicle *v)
3065 {
3066  assert(v != nullptr);
3067  if (!(_thd.place_mode & HT_VEHICLE)) return false;
3068 
3069  v = v->First();
3070  if (!v->IsPrimaryVehicle()) return false;
3071 
3072  return _thd.GetCallbackWnd()->OnVehicleSelect(v);
3073 }
3074 
3075 void StopGlobalFollowVehicle(const Vehicle *v)
3076 {
3078  if (w != nullptr && w->viewport->follow_vehicle == v->index) {
3079  ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos, true); // lock the main view on the vehicle's last position
3081  }
3082 }
3083 
3084 
3093 void CcBuildPrimaryVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
3094 {
3095  if (result.Failed()) return;
3096 
3097  const Vehicle *v = Vehicle::Get(_new_vehicle_id);
3099 }
3100 
3107 {
3108  switch (v->type) {
3109  case VEH_TRAIN:
3110  return Train::From(v)->GetDisplayImageWidth();
3111 
3112  case VEH_ROAD:
3114 
3115  default:
3116  bool rtl = _current_text_dir == TD_RTL;
3117  VehicleSpriteSeq seq;
3118  v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
3119  Rect rec;
3120  seq.GetBounds(&rec);
3121  return UnScaleGUI(rec.right - rec.left + 1);
3122  }
3123 }
3124 
3130 int GetVehicleWidth(const Vehicle *v, EngineImageType image_type)
3131 {
3132  if (v->type == VEH_TRAIN || v->type == VEH_ROAD) {
3133  int vehicle_width = 0;
3134  for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
3135  vehicle_width += GetSingleVehicleWidth(u, image_type);
3136  }
3137  return vehicle_width;
3138  } else {
3139  return GetSingleVehicleWidth(v, image_type);
3140  }
3141 }
3142 
3149 {
3150  bool rtl = _current_text_dir == TD_RTL;
3151 
3152  _cursor.sprite_count = 0;
3153  int total_width = 0;
3154  for (; v != nullptr; v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr) {
3155  if (total_width >= ScaleGUITrad(2 * (int)VEHICLEINFO_FULL_VEHICLE_WIDTH)) break;
3156 
3158  VehicleSpriteSeq seq;
3159  v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
3160 
3161  if (_cursor.sprite_count + seq.count > lengthof(_cursor.sprite_seq)) break;
3162 
3163  for (uint i = 0; i < seq.count; ++i) {
3164  PaletteID pal2 = (v->vehstatus & VS_CRASHED) || !seq.seq[i].pal ? pal : seq.seq[i].pal;
3165  _cursor.sprite_seq[_cursor.sprite_count].sprite = seq.seq[i].sprite;
3166  _cursor.sprite_seq[_cursor.sprite_count].pal = pal2;
3167  _cursor.sprite_pos[_cursor.sprite_count].x = rtl ? -total_width : total_width;
3168  _cursor.sprite_pos[_cursor.sprite_count].y = 0;
3169  _cursor.sprite_count++;
3170  }
3171 
3172  total_width += GetSingleVehicleWidth(v, image_type);
3173  }
3174 
3175  int offs = (ScaleGUITrad(VEHICLEINFO_FULL_VEHICLE_WIDTH) - total_width) / 2;
3176  if (rtl) offs = -offs;
3177  for (uint i = 0; i < _cursor.sprite_count; ++i) {
3178  _cursor.sprite_pos[i].x += offs;
3179  }
3180 
3181  UpdateCursorSize();
3182 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
Train::GetDisplayImageWidth
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
Definition: train_cmd.cpp:432
IsVehicleRefitable
static bool IsVehicleRefitable(const Vehicle *v)
Checks whether the vehicle may be refitted at the moment.
Definition: vehicle_gui.cpp:2617
WID_VL_AVAILABLE_VEHICLES
@ WID_VL_AVAILABLE_VEHICLES
Available vehicles.
Definition: vehicle_widget.h:72
Vehicle::GetGroundVehicleCache
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
Definition: vehicle.cpp:2886
Vehicle::IsChainInDepot
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Definition: vehicle_base.h:521
TC_FORCED
@ TC_FORCED
Ignore colour changes from strings.
Definition: gfx_type.h:275
VehicleListWindow::BP_HIDE_BUTTONS
@ BP_HIDE_BUTTONS
Show the empty panel.
Definition: vehicle_gui.cpp:1639
VehicleViewWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: vehicle_gui.cpp:2752
VehicleViewWindow::SEL_RT_TURN_AROUND
@ SEL_RT_TURN_AROUND
Display 'turn around' button in WID_VV_SELECT_REFIT_TURN stacked widget.
Definition: vehicle_gui.cpp:2637
VehicleOrderID
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:15
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
CountDigitsForAllocatingSpace
uint CountDigitsForAllocatingSpace(uint number)
Get the number of digits of space required for the given number.
Definition: vehicle_gui.cpp:146
CMD_MSG
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:372
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
BaseVehicleListWindow::GetActionDropdownSize
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group)
Compute the size for the Action dropdown.
Definition: vehicle_gui.cpp:227
VehicleGroupLengthSorter
static bool VehicleGroupLengthSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the number of vehicles in the group.
Definition: vehicle_gui.cpp:1173
WID_VV_TURN_AROUND
@ WID_VV_TURN_AROUND
Turn this vehicle around.
Definition: vehicle_widget.h:28
ClampToI32
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Definition: math_func.hpp:141
WC_INVALID
@ WC_INVALID
Invalid window.
Definition: window_type.h:700
DoCommand
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:450
CMD_REVERSE_TRAIN_DIRECTION
@ CMD_REVERSE_TRAIN_DIRECTION
turn a train around
Definition: command_type.h:222
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:61
GUIList::SortType
uint8 SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:93
VehicleList
std::vector< const Vehicle * > VehicleList
A list of vehicles.
Definition: vehiclelist.h:53
Pool::PoolItem<&_vehicle_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
VehicleViewWindow::PlaneSelections
PlaneSelections
Display planes available in the vehicle view window.
Definition: vehicle_gui.cpp:2632
WID_VR_MATRIX
@ WID_VR_MATRIX
Options to refit to.
Definition: vehicle_widget.h:39
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2443
VehicleListWindow::BP_SHOW_BUTTONS
@ BP_SHOW_BUTTONS
Show the buttons.
Definition: vehicle_gui.cpp:1638
WD_MATRIX_RIGHT
@ WD_MATRIX_RIGHT
Offset at right of a matrix cell.
Definition: window_gui.h:77
Vehicle::y_pos
int32 y_pos
y coordinate.
Definition: vehicle_base.h:279
HasAtMostOneBit
static bool HasAtMostOneBit(T value)
Test whether value has at most 1 bit set.
Definition: bitmath_func.hpp:286
VehicleDetailsWindow::GetRoadVehDetailsHeight
uint GetRoadVehDetailsHeight(const Vehicle *v)
Gets the desired height for the road vehicle details panel.
Definition: vehicle_gui.cpp:2135
TDW_TAB_INFO
@ TDW_TAB_INFO
Tab with name and value of the vehicles.
Definition: vehicle_gui.h:25
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1104
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:168
CMD_ORDER_REFIT
@ CMD_ORDER_REFIT
change the refit information of an order (for "goto depot" )
Definition: command_type.h:272
CcBuildPrimaryVehicle
void CcBuildPrimaryVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
This is the Callback method after the construction attempt of a primary vehicle.
Definition: vehicle_gui.cpp:3093
GetServiceIntervalClamped
uint16 GetServiceIntervalClamped(uint interval, bool ispercent)
Clamp the service interval to the correct min/max.
Definition: order_cmd.cpp:1918
VehicleListIdentifier::company
CompanyID company
The company associated with this list.
Definition: vehiclelist.h:32
WID_VL_LIST
@ WID_VL_LIST
List of the vehicles.
Definition: vehicle_widget.h:69
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
Vehicle::GetNumManualOrders
VehicleOrderID GetNumManualOrders() const
Get the number of manually added orders this vehicle has.
Definition: vehicle_base.h:704
Vehicle::value
Money value
Value of the vehicle.
Definition: vehicle_base.h:251
VehicleSettings::train_acceleration_model
uint8 train_acceleration_model
realistic acceleration for trains
Definition: settings_type.h:466
Vehicle::x_pos
int32 x_pos
x coordinate.
Definition: vehicle_base.h:278
train.h
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
command_func.h
TE_RISING
@ TE_RISING
Make the text effect slowly go upwards.
Definition: texteff.hpp:21
RefitWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: vehicle_gui.cpp:896
VehicleViewWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: vehicle_gui.cpp:2992
WID_VL_CAPTION
@ WID_VL_CAPTION
Caption of window.
Definition: vehicle_widget.h:64
Window::DrawSortButtonState
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:636
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1055
CursorVars::sprite_count
uint sprite_count
number of sprites to draw
Definition: gfx_type.h:130
Pool::PoolItem<&_vehicle_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:340
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:247
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:309
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:208
RefitWindow::click_x
int click_x
Position of the first click while dragging.
Definition: vehicle_gui.cpp:486
dropdown_func.h
VehicleDetailsWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: vehicle_gui.cpp:2384
BaseVehicleListWindow::grouping
GroupBy grouping
How we want to group the list.
Definition: vehicle_gui_base.h:79
VehicleGroupTotalProfitThisYearSorter
static bool VehicleGroupTotalProfitThisYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the total profit this year.
Definition: vehicle_gui.cpp:1179
VehicleListIdentifier
The information about a vehicle list.
Definition: vehiclelist.h:29
CBID_VEHICLE_CARGO_SUFFIX
@ CBID_VEHICLE_CARGO_SUFFIX
Determine the cargo "suffixes" for each refit possibility of a cargo.
Definition: newgrf_callbacks.h:60
RefitWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: vehicle_gui.cpp:1004
RefitWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: vehicle_gui.cpp:743
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:995
company_base.h
VehicleDetailsWindow::DrawVehicleDetails
static void DrawVehicleDetails(const Vehicle *v, int left, int right, int y, int vscroll_pos, uint vscroll_cap, TrainDetailsWindowTabs det_tab)
Draw the details for the given vehicle at the position of the Details windows.
Definition: vehicle_gui.cpp:2247
DrawRoadVehDetails
void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y)
Draw the details for the given vehicle at the given position.
Definition: roadveh_gui.cpp:30
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:592
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1077
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:81
RefitWindow::information_width
uint information_width
Width required for correctly displaying all cargoes in the information panel.
Definition: vehicle_gui.cpp:479
WD_MATRIX_TOP
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
Definition: window_gui.h:78
WID_VL_GROUP_BY_PULLDOWN
@ WID_VL_GROUP_BY_PULLDOWN
Group by dropdown list.
Definition: vehicle_widget.h:66
Vehicle::GetDisplayMaxSpeed
virtual int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: vehicle_base.h:497
TrainDetailsWindowTabs
TrainDetailsWindowTabs
The tabs in the train details window.
Definition: vehicle_gui.h:23
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:584
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Scrollbar::ScrollTowards
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:740
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:94
Vehicle::z_pos
int32 z_pos
z coordinate.
Definition: vehicle_base.h:280
RefitWindow::selected_vehicle
VehicleID selected_vehicle
First vehicle in the current selection.
Definition: vehicle_gui.cpp:487
VehicleDetailsWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: vehicle_gui.cpp:2111
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1972
BaseVehicleListWindow::order_arrow_width
uint order_arrow_width
Width of the arrow in the small order list.
Definition: vehicle_gui_base.h:86
VehicleDetailsWindow::VehicleDetailsWindow
VehicleDetailsWindow(WindowDesc *desc, WindowNumber window_number)
Initialize a newly created vehicle details window.
Definition: vehicle_gui.cpp:2094
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:239
RemapCoords
static Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Definition: landscape.h:82
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:327
GetVehicleSet
void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles)
Calculates the set of vehicles that will be affected by a given selection.
Definition: vehicle.cpp:2949
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:99
DrawVehicleImage
void DrawVehicleImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip)
Draws an image of a vehicle chain.
Definition: vehicle_gui.cpp:1473
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:326
WID_VR_CAPTION
@ WID_VR_CAPTION
Caption of window.
Definition: vehicle_widget.h:34
BaseConsist::name
std::string name
Name of vehicle.
Definition: base_consist.h:19
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
RefitWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: vehicle_gui.cpp:722
group_gui.h
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1832
DEPOT_MASS_SEND
@ DEPOT_MASS_SEND
Tells that it's a mass send to depot command (type in VLW flag)
Definition: vehicle_type.h:67
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:117
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:81
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
Vehicle::group_id
GroupID group_id
Index of group Pool array.
Definition: vehicle_base.h:335
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:57
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1133
CcStartStopVehicle
void CcStartStopVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
This is the Callback method after attempting to start/stop a vehicle.
Definition: vehicle_gui.cpp:2593
BaseVehicleListWindow::sorting
Listing * sorting
Pointer to the vehicle type related sorting.
Definition: vehicle_gui_base.h:82
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
UnScaleGUI
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:66
RefitOption::subtype
byte subtype
Subcargo to use.
Definition: vehicle_gui.cpp:383
VehicleViewWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: vehicle_gui.cpp:3030
_returned_mail_refit_capacity
uint16 _returned_mail_refit_capacity
Stores the mail capacity after a refit operation (Aircraft only).
Definition: vehicle.cpp:86
VehicleListWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: vehicle_gui.cpp:1803
ShowCompanyGroup
void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group=INVALID_GROUP, bool need_existing_window=false)
Show the group window for the given company and vehicle type.
Definition: group_gui.cpp:1096
_vehicle_view_zoom_levels
static const ZoomLevel _vehicle_view_zoom_levels[]
Zoom levels for vehicle views indexed by vehicle type.
Definition: vehicle_gui.cpp:2545
include
bool include(std::vector< T > &vec, const T &item)
Helper function to append an item to a vector if it is not already contained Consider using std::set,...
Definition: smallvec_type.hpp:27
VehicleViewWindow::SEL_DC_BASEPLANE
@ SEL_DC_BASEPLANE
First plane of the WID_VV_SELECT_DEPOT_CLONE stacked widget.
Definition: vehicle_gui.cpp:2639
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:679
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
WID_VL_START_ALL
@ WID_VL_START_ALL
Start all button.
Definition: vehicle_widget.h:75
Vehicle::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the vehicle is tied to.
Definition: vehicle.cpp:751
FOR_ALL_SORTED_CARGOSPECS
#define FOR_ALL_SORTED_CARGOSPECS(var)
Loop header for iterating over cargoes, sorted by name.
Definition: cargotype.h:164
VehicleViewWindow::SelectPlane
void SelectPlane(PlaneSelections plane)
Display a plane in the window.
Definition: vehicle_gui.cpp:2648
VehicleCommandTranslation
VehicleCommandTranslation
Command indices for the _vehicle_command_translation_table.
Definition: vehicle_gui.cpp:2558
WID_VD_SERVICE_INTERVAL_DROPDOWN
@ WID_VD_SERVICE_INTERVAL_DROPDOWN
Dropdown to select default/days/percent service interval.
Definition: vehicle_widget.h:51
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:939
zoom_func.h
autoreplace_gui.h
aircraft.h
GetUnitNumberDigits
uint GetUnitNumberDigits(VehicleList &vehicles)
Get the number of digits the biggest unit number of a set of vehicles has.
Definition: vehicle_gui.cpp:165
GUIVehicleGroup::vehicles_begin
VehicleList::const_iterator vehicles_begin
Pointer to beginning element of this vehicle group.
Definition: vehicle_gui_base.h:28
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:21
VehicleDetailsWindow::tab
TrainDetailsWindowTabs tab
For train vehicles: which tab is displayed.
Definition: vehicle_gui.cpp:2090
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
VehicleListWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: vehicle_gui.cpp:1711
ChangeVehicleViewWindow
void ChangeVehicleViewWindow(VehicleID from_index, VehicleID to_index)
Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows.
Definition: vehicle_gui.cpp:1359
EIT_IN_DETAILS
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
Definition: vehicle_type.h:88
DrawString
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:640
WindowDesc::cls
WindowClass cls
Class of the window,.
Definition: window_gui.h:175
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:55
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:398
WID_VV_VIEWPORT
@ WID_VV_VIEWPORT
Viewport widget.
Definition: vehicle_widget.h:16
WC_VEHICLE_TIMETABLE
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
Definition: window_type.h:217
newgrf_debug.h
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:325
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:104
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
WID_VV_SHOW_ORDERS
@ WID_VV_SHOW_ORDERS
Show the orders of this vehicle.
Definition: vehicle_widget.h:23
DIR_W
@ DIR_W
West.
Definition: direction_type.h:32
Vehicle::GetNextArticulatedPart
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
Definition: vehicle_base.h:923
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:315
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:85
CBM_VEHICLE_CARGO_SUFFIX
@ CBM_VEHICLE_CARGO_SUFFIX
Show suffix after cargo name.
Definition: newgrf_callbacks.h:294
Engine
Definition: engine_base.h:21
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle::cur_speed
uint16 cur_speed
current speed
Definition: vehicle_base.h:302
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
Vehicle::IsPrimaryVehicle
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:444
Vehicle::IsGroundVehicle
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:482
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_func.h:97
VehicleDefaultSettings::servint_ships
uint16 servint_ships
service interval for ships
Definition: settings_type.h:549
GUIList::SetSortType
void SetSortType(uint8 n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:103
WID_VL_SCROLLBAR
@ WID_VL_SCROLLBAR
Scrollbar for the list.
Definition: vehicle_widget.h:70
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:283
CMD_TURN_ROADVEH
@ CMD_TURN_ROADVEH
turn a road vehicle around
Definition: command_type.h:254
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
VehicleGroupTotalProfitLastYearSorter
static bool VehicleGroupTotalProfitLastYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the total profit last year.
Definition: vehicle_gui.cpp:1185
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:598
GetVehicleCallback
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1188
ShowTimetableWindow
void ShowTimetableWindow(const Vehicle *v)
Show the timetable for a given vehicle.
Definition: timetable_gui.cpp:708
WID_VD_DETAILS_CAPACITY_OF_EACH
@ WID_VD_DETAILS_CAPACITY_OF_EACH
Show the capacity of all train parts.
Definition: vehicle_widget.h:58
VehicleAgeSorter
static bool VehicleAgeSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their age.
Definition: vehicle_gui.cpp:1230
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:52
WID_VV_FORCE_PROCEED
@ WID_VV_FORCE_PROCEED
Force this vehicle to pass a signal at danger.
Definition: vehicle_widget.h:29
CursorVars::sprite_pos
Point sprite_pos[16]
relative position of individual sprites
Definition: gfx_type.h:129
VehicleListWindow
Window for the (old) vehicle listing.
Definition: vehicle_gui.cpp:1634
SetDParam
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:199
VehicleListWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: vehicle_gui.cpp:1873
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:919
RefitWindow::num_vehicles
uint8 num_vehicles
Number of selected vehicles.
Definition: vehicle_gui.cpp:488
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1023
_vehicle_view_desc
static WindowDesc _vehicle_view_desc(WDP_AUTO, "view_vehicle", 250, 116, WC_VEHICLE_VIEW, WC_NONE, 0, _nested_vehicle_view_widgets, lengthof(_nested_vehicle_view_widgets))
Vehicle view window descriptor for all vehicles but trains.
Vehicle::breakdowns_since_last_service
byte breakdowns_since_last_service
Counter for the amount of breakdowns.
Definition: vehicle_base.h:275
NWidgetCore::widget_data
uint32 widget_data
Data of the widget.
Definition: widget_type.h:314
RefitWindow::sprite_left
int sprite_left
Left position of the vehicle sprite.
Definition: vehicle_gui.cpp:483
VehicleDetailsWindow::IsVehicleServiceIntervalEnabled
static bool IsVehicleServiceIntervalEnabled(const VehicleType vehicle_type, CompanyID company_id)
Checks whether service interval is enabled for the vehicle.
Definition: vehicle_gui.cpp:2224
WD_IMGBTN_BOTTOM
@ WD_IMGBTN_BOTTOM
Bottom offset of image in the button.
Definition: window_gui.h:41
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:842
textbuf_gui.h
VehicleViewWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: vehicle_gui.cpp:2892
RefitWindow::auto_refit
bool auto_refit
Select cargo for auto-refitting.
Definition: vehicle_gui.cpp:489
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:763
CountBits
static uint CountBits(T value)
Counts the number of set bits in a variable.
Definition: bitmath_func.hpp:251
QSF_LEN_IN_CHARS
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
Definition: textbuf_gui.h:22
VehicleDetailsWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: vehicle_gui.cpp:2258
Vehicle::IsArticulatedPart
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition: vehicle_base.h:904
WID_VR_REFIT
@ WID_VR_REFIT
Perform the refit.
Definition: vehicle_widget.h:42
VehicleListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: vehicle_gui.cpp:1915
Order::GetType
OrderType GetType() const
Get the type of order of this order.
Definition: order_base.h:67
BaseVehicleListWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: vehicle_gui.cpp:243
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
UpdateCursorSize
void UpdateCursorSize()
Update cursor dimension.
Definition: gfx.cpp:1666
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
ALL_GROUP
static const GroupID ALL_GROUP
All vehicles are in this group.
Definition: group_type.h:16
RefitWindow::list
SubtypeList list[NUM_CARGO]
List of refit subtypes available for each sorted cargo.
Definition: vehicle_gui.cpp:477
TDW_TAB_TOTALS
@ TDW_TAB_TOTALS
Tab with sum of total cargo transported.
Definition: vehicle_gui.h:27
WindowDesc
High level window description.
Definition: window_gui.h:166
GetGrfSpecFeature
GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
Get the GrfSpecFeature associated with the tile.
Definition: newgrf_debug_gui.cpp:768
WID_VR_SHOW_HSCROLLBAR
@ WID_VR_SHOW_HSCROLLBAR
Selection widget for the horizontal scrollbar.
Definition: vehicle_widget.h:36
RefitWindow::sel
int sel[2]
Index in refit options, sel[0] == -1 if nothing is selected.
Definition: vehicle_gui.cpp:475
WID_VV_SHOW_DETAILS
@ WID_VV_SHOW_DETAILS
Show details of this vehicle.
Definition: vehicle_widget.h:24
GetRailTypeInfo
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:304
Vehicle::GetDisplayRunningCost
Money GetDisplayRunningCost() const
Gets the running cost of a vehicle that can be sent into SetDParam for string processing.
Definition: vehicle_base.h:571
ShowVehicleDetailsWindow
static void ShowVehicleDetailsWindow(const Vehicle *v)
Shows the vehicle details window of the given vehicle.
Definition: vehicle_gui.cpp:2464
Vehicle::breakdown_ctr
byte breakdown_ctr
Counter for managing breakdown events.
Definition: vehicle_base.h:273
CargoSpec::Index
CargoID Index() const
Determines index of this cargospec.
Definition: cargotype.h:88
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
BaseVehicleListWindow::vli
VehicleListIdentifier vli
Identifier of the vehicle list we want to currently show.
Definition: vehicle_gui_base.h:85
BaseVehicleListWindow::BuildActionDropdownList
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group)
Display the Action dropdown window.
Definition: vehicle_gui.cpp:254
GroundVehicleCache::cached_total_length
uint16 cached_total_length
Length of the whole vehicle (valid only for the first engine).
Definition: ground_vehicle.hpp:42
EF_AUTO_REFIT
@ EF_AUTO_REFIT
Automatic refitting is allowed.
Definition: engine_type.h:158
Vehicle::GetDisplayProfitThisYear
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
Definition: vehicle_base.h:577
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:223
RefitWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: vehicle_gui.cpp:761
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:154
Vehicle::GetDisplaySpeed
virtual int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: vehicle_base.h:491
GroundVehicleCache
Cached, frequently calculated values.
Definition: ground_vehicle.hpp:29
timetable.h
WID_VR_HSCROLLBAR
@ WID_VR_HSCROLLBAR
Horizontal scrollbar or the vehicle display.
Definition: vehicle_widget.h:37
WWT_PUSHBTN
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
Definition: widget_type.h:101
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:323
GetVehicleHeight
static uint GetVehicleHeight(VehicleType type)
Get the height of a single vehicle in the GUIs.
Definition: vehicle_gui.h:68
CommandCost
Common return value for all commands.
Definition: command_type.h:23
VehicleListWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: vehicle_gui.cpp:1768
VRF_TRAIN_STUCK
@ VRF_TRAIN_STUCK
Train can't get a path reservation.
Definition: train.h:32
VehicleViewWindow::SEL_DC_GOTO_DEPOT
@ SEL_DC_GOTO_DEPOT
Display 'goto depot' button in WID_VV_SELECT_DEPOT_CLONE stacked widget.
Definition: vehicle_gui.cpp:2633
WC_VEHICLE_VIEW
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
Definition: window_type.h:332
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:1949
WID_VL_STOP_ALL
@ WID_VL_STOP_ALL
Stop all button.
Definition: vehicle_widget.h:74
tilehighlight_func.h
_train_view_desc
static WindowDesc _train_view_desc(WDP_AUTO, "view_vehicle_train", 250, 134, WC_VEHICLE_VIEW, WC_NONE, 0, _nested_vehicle_view_widgets, lengthof(_nested_vehicle_view_widgets))
Vehicle view window descriptor for trains.
GetUnionOfArticulatedRefitMasks
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Definition: articulated_vehicles.cpp:255
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
StartStopVehicle
void StartStopVehicle(const Vehicle *v, bool texteffect)
Executes CMD_START_STOP_VEHICLE for given vehicle.
Definition: vehicle_gui.cpp:2610
WID_VL_SORT_ORDER
@ WID_VL_SORT_ORDER
Sort order.
Definition: vehicle_widget.h:67
INVALID_VEH_ORDER_ID
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
Definition: order_type.h:21
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:79
ShowCompanyGroupForVehicle
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
Definition: group_gui.cpp:1115
VEH_COMPANY_END
@ VEH_COMPANY_END
Last company-ownable type.
Definition: vehicle_type.h:29
WID_VD_DETAILS_TRAIN_VEHICLES
@ WID_VD_DETAILS_TRAIN_VEHICLES
Show all parts of the train with their description.
Definition: vehicle_widget.h:57
WID_VD_MIDDLE_DETAILS
@ WID_VD_MIDDLE_DETAILS
Details for non-trains.
Definition: vehicle_widget.h:53
EngineInfo::callback_mask
byte callback_mask
Bitmask of vehicle callbacks that have to be called.
Definition: engine_type.h:143
DIR_E
@ DIR_E
East.
Definition: direction_type.h:28
_nested_nontrain_vehicle_details_widgets
static const NWidgetPart _nested_nontrain_vehicle_details_widgets[]
Vehicle details widgets (other than train).
Definition: vehicle_gui.cpp:2016
TileHighlightData::window_number
WindowNumber window_number
The WindowNumber of the window that is responsible for the selection mode.
Definition: tilehighlight_type.h:69
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:321
VehicleClicked
bool VehicleClicked(const Vehicle *v)
Dispatch a "vehicle selected" event if any window waits for it.
Definition: vehicle_gui.cpp:3064
VehicleModelSorter
static bool VehicleModelSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by model.
Definition: vehicle_gui.cpp:1284
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:240
VehicleGroupAverageProfitLastYearSorter
static bool VehicleGroupAverageProfitLastYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the average profit last year.
Definition: vehicle_gui.cpp:1197
BaseVehicleListWindow
Definition: vehicle_gui_base.h:70
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
VehicleProfitThisYearSorter
static bool VehicleProfitThisYearSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by this year profit.
Definition: vehicle_gui.cpp:1237
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:55
ZOOM_LVL_ROADVEH
@ ZOOM_LVL_ROADVEH
Default zoom level for the road vehicle view.
Definition: zoom_type.h:42
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
WID_VL_SORT_BY_PULLDOWN
@ WID_VL_SORT_BY_PULLDOWN
Sort by dropdown list.
Definition: vehicle_widget.h:68
VehicleViewWindow::OnMouseOver
void OnMouseOver(Point pt, int widget) override
The mouse is currently moving over the window or has just moved outside of the window.
Definition: vehicle_gui.cpp:2983
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:130
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:297
RefitOption::operator!=
bool operator!=(const RefitOption &other) const
Inequality operator for RefitOption.
Definition: vehicle_gui.cpp:391
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:37
CMD_CHANGE_SERVICE_INT
@ CMD_CHANGE_SERVICE_INT
change the server interval of a vehicle
Definition: command_type.h:230
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:128
WID_VV_RENAME
@ WID_VV_RENAME
Rename vehicle.
Definition: vehicle_widget.h:18
SpecializedStation< Station, false >::IsExpected
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
Definition: base_station_base.h:200
VehicleMaxSpeedSorter
static bool VehicleMaxSpeedSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their max speed.
Definition: vehicle_gui.cpp:1277
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
DrawTrainImage
void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
Draws an image of a whole train.
Definition: train_gui.cpp:92
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:159
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
vehicle_gui_base.h
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:124
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:327
_cargo_mask
CargoTypes _cargo_mask
Bitmask of cargo types available.
Definition: cargotype.cpp:28
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
Window::OnVehicleSelect
virtual bool OnVehicleSelect(const struct Vehicle *v)
The user clicked on a vehicle while HT_VEHICLE has been set.
Definition: window_gui.h:761
WID_VL_MANAGE_VEHICLES_DROPDOWN
@ WID_VL_MANAGE_VEHICLES_DROPDOWN
Manage vehicles dropdown list.
Definition: vehicle_widget.h:73
Vehicle::max_age
Date max_age
Maximum age.
Definition: vehicle_base.h:269
RefitWindow::vscroll
Scrollbar * vscroll
The main scrollbar.
Definition: vehicle_gui.cpp:480
SPR_CLONE_TRAIN
static const SpriteID SPR_CLONE_TRAIN
Clone vehicles stuff.
Definition: sprites.h:100
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:447
GetVehicleListHeight
uint GetVehicleListHeight(VehicleType type, uint divisor)
Get the height of a vehicle in the vehicle list GUIs.
Definition: vehicle_gui.cpp:1490
SetMatrixDataTip
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1041
VehicleListIdentifier::Pack
uint32 Pack() const
Pack a VehicleListIdentifier in a single uint32.
Definition: vehiclelist.cpp:21
VehicleTimetableDelaySorter
static bool VehicleTimetableDelaySorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by the timetable delay.
Definition: vehicle_gui.cpp:1318
WID_VD_TOP_DETAILS
@ WID_VD_TOP_DETAILS
Panel with generic details.
Definition: vehicle_widget.h:48
ODATFB_NEAREST_DEPOT
@ ODATFB_NEAREST_DEPOT
Send the vehicle to the nearest depot.
Definition: order_type.h:105
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
RefitWindow::hscroll
Scrollbar * hscroll
Only used for long vehicles.
Definition: vehicle_gui.cpp:481
VehicleViewWindow::SEL_DC_CLONE
@ SEL_DC_CLONE
Display 'clone vehicle' button in WID_VV_SELECT_DEPOT_CLONE stacked widget.
Definition: vehicle_gui.cpp:2634
VehicleListWindow::ButtonPlanes
ButtonPlanes
Enumeration of planes of the button row at the bottom.
Definition: vehicle_gui.cpp:1637
WC_VEHICLE_DETAILS
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Definition: window_type.h:193
VehicleViewWindow::ShowNewGRFInspectWindow
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
Definition: vehicle_gui.cpp:3046
ZOOM_LVL_AIRCRAFT
@ ZOOM_LVL_AIRCRAFT
Default zoom level for the aircraft view.
Definition: zoom_type.h:39
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:393
VS_STOPPED
@ VS_STOPPED
Vehicle is stopped by the player.
Definition: vehicle_base.h:31
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:338
Vehicle::GetGRFID
uint32 GetGRFID() const
Retrieve the GRF ID of the NewGRF the vehicle is tied to.
Definition: vehicle.cpp:761
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:741
WID_VV_SELECT_REFIT_TURN
@ WID_VV_SELECT_REFIT_TURN
Selection widget between 'refit' and 'turn around' buttons.
Definition: vehicle_widget.h:27
DropDownListStringItem
Common string list item.
Definition: dropdown_type.h:39
_vehicle_command_translation_table
static const uint32 _vehicle_command_translation_table[][4]
Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type.
Definition: vehicle_gui.cpp:2565
GenerateVehicleSortList
bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli)
Generate a list of vehicles based on window type.
Definition: vehiclelist.cpp:114
safeguards.h
ShowQueryString
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:1141
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:318
VehicleGroupAverageProfitThisYearSorter
static bool VehicleGroupAverageProfitThisYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the average profit this year.
Definition: vehicle_gui.cpp:1191
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:311
Train
'Train' is either a loco or a wagon.
Definition: train.h:85
DrawSmallOrderList
static void DrawSmallOrderList(const Order *order, int left, int right, int y, uint order_arrow_width)
Draw small order list in the vehicle GUI, but without the little black arrow.
Definition: vehicle_gui.cpp:1446
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:82
DEFAULT_GROUP
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Definition: group_type.h:17
WID_VD_MATRIX
@ WID_VD_MATRIX
List of details for trains.
Definition: vehicle_widget.h:54
DepotCommand
DepotCommand
Flags to add to p1 for goto depot commands.
Definition: vehicle_type.h:65
GetGRFStringID
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition: newgrf_text.cpp:602
GroundVehicleCache::cached_max_te
uint32 cached_max_te
Maximum tractive effort of consist (valid only for the first engine).
Definition: ground_vehicle.hpp:33
WindowClass
WindowClass
Window classes.
Definition: window_type.h:37
SetMouseCursorVehicle
void SetMouseCursorVehicle(const Vehicle *v, EngineImageType image_type)
Set the mouse cursor to look like a vehicle.
Definition: vehicle_gui.cpp:3148
RefitWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: vehicle_gui.cpp:813
VehicleListWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: vehicle_gui.cpp:1674
DrawSprite
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:978
VehicleViewWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: vehicle_gui.cpp:2730
newgrf_text.h
ZOOM_LVL_SHIP
@ ZOOM_LVL_SHIP
Default zoom level for the ship view.
Definition: zoom_type.h:40
WID_VL_HIDE_BUTTONS
@ WID_VL_HIDE_BUTTONS
Selection to hide the buttons.
Definition: vehicle_widget.h:71
VehicleDefaultSettings
Default settings for vehicles.
Definition: settings_type.h:544
RefitWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: vehicle_gui.cpp:1072
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
ScrollMainWindowTo
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
Definition: smallmap_gui.cpp:1869
WID_VR_SCROLLBAR
@ WID_VR_SCROLLBAR
Scrollbar for the refit options.
Definition: vehicle_widget.h:40
DrawShipImage
void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type)
Draws an image of a ship.
Definition: ship_gui.cpp:32
VehicleViewWindow::SEL_RT_BASEPLANE
@ SEL_RT_BASEPLANE
First plane of the WID_VV_SELECT_REFIT_TURN stacked widget.
Definition: vehicle_gui.cpp:2640
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition: window_type.h:301
GetSingleVehicleWidth
int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type)
Get the width of a vehicle (part) in pixels.
Definition: vehicle_gui.cpp:3106
WID_VR_INFO
@ WID_VR_INFO
Information about the currently selected refit option.
Definition: vehicle_widget.h:41
WID_VL_GROUP_ORDER
@ WID_VL_GROUP_ORDER
Group order.
Definition: vehicle_widget.h:65
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:488
RefitWindow::sprite_right
int sprite_right
Right position of the vehicle sprite.
Definition: vehicle_gui.cpp:484
DAYS_IN_LEAP_YEAR
static const int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
Definition: date_type.h:30
WID_VV_CAPTION
@ WID_VV_CAPTION
Caption of window.
Definition: vehicle_widget.h:15
stdafx.h
WID_VD_CAPTION
@ WID_VD_CAPTION
Caption of window.
Definition: vehicle_widget.h:47
WID_VV_START_STOP
@ WID_VV_START_STOP
Start or stop this vehicle, and show information about the current state.
Definition: vehicle_widget.h:17
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:313
WID_VV_CLONE
@ WID_VV_CLONE
Clone this vehicle.
Definition: vehicle_widget.h:25
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:218
ChangeVehicleWindow
static void ChangeVehicleWindow(WindowClass window_class, VehicleID from_index, VehicleID to_index)
Assign a vehicle window a new vehicle.
Definition: vehicle_gui.cpp:1336
GUIList::ToggleSortOrder
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
Definition: sortlist_type.h:233
GUIList::NeedResort
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
Definition: sortlist_type.h:199
VehicleValueSorter
static bool VehicleValueSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their value.
Definition: vehicle_gui.cpp:1291
VehicleListType
VehicleListType
Vehicle List type flags.
Definition: vehiclelist.h:19
RefitWindow::order
VehicleOrderID order
If not INVALID_VEH_ORDER_ID, selection is part of a refit order (rather than execute directly).
Definition: vehicle_gui.cpp:478
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3261
NWidgetStacked::SetDisplayedPlane
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1091
EngineInfo::misc_flags
byte misc_flags
Miscellaneous flags.
Definition: engine_type.h:142
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:27
viewport_func.h
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:183
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:414
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
RefitOption::string
StringID string
GRF-local String to display for the cargo.
Definition: vehicle_gui.cpp:384
VehicleViewWindow::SEL_RT_REFIT
@ SEL_RT_REFIT
Display 'refit' button in WID_VV_SELECT_REFIT_TURN stacked widget.
Definition: vehicle_gui.cpp:2636
GetDigitWidth
byte GetDigitWidth(FontSize size)
Return the maximum width of single digit.
Definition: gfx.cpp:1308
ODATFB_HALT
@ ODATFB_HALT
Service the vehicle and then halt it.
Definition: order_type.h:104
WC_VEHICLE_REFIT
@ WC_VEHICLE_REFIT
Vehicle refit; Window numbers:
Definition: window_type.h:199
_returned_refit_capacity
uint _returned_refit_capacity
Stores the capacity after a refit operation.
Definition: vehicle.cpp:85
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
WID_VD_DECREASE_SERVICING_INTERVAL
@ WID_VD_DECREASE_SERVICING_INTERVAL
Decrease the servicing interval.
Definition: vehicle_widget.h:50
VehicleListIdentifier::index
uint32 index
A vehicle list type specific index.
Definition: vehiclelist.h:33
HT_VEHICLE
@ HT_VEHICLE
vehicle is accepted as target as well (bitmask)
Definition: tilehighlight_type.h:27
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:176
GetCargoSubtypeText
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
Definition: vehicle_gui.cpp:1157
HT_DRAG
@ HT_DRAG
dragging items in the depot windows
Definition: tilehighlight_type.h:24
VIWD_CONSIST_CHANGED
@ VIWD_CONSIST_CHANGED
Vehicle composition was changed.
Definition: vehicle_gui.h:34
VehicleLengthSorter
static bool VehicleLengthSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their length.
Definition: vehicle_gui.cpp:1304
WID_VD_DETAILS_TOTAL_CARGO
@ WID_VD_DETAILS_TOTAL_CARGO
Show the capacity and carried cargo amounts aggregated per cargo of the train.
Definition: vehicle_widget.h:59
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:913
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
Vehicle::list
OrderList * list
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:330
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:28
CMD_START_STOP_VEHICLE
@ CMD_START_STOP_VEHICLE
start or stop a vehicle
Definition: command_type.h:315
TileHighlightData::place_mode
HighLightStyle place_mode
Method which is used to place the selection.
Definition: tilehighlight_type.h:67
BaseVehicleListWindow::DrawVehicleListItems
void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const
Draw all the vehicle list items.
Definition: vehicle_gui.cpp:1510
GetWindowClassForVehicleType
static WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
Definition: vehicle_gui.h:91
WD_DROPDOWNTEXT_TOP
@ WD_DROPDOWNTEXT_TOP
Top offset of the dropdown widget string.
Definition: window_gui.h:134
RefitOption::operator==
bool operator==(const RefitOption &other) const
Equality operator for RefitOption.
Definition: vehicle_gui.cpp:401
string_func.h
VAF_DEST_TOO_FAR
@ VAF_DEST_TOO_FAR
Next destination is too far away.
Definition: aircraft.h:39
spritecache.h
VehicleDetailsWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: vehicle_gui.cpp:2424
Vehicle::FirstShared
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:686
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:404
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:103
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:224
WID_VV_SELECT_DEPOT_CLONE
@ WID_VV_SELECT_DEPOT_CLONE
Selection widget between 'goto depot', and 'clone vehicle' buttons.
Definition: vehicle_widget.h:26
Vehicle::vcache
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:339
EIT_IN_LIST
@ EIT_IN_LIST
Vehicle drawn in vehicle list, group list, ...
Definition: vehicle_type.h:89
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1008
RefitWindow::RefreshScrollbar
void RefreshScrollbar()
Refresh scrollbar after selection changed.
Definition: vehicle_gui.cpp:603
DEPOT_SERVICE
@ DEPOT_SERVICE
The vehicle will leave the depot right after arrival (service only)
Definition: vehicle_type.h:66
VehicleDetailsWindow
Class for managing the vehicle details window.
Definition: vehicle_gui.cpp:2089
station_base.h
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
WID_VV_LOCATION
@ WID_VV_LOCATION
Center the main view on this vehicle.
Definition: vehicle_widget.h:19
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1594
GetVehicleWidth
int GetVehicleWidth(const Vehicle *v, EngineImageType image_type)
Get the width of a vehicle (including all parts of the consist) in pixels.
Definition: vehicle_gui.cpp:3130
CMD_FORCE_TRAIN_PROCEED
@ CMD_FORCE_TRAIN_PROCEED
proceed a train to pass a red signal
Definition: command_type.h:221
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
CMD_CLONE_VEHICLE
@ CMD_CLONE_VEHICLE
clone a vehicle
Definition: command_type.h:314
_train_vehicle_details_desc
static WindowDesc _train_vehicle_details_desc(WDP_AUTO, "view_vehicle_details_train", 405, 178, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, 0, _nested_train_vehicle_details_widgets, lengthof(_nested_train_vehicle_details_widgets))
Vehicle details window descriptor.
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:605
DeleteWindowById
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1165
Sorting
Definition: vehicle_gui_base.h:146
RefitWindow::vehicle_margin
uint vehicle_margin
Margin to use while selecting vehicles when the vehicle image is centered.
Definition: vehicle_gui.cpp:485
DrawRoadVehImage
void DrawRoadVehImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip)
Draws an image of a road vehicle chain.
Definition: roadveh_gui.cpp:129
BaseConsist::lateness_counter
int32 lateness_counter
How many ticks late (or early if negative) this vehicle is.
Definition: base_consist.h:23
Vehicle::cargo_cap
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:316
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:169
VehicleDetailsWindow::OnPaint
void OnPaint() override
Repaint vehicle details window.
Definition: vehicle_gui.cpp:2361
GUIVehicleGroup
Definition: vehicle_gui_base.h:27
MAX_LENGTH_VEHICLE_NAME_CHARS
static const uint MAX_LENGTH_VEHICLE_NAME_CHARS
The maximum length of a vehicle name in characters including '\0'.
Definition: vehicle_type.h:73
RoadVehicle::GetDisplayImageWidth
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a road vehicle image in the GUI.
Definition: roadveh_cmd.cpp:90
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:185
GroundVehicleCache::cached_power
uint32 cached_power
Total power of the consist (valid only for the first engine).
Definition: ground_vehicle.hpp:38
WID_VD_DETAILS_CARGO_CARRIED
@ WID_VD_DETAILS_CARGO_CARRIED
Show carried cargo per part of the train.
Definition: vehicle_widget.h:56
VehicleDefaultSettings::servint_trains
uint16 servint_trains
service interval for trains
Definition: settings_type.h:546
CMD_MASS_START_STOP
@ CMD_MASS_START_STOP
start/stop all vehicles (in a depot)
Definition: command_type.h:316
VehicleViewWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: vehicle_gui.cpp:2782
HideDropDownMenu
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
Definition: dropdown.cpp:506
BaseVehicleListWindow::vehgroups
GUIVehicleGroupList vehgroups
List of (groups of) vehicles. This stores iterators of vehicles, and should be rebuilt if vehicles is...
Definition: vehicle_gui_base.h:81
WIDGET_LIST_END
static const int WIDGET_LIST_END
indicate the end of widgets' list for vararg functions
Definition: widget_type.h:20
TDW_TAB_CAPACITY
@ TDW_TAB_CAPACITY
Tab with cargo capacity of the vehicles.
Definition: vehicle_gui.h:26
ShowReplaceGroupVehicleWindow
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
Definition: autoreplace_gui.cpp:834
VehicleViewWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: vehicle_gui.cpp:2976
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1162
GetVehiclePalette
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
Definition: vehicle.cpp:2044
VehicleSettings::roadveh_acceleration_model
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
Definition: settings_type.h:467
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
VehicleListIdentifier::vtype
VehicleType vtype
The vehicle type associated with this list.
Definition: vehiclelist.h:31
Vehicle::GetFirstEnginePart
Vehicle * GetFirstEnginePart()
Get the first part of an articulated engine.
Definition: vehicle_base.h:933
VIWD_AUTOREPLACE
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
Definition: vehicle_gui.h:35
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:76
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1123
geometry_func.hpp
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
SetDParamMaxValue
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:104
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:956
WID_VR_VEHICLE_PANEL_DISPLAY
@ WID_VR_VEHICLE_PANEL_DISPLAY
Display with a representation of the vehicle to refit.
Definition: vehicle_widget.h:35
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
GetBestFittingSubType
byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type)
Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.
Definition: vehicle_gui.cpp:317
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition: sortlist_type.h:116
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
VehicleListIdentifier::type
VehicleListType type
The type of vehicle list.
Definition: vehiclelist.h:30
Window::SetWidgetsDisabledState
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:536
Vehicle::orders
union Vehicle::@51 orders
The orders currently assigned to the vehicle.
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:494
RefitWindow
Refit cargo window.
Definition: vehicle_gui.cpp:474
Vehicle::age
Date age
Age in days.
Definition: vehicle_base.h:268
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:64
VehicleDefaultSettings::servint_aircraft
uint16 servint_aircraft
service interval for aircraft
Definition: settings_type.h:548
GetStationIndex
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:28
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:913
VehicleNumberSorter
static bool VehicleNumberSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their number.
Definition: vehicle_gui.cpp:1203
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:640
VehicleViewWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: vehicle_gui.cpp:2774
WD_IMGBTN_TOP
@ WD_IMGBTN_TOP
Top offset of image in the button.
Definition: window_gui.h:40
DAYS_IN_YEAR
static const int DAYS_IN_YEAR
days per year
Definition: date_type.h:29
VehicleCargoSorter
static bool VehicleCargoSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their cargo.
Definition: vehicle_gui.cpp:1251
VehicleViewWindow::IsNewGRFInspectable
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
Definition: vehicle_gui.cpp:3041
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:70
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:44
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1848
_nested_vehicle_view_widgets
static const NWidgetPart _nested_vehicle_view_widgets[]
Vehicle view widgets.
Definition: vehicle_gui.cpp:2475
Vehicle::unitnumber
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:300
depot_map.h
VehicleTimeToLiveSorter
static bool VehicleTimeToLiveSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by the time they can still live.
Definition: vehicle_gui.cpp:1311
VehicleCache::cached_max_speed
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition: vehicle_base.h:121
VehicleDetailsWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: vehicle_gui.cpp:2151
company_func.h
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:49
ShowRefitOptionsList
uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
Display list of cargo types of the engine, for the purchase information window.
Definition: vehicle_gui.cpp:1128
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:213
ZOOM_LVL_TRAIN
@ ZOOM_LVL_TRAIN
Default zoom level for the train view.
Definition: zoom_type.h:41
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
VehicleViewWindow
Window manager class for viewing a vehicle.
Definition: vehicle_gui.cpp:2629
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:175
Vehicle::InvalidateNewGRFCache
void InvalidateNewGRFCache()
Invalidates cached NewGRF variables.
Definition: vehicle_base.h:462
NWidgetBase::SetDirty
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:773
VehicleListWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: vehicle_gui.cpp:1754
VehicleListIdentifier::UnPack
static VehicleListIdentifier UnPack(uint32 data)
Decode a packed vehicle list identifier into a new one.
Definition: vehiclelist.cpp:53
OrderList::GetFirstOrder
Order * GetFirstOrder() const
Get the first order of the order chain.
Definition: order_base.h:290
ViewportData::follow_vehicle
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Definition: window_gui.h:257
WD_MATRIX_BOTTOM
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
Definition: window_gui.h:79
ShowVehicleViewWindow
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
Definition: vehicle_gui.cpp:3054
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
BaseVehicleListWindow::vehicles
VehicleList vehicles
List of vehicles. This is the buffer for vehgroups to point into; if this is structurally modified,...
Definition: vehicle_gui_base.h:80
WID_VD_SCROLLBAR
@ WID_VD_SCROLLBAR
Scrollbar for train details.
Definition: vehicle_widget.h:55
CursorVars::sprite_seq
PalSpriteID sprite_seq[16]
current image of cursor
Definition: gfx_type.h:128
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:369
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:320
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:33
Scrollbar::SetCapacityFromWidget
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:1986
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:656
RefitWindow::OnMouseDrag
void OnMouseDrag(Point pt, int widget) override
An 'object' is being dragged at the provided position, highlight the target if possible.
Definition: vehicle_gui.cpp:1046
TileHighlightData::window_class
WindowClass window_class
The WindowClass of the window that is responsible for the selection mode.
Definition: tilehighlight_type.h:68
RefitOption::cargo
CargoID cargo
Cargo to refit to.
Definition: vehicle_gui.cpp:382
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
_nontrain_vehicle_details_desc
static WindowDesc _nontrain_vehicle_details_desc(WDP_AUTO, "view_vehicle_details", 405, 113, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, 0, _nested_nontrain_vehicle_details_widgets, lengthof(_nested_nontrain_vehicle_details_widgets))
Vehicle details window descriptor for other vehicles than a train.
VehicleNameSorter
static bool VehicleNameSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their name.
Definition: vehicle_gui.cpp:1209
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
Vehicle::IsStoppedInDepot
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
Definition: vehicle_base.h:527
ToPercent16
static uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
Definition: math_func.hpp:238
MemSetT
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
Definition: mem_func.hpp:49
TFP_SIGNAL
@ TFP_SIGNAL
Ignore next signal, after the signal ignore being stuck.
Definition: train.h:40
VehicleListWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: vehicle_gui.cpp:1925
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:88
CcCloneVehicle
void CcCloneVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
This is the Callback method after the cloning attempt of a vehicle.
Definition: depot_gui.cpp:120
SetObjectToPlaceWnd
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:3358
VehicleDefaultSettings::servint_roadveh
uint16 servint_roadveh
service interval for road vehicles
Definition: settings_type.h:547
RefitWindow::vehicle_width
int vehicle_width
Width of the vehicle being drawn.
Definition: vehicle_gui.cpp:482
strnatcmp
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:643
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:314
RefitWindow::OnDragDrop
void OnDragDrop(Point pt, int widget) override
A dragged 'object' has been released.
Definition: vehicle_gui.cpp:1059
IsNewGRFInspectable
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
Definition: newgrf_debug_gui.cpp:756
VehicleDetailsWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: vehicle_gui.cpp:2263
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:992
MAX_REFIT_CYCLE
static const uint MAX_REFIT_CYCLE
Maximum number of refit cycles we try, to prevent infinite loops.
Definition: vehicle_gui.cpp:306
Order::GetLocation
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:680
DrawTrainDetails
void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab)
Draw the details for the given vehicle at the given position.
Definition: train_gui.cpp:361
gui.h
VehicleIndividualToGroupSorterWrapper
static bool VehicleIndividualToGroupSorterWrapper(GUIVehicleGroup const &a, GUIVehicleGroup const &b)
Wrapper to convert a VehicleIndividualSortFunction to a VehicleGroupSortFunction.
Definition: vehicle_gui.cpp:67
SPR_CURSOR_MOUSE
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1374
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
BaseVehicleListWindow::unitnumber_digits
byte unitnumber_digits
The number of digits of the highest unit number.
Definition: vehicle_gui_base.h:83
GUISettings::advanced_vehicle_list
uint8 advanced_vehicle_list
use the "advanced" vehicle list
Definition: settings_type.h:111
WD_DROPDOWNTEXT_BOTTOM
@ WD_DROPDOWNTEXT_BOTTOM
Bottom offset of the dropdown widget string.
Definition: window_gui.h:135
articulated_vehicles.h
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:572
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition: newgrf_commons.cpp:516
Vehicle::cargo_subtype
byte cargo_subtype
Used for livery refits (NewGRF variations)
Definition: vehicle_base.h:315
DrawAircraftDetails
void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
Draw the details for the given vehicle at the given position.
Definition: aircraft_gui.cpp:32
IsEngineRefittable
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Definition: engine.cpp:1168
Window
Data structure for an opened window.
Definition: window_gui.h:277
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
DrawShipDetails
void DrawShipDetails(const Vehicle *v, int left, int right, int y)
Draw the details for the given vehicle at the given position.
Definition: ship_gui.cpp:64
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:318
WD_MATRIX_LEFT
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
Definition: window_gui.h:76
Vehicle::GetOrder
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
Definition: vehicle_base.h:872
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
RefitWindow::BuildRefitList
void BuildRefitList()
Collects all (cargo, subcargo) refit options of a vehicle chain.
Definition: vehicle_gui.cpp:494
ZOOM_LVL_OUT_4X
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
Definition: zoom_type.h:26
Vehicle::reliability
uint16 reliability
Reliability.
Definition: vehicle_base.h:271
DC_QUERY_COST
@ DC_QUERY_COST
query cost only, don't build.
Definition: command_type.h:350
VehicleProfitLastYearSorter
static bool VehicleProfitLastYearSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by last year profit.
Definition: vehicle_gui.cpp:1244
DrawVehicleProfitButton
static void DrawVehicleProfitButton(Date age, Money display_profit_last_year, uint num_vehicles, int x, int y)
draw the vehicle profit button in the vehicle list window.
Definition: vehicle_gui.cpp:288
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:225
WD_IMGBTN_LEFT
@ WD_IMGBTN_LEFT
Left offset of the image in the button.
Definition: window_gui.h:38
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:292
WID_VD_INCREASE_SERVICING_INTERVAL
@ WID_VD_INCREASE_SERVICING_INTERVAL
Increase the servicing interval.
Definition: vehicle_widget.h:49
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
WID_VV_ORDER_LOCATION
@ WID_VV_ORDER_LOCATION
Center the main view on the order's target location.
Definition: vehicle_widget.h:20
WWT_DEBUGBOX
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition: widget_type.h:61
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
RefitWindow::cargo
RefitOption * cargo
Refit option selected by sel.
Definition: vehicle_gui.cpp:476
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
WID_VV_GOTO_DEPOT
@ WID_VV_GOTO_DEPOT
Order this vehicle to go to the depot.
Definition: vehicle_widget.h:21
DrawAircraftImage
void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type)
Draws an image of an aircraft.
Definition: aircraft_gui.cpp:80
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:36
VehicleSpriteSeq::GetBounds
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Definition: vehicle.cpp:98
Order::GetDepotActionType
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
Definition: order_base.h:137
WID_VD_SERVICING_INTERVAL
@ WID_VD_SERVICING_INTERVAL
Information about the servicing interval.
Definition: vehicle_widget.h:52
ShowVehicleRefitWindow
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
Show the refit window for a vehicle.
Definition: vehicle_gui.cpp:1120
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
RefitWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: vehicle_gui.cpp:692
Window::DisableWidget
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:403
CMD_RENAME_VEHICLE
@ CMD_RENAME_VEHICLE
rename a whole vehicle
Definition: command_type.h:244
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:182
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:385
NWidgetStacked::shown_plane
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:429
WID_VR_SELECT_HEADER
@ WID_VR_SELECT_HEADER
Header with question about the cargo to carry.
Definition: vehicle_widget.h:38
Order::next
Order * next
Pointer to next order. If nullptr, end of list.
Definition: order_base.h:49
Order
Definition: order_base.h:32
WID_VV_REFIT
@ WID_VV_REFIT
Open the refit window.
Definition: vehicle_widget.h:22
RefitWindow::SetSelection
void SetSelection(uint click_row)
Select a row.
Definition: vehicle_gui.cpp:629
GroundVehicleCache::cached_weight
uint32 cached_weight
Total weight of the consist (valid only for the first engine).
Definition: ground_vehicle.hpp:31
WD_IMGBTN_RIGHT
@ WD_IMGBTN_RIGHT
Right offset of the image in the button.
Definition: window_gui.h:39
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:454
RefitWindow::GetCapacityString
StringID GetCapacityString(RefitOption *option) const
Gets the StringID to use for displaying capacity.
Definition: vehicle_gui.cpp:772
Engine::GetAircraftTypeText
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
Definition: engine.cpp:466
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
DAY_TICKS
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Definition: date_type.h:28
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
Vehicle::GetDisplayProfitLastYear
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
Definition: vehicle_base.h:583
VehicleListWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: vehicle_gui.cpp:1905
DrawVehicleRefitWindow
static void DrawVehicleRefitWindow(const SubtypeList list[NUM_CARGO], const int sel[2], uint pos, uint rows, uint delta, const Rect &r)
Draw the list of available refit options for a consist and highlight the selected refit option (if an...
Definition: vehicle_gui.cpp:418
RefitOption
Option to refit a vehicle chain.
Definition: vehicle_gui.cpp:381
VehicleReliabilitySorter
static bool VehicleReliabilitySorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their reliability.
Definition: vehicle_gui.cpp:1270
GetDepotIndex
static DepotID GetDepotIndex(TileIndex t)
Get the index of which depot is attached to the tile.
Definition: depot_map.h:52
GetTrainDetailsWndVScroll
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
Determines the number of lines in the train details window.
Definition: train_gui.cpp:318
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
WC_VEHICLE_ORDERS
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
Definition: window_type.h:205
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:581
debug.h
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:28
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:35
Vehicle::date_of_last_service
Date date_of_last_service
Last date the vehicle had a service at a depot.
Definition: vehicle_base.h:270
SetMinimalTextLines
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:974
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:68
TileHighlightData::GetCallbackWnd
Window * GetCallbackWnd()
Get the window that started the current highlighting.
Definition: viewport.cpp:2516
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:270
VEHICLE_PROFIT_MIN_AGE
static const int VEHICLE_PROFIT_MIN_AGE
Only vehicles older than this have a meaningful profit.
Definition: vehicle_func.h:27
VEHICLE_PROFIT_THRESHOLD
static const Money VEHICLE_PROFIT_THRESHOLD
Threshold for a vehicle to be considered making good profit.
Definition: vehicle_func.h:28
engine_func.h
TileVirtXY
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:194
VehicleDetailsWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: vehicle_gui.cpp:2438
roadveh.h
TDW_TAB_CARGO
@ TDW_TAB_CARGO
Tab with cargo carried by the vehicles.
Definition: vehicle_gui.h:24
RefitWindow::GetRefitOption
RefitOption * GetRefitOption()
Gets the RefitOption placed in the selected index.
Definition: vehicle_gui.cpp:658
SubtypeList
std::vector< RefitOption > SubtypeList
List of refit subtypes associated to a cargo.
Definition: vehicle_gui.cpp:407
_nested_train_vehicle_details_widgets
static const NWidgetPart _nested_train_vehicle_details_widgets[]
Train details widgets.
Definition: vehicle_gui.cpp:2039
MAX_YEAR
static const Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
Definition: date_type.h:94
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
Vehicle::GetImage
virtual void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Definition: vehicle_base.h:453