changeset 1672:12d0c7c4ad80

Disable most bindings when UI is active
author Michael Pavone <pavone@retrodev.com>
date Thu, 03 Jan 2019 09:14:49 -0800
parents 05c34078e1ac
children ab3b465c052c
files bindings.c bindings.h nuklear_ui/blastem_nuklear.c
diffstat 3 files changed, 106 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/bindings.c	Wed Jan 02 09:27:00 2019 -0800
+++ b/bindings.c	Thu Jan 03 09:14:49 2019 -0800
@@ -188,6 +188,12 @@
 	}
 }
 
+static uint8_t content_binds_enabled = 1;
+void set_content_binding_state(uint8_t enabled)
+{
+	content_binds_enabled = enabled;
+}
+
 void handle_binding_down(keybinding * binding)
 {
 	if (!current_system) {
@@ -256,12 +262,12 @@
 	switch(binding->bind_type)
 	{
 	case BIND_GAMEPAD:
-		if (current_system && current_system->gamepad_up) {
+		if (content_binds_enabled && current_system->gamepad_up) {
 			current_system->gamepad_up(current_system, binding->subtype_a, binding->subtype_b);
 		}
 		break;
 	case BIND_MOUSE:
-		if (current_system && current_system->mouse_up) {
+		if (content_binds_enabled && current_system->mouse_up) {
 			current_system->mouse_up(current_system, binding->subtype_a, binding->subtype_b);
 		}
 		break;
@@ -269,38 +275,50 @@
 		switch (binding->subtype_a)
 		{
 		case UI_DEBUG_MODE_INC:
-			current_system->inc_debug_mode(current_system);
+			if (content_binds_enabled) {
+				current_system->inc_debug_mode(current_system);
+			}
 			break;
 		case UI_ENTER_DEBUGGER:
-			current_system->enter_debugger = 1;
+			if (content_binds_enabled) {
+				current_system->enter_debugger = 1;
+			}
 			break;
 		case UI_SAVE_STATE:
-			current_system->save_state = QUICK_SAVE_SLOT+1;
+			if (content_binds_enabled) {
+				current_system->save_state = QUICK_SAVE_SLOT+1;
+			}
 			break;
 		case UI_NEXT_SPEED:
-			current_speed++;
-			if (current_speed >= num_speeds) {
-				current_speed = 0;
+			if (content_binds_enabled) {
+				current_speed++;
+				if (current_speed >= num_speeds) {
+					current_speed = 0;
+				}
+				printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]);
+				current_system->set_speed_percent(current_system, speeds[current_speed]);
 			}
-			printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]);
-			current_system->set_speed_percent(current_system, speeds[current_speed]);
 			break;
 		case UI_PREV_SPEED:
-			current_speed--;
-			if (current_speed < 0) {
-				current_speed = num_speeds - 1;
+			if (content_binds_enabled) {
+				current_speed--;
+				if (current_speed < 0) {
+					current_speed = num_speeds - 1;
+				}
+				printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]);
+				current_system->set_speed_percent(current_system, speeds[current_speed]);
 			}
-			printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]);
-			current_system->set_speed_percent(current_system, speeds[current_speed]);
 			break;
 		case UI_SET_SPEED:
-			if (binding->subtype_b < num_speeds) {
-				current_speed = binding->subtype_b;
-				printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]);
-				current_system->set_speed_percent(current_system, speeds[current_speed]);
-			} else {
-				printf("Setting speed to %d\n", speeds[current_speed]);
-				current_system->set_speed_percent(current_system, speeds[current_speed]);
+			if (content_binds_enabled) {
+				if (binding->subtype_b < num_speeds) {
+					current_speed = binding->subtype_b;
+					printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]);
+					current_system->set_speed_percent(current_system, speeds[current_speed]);
+				} else {
+					printf("Setting speed to %d\n", speeds[current_speed]);
+					current_system->set_speed_percent(current_system, speeds[current_speed]);
+				}
 			}
 			break;
 		case UI_RELEASE_MOUSE:
