diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 49785a9d..9ef11449 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -100,6 +100,7 @@ unsigned int configKeyDRight[MAX_BINDS] = { 0x0151, 0x100e, VK_INVALID unsigned int configKeyConsole[MAX_BINDS] = { 0x0029, 0x003B, VK_INVALID }; unsigned int configKeyPrevPage[MAX_BINDS] = { 0x0016, VK_INVALID, VK_INVALID }; unsigned int configKeyNextPage[MAX_BINDS] = { 0x0018, VK_INVALID, VK_INVALID }; +unsigned int configKeyDisconnect[MAX_BINDS] = { 0x003C, VK_INVALID, VK_INVALID }; unsigned int configStickDeadzone = 16; // 16*DEADZONE_STEP=4960 (the original default deadzone) unsigned int configRumbleStrength = 50; #ifdef EXTERNAL_DATA @@ -204,6 +205,7 @@ static const struct ConfigOption options[] = { {.name = "key_dright", .type = CONFIG_TYPE_BIND, .uintValue = configKeyDRight}, {.name = "key_prev", .type = CONFIG_TYPE_BIND, .uintValue = configKeyPrevPage}, {.name = "key_next", .type = CONFIG_TYPE_BIND, .uintValue = configKeyNextPage}, + {.name = "key_disconnect", .type = CONFIG_TYPE_BIND, .uintValue = configKeyDisconnect}, {.name = "stick_deadzone", .type = CONFIG_TYPE_UINT, .uintValue = &configStickDeadzone}, {.name = "rumble_strength", .type = CONFIG_TYPE_UINT, .uintValue = &configRumbleStrength}, #ifdef EXTERNAL_DATA diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 21351461..6ce283d3 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -59,6 +59,7 @@ extern unsigned int configKeyDRight[]; extern unsigned int configKeyConsole[]; extern unsigned int configKeyPrevPage[]; extern unsigned int configKeyNextPage[]; +extern unsigned int configKeyDisconnect[]; extern unsigned int configStickDeadzone; extern unsigned int configRumbleStrength; extern unsigned int configGamepadNumber; diff --git a/src/pc/controller/controller_keyboard.c b/src/pc/controller/controller_keyboard.c index 6828113e..6a250dd0 100644 --- a/src/pc/controller/controller_keyboard.c +++ b/src/pc/controller/controller_keyboard.c @@ -13,6 +13,7 @@ #include "engine/math_util.h" #include "menu/file_select.h" #include "src/pc/djui/djui.h" +#include "src/pc/djui/djui_panel_pause.h" static int keyboard_buttons_down; @@ -33,6 +34,8 @@ static int keyboard_map_scancode(int scancode) { } bool keyboard_on_key_down(int scancode) { + djui_panel_pause_disconnect_key_update(scancode); + // see if interactable captures this scancode if (djui_interactable_on_key_down(scancode)) { keyboard_lastkey = scancode; diff --git a/src/pc/controller/controller_sdl2.c b/src/pc/controller/controller_sdl2.c index fc3063eb..ea0841e7 100644 --- a/src/pc/controller/controller_sdl2.c +++ b/src/pc/controller/controller_sdl2.c @@ -27,6 +27,7 @@ #include "pc/lua/utils/smlua_misc_utils.h" #include "pc/djui/djui.h" +#include "pc/djui/djui_panel_pause.h" #include "pc/djui/djui_hud_utils.h" #define MAX_JOYBINDS 32 @@ -164,6 +165,7 @@ static inline void update_button(const int i, const bool new) { joy_buttons[i] = new; if (pressed) { last_joybutton = i; + djui_panel_pause_disconnect_key_update(VK_BASE_SDL_GAMEPAD + i); djui_interactable_on_key_down(VK_BASE_SDL_GAMEPAD + i); } if (unpressed) { diff --git a/src/pc/djui/djui_panel_controls_extra.c b/src/pc/djui/djui_panel_controls_extra.c index 25e8e482..92772d57 100644 --- a/src/pc/djui/djui_panel_controls_extra.c +++ b/src/pc/djui/djui_panel_controls_extra.c @@ -4,7 +4,7 @@ #include "src/pc/configfile.h" void djui_panel_controls_extra_create(struct DjuiBase* caller) { - f32 bindBodyHeight = 28 * 11 + 1 * 10; + f32 bindBodyHeight = 28 * 12 + 1 * 10; struct DjuiThreePanel* panel = djui_panel_menu_create(DLANG(CONTROLS, CONTROLS)); struct DjuiBase* body = djui_three_panel_get_body(panel); @@ -15,17 +15,18 @@ void djui_panel_controls_extra_create(struct DjuiBase* caller) { djui_base_set_color(&bindBody->base, 0, 0, 0, 0); djui_flow_layout_set_margin(bindBody, 1); { - djui_bind_create(&bindBody->base, DLANG(CONTROLS, CHAT), configKeyChat); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, PLAYERS), configKeyPlayerList); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_UP), configKeyDUp); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_DOWN), configKeyDDown); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_LEFT), configKeyDLeft); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_RIGHT), configKeyDRight); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, X), configKeyX); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, Y), configKeyY); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, CONSOLE), configKeyConsole); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, PREV), configKeyPrevPage); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, NEXT), configKeyNextPage); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, CHAT), configKeyChat); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, PLAYERS), configKeyPlayerList); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_UP), configKeyDUp); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_DOWN), configKeyDDown); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_LEFT), configKeyDLeft); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_RIGHT), configKeyDRight); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, X), configKeyX); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, Y), configKeyY); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, CONSOLE), configKeyConsole); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, PREV), configKeyPrevPage); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, NEXT), configKeyNextPage); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, DISCONNECT), configKeyDisconnect); } djui_button_create(body, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back); diff --git a/src/pc/djui/djui_panel_main.c b/src/pc/djui/djui_panel_main.c index d1e70bf0..7a117585 100644 --- a/src/pc/djui/djui_panel_main.c +++ b/src/pc/djui/djui_panel_main.c @@ -48,7 +48,7 @@ void djui_panel_main_create(struct DjuiBase* caller) { if (gCoopCompatibility) { char version[MAX_VERSION_LENGTH + 15]; - snprintf(version, MAX_VERSION_LENGTH + 15, "sm64ex-coop: %s", get_version_local()); + snprintf(version, MAX_VERSION_LENGTH + 15, "sm64ex-coop %s", get_version_local()); struct DjuiText* footer = djui_text_create(&panel->base, version); djui_base_set_size_type(&footer->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); djui_base_set_size(&footer->base, 1.0f, 1.0f); diff --git a/src/pc/djui/djui_panel_pause.c b/src/pc/djui/djui_panel_pause.c index e1bdbae0..9cf7b71b 100644 --- a/src/pc/djui/djui_panel_pause.c +++ b/src/pc/djui/djui_panel_pause.c @@ -20,11 +20,21 @@ static void djui_panel_pause_resume(UNUSED struct DjuiBase* caller) { djui_panel_shutdown(); } -static void djui_panel_pause_quit_yes(UNUSED struct DjuiBase* caller) { +void djui_panel_pause_quit_yes(UNUSED struct DjuiBase* caller) { network_reset_reconnect_and_rehost(); network_shutdown(true, false, false, false); } +void djui_panel_pause_disconnect_key_update(int scancode) { + if (gDjuiInMainMenu) { return; } + + for (int i = 0; i < MAX_BINDS; i++) { + if (scancode == (int)configKeyDisconnect[i]) { + djui_panel_pause_quit_yes(NULL); + } + } +} + static void djui_panel_pause_quit(struct DjuiBase* caller) { if (find_object_with_behavior(bhvActSelector) != NULL || gMarioStates[0].action == ACT_PUSHING_DOOR || gMarioStates[0].action == ACT_PULLING_DOOR) { return; } diff --git a/src/pc/djui/djui_panel_pause.h b/src/pc/djui/djui_panel_pause.h index 3d626318..ed754ca4 100644 --- a/src/pc/djui/djui_panel_pause.h +++ b/src/pc/djui/djui_panel_pause.h @@ -3,4 +3,8 @@ extern bool gDjuiPanelPauseCreated; +void djui_panel_pause_quit_yes(UNUSED struct DjuiBase* caller); + +void djui_panel_pause_disconnect_key_update(int scancode); + void djui_panel_pause_create(struct DjuiBase* caller);