53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
from engine.render.ui_draw import GLYPH_SIZE, PRINTABLE_MAX, PRINTABLE_MIN, glyph_texture_path, panel_texture_path
|
|
|
|
FONT_PIXEL_SIZE = 13
|
|
|
|
# Flat RGBA fills for menu chrome - deliberately plain (unlike world tiles/items' checker
|
|
# placeholder texture) so text stays legible on top of them. See engine/placeholder_textures.py
|
|
# for the equivalent generator for world-space art.
|
|
UI_PANEL_COLORS: dict[str, tuple[int, int, int, int]] = {
|
|
"background": (12, 14, 20, 235),
|
|
"highlight": (70, 110, 200, 235),
|
|
"border": (150, 160, 180, 255),
|
|
"accent": (200, 90, 40, 235),
|
|
}
|
|
|
|
_font_cache = None
|
|
|
|
|
|
def _font():
|
|
global _font_cache
|
|
if _font_cache is None:
|
|
_font_cache = ImageFont.load_default(size=FONT_PIXEL_SIZE)
|
|
return _font_cache
|
|
|
|
|
|
def generate_ui_textures(textures_dir: Path) -> None:
|
|
"""Writes one glyph PNG per printable ASCII character plus a handful of flat-color panel
|
|
fills, if missing. Same on-demand approach as generate_placeholder_textures, just for menu
|
|
chrome (start screen, controls menu, character card) instead of world tile/item art.
|
|
"""
|
|
size = int(GLYPH_SIZE)
|
|
for code in range(PRINTABLE_MIN, PRINTABLE_MAX + 1):
|
|
ch = chr(code)
|
|
path = textures_dir / glyph_texture_path(ch)
|
|
if path.exists():
|
|
continue
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
img = Image.new("RGBA", (size, size), (0, 0, 0, 0))
|
|
ImageDraw.Draw(img).text((1, 0), ch, font=_font(), fill=(255, 255, 255, 255))
|
|
img.save(path)
|
|
|
|
for name, color in UI_PANEL_COLORS.items():
|
|
path = textures_dir / panel_texture_path(name)
|
|
if path.exists():
|
|
continue
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
Image.new("RGBA", (8, 8), color).save(path)
|