|
OpenTTD Source 15.0-beta2
|
Functionality for NewGRF badges. More...
#include "stdafx.h"#include "dropdown_type.h"#include "newgrf.h"#include "newgrf_badge.h"#include "newgrf_badge_type.h"#include "newgrf_spritegroup.h"#include "stringfilter_type.h"#include "strings_func.h"#include "timer/timer_game_calendar.h"#include "window_gui.h"#include "zoom_func.h"#include "table/strings.h"#include "dropdown_common_type.h"#include "safeguards.h"Go to the source code of this file.
Data Structures | |
| class | Badges |
| Global state for badge definitions. More... | |
| struct | BadgeScopeResolver |
| Resolver for a badge scope. More... | |
| struct | BadgeResolverObject |
| Resolver of badges. More... | |
| class | UsedBadgeClasses |
| Utility class to create a list of badge classes used by a feature. More... | |
| class | DropDownBadges< TBase, TEnd, TFs > |
| Drop down element that draws a list of badges. More... | |
Typedefs | |
| using | DropDownListBadgeItem = DropDownBadges< DropDownListStringItem > |
| using | DropDownListBadgeIconItem = DropDownBadges< DropDownListIconItem > |
Functions | |
| static BadgeClassID | GetOrCreateBadgeClass (BadgeID index) |
| Assign a BadgeClassID to the given badge. | |
| void | ResetBadges () |
| Reset badges to the default state. | |
| Badge & | GetOrCreateBadge (std::string_view label) |
| Register a badge label and return its global index. | |
| Badge * | GetBadge (BadgeID index) |
| Get a badge if it exists. | |
| Badge * | GetBadgeByLabel (std::string_view label) |
| Get a badge by label if it exists. | |
| Badge * | GetClassBadge (BadgeClassID class_index) |
| Get the badge class of a badge label. | |
| 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. | |
| void | MarkBadgeSeen (BadgeID index, GrfSpecFeature feature) |
| Mark a badge a seen (used) by a feature. | |
| void | AppendCopyableBadgeList (std::vector< BadgeID > &dst, std::span< const BadgeID > src, GrfSpecFeature feature) |
| Append copyable badges from a list onto another. | |
| void | ApplyBadgeFeaturesToClassBadges () |
| Apply features from all badges to their badge classes. | |
| static PalSpriteID | GetBadgeSprite (const Badge &badge, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, PaletteID remap) |
| Get sprite for the given badge. | |
| static Dimension | GetBadgeMaximalDimension (BadgeClassID class_index, GrfSpecFeature feature) |
| Get the largest badge size (within limits) for a badge class. | |
| static bool | operator< (const GUIBadgeClasses::Element &a, const GUIBadgeClasses::Element &b) |
| int | DrawBadgeNameList (Rect r, std::span< const BadgeID > badges, GrfSpecFeature) |
| Draw names for a list of badge labels. | |
| 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. | |
| std::unique_ptr< DropDownListItem > | MakeDropDownListBadgeItem (const std::shared_ptr< GUIBadgeClasses > &badge_classes, std::span< const BadgeID > badges, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, std::string &&str, int value, bool masked, bool shaded) |
| std::unique_ptr< DropDownListItem > | MakeDropDownListBadgeIconItem (const std::shared_ptr< GUIBadgeClasses > &badge_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, bool shaded) |
Variables | |
| static constexpr char | BADGE_CLASS_SEPARATOR = '/' |
| Separator to identify badge classes from a label. | |
| static Badges | _badges = {} |
| Static instance of badge state. | |
| static constexpr uint | MAX_BADGE_HEIGHT = 12 |
| Maximal height of a badge sprite. | |
| static constexpr uint | MAX_BADGE_WIDTH = MAX_BADGE_HEIGHT * 2 |
| Maximal width. | |
Functionality for NewGRF badges.
Definition in file newgrf_badge.cpp.
Definition at line 543 of file newgrf_badge.cpp.
Definition at line 542 of file newgrf_badge.cpp.
| void AppendCopyableBadgeList | ( | std::vector< BadgeID > & | dst, |
| std::span< const BadgeID > | src, | ||
| GrfSpecFeature | feature | ||
| ) |
Append copyable badges from a list onto another.
Badges must exist and be marked with the Copy flag.
| dst | Destination badge list. |
| src | Source badge list. |
| feature | Feature of list. |
Definition at line 238 of file newgrf_badge.cpp.
References Copy, Badge::features, Badge::flags, GetBadge(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
Referenced by FinaliseEngineArray().
| void ApplyBadgeFeaturesToClassBadges | ( | ) |
Apply features from all badges to their badge classes.
Definition at line 255 of file newgrf_badge.cpp.
References _badges, Badge::features, GetClassBadge(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), and Badges::specs.
Referenced by FinaliseBadges().
| 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.
| r | rect to draw within. |
| column_group | column to draw. |
| badge_classes | badge classes. |
| badges | badges to draw. |
| feature | feature being used. |
| introduction_date | introduction date of item. |
| remap | palette remap to for company-coloured badges. |
Definition at line 481 of file newgrf_badge.cpp.
References _current_text_dir, Badge::class_index, GetBadge(), GetBadgeSprite(), Rect::Indent(), PalSpriteID::pal, SA_CENTER, WidgetDimensions::scaled, ScaleGUITrad(), PalSpriteID::sprite, TD_RTL, and Rect::WithWidth().
Referenced by BuildIndustryWindow::DrawWidget(), and PickerWindow::DrawWidget().
| int DrawBadgeNameList | ( | Rect | r, |
| std::span< const BadgeID > | badges, | ||
| GrfSpecFeature | feature | ||
| ) |
Draw names for a list of badge labels.
| r | Rect to draw in. |
| badges | List of badges. |
| feature | GRF feature being used. |
Definition at line 437 of file newgrf_badge.cpp.
References AppendStringInPlace(), Badge::class_index, DrawStringMultiLine(), Badge::flags, GetBadge(), GetClassBadge(), GetListSeparator(), GetString(), Badge::name, NameListFirstOnly, NameListStop, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
Referenced by DrawVehiclePurchaseInfo(), BuildIndustryWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), BuildAirportWindow::OnPaint(), BuildRailStationWindow::OnPaint(), and BuildRoadStationWindow::OnPaint().
Get a badge if it exists.
| index | Index of badge. |
Definition at line 100 of file newgrf_badge.cpp.
References _badges, and Badges::specs.
Referenced by AppendCopyableBadgeList(), DrawBadgeColumn(), DrawBadgeNameList(), NewGRFInspectWindow::DrawMainPanelWidget(), GetClassBadge(), MarkBadgeSeen(), and UsedBadgeClasses::UsedBadgeClasses().
| Badge * GetBadgeByLabel | ( | std::string_view | label | ) |
Get a badge by label if it exists.
| label | Label of badge. |
Definition at line 111 of file newgrf_badge.cpp.
References _badges, Badge::label, and Badges::specs.
Referenced by FinaliseBadges().
|
static |
Get the largest badge size (within limits) for a badge class.
| badge_class | Badge class. |
| feature | Feature being used. |
Definition at line 292 of file newgrf_badge.cpp.
References _badges, GetBadgeSprite(), GetSpriteSize(), MAX_BADGE_HEIGHT, MAX_BADGE_WIDTH, Badges::specs, PalSpriteID::sprite, and ZOOM_LVL_NORMAL.
Referenced by GUIBadgeClasses::GUIBadgeClasses().
|
static |
Get sprite for the given badge.
| badge | Badge being queried. |
| feature | GRF feature being used. |
| introduction_date | Introduction date of the item, if it has one. |
| remap | Palette remap to use if the flag is company-coloured. |
0 if not available. Definition at line 275 of file newgrf_badge.cpp.
References Badge::flags, SpriteGroup::Resolve(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and UseCompanyColour.
Referenced by DrawBadgeColumn(), and GetBadgeMaximalDimension().
| 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.
| grffile | GRF file of the current varaction. |
| badges | List of badges to test. |
| parameter | GRF-local badge index. |
Definition at line 213 of file newgrf_badge.cpp.
References GRFFile::badge_list.
Referenced by AirportScopeResolver::GetVariable(), AirportTileScopeResolver::GetVariable(), VehicleScopeResolver::GetVariable(), HouseScopeResolver::GetVariable(), IndustriesScopeResolver::GetVariable(), IndustryTileScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), RoadStopScopeResolver::GetVariable(), and StationScopeResolver::GetVariable().
| Badge * GetClassBadge | ( | BadgeClassID | class_index | ) |
Get the badge class of a badge label.
| label | Label to get class of. |
Definition at line 124 of file newgrf_badge.cpp.
References _badges, Badges::classes, and GetBadge().
Referenced by ApplyBadgeFeaturesToClassBadges(), DrawBadgeNameList(), GUIBadgeClasses::GUIBadgeClasses(), and UsedBadgeClasses::UsedBadgeClasses().
| Badge & GetOrCreateBadge | ( | std::string_view | label | ) |
Register a badge label and return its global index.
| label | Badge label to register. |
Definition at line 69 of file newgrf_badge.cpp.
References _badges, BADGE_CLASS_SEPARATOR, Badge::class_index, GetOrCreateBadge(), GetOrCreateBadgeClass(), Badge::label, and Badges::specs.
Referenced by GetOrCreateBadge().
|
static |
Assign a BadgeClassID to the given badge.
| index | Badge ID of badge that should be assigned. |
Definition at line 46 of file newgrf_badge.cpp.
References _badges, and Badges::classes.
Referenced by GetOrCreateBadge().
| std::unique_ptr< DropDownListItem > MakeDropDownListBadgeIconItem | ( | const std::shared_ptr< GUIBadgeClasses > & | badge_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, | ||
| bool | shaded | ||
| ) |
Definition at line 550 of file newgrf_badge.cpp.
| std::unique_ptr< DropDownListItem > MakeDropDownListBadgeItem | ( | const std::shared_ptr< GUIBadgeClasses > & | badge_classes, |
| std::span< const BadgeID > | badges, | ||
| GrfSpecFeature | feature, | ||
| std::optional< TimerGameCalendar::Date > | introduction_date, | ||
| std::string && | str, | ||
| int | value, | ||
| bool | masked, | ||
| bool | shaded | ||
| ) |
Definition at line 545 of file newgrf_badge.cpp.
| void MarkBadgeSeen | ( | BadgeID | index, |
| GrfSpecFeature | feature | ||
| ) |
Mark a badge a seen (used) by a feature.
Definition at line 224 of file newgrf_badge.cpp.
References Badge::features, GetBadge(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set().
Referenced by ReadBadgeList().
|
static |
Definition at line 338 of file newgrf_badge.cpp.
| void ResetBadges | ( | ) |
Reset badges to the default state.
Definition at line 59 of file newgrf_badge.cpp.
References _badges.
Referenced by ResetNewGRFData().
|
static |
Static instance of badge state.
Definition at line 39 of file newgrf_badge.cpp.
Referenced by ApplyBadgeFeaturesToClassBadges(), BadgeTextFilter::BadgeTextFilter(), GetBadge(), GetBadgeByLabel(), GetBadgeMaximalDimension(), GetClassBadge(), GetOrCreateBadge(), GetOrCreateBadgeClass(), ResetBadges(), and UsedBadgeClasses::UsedBadgeClasses().
|
staticconstexpr |
Separator to identify badge classes from a label.
Definition at line 29 of file newgrf_badge.cpp.
Referenced by GetOrCreateBadge().
|
staticconstexpr |
Maximal height of a badge sprite.
Definition at line 264 of file newgrf_badge.cpp.
Referenced by GetBadgeMaximalDimension().
|
staticconstexpr |
Maximal width.
Definition at line 265 of file newgrf_badge.cpp.
Referenced by GetBadgeMaximalDimension().