OpenTTD Source  13.0-beta1
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 #include "depot_cmd.h"
40 #include "vehicle_cmd.h"
41 #include "order_cmd.h"
42 #include "roadveh_cmd.h"
43 #include "train_cmd.h"
44 
45 #include "safeguards.h"
46 
47 
48 BaseVehicleListWindow::GroupBy _grouping[VLT_END][VEH_COMPANY_END];
49 Sorting _sorting[BaseVehicleListWindow::GB_END];
50 
51 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleNumberSorter;
52 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleNameSorter;
53 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleAgeSorter;
54 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleProfitThisYearSorter;
55 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleProfitLastYearSorter;
56 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleCargoSorter;
57 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleReliabilitySorter;
58 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleMaxSpeedSorter;
59 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleModelSorter;
60 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleValueSorter;
61 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleLengthSorter;
62 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleTimeToLiveSorter;
63 static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleTimetableDelaySorter;
64 static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupLengthSorter;
65 static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupTotalProfitThisYearSorter;
66 static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupTotalProfitLastYearSorter;
67 static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupAverageProfitThisYearSorter;
68 static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupAverageProfitLastYearSorter;
69 
71 template <BaseVehicleListWindow::VehicleIndividualSortFunction func>
73 {
74  return func(*(a.vehicles_begin), *(b.vehicles_begin));
75 }
76 
77 BaseVehicleListWindow::VehicleGroupSortFunction * const BaseVehicleListWindow::vehicle_group_none_sorter_funcs[] = {
78  &VehicleIndividualToGroupSorterWrapper<VehicleNumberSorter>,
79  &VehicleIndividualToGroupSorterWrapper<VehicleNameSorter>,
80  &VehicleIndividualToGroupSorterWrapper<VehicleAgeSorter>,
81  &VehicleIndividualToGroupSorterWrapper<VehicleProfitThisYearSorter>,
82  &VehicleIndividualToGroupSorterWrapper<VehicleProfitLastYearSorter>,
83  &VehicleIndividualToGroupSorterWrapper<VehicleCargoSorter>,
84  &VehicleIndividualToGroupSorterWrapper<VehicleReliabilitySorter>,
85  &VehicleIndividualToGroupSorterWrapper<VehicleMaxSpeedSorter>,
86  &VehicleIndividualToGroupSorterWrapper<VehicleModelSorter>,
87  &VehicleIndividualToGroupSorterWrapper<VehicleValueSorter>,
88  &VehicleIndividualToGroupSorterWrapper<VehicleLengthSorter>,
89  &VehicleIndividualToGroupSorterWrapper<VehicleTimeToLiveSorter>,
90  &VehicleIndividualToGroupSorterWrapper<VehicleTimetableDelaySorter>,
91 };
92 
93 const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names[] = {
94  STR_SORT_BY_NUMBER,
95  STR_SORT_BY_NAME,
96  STR_SORT_BY_AGE,
97  STR_SORT_BY_PROFIT_THIS_YEAR,
98  STR_SORT_BY_PROFIT_LAST_YEAR,
99  STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE,
100  STR_SORT_BY_RELIABILITY,
101  STR_SORT_BY_MAX_SPEED,
102  STR_SORT_BY_MODEL,
103  STR_SORT_BY_VALUE,
104  STR_SORT_BY_LENGTH,
105  STR_SORT_BY_LIFE_TIME,
106  STR_SORT_BY_TIMETABLE_DELAY,
108 };
109 
110 BaseVehicleListWindow::VehicleGroupSortFunction * const BaseVehicleListWindow::vehicle_group_shared_orders_sorter_funcs[] = {
116 };
117 
118 const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names[] = {
119  STR_SORT_BY_NUM_VEHICLES,
120  STR_SORT_BY_TOTAL_PROFIT_THIS_YEAR,
121  STR_SORT_BY_TOTAL_PROFIT_LAST_YEAR,
122  STR_SORT_BY_AVERAGE_PROFIT_THIS_YEAR,
123  STR_SORT_BY_AVERAGE_PROFIT_LAST_YEAR,
125 };
126 
127 const StringID BaseVehicleListWindow::vehicle_group_by_names[] = {
128  STR_GROUP_BY_NONE,
129  STR_GROUP_BY_SHARED_ORDERS,
131 };
132 
133 const StringID BaseVehicleListWindow::vehicle_depot_name[] = {
134  STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT,
135  STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT,
136  STR_VEHICLE_LIST_SEND_SHIP_TO_DEPOT,
137  STR_VEHICLE_LIST_SEND_AIRCRAFT_TO_HANGAR
138 };
139 
140 BaseVehicleListWindow::BaseVehicleListWindow(WindowDesc *desc, WindowNumber wno) : Window(desc), vli(VehicleListIdentifier::UnPack(wno))
141 {
142  this->grouping = _grouping[vli.type][vli.vtype];
143  this->UpdateSortingFromGrouping();
144 }
145 
152 {
153  if (number >= 10000) return 5;
154  if (number >= 1000) return 4;
155  if (number >= 100) return 3;
156 
157  /*
158  * When the smallest unit number is less than 10, it is
159  * quite likely that it will expand to become more than
160  * 10 quite soon.
161  */
162  return 2;
163 }
164 
171 {
172  uint unitnumber = 0;
173  for (const Vehicle *v : vehicles) {
174  unitnumber = std::max<uint>(unitnumber, v->unitnumber);
175  }
176 
177  return CountDigitsForAllocatingSpace(unitnumber);
178 }
179 
180 void BaseVehicleListWindow::BuildVehicleList()
181 {
182  if (!this->vehgroups.NeedRebuild()) return;
183 
184  Debug(misc, 3, "Building vehicle list type {} for company {} given index {}", this->vli.type, this->vli.company, this->vli.index);
185 
186  this->vehgroups.clear();
187 
188  GenerateVehicleSortList(&this->vehicles, this->vli);
189 
190  if (this->grouping == GB_NONE) {
191  uint max_unitnumber = 0;
192  for (auto it = this->vehicles.begin(); it != this->vehicles.end(); ++it) {
193  this->vehgroups.emplace_back(it, it + 1);
194 
195  max_unitnumber = std::max<uint>(max_unitnumber, (*it)->unitnumber);
196  }
197  this->unitnumber_digits = CountDigitsForAllocatingSpace(max_unitnumber);
198  } else {
199  /* Sort by the primary vehicle; we just want all vehicles that share the same orders to form a contiguous range. */
200  std::stable_sort(this->vehicles.begin(), this->vehicles.end(), [](const Vehicle * const &u, const Vehicle * const &v) {
201  return u->FirstShared() < v->FirstShared();
202  });
203 
204  uint max_num_vehicles = 0;
205 
206  VehicleList::const_iterator begin = this->vehicles.begin();
207  while (begin != this->vehicles.end()) {
208  VehicleList::const_iterator end = std::find_if_not(begin, this->vehicles.cend(), [first_shared = (*begin)->FirstShared()](const Vehicle * const &v) {
209  return v->FirstShared() == first_shared;
210  });
211 
212  this->vehgroups.emplace_back(begin, end);
213 
214  max_num_vehicles = std::max<uint>(max_num_vehicles, static_cast<uint>(end - begin));
215 
216  begin = end;
217  }
218 
219  this->unitnumber_digits = CountDigitsForAllocatingSpace(max_num_vehicles);
220  }
221 
222  this->vehgroups.RebuildDone();
223  this->vscroll->SetCount(static_cast<int>(this->vehgroups.size()));
224 }
225 
232 Dimension BaseVehicleListWindow::GetActionDropdownSize(bool show_autoreplace, bool show_group)
233 {
234  Dimension d = {0, 0};
235 
236  if (show_autoreplace) d = maxdim(d, GetStringBoundingBox(STR_VEHICLE_LIST_REPLACE_VEHICLES));
237  d = maxdim(d, GetStringBoundingBox(STR_VEHICLE_LIST_SEND_FOR_SERVICING));
238  d = maxdim(d, GetStringBoundingBox(this->vehicle_depot_name[this->vli.vtype]));
239 
240  if (show_group) {
241  d = maxdim(d, GetStringBoundingBox(STR_GROUP_ADD_SHARED_VEHICLE));
242  d = maxdim(d, GetStringBoundingBox(STR_GROUP_REMOVE_ALL_VEHICLES));
243  }
244 
245  return d;
246 }
247 
249 {
250  this->order_arrow_width = GetStringBoundingBox(STR_TINY_RIGHT_ARROW).width;
251 }
252 
259 DropDownList BaseVehicleListWindow::BuildActionDropdownList(bool show_autoreplace, bool show_group)
260 {
261  DropDownList list;
262 
263  if (show_autoreplace) list.emplace_back(new DropDownListStringItem(STR_VEHICLE_LIST_REPLACE_VEHICLES, ADI_REPLACE, false));
264  list.emplace_back(new DropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, ADI_SERVICE, false));
265  list.emplace_back(new DropDownListStringItem(this->vehicle_depot_name[this->vli.vtype], ADI_DEPOT, false));
266 
267  if (show_group) {
268  list.emplace_back(new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED, false));
269  list.emplace_back(new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, ADI_REMOVE_ALL, false));
270  }
271 
272  return list;
273 }
274 
275 /* cached values for VehicleNameSorter to spare many GetString() calls */
276 static const Vehicle *_last_vehicle[2] = { nullptr, nullptr };
277 
278 void BaseVehicleListWindow::SortVehicleList()
279 {
280  if (this->vehgroups.Sort()) return;
281 
282  /* invalidate cached values for name sorter - vehicle names could change */
283  _last_vehicle[0] = _last_vehicle[1] = nullptr;
284 }
285 
286 void DepotSortList(VehicleList *list)
287 {
288  if (list->size() < 2) return;
289  std::sort(list->begin(), list->end(), &VehicleNumberSorter);
290 }
291 
293 static void DrawVehicleProfitButton(Date age, Money display_profit_last_year, uint num_vehicles, int x, int y)
294 {
295  SpriteID spr;
296 
297  /* draw profit-based coloured icons */
298  if (age <= VEHICLE_PROFIT_MIN_AGE) {
299  spr = SPR_PROFIT_NA;
300  } else if (display_profit_last_year < 0) {
301  spr = SPR_PROFIT_NEGATIVE;
302  } else if (display_profit_last_year < VEHICLE_PROFIT_THRESHOLD * num_vehicles) {
303  spr = SPR_PROFIT_SOME;
304  } else {
305  spr = SPR_PROFIT_LOT;
306  }
307  DrawSprite(spr, PAL_NONE, x, y);
308 }
309 
311 static const uint MAX_REFIT_CYCLE = 256;
312 
322 byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type)
323 {
324  v_from = v_from->GetFirstEnginePart();
325  v_for = v_for->GetFirstEnginePart();
326 
327  /* Create a list of subtypes used by the various parts of v_for */
328  static std::vector<StringID> subtypes;
329  subtypes.clear();
330  for (; v_from != nullptr; v_from = v_from->HasArticulatedPart() ? v_from->GetNextArticulatedPart() : nullptr) {
331  const Engine *e_from = v_from->GetEngine();
332  if (!e_from->CanCarryCargo() || !HasBit(e_from->info.callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) continue;
333  include(subtypes, GetCargoSubtypeText(v_from));
334  }
335 
336  byte ret_refit_cyc = 0;
337  bool success = false;
338  if (subtypes.size() > 0) {
339  /* Check whether any articulated part is refittable to 'dest_cargo_type' with a subtype listed in 'subtypes' */
340  for (Vehicle *v = v_for; v != nullptr; v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr) {
341  const Engine *e = v->GetEngine();
342  if (!e->CanCarryCargo() || !HasBit(e->info.callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) continue;
343  if (!HasBit(e->info.refit_mask, dest_cargo_type) && v->cargo_type != dest_cargo_type) continue;
344 
345  CargoID old_cargo_type = v->cargo_type;
346  byte old_cargo_subtype = v->cargo_subtype;
347 
348  /* Set the 'destination' cargo */
349  v->cargo_type = dest_cargo_type;
350 
351  /* Cycle through the refits */
352  for (uint refit_cyc = 0; refit_cyc < MAX_REFIT_CYCLE; refit_cyc++) {
353  v->cargo_subtype = refit_cyc;
354 
355  /* Make sure we don't pick up anything cached. */
356  v->First()->InvalidateNewGRFCache();
357  v->InvalidateNewGRFCache();
358 
359  StringID subtype = GetCargoSubtypeText(v);
360  if (subtype == STR_EMPTY) break;
361 
362  if (std::find(subtypes.begin(), subtypes.end(), subtype) == subtypes.end()) continue;
363 
364  /* We found something matching. */
365  ret_refit_cyc = refit_cyc;
366  success = true;
367  break;
368  }
369 
370  /* Reset the vehicle's cargo type */
371  v->cargo_type = old_cargo_type;
372  v->cargo_subtype = old_cargo_subtype;
373 
374  /* Make sure we don't taint the vehicle. */
375  v->First()->InvalidateNewGRFCache();
376  v->InvalidateNewGRFCache();
377 
378  if (success) break;
379  }
380  }
381 
382  return ret_refit_cyc;
383 }
384 
386 struct RefitOption {
388  byte subtype;
390 
396  inline bool operator != (const RefitOption &other) const
397  {
398  return other.cargo != this->cargo || other.string != this->string;
399  }
400 
406  inline bool operator == (const RefitOption &other) const
407  {
408  return other.cargo == this->cargo && other.string == this->string;
409  }
410 };
411 
412 typedef std::vector<RefitOption> SubtypeList;
413 
423 static void DrawVehicleRefitWindow(const SubtypeList list[NUM_CARGO], const int sel[2], uint pos, uint rows, uint delta, const Rect &r)
424 {
425  uint y = r.top + WD_MATRIX_TOP;
426  uint current = 0;
427 
428  bool rtl = _current_text_dir == TD_RTL;
429  uint iconwidth = std::max(GetSpriteSize(SPR_CIRCLE_FOLDED).width, GetSpriteSize(SPR_CIRCLE_UNFOLDED).width);
430  uint iconheight = GetSpriteSize(SPR_CIRCLE_FOLDED).height;
431  int linecolour = _colour_gradient[COLOUR_ORANGE][4];
432 
433  int iconleft = rtl ? r.right - WD_MATRIX_RIGHT - iconwidth : r.left + WD_MATRIX_LEFT;
434  int iconcenter = rtl ? r.right - WD_MATRIX_RIGHT - iconwidth / 2 : r.left + WD_MATRIX_LEFT + iconwidth / 2;
435  int iconinner = rtl ? r.right - WD_MATRIX_RIGHT - iconwidth : r.left + WD_MATRIX_LEFT + iconwidth;
436 
437  int textleft = r.left + WD_MATRIX_LEFT + (rtl ? 0 : iconwidth + 4);
438  int textright = r.right - WD_MATRIX_RIGHT - (rtl ? iconwidth + 4 : 0);
439 
440  /* Draw the list of subtypes for each cargo, and find the selected refit option (by its position). */
441  for (uint i = 0; current < pos + rows && i < NUM_CARGO; i++) {
442  for (uint j = 0; current < pos + rows && j < list[i].size(); j++) {
443  const RefitOption &refit = list[i][j];
444 
445  /* Hide subtypes if sel[0] does not match */
446  if (sel[0] != (int)i && refit.subtype != 0xFF) continue;
447 
448  /* Refit options with a position smaller than pos don't have to be drawn. */
449  if (current < pos) {
450  current++;
451  continue;
452  }
453 
454  if (list[i].size() > 1) {
455  if (refit.subtype != 0xFF) {
456  /* Draw tree lines */
457  int ycenter = y + FONT_HEIGHT_NORMAL / 2;
458  GfxDrawLine(iconcenter, y - WD_MATRIX_TOP, iconcenter, j == list[i].size() - 1 ? ycenter : y - WD_MATRIX_TOP + delta - 1, linecolour);
459  GfxDrawLine(iconcenter, ycenter, iconinner, ycenter, linecolour);
460  } else {
461  /* Draw expand/collapse icon */
462  DrawSprite(sel[0] == (int)i ? SPR_CIRCLE_UNFOLDED : SPR_CIRCLE_FOLDED, PAL_NONE, iconleft, y + (FONT_HEIGHT_NORMAL - iconheight) / 2);
463  }
464  }
465 
466  TextColour colour = (sel[0] == (int)i && (uint)sel[1] == j) ? TC_WHITE : TC_BLACK;
467  /* Get the cargo name. */
468  SetDParam(0, CargoSpec::Get(refit.cargo)->name);
469  SetDParam(1, refit.string);
470  DrawString(textleft, textright, y, STR_JUST_STRING_STRING, colour);
471 
472  y += delta;
473  current++;
474  }
475  }
476 }
477 
479 struct RefitWindow : public Window {
480  int sel[2];
491  int click_x;
493  uint8 num_vehicles;
494  bool auto_refit;
495 
500  {
501  for (uint i = 0; i < NUM_CARGO; i++) this->list[i].clear();
502  Vehicle *v = Vehicle::Get(this->window_number);
503 
504  /* Check only the selected vehicles. */
505  VehicleSet vehicles_to_refit;
506  GetVehicleSet(vehicles_to_refit, Vehicle::Get(this->selected_vehicle), this->num_vehicles);
507 
508  do {
509  if (v->type == VEH_TRAIN && std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), v->index) == vehicles_to_refit.end()) continue;
510  const Engine *e = v->GetEngine();
511  CargoTypes cmask = e->info.refit_mask;
512  byte callback_mask = e->info.callback_mask;
513 
514  /* Skip this engine if it does not carry anything */
515  if (!e->CanCarryCargo()) continue;
516  /* Skip this engine if we build the list for auto-refitting and engine doesn't allow it. */
517  if (this->auto_refit && !HasBit(e->info.misc_flags, EF_AUTO_REFIT)) continue;
518 
519  /* Loop through all cargoes in the refit mask */
520  int current_index = 0;
521  for (const auto &cs : _sorted_cargo_specs) {
522  CargoID cid = cs->Index();
523  /* Skip cargo type if it's not listed */
524  if (!HasBit(cmask, cid)) {
525  current_index++;
526  continue;
527  }
528 
529  bool first_vehicle = this->list[current_index].size() == 0;
530  if (first_vehicle) {
531  /* Keeping the current subtype is always an option. It also serves as the option in case of no subtypes */
532  this->list[current_index].push_back({cid, 0xFF, STR_EMPTY});
533  }
534 
535  /* Check the vehicle's callback mask for cargo suffixes.
536  * This is not supported for ordered refits, since subtypes only have a meaning
537  * for a specific vehicle at a specific point in time, which conflicts with shared orders,
538  * autoreplace, autorenew, clone, order restoration, ... */
539  if (this->order == INVALID_VEH_ORDER_ID && HasBit(callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) {
540  /* Make a note of the original cargo type. It has to be
541  * changed to test the cargo & subtype... */
542  CargoID temp_cargo = v->cargo_type;
543  byte temp_subtype = v->cargo_subtype;
544 
545  v->cargo_type = cid;
546 
547  for (uint refit_cyc = 0; refit_cyc < MAX_REFIT_CYCLE; refit_cyc++) {
548  v->cargo_subtype = refit_cyc;
549 
550  /* Make sure we don't pick up anything cached. */
553 
554  StringID subtype = GetCargoSubtypeText(v);
555 
556  if (first_vehicle) {
557  /* Append new subtype (don't add duplicates though) */
558  if (subtype == STR_EMPTY) break;
559 
560  RefitOption option;
561  option.cargo = cid;
562  option.subtype = refit_cyc;
563  option.string = subtype;
564  include(this->list[current_index], option);
565  } else {
566  /* Intersect the subtypes of earlier vehicles with the subtypes of this vehicle */
567  if (subtype == STR_EMPTY) {
568  /* No more subtypes for this vehicle, delete all subtypes >= refit_cyc */
569  SubtypeList &l = this->list[current_index];
570  /* 0xFF item is in front, other subtypes are sorted. So just truncate the list in the right spot */
571  for (uint i = 1; i < l.size(); i++) {
572  if (l[i].subtype >= refit_cyc) {
573  l.resize(i);
574  break;
575  }
576  }
577  break;
578  } else {
579  /* Check whether the subtype matches with the subtype of earlier vehicles. */
580  uint pos = 1;
581  SubtypeList &l = this->list[current_index];
582  while (pos < l.size() && l[pos].subtype != refit_cyc) pos++;
583  if (pos < l.size() && l[pos].string != subtype) {
584  /* String mismatch, remove item keeping the order */
585  l.erase(l.begin() + pos);
586  }
587  }
588  }
589  }
590 
591  /* Reset the vehicle's cargo type */
592  v->cargo_type = temp_cargo;
593  v->cargo_subtype = temp_subtype;
594 
595  /* And make sure we haven't tainted the cache */
598  }
599  current_index++;
600  }
601  } while (v->IsGroundVehicle() && (v = v->Next()) != nullptr);
602  }
603 
608  {
609  uint scroll_row = 0;
610  uint row = 0;
611 
612  for (uint i = 0; i < NUM_CARGO; i++) {
613  for (uint j = 0; j < this->list[i].size(); j++) {
614  const RefitOption &refit = this->list[i][j];
615 
616  /* Hide subtypes if sel[0] does not match */
617  if (this->sel[0] != (int)i && refit.subtype != 0xFF) continue;
618 
619  if (this->sel[0] == (int)i && (uint)this->sel[1] == j) scroll_row = row;
620 
621  row++;
622  }
623  }
624 
625  this->vscroll->SetCount(row);
626  if (scroll_row < row) this->vscroll->ScrollTowards(scroll_row);
627  }
628 
633  void SetSelection(uint click_row)
634  {
635  uint row = 0;
636 
637  for (uint i = 0; i < NUM_CARGO; i++) {
638  for (uint j = 0; j < this->list[i].size(); j++) {
639  const RefitOption &refit = this->list[i][j];
640 
641  /* Hide subtypes if sel[0] does not match */
642  if (this->sel[0] != (int)i && refit.subtype != 0xFF) continue;
643 
644  if (row == click_row) {
645  this->sel[0] = i;
646  this->sel[1] = j;
647  return;
648  }
649 
650  row++;
651  }
652  }
653 
654  this->sel[0] = -1;
655  this->sel[1] = 0;
656  }
657 
663  {
664  if (this->sel[0] < 0) return nullptr;
665 
666  SubtypeList &l = this->list[this->sel[0]];
667  if ((uint)this->sel[1] >= l.size()) return nullptr;
668 
669  return &l[this->sel[1]];
670  }
671 
672  RefitWindow(WindowDesc *desc, const Vehicle *v, VehicleOrderID order, bool auto_refit) : Window(desc)
673  {
674  this->sel[0] = -1;
675  this->sel[1] = 0;
676  this->auto_refit = auto_refit;
677  this->order = order;
678  this->CreateNestedTree();
679 
680  this->vscroll = this->GetScrollbar(WID_VR_SCROLLBAR);
681  this->hscroll = (v->IsGroundVehicle() ? this->GetScrollbar(WID_VR_HSCROLLBAR) : nullptr);
682  this->GetWidget<NWidgetCore>(WID_VR_SELECT_HEADER)->tool_tip = STR_REFIT_TRAIN_LIST_TOOLTIP + v->type;
683  this->GetWidget<NWidgetCore>(WID_VR_MATRIX)->tool_tip = STR_REFIT_TRAIN_LIST_TOOLTIP + v->type;
684  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_VR_REFIT);
685  nwi->widget_data = STR_REFIT_TRAIN_REFIT_BUTTON + v->type;
686  nwi->tool_tip = STR_REFIT_TRAIN_REFIT_TOOLTIP + v->type;
687  this->GetWidget<NWidgetStacked>(WID_VR_SHOW_HSCROLLBAR)->SetDisplayedPlane(v->IsGroundVehicle() ? 0 : SZSP_HORIZONTAL);
688  this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY)->tool_tip = (v->type == VEH_TRAIN) ? STR_REFIT_SELECT_VEHICLES_TOOLTIP : STR_NULL;
689 
690  this->FinishInitNested(v->index);
691  this->owner = v->owner;
692 
693  this->SetWidgetDisabledState(WID_VR_REFIT, this->sel[0] < 0);
694  }
695 
696  void OnInit() override
697  {
698  if (this->cargo != nullptr) {
699  /* Store the RefitOption currently in use. */
700  RefitOption current_refit_option = *(this->cargo);
701 
702  /* Rebuild the refit list */
703  this->BuildRefitList();
704  this->sel[0] = -1;
705  this->sel[1] = 0;
706  this->cargo = nullptr;
707  for (uint i = 0; this->cargo == nullptr && i < NUM_CARGO; i++) {
708  for (uint j = 0; j < list[i].size(); j++) {
709  if (list[i][j] == current_refit_option) {
710  this->sel[0] = i;
711  this->sel[1] = j;
712  this->cargo = &list[i][j];
713  break;
714  }
715  }
716  }
717 
718  this->SetWidgetDisabledState(WID_VR_REFIT, this->sel[0] < 0);
719  this->RefreshScrollbar();
720  } else {
721  /* Rebuild the refit list */
723  }
724  }
725 
726  void OnPaint() override
727  {
728  /* Determine amount of items for scroller. */
729  if (this->hscroll != nullptr) this->hscroll->SetCount(this->vehicle_width);
730 
731  /* Calculate sprite position. */
732  NWidgetCore *vehicle_panel_display = this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY);
733  int sprite_width = std::max(0, ((int)vehicle_panel_display->current_x - this->vehicle_width) / 2);
734  this->sprite_left = vehicle_panel_display->pos_x;
735  this->sprite_right = vehicle_panel_display->pos_x + vehicle_panel_display->current_x - 1;
736  if (_current_text_dir == TD_RTL) {
737  this->sprite_right -= sprite_width;
738  this->vehicle_margin = vehicle_panel_display->current_x - sprite_right;
739  } else {
740  this->sprite_left += sprite_width;
741  this->vehicle_margin = sprite_left;
742  }
743 
744  this->DrawWidgets();
745  }
746 
747  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
748  {
749  switch (widget) {
750  case WID_VR_MATRIX:
752  size->height = resize->height * 8;
753  break;
754 
756  size->height = ScaleGUITrad(GetVehicleHeight(Vehicle::Get(this->window_number)->type));
757  break;
758 
759  case WID_VR_INFO:
760  size->width = WD_FRAMERECT_LEFT + this->information_width + WD_FRAMERECT_RIGHT;
761  break;
762  }
763  }
764 
765  void SetStringParameters(int widget) const override
766  {
767  if (widget == WID_VR_CAPTION) SetDParam(0, Vehicle::Get(this->window_number)->index);
768  }
769 
777  {
778  assert(_current_company == _local_company);
779  auto [cost, refit_capacity, mail_capacity] = Command<CMD_REFIT_VEHICLE>::Do(DC_QUERY_COST, this->selected_vehicle, option->cargo, option->subtype, this->auto_refit, false, this->num_vehicles);
780 
781  if (cost.Failed()) return INVALID_STRING_ID;
782 
783  SetDParam(0, option->cargo);
784  SetDParam(1, refit_capacity);
785 
786  Money money = cost.GetCost();
787  if (mail_capacity > 0) {
788  SetDParam(2, CT_MAIL);
789  SetDParam(3, mail_capacity);
790  if (this->order != INVALID_VEH_ORDER_ID) {
791  /* No predictable cost */
792  return STR_PURCHASE_INFO_AIRCRAFT_CAPACITY;
793  } else if (money <= 0) {
794  SetDParam(4, -money);
795  return STR_REFIT_NEW_CAPACITY_INCOME_FROM_AIRCRAFT_REFIT;
796  } else {
797  SetDParam(4, money);
798  return STR_REFIT_NEW_CAPACITY_COST_OF_AIRCRAFT_REFIT;
799  }
800  } else {
801  if (this->order != INVALID_VEH_ORDER_ID) {
802  /* No predictable cost */
803  SetDParam(2, STR_EMPTY);
804  return STR_PURCHASE_INFO_CAPACITY;
805  } else if (money <= 0) {
806  SetDParam(2, -money);
807  return STR_REFIT_NEW_CAPACITY_INCOME_FROM_REFIT;
808  } else {
809  SetDParam(2, money);
810  return STR_REFIT_NEW_CAPACITY_COST_OF_REFIT;
811  }
812  }
813  }
814 
815  void DrawWidget(const Rect &r, int widget) const override
816  {
817  switch (widget) {
819  Vehicle *v = Vehicle::Get(this->window_number);
820  DrawVehicleImage(v, this->sprite_left + WD_FRAMERECT_LEFT, this->sprite_right - WD_FRAMERECT_RIGHT,
821  r.top + WD_FRAMERECT_TOP, INVALID_VEHICLE, EIT_IN_DETAILS, this->hscroll != nullptr ? this->hscroll->GetPosition() : 0);
822 
823  /* Highlight selected vehicles. */
824  if (this->order != INVALID_VEH_ORDER_ID) break;
825  int x = 0;
826  switch (v->type) {
827  case VEH_TRAIN: {
828  VehicleSet vehicles_to_refit;
829  GetVehicleSet(vehicles_to_refit, Vehicle::Get(this->selected_vehicle), this->num_vehicles);
830 
831  int left = INT32_MIN;
832  int width = 0;
833 
834  for (Train *u = Train::From(v); u != nullptr; u = u->Next()) {
835  /* Start checking. */
836  const bool contained = std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), u->index) != vehicles_to_refit.end();
837  if (contained && left == INT32_MIN) {
838  left = x - this->hscroll->GetPosition() + r.left + this->vehicle_margin;
839  width = 0;
840  }
841 
842  /* Draw a selection. */
843  if ((!contained || u->Next() == nullptr) && left != INT32_MIN) {
844  if (u->Next() == nullptr && contained) {
845  int current_width = u->GetDisplayImageWidth();
846  width += current_width;
847  x += current_width;
848  }
849 
850  int right = Clamp(left + width, 0, r.right);
851  left = std::max(0, left);
852 
853  if (_current_text_dir == TD_RTL) {
854  right = this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY)->current_x - left;
855  left = right - width;
856  }
857 
858  if (left != right) {
859  DrawFrameRect(left, r.top + WD_FRAMERECT_TOP, right, r.top + WD_FRAMERECT_TOP + ScaleGUITrad(14) - 1, COLOUR_WHITE, FR_BORDERONLY);
860  }
861 
862  left = INT32_MIN;
863  }
864 
865  int current_width = u->GetDisplayImageWidth();
866  width += current_width;
867  x += current_width;
868  }
869  break;
870  }
871 
872  default: break;
873  }
874  break;
875  }
876 
877  case WID_VR_MATRIX:
878  DrawVehicleRefitWindow(this->list, this->sel, this->vscroll->GetPosition(), this->vscroll->GetCapacity(), this->resize.step_height, r);
879  break;
880 
881  case WID_VR_INFO:
882  if (this->cargo != nullptr) {
883  StringID string = this->GetCapacityString(this->cargo);
884  if (string != INVALID_STRING_ID) {
886  r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, string);
887  }
888  }
889  break;
890  }
891  }
892 
898  void OnInvalidateData(int data = 0, bool gui_scope = true) override
899  {
900  switch (data) {
901  case VIWD_AUTOREPLACE: // Autoreplace replaced the vehicle; selected_vehicle became invalid.
902  case VIWD_CONSIST_CHANGED: { // The consist has changed; rebuild the entire list.
903  /* Clear the selection. */
904  Vehicle *v = Vehicle::Get(this->window_number);
905  this->selected_vehicle = v->index;
906  this->num_vehicles = UINT8_MAX;
907  FALLTHROUGH;
908  }
909 
910  case 2: { // The vehicle selection has changed; rebuild the entire list.
911  if (!gui_scope) break;
912  this->BuildRefitList();
913 
914  /* The vehicle width has changed too. */
915  this->vehicle_width = GetVehicleWidth(Vehicle::Get(this->window_number), EIT_IN_DETAILS);
916  uint max_width = 0;
917 
918  /* Check the width of all cargo information strings. */
919  for (uint i = 0; i < NUM_CARGO; i++) {
920  for (uint j = 0; j < this->list[i].size(); j++) {
921  StringID string = this->GetCapacityString(&list[i][j]);
922  if (string != INVALID_STRING_ID) {
923  Dimension dim = GetStringBoundingBox(string);
924  max_width = std::max(dim.width, max_width);
925  }
926  }
927  }
928 
929  if (this->information_width < max_width) {
930  this->information_width = max_width;
931  this->ReInit();
932  }
933  FALLTHROUGH;
934  }
935 
936  case 1: // A new cargo has been selected.
937  if (!gui_scope) break;
938  this->cargo = GetRefitOption();
939  this->RefreshScrollbar();
940  break;
941  }
942  }
943 
944  int GetClickPosition(int click_x)
945  {
946  const NWidgetCore *matrix_widget = this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY);
947  if (_current_text_dir == TD_RTL) click_x = matrix_widget->current_x - click_x;
948  click_x -= this->vehicle_margin;
949  if (this->hscroll != nullptr) click_x += this->hscroll->GetPosition();
950 
951  return click_x;
952  }
953 
954  void SetSelectedVehicles(int drag_x)
955  {
956  drag_x = GetClickPosition(drag_x);
957 
958  int left_x = std::min(this->click_x, drag_x);
959  int right_x = std::max(this->click_x, drag_x);
960  this->num_vehicles = 0;
961 
962  Vehicle *v = Vehicle::Get(this->window_number);
963  /* Find the vehicle part that was clicked. */
964  switch (v->type) {
965  case VEH_TRAIN: {
966  /* Don't select anything if we are not clicking in the vehicle. */
967  if (left_x >= 0) {
968  const Train *u = Train::From(v);
969  bool start_counting = false;
970  for (; u != nullptr; u = u->Next()) {
971  int current_width = u->GetDisplayImageWidth();
972  left_x -= current_width;
973  right_x -= current_width;
974 
975  if (left_x < 0 && !start_counting) {
976  this->selected_vehicle = u->index;
977  start_counting = true;
978 
979  /* Count the first vehicle, even if articulated part */
980  this->num_vehicles++;
981  } else if (start_counting && !u->IsArticulatedPart()) {
982  /* Do not count articulated parts */
983  this->num_vehicles++;
984  }
985 
986  if (right_x < 0) break;
987  }
988  }
989 
990  /* If the selection is not correct, clear it. */
991  if (this->num_vehicles != 0) {
992  if (_ctrl_pressed) this->num_vehicles = UINT8_MAX;
993  break;
994  }
995  FALLTHROUGH;
996  }
997 
998  default:
999  /* Clear the selection. */
1000  this->selected_vehicle = v->index;
1001  this->num_vehicles = UINT8_MAX;
1002  break;
1003  }
1004  }
1005 
1006  void OnClick(Point pt, int widget, int click_count) override
1007  {
1008  switch (widget) {
1009  case WID_VR_VEHICLE_PANEL_DISPLAY: { // Vehicle image.
1010  if (this->order != INVALID_VEH_ORDER_ID) break;
1011  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_VR_VEHICLE_PANEL_DISPLAY);
1012  this->click_x = GetClickPosition(pt.x - nwi->pos_x);
1013  this->SetSelectedVehicles(pt.x - nwi->pos_x);
1015  if (!_ctrl_pressed) {
1016  SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1017  } else {
1018  /* The vehicle selection has changed. */
1019  this->InvalidateData(2);
1020  }
1021  break;
1022  }
1023 
1024  case WID_VR_MATRIX: { // listbox
1025  this->SetSelection(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_VR_MATRIX));
1026  this->SetWidgetDisabledState(WID_VR_REFIT, this->sel[0] < 0);
1027  this->InvalidateData(1);
1028 
1029  if (click_count == 1) break;
1030  FALLTHROUGH;
1031  }
1032 
1033  case WID_VR_REFIT: // refit button
1034  if (this->cargo != nullptr) {
1035  const Vehicle *v = Vehicle::Get(this->window_number);
1036 
1037  if (this->order == INVALID_VEH_ORDER_ID) {
1038  bool delete_window = this->selected_vehicle == v->index && this->num_vehicles == UINT8_MAX;
1039  if (Command<CMD_REFIT_VEHICLE>::Post(GetCmdRefitVehMsg(v), v->tile, this->selected_vehicle, this->cargo->cargo, this->cargo->subtype, false, false, this->num_vehicles) && delete_window) this->Close();
1040  } else {
1041  if (Command<CMD_ORDER_REFIT>::Post(v->tile, v->index, this->order, this->cargo->cargo)) this->Close();
1042  }
1043  }
1044  break;
1045  }
1046  }
1047 
1048  void OnMouseDrag(Point pt, int widget) override
1049  {
1050  switch (widget) {
1051  case WID_VR_VEHICLE_PANEL_DISPLAY: { // Vehicle image.
1052  if (this->order != INVALID_VEH_ORDER_ID) break;
1053  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_VR_VEHICLE_PANEL_DISPLAY);
1054  this->SetSelectedVehicles(pt.x - nwi->pos_x);
1056  break;
1057  }
1058  }
1059  }
1060 
1061  void OnDragDrop(Point pt, int widget) override
1062  {
1063  switch (widget) {
1064  case WID_VR_VEHICLE_PANEL_DISPLAY: { // Vehicle image.
1065  if (this->order != INVALID_VEH_ORDER_ID) break;
1066  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_VR_VEHICLE_PANEL_DISPLAY);
1067  this->SetSelectedVehicles(pt.x - nwi->pos_x);
1068  this->InvalidateData(2);
1069  break;
1070  }
1071  }
1072  }
1073 
1074  void OnResize() override
1075  {
1076  this->vehicle_width = GetVehicleWidth(Vehicle::Get(this->window_number), EIT_IN_DETAILS);
1077  this->vscroll->SetCapacityFromWidget(this, WID_VR_MATRIX);
1078  if (this->hscroll != nullptr) this->hscroll->SetCapacityFromWidget(this, WID_VR_VEHICLE_PANEL_DISPLAY);
1079  }
1080 };
1081 
1082 static const NWidgetPart _nested_vehicle_refit_widgets[] = {
1084  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1085  NWidget(WWT_CAPTION, COLOUR_GREY, WID_VR_CAPTION), SetDataTip(STR_REFIT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1086  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1087  EndContainer(),
1088  /* Vehicle display + scrollbar. */
1091  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VR_SHOW_HSCROLLBAR),
1092  NWidget(NWID_HSCROLLBAR, COLOUR_GREY, WID_VR_HSCROLLBAR),
1093  EndContainer(),
1094  EndContainer(),
1095  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_VR_SELECT_HEADER), SetDataTip(STR_REFIT_TITLE, STR_NULL), SetResize(1, 0),
1096  /* Matrix + scrollbar. */
1098  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),
1099  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_VR_SCROLLBAR),
1100  EndContainer(),
1103  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VR_REFIT), SetFill(1, 0), SetResize(1, 0),
1104  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1105  EndContainer(),
1106 };
1107 
1108 static WindowDesc _vehicle_refit_desc(
1109  WDP_AUTO, "view_vehicle_refit", 240, 174,
1112  _nested_vehicle_refit_widgets, lengthof(_nested_vehicle_refit_widgets)
1113 );
1114 
1122 void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
1123 {
1125  RefitWindow *w = new RefitWindow(&_vehicle_refit_desc, v, order, auto_refit);
1126  w->parent = parent;
1127 }
1128 
1130 uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
1131 {
1132  /* List of cargo types of this engine */
1133  CargoTypes cmask = GetUnionOfArticulatedRefitMasks(engine, false);
1134  /* List of cargo types available in this climate */
1135  CargoTypes lmask = _cargo_mask;
1136 
1137  /* Draw nothing if the engine is not refittable */
1138  if (HasAtMostOneBit(cmask)) return y;
1139 
1140  if (cmask == lmask) {
1141  /* Engine can be refitted to all types in this climate */
1142  SetDParam(0, STR_PURCHASE_INFO_ALL_TYPES);
1143  } else {
1144  /* Check if we are able to refit to more cargo types and unable to. If
1145  * so, invert the cargo types to list those that we can't refit to. */
1146  if (CountBits(cmask ^ lmask) < CountBits(cmask) && CountBits(cmask ^ lmask) <= 7) {
1147  cmask ^= lmask;
1148  SetDParam(0, STR_PURCHASE_INFO_ALL_BUT);
1149  } else {
1150  SetDParam(0, STR_JUST_CARGO_LIST);
1151  }
1152  SetDParam(1, cmask);
1153  }
1154 
1155  return DrawStringMultiLine(left, right, y, INT32_MAX, STR_PURCHASE_INFO_REFITTABLE_TO);
1156 }
1157 
1160 {
1161  if (HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) {
1162  uint16 cb = GetVehicleCallback(CBID_VEHICLE_CARGO_SUFFIX, 0, 0, v->engine_type, v);
1163  if (cb != CALLBACK_FAILED) {
1165  if (cb >= 0x400 || (v->GetGRF()->grf_version < 8 && cb == 0xFF)) cb = CALLBACK_FAILED;
1166  }
1167  if (cb != CALLBACK_FAILED) {
1168  return GetGRFStringID(v->GetGRFID(), 0xD000 + cb);
1169  }
1170  }
1171  return STR_EMPTY;
1172 }
1173 
1176 {
1177  return a.NumVehicles() < b.NumVehicles();
1178 }
1179 
1182 {
1183  return a.GetDisplayProfitThisYear() < b.GetDisplayProfitThisYear();
1184 }
1185 
1188 {
1189  return a.GetDisplayProfitLastYear() < b.GetDisplayProfitLastYear();
1190 }
1191 
1194 {
1195  return a.GetDisplayProfitThisYear() * static_cast<uint>(b.NumVehicles()) < b.GetDisplayProfitThisYear() * static_cast<uint>(a.NumVehicles());
1196 }
1197 
1200 {
1201  return a.GetDisplayProfitLastYear() * static_cast<uint>(b.NumVehicles()) < b.GetDisplayProfitLastYear() * static_cast<uint>(a.NumVehicles());
1202 }
1203 
1205 static bool VehicleNumberSorter(const Vehicle * const &a, const Vehicle * const &b)
1206 {
1207  return a->unitnumber < b->unitnumber;
1208 }
1209 
1211 static bool VehicleNameSorter(const Vehicle * const &a, const Vehicle * const &b)
1212 {
1213  static char last_name[2][64];
1214 
1215  if (a != _last_vehicle[0]) {
1216  _last_vehicle[0] = a;
1217  SetDParam(0, a->index);
1218  GetString(last_name[0], STR_VEHICLE_NAME, lastof(last_name[0]));
1219  }
1220 
1221  if (b != _last_vehicle[1]) {
1222  _last_vehicle[1] = b;
1223  SetDParam(0, b->index);
1224  GetString(last_name[1], STR_VEHICLE_NAME, lastof(last_name[1]));
1225  }
1226 
1227  int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
1228  return (r != 0) ? r < 0: VehicleNumberSorter(a, b);
1229 }
1230 
1232 static bool VehicleAgeSorter(const Vehicle * const &a, const Vehicle * const &b)
1233 {
1234  int r = a->age - b->age;
1235  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1236 }
1237 
1239 static bool VehicleProfitThisYearSorter(const Vehicle * const &a, const Vehicle * const &b)
1240 {
1242  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1243 }
1244 
1246 static bool VehicleProfitLastYearSorter(const Vehicle * const &a, const Vehicle * const &b)
1247 {
1249  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1250 }
1251 
1253 static bool VehicleCargoSorter(const Vehicle * const &a, const Vehicle * const &b)
1254 {
1255  const Vehicle *v;
1256  CargoArray diff;
1257 
1258  /* Append the cargo of the connected waggons */
1259  for (v = a; v != nullptr; v = v->Next()) diff[v->cargo_type] += v->cargo_cap;
1260  for (v = b; v != nullptr; v = v->Next()) diff[v->cargo_type] -= v->cargo_cap;
1261 
1262  int r = 0;
1263  for (CargoID i = 0; i < NUM_CARGO; i++) {
1264  r = diff[i];
1265  if (r != 0) break;
1266  }
1267 
1268  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1269 }
1270 
1272 static bool VehicleReliabilitySorter(const Vehicle * const &a, const Vehicle * const &b)
1273 {
1274  int r = a->reliability - b->reliability;
1275  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1276 }
1277 
1279 static bool VehicleMaxSpeedSorter(const Vehicle * const &a, const Vehicle * const &b)
1280 {
1282  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1283 }
1284 
1286 static bool VehicleModelSorter(const Vehicle * const &a, const Vehicle * const &b)
1287 {
1288  int r = a->engine_type - b->engine_type;
1289  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1290 }
1291 
1293 static bool VehicleValueSorter(const Vehicle * const &a, const Vehicle * const &b)
1294 {
1295  const Vehicle *u;
1296  Money diff = 0;
1297 
1298  for (u = a; u != nullptr; u = u->Next()) diff += u->value;
1299  for (u = b; u != nullptr; u = u->Next()) diff -= u->value;
1300 
1301  int r = ClampToI32(diff);
1302  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1303 }
1304 
1306 static bool VehicleLengthSorter(const Vehicle * const &a, const Vehicle * const &b)
1307 {
1309  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1310 }
1311 
1313 static bool VehicleTimeToLiveSorter(const Vehicle * const &a, const Vehicle * const &b)
1314 {
1315  int r = ClampToI32((a->max_age - a->age) - (b->max_age - b->age));
1316  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1317 }
1318 
1320 static bool VehicleTimetableDelaySorter(const Vehicle * const &a, const Vehicle * const &b)
1321 {
1322  int r = a->lateness_counter - b->lateness_counter;
1323  return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1324 }
1325 
1326 void InitializeGUI()
1327 {
1328  MemSetT(&_grouping, 0);
1329  MemSetT(&_sorting, 0);
1330 }
1331 
1338 static inline void ChangeVehicleWindow(WindowClass window_class, VehicleID from_index, VehicleID to_index)
1339 {
1340  Window *w = FindWindowById(window_class, from_index);
1341  if (w != nullptr) {
1342  /* Update window_number */
1343  w->window_number = to_index;
1344  if (w->viewport != nullptr) w->viewport->follow_vehicle = to_index;
1345 
1346  /* Update vehicle drag data */
1347  if (_thd.window_class == window_class && _thd.window_number == (WindowNumber)from_index) {
1348  _thd.window_number = to_index;
1349  }
1350 
1351  /* Notify the window. */
1352  w->InvalidateData(VIWD_AUTOREPLACE, false);
1353  }
1354 }
1355 
1361 void ChangeVehicleViewWindow(VehicleID from_index, VehicleID to_index)
1362 {
1363  ChangeVehicleWindow(WC_VEHICLE_VIEW, from_index, to_index);
1364  ChangeVehicleWindow(WC_VEHICLE_ORDERS, from_index, to_index);
1365  ChangeVehicleWindow(WC_VEHICLE_REFIT, from_index, to_index);
1366  ChangeVehicleWindow(WC_VEHICLE_DETAILS, from_index, to_index);
1367  ChangeVehicleWindow(WC_VEHICLE_TIMETABLE, from_index, to_index);
1368 }
1369 
1370 static const NWidgetPart _nested_vehicle_list[] = {
1372  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1374  NWidget(WWT_CAPTION, COLOUR_GREY, WID_VL_CAPTION),
1377  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VL_ORDER_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_GOTO_ORDER_VIEW, STR_GOTO_ORDER_VIEW_TOOLTIP),
1378  EndContainer(),
1379  EndContainer(),
1380  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1381  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1382  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1383  EndContainer(),
1384 
1386  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_VL_GROUP_ORDER), SetMinimalSize(81, 12), SetFill(0, 1), SetDataTip(STR_STATION_VIEW_GROUP, STR_TOOLTIP_GROUP_ORDER),
1387  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_VL_GROUP_BY_PULLDOWN), SetMinimalSize(167, 12), SetFill(0, 1), SetDataTip(0x0, STR_TOOLTIP_GROUP_ORDER),
1388  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(12, 12), SetFill(1, 1), SetResize(1, 0), EndContainer(),
1389  EndContainer(),
1390 
1392  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VL_SORT_ORDER), SetMinimalSize(81, 12), SetFill(0, 1), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
1393  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_VL_SORT_BY_PULLDOWN), SetMinimalSize(167, 12), SetFill(0, 1), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
1394  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(12, 12), SetFill(1, 1), SetResize(1, 0), EndContainer(),
1395  EndContainer(),
1396 
1398  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),
1399  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_VL_SCROLLBAR),
1400  EndContainer(),
1401 
1403  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VL_HIDE_BUTTONS),
1405  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VL_AVAILABLE_VEHICLES), SetMinimalSize(106, 12), SetFill(0, 1),
1406  SetDataTip(STR_BLACK_STRING, STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP),
1407  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetResize(1, 0), SetFill(1, 1), EndContainer(),
1409  SetDataTip(STR_VEHICLE_LIST_MANAGE_LIST, STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP),
1410  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VL_STOP_ALL), SetMinimalSize(12, 12), SetFill(0, 1),
1411  SetDataTip(SPR_FLAG_VEH_STOPPED, STR_VEHICLE_LIST_MASS_STOP_LIST_TOOLTIP),
1412  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VL_START_ALL), SetMinimalSize(12, 12), SetFill(0, 1),
1413  SetDataTip(SPR_FLAG_VEH_RUNNING, STR_VEHICLE_LIST_MASS_START_LIST_TOOLTIP),
1414  EndContainer(),
1415  /* Widget to be shown for other companies hiding the previous 5 widgets. */
1416  NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 0), EndContainer(),
1417  EndContainer(),
1418  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1419  EndContainer(),
1420 };
1421 
1422 static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, uint order_arrow_width, VehicleOrderID start)
1423 {
1424  const Order *order = v->GetOrder(start);
1425  if (order == nullptr) return;
1426 
1427  bool rtl = _current_text_dir == TD_RTL;
1428  int l_offset = rtl ? 0 : order_arrow_width;
1429  int r_offset = rtl ? order_arrow_width : 0;
1430  int i = 0;
1431  VehicleOrderID oid = start;
1432 
1433  do {
1434  if (oid == v->cur_real_order_index) DrawString(left, right, y, STR_TINY_RIGHT_ARROW, TC_BLACK);
1435 
1436  if (order->IsType(OT_GOTO_STATION)) {
1437  SetDParam(0, order->GetDestination());
1438  DrawString(left + l_offset, right - r_offset, y, STR_TINY_BLACK_STATION);
1439 
1440  y += FONT_HEIGHT_SMALL;
1441  if (++i == 4) break;
1442  }
1443 
1444  oid++;
1445  order = order->next;
1446  if (order == nullptr) {
1447  order = v->orders->GetFirstOrder();
1448  oid = 0;
1449  }
1450  } while (oid != start);
1451 }
1452 
1454 static void DrawSmallOrderList(const Order *order, int left, int right, int y, uint order_arrow_width)
1455 {
1456  bool rtl = _current_text_dir == TD_RTL;
1457  int l_offset = rtl ? 0 : order_arrow_width;
1458  int r_offset = rtl ? order_arrow_width : 0;
1459  int i = 0;
1460  while (order != nullptr) {
1461  if (order->IsType(OT_GOTO_STATION)) {
1462  SetDParam(0, order->GetDestination());
1463  DrawString(left + l_offset, right - r_offset, y, STR_TINY_BLACK_STATION);
1464 
1465  y += FONT_HEIGHT_SMALL;
1466  if (++i == 4) break;
1467  }
1468  order = order->next;
1469  }
1470 }
1471 
1481 void DrawVehicleImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip)
1482 {
1483  switch (v->type) {
1484  case VEH_TRAIN: DrawTrainImage(Train::From(v), left, right, y, selection, image_type, skip); break;
1485  case VEH_ROAD: DrawRoadVehImage(v, left, right, y, selection, image_type, skip); break;
1486  case VEH_SHIP: DrawShipImage(v, left, right, y, selection, image_type); break;
1487  case VEH_AIRCRAFT: DrawAircraftImage(v, left, right, y, selection, image_type); break;
1488  default: NOT_REACHED();
1489  }
1490 }
1491 
1498 uint GetVehicleListHeight(VehicleType type, uint divisor)
1499 {
1500  /* Name + vehicle + profit */
1501  uint base = ScaleGUITrad(GetVehicleHeight(type)) + 2 * FONT_HEIGHT_SMALL;
1502  /* Drawing of the 4 small orders + profit*/
1503  if (type >= VEH_SHIP) base = std::max(base, 5U * FONT_HEIGHT_SMALL);
1504 
1505  if (divisor == 1) return base;
1506 
1507  /* Make sure the height is dividable by divisor */
1508  uint rem = base % divisor;
1509  return base + (rem == 0 ? 0 : divisor - rem);
1510 }
1511 
1518 void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const
1519 {
1520  int left = r.left + WD_MATRIX_LEFT;
1521  int right = r.right - WD_MATRIX_RIGHT;
1522  int width = right - left;
1523  bool rtl = _current_text_dir == TD_RTL;
1524 
1525  int text_offset = std::max<int>(GetSpriteSize(SPR_PROFIT_LOT).width, GetDigitWidth() * this->unitnumber_digits) + WD_FRAMERECT_RIGHT;
1526  int text_left = left + (rtl ? 0 : text_offset);
1527  int text_right = right - (rtl ? text_offset : 0);
1528 
1529  bool show_orderlist = this->vli.vtype >= VEH_SHIP;
1530  int orderlist_left = left + (rtl ? 0 : std::max(ScaleGUITrad(100) + text_offset, width / 2));
1531  int orderlist_right = right - (rtl ? std::max(ScaleGUITrad(100) + text_offset, width / 2) : 0);
1532 
1533  int image_left = (rtl && show_orderlist) ? orderlist_right : text_left;
1534  int image_right = (!rtl && show_orderlist) ? orderlist_left : text_right;
1535 
1536  int vehicle_button_x = rtl ? right - GetSpriteSize(SPR_PROFIT_LOT).width : left;
1537 
1538  int y = r.top;
1539  uint max = static_cast<uint>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehgroups.size()));
1540  for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
1541 
1542  const GUIVehicleGroup &vehgroup = this->vehgroups[i];
1543 
1544  SetDParam(0, vehgroup.GetDisplayProfitThisYear());
1545  SetDParam(1, vehgroup.GetDisplayProfitLastYear());
1546  DrawString(text_left, text_right, y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1, STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR);
1547 
1548  DrawVehicleProfitButton(vehgroup.GetOldestVehicleAge(), vehgroup.GetDisplayProfitLastYear(), vehgroup.NumVehicles(), vehicle_button_x, y + FONT_HEIGHT_NORMAL + 3);
1549 
1550  switch (this->grouping) {
1551  case GB_NONE: {
1552  const Vehicle *v = vehgroup.GetSingleVehicle();
1553 
1555  DrawSprite(SPR_WARNING_SIGN, PAL_NONE, vehicle_button_x, y + FONT_HEIGHT_NORMAL + 3 + GetSpriteSize(SPR_PROFIT_LOT).height);
1556  }
1557 
1558  DrawVehicleImage(v, image_left, image_right, y + FONT_HEIGHT_SMALL - 1, selected_vehicle, EIT_IN_LIST, 0);
1559 
1560  if (!v->name.empty()) {
1561  /* The vehicle got a name so we will print it */
1562  SetDParam(0, v->index);
1563  DrawString(text_left, text_right, y, STR_TINY_BLACK_VEHICLE);
1564  } else if (v->group_id != DEFAULT_GROUP) {
1565  /* The vehicle has no name, but is member of a group, so print group name */
1566  SetDParam(0, v->group_id);
1567  DrawString(text_left, text_right, y, STR_TINY_GROUP, TC_BLACK);
1568  }
1569 
1570  if (show_orderlist) DrawSmallOrderList(v, orderlist_left, orderlist_right, y, this->order_arrow_width, v->cur_real_order_index);
1571 
1572  StringID str;
1573  if (v->IsChainInDepot()) {
1574  str = STR_BLUE_COMMA;
1575  } else {
1576  str = (v->age > v->max_age - DAYS_IN_LEAP_YEAR) ? STR_RED_COMMA : STR_BLACK_COMMA;
1577  }
1578 
1579  SetDParam(0, v->unitnumber);
1580  DrawString(left, right, y + 2, str);
1581  break;
1582  }
1583 
1584  case GB_SHARED_ORDERS:
1585  assert(vehgroup.NumVehicles() > 0);
1586 
1587  for (int i = 0; i < static_cast<int>(vehgroup.NumVehicles()); ++i) {
1588  if (image_left + 8 * i >= image_right) break; // Break if there is no more space to draw any more vehicles anyway.
1589  DrawVehicleImage(vehgroup.vehicles_begin[i], image_left + 8 * i, image_right, y + FONT_HEIGHT_SMALL - 1, selected_vehicle, EIT_IN_LIST, 0);
1590  }
1591 
1592  if (show_orderlist) DrawSmallOrderList((vehgroup.vehicles_begin[0])->GetFirstOrder(), orderlist_left, orderlist_right, y, this->order_arrow_width);
1593 
1594  SetDParam(0, vehgroup.NumVehicles());
1595  DrawString(left, right, y + 2, STR_BLACK_COMMA);
1596  break;
1597 
1598  default:
1599  NOT_REACHED();
1600  }
1601 
1602  y += line_height;
1603  }
1604 }
1605 
1606 void BaseVehicleListWindow::UpdateSortingFromGrouping()
1607 {
1608  /* Set up sorting. Make the window-specific _sorting variable
1609  * point to the correct global _sorting struct so we are freed
1610  * from having conditionals during window operation */
1611  switch (this->vli.vtype) {
1612  case VEH_TRAIN: this->sorting = &_sorting[this->grouping].train; break;
1613  case VEH_ROAD: this->sorting = &_sorting[this->grouping].roadveh; break;
1614  case VEH_SHIP: this->sorting = &_sorting[this->grouping].ship; break;
1615  case VEH_AIRCRAFT: this->sorting = &_sorting[this->grouping].aircraft; break;
1616  default: NOT_REACHED();
1617  }
1618  this->vehgroups.SetSortFuncs(this->GetVehicleSorterFuncs());
1619  this->vehgroups.SetListing(*this->sorting);
1620  this->vehgroups.ForceRebuild();
1621  this->vehgroups.NeedResort();
1622 }
1623 
1624 void BaseVehicleListWindow::UpdateVehicleGroupBy(GroupBy group_by)
1625 {
1626  if (this->grouping != group_by) {
1627  /* Save the old sorting option, so that if we change the grouping option back later on,
1628  * UpdateSortingFromGrouping() will automatically restore the saved sorting option. */
1629  *this->sorting = this->vehgroups.GetListing();
1630 
1631  this->grouping = group_by;
1632  _grouping[this->vli.type][this->vli.vtype] = group_by;
1633  this->UpdateSortingFromGrouping();
1634  }
1635 }
1636 
1647 private:
1652  };
1653 
1658  };
1659 
1660 public:
1662  {
1663  this->CreateNestedTree();
1664 
1665  this->vscroll = this->GetScrollbar(WID_VL_SCROLLBAR);
1666 
1667  this->BuildVehicleList();
1668  this->SortVehicleList();
1669 
1670  /* Set up the window widgets */
1671  this->GetWidget<NWidgetCore>(WID_VL_LIST)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype;
1672 
1673  NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(WID_VL_CAPTION_SELECTION);
1674  if (this->vli.type == VL_SHARED_ORDERS) {
1675  this->GetWidget<NWidgetCore>(WID_VL_CAPTION_SHARED_ORDERS)->widget_data = STR_VEHICLE_LIST_SHARED_ORDERS_LIST_CAPTION;
1676  /* If we are in the shared orders window, then disable the group-by dropdown menu.
1677  * Remove this when the group-by dropdown menu has another option apart from grouping by shared orders. */
1681  } else {
1682  this->GetWidget<NWidgetCore>(WID_VL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype;
1684  }
1685 
1686  this->FinishInitNested(window_number);
1687  if (this->vli.company != OWNER_NONE) this->owner = this->vli.company;
1688  }
1689 
1691  {
1692  *this->sorting = this->vehgroups.GetListing();
1693  }
1694 
1695  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1696  {
1697  switch (widget) {
1698  case WID_VL_LIST:
1699  resize->height = GetVehicleListHeight(this->vli.vtype, 1);
1700 
1701  switch (this->vli.vtype) {
1702  case VEH_TRAIN:
1703  case VEH_ROAD:
1704  size->height = 6 * resize->height;
1705  break;
1706  case VEH_SHIP:
1707  case VEH_AIRCRAFT:
1708  size->height = 4 * resize->height;
1709  break;
1710  default: NOT_REACHED();
1711  }
1712  break;
1713 
1714  case WID_VL_SORT_ORDER: {
1715  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
1716  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
1717  d.height += padding.height;
1718  *size = maxdim(*size, d);
1719  break;
1720  }
1721 
1723  Dimension d = this->GetActionDropdownSize(this->vli.type == VL_STANDARD, false);
1724  d.height += padding.height;
1725  d.width += padding.width;
1726  *size = maxdim(*size, d);
1727  break;
1728  }
1729  }
1730  }
1731 
1732  void SetStringParameters(int widget) const override
1733  {
1734  switch (widget) {
1736  SetDParam(0, STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vli.vtype);
1737  break;
1738 
1739  case WID_VL_CAPTION:
1741  switch (this->vli.type) {
1742  case VL_SHARED_ORDERS: // Shared Orders
1743  if (this->vehicles.size() == 0) {
1744  /* We can't open this window without vehicles using this order
1745  * and we should close the window when deleting the order. */
1746  NOT_REACHED();
1747  }
1748  SetDParam(0, this->vehicles.size());
1749  break;
1750 
1751  case VL_STANDARD: // Company Name
1752  SetDParam(0, STR_COMPANY_NAME);
1753  SetDParam(1, this->vli.index);
1754  SetDParam(3, this->vehicles.size());
1755  break;
1756 
1757  case VL_STATION_LIST: // Station/Waypoint Name
1758  SetDParam(0, Station::IsExpected(BaseStation::Get(this->vli.index)) ? STR_STATION_NAME : STR_WAYPOINT_NAME);
1759  SetDParam(1, this->vli.index);
1760  SetDParam(3, this->vehicles.size());
1761  break;
1762 
1763  case VL_DEPOT_LIST:
1764  SetDParam(0, STR_DEPOT_CAPTION);
1765  SetDParam(1, this->vli.vtype);
1766  SetDParam(2, this->vli.index);
1767  SetDParam(3, this->vehicles.size());
1768  break;
1769  default: NOT_REACHED();
1770  }
1771  break;
1772  }
1773  }
1774  }
1775 
1776  void DrawWidget(const Rect &r, int widget) const override
1777  {
1778  switch (widget) {
1779  case WID_VL_SORT_ORDER:
1780  /* draw arrow pointing up/down for ascending/descending sorting */
1781  this->DrawSortButtonState(widget, this->vehgroups.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
1782  break;
1783 
1784  case WID_VL_LIST:
1786  break;
1787  }
1788  }
1789 
1790  void OnPaint() override
1791  {
1792  this->BuildVehicleList();
1793  this->SortVehicleList();
1794 
1795  if (this->vehicles.size() == 0 && this->IsWidgetLowered(WID_VL_MANAGE_VEHICLES_DROPDOWN)) {
1796  HideDropDownMenu(this);
1797  }
1798 
1799  /* Hide the widgets that we will not use in this window
1800  * Some windows contains actions only fit for the owner */
1801  int plane_to_show = (this->owner == _local_company) ? BP_SHOW_BUTTONS : BP_HIDE_BUTTONS;
1802  NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(WID_VL_HIDE_BUTTONS);
1803  if (plane_to_show != nwi->shown_plane) {
1804  nwi->SetDisplayedPlane(plane_to_show);
1805  nwi->SetDirty(this);
1806  }
1807  if (this->owner == _local_company) {
1808  this->SetWidgetDisabledState(WID_VL_AVAILABLE_VEHICLES, this->vli.type != VL_STANDARD);
1809  this->SetWidgetsDisabledState(this->vehicles.size() == 0,
1813  WIDGET_LIST_END);
1814  }
1815 
1816  /* Set text of group by dropdown widget. */
1817  this->GetWidget<NWidgetCore>(WID_VL_GROUP_BY_PULLDOWN)->widget_data = this->vehicle_group_by_names[this->grouping];
1818 
1819  /* Set text of sort by dropdown widget. */
1820  this->GetWidget<NWidgetCore>(WID_VL_SORT_BY_PULLDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()];
1821 
1822  this->DrawWidgets();
1823  }
1824 
1825  void OnClick(Point pt, int widget, int click_count) override
1826  {
1827  switch (widget) {
1828  case WID_VL_ORDER_VIEW: // Open the shared orders window
1829  assert(this->vli.type == VL_SHARED_ORDERS);
1830  assert(!this->vehicles.empty());
1831  ShowOrdersWindow(this->vehicles[0]);
1832  break;
1833 
1834  case WID_VL_SORT_ORDER: // Flip sorting method ascending/descending
1835  this->vehgroups.ToggleSortOrder();
1836  this->SetDirty();
1837  break;
1838 
1839  case WID_VL_GROUP_BY_PULLDOWN: // Select sorting criteria dropdown menu
1840  ShowDropDownMenu(this, this->vehicle_group_by_names, this->grouping, WID_VL_GROUP_BY_PULLDOWN, 0, 0);
1841  return;
1842 
1843  case WID_VL_SORT_BY_PULLDOWN: // Select sorting criteria dropdown menu
1844  ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_VL_SORT_BY_PULLDOWN, 0,
1845  (this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10));
1846  return;
1847 
1848  case WID_VL_LIST: { // Matrix to show vehicles
1849  uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_VL_LIST);
1850  if (id_v >= this->vehgroups.size()) return; // click out of list bound
1851 
1852  const GUIVehicleGroup &vehgroup = this->vehgroups[id_v];
1853  switch (this->grouping) {
1854  case GB_NONE: {
1855  const Vehicle *v = vehgroup.GetSingleVehicle();
1856  if (!VehicleClicked(v)) {
1857  if (_ctrl_pressed) {
1859  } else {
1861  }
1862  }
1863  break;
1864  }
1865 
1866  case GB_SHARED_ORDERS: {
1867  assert(vehgroup.NumVehicles() > 0);
1868  const Vehicle *v = vehgroup.vehicles_begin[0];
1869  /* We do not support VehicleClicked() here since the contextual action may only make sense for individual vehicles */
1870 
1871  if (_ctrl_pressed) {
1872  ShowOrdersWindow(v);
1873  } else {
1874  if (vehgroup.NumVehicles() == 1) {
1876  } else {
1877  ShowVehicleListWindow(v);
1878  }
1879  }
1880  break;
1881  }
1882 
1883  default: NOT_REACHED();
1884  }
1885 
1886  break;
1887  }
1888 
1890  ShowBuildVehicleWindow(INVALID_TILE, this->vli.vtype);
1891  break;
1892 
1894  ShowDropDownList(this, this->BuildActionDropdownList(VehicleListIdentifier::UnPack(this->window_number).type == VL_STANDARD, false), 0, WID_VL_MANAGE_VEHICLES_DROPDOWN);
1895  break;
1896  }
1897 
1898  case WID_VL_STOP_ALL:
1899  case WID_VL_START_ALL:
1900  Command<CMD_MASS_START_STOP>::Post(0, widget == WID_VL_START_ALL, true, this->vli);
1901  break;
1902  }
1903  }
1904 
1905  void OnDropdownSelect(int widget, int index) override
1906  {
1907  switch (widget) {
1909  this->UpdateVehicleGroupBy(static_cast<GroupBy>(index));
1910  break;
1911 
1913  this->vehgroups.SetSortType(index);
1914  break;
1915 
1917  assert(this->vehicles.size() != 0);
1918 
1919  switch (index) {
1920  case ADI_REPLACE: // Replace window
1922  break;
1923  case ADI_SERVICE: // Send for servicing
1924  case ADI_DEPOT: // Send to Depots
1925  Command<CMD_SEND_VEHICLE_TO_DEPOT>::Post(GetCmdSendToDepotMsg(this->vli.vtype), 0, DepotCommand::MassSend | (index == ADI_SERVICE ? DepotCommand::Service : DepotCommand::None), this->vli);
1926  break;
1927 
1928  default: NOT_REACHED();
1929  }
1930  break;
1931 
1932  default: NOT_REACHED();
1933  }
1934  this->SetDirty();
1935  }
1936 
1937  void OnGameTick() override
1938  {
1939  if (this->vehgroups.NeedResort()) {
1940  StationID station = (this->vli.type == VL_STATION_LIST) ? this->vli.index : INVALID_STATION;
1941 
1942  Debug(misc, 3, "Periodic resort {} list company {} at station {}", this->vli.vtype, this->owner, station);
1943  this->SetDirty();
1944  }
1945  }
1946 
1947  void OnResize() override
1948  {
1949  this->vscroll->SetCapacityFromWidget(this, WID_VL_LIST);
1950  }
1951 
1957  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1958  {
1959  if (!gui_scope && HasBit(data, 31) && this->vli.type == VL_SHARED_ORDERS) {
1960  /* Needs to be done in command-scope, so everything stays valid */
1961  this->vli.index = GB(data, 0, 20);
1962  this->window_number = this->vli.Pack();
1963  this->vehgroups.ForceRebuild();
1964  return;
1965  }
1966 
1967  if (data == 0) {
1968  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
1969  this->vehgroups.ForceRebuild();
1970  } else {
1971  this->vehgroups.ForceResort();
1972  }
1973  }
1974 };
1975 
1976 static WindowDesc _vehicle_list_other_desc(
1977  WDP_AUTO, "list_vehicles", 260, 246,
1979  0,
1980  _nested_vehicle_list, lengthof(_nested_vehicle_list)
1981 );
1982 
1983 static WindowDesc _vehicle_list_train_desc(
1984  WDP_AUTO, "list_vehicles_train", 325, 246,
1986  0,
1987  _nested_vehicle_list, lengthof(_nested_vehicle_list)
1988 );
1989 
1990 static void ShowVehicleListWindowLocal(CompanyID company, VehicleListType vlt, VehicleType vehicle_type, uint32 unique_number)
1991 {
1992  if (!Company::IsValidID(company) && company != OWNER_NONE) return;
1993 
1994  WindowNumber num = VehicleListIdentifier(vlt, vehicle_type, company, unique_number).Pack();
1995  if (vehicle_type == VEH_TRAIN) {
1996  AllocateWindowDescFront<VehicleListWindow>(&_vehicle_list_train_desc, num);
1997  } else {
1998  _vehicle_list_other_desc.cls = GetWindowClassForVehicleType(vehicle_type);
1999  AllocateWindowDescFront<VehicleListWindow>(&_vehicle_list_other_desc, num);
2000  }
2001 }
2002 
2003 void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type)
2004 {
2005  /* If _settings_client.gui.advanced_vehicle_list > 1, display the Advanced list
2006  * if _settings_client.gui.advanced_vehicle_list == 1, display Advanced list only for local company
2007  * if _ctrl_pressed, do the opposite action (Advanced list x Normal list)
2008  */
2009 
2010  if ((_settings_client.gui.advanced_vehicle_list > (uint)(company != _local_company)) != _ctrl_pressed) {
2011  ShowCompanyGroup(company, vehicle_type);
2012  } else {
2013  ShowVehicleListWindowLocal(company, VL_STANDARD, vehicle_type, company);
2014  }
2015 }
2016 
2017 void ShowVehicleListWindow(const Vehicle *v)
2018 {
2019  ShowVehicleListWindowLocal(v->owner, VL_SHARED_ORDERS, v->type, v->FirstShared()->index);
2020 }
2021 
2022 void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, StationID station)
2023 {
2024  ShowVehicleListWindowLocal(company, VL_STATION_LIST, vehicle_type, station);
2025 }
2026 
2027 void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, TileIndex depot_tile)
2028 {
2029  uint16 depot_airport_index;
2030 
2031  if (vehicle_type == VEH_AIRCRAFT) {
2032  depot_airport_index = GetStationIndex(depot_tile);
2033  } else {
2034  depot_airport_index = GetDepotIndex(depot_tile);
2035  }
2036  ShowVehicleListWindowLocal(company, VL_DEPOT_LIST, vehicle_type, depot_airport_index);
2037 }
2038 
2039 
2040 /* Unified vehicle GUI - Vehicle Details Window */
2041 
2046 
2050  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2051  NWidget(WWT_CAPTION, COLOUR_GREY, WID_VD_CAPTION), SetDataTip(STR_VEHICLE_DETAILS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2052  NWidget(WWT_SHADEBOX, COLOUR_GREY),
2053  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
2054  NWidget(WWT_STICKYBOX, COLOUR_GREY),
2055  EndContainer(),
2056  NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_TOP_DETAILS), SetMinimalSize(405, 42), SetResize(1, 0), EndContainer(),
2057  NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_MIDDLE_DETAILS), SetMinimalSize(405, 45), SetResize(1, 0), EndContainer(),
2060  SetDataTip(AWV_DECREASE, STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP),
2062  SetDataTip(AWV_INCREASE, STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP),
2064  SetDataTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
2065  NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_SERVICING_INTERVAL), SetFill(1, 1), SetResize(1, 0), EndContainer(),
2066  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
2067  EndContainer(),
2068 };
2069 
2073  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2074  NWidget(WWT_CAPTION, COLOUR_GREY, WID_VD_CAPTION), SetDataTip(STR_VEHICLE_DETAILS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2075  NWidget(WWT_SHADEBOX, COLOUR_GREY),
2076  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
2077  NWidget(WWT_STICKYBOX, COLOUR_GREY),
2078  EndContainer(),
2079  NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_TOP_DETAILS), SetResize(1, 0), SetMinimalSize(405, 42), EndContainer(),
2081  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),
2082  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_VD_SCROLLBAR),
2083  EndContainer(),
2086  SetDataTip(AWV_DECREASE, STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP),
2088  SetDataTip(AWV_INCREASE, STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP),
2090  SetDataTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
2091  NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_SERVICING_INTERVAL), SetFill(1, 1), SetResize(1, 0), EndContainer(),
2092  EndContainer(),
2095  SetDataTip(STR_VEHICLE_DETAIL_TAB_CARGO, STR_VEHICLE_DETAILS_TRAIN_CARGO_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
2097  SetDataTip(STR_VEHICLE_DETAIL_TAB_INFORMATION, STR_VEHICLE_DETAILS_TRAIN_INFORMATION_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
2099  SetDataTip(STR_VEHICLE_DETAIL_TAB_CAPACITIES, STR_VEHICLE_DETAILS_TRAIN_CAPACITIES_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
2101  SetDataTip(STR_VEHICLE_DETAIL_TAB_TOTAL_CARGO, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CARGO_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
2102  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
2103  EndContainer(),
2104 };
2105 
2106 
2107 extern int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab);
2108 extern void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab);
2109 extern void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y);
2110 extern void DrawShipDetails(const Vehicle *v, int left, int right, int y);
2111 extern void DrawAircraftDetails(const Aircraft *v, int left, int right, int y);
2112 
2113 static StringID _service_interval_dropdown[] = {
2114  STR_VEHICLE_DETAILS_DEFAULT,
2115  STR_VEHICLE_DETAILS_DAYS,
2116  STR_VEHICLE_DETAILS_PERCENT,
2118 };
2119 
2123  Scrollbar *vscroll;
2124 
2127  {
2128  const Vehicle *v = Vehicle::Get(window_number);
2129 
2130  this->CreateNestedTree();
2131  this->vscroll = (v->type == VEH_TRAIN ? this->GetScrollbar(WID_VD_SCROLLBAR) : nullptr);
2132  this->FinishInitNested(window_number);
2133 
2134  this->owner = v->owner;
2135  this->tab = TDW_TAB_CARGO;
2136  }
2137 
2143  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2144  {
2145  if (data == VIWD_AUTOREPLACE) {
2146  /* Autoreplace replaced the vehicle.
2147  * Nothing to do for this window. */
2148  return;
2149  }
2150  if (!gui_scope) return;
2151  const Vehicle *v = Vehicle::Get(this->window_number);
2152  if (v->type == VEH_ROAD) {
2153  const NWidgetBase *nwid_info = this->GetWidget<NWidgetBase>(WID_VD_MIDDLE_DETAILS);
2154  uint aimed_height = this->GetRoadVehDetailsHeight(v);
2155  /* If the number of articulated parts changes, the size of the window must change too. */
2156  if (aimed_height != nwid_info->current_y) {
2157  this->ReInit();
2158  }
2159  }
2160  }
2161 
2168  {
2169  uint desired_height;
2170  if (v->HasArticulatedPart()) {
2171  /* An articulated RV has its text drawn under the sprite instead of after it, hence 15 pixels extra. */
2172  desired_height = WD_FRAMERECT_TOP + ScaleGUITrad(15) + 3 * FONT_HEIGHT_NORMAL + 2 + WD_FRAMERECT_BOTTOM;
2173  /* Add space for the cargo amount for each part. */
2174  for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
2175  if (u->cargo_cap != 0) desired_height += FONT_HEIGHT_NORMAL + 1;
2176  }
2177  } else {
2178  desired_height = WD_FRAMERECT_TOP + 4 * FONT_HEIGHT_NORMAL + 3 + WD_FRAMERECT_BOTTOM;
2179  }
2180  return desired_height;
2181  }
2182 
2183  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2184  {
2185  switch (widget) {
2186  case WID_VD_TOP_DETAILS: {
2187  Dimension dim = { 0, 0 };
2189 
2190  for (uint i = 0; i < 4; i++) SetDParamMaxValue(i, INT16_MAX);
2191  static const StringID info_strings[] = {
2192  STR_VEHICLE_INFO_MAX_SPEED,
2193  STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED,
2194  STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE,
2195  STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR,
2196  STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS
2197  };
2198  for (uint i = 0; i < lengthof(info_strings); i++) {
2199  dim = maxdim(dim, GetStringBoundingBox(info_strings[i]));
2200  }
2201  SetDParam(0, STR_VEHICLE_INFO_AGE);
2202  dim = maxdim(dim, GetStringBoundingBox(STR_VEHICLE_INFO_AGE_RUNNING_COST_YR));
2203  size->width = dim.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
2204  break;
2205  }
2206 
2207  case WID_VD_MIDDLE_DETAILS: {
2208  const Vehicle *v = Vehicle::Get(this->window_number);
2209  switch (v->type) {
2210  case VEH_ROAD:
2211  size->height = this->GetRoadVehDetailsHeight(v);
2212  break;
2213 
2214  case VEH_SHIP:
2215  size->height = WD_FRAMERECT_TOP + 4 * FONT_HEIGHT_NORMAL + 3 + WD_FRAMERECT_BOTTOM;
2216  break;
2217 
2218  case VEH_AIRCRAFT:
2219  size->height = WD_FRAMERECT_TOP + 5 * FONT_HEIGHT_NORMAL + 4 + WD_FRAMERECT_BOTTOM;
2220  break;
2221 
2222  default:
2223  NOT_REACHED(); // Train uses WID_VD_MATRIX instead.
2224  }
2225  break;
2226  }
2227 
2228  case WID_VD_MATRIX:
2230  size->height = 4 * resize->height;
2231  break;
2232 
2234  StringID *strs = _service_interval_dropdown;
2235  while (*strs != INVALID_STRING_ID) {
2236  *size = maxdim(*size, GetStringBoundingBox(*strs++));
2237  }
2238  size->width += padding.width;
2240  break;
2241  }
2242 
2244  SetDParamMaxValue(0, MAX_SERVINT_DAYS); // Roughly the maximum interval
2245  SetDParamMaxValue(1, MAX_YEAR * DAYS_IN_YEAR); // Roughly the maximum year
2246  size->width = std::max(
2247  GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT).width,
2248  GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS).width
2251  break;
2252  }
2253  }
2254 
2256  static bool IsVehicleServiceIntervalEnabled(const VehicleType vehicle_type, CompanyID company_id)
2257  {
2258  const VehicleDefaultSettings *vds = &Company::Get(company_id)->settings.vehicle;
2259  switch (vehicle_type) {
2260  default: NOT_REACHED();
2261  case VEH_TRAIN: return vds->servint_trains != 0;
2262  case VEH_ROAD: return vds->servint_roadveh != 0;
2263  case VEH_SHIP: return vds->servint_ships != 0;
2264  case VEH_AIRCRAFT: return vds->servint_aircraft != 0;
2265  }
2266  }
2267 
2279  static void DrawVehicleDetails(const Vehicle *v, int left, int right, int y, int vscroll_pos, uint vscroll_cap, TrainDetailsWindowTabs det_tab)
2280  {
2281  switch (v->type) {
2282  case VEH_TRAIN: DrawTrainDetails(Train::From(v), left, right, y, vscroll_pos, vscroll_cap, det_tab); break;
2283  case VEH_ROAD: DrawRoadVehDetails(v, left, right, y); break;
2284  case VEH_SHIP: DrawShipDetails(v, left, right, y); break;
2285  case VEH_AIRCRAFT: DrawAircraftDetails(Aircraft::From(v), left, right, y); break;
2286  default: NOT_REACHED();
2287  }
2288  }
2289 
2290  void SetStringParameters(int widget) const override
2291  {
2292  if (widget == WID_VD_CAPTION) SetDParam(0, Vehicle::Get(this->window_number)->index);
2293  }
2294 
2295  void DrawWidget(const Rect &r, int widget) const override
2296  {
2297  const Vehicle *v = Vehicle::Get(this->window_number);
2298 
2299  switch (widget) {
2300  case WID_VD_TOP_DETAILS: {
2301  int y = r.top + WD_FRAMERECT_TOP;
2302 
2303  /* Draw running cost */
2304  SetDParam(1, v->age / DAYS_IN_LEAP_YEAR);
2305  SetDParam(0, (v->age + DAYS_IN_YEAR < v->max_age) ? STR_VEHICLE_INFO_AGE : STR_VEHICLE_INFO_AGE_RED);
2308  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_AGE_RUNNING_COST_YR);
2309  y += FONT_HEIGHT_NORMAL;
2310 
2311  /* Draw max speed */
2312  StringID string;
2313  if (v->type == VEH_TRAIN ||
2314  (v->type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL)) {
2315  const GroundVehicleCache *gcache = v->GetGroundVehicleCache();
2316  SetDParam(2, v->GetDisplayMaxSpeed());
2317  SetDParam(1, gcache->cached_power);
2318  SetDParam(0, gcache->cached_weight);
2319  SetDParam(3, gcache->cached_max_te / 1000);
2320  if (v->type == VEH_TRAIN && (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL ||
2321  GetRailTypeInfo(Train::From(v)->railtype)->acceleration_type == 2)) {
2322  string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED;
2323  } else {
2324  string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE;
2325  }
2326  } else {
2327  SetDParam(0, v->GetDisplayMaxSpeed());
2328  if (v->type == VEH_AIRCRAFT) {
2330  if (Aircraft::From(v)->GetRange() > 0) {
2331  SetDParam(2, Aircraft::From(v)->GetRange());
2332  string = STR_VEHICLE_INFO_MAX_SPEED_TYPE_RANGE;
2333  } else {
2334  string = STR_VEHICLE_INFO_MAX_SPEED_TYPE;
2335  }
2336  } else {
2337  string = STR_VEHICLE_INFO_MAX_SPEED;
2338  }
2339  }
2340  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, string);
2341  y += FONT_HEIGHT_NORMAL;
2342 
2343  /* Draw profit */
2346  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR);
2347  y += FONT_HEIGHT_NORMAL;
2348 
2349  /* Draw breakdown & reliability */
2352  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS);
2353  break;
2354  }
2355 
2356  case WID_VD_MATRIX:
2357  /* For trains only. */
2358  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);
2359  break;
2360 
2361  case WID_VD_MIDDLE_DETAILS: {
2362  /* For other vehicles, at the place of the matrix. */
2363  bool rtl = _current_text_dir == TD_RTL;
2365 
2366  uint text_left = r.left + (rtl ? 0 : sprite_width);
2367  uint text_right = r.right - (rtl ? sprite_width : 0);
2368 
2369  /* Articulated road vehicles use a complete line. */
2370  if (v->type == VEH_ROAD && v->HasArticulatedPart()) {
2372  } else {
2373  uint sprite_left = rtl ? text_right : r.left;
2374  uint sprite_right = rtl ? r.right : text_left;
2375 
2377  }
2378  DrawVehicleDetails(v, text_left + WD_FRAMERECT_LEFT, text_right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, 0, 0, this->tab);
2379  break;
2380  }
2381 
2383  /* Draw service interval text */
2384  SetDParam(0, v->GetServiceInterval());
2386  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + (r.bottom - r.top + 1 - FONT_HEIGHT_NORMAL) / 2,
2387  v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS);
2388  break;
2389  }
2390  }
2391 
2393  void OnPaint() override
2394  {
2395  const Vehicle *v = Vehicle::Get(this->window_number);
2396 
2397  if (v->type == VEH_TRAIN) {
2398  this->DisableWidget(this->tab + WID_VD_DETAILS_CARGO_CARRIED);
2399  this->vscroll->SetCount(GetTrainDetailsWndVScroll(v->index, this->tab));
2400  }
2401 
2402  /* Disable service-scroller when interval is set to disabled */
2406  WIDGET_LIST_END);
2407 
2408  StringID str = v->ServiceIntervalIsCustom() ?
2409  (v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_PERCENT : STR_VEHICLE_DETAILS_DAYS) :
2410  STR_VEHICLE_DETAILS_DEFAULT;
2411  this->GetWidget<NWidgetCore>(WID_VD_SERVICE_INTERVAL_DROPDOWN)->widget_data = str;
2412 
2413  this->DrawWidgets();
2414  }
2415 
2416  void OnClick(Point pt, int widget, int click_count) override
2417  {
2418  switch (widget) {
2419  case WID_VD_INCREASE_SERVICING_INTERVAL: // increase int
2420  case WID_VD_DECREASE_SERVICING_INTERVAL: { // decrease int
2421  int mod = _ctrl_pressed ? 5 : 10;
2422  const Vehicle *v = Vehicle::Get(this->window_number);
2423 
2424  mod = (widget == WID_VD_DECREASE_SERVICING_INTERVAL) ? -mod : mod;
2425  mod = GetServiceIntervalClamped(mod + v->GetServiceInterval(), v->ServiceIntervalIsPercent());
2426  if (mod == v->GetServiceInterval()) return;
2427 
2428  Command<CMD_CHANGE_SERVICE_INT>::Post(STR_ERROR_CAN_T_CHANGE_SERVICING, v->index, mod, true, v->ServiceIntervalIsPercent());
2429  break;
2430  }
2431 
2433  const Vehicle *v = Vehicle::Get(this->window_number);
2434  ShowDropDownMenu(this, _service_interval_dropdown, v->ServiceIntervalIsCustom() ? (v->ServiceIntervalIsPercent() ? 2 : 1) : 0, widget, 0, 0);
2435  break;
2436  }
2437 
2442  this->SetWidgetsDisabledState(false,
2447  widget,
2448  WIDGET_LIST_END);
2449 
2450  this->tab = (TrainDetailsWindowTabs)(widget - WID_VD_DETAILS_CARGO_CARRIED);
2451  this->SetDirty();
2452  break;
2453  }
2454  }
2455 
2456  void OnDropdownSelect(int widget, int index) override
2457  {
2458  switch (widget) {
2460  const Vehicle *v = Vehicle::Get(this->window_number);
2461  bool iscustom = index != 0;
2462  bool ispercent = iscustom ? (index == 2) : Company::Get(v->owner)->settings.vehicle.servint_ispercent;
2463  uint16 interval = GetServiceIntervalClamped(v->GetServiceInterval(), ispercent);
2464  Command<CMD_CHANGE_SERVICE_INT>::Post(STR_ERROR_CAN_T_CHANGE_SERVICING, v->index, interval, iscustom, ispercent);
2465  break;
2466  }
2467  }
2468  }
2469 
2470  void OnResize() override
2471  {
2472  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_VD_MATRIX);
2473  if (nwi != nullptr) {
2474  this->vscroll->SetCapacityFromWidget(this, WID_VD_MATRIX);
2475  }
2476  }
2477 };
2478 
2481  WDP_AUTO, "view_vehicle_details_train", 405, 178,
2483  0,
2485 );
2486 
2489  WDP_AUTO, "view_vehicle_details", 405, 113,
2491  0,
2493 );
2494 
2496 static void ShowVehicleDetailsWindow(const Vehicle *v)
2497 {
2500  AllocateWindowDescFront<VehicleDetailsWindow>((v->type == VEH_TRAIN) ? &_train_vehicle_details_desc : &_nontrain_vehicle_details_desc, v->index);
2501 }
2502 
2503 
2504 /* Unified vehicle GUI - Vehicle View Window */
2505 
2509  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2510  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_RENAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_NULL /* filled in later */),
2511  NWidget(WWT_CAPTION, COLOUR_GREY, WID_VV_CAPTION), SetDataTip(STR_VEHICLE_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2512  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_NULL /* filled in later */),
2513  NWidget(WWT_DEBUGBOX, COLOUR_GREY),
2514  NWidget(WWT_SHADEBOX, COLOUR_GREY),
2515  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
2516  NWidget(WWT_STICKYBOX, COLOUR_GREY),
2517  EndContainer(),
2519  NWidget(WWT_PANEL, COLOUR_GREY),
2520  NWidget(WWT_INSET, COLOUR_GREY), SetPadding(2, 2, 2, 2),
2521  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_VV_VIEWPORT), SetMinimalSize(226, 84), SetResize(1, 1),
2522  EndContainer(),
2523  EndContainer(),
2526  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_GOTO_DEPOT), SetMinimalSize(18, 18), SetDataTip(0x0 /* filled later */, 0x0 /* filled later */),
2527  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_CLONE), SetMinimalSize(18, 18), SetDataTip(0x0 /* filled later */, 0x0 /* filled later */),
2528  EndContainer(),
2529  /* For trains only, 'ignore signal' button. */
2531  SetDataTip(SPR_IGNORE_SIGNALS, STR_VEHICLE_VIEW_TRAIN_IGNORE_SIGNAL_TOOLTIP),
2533  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_REFIT), SetMinimalSize(18, 18), SetDataTip(SPR_REFIT_VEHICLE, 0x0 /* filled later */),
2534  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_TURN_AROUND), SetMinimalSize(18, 18),
2535  SetDataTip(SPR_FORCE_VEHICLE_TURN, STR_VEHICLE_VIEW_ROAD_VEHICLE_REVERSE_TOOLTIP),
2536  EndContainer(),
2537  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_SHOW_ORDERS), SetMinimalSize(18, 18), SetDataTip(SPR_SHOW_ORDERS, 0x0 /* filled later */),
2538  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_SHOW_DETAILS), SetMinimalSize(18, 18), SetDataTip(SPR_SHOW_VEHICLE_DETAILS, 0x0 /* filled later */),
2539  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(18, 0), SetResize(0, 1), EndContainer(),
2540  EndContainer(),
2541  EndContainer(),
2544  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_ORDER_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_VEHICLE_VIEW_ORDER_LOCATION_TOOLTIP),
2545  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
2546  EndContainer(),
2547 };
2548 
2551  WDP_AUTO, "view_vehicle", 250, 116,
2553  0,
2555 );
2556 
2562  WDP_AUTO, "view_vehicle_train", 250, 134,
2564  0,
2566 );
2567 
2568 
2569 /* Just to make sure, nobody has changed the vehicle type constants, as we are
2570  using them for array indexing in a number of places here. */
2571 static_assert(VEH_TRAIN == 0);
2572 static_assert(VEH_ROAD == 1);
2573 static_assert(VEH_SHIP == 2);
2574 static_assert(VEH_AIRCRAFT == 3);
2575 
2580  ZOOM_LVL_SHIP,
2582 };
2583 
2584 /* Constants for geometry of vehicle view viewport */
2585 static const int VV_INITIAL_VIEWPORT_WIDTH = 226;
2586 static const int VV_INITIAL_VIEWPORT_HEIGHT = 84;
2587 static const int VV_INITIAL_VIEWPORT_HEIGHT_TRAIN = 102;
2588 
2591  VCT_CMD_START_STOP = 0,
2592  VCT_CMD_CLONE_VEH,
2593  VCT_CMD_TURN_AROUND,
2594 };
2595 
2598  { // VCT_CMD_START_STOP
2599  STR_ERROR_CAN_T_STOP_START_TRAIN,
2600  STR_ERROR_CAN_T_STOP_START_ROAD_VEHICLE,
2601  STR_ERROR_CAN_T_STOP_START_SHIP,
2602  STR_ERROR_CAN_T_STOP_START_AIRCRAFT
2603  },
2604  { // VCT_CMD_CLONE_VEH
2605  STR_ERROR_CAN_T_BUY_TRAIN,
2606  STR_ERROR_CAN_T_BUY_ROAD_VEHICLE,
2607  STR_ERROR_CAN_T_BUY_SHIP,
2608  STR_ERROR_CAN_T_BUY_AIRCRAFT
2609  },
2610  { // VCT_CMD_TURN_AROUND
2611  STR_ERROR_CAN_T_REVERSE_DIRECTION_TRAIN,
2612  STR_ERROR_CAN_T_MAKE_ROAD_VEHICLE_TURN,
2613  INVALID_STRING_ID, // invalid for ships
2614  INVALID_STRING_ID // invalid for aircraft
2615  },
2616 };
2617 
2624 void CcStartStopVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id, bool)
2625 {
2626  if (result.Failed()) return;
2627 
2628  const Vehicle *v = Vehicle::GetIfValid(veh_id);
2629  if (v == nullptr || !v->IsPrimaryVehicle() || v->owner != _local_company) return;
2630 
2631  StringID msg = (v->vehstatus & VS_STOPPED) ? STR_VEHICLE_COMMAND_STOPPED : STR_VEHICLE_COMMAND_STARTED;
2632  Point pt = RemapCoords(v->x_pos, v->y_pos, v->z_pos);
2633  AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
2634 }
2635 
2641 void StartStopVehicle(const Vehicle *v, bool texteffect)
2642 {
2643  assert(v->IsPrimaryVehicle());
2644  Command<CMD_START_STOP_VEHICLE>::Post(_vehicle_msg_translation_table[VCT_CMD_START_STOP][v->type], texteffect ? CcStartStopVehicle : nullptr, v->tile, v->index, false);
2645 }
2646 
2648 static bool IsVehicleRefitable(const Vehicle *v)
2649 {
2650  if (!v->IsStoppedInDepot()) return false;
2651 
2652  do {
2653  if (IsEngineRefittable(v->engine_type)) return true;
2654  } while (v->IsGroundVehicle() && (v = v->Next()) != nullptr);
2655 
2656  return false;
2657 }
2658 
2661 private:
2666 
2669 
2672  };
2673  bool mouse_over_start_stop = false;
2674 
2680  {
2681  switch (plane) {
2682  case SEL_DC_GOTO_DEPOT:
2683  case SEL_DC_CLONE:
2684  this->GetWidget<NWidgetStacked>(WID_VV_SELECT_DEPOT_CLONE)->SetDisplayedPlane(plane - SEL_DC_BASEPLANE);
2685  break;
2686 
2687  case SEL_RT_REFIT:
2688  case SEL_RT_TURN_AROUND:
2689  this->GetWidget<NWidgetStacked>(WID_VV_SELECT_REFIT_TURN)->SetDisplayedPlane(plane - SEL_RT_BASEPLANE);
2690  break;
2691 
2692  default:
2693  NOT_REACHED();
2694  }
2695  }
2696 
2697 public:
2699  {
2700  this->flags |= WF_DISABLE_VP_SCROLL;
2701  this->CreateNestedTree();
2702 
2703  /* Sprites for the 'send to depot' button indexed by vehicle type. */
2704  static const SpriteID vehicle_view_goto_depot_sprites[] = {
2705  SPR_SEND_TRAIN_TODEPOT,
2706  SPR_SEND_ROADVEH_TODEPOT,
2707  SPR_SEND_SHIP_TODEPOT,
2708  SPR_SEND_AIRCRAFT_TODEPOT,
2709  };
2710  const Vehicle *v = Vehicle::Get(window_number);
2711  this->GetWidget<NWidgetCore>(WID_VV_GOTO_DEPOT)->widget_data = vehicle_view_goto_depot_sprites[v->type];
2712 
2713  /* Sprites for the 'clone vehicle' button indexed by vehicle type. */
2714  static const SpriteID vehicle_view_clone_sprites[] = {
2716  SPR_CLONE_ROADVEH,
2717  SPR_CLONE_SHIP,
2718  SPR_CLONE_AIRCRAFT,
2719  };
2720  this->GetWidget<NWidgetCore>(WID_VV_CLONE)->widget_data = vehicle_view_clone_sprites[v->type];
2721 
2722  switch (v->type) {
2723  case VEH_TRAIN:
2724  this->GetWidget<NWidgetCore>(WID_VV_TURN_AROUND)->tool_tip = STR_VEHICLE_VIEW_TRAIN_REVERSE_TOOLTIP;
2725  break;
2726 
2727  case VEH_ROAD:
2728  break;
2729 
2730  case VEH_SHIP:
2731  case VEH_AIRCRAFT:
2732  this->SelectPlane(SEL_RT_REFIT);
2733  break;
2734 
2735  default: NOT_REACHED();
2736  }
2737  this->FinishInitNested(window_number);
2738  this->owner = v->owner;
2739  this->GetWidget<NWidgetViewport>(WID_VV_VIEWPORT)->InitializeViewport(this, this->window_number | (1 << 31), ScaleZoomGUI(_vehicle_view_zoom_levels[v->type]));
2740 
2741  this->GetWidget<NWidgetCore>(WID_VV_START_STOP)->tool_tip = STR_VEHICLE_VIEW_TRAIN_STATUS_START_STOP_TOOLTIP + v->type;
2742  this->GetWidget<NWidgetCore>(WID_VV_RENAME)->tool_tip = STR_VEHICLE_DETAILS_TRAIN_RENAME + v->type;
2743  this->GetWidget<NWidgetCore>(WID_VV_LOCATION)->tool_tip = STR_VEHICLE_VIEW_TRAIN_CENTER_TOOLTIP + v->type;
2744  this->GetWidget<NWidgetCore>(WID_VV_REFIT)->tool_tip = STR_VEHICLE_VIEW_TRAIN_REFIT_TOOLTIP + v->type;
2745  this->GetWidget<NWidgetCore>(WID_VV_GOTO_DEPOT)->tool_tip = STR_VEHICLE_VIEW_TRAIN_SEND_TO_DEPOT_TOOLTIP + v->type;
2746  this->GetWidget<NWidgetCore>(WID_VV_SHOW_ORDERS)->tool_tip = STR_VEHICLE_VIEW_TRAIN_ORDERS_TOOLTIP + v->type;
2747  this->GetWidget<NWidgetCore>(WID_VV_SHOW_DETAILS)->tool_tip = STR_VEHICLE_VIEW_TRAIN_SHOW_DETAILS_TOOLTIP + v->type;
2748  this->GetWidget<NWidgetCore>(WID_VV_CLONE)->tool_tip = STR_VEHICLE_VIEW_CLONE_TRAIN_INFO + v->type;
2749 
2750  this->UpdateButtonStatus();
2751  }
2752 
2753  void Close() override
2754  {
2755  CloseWindowById(WC_VEHICLE_ORDERS, this->window_number, false);
2756  CloseWindowById(WC_VEHICLE_REFIT, this->window_number, false);
2757  CloseWindowById(WC_VEHICLE_DETAILS, this->window_number, false);
2758  CloseWindowById(WC_VEHICLE_TIMETABLE, this->window_number, false);
2759  this->Window::Close();
2760  }
2761 
2762  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2763  {
2764  const Vehicle *v = Vehicle::Get(this->window_number);
2765  switch (widget) {
2766  case WID_VV_START_STOP:
2767  size->height = std::max({size->height, GetSpriteSize(SPR_WARNING_SIGN).height, GetSpriteSize(SPR_FLAG_VEH_STOPPED).height, GetSpriteSize(SPR_FLAG_VEH_RUNNING).height}) + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM;
2768  break;
2769 
2770  case WID_VV_FORCE_PROCEED:
2771  if (v->type != VEH_TRAIN) {
2772  size->height = 0;
2773  size->width = 0;
2774  }
2775  break;
2776 
2777  case WID_VV_VIEWPORT:
2778  size->width = VV_INITIAL_VIEWPORT_WIDTH;
2779  size->height = (v->type == VEH_TRAIN) ? VV_INITIAL_VIEWPORT_HEIGHT_TRAIN : VV_INITIAL_VIEWPORT_HEIGHT;
2780  break;
2781  }
2782  }
2783 
2784  void OnPaint() override
2785  {
2786  const Vehicle *v = Vehicle::Get(this->window_number);
2787  bool is_localcompany = v->owner == _local_company;
2788  bool refitable_and_stopped_in_depot = IsVehicleRefitable(v);
2789 
2790  this->SetWidgetDisabledState(WID_VV_RENAME, !is_localcompany);
2791  this->SetWidgetDisabledState(WID_VV_GOTO_DEPOT, !is_localcompany);
2792  this->SetWidgetDisabledState(WID_VV_REFIT, !refitable_and_stopped_in_depot || !is_localcompany);
2793  this->SetWidgetDisabledState(WID_VV_CLONE, !is_localcompany);
2794 
2795  if (v->type == VEH_TRAIN) {
2797  this->SetWidgetDisabledState(WID_VV_FORCE_PROCEED, !is_localcompany);
2798  }
2799 
2800  if (v->type == VEH_TRAIN || v->type == VEH_ROAD) {
2801  this->SetWidgetDisabledState(WID_VV_TURN_AROUND, !is_localcompany);
2802  }
2803 
2805 
2806  this->DrawWidgets();
2807  }
2808 
2809  void SetStringParameters(int widget) const override
2810  {
2811  if (widget != WID_VV_CAPTION) return;
2812 
2813  const Vehicle *v = Vehicle::Get(this->window_number);
2814  SetDParam(0, v->index);
2815  }
2816 
2817  void DrawWidget(const Rect &r, int widget) const override
2818  {
2819  if (widget != WID_VV_START_STOP) return;
2820 
2821  const Vehicle *v = Vehicle::Get(this->window_number);
2822  StringID str;
2823  TextColour text_colour = TC_FROMSTRING;
2824  if (v->vehstatus & VS_CRASHED) {
2825  str = STR_VEHICLE_STATUS_CRASHED;
2826  } else if (v->type != VEH_AIRCRAFT && v->breakdown_ctr == 1) { // check for aircraft necessary?
2827  str = STR_VEHICLE_STATUS_BROKEN_DOWN;
2828  } else if (v->vehstatus & VS_STOPPED && (!mouse_over_start_stop || v->IsStoppedInDepot())) {
2829  if (v->type == VEH_TRAIN) {
2830  if (v->cur_speed == 0) {
2831  if (Train::From(v)->gcache.cached_power == 0) {
2832  str = STR_VEHICLE_STATUS_TRAIN_NO_POWER;
2833  } else {
2834  str = STR_VEHICLE_STATUS_STOPPED;
2835  }
2836  } else {
2837  SetDParam(0, v->GetDisplaySpeed());
2838  str = STR_VEHICLE_STATUS_TRAIN_STOPPING_VEL;
2839  }
2840  } else { // no train
2841  str = STR_VEHICLE_STATUS_STOPPED;
2842  }
2843  } else if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_TRAIN_STUCK) && !v->current_order.IsType(OT_LOADING)) {
2844  str = STR_VEHICLE_STATUS_TRAIN_STUCK;
2845  } else if (v->type == VEH_AIRCRAFT && HasBit(Aircraft::From(v)->flags, VAF_DEST_TOO_FAR) && !v->current_order.IsType(OT_LOADING)) {
2846  str = STR_VEHICLE_STATUS_AIRCRAFT_TOO_FAR;
2847  } else { // vehicle is in a "normal" state, show current order
2848  if (mouse_over_start_stop) {
2849  if (v->vehstatus & VS_STOPPED) {
2850  text_colour = TC_RED | TC_FORCED;
2851  } else if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_TRAIN_STUCK) && !v->current_order.IsType(OT_LOADING)) {
2852  text_colour = TC_ORANGE | TC_FORCED;
2853  }
2854  }
2855  switch (v->current_order.GetType()) {
2856  case OT_GOTO_STATION: {
2858  SetDParam(1, v->GetDisplaySpeed());
2859  str = HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_STATION_VEL : STR_VEHICLE_STATUS_HEADING_FOR_STATION_VEL;
2860  break;
2861  }
2862 
2863  case OT_GOTO_DEPOT: {
2864  SetDParam(0, v->type);
2866  SetDParam(2, v->GetDisplaySpeed());
2867  if (v->current_order.GetDestination() == INVALID_DEPOT) {
2868  /* This case *only* happens when multiple nearest depot orders
2869  * follow each other (including an order list only one order: a
2870  * nearest depot order) and there are no reachable depots.
2871  * It is primarily to guard for the case that there is no
2872  * depot with index 0, which would be used as fallback for
2873  * evaluating the string in the status bar. */
2874  str = STR_EMPTY;
2875  } else if (v->current_order.GetDepotActionType() & ODATFB_HALT) {
2876  str = HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_VEL;
2877  } else {
2878  str = HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_SERVICE_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_SERVICE_VEL;
2879  }
2880  break;
2881  }
2882 
2883  case OT_LOADING:
2884  str = STR_VEHICLE_STATUS_LOADING_UNLOADING;
2885  break;
2886 
2887  case OT_GOTO_WAYPOINT: {
2888  assert(v->type == VEH_TRAIN || v->type == VEH_SHIP);
2890  str = HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_WAYPOINT_VEL : STR_VEHICLE_STATUS_HEADING_FOR_WAYPOINT_VEL;
2891  SetDParam(1, v->GetDisplaySpeed());
2892  break;
2893  }
2894 
2895  case OT_LEAVESTATION:
2896  if (v->type != VEH_AIRCRAFT) {
2897  str = STR_VEHICLE_STATUS_LEAVING;
2898  break;
2899  }
2900  FALLTHROUGH;
2901  default:
2902  if (v->GetNumManualOrders() == 0) {
2903  str = STR_VEHICLE_STATUS_NO_ORDERS_VEL;
2904  SetDParam(0, v->GetDisplaySpeed());
2905  } else {
2906  str = STR_EMPTY;
2907  }
2908  break;
2909  }
2910  }
2911 
2912  /* Draw the flag plus orders. */
2913  bool rtl = (_current_text_dir == TD_RTL);
2914  uint text_offset = std::max({GetSpriteSize(SPR_WARNING_SIGN).width, GetSpriteSize(SPR_FLAG_VEH_STOPPED).width, GetSpriteSize(SPR_FLAG_VEH_RUNNING).width}) + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
2915  int height = r.bottom - r.top;
2916  int text_left = r.left + (rtl ? (uint)WD_FRAMERECT_LEFT : text_offset);
2917  int text_right = r.right - (rtl ? text_offset : (uint)WD_FRAMERECT_RIGHT);
2918  int text_top = r.top + WD_FRAMERECT_TOP + (height - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM - FONT_HEIGHT_NORMAL) / 2;
2919  int image = ((v->vehstatus & VS_STOPPED) != 0) ? SPR_FLAG_VEH_STOPPED : (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) ? SPR_WARNING_SIGN : SPR_FLAG_VEH_RUNNING;
2920  int image_left = (rtl ? text_right + 1 : r.left) + WD_IMGBTN_LEFT;
2921  int image_top = r.top + WD_IMGBTN_TOP + (height - WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM - GetSpriteSize(image).height) / 2;
2922  int lowered = this->IsWidgetLowered(WID_VV_START_STOP) ? 1 : 0;
2923  DrawSprite(image, PAL_NONE, image_left + lowered, image_top + lowered);
2924  DrawString(text_left + lowered, text_right + lowered, text_top + lowered, str, text_colour, SA_HOR_CENTER);
2925  }
2926 
2927  void OnClick(Point pt, int widget, int click_count) override
2928  {
2929  const Vehicle *v = Vehicle::Get(this->window_number);
2930 
2931  switch (widget) {
2932  case WID_VV_RENAME: { // rename
2933  SetDParam(0, v->index);
2934  ShowQueryString(STR_VEHICLE_NAME, STR_QUERY_RENAME_TRAIN_CAPTION + v->type,
2936  break;
2937  }
2938 
2939  case WID_VV_START_STOP: // start stop
2940  StartStopVehicle(v, false);
2941  break;
2942 
2943  case WID_VV_ORDER_LOCATION: {
2944  /* Scroll to current order destination */
2945  TileIndex tile = v->current_order.GetLocation(v);
2946  if (tile == INVALID_TILE) break;
2947 
2948  if (_ctrl_pressed) {
2950  } else {
2951  ScrollMainWindowToTile(tile);
2952  }
2953  break;
2954  }
2955 
2956  case WID_VV_LOCATION: // center main view
2957  if (_ctrl_pressed) {
2959  } else {
2960  const Window *mainwindow = FindWindowById(WC_MAIN_WINDOW, 0);
2961  if (click_count > 1 && mainwindow->viewport->zoom <= ZOOM_LVL_OUT_4X) {
2962  /* main window 'follows' vehicle */
2963  mainwindow->viewport->follow_vehicle = v->index;
2964  } else {
2965  ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
2966  }
2967  }
2968  break;
2969 
2970  case WID_VV_GOTO_DEPOT: // goto hangar
2972  break;
2973  case WID_VV_REFIT: // refit
2975  break;
2976  case WID_VV_SHOW_ORDERS: // show orders
2977  if (_ctrl_pressed) {
2979  } else {
2980  ShowOrdersWindow(v);
2981  }
2982  break;
2983  case WID_VV_SHOW_DETAILS: // show details
2984  if (_ctrl_pressed) {
2986  } else {
2988  }
2989  break;
2990  case WID_VV_CLONE: // clone vehicle
2991  /* Suppress the vehicle GUI when share-cloning.
2992  * There is no point to it except for starting the vehicle.
2993  * For starting the vehicle the player has to open the depot GUI, which is
2994  * most likely already open, but is also visible in the vehicle viewport. */
2996  _ctrl_pressed ? nullptr : CcCloneVehicle,
2997  v->tile, v->index, _ctrl_pressed);
2998  break;
2999  case WID_VV_TURN_AROUND: // turn around
3000  assert(v->IsGroundVehicle());
3001  if (v->type == VEH_ROAD) {
3003  } else {
3005  }
3006  break;
3007  case WID_VV_FORCE_PROCEED: // force proceed
3008  assert(v->type == VEH_TRAIN);
3009  Command<CMD_FORCE_TRAIN_PROCEED>::Post(STR_ERROR_CAN_T_MAKE_TRAIN_PASS_SIGNAL, v->tile, v->index);
3010  break;
3011  }
3012  }
3013 
3014  void OnQueryTextFinished(char *str) override
3015  {
3016  if (str == nullptr) return;
3017 
3018  Command<CMD_RENAME_VEHICLE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type, this->window_number, str);
3019  }
3020 
3021  void OnMouseOver(Point pt, int widget) override
3022  {
3023  bool start_stop = widget == WID_VV_START_STOP;
3024  if (start_stop != mouse_over_start_stop) {
3025  mouse_over_start_stop = start_stop;
3027  }
3028  }
3029 
3030  void OnResize() override
3031  {
3032  if (this->viewport != nullptr) {
3033  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_VV_VIEWPORT);
3034  nvp->UpdateViewportCoordinates(this);
3035  }
3036  }
3037 
3038  void UpdateButtonStatus()
3039  {
3040  const Vehicle *v = Vehicle::Get(this->window_number);
3041  bool veh_stopped = v->IsStoppedInDepot();
3042 
3043  /* Widget WID_VV_GOTO_DEPOT must be hidden if the vehicle is already stopped in depot.
3044  * Widget WID_VV_CLONE_VEH should then be shown, since cloning is allowed only while in depot and stopped.
3045  */
3046  PlaneSelections plane = veh_stopped ? SEL_DC_CLONE : SEL_DC_GOTO_DEPOT;
3047  NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(WID_VV_SELECT_DEPOT_CLONE); // Selection widget 'send to depot' / 'clone'.
3048  if (nwi->shown_plane + SEL_DC_BASEPLANE != plane) {
3049  this->SelectPlane(plane);
3051  }
3052  /* The same system applies to widget WID_VV_REFIT_VEH and VVW_WIDGET_TURN_AROUND.*/
3053  if (v->IsGroundVehicle()) {
3054  PlaneSelections plane = veh_stopped ? SEL_RT_REFIT : SEL_RT_TURN_AROUND;
3055  NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(WID_VV_SELECT_REFIT_TURN);
3056  if (nwi->shown_plane + SEL_RT_BASEPLANE != plane) {
3057  this->SelectPlane(plane);
3059  }
3060  }
3061  }
3062 
3068  void OnInvalidateData(int data = 0, bool gui_scope = true) override
3069  {
3070  if (data == VIWD_AUTOREPLACE) {
3071  /* Autoreplace replaced the vehicle.
3072  * Nothing to do for this window. */
3073  return;
3074  }
3075 
3076  this->UpdateButtonStatus();
3077  }
3078 
3079  bool IsNewGRFInspectable() const override
3080  {
3081  return ::IsNewGRFInspectable(GetGrfSpecFeature(Vehicle::Get(this->window_number)->type), this->window_number);
3082  }
3083 
3084  void ShowNewGRFInspectWindow() const override
3085  {
3086  ::ShowNewGRFInspectWindow(GetGrfSpecFeature(Vehicle::Get(this->window_number)->type), this->window_number);
3087  }
3088 };
3089 
3090 
3093 {
3094  AllocateWindowDescFront<VehicleViewWindow>((v->type == VEH_TRAIN) ? &_train_view_desc : &_vehicle_view_desc, v->index);
3095 }
3096 
3102 bool VehicleClicked(const Vehicle *v)
3103 {
3104  assert(v != nullptr);
3105  if (!(_thd.place_mode & HT_VEHICLE)) return false;
3106 
3107  v = v->First();
3108  if (!v->IsPrimaryVehicle()) return false;
3109 
3110  return _thd.GetCallbackWnd()->OnVehicleSelect(v);
3111 }
3112 
3113 void StopGlobalFollowVehicle(const Vehicle *v)
3114 {
3116  if (w != nullptr && w->viewport->follow_vehicle == v->index) {
3117  ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos, true); // lock the main view on the vehicle's last position
3119  }
3120 }
3121 
3122 
3129 void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16)
3130 {
3131  if (result.Failed()) return;
3132 
3133  const Vehicle *v = Vehicle::Get(new_veh_id);
3135 }
3136 
3143 {
3144  switch (v->type) {
3145  case VEH_TRAIN:
3146  return Train::From(v)->GetDisplayImageWidth();
3147 
3148  case VEH_ROAD:
3150 
3151  default:
3152  bool rtl = _current_text_dir == TD_RTL;
3153  VehicleSpriteSeq seq;
3154  v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
3155  Rect rec;
3156  seq.GetBounds(&rec);
3157  return UnScaleGUI(rec.right - rec.left + 1);
3158  }
3159 }
3160 
3166 int GetVehicleWidth(const Vehicle *v, EngineImageType image_type)
3167 {
3168  if (v->type == VEH_TRAIN || v->type == VEH_ROAD) {
3169  int vehicle_width = 0;
3170  for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
3171  vehicle_width += GetSingleVehicleWidth(u, image_type);
3172  }
3173  return vehicle_width;
3174  } else {
3175  return GetSingleVehicleWidth(v, image_type);
3176  }
3177 }
3178 
3185 {
3186  bool rtl = _current_text_dir == TD_RTL;
3187 
3188  _cursor.sprite_count = 0;
3189  int total_width = 0;
3190  int y_offset = 0;
3191  bool rotor_seq = false; // Whether to draw the rotor of the vehicle in this step.
3192  bool is_ground_vehicle = v->IsGroundVehicle();
3193 
3194  while (v != nullptr) {
3195  if (total_width >= ScaleGUITrad(2 * (int)VEHICLEINFO_FULL_VEHICLE_WIDTH)) break;
3196 
3198  VehicleSpriteSeq seq;
3199 
3200  if (rotor_seq) {
3201  GetCustomRotorSprite(Aircraft::From(v), image_type, &seq);
3202  if (!seq.IsValid()) seq.Set(SPR_ROTOR_STOPPED);
3203  y_offset = - ScaleGUITrad(5);
3204  } else {
3205  v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
3206  }
3207 
3208  if (_cursor.sprite_count + seq.count > lengthof(_cursor.sprite_seq)) break;
3209 
3210  for (uint i = 0; i < seq.count; ++i) {
3211  PaletteID pal2 = (v->vehstatus & VS_CRASHED) || !seq.seq[i].pal ? pal : seq.seq[i].pal;
3212  _cursor.sprite_seq[_cursor.sprite_count].sprite = seq.seq[i].sprite;
3213  _cursor.sprite_seq[_cursor.sprite_count].pal = pal2;
3214  _cursor.sprite_pos[_cursor.sprite_count].x = rtl ? -total_width : total_width;
3215  _cursor.sprite_pos[_cursor.sprite_count].y = y_offset;
3216  _cursor.sprite_count++;
3217  }
3218 
3219  if (v->type == VEH_AIRCRAFT && v->subtype == AIR_HELICOPTER && !rotor_seq) {
3220  /* Draw rotor part in the next step. */
3221  rotor_seq = true;
3222  } else {
3223  total_width += GetSingleVehicleWidth(v, image_type);
3224  v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr;
3225  }
3226  }
3227 
3228  if (is_ground_vehicle) {
3229  /* Center trains and road vehicles on the front vehicle */
3230  int offs = (ScaleGUITrad(VEHICLEINFO_FULL_VEHICLE_WIDTH) - total_width) / 2;
3231  if (rtl) offs = -offs;
3232  for (uint i = 0; i < _cursor.sprite_count; ++i) {
3233  _cursor.sprite_pos[i].x += offs;
3234  }
3235  }
3236 
3237  UpdateCursorSize();
3238 }
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:442
IsVehicleRefitable
static bool IsVehicleRefitable(const Vehicle *v)
Checks whether the vehicle may be refitted at the moment.
Definition: vehicle_gui.cpp:2648
VehicleListType
VehicleListType
Vehicle List type flags.
Definition: vehiclelist.h:19
WID_VL_AVAILABLE_VEHICLES
@ WID_VL_AVAILABLE_VEHICLES
Available vehicles.
Definition: vehicle_widget.h:75
Vehicle::GetGroundVehicleCache
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
Definition: vehicle.cpp:2906
Vehicle::IsChainInDepot
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Definition: vehicle_base.h:527
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:1651
VehicleViewWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: vehicle_gui.cpp:2784
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:2668
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:64
CountDigitsForAllocatingSpace
uint CountDigitsForAllocatingSpace(uint number)
Get the number of digits of space required for the given number.
Definition: vehicle_gui.cpp:151
BaseVehicleListWindow::GetActionDropdownSize
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group)
Compute the size for the Action dropdown.
Definition: vehicle_gui.cpp:232
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:1175
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:698
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:71
GUIList::SortType
uint8 SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:93
order_cmd.h
VehicleList
std::vector< const Vehicle * > VehicleList
A list of vehicles.
Definition: vehiclelist.h:55
Pool::PoolItem<&_vehicle_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
VehicleViewWindow::PlaneSelections
PlaneSelections
Display planes available in the vehicle view window.
Definition: vehicle_gui.cpp:2663
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:2446
VehicleListWindow::BP_SHOW_BUTTONS
@ BP_SHOW_BUTTONS
Show the buttons.
Definition: vehicle_gui.cpp:1650
WD_MATRIX_RIGHT
@ WD_MATRIX_RIGHT
Offset at right of a matrix cell.
Definition: window_gui.h:79
Vehicle::y_pos
int32 y_pos
y coordinate.
Definition: vehicle_base.h:284
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:2167
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:1190
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:168
GetServiceIntervalClamped
uint16 GetServiceIntervalClamped(uint interval, bool ispercent)
Clamp the service interval to the correct min/max.
Definition: order_cmd.cpp:1878
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:72
WID_VL_CAPTION_SHARED_ORDERS
@ WID_VL_CAPTION_SHARED_ORDERS
Caption of window (for shared orders windows).
Definition: vehicle_widget.h:65
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:712
Vehicle::value
Money value
Value of the vehicle.
Definition: vehicle_base.h:256
VehicleSettings::train_acceleration_model
uint8 train_acceleration_model
realistic acceleration for trains
Definition: settings_type.h:483
Vehicle::x_pos
int32 x_pos
x coordinate.
Definition: vehicle_base.h:283
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:898
VehicleViewWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: vehicle_gui.cpp:3030
WID_VL_CAPTION
@ WID_VL_CAPTION
Caption of window (for non shared orders windows).
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:670
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:1141
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:348
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:320
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
RefitWindow::click_x
int click_x
Position of the first click while dragging.
Definition: vehicle_gui.cpp:491
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:2416
Commands
Commands
List of commands.
Definition: command_type.h:176
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:1181
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:1006
_sorted_cargo_specs
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:152
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:747
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:1004
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:2279
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:600
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1085
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:484
WD_MATRIX_TOP
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
Definition: window_gui.h:80
WID_VL_GROUP_BY_PULLDOWN
@ WID_VL_GROUP_BY_PULLDOWN
Group by dropdown list.
Definition: vehicle_widget.h:69
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:503
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:617
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:777
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:104
Vehicle::z_pos
int32 z_pos
z coordinate.
Definition: vehicle_base.h:285
RefitWindow::selected_vehicle
VehicleID selected_vehicle
First vehicle in the current selection.
Definition: vehicle_gui.cpp:492
VehicleDetailsWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: vehicle_gui.cpp:2143
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:2126
VehicleSpriteSeq::Set
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:165
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:241
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:321
depot_cmd.h
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:2969
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:1481
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:332
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:726
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:1760
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:118
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:82
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:341
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:1146
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
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
UnScaleGUI
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:77
RefitOption::subtype
byte subtype
Subcargo to use.
Definition: vehicle_gui.cpp:388
VehicleViewWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: vehicle_gui.cpp:3068
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:1825
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:1092
_vehicle_view_zoom_levels
static const ZoomLevel _vehicle_view_zoom_levels[]
Zoom levels for vehicle views indexed by vehicle type.
Definition: vehicle_gui.cpp:2577
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:2670
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:712
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
WID_VL_START_ALL
@ WID_VL_START_ALL
Start all button.
Definition: vehicle_widget.h:78
Vehicle::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the vehicle is tied to.
Definition: vehicle.cpp:751
VehicleViewWindow::SelectPlane
void SelectPlane(PlaneSelections plane)
Display a plane in the window.
Definition: vehicle_gui.cpp:2679
VehicleCommandTranslation
VehicleCommandTranslation
Command indices for the _vehicle_command_translation_table.
Definition: vehicle_gui.cpp:2590
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:995
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:170
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:2122
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
VehicleListWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: vehicle_gui.cpp:1732
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:1361
EIT_IN_DETAILS
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
Definition: vehicle_type.h:89
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:645
WindowDesc::cls
WindowClass cls
Class of the window,.
Definition: window_gui.h:177
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:422
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:216
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:319
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:106
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:931
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:336
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:86
CBM_VEHICLE_CARGO_SUFFIX
@ CBM_VEHICLE_CARGO_SUFFIX
Show suffix after cargo name.
Definition: newgrf_callbacks.h:294
Engine
Definition: engine_base.h:27
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle::cur_speed
uint16 cur_speed
current speed
Definition: vehicle_base.h:307
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
Vehicle::IsPrimaryVehicle
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:450
Vehicle::IsGroundVehicle
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:488
VehicleDefaultSettings::servint_ships
uint16 servint_ships
service interval for ships
Definition: settings_type.h:566
GUIList::SetSortType
void SetSortType(uint8 n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:103
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2138
WID_VL_SCROLLBAR
@ WID_VL_SCROLLBAR
Scrollbar for the list.
Definition: vehicle_widget.h:73
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:288
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:1187
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:631
GetVehicleCallback
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1160
ShowTimetableWindow
void ShowTimetableWindow(const Vehicle *v)
Show the timetable for a given vehicle.
Definition: timetable_gui.cpp:704
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:1232
_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:55
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:1646
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:196
VehicleListWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: vehicle_gui.cpp:1905
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
RefitWindow::num_vehicles
uint8 num_vehicles
Number of selected vehicles.
Definition: vehicle_gui.cpp:493
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1109
_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:280
NWidgetCore::widget_data
uint32 widget_data
Data of the widget.
Definition: widget_type.h:335
RefitWindow::sprite_left
int sprite_left
Left position of the vehicle sprite.
Definition: vehicle_gui.cpp:488
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:2256
WD_IMGBTN_BOTTOM
@ WD_IMGBTN_BOTTOM
Bottom offset of image in the button.
Definition: window_gui.h:43
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:891
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:2927
train_cmd.h
RefitWindow::auto_refit
bool auto_refit
Select cargo for auto-refitting.
Definition: vehicle_gui.cpp:494
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:790
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:2290
Vehicle::IsArticulatedPart
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition: vehicle_base.h:912
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:1947
Order::GetType
OrderType GetType() const
Get the type of order of this order.
Definition: order_base.h:77
BaseVehicleListWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: vehicle_gui.cpp:248
DepotCommand::Service
@ Service
The vehicle will leave the depot right after arrival (service only)
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
UpdateCursorSize
void UpdateCursorSize()
Update cursor dimension.
Definition: gfx.cpp:1822
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:482
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:168
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:480
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:579
ShowVehicleDetailsWindow
static void ShowVehicleDetailsWindow(const Vehicle *v)
Shows the vehicle details window of the given vehicle.
Definition: vehicle_gui.cpp:2496
Vehicle::breakdown_ctr
byte breakdown_ctr
Counter for managing breakdown events.
Definition: vehicle_base.h:278
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:259
VehicleSpriteSeq::IsValid
bool IsValid() const
Check whether the sequence contains any sprites.
Definition: vehicle_base.h:149
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:159
Vehicle::GetDisplayProfitThisYear
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
Definition: vehicle_base.h:585
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:765
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:156
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:497
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:103
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
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:24
VehicleListWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: vehicle_gui.cpp:1790
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:2664
WC_VEHICLE_VIEW
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
Definition: window_type.h:331
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2116
WID_VL_STOP_ALL
@ WID_VL_STOP_ALL
Stop all button.
Definition: vehicle_widget.h:77
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
StartStopVehicle
void StartStopVehicle(const Vehicle *v, bool texteffect)
Executes CMD_START_STOP_VEHICLE for given vehicle.
Definition: vehicle_gui.cpp:2641
WID_VL_SORT_ORDER
@ WID_VL_SORT_ORDER
Sort order.
Definition: vehicle_widget.h:70
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:1111
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:144
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:2048
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:315
VehicleClicked
bool VehicleClicked(const Vehicle *v)
Dispatch a "vehicle selected" event if any window waits for it.
Definition: vehicle_gui.cpp:3102
VehicleModelSorter
static bool VehicleModelSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by model.
Definition: vehicle_gui.cpp:1286
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:245
VehicleGroupAverageProfitLastYearSorter
static bool VehicleGroupAverageProfitLastYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the average profit last year.
Definition: vehicle_gui.cpp:1199
BaseVehicleListWindow
Definition: vehicle_gui_base.h:70
VehicleProfitThisYearSorter
static bool VehicleProfitThisYearSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by this year profit.
Definition: vehicle_gui.cpp:1239
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:993
WID_VL_SORT_BY_PULLDOWN
@ WID_VL_SORT_BY_PULLDOWN
Sort by dropdown list.
Definition: vehicle_widget.h:71
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:3021
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:130
DepotCommand::MassSend
@ MassSend
Tells that it's a mass send to depot command (type in VLW flag)
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:302
RefitOption::operator!=
bool operator!=(const RefitOption &other) const
Inequality operator for RefitOption.
Definition: vehicle_gui.cpp:396
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
VehicleListWindow::BP_NORMAL
@ BP_NORMAL
Show shared orders caption and buttons.
Definition: vehicle_gui.cpp:1656
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:41
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:132
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:1279
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
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:65
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:160
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
vehicle_gui_base.h
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:333
_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:756
WID_VL_MANAGE_VEHICLES_DROPDOWN
@ WID_VL_MANAGE_VEHICLES_DROPDOWN
Manage vehicles dropdown list.
Definition: vehicle_widget.h:76
Vehicle::max_age
Date max_age
Maximum age.
Definition: vehicle_base.h:274
RefitWindow::vscroll
Scrollbar * vscroll
The main scrollbar.
Definition: vehicle_gui.cpp:485
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:443
GetVehicleListHeight
uint GetVehicleListHeight(VehicleType type, uint divisor)
Get the height of a vehicle in the vehicle list GUIs.
Definition: vehicle_gui.cpp:1498
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:1127
VehicleListWindow::BP_SHARED_ORDERS
@ BP_SHARED_ORDERS
Show the normal caption.
Definition: vehicle_gui.cpp:1657
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:1320
WID_VD_TOP_DETAILS
@ WID_VD_TOP_DETAILS
Panel with generic details.
Definition: vehicle_widget.h:48
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
RefitWindow::hscroll
Scrollbar * hscroll
Only used for long vehicles.
Definition: vehicle_gui.cpp:486
VehicleViewWindow::SEL_DC_CLONE
@ SEL_DC_CLONE
Display 'clone vehicle' button in WID_VV_SELECT_DEPOT_CLONE stacked widget.
Definition: vehicle_gui.cpp:2665
VehicleListWindow::ButtonPlanes
ButtonPlanes
Enumeration of planes of the button row at the bottom.
Definition: vehicle_gui.cpp:1649
WC_VEHICLE_DETAILS
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Definition: window_type.h:192
VehicleViewWindow::ShowNewGRFInspectWindow
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
Definition: vehicle_gui.cpp:3084
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:386
VS_STOPPED
@ VS_STOPPED
Vehicle is stopped by the player.
Definition: vehicle_base.h:35
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:332
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
GenerateVehicleSortList
bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli)
Generate a list of vehicles based on window type.
Definition: vehiclelist.cpp:113
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:1125
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:312
VehicleGroupAverageProfitThisYearSorter
static bool VehicleGroupAverageProfitThisYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the average profit this year.
Definition: vehicle_gui.cpp:1193
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:305
Train
'Train' is either a loco or a wagon.
Definition: train.h:86
vehicle_cmd.h
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:1454
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
GetGRFStringID
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition: newgrf_text.cpp:601
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:36
SetMouseCursorVehicle
void SetMouseCursorVehicle(const Vehicle *v, EngineImageType image_type)
Set the mouse cursor to look like a vehicle.
Definition: vehicle_gui.cpp:3184
RefitWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: vehicle_gui.cpp:815
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:1695
VehicleListWindow::CaptionPlanes
CaptionPlanes
Enumeration of planes of the title row at the top.
Definition: vehicle_gui.cpp:1655
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:1044
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:2762
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:74
VehicleDefaultSettings
Default settings for vehicles.
Definition: settings_type.h:561
RefitWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: vehicle_gui.cpp:1074
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:1883
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
WID_VL_CAPTION_SELECTION
@ WID_VL_CAPTION_SELECTION
Selection for caption.
Definition: vehicle_widget.h:66
VehicleViewWindow::SEL_RT_BASEPLANE
@ SEL_RT_BASEPLANE
First plane of the WID_VV_SELECT_REFIT_TURN stacked widget.
Definition: vehicle_gui.cpp:2671
CcStartStopVehicle
void CcStartStopVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id, bool)
This is the Callback method after attempting to start/stop a vehicle.
Definition: vehicle_gui.cpp:2624
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition: window_type.h:300
GetSingleVehicleWidth
int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type)
Get the width of a vehicle (part) in pixels.
Definition: vehicle_gui.cpp:3142
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:68
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:480
RefitWindow::sprite_right
int sprite_right
Right position of the vehicle sprite.
Definition: vehicle_gui.cpp:489
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
BaseConsist::vehicle_flags
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:31
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:307
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:220
ChangeVehicleWindow
static void ChangeVehicleWindow(WindowClass window_class, VehicleID from_index, VehicleID to_index)
Assign a vehicle window a new vehicle.
Definition: vehicle_gui.cpp:1338
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:1293
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:483
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:3174
NWidgetStacked::SetDisplayedPlane
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1195
EngineInfo::misc_flags
byte misc_flags
Miscellaneous flags.
Definition: engine_type.h:143
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:187
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:438
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:37
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:329
RefitOption::string
StringID string
GRF-local String to display for the cargo.
Definition: vehicle_gui.cpp:389
VehicleViewWindow::SEL_RT_REFIT
@ SEL_RT_REFIT
Display 'refit' button in WID_VV_SELECT_REFIT_TURN stacked widget.
Definition: vehicle_gui.cpp:2667
GetDigitWidth
byte GetDigitWidth(FontSize size)
Return the maximum width of single digit.
Definition: gfx.cpp:1464
VehicleViewWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: vehicle_gui.cpp:2753
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:198
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:165
GetCargoSubtypeText
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
Definition: vehicle_gui.cpp:1159
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:1306
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:979
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
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:28
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:1518
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:136
RefitOption::operator==
bool operator==(const RefitOption &other) const
Equality operator for RefitOption.
Definition: vehicle_gui.cpp:406
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:2456
Vehicle::FirstShared
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:694
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:105
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:226
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:345
EIT_IN_LIST
@ EIT_IN_LIST
Vehicle drawn in vehicle list, group list, ...
Definition: vehicle_type.h:90
_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:1094
RefitWindow::RefreshScrollbar
void RefreshScrollbar()
Refresh scrollbar after selection changed.
Definition: vehicle_gui.cpp:607
VehicleDetailsWindow
Class for managing the vehicle details window.
Definition: vehicle_gui.cpp:2121
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:1596
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:3166
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
_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:613
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:490
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:322
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:161
VehicleDetailsWindow::OnPaint
void OnPaint() override
Repaint vehicle details window.
Definition: vehicle_gui.cpp:2393
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:74
RoadVehicle::GetDisplayImageWidth
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a road vehicle image in the GUI.
Definition: roadveh_cmd.cpp:92
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:189
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:563
VehicleViewWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: vehicle_gui.cpp:2817
HideDropDownMenu
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
Definition: dropdown.cpp:498
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:878
VehicleViewWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: vehicle_gui.cpp:3014
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1170
GetVehiclePalette
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
Definition: vehicle.cpp:2062
VehicleSettings::roadveh_acceleration_model
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
Definition: settings_type.h:484
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:168
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:941
ScaleZoomGUI
static ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition: zoom_func.h:87
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:107
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1209
geometry_func.hpp
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
AIR_HELICOPTER
@ AIR_HELICOPTER
an helicopter
Definition: aircraft.h:31
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:94
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1012
WID_VR_VEHICLE_PANEL_DISPLAY
@ WID_VR_VEHICLE_PANEL_DISPLAY
Display with a representation of the vehicle to refit.
Definition: vehicle_widget.h:35
CcBuildPrimaryVehicle
void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16)
This is the Callback method after the construction attempt of a primary vehicle.
Definition: vehicle_gui.cpp:3129
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:322
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:547
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:487
RefitWindow
Refit cargo window.
Definition: vehicle_gui.cpp:479
CcCloneVehicle
void CcCloneVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id)
This is the Callback method after the cloning attempt of a vehicle.
Definition: depot_gui.cpp:121
Vehicle::age
Date age
Age in days.
Definition: vehicle_base.h:273
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
VehicleDefaultSettings::servint_aircraft
uint16 servint_aircraft
service interval for aircraft
Definition: settings_type.h:565
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:921
VehicleNumberSorter
static bool VehicleNumberSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their number.
Definition: vehicle_gui.cpp:1205
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:673
VehicleViewWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: vehicle_gui.cpp:2809
WD_IMGBTN_TOP
@ WD_IMGBTN_TOP
Top offset of image in the button.
Definition: window_gui.h:42
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:1253
VehicleViewWindow::IsNewGRFInspectable
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
Definition: vehicle_gui.cpp:3079
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:71
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:43
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1776
_nested_vehicle_view_widgets
static const NWidgetPart _nested_vehicle_view_widgets[]
Vehicle view widgets.
Definition: vehicle_gui.cpp:2507
Vehicle::unitnumber
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:305
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:1313
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:125
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:2183
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:1130
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:2660
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:209
Vehicle::InvalidateNewGRFCache
void InvalidateNewGRFCache()
Invalidates cached NewGRF variables.
Definition: vehicle_base.h:468
NWidgetBase::SetDirty
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:807
VehicleListWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: vehicle_gui.cpp:1776
VehicleListIdentifier::UnPack
static VehicleListIdentifier UnPack(uint32 data)
Decode a packed vehicle list identifier into a new one.
Definition: vehiclelist.cpp:53
Vehicle::subtype
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition: vehicle_base.h:342
OrderList::GetFirstOrder
Order * GetFirstOrder() const
Get the first order of the order chain.
Definition: order_base.h:300
CommandHelper
Definition: command_func.h:94
ViewportData::follow_vehicle
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Definition: window_gui.h:259
WD_MATRIX_BOTTOM
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
Definition: window_gui.h:81
ShowVehicleViewWindow
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
Definition: vehicle_gui.cpp:3092
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
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
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:386
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
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:2212
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:690
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:1048
VF_PATHFINDER_LOST
@ VF_PATHFINDER_LOST
Vehicle's pathfinder is lost.
Definition: vehicle_base.h:53
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:387
OverflowSafeInt< int64 >
_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:1211
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:533
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1176
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:1957
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:3361
VehicleDefaultSettings::servint_roadveh
uint16 servint_roadveh
service interval for road vehicles
Definition: settings_type.h:564
RefitWindow::vehicle_width
int vehicle_width
Width of the vehicle being drawn.
Definition: vehicle_gui.cpp:487
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:736
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:320
WID_VL_ORDER_VIEW
@ WID_VL_ORDER_VIEW
Button to open order window (for shared orders windows).
Definition: vehicle_widget.h:67
RefitWindow::OnDragDrop
void OnDragDrop(Point pt, int widget) override
A dragged 'object' has been released.
Definition: vehicle_gui.cpp:1061
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:2295
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1078
MAX_REFIT_CYCLE
static const uint MAX_REFIT_CYCLE
Maximum number of refit cycles we try, to prevent infinite loops.
Definition: vehicle_gui.cpp:311
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:683
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:362
gui.h
VehicleIndividualToGroupSorterWrapper
static bool VehicleIndividualToGroupSorterWrapper(GUIVehicleGroup const &a, GUIVehicleGroup const &b)
Wrapper to convert a VehicleIndividualSortFunction to a VehicleGroupSortFunction.
Definition: vehicle_gui.cpp:72
SPR_CURSOR_MOUSE
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1376
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:125
WD_DROPDOWNTEXT_BOTTOM
@ WD_DROPDOWNTEXT_BOTTOM
Bottom offset of the dropdown widget string.
Definition: window_gui.h:137
articulated_vehicles.h
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:589
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:321
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:1146
Window
Data structure for an opened window.
Definition: window_gui.h:279
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:326
WD_MATRIX_LEFT
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
Definition: window_gui.h:78
Vehicle::GetOrder
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
Definition: vehicle_base.h:880
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:636
RefitWindow::BuildRefitList
void BuildRefitList()
Collects all (cargo, subcargo) refit options of a vehicle chain.
Definition: vehicle_gui.cpp:499
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:276
DC_QUERY_COST
@ DC_QUERY_COST
query cost only, don't build.
Definition: command_type.h:352
VehicleProfitLastYearSorter
static bool VehicleProfitLastYearSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by last year profit.
Definition: vehicle_gui.cpp:1246
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:293
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:227
WD_IMGBTN_LEFT
@ WD_IMGBTN_LEFT
Left offset of the image in the button.
Definition: window_gui.h:40
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:311
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:608
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:481
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
DepotCommand::None
@ None
No special flags.
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
Vehicle::orders
OrderList * orders
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:336
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:147
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:1122
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:696
Window::DisableWidget
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:396
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:186
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
NWidgetStacked::shown_plane
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:454
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:59
Order
Definition: order_base.h:36
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:633
GroundVehicleCache::cached_weight
uint32 cached_weight
Total weight of the consist (valid only for the first engine).
Definition: ground_vehicle.hpp:31
roadveh_cmd.h
WD_IMGBTN_RIGHT
@ WD_IMGBTN_RIGHT
Right offset of the image in the button.
Definition: window_gui.h:41
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:447
RefitWindow::GetCapacityString
StringID GetCapacityString(RefitOption *option) const
Gets the StringID to use for displaying capacity.
Definition: vehicle_gui.cpp:776
Engine::GetAircraftTypeText
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
Definition: engine.cpp:458
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:591
VehicleListWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: vehicle_gui.cpp:1937
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:423
RefitOption
Option to refit a vehicle chain.
Definition: vehicle_gui.cpp:386
VehicleReliabilitySorter
static bool VehicleReliabilitySorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their reliability.
Definition: vehicle_gui.cpp:1272
GetDepotIndex
static DepotID GetDepotIndex(TileIndex t)
Get the index of which depot is attached to the tile.
Definition: depot_map.h:52
_vehicle_msg_translation_table
static const StringID _vehicle_msg_translation_table[][4]
Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type.
Definition: vehicle_gui.cpp:2597
GetTrainDetailsWndVScroll
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
Determines the number of lines in the train details window.
Definition: train_gui.cpp:319
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:204
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:598
debug.h
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:30
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:275
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:1030
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:2519
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:2470
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:662
SubtypeList
std::vector< RefitOption > SubtypeList
List of refit subtypes associated to a cargo.
Definition: vehicle_gui.cpp:412
_nested_train_vehicle_details_widgets
static const NWidgetPart _nested_train_vehicle_details_widgets[]
Train details widgets.
Definition: vehicle_gui.cpp:2071
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:95
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1092
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:459