game-village-politics-frontend/app/components/map/FieldPopup.vue

64 lines
3.0 KiB
Vue
Raw Permalink Normal View History

<script setup lang="ts">
import type { MapMovement, MapVillage } from '~/types/map'
const props = defineProps<{
village: MapVillage
/** The player's village the bar shows, for distance and sending troops. */
from: { id: number; x: number; y: number } | null
/** With actions (a click), or just the facts (hovering). */
actions?: boolean
/** Groups on the map, for those leaving or coming to the village (on a click). */
movements?: MapMovement[]
now?: number
}>()
const emit = defineEmits<{ center: []; close: []; march: [id: number] }>()
const distance = computed(() => (props.from ? Math.hypot(props.village.x - props.from.x, props.village.y - props.from.y) : null))
const own = computed(() => props.village.own)
</script>
<!-- A village on the map up close: who it belongs to, its points and distance; on a click, what to do with it. -->
<template>
<div class="w-60 rounded-sm border-2 border-wood-950 bg-parchment-50 text-sm text-ink-900 shadow-hard">
<div class="flex items-start gap-2 border-b border-wood-700 bg-parchment-200 px-3 py-1.5">
<div class="min-w-0 flex-1">
<p class="truncate font-semibold">{{ village.name }}</p>
<p class="text-xs text-ink-500 tabular-nums">{{ village.x }}|{{ village.y }} {{ village.continent }}</p>
</div>
<button v-if="actions" type="button" class="text-ink-500 hover:text-blood-700" :aria-label="$t('common.close')" @click="emit('close')">
<IconUi name="close" class="size-4" />
</button>
</div>
<dl class="grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 px-3 py-1.5 text-xs">
<dt class="text-ink-500">{{ $t('map.info.owner') }}</dt>
<dd class="truncate">{{ village.player?.name ?? $t('map.barbarian') }}</dd>
<dt class="text-ink-500">{{ $t('map.info.points') }}</dt>
<dd class="tabular-nums">{{ village.points }}</dd>
<template v-if="distance !== null && distance > 0">
<dt class="text-ink-500">{{ $t('village.rally.distance') }}</dt>
<dd class="tabular-nums">{{ $t('village.rally.fields', { fields: distance.toFixed(1) }) }}</dd>
</template>
</dl>
<MapMarchList
v-if="actions && movements && now"
class="border-t border-parchment-300 px-3 py-1.5 text-xs"
:village-id="village.id"
:movements="movements"
:now="now"
@march="emit('march', $event)"
/>
<div v-if="actions" class="flex flex-wrap gap-1.5 border-t border-parchment-300 px-3 py-2">
<NuxtLink
v-if="from && from.id !== village.id"
:to="{ path: `/village/${from.id}/rally`, query: { x: village.x, y: village.y } }"
class="btn btn-attack"
>
<IconUi name="attack" class="size-3.5" />
{{ $t('map.info.send') }}
</NuxtLink>
<NuxtLink v-if="own" :to="`/village/${village.id}`" class="btn btn-outline px-2 py-1 text-xs">{{ $t('map.info.open') }}</NuxtLink>
<button type="button" class="btn btn-outline px-2 py-1 text-xs" @click="emit('center')">{{ $t('map.info.center') }}</button>
</div>
</div>
</template>