- work on menu transitions.

This commit is contained in:
Christoph Oelckers 2020-10-08 01:00:23 +02:00
parent a7e25a116f
commit cc7290e313
4 changed files with 56 additions and 31 deletions

View file

@ -101,6 +101,7 @@ static bool MenuEnabled = true;
DMenu *CurrentMenu; DMenu *CurrentMenu;
int MenuTime; int MenuTime;
DObject* menuDelegate; DObject* menuDelegate;
static MenuTransition transition;
extern PClass *DefaultListMenuClass; extern PClass *DefaultListMenuClass;
@ -193,6 +194,8 @@ void M_MarkMenus()
} }
GC::Mark(CurrentMenu); GC::Mark(CurrentMenu);
GC::Mark(menuDelegate); GC::Mark(menuDelegate);
GC::Mark(transition.previous);
GC::Mark(transition.current);
} }
@ -202,8 +205,6 @@ void M_MarkMenus()
// //
//============================================================================ //============================================================================
static MenuTransition transition;
bool MenuTransition::StartTransition(DMenu* from, DMenu* to, MenuTransitionType animtype) bool MenuTransition::StartTransition(DMenu* from, DMenu* to, MenuTransitionType animtype)
{ {
if (!from->canAnimate() || !to->canAnimate() || animtype == MA_None) if (!from->canAnimate() || !to->canAnimate() || animtype == MA_None)
@ -215,10 +216,11 @@ bool MenuTransition::StartTransition(DMenu* from, DMenu* to, MenuTransitionType
start = I_GetTimeNS() * (120. / 1'000'000'000.); start = I_GetTimeNS() * (120. / 1'000'000'000.);
length = 30; length = 30;
dir = animtype == MA_Advance ? 1 : -1; dir = animtype == MA_Advance ? 1 : -1;
destroyprev = animtype == MA_Return;
previous = from; previous = from;
current = to; current = to;
if (from) GC::AddSoftRoot(from); if (from) GC::WriteBarrier(from);
if (to) GC::AddSoftRoot(to); if (to) GC::WriteBarrier(to);
return true; return true;
} }
} }
@ -241,8 +243,9 @@ bool MenuTransition::Draw()
current->CallDrawer(); current->CallDrawer();
return true; return true;
} }
if (previous) GC::DelSoftRoot(previous); if (destroyprev && previous) previous->Destroy();
if (current) GC::DelSoftRoot(current); previous = nullptr;
current = nullptr;
return false; return false;
} }
@ -352,27 +355,24 @@ void DMenu::Close ()
assert(CurrentMenu == this); assert(CurrentMenu == this);
CurrentMenu = mParentMenu; CurrentMenu = mParentMenu;
if (false)// todo: && mParentMenu && transition.StartTransition(this, mParentMenu, MA_Return)) if (CurrentMenu != nullptr)
{ {
return; GC::WriteBarrier(CurrentMenu);
IFVIRTUALPTR(CurrentMenu, DMenu, OnReturn)
{
VMValue params[] = { CurrentMenu };
VMCall(func, params, 1, nullptr, 0);
}
if (transition.StartTransition(this, CurrentMenu, MA_Return))
{
return;
}
} }
else
{
Destroy();
if (CurrentMenu != nullptr)
{
GC::WriteBarrier(CurrentMenu);
IFVIRTUALPTR(CurrentMenu, DMenu, OnReturn)
{
VMValue params[] = { CurrentMenu };
VMCall(func, params, 1, nullptr, 0);
}
} Destroy();
else if (CurrentMenu == nullptr)
{ {
M_ClearMenus(); M_ClearMenus();
}
} }
} }
@ -474,7 +474,7 @@ void M_ActivateMenu(DMenu *menu)
CurrentMenu->mMouseCapture = false; CurrentMenu->mMouseCapture = false;
I_ReleaseMouseCapture(); I_ReleaseMouseCapture();
} }
//transition.StartTransition(CurrentMenu, menu, MA_Advance); transition.StartTransition(CurrentMenu, menu, MA_Advance);
} }
CurrentMenu = menu; CurrentMenu = menu;
GC::WriteBarrier(CurrentMenu); GC::WriteBarrier(CurrentMenu);
@ -826,10 +826,25 @@ void M_Drawer (void)
{ {
if (sysCallbacks.MenuDim) sysCallbacks.MenuDim(); if (sysCallbacks.MenuDim) sysCallbacks.MenuDim();
} }
CurrentMenu->CallDrawer(); bool going = false;
if (transition.previous)
{
going = transition.Draw();
if (!going)
{
if (transition.dir == -1) delete transition.previous;
transition.previous = nullptr;
transition.current = nullptr;
}
}
if (!going)
{
CurrentMenu->CallDrawer();
}
} }
} }
//============================================================================= //=============================================================================
// //
// //
@ -838,6 +853,9 @@ void M_Drawer (void)
void M_ClearMenus() void M_ClearMenus()
{ {
transition.previous = transition.current = nullptr;
transition.dir = 0;
while (CurrentMenu != nullptr) while (CurrentMenu != nullptr)
{ {
DMenu* parent = CurrentMenu->mParentMenu; DMenu* parent = CurrentMenu->mParentMenu;

View file

@ -89,6 +89,8 @@ public:
EColorRange mFontColor2; EColorRange mFontColor2;
bool mCenter; bool mCenter;
bool mFromEngine; bool mFromEngine;
bool mAnimated;
bool mAnimatedTransition;
int mVirtWidth; int mVirtWidth;
int mVirtHeight; int mVirtHeight;
@ -181,7 +183,8 @@ struct MenuTransition
double start; double start;
int32_t length; int32_t length;
int32_t dir; int8_t dir;
bool destroyprev;
bool StartTransition(DMenu* from, DMenu* to, MenuTransitionType animtype); bool StartTransition(DMenu* from, DMenu* to, MenuTransitionType animtype);
bool Draw(); bool Draw();

View file

@ -341,6 +341,10 @@ static void ParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc)
{ {
desc->mCenter = true; desc->mCenter = true;
} }
else if (sc.Compare("animatedtransition"))
{
desc->mAnimatedTransition = true;
}
else if (sc.Compare("MouseWindow")) else if (sc.Compare("MouseWindow"))
{ {
sc.MustGetNumber(); sc.MustGetNumber();

View file

@ -11,7 +11,7 @@ LISTMENU "MainMenu"
{ {
position 160, 55 position 160, 55
Linespacing 20 Linespacing 20
//animatedtransition animatedtransition
DukeLogo DukeLogo
DukeTextItem "$MNU_NEWGAME", "n", "EpisodeMenu" DukeTextItem "$MNU_NEWGAME", "n", "EpisodeMenu"
//DukeTextItem "$MNU_NEWGAME", "m", "MultiMenu" // In EDuke this replaces "New Game" when in networking mode. Kept here as a reminder. //DukeTextItem "$MNU_NEWGAME", "m", "MultiMenu" // In EDuke this replaces "New Game" when in networking mode. Kept here as a reminder.
@ -80,7 +80,7 @@ LISTMENU "IngameMenu"
{ {
position 160, 55 position 160, 55
linespacing 18 linespacing 18
//animatedtransition animatedtransition
DukeLogo DukeLogo
DukeTextItem "$MNU_NEWGAME", "n", "EpisodeMenu" DukeTextItem "$MNU_NEWGAME", "n", "EpisodeMenu"
DukeTextItem "$MNU_SAVEGAME", "s", "SaveGameMenu" DukeTextItem "$MNU_SAVEGAME", "s", "SaveGameMenu"
@ -152,7 +152,7 @@ LISTMENU "EpisodeMenu"
position 160, 48 position 160, 48
Linespacing 20 Linespacing 20
captionItem "$MNU_SELECTEPISODE" captionItem "$MNU_SELECTEPISODE"
//animatedtransition animatedtransition
} }
ifgame(blood) ifgame(blood)
{ {
@ -176,7 +176,7 @@ LISTMENU "SkillMenu"
position 160, 48 position 160, 48
Linespacing 20 Linespacing 20
captionItem "$MNU_SELECTSKILL" captionItem "$MNU_SELECTSKILL"
//animatedtransition animatedtransition
} }
ifgame(blood) ifgame(blood)
{ {