From 0abbc9f4f4633cc14febfb6fb3a0af79701d07af Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Sun, 10 Dec 2023 13:06:26 +0200 Subject: [PATCH] * Fix bad mouse controls on desktop. --- source/client/app/Minecraft.cpp | 23 ++++++++++++------- .../player/input/BuildActionIntention.hpp | 20 ++++++++++++---- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/source/client/app/Minecraft.cpp b/source/client/app/Minecraft.cpp index 19f9238..d1f9a64 100644 --- a/source/client/app/Minecraft.cpp +++ b/source/client/app/Minecraft.cpp @@ -359,16 +359,23 @@ void Minecraft::handleMouseClick(int type) { if (!isTouchscreen()) { - if (type == 1) + eBuildActionIntent intent; + switch (type) { - BuildActionIntention bai(INTENT_HELD); - handleBuildAction(&bai); - } - if (type == 2) - { - BuildActionIntention bai(INTENT_CLICKED); - handleBuildAction(&bai); + case BUTTON_LEFT: + intent = INTENT_MOUSE_LEFTCLICK; + break; + case BUTTON_RIGHT: + intent = INTENT_MOUSE_RIGHTCLICK; + break; + case BUTTON_MIDDLE: + intent = INTENT_MOUSE_MIDDLECLICK; + break; + } + + BuildActionIntention bai(intent); + handleBuildAction(&bai); } } diff --git a/source/client/player/input/BuildActionIntention.hpp b/source/client/player/input/BuildActionIntention.hpp index ef62f59..6b812e3 100644 --- a/source/client/player/input/BuildActionIntention.hpp +++ b/source/client/player/input/BuildActionIntention.hpp @@ -13,6 +13,10 @@ enum eBuildActionIntent INTENT_CLICKED = 1, // touch screen was clicked INTENT_HELD = 2, // touch screen is being held down INTENT_FIRST_REMOVE = 10, // after a small delay, starts breaking with this as a signal + + INTENT_MOUSE_LEFTCLICK = 16, + INTENT_MOUSE_RIGHTCLICK = 17, + INTENT_MOUSE_MIDDLECLICK = 18, }; class BuildActionIntention @@ -22,15 +26,19 @@ public: BuildActionIntention(int type) : m_type(type) {} bool isAttack() const { - return m_type == INTENT_CLICKED; + return m_type == INTENT_CLICKED || m_type == INTENT_MOUSE_LEFTCLICK; } bool isFirstRemove() const { - return m_type == INTENT_FIRST_REMOVE; + return m_type == INTENT_FIRST_REMOVE || m_type == INTENT_MOUSE_LEFTCLICK; } bool isInteract() const { - return m_type == INTENT_HELD; + return m_type == INTENT_HELD || m_type == INTENT_MOUSE_RIGHTCLICK; + } + + bool isBuild() { + return m_type == INTENT_CLICKED || m_type == INTENT_MOUSE_RIGHTCLICK; } bool isRemove() const { @@ -38,7 +46,11 @@ public: } bool isRemoveContinue() const { - return m_type == INTENT_HELD; + return m_type == INTENT_HELD || m_type == INTENT_MOUSE_LEFTCLICK; + } + + bool isPick() const { + return m_type == INTENT_MOUSE_MIDDLECLICK; } private: