# Village HUD

A game HUD over a little village scene built only from Cozy UI parts: resource chips, a minimap that opens the village map, a floating harvest button and a pick-one-of-three level-up sheet. Tap Harvest, then pick a card.

## Source

```tsx
import { useState } from "react";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogTitle } from "@/components/ui/dialog";
import { GameMap, MiniMap } from "@/components/ui/game-map";
import { Progress } from "@/components/ui/progress";
import { cn } from "@/lib/utils";
import { Coin, Grain, Scene, Sprout, Tools, Tree } from "@/docs/art";
import { VillageMapArt } from "@/docs/art/map";
import { KINDS, MAP_H, MAP_W, MARKERS, REGIONS, ROUTE } from "./map-data";

const world = { mapWidth: MAP_W, mapHeight: MAP_H, background: <VillageMapArt />, markers: MARKERS, regions: REGIONS, paths: ROUTE, kinds: KINDS, player: { x: 520, y: 300, heading: 135, label: "You" } };

const perks = [
  { Icon: Sprout, title: "Wider paddy", text: "Rice plots yield 20% more grain." },
  { Icon: Tree, title: "Shady grove", text: "Banana trees grow 15% faster." },
  { Icon: Tools, title: "Oiled thresher", text: "Threshing takes half the time." },
];

/** A game HUD over a village scene: resource chips, a floating harvest
 *  button and a "pick one of three" level-up sheet. */
export default function VillageHud() {
  const [coins, setCoins] = useState(1250);
  const [xp, setXp] = useState(72);
  const [ready, setReady] = useState(true);
  const [picked, setPicked] = useState<string | null>(null);
  const [showPick, setShowPick] = useState(true);
  const [mapOpen, setMapOpen] = useState(false);

  return (
    <div className="@container w-full">
    <div className="relative aspect-[3/4] w-full overflow-hidden rounded-[var(--cz-radius-lg)] border-3 border-outline @md:aspect-[4/3] @3xl:aspect-[16/10]">
      <Scene className="absolute inset-0 h-full w-full" />

      {/* resource chips: thin HUD frame */}
      <div className="absolute left-3 top-3 flex flex-wrap gap-2">
        <div className="cz-badge cz-badge--outline gap-2 px-3 py-1 text-base" style={{ boxShadow: "0 3px 0 var(--cz-outline)" }}>
          <Coin className="!h-7 !w-7" />
          <span className="tabular-nums">{coins.toLocaleString("en")}</span>
          <span className="sr-only">coins</span>
        </div>
        <div className="cz-badge cz-badge--outline gap-2 px-3 py-1" style={{ boxShadow: "0 3px 0 var(--cz-outline)" }}>
          <Grain className="!h-7 !w-7" />
          <Badge variant="secondary" className="!shadow-none">Lv 7</Badge>
          <Progress value={xp} size="sm" className="w-20 sm:w-28" aria-label="Experience" />
        </div>
      </div>

      {/* minimap: click to open the village map */}
      <div className="absolute right-4 top-3 hidden @md:block">
        <MiniMap {...world} size={128} zoom={0.7} zoomControls={false} onOpen={() => setMapOpen(true)} />
      </div>
      <Button size="sm" variant="outline" className="absolute right-3 top-3 @md:hidden" onClick={() => setMapOpen(true)}>Map</Button>
      <Dialog open={mapOpen} onOpenChange={setMapOpen}>
        <DialogContent style={{ width: "min(94vw, 960px)", maxWidth: "none" }}>
          <DialogTitle>Village map</DialogTitle>
          <DialogDescription>Click a pin to see what is there.</DialogDescription>
          <GameMap {...world} search height="min(62vh, 520px)" />
        </DialogContent>
      </Dialog>

      {/* floating harvest button above the house */}
      {ready && (
        <div className={cn("cz-motion-float absolute left-[42%] top-[22%]", showPick && "hidden @md:block")}>
          <Button
            variant="reward"
            className="cz-motion-pop rounded-full"
            onClick={() => { setReady(false); setCoins((c) => c + 120); setXp((v) => Math.min(100, v + 8)); setTimeout(() => setReady(true), 2600); }}
          >
            <Grain className="!h-6 !w-6" /> Harvest
          </Button>
        </div>
      )}
      {!ready && <span className="cz-motion-pop absolute left-[40%] top-[20%] rounded-full bg-surface px-3 py-1 text-sm" style={{ boxShadow: "0 3px 0 var(--cz-outline)" }}>+120 coins · +8 XP</span>}

      {/* level-up: pick one of three tear-off calendar sheets */}
      {showPick ? (
        <div className="absolute inset-x-0 bottom-0 grid gap-3 p-3 pt-10" style={{ background: "linear-gradient(transparent, var(--cz-overlay) 40%)" }}>
          <p className="m-0 text-center text-lg text-[var(--cz-text-inverse)] [text-shadow:0_2px_0_rgb(0_0_0/0.4)]">Level 8! Pick one</p>
          <div className="mx-auto grid w-full max-w-2xl grid-cols-3 gap-2 sm:gap-4">
            {perks.map((p, i) => (
              <button
                key={p.title}
                type="button"
                onClick={() => setPicked(p.title)}
                className={cn("cz-card cz-card--interactive cz-motion-bounce-in min-w-0 gap-1 overflow-hidden p-0 text-left", picked === p.title && "outline-3 outline-offset-2 outline-[var(--cz-reward)]")}
                style={{ animationDelay: `${i * 90}ms`, font: "inherit" }}
              >
                <span className="relative block h-5 border-b-3 border-outline sm:h-7" style={{ background: "var(--cz-primary)" }}>
                  <span className="absolute left-1/2 top-1/2 size-2.5 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-outline bg-page" />
                </span>
                <span className="grid justify-items-center gap-1 px-2 pb-3 pt-1 sm:px-3">
                  <p.Icon className="h-10 w-10 sm:h-16 sm:w-16" />
                  <span className="text-center text-sm leading-tight sm:text-base">{p.title}</span>
                  <span className="hidden text-center text-xs text-text-muted sm:block">{p.text}</span>
                </span>
              </button>
            ))}
          </div>
          <div className="flex justify-center">
            <Button size="sm" variant="success" disabled={!picked} onClick={() => setShowPick(false)}>
              {picked ? `Take “${picked}”` : "Choose a card"}
            </Button>
          </div>
        </div>
      ) : (
        <div className="absolute bottom-3 right-3">
          <Button size="sm" variant="secondary" onClick={() => { setPicked(null); setShowPick(true); }}>Show level-up again</Button>
        </div>
      )}
    </div>
    </div>
  );
}
```

Docs: https://cozy-ui.solo.engineer/blocks/village-hud/
