mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2025-02-23 07:22:17 +08:00
feat(KeyBoard): optimize the display of button setting
This commit is contained in:
parent
934c90cc2d
commit
79c70de696
@ -11,7 +11,6 @@ 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";
|
||||||
|
|
||||||
// TODO 设置面板的出现位置,不应该超出范围
|
|
||||||
// TODO 为技能添加圆形边框范围,将range属性转换为技能的灵敏度,鼠标移动按比例缩放,100时技能范围最大,最不灵敏,0时就是直接指向对应方向的技能边框的
|
// TODO 为技能添加圆形边框范围,将range属性转换为技能的灵敏度,鼠标移动按比例缩放,100时技能范围最大,最不灵敏,0时就是直接指向对应方向的技能边框的
|
||||||
// TODO 右键空白区域添加按键
|
// TODO 右键空白区域添加按键
|
||||||
// TODO 设置界面添加本地数据编辑器(类似utools)
|
// TODO 设置界面添加本地数据编辑器(类似utools)
|
||||||
|
@ -14,11 +14,7 @@ import {
|
|||||||
NInputNumber,
|
NInputNumber,
|
||||||
} from "naive-ui";
|
} from "naive-ui";
|
||||||
import { CloseCircle, Settings } from "@vicons/ionicons5";
|
import { CloseCircle, Settings } from "@vicons/ionicons5";
|
||||||
import {
|
import { KeyMacro, KeyMacroList, KeyTap } from "../../keyMappingConfig";
|
||||||
KeyMacro,
|
|
||||||
KeyMacroList,
|
|
||||||
KeyTap,
|
|
||||||
} from "../../keyMappingConfig";
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
edit: [];
|
edit: [];
|
||||||
@ -148,6 +144,20 @@ function saveMacro() {
|
|||||||
message.error("宏代码保存失败,请检查代码格式是否正确");
|
message.error("宏代码保存失败,请检查代码格式是否正确");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const settingPosX = ref(0);
|
||||||
|
const settingPosY = ref(0);
|
||||||
|
function showSetting() {
|
||||||
|
const keyboardElement = document.getElementById(
|
||||||
|
"keyboardElement"
|
||||||
|
) as HTMLElement;
|
||||||
|
const maxWidth = keyboardElement.clientWidth - 150;
|
||||||
|
const maxHeight = keyboardElement.clientHeight - 220;
|
||||||
|
|
||||||
|
settingPosX.value = Math.min(keyMapping.value.posX + 25, maxWidth);
|
||||||
|
settingPosY.value = Math.min(keyMapping.value.posY - 25, maxHeight);
|
||||||
|
showButtonSettingFlag.value = true;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -177,7 +187,7 @@ function saveMacro() {
|
|||||||
<NButton
|
<NButton
|
||||||
class="key-setting-btn"
|
class="key-setting-btn"
|
||||||
text
|
text
|
||||||
@click="showButtonSettingFlag = true"
|
@click="showSetting"
|
||||||
:type="isActive ? 'primary' : 'info'"
|
:type="isActive ? 'primary' : 'info'"
|
||||||
>
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
@ -191,8 +201,8 @@ function saveMacro() {
|
|||||||
class="key-setting"
|
class="key-setting"
|
||||||
v-if="isActive && showButtonSettingFlag"
|
v-if="isActive && showButtonSettingFlag"
|
||||||
:style="{
|
:style="{
|
||||||
left: `${keyMapping.posX + 25}px`,
|
left: `${settingPosX}px`,
|
||||||
top: `${keyMapping.posY - 45}px`,
|
top: `${settingPosY}px`,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<NH4 prefix="bar">{{
|
<NH4 prefix="bar">{{
|
||||||
@ -269,7 +279,9 @@ function saveMacro() {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
width: 100px;
|
box-sizing: border-box;
|
||||||
|
width: 150px;
|
||||||
|
height: 220px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
border: 2px solid var(--light-color);
|
border: 2px solid var(--light-color);
|
||||||
background-color: var(--bg-color);
|
background-color: var(--bg-color);
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { NIcon } from "naive-ui";
|
import { NIcon } from "naive-ui";
|
||||||
import { CloseCircle } from "@vicons/ionicons5";
|
import { CloseCircle } from "@vicons/ionicons5";
|
||||||
import { Ref, onActivated, ref } from "vue";
|
import { Ref, ref, watch } from "vue";
|
||||||
import { onBeforeRouteLeave } from "vue-router";
|
|
||||||
|
|
||||||
const showKeyInfoFlag = defineModel("showKeyInfoFlag", { required: true });
|
const showKeyInfoFlag = defineModel("showKeyInfoFlag", { required: true });
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ function mousemoveHandler(event: MouseEvent) {
|
|||||||
const keyboardCodeList: Ref<string[]> = ref([]);
|
const keyboardCodeList: Ref<string[]> = ref([]);
|
||||||
function keyupHandler(event: KeyboardEvent) {
|
function keyupHandler(event: KeyboardEvent) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (keyboardCodeList.value.length > 10) {
|
if (keyboardCodeList.value.length > 5) {
|
||||||
keyboardCodeList.value.shift();
|
keyboardCodeList.value.shift();
|
||||||
keyboardCodeList.value.push(event.code);
|
keyboardCodeList.value.push(event.code);
|
||||||
} else keyboardCodeList.value.push(event.code);
|
} else keyboardCodeList.value.push(event.code);
|
||||||
@ -36,27 +35,25 @@ function keyupHandler(event: KeyboardEvent) {
|
|||||||
|
|
||||||
function mousedownHandler(event: MouseEvent) {
|
function mousedownHandler(event: MouseEvent) {
|
||||||
const key = `M${event.button}`;
|
const key = `M${event.button}`;
|
||||||
if (keyboardCodeList.value.length > 10) {
|
if (keyboardCodeList.value.length > 5) {
|
||||||
keyboardCodeList.value.shift();
|
keyboardCodeList.value.shift();
|
||||||
keyboardCodeList.value.push(key);
|
keyboardCodeList.value.push(key);
|
||||||
} else keyboardCodeList.value.push(key);
|
} else keyboardCodeList.value.push(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
onActivated(() => {
|
watch(showKeyInfoFlag, (value) => {
|
||||||
const keyboardElement = document.getElementById("keyboardElement");
|
const keyboardElement = document.getElementById(
|
||||||
if (keyboardElement) {
|
"keyboardElement"
|
||||||
|
) as HTMLElement;
|
||||||
|
if (value) {
|
||||||
keyboardElement.addEventListener("mousemove", mousemoveHandler);
|
keyboardElement.addEventListener("mousemove", mousemoveHandler);
|
||||||
keyboardElement.addEventListener("mousedown", mousedownHandler);
|
keyboardElement.addEventListener("mousedown", mousedownHandler);
|
||||||
document.addEventListener("keyup", keyupHandler);
|
document.addEventListener("keyup", keyupHandler);
|
||||||
}
|
} else {
|
||||||
});
|
|
||||||
|
|
||||||
onBeforeRouteLeave(() => {
|
|
||||||
const keyboardElement = document.getElementById("keyboardElement");
|
|
||||||
if (keyboardElement) {
|
|
||||||
keyboardElement.removeEventListener("mousemove", mousemoveHandler);
|
keyboardElement.removeEventListener("mousemove", mousemoveHandler);
|
||||||
keyboardElement.removeEventListener("mousedown", mousedownHandler);
|
keyboardElement.removeEventListener("mousedown", mousedownHandler);
|
||||||
document.removeEventListener("keyup", keyupHandler);
|
document.removeEventListener("keyup", keyupHandler);
|
||||||
|
keyboardCodeList.value.splice(0, keyboardCodeList.value.length);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -70,14 +67,27 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
const target = downEvent.target;
|
const target = downEvent.target;
|
||||||
downEvent.preventDefault();
|
downEvent.preventDefault();
|
||||||
target.style.setProperty("cursor", "grabbing");
|
target.style.setProperty("cursor", "grabbing");
|
||||||
|
|
||||||
const element = downEvent.target.parentElement;
|
const element = downEvent.target.parentElement;
|
||||||
|
const keyboardElement = document.getElementById(
|
||||||
|
"keyboardElement"
|
||||||
|
) as HTMLElement;
|
||||||
|
const maxWidth = keyboardElement.clientWidth - 120;
|
||||||
|
const maxHeight = keyboardElement.clientHeight - 200;
|
||||||
|
|
||||||
const x = downEvent.clientX;
|
const x = downEvent.clientX;
|
||||||
const y = downEvent.clientY;
|
const y = downEvent.clientY;
|
||||||
const moveHandler = (moveEvent: MouseEvent) => {
|
const moveHandler = (moveEvent: MouseEvent) => {
|
||||||
let left = lastPosX + moveEvent.clientX - x;
|
const newX = lastPosX + moveEvent.clientX - x;
|
||||||
let top = lastPosY + moveEvent.clientY - y;
|
const newY = lastPosY + moveEvent.clientY - y;
|
||||||
element?.style.setProperty("left", `${left < 0 ? 0 : left}px`);
|
element?.style.setProperty(
|
||||||
element?.style.setProperty("top", `${top < 0 ? 0 : top}px`);
|
"left",
|
||||||
|
`${Math.max(0, Math.min(newX, maxWidth))}px`
|
||||||
|
);
|
||||||
|
element?.style.setProperty(
|
||||||
|
"top",
|
||||||
|
`${Math.max(0, Math.min(newY, maxHeight))}px`
|
||||||
|
);
|
||||||
};
|
};
|
||||||
window.addEventListener("mousemove", moveHandler);
|
window.addEventListener("mousemove", moveHandler);
|
||||||
const upHandler = (upEvent: MouseEvent) => {
|
const upHandler = (upEvent: MouseEvent) => {
|
||||||
@ -117,8 +127,10 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
color: var(--light-color);
|
color: var(--light-color);
|
||||||
background-color: var(--content-bg-color);
|
background-color: var(--content-bg-color);
|
||||||
width: 120px;
|
width: 120px;
|
||||||
|
height: 200px;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
text-align: center;
|
||||||
z-index: 8;
|
z-index: 8;
|
||||||
|
|
||||||
.key-info-header {
|
.key-info-header {
|
||||||
@ -127,7 +139,6 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
border-radius: 10px 10px 0 0;
|
border-radius: 10px 10px 0 0;
|
||||||
text-align: center;
|
|
||||||
cursor: grab;
|
cursor: grab;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
@ -152,8 +163,10 @@ function dragHandler(downEvent: MouseEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.key-info-content {
|
.key-info-content {
|
||||||
text-align: center;
|
height: 180px;
|
||||||
|
box-sizing: border-box;
|
||||||
border: 1px solid var(--gray-color);
|
border: 1px solid var(--gray-color);
|
||||||
|
border-radius: 0 0 10px 10px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,20 @@ function delCurKeyMapping() {
|
|||||||
activeIndex.value = -1;
|
activeIndex.value = -1;
|
||||||
store.editKeyMappingList.splice(props.index, 1);
|
store.editKeyMappingList.splice(props.index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const settingPosX = ref(0);
|
||||||
|
const settingPosY = ref(0);
|
||||||
|
function showSetting() {
|
||||||
|
const keyboardElement = document.getElementById(
|
||||||
|
"keyboardElement"
|
||||||
|
) as HTMLElement;
|
||||||
|
const maxWidth = keyboardElement.clientWidth - 150;
|
||||||
|
const maxHeight = keyboardElement.clientHeight - 220;
|
||||||
|
|
||||||
|
settingPosX.value = Math.min(keyMapping.value.posX + 40, maxWidth);
|
||||||
|
settingPosY.value = Math.min(keyMapping.value.posY - 30, maxHeight);
|
||||||
|
showButtonSettingFlag.value = true;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -96,7 +110,7 @@ function delCurKeyMapping() {
|
|||||||
<NButton
|
<NButton
|
||||||
class="key-setting-btn"
|
class="key-setting-btn"
|
||||||
text
|
text
|
||||||
@click="showButtonSettingFlag = true"
|
@click="showSetting"
|
||||||
:type="isActive ? 'primary' : 'info'"
|
:type="isActive ? 'primary' : 'info'"
|
||||||
>
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
@ -110,8 +124,8 @@ function delCurKeyMapping() {
|
|||||||
class="key-setting"
|
class="key-setting"
|
||||||
v-if="isActive && showButtonSettingFlag"
|
v-if="isActive && showButtonSettingFlag"
|
||||||
:style="{
|
:style="{
|
||||||
left: `${keyMapping.posX + 25}px`,
|
left: `${settingPosX}px`,
|
||||||
top: `${keyMapping.posY - 45}px`,
|
top: `${settingPosY}px`,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<NH4 prefix="bar">观察视角</NH4>
|
<NH4 prefix="bar">观察视角</NH4>
|
||||||
@ -139,7 +153,9 @@ function delCurKeyMapping() {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
width: 100px;
|
box-sizing: border-box;
|
||||||
|
width: 150px;
|
||||||
|
height: 220px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
border: 2px solid var(--light-color);
|
border: 2px solid var(--light-color);
|
||||||
background-color: var(--bg-color);
|
background-color: var(--bg-color);
|
||||||
|
@ -130,6 +130,20 @@ function changeSkillType(flag: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const settingPosX = ref(0);
|
||||||
|
const settingPosY = ref(0);
|
||||||
|
function showSetting() {
|
||||||
|
const keyboardElement = document.getElementById(
|
||||||
|
"keyboardElement"
|
||||||
|
) as HTMLElement;
|
||||||
|
const maxWidth = keyboardElement.clientWidth - 200;
|
||||||
|
const maxHeight = keyboardElement.clientHeight - 350;
|
||||||
|
|
||||||
|
settingPosX.value = Math.min(keyMapping.value.posX + 40, maxWidth);
|
||||||
|
settingPosY.value = Math.min(keyMapping.value.posY - 30, maxHeight);
|
||||||
|
showButtonSettingFlag.value = true;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -160,7 +174,7 @@ function changeSkillType(flag: string) {
|
|||||||
<NButton
|
<NButton
|
||||||
class="key-setting-btn"
|
class="key-setting-btn"
|
||||||
text
|
text
|
||||||
@click="showButtonSettingFlag = true"
|
@click="showSetting"
|
||||||
:type="isActive ? 'primary' : 'info'"
|
:type="isActive ? 'primary' : 'info'"
|
||||||
>
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
@ -174,8 +188,8 @@ function changeSkillType(flag: string) {
|
|||||||
class="key-setting"
|
class="key-setting"
|
||||||
v-if="isActive && showButtonSettingFlag"
|
v-if="isActive && showButtonSettingFlag"
|
||||||
:style="{
|
:style="{
|
||||||
left: `${keyMapping.posX + 65}px`,
|
left: `${settingPosX}px`,
|
||||||
top: `${keyMapping.posY - 90}px`,
|
top: `${settingPosY}px`,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<NH4 prefix="bar">技能</NH4>
|
<NH4 prefix="bar">技能</NH4>
|
||||||
@ -238,7 +252,9 @@ function changeSkillType(flag: string) {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
width: 120px;
|
box-sizing: border-box;
|
||||||
|
width: 200px;
|
||||||
|
height: 350px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
border: 2px solid var(--light-color);
|
border: 2px solid var(--light-color);
|
||||||
background-color: var(--bg-color);
|
background-color: var(--bg-color);
|
||||||
|
@ -82,6 +82,23 @@ function delCurKeyMapping() {
|
|||||||
activeIndex.value = -1;
|
activeIndex.value = -1;
|
||||||
store.editKeyMappingList.splice(props.index, 1);
|
store.editKeyMappingList.splice(props.index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const settingPosX = ref(0);
|
||||||
|
const settingPosY = ref(0);
|
||||||
|
function showSetting() {
|
||||||
|
const keyboardElement = document.getElementById(
|
||||||
|
"keyboardElement"
|
||||||
|
) as HTMLElement;
|
||||||
|
const maxWidth = keyboardElement.clientWidth - 150;
|
||||||
|
const maxHeight = keyboardElement.clientHeight - 220;
|
||||||
|
|
||||||
|
settingPosX.value = Math.min(
|
||||||
|
keyMapping.value.posX + offset.value + 10,
|
||||||
|
maxWidth
|
||||||
|
);
|
||||||
|
settingPosY.value = Math.min(keyMapping.value.posY - offset.value, maxHeight);
|
||||||
|
showButtonSettingFlag.value = true;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -151,7 +168,7 @@ function delCurKeyMapping() {
|
|||||||
<NButton
|
<NButton
|
||||||
class="key-setting-btn"
|
class="key-setting-btn"
|
||||||
text
|
text
|
||||||
@click="showButtonSettingFlag = true"
|
@click="showSetting"
|
||||||
:type="isActive ? 'primary' : 'info'"
|
:type="isActive ? 'primary' : 'info'"
|
||||||
:style="{
|
:style="{
|
||||||
left: `${offset * 2 + 10}px`,
|
left: `${offset * 2 + 10}px`,
|
||||||
@ -169,8 +186,8 @@ function delCurKeyMapping() {
|
|||||||
class="key-setting"
|
class="key-setting"
|
||||||
v-if="isActive && showButtonSettingFlag"
|
v-if="isActive && showButtonSettingFlag"
|
||||||
:style="{
|
:style="{
|
||||||
left: `${keyMapping.posX + offset + 10}px`,
|
left: `${settingPosX}px`,
|
||||||
top: `${keyMapping.posY - 120}px`,
|
top: `${settingPosY}px`,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<NH4 prefix="bar">键盘行走</NH4>
|
<NH4 prefix="bar">键盘行走</NH4>
|
||||||
@ -197,7 +214,9 @@ function delCurKeyMapping() {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
width: 100px;
|
box-sizing: border-box;
|
||||||
|
width: 150px;
|
||||||
|
height: 220px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
border: 2px solid var(--light-color);
|
border: 2px solid var(--light-color);
|
||||||
background-color: var(--bg-color);
|
background-color: var(--bg-color);
|
||||||
|
Loading…
Reference in New Issue
Block a user