Merge commit 'df81a8b7'

This commit is contained in:
Denis Pauk 2024-07-21 00:23:27 +03:00
commit 7258f240ce
3 changed files with 137 additions and 53 deletions

View file

@ -63,6 +63,8 @@ typedef struct _tag_menuframework
const char *statusbar;
void (*draw)(void);
const char *(*key)(int k);
void (*cursordraw)(struct _tag_menuframework *m);
} menuframework_s;
@ -135,6 +137,8 @@ typedef struct
menucommon_s generic;
} menuseparator_s;
void M_PushMenu(menuframework_s* menu);
qboolean Field_Key(menufield_s *field, int key);
void Menu_AddItem(menuframework_s *menu, void *item);

View file

@ -60,7 +60,7 @@ static void M_Menu_JoinServer_f(void);
static void M_Menu_AddressBook_f(void);
static void M_Menu_StartServer_f(void);
static void M_Menu_DMOptions_f(void);
static void M_Menu_Video_f(void);
void M_Menu_Video_f(void);
static void M_Menu_Options_f(void);
static void M_Menu_Keys_f(void);
static void M_Menu_Joy_f(void);
@ -72,9 +72,6 @@ void M_Menu_Credits(void);
qboolean m_entersound; /* play after drawing a frame, so caching won't disrupt the sound */
void (*m_drawfunc)(void);
const char *(*m_keyfunc)(int key);
/* Maximal number of submenus */
#define MAX_MENU_DEPTH 8
@ -85,6 +82,7 @@ typedef struct
} menulayer_t;
static menulayer_t m_layers[MAX_MENU_DEPTH];
static menulayer_t m_active; /* active menu layer */
static int m_menudepth;
static qboolean
@ -130,9 +128,9 @@ M_Banner(const char *name)
void
M_ForceMenuOff(void)
{
m_drawfunc = NULL;
m_keyfunc = NULL;
cls.key_dest = key_game;
m_active.draw = NULL;
m_active.key = NULL;
m_menudepth = 0;
Key_MarkAllUp();
Cvar_Set("paused", "0");
@ -150,8 +148,8 @@ M_PopMenu(void)
m_menudepth--;
m_drawfunc = m_layers[m_menudepth].draw;
m_keyfunc = m_layers[m_menudepth].key;
m_active.draw = m_layers[m_menudepth].draw;
m_active.key = m_layers[m_menudepth].key;
if (!m_menudepth)
{
@ -183,12 +181,17 @@ M_PopMenu(void)
* to the stack and make the requested menu the menu in
* flight.
*/
static void
M_PushMenu(void (*draw)(void), const char *(*key)(int))
void
M_PushMenu(menuframework_s* menu)
{
int i;
int alreadyPresent = 0;
if (menu == NULL)
{
return;
}
if ((Cvar_VariableValue("maxclients") == 1) &&
Com_ServerState())
{
@ -211,7 +214,8 @@ M_PushMenu(void (*draw)(void), const char *(*key)(int))
/* if this menu is already open (and on top),
close it => toggling behaviour */
if ((m_drawfunc == draw) && (m_keyfunc == key))
if ((m_active.draw == menu->draw) &&
(m_active.key == menu->key))
{
M_PopMenu();
return;
@ -221,8 +225,8 @@ M_PushMenu(void (*draw)(void), const char *(*key)(int))
that level to avoid stacking menus by hotkeys */
for (i = 0; i < m_menudepth; i++)
{
if ((m_layers[i].draw == draw) &&
(m_layers[i].key == key))
if ((m_layers[i].draw == menu->draw) &&
(m_layers[i].key == menu->key))
{
alreadyPresent = 1;
break;
@ -241,12 +245,12 @@ M_PushMenu(void (*draw)(void), const char *(*key)(int))
return;
}
m_layers[m_menudepth].draw = m_drawfunc;
m_layers[m_menudepth].key = m_keyfunc;
m_layers[m_menudepth].draw = m_active.draw;
m_layers[m_menudepth].key = m_active.key;
m_menudepth++;
m_drawfunc = draw;
m_keyfunc = key;
m_active.draw = menu->draw;
m_active.key = menu->key;
m_entersound = true;
@ -778,7 +782,10 @@ M_Menu_Main_f(void)
}
}
M_PushMenu(M_Main_Draw, M_Main_Key);
s_main.draw = M_Main_Draw;
s_main.key = M_Main_Key;
M_PushMenu(&s_main);
}
/*
@ -880,7 +887,10 @@ static void
M_Menu_Multiplayer_f(void)
{
Multiplayer_MenuInit();
M_PushMenu(Multiplayer_MenuDraw, Multiplayer_MenuKey);
s_multiplayer_menu.draw = Multiplayer_MenuDraw;
s_multiplayer_menu.key = Multiplayer_MenuKey;
M_PushMenu(&s_multiplayer_menu);
}
/*
@ -1147,7 +1157,10 @@ static void
M_Menu_Keys_f(void)
{
Keys_MenuInit();
M_PushMenu(Keys_MenuDraw, Keys_MenuKey);
s_keys_menu.draw = Keys_MenuDraw;
s_keys_menu.key = Keys_MenuKey;
M_PushMenu(&s_keys_menu);
}
/*
@ -1297,7 +1310,10 @@ static void
M_Menu_Multiplayer_Keys_f(void)
{
MultiplayerKeys_MenuInit();
M_PushMenu(MultiplayerKeys_MenuDraw, MultiplayerKeys_MenuKey);
s_multiplayer_keys_menu.draw = MultiplayerKeys_MenuDraw;
s_multiplayer_keys_menu.key = MultiplayerKeys_MenuKey;
M_PushMenu(&s_multiplayer_keys_menu);
}
/*
@ -1460,7 +1476,10 @@ static void
M_Menu_ControllerButtons_f(void)
{
ControllerButtons_MenuInit();
M_PushMenu(ControllerButtons_MenuDraw, ControllerButtons_MenuKey);
s_controller_buttons_menu.draw = ControllerButtons_MenuDraw;
s_controller_buttons_menu.key = ControllerButtons_MenuKey;
M_PushMenu(&s_controller_buttons_menu);
}
/*
@ -1624,7 +1643,10 @@ static void
M_Menu_ControllerAltButtons_f(void)
{
ControllerAltButtons_MenuInit();
M_PushMenu(ControllerAltButtons_MenuDraw, ControllerAltButtons_MenuKey);
s_controller_alt_buttons_menu.draw = ControllerAltButtons_MenuDraw;
s_controller_alt_buttons_menu.key = ControllerAltButtons_MenuKey;
M_PushMenu(&s_controller_alt_buttons_menu);
}
/*
@ -1772,7 +1794,10 @@ static void
M_Menu_Stick_f(void)
{
Stick_MenuInit();
M_PushMenu(Stick_MenuDraw, Stick_MenuKey);
s_sticks_config_menu.draw = Stick_MenuDraw;
s_sticks_config_menu.key = Stick_MenuKey;
M_PushMenu(&s_sticks_config_menu);
}
/*
@ -1987,7 +2012,10 @@ static void
M_Menu_Gyro_f(void)
{
Gyro_MenuInit();
M_PushMenu(Gyro_MenuDraw, Gyro_MenuKey);
s_gyro_menu.draw = Gyro_MenuDraw;
s_gyro_menu.key = Gyro_MenuKey;
M_PushMenu(&s_gyro_menu);
}
/*
@ -2158,7 +2186,10 @@ static void
M_Menu_Joy_f(void)
{
Joy_MenuInit();
M_PushMenu(Joy_MenuDraw, Joy_MenuKey);
s_joy_menu.draw = Joy_MenuDraw;
s_joy_menu.key = Joy_MenuKey;
M_PushMenu(&s_joy_menu);
}
/*
@ -2557,24 +2588,18 @@ static void
M_Menu_Options_f(void)
{
Options_MenuInit();
M_PushMenu(Options_MenuDraw, Options_MenuKey);
}
s_options_menu.draw = Options_MenuDraw;
s_options_menu.key = Options_MenuKey;
/*
* VIDEO MENU
*/
static void
M_Menu_Video_f(void)
{
VID_MenuInit();
M_PushMenu(VID_MenuDraw, VID_MenuKey);
M_PushMenu(&s_options_menu);
}
/*
* END GAME MENU
*/
menuframework_s s_credits;
#define CREDITS_SIZE 256
static int credits_start_time;
static const char **credits;
@ -2939,7 +2964,7 @@ static const char *idcredits[] = {
};
static void
M_Credits_MenuDraw(void)
M_Credits_Draw(void)
{
int i, y;
float scale = SCR_GetMenuScale();
@ -3069,7 +3094,11 @@ M_Menu_Credits_f(void)
}
credits_start_time = cls.realtime;
M_PushMenu(M_Credits_MenuDraw, M_Credits_Key);
s_credits.draw = M_Credits_Draw;
s_credits.key = M_Credits_Key;
M_PushMenu(&s_credits);
}
/*
@ -3241,7 +3270,10 @@ static void
M_Menu_Mods_f(void)
{
Mods_MenuInit();
M_PushMenu(Mods_MenuDraw, Mods_MenuKey);
s_mods_menu.draw = Mods_MenuDraw;
s_mods_menu.key = Mods_MenuKey;
M_PushMenu(&s_mods_menu);
}
/*
@ -3433,7 +3465,10 @@ static void
M_Menu_Game_f(void)
{
Game_MenuInit();
M_PushMenu(Game_MenuDraw, Game_MenuKey);
s_game_menu.draw = Game_MenuDraw;
s_game_menu.key = Game_MenuKey;
M_PushMenu(&s_game_menu);
m_game_cursor = 1;
}
@ -3758,7 +3793,10 @@ M_Menu_LoadGame_f(void)
{
LoadSave_AdjustPage(0);
LoadGame_MenuInit();
M_PushMenu(LoadGame_MenuDraw, LoadGame_MenuKey);
s_loadgame_menu.draw = LoadGame_MenuDraw;
s_loadgame_menu.key = LoadGame_MenuKey;
M_PushMenu(&s_loadgame_menu);
}
/*
@ -3913,7 +3951,10 @@ M_Menu_SaveGame_f(void)
LoadSave_AdjustPage(0);
SaveGame_MenuInit();
M_PushMenu(SaveGame_MenuDraw, SaveGame_MenuKey);
s_savegame_menu.draw = SaveGame_MenuDraw;
s_savegame_menu.key = SaveGame_MenuKey;
M_PushMenu(&s_savegame_menu);
}
/*
@ -4114,7 +4155,10 @@ static void
M_Menu_JoinServer_f(void)
{
JoinServer_MenuInit();
M_PushMenu(JoinServer_MenuDraw, JoinServer_MenuKey);
s_joinserver_menu.draw = JoinServer_MenuDraw;
s_joinserver_menu.key = JoinServer_MenuKey;
M_PushMenu(&s_joinserver_menu);
}
/*
@ -4519,7 +4563,10 @@ static void
M_Menu_StartServer_f(void)
{
StartServer_MenuInit();
M_PushMenu(StartServer_MenuDraw, StartServer_MenuKey);
s_startserver_menu.draw = StartServer_MenuDraw;
s_startserver_menu.key = StartServer_MenuKey;
M_PushMenu(&s_startserver_menu);
}
/*
@ -5004,7 +5051,10 @@ static void
M_Menu_DMOptions_f(void)
{
DMOptions_MenuInit();
M_PushMenu(DMOptions_MenuDraw, DMOptions_MenuKey);
s_dmoptions_menu.draw = DMOptions_MenuDraw;
s_dmoptions_menu.key = DMOptions_MenuKey;
M_PushMenu(&s_dmoptions_menu);
}
/*
@ -5169,7 +5219,10 @@ static void
M_Menu_DownloadOptions_f(void)
{
DownloadOptions_MenuInit();
M_PushMenu(DownloadOptions_MenuDraw, DownloadOptions_MenuKey);
s_downloadoptions_menu.draw = DownloadOptions_MenuDraw;
s_downloadoptions_menu.key = DownloadOptions_MenuKey;
M_PushMenu(&s_downloadoptions_menu);
}
/*
@ -5245,7 +5298,10 @@ static void
M_Menu_AddressBook_f(void)
{
AddressBook_MenuInit();
M_PushMenu(AddressBook_MenuDraw, AddressBook_MenuKey);
s_addressbook_menu.draw = AddressBook_MenuDraw;
s_addressbook_menu.key = AddressBook_MenuKey;
M_PushMenu(&s_addressbook_menu);
}
/*
@ -6236,13 +6292,18 @@ M_Menu_PlayerConfig_f(void)
}
Menu_SetStatusBar(&s_multiplayer_menu, NULL);
M_PushMenu(PlayerConfig_MenuDraw, PlayerConfig_MenuKey);
s_player_config_menu.draw = PlayerConfig_MenuDraw;
s_player_config_menu.key = PlayerConfig_MenuKey;
M_PushMenu(&s_player_config_menu);
}
/*
* QUIT MENU
*/
menuframework_s s_quit_menu;
static const char *
M_Quit_Key(int key)
{
@ -6282,7 +6343,10 @@ M_Quit_Draw(void)
static void
M_Menu_Quit_f(void)
{
M_PushMenu(M_Quit_Draw, M_Quit_Key);
s_quit_menu.draw = M_Quit_Draw;
s_quit_menu.key = M_Quit_Key;
M_PushMenu(&s_quit_menu);
}
void
@ -6362,7 +6426,10 @@ M_Draw(void)
Draw_FadeScreen();
}
m_drawfunc();
if (m_active.draw)
{
m_active.draw();
}
/* delay playing the enter sound until after the
menu has been drawn, to avoid delay while
@ -6377,10 +6444,10 @@ M_Draw(void)
void
M_Keydown(int key)
{
if (m_keyfunc)
if (m_active.key)
{
const char *s;
if ((s = m_keyfunc(key)) != 0)
if ((s = m_active.key(key)) != 0)
{
S_StartLocalSound((char *)s);
}

View file

@ -882,3 +882,16 @@ VID_MenuKey(int key)
return sound;
}
/*
* VIDEO MENU
*/
void
M_Menu_Video_f(void)
{
VID_MenuInit();
s_opengl_menu.draw = VID_MenuDraw;
s_opengl_menu.key = VID_MenuKey;
M_PushMenu(&s_opengl_menu);
}