2026-11-14 04:25:51 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
# games/blackjack/views/round_result_dialog.py
|
|
|
|
|
import tkinter as tk
|
|
|
|
|
from resources.code_res.game_constants import (
|
|
|
|
|
ACCENT_GOLD, ACCENT_GOTH, CELL_BG, ERROR_FG,
|
2026-11-14 23:28:01 +00:00
|
|
|
FG_COLOR, MODAL_BG, MUTED_FG, PANEL_BG, SUBTLE_BORDER
|
2026-11-14 04:25:51 +00:00
|
|
|
)
|
|
|
|
|
from resources.code_res.i18n import t
|
|
|
|
|
from view.widgets.image_button import ImageButton
|
|
|
|
|
|
2026-11-14 23:28:01 +00:00
|
|
|
SHOWDOWN_MINI_CARD_SIZE = (52, 76)
|
|
|
|
|
|
2026-11-14 04:25:51 +00:00
|
|
|
|
|
|
|
|
class BlackjackResultDialog(tk.Frame):
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
parent,
|
|
|
|
|
assets,
|
|
|
|
|
sounds,
|
|
|
|
|
result_data: dict,
|
|
|
|
|
on_next_round,
|
|
|
|
|
on_back_to_menu,
|
|
|
|
|
):
|
|
|
|
|
super().__init__(
|
2026-11-14 23:28:01 +00:00
|
|
|
parent, bg=MODAL_BG, padx=26, pady=18,
|
2026-11-14 04:25:51 +00:00
|
|
|
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
|
2026-11-14 23:28:01 +00:00
|
|
|
self._card_photos = []
|
2026-11-14 04:25:51 +00:00
|
|
|
|
|
|
|
|
self.place(relx=0.5, rely=0.5, anchor="center")
|
|
|
|
|
self.lift()
|
|
|
|
|
self._build()
|
|
|
|
|
|
|
|
|
|
def _build(self):
|
2026-11-14 23:28:01 +00:00
|
|
|
# Kompaktere Kopfzeile (GIF + Headline), damit alle Karten sauber Platz haben
|
|
|
|
|
header_row = tk.Frame(self, bg=MODAL_BG)
|
|
|
|
|
header_row.pack(pady=(0, 6))
|
|
|
|
|
|
|
|
|
|
self.gif_lbl = tk.Label(header_row, bg=MODAL_BG, bd=0)
|
|
|
|
|
self.gif_lbl.pack(pady=(0, 4))
|
2026-11-14 04:25:51 +00:00
|
|
|
if self.data.get("player_won") is True:
|
|
|
|
|
self._start_gif("win_gif")
|
|
|
|
|
elif self.data.get("player_won") is False:
|
|
|
|
|
self._start_gif("lose_gif")
|
|
|
|
|
|
|
|
|
|
headline_color = ACCENT_GOLD if self.data.get("player_won") else (
|
|
|
|
|
MUTED_FG if self.data.get("player_won") is None else ERROR_FG
|
|
|
|
|
)
|
|
|
|
|
tk.Label(
|
2026-11-14 23:28:01 +00:00
|
|
|
header_row, text=self.data["headline"],
|
|
|
|
|
font=("Georgia", 17, "bold"), fg=headline_color, bg=MODAL_BG,
|
|
|
|
|
).pack()
|
2026-11-14 04:25:51 +00:00
|
|
|
|
2026-11-14 23:28:01 +00:00
|
|
|
# Klare Begründung (z. B. warum Natural BJ gegen 3-Karten-21 gewonnen hat)
|
|
|
|
|
reason_txt = self.data.get("reason_text", "")
|
|
|
|
|
if reason_txt:
|
|
|
|
|
reason_box = tk.Frame(
|
|
|
|
|
self, bg=PANEL_BG, padx=14, pady=7,
|
|
|
|
|
highlightthickness=1, highlightbackground=ACCENT_GOLD
|
|
|
|
|
)
|
|
|
|
|
reason_box.pack(fill="x", pady=(2, 10))
|
|
|
|
|
tk.Label(
|
|
|
|
|
reason_box, text=reason_txt,
|
|
|
|
|
font=("Helvetica", 10, "bold"), fg=ACCENT_GOLD, bg=PANEL_BG,
|
|
|
|
|
wraplength=760, justify="center"
|
|
|
|
|
).pack()
|
|
|
|
|
|
|
|
|
|
# =========================================================
|
|
|
|
|
# SHOWDOWN-KARTENANSICHT ALLER TEILNEHMER (Dealer, Du, Bots)
|
|
|
|
|
# =========================================================
|
|
|
|
|
hands_list = self.data.get("showdown_hands", [])
|
|
|
|
|
if hands_list:
|
|
|
|
|
hands_outer = tk.Frame(
|
|
|
|
|
self, bg=CELL_BG, padx=12, pady=10,
|
|
|
|
|
highlightthickness=1, highlightbackground=SUBTLE_BORDER
|
|
|
|
|
)
|
|
|
|
|
hands_outer.pack(fill="x", pady=(0, 10))
|
|
|
|
|
|
|
|
|
|
tk.Label(
|
|
|
|
|
hands_outer, text=t("bj_showdown_section_title"),
|
|
|
|
|
font=("Georgia", 10, "bold"), fg=ACCENT_GOTH, bg=CELL_BG
|
|
|
|
|
).pack(anchor="w", pady=(0, 6))
|
|
|
|
|
|
|
|
|
|
cards_grid = tk.Frame(hands_outer, bg=CELL_BG)
|
|
|
|
|
cards_grid.pack()
|
|
|
|
|
|
|
|
|
|
max_cols = 3 if len(hands_list) <= 3 else 3
|
|
|
|
|
for idx, entry in enumerate(hands_list):
|
|
|
|
|
r_idx = idx // max_cols
|
|
|
|
|
c_idx = idx % max_cols
|
|
|
|
|
|
|
|
|
|
is_win = entry.get("is_winner", False)
|
|
|
|
|
is_dead = entry.get("busted", False) or entry.get("folded", False)
|
|
|
|
|
border_col = ACCENT_GOLD if is_win else (ERROR_FG if is_dead else SUBTLE_BORDER)
|
|
|
|
|
|
|
|
|
|
seat_card = tk.Frame(
|
|
|
|
|
cards_grid, bg=PANEL_BG, padx=10, pady=7,
|
|
|
|
|
highlightthickness=2 if is_win else 1, highlightbackground=border_col
|
|
|
|
|
)
|
|
|
|
|
seat_card.grid(row=r_idx, column=c_idx, padx=5, pady=4, sticky="nsew")
|
|
|
|
|
|
|
|
|
|
title_col = ACCENT_GOLD if is_win else (ACCENT_GOTH if entry.get("is_dealer") else FG_COLOR)
|
|
|
|
|
tk.Label(
|
|
|
|
|
seat_card, text=entry["owner_label"],
|
|
|
|
|
font=("Georgia", 10, "bold"), fg=title_col, bg=PANEL_BG
|
|
|
|
|
).pack()
|
|
|
|
|
|
|
|
|
|
c_row = tk.Frame(seat_card, bg=PANEL_BG)
|
|
|
|
|
c_row.pack(pady=4)
|
|
|
|
|
for img_name in entry.get("card_images", []):
|
|
|
|
|
photo = self.assets.get_card_photo(img_name, size=SHOWDOWN_MINI_CARD_SIZE)
|
|
|
|
|
if photo:
|
|
|
|
|
self._card_photos.append(photo)
|
|
|
|
|
tk.Label(c_row, image=photo, bg=PANEL_BG, bd=0).pack(side="left", padx=2)
|
|
|
|
|
|
|
|
|
|
badge_col = (
|
|
|
|
|
"#7be08a" if is_win else (ERROR_FG if is_dead else FG_COLOR)
|
|
|
|
|
)
|
|
|
|
|
tk.Label(
|
|
|
|
|
seat_card, text=entry["rank_label"],
|
|
|
|
|
font=("Helvetica", 9, "bold"), fg=badge_col, bg=PANEL_BG
|
|
|
|
|
).pack()
|
|
|
|
|
|
|
|
|
|
# =========================================================
|
|
|
|
|
# GOLD- & XP-ABRECHNUNG
|
|
|
|
|
# =========================================================
|
2026-11-14 04:25:51 +00:00
|
|
|
info_box = tk.Frame(
|
2026-11-14 23:28:01 +00:00
|
|
|
self, bg=CELL_BG, padx=18, pady=10,
|
2026-11-14 04:25:51 +00:00
|
|
|
highlightthickness=1, highlightbackground=SUBTLE_BORDER
|
|
|
|
|
)
|
2026-11-14 23:28:01 +00:00
|
|
|
info_box.pack(fill="x", pady=(0, 10))
|
2026-11-14 04:25:51 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2026-11-14 23:28:01 +00:00
|
|
|
tk.Label(info_box, text=own_txt, font=("Helvetica", 11, "bold"), fg=own_col, bg=CELL_BG).pack(pady=2)
|
2026-11-14 04:25:51 +00:00
|
|
|
|
|
|
|
|
for extra_line in self.data.get("other_gains", []):
|
2026-11-14 23:28:01 +00:00
|
|
|
tk.Label(info_box, text=extra_line, font=("Helvetica", 10), fg=MUTED_FG, bg=CELL_BG).pack(pady=1)
|
2026-11-14 04:25:51 +00:00
|
|
|
|
2026-11-14 23:28:01 +00:00
|
|
|
tk.Frame(info_box, bg=SUBTLE_BORDER, height=1).pack(fill="x", pady=6)
|
2026-11-14 04:25:51 +00:00
|
|
|
|
|
|
|
|
tk.Label(
|
|
|
|
|
info_box, text=t("bj_popup_xp_earned", self.data["xp_gained"]),
|
2026-11-14 23:28:01 +00:00
|
|
|
font=("Helvetica", 11, "bold"), fg=ACCENT_GOTH, bg=CELL_BG,
|
|
|
|
|
).pack(pady=1)
|
2026-11-14 04:25:51 +00:00
|
|
|
|
|
|
|
|
if self.data.get("new_level_title"):
|
|
|
|
|
tk.Label(
|
|
|
|
|
info_box, text=self.data["new_level_title"],
|
2026-11-14 23:28:01 +00:00
|
|
|
font=("Georgia", 10, "bold"), fg=ACCENT_GOLD, bg=CELL_BG,
|
|
|
|
|
).pack(pady=(3, 0))
|
2026-11-14 04:25:51 +00:00
|
|
|
|
|
|
|
|
btn_row = tk.Frame(self, bg=MODAL_BG)
|
2026-11-14 23:28:01 +00:00
|
|
|
btn_row.pack(fill="x", pady=(4, 0))
|
2026-11-14 04:25:51 +00:00
|
|
|
|
|
|
|
|
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,
|
2026-11-14 23:28:01 +00:00
|
|
|
self._handle_next, sound_mgr=self.sounds, width=195, height=38, font=("Helvetica", 10, "bold")
|
2026-11-14 04:25:51 +00:00
|
|
|
).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,
|
2026-11-14 23:28:01 +00:00
|
|
|
self._handle_menu, sound_mgr=self.sounds, width=165, height=38, font=("Helvetica", 10, "bold")
|
2026-11-14 04:25:51 +00:00
|
|
|
).pack(side="right")
|
|
|
|
|
|
|
|
|
|
def _start_gif(self, key: str):
|
|
|
|
|
frames = self.assets.get_gif_frames(key)
|
|
|
|
|
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
|
2026-11-14 23:28:01 +00:00
|
|
|
self._card_photos.clear()
|
2026-11-14 04:25:51 +00:00
|
|
|
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()
|