Skip to content

Commit

Permalink
1. 在选择生涯背景时提供预览
Browse files Browse the repository at this point in the history
2. 在选择生涯背景时, 可以将原画保存到本地
  • Loading branch information
Hpero4 committed Aug 3, 2024
1 parent 5c8829d commit b850f38
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 23 deletions.
3 changes: 2 additions & 1 deletion app/components/champion_icon_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ def mousePressEvent(self, a0: QMouseEvent) -> None:
def mouseReleaseEvent(self, a0: QMouseEvent) -> None:
self.isPressed = False
self.update()
ret = super().mouseReleaseEvent(a0)
self.clicked.emit(self.championId)
return super().mouseReleaseEvent(a0)
return ret


class RoundedLabel(QLabel):
Expand Down
66 changes: 62 additions & 4 deletions app/components/message_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import webbrowser
import py7zr

from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtWidgets import QPushButton, QVBoxLayout, QWidget
from PyQt5.QtCore import Qt, pyqtSignal, QUrl
from PyQt5.QtWidgets import QPushButton, QVBoxLayout, QWidget, QLabel, QFileDialog
from PyQt5.QtGui import QFont, QPixmap

from app.common.qfluentwidgets import (MessageBoxBase, SmoothScrollArea,
BodyLabel, TextEdit, TitleLabel,
ProgressBar,
PrimaryPushButton, ComboBox)
PrimaryPushButton, ComboBox, PipsScrollButtonDisplayMode, HorizontalPipsPager)

from app.common.config import VERSION, cfg, LOCAL_PATH, BETA
from app.common.util import getLolClientPidSlowly
Expand Down Expand Up @@ -390,7 +392,7 @@ def __init__(self, paths: list, parent=None):
self.myYesButton = PrimaryPushButton(self.tr('OK'), self.buttonGroup)
self.myCancelButton = QPushButton(self.tr('Cancel'), self.buttonGroup)

self.titleLabel = TitleLabel(self.tr("Set LOL cLient path"))
self.titleLabel = TitleLabel(self.tr("Set LOL Client path"))
self.pathsWidget = PathDraggableWidget(paths)

self.__initWidget()
Expand Down Expand Up @@ -425,6 +427,62 @@ def __myOnCancelButtonClicked(self):
self.rejected.emit()


class SplashesMessageBox(MessageBoxBase):
def __init__(self, skinList, parent=None):
super().__init__(parent)

self.skinList = skinList

self.splashesImg = QLabel(self)
self.splashesNameLabel = QLabel(self)
self.splashesNameLabel.setFont(QFont('Microsoft YaHei', 13))
self.pager = HorizontalPipsPager(self)
self.pager.setPreviousButtonDisplayMode(PipsScrollButtonDisplayMode.ALWAYS)
self.pager.setNextButtonDisplayMode(PipsScrollButtonDisplayMode.ALWAYS)
self.pager.setPageNumber(len(skinList))

self.saveButton = QPushButton(self.tr('Save'), self.buttonGroup)
self.saveButton.setObjectName('cancelButton') # TODO own style

self.viewLayout.addWidget(self.splashesImg, 0, Qt.AlignCenter)
self.viewLayout.addWidget(self.splashesNameLabel, 0, Qt.AlignCenter)
self.viewLayout.addWidget(self.pager, 0, Qt.AlignCenter)

self.buttonLayout.removeWidget(self.cancelButton)
self.buttonLayout.addWidget(self.saveButton, 1, Qt.AlignVCenter)
self.buttonLayout.addWidget(self.cancelButton, 1, Qt.AlignVCenter)

self.pager.currentIndexChanged.connect(self.__onChangeSplashes)
self.saveButton.clicked.connect(self.__onSaveSplashes)

self.pager.setCurrentIndex(0)

@asyncSlot(int)
async def __onChangeSplashes(self, idx):
skinItem = self.skinList[idx]
self.splashesNameLabel.setText(skinItem[0])

url = await connector.getChampionSplashes(skinItem[1], False)
img = QPixmap(url).scaled(1020, 565)
self.splashesImg.setPixmap(img)

@asyncSlot()
async def __onSaveSplashes(self):
saveTarget = QFileDialog.getSaveFileUrl(
self,
self.tr("Choose Path"),
QUrl(""),
"JPG Files (*.jpg *.jpeg)"
)

