From 5e43aaff354c963b42a7e9a62aecfc28defad063 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 17 Feb 2025 17:27:57 +0000 Subject: [PATCH] Add: Also show badges in fund industry list. (#13590) --- src/industry_gui.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 165a3f4e57..f777b9aebd 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -311,6 +311,7 @@ class BuildIndustryWindow : public Window { bool enabled; ///< Availability state of the selected industry. Scrollbar *vscroll; Dimension legend; ///< Dimension of the legend 'blob'. + GUIBadgeClasses badge_classes{GSF_INDUSTRIES}; /** The largest allowed minimum-width of the window, given in line heights */ static const int MAX_MINWIDTH_LINEHEIGHTS = 20; @@ -436,7 +437,7 @@ public: d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(indtype)->name)); } resize.height = std::max({this->legend.height, d.height, count.height}) + padding.height; - d.width += this->legend.width + WidgetDimensions::scaled.hsep_wide + WidgetDimensions::scaled.hsep_normal + count.width + padding.width; + d.width += this->badge_classes.GetTotalColumnsWidth() + this->legend.width + WidgetDimensions::scaled.hsep_wide + WidgetDimensions::scaled.hsep_normal + count.width + padding.width; d.height = 5 * resize.height; size = maxdim(size, d); break; @@ -533,18 +534,30 @@ public: icon.top = r.top + (this->resize.step_height - this->legend.height + 1) / 2; icon.bottom = icon.top + this->legend.height - 1; + auto badge_column_widths = badge_classes.GetColumnWidths(); + auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->list); for (auto it = first; it != last; ++it) { IndustryType type = *it; bool selected = this->selected_type == type; const IndustrySpec *indsp = GetIndustrySpec(type); + Rect tr = text; + if (badge_column_widths.size() >= 1 && badge_column_widths[0] > 0) { + DrawBadgeColumn(tr.WithWidth(badge_column_widths[0], rtl), 0, this->badge_classes, indsp->badges, GSF_INDUSTRIES, std::nullopt, PAL_NONE); + tr = tr.Indent(badge_column_widths[0], rtl); + } + if (badge_column_widths.size() >= 2 && badge_column_widths[1] > 0) { + DrawBadgeColumn(tr.WithWidth(badge_column_widths[1], !rtl), 0, this->badge_classes, indsp->badges, GSF_INDUSTRIES, std::nullopt, PAL_NONE); + tr = tr.Indent(badge_column_widths[1], !rtl); + } + /* Draw the name of the industry in white is selected, otherwise, in orange */ - DrawString(text, indsp->name, selected ? TC_WHITE : TC_ORANGE); + DrawString(tr, indsp->name, selected ? TC_WHITE : TC_ORANGE); GfxFillRect(icon, selected ? PC_WHITE : PC_BLACK); GfxFillRect(icon.Shrink(WidgetDimensions::scaled.bevel), indsp->map_colour); SetDParam(0, Industry::GetIndustryTypeCount(type)); - DrawString(text, STR_JUST_COMMA, TC_BLACK, SA_RIGHT, false, FS_SMALL); + DrawString(tr, STR_JUST_COMMA, TC_BLACK, SA_RIGHT, false, FS_SMALL); text = text.Translate(0, this->resize.step_height); icon = icon.Translate(0, this->resize.step_height);