-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd6569b
commit 32a87a4
Showing
6 changed files
with
132 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "MouseKeyToAxisDirectionMapping.h" | ||
#include <spdlog/spdlog.h> | ||
#include "utils/StringHelper.h" | ||
#include "window/gui/IconsFontAwesome4.h" | ||
#include "public/bridge/consolevariablebridge.h" | ||
#include "Context.h" | ||
|
||
namespace Ship { | ||
KeyMouseToAxisDirectionMapping::MouseKeyToAxisDirectionMapping(uint8_t portIndex, Stick stick, | ||
Direction direction, MouseBtn button) | ||
: ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(button), | ||
ControllerAxisDirectionMapping(ShipDeviceIndex::Mouse, portIndex, stick, direction) { | ||
} | ||
|
||
float MouseKeyToAxisDirectionMapping::GetNormalizedAxisDirectionValue() { | ||
if (Context::GetInstance()->GetControlDeck()->MouseGameInputBlocked()) { | ||
return 0.0f; | ||
} | ||
|
||
return mKeyPressed ? MAX_AXIS_RANGE : 0.0f; | ||
} | ||
|
||
std::string MouseKeyToAxisDirectionMapping::GetAxisDirectionMappingId() { | ||
return StringHelper::Sprintf("P%d-S%d-D%d-MOUSE%d", mPortIndex, mStick, mDirection, mButton); | ||
} | ||
|
||
void MouseKeyToAxisDirectionMapping::SaveToConfig() { | ||
const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".AxisDirectionMappings." + GetAxisDirectionMappingId(); | ||
CVarSetString(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str(), | ||
"MouseKeyToAxisDirectionMapping"); | ||
CVarSetInteger(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str(), mStick); | ||
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() { | ||
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()); | ||
CVarClear(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str()); | ||
CVarClear(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str()); | ||
CVarSave(); | ||
} | ||
|
||
uint8_t MouseKeyToAxisDirectionMapping::GetMappingType() { | ||
return MAPPING_TYPE_MOUSE; | ||
} | ||
} // namespace Ship |
17 changes: 17 additions & 0 deletions
17
src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include "controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h" | ||
#include "MouseKeyToAnyMapping.h" | ||
#include "window/MouseMeta.h" | ||
|
||
namespace Ship { | ||
class MouseKeyToAxisDirectionMapping final : public MouseKeyToAnyMapping, public ControllerAxisDirectionMapping { | ||
public: | ||
MouseKeyToAxisDirectionMapping(uint8_t portIndex, Stick stick, Direction direction, MouseBtn button); | ||
float GetNormalizedAxisDirectionValue() override; | ||
std::string GetAxisDirectionMappingId() override; | ||
uint8_t GetMappingType() override; | ||
void SaveToConfig() override; | ||
void EraseFromConfig() override; | ||
}; | ||
} // namespace Ship |