From af59f7e254b18ea47d98112b5e64778e46d97923 Mon Sep 17 00:00:00 2001 From: staphen Date: Mon, 20 Dec 2021 16:20:00 -0500 Subject: [PATCH] Update fullscreen option in settings menu after Alt+Enter --- Source/DiabloUI/diabloui.cpp | 7 ++++++- Source/DiabloUI/diabloui.h | 2 +- Source/DiabloUI/selgame.cpp | 2 +- Source/DiabloUI/selhero.cpp | 2 +- Source/DiabloUI/selok.cpp | 2 +- Source/DiabloUI/selyesno.cpp | 2 +- Source/DiabloUI/settingsmenu.cpp | 22 +++++++++++++++++++++- 7 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index 268819573..cb2f05140 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -62,6 +62,7 @@ std::size_t listOffset = 0; void (*gfnListFocus)(int value); void (*gfnListSelect)(int value); void (*gfnListEsc)(); +void (*gfnFullscreen)(); bool (*gfnListYesNo)(); std::vector gUiItems; UiList *gUiList = nullptr; @@ -94,7 +95,7 @@ void AdjustListOffset(std::size_t itemIndex) } // namespace -void UiInitList(void (*fnFocus)(int value), void (*fnSelect)(int value), void (*fnEsc)(), const std::vector> &items, bool itemsWraps, bool (*fnYesNo)(), size_t selectedItem /*= 0*/) +void UiInitList(void (*fnFocus)(int value), void (*fnSelect)(int value), void (*fnEsc)(), const std::vector> &items, bool itemsWraps, void (*fnFullscreen)(), bool (*fnYesNo)(), size_t selectedItem /*= 0*/) { SelectedItem = selectedItem; SelectedItemMax = 0; @@ -102,6 +103,7 @@ void UiInitList(void (*fnFocus)(int value), void (*fnSelect)(int value), void (* gfnListFocus = fnFocus; gfnListSelect = fnSelect; gfnListEsc = fnEsc; + gfnFullscreen = fnFullscreen; gfnListYesNo = fnYesNo; gUiItems.clear(); for (const auto &item : items) @@ -162,6 +164,7 @@ void UiInitList_clear() gfnListFocus = nullptr; gfnListSelect = nullptr; gfnListEsc = nullptr; + gfnFullscreen = nullptr; gfnListYesNo = nullptr; gUiList = nullptr; gUiItems.clear(); @@ -445,6 +448,8 @@ void UiHandleEvents(SDL_Event *event) const Uint8 *state = SDLC_GetKeyState(); if (state[SDLC_KEYSTATE_LALT] != 0 || state[SDLC_KEYSTATE_RALT] != 0) { sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen()); + if (gfnFullscreen != nullptr) + gfnFullscreen(); return; } } diff --git a/Source/DiabloUI/diabloui.h b/Source/DiabloUI/diabloui.h index 6dde30075..c03ed1e79 100644 --- a/Source/DiabloUI/diabloui.h +++ b/Source/DiabloUI/diabloui.h @@ -118,7 +118,7 @@ void UiAddLogo(std::vector> *vecDialog, int size = L void UiFocusNavigationSelect(); void UiFocusNavigationEsc(); void UiFocusNavigationYesNo(); -void UiInitList(void (*fnFocus)(int value), void (*fnSelect)(int value), void (*fnEsc)(), const std::vector> &items, bool wraps = false, bool (*fnYesNo)() = NULL, size_t selectedItem = 0); +void UiInitList(void (*fnFocus)(int value), void (*fnSelect)(int value), void (*fnEsc)(), const std::vector> &items, bool wraps = false, void (*fnFullscreen)() = nullptr, bool (*fnYesNo)() = nullptr, size_t selectedItem = 0); void UiClearScreen(); void UiPollAndRender(); void UiRenderItems(const std::vector &items); diff --git a/Source/DiabloUI/selgame.cpp b/Source/DiabloUI/selgame.cpp index d1c64c94b..b328b0b9e 100644 --- a/Source/DiabloUI/selgame.cpp +++ b/Source/DiabloUI/selgame.cpp @@ -121,7 +121,7 @@ void selgame_GameSelection_Init() int itemValue = vecSelGameDlgItems[index]->m_value; selgame_GameSelection_Select(itemValue); }; - UiInitList(selgame_GameSelection_Focus, selectFn, selgame_GameSelection_Esc, vecSelGameDialog, true, nullptr, HighlightedItem); + UiInitList(selgame_GameSelection_Focus, selectFn, selgame_GameSelection_Esc, vecSelGameDialog, true, nullptr, nullptr, HighlightedItem); } void selgame_GameSelection_Focus(int value) diff --git a/Source/DiabloUI/selhero.cpp b/Source/DiabloUI/selhero.cpp index 0dc4d00ef..ebd8cb4bc 100644 --- a/Source/DiabloUI/selhero.cpp +++ b/Source/DiabloUI/selhero.cpp @@ -498,7 +498,7 @@ void selhero_List_Init() SDL_Rect rect5 = { (Sint16)(PANEL_LEFT + 489), (Sint16)(UI_OFFSET_Y + 429), 120, 35 }; vecSelDlgItems.push_back(std::make_unique(_("Cancel"), &UiFocusNavigationEsc, rect5, UiFlags::AlignCenter | UiFlags::FontSize30 | UiFlags::ColorUiGold)); - UiInitList(SelheroListFocus, SelheroListSelect, SelheroListEsc, vecSelDlgItems, false, SelheroListDeleteYesNo, selectedItem); + UiInitList(SelheroListFocus, SelheroListSelect, SelheroListEsc, vecSelDlgItems, false, nullptr, SelheroListDeleteYesNo, selectedItem); if (selhero_isMultiPlayer) { title = _("Multi Player Characters"); } else { diff --git a/Source/DiabloUI/selok.cpp b/Source/DiabloUI/selok.cpp index b739547f1..87bc6aaa6 100644 --- a/Source/DiabloUI/selok.cpp +++ b/Source/DiabloUI/selok.cpp @@ -70,7 +70,7 @@ void UiSelOkDialog(const char *title, const char *body, bool background) strcpy(dialogText, WordWrapString(body, MESSAGE_WIDTH, GameFont24).c_str()); - UiInitList(nullptr, selok_Select, selok_Esc, vecSelOkDialog, false, nullptr); + UiInitList(nullptr, selok_Select, selok_Esc, vecSelOkDialog, false); selok_endMenu = false; while (!selok_endMenu) { diff --git a/Source/DiabloUI/selyesno.cpp b/Source/DiabloUI/selyesno.cpp index ee9027e91..b126de724 100644 --- a/Source/DiabloUI/selyesno.cpp +++ b/Source/DiabloUI/selyesno.cpp @@ -57,7 +57,7 @@ bool UiSelHeroYesNoDialog(const char *title, const char *body) strcpy(selyesno_confirmationMessage, WordWrapString(body, MESSAGE_WIDTH, GameFont24).c_str()); - UiInitList(nullptr, SelyesnoSelect, SelyesnoEsc, vecSelYesNoDialog, true, nullptr); + UiInitList(nullptr, SelyesnoSelect, SelyesnoEsc, vecSelYesNoDialog, true); selyesno_value = true; selyesno_endMenu = false; diff --git a/Source/DiabloUI/settingsmenu.cpp b/Source/DiabloUI/settingsmenu.cpp index 2c033e0a4..97562cd1f 100644 --- a/Source/DiabloUI/settingsmenu.cpp +++ b/Source/DiabloUI/settingsmenu.cpp @@ -181,6 +181,26 @@ void EscPressed() GoBackOneMenuLevel(); } +void FullscreenChanged() +{ + auto *fullscreenOption = &sgOptions.Graphics.fullscreen; + + for (auto &vecItem : vecDialogItems) { + int vecItemValue = vecItem->m_value; + if (vecItemValue < 0) + continue; + + auto *pOption = vecOptions[vecItemValue]; + if (pOption != fullscreenOption) + continue; + + vecItem->args.clear(); + for (auto &arg : CreateDrawStringFormatArgForEntry(pOption)) + vecItem->args.push_back(arg); + break; + } +} + } // namespace void UiSettingsMenu() @@ -247,7 +267,7 @@ void UiSettingsMenu() vecDialog.push_back(std::make_unique(vecDialogItems, rectList.size.height / 26, rectList.position.x, rectList.position.y, rectList.size.width, 26, UiFlags::FontSize24 | UiFlags::AlignCenter)); - UiInitList(ItemFocused, ItemSelected, EscPressed, vecDialog, true, nullptr, itemToSelect); + UiInitList(ItemFocused, ItemSelected, EscPressed, vecDialog, true, FullscreenChanged, nullptr, itemToSelect); while (!endMenu) { UiClearScreen();