From bd821bf493d90b55f8f7312c5728436a31af62c2 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sun, 7 Jul 2024 18:30:25 +0100 Subject: [PATCH] Settings context menu (#116) ## Description Adds ability to set the config.ini settings from the menu. ## Motivation and Context Ability to set the settings was missing from the menu. ## How Has This Been Tested? Tested on an SC64. ## Screenshots ![image](https://github.com/Polprzewodnikowy/N64FlashcartMenu/assets/11439699/6ca39679-d997-4f6c-a670-55d2334814ce) ## Types of changes - [x] Improvement (non-breaking change that adds a new feature) - [ ] Bug fix (fixes an issue) - [ ] Breaking change (breaking change) - [ ] Config and build (change in the configuration and build system, has no impact on code or features) ## Checklist: - [ ] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. Signed-off-by: GITHUB_USER --- libdragon | 2 +- src/menu/views/rtc.c | 2 +- src/menu/views/settings_editor.c | 146 +++++++++++++++++++++++++++---- 3 files changed, 131 insertions(+), 19 deletions(-) diff --git a/libdragon b/libdragon index 536df10a..4d4449aa 160000 --- a/libdragon +++ b/libdragon @@ -1 +1 @@ -Subproject commit 536df10ad65614f519bea40482b6e2657b9c4c84 +Subproject commit 4d4449aac2af2ba8306cd4e61974ac682f1ea400 diff --git a/src/menu/views/rtc.c b/src/menu/views/rtc.c index d810f382..ae56fd8b 100644 --- a/src/menu/views/rtc.c +++ b/src/menu/views/rtc.c @@ -36,7 +36,7 @@ static void draw (menu_t *menu, surface_t *d) { "\n" "\n" "To set the date and time, please use the PC terminal\n" - "application and set via USB.\n\n" + "application and set via USB or a game that uses it.\n\n" "Current date & time: %s\n", menu->current_time >= 0 ? ctime(&menu->current_time) : "Unknown\n" ); diff --git a/src/menu/views/settings_editor.c b/src/menu/views/settings_editor.c index badb3696..4dc2539c 100644 --- a/src/menu/views/settings_editor.c +++ b/src/menu/views/settings_editor.c @@ -1,4 +1,6 @@ +#include #include "../sound.h" +#include "../settings.h" #include "views.h" @@ -9,9 +11,108 @@ static const char *format_switch (bool state) { } } +static void set_pal60_type (menu_t *menu, void *arg) { + menu->settings.pal60_enabled = (bool) (arg); + settings_save(&menu->settings); +} + +static void set_protected_entries_type (menu_t *menu, void *arg) { + menu->settings.show_protected_entries = (bool) (arg); + settings_save(&menu->settings); + + menu->browser.reload = true; +} + +static void set_use_saves_folder_type (menu_t *menu, void *arg) { + menu->settings.use_saves_folder = (bool) (arg); + settings_save(&menu->settings); +} + +static void set_sound_enabled_type (menu_t *menu, void *arg) { + menu->settings.sound_enabled = (bool) (arg); + settings_save(&menu->settings); +} + +#ifdef BETA_SETTINGS +static void set_bgm_enabled_type (menu_t *menu, void *arg) { + menu->settings.bgm_enabled = (bool) (arg); + settings_save(&menu->settings); +} + +static void set_rumble_enabled_type (menu_t *menu, void *arg) { + menu->settings.rumble_enabled = (bool) (arg); + settings_save(&menu->settings); +} + +// static void set_use_default_settings (menu_t *menu, void *arg) { +// // FIXME: add implementation +// menu->browser.reload = true; +// } +#endif + + +static component_context_menu_t set_pal60_type_context_menu = { .list = { + {.text = "On", .action = set_pal60_type, .arg = (void *) (true) }, + {.text = "Off", .action = set_pal60_type, .arg = (void *) (false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + +static component_context_menu_t set_protected_entries_type_context_menu = { .list = { + {.text = "On", .action = set_protected_entries_type, .arg = (void *) (true) }, + {.text = "Off", .action = set_protected_entries_type, .arg = (void *) (false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + +static component_context_menu_t set_sound_enabled_type_context_menu = { .list = { + {.text = "On", .action = set_sound_enabled_type, .arg = (void *) (true) }, + {.text = "Off", .action = set_sound_enabled_type, .arg = (void *) (false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + +static component_context_menu_t set_use_saves_folder_type_context_menu = { .list = { + {.text = "On", .action = set_use_saves_folder_type, .arg = (void *) (true) }, + {.text = "Off", .action = set_use_saves_folder_type, .arg = (void *) (false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + +#ifdef BETA_SETTINGS +static component_context_menu_t set_bgm_enabled_type_context_menu = { .list = { + {.text = "On", .action = set_bgm_enabled_type, .arg = (void *) (true) }, + {.text = "Off", .action = set_bgm_enabled_type, .arg = (void *) (false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + +static component_context_menu_t set_rumble_enabled_type_context_menu = { .list = { + {.text = "On", .action = set_rumble_enabled_type, .arg = (void *) (true) }, + {.text = "Off", .action = set_rumble_enabled_type, .arg = (void *) (false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; +#endif + +static component_context_menu_t options_context_menu = { .list = { + { .text = "PAL60 Mode", .submenu = &set_pal60_type_context_menu }, + { .text = "Show Hidden Files", .submenu = &set_protected_entries_type_context_menu }, + { .text = "Sound Effects", .submenu = &set_sound_enabled_type_context_menu }, + { .text = "Use Saves Folder", .submenu = &set_use_saves_folder_type_context_menu }, +#ifdef BETA_SETTINGS + { .text = "Background Music", .submenu = &set_bgm_enabled_type_context_menu }, + { .text = "Rumble Feedback", .submenu = &set_rumble_enabled_type_context_menu }, + // { .text = "Restore Defaults", .action = set_use_default_settings }, +#endif + + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + static void process (menu_t *menu) { - if (menu->actions.back) { + if (component_context_menu_process(menu, &options_context_menu)) { + return; + } + + if (menu->actions.enter) { + component_context_menu_show(&options_context_menu); + sound_play_effect(SFX_SETTING); + } else if (menu->actions.back) { menu->next_mode = MENU_MODE_BROWSER; sound_play_effect(SFX_EXIT); } @@ -26,44 +127,55 @@ static void draw (menu_t *menu, surface_t *d) { component_main_text_draw( ALIGN_CENTER, VALIGN_TOP, - "SETTINGS EDITOR\n" + "MENU SETTINGS EDITOR\n" "\n" ); component_main_text_draw( ALIGN_LEFT, VALIGN_TOP, - "\n" - "\n" - "To change the settings, please adjust them\n" - "directly in the 'menu/config.ini' file.\n\n" - "pal60_enabled: %s\n" - "show_protected_entries: %s\n" - "default_directory: %s\n" - "use_saves_folder: %s\n" - "bgm_enabled: %s\n" - "sound_enabled: %s\n" - "rumble_enabled: %s\n", + "\n\n" + " Default Directory : %s\n\n" + "To change the menu settings, press 'A'.\n\n" + " PAL60 Mode : %s\n" + " Show Hidden Files : %s\n" + " Use Saves folder : %s\n" + "* Sound Effects : %s\n" +#ifdef BETA_SETTINGS + " Background Music : %s\n" + " Rumble Feedback : %s\n" +#endif + "\n\n" + "Note: Certain settings have the following caveats:\n\n" + "* Requires a flashcart reboot.\n", + menu->settings.default_directory, format_switch(menu->settings.pal60_enabled), format_switch(menu->settings.show_protected_entries), - menu->settings.default_directory, format_switch(menu->settings.use_saves_folder), + format_switch(menu->settings.sound_enabled) +#ifdef BETA_SETTINGS + , format_switch(menu->settings.bgm_enabled), - format_switch(menu->settings.sound_enabled), format_switch(menu->settings.rumble_enabled) +#endif ); + component_actions_bar_text_draw( ALIGN_LEFT, VALIGN_TOP, - "\n" + "A: Change\n" "B: Back" ); + component_context_menu_draw(&options_context_menu); + rdpq_detach_show(); } void view_settings_init (menu_t *menu) { - // Nothing to initialize (yet) + + component_context_menu_init(&options_context_menu); + } void view_settings_display (menu_t *menu, surface_t *display) {