OpenTTD Source  1.11.0-beta2
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 "company_base.h"
26 #include "company_gui.h"
27 
28 #include "widgets/group_widget.h"
29 
30 #include "table/sprites.h"
31 
32 #include "safeguards.h"
33 
34 static const int LEVEL_WIDTH = 10;
35 
37 
38 static const NWidgetPart _nested_group_widgets[] = {
39  NWidget(NWID_HORIZONTAL), // Window header
40  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
41  NWidget(WWT_CAPTION, COLOUR_GREY, WID_GL_CAPTION),
42  NWidget(WWT_SHADEBOX, COLOUR_GREY),
43  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
44  NWidget(WWT_STICKYBOX, COLOUR_GREY),
45  EndContainer(),
47  /* left part */
50  NWidget(WWT_PANEL, COLOUR_GREY, WID_GL_ALL_VEHICLES), SetFill(1, 0), EndContainer(),
53  NWidget(WWT_MATRIX, COLOUR_GREY, WID_GL_LIST_GROUP), SetMatrixDataTip(1, 0, STR_GROUPS_CLICK_ON_GROUP_FOR_TOOLTIP),
56  EndContainer(),
57  NWidget(WWT_PANEL, COLOUR_GREY, WID_GL_INFO), SetFill(1, 0), EndContainer(),
59  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_CREATE_GROUP), SetFill(0, 1),
60  SetDataTip(SPR_GROUP_CREATE_TRAIN, STR_GROUP_CREATE_TOOLTIP),
61  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_DELETE_GROUP), SetFill(0, 1),
62  SetDataTip(SPR_GROUP_DELETE_TRAIN, STR_GROUP_DELETE_TOOLTIP),
63  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_RENAME_GROUP), SetFill(0, 1),
64  SetDataTip(SPR_GROUP_RENAME_TRAIN, STR_GROUP_RENAME_TOOLTIP),
65  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_LIVERY_GROUP), SetFill(0, 1),
66  SetDataTip(SPR_GROUP_LIVERY_TRAIN, STR_GROUP_LIVERY_TOOLTIP),
67  NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), EndContainer(),
69  SetDataTip(SPR_GROUP_REPLACE_OFF_TRAIN, STR_GROUP_REPLACE_PROTECTION_TOOLTIP),
70  EndContainer(),
71  EndContainer(),
72  /* right part */
75  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GL_GROUP_BY_ORDER), SetMinimalSize(81, 12), SetDataTip(STR_STATION_VIEW_GROUP, STR_TOOLTIP_GROUP_ORDER),
76  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GL_GROUP_BY_DROPDOWN), SetMinimalSize(167, 12), SetDataTip(0x0, STR_TOOLTIP_GROUP_ORDER),
77  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(12, 12), SetResize(1, 0), EndContainer(),
78  EndContainer(),
80  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GL_SORT_BY_ORDER), SetMinimalSize(81, 12), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
81  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GL_SORT_BY_DROPDOWN), SetMinimalSize(167, 12), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
82  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(12, 12), SetResize(1, 0), EndContainer(),
83  EndContainer(),
87  EndContainer(),
88  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(1, 0), SetFill(1, 1), SetResize(1, 0), EndContainer(),
91  SetDataTip(STR_BLACK_STRING, STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP),
92  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 1), SetResize(1, 0), EndContainer(),
94  SetDataTip(STR_VEHICLE_LIST_MANAGE_LIST, STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP),
95  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_STOP_ALL), SetMinimalSize(12, 12), SetFill(0, 1),
96  SetDataTip(SPR_FLAG_VEH_STOPPED, STR_VEHICLE_LIST_MASS_STOP_LIST_TOOLTIP),
97  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_START_ALL), SetMinimalSize(12, 12), SetFill(0, 1),
98  SetDataTip(SPR_FLAG_VEH_RUNNING, STR_VEHICLE_LIST_MASS_START_LIST_TOOLTIP),
99  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
100  EndContainer(),
101  EndContainer(),
102  EndContainer(),
103 };
104 
106 private:
107  /* Columns in the group list */
108  enum ListColumns {
115 
116  VGC_END
117  };
118 
126  Scrollbar *group_sb;
127 
128  std::vector<int> indents;
129 
131 
132  void AddChildren(GUIGroupList *source, GroupID parent, int indent)
133  {
134  for (const Group *g : *source) {
135  if (g->parent != parent) continue;
136  this->groups.push_back(g);
137  this->indents.push_back(indent);
138  if (g->folded) {
139  /* Test if this group has children at all. If not, the folded flag should be cleared to avoid lingering unfold buttons in the list. */
140  auto child = std::find_if(source->begin(), source->end(), [g](const Group *child){ return child->parent == g->index; });
141  bool has_children = child != source->end();
142  Group::Get(g->index)->folded = has_children;
143  } else {
144  AddChildren(source, g->index, indent + 1);
145  }
146  }
147  }
148 
155  {
156  if (!this->groups.NeedRebuild()) return;
157 
158  this->groups.clear();
159  this->indents.clear();
160 
161  GUIGroupList list;
162 
163  for (const Group *g : Group::Iterate()) {
164  if (g->owner == owner && g->vehicle_type == this->vli.vtype) {
165  list.push_back(g);
166  }
167  }
168 
169  list.ForceResort();
170 
171  /* Sort the groups by their name */
172  const Group *last_group[2] = { nullptr, nullptr };
173  char last_name[2][64] = { "", "" };
174  list.Sort([&](const Group * const &a, const Group * const &b) {
175  if (a != last_group[0]) {
176  last_group[0] = a;
177  SetDParam(0, a->index);
178  GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0]));
179  }
180 
181  if (b != last_group[1]) {
182  last_group[1] = b;
183  SetDParam(0, b->index);
184  GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
185  }
186 
187  int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
188  if (r == 0) return a->index < b->index;
189  return r < 0;
190  });
191 
192  AddChildren(&list, INVALID_GROUP, 0);
193 
194  this->groups.shrink_to_fit();
195  this->groups.RebuildDone();
196  }
197 
203  {
204  this->column_size[VGC_FOLD] = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED));
205  this->tiny_step_height = this->column_size[VGC_FOLD].height;
206 
207  this->column_size[VGC_NAME] = maxdim(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + this->vli.vtype), GetStringBoundingBox(STR_GROUP_ALL_TRAINS + this->vli.vtype));
208  this->column_size[VGC_NAME].width = std::max(170u, this->column_size[VGC_NAME].width);
209  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_NAME].height);
210 
211  this->column_size[VGC_PROTECT] = GetSpriteSize(SPR_GROUP_REPLACE_PROTECT);
212  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_PROTECT].height);
213 
214  this->column_size[VGC_AUTOREPLACE] = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
215  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_AUTOREPLACE].height);
216 
217  this->column_size[VGC_PROFIT].width = 0;
218  this->column_size[VGC_PROFIT].height = 0;
219  static const SpriteID profit_sprites[] = {SPR_PROFIT_NA, SPR_PROFIT_NEGATIVE, SPR_PROFIT_SOME, SPR_PROFIT_LOT};
220  for (uint i = 0; i < lengthof(profit_sprites); i++) {
221  Dimension d = GetSpriteSize(profit_sprites[i]);
222  this->column_size[VGC_PROFIT] = maxdim(this->column_size[VGC_PROFIT], d);
223  }
224  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_PROFIT].height);
225 
226  int num_vehicle = GetGroupNumVehicle(this->vli.company, ALL_GROUP, this->vli.vtype);
227  SetDParamMaxValue(0, num_vehicle, 3, FS_SMALL);
228  SetDParamMaxValue(1, num_vehicle, 3, FS_SMALL);
229  this->column_size[VGC_NUMBER] = GetStringBoundingBox(STR_GROUP_COUNT_WITH_SUBGROUP);
230  this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_NUMBER].height);
231 
232  this->tiny_step_height += WD_MATRIX_TOP;
233 
234  return WD_FRAMERECT_LEFT + 8 +
235  this->column_size[VGC_FOLD].width + 2 +
236  this->column_size[VGC_NAME].width + 8 +
237  this->column_size[VGC_PROTECT].width + 2 +
238  this->column_size[VGC_AUTOREPLACE].width + 2 +
239  this->column_size[VGC_PROFIT].width + 2 +
240  this->column_size[VGC_NUMBER].width + 2 +
242  }
243 
254  void DrawGroupInfo(int y, int left, int right, GroupID g_id, int indent = 0, bool protection = false, bool has_children = false) const
255  {
256  /* Highlight the group if a vehicle is dragged over it */
257  if (g_id == this->group_over) {
258  GfxFillRect(left + WD_FRAMERECT_LEFT, y + WD_FRAMERECT_TOP, right - WD_FRAMERECT_RIGHT, y + this->tiny_step_height - WD_FRAMERECT_BOTTOM - WD_MATRIX_TOP, _colour_gradient[COLOUR_GREY][7]);
259  }
260 
261  if (g_id == NEW_GROUP) return;
262 
263  /* draw the selected group in white, else we draw it in black */
264  TextColour colour = g_id == this->vli.index ? TC_WHITE : TC_BLACK;
265  const GroupStatistics &stats = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype);
266  bool rtl = _current_text_dir == TD_RTL;
267 
268  /* draw fold / unfold button */
269  int x = rtl ? right - WD_FRAMERECT_RIGHT - 8 - this->column_size[VGC_FOLD].width + 1 : left + WD_FRAMERECT_LEFT + 8;
270  if (has_children) {
271  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);
272  }
273 
274  /* draw group name */
275  StringID str;
276  if (IsAllGroupID(g_id)) {
277  str = STR_GROUP_ALL_TRAINS + this->vli.vtype;
278  } else if (IsDefaultGroupID(g_id)) {
279  str = STR_GROUP_DEFAULT_TRAINS + this->vli.vtype;
280  } else {
281  SetDParam(0, g_id);
282  str = STR_GROUP_NAME;
283  }
284  x = rtl ? x - 2 - this->column_size[VGC_NAME].width : x + 2 + this->column_size[VGC_FOLD].width;
285  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);
286 
287  /* draw autoreplace protection */
288  x = rtl ? x - 8 - this->column_size[VGC_PROTECT].width : x + 8 + this->column_size[VGC_NAME].width;
289  if (protection) DrawSprite(SPR_GROUP_REPLACE_PROTECT, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_PROTECT].height) / 2);
290 
291  /* draw autoreplace status */
292  x = rtl ? x - 2 - this->column_size[VGC_AUTOREPLACE].width : x + 2 + this->column_size[VGC_PROTECT].width;
293  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);
294 
295  /* draw the profit icon */
296  x = rtl ? x - 2 - this->column_size[VGC_PROFIT].width : x + 2 + this->column_size[VGC_AUTOREPLACE].width;
297  SpriteID spr;
298  uint num_profit_vehicle = GetGroupNumProfitVehicle(this->vli.company, g_id, this->vli.vtype);
299  Money profit_last_year = GetGroupProfitLastYear(this->vli.company, g_id, this->vli.vtype);
300  if (num_profit_vehicle == 0) {
301  spr = SPR_PROFIT_NA;
302  } else if (profit_last_year < 0) {
303  spr = SPR_PROFIT_NEGATIVE;
304  } else if (profit_last_year < VEHICLE_PROFIT_THRESHOLD * num_profit_vehicle) {
305  spr = SPR_PROFIT_SOME;
306  } else {
307  spr = SPR_PROFIT_LOT;
308  }
309  DrawSprite(spr, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_PROFIT].height) / 2);
310 
311  /* draw the number of vehicles of the group */
312  x = rtl ? x - 2 - this->column_size[VGC_NUMBER].width : x + 2 + this->column_size[VGC_PROFIT].width;
313  int num_vehicle_with_subgroups = GetGroupNumVehicle(this->vli.company, g_id, this->vli.vtype);
314  int num_vehicle = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype).num_vehicle;
315  if (IsAllGroupID(g_id) || IsDefaultGroupID(g_id) || num_vehicle_with_subgroups == num_vehicle) {
316  SetDParam(0, num_vehicle);
317  DrawString(x, x + this->column_size[VGC_NUMBER].width - 1, y + (this->tiny_step_height - this->column_size[VGC_NUMBER].height) / 2, STR_TINY_COMMA, colour, SA_RIGHT | SA_FORCE);
318  } else {
319  SetDParam(0, num_vehicle);
320  SetDParam(1, num_vehicle_with_subgroups - num_vehicle);
321  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);
322  }
323  }
324 
329  {
330  if (this->group_over == INVALID_GROUP) return;
331 
332  if (IsAllGroupID(this->group_over)) {
334  } else if (IsDefaultGroupID(this->group_over)) {
336  } else {
338  }
339  }
340 
341 public:
343  {
344  this->CreateNestedTree();
345 
346  this->vscroll = this->GetScrollbar(WID_GL_LIST_VEHICLE_SCROLLBAR);
347  this->group_sb = this->GetScrollbar(WID_GL_LIST_GROUP_SCROLLBAR);
348 
349  this->vli.index = ALL_GROUP;
350  this->vehicle_sel = INVALID_VEHICLE;
351  this->group_sel = INVALID_GROUP;
352  this->group_rename = INVALID_GROUP;
353  this->group_over = INVALID_GROUP;
354 
355  this->BuildVehicleList();
356  this->SortVehicleList();
357 
358  this->groups.ForceRebuild();
359  this->groups.NeedResort();
360  this->BuildGroupList(vli.company);
361  this->group_sb->SetCount((uint)this->groups.size());
362 
363  this->GetWidget<NWidgetCore>(WID_GL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype;
364  this->GetWidget<NWidgetCore>(WID_GL_LIST_VEHICLE)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype;
365 
366  this->GetWidget<NWidgetCore>(WID_GL_CREATE_GROUP)->widget_data += this->vli.vtype;
367  this->GetWidget<NWidgetCore>(WID_GL_RENAME_GROUP)->widget_data += this->vli.vtype;
368  this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->widget_data += this->vli.vtype;
369  this->GetWidget<NWidgetCore>(WID_GL_LIVERY_GROUP)->widget_data += this->vli.vtype;
370  this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data += this->vli.vtype;
371 
372  this->FinishInitNested(window_number);
373  this->owner = vli.company;
374  }
375 
377  {
378  *this->sorting = this->vehgroups.GetListing();
379  }
380 
381  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
382  {
383  switch (widget) {
384  case WID_GL_LIST_GROUP: {
385  size->width = this->ComputeGroupInfoSize();
386  resize->height = this->tiny_step_height;
387 
388  /* Minimum height is the height of the list widget minus all and default vehicles... */
389  size->height = 4 * GetVehicleListHeight(this->vli.vtype, this->tiny_step_height) - 2 * this->tiny_step_height;
390 
391  /* ... minus the buttons at the bottom ... */
392  uint max_icon_height = GetSpriteSize(this->GetWidget<NWidgetCore>(WID_GL_CREATE_GROUP)->widget_data).height;
393  max_icon_height = std::max(max_icon_height, GetSpriteSize(this->GetWidget<NWidgetCore>(WID_GL_RENAME_GROUP)->widget_data).height);
394  max_icon_height = std::max(max_icon_height, GetSpriteSize(this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->widget_data).height);
395  max_icon_height = std::max(max_icon_height, GetSpriteSize(this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data).height);
396 
397  /* ... minus the height of the group info ... */
398  max_icon_height += (FONT_HEIGHT_NORMAL * 3) + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
399 
400  /* Get a multiple of tiny_step_height of that amount */
401  size->height = Ceil(size->height - max_icon_height, tiny_step_height);
402  break;
403  }
404 
405  case WID_GL_ALL_VEHICLES:
407  size->width = this->ComputeGroupInfoSize();
408  size->height = this->tiny_step_height;
409  break;
410 
411  case WID_GL_SORT_BY_ORDER: {
412  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
413  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
414  d.height += padding.height;
415  *size = maxdim(*size, d);
416  break;
417  }
418 
419  case WID_GL_LIST_VEHICLE:
420  this->ComputeGroupInfoSize();
421  resize->height = GetVehicleListHeight(this->vli.vtype, this->tiny_step_height);
422  size->height = 4 * resize->height;
423  break;
424 
426  Dimension d = this->GetActionDropdownSize(true, true);
427  d.height += padding.height;
428  d.width += padding.width;
429  *size = maxdim(*size, d);
430  break;
431  }
432 
433  case WID_GL_INFO: {
435  break;
436  }
437  }
438  }
439 
445  void OnInvalidateData(int data = 0, bool gui_scope = true) override
446  {
447  if (data == 0) {
448  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
449  this->vehgroups.ForceRebuild();
450  this->groups.ForceRebuild();
451  } else {
452  this->vehgroups.ForceResort();
453  this->groups.ForceResort();
454  }
455 
456  /* Process ID-invalidation in command-scope as well */
457  if (this->group_rename != INVALID_GROUP && !Group::IsValidID(this->group_rename)) {
459  this->group_rename = INVALID_GROUP;
460  }
461 
462  if (!(IsAllGroupID(this->vli.index) || IsDefaultGroupID(this->vli.index) || Group::IsValidID(this->vli.index))) {
463  this->vli.index = ALL_GROUP;
464  HideDropDownMenu(this);
465  }
466  this->SetDirty();
467  }
468 
469  void SetStringParameters(int widget) const override
470  {
471  switch (widget) {
473  SetDParam(0, STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vli.vtype);
474  break;
475 
476  case WID_GL_CAPTION:
477  /* If selected_group == DEFAULT_GROUP || ALL_GROUP, draw the standard caption
478  * We list all vehicles or ungrouped vehicles */
479  if (IsDefaultGroupID(this->vli.index) || IsAllGroupID(this->vli.index)) {
480  SetDParam(0, STR_COMPANY_NAME);
481  SetDParam(1, this->vli.company);
482  SetDParam(2, this->vehicles.size());
483  SetDParam(3, this->vehicles.size());
484  } else {
485  uint num_vehicle = GetGroupNumVehicle(this->vli.company, this->vli.index, this->vli.vtype);
486 
487  SetDParam(0, STR_GROUP_NAME);
488  SetDParam(1, this->vli.index);
489  SetDParam(2, num_vehicle);
490  SetDParam(3, num_vehicle);
491  }
492  break;
493  }
494  }
495 
496  void OnPaint() override
497  {
498  /* If we select the all vehicles, this->list will contain all vehicles of the owner
499  * else this->list will contain all vehicles which belong to the selected group */
500  this->BuildVehicleList();
501  this->SortVehicleList();
502 
503  this->BuildGroupList(this->owner);
504 
505  this->group_sb->SetCount(static_cast<int>(this->groups.size()));
506  this->vscroll->SetCount(static_cast<int>(this->vehgroups.size()));
507 
508  /* The drop down menu is out, *but* it may not be used, retract it. */
509  if (this->vehicles.size() == 0 && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) {
511  HideDropDownMenu(this);
512  }
513 
514  /* Disable all lists management button when the list is empty */
515  this->SetWidgetsDisabledState(this->vehicles.size() == 0 || _local_company != this->vli.company,
520 
521  /* Disable the group specific function when we select the default group or all vehicles */
522  this->SetWidgetsDisabledState(IsDefaultGroupID(this->vli.index) || IsAllGroupID(this->vli.index) || _local_company != this->vli.company,
528 
529  /* Disable remaining buttons for non-local companies
530  * Needed while changing _local_company, eg. by cheats
531  * All procedures (eg. move vehicle to another group)
532  * verify, whether you are the owner of the vehicle,
533  * so it doesn't have to be disabled
534  */
539 
540  /* If not a default group and the group has replace protection, show an enabled replace sprite. */
541  uint16 protect_sprite = SPR_GROUP_REPLACE_OFF_TRAIN;
542  if (!IsDefaultGroupID(this->vli.index) && !IsAllGroupID(this->vli.index) && Group::Get(this->vli.index)->replace_protection) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN;
543  this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data = protect_sprite + this->vli.vtype;
544 
545  /* Set text of "group by" dropdown widget. */
546  this->GetWidget<NWidgetCore>(WID_GL_GROUP_BY_DROPDOWN)->widget_data = this->vehicle_group_by_names[this->grouping];
547 
548  /* Set text of "sort by" dropdown widget. */
549  this->GetWidget<NWidgetCore>(WID_GL_SORT_BY_DROPDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()];
550 
551  this->DrawWidgets();
552  }
553 
554  void DrawWidget(const Rect &r, int widget) const override
555  {
556  switch (widget) {
557  case WID_GL_ALL_VEHICLES:
558  DrawGroupInfo(r.top + WD_FRAMERECT_TOP, r.left, r.right, ALL_GROUP);
559  break;
560 
562  DrawGroupInfo(r.top + WD_FRAMERECT_TOP, r.left, r.right, DEFAULT_GROUP);
563  break;
564 
565  case WID_GL_INFO: {
566  Money this_year = 0;
567  Money last_year = 0;
568  uint64 occupancy = 0;
569 
570  for (const Vehicle * const v : this->vehicles) {
571  assert(v->owner == this->owner);
572 
573  this_year += v->GetDisplayProfitThisYear();
574  last_year += v->GetDisplayProfitLastYear();
575  occupancy += v->trip_occupancy;
576  }
577 
578  const int left = r.left + WD_FRAMERECT_LEFT + 8;
579  const int right = r.right - WD_FRAMERECT_RIGHT - 8;
580 
581  int y = r.top + WD_FRAMERECT_TOP;
582  DrawString(left, right, y, STR_GROUP_PROFIT_THIS_YEAR, TC_BLACK);
583  SetDParam(0, this_year);
584  DrawString(left, right, y, STR_JUST_CURRENCY_LONG, TC_BLACK, SA_RIGHT);
585 
586  y += FONT_HEIGHT_NORMAL;
587  DrawString(left, right, y, STR_GROUP_PROFIT_LAST_YEAR, TC_BLACK);
588  SetDParam(0, last_year);
589  DrawString(left, right, y, STR_JUST_CURRENCY_LONG, TC_BLACK, SA_RIGHT);
590 
591  y += FONT_HEIGHT_NORMAL;
592  DrawString(left, right, y, STR_GROUP_OCCUPANCY, TC_BLACK);
593  const size_t vehicle_count = this->vehicles.size();
594  if (vehicle_count > 0) {
595  SetDParam(0, occupancy / vehicle_count);
596  DrawString(left, right, y, STR_GROUP_OCCUPANCY_VALUE, TC_BLACK, SA_RIGHT);
597  }
598 
599  break;
600  }
601 
602  case WID_GL_LIST_GROUP: {
603  int y1 = r.top + WD_FRAMERECT_TOP;
604  int max = std::min<size_t>(this->group_sb->GetPosition() + this->group_sb->GetCapacity(), this->groups.size());
605  for (int i = this->group_sb->GetPosition(); i < max; ++i) {
606  const Group *g = this->groups[i];
607 
608  assert(g->owner == this->owner);
609 
610  DrawGroupInfo(y1, r.left, r.right, g->index, this->indents[i] * LEVEL_WIDTH, g->replace_protection, g->folded || (i + 1 < (int)this->groups.size() && indents[i + 1] > this->indents[i]));
611 
612  y1 += this->tiny_step_height;
613  }
614  if ((uint)this->group_sb->GetPosition() + this->group_sb->GetCapacity() > this->groups.size()) {
615  DrawGroupInfo(y1, r.left, r.right, NEW_GROUP);
616  }
617  break;
618  }
619 
622  break;
623 
624  case WID_GL_LIST_VEHICLE:
625  if (this->vli.index != ALL_GROUP && this->grouping == GB_NONE) {
626  /* Mark vehicles which are in sub-groups (only if we are not using shared order coalescing) */
627  int y = r.top;
628  uint max = static_cast<uint>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehgroups.size()));
629  for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
630  const Vehicle *v = this->vehgroups[i].GetSingleVehicle();
631  if (v->group_id != this->vli.index) {
632  GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->resize.step_height - 2, _colour_gradient[COLOUR_GREY][3], FILLRECT_CHECKER);
633  }
634  y += this->resize.step_height;
635  }
636  }
637 
638  this->DrawVehicleListItems(this->vehicle_sel, this->resize.step_height, r);
639  break;
640  }
641  }
642 
643  static void DeleteGroupCallback(Window *win, bool confirmed)
644  {
645  if (confirmed) {
647  w->vli.index = ALL_GROUP;
648  DoCommandP(0, w->group_confirm, 0, CMD_DELETE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_DELETE));
649  }
650  }
651 
652  void OnClick(Point pt, int widget, int click_count) override
653  {
654  switch (widget) {
655  case WID_GL_SORT_BY_ORDER: // Flip sorting method ascending/descending
656  this->vehgroups.ToggleSortOrder();
657  this->SetDirty();
658  break;
659 
660  case WID_GL_GROUP_BY_DROPDOWN: // Select grouping option dropdown menu
661  ShowDropDownMenu(this, this->vehicle_group_by_names, this->grouping, WID_GL_GROUP_BY_DROPDOWN, 0, 0);
662  return;
663 
664  case WID_GL_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
665  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));
666  return;
667 
668  case WID_GL_ALL_VEHICLES: // All vehicles button
669  if (!IsAllGroupID(this->vli.index)) {
670  this->vli.index = ALL_GROUP;
671  this->vehgroups.ForceRebuild();
672  this->SetDirty();
673  }
674  break;
675 
676  case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles button
677  if (!IsDefaultGroupID(this->vli.index)) {
678  this->vli.index = DEFAULT_GROUP;
679  this->vehgroups.ForceRebuild();
680  this->SetDirty();
681  }
682  break;
683 
684  case WID_GL_LIST_GROUP: { // Matrix Group
685  uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
686  if (id_g >= this->groups.size()) return;
687 
688  if (groups[id_g]->folded || (id_g + 1 < this->groups.size() && this->indents[id_g + 1] > this->indents[id_g])) {
689  /* The group has children, check if the user clicked the fold / unfold button. */
690  NWidgetCore *group_display = this->GetWidget<NWidgetCore>(widget);
691  int x = _current_text_dir == TD_RTL ?
692  group_display->pos_x + group_display->current_x - WD_FRAMERECT_RIGHT - 8 - this->indents[id_g] * LEVEL_WIDTH - this->column_size[VGC_FOLD].width :
693  group_display->pos_x + WD_FRAMERECT_LEFT + 8 + this->indents[id_g] * LEVEL_WIDTH;
694  if (click_count > 1 || (pt.x >= x && pt.x < (int)(x + this->column_size[VGC_FOLD].width))) {
695 
696  GroupID g = this->vli.index;
697  if (!IsAllGroupID(g) && !IsDefaultGroupID(g)) {
698  do {
699  g = Group::Get(g)->parent;
700  if (g == groups[id_g]->index) {
701  this->vli.index = g;
702  break;
703  }
704  } while (g != INVALID_GROUP);
705  }
706 
707  Group::Get(groups[id_g]->index)->folded = !groups[id_g]->folded;
708  this->groups.ForceRebuild();
709 
710  this->SetDirty();
711  break;
712  }
713  }
714 
715  this->group_sel = this->vli.index = this->groups[id_g]->index;
716 
717  SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
718 
719  this->vehgroups.ForceRebuild();
720  this->SetDirty();
721  break;
722  }
723 
724  case WID_GL_LIST_VEHICLE: { // Matrix Vehicle
725  uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_VEHICLE);
726  if (id_v >= this->vehgroups.size()) return; // click out of list bound
727 
728  const GUIVehicleGroup &vehgroup = this->vehgroups[id_v];
729 
730  const Vehicle *v = nullptr;
731 
732  switch (this->grouping) {
733  case GB_NONE: {
734  const Vehicle *v2 = vehgroup.GetSingleVehicle();
735  if (VehicleClicked(v2)) break;
736  v = v2;
737  break;
738  }
739 
740  case GB_SHARED_ORDERS: {
741  assert(vehgroup.NumVehicles() > 0);
742  v = vehgroup.vehicles_begin[0];
743  /*
744  * No VehicleClicked(v) support for now, because don't want
745  * to enable any contextual actions except perhaps clicking/ctrl-clicking to clone orders.
746  */
747  break;
748  }
749 
750  default:
751  NOT_REACHED();
752  }
753  if (v) {
754  this->vehicle_sel = v->index;
755 
756  if (_ctrl_pressed) {
757  this->SelectGroup(v->group_id);
758  }
759 
760  SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
762  _cursor.vehchain = true;
763 
764  this->SetDirty();
765  }
766 
767  break;
768  }
769 
770  case WID_GL_CREATE_GROUP: { // Create a new group
771  DoCommandP(0, this->vli.vtype, this->vli.index, CMD_CREATE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE), CcCreateGroup);
772  break;
773  }
774 
775  case WID_GL_DELETE_GROUP: { // Delete the selected group
776  this->group_confirm = this->vli.index;
777  ShowQuery(STR_QUERY_GROUP_DELETE_CAPTION, STR_GROUP_DELETE_QUERY_TEXT, this, DeleteGroupCallback);
778  break;
779  }
780 
781  case WID_GL_RENAME_GROUP: // Rename the selected roup
782  this->ShowRenameGroupWindow(this->vli.index, false);
783  break;
784 
785  case WID_GL_LIVERY_GROUP: // Set group livery
786  ShowCompanyLiveryWindow(this->owner, this->vli.index);
787  break;
788 
790  ShowBuildVehicleWindow(INVALID_TILE, this->vli.vtype);
791  break;
792 
795  break;
796  }
797 
798  case WID_GL_START_ALL:
799  case WID_GL_STOP_ALL: { // Start/stop all vehicles of the list
800  DoCommandP(0, (1 << 1) | (widget == WID_GL_START_ALL ? (1 << 0) : 0), this->vli.Pack(), CMD_MASS_START_STOP);
801  break;
802  }
803 
805  const Group *g = Group::GetIfValid(this->vli.index);
806  if (g != nullptr) {
808  }
809  break;
810  }
811  }
812  }
813 
814  void OnDragDrop_Group(Point pt, int widget)
815  {
816  const Group *g = Group::Get(this->group_sel);
817 
818  switch (widget) {
819  case WID_GL_ALL_VEHICLES: // All vehicles
820  case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
821  if (g->parent != INVALID_GROUP) {
822  DoCommandP(0, this->group_sel | (1 << 16), INVALID_GROUP, CMD_ALTER_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_SET_PARENT));
823  }
824 
825  this->group_sel = INVALID_GROUP;
826  this->group_over = INVALID_GROUP;
827  this->SetDirty();
828  break;
829 
830  case WID_GL_LIST_GROUP: { // Matrix group
831  uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
832  GroupID new_g = id_g >= this->groups.size() ? INVALID_GROUP : this->groups[id_g]->index;
833 
834  if (this->group_sel != new_g && g->parent != new_g) {
835  DoCommandP(0, this->group_sel | (1 << 16), new_g, CMD_ALTER_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_SET_PARENT));
836  }
837 
838  this->group_sel = INVALID_GROUP;
839  this->group_over = INVALID_GROUP;
840  this->SetDirty();
841  break;
842  }
843  }
844  }
845 
846  void OnDragDrop_Vehicle(Point pt, int widget)
847  {
848  switch (widget) {
849  case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
850  DoCommandP(0, DEFAULT_GROUP, this->vehicle_sel | (_ctrl_pressed || this->grouping == GB_SHARED_ORDERS ? 1 << 31 : 0), CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE));
851 
852  this->vehicle_sel = INVALID_VEHICLE;
853  this->group_over = INVALID_GROUP;
854 
855  this->SetDirty();
856  break;
857 
858  case WID_GL_LIST_GROUP: { // Matrix group
859  const VehicleID vindex = this->vehicle_sel;
860  this->vehicle_sel = INVALID_VEHICLE;
861  this->group_over = INVALID_GROUP;
862  this->SetDirty();
863 
864  uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
865  GroupID new_g = id_g >= this->groups.size() ? NEW_GROUP : this->groups[id_g]->index;
866 
867  DoCommandP(0, new_g, vindex | (_ctrl_pressed || this->grouping == GB_SHARED_ORDERS ? 1 << 31 : 0), CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE), new_g == NEW_GROUP ? CcAddVehicleNewGroup : nullptr);
868  break;
869  }
870 
871  case WID_GL_LIST_VEHICLE: { // Matrix vehicle
872  const VehicleID vindex = this->vehicle_sel;
873  this->vehicle_sel = INVALID_VEHICLE;
874  this->group_over = INVALID_GROUP;
875  this->SetDirty();
876 
877  uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_VEHICLE);
878  if (id_v >= this->vehgroups.size()) return; // click out of list bound
879 
880  const GUIVehicleGroup &vehgroup = this->vehgroups[id_v];
881  switch (this->grouping) {
882  case GB_NONE: {
883  const Vehicle *v = vehgroup.GetSingleVehicle();
884  if (!VehicleClicked(v) && vindex == v->index) {
886  }
887  break;
888  }
889 
890  case GB_SHARED_ORDERS: {
891  const Vehicle *v = vehgroup.vehicles_begin[0];
892  /* We do not support VehicleClicked() here since the contextual action may only make sense for individual vehicles */
893 
894  if (vindex == v->index) {
895  ShowVehicleListWindow(v);
896  }
897  break;
898  }
899 
900  default:
901  NOT_REACHED();
902  }
903  break;
904  }
905  }
906  }
907 
908  void OnDragDrop(Point pt, int widget) override
909  {
910  if (this->vehicle_sel != INVALID_VEHICLE) OnDragDrop_Vehicle(pt, widget);
911  if (this->group_sel != INVALID_GROUP) OnDragDrop_Group(pt, widget);
912 
913  _cursor.vehchain = false;
914  }
915 
916  void OnQueryTextFinished(char *str) override
917  {
918  if (str != nullptr) DoCommandP(0, this->group_rename, 0, CMD_ALTER_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_RENAME), nullptr, str);
919  this->group_rename = INVALID_GROUP;
920  }
921 
922  void OnResize() override
923  {
924  this->group_sb->SetCapacityFromWidget(this, WID_GL_LIST_GROUP);
925  this->vscroll->SetCapacityFromWidget(this, WID_GL_LIST_VEHICLE);
926  }
927 
928  void OnDropdownSelect(int widget, int index) override
929  {
930  switch (widget) {
932  this->UpdateVehicleGroupBy(static_cast<GroupBy>(index));
933  break;
934 
936  this->vehgroups.SetSortType(index);
937  break;
938 
940  assert(this->vehicles.size() != 0);
941 
942  switch (index) {
943  case ADI_REPLACE: // Replace window
944  ShowReplaceGroupVehicleWindow(this->vli.index, this->vli.vtype);
945  break;
946  case ADI_SERVICE: // Send for servicing
947  case ADI_DEPOT: { // Send to Depots
948  DoCommandP(0, DEPOT_MASS_SEND | (index == ADI_SERVICE ? DEPOT_SERVICE : 0U), this->vli.Pack(), GetCmdSendToDepot(this->vli.vtype));
949  break;
950  }
951 
952  case ADI_ADD_SHARED: // Add shared Vehicles
953  assert(Group::IsValidID(this->vli.index));
954 
955  DoCommandP(0, this->vli.index, this->vli.vtype, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_SHARED_VEHICLE));
956  break;
957  case ADI_REMOVE_ALL: // Remove all Vehicles from the selected group
958  assert(Group::IsValidID(this->vli.index));
959 
960  DoCommandP(0, this->vli.index, 0, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_REMOVE_ALL_VEHICLES));
961  break;
962  default: NOT_REACHED();
963  }
964  break;
965 
966  default: NOT_REACHED();
967  }
968 
969  this->SetDirty();
970  }
971 
972  void OnGameTick() override
973  {
974  if (this->groups.NeedResort() || this->vehgroups.NeedResort()) {
975  this->SetDirty();
976  }
977  }
978 
979  void OnPlaceObjectAbort() override
980  {
981  /* abort drag & drop */
982  this->vehicle_sel = INVALID_VEHICLE;
984  this->group_sel = INVALID_GROUP;
985  this->group_over = INVALID_GROUP;
987  }
988 
989  void OnMouseDrag(Point pt, int widget) override
990  {
991  if (this->vehicle_sel == INVALID_VEHICLE && this->group_sel == INVALID_GROUP) return;
992 
993  /* A vehicle is dragged over... */
994  GroupID new_group_over = INVALID_GROUP;
995  switch (widget) {
996  case WID_GL_DEFAULT_VEHICLES: // ... the 'default' group.
997  new_group_over = DEFAULT_GROUP;
998  break;
999 
1000  case WID_GL_LIST_GROUP: { // ... the list of custom groups.
1001  uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
1002  new_group_over = id_g >= this->groups.size() ? NEW_GROUP : this->groups[id_g]->index;
1003  break;
1004  }
1005  }
1006 
1007  /* Do not highlight when dragging over the current group */
1008  if (this->vehicle_sel != INVALID_VEHICLE) {
1009  if (Vehicle::Get(vehicle_sel)->group_id == new_group_over) new_group_over = INVALID_GROUP;
1010  } else if (this->group_sel != INVALID_GROUP) {
1011  if (this->group_sel == new_group_over || Group::Get(this->group_sel)->parent == new_group_over) new_group_over = INVALID_GROUP;
1012  }
1013 
1014  /* Mark widgets as dirty if the group changed. */
1015  if (new_group_over != this->group_over) {
1017  this->group_over = new_group_over;
1019  }
1020  }
1021 
1022  void ShowRenameGroupWindow(GroupID group, bool empty)
1023  {
1024  assert(Group::IsValidID(group));
1025  this->group_rename = group;
1026  /* Show empty query for new groups */
1027  StringID str = STR_EMPTY;
1028  if (!empty) {
1029  SetDParam(0, group);
1030  str = STR_GROUP_NAME;
1031  }
1033  }
1034 
1041  {
1042  if (this->vehicle_sel == vehicle) ResetObjectToPlace();
1043  }
1044 
1050  void SelectGroup(const GroupID g_id)
1051  {
1052  if (g_id == INVALID_GROUP || g_id == this->vli.index) return;
1053 
1054  this->vli.index = g_id;
1055  if (g_id != ALL_GROUP && g_id != DEFAULT_GROUP) {
1056  const Group *g = Group::Get(g_id);
1057  int id_g = find_index(this->groups, g);
1058  // The group's branch is maybe collapsed, so try to expand it
1059  if (id_g == -1) {
1060  for (auto pg = Group::GetIfValid(g->parent); pg != nullptr; pg = Group::GetIfValid(pg->parent)) {
1061  pg->folded = false;
1062  }
1063  this->groups.ForceRebuild();
1064  this->BuildGroupList(this->owner);
1065  this->group_sb->SetCount((uint)this->groups.size());
1066  id_g = find_index(this->groups, g);
1067  }
1068  this->group_sb->ScrollTowards(id_g);
1069  }
1070  this->vehgroups.ForceRebuild();
1071  this->SetDirty();
1072  }
1073 
1074 };
1075 
1076 
1077 static WindowDesc _other_group_desc(
1078  WDP_AUTO, "list_groups", 460, 246,
1080  0,
1081  _nested_group_widgets, lengthof(_nested_group_widgets)
1082 );
1083 
1084 static WindowDesc _train_group_desc(
1085  WDP_AUTO, "list_groups_train", 525, 246,
1087  0,
1088  _nested_group_widgets, lengthof(_nested_group_widgets)
1089 );
1090 
1098 void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group = INVALID_GROUP, bool need_existing_window = false)
1099 {
1100  if (!Company::IsValidID(company)) return;
1101 
1102  const WindowNumber num = VehicleListIdentifier(VL_GROUP_LIST, vehicle_type, company).Pack();
1103  VehicleGroupWindow *w;
1104  if (vehicle_type == VEH_TRAIN) {
1105  w = AllocateWindowDescFront<VehicleGroupWindow>(&_train_group_desc, num, need_existing_window);
1106  } else {
1107  _other_group_desc.cls = GetWindowClassForVehicleType(vehicle_type);
1108  w = AllocateWindowDescFront<VehicleGroupWindow>(&_other_group_desc, num, need_existing_window);
1109  }
1110  if (w != nullptr) w->SelectGroup(group);
1111 }
1112 
1118 {
1119  ShowCompanyGroup(v->owner, v->type, v->group_id, true);
1120 }
1121 
1129 {
1130  return (VehicleGroupWindow *)FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).Pack());
1131 }
1132 
1142 void CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
1143 {
1144  if (result.Failed()) return;
1145  assert(p1 <= VEH_AIRCRAFT);
1146 
1148  if (w != nullptr) w->ShowRenameGroupWindow(_new_group_id, true);
1149 }
1150 
1159 void CcAddVehicleNewGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
1160 {
1161  if (result.Failed()) return;
1162  assert(Vehicle::IsValidID(GB(p2, 0, 20)));
1163 
1164  CcCreateGroup(result, 0, Vehicle::Get(GB(p2, 0, 20))->type, 0, cmd);
1165 }
1166 
1172 {
1173  /* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any group windows either
1174  * If that is the case, we can skip looping though the windows and save time
1175  */
1176  if (_special_mouse_mode != WSM_DRAGDROP) return;
1177 
1179  if (w != nullptr) w->UnselectVehicle(v->index);
1180 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
CMD_MSG
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:372
VehicleGroupWindow::SelectGroup
void SelectGroup(const GroupID g_id)
Selects the specified group in the list.
Definition: group_gui.cpp:1050
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
VehicleGroupWindow::ListColumns
ListColumns
Definition: group_gui.cpp:108
BaseVehicleListWindow::GetActionDropdownSize
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group)
Compute the size for the Action dropdown.
Definition: vehicle_gui.cpp:227
WC_INVALID
@ WC_INVALID
Invalid window.
Definition: window_type.h:700
VehicleGroupWindow::VGC_NAME
@ VGC_NAME
Group name.
Definition: group_gui.cpp:110
GUIList::SortType
uint8 SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:93
Pool::PoolItem<&_group_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
vehicle_gui.h
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1094
WID_GL_DEFAULT_VEHICLES
@ WID_GL_DEFAULT_VEHICLES
Default vehicles entry.
Definition: group_widget.h:28
VehicleListIdentifier::company
CompanyID company
The company associated with this list.
Definition: vehiclelist.h:32
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
CMD_ADD_VEHICLE_GROUP
@ CMD_ADD_VEHICLE_GROUP
add a vehicle to a group
Definition: command_type.h:324
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
command_func.h
Window::DrawSortButtonState
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:636
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
Pool::PoolItem<&_group_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:340
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:247
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:309
dropdown_func.h
BaseVehicleListWindow::grouping
GroupBy grouping
How we want to group the list.
Definition: vehicle_gui_base.h:79
VehicleListIdentifier
The information about a vehicle list.
Definition: vehiclelist.h:29
_special_mouse_mode
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
Definition: window.cpp:80
VehicleGroupWindow::group_confirm
GroupID group_confirm
Group awaiting delete confirmation.
Definition: group_gui.cpp:123
VehicleGroupWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: group_gui.cpp:445
company_base.h
VehicleGroupWindow::tiny_step_height
uint tiny_step_height
Step height for the group list.
Definition: group_gui.cpp:125
VehicleGroupWindow::VGC_AUTOREPLACE
@ VGC_AUTOREPLACE
Autoreplace active icon.
Definition: group_gui.cpp:112
WD_MATRIX_TOP
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
Definition: window_gui.h:78
CMD_REMOVE_ALL_VEHICLES_GROUP
@ CMD_REMOVE_ALL_VEHICLES_GROUP
remove all vehicles from a group
Definition: command_type.h:326
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:730
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
company_gui.h
CursorVars::vehchain
bool vehchain
vehicle chain is dragged
Definition: gfx_type.h:144
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1966
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_func.h:98
VehicleGroupWindow::group_rename
GroupID group_rename
Group being renamed, INVALID_GROUP if none.
Definition: group_gui.cpp:121
GUIList< const Group * >
WID_GL_DELETE_GROUP
@ WID_GL_DELETE_GROUP
Delete group button.
Definition: group_widget.h:32
WID_GL_STOP_ALL
@ WID_GL_STOP_ALL
Stop all button.
Definition: group_widget.h:24
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1832
DEPOT_MASS_SEND
@ DEPOT_MASS_SEND
Tells that it's a mass send to depot command (type in VLW flag)
Definition: vehicle_type.h:67
Group::parent
GroupID parent
Parent group.
Definition: group.h:77
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
VehicleGroupWindow::DirtyHighlightedGroupWidget
void DirtyHighlightedGroupWidget()
Mark the widget containing the currently highlighted group as dirty.
Definition: group_gui.cpp:328
Vehicle::group_id
GroupID group_id
Index of group Pool array.
Definition: vehicle_base.h:335
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:57
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1133
BaseVehicleListWindow::sorting
Listing * sorting
Pointer to the vehicle type related sorting.
Definition: vehicle_gui_base.h:82
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:1098
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:669
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:288
GroupStatistics::autoreplace_finished
bool autoreplace_finished
Have all autoreplacement finished?
Definition: group.h:30
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
vehicle_base.h
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:929
autoreplace_gui.h
VehicleGroupWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: group_gui.cpp:496
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:1040
GUIVehicleGroup::vehicles_begin
VehicleList::const_iterator vehicles_begin
Pointer to beginning element of this vehicle group.
Definition: vehicle_gui_base.h:28
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:640
WindowDesc::cls
WindowClass cls
Class of the window,.
Definition: window_gui.h:175
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
DeleteWindowByClass
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1178
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:324
WID_GL_START_ALL
@ WID_GL_START_ALL
Start all button.
Definition: group_widget.h:25
VehicleGroupWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: group_gui.cpp:972
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
WID_GL_LIST_VEHICLE
@ WID_GL_LIST_VEHICLE
List of the vehicles.
Definition: group_widget.h:20
VehicleGroupWindow::VGC_FOLD
@ VGC_FOLD
Fold / Unfold button.
Definition: group_gui.cpp:109
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_func.h:108
GUIList::SetSortType
void SetSortType(uint8 n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:103
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:283
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:588
VehicleGroupWindow::column_size
Dimension column_size[VGC_END]
Size of the columns in the group list.
Definition: group_gui.cpp:130
NEW_GROUP
static const GroupID NEW_GROUP
Sentinel for a to-be-created group.
Definition: group_type.h:15
VehicleGroupWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: group_gui.cpp:381
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:52
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:909
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1013
VehicleGroupWindow::indents
std::vector< int > indents
Indentation levels.
Definition: group_gui.cpp:128
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:842
textbuf_gui.h
GroupStatistics::num_vehicle
uint16 num_vehicle
Number of vehicles.
Definition: group.h:26
QSF_LEN_IN_CHARS
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
Definition: textbuf_gui.h:22
CcAddVehicleNewGroup
void CcAddVehicleNewGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Open rename window after adding a vehicle to a new group via drag and drop.
Definition: group_gui.cpp:1159
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
ALL_GROUP
static const GroupID ALL_GROUP
All vehicles are in this group.
Definition: group_type.h:16
WID_GL_GROUP_BY_ORDER
@ WID_GL_GROUP_BY_ORDER
Group order.
Definition: group_widget.h:16
WindowDesc
High level window description.
Definition: window_gui.h:166
Group
Group data.
Definition: group.h:66
WID_GL_ALL_VEHICLES
@ WID_GL_ALL_VEHICLES
All vehicles entry.
Definition: group_widget.h:27
CcCreateGroup
void CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Opens a 'Rename group' window for newly created group.
Definition: group_gui.cpp:1142
Group::replace_protection
bool replace_protection
If set to true, the global autoreplace have no effect on the group.
Definition: group.h:71
GroupStatistics
Statistics and caches on the vehicles in a group.
Definition: group.h:25
BaseVehicleListWindow::vli
VehicleListIdentifier vli
Identifier of the vehicle list we want to currently show.
Definition: vehicle_gui_base.h:85
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:116
WID_GL_GROUP_BY_DROPDOWN
@ WID_GL_GROUP_BY_DROPDOWN
Group by dropdown list.
Definition: group_widget.h:17
BaseVehicleListWindow::BuildActionDropdownList
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group)
Display the Action dropdown window.
Definition: vehicle_gui.cpp:249
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:223
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:154
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:322
CommandCost
Common return value for all commands.
Definition: command_type.h:23
tilehighlight_func.h
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
ShowCompanyGroupForVehicle
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
Definition: group_gui.cpp:1117
WID_GL_LIST_GROUP
@ WID_GL_LIST_GROUP
List of the groups.
Definition: group_widget.h:29
WID_GL_LIST_GROUP_SCROLLBAR
@ WID_GL_LIST_GROUP_SCROLLBAR
Scrollbar for the list.
Definition: group_widget.h:30
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:320
WID_GL_AVAILABLE_VEHICLES
@ WID_GL_AVAILABLE_VEHICLES
Available vehicles.
Definition: group_widget.h:22
WID_GL_LIST_VEHICLE_SCROLLBAR
@ WID_GL_LIST_VEHICLE_SCROLLBAR
Scrollbar for the list.
Definition: group_widget.h:21
VehicleClicked
bool VehicleClicked(const Vehicle *v)
Dispatch a "vehicle selected" event if any window waits for it.
Definition: vehicle_gui.cpp:3053
BaseVehicleListWindow
Definition: vehicle_gui_base.h:70
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:55
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
VehicleGroupWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: group_gui.cpp:916
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:208
VehicleGroupWindow::vehicle_sel
VehicleID vehicle_sel
Selected vehicle.
Definition: group_gui.cpp:119
VehicleGroupWindow::ComputeGroupInfoSize
uint ComputeGroupInfoSize()
Compute tiny_step_height and column_size.
Definition: group_gui.cpp:202
LEVEL_WIDTH
static const int LEVEL_WIDTH
Indenting width of a sub-group in pixels.
Definition: group_gui.cpp:34
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
find_index
int find_index(std::vector< T > const &vec, T const &item)
Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_...
Definition: smallvec_type.hpp:44
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:159
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
vehicle_gui_base.h
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:453
GetVehicleListHeight
uint GetVehicleListHeight(VehicleType type, uint divisor)
Get the height of a vehicle in the vehicle list GUIs.
Definition: vehicle_gui.cpp:1485
Group::owner
Owner owner
Group Owner.
Definition: group.h:68
SetMatrixDataTip
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1031
VehicleGroupWindow::VGC_NUMBER
@ VGC_NUMBER
Number of vehicles in the group.
Definition: group_gui.cpp:114
VehicleListIdentifier::Pack
uint32 Pack() const
Pack a VehicleListIdentifier in a single uint32.
Definition: vehiclelist.cpp:21
VehicleGroupWindow::OnDragDrop
void OnDragDrop(Point pt, int widget) override
A dragged 'object' has been released.
Definition: group_gui.cpp:908
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:337
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
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:1131
CMD_ALTER_GROUP
@ CMD_ALTER_GROUP
alter a group
Definition: command_type.h:323
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:317
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:3137
CMD_SET_GROUP_REPLACE_PROTECTION
@ CMD_SET_GROUP_REPLACE_PROTECTION
set the autoreplace-protection for a group
Definition: command_type.h:327
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:978
IsAllGroupID
static bool IsAllGroupID(GroupID id_g)
Checks if a GroupID stands for all vehicles of a company.
Definition: group.h:93
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:301
WSM_DRAGDROP
@ WSM_DRAGDROP
Drag&drop an object.
Definition: window_gui.h:908
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:494
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:312
CMD_DELETE_GROUP
@ CMD_DELETE_GROUP
delete a group
Definition: command_type.h:322
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:114
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:218
GUIList::ToggleSortOrder
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
Definition: sortlist_type.h:233
GUIList::NeedResort
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
Definition: sortlist_type.h:199
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:27
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
VehicleGroupWindow::VGC_PROTECT
@ VGC_PROTECT
Autoreplace protect icon.
Definition: group_gui.cpp:111
WID_GL_REPLACE_PROTECTION
@ WID_GL_REPLACE_PROTECTION
Replace protection button.
Definition: group_widget.h:35
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
VehicleListIdentifier::index
uint32 index
A vehicle list type specific index.
Definition: vehiclelist.h:33
GroupStatistics::autoreplace_defined
bool autoreplace_defined
Are any autoreplace rules set?
Definition: group.h:29
HT_DRAG
@ HT_DRAG
dragging items in the depot windows
Definition: tilehighlight_type.h:24
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:913
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
CMD_ADD_SHARED_VEHICLE_GROUP
@ CMD_ADD_SHARED_VEHICLE_GROUP
add all other shared vehicles to a group which are missing
Definition: command_type.h:325
WID_GL_CAPTION
@ WID_GL_CAPTION
Caption of the window.
Definition: group_widget.h:15
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
BaseVehicleListWindow::DrawVehicleListItems
void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const
Draw all the vehicle list items.
Definition: vehicle_gui.cpp:1505
GetWindowClassForVehicleType
static WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
Definition: vehicle_gui.h:91
WD_DROPDOWNTEXT_TOP
@ WD_DROPDOWNTEXT_TOP
Top offset of the dropdown widget string.
Definition: window_gui.h:134
string_func.h
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:103
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1274
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:224
EIT_IN_LIST
@ EIT_IN_LIST
Vehicle drawn in vehicle list, group list, ...
Definition: vehicle_type.h:89
GetGroupNumProfitVehicle
uint GetGroupNumProfitVehicle(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:819
CMD_CREATE_GROUP
@ CMD_CREATE_GROUP
create a new group
Definition: command_type.h:321
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:998
DEPOT_SERVICE
@ DEPOT_SERVICE
The vehicle will leave the depot right after arrival (service only)
Definition: vehicle_type.h:66
DeleteGroupHighlightOfVehicle
void DeleteGroupHighlightOfVehicle(const Vehicle *v)
Removes the highlight of a vehicle in a group window.
Definition: group_gui.cpp:1171
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1594
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:378
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
VehicleGroupWindow::VGC_PROFIT
@ VGC_PROFIT
Profit icon.
Definition: group_gui.cpp:113
GroupID
uint16 GroupID
Type for all group identifiers.
Definition: group_type.h:13
GUIVehicleGroup
Definition: vehicle_gui_base.h:27
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:175
VehicleGroupWindow::groups
GUIGroupList groups
List of groups.
Definition: group_gui.cpp:124
WID_GL_LIVERY_GROUP
@ WID_GL_LIVERY_GROUP
Group livery button.
Definition: group_widget.h:34
CMD_MASS_START_STOP
@ CMD_MASS_START_STOP
start/stop all vehicles (in a depot)
Definition: command_type.h:316
HideDropDownMenu
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
Definition: dropdown.cpp:512
VehicleGroupWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: group_gui.cpp:922
VehicleGroupWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: group_gui.cpp:652
BaseVehicleListWindow::vehgroups
GUIVehicleGroupList vehgroups
List of (groups of) vehicles. This stores iterators of vehicles, and should be rebuilt if vehicles is...
Definition: vehicle_gui_base.h:81
WIDGET_LIST_END
static const int WIDGET_LIST_END
indicate the end of widgets' list for vararg functions
Definition: widget_type.h:20
ShowReplaceGroupVehicleWindow
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
Definition: autoreplace_gui.cpp:834
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
VehicleListIdentifier::vtype
VehicleType vtype
The vehicle type associated with this list.
Definition: vehiclelist.h:31
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1113
geometry_func.hpp
SetDParamMaxValue
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:104
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:946
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
WID_GL_SORT_BY_DROPDOWN
@ WID_GL_SORT_BY_DROPDOWN
Sort by dropdown list.
Definition: group_widget.h:19
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition: sortlist_type.h:116
Window::SetWidgetsDisabledState
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:536
VehicleGroupWindow::group_over
GroupID group_over
Group over which a vehicle is dragged, INVALID_GROUP if none.
Definition: group_gui.cpp:122
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:630
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:254
WID_GL_CREATE_GROUP
@ WID_GL_CREATE_GROUP
Create group button.
Definition: group_widget.h:31
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1848
WID_GL_MANAGE_VEHICLES_DROPDOWN
@ WID_GL_MANAGE_VEHICLES_DROPDOWN
Manage vehicles dropdown list.
Definition: group_widget.h:23
company_func.h
WID_GL_RENAME_GROUP
@ WID_GL_RENAME_GROUP
Rename group button.
Definition: group_widget.h:33
FindVehicleGroupWindow
static VehicleGroupWindow * FindVehicleGroupWindow(VehicleType vt, Owner owner)
Finds a group list window determined by vehicle type and owner.
Definition: group_gui.cpp:1128
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:213
VehicleGroupWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: group_gui.cpp:554
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
Ceil
static uint Ceil(uint a, uint b)
Computes ceil(a / b) * b for non-negative a and b.
Definition: math_func.hpp:265
VehicleGroupWindow::BuildGroupList
void BuildGroupList(Owner owner)
(Re)Build the group list.
Definition: group_gui.cpp:154
WID_GL_INFO
@ WID_GL_INFO
Group info.
Definition: group_widget.h:36
ShowVehicleViewWindow
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
Definition: vehicle_gui.cpp:3043
window_func.h
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
BaseVehicleListWindow::vehicles
VehicleList vehicles
List of vehicles. This is the buffer for vehgroups to point into; if this is structurally modified,...
Definition: vehicle_gui_base.h:80
VehicleGroupWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: group_gui.cpp:928
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:319
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:1980
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:656
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
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:802
WID_GL_SORT_BY_ORDER
@ WID_GL_SORT_BY_ORDER
Sort order.
Definition: group_widget.h:18
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
SetObjectToPlaceWnd
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
Definition: viewport.cpp:3358
Group::folded
bool folded
NOSAVE: Is this group folded in the group view?
Definition: group.h:75
strnatcmp
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:625
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:982
SPR_CURSOR_MOUSE
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1374
VehicleGroupWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: group_gui.cpp:979
WD_DROPDOWNTEXT_BOTTOM
@ WD_DROPDOWNTEXT_BOTTOM
Bottom offset of the dropdown widget string.
Definition: window_gui.h:135
Window
Data structure for an opened window.
Definition: window_gui.h:276
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
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:318
Window::RaiseWidget
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:483
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:225
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:282
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
VehicleGroupWindow::OnMouseDrag
void OnMouseDrag(Point pt, int widget) override
An 'object' is being dragged at the provided position, highlight the target if possible.
Definition: group_gui.cpp:989
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:172
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:383
VehicleGroupWindow::group_sel
GroupID group_sel
Selected group (for drag/drop)
Definition: group_gui.cpp:120
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3421
VehicleGroupWindow
Definition: group_gui.cpp:105
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:48
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
SetMinimalTextLines
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:964
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:68
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:62
VehicleGroupWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: group_gui.cpp:469
GetGroupProfitLastYear
Money GetGroupProfitLastYear(CompanyID company, GroupID id_g, VehicleType type)
Get last year's profit for the group with GroupID id_g and its sub-groups.
Definition: group_cmd.cpp:836