OpenTTD Source  20240917-master-g9ab0a47812
group_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 "textbuf_gui.h"
12 #include "command_func.h"
13 #include "vehicle_gui.h"
14 #include "vehicle_base.h"
15 #include "string_func.h"
16 #include "strings_func.h"
17 #include "window_func.h"
18 #include "vehicle_func.h"
19 #include "autoreplace_gui.h"
20 #include "company_func.h"
21 #include "dropdown_func.h"
22 #include "tilehighlight_func.h"
23 #include "vehicle_gui_base.h"
24 #include "core/geometry_func.hpp"
25 #include "core/container_func.hpp"
26 #include "company_base.h"
27 #include "company_gui.h"
28 #include "gui.h"
29 #include "group_cmd.h"
30 #include "group_gui.h"
31 #include "vehicle_cmd.h"
32 #include "gfx_func.h"
33 
34 #include "widgets/group_widget.h"
35 
36 #include "table/sprites.h"
37 
38 #include "safeguards.h"
39 
40 static constexpr NWidgetPart _nested_group_widgets[] = {
41  NWidget(NWID_HORIZONTAL), // Window header
42  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
43  NWidget(WWT_CAPTION, COLOUR_GREY, WID_GL_CAPTION),
44  NWidget(WWT_SHADEBOX, COLOUR_GREY),
45  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
46  NWidget(WWT_STICKYBOX, COLOUR_GREY),
47  EndContainer(),
49  /* left part */
51  NWidget(WWT_PANEL, COLOUR_GREY, WID_GL_ALL_VEHICLES), SetFill(1, 0), EndContainer(),
54  NWidget(WWT_MATRIX, COLOUR_GREY, WID_GL_LIST_GROUP), SetMatrixDataTip(1, 0, STR_GROUPS_CLICK_ON_GROUP_FOR_TOOLTIP),
57  EndContainer(),
58  NWidget(WWT_PANEL, COLOUR_GREY, WID_GL_INFO), SetFill(1, 1), SetMinimalTextLines(3, WidgetDimensions::unscaled.framerect.Vertical()), EndContainer(),
61  SetDataTip(SPR_GROUP_CREATE_TRAIN, STR_GROUP_CREATE_TOOLTIP),
63  SetDataTip(SPR_GROUP_DELETE_TRAIN, STR_GROUP_DELETE_TOOLTIP),
65  SetDataTip(SPR_GROUP_RENAME_TRAIN, STR_GROUP_RENAME_TOOLTIP),
67  SetDataTip(SPR_GROUP_LIVERY_TRAIN, STR_GROUP_LIVERY_TOOLTIP),
68  NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 0), EndContainer(),
70  SetDataTip(SPR_GROUP_REPLACE_OFF_TRAIN, STR_GROUP_REPLACE_PROTECTION_TOOLTIP),
71  EndContainer(),
72  EndContainer(),
73  /* right part */
77  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GL_GROUP_BY_ORDER), SetFill(1, 1), SetMinimalSize(0, 12), SetDataTip(STR_STATION_VIEW_GROUP, STR_TOOLTIP_GROUP_ORDER),
78  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GL_SORT_BY_ORDER), SetFill(1, 1), SetMinimalSize(0, 12), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
79  EndContainer(),
81  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GL_GROUP_BY_DROPDOWN), SetFill(1, 1), SetMinimalSize(0, 12), SetDataTip(0x0, STR_TOOLTIP_GROUP_ORDER),
82  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GL_SORT_BY_DROPDOWN), SetFill(1, 1), SetMinimalSize(0, 12), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
83  EndContainer(),
85  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetFill(0, 1), SetResize(1, 0), EndContainer(),
87  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GL_FILTER_BY_CARGO), SetMinimalSize(0, 12), SetFill(0, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA),
88  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(0, 1), SetResize(1, 0), EndContainer(),
89  EndContainer(),
90  EndContainer(),
91  EndContainer(),
95  EndContainer(),
96  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(1, 0), SetFill(1, 1), SetResize(1, 0), EndContainer(),
99  SetDataTip(STR_JUST_STRING, STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP),
100  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetResize(1, 0), EndContainer(),
102  SetDataTip(STR_VEHICLE_LIST_MANAGE_LIST, STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP),
103  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_STOP_ALL), SetAspect(WidgetDimensions::ASPECT_VEHICLE_FLAG),
104  SetDataTip(SPR_FLAG_VEH_STOPPED, STR_VEHICLE_LIST_MASS_STOP_LIST_TOOLTIP),
105  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_START_ALL), SetAspect(WidgetDimensions::ASPECT_VEHICLE_FLAG),
106  SetDataTip(SPR_FLAG_VEH_RUNNING, STR_VEHICLE_LIST_MASS_START_LIST_TOOLTIP),
107  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
108  EndContainer(),
109  EndContainer(),
110  EndContainer(),
111 };
112 
121 static void GuiGroupListAddChildren(GUIGroupList &dst, const GUIGroupList &src, bool fold, GroupID parent = INVALID_GROUP, uint8_t indent = 0)
122 {
123  for (const auto &item : src) {
124  if (item.group->parent != parent) continue;
125 
126  dst.emplace_back(item.group, indent);
127 
128  if (fold && item.group->folded) {
129  /* Test if this group has children at all. If not, the folded flag should be cleared to avoid lingering unfold buttons in the list. */
130  GroupID groupid = item.group->index;
131  bool has_children = std::any_of(src.begin(), src.end(), [groupid](const auto &child) { return child.group->parent == groupid; });
132  Group::Get(item.group->index)->folded = has_children;
133  } else {
134  GuiGroupListAddChildren(dst, src, fold, item.group->index, indent + 1);
135  }
136  }
137 
138  if (indent > 0 || dst.empty()) return;
139 
140  /* Hierarchy is complete, traverse in reverse to find where indentation levels continue. */
141  uint16_t level_mask = 0;
142  for (auto it = std::rbegin(dst); std::next(it) != std::rend(dst); ++it) {
143  auto next_it = std::next(it);
144  AssignBit(level_mask, it->indent, it->indent <= next_it->indent);
145  next_it->level_mask = level_mask;
146  }
147 }
148 
156 void BuildGuiGroupList(GUIGroupList &dst, bool fold, Owner owner, VehicleType veh_type)
157 {
158  GUIGroupList list;
159 
160  for (const Group *g : Group::Iterate()) {
161  if (g->owner == owner && g->vehicle_type == veh_type) {
162  list.emplace_back(g, 0);
163  }
164  }
165 
166  list.ForceResort();
167 
168  /* Sort the groups by their name */
169  std::array<std::pair<const Group *, std::string>, 2> last_group{};
170 
171  list.Sort([&last_group](const GUIGroupListItem &a, const GUIGroupListItem &b) -> bool {
172  if (a.group != last_group[0].first) {
173  SetDParam(0, a.group->index);
174  last_group[0] = {a.group, GetString(STR_GROUP_NAME)};
175  }
176 
177  if (b.group != last_group[1].first) {
178  SetDParam(0, b.group->index);
179  last_group[1] = {b.group, GetString(STR_GROUP_NAME)};
180  }
181 
182  int r = StrNaturalCompare(last_group[0].second, last_group[1].second); // Sort by name (natural sorting).
183  if (r == 0) return a.group->number < b.group->number;
184  return r < 0;
185  });
186 
187  GuiGroupListAddChildren(dst, list, fold, INVALID_GROUP, 0);
188 }
189 
191 private:
192  /* Columns in the group list */
193  enum ListColumns {
200 
201  VGC_END
202  };
203 
210  Scrollbar *group_sb;
211 
213 
220  {
221  if (!this->groups.NeedRebuild()) return;
222 
223  this->groups.clear();
224 
225  BuildGuiGroupList(this->groups, true, owner, this->vli.vtype);
226 
227  this->groups.RebuildDone();
228  }
229 
235  {
236  this->column_size[VGC_FOLD] = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED));
237  this->tiny_step_height = this->column_size[VGC_FOLD].height;
238 
239  this->column_size[VGC_NAME] = maxdim(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + this->vli.vtype), GetStringBoundingBox(STR_GROUP_ALL_TRAINS + this->vli.vtype));
240  this->column_size[VGC_NAME].width = std::max(170u, this->column_size[VGC_NAME].width) + WidgetDimensions::scaled.hsep_indent;
241  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_NAME].height);
242 
243  this->column_size[VGC_PROTECT] = GetSpriteSize(SPR_GROUP_REPLACE_PROTECT);
244  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_PROTECT].height);
245 
246  this->column_size[VGC_AUTOREPLACE] = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
247  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_AUTOREPLACE].height);
248 
249  this->column_size[VGC_PROFIT].width = 0;
250  this->column_size[VGC_PROFIT].height = 0;
251  static const SpriteID profit_sprites[] = {SPR_PROFIT_NA, SPR_PROFIT_NEGATIVE, SPR_PROFIT_SOME, SPR_PROFIT_LOT};
252  for (const auto &profit_sprite : profit_sprites) {
253  Dimension d = GetSpriteSize(profit_sprite);
254  this->column_size[VGC_PROFIT] = maxdim(this->column_size[VGC_PROFIT], d);
255  }
256  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_PROFIT].height);
257 
258  int num_vehicle = GetGroupNumVehicle(this->vli.company, ALL_GROUP, this->vli.vtype);
259  SetDParamMaxValue(0, num_vehicle, 3, FS_SMALL);
260  SetDParamMaxValue(1, num_vehicle, 3, FS_SMALL);
261  this->column_size[VGC_NUMBER] = GetStringBoundingBox(STR_GROUP_COUNT_WITH_SUBGROUP);
262  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_NUMBER].height);
263 
264  this->tiny_step_height += WidgetDimensions::scaled.framerect.Vertical();
265 
266  return WidgetDimensions::scaled.framerect.left +
267  this->column_size[VGC_FOLD].width + WidgetDimensions::scaled.hsep_normal +
268  this->column_size[VGC_NAME].width + WidgetDimensions::scaled.hsep_wide +
269  this->column_size[VGC_PROTECT].width + WidgetDimensions::scaled.hsep_normal +
270  this->column_size[VGC_AUTOREPLACE].width + WidgetDimensions::scaled.hsep_normal +
271  this->column_size[VGC_PROFIT].width + WidgetDimensions::scaled.hsep_normal +
272  this->column_size[VGC_NUMBER].width +
274  }
275 
286  void DrawGroupInfo(int y, int left, int right, GroupID g_id, uint16_t level_mask = 0, uint8_t indent = 0, bool protection = false, bool has_children = false) const
287  {
288  /* Highlight the group if a vehicle is dragged over it */
289  if (g_id == this->group_over) {
290  GfxFillRect(left + WidgetDimensions::scaled.bevel.left, y + WidgetDimensions::scaled.framerect.top, right - WidgetDimensions::scaled.bevel.right, y + this->tiny_step_height - 1 - WidgetDimensions::scaled.framerect.bottom, GetColourGradient(COLOUR_GREY, SHADE_LIGHTEST));
291  }
292 
293  if (g_id == NEW_GROUP) return;
294 
295  /* draw the selected group in white, else we draw it in black */
296  TextColour colour = g_id == this->vli.index ? TC_WHITE : TC_BLACK;
297  const GroupStatistics &stats = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype);
298  bool rtl = _current_text_dir == TD_RTL;
299 
300  const int offset = (rtl ? -(int)this->column_size[VGC_FOLD].width : (int)this->column_size[VGC_FOLD].width) / 2;
302  const int linecolour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL);
303 
304  if (indent > 0) {
305  /* Draw tree continuation lines. */
306  int tx = (rtl ? right - WidgetDimensions::scaled.framerect.right : left + WidgetDimensions::scaled.framerect.left) + offset;
307  for (uint lvl = 1; lvl <= indent; ++lvl) {
308  if (HasBit(level_mask, lvl)) GfxDrawLine(tx, y, tx, y + this->tiny_step_height - 1, linecolour, WidgetDimensions::scaled.fullbevel.top);
309  if (lvl < indent) tx += level_width;
310  }
311  /* Draw our node in the tree. */
312  int ycentre = y + this->tiny_step_height / 2 - 1;
313  if (!HasBit(level_mask, indent)) GfxDrawLine(tx, y, tx, ycentre, linecolour, WidgetDimensions::scaled.fullbevel.top);
314  GfxDrawLine(tx, ycentre, tx + offset - (rtl ? -1 : 1), ycentre, linecolour, WidgetDimensions::scaled.fullbevel.top);
315  }
316 
317  /* draw fold / unfold button */
318  int x = rtl ? right - WidgetDimensions::scaled.framerect.right - this->column_size[VGC_FOLD].width + 1 : left + WidgetDimensions::scaled.framerect.left;
319  if (has_children) {
320  DrawSprite(Group::Get(g_id)->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, x + indent * level_width, y + (this->tiny_step_height - this->column_size[VGC_FOLD].height) / 2);
321  }
322 
323  /* draw group name */
324  StringID str;
325  if (IsAllGroupID(g_id)) {
326  str = STR_GROUP_ALL_TRAINS + this->vli.vtype;
327  } else if (IsDefaultGroupID(g_id)) {
328  str = STR_GROUP_DEFAULT_TRAINS + this->vli.vtype;
329  } else {
330  SetDParam(0, g_id);
331  str = STR_GROUP_NAME;
332  }
333  x = rtl ? x - WidgetDimensions::scaled.hsep_normal - this->column_size[VGC_NAME].width : x + WidgetDimensions::scaled.hsep_normal + this->column_size[VGC_FOLD].width;
334  DrawString(x + (rtl ? 0 : indent * WidgetDimensions::scaled.hsep_indent), x + this->column_size[VGC_NAME].width - 1 - (rtl ? indent * WidgetDimensions::scaled.hsep_indent : 0), y + (this->tiny_step_height - this->column_size[VGC_NAME].height) / 2, str, colour);
335 
336  /* draw autoreplace protection */
337  x = rtl ? x - WidgetDimensions::scaled.hsep_wide - this->column_size[VGC_PROTECT].width : x + WidgetDimensions::scaled.hsep_wide + this->column_size[VGC_NAME].width;
338  if (protection) DrawSprite(SPR_GROUP_REPLACE_PROTECT, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_PROTECT].height) / 2);
339 
340  /* draw autoreplace status */
341  x = rtl ? x - WidgetDimensions::scaled.hsep_normal - this->column_size[VGC_AUTOREPLACE].width : x + WidgetDimensions::scaled.hsep_normal + this->column_size[VGC_PROTECT].width;
342  if (stats.autoreplace_defined) DrawSprite(SPR_GROUP_REPLACE_ACTIVE, stats.autoreplace_finished ? PALETTE_CRASH : PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_AUTOREPLACE].height) / 2);
343 
344  /* draw the profit icon */
345  x = rtl ? x - WidgetDimensions::scaled.hsep_normal - this->column_size[VGC_PROFIT].width : x + WidgetDimensions::scaled.hsep_normal + this->column_size[VGC_AUTOREPLACE].width;
346  SpriteID spr;
347  uint num_vehicle_min_age = GetGroupNumVehicleMinAge(this->vli.company, g_id, this->vli.vtype);
348  Money profit_last_year_min_age = GetGroupProfitLastYearMinAge(this->vli.company, g_id, this->vli.vtype);
349  if (num_vehicle_min_age == 0) {
350  spr = SPR_PROFIT_NA;
351  } else if (profit_last_year_min_age < 0) {
352  spr = SPR_PROFIT_NEGATIVE;
353  } else if (profit_last_year_min_age < VEHICLE_PROFIT_THRESHOLD * num_vehicle_min_age) {
354  spr = SPR_PROFIT_SOME;
355  } else {
356  spr = SPR_PROFIT_LOT;
357  }
358  DrawSprite(spr, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_PROFIT].height) / 2);
359 
360  /* draw the number of vehicles of the group */
361  x = rtl ? x - WidgetDimensions::scaled.hsep_normal - this->column_size[VGC_NUMBER].width : x + WidgetDimensions::scaled.hsep_normal + this->column_size[VGC_PROFIT].width;
362  int num_vehicle_with_subgroups = GetGroupNumVehicle(this->vli.company, g_id, this->vli.vtype);
363  int num_vehicle = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype).num_vehicle;
364  if (IsAllGroupID(g_id) || IsDefaultGroupID(g_id) || num_vehicle_with_subgroups == num_vehicle) {
365  SetDParam(0, num_vehicle);
366  DrawString(x, x + this->column_size[VGC_NUMBER].width - 1, y + (this->tiny_step_height - this->column_size[VGC_NUMBER].height) / 2, STR_JUST_COMMA, colour, SA_RIGHT | SA_FORCE, false, FS_SMALL);
367  } else {
368  SetDParam(0, num_vehicle);
369  SetDParam(1, num_vehicle_with_subgroups - num_vehicle);
370  DrawString(x, x + this->column_size[VGC_NUMBER].width - 1, y + (this->tiny_step_height - this->column_size[VGC_NUMBER].height) / 2, STR_GROUP_COUNT_WITH_SUBGROUP, colour, SA_RIGHT | SA_FORCE);
371  }
372  }
373 
378  {
379  if (this->group_over == INVALID_GROUP) return;
380 
381  if (IsAllGroupID(this->group_over)) {
383  } else if (IsDefaultGroupID(this->group_over)) {
385  } else {
387  }
388  }
389 
390 public:
392  {
393  this->CreateNestedTree();
394 
395  this->vscroll = this->GetScrollbar(WID_GL_LIST_VEHICLE_SCROLLBAR);
396  this->group_sb = this->GetScrollbar(WID_GL_LIST_GROUP_SCROLLBAR);
397 
398  this->vli.index = ALL_GROUP;
399  this->group_sel = INVALID_GROUP;
400  this->group_rename = INVALID_GROUP;
401  this->group_over = INVALID_GROUP;
402 
403  this->groups.ForceRebuild();
404  this->groups.NeedResort();
405  this->BuildGroupList(vli.company);
406  this->group_sb->SetCount(this->groups.size());
407 
408  this->GetWidget<NWidgetCore>(WID_GL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype;
409  this->GetWidget<NWidgetCore>(WID_GL_LIST_VEHICLE)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype;
410 
411  this->GetWidget<NWidgetCore>(WID_GL_CREATE_GROUP)->widget_data += this->vli.vtype;
412  this->GetWidget<NWidgetCore>(WID_GL_RENAME_GROUP)->widget_data += this->vli.vtype;
413  this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->widget_data += this->vli.vtype;
414  this->GetWidget<NWidgetCore>(WID_GL_LIVERY_GROUP)->widget_data += this->vli.vtype;
415  this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data += this->vli.vtype;
416 
417  this->FinishInitNested(window_number);
418  this->owner = vli.company;
419 
420  this->BuildVehicleList();
421  this->SortVehicleList();
422  }
423 
425  {
426  *this->sorting = this->vehgroups.GetListing();
427  }
428 
429  void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
430  {
431  switch (widget) {
432  case WID_GL_LIST_GROUP:
433  size.width = this->ComputeGroupInfoSize();
434  resize.height = this->tiny_step_height;
435  fill.height = this->tiny_step_height;
436  break;
437 
438  case WID_GL_ALL_VEHICLES:
440  size.width = this->ComputeGroupInfoSize();
441  size.height = this->tiny_step_height;
442  break;
443 
444  case WID_GL_SORT_BY_ORDER: {
445  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
446  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
447  d.height += padding.height;
448  size = maxdim(size, d);
449  break;
450  }
451 
452  case WID_GL_LIST_VEHICLE:
453  this->ComputeGroupInfoSize();
454  resize.height = GetVehicleListHeight(this->vli.vtype, this->tiny_step_height);
455  size.height = 4 * resize.height;
456  break;
457 
459  size.width = GetStringListWidth(this->vehicle_group_by_names) + padding.width;
460  break;
461 
463  size.width = GetStringListWidth(this->vehicle_group_none_sorter_names_calendar);
464  size.width = std::max(size.width, GetStringListWidth(this->vehicle_group_none_sorter_names_wallclock));
465  size.width = std::max(size.width, GetStringListWidth(this->vehicle_group_shared_orders_sorter_names_calendar));
466  size.width = std::max(size.width, GetStringListWidth(this->vehicle_group_shared_orders_sorter_names_wallclock));
467  size.width += padding.width;
468  break;
469 
471  size.width = std::max(size.width, GetDropDownListDimension(this->BuildCargoDropDownList(true)).width + padding.width);
472  break;
473 
475  Dimension d = this->GetActionDropdownSize(true, true, true);
476  d.height += padding.height;
477  d.width += padding.width;
478  size = maxdim(size, d);
479  break;
480  }
481  }
482  }
483 
489  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
490  {
491  if (data == 0) {
492  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
493  this->vehgroups.ForceRebuild();
494  this->groups.ForceRebuild();
495  } else {
496  this->vehgroups.ForceResort();
497  this->groups.ForceResort();
498  }
499 
500  /* Process ID-invalidation in command-scope as well */
501  if (this->group_rename != INVALID_GROUP && !Group::IsValidID(this->group_rename)) {
503  this->group_rename = INVALID_GROUP;
504  }
505 
506  if (!(IsAllGroupID(this->vli.index) || IsDefaultGroupID(this->vli.index) || Group::IsValidID(this->vli.index))) {
507  this->vli.index = ALL_GROUP;
509  }
510  this->SetDirty();
511  }
512 
513  void SetStringParameters(WidgetID widget) const override
514  {
515  switch (widget) {
517  SetDParam(0, this->GetCargoFilterLabel(this->cargo_filter_criteria));
518  break;
519 
521  SetDParam(0, STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vli.vtype);
522  break;
523 
524  case WID_GL_CAPTION:
525  /* If selected_group == DEFAULT_GROUP || ALL_GROUP, draw the standard caption
526  * We list all vehicles or ungrouped vehicles */
527  if (IsDefaultGroupID(this->vli.index) || IsAllGroupID(this->vli.index)) {
528  SetDParam(0, STR_COMPANY_NAME);
529  SetDParam(1, this->vli.company);
530  SetDParam(2, this->vehicles.size());
531  SetDParam(3, this->vehicles.size());
532  } else {
533  uint num_vehicle = GetGroupNumVehicle(this->vli.company, this->vli.index, this->vli.vtype);
534 
535  SetDParam(0, STR_GROUP_NAME);
536  SetDParam(1, this->vli.index);
537  SetDParam(2, num_vehicle);
538  SetDParam(3, num_vehicle);
539  }
540  break;
541  }
542  }
543 
544  void OnPaint() override
545  {
546  /* If we select the all vehicles, this->list will contain all vehicles of the owner
547  * else this->list will contain all vehicles which belong to the selected group */
548  this->BuildVehicleList();
549  this->SortVehicleList();
550 
551  this->BuildGroupList(this->owner);
552 
553  this->group_sb->SetCount(this->groups.size());
554  this->vscroll->SetCount(this->vehgroups.size());
555 
556  /* The drop down menu is out, *but* it may not be used, retract it. */
557  if (this->vehicles.empty() && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) {
560  }
561 
562  /* Disable all lists management button when the list is empty */
563  this->SetWidgetsDisabledState(this->vehicles.empty() || _local_company != this->vli.company,
567 
568  /* Disable the group specific function when we select the default group or all vehicles */
569  this->SetWidgetsDisabledState(IsDefaultGroupID(this->vli.index) || IsAllGroupID(this->vli.index) || _local_company != this->vli.company,
574 
575  /* Disable remaining buttons for non-local companies
576  * Needed while changing _local_company, eg. by cheats
577  * All procedures (eg. move vehicle to another group)
578  * verify, whether you are the owner of the vehicle,
579  * so it doesn't have to be disabled
580  */
584 
585  /* If not a default group and the group has replace protection, show an enabled replace sprite. */
586  uint16_t protect_sprite = SPR_GROUP_REPLACE_OFF_TRAIN;
587  if (!IsDefaultGroupID(this->vli.index) && !IsAllGroupID(this->vli.index) && HasBit(Group::Get(this->vli.index)->flags, GroupFlags::GF_REPLACE_PROTECTION)) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN;
588  this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data = protect_sprite + this->vli.vtype;
589 
590  /* Set text of "group by" dropdown widget. */
591  this->GetWidget<NWidgetCore>(WID_GL_GROUP_BY_DROPDOWN)->widget_data = std::data(this->vehicle_group_by_names)[this->grouping];
592 
593  /* Set text of "sort by" dropdown widget. */
594  this->GetWidget<NWidgetCore>(WID_GL_SORT_BY_DROPDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()];
595 
596  this->DrawWidgets();
597  }
598 
599  void DrawWidget(const Rect &r, WidgetID widget) const override
600  {
601  switch (widget) {
602  case WID_GL_ALL_VEHICLES:
603  DrawGroupInfo(r.top, r.left, r.right, ALL_GROUP);
604  break;
605 
607  DrawGroupInfo(r.top, r.left, r.right, DEFAULT_GROUP);
608  break;
609 
610  case WID_GL_INFO: {
611  Money this_year = 0;
612  Money last_year = 0;
613  uint64_t occupancy = 0;
614 
615  for (const Vehicle * const v : this->vehicles) {
616  assert(v->owner == this->owner);
617 
618  this_year += v->GetDisplayProfitThisYear();
619  last_year += v->GetDisplayProfitLastYear();
620  occupancy += v->trip_occupancy;
621  }
622 
623  Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
624 
625  DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_THIS_PERIOD : STR_GROUP_PROFIT_THIS_YEAR, TC_BLACK);
626  SetDParam(0, this_year);
627  DrawString(tr, STR_JUST_CURRENCY_LONG, TC_BLACK, SA_RIGHT);
628 
629  tr.top += GetCharacterHeight(FS_NORMAL);
630  DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_LAST_PERIOD : STR_GROUP_PROFIT_LAST_YEAR, TC_BLACK);
631  SetDParam(0, last_year);
632  DrawString(tr, STR_JUST_CURRENCY_LONG, TC_BLACK, SA_RIGHT);
633 
634  tr.top += GetCharacterHeight(FS_NORMAL);
635  DrawString(tr, STR_GROUP_OCCUPANCY, TC_BLACK);
636  const size_t vehicle_count = this->vehicles.size();
637  if (vehicle_count > 0) {
638  SetDParam(0, occupancy / vehicle_count);
639  DrawString(tr, STR_GROUP_OCCUPANCY_VALUE, TC_BLACK, SA_RIGHT);
640  }
641 
642  break;
643  }
644 
645  case WID_GL_LIST_GROUP: {
646  int y1 = r.top;
647  auto [first, last] = this->group_sb->GetVisibleRangeIterators(this->groups);
648  for (auto it = first; it != last; ++it) {
649  const Group *g = it->group;
650 
651  assert(g->owner == this->owner);
652 
653  DrawGroupInfo(y1, r.left, r.right, g->index, it->level_mask, it->indent, HasBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION), g->folded || (std::next(it) != std::end(this->groups) && std::next(it)->indent > it->indent));
654 
655  y1 += this->tiny_step_height;
656  }
657  if ((uint)this->group_sb->GetPosition() + this->group_sb->GetCapacity() > this->groups.size()) {
658  DrawGroupInfo(y1, r.left, r.right, NEW_GROUP);
659  }
660  break;
661  }
662 
665  break;
666 
667  case WID_GL_LIST_VEHICLE:
668  if (this->vli.index != ALL_GROUP && this->grouping == GB_NONE) {
669  /* Mark vehicles which are in sub-groups (only if we are not using shared order coalescing) */
670  Rect mr = r.WithHeight(this->resize.step_height);
671  auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->vehgroups);
672  for (auto it = first; it != last; ++it) {
673  const Vehicle *v = it->GetSingleVehicle();
674  if (v->group_id != this->vli.index) {
676  }
677  mr = mr.Translate(0, this->resize.step_height);
678  }
679  }
680 
681  this->DrawVehicleListItems(this->vehicle_sel, this->resize.step_height, r);
682  break;
683  }
684  }
685 
686  static void DeleteGroupCallback(Window *win, bool confirmed)
687  {
688  if (confirmed) {
690  w->vli.index = ALL_GROUP;
691  Command<CMD_DELETE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_DELETE, w->group_confirm);
692  }
693  }
694 
695  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
696  {
697  switch (widget) {
698  case WID_GL_SORT_BY_ORDER: // Flip sorting method ascending/descending
699  this->vehgroups.ToggleSortOrder();
700  this->SetDirty();
701  break;
702 
703  case WID_GL_GROUP_BY_DROPDOWN: // Select grouping option dropdown menu
704  ShowDropDownMenu(this, this->vehicle_group_by_names, this->grouping, WID_GL_GROUP_BY_DROPDOWN, 0, 0);
705  return;
706 
707  case WID_GL_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
708  ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_GL_SORT_BY_DROPDOWN, 0, (this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10));
709  return;
710 
711  case WID_GL_FILTER_BY_CARGO: // Select filtering criteria dropdown menu
712  ShowDropDownList(this, this->BuildCargoDropDownList(false), this->cargo_filter_criteria, widget);
713  break;
714 
715  case WID_GL_ALL_VEHICLES: // All vehicles button
716  if (!IsAllGroupID(this->vli.index)) {
717  this->vli.index = ALL_GROUP;
718  this->vehgroups.ForceRebuild();
719  this->SetDirty();
720  }
721  break;
722 
723  case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles button
724  if (!IsDefaultGroupID(this->vli.index)) {
725  this->vli.index = DEFAULT_GROUP;
726  this->vehgroups.ForceRebuild();
727  this->SetDirty();
728  }
729  break;
730 
731  case WID_GL_LIST_GROUP: { // Matrix Group
732  auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
733  if (it == this->groups.end()) return;
734 
735  if (it->group->folded || (std::next(it) != std::end(this->groups) && std::next(it)->indent > it->indent)) {
736  /* The group has children, check if the user clicked the fold / unfold button. */
737  NWidgetCore *group_display = this->GetWidget<NWidgetCore>(widget);
738  int x = _current_text_dir == TD_RTL ?
739  group_display->pos_x + group_display->current_x - WidgetDimensions::scaled.framerect.right - it->indent * WidgetDimensions::scaled.hsep_indent - this->column_size[VGC_FOLD].width :
740  group_display->pos_x + WidgetDimensions::scaled.framerect.left + it->indent * WidgetDimensions::scaled.hsep_indent;
741  if (click_count > 1 || (pt.x >= x && pt.x < (int)(x + this->column_size[VGC_FOLD].width))) {
742 
743  GroupID g = this->vli.index;
744  if (!IsAllGroupID(g) && !IsDefaultGroupID(g)) {
745  do {
746  g = Group::Get(g)->parent;
747  if (g == it->group->index) {
748  this->vli.index = g;
749  break;
750  }
751  } while (g != INVALID_GROUP);
752  }
753 
754  Group::Get(it->group->index)->folded = !it->group->folded;
755  this->groups.ForceRebuild();
756 
757  this->SetDirty();
758  break;
759  }
760  }
761 
762  this->group_sel = this->vli.index = it->group->index;
763 
764  SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
765 
766  this->vehgroups.ForceRebuild();
767  this->SetDirty();
768  break;
769  }
770 
771  case WID_GL_LIST_VEHICLE: { // Matrix Vehicle
772  auto it = this->vscroll->GetScrolledItemFromWidget(this->vehgroups, pt.y, this, WID_GL_LIST_VEHICLE);
773  if (it == this->vehgroups.end()) return; // click out of list bound
774 
775  const GUIVehicleGroup &vehgroup = *it;
776 
777  const Vehicle *v = nullptr;
778 
779  switch (this->grouping) {
780  case GB_NONE: {
781  const Vehicle *v2 = vehgroup.GetSingleVehicle();
782  if (VehicleClicked(v2)) break;
783  v = v2;
784  break;
785  }
786 
787  case GB_SHARED_ORDERS: {
788  assert(vehgroup.NumVehicles() > 0);
789  v = vehgroup.vehicles_begin[0];
790  /*
791  * No VehicleClicked(v) support for now, because don't want
792  * to enable any contextual actions except perhaps clicking/ctrl-clicking to clone orders.
793  */
794  break;
795  }
796 
797  default:
798  NOT_REACHED();
799  }
800  if (v) {
801  if (_ctrl_pressed && this->grouping == GB_SHARED_ORDERS) {
802  ShowOrdersWindow(v);
803  } else {
804  this->vehicle_sel = v->index;
805 
806  if (_ctrl_pressed && this->grouping == GB_NONE) {
807  /*
808  * It only makes sense to select a group if not using shared orders
809  * since two vehicles sharing orders can be from different groups.
810  */
811  this->SelectGroup(v->group_id);
812  }
813 
814  SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
816  _cursor.vehchain = true;
817 
818  this->SetDirty();
819  }
820  }
821 
822  break;
823  }
824 
825  case WID_GL_CREATE_GROUP: { // Create a new group
826  Command<CMD_CREATE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_CREATE, CcCreateGroup, this->vli.vtype, this->vli.index);
827  break;
828  }
829 
830  case WID_GL_DELETE_GROUP: { // Delete the selected group
831  this->group_confirm = this->vli.index;
832  ShowQuery(STR_QUERY_GROUP_DELETE_CAPTION, STR_GROUP_DELETE_QUERY_TEXT, this, DeleteGroupCallback);
833  break;
834  }
835 
836  case WID_GL_RENAME_GROUP: // Rename the selected roup
837  this->ShowRenameGroupWindow(this->vli.index, false);
838  break;
839 
840  case WID_GL_LIVERY_GROUP: // Set group livery
841  ShowCompanyLiveryWindow(this->owner, this->vli.index);
842  break;
843 
845  ShowBuildVehicleWindow(INVALID_TILE, this->vli.vtype);
846  break;
847 
849  ShowDropDownList(this, this->BuildActionDropdownList(true, Group::IsValidID(this->vli.index), IsDefaultGroupID(this->vli.index)), -1, WID_GL_MANAGE_VEHICLES_DROPDOWN);
850  break;
851  }
852 
853  case WID_GL_START_ALL:
854  case WID_GL_STOP_ALL: { // Start/stop all vehicles of the list
855  Command<CMD_MASS_START_STOP>::Post(0, widget == WID_GL_START_ALL, true, this->vli);
856  break;
857  }
858 
860  const Group *g = Group::GetIfValid(this->vli.index);
861  if (g != nullptr) {
863  }
864  break;
865  }
866  }
867  }
868 
869  void OnDragDrop_Group(Point pt, WidgetID widget)
870  {
871  const Group *g = Group::Get(this->group_sel);
872 
873  switch (widget) {
874  case WID_GL_ALL_VEHICLES: // All vehicles
875  case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
876  if (g->parent != INVALID_GROUP) {
877  Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_SET_PARENT, AlterGroupMode::SetParent, this->group_sel, INVALID_GROUP, {});
878  }
879 
880  this->group_sel = INVALID_GROUP;
881  this->group_over = INVALID_GROUP;
882  this->SetDirty();
883  break;
884 
885  case WID_GL_LIST_GROUP: { // Matrix group
886  auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
887  GroupID new_g = it == this->groups.end() ? INVALID_GROUP : it->group->index;
888 
889  if (this->group_sel != new_g && g->parent != new_g) {
890  Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_SET_PARENT, AlterGroupMode::SetParent, this->group_sel, new_g, {});
891  }
892 
893  this->group_sel = INVALID_GROUP;
894  this->group_over = INVALID_GROUP;
895  this->SetDirty();
896  break;
897  }
898  }
899  }
900 
901  void OnDragDrop_Vehicle(Point pt, WidgetID widget)
902  {
903  switch (widget) {
904  case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
905  Command<CMD_ADD_VEHICLE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE, DEFAULT_GROUP, this->vehicle_sel, _ctrl_pressed || this->grouping == GB_SHARED_ORDERS, VehicleListIdentifier{});
906 
908  this->group_over = INVALID_GROUP;
909 
910  this->SetDirty();
911  break;
912 
913  case WID_GL_LIST_GROUP: { // Matrix group
914  const VehicleID vindex = this->vehicle_sel;
915  this->vehicle_sel = INVALID_VEHICLE;
916  this->group_over = INVALID_GROUP;
917  this->SetDirty();
918 
919  auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
920  GroupID new_g = it == this->groups.end() ? NEW_GROUP : it->group->index;
921 
922  Command<CMD_ADD_VEHICLE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE, new_g == NEW_GROUP ? CcAddVehicleNewGroup : nullptr, new_g, vindex, _ctrl_pressed || this->grouping == GB_SHARED_ORDERS, VehicleListIdentifier{});
923  break;
924  }
925 
926  case WID_GL_LIST_VEHICLE: { // Matrix vehicle
927  const VehicleID vindex = this->vehicle_sel;
928  this->vehicle_sel = INVALID_VEHICLE;
929  this->group_over = INVALID_GROUP;
930  this->SetDirty();
931 
932  auto it = this->vscroll->GetScrolledItemFromWidget(this->vehgroups, pt.y, this, WID_GL_LIST_VEHICLE);
933  if (it == this->vehgroups.end()) return; // click out of list bound
934 
935  const GUIVehicleGroup &vehgroup = *it;
936  switch (this->grouping) {
937  case GB_NONE: {
938  const Vehicle *v = vehgroup.GetSingleVehicle();
939  if (!VehicleClicked(v) && vindex == v->index) {
941  }
942  break;
943  }
944 
945  case GB_SHARED_ORDERS: {
946  if (!VehicleClicked(vehgroup)) {
947  const Vehicle *v = vehgroup.vehicles_begin[0];
948  if (vindex == v->index) {
949  if (vehgroup.NumVehicles() == 1) {
951  } else {
952  ShowVehicleListWindow(v);
953  }
954  }
955  }
956  break;
957  }
958 
959  default:
960  NOT_REACHED();
961  }
962  break;
963  }
964  }
965  }
966 
967  void OnDragDrop(Point pt, WidgetID widget) override
968  {
969  if (this->vehicle_sel != INVALID_VEHICLE) OnDragDrop_Vehicle(pt, widget);
970  if (this->group_sel != INVALID_GROUP) OnDragDrop_Group(pt, widget);
971 
972  _cursor.vehchain = false;
973  }
974 
975  void OnQueryTextFinished(std::optional<std::string> str) override
976  {
977  if (str.has_value()) Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_RENAME, AlterGroupMode::Rename, this->group_rename, 0, *str);
978  this->group_rename = INVALID_GROUP;
979  }
980 
981  void OnResize() override
982  {
983  this->group_sb->SetCapacityFromWidget(this, WID_GL_LIST_GROUP);
984  this->vscroll->SetCapacityFromWidget(this, WID_GL_LIST_VEHICLE);
985  }
986 
987  void OnDropdownSelect(WidgetID widget, int index) override
988  {
989  switch (widget) {
991  this->UpdateVehicleGroupBy(static_cast<GroupBy>(index));
992  break;
993 
995  this->vehgroups.SetSortType(index);
996  break;
997 
998  case WID_GL_FILTER_BY_CARGO: // Select a cargo filter criteria
999  this->SetCargoFilter(index);
1000  break;
1001 
1003  assert(!this->vehicles.empty());
1004 
1005  switch (index) {
1006  case ADI_REPLACE: // Replace window
1007  ShowReplaceGroupVehicleWindow(this->vli.index, this->vli.vtype);
1008  break;
1009  case ADI_SERVICE: // Send for servicing
1010  case ADI_DEPOT: { // Send to Depots
1011  Command<CMD_SEND_VEHICLE_TO_DEPOT>::Post(GetCmdSendToDepotMsg(this->vli.vtype), 0, DepotCommand::MassSend | (index == ADI_SERVICE ? DepotCommand::Service : DepotCommand::None), this->vli);
1012  break;
1013  }
1014 
1015  case ADI_CREATE_GROUP: // Create group
1017  break;
1018 
1019  case ADI_ADD_SHARED: // Add shared Vehicles
1020  assert(Group::IsValidID(this->vli.index));
1021 
1022  Command<CMD_ADD_SHARED_VEHICLE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_ADD_SHARED_VEHICLE, this->vli.index, this->vli.vtype);
1023  break;
1024  case ADI_REMOVE_ALL: // Remove all Vehicles from the selected group
1025  assert(Group::IsValidID(this->vli.index));
1026 
1027  Command<CMD_REMOVE_ALL_VEHICLES_GROUP>::Post(STR_ERROR_GROUP_CAN_T_REMOVE_ALL_VEHICLES, this->vli.index);
1028  break;
1029  default: NOT_REACHED();
1030  }
1031  break;
1032 
1033  default: NOT_REACHED();
1034  }
1035 
1036  this->SetDirty();
1037  }
1038 
1039  void OnGameTick() override
1040  {
1041  if (this->groups.NeedResort() || this->vehgroups.NeedResort()) {
1042  this->SetDirty();
1043  }
1044  }
1045 
1046  void OnPlaceObjectAbort() override
1047  {
1048  /* abort drag & drop */
1049  this->vehicle_sel = INVALID_VEHICLE;
1051  this->group_sel = INVALID_GROUP;
1052  this->group_over = INVALID_GROUP;
1054  }
1055 
1056  void OnMouseDrag(Point pt, WidgetID widget) override
1057  {
1058  if (this->vehicle_sel == INVALID_VEHICLE && this->group_sel == INVALID_GROUP) return;
1059 
1060  /* A vehicle is dragged over... */
1061  GroupID new_group_over = INVALID_GROUP;
1062  switch (widget) {
1063  case WID_GL_DEFAULT_VEHICLES: // ... the 'default' group.
1064  new_group_over = DEFAULT_GROUP;
1065  break;
1066 
1067  case WID_GL_LIST_GROUP: { // ... the list of custom groups.
1068  auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
1069  new_group_over = it == this->groups.end() ? NEW_GROUP : it->group->index;
1070  break;
1071  }
1072  }
1073 
1074  /* Do not highlight when dragging over the current group */
1075  if (this->vehicle_sel != INVALID_VEHICLE) {
1076  if (Vehicle::Get(vehicle_sel)->group_id == new_group_over) new_group_over = INVALID_GROUP;
1077  } else if (this->group_sel != INVALID_GROUP) {
1078  if (this->group_sel == new_group_over || Group::Get(this->group_sel)->parent == new_group_over) new_group_over = INVALID_GROUP;
1079  }
1080 
1081  /* Mark widgets as dirty if the group changed. */
1082  if (new_group_over != this->group_over) {
1084  this->group_over = new_group_over;
1086  }
1087  }
1088 
1089  void ShowRenameGroupWindow(GroupID group, bool empty)
1090  {
1091  assert(Group::IsValidID(group));
1092  this->group_rename = group;
1093  /* Show empty query for new groups */
1094  StringID str = STR_EMPTY;
1095  if (!empty) {
1096  SetDParam(0, group);
1097  str = STR_GROUP_NAME;
1098  }
1100  }
1101 
1108  {
1109  if (this->vehicle_sel == vehicle) ResetObjectToPlace();
1110  }
1111 
1117  void SelectGroup(const GroupID g_id)
1118  {
1119  if (g_id == INVALID_GROUP || g_id == this->vli.index) return;
1120 
1121  this->vli.index = g_id;
1122  if (g_id != ALL_GROUP && g_id != DEFAULT_GROUP) {
1123  const Group *g = Group::Get(g_id);
1124 
1125  auto found = std::find_if(std::begin(this->groups), std::end(this->groups), [g](const auto &item) { return item.group == g; });
1126  if (found == std::end(this->groups)) {
1127  /* The group's branch is maybe collapsed, so try to expand it. */
1128  for (auto pg = Group::GetIfValid(g->parent); pg != nullptr; pg = Group::GetIfValid(pg->parent)) {
1129  pg->folded = false;
1130  }
1131  this->groups.ForceRebuild();
1132  this->BuildGroupList(this->owner);
1133  this->group_sb->SetCount(this->groups.size());
1134  found = std::find_if(std::begin(this->groups), std::end(this->groups), [g](const auto &item) { return item.group == g; });
1135  }
1136  if (found != std::end(this->groups)) this->group_sb->ScrollTowards(std::distance(std::begin(this->groups), found));
1137  }
1138  this->vehgroups.ForceRebuild();
1139  this->SetDirty();
1140  }
1141 
1142 };
1143 
1144 
1145 static WindowDesc _other_group_desc(
1146  WDP_AUTO, "list_groups", 460, 246,
1148  0,
1149  _nested_group_widgets
1150 );
1151 
1152 static WindowDesc _train_group_desc(
1153  WDP_AUTO, "list_groups_train", 525, 246,
1155  0,
1156  _nested_group_widgets
1157 );
1158 
1166 void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group, bool need_existing_window)
1167 {
1168  if (!Company::IsValidID(company)) return;
1169 
1170  const WindowNumber num = VehicleListIdentifier(VL_GROUP_LIST, vehicle_type, company).Pack();
1171  VehicleGroupWindow *w;
1172  if (vehicle_type == VEH_TRAIN) {
1173  w = AllocateWindowDescFront<VehicleGroupWindow>(_train_group_desc, num, need_existing_window);
1174  } else {
1175  _other_group_desc.cls = GetWindowClassForVehicleType(vehicle_type);
1176  w = AllocateWindowDescFront<VehicleGroupWindow>(_other_group_desc, num, need_existing_window);
1177  }
1178  if (w != nullptr) w->SelectGroup(group);
1179 }
1180 
1186 {
1187  ShowCompanyGroup(v->owner, v->type, v->group_id, true);
1188 }
1189 
1197 {
1198  return dynamic_cast<VehicleGroupWindow *>(FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).Pack()));
1199 }
1200 
1205 static void CcCreateGroup(GroupID gid, VehicleType veh_type)
1206 {
1208  if (w != nullptr) w->ShowRenameGroupWindow(gid, true);
1209 }
1210 
1218 void CcCreateGroup(Commands, const CommandCost &result, GroupID new_group, VehicleType vt, GroupID)
1219 {
1220  if (result.Failed()) return;
1221 
1222  assert(vt <= VEH_AIRCRAFT);
1223  CcCreateGroup(new_group, vt);
1224 }
1225 
1232 {
1233  if (result.Failed()) return;
1234 
1235  const Group *g = Group::Get(new_group);
1236  CcCreateGroup(new_group, g->vehicle_type);
1237 }
1238 
1244 {
1245  /* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any group windows either
1246  * If that is the case, we can skip looping though the windows and save time
1247  */
1248  if (_special_mouse_mode != WSM_DRAGDROP) return;
1249 
1251  if (w != nullptr) w->UnselectVehicle(v->index);
1252 }
WID_GL_CAPTION
@ WID_GL_CAPTION
Caption of the window.
Definition: group_widget.h:15
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1183
GetColourGradient
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Definition: palette.cpp:314
Scrollbar::ScrollTowards
void ScrollTowards(size_type position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:843
WID_GL_AVAILABLE_VEHICLES
@ WID_GL_AVAILABLE_VEHICLES
Available vehicles.
Definition: group_widget.h:23
WID_GL_CREATE_GROUP
@ WID_GL_CREATE_GROUP
Create group button.
Definition: group_widget.h:32
VehicleGroupWindow::SelectGroup
void SelectGroup(const GroupID g_id)
Selects the specified group in the list.
Definition: group_gui.cpp:1117
VehicleGroupWindow::ListColumns
ListColumns
Definition: group_gui.cpp:193
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition: window.cpp:1152
WC_INVALID
@ WC_INVALID
Invalid window.
Definition: window_type.h:718
VehicleGroupWindow::VGC_NAME
@ VGC_NAME
Group name.
Definition: group_gui.cpp:195
Pool::PoolItem<&_group_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
vehicle_gui.h
WID_GL_SORT_BY_DROPDOWN
@ WID_GL_SORT_BY_DROPDOWN
Sort by dropdown list.
Definition: group_widget.h:19
DepotCommand::MassSend
@ MassSend
Tells that it's a mass send to depot command (type in VLW flag)
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
Definition: misc_gui.cpp:1223
VehicleListIdentifier::company
CompanyID company
The company associated with this list.
Definition: vehiclelist.h:31
WID_GL_FILTER_BY_CARGO
@ WID_GL_FILTER_BY_CARGO
Filter vehicles by cargo type.
Definition: group_widget.h:20
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
command_func.h
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
BaseVehicleListWindow::BuildActionDropdownList
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group, bool show_create)
Display the Action dropdown window.
Definition: vehicle_gui.cpp:449
Pool::PoolItem<&_group_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:350
WID_GL_GROUP_BY_ORDER
@ WID_GL_GROUP_BY_ORDER
Group order.
Definition: group_widget.h:16
dropdown_func.h
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
BaseVehicleListWindow::grouping
GroupBy grouping
How we want to group the list.
Definition: vehicle_gui_base.h:76
VehicleListIdentifier
The information about a vehicle list.
Definition: vehiclelist.h:28
_special_mouse_mode
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
Definition: window.cpp:93
VehicleGroupWindow::group_confirm
GroupID group_confirm
Group awaiting delete confirmation.
Definition: group_gui.cpp:207
WID_GL_START_ALL
@ WID_GL_START_ALL
Start all button.
Definition: group_widget.h:26
company_base.h
VehicleGroupWindow::tiny_step_height
uint tiny_step_height
Step height for the group list.
Definition: group_gui.cpp:209
VehicleGroupWindow::VGC_AUTOREPLACE
@ VGC_AUTOREPLACE
Autoreplace active icon.
Definition: group_gui.cpp:197
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
company_gui.h
CursorVars::vehchain
bool vehchain
vehicle chain is dragged
Definition: gfx_type.h:150
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:551
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
VehicleGroupWindow::group_rename
GroupID group_rename
Group being renamed, INVALID_GROUP if none.
Definition: group_gui.cpp:205
GUIList< GUIGroupListItem >
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
group_gui.h
Group::parent
GroupID parent
Parent group.
Definition: group.h:83
WID_GL_REPLACE_PROTECTION
@ WID_GL_REPLACE_PROTECTION
Replace protection button.
Definition: group_widget.h:36
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:238
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
VehicleGroupWindow::DirtyHighlightedGroupWidget
void DirtyHighlightedGroupWidget()
Mark the widget containing the currently highlighted group as dirty.
Definition: group_gui.cpp:377
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
Vehicle::group_id
GroupID group_id
Index of group Pool array.
Definition: vehicle_base.h:366
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:61
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1098
BaseVehicleListWindow::sorting
Listing * sorting
Pointer to the vehicle type related sorting.
Definition: vehicle_gui_base.h:79
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1193
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1216
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:301
GroupStatistics::autoreplace_finished
bool autoreplace_finished
Have all autoreplacement finished?
Definition: group.h:31
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:260
vehicle_base.h
WID_GL_STOP_ALL
@ WID_GL_STOP_ALL
Stop all button.
Definition: group_widget.h:25
GUIList::SetSortType
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:124
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
autoreplace_gui.h
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2394
StrNaturalCompare
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:566
VehicleGroupWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: group_gui.cpp:544
VehicleGroupWindow::UnselectVehicle
void UnselectVehicle(VehicleID vehicle)
Tests whether a given vehicle is selected in the window, and unselects it if necessary.
Definition: group_gui.cpp:1107
GUIVehicleGroup::vehicles_begin
VehicleList::const_iterator vehicles_begin
Pointer to beginning element of this vehicle group.
Definition: vehicle_gui_base.h:25
WindowDesc::cls
WindowClass cls
Class of the window,.
Definition: window_gui.h:173
MAX_LENGTH_GROUP_NAME_CHARS
static const uint MAX_LENGTH_GROUP_NAME_CHARS
The maximum length of a group name in characters including '\0'.
Definition: group_type.h:20
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition: timer_game_economy.cpp:97
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
GetGroupProfitLastYearMinAge
Money GetGroupProfitLastYearMinAge(CompanyID company, GroupID id_g, VehicleType type)
Get last year's profit of vehicles above minimum age for the group with GroupID id_g and its sub-grou...
Definition: group_cmd.cpp:851
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
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
VehicleGroupWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: group_gui.cpp:1039
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:347
VehicleGroupWindow::VGC_FOLD
@ VGC_FOLD
Fold / Unfold button.
Definition: group_gui.cpp:194
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:244
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:309
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:696
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:314
VehicleGroupWindow::column_size
Dimension column_size[VGC_END]
Size of the columns in the group list.
Definition: group_gui.cpp:212
Group::vehicle_type
VehicleType vehicle_type
Vehicle type of the group.
Definition: group.h:75
WID_GL_SORT_BY_ORDER
@ WID_GL_SORT_BY_ORDER
Sort order.
Definition: group_widget.h:18
NEW_GROUP
static const GroupID NEW_GROUP
Sentinel for a to-be-created group.
Definition: group_type.h:15
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:211
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1077
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:391
textbuf_gui.h
QSF_LEN_IN_CHARS
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
Definition: textbuf_gui.h:22
ALL_GROUP
static const GroupID ALL_GROUP
All vehicles are in this group.
Definition: group_type.h:16
gfx_func.h
WindowDesc
High level window description.
Definition: window_gui.h:162
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
Group
Group data.
Definition: group.h:72
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:526
WID_GL_DELETE_GROUP
@ WID_GL_DELETE_GROUP
Delete group button.
Definition: group_widget.h:33
GroupStatistics
Statistics and caches on the vehicles in a group.
Definition: group.h:24
BaseVehicleListWindow::vli
VehicleListIdentifier vli
Identifier of the vehicle list we want to currently show.
Definition: vehicle_gui_base.h:82
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:123
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1128
WID_GL_ALL_VEHICLES
@ WID_GL_ALL_VEHICLES
All vehicles entry.
Definition: group_widget.h:28
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:222
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:150
INVALID_GROUP
static const GroupID INVALID_GROUP
Sentinel for invalid groups.
Definition: group_type.h:18
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
CommandCost
Common return value for all commands.
Definition: command_type.h:23
tilehighlight_func.h
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:731
GetGroupNumVehicleMinAge
uint GetGroupNumVehicleMinAge(CompanyID company, GroupID id_g, VehicleType type)
Get the number of vehicles above profit minimum age in the group with GroupID id_g and its sub-groups...
Definition: group_cmd.cpp:834
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:209
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:174
WID_GL_LIVERY_GROUP
@ WID_GL_LIVERY_GROUP
Group livery button.
Definition: group_widget.h:35
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1286
ShowCompanyGroupForVehicle
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
Definition: group_gui.cpp:1185
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:315
WID_GL_LIST_GROUP
@ WID_GL_LIST_GROUP
List of the groups.
Definition: group_widget.h:30
VehicleClicked
bool VehicleClicked(const Vehicle *v)
Dispatch a "vehicle selected" event if any window waits for it.
Definition: vehicle_gui.cpp:3423
WID_GL_INFO
@ WID_GL_INFO
Group info.
Definition: group_widget.h:37
BaseVehicleListWindow
Definition: vehicle_gui_base.h:67
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:54
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:940
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:236
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:210
VehicleListIdentifier::index
uint32_t index
A vehicle list type specific index.
Definition: vehiclelist.h:32
AlterGroupMode::Rename
@ Rename
Change group name.
VehicleGroupWindow::ComputeGroupInfoSize
uint ComputeGroupInfoSize()
Compute tiny_step_height and column_size.
Definition: group_gui.cpp:234
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:171
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:114
vehicle_gui_base.h
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:256
GetVehicleListHeight
uint GetVehicleListHeight(VehicleType type, uint divisor)
Get the height of a vehicle in the vehicle list GUIs.
Definition: vehicle_gui.cpp:1675
Group::owner
Owner owner
Group Owner.
Definition: group.h:74
VehicleGroupWindow::VGC_NUMBER
@ VGC_NUMBER
Number of vehicles in the group.
Definition: group_gui.cpp:199
WID_GL_LIST_VEHICLE_SCROLLBAR
@ WID_GL_LIST_VEHICLE_SCROLLBAR
Scrollbar for the list.
Definition: group_widget.h:22
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:357
VehicleListIdentifier::Pack
uint32_t Pack() const
Pack a VehicleListIdentifier in a single uint32.
Definition: vehiclelist.cpp:23
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:331
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1311
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:246
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:52
BaseVehicleListWindow::BuildCargoDropDownList
DropDownList BuildCargoDropDownList(bool full) const
Build drop down list for cargo filter selection.
Definition: vehicle_gui.cpp:421
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:1079
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:312
vehicle_cmd.h
GroupStatistics::Get
static GroupStatistics & Get(CompanyID company, GroupID id_g, VehicleType type)
Returns the GroupStatistics for a specific group.
Definition: group_cmd.cpp:63
DEFAULT_GROUP
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Definition: group_type.h:17
SetMouseCursorVehicle
void SetMouseCursorVehicle(const Vehicle *v, EngineImageType image_type)
Set the mouse cursor to look like a vehicle.
Definition: vehicle_gui.cpp:3531
WID_GL_DEFAULT_VEHICLES
@ WID_GL_DEFAULT_VEHICLES
Default vehicles entry.
Definition: group_widget.h:29
VehicleID
uint32_t VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
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:988
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition: window_type.h:308
WSM_DRAGDROP
@ WSM_DRAGDROP
Drag&drop an object.
Definition: window_gui.h:1044
BaseVehicleListWindow::GetActionDropdownSize
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group, bool show_create)
Compute the size for the Action dropdown.
Definition: vehicle_gui.cpp:382
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:305
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:114
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:18
GroupStatistics::num_vehicle
uint16_t num_vehicle
Number of vehicles.
Definition: group.h:28
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:25
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
VehicleGroupWindow::VGC_PROTECT
@ VGC_PROTECT
Autoreplace protect icon.
Definition: group_gui.cpp:196
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
BaseVehicleListWindow::cargo_filter_criteria
CargoID cargo_filter_criteria
Selected cargo filter index.
Definition: vehicle_gui_base.h:84
GroupStatistics::autoreplace_defined
bool autoreplace_defined
Are any autoreplace rules set?
Definition: group.h:30
HT_DRAG
@ HT_DRAG
dragging items in the depot windows
Definition: tilehighlight_type.h:24
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
group_cmd.h
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:922
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
AssignBit
constexpr T AssignBit(T &x, const uint8_t y, bool value)
Assigns a bit in a variable.
Definition: bitmath_func.hpp:200
BaseVehicleListWindow::DrawVehicleListItems
void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const
Draw all the vehicle list items.
Definition: vehicle_gui.cpp:1706
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:399
string_func.h
IsAllGroupID
bool IsAllGroupID(GroupID id_g)
Checks if a GroupID stands for all vehicles of a company.
Definition: group.h:100
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:115
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:223
EIT_IN_LIST
@ EIT_IN_LIST
Vehicle drawn in vehicle list, group list, ...
Definition: vehicle_type.h:82
WID_GL_LIST_GROUP_SCROLLBAR
@ WID_GL_LIST_GROUP_SCROLLBAR
Scrollbar for the list.
Definition: group_widget.h:31
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:53
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:763
vehicle_func.h
DeleteGroupHighlightOfVehicle
void DeleteGroupHighlightOfVehicle(const Vehicle *v)
Removes the highlight of a vehicle in a group window.
Definition: group_gui.cpp:1243
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1610
Pool::PoolItem<&_group_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:388
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1723
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
VehicleGroupWindow::VGC_PROFIT
@ VGC_PROFIT
Profit icon.
Definition: group_gui.cpp:198
Group::flags
uint8_t flags
Group flags.
Definition: group.h:77
GUIVehicleGroup
Definition: vehicle_gui_base.h:24
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:250
VehicleGroupWindow::groups
GUIGroupList groups
List of groups.
Definition: group_gui.cpp:208
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition: sortlist_type.h:138
VehicleGroupWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: group_gui.cpp:981
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:78
ShowReplaceGroupVehicleWindow
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
Definition: autoreplace_gui.cpp:889
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1035
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
SetDParamMaxValue
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:127
VehicleListIdentifier::vtype
VehicleType vtype
The vehicle type associated with this list.
Definition: vehiclelist.h:30
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
geometry_func.hpp
BaseVehicleListWindow::vehicle_sel
VehicleID vehicle_sel
Selected vehicle.
Definition: vehicle_gui_base.h:83
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
CcAddVehicleNewGroup
void CcAddVehicleNewGroup(Commands, const CommandCost &result, GroupID new_group, GroupID, VehicleID, bool, const VehicleListIdentifier &)
Open rename window after adding a vehicle to a new group via drag and drop.
Definition: group_gui.cpp:1231
VehicleGroupWindow::group_over
GroupID group_over
Group over which a vehicle is dragged, INVALID_GROUP if none.
Definition: group_gui.cpp:206
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:782
ShowDropDownMenu
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:441
WID_GL_RENAME_GROUP
@ WID_GL_RENAME_GROUP
Rename group button.
Definition: group_widget.h:34
DepotCommand::None
@ None
No special flags.
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1733
GroupID
uint16_t GroupID
Type for all group identifiers.
Definition: group_type.h:13
CcCreateGroup
static void CcCreateGroup(GroupID gid, VehicleType veh_type)
Opens a 'Rename group' window for newly created group.
Definition: group_gui.cpp:1205
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Definition: dropdown.cpp:404
BaseVehicleListWindow::SetCargoFilter
void SetCargoFilter(uint8_t index)
Set cargo filter for the vehicle group list.
Definition: vehicle_gui.cpp:340
container_func.hpp
company_func.h
FindVehicleGroupWindow
static VehicleGroupWindow * FindVehicleGroupWindow(VehicleType vt, Owner owner)
Finds a group list window determined by vehicle type and owner.
Definition: group_gui.cpp:1196
Window::RaiseWidget
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition: window_gui.h:478
VehicleGroupWindow::BuildGroupList
void BuildGroupList(Owner owner)
(Re)Build the group list.
Definition: group_gui.cpp:219
CommandHelper
Definition: command_func.h:93
GUIList::SortType
uint8_t SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:114
ShowVehicleViewWindow
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
Definition: vehicle_gui.cpp:3413
window_func.h
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:77
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:77
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1139
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:780
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:409
GF_REPLACE_PROTECTION
@ GF_REPLACE_PROTECTION
If set to true, the global autoreplace has no effect on the group.
Definition: group.h:66
OverflowSafeInt< int64_t >
DepotCommand::Service
@ Service
The vehicle will leave the depot right after arrival (service only)
GetGroupNumVehicle
uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type)
Get the number of vehicles in the group with GroupID id_g and its sub-groups.
Definition: group_cmd.cpp:817
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
WID_GL_GROUP_BY_DROPDOWN
@ WID_GL_GROUP_BY_DROPDOWN
Group by dropdown list.
Definition: group_widget.h:17
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:657
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:3432
Group::folded
bool folded
NOSAVE: Is this group folded in the group view?
Definition: group.h:81
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
ShowCompanyGroup
void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group, bool need_existing_window)
Show the group window for the given company and vehicle type.
Definition: group_gui.cpp:1166
BuildGuiGroupList
void BuildGuiGroupList(GUIGroupList &dst, bool fold, Owner owner, VehicleType veh_type)
Build GUI group list, a sorted hierarchical list of groups for owner and vehicle type.
Definition: group_gui.cpp:156
WID_GL_LIST_VEHICLE
@ WID_GL_LIST_VEHICLE
List of the vehicles.
Definition: group_widget.h:21
Scrollbar::GetPosition
size_type GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:742
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition: window_gui.h:40
gui.h
SPR_CURSOR_MOUSE
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1390
VehicleGroupWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: group_gui.cpp:1046
Window
Data structure for an opened window.
Definition: window_gui.h:276
Commands
Commands
List of commands.
Definition: command_type.h:187
Pool::PoolItem<&_group_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:328
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:51
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
GetDropDownListDimension
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
Definition: dropdown.cpp:363
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1204
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:224
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1151
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:372
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
GetStringListWidth
uint GetStringListWidth(std::span< const StringID > list, FontSize fontsize)
Get maximum width of a list of strings.
Definition: gfx.cpp:874
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition: window_type.h:156
SetAspect
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlags::ResizeX)
Widget part function for setting the aspect ratio.
Definition: widget_type.h:1297
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:270
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition: window_gui.h:524
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:245
WID_GL_MANAGE_VEHICLES_DROPDOWN
@ WID_GL_MANAGE_VEHICLES_DROPDOWN
Manage vehicles dropdown list.
Definition: group_widget.h:24
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
VehicleGroupWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: group_gui.cpp:489
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
VehicleGroupWindow::group_sel
GroupID group_sel
Selected group (for drag/drop)
Definition: group_gui.cpp:204
Scrollbar::GetScrolledItemFromWidget
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition: widget_type.h:881
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3495
VehicleGroupWindow
Definition: group_gui.cpp:190
Scrollbar::GetVisibleRangeIterators
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition: widget_type.h:862
GUIGroupListItem
Definition: group_gui.h:20
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
group_widget.h
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:851
VehicleGroupWindow::DrawGroupInfo
void DrawGroupInfo(int y, int left, int right, GroupID g_id, uint16_t level_mask=0, uint8_t indent=0, bool protection=false, bool has_children=false) const
Draw a row in the group list.
Definition: group_gui.cpp:286
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
GetWindowClassForVehicleType
WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
Definition: vehicle_gui.h:97
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:72
NC_BIGFIRST
@ NC_BIGFIRST
Value of the NCB_BIGFIRST flag.
Definition: widget_type.h:527
VEHICLE_PROFIT_THRESHOLD
static const Money VEHICLE_PROFIT_THRESHOLD
Threshold for a vehicle to be considered making good profit.
Definition: vehicle_func.h:29
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
GuiGroupListAddChildren
static void GuiGroupListAddChildren(GUIGroupList &dst, const GUIGroupList &src, bool fold, GroupID parent=INVALID_GROUP, uint8_t indent=0)
Add children to GUI group list to build a hierarchical tree.
Definition: group_gui.cpp:121
AlterGroupMode::SetParent
@ SetParent
Change group parent.
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103