Release v0.10.0-beta: compact topbar HUD, full-width quick-action bottombar & borderless Spider/TriPeaks scaling
This commit is contained in:
parent
a81c8f02de
commit
1170dd1105
|
|
@ -40,7 +40,7 @@ class BlackjackTurnDriver:
|
|||
hover_text=lambda: t("bj_tip_call_yes"),
|
||||
)
|
||||
)
|
||||
overflow_btns.append(
|
||||
primary_btns.append(
|
||||
ImageButton(
|
||||
view.bottom_bar, t("bj_tree_btn_call_no_lose"),
|
||||
btn_norm, btn_purp, view._on_fold_hand,
|
||||
|
|
@ -56,17 +56,25 @@ class BlackjackTurnDriver:
|
|||
ImageButton(
|
||||
view.bottom_bar, t("bj_tree_btn_draw_yes"),
|
||||
btn_fire, btn_fire, view._on_step2_draw_yes,
|
||||
sound_mgr=view.ctx.sounds, width=138, height=30, style="fire",
|
||||
sound_mgr=view.ctx.sounds, width=130, height=30, style="fire",
|
||||
hover_text=lambda: t("bj_tip_draw_yes"),
|
||||
)
|
||||
)
|
||||
primary_btns.append(
|
||||
ImageButton(
|
||||
view.bottom_bar, t("bj_tree_btn_draw_no"),
|
||||
btn_norm, btn_purp, view._on_step2_draw_no,
|
||||
sound_mgr=None, width=126, height=30, style="amethyst",
|
||||
hover_text=lambda: t("bj_tip_draw_no"),
|
||||
)
|
||||
)
|
||||
if view.engine.can_double_down(view.active_hand_idx, wallet):
|
||||
dd_cost = view.engine.get_double_down_cost(view.active_hand_idx)
|
||||
primary_btns.append(
|
||||
ImageButton(
|
||||
view.bottom_bar, t("bj_double_btn", dd_cost),
|
||||
btn_norm, btn_purp, view._on_step2_double_down,
|
||||
sound_mgr=view.ctx.sounds, width=132, height=30,
|
||||
sound_mgr=view.ctx.sounds, width=124, height=30,
|
||||
style="amethyst", hover_text=lambda: t("bj_tip_double"),
|
||||
)
|
||||
)
|
||||
|
|
@ -75,23 +83,15 @@ class BlackjackTurnDriver:
|
|||
ImageButton(
|
||||
view.bottom_bar, t("bj_split_btn", view.engine.highest_bet),
|
||||
btn_norm, btn_purp, view._on_step2_split,
|
||||
sound_mgr=view.ctx.sounds, width=124, height=30,
|
||||
sound_mgr=view.ctx.sounds, width=114, height=30,
|
||||
style="amethyst", hover_text=lambda: t("bj_tip_split"),
|
||||
)
|
||||
)
|
||||
overflow_btns.append(
|
||||
ImageButton(
|
||||
view.bottom_bar, t("bj_tree_btn_draw_no"),
|
||||
btn_norm, btn_purp, view._on_step2_draw_no,
|
||||
sound_mgr=None, width=134, height=30, style="amethyst",
|
||||
hover_text=lambda: t("bj_tip_draw_no"),
|
||||
)
|
||||
)
|
||||
overflow_btns.append(
|
||||
ImageButton(
|
||||
view.bottom_bar, t("bj_fold_btn"),
|
||||
btn_norm, btn_purp, view._on_fold_hand,
|
||||
sound_mgr=view.ctx.sounds, width=110, height=30, style="amethyst",
|
||||
sound_mgr=view.ctx.sounds, width=98, height=30, style="amethyst",
|
||||
hover_text=lambda: t("bj_tip_fold"),
|
||||
)
|
||||
)
|
||||
|
|
@ -104,15 +104,15 @@ class BlackjackTurnDriver:
|
|||
ImageButton(
|
||||
view.bottom_bar, f"+{chip}g",
|
||||
btn_fire, btn_fire, lambda c=chip: view._on_step3_raise_yes(c),
|
||||
sound_mgr=view.ctx.sounds, width=76, height=30, style="fire",
|
||||
sound_mgr=view.ctx.sounds, width=68, height=30, style="fire",
|
||||
hover_text=lambda: t("bj_tip_raise_chip"),
|
||||
)
|
||||
)
|
||||
overflow_btns.append(
|
||||
primary_btns.append(
|
||||
ImageButton(
|
||||
view.bottom_bar, t("bj_tree_btn_raise_no"),
|
||||
btn_norm, btn_purp, view._finish_current_hand_turn,
|
||||
sound_mgr=view.ctx.sounds, width=162, height=30, style="amethyst",
|
||||
sound_mgr=view.ctx.sounds, width=154, height=30, style="amethyst",
|
||||
hover_text=lambda: t("bj_tip_raise_no"),
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -246,7 +246,20 @@ class PokerArenaRenderer:
|
|||
fill="#161220", outline=SUBTLE_BORDER, width=1, tags="fg",
|
||||
)
|
||||
|
||||
pot_txt = t("pk_pot_banner", view.engine.total_pot).split("|")[0].strip()
|
||||
# In draw_board_and_pot(...) direkt beim Pot-Text:
|
||||
raw_pot_banner = t("pk_pot_banner", view.engine.total_pot)
|
||||
pot_parts = [p.strip() for p in raw_pot_banner.split("|") if p.strip()]
|
||||
pot_base = pot_parts[0] if pot_parts else raw_pot_banner.strip()
|
||||
street_map = {
|
||||
"PREFLOP": "Pre-Flop",
|
||||
"FLOP": "Flop",
|
||||
"TURN": "Turn",
|
||||
"RIVER": "River",
|
||||
"SHOWDOWN": "Showdown",
|
||||
}
|
||||
street_lbl = street_map.get(getattr(view.engine, "street", ""), "")
|
||||
pot_txt = f"{pot_base} • {street_lbl}" if (compact and street_lbl) else pot_base
|
||||
|
||||
pot_cy = min(felt_bot - 18, max(board_cy + card_h // 2 + 24, (board_cy + card_h // 2 + felt_bot) // 2))
|
||||
pot_sz = max(14 if compact else 15, FONT_SIZE_BODY - (1 if compact else 0))
|
||||
pot_ph = view._make_goth_photo(pot_txt, pot_sz, FONT_COLOR_TITLE_MAIN)
|
||||
|
|
@ -309,22 +322,22 @@ class PokerArenaRenderer:
|
|||
|
||||
view._place_goth_photo_or_fallback(box_cx, zone_cy + box_h // 2 - 18, lbl_ph, lbl_txt, lbl_sz, lbl_col)
|
||||
|
||||
# Vor view._draw_framed_panel(...) in draw_human_hand(...):
|
||||
ref_btn = view._card_ref_btn
|
||||
if ref_btn is not None and ref_btn.winfo_exists():
|
||||
if view._result_dialog is not None or view._fx_overlay is not None or view.engine.street == "SHOWDOWN":
|
||||
ref_btn.place_forget()
|
||||
show_ref = (
|
||||
ref_btn is not None
|
||||
and ref_btn.winfo_exists()
|
||||
and view._result_dialog is None
|
||||
and view._fx_overlay is None
|
||||
and view.engine.street != "SHOWDOWN"
|
||||
)
|
||||
if compact and show_ref:
|
||||
ref_bw = ref_btn.pixel_width
|
||||
max_box_for_side_btn = cw - 2 * pad_x - ref_bw - 12
|
||||
box_w = max(250, min(max_box_for_side_btn, max(cards_span_w + 52, txt_w + 36)))
|
||||
box_cx = pad_x + box_w // 2 + 2
|
||||
else:
|
||||
ref_bw, ref_bh = ref_btn.pixel_width, ref_btn.pixel_height
|
||||
if compact:
|
||||
ref_x = cw - pad_x - ref_bw - 4
|
||||
ref_y = max(player_zone_top - ref_bh - 4, zone_cy - box_h // 2 - ref_bh - 4)
|
||||
else:
|
||||
ref_x = box_cx + box_w // 2 + 16
|
||||
if ref_x + ref_bw > cw - pad_x - 6:
|
||||
ref_x = max(pad_x + 6, box_cx - box_w // 2 - ref_bw - 16)
|
||||
ref_y = zone_cy + box_h // 2 - ref_bh - 6
|
||||
ref_btn.place(x=ref_x, y=ref_y, width=ref_bw, height=ref_bh)
|
||||
tk.Widget.tkraise(ref_btn)
|
||||
box_cx = cw // 2
|
||||
|
||||
@staticmethod
|
||||
def collect_all_seats_reveal(eng, winner_names: list[str]) -> list[dict]:
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class PokerTurnDriver:
|
|||
ImageButton(
|
||||
view.bottom_bar, t("pk_btn_check"), btn_fire, btn_fire,
|
||||
lambda: view._on_human_action("CHECK", 0), sound_mgr=None,
|
||||
width=138, height=30, style="fire",
|
||||
width=130, height=30, style="fire",
|
||||
hover_text=lambda: t("pk_tip_check"),
|
||||
)
|
||||
)
|
||||
|
|
@ -96,7 +96,7 @@ class PokerTurnDriver:
|
|||
ImageButton(
|
||||
view.bottom_bar, t("pk_btn_call", to_call), btn_fire, btn_fire,
|
||||
lambda: view._on_human_action("CALL", 0),
|
||||
sound_mgr=view.ctx.sounds, width=138, height=30, style="fire",
|
||||
sound_mgr=view.ctx.sounds, width=130, height=30, style="fire",
|
||||
hover_text=lambda: t("pk_tip_call"),
|
||||
)
|
||||
)
|
||||
|
|
@ -111,33 +111,38 @@ class PokerTurnDriver:
|
|||
ImageButton(
|
||||
view.bottom_bar, f"+{r_delta}g", btn_norm, btn_purp,
|
||||
lambda d=r_delta: view._on_human_action("RAISE", d),
|
||||
sound_mgr=view.ctx.sounds, width=74, height=30, style="amethyst",
|
||||
sound_mgr=view.ctx.sounds, width=64, height=30, style="amethyst",
|
||||
hover_text=lambda: t("pk_tip_raise"),
|
||||
)
|
||||
)
|
||||
|
||||
# Passen (Fold) bleibt als direkter Schnellzugriff in der Hauptleiste!
|
||||
primary_btns.append(
|
||||
ImageButton(
|
||||
view.bottom_bar, t("pk_btn_fold"), btn_norm, btn_purp,
|
||||
lambda: view._on_human_action("FOLD", 0),
|
||||
sound_mgr=view.ctx.sounds, width=114, height=30, style="amethyst",
|
||||
hover_text=lambda: t("pk_tip_fold"),
|
||||
)
|
||||
)
|
||||
|
||||
# ALL-IN passt bis 3 Raise-Stufen direkt daneben; nur bei 4 Raise-Stufen auf schmalen Screens weicht er in [ ⋮ ] aus
|
||||
if human.stack > 0:
|
||||
allin_fire = to_call > 0 and human.stack <= to_call
|
||||
overflow_btns.append(
|
||||
ImageButton(
|
||||
allin_btn = ImageButton(
|
||||
view.bottom_bar, t("pk_btn_allin", human.stack),
|
||||
btn_fire if allin_fire else btn_norm,
|
||||
btn_fire if allin_fire else btn_purp,
|
||||
lambda: view._on_human_action("ALLIN", 0),
|
||||
sound_mgr=view.ctx.sounds, width=132, height=30,
|
||||
sound_mgr=view.ctx.sounds, width=124, height=30,
|
||||
style="fire" if allin_fire else "amethyst",
|
||||
hover_text=lambda: t("pk_tip_allin"),
|
||||
)
|
||||
)
|
||||
if allin_fire:
|
||||
primary_btns.insert(0, allin_btn)
|
||||
else:
|
||||
overflow_btns.append(allin_btn)
|
||||
|
||||
overflow_btns.append(
|
||||
ImageButton(
|
||||
view.bottom_bar, t("pk_btn_fold"), btn_norm, btn_purp,
|
||||
lambda: view._on_human_action("FOLD", 0),
|
||||
sound_mgr=view.ctx.sounds, width=122, height=30, style="amethyst",
|
||||
hover_text=lambda: t("pk_tip_fold"),
|
||||
)
|
||||
)
|
||||
view._set_bottom_buttons(primary_btns, overflow_buttons=overflow_btns)
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -6,19 +6,19 @@ import tkinter as tk
|
|||
|
||||
from games.solitaire.base.cards.card_animator import CardFlightAnimator
|
||||
from games.solitaire.base.cards.card_hover_zoom import CardHoverZoom
|
||||
from view.widgets.bars.goth_bottombar import GothBottombar
|
||||
from games.solitaire.base.table.solitaire_core import SolitaireCard
|
||||
from games.solitaire.base.session.solitaire_outcome_flow import SolitaireOutcomeFlow
|
||||
from games.solitaire.base.session.solitaire_session_guard import SolitaireSessionGuard
|
||||
from games.solitaire.base.solitaire_theme import SolitaireTableBgRenderer
|
||||
from games.solitaire.base.table.solitaire_core import SolitaireCard
|
||||
from resources.code_res.game_constants import (
|
||||
PLAYING_CARD_SIZE,
|
||||
SOLITAIRE_DIFFICULTIES,
|
||||
TABLE_BG,
|
||||
)
|
||||
from resources.code_res.i18n import t
|
||||
from view.widgets.overlays.endgame_fx_overlay import EndgameFxOverlay
|
||||
from view.widgets.bars.goth_bottombar import GothBottombar
|
||||
from view.widgets.buttons.image_button import ImageButton
|
||||
from view.widgets.overlays.endgame_fx_overlay import EndgameFxOverlay
|
||||
|
||||
|
||||
class SolitaireTableController(SolitaireSessionGuard):
|
||||
|
|
@ -107,7 +107,7 @@ class SolitaireTableController(SolitaireSessionGuard):
|
|||
self.bottom_bar = GothBottombar(
|
||||
self.ctx.root, self.ctx, self.hud_var, self.status_var
|
||||
)
|
||||
self.bottom_bar.pack(fill="x", side="bottom", padx=14, pady=(4, 10))
|
||||
self.bottom_bar.pack(fill="x", side="bottom")
|
||||
|
||||
btn_norm = self.ctx.assets.raw_btn_default
|
||||
btn_purp = self.ctx.assets.raw_btn_purple
|
||||
|
|
@ -115,17 +115,17 @@ class SolitaireTableController(SolitaireSessionGuard):
|
|||
|
||||
self.undo_btn = ImageButton(
|
||||
self.bottom_bar, t("sol_btn_undo"), btn_norm, btn_purp,
|
||||
self._on_undo, sound_mgr=self.ctx.sounds, width=136, height=32,
|
||||
self._on_undo, sound_mgr=self.ctx.sounds, width=132, height=32,
|
||||
enabled=self.engine.can_undo, style="amethyst",
|
||||
)
|
||||
self.undo_all_btn = ImageButton(
|
||||
self.bottom_bar, t("sol_btn_undo_all"), btn_norm, btn_purp,
|
||||
self._on_undo_all, sound_mgr=self.ctx.sounds, width=92, height=32,
|
||||
self._on_undo_all, sound_mgr=self.ctx.sounds, width=88, height=32,
|
||||
enabled=self.engine.can_undo_all, style="amethyst",
|
||||
)
|
||||
self.hint_btn = ImageButton(
|
||||
self.bottom_bar, t("sol_btn_hint"), btn_norm, btn_purp,
|
||||
self._on_hint, sound_mgr=self.ctx.sounds, width=92, height=32,
|
||||
self._on_hint, sound_mgr=self.ctx.sounds, width=90, height=32,
|
||||
enabled=not self.engine.won, style="amethyst",
|
||||
)
|
||||
main_btns = [self.undo_btn, self.undo_all_btn, self.hint_btn]
|
||||
|
|
@ -133,7 +133,7 @@ class SolitaireTableController(SolitaireSessionGuard):
|
|||
self.auto_btn = ImageButton(
|
||||
self.bottom_bar, t("sol_btn_autocomplete"), btn_fire, btn_fire,
|
||||
self._start_auto_complete, sound_mgr=self.ctx.sounds,
|
||||
width=112, height=32, enabled=self.engine.can_auto_complete(),
|
||||
width=108, height=32, enabled=self.engine.can_auto_complete(),
|
||||
style="fire",
|
||||
)
|
||||
main_btns.append(self.auto_btn)
|
||||
|
|
@ -142,14 +142,14 @@ class SolitaireTableController(SolitaireSessionGuard):
|
|||
self.bottom_bar,
|
||||
t("sol_btn_forfeit") if self.engine.moves > 0 else t("sol_btn_new_deal"),
|
||||
btn_norm, btn_purp, self._on_new_or_forfeit_clicked,
|
||||
sound_mgr=self.ctx.sounds, width=104, height=32, style="amethyst",
|
||||
sound_mgr=self.ctx.sounds, width=102, height=32, style="amethyst",
|
||||
)
|
||||
self.bottom_bar.set_buttons(main_btns, overflow_buttons=[self.new_btn])
|
||||
|
||||
self.canvas = tk.Canvas(
|
||||
self.ctx.root, bg=TABLE_BG, bd=0, highlightthickness=0
|
||||
)
|
||||
self.canvas.pack(fill="both", expand=True, padx=14, pady=(4, 2))
|
||||
self.canvas.pack(fill="both", expand=True)
|
||||
self.animator = CardFlightAnimator(self.ctx.root, self.canvas)
|
||||
self.hover_zoom = CardHoverZoom(
|
||||
self.ctx.root,
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -13,6 +13,7 @@ from resources.code_res.game_constants import (
|
|||
SUBTLE_BORDER,
|
||||
)
|
||||
from resources.code_res.i18n import t
|
||||
from view.layout_mode import LayoutMode
|
||||
|
||||
GAME_FOLDER_ID = "solitaire/spider_solitaire"
|
||||
GAME_TITLE_KEY = "game_title_spider_solitaire"
|
||||
|
|
@ -39,6 +40,7 @@ class SpiderTableView(SolitaireTableController):
|
|||
self._col_x: list[int] = [0] * 10
|
||||
self._top_y: int = 14
|
||||
self._tableau_y: int = 178
|
||||
self._is_compact_board: bool = False
|
||||
self._stock_bbox: tuple[int, int, int, int] = (0, 0, 0, 0)
|
||||
self._tableau_card_rects: list[list[tuple[int, int, int, int]]] = [[] for _ in range(10)]
|
||||
self._runs_before_drop: int = 0
|
||||
|
|
@ -74,16 +76,17 @@ class SpiderTableView(SolitaireTableController):
|
|||
if not cards:
|
||||
return []
|
||||
_cw, ch = self.card_size
|
||||
avail_h = max(180, max(440, self.canvas.winfo_height()) - self._tableau_y - self._frame_bot_pad)
|
||||
avail_h = max(180, max(360, self.canvas.winfo_height()) - self._tableau_y - self._frame_bot_pad)
|
||||
|
||||
down_cnt = sum(1 for c in cards if not c.face_up)
|
||||
up_cnt = max(0, len(cards) - down_cnt - 1)
|
||||
down_dy, up_dy = max(6, int(ch * 0.088)), max(15, int(ch * 0.195))
|
||||
down_dy = max(5 if self._is_compact_board else 6, int(ch * 0.088))
|
||||
up_dy = max(13 if self._is_compact_board else 15, int(ch * 0.195))
|
||||
|
||||
if (down_cnt * down_dy + up_cnt * up_dy + ch) > avail_h and (down_cnt + up_cnt) > 0:
|
||||
scale = max(0.30, (avail_h - ch) / max(1, down_cnt * down_dy + up_cnt * up_dy))
|
||||
down_dy = max(5, int(down_dy * scale))
|
||||
up_dy = max(11, int(up_dy * scale))
|
||||
scale = max(0.28, (avail_h - ch) / max(1, down_cnt * down_dy + up_cnt * up_dy))
|
||||
down_dy = max(4, int(down_dy * scale))
|
||||
up_dy = max(10, int(up_dy * scale))
|
||||
|
||||
ys: list[int] = []
|
||||
cur_y = self._tableau_y
|
||||
|
|
@ -93,7 +96,8 @@ class SpiderTableView(SolitaireTableController):
|
|||
return ys
|
||||
|
||||
def _stock_pack_x(self, pack_idx: int) -> int:
|
||||
return self._col_x[0] + pack_idx * max(10, self.card_size[0] // 7)
|
||||
step = max(6 if self._is_compact_board else 10, self.card_size[0] // (8 if self._is_compact_board else 7))
|
||||
return self._col_x[0] + pack_idx * step
|
||||
|
||||
def _snapshot_card_positions(self) -> dict[tuple[str, str, int], tuple[int, int]]:
|
||||
pos: dict[tuple[str, str, int], tuple[int, int]] = {}
|
||||
|
|
@ -135,22 +139,42 @@ class SpiderTableView(SolitaireTableController):
|
|||
self._resize_job = None
|
||||
if not self._canvas_alive() or self._fx_overlay is not None:
|
||||
return
|
||||
cw, ch = max(720, self.canvas.winfo_width()), max(440, self.canvas.winfo_height())
|
||||
rw = max(440, self.ctx.root.winfo_width())
|
||||
rh = max(580, self.ctx.root.winfo_height())
|
||||
self._is_compact_board = LayoutMode.is_compact(rw, rh)
|
||||
|
||||
min_cw = 420 if self._is_compact_board else 720
|
||||
min_ch = 360 if self._is_compact_board else 440
|
||||
cw = max(min_cw, self.canvas.winfo_width())
|
||||
ch = max(min_ch, self.canvas.winfo_height())
|
||||
aspect = self._get_card_aspect()
|
||||
|
||||
if self._is_compact_board:
|
||||
# Kompaktmodus: minimale Seitenränder & 2px Spaltenabstand -> alle 10 Spalten 100 % im Bild!
|
||||
margin_x = 6
|
||||
top_pad, bot_pad = 8, 8
|
||||
self._frame_bot_pad = bot_pad
|
||||
usable_w = max(380, cw - 2 * margin_x)
|
||||
gap_x = 2
|
||||
row_gap = 10
|
||||
card_w_by_w = (usable_w - 9 * gap_x) // 10
|
||||
card_w_by_h = int(round((max(220, ch - top_pad - row_gap - bot_pad) / 3.0) / aspect))
|
||||
card_w = max(40, min(card_w_by_w, card_w_by_h))
|
||||
else:
|
||||
margin_x, top_pad, bot_pad = self._bg_renderer.get_frame_insets(cw, ch)
|
||||
self._frame_bot_pad = bot_pad
|
||||
usable_w = cw - 2 * margin_x
|
||||
gap_x = max(7, int(usable_w * 0.011))
|
||||
row_gap = max(14, int(ch * 0.026))
|
||||
|
||||
card_w_by_w = int((usable_w - 9 * gap_x) / 10)
|
||||
card_w_by_h = int(round((max(220, ch - top_pad - row_gap - bot_pad) / 3.08) / aspect))
|
||||
card_w = max(54, min(card_w_by_w, card_w_by_h))
|
||||
|
||||
card_h = int(round(card_w * aspect))
|
||||
self.card_size = (card_w, card_h)
|
||||
|
||||
start_x = max(margin_x, (cw - (10 * card_w + 9 * gap_x)) // 2)
|
||||
total_span = 10 * card_w + 9 * gap_x
|
||||
start_x = max(4, (cw - total_span) // 2)
|
||||
self._col_x = [start_x + i * (card_w + gap_x) for i in range(10)]
|
||||
self._top_y = top_pad
|
||||
self._tableau_y = self._top_y + card_h + row_gap
|
||||
|
|
@ -163,7 +187,9 @@ class SpiderTableView(SolitaireTableController):
|
|||
):
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
canvas_w, canvas_h = self._prepare_canvas_frame(720, 440)
|
||||
min_cw = 420 if self._is_compact_board else 720
|
||||
min_ch = 360 if self._is_compact_board else 440
|
||||
canvas_w, canvas_h = self._prepare_canvas_frame(min_cw, min_ch)
|
||||
cw, ch = self.card_size
|
||||
hidden = hidden_card_keys or set()
|
||||
|
||||
|
|
@ -187,6 +213,7 @@ class SpiderTableView(SolitaireTableController):
|
|||
vis_packs = [p for p in self.engine.stock_deals if any(self._card_key(c) not in hidden for c in p)]
|
||||
|
||||
if not vis_packs:
|
||||
if not self._is_compact_board:
|
||||
self._draw_slot(sx0, self._top_y, symbol="-", symbol_color=SUBTLE_BORDER)
|
||||
self._stock_bbox = (sx0, self._top_y, sx0 + cw, self._top_y + ch)
|
||||
else:
|
||||
|
|
@ -202,22 +229,23 @@ class SpiderTableView(SolitaireTableController):
|
|||
last_px = self._stock_pack_x(len(vis_packs) - 1)
|
||||
self._stock_bbox = (sx0, self._top_y, last_px + cw, self._top_y + ch)
|
||||
self.canvas.create_text(
|
||||
last_px + cw - max(5, cw // 15), self._top_y + ch - max(5, ch // 18),
|
||||
last_px + cw - max(4, cw // 15), self._top_y + ch - max(4, ch // 18),
|
||||
text=f"x{len(vis_packs)}", anchor="se",
|
||||
font=("Helvetica", max(8, cw // 11), "bold"),
|
||||
fill=ERROR_FG if (not can_deal_now) else ACCENT_GOLD,
|
||||
)
|
||||
|
||||
# 2. Abgeschlossene Sequenzen oben rechts
|
||||
# 2. Abgeschlossene Sequenzen oben rechts (im Kompaktmodus OHNE leere lila Rahmen!)
|
||||
for r_slot in range(8):
|
||||
rx = self._col_x[2 + r_slot]
|
||||
if not self._is_compact_board:
|
||||
self._draw_slot(rx, self._top_y, symbol="♠", symbol_color=SUBTLE_BORDER)
|
||||
if r_slot < len(self.engine.completed_runs):
|
||||
vis_run = [c for c in self.engine.completed_runs[r_slot] if self._card_key(c) not in hidden]
|
||||
if vis_run:
|
||||
self._draw_card_at(vis_run[0], rx, self._top_y, tags=(f"sp_run_{r_slot}",), highlight_color=ACCENT_GOLD)
|
||||
|
||||
# 3. 10 Tableau-Spalten
|
||||
# 3. 10 Tableau-Spalten (im Kompaktmodus keine leeren Spaltenrahmen außer bei aktivem Drag/Hint/Warnung)
|
||||
self._tableau_card_rects = [[] for _ in range(10)]
|
||||
need_fill_warning = bool(self.engine.stock_deals) and self.engine.has_empty_column()
|
||||
|
||||
|
|
@ -228,16 +256,21 @@ class SpiderTableView(SolitaireTableController):
|
|||
full_col = full_col[: exclude_source["idx"]]
|
||||
cards = [c for c in full_col if self._card_key(c) not in hidden]
|
||||
|
||||
slot_hl = None
|
||||
if not cards:
|
||||
slot_hl = None
|
||||
if col_idx in valid_drag_mixed:
|
||||
slot_hl = ACCENT_GOTH
|
||||
elif hint and hint.get("dst_col") == col_idx:
|
||||
slot_hl = ACCENT_GOLD
|
||||
elif need_fill_warning and not self._dragging:
|
||||
slot_hl = SUBTLE_BORDER
|
||||
self._draw_slot(tx, self._tableau_y, symbol="!" if (not cards and need_fill_warning) else "", highlight_color=slot_hl)
|
||||
if not cards:
|
||||
slot_hl = ERROR_FG if self._is_compact_board else SUBTLE_BORDER
|
||||
|
||||
if (not self._is_compact_board) or (slot_hl is not None):
|
||||
self._draw_slot(
|
||||
tx, self._tableau_y,
|
||||
symbol="!" if need_fill_warning else "",
|
||||
highlight_color=slot_hl,
|
||||
)
|
||||
continue
|
||||
|
||||
movable_from = self.engine.movable_tail_start_index(col_idx)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ from resources.code_res.game_constants import (
|
|||
TRIPEAKS_VARIANTS,
|
||||
)
|
||||
from resources.code_res.i18n import t
|
||||
from view.layout_mode import LayoutMode
|
||||
|
||||
GAME_FOLDER_ID = "solitaire/tripeaks"
|
||||
GAME_TITLE_KEY = "game_title_tripeaks"
|
||||
|
|
@ -43,6 +44,7 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
cfg = TRIPEAKS_VARIANTS[v_key]
|
||||
self._init_controller_state(context, v_key, cfg, difficulty, on_back_to_menu)
|
||||
|
||||
self._is_compact_board: bool = False
|
||||
self._slot_coords: list[tuple[int, int]] = [(0, 0)] * 28
|
||||
self._stock_xy: tuple[int, int] = (0, 0)
|
||||
self._waste_xy: tuple[int, int] = (0, 0)
|
||||
|
|
@ -135,19 +137,48 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
self._resize_job = None
|
||||
if not self._canvas_alive() or self._fx_overlay is not None:
|
||||
return
|
||||
cw, ch = max(680, self.canvas.winfo_width()), max(420, self.canvas.winfo_height())
|
||||
aspect = self._get_card_aspect()
|
||||
margin_x, top_pad, bot_pad = self._bg_renderer.get_frame_insets(cw, ch)
|
||||
rw = max(440, self.ctx.root.winfo_width())
|
||||
rh = max(580, self.ctx.root.winfo_height())
|
||||
self._is_compact_board = LayoutMode.is_compact(rw, rh)
|
||||
|
||||
min_cw = 420 if self._is_compact_board else 680
|
||||
min_ch = 360 if self._is_compact_board else 420
|
||||
cw = max(min_cw, self.canvas.winfo_width())
|
||||
ch = max(min_ch, self.canvas.winfo_height())
|
||||
aspect = self._get_card_aspect()
|
||||
|
||||
if self._is_compact_board:
|
||||
margin_x = 8
|
||||
v_top, v_bot = 8, 8
|
||||
self._frame_bot_pad = v_bot
|
||||
usable_w = max(380, cw - 2 * margin_x)
|
||||
usable_h = max(270, ch - v_top - v_bot)
|
||||
|
||||
# Im Kompaktmodus eng gestaucht: 18 Halb-Schritte + 1 Karte passen exakt in usable_w!
|
||||
# (Mit leichter Überlappung von ~9.6 Kartenbreiten bleiben die Karten groß & gut lesbar)
|
||||
card_w_by_w = int(usable_w / 9.65)
|
||||
card_w_by_h = int(round((usable_h / 3.55) / aspect))
|
||||
card_w = max(46, min(96, card_w_by_w, card_w_by_h))
|
||||
card_h = int(round(card_w * aspect))
|
||||
self.card_size = (card_w, card_h)
|
||||
|
||||
half_step_x = max(18, (usable_w - card_w) // 18)
|
||||
row_dy = max(22, int(round(card_h * 0.42)))
|
||||
peaks_total_w = 18 * half_step_x + card_w
|
||||
peaks_total_h = 3 * row_dy + card_h
|
||||
bottom_gap = max(30, min(48, usable_h - peaks_total_h - card_h - 8))
|
||||
scene_h = peaks_total_h + bottom_gap + card_h
|
||||
|
||||
start_x = (cw - peaks_total_w) // 2
|
||||
start_y = v_top + max(0, (usable_h - scene_h) // 2)
|
||||
else:
|
||||
margin_x, top_pad, bot_pad = self._bg_renderer.get_frame_insets(cw, ch)
|
||||
v_top = max(14, int(top_pad * 0.34))
|
||||
v_bot = max(14, int(bot_pad * 0.34))
|
||||
self._frame_bot_pad = v_bot
|
||||
|
||||
usable_w = max(580, cw - 2 * margin_x)
|
||||
usable_h = max(270, ch - v_top - v_bot)
|
||||
|
||||
# Breite: 10 Basiskarten nebeneinander (18 Halb-Schritte + 1 Kartenbreite)
|
||||
# Höhe: 4 Gipfel-Reihen (1 + 3*0.44 Kartenhöhen) + Abstand + untere Deck/Ablage-Zeile (1 Kartenhöhe)
|
||||
card_w_by_w = int(usable_w / 10.75)
|
||||
card_w_by_h = int(round((usable_h / 3.68) / aspect))
|
||||
card_w = max(58, min(124, card_w_by_w, card_w_by_h))
|
||||
|
|
@ -156,7 +187,6 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
|
||||
half_step_x = max(31, int(round((card_w + max(6, int(card_w * 0.08))) / 2.0)))
|
||||
row_dy = max(28, int(round(card_h * 0.44)))
|
||||
|
||||
peaks_total_w = 18 * half_step_x + card_w
|
||||
peaks_total_h = 3 * row_dy + card_h
|
||||
bottom_gap = max(32, min(54, usable_h - peaks_total_h - card_h - 12))
|
||||
|
|
@ -168,8 +198,7 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
for idx, (r, xh) in enumerate(TRIPEAKS_LAYOUT):
|
||||
self._slot_coords[idx] = (start_x + xh * half_step_x, start_y + r * row_dy)
|
||||
|
||||
# Unten mittig unter den 3 Gipfeln: [Verdeckter Talon] [Offene Ablage (±1)]
|
||||
pair_gap = max(28, int(card_w * 0.36))
|
||||
pair_gap = max(20 if self._is_compact_board else 28, int(card_w * 0.34))
|
||||
pair_w = 2 * card_w + pair_gap
|
||||
pair_x0 = (cw - pair_w) // 2
|
||||
deck_y = start_y + peaks_total_h + bottom_gap
|
||||
|
|
@ -180,6 +209,16 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
self.redraw()
|
||||
|
||||
def _draw_deck_socket(self, x: int, y: int, highlight_color: str | None = None):
|
||||
if self._is_compact_board:
|
||||
# Im Kompaktmodus KEINE lila Sockelrahmen um die Karten!
|
||||
if highlight_color:
|
||||
cw, ch = self.card_size
|
||||
self.canvas.create_rectangle(
|
||||
x - 2, y - 2, x + cw + 2, y + ch + 2,
|
||||
fill="", outline=highlight_color, width=2,
|
||||
)
|
||||
return
|
||||
|
||||
cw, ch = self.card_size
|
||||
pad = self.SOCKET_PAD_PX
|
||||
outer_col = highlight_color if highlight_color else BORDER_COLOR
|
||||
|
|
@ -205,12 +244,13 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
):
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
canvas_w, canvas_h = self._prepare_canvas_frame(680, 420)
|
||||
min_cw = 420 if self._is_compact_board else 680
|
||||
min_ch = 360 if self._is_compact_board else 420
|
||||
canvas_w, canvas_h = self._prepare_canvas_frame(min_cw, min_ch)
|
||||
cw, ch = self.card_size
|
||||
hidden = hidden_card_keys or set()
|
||||
hint_refs = set(self._active_hint.get("refs", [])) if self._active_hint else set()
|
||||
|
||||
# 1. Alle 28 Plätze der 3 Gipfel von oben (Reihe 0) nach unten (Reihe 3) zeichnen
|
||||
for idx in range(28):
|
||||
px, py = self._slot_coords[idx]
|
||||
card = self.engine.board[idx]
|
||||
|
|
@ -219,24 +259,16 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
card = None
|
||||
|
||||
if card is None or self._card_key(card) in hidden:
|
||||
if idx in TriPeaksEngine.PEAK_INDICES and self.engine.board[idx] is None:
|
||||
if (not self._is_compact_board) and idx in TriPeaksEngine.PEAK_INDICES and self.engine.board[idx] is None:
|
||||
self._draw_slot(px, py, symbol="▲", symbol_color=ACCENT_GOLD)
|
||||
continue
|
||||
|
||||
is_shaking, s_dx = (
|
||||
self.animator.shake_state_for(ref) if self.animator else (False, 0)
|
||||
)
|
||||
hl = (
|
||||
ERROR_FG
|
||||
if is_shaking
|
||||
else (ACCENT_GOLD if ref in hint_refs else None)
|
||||
)
|
||||
hl = ERROR_FG if is_shaking else (ACCENT_GOLD if ref in hint_refs else None)
|
||||
self._draw_card_at(
|
||||
card,
|
||||
px + s_dx,
|
||||
py,
|
||||
tags=(f"tp_slot_{idx}",),
|
||||
highlight_color=hl,
|
||||
card, px + s_dx, py, tags=(f"tp_slot_{idx}",), highlight_color=hl,
|
||||
)
|
||||
|
||||
# 2. Verdeckter Zieh-Stapel unten links
|
||||
|
|
@ -247,9 +279,7 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
|
||||
self._draw_deck_socket(sx, sy, highlight_color=draw_hl)
|
||||
if vis_stock:
|
||||
back_ph = self.ctx.assets.get_card_back_photo(
|
||||
self.cfg["back_color"], size=self.card_size
|
||||
)
|
||||
back_ph = self.ctx.assets.get_card_back_photo(self.cfg["back_color"], size=self.card_size)
|
||||
if back_ph is not None:
|
||||
if len(vis_stock) >= 10:
|
||||
self.canvas.create_image(sx - 3, sy - 3, image=back_ph, anchor="nw")
|
||||
|
|
@ -265,19 +295,19 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
else:
|
||||
sym = "" if locked else ("↻" if len(self.engine.waste) > 1 else "—")
|
||||
self._draw_slot(
|
||||
sx,
|
||||
sy,
|
||||
symbol=sym,
|
||||
sx, sy, symbol=sym,
|
||||
symbol_color=ACCENT_GOLD if sym == "↻" else SUBTLE_BORDER,
|
||||
highlight_color=draw_hl,
|
||||
draw_red_cross=bool(locked and len(self.engine.waste) > 1),
|
||||
)
|
||||
|
||||
cap_offset = 12 if self._is_compact_board else (self.SOCKET_PAD_PX + 14)
|
||||
stock_lbl = (
|
||||
t("tp_lbl_draw", len(self.engine.stock))
|
||||
if self.engine.stock
|
||||
else t("tp_lbl_redeal", self.engine.redeals_remaining)
|
||||
)
|
||||
self._draw_pile_caption(sx + cw // 2, sy - self.SOCKET_PAD_PX - 14, stock_lbl)
|
||||
self._draw_pile_caption(sx + cw // 2, sy - cap_offset, stock_lbl)
|
||||
|
||||
# 3. Offene Ablagekarte (±1 Zielstapel) unten rechts
|
||||
wx, wy = self._waste_xy
|
||||
|
|
@ -299,9 +329,7 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
self._draw_card_at(w_pile[-1], wx + w_dx, wy, tags=("tp_waste_top",), highlight_color=w_hl)
|
||||
else:
|
||||
self._draw_slot(wx, wy, symbol="±1", symbol_color=SUBTLE_BORDER)
|
||||
self._draw_pile_caption(
|
||||
wx + cw // 2, wy - self.SOCKET_PAD_PX - 14, t("tp_lbl_waste"), FONT_COLOR_TITLE_MAIN
|
||||
)
|
||||
self._draw_pile_caption(wx + cw // 2, wy - cap_offset, t("tp_lbl_waste"), FONT_COLOR_TITLE_MAIN)
|
||||
|
||||
self._finish_canvas_frame(canvas_w, canvas_h, exclude_source, hidden)
|
||||
|
||||
|
|
@ -338,7 +366,7 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
|
||||
def _hit_test(self, x: int, y: int) -> dict | None:
|
||||
cw, ch = self.card_size
|
||||
pad = self.SOCKET_PAD_PX
|
||||
pad = 2 if self._is_compact_board else self.SOCKET_PAD_PX
|
||||
sx, sy = self._stock_xy
|
||||
if sx - pad <= x <= sx + cw + pad and sy - pad <= y <= sy + ch + pad:
|
||||
return {"zone": "stock", "cards": [], "origin": (sx, sy)}
|
||||
|
|
@ -351,19 +379,13 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
if px <= x <= px + cw and py <= y <= py + ch:
|
||||
if not self.engine.is_slot_exposed(idx):
|
||||
return None
|
||||
return {
|
||||
"zone": "board",
|
||||
"ref": ("board", idx),
|
||||
"cards": [card],
|
||||
"origin": (px, py),
|
||||
}
|
||||
return {"zone": "board", "ref": ("board", idx), "cards": [card], "origin": (px, py)}
|
||||
return None
|
||||
|
||||
def _trigger_draw_or_recycle(self):
|
||||
if self.animator:
|
||||
self.animator.cancel_shake()
|
||||
|
||||
# Fall A: Neue Karte vom linken Stapel ziehen -> gleitet verdeckt nach rechts und deckt dort auf!
|
||||
if self.engine.stock:
|
||||
self.engine.start_timer_if_needed()
|
||||
ok, _reason = self.engine.draw_or_recycle_stock()
|
||||
|
|
@ -391,7 +413,6 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
_reveal_on_waste()
|
||||
return
|
||||
|
||||
# Fall B: Redeal (Ablagestapel umdrehen)
|
||||
def do_recycle() -> bool:
|
||||
ok, reason = self.engine.draw_or_recycle_stock()
|
||||
if not ok:
|
||||
|
|
@ -430,7 +451,6 @@ class TriPeaksTableView(SolitaireTableController):
|
|||
self.ctx.sounds.play("click")
|
||||
return
|
||||
|
||||
# Passt nicht (±1 verletzt) -> Status-Hinweis + rotes Wackeln von Karte & Ablage!
|
||||
w_top = self.engine.waste_top
|
||||
if w_top is not None:
|
||||
self.status_var.set(t("tp_adj_mismatch_msg", card.label, w_top.label))
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@ from view.widgets.buttons.image_button import ImageButton
|
|||
class GothBottombar(tk.Frame):
|
||||
"""
|
||||
Vorgeschalteter Größen-Regler für die universelle Fußleiste aller Spiele:
|
||||
- Normales Fenster: zeigt `DesktopGothBottombar`
|
||||
- Kompaktes Fenster (< 920x680, z. B. 658x768 Split-Screen): zeigt `CompactMoreBottombar` mit [ ⋮ ]
|
||||
- Normales Fenster: zeigt `DesktopGothBottombar` (HUD links + Buttons rechts)
|
||||
- Kompaktes Fenster: übergibt HUD/Status an die `CompactBurgerTopbar` oben rechts
|
||||
und nutzt unten die volle Breite für Schnellzugriffs-Buttons (`CompactMoreBottombar`).
|
||||
"""
|
||||
|
||||
def __init__(self, parent, ctx, hud_var: tk.StringVar, status_var: tk.StringVar):
|
||||
|
|
@ -31,6 +32,10 @@ class GothBottombar(tk.Frame):
|
|||
self.status_var = status_var
|
||||
self._root_win = ctx.root
|
||||
|
||||
# HUD-Variablen am Kontext registrieren, damit die Burger-Topbar sie oben rechts anzeigen kann
|
||||
setattr(self.ctx, "_active_hud_var", self.hud_var)
|
||||
setattr(self.ctx, "_active_status_var", self.status_var)
|
||||
|
||||
rw = max(480, self._root_win.winfo_width())
|
||||
rh = max(620, self._root_win.winfo_height())
|
||||
self._is_compact = LayoutMode.is_compact(rw, rh)
|
||||
|
|
@ -53,6 +58,7 @@ class GothBottombar(tk.Frame):
|
|||
self.status_var.trace_add("write", lambda *_: self.refresh_texts())
|
||||
|
||||
self._apply_mode_widget(force=True)
|
||||
self._notify_topbar_hud()
|
||||
|
||||
self.bind("<Destroy>", self._on_destroy)
|
||||
try:
|
||||
|
|
@ -66,6 +72,11 @@ class GothBottombar(tk.Frame):
|
|||
def total_height(self) -> int:
|
||||
return COMPACT_BOTTOMBAR_TOTAL_H if self._is_compact else int(self.cget("height"))
|
||||
|
||||
def _notify_topbar_hud(self):
|
||||
cb = getattr(self.ctx, "_compact_topbar_hud_cb", None)
|
||||
if callable(cb):
|
||||
cb()
|
||||
|
||||
def set_buttons(
|
||||
self,
|
||||
buttons: list[ImageButton],
|
||||
|
|
@ -73,6 +84,8 @@ class GothBottombar(tk.Frame):
|
|||
):
|
||||
primary_list = list(buttons)
|
||||
extra_list = list(overflow_buttons) if overflow_buttons else []
|
||||
for b in primary_list:
|
||||
setattr(b, "can_overflow", False)
|
||||
for b in extra_list:
|
||||
setattr(b, "can_overflow", True)
|
||||
|
||||
|
|
@ -93,7 +106,7 @@ class GothBottombar(tk.Frame):
|
|||
self._desktop_bar._last_btn_split = None
|
||||
if self._compact_bar is not None:
|
||||
self._compact_bar.close_drawer()
|
||||
self._compact_bar._last_inline_sig = None
|
||||
self._compact_bar._last_layout_sig = None
|
||||
|
||||
self.relayout()
|
||||
self.after(20, self.relayout)
|
||||
|
|
@ -101,9 +114,9 @@ class GothBottombar(tk.Frame):
|
|||
def refresh_texts(self):
|
||||
if not self.winfo_exists():
|
||||
return
|
||||
if self._is_compact and self._compact_bar is not None:
|
||||
self._compact_bar.refresh_texts()
|
||||
elif not self._is_compact and self._desktop_bar is not None:
|
||||
if self._is_compact:
|
||||
self._notify_topbar_hud()
|
||||
elif self._desktop_bar is not None:
|
||||
self._desktop_bar.refresh_texts()
|
||||
|
||||
def relayout(self):
|
||||
|
|
@ -112,6 +125,7 @@ class GothBottombar(tk.Frame):
|
|||
self._apply_mode_widget(force=False)
|
||||
if self._is_compact and self._compact_bar is not None:
|
||||
self._compact_bar.relayout(force=True)
|
||||
self._notify_topbar_hud()
|
||||
elif not self._is_compact and self._desktop_bar is not None:
|
||||
target_h = self._desktop_bar.desired_height
|
||||
if int(self.cget("height")) != target_h:
|
||||
|
|
@ -135,8 +149,9 @@ class GothBottombar(tk.Frame):
|
|||
self.configure(height=COMPACT_BOTTOMBAR_TOTAL_H)
|
||||
self._compact_bar.pack(fill="both", expand=True)
|
||||
tk.Misc.lower(self._compact_bar)
|
||||
self._compact_bar._last_inline_sig = None
|
||||
self._compact_bar._last_layout_sig = None
|
||||
self._compact_bar.relayout(force=True)
|
||||
self._notify_topbar_hud()
|
||||
else:
|
||||
if self._compact_bar is not None:
|
||||
self._compact_bar.close_drawer()
|
||||
|
|
@ -153,6 +168,10 @@ class GothBottombar(tk.Frame):
|
|||
def _on_destroy(self, event=None):
|
||||
if event is not None and event.widget is not self:
|
||||
return
|
||||
if getattr(self.ctx, "_active_hud_var", None) is self.hud_var:
|
||||
setattr(self.ctx, "_active_hud_var", None)
|
||||
setattr(self.ctx, "_active_status_var", None)
|
||||
self._notify_topbar_hud()
|
||||
if self._sync_job is not None:
|
||||
try:
|
||||
self.after_cancel(self._sync_job)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from resources.code_res.game_constants import (
|
|||
FONT_SIZE_BODY,
|
||||
FONT_SIZE_SMALL_MIN,
|
||||
SUBTLE_BORDER,
|
||||
UI_ACCENT_AMETHYST,
|
||||
UI_ACCENT_GOLD,
|
||||
)
|
||||
from resources.code_res.i18n import t
|
||||
|
|
@ -20,13 +21,34 @@ 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
|
||||
COMPACT_TOPBAR_TWO_LINE_H = 58
|
||||
DRAWER_BG_COLOR = "#171421"
|
||||
_ANIM_STEPS = 8
|
||||
_ANIM_STEP_MS = 15
|
||||
|
||||
_BURGER_BTN_CACHE: dict[tuple[int, int, bool], ImageTk.PhotoImage] = {}
|
||||
|
||||
|
||||
def _is_timer_seg(txt: str) -> bool:
|
||||
if ":" not in txt or "'" in txt:
|
||||
return False
|
||||
tail = txt.rsplit(" ", 1)[-1]
|
||||
parts = tail.split(":")
|
||||
return len(parts) in (2, 3) and all(p.isdigit() for p in parts)
|
||||
|
||||
|
||||
def _is_redundant_pot_or_street(clean_seg: str, game_folder: str) -> bool:
|
||||
"""Filtert doppelte Pot-/Street-Segmente bei Poker & Blackjack (stehen bereits in der Tischmitte)."""
|
||||
if game_folder not in ("poker", "blackjack"):
|
||||
return False
|
||||
low = clean_seg.lower()
|
||||
if low.startswith("pot:") or low.startswith("gesamt-pot") or low.startswith("gold-pot"):
|
||||
return True
|
||||
if low in ("pre-flop", "flop", "turn", "river", "showdown"):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _get_burger_button_photo(assets, w: int, h: int, hovered: bool) -> ImageTk.PhotoImage:
|
||||
key = (w, h, hovered)
|
||||
if key in _BURGER_BTN_CACHE:
|
||||
|
|
@ -45,16 +67,8 @@ def _get_burger_button_photo(assets, w: int, h: int, hovered: bool) -> ImageTk.P
|
|||
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,
|
||||
)
|
||||
draw.rounded_rectangle((cx - half_len + 1, y, cx + half_len + 1, y + 2), 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
|
||||
|
|
@ -63,16 +77,16 @@ def _get_burger_button_photo(assets, w: int, h: int, hovered: bool) -> ImageTk.P
|
|||
|
||||
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.
|
||||
Kompakt-/Mobile-Kopfleiste mit Burger-Button links und dynamischem 1–2-zeiligem HUD rechts:
|
||||
- Übernimmt sämtliche HUD- und Status-Texte aus der Fußleiste oben rechts neben [ ☰ ].
|
||||
- Wächst bei Bedarf automatisch von 44 px auf 58 px (2 Zeilen), sodass die Karten sauber nach unten rücken.
|
||||
"""
|
||||
|
||||
def __init__(self, parent, controller_bar):
|
||||
self._cur_h = COMPACT_TOPBAR_HEIGHT
|
||||
super().__init__(
|
||||
parent,
|
||||
height=COMPACT_TOPBAR_HEIGHT,
|
||||
height=self._cur_h,
|
||||
bg=BG_COLOR,
|
||||
bd=0,
|
||||
highlightthickness=0,
|
||||
|
|
@ -82,11 +96,18 @@ class CompactBurgerTopbar(tk.Canvas):
|
|||
self.assets = controller_bar.assets
|
||||
self.sounds = controller_bar.sounds
|
||||
|
||||
setattr(self._bar.ctx, "_compact_topbar_hud_cb", self.refresh_hud_texts)
|
||||
|
||||
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._hud_refs: list[ImageTk.PhotoImage] = []
|
||||
self._timer_item_id: int | None = None
|
||||
self._timer_live_ph: ImageTk.PhotoImage | None = None
|
||||
self._last_timer_txt: str = ""
|
||||
self._last_hud_sig: tuple | None = None
|
||||
self._last_bg_key: tuple[int, int, int, int, int, int] = (0, 0, 0, 0, 0, 0)
|
||||
|
||||
self._backdrop_cv: tk.Canvas | None = None
|
||||
self._backdrop_item_id: int | None = None
|
||||
|
|
@ -104,11 +125,13 @@ class CompactBurgerTopbar(tk.Canvas):
|
|||
|
||||
@property
|
||||
def total_height(self) -> int:
|
||||
return COMPACT_TOPBAR_HEIGHT
|
||||
return self._cur_h
|
||||
|
||||
def _on_destroy(self, event=None):
|
||||
if event is not None and event.widget is not self:
|
||||
return
|
||||
if getattr(self._bar.ctx, "_compact_topbar_hud_cb", None) == self.refresh_hud_texts:
|
||||
setattr(self._bar.ctx, "_compact_topbar_hud_cb", None)
|
||||
self.close_drawer(animate=False)
|
||||
|
||||
def _on_configure(self, event):
|
||||
|
|
@ -116,38 +139,116 @@ class CompactBurgerTopbar(tk.Canvas):
|
|||
return
|
||||
self.sync_layout()
|
||||
|
||||
def _collect_hud_segments(self) -> tuple[list[str], str]:
|
||||
hud_var = getattr(self._bar.ctx, "_active_hud_var", None)
|
||||
st_var = getattr(self._bar.ctx, "_active_status_var", None)
|
||||
g_folder = getattr(self._bar.ctx, "game_folder", "") or ""
|
||||
|
||||
segs: list[str] = []
|
||||
if hud_var is not None:
|
||||
raw = (hud_var.get() or "").replace("•", "|")
|
||||
for p in raw.split("|"):
|
||||
s = p.strip()
|
||||
if s.startswith("~"):
|
||||
s = s[1:].strip()
|
||||
if s and not _is_redundant_pot_or_street(s, g_folder):
|
||||
segs.append(s)
|
||||
|
||||
if not segs:
|
||||
for attr in ("_title_text", "title_text", "_title", "title"):
|
||||
val = getattr(self._bar, attr, None)
|
||||
if isinstance(val, str) and val.strip():
|
||||
segs.append(val.strip())
|
||||
break
|
||||
|
||||
extra_lbl = getattr(self._bar, "extra_label", None)
|
||||
if extra_lbl is not None:
|
||||
try:
|
||||
ex_txt = str(extra_lbl.cget("text") or "").strip()
|
||||
if ex_txt and ex_txt not in segs:
|
||||
segs.append(ex_txt)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
st_txt = (st_var.get() or "").strip() if st_var is not None else ""
|
||||
return segs, st_txt
|
||||
|
||||
def _render_seg(self, txt: str, color: str = FONT_COLOR_HEADING_SUB, max_w: int | None = None) -> ImageTk.PhotoImage:
|
||||
if _is_timer_seg(txt):
|
||||
pil_s = self.assets.render_goth_text_pil(
|
||||
txt, size_px=FONT_SIZE_SMALL_MIN, color=color, max_width=max_w, align="left", uncached=True
|
||||
)
|
||||
return ImageTk.PhotoImage(pil_s)
|
||||
return self.assets.get_goth_text_photo(
|
||||
txt, size_px=FONT_SIZE_SMALL_MIN, color=color, max_width=max_w, align="left"
|
||||
)
|
||||
|
||||
def refresh_hud_texts(self):
|
||||
if not self.winfo_exists():
|
||||
return
|
||||
w = self.winfo_width()
|
||||
if w < 80:
|
||||
return
|
||||
segs, st_txt = self._collect_hud_segments()
|
||||
masked = tuple(f"<T:{len(s)}>" if _is_timer_seg(s) else s for s in segs)
|
||||
sig = (w, masked, st_txt)
|
||||
|
||||
if sig == self._last_hud_sig:
|
||||
cur_t = next((s for s in segs if _is_timer_seg(s)), "")
|
||||
if (
|
||||
cur_t
|
||||
and cur_t != self._last_timer_txt
|
||||
and self._timer_item_id is not None
|
||||
and self.type(self._timer_item_id)
|
||||
):
|
||||
self._last_timer_txt = cur_t
|
||||
self._timer_live_ph = self._render_seg(cur_t)
|
||||
self.itemconfigure(self._timer_item_id, image=self._timer_live_ph)
|
||||
return
|
||||
|
||||
self._draw_hud_area(w, segs, st_txt, sig)
|
||||
|
||||
def _set_bar_height(self, target_h: int):
|
||||
if target_h == self._cur_h:
|
||||
return
|
||||
self._cur_h = target_h
|
||||
self.configure(height=target_h)
|
||||
if int(self._bar.cget("height")) != target_h:
|
||||
self._bar.configure(height=target_h)
|
||||
self._last_bg_key = (0, 0, 0, 0, 0, 0)
|
||||
|
||||
def sync_layout(self):
|
||||
if not self.winfo_exists():
|
||||
return
|
||||
w = max(1, self.winfo_width())
|
||||
if w < 60:
|
||||
return
|
||||
segs, st_txt = self._collect_hud_segments()
|
||||
masked = tuple(f"<T:{len(s)}>" if _is_timer_seg(s) else s for s in segs)
|
||||
self._draw_hud_area(w, segs, st_txt, (w, masked, st_txt), force_bg=False)
|
||||
|
||||
def _draw_bg_and_burger(self, w: int, force: bool = False):
|
||||
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(),
|
||||
),
|
||||
)
|
||||
oy = max(0, min(max(0, rh - self._cur_h), self.winfo_rooty() - self._root_win.winfo_rooty()))
|
||||
|
||||
key = (w, rw, rh, ox, oy)
|
||||
if key == self._last_render_key:
|
||||
key = (w, self._cur_h, rw, rh, ox, oy)
|
||||
if not force and key == self._last_bg_key:
|
||||
return
|
||||
self._last_render_key = key
|
||||
self._last_bg_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)
|
||||
rw, rh, ox, oy, min(w, rw - ox), min(self._cur_h, rh - oy)
|
||||
)
|
||||
self.delete("all")
|
||||
self.delete("c_bg")
|
||||
self.delete("burger_hit")
|
||||
if self._bg_slice_photo is not None:
|
||||
self.create_image(0, 0, image=self._bg_slice_photo, anchor="nw", tags="c_bg")
|
||||
self.tag_lower("c_bg")
|
||||
|
||||
bw, bh = 48, 34
|
||||
bx, by = 12 + bw // 2, COMPACT_TOPBAR_HEIGHT // 2
|
||||
bx, by = 12 + bw // 2, self._cur_h // 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)
|
||||
|
||||
|
|
@ -159,11 +260,93 @@ class CompactBurgerTopbar(tk.Canvas):
|
|||
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 _draw_hud_area(self, w: int, segs: list[str], st_txt: str, sig: tuple, force_bg: bool = False):
|
||||
x_start = 72
|
||||
avail_w = max(120, w - x_start - 12)
|
||||
|
||||
pipe_ph = self.assets.get_goth_text_photo("|", FONT_SIZE_SMALL_MIN, SUBTLE_BORDER)
|
||||
pipe_step = pipe_ph.width() + 10
|
||||
|
||||
rendered: list[tuple[str, ImageTk.PhotoImage]] = [
|
||||
(s, self._render_seg(s, FONT_COLOR_HEADING_SUB, max_w=avail_w)) for s in segs
|
||||
]
|
||||
|
||||
# Segmente gierig auf Zeile 1 und optional Zeile 2 aufteilen
|
||||
line1: list[tuple[str, ImageTk.PhotoImage]] = []
|
||||
line2: list[tuple[str, ImageTk.PhotoImage]] = []
|
||||
w1 = w2 = 0
|
||||
for item in rendered:
|
||||
iw = item[1].width()
|
||||
add1 = iw + (pipe_step if line1 else 0)
|
||||
if not line2 and (w1 + add1 <= avail_w or not line1):
|
||||
line1.append(item)
|
||||
w1 += add1
|
||||
else:
|
||||
add2 = iw + (pipe_step if line2 else 0)
|
||||
if w2 + add2 <= avail_w or not line2:
|
||||
line2.append(item)
|
||||
w2 += add2
|
||||
|
||||
st_ph = None
|
||||
if st_txt:
|
||||
rem2 = avail_w - (w2 + (pipe_step if line2 else 0))
|
||||
if not line2:
|
||||
st_ph = self._render_seg(st_txt, UI_ACCENT_AMETHYST, max_w=avail_w)
|
||||
elif rem2 >= 90:
|
||||
st_ph = self._render_seg(st_txt, UI_ACCENT_AMETHYST, max_w=rem2)
|
||||
|
||||
need_two_lines = bool(line2 or st_ph is not None)
|
||||
target_h = COMPACT_TOPBAR_TWO_LINE_H if need_two_lines else COMPACT_TOPBAR_HEIGHT
|
||||
height_changed = (target_h != self._cur_h)
|
||||
if height_changed:
|
||||
self._set_bar_height(target_h)
|
||||
|
||||
self._draw_bg_and_burger(w, force=force_bg or height_changed)
|
||||
|
||||
self.delete("c_hud")
|
||||
self._hud_refs.clear()
|
||||
self._hud_refs.append(pipe_ph)
|
||||
self._timer_item_id = None
|
||||
self._last_timer_txt = ""
|
||||
|
||||
y1 = 17 if need_two_lines else (self._cur_h // 2)
|
||||
y2 = 41
|
||||
|
||||
def _place_row(entries: list[tuple[str, ImageTk.PhotoImage]], row_y: int, row_w: int, extra_st=None):
|
||||
total_rw = row_w + ((pipe_step if entries else 0) + extra_st.width() if extra_st else 0)
|
||||
# Rechtsbündig/zentriert im Raum neben dem Burger-Button ausrichten
|
||||
cx = x_start + max(0, (avail_w - total_rw) // 2)
|
||||
for idx, (s_txt, ph) in enumerate(entries):
|
||||
if idx > 0:
|
||||
self.create_image(cx + 3, row_y, image=pipe_ph, anchor="w", tags="c_hud")
|
||||
cx += pipe_step
|
||||
iid = self.create_image(cx, row_y, image=ph, anchor="w", tags="c_hud")
|
||||
if _is_timer_seg(s_txt) and self._timer_item_id is None:
|
||||
self._timer_item_id = iid
|
||||
self._timer_live_ph = ph
|
||||
self._last_timer_txt = s_txt
|
||||
else:
|
||||
self._hud_refs.append(ph)
|
||||
cx += ph.width()
|
||||
if extra_st is not None:
|
||||
if entries:
|
||||
self.create_image(cx + 3, row_y, image=pipe_ph, anchor="w", tags="c_hud")
|
||||
cx += pipe_step
|
||||
self._hud_refs.append(extra_st)
|
||||
self.create_image(cx, row_y, image=extra_st, anchor="w", tags="c_hud")
|
||||
|
||||
if line1:
|
||||
_place_row(line1, y1, w1, extra_st=None)
|
||||
if need_two_lines:
|
||||
_place_row(line2, y2, w2, extra_st=st_ph)
|
||||
|
||||
self.create_line(10, self._cur_h - 1, w - 10, self._cur_h - 1, fill=SUBTLE_BORDER, width=1, tags="c_hud")
|
||||
self._last_hud_sig = sig
|
||||
|
||||
def _set_hover(self, hov: bool):
|
||||
self.configure(cursor="hand2" if hov else "")
|
||||
if self._btn_item_id is not None:
|
||||
|
|
@ -180,31 +363,23 @@ class CompactBurgerTopbar(tk.Canvas):
|
|||
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()
|
||||
rx, ry = self._root_win.winfo_rootx(), 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))
|
||||
return fb.convert("RGB") if fb is not None else 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))
|
||||
eased = 1.0 - (1.0 - (step / _ANIM_STEPS)) ** 3
|
||||
frames.append(ImageTk.PhotoImage(Image.blend(base_rgb, dark_target, eased * 0.58)))
|
||||
return frames
|
||||
|
||||
def _toggle_drawer(self, _event=None):
|
||||
|
|
@ -225,22 +400,19 @@ class CompactBurgerTopbar(tk.Canvas):
|
|||
|
||||
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()
|
||||
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()
|
||||
self._destroy_drawer_now()
|
||||
if callable(on_closed):
|
||||
on_closed()
|
||||
return
|
||||
|
||||
if self._is_closing:
|
||||
return
|
||||
if not self._is_closing:
|
||||
self._is_closing = True
|
||||
self._run_slide_step(_ANIM_STEPS - 1, opening=False, on_done=on_closed)
|
||||
|
||||
def _destroy_drawer_Now(self):
|
||||
def _destroy_drawer_now(self):
|
||||
self._cancel_anim()
|
||||
self._is_closing = False
|
||||
for b in self._drawer_buttons:
|
||||
|
|
@ -253,7 +425,6 @@ class CompactBurgerTopbar(tk.Canvas):
|
|||
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:
|
||||
|
|
@ -261,56 +432,35 @@ class CompactBurgerTopbar(tk.Canvas):
|
|||
wgt.destroy()
|
||||
except Exception:
|
||||
pass
|
||||
self._drawer_panel = None
|
||||
self._backdrop_cv = None
|
||||
self._drawer_panel = 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)
|
||||
self._backdrop_frames = self._build_dim_frames(self._capture_live_window_pil(rw, rh))
|
||||
|
||||
# 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)),
|
||||
)
|
||||
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,
|
||||
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="+",
|
||||
"<Escape>", lambda _e: (self.sounds.play("click"), self.close_drawer(animate=True), "break")[2], add="+"
|
||||
)
|
||||
except tk.TclError:
|
||||
self._esc_bind_id = None
|
||||
|
|
@ -320,48 +470,28 @@ class CompactBurgerTopbar(tk.Canvas):
|
|||
|
||||
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
|
||||
bx, by = 12 + bw // 2, self._cur_h // 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",
|
||||
)
|
||||
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)),
|
||||
)
|
||||
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)
|
||||
sep1_y = self._cur_h + 4
|
||||
panel.create_line(14, sep1_y, panel_w - 14, sep1_y, 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
|
||||
av_cx, hdr_cy = 18 + av_px // 2, sep1_y + 40
|
||||
panel.create_image(av_cx, hdr_cy, image=av_ph, anchor="center")
|
||||
|
||||
u_name = str(prof.get("name", "") or "Soul")
|
||||
|
|
@ -369,16 +499,11 @@ class CompactBurgerTopbar(tk.Canvas):
|
|||
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"
|
||||
)
|
||||
|
||||
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(f"Lv. {lvl_num} • {xp_val} XP", 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")
|
||||
|
|
@ -386,110 +511,60 @@ class CompactBurgerTopbar(tk.Canvas):
|
|||
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
|
||||
btn_norm, btn_purp = self.assets.raw_btn_default, 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,
|
||||
)
|
||||
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,
|
||||
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",
|
||||
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:
|
||||
if self._bar._stats_enabled:
|
||||
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",
|
||||
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",
|
||||
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()
|
||||
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)
|
||||
eased = 1.0 - (1.0 - (clamped / _ANIM_STEPS)) ** 3
|
||||
self._drawer_panel.place_configure(x=int(round(-self._panel_w * (1.0 - eased))))
|
||||
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]
|
||||
)
|
||||
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 opening and clamped < _ANIM_STEPS:
|
||||
self._anim_job = self.after(_ANIM_STEP_MS, self._run_slide_step, clamped + 1, True, on_done)
|
||||
elif not opening and clamped > 0:
|
||||
self._anim_job = self.after(_ANIM_STEP_MS, self._run_slide_step, clamped - 1, False, on_done)
|
||||
elif not opening:
|
||||
self._destroy_drawer_now()
|
||||
if callable(on_done):
|
||||
on_done()
|
||||
|
|
@ -7,9 +7,6 @@ from PIL import Image, ImageDraw, ImageTk
|
|||
|
||||
from resources.code_res.game_constants import (
|
||||
BG_COLOR,
|
||||
FONT_COLOR_BODY_MUTED,
|
||||
FONT_COLOR_HEADING_SUB,
|
||||
FONT_SIZE_SMALL_MIN,
|
||||
SUBTLE_BORDER,
|
||||
UI_ACCENT_GOLD,
|
||||
)
|
||||
|
|
@ -17,7 +14,7 @@ from view.widgets.buttons.button_art_compositor import ButtonArtCompositor
|
|||
from view.widgets.buttons.image_button import ImageButton
|
||||
|
||||
COMPACT_BOTTOMBAR_BAR_H = 42
|
||||
COMPACT_BOTTOMBAR_PAD_BOT = 8
|
||||
COMPACT_BOTTOMBAR_PAD_BOT = 6
|
||||
COMPACT_BOTTOMBAR_TOTAL_H = COMPACT_BOTTOMBAR_BAR_H + COMPACT_BOTTOMBAR_PAD_BOT
|
||||
POPUP_BG_COLOR = "#171421"
|
||||
|
||||
|
|
@ -85,16 +82,34 @@ def _extract_btn_meta(btn: ImageButton) -> tuple[str, object, bool, str]:
|
|||
return label, cmd, enabled, style
|
||||
|
||||
|
||||
def _overflow_priority_score(btn: ImageButton) -> int:
|
||||
"""Bestimmt, welcher Button bei echtem Platzmangel ZUERST ins [ ⋮ ]-Menü weicht (höher = zuerst raus)."""
|
||||
lbl, _cmd, _en, _st = _extract_btn_meta(btn)
|
||||
low = lbl.lower()
|
||||
# Menü-Verlassen / Aufgeben weicht als Erstes, falls nicht alles passt
|
||||
if any(k in low for k in ("spielmenü", "game menu", "aufgeben", "give up", "forfeit", "austreten")):
|
||||
return 100
|
||||
# Poker: ALL-IN weicht vor Check/Bet/Fold ins Menü, wenn die Breite knapp wird
|
||||
if "all-in" in low or "all in" in low:
|
||||
return 90
|
||||
if any(k in low for k in ("neu geben", "new deal", "neues spiel")):
|
||||
return 75
|
||||
if getattr(btn, "can_overflow", False):
|
||||
return 50
|
||||
return 10
|
||||
|
||||
|
||||
class CompactMoreBottombar(tk.Canvas):
|
||||
"""
|
||||
Flache Kompakt-/Mobile-Fußleiste (50 px Gesamthöhe, direkt am unteren Rand):
|
||||
- Zeigt links primäre HUD-Werte und rechts max. 2 primäre Aktions-Buttons + [ ⋮ ].
|
||||
- Das [ ⋮ ]-Menü öffnet sich als kleines, nicht-blockierendes Popup unten rechts:
|
||||
Der gesamte Spieltisch bleibt frei sichtbar und direkt bespielbar!
|
||||
Reine Schnellzugriffs-Button-Leiste am unteren Rand (kein HUD-Text – der steht oben neben [ ☰ ]!):
|
||||
- Nutzt 100 % der Leistenbreite, um möglichst ALLE Aktions-Buttons direkt nebeneinander zu zeigen.
|
||||
- Blendet [ ⋮ ] nur dann ein, wenn die Buttons physisch breiter als das Fenster sind;
|
||||
das [ ⋮ ]-Popup enthält ausschließlich die überzähligen Buttons (keinen doppelten Text).
|
||||
"""
|
||||
|
||||
SIDE_PAD = 10
|
||||
MORE_W = 42
|
||||
SIDE_PAD = 8
|
||||
BTN_GAP = 5
|
||||
MORE_W = 40
|
||||
MORE_H = 32
|
||||
|
||||
def __init__(self, parent, controller_bar):
|
||||
|
|
@ -116,19 +131,12 @@ class CompactMoreBottombar(tk.Canvas):
|
|||
self._more_hov_ph: ImageTk.PhotoImage | None = None
|
||||
self._more_item_id: int | None = None
|
||||
self._more_bbox: tuple[int, int, int, int] = (0, 0, 0, 0)
|
||||
self._txt_refs: list[ImageTk.PhotoImage] = []
|
||||
|
||||
self._more_btns: list[ImageButton] = []
|
||||
self._more_hud_lines: list[str] = []
|
||||
self._last_bg_key: tuple[int, int, int, int, int, int] = (0, 0, 0, 0, 0, 0)
|
||||
self._last_inline_sig: tuple | None = None
|
||||
self._last_layout_sig: tuple | None = None
|
||||
|
||||
# Schwebendes kleines Popup ohne Vollbild-Schleier (Tisch bleibt aktiv!)
|
||||
self._popup_cv: tk.Canvas | None = None
|
||||
self._popup_info_id: int | None = None
|
||||
self._popup_info_ph: ImageTk.PhotoImage | None = None
|
||||
self._popup_panel_w: int = 236
|
||||
self._popup_refs: list = []
|
||||
self._popup_widgets: list[ImageButton] = []
|
||||
self._outside_click_bind_id: str | None = None
|
||||
self._esc_bind_id: str | None = None
|
||||
|
|
@ -148,102 +156,40 @@ class CompactMoreBottombar(tk.Canvas):
|
|||
self.close_drawer()
|
||||
self.relayout(force=True)
|
||||
|
||||
def _split_hud_strings(self) -> tuple[list[str], list[str]]:
|
||||
raw_hud = (self._bar.hud_var.get() or "").replace("•", "|")
|
||||
inline_strs: list[str] = []
|
||||
ovf_strs: list[str] = []
|
||||
for part in raw_hud.split("|"):
|
||||
p = part.strip()
|
||||
if not p:
|
||||
continue
|
||||
if p.startswith("~"):
|
||||
clean = p[1:].strip()
|
||||
if clean:
|
||||
ovf_strs.append(clean)
|
||||
else:
|
||||
inline_strs.append(p)
|
||||
@classmethod
|
||||
def _btns_span(cls, lst: list[ImageButton]) -> int:
|
||||
if not lst:
|
||||
return 0
|
||||
return sum(b.pixel_width for b in lst) + max(0, len(lst) - 1) * cls.BTN_GAP
|
||||
|
||||
st = (self._bar.status_var.get() or "").strip()
|
||||
if st:
|
||||
ovf_strs.append(st)
|
||||
return inline_strs, ovf_strs
|
||||
|
||||
def _partition_buttons(self, w: int, has_ovf_hud: bool) -> tuple[list[ImageButton], list[ImageButton]]:
|
||||
def _partition_buttons(self, w: int) -> tuple[list[ImageButton], list[ImageButton]]:
|
||||
"""Behält maximal viele Buttons direkt sichtbar; lagert nur echten Breiten-Überhang aus."""
|
||||
alive = [b for b in self._bar._buttons if b.winfo_exists()]
|
||||
inline_b: list[ImageButton] = []
|
||||
if not alive:
|
||||
return [], []
|
||||
|
||||
inner_avail = max(140, w - 2 * self.SIDE_PAD - 20)
|
||||
# Idealfall: Alle Buttons passen gemeinsam auf volle Breite -> kein [ ⋮ ] nötig!
|
||||
if self._btns_span(alive) <= inner_avail:
|
||||
return alive, []
|
||||
|
||||
inline_b = list(alive)
|
||||
more_b: list[ImageButton] = []
|
||||
avail_with_dots = max(100, inner_avail - self.MORE_W - self.BTN_GAP)
|
||||
|
||||
for b in alive:
|
||||
if getattr(b, "can_overflow", False):
|
||||
more_b.append(b)
|
||||
else:
|
||||
inline_b.append(b)
|
||||
|
||||
max_inline_count = 2 if w < 720 else 3
|
||||
while len(inline_b) > max_inline_count:
|
||||
more_b.insert(0, inline_b.pop())
|
||||
|
||||
need_dots = bool(more_b or has_ovf_hud)
|
||||
dots_reserve = (self.MORE_W + 6) if need_dots else 0
|
||||
max_btn_budget = max(130, int((w - 2 * self.SIDE_PAD) * 0.56) - dots_reserve)
|
||||
|
||||
def _btns_w(lst: list[ImageButton]) -> int:
|
||||
return sum(x.pixel_width for x in lst) + max(0, len(lst) - 1) * 5
|
||||
|
||||
while len(inline_b) > 1 and _btns_w(inline_b) > max_btn_budget:
|
||||
more_b.insert(0, inline_b.pop())
|
||||
if not need_dots:
|
||||
need_dots = True
|
||||
max_btn_budget = max(110, max_btn_budget - (self.MORE_W + 6))
|
||||
while len(inline_b) > 1 and self._btns_span(inline_b) > avail_with_dots:
|
||||
# Kandidat mit höchster Auslagerungs-Priorität (z. B. Spielmenü / ALL-IN / hinten) wählen
|
||||
best_idx = max(
|
||||
range(len(inline_b)),
|
||||
key=lambda idx: (_overflow_priority_score(inline_b[idx]), idx),
|
||||
)
|
||||
more_b.insert(0, inline_b.pop(best_idx))
|
||||
|
||||
return inline_b, more_b
|
||||
|
||||
def _update_open_popup_info_live(self, extra_lines: list[str]):
|
||||
"""Aktualisiert z. B. den laufenden Timer im geöffneten Popup ohne Neuaufbau."""
|
||||
if (
|
||||
self._popup_cv is None
|
||||
or not self._popup_cv.winfo_exists()
|
||||
or self._popup_info_id is None
|
||||
):
|
||||
return
|
||||
info_txt = " • ".join(extra_lines)
|
||||
if not info_txt:
|
||||
return
|
||||
pil_img = self.assets.render_goth_text_pil(
|
||||
info_txt,
|
||||
size_px=FONT_SIZE_SMALL_MIN,
|
||||
color=FONT_COLOR_BODY_MUTED,
|
||||
max_width=self._popup_panel_w - 28,
|
||||
align="center",
|
||||
uncached=True,
|
||||
)
|
||||
self._popup_info_ph = ImageTk.PhotoImage(pil_img)
|
||||
self._popup_cv.itemconfigure(self._popup_info_id, image=self._popup_info_ph)
|
||||
|
||||
def refresh_texts(self):
|
||||
if not self.winfo_exists() or self._bar._is_compact is False:
|
||||
# Text läuft jetzt komplett oben in der Burger-Topbar -> hier 0 Arbeit!
|
||||
return
|
||||
w = self.winfo_width()
|
||||
if w < 80:
|
||||
return
|
||||
inline_strs, ovf_strs = self._split_hud_strings()
|
||||
inline_b, more_b = self._partition_buttons(w, bool(ovf_strs))
|
||||
extra_all = inline_strs[2:] + ovf_strs
|
||||
self._more_hud_lines = extra_all
|
||||
|
||||
if self._popup_cv is not None and self._popup_cv.winfo_exists():
|
||||
self._update_open_popup_info_live(extra_all)
|
||||
|
||||
sig = (
|
||||
w,
|
||||
tuple(inline_strs[:2]),
|
||||
bool(more_b or extra_all),
|
||||
tuple(id(b) for b in inline_b),
|
||||
tuple(id(b) for b in more_b),
|
||||
)
|
||||
if sig == self._last_inline_sig:
|
||||
return
|
||||
self.relayout(force=True)
|
||||
|
||||
def relayout(self, force: bool = False):
|
||||
if not self.winfo_exists():
|
||||
|
|
@ -284,92 +230,48 @@ class CompactMoreBottombar(tk.Canvas):
|
|||
self._render_foreground(w)
|
||||
|
||||
def _render_foreground(self, w: int):
|
||||
self.delete("cbb_fg")
|
||||
self.delete("more_hit")
|
||||
self._txt_refs.clear()
|
||||
self._more_item_id = None
|
||||
self._more_bbox = (0, 0, 0, 0)
|
||||
|
||||
inline_strs, ovf_strs = self._split_hud_strings()
|
||||
inline_b, more_b = self._partition_buttons(w, bool(ovf_strs))
|
||||
|
||||
inline_b, more_b = self._partition_buttons(w)
|
||||
for b in more_b:
|
||||
b.place_forget()
|
||||
|
||||
cy = COMPACT_BOTTOMBAR_BAR_H // 2
|
||||
rx = w - self.SIDE_PAD - 10
|
||||
show_dots = bool(more_b)
|
||||
|
||||
kept_hud = inline_strs[:2]
|
||||
extra_hud = inline_strs[2:] + ovf_strs
|
||||
show_dots = bool(more_b or extra_hud)
|
||||
total_span = self._btns_span(inline_b) + ((self.BTN_GAP + self.MORE_W) if show_dots else 0)
|
||||
cur_x = max(self.SIDE_PAD + 10, (w - total_span) // 2)
|
||||
|
||||
for btn in inline_b:
|
||||
bw = btn.pixel_width
|
||||
bh = min(btn.pixel_height, 32)
|
||||
btn.place(x=cur_x, y=cy - bh // 2, width=bw, height=bh)
|
||||
tk.Widget.tkraise(btn)
|
||||
cur_x += bw + self.BTN_GAP
|
||||
|
||||
if show_dots:
|
||||
self._more_norm_ph = _get_more_dots_photo(self.assets, self.MORE_W, self.MORE_H, False)
|
||||
self._more_hov_ph = _get_more_dots_photo(self.assets, self.MORE_W, self.MORE_H, True)
|
||||
mx = rx - self.MORE_W // 2
|
||||
mx = min(w - self.SIDE_PAD - 10 - self.MORE_W // 2, cur_x + self.MORE_W // 2)
|
||||
x1, y1 = mx - self.MORE_W // 2, cy - self.MORE_H // 2
|
||||
x2, y2 = mx + self.MORE_W // 2, cy + self.MORE_H // 2
|
||||
self._more_bbox = (x1, y1, x2, y2)
|
||||
|
||||
is_open = self._popup_cv is not None and self._popup_cv.winfo_exists()
|
||||
self._more_item_id = self.create_image(
|
||||
mx,
|
||||
cy,
|
||||
image=self._more_hov_ph if is_open else self._more_norm_ph,
|
||||
anchor="center",
|
||||
tags="more_hit",
|
||||
mx, cy, image=self._more_hov_ph if is_open else self._more_norm_ph,
|
||||
anchor="center", tags="more_hit",
|
||||
)
|
||||
hit = self.create_rectangle(x1, y1, x2, y2, fill="", outline="", width=0, tags="more_hit")
|
||||
self.tag_raise(hit)
|
||||
self.tag_bind("more_hit", "<Enter>", lambda _e: self._set_more_hover(True))
|
||||
self.tag_bind("more_hit", "<Leave>", lambda _e: self._set_more_hover(False))
|
||||
self.tag_bind("more_hit", "<Button-1>", self._toggle_drawer)
|
||||
rx -= (self.MORE_W + 6)
|
||||
|
||||
for btn in reversed(inline_b):
|
||||
bw = btn.pixel_width
|
||||
bh = min(btn.pixel_height, 32)
|
||||
btn.place(x=rx - bw, y=cy - bh // 2, width=bw, height=bh)
|
||||
tk.Widget.tkraise(btn)
|
||||
rx -= (bw + 5)
|
||||
|
||||
lx_min = self.SIDE_PAD + 14
|
||||
avail_txt_w = max(0, rx - 10 - lx_min)
|
||||
pipe_ph = self.assets.get_goth_text_photo("|", FONT_SIZE_SMALL_MIN, FONT_COLOR_HEADING_SUB)
|
||||
self._txt_refs.append(pipe_ph)
|
||||
pipe_w = pipe_ph.width() + 8
|
||||
|
||||
fitted_photos: list[ImageTk.PhotoImage] = []
|
||||
used_w = 0
|
||||
for s_txt in kept_hud:
|
||||
ph = self.assets.get_goth_text_photo(
|
||||
s_txt, FONT_SIZE_SMALL_MIN, FONT_COLOR_HEADING_SUB, align="left"
|
||||
)
|
||||
add_w = ph.width() + (pipe_w if fitted_photos else 0)
|
||||
if used_w + add_w <= avail_txt_w or not fitted_photos:
|
||||
fitted_photos.append(ph)
|
||||
used_w += add_w
|
||||
else:
|
||||
extra_hud.insert(0, s_txt)
|
||||
|
||||
lx = lx_min + max(0, (avail_txt_w - used_w) // 2)
|
||||
for i, ph in enumerate(fitted_photos):
|
||||
if i > 0:
|
||||
self.create_image(lx + 3, cy + 1, image=pipe_ph, anchor="w", tags="cbb_fg")
|
||||
lx += pipe_w
|
||||
self._txt_refs.append(ph)
|
||||
self.create_image(lx, cy + 1, image=ph, anchor="w", tags="cbb_fg")
|
||||
lx += ph.width()
|
||||
|
||||
self._more_btns = more_b
|
||||
self._more_hud_lines = extra_hud
|
||||
self._last_inline_sig = (
|
||||
w,
|
||||
tuple(kept_hud),
|
||||
show_dots,
|
||||
tuple(id(b) for b in inline_b),
|
||||
tuple(id(b) for b in more_b),
|
||||
)
|
||||
self._last_layout_sig = (w, tuple(id(b) for b in inline_b), tuple(id(b) for b in more_b))
|
||||
|
||||
def _set_more_hover(self, hov: bool):
|
||||
self.configure(cursor="hand2" if hov else "")
|
||||
|
|
@ -402,9 +304,6 @@ class CompactMoreBottombar(tk.Canvas):
|
|||
except Exception:
|
||||
pass
|
||||
self._popup_widgets.clear()
|
||||
self._popup_refs.clear()
|
||||
self._popup_info_id = None
|
||||
self._popup_info_ph = None
|
||||
|
||||
if self._popup_cv is not None:
|
||||
try:
|
||||
|
|
@ -418,30 +317,19 @@ class CompactMoreBottombar(tk.Canvas):
|
|||
self.itemconfigure(self._more_item_id, image=self._more_norm_ph)
|
||||
|
||||
def _on_global_root_press(self, event):
|
||||
"""
|
||||
Schließt das kleine Popup bei Klicks auf das Spielfeld, OHNE das Event zu schlucken:
|
||||
Dadurch wird ein Klick auf eine Karte auf dem Tisch direkt ganz normal ausgeführt!
|
||||
"""
|
||||
pop = self._popup_cv
|
||||
if pop is None or not pop.winfo_exists():
|
||||
self._unbind_popup_watchers()
|
||||
return
|
||||
|
||||
# 1. Klick innerhalb des Popups (oder auf einen Button im Popup) -> offen lassen
|
||||
wgt = event.widget
|
||||
cur = wgt
|
||||
cur = event.widget
|
||||
while cur is not None:
|
||||
if cur is pop:
|
||||
return
|
||||
cur = getattr(cur, "master", None)
|
||||
|
||||
# 2. Klick direkt auf das [ ⋮ ]-Icon -> erledigt _toggle_drawer selbst
|
||||
if wgt is self:
|
||||
if event.widget is self:
|
||||
x1, y1, x2, y2 = self._more_bbox
|
||||
if x1 <= event.x <= x2 and y1 <= event.y <= y2:
|
||||
return
|
||||
|
||||
# 3. Klick auf den aktiven Tisch / Rest des Fensters -> Popup schließen, Klick durchlassen!
|
||||
self.close_drawer()
|
||||
|
||||
def _toggle_drawer(self, _event=None):
|
||||
|
|
@ -453,100 +341,54 @@ class CompactMoreBottombar(tk.Canvas):
|
|||
|
||||
def _open_drawer(self):
|
||||
self.close_drawer()
|
||||
info_lines = list(self._more_hud_lines)
|
||||
btns = [b for b in self._more_btns if b.winfo_exists()]
|
||||
if not btns and not info_lines:
|
||||
if not btns:
|
||||
return
|
||||
|
||||
rw = max(320, self._root_win.winfo_width())
|
||||
rh = max(420, self._root_win.winfo_height())
|
||||
|
||||
panel_w = min(244, rw - 24)
|
||||
self._popup_panel_w = panel_w
|
||||
|
||||
info_txt = " • ".join(info_lines)
|
||||
info_ph = None
|
||||
info_block_h = 0
|
||||
if info_txt:
|
||||
pil_info = self.assets.render_goth_text_pil(
|
||||
info_txt,
|
||||
size_px=FONT_SIZE_SMALL_MIN,
|
||||
color=FONT_COLOR_BODY_MUTED,
|
||||
max_width=panel_w - 28,
|
||||
align="center",
|
||||
uncached=True,
|
||||
)
|
||||
info_ph = ImageTk.PhotoImage(pil_info)
|
||||
self._popup_info_ph = info_ph
|
||||
info_block_h = info_ph.height() + (18 if btns else 6)
|
||||
|
||||
panel_h = 20 + info_block_h + len(btns) * 42
|
||||
panel_w = min(224, rw - 20)
|
||||
panel_h = 16 + len(btns) * 40
|
||||
px = max(8, rw - panel_w - self.SIDE_PAD)
|
||||
py = max(48, rh - COMPACT_BOTTOMBAR_TOTAL_H - panel_h - 4)
|
||||
pcx = panel_w // 2
|
||||
|
||||
# Nur dieses kleine Widget schwebt rechts unten; der restliche Tisch bleibt komplett frei & klickbar!
|
||||
pop = tk.Canvas(
|
||||
self._root_win,
|
||||
width=panel_w,
|
||||
height=panel_h,
|
||||
bg=POPUP_BG_COLOR,
|
||||
bd=0,
|
||||
relief="flat",
|
||||
highlightthickness=1,
|
||||
highlightbackground=SUBTLE_BORDER,
|
||||
highlightcolor=SUBTLE_BORDER,
|
||||
self._root_win, width=panel_w, height=panel_h,
|
||||
bg=POPUP_BG_COLOR, bd=0, relief="flat",
|
||||
highlightthickness=1, highlightbackground=SUBTLE_BORDER, highlightcolor=SUBTLE_BORDER,
|
||||
)
|
||||
pop.place(x=px, y=py, width=panel_w, height=panel_h)
|
||||
tk.Widget.tkraise(pop)
|
||||
self._popup_cv = pop
|
||||
|
||||
cur_y = 10
|
||||
if info_ph is not None:
|
||||
self._popup_info_id = pop.create_image(
|
||||
pcx, cur_y + info_ph.height() // 2, image=info_ph, anchor="center"
|
||||
)
|
||||
cur_y += info_ph.height() + 8
|
||||
if btns:
|
||||
pop.create_line(12, cur_y, panel_w - 12, cur_y, fill=SUBTLE_BORDER, width=1)
|
||||
cur_y += 10
|
||||
|
||||
btn_norm = self.assets.raw_btn_default
|
||||
btn_purp = self.assets.raw_btn_purple
|
||||
btn_norm, btn_purp = self.assets.raw_btn_default, self.assets.raw_btn_purple
|
||||
btn_fire = self.assets.raw_btn_fire or btn_purp
|
||||
bw = panel_w - 28
|
||||
bw = panel_w - 24
|
||||
cur_y = 8
|
||||
|
||||
for src_btn in btns:
|
||||
lbl, cmd, en, st = _extract_btn_meta(src_btn)
|
||||
is_fire = (st == "fire")
|
||||
d_btn = ImageButton(
|
||||
pop,
|
||||
lbl,
|
||||
pop, lbl,
|
||||
btn_fire if is_fire else btn_norm,
|
||||
btn_fire if is_fire else btn_purp,
|
||||
# Bei Aktionen wie "Tipp" schließt sich das kleine Popup sofort, damit der Tipp auf dem Tisch frei strahlt
|
||||
(lambda fn=cmd: (self.close_drawer(), fn() if callable(fn) else None)),
|
||||
sound_mgr=self.sounds,
|
||||
width=bw,
|
||||
height=34,
|
||||
enabled=en,
|
||||
sound_mgr=self.sounds, width=bw, height=34, enabled=en,
|
||||
style="fire" if is_fire else "amethyst",
|
||||
)
|
||||
self._popup_widgets.append(d_btn)
|
||||
pop.create_window(pcx, cur_y + 17, window=d_btn, anchor="center")
|
||||
cur_y += 42
|
||||
cur_y += 40
|
||||
|
||||
if self._more_item_id is not None and self._more_hov_ph is not None:
|
||||
self.itemconfigure(self._more_item_id, image=self._more_hov_ph)
|
||||
|
||||
try:
|
||||
self._outside_click_bind_id = self._root_win.bind(
|
||||
"<ButtonPress-1>", self._on_global_root_press, add="+"
|
||||
)
|
||||
self._outside_click_bind_id = self._root_win.bind("<ButtonPress-1>", self._on_global_root_press, add="+")
|
||||
self._esc_bind_id = self._root_win.bind(
|
||||
"<Escape>",
|
||||
lambda _e: (self.sounds.play("click"), self.close_drawer(), "break")[2],
|
||||
add="+",
|
||||
"<Escape>", lambda _e: (self.sounds.play("click"), self.close_drawer(), "break")[2], add="+"
|
||||
)
|
||||
except tk.TclError:
|
||||
pass
|
||||
Loading…
Reference in New Issue