mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 23:19:57 -04:00
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:
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user