the_goth_cardgame_collection/games/poker/views/poker_result_dialog.py

242 lines
7.5 KiB
Python

# -*- coding: utf-8 -*-
# games/poker/views/poker_result_dialog.py
from __future__ import annotations
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.goth_dropdown import GothDropdown
from view.widgets.image_button import ImageButton
from view.widgets.modal_veil import ModalVeil
POPUP_HOLE_CARD_SIZE = (48, 70)
POPUP_BOARD_CARD_SIZE = (44, 64)
class PokerResultDialog(tk.Frame):
"""
Ergebnis-Overlay für Texas Hold'em (ohne eingebettetes GIF),
immer über allen UI-Leisten platziert und mit abgedunkeltem, gesperrtem Tisch.
"""
def __init__(
self,
parent,
assets,
sounds,
result_data: dict,
on_next_round,
on_back_to_menu,
):
GothDropdown.close_any_open_popup()
top_root = parent.winfo_toplevel()
super().__init__(
top_root,
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._card_photos = []
self.place(relx=0.5, rely=0.5, anchor="center")
self._build()
self._veil = ModalVeil(top_root, assets, modal_widget=self)
def _build(self):
p_won = self.data.get("player_won")
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))
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()
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))
btn_row = tk.Frame(self, bg=MODAL_BG)
btn_row.pack(fill="x", pady=(4, 0))
btn_norm = self.assets.raw_btn_default
btn_purp = self.assets.raw_btn_purple
btn_fire = self.assets.raw_btn_fire or btn_purp
if self.data.get("can_continue", True):
ImageButton(
btn_row,
t("bj_popup_next_round_btn"),
btn_fire,
btn_fire,
self._handle_next,
sound_mgr=self.sounds,
width=200,
height=38,
style="fire",
).pack(side="left", padx=(0, 10))
if self.data.get("can_leave_menu", True):
ImageButton(
btn_row,
t("bj_popup_to_menu_btn"),
btn_norm,
btn_purp,
self._handle_menu,
sound_mgr=self.sounds,
width=170,
height=38,
style="amethyst",
).pack(side="right")
def close_dialog(self):
self._veil.release()
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()