Skip to content

Commit

Permalink
为更换生涯背景选项卡提供英雄选择器
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzaphkiel committed Jun 14, 2024
1 parent 0be192b commit 06684e8
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 241 deletions.
90 changes: 62 additions & 28 deletions app/components/multi_champion_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
from PyQt5.QtGui import QMouseEvent
from PyQt5.QtWidgets import (QVBoxLayout, QFrame, QHBoxLayout,
QLabel, QApplication, QWidget, QCompleter)
from app.common.qfluentwidgets import (TransparentToolButton, FluentIcon, ToolButton,
SearchLineEdit, FlowLayout, SmoothScrollArea,
FlyoutViewBase, TeachingTipView)


from app.common.qfluentwidgets import (TransparentToolButton, FluentIcon, ToolButton,
SearchLineEdit, FlowLayout, SmoothScrollArea)
from app.common.style_sheet import StyleSheet
from app.components.animation_frame import CardWidget
from app.components.champion_icon_widget import RoundIcon, RoundIconButton
Expand Down Expand Up @@ -67,7 +68,7 @@ def sizeHint(self):
return QSize(141, 44)


class ItemsDraggableLayout(QFrame):
class ItemsDraggableWidget(QFrame):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.items: List[ChampionTabItem] = []
Expand Down Expand Up @@ -231,44 +232,34 @@ def tabRect(self, index: int) -> QRect:
return rect


class MultiChampionSelectWidget(QWidget):
def __init__(self, champions: dict, selected: list, parent=None):
super().__init__(parent=parent)
class ChampionsSelectWidget(QWidget):
championClicked = pyqtSignal(int)

self.hBoxLayout = QHBoxLayout(self)
def __init__(self, champions: dict, parent: QWidget = None):
super().__init__(parent=parent)

self.itemsDraggableWidget = ItemsDraggableLayout()
self.championSelectLayout = QVBoxLayout()
self.champions = champions

self.searchLineEdit = SearchLineEdit()

self.vBoxLayout = QVBoxLayout(self)
self.scrollArea = SmoothScrollArea()
self.scrollWidget = QWidget()
self.championsShowLayout = FlowLayout(needAni=False)

self.champions: dict = champions
self.selected = selected

self.__initWidget()
self.__initLayout()

StyleSheet.CHAMPION_SELECT_WIDGET.apply(self)

def __initWidget(self):
self.scrollArea.setObjectName("scrollArea")
self.scrollWidget.setObjectName("scrollWidget")

for i, [name, icon] in self.champions.items():
button = RoundIconButton(icon, 38, 4, 2, name, i)
button.clicked.connect(self.__onChampionIconClicked)
button.clicked.connect(self.championClicked)

self.championsShowLayout.addWidget(button)

for id in self.selected:
name = connector.manager.getChampionNameById(id)
icon = self.champions[id][1]

self.itemsDraggableWidget.addItem(icon, name, id)

self.searchLineEdit.textChanged.connect(self.__onSearchLineTextChanged)

def __initLayout(self):
Expand All @@ -283,12 +274,9 @@ def __initLayout(self):

self.scrollArea.setFixedSize(330, 279)

self.championSelectLayout.setContentsMargins(0, 0, 0, 0)
self.championSelectLayout.addWidget(self.searchLineEdit)
self.championSelectLayout.addWidget(self.scrollArea)

self.hBoxLayout.addWidget(self.itemsDraggableWidget)
self.hBoxLayout.addLayout(self.championSelectLayout)
self.vBoxLayout.setContentsMargins(0, 0, 0, 0)
self.vBoxLayout.addWidget(self.searchLineEdit)
self.vBoxLayout.addWidget(self.scrollArea)

def __onSearchLineTextChanged(self, text: str):
for i in reversed(range(self.championsShowLayout.count())):
Expand All @@ -305,7 +293,7 @@ def __onSearchLineTextChanged(self, text: str):
icon = champion[1]

button = RoundIconButton(icon, 38, 4, 2, name, i)
button.clicked.connect(self.__onChampionIconClicked)
button.clicked.connect(self.championClicked)

self.championsShowLayout.addWidget(button)

Expand All @@ -318,6 +306,37 @@ def __getChampionIdsByAlias(self, alias):
return [id for id, [name, _] in self.champions.items()
if alias in name]


class MultiChampionSelectWidget(QWidget):
def __init__(self, champions: dict, selected: list, parent=None):
super().__init__(parent=parent)

self.hBoxLayout = QHBoxLayout(self)

self.itemsDraggableWidget = ItemsDraggableWidget()
self.championsSelectWidget = ChampionsSelectWidget(champions)
self.champions: dict = champions
self.selected = selected

self.__initWidget()
self.__initLayout()

StyleSheet.CHAMPION_SELECT_WIDGET.apply(self)

def __initWidget(self):
for id in self.selected:
name = connector.manager.getChampionNameById(id)
icon = self.champions[id][1]

self.itemsDraggableWidget.addItem(icon, name, id)

self.championsSelectWidget.championClicked.connect(
self.__onChampionIconClicked)

def __initLayout(self):
self.hBoxLayout.addWidget(self.itemsDraggableWidget)
self.hBoxLayout.addWidget(self.championsSelectWidget)

def __onChampionIconClicked(self, championId):
if self.itemsDraggableWidget.count() == 6:
return
Expand All @@ -330,3 +349,18 @@ def __onChampionIconClicked(self, championId):

def getSelectedChampionIds(self) -> list:
return self.itemsDraggableWidget.getCurrentChampionIds()


class ChampionSelectFlyout(FlyoutViewBase):
championSelected = pyqtSignal(int)

def __init__(self, champions: dict, parent=None):
super().__init__(parent)

self.vBoxLayout = QVBoxLayout(self)
self.selectWidget = ChampionsSelectWidget(champions)
self.selectWidget.championClicked.connect(self.championSelected)

self.vBoxLayout.addWidget(self.selectWidget)

StyleSheet.CHAMPION_SELECT_WIDGET.apply(self)
2 changes: 1 addition & 1 deletion app/lol/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ def getChampions(self):

def getSkinListByChampionName(self, championName):
try:
return [item for item in self.champions[championName]["skins"]]
return [item for item in self.champions[championName]["skins"].items()]
except:
return []

Expand Down
Binary file modified app/resource/i18n/Seraphine.zh_CN.qm
Binary file not shown.
Loading

0 comments on commit 06684e8

Please sign in to comment.