fix(CustomGameModal): improve difficulty map UX - resize and drag outside
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted, watch, nextTick } from 'vue';
|
import { ref, computed, onMounted, onUnmounted, watch, nextTick } from 'vue';
|
||||||
import { usePuzzleStore } from '@/stores/puzzle';
|
import { usePuzzleStore } from '@/stores/puzzle';
|
||||||
import { useI18n } from '@/composables/useI18n';
|
import { useI18n } from '@/composables/useI18n';
|
||||||
import { calculateDifficulty } from '@/utils/puzzleUtils';
|
import { calculateDifficulty } from '@/utils/puzzleUtils';
|
||||||
@@ -140,6 +140,9 @@ const updateFromEvent = (e) => {
|
|||||||
const startDrag = (e) => {
|
const startDrag = (e) => {
|
||||||
isDragging.value = true;
|
isDragging.value = true;
|
||||||
updateFromEvent(e);
|
updateFromEvent(e);
|
||||||
|
// Add global listeners for mouse to handle dragging outside canvas
|
||||||
|
window.addEventListener('mousemove', onDrag);
|
||||||
|
window.addEventListener('mouseup', stopDrag);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onDrag = (e) => {
|
const onDrag = (e) => {
|
||||||
@@ -149,8 +152,15 @@ const onDrag = (e) => {
|
|||||||
|
|
||||||
const stopDrag = () => {
|
const stopDrag = () => {
|
||||||
isDragging.value = false;
|
isDragging.value = false;
|
||||||
|
window.removeEventListener('mousemove', onDrag);
|
||||||
|
window.removeEventListener('mouseup', stopDrag);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
window.removeEventListener('mousemove', onDrag);
|
||||||
|
window.removeEventListener('mouseup', stopDrag);
|
||||||
|
});
|
||||||
|
|
||||||
const showAdvanced = ref(false);
|
const showAdvanced = ref(false);
|
||||||
|
|
||||||
const toggleAdvanced = () => {
|
const toggleAdvanced = () => {
|
||||||
@@ -271,12 +281,9 @@ const confirm = () => {
|
|||||||
<div class="map-section" v-if="showAdvanced">
|
<div class="map-section" v-if="showAdvanced">
|
||||||
<canvas
|
<canvas
|
||||||
ref="difficultyCanvas"
|
ref="difficultyCanvas"
|
||||||
width="200"
|
width="400"
|
||||||
height="200"
|
height="400"
|
||||||
@mousedown="startDrag"
|
@mousedown="startDrag"
|
||||||
@mousemove="onDrag"
|
|
||||||
@mouseup="stopDrag"
|
|
||||||
@mouseleave="stopDrag"
|
|
||||||
@touchstart.prevent="startDrag"
|
@touchstart.prevent="startDrag"
|
||||||
@touchmove.prevent="onDrag"
|
@touchmove.prevent="onDrag"
|
||||||
@touchend="stopDrag"
|
@touchend="stopDrag"
|
||||||
@@ -371,6 +378,8 @@ const confirm = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canvas {
|
canvas {
|
||||||
|
width: 400px;
|
||||||
|
height: 400px;
|
||||||
border: 2px solid var(--panel-border);
|
border: 2px solid var(--panel-border);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
box-shadow: 0 0 20px rgba(0, 242, 255, 0.1);
|
box-shadow: 0 0 20px rgba(0, 242, 255, 0.1);
|
||||||
@@ -378,6 +387,14 @@ canvas {
|
|||||||
background: #000;
|
background: #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
canvas {
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
aspect-ratio: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
color: var(--accent-cyan);
|
color: var(--accent-cyan);
|
||||||
|
|||||||
Reference in New Issue
Block a user