130 lines
5.4 KiB
Python
130 lines
5.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# games/blackjack/views/round_result_dialog.py
|
|
from __future__ import annotations
|
|
|
|
from resources.code_res.game_constants import (
|
|
FONT_COLOR_BODY_DEFAULT,
|
|
FONT_COLOR_BODY_MUTED,
|
|
FONT_COLOR_HEADING_SUB,
|
|
FONT_COLOR_STATUS_LOSS,
|
|
FONT_COLOR_STATUS_WIN,
|
|
FONT_COLOR_TITLE_MAIN,
|
|
FONT_SIZE_SMALL_MIN,
|
|
)
|
|
from resources.code_res.i18n import t
|
|
from view.widgets.casino_result_dialog_base import CasinoResultDialogBase
|
|
|
|
SHOWDOWN_MINI_CARD_SIZE = (48, 70)
|
|
|
|
|
|
class BlackjackResultDialog(CasinoResultDialogBase):
|
|
"""Gothic-Showdown-Overlay für Blackjack auf Basis von CasinoResultDialogBase."""
|
|
|
|
def __init__(self, parent, assets, sounds, result_data: dict, on_next_round, on_back_to_menu):
|
|
hands_list = result_data.get("showdown_hands", [])
|
|
cols = min(3, max(1, len(hands_list)))
|
|
rows = (len(hands_list) + 2) // 3 if hands_list else 0
|
|
extra_lines = len(result_data.get("other_gains", []))
|
|
|
|
dlg_w = max(560, min(830, cols * 250 + 64))
|
|
dlg_h = (
|
|
58
|
|
+ (48 if result_data.get("reason_text") else 8)
|
|
+ (rows * 140 + 28 if rows else 0)
|
|
+ 92 + min(2, extra_lines) * 20
|
|
+ (24 if result_data.get("new_level_title") else 0)
|
|
+ 62
|
|
)
|
|
super().__init__(parent, assets, sounds, result_data, dlg_w, dlg_h, on_next_round, on_back_to_menu)
|
|
|
|
def _draw_showdown_middle(self, w: int, cx: int, cur_y: int) -> int:
|
|
reason_txt = self.data.get("reason_text", "")
|
|
if reason_txt:
|
|
r_ph = self.assets.get_goth_text_photo(
|
|
reason_txt, FONT_SIZE_SMALL_MIN + 1, FONT_COLOR_HEADING_SUB, max_width=w - 92
|
|
)
|
|
self._photo_refs.append(r_ph)
|
|
rb_h = max(36, r_ph.height() + 14)
|
|
rb_cy = cur_y + rb_h // 2
|
|
rb_box = self.assets.get_box_photo("box_gold_double", (w - 56, rb_h))
|
|
if rb_box:
|
|
self._photo_refs.append(rb_box)
|
|
self.create_image(cx, rb_cy, image=rb_box, anchor="center")
|
|
self.create_image(cx, rb_cy, image=r_ph, anchor="center")
|
|
cur_y += rb_h + 8
|
|
|
|
hands_list = self.data.get("showdown_hands", [])
|
|
if not hands_list:
|
|
return cur_y
|
|
|
|
sec_ph = self.assets.get_goth_text_photo(
|
|
t("bj_showdown_section_title"), FONT_SIZE_SMALL_MIN, FONT_COLOR_BODY_MUTED, align="left"
|
|
)
|
|
self._photo_refs.append(sec_ph)
|
|
self.create_image(32, cur_y + 10, image=sec_ph, anchor="w")
|
|
cur_y += 22
|
|
|
|
max_cols = 3
|
|
rows = (len(hands_list) + max_cols - 1) // max_cols
|
|
seat_w = min(242, (w - 64 - (max_cols - 1) * 10) // max(1, min(max_cols, len(hands_list))))
|
|
seat_h = 128 if rows > 1 else 136
|
|
|
|
win_box = self.assets.get_box_photo("box_gold_small", (seat_w, seat_h))
|
|
std_box = self.assets.get_box_photo("box_purple", (seat_w, seat_h))
|
|
if win_box:
|
|
self._photo_refs.append(win_box)
|
|
if std_box:
|
|
self._photo_refs.append(std_box)
|
|
|
|
for idx, entry in enumerate(hands_list):
|
|
r_i, c_i = divmod(idx, max_cols)
|
|
in_row = min(max_cols, len(hands_list) - r_i * max_cols)
|
|
row_total_w = in_row * seat_w + (in_row - 1) * 10
|
|
sx = (w - row_total_w) // 2 + c_i * (seat_w + 10) + seat_w // 2
|
|
sy = cur_y + r_i * (seat_h + 6) + seat_h // 2
|
|
|
|
is_win = entry.get("is_winner", False)
|
|
is_dead = entry.get("busted", False) or entry.get("folded", False)
|
|
|
|
frame_ph = win_box if is_win else std_box
|
|
if frame_ph:
|
|
self.create_image(sx, sy, image=frame_ph, anchor="center")
|
|
|
|
o_col = (
|
|
FONT_COLOR_TITLE_MAIN if is_win
|
|
else (FONT_COLOR_HEADING_SUB if entry.get("is_dealer") else FONT_COLOR_BODY_DEFAULT)
|
|
)
|
|
o_ph = self.assets.get_goth_text_photo(
|
|
entry["owner_label"], FONT_SIZE_SMALL_MIN + 1, o_col, max_width=seat_w - 24
|
|
)
|
|
self._photo_refs.append(o_ph)
|
|
self.create_image(sx, sy - seat_h // 2 + 20, image=o_ph, anchor="center")
|
|
|
|
c_photos = [
|
|
ph for img_name in entry.get("card_images", [])
|
|
if (ph := self.assets.get_card_photo(img_name, size=SHOWDOWN_MINI_CARD_SIZE)) is not None
|
|
]
|
|
self._photo_refs.extend(c_photos)
|
|
|
|
if c_photos:
|
|
cw_c, ch_c = SHOWDOWN_MINI_CARD_SIZE
|
|
n_c = len(c_photos)
|
|
step = 24
|
|
if n_c > 1 and (cw_c + (n_c - 1) * step) > (seat_w - 28):
|
|
step = max(14, (seat_w - 28 - cw_c) // (n_c - 1))
|
|
fan_w = cw_c + (n_c - 1) * step if n_c > 1 else cw_c
|
|
start_cx, card_top = sx - fan_w // 2, sy - ch_c // 2 + 2
|
|
for ci, cph in enumerate(c_photos):
|
|
self.create_image(start_cx + ci * step, card_top, image=cph, anchor="nw")
|
|
|
|
rk_col = (
|
|
FONT_COLOR_STATUS_WIN if is_win
|
|
else (FONT_COLOR_STATUS_LOSS if is_dead else FONT_COLOR_BODY_DEFAULT)
|
|
)
|
|
rk_ph = self.assets.get_goth_text_photo(
|
|
entry["rank_label"], FONT_SIZE_SMALL_MIN, rk_col, max_width=seat_w - 22
|
|
)
|
|
self._photo_refs.append(rk_ph)
|
|
self.create_image(sx, sy + seat_h // 2 - 18, image=rk_ph, anchor="center")
|
|
|
|
return cur_y + rows * (seat_h + 6) + 6 |