From 3512fe8fba96d22f8ba0fbec6d015ca7b0cc7ab4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 26 Jun 2021 11:58:40 +0200 Subject: [PATCH] - dynamically adjust SW's menu spacing based on language. --- wadsrc/static/menudef.txt | 5 +++- .../static/zscript/engine/ui/menu/listmenu.zs | 30 +++++++++++++++++++ .../zscript/engine/ui/menu/menuitembase.zs | 1 + wadsrc/static/zscript/games/sw/ui/menu.zs | 17 +++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index f794c1cb9..76e9fb737 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -44,7 +44,8 @@ LISTMENU "MainMenu" ifgame(ShadowWarrior) { Position 55, 32 - Linespacing 21 + Linespacing 17 + class SWMainMenu SWLogo SWTextItem "$MNU_NEWGAME", "n", "EpisodeMenu" SWTextItem "$MNU_LOADGAME", "l", "LoadGameMenu" @@ -116,6 +117,7 @@ LISTMENU "IngameMenu" { Position 55, 32 Linespacing 17 + class SWMainMenu SWLogo SWTextItem "$MNU_NEWGAME", "n", "EpisodeMenu" SWTextItem "$MNU_LOADGAME", "l", "LoadGameMenu" @@ -195,6 +197,7 @@ LISTMENU "SkillMenu" } ifgame(ShadowWarrior) { + class SWMainMenu CaptionItem "$MNU_DIFFICULTY" Position 35, 32 Linespacing 17 diff --git a/wadsrc/static/zscript/engine/ui/menu/listmenu.zs b/wadsrc/static/zscript/engine/ui/menu/listmenu.zs index c8a8a0f2e..dc12f4129 100644 --- a/wadsrc/static/zscript/engine/ui/menu/listmenu.zs +++ b/wadsrc/static/zscript/engine/ui/menu/listmenu.zs @@ -328,6 +328,36 @@ class ListMenu : Menu { mFocusControl = NULL; } + + //============================================================================= + // + // + // + //============================================================================= + + void ChangeLineSpacing(int newspace) + { + double top = -32767; + + for (int i = 0; i < mDesc.mItems.Size(); i++) + { + let selitem = ListMenuItemSelectable(mDesc.mItems[i]); + if (selitem) + { + let y = mDesc.mItems[i].GetY(); + if (top == -32767) + { + top = y; + } + else + { + let newy = top + (y - top) / mDesc.mLineSpacing * newspace; + mDesc.mItems[i].SetY(newy); + } + } + } + mDesc.mLineSpacing = newspace; + } } diff --git a/wadsrc/static/zscript/engine/ui/menu/menuitembase.zs b/wadsrc/static/zscript/engine/ui/menu/menuitembase.zs index 53a32e47f..2169e9fac 100644 --- a/wadsrc/static/zscript/engine/ui/menu/menuitembase.zs +++ b/wadsrc/static/zscript/engine/ui/menu/menuitembase.zs @@ -40,6 +40,7 @@ class MenuItemBase : Object native ui version("2.4") double GetY() { return mYpos; } double GetX() { return mXpos; } void SetX(double x) { mXpos = x; } + void SetY(double x) { mYpos = x; } virtual void OnMenuCreated() {} } diff --git a/wadsrc/static/zscript/games/sw/ui/menu.zs b/wadsrc/static/zscript/games/sw/ui/menu.zs index 1be722880..f5fcb0aa7 100644 --- a/wadsrc/static/zscript/games/sw/ui/menu.zs +++ b/wadsrc/static/zscript/games/sw/ui/menu.zs @@ -55,6 +55,23 @@ class SWMenuDelegate : RazeMenuDelegate } } +//============================================================================= +// +// +// +//============================================================================= + +class SWMainMenu : ListMenu +{ + override void Drawer() + { + let p = StringTable.Localize("REQUIRED_CHARACTERS", false); + int newls = (p == "REQUIRED_CHARACTERS")? 17 : 21; + if (newls != mDesc.mLineSpacing) ChangeLineSpacing(newls); + super.Drawer(); + } +} + //============================================================================= // // logo