From f8aa2e64e42e3cb6c4ac9de35ff8f903641b66c2 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 29 Sep 2025 19:23:02 +0100 Subject: [PATCH] Add: Include build cost in rail/road dropdowns. (#14599) --- src/dropdown_common_type.h | 26 ++++++++++++++++++++++++++ src/newgrf_badge_gui.cpp | 12 ++++++------ src/newgrf_badge_gui.h | 4 ++-- src/rail_gui.cpp | 4 ++-- src/road_gui.cpp | 6 +++--- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/dropdown_common_type.h b/src/dropdown_common_type.h index 81e2b36be9..dac1500d46 100644 --- a/src/dropdown_common_type.h +++ b/src/dropdown_common_type.h @@ -260,6 +260,32 @@ public: } }; +/** + * Drop down spacer component. + * @tparam TBase Base component. + * @tparam TEnd Position space at end if true, or start if false. + */ +template +class DropDownSpacer : public TBase { +public: + template + explicit DropDownSpacer(Args&&... args) : TBase(std::forward(args)...) {} + + uint Width() const override { return WidgetDimensions::scaled.hsep_wide + this->TBase::Width(); } + + int OnClick(const Rect &r, const Point &pt) const override + { + bool rtl = TEnd ^ (_current_text_dir == TD_RTL); + return this->TBase::OnClick(r.Indent(WidgetDimensions::scaled.hsep_wide, rtl), pt); + } + + void Draw(const Rect &full, const Rect &r, bool sel, int click_result, Colours bg_colour) const override + { + bool rtl = TEnd ^ (_current_text_dir == TD_RTL); + this->TBase::Draw(full, r.Indent(WidgetDimensions::scaled.hsep_wide, rtl), sel, click_result, bg_colour); + } +}; + /** * Drop down component that makes the item unselectable. * @tparam TBase Base component. diff --git a/src/newgrf_badge_gui.cpp b/src/newgrf_badge_gui.cpp index 8c10484df4..491986c82b 100644 --- a/src/newgrf_badge_gui.cpp +++ b/src/newgrf_badge_gui.cpp @@ -240,17 +240,17 @@ private: Dimension dim{}; }; -using DropDownListBadgeItem = DropDownBadges; -using DropDownListBadgeIconItem = DropDownBadges; +using DropDownListBadgeItem = DropDownBadges, FS_SMALL, true>>; +using DropDownListBadgeIconItem = DropDownBadges, FS_SMALL, true>>; -std::unique_ptr MakeDropDownListBadgeItem(const std::shared_ptr &gui_classes, std::span badges, GrfSpecFeature feature, std::optional introduction_date, std::string &&str, int value, bool masked, bool shaded) +std::unique_ptr MakeDropDownListBadgeItem(const std::shared_ptr &gui_classes, std::span badges, GrfSpecFeature feature, std::optional introduction_date, Money cost, std::string &&str, int value, bool masked, bool shaded) { - return std::make_unique(gui_classes, badges, feature, introduction_date, std::move(str), value, masked, shaded); + return std::make_unique(gui_classes, badges, feature, introduction_date, GetString(STR_JUST_CURRENCY_SHORT, cost), std::move(str), value, masked, shaded); } -std::unique_ptr MakeDropDownListBadgeIconItem(const std::shared_ptr &gui_classes, std::span badges, GrfSpecFeature feature, std::optional introduction_date, const Dimension &dim, SpriteID sprite, PaletteID palette, std::string &&str, int value, bool masked, bool shaded) +std::unique_ptr MakeDropDownListBadgeIconItem(const std::shared_ptr &gui_classes, std::span badges, GrfSpecFeature feature, std::optional introduction_date, Money cost, const Dimension &dim, SpriteID sprite, PaletteID palette, std::string &&str, int value, bool masked, bool shaded) { - return std::make_unique(gui_classes, badges, feature, introduction_date, dim, sprite, palette, std::move(str), value, masked, shaded); + return std::make_unique(gui_classes, badges, feature, introduction_date, GetString(STR_JUST_CURRENCY_SHORT, cost), dim, sprite, palette, std::move(str), value, masked, shaded); } /** diff --git a/src/newgrf_badge_gui.h b/src/newgrf_badge_gui.h index e73186d951..b908cf7f55 100644 --- a/src/newgrf_badge_gui.h +++ b/src/newgrf_badge_gui.h @@ -50,8 +50,8 @@ private: int DrawBadgeNameList(Rect r, std::span badges, GrfSpecFeature feature); void DrawBadgeColumn(Rect r, int column_group, const GUIBadgeClasses &gui_classes, std::span badges, GrfSpecFeature feature, std::optional introduction_date, PaletteID remap); -std::unique_ptr MakeDropDownListBadgeItem(const std::shared_ptr &gui_classes, std::span badges, GrfSpecFeature feature, std::optional introduction_date, std::string &&str, int value, bool masked = false, bool shaded = false); -std::unique_ptr MakeDropDownListBadgeIconItem(const std::shared_ptr &gui_classes, std::span badges, GrfSpecFeature feature, std::optional introduction_date, const Dimension &dim, SpriteID sprite, PaletteID palette, std::string &&str, int value, bool masked = false, bool shaded = false); +std::unique_ptr MakeDropDownListBadgeItem(const std::shared_ptr &gui_classes, std::span badges, GrfSpecFeature feature, std::optional introduction_date, Money cost, std::string &&str, int value, bool masked = false, bool shaded = false); +std::unique_ptr MakeDropDownListBadgeIconItem(const std::shared_ptr &gui_classes, std::span badges, GrfSpecFeature feature, std::optional introduction_date, Money cost, const Dimension &dim, SpriteID sprite, PaletteID palette, std::string &&str, int value, bool masked = false, bool shaded = false); DropDownList BuildBadgeClassConfigurationList(const class GUIBadgeClasses &badge_class, uint columns, std::span column_separators); bool HandleBadgeConfigurationDropDownClick(GrfSpecFeature feature, uint columns, int result, int click_result, BadgeFilterChoices &choices); diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 3ff53b0648..a0d8688096 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -2065,12 +2065,12 @@ DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option) const RailTypeInfo *rti = GetRailTypeInfo(rt); if (for_replacement) { - list.push_back(MakeDropDownListBadgeItem(badge_class_list, rti->badges, GSF_RAILTYPES, rti->introduction_date, GetString(rti->strings.replace_text), rt, !avail_railtypes.Test(rt))); + list.push_back(MakeDropDownListBadgeItem(badge_class_list, rti->badges, GSF_RAILTYPES, rti->introduction_date, RailBuildCost(rt), GetString(rti->strings.replace_text), rt, !avail_railtypes.Test(rt))); } else { std::string str = rti->max_speed > 0 ? GetString(STR_TOOLBAR_RAILTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed) : GetString(rti->strings.menu_text); - list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_RAILTYPES, rti->introduction_date, d, rti->gui_sprites.build_x_rail, PAL_NONE, std::move(str), rt, !avail_railtypes.Test(rt))); + list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_RAILTYPES, rti->introduction_date, RailBuildCost(rt), d, rti->gui_sprites.build_x_rail, PAL_NONE, std::move(str), rt, !avail_railtypes.Test(rt))); } } diff --git a/src/road_gui.cpp b/src/road_gui.cpp index e3d29dbd38..3e37167a76 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -1805,12 +1805,12 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b const RoadTypeInfo *rti = GetRoadTypeInfo(rt); if (for_replacement) { - list.push_back(MakeDropDownListBadgeItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, GetString(rti->strings.replace_text), rt, !avail_roadtypes.Test(rt))); + list.push_back(MakeDropDownListBadgeItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, RoadBuildCost(rt), GetString(rti->strings.replace_text), rt, !avail_roadtypes.Test(rt))); } else { std::string str = rti->max_speed > 0 ? GetString(STR_TOOLBAR_RAILTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed / 2) : GetString(rti->strings.menu_text); - list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt))); + list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, RoadBuildCost(rt), d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt))); } } @@ -1854,7 +1854,7 @@ DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts) std::string str = rti->max_speed > 0 ? GetString(STR_TOOLBAR_RAILTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed / 2) : GetString(rti->strings.menu_text); - list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt))); + list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, RoadBuildCost(rt), d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt))); } if (list.empty()) {