Skip to content

Commit

Permalink
- use original menu spacing for skill and episode menus if all elemen…
Browse files Browse the repository at this point in the history
…ts are patches.
  • Loading branch information
coelckers committed Aug 10, 2021
1 parent f29eff5 commit 99c6607
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 10 deletions.
46 changes: 36 additions & 10 deletions src/menu/doommenu.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions wadsrc/static/menudef.txt
Expand Up @@ -209,6 +209,7 @@ ListMenu "EpisodeMenu"
{
Position 48, 63
StaticPatch 54, 38, "M_EPISOD", 0 , "$MNU_EPISODE"
linespacing 16
}
IfGame(Strife)
{
Expand All @@ -234,6 +235,7 @@ ListMenu "SkillMenu"
IfGame(Doom, Chex)
{
StaticPatch 96, 14, "M_NEWG", 0, "$MNU_NEWGAME"
linespacing 16
}
IfGame(Strife)
{
Expand Down
30 changes: 30 additions & 0 deletions wadsrc/static/zscript/engine/ui/menu/listmenu.zs
Expand Up @@ -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;
}
}


1 change: 1 addition & 0 deletions wadsrc/static/zscript/engine/ui/menu/menuitembase.zs
Expand Up @@ -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() {}
}

Expand Down

0 comments on commit 99c6607

Please sign in to comment.