Add a Custom colour scheme with a colour square and a hex code, start the player's background picture below the title band, and shorten the Add to Steam description.

Custom is the last scheme in Customize Launcher. Its Background Color and Button Color rows open a picker in the description box's place: a square of the hue's colours (saturation across, brightness up and down) with a hue bar under it to click or drag on, Hue, Saturation and Brightness rows for the arrows and the gamepad, and a Hex Code row to type a code into. Each picked colour takes the place of one colour of the first scheme, the backdrop's middle tint or the buttons' wood, and the rest of its group follows it, lighter and darker as in the first scheme; light buttons get dark text. The colours are kept as custom_background and custom_buttons in launcher.json.

The background picture used to fill the whole window, so its top was hidden under the title band. It now fills the window from where the band ends, cut to that shape around its middle and scaled evenly. A copy an older launcher kept for the whole window is cut, never squeezed, and made again from the picture file while it is there.

Add to Steam's description and result are now one plain sentence each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
epicmeme546
2026-11-11 02:50:15 -05:00
parent a7b8810d37
commit 43760d4129
9 changed files with 534 additions and 50 deletions

View File

@@ -38,10 +38,18 @@ Customize Launcher (on the home screen) makes the look the player's own:
- Color Scheme: Forest (the colours above), Volcano, Lake, Desert, Temple and Shadow. A scheme is the first one with
its woods, accents, backdrop and glow turned to other hues (`art.THEMES`, `art.recolor`), so each keeps the same
light and dark steps and the same readable text. The window is drawn again in the new colours at once. The names
are plain words, not the game's.
are plain words, not the game's. Custom, the last one, takes two colours of the player's: Background Color for the
backdrop and Button Color for the buttons, the panels and the title band. Each opens a picker in the description
box's place: a square of the hue's colours (saturation across, brightness up and down) and a hue bar under it, to
click or drag on, Hue, Saturation and Brightness rows for the arrows and the gamepad, and Hex Code, where a code
such as `#3A7BD5` is typed. The picked colour stands in for one colour of the first scheme (`art.CUSTOM_SLOTS`) and
the rest of its group follows it, lighter and darker as in the first scheme (`art.follow`); light buttons get dark
text. The window takes the new colour as the mouse moves; Reset brings back the first scheme's colour.
- Background: a picture of the player's own behind the panels instead of the scheme's backdrop (`launcher/ui/picture.py`:
PNG, JPEG, WebP, BMP, GIF or TIFF, read with Pillow). It is cut to the window's shape around its middle and kept as
`data/background.npy`, so the launcher needs the file no more; Background Dimming darkens it (0 to 80 %) for the
PNG, JPEG, WebP, BMP, GIF or TIFF, read with Pillow). It fills the window below the title band, so none of it is
hidden under the band: cut to that shape around its middle and scaled evenly, never stretched, and kept as
`data/background.npy`, so the launcher needs the file no more (a copy an older launcher kept for the whole window is
made again from the file while it is there); Background Dimming darkens it (0 to 80 %) for the
text over it, the list panel and the description box turn a little see-through, and Remove Background brings the
scheme's backdrop back.
- Animations (on by default): the cursor glides from row to row, a new screen slides into place, sparks drift up
@@ -67,7 +75,8 @@ Customize Launcher (on the home screen) makes the look the player's own:
starts the launcher of `app/current.txt` with `--play`: the game starts as Play starts it, and the process waits
for it, so Steam counts the game as running while it is.
The choices are `theme`, `background`, `background_dim`, `animations` and `sounds` in `data/launcher.json`.
The choices are `theme`, `custom_background`, `custom_buttons`, `background`, `background_dim`, `animations` and
`sounds` in `data/launcher.json`.
Navi (`art.NAVI`, 22 x 21 pixels, drawn in whole pixels at every size) is also the icon of `NX2navi.exe`,
`NX2navi-Setup.exe`, the window and its taskbar button (`art.navi_ico`, written into the release by
@@ -77,8 +86,9 @@ identity (`NX2navi.Launcher`), so the taskbar groups and pins it under NX2navi r
Screens (`launcher/ui/app.py`): first run (dump, install folder, Desktop Shortcut, Check for Updates at Start,
Update Channel, Begin Installation); the steps of an install, update or rebuild with their progress, the build log's
last lines and Cancel, and after a failure Try Again and Copy Report; home (Play, Updates, Game Folder, Saves,
Rebuild the Game, Customize Launcher, Settings); customize (Color Scheme, Background, with a picture set Background
Dimming and Remove Background, Animations, Sounds, Add to Steam on Windows, Back); saves (Export Save, Add Log and Settings, Export To, Import a Save, Import a Save Folder,
Rebuild the Game, Customize Launcher, Settings); customize (Color Scheme, with Custom Background Color and Button
Color, Background, with a picture set Background Dimming and Remove Background, Animations, Sounds, Add to Steam on
Windows, Back); the colour picker (Hue, Saturation, Brightness, Hex Code, Reset, Done); saves (Export Save, Add Log and Settings, Export To, Import a Save, Import a Save Folder,
Open Saves Folder, Back); settings (update check, Install Updates Automatically, Hide Launcher While Playing, Keep
Build Cache, Update Channel, the folders, Open Logs Folder, Uninstall, Back); uninstall (keep or remove the built game).
A screen with more rows than the window holds draws them closer together (`fit_rows`).
@@ -105,7 +115,7 @@ toolchain/msys64/ucrt64 MSYS2's clang and libraries, downloaded from the MSYS2
toolchain/pkgs/ the downloaded package files
data/launcher.json settings; data/logs/launcher.log (and crash.log); data/cache/fonts and data/cache/sounds
(the game's font and interface sounds, decoded from the player's game);
data/background.npy (the player's background picture, fitted to the window)
data/background.npy (the player's background picture, fitted below the title band)
game/ the built game, unless another folder was chosen (its layout: README-BuildKit.md), with
saves/ for saves to import and the backups imports make (below)
```
@@ -390,7 +400,8 @@ pruning, unsafe archives, the background update (a release staged beside the run
`staged.json` marker, a staged release installed after a restart, no install while the game runs, the install once
it exited, nothing by itself with Install Updates Automatically off, a failed staging tried again after the next
check), the font decoding on a system font wrapped like the game's, the look (every colour scheme complete, the
background picture cut to the window's shape and kept, the sound effects as WAVs and low by default), `make_game.py`
Custom scheme's picked colours, colour square and typed hex code, the background picture cut to the shape below the
title band and kept, never stretched, the sound effects as WAVs and low by default), `make_game.py`
on a synthetic
`.nup` (events, skipped steps, `--rebuild` without the dump, step keys, the shaders key following the translator the
build uses), the RomFS step beside the lift and compile

View File

@@ -18,13 +18,17 @@ Draft notes for the release after 0.7.1. The version number is not decided yet.
## New
- **Add to Steam** in Customize Launcher (Windows): the game joins your Steam library as *The Legend of Zelda Ocarina
of Time*, with Navi as its icon, the title screen's moonlit field as its background and cover, and the game's logo,
all made from your own game files when you select the row. Playing it from Steam starts the game straight away,
without the launcher. Steam closes for a moment while the shortcut is written and starts again with it.
- **Add to Steam** in Customize Launcher (Windows): adds the game to your Steam library as *The Legend of Zelda
Ocarina of Time*, with Navi as its icon and the title screen's artwork and logo. Starting it from Steam starts the
game. Steam restarts once while it is added.
- **Custom color scheme** in Customize Launcher: pick your own background color and button color on a color square
with a hue bar, or type a hex code.
## Fixed
- Your own background picture in the launcher is no longer partly hidden under the top bar: it now starts right
below it, and keeps its shape.
- Black and white blocks on AMD RX 5000 and RX 6000 cards: on Navi and on Link next to her, on bright floors near her,
and on the bright outdoors seen through a door or window from inside a house. Every float colour a shader writes is
checked for NaN, so that one bad pixel cannot spread through the blur and bloom passes; those checks, and the

View File

@@ -16,6 +16,8 @@ DEFAULTS = {
'save_export_dir': '', # where Saves > Export Save writes its zip; empty: the Downloads folder
'export_with_log': True, # Export Save adds the game's latest log and nx2navi.ini (for a bug report)
'theme': 'forest', # the colour scheme (launcher/ui/art.py THEMES)
'custom_background': '', # the Custom scheme's backdrop colour, #rrggbb; empty: the first scheme's
'custom_buttons': '', # the Custom scheme's colour of the buttons, panels and title band
'background': '', # the picture the player chose as the background; its fitted copy is data/background.npy
'background_dim': 40, # how much that picture is darkened, in percent
'animations': True, # the cursor glides, screens slide in, sparks drift, Navi bobs

View File

@@ -325,5 +325,5 @@ def add(layout, game_dir, dump='', log=print, restart=True):
subprocess.Popen([str(exe_steam)], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, creationflags=0x00000008, close_fds=True) # detached
if was_running and restart:
return f'Added to Steam as {NAME}. Steam is starting again with it in the library.'
return f'Added to Steam as {NAME}. It is in the library the next time Steam starts.'
return 'Added to Steam.'
return 'Added. It shows up the next time you open Steam.'

View File

@@ -10,6 +10,7 @@ flat cells and the orange choices are canvas items. Screens:
first_run the dump, the install folder, three choices and Begin Installation
home Play, Updates, the game folder, Saves, Rebuild the Game, Customize Launcher, Settings
customize the colour scheme, the player's own background picture, animations and sounds; Add to Steam
color the Custom scheme's colour picker: a colour square, a hue bar and the hex code
saves Export Save (a zip for a bug report or another player), Import a Save (such a zip), a save folder
job the steps of an install, update or rebuild, with their progress, and Cancel; after a failure Try Again
and Copy Report
@@ -24,6 +25,7 @@ rows, a new screen slides in, sparks drift over the backdrop and Navi bobs in th
plays the game's own decide and cancel sounds, read from the player's game, for a choice and for going back.
"""
import argparse
import colorsys
import math
import os
import random
@@ -41,6 +43,7 @@ from . import art, picture, sound
W, H = 1000, 640
BAND = (0, 1000, 56) # x0, x1, height: the whole top of the window, which is also its title bar
PIC_TOP = 60 # the player's background picture starts under the band and its two lines
TITLE_BUTTONS = (('min', 908, 954), ('close', 954, 1000)) # x ranges on the band
PANEL = (112, 60, 580) # x0, top, x1
ROWS = (140, 552, 96) # x0, x1, top
@@ -50,7 +53,14 @@ DESC = (614, 336) # x, width
P = art.PALETTE # the colour scheme in use: art.set_theme changes it in place
FRAME_MS = 15 # between two steps of the animations; they move by the time that really passed
SPARKS = 22 # the dust drifting over the backdrop
DEPTH = {'first_run': 0, 'home': 0, 'job': 1, 'saves': 1, 'settings': 1, 'customize': 1, 'uninstall': 2}
DEPTH = {'first_run': 0, 'home': 0, 'job': 1, 'saves': 1, 'settings': 1, 'customize': 1, 'uninstall': 2,
'color': 2}
# the Custom scheme's picker (draw_picker), logical pixels: its box (x, top, width, height), the colour square and
# the hue bar (x0, y0, x1, y1)
PICKER_BOX = (614, 100, 336, 452)
SQUARE = (667, 160, 897, 390)
BAR = (667, 408, 897, 430)
CUSTOM_LABELS = {'background': 'Background Color', 'buttons': 'Button Color'}
DIMS = (0, 20, 40, 60, 80) # Background Dimming, in percent
SOUND_LEVELS = (('off', 'Off'), ('low', 'Low'), ('medium', 'Medium'), ('high', 'High'))
@@ -172,6 +182,10 @@ class App:
self.export_message = '' # the last Export Save result, shown in its description
self.steam_message = '' # the last Add to Steam result, shown in its description
self.steam_busy = False # Add to Steam is making the pictures or writing Steam's files
self.pick = None # the colour picker: {'slot', 'h', 's', 'v'} (HSV in 0..1) of the colour being picked
self.pick_drag = None # 'square' or 'bar' while the mouse drags on the picker
self.hex_entry = None # the box the hex code is typed into
self.look_after = None # the redraw a picked colour waits for (look_soon)
self.dumps = None
self.dump_search = None
self.uninstall_game = False
@@ -184,7 +198,7 @@ class App:
self.ico = None
# the look: the colour scheme, the player's background picture at the window's size (None: the scheme's own
# backdrop), the sounds (none while the selftest draws the screens)
art.set_theme(self.settings.get('theme'))
art.set_theme(self.settings.get('theme'), self.custom_colors())
self.bg_store = self.layout.data / 'background.npy'
self.picture = None
self.sounds = sound.Sounds(self.layout.cache, 'off' if args.selftest else self.settings.get('sounds'), ctx.log)
@@ -351,10 +365,19 @@ class App:
return bool(self.settings.get('animations')) and not self.args.selftest
def load_picture(self):
"""The player's background at the window's size, when one is set and its kept copy is readable."""
"""The player's background at the size of the window below the title band, when one is set and its kept copy
is readable. A copy an older launcher kept for the whole window is made again from the picture when the file
is still there, so no more of it is cut off than the new shape needs."""
self.picture = None
if self.settings.get('background'):
self.picture = picture.kept(self.bg_store, self.X(W), self.X(H))
src = self.settings.get('background')
if src:
if picture.kept_shape(self.bg_store) not in (None, (picture.KEEP_H, picture.KEEP_W)) \
and Path(src).is_file():
try:
picture.keep(src, self.bg_store, self.root)
except (picture.PictureError, OSError, MemoryError, ValueError) as e:
self.ctx.log(f'background: {src}: {e!r}; the copy kept before stays')
self.picture = picture.kept(self.bg_store, self.X(W), self.X(H) - self.X(PIC_TOP))
if self.picture is None:
self.ctx.log(f'background: {self.bg_store} is missing or unreadable; the colour scheme\'s backdrop')
@@ -367,7 +390,8 @@ class App:
c.delete('static')
dim = max(0, min(100, self.settings.get('background_dim', 40))) / 100.0
c.create_image(0, 0, anchor='nw', tags='static',
image=self.sprite('backdrop', lambda: art.backdrop(self.X(W), self.X(H), s, self.picture, dim)))
image=self.sprite('backdrop', lambda: art.backdrop(self.X(W), self.X(H), s, self.picture, dim,
self.X(PIC_TOP))))
self.make_sparks() # over the backdrop, under the panel and the band
bx0, bx1, bh = BAND
px0, ptop, px1 = PANEL
@@ -418,7 +442,7 @@ class App:
def apply_look(self):
"""Draw everything again after the colour scheme, the background or Animations changed."""
art.set_theme(self.settings.get('theme'))
art.set_theme(self.settings.get('theme'), self.custom_colors())
self.sprites.clear()
self.root.configure(background=P['window'])
self.canvas.configure(background=P['window'])
@@ -460,7 +484,7 @@ class App:
self.canvas.bind('<Motion>', self.on_motion)
self.canvas.bind('<Button-1>', self.on_click)
self.canvas.bind('<B1-Motion>', self.on_drag)
self.canvas.bind('<ButtonRelease-1>', lambda e: setattr(self, 'drag', None))
self.canvas.bind('<ButtonRelease-1>', self.on_release)
self.canvas.bind('<Leave>', lambda e: self.set_tb_hover(None))
r.bind('<Alt-F4>', lambda e: self.on_close())
r.protocol('WM_DELETE_WINDOW', self.on_close)
@@ -531,9 +555,11 @@ class App:
return next((i for i, r in enumerate(self.rows_home()) if r.label == label), None)
def back(self):
if self.screen in ('settings', 'uninstall', 'saves', 'customize', 'job'):
if self.screen in ('settings', 'uninstall', 'saves', 'customize', 'job', 'color'):
self.sounds.play('back')
if self.screen == 'settings':
if self.screen == 'color':
self.pick_done()
elif self.screen == 'settings':
self.show('home', self.home_row('Settings'))
elif self.screen == 'uninstall':
self.show('settings')
@@ -560,6 +586,9 @@ class App:
self.draw_title_buttons()
def on_drag(self, e):
if self.pick_drag:
self.picker_at(e.x, e.y, self.pick_drag)
return
if self.drag: # moving the window without the system's help (Linux)
dx, dy = self.drag
self.root.geometry(f'+{e.x_root - dx}+{e.y_root - dy}')
@@ -597,6 +626,11 @@ class App:
if not winsys.start_drag(self.root):
self.drag = (e.x_root - self.root.winfo_x(), e.y_root - self.root.winfo_y())
return
if self.screen == 'color':
part = self.picker_at(e.x, e.y)
if part:
self.pick_drag = part
return
i = self.hit(e.x, e.y)
if i is None:
return
@@ -622,6 +656,12 @@ class App:
else:
self.activate()
def on_release(self, e):
self.drag = None
if self.pick_drag:
self.pick_drag = None
self.pick_changed(final=True)
def on_close(self):
if self.job and self.job.result is None:
self.job.cancel()
@@ -671,6 +711,7 @@ class App:
# another screen slides into place: from the right when it lies deeper, from the left on the way back
deeper = DEPTH.get(screen, 1) >= DEPTH.get(self.screen, 0)
self.slide = float(self.X(44) if deeper else -self.X(44))
self.close_hex()
self.screen = screen
self.rows = getattr(self, 'rows_' + screen)()
idx = self.focusables()
@@ -932,7 +973,17 @@ class App:
rows = [
Row('enum', 'Color Scheme', get=lambda: art.THEMES[art.theme]['label'],
left=lambda: scheme(-1), right=lambda: scheme(1),
desc=('The launcher\'s colours.',)),
desc=('The launcher\'s colours. Custom lets you pick your own.',)),
]
if art.theme == 'custom':
rows += [
Row('value', CUSTOM_LABELS['background'], art.CUSTOM['background'], 'swatch',
on=lambda: self.open_picker('background'), desc=('The color behind the menus.',)),
Row('value', CUSTOM_LABELS['buttons'], art.CUSTOM['buttons'], 'swatch',
on=lambda: self.open_picker('buttons'),
desc=('The color of the buttons, the panels and the top bar.',)),
]
rows += [
Row('value', 'Background', Path(self.settings['background']).name if custom else 'Choose a Picture',
'arrow', on=self.choose_background, desc=bg_desc),
]
@@ -962,14 +1013,210 @@ class App:
]
return rows
# ---- the Custom scheme's colour picker
def custom_colors(self):
return {slot: self.settings.get('custom_' + slot, '') for slot in art.CUSTOM_SLOTS}
def open_picker(self, slot):
h = art.CUSTOM.get(slot) or art.CUSTOM_DEFAULT[slot]
hh, ss, vv = colorsys.rgb_to_hsv(*(int(h[i:i + 2], 16) / 255.0 for i in (1, 3, 5)))
self.pick = {'slot': slot, 'h': hh, 's': ss, 'v': vv}
self.show('color', 0)
def pick_hex(self):
p = self.pick
return art.hexcode(*colorsys.hsv_to_rgb(p['h'], p['s'], p['v']))
def pick_step(self, key, d):
"""Hue by 5 degrees along the hue bar, saturation and brightness by 5 % (the arrows and the gamepad)."""
p = self.pick
if key == 'h':
p['h'] = (round(p['h'] * 72) + d) % 72 / 72.0
else:
p[key] = max(0.0, min(1.0, (round(p[key] * 20) + d) / 20.0))
self.pick_changed(final=True)
def pick_changed(self, final):
"""The picked colour into the settings and onto the screen: the picker at once, the launcher's colours a
moment later (look_soon), so dragging over the square stays smooth. final: saved to launcher.json."""
if not self.pick:
return
self.settings['custom_' + self.pick['slot']] = self.pick_hex()
if final:
self.settings.save()
if self.screen == 'color':
self.rows = self.rows_color()
self.render()
self.look_soon(0 if final else 120)
def look_soon(self, ms):
if self.look_after:
self.root.after_cancel(self.look_after)
self.look_after = self.root.after(ms, self.look_now)
def look_now(self):
self.look_after = None
self.apply_look()
def pick_reset(self):
slot = self.pick['slot']
self.settings['custom_' + slot] = ''
self.settings.save()
art.CUSTOM[slot] = art.CUSTOM_DEFAULT[slot]
self.open_picker(slot)
self.focus = next(i for i, r in enumerate(self.rows) if r.label == 'Reset')
self.apply_look()
def pick_done(self):
slot = self.pick['slot'] if self.pick else 'background'
if self.look_after:
self.root.after_cancel(self.look_after)
self.look_after = None
self.apply_look()
rows = self.rows_customize()
self.show('customize', next((i for i, r in enumerate(rows) if r.label == CUSTOM_LABELS[slot]), 0))
def rows_color(self):
p = self.pick
return [
Row('enum', 'Hue', get=lambda: f'{round(p["h"] * 360) % 360}°',
left=lambda: self.pick_step('h', -1), right=lambda: self.pick_step('h', 1)),
Row('enum', 'Saturation', get=lambda: f'{round(p["s"] * 100)} %',
left=lambda: self.pick_step('s', -1), right=lambda: self.pick_step('s', 1)),
Row('enum', 'Brightness', get=lambda: f'{round(p["v"] * 100)} %',
left=lambda: self.pick_step('v', -1), right=lambda: self.pick_step('v', 1)),
Row('value', 'Hex Code', self.pick_hex().upper(), 'arrow', on=self.type_hex),
Row('divider'),
Row('value', 'Reset', '', 'arrow', on=self.pick_reset),
Row('divider'),
Row('action', 'Done', on=self.pick_done, height=40),
]
def picker_at(self, x, y, part=None):
"""The colour under the mouse at (x, y) on the square or the bar into the picker; which of the two it was
(part: the one being dragged, which takes the mouse also outside it), or None."""
X, p = self.X, self.pick
def inside(box, m=0):
x0, y0, x1, y1 = box
return X(x0) - X(m) <= x <= X(x1) + X(m) and X(y0) - X(m) <= y <= X(y1) + X(m)
def frac(v, a, b):
return max(0.0, min(1.0, (v - X(a)) / max(1, X(b) - X(a))))
sx0, sy0, sx1, sy1 = SQUARE
bx0, _, bx1, _ = BAR
if part == 'square' or (part is None and inside(SQUARE, 4)):
p['s'] = frac(x, sx0, sx1)
p['v'] = 1 - frac(y, sy0, sy1)
part = 'square'
elif part == 'bar' or (part is None and inside(BAR, 8)):
p['h'] = min(frac(x, bx0, bx1), 0.9999)
part = 'bar'
else:
return None
self.pick_changed(final=False)
return part
def type_hex(self):
"""A box over the Hex Code row to type a colour into, like #3A7BD5; Enter takes it, Esc leaves it."""
r = self.focused()
if self.hex_entry or not r or not r.value_rect:
return
x0, y0, x1, y1 = r.value_rect
X = self.X
e = tk.Entry(self.canvas, font=self.f['label'], bg=P['value'], fg=P['value_text'],
insertbackground=P['value_text'], selectbackground=P['orange'], selectforeground=P['on_text'],
relief='flat', justify='center', highlightthickness=1, highlightcolor=P['orange'],
highlightbackground=P['value_border'])
e.insert(0, self.pick_hex().upper())
e.select_range(0, 'end')
self.hex_entry = e
self.canvas.create_window(x0 + X(3), y0 + X(3), anchor='nw', window=e, width=x1 - x0 - X(6),
height=y1 - y0 - X(6), tags='hexentry')
e.focus_set()
def take(ev):
self.hex_typed(e.get())
return 'break'
def leave(ev):
self.close_hex()
return 'break'
for key in ('<Return>', '<KP_Enter>'):
e.bind(key, take)
e.bind('<Escape>', leave)
for key in ('<Up>', '<Down>', '<space>'):
e.bind(key, lambda ev: 'break')
e.bind('<FocusOut>', lambda ev: self.close_hex())
@staticmethod
def parse_hex(text):
"""(r, g, b) in 0..255 of a typed hex code (#3A7BD5, 3A7BD5 or #37D), or None."""
t = text.strip().lstrip('#').lower()
if len(t) == 3:
t = ''.join(ch * 2 for ch in t)
return tuple(int(t[i:i + 2], 16) for i in (0, 2, 4)) if art.HEX.match('#' + t) else None
def hex_typed(self, text):
got = self.parse_hex(text)
if got is None:
self.sounds.play('back')
self.hex_entry.select_range(0, 'end')
return
self.sounds.play('select')
hh, ss, vv = colorsys.rgb_to_hsv(*(v / 255.0 for v in got))
self.pick.update(h=hh, s=ss, v=vv)
self.close_hex()
self.pick_changed(final=True)
def close_hex(self):
if self.hex_entry:
e, self.hex_entry = self.hex_entry, None
self.canvas.delete('hexentry')
e.destroy()
try:
self.root.focus_force()
except tk.TclError:
pass
def draw_picker(self):
"""The colour picker in the description box's place: the slot's name, the colour square of the picked hue
with a ring on the picked colour, the hue bar, and the colour itself with its hex code."""
c, X, s, p = self.canvas, self.X, self.s, self.pick
bx, by, bw, bh = PICKER_BOX
key = ('desc', X(bw), X(bh) // 4)
if key not in self.sprites:
img, pad = art.desc_box(X(bw), X(bh), s, self.see_through())
self.sprites[key] = (art.photo(self.root, img), pad)
pic, pad = self.sprites[key]
c.create_image(X(bx) - pad, X(by) - pad, anchor='nw', image=pic, tags='dyn')
self.text(X(bx + 26), X(by + 34), CUSTOM_LABELS[p['slot']], self.f['heading'], P['text_bright'])
sx0, sy0, sx1, sy1 = SQUARE
sw, sh = X(sx1) - X(sx0), X(sy1) - X(sy0)
hue = round(p['h'], 3)
square = self.sprite(('square', sw, sh, hue), lambda: art.color_square(sw, sh, hue))
c.create_rectangle(X(sx0) - 1, X(sy0) - 1, X(sx0) + sw, X(sy0) + sh, outline=P['value_border'], tags='dyn')
c.create_image(X(sx0), X(sy0), anchor='nw', image=square, tags='dyn')
size = X(18)
mark = self.sprite(('mark', size), lambda: art.picker_mark(size, s))
c.create_image(X(sx0) + round(p['s'] * sw), X(sy0) + round((1 - p['v']) * sh), image=mark, tags='dyn')
bx0, by0, bx1, by1 = BAR
bw_, bh_ = X(bx1) - X(bx0), X(by1) - X(by0)
bar = self.sprite(('hues', bw_, bh_), lambda: art.hue_bar(bw_, bh_))
c.create_rectangle(X(bx0) - 1, X(by0) - 1, X(bx0) + bw_, X(by0) + bh_, outline=P['value_border'], tags='dyn')
c.create_image(X(bx0), X(by0), anchor='nw', image=bar, tags='dyn')
c.create_image(X(bx0) + round(p['h'] * bw_), X(by0) + bh_ // 2, image=mark, tags='dyn')
hexc = self.pick_hex()
c.create_rectangle(X(bx0), X(452), X(bx0 + 64), X(500), fill=hexc, outline=P['value_border'], tags='dyn')
self.text(X(bx0 + 80), X(476), hexc.upper(), self.f['label'], P['text_bright'])
self.text(X(bx + 26), X(526), 'Click or drag the square and the bar.', self.f['small'], P['muted'])
def steam_row(self):
"""Add to Steam: the game in the Steam library, started from there without the launcher (launcher/steam.py)."""
found = steam.find_steam()
desc = ('Add Ocarina of Time to your Steam library as The Legend of Zelda Ocarina of Time, with Navi as its '
'icon and the title screen\'s moonlit field and logo as its pictures, all taken from your game. '
'Playing it from Steam starts the game straight away.',
'Steam closes while the shortcut is written and starts again with it. Select the row again after an '
'update of the game to refresh it.')
desc = ('Adds the game to your Steam library with its own icon and artwork, so you can start it from Steam.',
'Steam restarts while it is added.')
if self.steam_message:
desc = (self.steam_message,) + desc
if self.steam_busy:
@@ -996,7 +1243,7 @@ class App:
self.show('customize', self.focus)
return
self.steam_busy = True
self.steam_message = 'Making the pictures from your game and adding it to Steam…'
self.steam_message = 'Adding to Steam…'
self.sounds.play('select')
self.show('customize', self.focus)
dump = self.settings.get('dump')
@@ -1728,7 +1975,10 @@ class App:
y += h + self.row_gap
self.draw_status()
self.draw_cursor()
self.draw_desc()
if self.screen == 'color' and self.pick:
self.draw_picker()
else:
self.draw_desc()
self.slide_applied = int(self.slide)
if self.slide_applied: # drawn in place, then put where the slide has got to (step_slide)
c.move('dyn', self.slide_applied, 0)
@@ -1866,6 +2116,16 @@ class App:
self.canvas.create_text(sx, cy, text=r.value, font=vfont, fill=P['on_text'], anchor='w', tags='dyn')
img = self.sprite(('chev', cw, ch, False, 'on'), lambda: art.chevron(cw, ch, P['on_text']))
c.create_image(sx + label_w + X(10), cy, anchor='w', image=img, tags='dyn')
elif r.style == 'swatch': # a colour of the Custom scheme: a patch of it and its hex code
cw, ch = X(9), X(12)
img = self.sprite(('chev', cw, ch, False, 'dim'), lambda: art.chevron(cw, ch, P['chevron_dim']))
c.create_image(x1 - X(16), cy, anchor='e', image=img, tags='dyn')
tw = vfont.measure(r.value.upper())
sw = X(26)
sx = (vx0 + x1 - X(16) - cw - X(10)) // 2 - (sw + X(10) + tw) // 2
c.create_rectangle(sx, cy - X(9), sx + sw, cy + X(9), fill=r.value, outline=P['value_border'], tags='dyn')
c.create_text(sx + sw + X(10), cy, text=r.value.upper(), font=vfont, fill=P['value_text'], anchor='w',
tags='dyn')
elif r.style == 'arrow':
cw, ch = X(9), X(12)
img = self.sprite(('chev', cw, ch, False, 'dim'), lambda: art.chevron(cw, ch, P['chevron_dim']))

View File

@@ -7,7 +7,9 @@ shape is a picture; flat rectangles and text stay canvas items.
Colours follow the game's options menu (docs/launcher.md, "Look"). Sizes are in logical pixels times the display
scale s. PALETTE holds the colours of the colour scheme in use: set_theme fills it from THEMES, each scheme the
first one with its woods, accents, backdrop and glow turned to other hues.
first one with its woods, accents, backdrop and glow turned to other hues. The Custom scheme takes two colours the
player picks on a colour square (color_square, hue_bar): one for the backdrop, one for the buttons, panels and title
band.
"""
import base64
import colorsys
@@ -75,9 +77,18 @@ THEMES = {
'scene': (222, 0.55, 1.0, 0.05), 'glow': (48, 1.0, 1.0, 0.5), 'text': (48, 0.45, 1.02, 0)},
'shadow': {'label': 'Shadow', 'wood': (268, 0.55, 0.78, 0), 'accent': (286, 0.75, 1.0, 0),
'scene': (272, 0.9, 0.8, 0.2), 'glow': (280, 1.0, 1.0, 0.2), 'text': (270, 0.5, 1.0, 0)},
'custom': {'label': 'Custom'},
}
DEFAULT_THEME = 'forest'
# The Custom scheme: each colour the player picks takes the place of one colour of the first scheme, and the rest of
# that colour's group follows it, lighter and darker as in the first scheme (follow). Its two colours start as the
# first scheme's.
CUSTOM_SLOTS = {'background': ('scene', 'tint_mid'), 'buttons': ('wood', 'label_mid')}
CUSTOM_DEFAULT = {slot: BASE[ref] for slot, (_, ref) in CUSTOM_SLOTS.items()}
CUSTOM = dict(CUSTOM_DEFAULT)
HEX = re.compile(r'^#[0-9a-f]{6}$')
def recolor(hexcolor, hue, sat=1.0, light=1.0, add=0.0):
"""hexcolor turned to hue (degrees; None keeps its own), its saturation times sat plus add, its lightness times
@@ -91,8 +102,59 @@ def recolor(hexcolor, hue, sat=1.0, light=1.0, add=0.0):
return '#%02x%02x%02x' % tuple(int(round(v * 255)) for v in (r, g, b))
def hls(hexcolor):
h = hexcolor.lstrip('#')
return colorsys.rgb_to_hls(*(int(h[i:i + 2], 16) / 255.0 for i in (0, 2, 4)))
def hexcode(r, g, b):
"""#rrggbb of r, g, b in 0..1."""
return '#%02x%02x%02x' % tuple(int(round(max(0.0, min(1.0, v)) * 255)) for v in (r, g, b))
def follow(hexcolor, ref, chosen):
"""hexcolor moved as ref moves to chosen: chosen's hue, and its lightness and saturation shifted the way ref's
shift, so ref becomes chosen exactly and the colours lighter or darker than ref stay so."""
_, l, s = hls(hexcolor)
_, rl, rs = hls(ref)
ch, cl, cs = hls(chosen)
def move(v, r, c):
if c <= r:
return v * c / r if r > 0 else c
return v + (1 - v) * (c - r) / (1 - r) if r < 1 else c
return hexcode(*colorsys.hls_to_rgb(ch, max(0.0, min(1.0, move(l, rl, cl))), max(0.0, min(1.0, move(s, rs, cs)))))
def luminance(hexcolor):
h = hexcolor.lstrip('#')
r, g, b = (int(h[i:i + 2], 16) / 255.0 for i in (0, 2, 4))
return 0.2126 * r + 0.7152 * g + 0.0722 * b
def custom_palette(colors):
"""The Custom scheme's colours from {slot: '#rrggbb'} (CUSTOM_SLOTS); a slot left out or not a colour keeps the
first scheme's. Light buttons get dark text, so the labels stay readable on them."""
pal = dict(BASE)
for slot, (group, ref) in CUSTOM_SLOTS.items():
c = str((colors or {}).get(slot) or '').lower()
if not HEX.match(c) or c == BASE[ref]: # the first scheme's own colour: its colours as written
continue
for k in GROUPS[group]:
pal[k] = follow(BASE[k], BASE[ref], c)
if slot == 'buttons' and luminance(c) > 0.5:
h = hls(c)[0] * 360
for k in GROUPS['text']:
pal[k] = recolor(BASE[k], h, 0.5, 0.18)
pal['text_shadow'] = follow(BASE['label_top'], BASE[ref], c)
pal['chevron_dim'] = recolor(BASE['chevron_dim'], h, 0.5, 0.3)
return pal
def theme_palette(name):
"""The colours of scheme name (an unknown name: the first scheme's)."""
if name == 'custom':
return custom_palette(CUSTOM)
t = THEMES.get(name) or THEMES[DEFAULT_THEME]
pal = dict(BASE)
for group, keys in GROUPS.items():
@@ -107,9 +169,14 @@ PALETTE = dict(BASE)
theme = DEFAULT_THEME
def set_theme(name):
"""Fills PALETTE (in place: the window holds a reference) with scheme name's colours; the name in effect."""
def set_theme(name, custom=None):
"""Fills PALETTE (in place: the window holds a reference) with scheme name's colours; the name in effect.
custom: the Custom scheme's colours, {slot: '#rrggbb'} (CUSTOM_SLOTS)."""
global theme
if custom is not None:
CUSTOM.clear()
CUSTOM.update(CUSTOM_DEFAULT)
CUSTOM.update({k: v.lower() for k, v in custom.items() if k in CUSTOM_SLOTS and HEX.match(str(v).lower())})
theme = name if name in THEMES else DEFAULT_THEME
PALETTE.clear()
PALETTE.update(theme_palette(theme))
@@ -462,17 +529,19 @@ FILIGREE_PATHS = (
# ---------------------------------------------------------------- the window's pieces
def backdrop(W, H, s, picture=None, dim=0.4):
def backdrop(W, H, s, picture=None, dim=0.4, top=0):
"""The whole window behind the panels: a dim misty field under a see-through tint of the colour scheme, darker at
the sides. picture: the player's own background instead of the field, an H x W x 3 array in 0..1 (the window's
size), darkened by dim (0 as it is .. 1 the scheme's darkest colour) so the text over it stays readable."""
the sides. picture: the player's own background instead of the field, an array of H - top rows and W columns in
0..1 put below the title band (top: where the band ends), darkened by dim (0 as it is .. 1 the scheme's darkest
colour) so the text over it stays readable."""
P = PALETTE
img = new(H, W, P['window'], 1.0)
pad = int(45 * s)
vig = kept(('vignette', W, H, s), lambda: 1 - box_blur(np.pad(rect_mask(H, W, 0, 0, W, H), pad,
constant_values=0), 45 * s)[pad:-pad, pad:-pad])
if picture is not None:
img[..., :3] = picture[:H, :W]
part = picture[:H - top, :W]
img[top:top + part.shape[0], :part.shape[1], :3] = part
paint(img, np.ones((H, W), dtype=np.float32), P['tint_edge'], max(0.0, min(1.0, dim)))
paint(img, np.clip(vig * 1.6, 0, 1), P['vignette'], 0.45)
return img
@@ -495,6 +564,54 @@ def backdrop(W, H, s, picture=None, dim=0.4):
return img
def hsv_rgb(h, s, v):
"""HSV to RGB on arrays (or numbers) in 0..1; an H... x 3 array."""
h, s, v = (np.asarray(a, dtype=np.float32) for a in (h, s, v))
h6 = (h % 1.0) * 6
c = v * s
x = c * (1 - np.abs(h6 % 2 - 1))
z = np.zeros_like(c)
k = np.floor(h6).astype(int) % 6
r = np.choose(k, [c, x, z, z, x, c])
g = np.choose(k, [x, c, c, x, z, z])
b = np.choose(k, [z, z, x, c, c, x])
m = v - c
return np.stack([r + m, g + m, b + m], axis=-1)
def color_square(w, h, hue):
"""The colour square of the Custom scheme's picker for one hue (0..1): saturation from grey on the left to the
full colour on the right, brightness from black at the bottom to full at the top."""
sat = (np.arange(w, dtype=np.float32) + 0.5) / w
val = 1 - (np.arange(h, dtype=np.float32) + 0.5) / h
img = new(h, w)
img[..., :3] = hsv_rgb(np.full((h, w), hue), np.broadcast_to(sat, (h, w)), np.broadcast_to(val[:, None], (h, w)))
img[..., 3] = 1
return img
def hue_bar(w, h):
"""The picker's hue bar: every hue from red on the left through yellow, green, cyan, blue and magenta to red."""
hue = (np.arange(w, dtype=np.float32) + 0.5) / w
img = new(h, w)
img[..., :3] = hsv_rgb(np.broadcast_to(hue, (h, w)), np.ones((h, w)), np.ones((h, w)))
img[..., 3] = 1
return img
def picker_mark(size, s):
"""The ring that shows the picked colour on the square and the bar: white with a dark edge inside and out."""
t = (np.arange(size, dtype=np.float32) + 0.5) - size / 2
d = np.hypot(t[None, :], t[:, None])
r = size / 2 - 1.5 * s
img = new(size, size, '#000000')
dark = np.clip(1.6 * s - np.abs(d - r) + 0.5, 0, 1) * 0.7
white = np.clip(0.9 * s - np.abs(d - r) + 0.5, 0, 1)
img[..., 3] = np.maximum(dark, white)
img[..., :3] = np.where(white[..., None] > dark[..., None] * 0.5, 1.0, 0.0)
return img
def spark(size, alpha=1.0):
"""One spark of the dust drifting over the backdrop: a soft round dot of the scheme's spark colour, size pixels
across, brightest in its middle."""

View File

@@ -1,11 +1,13 @@
"""The player's own background picture (Customize Launcher): read a picture file into a numpy array, fit it to the
window's shape and keep that copy in data/background.npy, so the launcher shows it without the file it came from.
shape of the window below its title band and keep that copy in data/background.npy, so the launcher shows it without
the file it came from. Fitting cuts the picture to that shape around its middle and scales it evenly: it is never
stretched.
Pillow reads the file where the launcher's Python has it (a release's does: tools/requirements-launcher.txt), turned
the way its EXIF data says. Without Pillow (a checkout's Python may lack it), GDI+ reads it on Windows (PNG, JPEG,
BMP, GIF, TIFF) and Tk elsewhere (PNG, GIF; the pixels come over as a PPM file). The kept copy is 8-bit RGB at
KEEP_W x KEEP_H, 1.6 times the window's logical size: enough for a display scaled to 200 %, and five megabytes on
disk.
KEEP_W x KEEP_H, 1.6 times the logical size of the window below the band: enough for a display scaled to 200 %,
and four and a half megabytes on disk.
"""
import ctypes
import os
@@ -14,7 +16,7 @@ from pathlib import Path
import numpy as np
KEEP_W, KEEP_H = 1600, 1024 # the window's 1000 x 640 times 1.6
KEEP_W, KEEP_H = 1600, 928 # the window's 1000 x 580 below the title band, times 1.6
MAX_SIDE, MAX_PIXELS = 16384, 120_000_000
try:
from PIL import Image, ImageOps
@@ -180,9 +182,9 @@ def resize(img, w, h):
return top * (1 - fy) + bot * fy
def cover(img, w, h):
"""img cut to the shape w : h around its middle and resized to w x h, so it fills the window with nothing
stretched; uint8."""
def cover(img, w, h, as_float=False):
"""img cut to the shape w : h around its middle and resized to w x h, so it fills the room with nothing
stretched; uint8, or float32 in 0..255 with as_float."""
H, W = img.shape[:2]
if W * h > H * w: # wider than the window: cut the sides
cw = max(1, round(H * w / h))
@@ -193,6 +195,8 @@ def cover(img, w, h):
y = (H - ch) // 2
img = img[y:y + ch]
out = resize(img, w, h)
if as_float:
return np.clip(out.astype(np.float32), 0, 255)
return np.clip(np.rint(out), 0, 255).astype(np.uint8)
@@ -207,12 +211,22 @@ def keep(path, store, master=None):
return fitted
def kept_shape(store):
"""(height, width) of the kept background, or None."""
try:
a = np.load(store, mmap_mode='r', allow_pickle=False)
return a.shape[:2] if a.ndim == 3 else None
except (OSError, ValueError):
return None
def kept(store, w, h):
"""The kept background at w x h as float32 in 0..1, or None when there is none (or it is not what keep wrote)."""
"""The kept background at w x h as float32 in 0..1, cut to that shape when it has another (one kept by an older
launcher for the whole window), or None when there is none (or it is not what keep wrote)."""
try:
a = np.load(store, allow_pickle=False)
except (OSError, ValueError):
return None
if a.dtype != np.uint8 or a.ndim != 3 or a.shape[2] != 3 or a.shape[0] < 8 or a.shape[1] < 8:
return None
return np.clip(resize(a, w, h).astype(np.float32) / 255.0, 0, 1)
return cover(a, w, h, as_float=True) / 255.0

View File

@@ -203,6 +203,15 @@ def states(app):
app.show('home', 0)
s['theme'] = was
def custom_picker(): # the Custom scheme with two picked colours, and its picker on the button colour
from . import art
was = {k: s.get(k) for k in ('theme', 'custom_background', 'custom_buttons')}
s.update(theme='custom', custom_background='#3a1d5c', custom_buttons='#2f6fb0')
app.apply_look()
app.open_picker('buttons')
s.update(was)
art.set_theme(was['theme'], app.custom_colors()) # the next screen's colours; this one is drawn already
def restore_scheme():
app.apply_look()
app.show('home', 0)
@@ -211,7 +220,8 @@ def states(app):
('4-update-ready', update_ready), ('5-updating', updating), ('6-settings', settings),
('7-build-failed', failed), ('8-uninstall', uninstall), ('9-import-saves', import_saves),
('10-shaders', shaders), ('11-update-staged', update_staged), ('12-export-save', export_save),
('13-customize', customize), ('14-color-scheme', color_scheme), ('15-first-scheme', restore_scheme)]
('13-customize', customize), ('14-color-scheme', color_scheme), ('15-custom-picker', custom_picker),
('16-first-scheme', restore_scheme)]
def run(app, shots):

View File

@@ -19,7 +19,8 @@ Run: python tests/launcher_test.py (Python 3.14 for the zstd tests; the window
step with the system's C compiler, and its windres call under folders with spaces (a script in windres's place)
- jobs: an install driven by a fake make_game.py, with and without the prompts row
- Add to Steam: the binary shortcuts file read and written back unchanged, a shortcut added and updated in place
- the look: the colour schemes, the background picture's fitting and kept copy, the sound effects (low by default,
- the look: the colour schemes with the Custom one, its colour square and a typed hex code, the background picture's
fitting below the title band and kept copy, the sound effects (low by default,
only the game's own select and back sounds, decoded from a made-up .bwav)
- the window: --selftest draws every screen (skipped without a display)
"""
@@ -2709,6 +2710,71 @@ class LookTest(Tmp):
with self.assertRaises(pic.PictureError):
pic.load(self.tmp / 'gone.png')
def test_the_custom_scheme(self):
art = self.art
self.assertEqual(art.custom_palette({}), art.BASE) # nothing picked yet: the first scheme's colours
pal = art.custom_palette({'background': '#3A7BD5', 'buttons': '#802020'})
self.assertEqual(pal['tint_mid'], '#3a7bd5') # the picked colours exactly where they stand in
self.assertEqual(pal['label_mid'], '#802020')
self.assertEqual(pal['orange'], art.BASE['orange']) # the other groups stay
for group, ref in (('scene', 'tint_mid'), ('wood', 'label_mid')):
for k in art.GROUPS[group]: # lighter than the picked colour where the first scheme's is lighter
if art.hls(art.BASE[k])[1] > art.hls(art.BASE[ref])[1] + 0.02:
self.assertGreater(art.hls(pal[k])[1], art.hls(pal[ref])[1], k)
self.assertGreater(art.luminance(pal['text']), 0.6) # light text on dark buttons
light = art.custom_palette({'buttons': '#f0e0a0'})
self.assertLess(art.luminance(light['text']), 0.3) # and dark text on light ones
self.assertEqual(art.custom_palette({'buttons': 'red', 'background': None}), art.BASE)
held = art.PALETTE
try:
self.assertEqual(art.set_theme('custom', {'buttons': '#802020', 'other': '#000000'}), 'custom')
self.assertEqual(held['label_mid'], '#802020')
self.assertEqual(art.CUSTOM, {'background': art.BASE['tint_mid'], 'buttons': '#802020'})
art.set_theme('custom', {})
self.assertEqual(dict(held), art.BASE)
finally:
art.set_theme('forest', {})
def test_the_colour_square(self):
import numpy as np
art = self.art
sq = art.color_square(40, 30, 0.0) # red
self.assertEqual(sq.shape, (30, 40, 4))
self.assertTrue(np.allclose(sq[0, -1, :3], [1, 0, 0], atol=0.05)) # top right: the full colour
self.assertLess(sq[-1, :, :3].max(), 0.05) # the bottom row: black
self.assertLess(np.ptp(sq[0, 0, :3]), 0.05) # left: grey
bar = art.hue_bar(60, 4)
self.assertTrue(np.allclose(bar[0, 20, :3], [0, 1, 0], atol=0.1)) # a third of the way: green
self.assertTrue(np.allclose(bar[0, 40, :3], [0, 0, 1], atol=0.1)) # two thirds: blue
def test_a_typed_hex_code(self):
try:
from launcher.ui.app import App
except ImportError:
self.skipTest('needs tkinter')
parse = App.parse_hex
self.assertEqual(parse('#3A7BD5'), (58, 123, 213))
self.assertEqual(parse(' 3a7bd5 '), (58, 123, 213))
self.assertEqual(parse('#37d'), (0x33, 0x77, 0xdd))
self.assertIsNone(parse('#3A7BD'))
self.assertIsNone(parse('blue'))
def test_the_picture_starts_below_the_band_and_is_never_stretched(self):
import numpy as np
art, pic = self.art, self.picture
store = self.tmp / 'background.npy'
old = np.zeros((1024, 1600, 3), dtype=np.uint8) # a copy an older launcher kept for the window
old[:, :800, 0] = 255 # left half red: a circle stays a circle
np.save(store, old)
self.assertEqual(pic.kept_shape(store), (1024, 1600))
back = pic.kept(store, 1000, 580) # cut to the new shape, not squeezed
self.assertEqual(back.shape, (580, 1000, 3))
self.assertGreater(back[:, 490, 0].min(), 0.95)
self.assertLess(back[:, 510, 0].max(), 0.05)
img = art.backdrop(200, 128, 1.0, np.ones((116, 200, 3), dtype=np.float32), 0.0, top=12)
self.assertLess(img[6, 100, :3].max(), 0.2) # under the band: the scheme's colour
self.assertGreater(img[20, 100, :3].min(), 0.7) # from the band's end on: the picture
def test_ppm(self):
import numpy as np
px = bytes(range(18))