Skip to content

Commit

Permalink
1. 战绩查询添加筛选功能
Browse files Browse the repository at this point in the history
2. 重构历史战绩拉取逻辑
  • Loading branch information
Hpero4 committed Sep 17, 2023
1 parent b9ad54c commit a8a898b
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 26 deletions.
92 changes: 92 additions & 0 deletions app/components/mode_filter_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import sys

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QApplication
from qfluentwidgets import CheckBox
from typing import List, Tuple


# TODO GameInfoInterface添加筛选功能

class ModeFilterWidget(QWidget):
def __init__(self, parent=None):
super().__init__(parent=parent)

self.selected: List[int] = []

self.hBoxLayout = QHBoxLayout(self)
self.hBoxLayout.setAlignment(Qt.AlignCenter)

# TODO 本地化
self.rankSoloCheckBox = CheckBox(self.tr("Rank solo"))
self.rankFlexCheckBox = CheckBox(self.tr("Rank Flex"))
self.normalCheckBox = CheckBox(self.tr("Normal"))
self.aramCheckBox = CheckBox(self.tr("Aram"))

self.checkBoxDict = {
self.rankSoloCheckBox: 420, # 单双排
self.rankFlexCheckBox: 440, # 灵活组排
self.normalCheckBox: 430, # 匹配模式
self.aramCheckBox: 450 # 大乱斗
}

for checkBox, num in self.checkBoxDict.items():
checkBox.stateChanged.connect(lambda state, num=num: self.updateSelected(state, num))

self.hBoxLayout.addWidget(self.rankSoloCheckBox, alignment=Qt.AlignCenter)
self.hBoxLayout.addWidget(self.rankFlexCheckBox, alignment=Qt.AlignCenter)
self.hBoxLayout.addWidget(self.normalCheckBox, alignment=Qt.AlignCenter)
self.hBoxLayout.addWidget(self.aramCheckBox, alignment=Qt.AlignCenter)

self.setLayout(self.hBoxLayout)

def updateSelected(self, state, num, callback=None):
if state == Qt.Checked:
if num not in self.selected:
self.selected.append(num)
else:
if num in self.selected:
self.selected.remove(num)

if callback:
callback()

def setCallback(self, func):
"""
@param func: check box状态改变时回调该方法
@return:
"""
for checkBox, num in self.checkBoxDict.items():
checkBox.stateChanged.connect(lambda state, num=num, func=func: self.updateSelected(state, num, func))

def getFilterMode(self) -> Tuple[int]:
"""
获取选中的模式
@return:
@rtype: Tuple[int]
"""
return set(self.selected)

def setCheckBoxState(self, data: tuple):
"""
设置复选框状态
@param data:
@return:
"""
for checkBox, num in self.checkBoxDict.items():
if num in data:
checkBox.setChecked(True)
else:
checkBox.setChecked(False)


if __name__ == '__main__':
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

app = QApplication(sys.argv)
w = ModeFilterWidget()
w.show()
app.exec_()
2 changes: 2 additions & 0 deletions app/lol/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def secsToStr(secs):


def processGameData(game):
timeStamp = game["gameCreation"]
time = timeStampToStr(game['gameCreation'])
shortTime = timeStampToShortStr(game['gameCreation'])
gameId = game['gameId']
Expand Down Expand Up @@ -111,6 +112,7 @@ def processGameData(game):
'runeIcon': runeIcon,
'cs': cs,
'gold': gold,
'timeStamp': timeStamp,
}


Expand Down
91 changes: 65 additions & 26 deletions app/view/search_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QPixmap
from qfluentwidgets import (SmoothScrollArea, LineEdit, PushButton, ToolButton, InfoBar,
InfoBarPosition, ToolTipFilter, ToolTipPosition, Theme, isDarkTheme, FlyoutViewBase, Flyout, CardWidget, IndeterminateProgressRing)
InfoBarPosition, ToolTipFilter, ToolTipPosition, Theme, isDarkTheme, FlyoutViewBase, Flyout,
CardWidget, IndeterminateProgressRing, FlyoutView, FlyoutAnimationType)

from ..common.style_sheet import StyleSheet
from ..common.icons import Icon
from ..common.config import cfg
from ..components.champion_icon_widget import RoundIcon
from ..components.mode_filter_widget import ModeFilterWidget
from ..components.summoner_name_button import SummonerName
from ..lol.connector import LolClientConnector, connector
from ..lol.tools import processGameData, processGameDetailData
Expand Down Expand Up @@ -41,6 +43,8 @@ def __init__(self, parnet=None):
self.puuid = None
self.games = []

