From ba7cd3e1cb8a3ea90481519ef6b3dedee754ad0d Mon Sep 17 00:00:00 2001 From: obligaron Date: Thu, 25 Nov 2021 00:58:43 +0100 Subject: [PATCH] Use DrawStringWithColors in settingsmenu --- Source/DiabloUI/settingsmenu.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Source/DiabloUI/settingsmenu.cpp b/Source/DiabloUI/settingsmenu.cpp index 6569bc4e1..2bc38b922 100644 --- a/Source/DiabloUI/settingsmenu.cpp +++ b/Source/DiabloUI/settingsmenu.cpp @@ -3,6 +3,7 @@ #include "DiabloUI/diabloui.h" #include "DiabloUI/scrollbar.h" #include "control.h" +#include "engine/render/text_render.hpp" #include "hwcursor.hpp" #include "options.h" #include "utils/language.h" @@ -33,6 +34,14 @@ bool IsValidEntry(OptionEntryBase *pOptionEntry) return HasNoneOf(pOptionEntry->GetFlags(), OptionEntryFlags::Invisible | (gbIsHellfire ? OptionEntryFlags::OnlyDiablo : OptionEntryFlags::OnlyHellfire)); } +std::vector CreateDrawStringFormatArgForEntry(OptionEntryBase *pEntry) +{ + return std::vector { + { pEntry->GetName().data(), UiFlags::ColorUiGold }, + { pEntry->GetValueDescription().data(), UiFlags::ColorUiSilver } + }; +} + void ItemFocused(int value) { auto &vecItem = vecDialogItems[value]; @@ -51,6 +60,8 @@ void ItemSelected(int value) if (vecItem->m_value < 0) { auto specialMenuEntry = static_cast(vecItem->m_value); switch (specialMenuEntry) { + case SpecialMenuEntry::None: + break; case SpecialMenuEntry::PreviousMenu: endMenu = true; break; @@ -83,7 +94,9 @@ void ItemSelected(int value) pOptionList->SetActiveListIndex(nextIndex); } break; } - vecDialogItems[value + 1]->m_text = pOption->GetValueDescription().data(); + vecDialogItems[value]->args.clear(); + for (auto &arg : CreateDrawStringFormatArgForEntry(pOption)) + vecDialogItems[value]->args.push_back(arg); } void EscPressed() @@ -132,8 +145,8 @@ void UiSettingsMenu() vecDialogItems.push_back(std::make_unique(pCategory->GetName().data(), static_cast(SpecialMenuEntry::None), UiFlags::ColorWhitegold | UiFlags::ElementDisabled)); categoryCreated = true; } - vecDialogItems.push_back(std::make_unique(pEntry->GetName().data(), vecOptions.size(), UiFlags::ColorUiGold | UiFlags::NeedsNextElement)); - vecDialogItems.push_back(std::make_unique(pEntry->GetValueDescription().data(), vecOptions.size(), UiFlags::ColorUiSilver | UiFlags::ElementDisabled)); + auto formatArgs = CreateDrawStringFormatArgForEntry(pEntry); + vecDialogItems.push_back(std::make_unique("{}: {}", formatArgs, vecOptions.size(), UiFlags::ColorUiGold)); vecOptions.push_back(pEntry); } }