mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2025-04-21 04:25:13 +08:00
feat(KeyBoard): use store
This commit is contained in:
parent
2fae4a93b8
commit
9b3c6e4aa2
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onActivated, ref } from "vue";
|
import { onActivated } from "vue";
|
||||||
import KeyInfo from "./KeyInfo.vue";
|
import KeyInfo from "./KeyInfo.vue";
|
||||||
import KeySetting from "./KeySetting.vue";
|
import KeySetting from "./KeySetting.vue";
|
||||||
import KeyCommon from "./KeyCommon.vue";
|
import KeyCommon from "./KeyCommon.vue";
|
||||||
@ -10,6 +10,7 @@ import { useGlobalStore } from "../../store/global";
|
|||||||
import { useDialog, useMessage } from "naive-ui";
|
import { useDialog, useMessage } from "naive-ui";
|
||||||
import { onBeforeRouteLeave } from "vue-router";
|
import { onBeforeRouteLeave } from "vue-router";
|
||||||
import KeyObservation from "./KeyObservation.vue";
|
import KeyObservation from "./KeyObservation.vue";
|
||||||
|
import { useKeyboardStore } from "../../store/keyboard";
|
||||||
|
|
||||||
// TODO 打开设置时要关闭active,建议将各种数据打包到一个对象中共享,省的麻烦
|
// TODO 打开设置时要关闭active,建议将各种数据打包到一个对象中共享,省的麻烦
|
||||||
// TODO 切换按键方案时提示未保存,然后修改edit
|
// TODO 切换按键方案时提示未保存,然后修改edit
|
||||||
@ -19,17 +20,11 @@ import KeyObservation from "./KeyObservation.vue";
|
|||||||
// TODO 添加开发者工具打开按钮
|
// TODO 添加开发者工具打开按钮
|
||||||
// TODO 添加息屏按键
|
// TODO 添加息屏按键
|
||||||
|
|
||||||
const showKeyInfoFlag = ref(false);
|
|
||||||
const showSettingFlag = ref(false);
|
|
||||||
const showButtonSettingFlag = ref(false);
|
|
||||||
const store = useGlobalStore();
|
const store = useGlobalStore();
|
||||||
|
const keyboardStore = useKeyboardStore();
|
||||||
const dialog = useDialog();
|
const dialog = useDialog();
|
||||||
const message = useMessage();
|
const message = useMessage();
|
||||||
|
|
||||||
const activeButtonIndex = ref(-1);
|
|
||||||
const activeSteeringWheelButtonKeyIndex = ref(-1);
|
|
||||||
let edited = ref(false);
|
|
||||||
|
|
||||||
function isKeyUnique(curKey: string): boolean {
|
function isKeyUnique(curKey: string): boolean {
|
||||||
const set = new Set<string>();
|
const set = new Set<string>();
|
||||||
for (const keyMapping of store.editKeyMappingList) {
|
for (const keyMapping of store.editKeyMappingList) {
|
||||||
@ -60,7 +55,7 @@ function setCurButtonKey(curKey: string) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const keyMapping = store.editKeyMappingList[activeButtonIndex.value];
|
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;
|
||||||
@ -74,45 +69,47 @@ function setCurButtonKey(curKey: string) {
|
|||||||
"left",
|
"left",
|
||||||
"right",
|
"right",
|
||||||
];
|
];
|
||||||
|
const activeSteeringWheelButtonKeyIndex =
|
||||||
|
keyboardStore.activeSteeringWheelButtonKeyIndex;
|
||||||
if (
|
if (
|
||||||
activeSteeringWheelButtonKeyIndex.value >= 0 &&
|
activeSteeringWheelButtonKeyIndex >= 0 &&
|
||||||
activeSteeringWheelButtonKeyIndex.value <= 3
|
activeSteeringWheelButtonKeyIndex <= 3
|
||||||
) {
|
) {
|
||||||
const curName = nameList[activeSteeringWheelButtonKeyIndex.value];
|
const curName = nameList[activeSteeringWheelButtonKeyIndex];
|
||||||
keyObject[curName] = curKey;
|
keyObject[curName] = curKey;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
keyMapping.key = curKey;
|
keyMapping.key = curKey;
|
||||||
}
|
}
|
||||||
edited.value = true;
|
keyboardStore.edited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleClick(event: MouseEvent) {
|
function handleClick(event: MouseEvent) {
|
||||||
if (event.button === 0) {
|
if (event.button === 0) {
|
||||||
// left click
|
// left click
|
||||||
if (event.target === document.getElementById("keyboardElement")) {
|
if (event.target === document.getElementById("keyboardElement")) {
|
||||||
if (showSettingFlag.value) {
|
if (keyboardStore.showSettingFlag) {
|
||||||
showSettingFlag.value = false;
|
keyboardStore.showSettingFlag = false;
|
||||||
} else {
|
} else {
|
||||||
activeButtonIndex.value = -1;
|
keyboardStore.activeButtonIndex = -1;
|
||||||
activeSteeringWheelButtonKeyIndex.value = -1;
|
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
||||||
showButtonSettingFlag.value = false;
|
keyboardStore.showButtonSettingFlag = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (event.button === 2) {
|
} else if (event.button === 2) {
|
||||||
// right click
|
// right click
|
||||||
if (event.target === document.getElementById("keyboardElement")) {
|
if (event.target === document.getElementById("keyboardElement")) {
|
||||||
// add button
|
// add button
|
||||||
if (showSettingFlag.value) showSettingFlag.value = false;
|
if (keyboardStore.showSettingFlag) keyboardStore.showSettingFlag = false;
|
||||||
activeButtonIndex.value = -1;
|
keyboardStore.activeButtonIndex = -1;
|
||||||
activeSteeringWheelButtonKeyIndex.value = -1;
|
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
||||||
|
|
||||||
console.log("弹出新增");
|
console.log("弹出新增");
|
||||||
} else if (
|
} else if (
|
||||||
// modify key
|
// modify key
|
||||||
activeButtonIndex.value !== -1 &&
|
keyboardStore.activeButtonIndex !== -1 &&
|
||||||
activeButtonIndex.value < store.editKeyMappingList.length &&
|
keyboardStore.activeButtonIndex < store.editKeyMappingList.length &&
|
||||||
!showButtonSettingFlag.value
|
!keyboardStore.showButtonSettingFlag
|
||||||
) {
|
) {
|
||||||
const curKey = `M${event.button}`;
|
const curKey = `M${event.button}`;
|
||||||
setCurButtonKey(curKey);
|
setCurButtonKey(curKey);
|
||||||
@ -121,9 +118,9 @@ function handleClick(event: MouseEvent) {
|
|||||||
// other click
|
// other click
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (
|
if (
|
||||||
activeButtonIndex.value !== -1 &&
|
keyboardStore.activeButtonIndex !== -1 &&
|
||||||
activeButtonIndex.value < store.editKeyMappingList.length &&
|
keyboardStore.activeButtonIndex < store.editKeyMappingList.length &&
|
||||||
!showButtonSettingFlag.value
|
!keyboardStore.showButtonSettingFlag
|
||||||
) {
|
) {
|
||||||
const curKey = `M${event.button}`;
|
const curKey = `M${event.button}`;
|
||||||
setCurButtonKey(curKey);
|
setCurButtonKey(curKey);
|
||||||
@ -133,9 +130,9 @@ function handleClick(event: MouseEvent) {
|
|||||||
|
|
||||||
function handleKeyUp(event: KeyboardEvent) {
|
function handleKeyUp(event: KeyboardEvent) {
|
||||||
if (
|
if (
|
||||||
activeButtonIndex.value !== -1 &&
|
keyboardStore.activeButtonIndex !== -1 &&
|
||||||
activeButtonIndex.value < store.editKeyMappingList.length &&
|
keyboardStore.activeButtonIndex < store.editKeyMappingList.length &&
|
||||||
!showButtonSettingFlag.value
|
!keyboardStore.showButtonSettingFlag
|
||||||
) {
|
) {
|
||||||
const curKey = event.code;
|
const curKey = event.code;
|
||||||
setCurButtonKey(curKey);
|
setCurButtonKey(curKey);
|
||||||
@ -144,9 +141,9 @@ function handleKeyUp(event: KeyboardEvent) {
|
|||||||
|
|
||||||
function handleMouseWheel(event: WheelEvent) {
|
function handleMouseWheel(event: WheelEvent) {
|
||||||
if (
|
if (
|
||||||
activeButtonIndex.value !== -1 &&
|
keyboardStore.activeButtonIndex !== -1 &&
|
||||||
activeButtonIndex.value < store.editKeyMappingList.length &&
|
keyboardStore.activeButtonIndex < store.editKeyMappingList.length &&
|
||||||
!showButtonSettingFlag.value
|
!keyboardStore.showButtonSettingFlag
|
||||||
) {
|
) {
|
||||||
if (event.deltaY > 0) {
|
if (event.deltaY > 0) {
|
||||||
// WheelDown
|
// WheelDown
|
||||||
@ -159,11 +156,11 @@ function handleMouseWheel(event: WheelEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resetEditKeyMappingList() {
|
function resetEditKeyMappingList() {
|
||||||
showSettingFlag.value = false;
|
keyboardStore.showSettingFlag = false;
|
||||||
activeButtonIndex.value = -1;
|
keyboardStore.activeButtonIndex = -1;
|
||||||
activeSteeringWheelButtonKeyIndex.value = -1;
|
keyboardStore.activeSteeringWheelButtonKeyIndex = -1;
|
||||||
store.resetEditKeyMappingList();
|
store.resetEditKeyMappingList();
|
||||||
edited.value = false;
|
keyboardStore.edited = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
onActivated(() => {
|
onActivated(() => {
|
||||||
@ -174,7 +171,7 @@ onActivated(() => {
|
|||||||
onBeforeRouteLeave(() => {
|
onBeforeRouteLeave(() => {
|
||||||
document.removeEventListener("keyup", handleKeyUp);
|
document.removeEventListener("keyup", handleKeyUp);
|
||||||
document.removeEventListener("wheel", handleMouseWheel);
|
document.removeEventListener("wheel", handleMouseWheel);
|
||||||
if (edited.value) {
|
if (keyboardStore.edited) {
|
||||||
dialog.warning({
|
dialog.warning({
|
||||||
title: "Warning",
|
title: "Warning",
|
||||||
content: "当前方案尚未保存,是否保存?",
|
content: "当前方案尚未保存,是否保存?",
|
||||||
@ -182,7 +179,7 @@ onBeforeRouteLeave(() => {
|
|||||||
negativeText: "取消",
|
negativeText: "取消",
|
||||||
onPositiveClick: () => {
|
onPositiveClick: () => {
|
||||||
if (store.applyEditKeyMappingList()) {
|
if (store.applyEditKeyMappingList()) {
|
||||||
edited.value = false;
|
keyboardStore.edited = false;
|
||||||
} else {
|
} else {
|
||||||
message.error("存在重复按键,无法保存");
|
message.error("存在重复按键,无法保存");
|
||||||
}
|
}
|
||||||
@ -203,23 +200,12 @@ onBeforeRouteLeave(() => {
|
|||||||
@mousedown="handleClick"
|
@mousedown="handleClick"
|
||||||
@contextmenu.prevent
|
@contextmenu.prevent
|
||||||
>
|
>
|
||||||
<KeySetting
|
<KeySetting @reset-edit-key-mapping-list="resetEditKeyMappingList" />
|
||||||
v-model:show-key-info-flag="showKeyInfoFlag"
|
<KeyInfo />
|
||||||
v-model:show-setting-flag="showSettingFlag"
|
|
||||||
v-model:edited="edited"
|
|
||||||
@reset-edit-key-mapping-list="resetEditKeyMappingList"
|
|
||||||
/>
|
|
||||||
<KeyInfo v-model:showKeyInfoFlag="showKeyInfoFlag" />
|
|
||||||
<template v-for="(_, index) in store.editKeyMappingList">
|
<template v-for="(_, index) in store.editKeyMappingList">
|
||||||
<KeySteeringWheel
|
<KeySteeringWheel
|
||||||
v-if="store.editKeyMappingList[index].type === 'SteeringWheel'"
|
v-if="store.editKeyMappingList[index].type === 'SteeringWheel'"
|
||||||
@edit="edited = true"
|
|
||||||
:index="index"
|
:index="index"
|
||||||
v-model:active-index="activeButtonIndex"
|
|
||||||
v-model:active-steering-wheel-button-key-index="
|
|
||||||
activeSteeringWheelButtonKeyIndex
|
|
||||||
"
|
|
||||||
v-model:show-button-setting-flag="showButtonSettingFlag"
|
|
||||||
/>
|
/>
|
||||||
<KeySkill
|
<KeySkill
|
||||||
v-else-if="
|
v-else-if="
|
||||||
@ -227,25 +213,13 @@ onBeforeRouteLeave(() => {
|
|||||||
store.editKeyMappingList[index].type === 'DirectionlessSkill' ||
|
store.editKeyMappingList[index].type === 'DirectionlessSkill' ||
|
||||||
store.editKeyMappingList[index].type === 'TriggerWhenPressedSkill'
|
store.editKeyMappingList[index].type === 'TriggerWhenPressedSkill'
|
||||||
"
|
"
|
||||||
@edit="edited = true"
|
|
||||||
:index="index"
|
:index="index"
|
||||||
v-model:active-index="activeButtonIndex"
|
|
||||||
v-model:show-button-setting-flag="showButtonSettingFlag"
|
|
||||||
/>
|
/>
|
||||||
<KeyObservation
|
<KeyObservation
|
||||||
v-else-if="store.editKeyMappingList[index].type === 'Observation'"
|
v-else-if="store.editKeyMappingList[index].type === 'Observation'"
|
||||||
@edit="edited = true"
|
|
||||||
:index="index"
|
:index="index"
|
||||||
v-model:active-index="activeButtonIndex"
|
|
||||||
v-model:show-button-setting-flag="showButtonSettingFlag"
|
|
||||||
/>
|
|
||||||
<KeyCommon
|
|
||||||
v-else
|
|
||||||
@edit="edited = true"
|
|
||||||
:index="index"
|
|
||||||
v-model:active-index="activeButtonIndex"
|
|
||||||
v-model:show-button-setting-flag="showButtonSettingFlag"
|
|
||||||
/>
|
/>
|
||||||
|
<KeyCommon v-else :index="index" />
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -15,25 +15,21 @@ import {
|
|||||||
} from "naive-ui";
|
} from "naive-ui";
|
||||||
import { CloseCircle, Settings } from "@vicons/ionicons5";
|
import { CloseCircle, Settings } from "@vicons/ionicons5";
|
||||||
import { KeyMacro, KeyMacroList, KeyTap } from "../../keyMappingConfig";
|
import { KeyMacro, KeyMacroList, KeyTap } from "../../keyMappingConfig";
|
||||||
|
import { useKeyboardStore } from "../../store/keyboard";
|
||||||
const emit = defineEmits<{
|
|
||||||
edit: [];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
index: number;
|
index: number;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const activeIndex = defineModel("activeIndex", { required: true });
|
const keyboardStore = useKeyboardStore();
|
||||||
const showButtonSettingFlag = defineModel("showButtonSettingFlag", {
|
|
||||||
required: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const store = useGlobalStore();
|
const store = useGlobalStore();
|
||||||
const message = useMessage();
|
const message = useMessage();
|
||||||
const elementRef = ref<HTMLElement | null>(null);
|
const elementRef = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
const isActive = computed(() => props.index === activeIndex.value);
|
const isActive = computed(
|
||||||
|
() => props.index === keyboardStore.activeButtonIndex
|
||||||
|
);
|
||||||
const keyMapping = computed(() => store.editKeyMappingList[props.index]);
|
const keyMapping = computed(() => store.editKeyMappingList[props.index]);
|
||||||
|
|
||||||
const showMacroModal = ref(false);
|
const showMacroModal = ref(false);
|
||||||
@ -44,8 +40,8 @@ const editedMacroRaw = ref({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function dragHandler(downEvent: MouseEvent) {
|
function dragHandler(downEvent: MouseEvent) {
|
||||||
activeIndex.value = props.index;
|
keyboardStore.activeButtonIndex = props.index;
|
||||||
showButtonSettingFlag.value = false;
|
keyboardStore.showButtonSettingFlag = false;
|
||||||
const oldX = keyMapping.value.posX;
|
const oldX = keyMapping.value.posX;
|
||||||
const oldY = keyMapping.value.posY;
|
const oldY = keyMapping.value.posY;
|
||||||
const element = elementRef.value;
|
const element = elementRef.value;
|
||||||
@ -71,7 +67,7 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
window.removeEventListener("mousemove", moveHandler);
|
window.removeEventListener("mousemove", moveHandler);
|
||||||
window.removeEventListener("mouseup", upHandler);
|
window.removeEventListener("mouseup", upHandler);
|
||||||
if (oldX !== keyMapping.value.posX || oldY !== keyMapping.value.posY) {
|
if (oldX !== keyMapping.value.posX || oldY !== keyMapping.value.posY) {
|
||||||
emit("edit");
|
keyboardStore.edited = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
window.addEventListener("mouseup", upHandler);
|
window.addEventListener("mouseup", upHandler);
|
||||||
@ -79,8 +75,8 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function delCurKeyMapping() {
|
function delCurKeyMapping() {
|
||||||
emit("edit");
|
keyboardStore.edited = true;
|
||||||
activeIndex.value = -1;
|
keyboardStore.activeButtonIndex = -1;
|
||||||
store.editKeyMappingList.splice(props.index, 1);
|
store.editKeyMappingList.splice(props.index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +133,7 @@ function saveMacro() {
|
|||||||
|
|
||||||
(keyMapping.value as KeyMacro).macro = macro;
|
(keyMapping.value as KeyMacro).macro = macro;
|
||||||
showMacroModal.value = false;
|
showMacroModal.value = false;
|
||||||
emit("edit");
|
keyboardStore.edited = true;
|
||||||
message.success("宏代码解析成功,但不保证代码正确性,请自行测试");
|
message.success("宏代码解析成功,但不保证代码正确性,请自行测试");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@ -156,7 +152,7 @@ function showSetting() {
|
|||||||
|
|
||||||
settingPosX.value = Math.min(keyMapping.value.posX + 25, maxWidth);
|
settingPosX.value = Math.min(keyMapping.value.posX + 25, maxWidth);
|
||||||
settingPosY.value = Math.min(keyMapping.value.posY - 25, maxHeight);
|
settingPosY.value = Math.min(keyMapping.value.posY - 25, maxHeight);
|
||||||
showButtonSettingFlag.value = true;
|
keyboardStore.showButtonSettingFlag = true;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -199,7 +195,7 @@ function showSetting() {
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="key-setting"
|
class="key-setting"
|
||||||
v-if="isActive && showButtonSettingFlag"
|
v-if="isActive && keyboardStore.showButtonSettingFlag"
|
||||||
:style="{
|
:style="{
|
||||||
left: `${settingPosX}px`,
|
left: `${settingPosX}px`,
|
||||||
top: `${settingPosY}px`,
|
top: `${settingPosY}px`,
|
||||||
@ -220,14 +216,14 @@ function showSetting() {
|
|||||||
v-model:value="(keyMapping as KeyTap).time"
|
v-model:value="(keyMapping as KeyTap).time"
|
||||||
:min="0"
|
:min="0"
|
||||||
placeholder="请输入触摸时长(ms)"
|
placeholder="请输入触摸时长(ms)"
|
||||||
@update:value="emit('edit')"
|
@update:value="keyboardStore.edited = true"
|
||||||
/>
|
/>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem label="备注">
|
<NFormItem label="备注">
|
||||||
<NInput
|
<NInput
|
||||||
v-model:value="keyMapping.note"
|
v-model:value="keyMapping.note"
|
||||||
placeholder="请输入备注"
|
placeholder="请输入备注"
|
||||||
@update:value="emit('edit')"
|
@update:value="keyboardStore.edited = true"
|
||||||
/>
|
/>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NModal
|
<NModal
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
import { NIcon } from "naive-ui";
|
import { NIcon } from "naive-ui";
|
||||||
import { CloseCircle } from "@vicons/ionicons5";
|
import { CloseCircle } from "@vicons/ionicons5";
|
||||||
import { Ref, ref, watch } from "vue";
|
import { Ref, ref, watch } from "vue";
|
||||||
|
import { useKeyboardStore } from "../../store/keyboard";
|
||||||
|
|
||||||
const showKeyInfoFlag = defineModel("showKeyInfoFlag", { required: true });
|
const keyboardStore = useKeyboardStore();
|
||||||
|
|
||||||
const mouseX = ref(0);
|
const mouseX = ref(0);
|
||||||
const mouseY = ref(0);
|
const mouseY = ref(0);
|
||||||
@ -41,21 +42,24 @@ function mousedownHandler(event: MouseEvent) {
|
|||||||
} else keyboardCodeList.value.push(key);
|
} else keyboardCodeList.value.push(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(showKeyInfoFlag, (value) => {
|
watch(
|
||||||
const keyboardElement = document.getElementById(
|
() => keyboardStore.showKeyInfoFlag,
|
||||||
"keyboardElement"
|
(value) => {
|
||||||
) as HTMLElement;
|
const keyboardElement = document.getElementById(
|
||||||
if (value) {
|
"keyboardElement"
|
||||||
keyboardElement.addEventListener("mousemove", mousemoveHandler);
|
) as HTMLElement;
|
||||||
keyboardElement.addEventListener("mousedown", mousedownHandler);
|
if (value) {
|
||||||
document.addEventListener("keyup", keyupHandler);
|
keyboardElement.addEventListener("mousemove", mousemoveHandler);
|
||||||
} else {
|
keyboardElement.addEventListener("mousedown", mousedownHandler);
|
||||||
keyboardElement.removeEventListener("mousemove", mousemoveHandler);
|
document.addEventListener("keyup", keyupHandler);
|
||||||
keyboardElement.removeEventListener("mousedown", mousedownHandler);
|
} else {
|
||||||
document.removeEventListener("keyup", keyupHandler);
|
keyboardElement.removeEventListener("mousemove", mousemoveHandler);
|
||||||
keyboardCodeList.value.splice(0, keyboardCodeList.value.length);
|
keyboardElement.removeEventListener("mousedown", mousedownHandler);
|
||||||
|
document.removeEventListener("keyup", keyupHandler);
|
||||||
|
keyboardCodeList.value.splice(0, keyboardCodeList.value.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
let lastPosX = 0;
|
let lastPosX = 0;
|
||||||
let lastPosY = 0;
|
let lastPosY = 0;
|
||||||
@ -103,10 +107,13 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-show="showKeyInfoFlag" class="key-info" @contextmenu.prevent>
|
<div v-show="keyboardStore.showKeyInfoFlag" class="key-info" @contextmenu.prevent>
|
||||||
<div class="key-info-header" @mousedown="dragHandler">
|
<div class="key-info-header" @mousedown="dragHandler">
|
||||||
Key Info
|
Key Info
|
||||||
<div class="key-info-close" @click="showKeyInfoFlag = false">
|
<div
|
||||||
|
class="key-info-close"
|
||||||
|
@click="keyboardStore.showKeyInfoFlag = false"
|
||||||
|
>
|
||||||
<NIcon><CloseCircle></CloseCircle></NIcon>
|
<NIcon><CloseCircle></CloseCircle></NIcon>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -4,31 +4,27 @@ import { useGlobalStore } from "../../store/global";
|
|||||||
import { NIcon, NButton, NFormItem, NInput, NH4, NInputNumber } from "naive-ui";
|
import { NIcon, NButton, NFormItem, NInput, NH4, NInputNumber } from "naive-ui";
|
||||||
import { Eye, CloseCircle, Settings } from "@vicons/ionicons5";
|
import { Eye, CloseCircle, Settings } from "@vicons/ionicons5";
|
||||||
import { KeyObservation } from "../../keyMappingConfig";
|
import { KeyObservation } from "../../keyMappingConfig";
|
||||||
|
import { useKeyboardStore } from "../../store/keyboard";
|
||||||
const emit = defineEmits<{
|
|
||||||
edit: [];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
index: number;
|
index: number;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const activeIndex = defineModel("activeIndex", { required: true });
|
const keyboardStore = useKeyboardStore();
|
||||||
const showButtonSettingFlag = defineModel("showButtonSettingFlag", {
|
|
||||||
required: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const store = useGlobalStore();
|
const store = useGlobalStore();
|
||||||
const elementRef = ref<HTMLElement | null>(null);
|
const elementRef = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
const isActive = computed(() => props.index === activeIndex.value);
|
const isActive = computed(
|
||||||
|
() => props.index === keyboardStore.activeButtonIndex
|
||||||
|
);
|
||||||
const keyMapping = computed(
|
const keyMapping = computed(
|
||||||
() => store.editKeyMappingList[props.index] as KeyObservation
|
() => store.editKeyMappingList[props.index] as KeyObservation
|
||||||
);
|
);
|
||||||
|
|
||||||
function dragHandler(downEvent: MouseEvent) {
|
function dragHandler(downEvent: MouseEvent) {
|
||||||
activeIndex.value = props.index;
|
keyboardStore.activeButtonIndex = props.index;
|
||||||
showButtonSettingFlag.value = false;
|
keyboardStore.showButtonSettingFlag = false;
|
||||||
const oldX = keyMapping.value.posX;
|
const oldX = keyMapping.value.posX;
|
||||||
const oldY = keyMapping.value.posY;
|
const oldY = keyMapping.value.posY;
|
||||||
const element = elementRef.value;
|
const element = elementRef.value;
|
||||||
@ -54,7 +50,7 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
window.removeEventListener("mousemove", moveHandler);
|
window.removeEventListener("mousemove", moveHandler);
|
||||||
window.removeEventListener("mouseup", upHandler);
|
window.removeEventListener("mouseup", upHandler);
|
||||||
if (oldX !== keyMapping.value.posX || oldY !== keyMapping.value.posY) {
|
if (oldX !== keyMapping.value.posX || oldY !== keyMapping.value.posY) {
|
||||||
emit("edit");
|
keyboardStore.edited = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
window.addEventListener("mouseup", upHandler);
|
window.addEventListener("mouseup", upHandler);
|
||||||
@ -62,8 +58,8 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function delCurKeyMapping() {
|
function delCurKeyMapping() {
|
||||||
emit("edit");
|
keyboardStore.edited = true;
|
||||||
activeIndex.value = -1;
|
keyboardStore.activeButtonIndex = -1;
|
||||||
store.editKeyMappingList.splice(props.index, 1);
|
store.editKeyMappingList.splice(props.index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +74,7 @@ function showSetting() {
|
|||||||
|
|
||||||
settingPosX.value = Math.min(keyMapping.value.posX + 40, maxWidth);
|
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 - 30, maxHeight);
|
||||||
showButtonSettingFlag.value = true;
|
keyboardStore.showButtonSettingFlag = true;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -122,7 +118,7 @@ function showSetting() {
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="key-setting"
|
class="key-setting"
|
||||||
v-if="isActive && showButtonSettingFlag"
|
v-if="isActive && keyboardStore.showButtonSettingFlag"
|
||||||
:style="{
|
:style="{
|
||||||
left: `${settingPosX}px`,
|
left: `${settingPosX}px`,
|
||||||
top: `${settingPosY}px`,
|
top: `${settingPosY}px`,
|
||||||
@ -134,14 +130,14 @@ function showSetting() {
|
|||||||
v-model:value="keyMapping.scale"
|
v-model:value="keyMapping.scale"
|
||||||
placeholder="请输入灵敏度"
|
placeholder="请输入灵敏度"
|
||||||
:step="0.1"
|
:step="0.1"
|
||||||
@update:value="emit('edit')"
|
@update:value="keyboardStore.edited = true"
|
||||||
/>
|
/>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem label="备注">
|
<NFormItem label="备注">
|
||||||
<NInput
|
<NInput
|
||||||
v-model:value="keyMapping.note"
|
v-model:value="keyMapping.note"
|
||||||
placeholder="请输入备注"
|
placeholder="请输入备注"
|
||||||
@update:value="emit('edit')"
|
@update:value="keyboardStore.edited = true"
|
||||||
/>
|
/>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
</div>
|
</div>
|
||||||
|
@ -18,19 +18,17 @@ import { Store } from "@tauri-apps/plugin-store";
|
|||||||
import { writeText } from "@tauri-apps/plugin-clipboard-manager";
|
import { writeText } from "@tauri-apps/plugin-clipboard-manager";
|
||||||
import { loadDefaultKeyconfig } from "../../invoke";
|
import { loadDefaultKeyconfig } from "../../invoke";
|
||||||
import { KeyMappingConfig } from "../../keyMappingConfig";
|
import { KeyMappingConfig } from "../../keyMappingConfig";
|
||||||
|
import { useKeyboardStore } from "../../store/keyboard";
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
resetEditKeyMappingList: [];
|
resetEditKeyMappingList: [];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const store = useGlobalStore();
|
const store = useGlobalStore();
|
||||||
|
const keyboardStore = useKeyboardStore();
|
||||||
const localStore = new Store("store.bin");
|
const localStore = new Store("store.bin");
|
||||||
const message = useMessage();
|
const message = useMessage();
|
||||||
|
|
||||||
const showKeyInfoFlag = defineModel("showKeyInfoFlag", { required: true });
|
|
||||||
const showSettingFlag = defineModel("showSettingFlag", { required: true });
|
|
||||||
const edited = defineModel("edited", { required: true });
|
|
||||||
|
|
||||||
const showImportModal = ref(false);
|
const showImportModal = ref(false);
|
||||||
const showRenameModal = ref(false);
|
const showRenameModal = ref(false);
|
||||||
const importModalInputValue = ref("");
|
const importModalInputValue = ref("");
|
||||||
@ -126,7 +124,7 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
localStore.set("keySettingPos", keySettingPos.value);
|
localStore.set("keySettingPos", keySettingPos.value);
|
||||||
} else {
|
} else {
|
||||||
// click up
|
// click up
|
||||||
showSettingFlag.value = !showSettingFlag.value;
|
keyboardStore.showSettingFlag = !keyboardStore.showSettingFlag;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
window.addEventListener("mouseup", upHandler);
|
window.addEventListener("mouseup", upHandler);
|
||||||
@ -240,7 +238,7 @@ function exportKeyMappingConfig() {
|
|||||||
|
|
||||||
function saveKeyMappingConfig() {
|
function saveKeyMappingConfig() {
|
||||||
if (store.applyEditKeyMappingList()) {
|
if (store.applyEditKeyMappingList()) {
|
||||||
edited.value = false;
|
keyboardStore.edited = false;
|
||||||
} else {
|
} else {
|
||||||
message.error("存在重复按键,无法保存");
|
message.error("存在重复按键,无法保存");
|
||||||
}
|
}
|
||||||
@ -322,8 +320,12 @@ function migrateKeyMappingConfig() {
|
|||||||
<NIcon><Settings /></NIcon>
|
<NIcon><Settings /></NIcon>
|
||||||
</template>
|
</template>
|
||||||
</NButton>
|
</NButton>
|
||||||
<div class="key-setting" v-show="showSettingFlag">
|
<div class="key-setting" v-show="keyboardStore.showSettingFlag">
|
||||||
<NButton text class="key-setting-close" @click="showSettingFlag = false">
|
<NButton
|
||||||
|
text
|
||||||
|
class="key-setting-close"
|
||||||
|
@click="keyboardStore.showSettingFlag = false"
|
||||||
|
>
|
||||||
<NIcon><CloseCircle></CloseCircle></NIcon>
|
<NIcon><CloseCircle></CloseCircle></NIcon>
|
||||||
</NButton>
|
</NButton>
|
||||||
<NH4 prefix="bar">按键方案</NH4>
|
<NH4 prefix="bar">按键方案</NH4>
|
||||||
@ -334,7 +336,7 @@ function migrateKeyMappingConfig() {
|
|||||||
/>
|
/>
|
||||||
<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="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="emit('resetEditKeyMappingList')"
|
||||||
>还原方案</NButton
|
>还原方案</NButton
|
||||||
@ -364,7 +366,10 @@ function migrateKeyMappingConfig() {
|
|||||||
>
|
>
|
||||||
<NButton @click="exportKeyMappingConfig">导出方案</NButton>
|
<NButton @click="exportKeyMappingConfig">导出方案</NButton>
|
||||||
<NButton @click="importDefaultKeyMappingConfig">导入默认</NButton>
|
<NButton @click="importDefaultKeyMappingConfig">导入默认</NButton>
|
||||||
<NButton @click="showKeyInfoFlag = !showKeyInfoFlag">按键信息</NButton>
|
<NButton
|
||||||
|
@click="keyboardStore.showKeyInfoFlag = !keyboardStore.showKeyInfoFlag"
|
||||||
|
>按键信息</NButton
|
||||||
|
>
|
||||||
</NFlex>
|
</NFlex>
|
||||||
</div>
|
</div>
|
||||||
<NModal v-model:show="showImportModal">
|
<NModal v-model:show="showImportModal">
|
||||||
|
@ -16,28 +16,25 @@ import {
|
|||||||
KeyDirectionalSkill,
|
KeyDirectionalSkill,
|
||||||
KeyTriggerWhenPressedSkill,
|
KeyTriggerWhenPressedSkill,
|
||||||
} from "../../keyMappingConfig";
|
} from "../../keyMappingConfig";
|
||||||
const emit = defineEmits<{
|
import { useKeyboardStore } from "../../store/keyboard";
|
||||||
edit: [];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
index: number;
|
index: number;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const activeIndex = defineModel("activeIndex", { required: true });
|
const keyboardStore = useKeyboardStore();
|
||||||
const showButtonSettingFlag = defineModel("showButtonSettingFlag", {
|
|
||||||
required: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const store = useGlobalStore();
|
const store = useGlobalStore();
|
||||||
const elementRef = ref<HTMLElement | null>(null);
|
const elementRef = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
const isActive = computed(() => props.index === activeIndex.value);
|
const isActive = computed(
|
||||||
|
() => props.index === keyboardStore.activeButtonIndex
|
||||||
|
);
|
||||||
const keyMapping = computed(() => store.editKeyMappingList[props.index]);
|
const keyMapping = computed(() => store.editKeyMappingList[props.index]);
|
||||||
|
|
||||||
function dragHandler(downEvent: MouseEvent) {
|
function dragHandler(downEvent: MouseEvent) {
|
||||||
activeIndex.value = props.index;
|
keyboardStore.activeButtonIndex = props.index;
|
||||||
showButtonSettingFlag.value = false;
|
keyboardStore.showButtonSettingFlag = false;
|
||||||
const oldX = keyMapping.value.posX;
|
const oldX = keyMapping.value.posX;
|
||||||
const oldY = keyMapping.value.posY;
|
const oldY = keyMapping.value.posY;
|
||||||
const element = elementRef.value;
|
const element = elementRef.value;
|
||||||
@ -63,7 +60,7 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
window.removeEventListener("mousemove", moveHandler);
|
window.removeEventListener("mousemove", moveHandler);
|
||||||
window.removeEventListener("mouseup", upHandler);
|
window.removeEventListener("mouseup", upHandler);
|
||||||
if (oldX !== keyMapping.value.posX || oldY !== keyMapping.value.posY) {
|
if (oldX !== keyMapping.value.posX || oldY !== keyMapping.value.posY) {
|
||||||
emit("edit");
|
keyboardStore.edited = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
window.addEventListener("mouseup", upHandler);
|
window.addEventListener("mouseup", upHandler);
|
||||||
@ -71,8 +68,9 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function delCurKeyMapping() {
|
function delCurKeyMapping() {
|
||||||
emit("edit");
|
keyboardStore.edited = true;
|
||||||
activeIndex.value = -1;
|
|
||||||
|
keyboardStore.activeButtonIndex = -1;
|
||||||
store.editKeyMappingList.splice(props.index, 1);
|
store.editKeyMappingList.splice(props.index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +89,7 @@ function changeSkillType(flag: string) {
|
|||||||
// the design of skill keymapping type is not good
|
// the design of skill keymapping type is not good
|
||||||
const t = keyMapping.value.type;
|
const t = keyMapping.value.type;
|
||||||
if (flag === "direction") {
|
if (flag === "direction") {
|
||||||
emit("edit");
|
keyboardStore.edited = true;
|
||||||
if (t === "DirectionalSkill") {
|
if (t === "DirectionalSkill") {
|
||||||
delete (keyMapping.value as any).range;
|
delete (keyMapping.value as any).range;
|
||||||
keyMapping.value.type = "DirectionlessSkill";
|
keyMapping.value.type = "DirectionlessSkill";
|
||||||
@ -104,7 +102,7 @@ function changeSkillType(flag: string) {
|
|||||||
k.rangeOrTime = k.directional ? 0 : 80;
|
k.rangeOrTime = k.directional ? 0 : 80;
|
||||||
}
|
}
|
||||||
} else if (flag === "trigger") {
|
} else if (flag === "trigger") {
|
||||||
emit("edit");
|
keyboardStore.edited = true;
|
||||||
if (t === "DirectionalSkill") {
|
if (t === "DirectionalSkill") {
|
||||||
const k = keyMapping.value as any;
|
const k = keyMapping.value as any;
|
||||||
k.directional = true;
|
k.directional = true;
|
||||||
@ -144,7 +142,7 @@ function showSetting() {
|
|||||||
settingPosX.value = Math.min(keyMapping.value.posX + 40, maxWidth);
|
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 - 30, maxHeight);
|
||||||
updateRangeIndicator(keyboardElement);
|
updateRangeIndicator(keyboardElement);
|
||||||
showButtonSettingFlag.value = true;
|
keyboardStore.showButtonSettingFlag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rangeIndicatorTop = ref(0);
|
const rangeIndicatorTop = ref(0);
|
||||||
@ -209,7 +207,7 @@ function updateRangeIndicator(element?: HTMLElement) {
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="key-setting"
|
class="key-setting"
|
||||||
v-if="isActive && showButtonSettingFlag"
|
v-if="isActive && keyboardStore.showButtonSettingFlag"
|
||||||
:style="{
|
:style="{
|
||||||
left: `${settingPosX}px`,
|
left: `${settingPosX}px`,
|
||||||
top: `${settingPosY}px`,
|
top: `${settingPosY}px`,
|
||||||
@ -238,7 +236,7 @@ function updateRangeIndicator(element?: HTMLElement) {
|
|||||||
:min="0"
|
:min="0"
|
||||||
:max="100"
|
:max="100"
|
||||||
@update:value="
|
@update:value="
|
||||||
emit('edit');
|
keyboardStore.edited = true;
|
||||||
updateRangeIndicator();
|
updateRangeIndicator();
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
@ -249,7 +247,7 @@ function updateRangeIndicator(element?: HTMLElement) {
|
|||||||
:min="0"
|
:min="0"
|
||||||
:max="100"
|
:max="100"
|
||||||
@update:value="
|
@update:value="
|
||||||
emit('edit');
|
keyboardStore.edited = true;
|
||||||
updateRangeIndicator();
|
updateRangeIndicator();
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
@ -262,19 +260,19 @@ function updateRangeIndicator(element?: HTMLElement) {
|
|||||||
v-model:value="(keyMapping as KeyTriggerWhenPressedSkill).rangeOrTime"
|
v-model:value="(keyMapping as KeyTriggerWhenPressedSkill).rangeOrTime"
|
||||||
:min="0"
|
:min="0"
|
||||||
placeholder="请输入触摸时长(ms)"
|
placeholder="请输入触摸时长(ms)"
|
||||||
@update:value="emit('edit')"
|
@update:value="keyboardStore.edited = true"
|
||||||
/>
|
/>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem label="备注">
|
<NFormItem label="备注">
|
||||||
<NInput
|
<NInput
|
||||||
v-model:value="keyMapping.note"
|
v-model:value="keyMapping.note"
|
||||||
placeholder="请输入备注"
|
placeholder="请输入备注"
|
||||||
@update:value="emit('edit')"
|
@update:value="keyboardStore.edited = true"
|
||||||
/>
|
/>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="isActive && showButtonSettingFlag"
|
v-if="isActive && keyboardStore.showButtonSettingFlag"
|
||||||
class="range-indicator"
|
class="range-indicator"
|
||||||
:style="{
|
:style="{
|
||||||
top: `${rangeIndicatorTop}px`,
|
top: `${rangeIndicatorTop}px`,
|
||||||
|
@ -4,29 +4,20 @@ import { useGlobalStore } from "../../store/global";
|
|||||||
import { KeySteeringWheel } from "../../keyMappingConfig";
|
import { KeySteeringWheel } from "../../keyMappingConfig";
|
||||||
import { NButton, NFormItem, NH4, NIcon, NInput, NInputNumber } from "naive-ui";
|
import { NButton, NFormItem, NH4, NIcon, NInput, NInputNumber } from "naive-ui";
|
||||||
import { CloseCircle, Move, Settings } from "@vicons/ionicons5";
|
import { CloseCircle, Move, Settings } from "@vicons/ionicons5";
|
||||||
|
import { useKeyboardStore } from "../../store/keyboard";
|
||||||
const emit = defineEmits<{
|
|
||||||
edit: [];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
index: number;
|
index: number;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const activeSteeringWheelButtonKeyIndex = defineModel(
|
const keyboardStore = useKeyboardStore();
|
||||||
"activeSteeringWheelButtonKeyIndex",
|
|
||||||
{ required: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
const activeIndex = defineModel("activeIndex", { required: true });
|
|
||||||
const showButtonSettingFlag = defineModel("showButtonSettingFlag", {
|
|
||||||
required: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const store = useGlobalStore();
|
const store = useGlobalStore();
|
||||||
const elementRef = ref<HTMLElement | null>(null);
|
const elementRef = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
const isActive = computed(() => props.index === activeIndex.value);
|
const isActive = computed(
|
||||||
|
() => props.index === keyboardStore.activeButtonIndex
|
||||||
|
);
|
||||||
const keyMapping = computed(
|
const keyMapping = computed(
|
||||||
() => store.editKeyMappingList[props.index] as KeySteeringWheel
|
() => store.editKeyMappingList[props.index] as KeySteeringWheel
|
||||||
);
|
);
|
||||||
@ -45,8 +36,8 @@ const offset = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function dragHandler(downEvent: MouseEvent) {
|
function dragHandler(downEvent: MouseEvent) {
|
||||||
activeIndex.value = props.index;
|
keyboardStore.activeButtonIndex = props.index;
|
||||||
showButtonSettingFlag.value = false;
|
keyboardStore.showButtonSettingFlag = false;
|
||||||
const oldX = keyMapping.value.posX;
|
const oldX = keyMapping.value.posX;
|
||||||
const oldY = keyMapping.value.posY;
|
const oldY = keyMapping.value.posY;
|
||||||
const element = elementRef.value;
|
const element = elementRef.value;
|
||||||
@ -72,7 +63,7 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
window.removeEventListener("mousemove", moveHandler);
|
window.removeEventListener("mousemove", moveHandler);
|
||||||
window.removeEventListener("mouseup", upHandler);
|
window.removeEventListener("mouseup", upHandler);
|
||||||
if (oldX !== keyMapping.value.posX || oldY !== keyMapping.value.posY) {
|
if (oldX !== keyMapping.value.posX || oldY !== keyMapping.value.posY) {
|
||||||
emit("edit");
|
keyboardStore.edited = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
window.addEventListener("mouseup", upHandler);
|
window.addEventListener("mouseup", upHandler);
|
||||||
@ -80,8 +71,8 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function delCurKeyMapping() {
|
function delCurKeyMapping() {
|
||||||
emit("edit");
|
keyboardStore.edited = true;
|
||||||
activeIndex.value = -1;
|
keyboardStore.activeButtonIndex = -1;
|
||||||
store.editKeyMappingList.splice(props.index, 1);
|
store.editKeyMappingList.splice(props.index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +90,7 @@ function showSetting() {
|
|||||||
maxWidth
|
maxWidth
|
||||||
);
|
);
|
||||||
settingPosY.value = Math.min(keyMapping.value.posY - offset.value, maxHeight);
|
settingPosY.value = Math.min(keyMapping.value.posY - offset.value, maxHeight);
|
||||||
showButtonSettingFlag.value = true;
|
keyboardStore.showButtonSettingFlag = true;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -118,17 +109,19 @@ function showSetting() {
|
|||||||
>
|
>
|
||||||
<i />
|
<i />
|
||||||
<span
|
<span
|
||||||
@mousedown="activeSteeringWheelButtonKeyIndex = 0"
|
@mousedown="keyboardStore.activeSteeringWheelButtonKeyIndex = 0"
|
||||||
:class="{
|
:class="{
|
||||||
'active-wheel': isActive && activeSteeringWheelButtonKeyIndex == 0,
|
'active-wheel':
|
||||||
|
isActive && keyboardStore.activeSteeringWheelButtonKeyIndex == 0,
|
||||||
}"
|
}"
|
||||||
>{{ keyMapping.key.up }}</span
|
>{{ keyMapping.key.up }}</span
|
||||||
>
|
>
|
||||||
<i />
|
<i />
|
||||||
<span
|
<span
|
||||||
@mousedown="activeSteeringWheelButtonKeyIndex = 2"
|
@mousedown="keyboardStore.activeSteeringWheelButtonKeyIndex = 2"
|
||||||
:class="{
|
:class="{
|
||||||
'active-wheel': isActive && activeSteeringWheelButtonKeyIndex == 2,
|
'active-wheel':
|
||||||
|
isActive && keyboardStore.activeSteeringWheelButtonKeyIndex == 2,
|
||||||
}"
|
}"
|
||||||
>{{ keyMapping.key.left }}</span
|
>{{ keyMapping.key.left }}</span
|
||||||
>
|
>
|
||||||
@ -136,17 +129,19 @@ function showSetting() {
|
|||||||
<Move />
|
<Move />
|
||||||
</NIcon>
|
</NIcon>
|
||||||
<span
|
<span
|
||||||
@mousedown="activeSteeringWheelButtonKeyIndex = 3"
|
@mousedown="keyboardStore.activeSteeringWheelButtonKeyIndex = 3"
|
||||||
:class="{
|
:class="{
|
||||||
'active-wheel': isActive && activeSteeringWheelButtonKeyIndex == 3,
|
'active-wheel':
|
||||||
|
isActive && keyboardStore.activeSteeringWheelButtonKeyIndex == 3,
|
||||||
}"
|
}"
|
||||||
>{{ keyMapping.key.right }}</span
|
>{{ keyMapping.key.right }}</span
|
||||||
>
|
>
|
||||||
<i />
|
<i />
|
||||||
<span
|
<span
|
||||||
@mousedown="activeSteeringWheelButtonKeyIndex = 1"
|
@mousedown="keyboardStore.activeSteeringWheelButtonKeyIndex = 1"
|
||||||
:class="{
|
:class="{
|
||||||
'active-wheel': isActive && activeSteeringWheelButtonKeyIndex == 1,
|
'active-wheel':
|
||||||
|
isActive && keyboardStore.activeSteeringWheelButtonKeyIndex == 1,
|
||||||
}"
|
}"
|
||||||
>{{ keyMapping.key.down }}</span
|
>{{ keyMapping.key.down }}</span
|
||||||
>
|
>
|
||||||
@ -186,7 +181,7 @@ function showSetting() {
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="key-setting"
|
class="key-setting"
|
||||||
v-if="isActive && showButtonSettingFlag"
|
v-if="isActive && keyboardStore.showButtonSettingFlag"
|
||||||
:style="{
|
:style="{
|
||||||
left: `${settingPosX}px`,
|
left: `${settingPosX}px`,
|
||||||
top: `${settingPosY}px`,
|
top: `${settingPosY}px`,
|
||||||
@ -197,14 +192,14 @@ function showSetting() {
|
|||||||
<NInputNumber
|
<NInputNumber
|
||||||
v-model:value="keyMapping.offset"
|
v-model:value="keyMapping.offset"
|
||||||
:min="1"
|
:min="1"
|
||||||
@update:value="emit('edit')"
|
@update:value="keyboardStore.edited = true"
|
||||||
/>
|
/>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem label="备注">
|
<NFormItem label="备注">
|
||||||
<NInput
|
<NInput
|
||||||
v-model:value="keyMapping.note"
|
v-model:value="keyMapping.note"
|
||||||
placeholder="请输入备注"
|
placeholder="请输入备注"
|
||||||
@update:value="emit('edit')"
|
@update:value="keyboardStore.edited = true"
|
||||||
/>
|
/>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,7 +10,7 @@ import { Store } from "@tauri-apps/plugin-store";
|
|||||||
|
|
||||||
const localStore = new Store("store.bin");
|
const localStore = new Store("store.bin");
|
||||||
|
|
||||||
export const useGlobalStore = defineStore("counter", () => {
|
export const useGlobalStore = defineStore("global", () => {
|
||||||
const showLoadingRef = ref(false);
|
const showLoadingRef = ref(false);
|
||||||
function showLoading() {
|
function showLoading() {
|
||||||
showLoadingRef.value = true;
|
showLoadingRef.value = true;
|
||||||
|
20
src/store/keyboard.ts
Normal file
20
src/store/keyboard.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { defineStore } from "pinia";
|
||||||
|
import { ref } from "vue";
|
||||||
|
|
||||||
|
export const useKeyboardStore = defineStore("keyboard", () => {
|
||||||
|
const showKeyInfoFlag = ref(false);
|
||||||
|
const showSettingFlag = ref(false);
|
||||||
|
const showButtonSettingFlag = ref(false);
|
||||||
|
const activeButtonIndex = ref(-1);
|
||||||
|
const activeSteeringWheelButtonKeyIndex = ref(-1);
|
||||||
|
const edited = ref(false);
|
||||||
|
|
||||||
|
return {
|
||||||
|
showKeyInfoFlag,
|
||||||
|
showSettingFlag,
|
||||||
|
showButtonSettingFlag,
|
||||||
|
activeButtonIndex,
|
||||||
|
activeSteeringWheelButtonKeyIndex,
|
||||||
|
edited,
|
||||||
|
};
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user