From 150a4edfdbd9edfc69e547d808575d9812b487d2 Mon Sep 17 00:00:00 2001 From: obligaron Date: Thu, 6 Jan 2022 17:59:51 +0100 Subject: [PATCH] Settingsmenu: Use two lines if text doesn't fix in one line --- Source/DiabloUI/settingsmenu.cpp | 34 ++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Source/DiabloUI/settingsmenu.cpp b/Source/DiabloUI/settingsmenu.cpp index 6d676f64a..399b36687 100644 --- a/Source/DiabloUI/settingsmenu.cpp +++ b/Source/DiabloUI/settingsmenu.cpp @@ -32,6 +32,7 @@ ShownMenuType shownMenu; char optionDescription[512]; +Rectangle rectList; Rectangle rectDescription; enum class SpecialMenuEntry { @@ -58,6 +59,12 @@ std::vector CreateDrawStringFormatArgForEntry(OptionEntryBa }; } +/** @brief Check if the option text can't fit in one list line (list width minus drawn selector) */ +bool NeedsTwoLinesToDisplayOption(std::vector &formatArgs) +{ + return GetLineWidth("{}: {}", formatArgs.data(), formatArgs.size(), GameFontTables::GameFont24, 1) >= (rectList.size.width - 90); +} + void CleanUpSettingsUI() { UiInitList_clear(); @@ -177,9 +184,19 @@ void ItemSelected(int value) updateValueDescription = ChangeOptionValue(pOption, 0); } if (updateValueDescription) { - vecItem->args.clear(); - for (auto &arg : CreateDrawStringFormatArgForEntry(pOption)) - vecItem->args.push_back(arg); + auto args = CreateDrawStringFormatArgForEntry(pOption); + bool optionUsesTwoLines = ((value + 1) < vecDialogItems.size() && vecDialogItems[value]->m_value == vecDialogItems[value + 1]->m_value); + if (NeedsTwoLinesToDisplayOption(args) != optionUsesTwoLines) { + selectedOption = pOption; + endMenu = true; + } else { + vecItem->args.clear(); + for (auto &arg : args) + vecItem->args.push_back(arg); + if (optionUsesTwoLines) { + vecDialogItems[value + 1]->m_text = pOption->GetValueDescription().data(); + } + } } } break; case ShownMenuType::ListOption: { @@ -230,7 +247,7 @@ void UiSettingsMenu() UiAddBackground(&vecDialog); UiAddLogo(&vecDialog); - Rectangle rectList = { { PANEL_LEFT + 50, (UI_OFFSET_Y + 204) }, { 540, 208 } }; + rectList = { { PANEL_LEFT + 50, (UI_OFFSET_Y + 204) }, { 540, 208 } }; rectDescription = { { PANEL_LEFT + 24, rectList.position.y + rectList.size.height + 16 }, { 590, 35 } }; optionDescription[0] = '\0'; @@ -258,10 +275,15 @@ void UiSettingsMenu() vecDialogItems.push_back(std::make_unique(pCategory->GetName().data(), static_cast(SpecialMenuEntry::None), UiFlags::ColorWhitegold | UiFlags::ElementDisabled)); categoryCreated = true; } - auto formatArgs = CreateDrawStringFormatArgForEntry(pEntry); if (selectedOption == pEntry) itemToSelect = vecDialogItems.size(); - vecDialogItems.push_back(std::make_unique("{}: {}", formatArgs, vecOptions.size(), UiFlags::ColorUiGold)); + auto formatArgs = CreateDrawStringFormatArgForEntry(pEntry); + if (NeedsTwoLinesToDisplayOption(formatArgs)) { + vecDialogItems.push_back(std::make_unique("{}:", formatArgs, vecOptions.size(), UiFlags::ColorUiGold | UiFlags::NeedsNextElement)); + vecDialogItems.push_back(std::make_unique(pEntry->GetValueDescription().data(), vecOptions.size(), UiFlags::ColorUiSilver | UiFlags::ElementDisabled)); + } else { + vecDialogItems.push_back(std::make_unique("{}: {}", formatArgs, vecOptions.size(), UiFlags::ColorUiGold)); + } vecOptions.push_back(pEntry); } }