@@ -310,7 +328,7 @@
 			}
 			break;
 		case UI_TOGGLE_KEYBOARD_CAPTURE:
-			if (current_system && current_system->has_keyboard) {
+			if (content_binds_enabled && current_system->has_keyboard) {
 				keyboard_captured = !keyboard_captured;
 			}
 			break;
@@ -318,37 +336,43 @@
 			render_toggle_fullscreen();
 			break;
 		case UI_SOFT_RESET:
-			current_system->soft_reset(current_system);
+			if (content_binds_enabled) {
+				current_system->soft_reset(current_system);
+			}
 			break;
 		case UI_RELOAD:
-			reload_media();
+			if (content_binds_enabled) {
+				reload_media();
+			}
 			break;
 		case UI_SMS_PAUSE:
-			if (current_system && current_system->gamepad_down) {
+			if (content_binds_enabled && current_system->gamepad_down) {
 				current_system->gamepad_down(current_system, GAMEPAD_MAIN_UNIT, MAIN_UNIT_PAUSE);
 			}
 			break;
 		case UI_SCREENSHOT: {
-			char *screenshot_base = tern_find_path(config, "ui\0screenshot_path\0", TVAL_PTR).ptrval;
-			if (!screenshot_base) {
-				screenshot_base = "$HOME";
+			if (content_binds_enabled) {
+				char *screenshot_base = tern_find_path(config, "ui\0screenshot_path\0", TVAL_PTR).ptrval;
+				if (!screenshot_base) {
+					screenshot_base = "$HOME";
+				}
+				tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir());
+				vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir());
+				screenshot_base = replace_vars(screenshot_base, vars, 1);
+				tern_free(vars);
+				time_t now = time(NULL);
+				struct tm local_store;
+				char fname_part[256];
+				char *template = tern_find_path(config, "ui\0screenshot_template\0", TVAL_PTR).ptrval;
+				if (!template) {
+					template = "blastem_%c.ppm";
+				}
+				strftime(fname_part, sizeof(fname_part), template, localtime_r(&now, &local_store));
+				char const *parts[] = {screenshot_base, PATH_SEP, fname_part};
+				char *path = alloc_concat_m(3, parts);
+				free(screenshot_base);
+				render_save_screenshot(path);
 			}
-			tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir());
-			vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir());
-			screenshot_base = replace_vars(screenshot_base, vars, 1);
-			tern_free(vars);
-			time_t now = time(NULL);
-			struct tm local_store;
-			char fname_part[256];
-			char *template = tern_find_path(config, "ui\0screenshot_template\0", TVAL_PTR).ptrval;
-			if (!template) {
-				template = "blastem_%c.ppm";
-			}
-			strftime(fname_part, sizeof(fname_part), template, localtime_r(&now, &local_store));
-			char const *parts[] = {screenshot_base, PATH_SEP, fname_part};
-			char *path = alloc_concat_m(3, parts);
-			free(screenshot_base);
-			render_save_screenshot(path);
 			break;
 		}
 		case UI_EXIT:
@@ -373,29 +397,30 @@
 		case UI_PLANE_DEBUG: 
 		case UI_VRAM_DEBUG: 
 		case UI_CRAM_DEBUG:
