Menus: generator for FancyMenu layouts, Create casing buttons, game menu, connecting screens, update check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fulldroper
2026-10-14 06:28:34 +03:00
co-authored by Claude Opus 5.5
parent 3876cb39a5
commit 4051a18f24
12 changed files with 901 additions and 2086 deletions
+38 -1
View File
@@ -298,14 +298,45 @@ def button_icon(rows: str, outline: bool = False) -> Image.Image:
return im
def casing_button(jar: zipfile.ZipFile, casing: str, tone: float = 1.0, grey: float = 0.0) -> Image.Image:
"""A 200x20 button sprite built from a Create casing: black outline, the casing's 3 px metal frame, its wood
inside. The wood is tiled with the block's own 16 px period and the sprite is nine-sliced with a 4 px border,
so the 192 px middle (12 tiles) repeats without a seam on buttons of any width."""
tile = texture(jar, f'assets/create/textures/block/{casing}.png')[..., :3].astype(int)
sheet = np.asarray(Image.open(io.BytesIO(
jar.read(f'assets/create/textures/block/{casing}_connected.png'))).convert('RGBA')).astype(int)
cells = [sheet[ty:ty + 16, tx:tx + 16] for ty in range(0, sheet.shape[0], 16) for tx in range(0, sheet.shape[1], 16)]
# the plain wood is the opaque tile of the connected sheet with the least contrast: every other one has frame in it
wood = min((c for c in cells if c[..., 3].min() == 255), key=lambda c: c[..., :3].std())[..., :3]
px = np.zeros((20, 200, 3), int)
px[1:19, 1:199] = np.tile(wood, (2, 13, 1))[2:20, :198] # wood everywhere inside the outline
for i in range(3): # frame rows and columns, taken from the block's edges
px[1 + i, 1:199] = np.tile(tile[i, 3:13], (20, 1))[:198]
px[18 - i, 1:199] = np.tile(tile[15 - i, 3:13], (20, 1))[:198]
px[1:19, 1 + i] = np.tile(tile[3:13, i], (2, 1))[:18]
px[1:19, 198 - i] = np.tile(tile[3:13, 15 - i], (2, 1))[:18]
for (y, x), (ty, tx) in (((1, 1), (0, 0)), ((1, 196), (0, 13)), ((16, 1), (13, 0)), ((16, 196), (13, 13))):
px[y:y + 3, x:x + 3] = tile[ty:ty + 3, tx:tx + 3] # the four corners
px[1:19, 1:199] = px[1:19, 1:199] * tone
mean = px.mean(axis=2, keepdims=True)
px = np.clip(px * (1 - grey) + mean * grey, 0, 255)
return Image.fromarray(px.astype(np.uint8), 'RGB').convert('RGBA')
BUTTON_META = '{"gui": {"scaling": {"type": "nine_slice", "width": 200, "height": 20, "border": 4}}}\n'
def main() -> None:
mc_jar, create_jar, key_art = sys.argv[1], sys.argv[2], Path(sys.argv[3])
emblem_raw = Path(sys.argv[4]) if len(sys.argv) > 4 else None
with zipfile.ZipFile(mc_jar) as mc, zipfile.ZipFile(create_jar) as cr:
font = Font(mc)
brass = texture(cr, 'assets/create/textures/block/brass_block.png')
buttons = {'button': casing_button(cr, 'andesite_casing', tone=0.82),
'button_highlighted': casing_button(cr, 'brass_casing', tone=1.12),
'button_disabled': casing_button(cr, 'andesite_casing', tone=0.42, grey=0.6)}
for d in ('logo', 'icons', 'banners', 'menu'):
for d in ('logo', 'icons', 'banners', 'menu', 'ui'):
(OUT / d).mkdir(parents=True, exist_ok=True)
# --- wordmark: CREATE in brass, RP in brick red, the motto underneath -------------------------
@@ -359,7 +390,13 @@ def main() -> None:
# --- FancyMenu: title screen background, the logo it shows, window icons -------------------------
shade(cover(art, 1920, 1080), *((0.95, 1.0) if night else (0.80, 0.92))).convert('RGB').save(OUT / 'menu' / 'background.png')
shade(cover(art, 1920, 1080), 0.42, 0.42).convert('RGB').save(OUT / 'menu' / 'background_dim.png') # behind "Connecting…"
stack([wordmark(8), motto(3)], gap=12).save(OUT / 'menu' / 'logo.png')
# --- every button of the game: andesite casing, brass casing under the cursor ---------------------------------
for name, sprite in buttons.items():
sprite.save(OUT / 'ui' / f'{name}.png')
(OUT / 'ui' / f'{name}.png.mcmeta').write_text(BUTTON_META, encoding='utf-8', newline='\n')
button_icon(QUIT_ICON).save(OUT / 'menu' / 'quit.png')
button_icon(SETTINGS_ICON).save(OUT / 'menu' / 'settings.png')
for name, rows in (('online', ONLINE_ICON), ('offline', OFFLINE_ICON), ('maintenance', MAINTENANCE_ICON)):