OpenTTD Source 20250714-master-g67e56391c7
newgrf_badge_gui.h
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef NEWGRF_BADGE_GUI_H
11#define NEWGRF_BADGE_GUI_H
12
13#include "dropdown_type.h"
14#include "newgrf.h"
15#include "newgrf_badge.h"
16#include "newgrf_badge_type.h"
18
20public:
21 struct Element {
23 uint8_t column_group;
24 bool visible;
27 std::string_view label;
28 };
29
30 GUIBadgeClasses() = default;
31 explicit GUIBadgeClasses(GrfSpecFeature feature);
32
33 inline std::span<const Element> GetClasses() const
34 {
35 return this->gui_classes;
36 }
37
38 inline std::span<const uint> GetColumnWidths() const
39 {
40 return this->column_widths;
41 }
42
43 uint GetTotalColumnsWidth() const;
44
45private:
46 std::vector<Element> gui_classes{};
47 std::vector<uint> column_widths{};
48};
49
50int DrawBadgeNameList(Rect r, std::span<const BadgeID> badges, GrfSpecFeature feature);
51void 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);
52
53std::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 = false, bool shaded = false);
54std::unique_ptr<DropDownListItem> MakeDropDownListBadgeIconItem(const std::shared_ptr<GUIBadgeClasses> &gui_classes, std::span<const BadgeID> badges, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, const Dimension &dim, SpriteID sprite, PaletteID palette, std::string &&str, int value, bool masked = false, bool shaded = false);
55
56DropDownList BuildBadgeClassConfigurationList(const class GUIBadgeClasses &badge_class, uint columns, std::span<const StringID> column_separators);
57bool HandleBadgeConfigurationDropDownClick(GrfSpecFeature feature, uint columns, int result, int click_result, BadgeFilterChoices &choices);
58
59std::pair<WidgetID, WidgetID> AddBadgeDropdownFilters(NWidgetContainer &container, WidgetID widget, Colours colour, GrfSpecFeature feature);
60
62public:
64
65 BadgeClassID GetBadgeClassID() const { return this->badge_class; }
66 std::string GetStringParameter(const BadgeFilterChoices &choices) const;
68
69private:
72};
73
74void ResetBadgeFilter(BadgeFilterChoices &choices, BadgeClassID badge_class_index);
75void SetBadgeFilter(BadgeFilterChoices &choices, BadgeID badge_index);
76
77#endif /* NEWGRF_BADGE_GUI_H */
uint GetTotalColumnsWidth() const
Get total width of all columns.
DropDownList GetDropDownList() const
Get the drop down list of badges for this filter.
BadgeClassID badge_class
Badge class of this dropdown.
GrfSpecFeature feature
Feature of this dropdown.
const WidgetID index
Index of the nested widget (-1 means 'not used').
Baseclass for container widgets.
Colours colour
Colour of this widget.
Leaf widget.
Utility class to create a list of badge classes used by a feature.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
Base for the NewGRF implementation.
GrfSpecFeature
Definition newgrf.h:69
Functions related to NewGRF badges.
Types related to NewGRF badges.
Dimensions (a width and height) of a rectangle in 2D.
Dimension size
Maximal size of this element.
uint sort_order
Order of element.
std::string_view label
Class label (string owned by the class badge)
BadgeClassID class_index
Badge class index.
bool visible
Whether the icon is visible.
uint8_t column_group
Column group in UI. 0 = left, 1 = centre, 2 = right.
Specification of a rectangle with absolute coordinates of all edges.
Definition of the game-calendar-timer.
int WidgetID
Widget ID.
Definition window_type.h:20