OpenTTD Source 20260206-master-g4d4e37dbf1
newgrf_badge_gui.cpp File Reference

GUI functionalities for NewGRF badges. More...

#include "stdafx.h"
#include "core/flatset_type.hpp"
#include "dropdown_type.h"
#include "dropdown_func.h"
#include "newgrf.h"
#include "newgrf_badge.h"
#include "newgrf_badge_config.h"
#include "newgrf_badge_gui.h"
#include "newgrf_badge_type.h"
#include "settings_gui.h"
#include "strings_func.h"
#include "timer/timer_game_calendar.h"
#include "window_gui.h"
#include "window_type.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  DropDownBadges< TBase, TEnd, TFs >
 Drop down element that draws a list of badges. More...
class  DropDownMover< TBase, TEnd, TFs >
 Drop down component that shows extra buttons to indicate that the item can be moved up or down. More...

Typedefs

using DropDownListBadgeItem = DropDownBadges<DropDownString<DropDownSpacer<DropDownListStringItem, true>, FS_SMALL, true>>
using DropDownListBadgeIconItem = DropDownBadges<DropDownString<DropDownSpacer<DropDownListIconItem, true>, FS_SMALL, true>>
using DropDownListToggleMoverItem = DropDownMover<DropDownToggle<DropDownString<DropDownListItem>>>
using DropDownListToggleItem = DropDownToggle<DropDownString<DropDownListItem>>

Enumerations

enum  BadgeClick : int {
  BADGE_CLICK_NONE , BADGE_CLICK_MOVE_UP , BADGE_CLICK_MOVE_DOWN , BADGE_CLICK_TOGGLE_ICON ,
  BADGE_CLICK_TOGGLE_FILTER
}

Functions

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 &gui_classes, std::span< const BadgeID > badges, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, PaletteID remap)
 Draw a badge column group.
std::unique_ptr< DropDownListItemMakeDropDownListBadgeItem (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)
std::unique_ptr< DropDownListItemMakeDropDownListBadgeItem (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)
std::unique_ptr< DropDownListItemMakeDropDownListBadgeIconItem (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)
DropDownList BuildBadgeClassConfigurationList (const GUIBadgeClasses &gui_classes, uint columns, std::span< const StringID > column_separators, Colours bg_colour)
static void BadgeClassToggleVisibility (GrfSpecFeature feature, Badge &class_badge, int click_result, BadgeFilterChoices &choices)
 Toggle badge class visibility.
static void BadgeClassMovePrevious (GrfSpecFeature feature, Badge &class_badge)
 Move the badge class to the previous position.
static void BadgeClassMoveNext (GrfSpecFeature feature, Badge &class_badge, uint columns)
 Move the badge class to the next position.
bool HandleBadgeConfigurationDropDownClick (GrfSpecFeature feature, uint columns, int result, int click_result, BadgeFilterChoices &choices)
 Handle the badge configuration drop down selection.
std::pair< WidgetID, WidgetIDAddBadgeDropdownFilters (Window *window, WidgetID container_id, WidgetID widget, Colours colour, GrfSpecFeature feature)
 Add badge drop down filter widgets.
void ResetBadgeFilter (BadgeFilterChoices &choices, BadgeClassID badge_class_index)
 Reset badge filter choice for a class.
void SetBadgeFilter (BadgeFilterChoices &choices, BadgeID badge_index)
 Set badge filter choice for a class.

Variables

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.

Detailed Description

GUI functionalities for NewGRF badges.

Definition in file newgrf_badge_gui.cpp.

Typedef Documentation

◆ DropDownListBadgeIconItem

using DropDownListBadgeIconItem = DropDownBadges<DropDownString<DropDownSpacer<DropDownListIconItem, true>, FS_SMALL, true>>

Definition at line 249 of file newgrf_badge_gui.cpp.

◆ DropDownListBadgeItem

using DropDownListBadgeItem = DropDownBadges<DropDownString<DropDownSpacer<DropDownListStringItem, true>, FS_SMALL, true>>

Definition at line 248 of file newgrf_badge_gui.cpp.

