From 67dc5cbc062c8e188d263993ea7c1071621d6500 Mon Sep 17 00:00:00 2001 From: KUN1007 Date: Mon, 15 May 2023 01:47:25 +0800 Subject: [PATCH] new feature: drug Loli ! --- .../setting-panel/KUNGalgameSettingPanel.vue | 5 +- .../setting-panel/components/Drug.vue | 150 ++++++++++-------- .../setting-panel/components/Loli.vue | 89 ++++++----- 3 files changed, 136 insertions(+), 108 deletions(-) diff --git a/src/components/setting-panel/KUNGalgameSettingPanel.vue b/src/components/setting-panel/KUNGalgameSettingPanel.vue index db4fe596..7c9b8a0c 100644 --- a/src/components/setting-panel/KUNGalgameSettingPanel.vue +++ b/src/components/setting-panel/KUNGalgameSettingPanel.vue @@ -45,7 +45,7 @@ const handleClick = () => {} we + /> @@ -68,7 +68,6 @@ const handleClick = () => {} - @@ -83,7 +82,7 @@ const handleClick = () => {} width: 600px; top: 65px; right: 0; - position: fixed; + position: absolute; background-color: @kungalgame-trans-white-5; backdrop-filter: blur(5px); border-radius: 10px; diff --git a/src/components/setting-panel/components/Drug.vue b/src/components/setting-panel/components/Drug.vue index 17c8ea59..54fb7f6a 100644 --- a/src/components/setting-panel/components/Drug.vue +++ b/src/components/setting-panel/components/Drug.vue @@ -6,77 +6,95 @@ @wheel.prevent="changeSize" :style="boxStyle" > - 拖动我 +
+ - - diff --git a/src/components/setting-panel/components/Loli.vue b/src/components/setting-panel/components/Loli.vue index b275d6a2..472c7a6b 100644 --- a/src/components/setting-panel/components/Loli.vue +++ b/src/components/setting-panel/components/Loli.vue @@ -17,58 +17,66 @@ import { mouth, face, } from '@/utils/loli' -import { onMounted, onUnmounted, ref } from 'vue' -interface Position { - x: number - y: number -} -const box = ref(null) -const isDragging = ref(false) -const mousePosition = ref({ x: 0, y: 0 }) -const elementPosition = ref({ x: 120, y: -250 }) +// 用户拖动看板娘和缩放看板娘 +import { ref, reactive, CSSProperties, onMounted, onBeforeUnmount } from 'vue' -const handleMouseDown = (event: MouseEvent) => { - isDragging.value = true - mousePosition.value = { x: event.clientX, y: event.clientY } +const loli = ref(null) + +const state = reactive({ + isDragging: false, + isResizing: false, + origin: { x: 0, y: 0 }, + translation: { x: 0, y: 0 }, +}) + +const loliStyle: CSSProperties = { + top: `${state.translation.y}px`, + left: `${state.translation.x}px`, } -const handleMouseMove = (event: MouseEvent) => { - if (isDragging.value) { - const deltaX = event.clientX - mousePosition.value.x - const deltaY = event.clientY - mousePosition.value.y - elementPosition.value = { - x: elementPosition.value.x + deltaX, - y: elementPosition.value.y + deltaY, - } - mousePosition.value = { x: event.clientX, y: event.clientY } +const startDragLoli = (event: MouseEvent) => { + if (event.ctrlKey) { + state.isResizing = true + } else { + state.isDragging = true + } + state.origin.x = event.clientX + state.origin.y = event.clientY +} + +const stopDrag = () => { + state.isDragging = false + state.isResizing = false +} + +const drag = (event: MouseEvent) => { + if (state.isDragging && loli.value !== null) { + const deltaX = event.clientX - state.origin.x + const deltaY = event.clientY - state.origin.y + state.translation.x += deltaX + state.translation.y += deltaY + loli.value.style.top = `${state.translation.y}px` + loli.value.style.left = `${state.translation.x}px` + state.origin.x = event.clientX + state.origin.y = event.clientY } } -const handleMouseUp = () => { - isDragging.value = false -} - onMounted(() => { - box.value?.addEventListener('mousedown', handleMouseDown) - box.value?.addEventListener('mousemove', handleMouseMove) - box.value?.addEventListener('mouseup', handleMouseUp) + window.addEventListener('mouseup', stopDrag) + window.addEventListener('mousemove', drag) }) - -const loliPositionXPixel = elementPosition.value.x + 'px' -const loliPositionYPixel = elementPosition.value.y + 'px' - -onUnmounted(() => { - box.value?.removeEventListener('mousedown', handleMouseDown) - box.value?.removeEventListener('mousemove', handleMouseMove) - box.value?.removeEventListener('mouseup', handleMouseUp) +onBeforeUnmount(() => { + window.removeEventListener('mouseup', stopDrag) + window.removeEventListener('mousemove', drag) })