1
0

feat: add leaderboard

This commit is contained in:
2026-06-05 01:33:51 +08:00
parent e11f48d93b
commit 1b10d2841f
3 changed files with 99 additions and 26 deletions
@@ -13,6 +13,7 @@ Rectangle {
color: UIStyle.background color: UIStyle.background
required property SqlLeaderboardModel leaderboard
required property ListModel rounds required property ListModel rounds
property QtObject selectedRound property QtObject selectedRound
@@ -66,40 +67,79 @@ Rectangle {
} }
} }
TableView { Label {
Layout.fillHeight: true Layout.alignment: Qt.AlignHCenter
columnSpacing: 1 font.pixelSize: UIStyle.fontSizeL
rowSpacing: 1 color: UIStyle.titletextColor
text: "Leaderboard"
}
ColumnLayout {
Layout.fillHeight: true
Layout.fillWidth: true
spacing: -1
HorizontalHeaderView {
Layout.fillWidth: true
syncView: tableView
clip: true
columnSpacing: -1
rowSpacing: -1
boundsBehavior: Flickable.StopAtBounds
rowHeightProvider: function (row) {
return 35
}
delegate: Rectangle {
border.width: 1
color: "#f1f1f1"
Text {
anchors.centerIn: parent
font.bold: true
text: display
}
}
}
TableView {
id: tableView
Layout.fillHeight: true
Layout.fillWidth: true
clip: true
columnSpacing: -1
rowSpacing: -1
boundsBehavior: Flickable.StopAtBounds
model: leaderboard
columnWidthProvider: function (column) {
if (column === 0)
return tableView.width * 0.6
return tableView.width * 0.4
}
rowHeightProvider: function (row) {
return 35
}
onWidthChanged: tableView.forceLayout()
delegate: Rectangle { delegate: Rectangle {
border.width: 1 border.width: 1
implicitHeight: 50
implicitWidth: 100
Text { Text {
anchors.centerIn: parent anchors.centerIn: parent
text: display text: display
} }
} }
model: TableModel {
rows: [
{
User: "me",
Score: "1"
} }
]
TableModelColumn {
display: "User"
} }
TableModelColumn {
display: "Score"
}
}
}
Item { Layout.fillHeight: true } Item { Layout.fillHeight: true }
} }
+10 -4
View File
@@ -18,11 +18,11 @@ ApplicationWindow {
ListElement { ListElement {
name: "Round 1" name: "Round 1"
mode: GameService.GameScoring.FirstGuess mode: GameService.GameScoring.FirstGuessThenHighestAmount
item_id: 100 item_id: 1061153
item_name: "Item 1" item_name: "Dreamweave Silk Selection Gift Box"
item_image: "" item_image: ""
clue: "Clue 1" clue: "Dreamweave Silk Selection Gift Box"
} }
ListElement { ListElement {
name: "Round 2" name: "Round 2"
@@ -50,11 +50,16 @@ ApplicationWindow {
} }
} }
SqlLeaderboardModel {
id: leaderboard
}
IdleView { IdleView {
id: idleView id: idleView
anchors.fill: parent anchors.fill: parent
leaderboard: leaderboard
rounds: rounds rounds: rounds
selectedRound: rounds.get(0) selectedRound: rounds.get(0)
onRoundSelected: { onRoundSelected: {
@@ -75,6 +80,7 @@ ApplicationWindow {
onClose: { onClose: {
idleView.visible = true idleView.visible = true
ongoingView.visible = false ongoingView.visible = false
leaderboard.select()
} }
} }
+28 -1
View File
@@ -3,9 +3,10 @@ import sys
from datetime import datetime from datetime import datetime
from enum import Enum from enum import Enum
from PySide6.QtCore import QObject, Signal, Slot, Property, QEnum from PySide6.QtCore import QObject, Signal, Slot, Property, QEnum, Qt, QCoreApplication
from PySide6.QtGui import QGuiApplication from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine, QmlElement from PySide6.QtQml import QQmlApplicationEngine, QmlElement
from PySide6.QtSql import QSqlTableModel, QSqlDatabase
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from star_resonance_tracer.proto.enum_chit_chat_channel_type_pb2 import ChitChatChannelType from star_resonance_tracer.proto.enum_chit_chat_channel_type_pb2 import ChitChatChannelType
@@ -145,14 +146,40 @@ class GameService(QObject):
return 0 return 0
@QmlElement
class SqlLeaderboardModel(QSqlTableModel):
def __init__(self, parent=None):
super().__init__(parent)
self.setTable("v_score")
self.setSort(2, Qt.SortOrder.DescendingOrder)
self.setHeaderData(0, Qt.Orientation.Horizontal, "User")
self.setHeaderData(1, Qt.Orientation.Horizontal, "Score")
self.select()
logger = logging.getLogger(__name__)
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
app = QGuiApplication(sys.argv) app = QGuiApplication(sys.argv)
QCoreApplication.setApplicationName("Inventory Wars")
database = QSqlDatabase.addDatabase("QSQLITE")
if not database.isValid():
logger.error("Failed to load SQLITE drivers")
sys.exit(1)
database.setDatabaseName("/home/dizzynight/Code/Python/inventory-wars/app.db")
if not database.open():
logger.error("Failed to open the sqlite database")
sys.exit(1)
engine = QQmlApplicationEngine() engine = QQmlApplicationEngine()
engine.addImportPath(sys.path[1]) engine.addImportPath(sys.path[1])
engine.loadFromModule("InventoryWars", "Main") engine.loadFromModule("InventoryWars", "Main")
if not engine.rootObjects(): if not engine.rootObjects():
sys.exit(-1) sys.exit(-1)