Title screen: icon-only quit, no Create/accessibility/Mods buttons, pack version instead of the Minecraft lines
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6ec630bf47
commit
1dcefc772c
@@ -188,6 +188,35 @@ def fit(im: Image.Image, max_w: int, max_h: int) -> Image.Image:
|
||||
return im.resize((im.width * k, im.height * k), Image.NEAREST)
|
||||
|
||||
|
||||
# The quit button of the title screen: a door frame with an arrow going out — the library's "sign-out" icon redrawn
|
||||
# on the 13 px grid of Minecraft's own button icons. '#' is white, '+' the light grey Minecraft shades them with.
|
||||
QUIT_ICON = '''
|
||||
#######......
|
||||
#++++++......
|
||||
#+...........
|
||||
#+.......#...
|
||||
#+.......##..
|
||||
#+..########.
|
||||
#+..#########
|
||||
#+..+++++##+.
|
||||
#+.......#+..
|
||||
#+.......+...
|
||||
#+...........
|
||||
#######......
|
||||
+++++++......
|
||||
'''
|
||||
|
||||
|
||||
def button_icon(rows: str) -> Image.Image:
|
||||
"""A 20x20 picture for a 20x20 button; the drawing starts at (4, 4), where Minecraft puts its own icons."""
|
||||
im = Image.new('RGBA', (20, 20), (0, 0, 0, 0))
|
||||
for y, row in enumerate(rows.split()):
|
||||
for x, c in enumerate(row):
|
||||
if c != '.':
|
||||
im.putpixel((4 + x, 4 + y), (255, 255, 255, 255) if c == '#' else (208, 208, 208, 255))
|
||||
return im
|
||||
|
||||
|
||||
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
|
||||
@@ -250,6 +279,7 @@ 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')
|
||||
stack([wordmark(8), motto(3)], gap=12).save(OUT / 'menu' / 'logo.png')
|
||||
button_icon(QUIT_ICON).save(OUT / 'menu' / 'quit.png')
|
||||
print('done:', ', '.join(sorted(str(p.relative_to(OUT)).replace('\\', '/') for p in OUT.rglob('*.png'))))
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
"""Writes the FancyMenu configuration of the Create RP title screen into a game's config folder.
|
||||
|
||||
python tools/branding/fancymenu.py <config dir> e.g. the client pack's config/ or a profile's config/
|
||||
python tools/branding/fancymenu.py <config dir> <1.21.1.jar> [pack version]
|
||||
|
||||
<config dir> is the client pack's config/ or a profile's config/. The version is read from pack.toml next to the
|
||||
config dir when it is not given.
|
||||
|
||||
Layout: the key art as the background, our logo instead of Minecraft's, one wide button that joins the server,
|
||||
then the usual buttons. The layout file itself is branding/menu/title_screen_layout.txt; this script only copies it
|
||||
with the pictures and switches the window title, the window icon and the title-screen customisation on.
|
||||
single player and multiplayer, then language, options and an icon-only quit button in one row. Minecraft's own
|
||||
lines in the bottom left corner are replaced with the pack version. The layout file itself is
|
||||
branding/menu/title_screen_layout.txt; this script copies it with the pictures, draws the version label and
|
||||
switches the window title, the window icon and the title-screen customisation on.
|
||||
"""
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent.parent
|
||||
sys.path.insert(0, str(ROOT / 'tools' / 'signs'))
|
||||
from render import Font # noqa: E402 (the pixel font reader made for the building signs)
|
||||
|
||||
MENU, ICONS = ROOT / 'branding' / 'menu', ROOT / 'branding' / 'icons'
|
||||
WINDOW_TITLE = 'Create RP'
|
||||
|
||||
@@ -23,15 +35,38 @@ def option(text: str, key: str, value: str) -> str:
|
||||
return pattern.sub(lambda m: m.group(1) + value + m.group(2), text)
|
||||
|
||||
|
||||
def label(font: Font, text: str) -> Image.Image:
|
||||
"""A line of text exactly as the game draws it: white, with the dark shadow one pixel down and right."""
|
||||
mask = font.line(text)
|
||||
rows = np.nonzero(mask.any(axis=1))[0]
|
||||
mask = mask[rows.min():rows.max() + 1]
|
||||
h, w = mask.shape
|
||||
px = np.zeros((h + 1, w + 1, 4), np.uint8)
|
||||
px[1:, 1:][mask] = (63, 63, 63, 255)
|
||||
px[:-1, :-1][mask] = (255, 255, 255, 255)
|
||||
return Image.fromarray(px, 'RGBA')
|
||||
|
||||
|
||||
def main() -> None:
|
||||
fm = Path(sys.argv[1]) / 'fancymenu'
|
||||
config = Path(sys.argv[1])
|
||||
fm = config / 'fancymenu'
|
||||
if len(sys.argv) > 3:
|
||||
version = sys.argv[3]
|
||||
else:
|
||||
version = re.search(r'^version = "([^"]+)"', (config.parent / 'pack.toml').read_text(encoding='utf-8'), re.M).group(1)
|
||||
with zipfile.ZipFile(sys.argv[2]) as jar:
|
||||
version_label = label(Font(jar), f'{WINDOW_TITLE} {version}')
|
||||
(fm / 'assets').mkdir(parents=True, exist_ok=True)
|
||||
(fm / 'customization').mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(MENU / 'logo.png', fm / 'assets' / 'logo.png')
|
||||
shutil.copyfile(MENU / 'background.png', fm / 'assets' / 'background.png')
|
||||
shutil.copyfile(MENU / 'quit.png', fm / 'assets' / 'quit.png')
|
||||
version_label.save(fm / 'assets' / 'version.png')
|
||||
for icon in ('favicon-16x16.png', 'favicon-32x32.png'):
|
||||
shutil.copyfile(ICONS / icon, fm / 'assets' / icon)
|
||||
shutil.copyfile(MENU / 'title_screen_layout.txt', fm / 'customization' / 'title_screen_layout.txt')
|
||||
layout = (MENU / 'title_screen_layout.txt').read_text(encoding='utf-8')
|
||||
layout = layout.replace('{version_width}', str(version_label.width)).replace('{version_height}', str(version_label.height))
|
||||
(fm / 'customization' / 'title_screen_layout.txt').write_text(layout, encoding='utf-8', newline='\n')
|
||||
(fm / 'customizablemenus.txt').write_text(
|
||||
'type = customizablemenus\n\nnet.minecraft.client.gui.screens.TitleScreen {\n}\n\n', encoding='utf-8')
|
||||
|
||||
@@ -43,7 +78,7 @@ def main() -> None:
|
||||
options = option(options, 'custom_window_icon_macos', '')
|
||||
options = option(options, 'global_background_panorama', '')
|
||||
(fm / 'options.txt').write_text(options, encoding='utf-8')
|
||||
print('title screen installed into', fm)
|
||||
print('title screen installed into', fm, '| version label:', version, version_label.size)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user