taloria/art/tools/ui_probe.py
torsten ee2c8b8efd ui: Neusatz auf 8x10 — Elemente, docs/ui.md, Karten-Mocks
Alle UI-Elemente sind auf den 8x10-Satz umgesetzt und werden mit 2x
ausgeliefert (vorher 4x aus der 320x180-Basis). Neue Maße: Dialog
390x71 / 390x107 (47 Zeichen/Zeile), Buttons 64x18, Slots 26, Pack
170x132, Zauberbuch 170x140, Kampfleiste 400x56, Misc 220x130,
Ladebalken 240x26. Die alten Elemente und die Szenen-HUDs sind gelöscht.

docs/ui.md hält jetzt verbindlich fest: Screens (Karte, Kampf,
Inventar) mit Pixelmaßen, Schriftmetriken, Textmengen, Zustände,
Palette und die zwei Linien/Alpha-Regeln.

Neue Mocks über echten Karten: art/prep/map-mock/ (Stadt mit Dialog,
Dungeon, Inventar über abgedunkelter Karte) und der aktualisierte
Kampf-Mock (400x56-Leiste, 228x56-Log). Beide bei 1x und 2x.

Roadmap: 0.2 Layout/Font/Mocks/Textregeln abgehakt; offen sind 9-Slice,
Engine-Export der Schrift und Listen-Zustände. 0.4: systeme.md und ui.md
stehen, offen bleibt das Referenzblatt aus 0.1. Der Nachlauf auf 2x ist
für die UI erledigt, die übrigen Kategorien folgen.
2026-11-14 23:45:29 +01:00

240 lines
9.1 KiB
Python