self.begIndex = 0

self.triggerByButton = True

self.__initWidget()
Expand Down Expand Up @@ -103,6 +107,9 @@ def __onPrevButtonClicked(self):
self.prevButton.setEnabled(False)

def __onNextButtonClicked(self):
if self.currentIndex == 0:
self.begIndex = 0

self.currentIndex += 1

if len(self.stackWidget) <= self.currentIndex:
Expand Down Expand Up @@ -179,30 +186,34 @@ def updateTabs(self, begin, n):

def updateGames(self, page):
def _():
if self.maxPage != None:
self.gamesInfoReady.emit(page)
return

count = 10 * (page + 1) - len(self.games)

begin = len(self.games)
end = begin + count - 1

games = connector.getSummonerGamesByPuuid(
self.puuid, begin, end)

self.games += [processGameData(game)
for game in games["games"]]

if page == 1:
if len(games["games"]) <= 10:
self.maxPage = 1
else:
if len(games["games"]) < 10:
if len(games["games"]) == 0:
self.maxPage = page
else:
self.maxPage = page + 1
retry = 0
tmp_games_cnt = len(self.games)
endIndex = self.begIndex + 9
while True:
games = connector.getSummonerGamesByPuuid(
self.puuid, self.begIndex, endIndex)

for game in games["games"]:
if self.games:
# 避免重复添加
if game['gameCreation'] >= self.games[-1]["timeStamp"]:
continue

if game["queueId"] in self.window().searchInterface.filterData:
self.games += [processGameData(game)]

if len(self.games) - tmp_games_cnt >= 10:
self.maxPage = page + 1
self.games = self.games[:10 * self.maxPage]
break

if retry >= 5:
self.maxPage = page
break

self.begIndex = endIndex + 1
endIndex += 4
retry += 1

self.gamesInfoReady.emit(page)

Expand Down Expand Up @@ -304,7 +315,6 @@ def __initLayout(self):

def updateGame(self, game: dict):
isCherry = game["queueId"] == 1700

mapIcon = QPixmap(game["mapIcon"]).scaled(
54, 54, Qt.KeepAspectRatio, Qt.SmoothTransformation)
if game["remake"]:
Expand Down Expand Up @@ -920,12 +930,16 @@ class SearchInterface(SmoothScrollArea):
def __init__(self, parent=None):
super().__init__(parent)

self.filterData = (420, 440, 430, 450) # 默认全选

self.vBoxLayout = QVBoxLayout(self)

self.searchLayout = QHBoxLayout()
self.searchLineEdit = LineEdit()
self.searchButton = PushButton(self.tr("Search 🔍"))
self.careerButton = PushButton(self.tr("Career"))
self.filterButton = PushButton(self.tr("Filter"))
self.filterButton.clicked.connect(self.showFilterFlyout)

self.gamesView = GamesView()
self.currentSummonerName = None
Expand All @@ -950,6 +964,7 @@ def __initLayout(self):
self.searchLayout.addSpacing(5)
self.searchLayout.addWidget(self.searchButton)
self.searchLayout.addWidget(self.careerButton)
self.searchLayout.addWidget(self.filterButton)

self.vBoxLayout.addLayout(self.searchLayout)
self.vBoxLayout.addSpacing(5)
Expand Down Expand Up @@ -1008,3 +1023,27 @@ def setEnabled(self, a0: bool) -> None:
return super().setEnabled(a0)

# def clear(self):

def showFilterFlyout(self):
filterFlyout = FlyoutView("", "")

filterBoxGroup = ModeFilterWidget()
filterBoxGroup.setCheckBoxState(self.filterData)

def _():
# 将选中状态同步到 interface
self.filterData = filterBoxGroup.getFilterMode()
self.gamesView.gamesTab.currentIndex = 0
self.__onSearchButtonClicked()
filterBoxGroup.setCallback(_)

filterFlyout.widgetLayout.addWidget(filterBoxGroup, 0, Qt.AlignCenter)

filterFlyout.widgetLayout.setContentsMargins(1, 1, 1, 1)
filterFlyout.widgetLayout.setAlignment(Qt.AlignCenter)

filterFlyout.viewLayout.setSpacing(0)
filterFlyout.viewLayout.setContentsMargins(1, 1, 1, 1)

w = Flyout.make(filterFlyout, self.filterButton, self.window(), FlyoutAnimationType.DROP_DOWN)
filterFlyout.closed.connect(w.close)

0 comments on commit a8a898b

Please sign in to comment.