diff options
author | Michael Pavone <pavone@retrodev.com> | 2020-11-09 00:29:47 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2020-11-09 00:29:47 -0800 |
commit | 4ddbae8255a0f223846c86b41d8b4e4cdcc1d8e2 (patch) | |
tree | 9013ab6232989a3cb8861209e46bbf6a26c6ffa1 | |
parent | 73a30109f67c3d168684ab26f10e9f51df676528 (diff) |
Add a UI button to reset config to defaults
-rw-r--r-- | config.c | 15 | ||||
-rw-r--r-- | config.h | 2 | ||||
-rw-r--r-- | controller_info.c | 9 | ||||
-rw-r--r-- | controller_info.h | 1 | ||||
-rw-r--r-- | nuklear_ui/blastem_nuklear.c | 24 | ||||
-rw-r--r-- | render.h | 1 | ||||
-rwxr-xr-x | render_sdl.c | 13 | ||||
-rw-r--r-- | tern.c | 9 |
8 files changed, 69 insertions, 5 deletions
@@ -298,6 +298,21 @@ void persist_config(tern_node *config) persist_config_at(config, config, "blastem.cfg"); } +void delete_custom_config_at(char *fname) +{ + char *confpath = path_append(get_exe_dir(), fname); + delete_file(confpath); + free(confpath); + confpath = path_append(get_config_dir(), fname); + delete_file(confpath); + free(confpath); +} + +void delete_custom_config(void) +{ + delete_custom_config_at("blastem.cfg"); +} + char **get_extension_list(tern_node *config, uint32_t *num_exts_out) { char *ext_filter = strdup(tern_find_path_default(config, "ui\0extensions\0", (tern_val){.ptrval = "bin gen md smd sms gg"}, TVAL_PTR).ptrval); @@ -16,6 +16,8 @@ char *serialize_config(tern_node *config, uint32_t *size_out); uint8_t serialize_config_file(tern_node *config, char *path); void persist_config_at(tern_node *app_config, tern_node *to_save, char *fname); void persist_config(tern_node *config); +void delete_custom_config_at(char *fname); +void delete_custom_config(void); char **get_extension_list(tern_node *config, uint32_t *num_exts_out); uint32_t get_lowpass_cutoff(tern_node *config); tern_node *get_systems_config(void); diff --git a/controller_info.c b/controller_info.c index 9fef8dd..af3469b 100644 --- a/controller_info.c +++ b/controller_info.c @@ -224,6 +224,15 @@ void save_controller_mapping(int joystick, char *mapping_string) #endif } +void delete_controller_info(void) +{ + delete_custom_config_at("controller_types.cfg"); + loaded = 0; + tern_free(info_config); + info_config = NULL; + render_reset_mappings(); +} + char const *labels_xbox[] = { "A", "B", "X", "Y", "Back", NULL, "Start", "Click", "Click", "White", "Black", "LT", "RT" }; diff --git a/controller_info.h b/controller_info.h index db1f6ec..eb4badb 100644 --- a/controller_info.h +++ b/controller_info.h @@ -47,6 +47,7 @@ const char *get_button_label(controller_info *info, int button); const char *get_axis_label(controller_info *info, int axis); void save_controller_info(int joystick, controller_info *info); void save_controller_mapping(int joystick, char *mapping_string); +void delete_controller_info(void); void controller_add_mappings(void); char *make_controller_type_key(controller_info *info); char *make_human_readable_type_name(controller_info *info); diff --git a/nuklear_ui/blastem_nuklear.c b/nuklear_ui/blastem_nuklear.c index 6e0db4d..dcb5ec5 100644 --- a/nuklear_ui/blastem_nuklear.c +++ b/nuklear_ui/blastem_nuklear.c @@ -2023,6 +2023,29 @@ void view_system_settings(struct nk_context *context) } } +void view_confirm_reset(struct nk_context *context) +{ + if (nk_begin(context, "Reset Confirm", nk_rect(0, 0, render_width(), render_height()), 0)) { + uint32_t desired_width = context->style.font->height * 20; + nk_layout_row_static(context, context->style.font->height, desired_width, 1); + nk_label(context, "This will reset all settings and controller", NK_TEXT_LEFT); + nk_label(context, "mappings back to the defaults.", NK_TEXT_LEFT); + nk_label(context, "Are you sure you want to proceed?", NK_TEXT_LEFT); + nk_layout_row_static(context, context->style.font->height * 1.5, desired_width / 2, 2); + if (nk_button_label(context, "Maybe not")) { + pop_view(); + } + if (nk_button_label(context, "Yep, delete it all")) { + delete_custom_config(); + config = load_config(); + delete_controller_info(); + config_dirty = 1; + pop_view(); + } + nk_end(context); + } +} + void view_back(struct nk_context *context) { pop_view(); @@ -2038,6 +2061,7 @@ void view_settings(struct nk_context *context) {"Video", view_video_settings}, {"Audio", view_audio_settings}, {"System", view_system_settings}, + {"Reset to Defaults", view_confirm_reset}, {"Back", view_back} }; @@ -140,6 +140,7 @@ void render_set_ui_fb_resize_handler(ui_render_fun resize); void render_video_loop(void); uint8_t render_should_release_on_exit(void); void render_set_external_sync(uint8_t ext_sync_on); +void render_reset_mappings(void); #ifndef IS_LIB uint8_t render_create_thread(render_thread *thread, const char *name, render_thread_fun fun, void *data); #endif diff --git a/render_sdl.c b/render_sdl.c index 81c2675..4099d5d 100755 --- a/render_sdl.c +++ b/render_sdl.c @@ -1203,6 +1203,19 @@ void render_init(int width, int height, char * title, uint8_t fullscreen) atexit(render_quit); } + +void render_reset_mappings(void) +{ + SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); + SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER); + uint32_t db_size; + char *db_data = read_bundled_file("gamecontrollerdb.txt", &db_size); + if (db_data) { + int added = SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(db_data, db_size), 1); + free(db_data); + debug_message("Added %d game controller mappings from gamecontrollerdb.txt\n", added); + } +} static int in_toggle; void render_config_updated(void) @@ -305,12 +305,11 @@ char * tern_int_key(uint32_t key, char * buf) void tern_free(tern_node *head) { - if (head->left) { - tern_free(head->left); - } - if (head->right) { - tern_free(head->right); + if (!head) { + return; } + tern_free(head->left); + tern_free(head->right); if (head->el) { tern_free(head->straight.next); } |