MENU: Navigate with keyboard/gamepad

This commit is contained in:
cypress 2024-10-15 21:38:47 -07:00
parent cdee3852d8
commit 12c092f91a
11 changed files with 468 additions and 5 deletions

View file

@ -51,6 +51,21 @@ void() Menu_Control;
void() Menu_Gamepad;
void() Menu_Credits;
string(string prev_id) Menu_Main_GetNextButton;
string(string next_id) Menu_Main_GetPreviousButton;
string(string prev_id) Menu_Maps_GetNextButton;
string(string next_id) Menu_Maps_GetPreviousButton;
string(string prev_id) Menu_Options_GetNextButton;
string(string next_id) Menu_Options_GetPreviousButton;
string(string prev_id) Menu_Video_GetNextButton;
string(string next_id) Menu_Video_GetPreviousButton;
string(string prev_id) Menu_Audio_GetNextButton;
string(string next_id) Menu_Audio_GetPreviousButton;
string(string prev_id) Menu_Control_GetNextButton;
string(string next_id) Menu_Control_GetPreviousButton;
string(string prev_id) Menu_Gamepad_GetNextButton;
string(string next_id) Menu_Gamepad_GetPreviousButton;
enum {
MAP_SOLOSTOCK,
MAP_SOLOUSER,

View file

@ -587,5 +587,6 @@ void(vector size) root_menu =
if (last_menu != current_menu) {
Menu_PlaySound(MENU_SND_ENTER);
last_menu = current_menu;
sui_reset_hover();
}
};

View file

