From 0845cb036dd06dbbada21b1c40531539c88c7b61 Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 1 Feb 2022 19:35:15 -0800 Subject: [PATCH] Added stick and dpad binds to controls menu --- build-windows-visual-studio/sm64ex.vcxproj | 4 ++ .../sm64ex.vcxproj.filters | 12 ++++++ src/pc/configfile.c | 10 ++++- src/pc/configfile.h | 4 ++ src/pc/controller/controller_keyboard.c | 4 ++ src/pc/controller/controller_sdl1.c | 4 ++ src/pc/controller/controller_sdl2.c | 4 ++ src/pc/djui/djui.h | 2 + src/pc/djui/djui_panel_controls.c | 33 +++++--------- src/pc/djui/djui_panel_controls_extra.c | 35 +++++++++++++++ src/pc/djui/djui_panel_controls_extra.h | 4 ++ src/pc/djui/djui_panel_controls_n64.c | 43 +++++++++++++++++++ src/pc/djui/djui_panel_controls_n64.h | 4 ++ 13 files changed, 140 insertions(+), 23 deletions(-) create mode 100644 src/pc/djui/djui_panel_controls_extra.c create mode 100644 src/pc/djui/djui_panel_controls_extra.h create mode 100644 src/pc/djui/djui_panel_controls_n64.c create mode 100644 src/pc/djui/djui_panel_controls_n64.h diff --git a/build-windows-visual-studio/sm64ex.vcxproj b/build-windows-visual-studio/sm64ex.vcxproj index 399f68ecc..77db1e7ef 100644 --- a/build-windows-visual-studio/sm64ex.vcxproj +++ b/build-windows-visual-studio/sm64ex.vcxproj @@ -464,6 +464,8 @@ + + @@ -935,6 +937,8 @@ + + diff --git a/build-windows-visual-studio/sm64ex.vcxproj.filters b/build-windows-visual-studio/sm64ex.vcxproj.filters index 1947e0764..b8e39ffc0 100644 --- a/build-windows-visual-studio/sm64ex.vcxproj.filters +++ b/build-windows-visual-studio/sm64ex.vcxproj.filters @@ -4872,6 +4872,12 @@ Source Files\src\pc\network\packets + + Source Files\src\pc\djui\panel + + + Source Files\src\pc\djui\panel + @@ -6022,5 +6028,11 @@ Source Files\src\pc\lua + + Source Files\src\pc\djui\panel + + + Source Files\src\pc\djui\panel + \ No newline at end of file diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 1d30448d8..cf2e7ac0c 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -74,7 +74,11 @@ unsigned int configKeyStickDown[MAX_BINDS] = { 0x001F, VK_INVALID, VK_INVALID unsigned int configKeyStickLeft[MAX_BINDS] = { 0x001E, VK_INVALID, VK_INVALID }; unsigned int configKeyStickRight[MAX_BINDS] = { 0x0020, VK_INVALID, VK_INVALID }; unsigned int configKeyChat[MAX_BINDS] = { 0x001C, VK_INVALID, VK_INVALID }; -unsigned int configKeyPlayerList[MAX_BINDS] = { 0x000F, VK_INVALID, 0x1004 }; +unsigned int configKeyPlayerList[MAX_BINDS] = { 0x000F, 0x1004, VK_INVALID }; +unsigned int configKeyDUp[MAX_BINDS] = { 0x0147, 0x100b, VK_INVALID }; +unsigned int configKeyDDown[MAX_BINDS] = { 0x014f, 0x100c, VK_INVALID }; +unsigned int configKeyDLeft[MAX_BINDS] = { 0x0153, 0x100d, VK_INVALID }; +unsigned int configKeyDRight[MAX_BINDS] = { 0x0151, 0x100e, VK_INVALID }; unsigned int configStickDeadzone = 16; // 16*DEADZONE_STEP=4960 (the original default deadzone) unsigned int configRumbleStrength = 50; #ifdef EXTERNAL_DATA @@ -144,6 +148,10 @@ static const struct ConfigOption options[] = { {.name = "key_stickright", .type = CONFIG_TYPE_BIND, .uintValue = configKeyStickRight}, {.name = "key_chat", .type = CONFIG_TYPE_BIND, .uintValue = configKeyChat}, {.name = "key_playerlist", .type = CONFIG_TYPE_BIND, .uintValue = configKeyPlayerList}, + {.name = "key_dup", .type = CONFIG_TYPE_BIND, .uintValue = configKeyDUp}, + {.name = "key_ddown", .type = CONFIG_TYPE_BIND, .uintValue = configKeyDDown}, + {.name = "key_dleft", .type = CONFIG_TYPE_BIND, .uintValue = configKeyDLeft}, + {.name = "key_dright", .type = CONFIG_TYPE_BIND, .uintValue = configKeyDRight}, {.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 47cfcdf55..ba2614db0 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -43,6 +43,10 @@ extern unsigned int configKeyStickLeft[]; extern unsigned int configKeyStickRight[]; extern unsigned int configKeyChat[]; extern unsigned int configKeyPlayerList[]; +extern unsigned int configKeyDUp[]; +extern unsigned int configKeyDDown[]; +extern unsigned int configKeyDLeft[]; +extern unsigned int configKeyDRight[]; extern unsigned int configStickDeadzone; extern unsigned int configRumbleStrength; #ifdef EXTERNAL_DATA diff --git a/src/pc/controller/controller_keyboard.c b/src/pc/controller/controller_keyboard.c index 9370e3ed1..250e5c1d2 100644 --- a/src/pc/controller/controller_keyboard.c +++ b/src/pc/controller/controller_keyboard.c @@ -100,6 +100,10 @@ static void keyboard_bindkeys(void) { keyboard_add_binds(L_TRIG, configKeyL); keyboard_add_binds(R_TRIG, configKeyR); keyboard_add_binds(START_BUTTON, configKeyStart); + keyboard_add_binds(U_JPAD, configKeyDUp); + keyboard_add_binds(D_JPAD, configKeyDDown); + keyboard_add_binds(L_JPAD, configKeyDLeft); + keyboard_add_binds(R_JPAD, configKeyDRight); } static void keyboard_init(void) { diff --git a/src/pc/controller/controller_sdl1.c b/src/pc/controller/controller_sdl1.c index a94d0d792..54b931219 100644 --- a/src/pc/controller/controller_sdl1.c +++ b/src/pc/controller/controller_sdl1.c @@ -100,6 +100,10 @@ static void controller_sdl_bind(void) { controller_add_binds(L_TRIG, configKeyL); controller_add_binds(R_TRIG, configKeyR); controller_add_binds(START_BUTTON, configKeyStart); + controller_add_binds(U_JPAD, configKeyDUp); + controller_add_binds(D_JPAD, configKeyDDown); + controller_add_binds(L_JPAD, configKeyDLeft); + controller_add_binds(R_JPAD, configKeyDRight); } static void controller_sdl_init(void) { diff --git a/src/pc/controller/controller_sdl2.c b/src/pc/controller/controller_sdl2.c index aacfc93c1..74eb01600 100644 --- a/src/pc/controller/controller_sdl2.c +++ b/src/pc/controller/controller_sdl2.c @@ -87,6 +87,10 @@ static void controller_sdl_bind(void) { controller_add_binds(L_TRIG, configKeyL); controller_add_binds(R_TRIG, configKeyR); controller_add_binds(START_BUTTON, configKeyStart); + controller_add_binds(U_JPAD, configKeyDUp); + controller_add_binds(D_JPAD, configKeyDDown); + controller_add_binds(L_JPAD, configKeyDLeft); + controller_add_binds(R_JPAD, configKeyDRight); } static void controller_sdl_init(void) { diff --git a/src/pc/djui/djui.h b/src/pc/djui/djui.h index 9c8d049de..5efbe68ea 100644 --- a/src/pc/djui/djui.h +++ b/src/pc/djui/djui.h @@ -49,6 +49,8 @@ #include "djui_panel_playerlist.h" #include "djui_panel_camera.h" #include "djui_panel_controls.h" +#include "djui_panel_controls_n64.h" +#include "djui_panel_controls_extra.h" #include "djui_panel_display.h" #include "djui_panel_sound.h" #include "djui_panel_confirm.h" diff --git a/src/pc/djui/djui_panel_controls.c b/src/pc/djui/djui_panel_controls.c index 7b04739e8..13603ae64 100644 --- a/src/pc/djui/djui_panel_controls.c +++ b/src/pc/djui/djui_panel_controls.c @@ -8,33 +8,22 @@ void djui_panel_controls_value_change(UNUSED struct DjuiBase* caller) { } void djui_panel_controls_create(struct DjuiBase* caller) { - f32 bindBodyHeight = 32 * 11 + 1 * 10; - f32 bodyHeight = bindBodyHeight + 16 * 3 + 32 * 2 + 64; + f32 bodyHeight = 16 * 5 + 32 * 2 + 64 * 3; struct DjuiBase* defaultBase = NULL; struct DjuiThreePanel* panel = djui_panel_menu_create(bodyHeight, "\\#ff0800\\C\\#1be700\\O\\#00b3ff\\N\\#ffef00\\T\\#ff0800\\R\\#1be700\\O\\#00b3ff\\L\\#ffef00\\S"); struct DjuiFlowLayout* body = (struct DjuiFlowLayout*)djui_three_panel_get_body(panel); { - struct DjuiFlowLayout* bindBody = djui_flow_layout_create(&body->base); - djui_base_set_size_type(&bindBody->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); - djui_base_set_size(&bindBody->base, 1.0f, bindBodyHeight); - djui_base_set_color(&bindBody->base, 0, 0, 0, 0); - djui_flow_layout_set_margin(bindBody, 1); - { - struct DjuiBind* bind1 = djui_bind_create(&bindBody->base, "A", configKeyA); - djui_bind_create(&bindBody->base, "B", configKeyB); - djui_bind_create(&bindBody->base, "Start", configKeyStart); - djui_bind_create(&bindBody->base, "L", configKeyL); - djui_bind_create(&bindBody->base, "R", configKeyR); - djui_bind_create(&bindBody->base, "Z", configKeyZ); - djui_bind_create(&bindBody->base, "C Up", configKeyCUp); - djui_bind_create(&bindBody->base, "C Down", configKeyCDown); - djui_bind_create(&bindBody->base, "C Left", configKeyCLeft); - djui_bind_create(&bindBody->base, "C Right", configKeyCRight); - djui_bind_create(&bindBody->base, "Chat", configKeyChat); - djui_bind_create(&bindBody->base, "Players", configKeyPlayerList); - defaultBase = &bind1->buttons[0]->base; - } + struct DjuiButton* button1 = djui_button_create(&body->base, "N64 Binds"); + djui_base_set_size_type(&button1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); + djui_base_set_size(&button1->base, 1.0f, 64); + djui_interactable_hook_click(&button1->base, djui_panel_controls_n64_create); + defaultBase = &button1->base; + + struct DjuiButton* button2 = djui_button_create(&body->base, "Extra Binds"); + djui_base_set_size_type(&button2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); + djui_base_set_size(&button2->base, 1.0f, 64); + djui_interactable_hook_click(&button2->base, djui_panel_controls_extra_create); struct DjuiSlider* slider1 = djui_slider_create(&body->base, "Deadzone", &configStickDeadzone, 0, 100); djui_base_set_size_type(&slider1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); diff --git a/src/pc/djui/djui_panel_controls_extra.c b/src/pc/djui/djui_panel_controls_extra.c new file mode 100644 index 000000000..0e877e537 --- /dev/null +++ b/src/pc/djui/djui_panel_controls_extra.c @@ -0,0 +1,35 @@ +#include "djui.h" +#include "src/pc/configfile.h" + +void djui_panel_controls_extra_create(struct DjuiBase* caller) { + f32 bindBodyHeight = 28 * 6 + 1 * 5; + f32 bodyHeight = bindBodyHeight + 16 + 64; + + struct DjuiBase* defaultBase = NULL; + struct DjuiThreePanel* panel = djui_panel_menu_create(bodyHeight, "\\#ff0800\\C\\#1be700\\O\\#00b3ff\\N\\#ffef00\\T\\#ff0800\\R\\#1be700\\O\\#00b3ff\\L\\#ffef00\\S"); + struct DjuiFlowLayout* body = (struct DjuiFlowLayout*)djui_three_panel_get_body(panel); + { + struct DjuiFlowLayout* bindBody = djui_flow_layout_create(&body->base); + djui_base_set_size_type(&bindBody->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); + djui_base_set_size(&bindBody->base, 1.0f, bindBodyHeight); + djui_base_set_color(&bindBody->base, 0, 0, 0, 0); + djui_flow_layout_set_margin(bindBody, 1); + { + djui_bind_create(&bindBody->base, "Chat", configKeyChat); + djui_bind_create(&bindBody->base, "Players", configKeyPlayerList); + djui_bind_create(&bindBody->base, "D Up", configKeyDUp); + djui_bind_create(&bindBody->base, "D Down", configKeyDDown); + djui_bind_create(&bindBody->base, "D Left", configKeyDLeft); + djui_bind_create(&bindBody->base, "D Right", configKeyDRight); + } + + struct DjuiButton* buttonBack = djui_button_create(&body->base, "Back"); + djui_base_set_size_type(&buttonBack->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); + djui_base_set_size(&buttonBack->base, 1.0f, 64); + djui_button_set_style(buttonBack, 1); + djui_interactable_hook_click(&buttonBack->base, djui_panel_menu_back); + defaultBase = &buttonBack->base; + } + + djui_panel_add(caller, &panel->base, defaultBase); +} diff --git a/src/pc/djui/djui_panel_controls_extra.h b/src/pc/djui/djui_panel_controls_extra.h new file mode 100644 index 000000000..f966c9591 --- /dev/null +++ b/src/pc/djui/djui_panel_controls_extra.h @@ -0,0 +1,4 @@ +#pragma once +#include "djui.h" + +void djui_panel_controls_extra_create(struct DjuiBase* caller); diff --git a/src/pc/djui/djui_panel_controls_n64.c b/src/pc/djui/djui_panel_controls_n64.c new file mode 100644 index 000000000..6188e7306 --- /dev/null +++ b/src/pc/djui/djui_panel_controls_n64.c @@ -0,0 +1,43 @@ +#include "djui.h" +#include "src/pc/configfile.h" + +void djui_panel_controls_n64_create(struct DjuiBase* caller) { + f32 bindBodyHeight = 28 * 14 + 1 * 13; + f32 bodyHeight = bindBodyHeight + 16 + 64; + + struct DjuiBase* defaultBase = NULL; + struct DjuiThreePanel* panel = djui_panel_menu_create(bodyHeight, "\\#ff0800\\C\\#1be700\\O\\#00b3ff\\N\\#ffef00\\T\\#ff0800\\R\\#1be700\\O\\#00b3ff\\L\\#ffef00\\S"); + struct DjuiFlowLayout* body = (struct DjuiFlowLayout*)djui_three_panel_get_body(panel); + { + struct DjuiFlowLayout* bindBody = djui_flow_layout_create(&body->base); + djui_base_set_size_type(&bindBody->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); + djui_base_set_size(&bindBody->base, 1.0f, bindBodyHeight); + djui_base_set_color(&bindBody->base, 0, 0, 0, 0); + djui_flow_layout_set_margin(bindBody, 1); + { + djui_bind_create(&bindBody->base, "Up", configKeyStickUp); + djui_bind_create(&bindBody->base, "Down", configKeyStickDown); + djui_bind_create(&bindBody->base, "Left", configKeyStickLeft); + djui_bind_create(&bindBody->base, "Right", configKeyStickRight); + djui_bind_create(&bindBody->base, "A", configKeyA); + djui_bind_create(&bindBody->base, "B", configKeyB); + djui_bind_create(&bindBody->base, "Start", configKeyStart); + djui_bind_create(&bindBody->base, "L", configKeyL); + djui_bind_create(&bindBody->base, "R", configKeyR); + djui_bind_create(&bindBody->base, "Z", configKeyZ); + djui_bind_create(&bindBody->base, "C Up", configKeyCUp); + djui_bind_create(&bindBody->base, "C Down", configKeyCDown); + djui_bind_create(&bindBody->base, "C Left", configKeyCLeft); + djui_bind_create(&bindBody->base, "C Right", configKeyCRight); + } + + struct DjuiButton* buttonBack = djui_button_create(&body->base, "Back"); + djui_base_set_size_type(&buttonBack->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); + djui_base_set_size(&buttonBack->base, 1.0f, 64); + djui_button_set_style(buttonBack, 1); + djui_interactable_hook_click(&buttonBack->base, djui_panel_menu_back); + defaultBase = &buttonBack->base; + } + + djui_panel_add(caller, &panel->base, defaultBase); +} diff --git a/src/pc/djui/djui_panel_controls_n64.h b/src/pc/djui/djui_panel_controls_n64.h new file mode 100644 index 000000000..50306056a --- /dev/null +++ b/src/pc/djui/djui_panel_controls_n64.h @@ -0,0 +1,4 @@ +#pragma once +#include "djui.h" + +void djui_panel_controls_n64_create(struct DjuiBase* caller);