From 7cc32d79c63c675ce9ee85b9978aedbbba392a8d Mon Sep 17 00:00:00 2001 From: AkiChase <1003019131@qq.com> Date: Fri, 17 May 2024 22:30:58 +0800 Subject: [PATCH 01/11] feat(hotkey): finish addFrontSightShortcuts --- src-tauri/capabilities/default.json | 2 + src/components/Mask.vue | 3 +- src/hotkey.ts | 496 ++++++++++++++++------------ 3 files changed, 280 insertions(+), 221 deletions(-) diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 6f3aadd..8b1ebe9 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -14,6 +14,8 @@ "window:allow-is-maximizable", "window:allow-start-dragging", "window:allow-unmaximize", + "window:allow-set-cursor-position", + "window:allow-set-cursor-visible", "store:default", "store:allow-get", "store:allow-set", diff --git a/src/components/Mask.vue b/src/components/Mask.vue index 6d2611b..bab7646 100644 --- a/src/components/Mask.vue +++ b/src/components/Mask.vue @@ -51,7 +51,8 @@ onActivated(async () => { if ( applyShortcuts( maskElement, - store.keyMappingConfigList[store.curKeyMappingIndex] + store.keyMappingConfigList[store.curKeyMappingIndex], + message ) ) { listenToEvent(); diff --git a/src/hotkey.ts b/src/hotkey.ts index 7050a24..43b94e7 100644 --- a/src/hotkey.ts +++ b/src/hotkey.ts @@ -1,4 +1,5 @@ // https://github.com/jamiebuilds/tinykeys/pull/193/commits/2598ecb3db6b3948c7acbf0e7bd8b0674961ad61 +import { useMessage } from "naive-ui"; import { SwipeAction, TouchAction, @@ -19,6 +20,7 @@ import { KeyTriggerWhenPressedSkill, } from "./keyMappingConfig"; import { useGlobalStore } from "./store/global"; +import { LogicalPosition, getCurrent } from "@tauri-apps/api/window"; function clientxToPosx(clientx: number) { return clientx < 70 @@ -158,46 +160,23 @@ function addObservationShortcuts( async () => { observationMouseX = clientxToPosx(mouseX); observationMouseY = clientyToPosy(mouseY); - await touch({ - action: TouchAction.Down, - pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX, - y: posY, - }, - }); + await touchX(TouchAction.Down, pointerId, posX, posY); }, async () => { - await touch({ - action: TouchAction.Move, + await touchX( + TouchAction.Move, pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX + clientxToPosOffsetx(mouseX, observationMouseX, scale), - y: posY + clientyToPosOffsety(mouseY, observationMouseY, scale), - }, - }); + posX + clientxToPosOffsetx(mouseX, observationMouseX, scale), + posY + clientyToPosOffsety(mouseY, observationMouseY, scale) + ); }, async () => { - await touch({ - action: TouchAction.Up, + await touchX( + TouchAction.Up, pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX + clientxToPosOffsetx(mouseX, observationMouseY, scale), - y: posY + clientyToPosOffsety(mouseY, observationMouseY, scale), - }, - }); + posX + clientxToPosOffsetx(mouseX, observationMouseY, scale), + posY + clientyToPosOffsety(mouseY, observationMouseY, scale) + ); } ); } @@ -216,19 +195,7 @@ function addTapShortcuts( addShortcut( key, async () => { - await touch({ - action: TouchAction.Default, - pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX, - y: posY, - }, - time, - }); + await touchX(TouchAction.Default, pointerId, posX, posY, time); }, undefined, undefined @@ -262,33 +229,11 @@ function addCancelSkillShortcuts( } let distance = 0; while (distance <= 20) { - await touch({ - action: TouchAction.Move, - pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX + distance, - y: posY, - }, - }); + await touchX(TouchAction.Move, pointerId, posX + distance, posY); await sleep(5); distance += 1; } - await touch({ - action: TouchAction.Up, - pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX, - y: posY, - }, - }); + await touchX(TouchAction.Up, pointerId, posX, posY); }, undefined, undefined @@ -346,19 +291,7 @@ function addTriggerWhenPressedSkillShortcuts( key, async () => { await upDoublePressedKey(); - await touch({ - action: TouchAction.Default, - pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX, - y: posY, - }, - time: rangeOrTime, - }); + await touchX(TouchAction.Default, pointerId, posX, posY, rangeOrTime); }, undefined, undefined @@ -414,18 +347,12 @@ function addTriggerWhenDoublePressedSkillShortcuts( { x: mouseX, y: mouseY }, range ); - await touch({ - action: TouchAction.Move, + await touchX( + TouchAction.Move, pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX + loopSkillOffset.offsetX, - y: posY + loopSkillOffset.offsetY, - }, - }); + posX + loopSkillOffset.offsetX, + posY + loopSkillOffset.offsetY + ); }); } else { // second press: touch up @@ -435,18 +362,12 @@ function addTriggerWhenDoublePressedSkillShortcuts( { x: mouseX, y: mouseY }, range ); - await touch({ - action: TouchAction.Up, + await touchX( + TouchAction.Up, pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX + skillOffset.offsetX, - y: posY + skillOffset.offsetY, - }, - }); + posX + skillOffset.offsetX, + posY + skillOffset.offsetY + ); // set the flag to false doublePressedDownKey.set(key, false); } @@ -473,18 +394,7 @@ function addDirectionlessSkillShortcuts( async () => { // up doublepress skill await upDoublePressedKey(); - await touch({ - action: TouchAction.Down, - pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX, - y: posY, - }, - }); + await touchX(TouchAction.Down, pointerId, posX, posY); }, // loop undefined, @@ -561,18 +471,12 @@ function addDirectionalSkillShortcuts( { x: mouseX, y: mouseY }, range ); - await touch({ - action: TouchAction.Move, + await touchX( + TouchAction.Move, pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX + skillOffset.offsetX, - y: posY + skillOffset.offsetY, - }, - }); + posX + skillOffset.offsetX, + posY + skillOffset.offsetY + ); }, // up async () => { @@ -580,18 +484,12 @@ function addDirectionalSkillShortcuts( { x: mouseX, y: mouseY }, range ); - await touch({ - action: TouchAction.Up, + await touchX( + TouchAction.Up, pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX + skillOffset.offsetX, - y: posY + skillOffset.offsetY, - }, - }); + posX + skillOffset.offsetX, + posY + skillOffset.offsetY + ); }, true ); @@ -657,15 +555,7 @@ function addSteeringWheelKeyboardShortcuts( curPosX = newPos.x; curPosY = newPos.y; // move to the direction - await touch({ - action: TouchAction.Move, - pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: newPos, - }); + await touchX(TouchAction.Move, pointerId, newPos.x, newPos.y); }; const unitedUpCB = async () => { @@ -682,18 +572,7 @@ function addSteeringWheelKeyboardShortcuts( upKeyCBMap.delete(key[k]); } // touch up - await touch({ - action: TouchAction.Up, - pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: curPosX, - y: curPosY, - }, - }); + await touchX(TouchAction.Up, pointerId, curPosX, curPosY); // recover the status curPosX = 0; curPosY = 0; @@ -711,18 +590,7 @@ function addSteeringWheelKeyboardShortcuts( upKeyCBMap.set(key[k], unitedUpCB); // touch down on the center position - await touch({ - action: TouchAction.Down, - pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: posX, - y: posY, - }, - }); + await touchX(TouchAction.Down, pointerId, posX, posY); // add loopCB loopDownKeyCBMap.set(key[k], unitedloopCB); }, @@ -745,50 +613,216 @@ function addClickShortcuts(key: string, pointerId: number) { addShortcut( key, async () => { - await touch({ - action: TouchAction.Down, + await touchX( + TouchAction.Down, pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: clientxToPosx(mouseX), - y: clientyToPosy(mouseY), - }, - }); + clientxToPosx(mouseX), + clientyToPosy(mouseY) + ); }, async () => { - await touch({ - action: TouchAction.Move, + await touchX( + TouchAction.Move, pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: clientxToPosx(mouseX), - y: clientyToPosy(mouseY), - }, - }); + clientxToPosx(mouseX), + clientyToPosy(mouseY) + ); }, async () => { - await touch({ - action: TouchAction.Up, + await touchX( + TouchAction.Up, pointerId, - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: clientxToPosx(mouseX), - y: clientyToPosy(mouseY), - }, - }); + clientxToPosx(mouseX), + clientyToPosy(mouseY) + ); } ); } +function addFrontSightShortcuts() { + // TODO 1. 补上开火键 2. i18n 3. 单独函数,同时配合可视化组件 4. 组件配置中唯一 + const appWindow = getCurrent(); + + // TODO cal it + const hasFireKey = true; + + const fireKeyMapping = { + type: "Fire", + pointerId: 2, + note: "开火键", + posX: 300, + posY: 300, + drag: true, + }; + + let mouseLock = false; + let msgReactive: ReturnType | null = null; + const key = "KeyH"; + const centerX = 70 + maskSizeW / 2; + const centerY = 30 + maskSizeH / 2; + const centerPosX = screenSizeW / 2; + const centerPosY = screenSizeH / 2; + const scaleX = 0.5; + const scaleY = 0.5; + + const removeShortcut = (key: string) => { + loopDownKeyCBMap.delete(key); + downKeyCBMap.delete(key); + upKeyCBMap.delete(key); + downKeyMap.delete(key); + }; + + const touchRelateToCenter = async (action: TouchAction) => { + await touchX( + action, + 0, + centerPosX + clientxToPosOffsetx(mouseX, centerPosX, scaleX), + centerPosY + clientyToPosOffsety(mouseY, centerPosY, scaleY) + ); + }; + + const sightLoopCB = async () => { + await touchRelateToCenter(TouchAction.Move); + }; + + const moveLeaveHandler = async () => { + // stop loop touch move + loopDownKeyCBMap.delete(key); + // touch up + await touchRelateToCenter(TouchAction.Up); + await sleep(150); + // move mouse + appWindow.setCursorPosition(new LogicalPosition(centerX, centerY)); + mouseX = centerX; + mouseY = centerY; + // touch down + touchX(TouchAction.Down, 0, centerPosX, centerPosY); + // start loop touch move + loopDownKeyCBMap.set(key, sightLoopCB); + }; + + // add sight shortcut + addShortcut(key, async () => { + if (mouseLock) { + // stop sight mode + loopDownKeyCBMap.delete(key); + await touchRelateToCenter(TouchAction.Up); + await appWindow.setCursorVisible(true); + maskElement.removeEventListener("mouseleave", moveLeaveHandler); + mouseLock = false; + if (msgReactive) { + msgReactive.destroy(); + msgReactive = null; + } + // remove fire key + if (hasFireKey) { + removeShortcut("M0"); + } + // add click + addClickShortcuts("M0", 0); + } else { + // start sight mode + await appWindow.setCursorVisible(false); + maskElement.addEventListener("mouseleave", moveLeaveHandler); + mouseLock = true; + msgReactive = message.info(`鼠标已锁定, 按 ${key} 键解锁`, { + duration: 0, + }); + + await touchX(TouchAction.Down, 0, centerPosX, centerPosY); + await appWindow.setCursorPosition(new LogicalPosition(centerX, centerY)); + mouseX = centerX; + mouseY = centerY; + loopDownKeyCBMap.set(key, sightLoopCB); + // remove click + removeShortcut("M0"); + // add fire key + if (hasFireKey) { + if (fireKeyMapping.drag) { + addShortcut( + "M0", + async () => { + // stop sight loop + loopDownKeyCBMap.delete(key); + await touchRelateToCenter(TouchAction.Up); + // move cursor to center + await appWindow.setCursorPosition( + new LogicalPosition(centerX, centerY) + ); + mouseX = centerX; + mouseY = centerY; + // touch down fire + await touchX( + TouchAction.Down, + fireKeyMapping.pointerId, + fireKeyMapping.posX, + fireKeyMapping.posY + ); + }, + async () => { + await touchX( + TouchAction.Move, + fireKeyMapping.pointerId, + fireKeyMapping.posX + + clientxToPosOffsetx(mouseX, centerPosX, scaleX), + fireKeyMapping.posY + + clientyToPosOffsety(mouseY, centerPosY, scaleY) + ); + }, + async () => { + // touch up fire + await touchX( + TouchAction.Up, + fireKeyMapping.pointerId, + fireKeyMapping.posX + + clientxToPosOffsetx(mouseX, centerPosX, scaleX), + fireKeyMapping.posY + + clientyToPosOffsety(mouseY, centerPosY, scaleY) + ); + // start sight loop + await touchX(TouchAction.Down, 0, centerPosX, centerPosY); + await appWindow.setCursorPosition( + new LogicalPosition(centerX, centerY) + ); + mouseX = centerX; + mouseY = centerY; + loopDownKeyCBMap.set(key, sightLoopCB); + } + ); + } else { + addShortcut( + "M0", + async () => { + await touchX( + TouchAction.Down, + fireKeyMapping.pointerId, + fireKeyMapping.posX, + fireKeyMapping.posY + ); + }, + async () => { + await touchX( + TouchAction.Move, + fireKeyMapping.pointerId, + fireKeyMapping.posX, + fireKeyMapping.posY + ); + }, + async () => { + await touchX( + TouchAction.Up, + fireKeyMapping.pointerId, + fireKeyMapping.posX, + fireKeyMapping.posY + ); + } + ); + } + } + } + }); +} + let screenSizeW: number; let screenSizeH: number; let maskSizeW: number; @@ -796,6 +830,7 @@ let maskSizeH: number; let mouseX = 0; let mouseY = 0; let maskElement: HTMLElement; +let message: ReturnType; const downKeyMap: Map = new Map(); const downKeyCBMap: Map Promise> = new Map(); @@ -1008,19 +1043,13 @@ async function execMacro( console.error("Invalid touch action: ", cmd.args[0]); return; } - await touch({ - action: touchAction, - pointerId: cmd.args[1], - screen: { - w: screenSizeW, - h: screenSizeH, - }, - pos: { - x: calculateMacroPosX(cmd.args[2], relativeSize.w), - y: calculateMacroPosY(cmd.args[3], relativeSize.h), - }, - time: cmd.args.length > 4 ? cmd.args[4] : undefined, - }); + await touchX( + touchAction, + cmd.args[1], + calculateMacroPosX(cmd.args[2], relativeSize.w), + calculateMacroPosY(cmd.args[3], relativeSize.h), + cmd.args.length > 4 ? cmd.args[4] : undefined + ); break; case "swipe": let swipeAction; @@ -1208,6 +1237,28 @@ function applyKeyMappingConfigShortcuts( } } +async function touchX( + action: TouchAction, + pointerId: number, + posX: number, + posY: number, + time?: number +) { + await touch({ + action, + pointerId, + screen: { + w: screenSizeW, + h: screenSizeH, + }, + pos: { + x: posX, + y: posY, + }, + time, + }); +} + export function listenToEvent() { window.addEventListener("keydown", handleKeydown); window.addEventListener("keyup", handleKeyup); @@ -1250,9 +1301,14 @@ export function updateScreenSizeAndMaskArea( export function applyShortcuts( element: HTMLElement, - keyMappingConfig: KeyMappingConfig + keyMappingConfig: KeyMappingConfig, + messageAPI: ReturnType ) { maskElement = element; + message = messageAPI; addClickShortcuts("M0", 0); + + addFrontSightShortcuts(); + return applyKeyMappingConfigShortcuts(keyMappingConfig); } From 8b848e5a72a15b3169d2fd19d561442fe43c0ce8 Mon Sep 17 00:00:00 2001 From: AkiChase <1003019131@qq.com> Date: Sat, 18 May 2024 17:25:29 +0800 Subject: [PATCH 02/11] feat(hotkey): addFrontSightShortcuts with scale --- src/hotkey.ts | 356 ++++++++++++++++++++++++++-------------- src/keyMappingConfig.ts | 17 ++ 2 files changed, 246 insertions(+), 127 deletions(-) diff --git a/src/hotkey.ts b/src/hotkey.ts index 43b94e7..9d5c323 100644 --- a/src/hotkey.ts +++ b/src/hotkey.ts @@ -10,10 +10,12 @@ import { KeyCancelSkill, KeyDirectionalSkill, KeyDirectionlessSkill, + KeyFire, KeyMacro, KeyMacroList, KeyMappingConfig, KeyObservation, + KeySight, KeySteeringWheel, KeyTap, KeyTriggerWhenDoublePressedSkill, @@ -146,6 +148,7 @@ function calculateMacroPosList( function addObservationShortcuts( key: string, relativeSize: { w: number; h: number }, + // pos relative to the mask posX: number, posY: number, scale: number, @@ -186,6 +189,7 @@ function addTapShortcuts( key: string, relativeSize: { w: number; h: number }, time: number, + // pos relative to the mask posX: number, posY: number, pointerId: number @@ -206,6 +210,7 @@ function addTapShortcuts( function addCancelSkillShortcuts( key: string, relativeSize: { w: number; h: number }, + // pos relative to the mask posX: number, posY: number, pointerId: number @@ -244,7 +249,7 @@ function addCancelSkillShortcuts( function addTriggerWhenPressedSkillShortcuts( key: string, relativeSize: { w: number; h: number }, - // pos relative to the device + // pos relative to the mask posX: number, posY: number, directional: boolean, @@ -304,7 +309,7 @@ const doublePressedDownKey = new Map(); function addTriggerWhenDoublePressedSkillShortcuts( key: string, relativeSize: { w: number; h: number }, - // pos relative to the device + // pos relative to the mask posX: number, posY: number, range: number, @@ -381,7 +386,7 @@ function addTriggerWhenDoublePressedSkillShortcuts( function addDirectionlessSkillShortcuts( key: string, relativeSize: { w: number; h: number }, - // pos relative to the device + // pos relative to the mask posX: number, posY: number, pointerId: number @@ -430,7 +435,7 @@ async function upDoublePressedKey() { function addDirectionalSkillShortcuts( key: string, relativeSize: { w: number; h: number }, - // pos relative to the device + // pos relative to the mask posX: number, posY: number, range: number, @@ -499,7 +504,7 @@ function addDirectionalSkillShortcuts( function addSteeringWheelKeyboardShortcuts( key: wheelKey, relativeSize: { w: number; h: number }, - // pos relative to the device + // pos relative to the mask posX: number, posY: number, offset: number, @@ -639,31 +644,25 @@ function addClickShortcuts(key: string, pointerId: number) { ); } -function addFrontSightShortcuts() { - // TODO 1. 补上开火键 2. i18n 3. 单独函数,同时配合可视化组件 4. 组件配置中唯一 +function addSightShortcuts( + relativeSize: { w: number; h: number }, + sightKeyMapping: KeySight, + fireKeyMapping?: KeyFire +) { + // TODO 2. i18n 3. 单独函数,同时配合可视化组件 4. 组件配置中唯一 const appWindow = getCurrent(); - // TODO cal it - const hasFireKey = true; - - const fireKeyMapping = { - type: "Fire", - pointerId: 2, - note: "开火键", - posX: 300, - posY: 300, - drag: true, - }; - let mouseLock = false; let msgReactive: ReturnType | null = null; const key = "KeyH"; - const centerX = 70 + maskSizeW / 2; - const centerY = 30 + maskSizeH / 2; - const centerPosX = screenSizeW / 2; - const centerPosY = screenSizeH / 2; - const scaleX = 0.5; - const scaleY = 0.5; + const sightClientX = 70 + sightKeyMapping.posX; + const sightClientY = 30 + sightKeyMapping.posY; + const sightDeviceX = Math.round( + (sightKeyMapping.posX / relativeSize.w) * screenSizeW + ); + const sightDeviceY = Math.round( + (sightKeyMapping.posY / relativeSize.h) * screenSizeH + ); const removeShortcut = (key: string) => { loopDownKeyCBMap.delete(key); @@ -672,33 +671,112 @@ function addFrontSightShortcuts() { downKeyMap.delete(key); }; - const touchRelateToCenter = async (action: TouchAction) => { + const touchRelateToSight = async (action: TouchAction) => { await touchX( action, - 0, - centerPosX + clientxToPosOffsetx(mouseX, centerPosX, scaleX), - centerPosY + clientyToPosOffsety(mouseY, centerPosY, scaleY) + sightKeyMapping.pointerId, + sightDeviceX + + clientxToPosOffsetx(mouseX, sightDeviceX, sightKeyMapping.scaleX), + sightDeviceY + + clientyToPosOffsety(mouseY, sightDeviceY, sightKeyMapping.scaleY) ); }; const sightLoopCB = async () => { - await touchRelateToCenter(TouchAction.Move); + await touchRelateToSight(TouchAction.Move); }; + // only scaleX and scaleY are different from sightLoopCB + const fireNoDragLoopCB = fireKeyMapping + ? async () => { + await touchX( + TouchAction.Move, + sightKeyMapping.pointerId, + sightDeviceX + + clientxToPosOffsetx(mouseX, sightDeviceX, fireKeyMapping.scaleX), + sightDeviceY + + clientyToPosOffsety(mouseY, sightDeviceY, fireKeyMapping.scaleY) + ); + } + : undefined; + + const fireDragLoopCB = fireKeyMapping + ? async () => { + await touchX( + TouchAction.Move, + fireKeyMapping.pointerId, + fireKeyMapping.posX + + accOffsetX + + clientxToPosOffsetx(mouseX, sightDeviceX, fireKeyMapping.scaleX), + fireKeyMapping.posX + + accOffsetY + + clientyToPosOffsety(mouseY, sightDeviceY, fireKeyMapping.scaleY) + ); + } + : undefined; + + let accOffsetX = 0; + let accOffsetY = 0; const moveLeaveHandler = async () => { - // stop loop touch move - loopDownKeyCBMap.delete(key); - // touch up - await touchRelateToCenter(TouchAction.Up); - await sleep(150); - // move mouse - appWindow.setCursorPosition(new LogicalPosition(centerX, centerY)); - mouseX = centerX; - mouseY = centerY; - // touch down - touchX(TouchAction.Down, 0, centerPosX, centerPosY); - // start loop touch move - loopDownKeyCBMap.set(key, sightLoopCB); + if (fireKeyMapping && fireKeyMapping.drag && downKeyMap.get("M0")) { + // fire drag mode + // stop fireDragLoopCB + loopDownKeyCBMap.delete(key); + // cal accOffset + accOffsetX += clientxToPosOffsetx( + mouseX, + sightDeviceX, + fireKeyMapping.scaleX + ); + accOffsetY += clientyToPosOffsety( + mouseY, + sightDeviceY, + fireKeyMapping.scaleY + ); + // move mouse + await appWindow.setCursorPosition( + new LogicalPosition(sightClientX, sightClientY) + ); + mouseX = sightClientX; + mouseY = sightClientY; + // start fireDragLoopCB + loopDownKeyCBMap.set(key, fireDragLoopCB!); + } else { + // sight mode or fire without drag mode + const fireFlag = + fireKeyMapping && !fireKeyMapping.drag && downKeyMap.get("M0"); + // stop sightLoopCB or fireNoDragLoopCB + loopDownKeyCBMap.delete(key); + // touch up + if (fireFlag) { + await touchX( + TouchAction.Move, + sightKeyMapping.pointerId, + sightDeviceX + + clientxToPosOffsetx(mouseX, sightDeviceX, fireKeyMapping.scaleX), + sightDeviceY + + clientyToPosOffsety(mouseY, sightDeviceY, fireKeyMapping.scaleY) + ); + } else { + await touchRelateToSight(TouchAction.Up); + } + await sleep(150); + // move mouse + await appWindow.setCursorPosition( + new LogicalPosition(sightClientX, sightClientY) + ); + mouseX = sightClientX; + mouseY = sightClientY; + // touch down + await touchX( + TouchAction.Down, + sightKeyMapping.pointerId, + sightDeviceX, + sightDeviceY + ); + // start sightLoopCB or fireNoDragLoopCB + loopDownKeyCBMap.set(key, fireFlag ? fireNoDragLoopCB! : sightLoopCB); + } }; // add sight shortcut @@ -706,7 +784,7 @@ function addFrontSightShortcuts() { if (mouseLock) { // stop sight mode loopDownKeyCBMap.delete(key); - await touchRelateToCenter(TouchAction.Up); + await touchRelateToSight(TouchAction.Up); await appWindow.setCursorVisible(true); maskElement.removeEventListener("mouseleave", moveLeaveHandler); mouseLock = false; @@ -715,7 +793,7 @@ function addFrontSightShortcuts() { msgReactive = null; } // remove fire key - if (hasFireKey) { + if (fireKeyMapping) { removeShortcut("M0"); } // add click @@ -729,95 +807,97 @@ function addFrontSightShortcuts() { duration: 0, }); - await touchX(TouchAction.Down, 0, centerPosX, centerPosY); - await appWindow.setCursorPosition(new LogicalPosition(centerX, centerY)); - mouseX = centerX; - mouseY = centerY; + await appWindow.setCursorPosition( + new LogicalPosition(sightClientX, sightClientY) + ); + mouseX = sightClientX; + mouseY = sightClientY; + await touchX( + TouchAction.Down, + sightKeyMapping.pointerId, + sightDeviceX, + sightDeviceY + ); loopDownKeyCBMap.set(key, sightLoopCB); // remove click removeShortcut("M0"); // add fire key - if (hasFireKey) { - if (fireKeyMapping.drag) { - addShortcut( - "M0", - async () => { - // stop sight loop - loopDownKeyCBMap.delete(key); - await touchRelateToCenter(TouchAction.Up); - // move cursor to center - await appWindow.setCursorPosition( - new LogicalPosition(centerX, centerY) - ); - mouseX = centerX; - mouseY = centerY; - // touch down fire + if (fireKeyMapping) { + // fire with drag + addShortcut( + "M0", + async () => { + // stop sightLoopCB + loopDownKeyCBMap.delete(key); + // touch up sight + await touchRelateToSight(TouchAction.Up); + if (!fireKeyMapping.drag) { + // touch down sight await touchX( TouchAction.Down, - fireKeyMapping.pointerId, - fireKeyMapping.posX, - fireKeyMapping.posY + sightKeyMapping.pointerId, + sightDeviceX, + sightDeviceY ); - }, - async () => { - await touchX( - TouchAction.Move, - fireKeyMapping.pointerId, - fireKeyMapping.posX + - clientxToPosOffsetx(mouseX, centerPosX, scaleX), - fireKeyMapping.posY + - clientyToPosOffsety(mouseY, centerPosY, scaleY) - ); - }, - async () => { - // touch up fire - await touchX( - TouchAction.Up, - fireKeyMapping.pointerId, - fireKeyMapping.posX + - clientxToPosOffsetx(mouseX, centerPosX, scaleX), - fireKeyMapping.posY + - clientyToPosOffsety(mouseY, centerPosY, scaleY) - ); - // start sight loop - await touchX(TouchAction.Down, 0, centerPosX, centerPosY); - await appWindow.setCursorPosition( - new LogicalPosition(centerX, centerY) - ); - mouseX = centerX; - mouseY = centerY; - loopDownKeyCBMap.set(key, sightLoopCB); + } else { + // clear accumulated offset + accOffsetX = 0; + accOffsetY = 0; } - ); - } else { - addShortcut( - "M0", - async () => { - await touchX( - TouchAction.Down, - fireKeyMapping.pointerId, - fireKeyMapping.posX, - fireKeyMapping.posY - ); - }, - async () => { - await touchX( - TouchAction.Move, - fireKeyMapping.pointerId, - fireKeyMapping.posX, - fireKeyMapping.posY - ); - }, - async () => { - await touchX( - TouchAction.Up, - fireKeyMapping.pointerId, - fireKeyMapping.posX, - fireKeyMapping.posY - ); - } - ); - } + // move cursor + await appWindow.setCursorPosition( + new LogicalPosition(sightClientX, sightClientY) + ); + mouseX = sightClientX; + mouseY = sightClientY; + // touch down fire + await touchX( + TouchAction.Down, + fireKeyMapping.pointerId, + fireKeyMapping.posX, + fireKeyMapping.posY + ); + + // start fireDragLoopCB or fireNoDragLoopCB + loopDownKeyCBMap.set( + key, + fireKeyMapping.drag ? fireDragLoopCB! : fireNoDragLoopCB! + ); + }, + undefined, + async () => { + // stop fireDragLoopCB or fireNoDragLoopCB + loopDownKeyCBMap.delete(key); + // touch up fire + await touchX( + TouchAction.Up, + fireKeyMapping.pointerId, + fireKeyMapping.posX + + clientxToPosOffsetx( + mouseX, + sightDeviceX, + fireKeyMapping.scaleX + ), + fireKeyMapping.posY + + clientyToPosOffsety(mouseY, sightDeviceY, fireKeyMapping.scaleY) + ); + // touch down sight + await touchX( + TouchAction.Down, + sightKeyMapping.pointerId, + sightDeviceX, + sightDeviceY + ); + // move cursor + await appWindow.setCursorPosition( + new LogicalPosition(sightClientX, sightClientY) + ); + mouseX = sightClientX; + mouseY = sightClientY; + // start sightLoopCB + loopDownKeyCBMap.set(key, sightLoopCB); + } + ); } } }); @@ -1308,7 +1388,29 @@ export function applyShortcuts( message = messageAPI; addClickShortcuts("M0", 0); - addFrontSightShortcuts(); + const relativeSize = { w: 1280, h: 720 }; + const sightKeyMapping = { + type: "Sight" as "Sight", + key: "KeyH", + pointerId: 0, + note: "准星键", + posX: 640, + posY: 360, + scaleX: 1, + scaleY: 1, + }; + + const fireKeyMapping = { + type: "Fire" as "Fire", + pointerId: 2, + note: "开火键", + posX: 300, + posY: 300, + drag: true, + scaleX: 0.5, + scaleY: 0.2, + }; + addSightShortcuts(relativeSize, sightKeyMapping, fireKeyMapping); return applyKeyMappingConfigShortcuts(keyMappingConfig); } diff --git a/src/keyMappingConfig.ts b/src/keyMappingConfig.ts index ca79637..87eff14 100644 --- a/src/keyMappingConfig.ts +++ b/src/keyMappingConfig.ts @@ -1,5 +1,6 @@ interface KeyBase { note: string; + // pos relative to the mask posX: number; posY: number; } @@ -79,6 +80,22 @@ export interface KeyMacro extends KeyBase { }; } +export interface KeySight extends KeyBase { + type: "Sight"; + key: string; + pointerId: number; + scaleX: number; + scaleY: number; +} + +export interface KeyFire extends KeyBase { + type: "Fire"; + drag: boolean; + pointerId: number; + scaleX: number; + scaleY: number; +} + export type KeyMapping = | KeySteeringWheel | KeyDirectionalSkill From 556e69ca46b9a2c616fe5ecba1bfc56c8898da84 Mon Sep 17 00:00:00 2001 From: AkiChase <1003019131@qq.com> Date: Sat, 18 May 2024 22:53:00 +0800 Subject: [PATCH 03/11] feat(KeySight+KeyFire): add KeySight and KeyFire module --- src/components/Mask.vue | 3 +- src/components/keyboard/KeyBoard.vue | 17 +- src/components/keyboard/KeyFire.vue | 250 +++++++++++++++++++++++++++ src/components/keyboard/KeySight.vue | 237 +++++++++++++++++++++++++ src/components/keyboard/KeySkill.vue | 4 +- src/hotkey.ts | 47 +++-- src/i18n/en-US.json | 16 +- src/i18n/zh-CN.json | 16 +- src/keyMappingConfig.ts | 4 +- 9 files changed, 558 insertions(+), 36 deletions(-) create mode 100644 src/components/keyboard/KeyFire.vue create mode 100644 src/components/keyboard/KeySight.vue diff --git a/src/components/Mask.vue b/src/components/Mask.vue index bab7646..78b985b 100644 --- a/src/components/Mask.vue +++ b/src/components/Mask.vue @@ -52,7 +52,8 @@ onActivated(async () => { applyShortcuts( maskElement, store.keyMappingConfigList[store.curKeyMappingIndex], - message + message, + t ) ) { listenToEvent(); diff --git a/src/components/keyboard/KeyBoard.vue b/src/components/keyboard/KeyBoard.vue index 3bafcad..221f428 100644 --- a/src/components/keyboard/KeyBoard.vue +++ b/src/components/keyboard/KeyBoard.vue @@ -6,6 +6,8 @@ import KeyCommon from "./KeyCommon.vue"; import KeySteeringWheel from "./KeySteeringWheel.vue"; import KeySkill from "./KeySkill.vue"; import KeyObservation from "./KeyObservation.vue"; +import KeySight from "./KeySight.vue"; +import KeyFire from "./KeyFire.vue"; import { KeyDirectionalSkill, KeySteeringWheel as KeyMappingSteeringWheel, @@ -115,7 +117,7 @@ function isKeyUnique(curKey: string): boolean { return false; set.add((keyMapping as KeyMappingSteeringWheel).key[name]); } - } else { + } else if (keyMapping.type !== "Fire") { if (set.has(keyMapping.key as string)) return false; set.add(keyMapping.key as string); } @@ -169,10 +171,11 @@ function setCurButtonKey(curKey: string) { const curName = nameList[activeSteeringWheelButtonKeyIndex]; keyObject[curName] = curKey; } - } else { + keyboardStore.edited = true; + } else if (keyMapping.type !== "Fire") { keyMapping.key = curKey; + keyboardStore.edited = true; } - keyboardStore.edited = true; } function handleClick(event: MouseEvent) { @@ -314,6 +317,14 @@ onBeforeRouteLeave(() => { v-else-if="store.editKeyMappingList[index].type === 'Observation'" :index="index" /> + + diff --git a/src/components/keyboard/KeyFire.vue b/src/components/keyboard/KeyFire.vue new file mode 100644 index 0000000..27e72da --- /dev/null +++ b/src/components/keyboard/KeyFire.vue @@ -0,0 +1,250 @@ + + + + + diff --git a/src/components/keyboard/KeySight.vue b/src/components/keyboard/KeySight.vue new file mode 100644 index 0000000..889fa3b --- /dev/null +++ b/src/components/keyboard/KeySight.vue @@ -0,0 +1,237 @@ + + + + + diff --git a/src/components/keyboard/KeySkill.vue b/src/components/keyboard/KeySkill.vue index 2b886b5..05f0f8e 100644 --- a/src/components/keyboard/KeySkill.vue +++ b/src/components/keyboard/KeySkill.vue @@ -185,7 +185,7 @@ function showSetting() { ) as HTMLElement; // setting const maxWidth = keyboardElement.clientWidth - 200; - const maxHeight = keyboardElement.clientHeight - 420; + const maxHeight = keyboardElement.clientHeight - 430; settingPosX.value = Math.min(keyMapping.value.posX + 40, maxWidth); settingPosY.value = Math.min(keyMapping.value.posY - 30, maxHeight); updateRangeIndicator(keyboardElement); @@ -374,7 +374,7 @@ function updateRangeIndicator(element?: HTMLElement) { padding: 10px 20px; box-sizing: border-box; width: 200px; - height: 420px; + height: 430px; border-radius: 5px; border: 2px solid var(--light-color); background-color: var(--bg-color); diff --git a/src/hotkey.ts b/src/hotkey.ts index 9d5c323..c02f331 100644 --- a/src/hotkey.ts +++ b/src/hotkey.ts @@ -23,6 +23,7 @@ import { } from "./keyMappingConfig"; import { useGlobalStore } from "./store/global"; import { LogicalPosition, getCurrent } from "@tauri-apps/api/window"; +import { useI18n } from "vue-i18n"; function clientxToPosx(clientx: number) { return clientx < 70 @@ -649,7 +650,7 @@ function addSightShortcuts( sightKeyMapping: KeySight, fireKeyMapping?: KeyFire ) { - // TODO 2. i18n 3. 单独函数,同时配合可视化组件 4. 组件配置中唯一 + // TODO 3. 可视化组件 4. 组件配置中唯一 const appWindow = getCurrent(); let mouseLock = false; @@ -803,7 +804,7 @@ function addSightShortcuts( await appWindow.setCursorVisible(false); maskElement.addEventListener("mouseleave", moveLeaveHandler); mouseLock = true; - msgReactive = message.info(`鼠标已锁定, 按 ${key} 键解锁`, { + msgReactive = message.info(t("pages.Mask.sightMode", [key]), { duration: 0, }); @@ -911,6 +912,7 @@ let mouseX = 0; let mouseY = 0; let maskElement: HTMLElement; let message: ReturnType; +let t: ReturnType["t"]; const downKeyMap: Map = new Map(); const downKeyCBMap: Map Promise> = new Map(); @@ -1304,6 +1306,19 @@ function applyKeyMappingConfigShortcuts( } ); break; + case "Sight": + asType(item); + let fireKeyMapping; + for (const keyMapping of keyMappingConfig.list) { + if (keyMapping.type === "Fire") { + fireKeyMapping = keyMapping; + break; + } + } + addSightShortcuts(relativeSize, item, fireKeyMapping); + break; + case "Fire": + break; default: console.error("Invalid item type: ", item); break; @@ -1382,35 +1397,13 @@ export function updateScreenSizeAndMaskArea( export function applyShortcuts( element: HTMLElement, keyMappingConfig: KeyMappingConfig, - messageAPI: ReturnType + messageAPI: ReturnType, + i18nT: ReturnType["t"] ) { maskElement = element; message = messageAPI; + t = i18nT; addClickShortcuts("M0", 0); - const relativeSize = { w: 1280, h: 720 }; - const sightKeyMapping = { - type: "Sight" as "Sight", - key: "KeyH", - pointerId: 0, - note: "准星键", - posX: 640, - posY: 360, - scaleX: 1, - scaleY: 1, - }; - - const fireKeyMapping = { - type: "Fire" as "Fire", - pointerId: 2, - note: "开火键", - posX: 300, - posY: 300, - drag: true, - scaleX: 0.5, - scaleY: 0.2, - }; - addSightShortcuts(relativeSize, sightKeyMapping, fireKeyMapping); - return applyKeyMappingConfigShortcuts(keyMappingConfig); } diff --git a/src/i18n/en-US.json b/src/i18n/en-US.json index a3fcfa9..7023b7d 100644 --- a/src/i18n/en-US.json +++ b/src/i18n/en-US.json @@ -61,7 +61,8 @@ "title": "Controlled device not found", "content": "Please go to the device page to control any device", "positiveText": "To control" - } + }, + "sightMode": "Mouse is locked, press {0} to unlock" }, "Setting": { "tabs": { @@ -218,6 +219,19 @@ "SteeringWheel": { "steeringWheel": "SteeringWheel", "offset": "Offset" + }, + "KeySight": { + "sight": "Front sight", + "scaleX": "Horizontal sensitivity", + "scalePlaceholder": "Please enter sensitivity", + "scaleY": "Vertical sensitivity" + }, + "KeyFire": { + "fire": "Fire", + "drag": "Drag to cast", + "scaleX": "Horizontal sensitivity", + "scalePlaceholder": "Please enter sensitivity", + "scaleY": "Vertical sensitivity" } } }, diff --git a/src/i18n/zh-CN.json b/src/i18n/zh-CN.json index 1b4a199..d05b3b1 100644 --- a/src/i18n/zh-CN.json +++ b/src/i18n/zh-CN.json @@ -61,7 +61,8 @@ "content": "请前往设备页面,控制任意设备", "positiveText": "去控制" }, - "inputBoxPlaceholder": "输入文本后按Enter/Esc" + "inputBoxPlaceholder": "输入文本后按Enter/Esc", + "sightMode": "鼠标已锁定, 按 {0} 键解锁" }, "Setting": { "tabs": { @@ -218,6 +219,19 @@ "SteeringWheel": { "steeringWheel": "键盘行走", "offset": "偏移" + }, + "KeySight": { + "sight": "准星", + "scaleX": "水平灵敏度", + "scaleY": "垂直灵敏度", + "scalePlaceholder": "请输入灵敏度" + }, + "KeyFire": { + "fire": "开火", + "drag": "拖动施法", + "scaleX": "水平灵敏度", + "scaleY": "垂直灵敏度", + "scalePlaceholder": "请输入灵敏度" } } }, diff --git a/src/keyMappingConfig.ts b/src/keyMappingConfig.ts index 87eff14..ff26717 100644 --- a/src/keyMappingConfig.ts +++ b/src/keyMappingConfig.ts @@ -105,7 +105,9 @@ export type KeyMapping = | KeyObservation | KeyMacro | KeyCancelSkill - | KeyTap; + | KeyTap + | KeySight + | KeyFire; export type KeyCommon = KeyMacro | KeyCancelSkill | KeyTap; From ab67d20198b4b1b05c10c126a3d2ac604c5d8f00 Mon Sep 17 00:00:00 2001 From: AkiChase <1003019131@qq.com> Date: Sun, 19 May 2024 08:57:08 +0800 Subject: [PATCH 04/11] feat(KeyBoard): add menu item for KeySight and KeyFire --- src/components/keyboard/KeyBoard.vue | 41 ++++++++++++++++++++++++++-- src/hotkey.ts | 2 +- src/i18n/en-US.json | 6 +++- src/i18n/zh-CN.json | 6 +++- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/components/keyboard/KeyBoard.vue b/src/components/keyboard/KeyBoard.vue index 221f428..4ce9f25 100644 --- a/src/components/keyboard/KeyBoard.vue +++ b/src/components/keyboard/KeyBoard.vue @@ -8,6 +8,7 @@ import KeySkill from "./KeySkill.vue"; import KeyObservation from "./KeyObservation.vue"; import KeySight from "./KeySight.vue"; import KeyFire from "./KeyFire.vue"; + import { KeyDirectionalSkill, KeySteeringWheel as KeyMappingSteeringWheel, @@ -15,6 +16,8 @@ import { KeyTap, KeyMacro, KeyMapping, + KeySight as KeyMappingKeySight, + KeyFire as KeyMappingKeyFire, } from "../../keyMappingConfig"; import { useGlobalStore } from "../../store/global"; import { DropdownOption, NDropdown, useDialog, useMessage } from "naive-ui"; @@ -54,6 +57,14 @@ const addButtonOptions: DropdownOption[] = [ label: () => t("pages.KeyBoard.addButton.Macro"), key: "Macro", }, + { + label: () => t("pages.KeyBoard.addButton.Sight"), + key: "Sight", + }, + { + label: () => t("pages.KeyBoard.addButton.Fire"), + key: "Fire", + }, ]; function onAddButtonSelect( @@ -64,6 +75,8 @@ function onAddButtonSelect( | "CancelSkill" | "Observation" | "Macro" + | "Sight" + | "Fire" ) { keyboardStore.showButtonAddFlag = false; const keyMapping = { @@ -72,11 +85,13 @@ function onAddButtonSelect( note: "", posX: addButtonPos.value.x - 70, posY: addButtonPos.value.y - 30, - pointerId: 2, // default skill pointerId + pointerId: 2, // default skill and fire pointerId }; if (type === "Tap") { + keyMapping.pointerId = 3; (keyMapping as KeyTap).time = 80; } else if (type === "SteeringWheel") { + keyMapping.pointerId = 1; (keyMapping as unknown as KeyMappingSteeringWheel).key = { left: "NONE1", right: "NONE2", @@ -89,14 +104,36 @@ function onAddButtonSelect( } else if (type === "CancelSkill") { keyMapping.note = t("pages.KeyBoard.addButton.CancelSkill"); } else if (type === "Observation") { + keyMapping.pointerId = 4; (keyMapping as unknown as KeyMappingObservation).scale = 0.6; } else if (type === "Macro") { + delete (keyMapping as any).pointerId; (keyMapping as unknown as KeyMacro).macro = { down: null, loop: null, up: null, }; - delete (keyMapping as any).pointerId; + } else if (type === "Sight") { + for (const mapping of store.editKeyMappingList) { + if (mapping.type === "Sight") { + message.error(t("pages.KeyBoard.addButton.existSight")); + return; + } + } + keyMapping.pointerId = 0; + (keyMapping as unknown as KeyMappingKeySight).scaleX = 0.5; + (keyMapping as unknown as KeyMappingKeySight).scaleY = 0.5; + } else if (type === "Fire") { + for (const mapping of store.editKeyMappingList) { + if (mapping.type === "Fire") { + message.error(t("pages.KeyBoard.addButton.existFire")); + return; + } + } + delete (keyMapping as any).key; + (keyMapping as unknown as KeyMappingKeyFire).scaleX = 0.5; + (keyMapping as unknown as KeyMappingKeyFire).scaleY = 0.5; + (keyMapping as unknown as KeyMappingKeyFire).drag = false; } else return; keyboardStore.edited = true; store.editKeyMappingList.push(keyMapping as KeyMapping); diff --git a/src/hotkey.ts b/src/hotkey.ts index c02f331..f71bcba 100644 --- a/src/hotkey.ts +++ b/src/hotkey.ts @@ -650,7 +650,7 @@ function addSightShortcuts( sightKeyMapping: KeySight, fireKeyMapping?: KeyFire ) { - // TODO 3. 可视化组件 4. 组件配置中唯一 + // TODO 5. 调整所有按键设置宽度,英文的存在换行问题 const appWindow = getCurrent(); let mouseLock = false; diff --git a/src/i18n/en-US.json b/src/i18n/en-US.json index 7023b7d..2858c69 100644 --- a/src/i18n/en-US.json +++ b/src/i18n/en-US.json @@ -133,7 +133,11 @@ "Skill": "Skill", "CancelSkill": "CancelSkill", "Observation": "Observation", - "Macro": "Macro" + "Macro": "Macro", + "Sight": "Front sight", + "Fire": "Fire", + "existFire": "Fire button already exists", + "existSight": "Front sight button already exists" }, "buttonKeyRepeat": "Key repeat: {0}", "KeyCommon": { diff --git a/src/i18n/zh-CN.json b/src/i18n/zh-CN.json index d05b3b1..cb127aa 100644 --- a/src/i18n/zh-CN.json +++ b/src/i18n/zh-CN.json @@ -126,7 +126,11 @@ "Skill": "技能", "CancelSkill": "技能取消", "Observation": "观察视角", - "Macro": "宏" + "Macro": "宏", + "Sight": "准星", + "Fire": "开火", + "existSight": "已存在准星按钮", + "existFire": "已存在开火按钮" }, "buttonKeyRepeat": "按键重复: {0}", "noSaveDialog": { From d1b6292b8a45586b7ed479e871694cfdebdfc408 Mon Sep 17 00:00:00 2001 From: AkiChase <1003019131@qq.com> Date: Sun, 19 May 2024 09:15:27 +0800 Subject: [PATCH 05/11] fix(KeyBoard): setting card width --- src/components/keyboard/KeyCommon.vue | 8 ++++---- src/components/keyboard/KeyFire.vue | 10 +++++----- src/components/keyboard/KeyObservation.vue | 2 +- src/components/keyboard/KeySight.vue | 6 +++--- src/components/keyboard/KeySkill.vue | 6 +++--- src/components/keyboard/KeySteeringWheel.vue | 4 ++-- src/hotkey.ts | 1 - src/i18n/en-US.json | 7 +++++-- src/i18n/zh-CN.json | 7 +++++-- 9 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/components/keyboard/KeyCommon.vue b/src/components/keyboard/KeyCommon.vue index 381e188..22dfcd7 100644 --- a/src/components/keyboard/KeyCommon.vue +++ b/src/components/keyboard/KeyCommon.vue @@ -210,14 +210,14 @@ function showSetting() { > {{ keyMapping.type === "CancelSkill" - ? "技能取消" + ? t("pages.KeyBoard.KeyCommon.cancelSkill") : keyMapping.type === "Tap" - ? "普通点击" - : "宏" + ? t("pages.KeyBoard.KeyCommon.tap") + : t("pages.KeyBoard.KeyCommon.macro") }} {{ $t("pages.KeyBoard.KeyCommon.editMacro") }} diff --git a/src/components/keyboard/KeyFire.vue b/src/components/keyboard/KeyFire.vue index 27e72da..023a4c5 100644 --- a/src/components/keyboard/KeyFire.vue +++ b/src/components/keyboard/KeyFire.vue @@ -77,11 +77,11 @@ function showSetting() { const keyboardElement = document.getElementById( "keyboardElement" ) as HTMLElement; - const maxWidth = keyboardElement.clientWidth - 150; - const maxHeight = keyboardElement.clientHeight - 420; + const maxWidth = keyboardElement.clientWidth - 200; + const maxHeight = keyboardElement.clientHeight - 430; settingPosX.value = Math.min(keyMapping.value.posX + 40, maxWidth); - settingPosY.value = Math.min(keyMapping.value.posY - 30, maxHeight); + settingPosY.value = Math.min(keyMapping.value.posY - 40, maxHeight); keyboardStore.showButtonSettingFlag = true; } @@ -189,8 +189,8 @@ function showSetting() { flex-direction: column; padding: 10px 20px; box-sizing: border-box; - width: 150px; - height: 420px; + width: 200px; + height: 430px; border-radius: 5px; border: 2px solid var(--light-color); background-color: var(--bg-color); diff --git a/src/components/keyboard/KeyObservation.vue b/src/components/keyboard/KeyObservation.vue index 07efc09..88e2c13 100644 --- a/src/components/keyboard/KeyObservation.vue +++ b/src/components/keyboard/KeyObservation.vue @@ -73,7 +73,7 @@ function showSetting() { const maxHeight = keyboardElement.clientHeight - 300; settingPosX.value = Math.min(keyMapping.value.posX + 40, maxWidth); - settingPosY.value = Math.min(keyMapping.value.posY - 30, maxHeight); + settingPosY.value = Math.min(keyMapping.value.posY - 40, maxHeight); keyboardStore.showButtonSettingFlag = true; } diff --git a/src/components/keyboard/KeySight.vue b/src/components/keyboard/KeySight.vue index 889fa3b..a086c17 100644 --- a/src/components/keyboard/KeySight.vue +++ b/src/components/keyboard/KeySight.vue @@ -69,11 +69,11 @@ function showSetting() { const keyboardElement = document.getElementById( "keyboardElement" ) as HTMLElement; - const maxWidth = keyboardElement.clientWidth - 150; + const maxWidth = keyboardElement.clientWidth - 200; const maxHeight = keyboardElement.clientHeight - 380; settingPosX.value = Math.min(keyMapping.value.posX + 40, maxWidth); - settingPosY.value = Math.min(keyMapping.value.posY - 30, maxHeight); + settingPosY.value = Math.min(keyMapping.value.posY - 40, maxHeight); keyboardStore.showButtonSettingFlag = true; } @@ -176,7 +176,7 @@ function showSetting() { flex-direction: column; padding: 10px 20px; box-sizing: border-box; - width: 150px; + width: 200px; height: 380px; border-radius: 5px; border: 2px solid var(--light-color); diff --git a/src/components/keyboard/KeySkill.vue b/src/components/keyboard/KeySkill.vue index 05f0f8e..4364ee9 100644 --- a/src/components/keyboard/KeySkill.vue +++ b/src/components/keyboard/KeySkill.vue @@ -184,10 +184,10 @@ function showSetting() { "keyboardElement" ) as HTMLElement; // setting - const maxWidth = keyboardElement.clientWidth - 200; + const maxWidth = keyboardElement.clientWidth - 220; const maxHeight = keyboardElement.clientHeight - 430; settingPosX.value = Math.min(keyMapping.value.posX + 40, maxWidth); - settingPosY.value = Math.min(keyMapping.value.posY - 30, maxHeight); + settingPosY.value = Math.min(keyMapping.value.posY - 40, maxHeight); updateRangeIndicator(keyboardElement); keyboardStore.showButtonSettingFlag = true; } @@ -373,7 +373,7 @@ function updateRangeIndicator(element?: HTMLElement) { flex-direction: column; padding: 10px 20px; box-sizing: border-box; - width: 200px; + width: 220px; height: 430px; border-radius: 5px; border: 2px solid var(--light-color); diff --git a/src/components/keyboard/KeySteeringWheel.vue b/src/components/keyboard/KeySteeringWheel.vue index d8b0754..36e37bc 100644 --- a/src/components/keyboard/KeySteeringWheel.vue +++ b/src/components/keyboard/KeySteeringWheel.vue @@ -79,7 +79,7 @@ function showSetting() { const keyboardElement = document.getElementById( "keyboardElement" ) as HTMLElement; - const maxWidth = keyboardElement.clientWidth - 150; + const maxWidth = keyboardElement.clientWidth - 179; const maxHeight = keyboardElement.clientHeight - 300; settingPosX.value = Math.min( @@ -219,7 +219,7 @@ function showSetting() { flex-direction: column; padding: 10px 20px; box-sizing: border-box; - width: 150px; + width: 170px; height: 300px; border-radius: 5px; border: 2px solid var(--light-color); diff --git a/src/hotkey.ts b/src/hotkey.ts index f71bcba..e5899e1 100644 --- a/src/hotkey.ts +++ b/src/hotkey.ts @@ -650,7 +650,6 @@ function addSightShortcuts( sightKeyMapping: KeySight, fireKeyMapping?: KeyFire ) { - // TODO 5. 调整所有按键设置宽度,英文的存在换行问题 const appWindow = getCurrent(); let mouseLock = false; diff --git a/src/i18n/en-US.json b/src/i18n/en-US.json index 2858c69..19e6042 100644 --- a/src/i18n/en-US.json +++ b/src/i18n/en-US.json @@ -143,7 +143,6 @@ "KeyCommon": { "macroParseSuccess": "The macro code is parsed successfully, but the correctness of the code is not guaranteed. Please test by yourself.", "macroParseFailed": "Macro code failed to save, please check whether the code format is correct.", - "macro": "Macro code", "editMacro": "Edit macro", "macroModal": { "title": "Macro editor", @@ -151,7 +150,11 @@ "placeholder": "JSON macro code, can be empty", "loop": "Macro executed on key press and hold", "up": "Macro executed on key up" - } + }, + "macroCode": "Macro code", + "cancelSkill": "CancelSkill", + "tap": "Tap", + "macro": "Macro" }, "setting": { "touchTime": "Touch duration", diff --git a/src/i18n/zh-CN.json b/src/i18n/zh-CN.json index cb127aa..7a3170d 100644 --- a/src/i18n/zh-CN.json +++ b/src/i18n/zh-CN.json @@ -143,7 +143,6 @@ "KeyCommon": { "macroParseSuccess": "宏代码解析成功,但不保证代码正确性,请自行测试", "macroParseFailed": "宏代码保存失败,请检查代码格式是否正确", - "macro": "宏代码", "editMacro": "编辑宏代码", "macroModal": { "title": "宏编辑", @@ -151,7 +150,11 @@ "loop": "按住执行的宏", "placeholder": "JSON宏代码, 可为空", "up": "抬起执行的宏" - } + }, + "cancelSkill": "技能取消", + "tap": "普通点击", + "macroCode": "宏代码", + "macro": "宏" }, "setting": { "touchTime": "触摸时长", From fd790b029ff63c57f33f40e71076643d8f98ff93 Mon Sep 17 00:00:00 2001 From: AkiChase <1003019131@qq.com> Date: Sun, 19 May 2024 10:45:37 +0800 Subject: [PATCH 06/11] fix(hotkey): sight and fire shortcuts --- src/hotkey.ts | 57 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/src/hotkey.ts b/src/hotkey.ts index e5899e1..bbf3406 100644 --- a/src/hotkey.ts +++ b/src/hotkey.ts @@ -654,7 +654,6 @@ function addSightShortcuts( let mouseLock = false; let msgReactive: ReturnType | null = null; - const key = "KeyH"; const sightClientX = 70 + sightKeyMapping.posX; const sightClientY = 30 + sightKeyMapping.posY; const sightDeviceX = Math.round( @@ -664,6 +663,14 @@ function addSightShortcuts( (sightKeyMapping.posY / relativeSize.h) * screenSizeH ); + const fireDeviceX = fireKeyMapping + ? Math.round((fireKeyMapping.posX / relativeSize.w) * screenSizeW) + : 0; + + const fireDeviceY = fireKeyMapping + ? Math.round((fireKeyMapping.posY / relativeSize.h) * screenSizeH) + : 0; + const removeShortcut = (key: string) => { loopDownKeyCBMap.delete(key); downKeyCBMap.delete(key); @@ -705,10 +712,10 @@ function addSightShortcuts( await touchX( TouchAction.Move, fireKeyMapping.pointerId, - fireKeyMapping.posX + + fireDeviceX + accOffsetX + clientxToPosOffsetx(mouseX, sightDeviceX, fireKeyMapping.scaleX), - fireKeyMapping.posX + + fireDeviceY + accOffsetY + clientyToPosOffsety(mouseY, sightDeviceY, fireKeyMapping.scaleY) ); @@ -721,7 +728,7 @@ function addSightShortcuts( if (fireKeyMapping && fireKeyMapping.drag && downKeyMap.get("M0")) { // fire drag mode // stop fireDragLoopCB - loopDownKeyCBMap.delete(key); + loopDownKeyCBMap.delete(sightKeyMapping.key); // cal accOffset accOffsetX += clientxToPosOffsetx( mouseX, @@ -740,13 +747,13 @@ function addSightShortcuts( mouseX = sightClientX; mouseY = sightClientY; // start fireDragLoopCB - loopDownKeyCBMap.set(key, fireDragLoopCB!); + loopDownKeyCBMap.set(sightKeyMapping.key, fireDragLoopCB!); } else { // sight mode or fire without drag mode const fireFlag = fireKeyMapping && !fireKeyMapping.drag && downKeyMap.get("M0"); // stop sightLoopCB or fireNoDragLoopCB - loopDownKeyCBMap.delete(key); + loopDownKeyCBMap.delete(sightKeyMapping.key); // touch up if (fireFlag) { await touchX( @@ -775,18 +782,22 @@ function addSightShortcuts( sightDeviceY ); // start sightLoopCB or fireNoDragLoopCB - loopDownKeyCBMap.set(key, fireFlag ? fireNoDragLoopCB! : sightLoopCB); + loopDownKeyCBMap.set( + sightKeyMapping.key, + fireFlag ? fireNoDragLoopCB! : sightLoopCB + ); } }; // add sight shortcut - addShortcut(key, async () => { + addShortcut(sightKeyMapping.key, async () => { if (mouseLock) { // stop sight mode - loopDownKeyCBMap.delete(key); + loopDownKeyCBMap.delete(sightKeyMapping.key); await touchRelateToSight(TouchAction.Up); await appWindow.setCursorVisible(true); maskElement.removeEventListener("mouseleave", moveLeaveHandler); + maskElement.style.cursor = "pointer"; mouseLock = false; if (msgReactive) { msgReactive.destroy(); @@ -802,10 +813,14 @@ function addSightShortcuts( // start sight mode await appWindow.setCursorVisible(false); maskElement.addEventListener("mouseleave", moveLeaveHandler); + maskElement.style.cursor = "none"; mouseLock = true; - msgReactive = message.info(t("pages.Mask.sightMode", [key]), { - duration: 0, - }); + msgReactive = message.info( + t("pages.Mask.sightMode", [sightKeyMapping.key]), + { + duration: 0, + } + ); await appWindow.setCursorPosition( new LogicalPosition(sightClientX, sightClientY) @@ -818,7 +833,7 @@ function addSightShortcuts( sightDeviceX, sightDeviceY ); - loopDownKeyCBMap.set(key, sightLoopCB); + loopDownKeyCBMap.set(sightKeyMapping.key, sightLoopCB); // remove click removeShortcut("M0"); // add fire key @@ -828,7 +843,7 @@ function addSightShortcuts( "M0", async () => { // stop sightLoopCB - loopDownKeyCBMap.delete(key); + loopDownKeyCBMap.delete(sightKeyMapping.key); // touch up sight await touchRelateToSight(TouchAction.Up); if (!fireKeyMapping.drag) { @@ -854,31 +869,31 @@ function addSightShortcuts( await touchX( TouchAction.Down, fireKeyMapping.pointerId, - fireKeyMapping.posX, - fireKeyMapping.posY + fireDeviceX, + fireDeviceY ); // start fireDragLoopCB or fireNoDragLoopCB loopDownKeyCBMap.set( - key, + sightKeyMapping.key, fireKeyMapping.drag ? fireDragLoopCB! : fireNoDragLoopCB! ); }, undefined, async () => { // stop fireDragLoopCB or fireNoDragLoopCB - loopDownKeyCBMap.delete(key); + loopDownKeyCBMap.delete(sightKeyMapping.key); // touch up fire await touchX( TouchAction.Up, fireKeyMapping.pointerId, - fireKeyMapping.posX + + fireDeviceX + clientxToPosOffsetx( mouseX, sightDeviceX, fireKeyMapping.scaleX ), - fireKeyMapping.posY + + fireDeviceY + clientyToPosOffsety(mouseY, sightDeviceY, fireKeyMapping.scaleY) ); // touch down sight @@ -895,7 +910,7 @@ function addSightShortcuts( mouseX = sightClientX; mouseY = sightClientY; // start sightLoopCB - loopDownKeyCBMap.set(key, sightLoopCB); + loopDownKeyCBMap.set(sightKeyMapping.key, sightLoopCB); } ); } From 396639d75266e8947294fc2c460100d8287f0975 Mon Sep 17 00:00:00 2001 From: AkiChase <1003019131@qq.com> Date: Sun, 19 May 2024 10:46:08 +0800 Subject: [PATCH 07/11] fix(KeyBoard): display bugs --- src/components/Mask.vue | 2 +- src/components/keyboard/KeyCommon.vue | 2 +- src/components/keyboard/KeyFire.vue | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/Mask.vue b/src/components/Mask.vue index 78b985b..1ef3430 100644 --- a/src/components/Mask.vue +++ b/src/components/Mask.vue @@ -336,7 +336,7 @@ async function checkUpdate() { top: button.posY - 14 + 'px', }" > - {{ button.key }} + {{ button.type === "Fire" ? "Fire" : button.key }} diff --git a/src/components/keyboard/KeyCommon.vue b/src/components/keyboard/KeyCommon.vue index 22dfcd7..ccaf5c0 100644 --- a/src/components/keyboard/KeyCommon.vue +++ b/src/components/keyboard/KeyCommon.vue @@ -267,7 +267,7 @@ function showSetting() {