if not saveTarget[0].toLocalFile():
return

skinItem = self.skinList[self.pager.currentIndex()]
imgUrl = await connector.getChampionSplashes(skinItem[1], False)
shutil.copy(imgUrl, saveTarget[0].toLocalFile())


class ChangeDpiMessageBox(MessageBoxBase):
def __init__(self, parent=None):
super().__init__(parent=parent)
Expand Down
48 changes: 45 additions & 3 deletions app/lol/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def __initFolder(self):
"rune icons",
"summoner spell icons",
"augment icons"
"splashes",
]:
p = f"app/resource/game/{folder}"
if not os.path.exists(p):
Expand Down Expand Up @@ -489,6 +490,39 @@ async def getAugmentIcon(self, augmentId):

return icon

@retry()
async def getChampionSplashes(self, skinInfo, isCentered: bool):
"""
:param skinInfo:
{
'skinId': 9000,
'splashPath': '/lol-game-data/.../xxxx.jpg',
'uncenteredSplashPath': '/lol-game-data/.../xxxx.jpg'
}
:param isCentered: True or False, 表示是否居中
注, splashPath获取到的原画是居中的;
如果你希望获取居中原画(如BP或生涯中看到的样式), 请使用'splashPath'
反之, 'uncenteredSplashPath'获取到的原画则是非居中的;
"""
splashesId = skinInfo["skinId"]

if isCentered:
image = f"app/resource/game/splashes/{splashesId}_centered.jpg"
url = skinInfo["splashPath"]
else:
image = f"app/resource/game/splashes/{splashesId}_uncentered.jpg"
url = skinInfo["uncenteredSplashPath"]

if not os.path.exists(image):
res = await self.__get(url)

with open(image, "wb") as f:
f.write(await res.read())

return image

@retry()
async def getSummonerSpellIcon(self, spellId):
icon = f"app/resource/game/summoner spell icons/{spellId}.png"
Expand Down Expand Up @@ -1139,14 +1173,22 @@ def __init__(self, itemData, spellData, runeData, queueData, champions, skins, p

if 'questSkinInfo' in item:
for tier in item['questSkinInfo']['tiers']:
champion["skins"][tier["name"]] = tier["id"]
champion["skins"][tier["name"]] = {
"skinId": tier["id"],
'splashPath': tier['splashPath'],
'uncenteredSplashPath': tier['uncenteredSplashPath']
}
champion["id"] = championId

if 'skinAugments' in tier and 'augments' in tier['skinAugments']:
contentId = tier['skinAugments']['augments'][0]['contentId']
self.skinAugments[tier['id']] = contentId
else:
champion["skins"][item["name"]] = item["id"]
champion["skins"][item["name"]] = {
"skinId": item["id"],
'splashPath': item['splashPath'],
'uncenteredSplashPath': item['uncenteredSplashPath']
}
champion["id"] = championId

if 'skinAugments' in item and 'augments' in item['skinAugments']:
Expand Down Expand Up @@ -1256,7 +1298,7 @@ def getSkinListByChampionName(self, championName):
return []

def getSkinIdByChampionAndSkinName(self, championName, skinName):
return self.champions[championName]["skins"][skinName]
return self.champions[championName]["skins"][skinName]["skinId"]

def getChampionIdByName(self, championName):
return self.champions[championName]["id"]
Expand Down
49 changes: 34 additions & 15 deletions app/view/auxiliary_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from qasync import asyncSlot

from app.components.seraphine_interface import SeraphineInterface
from app.components.message_box import MultiChampionSelectMsgBox
from app.components.message_box import MultiChampionSelectMsgBox, SplashesMessageBox
from app.components.champion_icon_widget import RoundIcon
from app.components.multi_champion_select import ChampionSelectFlyout
from app.lol.tools import fixLCUWindowViaExe
Expand Down Expand Up @@ -260,14 +260,17 @@ def __init__(self, title, content, parent):
self.championButton = PushButton(self.tr("Select champion"), self)

self.skinLabel = QLabel(self.tr("Skin's name: "))
self.skinComboBox = ComboBox()
self.skinButton = PushButton(self.tr("Select Skin"), self)

self.buttonWidget = QWidget(self.view)
self.buttonLayout = QHBoxLayout(self.buttonWidget)
self.pushButton = PushButton(self.tr("Apply"))

self.completer = None

self.chosenSkinId = None
self.skins = None

self.__initLayout()
self.__initWidget()

Expand All @@ -284,7 +287,7 @@ def __initLayout(self):
self.inputLayout.addWidget(
self.skinLabel, 1, 0, alignment=Qt.AlignLeft)
self.inputLayout.addWidget(
self.skinComboBox, 1, 1, alignment=Qt.AlignRight)
self.skinButton, 1, 1, alignment=Qt.AlignRight)

