feat: rally point tabs, map village popups, report filters, beginner protection bar, keyboard shortcuts

Ideas taken from how Die Stämme works, in our own look: the rally point splits into
commands, troops and simulator; hovering a village on the map shows its owner, points
and distance, a click offers send troops and centre; reports filter by attacks,
defence and support; a dismissible bar counts down beginner protection; one key per
screen (V, H, T, P, W, M, R); resources in the village bar lead to the workforce.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-29 01:00:13 +01:00
parent c1176aacc4
commit 9fba975c95
17 changed files with 334 additions and 44 deletions

View File

@ -10,7 +10,7 @@ This is the Nuxt client for a browser strategy game in the style of Tribal Wars.
- **Light Tailwind UI** (Tailwind 4, theme and component classes like `.panel`, `.btn` in `app/assets/css/main.css`) with simple hand-written inline SVG graphics (`app/components/icon/`, colours in `app/utils/palette.ts`). No paid, hosted or licensed assets: no icon packs, web fonts or images from outside the repo. - **Light Tailwind UI** (Tailwind 4, theme and component classes like `.panel`, `.btn` in `app/assets/css/main.css`) with simple hand-written inline SVG graphics (`app/components/icon/`, colours in `app/utils/palette.ts`). No paid, hosted or licensed assets: no icon packs, web fonts or images from outside the repo.
- **The village is a ground-level land view** (`app/components/village/Diorama.vue`, geometry in `app/diorama/`): isometric low-poly, drawn as inline SVG, no WebGL. The land fills the frame edge to edge (no island, no sky), cut to the container's shape; narrow screens scroll sideways. There are no tiles or positions: the server only sends each building's `space` and the village's `space.used/max`, and the client lays everything out deterministically in id order. The village core sits in the middle (headquarters on the plaza, storage, hiding places and rally point around it, inside the wall ring when there is one, a dirt edge without). Resource sites stand outside in their zones: iron mines at the rocky hill (upper left), clay pits on clay ground (lower left), timber camps at the forest edge (lower right), farms with fields (right); dirt roads lead from the gates to each zone and forest fills the rest. Levels start at 1. Each type has a model per level tier (1–4, 5–14, 15+); the wall goes stakes → timber → stone with towers. Buildings are focusable buttons that open their details card; a type that doesn't stand yet keeps an invisible empty plot that opens its build card. Buildings never move or light up on hover: only a click outlines the ground under them. Ambient life is welcome and stays out of the way: flat ground shadows, smoke from chimneys, forges and kilns, villagers walking the roads to the zones they work in; all motion stops under `prefers-reduced-motion`. The same models draw the building portraits on screen headers, the HQ list and the building cards (`VillageBuildingPortrait`). The world map groups forests, lakes and rocky hills by smooth noise of the coordinates, and village markers grow in five sizes with points. - **The village is a ground-level land view** (`app/components/village/Diorama.vue`, geometry in `app/diorama/`): isometric low-poly, drawn as inline SVG, no WebGL. The land fills the frame edge to edge (no island, no sky), cut to the container's shape; narrow screens scroll sideways. There are no tiles or positions: the server only sends each building's `space` and the village's `space.used/max`, and the client lays everything out deterministically in id order. The village core sits in the middle (headquarters on the plaza, storage, hiding places and rally point around it, inside the wall ring when there is one, a dirt edge without). Resource sites stand outside in their zones: iron mines at the rocky hill (upper left), clay pits on clay ground (lower left), timber camps at the forest edge (lower right), farms with fields (right); dirt roads lead from the gates to each zone and forest fills the rest. Levels start at 1. Each type has a model per level tier (1–4, 5–14, 15+); the wall goes stakes → timber → stone with towers. Buildings are focusable buttons that open their details card; a type that doesn't stand yet keeps an invisible empty plot that opens its build card. Buildings never move or light up on hover: only a click outlines the ground under them. Ambient life is welcome and stays out of the way: flat ground shadows, smoke from chimneys, forges and kilns, villagers walking the roads to the zones they work in; all motion stops under `prefers-reduced-motion`. The same models draw the building portraits on screen headers, the HQ list and the building cards (`VillageBuildingPortrait`). The world map groups forests, lakes and rocky hills by smooth noise of the coordinates, and village markers grow in five sizes with points.
- **Flat medieval colours only**, in the diorama and everywhere else: no gradients (CSS or SVG), no blur or backdrop-blur, no SVG filters or glows, no translucent overlays. Depth comes from the three flat shades per face in `app/diorama/iso.ts`, solid borders and hard shadows. Keep components small and typed, with state in composables (`useVillage`, `useWorld`). - **Flat medieval colours only**, in the diorama and everywhere else: no gradients (CSS or SVG), no blur or backdrop-blur, no SVG filters or glows, no translucent overlays. Depth comes from the three flat shades per face in `app/diorama/iso.ts`, solid borders and hard shadows. Keep components small and typed, with state in composables (`useVillage`, `useWorld`).
- **One game shell, like Die Stämme.** Pages inside a world (village screens, map, reports) use `layouts/game.vue`: the dark menu bar (`GameMenuBar`: village, map, reports with the unread count, server clock, account menu), then the sticky village bar (`GameVillageBar`: which village, stock with storage meters, incoming troops, and the village's screens as tabs: Overview, Headquarters, Recruit, Rally point, Workforce). On phones the screens move to a bottom tab bar (`GameTabBar`). The bar's village is the URL's on village screens and the last opened one elsewhere; `GameVillageFrame` holds its one `useVillage()` and shares it through `useVillageContext()`, so the map and reports keep the village on top. Pages outside a world use `layouts/default.vue` (menu bar only). The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens. - **One game shell, like Die Stämme.** Pages inside a world (village screens, map, reports) use `layouts/game.vue`: the dark menu bar (`GameMenuBar`: village, map, reports with the unread count, server clock, account menu), then the sticky village bar (`GameVillageBar`: which village, stock with storage meters, incoming troops, and the village's screens as tabs: Overview, Headquarters, Recruit, Rally point, Workforce). On phones the screens move to a bottom tab bar (`GameTabBar`). The bar's village is the URL's on village screens and the last opened one elsewhere; `GameVillageFrame` holds its one `useVillage()` and shares it through `useVillageContext()`, so the map and reports keep the village on top. One key per screen (`useShortcuts`): V overview, H headquarters, T recruit, P rally point, W workforce, M map, R reports. A building screen splits its parts into `UiSubTabs` (the rally point: commands, troops, simulator); the map shows a popup over a hovered village and actions under a clicked one. Pages outside a world use `layouts/default.vue` (menu bar only). The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens.
- All user-facing text goes through i18n keys, with `en` as the first locale. Sources are `i18n/locales/` and `i18n/pages/` (`@blax-software/i18n` layout); register a new page file in `i18n/messageloader.ts`. - All user-facing text goes through i18n keys, with `en` as the first locale. Sources are `i18n/locales/` and `i18n/pages/` (`@blax-software/i18n` layout); register a new page file in `i18n/messageloader.ts`.
## Mock server ## Mock server

