Skip to content

Commit 1e55555

Browse files
committed
Add Load State to Run menu
1 parent 8f6d51b commit 1e55555

20 files changed

Lines changed: 271 additions & 82 deletions

gfx/gfx_thumbnail.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
#include "../paths.h"
3939
#include "../file_path_special.h"
4040

41+
#ifdef HAVE_MENU
42+
#include "../menu/menu_driver.h"
43+
#endif
44+
4145
#include "../tasks/tasks_internal.h"
4246

4347
#define DEFAULT_GFX_THUMBNAIL_STREAM_DELAY 16.66667f * 3
@@ -1987,6 +1991,7 @@ void gfx_savestate_thumbnail_get_path(
19871991
int state_slot)
19881992
{
19891993
size_t _len;
1994+
playlist_t *playlist = playlist_get_cached();
19901995

19911996
if (!s || !len)
19921997
return;
@@ -1996,6 +2001,36 @@ void gfx_savestate_thumbnail_get_path(
19962001
if (!state_name || !*state_name)
19972002
return;
19982003

2004+
#ifdef HAVE_MENU
2005+
if (playlist)
2006+
{
2007+
struct menu_state *menu_st = menu_state_get_ptr();
2008+
runloop_state_t *runloop_st = runloop_state_get_ptr();
2009+
const struct playlist_entry *entry = NULL;
2010+
2011+
if (menu_st && menu_st->driver_data)
2012+
playlist_get_index(playlist, menu_st->driver_data->rpl_entry_selection_ptr, &entry);
2013+
2014+
if (*entry->path)
2015+
{
2016+
size_t _len;
2017+
char new_path[PATH_MAX_LENGTH];
2018+
char entry_basename[PATH_MAX_LENGTH];
2019+
2020+
strlcpy(new_path, entry->path, sizeof(new_path));
2021+
path_remove_extension(new_path);
2022+
2023+
_len = strlcpy(entry_basename, path_basename(new_path), sizeof(entry_basename));
2024+
2025+
strlcpy(entry_basename + _len, ".state", sizeof(entry_basename) - _len);
2026+
fill_pathname_join_special(new_path,
2027+
runloop_st->savestate_dir, entry_basename, sizeof(new_path));
2028+
2029+
state_name = strdup(new_path);
2030+
}
2031+
}
2032+
#endif /* HAVE_MENU */
2033+
19992034
_len = strlcpy(s, state_name, len);
20002035

20012036
/* The historical implementation accumulated _len from

intl/msg_hash_lbl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,10 @@ MSG_HASH(
826826
MENU_ENUM_LABEL_SAVESTATE_LIST,
827827
MENU_ENUM_LABEL_SAVESTATE_LIST_STR
828828
)
829+
MSG_HASH(
830+
MENU_ENUM_LABEL_STATE_SLOT_RUN,
831+
MENU_ENUM_LABEL_STATE_SLOT_RUN_STR
832+
)
829833
MSG_HASH(
830834
MENU_ENUM_LABEL_CORE_OPTIONS,
831835
MENU_ENUM_LABEL_CORE_OPTIONS_STR

menu/cbs/menu_cbs_cancel.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,32 @@ static int action_cancel_contentless_core(const char *path,
8989
{
9090
menu_state_get_ptr()->contentless_core_ptr = 0;
9191
menu_contentless_cores_flush_runtime();
92-
return action_cancel_pop_default(path, label, type, idx) ;
92+
return action_cancel_pop_default(path, label, type, idx);
93+
}
94+
95+
static int action_cancel_state_slot_run(const char *path,
96+
const char *label, unsigned type, size_t idx)
97+
{
98+
struct menu_state *menu_st = menu_state_get_ptr();
99+
runloop_state_t *runloop_st = runloop_state_get_ptr();
100+
101+
if (!(runloop_st->flags & RUNLOOP_FLAG_CORE_RUNNING))
102+
command_event(CMD_EVENT_UNLOAD_CORE, NULL);
103+
104+
menu_st->driver_data->state_slot_run = 0;
105+
106+
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH;
107+
menu_st->flags &= ~MENU_ST_FLAG_PREVENT_POPULATE;
108+
109+
return action_cancel_pop_default(path, label, type, idx);
93110
}
94111

95112
#ifdef HAVE_CHEATS
96113
static int action_cancel_cheat_details(const char *path,
97114
const char *label, unsigned type, size_t idx)
98115
{
99-
cheat_manager_copy_working_to_idx(cheat_manager_state.working_cheat.idx) ;
100-
return action_cancel_pop_default(path, label, type, idx) ;
116+
cheat_manager_copy_working_to_idx(cheat_manager_state.working_cheat.idx);
117+
return action_cancel_pop_default(path, label, type, idx);
101118
}
102119
#endif
103120

@@ -165,6 +182,9 @@ static int menu_cbs_init_bind_cancel_compare_type(
165182
case MENU_SETTING_ACTION_CONTENTLESS_CORE_RUN:
166183
BIND_ACTION_CANCEL(cbs, action_cancel_contentless_core);
167184
return 0;
185+
case MENU_SETTING_ACTION_STATE_SLOT_RUN:
186+
BIND_ACTION_CANCEL(cbs, action_cancel_state_slot_run);
187+
return 0;
168188
default:
169189
break;
170190
}

menu/cbs/menu_cbs_deferred_push.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ GENERIC_DEFERRED_PUSH(deferred_push_core_cheat_options, DISPLAYLIST_
121121
GENERIC_DEFERRED_PUSH(deferred_push_core_input_remapping_options, DISPLAYLIST_OPTIONS_REMAPPINGS)
122122
GENERIC_DEFERRED_PUSH(deferred_push_remap_file_manager, DISPLAYLIST_REMAP_FILE_MANAGER)
123123
GENERIC_DEFERRED_PUSH(deferred_push_savestate_list, DISPLAYLIST_SAVESTATE_LIST)
124+
GENERIC_DEFERRED_PUSH(deferred_push_state_slot_run, DISPLAYLIST_STATE_SLOT_RUN)
124125
GENERIC_DEFERRED_PUSH(deferred_push_core_options, DISPLAYLIST_CORE_OPTIONS)
125126
GENERIC_DEFERRED_PUSH(deferred_push_core_option_override_list, DISPLAYLIST_CORE_OPTION_OVERRIDE_LIST)
126127
GENERIC_DEFERRED_PUSH(deferred_push_disk_options, DISPLAYLIST_OPTIONS_DISK)
@@ -669,6 +670,7 @@ static int menu_cbs_init_bind_deferred_push_compare_label(
669670
{MENU_ENUM_LABEL_CORE_LIST, deferred_push_core_list},
670671
{MENU_ENUM_LABEL_LOAD_CONTENT_HISTORY, deferred_push_history_list},
671672
{MENU_ENUM_LABEL_SAVESTATE_LIST, deferred_push_savestate_list},
673+
{MENU_ENUM_LABEL_STATE_SLOT_RUN, deferred_push_state_slot_run},
672674
{MENU_ENUM_LABEL_CORE_OPTIONS, deferred_push_core_options},
673675
{MENU_ENUM_LABEL_DEFERRED_CORE_OPTION_OVERRIDE_LIST, deferred_push_core_option_override_list},
674676
{MENU_ENUM_LABEL_NETWORK_INFORMATION, deferred_push_network_information},
@@ -951,6 +953,9 @@ static int menu_cbs_init_bind_deferred_push_compare_label(
951953
case MENU_ENUM_LABEL_SAVESTATE_LIST:
952954
BIND_ACTION_DEFERRED_PUSH(cbs, deferred_push_savestate_list);
953955
break;
956+
case MENU_ENUM_LABEL_STATE_SLOT_RUN:
957+
BIND_ACTION_DEFERRED_PUSH(cbs, deferred_push_state_slot_run);
958+
break;
954959
case MENU_ENUM_LABEL_CORE_OPTIONS:
955960
BIND_ACTION_DEFERRED_PUSH(cbs, deferred_push_core_options);
956961
break;

menu/cbs/menu_cbs_ok.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6742,6 +6742,7 @@ STATIC_DEFAULT_ACTION_OK_FUNC(action_ok_push_core_manager_steam_list, ACTION_OK_
67426742
STATIC_DEFAULT_ACTION_OK_FUNC(action_ok_push_core_option_override_list, ACTION_OK_DL_CORE_OPTION_OVERRIDE_LIST)
67436743
STATIC_DEFAULT_ACTION_OK_FUNC(action_ok_push_remap_file_manager_list, ACTION_OK_DL_REMAP_FILE_MANAGER_LIST)
67446744
STATIC_DEFAULT_ACTION_OK_FUNC(action_ok_push_savestate_list, ACTION_OK_DL_SAVESTATE_LIST)
6745+
STATIC_DEFAULT_ACTION_OK_FUNC(action_ok_push_state_slot_run, ACTION_OK_DL_SAVESTATE_LIST)
67456746
STATIC_DEFAULT_ACTION_OK_FUNC(action_ok_push_core_options_list, ACTION_OK_DL_CORE_OPTIONS_LIST)
67466747
STATIC_DEFAULT_ACTION_OK_FUNC(action_ok_push_add_to_playlist_list, ACTION_OK_DL_ADD_TO_PLAYLIST)
67476748
STATIC_DEFAULT_ACTION_OK_FUNC(action_ok_push_add_to_playlist_quickmenu, ACTION_OK_DL_ADD_TO_PLAYLIST_QUICKMENU)
@@ -8043,6 +8044,27 @@ static int action_ok_contentless_core_run(const char *path,
80438044
return 0;
80448045
}
80458046

8047+
static int action_ok_state_slot_run(const char *path,
8048+
const char *label, unsigned type, size_t idx, size_t entry_idx)
8049+
{
8050+
settings_t *settings = config_get_ptr();
8051+
struct menu_state *menu_st = menu_state_get_ptr();
8052+
int slot = idx - 1;
8053+
size_t new_selection_ptr = 0;
8054+
8055+
menu_entries_pop_stack(&new_selection_ptr, 0, 0);
8056+
menu_st->selection_ptr = 0;
8057+
8058+
menu_st->driver_data->state_slot_run = slot;
8059+
8060+
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH;
8061+
menu_st->flags &= ~MENU_ST_FLAG_PREVENT_POPULATE;
8062+
8063+
action_ok_playlist_entry_collection(path, label, type, idx,
8064+
menu_st->driver_data->rpl_entry_selection_ptr);
8065+
return 0;
8066+
}
8067+
80468068
static int action_ok_load_archive(const char *path,
80478069
const char *label, unsigned type, size_t idx, size_t entry_idx)
80488070
{
@@ -9380,6 +9402,7 @@ static int menu_cbs_init_bind_ok_compare_label(menu_file_list_cbs_t *cbs,
93809402
{MENU_ENUM_LABEL_LOAD_DISC, action_ok_push_load_disc_list},
93819403
{MENU_ENUM_LABEL_SHADER_OPTIONS, action_ok_push_default},
93829404
{MENU_ENUM_LABEL_SAVESTATE_LIST, action_ok_push_savestate_list},
9405+
{MENU_ENUM_LABEL_STATE_SLOT_RUN, action_ok_push_state_slot_run},
93839406
{MENU_ENUM_LABEL_CORE_OPTIONS, action_ok_push_core_options_list},
93849407
{MENU_ENUM_LABEL_CORE_OPTION_OVERRIDE_LIST, action_ok_push_core_option_override_list},
93859408
{MENU_ENUM_LABEL_REMAP_FILE_MANAGER_LIST, action_ok_push_remap_file_manager_list},
@@ -10181,6 +10204,9 @@ static int menu_cbs_init_bind_ok_compare_type(menu_file_list_cbs_t *cbs,
1018110204
case MENU_SETTING_ACTION_CONTENTLESS_CORE_RUN:
1018210205
BIND_ACTION_OK(cbs, action_ok_contentless_core_run);
1018310206
break;
10207+
case MENU_SETTING_ACTION_STATE_SLOT_RUN:
10208+
BIND_ACTION_OK(cbs, action_ok_state_slot_run);
10209+
break;
1018410210
default:
1018510211
return -1;
1018610212
}

menu/cbs/menu_cbs_sublabel.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,16 +1955,6 @@ static int action_bind_sublabel_playlist_entry(
19551955
unsigned playlist_sublabel_runtime_type = settings->uints.playlist_sublabel_runtime_type;
19561956
bool content_runtime_log = settings->bools.content_runtime_log;
19571957
bool content_runtime_log_aggregate = settings->bools.content_runtime_log_aggregate;
1958-
const char *directory_runtime_log = settings->paths.directory_runtime_log;
1959-
const char *directory_playlist = settings->paths.directory_playlist;
1960-
enum playlist_sublabel_last_played_style_type
1961-
playlist_sublabel_last_played_style =
1962-
(enum playlist_sublabel_last_played_style_type)
1963-
settings->uints.playlist_sublabel_last_played_style;
1964-
enum playlist_sublabel_last_played_date_separator_type
1965-
menu_timedate_date_separator =
1966-
(enum playlist_sublabel_last_played_date_separator_type)
1967-
settings->uints.menu_timedate_date_separator;
19681958

19691959
if (!playlist_show_sublabels)
19701960
return 0;
@@ -2027,13 +2017,7 @@ static int action_bind_sublabel_playlist_entry(
20272017

20282018
/* Check whether runtime info should be loaded from log file */
20292019
if (entry->runtime_status == PLAYLIST_RUNTIME_UNKNOWN)
2030-
runtime_update_playlist(
2031-
playlist, playlist_index,
2032-
directory_runtime_log,
2033-
directory_playlist,
2034-
(playlist_sublabel_runtime_type == PLAYLIST_RUNTIME_PER_CORE),
2035-
playlist_sublabel_last_played_style,
2036-
menu_timedate_date_separator);
2020+
runtime_update_playlist(playlist, playlist_index);
20372021

20382022
/* Check whether runtime info is valid */
20392023
if (entry->runtime_status == PLAYLIST_RUNTIME_VALID)
@@ -3368,6 +3352,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
33683352
case MENU_ENUM_LABEL_SAVESTATE_LIST:
33693353
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_savestate_list);
33703354
break;
3355+
case MENU_ENUM_LABEL_STATE_SLOT_RUN:
3356+
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_load_state);
3357+
break;
33713358
case MENU_ENUM_LABEL_CORE_OPTIONS:
33723359
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_core_options);
33733360
break;

