mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-07-01 04:16:26 +00:00
wip: arcaea-offline==0.2.0
- fix imports
This commit is contained in:
@ -1,10 +1,11 @@
|
||||
import re
|
||||
from typing import Literal
|
||||
|
||||
from arcaea_offline.database import Database
|
||||
from arcaea_offline.models import Chart, Package
|
||||
from arcaea_offline.utils import rating_class_to_text
|
||||
from arcaea_offline.models import Chart, Pack
|
||||
from arcaea_offline.utils.rating import rating_class_to_text
|
||||
from PySide6.QtCore import QModelIndex, Qt, Signal, Slot
|
||||
from PySide6.QtGui import QColor
|
||||
from PySide6.QtGui import QColor, QShowEvent
|
||||
from PySide6.QtWidgets import QCompleter, QWidget
|
||||
|
||||
from ui.designer.components.chartSelector_ui import Ui_ChartSelector
|
||||
@ -19,7 +20,6 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.db = Database()
|
||||
self.db.register_update_hook(self.fillPackageComboBox)
|
||||
self.setupUi(self)
|
||||
|
||||
self.pstButton.setColors(QColor("#399bb2"), QColor("#f0f8fa"))
|
||||
@ -107,19 +107,28 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
ratingClass = self.selectedRatingClass()
|
||||
|
||||
if packageId and songId and isinstance(ratingClass, int):
|
||||
return Chart.from_db_row(self.db.get_chart(songId, ratingClass))
|
||||
return self.db.get_chart(songId, ratingClass)
|
||||
return None
|
||||
|
||||
def showEvent(self, event: QShowEvent):
|
||||
# update database results when widget visible
|
||||
self.fillPackageComboBox()
|
||||
return super().showEvent(event)
|
||||
|
||||
@Slot()
|
||||
def updateResultLabel(self):
|
||||
chart = self.value()
|
||||
if isinstance(chart, Chart):
|
||||
package = Package.from_db_row(
|
||||
self.db.get_package_by_package_id(chart.package_id)
|
||||
)
|
||||
pack = self.db.get_pack_by_id(chart.set)
|
||||
texts = [
|
||||
[package.name, chart.name_en, rating_class_to_text(chart.rating_class)],
|
||||
[package.id, chart.song_id, str(chart.rating_class)],
|
||||
[
|
||||
pack.name,
|
||||
chart.title,
|
||||
f"{rating_class_to_text(chart.rating_class)} "
|
||||
f"{chart.rating}{'+' if chart.rating_plus else ''}"
|
||||
f"({chart.constant / 10})",
|
||||
],
|
||||
[pack.id, chart.song_id, str(chart.rating_class)],
|
||||
]
|
||||
texts = [" | ".join(t) for t in texts]
|
||||
text = f'{texts[0]}<br><font color="gray">{texts[1]}</font>'
|
||||
@ -129,37 +138,41 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
|
||||
def fillPackageComboBox(self):
|
||||
self.packageComboBox.clear()
|
||||
packages = [Package.from_db_row(dbRow) for dbRow in self.db.get_packages()]
|
||||
for package in packages:
|
||||
self.packageComboBox.addItem(f"{package.name} ({package.id})", package.id)
|
||||
packs = self.db.get_packs()
|
||||
for pack in packs:
|
||||
isAppendPack = re.search(r"_append_.*$", pack.id)
|
||||
if isAppendPack:
|
||||
basePackId = re.sub(r"_append_.*$", "", pack.id)
|
||||
basePackName = self.db.get_pack_by_id(basePackId).name
|
||||
packName = f"{basePackName} - {pack.name}"
|
||||
else:
|
||||
packName = pack.name
|
||||
self.packageComboBox.addItem(f"{packName} ({pack.id})", pack.id)
|
||||
row = self.packageComboBox.count() - 1
|
||||
self.packageComboBox.setItemData(
|
||||
row, package.name, DescriptionDelegate.MainTextRole
|
||||
row, packName, DescriptionDelegate.MainTextRole
|
||||
)
|
||||
self.packageComboBox.setItemData(
|
||||
row, package.id, DescriptionDelegate.DescriptionTextRole
|
||||
row, pack.id, DescriptionDelegate.DescriptionTextRole
|
||||
)
|
||||
|
||||
self.packageComboBox.setCurrentIndex(-1)
|
||||
|
||||
def fillSongIdComboBox(self):
|
||||
self.songIdComboBox.clear()
|
||||
packageId = self.packageComboBox.currentData()
|
||||
if packageId:
|
||||
charts = [
|
||||
Chart.from_db_row(dbRow)
|
||||
for dbRow in self.db.get_charts_by_package_id(packageId)
|
||||
]
|
||||
packId = self.packageComboBox.currentData()
|
||||
if packId:
|
||||
charts = self.db.get_charts_by_pack_id(packId)
|
||||
inserted_song_ids = []
|
||||
for chart in charts:
|
||||
if chart.song_id not in inserted_song_ids:
|
||||
self.songIdComboBox.addItem(
|
||||
f"{chart.name_en} ({chart.song_id})", chart.song_id
|
||||
f"{chart.title} ({chart.song_id})", chart.song_id
|
||||
)
|
||||
inserted_song_ids.append(chart.song_id)
|
||||
row = self.songIdComboBox.count() - 1
|
||||
self.songIdComboBox.setItemData(
|
||||
row, chart.name_en, DescriptionDelegate.MainTextRole
|
||||
row, chart.title, DescriptionDelegate.MainTextRole
|
||||
)
|
||||
self.songIdComboBox.setItemData(
|
||||
row, chart.song_id, DescriptionDelegate.DescriptionTextRole
|
||||
@ -174,12 +187,7 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
def on_songIdComboBox_currentIndexChanged(self, index: int):
|
||||
rating_classes = []
|
||||
if index > -1:
|
||||
charts = [
|
||||
Chart.from_db_row(dbRow)
|
||||
for dbRow in self.db.get_charts_by_song_id(
|
||||
self.songIdComboBox.currentData()
|
||||
)
|
||||
]
|
||||
charts = self.db.get_charts_by_song_id(self.songIdComboBox.currentData())
|
||||
rating_classes = [chart.rating_class for chart in charts]
|
||||
self.updateRatingClassButtonsEnabled(rating_classes)
|
||||
|
||||
@ -196,7 +204,7 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
self.fuzzySearchCompleterModel.clear()
|
||||
|
||||
def selectChart(self, chart: Chart):
|
||||
packageIdIndex = self.packageComboBox.findData(chart.package_id)
|
||||
packageIdIndex = self.packageComboBox.findData(chart.set)
|
||||
if packageIdIndex > -1:
|
||||
self.packageComboBox.setCurrentIndex(packageIdIndex)
|
||||
else:
|
||||
|
@ -2,7 +2,7 @@ from enum import IntEnum
|
||||
from typing import Optional
|
||||
|
||||
from arcaea_offline.calculate import calculate_score_range
|
||||
from arcaea_offline.models import Chart, Score, ScoreInsert
|
||||
from arcaea_offline.models import Chart, Score
|
||||
from PySide6.QtCore import QCoreApplication, QDateTime, Signal, Slot
|
||||
from PySide6.QtWidgets import QMessageBox, QWidget
|
||||
|
||||
@ -37,9 +37,9 @@ class ScoreEditor(Ui_ScoreEditor, QWidget):
|
||||
self.valueChanged.connect(self.validateScore)
|
||||
self.valueChanged.connect(self.updateValidateLabel)
|
||||
|
||||
self.clearTypeComboBox.addItem("HARD LOST", -1)
|
||||
self.clearTypeComboBox.addItem("TRACK LOST", 0)
|
||||
self.clearTypeComboBox.addItem("TRACK COMPLETE", 1)
|
||||
self.clearTypeComboBox.addItem("HARD LOST", 2)
|
||||
self.clearTypeComboBox.setCurrentIndex(-1)
|
||||
|
||||
def setValidateBeforeAccept(self, __bool: bool):
|
||||
@ -159,33 +159,33 @@ class ScoreEditor(Ui_ScoreEditor, QWidget):
|
||||
|
||||
def value(self):
|
||||
if isinstance(self.__chart, Chart):
|
||||
return ScoreInsert(
|
||||
return Score(
|
||||
song_id=self.__chart.song_id,
|
||||
rating_class=self.__chart.rating_class,
|
||||
score=self.score(),
|
||||
pure=self.pureSpinBox.value(),
|
||||
far=self.farSpinBox.value(),
|
||||
lost=self.lostSpinBox.value(),
|
||||
time=self.dateTimeEdit.dateTime().toSecsSinceEpoch(),
|
||||
date=self.dateTimeEdit.dateTime().toSecsSinceEpoch(),
|
||||
max_recall=self.maxRecallSpinBox.value()
|
||||
if self.maxRecallSpinBox.value() > -1
|
||||
else None,
|
||||
clear_type=None,
|
||||
r10_clear_type=None,
|
||||
)
|
||||
|
||||
def setValue(self, score: Score | ScoreInsert):
|
||||
if isinstance(score, (Score, ScoreInsert)):
|
||||
def setValue(self, score: Score):
|
||||
if isinstance(score, Score):
|
||||
scoreText = str(score.score)
|
||||
scoreText = scoreText.rjust(8, "0")
|
||||
self.scoreLineEdit.setText(scoreText)
|
||||
self.pureSpinBox.setValue(score.pure)
|
||||
self.farSpinBox.setValue(score.far)
|
||||
self.lostSpinBox.setValue(score.lost)
|
||||
self.dateTimeEdit.setDateTime(QDateTime.fromSecsSinceEpoch(score.time))
|
||||
self.dateTimeEdit.setDateTime(QDateTime.fromSecsSinceEpoch(score.date))
|
||||
if score.max_recall is not None:
|
||||
self.maxRecallSpinBox.setValue(score.max_recall)
|
||||
if score.clear_type is not None:
|
||||
self.clearTypeComboBox.setCurrentIndex(score.clear_type)
|
||||
if score.r10_clear_type is not None:
|
||||
self.clearTypeComboBox.setCurrentIndex(score.r10_clear_type)
|
||||
|
||||
def reset(self):
|
||||
self.setChart(None)
|
||||
|
Reference in New Issue
Block a user