Mercurial > repos > blastem
comparison nuklear_ui/blastem_nuklear.c @ 2041:638eb2d25696 mame_interp
Merge from default
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 05 Aug 2021 09:29:33 -0700 |
parents | 380bc5d4a2cf |
children | 237068a25523 |
comparison
equal
deleted
inserted
replaced
1984:0d5f88e53dca | 2041:638eb2d25696 |
---|---|
29 uint32_t *image_data; | 29 uint32_t *image_data; |
30 uint32_t width, height; | 30 uint32_t width, height; |
31 struct nk_image ui; | 31 struct nk_image ui; |
32 } ui_image; | 32 } ui_image; |
33 | 33 |
34 static ui_image **ui_images, *controller_360, *controller_ps4, *controller_ps4_6b; | 34 static ui_image **ui_images, *controller_360, *controller_ps4, |
35 *controller_ps4_6b, *controller_wiiu, *controller_gen_6b; | |
35 static uint32_t num_ui_images, ui_image_storage; | 36 static uint32_t num_ui_images, ui_image_storage; |
36 | 37 |
37 typedef void (*view_fun)(struct nk_context *); | 38 typedef void (*view_fun)(struct nk_context *); |
38 static view_fun current_view; | 39 static view_fun current_view; |
39 static view_fun *previous_views; | 40 static view_fun *previous_views; |
86 if (!entries) { | 87 if (!entries) { |
87 entries = get_dir_list(current_path, &num_entries); | 88 entries = get_dir_list(current_path, &num_entries); |
88 if (entries) { | 89 if (entries) { |
89 sort_dir_list(entries, num_entries); | 90 sort_dir_list(entries, num_entries); |
90 } | 91 } |
92 if (!num_entries) { | |
93 //get_dir_list can fail if the user doesn't have permission | |
94 //for the current folder, make sure they can still navigate up | |
95 free_dir_list(entries, num_entries); | |
96 entries = calloc(1, sizeof(dir_entry)); | |
97 entries[0].name = strdup(".."); | |
98 entries[0].is_dir = 1; | |
99 num_entries = 1; | |
100 } | |
91 } | 101 } |
92 if (!got_ext_list) { | 102 if (!got_ext_list) { |
93 ext_list = get_extension_list(config, &num_exts); | 103 ext_list = get_extension_list(config, &num_exts); |
94 got_ext_list = 1; | 104 got_ext_list = 1; |
95 } | 105 } |
96 uint32_t width = render_width(); | 106 uint32_t width = render_width(); |
97 uint32_t height = render_height(); | 107 uint32_t height = render_height(); |
98 if (nk_begin(context, "Load ROM", nk_rect(0, 0, width, height), 0)) { | 108 if (nk_begin(context, "Load ROM", nk_rect(0, 0, width, height), 0)) { |
99 nk_layout_row_static(context, height - context->style.font->height * 3, width - 60, 1); | 109 nk_layout_row_static(context, height - context->style.font->height * 3, width - 60, 1); |
100 int32_t old_selected = selected_entry; | 110 int32_t old_selected = selected_entry; |
101 if (nk_group_begin(context, "Select ROM", NK_WINDOW_BORDER | NK_WINDOW_TITLE)) { | 111 char *title = alloc_concat("Select ROM: ", current_path); |
112 if (nk_group_begin(context, title, NK_WINDOW_BORDER | NK_WINDOW_TITLE)) { | |
102 nk_layout_row_static(context, context->style.font->height - 2, width-100, 1); | 113 nk_layout_row_static(context, context->style.font->height - 2, width-100, 1); |
103 for (int32_t i = 0; i < num_entries; i++) | 114 for (int32_t i = 0; i < num_entries; i++) |
104 { | 115 { |
105 if (entries[i].name[0] == '.' && entries[i].name[1] != '.') { | 116 if (entries[i].name[0] == '.' && entries[i].name[1] != '.') { |
106 continue; | 117 continue; |
116 selected_entry = -1; | 127 selected_entry = -1; |
117 } | 128 } |
118 } | 129 } |
119 nk_group_end(context); | 130 nk_group_end(context); |
120 } | 131 } |
132 free(title); | |
121 nk_layout_row_static(context, context->style.font->height * 1.75, width > 600 ? 300 : width / 2, 2); | 133 nk_layout_row_static(context, context->style.font->height * 1.75, width > 600 ? 300 : width / 2, 2); |
122 if (nk_button_label(context, "Back")) { | 134 if (nk_button_label(context, "Back")) { |
123 pop_view(); | 135 pop_view(); |
124 } | 136 } |
125 if (nk_button_label(context, "Open") || (old_selected >= 0 && selected_entry < 0)) { | 137 if (nk_button_label(context, "Open") || (old_selected >= 0 && selected_entry < 0)) { |
975 free((char *)options[SIMILAR_CONTROLLERS].title); | 987 free((char *)options[SIMILAR_CONTROLLERS].title); |
976 } | 988 } |
977 | 989 |
978 static ui_image *select_best_image(controller_info *info) | 990 static ui_image *select_best_image(controller_info *info) |
979 { | 991 { |
980 if (info->variant != VARIANT_NORMAL) { | 992 if (info->variant != VARIANT_NORMAL || info->type == TYPE_SEGA) { |
981 return controller_ps4_6b; | 993 if (info->type == TYPE_PSX) { |
994 return controller_ps4_6b; | |
995 } else { | |
996 return controller_gen_6b; | |
997 } | |
982 } else if (info->type == TYPE_PSX) { | 998 } else if (info->type == TYPE_PSX) { |
983 return controller_ps4; | 999 return controller_ps4; |
1000 } else if (info->type == TYPE_NINTENDO) { | |
1001 return controller_wiiu; | |
984 } else { | 1002 } else { |
985 return controller_360; | 1003 return controller_360; |
986 } | 1004 } |
987 } | 1005 } |
988 | 1006 |
1241 axis_value/abs(axis_value) != last_axis_value/abs(axis_value) && current_button >= SDL_CONTROLLER_BUTTON_DPAD_UP | 1259 axis_value/abs(axis_value) != last_axis_value/abs(axis_value) && current_button >= SDL_CONTROLLER_BUTTON_DPAD_UP |
1242 ) | 1260 ) |
1243 )) { | 1261 )) { |
1244 if (current_button <= SDL_CONTROLLER_BUTTON_B || axis_moved != button_a_axis) { | 1262 if (current_button <= SDL_CONTROLLER_BUTTON_B || axis_moved != button_a_axis) { |
1245 start_mapping(); | 1263 start_mapping(); |
1264 if (current_button >= SDL_CONTROLLER_BUTTON_DPAD_UP) { | |
1265 mapping_string[mapping_pos++] = axis_value >= 0 ? '+' : '-'; | |
1266 } | |
1246 mapping_string[mapping_pos++] = 'a'; | 1267 mapping_string[mapping_pos++] = 'a'; |
1247 if (axis_moved > 9) { | 1268 if (axis_moved > 9) { |
1248 mapping_string[mapping_pos++] = '0' + axis_moved / 10; | 1269 mapping_string[mapping_pos++] = '0' + axis_moved / 10; |
1249 } | 1270 } |
1250 mapping_string[mapping_pos++] = '0' + axis_moved % 10; | 1271 mapping_string[mapping_pos++] = '0' + axis_moved % 10; |
1251 if (current_button >= SDL_CONTROLLER_BUTTON_DPAD_UP) { | |
1252 mapping_string[mapping_pos++] = axis_value >= 0 ? '+' : '-'; | |
1253 } | |
1254 last_axis = axis_moved; | 1272 last_axis = axis_moved; |
1255 last_axis_value = axis_value; | 1273 last_axis_value = axis_value; |
1256 } | 1274 } |
1257 added_mapping = 1; | 1275 added_mapping = 1; |
1258 } | 1276 } |
1328 nk_layout_row_static(context, context->style.font->height*1.25, render_width() - context->style.font->height * 2, 1); | 1346 nk_layout_row_static(context, context->style.font->height*1.25, render_width() - context->style.font->height * 2, 1); |
1329 nk_label(context, "", NK_TEXT_CENTERED); | 1347 nk_label(context, "", NK_TEXT_CENTERED); |
1330 nk_label(context, "Select the layout that", NK_TEXT_CENTERED); | 1348 nk_label(context, "Select the layout that", NK_TEXT_CENTERED); |
1331 nk_label(context, "best matches your controller", NK_TEXT_CENTERED); | 1349 nk_label(context, "best matches your controller", NK_TEXT_CENTERED); |
1332 nk_label(context, "", NK_TEXT_CENTERED); | 1350 nk_label(context, "", NK_TEXT_CENTERED); |
1333 if (nk_button_label(context, "4 face buttons")) { | 1351 if (selected_controller_info.subtype == SUBTYPE_GENESIS) { |
1334 selected_controller_info.variant = VARIANT_NORMAL; | 1352 if (nk_button_label(context, "3 button")) { |
1335 selected = 1; | 1353 selected_controller_info.variant = VARIANT_3BUTTON; |
1336 } | 1354 selected = 1; |
1337 char buffer[512]; | 1355 } |
1338 snprintf(buffer, sizeof(buffer), "6 face buttons including %s and %s", | 1356 if (nk_button_label(context, "Standard 6 button")) { |
1339 get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), | 1357 selected_controller_info.variant = VARIANT_6B_BUMPERS; |
1340 get_axis_label(&selected_controller_info, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) | 1358 selected = 1; |
1341 ); | 1359 } |
1342 if (nk_button_label(context, buffer)) { | 1360 if (nk_button_label(context, "6 button with 2 shoulder buttons")) { |
1343 selected_controller_info.variant = VARIANT_6B_RIGHT; | 1361 selected_controller_info.variant = VARIANT_8BUTTON; |
1344 selected = 1; | 1362 selected = 1; |
1345 } | 1363 } |
1346 snprintf(buffer, sizeof(buffer), "6 face buttons including %s and %s", | 1364 } else { |
1347 get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_LEFTSHOULDER), | 1365 if (nk_button_label(context, "4 face buttons")) { |
1348 get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) | 1366 selected_controller_info.variant = VARIANT_NORMAL; |
1349 ); | 1367 selected = 1; |
1350 if (nk_button_label(context, buffer)) { | 1368 } |
1351 selected_controller_info.variant = VARIANT_6B_BUMPERS; | 1369 char buffer[512]; |
1352 selected = 1; | 1370 snprintf(buffer, sizeof(buffer), "6 face buttons including %s and %s", |
1371 get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), | |
1372 get_axis_label(&selected_controller_info, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) | |
1373 ); | |
1374 if (nk_button_label(context, buffer)) { | |
1375 selected_controller_info.variant = VARIANT_6B_RIGHT; | |
1376 selected = 1; | |
1377 } | |
1378 snprintf(buffer, sizeof(buffer), "6 face buttons including %s and %s", | |
1379 get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_LEFTSHOULDER), | |
1380 get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) | |
1381 ); | |
1382 if (nk_button_label(context, buffer)) { | |
1383 selected_controller_info.variant = VARIANT_6B_BUMPERS; | |
1384 selected = 1; | |
1385 } | |
1353 } | 1386 } |
1354 nk_end(context); | 1387 nk_end(context); |
1355 } | 1388 } |
1356 if (selected) { | 1389 if (selected) { |
1357 save_controller_info(selected_controller, &selected_controller_info); | 1390 save_controller_info(selected_controller, &selected_controller_info); |
1378 { | 1411 { |
1379 if (nk_button_label(context, types[i])) { | 1412 if (nk_button_label(context, types[i])) { |
1380 selected_controller_info.type = type_id; | 1413 selected_controller_info.type = type_id; |
1381 selected_controller_info.subtype = first_subtype_id + i; | 1414 selected_controller_info.subtype = first_subtype_id + i; |
1382 pop_view(); | 1415 pop_view(); |
1383 push_view(view_controller_variant); | 1416 if (selected_controller_info.subtype == SUBTYPE_SATURN) { |
1417 selected_controller_info.variant = VARIANT_6B_BUMPERS; | |
1418 save_controller_info(selected_controller, &selected_controller_info); | |
1419 if (initial_controller_config) { | |
1420 SDL_GameController *controller = render_get_controller(selected_controller); | |
1421 if (controller) { | |
1422 push_view(view_controller_bindings); | |
1423 controller_binding_changed = 0; | |
1424 SDL_GameControllerClose(controller); | |
1425 } else { | |
1426 show_mapping_view(); | |
1427 } | |
1428 } | |
1429 } else { | |
1430 push_view(view_controller_variant); | |
1431 } | |
1384 } | 1432 } |
1385 } | 1433 } |
1386 nk_group_end(context); | 1434 nk_group_end(context); |
1387 } | 1435 } |
1388 } | 1436 } |
1958 uint32_t width = render_width(); | 2006 uint32_t width = render_width(); |
1959 uint32_t height = render_height(); | 2007 uint32_t height = render_height(); |
1960 uint32_t desired_width = context->style.font->height * 10; | 2008 uint32_t desired_width = context->style.font->height * 10; |
1961 if (nk_begin(context, "System Settings", nk_rect(0, 0, width, height), 0)) { | 2009 if (nk_begin(context, "System Settings", nk_rect(0, 0, width, height), 0)) { |
1962 nk_layout_row_static(context, context->style.font->height, desired_width, 2); | 2010 nk_layout_row_static(context, context->style.font->height, desired_width, 2); |
2011 | |
2012 selected_model = settings_dropdown_ex(context, "Model", model_opts, model_names, num_models, selected_model, "system\0model\0"); | |
2013 selected_io_1 = settings_dropdown_ex(context, "IO Port 1 Device", io_opts_1, device_type_names, num_io, selected_io_1, "io\0devices\0""1\0"); | |
2014 selected_io_2 = settings_dropdown_ex(context, "IO Port 2 Device", io_opts_2, device_type_names, num_io, selected_io_2, "io\0devices\0""2\0"); | |
2015 selected_region = settings_dropdown_ex(context, "Default Region", region_codes, regions, num_regions, selected_region, "system\0default_region\0"); | |
1963 selected_sync = settings_dropdown(context, "Sync Source", sync_opts, num_sync_opts, selected_sync, "system\0sync_source\0"); | 2016 selected_sync = settings_dropdown(context, "Sync Source", sync_opts, num_sync_opts, selected_sync, "system\0sync_source\0"); |
1964 settings_int_property(context, "68000 Clock Divider", "", "clocks\0m68k_divider\0", 7, 1, 53); | 2017 settings_int_property(context, "68000 Clock Divider", "", "clocks\0m68k_divider\0", 7, 1, 53); |
2018 selected_format = settings_dropdown(context, "Save State Format", formats, num_formats, selected_format, "ui\0state_format\0"); | |
2019 selected_init = settings_dropdown(context, "Initial RAM Value", ram_inits, num_inits, selected_init, "system\0ram_init\0"); | |
1965 settings_toggle(context, "Remember ROM Path", "ui\0remember_path\0", 1); | 2020 settings_toggle(context, "Remember ROM Path", "ui\0remember_path\0", 1); |
1966 settings_toggle(context, "Save config with EXE", "ui\0config_in_exe_dir\0", 0); | 2021 settings_toggle(context, "Save config with EXE", "ui\0config_in_exe_dir\0", 0); |
1967 settings_string(context, "Game Save Path", "ui\0save_path\0", "$USERDATA/blastem/$ROMNAME"); | 2022 settings_string(context, "Game Save Path", "ui\0save_path\0", "$USERDATA/blastem/$ROMNAME"); |
1968 selected_region = settings_dropdown_ex(context, "Default Region", region_codes, regions, num_regions, selected_region, "system\0default_region\0"); | 2023 |
1969 selected_model = settings_dropdown_ex(context, "Model", model_opts, model_names, num_models, selected_model, "system\0model\0"); | |
1970 selected_format = settings_dropdown(context, "Save State Format", formats, num_formats, selected_format, "ui\0state_format\0"); | |
1971 selected_init = settings_dropdown(context, "Initial RAM Value", ram_inits, num_inits, selected_init, "system\0ram_init\0"); | |
1972 selected_io_1 = settings_dropdown_ex(context, "IO Port 1 Device", io_opts_1, device_type_names, num_io, selected_io_1, "io\0devices\0""1\0"); | |
1973 selected_io_2 = settings_dropdown_ex(context, "IO Port 2 Device", io_opts_2, device_type_names, num_io, selected_io_2, "io\0devices\0""2\0"); | |
1974 if (nk_button_label(context, "Back")) { | 2024 if (nk_button_label(context, "Back")) { |
2025 pop_view(); | |
2026 } | |
2027 nk_end(context); | |
2028 } | |
2029 } | |
2030 | |
2031 void view_confirm_reset(struct nk_context *context) | |
2032 { | |
2033 if (nk_begin(context, "Reset Confirm", nk_rect(0, 0, render_width(), render_height()), 0)) { | |
2034 uint32_t desired_width = context->style.font->height * 20; | |
2035 nk_layout_row_static(context, context->style.font->height, desired_width, 1); | |
2036 nk_label(context, "This will reset all settings and controller", NK_TEXT_LEFT); | |
2037 nk_label(context, "mappings back to the defaults.", NK_TEXT_LEFT); | |
2038 nk_label(context, "Are you sure you want to proceed?", NK_TEXT_LEFT); | |
2039 nk_layout_row_static(context, context->style.font->height * 1.5, desired_width / 2, 2); | |
2040 if (nk_button_label(context, "Maybe not")) { | |
2041 pop_view(); | |
2042 } | |
2043 if (nk_button_label(context, "Yep, delete it all")) { | |
2044 delete_custom_config(); | |
2045 config = load_config(); | |
2046 delete_controller_info(); | |
2047 config_dirty = 1; | |
1975 pop_view(); | 2048 pop_view(); |
1976 } | 2049 } |
1977 nk_end(context); | 2050 nk_end(context); |
1978 } | 2051 } |
1979 } | 2052 } |
1991 {"Key Bindings", view_key_bindings}, | 2064 {"Key Bindings", view_key_bindings}, |
1992 {"Controllers", view_controllers}, | 2065 {"Controllers", view_controllers}, |
1993 {"Video", view_video_settings}, | 2066 {"Video", view_video_settings}, |
1994 {"Audio", view_audio_settings}, | 2067 {"Audio", view_audio_settings}, |
1995 {"System", view_system_settings}, | 2068 {"System", view_system_settings}, |
2069 {"Reset to Defaults", view_confirm_reset}, | |
1996 {"Back", view_back} | 2070 {"Back", view_back} |
1997 }; | 2071 }; |
1998 | 2072 |
1999 if (nk_begin(context, "Settings Menu", nk_rect(0, 0, render_width(), render_height()), 0)) { | 2073 if (nk_begin(context, "Settings Menu", nk_rect(0, 0, render_width(), render_height()), 0)) { |
2000 menu(context, sizeof(items)/sizeof(*items), items, NULL); | 2074 menu(context, sizeof(items)/sizeof(*items), items, NULL); |
2308 style_init(); | 2382 style_init(); |
2309 | 2383 |
2310 controller_360 = load_ui_image("images/360.png"); | 2384 controller_360 = load_ui_image("images/360.png"); |
2311 controller_ps4 = load_ui_image("images/ps4.png"); | 2385 controller_ps4 = load_ui_image("images/ps4.png"); |
2312 controller_ps4_6b = load_ui_image("images/ps4_6b.png"); | 2386 controller_ps4_6b = load_ui_image("images/ps4_6b.png"); |
2387 controller_wiiu = load_ui_image("images/wiiu.png"); | |
2388 controller_gen_6b = load_ui_image("images/genesis_6b.png"); | |
2313 | 2389 |
2314 texture_init(); | 2390 texture_init(); |
2315 | 2391 |
2316 if (file_loaded) { | 2392 if (file_loaded) { |
2317 current_view = view_play; | 2393 current_view = view_play; |