mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-04-11 05:30:17 +00:00
feat: PlayRatingCalculator
component
This commit is contained in:
parent
01457f3559
commit
b193b82d95
@ -694,57 +694,9 @@
|
||||
<property name="title">
|
||||
<string>playRatingCalculate</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="playRatingCalculateScoreLineEdit">
|
||||
<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>
|
||||
<widget class="PlayRatingCalculator" name="playRatingCalculator" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -764,6 +716,12 @@
|
||||
<header>ui.implements.components.ratingClassSelector</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>PlayRatingCalculator</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>ui.implements.components.playRatingCalculator</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
@ -16,9 +16,10 @@ from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
|
||||
QImage, QKeySequence, QLinearGradient, QPainter,
|
||||
QPalette, QPixmap, QRadialGradient, QTransform)
|
||||
from PySide6.QtWidgets import (QApplication, QComboBox, QFrame, QGridLayout,
|
||||
QGroupBox, QHBoxLayout, QLabel, QLineEdit,
|
||||
QSizePolicy, QSpacerItem, QVBoxLayout, QWidget)
|
||||
QGroupBox, QHBoxLayout, QLabel, QSizePolicy,
|
||||
QVBoxLayout, QWidget)
|
||||
|
||||
from ui.implements.components.playRatingCalculator import PlayRatingCalculator
|
||||
from ui.implements.components.ratingClassSelector import RatingClassSelector
|
||||
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.setObjectName(u"groupBox_6")
|
||||
self.horizontalLayout_5 = QHBoxLayout(self.groupBox_6)
|
||||
self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
|
||||
self.playRatingCalculateScoreLineEdit = QLineEdit(self.groupBox_6)
|
||||
self.playRatingCalculateScoreLineEdit.setObjectName(u"playRatingCalculateScoreLineEdit")
|
||||
self.playRatingCalculateScoreLineEdit.setMinimumSize(QSize(100, 0))
|
||||
self.playRatingCalculateScoreLineEdit.setMaximumSize(QSize(150, 16777215))
|
||||
self.playRatingCalculateScoreLineEdit.setInputMask(u"B9'999'999;_")
|
||||
self.verticalLayout_2 = QVBoxLayout(self.groupBox_6)
|
||||
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
|
||||
self.playRatingCalculator = PlayRatingCalculator(self.groupBox_6)
|
||||
self.playRatingCalculator.setObjectName(u"playRatingCalculator")
|
||||
|
||||
self.horizontalLayout_5.addWidget(self.playRatingCalculateScoreLineEdit)
|
||||
|
||||
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_2.addWidget(self.playRatingCalculator)
|
||||
|
||||
|
||||
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
|
||||
|
||||
from arcaea_offline.calculate import calculate_play_rating
|
||||
from arcaea_offline.database import Database
|
||||
from PySide6.QtCore import QDateTime
|
||||
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.updateChartInfoLabels)
|
||||
|
||||
self.songIdSelector.valueChanged.connect(
|
||||
self.updatePlayRatingCalculateResultLabel
|
||||
)
|
||||
self.ratingClassSelector.valueChanged.connect(
|
||||
self.updatePlayRatingCalculateResultLabel
|
||||
)
|
||||
self.playRatingCalculateScoreLineEdit.textChanged.connect(
|
||||
self.updatePlayRatingCalculateResultLabel
|
||||
)
|
||||
self.songIdSelector.valueChanged.connect(self.updatePlayRatingCalculator)
|
||||
self.ratingClassSelector.valueChanged.connect(self.updatePlayRatingCalculator)
|
||||
|
||||
self.langSelectComboBox.addItem("En - English [en]", "en")
|
||||
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 "-"
|
||||
)
|
||||
|
||||
def resetPlayRatingCalculateResultLabel(self):
|
||||
self.playRatingCalculateResultLabel.setText("...")
|
||||
|
||||
def updatePlayRatingCalculateResultLabel(self):
|
||||
def updatePlayRatingCalculator(self):
|
||||
songId = self.songIdSelector.songId()
|
||||
ratingClass = self.ratingClassSelector.value()
|
||||
|
||||
if not songId or ratingClass is None:
|
||||
self.resetPlayRatingCalculateResultLabel()
|
||||
return
|
||||
|
||||
chartInfo = self.db.get_chart_info(songId, ratingClass)
|
||||
|
||||
if not chartInfo or not chartInfo.constant:
|
||||
self.resetPlayRatingCalculateResultLabel()
|
||||
return
|
||||
|
||||
if scoreText := self.playRatingCalculateScoreLineEdit.text().replace("'", ""):
|
||||
score = int(scoreText)
|
||||
|
||||
self.playRatingCalculateResultLabel.setText(
|
||||
f"{calculate_play_rating(chartInfo.constant, score):.3f}"
|
||||
)
|
||||
if not chartInfo:
|
||||
self.playRatingCalculator.setConstant(None)
|
||||
else:
|
||||
self.resetPlayRatingCalculateResultLabel()
|
||||
return
|
||||
self.playRatingCalculator.setConstant(chartInfo.constant)
|
||||
|
Loading…
x
Reference in New Issue
Block a user