From 2ed598bb6cdc0ae27d7a7bf7eef9c57a08cb020c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 26 Nov 2019 00:29:51 +0100 Subject: [PATCH] - menu transition animation added. --- source/common/menu/menu.cpp | 52 +++++++++++++++++++++++++++++++++++++ source/common/menu/menu.h | 1 + 2 files changed, 53 insertions(+) diff --git a/source/common/menu/menu.cpp b/source/common/menu/menu.cpp index 170132509..42b121719 100644 --- a/source/common/menu/menu.cpp +++ b/source/common/menu/menu.cpp @@ -49,6 +49,8 @@ #include "v_draw.h" #include "gamecontrol.h" #include "fx_man.h" +#include "pragmas.h" +#include "build.h" void RegisterDukeMenus(); extern bool rotatesprite_2doverride; @@ -86,6 +88,56 @@ static bool MenuEnabled = true; #define KEY_REPEAT_DELAY (MENU_TICRATE*5/12) #define KEY_REPEAT_RATE (3) +enum MenuTransitionType +{ // Note: This enum is for logical categories, not visual types. + MA_None, + MA_Return, + MA_Advance, +} ; + +struct MenuTransition +{ + DMenu *previous; + DMenu *current; + + int32_t start; + int32_t length; + int32_t dir; +}; + +bool M_StartTransition(DMenu *from, DMenu *to, MenuTransitionType animtype, MenuTransition &transition) +{ + if (!from->canAnimate || !to->canAnimate || animtype == MA_None) + { + return false; + } + else + { + transition.start = (int32_t) totalclock; + transition.length = 30; + transition.dir = animtype == MA_Advance? 1 : -1; + transition.previous = from; + transition.current = to; + return true; + } +} + +bool M_DrawTransition(MenuTransition &transition) +{ + if (totalclock < transition.start + transition.length) + { + double factor = 120 * xdim / ydim; + double phase = ((int32_t) totalclock - transition.start) / double(transition.length) * M_PI + M_PI/2; + + transition.previous->origin.X = factor * transition.dir * (sin(phase) - 1.); + transition.current->origin.X = factor * transition.dir * (sin(phase) + 1.); + transition.previous->Drawer(); + transition.current->Drawer(); + return false; + } + return true; +} + //============================================================================ // // DMenu base class diff --git a/source/common/menu/menu.h b/source/common/menu/menu.h index b970a1f2a..cbabae10c 100644 --- a/source/common/menu/menu.h +++ b/source/common/menu/menu.h @@ -320,6 +320,7 @@ public: DMenu *mParentMenu; DVector2 origin; int scriptID = INT_MAX; + bool canAnimate = false; DMenu(DMenu *parent = NULL); virtual ~DMenu() = default;