art: 3x-Master — final3x, UI3 und Stadt-Satz aus alten Raws

- final3x/ als Master für 1920x1080: Fonts, UI-Satz, 96-px-Stadt
- Stadt/Boden aus den alten 1024er-Raws neu gerechnet (Erde, Gras,
  Wand, Fachwerkdach, goldene Tür) statt aus den neuen Prompts
- ui3.py, ui_slice.py und engine_assets.py auf 3x umgestellt
- Belege: Bildschirm vorher/nachher, Elemente, Kachelvergleiche
This commit is contained in:
torsten 2026-11-15 15:30:22 +01:00
parent ae7fde714e
commit c80e61bcb0
79 changed files with 1658 additions and 83 deletions

View file

@ -1,20 +1,18 @@
#!/usr/bin/env python3
"""engine_assets.py - 1x-Fassung der Assets fuer das Godot-Projekt.
Das Spiel rendert in einem **640x360-Viewport** (docs/engine.md E1). Darin ist
eine Kachel 32 px, eine Kreatur 96 px, die Dialogbox 390 px. `art/final/`
liegt dagegen in 2x (Kachel 64, Kreatur 192) — das ist das Bild, das bei 720p
auf dem Schirm steht, nicht das, was die Engine rechnet.
Das Spiel rendert in einem **1920x1080-Viewport** (docs/engine.md E1). Darin
ist eine Kachel 96 px, eine Kreatur 288 px, die Dialogbox 1170 px.
`art/final3x/` liegt genau in diesem Massstab (1x) — die 640er-Fassung in
`art/final/` ist Altbestand und wird hier nicht mehr gelesen.
Dieses Werkzeug schreibt deshalb die 1x-Kopie nach `game/assets/`:
python3 tools/engine_assets.py --write
python3 tools/engine_assets.py --check # Exit 1, wenn die Kopie abweicht
Die Halbierung ist verlustfrei: jede 2x-Datei ist ein exakter
nearest-Upscale der 1x-Zeichnung (geprueft mit demselben Rundlauf wie
`nachlauf2x.py`). `font/` wird kopiert, nicht halbiert — der 1x-Font ist schon
die Engine-Fassung; `_palette_*` und `_versuche` kommen nicht mit.
Bilder und Schriften werden **1:1** kopiert. `_2x`-Fassungen (Reserve fuer 4K)
und Dateien mit Unterstrich (Paletten, Rampen, Belegbilder) bleiben draussen.
"""
from __future__ import annotations
@ -26,10 +24,10 @@ from pathlib import Path
from PIL import Image
ART = Path(__file__).resolve().parent.parent
FINAL = ART / "final"
FINAL = ART / "final3x"
PROJEKT = ART.parent / "game" / "assets"
# art/final/<Quelle> -> game/assets/<Ziel>
# art/final3x/<Quelle> -> game/assets/<Ziel>
ORDNER = {
"Terrain": "terrain",
"Creatures": "creatures",
@ -39,26 +37,20 @@ ORDNER = {
"UI": "ui",
"Pictures": "pictures",
}
KOPIEREN = {"Font": "font"} # 1:1, keine Halbierung
UEBERSPRINGEN = ("_palette_", "_karte_demo", "_vergleich", "_referenz")
KOPIEREN = {"Font": "font"}
UEBERSPRINGEN = ("_",)
def exakt_2x(im: Image.Image) -> bool:
"""Ist `im` ein exakter 2x-Nearest-Upscale? (Vergleich ueber Rohbytes --
`getbbox()` auf RGBA-Differenzen liefert immer None, siehe nachlauf2x.py.)"""
w, h = im.size
if w % 2 or h % 2:
def soll_datei(name: str) -> bool:
"""Gehoert die Datei in die Engine-Kopie? (keine 2x-Reserve, kein Beleg)"""
return not name.startswith(UEBERSPRINGEN) and "_2x" not in name
def gleich(a: Path, b: Path) -> bool:
"""Byte-Gleichheit; bei PNG zusaetzlich die Groesse (Fehlermeldung)."""
if not b.exists() or a.stat().st_size != b.stat().st_size:
return False
# NEAREST statt BOX: BOX rundet auf halbtransparentem RGBA um 1 ab.
klein = im.resize((w // 2, h // 2), Image.NEAREST)
return klein.resize(im.size, Image.NEAREST).tobytes() == im.tobytes()
def soll_bild(quelle: Path) -> Image.Image | None:
im = Image.open(quelle).convert("RGBA")
if not exakt_2x(im):
return None
return im.resize((im.width // 2, im.height // 2), Image.NEAREST)
return a.read_bytes() == b.read_bytes()
def lauf(schreiben: bool) -> list[str]:
@ -70,39 +62,36 @@ def lauf(schreiben: bool) -> list[str]:
if not q.is_dir():
continue
for p in sorted(q.glob("*.png")):
if p.name.startswith(UEBERSPRINGEN):
continue
bild = soll_bild(p)
if bild is None:
fehler.append(f"{p}: kein exakter 2x-Upscale")
if not soll_datei(p.name):
continue
ziel_dir = PROJEKT / ziel
ziel_pfad = ziel_dir / p.name
anzahl += 1
if schreiben:
ziel_dir.mkdir(parents=True, exist_ok=True)
bild.save(ziel_pfad)
elif not ziel_pfad.exists():
fehler.append(f"{ziel_pfad}: fehlt (--write ausfuehren)")
else:
ist = Image.open(ziel_pfad).convert("RGBA")
if ist.size != bild.size or ist.tobytes() != bild.tobytes():
fehler.append(f"{ziel_pfad}: weicht ab")
shutil.copyfile(p, ziel_pfad)
elif not gleich(p, ziel_pfad):
ist = (Image.open(ziel_pfad).size
if ziel_pfad.exists() else "fehlt")
fehler.append(f"{ziel_pfad}: weicht ab (Quelle "
f"{Image.open(p).size}, Kopie {ist})")
for quelle, ziel in KOPIEREN.items():
q = FINAL / quelle
if not q.is_dir():
continue
for p in sorted(q.iterdir()):
if not p.is_file() or p.suffix not in (".fnt", ".png") or "_2x" in p.name:
if (not p.is_file() or p.suffix not in (".fnt", ".png")
or not soll_datei(p.name)):
continue
ziel_dir = PROJEKT / ziel
anzahl += 1
if schreiben:
ziel_dir.mkdir(parents=True, exist_ok=True)
shutil.copyfile(p, ziel_dir / p.name)
elif not (ziel_dir / p.name).exists():
fehler.append(f"{ziel_dir / p.name}: fehlt (--write ausfuehren)")
elif not gleich(p, ziel_dir / p.name):
fehler.append(f"{ziel_dir / p.name}: fehlt oder weicht ab "
f"(--write ausfuehren)")
stand = "geschrieben" if schreiben else "geprueft"
print(f"{anzahl} Dateien {stand} -> {PROJEKT.relative_to(ART.parent)}/")

649
art/tools/ui3.py Normal file
View file

@ -0,0 +1,649 @@
#!/usr/bin/env python3
"""UI-Generator für Taloria bei 3x — 1920x1080-Basis.
Die 640er-Fassung steht in `ui.py`; dieses Werkzeug setzt dieselben Bausteine
im neuen Raster: Linien und Bevel **3 px**, 9-Slice-Rand **6 px**, Fließtext
**Press Start 2P 24** (Vorschub 24, Zeile 36), Titel **Pirata One 36**.
python3 tools/ui3.py # -> final3x/UI/
python3 tools/ui3.py --out /tmp/ui3 # woanders hin
python3 tools/ui3.py --preview # + Bildschirm-Mock in prep/ui3/
Die Dateinamen tragen die Basisgröße bei 1x (z. B.
`ui_dialog_1170x213.png`); die Datei ist genau so groß, weil 1x hier
1920x1080 bedeutet. Es wird **nicht** hochskaliert.
"""
from __future__ import annotations
import argparse
import random
import sys
from pathlib import Path
from PIL import Image, ImageDraw
HERE = Path(__file__).resolve().parent
sys.path.insert(0, str(HERE))
import ui # noqa: E402 (Palette der 640er-Fassung)
from font_ttf import Font # noqa: E402
ART = HERE.parent
FINAL3X = ART / "final3x"
OUT = FINAL3X / "UI"
PREP = ART / "prep" / "ui3"
K = 3 # 1x (640) -> 1x (1920)
B = 3 # Linien und Bevel
SLICE = 2 * B # 9-Slice-Rand: 3 px Linie + 3 px Bevel
UI = Font(FINAL3X / "Font/ttf/PressStart2P-Regular.ttf", 24)
UI.LINE = 36
TITEL = Font(FINAL3X / "Font/ttf/PirataOne-Regular.ttf", 36)
TITEL.LINE = 54
def s(v: int) -> int:
return v * K
def alpha(c, a: int = 255):
return (c[0], c[1], c[2], a)
# ------------------------------------------------------------- Bausteine ----
def panel(d, box, fill=ui.PANEL, line=ui.LINE, bevel=True):
"""Fläche mit 3-px-Bevel (Licht oben links) und 3-px-Rahmenlinie."""
x0, y0, x1, y1 = box
d.rectangle(box, fill=fill)
if bevel:
d.rectangle((x0 + B, y0 + B, x1 - B, y0 + 2 * B - 1),
fill=ui.PANEL_HI)
d.rectangle((x0 + B, y0 + B, x0 + 2 * B - 1, y1 - B),
fill=ui.PANEL_HI)
d.rectangle((x0 + B, y1 - 2 * B + 1, x1 - B, y1 - B),
fill=ui.PANEL_LO)
d.rectangle((x1 - 2 * B + 1, y0 + B, x1 - B, y1 - B),
fill=ui.PANEL_LO)
if line is not None:
d.rectangle(box, outline=line, width=B)
def well(d, box, fill=ui.PANEL_LO):
"""Vertiefte Fläche: 3 px dunkel oben/links, Licht unten/rechts."""
x0, y0, x1, y1 = box
d.rectangle(box, fill=fill)
d.rectangle((x0, y0, x1, y0 + B - 1), fill=ui.INK)
d.rectangle((x0, y0, x0 + B - 1, y1), fill=ui.INK)
d.rectangle((x0, y1 - B + 1, x1, y1), fill=ui.PANEL_HI)
d.rectangle((x1 - B + 1, y0, x1, y1), fill=ui.PANEL_HI)
def title_bar(im, d, box, label):
x0, y0, x1, y1 = box
d.rectangle(box, fill=ui.OCHRE_D)
d.rectangle((x0, y1 - B + 1, x1, y1), fill=ui.INK)
UI.draw_text(im, x0 + s(5), y0 + s(4), label, ui.CREAM)
def bar(im, d, x, y, w, h, label, value, vmax, color):
UI.draw_text(im, x, y + 3, label, ui.CREAM_D)
bx = x + UI.text_width(label) + s(4)
well(d, (bx, y, bx + w - 1, y + h - 1))
fillw = round((w - s(4)) * value / vmax)
if fillw > 0:
d.rectangle((bx + s(2), y + s(2), bx + s(1) + fillw, y + h - s(3)),
fill=color)
d.line((bx + s(2), y + s(2), bx + s(1) + fillw, y + s(2)),
fill=ui.lighter(color, 1.15), width=B)
UI.draw_text(im, bx + w + s(4), y + 3, f"{value}/{vmax}", ui.CREAM_D)
# ---------------------------------------------------------------- Elemente --
def elem_dialog(lines, name, height, w=390) -> Image.Image:
"""Textbox mit Namensschild — `height` bei 1x (66 = 3 Zeilen, 102 = 6)."""
w3, h3 = s(w), s(height + 5)
im = Image.new("RGBA", (w3, h3), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
d.rectangle((0, s(5), w3 - 1, h3 - 1), fill=alpha(ui.PANEL, 238))
d.rectangle((0, s(5), w3 - 1, h3 - 1), outline=ui.INK, width=B)
d.rectangle((B, s(6), w3 - 1 - B, h3 - 1 - B),
outline=ui.LINE, width=B)
d.line((s(2), s(6), w3 - s(3), s(6)), fill=ui.PANEL_LO, width=B)
tw = TITEL.text_width(name) + s(16)
d.rectangle((s(6), 0, s(6) + tw, s(19)), fill=ui.OCHRE_D)
d.rectangle((s(6), 0, s(6) + tw, s(19)), outline=ui.INK, width=B)
d.line((s(7), 3, s(5) + tw, 3), fill=ui.OCHRE, width=B)
TITEL.draw_text(im, s(14), s(4), name, ui.CREAM)
for i, line in enumerate(lines):
UI.draw_text(im, s(11), s(24) + i * UI.LINE, line,
ui.CREAM if i < len(lines) - 1 else ui.CREAM_D)
ax, ay = w3 - s(13), s(height) + 3
for i in range(4):
d.line((ax - i * B, ay - i * B, ax + i * B, ay - i * B),
fill=ui.OCHRE, width=B)
return im
def elem_menu() -> Image.Image:
"""MENU-Knopf oben links: 144x54."""
im = Image.new("RGBA", (s(48), s(18)), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
d.rectangle((0, 0, im.width - 1, im.height - 1),
fill=alpha(ui.PANEL, 232))
d.rectangle((0, 0, im.width - 1, im.height - 1),
outline=ui.LINE, width=B)
UI.draw_text(im, s(7), s(5), "MENU", ui.CREAM)
return im
def elem_buttons() -> Image.Image:
labels = ["ATTACK", "TALK", "USE", "FLEE"]
bw, bh, gap = s(64), s(18), s(6)
im = Image.new("RGBA", (bw, (bh + gap) * 4 + s(4)), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
for i, (label, state) in enumerate(zip(labels, ["idle", "hover",
"pressed", "disabled"])):
y = i * (bh + gap)
tw = UI.text_width(label)
if state == "hover":
panel(d, (0, y, bw - 1, y + bh - 1), fill=ui.OCHRE_D, line=ui.GOLD)
UI.draw_text(im, (bw - tw) // 2, y + s(4), label, ui.CREAM)
elif state == "pressed":
well(d, (0, y, bw - 1, y + bh - 1), fill=(30, 25, 21, 255))
UI.draw_text(im, (bw - tw) // 2 + B, y + s(5), label, ui.CREAM_D)
elif state == "disabled":
panel(d, (0, y, bw - 1, y + bh - 1), fill=(44, 37, 32, 255),
line=(74, 62, 50, 255), bevel=False)
UI.draw_text(im, (bw - tw) // 2, y + s(4), label, (98, 86, 70, 255))
else:
panel(d, (0, y, bw - 1, y + bh - 1))
UI.draw_text(im, (bw - tw) // 2, y + s(4), label, ui.CREAM)
return im
def icon_sword(size: int = 60) -> Image.Image:
im = Image.new("RGBA", (size, size), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
m = size / 20
# Diagonale Klinge — liest sich bei 60 px besser als eine senkrechte Nadel.
d.polygon([(15 * m, 1 * m), (19 * m, 5 * m), (7 * m, 17 * m),
(3 * m, 13 * m)], fill=ui.CREAM)
d.line((17 * m, 3 * m, 5 * m, 15 * m), fill=ui.CREAM_D, width=B)
d.line((2 * m, 14 * m, 9 * m, 7 * m), fill=ui.OCHRE_D, width=2 * B - 1)
d.line((1 * m, 18 * m, 6 * m, 13 * m), fill=ui.INK, width=B)
d.ellipse((0, 16 * m, 4 * m, 20 * m), fill=ui.GOLD)
return im
def icon_herb(size: int = 60) -> Image.Image:
im = Image.new("RGBA", (size, size), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
m = size / 20
d.polygon([(10 * m, 1 * m), (13 * m, 8 * m), (10 * m, 18 * m),
(7 * m, 8 * m)], fill=ui.OLIVE)
d.line((10 * m, 3 * m, 10 * m, 16 * m), fill=ui.OLIVE_D, width=B)
d.line((8 * m, 9 * m, 4 * m, 13 * m), fill=ui.OLIVE_D, width=B)
d.line((12 * m, 9 * m, 16 * m, 13 * m), fill=ui.OLIVE_D, width=B)
return im
def icon_coin(size: int = 60) -> Image.Image:
im = Image.new("RGBA", (size, size), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
m = size / 20
d.ellipse((3 * m, 6 * m, 16 * m, 18 * m), fill=ui.OCHRE)
d.ellipse((4 * m, 7 * m, 15 * m, 17 * m), outline=ui.GOLD, width=B)
return im
def elem_slots() -> Image.Image:
sl, gap = s(26), s(4)
im = Image.new("RGBA", (sl * 6 + gap * 5, sl + s(6)), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
sprites = [None, icon_sword(), icon_herb(), None, icon_coin(), None]
for i, sprite in enumerate(sprites):
x = i * (sl + gap)
well(d, (x, s(3), x + sl - 1, s(3) + sl - 1))
if sprite is not None:
im.alpha_composite(sprite, (x + s(3), s(6)))
if i == 4:
d.rectangle((x, s(3), x + sl - 1, s(3) + sl - 1),
outline=ui.GOLD, width=s(2))
d.rectangle((x + B, s(3) + B, x + sl - 1 - B, s(3) + sl - 1 - B),
outline=ui.GOLD, width=s(2))
d.rectangle((x + s(8), s(16), x + s(24), s(27)), fill=ui.INK)
UI.draw_text(im, x + s(9), s(17), "12", ui.GOLD)
if i == 5:
hatch = Image.new("RGBA", (sl, sl), (0, 0, 0, 0))
hd = ImageDraw.Draw(hatch)
for k in range(-sl, sl, s(6)):
hd.line((k, sl - 1, k + sl - 1, 0),
fill=(54, 46, 38, 255), width=B)
im.alpha_composite(hatch, (x, s(3)))
d.rectangle((x, s(3), x + sl - 1, s(3) + sl - 1),
outline=ui.INK, width=B)
return im
def elem_pack() -> Image.Image:
w, h = s(170), s(132)
im = Image.new("RGBA", (w, h), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
panel(d, (0, 0, w - 1, h - 1), line=ui.INK)
d.rectangle((B, B, w - 1 - B, h - 1 - B), outline=ui.LINE, width=B)
title_bar(im, d, (s(2), s(2), w - s(3), s(18)), "PACK")
d.rectangle((w - s(17), s(5), w - s(5), s(15)), fill=ui.PANEL_LO)
d.rectangle((w - s(17), s(5), w - s(5), s(15)), outline=ui.LINE, width=B)
d.line((w - s(13), s(7), w - s(9), s(11)), fill=ui.CREAM_D, width=B)
d.line((w - s(9), s(7), w - s(13), s(11)), fill=ui.CREAM_D, width=B)
sl, gap, ox, oy = s(26), s(4), s(8), s(24)
for row in range(3):
for col in range(5):
x = ox + col * (sl + gap)
y = oy + row * (sl + gap)
well(d, (x, y, x + sl - 1, y + sl - 1))
UI.draw_text(im, s(8), h - s(14), "LOAD 42/60", ui.CREAM_D)
UI.draw_text(im, w - s(8) - UI.text_width("128 GOLD"), h - s(14),
"128 GOLD", ui.GOLD)
return im
def rune(kind: str) -> Image.Image:
"""Magiesymbole für das Zauberbuch, 42x42."""
im = Image.new("RGBA", (s(14), s(14)), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
m = s(1)
if kind == "fire":
d.polygon([(7 * m, 0), (13 * m, 7 * m), (11 * m, 13 * m),
(3 * m, 13 * m), (1 * m, 7 * m)], fill=ui.BLOOD)
d.polygon([(7 * m, 5 * m), (10 * m, 8 * m), (9 * m, 12 * m),
(5 * m, 12 * m), (4 * m, 8 * m)], fill=ui.GOLD)
elif kind == "ice":
d.polygon([(7 * m, 0), (13 * m, 7 * m), (7 * m, 13 * m),
(1 * m, 7 * m)], fill=ui.SLATE)
d.polygon([(7 * m, 3 * m), (10 * m, 7 * m), (7 * m, 11 * m),
(4 * m, 7 * m)], fill=ui.CREAM)
elif kind == "bolt":
d.polygon([(9 * m, 0), (3 * m, 7 * m), (6 * m, 7 * m),
(4 * m, 13 * m), (11 * m, 5 * m), (8 * m, 5 * m)],
fill=ui.GOLD)
elif kind == "ward":
d.ellipse((m, m, 13 * m, 13 * m), outline=ui.CREAM, width=B)
d.line((7 * m, 3 * m, 7 * m, 10 * m), fill=ui.CREAM, width=B)
d.line((4 * m, 6 * m, 10 * m, 6 * m), fill=ui.CREAM, width=B)
elif kind == "eye":
d.ellipse((m, 4 * m, 13 * m, 10 * m), fill=ui.CREAM)
d.ellipse((5 * m, 5 * m, 9 * m, 9 * m), fill=ui.INK)
elif kind == "leaf":
d.polygon([(7 * m, 0), (12 * m, 7 * m), (7 * m, 13 * m),
(2 * m, 7 * m)], fill=ui.OLIVE)
d.line((7 * m, 2 * m, 7 * m, 11 * m), fill=ui.OLIVE_D, width=B)
elif kind == "star":
d.polygon([(7 * m, 0), (8 * m, 5 * m), (13 * m, 7 * m),
(8 * m, 8 * m), (7 * m, 13 * m), (6 * m, 8 * m),
(m, 7 * m), (6 * m, 5 * m)], fill=ui.GOLD)
elif kind == "skull":
d.rectangle((3 * m, m, 10 * m, 8 * m), fill=ui.CREAM)
d.rectangle((4 * m, 9 * m, 9 * m, 11 * m), fill=ui.CREAM)
d.rectangle((5 * m, 4 * m, 6 * m, 6 * m), fill=ui.INK)
d.rectangle((8 * m, 4 * m, 9 * m, 6 * m), fill=ui.INK)
d.rectangle((6 * m, 6 * m, 7 * m, 8 * m), fill=ui.INK)
return im
def elem_spells() -> Image.Image:
w, h = s(170), s(140)
im = Image.new("RGBA", (w, h), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
panel(d, (0, 0, w - 1, h - 1), line=ui.INK)
d.rectangle((B, B, w - 1 - B, h - 1 - B), outline=ui.LINE, width=B)
title_bar(im, d, (s(2), s(2), w - s(3), s(18)), "SPELLBOOK")
for i, (label, active) in enumerate([("ARCANE", True),
("DIVINE", False)]):
x = s(6) + i * s(62)
panel(d, (x, s(22), x + s(57), s(38)),
fill=ui.OCHRE_D if active else ui.PANEL_LO,
line=ui.GOLD if active else ui.LINE, bevel=not active)
UI.draw_text(im, x + s(5), s(26), label,
ui.CREAM if active else ui.CREAM_D)
spells = [("fire", 3), ("ice", 2), ("bolt", 2), ("ward", 1), ("eye", 4),
("leaf", 1), ("star", 3), (None, 0), (None, 0), (None, 0),
(None, 0), (None, 0), (None, 0), (None, 0), (None, 0)]
sl, gap, ox, oy = s(20), s(4), s(16), s(44)
for idx, (kind, cost) in enumerate(spells):
col, row = idx % 5, idx // 5
x = ox + col * (sl + gap)
y = oy + row * (sl + gap)
well(d, (x, y, x + sl - 1, y + sl - 1))
if kind:
im.alpha_composite(rune(kind), (x + s(3), y + s(3)))
d.rectangle((x + s(11), y + s(10), x + s(19), y + s(19)),
fill=ui.INK)
UI.draw_text(im, x + s(12), y + s(10), str(cost), ui.GOLD)
if idx == 0:
d.rectangle((x, y, x + sl - 1, y + sl - 1),
outline=ui.GOLD, width=s(2))
d.rectangle((x + B, y + B, x + sl - 1 - B, y + sl - 1 - B),
outline=ui.GOLD, width=s(2))
UI.draw_text(im, s(8), h - s(14), "MEM 3/6 SLOTS", ui.CREAM_D)
UI.draw_text(im, w - s(8) - UI.text_width("LVL 4"), h - s(14),
"LVL 4", ui.GOLD)
return im
def party_portraits(size: int = 96) -> list[Image.Image] | None:
names = ("krieger", "magierin", "zwerg", "elfin", "halbling", "gelehrter")
paths = [FINAL3X / "Players" / f"portrait_{n}_96px.png" for n in names]
if not all(p.exists() for p in paths):
return None
return [Image.open(p).convert("RGBA").resize((size, size), Image.NEAREST)
for p in paths]
def elem_party(portraits=None, count: int = 6, fw: int = 120,
fh: int = 126, psize: int = 96) -> Image.Image:
gap = 12
im = Image.new("RGBA", (fw, fh * count + gap * (count - 1)),
(0, 0, 0, 0))
d = ImageDraw.Draw(im)
hp = [(176, 140, 108, 255), (156, 122, 94, 255)]
for i in range(count):
y = i * (fh + gap)
panel(d, (0, y, fw - 1, y + fh - 1))
d.rectangle((9, y + 9, fw - 10, y + fh - 18), fill=ui.PANEL_LO)
if portraits and i < len(portraits):
im.alpha_composite(portraits[i], (12, y + 12))
bw = round((fw - 30) * (0.72 if i % 2 == 0 else 0.52))
by = y + fh - 15
d.rectangle((12, by, 12 + bw, by + 8), fill=hp[i % 2])
d.rectangle((9, by - 3, fw - 10, by + 9), outline=ui.INK, width=B)
if i == 0:
d.rectangle((0, y, fw - 1, y + fh - 1),
outline=ui.GOLD, width=B)
return im
def elem_misc() -> Image.Image:
im = Image.new("RGBA", (s(220), s(130)), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
bar(im, d, 0, 0, s(120), s(12), "HP", 24, 30, ui.BLOOD)
bar(im, d, 0, s(16), s(120), s(12), "SP", 11, 20, ui.OLIVE)
bar(im, d, 0, s(32), s(120), s(12), "MP", 3, 15, ui.SLATE)
for i, on in enumerate([False, True]):
x = s(188) + i * s(18)
well(d, (x, s(2), x + s(13), s(15)))
if on:
d.line((x + s(3), s(8), x + s(6), s(12)), fill=ui.GOLD, width=B)
d.line((x + s(6), s(12), x + s(10), s(4)), fill=ui.GOLD, width=B)
sx, sy = 0, s(70)
UI.draw_text(im, sx, s(52), "VOLUME", ui.CREAM_D)
well(d, (sx, sy, sx + s(100), sy + s(7)))
d.rectangle((sx + s(2), sy + s(2), sx + s(54), sy + s(5)),
fill=ui.OCHRE_D)
panel(d, (sx + s(51), sy - s(4), sx + s(59), sy + s(11)), bevel=False)
panel(d, (s(110), s(50), s(218), s(86)),
fill=alpha((30, 25, 21, 255), 246), line=ui.INK)
UI.draw_text(im, s(116), s(54), "RUSTY SWORD", ui.CREAM)
UI.draw_text(im, s(116), s(66), "1D6+1 SLASH", ui.CREAM_D)
UI.draw_text(im, s(116), s(78), "10 GOLD", ui.GOLD)
cx, cy = s(180), s(98)
d.polygon([(cx, cy), (cx + s(11), cy + s(4)), (cx + s(5), cy + s(6)),
(cx + s(8), cy + s(12)), (cx + s(5), cy + s(13)),
(cx + s(3), cy + s(7)), (cx, cy + s(7))],
fill=ui.CREAM, outline=ui.INK, width=B)
return im
def elem_combat() -> Image.Image:
w, h = s(400), s(56)
im = Image.new("RGBA", (w, h), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
chips = [ui.SLATE, ui.SLATE, ui.BLOOD, ui.GOLD, ui.SLATE, ui.BLOOD,
ui.SLATE, ui.BLOOD]
for i, fill in enumerate(chips):
x = s(6) + i * s(14)
d.rectangle((x, s(2), x + s(9), s(11)), fill=fill)
d.rectangle((x, s(2), x + s(9), s(11)),
outline=ui.GOLD if fill == ui.GOLD else ui.INK, width=B)
UI.draw_text(im, s(134), s(2), "RND 3", ui.CREAM_D)
panel(d, (0, s(17), w - 1, h - 1), fill=alpha(ui.PANEL, 236),
line=ui.INK)
labels = ["ATTACK", "MOVE", "SPELL", "ITEM", "DEFEND", "END TURN"]
x = s(6)
for label in labels:
bw = UI.text_width(label) + s(14)
panel(d, (x, s(23), x + bw - 1, s(49)),
fill=ui.OCHRE_D if label == "SPELL" else ui.PANEL,
line=ui.GOLD if label == "SPELL" else ui.LINE)
UI.draw_text(im, x + s(7), s(31), label,
ui.CREAM if label == "SPELL" else ui.CREAM_D)
x += bw + s(4)
return im
def elem_loadbar() -> Image.Image:
w, h = s(240), s(26)
im = Image.new("RGBA", (w, h), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
UI.draw_text(im, 0, 0, "LOADING THE HARBOUR", ui.CREAM_D)
UI.draw_text(im, w - UI.text_width("62%") - 3, 0, "62%", ui.CREAM_D)
well(d, (0, s(14), w - 1, h - 1))
fillw = round((w - s(4)) * 0.62)
d.rectangle((s(2), s(16), s(1) + fillw, h - s(2)), fill=ui.OCHRE_D)
d.line((s(2), s(16), s(1) + fillw, s(16)), fill=ui.OCHRE, width=B)
for k in range(1, 10):
x = s(2) + round((w - s(4)) * k / 10)
d.line((x, s(16), x, h - s(2)), fill=alpha(ui.INK, 150), width=B)
return im
def elem_panel_slice(size: int = 36) -> Image.Image:
im = Image.new("RGBA", (size, size), (0, 0, 0, 0))
panel(ImageDraw.Draw(im), (0, 0, size - 1, size - 1))
return im
def palette_anchor() -> Image.Image:
"""UI-Palette als PNG (16 Felder à 24 px)."""
im = Image.new("RGB", (s(32), s(32)), ui.INK[:3])
for i, c in enumerate(ui.PALETTE[:16]):
x, y = (i % 4) * s(8), (i // 4) * s(8)
ImageDraw.Draw(im).rectangle((x, y, x + s(8) - 1, y + s(8) - 1),
fill=c[:3])
return im
# ------------------------------------------------------------------ Ausgabe --
def save(im: Image.Image, out: Path, name: str) -> None:
out.mkdir(parents=True, exist_ok=True)
im.save(out / f"{name}.png")
px = list(im.getdata())
colors = len({p[:3] for p in px if len(p) < 4 or p[3] > 0})
print(f"{name:28s} {im.width:4d}x{im.height:<4d} {colors:5d} Farben")
def elemente() -> dict[str, Image.Image]:
return {
"ui_dialog_1170x213": elem_dialog(
["VALYRIA ZAHLT IN FERRUM, NICHT IN GOLD.",
"WAS WOLLT IHR IN GARANA?"], "WACHE", 66),
"ui_dialog_gross_1170x321": elem_dialog(
["DER HAFEN IST HEUTE NACHT STILL. ZU STILL",
"FÜR EINE STADT, DIE NACH SALZ UND EISEN",
"RIECHT. DIE LATERNE SCHWINGT, DIE MÖWEN",
"SIND FORT, UND DIE FLUT KOMMT UNTER DEN",
"KAI. ETWAS STIMMT NICHT MIT DEM WASSER,",
"UND NIEMAND SAGT, WAS ES IST."],
"ALDRIC DER GRAUE", 102),
"ui_menu_144x54": elem_menu(),
"ui_buttons_192x54": elem_buttons(),
"ui_slots_78px": elem_slots(),
"ui_window_pack_510x396": elem_pack(),
"ui_window_zauber_510x420": elem_spells(),
"ui_party_120px": elem_party(party_portraits()),
"ui_misc_660x390": elem_misc(),
"ui_kampf_leiste_1200x168": elem_combat(),
"ui_ladebalken_720x78": elem_loadbar(),
"ui_panel_9slice_36px": elem_panel_slice(),
}
def vorschau(el: dict[str, Image.Image], out_dir: Path) -> None:
"""Bildschirm-Mock: 1920x1080, nur Assets aus final3x."""
T, COLS, ROWS = 96, 20, 12
rnd = random.Random(5)
erde = [Image.open(FINAL3X / "Terrain" / f"boden_erde_{i}_96px.png")
.convert("RGBA") for i in (1, 2, 3, 4)]
wand = Image.open(FINAL3X / "Terrain/wand_stein_96px.png").convert("RGBA")
dach = Image.open(FINAL3X / "Terrain/dach_fachwerk_96px.png").convert("RGBA")
gras = Image.open(FINAL3X / "Terrain/battle_gras_96px.png").convert("RGBA")
grid = [["." for _ in range(COLS)] for _ in range(ROWS)]
for x in range(COLS):
grid[0][x] = grid[ROWS - 1][x] = "#"
for y in range(ROWS):
grid[y][0] = grid[y][COLS - 1] = "#"
grid[ROWS - 1][9] = "."
for (x0, y0, x1, y1) in ((4, 1, 7, 4), (12, 1, 17, 4),
(4, 8, 7, 10), (12, 8, 17, 10)):
for y in range(y0, y1 + 1):
for x in range(x0, x1 + 1):
grid[y][x] = "B"
for (x, y) in ((6, 4), (14, 4), (6, 8), (14, 8)):
grid[y][x] = "D"
for y in range(6, 8):
for x in range(8, 12):
grid[y][x] = "g"
im = Image.new("RGBA", (COLS * T, ROWS * T))
for y in range(ROWS):
for x in range(COLS):
k = grid[y][x]
tile = {".": rnd.choice(erde), "#": wand, "B": dach, "D": dach,
"g": gras}[k]
im.paste(tile, (x * T, y * T))
d = ImageDraw.Draw(im)
for y in range(ROWS):
for x in range(COLS):
if grid[y][x] in "#B":
if y + 1 < ROWS and grid[y + 1][x] not in "#B":
d.rectangle((x * T, (y + 1) * T, x * T + T - 1,
(y + 1) * T + 5), fill=(0, 0, 0, 80))
if x + 1 < COLS and grid[y][x + 1] not in "#B":
d.rectangle(((x + 1) * T, y * T, (x + 1) * T + 5,
y * T + T - 1), fill=(0, 0, 0, 55))
props = [("brunnen", 2, 6), ("wagen", 7, 5), ("tisch", 9, 6),
("fass", 3, 5), ("kiste", 4, 5), ("fass", 18, 5),
("grabstein", 17, 2), ("tuer", 6, 4), ("tuer", 14, 4),
("tuer", 6, 8), ("tuer", 14, 8)]
for name, x, y in props:
p = Image.open(FINAL3X / "Objects" / f"objekt_{name}_96px.png")
im.alpha_composite(p.convert("RGBA"), (x * T, y * T))
npcs = {"dorfbewohner": (2, 2), "dorfbewohnerin": (9, 5),
"wache": (10, 10), "haendler": (14, 5), "druide": (2, 9)}
for name, (x, y) in npcs.items():
p = Image.open(FINAL3X / "NPCs" / f"nsc_{name}_96px.png")
im.alpha_composite(p.convert("RGBA"), (x * T, y * T - 24))
im = im.crop((0, 0, 1920, 1080))
im.alpha_composite(el["ui_menu_144x54"], (24, 24))
party = el["ui_party_120px"]
im.alpha_composite(party, (1920 - party.width - 12, 24))
dialog = el["ui_dialog_1170x213"]
im.alpha_composite(dialog, (24, 1080 - dialog.height - 24))
out_dir.mkdir(parents=True, exist_ok=True)
im.convert("RGB").save(out_dir / "_bildschirm_1920x1080.png")
print(f"{out_dir / '_bildschirm_1920x1080.png'}")
def neun_slice(im: Image.Image, size: tuple[int, int],
border: int = SLICE) -> Image.Image:
"""9-Slice-Vorschau: Ecken bleiben, Kanten und Kern werden gestreckt."""
w, h = size
b = border
w0, h0 = im.size
out = Image.new("RGBA", (w, h), (0, 0, 0, 0))
for sx, dx in ((0, 0), (w0 - b, w - b)):
for sy, dy in ((0, 0), (h0 - b, h - b)):
out.paste(im.crop((sx, sy, sx + b, sy + b)), (dx, dy))
out.paste(im.crop((b, 0, w0 - b, b)).resize((w - 2 * b, b),
Image.NEAREST), (b, 0))
out.paste(im.crop((b, h0 - b, w0 - b, h0)).resize((w - 2 * b, b),
Image.NEAREST), (b, h - b))
out.paste(im.crop((0, b, b, h0 - b)).resize((b, h - 2 * b),
Image.NEAREST), (0, b))
out.paste(im.crop((w0 - b, b, w0, h0 - b)).resize((b, h - 2 * b),
Image.NEAREST), (w - b, b))
out.paste(im.crop((b, b, w0 - b, h0 - b)).resize((w - 2 * b, h - 2 * b),
Image.NEAREST), (b, b))
return out
def uebersicht(el: dict[str, Image.Image], out_dir: Path) -> None:
"""Belegblatt aller Elemente, 1:1, mit Beschriftung."""
W = 1920
sheet = Image.new("RGBA", (W, 1620), alpha(ui.INK))
d = ImageDraw.Draw(sheet)
def put(name: str, x: int, y: int, label: str | None = None) -> int:
UI.draw_text(sheet, x, y - 40, label or name, ui.CREAM_D)
sheet.alpha_composite(el[name], (x, y))
return y + el[name].height
put("ui_dialog_1170x213", 48, 90, "dialog 1170x213")
put("ui_dialog_gross_1170x321", 48, 360, "dialog gross 1170x321")
put("ui_kampf_leiste_1200x168", 48, 740, "kampfleiste 1200x168")
put("ui_ladebalken_720x78", 48, 960, "ladebalken 720x78")
put("ui_menu_144x54", 48, 1090, "menu 144x54")
put("ui_panel_9slice_36px", 400, 1090, "9-slice 36x36 -> 144x108")
sheet.alpha_composite(neun_slice(el["ui_panel_9slice_36px"], (144, 108)),
(460, 1090))
put("ui_misc_660x390", 48, 1200, "misc 660x390")
put("ui_buttons_192x54", 1460, 90, "buttons 192x54")
put("ui_slots_78px", 1300, 530, "slots 78x78")
put("ui_window_zauber_510x420", 1300, 700, "zauberbuch 510x420")
put("ui_window_pack_510x396", 1300, 1180, "pack 510x396")
out_dir.mkdir(parents=True, exist_ok=True)
sheet.convert("RGB").save(out_dir / "_elemente.png")
print(f"{out_dir / '_elemente.png'}")
def main(argv=None) -> int:
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--out", type=Path, default=OUT)
ap.add_argument("--preview", action="store_true",
help="auch Bildschirm-Mock und Elementblatt in prep/ui3/")
a = ap.parse_args(argv)
el = elemente()
for name, im in el.items():
save(im, a.out, name)
save(palette_anchor(), a.out, "_palette_ui")
if a.preview:
vorschau(el, PREP)
uebersicht(el, PREP)
return 0
if __name__ == "__main__":
sys.exit(main())

View file

@ -1,16 +1,17 @@
#!/usr/bin/env python3
"""ui_slice.py - 9-Slice-Panel aus ui.py pruefen und als Blatt zeigen.
"""ui_slice.py - 9-Slice-Panel pruefen und als Blatt zeigen.
`tools/ui.py` zeichnet Panels prozedural (`panel()`). Fuer die Engine wird
dasselbe als **9-Slice-Textur** ausgeliefert
(`final/UI/ui_panel_9slice_12px.png`, Rand 2 px bei 1x), damit ein
`NinePatchRect` in Godot jedes Fenster ohne eigene Zeichenroutine fuellt.
`tools/ui.py` (640er) und `tools/ui3.py` (1920er) zeichnen Panels prozedural.
Fuer die Engine wird dasselbe als **9-Slice-Textur** ausgeliefert
(`final3x/UI/ui_panel_9slice_36px.png`, Rand 6 px) und in Godot von einem
`NinePatchRect` gestreckt.
Dieses Werkzeug beweist, dass die Textur stimmt: es setzt Panels aus den neun
Teilen zusammen und vergleicht sie Pixel fuer Pixel mit `panel()`.
python3 tools/ui_slice.py # pruefen + Blatt nach prep/ui-slice/
python3 tools/ui_slice.py --check # nur pruefen (Exit 1 bei Abweichung)
python3 tools/ui_slice.py # 1920er-Satz pruefen + Blatt
python3 tools/ui_slice.py --basis 640 # alte 640er-Fassung
python3 tools/ui_slice.py --check # nur pruefen (Exit 1)
"""
from __future__ import annotations
@ -23,17 +24,40 @@ from PIL import Image, ImageDraw
ART = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ART / "tools"))
import ui # noqa: E402
import ui3 # noqa: E402
M = ui.PANEL_SLICE
# Groessen aus docs/ui.md: Dialog, Kampf-Log, Handelsfenster, Leiste, Minimum
GROESSEN = [(4, 4), (12, 12), (24, 16), (170, 132), (228, 56), (390, 71),
(400, 56)]
# Groessen aus docs/ui.md; Minimum = 2 x Rand.
BASIS = {
"1920": {
"mod": ui3,
"rand": 6,
"textur": ui3.elem_panel_slice(36),
"groessen": [(12, 12), (36, 36), (72, 48), (510, 396), (684, 168),
(1170, 213), (1200, 168)],
"out": ART / "prep" / "ui3",
"blatt": "_panel_probe_1200x620.png",
"titel": "9-SLICE PANEL 3X - GEGENPROBE",
"zeilen": [("510x96", 510, 96), ("684x168", 684, 168),
("1170x213", 1170, 213)],
},
"640": {
"mod": ui,
"rand": 2,
"textur": ui.elem_panel_slice(),
"groessen": [(4, 4), (12, 12), (24, 16), (170, 132), (228, 56),
(390, 71), (400, 56)],
"out": ART / "prep" / "ui-slice",
"blatt": "_panel_probe_420x212.png",
"titel": "9-SLICE PANEL - GEGENPROBE",
"zeilen": [("390x71", 390, 71), ("228x56", 228, 56),
("170x52", 170, 52)],
},
}
def neun(textur: Image.Image, w: int, h: int) -> Image.Image:
def neun(textur: Image.Image, w: int, h: int, m: int) -> Image.Image:
"""Panel aus neun Teilen bauen, wie ein NinePatchRect es tut (nearest)."""
s = textur.width
m = M
out = Image.new("RGBA", (w, h), (0, 0, 0, 0))
wm, hm = w - 2 * m, h - 2 * m
@ -43,7 +67,6 @@ def neun(textur: Image.Image, w: int, h: int) -> Image.Image:
teil = teil.resize(ziel, Image.NEAREST)
out.paste(teil, ziel_box)
# Ecken bleiben 1:1
out.paste(textur.crop((0, 0, m, m)), (0, 0))
out.paste(textur.crop((s - m, 0, s, m)), (w - m, 0))
out.paste(textur.crop((0, s - m, m, s)), (0, h - m))
@ -59,52 +82,64 @@ def neun(textur: Image.Image, w: int, h: int) -> Image.Image:
return out
def soll(w: int, h: int) -> Image.Image:
def soll(mod, w: int, h: int) -> Image.Image:
im = Image.new("RGBA", (w, h), (0, 0, 0, 0))
ui.panel(ImageDraw.Draw(im), (0, 0, w - 1, h - 1))
mod.panel(ImageDraw.Draw(im), (0, 0, w - 1, h - 1))
return im
def main(argv: list[str] | None = None) -> int:
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--basis", choices=sorted(BASIS), default="1920")
ap.add_argument("--check", action="store_true", help="nur pruefen, kein Blatt")
a = ap.parse_args(argv)
b = BASIS[a.basis]
mod, m, textur = b["mod"], b["rand"], b["textur"]
textur = ui.elem_panel_slice()
fehler = []
for w, h in GROESSEN:
ist, ref = neun(textur, w, h), soll(w, h)
for w, h in b["groessen"]:
ist, ref = neun(textur, w, h, m), soll(mod, w, h)
gleich = ist.tobytes() == ref.tobytes()
print(f" {w:4d}x{h:<4d} {'pixelgleich' if gleich else 'ABWEICHUNG'}")
if not gleich:
fehler.append(f"{w}x{h}")
if not a.check:
blatt = Image.new("RGBA", (420, 212), (24, 20, 17, 255))
d = ImageDraw.Draw(blatt)
ui.draw_text(d, 6, 4, "9-SLICE PANEL - GEGENPROBE", ui.OCHRE)
# Reihe 1: die breite Dialogbox, Reihe 2: Log und Handelsfenster
ui.draw_text(d, 6, 16, "390x71", ui.CREAM_D)
blatt.alpha_composite(neun(textur, 390, 71), (6, 28))
ui.draw_text(d, 6, 103, "228x56", ui.CREAM_D)
blatt.alpha_composite(neun(textur, 228, 56), (6, 115))
ui.draw_text(d, 242, 103, "170x52", ui.CREAM_D)
blatt.alpha_composite(neun(textur, 170, 52), (242, 115))
ui.draw_text(d, 6, 178, f"TEXTUR {textur.width}x{textur.height}, RAND {M} PX (1X)",
ui.CREAM)
ui.draw_text(d, 6, 194, "GODOT: NINEPATCHRECT, MARGIN 2 (1X) / 4 (2X)",
ui.CREAM_D)
out = ART / "prep" / "ui-slice"
if a.basis == "1920":
blatt = Image.new("RGBA", (1200, 620), (92, 82, 70, 255))
d = ImageDraw.Draw(blatt)
ui3.UI.draw_text(blatt, 12, 8, b["titel"], ui.CREAM)
y = 50
for label, w, h in b["zeilen"]:
ui3.UI.draw_text(blatt, 12, y, label, ui.CREAM)
blatt.alpha_composite(neun(textur, w, h, m), (12, y + 30))
y += h + 80
ui3.UI.draw_text(blatt, 12, 590, "TEXTUR 36x36, RAND 6 PX (1:1)",
ui.CREAM_D)
else:
blatt = Image.new("RGBA", (420, 212), (24, 20, 17, 255))
d = ImageDraw.Draw(blatt)
ui.draw_text(d, 6, 4, b["titel"], ui.OCHRE)
ui.draw_text(d, 6, 16, "390x71", ui.CREAM_D)
blatt.alpha_composite(neun(textur, 390, 71, m), (6, 28))
ui.draw_text(d, 6, 103, "228x56", ui.CREAM_D)
blatt.alpha_composite(neun(textur, 228, 56, m), (6, 115))
ui.draw_text(d, 242, 103, "170x52", ui.CREAM_D)
blatt.alpha_composite(neun(textur, 170, 52, m), (242, 115))
ui.draw_text(d, 6, 178,
f"TEXTUR {textur.width}x{textur.height}, RAND {m} PX (1X)",
ui.CREAM)
ui.draw_text(d, 6, 194,
"GODOT: NINEPATCHRECT, MARGIN 2 (1X) / 4 (2X)",
ui.CREAM_D)
out = b["out"]
out.mkdir(parents=True, exist_ok=True)
blatt.save(out / "_panel_probe_420x212.png")
blatt.resize((840, 424), Image.NEAREST).save(
out / "_panel_probe_840x424.png")
print(f"{out}/_panel_probe_420x212.png (+2x)")
blatt.save(out / b["blatt"])
print(f"{out / b['blatt']}")
if fehler:
print(f"\n{len(fehler)} Abweichungen: {', '.join(fehler)}", file=sys.stderr)
print(f"\n{len(fehler)} Abweichungen: {', '.join(fehler)}",
file=sys.stderr)
return 1
print("\nAlle Groessen pixelgleich.")
return 0