71 lines
2.6 KiB
Python
71 lines
2.6 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
# view/assets/asset_preloader.py
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import tkinter as tk
|
||
|
|
|
||
|
|
|
||
|
|
def run_startup_preload(assets, init_win_size: tuple[int, int] = (1280, 760), on_step=None) -> None:
|
||
|
|
"""Wärmt Schriften, Hintergründe, UI-Rahmen und Kartendecks beim Start einmalig vor."""
|
||
|
|
from resources.code_res.game_constants import CARD_FILE_PATTERN, RANKS, SUITS
|
||
|
|
from resources.code_res.i18n import t
|
||
|
|
from view.widgets.buttons.image_button import ImageButton, _trim_button_art
|
||
|
|
from view.widgets.dropdown.goth_dropdown import _trim_outer_black_bbox
|
||
|
|
|
||
|
|
if callable(on_step):
|
||
|
|
on_step("Fonts...")
|
||
|
|
for px in (14, 15, 16, 18, 20, 22, 24, 26, 30, 34, 38):
|
||
|
|
assets.get_pil_font(px, alternate=False)
|
||
|
|
|
||
|
|
if callable(on_step):
|
||
|
|
on_step("Background...")
|
||
|
|
w, h = max(480, init_win_size[0]), max(620, init_win_size[1])
|
||
|
|
assets.get_bg_patch_photo(w, h, 0, 0, w, h)
|
||
|
|
if assets.raw_title is not None:
|
||
|
|
assets.get_proportional_photo("title_main_header", assets.raw_title, 265)
|
||
|
|
|
||
|
|
if callable(on_step):
|
||
|
|
on_step("UI Controls...")
|
||
|
|
for raw_b in (assets.raw_btn_default, assets.raw_btn_purple, assets.raw_btn_fire):
|
||
|
|
if raw_b is not None:
|
||
|
|
_trim_button_art(raw_b)
|
||
|
|
|
||
|
|
for raw_dd in (
|
||
|
|
assets.raw_dropdown_closed,
|
||
|
|
assets.raw_dropdown_closed_btn,
|
||
|
|
assets.raw_dropdown_open,
|
||
|
|
assets.raw_dropdown_open_btn,
|
||
|
|
):
|
||
|
|
if raw_dd is not None:
|
||
|
|
_trim_outer_black_bbox(raw_dd)
|
||
|
|
|
||
|
|
dummy_root = tk._default_root
|
||
|
|
if dummy_root is not None and assets.raw_btn_default is not None:
|
||
|
|
for lbl, bw, bh in (
|
||
|
|
(t("btn_back_main"), 110, 32),
|
||
|
|
(t("btn_back_game_menu"), 108, 32),
|
||
|
|
(t("btn_stats"), 96, 32),
|
||
|
|
(t("btn_settings"), 122, 32),
|
||
|
|
(t("btn_switch_profile"), 124, 34),
|
||
|
|
):
|
||
|
|
tmp = ImageButton(
|
||
|
|
dummy_root, lbl, assets.raw_btn_default, assets.raw_btn_purple,
|
||
|
|
None, width=bw, height=bh, style="amethyst",
|
||
|
|
)
|
||
|
|
tmp._ensure_hover()
|
||
|
|
tmp.destroy()
|
||
|
|
|
||
|
|
if callable(on_step):
|
||
|
|
on_step("Cards...")
|
||
|
|
for suit in SUITS:
|
||
|
|
for rank in RANKS:
|
||
|
|
p = assets.res.get_card_path(CARD_FILE_PATTERN.format(suit=suit, rank=rank))
|
||
|
|
if p and p.is_file():
|
||
|
|
assets._get_raw_card_pil(p)
|
||
|
|
for back_col in ("Black", "Red", "Blue", "Purple", "Gold"):
|
||
|
|
bp = assets.res.get_card_back_path(back_col)
|
||
|
|
if bp and bp.is_file():
|
||
|
|
assets._get_raw_card_pil(bp)
|
||
|
|
|
||
|
|
if callable(on_step):
|
||
|
|
on_step("Animations...")
|