OpenTTD Source 20250220-master-gf89924a727
newgrf_badge.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef NEWGRF_BADGE_H
11#define NEWGRF_BADGE_H
12
13#include "dropdown_type.h"
14#include "newgrf.h"
15#include "newgrf_badge_type.h"
16#include "newgrf_commons.h"
17#include "strings_type.h"
19
32
33void ResetBadges();
34
35Badge &GetOrCreateBadge(std::string_view label);
36void MarkBadgeSeen(BadgeID index, GrfSpecFeature feature);
37void AppendCopyableBadgeList(std::vector<BadgeID> &dst, std::span<const BadgeID> src, GrfSpecFeature feature);
39
40Badge *GetBadge(BadgeID index);
41Badge *GetBadgeByLabel(std::string_view label);
42Badge *GetClassBadge(BadgeClassID class_index);
43
45public:
57
58 GUIBadgeClasses() = default;
59 explicit GUIBadgeClasses(GrfSpecFeature feature);
60
61 inline std::span<const Element> GetClasses() const { return this->gui_classes; }
62
63 inline std::span<const uint> GetColumnWidths() const { return this->column_widths; }
64
65 uint GetTotalColumnsWidth() const;
66
67private:
68 std::vector<Element> gui_classes{};
69 std::vector<uint> column_widths{};
70};
71
72int DrawBadgeNameList(Rect r, std::span<const BadgeID> badges, GrfSpecFeature feature);
73void DrawBadgeColumn(Rect r, int column_group, const GUIBadgeClasses &badge_classes, std::span<const BadgeID> badges, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, PaletteID remap);
74
75uint32_t GetBadgeVariableResult(const struct GRFFile &grffile, std::span<const BadgeID> badges, uint32_t parameter);
76
78public:
79 BadgeTextFilter(struct StringFilter &filter, GrfSpecFeature feature);
80 bool Filter(std::span<const BadgeID> badges) const;
81
82private:
83 std::vector<BadgeID> badges{};
84};
85
86std::unique_ptr<DropDownListItem> MakeDropDownListBadgeItem(const std::shared_ptr<GUIBadgeClasses> &gui_classes, std::span<const BadgeID> badges, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, StringID str, int value, bool masked = false, bool shaded = false);
87std::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, StringID str, int value, bool masked = false, bool shaded = false);
88
89#endif /* NEWGRF_BADGE_H */
VariableGRFFileProps grf_prop
Sprite information.
BadgeClassID class_index
Index of class this badge belongs to.
std::string label
Label of badge.
BadgeID index
Index assigned to badge.
BadgeFlags flags
Display flags.
GrfSpecFeatures features
Bitmask of which features use this badge.
StringID name
Short name.
uint GetTotalColumnsWidth() const
Get total width of all columns.
Types related to the drop down widget.
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
uint32_t GetBadgeVariableResult(const GRFFile &grffile, std::span< const BadgeID > badges, uint32_t parameter)
Test for a matching badge in a list of badges, returning the number of matching bits.
Badge * GetBadge(BadgeID index)
Get a badge if it exists.
void ApplyBadgeFeaturesToClassBadges()
Apply features from all badges to their badge classes.
void MarkBadgeSeen(BadgeID index, GrfSpecFeature feature)
Mark a badge a seen (used) by a feature.
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature feature)
Draw names for a list of badge labels.
void AppendCopyableBadgeList(std::vector< BadgeID > &dst, std::span< const BadgeID > src, GrfSpecFeature feature)
Append copyable badges from a list onto another.
Badge * GetClassBadge(BadgeClassID class_index)
Get the badge class of a badge label.
Badge & GetOrCreateBadge(std::string_view label)
Register a badge label and return its global index.
Badge * GetBadgeByLabel(std::string_view label)
Get a badge by label if it exists.
void DrawBadgeColumn(Rect r, int column_group, const GUIBadgeClasses &badge_classes, std::span< const BadgeID > badges, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, PaletteID remap)
Draw a badge column group.
void ResetBadges()
Reset badges to the default state.
Types related to NewGRF badges.
This file simplyfies and embeds a common mechanism of loading/saving and mapping of grf entities.
@ Filter
filter disabled/enabled
Types related to strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Dimensions (a width and height) of a rectangle in 2D.
Dynamic data of a loaded NewGRF.
Definition newgrf.h:112
Dimension size
Maximal size of this element.
uint sort_order
Order of element.
BadgeClassID badge_class
Badge class index.
std::string_view label
Class label (string owned by the class badge)
bool visible
Whether this element 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.
String filter and state.
Variable-length list of sprite groups for an entity.
Definition of the game-calendar-timer.