mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 14:39:58 -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:
@@ -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']))
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user