OpenTTD Source 20250716-master-g6b6caa6fa8
group_gui.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#include "stdafx.h"
11#include "textbuf_gui.h"
12#include "command_func.h"
13#include "vehicle_gui.h"
14#include "vehicle_base.h"
15#include "string_func.h"
16#include "strings_func.h"
17#include "window_func.h"
18#include "vehicle_func.h"
19#include "autoreplace_gui.h"
20#include "company_func.h"
21#include "dropdown_func.h"
22#include "tilehighlight_func.h"
23#include "vehicle_gui_base.h"
26#include "company_base.h"
27#include "company_gui.h"
28#include "gui.h"
29#include "group_cmd.h"
30#include "group_gui.h"
31#include "vehicle_cmd.h"
32#include "gfx_func.h"
33
35
36#include "table/sprites.h"
37#include "table/strings.h"
38
39#include "safeguards.h"
40
41static 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),
50 /* left part */
55 NWidget(WWT_MATRIX, COLOUR_GREY, WID_GL_LIST_GROUP), SetMatrixDataTip(1, 0, STR_GROUPS_CLICK_ON_GROUP_FOR_TOOLTIP),
59 NWidget(WWT_PANEL, COLOUR_GREY, WID_GL_INFO), SetFill(1, 1), SetMinimalTextLines(3, WidgetDimensions::unscaled.framerect.Vertical()), EndContainer(),
62 SetToolTip(STR_GROUP_CREATE_TOOLTIP),
64 SetToolTip(STR_GROUP_DELETE_TOOLTIP),
66 SetToolTip(STR_GROUP_RENAME_TOOLTIP),
68 SetToolTip(STR_GROUP_LIVERY_TOOLTIP),
69 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 0), EndContainer(),
71 SetToolTip(STR_GROUP_REPLACE_PROTECTION_TOOLTIP),
74 /* right part */
78 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GL_GROUP_BY_ORDER), SetFill(1, 1), SetMinimalSize(0, 12), SetStringTip(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), SetStringTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
82 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GL_GROUP_BY_DROPDOWN), SetFill(1, 1), SetMinimalSize(0, 12), SetToolTip(STR_TOOLTIP_GROUP_ORDER),
83 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GL_SORT_BY_DROPDOWN), SetFill(1, 1), SetMinimalSize(0, 12), SetToolTip(STR_TOOLTIP_SORT_CRITERIA),
86 NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetFill(0, 1), SetResize(1, 0), EndContainer(),
88 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GL_FILTER_BY_CARGO), SetMinimalSize(0, 12), SetFill(0, 1), SetToolTip(STR_TOOLTIP_FILTER_CRITERIA),
89 NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(0, 1), SetResize(1, 0), EndContainer(),
97 NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(1, 0), SetFill(1, 1), SetResize(1, 0), EndContainer(),
100 SetToolTip(STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP),
101 NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetResize(1, 0), EndContainer(),
103 SetStringTip(STR_VEHICLE_LIST_MANAGE_LIST, STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP),
104 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_STOP_ALL), SetAspect(WidgetDimensions::ASPECT_VEHICLE_FLAG),
105 SetSpriteTip(SPR_FLAG_VEH_STOPPED, STR_VEHICLE_LIST_MASS_STOP_LIST_TOOLTIP),
106 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_START_ALL), SetAspect(WidgetDimensions::ASPECT_VEHICLE_FLAG),
107 SetSpriteTip(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
114static void SortGUIGroupList(std::vector<GUIGroupListItem> &list)
115{
116 /* Sort the groups by their name */
117 std::array<std::pair<const Group *, std::string>, 2> last_group{};
118
119 std::ranges::sort(list, [&last_group](const GUIGroupListItem &a, const GUIGroupListItem &b) -> bool {
120 if (a.group != last_group[0].first) {
121 last_group[0] = {a.group, GetString(STR_GROUP_NAME, a.group->index)};
122 }
123
124 if (b.group != last_group[1].first) {
125 last_group[1] = {b.group, GetString(STR_GROUP_NAME, b.group->index)};
126 }
127
128 int r = StrNaturalCompare(last_group[0].second, last_group[1].second); // Sort by name (natural sorting).
129 if (r == 0) return a.group->number < b.group->number;
130 return r < 0;
131 });
132}
133
141static void GuiGroupListAddChildren(GUIGroupList &list, GUIGroupListItem &item, bool fold, uint8_t indent = 1)
142{
143 if (fold && item.group->folded) {
144 Group::Get(item.group->index)->folded = !item.group->children.empty();
145 return;
146 }
147
148 if (item.group->children.empty()) return;
149
150 std::vector<GUIGroupListItem> sublist;
151 for (const GroupID &group : item.group->children) {
152 sublist.emplace_back(Group::Get(group), indent);
153 }
154 SortGUIGroupList(sublist);
155
156 for (const GUIGroupListItem &subitem : sublist) {
157 GuiGroupListAddChildren(list, list.emplace_back(subitem), fold, indent + 1);
158 }
159}
160
168void BuildGuiGroupList(GUIGroupList &list, bool fold, Owner owner, VehicleType veh_type)
169{
170 /* Make a temporary list of parent groups */
171 std::vector<GUIGroupListItem> sublist;
172 for (const Group *g : Group::Iterate()) {
173 if (g->parent != GroupID::Invalid()) continue;
174 if (g->owner != owner) continue;
175 if (g->vehicle_type != veh_type) continue;
176 sublist.emplace_back(g, 0);
177 }
178 SortGUIGroupList(sublist);
179
180 /* Now add each parent group, and its children if necessary, to the list. */
181 for (auto &item : sublist) {
182 GuiGroupListAddChildren(list, list.emplace_back(item), fold);
183 }
184
185 if (list.empty()) return;
186
187 /* Hierarchy is complete, traverse in reverse to find where indentation levels continue. */
188 uint16_t level_mask = 0;
189 for (auto it = std::rbegin(list); std::next(it) != std::rend(list); ++it) {
190 auto next_it = std::next(it);
191 AssignBit(level_mask, it->indent, it->indent <= next_it->indent);
192 next_it->level_mask = level_mask;
193 }
194}
195
197private:
198 /* Columns in the group list */
209
210 GroupID group_sel = GroupID::Invalid();
211 GroupID group_rename = GroupID::Invalid();
212 GroupID group_over = GroupID::Invalid();
213 GroupID group_confirm = GroupID::Invalid();
216 Scrollbar *group_sb = nullptr;
217
218 std::array<Dimension, VGC_END> column_size{};
219 bool last_overlay_state = false;
220
227 {
228 if (!this->groups.NeedRebuild()) return;
229
230 this->groups.clear();
231
232 BuildGuiGroupList(this->groups, true, owner, this->vli.vtype);
233
234 this->groups.RebuildDone();
235 }
236
242 {
243 this->column_size[VGC_FOLD] = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED));
244 this->tiny_step_height = this->column_size[VGC_FOLD].height;
245
246 this->column_size[VGC_NAME] = maxdim(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + this->vli.vtype), GetStringBoundingBox(STR_GROUP_ALL_TRAINS + this->vli.vtype));
247 this->column_size[VGC_NAME].width = std::max(170u, this->column_size[VGC_NAME].width) + WidgetDimensions::scaled.hsep_indent;
248 this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_NAME].height);
249
250 this->column_size[VGC_PROTECT] = GetSpriteSize(SPR_GROUP_REPLACE_PROTECT);
251 this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_PROTECT].height);
252
253 this->column_size[VGC_AUTOREPLACE] = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
254 this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_AUTOREPLACE].height);
255
256 this->column_size[VGC_PROFIT].width = 0;
257 this->column_size[VGC_PROFIT].height = 0;
258 static const SpriteID profit_sprites[] = {SPR_PROFIT_NA, SPR_PROFIT_NEGATIVE, SPR_PROFIT_SOME, SPR_PROFIT_LOT};
259 for (const auto &profit_sprite : profit_sprites) {
260 Dimension d = GetSpriteSize(profit_sprite);
262 }
263 this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_PROFIT].height);
264
265 int num_vehicle = GetGroupNumVehicle(this->vli.company, ALL_GROUP, this->vli.vtype);
266 uint64_t max_value = GetParamMaxValue(num_vehicle, 3, FS_SMALL);
267 this->column_size[VGC_NUMBER] = GetStringBoundingBox(GetString(STR_GROUP_COUNT_WITH_SUBGROUP, max_value, max_value));
268 this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_NUMBER].height);
269
270 this->tiny_step_height += WidgetDimensions::scaled.framerect.Vertical();
271
278 this->column_size[VGC_NUMBER].width +
280 }
281
292 void DrawGroupInfo(int y, int left, int right, GroupID g_id, uint16_t level_mask = 0, uint8_t indent = 0, bool protection = false, bool has_children = false) const
293 {
294 /* Highlight the group if a vehicle is dragged over it */
295 if (g_id == this->group_over) {
296 GfxFillRect(left + WidgetDimensions::scaled.bevel.left, y + WidgetDimensions::scaled.framerect.top, right - WidgetDimensions::scaled.bevel.right, y + this->tiny_step_height - 1 - WidgetDimensions::scaled.framerect.bottom, GetColourGradient(COLOUR_GREY, SHADE_LIGHTEST));
297 }
298
299 if (g_id == NEW_GROUP) return;
300
301 /* draw the selected group in white, else we draw it in black */
302 TextColour colour = g_id == this->vli.ToGroupID() ? TC_WHITE : TC_BLACK;
303 const GroupStatistics &stats = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype);
304 bool rtl = _current_text_dir == TD_RTL;
305
306 const int offset = (rtl ? -(int)this->column_size[VGC_FOLD].width : (int)this->column_size[VGC_FOLD].width) / 2;
308 const int linecolour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL);
309
310 if (indent > 0) {
311 /* Draw tree continuation lines. */
312 int tx = (rtl ? right - WidgetDimensions::scaled.framerect.right : left + WidgetDimensions::scaled.framerect.left) + offset;
313 for (uint lvl = 1; lvl <= indent; ++lvl) {
314 if (HasBit(level_mask, lvl)) GfxDrawLine(tx, y, tx, y + this->tiny_step_height - 1, linecolour, WidgetDimensions::scaled.fullbevel.top);
315 if (lvl < indent) tx += level_width;
316 }
317 /* Draw our node in the tree. */
318 int ycentre = y + this->tiny_step_height / 2 - 1;
319 if (!HasBit(level_mask, indent)) GfxDrawLine(tx, y, tx, ycentre, linecolour, WidgetDimensions::scaled.fullbevel.top);
320 GfxDrawLine(tx, ycentre, tx + offset - (rtl ? -1 : 1), ycentre, linecolour, WidgetDimensions::scaled.fullbevel.top);
321 }
322
323 /* draw fold / unfold button */
324 int x = rtl ? right - WidgetDimensions::scaled.framerect.right - this->column_size[VGC_FOLD].width + 1 : left + WidgetDimensions::scaled.framerect.left;
325 if (has_children) {
326 DrawSprite(Group::Get(g_id)->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, x + indent * level_width, y + (this->tiny_step_height - this->column_size[VGC_FOLD].height) / 2);
327 }
328
329 /* draw group name */
330 std::string str;
331 if (IsAllGroupID(g_id)) {
332 str = GetString(STR_GROUP_ALL_TRAINS + this->vli.vtype);
333 } else if (IsDefaultGroupID(g_id)) {
334 str = GetString(STR_GROUP_DEFAULT_TRAINS + this->vli.vtype);
335 } else {
336 str = GetString(STR_GROUP_NAME, g_id);
337 }
339 DrawString(x + (rtl ? 0 : indent * WidgetDimensions::scaled.hsep_indent), x + this->column_size[VGC_NAME].width - 1 - (rtl ? indent * WidgetDimensions::scaled.hsep_indent : 0), y + (this->tiny_step_height - this->column_size[VGC_NAME].height) / 2, std::move(str), colour);
340
341 /* draw autoreplace protection */
343 if (protection) DrawSprite(SPR_GROUP_REPLACE_PROTECT, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_PROTECT].height) / 2);
344
345 /* draw autoreplace status */
347 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);
348
349 /* draw the profit icon */
351 SpriteID spr;
352 uint num_vehicle_min_age = GetGroupNumVehicleMinAge(this->vli.company, g_id, this->vli.vtype);
353 Money profit_last_year_min_age = GetGroupProfitLastYearMinAge(this->vli.company, g_id, this->vli.vtype);
354 if (num_vehicle_min_age == 0) {
355 spr = SPR_PROFIT_NA;
356 } else if (profit_last_year_min_age < 0) {
357 spr = SPR_PROFIT_NEGATIVE;
358 } else if (profit_last_year_min_age < VEHICLE_PROFIT_THRESHOLD * num_vehicle_min_age) {
359 spr = SPR_PROFIT_SOME;
360 } else {
361 spr = SPR_PROFIT_LOT;
362 }
363 DrawSprite(spr, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_PROFIT].height) / 2);
364
365 /* draw the number of vehicles of the group */
367 int num_vehicle_with_subgroups = GetGroupNumVehicle(this->vli.company, g_id, this->vli.vtype);
368 int num_vehicle = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype).num_vehicle;
369 if (IsAllGroupID(g_id) || IsDefaultGroupID(g_id) || num_vehicle_with_subgroups == num_vehicle) {
370 DrawString(x, x + this->column_size[VGC_NUMBER].width - 1, y + (this->tiny_step_height - this->column_size[VGC_NUMBER].height) / 2, GetString(STR_JUST_COMMA, num_vehicle), colour, SA_RIGHT | SA_FORCE, false, FS_SMALL);
371 } else {
372 DrawString(x, x + this->column_size[VGC_NUMBER].width - 1, y + (this->tiny_step_height - this->column_size[VGC_NUMBER].height) / 2, GetString(STR_GROUP_COUNT_WITH_SUBGROUP, num_vehicle, num_vehicle_with_subgroups - num_vehicle), colour, SA_RIGHT | SA_FORCE);
373 }
374 }
375
380 {
381 if (this->group_over == GroupID::Invalid()) return;
382
383 if (IsAllGroupID(this->group_over)) {
385 } else if (IsDefaultGroupID(this->group_over)) {
387 } else {
389 }
390 }
391
392public:
394 {
395 this->CreateNestedTree();
396
397 this->vscroll = this->GetScrollbar(WID_GL_LIST_VEHICLE_SCROLLBAR);
398 this->group_sb = this->GetScrollbar(WID_GL_LIST_GROUP_SCROLLBAR);
399
400 this->vli.SetIndex(ALL_GROUP);
401
402 this->groups.ForceRebuild();
403 this->groups.NeedResort();
404 this->BuildGroupList(vli.company);
405 this->group_sb->SetCount(this->groups.size());
406
407 this->GetWidget<NWidgetCore>(WID_GL_CAPTION)->SetString(STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype);
408 this->GetWidget<NWidgetCore>(WID_GL_LIST_VEHICLE)->SetToolTip(STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype);
409
410 this->GetWidget<NWidgetCore>(WID_GL_CREATE_GROUP)->SetSprite(SPR_GROUP_CREATE_TRAIN + this->vli.vtype);
411 this->GetWidget<NWidgetCore>(WID_GL_RENAME_GROUP)->SetSprite(SPR_GROUP_RENAME_TRAIN + this->vli.vtype);
412 this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->SetSprite(SPR_GROUP_DELETE_TRAIN + this->vli.vtype);
413 this->GetWidget<NWidgetCore>(WID_GL_LIVERY_GROUP)->SetSprite(SPR_GROUP_LIVERY_TRAIN + this->vli.vtype);
414 this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->SetSprite(SPR_GROUP_REPLACE_OFF_TRAIN + this->vli.vtype);
415
416 this->FinishInitNested(window_number);
417 this->owner = vli.company;
418
419 this->BuildVehicleList();
420 this->SortVehicleList();
421 }
422
424 {
425 *this->sorting = this->vehgroups.GetListing();
426 }
427
428 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
429 {
430 switch (widget) {
432 size.width = this->ComputeGroupInfoSize();
433 fill.height = resize.height = this->tiny_step_height;
434 break;
435
438 size.width = this->ComputeGroupInfoSize();
439 size.height = this->tiny_step_height;
440 break;
441
443 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->GetString());
444 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
445 d.height += padding.height;
446 size = maxdim(size, d);
447 break;
448 }
449
451 this->ComputeGroupInfoSize();
452 fill.height = resize.height = GetVehicleListHeight(this->vli.vtype, this->tiny_step_height);
453 size.height = 4 * resize.height;
454 break;
455
457 size.width = GetStringListWidth(this->vehicle_group_by_names) + padding.width;
458 break;
459
461 size.width = GetStringListWidth(this->vehicle_group_none_sorter_names_calendar);
462 size.width = std::max(size.width, GetStringListWidth(this->vehicle_group_none_sorter_names_wallclock));
463 size.width = std::max(size.width, GetStringListWidth(this->vehicle_group_shared_orders_sorter_names_calendar));
464 size.width = std::max(size.width, GetStringListWidth(this->vehicle_group_shared_orders_sorter_names_wallclock));
465 size.width += padding.width;
466 break;
467
469 size.width = std::max(size.width, GetDropDownListDimension(this->BuildCargoDropDownList(true)).width + padding.width);
470 break;
471
473 Dimension d = this->GetActionDropdownSize(true, true, true);
474 d.height += padding.height;
475 d.width += padding.width;
476 size = maxdim(size, d);
477 break;
478 }
479 }
480 }
481
487 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
488 {
489 if (data == 0) {
490 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
491 this->vehgroups.ForceRebuild();
492 this->groups.ForceRebuild();
493 } else {
494 this->vehgroups.ForceResort();
495 this->groups.ForceResort();
496 }
497
498 /* Process ID-invalidation in command-scope as well */
499 if (this->group_rename != GroupID::Invalid() && !Group::IsValidID(this->group_rename)) {
501 this->group_rename = GroupID::Invalid();
502 }
503
504 GroupID group = this->vli.ToGroupID();
505 if (!(IsAllGroupID(group) || IsDefaultGroupID(group) || Group::IsValidID(group))) {
506 this->vli.SetIndex(ALL_GROUP);
508 }
509 this->SetDirty();
510 }
511
512 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
513 {
514 switch (widget) {
516 return GetString(this->GetCargoFilterLabel(this->cargo_filter_criteria));
517
519 return GetString(STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vli.vtype);
520
521 case WID_GL_CAPTION:
522 /* If selected_group == DEFAULT_GROUP || ALL_GROUP, draw the standard caption
523 * We list all vehicles or ungrouped vehicles */
524 if (IsDefaultGroupID(this->vli.ToGroupID()) || IsAllGroupID(this->vli.ToGroupID())) {
525 return GetString(stringid, STR_COMPANY_NAME, this->vli.company, this->vehicles.size(), this->vehicles.size());
526 } else {
527 uint num_vehicle = GetGroupNumVehicle(this->vli.company, this->vli.ToGroupID(), this->vli.vtype);
528
529 return GetString(stringid, STR_GROUP_NAME, this->vli.ToGroupID(), num_vehicle, num_vehicle);
530 }
531
532 default:
533 return this->Window::GetWidgetString(widget, stringid);
534 }
535 }
536
537 void OnPaint() override
538 {
539 /* If we select the all vehicles, this->list will contain all vehicles of the owner
540 * else this->list will contain all vehicles which belong to the selected group */
541 this->BuildVehicleList();
542 this->SortVehicleList();
543
544 this->BuildGroupList(this->owner);
545
546 this->group_sb->SetCount(this->groups.size());
547 this->vscroll->SetCount(this->vehgroups.size());
548
549 /* The drop down menu is out, *but* it may not be used, retract it. */
550 if (this->vehicles.empty() && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) {
553 }
554
555 /* Disable all lists management button when the list is empty */
556 this->SetWidgetsDisabledState(this->vehicles.empty() || _local_company != this->vli.company,
560
561 /* Disable the group specific function when we select the default group or all vehicles */
562 GroupID group = this->vli.ToGroupID();
563 this->SetWidgetsDisabledState(IsDefaultGroupID(group) || IsAllGroupID(group) || _local_company != this->vli.company,
568
569 /* Disable remaining buttons for non-local companies
570 * Needed while changing _local_company, eg. by cheats
571 * All procedures (eg. move vehicle to another group)
572 * verify, whether you are the owner of the vehicle,
573 * so it doesn't have to be disabled
574 */
578
579 /* If not a default group and the group has replace protection, show an enabled replace sprite. */
580 uint16_t protect_sprite = SPR_GROUP_REPLACE_OFF_TRAIN;
581 if (!IsDefaultGroupID(group) && !IsAllGroupID(group) && Group::Get(group)->flags.Test(GroupFlag::ReplaceProtection)) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN;
582 this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->SetSprite(protect_sprite + this->vli.vtype);
583
584 /* Set text of "group by" dropdown widget. */
585 this->GetWidget<NWidgetCore>(WID_GL_GROUP_BY_DROPDOWN)->SetString(std::data(this->vehicle_group_by_names)[this->grouping]);
586
587 /* Set text of "sort by" dropdown widget. */
588 this->GetWidget<NWidgetCore>(WID_GL_SORT_BY_DROPDOWN)->SetString(this->GetVehicleSorterNames()[this->vehgroups.SortType()]);
589
590 this->DrawWidgets();
591 }
592
593 void DrawWidget(const Rect &r, WidgetID widget) const override
594 {
595 switch (widget) {
597 DrawGroupInfo(r.top, r.left, r.right, ALL_GROUP);
598 break;
599
601 DrawGroupInfo(r.top, r.left, r.right, DEFAULT_GROUP);
602 break;
603
604 case WID_GL_INFO: {
605 Money this_year = 0;
606 Money last_year = 0;
607 uint64_t occupancy = 0;
608
609 for (const Vehicle * const v : this->vehicles) {
610 assert(v->owner == this->owner);
611
612 this_year += v->GetDisplayProfitThisYear();
613 last_year += v->GetDisplayProfitLastYear();
614 occupancy += v->trip_occupancy;
615 }
616
617 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
618
619 DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_THIS_PERIOD : STR_GROUP_PROFIT_THIS_YEAR, TC_BLACK);
620 DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, this_year), TC_BLACK, SA_RIGHT);
621
622 tr.top += GetCharacterHeight(FS_NORMAL);
623 DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_LAST_PERIOD : STR_GROUP_PROFIT_LAST_YEAR, TC_BLACK);
624 DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, last_year), TC_BLACK, SA_RIGHT);
625
626 tr.top += GetCharacterHeight(FS_NORMAL);
627 DrawString(tr, STR_GROUP_OCCUPANCY, TC_BLACK);
628 const size_t vehicle_count = this->vehicles.size();
629 if (vehicle_count > 0) {
630 DrawString(tr, GetString(STR_GROUP_OCCUPANCY_VALUE, occupancy / vehicle_count), TC_BLACK, SA_RIGHT);
631 }
632
633 break;
634 }
635
636 case WID_GL_LIST_GROUP: {
637 int y1 = r.top;
638 auto [first, last] = this->group_sb->GetVisibleRangeIterators(this->groups);
639 for (auto it = first; it != last; ++it) {
640 const Group *g = it->group;
641
642 assert(g->owner == this->owner);
643
644 DrawGroupInfo(y1, r.left, r.right, g->index, it->level_mask, it->indent, g->flags.Test(GroupFlag::ReplaceProtection), g->folded || (std::next(it) != std::end(this->groups) && std::next(it)->indent > it->indent));
645
646 y1 += this->tiny_step_height;
647 }
648 if ((uint)this->group_sb->GetPosition() + this->group_sb->GetCapacity() > this->groups.size()) {
649 DrawGroupInfo(y1, r.left, r.right, NEW_GROUP);
650 }
651 break;
652 }
653
656 break;
657
659 if (this->vli.ToGroupID() != ALL_GROUP && this->grouping == GB_NONE) {
660 /* Mark vehicles which are in sub-groups (only if we are not using shared order coalescing) */
661 Rect mr = r.WithHeight(this->resize.step_height);
662 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->vehgroups);
663 for (auto it = first; it != last; ++it) {
664 const Vehicle *v = it->GetSingleVehicle();
665 if (v->group_id != this->vli.ToGroupID()) {
667 }
668 mr = mr.Translate(0, this->resize.step_height);
669 }
670 }
671
672 this->DrawVehicleListItems(this->vehicle_sel, this->resize.step_height, r);
673 break;
674 }
675 }
676
677 static void DeleteGroupCallback(Window *win, bool confirmed)
678 {
679 if (confirmed) {
681 w->vli.SetIndex(ALL_GROUP);
682 Command<CMD_DELETE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_DELETE, w->group_confirm);
683 }
684 }
685
686 void OnMouseLoop() override
687 {
688 if (last_overlay_state != ShowCargoIconOverlay()) {
689 last_overlay_state = ShowCargoIconOverlay();
690 this->SetDirty();
691 }
692 }
693
694 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
695 {
696 switch (widget) {
697 case WID_GL_SORT_BY_ORDER: // Flip sorting method ascending/descending
699 this->SetDirty();
700 break;
701
702 case WID_GL_GROUP_BY_DROPDOWN: // Select grouping option dropdown menu
703 ShowDropDownMenu(this, this->vehicle_group_by_names, this->grouping, WID_GL_GROUP_BY_DROPDOWN, 0, 0);
704 return;
705
706 case WID_GL_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
707 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));
708 return;
709
710 case WID_GL_FILTER_BY_CARGO: // Select filtering criteria dropdown menu
711 ShowDropDownList(this, this->BuildCargoDropDownList(false), this->cargo_filter_criteria, widget);
712 break;
713
714 case WID_GL_ALL_VEHICLES: // All vehicles button
715 if (!IsAllGroupID(this->vli.ToGroupID())) {
716 this->vli.SetIndex(ALL_GROUP);
717 this->vehgroups.ForceRebuild();
718 this->SetDirty();
719 }
720 break;
721
722 case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles button
723 if (!IsDefaultGroupID(this->vli.ToGroupID())) {
724 this->vli.SetIndex(DEFAULT_GROUP);
725 this->vehgroups.ForceRebuild();
726 this->SetDirty();
727 }
728 break;
729
730 case WID_GL_LIST_GROUP: { // Matrix Group
731 auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
732 if (it == this->groups.end()) return;
733
734 if (it->group->folded || (std::next(it) != std::end(this->groups) && std::next(it)->indent > it->indent)) {
735 /* The group has children, check if the user clicked the fold / unfold button. */
736 NWidgetCore *group_display = this->GetWidget<NWidgetCore>(widget);
737 int x = _current_text_dir == TD_RTL ?
738 group_display->pos_x + group_display->current_x - WidgetDimensions::scaled.framerect.right - it->indent * WidgetDimensions::scaled.hsep_indent - this->column_size[VGC_FOLD].width :
740 if (click_count > 1 || (pt.x >= x && pt.x < (int)(x + this->column_size[VGC_FOLD].width))) {
741
742 GroupID g = this->vli.ToGroupID();
743 if (!IsAllGroupID(g) && !IsDefaultGroupID(g)) {
744 do {
745 g = Group::Get(g)->parent;
746 if (g == it->group->index) {
747 this->vli.SetIndex(g);
748 break;
749 }
750 } while (g != GroupID::Invalid());
751 }
752
753 Group::Get(it->group->index)->folded = !it->group->folded;
754 this->groups.ForceRebuild();
755
756 this->SetDirty();
757 break;
758 }
759 }
760
761 this->vli.SetIndex(it->group->index);
762 this->group_sel = it->group->index;
763
765
766 this->vehgroups.ForceRebuild();
767 this->SetDirty();
768 break;
769 }
770
771 case WID_GL_LIST_VEHICLE: { // Matrix Vehicle
772 auto it = this->vscroll->GetScrolledItemFromWidget(this->vehgroups, pt.y, this, WID_GL_LIST_VEHICLE);
773 if (it == this->vehgroups.end()) return; // click out of list bound
774
775 const GUIVehicleGroup &vehgroup = *it;
776
777 const Vehicle *v = nullptr;
778
779 switch (this->grouping) {
780 case GB_NONE: {
781 const Vehicle *v2 = vehgroup.GetSingleVehicle();
782 if (VehicleClicked(v2)) break;
783 v = v2;
784 break;
785 }
786
787 case GB_SHARED_ORDERS: {
788 assert(vehgroup.NumVehicles() > 0);
789 v = vehgroup.vehicles_begin[0];
790 /*
791 * No VehicleClicked(v) support for now, because don't want
792 * to enable any contextual actions except perhaps clicking/ctrl-clicking to clone orders.
793 */
794 break;
795 }
796
797 default:
798 NOT_REACHED();
799 }
800 if (v) {
801 if (_ctrl_pressed && this->grouping == GB_SHARED_ORDERS) {
802 ShowOrdersWindow(v);
803 } else {
804 this->vehicle_sel = v->index;
805
806 if (_ctrl_pressed && this->grouping == GB_NONE) {
807 /*
808 * It only makes sense to select a group if not using shared orders
809 * since two vehicles sharing orders can be from different groups.
810 */
811 this->SelectGroup(v->group_id);
812 }
813
816 _cursor.vehchain = true;
817
818 this->SetDirty();
819 }
820 }
821
822 break;
823 }
824
825 case WID_GL_CREATE_GROUP: { // Create a new group
826 Command<CMD_CREATE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_CREATE, CcCreateGroup, this->vli.vtype, this->vli.ToGroupID());
827 break;
828 }
829
830 case WID_GL_DELETE_GROUP: { // Delete the selected group
831 this->group_confirm = this->vli.ToGroupID();
832 ShowQuery(
833 GetEncodedString(STR_QUERY_GROUP_DELETE_CAPTION),
834 GetEncodedString(STR_GROUP_DELETE_QUERY_TEXT),
835 this, DeleteGroupCallback);
836 break;
837 }
838
839 case WID_GL_RENAME_GROUP: // Rename the selected roup
840 this->ShowRenameGroupWindow(this->vli.ToGroupID(), false);
841 break;
842
843 case WID_GL_LIVERY_GROUP: // Set group livery
844 ShowCompanyLiveryWindow(this->owner, this->vli.ToGroupID());
845 break;
846
848 ShowBuildVehicleWindow(INVALID_TILE, this->vli.vtype);
849 break;
850
852 ShowDropDownList(this, this->BuildActionDropdownList(true, Group::IsValidID(this->vli.ToGroupID()), IsDefaultGroupID(this->vli.ToGroupID())), -1, WID_GL_MANAGE_VEHICLES_DROPDOWN);
853 break;
854 }
855
856 case WID_GL_START_ALL:
857 case WID_GL_STOP_ALL: { // Start/stop all vehicles of the list
859 break;
860 }
861
863 const Group *g = Group::GetIfValid(this->vli.ToGroupID());
864 if (g != nullptr) {
866 }
867 break;
868 }
869 }
870 }
871
872 void OnDragDrop_Group(Point pt, WidgetID widget)
873 {
874 const Group *g = Group::Get(this->group_sel);
875
876 switch (widget) {
877 case WID_GL_ALL_VEHICLES: // All vehicles
878 case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
879 if (g->parent != GroupID::Invalid()) {
880 Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_SET_PARENT, AlterGroupMode::SetParent, this->group_sel, GroupID::Invalid(), {});
881 }
882
883 this->group_sel = GroupID::Invalid();
884 this->group_over = GroupID::Invalid();
885 this->SetDirty();
886 break;
887
888 case WID_GL_LIST_GROUP: { // Matrix group
889 auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
890 GroupID new_g = it == this->groups.end() ? GroupID::Invalid() : it->group->index;
891
892 if (this->group_sel != new_g && g->parent != new_g) {
893 Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_SET_PARENT, AlterGroupMode::SetParent, this->group_sel, new_g, {});
894 }
895
896 this->group_sel = GroupID::Invalid();
897 this->group_over = GroupID::Invalid();
898 this->SetDirty();
899 break;
900 }
901 }
902 }
903
904 void OnDragDrop_Vehicle(Point pt, WidgetID widget)
905 {
906 switch (widget) {
907 case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
908 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{});
909
910 this->vehicle_sel = VehicleID::Invalid();
911 this->group_over = GroupID::Invalid();
912
913 this->SetDirty();
914 break;
915
916 case WID_GL_LIST_GROUP: { // Matrix group
917 const VehicleID vindex = this->vehicle_sel;
918 this->vehicle_sel = VehicleID::Invalid();
919 this->group_over = GroupID::Invalid();
920 this->SetDirty();
921
922 auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
923 GroupID new_g = it == this->groups.end() ? NEW_GROUP : it->group->index;
924
925 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{});
926 break;
927 }
928
929 case WID_GL_LIST_VEHICLE: { // Matrix vehicle
930 const VehicleID vindex = this->vehicle_sel;
931 this->vehicle_sel = VehicleID::Invalid();
932 this->group_over = GroupID::Invalid();
933 this->SetDirty();
934
935 auto it = this->vscroll->GetScrolledItemFromWidget(this->vehgroups, pt.y, this, WID_GL_LIST_VEHICLE);
936 if (it == this->vehgroups.end()) return; // click out of list bound
937
938 const GUIVehicleGroup &vehgroup = *it;
939 switch (this->grouping) {
940 case GB_NONE: {
941 const Vehicle *v = vehgroup.GetSingleVehicle();
942 if (!VehicleClicked(v) && vindex == v->index) {
944 }
945 break;
946 }
947
948 case GB_SHARED_ORDERS: {
949 if (!VehicleClicked(vehgroup)) {
950 const Vehicle *v = vehgroup.vehicles_begin[0];
951 if (vindex == v->index) {
952 if (vehgroup.NumVehicles() == 1) {
954 } else {
955 ShowVehicleListWindow(v);
956 }
957 }
958 }
959 break;
960 }
961
962 default:
963 NOT_REACHED();
964 }
965 break;
966 }
967 }
968 }
969
970 void OnDragDrop(Point pt, WidgetID widget) override
971 {
972 if (this->vehicle_sel != VehicleID::Invalid()) OnDragDrop_Vehicle(pt, widget);
973 if (this->group_sel != GroupID::Invalid()) OnDragDrop_Group(pt, widget);
974
975 _cursor.vehchain = false;
976 }
977
978 void OnQueryTextFinished(std::optional<std::string> str) override
979 {
980 if (str.has_value()) Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_RENAME, AlterGroupMode::Rename, this->group_rename, GroupID::Invalid(), *str);
981 this->group_rename = GroupID::Invalid();
982 }
983
984 void OnResize() override
985 {
986 this->group_sb->SetCapacityFromWidget(this, WID_GL_LIST_GROUP);
987 this->vscroll->SetCapacityFromWidget(this, WID_GL_LIST_VEHICLE);
988 }
989
990 void OnDropdownSelect(WidgetID widget, int index, int) override
991 {
992 switch (widget) {
994 this->UpdateVehicleGroupBy(static_cast<GroupBy>(index));
995 break;
996
998 this->vehgroups.SetSortType(index);
999 break;
1000
1001 case WID_GL_FILTER_BY_CARGO: // Select a cargo filter criteria
1002 this->SetCargoFilter(index);
1003 break;
1004
1006 assert(!this->vehicles.empty());
1007
1008 switch (index) {
1009 case ADI_REPLACE: // Replace window
1010 ShowReplaceGroupVehicleWindow(this->vli.ToGroupID(), this->vli.vtype);
1011 break;
1012 case ADI_SERVICE: // Send for servicing
1013 case ADI_DEPOT: { // Send to Depots
1014 Command<CMD_SEND_VEHICLE_TO_DEPOT>::Post(GetCmdSendToDepotMsg(this->vli.vtype), VehicleID::Invalid(), (index == ADI_SERVICE ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::MassSend, this->vli);
1015 break;
1016 }
1017
1018 case ADI_CREATE_GROUP: // Create group
1019 Command<CMD_ADD_VEHICLE_GROUP>::Post(CcAddVehicleNewGroup, NEW_GROUP, VehicleID::Invalid(), false, this->vli);
1020 break;
1021
1022 case ADI_ADD_SHARED: // Add shared Vehicles
1023 assert(Group::IsValidID(this->vli.ToGroupID()));
1024
1025 Command<CMD_ADD_SHARED_VEHICLE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_ADD_SHARED_VEHICLE, this->vli.ToGroupID(), this->vli.vtype);
1026 break;
1027 case ADI_REMOVE_ALL: // Remove all Vehicles from the selected group
1028 assert(Group::IsValidID(this->vli.ToGroupID()));
1029
1030 Command<CMD_REMOVE_ALL_VEHICLES_GROUP>::Post(STR_ERROR_GROUP_CAN_T_REMOVE_ALL_VEHICLES, this->vli.ToGroupID());
1031 break;
1032 default: NOT_REACHED();
1033 }
1034 break;
1035
1036 default: NOT_REACHED();
1037 }
1038
1039 this->SetDirty();
1040 }
1041
1042 void OnGameTick() override
1043 {
1044 if (this->groups.NeedResort() || this->vehgroups.NeedResort()) {
1045 this->SetDirty();
1046 }
1047 }
1048
1049 void OnPlaceObjectAbort() override
1050 {
1051 /* abort drag & drop */
1052 this->vehicle_sel = VehicleID::Invalid();
1054 this->group_sel = GroupID::Invalid();
1055 this->group_over = GroupID::Invalid();
1057 }
1058
1059 void OnMouseDrag(Point pt, WidgetID widget) override
1060 {
1061 if (this->vehicle_sel == VehicleID::Invalid() && this->group_sel == GroupID::Invalid()) return;
1062
1063 /* A vehicle is dragged over... */
1064 GroupID new_group_over = GroupID::Invalid();
1065 switch (widget) {
1066 case WID_GL_DEFAULT_VEHICLES: // ... the 'default' group.
1067 new_group_over = DEFAULT_GROUP;
1068 break;
1069
1070 case WID_GL_LIST_GROUP: { // ... the list of custom groups.
1071 auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
1072 new_group_over = it == this->groups.end() ? NEW_GROUP : it->group->index;
1073 break;
1074 }
1075 }
1076
1077 /* Do not highlight when dragging over the current group */
1078 if (this->vehicle_sel != VehicleID::Invalid()) {
1079 if (Vehicle::Get(vehicle_sel)->group_id == new_group_over) new_group_over = GroupID::Invalid();
1080 } else if (this->group_sel != GroupID::Invalid()) {
1081 if (this->group_sel == new_group_over || Group::Get(this->group_sel)->parent == new_group_over) new_group_over = GroupID::Invalid();
1082 }
1083
1084 /* Mark widgets as dirty if the group changed. */
1085 if (new_group_over != this->group_over) {
1087 this->group_over = new_group_over;
1089 }
1090 }
1091
1092 void ShowRenameGroupWindow(GroupID group, bool empty)
1093 {
1094 assert(Group::IsValidID(group));
1095 this->group_rename = group;
1096
1097 /* Show empty query for new groups */
1098 std::string str;
1099 if (!empty) str = GetString(STR_GROUP_NAME, group);
1100
1102 }
1103
1110 {
1111 if (this->vehicle_sel == vehicle) ResetObjectToPlace();
1112 }
1113
1119 void SelectGroup(const GroupID g_id)
1120 {
1121 if (g_id == GroupID::Invalid() || g_id == this->vli.ToGroupID()) return;
1122
1123 this->vli.SetIndex(g_id);
1124 if (g_id != ALL_GROUP && g_id != DEFAULT_GROUP) {
1125 const Group *g = Group::Get(g_id);
1126
1127 auto found = std::ranges::find(this->groups, g, &GUIGroupListItem::group);
1128 if (found == std::end(this->groups)) {
1129 /* The group's branch is maybe collapsed, so try to expand it. */
1130 for (auto pg = Group::GetIfValid(g->parent); pg != nullptr; pg = Group::GetIfValid(pg->parent)) {
1131 pg->folded = false;
1132 }
1133 this->groups.ForceRebuild();
1134 this->BuildGroupList(this->owner);
1135 this->group_sb->SetCount(this->groups.size());
1136 found = std::ranges::find(this->groups, g, &GUIGroupListItem::group);
1137 }
1138 if (found != std::end(this->groups)) this->group_sb->ScrollTowards(std::distance(std::begin(this->groups), found));
1139 }
1140 this->vehgroups.ForceRebuild();
1141 this->SetDirty();
1142 }
1143
1144};
1145
1146static WindowDesc _vehicle_group_desc[] = {
1147 {
1148 WDP_AUTO, "list_groups_train", 525, 246,
1150 {},
1151 _nested_group_widgets
1152 },
1153 {
1154 WDP_AUTO, "list_groups_roadveh", 460, 246,
1156 {},
1157 _nested_group_widgets
1158 },
1159 {
1160 WDP_AUTO, "list_groups_ship", 460, 246,
1162 {},
1163 _nested_group_widgets
1164 },
1165 {
1166 WDP_AUTO, "list_groups_aircraft", 460, 246,
1168 {},
1169 _nested_group_widgets
1170 },
1171};
1172
1180template <bool Tneed_existing_window>
1181static void ShowCompanyGroupInternal(CompanyID company, VehicleType vehicle_type, GroupID group)
1182{
1183 if (!Company::IsValidID(company)) return;
1184
1185 assert(vehicle_type < std::size(_vehicle_group_desc));
1186 VehicleListIdentifier vli(VL_GROUP_LIST, vehicle_type, company);
1187 VehicleGroupWindow *w = AllocateWindowDescFront<VehicleGroupWindow, Tneed_existing_window>(_vehicle_group_desc[vehicle_type], vli.ToWindowNumber(), vli);
1188 if (w != nullptr) w->SelectGroup(group);
1189}
1190
1197void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group)
1198{
1199 ShowCompanyGroupInternal<false>(company, vehicle_type, group);
1200}
1201
1207{
1208 ShowCompanyGroupInternal<true>(v->owner, v->type, v->group_id);
1209}
1210
1218{
1219 return dynamic_cast<VehicleGroupWindow *>(FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).ToWindowNumber()));
1220}
1221
1226static void CcCreateGroup(GroupID gid, VehicleType veh_type)
1227{
1229 if (w != nullptr) w->ShowRenameGroupWindow(gid, true);
1230}
1231
1239void CcCreateGroup(Commands, const CommandCost &result, GroupID new_group, VehicleType vt, GroupID)
1240{
1241 if (result.Failed()) return;
1242
1243 assert(vt <= VEH_AIRCRAFT);
1244 CcCreateGroup(new_group, vt);
1245}
1246
1253{
1254 if (result.Failed()) return;
1255
1256 const Group *g = Group::Get(new_group);
1257 CcCreateGroup(new_group, g->vehicle_type);
1258}
1259
1265{
1266 /* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any group windows either
1267 * If that is the case, we can skip looping though the windows and save time
1268 */
1269 if (_special_mouse_mode != WSM_DRAGDROP) return;
1270
1272 if (w != nullptr) w->UnselectVehicle(v->index);
1273}
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
Functions related to the autoreplace GUIs.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T AssignBit(T &x, const uint8_t y, bool value)
Assigns a bit in a variable.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Common return value for all commands.
bool Failed() const
Did this command fail?
Enum-as-bit-set wrapper.
void RebuildDone()
Notify the sortlist that the rebuild is done.
bool IsDescSortOrder() const
Check if the sort order is descending.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
bool NeedRebuild() const
Check if a rebuild is needed.
void ForceRebuild()
Force that a rebuild is needed.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
uint8_t SortType() const
Get the sorttype of the list.
Listing GetListing() const
Export current sort conditions.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
uint current_x
Current horizontal size (after resizing).
int pos_x
Horizontal position of top-left corner of the widget in the window.
Base class for a 'real' widget.
Scrollbar data structure.
void SetCount(size_t num)
Sets the number of elements in the list.
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
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:2510
void ScrollTowards(size_type position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
size_type GetPosition() const
Gets the position of the first visible element in the list.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
void UnselectVehicle(VehicleID vehicle)
Tests whether a given vehicle is selected in the window, and unselects it if necessary.
void DirtyHighlightedGroupWidget()
Mark the widget containing the currently highlighted group as dirty.
GroupID group_sel
Selected group (for drag/drop)
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnDragDrop(Point pt, WidgetID widget) override
A dragged 'object' has been released.
GroupID group_rename
Group being renamed, GroupID::Invalid() if none.
void OnMouseDrag(Point pt, WidgetID widget) override
An 'object' is being dragged at the provided position, highlight the target if possible.
void BuildGroupList(Owner owner)
(Re)Build the group list.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
uint tiny_step_height
Step height for the group list.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnResize() override
Called after the window got resized.
void OnGameTick() override
Called once per (game) tick.
@ VGC_PROFIT
Profit icon.
@ VGC_AUTOREPLACE
Autoreplace active icon.
@ VGC_FOLD
Fold / Unfold button.
@ VGC_NAME
Group name.
@ VGC_PROTECT
Autoreplace protect icon.
@ VGC_NUMBER
Number of vehicles in the group.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
GroupID group_confirm
Group awaiting delete confirmation.
std::array< Dimension, VGC_END > column_size
Size of the columns in the group list.
GUIGroupList groups
List of groups.
GroupID group_over
Group over which a vehicle is dragged, GroupID::Invalid() if none.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
uint ComputeGroupInfoSize()
Compute tiny_step_height and column_size.
void DrawGroupInfo(int y, int left, int right, GroupID g_id, uint16_t level_mask=0, uint8_t indent=0, bool protection=false, bool has_children=false) const
Draw a row in the group list.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void SelectGroup(const GroupID g_id)
Selects the specified group in the list.
void OnPaint() override
The window must be repainted.
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:40
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
int hsep_wide
Wide horizontal spacing.
Definition window_gui.h:62
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:61
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition window_gui.h:38
int hsep_indent
Width of indentation for tree layouts.
Definition window_gui.h:63
Functions related to commands.
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
GUI Functions related to companies.
Some simple functions to help with accessing containers.
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition dropdown.cpp:451
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Definition dropdown.cpp:414
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
Definition dropdown.cpp:373
Functions related to the drop down widget.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:958
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:887
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
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
uint GetStringListWidth(std::span< const StringID > list, FontSize fontsize)
Get maximum width of a list of strings.
Definition gfx.cpp:910
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:115
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:1024
Functions related to the gfx engine.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ FS_SMALL
Index of the small font in the font tables.
Definition gfx_type.h:252
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:251
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:385
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition gfx_type.h:395
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:302
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition gfx_type.h:341
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...
@ ReplaceProtection
If set, the global autoreplace has no effect on the group.
bool IsAllGroupID(GroupID id_g)
Checks if a GroupID stands for all vehicles of a company.
Definition group.h:103
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.
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...
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Command definitions related to engine groups.
@ Rename
Change group name.
@ SetParent
Change group parent.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:955
void BuildGuiGroupList(GUIGroupList &list, bool fold, Owner owner, VehicleType veh_type)
Build GUI group list, a sorted hierarchical list of groups for owner and vehicle type.
void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group)
Show the group window for the given company and vehicle type.
void DeleteGroupHighlightOfVehicle(const Vehicle *v)
Removes the highlight of a vehicle in a group window.
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.
static VehicleGroupWindow * FindVehicleGroupWindow(VehicleType vt, Owner owner)
Finds a group list window determined by vehicle type and owner.
static void ShowCompanyGroupInternal(CompanyID company, VehicleType vehicle_type, GroupID group)
Show the group window for the given company and vehicle type.
static void GuiGroupListAddChildren(GUIGroupList &list, GUIGroupListItem &item, bool fold, uint8_t indent=1)
Add children to GUI group list to build a hierarchical tree.
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
static void CcCreateGroup(GroupID gid, VehicleType veh_type)
Opens a 'Rename group' window for newly created group.
Functions/definitions that have something to do with groups.
static constexpr GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Definition group_type.h:18
static constexpr GroupID ALL_GROUP
All vehicles are in this group.
Definition group_type.h:17
static constexpr GroupID NEW_GROUP
Sentinel for a to-be-created group.
Definition group_type.h:16
static const uint MAX_LENGTH_GROUP_NAME_CHARS
The maximum length of a group name in characters including '\0'.
Definition group_type.h:20
Types related to the group widgets.
@ WID_GL_LIST_GROUP
List of the groups.
@ WID_GL_STOP_ALL
Stop all button.
@ WID_GL_REPLACE_PROTECTION
Replace protection button.
@ WID_GL_MANAGE_VEHICLES_DROPDOWN
Manage vehicles dropdown list.
@ WID_GL_GROUP_BY_ORDER
Group order.
@ WID_GL_SORT_BY_ORDER
Sort order.
@ WID_GL_GROUP_BY_DROPDOWN
Group by dropdown list.
@ WID_GL_CAPTION
Caption of the window.
@ WID_GL_START_ALL
Start all button.
@ WID_GL_ALL_VEHICLES
All vehicles entry.
@ WID_GL_DELETE_GROUP
Delete group button.
@ WID_GL_AVAILABLE_VEHICLES
Available vehicles.
@ WID_GL_RENAME_GROUP
Rename group button.
@ WID_GL_LIST_VEHICLE_SCROLLBAR
Scrollbar for the list.
@ WID_GL_LIVERY_GROUP
Group livery button.
@ WID_GL_SORT_BY_DROPDOWN
Sort by dropdown list.
@ WID_GL_LIST_VEHICLE
List of the vehicles.
@ WID_GL_FILTER_BY_CARGO
Filter vehicles by cargo type.
@ WID_GL_CREATE_GROUP
Create group button.
@ WID_GL_LIST_GROUP_SCROLLBAR
Scrollbar for the list.
@ WID_GL_INFO
Group info.
@ WID_GL_DEFAULT_VEHICLES
Default vehicles entry.
GUI functions that shouldn't be here.
void ShowQuery(EncodedString &&caption, EncodedString &&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...
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Definition palette.cpp:388
A number of safeguards to prevent using unsafe methods.
This file contains all sprite-related enums and defines.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition sprites.h:1611
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition sprites.h:1396
Definition of base types and functions in a cross-platform compatible way.
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:425
Functions related to low-level strings.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition string_type.h:25
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
Get some number that is suitable for string size computations.
Definition strings.cpp:237
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:91
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:425
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:57
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
VehicleListIdentifier vli
Identifier of the vehicle list we want to currently show.
void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const
Draw all the vehicle list items.
VehicleID vehicle_sel
Selected vehicle.
Listing * sorting
Pointer to the vehicle type related sorting.
void SetCargoFilter(uint8_t index)
Set cargo filter for the vehicle group list.
GroupBy grouping
How we want to group the list.
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group, bool show_create)
Compute the size for the Action dropdown.
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group, bool show_create)
Display the Action dropdown window.
VehicleList vehicles
List of vehicles. This is the buffer for vehgroups to point into; if this is structurally modified,...
GUIVehicleGroupList vehgroups
List of (groups of) vehicles. This stores iterators of vehicles, and should be rebuilt if vehicles is...
DropDownList BuildCargoDropDownList(bool full) const
Build drop down list for cargo filter selection.
CargoType cargo_filter_criteria
Selected cargo filter index.
VehicleType type
Type of vehicle.
bool vehchain
vehicle chain is dragged
Definition gfx_type.h:151
Dimensions (a width and height) of a rectangle in 2D.
VehicleList::const_iterator vehicles_begin
Pointer to beginning element of this vehicle group.
Statistics and caches on the vehicles in a group.
Definition group.h:25
uint16_t num_vehicle
Number of vehicles.
Definition group.h:29
bool autoreplace_defined
Are any autoreplace rules set?
Definition group.h:31
static GroupStatistics & Get(CompanyID company, GroupID id_g, VehicleType type)
Returns the GroupStatistics for a specific group.
Definition group_cmd.cpp:73
bool autoreplace_finished
Have all autoreplacement finished?
Definition group.h:32
Group data.
Definition group.h:73
GroupFlags flags
Group flags.
Definition group.h:78
GroupID parent
Parent group.
Definition group.h:85
VehicleType vehicle_type
Vehicle type of the group.
Definition group.h:76
bool folded
NOSAVE: Is this group folded in the group view?
Definition group.h:83
uint16_t number
Per-company group number.
Definition group.h:86
Owner owner
Group Owner.
Definition group.h:75
FlatSet< GroupID > children
NOSAVE: child groups belonging to this group.
Definition group.h:82
Partial widget specification to allow NWidgets to be written nested.
Coordinates of a point in 2D.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * Get(auto index)
Returns Titem with given index.
Tindex index
Index of this pool item.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * GetIfValid(auto index)
Returns Titem with given index.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
uint step_height
Step-size of height resize changes.
Definition window_gui.h:212
The information about a vehicle list.
Definition vehiclelist.h:32
CompanyID company
The company associated with this list.
Definition vehiclelist.h:35
WindowNumber ToWindowNumber() const
Pack a VehicleListIdentifier in 32 bits so it can be used as unique WindowNumber.
VehicleType vtype
The vehicle type associated with this list.
Definition vehiclelist.h:34
Vehicle data structure.
GroupID group_id
Index of group Pool array.
Owner owner
Which company owns the vehicle?
High level window description.
Definition window_gui.h:167
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:273
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition widget.cpp:826
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1778
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:777
Window * parent
Parent window.
Definition window_gui.h:328
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:469
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:555
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:503
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition widget.cpp:809
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1064
ResizeInfo resize
Resize information.
Definition window_gui.h:314
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:515
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1768
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:316
int left
x position of left edge of the window
Definition window_gui.h:309
WindowFlags flags
Window flags.
Definition window_gui.h:300
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:312
int height
Height of the window (number of pixels down in y direction)
Definition window_gui.h:312
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:311
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:302
Stuff related to the text buffer GUI.
@ EnableDefault
enable the 'Default' button ("\0" is returned)
@ LengthIsInChars
the length of the string is counted in characters
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
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...
@ HT_DRAG
dragging items in the depot windows
Base class for all vehicles.
Command definitions for vehicles.
Functions related to vehicles.
static const Money VEHICLE_PROFIT_THRESHOLD
Threshold for a vehicle to be considered making good profit.
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
bool VehicleClicked(const Vehicle *v)
Dispatch a "vehicle selected" event if any window waits for it.
uint GetVehicleListHeight(VehicleType type, uint divisor)
Get the height of a vehicle in the vehicle list GUIs.
void SetMouseCursorVehicle(const Vehicle *v, EngineImageType image_type)
Set the mouse cursor to look like a vehicle.
bool ShowCargoIconOverlay()
Test if cargo icon overlays should be drawn.
Functions related to the vehicle's GUIs.
WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
Definition vehicle_gui.h:97
Functions/classes shared between the different vehicle list GUIs.
@ EIT_IN_LIST
Vehicle drawn in vehicle list, group list, ...
VehicleType
Available vehicle types.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_TRAIN
Train vehicle type.
@ MassSend
Tells that it's a mass send to depot command (type in VLW flag)
@ Service
The vehicle will leave the depot right after arrival (service only)
@ VL_GROUP_LIST
Index is the group.
Definition vehiclelist.h:27
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:67
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:45
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:58
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:51
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:56
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:53
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:77
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:69
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:61
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:60
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:57
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:62
@ EqualSize
Containers should keep all their (resizing) children equally large.
@ BigFirst
Allocate space to biggest resize first.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1194
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
Definition window.cpp:95
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1140
Window functions not directly related to making/drawing windows.
@ SBS_DOWN
Sort ascending.
Definition window_gui.h:218
@ SBS_UP
Sort descending.
Definition window_gui.h:219
@ WSM_DRAGDROP
Drag&drop an object.
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
int WidgetID
Widget ID.
Definition window_type.h:20
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47
@ WC_SHIPS_LIST
Ships list; Window numbers:
@ WC_TRAINS_LIST
Trains list; Window numbers:
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
@ WC_QUERY_STRING
Query string window; Window numbers:
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers: