feat: every box folds and drags: overview and map boxes reorder in their column or float anywhere, windows drag by the title bar
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
59b551c246
commit
4063939bec
|
|
@ -11,11 +11,7 @@ const { current } = useCurrentWorld()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<section class="panel">
|
<div class="panel-body text-sm">
|
||||||
<div class="panel-head">
|
|
||||||
<h2 class="panel-title">{{ $t('map.info.title') }}</h2>
|
|
||||||
</div>
|
|
||||||
<div class="panel-body text-sm">
|
|
||||||
<template v-if="village">
|
<template v-if="village">
|
||||||
<p class="font-display text-lg font-semibold">{{ village.name }}</p>
|
<p class="font-display text-lg font-semibold">{{ village.name }}</p>
|
||||||
<dl class="mt-3 grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5">
|
<dl class="mt-3 grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5">
|
||||||
|
|
@ -46,6 +42,5 @@ const { current } = useCurrentWorld()
|
||||||
<p class="mt-1 font-semibold tabular-nums">{{ at.x }}|{{ at.y }} <span class="text-ink-500">{{ continentOf(at.x, at.y) }}</span></p>
|
<p class="mt-1 font-semibold tabular-nums">{{ at.x }}|{{ at.y }} <span class="text-ink-500">{{ continentOf(at.x, at.y) }}</span></p>
|
||||||
</template>
|
</template>
|
||||||
<p v-else class="text-ink-500">{{ $t('map.info.hint') }}</p>
|
<p v-else class="text-ink-500">{{ $t('map.info.hint') }}</p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,189 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { ComponentPublicInstance } from 'vue'
|
||||||
|
|
||||||
|
export interface DockItem {
|
||||||
|
key: string
|
||||||
|
title: string
|
||||||
|
alarm?: boolean
|
||||||
|
/** false hides the box for now (no incoming attacks); it keeps its place. */
|
||||||
|
show?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<{ scope: string; cards: DockItem[] }>()
|
||||||
|
const { layout, ordered, toggle, dock, float } = useCardLayout(props.scope)
|
||||||
|
|
||||||
|
// Dragging only on wide screens; phones keep the boxes in their sheet, still foldable.
|
||||||
|
const wide = ref(false)
|
||||||
|
const viewport = ref({ w: 1600, h: 900 })
|
||||||
|
function measure() {
|
||||||
|
viewport.value = { w: window.innerWidth, h: window.innerHeight }
|
||||||
|
}
|
||||||
|
let mq: MediaQueryList | undefined
|
||||||
|
const onMq = (e: MediaQueryListEvent) => (wide.value = e.matches)
|
||||||
|
onMounted(() => {
|
||||||
|
mq = window.matchMedia('(min-width: 1024px)')
|
||||||
|
wide.value = mq.matches
|
||||||
|
mq.addEventListener('change', onMq)
|
||||||
|
measure()
|
||||||
|
window.addEventListener('resize', measure)
|
||||||
|
})
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
mq?.removeEventListener('change', onMq)
|
||||||
|
window.removeEventListener('resize', measure)
|
||||||
|
window.removeEventListener('pointermove', onMove)
|
||||||
|
})
|
||||||
|
|
||||||
|
const defaults = computed(() => props.cards.map((c) => c.key))
|
||||||
|
const byKey = computed(() => new Map(props.cards.map((c) => [c.key, c])))
|
||||||
|
const shown = (k: string) => byKey.value.get(k)?.show !== false
|
||||||
|
const floats = (k: string) => wide.value && !!layout.value.floating[k]
|
||||||
|
|
||||||
|
interface Drag {
|
||||||
|
key: string
|
||||||
|
x: number
|
||||||
|
y: number
|
||||||
|
w: number
|
||||||
|
/** Over the dock: dropped before this box (null: at the end). */
|
||||||
|
over: boolean
|
||||||
|
before: string | null
|
||||||
|
}
|
||||||
|
const drag = ref<Drag | null>(null)
|
||||||
|
let pending: { key: string; startX: number; startY: number; dx: number; dy: number; w: number } | null = null
|
||||||
|
|
||||||
|
const docked = computed(() => ordered(defaults.value).filter((k) => shown(k) && !floats(k) && drag.value?.key !== k))
|
||||||
|
const floating = computed(() => ordered(defaults.value).filter((k) => shown(k) && floats(k) && drag.value?.key !== k))
|
||||||
|
|
||||||
|
const column = ref<HTMLElement | null>(null)
|
||||||
|
const els = new Map<string, HTMLElement>()
|
||||||
|
function setEl(key: string, c: Element | ComponentPublicInstance | null) {
|
||||||
|
const el = c && '$el' in c ? (c.$el as HTMLElement) : (c as HTMLElement | null)
|
||||||
|
if (el) els.set(key, el)
|
||||||
|
else els.delete(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Header pressed: a click folds the box, a drag moves it. */
|
||||||
|
function grab(key: string, e: PointerEvent) {
|
||||||
|
if (e.button !== 0) return
|
||||||
|
const card = (e.currentTarget as HTMLElement).closest('section')
|
||||||
|
if (!card) return
|
||||||
|
const r = card.getBoundingClientRect()
|
||||||
|
pending = { key, startX: e.clientX, startY: e.clientY, dx: e.clientX - r.left, dy: e.clientY - r.top, w: r.width }
|
||||||
|
window.addEventListener('pointermove', onMove)
|
||||||
|
window.addEventListener('pointerup', onUp, { once: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMove(e: PointerEvent) {
|
||||||
|
const p = pending
|
||||||
|
if (!p || !wide.value) return
|
||||||
|
if (!drag.value && Math.hypot(e.clientX - p.startX, e.clientY - p.startY) < 5) return
|
||||||
|
e.preventDefault()
|
||||||
|
const box = column.value?.getBoundingClientRect()
|
||||||
|
const over = !!box && e.clientX >= box.left - 24 && e.clientX <= box.right + 24 && e.clientY >= box.top - 24 && e.clientY <= box.bottom + 48
|
||||||
|
drag.value = { key: p.key, x: e.clientX - p.dx, y: e.clientY - p.dy, w: p.w, over, before: over ? beforeKey(e.clientY) : null }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The docked box the pointer is above the middle of. */
|
||||||
|
function beforeKey(y: number): string | null {
|
||||||
|
for (const k of docked.value) {
|
||||||
|
const r = els.get(k)?.getBoundingClientRect()
|
||||||
|
if (r && y < r.top + r.height / 2) return k
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const clamp = (x: number, y: number) => ({
|
||||||
|
x: Math.max(0, Math.min(viewport.value.w - 120, x)),
|
||||||
|
y: Math.max(0, Math.min(viewport.value.h - 40, y)),
|
||||||
|
})
|
||||||
|
|
||||||
|
function onUp() {
|
||||||
|
window.removeEventListener('pointermove', onMove)
|
||||||
|
const p = pending
|
||||||
|
const d = drag.value
|
||||||
|
pending = null
|
||||||
|
drag.value = null
|
||||||
|
if (!p) return
|
||||||
|
if (!d) return toggle(p.key)
|
||||||
|
if (d.over) dock(p.key, d.before, defaults.value)
|
||||||
|
else {
|
||||||
|
const at = clamp(d.x, d.y)
|
||||||
|
float(p.key, at.x, at.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const placed = (k: string) => {
|
||||||
|
const at = clamp(layout.value.floating[k]!.x, layout.value.floating[k]!.y)
|
||||||
|
return { left: `${at.x}px`, top: `${at.y}px` }
|
||||||
|
}
|
||||||
|
const title = (k: string) => byKey.value.get(k)?.title ?? k
|
||||||
|
const alarm = (k: string) => !!byKey.value.get(k)?.alarm
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
A column of boxes the player arranges: each folds by its header, drags to another place
|
||||||
|
in the column, or out to float anywhere over the stage and back. The layout is kept per
|
||||||
|
browser (useCardLayout); content comes in a slot named after each box's key.
|
||||||
|
-->
|
||||||
|
<template>
|
||||||
|
<div ref="column" class="space-y-2" :class="drag ? 'min-h-24' : ''">
|
||||||
|
<template v-for="k in docked" :key="k">
|
||||||
|
<div v-if="drag?.over && drag.before === k" class="dock-gap" />
|
||||||
|
<UiDockCard
|
||||||
|
:ref="(c) => setEl(k, c as ComponentPublicInstance | null)"
|
||||||
|
:title="title(k)"
|
||||||
|
:alarm="alarm(k)"
|
||||||
|
:collapsed="!!layout.collapsed[k]"
|
||||||
|
:draggable="wide"
|
||||||
|
@grab="grab(k, $event)"
|
||||||
|
@toggle="toggle(k)"
|
||||||
|
>
|
||||||
|
<template #extra><slot :name="`${k}-extra`" /></template>
|
||||||
|
<slot :name="k" />
|
||||||
|
</UiDockCard>
|
||||||
|
</template>
|
||||||
|
<div v-if="drag?.over && drag.before === null" class="dock-gap" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Teleport to="body">
|
||||||
|
<div v-if="floating.length || drag" class="pointer-events-none fixed inset-0 z-30 text-sm">
|
||||||
|
<UiDockCard
|
||||||
|
v-for="k in floating"
|
||||||
|
:key="k"
|
||||||
|
class="float pointer-events-auto absolute w-[16.5rem]"
|
||||||
|
:style="placed(k)"
|
||||||
|
:title="title(k)"
|
||||||
|
:alarm="alarm(k)"
|
||||||
|
:collapsed="!!layout.collapsed[k]"
|
||||||
|
floating
|
||||||
|
draggable
|
||||||
|
@grab="grab(k, $event)"
|
||||||
|
@toggle="toggle(k)"
|
||||||
|
@dock="dock(k, null, defaults)"
|
||||||
|
>
|
||||||
|
<template #extra><slot :name="`${k}-extra`" /></template>
|
||||||
|
<slot :name="k" />
|
||||||
|
</UiDockCard>
|
||||||
|
<UiDockCard
|
||||||
|
v-if="drag"
|
||||||
|
class="float absolute cursor-grabbing"
|
||||||
|
:style="{ left: `${drag.x}px`, top: `${drag.y}px`, width: `${drag.w}px` }"
|
||||||
|
:title="title(drag.key)"
|
||||||
|
:alarm="alarm(drag.key)"
|
||||||
|
:collapsed="!!layout.collapsed[drag.key]"
|
||||||
|
draggable
|
||||||
|
>
|
||||||
|
<template #extra><slot :name="`${drag.key}-extra`" /></template>
|
||||||
|
<slot :name="drag.key" />
|
||||||
|
</UiDockCard>
|
||||||
|
</div>
|
||||||
|
</Teleport>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
@reference "~/assets/css/main.css";
|
||||||
|
|
||||||
|
/* Where the box lands: a dashed slot in the column. */
|
||||||
|
.dock-gap {
|
||||||
|
@apply h-10 border-2 border-dashed border-wood-700 bg-parchment-200;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
title: string
|
||||||
|
collapsed?: boolean
|
||||||
|
/** Incoming attacks: the band in oxblood. */
|
||||||
|
alarm?: boolean
|
||||||
|
/** Floats over the village: offers a way back into the dock. */
|
||||||
|
floating?: boolean
|
||||||
|
/** Can be dragged (wide screens). */
|
||||||
|
draggable?: boolean
|
||||||
|
}>()
|
||||||
|
const emit = defineEmits<{ grab: [e: PointerEvent]; toggle: []; dock: [] }>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
One box of a dock: its header folds it with a click and drags it with the pointer (to
|
||||||
|
another place in the dock, or out to float anywhere); a floating box has a way back.
|
||||||
|
-->
|
||||||
|
<template>
|
||||||
|
<section class="dock-card" :class="alarm ? 'border-blood-700' : 'border-wood-700'">
|
||||||
|
<header
|
||||||
|
class="panel-head panel-title flex select-none items-center gap-1 py-0.5"
|
||||||
|
:class="[alarm ? 'dock-alarm' : '', draggable ? 'cursor-grab active:cursor-grabbing' : 'cursor-pointer']"
|
||||||
|
@pointerdown="emit('grab', $event)"
|
||||||
|
>
|
||||||
|
<span class="min-w-0 flex-1 truncate">{{ title }}</span>
|
||||||
|
<slot name="extra" />
|
||||||
|
<button
|
||||||
|
v-if="floating"
|
||||||
|
type="button"
|
||||||
|
class="btn btn-ghost px-1 normal-case"
|
||||||
|
:class="alarm ? 'text-parchment-50' : ''"
|
||||||
|
:title="$t('window.dock')"
|
||||||
|
@pointerdown.stop
|
||||||
|
@click.stop="emit('dock')"
|
||||||
|
>
|
||||||
|
<IconUi name="return" class="size-3.5" />
|
||||||
|
<span class="sr-only">{{ $t('window.dock') }}</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-ghost px-1"
|
||||||
|
:class="alarm ? 'text-parchment-50' : ''"
|
||||||
|
:title="$t(collapsed ? 'window.unfold' : 'window.fold')"
|
||||||
|
:aria-expanded="!collapsed"
|
||||||
|
@pointerdown.stop
|
||||||
|
@click.stop="emit('toggle')"
|
||||||
|
>
|
||||||
|
<IconUi :name="collapsed ? 'plus' : 'minus'" class="size-3.5" />
|
||||||
|
<span class="sr-only">{{ $t(collapsed ? 'window.unfold' : 'window.fold') }}</span>
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
<div v-show="!collapsed">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
@reference "~/assets/css/main.css";
|
||||||
|
|
||||||
|
.dock-card {
|
||||||
|
@apply border bg-parchment-50;
|
||||||
|
background-image: var(--pat-parchment-50);
|
||||||
|
}
|
||||||
|
/* Incoming attacks: the band in oxblood, no cloth texture. */
|
||||||
|
.dock-alarm {
|
||||||
|
@apply border-blood-800 bg-blood-700 text-parchment-50;
|
||||||
|
background-image: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
@ -11,16 +11,64 @@ defineProps<{
|
||||||
const emit = defineEmits<{ close: [] }>()
|
const emit = defineEmits<{ close: [] }>()
|
||||||
/** Folded to its title bar, so the village behind shows. */
|
/** Folded to its title bar, so the village behind shows. */
|
||||||
const folded = defineModel<boolean>('folded', { default: false })
|
const folded = defineModel<boolean>('folded', { default: false })
|
||||||
|
|
||||||
|
// Its parent docks it; the player can drag it away by the title bar on wide screens, and
|
||||||
|
// a double-click there puts it back. One offset for every window, kept per browser.
|
||||||
|
const offset = useWindowOffset()
|
||||||
|
const root = ref<HTMLElement | null>(null)
|
||||||
|
const wide = ref(false)
|
||||||
|
let mq: MediaQueryList | undefined
|
||||||
|
const onMq = (e: MediaQueryListEvent) => (wide.value = e.matches)
|
||||||
|
onMounted(() => {
|
||||||
|
mq = window.matchMedia('(min-width: 1024px)')
|
||||||
|
wide.value = mq.matches
|
||||||
|
mq.addEventListener('change', onMq)
|
||||||
|
})
|
||||||
|
|
||||||
|
let start: { x: number; y: number; ox: number; oy: number; left: number; top: number; w: number } | null = null
|
||||||
|
function grab(e: PointerEvent) {
|
||||||
|
if (!wide.value || e.button !== 0 || (e.target as HTMLElement).closest('button, a')) return
|
||||||
|
const r = root.value?.getBoundingClientRect()
|
||||||
|
if (!r) return
|
||||||
|
// Where its frame docks it, without the offset.
|
||||||
|
start = { x: e.clientX, y: e.clientY, ox: offset.value.x, oy: offset.value.y, left: r.left - offset.value.x, top: r.top - offset.value.y, w: r.width }
|
||||||
|
window.addEventListener('pointermove', move)
|
||||||
|
window.addEventListener('pointerup', drop, { once: true })
|
||||||
|
}
|
||||||
|
function move(e: PointerEvent) {
|
||||||
|
const s = start
|
||||||
|
if (!s) return
|
||||||
|
e.preventDefault()
|
||||||
|
// Keep the title bar on screen.
|
||||||
|
const x = Math.max(-s.left - s.w + 120, Math.min(window.innerWidth - s.left - 120, s.ox + e.clientX - s.x))
|
||||||
|
const y = Math.max(-s.top, Math.min(window.innerHeight - s.top - 40, s.oy + e.clientY - s.y))
|
||||||
|
offset.value = { x: Math.round(x), y: Math.round(y) }
|
||||||
|
}
|
||||||
|
function drop() {
|
||||||
|
start = null
|
||||||
|
window.removeEventListener('pointermove', move)
|
||||||
|
}
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
mq?.removeEventListener('change', onMq)
|
||||||
|
drop()
|
||||||
|
})
|
||||||
|
const style = computed(() => (wide.value && (offset.value.x || offset.value.y) ? { transform: `translate(${offset.value.x}px, ${offset.value.y}px)` } : undefined))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
A window over the fullscreen village, docked to an edge by its parent: a title bar
|
A window over the fullscreen village, docked to an edge by its parent: a title bar
|
||||||
with fold and close, and its content scrolling inside. Solid like every other frame.
|
with fold and close that also drags it, and its content scrolling inside. Solid like
|
||||||
Kept free of position logic so it can become draggable later.
|
every other frame.
|
||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
<section class="pointer-events-auto flex max-h-full min-h-0 flex-col float border border-wood-900 bg-parchment-100">
|
<section ref="root" class="pointer-events-auto flex max-h-full min-h-0 flex-col float border border-wood-900 bg-parchment-100" :style="style">
|
||||||
<header class="panel-head shrink-0 flex-nowrap gap-1 py-0.5">
|
<header
|
||||||
|
class="panel-head shrink-0 flex-nowrap gap-1 py-0.5 select-none"
|
||||||
|
:class="wide ? 'cursor-grab active:cursor-grabbing' : ''"
|
||||||
|
:title="wide ? $t('window.reset') : undefined"
|
||||||
|
@pointerdown="grab"
|
||||||
|
@dblclick="offset = { x: 0, y: 0 }"
|
||||||
|
>
|
||||||
<span class="panel-title min-w-0 flex-1 truncate">{{ title }}</span>
|
<span class="panel-title min-w-0 flex-1 truncate">{{ title }}</span>
|
||||||
<button type="button" class="btn btn-ghost px-1" :title="$t(folded ? 'window.unfold' : 'window.fold')" :aria-expanded="!folded" @click="folded = !folded">
|
<button type="button" class="btn btn-ghost px-1" :title="$t(folded ? 'window.unfold' : 'window.fold')" :aria-expanded="!folded" @click="folded = !folded">
|
||||||
<IconUi :name="folded ? 'plus' : 'minus'" class="size-3.5" />
|
<IconUi :name="folded ? 'plus' : 'minus'" class="size-3.5" />
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import type { DockItem } from '~/components/ui/Dock.vue'
|
||||||
import type { BuildOrder, UnitType, VillageRole, VillageState } from '~/types/game'
|
import type { BuildOrder, UnitType, VillageRole, VillageState } from '~/types/game'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
|
|
@ -19,6 +20,16 @@ const spec = computed(() => props.village.specialisation)
|
||||||
const season = computed(() => props.village.season)
|
const season = computed(() => props.village.season)
|
||||||
const roleSpace = computed(() => spec.value.roles.reduce((sum, r) => sum + (spec.value.space[r.role] ?? 0), 0))
|
const roleSpace = computed(() => spec.value.roles.reduce((sum, r) => sum + (spec.value.space[r.role] ?? 0), 0))
|
||||||
const roleShare = (role: VillageRole) => (roleSpace.value ? Math.round((100 * (spec.value.space[role] ?? 0)) / roleSpace.value) : 0)
|
const roleShare = (role: VillageRole) => (roleSpace.value ? Math.round((100 * (spec.value.space[role] ?? 0)) / roleSpace.value) : 0)
|
||||||
|
// Every box folds and moves (UiDock); the incoming attacks only while there are any.
|
||||||
|
const cards = computed<DockItem[]>(() => [
|
||||||
|
{ key: 'incoming', title: t('village.side.incoming'), alarm: true, show: incoming.value.length > 0 },
|
||||||
|
{ key: 'production', title: t('village.side.production') },
|
||||||
|
{ key: 'units', title: t('village.side.units') },
|
||||||
|
{ key: 'population', title: t('village.population.title') },
|
||||||
|
{ key: 'season', title: t('village.season.title') },
|
||||||
|
{ key: 'role', title: t('village.role.title') },
|
||||||
|
{ key: 'construction', title: t('village.side.construction') },
|
||||||
|
])
|
||||||
const bonuses = computed(() => Object.entries(spec.value.roles.find((r) => r.role === spec.value.role)?.bonuses ?? {}))
|
const bonuses = computed(() => Object.entries(spec.value.roles.find((r) => r.role === spec.value.role)?.bonuses ?? {}))
|
||||||
|
|
||||||
function order(o: BuildOrder) {
|
function order(o: BuildOrder) {
|
||||||
|
|
@ -30,9 +41,9 @@ function order(o: BuildOrder) {
|
||||||
|
|
||||||
<!-- The column beside the village: small boxes with the numbers that matter at a glance. -->
|
<!-- The column beside the village: small boxes with the numbers that matter at a glance. -->
|
||||||
<template>
|
<template>
|
||||||
<aside class="space-y-2 p-2 text-sm">
|
<aside class="p-2 text-sm">
|
||||||
<section v-if="incoming.length" class="side-box border-blood-700">
|
<UiDock scope="overview" :cards="cards">
|
||||||
<h2 class="panel-head panel-title side-alarm">{{ $t('village.side.incoming') }}</h2>
|
<template #incoming>
|
||||||
<ul class="side-body">
|
<ul class="side-body">
|
||||||
<li v-for="m in incoming" :key="m.id" class="flex items-center gap-2 text-blood-700">
|
<li v-for="m in incoming" :key="m.id" class="flex items-center gap-2 text-blood-700">
|
||||||
<IconUi name="attack" class="size-4" />
|
<IconUi name="attack" class="size-4" />
|
||||||
|
|
@ -40,10 +51,9 @@ function order(o: BuildOrder) {
|
||||||
<span class="font-semibold tabular-nums">{{ formatDuration(secondsUntil(m.arrives_at)) }}</span>
|
<span class="font-semibold tabular-nums">{{ formatDuration(secondsUntil(m.arrives_at)) }}</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</template>
|
||||||
|
|
||||||
<section class="side-box">
|
<template #production>
|
||||||
<h2 class="panel-head panel-title">{{ $t('village.side.production') }}</h2>
|
|
||||||
<ul class="side-body">
|
<ul class="side-body">
|
||||||
<li v-for="{ r, rate } in production" :key="r" class="flex items-center gap-2">
|
<li v-for="{ r, rate } in production" :key="r" class="flex items-center gap-2">
|
||||||
<IconResource :resource="r" class="size-4" />
|
<IconResource :resource="r" class="size-4" />
|
||||||
|
|
@ -53,10 +63,9 @@ function order(o: BuildOrder) {
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</template>
|
||||||
|
|
||||||
<section class="side-box">
|
<template #units>
|
||||||
<h2 class="panel-head panel-title">{{ $t('village.side.units') }}</h2>
|
|
||||||
<div class="side-body">
|
<div class="side-body">
|
||||||
<ul v-if="troops.length || village.levy.militia">
|
<ul v-if="troops.length || village.levy.militia">
|
||||||
<li v-for="[unit, count] in troops" :key="unit" class="flex items-center gap-2">
|
<li v-for="[unit, count] in troops" :key="unit" class="flex items-center gap-2">
|
||||||
|
|
@ -78,10 +87,9 @@ function order(o: BuildOrder) {
|
||||||
<NuxtLink :to="`${base}/rally`" class="btn btn-outline">{{ $t('village.side.rally') }}</NuxtLink>
|
<NuxtLink :to="`${base}/rally`" class="btn btn-outline">{{ $t('village.side.rally') }}</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</template>
|
||||||
|
|
||||||
<section class="side-box">
|
<template #population>
|
||||||
<h2 class="panel-head panel-title">{{ $t('village.population.title') }}</h2>
|
|
||||||
<dl class="grid grid-cols-[1fr_auto] gap-x-2 gap-y-1 px-2.5 py-1.5">
|
<dl class="grid grid-cols-[1fr_auto] gap-x-2 gap-y-1 px-2.5 py-1.5">
|
||||||
<dt>{{ $t('village.population.villagers') }}</dt>
|
<dt>{{ $t('village.population.villagers') }}</dt>
|
||||||
<dd class="text-right font-semibold tabular-nums">{{ village.population.villagers }}</dd>
|
<dd class="text-right font-semibold tabular-nums">{{ village.population.villagers }}</dd>
|
||||||
|
|
@ -92,10 +100,9 @@ function order(o: BuildOrder) {
|
||||||
<dt>{{ $t('village.population.upkeep') }}</dt>
|
<dt>{{ $t('village.population.upkeep') }}</dt>
|
||||||
<dd class="text-right tabular-nums">{{ village.population.upkeep }}/{{ village.population.food_budget }}</dd>
|
<dd class="text-right tabular-nums">{{ village.population.upkeep }}/{{ village.population.food_budget }}</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</section>
|
</template>
|
||||||
|
|
||||||
<section class="side-box">
|
<template #season>
|
||||||
<h2 class="panel-head panel-title">{{ $t('village.season.title') }}</h2>
|
|
||||||
<div class="side-body">
|
<div class="side-body">
|
||||||
<template v-if="season.winner">
|
<template v-if="season.winner">
|
||||||
<p class="font-semibold">{{ $t('village.season.won', { player: season.winner.name }) }}</p>
|
<p class="font-semibold">{{ $t('village.season.won', { player: season.winner.name }) }}</p>
|
||||||
|
|
@ -120,10 +127,9 @@ function order(o: BuildOrder) {
|
||||||
{{ $t('village.season.rule', { needed: season.needed, count: season.count, time: formatSpan(season.hold_seconds, t) }) }}
|
{{ $t('village.season.rule', { needed: season.needed, count: season.count, time: formatSpan(season.hold_seconds, t) }) }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</template>
|
||||||
|
|
||||||
<section class="side-box">
|
<template #role>
|
||||||
<h2 class="panel-head panel-title">{{ $t('village.role.title') }}</h2>
|
|
||||||
<div class="side-body">
|
<div class="side-body">
|
||||||
<p class="font-semibold">{{ spec.role ? $t(`village.role.${spec.role}`) : $t('village.role.none') }}</p>
|
<p class="font-semibold">{{ spec.role ? $t(`village.role.${spec.role}`) : $t('village.role.none') }}</p>
|
||||||
<ul v-if="spec.role" class="text-moss-700">
|
<ul v-if="spec.role" class="text-moss-700">
|
||||||
|
|
@ -137,10 +143,9 @@ function order(o: BuildOrder) {
|
||||||
</ul>
|
</ul>
|
||||||
<p v-if="!spec.role" class="text-xs text-ink-500">{{ $t('village.role.hint', { min: spec.min_space, share: Math.round(spec.share * 100) }) }}</p>
|
<p v-if="!spec.role" class="text-xs text-ink-500">{{ $t('village.role.hint', { min: spec.min_space, share: Math.round(spec.share * 100) }) }}</p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</template>
|
||||||
|
|
||||||
<section class="side-box">
|
<template #construction>
|
||||||
<h2 class="panel-head panel-title">{{ $t('village.side.construction') }}</h2>
|
|
||||||
<div class="side-body">
|
<div class="side-body">
|
||||||
<ol v-if="village.queue.length">
|
<ol v-if="village.queue.length">
|
||||||
<li v-for="o in village.queue" :key="o.id" class="flex items-center gap-2">
|
<li v-for="o in village.queue" :key="o.id" class="flex items-center gap-2">
|
||||||
|
|
@ -163,23 +168,14 @@ function order(o: BuildOrder) {
|
||||||
<NuxtLink :to="`${base}/build`" class="btn btn-outline">{{ $t('village.screens.build') }}</NuxtLink>
|
<NuxtLink :to="`${base}/build`" class="btn btn-outline">{{ $t('village.screens.build') }}</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</template>
|
||||||
|
</UiDock>
|
||||||
</aside>
|
</aside>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@reference "~/assets/css/main.css";
|
@reference "~/assets/css/main.css";
|
||||||
|
|
||||||
/* The same panel as everywhere; the column around them is the frame. */
|
|
||||||
.side-box {
|
|
||||||
@apply border border-wood-700 bg-parchment-50;
|
|
||||||
background-image: var(--pat-parchment-50);
|
|
||||||
}
|
|
||||||
/* Incoming attacks: the band in oxblood, no cloth texture. */
|
|
||||||
.side-alarm {
|
|
||||||
@apply border-blood-800 bg-blood-700 text-parchment-50;
|
|
||||||
background-image: none;
|
|
||||||
}
|
|
||||||
.side-body {
|
.side-body {
|
||||||
@apply space-y-0.5 px-1.5 py-1;
|
@apply space-y-0.5 px-1.5 py-1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
/** Where the player put the boxes of one dock: their order, which are folded, which float and where. */
|
||||||
|
export interface CardLayout {
|
||||||
|
order: string[]
|
||||||
|
collapsed: Record<string, boolean>
|
||||||
|
/** Viewport pixels of a floating box's top-left corner. */
|
||||||
|
floating: Record<string, { x: number; y: number }>
|
||||||
|
}
|
||||||
|
|
||||||
|
const empty = (): CardLayout => ({ order: [], collapsed: {}, floating: {} })
|
||||||
|
|
||||||
|
function load(key: string): CardLayout {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem(key)
|
||||||
|
return raw ? { ...empty(), ...JSON.parse(raw) } : empty()
|
||||||
|
} catch {
|
||||||
|
return empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The layout of one dock (`overview`, `map`), kept in this browser only: it is a
|
||||||
|
* per-viewer convenience, so the page works the same without storage.
|
||||||
|
*/
|
||||||
|
export function useCardLayout(scope: string) {
|
||||||
|
const key = `vp.layout.${scope}`
|
||||||
|
const layout = useState<CardLayout>(key, () => (import.meta.client ? load(key) : empty()))
|
||||||
|
watch(
|
||||||
|
layout,
|
||||||
|
(value) => {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(key, JSON.stringify(value))
|
||||||
|
} catch {
|
||||||
|
// Storage off: the layout lasts until the page reloads.
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ deep: true },
|
||||||
|
)
|
||||||
|
|
||||||
|
/** Every key in the player's order; keys the player never moved keep their default place. */
|
||||||
|
function ordered(defaults: string[]): string[] {
|
||||||
|
const known = layout.value.order.filter((k) => defaults.includes(k))
|
||||||
|
for (const [i, k] of defaults.entries()) {
|
||||||
|
if (known.includes(k)) continue
|
||||||
|
// A new box goes after the default one before it.
|
||||||
|
const before = defaults.slice(0, i).reverse().find((d) => known.includes(d))
|
||||||
|
known.splice(before ? known.indexOf(before) + 1 : 0, 0, k)
|
||||||
|
}
|
||||||
|
return known
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggle(card: string) {
|
||||||
|
layout.value.collapsed = { ...layout.value.collapsed, [card]: !layout.value.collapsed[card] }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Put a box back into the dock at a place among the docked ones. */
|
||||||
|
function dock(card: string, before: string | null, defaults: string[]) {
|
||||||
|
const order = ordered(defaults).filter((k) => k !== card)
|
||||||
|
const at = before ? order.indexOf(before) : -1
|
||||||
|
order.splice(at < 0 ? order.length : at, 0, card)
|
||||||
|
const { [card]: _, ...floating } = layout.value.floating
|
||||||
|
layout.value = { ...layout.value, order, floating }
|
||||||
|
}
|
||||||
|
|
||||||
|
function float(card: string, x: number, y: number) {
|
||||||
|
layout.value.floating = { ...layout.value.floating, [card]: { x: Math.round(x), y: Math.round(y) } }
|
||||||
|
}
|
||||||
|
|
||||||
|
return { layout, ordered, toggle, dock, float }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A window's offset from where its frame docks it, kept per browser; one place for every window. */
|
||||||
|
export function useWindowOffset(name = 'main') {
|
||||||
|
const key = `vp.window.${name}`
|
||||||
|
const offset = useState<{ x: number; y: number }>(key, () => {
|
||||||
|
if (!import.meta.client) return { x: 0, y: 0 }
|
||||||
|
try {
|
||||||
|
return { x: 0, y: 0, ...JSON.parse(localStorage.getItem(key) ?? '{}') }
|
||||||
|
} catch {
|
||||||
|
return { x: 0, y: 0 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
watch(offset, (value) => {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(key, JSON.stringify(value))
|
||||||
|
} catch {
|
||||||
|
// Storage off: the window stays put until the page reloads.
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return offset
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import type { DockItem } from '~/components/ui/Dock.vue'
|
||||||
import type { MapVillage } from '~/types/map'
|
import type { MapVillage } from '~/types/map'
|
||||||
|
|
||||||
definePageMeta({ layout: 'game' })
|
definePageMeta({ layout: 'game' })
|
||||||
|
|
@ -176,6 +177,15 @@ function onDragEnd() {
|
||||||
if (rounded.value) goTo(rounded.value)
|
if (rounded.value) goTo(rounded.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The panels in the dock fold and move like the village's boxes.
|
||||||
|
const { t } = useI18n()
|
||||||
|
const mapCards = computed<DockItem[]>(() => [
|
||||||
|
{ key: 'view', title: t('map.continent', { k: continent.value }) },
|
||||||
|
{ key: 'minimap', title: t('map.minimap') },
|
||||||
|
{ key: 'field', title: t('map.info.title') },
|
||||||
|
{ key: 'legend', title: t('map.legend.title') },
|
||||||
|
])
|
||||||
|
|
||||||
/** Villages in the visible area, for the legend. */
|
/** Villages in the visible area, for the legend. */
|
||||||
const counts = computed(() => {
|
const counts = computed(() => {
|
||||||
const v = visible.value
|
const v = visible.value
|
||||||
|
|
@ -248,12 +258,12 @@ const continent = computed(() => (rounded.value ? continentOf(rounded.value.x, r
|
||||||
|
|
||||||
<!-- The map's panels go into the stage's dock on the right. -->
|
<!-- The map's panels go into the stage's dock on the right. -->
|
||||||
<Teleport defer to="#stage-dock" :disabled="!staged">
|
<Teleport defer to="#stage-dock" :disabled="!staged">
|
||||||
<div class="space-y-2" :class="staged ? '' : 'p-2.5 pt-0'">
|
<div :class="staged ? 'text-sm' : 'p-2.5 pt-0 text-sm'">
|
||||||
<section class="panel">
|
<UiDock scope="map" :cards="mapCards">
|
||||||
<div class="panel-head">
|
<template #view-extra>
|
||||||
<h1 class="panel-title">{{ $t('map.continent', { k: continent }) }}</h1>
|
<span v-if="rounded" class="text-sm font-normal text-ink-500 normal-case tabular-nums">{{ rounded.x }}|{{ rounded.y }}</span>
|
||||||
<span v-if="rounded" class="text-sm text-ink-500 tabular-nums">{{ rounded.x }}|{{ rounded.y }}</span>
|
</template>
|
||||||
</div>
|
<template #view>
|
||||||
<div class="flex items-center gap-1.5 p-2">
|
<div class="flex items-center gap-1.5 p-2">
|
||||||
<button type="button" class="btn btn-outline" @click="router.replace({ query: {} })">{{ $t('map.home') }}</button>
|
<button type="button" class="btn btn-outline" @click="router.replace({ query: {} })">{{ $t('map.home') }}</button>
|
||||||
<div class="ml-auto flex items-center border border-wood-600 bg-parchment-50">
|
<div class="ml-auto flex items-center border border-wood-600 bg-parchment-50">
|
||||||
|
|
@ -262,13 +272,12 @@ const continent = computed(() => (rounded.value ? continentOf(rounded.value.x, r
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="error" class="alert m-2 mt-0" role="alert">{{ error }}</p>
|
<p v-if="error" class="alert m-2 mt-0" role="alert">{{ error }}</p>
|
||||||
</section>
|
</template>
|
||||||
|
|
||||||
<section class="panel overflow-hidden">
|
<template #minimap-extra>
|
||||||
<div class="panel-head">
|
<span v-if="overview.view.value" class="text-xs font-normal text-ink-500 normal-case tabular-nums">{{ overview.view.value.w }}×{{ overview.view.value.h }}</span>
|
||||||
<h2 class="panel-title">{{ $t('map.minimap') }}</h2>
|
</template>
|
||||||
<span v-if="overview.view.value" class="text-xs text-ink-500 tabular-nums">{{ overview.view.value.w }}×{{ overview.view.value.h }}</span>
|
<template #minimap>
|
||||||
</div>
|
|
||||||
<div class="border-b border-wood-700">
|
<div class="border-b border-wood-700">
|
||||||
<MapMiniMap
|
<MapMiniMap
|
||||||
v-if="overview.view.value"
|
v-if="overview.view.value"
|
||||||
|
|
@ -286,14 +295,13 @@ const continent = computed(() => (rounded.value ? continentOf(rounded.value.x, r
|
||||||
<input id="jump-y" v-model.number="jumpY" class="input w-16 px-1.5 py-1 text-center tabular-nums" type="number" :min="lo" :max="hi" />
|
<input id="jump-y" v-model.number="jumpY" class="input w-16 px-1.5 py-1 text-center tabular-nums" type="number" :min="lo" :max="hi" />
|
||||||
<button type="submit" class="btn btn-primary ml-auto py-1">{{ $t('map.jump') }}</button>
|
<button type="submit" class="btn btn-primary ml-auto py-1">{{ $t('map.jump') }}</button>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</template>
|
||||||
|
|
||||||
<MapInfoCard :village="shown" :at="selected" @center="goTo" />
|
<template #field>
|
||||||
|
<MapInfoCard :village="shown" :at="selected" @center="goTo" />
|
||||||
|
</template>
|
||||||
|
|
||||||
<section class="panel">
|
<template #legend>
|
||||||
<div class="panel-head">
|
|
||||||
<h2 class="panel-title">{{ $t('map.legend.title') }}</h2>
|
|
||||||
</div>
|
|
||||||
<ul class="panel-body space-y-1.5 text-sm">
|
<ul class="panel-body space-y-1.5 text-sm">
|
||||||
<li class="flex items-center gap-2"><span class="size-3 border border-wood-900 bg-[#d9b44a]" /> {{ $t('map.legend.own') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.own }}</span></li>
|
<li class="flex items-center gap-2"><span class="size-3 border border-wood-900 bg-[#d9b44a]" /> {{ $t('map.legend.own') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.own }}</span></li>
|
||||||
<li class="flex items-center gap-2"><span class="size-3 border border-wood-900 bg-[#962a1f]" /> {{ $t('map.legend.players') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.players }}</span></li>
|
<li class="flex items-center gap-2"><span class="size-3 border border-wood-900 bg-[#962a1f]" /> {{ $t('map.legend.players') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.players }}</span></li>
|
||||||
|
|
@ -302,7 +310,8 @@ const continent = computed(() => (rounded.value ? continentOf(rounded.value.x, r
|
||||||
<li class="pt-1 text-xs text-ink-500">{{ $t('map.legend.lines') }}</li>
|
<li class="pt-1 text-xs text-ink-500">{{ $t('map.legend.lines') }}</li>
|
||||||
<li class="text-xs text-ink-500">{{ $t('map.controls') }}<template v-if="busy"> · {{ $t('common.loading') }}</template></li>
|
<li class="text-xs text-ink-500">{{ $t('map.controls') }}<template v-if="busy"> · {{ $t('common.loading') }}</template></li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</template>
|
||||||
|
</UiDock>
|
||||||
</div>
|
</div>
|
||||||
</Teleport>
|
</Teleport>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ export default {
|
||||||
nobleman: 'Nobleman',
|
nobleman: 'Nobleman',
|
||||||
militia: 'Militia',
|
militia: 'Militia',
|
||||||
},
|
},
|
||||||
window: { fold: 'Fold', unfold: 'Unfold', close: 'Close' },
|
window: { fold: 'Fold', unfold: 'Unfold', close: 'Close', dock: 'Back into the column', reset: 'Double-click to put it back' },
|
||||||
errors: {
|
errors: {
|
||||||
unknown: 'Something went wrong.',
|
unknown: 'Something went wrong.',
|
||||||
unauthenticated: 'Please log in again.',
|
unauthenticated: 'Please log in again.',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue