18#include "table/strings.h"
27 std::array<std::vector<BadgeClassConfigItem>, GrfSpecFeature::GSF_END> features = {};
30 GSF_TRAINS, GSF_ROADVEHICLES, GSF_SHIPS, GSF_AIRCRAFT, GSF_STATIONS, GSF_HOUSES, GSF_OBJECTS, GSF_ROADSTOPS,
33 static inline const std::array<std::string_view, GrfSpecFeature::GSF_END> sections = {
35 "badges_roadvehicles",
68 assert(BadgeClassConfig::CONFIGURABLE_FEATURES.Test(feature));
78 for (
const GrfSpecFeature &feature : BadgeClassConfig::CONFIGURABLE_FEATURES) {
83 if (badge.
name == STR_NULL)
continue;
87 if (found != std::end(config))
continue;
90 config.emplace_back(badge.
label, 0,
true,
false);
101 assert(feature < GrfSpecFeature::GSF_END);
108 if (badge.
name == STR_NULL)
continue;
109 config.emplace_back(badge.
label, 0,
true,
false);
121 if (BadgeClassConfig::CONFIGURABLE_FEATURES.Test(feature)) {
124 if (found != std::end(config)) {
126 return {*found,
static_cast<int>(std::distance(std::begin(config), found))};
130 return {BadgeClassConfig::EMPTY_CONFIG_ITEM, 0};
140 assert(BadgeClassConfig::CONFIGURABLE_FEATURES.Test(feature));
141 assert(!BadgeClassConfig::sections[feature].empty());
147 if (group ==
nullptr)
return;
151 bool show_icon =
true;
152 bool show_filter =
false;
154 if (item.value.has_value() && !item.value.value().empty()) {
156 if (consumer.
ReadCharIf(
'?')) show_filter =
true;
157 if (consumer.
ReadCharIf(
'!')) show_icon =
false;
158 if (
auto value = consumer.
TryReadIntegerBase<
int>(10); value.has_value()) column = *value;
161 config.emplace_back(item.name, column, show_icon, show_filter);
171 for (
const GrfSpecFeature &feature : BadgeClassConfig::CONFIGURABLE_FEATURES) {
183 assert(BadgeClassConfig::CONFIGURABLE_FEATURES.Test(feature));
184 assert(!BadgeClassConfig::sections[feature].empty());
190 group.
CreateItem(item.label).
SetValue(fmt::format(
"{}{}{}", item.show_filter ?
"?" :
"", item.show_icon ?
"" :
"!", item.column));
200 for (
const GrfSpecFeature &feature : BadgeClassConfig::CONFIGURABLE_FEATURES) {
std::string label
Class label.
Global state for badge class configuration.
std::string label
Label of badge.
GrfSpecFeatures features
Bitmask of which features use this badge.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Parse data from a string / buffer.
bool ReadCharIf(char c)
Check whether the next 8-bit char matches 'c', and skip it.
std::optional< T > TryReadIntegerBase(int base, bool clamp=false)
Try to read and parse an integer in number 'base', and then advance the reader.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
Types related to reading/writing '*.ini' files.
Base for the NewGRF implementation.
Badge * GetBadge(BadgeID index)
Get a badge if it exists.
std::span< const BadgeID > GetClassBadges()
Get a read-only view of class badge index.
Functions related to NewGRF badges.
void AddBadgeClassesToConfiguration()
Add current badge classes to user configuration.
void ResetBadgeClassConfiguration(GrfSpecFeature feature)
Reset badge class configuration for a feature.
static void BadgeClassSaveConfigFeature(IniFile &ini, GrfSpecFeature feature)
Save badge column preferences.
static void BadgeClassLoadConfigFeature(const IniFile &ini, GrfSpecFeature feature)
Load badge column preferences.
std::pair< const BadgeClassConfigItem &, int > GetBadgeClassConfigItem(GrfSpecFeature feature, std::string_view label)
Get configuration for a badge class.
void BadgeClassSaveConfig(IniFile &ini)
Save badge column preferences.
static BadgeClassConfig _badge_config
Static instance of badge class configuration state.
std::span< BadgeClassConfigItem > GetBadgeClassConfiguration(GrfSpecFeature feature)
Get the badge user configuration for a feature.
void BadgeClassLoadConfig(const IniFile &ini)
Load badge column preferences.
Functions related to NewGRF badge configuration.
Types related to NewGRF badges.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
Ini file that supports both loading and saving.
A group within an ini file.
void Clear()
Clear all items in the group.
IniItem & CreateItem(std::string_view name)
Create an item with the given name.
std::list< IniItem > items
all items in the group
A single "line" in an ini file.
void SetValue(std::string_view value)
Replace the current value with another value.
const IniGroup * GetGroup(std::string_view name) const
Get the group with the given name.
IniGroup & GetOrCreateGroup(std::string_view name)
Get the group with the given name, and if it doesn't exist create a new group.