85 lines
1.9 KiB
Vue
85 lines
1.9 KiB
Vue
<script setup lang="ts">
|
|
import type { Card } from '~/netcode/Card';
|
|
|
|
|
|
export interface Props {
|
|
data?: Card | null
|
|
locked?: boolean
|
|
}
|
|
|
|
const props = defineProps<Props>()
|
|
|
|
const emit = defineEmits(["click"])
|
|
|
|
const buttonsElement = ref<HTMLElement | null>(null)
|
|
const rightClicked = ref(false)
|
|
|
|
function cardClick() {
|
|
if (props.data == null) return
|
|
emit("click")
|
|
}
|
|
|
|
function contextmenu(e: MouseEvent) {
|
|
if (buttonsElement.value?.childElementCount === 0) { return }
|
|
buttonsElement.value?.setAttribute("style", `top:${e.clientY + 10}px;left:${e.clientX + 10}px`)
|
|
rightClicked.value = true
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div :class="`card ${Number(buttonsElement?.childElementCount) > 0 ? 'active' : ''}`" @contextmenu.prevent="false"
|
|
@click.left="cardClick" @click.right="contextmenu">
|
|
<img :class="`card_image ${rightClicked ? 'outlined' : ''} ${props.locked ? 'locked' : ''}`" v-if="props.data"
|
|
:src="'/cards/' + data?.card_id?.toString().padStart(3, '0') + '.png'">
|
|
|
|
<img :class="`card_image ${rightClicked ? 'outlined' : ''} ${props.locked ? 'locked' : ''}`" v-if="!props.data"
|
|
:src="'/cards/background.png'">
|
|
|
|
</div>
|
|
|
|
<div :class="rightClicked ? '' : 'hidden'" id="contextMenu" @click.self.prevent="rightClicked = false">
|
|
<div id="contextMenuButtons" ref="buttonsElement">
|
|
<slot></slot>
|
|
</div>
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<style scoped>
|
|
.card.active {
|
|
cursor: pointer
|
|
}
|
|
|
|
.card_image.outlined {
|
|
outline: 2px solid red;
|
|
outline-offset: -2px;
|
|
}
|
|
|
|
.card_image.locked {
|
|
filter: brightness(0.5);
|
|
}
|
|
|
|
.card_image {
|
|
max-height: 250px;
|
|
}
|
|
|
|
.hidden {
|
|
display: none;
|
|
}
|
|
|
|
#contextMenu {
|
|
position: fixed;
|
|
height: 100%;
|
|
width: 100%;
|
|
top: 0;
|
|
left: 0;
|
|
/* background: rgba(0, 0, 0, .5); */
|
|
}
|
|
|
|
#contextMenuButtons {
|
|
position: absolute;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
</style>
|