RetroArch/menu/drivers/menu_generic.c

413 lines
13 KiB
C
Raw Normal View History

2015-10-03 01:15:47 +00:00
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2016-01-10 03:06:50 +00:00
* Copyright (C) 2011-2016 - Daniel De Matteis
2015-10-03 01:15:47 +00:00
* Copyright (C) 2012-2015 - Michael Lelli
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <compat/strl.h>
#include <string/stdstring.h>
2015-10-03 01:15:47 +00:00
#include "menu_generic.h"
2015-12-06 16:55:27 +00:00
#include "../menu_driver.h"
2015-10-03 02:21:38 +00:00
#include "../menu_display.h"
2015-10-03 01:15:47 +00:00
#include "../menu_displaylist.h"
2015-12-09 08:53:43 +00:00
#include "../menu_navigation.h"
2015-10-03 01:15:47 +00:00
#include "../menu_hash.h"
2015-10-17 17:38:33 +00:00
#include "../menu_entries.h"
2015-10-03 01:15:47 +00:00
2015-10-03 02:21:38 +00:00
#include "../../configuration.h"
#include "../../performance.h"
#include "../../input/input_autodetect.h"
#include "../../input/input_config.h"
#include "../../cheevos.h"
2015-10-03 02:21:38 +00:00
2015-11-23 11:03:38 +00:00
#include "../../verbosity.h"
2015-10-03 02:21:38 +00:00
2015-12-10 18:38:46 +00:00
static int action_iterate_help(menu_handle_t *menu,
char *s, size_t len, const char *label)
2015-10-03 02:21:38 +00:00
{
2016-02-13 05:30:39 +00:00
#ifdef HAVE_CHEEVOS
cheevos_ctx_desc_t desc_info;
#endif
bool do_exit = false;
2015-10-03 02:21:38 +00:00
settings_t *settings = config_get_ptr();
switch (menu->help_screen_type)
{
case MENU_HELP_WELCOME:
{
static int64_t timeout_end;
int64_t timeout;
static bool timer_begin = false;
static bool timer_end = false;
int64_t current = retro_get_time_usec();
if (!timer_begin)
{
timeout_end = retro_get_time_usec() +
3 /* seconds */ * 1000000;
timer_begin = true;
timer_end = false;
}
timeout = (timeout_end - current) / 1000000;
menu_hash_get_help(MENU_LABEL_WELCOME_TO_RETROARCH,
s, len);
if (!timer_end && timeout <= 0)
{
timer_end = true;
timer_begin = false;
timeout_end = 0;
do_exit = true;
2015-10-03 02:21:38 +00:00
}
}
break;
case MENU_HELP_CONTROLS:
{
unsigned i;
char s2[PATH_MAX_LENGTH];
const unsigned binds[] = {
RETRO_DEVICE_ID_JOYPAD_UP,
RETRO_DEVICE_ID_JOYPAD_DOWN,
RETRO_DEVICE_ID_JOYPAD_A,
RETRO_DEVICE_ID_JOYPAD_B,
RETRO_DEVICE_ID_JOYPAD_SELECT,
RETRO_DEVICE_ID_JOYPAD_START,
RARCH_MENU_TOGGLE,
RARCH_QUIT_KEY,
RETRO_DEVICE_ID_JOYPAD_X,
RETRO_DEVICE_ID_JOYPAD_Y,
};
char desc[ARRAY_SIZE(binds)][64] = {{0}};
for (i = 0; i < ARRAY_SIZE(binds); i++)
{
2016-02-04 20:42:42 +00:00
const struct retro_keybind *keybind =
(const struct retro_keybind*)
2015-10-03 02:21:38 +00:00
&settings->input.binds[0][binds[i]];
2016-02-04 20:42:42 +00:00
const struct retro_keybind *auto_bind =
(const struct retro_keybind*)
2015-10-03 02:21:38 +00:00
input_get_auto_bind(0, binds[i]);
2016-02-04 20:42:42 +00:00
input_config_get_bind_string(desc[i],
keybind, auto_bind, sizeof(desc[i]));
2015-10-03 02:21:38 +00:00
}
menu_hash_get_help(MENU_LABEL_VALUE_MENU_CONTROLS_PROLOG,
s2, sizeof(s2));
snprintf(s, len,
"%s"
"[%s]: "
"%-20s\n"
"[%s]: "
"%-20s\n"
"[%s]: "
"%-20s\n"
"[%s]: "
"%-20s\n"
"[%s]: "
"%-20s\n"
"[%s]: "
"%-20s\n"
"[%s]: "
"%-20s\n"
"[%s]: "
"%-20s\n"
"[%s]: "
"%-20s\n",
2016-02-10 19:24:09 +00:00
2015-10-03 02:21:38 +00:00
s2,
2016-02-10 19:24:09 +00:00
menu_hash_to_str(
MENU_LABEL_VALUE_BASIC_MENU_CONTROLS_SCROLL_UP),
desc[0],
menu_hash_to_str(
MENU_LABEL_VALUE_BASIC_MENU_CONTROLS_SCROLL_DOWN),
desc[1],
menu_hash_to_str(
MENU_LABEL_VALUE_BASIC_MENU_CONTROLS_CONFIRM),
desc[2],
menu_hash_to_str(
MENU_LABEL_VALUE_BASIC_MENU_CONTROLS_BACK),
desc[3],
menu_hash_to_str(
MENU_LABEL_VALUE_BASIC_MENU_CONTROLS_INFO),
desc[4],
menu_hash_to_str(
MENU_LABEL_VALUE_BASIC_MENU_CONTROLS_START),
desc[5],
menu_hash_to_str(
MENU_LABEL_VALUE_BASIC_MENU_CONTROLS_TOGGLE_MENU),
desc[6],
menu_hash_to_str(
MENU_LABEL_VALUE_BASIC_MENU_CONTROLS_QUIT),
desc[7],
menu_hash_to_str(
MENU_LABEL_VALUE_BASIC_MENU_CONTROLS_TOGGLE_KEYBOARD),
desc[8]
2015-10-03 02:21:38 +00:00
);
}
break;
#ifdef HAVE_CHEEVOS
case MENU_HELP_CHEEVOS_DESCRIPTION:
2016-02-13 05:30:39 +00:00
desc_info.idx = menu->help_screen_id;
desc_info.s = s;
desc_info.len = len;
cheevos_ctl(CHEEVOS_CTL_GET_DESCRIPTION, &desc_info);
break;
#endif
2015-10-03 02:21:38 +00:00
case MENU_HELP_WHAT_IS_A_CORE:
menu_hash_get_help(MENU_LABEL_VALUE_WHAT_IS_A_CORE_DESC,
s, len);
break;
case MENU_HELP_LOADING_CONTENT:
menu_hash_get_help(MENU_LABEL_LOAD_CONTENT,
s, len);
break;
case MENU_HELP_CHANGE_VIRTUAL_GAMEPAD:
2016-02-10 19:24:09 +00:00
menu_hash_get_help(
MENU_LABEL_VALUE_HELP_CHANGE_VIRTUAL_GAMEPAD_DESC,
2015-10-03 02:21:38 +00:00
s, len);
break;
case MENU_HELP_AUDIO_VIDEO_TROUBLESHOOTING:
2016-02-10 19:24:09 +00:00
menu_hash_get_help(
MENU_LABEL_VALUE_HELP_AUDIO_VIDEO_TROUBLESHOOTING_DESC,
2015-10-03 02:21:38 +00:00
s, len);
break;
case MENU_HELP_SCANNING_CONTENT:
menu_hash_get_help(MENU_LABEL_VALUE_HELP_SCANNING_CONTENT_DESC,
s, len);
break;
case MENU_HELP_EXTRACT:
menu_hash_get_help(MENU_LABEL_VALUE_EXTRACTING_PLEASE_WAIT,
s, len);
if (settings->bundle_finished)
{
settings->bundle_finished = false;
do_exit = true;
}
2015-10-03 02:21:38 +00:00
break;
case MENU_HELP_NONE:
default:
break;
}
if (do_exit)
{
menu->help_screen_type = MENU_HELP_NONE;
return 1;
}
2015-10-03 02:21:38 +00:00
return 0;
}
static enum action_iterate_type action_iterate_type(uint32_t hash)
{
switch (hash)
{
case MENU_LABEL_HELP:
case MENU_LABEL_HELP_CONTROLS:
case MENU_LABEL_HELP_WHAT_IS_A_CORE:
case MENU_LABEL_HELP_LOADING_CONTENT:
case MENU_LABEL_HELP_CHANGE_VIRTUAL_GAMEPAD:
case MENU_LABEL_CHEEVOS_DESCRIPTION:
2015-10-03 02:21:38 +00:00
case MENU_LABEL_HELP_AUDIO_VIDEO_TROUBLESHOOTING:
case MENU_LABEL_HELP_SCANNING_CONTENT:
return ITERATE_TYPE_HELP;
case MENU_LABEL_INFO_SCREEN:
return ITERATE_TYPE_INFO;
case MENU_LABEL_CUSTOM_BIND:
case MENU_LABEL_CUSTOM_BIND_ALL:
case MENU_LABEL_CUSTOM_BIND_DEFAULTS:
return ITERATE_TYPE_BIND;
}
return ITERATE_TYPE_DEFAULT;
}
/**
* menu_iterate:
* @input : input sample for this frame
* @old_input : input sample of the previous frame
* @trigger_input : difference' input sample - difference
* between 'input' and 'old_input'
*
* Runs RetroArch menu for one frame.
*
* Returns: 0 on success, -1 if we need to quit out of the loop.
**/
2015-12-10 18:38:46 +00:00
int generic_menu_iterate(void *data, void *userdata, enum menu_action action)
2015-10-03 02:21:38 +00:00
{
size_t selection;
menu_entry_t entry;
enum action_iterate_type iterate_type;
2015-10-17 16:02:41 +00:00
const char *label = NULL;
int ret = 0;
uint32_t label_hash = 0;
uint32_t hash = 0;
2015-12-10 18:38:46 +00:00
menu_handle_t *menu = (menu_handle_t*)data;
file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0);
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
2015-10-03 02:21:38 +00:00
menu_entries_get_last_stack(NULL, &label, NULL, NULL);
2015-10-03 02:21:38 +00:00
2015-10-17 17:21:18 +00:00
if (!menu)
2015-10-03 02:21:38 +00:00
return 0;
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
return 0;
menu->menu_state.msg[0] = '\0';
hash = menu_hash_calculate(label);
iterate_type = action_iterate_type(hash);
2015-12-11 20:41:59 +00:00
if ( action != MENU_ACTION_NOOP
|| menu_entries_ctl(MENU_ENTRIES_CTL_NEEDS_REFRESH, NULL)
|| menu_display_ctl(MENU_DISPLAY_CTL_UPDATE_PENDING, NULL))
2015-10-03 02:21:38 +00:00
{
BIT64_SET(menu->state, MENU_STATE_RENDER_FRAMEBUFFER);
2015-10-03 02:21:38 +00:00
}
switch (iterate_type)
{
case ITERATE_TYPE_HELP:
2016-02-04 20:42:42 +00:00
ret = action_iterate_help(menu,
menu->menu_state.msg, sizeof(menu->menu_state.msg), label);
2015-10-03 02:21:38 +00:00
BIT64_SET(menu->state, MENU_STATE_RENDER_MESSAGEBOX);
BIT64_SET(menu->state, MENU_STATE_POST_ITERATE);
if (ret == 1 || action == MENU_ACTION_OK)
BIT64_SET(menu->state, MENU_STATE_POP_STACK);
break;
case ITERATE_TYPE_BIND:
{
2016-02-25 16:55:45 +00:00
menu_input_ctx_bind_t bind;
bind.s = menu->menu_state.msg;
bind.len = sizeof(menu->menu_state.msg);
if (menu_input_ctl(MENU_INPUT_CTL_BIND_ITERATE, &bind))
{
menu_entries_pop_stack(&selection, 0);
menu_navigation_ctl(
MENU_NAVIGATION_CTL_SET_SELECTION, &selection);
}
else
BIT64_SET(menu->state, MENU_STATE_RENDER_MESSAGEBOX);
2015-10-03 02:21:38 +00:00
}
break;
case ITERATE_TYPE_INFO:
{
2016-02-04 20:42:42 +00:00
menu_file_list_cbs_t *cbs =
menu_entries_get_actiondata_at_offset(selection_buf, selection);
2015-10-03 02:21:38 +00:00
rarch_setting_t *setting = cbs->setting;
if (setting)
{
char needle[PATH_MAX_LENGTH];
2015-10-11 11:10:46 +00:00
strlcpy(needle, menu_setting_get_name(setting), sizeof(needle));
2015-10-03 02:21:38 +00:00
label_hash = menu_hash_calculate(needle);
}
2016-02-04 20:42:42 +00:00
ret = menu_hash_get_help(label_hash,
menu->menu_state.msg, sizeof(menu->menu_state.msg));
2015-10-03 02:21:38 +00:00
}
BIT64_SET(menu->state, MENU_STATE_RENDER_MESSAGEBOX);
BIT64_SET(menu->state, MENU_STATE_POST_ITERATE);
if (action == MENU_ACTION_OK)
BIT64_SET(menu->state, MENU_STATE_POP_STACK);
break;
case ITERATE_TYPE_DEFAULT:
2016-02-21 08:54:53 +00:00
/* FIXME: Crappy hack, needed for mouse controls
* to not be completely broken in case we press back.
2015-10-03 02:21:38 +00:00
*
2016-02-21 08:54:53 +00:00
* We need to fix this entire mess, mouse controls
* should not rely on a hack like this in order to work. */
2016-03-01 23:07:31 +00:00
selection = MAX(MIN(selection, (menu_entries_get_size() - 1)), 0);
2015-10-03 02:21:38 +00:00
menu_entry_get(&entry, 0, selection, NULL, false);
2015-10-03 02:21:38 +00:00
ret = menu_entry_action(&entry, selection, (enum menu_action)action);
if (ret)
goto end;
BIT64_SET(menu->state, MENU_STATE_POST_ITERATE);
/* Have to defer it so we let settings refresh. */
if (menu->push_help_screen)
{
menu_displaylist_info_t info = {0};
2015-10-17 16:02:41 +00:00
info.list = menu_stack;
2015-10-03 02:21:38 +00:00
strlcpy(info.label,
menu_hash_to_str(MENU_LABEL_HELP),
sizeof(info.label));
menu_displaylist_ctl(DISPLAYLIST_HELP, &info);
2015-10-03 02:21:38 +00:00
}
break;
}
BIT64_SET(menu->state, MENU_STATE_BLIT);
2015-10-03 02:21:38 +00:00
if (BIT64_GET(menu->state, MENU_STATE_POP_STACK))
{
size_t new_selection_ptr = selection;
2015-10-27 09:29:50 +00:00
menu_entries_pop_stack(&new_selection_ptr, 0);
2015-10-03 02:21:38 +00:00
menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &selection);
}
if (BIT64_GET(menu->state, MENU_STATE_POST_ITERATE))
menu_input_post_iterate(&ret, action);
end:
if (ret)
return -1;
return 0;
}
2015-10-03 01:15:47 +00:00
bool generic_menu_init_list(void *data)
{
menu_displaylist_info_t info = {0};
file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0);
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
2015-10-03 01:15:47 +00:00
2016-02-04 20:42:42 +00:00
strlcpy(info.label,
menu_hash_to_str(MENU_VALUE_MAIN_MENU), sizeof(info.label));
2015-10-03 01:15:47 +00:00
menu_entries_add(menu_stack, info.path,
2016-02-04 20:42:42 +00:00
info.label, info.type, info.flags, 0);
2015-10-22 01:02:03 +00:00
info.list = selection_buf;
2016-02-24 22:05:54 +00:00
if (menu_displaylist_ctl(DISPLAYLIST_MAIN_MENU, &info))
2016-02-24 22:19:53 +00:00
menu_displaylist_ctl(DISPLAYLIST_PROCESS, &info);
2015-10-03 01:15:47 +00:00
return true;
}