OpenTTD Source: src/group_gui.cpp Source File

OpenTTD Source 15.3

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