Add Disconnect Key (F2)

This commit is contained in:
Agent X 2023-10-30 19:00:08 -04:00
parent 0b53dbcdbd
commit a6d456fed7
8 changed files with 37 additions and 14 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

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

View File

@ -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);