OpenTTD Source: src/newgrf_badge_gui.h Source File

OpenTTD Source 15.0-RC2

newgrf_badge_gui.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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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"
17#include "timer/timer_game_calendar.h"
18
19 class GUIBadgeClasses : public UsedBadgeClasses {
20public:
21 struct Element {
22 BadgeClassID class_index;
23 uint8_t column_group;
24 bool visible;
25 uint sort_order;
26 Dimension size;
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> 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 = false, bool shaded = false);
55std::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 = false, bool shaded = false);
56
57 DropDownList BuildBadgeClassConfigurationList(const class GUIBadgeClasses &badge_class, uint columns, std::span<const StringID> column_separators, Colours bg_colour);
58bool HandleBadgeConfigurationDropDownClick(GrfSpecFeature feature, uint columns, int result, int click_result, BadgeFilterChoices &choices);
59
60std::pair<WidgetID, WidgetID> AddBadgeDropdownFilters(Window *window, WidgetID container_id, WidgetID widget, Colours colour, GrfSpecFeature feature);
61
62 class NWidgetBadgeFilter : public NWidgetLeaf {
63public:
64 NWidgetBadgeFilter(Colours colour, WidgetID index, GrfSpecFeature feature, BadgeClassID badge_class);
65
66 BadgeClassID GetBadgeClassID() const { return this->badge_class; }
67 std::string GetStringParameter(const BadgeFilterChoices &choices) const;
68 DropDownList GetDropDownList(PaletteID palette = PAL_NONE) const;
69
70private:
71 GrfSpecFeature feature;
72 BadgeClassID badge_class;
73};
74
75void ResetBadgeFilter(BadgeFilterChoices &choices, BadgeClassID badge_class_index);
76void SetBadgeFilter(BadgeFilterChoices &choices, BadgeID badge_index);
77
78#endif /* NEWGRF_BADGE_GUI_H */
GUIBadgeClasses
Definition newgrf_badge_gui.h:19
GUIBadgeClasses::GetTotalColumnsWidth
uint GetTotalColumnsWidth() const
Get total width of all columns.
Definition newgrf_badge_gui.cpp:108
NWidgetBadgeFilter
Definition newgrf_badge_gui.h:62
NWidgetBadgeFilter::badge_class
BadgeClassID badge_class
Badge class of this dropdown.
Definition newgrf_badge_gui.h:72
NWidgetBadgeFilter::feature
GrfSpecFeature feature
Feature of this dropdown.
Definition newgrf_badge_gui.h:71
NWidgetBadgeFilter::GetDropDownList
DropDownList GetDropDownList(PaletteID palette=PAL_NONE) const
Get the drop down list of badges for this filter.
Definition newgrf_badge_gui.cpp:516
NWidgetBase::index
const WidgetID index
Index of the nested widget (INVALID_WIDGET means 'not used').
Definition widget_type.h:251
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition widget_type.h:400
NWidgetLeaf
Leaf widget.
Definition widget_type.h:928
OverflowSafeInt< int64_t >
UsedBadgeClasses
Utility class to create a list of badge classes used by a feature.
Definition newgrf_badge.h:34
dropdown_type.h
Types related to the drop down widget.
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition dropdown_type.h:56
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
newgrf.h
Base for the NewGRF implementation.
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
newgrf_badge.h
Functions related to NewGRF badges.
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.
Definition newgrf_badge_gui.cpp:165
DrawBadgeNameList
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature feature)
Draw names for a list of badge labels.
Definition newgrf_badge_gui.cpp:120
AddBadgeDropdownFilters
std::pair< WidgetID, WidgetID > AddBadgeDropdownFilters(Window *window, WidgetID container_id, WidgetID widget, Colours colour, GrfSpecFeature feature)
Add badge drop down filter widgets.
Definition newgrf_badge_gui.cpp:561
HandleBadgeConfigurationDropDownClick
bool HandleBadgeConfigurationDropDownClick(GrfSpecFeature feature, uint columns, int result, int click_result, BadgeFilterChoices &choices)
Handle the badge configuration drop down selection.
Definition newgrf_badge_gui.cpp:465
SetBadgeFilter
void SetBadgeFilter(BadgeFilterChoices &choices, BadgeID badge_index)
Set badge filter choice for a class.
Definition newgrf_badge_gui.cpp:597
ResetBadgeFilter
void ResetBadgeFilter(BadgeFilterChoices &choices, BadgeClassID badge_class_index)
Reset badge filter choice for a class.
Definition newgrf_badge_gui.cpp:586
newgrf_badge_type.h
Types related to NewGRF badges.
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
GUIBadgeClasses::Element
Definition newgrf_badge_gui.h:21
GUIBadgeClasses::Element::size
Dimension size
Maximal size of this element.
Definition newgrf_badge_gui.h:26
GUIBadgeClasses::Element::sort_order
uint sort_order
Order of element.
Definition newgrf_badge_gui.h:25
GUIBadgeClasses::Element::label
std::string_view label
Class label (string owned by the class badge)
Definition newgrf_badge_gui.h:27
GUIBadgeClasses::Element::class_index
BadgeClassID class_index
Badge class index.
Definition newgrf_badge_gui.h:22
GUIBadgeClasses::Element::visible
bool visible
Whether the icon is visible.
Definition newgrf_badge_gui.h:24
GUIBadgeClasses::Element::column_group
uint8_t column_group
Column group in UI. 0 = left, 1 = centre, 2 = right.
Definition newgrf_badge_gui.h:23
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
StrongType::Typedef< uint16_t, struct BadgeClassIDTag, StrongType::Compare >
Window
Data structure for an opened window.
Definition window_gui.h:274
timer_game_calendar.h
Definition of the game-calendar-timer.
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20