OpenTTD Source 20250924-master-gbec4e71d53
newgrf_badge_gui.cpp
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#include "stdafx.h"
11
12#include "core/flatset_type.hpp"
13#include "dropdown_type.h"
14#include "dropdown_func.h"
15#include "newgrf.h"
16#include "newgrf_badge.h"
17#include "newgrf_badge_config.h"
18#include "newgrf_badge_gui.h"
19#include "newgrf_badge_type.h"
20#include "settings_gui.h"
21#include "strings_func.h"
23#include "window_gui.h"
24#include "zoom_func.h"
25
26#include "table/strings.h"
27
29
30#include "safeguards.h"
31
32static constexpr uint MAX_BADGE_HEIGHT = 12;
33static constexpr uint MAX_BADGE_WIDTH = MAX_BADGE_HEIGHT * 2;
34
41static Dimension GetBadgeMaximalDimension(BadgeClassID class_index, GrfSpecFeature feature)
42{
43 Dimension d = {0, MAX_BADGE_HEIGHT};
44
45 for (const auto &badge : GetBadges()) {
46 if (badge.class_index != class_index) continue;
47
48 PalSpriteID ps = GetBadgeSprite(badge, feature, std::nullopt, PAL_NONE);
49 if (ps.sprite == 0) continue;
50
51 d.width = std::max(d.width, GetSpriteSize(ps.sprite, nullptr, ZoomLevel::Normal).width);
52 if (d.width > MAX_BADGE_WIDTH) break;
53 }
54
55 d.width = std::min(d.width, MAX_BADGE_WIDTH);
56 return d;
57}
58
59static bool operator<(const GUIBadgeClasses::Element &a, const GUIBadgeClasses::Element &b)
60{
61 if (a.column_group != b.column_group) return a.column_group < b.column_group;
62 if (a.sort_order != b.sort_order) return a.sort_order < b.sort_order;
63 return a.label < b.label;
64}
65
70GUIBadgeClasses::GUIBadgeClasses(GrfSpecFeature feature) : UsedBadgeClasses(feature)
71{
72 /* Get list of classes used by feature. */
73 uint max_column = 0;
74 for (BadgeClassID class_index : this->Classes()) {
75 const Badge *class_badge = GetClassBadge(class_index);
76 if (class_badge->name == STR_NULL) continue;
77
78 Dimension size = GetBadgeMaximalDimension(class_index, feature);
79 if (size.width == 0) continue;
80
81 const auto [config, sort_order] = GetBadgeClassConfigItem(feature, class_badge->label);
82
83 this->gui_classes.emplace_back(class_index, config.column, config.show_icon, sort_order, size, class_badge->label);
84 if (size.width != 0 && config.show_icon) max_column = std::max<uint>(max_column, config.column);
85 }
86
87 std::sort(std::begin(this->gui_classes), std::end(this->gui_classes));
88
89 /* Determine total width of visible badge columns. */
90 this->column_widths.resize(max_column + 1);
91 for (const auto &el : this->gui_classes) {
92 if (!el.visible || el.size.width == 0) continue;
93 this->column_widths[el.column_group] += ScaleGUITrad(el.size.width) + WidgetDimensions::scaled.hsep_normal;
94 }
95
96 /* Replace trailing `hsep_normal` spacer with wider `hsep_wide` spacer. */
97 for (uint &badge_width : this->column_widths) {
98 if (badge_width == 0) continue;
100 }
101}
102
108{
109 return std::accumulate(std::begin(this->column_widths), std::end(this->column_widths), 0U);
110}
111
119int DrawBadgeNameList(Rect r, std::span<const BadgeID> badges, GrfSpecFeature)
120{
121 if (badges.empty()) return r.top;
122
123 FlatSet<BadgeClassID> class_indexes;
124 for (const BadgeID &index : badges) class_indexes.insert(GetBadge(index)->class_index);
125
126 std::string_view list_separator = GetListSeparator();
127 for (const BadgeClassID &class_index : class_indexes) {
128 const Badge *class_badge = GetClassBadge(class_index);
129 if (class_badge == nullptr || class_badge->name == STR_NULL) continue;
130
131 std::string s;
132 for (const BadgeID &index : badges) {
133 const Badge *badge = GetBadge(index);
134 if (badge == nullptr || badge->name == STR_NULL) continue;
135 if (badge->class_index != class_index) continue;
136
137 if (!s.empty()) {
138 if (badge->flags.Test(BadgeFlag::NameListFirstOnly)) continue;
139 s += list_separator;
140 }
141 AppendStringInPlace(s, badge->name);
142 if (badge->flags.Test(BadgeFlag::NameListStop)) break;
143 }
144
145 if (s.empty()) continue;
146
147 r.top = DrawStringMultiLine(r, GetString(STR_BADGE_NAME_LIST, class_badge->name, std::move(s)), TC_BLACK);
148 }
149
150 return r.top;
151}
152
163void 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)
164{
165 bool rtl = _current_text_dir == TD_RTL;
166 for (const auto &gc : gui_classes.GetClasses()) {
167 if (gc.column_group != column_group) continue;
168 if (!gc.visible) continue;
169
170 int width = ScaleGUITrad(gc.size.width);
171 for (const BadgeID &index : badges) {
172 const Badge &badge = *GetBadge(index);
173 if (badge.class_index != gc.class_index) continue;
174
175 PalSpriteID ps = GetBadgeSprite(badge, feature, introduction_date, remap);
176 if (ps.sprite == 0) continue;
177
178 DrawSpriteIgnorePadding(ps.sprite, ps.pal, r.WithWidth(width, rtl), SA_CENTER);
179 break;
180 }
181
182 r = r.Indent(width + WidgetDimensions::scaled.hsep_normal, rtl);
183 }
184}
185
187template <class TBase, bool TEnd = true, FontSize TFs = FS_NORMAL>
188class DropDownBadges : public TBase {
189public:
190 template <typename... Args>
191 explicit DropDownBadges(const std::shared_ptr<GUIBadgeClasses> &gui_classes, std::span<const BadgeID> badges, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, Args &&...args) :
192 TBase(std::forward<Args>(args)...), gui_classes(gui_classes), badges(badges), feature(feature), introduction_date(introduction_date)
193 {
194 for (const auto &gc : gui_classes->GetClasses()) {
195 if (gc.column_group != 0) continue;
196 dim.width += gc.size.width + WidgetDimensions::scaled.hsep_normal;
197 dim.height = std::max(dim.height, gc.size.height);
198 }
199 }
200
201 uint Height() const override
202 {
203 return std::max<uint>(this->dim.height, this->TBase::Height());
204 }
205
206 uint Width() const override
207 {
208 if (this->dim.width == 0) return this->TBase::Width();
209 return this->dim.width + WidgetDimensions::scaled.hsep_wide + this->TBase::Width();
210 }
211
212 int OnClick(const Rect &r, const Point &pt) const override
213 {
214 if (this->dim.width == 0) {
215 return this->TBase::OnClick(r, pt);
216 } else {
217 bool rtl = TEnd ^ (_current_text_dir == TD_RTL);
218 return this->TBase::OnClick(r.Indent(this->dim.width + WidgetDimensions::scaled.hsep_wide, rtl), pt);
219 }
220 }
221
222 void Draw(const Rect &full, const Rect &r, bool sel, int click_result, Colours bg_colour) const override
223 {
224 if (this->dim.width == 0) {
225 this->TBase::Draw(full, r, sel, click_result, bg_colour);
226 } else {
227 bool rtl = TEnd ^ (_current_text_dir == TD_RTL);
228 DrawBadgeColumn(r.WithWidth(this->dim.width, rtl), 0, *this->gui_classes, this->badges, this->feature, this->introduction_date, PAL_NONE);
229 this->TBase::Draw(full, r.Indent(this->dim.width + WidgetDimensions::scaled.hsep_wide, rtl), sel, click_result, bg_colour);
230 }
231 }
232
233private:
234 std::shared_ptr<GUIBadgeClasses> gui_classes;
235
236 const std::span<const BadgeID> badges;
237 const GrfSpecFeature feature;
238 const std::optional<TimerGameCalendar::Date> introduction_date;
239
240 Dimension dim{};
241};
242
245
246std::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)
247{
248 return std::make_unique<DropDownListBadgeItem>(gui_classes, badges, feature, introduction_date, std::move(str), value, masked, shaded);
249}
250
251std::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, std::string &&str, int value, bool masked, bool shaded)
252{
253 return std::make_unique<DropDownListBadgeIconItem>(gui_classes, badges, feature, introduction_date, dim, sprite, palette, std::move(str), value, masked, shaded);
254}
255
259template <class TBase, bool TEnd = true, FontSize TFs = FS_NORMAL>
260class DropDownMover : public TBase {
261public:
262 template <typename... Args>
263 explicit DropDownMover(int click_up, int click_down, Colours button_colour, Args &&...args)
264 : TBase(std::forward<Args>(args)...), click_up(click_up), click_down(click_down), button_colour(button_colour)
265 {
266 }
267
268 uint Height() const override
269 {
270 return std::max<uint>(SETTING_BUTTON_HEIGHT, this->TBase::Height());
271 }
272
273 uint Width() const override
274 {
275 return SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide + this->TBase::Width();
276 }
277
278 int OnClick(const Rect &r, const Point &pt) const override
279 {
280 bool rtl = (_current_text_dir == TD_RTL);
281 int w = SETTING_BUTTON_WIDTH;
282
283 Rect br = r.WithWidth(w, TEnd ^ rtl).CentreTo(w, SETTING_BUTTON_HEIGHT);
284 if (br.WithWidth(w / 2, rtl).Contains(pt)) return this->click_up;
285 if (br.WithWidth(w / 2, !rtl).Contains(pt)) return this->click_down;
286
287 return this->TBase::OnClick(r.Indent(w + WidgetDimensions::scaled.hsep_wide, TEnd ^ rtl), pt);
288 }
289
290 void Draw(const Rect &full, const Rect &r, bool sel, int click_result, Colours bg_colour) const override
291 {
292 bool rtl = (_current_text_dir == TD_RTL);
293 int w = SETTING_BUTTON_WIDTH;
294
295 int state = 0;
296 if (sel && click_result != 0) {
297 if (click_result == this->click_up) state = 1;
298 if (click_result == this->click_down) state = 2;
299 }
300
301 Rect br = r.WithWidth(w, TEnd ^ rtl).CentreTo(w, SETTING_BUTTON_HEIGHT);
302 DrawUpDownButtons(br.left, br.top, this->button_colour, state, this->click_up != 0, this->click_down != 0);
303
304 this->TBase::Draw(full, r.Indent(w + WidgetDimensions::scaled.hsep_wide, TEnd ^ rtl), sel, click_result, bg_colour);
305 }
306
307private:
311};
312
315
316enum BadgeClick : int {
317 BADGE_CLICK_NONE,
318 BADGE_CLICK_MOVE_UP,
319 BADGE_CLICK_MOVE_DOWN,
320 BADGE_CLICK_TOGGLE_ICON,
321 BADGE_CLICK_TOGGLE_FILTER,
322};
323
324DropDownList BuildBadgeClassConfigurationList(const GUIBadgeClasses &gui_classes, uint columns, std::span<const StringID> column_separators)
325{
326 DropDownList list;
327
328 list.push_back(MakeDropDownListStringItem(STR_BADGE_CONFIG_RESET, INT_MAX));
329 if (gui_classes.GetClasses().empty()) return list;
330 list.push_back(MakeDropDownListDividerItem());
331 list.push_back(std::make_unique<DropDownUnselectable<DropDownListStringItem>>(GetString(STR_BADGE_CONFIG_ICONS), -1));
332
333 const BadgeClassID front = gui_classes.GetClasses().front().class_index;
334 const BadgeClassID back = gui_classes.GetClasses().back().class_index;
335
336 for (uint i = 0; i < columns; ++i) {
337 for (const auto &gc : gui_classes.GetClasses()) {
338 if (gc.column_group != i) continue;
339 if (gc.size.width == 0) continue;
340
341 bool first = (i == 0 && gc.class_index == front);
342 bool last = (i == columns - 1 && gc.class_index == back);
343 list.push_back(std::make_unique<DropDownListToggleMoverItem>(first ? 0 : BADGE_CLICK_MOVE_UP, last ? 0 : BADGE_CLICK_MOVE_DOWN, COLOUR_YELLOW, gc.visible, BADGE_CLICK_TOGGLE_ICON, COLOUR_YELLOW, COLOUR_GREY, GetString(GetClassBadge(gc.class_index)->name), gc.class_index.base()));
344 }
345
346 if (i >= column_separators.size()) continue;
347
348 if (column_separators[i] == STR_NULL) {
349 list.push_back(MakeDropDownListDividerItem());
350 } else {
351 list.push_back(MakeDropDownListStringItem(column_separators[i], INT_MIN + i, false, true));
352 }
353 }
354
355 list.push_back(MakeDropDownListDividerItem());
356 list.push_back(std::make_unique<DropDownUnselectable<DropDownListStringItem>>(GetString(STR_BADGE_CONFIG_FILTERS), -1));
357
358 for (const BadgeClassID &badge_class_index : gui_classes.Classes()) {
359 const Badge *badge = GetClassBadge(badge_class_index);
360 if (!badge->flags.Test(BadgeFlag::HasText)) continue;
361
362 const auto [config, _] = GetBadgeClassConfigItem(gui_classes.GetFeature(), badge->label);
363 list.push_back(std::make_unique<DropDownListToggleItem>(config.show_filter, BADGE_CLICK_TOGGLE_FILTER, COLOUR_YELLOW, COLOUR_GREY, GetString(badge->name), (1U << 16) | badge_class_index.base()));
364 }
365
366 return list;
367}
368
375static void BadgeClassToggleVisibility(GrfSpecFeature feature, Badge &class_badge, int click_result, BadgeFilterChoices &choices)
376{
377 auto config = GetBadgeClassConfiguration(feature);
378 auto it = std::ranges::find(config, class_badge.label, &BadgeClassConfigItem::label);
379 if (it == std::end(config)) return;
380
381 if (click_result == BADGE_CLICK_TOGGLE_ICON) it->show_icon = !it->show_icon;
382 if (click_result == BADGE_CLICK_TOGGLE_FILTER) {
383 it->show_filter = !it->show_filter;
384 if (!it->show_filter) ResetBadgeFilter(choices, class_badge.class_index);
385 }
386}
387
393static void BadgeClassMovePrevious(GrfSpecFeature feature, Badge &class_badge)
394{
395 GUIBadgeClasses gui_classes(feature);
396 if (gui_classes.GetClasses().empty()) return;
397
398 auto config = GetBadgeClassConfiguration(feature);
399 auto it = std::ranges::find(config, class_badge.label, &BadgeClassConfigItem::label);
400 if (it == std::end(config)) return;
401
402 auto pos_cur = std::ranges::find(gui_classes.GetClasses(), class_badge.class_index, &GUIBadgeClasses::Element::class_index);
403 if (pos_cur == std::begin(gui_classes.GetClasses())) {
404 if (it->column > 0) --it->column;
405 return;
406 }
407
408 auto pos_prev = std::ranges::find(config, std::prev(pos_cur)->label, &BadgeClassConfigItem::label);
409 if (it->column > pos_prev->column) {
410 --it->column;
411 } else {
412 /* Rotate elements right so that it is placed before pos_prev, maintaining order of non-visible elements. */
413 std::rotate(pos_prev, it, std::next(it));
414 }
415}
416
423static void BadgeClassMoveNext(GrfSpecFeature feature, Badge &class_badge, uint columns)
424{
425 GUIBadgeClasses gui_classes(feature);
426 if (gui_classes.GetClasses().empty()) return;
427
428 auto config = GetBadgeClassConfiguration(feature);
429 auto it = std::ranges::find(config, class_badge.label, &BadgeClassConfigItem::label);
430 if (it == std::end(config)) return;
431
432 auto pos_cur = std::ranges::find(gui_classes.GetClasses(), class_badge.class_index, &GUIBadgeClasses::Element::class_index);
433 if (std::next(pos_cur) == std::end(gui_classes.GetClasses())) {
434 if (it->column < static_cast<int>(columns - 1)) ++it->column;
435 return;
436 }
437
438 auto pos_next = std::ranges::find(config, std::next(pos_cur)->label, &BadgeClassConfigItem::label);
439 if (it->column < pos_next->column) {
440 ++it->column;
441 } else {
442 /* Rotate elements left so that it is placed after pos_next, maintaining order of non-visible elements. */
443 std::rotate(it, std::next(it), std::next(pos_next));
444 }
445}
446
455bool HandleBadgeConfigurationDropDownClick(GrfSpecFeature feature, uint columns, int result, int click_result, BadgeFilterChoices &choices)
456{
457 if (result == INT_MAX) {
459 return true;
460 }
461
462 Badge *class_badge = GetClassBadge(static_cast<BadgeClassID>(result));
463 if (class_badge == nullptr) return false;
464
465 switch (click_result) {
466 case BADGE_CLICK_MOVE_DOWN: // Move down button.
467 BadgeClassMoveNext(feature, *class_badge, columns);
468 break;
469 case BADGE_CLICK_MOVE_UP: // Move up button.
470 BadgeClassMovePrevious(feature, *class_badge);
471 break;
472 case BADGE_CLICK_TOGGLE_ICON:
473 case BADGE_CLICK_TOGGLE_FILTER:
474 BadgeClassToggleVisibility(feature, *class_badge, click_result, choices);
475 break;
476 default:
477 break;
478 }
479
480 return true;
481}
482
483NWidgetBadgeFilter::NWidgetBadgeFilter(Colours colour, WidgetID index, GrfSpecFeature feature, BadgeClassID badge_class)
484 : NWidgetLeaf(WWT_DROPDOWN, colour, index, WidgetData{ .string = STR_JUST_STRING }, STR_NULL)
485 , feature(feature), badge_class(badge_class)
486{
487 this->SetFill(1, 0);
488 this->SetResize(1, 0);
489}
490
491std::string NWidgetBadgeFilter::GetStringParameter(const BadgeFilterChoices &choices) const
492{
493 auto it = choices.find(this->badge_class);
494 if (it == std::end(choices)) {
495 return ::GetString(STR_BADGE_FILTER_ANY_LABEL, GetClassBadge(this->badge_class)->name);
496 }
497
498 return ::GetString(STR_BADGE_FILTER_IS_LABEL, GetClassBadge(it->first)->name, GetBadge(it->second)->name);
499}
500
506{
507 DropDownList list;
508
509 /* Add item for disabling filtering. */
510 list.push_back(MakeDropDownListStringItem(::GetString(STR_BADGE_FILTER_ANY_LABEL, GetClassBadge(this->badge_class)->name), -1));
511 list.push_back(MakeDropDownListDividerItem());
512
513 /* Add badges */
514 Dimension d = GetBadgeMaximalDimension(this->badge_class, this->feature);
515 d.width = ScaleGUITrad(d.width);
516 d.height = ScaleGUITrad(d.height);
517
518 auto start = list.size();
519
520 const auto *bc = GetClassBadge(this->badge_class);
521
522 for (const Badge &badge : GetBadges()) {
523 if (badge.class_index != this->badge_class) continue;
524 if (badge.index == bc->index) continue;
525 if (badge.name == STR_NULL) continue;
526 if (!badge.features.Test(this->feature)) continue;
527
528 PalSpriteID ps = GetBadgeSprite(badge, this->feature, std::nullopt, PAL_NONE);
529 if (ps.sprite == 0) {
530 list.push_back(MakeDropDownListStringItem(badge.name, badge.index.base()));
531 } else {
532 list.push_back(MakeDropDownListIconItem(d, ps.sprite, ps.pal, badge.name, badge.index.base()));
533 }
534 }
535
536 std::sort(std::begin(list) + start, std::end(list), DropDownListStringItem::NatSortFunc);
537
538 return list;
539}
540
549std::pair<WidgetID, WidgetID> AddBadgeDropdownFilters(NWidgetContainer &container, WidgetID widget, Colours colour, GrfSpecFeature feature)
550{
551 container.Clear();
552 WidgetID first = ++widget;
553
554 /* Get list of classes used by feature. */
555 UsedBadgeClasses used(feature);
556
557 for (BadgeClassID class_index : used.Classes()) {
558 const auto [config, _] = GetBadgeClassConfigItem(feature, GetClassBadge(class_index)->label);
559 if (!config.show_filter) continue;
560
561 container.Add(std::make_unique<NWidgetBadgeFilter>(colour, widget, feature, class_index));
562 ++widget;
563 }
564
565 return {first, widget};
566}
567
573void ResetBadgeFilter(BadgeFilterChoices &choices, BadgeClassID badge_class_index)
574{
575 choices.erase(badge_class_index);
576}
577
584void SetBadgeFilter(BadgeFilterChoices &choices, BadgeID badge_index)
585{
586 const Badge *badge = GetBadge(badge_index);
587 assert(badge != nullptr);
588
589 choices[badge->class_index] = badge_index;
590}
std::string label
Class label.
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.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Drop down element that draws a list of badges.
Drop down component that shows extra buttons to indicate that the item can be moved up or down.
int click_down
Click result for down button. Button is inactive if 0.
Colours button_colour
Colour of buttons.
int click_up
Click result for up button. Button is inactive if 0.
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Natural sorting comparator function for DropDownList::sort().
Drop down boolean toggle component.
Drop down component that makes the item unselectable.
Flat set implementation that uses a sorted vector for storage.
uint GetTotalColumnsWidth() const
Get total width of all columns.
DropDownList GetDropDownList() const
Get the drop down list of badges for this filter.
BadgeClassID badge_class
Badge class of this dropdown.
Baseclass for container widgets.
void Add(std::unique_ptr< NWidgetBase > &&wid)
Append widget wid to container.
Definition widget.cpp:1290
StringID GetString() const
Get the string that has been set for this nested widget.
Definition widget.cpp:1249
Leaf widget.
Utility class to create a list of badge classes used by a feature.
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
int hsep_wide
Wide horizontal spacing.
Definition window_gui.h:62
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:61
Common drop down list components.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Flat set container implementation.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:966
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:783
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Base for the NewGRF implementation.
GrfSpecFeature
Definition newgrf.h:69
Badge * GetBadge(BadgeID index)
Get a badge if it exists.
std::span< const Badge > GetBadges()
Get a read-only view of badges.
PalSpriteID GetBadgeSprite(const Badge &badge, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, PaletteID remap)
Get sprite for the given badge.
Badge * GetClassBadge(BadgeClassID class_index)
Get the badge class of a badge label.
Functions related to NewGRF badges.
void ResetBadgeClassConfiguration(GrfSpecFeature feature)
Reset badge class configuration for a feature.
std::pair< const BadgeClassConfigItem &, int > GetBadgeClassConfigItem(GrfSpecFeature feature, std::string_view label)
Get configuration for a badge class.
std::span< BadgeClassConfigItem > GetBadgeClassConfiguration(GrfSpecFeature feature)
Get the badge user configuration for a feature.
Functions related to NewGRF badge configuration.
Types related to NewGRF badges.
@ NameListStop
Stop adding names to the name list after this badge.
@ NameListFirstOnly
Don't add this name to the name list if not first.
@ HasText
Internal flag set if the badge has text.
A number of safeguards to prevent using unsafe methods.
void DrawUpDownButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_up, bool clickable_down)
Draw [^][v] buttons.
Functions for setting GUIs.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition of base types and functions in a cross-platform compatible way.
std::string_view GetListSeparator()
Get the list separator string for the current language.
Definition strings.cpp:299
void AppendStringInPlace(std::string &result, StringID string)
Resolve the given StringID and append in place into an existing std::string with formatting but no pa...
Definition strings.cpp:434
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
Dimensions (a width and height) of a rectangle in 2D.
uint sort_order
Order of element.
std::string_view label
Class label (string owned by the class badge)
BadgeClassID class_index
Badge class index.
uint8_t column_group
Column group in UI. 0 = left, 1 = centre, 2 = right.
Combination of a palette sprite and a 'real' sprite.
Definition gfx_type.h:22
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:23
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition gfx_type.h:24
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Rect CentreTo(int width, int height) const
Centre a dimension within this Rect.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
bool Contains(const Point &pt) const
Test if a point falls inside this Rect.
Container with the data associated to a single widget.
int16_t Height
Fixed point type for heights.
Definition tgp.cpp:153
Definition of the game-calendar-timer.
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:49
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:62
Functions, definitions and such used only by the GUI.
int WidgetID
Widget ID.
Definition window_type.h:20
Functions related to zooming.
@ Normal
The normal zoom level.