Enhance speedRatio settings (#270 #290)

This commit changes the way the mouse sensitivity works as follows:

1. Turn speedRatio into a QPointF, so we have two floats instead of
   one integer.
2. Default the y-speedRatio to be x-speedRatio / 2.25, which takes
   the ultra-wideness of modern phone screens into account.
3. Add new configuration value speedRatioX to allow users to
   configure an individual X-ratio
4. Add new configuration value speedRatioY to allow users to
   configure an individual Y-ratio
5. Optimze distance-translation a bit.
6. Add keymaps/FRAG.json using new speedRatioX/speedRatioY for the
   game "FRAG! Pro Shooter"

Bug: #270
Bug: #290
Signed-off-by: Sven Eden <sven.eden@prydeworx.com>
This commit is contained in:
Sven Eden 2021-02-01 19:10:46 +01:00
parent b5c5188676
commit 6424af40ec
4 changed files with 154 additions and 7 deletions

View file

@ -395,8 +395,9 @@ bool InputConvertGame::processMouseMove(const QMouseEvent *from)
}
if (!m_ctrlMouseMove.lastPos.isNull() && m_processMouseMove) {
QPointF distance = from->localPos() - m_ctrlMouseMove.lastPos;
distance /= m_keyMap.getMouseMoveMap().data.mouseMove.speedRatio;
QPointF distance_raw{from->localPos() - m_ctrlMouseMove.lastPos};
QPointF speedRatio {m_keyMap.getMouseMoveMap().data.mouseMove.speedRatio};
QPointF distance {distance_raw.x() / speedRatio.x(), distance_raw.y() / speedRatio.y()};
mouseMoveStartTouch(from);
startMouseMoveTimer();

View file

@ -64,11 +64,38 @@ void KeyMap::loadKeyMap(const QString &json)
KeyMapNode keyMapNode;
keyMapNode.type = KMT_MOUSE_MOVE;
if (!checkItemDouble(mouseMoveMap, "speedRatio")) {
errorString = QString("json error: mouseMoveMap on find speedRatio");
bool have_speedRatio = false;
// General speedRatio (for backwards compatibility)
if (checkItemDouble(mouseMoveMap, "speedRatio")) {
float ratio = static_cast<float>(getItemDouble(mouseMoveMap, "speedRatio"));
keyMapNode.data.mouseMove.speedRatio.setX(ratio);
keyMapNode.data.mouseMove.speedRatio.setY(ratio / 2.25f); // Phone screens are often FHD+
have_speedRatio = true;
}
// Individual X Ratio
if (checkItemDouble(mouseMoveMap, "speedRatioX")) {
keyMapNode.data.mouseMove.speedRatio.setX(static_cast<float>(getItemDouble(mouseMoveMap, "speedRatioX")));
have_speedRatio = true;
}
// Individual Y Ratio
if (checkItemDouble(mouseMoveMap, "speedRatioY")) {
keyMapNode.data.mouseMove.speedRatio.setY(static_cast<float>(getItemDouble(mouseMoveMap, "speedRatioY")));
have_speedRatio = true;
}
if (!have_speedRatio) {
errorString = QString("json error: speedRatio setting is missing in mouseMoveMap!");
goto parseError;
}
// Sanity check: No ratio must be lower than 0.001
if ( ( keyMapNode.data.mouseMove.speedRatio.x() < 0.001f ) || ( keyMapNode.data.mouseMove.speedRatio.x() < 0.001f ) ) {
errorString = QString("json error: Minimum speedRatio is 0.001");
goto parseError;
}
keyMapNode.data.mouseMove.speedRatio = static_cast<int>(getItemDouble(mouseMoveMap, "speedRatio"));
if (!checkItemObject(mouseMoveMap, "startPos")) {
errorString = QString("json error: mouseMoveMap on find startPos");

View file

@ -91,8 +91,8 @@ public:
} drag;
struct
{
QPointF startPos = { 0.0, 0.0 };
int speedRatio = 1;
QPointF startPos = { 0.0, 0.0 };
QPointF speedRatio = { 1.0, 1.0 };
KeyNode smallEyes;
} mouseMove;
DATA() {}

119
keymap/FRAG.json Normal file
View file

@ -0,0 +1,119 @@
{
"old-switchKey": "Key_QuoteLeft",
"switchKey": "RightButton",
"mouseMoveMap": {
"startPos": {
"x": 0.5,
"y": 0.5
},
"speedRatioX": 3.25,
"speedRatioY": 1.25
},
"keyMapNodes": [{
"comment": "Steering Wheel",
"type": "KMT_STEER_WHEEL",
"centerPos": {
"x": 0.194792,
"y": 0.716484
},
"leftOffset": 0.15,
"rightOffset": 0.15,
"upOffset": 0.15,
"downOffset": 0.15,
"leftKey": "Key_A",
"rightKey": "Key_D",
"upKey": "Key_W",
"downKey": "Key_S"
},
{
"comment": "Activate item under crosshair",
"type": "KMT_CLICK",
"key": "LeftButton",
"pos": {
"x": 0.51875,
"y": 0.496703
},
"switchMap": false
},
{
"comment": "Activate first special skill",
"type": "KMT_CLICK",
"key": "Key_E",
"pos": {
"x": 0.909375,
"y": 0.542857
},
"switchMap": false
},
{
"comment": "Activate Chat",
"type": "KMT_CLICK",
"key": "Key_C",
"pos": {
"x": 0.905208,
"y": 0.254945
},
"switchMap": false
},
{
"comment": "Chat option 1",
"type": "KMT_CLICK",
"key": "Key_1",
"pos": {
"x": 0.875,
"y": 0.523077
},
"switchMap": false
},
{
"comment": "Chat option 2",
"type": "KMT_CLICK",
"key": "Key_2",
"pos": {
"x": 0.875,
"y": 0.606593
},
"switchMap": false
},
{
"comment": "Chat option 3",
"type": "KMT_CLICK",
"key": "Key_3",
"pos": {
"x": 0.875,
"y": 0.685714
},
"switchMap": false
},
{
"comment": "Chat option 4",
"type": "KMT_CLICK",
"key": "Key_4",
"pos": {
"x": 0.875,
"y": 0.756044
},
"switchMap": false
},
{
"comment": "Chat option 5",
"type": "KMT_CLICK",
"key": "Key_5",
"pos": {
"x": 0.875,
"y": 0.832967
},
"switchMap": false
},
{
"comment": "Chat option 6",
"type": "KMT_CLICK",
"key": "Key_6",
"pos": {
"x": 0.875,
"y": 0.911273
},
"switchMap": false
}
]
}