menu: menu framework function pointers

Add function pointers draw and key event to menu framework.
Setup function pointers for menu frames.
Pass menu framework as parameter to M_PushMenu().
This commit is contained in:
apartfromtime 2024-07-20 10:15:27 +10:00
parent 4b9b8e14a4
commit 2bafa22cfc
3 changed files with 133 additions and 49 deletions

View file

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

View file

@ -59,7 +59,7 @@ static void M_Menu_JoinServer_f(void);
static void M_Menu_AddressBook_f(void); static void M_Menu_AddressBook_f(void);
static void M_Menu_StartServer_f(void); static void M_Menu_StartServer_f(void);
static void M_Menu_DMOptions_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_Options_f(void);
static void M_Menu_Keys_f(void); static void M_Menu_Keys_f(void);
static void M_Menu_Joy_f(void); static void M_Menu_Joy_f(void);
@ -166,12 +166,17 @@ M_PopMenu(void)
* to the stack and make the requested menu the menu in * to the stack and make the requested menu the menu in
* flight. * flight.
*/ */
static void void
M_PushMenu(void (*draw)(void), const char *(*key)(int)) M_PushMenu(menuframework_s* menu)
{ {
int i; int i;
int alreadyPresent = 0; int alreadyPresent = 0;
if (menu == NULL)
{
return;
}
if ((Cvar_VariableValue("maxclients") == 1) && if ((Cvar_VariableValue("maxclients") == 1) &&
Com_ServerState()) Com_ServerState())
{ {
@ -194,7 +199,7 @@ M_PushMenu(void (*draw)(void), const char *(*key)(int))
/* if this menu is already open (and on top), /* if this menu is already open (and on top),
close it => toggling behaviour */ close it => toggling behaviour */
if ((m_drawfunc == draw) && (m_keyfunc == key)) if ((m_drawfunc == menu->draw) && (m_keyfunc == menu->key))
{ {
M_PopMenu(); M_PopMenu();
return; return;
@ -204,8 +209,8 @@ M_PushMenu(void (*draw)(void), const char *(*key)(int))
that level to avoid stacking menus by hotkeys */ that level to avoid stacking menus by hotkeys */
for (i = 0; i < m_menudepth; i++) for (i = 0; i < m_menudepth; i++)
{ {
if ((m_layers[i].draw == draw) && if ((m_layers[i].draw == menu->draw) &&
(m_layers[i].key == key)) (m_layers[i].key == menu->key))
{ {
alreadyPresent = 1; alreadyPresent = 1;
break; break;
@ -228,8 +233,8 @@ M_PushMenu(void (*draw)(void), const char *(*key)(int))
m_layers[m_menudepth].key = m_keyfunc; m_layers[m_menudepth].key = m_keyfunc;
m_menudepth++; m_menudepth++;
m_drawfunc = draw; m_drawfunc = menu->draw;
m_keyfunc = key; m_keyfunc = menu->key;
m_entersound = true; m_entersound = true;
@ -771,7 +776,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);
} }
/* /*
@ -873,7 +881,10 @@ static void
M_Menu_Multiplayer_f(void) M_Menu_Multiplayer_f(void)
{ {
Multiplayer_MenuInit(); 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);
} }
/* /*
@ -1140,7 +1151,10 @@ static void
M_Menu_Keys_f(void) M_Menu_Keys_f(void)
{ {
Keys_MenuInit(); 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);
} }
/* /*
@ -1290,7 +1304,10 @@ static void
M_Menu_Multiplayer_Keys_f(void) M_Menu_Multiplayer_Keys_f(void)
{ {
MultiplayerKeys_MenuInit(); 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);
} }
/* /*
@ -1453,7 +1470,10 @@ static void
M_Menu_ControllerButtons_f(void) M_Menu_ControllerButtons_f(void)
{ {
ControllerButtons_MenuInit(); 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);
} }
/* /*
@ -1617,7 +1637,10 @@ static void
M_Menu_ControllerAltButtons_f(void) M_Menu_ControllerAltButtons_f(void)
{ {
ControllerAltButtons_MenuInit(); 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);
} }
/* /*
@ -1765,7 +1788,10 @@ static void
M_Menu_Stick_f(void) M_Menu_Stick_f(void)
{ {
Stick_MenuInit(); 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);
} }
/* /*
@ -1980,7 +2006,10 @@ static void
M_Menu_Gyro_f(void) M_Menu_Gyro_f(void)
{ {
Gyro_MenuInit(); 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);
} }
/* /*
@ -2151,7 +2180,10 @@ static void
M_Menu_Joy_f(void) M_Menu_Joy_f(void)
{ {
Joy_MenuInit(); 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);
} }
/* /*
@ -2553,24 +2585,18 @@ static void
M_Menu_Options_f(void) M_Menu_Options_f(void)
{ {
Options_MenuInit(); Options_MenuInit();
M_PushMenu(Options_MenuDraw, Options_MenuKey); s_options_menu.draw = Options_MenuDraw;
} s_options_menu.key = Options_MenuKey;
/* M_PushMenu(&s_options_menu);
* VIDEO MENU
*/
static void
M_Menu_Video_f(void)
{
VID_MenuInit();
M_PushMenu(VID_MenuDraw, VID_MenuKey);
} }
/* /*
* END GAME MENU * END GAME MENU
*/ */
menuframework_s s_credits;
#define CREDITS_SIZE 256 #define CREDITS_SIZE 256
static int credits_start_time; static int credits_start_time;
static const char **credits; static const char **credits;
@ -2933,7 +2959,7 @@ static const char *roguecredits[] =
}; };
static void static void
M_Credits_MenuDraw(void) M_Credits_Draw(void)
{ {
int i, y; int i, y;
float scale = SCR_GetMenuScale(); float scale = SCR_GetMenuScale();
@ -3076,7 +3102,11 @@ M_Menu_Credits_f(void)
} }
credits_start_time = cls.realtime; 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 +3271,10 @@ static void
M_Menu_Mods_f(void) M_Menu_Mods_f(void)
{ {
Mods_MenuInit(); 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 +3466,10 @@ static void
M_Menu_Game_f(void) M_Menu_Game_f(void)
{ {
Game_MenuInit(); 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; m_game_cursor = 1;
} }
@ -3756,7 +3792,10 @@ M_Menu_LoadGame_f(void)
{ {
LoadSave_AdjustPage(0); LoadSave_AdjustPage(0);
LoadGame_MenuInit(); 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);
} }
/* /*
@ -3911,7 +3950,10 @@ M_Menu_SaveGame_f(void)
LoadSave_AdjustPage(0); LoadSave_AdjustPage(0);
SaveGame_MenuInit(); 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);
} }
/* /*
@ -4112,7 +4154,10 @@ static void
M_Menu_JoinServer_f(void) M_Menu_JoinServer_f(void)
{ {
JoinServer_MenuInit(); 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);
} }
/* /*
@ -4511,7 +4556,10 @@ static void
M_Menu_StartServer_f(void) M_Menu_StartServer_f(void)
{ {
StartServer_MenuInit(); 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);
} }
/* /*
@ -4992,7 +5040,10 @@ static void
M_Menu_DMOptions_f(void) M_Menu_DMOptions_f(void)
{ {
DMOptions_MenuInit(); 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);
} }
/* /*
@ -5157,7 +5208,10 @@ static void
M_Menu_DownloadOptions_f(void) M_Menu_DownloadOptions_f(void)
{ {
DownloadOptions_MenuInit(); 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);
} }
/* /*
@ -5233,7 +5287,10 @@ static void
M_Menu_AddressBook_f(void) M_Menu_AddressBook_f(void)
{ {
AddressBook_MenuInit(); 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);
} }
/* /*
@ -6069,13 +6126,18 @@ M_Menu_PlayerConfig_f(void)
} }
Menu_SetStatusBar(&s_multiplayer_menu, NULL); 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 * QUIT MENU
*/ */
menuframework_s s_quit_menu;
static const char * static const char *
M_Quit_Key(int key) M_Quit_Key(int key)
{ {
@ -6115,7 +6177,10 @@ M_Quit_Draw(void)
static void static void
M_Menu_Quit_f(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 void

View file

@ -882,3 +882,18 @@ VID_MenuKey(int key)
return sound; 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);
}