204 lines
7.4 KiB
Python
204 lines
7.4 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
# games/poker/views/poker_result_dialog.py
|
||
|
|
import tkinter as tk
|
||
|
|
from models.card import Card
|
||
|
|
from resources.code_res.game_constants import (
|
||
|
|
ACCENT_GOLD, ACCENT_GOTH, CELL_BG, ERROR_FG,
|
||
|
|
FG_COLOR, MODAL_BG, MUTED_FG, SUBTLE_BORDER
|
||
|
|
)
|
||
|
|
from resources.code_res.i18n import t
|
||
|
|
from view.widgets.image_button import ImageButton
|
||
|
|
|
||
|
|
POPUP_GIF_SIZE = (145, 80)
|
||
|
|
POPUP_HOLE_CARD_SIZE = (48, 70)
|
||
|
|
POPUP_BOARD_CARD_SIZE = (44, 64)
|
||
|
|
|
||
|
|
|
||
|
|
class PokerResultDialog(tk.Frame):
|
||
|
|
"""Ergebnis-Overlay im einheitlichen BlackjackResultDialog-Stil inkl. Kartenbild-Showdown."""
|
||
|
|
def __init__(
|
||
|
|
self,
|
||
|
|
parent,
|
||
|
|
assets,
|
||
|
|
sounds,
|
||
|
|
result_data: dict,
|
||
|
|
on_next_round,
|
||
|
|
on_back_to_menu,
|
||
|
|
):
|
||
|
|
super().__init__(
|
||
|
|
parent, bg=MODAL_BG, padx=26, pady=18,
|
||
|
|
highlightthickness=2, highlightbackground=ACCENT_GOTH
|
||
|
|
)
|
||
|
|
self.assets = assets
|
||
|
|
self.sounds = sounds
|
||
|
|
self.data = result_data
|
||
|
|
self.on_next_round = on_next_round
|
||
|
|
self.on_back_to_menu = on_back_to_menu
|
||
|
|
self._gif_job = None
|
||
|
|
self._card_photos = []
|
||
|
|
|
||
|
|
self.place(relx=0.5, rely=0.5, anchor="center")
|
||
|
|
self.lift()
|
||
|
|
self._build()
|
||
|
|
|
||
|
|
def _build(self):
|
||
|
|
self.gif_lbl = tk.Label(self, bg=MODAL_BG, bd=0)
|
||
|
|
self.gif_lbl.pack(pady=(0, 4))
|
||
|
|
|
||
|
|
p_won = self.data.get("player_won")
|
||
|
|
if p_won is True:
|
||
|
|
self._start_gif("win_gif")
|
||
|
|
elif p_won is False:
|
||
|
|
self._start_gif("lose_gif")
|
||
|
|
|
||
|
|
headline_color = ACCENT_GOLD if p_won else (
|
||
|
|
MUTED_FG if p_won is None else ERROR_FG
|
||
|
|
)
|
||
|
|
tk.Label(
|
||
|
|
self, text=self.data["headline"],
|
||
|
|
font=("Georgia", 16, "bold"), fg=headline_color, bg=MODAL_BG,
|
||
|
|
wraplength=680, justify="center"
|
||
|
|
).pack(pady=(2, 10))
|
||
|
|
|
||
|
|
# --- Karten-Aufdeckung: Gemeinschaftskarten + alle Sitze mit Kartenbildern ---
|
||
|
|
reveal_box = tk.Frame(
|
||
|
|
self, bg=CELL_BG, padx=12, pady=8,
|
||
|
|
highlightthickness=1, highlightbackground=SUBTLE_BORDER
|
||
|
|
)
|
||
|
|
reveal_box.pack(fill="x", pady=(0, 10))
|
||
|
|
|
||
|
|
board_raw = self.data.get("board_cards", [])
|
||
|
|
if board_raw:
|
||
|
|
b_row = tk.Frame(reveal_box, bg=CELL_BG)
|
||
|
|
b_row.pack(pady=(0, 6))
|
||
|
|
tk.Label(
|
||
|
|
b_row, text=f"{t('pk_board_title')}:",
|
||
|
|
font=("Georgia", 9, "bold"), fg=MUTED_FG, bg=CELL_BG
|
||
|
|
).pack(side="left", padx=(0, 8))
|
||
|
|
|
||
|
|
for s_suit, s_rank in board_raw:
|
||
|
|
c_obj = Card(s_suit, s_rank)
|
||
|
|
ph = self.assets.get_card_photo(c_obj.image_filename, size=POPUP_BOARD_CARD_SIZE)
|
||
|
|
if ph:
|
||
|
|
self._card_photos.append(ph)
|
||
|
|
tk.Label(b_row, image=ph, bg=CELL_BG, bd=0).pack(side="left", padx=2)
|
||
|
|
|
||
|
|
tk.Frame(reveal_box, bg=SUBTLE_BORDER, height=1).pack(fill="x", pady=(2, 6))
|
||
|
|
|
||
|
|
seats_row = tk.Frame(reveal_box, bg=CELL_BG)
|
||
|
|
seats_row.pack()
|
||
|
|
|
||
|
|
for idx, entry in enumerate(self.data.get("seat_showdown", [])):
|
||
|
|
is_win = entry["is_winner"]
|
||
|
|
folded = entry["folded"]
|
||
|
|
|
||
|
|
border_c = ACCENT_GOLD if is_win else (SUBTLE_BORDER if not folded else "#3a252a")
|
||
|
|
s_card = tk.Frame(
|
||
|
|
seats_row, bg="#191521", padx=8, pady=5,
|
||
|
|
highlightthickness=2 if is_win else 1, highlightbackground=border_c
|
||
|
|
)
|
||
|
|
s_card.grid(row=idx // 6, column=idx % 6, padx=4, pady=2, sticky="nsew")
|
||
|
|
|
||
|
|
name_col = ACCENT_GOLD if is_win else (MUTED_FG if folded else ACCENT_GOTH)
|
||
|
|
tk.Label(
|
||
|
|
s_card, text=entry["name"],
|
||
|
|
font=("Georgia", 9, "bold"), fg=name_col, bg="#191521"
|
||
|
|
).pack()
|
||
|
|
|
||
|
|
c_frame = tk.Frame(s_card, bg="#191521", height=POPUP_HOLE_CARD_SIZE[1] + 2)
|
||
|
|
c_frame.pack(pady=3)
|
||
|
|
for s_suit, s_rank in entry["cards"]:
|
||
|
|
c_obj = Card(s_suit, s_rank)
|
||
|
|
ph = self.assets.get_card_photo(c_obj.image_filename, size=POPUP_HOLE_CARD_SIZE)
|
||
|
|
if ph:
|
||
|
|
self._card_photos.append(ph)
|
||
|
|
tk.Label(c_frame, image=ph, bg="#191521", bd=0).pack(side="left", padx=1)
|
||
|
|
|
||
|
|
combo_col = "#7be08a" if is_win else (ERROR_FG if folded else FG_COLOR)
|
||
|
|
tk.Label(
|
||
|
|
s_card, text=entry["combo_text"],
|
||
|
|
font=("Helvetica", 8, "bold"), fg=combo_col, bg="#191521",
|
||
|
|
wraplength=112, justify="center"
|
||
|
|
).pack()
|
||
|
|
|
||
|
|
# --- Gewinn / Verlust & XP Box (identisch zu BlackjackResultDialog) ---
|
||
|
|
info_box = tk.Frame(
|
||
|
|
self, bg=CELL_BG, padx=20, pady=10,
|
||
|
|
highlightthickness=1, highlightbackground=SUBTLE_BORDER
|
||
|
|
)
|
||
|
|
info_box.pack(fill="x", pady=(0, 12))
|
||
|
|
|
||
|
|
p_net = self.data["player_net"]
|
||
|
|
if p_net > 0:
|
||
|
|
own_txt, own_col = t("bj_popup_your_gain", p_net), "#7be08a"
|
||
|
|
elif p_net < 0:
|
||
|
|
own_txt, own_col = t("bj_popup_your_loss", abs(p_net)), ERROR_FG
|
||
|
|
else:
|
||
|
|
own_txt, own_col = t("bj_popup_your_even"), FG_COLOR
|
||
|
|
|
||
|
|
tk.Label(info_box, text=own_txt, font=("Helvetica", 11, "bold"), fg=own_col, bg=CELL_BG).pack(pady=2)
|
||
|
|
|
||
|
|
for extra_line in self.data.get("other_gains", []):
|
||
|
|
tk.Label(info_box, text=extra_line, font=("Helvetica", 10), fg=MUTED_FG, bg=CELL_BG).pack(pady=1)
|
||
|
|
|
||
|
|
tk.Frame(info_box, bg=SUBTLE_BORDER, height=1).pack(fill="x", pady=8)
|
||
|
|
|
||
|
|
tk.Label(
|
||
|
|
info_box, text=t("bj_popup_xp_earned", self.data["xp_gained"]),
|
||
|
|
font=("Helvetica", 11, "bold"), fg=ACCENT_GOTH, bg=CELL_BG,
|
||
|
|
).pack(pady=1)
|
||
|
|
|
||
|
|
if self.data.get("new_level_title"):
|
||
|
|
tk.Label(
|
||
|
|
info_box, text=self.data["new_level_title"],
|
||
|
|
font=("Georgia", 11, "bold"), fg=ACCENT_GOLD, bg=CELL_BG,
|
||
|
|
).pack(pady=(3, 0))
|
||
|
|
|
||
|
|
# --- Buttons ---
|
||
|
|
btn_row = tk.Frame(self, bg=MODAL_BG)
|
||
|
|
btn_row.pack(fill="x", pady=(4, 0))
|
||
|
|
|
||
|
|
if self.data.get("can_continue", True):
|
||
|
|
ImageButton(
|
||
|
|
btn_row, t("bj_popup_next_round_btn"),
|
||
|
|
self.assets.raw_btn, self.assets.raw_btn_active,
|
||
|
|
self._handle_next, sound_mgr=self.sounds, width=200, height=40, font=("Helvetica", 10, "bold")
|
||
|
|
).pack(side="left", padx=(0, 10))
|
||
|
|
|
||
|
|
if self.data.get("can_leave_menu", True):
|
||
|
|
ImageButton(
|
||
|
|
btn_row, t("bj_popup_to_menu_btn"),
|
||
|
|
self.assets.raw_sel, self.assets.raw_sel_active,
|
||
|
|
self._handle_menu, sound_mgr=self.sounds, width=170, height=40, font=("Helvetica", 10, "bold")
|
||
|
|
).pack(side="right")
|
||
|
|
|
||
|
|
def _start_gif(self, key: str):
|
||
|
|
frames = self.assets.get_gif_frames(key, size=POPUP_GIF_SIZE)
|
||
|
|
if not frames:
|
||
|
|
return
|
||
|
|
|
||
|
|
def _step(idx=0):
|
||
|
|
if not self.gif_lbl.winfo_exists():
|
||
|
|
return
|
||
|
|
self.gif_lbl.configure(image=frames[idx])
|
||
|
|
self._gif_job = self.after(90, _step, (idx + 1) % len(frames))
|
||
|
|
|
||
|
|
_step(0)
|
||
|
|
|
||
|
|
def close_dialog(self):
|
||
|
|
if self._gif_job:
|
||
|
|
try:
|
||
|
|
self.after_cancel(self._gif_job)
|
||
|
|
except Exception:
|
||
|
|
pass
|
||
|
|
self._gif_job = None
|
||
|
|
if self.winfo_exists():
|
||
|
|
self.destroy()
|
||
|
|
|
||
|
|
def _handle_next(self):
|
||
|
|
self.close_dialog()
|
||
|
|
self.on_next_round()
|
||
|
|
|
||
|
|
def _handle_menu(self):
|
||
|
|
self.close_dialog()
|
||
|
|
self.on_back_to_menu()
|