◆ DropDownListToggleItem

using DropDownListToggleItem = DropDownToggle<DropDownString<DropDownListItem>>

Definition at line 324 of file newgrf_badge_gui.cpp.

◆ DropDownListToggleMoverItem

using DropDownListToggleMoverItem = DropDownMover<DropDownToggle<DropDownString<DropDownListItem>>>

Definition at line 323 of file newgrf_badge_gui.cpp.

Enumeration Type Documentation

◆ BadgeClick

enum BadgeClick : int

Definition at line 326 of file newgrf_badge_gui.cpp.

Function Documentation

◆ AddBadgeDropdownFilters()

std::pair< WidgetID, WidgetID > AddBadgeDropdownFilters ( Window * window,
WidgetID container_id,
WidgetID widget,
Colours colour,
GrfSpecFeature feature )

Add badge drop down filter widgets.

Parameters
windowWindow that holds the container.
container_idContainer widget index to hold filter widgets.
widgetWidget index to apply to first filter.
colourBackground colour of widgets.
featureGRF feature for filters.
Returns
First and last widget indexes of filter widgets.

Definition at line 563 of file newgrf_badge_gui.cpp.

References NWidgetContainer::Clear(), GetBadgeClassConfigItem(), GetClassBadge(), and Window::GetWidget().

Referenced by BuildVehicleWindow::OnInit(), and PickerWindow::OnInit().

◆ BadgeClassMoveNext()

void BadgeClassMoveNext ( GrfSpecFeature feature,
Badge & class_badge,
uint columns )
static

Move the badge class to the next position.

Parameters
featureFeature being used.
class_badgeClass badge.
columnsMaximum column number permitted.

Definition at line 434 of file newgrf_badge_gui.cpp.

References Badge::class_index, GUIBadgeClasses::Element::class_index, GetBadgeClassConfiguration(), Badge::label, and BadgeClassConfigItem::label.

Referenced by HandleBadgeConfigurationDropDownClick().

◆ BadgeClassMovePrevious()

void BadgeClassMovePrevious ( GrfSpecFeature feature,
Badge & class_badge )
static

Move the badge class to the previous position.

Parameters
featureFeature being used.
class_badgeClass badge.

Definition at line 404 of file newgrf_badge_gui.cpp.

References Badge::class_index, GUIBadgeClasses::Element::class_index, GetBadgeClassConfiguration(), Badge::label, and BadgeClassConfigItem::label.

Referenced by HandleBadgeConfigurationDropDownClick().

◆ BadgeClassToggleVisibility()

void BadgeClassToggleVisibility ( GrfSpecFeature feature,
Badge & class_badge,
int click_result,
BadgeFilterChoices & choices )
static

Toggle badge class visibility.

Parameters
featureFeature being used.
class_badgeClass badge.
click_resultDropdown click result.
choicesConfiguration of the badge filters.

Definition at line 386 of file newgrf_badge_gui.cpp.

References Badge::class_index, GetBadgeClassConfiguration(), Badge::label, BadgeClassConfigItem::label, and ResetBadgeFilter().

Referenced by HandleBadgeConfigurationDropDownClick().

◆ BuildBadgeClassConfigurationList()

DropDownList BuildBadgeClassConfigurationList ( const GUIBadgeClasses & gui_classes,
uint columns,
std::span< const StringID > column_separators,
Colours bg_colour )

Definition at line 334 of file newgrf_badge_gui.cpp.

◆ DrawBadgeColumn()

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 )

Draw a badge column group.

Parameters
rrect to draw within.
column_groupcolumn to draw.
gui_classesgui badge classes.
badgesbadges to draw.
featurefeature being used.
introduction_dateintroduction date of item.
remappalette remap to for company-coloured badges.

Definition at line 165 of file newgrf_badge_gui.cpp.

References _current_text_dir, Badge::class_index, GetBadge(), GetBadgeSprite(), Rect::Indent(), PalSpriteID::pal, Rect, SA_CENTER, WidgetDimensions::scaled, ScaleGUITrad(), PalSpriteID::sprite, TD_RTL, and Rect::WithWidth().

