Skip to content

Commit

Permalink
Extended MENUDEF Functionality
Browse files Browse the repository at this point in the history
*Added Font and TextureID types to Option and Image Scroller items (List items already have these)
*Added "Class" instruction for Image Scrollers
*Added ability for Option items to read in their OptionMenuDescriptor (List and Image Scroller items already have this)
*Added "ForceList" instruction for Lists so that skill, playerclass, and episode menus don't get overridden
  • Loading branch information
Boondorl authored and coelckers committed Nov 22, 2022
1 parent 63c2d93 commit 599b00f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/common/menu/menu.h
Expand Up @@ -94,6 +94,7 @@ class DListMenuDescriptor : public DMenuDescriptor
int mVirtWidth;
int mVirtHeight;
bool mCustomSizeSet;
bool mForceList;

void Reset();
};
Expand Down
59 changes: 58 additions & 1 deletion src/common/menu/menudef.cpp
Expand Up @@ -419,6 +419,10 @@ static void DoParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc, bool &s
}
}
}
else if (sc.Compare("ForceList"))
{
desc->mForceList = true;
}
else
{
// all item classes from which we know that they support sized scaling.
Expand Down Expand Up @@ -759,6 +763,7 @@ static void ParseListMenu(FScanner &sc)
desc->mFromEngine = fileSystem.GetFileContainer(sc.LumpNum) == 0; // flags menu if the definition is from the IWAD.
desc->mVirtWidth = -2;
desc->mCustomSizeSet = false;
desc->mForceList = false;
if (DefaultListMenuSettings->mCustomSizeSet)
{
desc->mVirtHeight = DefaultListMenuSettings->mVirtHeight;
Expand Down Expand Up @@ -1028,13 +1033,19 @@ static void ParseOptionMenuBody(FScanner &sc, DOptionMenuDescriptor *desc, int i
{
auto &args = func->Variants[0].Proto->ArgumentTypes;
TArray<VMValue> params;
int start = 1;

params.Push(0);
if (args.Size() > 1 && args[1] == NewPointer(PClass::FindClass("OptionMenuDescriptor")))
{
params.Push(desc);
start = 2;
}
auto TypeCVar = NewPointer(NewStruct("CVar", nullptr, true));

// Note that this array may not be reallocated so its initial size must be the maximum possible elements.
TArray<FString> strings(args.Size());
for (unsigned i = 1; i < args.Size(); i++)
for (unsigned i = start; i < args.Size(); i++)
{
sc.MustGetString();
if (args[i] == TypeString)
Expand All @@ -1050,6 +1061,24 @@ static void ParseOptionMenuBody(FScanner &sc, DOptionMenuDescriptor *desc, int i
{
params.Push(V_GetColor(sc));
}
else if (args[i] == TypeFont)
{
auto f = V_GetFont(sc.String);
if (f == nullptr)
{
sc.ScriptError("Unknown font %s", sc.String);
}
params.Push(f);
}
else if (args[i] == TypeTextureID)
{
auto f = TexMan.CheckForTexture(sc.String, ETextureType::MiscPatch);
if (!f.Exists())
{
sc.ScriptMessage("Unknown texture %s", sc.String);
}
params.Push(f.GetIndex());
}
else if (args[i]->isIntCompatible())
{
char *endp;
Expand Down Expand Up @@ -1228,6 +1257,16 @@ static void ParseImageScrollerBody(FScanner& sc, DImageScrollerDescriptor* desc)
ParseImageScrollerBody(sc, desc);
}
}
else if (sc.Compare("Class"))
{
sc.MustGetString();
PClass* cls = PClass::FindClass(sc.String);
if (cls == nullptr || !cls->IsDescendantOf("ImageScrollerMenu"))
{
sc.ScriptError("Unknown menu class '%s'", sc.String);
}
desc->mClass = cls;
}
else if (sc.Compare("animatedtransition"))
{
desc->mAnimatedTransition = true;
Expand Down Expand Up @@ -1300,6 +1339,24 @@ static void ParseImageScrollerBody(FScanner& sc, DImageScrollerDescriptor* desc)
{
params.Push(V_GetColor(sc));
}
else if (args[i] == TypeFont)
{
auto f = V_GetFont(sc.String);
if (f == nullptr)
{
sc.ScriptError("Unknown font %s", sc.String);
}
params.Push(f);
}
else if (args[i] == TypeTextureID)
{
auto f = TexMan.CheckForTexture(sc.String, ETextureType::MiscPatch);
if (!f.Exists())
{
sc.ScriptMessage("Unknown texture %s", sc.String);
}
params.Push(f.GetIndex());
}
else if (args[i]->isIntCompatible())
{
char* endp;
Expand Down
12 changes: 6 additions & 6 deletions src/menu/doommenu.cpp
Expand Up @@ -616,9 +616,9 @@ void M_StartupEpisodeMenu(FNewGameStartup *gs)
// center the menu on the screen if the top space is larger than the bottom space
int totalheight = posy + AllEpisodes.Size() * spacing - topy;

if (totalheight < 190 || AllEpisodes.Size() == 1)
if (ld->mForceList || totalheight < 190 || AllEpisodes.Size() == 1)
{
int newtop = (200 - totalheight) / 2;
int newtop = max(10, 200 - totalheight) / 2;
int topdelta = newtop - topy;
if (topdelta < 0)
{
Expand Down Expand Up @@ -760,9 +760,9 @@ static void BuildPlayerclassMenu()
ld->mAutoselect = ld->mItems.Push(it);
success = true;
}
else if (totalheight <= 190)
else if (ld->mForceList || totalheight <= 190)
{
int newtop = (200 - totalheight + topy) / 2;
int newtop = (max(10, 200 - totalheight) + topy) / 2;
int topdelta = newtop - topy;
if (topdelta < 0)
{
Expand Down Expand Up @@ -1146,9 +1146,9 @@ void M_StartupSkillMenu(FNewGameStartup *gs)
// center the menu on the screen if the top space is larger than the bottom space
int totalheight = posy + MenuSkills.Size() * spacing - topy;

if (totalheight < 190 || MenuSkills.Size() == 1)
if (ld->mForceList || totalheight < 190 || MenuSkills.Size() == 1)
{
int newtop = (200 - totalheight) / 2;
int newtop = max(10, 200 - totalheight) / 2;
int topdelta = newtop - topy;
if (topdelta < 0)
{
Expand Down

0 comments on commit 599b00f

Please sign in to comment.