83 lines
3.2 KiB
Python
83 lines
3.2 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
# games/poker/views/poker_stats_view.py
|
||
|
|
import tkinter as tk
|
||
|
|
from models.database import Database
|
||
|
|
from resources.code_res.game_constants import ACCENT_GOLD, BG_COLOR, BORDER_COLOR, PANEL_BG
|
||
|
|
from resources.code_res.i18n import t
|
||
|
|
from view.widgets.image_button import ImageButton
|
||
|
|
from view.widgets.stats_board_widget import StatsBoardWidget
|
||
|
|
|
||
|
|
GAME_FOLDER_ID = "poker"
|
||
|
|
|
||
|
|
|
||
|
|
class PokerStatsView:
|
||
|
|
"""Dedizierte Statistik-Ansicht für die einzelnen Poker-Goldbeutel."""
|
||
|
|
def __init__(self, context, on_back_to_pk_menu):
|
||
|
|
self.ctx = context
|
||
|
|
self.on_back_to_pk_menu = on_back_to_pk_menu
|
||
|
|
|
||
|
|
def show(self, selected_acc_id: int | None = None):
|
||
|
|
self.ctx.root.clear_window(apply_global_bg=True)
|
||
|
|
pid = self.ctx.profile["id"]
|
||
|
|
accounts = Database.get_poker_accounts(pid)
|
||
|
|
|
||
|
|
if not accounts:
|
||
|
|
self.on_back_to_pk_menu(None)
|
||
|
|
return
|
||
|
|
|
||
|
|
active_acc = accounts[0]
|
||
|
|
if selected_acc_id is not None:
|
||
|
|
for a in accounts:
|
||
|
|
if a["id"] == selected_acc_id:
|
||
|
|
active_acc = a
|
||
|
|
break
|
||
|
|
|
||
|
|
self.ctx.build_game_topbar(
|
||
|
|
self.ctx.root,
|
||
|
|
t("pk_stats_view_topbar"),
|
||
|
|
on_game_menu=lambda: self.on_back_to_pk_menu(active_acc["id"]),
|
||
|
|
extra_right_text=t("pk_header_gold", active_acc["account_name"], active_acc["gold"]),
|
||
|
|
on_lang_refresh=lambda: self.show(active_acc["id"]),
|
||
|
|
)
|
||
|
|
|
||
|
|
container = tk.Frame(self.ctx.root, bg=BG_COLOR, padx=24, pady=18)
|
||
|
|
container.place(relx=0.5, rely=0.54, anchor="center", relwidth=0.88, relheight=0.82)
|
||
|
|
|
||
|
|
selector_panel = tk.Frame(
|
||
|
|
container, bg=PANEL_BG, padx=18, pady=14,
|
||
|
|
highlightthickness=1, highlightbackground=BORDER_COLOR
|
||
|
|
)
|
||
|
|
selector_panel.pack(fill="x", pady=(0, 16))
|
||
|
|
|
||
|
|
tk.Label(
|
||
|
|
selector_panel, text=t("bj_stats_select_acc_lbl"),
|
||
|
|
font=("Georgia", 13, "bold"), fg=ACCENT_GOLD, bg=PANEL_BG
|
||
|
|
).pack(anchor="w", pady=(0, 10))
|
||
|
|
|
||
|
|
tabs_row = tk.Frame(selector_panel, bg=PANEL_BG)
|
||
|
|
tabs_row.pack(fill="x")
|
||
|
|
|
||
|
|
for acc in accounts:
|
||
|
|
is_sel = (acc["id"] == active_acc["id"])
|
||
|
|
pil_norm = self.ctx.assets.raw_btn if is_sel else self.ctx.assets.raw_sel
|
||
|
|
pil_hov = self.ctx.assets.raw_btn_active if is_sel else self.ctx.assets.raw_sel_active
|
||
|
|
btn_lbl = f"{acc['account_name']} ({acc['gold']}g)"
|
||
|
|
|
||
|
|
ImageButton(
|
||
|
|
tabs_row, btn_lbl, pil_norm, pil_hov,
|
||
|
|
lambda aid=acc["id"]: self.show(selected_acc_id=aid),
|
||
|
|
sound_mgr=self.ctx.sounds, width=185, height=38, font=("Helvetica", 9, "bold")
|
||
|
|
).pack(side="left", padx=(0, 8))
|
||
|
|
|
||
|
|
pk_variants = Database.get_variants_for_filter(folder_path=GAME_FOLDER_ID)
|
||
|
|
pk_filter_map = {t("pk_filter_all_tables"): None}
|
||
|
|
for v in pk_variants:
|
||
|
|
pk_filter_map[v["translated_name"]] = v["id"]
|
||
|
|
|
||
|
|
board = StatsBoardWidget(
|
||
|
|
container,
|
||
|
|
title=t("bj_stats_acc_title", active_acc["account_name"]),
|
||
|
|
filter_map=pk_filter_map,
|
||
|
|
fetch_callback=lambda vid: Database.get_pk_account_stats_overview(active_acc["id"], vid)
|
||
|
|
)
|
||
|
|
board.pack(fill="x")
|