OpenTTD Source  14.0-beta1
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 "widgets/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 "vehicle_cmd.h"
31 #include "gfx_func.h"
32 
33 #include "widgets/group_widget.h"
34 
35 #include "table/sprites.h"
36 
37 #include "safeguards.h"
38 
40 
41 static constexpr NWidgetPart _nested_group_widgets[] = {
42  NWidget(NWID_HORIZONTAL), // Window header
43  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
44  NWidget(WWT_CAPTION, COLOUR_GREY, WID_GL_CAPTION),
45  NWidget(WWT_SHADEBOX, COLOUR_GREY),
46  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
47  NWidget(WWT_STICKYBOX, COLOUR_GREY),
48  EndContainer(),
50  /* left part */
52  NWidget(WWT_PANEL, COLOUR_GREY, WID_GL_ALL_VEHICLES), SetFill(1, 0), EndContainer(),
55  NWidget(WWT_MATRIX, COLOUR_GREY, WID_GL_LIST_GROUP), SetMatrixDataTip(1, 0, STR_GROUPS_CLICK_ON_GROUP_FOR_TOOLTIP),
58  EndContainer(),
59  NWidget(WWT_PANEL, COLOUR_GREY, WID_GL_INFO), SetFill(1, 1), SetMinimalTextLines(3, WidgetDimensions::unscaled.framerect.Vertical()), EndContainer(),
62  SetDataTip(SPR_GROUP_CREATE_TRAIN, STR_GROUP_CREATE_TOOLTIP),
64  SetDataTip(SPR_GROUP_DELETE_TRAIN, STR_GROUP_DELETE_TOOLTIP),
66  SetDataTip(SPR_GROUP_RENAME_TRAIN, STR_GROUP_RENAME_TOOLTIP),
68  SetDataTip(SPR_GROUP_LIVERY_TRAIN, STR_GROUP_LIVERY_TOOLTIP),
69  NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 0), EndContainer(),
71  SetDataTip(SPR_GROUP_REPLACE_OFF_TRAIN, STR_GROUP_REPLACE_PROTECTION_TOOLTIP),
72  EndContainer(),
73  EndContainer(),
74  /* right part */
78  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),
79  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),
80  EndContainer(),
82  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GL_GROUP_BY_DROPDOWN), SetFill(1, 0), SetMinimalSize(0, 12), SetDataTip(0x0, STR_TOOLTIP_GROUP_ORDER),
83  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GL_SORT_BY_DROPDOWN), SetFill(1, 0), SetMinimalSize(0, 12), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
84  EndContainer(),
86  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetResize(1, 0), EndContainer(),
88  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GL_FILTER_BY_CARGO), SetMinimalSize(0, 12), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA),
89  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetResize(1, 0), EndContainer(),
90  EndContainer(),
91  EndContainer(),
92  EndContainer(),
96  EndContainer(),
97  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(1, 0), SetFill(1, 1), SetResize(1, 0), EndContainer(),
100  SetDataTip(STR_JUST_STRING, STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP),
101  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetResize(1, 0), EndContainer(),
103  SetDataTip(STR_VEHICLE_LIST_MANAGE_LIST, STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP),
104  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_STOP_ALL), SetMinimalSize(12, 12),
105  SetDataTip(SPR_FLAG_VEH_STOPPED, STR_VEHICLE_LIST_MASS_STOP_LIST_TOOLTIP),
106  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_START_ALL), SetMinimalSize(12, 12),
107  SetDataTip(SPR_FLAG_VEH_RUNNING, STR_VEHICLE_LIST_MASS_START_LIST_TOOLTIP),
108  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
109  EndContainer(),
110  EndContainer(),
111  EndContainer(),
112 };
113 
115 private:
116  /* Columns in the group list */
117  enum ListColumns {
124 
125  VGC_END
126  };
127 
134  Scrollbar *group_sb;
135 
136  std::vector<int> indents;
137 
139 
140  void AddChildren(GUIGroupList &source, GroupID parent, int indent)
141  {
142  for (const Group *g : source) {
143  if (g->parent != parent) continue;
144  this->groups.push_back(g);
145  this->indents.push_back(indent);
146  if (g->folded) {
147  /* Test if this group has children at all. If not, the folded flag should be cleared to avoid lingering unfold buttons in the list. */
148  bool has_children = std::any_of(source.begin(), source.end(), [g](const Group *child){ return child->parent == g->index; });
149  Group::Get(g->index)->folded = has_children;
150  } else {
151  AddChildren(source, g->index, indent + 1);
152  }
153  }
154  }
155 
162  {
163  if (!this->groups.NeedRebuild()) return;
164 
165  this->groups.clear();
166  this->indents.clear();
167 
168  GUIGroupList list;
169 
170  for (const Group *g : Group::Iterate()) {
171  if (g->owner == owner && g->vehicle_type == this->vli.vtype) {
172  list.push_back(g);
173  }
174  }
175 
176  list.ForceResort();
177 
178  /* Sort the groups by their name */
179  const Group *last_group[2] = { nullptr, nullptr };
180  std::string last_name[2] = { {}, {} };
181  list.Sort([&](const Group * const &a, const Group * const &b) {
182  if (a != last_group[0]) {
183  last_group[0] = a;
184  SetDParam(0, a->index);
185  last_name[0] = GetString(STR_GROUP_NAME);
186  }
187 
188  if (b != last_group[1]) {
189  last_group[1] = b;
190  SetDParam(0, b->index);
191  last_name[1] = GetString(STR_GROUP_NAME);
192  }
193 
194  int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
195  if (r == 0) return a->index < b->index;
196  return r < 0;
197  });
198 
199  AddChildren(list, INVALID_GROUP, 0);
200 
201  this->groups.shrink_to_fit();
202  this->groups.RebuildDone();
203  }
204 
210  {
211  this->column_size[VGC_FOLD] = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED));
212  this->tiny_step_height = this->column_size[VGC_FOLD].height;
213 
214  this->column_size[VGC_NAME] = maxdim(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + this->vli.vtype), GetStringBoundingBox(STR_GROUP_ALL_TRAINS + this->vli.vtype));
215  this->column_size[VGC_NAME].width = std::max(170u, this->column_size[VGC_NAME].width) + WidgetDimensions::scaled.hsep_indent;
216  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_NAME].height);
217 
218  this->column_size[VGC_PROTECT] = GetSpriteSize(SPR_GROUP_REPLACE_PROTECT);
219  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_PROTECT].height);
220 
221  this->column_size[VGC_AUTOREPLACE] = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
222  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_AUTOREPLACE].height);
223 
224  this->column_size[VGC_PROFIT].width = 0;
225  this->column_size[VGC_PROFIT].height = 0;
226  static const SpriteID profit_sprites[] = {SPR_PROFIT_NA, SPR_PROFIT_NEGATIVE, SPR_PROFIT_SOME, SPR_PROFIT_LOT};
227  for (uint i = 0; i < lengthof(profit_sprites); i++) {
228  Dimension d = GetSpriteSize(profit_sprites[i]);
229  this->column_size[VGC_PROFIT] = maxdim(this->column_size[VGC_PROFIT], d);
230  }
231  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_PROFIT].height);
232 
233  int num_vehicle = GetGroupNumVehicle(this->vli.company, ALL_GROUP, this->vli.vtype);
234  SetDParamMaxValue(0, num_vehicle, 3, FS_SMALL);
235  SetDParamMaxValue(1, num_vehicle, 3, FS_SMALL);
236  this->column_size[VGC_NUMBER] = GetStringBoundingBox(STR_GROUP_COUNT_WITH_SUBGROUP);
237  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_NUMBER].height);
238 
239  this->tiny_step_height += WidgetDimensions::scaled.framerect.Vertical();
240 
241  return WidgetDimensions::scaled.framerect.left +
242  this->column_size[VGC_FOLD].width + WidgetDimensions::scaled.hsep_normal +
243  this->column_size[VGC_NAME].width + WidgetDimensions::scaled.hsep_wide +
244  this->column_size[VGC_PROTECT].width + WidgetDimensions::scaled.hsep_normal +
245  this->column_size[VGC_AUTOREPLACE].width + WidgetDimensions::scaled.hsep_normal +
246  this->column_size[VGC_PROFIT].width + WidgetDimensions::scaled.hsep_normal +
247  this->column_size[VGC_NUMBER].width +
249  }
250 
261  void DrawGroupInfo(int y, int left, int right, GroupID g_id, int indent = 0, bool protection = false, bool has_children = false) const
262  {
263  /* Highlight the group if a vehicle is dragged over it */
264  if (g_id == this->group_over) {
265  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, _colour_gradient[COLOUR_GREY][7]);
266  }
267 
268  if (g_id == NEW_GROUP) return;
269 
270  /* draw the selected group in white, else we draw it in black */
271  TextColour colour = g_id == this->vli.index ? TC_WHITE : TC_BLACK;
272  const GroupStatistics &stats = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype);
273  bool rtl = _current_text_dir == TD_RTL;
274 
275  /* draw fold / unfold button */
276  int x = rtl ? right - WidgetDimensions::scaled.framerect.right - this->column_size[VGC_FOLD].width + 1 : left + WidgetDimensions::scaled.framerect.left;
277  if (has_children) {
278  DrawSprite(Group::Get(g_id)->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, rtl ? x - indent : x + indent, y + (this->tiny_step_height - this->column_size[VGC_FOLD].height) / 2);
279  }
280 
281  /* draw group name */
282  StringID str;
283  if (IsAllGroupID(g_id)) {
284  str = STR_GROUP_ALL_TRAINS + this->vli.vtype;
285  } else if (IsDefaultGroupID(g_id)) {
286  str = STR_GROUP_DEFAULT_TRAINS + this->vli.vtype;
287  } else {
288  SetDParam(0, g_id);
289  str = STR_GROUP_NAME;
290  }
291  x = rtl ? x - WidgetDimensions::scaled.hsep_normal - this->column_size[VGC_NAME].width : x + WidgetDimensions::scaled.hsep_normal + this->column_size[VGC_FOLD].width;
292  DrawString(x + (rtl ? 0 : indent), x + this->column_size[VGC_NAME].width - 1 - (rtl ? indent : 0), y + (this->tiny_step_height - this->column_size[VGC_NAME].height) / 2, str, colour);
293 
294  /* draw autoreplace protection */
295  x = rtl ? x - WidgetDimensions::scaled.hsep_wide - this->column_size[VGC_PROTECT].width : x + WidgetDimensions::scaled.hsep_wide + this->column_size[VGC_NAME].width;
296  if (protection) DrawSprite(SPR_GROUP_REPLACE_PROTECT, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_PROTECT].height) / 2);
297 
298  /* draw autoreplace status */
299  x = rtl ? x - WidgetDimensions::scaled.hsep_normal - this->column_size[VGC_AUTOREPLACE].width : x + WidgetDimensions::scaled.hsep_normal + this->column_size[VGC_PROTECT].width;
300  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);
301 
302  /* draw the profit icon */
303  x = rtl ? x - WidgetDimensions::scaled.hsep_normal - this->column_size[VGC_PROFIT].width : x + WidgetDimensions::scaled.hsep_normal + this->column_size[VGC_AUTOREPLACE].width;
304  SpriteID spr;
305  uint num_vehicle_min_age = GetGroupNumVehicleMinAge(this->vli.company, g_id, this->vli.vtype);
306  Money profit_last_year_min_age = GetGroupProfitLastYearMinAge(this->vli.company, g_id, this->vli.vtype);
307  if (num_vehicle_min_age == 0) {
308  spr = SPR_PROFIT_NA;
309  } else if (profit_last_year_min_age < 0) {
310  spr = SPR_PROFIT_NEGATIVE;
311  } else if (profit_last_year_min_age < VEHICLE_PROFIT_THRESHOLD * num_vehicle_min_age) {
312  spr = SPR_PROFIT_SOME;
313  } else {
314  spr = SPR_PROFIT_LOT;
315  }
316  DrawSprite(spr, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_PROFIT].height) / 2);
317 
318  /* draw the number of vehicles of the group */
319  x = rtl ? x - WidgetDimensions::scaled.hsep_normal - this->column_size[VGC_NUMBER].width : x + WidgetDimensions::scaled.hsep_normal + this->column_size[VGC_PROFIT].width;
320  int num_vehicle_with_subgroups = GetGroupNumVehicle(this->vli.company, g_id, this->vli.vtype);
321  int num_vehicle = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype).num_vehicle;
322  if (IsAllGroupID(g_id) || IsDefaultGroupID(g_id) || num_vehicle_with_subgroups == num_vehicle) {
323  SetDParam(0, num_vehicle);
324  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);
325  } else {
326  SetDParam(0, num_vehicle);
327  SetDParam(1, num_vehicle_with_subgroups - num_vehicle);
328  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);
329  }
330  }
331 
336  {
337  if (this->group_over == INVALID_GROUP) return;
338 
339  if (IsAllGroupID(this->group_over)) {
341  } else if (IsDefaultGroupID(this->group_over)) {
343  } else {
345  }
346  }
347 
348 public:
350  {
351  this->CreateNestedTree();
352 
353  this->vscroll = this->GetScrollbar(WID_GL_LIST_VEHICLE_SCROLLBAR);
354  this->group_sb = this->GetScrollbar(WID_GL_LIST_GROUP_SCROLLBAR);
355 
356  this->vli.index = ALL_GROUP;
357  this->group_sel = INVALID_GROUP;
358  this->group_rename = INVALID_GROUP;
359  this->group_over = INVALID_GROUP;
360 
361  this->groups.ForceRebuild();
362  this->groups.NeedResort();
363  this->BuildGroupList(vli.company);
364  this->group_sb->SetCount(this->groups.size());
365 
366  this->GetWidget<NWidgetCore>(WID_GL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype;
367  this->GetWidget<NWidgetCore>(WID_GL_LIST_VEHICLE)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype;
368 
369  this->GetWidget<NWidgetCore>(WID_GL_CREATE_GROUP)->widget_data += this->vli.vtype;
370  this->GetWidget<NWidgetCore>(WID_GL_RENAME_GROUP)->widget_data += this->vli.vtype;
371  this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->widget_data += this->vli.vtype;
372  this->GetWidget<NWidgetCore>(WID_GL_LIVERY_GROUP)->widget_data += this->vli.vtype;
373  this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data += this->vli.vtype;
374 
375  this->FinishInitNested(window_number);
376  this->owner = vli.company;
377 
378  this->BuildVehicleList();
379  this->SortVehicleList();
380  }
381 
383  {
384  *this->sorting = this->vehgroups.GetListing();
385  }
386 
387  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
388  {
389  switch (widget) {
390  case WID_GL_LIST_GROUP:
391  size->width = this->ComputeGroupInfoSize();
392  resize->height = this->tiny_step_height;
393  fill->height = this->tiny_step_height;
394  break;
395 
396  case WID_GL_ALL_VEHICLES:
398  size->width = this->ComputeGroupInfoSize();
399  size->height = this->tiny_step_height;
400  break;
401 
402  case WID_GL_SORT_BY_ORDER: {
403  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
404  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
405  d.height += padding.height;
406  *size = maxdim(*size, d);
407  break;
408  }
409 
410  case WID_GL_LIST_VEHICLE:
411  this->ComputeGroupInfoSize();
412  resize->height = GetVehicleListHeight(this->vli.vtype, this->tiny_step_height);
413  size->height = 4 * resize->height;
414  break;
415 
417  size->width = GetStringListWidth(this->vehicle_group_by_names) + padding.width;
418  break;
419 
421  size->width = GetStringListWidth(this->vehicle_group_none_sorter_names_calendar);
422  size->width = std::max(size->width, GetStringListWidth(this->vehicle_group_none_sorter_names_wallclock));
423  size->width = std::max(size->width, GetStringListWidth(this->vehicle_group_shared_orders_sorter_names_calendar));
424  size->width = std::max(size->width, GetStringListWidth(this->vehicle_group_shared_orders_sorter_names_wallclock));
425  size->width += padding.width;
426  break;
427 
429  size->width = std::max(size->width, GetDropDownListDimension(this->BuildCargoDropDownList(true)).width + padding.width);
430  break;
431 
433  Dimension d = this->GetActionDropdownSize(true, true, true);
434  d.height += padding.height;
435  d.width += padding.width;
436  *size = maxdim(*size, d);
437  break;
438  }
439  }
440  }
441 
447  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
448  {
449  if (data == 0) {
450  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
451  this->vehgroups.ForceRebuild();
452  this->groups.ForceRebuild();
453  } else {
454  this->vehgroups.ForceResort();
455  this->groups.ForceResort();
456  }
457 
458  /* Process ID-invalidation in command-scope as well */
459  if (this->group_rename != INVALID_GROUP && !Group::IsValidID(this->group_rename)) {
461  this->group_rename = INVALID_GROUP;
462  }
463 
464  if (!(IsAllGroupID(this->vli.index) || IsDefaultGroupID(this->vli.index) || Group::IsValidID(this->vli.index))) {
465  this->vli.index = ALL_GROUP;
467  }
468  this->SetDirty();
469  }
470 
471  void SetStringParameters(WidgetID widget) const override
472  {
473  switch (widget) {
475  SetDParam(0, this->GetCargoFilterLabel(this->cargo_filter_criteria));
476  break;
477 
479  SetDParam(0, STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vli.vtype);
480  break;
481 
482  case WID_GL_CAPTION:
483  /* If selected_group == DEFAULT_GROUP || ALL_GROUP, draw the standard caption
484  * We list all vehicles or ungrouped vehicles */
485  if (IsDefaultGroupID(this->vli.index) || IsAllGroupID(this->vli.index)) {
486  SetDParam(0, STR_COMPANY_NAME);
487  SetDParam(1, this->vli.company);
488  SetDParam(2, this->vehicles.size());
489  SetDParam(3, this->vehicles.size());
490  } else {
491  uint num_vehicle = GetGroupNumVehicle(this->vli.company, this->vli.index, this->vli.vtype);
492 
493  SetDParam(0, STR_GROUP_NAME);
494  SetDParam(1, this->vli.index);
495  SetDParam(2, num_vehicle);
496  SetDParam(3, num_vehicle);
497  }
498  break;
499  }
500  }
501 
502  void OnPaint() override
503  {
504  /* If we select the all vehicles, this->list will contain all vehicles of the owner
505  * else this->list will contain all vehicles which belong to the selected group */
506  this->BuildVehicleList();
507  this->SortVehicleList();
508 
509  this->BuildGroupList(this->owner);
510 
511  this->group_sb->SetCount(this->groups.size());
512  this->vscroll->SetCount(this->vehgroups.size());
513 
514  /* The drop down menu is out, *but* it may not be used, retract it. */
515  if (this->vehicles.empty() && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) {
518  }
519 
520  /* Disable all lists management button when the list is empty */
521  this->SetWidgetsDisabledState(this->vehicles.empty() || _local_company != this->vli.company,
525 
526  /* Disable the group specific function when we select the default group or all vehicles */
527  this->SetWidgetsDisabledState(IsDefaultGroupID(this->vli.index) || IsAllGroupID(this->vli.index) || _local_company != this->vli.company,
532 
533  /* Disable remaining buttons for non-local companies
534  * Needed while changing _local_company, eg. by cheats
535  * All procedures (eg. move vehicle to another group)
536  * verify, whether you are the owner of the vehicle,
537  * so it doesn't have to be disabled
538  */
542 
543  /* If not a default group and the group has replace protection, show an enabled replace sprite. */
544  uint16_t protect_sprite = SPR_GROUP_REPLACE_OFF_TRAIN;
545  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;
546  this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data = protect_sprite + this->vli.vtype;
547 
548  /* Set text of "group by" dropdown widget. */
549  this->GetWidget<NWidgetCore>(WID_GL_GROUP_BY_DROPDOWN)->widget_data = this->vehicle_group_by_names[this->grouping];
550 
551  /* Set text of "sort by" dropdown widget. */
552  this->GetWidget<NWidgetCore>(WID_GL_SORT_BY_DROPDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()];
553 
554  this->DrawWidgets();
555  }
556 
557  void DrawWidget(const Rect &r, WidgetID widget) const override
558  {
559  switch (widget) {
560  case WID_GL_ALL_VEHICLES:
561  DrawGroupInfo(r.top, r.left, r.right, ALL_GROUP);
562  break;
563 
565  DrawGroupInfo(r.top, r.left, r.right, DEFAULT_GROUP);
566  break;
567 
568  case WID_GL_INFO: {
569  Money this_year = 0;
570  Money last_year = 0;
571  uint64_t occupancy = 0;
572 
573  for (const Vehicle * const v : this->vehicles) {
574  assert(v->owner == this->owner);
575 
576  this_year += v->GetDisplayProfitThisYear();
577  last_year += v->GetDisplayProfitLastYear();
578  occupancy += v->trip_occupancy;
579  }
580 
581  Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
582 
583  DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_THIS_PERIOD : STR_GROUP_PROFIT_THIS_YEAR, TC_BLACK);
584  SetDParam(0, this_year);
585  DrawString(tr, STR_JUST_CURRENCY_LONG, TC_BLACK, SA_RIGHT);
586 
587  tr.top += GetCharacterHeight(FS_NORMAL);
588  DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_LAST_PERIOD : STR_GROUP_PROFIT_LAST_YEAR, TC_BLACK);
589  SetDParam(0, last_year);
590  DrawString(tr, STR_JUST_CURRENCY_LONG, TC_BLACK, SA_RIGHT);
591 
592  tr.top += GetCharacterHeight(FS_NORMAL);
593  DrawString(tr, STR_GROUP_OCCUPANCY, TC_BLACK);
594  const size_t vehicle_count = this->vehicles.size();
595  if (vehicle_count > 0) {
596  SetDParam(0, occupancy / vehicle_count);
597  DrawString(tr, STR_GROUP_OCCUPANCY_VALUE, TC_BLACK, SA_RIGHT);
598  }
599 
600  break;
601  }
602 
603  case WID_GL_LIST_GROUP: {
604  int y1 = r.top;
605  size_t max = std::min<size_t>(this->group_sb->GetPosition() + this->group_sb->GetCapacity(), this->groups.size());
606  for (size_t i = this->group_sb->GetPosition(); i < max; ++i) {
607  const Group *g = this->groups[i];
608 
609  assert(g->owner == this->owner);
610 
611  DrawGroupInfo(y1, r.left, r.right, g->index, this->indents[i] * WidgetDimensions::scaled.hsep_indent, HasBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION), g->folded || (i + 1 < this->groups.size() && indents[i + 1] > this->indents[i]));
612 
613  y1 += this->tiny_step_height;
614  }
615  if ((uint)this->group_sb->GetPosition() + this->group_sb->GetCapacity() > this->groups.size()) {
616  DrawGroupInfo(y1, r.left, r.right, NEW_GROUP);
617  }
618  break;
619  }
620 
623  break;
624 
625  case WID_GL_LIST_VEHICLE:
626  if (this->vli.index != ALL_GROUP && this->grouping == GB_NONE) {
627  /* Mark vehicles which are in sub-groups (only if we are not using shared order coalescing) */
628  Rect mr = r.WithHeight(this->resize.step_height);
629  size_t max = std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehgroups.size());
630  for (size_t i = this->vscroll->GetPosition(); i < max; ++i) {
631  const Vehicle *v = this->vehgroups[i].GetSingleVehicle();
632  if (v->group_id != this->vli.index) {
634  }
635  mr = mr.Translate(0, this->resize.step_height);
636  }
637  }
638 
639  this->DrawVehicleListItems(this->vehicle_sel, this->resize.step_height, r);
640  break;
641  }
642  }
643 
644  static void DeleteGroupCallback(Window *win, bool confirmed)
645  {
646  if (confirmed) {
648  w->vli.index = ALL_GROUP;
649  Command<CMD_DELETE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_DELETE, w->group_confirm);
650  }
651  }
652 
653  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
654  {
655  switch (widget) {
656  case WID_GL_SORT_BY_ORDER: // Flip sorting method ascending/descending
657  this->vehgroups.ToggleSortOrder();
658  this->SetDirty();
659  break;
660 
661  case WID_GL_GROUP_BY_DROPDOWN: // Select grouping option dropdown menu
662  ShowDropDownMenu(this, this->vehicle_group_by_names, this->grouping, WID_GL_GROUP_BY_DROPDOWN, 0, 0);
663  return;
664 
665  case WID_GL_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
666  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));
667  return;
668 
669  case WID_GL_FILTER_BY_CARGO: // Select filtering criteria dropdown menu
670  ShowDropDownList(this, this->BuildCargoDropDownList(false), this->cargo_filter_criteria, widget);
671  break;
672 
673  case WID_GL_ALL_VEHICLES: // All vehicles button
674  if (!IsAllGroupID(this->vli.index)) {
675  this->vli.index = ALL_GROUP;
676  this->vehgroups.ForceRebuild();
677  this->SetDirty();
678  }
679  break;
680 
681  case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles button
682  if (!IsDefaultGroupID(this->vli.index)) {
683  this->vli.index = DEFAULT_GROUP;
684  this->vehgroups.ForceRebuild();
685  this->SetDirty();
686  }
687  break;
688 
689  case WID_GL_LIST_GROUP: { // Matrix Group
690  auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
691  if (it == this->groups.end()) return;
692 
693  size_t id_g = it - this->groups.begin();
694  if ((*it)->folded || (id_g + 1 < this->groups.size() && this->indents[id_g + 1] > this->indents[id_g])) {
695  /* The group has children, check if the user clicked the fold / unfold button. */
696  NWidgetCore *group_display = this->GetWidget<NWidgetCore>(widget);
697  int x = _current_text_dir == TD_RTL ?
698  group_display->pos_x + group_display->current_x - WidgetDimensions::scaled.framerect.right - this->indents[id_g] * WidgetDimensions::scaled.hsep_indent - this->column_size[VGC_FOLD].width :
699  group_display->pos_x + WidgetDimensions::scaled.framerect.left + this->indents[id_g] * WidgetDimensions::scaled.hsep_indent;
700  if (click_count > 1 || (pt.x >= x && pt.x < (int)(x + this->column_size[VGC_FOLD].width))) {
701 
702  GroupID g = this->vli.index;
703  if (!IsAllGroupID(g) && !IsDefaultGroupID(g)) {
704  do {
705  g = Group::Get(g)->parent;
706  if (g == groups[id_g]->index) {
707  this->vli.index = g;
708  break;
709  }
710  } while (g != INVALID_GROUP);
711  }
712 
713  Group::Get(groups[id_g]->index)->folded = !groups[id_g]->folded;
714  this->groups.ForceRebuild();
715 
716  this->SetDirty();
717  break;
718  }
719  }
720 
721  this->group_sel = this->vli.index = this->groups[id_g]->index;
722 
723  SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
724 
725  this->vehgroups.ForceRebuild();
726  this->SetDirty();
727  break;
728  }
729 
730  case WID_GL_LIST_VEHICLE: { // Matrix Vehicle
731  auto it = this->vscroll->GetScrolledItemFromWidget(this->vehgroups, pt.y, this, WID_GL_LIST_VEHICLE);
732  if (it == this->vehgroups.end()) return; // click out of list bound
733 
734  const GUIVehicleGroup &vehgroup = *it;
735 
736  const Vehicle *v = nullptr;
737 
738  switch (this->grouping) {
739  case GB_NONE: {
740  const Vehicle *v2 = vehgroup.GetSingleVehicle();
741  if (VehicleClicked(v2)) break;
742  v = v2;
743  break;
744  }
745 
746  case GB_SHARED_ORDERS: {
747  assert(vehgroup.NumVehicles() > 0);
748  v = vehgroup.vehicles_begin[0];
749  /*
750  * No VehicleClicked(v) support for now, because don't want
751  * to enable any contextual actions except perhaps clicking/ctrl-clicking to clone orders.
752  */
753  break;
754  }
755 
756  default:
757  NOT_REACHED();
758  }
759  if (v) {
760  if (_ctrl_pressed && this->grouping == GB_SHARED_ORDERS) {
761  ShowOrdersWindow(v);
762  } else {
763  this->vehicle_sel = v->index;
764 
765  if (_ctrl_pressed && this->grouping == GB_NONE) {
766  /*
767  * It only makes sense to select a group if not using shared orders
768  * since two vehicles sharing orders can be from different groups.
769  */
770  this->SelectGroup(v->group_id);
771  }
772 
773  SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
775  _cursor.vehchain = true;
776 
777  this->SetDirty();
778  }
779  }
780 
781  break;
782  }
783 
784  case WID_GL_CREATE_GROUP: { // Create a new group
785  Command<CMD_CREATE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_CREATE, CcCreateGroup, this->vli.vtype, this->vli.index);
786  break;
787  }
788 
789  case WID_GL_DELETE_GROUP: { // Delete the selected group
790  this->group_confirm = this->vli.index;
791  ShowQuery(STR_QUERY_GROUP_DELETE_CAPTION, STR_GROUP_DELETE_QUERY_TEXT, this, DeleteGroupCallback);
792  break;
793  }
794 
795  case WID_GL_RENAME_GROUP: // Rename the selected roup
796  this->ShowRenameGroupWindow(this->vli.index, false);
797  break;
798 
799  case WID_GL_LIVERY_GROUP: // Set group livery
800  ShowCompanyLiveryWindow(this->owner, this->vli.index);
801  break;
802 
804  ShowBuildVehicleWindow(INVALID_TILE, this->vli.vtype);
805  break;
806 
808  ShowDropDownList(this, this->BuildActionDropdownList(true, Group::IsValidID(this->vli.index), IsDefaultGroupID(this->vli.index)), 0, WID_GL_MANAGE_VEHICLES_DROPDOWN);
809  break;
810  }
811 
812  case WID_GL_START_ALL:
813  case WID_GL_STOP_ALL: { // Start/stop all vehicles of the list
814  Command<CMD_MASS_START_STOP>::Post(0, widget == WID_GL_START_ALL, true, this->vli);
815  break;
816  }
817 
819  const Group *g = Group::GetIfValid(this->vli.index);
820  if (g != nullptr) {
822  }
823  break;
824  }
825  }
826  }
827 
828  void OnDragDrop_Group(Point pt, WidgetID widget)
829  {
830  const Group *g = Group::Get(this->group_sel);
831 
832  switch (widget) {
833  case WID_GL_ALL_VEHICLES: // All vehicles
834  case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
835  if (g->parent != INVALID_GROUP) {
836  Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_SET_PARENT, AlterGroupMode::SetParent, this->group_sel, INVALID_GROUP, {});
837  }
838 
839  this->group_sel = INVALID_GROUP;
840  this->group_over = INVALID_GROUP;
841  this->SetDirty();
842  break;
843 
844  case WID_GL_LIST_GROUP: { // Matrix group
845  auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
846  GroupID new_g = it == this->groups.end() ? INVALID_GROUP : (*it)->index;
847 
848  if (this->group_sel != new_g && g->parent != new_g) {
849  Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_SET_PARENT, AlterGroupMode::SetParent, this->group_sel, new_g, {});
850  }
851 
852  this->group_sel = INVALID_GROUP;
853  this->group_over = INVALID_GROUP;
854  this->SetDirty();
855  break;
856  }
857  }
858  }
859 
860  void OnDragDrop_Vehicle(Point pt, WidgetID widget)
861  {
862  switch (widget) {
863  case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
864  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{});
865 
867  this->group_over = INVALID_GROUP;
868 
869  this->SetDirty();
870  break;
871 
872  case WID_GL_LIST_GROUP: { // Matrix group
873  const VehicleID vindex = this->vehicle_sel;
874  this->vehicle_sel = INVALID_VEHICLE;
875  this->group_over = INVALID_GROUP;
876  this->SetDirty();
877 
878  auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
879  GroupID new_g = it == this->groups.end() ? NEW_GROUP : (*it)->index;
880 
881  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{});
882  break;
883  }
884 
885  case WID_GL_LIST_VEHICLE: { // Matrix vehicle
886  const VehicleID vindex = this->vehicle_sel;
887  this->vehicle_sel = INVALID_VEHICLE;
888  this->group_over = INVALID_GROUP;
889  this->SetDirty();
890 
891  auto it = this->vscroll->GetScrolledItemFromWidget(this->vehgroups, pt.y, this, WID_GL_LIST_VEHICLE);
892  if (it == this->vehgroups.end()) return; // click out of list bound
893 
894  const GUIVehicleGroup &vehgroup = *it;
895  switch (this->grouping) {
896  case GB_NONE: {
897  const Vehicle *v = vehgroup.GetSingleVehicle();
898  if (!VehicleClicked(v) && vindex == v->index) {
900  }
901  break;
902  }
903 
904  case GB_SHARED_ORDERS: {
905  if (!VehicleClicked(vehgroup)) {
906  const Vehicle *v = vehgroup.vehicles_begin[0];
907  if (vindex == v->index) {
908  if (vehgroup.NumVehicles() == 1) {
910  } else {
911  ShowVehicleListWindow(v);
912  }
913  }
914  }
915  break;
916  }
917 
918  default:
919  NOT_REACHED();
920  }
921  break;
922  }
923  }
924  }
925 
926  void OnDragDrop(Point pt, WidgetID widget) override
927  {
928  if (this->vehicle_sel != INVALID_VEHICLE) OnDragDrop_Vehicle(pt, widget);
929  if (this->group_sel != INVALID_GROUP) OnDragDrop_Group(pt, widget);
930 
931  _cursor.vehchain = false;
932  }
933 
934  void OnQueryTextFinished(char *str) override
935  {
936  if (str != nullptr) Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_RENAME, AlterGroupMode::Rename, this->group_rename, 0, str);
937  this->group_rename = INVALID_GROUP;
938  }
939 
940  void OnResize() override
941  {
942  this->group_sb->SetCapacityFromWidget(this, WID_GL_LIST_GROUP);
943  this->vscroll->SetCapacityFromWidget(this, WID_GL_LIST_VEHICLE);
944  }
945 
946  void OnDropdownSelect(WidgetID widget, int index) override
947  {
948  switch (widget) {
950  this->UpdateVehicleGroupBy(static_cast<GroupBy>(index));
951  break;
952 
954  this->vehgroups.SetSortType(index);
955  break;
956 
957  case WID_GL_FILTER_BY_CARGO: // Select a cargo filter criteria
958  this->SetCargoFilter(index);
959  break;
960 
962  assert(!this->vehicles.empty());
963 
964  switch (index) {
965  case ADI_REPLACE: // Replace window
966  ShowReplaceGroupVehicleWindow(this->vli.index, this->vli.vtype);
967  break;
968  case ADI_SERVICE: // Send for servicing
969  case ADI_DEPOT: { // Send to Depots
970  Command<CMD_SEND_VEHICLE_TO_DEPOT>::Post(GetCmdSendToDepotMsg(this->vli.vtype), 0, DepotCommand::MassSend | (index == ADI_SERVICE ? DepotCommand::Service : DepotCommand::None), this->vli);
971  break;
972  }
973 
974  case ADI_CREATE_GROUP: // Create group
976  break;
977 
978  case ADI_ADD_SHARED: // Add shared Vehicles
979  assert(Group::IsValidID(this->vli.index));
980 
981  Command<CMD_ADD_SHARED_VEHICLE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_ADD_SHARED_VEHICLE, this->vli.index, this->vli.vtype);
982  break;
983  case ADI_REMOVE_ALL: // Remove all Vehicles from the selected group
984  assert(Group::IsValidID(this->vli.index));
985 
986  Command<CMD_REMOVE_ALL_VEHICLES_GROUP>::Post(STR_ERROR_GROUP_CAN_T_REMOVE_ALL_VEHICLES, this->vli.index);
987  break;
988  default: NOT_REACHED();
989  }
990  break;
991 
992  default: NOT_REACHED();
993  }
994 
995  this->SetDirty();
996  }
997 
998  void OnGameTick() override
999  {
1000  if (this->groups.NeedResort() || this->vehgroups.NeedResort()) {
1001  this->SetDirty();
1002  }
1003  }
1004 
1005  void OnPlaceObjectAbort() override
1006  {
1007  /* abort drag & drop */
1008  this->vehicle_sel = INVALID_VEHICLE;
1010  this->group_sel = INVALID_GROUP;
1011  this->group_over = INVALID_GROUP;
1013  }
1014 
1015  void OnMouseDrag(Point pt, WidgetID widget) override
1016  {
1017  if (this->vehicle_sel == INVALID_VEHICLE && this->group_sel == INVALID_GROUP) return;
1018 
1019  /* A vehicle is dragged over... */
1020  GroupID new_group_over = INVALID_GROUP;
1021  switch (widget) {
1022  case WID_GL_DEFAULT_VEHICLES: // ... the 'default' group.
1023  new_group_over = DEFAULT_GROUP;
1024  break;
1025 
1026  case WID_GL_LIST_GROUP: { // ... the list of custom groups.
1027  auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
1028  new_group_over = it == this->groups.end() ? NEW_GROUP : (*it)->index;
1029  break;
1030  }
1031  }
1032 
1033  /* Do not highlight when dragging over the current group */
1034  if (this->vehicle_sel != INVALID_VEHICLE) {
1035  if (Vehicle::Get(vehicle_sel)->group_id == new_group_over) new_group_over = INVALID_GROUP;
1036  } else if (this->group_sel != INVALID_GROUP) {
1037  if (this->group_sel == new_group_over || Group::Get(this->group_sel)->parent == new_group_over) new_group_over = INVALID_GROUP;
1038  }
1039 
1040  /* Mark widgets as dirty if the group changed. */
1041  if (new_group_over != this->group_over) {
1043  this->group_over = new_group_over;
1045  }
1046  }
1047 
1048  void ShowRenameGroupWindow(GroupID group, bool empty)
1049  {
1050  assert(Group::IsValidID(group));
1051  this->group_rename = group;
1052  /* Show empty query for new groups */
1053  StringID str = STR_EMPTY;
1054  if (!empty) {
1055  SetDParam(0, group);
1056  str = STR_GROUP_NAME;
1057  }
1059  }
1060 
1067  {
1068  if (this->vehicle_sel == vehicle) ResetObjectToPlace();
1069  }
1070 
1076  void SelectGroup(const GroupID g_id)
1077  {
1078  if (g_id == INVALID_GROUP || g_id == this->vli.index) return;
1079 
1080  this->vli.index = g_id;
1081  if (g_id != ALL_GROUP && g_id != DEFAULT_GROUP) {
1082  const Group *g = Group::Get(g_id);
1083  int id_g = find_index(this->groups, g);
1084  // The group's branch is maybe collapsed, so try to expand it
1085  if (id_g == -1) {
1086  for (auto pg = Group::GetIfValid(g->parent); pg != nullptr; pg = Group::GetIfValid(pg->parent)) {
1087  pg->folded = false;
1088  }
1089  this->groups.ForceRebuild();
1090  this->BuildGroupList(this->owner);
1091  this->group_sb->SetCount(this->groups.size());
1092  id_g = find_index(this->groups, g);
1093  }
1094  this->group_sb->ScrollTowards(id_g);
1095  }
1096  this->vehgroups.ForceRebuild();
1097  this->SetDirty();
1098  }
1099 
1100 };
1101 
1102 
1103 static WindowDesc _other_group_desc(__FILE__, __LINE__,
1104  WDP_AUTO, "list_groups", 460, 246,
1106  0,
1107  std::begin(_nested_group_widgets), std::end(_nested_group_widgets)
1108 );
1109 
1110 static WindowDesc _train_group_desc(__FILE__, __LINE__,
1111  WDP_AUTO, "list_groups_train", 525, 246,
1113  0,
1114  std::begin(_nested_group_widgets), std::end(_nested_group_widgets)
1115 );
1116 
1124 void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group = INVALID_GROUP, bool need_existing_window = false)
1125 {
1126  if (!Company::IsValidID(company)) return;
1127 
1128  const WindowNumber num = VehicleListIdentifier(VL_GROUP_LIST, vehicle_type, company).Pack();
1129  VehicleGroupWindow *w;
1130  if (vehicle_type == VEH_TRAIN) {
1131  w = AllocateWindowDescFront<VehicleGroupWindow>(&_train_group_desc, num, need_existing_window);
1132  } else {
1133  _other_group_desc.cls = GetWindowClassForVehicleType(vehicle_type);
1134  w = AllocateWindowDescFront<VehicleGroupWindow>(&_other_group_desc, num, need_existing_window);
1135  }
1136  if (w != nullptr) w->SelectGroup(group);
1137 }
1138 
1144 {
1145  ShowCompanyGroup(v->owner, v->type, v->group_id, true);
1146 }
1147 
1155 {
1156  return (VehicleGroupWindow *)FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).Pack());
1157 }
1158 
1163 static void CcCreateGroup(GroupID gid, VehicleType veh_type)
1164 {
1166  if (w != nullptr) w->ShowRenameGroupWindow(gid, true);
1167 }
1168 
1176 void CcCreateGroup(Commands, const CommandCost &result, GroupID new_group, VehicleType vt, GroupID)
1177 {
1178  if (result.Failed()) return;
1179 
1180  assert(vt <= VEH_AIRCRAFT);
1181  CcCreateGroup(new_group, vt);
1182 }
1183 
1190 {
1191  if (result.Failed()) return;
1192 
1193  const Group *g = Group::Get(new_group);
1194  CcCreateGroup(new_group, g->vehicle_type);
1195 }
1196 
1202 {
1203  /* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any group windows either
1204  * If that is the case, we can skip looping though the windows and save time
1205  */
1206  if (_special_mouse_mode != WSM_DRAGDROP) return;
1207 
1209  if (w != nullptr) w->UnselectVehicle(v->index);
1210 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
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:1141
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:1076
VehicleGroupWindow::ListColumns
ListColumns
Definition: group_gui.cpp:117
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition: window.cpp:1153
WC_INVALID
@ WC_INVALID
Invalid window.
Definition: window_type.h:719
BaseVehicleListWindow::SetCargoFilter
void SetCargoFilter(byte index)
Set cargo filter for the vehicle group list.
Definition: vehicle_gui.cpp:344
VehicleGroupWindow::VGC_NAME
@ VGC_NAME
Group name.
Definition: group_gui.cpp:119
Pool::PoolItem<&_group_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
vehicle_gui.h
WID_GL_SORT_BY_DROPDOWN
@ WID_GL_SORT_BY_DROPDOWN
Sort by dropdown list.
Definition: group_widget.h:19
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:1227
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:453
Pool::PoolItem<&_group_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:346
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:131
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:133
VehicleGroupWindow::VGC_AUTOREPLACE
@ VGC_AUTOREPLACE
Autoreplace active icon.
Definition: group_gui.cpp:121
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:821
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:144
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:552
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:129
GUIList< const Group * >
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::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
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
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:335
Vehicle::group_id
GroupID group_id
Index of group Pool array.
Definition: vehicle_base.h:357
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:1099
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
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:1124
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
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:1174
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:294
GroupStatistics::autoreplace_finished
bool autoreplace_finished
Have all autoreplacement finished?
Definition: group.h:31
GetStringListWidth
uint GetStringListWidth(const StringID *list, FontSize fontsize)
Get maximum width of a list of strings.
Definition: gfx.cpp:875
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
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
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:2334
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:585
VehicleGroupWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: group_gui.cpp:502
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:1066
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:164
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:849
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:310
VehicleGroupWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: group_gui.cpp:998
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:340
VehicleGroupWindow::VGC_FOLD
@ VGC_FOLD
Fold / Unfold button.
Definition: group_gui.cpp:118
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:304
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
VehicleGroupWindow::column_size
Dimension column_size[VGC_END]
Size of the columns in the group list.
Definition: group_gui.cpp:138
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:1038
VehicleGroupWindow::indents
std::vector< int > indents
Indentation levels.
Definition: group_gui.cpp:136
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:387
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: palette.cpp:26
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
find_index
int find_index(Container const &container, typename Container::const_reference item)
Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_...
Definition: container_func.hpp:41
DepotCommand::Service
@ Service
The vehicle will leave the depot right after arrival (service only)
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:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
Group
Group data.
Definition: group.h:72
AlterGroupMode::Rename
@ Rename
Change group name.
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:1086
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:220
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
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:308
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:732
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:832
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
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:1244
ShowCompanyGroupForVehicle
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
Definition: group_gui.cpp:1143
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:306
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:3408
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:941
DepotCommand::MassSend
@ MassSend
Tells that it's a mass send to depot command (type in VLW flag)
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:234
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:204
VehicleListIdentifier::index
uint32_t index
A vehicle list type specific index.
Definition: vehiclelist.h:32
VehicleGroupWindow::ComputeGroupInfoSize
uint ComputeGroupInfoSize()
Compute tiny_step_height and column_size.
Definition: group_gui.cpp:209
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:110
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:254
GetVehicleListHeight
uint GetVehicleListHeight(VehicleType type, uint divisor)
Get the height of a vehicle in the vehicle list GUIs.
Definition: vehicle_gui.cpp:1670
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:123
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:350
VehicleListIdentifier::Pack
uint32_t Pack() const
Pack a VehicleListIdentifier in a single uint32.
Definition: vehiclelist.cpp:22
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:322
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:244
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
BaseVehicleListWindow::BuildCargoDropDownList
DropDownList BuildCargoDropDownList(bool full) const
Build drop down list for cargo filter selection.
Definition: vehicle_gui.cpp:425
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:1083
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:303
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:3516
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:1007
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:1034
BaseVehicleListWindow::GetActionDropdownSize
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group, bool show_create)
Compute the size for the Action dropdown.
Definition: vehicle_gui.cpp:386
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator 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:845
ShowDropDownMenu
void ShowDropDownMenu(Window *w, 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:386
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
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:113
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
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:120
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:941
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
BaseVehicleListWindow::DrawVehicleListItems
void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const
Draw all the vehicle list items.
Definition: vehicle_gui.cpp:1690
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:395
string_func.h
IsAllGroupID
bool IsAllGroupID(GroupID id_g)
Checks if a GroupID stands for all vehicles of a company.
Definition: group.h:99
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:111
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:214
EIT_IN_LIST
@ EIT_IN_LIST
Vehicle drawn in vehicle list, group list, ...
Definition: vehicle_type.h:89
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:50
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:1201
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1602
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:384
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
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:122
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:349
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:236
VehicleGroupWindow::groups
GUIGroupList groups
List of groups.
Definition: group_gui.cpp:132
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition: sortlist_type.h:137
VehicleGroupWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: group_gui.cpp:940
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:916
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1036
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:1189
VehicleGroupWindow::group_over
GroupID group_over
Group over which a vehicle is dragged, INVALID_GROUP if none.
Definition: group_gui.cpp:130
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:327
WID_GL_RENAME_GROUP
@ WID_GL_RENAME_GROUP
Rename group button.
Definition: group_widget.h:34
VehicleGroupWindow::DrawGroupInfo
void DrawGroupInfo(int y, int left, int right, GroupID g_id, int indent=0, bool protection=false, bool has_children=false) const
Draw a row in the group list.
Definition: group_gui.cpp:261
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
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:1163
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:1154
Window::RaiseWidget
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition: window_gui.h:469
VehicleGroupWindow::BuildGroupList
void BuildGroupList(Owner owner)
(Re)Build the group list.
Definition: group_gui.cpp:161
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:3398
window_func.h
AlterGroupMode::SetParent
@ SetParent
Change group parent.
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:78
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
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:405
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 >
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:815
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:658
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:3420
Group::folded
bool folded
NOSAVE: Is this group folded in the group view?
Definition: group.h:81
WID_GL_LIST_VEHICLE
@ WID_GL_LIST_VEHICLE
List of the vehicles.
Definition: group_widget.h:21
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:1382
VehicleGroupWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: group_gui.cpp:1005
Window
Data structure for an opened window.
Definition: window_gui.h:267
Commands
Commands
List of commands.
Definition: command_type.h:187
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
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:324
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:310
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:215
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:1109
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition: window_type.h:156
DepotCommand::None
@ None
No special flags.
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:268
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition: window_gui.h:515
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:233
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:447
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:128
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3483
VehicleGroupWindow
Definition: group_gui.cpp:114
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:852
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:509
VEHICLE_PROFIT_THRESHOLD
static const Money VEHICLE_PROFIT_THRESHOLD
Threshold for a vehicle to be considered making good profit.
Definition: vehicle_func.h:28
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
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