From 99c66071fb8b2be84eac674bf6c2b07a7bd574da Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 10 Aug 2021 21:08:26 +0200 Subject: [PATCH] - use original menu spacing for skill and episode menus if all elements are patches. --- src/menu/doommenu.cpp | 46 +++++++++++++++---- wadsrc/static/menudef.txt | 2 + .../static/zscript/engine/ui/menu/listmenu.zs | 30 ++++++++++++ .../zscript/engine/ui/menu/menuitembase.zs | 1 + 4 files changed, 69 insertions(+), 10 deletions(-) diff --git a/src/menu/doommenu.cpp b/src/menu/doommenu.cpp index 8a8e9cf8a8..652530a64a 100644 --- a/src/menu/doommenu.cpp +++ b/src/menu/doommenu.cpp @@ -571,8 +571,21 @@ void M_StartupEpisodeMenu(FNewGameStartup *gs) if (y < topy) topy = y; } + int spacing = ld->mLinespacing; + for (unsigned i = 0; i < AllEpisodes.Size(); i++) + { + if (AllEpisodes[i].mPicName.IsNotEmpty()) + { + FTextureID tex = GetMenuTexture(AllEpisodes[i].mPicName); + if (AllEpisodes[i].mEpisodeName.IsEmpty() || OkForLocalization(tex, AllEpisodes[i].mEpisodeName)) + continue; + } + if ((gameinfo.gametype & GAME_DoomStrifeChex) && spacing == 16) spacing = 18; + break; + } + // center the menu on the screen if the top space is larger than the bottom space - int totalheight = posy + AllEpisodes.Size() * ld->mLinespacing - topy; + int totalheight = posy + AllEpisodes.Size() * spacing - topy; if (totalheight < 190 || AllEpisodes.Size() == 1) { @@ -613,15 +626,15 @@ void M_StartupEpisodeMenu(FNewGameStartup *gs) { FTextureID tex = GetMenuTexture(AllEpisodes[i].mPicName); if (AllEpisodes[i].mEpisodeName.IsEmpty() || OkForLocalization(tex, AllEpisodes[i].mEpisodeName)) - it = CreateListMenuItemPatch(posx, posy, ld->mLinespacing, AllEpisodes[i].mShortcut, tex, NAME_Skillmenu, i); + it = CreateListMenuItemPatch(posx, posy, spacing, AllEpisodes[i].mShortcut, tex, NAME_Skillmenu, i); } if (it == nullptr) { - it = CreateListMenuItemText(posx, posy, ld->mLinespacing, AllEpisodes[i].mShortcut, + it = CreateListMenuItemText(posx, posy, spacing, AllEpisodes[i].mShortcut, AllEpisodes[i].mEpisodeName, ld->mFont, ld->mFontColor, ld->mFontColor2, NAME_Skillmenu, i); } ld->mItems.Push(it); - posy += ld->mLinespacing; + posy += spacing; } if (AllEpisodes.Size() == 1) { @@ -1073,9 +1086,10 @@ void M_StartupSkillMenu(FNewGameStartup *gs) } } - if (done != restart) + int spacing = ld->mLinespacing; + //if (done != restart) { - done = restart; + //done = restart; ld->mSelectedItem = ld->mItems.Size() + defindex; int posy = y; @@ -1088,8 +1102,20 @@ void M_StartupSkillMenu(FNewGameStartup *gs) if (y < topy) topy = y; } + for (unsigned i = 0; i < MenuSkills.Size(); i++) + { + if (MenuSkills[i]->PicName.IsNotEmpty()) + { + FTextureID tex = GetMenuTexture(MenuSkills[i]->PicName); + if (MenuSkills[i]->MenuName.IsEmpty() || OkForLocalization(tex, MenuSkills[i]->MenuName)) + continue; + } + if ((gameinfo.gametype & GAME_DoomStrifeChex) && spacing == 16) spacing = 18; + break; + } + // center the menu on the screen if the top space is larger than the bottom space - int totalheight = posy + MenuSkills.Size() * ld->mLinespacing - topy; + int totalheight = posy + MenuSkills.Size() * spacing - topy; if (totalheight < 190 || MenuSkills.Size() == 1) { @@ -1157,16 +1183,16 @@ void M_StartupSkillMenu(FNewGameStartup *gs) { FTextureID tex = GetMenuTexture(skill.PicName); if (skill.MenuName.IsEmpty() || OkForLocalization(tex, skill.MenuName)) - li = CreateListMenuItemPatch(posx, y, ld->mLinespacing, skill.Shortcut, tex, action, SkillIndices[i]); + li = CreateListMenuItemPatch(posx, y, spacing, skill.Shortcut, tex, action, SkillIndices[i]); } if (li == nullptr) { - li = CreateListMenuItemText(posx, y, ld->mLinespacing, skill.Shortcut, + li = CreateListMenuItemText(posx, y, spacing, skill.Shortcut, pItemText? *pItemText : skill.MenuName, ld->mFont, color,ld->mFontColor2, action, SkillIndices[i]); } ld->mItems.Push(li); GC::WriteBarrier(*desc, li); - y += ld->mLinespacing; + y += spacing; } if (AllEpisodes[gs->Episode].mNoSkill || MenuSkills.Size() == 1) { diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index b3d8bd4c52..1725da9dd7 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -209,6 +209,7 @@ ListMenu "EpisodeMenu" { Position 48, 63 StaticPatch 54, 38, "M_EPISOD", 0 , "$MNU_EPISODE" + linespacing 16 } IfGame(Strife) { @@ -234,6 +235,7 @@ ListMenu "SkillMenu" IfGame(Doom, Chex) { StaticPatch 96, 14, "M_NEWG", 0, "$MNU_NEWGAME" + linespacing 16 } IfGame(Strife) { diff --git a/wadsrc/static/zscript/engine/ui/menu/listmenu.zs b/wadsrc/static/zscript/engine/ui/menu/listmenu.zs index c8a8a0f2ec..dc12f41292 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 53a32e47f1..2169e9fac6 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() {} }