Skip to content

Commit

Permalink
MouseKey -> MouseButton
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmanLP committed Dec 18, 2024
1 parent 57be37f commit b1c5c65
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 48 deletions.
8 changes: 4 additions & 4 deletions src/controller/controldevice/controller/ControllerButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h"

#include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h"
#include "controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h"
#include "controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.h"

#include "public/bridge/consolevariablebridge.h"
#include "utils/StringHelper.h"
Expand Down Expand Up @@ -183,7 +183,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi
mapping = std::make_shared<KeyboardKeyToButtonMapping>(mPortIndex, bitmask, mKeyboardScancodeForNewMapping);
} else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) {
// TODO: I dont think direct ImGui calls should be here
mapping = std::make_shared<MouseKeyToButtonMapping>(mPortIndex, bitmask, mMouseButtonForNewMapping);
mapping = std::make_shared<MouseButtonToButtonMapping>(mPortIndex, bitmask, mMouseButtonForNewMapping);
} else {
mapping = ButtonMappingFactory::CreateButtonMappingFromSDLInput(mPortIndex, bitmask);
}
Expand Down Expand Up @@ -246,8 +246,8 @@ bool ControllerButton::ProcessMouseEvent(bool isPressed, MouseBtn button) {
bool result = false;
for (auto [id, mapping] : GetAllButtonMappings()) {
if (mapping->GetMappingType() == MAPPING_TYPE_MOUSE) {
std::shared_ptr<MouseKeyToButtonMapping> mtobMapping =
std::dynamic_pointer_cast<MouseKeyToButtonMapping>(mapping);
std::shared_ptr<MouseButtonToButtonMapping> mtobMapping =
std::dynamic_pointer_cast<MouseButtonToButtonMapping>(mapping);
if (mtobMapping != nullptr) {
result = result || mtobMapping->ProcessMouseEvent(isPressed, button);
}
Expand Down
8 changes: 4 additions & 4 deletions src/controller/controldevice/controller/ControllerStick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <spdlog/spdlog.h>

#include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h"
#include "controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h"
#include "controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h"

#include "controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.h"

Expand Down Expand Up @@ -278,7 +278,7 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct
mKeyboardScancodeForNewMapping);
} else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) {
// TODO: I dont think direct ImGui calls should be here (again)
mapping = std::make_shared<MouseKeyToAxisDirectionMapping>(mPortIndex, mStickIndex, direction,
mapping = std::make_shared<MouseButtonToAxisDirectionMapping>(mPortIndex, mStickIndex, direction,
mMouseButtonForNewMapping);
} else {
mapping =
Expand Down Expand Up @@ -364,8 +364,8 @@ bool ControllerStick::ProcessMouseEvent(bool isPressed, MouseBtn button) {
for (auto [direction, mappings] : mAxisDirectionMappings) {
for (auto [id, mapping] : mappings) {
if (mapping->GetMappingType() == MAPPING_TYPE_MOUSE) {
std::shared_ptr<MouseKeyToAxisDirectionMapping> mtoadMapping =
std::dynamic_pointer_cast<MouseKeyToAxisDirectionMapping>(mapping);
std::shared_ptr<MouseButtonToAxisDirectionMapping> mtoadMapping =
std::dynamic_pointer_cast<MouseButtonToAxisDirectionMapping>(mapping);
if (mtoadMapping != nullptr) {
result = result || mtoadMapping->ProcessMouseEvent(isPressed, button);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "AxisDirectionMappingFactory.h"
#include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h"
#include "controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h"
#include "controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h"

#include "controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.h"
#include "controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.h"
Expand Down Expand Up @@ -78,7 +78,7 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn
portIndex, stickIndex, static_cast<Direction>(direction), static_cast<KbScancode>(scancode));
}

if (mappingClass == "MouseKeyToAxisDirectionMapping") {
if (mappingClass == "MouseButtonToAxisDirectionMapping") {
int32_t direction = CVarGetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), -1);
int mouseButton = CVarGetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), 0);

Expand All @@ -89,7 +89,7 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn
return nullptr;
}

return std::make_shared<MouseKeyToAxisDirectionMapping>(
return std::make_shared<MouseButtonToAxisDirectionMapping>(
portIndex, stickIndex, static_cast<Direction>(direction), static_cast<MouseBtn>(mouseButton));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "libultraship/libultra/controller.h"
#include "Context.h"
#include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h"
#include "controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h"
#include "controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.h"
#include "controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.h"
#include "controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h"
#include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h"
Expand Down Expand Up @@ -68,10 +68,10 @@ std::shared_ptr<ControllerButtonMapping> ButtonMappingFactory::CreateButtonMappi
return std::make_shared<KeyboardKeyToButtonMapping>(portIndex, bitmask, static_cast<KbScancode>(scancode));
}

if (mappingClass == "MouseKeyToButtonMapping") {
if (mappingClass == "MouseButtonToButtonMapping") {
int mouseButton = CVarGetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), 0);

return std::make_shared<MouseKeyToButtonMapping>(portIndex, bitmask, static_cast<MouseBtn>(mouseButton));
return std::make_shared<MouseButtonToButtonMapping>(portIndex, bitmask, static_cast<MouseBtn>(mouseButton));
}

return nullptr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#include "MouseKeyToAnyMapping.h"
#include "MouseButtonToAnyMapping.h"
#include "Context.h"

#include "utils/StringHelper.h"
#include "window/gui/IconsFontAwesome4.h"

namespace Ship {
MouseKeyToAnyMapping::MouseKeyToAnyMapping(MouseBtn button)
MouseButtonToAnyMapping::MouseButtonToAnyMapping(MouseBtn button)
: ControllerInputMapping(ShipDeviceIndex::Mouse), mButton(button), mKeyPressed(false) {
}

MouseKeyToAnyMapping::~MouseKeyToAnyMapping() {
MouseButtonToAnyMapping::~MouseButtonToAnyMapping() {
}

std::string MouseKeyToAnyMapping::GetPhysicalInputName() {
std::string MouseButtonToAnyMapping::GetPhysicalInputName() {
return mouseBtnNames[static_cast<int>(mButton)];
}

bool MouseKeyToAnyMapping::ProcessMouseEvent(bool isPressed, MouseBtn button) {
bool MouseButtonToAnyMapping::ProcessMouseEvent(bool isPressed, MouseBtn button) {
if (mButton != button) {
return false;
}
Expand All @@ -25,11 +25,11 @@ bool MouseKeyToAnyMapping::ProcessMouseEvent(bool isPressed, MouseBtn button) {
return true;
}

std::string MouseKeyToAnyMapping::GetPhysicalDeviceName() {
std::string MouseButtonToAnyMapping::GetPhysicalDeviceName() {
return "Mouse";
}

bool MouseKeyToAnyMapping::PhysicalDeviceIsConnected() {
bool MouseButtonToAnyMapping::PhysicalDeviceIsConnected() {
return true;
}
} // namespace Ship
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"

namespace Ship {
class MouseKeyToAnyMapping : virtual public ControllerInputMapping {
class MouseButtonToAnyMapping : virtual public ControllerInputMapping {
public:
MouseKeyToAnyMapping(MouseBtn button);
~MouseKeyToAnyMapping();
MouseButtonToAnyMapping(MouseBtn button);
~MouseButtonToAnyMapping();
std::string GetPhysicalInputName() override;
bool ProcessMouseEvent(bool isPressed, MouseBtn button);
std::string GetPhysicalDeviceName() override;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
#include "MouseKeyToAxisDirectionMapping.h"
#include "MouseButtonToAxisDirectionMapping.h"
#include <spdlog/spdlog.h>
#include "utils/StringHelper.h"
#include "window/gui/IconsFontAwesome4.h"
#include "public/bridge/consolevariablebridge.h"
#include "Context.h"

namespace Ship {
MouseKeyToAxisDirectionMapping::MouseKeyToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex,
MouseButtonToAxisDirectionMapping::MouseButtonToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex,
Direction direction, MouseBtn button)
: ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(button),
: ControllerInputMapping(ShipDeviceIndex::Mouse), MouseButtonToAnyMapping(button),
ControllerAxisDirectionMapping(ShipDeviceIndex::Mouse, portIndex, stickIndex, direction) {
}

float MouseKeyToAxisDirectionMapping::GetNormalizedAxisDirectionValue() {
float MouseButtonToAxisDirectionMapping::GetNormalizedAxisDirectionValue() {
if (Context::GetInstance()->GetControlDeck()->MouseGameInputBlocked()) {
return 0.0f;
}

return mKeyPressed ? MAX_AXIS_RANGE : 0.0f;
}

std::string MouseKeyToAxisDirectionMapping::GetAxisDirectionMappingId() {
std::string MouseButtonToAxisDirectionMapping::GetAxisDirectionMappingId() {
return StringHelper::Sprintf("P%d-S%d-D%d-MOUSE%d", mPortIndex, mStickIndex, mDirection, mButton);
}

void MouseKeyToAxisDirectionMapping::SaveToConfig() {
void MouseButtonToAxisDirectionMapping::SaveToConfig() {
const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".AxisDirectionMappings." + GetAxisDirectionMappingId();
CVarSetString(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str(),
"MouseKeyToAxisDirectionMapping");
"MouseButtonToAxisDirectionMapping");
CVarSetInteger(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str(), mStickIndex);
CVarSetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), mDirection);
CVarSetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), static_cast<int>(mButton));
CVarSave();
}

void MouseKeyToAxisDirectionMapping::EraseFromConfig() {
void MouseButtonToAxisDirectionMapping::EraseFromConfig() {
const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".AxisDirectionMappings." + GetAxisDirectionMappingId();
CVarClear(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str());
CVarClear(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str());
Expand All @@ -43,7 +43,7 @@ void MouseKeyToAxisDirectionMapping::EraseFromConfig() {
CVarSave();
}

uint8_t MouseKeyToAxisDirectionMapping::GetMappingType() {
uint8_t MouseButtonToAxisDirectionMapping::GetMappingType() {
return MAPPING_TYPE_MOUSE;
}
} // namespace Ship
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once

#include "controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h"
#include "MouseKeyToAnyMapping.h"
#include "MouseButtonToAnyMapping.h"
#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"

namespace Ship {
class MouseKeyToAxisDirectionMapping final : public MouseKeyToAnyMapping, public ControllerAxisDirectionMapping {
class MouseButtonToAxisDirectionMapping final : public MouseButtonToAnyMapping, public ControllerAxisDirectionMapping {
public:
MouseKeyToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction, MouseBtn button);
MouseButtonToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction, MouseBtn button);
float GetNormalizedAxisDirectionValue() override;
std::string GetAxisDirectionMappingId() override;
uint8_t GetMappingType() override;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "MouseKeyToButtonMapping.h"
#include "MouseButtonToButtonMapping.h"
#include <spdlog/spdlog.h>
#include "utils/StringHelper.h"
#include "public/bridge/consolevariablebridge.h"
#include "Context.h"

namespace Ship {
MouseKeyToButtonMapping::MouseKeyToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button)
: ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(button),
MouseButtonToButtonMapping::MouseButtonToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button)
: ControllerInputMapping(ShipDeviceIndex::Mouse), MouseButtonToAnyMapping(button),
ControllerButtonMapping(ShipDeviceIndex::Mouse, portIndex, bitmask) {
}

void MouseKeyToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) {
void MouseButtonToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) {
if (Context::GetInstance()->GetControlDeck()->MouseGameInputBlocked()) {
return;
}
Expand All @@ -22,24 +22,24 @@ void MouseKeyToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) {
padButtons |= mBitmask;
}

uint8_t MouseKeyToButtonMapping::GetMappingType() {
uint8_t MouseButtonToButtonMapping::GetMappingType() {
return MAPPING_TYPE_MOUSE;
}

std::string MouseKeyToButtonMapping::GetButtonMappingId() {
std::string MouseButtonToButtonMapping::GetButtonMappingId() {
return StringHelper::Sprintf("P%d-B%d-MOUSE%d", mPortIndex, mBitmask, mButton);
}

void MouseKeyToButtonMapping::SaveToConfig() {
void MouseButtonToButtonMapping::SaveToConfig() {
const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".ButtonMappings." + GetButtonMappingId();
CVarSetString(StringHelper::Sprintf("%s.ButtonMappingClass", mappingCvarKey.c_str()).c_str(),
"MouseKeyToButtonMapping");
"MouseButtonToButtonMapping");
CVarSetInteger(StringHelper::Sprintf("%s.Bitmask", mappingCvarKey.c_str()).c_str(), mBitmask);
CVarSetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), static_cast<int>(mButton));
CVarSave();
}

void MouseKeyToButtonMapping::EraseFromConfig() {
void MouseButtonToButtonMapping::EraseFromConfig() {
const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".ButtonMappings." + GetButtonMappingId();

CVarClear(StringHelper::Sprintf("%s.ButtonMappingClass", mappingCvarKey.c_str()).c_str());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once

#include "controller/controldevice/controller/mapping/ControllerButtonMapping.h"
#include "MouseKeyToAnyMapping.h"
#include "MouseButtonToAnyMapping.h"
#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"

namespace Ship {
class MouseKeyToButtonMapping final : public MouseKeyToAnyMapping, public ControllerButtonMapping {
class MouseButtonToButtonMapping final : public MouseButtonToAnyMapping, public ControllerButtonMapping {
public:
MouseKeyToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button);
MouseButtonToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button);
void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override;
uint8_t GetMappingType() override;
std::string GetButtonMappingId() override;
Expand Down

0 comments on commit b1c5c65

Please sign in to comment.