From f62611e90df5e6f29ef1f55a9c4c3e072f7b3ab6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 28 Nov 2019 01:49:50 +0100 Subject: [PATCH] - cleaned out a large chunk of menus.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … leaving only the parts still needed for reference. --- source/duke3d/src/menus.cpp | 3504 +---------------------------------- 1 file changed, 2 insertions(+), 3502 deletions(-) diff --git a/source/duke3d/src/menus.cpp b/source/duke3d/src/menus.cpp index ac6f30af6..18b1a50ff 100644 --- a/source/duke3d/src/menus.cpp +++ b/source/duke3d/src/menus.cpp @@ -55,87 +55,6 @@ BEGIN_DUKE_NS #define USERMAPENTRYLENGTH 25 -static FORCE_INLINE void Menu_StartTextInput() -{ - inputState.keyFlushChars(); - inputState.ClearKeysDown(); -} - -static FORCE_INLINE void Menu_StopTextInput() -{ -} - -static FORCE_INLINE void rotatesprite_ybounds(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, uint8_t dapalnum, int32_t dastat, int32_t ydim_upper, int32_t ydim_lower) -{ - rotatesprite_(sx, sy, z, a, picnum, dashade, dapalnum, dastat, 0, 0, 0, ydim_upper, xdim-1, ydim_lower); -} - -static void mgametext(int32_t x, int32_t y, char const * t) -{ - G_ScreenText(MF_Bluefont.tilenum, x, y, MF_Bluefont.zoom, 0, 0, t, 0, MF_Bluefont.pal, 2|8|16|ROTATESPRITE_FULL16, 0, MF_Bluefont.emptychar.x, MF_Bluefont.emptychar.y, MF_Bluefont.between.x, MF_Bluefont.between.y, MF_Bluefont.textflags, 0, 0, xdim-1, ydim-1); -} - - -#define mminitext(x,y,t,p) minitext_(x, y, t, 0, p, 2|8|16|ROTATESPRITE_FULL16) -#define mmenutext menutext - -#ifndef EDUKE32_STANDALONE -#endif -static void creditsminitext(int32_t x, int32_t y, const char *t, int32_t p) -{ - int32_t f = TEXT_XCENTER; - - if (!minitext_lowercase) - f |= TEXT_UPPERCASE; - - G_ScreenTextShadow(1, 1, MINIFONT, x, y, 65536, 0, 0, t, 0, p, 2|8|16|ROTATESPRITE_FULL16, 0, 4<<16, 8<<16, 1<<16, 0, f, 0, 0, xdim-1, ydim-1); -} - -#pragma pack(push,1) -static savehead_t savehead; -#pragma pack(pop) - -static void Menu_DrawTopBar(const vec2_t origin) -{ - if ((G_GetLogoFlags() & LOGO_NOTITLEBAR) == 0) - rotatesprite_fs(origin.x + (MENU_MARGIN_CENTER<<16), origin.y + (19<<16), MF_Redfont.cursorScale, 0,MENUBAR,16,0,10); -} - -static void Menu_DrawTopBarCaption(const char *caption, const vec2_t origin) -{ - static char t[64]; - size_t const srclen = strlen(caption); - size_t const dstlen = min(srclen, ARRAY_SIZE(t)-1); - memcpy(t, caption, dstlen); - t[dstlen] = '\0'; - char *p = &t[dstlen-1]; - if (*p == ':') - *p = '\0'; - captionmenutext(origin.x + (MENU_MARGIN_CENTER<<16), origin.y + (24<<16) + ((15>>1)<<16), t); -} - -static void Menu_DrawCursorTextTile(int32_t x, int32_t y, int32_t h, int32_t picnum, vec2_16_t const & siz, int32_t ydim_upper = 0, int32_t ydim_lower = ydim-1) -{ - vec2_t const adjsiz = { (siz.x>>1)<<16, siz.y<<16 }; - Menu_DrawCursorCommon(x + scale(adjsiz.x, h, adjsiz.y), y, divscale16(h, adjsiz.y), picnum, ydim_upper, ydim_lower); -} -static void Menu_DrawCursorText(int32_t x, int32_t y, int32_t h, int32_t ydim_upper = 0, int32_t ydim_lower = ydim-1) -{ - vec2_16_t const & siz = tilesiz[SPINNINGNUKEICON]; - - if (FURY || siz.x == 0) - { - Menu_DrawCursorTextTile(x, y, h, SMALLFNTCURSOR, tilesiz[SMALLFNTCURSOR], ydim_upper, ydim_lower); - return; - } - - Menu_DrawCursorTextTile(x, y, h, SPINNINGNUKEICON+(((int32_t) totalclock>>3)%7), siz, ydim_upper, ydim_lower); -} - - -static uint16_t g_oldSaveCnt; - - /* @@ -151,11 +70,6 @@ they effectively stand in for curly braces as struct initializers. */ -static MenuMenuFormat_t MMF_Top_Main = { { MENU_MARGIN_CENTER<<16, 55<<16, }, -(170<<16) }; -static MenuMenuFormat_t MMF_Top_Episode = { { MENU_MARGIN_CENTER<<16, 48<<16, }, -(190<<16) }; -static MenuMenuFormat_t MMF_Top_NewGameCustom = { { MENU_MARGIN_CENTER<<16, 48<<16, }, -(190<<16) }; -static MenuMenuFormat_t MMF_Top_NewGameCustomSub = { { MENU_MARGIN_CENTER<<16, 48<<16, }, -(190<<16) }; -static MenuMenuFormat_t MMF_Top_Skill = { { MENU_MARGIN_CENTER<<16, 58<<16, }, -(190<<16) }; static MenuMenuFormat_t MMF_Top_Options = { { MENU_MARGIN_CENTER<<16, 38<<16, }, -(190<<16) }; static MenuMenuFormat_t MMF_Top_Joystick_Network = { { MENU_MARGIN_CENTER<<16, 70<<16, }, -(190<<16) }; static MenuMenuFormat_t MMF_BigOptions = { { MENU_MARGIN_WIDE<<16, 38<<16, }, -(190<<16) }; @@ -172,8 +86,7 @@ static MenuMenuFormat_t MMF_NetSetup = { { 36<<16, static MenuMenuFormat_t MMF_FileSelectLeft = { { 40<<16, 45<<16, }, 162<<16 }; static MenuMenuFormat_t MMF_FileSelectRight = { { 164<<16, 45<<16, }, 162<<16 }; -static MenuEntryFormat_t MEF_Null = { 0, 0, 0 }; -static MenuEntryFormat_t MEF_MainMenu = { 4<<16, 0, 0 }; + static MenuEntryFormat_t MEF_OptionsMenu = { 7<<16, 0, 0 }; static MenuEntryFormat_t MEF_LeftMenu = { 7<<16, 0, 120<<16 }; static MenuEntryFormat_t MEF_CenterMenu = { 7<<16, 0, 0 }; @@ -254,84 +167,6 @@ static MenuEntry_t ME_Space8_Bluefont = MAKE_MENUENTRY( NULL, &MF_Bluefont, &MEF static MenuEntry_t ME_Space6_Redfont = MAKE_MENUENTRY( NULL, &MF_Redfont, &MEF_Null, &MEO_Space6, Spacer ); static MenuEntry_t ME_Space8_Redfont = MAKE_MENUENTRY( NULL, &MF_Redfont, &MEF_Null, &MEO_Space8, Spacer ); -#define MAKE_MENU_TOP_ENTRYLINK( Title, Format, EntryName, LinkID ) \ -static MenuLink_t MEO_ ## EntryName = { LinkID, MA_Advance, };\ -static MenuEntry_t ME_ ## EntryName = MAKE_MENUENTRY( Title, &MF_Redfont, &Format, &MEO_ ## EntryName, Link ) - -static char const s_NewGame[] = "New Game"; -static char const s_SaveGame[] = "Save Game"; -static char const s_LoadGame[] = "Load Game"; -static char const s_Continue[] = "Continue"; -static char const s_Options[] = "Options"; -static char const s_Credits[] = "Credits"; - -MAKE_MENU_TOP_ENTRYLINK( s_NewGame, MEF_MainMenu, MAIN_NEWGAME, MENU_EPISODE ); -#ifdef EDUKE32_SIMPLE_MENU -MAKE_MENU_TOP_ENTRYLINK( "Resume Game", MEF_MainMenu, MAIN_RESUMEGAME, MENU_CLOSE ); -#endif -MAKE_MENU_TOP_ENTRYLINK( s_NewGame, MEF_MainMenu, MAIN_NEWGAME_INGAME, MENU_NEWVERIFY ); -static MenuLink_t MEO_MAIN_NEWGAME_NETWORK = { MENU_NETWORK, MA_Advance, }; -MAKE_MENU_TOP_ENTRYLINK( s_SaveGame, MEF_MainMenu, MAIN_SAVEGAME, MENU_SAVE ); -MAKE_MENU_TOP_ENTRYLINK( s_LoadGame, MEF_MainMenu, MAIN_LOADGAME, MENU_LOAD ); -MAKE_MENU_TOP_ENTRYLINK( s_Options, MEF_MainMenu, MAIN_OPTIONS, MENU_OPTIONS ); -#ifdef EDUKE32_STANDALONE -MAKE_MENU_TOP_ENTRYLINK( "Read me!", MEF_MainMenu, MAIN_HELP, MENU_STORY ); -#else -MAKE_MENU_TOP_ENTRYLINK("Help", MEF_MainMenu, MAIN_HELP, MENU_STORY); -#endif -#ifndef EDUKE32_SIMPLE_MENU -MAKE_MENU_TOP_ENTRYLINK( s_Credits, MEF_MainMenu, MAIN_CREDITS, MENU_CREDITS ); -#endif -MAKE_MENU_TOP_ENTRYLINK( "End Game", MEF_MainMenu, MAIN_QUITTOTITLE, MENU_QUITTOTITLE ); -MAKE_MENU_TOP_ENTRYLINK( "Quit", MEF_MainMenu, MAIN_QUIT, MENU_QUIT ); -#ifndef EDUKE32_SIMPLE_MENU -MAKE_MENU_TOP_ENTRYLINK( "Quit Game", MEF_MainMenu, MAIN_QUITGAME, MENU_QUIT ); -#endif - -static MenuEntry_t *MEL_MAIN[] = { - &ME_MAIN_NEWGAME, - &ME_MAIN_LOADGAME, - &ME_MAIN_OPTIONS, - &ME_MAIN_HELP, -#ifndef EDUKE32_SIMPLE_MENU - &ME_MAIN_CREDITS, -#endif - &ME_MAIN_QUIT, -}; - -static MenuEntry_t *MEL_MAIN_INGAME[] = { -#ifdef EDUKE32_SIMPLE_MENU - &ME_MAIN_RESUMEGAME, -#else - &ME_MAIN_NEWGAME_INGAME, -#endif - &ME_MAIN_SAVEGAME, - &ME_MAIN_LOADGAME, - &ME_MAIN_OPTIONS, - &ME_MAIN_HELP, - &ME_MAIN_QUITTOTITLE, -#ifndef EDUKE32_SIMPLE_MENU - &ME_MAIN_QUITGAME, -#endif -}; - -// Episode and Skill will be dynamically generated after CONs are parsed -static MenuLink_t MEO_EPISODE = { MENU_SKILL, MA_Advance, }; -static MenuLink_t MEO_EPISODE_SHAREWARE = { MENU_BUYDUKE, MA_Advance, }; -static MenuEntry_t ME_EPISODE_TEMPLATE = MAKE_MENUENTRY( NULL, &MF_Redfont, &MEF_CenterMenu, &MEO_EPISODE, Link ); -static MenuEntry_t ME_EPISODE[MAXVOLUMES]; -static MenuLink_t MEO_EPISODE_USERMAP = { MENU_USERMAP, MA_Advance, }; -static MenuEntry_t ME_EPISODE_USERMAP = MAKE_MENUENTRY( "User Map", &MF_Redfont, &MEF_CenterMenu, &MEO_EPISODE_USERMAP, Link ); -static MenuEntry_t *MEL_EPISODE[MAXVOLUMES+2]; // +2 for spacer and User Map - -static MenuLink_t MEO_NEWGAMECUSTOM_TEMPLATE = { MENU_NEWGAMECUSTOMSUB, MA_Advance, }; -static MenuLink_t MEO_NEWGAMECUSTOM[MAXMENUGAMEPLAYENTRIES]; -static MenuLink_t MEO_NEWGAMECUSTOMSUB_TEMPLATE = { MENU_SKILL, MA_Advance, }; -static MenuLink_t MEO_NEWGAMECUSTOMSUB[MAXMENUGAMEPLAYENTRIES][MAXMENUGAMEPLAYENTRIES]; -MenuEntry_t ME_NEWGAMECUSTOMENTRIES[MAXMENUGAMEPLAYENTRIES]; -MenuEntry_t ME_NEWGAMECUSTOMSUBENTRIES[MAXMENUGAMEPLAYENTRIES][MAXMENUGAMEPLAYENTRIES]; -static MenuEntry_t *MEL_NEWGAMECUSTOM[MAXMENUGAMEPLAYENTRIES]; -static MenuEntry_t *MEL_NEWGAMECUSTOMSUB[MAXMENUGAMEPLAYENTRIES]; static MenuEntry_t ME_SKILL_TEMPLATE = MAKE_MENUENTRY( NULL, &MF_Redfont, &MEF_CenterMenu, &MEO_NULL, Link ); static MenuEntry_t ME_SKILL[MAXSKILLS]; @@ -529,36 +364,6 @@ static MenuEntry_t ME_DISPLAYSETUP_VIDEOSETUP = MAKE_MENUENTRY( "Video mode", &M #endif -static MenuLink_t MEO_ENTERCHEAT = { MENU_CHEATENTRY, MA_None, }; -static MenuEntry_t ME_ENTERCHEAT = MAKE_MENUENTRY( "Enter Cheat Code", &MF_Redfont, &MEF_BigCheats, &MEO_ENTERCHEAT, Link ); - -static MenuLink_t MEO_CHEAT_WARP = { MENU_CHEAT_WARP, MA_None, }; -static MenuLink_t MEO_CHEAT_SKILL = { MENU_CHEAT_SKILL, MA_None, }; -// KEEPINSYNC cheats.h: enum CheatCodeFunctions -// KEEPINSYNC cheats.cpp: uint8_t CheatFunctionIDs[] -#define MAKE_MENUCHEAT( Name ) MAKE_MENUENTRY( Name, &MF_Bluefont, &MEF_Cheats, &MEO_NULL, Link ) -static MenuEntry_t ME_CheatCodes[] = { - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_CASHMAN] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_CORNHOLIO] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_STUFF] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_WEAPONS] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_ITEMS] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_INVENTORY] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_KEYS] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_HYPER] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_VIEW] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_SHOWMAP] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_UNLOCK] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_CLIP] ), - MAKE_MENUENTRY( CheatDescriptions[CHEAT_SCOTTY], &MF_Bluefont, &MEF_Cheats, &MEO_CHEAT_WARP, Link ), - MAKE_MENUENTRY( CheatDescriptions[CHEAT_SKILL], &MF_Bluefont, &MEF_Cheats, &MEO_CHEAT_SKILL, Link ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_MONSTERS] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_RATE] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_BETA] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_TODD] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_ALLEN] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_COORDS] ), - MAKE_MENUCHEAT( CheatDescriptions[CHEAT_DEBUG] ), }; static MenuEntry_t *MEL_OPTIONS[] = { @@ -1182,12 +987,6 @@ static MenuEntry_t *MEL_NETJOIN[] = { #define MAKE_MENUMENU(Title, Format, Entries) { Title, Format, Entries, ARRAY_SIZE(Entries), 0, 0, 0 } #define MAKE_MENUMENU_CUSTOMSIZE(Title, Format, Entries) { Title, Format, Entries, 0, 0, 0, 0 } -static MenuMenu_t M_MAIN = MAKE_MENUMENU( NoTitle, &MMF_Top_Main, MEL_MAIN ); -static MenuMenu_t M_MAIN_INGAME = MAKE_MENUMENU( NoTitle, &MMF_Top_Main, MEL_MAIN_INGAME ); -static MenuMenu_t M_EPISODE = MAKE_MENUMENU( "Select An Episode", &MMF_Top_Episode, MEL_EPISODE ); -static MenuMenu_t M_SKILL = MAKE_MENUMENU( "Select Skill", &MMF_Top_Skill, MEL_SKILL ); -static MenuMenu_t M_NEWGAMECUSTOM = MAKE_MENUMENU( s_NewGame, &MMF_Top_NewGameCustom, MEL_NEWGAMECUSTOM ); -static MenuMenu_t M_NEWGAMECUSTOMSUB = MAKE_MENUMENU( s_NewGame, &MMF_Top_NewGameCustomSub, MEL_NEWGAMECUSTOMSUB ); #ifndef EDUKE32_SIMPLE_MENU static MenuMenu_t M_GAMESETUP = MAKE_MENUMENU( "Game Setup", &MMF_BigOptions, MEL_GAMESETUP ); #endif @@ -1197,11 +996,6 @@ static MenuMenu_t M_KEYBOARDSETUP = MAKE_MENUMENU( "Configure Controls", &MMF_To static MenuMenu_t M_CONTROLS = MAKE_MENUMENU( "Control Setup", &MMF_BigOptions, MEL_CONTROLS ); static MenuMenu_t M_CHEATS = MAKE_MENUMENU( "Cheats", &MMF_SmallOptions, MEL_CHEATS ); static MenuMenu_t M_MOUSESETUP = MAKE_MENUMENU( "Mouse Setup", &MMF_BigOptions, MEL_MOUSESETUP ); -#ifdef EDUKE32_ANDROID_MENU -static MenuMenu_t M_TOUCHSETUP = MAKE_MENUMENU( "Touch Setup", &MMF_Top_Options, MEL_TOUCHSETUP ); -static MenuMenu_t M_TOUCHSENS = MAKE_MENUMENU( "Sensitivity", &MMF_BigOptions, MEL_TOUCHSENS); -static MenuPanel_t M_TOUCHBUTTONS = { "Button Setup", MENU_TOUCHSETUP, MA_Return, MENU_TOUCHSETUP, MA_Advance, }; -#endif static MenuMenu_t M_JOYSTICKSETUP = MAKE_MENUMENU( "Gamepad Setup", &MMF_BigOptions, MEL_JOYSTICKSETUP ); static MenuMenu_t M_JOYSTICKAXES = MAKE_MENUMENU( "Gamepad Axes", &MMF_BigSliders, MEL_JOYSTICKAXES ); static MenuMenu_t M_KEYBOARDKEYS = MAKE_MENUMENU( "Key Configuration", &MMF_KeyboardSetupFuncs, MEL_KEYBOARDSETUPFUNCS ); @@ -1209,9 +1003,6 @@ static MenuMenu_t M_MOUSEADVANCED = MAKE_MENUMENU( "Advanced Mouse", &MMF_BigSli static MenuMenu_t M_JOYSTICKAXIS = MAKE_MENUMENU( NULL, &MMF_BigSliders, MEL_JOYSTICKAXIS ); #ifdef USE_OPENGL static MenuMenu_t M_RENDERERSETUP_POLYMOST = MAKE_MENUMENU( "Polymost Setup", &MMF_SmallOptions, MEL_RENDERERSETUP_POLYMOST ); -# ifdef POLYMER -static MenuMenu_t M_RENDERERSETUP_POLYMER = MAKE_MENUMENU("Polymer Setup", &MMF_SmallOptions, MEL_RENDERERSETUP_POLYMER ); -# endif #endif static MenuMenu_t M_COLCORR = MAKE_MENUMENU( "Color Correction", &MMF_ColorCorrect, MEL_COLCORR ); static MenuMenu_t M_SCREENSETUP = MAKE_MENUMENU( "HUD Setup", &MMF_BigOptions, MEL_SCREENSETUP ); @@ -1228,16 +1019,6 @@ static MenuMenu_t M_NETHOST = MAKE_MENUMENU( "Host Network Game", &MMF_SmallOpti static MenuMenu_t M_NETOPTIONS = MAKE_MENUMENU( "Net Game Options", &MMF_NetSetup, MEL_NETOPTIONS ); static MenuMenu_t M_NETJOIN = MAKE_MENUMENU( "Join Network Game", &MMF_SmallOptionsNarrow, MEL_NETJOIN ); -#ifdef EDUKE32_SIMPLE_MENU -static MenuPanel_t M_STORY = { NoTitle, MENU_STORY, MA_Return, MENU_STORY, MA_Advance, }; -#else -static MenuPanel_t M_STORY = { NoTitle, MENU_F1HELP, MA_Return, MENU_F1HELP, MA_Advance, }; -#endif - -static MenuPanel_t M_F1HELP = { NoTitle, MENU_STORY, MA_Return, MENU_STORY, MA_Advance, }; -static MenuPanel_t M_CREDITS = { NoTitle, MENU_CREDITS5, MA_Return, MENU_CREDITS2, MA_Advance, }; -static MenuPanel_t M_CREDITS2 = { NoTitle, MENU_CREDITS, MA_Return, MENU_CREDITS3, MA_Advance, }; -static MenuPanel_t M_CREDITS3 = { NoTitle, MENU_CREDITS2, MA_Return, MENU_CREDITS4, MA_Advance, }; static MenuPanel_t M_CREDITS4 = { "About " APPNAME, MENU_CREDITS3, MA_Return, MENU_CREDITS5, MA_Advance, }; static MenuPanel_t M_CREDITS5 = { "About " APPNAME, MENU_CREDITS4, MA_Return, MENU_CREDITS, MA_Advance, }; @@ -1277,13 +1058,6 @@ static MenuTextForm_t M_CHEAT_SKILL = { NULL, "Enter Skill #:", 1, 0 }; // MUST be in ascending order of MenuID enum values due to binary search static Menu_t Menus[] = { - { &M_MAIN, MENU_MAIN, MENU_CLOSE, MA_None, Menu }, - { &M_MAIN_INGAME, MENU_MAIN_INGAME, MENU_CLOSE, MA_None, Menu }, - { &M_EPISODE, MENU_EPISODE, MENU_MAIN, MA_Return, Menu }, - //{ &M_USERMAP, MENU_USERMAP, MENU_PREVIOUS, MA_Return, FileSelect }, - { &M_NEWGAMECUSTOM, MENU_NEWGAMECUSTOM, MENU_MAIN, MA_Return, Menu }, - { &M_NEWGAMECUSTOMSUB, MENU_NEWGAMECUSTOMSUB, MENU_NEWGAMECUSTOM, MA_Return, Menu }, - { &M_SKILL, MENU_SKILL, MENU_PREVIOUS, MA_Return, Menu }, #ifndef EDUKE32_SIMPLE_MENU { &M_GAMESETUP, MENU_GAMESETUP, MENU_OPTIONS, MA_Return, Menu }, #endif @@ -1358,112 +1132,6 @@ static Menu_t Menus[] = { { &M_NETJOIN, MENU_NETJOIN, MENU_NETWORK, MA_Return, Menu }, }; -static CONSTEXPR const uint16_t numMenus = ARRAY_SIZE(Menus); - -Menu_t *m_currentMenu = &Menus[0]; -static Menu_t *m_previousMenu = &Menus[0]; -static Menu_t * m_parentMenu; - -MenuID_t g_currentMenu; -static MenuID_t g_previousMenu; - -#define MenuMenu_ChangeEntryList(m, el)\ - do {\ - m.entrylist = el;\ - m.numEntries = ARRAY_SIZE(el);\ - } while (0) - -static void MenuEntry_DisableOnCondition(MenuEntry_t * const entry, const int32_t condition) -{ - if (condition) - entry->flags |= MEF_Disabled; - else - entry->flags &= ~MEF_Disabled; -} -static void MenuEntry_LookDisabledOnCondition(MenuEntry_t * const entry, const int32_t condition) -{ - if (condition) - entry->flags |= MEF_LookDisabled; - else - entry->flags &= ~MEF_LookDisabled; -} -static void MenuEntry_HideOnCondition(MenuEntry_t * const entry, const int32_t condition) -{ - if (condition) - entry->flags |= MEF_Hidden; - else - entry->flags &= ~MEF_Hidden; -} - -static int32_t M_RunMenu_Menu(Menu_t *cm, MenuMenu_t *menu, MenuEntry_t *currentry, int32_t state, vec2_t origin, bool actually_draw = true); -static void Menu_EntryFocus(/*MenuEntry_t *entry*/); - -static MenuEntry_t *Menu_AdjustForCurrentEntryAssignment(MenuMenu_t *menu) -{ - MenuEntry_t *currentry = menu->entrylist[menu->currentEntry]; - - Menu_EntryFocus(/*currentry*/); - - if (currentry->ybottom - menu->scrollPos > klabs(menu->format->bottomcutoff)) - menu->scrollPos = currentry->ybottom - klabs(menu->format->bottomcutoff); - else if (currentry->ytop - menu->scrollPos < menu->format->pos.y) - menu->scrollPos = currentry->ytop - menu->format->pos.y; - - return currentry; -} - -static MenuEntry_t *Menu_AdjustForCurrentEntryAssignmentBlind(MenuMenu_t *menu) -{ - M_RunMenu_Menu(nullptr, menu, nullptr, 0, { 0, 0 }, false); - return Menu_AdjustForCurrentEntryAssignment(menu); -} - -static int32_t SELECTDIR_z = 65536; - -void Menu_PopulateNewGameCustom(void) -{ - M_NEWGAMECUSTOM.title = s_NewGame; - - int e = 0; - for (MenuGameplayStemEntry const & stem : g_MenuGameplayEntries) - { - MenuGameplayEntry const & entry = stem.entry; - if (!entry.isValid()) - break; - - MEL_NEWGAMECUSTOM[e] = &ME_NEWGAMECUSTOMENTRIES[e]; - - ++e; - } - M_NEWGAMECUSTOM.numEntries = e; - MMF_Top_NewGameCustom.pos.y = (58 + (3-e)*6)<<16; -} - -void Menu_PopulateNewGameCustomSub(int e) -{ - if ((unsigned)e >= MAXMENUGAMEPLAYENTRIES) - return; - - MenuGameplayStemEntry const & stem = g_MenuGameplayEntries[e]; - MenuGameplayEntry const & entry = stem.entry; - if (!entry.isValid()) - return; - - M_NEWGAMECUSTOMSUB.title = entry.name; - - int s = 0; - for (MenuGameplayEntry const & subentry : stem.subentries) - { - if (!subentry.isValid()) - break; - - MEL_NEWGAMECUSTOMSUB[s] = &ME_NEWGAMECUSTOMSUBENTRIES[e][s]; - - ++s; - } - M_NEWGAMECUSTOMSUB.numEntries = s; - MMF_Top_NewGameCustomSub.pos.y = (58 + (3-s)*6)<<16; -} /* This function prepares data after ART and CON have been processed. @@ -1479,78 +1147,7 @@ void Menu_Init(void) ME_SKILL_TEMPLATE.format = &MEF_LeftMenu; } - // prepare menu fonts - // check if tilenum is -1 in case it was set in EVENT_SETDEFAULTS - if ((unsigned)MF_Redfont.tilenum >= MAXTILES) MF_Redfont.tilenum = BIGALPHANUM; - if ((unsigned)MF_Bluefont.tilenum >= MAXTILES) MF_Bluefont.tilenum = STARTALPHANUM; - if ((unsigned)MF_Minifont.tilenum >= MAXTILES) MF_Minifont.tilenum = MINIFONT; - MF_Redfont.emptychar.y = tilesiz[MF_Redfont.tilenum].y<<16; - MF_Bluefont.emptychar.y = tilesiz[MF_Bluefont.tilenum].y<<16; - MF_Minifont.emptychar.y = tilesiz[MF_Minifont.tilenum].y<<16; - if (!minitext_lowercase) - MF_Minifont.textflags |= TEXT_UPPERCASE; - // prepare gamefuncs and keys - MEOSN_Gamefuncs[0] = MenuGameFuncNone; - MEOSV_Gamefuncs[0] = -1; - k = 1; - for (i = 0; i < NUMGAMEFUNCTIONS; ++i) - { - MenuGameFuncs[i] = buttonMap.GetButtonAlias(i); - MenuGameFuncs[i].Substitute('_', ' '); - - if (MenuGameFuncs[i][0] != '\0') - { - MEOSN_Gamefuncs[k] = MenuGameFuncs[i]; - MEOSV_Gamefuncs[k] = i; - ++k; - } - } - MEOS_Gamefuncs.numOptions = k; - - for (i = 1; i < NUMKEYS-1; ++i) - MEOSN_Keys[i] = KB_ScanCodeToString(i); - MEOSN_Keys[0] = MenuKeyNone; - MEOSN_Keys[NUMKEYS-1] = MenuKeyNone; - - // prepare levels - MEOS_NETOPTIONS_LEVEL[i] = MEOS_NETOPTIONS_LEVEL_TEMPLATE; - for (j = 0; j < MAXLEVELS; ++j) - { - MEOSN_NetLevels[i][j] = g_mapInfo[MAXLEVELS*i+j].name; - if (g_mapInfo[i*MAXLEVELS+j].filename != NULL) - MEOS_NETOPTIONS_LEVEL[i].numOptions = j+1; - } - MEOS_NETOPTIONS_LEVEL[i].optionNames = MEOSN_NetLevels[i]; - } - M_EPISODE.numEntries = g_volumeCnt+2; - - MEOSN_NetEpisodes[k] = MenuUserMap; - MEOSV_NetEpisodes[k] = MAXVOLUMES; - - MEOS_NETOPTIONS_EPISODE.numOptions = k + 1; - NetEpisode = MEOSV_NetEpisodes[0]; - MMF_Top_Episode.pos.y = (58 + (3-k)*6)<<16; - if (g_skillCnt == 0) - MEO_EPISODE.linkID = MENU_NULL; - M_EPISODE.currentEntry = ud.default_volume; - - ++k; - M_SKILL.numEntries = g_skillCnt; // k; - MEOS_NETOPTIONS_MONSTERS.numOptions = g_skillCnt + 1; // k+1; - MEOSN_NetSkills[g_skillCnt] = MenuSkillNone; - MMF_Top_Skill.pos.y = (58 + (4-g_skillCnt)*6)<<16; - M_SKILL.currentEntry = ud.default_skill; - Menu_AdjustForCurrentEntryAssignmentBlind(&M_SKILL); - - // prepare multiplayer gametypes - k = -1; - for (i = 0; i < MAXGAMETYPES; ++i) - if (g_gametypeNames[i][0]) - { - MEOSN_NetGametypes[i] = g_gametypeNames[i]; - k = i; - } ++k; MEOS_NETOPTIONS_GAMETYPE.numOptions = k; if (NAM_WW2GI) @@ -1560,55 +1157,7 @@ void Menu_Init(void) for (i = 0; i < NUMCHEATFUNCS; ++i) MEL_CHEATS[i+1] = &ME_CheatCodes[i]; - // prepare text chat macros - for (i = 0; i < MAXRIDECULE; ++i) - { - MEL_MACROS[i] = &ME_MACROS[i]; - ME_MACROS[i] = ME_MACROS_TEMPLATE; - ME_MACROS[i].entry = &MEO_MACROS[i]; - MEO_MACROS[i] = MEO_MACROS_TEMPLATE; - - MEO_MACROS[i].variable = sink;// ud.ridecule[i]; temporarily disabled - } - - // prepare input - for (i = 0; i < NUMGAMEFUNCTIONS; ++i) - { - if (MenuGameFuncs[i][0] == '\0') - { - MEL_KEYBOARDSETUPFUNCS[i] = NULL; - continue; - } - - MEL_KEYBOARDSETUPFUNCS[i] = &ME_KEYBOARDSETUPFUNCS[i]; - ME_KEYBOARDSETUPFUNCS[i] = ME_KEYBOARDSETUPFUNCS_TEMPLATE; - ME_KEYBOARDSETUPFUNCS[i].name = MenuGameFuncs[i]; - ME_KEYBOARDSETUPFUNCS[i].entry = &MEO_KEYBOARDSETUPFUNCS[i]; - MEO_KEYBOARDSETUPFUNCS[i] = MEO_KEYBOARDSETUPFUNCS_TEMPLATE; - } - M_KEYBOARDKEYS.numEntries = NUMGAMEFUNCTIONS; - for (i = 0; i < 2*joystick.numButtons + 8*joystick.numHats; ++i) - { - if (i < 2*joystick.numButtons) - { - if (i & 1) - Bsnprintf(MenuJoystickNames[i], MAXJOYBUTTONSTRINGLENGTH, "Double %s", joyGetName(1, i>>1)); - else - Bstrncpy(MenuJoystickNames[i], joyGetName(1, i>>1), MAXJOYBUTTONSTRINGLENGTH); - } - else - { - Bsnprintf(MenuJoystickNames[i], MAXJOYBUTTONSTRINGLENGTH, (i & 1) ? "Double Hat %d %s" : "Hat %d %s", ((i - 2*joystick.numButtons)>>3), MenuJoystickHatDirections[((i - 2*joystick.numButtons)>>1) % 4]); - } - } - for (i = 0; i < joystick.numAxes; ++i) - { - ME_JOYSTICKAXES[i] = ME_JOYSTICKAXES_TEMPLATE; - Bstrncpy(MenuJoystickAxes[i], joyGetName(0, i), MAXJOYBUTTONSTRINGLENGTH); - ME_JOYSTICKAXES[i].name = MenuJoystickAxes[i]; - MEL_JOYSTICKAXES[i] = &ME_JOYSTICKAXES[i]; - } - M_JOYSTICKAXES.numEntries = joystick.numAxes; + // prepare sound setup #ifndef EDUKE32_STANDALONE @@ -1618,25 +1167,6 @@ void Menu_Init(void) ME_SOUND_DUKETALK.name = "Grunt talk:"; #endif - if (FURY) - { - MF_Redfont.between.x = 2<<16; - MF_Redfont.cursorScale = 32768; - MF_Redfont.zoom = 16384; - MF_Bluefont.zoom = 16384; - - // hack; should swap out pointers - MF_Minifont = MF_Bluefont; - - M_OPTIONS.format = &MMF_Top_Main; - - MEF_MainMenu.width = MEF_OptionsMenu.width = -(160<<16); - MEF_MainMenu.marginBottom = 7<<16; - - M_OPTIONS.title = NoTitle; - - SELECTDIR_z = 16384; - } // prepare shareware if (VOLUMEONE) @@ -1668,16 +1198,8 @@ void Menu_Init(void) #endif } -static void Menu_Run(Menu_t *cm, vec2_t origin); -static void Menu_BlackRectangle(int32_t x, int32_t y, int32_t width, int32_t height, int32_t orientation); - -/* -At present, no true difference is planned between Menu_Pre() and Menu_PreDraw(). -They are separate for purposes of organization. -*/ - static void Menu_Pre(MenuID_t cm) { int32_t i; @@ -1685,22 +1207,6 @@ static void Menu_Pre(MenuID_t cm) switch (cm) { - case MENU_MAIN_INGAME: - MenuEntry_DisableOnCondition(&ME_MAIN_SAVEGAME, ud.recstat == 2); - MenuEntry_DisableOnCondition(&ME_MAIN_QUITTOTITLE, g_netServer || numplayers > 1); - fallthrough__; - case MENU_MAIN: - if ((g_netServer || ud.multimode > 1) && ud.recstat != 2) - { - ME_MAIN_NEWGAME.entry = &MEO_MAIN_NEWGAME_NETWORK; - ME_MAIN_NEWGAME_INGAME.entry = &MEO_MAIN_NEWGAME_NETWORK; - } - else - { - ME_MAIN_NEWGAME.entry = &MEO_MAIN_NEWGAME; - ME_MAIN_NEWGAME_INGAME.entry = &MEO_MAIN_NEWGAME_INGAME; - } - break; case MENU_GAMESETUP: MEO_GAMESETUP_DEMOREC.options = (ps->gm&MODE_GAME) ? &MEOS_DemoRec : &MEOS_OffOn; @@ -1848,78 +1354,8 @@ static void Menu_Pre(MenuID_t cm) case MENU_OPTIONS: MenuEntry_DisableOnCondition(&ME_OPTIONS_PLAYERSETUP, ud.recstat == 1); break; - - case MENU_COLCORR: - case MENU_COLCORR_INGAME: - break; - - case MENU_CHEATS: - case MENU_CHEATENTRY: - case MENU_CHEAT_WARP: - case MENU_CHEAT_SKILL: - { - const int32_t menucheatsdisabled = numplayers != 1 || !(g_player[myconnectindex].ps->gm & MODE_GAME); - - // refresh display names of quote cheats - if (!DUKEBETA) - { - ME_CheatCodes[CHEATFUNC_QUOTEBETA].name = apStrings[QUOTE_CHEAT_BETA]; - if (!NAM) - ME_CheatCodes[CHEATFUNC_QUOTETODD].name = apStrings[QUOTE_CHEAT_TODD]; - ME_CheatCodes[CHEATFUNC_QUOTEALLEN].name = apStrings[QUOTE_CHEAT_ALLEN]; - } - - for (i = 0; i < NUMCHEATFUNCS; i++) - { - uint32_t cheatmask = cl_cheatmask & (1<>11),0,2+8); - } - break; case MENU_PLAYER: rotatesprite_fs(origin.x + (260<<16), origin.y + ((24+(tilesiz[APLAYER].y>>1))<<16), 49152L,0,1441-((((4-((int32_t) totalclock>>4)))&3)*5),0,entry == &ME_PLAYER_TEAM ? G_GetTeamPalette(playerteam) : playercolor,10); @@ -2013,129 +1438,6 @@ static void Menu_PreDraw(MenuID_t cm, MenuEntry_t *entry, const vec2_t origin) Menu_DrawVerifyPrompt(origin.x, origin.y, tempbuf, 2); break; - case MENU_LOAD: - { -#if 0 - for (i = 0; i <= 108; i += 12) - rotatesprite_fs(origin.x + ((160+64+91-64)<<16), origin.y + ((i+56)<<16), 65536L,0,TEXTBOX,24,0,10); -#endif - Menu_BlackRectangle(origin.x + (198<<16), origin.y + (47<<16), 102<<16, 100<<16, 1|32); - - rotatesprite_fs(origin.x + (22<<16), origin.y + (97<<16), 65536L,0,WINDOWBORDER2,24,0,10); - rotatesprite_fs(origin.x + (180<<16), origin.y + (97<<16), 65536L,1024,WINDOWBORDER2,24,0,10); - rotatesprite_fs(origin.x + (99<<16), origin.y + (50<<16), 65536L,512,WINDOWBORDER1,24,0,10); - rotatesprite_fs(origin.x + (103<<16), origin.y + (144<<16), 65536L,1024+512,WINDOWBORDER1,24,0,10); - - if (M_LOAD.currentEntry >= (int32_t)g_nummenusaves) - { - menutext_centeralign(origin.x + (101<<16), origin.y + (97<<16), "Empty"); - break; - } - - menusave_t & msv = g_menusaves[M_LOAD.currentEntry]; - - if (msv.brief.isValid()) - { - if (tilePtr(TILE_LOADSHOT)) - rotatesprite_fs(origin.x + (101<<16), origin.y + (97<<16), 65536>>1,512,TILE_LOADSHOT, msv.isOldVer?16:-32, 0,4+10+64); - - if (msv.isOldVer) - { - mgametextcenterat(origin.x + (101<<16), origin.y + (50<<16), - msv.brief.isExt ? "Previous Version,\nSequence Point Available" : "Previous Version,\nUnable to Load"); - -#ifndef EDUKE32_SIMPLE_MENU - Bsprintf(tempbuf,"Saved: %d.%d.%d.%u %d-bit", savehead.majorver, savehead.minorver, - savehead.bytever, savehead.userbytever, 8*savehead.getPtrSize()); - mgametext(origin.x + (25<<16), origin.y + (124<<16), tempbuf); - Bsprintf(tempbuf,"Our: %d.%d.%d.%u %d-bit", SV_MAJOR_VER, SV_MINOR_VER, BYTEVERSION, - ud.userbytever, (int32_t)(8*sizeof(intptr_t))); - mgametext(origin.x + ((25+16)<<16), origin.y + (134<<16), tempbuf); -#endif - - if (msv.isUnreadable) - break; - } - - if (savehead.numplayers > 1) - { - Bsprintf(tempbuf, "Players: %-2d ", savehead.numplayers); - mgametextcenter(origin.x, origin.y + (156<<16), tempbuf); - } - - { - const char *name = g_mapInfo[(savehead.volnum*MAXLEVELS) + savehead.levnum].name; - Bsprintf(tempbuf, "%s / %s", name ? name : "^10unnamed^0", g_skillNames[savehead.skill-1]); - } - - mgametextcenter(origin.x, origin.y + (168<<16), tempbuf); - if (savehead.volnum == 0 && savehead.levnum == 7) - mgametextcenter(origin.x, origin.y + (180<<16), savehead.boardfn); - } - break; - } - - case MENU_SAVE: - { -#if 0 - for (i = 0; i <= 108; i += 12) - rotatesprite_fs(origin.x + ((160+64+91-64)<<16), origin.y + ((i+56)<<16), 65536L,0,TEXTBOX,24,0,10); -#endif - Menu_BlackRectangle(origin.x + (198<<16), origin.y + (47<<16), 102<<16, 100<<16, 1|32); - - rotatesprite_fs(origin.x + (22<<16), origin.y + (97<<16), 65536L,0,WINDOWBORDER2,24,0,10); - rotatesprite_fs(origin.x + (180<<16), origin.y + (97<<16), 65536L,1024,WINDOWBORDER2,24,0,10); - rotatesprite_fs(origin.x + (99<<16), origin.y + (50<<16), 65536L,512,WINDOWBORDER1,24,0,10); - rotatesprite_fs(origin.x + (103<<16), origin.y + (144<<16), 65536L,1024+512,WINDOWBORDER1,24,0,10); - - j = 0; - for (int k = 0; k < g_nummenusaves+1; ++k) - if (((MenuString_t*)M_SAVE.entrylist[k]->entry)->editfield) - j |= 1; - - if (j) - rotatesprite_fs(origin.x + (101<<16), origin.y + (97<<16), 65536L>>1,512,TILE_SAVESHOT,-32,0,4+10+64); - else if (0 < M_SAVE.currentEntry && M_SAVE.currentEntry <= (int32_t)g_nummenusaves) - { - menusave_t & msv = g_menusaves[M_SAVE.currentEntry-1]; - - if (msv.brief.isValid()) - { - if (tilePtr(TILE_LOADSHOT)) - rotatesprite_fs(origin.x + (101<<16), origin.y + (97<<16), 65536>>1,512,TILE_LOADSHOT, msv.isOldVer?16:-32, 0,4+10+64); - - if (msv.isOldVer) - { - mgametextcenterat(origin.x + (101<<16), origin.y + (50<<16), - msv.brief.isExt ? "Previous Version,\nSequence Point Available" : "Previous Version,\nUnable to Load"); - -#ifndef EDUKE32_SIMPLE_MENU - Bsprintf(tempbuf,"Saved: %d.%d.%d.%u %d-bit", savehead.majorver, savehead.minorver, - savehead.bytever, savehead.userbytever, 8*savehead.getPtrSize()); - mgametext(origin.x + (25<<16), origin.y + (124<<16), tempbuf); - Bsprintf(tempbuf,"Our: %d.%d.%d.%u %d-bit", SV_MAJOR_VER, SV_MINOR_VER, BYTEVERSION, - ud.userbytever, (int32_t)(8*sizeof(intptr_t))); - mgametext(origin.x + ((25+16)<<16), origin.y + (134<<16), tempbuf); -#endif - } - } - } - else - menutext_centeralign(origin.x + (101<<16), origin.y + (97<<16), "New"); - - if (ud.multimode > 1) - { - Bsprintf(tempbuf, "Players: %-2d ", ud.multimode); - mgametextcenter(origin.x, origin.y + (156<<16), tempbuf); - } - - Bsprintf(tempbuf,"%s / %s",g_mapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name, g_skillNames[ud.player_skill-1]); - mgametextcenter(origin.x, origin.y + (168<<16), tempbuf); - if (ud.volume_number == 0 && ud.level_number == 7) - mgametextcenter(origin.x, origin.y + (180<<16), currentboardfilename); - break; - } - case MENU_SAVECLEANVERIFY: videoFadeToBlack(1); @@ -2364,193 +1666,6 @@ static void Menu_PreDraw(MenuID_t cm, MenuEntry_t *entry, const vec2_t origin) } -static void Menu_PreInput(MenuEntry_t *entry) -{ - switch (g_currentMenu) - { - - case MENU_KEYBOARDKEYS: - if (inputState.GetKeyStatus(sc_Delete)) - { - Bindings.UnbindACommand(buttonMap.GetButtonName(M_KEYBOARDKEYS.currentEntry)); - S_PlaySound(KICK_HIT); - inputState.ClearKeyStatus(sc_Delete); - } - break; - - case MENU_LOAD: - if (inputState.GetKeyStatus(sc_Delete)) - { - inputState.ClearKeyStatus(sc_Delete); - if (M_LOAD.currentEntry < g_nummenusaves) - Menu_Change(MENU_LOADDELVERIFY); - } - break; - case MENU_SAVE: - if (inputState.GetKeyStatus(sc_Delete)) - { - inputState.ClearKeyStatus(sc_Delete); - if (0 < M_SAVE.currentEntry && M_SAVE.currentEntry <= (int32_t)g_nummenusaves) - Menu_Change(MENU_SAVEDELVERIFY); - } - break; - - default: - break; - } -} - -static void Menu_PreOptionListDraw(MenuEntry_t *entry, const vec2_t origin) -{ - switch (g_currentMenu) - { - case MENU_MOUSEBTNS: - case MENU_MOUSEADVANCED: - case MENU_JOYSTICKBTNS: - case MENU_JOYSTICKAXIS: - mgametextcenter(origin.x, origin.y + (31<<16), "Select a function to assign"); - - Bsprintf(tempbuf, "to %s", entry->name); - - mgametextcenter(origin.x, origin.y + ((31+9)<<16), tempbuf); - - mgametextcenter(origin.x, origin.y + (161<<16), "Press \"Escape\" To Cancel"); - break; - } -} - -static int32_t Menu_PreCustom2ColScreen(MenuEntry_t *entry) -{ - if (g_currentMenu == MENU_KEYBOARDKEYS) - { - auto column = (MenuCustom2Col_t*)entry->entry; - - int32_t sc = inputState.GetLastScanCode(); - if (sc != sc_None) - { - S_PlaySound(PISTOL_BODYHIT); - Bindings.SetBind(sc, buttonMap.GetButtonName(M_KEYBOARDKEYS.currentEntry)); - inputState.ClearKeyStatus(sc); - - return -1; - } - } - - return 0; -} - -static void Menu_PreCustom2ColScreenDraw(MenuEntry_t *entry, const vec2_t origin) -{ - if (g_currentMenu == MENU_KEYBOARDKEYS) - { - Bsprintf(tempbuf, "Press the key to assign as\n" - "%s for \"%s\"\n" - "\n" - "Press \"Escape\" To Cancel" - , M_KEYBOARDKEYS.currentColumn?"secondary":"primary", entry->name); - mgametextcenter(origin.x, origin.y + (90<<16), tempbuf); - } -} - -static void Menu_EntryFocus(/*MenuEntry_t *entry*/) -{ - switch (g_currentMenu) - { - case MENU_LOAD: - if (M_LOAD.currentEntry < (int32_t)g_nummenusaves) - { - savebrief_t & sv = g_menusaves[M_LOAD.currentEntry].brief; - if (sv.isValid()) - G_LoadSaveHeaderNew(sv.path, &savehead); - } - break; - - case MENU_SAVE: - if (0 < M_SAVE.currentEntry && M_SAVE.currentEntry <= (int32_t)g_nummenusaves) - { - savebrief_t & sv = g_menusaves[M_SAVE.currentEntry-1].brief; - if (sv.isValid()) - G_LoadSaveHeaderNew(sv.path, &savehead); - } - break; - - default: - break; - } -} - -static void Menu_StartGameWithoutSkill(void) -{ - ud.m_player_skill = M_SKILL.currentEntry+1; - - ud.skill_voice = S_PlaySound(PISTOL_BODYHIT); - - ud.m_respawn_monsters = 0; - - ud.m_monsters_off = ud.monsters_off = 0; - - ud.m_respawn_items = 0; - ud.m_respawn_inventory = 0; - - ud.multimode = 1; - - G_NewGame_EnterLevel(); -} - -static void Menu_DoCheat(int32_t cheatID) -{ - if (numplayers != 1 || !(g_player[myconnectindex].ps->gm & MODE_GAME)) - return; - - osdcmd_cheatsinfo_stat.cheatnum = cheatID; -} - -static int32_t Menu_Cheat_Warp(char const * const numbers) -{ - if (numplayers != 1 || !(g_player[myconnectindex].ps->gm & MODE_GAME)) - return 0; - - if (numbers == NULL || !numbers[0] || !numbers[1] || (VOLUMEALL && !numbers[2])) - return 1; - - if (VOLUMEALL) - { - osdcmd_cheatsinfo_stat.volume = numbers[0] - '0'; - osdcmd_cheatsinfo_stat.level = (numbers[1] - '0')*10+(numbers[2]-'0'); - } - else - { - osdcmd_cheatsinfo_stat.volume = numbers[0] - '0'; - osdcmd_cheatsinfo_stat.level = numbers[1] - '0'; - } - - osdcmd_cheatsinfo_stat.volume--; - osdcmd_cheatsinfo_stat.level--; - - if ((VOLUMEONE && osdcmd_cheatsinfo_stat.volume > 0) || osdcmd_cheatsinfo_stat.volume > g_volumeCnt-1 || - osdcmd_cheatsinfo_stat.level >= MAXLEVELS || g_mapInfo[osdcmd_cheatsinfo_stat.volume *MAXLEVELS+osdcmd_cheatsinfo_stat.level].filename == NULL) - return 1; - - osdcmd_cheatsinfo_stat.cheatnum = CHEAT_SCOTTY; - - return 0; -} - -static int32_t Menu_Cheat_Skill(char const * const number) -{ - if (numplayers != 1 || !(g_player[myconnectindex].ps->gm & MODE_GAME)) - return 0; - - if (number == NULL || !number[0]) - return 1; - - osdcmd_cheatsinfo_stat.volume = number[0] - '1'; - - osdcmd_cheatsinfo_stat.cheatnum = CHEAT_SKILL; - - return 0; -} - /* Functions where a "newValue" or similar is passed are run *before* the linked variable is actually changed. That way you can compare the new and old values and potentially block the change. @@ -2767,187 +1882,10 @@ static int32_t Menu_EntryOptionModify(MenuEntry_t *entry, int32_t newOption) } } - switch (g_currentMenu) - { - case MENU_MOUSEBTNS: - break; - case MENU_JOYSTICKBTNS: - break; - case MENU_JOYSTICKAXIS: - { - for (int i = 0; i < ARRAY_SSIZE(MEL_INTERNAL_JOYSTICKAXIS_DIGITAL); i++) - if (entry == MEL_INTERNAL_JOYSTICKAXIS_DIGITAL[i]) - CONTROL_MapDigitalAxis(M_JOYSTICKAXES.currentEntry, newOption, i&1, controldevice_joystick); - } - break; - } return 0; } -static void Menu_EntryOptionDidModify(MenuEntry_t *entry) -{ -#ifdef USE_OPENGL - int domodechange = 0; -#endif - - if (entry == &ME_GAMESETUP_AIM_AUTO || - entry == &ME_GAMESETUP_WEAPSWITCH_PICKUP || - //entry == &ME_PLAYER_NAME || - entry == &ME_PLAYER_COLOR || - entry == &ME_PLAYER_TEAM) - G_UpdatePlayerFromMenu(); -#ifdef USE_OPENGL - if (domodechange) - { - videoResetMode(); - if (videoSetGameMode(fullscreen, xres, yres, bpp, upscalefactor)) - OSD_Printf("restartvid: Reset failed...\n"); - onvideomodechange(ScreenBPP>8); - G_RefreshLights(); - } -#endif -} - -static void Menu_Custom2ColScreen(/*MenuEntry_t *entry*/) -{ - if (g_currentMenu == MENU_KEYBOARDKEYS) - { - inputState.keyFlushChars(); - inputState.ClearLastScanCode(); - } -} - -static int32_t Menu_EntryRangeInt32Modify(MenuEntry_t *entry, int32_t newValue) -{ - if (entry == &ME_SCREENSETUP_SBARSIZE) - G_SetStatusBarScale(newValue); - else if (entry == &ME_SOUND_VOLUME_FX) - FX_SetVolume(newValue); - else if (entry == &ME_SOUND_VOLUME_MUSIC) - S_MusicVolume(newValue); - else if (entry == &ME_JOYSTICKAXIS_SCALE) - CONTROL_SetAnalogAxisScale(M_JOYSTICKAXES.currentEntry, newValue, controldevice_joystick); - else if (entry == &ME_JOYSTICKAXIS_DEAD) - joySetDeadZone(M_JOYSTICKAXES.currentEntry, newValue, *MEO_JOYSTICKAXIS_SATU.cVar); - else if (entry == &ME_JOYSTICKAXIS_SATU) - joySetDeadZone(M_JOYSTICKAXES.currentEntry, *MEO_JOYSTICKAXIS_DEAD.cVar, newValue); - - return 0; -} - -static int32_t Menu_EntryRangeFloatModify(MenuEntry_t *entry, float newValue) -{ -#ifndef EDUKE32_SIMPLE_MENU - if (entry == &ME_COLCORR_AMBIENT) - r_ambientlightrecip = 1.f/newValue; -#else - UNREFERENCED_PARAMETER(entry); - UNREFERENCED_PARAMETER(newValue); -#endif - - return 0; -} - -static int32_t Menu_EntryRangeFloatDidModify(MenuEntry_t *entry) -{ - return 0; -} - -#ifdef MENU_ENABLE_RANGEDOUBLE -static int32_t Menu_EntryRangeDoubleModify(void /*MenuEntry_t *entry, double newValue*/) -{ - - return 0; -} -#endif - -static uint32_t save_xxh = 0; - -static void Menu_EntryStringActivate(/*MenuEntry_t *entry*/) -{ - switch (g_currentMenu) - { - case MENU_SAVE: - if (M_SAVE.currentEntry > 0) - { - savebrief_t & sv = g_menusaves[M_SAVE.currentEntry-1].brief; - if (!save_xxh) - save_xxh = SuperFastHash(sv.name, MAXSAVEGAMENAME); - if (sv.isValid()) - Menu_Change(MENU_SAVEVERIFY); - } - else - { - ME_SAVE_NEW.name = nullptr; - save_xxh = 0; - } - break; - - default: - break; - } -} - -static int32_t Menu_EntryStringSubmit(/*MenuEntry_t *entry, */char *input) -{ - int32_t returnvar = 0; - - switch (g_currentMenu) - { - case MENU_SAVE: - { - savebrief_t & sv = g_lastusersave = M_SAVE.currentEntry == 0 ? savebrief_t{input} : g_menusaves[M_SAVE.currentEntry-1].brief; - - // dirty hack... char 127 in last position indicates an auto-filled name -#ifdef __ANDROID__ - if (1) -#else - if (input[0] == 0 || (sv.name[MAXSAVEGAMENAME] == 127 && - strncmp(sv.name, input, MAXSAVEGAMENAME) == 0 && - save_xxh == SuperFastHash(sv.name, MAXSAVEGAMENAME))) -#endif - { - strncpy(sv.name, g_mapInfo[ud.volume_number * MAXLEVELS + ud.level_number].name, MAXSAVEGAMENAME); - sv.name[MAXSAVEGAMENAME] = 127; - returnvar = -1; - } - else - { - strncpy(sv.name, input, MAXSAVEGAMENAME); - sv.name[MAXSAVEGAMENAME] = 0; - } - - G_SavePlayerMaybeMulti(sv); - - g_quickload = &sv; - g_player[myconnectindex].ps->gm = MODE_GAME; - - Menu_Change(MENU_CLOSE); - save_xxh = 0; - break; - } - - default: - break; - } - - return returnvar; -} - -static void Menu_EntryStringCancel(/*MenuEntry_t *entry*/) -{ - switch (g_currentMenu) - { - case MENU_SAVE: - save_xxh = 0; - ME_SAVE_NEW.name = s_NewSaveGame; - break; - - default: - break; - } -} /* This is polled when the menu code is populating the screen but for some reason doesn't have the data. @@ -2964,533 +1902,6 @@ static int32_t Menu_EntryOptionSource(MenuEntry_t *entry, int32_t currentValue) return currentValue; } -static void Menu_Verify(int32_t input) -{ - switch (g_currentMenu) - { - case MENU_SAVECLEANVERIFY: - if (input) - { - G_DeleteOldSaves(); - } - break; - - case MENU_RESETPLAYER: - switch (input) - { - default: - inputState.keyFlushChars(); - inputState.ClearKeysDown(); - FX_StopAllSounds(); - - if (G_LoadPlayerMaybeMulti(*g_quickload) == 0) - break; - - // error state, consider as a no instead of yes - g_quickload->reset(); - - fallthrough__; - case 0: - if (sprite[g_player[myconnectindex].ps->i].extra <= 0) - { - if (G_EnterLevel(MODE_GAME)) G_BackToMenu(); - return; - } - - Menu_Change(MENU_CLOSE); - break; - } - break; - - case MENU_LOADVERIFY: - if (input) - { - menusave_t & msv = g_menusaves[M_LOAD.currentEntry]; - savebrief_t & sv = msv.brief; - - if (strcmp(sv.path, g_lastusersave.path) != 0) - { - g_freshload = sv; - g_lastusersave.reset(); - g_lastautosave.reset(); - g_quickload = &g_freshload; - } - else - { - g_quickload = &g_lastusersave; - } - - inputState.keyFlushChars(); - inputState.ClearKeysDown(); - - if (G_LoadPlayerMaybeMulti(sv)) - Menu_Change(MENU_PREVIOUS); - else - Menu_Change(MENU_CLOSE); - } - break; - - case MENU_SAVEVERIFY: - if (!input) - { - save_xxh = 0; - - ((MenuString_t*)M_SAVE.entrylist[M_SAVE.currentEntry]->entry)->editfield = NULL; - } - break; - - case MENU_LOADDELVERIFY: - if (input) - { - Menu_LoadReadHeaders(); - M_LOAD.currentEntry = clamp(M_LOAD.currentEntry, 0, (int32_t)g_nummenusaves-1); - } - break; - case MENU_SAVEDELVERIFY: - if (input) - { - Menu_SaveReadHeaders(); - M_SAVE.currentEntry = clamp(M_SAVE.currentEntry, 0, (int32_t)g_nummenusaves); - } - break; - - case MENU_COLCORRRESETVERIFY: - if (input) - { - vid_gamma = 1.f; - vid_contrast = 1.f; - vid_brightness = 0.f; - r_ambientlight = 1.f; - videoSetPalette(0,g_player[myconnectindex].ps->palette,0); - } - break; - - case MENU_KEYSRESETVERIFY: - if (input) - CONFIG_SetDefaultKeys("demolition/defbinds.txt"); - break; - case MENU_KEYSCLASSICVERIFY: - if (input) - CONFIG_SetDefaultKeys("demolition/origbinds.txt"); - break; - case MENU_JOYSTANDARDVERIFY: - if (input) - CONFIG_SetGameControllerDefaultsStandard(); - break; - case MENU_JOYPROVERIFY: - if (input) - CONFIG_SetGameControllerDefaultsPro(); - break; - case MENU_JOYCLEARVERIFY: - if (input) - CONFIG_SetGameControllerDefaultsClear(); - break; - - case MENU_QUIT: - case MENU_QUIT_INGAME: - if (input) - G_GameQuit(); - else - g_quitDeadline = 0; - break; - - case MENU_QUITTOTITLE: - if (input) - { - g_player[myconnectindex].ps->gm = MODE_DEMO; - if (ud.recstat == 1) - G_CloseDemoWrite(); - artClearMapArt(); - } - break; - - case MENU_NETWAITVOTES: - if (!input) - Net_SendMapVoteCancel(0); - break; - - default: - break; - } -} - -static int Menu_CheatStringMatch(char const * input, char const * cheat) -{ - while (*cheat || *input) - { - if (*cheat != *input) - { - if (!(*cheat == '#' && Bisdigit(*input))) - return 0; - } - - ++cheat; - ++input; - } - - return 1; -} - -static void Menu_TextFormSubmit(char *input) -{ - switch (g_currentMenu) - { - case MENU_ADULTPASSWORD: - break; - - case MENU_CHEATENTRY: - { - const size_t inputlength = Bstrlen(input); - Bstrcpy(tempbuf, input); - for (size_t i = 0; i < inputlength; i++) - tempbuf[i] = Btolower(tempbuf[i]); - - int8_t cheatID = -1; - - if (inputlength > 2 && tempbuf[0] == g_keyAsciiTable[CheatKeys[0]] && tempbuf[1] == g_keyAsciiTable[CheatKeys[1]]) - { - for (int i = 0; i < NUMCHEATS; i++) - if (Menu_CheatStringMatch(tempbuf+2, CheatStrings[i])) - { - cheatID = i; - break; - } - } - - switch (cheatID) - { - case -1: - S_PlaySound(KICK_HIT); - break; - case CHEAT_SCOTTY: - { - char const * const numberpos = Bstrchr(CheatStrings[CHEAT_SCOTTY], '#'); - if (numberpos == NULL) - { - S_PlaySound(KICK_HIT); - break; - } - - Menu_Cheat_Warp(input + (numberpos - CheatStrings[CHEAT_SCOTTY]) + 2); - if (g_player[myconnectindex].ps->gm&MODE_MENU) - S_PlaySound(DUKE_GET); - break; - } - case CHEAT_SKILL: - { - char const * const numberpos = Bstrchr(CheatStrings[CHEAT_SKILL], '#'); - if (numberpos == NULL) - { - S_PlaySound(KICK_HIT); - break; - } - - Menu_Cheat_Skill(input + (numberpos - CheatStrings[CHEAT_SKILL]) + 2); - if (g_player[myconnectindex].ps->gm&MODE_MENU) - S_PlaySound(DUKE_GET); - break; - } - default: - Menu_DoCheat(cheatID); - S_PlaySound(DUKE_GET); - break; - } - - if (cheatID >= 0) - cl_cheatmask = cl_cheatmask | CheatFunctionFlags[cheatID]; - - if ((NAM_WW2GI && (cl_cheatmask & (1<menuID) - { - case MENU_NEWGAMECUSTOMSUB: - Menu_PopulateNewGameCustomSub(M_NEWGAMECUSTOM.currentEntry); - break; - - case MENU_LOAD: - if (FURY) - M_LOAD.title = (g_player[myconnectindex].ps->gm & MODE_GAME) ? s_LoadGame : s_Continue; - - Menu_LoadReadHeaders(); - - if (g_quickload && g_quickload->isValid()) - { - for (int i = 0; i < g_nummenusaves; ++i) - { - if (strcmp(g_menusaves[i].brief.path, g_quickload->path) == 0) - { - M_LOAD.currentEntry = i; - Menu_AdjustForCurrentEntryAssignmentBlind(&M_LOAD); - break; - } - } - } - break; - - case MENU_SAVE: - if (g_previousMenu == MENU_SAVEVERIFY || g_previousMenu == MENU_SAVEDELVERIFY) - break; - - Menu_SaveReadHeaders(); - - if (g_lastusersave.isValid()) - { - for (int i = 0; i < g_nummenusaves; ++i) - { - if (strcmp(g_menusaves[i].brief.path, g_lastusersave.path) == 0) - { - M_SAVE.currentEntry = i+1; - Menu_AdjustForCurrentEntryAssignmentBlind(&M_SAVE); - break; - } - } - } - - if (g_player[myconnectindex].ps->gm&MODE_GAME) - { - g_screenCapture = 1; - G_DrawRooms(myconnectindex,65536); - g_screenCapture = 0; - } - break; - - case MENU_VIDEOSETUP: - newresolution = 0; - for (int i = 0; i < MAXVALIDMODES; ++i) - { - if (resolution[i].xdim == xres && resolution[i].ydim == yres) - { - newresolution = i; - break; - } - } - newrendermode = videoGetRenderMode(); - newfullscreen = fullscreen; - newvsync = vid_vsync; - newborderless = r_borderless; - break; - - case MENU_ADVSOUND: - soundrate = snd_mixrate; - soundvoices = snd_numvoices; - musicdevice = MusicDevice; - break; - - default: - break; - } - - switch (m->type) - { - case TextForm: - typebuf[0] = 0; - ((MenuTextForm_t*)m->object)->input = typebuf; - break; - case FileSelect: - Menu_FileSelectInit((MenuFileSelect_t*)m->object); - break; - case Menu: - { - auto menu = (MenuMenu_t*)m->object; - // MenuEntry_t* currentry = menu->entrylist[menu->currentEntry]; - - // need this for MENU_SKILL - if (menu->currentEntry >= menu->numEntries) - menu->currentEntry = 0; - - int32_t i = menu->currentEntry; - while (!menu->entrylist[menu->currentEntry] || - (((MenuEntry_t*)menu->entrylist[menu->currentEntry])->flags & MEF_Hidden) || - ((MenuEntry_t*)menu->entrylist[menu->currentEntry])->type == Spacer) - { - menu->currentEntry++; - if (menu->currentEntry >= menu->numEntries) - menu->currentEntry = 0; - if (menu->currentEntry == i) - G_GameExit("Menu_Change: Attempted to show a menu with no entries."); - } - - Menu_EntryFocus(/*currentry*/); - break; - } - default: - break; - } -} - -static void Menu_ChangingTo(Menu_t * m) -{ - - - switch (m->type) - { - case TextForm: - Menu_StartTextInput(); - break; - default: - break; - } -} - - - - - - -int G_CheckPlayerColor(int color) -{ - for (int i : MEOSV_PLAYER_COLOR) - if (i == color) - return color; - - return -1; -} - - -int32_t Menu_DetermineSpecialState(MenuEntry_t *entry) -{ - if (entry == NULL) - return 0; - - if (entry->type == String) - { - if (((MenuString_t*)entry->entry)->editfield) - return 1; - } - else if (entry->type == Option) - { - if (((MenuOption_t*)entry->entry)->options->currentEntry >= 0) - return 2; - } - else if (entry->type == Custom2Col) - { - if (((MenuCustom2Col_t*)entry->entry)->screenOpen) - return 2; - } - - return 0; -} - -int32_t Menu_IsTextInput(Menu_t *cm) -{ - switch (m_currentMenu->type) - { - case Verify: - case TextForm: - case FileSelect: - case Message: - return 1; - break; - case Panel: - return 0; - break; - case Menu: - { - auto menu = (MenuMenu_t *)cm->object; - auto entry = menu->entrylist[menu->currentEntry]; - return Menu_DetermineSpecialState(entry); - } - break; - } - - return 0; -} - -static inline int32_t Menu_BlackTranslucentBackgroundOK(MenuID_t cm) -{ - switch (cm) - { - case MENU_COLCORR: - case MENU_COLCORR_INGAME: - return 0; - break; - default: - return 1; - break; - } - - return 1; -} - -static inline int32_t Menu_UpdateScreenOK(MenuID_t cm) -{ - switch (cm) - { - case MENU_LOAD: - case MENU_SAVE: - case MENU_LOADVERIFY: - case MENU_LOADDELVERIFY: - case MENU_SAVEVERIFY: - case MENU_SAVEDELVERIFY: - return 0; - break; - default: - return 1; - break; - } - - return 1; -} - - -/* - Code below this point is entirely general, - so if you want to change or add a menu, - chances are you should scroll up. -*/ - -int32_t m_mouselastactivity; -#if !defined EDUKE32_TOUCH_DEVICES -int32_t m_mousewake_watchpoint, m_menuchange_watchpoint; -#endif -int32_t m_mousecaught; -static vec2_t m_prevmousepos, m_mousepos, m_mousedownpos; - -void Menu_Open(uint8_t playerID) -{ - g_player[playerID].ps->gm |= MODE_MENU; - - inputState.mouseReadAbs(&m_prevmousepos); - m_mouselastactivity = -M_MOUSETIMEOUT; - -#if !defined EDUKE32_TOUCH_DEVICES - m_mousewake_watchpoint = 0; -#endif - - mouseLockToWindow(0); -} - void Menu_Close(uint8_t playerID) { auto & gm = g_player[playerID].ps->gm; @@ -3523,1917 +1934,6 @@ void Menu_Close(uint8_t playerID) } } -static int32_t x_widescreen_left(void) -{ - return (320<<15) - scale(240<<15, xdim, ydim); -} - -static int32_t xdim_from_320_16(int32_t x) -{ - const int32_t screenwidth = scale(240<<16, xdim, ydim); - return scale(x + (screenwidth>>1) - (160<<16), xdim, screenwidth); -} -static int32_t ydim_from_200_16(int32_t y) -{ - y = mulscale16(y + rotatesprite_y_offset - (200<<15), rotatesprite_yxaspect) + (200<<15); - return scale(y, ydim, 200<<16); -} - -static void Menu_BlackRectangle(int32_t x, int32_t y, int32_t width, int32_t height, int32_t orientation) -{ - const int32_t xscale = divscale16(width, tilesiz[0].x<<16), yscale = divscale16(height, tilesiz[0].y<<16); - - rotatesprite_(x, y, max(xscale, yscale), 0, 0, 127, ud.shadow_pal, (orientation&(1|32))|2|8|16, 0, 0, xdim_from_320_16(x), ydim_from_200_16(y), xdim_from_320_16(x + width), ydim_from_200_16(y + height)); -} - -enum MenuTextFlags_t -{ - MT_Selected = 1<<0, - MT_Disabled = 1<<1, - MT_XCenter = 1<<2, - MT_XRight = 1<<3, - MT_YCenter = 1<<4, - MT_Literal = 1<<5, - MT_RightSide = 1<<6, -}; - -static int32_t Menu_FindOptionBinarySearch(MenuOption_t *object, const int32_t query, uint16_t searchstart, uint16_t searchend) -{ - const uint16_t thissearch = (searchstart + searchend) / 2; - const bool isIdentityMap = object->options->optionValues == NULL; - const int32_t destination = isIdentityMap ? (int32_t)thissearch : object->options->optionValues[thissearch]; - const int32_t difference = query - destination; - - Bassert(!isIdentityMap || query >= 0); - - if (difference == 0) - return thissearch; - else if (searchstart == searchend) - return -1; - else if (difference > 0) - { - if (thissearch == searchend) - return -1; - searchstart = thissearch + 1; - } - else if (difference < 0) - { - if (thissearch == searchstart) - return -1; - searchend = thissearch - 1; - } - - return Menu_FindOptionBinarySearch(object, query, searchstart, searchend); -} - -static int32_t Menu_MouseOutsideBounds(vec2_t const * const pos, const int32_t x, const int32_t y, const int32_t width, const int32_t height) -{ - return pos->x < x || pos->x >= x + width || pos->y < y || pos->y >= y + height; -} - -static void Menu_RunScrollbar(Menu_t *cm, MenuMenuFormat_t const * const format, const int32_t totalextent, int32_t * const scrollPos, const int32_t rightedge, const vec2_t origin) -{ - if (totalextent > klabs(format->bottomcutoff)) - { - int32_t scrollTile = (ud.menu_scrollbartilenum >= 0) ? ud.menu_scrollbartilenum : -1; - int32_t scrollTileTop = (ud.menu_scrollbartilenum >= 0) ? ud.menu_scrollbartilenum + 1 : -1; - int32_t scrollTileBottom = (ud.menu_scrollbartilenum >= 0) ? ud.menu_scrollbartilenum + 2 : -1; - int32_t scrollTileCursor = (ud.menu_scrollbartilenum >= 0) ? ud.menu_scrollbartilenum + 3 : SELECTDIR; - - const int32_t scrollwidth = (scrollTile >= 0) ? tilesiz[scrollTile].x*ud.menu_scrollbarz : tilesiz[scrollTileCursor].x*ud.menu_scrollcursorz; - const int32_t scrollx = origin.x + rightedge - scrollwidth, scrolly = origin.y + format->pos.y; - const int32_t scrollheight = klabs(format->bottomcutoff) - format->pos.y; - int32_t scrollregionstart = scrolly; - int32_t scrollregionend = scrolly + scrollheight; - if (ud.menu_scrollbartilenum >= 0) - { - scrollregionstart += tilesiz[scrollTileTop].y*ud.menu_scrollbarz; - scrollregionend -= tilesiz[scrollTileBottom].y*ud.menu_scrollbarz; - } - const int32_t scrollregionheight = scrollregionend - scrollregionstart - (tilesiz[scrollTileCursor].y*ud.menu_scrollcursorz); - const int32_t scrollPosMax = totalextent - klabs(format->bottomcutoff); - - if (scrollTile >= 0) - { - // draw the scrollbar (minus the top tile) twice to fill the gaps between tiles - if (tilesiz[scrollTile].y > 0) - { - for (int32_t y = scrollregionstart + ((tilesiz[scrollTileTop].y == 0)*tilesiz[scrollTile].y*ud.menu_scrollbarz); y < scrollregionend; y += tilesiz[scrollTile].y*ud.menu_scrollbarz) - rotatesprite(scrollx, y - (ud.menu_scrollbarz>>1), ud.menu_scrollbarz, 0, scrollTile, 0, 0, 26, 0, 0, xdim-1, mulscale16(scrollregionend, ydim*200)-1); - } - rotatesprite_fs(scrollx, scrollregionend - (ud.menu_scrollbarz>>1), ud.menu_scrollbarz, 0, scrollTileBottom, 0, 0, 26); - - if (tilesiz[scrollTile].y > 0) - { - for (int32_t y = scrollregionstart; y < scrollregionend; y += tilesiz[scrollTile].y*ud.menu_scrollbarz) - rotatesprite(scrollx, y, ud.menu_scrollbarz, 0, scrollTile, 0, 0, 26, 0, 0, xdim-1, mulscale16(scrollregionend, ydim*200)-1); - } - rotatesprite_fs(scrollx, scrolly, ud.menu_scrollbarz, 0, scrollTileTop, 0, 0, 26); - rotatesprite_fs(scrollx, scrollregionend, ud.menu_scrollbarz, 0, scrollTileBottom, 0, 0, 26); - } - else - Menu_BlackRectangle(scrollx, scrolly, scrollwidth, scrollheight, 1|32); - - rotatesprite_fs(scrollx + ((scrollwidth>>17)<<16) - ((tilesiz[scrollTileCursor].x>>1)*ud.menu_scrollcursorz), scrollregionstart + scale(scrollregionheight, *scrollPos, scrollPosMax), ud.menu_scrollcursorz, 0, scrollTileCursor, 0, 0, 26); - - if (cm == m_currentMenu && !m_mousecaught && MOUSEACTIVECONDITIONAL(inputState.mouseClickState() == MOUSE_PRESSED || inputState.mouseClickState() == MOUSE_HELD)) - { - const int32_t scrolltilehalfheight = (tilesiz[scrollTileCursor].y>>1)*ud.menu_scrollcursorz; - const int32_t scrollregiony = scrollregionstart + scrolltilehalfheight; - - // region between the y-midline of the arrow at the extremes scrolls proportionally - if (!Menu_MouseOutsideBounds(&m_mousepos, scrollx, scrollregiony, scrollwidth, scrollregionheight)) - { - *scrollPos = scale(m_mousepos.y - scrollregiony, scrollPosMax, scrollregionheight); - - m_mousecaught = 1; - } - // region outside the y-midlines clamps to the extremes - else if (!Menu_MouseOutsideBounds(&m_mousepos, scrollx, scrolly, scrollwidth, scrollheight)) - { - if (m_mousepos.y > scrolly + ((scrollheight>>17)<<16)) - *scrollPos = scrollPosMax; - else - *scrollPos = 0; - - m_mousecaught = 1; - } - } - } -} - -typedef enum MenuMovement_t -{ - MM_Up = 1, - MM_End = 3, - MM_Down = 4, - MM_Home = 12, - MM_Left = 16, - MM_AllTheWayLeft = 48, - MM_Right = 64, - MM_AllTheWayRight = 192, - MM_Swap = 80, -} MenuMovement_t; - -static MenuEntry_t *Menu_RunInput_Menu_MovementVerify(MenuMenu_t *menu); -static MenuEntry_t *Menu_RunInput_Menu_Movement(MenuMenu_t *menu, MenuMovement_t direction); -static void Menu_RunInput_EntryLink_Activate(MenuEntry_t *entry); -static void Menu_RunInput_EntryOptionList_MovementVerify(MenuOption_t *object); -static void Menu_RunInput_EntryOptionList_Movement(MenuOption_t *object, MenuMovement_t direction); -static int32_t Menu_RunInput_EntryOption_Modify(MenuEntry_t *entry, MenuOption_t *object, int32_t newValueIndex); -static int32_t Menu_RunInput_EntryOption_Movement(MenuEntry_t *entry, MenuOption_t *object, MenuMovement_t direction); -static int32_t Menu_RunInput_EntryOption_Activate(MenuEntry_t *entry, MenuOption_t *object); -static int32_t Menu_RunInput_EntryOptionList_Activate(MenuEntry_t *entry, MenuOption_t *object); -static void Menu_RunInput_EntryCustom2Col_Activate(MenuEntry_t *entry); -static void Menu_RunInput_EntryRangeInt32_MovementVerify(MenuEntry_t *entry, MenuRangeInt32_t *object, int32_t newValue); -static void Menu_RunInput_EntryRangeInt32_MovementArbitrary(MenuEntry_t *entry, MenuRangeInt32_t *object, int32_t newValue); -static void Menu_RunInput_EntryRangeInt32_Movement(MenuEntry_t *entry, MenuRangeInt32_t *object, MenuMovement_t direction); -static void Menu_RunInput_EntryRangeFloat_MovementVerify(MenuEntry_t *entry, MenuRangeFloat_t *object, float newValue); -static void Menu_RunInput_EntryRangeFloat_MovementArbitrary(MenuEntry_t *entry, MenuRangeFloat_t *object, float newValue); -static void Menu_RunInput_EntryRangeFloat_Movement(MenuEntry_t *entry, MenuRangeFloat_t *object, MenuMovement_t direction); -#ifdef MENU_ENABLE_RANGEDOUBLE -static void Menu_RunInput_EntryRangeDouble_MovementVerify(/*MenuEntry_t *entry, */MenuRangeDouble_t *object, double newValue); -static void Menu_RunInput_EntryRangeDouble_MovementArbitrary(/*MenuEntry_t *entry, */MenuRangeDouble_t *object, double newValue); -static void Menu_RunInput_EntryRangeDouble_Movement(/*MenuEntry_t *entry, */MenuRangeDouble_t *object, MenuMovement_t direction); -#endif -static void Menu_RunInput_EntryString_Activate(MenuEntry_t *entry); -static void Menu_RunInput_EntryString_Submit(/*MenuEntry_t *entry, */MenuString_t *object); -static void Menu_RunInput_EntryString_Cancel(/*MenuEntry_t *entry, */MenuString_t *object); -static void Menu_RunInput_FileSelect_MovementVerify(MenuFileSelect_t *object); -static void Menu_RunInput_FileSelect_Movement(MenuFileSelect_t *object, MenuMovement_t direction); -static void Menu_RunInput_FileSelect_Select(MenuFileSelect_t *object); - -static int32_t M_RunMenu_Menu(Menu_t *cm, MenuMenu_t *menu, MenuEntry_t *currentry, int32_t state, const vec2_t origin, bool actually_draw) -{ - int32_t totalHeight = 0; - - // RIP MenuGroup_t b. 2014-03-?? d. 2014-11-29 - { - int32_t e; - const int32_t y_upper = menu->format->pos.y; - const int32_t y_lower = klabs(menu->format->bottomcutoff); - int32_t y = 0; - int32_t calculatedentryspacing = 0; - - if (menu->format->bottomcutoff < 0) - { - int32_t totalheight = 0, numvalidentries = 0; - - for (e = 0; e < menu->numEntries; ++e) - { - MenuEntry_t *entry = menu->entrylist[e]; - - if (entry == NULL || (entry->flags & MEF_Hidden)) - continue; - - ++numvalidentries; - - // assumes height == font->get_yline()! - totalheight += entry->getHeight(); - } - - calculatedentryspacing = (klabs(menu->format->bottomcutoff) - menu->format->pos.y - totalheight) / (numvalidentries > 1 ? numvalidentries - 1 : 1); - } - - // totalHeight calculating pass - for (e = 0; e < menu->numEntries; ++e) - { - MenuEntry_t *entry = menu->entrylist[e]; - - if (entry == NULL || (entry->flags & MEF_Hidden)) - continue; - - int32_t const height = entry->getHeight(); - - y += height; - totalHeight = y; - y += (!calculatedentryspacing || calculatedentryspacing > entry->getMarginBottom()) ? entry->getMarginBottom() : calculatedentryspacing; - } - y = 0; - - int32_t ydim_upper, ydim_lower; - if (y_upper + totalHeight > y_lower) - { - ydim_upper = ydim_from_200_16(origin.y + y_upper); - ydim_lower = ydim_from_200_16(origin.y + y_lower); - } - else - { - ydim_upper = 0; - ydim_lower = ydim-1; - } - - for (e = 0; e < menu->numEntries; ++e) - { - MenuEntry_t *entry = menu->entrylist[e]; - - if (entry == NULL || (entry->flags & MEF_Hidden)) - continue; - - int32_t const indent = entry->getIndent(); - int32_t x = menu->format->pos.x; - - uint8_t status = 0; - if (e == menu->currentEntry) - status |= MT_Selected; - if (entry->flags & (MEF_Disabled|MEF_LookDisabled)) - status |= MT_Disabled; - if (entry->format->width == 0) - status |= MT_XCenter; - - bool const dodraw = entry->type != Spacer && actually_draw && - 0 <= y - menu->scrollPos + entry->font->get_yline() && - y - menu->scrollPos <= klabs(menu->format->bottomcutoff) - menu->format->pos.y; - - int32_t const height = entry->getHeight(); // max(textsize.y, entry->font->get_yline()); // bluefont Q ruins this - status |= MT_YCenter; - int32_t const y_internal = origin.y + y_upper + y + ((height>>17)<<16) - menu->scrollPos; - - vec2_t textsize; - if (dodraw) - textsize = Menu_Text(origin.x + x + indent, y_internal, entry->font, entry->name, status, ydim_upper, ydim_lower); - - if (entry->format->width < 0) - status |= MT_XRight; - - if (dodraw && (status & MT_Selected) && state != 1) - { - if (status & MT_XCenter) - { - Menu_DrawCursorLeft(origin.x + (MENU_MARGIN_CENTER<<16) + entry->font->cursorCenterPosition, y_internal, entry->font->cursorScale); - Menu_DrawCursorRight(origin.x + (MENU_MARGIN_CENTER<<16) - entry->font->cursorCenterPosition, y_internal, entry->font->cursorScale); - } - else - Menu_DrawCursorLeft(origin.x + x + indent - entry->font->cursorLeftPosition, y_internal, entry->font->cursorScale); - } - - if (entry->name != nullptr && entry->name[0] != '\0') - status |= MT_RightSide; - - // need this up here to avoid race conditions - entry->ybottom = (entry->ytop = y_upper + y) + height; - - if (dodraw) - { - const int32_t mousex = origin.x + indent + entry->format->width == 0 ? x - ((textsize.x>>17)<<16) : x; - const int32_t mousey = origin.y + y_upper + y - menu->scrollPos; - int32_t mousewidth = entry->format->width == 0 ? textsize.x : klabs(entry->format->width); - - if (entry->name) - x += klabs(entry->format->width); - - switch (entry->type) - { - case Spacer: - break; - case Dummy: - if (MOUSEACTIVECONDITIONAL(state != 1 && cm == m_currentMenu && !Menu_MouseOutsideBounds(&m_mousepos, mousex, mousey, mousewidth, height))) - { - if (MOUSEWATCHPOINTCONDITIONAL(Menu_MouseOutsideBounds(&m_prevmousepos, mousex, mousey, mousewidth, height))) - { - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - } - } - break; - case Link: - if (MOUSEACTIVECONDITIONAL(state != 1 && cm == m_currentMenu && !Menu_MouseOutsideBounds(&m_mousepos, mousex, mousey, mousewidth, height))) - { - if (MOUSEWATCHPOINTCONDITIONAL(Menu_MouseOutsideBounds(&m_prevmousepos, mousex, mousey, mousewidth, height))) - { - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - } - - if (!m_mousecaught && inputState.mouseClickState() == MOUSE_RELEASED && !Menu_MouseOutsideBounds(&m_mousedownpos, mousex, mousey, mousewidth, entry->font->get_yline())) - { - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - - if (entry->flags & MEF_Disabled) - break; - - Menu_RunInput_EntryLink_Activate(entry); - - if (g_player[myconnectindex].ps->gm&MODE_MENU) // for skill selection - S_PlaySound(PISTOL_BODYHIT); - - m_mousecaught = 1; - } - } - break; - case Option: - { - auto object = (MenuOption_t*)entry->entry; - int32_t currentOption = Menu_FindOptionBinarySearch(object, object->cVar == NULL ? Menu_EntryOptionSource(entry, object->currentOption) : object->cVar->ToInt(), 0, object->options->numOptions); - - if (currentOption >= 0) - object->currentOption = currentOption; - - int32_t optiontextx = origin.x + x; - const int32_t optiontexty = origin.y + y_upper + y - menu->scrollPos; - - const vec2_t optiontextsize = Menu_Text(optiontextx, optiontexty + ((height>>17)<<16), object->font, - currentOption < 0 ? MenuCustom : currentOption < object->options->numOptions ? object->options->optionNames[currentOption] : NULL, - status, ydim_upper, ydim_lower); - - if (entry->format->width > 0) - mousewidth += optiontextsize.x; - else - optiontextx -= optiontextsize.x; - - if (MOUSEACTIVECONDITIONAL(state != 1 && cm == m_currentMenu && !Menu_MouseOutsideBounds(&m_mousepos, mousex, mousey, mousewidth, height))) - { - if (MOUSEWATCHPOINTCONDITIONAL(Menu_MouseOutsideBounds(&m_prevmousepos, mousex, mousey, mousewidth, height))) - { - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - } - - if (!m_mousecaught && inputState.mouseClickState() == MOUSE_RELEASED && !Menu_MouseOutsideBounds(&m_mousedownpos, mousex, mousey, mousewidth, entry->font->get_yline())) - { - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - - if (entry->flags & MEF_Disabled) - break; - - Menu_RunInput_EntryOption_Activate(entry, object); - - S_PlaySound(PISTOL_BODYHIT); - - m_mousecaught = 1; - } - } - - break; - } - case Custom2Col: - { - auto object = (MenuCustom2Col_t*)entry->entry; - int32_t columnx[2] = { origin.x + x - ((status & MT_XRight) ? object->columnWidth : 0), origin.x + x + ((status & MT_XRight) ? 0 : object->columnWidth) }; - const int32_t columny = origin.y + y_upper + y - menu->scrollPos; - - // Beware of hack job! - auto keys = Bindings.GetKeysForCommand(buttonMap.GetButtonName(object->buttonindex)); - FString text1; - FString text2; - if (keys.Size() > 0) text1 = C_NameKeys(&keys[0], 1); - if (keys.Size() > 1) text2 = C_NameKeys(&keys[1], 1); - const vec2_t column0textsize = Menu_Text(columnx[0], columny + ((height >> 17) << 16), object->font, text1, menu->currentColumn == 0 ? status : (status & ~MT_Selected), ydim_upper, ydim_lower); - const vec2_t column1textsize = Menu_Text(columnx[1], columny + ((height>>17)<<16), object->font, text2, menu->currentColumn == 1 ? status : (status & ~MT_Selected), ydim_upper, ydim_lower); - - if (entry->format->width > 0) - mousewidth += object->columnWidth + column1textsize.x; - else - { - columnx[0] -= column0textsize.x; - columnx[1] -= column0textsize.x; - } - - if (MOUSEACTIVECONDITIONAL(state != 1 && cm == m_currentMenu && !Menu_MouseOutsideBounds(&m_mousepos, mousex, mousey, mousewidth, height))) - { - if (MOUSEWATCHPOINTCONDITIONAL(Menu_MouseOutsideBounds(&m_prevmousepos, mousex, mousey, mousewidth, height))) - { - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - } - - if (!Menu_MouseOutsideBounds(&m_mousepos, columnx[1], mousey, column1textsize.x, object->font->get_yline())) - { - if (MOUSEWATCHPOINTCONDITIONAL(Menu_MouseOutsideBounds(&m_prevmousepos, columnx[1], mousey, column1textsize.x, object->font->get_yline()))) - { - menu->currentColumn = 1; - } - - if (!m_mousecaught && inputState.mouseClickState() == MOUSE_RELEASED && !Menu_MouseOutsideBounds(&m_mousedownpos, columnx[1], mousey, column1textsize.x, object->font->get_yline())) - { - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - menu->currentColumn = 1; - - if (entry->flags & MEF_Disabled) - break; - - Menu_RunInput_EntryCustom2Col_Activate(entry); - - S_PlaySound(PISTOL_BODYHIT); - - m_mousecaught = 1; - } - } - else if (!Menu_MouseOutsideBounds(&m_mousepos, columnx[0], mousey, column0textsize.x, object->font->get_yline())) - { - if (MOUSEWATCHPOINTCONDITIONAL(Menu_MouseOutsideBounds(&m_prevmousepos, columnx[0], mousey, column0textsize.x, object->font->get_yline()))) - { - menu->currentColumn = 0; - } - - if (!m_mousecaught && inputState.mouseClickState() == MOUSE_RELEASED && !Menu_MouseOutsideBounds(&m_mousedownpos, columnx[0], mousey, column0textsize.x, object->font->get_yline())) - { - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - menu->currentColumn = 0; - - if (entry->flags & MEF_Disabled) - break; - - Menu_RunInput_EntryCustom2Col_Activate(entry); - - S_PlaySound(PISTOL_BODYHIT); - - m_mousecaught = 1; - } - } - } - break; - } - case RangeInt32: - { - auto object = (MenuRangeInt32_t*)entry->entry; - - int32_t s, p; - int32_t z = entry->font->cursorScale; - Menu_GetFmt(object->font, status|MT_RightSide, &s, &z); - - if (status & MT_Disabled) - p = ud.slidebar_paldisabled; - else if (status & MT_Selected) - p = ud.slidebar_palselected; - else - p = 0; - - const int32_t slidebarwidth = mulscale16(tilesiz[SLIDEBAR].x * ud.menu_slidebarz, z); - const int32_t slidebarheight = mulscale16(tilesiz[SLIDEBAR].y * ud.menu_slidebarz, z); - - if (status & MT_XRight) - x -= slidebarwidth; - else - mousewidth += slidebarwidth; - - const int32_t slidebarx = origin.x + x; - const int32_t slidebary = origin.y + y_upper + y + (((height - slidebarheight)>>17)<<16) - menu->scrollPos; - - rotatesprite_ybounds(slidebarx, slidebary, mulscale16(ud.menu_slidebarz, z), 0, SLIDEBAR, s, p, 2|8|16|ROTATESPRITE_FULL16, ydim_upper, ydim_lower); - - const int32_t slideregionwidth = mulscale16((tilesiz[SLIDEBAR].x * ud.menu_slidebarz) - (ud.menu_slidebarmargin<<1) - (tilesiz[SLIDEBAR+1].x * ud.menu_slidecursorz), z); - const int32_t slidepointx = slidebarx + mulscale16(ud.menu_slidebarmargin, z) + scale(slideregionwidth, *object->cVar - object->min, object->max - object->min); - const int32_t slidepointy = slidebary + mulscale16((((tilesiz[SLIDEBAR].y>>1) * ud.menu_slidebarz) - ((tilesiz[SLIDEBAR+1].y>>1) * ud.menu_slidecursorz)), z); - - rotatesprite_ybounds(slidepointx, slidepointy, mulscale16(ud.menu_slidecursorz, z), 0, SLIDEBAR+1, s, p, 2|8|16|ROTATESPRITE_FULL16, ydim_upper, ydim_lower); - - if (object->flags & DisplayTypeMask) - { - status |= MT_XRight; - - int32_t onehundredpercent = object->onehundredpercent; - if (onehundredpercent == 0) - onehundredpercent = object->max; - - switch (object->flags & DisplayTypeMask) - { - case DisplayTypeInteger: - Bsprintf(tempbuf, "%d", **object->cVar); - break; - case DisplayTypePercent: - Bsprintf(tempbuf, "%d%%", roundscale(*object->cVar, 100, onehundredpercent)); - break; - case DisplayTypeNormalizedDecimal: - Bsprintf(tempbuf, "%.2f", (double) *object->cVar / (double) onehundredpercent); - break; - } - - Menu_Text(origin.x + x - (4<<16), origin.y + y_upper + y + ((height>>17)<<16) - menu->scrollPos, object->font, tempbuf, status, ydim_upper, ydim_lower); - } - - if (MOUSEACTIVECONDITIONAL(state != 1 && cm == m_currentMenu && !Menu_MouseOutsideBounds(&m_mousepos, mousex, mousey, mousewidth, height))) - { - if (MOUSEWATCHPOINTCONDITIONAL(Menu_MouseOutsideBounds(&m_prevmousepos, mousex, mousey, mousewidth, height))) - { - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - } - - if (!m_mousecaught && (inputState.mouseClickState() == MOUSE_PRESSED || inputState.mouseClickState() == MOUSE_HELD)) - { - const int32_t slidepointhalfwidth = mulscale16((((tilesiz[SLIDEBAR+1].x)*ud.menu_slidecursorz)>>2) + ud.menu_slidebarmargin, z); - const int32_t slideregionx = slidebarx + slidepointhalfwidth; - - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - - if (entry->flags & MEF_Disabled) - break; - - // region between the x-midline of the slidepoint at the extremes slides proportionally - if (!Menu_MouseOutsideBounds(&m_mousepos, slideregionx, mousey, slideregionwidth, height)) - { - Menu_RunInput_EntryRangeInt32_MovementArbitrary(entry, object, roundscale(object->max - object->min, m_mousepos.x - slideregionx, slideregionwidth) + object->min); - - m_mousecaught = 1; - } - // region outside the x-midlines clamps to the extremes - else if (!Menu_MouseOutsideBounds(&m_mousepos, slidebarx, mousey, slidebarwidth, height)) - { - if (m_mousepos.x > slideregionx + ((slideregionwidth>>17)<<16)) - Menu_RunInput_EntryRangeInt32_MovementVerify(entry, object, object->max); - else - Menu_RunInput_EntryRangeInt32_MovementVerify(entry, object, object->min); - - m_mousecaught = 1; - } - } - } - - break; - } - case RangeFloat: - { - auto object = (MenuRangeFloat_t*)entry->entry; - - int32_t s, p; - int32_t z = entry->font->cursorScale; - Menu_GetFmt(object->font, status|MT_RightSide, &s, &z); - - if (status & MT_Disabled) - p = ud.slidebar_paldisabled; - else if (status & MT_Selected) - p = ud.slidebar_palselected; - else - p = 0; - - const int32_t slidebarwidth = mulscale16(tilesiz[SLIDEBAR].x * ud.menu_slidebarz, z); - const int32_t slidebarheight = mulscale16(tilesiz[SLIDEBAR].y * ud.menu_slidebarz, z); - - if (status & MT_XRight) - x -= slidebarwidth; - else - mousewidth += slidebarwidth; - - const int32_t slidebarx = origin.x + x; - const int32_t slidebary = origin.y + y_upper + y + (((height - slidebarheight)>>17)<<16) - menu->scrollPos; - - rotatesprite_ybounds(slidebarx, slidebary, mulscale16(ud.menu_slidebarz, z), 0, SLIDEBAR, s, p, 2|8|16|ROTATESPRITE_FULL16, ydim_upper, ydim_lower); - - const int32_t slideregionwidth = mulscale16((tilesiz[SLIDEBAR].x * ud.menu_slidebarz) - (ud.menu_slidebarmargin<<1) - (tilesiz[SLIDEBAR+1].x * ud.menu_slidecursorz), z); - const int32_t slidepointx = slidebarx + mulscale16(ud.menu_slidebarmargin, z) + Blrintf((float) slideregionwidth * (*object->cVar - object->min) / (object->max - object->min)); - const int32_t slidepointy = slidebary + mulscale16(((tilesiz[SLIDEBAR].y>>1) * ud.menu_slidebarz) - ((tilesiz[SLIDEBAR+1].y>>1) * ud.menu_slidecursorz), z); - - rotatesprite_ybounds(slidepointx, slidepointy, mulscale16(ud.menu_slidecursorz, z), 0, SLIDEBAR+1, s, p, 2|8|16|ROTATESPRITE_FULL16, ydim_upper, ydim_lower); - - if (object->flags & DisplayTypeMask) - { - status |= MT_XRight; - - float onehundredpercent = object->onehundredpercent; - if (onehundredpercent == 0.f) - onehundredpercent = 1.f; - - switch (object->flags & DisplayTypeMask) - { - case DisplayTypeInteger: - Bsprintf(tempbuf, "%.2f", **object->cVar); - break; - case DisplayTypePercent: - Bsprintf(tempbuf, "%ld%%", lrintf(*object->cVar * 100.f / onehundredpercent)); - break; - case DisplayTypeNormalizedDecimal: - Bsprintf(tempbuf, "%.2f", *object->cVar / onehundredpercent); - break; - } - - Menu_Text(origin.x + x - (4<<16), origin.y + y_upper + y + ((height>>17)<<16) - menu->scrollPos, object->font, tempbuf, status, ydim_upper, ydim_lower); - } - - if (MOUSEACTIVECONDITIONAL(state != 1 && cm == m_currentMenu && !Menu_MouseOutsideBounds(&m_mousepos, mousex, mousey, mousewidth, height))) - { - if (MOUSEWATCHPOINTCONDITIONAL(Menu_MouseOutsideBounds(&m_prevmousepos, mousex, mousey, mousewidth, height))) - { - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - } - - if (!m_mousecaught && (inputState.mouseClickState() == MOUSE_PRESSED || inputState.mouseClickState() == MOUSE_HELD)) - { - const int32_t slidepointhalfwidth = mulscale16((2+tilesiz[SLIDEBAR+1].x)<<15, z); - const int32_t slideregionx = slidebarx + slidepointhalfwidth; - - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - - if (entry->flags & MEF_Disabled) - break; - - // region between the x-midline of the slidepoint at the extremes slides proportionally - if (!Menu_MouseOutsideBounds(&m_mousepos, slideregionx, mousey, slideregionwidth, height)) - { - Menu_RunInput_EntryRangeFloat_MovementArbitrary(entry, object, (object->max - object->min) * (m_mousepos.x - slideregionx) / slideregionwidth + object->min); - - m_mousecaught = 1; - } - // region outside the x-midlines clamps to the extremes - else if (!Menu_MouseOutsideBounds(&m_mousepos, slidebarx, mousey, slidebarwidth, height)) - { - if (m_mousepos.x > slideregionx + (slideregionwidth>>17<<16)) - Menu_RunInput_EntryRangeFloat_MovementVerify(entry, object, object->max); - else - Menu_RunInput_EntryRangeFloat_MovementVerify(entry, object, object->min); - - m_mousecaught = 1; - } - } - } - - break; - } - - case String: - { - auto object = (MenuString_t*)entry->entry; - - vec2_t dim; - int32_t stringx = x; - const int32_t stringy = origin.y + y_upper + y + ((height>>17)<<16) - menu->scrollPos; - int32_t h; - - if (entry == currentry && object->editfield != NULL) - { - dim = Menu_Text(origin.x + stringx, stringy, object->font, object->editfield, (status & ~MT_Disabled) | MT_Literal, ydim_upper, ydim_lower); - h = max(dim.y, entry->font->get_yline()); - - Menu_DrawCursorText(origin.x + x + dim.x + (1<<16), stringy, h, ydim_upper, ydim_lower); - } - else - { - dim = Menu_Text(origin.x + stringx, stringy, object->font, object->variable, status, ydim_upper, ydim_lower); - h = max(dim.y, entry->font->get_yline()); - } - - if (entry->format->width > 0) - { - if (entry->name) - mousewidth += dim.x; - } - else - stringx -= dim.x; - - if (MOUSEACTIVECONDITIONAL(cm == m_currentMenu && !Menu_MouseOutsideBounds(&m_mousepos, mousex, mousey, mousewidth, h))) - { - if (state != 1 && Menu_MouseOutsideBounds(&m_prevmousepos, mousex, mousey, mousewidth, h)) - { - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - } - - #ifndef EDUKE32_TOUCH_DEVICES - if (!m_mousecaught && inputState.mouseClickState() == MOUSE_RELEASED && !Menu_MouseOutsideBounds(&m_mousepos, mousex, mousey, mousewidth, h) && !Menu_MouseOutsideBounds(&m_mousedownpos, mousex, mousey, mousewidth, h)) - #endif - { - if (entry == currentry && object->editfield != NULL) - { - Menu_RunInput_EntryString_Submit(/*entry, */object); - - S_PlaySound(PISTOL_BODYHIT); - - m_mousecaught = 1; - } - else if (state != 1) - { - menu->currentEntry = e; - Menu_RunInput_Menu_MovementVerify(menu); - - if (entry->flags & MEF_Disabled) - break; - - Menu_RunInput_EntryString_Activate(entry); - - S_PlaySound(PISTOL_BODYHIT); - - m_mousecaught = 1; - } - } - } - - break; - } - } - } - - // prepare for the next line - y += height; - y += (!calculatedentryspacing || calculatedentryspacing > entry->getMarginBottom()) ? entry->getMarginBottom() : calculatedentryspacing; - } - - // draw indicators if applicable - if (actually_draw) - Menu_RunScrollbar(cm, menu->format, y_upper + totalHeight, &menu->scrollPos, 320<<16, origin); - } - - return totalHeight; -} - -static void Menu_RunOptionList(Menu_t *cm, MenuEntry_t *entry, MenuOption_t *object, const vec2_t origin) -{ - int32_t e, y = 0; - const int32_t y_upper = object->options->menuFormat->pos.y; - const int32_t y_lower = object->options->menuFormat->bottomcutoff; - int32_t calculatedentryspacing = object->options->getMarginBottom(); - - // assumes height == font->get_yline()! - if (calculatedentryspacing < 0) - calculatedentryspacing = (-calculatedentryspacing - object->options->font->get_yline()) / (object->options->numOptions - 1) - object->options->font->get_yline(); - - int32_t totalHeight = 0; - for (e = 0; e < object->options->numOptions; ++e) - { - int32_t const height = object->options->font->get_yline(); - - y += height; - totalHeight = y; - y += calculatedentryspacing; - } - y = 0; - - int32_t ydim_upper, ydim_lower; - if (y_upper + totalHeight > y_lower) - { - ydim_upper = ydim_from_200_16(origin.y + y_upper); - ydim_lower = ydim_from_200_16(origin.y + y_lower); - } - else - { - ydim_upper = 0; - ydim_lower = ydim-1; - } - - for (e = 0; e < object->options->numOptions; ++e) - { - int32_t const x = object->options->menuFormat->pos.x; - - uint8_t status = 0; - if (e == object->options->currentEntry) - status |= MT_Selected; - if (object->options->entryFormat->width == 0) - status |= MT_XCenter; - - bool const dodraw = 0 <= y - object->options->scrollPos + object->options->font->get_yline() && - y - object->options->scrollPos <= object->options->menuFormat->bottomcutoff - object->options->menuFormat->pos.y; - - int32_t const height = object->options->font->get_yline(); // max(textsize.y, object->options->font->get_yline()); - status |= MT_YCenter; - int32_t const y_internal = origin.y + y_upper + y + ((height>>17)<<16) - object->options->scrollPos; - - vec2_t textsize; - if (dodraw) - textsize = Menu_Text(origin.x + x, y_internal, object->options->font, object->options->optionNames[e], status, ydim_upper, ydim_lower); - - if (object->options->entryFormat->width < 0) - status |= MT_XRight; - - if (dodraw && (status & MT_Selected)) - { - if (status & MT_XCenter) - { - Menu_DrawCursorLeft(origin.x + (MENU_MARGIN_CENTER<<16) + object->options->font->cursorCenterPosition, y_internal, object->options->font->cursorScale); - Menu_DrawCursorRight(origin.x + (MENU_MARGIN_CENTER<<16) - object->options->font->cursorCenterPosition, y_internal, object->options->font->cursorScale); - } - else - Menu_DrawCursorLeft(origin.x + x - object->options->font->cursorLeftPosition, y_internal, object->options->font->cursorScale); - } - - if (dodraw) - { - const int32_t mousex = origin.x + object->options->entryFormat->width == 0 ? x - ((textsize.x>>17)<<16) : x; - const int32_t mousey = origin.y + y_upper + y - object->options->scrollPos; - const int32_t mousewidth = object->options->entryFormat->width == 0 ? textsize.x : klabs(object->options->entryFormat->width); - - if (MOUSEACTIVECONDITIONAL(cm == m_currentMenu && !Menu_MouseOutsideBounds(&m_mousepos, mousex, mousey, mousewidth, object->options->font->get_yline()))) - { - if (MOUSEWATCHPOINTCONDITIONAL(Menu_MouseOutsideBounds(&m_prevmousepos, mousex, mousey, mousewidth, object->options->font->get_yline()))) - { - object->options->currentEntry = e; - } - - if (!m_mousecaught && inputState.mouseClickState() == MOUSE_RELEASED && !Menu_MouseOutsideBounds(&m_mousedownpos, mousex, mousey, mousewidth, object->options->font->get_yline())) - { - object->options->currentEntry = e; - - if (!Menu_RunInput_EntryOptionList_Activate(entry, object)) - S_PlaySound(PISTOL_BODYHIT); - - m_mousecaught = 1; - } - } - } - - // prepare for the next line - y += height; - y += calculatedentryspacing; - } - - // draw indicators if applicable - Menu_RunScrollbar(cm, object->options->menuFormat, y_upper + totalHeight, &object->options->scrollPos, 320<<16, origin); -} - -static int32_t Menu_RunInput_MouseAdvance(void) -{ - return MOUSEACTIVECONDITIONAL(!m_mousecaught && inputState.mouseClickState() == MOUSE_RELEASED); -} - -static int32_t Menu_RunInput_MouseReturn_status; - -#if !defined EDUKE32_TOUCH_DEVICES -static void Menu_Run_MouseReturn(Menu_t *cm, const vec2_t origin) -{ - if (!MOUSEACTIVECONDITION) - return; - - if (cm->menuID == MENU_MAIN) - return; - - uint32_t const posx = tilesiz[SELECTDIR].y * SELECTDIR_z; - - rotatesprite_(origin.x + posx, 0, SELECTDIR_z, 512, SELECTDIR, - Menu_RunInput_MouseReturn_status ? 4 - (sintable[((int32_t) totalclock << 4) & 2047] >> 11) : 6, 0, - 2 | 8 | 16 | RS_ALIGN_L, MOUSEALPHA, 0, xdim_from_320_16(origin.x + x_widescreen_left()), 0, - xdim_from_320_16(origin.x + x_widescreen_left() + ((posx>>17)<<16)), ydim - 1); -} -#endif - -static int32_t Menu_RunInput_MouseReturn(void) -{ -#if !defined EDUKE32_TOUCH_DEVICES - if (!MOUSEACTIVECONDITION) - { - Menu_RunInput_MouseReturn_status = 0; - return 0; - } -#endif - - if (g_currentMenu == MENU_MAIN) - return 0; - - const int32_t MouseReturnRegionX = x_widescreen_left(); - - vec2_t backbuttonbound = { ((tilesiz[SELECTDIR].y * SELECTDIR_z)>>17)<<16, tilesiz[SELECTDIR].x * SELECTDIR_z }; - - if (!Menu_MouseOutsideBounds(&m_mousepos, MouseReturnRegionX, 0, backbuttonbound.x, backbuttonbound.y)) - { -#if !defined EDUKE32_TOUCH_DEVICES - Menu_RunInput_MouseReturn_status = 1; -#else - Menu_RunInput_MouseReturn_status = (inputState.mouseClickState() == MOUSE_PRESSED || inputState.mouseClickState() == MOUSE_HELD); -#endif - - return !m_mousecaught && inputState.mouseClickState() == MOUSE_RELEASED && !Menu_MouseOutsideBounds(&m_mousedownpos, MouseReturnRegionX, 0, backbuttonbound.x, backbuttonbound.y); - } - - Menu_RunInput_MouseReturn_status = 0; - - return 0; -} - -static void Menu_Run_AbbreviateNameIntoBuffer(const char* name, int32_t entrylength) -{ - int32_t len = Bstrlen(name); - Bstrncpy(tempbuf, name, ARRAY_SIZE(tempbuf)); - if (len > entrylength) - { - len = entrylength-3; - tempbuf[len] = 0; - while (len < entrylength) - tempbuf[len++] = '.'; - } - tempbuf[len] = 0; -} - -static void Menu_Recurse(MenuID_t cm, const vec2_t origin) -{ - switch (cm) - { - case MENU_SAVECLEANVERIFY: - case MENU_LOADVERIFY: - case MENU_LOADDELVERIFY: - case MENU_SAVEVERIFY: - case MENU_SAVEDELVERIFY: - case MENU_COLCORRRESETVERIFY: - case MENU_KEYSRESETVERIFY: - case MENU_KEYSCLASSICVERIFY: - case MENU_JOYSTANDARDVERIFY: - case MENU_JOYPROVERIFY: - case MENU_JOYCLEARVERIFY: - case MENU_ADULTPASSWORD: - case MENU_CHEATENTRY: - case MENU_CHEAT_WARP: - case MENU_CHEAT_SKILL: - Menu_Run(m_previousMenu, origin); - break; - default: - break; - } -} - -static void Menu_Run(Menu_t *cm, const vec2_t origin) -{ - Menu_Recurse(cm->menuID, origin); - - switch (cm->type) - { - case Verify: - { - auto object = (MenuVerify_t*)cm->object; - - Menu_Pre(cm->menuID); - - Menu_PreDrawBackground(cm->menuID, origin); - - Menu_PreDraw(cm->menuID, NULL, origin); - - Menu_DrawCursorLeft(origin.x + object->cursorpos.x, origin.y + object->cursorpos.y, 65536); - - break; - } - - case Message: - { - auto object = (MenuMessage_t*)cm->object; - - Menu_Pre(cm->menuID); - - Menu_PreDrawBackground(cm->menuID, origin); - - Menu_PreDraw(cm->menuID, NULL, origin); - - Menu_DrawCursorLeft(origin.x + object->cursorpos.x, origin.y + object->cursorpos.y, 65536); - - break; - } - - case TextForm: - { - auto object = (MenuTextForm_t*)cm->object; - - Menu_Pre(cm->menuID); - - Menu_PreDrawBackground(cm->menuID, origin); - - Menu_BlackRectangle(origin.x + (60<<16), origin.y + (86<<16), 200<<16, 28<<16, 0); - - mgametextcenter(origin.x, origin.y + (98<<16), object->instructions, TEXT_YBOTTOM); - - const char *displaytext = object->input; - - if (object->flags & MTF_Password) - { - size_t x; - for (x = 0; x < Bstrlen(object->input); ++x) - tempbuf[x] = '*'; - tempbuf[x] = 0; - - displaytext = tempbuf; - } - - const vec2_t textreturn = mgametextcenter(origin.x, origin.y + (102<<16), displaytext); - - Menu_PreDraw(cm->menuID, NULL, origin); - - int32_t const h = MF_Bluefont.get_yline(); - - Menu_DrawCursorText(origin.x + (MENU_MARGIN_CENTER<<16) + ((textreturn.x>>17)<<16) + (1<<16), origin.y + (102<<16) + ((h>>17)<<16), h); - - break; - } - - - - case Panel: - { - auto object = (MenuPanel_t*)cm->object; - - Menu_Pre(cm->menuID); - - Menu_PreDrawBackground(cm->menuID, origin); - - if (object->title != NoTitle) - Menu_DrawTopBar(origin); - - Menu_PreDraw(cm->menuID, NULL, origin); - - if (object->title != NoTitle) - Menu_DrawTopBarCaption(object->title, origin); - - break; - } - - case Menu: - { - int32_t state; - - auto menu = (MenuMenu_t*)cm->object; - MenuEntry_t *currentry = menu->entrylist[menu->currentEntry]; - - state = Menu_DetermineSpecialState(currentry); - - if (state != 2) - { - Menu_Pre(cm->menuID); - - Menu_PreDrawBackground(cm->menuID, origin); - - if (menu->title != NoTitle) - Menu_DrawTopBar(origin); - - Menu_PreDraw(cm->menuID, currentry, origin); - - M_RunMenu_Menu(cm, menu, currentry, state, origin); - } - else - { - Menu_PreDrawBackground(cm->menuID, origin); - - if (menu->title != NoTitle) - Menu_DrawTopBar(origin); - - if (currentry->type == Option) - { - if (currentry->name) - Menu_DrawTopBarCaption(currentry->name, origin); - - Menu_PreOptionListDraw(currentry, origin); - - Menu_RunOptionList(cm, currentry, (MenuOption_t*)currentry->entry, origin); - } - else if (currentry->type == Custom2Col) - { - Menu_PreCustom2ColScreenDraw(currentry, origin); - } - } - - if ((currentry->type != Option || state != 2) && menu->title != NoTitle) - Menu_DrawTopBarCaption(menu->title, origin); - - break; - } - } - -#if !defined EDUKE32_TOUCH_DEVICES - Menu_Run_MouseReturn(cm, origin); -#endif -} - -/* -Note: When menus are exposed to scripting, care will need to be taken so that -a user cannot define an empty MenuEntryList, or one containing only spacers, -or else this function will recurse infinitely. -*/ -static MenuEntry_t *Menu_RunInput_Menu_MovementVerify(MenuMenu_t *menu) -{ - return Menu_AdjustForCurrentEntryAssignment(menu); -} - -static MenuEntry_t *Menu_RunInput_Menu_Movement(MenuMenu_t *menu, MenuMovement_t direction) -{ - if (menu->numEntries == 1) - return menu->entrylist[menu->currentEntry]; - - switch (direction) - { - case MM_End: - menu->currentEntry = menu->numEntries; - fallthrough__; - case MM_Up: - do - { - --menu->currentEntry; - if (menu->currentEntry < 0) - return Menu_RunInput_Menu_Movement(menu, MM_End); - } - while (!menu->entrylist[menu->currentEntry] || - (menu->entrylist[menu->currentEntry]->flags & MEF_Hidden) || - menu->entrylist[menu->currentEntry]->type == Spacer); - break; - - case MM_Home: - menu->currentEntry = -1; - fallthrough__; - case MM_Down: - do - { - ++menu->currentEntry; - if (menu->currentEntry >= menu->numEntries) - return Menu_RunInput_Menu_Movement(menu, MM_Home); - } - while (!menu->entrylist[menu->currentEntry] || - (menu->entrylist[menu->currentEntry]->flags & MEF_Hidden) || - menu->entrylist[menu->currentEntry]->type == Spacer); - break; - - case MM_Swap: - menu->currentColumn = !menu->currentColumn; - break; - - default: - break; - } - - return Menu_RunInput_Menu_MovementVerify(menu); -} - -static void Menu_RunInput_EntryLink_Activate(MenuEntry_t *entry) -{ - auto link = (MenuLink_t*)entry->entry; - - Menu_EntryLinkActivate(entry); - - Menu_AnimateChange(link->linkID, link->animation); -} - -static void Menu_RunInput_EntryOptionList_MovementVerify(MenuOption_t *object) -{ - const int32_t listytop = object->options->menuFormat->pos.y; - // assumes height == font->get_yline()! - const int32_t unitheight = object->options->getMarginBottom() < 0 ? (-object->options->getMarginBottom() - object->options->font->get_yline()) / object->options->numOptions : (object->options->font->get_yline() + object->options->getMarginBottom()); - const int32_t ytop = listytop + object->options->currentEntry * unitheight; - const int32_t ybottom = ytop + object->options->font->get_yline(); - - if (ybottom - object->options->scrollPos > object->options->menuFormat->bottomcutoff) - object->options->scrollPos = ybottom - object->options->menuFormat->bottomcutoff; - else if (ytop - object->options->scrollPos < listytop) - object->options->scrollPos = ytop - listytop; -} - -static void Menu_RunInput_EntryOptionList_Movement(MenuOption_t *object, MenuMovement_t direction) -{ - switch (direction) - { - case MM_Up: - --object->options->currentEntry; - if (object->options->currentEntry >= 0) - break; - fallthrough__; - case MM_End: - object->options->currentEntry = object->options->numOptions-1; - break; - - case MM_Down: - ++object->options->currentEntry; - if (object->options->currentEntry < object->options->numOptions) - break; - fallthrough__; - case MM_Home: - object->options->currentEntry = 0; - break; - - default: - break; - } - - Menu_RunInput_EntryOptionList_MovementVerify(object); -} - -static int32_t Menu_RunInput_EntryOption_Modify(MenuEntry_t *entry, MenuOption_t *object, int32_t newValueIndex) -{ - int32_t newValue = (object->options->optionValues == NULL) ? newValueIndex : object->options->optionValues[newValueIndex]; - if (!Menu_EntryOptionModify(entry, newValue)) - { - object->currentOption = newValueIndex; - - if (object->cVar != NULL) // NULL implies the functions will handle it - { - UCVarValue v; - v.Int = newValue; - object->cVar->ForceSet(v, CVAR_Int, false); - } - Menu_EntryOptionDidModify(entry); - - return 0; - } - - return -1; -} - -static int32_t Menu_RunInput_EntryOption_Movement(MenuEntry_t *entry, MenuOption_t *object, MenuMovement_t direction) -{ - int32_t newValueIndex = object->currentOption; - - switch (direction) - { - case MM_Left: - --newValueIndex; - if (newValueIndex >= 0) - break; - fallthrough__; - case MM_AllTheWayRight: - newValueIndex = object->options->numOptions-1; - break; - - case MM_Right: - ++newValueIndex; - if (newValueIndex < object->options->numOptions) - break; - fallthrough__; - case MM_AllTheWayLeft: - newValueIndex = 0; - break; - - default: - break; - } - - return Menu_RunInput_EntryOption_Modify(entry, object, newValueIndex); -} - -static int32_t Menu_RunInput_EntryOption_Activate(MenuEntry_t *entry, MenuOption_t *object) -{ - if (object->options->features & 2) - return Menu_RunInput_EntryOption_Movement(entry, object, MM_Right); - else - { - object->options->currentEntry = object->currentOption >= 0 ? object->currentOption : 0; - Menu_RunInput_EntryOptionList_MovementVerify(object); - - return 0; - } -} - -static int32_t Menu_RunInput_EntryOptionList_Activate(MenuEntry_t *entry, MenuOption_t *object) -{ - if (!Menu_RunInput_EntryOption_Modify(entry, object, object->options->currentEntry)) - { - object->options->currentEntry = -1; - - return 0; - } - - return -1; -} - -static void Menu_RunInput_EntryCustom2Col_Activate(MenuEntry_t *entry) -{ - auto object = (MenuCustom2Col_t*)entry->entry; - - Menu_Custom2ColScreen(/*entry*/); - - object->screenOpen = 1; -} - -static void Menu_RunInput_EntryRangeInt32_MovementVerify(MenuEntry_t *entry, MenuRangeInt32_t *object, int32_t newValue) -{ - if (!Menu_EntryRangeInt32Modify(entry, newValue)) - *object->cVar = newValue; -} - -static void Menu_RunInput_EntryRangeInt32_MovementArbitrary(MenuEntry_t *entry, MenuRangeInt32_t *object, int32_t newValue) -{ - if (object->flags & EnforceIntervals) - { - int32_t const range = object->max - object->min; - int32_t const maxInterval = object->steps - 1; - int32_t const newValueIndex = roundscale(newValue - object->min, maxInterval, range); - newValue = newValueIndex * range / maxInterval + object->min; - } - - Menu_RunInput_EntryRangeInt32_MovementVerify(entry, object, newValue); -} - -static void Menu_RunInput_EntryRangeInt32_Movement(MenuEntry_t *entry, MenuRangeInt32_t *object, MenuMovement_t direction) -{ - int32_t const oldValue = *object->cVar; - int32_t const range = object->max - object->min; - int32_t const maxInterval = object->steps - 1; - int32_t const oldValueIndex = roundscale(oldValue - object->min, maxInterval, range); - int32_t const oldValueQuantized = oldValueIndex * range / maxInterval + object->min; - int32_t newValueIndex = oldValueIndex; - - switch (direction) - { - case MM_Left: - if (oldValueQuantized >= oldValue) - --newValueIndex; - if (newValueIndex >= 0) - break; - fallthrough__; - case MM_AllTheWayLeft: - newValueIndex = 0; - break; - - case MM_Right: - if (oldValueQuantized <= oldValue) - ++newValueIndex; - if (newValueIndex <= maxInterval) - break; - fallthrough__; - case MM_AllTheWayRight: - newValueIndex = maxInterval; - break; - - default: - break; - } - - int32_t const newValue = newValueIndex * range / maxInterval + object->min; - Menu_RunInput_EntryRangeInt32_MovementVerify(entry, object, newValue); -} - -static void Menu_RunInput_EntryRangeFloat_MovementVerify(MenuEntry_t *entry, MenuRangeFloat_t *object, float newValue) -{ - if (!Menu_EntryRangeFloatModify(entry, newValue)) - { - *object->cVar = newValue; - Menu_EntryRangeFloatDidModify(entry); - } -} - -static void Menu_RunInput_EntryRangeFloat_MovementArbitrary(MenuEntry_t *entry, MenuRangeFloat_t *object, float newValue) -{ - if (object->flags & EnforceIntervals) - { - float const range = object->max - object->min; - float const maxInterval = (float)(object->steps - 1); - float const newValueIndex = rintf((newValue - object->min) * maxInterval / range); - newValue = newValueIndex * range / maxInterval + object->min; - } - - Menu_RunInput_EntryRangeFloat_MovementVerify(entry, object, newValue); -} - -static void Menu_RunInput_EntryRangeFloat_Movement(MenuEntry_t *entry, MenuRangeFloat_t *object, MenuMovement_t direction) -{ - float const oldValue = *object->cVar; - float const range = object->max - object->min; - float const maxInterval = (float)(object->steps - 1); - float const oldValueIndexUnrounded = (oldValue - object->min) * maxInterval / range; - float const oldValueIndex = rintf(oldValueIndexUnrounded); - float const oldValueQuantized = oldValueIndex * range / maxInterval + object->min; - float newValueIndex = oldValueIndex; - - switch (direction) - { - case MM_Left: - if (oldValueQuantized >= oldValue) - newValueIndex -= 1.f; - if (newValueIndex >= 0.f) - break; - fallthrough__; - case MM_AllTheWayLeft: - newValueIndex = 0.f; - break; - - case MM_Right: - if (oldValueQuantized <= oldValue) - newValueIndex += 1.f; - if (newValueIndex <= maxInterval) - break; - fallthrough__; - case MM_AllTheWayRight: - newValueIndex = maxInterval; - break; - - default: - break; - } - - float const newValue = newValueIndex * range / maxInterval + object->min; - Menu_RunInput_EntryRangeFloat_MovementVerify(entry, object, newValue); -} - -static void Menu_RunInput_EntryString_Activate(MenuEntry_t *entry) -{ - auto object = (MenuString_t*)entry->entry; - - if (object->variable) - strncpy(typebuf, object->variable, TYPEBUFSIZE); - else - typebuf[0] = '\0'; - object->editfield = typebuf; - - // this limitation is an arbitrary implementation detail - if (object->bufsize > TYPEBUFSIZE) - object->bufsize = TYPEBUFSIZE; - - Menu_EntryStringActivate(/*entry*/); - Menu_StartTextInput(); -} - -static void Menu_RunInput_EntryString_Submit(/*MenuEntry_t *entry, */MenuString_t *object) -{ - if (!Menu_EntryStringSubmit(/*entry, */object->editfield)) - { - if (object->variable) - strncpy(object->variable, object->editfield, object->bufsize); - } - - object->editfield = NULL; - Menu_StopTextInput(); -} - -static void Menu_RunInput_EntryString_Cancel(/*MenuEntry_t *entry, */MenuString_t *object) -{ - Menu_EntryStringCancel(/*entry*/); - - object->editfield = NULL; - Menu_StopTextInput(); -} - -static void Menu_RunInput_FileSelect_MovementVerify(MenuFileSelect_t *object) -{ - -} - -static void Menu_RunInput_FileSelect_Movement(MenuFileSelect_t *object, MenuMovement_t direction) -{ -} - -static void Menu_RunInput_FileSelect_Select(MenuFileSelect_t *object) -{ - -} - -static void Menu_RunInput(Menu_t *cm) -{ - switch (cm->type) - { - case Panel: - { - auto panel = (MenuPanel_t*)cm->object; - - if (I_ReturnTrigger() || Menu_RunInput_MouseReturn()) - { - I_ReturnTriggerClear(); - m_mousecaught = 1; - - S_PlaySound(EXITMENUSOUND); - - Menu_AnimateChange(cm->parentID, cm->parentAnimation); - } - else if (I_PanelUp()) - { - I_PanelUpClear(); - - S_PlaySound(KICK_HIT); - Menu_AnimateChange(panel->previousID, panel->previousAnimation); - } - else if (I_PanelDown() || Menu_RunInput_MouseAdvance()) - { - I_PanelDownClear(); - m_mousecaught = 1; - - S_PlaySound(KICK_HIT); - Menu_AnimateChange(panel->nextID, panel->nextAnimation); - } - break; - } - - case TextForm: - { - auto object = (MenuTextForm_t*)cm->object; - int32_t hitstate = I_EnterText(object->input, object->bufsize-1, 0); - - if (hitstate == -1 || Menu_RunInput_MouseReturn()) - { - m_mousecaught = 1; - - S_PlaySound(EXITMENUSOUND); - - object->input = NULL; - - Menu_AnimateChange(cm->parentID, cm->parentAnimation); - Menu_StopTextInput(); - } - else if (hitstate == 1 || Menu_RunInput_MouseAdvance()) - { - m_mousecaught = 1; - - Menu_TextFormSubmit(object->input); - - object->input = NULL; - Menu_StopTextInput(); - } - break; - } - - case FileSelect: - { - Menu_PreInput(NULL); - break; - } - - case Message: - if (I_ReturnTrigger() || Menu_RunInput_MouseReturn()) - { - I_ReturnTriggerClear(); - m_mousecaught = 1; - - S_PlaySound(EXITMENUSOUND); - - Menu_AnimateChange(cm->parentID, cm->parentAnimation); - } - - if (I_CheckAllInput()) - { - auto message = (MenuMessage_t*)cm->object; - - I_ClearAllInput(); - - S_PlaySound(EXITMENUSOUND); - - Menu_AnimateChange(message->linkID, message->animation); - } - - Menu_PreInput(NULL); - break; - - case Verify: - if (I_ReturnTrigger() || inputState.GetKeyStatus(sc_N) || Menu_RunInput_MouseReturn()) - { - I_ReturnTriggerClear(); - inputState.ClearKeyStatus(sc_N); - m_mousecaught = 1; - - Menu_Verify(0); - - Menu_AnimateChange(cm->parentID, cm->parentAnimation); - - S_PlaySound(EXITMENUSOUND); - } - - if (I_AdvanceTrigger() || inputState.GetKeyStatus(sc_Y) || Menu_RunInput_MouseAdvance()) - { - auto verify = (MenuVerify_t*)cm->object; - - I_AdvanceTriggerClear(); - inputState.ClearKeyStatus(sc_Y); - m_mousecaught = 1; - - Menu_Verify(1); - - Menu_AnimateChange(verify->linkID, verify->animation); - - S_PlaySound(PISTOL_BODYHIT); - } - - Menu_PreInput(NULL); - break; - - else if (inputState.GetKeyStatus(sc_Home)) - { - inputState.ClearKeyStatus(sc_Home); - - S_PlaySound(KICK_HIT); - - currentry = Menu_RunInput_Menu_Movement(menu, MM_Home); - } - else if (inputState.GetKeyStatus(sc_End)) - { - inputState.ClearKeyStatus(sc_End); - - S_PlaySound(KICK_HIT); - - currentry = Menu_RunInput_Menu_Movement(menu, MM_End); - } - else if (I_MenuUp()) - { - I_MenuUpClear(); - - S_PlaySound(KICK_HIT); - - currentry = Menu_RunInput_Menu_Movement(menu, MM_Up); - } - else if (I_MenuDown()) - { - I_MenuDownClear(); - - S_PlaySound(KICK_HIT); - - currentry = Menu_RunInput_Menu_Movement(menu, MM_Down); - } - - if (currentry != NULL) - Menu_PreInput(currentry); - } - else if (state == 1) - { - if (currentry->type == String) - { - auto object = (MenuString_t*)currentry->entry; - - int32_t hitstate = I_EnterText(object->editfield, object->bufsize-1, object->flags); - - if (hitstate == -1 || Menu_RunInput_MouseReturn()) - { - m_mousecaught = 1; - - Menu_RunInput_EntryString_Cancel(/*currentry, */object); - - S_PlaySound(EXITMENUSOUND); - } - else if (hitstate == 1) - { - Menu_RunInput_EntryString_Submit(/*currentry, */object); - - S_PlaySound(PISTOL_BODYHIT); - } - } - } - else if (state == 2) - { - if (currentry->type == Option) - { - auto object = (MenuOption_t*)currentry->entry; - - if (I_ReturnTrigger() || Menu_RunInput_MouseReturn()) - { - I_ReturnTriggerClear(); - m_mousecaught = 1; - - S_PlaySound(EXITMENUSOUND); - - object->options->currentEntry = -1; - } - else if (I_AdvanceTrigger()) - { - I_AdvanceTriggerClear(); - - if (!Menu_RunInput_EntryOptionList_Activate(currentry, object)) - S_PlaySound(PISTOL_BODYHIT); - } - else if (inputState.GetKeyStatus(sc_Home)) - { - inputState.ClearKeyStatus(sc_Home); - - S_PlaySound(KICK_HIT); - - Menu_RunInput_EntryOptionList_Movement(object, MM_Home); - } - else if (inputState.GetKeyStatus(sc_End)) - { - inputState.ClearKeyStatus(sc_End); - - S_PlaySound(KICK_HIT); - - Menu_RunInput_EntryOptionList_Movement(object, MM_End); - } - else if (I_MenuUp()) - { - I_MenuUpClear(); - - S_PlaySound(KICK_HIT); - - Menu_RunInput_EntryOptionList_Movement(object, MM_Up); - } - else if (I_MenuDown()) - { - I_MenuDownClear(); - - S_PlaySound(KICK_HIT); - - Menu_RunInput_EntryOptionList_Movement(object, MM_Down); - } - } - else if (currentry->type == Custom2Col) - { - if (I_EscapeTrigger() || Menu_RunInput_MouseReturn()) - { - I_EscapeTriggerClear(); - m_mousecaught = 1; - - S_PlaySound(EXITMENUSOUND); - - ((MenuCustom2Col_t*)currentry->entry)->screenOpen = 0; - } - else if (Menu_PreCustom2ColScreen(currentry)) - ((MenuCustom2Col_t*)currentry->entry)->screenOpen = 0; - } - } - - break; - } - } -} - -void M_DisplayMenus(void) -{ - vec2_t origin = { 0, 0 }, previousOrigin = { 0, 0 }; - - Net_GetPackets(); - - if ((g_player[myconnectindex].ps->gm&MODE_MENU) == 0) - { - return; - } - - if (!Menu_IsTextInput(m_currentMenu) && inputState.GetKeyStatus(sc_Q)) - Menu_AnimateChange(MENU_QUIT, MA_Advance); - - int32_t mousestatus = inputState.mouseReadAbs(&m_mousepos); - if (mousestatus && inputState.mouseClickState() == MOUSE_PRESSED) - m_mousedownpos = m_mousepos; - - Menu_RunInput(m_currentMenu); - - g_player[myconnectindex].ps->gm &= (0xff-MODE_TYPE); - // g_player[myconnectindex].ps->fta = 0; - - int32_t const backgroundOK = ud.menubackground && Menu_BlackTranslucentBackgroundOK(g_currentMenu); - - // need EVENT_DISPLAYMENUBACKGROUND here - - if (!FURY && ((g_player[myconnectindex].ps->gm&MODE_GAME) || ud.recstat==2) && backgroundOK) - videoFadeToBlack(1); - - if (Menu_UpdateScreenOK(g_currentMenu)) - G_UpdateScreenArea(); - -#if !defined EDUKE32_TOUCH_DEVICES - if (m_menuchange_watchpoint > 0) - m_menuchange_watchpoint++; -#endif - - if (m_parentMenu) - { - ud.returnvar[0] = origin.x; - ud.returnvar[1] = origin.y; - if (m_parentMenu->type == Menu) - { - ud.returnvar[2] = ((MenuMenu_t *)m_parentMenu->object)->currentEntry; - if (m_parentMenu->menuID == MENU_NEWGAMECUSTOMSUB) - ud.returnvar[3] = M_NEWGAMECUSTOM.currentEntry; - } - VM_OnEventWithReturn(EVENT_DISPLAYINACTIVEMENU, g_player[screenpeek].ps->i, screenpeek, m_parentMenu->menuID); - origin.x = ud.returnvar[0]; - origin.y = ud.returnvar[1]; - } - - - - if (m_parentMenu && backgroundOK) - { - Menu_Run(m_parentMenu, origin); - } - - // hack; need EVENT_DISPLAYMENUBACKGROUND above - if (FURY && ((g_player[myconnectindex].ps->gm&MODE_GAME) || ud.recstat==2 || m_parentMenu != NULL) && backgroundOK) - videoFadeToBlack(1); - - // Display the menu, with a transition animation if applicable. - if (totalclock < m_animation.start + m_animation.length) - { - Menu_Run(m_animation.previous, previousOrigin); - Menu_Run(m_animation.current, origin); - } - else - Menu_Run(m_currentMenu, origin); - -#if !defined EDUKE32_TOUCH_DEVICES - if (m_menuchange_watchpoint >= 3) - m_menuchange_watchpoint = 0; -#endif - - if (m_parentMenu) - { - ud.returnvar[0] = origin.x; - ud.returnvar[1] = origin.y; - if (m_parentMenu->type == Menu) - { - ud.returnvar[2] = ((MenuMenu_t *)m_parentMenu->object)->currentEntry; - if (m_parentMenu->menuID == MENU_NEWGAMECUSTOMSUB) - ud.returnvar[3] = M_NEWGAMECUSTOM.currentEntry; - } - VM_OnEventWithReturn(EVENT_DISPLAYINACTIVEMENUREST, g_player[screenpeek].ps->i, screenpeek, m_parentMenu->menuID); - } - - - -#if !defined EDUKE32_TOUCH_DEVICES - if (tilesiz[CROSSHAIR].x > 0 && mousestatus) -#else - if (mousestatus) -#endif - { -#if !defined EDUKE32_TOUCH_DEVICES - if (!MOUSEACTIVECONDITION) - m_mousewake_watchpoint = 1; -#endif - - if (MOUSEACTIVECONDITIONAL(inputState.mouseAdvanceClickState()) || m_mousepos.x != m_prevmousepos.x || m_mousepos.y != m_prevmousepos.y) - { - m_prevmousepos = m_mousepos; - m_mouselastactivity = (int32_t) totalclock; - } -#if !defined EDUKE32_TOUCH_DEVICES - else - m_mousewake_watchpoint = 0; -#endif - - m_mousecaught = 0; - } - else - { - m_mouselastactivity = -M_MOUSETIMEOUT; - -#if !defined EDUKE32_TOUCH_DEVICES - m_mousewake_watchpoint = 0; -#endif - } - -#ifndef EDUKE32_TOUCH_DEVICES - // Display the mouse cursor, except on touch devices. - if (MOUSEACTIVECONDITION) - { - if (VM_HaveEvent(EVENT_DISPLAYCURSOR)) - { - ud.returnvar[0] = m_mousepos.x; - ud.returnvar[1] = m_mousepos.y; - ud.returnvar[2] = CURSORALPHA; - } - int32_t a = VM_OnEventWithReturn(EVENT_DISPLAYCURSOR, g_player[screenpeek].ps->i, screenpeek, CROSSHAIR); - - if ((unsigned) a < MAXTILES) - { - vec2_t cursorpos = m_mousepos; - int32_t z = 65536; - uint8_t p = CROSSHAIR_PAL; - uint32_t o = 2|8; - - auto const oyxaspect = yxaspect; - int32_t alpha; - if (FURY) - { - renderSetAspect(viewingrange, 65536); - cursorpos.x = scale(cursorpos.x - (320<<15), ydim << 2, xdim * 3) + (320<<15); - cursorpos.y = scale(cursorpos.y - (200<<15), (ydim << 2) * 6, (xdim * 3) * 5) + (200<<15); - z = scale(32768, ydim << 2, xdim * 3); - p = 0; - o |= 1024; - alpha = MOUSEALPHA; - } - else - { - alpha = CURSORALPHA; - } - - rotatesprite_fs_alpha(cursorpos.x, cursorpos.y, z, 0, a, 0, p, o, alpha); - - if (FURY) - renderSetAspect(viewingrange, oyxaspect); - } - } - else - inputState.clearMouseClickState(); -#endif - - if ((g_player[myconnectindex].ps->gm&MODE_MENU) != MODE_MENU) - { - G_UpdateScreenArea(); - CAMERACLOCK = (int32_t) totalclock; - CAMERADIST = 65536; - } -} - -bool GameInterface::mouseInactiveConditional(bool condition) -{ - return MOUSEINACTIVECONDITIONAL(condition); -} #endif