@ -1,9 +1,51 @@
string menu_audio_buttons[5] = {"am_maste", "am_menu", "am_bgm", "am_apply", "am_back"};
void() Menu_Audio_ApplySettings =
{
localcmd("vid_reload\nsaveconfig user_settings.cfg\n");
music_duration_time = 0;
};
string(string prev_id) Menu_Audio_GetNextButton =
{
if (prev_id == "")
return menu_audio_buttons[0];
string ret = menu_audio_buttons[0];
for(float i = 0; i < menu_audio_buttons.length; i++) {
if (menu_audio_buttons[i] == prev_id) {
if (i + 1 >= menu_audio_buttons.length)
break;
ret = menu_audio_buttons[i + 1];
break;
}
}
return ret;
};
string(string next_id) Menu_Audio_GetPreviousButton =
{
if (next_id == "")
return menu_audio_buttons[menu_audio_buttons.length - 1];
string ret = menu_audio_buttons[menu_audio_buttons.length - 1];
for(float i = menu_audio_buttons.length - 1; i > 0; i--) {
if (menu_audio_buttons[i] == next_id) {
if (i - 1 < 0)
break;
ret = menu_audio_buttons[i - 1];
break;
}
}
return ret;
};
void() Menu_Audio =
{
Menu_DrawBackground();

View file

@ -1,3 +1,5 @@
string menu_ctrl_buttons[6] = {"cm_adsm", "cm_sens", "cm_invs", "cm_gpad", "cm_apply", "cm_back"};
float menu_ctrl_init;
float current_adsmode;
@ -62,6 +64,46 @@ void() Menu_Control_ApplySettings =
music_duration_time = 0;
};
string(string prev_id) Menu_Control_GetNextButton =
{
if (prev_id == "")
return menu_ctrl_buttons[0];
string ret = menu_ctrl_buttons[0];
for(float i = 0; i < menu_ctrl_buttons.length; i++) {
if (menu_ctrl_buttons[i] == prev_id) {
if (i + 1 >= menu_ctrl_buttons.length)
break;
ret = menu_ctrl_buttons[i + 1];
break;
}
}
return ret;
};
string(string next_id) Menu_Control_GetPreviousButton =
{
if (next_id == "")
return menu_ctrl_buttons[menu_ctrl_buttons.length - 1];
string ret = menu_ctrl_buttons[menu_ctrl_buttons.length - 1];
for(float i = menu_ctrl_buttons.length - 1; i > 0; i--) {
if (menu_ctrl_buttons[i] == next_id) {
if (i - 1 < 0)
break;
ret = menu_ctrl_buttons[i - 1];
break;
}
}
return ret;
};
void() Menu_Control =
{
if (!menu_ctrl_init)

View file

@ -1,3 +1,5 @@
string menu_gpad_buttons[5] = {"gp_glyp", "gp_rumb", "gp_aima", "gp_apply", "gp_back"};
void() Menu_Gamepad_ApplyGlpyh =
{
Menu_PlaySound(MENU_SND_ENTER);
@ -42,6 +44,46 @@ void() Menu_Gamepad_ApplySettings =
music_duration_time = 0;
};
string(string prev_id) Menu_Gamepad_GetNextButton =
{
if (prev_id == "")
return menu_gpad_buttons[0];
string ret = menu_gpad_buttons[0];
for(float i = 0; i < menu_gpad_buttons.length; i++) {
if (menu_gpad_buttons[i] == prev_id) {
if (i + 1 >= menu_gpad_buttons.length)
break;
ret = menu_gpad_buttons[i + 1];
break;
}
}
return ret;
};
string(string next_id) Menu_Gamepad_GetPreviousButton =
{
if (next_id == "")
return menu_gpad_buttons[menu_gpad_buttons.length - 1];
string ret = menu_gpad_buttons[menu_gpad_buttons.length - 1];
for(float i = menu_gpad_buttons.length - 1; i > 0; i--) {
if (menu_gpad_buttons[i] == next_id) {
if (i - 1 < 0)
break;
ret = menu_gpad_buttons[i - 1];
break;
}
}
return ret;
};
void() Menu_Gamepad =
{
Menu_DrawBackground();

View file

@ -37,7 +37,8 @@ string loading_tips[] =
"\"not my trouble\" - Cooller",
"\"it's not internet\" - Cooller",
"\"relax\" - Cooller",
"Also try LibreQuake."
"Also try LibreQuake.",
"Support the Internet Archive!"
};
float loading_tip_endtime;

View file

@ -1,3 +1,5 @@
string menu_main_buttons[5] = {"mm_start", "mm_coop", "mm_options", "mm_credits", "mm_quit"};
string() Menu_Main_GetDashboardName =
{
switch(running_platform) {
@ -15,6 +17,54 @@ string() Menu_Main_GetDashboardName =
return "System";
};
string(string prev_id) Menu_Main_GetNextButton =
{
if (prev_id == "")
return menu_main_buttons[0];
string ret = menu_main_buttons[0];
for(float i = 0; i < menu_main_buttons.length; i++) {
if (menu_main_buttons[i] == prev_id) {
if (i + 1 >= menu_main_buttons.length)
break;
ret = menu_main_buttons[i + 1];
break;
}
}
// Wrap around to first if we selected Quit and this is WASM.
if (running_platform == PLATFORM_WEB && ret == "mm_quit")
ret = menu_main_buttons[0];
return ret;
};
string(string next_id) Menu_Main_GetPreviousButton =
{
if (next_id == "")
return menu_main_buttons[menu_main_buttons.length - 1];
string ret = menu_main_buttons[menu_main_buttons.length - 1];
for(float i = menu_main_buttons.length - 1; i > 0; i--) {
if (menu_main_buttons[i] == next_id) {
if (i - 1 < 0)
break;
ret = menu_main_buttons[i - 1];
break;
}
}
// Wrap around to first if we selected Quit and this is WASM.
if (running_platform == PLATFORM_WEB && ret == "mm_quit")
ret = menu_main_buttons[menu_main_buttons.length - 1];
return ret;
};
void() Menu_Main =
{
Menu_DrawBackground();

View file

@ -1,3 +1,6 @@
// Since these are built on-the-fly, do not populate here
string menu_maps_buttons[13];
float menu_maps_init;
//
@ -37,6 +40,58 @@ void(string bsp_name) Menu_Maps_LoadMap =
current_menu = MENU_MAIN;
};
string(string prev_id) Menu_Maps_GetNextButton =
{
if (prev_id == "")
return menu_maps_buttons[0];
string ret = menu_maps_buttons[0];
for(float i = 0; i < menu_maps_buttons.length; i++) {
if (menu_maps_buttons[i] == prev_id) {
if (i + 1 >= menu_maps_buttons.length)
break;
ret = menu_maps_buttons[i + 1];
break;
}
}
if (ret == "")
return menu_maps_buttons[0];
return ret;
};
string(string next_id) Menu_Maps_GetPreviousButton =
{
// Get the last populated entry.
string last_populated_entry = "";
for(float j = menu_maps_buttons.length - 1; j > 0; j--) {
if (menu_maps_buttons[j] != "") {
last_populated_entry = menu_maps_buttons[j];
break;
}
}
if (next_id == "")
return last_populated_entry;
string ret = last_populated_entry;
for(float i = menu_maps_buttons.length - 1; i > 0; i--) {
if (menu_maps_buttons[i] == next_id) {
if (i - 1 < 0)
break;
ret = menu_maps_buttons[i - 1];
break;
}
}
return ret;
};
void() Menu_Maps =
{
if (!menu_maps_init)
@ -59,13 +114,25 @@ void() Menu_Maps =
int i;
// Reset map button registry
for(int h = 0; h < 13; h++) {
menu_maps_buttons[h] = "";
}
// Stock Maps
if (menu_map_mode == MAP_SOLOSTOCK || menu_map_mode == MAP_COOPSTOCK) {
for(i = 0; i < stock_maps.length; i++) {
// Build the map strings
menu_maps_buttons[i] = sprintf("map_%s", stock_maps[i].bsp_name);
Menu_MapButton(i + 1, sprintf("map_%s", stock_maps[i].bsp_name), stock_maps[i].bsp_name, -1) ? Menu_Maps_LoadMap(stock_maps[i].bsp_name) : 0;
}
Menu_DrawDivider(i + 1.25);
Menu_Button(i + 1.5, "map_nzpusermaps", "USER MAPS", "View User-Created Maps.") ? current_menu = MENU_SOLOUSER : 0;
// Usermaps and back button registry
menu_maps_buttons[i] = "map_nzpusermaps";
menu_maps_buttons[i + 1] = "map_back";
} else {
// calculate the amount of usermaps we can display on this page.
int maps_on_page = 10; // default to 10, all that will fit on the UI.
@ -79,20 +146,33 @@ void() Menu_Maps =
int menu_position = (i + 1) - (user_maps_page * 10);
string bsp_name = user_maps[i].map_name;
// Build the map strings
menu_maps_buttons[menu_position - 1] = sprintf("map_%s", bsp_name);
Menu_MapButton(menu_position, sprintf("map_%s", bsp_name), bsp_name, i) ? localcmd(sprintf("map %s\n", bsp_name)) : 0;
}
int current_registry_position = ((i + 1) - (user_maps_page * 10)) - 1;
Menu_DrawDivider(11.25);
if (maps_on_page + maps_start_position < user_maps_count)
if (maps_on_page + maps_start_position < user_maps_count) {
menu_maps_buttons[current_registry_position] = "map_usernext";
current_registry_position++;
Menu_Button(-3, "map_usernext", "NEXT PAGE", "Advance to next User Map page.") ? Menu_Maps_NextPage() : 0;
else
} else {
Menu_GreyButton(-3, "NEXT PAGE");
}
if (user_maps_page != 0)
if (user_maps_page != 0) {
menu_maps_buttons[current_registry_position] = "map_userprev";
current_registry_position++;
Menu_Button(-2, "map_userprev", "PREVIOUS PAGE", "Return to last User Map page.") ? Menu_Maps_PrevPage() : 0;
else
} else {
Menu_GreyButton(-2, "PREVIOUS PAGE");
}
menu_maps_buttons[current_registry_position] = "map_back";
}
Menu_Button(-1, "map_back", "BACK", back_string) ? current_menu = back_menudest : 0;

View file

@ -1,3 +1,45 @@
string menu_opts_buttons[5] = {"om_video", "om_audio", "om_binds", "om_console", "om_back"};
string(string prev_id) Menu_Options_GetNextButton =
{
if (prev_id == "")
return menu_opts_buttons[0];
string ret = menu_opts_buttons[0];
for(float i = 0; i < menu_opts_buttons.length; i++) {
if (menu_opts_buttons[i] == prev_id) {
if (i + 1 >= menu_opts_buttons.length)
break;
ret = menu_opts_buttons[i + 1];
break;
}
}
return ret;
};
string(string next_id) Menu_Options_GetPreviousButton =
{
if (next_id == "")
return menu_opts_buttons[menu_opts_buttons.length - 1];
string ret = menu_opts_buttons[menu_opts_buttons.length - 1];
for(float i = menu_opts_buttons.length - 1; i > 0; i--) {
if (menu_opts_buttons[i] == next_id) {
if (i - 1 < 0)
break;
ret = menu_opts_buttons[i - 1];
break;
}
}
return ret;
};
void() Menu_Options =
{
Menu_DrawBackground();

View file

@ -1,3 +1,5 @@
string menu_video_buttons[12] = {"vm_resol", "vm_fulls", "vm_shfps", "vm_maxps", "vm_vsync", "vm_fov", "vm_gamma", "vm_uwide", "vm_parts", "vm_filtr", "vm_apply", "vm_back"};
float menu_video_init;
float menu_video_modes;
@ -155,6 +157,52 @@ void() Menu_Video_UpdateFiltering =
}
};
string(string prev_id) Menu_Video_GetNextButton =
{
if (prev_id == "")
return menu_video_buttons[0];
string ret = menu_video_buttons[0];
for(float i = 0; i < menu_video_buttons.length; i++) {
if (menu_video_buttons[i] == prev_id) {
if (i + 1 >= menu_video_buttons.length)
break;
ret = menu_video_buttons[i + 1];
break;
}
}
if (cvar("vid_vsync") && ret == "vm_maxps")
ret = "vm_vsync";
return ret;
};
string(string next_id) Menu_Video_GetPreviousButton =
{
if (next_id == "")
return menu_video_buttons[menu_video_buttons.length - 1];
string ret = menu_video_buttons[menu_video_buttons.length - 1];
for(float i = menu_video_buttons.length - 1; i > 0; i--) {
if (menu_video_buttons[i] == next_id) {
if (i - 1 < 0)
break;
ret = menu_video_buttons[i - 1];
break;
}
}
if (cvar("vid_vsync") && ret == "vm_maxps")
ret = "vm_shfps";
return ret;
};
void() Menu_Video =
{
if (!menu_video_init)

View file

@ -368,6 +368,7 @@ void(vector pos) _sui_mouse_move =
// Reset hover, it'll be back to what it used to be before draw gets called if mouse is still on same element
_hover_action_count = 0;
_hover_actions[0] = "";
// Iterate front to back, so topmost element gets the click/hover
for (int i = min(MAX_ACTION_ELEMENTS, _action_elements_index) - 1; i >= 0; i--)
@ -388,6 +389,84 @@ void(vector pos) _sui_mouse_move =
last_hovered_id = "";
};
void() _sui_menukey_downarrow =
{
string current_hovered_option = _hover_actions[0];
switch(current_menu) {
case MENU_MAIN:
_hover_actions[0] = Menu_Main_GetNextButton(current_hovered_option);
break;
case MENU_SOLO:
case MENU_SOLOUSER:
_hover_actions[0] = Menu_Maps_GetNextButton(current_hovered_option);
break;
case MENU_OPTIONS:
_hover_actions[0] = Menu_Options_GetNextButton(current_hovered_option);
break;
case MENU_VIDEO:
_hover_actions[0] = Menu_Video_GetNextButton(current_hovered_option);
break;
case MENU_AUDIO:
_hover_actions[0] = Menu_Audio_GetNextButton(current_hovered_option);
break;
case MENU_CONTROL:
_hover_actions[0] = Menu_Control_GetNextButton(current_hovered_option);
break;
case MENU_GAMEPAD:
_hover_actions[0] = Menu_Gamepad_GetNextButton(current_hovered_option);
break;
default:
break;
}
_hover_action_count = 1;
};
void() _sui_menukey_uparrow =
{
string current_hovered_option = _hover_actions[0];
switch(current_menu) {
case MENU_MAIN:
_hover_actions[0] = Menu_Main_GetPreviousButton(current_hovered_option);
break;
case MENU_SOLO:
case MENU_SOLOUSER:
_hover_actions[0] = Menu_Maps_GetPreviousButton(current_hovered_option);
break;
case MENU_OPTIONS:
_hover_actions[0] = Menu_Options_GetPreviousButton(current_hovered_option);
break;
case MENU_VIDEO:
_hover_actions[0] = Menu_Video_GetPreviousButton(current_hovered_option);
break;
case MENU_AUDIO:
_hover_actions[0] = Menu_Audio_GetPreviousButton(current_hovered_option);
break;
case MENU_CONTROL:
_hover_actions[0] = Menu_Control_GetPreviousButton(current_hovered_option);
break;
case MENU_GAMEPAD:
_hover_actions[0] = Menu_Gamepad_GetPreviousButton(current_hovered_option);
break;
default:
break;
}
_hover_action_count = 1;
};
void() _sui_menukey_enter =
{
if (_hover_actions[0] == "")
_sui_menukey_downarrow();
_click_actions[0] = _hover_actions[0];
_click_action_count = 1;
_last_clicked_action_count = 1;
};
// JERK ALERT: hard to pass input params for it without them just being the globals
// ... so it just straight up uses the globals... optimization
void() _sui_mouse1_down =
@ -440,6 +519,12 @@ void() _sui_mouse1_up =
_holding_click = FALSE;
};
// HACK!
void() sui_reset_hover =
{
_hover_actions[0] = "";
};
void(vector pos, vector size, string id, void(float index, vector click_ratios) action) sui_action_element =
{
if (!_sui_draw_initialized)
@ -671,6 +756,21 @@ float(float evtype, float scanx, float chary, float devid) sui_input_event =
_sui_mouse1_down();
return TRUE;
}
else if (scanx == K_DOWNARROW || scanx == K_GP_DPAD_DOWN)
{
_sui_menukey_downarrow();
return TRUE;
}
else if (scanx == K_UPARROW || scanx == K_GP_DPAD_UP)
{
_sui_menukey_uparrow();
return TRUE;
}
else if (scanx == K_ENTER || scanx == K_GP_A)
{
_sui_menukey_enter();
return TRUE;
}
else
{
if ((scanx == K_ESCAPE || scanx == K_BACKSPACE) && _sui_binding_command != "")