OpenTTD Source: src/newgrf_badge_gui.cpp Source File

OpenTTD Source 15.3

newgrf_badge_gui.cpp
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
12#include "core/flatset_type.hpp"
13#include "dropdown_type.h"
14#include "dropdown_func.h"
15#include "newgrf.h"
16#include "newgrf_badge.h"
17#include "newgrf_badge_config.h"
18#include "newgrf_badge_gui.h"
19#include "newgrf_badge_type.h"
20#include "settings_gui.h"
21#include "strings_func.h"
22#include "timer/timer_game_calendar.h"
23#include "window_gui.h"
24#include "window_type.h"
25#include "zoom_func.h"
26
27#include "table/strings.h"
28
29#include "dropdown_common_type.h"
30
31#include "safeguards.h"
32
33static constexpr uint MAX_BADGE_HEIGHT = 12;
34static constexpr uint MAX_BADGE_WIDTH = MAX_BADGE_HEIGHT * 2;
35
42static Dimension GetBadgeMaximalDimension(BadgeClassID class_index, GrfSpecFeature feature)
43{
44 Dimension d = {0, MAX_BADGE_HEIGHT};
45
46 for (const auto &badge : GetBadges()) {
47 if (badge.class_index != class_index) continue;
48
49 PalSpriteID ps = GetBadgeSprite(badge, feature, std::nullopt, PAL_NONE);
50 if (ps.sprite == 0) continue;
51
52 d.width = std::max(d.width, GetSpriteSize(ps.sprite, nullptr, ZoomLevel::Normal).width);
53 if (d.width > MAX_BADGE_WIDTH) break;
54 }
55
56 d.width = std::min(d.width, MAX_BADGE_WIDTH);
57 return d;
58}
59
60static bool operator<(const GUIBadgeClasses::Element &a, const GUIBadgeClasses::Element &b)
61{
62 if (a.column_group != b.column_group) return a.column_group < b.column_group;
63 if (a.sort_order != b.sort_order) return a.sort_order < b.sort_order;
64 return a.label < b.label;
65}
66
71GUIBadgeClasses::GUIBadgeClasses(GrfSpecFeature feature) : UsedBadgeClasses(feature)
72{
73 /* Get list of classes used by feature. */
74 uint max_column = 0;
75 for (BadgeClassID class_index : this->Classes()) {
76 const Badge *class_badge = GetClassBadge(class_index);
77 if (class_badge->name == STR_NULL) continue;
78
79 Dimension size = GetBadgeMaximalDimension(class_index, feature);
80 if (size.width == 0) continue;
81
82 const auto [config, sort_order] = GetBadgeClassConfigItem(feature, class_badge->label);
83
84 this->gui_classes.emplace_back(class_index, config.column, config.show_icon, sort_order, size, class_badge->label);
85 if (size.width != 0 && config.show_icon) max_column = std::max(max_column, config.column);
86 }
87
88 std::sort(std::begin(this->gui_classes), std::end(this->gui_classes));
89
90 /* Determine total width of visible badge columns. */
91 this->column_widths.resize(max_column + 1);
92 for (const auto &el : this->gui_classes) {
93 if (!el.visible || el.size.width == 0) continue;
94 this->column_widths[el.column_group] += ScaleGUITrad(el.size.width) + WidgetDimensions::scaled.hsep_normal;
95 }
96
97 /* Replace trailing `hsep_normal` spacer with wider `hsep_wide` spacer. */
98 for (uint &badge_width : this->column_widths) {
99 if (badge_width == 0) continue;
100 badge_width = badge_width - WidgetDimensions::scaled.hsep_normal + WidgetDimensions::scaled.hsep_wide;
101 }
102}
103
108uint GUIBadgeClasses::GetTotalColumnsWidth() const
109{
110 return std::accumulate(std::begin(this->column_widths), std::end(this->column_widths), 0U);
111}
112
120 int DrawBadgeNameList(Rect r, std::span<const BadgeID> badges, GrfSpecFeature)
121{
122 if (badges.empty()) return r.top;
123
124 FlatSet<BadgeClassID> class_indexes;
125 for (const BadgeID &index : badges) class_indexes.insert(GetBadge(index)->class_index);
126
127 std::string_view list_separator = GetListSeparator();
128 for (const BadgeClassID &class_index : class_indexes) {
129 const Badge *class_badge = GetClassBadge(class_index);
130 if (class_badge == nullptr || class_badge->name == STR_NULL) continue;
131
132 std::string s;
133 for (const BadgeID &index : badges) {
134 const Badge *badge = GetBadge(index);
135 if (badge == nullptr || badge->name == STR_NULL) continue;
136 if (badge->class_index != class_index) continue;
137 if (badge->flags.Test(BadgeFlag::NameListSkip)) continue;
138
139 if (!s.empty()) {
140 if (badge->flags.Test(BadgeFlag::NameListFirstOnly)) continue;
141 s += list_separator;
142 }
143 AppendStringInPlace(s, badge->name);
144 if (badge->flags.Test(BadgeFlag::NameListStop)) break;
145 }
146
147 if (s.empty()) continue;
148
149 r.top = DrawStringMultiLine(r, GetString(STR_BADGE_NAME_LIST, class_badge->name, std::move(s)), TC_BLACK);
150 }
151
152 return r.top;
153}
154
165 void DrawBadgeColumn(Rect r, int column_group, const GUIBadgeClasses &gui_classes, std::span<const BadgeID> badges, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, PaletteID remap)
166{
167 bool rtl = _current_text_dir == TD_RTL;
168 for (const auto &gc : gui_classes.GetClasses()) {
169 if (gc.column_group != column_group) continue;
170 if (!gc.visible) continue;
171
172 int width = ScaleGUITrad(gc.size.width);
173 for (const BadgeID &index : badges) {
174 const Badge &badge = *GetBadge(index);
175 if (badge.class_index != gc.class_index) continue;
176
177 PalSpriteID ps = GetBadgeSprite(badge, feature, introduction_date, remap);
178 if (ps.sprite == 0) continue;
179
180 DrawSpriteIgnorePadding(ps.sprite, ps.pal, r.WithWidth(width, rtl), SA_CENTER);
181 break;
182 }
183
184 r = r.Indent(width + WidgetDimensions::scaled.hsep_normal, rtl);
185 }
186}
187
189template <class TBase, bool TEnd = true, FontSize TFs = FS_NORMAL>
190 class DropDownBadges : public TBase {
191public:
192 template <typename... Args>
193 explicit DropDownBadges(const std::shared_ptr<GUIBadgeClasses> &gui_classes, std::span<const BadgeID> badges, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, Args &&...args) :
194 TBase(std::forward<Args>(args)...), gui_classes(gui_classes), badges(badges), feature(feature), introduction_date(introduction_date)
195 {
196 for (const auto &gc : gui_classes->GetClasses()) {
197 if (gc.column_group != 0) continue;
198 dim.width += ScaleGUITrad(gc.size.width) + WidgetDimensions::scaled.hsep_normal;
199 dim.height = std::max<uint>(dim.height, ScaleGUITrad(gc.size.height));
200 }
201
202 /* Remove trailing `hsep_normal` spacer. */
203 if (dim.width > 0) dim.width -= WidgetDimensions::scaled.hsep_normal;
204 }
205
206 uint Height() const override
207 {
208 return std::max<uint>(this->dim.height, this->TBase::Height());
209 }
210
211 uint Width() const override
212 {
213 if (this->dim.width == 0) return this->TBase::Width();
214 return this->dim.width + WidgetDimensions::scaled.hsep_normal + this->TBase::Width();
215 }
216
217 int OnClick(const Rect &r, const Point &pt) const override
218 {
219 if (this->dim.width == 0) {
220 return this->TBase::OnClick(r, pt);
221 } else {
222 bool rtl = TEnd ^ (_current_text_dir == TD_RTL);
223 return this->TBase::OnClick(r.Indent(this->dim.width + WidgetDimensions::scaled.hsep_normal, rtl), pt);
224 }
225 }
226
227 void Draw(const Rect &full, const Rect &r, bool sel, int click_result, Colours bg_colour) const override
228 {
229 if (this->dim.width == 0) {
230 this->TBase::Draw(full, r, sel, click_result, bg_colour);
231 } else {
232 bool rtl = TEnd ^ (_current_text_dir == TD_RTL);
233 DrawBadgeColumn(r.WithWidth(this->dim.width, rtl), 0, *this->gui_classes, this->badges, this->feature, this->introduction_date, PAL_NONE);
234 this->TBase::Draw(full, r.Indent(this->dim.width + WidgetDimensions::scaled.hsep_normal, rtl), sel, click_result, bg_colour);
235 }
236 }
237
238private:
239 std::shared_ptr<GUIBadgeClasses> gui_classes;
240
241 const std::span<const BadgeID> badges;
242 const GrfSpecFeature feature;
243 const std::optional<TimerGameCalendar::Date> introduction_date;
244
245 Dimension dim{};
246};
247
248using DropDownListBadgeItem = DropDownBadges<DropDownString<DropDownSpacer<DropDownListStringItem, true>, FS_SMALL, true>>;
249using DropDownListBadgeIconItem = DropDownBadges<DropDownString<DropDownSpacer<DropDownListIconItem, true>, FS_SMALL, true>>;
250
251std::unique_ptr<DropDownListItem> MakeDropDownListBadgeItem(const std::shared_ptr<GUIBadgeClasses> &gui_classes, std::span<const BadgeID> badges, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, std::string &&str, int value, bool masked, bool shaded)
252{
253 return std::make_unique<DropDownListBadgeItem>(gui_classes, badges, feature, introduction_date, "", std::move(str), value, masked, shaded);
254}
255
256std::unique_ptr<DropDownListItem> MakeDropDownListBadgeItem(const std::shared_ptr<GUIBadgeClasses> &gui_classes, std::span<const BadgeID> badges, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, Money cost, std::string &&str, int value, bool masked, bool shaded)
257{
258 return std::make_unique<DropDownListBadgeItem>(gui_classes, badges, feature, introduction_date, GetString(STR_JUST_CURRENCY_SHORT, cost), std::move(str), value, masked, shaded);
259}
260
261std::unique_ptr<DropDownListItem> MakeDropDownListBadgeIconItem(const std::shared_ptr<GUIBadgeClasses> &gui_classes, std::span<const BadgeID> badges, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, Money cost, const Dimension &dim, SpriteID sprite, PaletteID palette, std::string &&str, int value, bool masked, bool shaded)
262{
263 return std::make_unique<DropDownListBadgeIconItem>(gui_classes, badges, feature, introduction_date, GetString(STR_JUST_CURRENCY_SHORT, cost), dim, sprite, palette, std::move(str), value, masked, shaded);
264}
265
269template <class TBase, bool TEnd = true, FontSize TFs = FS_NORMAL>
270 class DropDownMover : public TBase {
271public:
272 template <typename... Args>
273 explicit DropDownMover(int click_up, int click_down, Colours button_colour, Args &&...args)
274 : TBase(std::forward<Args>(args)...), click_up(click_up), click_down(click_down), button_colour(button_colour)
275 {
276 }
277
278 uint Height() const override
279 {
280 return std::max<uint>(SETTING_BUTTON_HEIGHT, this->TBase::Height());
281 }
282
283 uint Width() const override
284 {
285 return SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide + this->TBase::Width();
286 }
287
288 int OnClick(const Rect &r, const Point &pt) const override
289 {
290 bool rtl = (_current_text_dir == TD_RTL);
291 int w = SETTING_BUTTON_WIDTH;
292
293 Rect br = r.WithWidth(w, TEnd ^ rtl).CentreToHeight(SETTING_BUTTON_HEIGHT);
294 if (br.WithWidth(w / 2, rtl).Contains(pt)) return this->click_up;
295 if (br.WithWidth(w / 2, !rtl).Contains(pt)) return this->click_down;
296
297 return this->TBase::OnClick(r.Indent(w + WidgetDimensions::scaled.hsep_wide, TEnd ^ rtl), pt);
298 }
299
300 void Draw(const Rect &full, const Rect &r, bool sel, int click_result, Colours bg_colour) const override
301 {
302 bool rtl = (_current_text_dir == TD_RTL);
303 int w = SETTING_BUTTON_WIDTH;
304
305 int state = 0;
306 if (sel && click_result != 0) {
307 if (click_result == this->click_up) state = 1;
308 if (click_result == this->click_down) state = 2;
309 }
310
311 Rect br = r.WithWidth(w, TEnd ^ rtl).CentreToHeight(SETTING_BUTTON_HEIGHT);
312 DrawUpDownButtons(br.left, br.top, this->button_colour, state, this->click_up != 0, this->click_down != 0);
313
314 this->TBase::Draw(full, r.Indent(w + WidgetDimensions::scaled.hsep_wide, TEnd ^ rtl), sel, click_result, bg_colour);
315 }
316
317private:
318 int click_up;
319 int click_down;
320 Colours button_colour;
321};
322
323using DropDownListToggleMoverItem = DropDownMover<DropDownToggle<DropDownString<DropDownListItem>>>;
324using DropDownListToggleItem = DropDownToggle<DropDownString<DropDownListItem>>;
325
326enum BadgeClick : int {
327 BADGE_CLICK_NONE,
328 BADGE_CLICK_MOVE_UP,
329 BADGE_CLICK_MOVE_DOWN,
330 BADGE_CLICK_TOGGLE_ICON,
331 BADGE_CLICK_TOGGLE_FILTER,
332};
333
334 DropDownList BuildBadgeClassConfigurationList(const GUIBadgeClasses &gui_classes, uint columns, std::span<const StringID> column_separators, Colours bg_colour)
335{
336 DropDownList list;
337
338 list.push_back(MakeDropDownListStringItem(STR_BADGE_CONFIG_RESET, INT_MAX));
339 if (gui_classes.GetClasses().empty()) return list;
340 list.push_back(MakeDropDownListDividerItem());
341 list.push_back(std::make_unique<DropDownUnselectable<DropDownListStringItem>>(GetString(STR_BADGE_CONFIG_ICONS), -1));
342
343 const BadgeClassID front = gui_classes.GetClasses().front().class_index;
344 const BadgeClassID back = gui_classes.GetClasses().back().class_index;
345
346 for (uint i = 0; i < columns; ++i) {
347 for (const auto &gc : gui_classes.GetClasses()) {
348 if (gc.column_group != i) continue;
349 if (gc.size.width == 0) continue;
350
351 bool first = (i == 0 && gc.class_index == front);
352 bool last = (i == columns - 1 && gc.class_index == back);
353 list.push_back(std::make_unique<DropDownListToggleMoverItem>(first ? 0 : BADGE_CLICK_MOVE_UP, last ? 0 : BADGE_CLICK_MOVE_DOWN, COLOUR_YELLOW, gc.visible, BADGE_CLICK_TOGGLE_ICON, COLOUR_YELLOW, bg_colour, GetString(GetClassBadge(gc.class_index)->name), gc.class_index.base()));
354 }
355
356 if (i >= column_separators.size()) continue;
357
358 if (column_separators[i] == STR_NULL) {
359 list.push_back(MakeDropDownListDividerItem());
360 } else {
361 list.push_back(MakeDropDownListStringItem(column_separators[i], INT_MIN + i, false, true));
362 }
363 }
364
365 list.push_back(MakeDropDownListDividerItem());
366 list.push_back(std::make_unique<DropDownUnselectable<DropDownListStringItem>>(GetString(STR_BADGE_CONFIG_FILTERS), -1));
367
368 for (const BadgeClassID &badge_class_index : gui_classes.Classes()) {
369 const Badge *badge = GetClassBadge(badge_class_index);
370 if (!badge->flags.Test(BadgeFlag::HasText)) continue;
371
372 const auto [config, _] = GetBadgeClassConfigItem(gui_classes.GetFeature(), badge->label);
373 list.push_back(std::make_unique<DropDownListToggleItem>(config.show_filter, BADGE_CLICK_TOGGLE_FILTER, COLOUR_YELLOW, bg_colour, GetString(badge->name), badge_class_index.base()));
374 }
375
376 return list;
377}
378
385static void BadgeClassToggleVisibility(GrfSpecFeature feature, Badge &class_badge, int click_result, BadgeFilterChoices &choices)
386{
387 auto config = GetBadgeClassConfiguration(feature);
388 auto it = std::ranges::find(config, class_badge.label, &BadgeClassConfigItem::label);
389 if (it == std::end(config)) return;
390
391 if (click_result == BADGE_CLICK_TOGGLE_ICON) it->show_icon = !it->show_icon;
392 if (click_result == BADGE_CLICK_TOGGLE_FILTER) {
393 it->show_filter = !it->show_filter;
394 if (!it->show_filter) ResetBadgeFilter(choices, class_badge.class_index);
395 }
396}
397
403static void BadgeClassMovePrevious(GrfSpecFeature feature, Badge &class_badge)
404{
405 GUIBadgeClasses gui_classes(feature);
406 if (gui_classes.GetClasses().empty()) return;
407
408 auto config = GetBadgeClassConfiguration(feature);
409 auto it = std::ranges::find(config, class_badge.label, &BadgeClassConfigItem::label);
410 if (it == std::end(config)) return;
411
412 auto pos_cur = std::ranges::find(gui_classes.GetClasses(), class_badge.class_index, &GUIBadgeClasses::Element::class_index);
413 if (pos_cur == std::begin(gui_classes.GetClasses())) {
414 if (it->column > 0) --it->column;
415 return;
416 }
417
418 auto pos_prev = std::ranges::find(config, std::prev(pos_cur)->label, &BadgeClassConfigItem::label);
419 if (it->column > pos_prev->column) {
420 --it->column;
421 } else {
422 /* Rotate elements right so that it is placed before pos_prev, maintaining order of non-visible elements. */
423 std::rotate(pos_prev, it, std::next(it));
424 }
425}
426
433static void BadgeClassMoveNext(GrfSpecFeature feature, Badge &class_badge, uint columns)
434{
435 GUIBadgeClasses gui_classes(feature);
436 if (gui_classes.GetClasses().empty()) return;
437
438 auto config = GetBadgeClassConfiguration(feature);
439 auto it = std::ranges::find(config, class_badge.label, &BadgeClassConfigItem::label);
440 if (it == std::end(config)) return;
441
442 auto pos_cur = std::ranges::find(gui_classes.GetClasses(), class_badge.class_index, &GUIBadgeClasses::Element::class_index);
443 if (std::next(pos_cur) == std::end(gui_classes.GetClasses())) {
444 if (it->column < columns - 1) ++it->column;
445 return;
446 }
447
448 auto pos_next = std::ranges::find(config, std::next(pos_cur)->label, &BadgeClassConfigItem::label);
449 if (it->column < pos_next->column) {
450 ++it->column;
451 } else {
452 /* Rotate elements left so that it is placed after pos_next, maintaining order of non-visible elements. */
453 std::rotate(it, std::next(it), std::next(pos_next));
454 }
455}
456
465 bool HandleBadgeConfigurationDropDownClick(GrfSpecFeature feature, uint columns, int result, int click_result, BadgeFilterChoices &choices)
466{
467 if (result == INT_MAX) {
468 ResetBadgeClassConfiguration(feature);
469 return true;
470 }
471
472 Badge *class_badge = GetClassBadge(static_cast<BadgeClassID>(result));
473 if (class_badge == nullptr) return false;
474
475 switch (click_result) {
476 case BADGE_CLICK_MOVE_DOWN: // Move down button.
477 BadgeClassMoveNext(feature, *class_badge, columns);
478 break;
479 case BADGE_CLICK_MOVE_UP: // Move up button.
480 BadgeClassMovePrevious(feature, *class_badge);
481 break;
482 case BADGE_CLICK_TOGGLE_ICON:
483 case BADGE_CLICK_TOGGLE_FILTER:
484 BadgeClassToggleVisibility(feature, *class_badge, click_result, choices);
485 break;
486 default:
487 break;
488 }
489
490 return true;
491}
492
493NWidgetBadgeFilter::NWidgetBadgeFilter(Colours colour, WidgetID index, GrfSpecFeature feature, BadgeClassID badge_class)
494 : NWidgetLeaf(WWT_DROPDOWN, colour, index, WidgetData{ .string = STR_JUST_STRING }, STR_NULL)
495 , feature(feature), badge_class(badge_class)
496{
497 this->SetFill(1, 0);
498 this->SetResize(1, 0);
499}
500
501std::string NWidgetBadgeFilter::GetStringParameter(const BadgeFilterChoices &choices) const
502{
503 auto it = choices.find(this->badge_class);
504 if (it == std::end(choices)) {
505 return ::GetString(STR_BADGE_FILTER_ANY_LABEL, GetClassBadge(this->badge_class)->name);
506 }
507
508 return ::GetString(STR_BADGE_FILTER_IS_LABEL, GetClassBadge(it->first)->name, GetBadge(it->second)->name);
509}
510
516 DropDownList NWidgetBadgeFilter::GetDropDownList(PaletteID palette) const
517{
518 DropDownList list;
519
520 /* Add item for disabling filtering. */
521 list.push_back(MakeDropDownListStringItem(::GetString(STR_BADGE_FILTER_ANY_LABEL, GetClassBadge(this->badge_class)->name), -1));
522 list.push_back(MakeDropDownListDividerItem());
523
524 /* Add badges */
525 Dimension d = GetBadgeMaximalDimension(this->badge_class, this->feature);
526 d.width = ScaleGUITrad(d.width);
527 d.height = ScaleGUITrad(d.height);
528
529 auto start = list.size();
530
531 const auto *bc = GetClassBadge(this->badge_class);
532
533 for (const Badge &badge : GetBadges()) {
534 if (badge.class_index != this->badge_class) continue;
535 if (badge.index == bc->index) continue;
536 if (badge.name == STR_NULL) continue;
537 if (!badge.features.Test(this->feature)) continue;
538
539 PalSpriteID ps = GetBadgeSprite(badge, this->feature, std::nullopt, palette);
540 if (ps.sprite == 0) {
541 list.push_back(MakeDropDownListStringItem(badge.name, badge.index.base()));
542 } else {
543 list.push_back(MakeDropDownListIconItem(d, ps.sprite, ps.pal, badge.name, badge.index.base()));
544 }
545 }
546
547 std::sort(std::begin(list) + start, std::end(list), DropDownListStringItem::NatSortFunc);
548
549 return list;
550}
551
561std::pair<WidgetID, WidgetID> AddBadgeDropdownFilters(Window *window, WidgetID container_id, WidgetID widget, Colours colour, GrfSpecFeature feature)
562{
563 auto container = window->GetWidget<NWidgetContainer>(container_id);
564 container->Clear(window);
565 WidgetID first = ++widget;
566
567 /* Get list of classes used by feature. */
568 UsedBadgeClasses used(feature);
569
570 for (BadgeClassID class_index : used.Classes()) {
571 const auto [config, _] = GetBadgeClassConfigItem(feature, GetClassBadge(class_index)->label);
572 if (!config.show_filter) continue;
573
574 container->Add(std::make_unique<NWidgetBadgeFilter>(colour, widget, feature, class_index));
575 ++widget;
576 }
577
578 return {first, widget};
579}
580
586 void ResetBadgeFilter(BadgeFilterChoices &choices, BadgeClassID badge_class_index)
587{
588 choices.erase(badge_class_index);
589}
590
597 void SetBadgeFilter(BadgeFilterChoices &choices, BadgeID badge_index)
598{
599 const Badge *badge = GetBadge(badge_index);
600 assert(badge != nullptr);
601
602 choices[badge->class_index] = badge_index;
603}
BadgeClassConfigItem::label
std::string label
Class label.
Definition newgrf_badge_config.h:18
Badge
Definition newgrf_badge.h:20
Badge::class_index
BadgeClassID class_index
Index of class this badge belongs to.
Definition newgrf_badge.h:24
Badge::label
std::string label
Label of badge.
Definition newgrf_badge.h:22
Badge::index
BadgeID index
Index assigned to badge.
Definition newgrf_badge.h:23
Badge::flags
BadgeFlags flags
Display flags.
Definition newgrf_badge.h:25
Badge::features
GrfSpecFeatures features
Bitmask of which features use this badge.
Definition newgrf_badge.h:27
Badge::name
StringID name
Short name.
Definition newgrf_badge.h:26
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
DropDownBadges
Drop down element that draws a list of badges.
Definition newgrf_badge_gui.cpp:190
DropDownMover
Drop down component that shows extra buttons to indicate that the item can be moved up or down.
Definition newgrf_badge_gui.cpp:270
DropDownMover::click_down
int click_down
Click result for down button. Button is inactive if 0.
Definition newgrf_badge_gui.cpp:319
DropDownMover::button_colour
Colours button_colour
Colour of buttons.
Definition newgrf_badge_gui.cpp:320
DropDownMover::click_up
int click_up
Click result for up button. Button is inactive if 0.
Definition newgrf_badge_gui.cpp:318
DropDownString< DropDownListItem >::NatSortFunc
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Natural sorting comparator function for DropDownList::sort().
Definition dropdown_common_type.h:99
DropDownToggle
Drop down boolean toggle component.
Definition dropdown_common_type.h:192
DropDownUnselectable
Drop down component that makes the item unselectable.
Definition dropdown_common_type.h:294
FlatSet
Flat set implementation that uses a sorted vector for storage.
Definition flatset_type.hpp:20
FlatSet::insert
std::pair< const_iterator, bool > insert(const Tkey &key)
Insert a key into the set, if it does not already exist.
Definition flatset_type.hpp:31
GUIBadgeClasses
Definition newgrf_badge_gui.h:19
GUIBadgeClasses::GetTotalColumnsWidth
uint GetTotalColumnsWidth() const
Get total width of all columns.
Definition newgrf_badge_gui.cpp:108
NWidgetBadgeFilter::badge_class
BadgeClassID badge_class
Badge class of this dropdown.
Definition newgrf_badge_gui.h:72
NWidgetBadgeFilter::GetDropDownList
DropDownList GetDropDownList(PaletteID palette=PAL_NONE) const
Get the drop down list of badges for this filter.
Definition newgrf_badge_gui.cpp:516
NWidgetContainer
Baseclass for container widgets.
Definition widget_type.h:474
NWidgetContainer::Clear
void Clear(Window *parent_window)
Clears the container, deleting all widgets that were contained.
Definition widget_type.h:495
NWidgetCore::GetString
StringID GetString() const
Get the string that has been set for this nested widget.
Definition widget.cpp:1279
NWidgetLeaf
Leaf widget.
Definition widget_type.h:931
OverflowSafeInt< int64_t >
UsedBadgeClasses
Utility class to create a list of badge classes used by a feature.
Definition newgrf_badge.h:34
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::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:61
dropdown_common_type.h
Common drop down list components.
dropdown_func.h
Functions related to the drop down widget.
dropdown_type.h
Types related to the drop down widget.
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition dropdown_type.h:56
flatset_type.hpp
Flat set container implementation.
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:968
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:785
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
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1222
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1148
newgrf.h
Base for the NewGRF implementation.
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
GetBadge
Badge * GetBadge(BadgeID index)
Get a badge if it exists.
Definition newgrf_badge.cpp:113
GetBadges
std::span< const Badge > GetBadges()
Get a read-only view of badges.
Definition newgrf_badge.cpp:40
GetBadgeSprite
PalSpriteID GetBadgeSprite(const Badge &badge, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, PaletteID remap)
Get sprite for the given badge.
Definition newgrf_badge.cpp:285
GetClassBadge
Badge * GetClassBadge(BadgeClassID class_index)
Get the badge for a badge class index.
Definition newgrf_badge.cpp:137
newgrf_badge.h
Functions related to NewGRF badges.
ResetBadgeClassConfiguration
void ResetBadgeClassConfiguration(GrfSpecFeature feature)
Reset badge class configuration for a feature.
Definition newgrf_badge_config.cpp:99
GetBadgeClassConfigItem
std::pair< const BadgeClassConfigItem &, int > GetBadgeClassConfigItem(GrfSpecFeature feature, std::string_view label)
Get configuration for a badge class.
Definition newgrf_badge_config.cpp:119
GetBadgeClassConfiguration
std::span< BadgeClassConfigItem > GetBadgeClassConfiguration(GrfSpecFeature feature)
Get the badge user configuration for a feature.
Definition newgrf_badge_config.cpp:66
newgrf_badge_config.h
Functions related to NewGRF badge configuration.
newgrf_badge_gui.h
GUI functions related to NewGRF badges.
newgrf_badge_type.h
Types related to NewGRF badges.
BadgeFlag::NameListStop
@ NameListStop
Stop adding names to the name list after this badge.
BadgeFlag::NameListFirstOnly
@ NameListFirstOnly
Don't add this name to the name list if not first.
BadgeFlag::HasText
@ HasText
Internal flag set if the badge has text.
BadgeFlag::NameListSkip
@ NameListSkip
Don't show name in name list at all.
safeguards.h
A number of safeguards to prevent using unsafe methods.
DrawUpDownButtons
void DrawUpDownButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_up, bool clickable_down)
Draw [^][v] buttons.
Definition settings_gui.cpp:1898
settings_gui.h
Functions for setting GUIs.
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition settings_gui.h:17
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition settings_gui.h:19
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
GetListSeparator
std::string_view GetListSeparator()
Get the list separator string for the current language.
Definition strings.cpp:299
AppendStringInPlace
void AppendStringInPlace(std::string &result, StringID string)
Resolve the given StringID and append in place into an existing std::string with formatting but no pa...
Definition strings.cpp:434
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
strings_func.h
Functions related to OTTD's strings.
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:27
Coord2D< int >
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
GUIBadgeClasses::Element
Definition newgrf_badge_gui.h:21
GUIBadgeClasses::Element::sort_order
uint sort_order
Order of element.
Definition newgrf_badge_gui.h:25
GUIBadgeClasses::Element::label
std::string_view label
Class label (string owned by the class badge)
Definition newgrf_badge_gui.h:27
GUIBadgeClasses::Element::class_index
BadgeClassID class_index
Badge class index.
Definition newgrf_badge_gui.h:22
GUIBadgeClasses::Element::column_group
uint8_t column_group
Column group in UI. 0 = left, 1 = centre, 2 = right.
Definition newgrf_badge_gui.h:23
PalSpriteID
Combination of a palette sprite and a 'real' sprite.
Definition gfx_type.h:22
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:23
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition gfx_type.h:24
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::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::Contains
bool Contains(const Point &pt) const
Test if a point falls inside this Rect.
Definition geometry_type.hpp:249
StrongType::Typedef< uint32_t, struct BadgeClassIDTag, StrongType::Compare >
WidgetData
Container with the data associated to a single widget.
Definition widget_type.h:358
Window
Data structure for an opened window.
Definition window_gui.h:274
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:983
Height
int16_t Height
Fixed point type for heights.
Definition tgp.cpp:153
timer_game_calendar.h
Definition of the game-calendar-timer.
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:49
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
window_gui.h
Functions, definitions and such used only by the GUI.
window_type.h
Types related to windows.
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
zoom_func.h
Functions related to zooming.
ZoomLevel::Normal
@ Normal
The normal zoom level.