176 lines
6.5 KiB
Python
176 lines
6.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# view/stats_detail_renderer.py
|
|
from __future__ import annotations
|
|
|
|
import tkinter as tk
|
|
|
|
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_BODY,
|
|
FONT_SIZE_HEADING,
|
|
FONT_SIZE_SMALL_MIN,
|
|
STAT_FIELD_KEYS,
|
|
SUBTLE_BORDER,
|
|
UI_ACCENT_AMETHYST,
|
|
UI_ACCENT_GOLD,
|
|
)
|
|
from resources.code_res.i18n import t
|
|
|
|
|
|
class StatsDetailRenderer:
|
|
"""Rendert die Detail-Statistikansicht eines einzelnen Kartenspiels."""
|
|
|
|
@staticmethod
|
|
def draw_detail(
|
|
cv: tk.Canvas,
|
|
assets,
|
|
game_title: str,
|
|
rank_line: str,
|
|
xp_ratio: float,
|
|
board_heading: str,
|
|
stats_data: dict,
|
|
back_btn: tk.Widget,
|
|
hub_btn: tk.Widget | None,
|
|
var_btns: list[tuple[tk.Widget, int]],
|
|
acc_btns: list[tuple[tk.Widget, int]],
|
|
photo_refs: list,
|
|
w: int,
|
|
h: int,
|
|
) -> None:
|
|
compact = (h < 780)
|
|
pad_x = max(72, int(w * 0.08))
|
|
content_w = min(1080, w - 2 * pad_x)
|
|
left_x = (w - content_w) // 2
|
|
top_y = max(48, int(h * 0.085))
|
|
|
|
cv.create_window(left_x, top_y, window=back_btn, anchor="w", tags="fg")
|
|
if hub_btn is not None:
|
|
cv.create_window(left_x + content_w, top_y, window=hub_btn, anchor="e", tags="fg")
|
|
|
|
hdr_ph = assets.get_goth_text_photo(
|
|
t("stats_view_topbar", game_title),
|
|
size_px=FONT_SIZE_HEADING + (0 if compact else 2),
|
|
color=FONT_COLOR_TITLE_MAIN,
|
|
max_width=max(220, content_w - 340),
|
|
)
|
|
photo_refs.append(hdr_ph)
|
|
cv.create_image(w // 2, top_y, image=hdr_ph, anchor="center", tags="fg")
|
|
|
|
sep_y = top_y + (34 if compact else 42)
|
|
cv.create_line(left_x, sep_y, left_x + content_w, sep_y, fill=SUBTLE_BORDER, width=1, tags="fg")
|
|
cur_y = sep_y + (16 if compact else 22)
|
|
|
|
# 1. Rang-, Varianten- & optionale Goldbeutel-Box
|
|
has_acc = len(acc_btns) > 0
|
|
has_vars = len(var_btns) > 0
|
|
hdr_h = 112 if has_acc else (98 if has_vars else 72)
|
|
hdr_cy = cur_y + hdr_h // 2
|
|
|
|
hdr_box = assets.get_box_photo("box_gold_double", (content_w, hdr_h))
|
|
if hdr_box:
|
|
photo_refs.append(hdr_box)
|
|
cv.create_image(w // 2, hdr_cy, image=hdr_box, anchor="center", tags="fg")
|
|
|
|
top_row_y = (cur_y + 28) if (has_acc or has_vars) else hdr_cy
|
|
bar_w = 210
|
|
rank_ph = assets.get_goth_text_photo(
|
|
rank_line,
|
|
size_px=FONT_SIZE_BODY + 1,
|
|
color=FONT_COLOR_TITLE_MAIN,
|
|
max_width=max(220, content_w - bar_w - 72),
|
|
align="left",
|
|
)
|
|
photo_refs.append(rank_ph)
|
|
cv.create_image(left_x + 26, top_row_y, image=rank_ph, anchor="w", tags="fg")
|
|
|
|
# XP-Fortschrittsbalken rechts
|
|
bx2 = left_x + content_w - 26
|
|
bx1 = bx2 - bar_w
|
|
by1, by2 = top_row_y - 7, top_row_y + 7
|
|
cv.create_rectangle(bx1, by1, bx2, by2, fill="#0b0810", outline=UI_ACCENT_GOLD, width=1, tags="fg")
|
|
clamped = max(0.0, min(1.0, xp_ratio))
|
|
if clamped > 0.0:
|
|
fw = max(2, int((bar_w - 4) * clamped))
|
|
cv.create_rectangle(bx1 + 2, by1 + 2, bx1 + 2 + fw, by2 - 2, fill=UI_ACCENT_AMETHYST, outline="", tags="fg")
|
|
|
|
sub_row_y = cur_y + hdr_h - 28
|
|
if has_acc:
|
|
ax = left_x + 26
|
|
p_ph = assets.get_goth_text_photo(t("stats_pouch_lbl"), FONT_SIZE_BODY, FONT_COLOR_HEADING_SUB, align="left")
|
|
photo_refs.append(p_ph)
|
|
cv.create_image(ax, sub_row_y, image=p_ph, anchor="w", tags="fg")
|
|
ax += p_ph.width() + 12
|
|
for b_wgt, bw in acc_btns:
|
|
cv.create_window(ax, sub_row_y, window=b_wgt, anchor="w", tags="fg")
|
|
ax += bw + 8
|
|
|
|
if has_vars:
|
|
rx = left_x + content_w - 24
|
|
for b_wgt, bw in reversed(var_btns):
|
|
cv.create_window(rx, sub_row_y, window=b_wgt, anchor="e", tags="fg")
|
|
rx -= (bw + 6)
|
|
|
|
cur_y += hdr_h + (14 if compact else 18)
|
|
|
|
# 2. 8-Kacheln-Statistik-Board
|
|
bottom_safe = max(46, int(h * 0.075))
|
|
board_h = max(248, min(360, h - cur_y - bottom_safe))
|
|
board_cy = cur_y + board_h // 2
|
|
|
|
outer_box = assets.get_box_photo("box_big", (content_w, board_h))
|
|
if outer_box:
|
|
photo_refs.append(outer_box)
|
|
cv.create_image(w // 2, board_cy, image=outer_box, anchor="center", tags="fg")
|
|
|
|
sub_ph = assets.get_goth_text_photo(
|
|
board_heading,
|
|
size_px=FONT_SIZE_HEADING - 3,
|
|
color=FONT_COLOR_HEADING_SUB,
|
|
max_width=content_w - 56,
|
|
align="left",
|
|
)
|
|
photo_refs.append(sub_ph)
|
|
cv.create_image(left_x + 28, cur_y + 30, image=sub_ph, anchor="w", tags="fg")
|
|
|
|
grid_top = cur_y + 58
|
|
grid_h = board_h - 78
|
|
cols, rows = 4, 2
|
|
gap_x, gap_y = 14, 12
|
|
cell_w = (content_w - 56 - (cols - 1) * gap_x) // cols
|
|
cell_h = max(68, (grid_h - (rows - 1) * gap_y) // rows)
|
|
|
|
cell_frame = assets.get_box_photo("box_purple", (cell_w, cell_h))
|
|
if cell_frame:
|
|
photo_refs.append(cell_frame)
|
|
|
|
for idx, (field_key, label_i18n_key) in enumerate(STAT_FIELD_KEYS):
|
|
r, c = divmod(idx, cols)
|
|
cx = left_x + 28 + c * (cell_w + gap_x) + cell_w // 2
|
|
cy = grid_top + r * (cell_h + gap_y) + cell_h // 2
|
|
|
|
if cell_frame:
|
|
cv.create_image(cx, cy, image=cell_frame, anchor="center", tags="fg")
|
|
|
|
lbl_ph = assets.get_goth_text_photo(
|
|
t(label_i18n_key), FONT_SIZE_SMALL_MIN, FONT_COLOR_BODY_MUTED, max_width=cell_w - 24
|
|
)
|
|
if field_key == "won":
|
|
v_col = FONT_COLOR_STATUS_WIN
|
|
elif field_key == "lost":
|
|
v_col = FONT_COLOR_STATUS_LOSS
|
|
elif "streak" in field_key or field_key == "win_pct":
|
|
v_col = FONT_COLOR_HEADING_SUB
|
|
else:
|
|
v_col = FONT_COLOR_BODY_DEFAULT
|
|
|
|
val_ph = assets.get_goth_text_photo(
|
|
str(stats_data.get(field_key, "--")), FONT_SIZE_HEADING - 2, v_col, max_width=cell_w - 24
|
|
)
|
|
photo_refs.extend([lbl_ph, val_ph])
|
|
cv.create_image(cx, cy - cell_h // 4 + 2, image=lbl_ph, anchor="center", tags="fg")
|
|
cv.create_image(cx, cy + cell_h // 5 + 2, image=val_ph, anchor="center", tags="fg") |