# -*- coding: utf-8 -*- # games/poker/views/poker_result_dialog.py from __future__ import annotations from models.card import Card 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 POPUP_HOLE_CARD_SIZE = (46, 68) POPUP_BOARD_CARD_SIZE = (44, 64) class PokerResultDialog(CasinoResultDialogBase): """Gothic-Showdown-Overlay für Texas Hold'em auf Basis von CasinoResultDialogBase.""" def __init__(self, parent, assets, sounds, result_data: dict, on_next_round, on_back_to_menu): seats = result_data.get("seat_showdown", []) has_board = bool(result_data.get("board_cards")) cols = min(3, max(1, len(seats))) rows = (len(seats) + 2) // 3 if seats else 0 extra_lines = len(result_data.get("other_gains", [])) dlg_w = max(580, min(840, cols * 252 + 64)) dlg_h = ( 62 + (86 if has_board else 8) + (rows * 134 + 14 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: board_raw = self.data.get("board_cards", []) if board_raw: b_box_h = 76 b_cy = cur_y + b_box_h // 2 b_box = self.assets.get_box_photo("box_gold_double", (w - 56, b_box_h)) if b_box: self._photo_refs.append(b_box) self.create_image(cx, b_cy, image=b_box, anchor="center") lbl_ph = self.assets.get_goth_text_photo( f"{t('pk_board_title')}:", FONT_SIZE_SMALL_MIN, FONT_COLOR_HEADING_SUB, align="left" ) self._photo_refs.append(lbl_ph) b_photos = [] for s_suit, s_rank in board_raw: ph = self.assets.get_card_photo(Card(s_suit, s_rank).image_filename, size=POPUP_BOARD_CARD_SIZE) if ph: self._photo_refs.append(ph) b_photos.append(ph) cw_b, ch_b = POPUP_BOARD_CARD_SIZE cards_w = len(b_photos) * cw_b + max(0, len(b_photos) - 1) * 6 total_w = lbl_ph.width() + 14 + cards_w start_x = cx - total_w // 2 self.create_image(start_x, b_cy, image=lbl_ph, anchor="w") cx_card = start_x + lbl_ph.width() + 14 for bph in b_photos: self.create_image(cx_card, b_cy - ch_b // 2, image=bph, anchor="nw") cx_card += cw_b + 6 cur_y += b_box_h + 8 seats = self.data.get("seat_showdown", []) if not seats: return cur_y max_cols = 3 rows = (len(seats) + max_cols - 1) // max_cols seat_w = min(244, (w - 64 - (max_cols - 1) * 10) // max(1, min(max_cols, len(seats)))) seat_h = 126 if rows > 1 else 132 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(seats): r_i, c_i = divmod(idx, max_cols) in_row = min(max_cols, len(seats) - 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, folded = entry["is_winner"], entry["folded"] frame_ph = win_box if is_win else std_box if frame_ph: self.create_image(sx, sy, image=frame_ph, anchor="center") n_col = FONT_COLOR_TITLE_MAIN if is_win else (FONT_COLOR_BODY_MUTED if folded else FONT_COLOR_HEADING_SUB) n_ph = self.assets.get_goth_text_photo(entry["name"], FONT_SIZE_SMALL_MIN + 1, n_col, max_width=seat_w - 24) self._photo_refs.append(n_ph) self.create_image(sx, sy - seat_h // 2 + 19, image=n_ph, anchor="center") cw_h, ch_h = POPUP_HOLE_CARD_SIZE h_photos = [ ph for s_suit, s_rank in entry["cards"] if (ph := self.assets.get_card_photo(Card(s_suit, s_rank).image_filename, size=POPUP_HOLE_CARD_SIZE)) ] self._photo_refs.extend(h_photos) if h_photos: span_w = len(h_photos) * cw_h + max(0, len(h_photos) - 1) * 6 hx = sx - span_w // 2 for hph in h_photos: self.create_image(hx, sy - ch_h // 2 + 1, image=hph, anchor="nw") hx += cw_h + 6 cb_col = FONT_COLOR_STATUS_WIN if is_win else (FONT_COLOR_STATUS_LOSS if folded else FONT_COLOR_BODY_DEFAULT) cb_ph = self.assets.get_goth_text_photo(entry["combo_text"], FONT_SIZE_SMALL_MIN, cb_col, max_width=seat_w - 20) self._photo_refs.append(cb_ph) self.create_image(sx, sy + seat_h // 2 - 18, image=cb_ph, anchor="center") return cur_y + rows * (seat_h + 6) + 6