menu/cbs/menu_cbs_title.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ DEFAULT_TITLE_MACRO(action_get_configurations_list, MENU_ENUM_LABEL_
591591
DEFAULT_TITLE_MACRO(action_get_core_option_override_list, MENU_ENUM_LABEL_VALUE_CORE_OPTION_OVERRIDE_LIST)
592592
DEFAULT_TITLE_MACRO(action_get_quick_menu_list, MENU_ENUM_LABEL_VALUE_CONTENT_SETTINGS)
593593
DEFAULT_TITLE_MACRO(action_get_savestate_list, MENU_ENUM_LABEL_VALUE_SAVESTATE_LIST)
594+
DEFAULT_TITLE_MACRO(action_get_state_slot_run, MENU_ENUM_LABEL_VALUE_LOAD_STATE)
594595
DEFAULT_TITLE_MACRO(action_get_input_remapping_options_list, MENU_ENUM_LABEL_VALUE_CORE_INPUT_REMAPPING_OPTIONS)
595596
DEFAULT_TITLE_MACRO(action_get_remap_file_manager_list, MENU_ENUM_LABEL_VALUE_REMAP_FILE_MANAGER_LIST)
596597
DEFAULT_TITLE_MACRO(action_get_shader_options_list, MENU_ENUM_LABEL_VALUE_SHADER_OPTIONS)
@@ -1179,6 +1180,8 @@ static int menu_cbs_init_bind_title_compare_label(menu_file_list_cbs_t *cbs,
11791180
action_get_add_content_list},
11801181
{MENU_ENUM_LABEL_SAVESTATE_LIST,
11811182
action_get_savestate_list},
1183+
{MENU_ENUM_LABEL_STATE_SLOT_RUN,
1184+
action_get_state_slot_run},
11821185
{MENU_ENUM_LABEL_CORE_OPTIONS,
11831186
action_get_title_core_options_list},
11841187
{MENU_ENUM_LABEL_DEFERRED_CORE_OPTION_OVERRIDE_LIST,

menu/drivers/materialui.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,6 +2524,7 @@ static void materialui_update_savestate_thumbnail_path(void *data, unsigned i)
25242524
{
25252525
unsigned _state_slot = string_to_unsigned(entry.label);
25262526
if ( _state_slot == MENU_ENUM_LABEL_STATE_SLOT
2527+
|| string_is_equal(entry.label, MENU_ENUM_LABEL_STATE_SLOT_RUN_STR)
25272528
|| string_is_equal(entry.label, MENU_ENUM_LABEL_STATE_SLOT_STR)
25282529
|| string_is_equal(entry.label, MENU_ENUM_LABEL_LOAD_STATE_STR)
25292530
|| string_is_equal(entry.label, MENU_ENUM_LABEL_SAVE_STATE_STR))
@@ -2533,7 +2534,8 @@ static void materialui_update_savestate_thumbnail_path(void *data, unsigned i)
25332534
int state_slot = settings->ints.state_slot;
25342535

25352536
/* State slot dropdown */
2536-
if (_state_slot == MENU_ENUM_LABEL_STATE_SLOT)
2537+
if ( _state_slot == MENU_ENUM_LABEL_STATE_SLOT
2538+
|| string_is_equal(entry.label, MENU_ENUM_LABEL_STATE_SLOT_RUN_STR))
25372539
state_slot = i - 1;
25382540

25392541
gfx_savestate_thumbnail_get_path(path, sizeof(path),
@@ -3685,17 +3687,6 @@ static bool materialui_render_process_entry_playlist_desktop(
36853687
settings_t *settings = config_get_ptr();
36863688
bool content_runtime_log = settings->bools.content_runtime_log;
36873689
bool content_runtime_log_aggregate = settings->bools.content_runtime_log_aggregate;
3688-
const char *directory_runtime_log = settings->paths.directory_runtime_log;
3689-
const char *directory_playlist = settings->paths.directory_playlist;
3690-
unsigned runtime_type = settings->uints.playlist_sublabel_runtime_type;
3691-
enum playlist_sublabel_last_played_style_type
3692-
runtime_last_played_style =
3693-
(enum playlist_sublabel_last_played_style_type)
3694-
settings->uints.playlist_sublabel_last_played_style;
3695-
enum playlist_sublabel_last_played_date_separator_type
3696-
runtime_date_separator =
3697-
(enum playlist_sublabel_last_played_date_separator_type)
3698-
settings->uints.menu_timedate_date_separator;
36993690
float fade_duration = gfx_thumb_get_ptr()->fade_duration;
37003691
const struct playlist_entry *entry = NULL;
37013692
const char *core_name = NULL;
@@ -3729,13 +3720,7 @@ static bool materialui_render_process_entry_playlist_desktop(
37293720
if (content_runtime_log || content_runtime_log_aggregate)
37303721
{
37313722
if (entry->runtime_status == PLAYLIST_RUNTIME_UNKNOWN)
3732-
runtime_update_playlist(
3733-
mui->playlist, playlist_idx,
3734-
directory_runtime_log,
3735-
directory_playlist,
3736-
(runtime_type == PLAYLIST_RUNTIME_PER_CORE),
3737-
runtime_last_played_style,
3738-
runtime_date_separator);
3723+
runtime_update_playlist(mui->playlist, playlist_idx);
37393724

37403725
if (entry->runtime_str && *entry->runtime_str)
37413726
runtime_str = entry->runtime_str;
@@ -5901,7 +5886,6 @@ static bool materialui_is_savestate_list(materialui_handle_t *mui)
59015886
MENU_ENTRY_INITIALIZE(entry);
59025887
entry.flags |= MENU_ENTRY_FLAG_LABEL_ENABLED;
59035888
menu_entry_get(&entry, 0, menu_st->selection_ptr, NULL, true);
5904-
59055889
return
59065890
( string_is_equal(entry.label, MENU_ENUM_LABEL_STATE_SLOT_STR)
59075891
|| string_is_equal(entry.label, MENU_ENUM_LABEL_LOAD_STATE_STR)
@@ -5916,7 +5900,10 @@ static bool materialui_is_savestate_slot(materialui_handle_t *mui)
59165900
MENU_ENTRY_INITIALIZE(entry);
59175901
entry.flags |= MENU_ENTRY_FLAG_LABEL_ENABLED;
59185902
menu_entry_get(&entry, 0, menu_st->selection_ptr, NULL, true);
5919-
return string_to_unsigned(entry.label) == MENU_ENUM_LABEL_STATE_SLOT;
5903+
return
5904+
( string_to_unsigned(entry.label) == MENU_ENUM_LABEL_STATE_SLOT
5905+
|| string_is_equal(entry.label, MENU_ENUM_LABEL_STATE_SLOT_RUN_STR)
5906+
);
59205907
}
59215908

59225909
/* Used for savestate layout list displays.
@@ -9877,6 +9864,7 @@ static void materialui_populate_entries(void *data, const char *path,
98779864

98789865
if ( settings->bools.savestate_thumbnail_enable
98799866
&& ( string_is_equal(label, MENU_ENUM_LABEL_SAVESTATE_LIST_STR)
9867+
|| string_is_equal(label, MENU_ENUM_LABEL_STATE_SLOT_RUN_STR)
98809868
|| string_to_unsigned(path) == MENU_ENUM_LABEL_STATE_SLOT))
98819869
{
98829870
mui->flags |= MUI_FLAG_IS_SAVESTATE_LIST;
@@ -11780,6 +11768,7 @@ static void materialui_list_insert(void *userdata,
1178011768
node->icon_type = MUI_ICON_TYPE_INTERNAL;
1178111769
}
1178211770
else if ( string_is_equal(label, MENU_ENUM_LABEL_LOAD_STATE_STR)
11771+
|| (string_is_equal(label, MENU_ENUM_LABEL_STATE_SLOT_RUN_STR) && type != MENU_SETTING_ACTION_STATE_SLOT_RUN)
1178311772
|| string_is_equal(label, MENU_ENUM_LABEL_OVERRIDE_FILE_LOAD_STR)
1178411773
|| string_is_equal(label, MENU_ENUM_LABEL_CHEAT_FILE_LOAD_STR)
1178511774
|| string_is_equal(label, MENU_ENUM_LABEL_CHEAT_FILE_LOAD_APPEND_STR)

0 commit comments

Comments
 (0)