From 0a16951170685cc9a0170d14f15b5c27012c3b38 Mon Sep 17 00:00:00 2001 From: RaelCappra Date: Sun, 2 Jul 2023 14:13:14 -0300 Subject: [PATCH 01/21] mouse --- libultraship | 2 +- soh/include/z64player.h | 5 + .../controls/GameControlEditor.cpp | 4 + soh/soh/OTRGlobals.cpp | 4 + soh/soh/OTRGlobals.h | 1 + soh/src/code/padmgr.c | 9 ++ soh/src/code/z_camera.c | 30 +++- .../actors/ovl_player_actor/z_player.c | 142 ++++++++++++++++-- 8 files changed, 180 insertions(+), 17 deletions(-) diff --git a/libultraship b/libultraship index 7d60dd37120..bf3d1950eef 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit 7d60dd37120d3b37938a2ed7377007971171c8be +Subproject commit bf3d1950eefff78549d666cc0680df9679524eb4 diff --git a/soh/include/z64player.h b/soh/include/z64player.h index 4aaf5758653..c871dfd2e37 100644 --- a/soh/include/z64player.h +++ b/soh/include/z64player.h @@ -680,7 +680,12 @@ typedef struct Player { // #region SOH [Enhancements] // Upstream TODO: Rename this to make it more obvious it is apart of an enhancement /* */ u8 boomerangQuickRecall; // Has the player pressed the boomerang button while it's in the air still? + + /* 0x???? */ f32 mouseQuickspinX[5]; + /* 0x???? */ f32 mouseQuickspinY[5]; + /* 0x???? */ u8 quickspinCount; // #endregion + u8 ivanFloating; u8 ivanDamageMultiplier; } Player; // size = 0xA94 diff --git a/soh/soh/Enhancements/controls/GameControlEditor.cpp b/soh/soh/Enhancements/controls/GameControlEditor.cpp index 3b2415de6a9..db317a4fac4 100644 --- a/soh/soh/Enhancements/controls/GameControlEditor.cpp +++ b/soh/soh/Enhancements/controls/GameControlEditor.cpp @@ -314,6 +314,9 @@ namespace GameControlEditor { UIWidgets::Spacer(5); window->BeginGroupPanelPublic("Walk Modifier", ImGui::GetContentRegionAvail()); UIWidgets::PaddedEnhancementCheckbox("Toggle modifier instead of holding", "gWalkSpeedToggle", true, false); + UIWidgets::PaddedEnhancementCheckbox("Apply walk speed modifier to raw player inputs if less than 100%", "gWalkModifierToInputs", true, false); + DrawHelpIcon("If selected, the walk speed modifier will be taken into account for all player controls that relies on stick magnitude.\n" + "This allows, for example, to put away your sword while moving, easily achieving ESS position, or a quick adjustment of aim sensitivity."); UIWidgets::PaddedEnhancementCheckbox("Don't affect jump distance/velocity", "gWalkModifierDoesntChangeJump", true, false); UIWidgets::PaddedEnhancementSliderFloat("Modifier 1: %d %%", "##WalkMod1", "gWalkModifierOne", 0.0f, 5.0f, "", 1.0f, true, true, false, true); UIWidgets::PaddedEnhancementSliderFloat("Modifier 2: %d %%", "##WalkMod2", "gWalkModifierTwo", 0.0f, 5.0f, "", 1.0f, true, true, false, true); @@ -322,6 +325,7 @@ namespace GameControlEditor { UIWidgets::Spacer(0); UIWidgets::PaddedEnhancementCheckbox("Answer Navi Prompt with L Button", "gNaviOnL"); DrawHelpIcon("Speak to Navi with L but enter first-person camera with C-Up"); + UIWidgets::PaddedEnhancementCheckbox("Mouse/Touch Enabled", "gMouseTouchEnabled"); window->EndGroupPanelPublic(0); } diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index b044c05339b..372d7092f55 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1624,6 +1624,10 @@ extern "C" uint32_t OTRGetCurrentHeight() { return OTRGlobals::Instance->context->GetWindow()->GetHeight(); } +extern "C" void OTRMoveCursor(uint32_t x, uint32_t y) { + OTRGlobals::Instance->context->GetWindow()->MoveCursor(x, y); +} + Color_RGB8 GetColorForControllerLED() { auto brightness = CVarGetFloat("gLedBrightness", 1.0f) / 1.0f; Color_RGB8 color = { 0, 0, 0 }; diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index bef92f30605..d7b43ab8a3f 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -100,6 +100,7 @@ uint64_t osGetTime(void); uint32_t osGetCount(void); uint32_t OTRGetCurrentWidth(void); uint32_t OTRGetCurrentHeight(void); +OTRMoveCursor(uint32_t x, uint32_t y); //(RR) for shield float OTRGetAspectRatio(void); float OTRGetDimensionFromLeftEdge(float v); float OTRGetDimensionFromRightEdge(float v); diff --git a/soh/src/code/padmgr.c b/soh/src/code/padmgr.c index abfa029e19c..4b28312ebd5 100644 --- a/soh/src/code/padmgr.c +++ b/soh/src/code/padmgr.c @@ -268,6 +268,9 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) { input->cur.button = 0; input->cur.stick_x = 0; input->cur.stick_y = 0; + input->cur.left_click = 0; + input->cur.right_click = 0; + input->cur.err_no = padnow1->err_no; if (padMgr->ctrlrIsConnected[i]) { padMgr->ctrlrIsConnected[i] = false; @@ -290,6 +293,12 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) { PadUtils_UpdateRelXY(input); input->press.stick_x += (s8)(input->cur.stick_x - input->prev.stick_x); input->press.stick_y += (s8)(input->cur.stick_y - input->prev.stick_y); + buttonDiff = input->prev.left_click != input->cur.left_click; + input->press.left_click = buttonDiff; + + buttonDiff = input->prev.right_click != input->cur.right_click; + input->press.right_click = buttonDiff; + } uint8_t rumble = (padMgr->rumbleEnable[0] > 0); diff --git a/soh/src/code/z_camera.c b/soh/src/code/z_camera.c index e0d82710796..691351b5dd3 100644 --- a/soh/src/code/z_camera.c +++ b/soh/src/code/z_camera.c @@ -1422,6 +1422,20 @@ s32 SetCameraManual(Camera* camera) { f32 newCamX = -D_8015BD7C->state.input[0].cur.right_stick_x * 10.0f; f32 newCamY = D_8015BD7C->state.input[0].cur.right_stick_y * 10.0f; + int mouseX, mouseY; + SDL_GetRelativeMouseState(&mouseX, &mouseY); + D_8015BD7C->state.input[0].cur.mouse_move_x = mouseX; + D_8015BD7C->state.input[0].cur.mouse_move_y = mouseY; + + if (CVarGetInteger("gMouseTouchEnabled", 0) != 1) { + mouseX = 0.0f; + mouseY = 0.0f; + } + + newCamX -= mouseX * 40.0f; + newCamY += mouseY * 40.0f; + + if ((fabsf(newCamX) >= 15.0f || fabsf(newCamY) >= 15.0f) && camera->play->manualCamera == false) { camera->play->manualCamera = true; @@ -1485,8 +1499,20 @@ s32 Camera_Free(Camera* camera) { camera->animState = 0; - f32 newCamX = -D_8015BD7C->state.input[0].cur.right_stick_x * 10.0f * (CVarGetFloat("gThirdPersonCameraSensitivityX", 1.0f)); - f32 newCamY = D_8015BD7C->state.input[0].cur.right_stick_y * 10.0f * (CVarGetFloat("gThirdPersonCameraSensitivityY", 1.0f)); + int mouseX, mouseY; + mouseX = D_8015BD7C->state.input[0].cur.mouse_move_x; + mouseY = D_8015BD7C->state.input[0].cur.mouse_move_y; + + if (CVarGetInteger("gMouseTouchEnabled", 0) != 1 || + /* Disable mouse movement when holding down the shield */ + camera->player->stateFlags1 & 0x400000 ) { + mouseX = 0.0f; + mouseY = 0.0f; + } + + f32 newCamX = (-D_8015BD7C->state.input[0].cur.right_stick_x * 10.0f - (mouseX * 40.0f)) * (CVarGetFloat("gThirdPersonCameraSensitivityX", 1.0f)); + f32 newCamY = (+D_8015BD7C->state.input[0].cur.right_stick_y * 10.0f + (mouseY * 40.0f)) * (CVarGetFloat("gThirdPersonCameraSensitivityY", 1.0f)); + bool invertXAxis = (CVarGetInteger("gInvertXAxis", 0) && !CVarGetInteger("gMirroredWorld", 0)) || (!CVarGetInteger("gInvertXAxis", 0) && CVarGetInteger("gMirroredWorld", 0)); camera->play->camX += newCamX * (invertXAxis ? -1 : 1); diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index 86a6854cf65..57809c8731b 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -1692,6 +1692,7 @@ void func_8083315C(PlayState* play, Player* this) { D_808535DC = Camera_GetInputDirYaw(GET_ACTIVE_CAM(play)) + D_808535D8; + this->quickspinCount = (this->quickspinCount + 1) % 5; this->unk_846 = (this->unk_846 + 1) % 4; if (D_808535D4 < 55.0f) { @@ -1702,6 +1703,12 @@ void func_8083315C(PlayState* play, Player* this) { phi_v0 = (u16)((s16)(D_808535DC - this->actor.shape.rot.y) + 0x2000) >> 14; } + if(CVarGetInteger("gMouseTouchEnabled", 0)){ + f32 x = sControlInput->cur.touch_x; + f32 y = sControlInput->cur.touch_y; + this->mouseQuickspinX[this->quickspinCount] = x; + this->mouseQuickspinY[this->quickspinCount] = y; + } this->unk_847[this->unk_846] = phi_v1; this->unk_84B[this->unk_846] = phi_v0; } @@ -3506,6 +3513,7 @@ void func_80837530(PlayState* play, Player* this, s32 arg2) { s32 func_808375D8(Player* this) { s8 sp3C[4]; s8* iter; + s8 iterMouse; s8* iter2; s8 temp1; s8 temp2; @@ -3515,6 +3523,40 @@ s32 func_808375D8(Player* this) { return 0; } + if(CVarGetInteger("gMouseTouchEnabled", 0)){ //mouse quickspin + iter2 = &sp3C[0]; + u32 willSpin = 1; + for (i = 0; i < 4; i++, iter2++){ + f32 relY = this->mouseQuickspinY[i + 1] - this->mouseQuickspinY[i]; + f32 relX = this->mouseQuickspinX[i + 1] - this->mouseQuickspinX[i]; + s16 aTan = Math_Atan2S(relY, -relX); + iterMouse = (u16)(aTan + 0x2000) >> 9; + if ((*iter2 = iterMouse) < 0) { + willSpin = 0; + break; + } + *iter2 *= 2; + } + temp1 = sp3C[0] - sp3C[1]; + if (ABS(temp1) < 10) { + willSpin = 0; + } + iter2 = &sp3C[1]; + for (i = 1; i < 3; i++, iter2++) { + temp2 = *iter2 - *(iter2 + 1); + if ((ABS(temp2) < 10) || (temp2 * temp1 < 0)) { + willSpin = 0; + break; + } + } + if (willSpin){ + return 1; + } + } + sp3C[0] = 0; + sp3C[1] = 0; + sp3C[2] = 0; + sp3C[3] = 0; iter = &this->unk_847[0]; iter2 = &sp3C[0]; for (i = 0; i < 4; i++, iter++, iter2++) { @@ -5494,6 +5536,14 @@ s32 func_8083C2B0(Player* this, PlayState* play) { func_808323B4(play, this); if (func_80835C58(play, this, func_80843188, 0)) { + /* MOD: move cursor to the middle on shield pull (RR) */ + if (CVarGetInteger("gMouseTouchEnabled", 0)) { + u32 width = OTRGetCurrentWidth(); + u32 height = OTRGetCurrentHeight(); + OTRMoveCursor(width/2, height/2); + } + /* */ + this->stateFlags1 |= PLAYER_STATE1_SHIELDING; if (!Player_IsChildWithHylianShield(this)) { @@ -6132,20 +6182,29 @@ void func_8083DFE0(Player* this, f32* arg1, s16* arg2) { } if (CVarGetInteger("gEnableWalkModify", 0) && !CVarGetInteger("gWalkModifierDoesntChangeJump", 0)) { - if (CVarGetInteger("gWalkSpeedToggle", 0)) { - if (gWalkSpeedToggle1) { - maxSpeed *= CVarGetFloat("gWalkModifierOne", 1.0f); - } else if (gWalkSpeedToggle2) { - maxSpeed *= CVarGetFloat("gWalkModifierTwo", 1.0f); - } - } else { - if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER1)) { - maxSpeed *= CVarGetFloat("gWalkModifierOne", 1.0f); - } else if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER2)) { - maxSpeed *= CVarGetFloat("gWalkModifierTwo", 1.0f); - } - } - } + f32 modifierValue = 1.0; + if (CVarGetInteger("gWalkSpeedToggle", 0)) { + if (gWalkSpeedToggle1) { + maxSpeed *= CVarGetFloat("gWalkModifierOne", 1.0f); + modifierValue = CVarGetFloat("gWalkModifierOne", 1.0f); + } else if (gWalkSpeedToggle2) { + maxSpeed *= CVarGetFloat("gWalkModifierTwo", 1.0f); + modifierValue = CVarGetFloat("gWalkModifierTwo", 1.0f); + } + } else { + if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER1)) { + maxSpeed *= CVarGetFloat("gWalkModifierOne", 1.0f); + modifierValue = CVarGetFloat("gWalkModifierOne", 1.0f); + } else if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER2)) { + maxSpeed *= CVarGetFloat("gWalkModifierTwo", 1.0f); + modifierValue = CVarGetFloat("gWalkModifierTwo", 1.0f); + } + } + + if (modifierValue > 1.0 || !CVarGetInteger("gWalkModifierToInputs", 0)) { + maxSpeed *= modifierValue; + } + } this->linearVelocity = CLAMP(this->linearVelocity, -maxSpeed, maxSpeed); } @@ -8189,6 +8248,19 @@ void func_80843188(Player* this, PlayState* play) { sp50 = sControlInput->rel.stick_x * (CVarGetInteger("gMirroredWorld", 0) ? 120 : -120); sp4E = this->actor.shape.rot.y - Camera_GetInputDirYaw(GET_ACTIVE_CAM(play)); + if (CVarGetInteger("gMouseTouchEnabled", 0)) { + u32 width = OTRGetCurrentWidth(); + u32 height = OTRGetCurrentHeight(); + /* + * Y: -12800 ~ +12700 + * X: -15360 ~ +15240 + */ + f32 xBound = 15360 / ((f32)width / 2); + f32 yBound = 12800 / ((f32)height / 2); + sp54 += +(sControlInput->cur.touch_y - (height) / 2) * yBound; + sp50 += +(sControlInput->cur.touch_x - (width) / 2) * xBound * (CVarGetInteger("gMirroredWorld", 0) ? 1 : -1); + } + sp40 = Math_CosS(sp4E); sp4C = (Math_SinS(sp4E) * sp50) + (sp54 * sp40); sp40 = Math_CosS(sp4E); @@ -10599,6 +10671,30 @@ void Player_UpdateCommon(Player* this, PlayState* play, Input* input) { sControlInput = input; + if (CVarGetInteger("gEnableWalkModify", 0)) { + f32 modifierValue = 1.0; + if (CVarGetInteger("gWalkSpeedToggle", 0)) { + if (gWalkSpeedToggle1 || sControlInput->cur.middle_click) { + modifierValue = CVarGetFloat("gWalkModifierOne", 1.0f); + } else if (gWalkSpeedToggle2) { + modifierValue = CVarGetFloat("gWalkModifierTwo", 1.0f); + } + } else { + if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER1) || sControlInput->cur.middle_click) { + modifierValue = CVarGetFloat("gWalkModifierOne", 1.0f); + } else if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER2)) { + modifierValue = CVarGetFloat("gWalkModifierTwo", 1.0f); + } + } + + if (modifierValue < 1.0 && CVarGetInteger("gWalkModifierToInputs", 0)) { + s32 old_stick_x = input->rel.stick_x; + s32 old_stick_y = input->rel.stick_y; + input->rel.stick_x *= modifierValue * ABS(cosf(Math_Atan2F(old_stick_x, old_stick_y))); + input->rel.stick_y *= modifierValue * ABS(sinf(Math_Atan2F(old_stick_x, old_stick_y))); + } + } + if (this->unk_A86 < 0) { this->unk_A86++; if (this->unk_A86 == 0) { @@ -11364,6 +11460,24 @@ s16 func_8084ABD8(PlayState* play, Player* this, s32 arg2, s16 arg3) { s16 temp2; s16 temp3; bool gInvertAimingXAxis = (CVarGetInteger("gInvertAimingXAxis", 0) && !CVarGetInteger("gMirroredWorld", 0)) || (!CVarGetInteger("gInvertAimingXAxis", 0) && CVarGetInteger("gMirroredWorld", 0)); + /* TODO: Move all this mouse stuff somewhere more appropriate */ + if(CVarGetInteger("gMouseTouchEnabled", 0)) { + int mouseX, mouseY; + SDL_GetRelativeMouseState(&mouseX, &mouseY); + + sControlInput->cur.mouse_move_x = mouseX; + sControlInput->cur.mouse_move_y = mouseY; + if (fabsf(sControlInput->cur.mouse_move_x) > 0) { + //printf("x:%d\n", sControlInput->cur.mouse_move_x); + this->actor.focus.rot.y -= (sControlInput->cur.mouse_move_x) * 12.0f * (CVarGetFloat("gFirstPersonCameraSensitivity", 1.0f)) *\ + (gInvertAimingXAxis ? -1 : 1); + } + if (fabsf(sControlInput->cur.mouse_move_y) > 0) { + //printf("y:%d\n", sControlInput->cur.mouse_move_y); + this->actor.focus.rot.x += (sControlInput->cur.mouse_move_y) * 12.0f * (CVarGetFloat("gFirstPersonCameraSensitivity", 1.0f)); + } + } + /* ********************************************************** */ if (!func_8002DD78(this) && !func_808334B4(this) && (arg2 == 0) && !CVarGetInteger("gDisableAutoCenterViewFirstPerson", 0)) { temp2 = sControlInput->rel.stick_y * 240.0f * (CVarGetInteger("gInvertAimingYAxis", 1) ? 1 : -1); // Sensitivity not applied here because higher than default sensitivies will allow the camera to escape the autocentering, and glitch out massively From 5c4a3f76f405e838fcec7e34abc6c5efdc407ad1 Mon Sep 17 00:00:00 2001 From: RaelCappra Date: Sun, 2 Jul 2023 14:15:14 -0300 Subject: [PATCH 02/21] (mouse) small fix --- soh/soh/OTRGlobals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index d7b43ab8a3f..4f56d5f9e6d 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -100,7 +100,7 @@ uint64_t osGetTime(void); uint32_t osGetCount(void); uint32_t OTRGetCurrentWidth(void); uint32_t OTRGetCurrentHeight(void); -OTRMoveCursor(uint32_t x, uint32_t y); //(RR) for shield +void OTRMoveCursor(uint32_t x, uint32_t y); //(RR) for shield float OTRGetAspectRatio(void); float OTRGetDimensionFromLeftEdge(float v); float OTRGetDimensionFromRightEdge(float v); From cb576e502e78abbb88b40e3cfcd5676f1ad21a3c Mon Sep 17 00:00:00 2001 From: RaelCappra Date: Fri, 7 Jul 2023 15:30:43 -0300 Subject: [PATCH 03/21] "fix" implicit declaration --- soh/src/code/z_camera.c | 2 ++ soh/src/overlays/actors/ovl_player_actor/z_player.c | 1 + 2 files changed, 3 insertions(+) diff --git a/soh/src/code/z_camera.c b/soh/src/code/z_camera.c index 691351b5dd3..459a9fb2037 100644 --- a/soh/src/code/z_camera.c +++ b/soh/src/code/z_camera.c @@ -8,6 +8,8 @@ #include "soh/frame_interpolation.h" +#include //TODO (RR): don't import SDL in game code + s16 Camera_ChangeSettingFlags(Camera* camera, s16 setting, s16 flags); s32 Camera_ChangeModeFlags(Camera* camera, s16 mode, u8 flags); s32 Camera_QRegInit(void); diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index 57809c8731b..06f37fff2bf 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -6,6 +6,7 @@ #include #include "global.h" +#include //TODO (RR): don't import SDL in game code #include "overlays/actors/ovl_Bg_Heavy_Block/z_bg_heavy_block.h" #include "overlays/actors/ovl_Door_Shutter/z_door_shutter.h" From 3034179f41d52131be4c9308969bb4ea51880dd7 Mon Sep 17 00:00:00 2001 From: RaelCappra Date: Fri, 28 Jul 2023 16:38:09 -0300 Subject: [PATCH 04/21] LUS 1.2 --- libultraship | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libultraship b/libultraship index bf3d1950eef..36cee298427 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit bf3d1950eefff78549d666cc0680df9679524eb4 +Subproject commit 36cee2984270c055fdcd870d271690d44c3d8dd0 From 33609d0ba0117b53c0c055d65c58aedd4cc1df37 Mon Sep 17 00:00:00 2001 From: RaelCappra Date: Sat, 20 Apr 2024 18:01:22 -0300 Subject: [PATCH 05/21] empty commit to force CI re-run From 734134e0254b8e874dff122d2e50a54590cdd940 Mon Sep 17 00:00:00 2001 From: RaelCappra Date: Thu, 15 Aug 2024 11:08:04 -0300 Subject: [PATCH 06/21] include new mouse LUS --- libultraship | 2 +- soh/src/overlays/actors/ovl_player_actor/z_player.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libultraship b/libultraship index 31e9b009f94..40f01f3ca40 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit 31e9b009f94e7074a847c7954926cba354cd7c72 +Subproject commit 40f01f3ca400b890489c554ee352d426930ecfcc diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index aac84878661..43c75300476 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -12104,11 +12104,12 @@ s16 func_8084ABD8(PlayState* play, Player* this, s32 arg2, s16 arg3) { if (fabsf(sControlInput->cur.mouse_move_x) > 0) { //printf("x:%d\n", sControlInput->cur.mouse_move_x); this->actor.focus.rot.y -= (sControlInput->cur.mouse_move_x) * 12.0f * (CVarGetFloat("gFirstPersonCameraSensitivity", 1.0f)) *\ - (gInvertAimingXAxis ? -1 : 1); + invertXAxisMulti; } if (fabsf(sControlInput->cur.mouse_move_y) > 0) { //printf("y:%d\n", sControlInput->cur.mouse_move_y); - this->actor.focus.rot.x += (sControlInput->cur.mouse_move_y) * 12.0f * (CVarGetFloat("gFirstPersonCameraSensitivity", 1.0f)); + this->actor.focus.rot.x += (sControlInput->cur.mouse_move_y) * 12.0f * (CVarGetFloat("gFirstPersonCameraSensitivity", 1.0f)) *\ + invertYAxisMulti; } } /* ********************************************************** */ From 1113f2f4e76b9ea88c6ad49215cceeda51c82396 Mon Sep 17 00:00:00 2001 From: RaelCappra Date: Wed, 21 Aug 2024 18:28:49 -0300 Subject: [PATCH 07/21] deleted: soh/soh/Enhancements/controls/GameControlEditor.cpp --- .../controls/GameControlEditor.cpp | 413 ------------------ 1 file changed, 413 deletions(-) delete mode 100644 soh/soh/Enhancements/controls/GameControlEditor.cpp diff --git a/soh/soh/Enhancements/controls/GameControlEditor.cpp b/soh/soh/Enhancements/controls/GameControlEditor.cpp deleted file mode 100644 index 9a54495d8e6..00000000000 --- a/soh/soh/Enhancements/controls/GameControlEditor.cpp +++ /dev/null @@ -1,413 +0,0 @@ -#include "GameControlEditor.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "../../UIWidgets.hpp" - -namespace GameControlEditor { - const ImGuiTableFlags PANEL_TABLE_FLAGS = - ImGuiTableFlags_BordersH | - ImGuiTableFlags_BordersV; - const ImGuiTableColumnFlags PANEL_TABLE_COLUMN_FLAGS = - ImGuiTableColumnFlags_IndentEnable | - ImGuiTableColumnFlags_NoSort; - - namespace TableHelper { - void InitHeader(bool has_header = true) { - if (has_header) { - ImGui::TableHeadersRow(); - } - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::AlignTextToFramePadding(); //This is to adjust Vertical pos of item in a cell to be normlized. - ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); - } - - void NextCol() { - ImGui::TableNextColumn(); - ImGui::AlignTextToFramePadding(); - ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); - } - - void NextLine() { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::AlignTextToFramePadding(); - ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); - } - } - - void DrawHelpIcon(const std::string& helptext) { - // place the ? button to the most of the right side of the cell it is using. - ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 22); - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 15); - ImGui::SmallButton("?"); - UIWidgets::Tooltip(helptext.c_str()); - } - - typedef uint32_t N64ButtonMask; - - // Used together for an incomplete linked hash map implementation in order to - // map button masks to their names and original mapping on N64 - static std::list> buttons; - static std::unordered_map buttonNames; - - void addButtonName(N64ButtonMask mask, const char* name) { - buttons.push_back(std::make_pair(mask, name)); - buttonNames[mask] = std::prev(buttons.end()); - } - - typedef struct { - const char* label; - const char* cVarName; - N64ButtonMask defaultBtn; - } CustomButtonMap; - - // Ocarina button maps - static CustomButtonMap ocarinaD5 = {"D5", "gOcarinaD5BtnMap", BTN_CUP}; - static CustomButtonMap ocarinaB4 = {"B4", "gOcarinaB4BtnMap", BTN_CLEFT}; - static CustomButtonMap ocarinaA4 = {"A4", "gOcarinaA4BtnMap", BTN_CRIGHT}; - static CustomButtonMap ocarinaF4 = {"F4", "gOcarinaF4BtnMap", BTN_CDOWN}; - static CustomButtonMap ocarinaD4 = {"D4", "gOcarinaD4BtnMap", BTN_A}; - static CustomButtonMap ocarinaSongDisable = {"Disable songs", "gOcarinaDisableBtnMap", BTN_L}; - static CustomButtonMap ocarinaSharp = {"Pitch up", "gOcarinaSharpBtnMap", BTN_R}; - static CustomButtonMap ocarinaFlat = {"Pitch down", "gOcarinaFlatBtnMap", BTN_Z}; - - void GameControlEditorWindow::InitElement() { - addButtonName(BTN_A, "A"); - addButtonName(BTN_B, "B"); - addButtonName(BTN_CUP, "C Up"); - addButtonName(BTN_CDOWN, "C Down"); - addButtonName(BTN_CLEFT, "C Left"); - addButtonName(BTN_CRIGHT, "C Right"); - addButtonName(BTN_L, "L"); - addButtonName(BTN_Z, "Z"); - addButtonName(BTN_R, "R"); - addButtonName(BTN_START, "Start"); - addButtonName(BTN_DUP, "D-pad up"); - addButtonName(BTN_DDOWN, "D-pad down"); - addButtonName(BTN_DLEFT, "D-pad left"); - addButtonName(BTN_DRIGHT, "D-pad right"); - addButtonName(0, "None"); - } - - // Draw a button mapping setting consisting of a padded label and button dropdown. - // excludedButtons indicates which buttons are unavailable to choose from. - void DrawMapping(CustomButtonMap& mapping, float labelWidth, N64ButtonMask excludedButtons) { - N64ButtonMask currentButton = CVarGetInteger(mapping.cVarName, mapping.defaultBtn); - - const char* preview; - if (buttonNames.contains(currentButton)) { - preview = buttonNames[currentButton]->second; - } else { - preview = "Unknown"; - } - - UIWidgets::Spacer(0); - ImVec2 cursorPos = ImGui::GetCursorPos(); - ImVec2 textSize = ImGui::CalcTextSize(mapping.label); - ImGui::SetCursorPosY(cursorPos.y + textSize.y / 4); - ImGui::SetCursorPosX(cursorPos.x + abs(textSize.x - labelWidth)); - ImGui::Text("%s", mapping.label); - ImGui::SameLine(); - ImGui::SetCursorPosY(cursorPos.y); - - ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8); - if (ImGui::BeginCombo(StringHelper::Sprintf("##%s", mapping.cVarName).c_str(), preview)) { - for (auto i = buttons.begin(); i != buttons.end(); i++) { - if ((i->first & excludedButtons) != 0) { - continue; - } - if (ImGui::Selectable(i->second, i->first == currentButton)) { - CVarSetInteger(mapping.cVarName, i->first); - LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); - } - } - ImGui::EndCombo(); - } - UIWidgets::Spacer(0); - } - - void DrawOcarinaControlPanel(GameControlEditorWindow* window) { - if (!ImGui::CollapsingHeader("Ocarina Controls")) { - return; - } - - if (!ImGui::BeginTable("tableCustomOcarinaControls", 1, PANEL_TABLE_FLAGS)) { - return; - } - - ImGui::TableSetupColumn("Custom Ocarina Controls", PANEL_TABLE_COLUMN_FLAGS | ImGuiTableColumnFlags_WidthStretch); - TableHelper::InitHeader(false); - - ImVec2 cursor = ImGui::GetCursorPos(); - ImGui::SetCursorPos(ImVec2(cursor.x + 5, cursor.y + 5)); - UIWidgets::EnhancementCheckbox("Customize Ocarina Controls", "gCustomOcarinaControls"); - - if (CVarGetInteger("gCustomOcarinaControls", 0) == 1) { - if (ImGui::BeginTable("tableCustomMainOcarinaControls", 2, ImGuiTableFlags_SizingStretchProp)) { - float labelWidth; - N64ButtonMask disableMask = BTN_B; - if (CVarGetInteger("gDpadOcarina", 0)) { - disableMask |= BTN_DUP | BTN_DDOWN | BTN_DLEFT | BTN_DRIGHT; - } - - ImGui::TableSetupColumn("Notes##CustomOcarinaNotes", PANEL_TABLE_COLUMN_FLAGS); - ImGui::TableSetupColumn("Modifiers##CustomOcaranaModifiers", PANEL_TABLE_COLUMN_FLAGS); - TableHelper::InitHeader(false); - - window->BeginGroupPanelPublic("Notes", ImGui::GetContentRegionAvail()); - labelWidth = ImGui::CalcTextSize("D5").x + 10; - DrawMapping(ocarinaD5, labelWidth, disableMask); - DrawMapping(ocarinaB4, labelWidth, disableMask); - DrawMapping(ocarinaA4, labelWidth, disableMask); - DrawMapping(ocarinaF4, labelWidth, disableMask); - DrawMapping(ocarinaD4, labelWidth, disableMask); - ImGui::Dummy(ImVec2(0, 5)); - float cursorY = ImGui::GetCursorPosY(); - window->EndGroupPanelPublic(0); - - TableHelper::NextCol(); - - window->BeginGroupPanelPublic("Modifiers", ImGui::GetContentRegionAvail()); - labelWidth = ImGui::CalcTextSize(ocarinaSongDisable.label).x + 10; - DrawMapping(ocarinaSongDisable, labelWidth, disableMask); - DrawMapping(ocarinaSharp, labelWidth, disableMask); - DrawMapping(ocarinaFlat, labelWidth, disableMask); - window->EndGroupPanelPublic(cursorY - ImGui::GetCursorPosY() + 2); - - ImGui::EndTable(); - } - } else { - UIWidgets::Spacer(0); - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 5); - ImGui::TextWrapped("To modify the main ocarina controls, select the \"Customize Ocarina Controls\" checkbox."); - UIWidgets::Spacer(0); - } - - window->BeginGroupPanelPublic("Alternate controls", ImGui::GetContentRegionAvail()); - if (ImGui::BeginTable("tableOcarinaAlternateControls", 2, ImGuiTableFlags_SizingFixedSame)) { - ImGui::TableSetupColumn("D-pad", PANEL_TABLE_COLUMN_FLAGS); - ImGui::TableSetupColumn("Right stick", PANEL_TABLE_COLUMN_FLAGS); - TableHelper::InitHeader(false); - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 5); - UIWidgets::EnhancementCheckbox("Play with D-pad", "gDpadOcarina"); - TableHelper::NextCol(); - UIWidgets::EnhancementCheckbox("Play with camera stick", "gRStickOcarina"); - UIWidgets::Spacer(0); - ImGui::EndTable(); - } - window->EndGroupPanelPublic(0); - - ImGui::EndTable(); - } - - // CurrentPort is indexed started at 1 here due to the Generic tab, instead of 0 like in InputEditorWindow - // Therefore CurrentPort - 1 must always be used inside this function instead of CurrentPort - void DrawCustomButtons() { - auto inputEditorWindow = std::reinterpret_pointer_cast(LUS::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Input Editor")); - inputEditorWindow->DrawControllerSelect(CurrentPort - 1); - - inputEditorWindow->DrawButton("Modifier 1", BTN_MODIFIER1, CurrentPort - 1, &BtnReading); - inputEditorWindow->DrawButton("Modifier 2", BTN_MODIFIER2, CurrentPort - 1, &BtnReading); - } - - void DrawCameraControlPanel(GameControlEditorWindow* window) { - if (!ImGui::CollapsingHeader("Camera Controls")) { - return; - } - - UIWidgets::Spacer(0); - window->BeginGroupPanelPublic("Aiming/First-Person Camera", ImGui::GetContentRegionAvail()); - UIWidgets::PaddedEnhancementCheckbox("Right Stick Aiming", "gRightStickAiming"); - DrawHelpIcon("Allows for aiming with the right stick in:\n-First-Person/C-Up view\n-Weapon Aiming"); - UIWidgets::PaddedEnhancementCheckbox("Invert Aiming X Axis", "gInvertAimingXAxis"); - DrawHelpIcon("Inverts the Camera X Axis in:\n-First-Person/C-Up view\n-Weapon Aiming"); - UIWidgets::PaddedEnhancementCheckbox("Invert Aiming Y Axis", "gInvertAimingYAxis", true, true, false, "", UIWidgets::CheckboxGraphics::Cross, true); - DrawHelpIcon("Inverts the Camera Y Axis in:\n-First-Person/C-Up view\n-Weapon Aiming"); - UIWidgets::PaddedEnhancementCheckbox("Invert Shield Aiming Y Axis", "gInvertShieldAimingYAxis", true, true, false, "", UIWidgets::CheckboxGraphics::Cross, true); - DrawHelpIcon("Inverts the Shield Aiming Y Axis"); - UIWidgets::PaddedEnhancementCheckbox("Invert Shield Aiming X Axis", "gInvertShieldAimingXAxis"); - DrawHelpIcon("Inverts the Shield Aiming X Axis"); - UIWidgets::PaddedEnhancementCheckbox("Disable Auto-Centering in First-Person View", "gDisableAutoCenterViewFirstPerson"); - DrawHelpIcon("Prevents the C-Up view from auto-centering, allowing for Gyro Aiming"); - if (UIWidgets::PaddedEnhancementCheckbox("Enable Custom Aiming/First-Person sensitivity", "gEnableFirstPersonSensitivity", true, false)) { - if (!CVarGetInteger("gEnableFirstPersonSensitivity", 0)) { - CVarClear("gFirstPersonCameraSensitivity"); - } - } - if (CVarGetInteger("gEnableFirstPersonSensitivity", 0)) { - UIWidgets::EnhancementSliderFloat("Aiming/First-Person Horizontal Sensitivity: %d %%", "##FirstPersonSensitivity Horizontal", - "gFirstPersonCameraSensitivityX", 0.01f, 5.0f, "", 1.0f, true); - UIWidgets::EnhancementSliderFloat("Aiming/First-Person Vertical Sensitivity: %d %%", "##FirstPersonSensitivity Vertical", - "gFirstPersonCameraSensitivityY", 0.01f, 5.0f, "", 1.0f, true); - } - UIWidgets::Spacer(0); - window->EndGroupPanelPublic(0); - - UIWidgets::Spacer(0); - window->BeginGroupPanelPublic("Third-Person Camera", ImGui::GetContentRegionAvail()); - - UIWidgets::PaddedEnhancementCheckbox("Free Camera", "gFreeCamera"); - DrawHelpIcon("Enables free camera control\nNote: You must remap C buttons off of the right stick in the " - "controller config menu, and map the camera stick to the right stick."); - UIWidgets::PaddedEnhancementCheckbox("Invert Camera X Axis", "gInvertXAxis"); - DrawHelpIcon("Inverts the Camera X Axis in:\n-Free camera"); - UIWidgets::PaddedEnhancementCheckbox("Invert Camera Y Axis", "gInvertYAxis", true, true, false, "", UIWidgets::CheckboxGraphics::Cross, true); - DrawHelpIcon("Inverts the Camera Y Axis in:\n-Free camera"); - UIWidgets::Spacer(0); - UIWidgets::PaddedEnhancementSliderFloat("Third-Person Horizontal Sensitivity: %d %%", "##ThirdPersonSensitivity Horizontal", - "gThirdPersonCameraSensitivityX", 0.01f, 5.0f, "", 1.0f, true, true, false, true); - UIWidgets::PaddedEnhancementSliderFloat("Third-Person Vertical Sensitivity: %d %%", "##ThirdPersonSensitivity Vertical", - "gThirdPersonCameraSensitivityY", 0.01f, 5.0f, "", 1.0f, true, true, false, true); - UIWidgets::PaddedEnhancementSliderInt("Camera Distance: %d", "##CamDist", - "gFreeCameraDistMax", 100, 900, "", 185, true, false, true); - UIWidgets::PaddedEnhancementSliderInt("Camera Transition Speed: %d", "##CamTranSpeed", - "gFreeCameraTransitionSpeed", 0, 900, "", 25, true, false, true); - window->EndGroupPanelPublic(0); - } - - void DrawDpadControlPanel(GameControlEditorWindow* window) { - if (!ImGui::CollapsingHeader("D-Pad Controls")) { - return; - } - - ImVec2 cursor = ImGui::GetCursorPos(); - ImGui::SetCursorPos(ImVec2(cursor.x + 5, cursor.y + 5)); - window->BeginGroupPanelPublic("D-Pad Options", ImGui::GetContentRegionAvail()); - UIWidgets::PaddedEnhancementCheckbox("D-pad Support on Pause Screen", "gDpadPause"); - DrawHelpIcon("Navigate Pause with the D-pad\nIf used with D-pad as Equip Items, you must hold C-Up to equip instead of navigate\n" - "To make the cursor only move a single space no matter how long a direction is held, manually set gDpadHoldChange to 0"); - UIWidgets::PaddedEnhancementCheckbox("D-pad Support in Text Boxes", "gDpadText"); - DrawHelpIcon("Navigate choices in text boxes, shop item selection, and the file select / name entry screens with the D-pad\n" - "To make the cursor only move a single space during name entry no matter how long a direction is held, manually set gDpadHoldChange to 0"); - UIWidgets::PaddedEnhancementCheckbox("D-pad as Equip Items", "gDpadEquips"); - DrawHelpIcon("Equip items and equipment on the D-pad\nIf used with D-pad on Pause Screen, you must hold C-Up to equip instead of navigate"); - window->EndGroupPanelPublic(0); - } - - void DrawMiscControlPanel(GameControlEditorWindow* window) { - if (!ImGui::CollapsingHeader("Miscellaneous Controls")) { - return; - } - - ImVec2 cursor = ImGui::GetCursorPos(); - ImGui::SetCursorPos(ImVec2(cursor.x + 5, cursor.y + 5)); - window->BeginGroupPanelPublic("Misc Controls", ImGui::GetContentRegionAvail()); - UIWidgets::PaddedText("Allow the cursor to be on any slot"); - static const char* cursorOnAnySlot[3] = { "Only in Rando", "Always", "Never" }; - UIWidgets::EnhancementCombobox("gPauseAnyCursor", cursorOnAnySlot, PAUSE_ANY_CURSOR_RANDO_ONLY); - DrawHelpIcon("Allows the cursor on the pause menu to be over any slot. Sometimes required in rando to select " - "certain items."); - UIWidgets::Spacer(0); - ImGui::BeginDisabled(CVarGetInteger("gDisableChangingSettings", 0)); - UIWidgets::PaddedEnhancementCheckbox("Enable walk speed modifiers", "gEnableWalkModify", true, false); - DrawHelpIcon("Hold the assigned button to change the maximum walking speed\nTo change the assigned button, go into the Ports tabs above"); - if (CVarGetInteger("gEnableWalkModify", 0)) { - UIWidgets::Spacer(5); - window->BeginGroupPanelPublic("Walk Modifier", ImGui::GetContentRegionAvail()); - UIWidgets::PaddedEnhancementCheckbox("Toggle modifier instead of holding", "gWalkSpeedToggle", true, false); - UIWidgets::PaddedEnhancementCheckbox("Apply walk speed modifier to raw player inputs if less than 100%", "gWalkModifierToInputs", true, false); - DrawHelpIcon("If selected, the walk speed modifier will be taken into account for all player controls that relies on stick magnitude.\n" - "This allows, for example, to put away your sword while moving, easily achieving ESS position, or a quick adjustment of aim sensitivity."); - UIWidgets::PaddedEnhancementCheckbox("Don't affect jump distance/velocity", "gWalkModifierDoesntChangeJump", true, false); - UIWidgets::PaddedEnhancementSliderFloat("Modifier 1: %d %%", "##WalkMod1", "gWalkModifierOne", 0.0f, 5.0f, "", 1.0f, true, true, false, true); - UIWidgets::PaddedEnhancementSliderFloat("Modifier 2: %d %%", "##WalkMod2", "gWalkModifierTwo", 0.0f, 5.0f, "", 1.0f, true, true, false, true); - window->EndGroupPanelPublic(0); - } - ImGui::EndDisabled(); - UIWidgets::Spacer(0); - UIWidgets::PaddedEnhancementCheckbox("Answer Navi Prompt with L Button", "gNaviOnL"); - DrawHelpIcon("Speak to Navi with L but enter first-person camera with C-Up"); - UIWidgets::PaddedEnhancementCheckbox("Mouse/Touch Enabled", "gMouseTouchEnabled"); - window->EndGroupPanelPublic(0); - } - - void DrawLEDControlPanel(GameControlEditorWindow* window) { - window->BeginGroupPanelPublic("LED Colors", ImGui::GetContentRegionAvail()); - static const char* ledSources[] = { "Original Tunic Colors", "Cosmetics Tunic Colors", "Health Colors", - "Original Navi Targeting Colors", "Cosmetics Navi Targeting Colors", "Custom" }; - UIWidgets::PaddedText("Source"); - UIWidgets::EnhancementCombobox("gLedColorSource", ledSources, LED_SOURCE_TUNIC_ORIGINAL); - DrawHelpIcon("Health\n- Red when health critical (13-20% depending on max health)\n- Yellow when health < 40%. Green otherwise.\n\n" \ - "Tunics: colors will mirror currently equipped tunic, whether original or the current values in Cosmetics Editor.\n\n" \ - "Custom: single, solid color"); - if (CVarGetInteger("gLedColorSource", 1) == LED_SOURCE_CUSTOM) { - UIWidgets::Spacer(3); - auto port1Color = CVarGetColor24("gLedPort1Color", { 255, 255, 255 }); - ImVec4 colorVec = { port1Color.r / 255.0f, port1Color.g / 255.0f, port1Color.b / 255.0f, 1.0f }; - if (ImGui::ColorEdit3("", (float*)&colorVec, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel)) { - Color_RGB8 color; - color.r = colorVec.x * 255.0; - color.g = colorVec.y * 255.0; - color.b = colorVec.z * 255.0; - - CVarSetColor24("gLedPort1Color", color); - LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); - } - ImGui::SameLine(); - ImGui::Text("Custom Color"); - } - UIWidgets::PaddedEnhancementSliderFloat("Brightness: %d%%", "##LED_Brightness", "gLedBrightness", - 0.0f, 1.0f, "", 1.0f, true, true); - DrawHelpIcon("Sets the brightness of controller LEDs. 0% brightness = LEDs off."); - UIWidgets::PaddedEnhancementCheckbox("Critical Health Override", "gLedCriticalOverride", true, true, - CVarGetInteger("gLedColorSource", LED_SOURCE_TUNIC_ORIGINAL) == LED_SOURCE_HEALTH, "Override redundant for health source.", - UIWidgets::CheckboxGraphics::Cross, true); - DrawHelpIcon("Shows red color when health is critical, otherwise displays according to color source."); - window->EndGroupPanelPublic(0); - } - - void GameControlEditorWindow::DrawElement() { - ImGui::SetNextWindowSize(ImVec2(465, 430), ImGuiCond_FirstUseEver); - if (ImGui::Begin("Game Controls Configuration", &mIsVisible)) { - ImGui::BeginTabBar("##CustomControllers"); - if (ImGui::BeginTabItem("Generic")) { - CurrentPort = 0; - ImGui::EndTabItem(); - } - - for (int i = 1; i <= 4; i++) { - if (ImGui::BeginTabItem(StringHelper::Sprintf("Port %d", i).c_str())) { - CurrentPort = i; - ImGui::EndTabItem(); - } - } - - ImGui::EndTabBar(); - - if (CurrentPort == 0) { - DrawOcarinaControlPanel(this); - DrawCameraControlPanel(this); - DrawDpadControlPanel(this); - DrawMiscControlPanel(this); - } else { - DrawCustomButtons(); - if (CurrentPort == 1 && LUS::Context::GetInstance()->GetControlDeck()->GetDeviceFromPortIndex(0)->CanSetLed()) { - DrawLEDControlPanel(this); - } - } - } - ImGui::End(); - } - - void GameControlEditorWindow::BeginGroupPanelPublic(const char* name, const ImVec2& size) { - BeginGroupPanel(name, size); - } - - void GameControlEditorWindow::EndGroupPanelPublic(float minHeight) { - EndGroupPanel(minHeight); - } -} From a156632986188d9330fe76518983c23fe50d9f10 Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:19:35 -0300 Subject: [PATCH 08/21] [mouse]LUS --- libultraship | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libultraship b/libultraship index 40f01f3ca40..471546d8376 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit 40f01f3ca400b890489c554ee352d426930ecfcc +Subproject commit 471546d837656fc69412fb57e04130d63d0469de From d24981edbb1e9ce3c6baf0bd644e91cb11decb7b Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Wed, 21 Aug 2024 22:30:30 -0300 Subject: [PATCH 09/21] fix input viewer header --- soh/soh/Enhancements/controls/InputViewer.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/soh/soh/Enhancements/controls/InputViewer.h b/soh/soh/Enhancements/controls/InputViewer.h index 3e1e9c98798..b4d6413e16a 100644 --- a/soh/soh/Enhancements/controls/InputViewer.h +++ b/soh/soh/Enhancements/controls/InputViewer.h @@ -28,8 +28,6 @@ class InputViewer : public Ship::GuiWindow { InputViewer(); ~InputViewer(); - void Draw(); - private: void RenderButton(std::string btn, std::string btnOutline, int state, ImVec2 size, int outlineMode); }; @@ -44,6 +42,4 @@ class InputViewerSettingsWindow : public Ship::GuiWindow { InputViewerSettingsWindow(); ~InputViewerSettingsWindow(); - - void Draw(); }; From d02668aa0f5dc71cb80e3096d78a740b4825c565 Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:02:06 -0300 Subject: [PATCH 10/21] Bump LUS for mouse support --- libultraship | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libultraship b/libultraship index d252cc241e0..ee1c0df9c92 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit d252cc241e0ff2270a289abba274ed43bd0b1792 +Subproject commit ee1c0df9c92964e7a26341700e0d983d8f732e50 From df80c4c25e6a28ff6c31ff8706d5bd2ed267ea97 Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Wed, 11 Dec 2024 22:37:19 -0300 Subject: [PATCH 11/21] Mouse Support --- soh/include/z64player.h | 5 -- soh/soh/OTRGlobals.cpp | 4 - soh/soh/OTRGlobals.h | 1 - soh/src/code/padmgr.c | 10 +-- soh/src/code/z_camera.c | 33 ++----- .../actors/ovl_player_actor/z_player.c | 89 +++---------------- 6 files changed, 23 insertions(+), 119 deletions(-) diff --git a/soh/include/z64player.h b/soh/include/z64player.h index c7a2b7d1d57..b33e64724e6 100644 --- a/soh/include/z64player.h +++ b/soh/include/z64player.h @@ -924,11 +924,6 @@ typedef struct Player { /* */ u8 ivanDamageMultiplier; // #endregion - /* 0x???? */ f32 mouseQuickspinX[5]; - /* 0x???? */ f32 mouseQuickspinY[5]; - /* 0x???? */ u8 quickspinCount; - // #endregion - } Player; // size = 0xA94 #endif diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index d3163b7d17c..ee41d723124 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1675,10 +1675,6 @@ extern "C" uint32_t OTRGetCurrentHeight() { return OTRGlobals::Instance->context->GetWindow()->GetHeight(); } -extern "C" void OTRMoveCursor(uint32_t x, uint32_t y) { - OTRGlobals::Instance->context->GetWindow()->MoveCursor(x, y); -} - Color_RGB8 GetColorForControllerLED() { auto brightness = CVarGetFloat(CVAR_SETTING("LEDBrightness"), 1.0f) / 1.0f; Color_RGB8 color = { 0, 0, 0 }; diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index cbd8c87a79f..854ef5b8fc2 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -97,7 +97,6 @@ uint64_t osGetTime(void); uint32_t osGetCount(void); uint32_t OTRGetCurrentWidth(void); uint32_t OTRGetCurrentHeight(void); -void OTRMoveCursor(uint32_t x, uint32_t y); //(RR) for shield float OTRGetAspectRatio(void); float OTRGetDimensionFromLeftEdge(float v); float OTRGetDimensionFromRightEdge(float v); diff --git a/soh/src/code/padmgr.c b/soh/src/code/padmgr.c index 1a77f2cf6d2..d96cccf2d91 100644 --- a/soh/src/code/padmgr.c +++ b/soh/src/code/padmgr.c @@ -3,6 +3,7 @@ #include #include "soh/Enhancements/game-interactor/GameInteractor.h" +#include "soh/Enhancements/controls/Mouse.h" #include "soh/OTRGlobals.h" #include "soh/ResourceManagerHelpers.h" @@ -270,8 +271,6 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) { input->cur.button = 0; input->cur.stick_x = 0; input->cur.stick_y = 0; - input->cur.left_click = 0; - input->cur.right_click = 0; input->cur.err_no = padnow1->err_no; if (padMgr->ctrlrIsConnected[i]) { @@ -307,11 +306,6 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) { input->press.right_stick_x += (s8)(input->cur.right_stick_x - input->prev.right_stick_x); input->press.right_stick_y += (s8)(input->cur.right_stick_y - input->prev.right_stick_y); // #endregion - buttonDiff = input->prev.left_click != input->cur.left_click; - input->press.left_click = buttonDiff; - - buttonDiff = input->prev.right_click != input->cur.right_click; - input->press.right_click = buttonDiff; } @@ -333,6 +327,8 @@ void PadMgr_HandleRetraceMsg(PadMgr* padMgr) { osRecvMesg(queue, NULL, OS_MESG_BLOCK); osContGetReadData(padMgr->pads); + Mouse_UpdateAll(); + for (i = 0; i < __osMaxControllers; i++) { padMgr->padStatus[i].status = Controller_ShouldRumble(i); } diff --git a/soh/src/code/z_camera.c b/soh/src/code/z_camera.c index d42292ac6d5..195895930a9 100644 --- a/soh/src/code/z_camera.c +++ b/soh/src/code/z_camera.c @@ -8,8 +8,6 @@ #include "soh/frame_interpolation.h" -#include //TODO (RR): don't import SDL in game code - s16 Camera_ChangeSettingFlags(Camera* camera, s16 setting, s16 flags); s32 Camera_ChangeModeFlags(Camera* camera, s16 mode, u8 flags); s32 Camera_QRegInit(void); @@ -1424,19 +1422,7 @@ s32 SetCameraManual(Camera* camera) { f32 newCamX = -D_8015BD7C->state.input[0].cur.right_stick_x * 10.0f; f32 newCamY = D_8015BD7C->state.input[0].cur.right_stick_y * 10.0f; - int mouseX, mouseY; - SDL_GetRelativeMouseState(&mouseX, &mouseY); - D_8015BD7C->state.input[0].cur.mouse_move_x = mouseX; - D_8015BD7C->state.input[0].cur.mouse_move_y = mouseY; - - if (CVarGetInteger(CVAR_SETTING("EnableMouse"), 0) != 1) { - mouseX = 0.0f; - mouseY = 0.0f; - } - - newCamX -= mouseX * 40.0f; - newCamY += mouseY * 40.0f; - + Mouse_HandleThirdPerson(&newCamX, &newCamY); if ((fabsf(newCamX) >= 15.0f || fabsf(newCamY) >= 15.0f) && camera->play->manualCamera == false) { camera->play->manualCamera = true; @@ -1501,19 +1487,16 @@ s32 Camera_Free(Camera* camera) { camera->animState = 0; - int mouseX, mouseY; - mouseX = D_8015BD7C->state.input[0].cur.mouse_move_x; - mouseY = D_8015BD7C->state.input[0].cur.mouse_move_y; + f32 newCamX = -D_8015BD7C->state.input[0].cur.right_stick_x * 10.0f; + f32 newCamY = +D_8015BD7C->state.input[0].cur.right_stick_y * 10.0f; - if (CVarGetInteger(CVAR_SETTING("EnableMouse"), 0) != 1 || - /* Disable mouse movement when holding down the shield */ - camera->player->stateFlags1 & 0x400000 ) { - mouseX = 0.0f; - mouseY = 0.0f; + /* Disable mouse movement when holding down the shield */ + if (!(camera->player->stateFlags1 & 0x400000)) { + Mouse_HandleThirdPerson(&newCamX, &newCamY); } - f32 newCamX = (-D_8015BD7C->state.input[0].cur.right_stick_x * 10.0f - (mouseX * 40.0f)) * (CVarGetFloat(CVAR_SETTING("FreeLook.CameraSensitivity.X"), 1.0f)); - f32 newCamY = (+D_8015BD7C->state.input[0].cur.right_stick_y * 10.0f + (mouseY * 40.0f)) * (CVarGetFloat(CVAR_SETTING("FreeLook.CameraSensitivity.Y"), 1.0f)); + newCamX *= (CVarGetFloat(CVAR_SETTING("FreeLook.CameraSensitivity.X"), 1.0f)); + newCamY *= (CVarGetFloat(CVAR_SETTING("FreeLook.CameraSensitivity.Y"), 1.0f)); bool invertXAxis = (CVarGetInteger(CVAR_SETTING("FreeLook.InvertXAxis"), 0) && !CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0)) || (!CVarGetInteger(CVAR_SETTING("FreeLook.InvertXAxis"), 0) && CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0)); diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index d69ecff7a82..5ff910f0e2c 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -6,7 +6,6 @@ #include #include "global.h" -#include //TODO (RR): don't import SDL in game code #include "overlays/actors/ovl_Bg_Heavy_Block/z_bg_heavy_block.h" #include "overlays/actors/ovl_Door_Shutter/z_door_shutter.h" @@ -2072,7 +2071,6 @@ void Player_ProcessControlStick(PlayState* play, Player* this) { sControlStickWorldYaw = Camera_GetInputDirYaw(GET_ACTIVE_CAM(play)) + sControlStickAngle; - this->quickspinCount = (this->quickspinCount + 1) % 5; this->controlStickDataIndex = (this->controlStickDataIndex + 1) % 4; if (sControlStickMagnitude < 55.0f) { @@ -2083,12 +2081,8 @@ void Player_ProcessControlStick(PlayState* play, Player* this) { direction = (u16)((s16)(sControlStickWorldYaw - this->actor.shape.rot.y) + 0x2000) >> 14; } - if(CVarGetInteger(CVAR_SETTING("EnableMouse"), 0)){ - f32 x = sControlInput->cur.touch_x; - f32 y = sControlInput->cur.touch_y; - this->mouseQuickspinX[this->quickspinCount] = x; - this->mouseQuickspinY[this->quickspinCount] = y; - } + Mouse_UpdateQuickspinCount(); + this->controlStickSpinAngles[this->controlStickDataIndex] = spinAngle; this->controlStickDirections[this->controlStickDataIndex] = direction; } @@ -4280,7 +4274,6 @@ void func_80837530(PlayState* play, Player* this, s32 arg2) { s32 Player_CanSpinAttack(Player* this) { s8 sp3C[4]; s8* iter; - s8 iterMouse; s8* iter2; s8 temp1; s8 temp2; @@ -4290,36 +4283,6 @@ s32 Player_CanSpinAttack(Player* this) { return false; } - if(CVarGetInteger(CVAR_SETTING("EnableMouse"), 0)){ //mouse quickspin - iter2 = &sp3C[0]; - u32 willSpin = 1; - for (i = 0; i < 4; i++, iter2++){ - f32 relY = this->mouseQuickspinY[i + 1] - this->mouseQuickspinY[i]; - f32 relX = this->mouseQuickspinX[i + 1] - this->mouseQuickspinX[i]; - s16 aTan = Math_Atan2S(relY, -relX); - iterMouse = (u16)(aTan + 0x2000) >> 9; - if ((*iter2 = iterMouse) < 0) { - willSpin = 0; - break; - } - *iter2 *= 2; - } - temp1 = sp3C[0] - sp3C[1]; - if (ABS(temp1) < 10) { - willSpin = 0; - } - iter2 = &sp3C[1]; - for (i = 1; i < 3; i++, iter2++) { - temp2 = *iter2 - *(iter2 + 1); - if ((ABS(temp2) < 10) || (temp2 * temp1 < 0)) { - willSpin = 0; - break; - } - } - if (willSpin){ - return 1; - } - } sp3C[0] = 0; sp3C[1] = 0; sp3C[2] = 0; @@ -4327,6 +4290,10 @@ s32 Player_CanSpinAttack(Player* this) { iter = &this->controlStickSpinAngles[0]; iter2 = &sp3C[0]; + if (Mouse_HandleQuickspin(iter2, sp3C)) { + return true; + } + for (i = 0; i < 4; i++, iter++, iter2++) { if ((*iter2 = *iter) < 0) { return false; @@ -6478,13 +6445,7 @@ s32 Player_ActionHandler_11(Player* this, PlayState* play) { Player_DetachHeldActor(play, this); if (Player_SetupAction(play, this, Player_Action_80843188, 0)) { - /* MOD: move cursor to the middle on shield pull (RR) */ - if (CVarGetInteger(CVAR_SETTING("EnableMouse"), 0)) { - u32 width = OTRGetCurrentWidth(); - u32 height = OTRGetCurrentHeight(); - OTRMoveCursor(width/2, height/2); - } - /* */ + Mouse_RecenterCursor(); this->stateFlags1 |= PLAYER_STATE1_SHIELDING; @@ -9322,19 +9283,7 @@ void Player_Action_80843188(Player* this, PlayState* play) { sp54 = sControlInput->rel.stick_y * 100 * (CVarGetInteger(CVAR_SETTING("Controls.InvertShieldAimingYAxis"), 1) ? 1 : -1); sp50 = sControlInput->rel.stick_x * (CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0) ? 120 : -120) * (CVarGetInteger(CVAR_SETTING("Controls.InvertShieldAimingYAxis"), 0) ? -1 : 1); sp4E = this->actor.shape.rot.y - Camera_GetInputDirYaw(GET_ACTIVE_CAM(play)); - - if (CVarGetInteger(CVAR_SETTING("EnableMouse"), 0)) { - u32 width = OTRGetCurrentWidth(); - u32 height = OTRGetCurrentHeight(); - /* - * Y: -12800 ~ +12700 - * X: -15360 ~ +15240 - */ - f32 xBound = 15360 / ((f32)width / 2); - f32 yBound = 12800 / ((f32)height / 2); - sp54 += +(sControlInput->cur.touch_y - (height) / 2) * yBound; - sp50 += +(sControlInput->cur.touch_x - (width) / 2) * xBound * (CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0) ? 1 : -1); - } + Mouse_HandleShield(&sp50, &sp54); sp40 = Math_CosS(sp4E); sp4C = (Math_SinS(sp4E) * sp50) + (sp54 * sp40); @@ -12000,6 +11949,7 @@ void Player_UpdateCommon(Player* this, PlayState* play, Input* input) { sControlInput = input; + /* (LL) future reference for sensitivity modifiers if (CVarGetInteger("gEnableWalkModify", 0)) { f32 modifierValue = 1.0; if (CVarGetInteger("gWalkSpeedToggle", 0)) { @@ -12023,6 +11973,8 @@ void Player_UpdateCommon(Player* this, PlayState* play, Input* input) { input->rel.stick_y *= modifierValue * ABS(sinf(Math_Atan2F(old_stick_x, old_stick_y))); } } + *********************************** + */ if (this->unk_A86 < 0) { this->unk_A86++; @@ -12802,25 +12754,8 @@ s16 func_8084ABD8(PlayState* play, Player* this, s32 arg2, s16 arg3) { s8 invertYAxisMulti = CVarGetInteger(CVAR_SETTING("Controls.InvertAimingYAxis"), 1) ? 1 : -1; f32 xAxisMulti = CVarGetFloat(CVAR_SETTING("FirstPersonCameraSensitivity.X"), 1.0f); f32 yAxisMulti = CVarGetFloat(CVAR_SETTING("FirstPersonCameraSensitivity.Y"), 1.0f); - /* TODO: Move all this mouse stuff somewhere more appropriate */ - if(CVarGetInteger(CVAR_SETTING("EnableMouse"), 0)) { - int mouseX, mouseY; - SDL_GetRelativeMouseState(&mouseX, &mouseY); - sControlInput->cur.mouse_move_x = mouseX; - sControlInput->cur.mouse_move_y = mouseY; - if (fabsf(sControlInput->cur.mouse_move_x) > 0) { - //printf("x:%d\n", sControlInput->cur.mouse_move_x); - this->actor.focus.rot.y -= (sControlInput->cur.mouse_move_x) * 12.0f * xAxisMulti *\ - invertXAxisMulti; - } - if (fabsf(sControlInput->cur.mouse_move_y) > 0) { - //printf("y:%d\n", sControlInput->cur.mouse_move_y); - this->actor.focus.rot.x += (sControlInput->cur.mouse_move_y) * 12.0f * yAxisMulti *\ - invertYAxisMulti; - } - } - /* ********************************************************** */ + Mouse_HandleFirstPerson(this, invertXAxisMulti, invertYAxisMulti, xAxisMulti, yAxisMulti); if (!func_8002DD78(this) && !func_808334B4(this) && (arg2 == 0)) { // First person without weapon // Y Axis From addd23b4305488adbc86d0ca7348373b9a2116f4 Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Wed, 11 Dec 2024 22:43:13 -0300 Subject: [PATCH 12/21] Comment cleanup --- .../actors/ovl_player_actor/z_player.c | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index 5ff910f0e2c..0b95f627ba7 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -11949,33 +11949,6 @@ void Player_UpdateCommon(Player* this, PlayState* play, Input* input) { sControlInput = input; - /* (LL) future reference for sensitivity modifiers - if (CVarGetInteger("gEnableWalkModify", 0)) { - f32 modifierValue = 1.0; - if (CVarGetInteger("gWalkSpeedToggle", 0)) { - if (gWalkSpeedToggle1 || sControlInput->cur.middle_click) { - modifierValue = CVarGetFloat("gWalkModifierOne", 1.0f); - } else if (gWalkSpeedToggle2) { - modifierValue = CVarGetFloat("gWalkModifierTwo", 1.0f); - } - } else { - if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_CUSTOM_MODIFIER1) || sControlInput->cur.middle_click) { - modifierValue = CVarGetFloat("gWalkModifierOne", 1.0f); - } else if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_CUSTOM_MODIFIER2)) { - modifierValue = CVarGetFloat("gWalkModifierTwo", 1.0f); - } - } - - if (modifierValue < 1.0 && CVarGetInteger("gWalkModifierToInputs", 0)) { - s32 old_stick_x = input->rel.stick_x; - s32 old_stick_y = input->rel.stick_y; - input->rel.stick_x *= modifierValue * ABS(cosf(Math_Atan2F(old_stick_x, old_stick_y))); - input->rel.stick_y *= modifierValue * ABS(sinf(Math_Atan2F(old_stick_x, old_stick_y))); - } - } - *********************************** - */ - if (this->unk_A86 < 0) { this->unk_A86++; if (this->unk_A86 == 0) { From 31588b2ace897e6ae6ccd02d0f96d6f9c6336b6a Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Wed, 11 Dec 2024 23:21:25 -0300 Subject: [PATCH 13/21] Adding the actual mouse enhancement files --- libultraship | 2 +- soh/soh/Enhancements/controls/Mouse.cpp | 116 ++++++++++++++++++++++++ soh/soh/Enhancements/controls/Mouse.h | 29 ++++++ 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 soh/soh/Enhancements/controls/Mouse.cpp create mode 100644 soh/soh/Enhancements/controls/Mouse.h diff --git a/libultraship b/libultraship index ee1c0df9c92..c1f84799dec 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit ee1c0df9c92964e7a26341700e0d983d8f732e50 +Subproject commit c1f84799dec68356ca0529b02a3a930b099325b3 diff --git a/soh/soh/Enhancements/controls/Mouse.cpp b/soh/soh/Enhancements/controls/Mouse.cpp new file mode 100644 index 00000000000..790278023bb --- /dev/null +++ b/soh/soh/Enhancements/controls/Mouse.cpp @@ -0,0 +1,116 @@ +#include "Mouse.h" +#include + +static Ship::Coords mouseCoord = {}; +static Ship::Coords mouseCoordRel = {}; + +#define MOUSE_ENABLED (CVarGetInteger(CVAR_SETTING("EnableMouse"), 0) && GetWindow()->IsMouseCaptured()) + +std::shared_ptr GetWindow() { + return OTRGlobals::Instance->context->GetWindow(); +} + +extern "C" { +void Mouse_UpdatePos() { + mouseCoord = GetWindow()->GetMousePos(); +} + +void Mouse_UpdatePosRel() { + mouseCoordRel = GetWindow()->GetMouseDelta(); +} + +void Mouse_UpdateAll() { + Mouse_UpdatePos(); + Mouse_UpdatePosRel(); +} + +void Mouse_HandleThirdPerson(f32* newCamX, f32* newCamY) { + if (MOUSE_ENABLED) { + *newCamX -= mouseCoordRel.x * 40.0f; + *newCamY += mouseCoordRel.y * 40.0f; + } +} + +void Mouse_HandleFirstPerson(Player* player, s8 invertXAxisMulti, s8 invertYAxisMulti) { + f32 xAxisMulti = CVarGetFloat(CVAR_SETTING("FirstPersonCameraSensitivity.X"), 1.0f); + f32 yAxisMulti = CVarGetFloat(CVAR_SETTING("FirstPersonCameraSensitivity.Y"), 1.0f); + if (MOUSE_ENABLED) { + player->actor.focus.rot.y -= mouseCoordRel.x * 6.0f * xAxisMulti * invertXAxisMulti; + player->actor.focus.rot.x += mouseCoordRel.y * 6.0f * yAxisMulti * invertYAxisMulti; + } +} + +void Mouse_RecenterCursor() { + if (MOUSE_ENABLED) { + u32 width = GetWindow()->GetWidth(); + u32 height = GetWindow()->GetHeight(); + //fetch the movecursor LUS PR + GetWindow()->SetMousePos({width/2, height/2}); + } +} + +void Mouse_HandleShield(f32* sp50, f32* sp54) { + if (MOUSE_ENABLED) { + s32 width = GetWindow()->GetWidth(); + s32 height = GetWindow()->GetHeight(); + /* + * Y: -12800 ~ +12700 + * X: -15360 ~ +15240 + */ + f32 xBound = 15360 / ((f32)width / 2); + f32 yBound = 12800 / ((f32)height / 2); + *sp54 += (mouseCoord.y - (height / 2)) * yBound; + *sp50 += (mouseCoord.x - (width / 2)) * xBound * (CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0) ? 1 : -1); + } +} + +static s8 iterMouse = 0; +static f32 mouseQuickspinX[5] = {}; +static f32 mouseQuickspinY[5] = {}; +static u8 quickspinCount = 0; + +void Mouse_UpdateQuickspinCount() { + quickspinCount = (quickspinCount + 1) % 5; + + if (MOUSE_ENABLED) { + mouseQuickspinX[quickspinCount] = mouseCoord.x; + mouseQuickspinY[quickspinCount] = mouseCoord.y; + } +} + +bool Mouse_HandleQuickspin(s8* iter2, s8* sp3C) { + s8 temp1; + s8 temp2; + s32 i; + if (MOUSE_ENABLED) { //mouse quickspin + s32 willSpin = 1; + for (i = 0; i < 4; i++, iter2++) { + f32 relY = mouseQuickspinY[i + 1] - mouseQuickspinY[i]; + f32 relX = mouseQuickspinX[i + 1] - mouseQuickspinX[i]; + s16 aTan = Math_Atan2S(relY, -relX); + iterMouse = (u16)(aTan + 0x2000) >> 9; + if ((*iter2 = iterMouse) < 0) { + willSpin = 0; + break; + } + *iter2 *= 2; + } + temp1 = sp3C[0] - sp3C[1]; + if (ABS(temp1) < 10) { + willSpin = 0; + } + iter2 = &sp3C[1]; + for (i = 1; i < 3; i++, iter2++) { + temp2 = *iter2 - *(iter2 + 1); + if ((ABS(temp2) < 10) || (temp2 * temp1 < 0)) { + willSpin = 0; + break; + } } + if (willSpin) { + return true; + } + } + + return false; +} +}; //extern "C" diff --git a/soh/soh/Enhancements/controls/Mouse.h b/soh/soh/Enhancements/controls/Mouse.h new file mode 100644 index 00000000000..a91ab9adf48 --- /dev/null +++ b/soh/soh/Enhancements/controls/Mouse.h @@ -0,0 +1,29 @@ +#ifndef MOUSE_H +#define MOUSE_H + +#pragma once + +#include "soh/OTRGlobals.h" +#include +#include "z64player.h" +#include "global.h" + +#ifdef __cplusplus +extern "C" { +#endif +void Mouse_UpdatePos(); +void Mouse_UpdatePosRel(); +void Mouse_UpdatePosWheel(); +void Mouse_UpdateAll(); +void Mouse_RecenterCursor(); +void Mouse_HandleThirdPerson(f32* newCamX, f32* newCamY); +void Mouse_HandleFirstPerson(Player* player, s8 invertXAxisMulti, s8 invertYAxisMulti); +void Mouse_HandleShield(f32* sp50, f32* sp54); +bool Mouse_HandleQuickspin(s8* iter2, s8* sp3C); +void Mouse_UpdateQuickspinCount(); +#ifdef __cplusplus +}; //extern "C" +#endif + +//MOUSE_H +#endif From 5bf27cac12c3bbd36acf9c38e8d278dccfda8ad1 Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Wed, 11 Dec 2024 23:57:16 -0300 Subject: [PATCH 14/21] Fix (?) Windows and Mac builds --- soh/soh/Enhancements/controls/Mouse.cpp | 2 +- soh/src/code/z_camera.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/soh/soh/Enhancements/controls/Mouse.cpp b/soh/soh/Enhancements/controls/Mouse.cpp index 790278023bb..7fc9037b97a 100644 --- a/soh/soh/Enhancements/controls/Mouse.cpp +++ b/soh/soh/Enhancements/controls/Mouse.cpp @@ -45,7 +45,7 @@ void Mouse_RecenterCursor() { u32 width = GetWindow()->GetWidth(); u32 height = GetWindow()->GetHeight(); //fetch the movecursor LUS PR - GetWindow()->SetMousePos({width/2, height/2}); + GetWindow()->SetMousePos({(s32) (width/2), (s32) (height/2)}); } } diff --git a/soh/src/code/z_camera.c b/soh/src/code/z_camera.c index 195895930a9..3bdd1961fef 100644 --- a/soh/src/code/z_camera.c +++ b/soh/src/code/z_camera.c @@ -7,6 +7,7 @@ #include "overlays/actors/ovl_En_Horse/z_en_horse.h" #include "soh/frame_interpolation.h" +#include "soh/Enhancements/controls/Mouse.h" s16 Camera_ChangeSettingFlags(Camera* camera, s16 setting, s16 flags); s32 Camera_ChangeModeFlags(Camera* camera, s16 mode, u8 flags); From b67e4b6f133c44f4623a276ab1cf1d14b92bcab0 Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Thu, 12 Dec 2024 00:13:12 -0300 Subject: [PATCH 15/21] Maybe fix MacOS now --- soh/src/overlays/actors/ovl_player_actor/z_player.c | 1 + 1 file changed, 1 insertion(+) diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index 0b95f627ba7..6d8aa4683f9 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -29,6 +29,7 @@ #include "soh/Enhancements/enhancementTypes.h" #include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h" #include "soh/Enhancements/randomizer/randomizer_grotto.h" +#include "soh/Enhancements/controls/Mouse.h" #include "soh/frame_interpolation.h" #include "soh/OTRGlobals.h" #include "soh/ResourceManagerHelpers.h" From 0ea05d1d10b4391783a9095967fa75b85f191ea3 Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Thu, 12 Dec 2024 00:27:49 -0300 Subject: [PATCH 16/21] Why was it compiling with this?? --- soh/src/overlays/actors/ovl_player_actor/z_player.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index 6d8aa4683f9..75210db3f66 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -12729,7 +12729,7 @@ s16 func_8084ABD8(PlayState* play, Player* this, s32 arg2, s16 arg3) { f32 xAxisMulti = CVarGetFloat(CVAR_SETTING("FirstPersonCameraSensitivity.X"), 1.0f); f32 yAxisMulti = CVarGetFloat(CVAR_SETTING("FirstPersonCameraSensitivity.Y"), 1.0f); - Mouse_HandleFirstPerson(this, invertXAxisMulti, invertYAxisMulti, xAxisMulti, yAxisMulti); + Mouse_HandleFirstPerson(this, invertXAxisMulti, invertYAxisMulti); if (!func_8002DD78(this) && !func_808334B4(this) && (arg2 == 0)) { // First person without weapon // Y Axis From e8f5b707c9fd58c6ce88e44af3b285d96b4d34ce Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Mon, 30 Dec 2024 14:17:39 -0300 Subject: [PATCH 17/21] Mouse input viewer handling --- .../controls/SohInputEditorWindow.cpp | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/soh/soh/Enhancements/controls/SohInputEditorWindow.cpp b/soh/soh/Enhancements/controls/SohInputEditorWindow.cpp index d18ed9a1cc1..7b5a9c88e09 100644 --- a/soh/soh/Enhancements/controls/SohInputEditorWindow.cpp +++ b/soh/soh/Enhancements/controls/SohInputEditorWindow.cpp @@ -50,6 +50,7 @@ void SohInputEditorWindow::InitElement() { mDeviceIndexVisiblity.clear(); mDeviceIndexVisiblity[Ship::ShipDeviceIndex::Keyboard] = true; mDeviceIndexVisiblity[Ship::ShipDeviceIndex::Blue] = true; + mDeviceIndexVisiblity[Ship::ShipDeviceIndex::Mouse] = true; for (auto index = 1; index < Ship::ShipDeviceIndex::Max; index++) { mDeviceIndexVisiblity[static_cast(index)] = false; } @@ -176,6 +177,9 @@ void SohInputEditorWindow::DrawAnalogPreview(const char* label, ImVec2 stick, fl #define BUTTON_COLOR_KEYBOARD_BEIGE ImVec4(0.651f, 0.482f, 0.357f, 0.5f) #define BUTTON_COLOR_KEYBOARD_BEIGE_HOVERED ImVec4(0.651f, 0.482f, 0.357f, 1.0f) +#define BUTTON_COLOR_MOUSE_BEIGE ImVec4(0.5f, 0.5f, 0.5f, 0.5f) +#define BUTTON_COLOR_MOUSE_BEIGE_HOVERED ImVec4(0.5f, 0.5f, 0.5f, 1.0f) + #define BUTTON_COLOR_GAMEPAD_BLUE ImVec4(0.0f, 0.255f, 0.976f, 0.5f) #define BUTTON_COLOR_GAMEPAD_BLUE_HOVERED ImVec4(0.0f, 0.255f, 0.976f, 1.0f) @@ -198,6 +202,10 @@ void SohInputEditorWindow::GetButtonColorsForLUSDeviceIndex(Ship::ShipDeviceInde buttonColor = BUTTON_COLOR_KEYBOARD_BEIGE; buttonHoveredColor = BUTTON_COLOR_KEYBOARD_BEIGE_HOVERED; break; + case Ship::ShipDeviceIndex::Mouse: + buttonColor = BUTTON_COLOR_MOUSE_BEIGE; + buttonHoveredColor = BUTTON_COLOR_MOUSE_BEIGE_HOVERED; + break; case Ship::ShipDeviceIndex::Blue: buttonColor = BUTTON_COLOR_GAMEPAD_BLUE; buttonHoveredColor = BUTTON_COLOR_GAMEPAD_BLUE_HOVERED; @@ -277,6 +285,7 @@ void SohInputEditorWindow::DrawButtonLineEditMappingButton(uint8_t port, N64Butt icon = ICON_FA_GAMEPAD; break; case MAPPING_TYPE_KEYBOARD: + case MAPPING_TYPE_MOUSE: icon = ICON_FA_KEYBOARD_O; break; case MAPPING_TYPE_UNKNOWN: @@ -1259,6 +1268,7 @@ void SohInputEditorWindow::DrawGyroSection(uint8_t port) { void SohInputEditorWindow::DrawButtonDeviceIcons(uint8_t portIndex, std::set bitmasks) { std::set allLusDeviceIndices; allLusDeviceIndices.insert(Ship::ShipDeviceIndex::Keyboard); + allLusDeviceIndices.insert(Ship::ShipDeviceIndex::Mouse); for (auto [lusIndex, mapping] : Ship::Context::GetInstance() ->GetControlDeck() ->GetDeviceIndexMappingManager() @@ -1307,6 +1317,7 @@ void SohInputEditorWindow::DrawButtonDeviceIcons(uint8_t portIndex, std::set allLusDeviceIndices; allLusDeviceIndices.insert(Ship::ShipDeviceIndex::Keyboard); + allLusDeviceIndices.insert(Ship::ShipDeviceIndex::Mouse); for (auto [lusIndex, mapping] : Ship::Context::GetInstance() ->GetControlDeck() ->GetDeviceIndexMappingManager() @@ -1345,7 +1356,7 @@ void SohInputEditorWindow::DrawAnalogStickDeviceIcons(uint8_t portIndex, Ship::S ImGui::PushStyleColor(ImGuiCol_Button, buttonColor); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, buttonHoveredColor); ImGui::SameLine(); - if (lusIndex == Ship::ShipDeviceIndex::Keyboard) { + if (lusIndex == Ship::ShipDeviceIndex::Keyboard || lusIndex == Ship::ShipDeviceIndex::Mouse) { ImGui::SmallButton(ICON_FA_KEYBOARD_O); } else { ImGui::SmallButton(connected ? ICON_FA_GAMEPAD : ICON_FA_CHAIN_BROKEN); @@ -1692,6 +1703,19 @@ void SohInputEditorWindow::DrawDeviceVisibilityButtons() { ImGui::PopStyleColor(); ImGui::PopStyleColor(); + auto mouseButtonColor = ImGui::GetStyleColorVec4(ImGuiCol_Button); + auto mouseButtonHoveredColor = ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered); + GetButtonColorsForLUSDeviceIndex(Ship::ShipDeviceIndex::Mouse, mouseButtonColor, mouseButtonHoveredColor); + ImGui::PushStyleColor(ImGuiCol_Button, mouseButtonColor); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, mouseButtonHoveredColor); + bool mouseVisible = mDeviceIndexVisiblity[Ship::ShipDeviceIndex::Mouse]; + if (ImGui::Button(StringHelper::Sprintf("%s %s Mouse", mouseVisible ? ICON_FA_EYE : ICON_FA_EYE_SLASH, + ICON_FA_KEYBOARD_O) + .c_str())) { + mDeviceIndexVisiblity[Ship::ShipDeviceIndex::Mouse] = !mouseVisible; + } + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); for (auto [lusIndex, info] : indexMappings) { auto [name, sdlIndex] = info; @@ -1824,6 +1848,8 @@ void SohInputEditorWindow::DrawLinkTab() { UIWidgets::PaddedEnhancementSliderFloat("Swim Modifier 2: %.0f %%", "##SwimMod2", CVAR_SETTING("WalkModifier.SwimMapping2"), 0.0f, 5.0f, "", 1.0f, true, true, false, true); + + Ship::GuiWindow::EndGroupPanel(0); Ship::GuiWindow::EndGroupPanel(0); } @@ -2050,6 +2076,33 @@ void SohInputEditorWindow::DrawSetDefaultsButton(uint8_t portIndex) { } ImGui::EndPopup(); } + ImGui::PushStyleColor(ImGuiCol_Button, BUTTON_COLOR_MOUSE_BEIGE); + + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, BUTTON_COLOR_MOUSE_BEIGE_HOVERED); + if (ImGui::Button(StringHelper::Sprintf("%s Mouse", ICON_FA_KEYBOARD_O).c_str())) { + ImGui::OpenPopup("Set Defaults for Mouse"); + } + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + if (ImGui::BeginPopupModal("Set Defaults for Mouse", NULL, ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::Text("This will clear all existing mappings for\nMouse on port %d.\n\nContinue?", portIndex + 1); + if (ImGui::Button("Cancel")) { + shouldClose = true; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Set defaults")) { + Ship::Context::GetInstance() + ->GetControlDeck() + ->GetControllerByPort(portIndex) + ->ClearAllMappingsForDevice(Ship::ShipDeviceIndex::Mouse); + Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->AddDefaultMappings( + Ship::ShipDeviceIndex::Mouse); + shouldClose = true; + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + for (auto [lusIndex, info] : indexMappings) { auto [name, sdlIndex] = info; From 7e797e2941d89d3de5722745ae55c85d6e29c130 Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Mon, 30 Dec 2024 14:18:06 -0300 Subject: [PATCH 18/21] [Mouse] LUS bump --- libultraship | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libultraship b/libultraship index bd307e8edc3..7aa1d807def 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit bd307e8edc3ec4424c284484fce6233c2c618eae +Subproject commit 7aa1d807deff9bbbd8b8efc35620d4e553506414 From e2cbd3874e6c26aae6b5661aa1fd0f56bf036eab Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Sun, 5 Jan 2025 00:17:14 -0300 Subject: [PATCH 19/21] [mouse] LUS --- libultraship | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libultraship b/libultraship index 7aa1d807def..78d951e4130 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit 7aa1d807deff9bbbd8b8efc35620d4e553506414 +Subproject commit 78d951e41301a2c2fbba514f8355015669ea7541 From 2a443c4279b9e819706b564702afd29055fca759 Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Sun, 5 Jan 2025 02:22:16 -0300 Subject: [PATCH 20/21] (Mouse) bump LUS for dxgi fix --- libultraship | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libultraship b/libultraship index 78d951e4130..3e46fe77a45 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit 78d951e41301a2c2fbba514f8355015669ea7541 +Subproject commit 3e46fe77a4581a84f9c0edfab9c3a69a5320fe01 From 78d1b354a341fa723dd2463496568fb39ec6beb6 Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:13:04 -0300 Subject: [PATCH 21/21] F2 mouse notif --- soh/soh/Enhancements/controls/Mouse.cpp | 1 - soh/soh/SohGui.cpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/soh/soh/Enhancements/controls/Mouse.cpp b/soh/soh/Enhancements/controls/Mouse.cpp index 7fc9037b97a..976c796d562 100644 --- a/soh/soh/Enhancements/controls/Mouse.cpp +++ b/soh/soh/Enhancements/controls/Mouse.cpp @@ -44,7 +44,6 @@ void Mouse_RecenterCursor() { if (MOUSE_ENABLED) { u32 width = GetWindow()->GetWidth(); u32 height = GetWindow()->GetHeight(); - //fetch the movecursor LUS PR GetWindow()->SetMousePos({(s32) (width/2), (s32) (height/2)}); } } diff --git a/soh/soh/SohGui.cpp b/soh/soh/SohGui.cpp index 42ba25de2b4..6ac592ab57a 100644 --- a/soh/soh/SohGui.cpp +++ b/soh/soh/SohGui.cpp @@ -150,6 +150,7 @@ namespace SohGui { Notification::Emit({ .message = "Press - to access enhancements menu", .remainingTime = 10.0f }); #else Notification::Emit({ .message = "Press F1 to access enhancements menu", .remainingTime = 10.0f }); + Notification::Emit({ .message = "Press F2 to enable mouse controls", .remainingTime = 10.0f }); #endif }