2026-11-14 04:25:51 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
# controller/app_context.py
|
feat(ui): overhaul menus, stats & dialogs to custom canvas-based Gothic UI
- Add ui_typography.py and update game_constants.py for Old London typography and new image assets
- Upgrade AssetManager with downscaled 9-slice box rendering and PIL Old London text engine
- Convert ResizingBG to full-window Canvas with automatic horizontal/vertical background switching
- Add GothEntry and two-part GothDropdown with proportional arrow cap, mousewheel scrolling, and scroll indicators
- Update ImageButton with 3-slice side caps, frame-aware auto-width, and automatic icon stripping
- Refactor GothTopbar, LoginView, MainMenuView (hover zoom), StatisticsView, StatsBoardWidget, BotSetupWidget, and AudioSettingsDialog
- Migrate Blackjack, Poker, FreeCell, Klondike, and Spider menu/stats views plus BlackjackResultDialog to frameless canvas layouts
- Fix Crostini shelf icon matching via exact X11 WM_CLASS and absolute pixmap path
2026-11-17 21:31:02 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-11-14 04:25:51 +00:00
|
|
|
from models.database import Database
|
|
|
|
|
from view.dialogs.audio_settings_dialog import AudioSettingsDialog
|
2026-11-21 01:20:50 +00:00
|
|
|
from view.unified_stats_view import UnifiedStatsView
|
feat(ui): overhaul menus, stats & dialogs to custom canvas-based Gothic UI
- Add ui_typography.py and update game_constants.py for Old London typography and new image assets
- Upgrade AssetManager with downscaled 9-slice box rendering and PIL Old London text engine
- Convert ResizingBG to full-window Canvas with automatic horizontal/vertical background switching
- Add GothEntry and two-part GothDropdown with proportional arrow cap, mousewheel scrolling, and scroll indicators
- Update ImageButton with 3-slice side caps, frame-aware auto-width, and automatic icon stripping
- Refactor GothTopbar, LoginView, MainMenuView (hover zoom), StatisticsView, StatsBoardWidget, BotSetupWidget, and AudioSettingsDialog
- Migrate Blackjack, Poker, FreeCell, Klondike, and Spider menu/stats views plus BlackjackResultDialog to frameless canvas layouts
- Fix Crostini shelf icon matching via exact X11 WM_CLASS and absolute pixmap path
2026-11-17 21:31:02 +00:00
|
|
|
from view.widgets.goth_dropdown import GothDropdown
|
2026-11-21 01:20:50 +00:00
|
|
|
from view.widgets.goth_topbar import GothTopbar, format_compact_user_badge
|
2026-11-14 04:25:51 +00:00
|
|
|
|
2026-11-21 01:20:50 +00:00
|
|
|
__all__ = ["AppContext", "GothTopbar", "UnifiedStatsView", "format_compact_user_badge"]
|
2026-11-19 21:47:35 +00:00
|
|
|
|
feat(ui): overhaul menus, stats & dialogs to custom canvas-based Gothic UI
- Add ui_typography.py and update game_constants.py for Old London typography and new image assets
- Upgrade AssetManager with downscaled 9-slice box rendering and PIL Old London text engine
- Convert ResizingBG to full-window Canvas with automatic horizontal/vertical background switching
- Add GothEntry and two-part GothDropdown with proportional arrow cap, mousewheel scrolling, and scroll indicators
- Update ImageButton with 3-slice side caps, frame-aware auto-width, and automatic icon stripping
- Refactor GothTopbar, LoginView, MainMenuView (hover zoom), StatisticsView, StatsBoardWidget, BotSetupWidget, and AudioSettingsDialog
- Migrate Blackjack, Poker, FreeCell, Klondike, and Spider menu/stats views plus BlackjackResultDialog to frameless canvas layouts
- Fix Crostini shelf icon matching via exact X11 WM_CLASS and absolute pixmap path
2026-11-17 21:31:02 +00:00
|
|
|
|
2026-11-14 04:25:51 +00:00
|
|
|
class AppContext:
|
2026-11-21 01:20:50 +00:00
|
|
|
"""Schlanker Spiel-Kontext; Topbar und Statistik laufen zentral über eigene Widgets."""
|
|
|
|
|
|
2026-11-14 04:25:51 +00:00
|
|
|
def __init__(self, controller, game_folder: str):
|
|
|
|
|
self._ctrl = controller
|
|
|
|
|
self.game_folder = game_folder
|
|
|
|
|
self.root = controller.view
|
|
|
|
|
self.assets = controller.view.assets
|
|
|
|
|
self.sounds = controller.sounds
|
2026-11-21 01:20:50 +00:00
|
|
|
setattr(self.root, "_app_controller", controller)
|
2026-11-14 04:25:51 +00:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def profile(self) -> dict:
|
|
|
|
|
return self._ctrl.active_profile
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def game_progress(self) -> dict:
|
|
|
|
|
return Database.get_game_progress(self.profile["id"], self.game_folder)
|
|
|
|
|
|
|
|
|
|
def refresh_game_progress(self) -> dict:
|
|
|
|
|
return Database.get_game_progress(self.profile["id"], self.game_folder)
|
|
|
|
|
|
|
|
|
|
def back_to_main_menu(self):
|
feat(ui): overhaul menus, stats & dialogs to custom canvas-based Gothic UI
- Add ui_typography.py and update game_constants.py for Old London typography and new image assets
- Upgrade AssetManager with downscaled 9-slice box rendering and PIL Old London text engine
- Convert ResizingBG to full-window Canvas with automatic horizontal/vertical background switching
- Add GothEntry and two-part GothDropdown with proportional arrow cap, mousewheel scrolling, and scroll indicators
- Update ImageButton with 3-slice side caps, frame-aware auto-width, and automatic icon stripping
- Refactor GothTopbar, LoginView, MainMenuView (hover zoom), StatisticsView, StatsBoardWidget, BotSetupWidget, and AudioSettingsDialog
- Migrate Blackjack, Poker, FreeCell, Klondike, and Spider menu/stats views plus BlackjackResultDialog to frameless canvas layouts
- Fix Crostini shelf icon matching via exact X11 WM_CLASS and absolute pixmap path
2026-11-17 21:31:02 +00:00
|
|
|
GothDropdown.close_any_open_popup()
|
2026-11-14 04:25:51 +00:00
|
|
|
self._ctrl.show_main_menu()
|
|
|
|
|
|
2026-11-21 01:20:50 +00:00
|
|
|
def open_settings(self, on_lang_refresh=None):
|
feat(ui): overhaul menus, stats & dialogs to custom canvas-based Gothic UI
- Add ui_typography.py and update game_constants.py for Old London typography and new image assets
- Upgrade AssetManager with downscaled 9-slice box rendering and PIL Old London text engine
- Convert ResizingBG to full-window Canvas with automatic horizontal/vertical background switching
- Add GothEntry and two-part GothDropdown with proportional arrow cap, mousewheel scrolling, and scroll indicators
- Update ImageButton with 3-slice side caps, frame-aware auto-width, and automatic icon stripping
- Refactor GothTopbar, LoginView, MainMenuView (hover zoom), StatisticsView, StatsBoardWidget, BotSetupWidget, and AudioSettingsDialog
- Migrate Blackjack, Poker, FreeCell, Klondike, and Spider menu/stats views plus BlackjackResultDialog to frameless canvas layouts
- Fix Crostini shelf icon matching via exact X11 WM_CLASS and absolute pixmap path
2026-11-17 21:31:02 +00:00
|
|
|
GothDropdown.close_any_open_popup()
|
2026-11-21 01:20:50 +00:00
|
|
|
AudioSettingsDialog.open(
|
|
|
|
|
self.root,
|
|
|
|
|
self.assets,
|
|
|
|
|
self.sounds,
|
|
|
|
|
on_toggle_lang=lambda: self.toggle_language(on_lang_refresh),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def open_audio_settings(self):
|
|
|
|
|
self.open_settings(on_lang_refresh=None)
|
|
|
|
|
|
|
|
|
|
def open_stats(self, game_endpoint: str | None = None, on_back=None):
|
|
|
|
|
"""Öffnet die zentrale Statistik-Ansicht für `game_endpoint` (oder das aktive Spiel)."""
|
|
|
|
|
endpoint = self.game_folder if game_endpoint is None else game_endpoint
|
|
|
|
|
UnifiedStatsView.open(self, game_endpoint=endpoint, on_back=on_back)
|
|
|
|
|
|
|
|
|
|
# Alias für etwaige bestehende Aufrufe
|
|
|
|
|
open_global_stats = open_stats
|
2026-11-14 04:25:51 +00:00
|
|
|
|
|
|
|
|
def toggle_language(self, refresh_callback=None):
|
feat(ui): overhaul menus, stats & dialogs to custom canvas-based Gothic UI
- Add ui_typography.py and update game_constants.py for Old London typography and new image assets
- Upgrade AssetManager with downscaled 9-slice box rendering and PIL Old London text engine
- Convert ResizingBG to full-window Canvas with automatic horizontal/vertical background switching
- Add GothEntry and two-part GothDropdown with proportional arrow cap, mousewheel scrolling, and scroll indicators
- Update ImageButton with 3-slice side caps, frame-aware auto-width, and automatic icon stripping
- Refactor GothTopbar, LoginView, MainMenuView (hover zoom), StatisticsView, StatsBoardWidget, BotSetupWidget, and AudioSettingsDialog
- Migrate Blackjack, Poker, FreeCell, Klondike, and Spider menu/stats views plus BlackjackResultDialog to frameless canvas layouts
- Fix Crostini shelf icon matching via exact X11 WM_CLASS and absolute pixmap path
2026-11-17 21:31:02 +00:00
|
|
|
GothDropdown.close_any_open_popup()
|
2026-11-14 04:25:51 +00:00
|
|
|
self._ctrl.toggle_language(refresh_callback)
|
|
|
|
|
|
|
|
|
|
def record_result(
|
|
|
|
|
self,
|
|
|
|
|
variant_key: str,
|
|
|
|
|
won: bool,
|
|
|
|
|
duration_sec: float,
|
|
|
|
|
points_gained: int = 0,
|
2026-11-14 21:47:38 +00:00
|
|
|
bj_account_id: int | None = None,
|
|
|
|
|
pk_account_id: int | None = None,
|
2026-11-14 04:25:51 +00:00
|
|
|
) -> tuple[int, int]:
|
|
|
|
|
if not self._ctrl.active_profile:
|
|
|
|
|
return (1, 1)
|
|
|
|
|
pid = self._ctrl.active_profile["id"]
|
|
|
|
|
old_lvl, new_lvl = Database.record_game_result(
|
2026-11-14 21:47:38 +00:00
|
|
|
pid,
|
|
|
|
|
variant_key,
|
|
|
|
|
won,
|
|
|
|
|
duration_sec,
|
|
|
|
|
points_gained,
|
|
|
|
|
bj_account_id=bj_account_id,
|
|
|
|
|
pk_account_id=pk_account_id,
|
2026-11-14 04:25:51 +00:00
|
|
|
)
|
|
|
|
|
self.sounds.play("end_battle" if new_lvl > old_lvl else ("win" if won else "lose"))
|
|
|
|
|
return old_lvl, new_lvl
|
|
|
|
|
|
|
|
|
|
def build_game_topbar(
|
|
|
|
|
self,
|
|
|
|
|
parent,
|
2026-11-21 01:20:50 +00:00
|
|
|
title: str = "",
|
2026-11-14 04:25:51 +00:00
|
|
|
on_game_menu=None,
|
|
|
|
|
on_stats=None,
|
|
|
|
|
stats_enabled: bool = True,
|
|
|
|
|
extra_right_text: str = "",
|
|
|
|
|
on_lang_refresh=None,
|
|
|
|
|
locked_exit: bool = False,
|
2026-11-21 01:20:50 +00:00
|
|
|
stats_endpoint: str | None = None,
|
|
|
|
|
on_stats_back=None,
|
feat(ui): overhaul menus, stats & dialogs to custom canvas-based Gothic UI
- Add ui_typography.py and update game_constants.py for Old London typography and new image assets
- Upgrade AssetManager with downscaled 9-slice box rendering and PIL Old London text engine
- Convert ResizingBG to full-window Canvas with automatic horizontal/vertical background switching
- Add GothEntry and two-part GothDropdown with proportional arrow cap, mousewheel scrolling, and scroll indicators
- Update ImageButton with 3-slice side caps, frame-aware auto-width, and automatic icon stripping
- Refactor GothTopbar, LoginView, MainMenuView (hover zoom), StatisticsView, StatsBoardWidget, BotSetupWidget, and AudioSettingsDialog
- Migrate Blackjack, Poker, FreeCell, Klondike, and Spider menu/stats views plus BlackjackResultDialog to frameless canvas layouts
- Fix Crostini shelf icon matching via exact X11 WM_CLASS and absolute pixmap path
2026-11-17 21:31:02 +00:00
|
|
|
) -> GothTopbar:
|
2026-11-21 01:20:50 +00:00
|
|
|
"""Erstellt die universelle Topbar und verknüpft automatisch den Statistik-Endpunkt."""
|
feat(ui): overhaul menus, stats & dialogs to custom canvas-based Gothic UI
- Add ui_typography.py and update game_constants.py for Old London typography and new image assets
- Upgrade AssetManager with downscaled 9-slice box rendering and PIL Old London text engine
- Convert ResizingBG to full-window Canvas with automatic horizontal/vertical background switching
- Add GothEntry and two-part GothDropdown with proportional arrow cap, mousewheel scrolling, and scroll indicators
- Update ImageButton with 3-slice side caps, frame-aware auto-width, and automatic icon stripping
- Refactor GothTopbar, LoginView, MainMenuView (hover zoom), StatisticsView, StatsBoardWidget, BotSetupWidget, and AudioSettingsDialog
- Migrate Blackjack, Poker, FreeCell, Klondike, and Spider menu/stats views plus BlackjackResultDialog to frameless canvas layouts
- Fix Crostini shelf icon matching via exact X11 WM_CLASS and absolute pixmap path
2026-11-17 21:31:02 +00:00
|
|
|
bar = GothTopbar(
|
|
|
|
|
parent=parent,
|
|
|
|
|
ctx=self,
|
2026-11-21 01:20:50 +00:00
|
|
|
stats_endpoint=stats_endpoint if stats_endpoint is not None else self.game_folder,
|
|
|
|
|
on_stats_back=on_stats_back,
|
|
|
|
|
stats_enabled=stats_enabled,
|
|
|
|
|
on_lang_refresh=on_lang_refresh,
|
|
|
|
|
locked_exit=locked_exit,
|
feat(ui): overhaul menus, stats & dialogs to custom canvas-based Gothic UI
- Add ui_typography.py and update game_constants.py for Old London typography and new image assets
- Upgrade AssetManager with downscaled 9-slice box rendering and PIL Old London text engine
- Convert ResizingBG to full-window Canvas with automatic horizontal/vertical background switching
- Add GothEntry and two-part GothDropdown with proportional arrow cap, mousewheel scrolling, and scroll indicators
- Update ImageButton with 3-slice side caps, frame-aware auto-width, and automatic icon stripping
- Refactor GothTopbar, LoginView, MainMenuView (hover zoom), StatisticsView, StatsBoardWidget, BotSetupWidget, and AudioSettingsDialog
- Migrate Blackjack, Poker, FreeCell, Klondike, and Spider menu/stats views plus BlackjackResultDialog to frameless canvas layouts
- Fix Crostini shelf icon matching via exact X11 WM_CLASS and absolute pixmap path
2026-11-17 21:31:02 +00:00
|
|
|
title=title,
|
|
|
|
|
on_game_menu=on_game_menu,
|
|
|
|
|
on_stats=on_stats,
|
|
|
|
|
extra_right_text=extra_right_text,
|
2026-11-14 04:25:51 +00:00
|
|
|
)
|
feat(ui): overhaul menus, stats & dialogs to custom canvas-based Gothic UI
- Add ui_typography.py and update game_constants.py for Old London typography and new image assets
- Upgrade AssetManager with downscaled 9-slice box rendering and PIL Old London text engine
- Convert ResizingBG to full-window Canvas with automatic horizontal/vertical background switching
- Add GothEntry and two-part GothDropdown with proportional arrow cap, mousewheel scrolling, and scroll indicators
- Update ImageButton with 3-slice side caps, frame-aware auto-width, and automatic icon stripping
- Refactor GothTopbar, LoginView, MainMenuView (hover zoom), StatisticsView, StatsBoardWidget, BotSetupWidget, and AudioSettingsDialog
- Migrate Blackjack, Poker, FreeCell, Klondike, and Spider menu/stats views plus BlackjackResultDialog to frameless canvas layouts
- Fix Crostini shelf icon matching via exact X11 WM_CLASS and absolute pixmap path
2026-11-17 21:31:02 +00:00
|
|
|
bar.pack(fill="x", side="top")
|
2026-11-14 04:25:51 +00:00
|
|
|
return bar
|