mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-25 05:55:01 +00:00
feat: game keymap finish
This commit is contained in:
parent
11c4ed6a23
commit
62a9b70a37
5 changed files with 27 additions and 33 deletions
|
@ -13,7 +13,9 @@ Controller::Controller(QString gameScript, QObject* parent) : QObject(parent)
|
|||
Q_ASSERT(m_receiver);
|
||||
|
||||
if (!gameScript.isEmpty()) {
|
||||
m_inputConvert = new InputConvertGame(this);
|
||||
InputConvertGame* convertgame = new InputConvertGame(this);
|
||||
convertgame->loadKeyMap(gameScript);
|
||||
m_inputConvert = convertgame;
|
||||
} else {
|
||||
m_inputConvert = new InputConvertNormal(this);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, c
|
|||
return;
|
||||
}
|
||||
|
||||
KeyMap::KeyMapNode node = m_keyMap.getKeyMapNode(from->key());
|
||||
KeyMap::KeyMapNode& node = m_keyMap.getKeyMapNode(from->key());
|
||||
// 处理特殊按键:可以在按键映射和普通映射间切换的按键
|
||||
if (m_needSwitchGameAgain
|
||||
&& KeyMap::KMT_CLICK == node.type
|
||||
|
@ -200,7 +200,8 @@ void InputConvertGame::processSteerWheel(KeyMap::KeyMapNode &node, const QKeyEve
|
|||
}
|
||||
} else if (QEvent::KeyRelease == from->type()){
|
||||
if (0 == keysNum) {
|
||||
sendTouchUpEvent(getTouchID(node.steerWheel.firstPressKey), node.steerWheel.centerPos);
|
||||
int id = getTouchID(node.steerWheel.firstPressKey);
|
||||
sendTouchUpEvent(id, node.steerWheel.centerPos);
|
||||
detachTouchID(node.steerWheel.firstPressKey);
|
||||
node.steerWheel.firstPressKey = 0;
|
||||
} else if (1 == keysNum) {
|
||||
|
@ -328,7 +329,7 @@ void InputConvertGame::processKeyClick(QPointF clickPos, bool clickTwice, bool s
|
|||
|
||||
bool InputConvertGame::processMouseClick(const QMouseEvent *from)
|
||||
{
|
||||
KeyMap::KeyMapNode node = m_keyMap.getKeyMapNode(from->button());
|
||||
KeyMap::KeyMapNode& node = m_keyMap.getKeyMapNode(from->button());
|
||||
if (KeyMap::KMT_INVALID == node.type) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ QString KeyMap::s_keyMapPath = "";
|
|||
KeyMap::KeyMap(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
loadKeyMap("");
|
||||
|
||||
}
|
||||
|
||||
KeyMap::~KeyMap()
|
||||
|
@ -37,7 +37,6 @@ const QString& KeyMap::getKeyMapPath()
|
|||
void KeyMap::loadKeyMap(const QString &json)
|
||||
{
|
||||
QString errorString;
|
||||
QByteArray allData;
|
||||
QJsonParseError jsonError;
|
||||
QJsonDocument jsonDoc;
|
||||
QJsonObject rootObj;
|
||||
|
@ -46,7 +45,7 @@ void KeyMap::loadKeyMap(const QString &json)
|
|||
QMetaEnum metaEnumMouseButtons = QMetaEnum::fromType<Qt::MouseButtons>();
|
||||
QMetaEnum metaEnumKeyMapType = QMetaEnum::fromType<KeyMap::KeyMapType>();
|
||||
|
||||
jsonDoc = QJsonDocument::fromJson(allData, &jsonError);
|
||||
jsonDoc = QJsonDocument::fromJson(json.toUtf8(), &jsonError);
|
||||
|
||||
if(jsonError.error != QJsonParseError::NoError)
|
||||
{
|
||||
|
@ -255,44 +254,35 @@ parseError:
|
|||
return;
|
||||
}
|
||||
|
||||
KeyMap::KeyMapNode KeyMap::getKeyMapNode(int key)
|
||||
KeyMap::KeyMapNode& KeyMap::getKeyMapNode(int key)
|
||||
{
|
||||
KeyMapNode retNode;
|
||||
bool find = false;
|
||||
for (auto& node : m_keyMapNodes) {
|
||||
switch (node.type) {
|
||||
for (auto& itemNode : m_keyMapNodes) {
|
||||
switch (itemNode.type) {
|
||||
case KMT_CLICK:
|
||||
if (node.click.keyNode.key == key) {
|
||||
retNode = node;
|
||||
find = true;
|
||||
if (itemNode.click.keyNode.key == key) {
|
||||
return itemNode;
|
||||
}
|
||||
break;
|
||||
case KMT_CLICK_TWICE:
|
||||
if (node.clickTwice.keyNode.key == key) {
|
||||
retNode = node;
|
||||
find = true;
|
||||
if (itemNode.clickTwice.keyNode.key == key) {
|
||||
return itemNode;
|
||||
}
|
||||
break;
|
||||
case KMT_STEER_WHEEL:
|
||||
if (node.steerWheel.leftKey == key
|
||||
|| node.steerWheel.rightKey == key
|
||||
|| node.steerWheel.upKey == key
|
||||
|| node.steerWheel.downKey == key
|
||||
if (itemNode.steerWheel.leftKey == key
|
||||
|| itemNode.steerWheel.rightKey == key
|
||||
|| itemNode.steerWheel.upKey == key
|
||||
|| itemNode.steerWheel.downKey == key
|
||||
) {
|
||||
retNode = node;
|
||||
find = true;
|
||||
return itemNode;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (find) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return retNode;
|
||||
return m_invalidNode;
|
||||
}
|
||||
|
||||
int KeyMap::getSwitchKey()
|
||||
|
|
|
@ -74,7 +74,7 @@ public:
|
|||
virtual ~KeyMap();
|
||||
|
||||
void loadKeyMap(const QString &json);
|
||||
KeyMap::KeyMapNode getKeyMapNode(int key);
|
||||
KeyMap::KeyMapNode& getKeyMapNode(int key);
|
||||
int getSwitchKey();
|
||||
MouseMoveMap getMouseMoveMap();
|
||||
bool enableMouseMoveMap();
|
||||
|
@ -83,6 +83,7 @@ public:
|
|||
|
||||
private:
|
||||
QVector<KeyMapNode> m_keyMapNodes;
|
||||
KeyMapNode m_invalidNode;
|
||||
int m_switchKey = Qt::Key_QuoteLeft;
|
||||
MouseMoveMap m_mouseMoveMap;
|
||||
static QString s_keyMapPath;
|
||||
|
|
|
@ -364,10 +364,10 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="10" colspan="2">
|
||||
<item row="3" column="9" colspan="4">
|
||||
<widget class="QCheckBox" name="gameCheck">
|
||||
<property name="text">
|
||||
<string>Game for Peace</string>
|
||||
<string>custom map</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Add table
Reference in a new issue