[FEAT] Multi select, flip, rotate, multi remove
This commit is contained in:
@@ -5,6 +5,18 @@
|
||||
<i class="fas fa-plus text-blue-600 dark:text-blue-400"></i>
|
||||
<span>Add Sprite</span>
|
||||
</button>
|
||||
<button v-if="contextMenuSpriteId" @click="rotateSpriteInMenu(90)" class="w-full px-5 py-3 text-left hover:bg-green-50 dark:hover:bg-green-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-3 transition-colors font-medium">
|
||||
<i class="fas fa-redo text-green-600 dark:text-green-400"></i>
|
||||
<span>Rotate +90°</span>
|
||||
</button>
|
||||
<button v-if="contextMenuSpriteId" @click="flipSpriteInMenu('horizontal')" class="w-full px-5 py-3 text-left hover:bg-orange-50 dark:hover:bg-orange-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-3 transition-colors font-medium">
|
||||
<i class="fas fa-arrows-alt-h text-orange-600 dark:text-orange-400"></i>
|
||||
<span>Flip Horizontal</span>
|
||||
</button>
|
||||
<button v-if="contextMenuSpriteId" @click="flipSpriteInMenu('vertical')" class="w-full px-5 py-3 text-left hover:bg-orange-50 dark:hover:bg-orange-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-3 transition-colors font-medium">
|
||||
<i class="fas fa-arrows-alt-v text-orange-600 dark:text-orange-400"></i>
|
||||
<span>Flip Vertical</span>
|
||||
</button>
|
||||
<button v-if="contextMenuSpriteId" @click="replaceSprite" class="w-full px-5 py-3 text-left hover:bg-purple-50 dark:hover:bg-purple-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-3 transition-colors font-medium">
|
||||
<i class="fas fa-exchange-alt text-purple-600 dark:text-purple-400"></i>
|
||||
<span>Replace Sprite</span>
|
||||
@@ -12,7 +24,7 @@
|
||||
<div v-if="contextMenuSpriteId" class="h-px bg-gray-200 dark:bg-gray-600 my-1"></div>
|
||||
<button v-if="contextMenuSpriteId" @click="removeSprite" class="w-full px-5 py-3 text-left hover:bg-red-50 dark:hover:bg-red-900/30 text-red-600 dark:text-red-400 flex items-center gap-3 transition-colors font-medium">
|
||||
<i class="fas fa-trash"></i>
|
||||
<span>Remove Sprite</span>
|
||||
<span>{{ selectedSpriteIds.size > 1 ? `Remove ${selectedSpriteIds.size} Sprites` : 'Remove Sprite' }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</Teleport>
|
||||
@@ -27,6 +39,15 @@
|
||||
<div class="flex flex-wrap items-center gap-1">
|
||||
<!-- Toggles Group -->
|
||||
<div class="flex items-center gap-1 p-1">
|
||||
<label class="flex items-center gap-2 px-3 py-2 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 cursor-pointer transition-colors" title="Toggle Multi-Select Mode">
|
||||
<input id="multi-select-mode" type="checkbox" v-model="isMultiSelectMode" class="w-4 h-4 rounded text-blue-600 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600" />
|
||||
<span class="text-sm font-medium text-gray-700 dark:text-gray-200">Multi-Select</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-2 px-3 py-2 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 cursor-pointer transition-colors" title="Show Selection Borders">
|
||||
<input id="show-active-border" type="checkbox" v-model="showActiveBorder" class="w-4 h-4 rounded text-blue-600 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600" />
|
||||
<span class="text-sm font-medium text-gray-700 dark:text-gray-200">Borders</span>
|
||||
</label>
|
||||
<div class="w-px h-4 bg-gray-200 dark:bg-gray-700 mx-1"></div>
|
||||
<label class="flex items-center gap-2 px-3 py-2 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 cursor-pointer transition-colors" title="Pixel Perfect">
|
||||
<input id="pixel-perfect" type="checkbox" v-model="settingsStore.pixelPerfect" class="w-4 h-4 rounded text-blue-600 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600" />
|
||||
<span class="text-sm font-medium text-gray-700 dark:text-gray-200">Pixel Perfect</span>
|
||||
@@ -181,7 +202,8 @@
|
||||
<img
|
||||
v-if="!(activeSpriteId === sprite.id && ghostSprite)"
|
||||
:src="sprite.url"
|
||||
class="absolute cursor-move"
|
||||
class="absolute cursor-move transition-transform duration-200"
|
||||
:class="{ 'ring-2 ring-blue-500 ring-offset-1 dark:ring-offset-gray-900': showActiveBorder && selectedSpriteIds.has(sprite.id) }"
|
||||
:style="{
|
||||
left: `${getCellPosition(index).x + gridMetrics.negativeSpacing + sprite.x}px`,
|
||||
top: `${getCellPosition(index).y + gridMetrics.negativeSpacing + sprite.y}px`,
|
||||
@@ -189,6 +211,7 @@
|
||||
height: `${sprite.height}px`,
|
||||
opacity: layer.id === activeLayerId ? '1' : '0.85',
|
||||
imageRendering: settingsStore.pixelPerfect ? 'pixelated' : 'auto',
|
||||
transform: `rotate(${sprite.rotation}deg) scale(${sprite.flipX ? -1 : 1}, ${sprite.flipY ? -1 : 1})`,
|
||||
}"
|
||||
:data-sprite-id="sprite.id"
|
||||
:data-layer-id="layer.id"
|
||||
@@ -210,6 +233,7 @@
|
||||
height: `${activeSpriteSprite?.height}px`,
|
||||
opacity: '0.6',
|
||||
imageRendering: settingsStore.pixelPerfect ? 'pixelated' : 'auto',
|
||||
transform: `rotate(${activeSpriteSprite?.rotation || 0}deg) scale(${activeSpriteSprite?.flipX ? -1 : 1}, ${activeSpriteSprite?.flipY ? -1 : 1})`,
|
||||
}"
|
||||
draggable="false"
|
||||
/>
|
||||
@@ -256,9 +280,12 @@
|
||||
(e: 'updateSprite', id: string, x: number, y: number): void;
|
||||
(e: 'updateSpriteCell', id: string, newIndex: number): void;
|
||||
(e: 'removeSprite', id: string): void;
|
||||
(e: 'removeSprites', ids: string[]): void;
|
||||
(e: 'replaceSprite', id: string, file: File): void;
|
||||
(e: 'addSprite', file: File): void;
|
||||
(e: 'addSpriteWithResize', file: File): void;
|
||||
(e: 'rotateSprite', id: string, angle: number): void;
|
||||
(e: 'flipSprite', id: string, direction: 'horizontal' | 'vertical'): void;
|
||||
}>();
|
||||
|
||||
// Get settings from store
|
||||
@@ -337,9 +364,17 @@
|
||||
const contextMenuX = ref(0);
|
||||
const contextMenuY = ref(0);
|
||||
const contextMenuSpriteId = ref<string | null>(null);
|
||||
const selectedSpriteIds = ref<Set<string>>(new Set());
|
||||
const replacingSpriteId = ref<string | null>(null);
|
||||
const fileInput = ref<HTMLInputElement | null>(null);
|
||||
const customColor = ref('#ffffff');
|
||||
const isMultiSelectMode = ref(false);
|
||||
const showActiveBorder = ref(true);
|
||||
|
||||
// Clear selection when toggling multi-select mode
|
||||
watch(isMultiSelectMode, () => {
|
||||
selectedSpriteIds.value.clear();
|
||||
});
|
||||
|
||||
// Grid metrics
|
||||
const gridMetrics = computed(() => calculateMaxDimensions());
|
||||
@@ -467,6 +502,18 @@
|
||||
const clickedSprite = findSpriteAtPosition(pos.x, pos.y);
|
||||
contextMenuSpriteId.value = clickedSprite?.id || null;
|
||||
|
||||
if (clickedSprite) {
|
||||
// If the right-clicked sprite is not in the selection, clear selection and select just this one
|
||||
if (!selectedSpriteIds.value.has(clickedSprite.id)) {
|
||||
selectedSpriteIds.value.clear();
|
||||
selectedSpriteIds.value.add(clickedSprite.id);
|
||||
}
|
||||
// If it IS in the selection, keep the current selection (so we can apply action to all)
|
||||
} else {
|
||||
// Right click on empty space
|
||||
selectedSpriteIds.value.clear();
|
||||
}
|
||||
|
||||
contextMenuX.value = event.clientX;
|
||||
contextMenuY.value = event.clientY;
|
||||
|
||||
@@ -477,6 +524,34 @@
|
||||
// Ignore non-left mouse buttons
|
||||
if ('button' in event && (event as MouseEvent).button !== 0) return;
|
||||
|
||||
// Handle selection logic for left click
|
||||
const pos = getMousePosition(event, zoom.value);
|
||||
if (pos) {
|
||||
const clickedSprite = findSpriteAtPosition(pos.x, pos.y);
|
||||
if (clickedSprite) {
|
||||
// Selection logic with multi-select mode check
|
||||
if (event.ctrlKey || event.metaKey || isMultiSelectMode.value) {
|
||||
// Toggle selection
|
||||
if (selectedSpriteIds.value.has(clickedSprite.id)) {
|
||||
selectedSpriteIds.value.delete(clickedSprite.id);
|
||||
} else {
|
||||
selectedSpriteIds.value.add(clickedSprite.id);
|
||||
}
|
||||
} else {
|
||||
// Single select (but don't clear if dragging starts immediately?
|
||||
// Usually standard behavior is to clear others unless shift/ctrl held)
|
||||
if (!selectedSpriteIds.value.has(clickedSprite.id)) {
|
||||
selectedSpriteIds.value.clear();
|
||||
selectedSpriteIds.value.add(clickedSprite.id);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Clicked on empty space
|
||||
selectedSpriteIds.value.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate to composable for actual drag handling
|
||||
dragStart(event);
|
||||
};
|
||||
@@ -500,13 +575,52 @@
|
||||
};
|
||||
|
||||
const removeSprite = () => {
|
||||
if (contextMenuSpriteId.value) {
|
||||
if (selectedSpriteIds.value.size > 0) {
|
||||
emit('removeSprites', Array.from(selectedSpriteIds.value));
|
||||
selectedSpriteIds.value.clear();
|
||||
showContextMenu.value = false;
|
||||
contextMenuSpriteId.value = null;
|
||||
} else if (contextMenuSpriteId.value) {
|
||||
emit('removeSprite', contextMenuSpriteId.value);
|
||||
showContextMenu.value = false;
|
||||
contextMenuSpriteId.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
const rotateSpriteInMenu = (angle: number) => {
|
||||
if (selectedSpriteIds.value.size > 0) {
|
||||
selectedSpriteIds.value.forEach(id => {
|
||||
emit('rotateSprite', id, angle);
|
||||
});
|
||||
} else if (contextMenuSpriteId.value) {
|
||||
emit('rotateSprite', contextMenuSpriteId.value, angle);
|
||||
}
|
||||
showContextMenu.value = false;
|
||||
};
|
||||
|
||||
const flipSpriteInMenu = (direction: 'horizontal' | 'vertical') => {
|
||||
if (selectedSpriteIds.value.size > 0) {
|
||||
selectedSpriteIds.value.forEach(id => {
|
||||
emit('flipSprite', id, direction);
|
||||
});
|
||||
} else if (contextMenuSpriteId.value) {
|
||||
emit('flipSprite', contextMenuSpriteId.value, direction);
|
||||
}
|
||||
showContextMenu.value = false;
|
||||
};
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Delete' || event.key === 'Backspace') {
|
||||
// Don't delete if editing text/input
|
||||
if (document.activeElement?.tagName === 'INPUT' || document.activeElement?.tagName === 'TEXTAREA') return;
|
||||
|
||||
if (selectedSpriteIds.value.size > 0) {
|
||||
emit('removeSprites', Array.from(selectedSpriteIds.value));
|
||||
selectedSpriteIds.value.clear();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const replaceSprite = () => {
|
||||
if (contextMenuSpriteId.value && fileInput.value) {
|
||||
replacingSpriteId.value = contextMenuSpriteId.value;
|
||||
@@ -554,10 +668,12 @@
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('mouseup', stopDrag);
|
||||
document.addEventListener('keydown', handleKeyDown);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('mouseup', stopDrag);
|
||||
document.removeEventListener('keydown', handleKeyDown);
|
||||
});
|
||||
|
||||
// Watch for background color changes
|
||||
|
||||
Reference in New Issue
Block a user