-		case UI_COMPOSITE_DEBUG: {
-			vdp_context *vdp = NULL;
-			if (current_system->type == SYSTEM_GENESIS) {
-				genesis_context *gen = (genesis_context *)current_system;
-				vdp = gen->vdp;
-			} else if (current_system->type == SYSTEM_SMS) {
-				sms_context *sms = (sms_context *)current_system;
-				vdp = sms->vdp;
+		case UI_COMPOSITE_DEBUG:
+			if (content_binds_enabled) {
+				vdp_context *vdp = NULL;
+				if (current_system->type == SYSTEM_GENESIS) {
+					genesis_context *gen = (genesis_context *)current_system;
+					vdp = gen->vdp;
+				} else if (current_system->type == SYSTEM_SMS) {
+					sms_context *sms = (sms_context *)current_system;
+					vdp = sms->vdp;
+				}
+				if (vdp) {
+					uint8_t debug_type;
+					switch(binding->subtype_a)
+					{
+					case UI_PLANE_DEBUG: debug_type = VDP_DEBUG_PLANE; break;
+					case UI_VRAM_DEBUG: debug_type = VDP_DEBUG_VRAM; break;
+					case UI_CRAM_DEBUG: debug_type = VDP_DEBUG_CRAM; break;
+					case UI_COMPOSITE_DEBUG: debug_type = VDP_DEBUG_COMPOSITE; break;
+					default: return;
+					}
+					vdp_toggle_debug_view(vdp, debug_type);
+				}
+				break;
 			}
-			if (vdp) {
-				uint8_t debug_type;
-				switch(binding->subtype_a)
-				{
-				case UI_PLANE_DEBUG: debug_type = VDP_DEBUG_PLANE; break;
-				case UI_VRAM_DEBUG: debug_type = VDP_DEBUG_VRAM; break;
-				case UI_CRAM_DEBUG: debug_type = VDP_DEBUG_CRAM; break;
-				case UI_COMPOSITE_DEBUG: debug_type = VDP_DEBUG_COMPOSITE; break;
-				default: return;
-				}
-				vdp_toggle_debug_view(vdp, debug_type);
-			}
-			break;
-		}
 		}
 		break;
 	}
--- a/bindings.h	Wed Jan 02 09:27:00 2019 -0800
+++ b/bindings.h	Thu Jan 03 09:14:49 2019 -0800
@@ -25,5 +25,6 @@
 
 void bindings_release_capture(void);
 void bindings_reacquire_capture(void);
+void set_content_binding_state(uint8_t enabled);
 
 #endif //BINDINGS_H_
--- a/nuklear_ui/blastem_nuklear.c	Wed Jan 02 09:27:00 2019 -0800
+++ b/nuklear_ui/blastem_nuklear.c	Thu Jan 03 09:14:49 2019 -0800
@@ -139,7 +139,7 @@
 					free(full_path);
 				}
 				clear_view_stack();
-				current_view = view_play;
+				show_play_view();
 			}
 			selected_entry = -1;
 		}
@@ -246,12 +246,12 @@
 		if (is_load) {
 			if (nk_button_label(context, "Load")) {
 				current_system->load_state(current_system, selected_slot);
-				current_view = view_play;
+				show_play_view();
 			}
 		} else {
 			if (nk_button_label(context, "Save")) {
 				current_system->save_state = selected_slot + 1;
-				current_view = view_play;
+				show_play_view();
 			}
 		}
 		nk_end(context);
@@ -292,6 +292,8 @@
 				if (current_view == view_save_state || current_view == view_load_state) {
 					free_slot_info(slots);
 					slots = NULL;
+				} else if (current_view == view_play) {
+					set_content_binding_state(1);
 				}
 			} else {
 				handler(i);
@@ -1917,6 +1919,7 @@
 
 void show_pause_menu(void)
 {
+	set_content_binding_state(0);
 	context->style.window.background = nk_rgba(0, 0, 0, 128);
 	context->style.window.fixed_background = nk_style_item_color(nk_rgba(0, 0, 0, 128));
 	current_view = view_pause;
@@ -1925,6 +1928,7 @@
 
 void show_play_view(void)
 {
+	set_content_binding_state(1);
 	current_view = view_play;
 }
 
@@ -1996,7 +2000,12 @@
 	
 	texture_init();
 	
-	current_view = file_loaded ? view_play : view_menu;
+	if (file_loaded) {
+		current_view = view_play;
+	} else {
+		current_view = view_menu;
+		set_content_binding_state(0);
+	}
 	render_set_ui_render_fun(blastem_nuklear_render);
 	render_set_event_handler(handle_event);
 	render_set_gl_context_handlers(context_destroyed, context_created);