Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings context menu #116

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/menu/views/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
Expand Down
136 changes: 119 additions & 17 deletions src/menu/views/settings_editor.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <stdbool.h>
#include "../sound.h"
#include "../settings.h"
#include "views.h"


Expand All @@ -9,9 +11,102 @@ 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;
networkfusion marked this conversation as resolved.
Show resolved Hide resolved
}

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_bgm_enabled_type (menu_t *menu, void *arg) {
menu->settings.bgm_enabled = (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);
}

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;
// }


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,
}};

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,
}};

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 = "Background Music", .submenu = &set_bgm_enabled_type_context_menu },
{ .text = "Rumble Feedback", .submenu = &set_rumble_enabled_type_context_menu },
{ .text = "Use Saves Folder", .submenu = &set_use_saves_folder_type_context_menu },
// { .text = "Restore Defaults", .action = set_use_default_settings },

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);
}
Expand All @@ -26,44 +121,51 @@ 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"
"To change the menu settings, press 'A'.\n\n"
"* Default Directory : %s\n"
" PAL60 Mode : %s\n"
" Show Hidden Files : %s\n"
" Use Saves folder : %s\n"
"** Sound Effects : %s\n"
"*** Background Music : %s\n"
"*** Rumble Feedback : %s\n\n\n"
networkfusion marked this conversation as resolved.
Show resolved Hide resolved
"Note: Certain settings have the following caveats:\n\n"
"* Settable from file browser options.\n"
"** Requires a flashcart reboot.\n"
"*** Not currently supported.\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.bgm_enabled),
format_switch(menu->settings.sound_enabled),
format_switch(menu->settings.bgm_enabled),
format_switch(menu->settings.rumble_enabled)
);


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) {
Expand Down