mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-04-21 18:20:18 +00:00
feat: PlayRatingCalculator
component
This commit is contained in:
parent
01457f3559
commit
b193b82d95
@ -694,57 +694,9 @@
|
|||||||
<property name="title">
|
<property name="title">
|
||||||
<string>playRatingCalculate</string>
|
<string>playRatingCalculate</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="playRatingCalculateScoreLineEdit">
|
<widget class="PlayRatingCalculator" name="playRatingCalculator" native="true"/>
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>100</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>150</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="inputMask">
|
|
||||||
<string notr="true">B9'999'999;_</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">></string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="playRatingCalculateResultLabel">
|
|
||||||
<property name="font">
|
|
||||||
<font>
|
|
||||||
<bold>true</bold>
|
|
||||||
</font>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -764,6 +716,12 @@
|
|||||||
<header>ui.implements.components.ratingClassSelector</header>
|
<header>ui.implements.components.ratingClassSelector</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>PlayRatingCalculator</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>ui.implements.components.playRatingCalculator</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
@ -16,9 +16,10 @@ from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
|
|||||||
QImage, QKeySequence, QLinearGradient, QPainter,
|
QImage, QKeySequence, QLinearGradient, QPainter,
|
||||||
QPalette, QPixmap, QRadialGradient, QTransform)
|
QPalette, QPixmap, QRadialGradient, QTransform)
|
||||||
from PySide6.QtWidgets import (QApplication, QComboBox, QFrame, QGridLayout,
|
from PySide6.QtWidgets import (QApplication, QComboBox, QFrame, QGridLayout,
|
||||||
QGroupBox, QHBoxLayout, QLabel, QLineEdit,
|
QGroupBox, QHBoxLayout, QLabel, QSizePolicy,
|
||||||
QSizePolicy, QSpacerItem, QVBoxLayout, QWidget)
|
QVBoxLayout, QWidget)
|
||||||
|
|
||||||
|
from ui.implements.components.playRatingCalculator import PlayRatingCalculator
|
||||||
from ui.implements.components.ratingClassSelector import RatingClassSelector
|
from ui.implements.components.ratingClassSelector import RatingClassSelector
|
||||||
from ui.implements.components.songIdSelector import SongIdSelector
|
from ui.implements.components.songIdSelector import SongIdSelector
|
||||||
|
|
||||||
@ -502,34 +503,12 @@ class Ui_TabTools_InfoLookup(object):
|
|||||||
|
|
||||||
self.groupBox_6 = QGroupBox(TabTools_InfoLookup)
|
self.groupBox_6 = QGroupBox(TabTools_InfoLookup)
|
||||||
self.groupBox_6.setObjectName(u"groupBox_6")
|
self.groupBox_6.setObjectName(u"groupBox_6")
|
||||||
self.horizontalLayout_5 = QHBoxLayout(self.groupBox_6)
|
self.verticalLayout_2 = QVBoxLayout(self.groupBox_6)
|
||||||
self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
|
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
|
||||||
self.playRatingCalculateScoreLineEdit = QLineEdit(self.groupBox_6)
|
self.playRatingCalculator = PlayRatingCalculator(self.groupBox_6)
|
||||||
self.playRatingCalculateScoreLineEdit.setObjectName(u"playRatingCalculateScoreLineEdit")
|
self.playRatingCalculator.setObjectName(u"playRatingCalculator")
|
||||||
self.playRatingCalculateScoreLineEdit.setMinimumSize(QSize(100, 0))
|
|
||||||
self.playRatingCalculateScoreLineEdit.setMaximumSize(QSize(150, 16777215))
|
|
||||||
self.playRatingCalculateScoreLineEdit.setInputMask(u"B9'999'999;_")
|
|
||||||
|
|
||||||
self.horizontalLayout_5.addWidget(self.playRatingCalculateScoreLineEdit)
|
self.verticalLayout_2.addWidget(self.playRatingCalculator)
|
||||||
|
|
||||||
self.label = QLabel(self.groupBox_6)
|
|
||||||
self.label.setObjectName(u"label")
|
|
||||||
self.label.setText(u">")
|
|
||||||
|
|
||||||
self.horizontalLayout_5.addWidget(self.label)
|
|
||||||
|
|
||||||
self.playRatingCalculateResultLabel = QLabel(self.groupBox_6)
|
|
||||||
self.playRatingCalculateResultLabel.setObjectName(u"playRatingCalculateResultLabel")
|
|
||||||
font = QFont()
|
|
||||||
font.setBold(True)
|
|
||||||
self.playRatingCalculateResultLabel.setFont(font)
|
|
||||||
self.playRatingCalculateResultLabel.setText(u"...")
|
|
||||||
|
|
||||||
self.horizontalLayout_5.addWidget(self.playRatingCalculateResultLabel)
|
|
||||||
|
|
||||||
self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
||||||
|
|
||||||
self.horizontalLayout_5.addItem(self.horizontalSpacer)
|
|
||||||
|
|
||||||
|
|
||||||
self.verticalLayout.addWidget(self.groupBox_6)
|
self.verticalLayout.addWidget(self.groupBox_6)
|
||||||
|
23
ui/implements/components/arcaeaScoreLineEdit.py
Normal file
23
ui/implements/components/arcaeaScoreLineEdit.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from PySide6.QtGui import QFont
|
||||||
|
|
||||||
|
from .focusSelectAllLineEdit import FocusSelectAllLineEdit
|
||||||
|
|
||||||
|
|
||||||
|
class ArcaeaScoreLineEdit(FocusSelectAllLineEdit):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
|
||||||
|
font = QFont("GeosansLight")
|
||||||
|
font.setPointSize(14)
|
||||||
|
font.setBold(True)
|
||||||
|
font.setStyleStrategy(
|
||||||
|
QFont.StyleStrategy.NoSubpixelAntialias
|
||||||
|
| QFont.StyleStrategy.PreferAntialias
|
||||||
|
)
|
||||||
|
self.setFont(font)
|
||||||
|
|
||||||
|
self.setInputMask("B9'999'999;_")
|
||||||
|
|
||||||
|
def score(self) -> int | None:
|
||||||
|
textWithoutMask = self.text().replace("'", "")
|
||||||
|
return int(textWithoutMask) if textWithoutMask else None
|
86
ui/implements/components/playRatingCalculator.py
Normal file
86
ui/implements/components/playRatingCalculator.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
from arcaea_offline.calculate import calculate_play_rating
|
||||||
|
from PySide6.QtCore import QCoreApplication
|
||||||
|
from PySide6.QtGui import QGuiApplication
|
||||||
|
from PySide6.QtWidgets import (
|
||||||
|
QHBoxLayout,
|
||||||
|
QLabel,
|
||||||
|
QPushButton,
|
||||||
|
QSizePolicy,
|
||||||
|
QSpacerItem,
|
||||||
|
QWidget,
|
||||||
|
)
|
||||||
|
|
||||||
|
from ui.extends.shared.language import LanguageChangeEventFilter
|
||||||
|
|
||||||
|
from .arcaeaScoreLineEdit import ArcaeaScoreLineEdit
|
||||||
|
|
||||||
|
|
||||||
|
class PlayRatingCalculator(QWidget):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
|
||||||
|
self.languageChangeEventFilter = LanguageChangeEventFilter(self)
|
||||||
|
self.installEventFilter(self.languageChangeEventFilter)
|
||||||
|
|
||||||
|
self.setupUi()
|
||||||
|
|
||||||
|
self.arcaeaScoreLineEdit.textChanged.connect(self.updateResultLabel)
|
||||||
|
self.copyButton.clicked.connect(self.on_copyButton_clicked)
|
||||||
|
|
||||||
|
self.constant: int | None = None
|
||||||
|
|
||||||
|
def setConstant(self, constant: int | None):
|
||||||
|
self.constant = constant
|
||||||
|
self.updateResultLabel()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def result(self):
|
||||||
|
if self.constant is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
score = self.arcaeaScoreLineEdit.score()
|
||||||
|
if score is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return calculate_play_rating(self.constant, score)
|
||||||
|
|
||||||
|
def updateResultLabel(self):
|
||||||
|
result = self.result
|
||||||
|
self.resultLabel.setText(str(result) if result is not None else "...")
|
||||||
|
|
||||||
|
def on_copyButton_clicked(self):
|
||||||
|
result = self.result
|
||||||
|
if result is not None:
|
||||||
|
QGuiApplication.clipboard().setText(str(result))
|
||||||
|
|
||||||
|
def setupUi(self, *args):
|
||||||
|
self.horizontalLayout = QHBoxLayout(self)
|
||||||
|
|
||||||
|
self.arcaeaScoreLineEdit = ArcaeaScoreLineEdit(self)
|
||||||
|
self.horizontalLayout.addWidget(self.arcaeaScoreLineEdit)
|
||||||
|
|
||||||
|
self.label = QLabel(self)
|
||||||
|
self.label.setText(" > ")
|
||||||
|
self.horizontalLayout.addWidget(self.label)
|
||||||
|
|
||||||
|
self.resultLabel = QLabel(self)
|
||||||
|
self.resultLabel.setText("...")
|
||||||
|
self.resultLabel.setSizePolicy(
|
||||||
|
QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred
|
||||||
|
)
|
||||||
|
self.horizontalLayout.addWidget(self.resultLabel)
|
||||||
|
|
||||||
|
self.horizontalSpacer = QSpacerItem(
|
||||||
|
20, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred
|
||||||
|
)
|
||||||
|
self.horizontalLayout.addSpacerItem(self.horizontalSpacer)
|
||||||
|
|
||||||
|
self.copyButton = QPushButton(self)
|
||||||
|
self.horizontalLayout.addWidget(self.copyButton)
|
||||||
|
|
||||||
|
self.retranslateUi()
|
||||||
|
|
||||||
|
def retranslateUi(self, *args):
|
||||||
|
self.copyButton.setText(
|
||||||
|
QCoreApplication.translate("PotentialCalculator", "copyButton")
|
||||||
|
)
|
@ -1,6 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from arcaea_offline.calculate import calculate_play_rating
|
|
||||||
from arcaea_offline.database import Database
|
from arcaea_offline.database import Database
|
||||||
from PySide6.QtCore import QDateTime
|
from PySide6.QtCore import QDateTime
|
||||||
from PySide6.QtWidgets import QVBoxLayout, QWidget
|
from PySide6.QtWidgets import QVBoxLayout, QWidget
|
||||||
@ -27,15 +26,8 @@ class TabTools_InfoLookup(Ui_TabTools_InfoLookup, QWidget):
|
|||||||
self.ratingClassSelector.valueChanged.connect(self.updateDifficultyLabels)
|
self.ratingClassSelector.valueChanged.connect(self.updateDifficultyLabels)
|
||||||
self.ratingClassSelector.valueChanged.connect(self.updateChartInfoLabels)
|
self.ratingClassSelector.valueChanged.connect(self.updateChartInfoLabels)
|
||||||
|
|
||||||
self.songIdSelector.valueChanged.connect(
|
self.songIdSelector.valueChanged.connect(self.updatePlayRatingCalculator)
|
||||||
self.updatePlayRatingCalculateResultLabel
|
self.ratingClassSelector.valueChanged.connect(self.updatePlayRatingCalculator)
|
||||||
)
|
|
||||||
self.ratingClassSelector.valueChanged.connect(
|
|
||||||
self.updatePlayRatingCalculateResultLabel
|
|
||||||
)
|
|
||||||
self.playRatingCalculateScoreLineEdit.textChanged.connect(
|
|
||||||
self.updatePlayRatingCalculateResultLabel
|
|
||||||
)
|
|
||||||
|
|
||||||
self.langSelectComboBox.addItem("En - English [en]", "en")
|
self.langSelectComboBox.addItem("En - English [en]", "en")
|
||||||
self.langSelectComboBox.addItem("あ - Japanese [ja]", "ja")
|
self.langSelectComboBox.addItem("あ - Japanese [ja]", "ja")
|
||||||
@ -213,29 +205,12 @@ class TabTools_InfoLookup(Ui_TabTools_InfoLookup, QWidget):
|
|||||||
str(chartInfo.notes) if chartInfo.notes is not None else "-"
|
str(chartInfo.notes) if chartInfo.notes is not None else "-"
|
||||||
)
|
)
|
||||||
|
|
||||||
def resetPlayRatingCalculateResultLabel(self):
|
def updatePlayRatingCalculator(self):
|
||||||
self.playRatingCalculateResultLabel.setText("...")
|
|
||||||
|
|
||||||
def updatePlayRatingCalculateResultLabel(self):
|
|
||||||
songId = self.songIdSelector.songId()
|
songId = self.songIdSelector.songId()
|
||||||
ratingClass = self.ratingClassSelector.value()
|
ratingClass = self.ratingClassSelector.value()
|
||||||
|
|
||||||
if not songId or ratingClass is None:
|
|
||||||
self.resetPlayRatingCalculateResultLabel()
|
|
||||||
return
|
|
||||||
|
|
||||||
chartInfo = self.db.get_chart_info(songId, ratingClass)
|
chartInfo = self.db.get_chart_info(songId, ratingClass)
|
||||||
|
|
||||||
if not chartInfo or not chartInfo.constant:
|
if not chartInfo:
|
||||||
self.resetPlayRatingCalculateResultLabel()
|
self.playRatingCalculator.setConstant(None)
|
||||||
return
|
|
||||||
|
|
||||||
if scoreText := self.playRatingCalculateScoreLineEdit.text().replace("'", ""):
|
|
||||||
score = int(scoreText)
|
|
||||||
|
|
||||||
self.playRatingCalculateResultLabel.setText(
|
|
||||||
f"{calculate_play_rating(chartInfo.constant, score):.3f}"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self.resetPlayRatingCalculateResultLabel()
|
self.playRatingCalculator.setConstant(chartInfo.constant)
|
||||||
return
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user