#!/usr/bin/env python3
"""Auflösungs-Gegenprobe für docs/roadmap.md §0.0.
> **Historisch (14.11.2026):** Die Bilder in `prep/aufloesung/` entstanden
> mit dem 5x7-Satz. `ui.draw_text` liefert inzwischen 8x10 — ein erneuter Lauf
> überschreibt die damalige Gegenprobe mit anderen Maßen. Nur ausführen, wenn
> eine neue Probe gewollt ist.
Zeichnet zwei Mocks (Dialog, Kampf) bei 320x180 und 640x360 mit **gleicher
absoluter Pixelgröße** — 5x7-Font, 32-px-Raster, gleiche Buttons. Damit ist
die Frage nicht „welche Auflösung sieht retro aus", sondern: wie viel Text,
wie viele Rasterfelder und wie viel Platz für ein Kampf-Log hat man.
python3 art/tools/ui_probe.py # -> art/prep/aufloesung/
python3 art/tools/ui_probe.py --out /tmp/x
Ausgabe je Auflösung 1x (PNG) plus zwei Vergleichsblätter, auf denen beide
Kandidaten gleich groß auf dem Schirm stehen (320 -> 4x, 640 -> 2x).
"""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
from PIL import Image, ImageDraw
sys.path.insert(0, str(Path(__file__).resolve().parent))
import ui # noqa: E402 (Nachbarwerkzeug, bewusst kein Paket)
ART = Path(__file__).resolve().parent.parent
FINAL = ART / "final"
SCENE_DIALOG = FINAL / "Pictures" / "taverne_B_1280x720.png"
SCENE_KAMPF = FINAL / "Pictures" / "waldrand_1280x720.png"
WOLF = FINAL / "Creatures" / "monster_wolf_96px.png"
from ui import ( # noqa: E402
BLOOD, CREAM, CREAM_D, GOLD, INK, LINE, OCHRE, OCHRE_D, OLIVE, PANEL,
PANEL_HI, PANEL_LO, SLATE, SLATE_D, alpha, draw_text, elem_combat,
elem_dialog, elem_party, panel, text_width, well,
)
RENDER = [(320, 180, 4), (640, 360, 2)]
# ------------------------------------------------------------------ Text -----
DIALOG_TEXT = (
"The harbour is quiet tonight. Too quiet for a town that smells of salt "
"and iron. The lanterns swing, the gulls have gone to roost, and the tide "
"is coming in under the pier. Something is wrong with the water, and "
"nobody will say what. Ask the harbourmaster, or ask the woman by the "
"crane who has been counting ships since noon."
)
LOG_LINES = [
"RND 3 - ALDRIC MOVES 2 (14/30 AP)",
"WOLF 1 ATTACKS RAI -> MISS",
"RAI ATTACKS WOLF 2 -> 6 DAMAGE",
]
def wrap(text: str, max_chars: int) -> list[str]:
lines, cur = [], ""
for word in text.split():
t = (cur + " " + word).strip()
if len(t) <= max_chars:
cur = t
else:
if cur:
lines.append(cur)
cur = word
if cur:
lines.append(cur)
return lines
def scene(path: Path, size, darken: int = 0) -> Image.Image:
im = Image.open(path).convert("RGBA").resize(size, Image.LANCZOS)
if darken:
shade = Image.new("RGBA", size, (0, 0, 0, darken))
im.alpha_composite(shade)
return im
# --------------------------------------------------------------- Dialog -----
def mock_dialog(w: int, h: int) -> tuple[Image.Image, int, int, int, int]:
im = scene(SCENE_DIALOG, (w, h))
d = ImageDraw.Draw(im)
im.alpha_composite(elem_party(count=3, fw=34, fh=34, psize=26), (w - 34 - 6, 6))
panel(d, (6, 6, 46, 20), fill=alpha(PANEL, 232))
draw_text(d, 11, 10, "MENU", CREAM)
bw = w - 28 # gleicher Rand links/rechts wie im Bestand
chars = (bw - 22) // 6 # 11 px Rand je Seite, 6 px Vorschub
full = wrap(DIALOG_TEXT, chars)
max_lines = max(1, (round(h * 0.33) - 24) // 10)
lines = full[:max_lines]
box_h = 24 + 10 * len(lines) # Höhe folgt dem Inhalt, nicht dem Schirm
im.alpha_composite(elem_dialog(lines, "ALDRIC THE GREY", box_h, w=bw),
(14, h - box_h - 9))
d.rectangle((0, 0, w - 1, h - 1), outline=INK)
return im, chars, len(lines), len(full), box_h
# ---------------------------------------------------------------- Kampf -----
def mock_kampf(w: int, h: int) -> tuple[Image.Image, int, int, int]:
im = scene(SCENE_KAMPF, (w, h), darken=70)
d = ImageDraw.Draw(im)
bar = elem_combat() # 300x40, feste Elementgröße
bar_h = bar.height
bar_y = h - bar_h - 6
party = elem_party(count=3, fw=34, fh=34, psize=26) # 34x110
im.alpha_composite(party, (w - 34 - 6, 6))
# Rasterfeld: alles über der Aktionsleiste, links der Party-Spalte
gx0, gy0 = 6, 6
gx1 = w - 34 - 12
gy1 = bar_y - 6
cols = (gx1 - gx0 + 1) // 32
rows = (gy1 - gy0 + 1) // 32
gy0 = gy1 - rows * 32 + 1 # unten an die Aktionsleiste anschließen
overlay = Image.new("RGBA", (w, h), (0, 0, 0, 0))
od = ImageDraw.Draw(overlay)
for c in range(cols + 1):
x = gx0 + c * 32
od.line((x, gy0, x, gy0 + rows * 32), fill=alpha(INK, 56))
for r in range(rows + 1):
y = gy0 + r * 32
od.line((gx0, y, gx0 + cols * 32, y), fill=alpha(INK, 56))
im.alpha_composite(overlay)
d = ImageDraw.Draw(im)
def cell(c: int, r: int) -> tuple[int, int]:
return gx0 + c * 32, gy0 + r * 32
# Bewegung des aktiven Helden: 2 Felder Reichweite
active = (2, rows - 1)
for c in range(cols):
for r in range(rows):
if max(abs(c - active[0]), abs(r - active[1])) <= 2:
x, y = cell(c, r)
im.alpha_composite(Image.new("RGBA", (32, 32), alpha(OCHRE, 44)),
(x, y))
d.rectangle((x, y, x + 31, y + 31), outline=alpha(OCHRE, 120))
# Gegner: Wolf-Sprite 1x (96 -> 24 px, exakt /4)
wolf = Image.open(WOLF).convert("RGBA").resize((24, 24), Image.NEAREST)
for c, r in [(cols - 2, 0), (cols - 4, 0), (cols - 3, 1)]:
x, y = cell(c, r)
im.alpha_composite(wolf, (x + 4, y + 6))
d.rectangle((x + 2, y + 2, x + 29, y + 29), outline=BLOOD)
# Party: Chips 20x20 mit Initiale, unten links
for (c, r), letter in [(active, "A"), ((1, rows - 1), "B"),
((1, rows - 2), "C")]:
x, y = cell(c, r)
well(d, (x + 6, y + 6, x + 25, y + 25))
d.rectangle((x + 6, y + 6, x + 25, y + 25), outline=GOLD)
draw_text(d, x + 13, y + 13, letter, CREAM)
im.alpha_composite(bar, (6, bar_y))
# Kampf-Log passt nur, wenn rechts neben der Leiste Platz ist
log_x = 6 + bar.width + 6
log_w = w - 6 - log_x
if log_w >= 120:
panel(d, (log_x, bar_y, w - 7, bar_y + bar_h - 1),
fill=alpha(PANEL, 236), line=INK)
draw_text(d, log_x + 5, bar_y + 4, "COMBAT LOG", OCHRE)
for i, line in enumerate(LOG_LINES):
draw_text(d, log_x + 5, bar_y + 14 + i * 8,
line[: (log_w - 10) // 6], CREAM_D)
d.rectangle((0, 0, w - 1, h - 1), outline=INK)
return im, cols, rows, log_w if log_w >= 120 else 0
# ------------------------------------------------------------- Vergleich ----
def label(text: str, w: int) -> Image.Image:
im = Image.new("RGBA", (w // 2, 12), alpha(INK))
draw_text(ImageDraw.Draw(im), 4, 3, text, CREAM)
return im.resize((w, 24), Image.NEAREST)
def sheet(pairs, out: Path, name: str) -> None:
"""Beide Kandidaten gleich groß auf dem Schirm: 320 -> 4x, 640 -> 2x."""
tiles = []
for text, im, scale in pairs:
big = im.resize((im.width * scale, im.height * scale), Image.NEAREST)
tiles.append((label(text, big.width), big))
gap = 10
W = max(t.width for t, _ in tiles)
H = sum(t.height + b.height for t, b in tiles) + gap * (len(tiles) - 1)
canvas = Image.new("RGBA", (W, H), alpha(INK))
y = 0
for t, b in tiles:
canvas.alpha_composite(t, (0, y))
y += t.height
canvas.alpha_composite(b, (0, y))
y += b.height + gap
out.mkdir(parents=True, exist_ok=True)
canvas.save(out / f"{name}.png")
print(f"{name:24s} {canvas.width}x{canvas.height}")
def main(argv=None) -> None:
ap = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--out", type=Path, default=ART / "prep" / "aufloesung")
a = ap.parse_args(argv)
dialog_tiles, kampf_tiles = [], []
for w, h, scale in RENDER:
dlg, chars, used, full, box_h = mock_dialog(w, h)
kpf, cols, rows, log_w = mock_kampf(w, h)
a.out.mkdir(parents=True, exist_ok=True)
dlg.save(a.out / f"dialog_{w}x{h}.png")
kpf.save(a.out / f"kampf_{w}x{h}.png")
pct = round(100 * box_h / h)
print(f"{w}x{h}: Dialog {chars} Zeichen/Zeile, {used} von {full} "
f"Zeilen sichtbar, Panel {box_h} px = {pct} % Höhe "
f"({chars * used} Zeichen) | Raster {cols}x{rows} "
f"= {cols * rows} Felder | Log {log_w or '—'} px")
dialog_tiles.append((f"{w}x{h} - Dialog: {used} von {full} Zeilen, "
f"Panel {box_h} px", dlg, scale))
kampf_tiles.append((f"{w}x{h} - Kampf: {cols}x{rows} Felder"
+ (f", Log {log_w} px" if log_w else ", kein Log"),
kpf, scale))
sheet(dialog_tiles, a.out, "_vergleich_dialog")
sheet(kampf_tiles, a.out, "_vergleich_kampf")
if __name__ == "__main__":
main()