RetroArch/menu/widgets/menu_dialog.c

317 lines
9.0 KiB
C
Raw Normal View History

2016-09-04 22:58:54 +02:00
/* RetroArch - A frontend for libretro.
2017-01-22 13:40:32 +01:00
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Brad Parker
2016-09-04 22:58:54 +02:00
*
* 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 <features/features_cpu.h>
2016-09-08 05:43:10 +02:00
#ifdef HAVE_CONFIG_H
2016-09-11 21:03:31 +02:00
#include "../../config.h"
2016-09-08 05:43:10 +02:00
#endif
#ifdef HAVE_CHEEVOS
#include "../../cheevos/cheevos.h"
2016-09-08 05:43:10 +02:00
#endif
#include "menu_dialog.h"
2016-09-04 22:58:54 +02:00
2016-09-11 21:03:31 +02:00
#include "../menu_driver.h"
2016-09-08 05:43:10 +02:00
2016-09-11 21:03:31 +02:00
#include "../../retroarch.h"
#include "../../configuration.h"
#include "../../tasks/tasks_internal.h"
#include "../../input/input_driver.h"
#include "../../performance_counters.h"
2016-09-04 22:58:54 +02:00
2016-09-15 16:07:20 +02:00
static bool menu_dialog_pending_push = false;
static bool menu_dialog_active = false;
static unsigned menu_dialog_current_id = 0;
2016-09-15 16:07:20 +02:00
static enum menu_dialog_type menu_dialog_current_type = MENU_DIALOG_NONE;
static enum msg_hash_enums menu_dialog_current_msg = MSG_UNKNOWN;
2016-09-04 23:34:24 +02:00
2016-09-15 16:07:20 +02:00
int menu_dialog_iterate(char *s, size_t len, const char *label)
2016-09-04 22:58:54 +02:00
{
#ifdef HAVE_CHEEVOS
cheevos_ctx_desc_t desc_info;
#endif
2016-09-04 23:34:24 +02:00
bool do_exit = false;
2016-09-04 22:58:54 +02:00
settings_t *settings = config_get_ptr();
2016-09-15 16:07:20 +02:00
switch (menu_dialog_current_type)
2016-09-04 22:58:54 +02:00
{
2016-09-15 16:07:20 +02:00
case MENU_DIALOG_WELCOME:
2016-09-04 22:58:54 +02:00
{
static rarch_timer_t timer;
2016-09-04 22:58:54 +02:00
if (!rarch_timer_is_running(&timer))
rarch_timer_begin(&timer, 3);
2016-09-04 22:58:54 +02:00
rarch_timer_tick(&timer);
2016-09-04 22:58:54 +02:00
menu_hash_get_help_enum(
MENU_ENUM_LABEL_WELCOME_TO_RETROARCH,
s, len);
2016-12-23 16:32:21 +01:00
if (!timer.timer_end && rarch_timer_has_expired(&timer))
2016-09-04 22:58:54 +02:00
{
rarch_timer_end(&timer);
2016-09-04 22:58:54 +02:00
do_exit = true;
}
}
break;
2016-09-15 16:07:20 +02:00
case MENU_DIALOG_HELP_CONTROLS:
2016-09-04 22:58:54 +02:00
{
unsigned i;
char s2[PATH_MAX_LENGTH];
2016-09-04 22:58:54 +02:00
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];
for (i = 0; i < ARRAY_SIZE(binds); i++)
desc[i][0] = '\0';
2016-09-04 22:58:54 +02:00
for (i = 0; i < ARRAY_SIZE(binds); i++)
{
2017-04-26 00:24:59 +02:00
const struct retro_keybind *keybind = &input_config_binds[0][binds[i]];
const struct retro_keybind *auto_bind =
2016-09-04 22:58:54 +02:00
(const struct retro_keybind*)
input_config_get_bind_auto(0, binds[i]);
2016-09-04 22:58:54 +02:00
input_config_get_bind_string(desc[i],
keybind, auto_bind, sizeof(desc[i]));
}
s2[0] = '\0';
2016-09-04 22:58:54 +02:00
menu_hash_get_help_enum(MENU_ENUM_LABEL_VALUE_MENU_ENUM_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",
s2,
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_SCROLL_UP),
desc[0],
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_SCROLL_DOWN),
desc[1],
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_CONFIRM),
desc[2],
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_BACK),
desc[3],
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_INFO),
desc[4],
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_START),
desc[5],
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_TOGGLE_MENU),
desc[6],
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_QUIT),
desc[7],
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_TOGGLE_KEYBOARD),
desc[8]
);
}
break;
2016-09-04 22:58:54 +02:00
#ifdef HAVE_CHEEVOS
2016-09-15 16:07:20 +02:00
case MENU_DIALOG_HELP_CHEEVOS_DESCRIPTION:
desc_info.idx = menu_dialog_current_id;
2016-09-04 22:58:54 +02:00
desc_info.s = s;
desc_info.len = len;
cheevos_get_description(&desc_info);
break;
#endif
2016-09-15 16:07:20 +02:00
case MENU_DIALOG_HELP_WHAT_IS_A_CORE:
2016-09-04 22:58:54 +02:00
menu_hash_get_help_enum(MENU_ENUM_LABEL_VALUE_WHAT_IS_A_CORE_DESC,
s, len);
break;
2016-09-15 16:07:20 +02:00
case MENU_DIALOG_HELP_LOADING_CONTENT:
2016-09-04 22:58:54 +02:00
menu_hash_get_help_enum(MENU_ENUM_LABEL_LOAD_CONTENT_LIST,
s, len);
break;
2016-09-15 16:07:20 +02:00
case MENU_DIALOG_HELP_CHANGE_VIRTUAL_GAMEPAD:
2016-09-04 22:58:54 +02:00
menu_hash_get_help_enum(
MENU_ENUM_LABEL_VALUE_HELP_CHANGE_VIRTUAL_GAMEPAD_DESC,
s, len);
break;
2016-09-15 16:07:20 +02:00
case MENU_DIALOG_HELP_AUDIO_VIDEO_TROUBLESHOOTING:
2016-09-04 22:58:54 +02:00
menu_hash_get_help_enum(
MENU_ENUM_LABEL_VALUE_HELP_AUDIO_VIDEO_TROUBLESHOOTING_DESC,
s, len);
break;
2016-09-15 16:07:20 +02:00
case MENU_DIALOG_HELP_SCANNING_CONTENT:
2016-09-04 22:58:54 +02:00
menu_hash_get_help_enum(MENU_ENUM_LABEL_VALUE_HELP_SCANNING_CONTENT_DESC,
s, len);
break;
2016-09-15 16:07:20 +02:00
case MENU_DIALOG_HELP_EXTRACT:
2016-09-04 22:58:54 +02:00
menu_hash_get_help_enum(MENU_ENUM_LABEL_VALUE_EXTRACTING_PLEASE_WAIT,
s, len);
2017-04-28 00:00:43 +02:00
if (settings->bools.bundle_finished)
2016-09-04 22:58:54 +02:00
{
2017-04-28 00:00:43 +02:00
settings->bools.bundle_finished = false;
do_exit = true;
2016-09-04 22:58:54 +02:00
}
break;
2016-09-15 16:07:20 +02:00
case MENU_DIALOG_QUIT_CONFIRM:
case MENU_DIALOG_INFORMATION:
case MENU_DIALOG_QUESTION:
case MENU_DIALOG_WARNING:
case MENU_DIALOG_ERROR:
menu_hash_get_help_enum(menu_dialog_current_msg,
s, len);
break;
2016-09-15 16:07:20 +02:00
case MENU_DIALOG_NONE:
2016-09-04 22:58:54 +02:00
default:
break;
}
if (do_exit)
{
2016-09-15 16:07:20 +02:00
menu_dialog_current_type = MENU_DIALOG_NONE;
2016-09-04 22:58:54 +02:00
return 1;
}
return 0;
}
2016-09-15 16:07:20 +02:00
bool menu_dialog_is_push_pending(void)
2016-09-04 23:27:08 +02:00
{
2016-09-15 16:07:20 +02:00
return menu_dialog_pending_push;
2016-09-04 23:27:08 +02:00
}
2016-09-15 16:07:20 +02:00
void menu_dialog_unset_pending_push(void)
2016-09-04 23:27:08 +02:00
{
2016-09-15 16:07:20 +02:00
menu_dialog_pending_push = false;
2016-09-04 23:27:08 +02:00
}
2016-09-15 16:07:20 +02:00
void menu_dialog_push_pending(bool push, enum menu_dialog_type type)
2016-09-04 23:20:27 +02:00
{
2016-09-15 16:07:20 +02:00
menu_dialog_pending_push = push;
menu_dialog_current_type = type;
menu_dialog_active = true;
2016-09-04 23:20:27 +02:00
}
2016-09-15 16:07:20 +02:00
void menu_dialog_push(void)
2016-09-04 22:58:54 +02:00
{
menu_displaylist_info_t info;
2017-11-21 04:38:38 +01:00
const char *label;
2016-09-04 22:58:54 +02:00
2016-09-15 16:07:20 +02:00
if (!menu_dialog_is_push_pending())
2016-09-04 22:58:54 +02:00
return;
2017-09-28 02:30:31 +02:00
menu_displaylist_info_init(&info);
info.list = menu_entries_get_menu_stack_ptr(0);
info.enum_idx = MENU_ENUM_LABEL_HELP;
2017-11-20 18:46:07 -05:00
2017-11-21 04:38:38 +01:00
/* Set the label string, if it exists. */
label = msg_hash_to_str(MENU_ENUM_LABEL_HELP);
2017-11-20 18:46:07 -05:00
if (label)
2017-11-21 04:38:38 +01:00
info.label = strdup(label);
2016-09-04 22:58:54 +02:00
menu_displaylist_ctl(DISPLAYLIST_HELP, &info);
}
2016-09-04 23:34:24 +02:00
void menu_dialog_set_current_id(unsigned id)
{
menu_dialog_current_id = id;
}
2016-09-15 16:07:20 +02:00
void menu_dialog_reset(void)
2016-09-04 23:34:24 +02:00
{
2016-09-15 16:07:20 +02:00
menu_dialog_pending_push = false;
menu_dialog_current_id = 0;
menu_dialog_current_type = MENU_DIALOG_NONE;
menu_dialog_current_msg = MSG_UNKNOWN;
menu_display_toggle_set_reason(MENU_TOGGLE_REASON_NONE);
}
2016-09-15 16:07:20 +02:00
void menu_dialog_show_message(
enum menu_dialog_type type, enum msg_hash_enums msg)
{
2016-09-15 16:07:20 +02:00
menu_dialog_current_msg = msg;
if (!menu_driver_ctl(RARCH_MENU_CTL_IS_TOGGLE, NULL))
menu_display_toggle_set_reason(MENU_TOGGLE_REASON_MESSAGE);
2016-09-15 16:07:20 +02:00
menu_dialog_push_pending(true, type);
menu_dialog_push();
}
2016-09-15 16:07:20 +02:00
bool menu_dialog_is_active(void)
{
2016-09-15 16:07:20 +02:00
return menu_dialog_active;
}
2016-09-15 16:07:20 +02:00
void menu_dialog_set_active(bool on)
{
2016-09-15 16:07:20 +02:00
menu_dialog_active = on;
}
2016-09-15 16:07:20 +02:00
enum menu_dialog_type menu_dialog_get_current_type(void)
{
2016-09-15 16:07:20 +02:00
return menu_dialog_current_type;
2016-09-04 23:34:24 +02:00
}