From 26ddf5379e33ba833522d7c6521acd92163f8b69 Mon Sep 17 00:00:00 2001 From: Poleric Date: Sat, 6 Jun 2026 16:39:22 +0800 Subject: [PATCH] feat: add leaderboard resetting --- .../gui/InventoryWars/IdleView.qml | 18 ++++++++++++++++-- src/inventory_wars/gui/InventoryWars/Main.qml | 1 + src/inventory_wars/gui/app.py | 12 +++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/inventory_wars/gui/InventoryWars/IdleView.qml b/src/inventory_wars/gui/InventoryWars/IdleView.qml index 3134343..d78019d 100644 --- a/src/inventory_wars/gui/InventoryWars/IdleView.qml +++ b/src/inventory_wars/gui/InventoryWars/IdleView.qml @@ -15,6 +15,7 @@ Rectangle { required property SqlLeaderboardModel leaderboard required property ListModel rounds + required property GameService gameService property QtObject selectedRound: rounds.get(0) property bool selected: false @@ -152,10 +153,23 @@ Rectangle { } } } + + Button { + Layout.alignment: Qt.AlignHCenter + + // buttonColor: UIStyle.highlightColor + // buttonBorderColor: UIStyle.highlightBorderColor + // textColor: UIStyle.textColor + + text: "Reset" + + onClicked: { + root.gameService.resetScore() + leaderboard.select() + } + } } - - Item { Layout.fillHeight: true } } } diff --git a/src/inventory_wars/gui/InventoryWars/Main.qml b/src/inventory_wars/gui/InventoryWars/Main.qml index 0d9c243..44c5bff 100644 --- a/src/inventory_wars/gui/InventoryWars/Main.qml +++ b/src/inventory_wars/gui/InventoryWars/Main.qml @@ -61,6 +61,7 @@ ApplicationWindow { leaderboard: leaderboard rounds: rounds + gameService: gameService onRoundSelected: { idleView.visible = false ongoingView.start() diff --git a/src/inventory_wars/gui/app.py b/src/inventory_wars/gui/app.py index 7457a27..3864b63 100644 --- a/src/inventory_wars/gui/app.py +++ b/src/inventory_wars/gui/app.py @@ -8,12 +8,12 @@ from PySide6.QtCore import QObject, Signal, Slot, Property, QEnum, Qt, QCoreAppl from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine, QmlElement from PySide6.QtSql import QSqlTableModel, QSqlDatabase -from sqlalchemy import create_engine +from sqlalchemy import create_engine, update from sqlalchemy.orm import Session from star_resonance_tracer.proto.enum_chit_chat_channel_type_pb2 import ChitChatChannelType from inventory_wars.game import Game -from inventory_wars.models import Base, ItemShare +from inventory_wars.models import Base, ItemShare, User from inventory_wars.scoring import FirstGuess, FirstThenHighest, HighestAmount from inventory_wars.state import GameOngoing, GameIdle @@ -129,7 +129,13 @@ class GameService(QObject): return self.m_revealed @Slot() - def end(self): + def resetScore(self) -> None: + stmt = update(User).values(score=0) + session.execute(stmt) + session.commit() + + @Slot() + def end(self) -> None: self.m_game.end() self.stateChanged.emit()