View File

@ -25,6 +25,9 @@ const links = computed(() => {
] ]
}) })
/** The key that opens a menu entry (the village link opens its overview). */
const shortcutOf = (key: string) => SHORTCUTS[(key === 'village' ? 'overview' : key) as keyof typeof SHORTCUTS].toUpperCase()
const connection = computed(() => const connection = computed(() =>
isMockServer isMockServer
? { text: t('app.mock'), tone: 'bg-gold-400' } ? { text: t('app.mock'), tone: 'bg-gold-400' }
@ -58,6 +61,7 @@ watch(() => route.fullPath, () => menu.value?.removeAttribute('open'))
class="menu-link" class="menu-link"
:class="{ 'menu-link-active': l.active }" :class="{ 'menu-link-active': l.active }"
:aria-current="l.active ? 'page' : undefined" :aria-current="l.active ? 'page' : undefined"
:title="t('app.shortcut', { key: shortcutOf(l.key) })"
> >
<span class="relative"> <span class="relative">
<IconUi :name="l.icon" class="size-5 sm:size-4" /> <IconUi :name="l.icon" class="size-5 sm:size-4" />

View File

@ -0,0 +1,44 @@
<script setup lang="ts">
const props = defineProps<{
until: string
villageId: number
secondsUntil: (iso: string) => number
}>()
// Shown until it ends, or until the player closes it for this session.
const key = computed(() => `vp.protection.hidden.${props.villageId}`)
const hidden = ref(false)
onMounted(() => {
try {
hidden.value = sessionStorage.getItem(key.value) === '1'
} catch {
// no storage: the bar just shows again
}
})
function close() {
hidden.value = true
try {
sessionStorage.setItem(key.value, '1')
} catch {
// only this page view remembers it
}
}
const left = computed(() => props.secondsUntil(props.until))
</script>
<!-- A slim notice under the village bar while beginner protection lasts, with its countdown. -->
<template>
<div v-if="!hidden && left > 0" class="border-b-2 border-wood-700 bg-parchment-50" role="status">
<div class="mx-auto flex max-w-[96rem] items-center gap-2 px-3 py-1.5 text-sm sm:px-6">
<IconUi name="support" class="size-4 shrink-0 text-moss-700" />
<p class="min-w-0 flex-1">
{{ $t('village.protection.ends_in') }}
<span class="font-semibold tabular-nums">{{ formatDuration(left) }}</span>
<span class="hidden text-ink-500 sm:inline"> · {{ $t('village.protection.hint') }}</span>
</p>
<button type="button" class="text-ink-500 hover:text-blood-700" :aria-label="$t('common.close')" @click="close">
<IconUi name="close" class="size-4" />
</button>
</div>
</div>
</template>

View File

@ -75,14 +75,10 @@ async function rename() {
<!-- The stock: four resources with their storage meters, the storage cap and the villagers. --> <!-- The stock: four resources with their storage meters, the storage cap and the villagers. -->
<div class="order-3 grid w-full grid-cols-[repeat(4,minmax(0,1fr))_auto] items-center gap-x-3 md:order-2 md:mb-2 md:ml-auto md:flex md:w-auto md:gap-x-4"> <div class="order-3 grid w-full grid-cols-[repeat(4,minmax(0,1fr))_auto] items-center gap-x-3 md:order-2 md:mb-2 md:ml-auto md:flex md:w-auto md:gap-x-4">
<GameResource <!-- Each resource leads to where it is made: the workforce, production per building. -->
v-for="r in (['wood', 'clay', 'iron', 'food'] as const)" <NuxtLink v-for="r in (['wood', 'clay', 'iron', 'food'] as const)" :key="r" :to="`${base}/workforce`" class="min-w-0 hover:opacity-80">
:key="r" <GameResource :resource="r" :amount="resources[r]" :cap="village.storage_cap" :rate="village.rates[r]" />
:resource="r" </NuxtLink>
:amount="resources[r]"
:cap="village.storage_cap"
:rate="village.rates[r]"
/>
<span class="hidden items-center gap-1.5 text-sm text-ink-700 tabular-nums lg:inline-flex" :title="$t('village.resources.cap')"> <span class="hidden items-center gap-1.5 text-sm text-ink-700 tabular-nums lg:inline-flex" :title="$t('village.resources.cap')">
<IconBuilding type="storage" class="size-4" />{{ village.storage_cap }} <IconBuilding type="storage" class="size-4" />{{ village.storage_cap }}
</span> </span>
@ -104,6 +100,7 @@ async function rename() {
class="tab" class="tab"
:class="{ 'tab-active': isActive(s.path) }" :class="{ 'tab-active': isActive(s.path) }"
:aria-current="isActive(s.path) ? 'page' : undefined" :aria-current="isActive(s.path) ? 'page' : undefined"
:title="$t('app.shortcut', { key: SHORTCUTS[s.name].toUpperCase() })"
> >
<IconBuilding :type="s.icon" class="size-4" /> <IconBuilding :type="s.icon" class="size-4" />
{{ $t(`village.screens.${s.name}`) }} {{ $t(`village.screens.${s.name}`) }}

View File

@ -11,11 +11,27 @@ const { enter } = useCurrentWorld()
watch(v.village, (state) => { watch(v.village, (state) => {
if (state) enter(state.world_id, state.id) if (state) enter(state.world_id, state.id)
}) })
// One key per screen of the world, as the tab titles show.
useShortcuts(() => {
const base = `/village/${props.villageId}`
const worldId = v.village.value?.world_id
return {
...Object.fromEntries(VILLAGE_SCREENS.map((s) => [s.name, `${base}${s.path}`])),
...(worldId ? { map: `/map/${worldId}`, reports: `/reports/${worldId}` } : {}),
}
})
</script> </script>
<template> <template>
<div> <div>
<GameVillageBar v-if="v.village.value && v.resources.value" :village="v.village.value" :resources="v.resources.value" /> <GameVillageBar v-if="v.village.value && v.resources.value" :village="v.village.value" :resources="v.resources.value" />
<GameProtectionBar
v-if="v.village.value?.rally.protected_until"
:until="v.village.value.rally.protected_until"
:village-id="villageId"
:seconds-until="v.secondsUntil"
/>
<VillageFoodWarning <VillageFoodWarning
v-if="v.village.value" v-if="v.village.value"
:starvation="v.village.value.starvation" :starvation="v.village.value.starvation"

View File

@ -0,0 +1,52 @@
<script setup lang="ts">
import type { 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
}>()
const emit = defineEmits<{ center: []; close: [] }>()
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>
<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-primary px-2 py-1 text-xs"
>
<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>

View File

@ -0,0 +1,27 @@
<script setup lang="ts" generic="K extends string">
import type { UiIconName } from '~/components/icon/Ui.vue'
defineProps<{ tabs: { key: K; label: string; icon?: UiIconName; count?: number }[] }>()
/** The open tab. */
const current = defineModel<K>({ required: true })
</script>
<!-- A building screen's own sections, like the tabs under a Die Stämme building header. -->
<template>
<nav class="flex flex-wrap gap-1 border-b-2 border-wood-700" role="tablist">
<button
v-for="tab in tabs"
:key="tab.key"
type="button"
role="tab"
:aria-selected="current === tab.key"
class="-mb-0.5 inline-flex items-center gap-1.5 rounded-t-sm border-2 border-b-0 px-3 py-1.5 text-sm font-semibold"
:class="current === tab.key ? 'border-wood-700 bg-parchment-50 text-blood-700' : 'border-transparent text-wood-800 hover:text-blood-700'"
@click="current = tab.key"
>
<IconUi v-if="tab.icon" :name="tab.icon" class="size-4" />
{{ tab.label }}
<span v-if="tab.count" class="rounded-sm bg-blood-700 px-1.5 text-xs text-parchment-50 tabular-nums">{{ tab.count }}</span>
</button>
</nav>
</template>

View File

@ -1,4 +1,4 @@
import type { Report, ReportPage } from '~/types/game' import type { Report, ReportPage, ReportType } from '~/types/game'
/** Unread reports on the current world, for the header badge; every village state and report page updates it. */ /** Unread reports on the current world, for the header badge; every village state and report page updates it. */
export const useUnreadReports = () => useState<number>('reports.unread', () => 0) export const useUnreadReports = () => useState<number>('reports.unread', () => 0)
@ -6,6 +6,8 @@ export const useUnreadReports = () => useState<number>('reports.unread', () => 0
/** The player's reports on one world: a page of the list, one report, delete and mark read. */ /** The player's reports on one world: a page of the list, one report, delete and mark read. */
export function useReports(worldId: number) { export function useReports(worldId: number) {
const page = ref<ReportPage | null>(null) const page = ref<ReportPage | null>(null)
/** The kind of reports listed; null for all. */
const type = ref<ReportType | null>(null)
const error = ref<string | null>(null) const error = ref<string | null>(null)
const busy = ref(false) const busy = ref(false)
const unread = useUnreadReports() const unread = useUnreadReports()
@ -25,7 +27,7 @@ export function useReports(worldId: number) {
} }
async function list(event: string, data: object) { async function list(event: string, data: object) {
const result = await call<ReportPage>(event, { world_id: worldId, ...data }) const result = await call<ReportPage>(event, { world_id: worldId, type: type.value, ...data })
if (result) { if (result) {
page.value = result page.value = result
unread.value = result.unread unread.value = result.unread
@ -34,11 +36,19 @@ export function useReports(worldId: number) {
return { return {
page, page,
type,
error, error,
busy, busy,
load: (n = 1) => list('report.index', { page: n }), load: (n = 1) => list('report.index', { page: n }),
remove: (ids: number[]) => list('report.delete', { ids }), // Both answer with every kind; a filtered list loads its kind again.
readAll: () => list('report.readAll', {}), remove: async (ids: number[]) => {
await list('report.delete', { ids })
if (type.value) await list('report.index', { page: 1 })
},
readAll: async () => {
await list('report.readAll', {})
if (type.value) await list('report.index', { page: 1 })
},
/** One report; opening an unread one marks it read. */ /** One report; opening an unread one marks it read. */
show: async (id: number) => { show: async (id: number) => {
const report = await call<Report>('report.show', { id }) const report = await call<Report>('report.show', { id })

View File

@ -0,0 +1,22 @@
/** Keys for the screens of a world, like the shortcuts in Die Stämme: one letter, no modifier. */
export const SHORTCUTS = { overview: 'v', build: 'h', recruit: 't', rally: 'p', workforce: 'w', map: 'm', reports: 'r' } as const
/**
* Jumps between screens by key while the page is mounted. Keys typed into a field,
* or pressed with a modifier, are left alone.
*/
export function useShortcuts(targets: () => Partial<Record<keyof typeof SHORTCUTS, string>>) {
function onKey(e: KeyboardEvent) {
if (e.ctrlKey || e.metaKey || e.altKey || e.repeat) return
const el = e.target as HTMLElement | null
if (el && (el.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(el.tagName))) return
const key = e.key.toLowerCase()
const name = (Object.keys(SHORTCUTS) as (keyof typeof SHORTCUTS)[]).find((n) => SHORTCUTS[n] === key)
const to = name ? targets()[name] : undefined
if (!to) return
e.preventDefault()
navigateTo(to)
}
onMounted(() => window.addEventListener('keydown', onKey))
onBeforeUnmount(() => window.removeEventListener('keydown', onKey))
}

View File

@ -135,3 +135,8 @@ export function useVillageContext(): VillageContext {
if (!context) throw new Error('useVillageContext() needs the village page around it.') if (!context) throw new Error('useVillageContext() needs the village page around it.')
return context return context
} }
/** The village of the bar on top, where a page may also stand without one (the map). */
export function useVillageContextOrNull(): VillageContext | null {
return inject(VILLAGE, null)
}

View File

@ -911,14 +911,15 @@ const presentReport = (r: MockReport) =>
({ id: r.id, type: r.type, happened_at: r.happened_at, read: r.read, payload: r.payload }) as Report ({ id: r.id, type: r.type, happened_at: r.happened_at, read: r.read, payload: r.payload }) as Report
/** The player's reports on a world, newest first. */ /** The player's reports on a world, newest first. */
function reportPage(state: MockState, user: AuthUser, worldId: number, page = 1): ReportPage { function reportPage(state: MockState, user: AuthUser, worldId: number, page = 1, type: string | null = null): ReportPage {
const mine = (state.reports ?? []) const mine = (state.reports ?? [])
.filter((r) => r.user_id === user.id && r.world_id === worldId) .filter((r) => r.user_id === user.id && r.world_id === worldId)
.sort((a, b) => Date.parse(b.happened_at) - Date.parse(a.happened_at) || b.id - a.id) .sort((a, b) => Date.parse(b.happened_at) - Date.parse(a.happened_at) || b.id - a.id)
const pages = Math.max(1, Math.ceil(mine.length / REPORTS_PER_PAGE)) const shown = type ? mine.filter((r) => r.type === type) : mine
const pages = Math.max(1, Math.ceil(shown.length / REPORTS_PER_PAGE))
const current = Math.max(1, Math.min(pages, Math.floor(page) || 1)) const current = Math.max(1, Math.min(pages, Math.floor(page) || 1))
return { return {
reports: mine.slice((current - 1) * REPORTS_PER_PAGE, current * REPORTS_PER_PAGE).map(presentReport), reports: shown.slice((current - 1) * REPORTS_PER_PAGE, current * REPORTS_PER_PAGE).map(presentReport),
page: current, page: current,
pages, pages,
unread: mine.filter((r) => !r.read).length, unread: mine.filter((r) => !r.read).length,
@ -1206,7 +1207,7 @@ const handlers: Record<string, Handler> = {
return view(state, v, now) return view(state, v, now)
}, },
'report.index': (state, user, data): ReportPage => reportPage(state, user, Number(data.world_id), Number(data.page) || 1), 'report.index': (state, user, data): ReportPage => reportPage(state, user, Number(data.world_id), Number(data.page) || 1, data.type || null),
// Opening a report marks it read. // Opening a report marks it read.
'report.show': (state, user, data): Report => { 'report.show': (state, user, data): Report => {

View File

@ -136,6 +136,38 @@ const selectedVillage = computed(() =>
) )
const shown = computed(() => hovered.value ?? selectedVillage.value) const shown = computed(() => hovered.value ?? selectedVillage.value)
// Up close on the map, like a village's popup: the facts while hovering, actions on a click.
const bar = useVillageContextOrNull()
const from = computed(() => {
const v = bar?.village.value
return v && v.world_id === worldId ? { id: v.id, x: v.x, y: v.y } : null
})
/** Where a field sits inside the map frame, in px (the frame's border is 4 px). */
function fieldAt(x: number, y: number) {
const v = visible.value!
return { left: 4 + RULER + (x - v.left + 0.5) * field.value, top: 4 + RULER + (y - v.top) * field.value }
}
const popupAt = (x: number, y: number, below: boolean) => {
const p = fieldAt(x, y)
const half = 120
return {
left: `${clamp(p.left, half + 4, area.value.w - half)}px`,
top: below ? `${p.top + field.value + 4}px` : `${p.top - 4}px`,
}
}
const tip = computed(() => (hovered.value && hovered.value !== selectedVillage.value && visible.value ? hovered.value : null))
/** While the map is dragged, the click menu stays hidden. */
const dragging = ref(false)
const menu = computed(() => (selectedVillage.value && visible.value && !dragging.value ? selectedVillage.value : null))
function onDragMove(dx: number, dy: number) {
dragging.value = true
onDrag(dx, dy)
}
function onDragEnd() {
dragging.value = false
if (rounded.value) goTo(rounded.value)
}
/** 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
@ -191,12 +223,29 @@ const continent = computed(() => (rounded.value ? `K${Math.floor(rounded.value.y
:selected="selected" :selected="selected"
@select="selected = $event" @select="selected = $event"
@hover="hovered = $event" @hover="hovered = $event"
@drag="onDrag" @drag="onDragMove"
@dragend="rounded && goTo(rounded)" @dragend="onDragEnd"
@pan="pan" @pan="pan"
/> />
<p v-else class="py-24 text-center text-sm text-parchment-100">{{ $t('common.loading') }}</p> <p v-else class="py-24 text-center text-sm text-parchment-100">{{ $t('common.loading') }}</p>
</div> </div>
<MapFieldPopup
v-if="tip"
:village="tip"
:from="from"
class="pointer-events-none absolute z-20 -translate-x-1/2 -translate-y-full"
:style="popupAt(tip.x, tip.y, false)"
/>
<MapFieldPopup
v-if="menu"
:village="menu"
:from="from"
actions
class="absolute z-20 -translate-x-1/2"
:style="popupAt(menu.x, menu.y, true)"
@center="goTo(menu)"
@close="selected = null"
/>
<div class="mt-2 flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-ink-500"> <div class="mt-2 flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-ink-500">
<span>{{ $t('map.controls') }}</span> <span>{{ $t('map.controls') }}</span>
<span v-if="busy">{{ $t('common.loading') }}</span> <span v-if="busy">{{ $t('common.loading') }}</span>

View File

@ -1,11 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import type { Report } from '~/types/game' import type { Report, ReportType } from '~/types/game'
definePageMeta({ layout: 'game' }) definePageMeta({ layout: 'game' })
const route = useRoute() const route = useRoute()
const worldId = Number(route.params.worldId) const worldId = Number(route.params.worldId)
const { page, error, busy, load, remove, readAll } = useReports(worldId) const { page, type, error, busy, load, remove, readAll } = useReports(worldId)
useCurrentWorld().enter(worldId) useCurrentWorld().enter(worldId)
const { t } = useI18n() const { t } = useI18n()
const clock = useNow() const clock = useNow()
@ -24,6 +24,21 @@ function subject(r: Report) {
return t('reports.title_attack', { from: villageLabel(r.payload.attacker.village), to: villageLabel(r.payload.defender.village) }) return t('reports.title_attack', { from: villageLabel(r.payload.attacker.village), to: villageLabel(r.payload.defender.village) })
} }
// Kinds of reports as tabs, like the report folders in Die Stämme.
const kind = computed({
get: () => type.value ?? 'all',
set: (value: 'all' | ReportType) => {
type.value = value === 'all' ? null : value
load(1)
},
})
const kinds = computed(() => [
{ key: 'all' as const, label: t('reports.kinds.all'), icon: 'report' as const },
{ key: 'attack' as const, label: t('reports.kinds.attack'), icon: 'attack' as const },
{ key: 'defense' as const, label: t('reports.kinds.defense'), icon: 'support' as const },
{ key: 'support' as const, label: t('reports.kinds.support'), icon: 'users' as const },
])
const DOT = { won: 'bg-moss-600', losses: 'bg-gold-500', lost: 'bg-blood-700', info: 'bg-iron-400' } const DOT = { won: 'bg-moss-600', losses: 'bg-gold-500', lost: 'bg-blood-700', info: 'bg-iron-400' }
</script> </script>
@ -38,6 +53,7 @@ const DOT = { won: 'bg-moss-600', losses: 'bg-gold-500', lost: 'bg-blood-700', i
</button> </button>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<UiSubTabs v-model="kind" :tabs="kinds" class="mb-3" />
<p v-if="error" class="alert mb-3" role="alert">{{ error }}</p> <p v-if="error" class="alert mb-3" role="alert">{{ error }}</p>
<p v-if="!page" class="py-6 text-center text-sm text-ink-500">{{ $t('common.loading') }}</p> <p v-if="!page" class="py-6 text-center text-sm text-ink-500">{{ $t('common.loading') }}</p>
<p v-else-if="!page.reports.length" class="py-6 text-center text-sm text-ink-500">{{ $t('reports.none') }}</p> <p v-else-if="!page.reports.length" class="py-6 text-center text-sm text-ink-500">{{ $t('reports.none') }}</p>

View File

@ -1,38 +1,75 @@
<script setup lang="ts"> <script setup lang="ts">
import type { UnitType } from '~/types/game'
const route = useRoute() const route = useRoute()
const router = useRouter()
const v = useVillageContext() const v = useVillageContext()
const { t } = useI18n()
const village = computed(() => v.village.value!) const village = computed(() => v.village.value!)
/** `?x=&y=` from the map fills in the target. */ /** `?x=&y=` from the map fills in the target. */
const initialTarget = computed(() => (route.query.x && route.query.y ? { x: Number(route.query.x), y: Number(route.query.y) } : null)) const initialTarget = computed(() => (route.query.x && route.query.y ? { x: Number(route.query.x), y: Number(route.query.y) } : null))
const rallyPoint = computed(() => village.value.buildings.find((b) => b.type === 'rally_point') ?? null) const rallyPoint = computed(() => village.value.buildings.find((b) => b.type === 'rally_point') ?? null)
// Like the rally point in Die Stämme, its parts are tabs: commands, troops, simulator.
type Tab = 'commands' | 'troops' | 'simulator'
const tab = computed<Tab>({
get: () => (['troops', 'simulator'].includes(String(route.query.tab)) ? (route.query.tab as Tab) : 'commands'),
set: (value) => router.replace({ query: { ...route.query, tab: value === 'commands' ? undefined : value } }),
})
const incoming = computed(() => village.value.movements.filter((m) => m.direction === 'in').length)
const tabs = computed(() => [
{ key: 'commands' as const, label: t('village.rally.tabs.commands'), icon: 'attack' as const, count: incoming.value },
{ key: 'troops' as const, label: t('village.rally.tabs.troops'), icon: 'users' as const },
{ key: 'simulator' as const, label: t('village.rally.tabs.simulator'), icon: 'support' as const },
])
const home = computed(() => unitRows(village.value.troops))
</script> </script>
<!-- The rally point: send troops, the troop movements, and support. --> <!-- The rally point: send troops and follow them, see where the troops are, and simulate battles. -->
<template> <template>
<div class="mx-auto max-w-[96rem] space-y-6 px-4 py-6 sm:px-6"> <div class="mx-auto max-w-[96rem] space-y-5 px-4 py-6 sm:px-6">
<VillageScreenHeader type="rally_point" :level="rallyPoint?.level ?? null" :title="$t('buildings.rally_point')" :description="$t('village.about.rally')" /> <VillageScreenHeader type="rally_point" :level="rallyPoint?.level ?? null" :title="$t('buildings.rally_point')" :description="$t('village.about.rally')" />
<div class="grid gap-6 lg:grid-cols-[minmax(0,1fr)_22rem] 2xl:grid-cols-[minmax(0,1fr)_26rem]"> <UiSubTabs v-model="tab" :tabs="tabs" />
<div class="min-w-0 space-y-6">
<VillageSendTroops <div v-if="tab === 'commands'" class="grid gap-6 xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
:key="`${route.query.x}|${route.query.y}`" <VillageSendTroops
:village="village" :key="`${route.query.x}|${route.query.y}`"
:busy="v.busy.value" class="self-start"
:initial-target="initialTarget" :village="village"
:now="v.now.value" :busy="v.busy.value"
:preview="v.preview" :initial-target="initialTarget"
:send="v.send" :now="v.now.value"
/> :preview="v.preview"
<VillageMovements :send="v.send"
:movements="village.movements" />
:world-id="village.world_id" <VillageMovements
:now="v.now.value" class="self-start"
:seconds-until="v.secondsUntil" :movements="village.movements"
:busy="v.busy.value" :world-id="village.world_id"
@cancel="v.cancelMovement" :now="v.now.value"
/> :seconds-until="v.secondsUntil"
<VillageSimulator :world-id="village.world_id" :troops="village.troops" /> :busy="v.busy.value"
</div> @cancel="v.cancelMovement"
/>
</div>
<div v-else-if="tab === 'troops'" class="grid gap-6 lg:grid-cols-[22rem_minmax(0,1fr)]">
<section class="panel self-start">
<div class="panel-head">
<h2 class="panel-title">{{ $t('village.rally.at_home') }}</h2>
</div>
<div class="panel-body">
<ul v-if="home.length" class="divide-y divide-parchment-300 text-sm">
<li v-for="[unit, count] in home" :key="unit" class="flex items-center gap-2 py-1">
<IconUnit :unit="unit as UnitType" class="size-5 text-wood-800" />
<span class="flex-1">{{ $t(`units.${unit}`) }}</span>
<span class="font-semibold tabular-nums">{{ count }}</span>
</li>
</ul>
<p v-else class="text-sm text-ink-500">{{ $t('village.troops.none') }}</p>
</div>
</section>
<VillageSupportPanel <VillageSupportPanel
class="self-start" class="self-start"
:here="village.support.here" :here="village.support.here"
@ -43,5 +80,7 @@ const rallyPoint = computed(() => village.value.buildings.find((b) => b.type ===
@withdraw="v.withdraw" @withdraw="v.withdraw"
/> />
</div> </div>
<VillageSimulator v-else :world-id="village.world_id" :troops="village.troops" open />
</div> </div>
</template> </template>

View File

@ -4,6 +4,7 @@ export default {
menu: 'Main menu', menu: 'Main menu',
account: 'Account', account: 'Account',
server_time: 'Server time', server_time: 'Server time',
shortcut: 'Key: {key}',
map: 'Map', map: 'Map',
reports: 'Reports', reports: 'Reports',
unread_reports: '{count} unread reports', unread_reports: '{count} unread reports',

View File

@ -4,6 +4,7 @@ export default {
en: { en: {
reports: { reports: {
title: 'Reports', title: 'Reports',
kinds: { all: 'All', attack: 'Attacks', defense: 'Defence', support: 'Support' },
none: 'No reports yet.', none: 'No reports yet.',
subject: 'Subject', subject: 'Subject',
received: 'Received', received: 'Received',

View File

@ -17,6 +17,10 @@ export default {
workforce: 'Workforce', workforce: 'Workforce',
short: { overview: 'Village', build: 'Build', recruit: 'Recruit', rally: 'Rally', workforce: 'Workers' }, short: { overview: 'Village', build: 'Build', recruit: 'Recruit', rally: 'Rally', workforce: 'Workers' },
}, },
protection: {
ends_in: 'Beginner protection ends in',
hint: 'Players can’t attack you yet, and you can only attack barbarian villages.',
},
about: { about: {
build: 'The heart of your village. Your builders put up new buildings here, upgrade them and tear them down. Every level builds faster and makes room for more.', build: 'The heart of your village. Your builders put up new buildings here, upgrade them and tear them down. Every level builds faster and makes room for more.',
recruit: 'Barracks, stables, workshops and the academy train your army. Every soldier was a villager, and eats from your farms for as long as it serves.', recruit: 'Barracks, stables, workshops and the academy train your army. Every soldier was a villager, and eats from your farms for as long as it serves.',
@ -107,6 +111,8 @@ export default {
fix_levy: 'The drafted militia leave the farms unworked: ending the levy helps.', fix_levy: 'The drafted militia leave the farms unworked: ending the levy helps.',
}, },
rally: { rally: {
tabs: { commands: 'Commands', troops: 'Troops', simulator: 'Simulator' },
at_home: 'In the village',
send: 'Send troops', send: 'Send troops',
all: 'All troops', all: 'All troops',
none_home: 'No troops in the village.', none_home: 'No troops in the village.',