new: dev: initialize the GTK client #11
This commit is contained in:
96
gtk-client/mineseeker/ui/bonus_dialog.py
Normal file
96
gtk-client/mineseeker/ui/bonus_dialog.py
Normal file
@@ -0,0 +1,96 @@
|
||||
"""
|
||||
This file is part of the SplendidBear Websites' projects.
|
||||
|
||||
Copyright (c) 2026 @ www.splendidbear.org
|
||||
|
||||
For the full copyright and license information, please view the LICENSE
|
||||
file that was distributed with this source code.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import gi
|
||||
gi.require_version("Gtk", "4.0")
|
||||
gi.require_version("Adw", "1")
|
||||
from gi.repository import Gtk, Adw
|
||||
|
||||
from mineseeker.state.game_state import BonusStats
|
||||
from mineseeker.constants import BONUS_LABELS
|
||||
|
||||
|
||||
class BonusDialog(Adw.Dialog):
|
||||
"""Modal dialog displaying bonus stats for both players."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
parent: Gtk.Widget,
|
||||
red_name: str,
|
||||
blue_name: str,
|
||||
red_points: float,
|
||||
blue_points: float,
|
||||
red_stats: BonusStats,
|
||||
blue_stats: BonusStats,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.set_title("Bonus Statistics")
|
||||
self.set_content_width(480)
|
||||
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
|
||||
|
||||
header = Adw.HeaderBar()
|
||||
box.append(header)
|
||||
|
||||
content = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=16)
|
||||
content.set_margin_top(16)
|
||||
content.set_margin_bottom(16)
|
||||
content.set_margin_start(16)
|
||||
content.set_margin_end(16)
|
||||
|
||||
# Totals row
|
||||
totals = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
|
||||
totals.add_css_class("card")
|
||||
|
||||
red_total = Gtk.Label(label=f"{red_name}: {red_points:.1f} pts")
|
||||
red_total.add_css_class("red-player")
|
||||
red_total.set_hexpand(True)
|
||||
red_total.set_xalign(0)
|
||||
red_total.set_margin_start(12)
|
||||
red_total.set_margin_top(8)
|
||||
red_total.set_margin_bottom(8)
|
||||
totals.append(red_total)
|
||||
|
||||
blue_total = Gtk.Label(label=f"{blue_name}: {blue_points:.1f} pts")
|
||||
blue_total.add_css_class("blue-player")
|
||||
blue_total.set_hexpand(True)
|
||||
blue_total.set_xalign(1)
|
||||
blue_total.set_margin_end(12)
|
||||
totals.append(blue_total)
|
||||
|
||||
content.append(totals)
|
||||
|
||||
# Per-stat rows
|
||||
group = Adw.PreferencesGroup(title="Breakdown")
|
||||
stat_fields = [
|
||||
("blind_hits", red_stats.blind_hits, blue_stats.blind_hits),
|
||||
("chain_best", red_stats.chain_best, blue_stats.chain_best),
|
||||
("last_mine_hits",red_stats.last_mine_hits,blue_stats.last_mine_hits),
|
||||
("edge_mines", red_stats.edge_mines, blue_stats.edge_mines),
|
||||
("biggest_reveal",red_stats.biggest_reveal,blue_stats.biggest_reveal),
|
||||
]
|
||||
key_map = {
|
||||
"blind_hits": "blindHits",
|
||||
"chain_best": "chainBest",
|
||||
"last_mine_hits": "lastMineHits",
|
||||
"edge_mines": "edgeMines",
|
||||
"biggest_reveal": "biggestReveal",
|
||||
}
|
||||
for field_name, rv, bv in stat_fields:
|
||||
label = BONUS_LABELS.get(key_map[field_name], field_name)
|
||||
row = Adw.ActionRow(title=label)
|
||||
row.set_subtitle(f"Red: {rv} Blue: {bv}")
|
||||
group.add(row)
|
||||
|
||||
content.append(group)
|
||||
box.append(content)
|
||||
self.set_child(box)
|
||||
self.present(parent)
|
||||
Reference in New Issue
Block a user