taloria/art/tools/ui.py
torsten bf7bd44d2d docs/: Projektbeschreibung, Roadmap und Basisauflösung 640×360
Projektbeschreibung (docs/projekt.md): Retro-CRPG in Erstperson-Ansicht,
Party, Overland-Karte, rundenbasierter Rasterkampf; Schauplatz Königreich
Taloria aus dem Westreiche-Kanon (Kanon bleibt im Vault, Spiel-Abweichungen
werden hier notiert); Grafik verbindlich hybrid (A für Sprites/UI/Terrain,
B für Pictures); Engine/Systeme zuerst, Inhalte danach.

Roadmap (docs/roadmap.md): Phase 0 — Stil, UI und Systeme festlegen — steht
vor Engine und Content. Darin §0.0 Basisauflösung als erste Entscheidung,
weil sie Textmenge, Kampfraster, Kachelzahl und Sprite-Wirkung gleichzeitig
festlegt.

Basisauflösung entschieden (14.11.2026): 640×360, Ausgabe 1280×720 (2×)
bzw. 1920×1080 (3×), nearest und ganzzahlig auf beiden Zielen. Nicht aus
"16:9 passt", sondern aus einer Gegenprobe: bei 320×180 sind 3 von 8
Dialogzeilen sichtbar und das Kampfraster hat 8×3 Felder, bei 640×360 alle
Zeilen und 18×9 Felder — ein Bewegungsradius von 2 deckt dort 9 % statt
63 % des Feldes.

- art/tools/ui_probe.py: die Gegenprobe als Werkzeug (Dialog + Kampf bei
  320×180 und 640×360, gleiche Elementgrößen, Vergleichsblätter auf
  gleicher Schirmgröße)
- art/prep/aufloesung/: die sechs Bilder, auf die sich die Entscheidung
  stützt
