495 lines
18 KiB
Python
495 lines
18 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
# view/widgets/bars/goth_burger_topbar.py
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import tkinter as tk
|
||
|
|
from PIL import Image, ImageDraw, ImageGrab, ImageTk
|
||
|
|
|
||
|
|
from resources.code_res.game_constants import (
|
||
|
|
BG_COLOR,
|
||
|
|
FONT_COLOR_HEADING_SUB,
|
||
|
|
FONT_COLOR_STATUS_LOSS,
|
||
|
|
FONT_COLOR_TITLE_MAIN,
|
||
|
|
FONT_SIZE_BODY,
|
||
|
|
FONT_SIZE_SMALL_MIN,
|
||
|
|
SUBTLE_BORDER,
|
||
|
|
UI_ACCENT_GOLD,
|
||
|
|
)
|
||
|
|
from resources.code_res.i18n import t
|
||
|
|
from view.widgets.buttons.button_art_compositor import ButtonArtCompositor
|
||
|
|
from view.widgets.buttons.image_button import ImageButton
|
||
|
|
|
||
|
|
COMPACT_TOPBAR_HEIGHT = 44
|
||
|
|
DRAWER_BG_COLOR = "#171421" # Leicht ausgegrautes Dunkel-Violett passend zum Thema
|
||
|
|
_ANIM_STEPS = 8
|
||
|
|
_ANIM_STEP_MS = 15
|
||
|
|
|
||
|
|
_BURGER_BTN_CACHE: dict[tuple[int, int, bool], ImageTk.PhotoImage] = {}
|
||
|
|
|
||
|
|
|
||
|
|
def _get_burger_button_photo(assets, w: int, h: int, hovered: bool) -> ImageTk.PhotoImage:
|
||
|
|
key = (w, h, hovered)
|
||
|
|
if key in _BURGER_BTN_CACHE:
|
||
|
|
return _BURGER_BTN_CACHE[key]
|
||
|
|
|
||
|
|
src = assets.raw_btn_purple if hovered else assets.raw_btn_default
|
||
|
|
if src is not None:
|
||
|
|
bg, _ = ButtonArtCompositor.scale_button_3slice(src, w, h)
|
||
|
|
else:
|
||
|
|
bg = Image.new("RGBA", (w, h), (26, 20, 38, 240))
|
||
|
|
|
||
|
|
draw = ImageDraw.Draw(bg)
|
||
|
|
bar_col = UI_ACCENT_GOLD if hovered else "#ffffff"
|
||
|
|
shadow_col = "#09060e"
|
||
|
|
cx = w // 2
|
||
|
|
half_len = 9
|
||
|
|
for dy in (-6, 0, 6):
|
||
|
|
y = h // 2 + dy
|
||
|
|
draw.rounded_rectangle(
|
||
|
|
(cx - half_len + 1, y - 1 + 1, cx + half_len + 1, y + 1 + 1),
|
||
|
|
radius=1,
|
||
|
|
fill=shadow_col,
|
||
|
|
)
|
||
|
|
draw.rounded_rectangle(
|
||
|
|
(cx - half_len, y - 1, cx + half_len, y + 1),
|
||
|
|
radius=1,
|
||
|
|
fill=bar_col,
|
||
|
|
)
|
||
|
|
|
||
|
|
photo = ImageTk.PhotoImage(bg)
|
||
|
|
_BURGER_BTN_CACHE[key] = photo
|
||
|
|
return photo
|
||
|
|
|
||
|
|
|
||
|
|
class CompactBurgerTopbar(tk.Canvas):
|
||
|
|
"""
|
||
|
|
Schlanke Kompakt-/Mobile-Kopfleiste (44 px hoch):
|
||
|
|
- Öffnet ein vollhohes Slide-In-Seitenmenü von links mit Live-Abdunklung der aktiven Ansicht.
|
||
|
|
- Während das Menü offen ist, sind alle Elemente darunter gesperrt; Klick in den
|
||
|
|
abgedunkelten Bereich, Escape oder erneuter Klick auf das Burger-Icon gleitet es zurück.
|
||
|
|
"""
|
||
|
|
|
||
|
|
def __init__(self, parent, controller_bar):
|
||
|
|
super().__init__(
|
||
|
|
parent,
|
||
|
|
height=COMPACT_TOPBAR_HEIGHT,
|
||
|
|
bg=BG_COLOR,
|
||
|
|
bd=0,
|
||
|
|
highlightthickness=0,
|
||
|
|
)
|
||
|
|
self._bar = controller_bar
|
||
|
|
self._root_win = controller_bar._root_win
|
||
|
|
self.assets = controller_bar.assets
|
||
|
|
self.sounds = controller_bar.sounds
|
||
|
|
|
||
|
|
self._bg_slice_photo: ImageTk.PhotoImage | None = None
|
||
|
|
self._btn_norm_ph: ImageTk.PhotoImage | None = None
|
||
|
|
self._btn_hov_ph: ImageTk.PhotoImage | None = None
|
||
|
|
self._btn_item_id: int | None = None
|
||
|
|
self._last_render_key: tuple[int, int, int, int, int] = (0, 0, 0, 0, 0)
|
||
|
|
|
||
|
|
self._backdrop_cv: tk.Canvas | None = None
|
||
|
|
self._backdrop_item_id: int | None = None
|
||
|
|
self._backdrop_frames: list[ImageTk.PhotoImage] = []
|
||
|
|
self._drawer_panel: tk.Canvas | None = None
|
||
|
|
self._drawer_refs: list = []
|
||
|
|
self._drawer_buttons: list[ImageButton] = []
|
||
|
|
self._panel_w: int = 272
|
||
|
|
self._anim_job: str | None = None
|
||
|
|
self._is_closing: bool = False
|
||
|
|
self._esc_bind_id: str | None = None
|
||
|
|
|
||
|
|
self.bind("<Configure>", self._on_configure)
|
||
|
|
self.bind("<Destroy>", self._on_destroy)
|
||
|
|
|
||
|
|
@property
|
||
|
|
def total_height(self) -> int:
|
||
|
|
return COMPACT_TOPBAR_HEIGHT
|
||
|
|
|
||
|
|
def _on_destroy(self, event=None):
|
||
|
|
if event is not None and event.widget is not self:
|
||
|
|
return
|
||
|
|
self.close_drawer(animate=False)
|
||
|
|
|
||
|
|
def _on_configure(self, event):
|
||
|
|
if event.widget is not self or event.width < 60:
|
||
|
|
return
|
||
|
|
self.sync_layout()
|
||
|
|
|
||
|
|
def sync_layout(self):
|
||
|
|
if not self.winfo_exists():
|
||
|
|
return
|
||
|
|
rw = max(1, self._root_win.winfo_width())
|
||
|
|
rh = max(1, self._root_win.winfo_height())
|
||
|
|
w = max(1, self.winfo_width())
|
||
|
|
if w < 60 or rw < 60:
|
||
|
|
return
|
||
|
|
|
||
|
|
ox = max(0, min(max(0, rw - w), self.winfo_rootx() - self._root_win.winfo_rootx()))
|
||
|
|
oy = max(
|
||
|
|
0,
|
||
|
|
min(
|
||
|
|
max(0, rh - COMPACT_TOPBAR_HEIGHT),
|
||
|
|
self.winfo_rooty() - self._root_win.winfo_rooty(),
|
||
|
|
),
|
||
|
|
)
|
||
|
|
|
||
|
|
key = (w, rw, rh, ox, oy)
|
||
|
|
if key == self._last_render_key:
|
||
|
|
return
|
||
|
|
self._last_render_key = key
|
||
|
|
|
||
|
|
self._bg_slice_photo = self.assets.get_bg_patch_photo(
|
||
|
|
rw, rh, ox, oy, min(w, rw - ox), min(COMPACT_TOPBAR_HEIGHT, rh - oy)
|
||
|
|
)
|
||
|
|
self.delete("all")
|
||
|
|
if self._bg_slice_photo is not None:
|
||
|
|
self.create_image(0, 0, image=self._bg_slice_photo, anchor="nw", tags="c_bg")
|
||
|
|
|
||
|
|
bw, bh = 48, 34
|
||
|
|
bx, by = 12 + bw // 2, COMPACT_TOPBAR_HEIGHT // 2
|
||
|
|
self._btn_norm_ph = _get_burger_button_photo(self.assets, bw, bh, False)
|
||
|
|
self._btn_hov_ph = _get_burger_button_photo(self.assets, bw, bh, True)
|
||
|
|
|
||
|
|
self._btn_item_id = self.create_image(
|
||
|
|
bx, by, image=self._btn_norm_ph, anchor="center", tags="burger_hit"
|
||
|
|
)
|
||
|
|
hit = self.create_rectangle(
|
||
|
|
bx - bw // 2, by - bh // 2, bx + bw // 2, by + bh // 2,
|
||
|
|
fill="", outline="", width=0, tags="burger_hit",
|
||
|
|
)
|
||
|
|
self.tag_raise(hit)
|
||
|
|
|
||
|
|
self.tag_bind("burger_hit", "<Enter>", lambda _e: self._set_hover(True))
|
||
|
|
self.tag_bind("burger_hit", "<Leave>", lambda _e: self._set_hover(False))
|
||
|
|
self.tag_bind("burger_hit", "<Button-1>", self._toggle_drawer)
|
||
|
|
|
||
|
|
def _set_hover(self, hov: bool):
|
||
|
|
self.configure(cursor="hand2" if hov else "")
|
||
|
|
if self._btn_item_id is not None:
|
||
|
|
ph = self._btn_hov_ph if hov else self._btn_norm_ph
|
||
|
|
if ph is not None:
|
||
|
|
self.itemconfigure(self._btn_item_id, image=ph)
|
||
|
|
|
||
|
|
def _cancel_anim(self):
|
||
|
|
if self._anim_job is not None:
|
||
|
|
try:
|
||
|
|
self.after_cancel(self._anim_job)
|
||
|
|
except Exception:
|
||
|
|
pass
|
||
|
|
self._anim_job = None
|
||
|
|
|
||
|
|
def _capture_live_window_pil(self, rw: int, rh: int) -> Image.Image:
|
||
|
|
"""Greift einmalig den aktuellen Fensterinhalt ab, damit die Spielansicht echt durchscheint."""
|
||
|
|
try:
|
||
|
|
self._root_win.update_idletasks()
|
||
|
|
rx = self._root_win.winfo_rootx()
|
||
|
|
ry = self._root_win.winfo_rooty()
|
||
|
|
snap = ImageGrab.grab(bbox=(rx, ry, rx + rw, ry + rh))
|
||
|
|
if snap.size != (rw, rh):
|
||
|
|
snap = snap.resize((rw, rh), Image.Resampling.BILINEAR)
|
||
|
|
return snap.convert("RGB")
|
||
|
|
except Exception:
|
||
|
|
fb = self.assets.get_window_bg_pil(rw, rh)
|
||
|
|
if fb is not None:
|
||
|
|
return fb.convert("RGB")
|
||
|
|
return Image.new("RGB", (rw, rh), (15, 12, 22))
|
||
|
|
|
||
|
|
def _build_dim_frames(self, base_rgb: Image.Image) -> list[ImageTk.PhotoImage]:
|
||
|
|
"""Erzeugt vorab die weichen Abdunklungs-Stufen für 0 ms Lag während der Gleitanimation."""
|
||
|
|
dark_target = Image.new("RGB", base_rgb.size, (7, 5, 12))
|
||
|
|
frames: list[ImageTk.PhotoImage] = []
|
||
|
|
max_alpha = 0.58
|
||
|
|
for step in range(_ANIM_STEPS + 1):
|
||
|
|
t_norm = step / _ANIM_STEPS
|
||
|
|
eased = 1.0 - (1.0 - t_norm) ** 3
|
||
|
|
blended = Image.blend(base_rgb, dark_target, eased * max_alpha)
|
||
|
|
frames.append(ImageTk.PhotoImage(blended))
|
||
|
|
return frames
|
||
|
|
|
||
|
|
def _toggle_drawer(self, _event=None):
|
||
|
|
self.sounds.play("click")
|
||
|
|
if self._backdrop_cv is not None and self._backdrop_cv.winfo_exists():
|
||
|
|
self.close_drawer(animate=True)
|
||
|
|
return
|
||
|
|
self._open_drawer()
|
||
|
|
|
||
|
|
def close_drawer(self, animate: bool = False, on_closed=None):
|
||
|
|
self._cancel_anim()
|
||
|
|
if self._esc_bind_id is not None:
|
||
|
|
try:
|
||
|
|
self._root_win.unbind("<Escape>", self._esc_bind_id)
|
||
|
|
except Exception:
|
||
|
|
pass
|
||
|
|
self._esc_bind_id = None
|
||
|
|
|
||
|
|
if (
|
||
|
|
not animate
|
||
|
|
or self._backdrop_cv is None
|
||
|
|
or not self._backdrop_cv.winfo_exists()
|
||
|
|
or self._drawer_panel is None
|
||
|
|
or not self._drawer_panel.winfo_exists()
|
||
|
|
):
|
||
|
|
self._destroy_drawer_Now()
|
||
|
|
if callable(on_closed):
|
||
|
|
on_closed()
|
||
|
|
return
|
||
|
|
|
||
|
|
if self._is_closing:
|
||
|
|
return
|
||
|
|
self._is_closing = True
|
||
|
|
self._run_slide_step(_ANIM_STEPS - 1, opening=False, on_done=on_closed)
|
||
|
|
|
||
|
|
def _destroy_drawer_Now(self):
|
||
|
|
self._cancel_anim()
|
||
|
|
self._is_closing = False
|
||
|
|
for b in self._drawer_buttons:
|
||
|
|
try:
|
||
|
|
if b.winfo_exists():
|
||
|
|
b.destroy()
|
||
|
|
except Exception:
|
||
|
|
pass
|
||
|
|
self._drawer_buttons.clear()
|
||
|
|
self._drawer_refs.clear()
|
||
|
|
self._backdrop_frames.clear()
|
||
|
|
self._backdrop_item_id = None
|
||
|
|
|
||
|
|
for wgt in (self._drawer_panel, self._backdrop_cv):
|
||
|
|
if wgt is not None:
|
||
|
|
try:
|
||
|
|
if wgt.winfo_exists():
|
||
|
|
wgt.destroy()
|
||
|
|
except Exception:
|
||
|
|
pass
|
||
|
|
self._drawer_panel = None
|
||
|
|
self._backdrop_cv = None
|
||
|
|
|
||
|
|
def _open_drawer(self):
|
||
|
|
self.close_drawer(animate=False)
|
||
|
|
rw = max(320, self._root_win.winfo_width())
|
||
|
|
rh = max(420, self._root_win.winfo_height())
|
||
|
|
|
||
|
|
# 1. Live-Ansicht abgreifen, BEVOR das sperrende Backdrop-Canvas darübergelegt wird
|
||
|
|
live_rgb = self._capture_live_window_pil(rw, rh)
|
||
|
|
self._backdrop_frames = self._build_dim_frames(live_rgb)
|
||
|
|
|
||
|
|
# 2. Vollflächiger Backdrop sperrt alle Klicks auf das Spiel darunter & dunkelt sanft ab
|
||
|
|
ov = tk.Canvas(self._root_win, bg=BG_COLOR, bd=0, highlightthickness=0)
|
||
|
|
ov.place(x=0, y=0, width=rw, height=rh)
|
||
|
|
tk.Widget.tkraise(ov)
|
||
|
|
self._backdrop_cv = ov
|
||
|
|
self._backdrop_item_id = ov.create_image(
|
||
|
|
0, 0, image=self._backdrop_frames[0], anchor="nw", tags="outside"
|
||
|
|
)
|
||
|
|
ov.tag_bind(
|
||
|
|
"outside",
|
||
|
|
"<Button-1>",
|
||
|
|
lambda _e: (self.sounds.play("click"), self.close_drawer(animate=True)),
|
||
|
|
)
|
||
|
|
|
||
|
|
# 3. Vollhohes Seitenmenü mit schlichtem Tkinter-Rand und leicht ausgegrautem Themen-Hintergrund
|
||
|
|
panel_w = min(276, int(rw * 0.76))
|
||
|
|
self._panel_w = panel_w
|
||
|
|
panel = tk.Canvas(
|
||
|
|
ov,
|
||
|
|
width=panel_w,
|
||
|
|
height=rh,
|
||
|
|
bg=DRAWER_BG_COLOR,
|
||
|
|
bd=0,
|
||
|
|
relief="flat",
|
||
|
|
highlightthickness=1,
|
||
|
|
highlightbackground=SUBTLE_BORDER,
|
||
|
|
highlightcolor=SUBTLE_BORDER,
|
||
|
|
)
|
||
|
|
panel.place(x=-panel_w, y=0, width=panel_w, height=rh)
|
||
|
|
self._drawer_panel = panel
|
||
|
|
|
||
|
|
self._populate_drawer_panel(panel, panel_w)
|
||
|
|
|
||
|
|
try:
|
||
|
|
self._esc_bind_id = self._root_win.bind(
|
||
|
|
"<Escape>",
|
||
|
|
lambda _e: (self.sounds.play("click"), self.close_drawer(animate=True), "break")[2],
|
||
|
|
add="+",
|
||
|
|
)
|
||
|
|
except tk.TclError:
|
||
|
|
self._esc_bind_id = None
|
||
|
|
|
||
|
|
self._is_closing = False
|
||
|
|
self._run_slide_step(1, opening=True)
|
||
|
|
|
||
|
|
def _populate_drawer_panel(self, panel: tk.Canvas, panel_w: int):
|
||
|
|
pcx = panel_w // 2
|
||
|
|
|
||
|
|
# Burger-Symbol an exakt derselben Stelle (12, 22) zum direkten Wieder-Schließen
|
||
|
|
bw, bh = 48, 34
|
||
|
|
bx, by = 12 + bw // 2, COMPACT_TOPBAR_HEIGHT // 2
|
||
|
|
b_norm = _get_burger_button_photo(self.assets, bw, bh, False)
|
||
|
|
b_hov = _get_burger_button_photo(self.assets, bw, bh, True)
|
||
|
|
self._drawer_refs.extend([b_norm, b_hov])
|
||
|
|
|
||
|
|
b_id = panel.create_image(bx, by, image=b_norm, anchor="center", tags="close_burger")
|
||
|
|
b_hit = panel.create_rectangle(
|
||
|
|
bx - bw // 2, by - bh // 2, bx + bw // 2, by + bh // 2,
|
||
|
|
fill="", outline="", width=0, tags="close_burger",
|
||
|
|
)
|
||
|
|
panel.tag_raise(b_hit)
|
||
|
|
panel.tag_bind(
|
||
|
|
"close_burger",
|
||
|
|
"<Enter>",
|
||
|
|
lambda _e: (panel.configure(cursor="hand2"), panel.itemconfigure(b_id, image=b_hov)),
|
||
|
|
)
|
||
|
|
panel.tag_bind(
|
||
|
|
"close_burger",
|
||
|
|
"<Leave>",
|
||
|
|
lambda _e: (panel.configure(cursor=""), panel.itemconfigure(b_id, image=b_norm)),
|
||
|
|
)
|
||
|
|
panel.tag_bind(
|
||
|
|
"close_burger",
|
||
|
|
"<Button-1>",
|
||
|
|
lambda _e: (self.sounds.play("click"), self.close_drawer(animate=True)),
|
||
|
|
)
|
||
|
|
|
||
|
|
# Dezente Trennlinie unter der Kopfzeile
|
||
|
|
panel.create_line(14, COMPACT_TOPBAR_HEIGHT + 4, panel_w - 14, COMPACT_TOPBAR_HEIGHT + 4, fill=SUBTLE_BORDER, width=1)
|
||
|
|
|
||
|
|
# Über allen Buttons: Avatar + Benutzername + aktuelle Spielstufe & XP
|
||
|
|
prof = self._bar.ctx.profile or {}
|
||
|
|
prog = self._bar.ctx.refresh_game_progress() if prof else {}
|
||
|
|
|
||
|
|
av_px = 56
|
||
|
|
av_ph = self.assets.get_avatar_photo(prof.get("avatar_ref"), size_px=av_px)
|
||
|
|
self._drawer_refs.append(av_ph)
|
||
|
|
av_cx = 18 + av_px // 2
|
||
|
|
hdr_cy = COMPACT_TOPBAR_HEIGHT + 44
|
||
|
|
panel.create_image(av_cx, hdr_cy, image=av_ph, anchor="center")
|
||
|
|
|
||
|
|
u_name = str(prof.get("name", "") or "Soul")
|
||
|
|
if prof.get("is_online"):
|
||
|
|
u_name = f"{u_name} [ON]"
|
||
|
|
lvl_num = int(prog.get("level", 1) or 1)
|
||
|
|
xp_val = int(prog.get("total_points", prog.get("current_xp", 0)) or 0)
|
||
|
|
sub_line = f"Lv. {lvl_num} • {xp_val} XP"
|
||
|
|
|
||
|
|
tx_left = av_cx + av_px // 2 + 12
|
||
|
|
max_tw = max(90, panel_w - tx_left - 14)
|
||
|
|
name_ph = self.assets.get_goth_text_photo(
|
||
|
|
u_name, FONT_SIZE_BODY + 2, FONT_COLOR_TITLE_MAIN, max_width=max_tw, align="left"
|
||
|
|
)
|
||
|
|
xp_ph = self.assets.get_goth_text_photo(
|
||
|
|
sub_line, FONT_SIZE_SMALL_MIN, FONT_COLOR_HEADING_SUB, max_width=max_tw, align="left"
|
||
|
|
)
|
||
|
|
self._drawer_refs.extend([name_ph, xp_ph])
|
||
|
|
panel.create_image(tx_left, hdr_cy - 12, image=name_ph, anchor="w")
|
||
|
|
panel.create_image(tx_left, hdr_cy + 13, image=xp_ph, anchor="w")
|
||
|
|
|
||
|
|
sep2_y = hdr_cy + 42
|
||
|
|
panel.create_line(14, sep2_y, panel_w - 14, sep2_y, fill=SUBTLE_BORDER, width=1)
|
||
|
|
|
||
|
|
# Navigations-Buttons untereinander (schließen das Menü vor dem Wechsel sofort sauber)
|
||
|
|
cur_y = sep2_y + 32
|
||
|
|
btn_w = panel_w - 32
|
||
|
|
btn_norm = self.assets.raw_btn_default
|
||
|
|
btn_purp = self.assets.raw_btn_purple
|
||
|
|
locked = self._bar._locked_exit
|
||
|
|
show_stats = (not locked) and self._bar._stats_enabled
|
||
|
|
|
||
|
|
if locked:
|
||
|
|
lk_ph = self.assets.get_goth_text_photo(
|
||
|
|
t("devils_deal_locked_badge"),
|
||
|
|
FONT_SIZE_SMALL_MIN,
|
||
|
|
FONT_COLOR_STATUS_LOSS,
|
||
|
|
max_width=btn_w,
|
||
|
|
)
|
||
|
|
self._drawer_refs.append(lk_ph)
|
||
|
|
panel.create_image(pcx, cur_y, image=lk_ph, anchor="center")
|
||
|
|
cur_y += 42
|
||
|
|
else:
|
||
|
|
b_main = ImageButton(
|
||
|
|
panel,
|
||
|
|
t("btn_back_main"),
|
||
|
|
btn_norm,
|
||
|
|
btn_purp,
|
||
|
|
lambda: self.close_drawer(animate=False, on_closed=self._bar._on_main_menu),
|
||
|
|
sound_mgr=self.sounds,
|
||
|
|
width=btn_w,
|
||
|
|
height=38,
|
||
|
|
style="amethyst",
|
||
|
|
)
|
||
|
|
self._drawer_buttons.append(b_main)
|
||
|
|
panel.create_window(pcx, cur_y, window=b_main, anchor="center")
|
||
|
|
cur_y += 48
|
||
|
|
|
||
|
|
if show_stats:
|
||
|
|
b_stats = ImageButton(
|
||
|
|
panel,
|
||
|
|
t("btn_stats"),
|
||
|
|
btn_norm,
|
||
|
|
btn_purp,
|
||
|
|
lambda: self.close_drawer(
|
||
|
|
animate=False, on_closed=self._bar._trigger_central_stats
|
||
|
|
),
|
||
|
|
sound_mgr=self.sounds,
|
||
|
|
width=btn_w,
|
||
|
|
height=38,
|
||
|
|
style="amethyst",
|
||
|
|
)
|
||
|
|
self._drawer_buttons.append(b_stats)
|
||
|
|
panel.create_window(pcx, cur_y, window=b_stats, anchor="center")
|
||
|
|
cur_y += 48
|
||
|
|
|
||
|
|
b_set = ImageButton(
|
||
|
|
panel,
|
||
|
|
t("btn_settings"),
|
||
|
|
btn_norm,
|
||
|
|
btn_purp,
|
||
|
|
lambda: self.close_drawer(
|
||
|
|
animate=False,
|
||
|
|
on_closed=lambda: self._bar.ctx.open_settings(
|
||
|
|
on_lang_refresh=self._bar._on_lang_refresh
|
||
|
|
),
|
||
|
|
),
|
||
|
|
sound_mgr=self.sounds,
|
||
|
|
width=btn_w,
|
||
|
|
height=38,
|
||
|
|
style="amethyst",
|
||
|
|
)
|
||
|
|
self._drawer_buttons.append(b_set)
|
||
|
|
panel.create_window(pcx, cur_y, window=b_set, anchor="center")
|
||
|
|
|
||
|
|
def _run_slide_step(self, step_idx: int, opening: bool, on_done=None):
|
||
|
|
self._anim_job = None
|
||
|
|
if (
|
||
|
|
self._backdrop_cv is None
|
||
|
|
or not self._backdrop_cv.winfo_exists()
|
||
|
|
or self._drawer_panel is None
|
||
|
|
or not self._drawer_panel.winfo_exists()
|
||
|
|
):
|
||
|
|
self._destroy_drawer_Now()
|
||
|
|
return
|
||
|
|
|
||
|
|
clamped = max(0, min(_ANIM_STEPS, step_idx))
|
||
|
|
t_norm = clamped / _ANIM_STEPS
|
||
|
|
eased = 1.0 - (1.0 - t_norm) ** 3
|
||
|
|
cur_x = int(round(-self._panel_w * (1.0 - eased)))
|
||
|
|
|
||
|
|
self._drawer_panel.place_configure(x=cur_x)
|
||
|
|
if self._backdrop_item_id is not None and clamped < len(self._backdrop_frames):
|
||
|
|
self._backdrop_cv.itemconfigure(
|
||
|
|
self._backdrop_item_id, image=self._backdrop_frames[clamped]
|
||
|
|
)
|
||
|
|
|
||
|
|
if opening:
|
||
|
|
if clamped < _ANIM_STEPS:
|
||
|
|
self._anim_job = self.after(
|
||
|
|
_ANIM_STEP_MS, self._run_slide_step, clamped + 1, True, on_done
|
||
|
|
)
|
||
|
|
else:
|
||
|
|
if clamped > 0:
|
||
|
|
self._anim_job = self.after(
|
||
|
|
_ANIM_STEP_MS, self._run_slide_step, clamped - 1, False, on_done
|
||
|
|
)
|
||
|
|
else:
|
||
|
|
self._destroy_drawer_Now()
|
||
|
|
if callable(on_done):
|
||
|
|
on_done()
|