self.inputLayout.setSizeConstraint(QHBoxLayout.SetMinimumSize)

Expand All @@ -301,13 +304,14 @@ def __initWidget(self):
self.championButton.setMinimumWidth(100)
self.championButton.clicked.connect(self.__onSelectButtonClicked)

self.skinButton.setMinimumWidth(100)
self.skinButton.setEnabled(False)
self.skinButton.clicked.connect(self.__onSkinButtonClicked)

self.pushButton.setMinimumWidth(100)
self.pushButton.setEnabled(False)
self.pushButton.clicked.connect(self.__onApplyButtonClicked)

self.skinComboBox.setEnabled(False)
self.skinComboBox.setMinimumWidth(250)
self.skinComboBox.setPlaceholderText(self.tr("Please select skin"))

def __onSelectButtonClicked(self):
view = ChampionSelectFlyout(self.champions)
Expand All @@ -316,6 +320,13 @@ def __onSelectButtonClicked(self):

view.championSelected.connect(self.__onChampionSelected)


def __onSkinButtonClicked(self):
w = SplashesMessageBox(self.skins, self.window())
if w.exec():
self.chosenSkinId = self.skins[w.pager.currentIndex()][1]["skinId"]
self.skinLabel.setText(self.tr("Skin's name: ") + self.skins[w.pager.currentIndex()][0])

async def initChampionList(self, champions: dict = None):
if champions:
self.champions = champions
Expand All @@ -330,27 +341,31 @@ async def initChampionList(self, champions: dict = None):

def __onChampionSelected(self, championId):
self.w.fadeOut()
self.skinComboBox.clear()
self.championLabel.setText(self.tr("Champion's name: ") + connector.manager.getChampionNameById(championId))
self.skinLabel.setText(self.tr("Skin's name: "))
self.chosenSkinId = None

name = self.champions[championId][0]
skins = connector.manager.getSkinListByChampionName(name)
self.skins = connector.manager.getSkinListByChampionName(name)

for skin in skins:
self.skinComboBox.addItem(skin[0], userData=skin[1])
self.skinButton.clicked.emit()

self.skinComboBox.setEnabled(True)
self.skinButton.setEnabled(True)
self.pushButton.setEnabled(True)

@asyncSlot()
async def __onApplyButtonClicked(self):
skinId = self.skinComboBox.currentData()
contentId = connector.manager.getSkinAugments(skinId)
contentId = connector.manager.getSkinAugments(self.chosenSkinId)

if contentId == None:
await connector.setProfileBackground(skinId)
await connector.setProfileBackground(self.chosenSkinId)
InfoBar.success(title=self.tr("Apply"), content=self.tr("Successfully"), orient=Qt.Vertical,
isClosable=True,
position=InfoBarPosition.TOP_RIGHT, duration=5000,
parent=self.window().auxiliaryFuncInterface)
return

self.skinId = skinId
self.skinId = self.chosenSkinId
self.contentId = contentId

msg = MessageBox(
Expand All @@ -366,6 +381,10 @@ async def __onApplyButtonClicked(self):

msg.exec_()

InfoBar.success(title=self.tr("Apply"), content=self.tr("Successfully"), orient=Qt.Vertical, isClosable=True,
position=InfoBarPosition.TOP_RIGHT, duration=5000,
parent=self.window().auxiliaryFuncInterface)

@asyncSlot()
async def __onMsgBoxYesButtonClicked(self):
await connector.setProfileBackground(self.skinId)
Expand Down

0 comments on commit b850f38

Please sign in to comment.