- art/WORKFLOW.md §0: Zielformat 640×360, --upscale 2; §9.1 geschlossen
- art/README.md + art/final/*/README.md: Ausgabegrößen auf 2×, Hinweis auf
  den ausstehenden Nachlauf der noch 4×-Dateien
- art/tools/ui.py: elem_dialog nimmt die Breite als Parameter (Ausgabe der
  bestehenden UI-Assets geprüft: pixelgleich)

Bewusst offen (0.1/0.2): Kachelgröße 32 vs. 64 px, Sprite-Basis 96 vs. 192,
Font 5×7 vs. 8×10 — die Auflösung ist entschieden, die Elementgröße darin
nicht.
2026-11-14 20:36:02 +01:00

570 lines
22 KiB
Python

#!/usr/bin/env python3
"""UI-Generator für Taloria — prozedural gezeichnet, 1x = 320x180-Maßstab.
UI ist Linienarbeit: 1-px-Bevel, 2-px-Rahmen, harte Kanten. Ein
Diffusionsmodell liefert dort Farbverläufe und ausgefranste Kanten, die beim
Herunterrechnen wegbrechen. Deshalb wird hier gezeichnet, nicht generiert,
und zwar direkt bei 1x; ausgeliefert wird mit nearest 4x.
python3 tools/ui.py # -> final/UI/, 4x (1280x720)
python3 tools/ui.py --scale 1 # -> Basisgrößen, 1x
python3 tools/ui.py --out /tmp/ui # woanders hin
Die Dateinamen tragen die **Basisgröße** (z. B. ui_dialog_292x59.png =
292x59 bei 1x, 1168x236 in der Datei) — dieselbe Regel wie
monster_wolf_96px.png in final/Creatures/.
"""
from __future__ import annotations
import argparse
from pathlib import Path
from PIL import Image, ImageDraw
ART = Path(__file__).resolve().parent.parent
FINAL = ART / "final"
SCENE_B = FINAL / "Pictures" / "taverne_B_1280x720.png"
SCENE_A = FINAL / "Pictures" / "taverne_A_1280x720.png"
SWORD = FINAL / "Objects" / "objekt_schwert_32px.png"
# ---------------------------------------------------------------- Palette (16)
INK = (26, 21, 18, 255) # fast schwarz, warm
PANEL = (58, 47, 39, 255) # umber, Fläche
PANEL_HI = (84, 69, 54, 255) # Bevel oben/links
PANEL_LO = (39, 32, 27, 255) # Bevel unten/rechts, vertiefte Fläche
LINE = (124, 103, 78, 255) # 1-px-Rahmenlinie
CREAM = (226, 209, 176, 255) # Text, hellste Fläche
CREAM_D = (176, 160, 130, 255) # sekundärer Text
OCHRE = (178, 138, 74, 255) # Akzent
OCHRE_D = (122, 90, 46, 255) # Akzent dunkel, Titelleiste
GOLD = (216, 180, 104, 255) # Fokus, Auswahl, Hover
SLATE = (76, 94, 106, 255)
SLATE_D = (46, 60, 70, 255)
OLIVE = (108, 114, 66, 255)
OLIVE_D = (72, 78, 44, 255)
BLOOD = (150, 58, 46, 255)
PALETTE = [INK, PANEL, PANEL_HI, PANEL_LO, LINE, CREAM, CREAM_D, OCHRE,
OCHRE_D, GOLD, SLATE, SLATE_D, OLIVE, OLIVE_D, BLOOD]
# -------------------------------------------------------------- Font 5x7
FONT = {
"A": ".###.|#...#|#...#|#####|#...#|#...#|#...#",
"B": "####.|#...#|#...#|####.|#...#|#...#|####.",
"C": ".####|#....|#....|#....|#....|#....|.####",
"D": "####.|#...#|#...#|#...#|#...#|#...#|####.",
"E": "#####|#....|#....|####.|#....|#....|#####",
"F": "#####|#....|#....|####.|#....|#....|#....",
"G": ".####|#....|#....|#..##|#...#|#...#|.###.",
"H": "#...#|#...#|#...#|#####|#...#|#...#|#...#",
"I": "#####|..#..|..#..|..#..|..#..|..#..|#####",
"J": "..###|...#.|...#.|...#.|...#.|#..#.|.##..",
"K": "#...#|#..#.|#.#..|##...|#.#..|#..#.|#...#",
"L": "#....|#....|#....|#....|#....|#....|#####",
"M": "#...#|##.##|#.#.#|#.#.#|#...#|#...#|#...#",
"N": "#...#|##..#|#.#.#|#.#.#|#..##|#...#|#...#",
"O": ".###.|#...#|#...#|#...#|#...#|#...#|.###.",
"P": "####.|#...#|#...#|####.|#....|#....|#....",
"Q": ".###.|#...#|#...#|#...#|#.#.#|#..#.|.##.#",
"R": "####.|#...#|#...#|####.|#.#..|#..#.|#...#",
"S": ".####|#....|#....|.###.|....#|....#|####.",
"T": "#####|..#..|..#..|..#..|..#..|..#..|..#..",
"U": "#...#|#...#|#...#|#...#|#...#|#...#|.###.",
"V": "#...#|#...#|#...#|#...#|#...#|.#.#.|..#..",
"W": "#...#|#...#|#...#|#.#.#|#.#.#|##.##|#...#",
"X": "#...#|#...#|.#.#.|..#..|.#.#.|#...#|#...#",
"Y": "#...#|#...#|.#.#.|..#..|..#..|..#..|..#..",
"Z": "#####|....#|...#.|..#..|.#...|#....|#####",
"0": ".###.|#...#|#..##|#.#.#|##..#|#...#|.###.",
"1": "..#..|.##..|..#..|..#..|..#..|..#..|.###.",
"2": ".###.|#...#|....#|...#.|..#..|.#...|#####",
"3": "####.|....#|....#|.###.|....#|....#|####.",
"4": "...#.|..##.|.#.#.|#..#.|#####|...#.|...#.",
"5": "#####|#....|####.|....#|....#|#...#|.###.",
"6": "..##.|.#...|#....|####.|#...#|#...#|.###.",
"7": "#####|....#|...#.|..#..|.#...|.#...|.#...",
"8": ".###.|#...#|#...#|.###.|#...#|#...#|.###.",
"9": ".###.|#...#|#...#|.####|....#|...#.|.##..",
".": ".....|.....|.....|.....|.....|.##..|.##..",
",": ".....|.....|.....|.....|.##..|.##..|.#...",
"/": "....#|....#|...#.|..#..|.#...|#....|#....",
":": ".....|.##..|.##..|.....|.##..|.##..|.....",
"-": ".....|.....|.....|#####|.....|.....|.....",
"!": "..#..|..#..|..#..|..#..|..#..|.....|..#..",
"?": ".###.|#...#|....#|...#.|..#..|.....|..#..",
"+": ".....|..#..|..#..|#####|..#..|..#..|.....",
"'": "..#..|..#..|.....|.....|.....|.....|.....",
}
def alpha(c, a: int = 255):
return (c[0], c[1], c[2], a)
def darker(c, f: float = 0.72):
return alpha(tuple(int(v * f) for v in c[:3]))
def lighter(c, f: float = 1.12):
return alpha(tuple(min(255, int(v * f)) for v in c[:3]))
# ---------------------------------------------------------------- Schrift ----
def draw_text(d: ImageDraw.ImageDraw, x: int, y: int, text: str,
color=CREAM) -> int:
"""5x7-Pixelfont, 1 px Laufweite → 6 px Vorschub."""
for ch in text.upper():
glyph = FONT.get(ch)
if glyph:
for row, bits in enumerate(glyph.split("|")):
for col, bit in enumerate(bits):
if bit == "#":
d.point((x + col, y + row), fill=color)
x += 6
return x
def text_width(text: str) -> int:
return max(0, len(text) * 6 - 1)
# ---------------------------------------------------------------- Bausteine --
def panel(d, box, fill=PANEL, line=LINE, bevel=True):
"""Fläche mit Bevel (Licht oben links) und 1-px-Rahmenlinie."""
x0, y0, x1, y1 = box
d.rectangle((x0, y0, x1, y1), fill=fill)
if bevel:
d.line((x0 + 1, y0 + 1, x1 - 1, y0 + 1), fill=PANEL_HI)
d.line((x0 + 1, y0 + 1, x0 + 1, y1 - 1), fill=PANEL_HI)
d.line((x0 + 1, y1 - 1, x1 - 1, y1 - 1), fill=PANEL_LO)
d.line((x1 - 1, y0 + 1, x1 - 1, y1 - 1), fill=PANEL_LO)
if line is not None:
d.rectangle((x0, y0, x1, y1), outline=line)
return d
def well(d, box, fill=PANEL_LO):
"""Vertiefte Fläche: dunkel oben/links, Licht unten/rechts."""
x0, y0, x1, y1 = box
d.rectangle((x0, y0, x1, y1), fill=fill)
d.line((x0, y0, x1, y0), fill=INK)
d.line((x0, y0, x0, y1), fill=INK)
d.line((x1, y0, x1, y1), fill=PANEL_HI)
d.line((x0, y1, x1, y1), fill=PANEL_HI)
def bar(d, x, y, w, h, label, value, vmax, color):
draw_text(d, x, y + 1, label, CREAM_D)
bx = x + text_width(label) + 4
well(d, (bx, y, bx + w - 1, y + h - 1))
fillw = round((w - 4) * value / vmax)
if fillw > 0:
d.rectangle((bx + 2, y + 2, bx + 1 + fillw, y + h - 3), fill=color)
d.line((bx + 2, y + 2, bx + 1 + fillw, y + 2), fill=lighter(color, 1.15))
draw_text(d, bx + w + 4, y + 1, f"{value}/{vmax}", CREAM_D)
def title_bar(d, box, label):
x0, y0, x1, y1 = box
d.rectangle((x0, y0, x1, y1), fill=OCHRE_D)
d.line((x0, y1, x1, y1), fill=INK)
draw_text(d, x0 + 5, y0 + 3, label, CREAM)
# ------------------------------------------------------------------ Elemente
def elem_dialog(lines, name, height, w=292) -> Image.Image:
"""Textbox mit Namensschild; height = Panelhöhe bei 1x, w = Breite bei 1x."""
im = Image.new("RGBA", (w, height + 5), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
d.rectangle((0, 5, w - 1, height + 4), fill=alpha(PANEL, 238))
d.rectangle((0, 5, w - 1, height + 4), outline=INK)
d.rectangle((1, 6, w - 2, height + 3), outline=LINE)
d.line((2, 6, w - 3, 6), fill=PANEL_LO)
tw = text_width(name) + 10
d.rectangle((6, 0, 6 + tw, 13), fill=OCHRE_D)
d.rectangle((6, 0, 6 + tw, 13), outline=INK)
d.line((7, 1, 5 + tw, 1), fill=OCHRE)
draw_text(d, 11, 3, name, CREAM)
for i, line in enumerate(lines):
draw_text(d, 11, 21 + i * 10, line,
CREAM if i < len(lines) - 1 else CREAM_D)
ax, ay = w - 13, height + 1
for i in range(4):
d.line((ax - i, ay - i, ax + i, ay - i), fill=OCHRE)
return im
def elem_buttons() -> Image.Image:
labels = ["ATTACK", "TALK", "USE", "FLEE"]
bw, bh, gap = 52, 14, 4
im = Image.new("RGBA", (bw, (bh + gap) * 4 + 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 = text_width(label)
if state == "hover":
panel(d, (0, y, bw - 1, y + bh - 1), fill=OCHRE_D, line=GOLD)
draw_text(d, (bw - tw) // 2, y + 4, label, CREAM)
elif state == "pressed":
well(d, (0, y, bw - 1, y + bh - 1), fill=(30, 25, 21, 255))
draw_text(d, (bw - tw) // 2 + 1, y + 5, label, 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)
draw_text(d, (bw - tw) // 2, y + 4, label, (98, 86, 70, 255))
else:
panel(d, (0, y, bw - 1, y + bh - 1))
draw_text(d, (bw - tw) // 2, y + 4, label, CREAM)
return im
def icon_sword() -> Image.Image:
return Image.open(SWORD).convert("RGBA").resize((18, 18), Image.NEAREST)
def icon_herb() -> Image.Image:
im = Image.new("RGBA", (18, 18), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
d.polygon([(9, 1), (12, 7), (9, 16), (6, 7)], fill=OLIVE)
d.line((9, 3, 9, 14), fill=OLIVE_D)
d.line((7, 8, 4, 12), fill=OLIVE_D)
d.line((11, 8, 14, 12), fill=OLIVE_D)
return im
def icon_coin() -> Image.Image:
im = Image.new("RGBA", (18, 18), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
d.ellipse((3, 5, 14, 16), fill=OCHRE)
d.ellipse((4, 6, 13, 15), outline=GOLD)
return im
def elem_slots() -> Image.Image:
s, gap = 22, 3
im = Image.new("RGBA", (s * 6 + gap * 5, s + 6), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
for i, sprite in enumerate([None, icon_sword(), icon_herb(), None,
icon_coin(), None]):
x = i * (s + gap)
well(d, (x, 3, x + s - 1, 3 + s - 1))
if sprite is not None:
im.alpha_composite(sprite, (x + 2, 5))
if i == 4: # Auswahl: 2-px-Rahmen + Stapelzahl
d.rectangle((x, 3, x + s - 1, 3 + s - 1), outline=GOLD)
d.rectangle((x + 1, 4, x + s - 2, 2 + s), outline=GOLD)
d.rectangle((x + 7, 13, x + s - 2, 3 + s - 2), fill=INK)
draw_text(d, x + 8, 15, "12", GOLD)
if i == 5: # gesperrt: Schraffur, auf die Slot-Fläche beschnitten
hatch = Image.new("RGBA", (s, s), (0, 0, 0, 0))
hd2 = ImageDraw.Draw(hatch)
for k in range(-s, s, 5):
hd2.line((k, s - 1, k + s - 1, 0), fill=(54, 46, 38, 255))
im.alpha_composite(hatch, (x, 3))
d.line((x, 3, x + s - 1, 3), fill=INK)
d.line((x, 3, x, 3 + s - 1), fill=INK)
d.line((x + s - 1, 3, x + s - 1, 3 + s - 1), fill=PANEL_HI)
d.line((x, 3 + s - 1, x + s - 1, 3 + s - 1), fill=PANEL_HI)
return im
def elem_pack() -> Image.Image:
w, h = 148, 112
im = Image.new("RGBA", (w, h), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
panel(d, (0, 0, w - 1, h - 1), line=INK)
d.rectangle((1, 1, w - 2, h - 2), outline=LINE)
title_bar(d, (2, 2, w - 3, 14), "PACK")
d.rectangle((w - 15, 4, w - 5, 12), fill=PANEL_LO)
d.rectangle((w - 15, 4, w - 5, 12), outline=LINE)
d.line((w - 12, 6, w - 8, 10), fill=CREAM_D)
d.line((w - 8, 6, w - 12, 10), fill=CREAM_D)
s, gap, ox, oy = 22, 4, 6, 19
for row in range(3):
for col in range(5):
x = ox + col * (s + gap)
y = oy + row * (s + gap)
well(d, (x, y, x + s - 1, y + s - 1))
draw_text(d, 7, h - 11, "LOAD 42/60", CREAM_D)
draw_text(d, w - 7 - text_width("128 GOLD"), h - 11, "128 GOLD", GOLD)
return im
def rune(kind: str) -> Image.Image:
"""14x14-Magiesymbole für das Zauberbuch."""
im = Image.new("RGBA", (14, 14), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
if kind == "fire":
d.polygon([(7, 0), (13, 7), (11, 13), (3, 13), (1, 7)], fill=BLOOD)
d.polygon([(7, 5), (10, 8), (9, 12), (5, 12), (4, 8)], fill=GOLD)
elif kind == "ice":
d.polygon([(7, 0), (13, 7), (7, 13), (1, 7)], fill=SLATE)
d.polygon([(7, 3), (10, 7), (7, 11), (4, 7)], fill=CREAM)
elif kind == "bolt":
d.polygon([(9, 0), (3, 7), (6, 7), (4, 13), (11, 5), (8, 5)], fill=GOLD)
elif kind == "ward":
d.ellipse((1, 1, 12, 12), outline=CREAM)
d.line((7, 3, 7, 10), fill=CREAM)
d.line((4, 6, 10, 6), fill=CREAM)
elif kind == "eye":
d.ellipse((1, 4, 12, 10), fill=CREAM)
d.ellipse((5, 5, 8, 9), fill=INK)
elif kind == "leaf":
d.polygon([(7, 0), (12, 7), (7, 13), (2, 7)], fill=OLIVE)
d.line((7, 2, 7, 11), fill=OLIVE_D)
elif kind == "star":
d.polygon([(7, 0), (8, 5), (13, 7), (8, 8), (7, 13), (6, 8),
(1, 7), (6, 5)], fill=GOLD)
elif kind == "skull":
d.rectangle((3, 1, 10, 8), fill=CREAM)
d.rectangle((4, 9, 9, 11), fill=CREAM)
d.point((5, 4), fill=INK)
d.point((8, 4), fill=INK)
d.point((6, 6), fill=INK)
return im
def elem_spells() -> Image.Image:
w, h = 148, 116
im = Image.new("RGBA", (w, h), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
panel(d, (0, 0, w - 1, h - 1), line=INK)
d.rectangle((1, 1, w - 2, h - 2), outline=LINE)
title_bar(d, (2, 2, w - 3, 14), "SPELLBOOK")
# Schulen-Tabs, der erste aktiv
for i, (label, active) in enumerate([("ARCANE", True), ("DIVINE", False)]):
x = 6 + i * 46
panel(d, (x, 17, x + 43, 29), fill=OCHRE_D if active else PANEL_LO,
line=GOLD if active else LINE, bevel=not active)
draw_text(d, x + 5, 21, label, CREAM if active else 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)]
s, gap, ox, oy = 20, 4, 16, 33
for idx, (kind, cost) in enumerate(spells):
col, row = idx % 5, idx // 5
x = ox + col * (s + gap)
y = oy + row * (s + gap)
well(d, (x, y, x + s - 1, y + s - 1))
if kind:
im.alpha_composite(rune(kind), (x + 3, y + 2))
d.rectangle((x + s - 8, y + s - 8, x + s - 2, y + s - 2), fill=INK)
draw_text(d, x + s - 7, y + s - 7, str(cost), GOLD)
if idx == 0: # gewählter Zauber
d.rectangle((x, y, x + s - 1, y + s - 1), outline=GOLD)
d.rectangle((x + 1, y + 1, x + s - 2, y + s - 2), outline=GOLD)
draw_text(d, 7, h - 11, "MEM 3/6 SLOTS", CREAM_D)
draw_text(d, w - 7 - text_width("LVL 4"), h - 11, "LVL 4", GOLD)
return im
def elem_party() -> Image.Image:
fw, fh, gap = 34, 34, 4
im = Image.new("RGBA", (fw, fh * 3 + gap * 2), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
figures = [(SLATE_D, OCHRE_D, (176, 140, 108, 255), (26, 30)),
(OLIVE_D, PANEL_HI, (156, 122, 94, 255), (12, 30)),
(PANEL_HI, SLATE_D, (150, 118, 92, 255), (30, 30))]
for i, (hood, trim, skin, hp) in enumerate(figures):
y = i * (fh + gap)
panel(d, (0, y, fw - 1, y + fh - 1))
well(d, (3, y + 3, fw - 4, y + 26))
bust(d, 3, y + 3, hood, trim, skin)
fillw = round(24 * hp[0] / hp[1])
d.rectangle((4, y + 29, 4 + fillw, y + 31), fill=BLOOD)
d.rectangle((4, y + 29, fw - 5, y + 31), outline=INK)
if i == 0:
d.rectangle((0, y, fw - 1, y + fh - 1), outline=GOLD)
return im
def bust(d, x, y, hood, trim, skin):
"""Flache Kopf-Schulter-Silhouette, 26x26 — für Party-Rahmen.
Ein Crop aus dem Vollkörper-Sprite (64x80) auf 26x26 ist ein Fleck;
gezeichnete Formen bleiben auch bei 1x lesbar.
"""
d.polygon([(x + 1, y + 25), (x + 4, y + 17), (x + 9, y + 15),
(x + 17, y + 15), (x + 22, y + 17), (x + 25, y + 25)], fill=trim)
d.ellipse((x + 6, y + 1, x + 20, y + 20), fill=hood)
d.ellipse((x + 9, y + 6, x + 17, y + 17), fill=darker(hood, 0.55))
d.ellipse((x + 10, y + 7, x + 16, y + 16), fill=skin)
d.point((x + 11, y + 11), fill=INK)
d.point((x + 15, y + 11), fill=INK)
d.line((x + 12, y + 14, x + 14, y + 14), fill=darker(skin, 0.6))
d.line((x + 7, y + 4, x + 11, y + 2), fill=darker(hood, 1.25))
def elem_misc() -> Image.Image:
im = Image.new("RGBA", (170, 104), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
bar(d, 0, 0, 52, 10, "HP", 24, 30, BLOOD)
bar(d, 0, 12, 52, 10, "SP", 11, 20, OLIVE)
bar(d, 0, 24, 52, 10, "MP", 3, 15, SLATE)
for i, on in enumerate([False, True]):
x = 112 + i * 16
well(d, (x, 2, x + 11, 13))
if on:
d.line((x + 2, 7, x + 4, 10), fill=GOLD)
d.line((x + 4, 10, x + 9, 4), fill=GOLD)
sx, sy = 0, 57
draw_text(d, sx, 46, "VOLUME", CREAM_D)
well(d, (sx, sy, sx + 64, sy + 5))
d.rectangle((sx + 1, sy + 1, sx + 34, sy + 4), fill=OCHRE_D)
panel(d, (sx + 31, sy - 4, sx + 39, sy + 8), bevel=False)
panel(d, (88, 40, 168, 65), fill=alpha((30, 25, 21, 255), 246), line=INK)
draw_text(d, 93, 44, "RUSTY SWORD", CREAM)
draw_text(d, 93, 54, "1D6+1 SLASH", CREAM_D)
cx, cy = 112, 76
d.polygon([(cx, cy), (cx + 11, cy + 4), (cx + 5, cy + 6),
(cx + 8, cy + 12), (cx + 5, cy + 13), (cx + 3, cy + 7),
(cx, cy + 7)], fill=CREAM, outline=INK)
return im
def elem_combat() -> Image.Image:
"""Kampf-Aktionsleiste: Initiative-Reihe oben, Aktionen unten."""
w, h = 300, 40
im = Image.new("RGBA", (w, h), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
# Initiative: Chips, der aktive in GOLD, Gegner in BLOOD
for i in range(8):
x = 6 + i * 12
chip = [(SLATE, None), (SLATE, None), (BLOOD, None), (GOLD, INK),
(SLATE, None), (BLOOD, None), (SLATE, None), (BLOOD, None)][i]
d.rectangle((x, 1, x + 8, 9), fill=chip[0])
d.rectangle((x, 1, x + 8, 9), outline=INK if chip[1] is None else GOLD)
draw_text(d, 110, 2, "RND 3", CREAM_D)
panel(d, (0, 13, w - 1, h - 1), fill=alpha(PANEL, 236), line=INK)
labels = ["ATTACK", "MOVE", "SPELL", "ITEM", "DEFEND"]
for i, label in enumerate(labels):
x = 6 + i * 47
panel(d, (x, 19, x + 42, 34), fill=OCHRE_D if label == "SPELL" else PANEL,
line=GOLD if label == "SPELL" else LINE)
tw = text_width(label)
draw_text(d, x + (43 - tw) // 2, 23, label,
CREAM if label == "SPELL" else CREAM_D)
panel(d, (241, 19, 293, 34), fill=PANEL, line=LINE)
draw_text(d, 241 + (53 - text_width("END TURN")) // 2, 23, "END TURN", CREAM)
return im
def elem_loadbar() -> Image.Image:
w, h = 180, 20
im = Image.new("RGBA", (w, h), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
draw_text(d, 0, 0, "LOADING THE HARBOUR", CREAM_D)
draw_text(d, w - text_width("62%"), 0, "62%", CREAM_D)
well(d, (0, 9, w - 1, h - 1))
fillw = round((w - 4) * 0.62)
d.rectangle((2, 11, 1 + fillw, h - 2), fill=OCHRE_D)
d.line((2, 11, 1 + fillw, 11), fill=OCHRE)
# Segmentmarken alle 10 %
for k in range(1, 10):
x = 2 + round((w - 4) * k / 10)
d.line((x, 11, x, h - 2), fill=alpha(INK, 150))
return im
# ------------------------------------------------------------------ Mocks ---
def mock_hud(scene: Path) -> Image.Image:
"""Szene als Hintergrund, UI darüber — die Lesbarkeitsprobe bei 1x."""
base = Image.open(scene).convert("RGBA").resize((320, 180), Image.LANCZOS)
d = ImageDraw.Draw(base)
base.alpha_composite(elem_party(), (320 - 34 - 6, 6))
panel(d, (6, 6, 46, 20), fill=alpha(PANEL, 232))
draw_text(d, 11, 10, "MENU", CREAM)
d.rectangle((153, 6, 166, 20), fill=alpha(PANEL, 232))
d.rectangle((153, 6, 166, 20), outline=LINE)
draw_text(d, 156, 10, "N", GOLD)
base.alpha_composite(
elem_dialog(["THE HARBOUR IS QUIET TONIGHT. TOO QUIET",
"FOR A TOWN THAT SMELLS OF SALT AND IRON.",
"WHAT DO YOU WANT TO DO?"], "ALDRIC THE GREY", 54),
(14, 116))
d.rectangle((0, 0, 319, 179), outline=INK)
return base
def palette_anchor() -> Image.Image:
"""Palette-Anker für `pixelize.py --palette` (16 Farben, 4x4-Raster)."""
im = Image.new("RGB", (32, 32), INK[:3])
for i, c in enumerate(PALETTE[:16]):
x, y = (i % 4) * 8, (i // 4) * 8
ImageDraw.Draw(im).rectangle((x, y, x + 7, y + 7), fill=c[:3])
return im
# ------------------------------------------------------------------ Ausgabe --
def save(im: Image.Image, out: Path, name: str, scale: int) -> None:
if scale > 1:
im = im.resize((im.width * scale, im.height * scale), Image.NEAREST)
out.mkdir(parents=True, exist_ok=True)
path = out / f"{name}.png"
im.save(path)
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 main(argv=None) -> None:
ap = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--out", type=Path, default=FINAL / "UI")
ap.add_argument("--scale", type=int, default=4,
help="1 = Basisgröße, 4 = Auslieferung (Default)")
a = ap.parse_args(argv)
elements = {
"ui_dialog_292x59": elem_dialog(
["THE HARBOUR IS QUIET TONIGHT. TOO QUIET",
"FOR A TOWN THAT SMELLS OF SALT AND IRON.",
"WHAT DO YOU WANT TO DO?"], "ALDRIC THE GREY", 54),
"ui_dialog_gross_292x89": elem_dialog(
["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."],
"ALDRIC THE GREY", 84),
"ui_buttons_52x14": elem_buttons(),
"ui_slots_22px": elem_slots(),
"ui_window_pack_148x112": elem_pack(),
"ui_window_zauber_148x116": elem_spells(),
"ui_party_34px": elem_party(),
"ui_misc_170x104": elem_misc(),
"ui_kampf_leiste_300x40": elem_combat(),
"ui_ladebalken_180x20": elem_loadbar(),
}
for name, im in elements.items():
save(im, a.out, name, a.scale)
save(mock_hud(SCENE_B), a.out, "_mock_hud_B_1280x720", a.scale)
save(mock_hud(SCENE_A), a.out, "_mock_hud_A_1280x720", a.scale)
save(palette_anchor(), a.out, "_palette_ui", 1)
if __name__ == "__main__":
main()