#!/usr/bin/env python3 """UI-Generator für Taloria — prozedural gezeichnet, 1x = 640x360-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 2x (1280x720). python3 tools/ui.py # -> final/UI/, 2x (1280x720) python3 tools/ui.py --scale 1 # -> Basisgrößen, 1x python3 tools/ui.py --out /tmp/ui # woanders hin Schrift: 8x10 aus `font8.py` (Vorschub 8, Zeile 12). Die Dateinamen tragen die **Basisgröße** (z. B. ui_dialog_390x66.png = 390x66 bei 1x, 780x132 in der Datei) — dieselbe Regel wie monster_wolf_96px.png. """ from __future__ import annotations import argparse from pathlib import Path from PIL import Image, ImageDraw import font8 # noqa: E402 (gleicher Ordner) ART = Path(__file__).resolve().parent.parent FINAL = ART / "final" 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] 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: """8x10-Pixelfont aus font8.py, Vorschub 8, Zeile 12.""" return font8.draw_text(d, x, y, text, color) def text_width(text: str) -> int: return font8.text_width(text) # ---------------------------------------------------------------- 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 + 4, label, CREAM) # ------------------------------------------------------------------ Elemente def elem_dialog(lines, name, height, w=390) -> Image.Image: """Textbox mit Namensschild; height = Panelhöhe bei 1x, w = Breite bei 1x. Achtung: `height` ist die Panelhöhe ohne das Namensschild (5 px Überstand oben). Drei Zeilen brauchen 66, sechs Zeilen 102. """ 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) + 12 d.rectangle((6, 0, 6 + tw, 17), fill=OCHRE_D) d.rectangle((6, 0, 6 + tw, 17), outline=INK) d.line((7, 1, 5 + tw, 1), fill=OCHRE) draw_text(d, 11, 4, name, CREAM) for i, line in enumerate(lines): draw_text(d, 11, 24 + i * 12, 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 = 64, 18, 6 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((20, 20), Image.NEAREST) def icon_herb() -> Image.Image: im = Image.new("RGBA", (20, 20), (0, 0, 0, 0)) d = ImageDraw.Draw(im) d.polygon([(10, 1), (13, 8), (10, 18), (7, 8)], fill=OLIVE) d.line((10, 3, 10, 16), fill=OLIVE_D) d.line((8, 9, 4, 13), fill=OLIVE_D) d.line((12, 9, 16, 13), fill=OLIVE_D) return im def icon_coin() -> Image.Image: im = Image.new("RGBA", (20, 20), (0, 0, 0, 0)) d = ImageDraw.Draw(im) d.ellipse((3, 6, 16, 18), fill=OCHRE) d.ellipse((4, 7, 15, 17), outline=GOLD) return im def elem_slots() -> Image.Image: s, gap = 26, 4 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 + 3, 6)) 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 + 8, 16, x + 24, 27), fill=INK) draw_text(d, x + 9, 17, "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, 6): 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 = 170, 132 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, 18), "PACK") d.rectangle((w - 17, 5, w - 5, 15), fill=PANEL_LO) d.rectangle((w - 17, 5, w - 5, 15), outline=LINE) d.line((w - 13, 7, w - 9, 11), fill=CREAM_D) d.line((w - 9, 7, w - 13, 11), fill=CREAM_D) s, gap, ox, oy = 26, 4, 8, 24 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, 8, h - 14, "LOAD 42/60", CREAM_D) draw_text(d, w - 8 - text_width("128 GOLD"), h - 14, "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 = 170, 140 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, 18), "SPELLBOOK") # Schulen-Tabs, der erste aktiv for i, (label, active) in enumerate([("ARCANE", True), ("DIVINE", False)]): x = 6 + i * 62 panel(d, (x, 22, x + 57, 38), fill=OCHRE_D if active else PANEL_LO, line=GOLD if active else LINE, bevel=not active) draw_text(d, x + 5, 26, 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, 44 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 + 3)) d.rectangle((x + 11, y + 10, x + 19, y + 19), fill=INK) draw_text(d, x + 12, y + 10, 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, 8, h - 14, "MEM 3/6 SLOTS", CREAM_D) draw_text(d, w - 8 - text_width("LVL 4"), h - 14, "LVL 4", GOLD) return im def party_portraits(size: int = 32) -> list[Image.Image] | None: """Die sechs Party-Porträts aus `final/Players/`, falls vorhanden. Die Rahmen sind prozedural, die Porträts sind generierte Assets. Für den Export (Vorschau) und die Mocks werden sie hier hineinkomponiert; im Spiel macht das die Engine. """ names = ("krieger", "magierin", "zwerg", "elfin", "halbling", "gelehrter") paths = [ART / "final" / "Players" / f"portrait_{n}_32px.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: list[Image.Image] | None = None, count: int = 6, fw: int = 40, fh: int = 42, psize: int = 32) -> Image.Image: """Party-Spalte: Rahmen mit Porträt und HP-Rinne, erster aktiv. `portraits` sind fertige Bilder in `psize`; ohne sie zeichnet die Funktion die alten Silhouetten-Platzhalter (`bust`). Die Vorgaben (6× 40x42) passen zur 640x360-Basis und zur Kampf-Spalte; die alten HUD-Mocks rufen bewusst `count=3, fw=34, fh=34, psize=26` auf. """ gap = 4 im = Image.new("RGBA", (fw, fh * count + gap * (count - 1)), (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 in range(count): y = i * (fh + gap) hood, trim, skin, hp = figures[i % len(figures)] panel(d, (0, y, fw - 1, y + fh - 1)) well(d, (3, y + 3, fw - 4, y + fh - 6)) if portraits and i < len(portraits): im.alpha_composite(portraits[i], (4, y + 4)) else: tmp = Image.new("RGBA", (26, 26), (0, 0, 0, 0)) bust(ImageDraw.Draw(tmp), 0, 0, hood, trim, skin) im.alpha_composite(tmp, (4 + (psize - 26) // 2, y + 4 + (psize - 26) // 2)) fillw = round((fw - 10) * hp[0] / hp[1]) by = y + fh - 5 d.rectangle((4, by, 4 + fillw, by + 2), fill=BLOOD) d.rectangle((4, by, fw - 5, by + 2), 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", (220, 130), (0, 0, 0, 0)) d = ImageDraw.Draw(im) bar(d, 0, 0, 120, 12, "HP", 24, 30, BLOOD) bar(d, 0, 16, 120, 12, "SP", 11, 20, OLIVE) bar(d, 0, 32, 120, 12, "MP", 3, 15, SLATE) for i, on in enumerate([False, True]): x = 188 + i * 18 well(d, (x, 2, x + 13, 15)) if on: d.line((x + 3, 8, x + 6, 12), fill=GOLD) d.line((x + 6, 12, x + 10, 4), fill=GOLD) sx, sy = 0, 70 draw_text(d, sx, 52, "VOLUME", CREAM_D) well(d, (sx, sy, sx + 100, sy + 7)) d.rectangle((sx + 2, sy + 2, sx + 54, sy + 5), fill=OCHRE_D) panel(d, (sx + 51, sy - 4, sx + 59, sy + 11), bevel=False) panel(d, (110, 50, 218, 86), fill=alpha((30, 25, 21, 255), 246), line=INK) draw_text(d, 116, 54, "RUSTY SWORD", CREAM) draw_text(d, 116, 66, "1D6+1 SLASH", CREAM_D) draw_text(d, 116, 78, "10 GOLD", GOLD) cx, cy = 180, 98 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 = 400, 56 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 * 14 chip = [(SLATE, None), (SLATE, None), (BLOOD, None), (GOLD, INK), (SLATE, None), (BLOOD, None), (SLATE, None), (BLOOD, None)][i] d.rectangle((x, 2, x + 9, 11), fill=chip[0]) d.rectangle((x, 2, x + 9, 11), outline=INK if chip[1] is None else GOLD) draw_text(d, 134, 2, "RND 3", CREAM_D) panel(d, (0, 17, w - 1, h - 1), fill=alpha(PANEL, 236), line=INK) labels = ["ATTACK", "MOVE", "SPELL", "ITEM", "DEFEND", "END TURN"] x = 6 for label in labels: bw = text_width(label) + 14 panel(d, (x, 23, x + bw - 1, 49), fill=OCHRE_D if label == "SPELL" else PANEL, line=GOLD if label == "SPELL" else LINE) draw_text(d, x + 7, 31, label, CREAM if label == "SPELL" else CREAM_D) x += bw + 4 return im def elem_loadbar() -> Image.Image: w, h = 240, 26 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%") - 1, 0, "62%", CREAM_D) well(d, (0, 14, w - 1, h - 1)) fillw = round((w - 4) * 0.62) d.rectangle((2, 16, 1 + fillw, h - 2), fill=OCHRE_D) d.line((2, 16, 1 + fillw, 16), fill=OCHRE) # Segmentmarken alle 10 % for k in range(1, 10): x = 2 + round((w - 4) * k / 10) d.line((x, 16, x, h - 2), fill=alpha(INK, 150)) return im 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=2, help="1 = Basisgröße, 2 = Auslieferung (Default)") a = ap.parse_args(argv) elements = { "ui_dialog_390x71": 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", 66), "ui_dialog_gross_390x107": 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", 102), "ui_buttons_64x18": elem_buttons(), "ui_slots_26px": elem_slots(), "ui_window_pack_170x132": elem_pack(), "ui_window_zauber_170x140": elem_spells(), "ui_party_40px": elem_party(party_portraits()), "ui_misc_220x130": elem_misc(), "ui_kampf_leiste_400x56": elem_combat(), "ui_ladebalken_240x26": elem_loadbar(), } for name, im in elements.items(): save(im, a.out, name, a.scale) save(palette_anchor(), a.out, "_palette_ui", 1) if __name__ == "__main__": main()