Skip to content

Commit

Permalink
Random selector Explore View fix (#17518)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonninnos authored Feb 4, 2025
1 parent ea22c7c commit 94d5223
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 91 deletions.
24 changes: 1 addition & 23 deletions menu/drivers/materialui.c
Original file line number Diff line number Diff line change
Expand Up @@ -9352,29 +9352,7 @@ static enum menu_action materialui_parse_menu_entry_action(
else if ((mui->flags & MUI_FLAG_IS_PLAYLIST)
|| (mui->flags & MUI_FLAG_IS_EXPLORE_LIST))
{
struct menu_state *menu_st = menu_state_get_ptr();
size_t selection_start = 0;
size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0;
size_t selection = menu_st->selection_ptr;
size_t new_selection = selection;

/* Skip header items (Search Name + Add Additional Filter + Save as View) */
if (mui->flags & MUI_FLAG_IS_EXPLORE_LIST)
{
menu_entry_t entry;
MENU_ENTRY_INITIALIZE(entry);
menu_entry_get(&entry, 0, 0, NULL, true);

if (entry.type == MENU_SETTINGS_LAST + 1)
selection_start = 1;
else if (entry.type == FILE_TYPE_RDB)
selection_start = 2;
}

new_selection = random_range(selection_start, selection_total - 1);

while (new_selection == selection && selection_start != selection_total - 1)
new_selection = random_range(selection_start, selection_total - 1);
size_t new_selection = menu_playlist_random_selection(selection, mui->flags & MUI_FLAG_IS_EXPLORE_LIST);

if (new_selection != selection)
{
Expand Down
24 changes: 3 additions & 21 deletions menu/drivers/ozone.c
Original file line number Diff line number Diff line change
Expand Up @@ -8218,27 +8218,9 @@ static enum menu_action ozone_parse_menu_entry_action(
else if ((ozone->flags & OZONE_FLAG_IS_PLAYLIST)
|| (ozone->flags & OZONE_FLAG_IS_EXPLORE_LIST))
{
size_t selection_start = 0;
size_t new_selection = menu_playlist_random_selection(selection, ozone->flags & OZONE_FLAG_IS_EXPLORE_LIST);

/* Skip header items (Search Name + Add Additional Filter + Save as View) */
if (ozone->flags & OZONE_FLAG_IS_EXPLORE_LIST)
{
menu_entry_t entry;
MENU_ENTRY_INITIALIZE(entry);
menu_entry_get(&entry, 0, 0, NULL, true);

if (entry.type == MENU_SETTINGS_LAST + 1)
selection_start = 1;
else if (entry.type == FILE_TYPE_RDB)
selection_start = 2;
}

new_selection = random_range(selection_start, selection_total - 1);

while (new_selection == (int)selection && selection_start != selection_total - 1)
new_selection = random_range(selection_start, selection_total - 1);

if (new_selection != (int)selection)
if (new_selection != selection)
{
menu_st->selection_ptr = new_selection;
ozone_selection_changed(ozone, false);
Expand All @@ -8248,7 +8230,7 @@ static enum menu_action ozone_parse_menu_entry_action(
new_action = MENU_ACTION_NOOP;

#ifdef HAVE_AUDIOMIXER
if (new_selection != (int)selection)
if (new_selection != selection)
audio_driver_mixer_play_scroll_sound(true);
#endif
break;
Expand Down
28 changes: 3 additions & 25 deletions menu/drivers/rgui.c
Original file line number Diff line number Diff line change
Expand Up @@ -7989,6 +7989,7 @@ static enum menu_action rgui_parse_menu_entry_action(
menu_entry_t *entry,
enum menu_action action)
{
struct menu_state *menu_st = menu_state_get_ptr();
enum menu_action new_action = action;

/* Scan user inputs */
Expand Down Expand Up @@ -8056,7 +8057,6 @@ static enum menu_action rgui_parse_menu_entry_action(

if (string_is_equal(rgui->menu_title, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_MAIN_MENU)))
{
struct menu_state *menu_st = menu_state_get_ptr();
/* Jump to first item on Main Menu */
menu_st->selection_ptr = 0;
new_action = MENU_ACTION_NOOP;
Expand Down Expand Up @@ -8112,7 +8112,6 @@ static enum menu_action rgui_parse_menu_entry_action(
case MENU_ACTION_SCAN:
if (rgui->flags & RGUI_FLAG_IS_PLAYLISTS_TAB)
{
struct menu_state *menu_st = menu_state_get_ptr();
size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0;
size_t selection = menu_st->selection_ptr;
size_t new_selection = random_range(0, selection_total - 1);
Expand Down Expand Up @@ -8145,29 +8144,8 @@ static enum menu_action rgui_parse_menu_entry_action(
else if ((rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|| (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST))
{
struct menu_state *menu_st = menu_state_get_ptr();
size_t selection_start = 0;
size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0;
size_t selection = menu_st->selection_ptr;
size_t new_selection = selection;

/* Skip header items (Search Name + Add Additional Filter + Save as View) */
if (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)
{
menu_entry_t entry;
MENU_ENTRY_INITIALIZE(entry);
menu_entry_get(&entry, 0, 0, NULL, true);

if (entry.type == MENU_SETTINGS_LAST + 1)
selection_start = 1;
else if (entry.type == FILE_TYPE_RDB)
selection_start = 2;
}

new_selection = random_range(selection_start, selection_total - 1);

while (new_selection == selection && selection_start != selection_total - 1)
new_selection = random_range(selection_start, selection_total - 1);
size_t selection = menu_st->selection_ptr;
size_t new_selection = menu_playlist_random_selection(selection, rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST);

if (new_selection != selection)
{
Expand Down
24 changes: 2 additions & 22 deletions menu/drivers/xmb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5591,28 +5591,8 @@ static enum menu_action xmb_parse_menu_entry_action(
else if ((xmb->is_playlist)
|| (xmb->is_explore_list))
{
size_t selection_start = 0;
size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0;
size_t selection = menu_st->selection_ptr;
size_t new_selection = selection;

/* Skip header items (Search Name + Add Additional Filter + Save as View) */
if (xmb->is_explore_list)
{
menu_entry_t entry;
MENU_ENTRY_INITIALIZE(entry);
menu_entry_get(&entry, 0, 0, NULL, true);

if (entry.type == MENU_SETTINGS_LAST + 1)
selection_start = 1;
else if (entry.type == FILE_TYPE_RDB)
selection_start = 2;
}

new_selection = random_range(selection_start, selection_total - 1);

while (new_selection == selection && selection_start != selection_total - 1)
new_selection = random_range(selection_start, selection_total - 1);
size_t selection = menu_st->selection_ptr;
size_t new_selection = menu_playlist_random_selection(selection, xmb->is_explore_list);

if (new_selection != selection)
{
Expand Down
30 changes: 30 additions & 0 deletions menu/menu_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#endif

#include <retro_timers.h>
#include <retro_math.h>
#include <file/file_path.h>
#include <lists/dir_list.h>
#include <string/stdstring.h>
Expand Down Expand Up @@ -8106,3 +8107,32 @@ void menu_update_runahead_mode(void)
menu_st->runahead_mode = MENU_RUNAHEAD_MODE_OFF;
}
#endif

/* Common method for ignoring specifics while picking random playlist items. */
size_t menu_playlist_random_selection(size_t selection, bool is_explore_list)
{
struct menu_state *menu_st = menu_state_get_ptr();
size_t selection_start = 0;
size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0;
size_t new_selection = selection;

/* Skip header items (Search Name + Add Additional Filter + Save as View + Delete this View) */
if (is_explore_list)
{
menu_entry_t entry;
MENU_ENTRY_INITIALIZE(entry);
menu_entry_get(&entry, 0, 0, NULL, true);

if (entry.type == MENU_SETTINGS_LAST + 1 || entry.type == FILE_TYPE_PLAIN)
selection_start = 1;
else if (entry.type == FILE_TYPE_RDB)
selection_start = 2;
}

new_selection = random_range(selection_start, selection_total - 1);

while (new_selection == selection && selection_start != selection_total - 1)
new_selection = random_range(selection_start, selection_total - 1);

return new_selection;
}
3 changes: 3 additions & 0 deletions menu/menu_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,9 @@ bool menu_input_key_bind_set_mode(
void menu_update_runahead_mode(void);
#endif

size_t menu_playlist_random_selection(
size_t selection, bool is_explore_list);

extern const menu_ctx_driver_t *menu_ctx_drivers[];

extern menu_ctx_driver_t menu_ctx_ozone;
Expand Down

0 comments on commit 94d5223

Please sign in to comment.