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
@@ -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