mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2025-04-21 04:25:13 +08:00
feat(KeyBoard): optimize user interact
This commit is contained in:
parent
9b3c6e4aa2
commit
95253ac908
@ -12,9 +12,6 @@ import { onBeforeRouteLeave } from "vue-router";
|
|||||||
import KeyObservation from "./KeyObservation.vue";
|
import KeyObservation from "./KeyObservation.vue";
|
||||||
import { useKeyboardStore } from "../../store/keyboard";
|
import { useKeyboardStore } from "../../store/keyboard";
|
||||||
|
|
||||||
// TODO 打开设置时要关闭active,建议将各种数据打包到一个对象中共享,省的麻烦
|
|
||||||
// TODO 切换按键方案时提示未保存,然后修改edit
|
|
||||||
// TODO 方向轮盘具体按键还没激活时也会触发按键检查
|
|
||||||
// TODO 右键空白区域添加按键
|
// TODO 右键空白区域添加按键
|
||||||
// TODO 设置界面添加本地数据编辑器(类似utools)
|
// TODO 设置界面添加本地数据编辑器(类似utools)
|
||||||
// TODO 添加开发者工具打开按钮
|
// TODO 添加开发者工具打开按钮
|
||||||
@ -50,12 +47,24 @@ function isKeyUnique(curKey: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setCurButtonKey(curKey: string) {
|
function setCurButtonKey(curKey: string) {
|
||||||
|
if (
|
||||||
|
keyboardStore.activeButtonIndex === -1 ||
|
||||||
|
keyboardStore.activeButtonIndex >= store.editKeyMappingList.length
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const keyMapping = store.editKeyMappingList[keyboardStore.activeButtonIndex];
|
||||||
|
if (
|
||||||
|
keyMapping.type === "SteeringWheel" &&
|
||||||
|
keyboardStore.activeSteeringWheelButtonKeyIndex === -1
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!isKeyUnique(curKey)) {
|
if (!isKeyUnique(curKey)) {
|
||||||
message.error("按键重复:" + curKey);
|
message.error("按键重复:" + curKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const keyMapping = store.editKeyMappingList[keyboardStore.activeButtonIndex];
|
|
||||||
if (keyMapping.type === "SteeringWheel") {
|
if (keyMapping.type === "SteeringWheel") {
|
||||||
const keyObject = keyMapping.key as {
|
const keyObject = keyMapping.key as {
|
||||||
left: string;
|
left: string;
|
||||||
@ -100,65 +109,39 @@ function handleClick(event: MouseEvent) {
|
|||||||
// right click
|
// right click
|
||||||
if (event.target === document.getElementById("keyboardElement")) {
|
if (event.target === document.getElementById("keyboardElement")) {
|
||||||
// add button
|
// add button
|
||||||
if (keyboardStore.showSettingFlag) keyboardStore.showSettingFlag = false;
|
keyboardStore.showSettingFlag = false;
|
||||||
keyboardStore.activeButtonIndex = -1;
|
keyboardStore.activeButtonIndex = -1;
|
||||||
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
||||||
|
|
||||||
console.log("弹出新增");
|
console.log("弹出新增");
|
||||||
} else if (
|
} else {
|
||||||
// modify key
|
setCurButtonKey(`M${event.button}`);
|
||||||
keyboardStore.activeButtonIndex !== -1 &&
|
|
||||||
keyboardStore.activeButtonIndex < store.editKeyMappingList.length &&
|
|
||||||
!keyboardStore.showButtonSettingFlag
|
|
||||||
) {
|
|
||||||
const curKey = `M${event.button}`;
|
|
||||||
setCurButtonKey(curKey);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// other click
|
// other click
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (
|
setCurButtonKey(`M${event.button}`);
|
||||||
keyboardStore.activeButtonIndex !== -1 &&
|
|
||||||
keyboardStore.activeButtonIndex < store.editKeyMappingList.length &&
|
|
||||||
!keyboardStore.showButtonSettingFlag
|
|
||||||
) {
|
|
||||||
const curKey = `M${event.button}`;
|
|
||||||
setCurButtonKey(curKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleKeyUp(event: KeyboardEvent) {
|
function handleKeyUp(event: KeyboardEvent) {
|
||||||
if (
|
setCurButtonKey(event.code);
|
||||||
keyboardStore.activeButtonIndex !== -1 &&
|
|
||||||
keyboardStore.activeButtonIndex < store.editKeyMappingList.length &&
|
|
||||||
!keyboardStore.showButtonSettingFlag
|
|
||||||
) {
|
|
||||||
const curKey = event.code;
|
|
||||||
setCurButtonKey(curKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseWheel(event: WheelEvent) {
|
function handleMouseWheel(event: WheelEvent) {
|
||||||
if (
|
if (event.deltaY > 0) {
|
||||||
keyboardStore.activeButtonIndex !== -1 &&
|
// WheelDown
|
||||||
keyboardStore.activeButtonIndex < store.editKeyMappingList.length &&
|
setCurButtonKey("WheelDown");
|
||||||
!keyboardStore.showButtonSettingFlag
|
} else if (event.deltaY < 0) {
|
||||||
) {
|
// WheelUp
|
||||||
if (event.deltaY > 0) {
|
setCurButtonKey("WheelUp");
|
||||||
// WheelDown
|
|
||||||
setCurButtonKey("WheelDown");
|
|
||||||
} else if (event.deltaY < 0) {
|
|
||||||
// WheelUp
|
|
||||||
setCurButtonKey("WheelUp");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetEditKeyMappingList() {
|
function resetKeyMappingConfig() {
|
||||||
keyboardStore.showSettingFlag = false;
|
|
||||||
keyboardStore.activeButtonIndex = -1;
|
keyboardStore.activeButtonIndex = -1;
|
||||||
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
||||||
|
keyboardStore.showSettingFlag = false;
|
||||||
store.resetEditKeyMappingList();
|
store.resetEditKeyMappingList();
|
||||||
keyboardStore.edited = false;
|
keyboardStore.edited = false;
|
||||||
}
|
}
|
||||||
@ -185,7 +168,7 @@ onBeforeRouteLeave(() => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onNegativeClick: () => {
|
onNegativeClick: () => {
|
||||||
resetEditKeyMappingList();
|
resetKeyMappingConfig();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -200,7 +183,7 @@ onBeforeRouteLeave(() => {
|
|||||||
@mousedown="handleClick"
|
@mousedown="handleClick"
|
||||||
@contextmenu.prevent
|
@contextmenu.prevent
|
||||||
>
|
>
|
||||||
<KeySetting @reset-edit-key-mapping-list="resetEditKeyMappingList" />
|
<KeySetting />
|
||||||
<KeyInfo />
|
<KeyInfo />
|
||||||
<template v-for="(_, index) in store.editKeyMappingList">
|
<template v-for="(_, index) in store.editKeyMappingList">
|
||||||
<KeySteeringWheel
|
<KeySteeringWheel
|
||||||
|
@ -20,10 +20,6 @@ import { loadDefaultKeyconfig } from "../../invoke";
|
|||||||
import { KeyMappingConfig } from "../../keyMappingConfig";
|
import { KeyMappingConfig } from "../../keyMappingConfig";
|
||||||
import { useKeyboardStore } from "../../store/keyboard";
|
import { useKeyboardStore } from "../../store/keyboard";
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
resetEditKeyMappingList: [];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const store = useGlobalStore();
|
const store = useGlobalStore();
|
||||||
const keyboardStore = useKeyboardStore();
|
const keyboardStore = useKeyboardStore();
|
||||||
const localStore = new Store("store.bin");
|
const localStore = new Store("store.bin");
|
||||||
@ -74,7 +70,7 @@ onMounted(async () => {
|
|||||||
|
|
||||||
onActivated(() => {
|
onActivated(() => {
|
||||||
// reset editKeyMappingList as the same as keyMappingList
|
// reset editKeyMappingList as the same as keyMappingList
|
||||||
store.resetEditKeyMappingList();
|
resetKeyMappingConfig();
|
||||||
// check config relative size
|
// check config relative size
|
||||||
checkConfigSize();
|
checkConfigSize();
|
||||||
});
|
});
|
||||||
@ -124,6 +120,8 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
localStore.set("keySettingPos", keySettingPos.value);
|
localStore.set("keySettingPos", keySettingPos.value);
|
||||||
} else {
|
} else {
|
||||||
// click up
|
// click up
|
||||||
|
keyboardStore.activeButtonIndex = -1;
|
||||||
|
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
||||||
keyboardStore.showSettingFlag = !keyboardStore.showSettingFlag;
|
keyboardStore.showSettingFlag = !keyboardStore.showSettingFlag;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -167,6 +165,11 @@ async function importDefaultKeyMappingConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createKeyMappingConfig() {
|
function createKeyMappingConfig() {
|
||||||
|
if (keyboardStore.edited) {
|
||||||
|
message.error("请先保存或还原当前方案");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const keyboardElement = document.getElementById(
|
const keyboardElement = document.getElementById(
|
||||||
"keyboardElement"
|
"keyboardElement"
|
||||||
) as HTMLElement;
|
) as HTMLElement;
|
||||||
@ -185,6 +188,11 @@ function createKeyMappingConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function copyCurKeyMappingConfig() {
|
function copyCurKeyMappingConfig() {
|
||||||
|
if (keyboardStore.edited) {
|
||||||
|
message.error("请先保存或还原当前方案");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const curConfig = store.keyMappingConfigList[store.curKeyMappingIndex];
|
const curConfig = store.keyMappingConfigList[store.curKeyMappingIndex];
|
||||||
const newConfig: KeyMappingConfig = {
|
const newConfig: KeyMappingConfig = {
|
||||||
title: curConfig.title + "-副本",
|
title: curConfig.title + "-副本",
|
||||||
@ -192,6 +200,8 @@ function copyCurKeyMappingConfig() {
|
|||||||
list: curConfig.list,
|
list: curConfig.list,
|
||||||
};
|
};
|
||||||
store.keyMappingConfigList.push(newConfig);
|
store.keyMappingConfigList.push(newConfig);
|
||||||
|
keyboardStore.activeButtonIndex = -1;
|
||||||
|
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
||||||
store.setKeyMappingIndex(store.keyMappingConfigList.length - 1);
|
store.setKeyMappingIndex(store.keyMappingConfigList.length - 1);
|
||||||
localStore.set("keyMappingConfigList", store.keyMappingConfigList);
|
localStore.set("keyMappingConfigList", store.keyMappingConfigList);
|
||||||
message.success("方案已复制为:" + curConfig.title + "-副本");
|
message.success("方案已复制为:" + curConfig.title + "-副本");
|
||||||
@ -204,6 +214,11 @@ function delCurKeyMappingConfig() {
|
|||||||
}
|
}
|
||||||
const title = store.keyMappingConfigList[store.curKeyMappingIndex].title;
|
const title = store.keyMappingConfigList[store.curKeyMappingIndex].title;
|
||||||
store.keyMappingConfigList.splice(store.curKeyMappingIndex, 1);
|
store.keyMappingConfigList.splice(store.curKeyMappingIndex, 1);
|
||||||
|
|
||||||
|
// reset active and edit status
|
||||||
|
keyboardStore.activeButtonIndex = -1;
|
||||||
|
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
||||||
|
keyboardStore.edited = false;
|
||||||
store.setKeyMappingIndex(
|
store.setKeyMappingIndex(
|
||||||
store.curKeyMappingIndex > 0 ? store.curKeyMappingIndex - 1 : 0
|
store.curKeyMappingIndex > 0 ? store.curKeyMappingIndex - 1 : 0
|
||||||
);
|
);
|
||||||
@ -263,6 +278,11 @@ function checkConfigSize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function migrateKeyMappingConfig() {
|
function migrateKeyMappingConfig() {
|
||||||
|
if (keyboardStore.edited) {
|
||||||
|
message.error("请先保存或还原当前按键方案");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const keyboardElement = document.getElementById(
|
const keyboardElement = document.getElementById(
|
||||||
"keyboardElement"
|
"keyboardElement"
|
||||||
) as HTMLElement;
|
) as HTMLElement;
|
||||||
@ -294,12 +314,32 @@ function migrateKeyMappingConfig() {
|
|||||||
0,
|
0,
|
||||||
newConfig
|
newConfig
|
||||||
);
|
);
|
||||||
store.setKeyMappingIndex(store.curKeyMappingIndex + 1);
|
|
||||||
message.success("已迁移到新方案:" + newConfig.title);
|
message.success("已迁移到新方案:" + newConfig.title);
|
||||||
|
keyboardStore.activeButtonIndex = -1;
|
||||||
|
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
||||||
|
store.setKeyMappingIndex(store.curKeyMappingIndex + 1);
|
||||||
} else {
|
} else {
|
||||||
message.info("当前方案符合蒙版尺寸,无需迁移");
|
message.info("当前方案符合蒙版尺寸,无需迁移");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectKeyMappingConfig(index: number) {
|
||||||
|
if (keyboardStore.edited) {
|
||||||
|
message.error("请先保存或还原当前按键方案");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyboardStore.activeButtonIndex = -1;
|
||||||
|
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
||||||
|
store.setKeyMappingIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetKeyMappingConfig() {
|
||||||
|
keyboardStore.activeButtonIndex = -1;
|
||||||
|
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
||||||
|
store.resetEditKeyMappingList();
|
||||||
|
keyboardStore.edited = false;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -320,7 +360,14 @@ function migrateKeyMappingConfig() {
|
|||||||
<NIcon><Settings /></NIcon>
|
<NIcon><Settings /></NIcon>
|
||||||
</template>
|
</template>
|
||||||
</NButton>
|
</NButton>
|
||||||
<div class="key-setting" v-show="keyboardStore.showSettingFlag">
|
<div
|
||||||
|
class="key-setting"
|
||||||
|
v-show="keyboardStore.showSettingFlag"
|
||||||
|
@mousedown="
|
||||||
|
keyboardStore.activeButtonIndex = -1;
|
||||||
|
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
||||||
|
"
|
||||||
|
>
|
||||||
<NButton
|
<NButton
|
||||||
text
|
text
|
||||||
class="key-setting-close"
|
class="key-setting-close"
|
||||||
@ -331,16 +378,14 @@ function migrateKeyMappingConfig() {
|
|||||||
<NH4 prefix="bar">按键方案</NH4>
|
<NH4 prefix="bar">按键方案</NH4>
|
||||||
<NSelect
|
<NSelect
|
||||||
:value="store.curKeyMappingIndex"
|
:value="store.curKeyMappingIndex"
|
||||||
@update:value="(value: number)=>store.setKeyMappingIndex(value)"
|
@update:value="selectKeyMappingConfig"
|
||||||
:options="keyMappingNameOptions"
|
:options="keyMappingNameOptions"
|
||||||
/>
|
/>
|
||||||
<NP> Relative Size:{{ curRelativeSize.w }}x{{ curRelativeSize.h }} </NP>
|
<NP> Relative Size:{{ curRelativeSize.w }}x{{ curRelativeSize.h }} </NP>
|
||||||
<NFlex style="margin-top: 20px">
|
<NFlex style="margin-top: 20px">
|
||||||
<template v-if="keyboardStore.edited">
|
<template v-if="keyboardStore.edited">
|
||||||
<NButton type="success" @click="saveKeyMappingConfig">保存方案</NButton>
|
<NButton type="success" @click="saveKeyMappingConfig">保存方案</NButton>
|
||||||
<NButton type="error" @click="emit('resetEditKeyMappingList')"
|
<NButton type="error" @click="resetKeyMappingConfig">还原方案</NButton>
|
||||||
>还原方案</NButton
|
|
||||||
>
|
|
||||||
</template>
|
</template>
|
||||||
<NButton @click="createKeyMappingConfig">新建方案</NButton>
|
<NButton @click="createKeyMappingConfig">新建方案</NButton>
|
||||||
<NButton @click="copyCurKeyMappingConfig">复制方案</NButton>
|
<NButton @click="copyCurKeyMappingConfig">复制方案</NButton>
|
||||||
|
Loading…
Reference in New Issue
Block a user