Referenced by BuildIndustryWindow::DrawWidget(), and PickerWindow::DrawWidget().

◆ DrawBadgeNameList()

int DrawBadgeNameList ( Rect r,
std::span< const BadgeID > badges,
GrfSpecFeature feature )

◆ GetBadgeMaximalDimension()

Dimension GetBadgeMaximalDimension ( BadgeClassID class_index,
GrfSpecFeature feature )
static

Get the largest badge size (within limits) for a badge class.

Parameters
class_indexBadge class.
featureFeature being used.
Returns
Largest base size of the badge class for the feature.

Definition at line 42 of file newgrf_badge_gui.cpp.

References GetBadges(), GetBadgeSprite(), GetSpriteSize(), MAX_BADGE_HEIGHT, MAX_BADGE_WIDTH, Normal, and PalSpriteID::sprite.

Referenced by NWidgetBadgeFilter::GetDropDownList(), and GUIBadgeClasses::GUIBadgeClasses().

◆ HandleBadgeConfigurationDropDownClick()

bool HandleBadgeConfigurationDropDownClick ( GrfSpecFeature feature,
uint columns,
int result,
int click_result,
BadgeFilterChoices & choices )

Handle the badge configuration drop down selection.

Parameters
featureFeature being used.
columnsMaximum column number permitted.
resultSelected dropdown item value.
click_resultDropdown click result.
choicesConfiguration of the badge filters.
Returns
true iff the caller should reinitialise their widgets.

Definition at line 467 of file newgrf_badge_gui.cpp.

References BadgeClassMoveNext(), BadgeClassMovePrevious(), BadgeClassToggleVisibility(), GetClassBadge(), and ResetBadgeClassConfiguration().

Referenced by BuildVehicleWindow::OnDropdownSelect(), and PickerWindow::OnDropdownSelect().

◆ MakeDropDownListBadgeIconItem()

std::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 )

Definition at line 261 of file newgrf_badge_gui.cpp.

◆ MakeDropDownListBadgeItem() [1/2]

std::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 )

Definition at line 256 of file newgrf_badge_gui.cpp.

◆ MakeDropDownListBadgeItem() [2/2]

std::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 )

Definition at line 251 of file newgrf_badge_gui.cpp.

◆ operator<()

bool operator< ( const GUIBadgeClasses::Element & a,
const GUIBadgeClasses::Element & b )
static

Definition at line 60 of file newgrf_badge_gui.cpp.

◆ ResetBadgeFilter()

void ResetBadgeFilter ( BadgeFilterChoices & choices,
BadgeClassID badge_class_index )

Reset badge filter choice for a class.

Parameters
choicesBadge filter choices.
badge_class_indexBadge class to reset.

Definition at line 588 of file newgrf_badge_gui.cpp.

Referenced by BadgeClassToggleVisibility(), BuildVehicleWindow::OnDropdownSelect(), and PickerWindow::OnDropdownSelect().

◆ SetBadgeFilter()

void SetBadgeFilter ( BadgeFilterChoices & choices,
BadgeID badge_index )

Set badge filter choice for a class.

Parameters
choicesBadge filter choices.
badge_indexBadge to set. The badge class is inferred from the badge.
Note
if the badge_index is invalid, the filter will be reset instead.

Definition at line 599 of file newgrf_badge_gui.cpp.

References Badge::class_index, and GetBadge().

Referenced by BuildVehicleWindow::OnDropdownSelect(), and PickerWindow::OnDropdownSelect().

Variable Documentation

◆ MAX_BADGE_HEIGHT

uint MAX_BADGE_HEIGHT = 12
staticconstexpr

Maximal height of a badge sprite.

Definition at line 33 of file newgrf_badge_gui.cpp.

Referenced by GetBadgeMaximalDimension().

◆ MAX_BADGE_WIDTH

uint MAX_BADGE_WIDTH = MAX_BADGE_HEIGHT * 2
staticconstexpr

Maximal width.

Definition at line 34 of file newgrf_badge_gui.cpp.

Referenced by GetBadgeMaximalDimension().