Skip to content

Commit

Permalink
Merge pull request #52 from Hpero4/main
Browse files Browse the repository at this point in the history
对局信息页面使用英雄头像而不是召唤师头像 (#41),设置部分选项卡添加应用后反馈
  • Loading branch information
Zzaphkiel authored Sep 16, 2023
2 parents 9b832c3 + 7fb8b99 commit 96ad4b6
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 13 deletions.
14 changes: 9 additions & 5 deletions app/components/profile_level_icon_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,17 @@ def paintEvent(self, event):
painter.setClipPath(clipPath)
painter.drawImage(self.sep // 2, self.sep // 2, scaledImage)

def updateIcon(self, icon, xpSinceLastLevel, xpUntilNextLevel, text=""):
def updateIcon(self, icon: str, xpSinceLastLevel=None, xpUntilNextLevel=None, text=""):
self.image = QImage(icon)
self.xpSinceLastLevel = xpSinceLastLevel
self.xpUntilNextLevel = xpUntilNextLevel
if xpSinceLastLevel is None and xpUntilNextLevel is not None:
self.xpSinceLastLevel = xpSinceLastLevel
self.xpUntilNextLevel = xpUntilNextLevel

self.setToolTip(f"Exp: {xpSinceLastLevel} / {xpUntilNextLevel}")

if text:
self.progressRing.text = text

self.setToolTip(f"Exp: {xpSinceLastLevel} / {xpUntilNextLevel}")
self.progressRing.text = text
self.repaint()


Expand Down
9 changes: 8 additions & 1 deletion app/lol/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,14 @@ def getSummonerSpellIcon(self, spellId):
return icon

@retry()
def getChampionIcon(self, championId):
def getChampionIcon(self, championId) -> str:
"""
@param championId:
@return: path
@rtype: str
"""

if championId == -1:
return "app/resource/images/champion-0.png"

Expand Down
8 changes: 8 additions & 0 deletions app/lol/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def run(self):
class LolClientEventListener(QThread):
currentSummonerProfileChanged = pyqtSignal(dict)
gameStatusChanged = pyqtSignal(str)
champSelectChanged = pyqtSignal(dict)

def __init__(self, parent) -> None:
super().__init__(parent)
Expand All @@ -64,6 +65,9 @@ async def onCurrentSummonerProfileChanged(data):
async def onGameFlowPhaseChanged(data):
self.gameStatusChanged.emit(data["data"])

async def onChampSelectChanged(data):
self.champSelectChanged.emit(data["data"])

async def defaultHandler(data):
print(data)

Expand All @@ -84,6 +88,10 @@ async def main():
wllp.subscription_filter_endpoint(
allEventSubscription, '/lol-gameflow/v1/gameflow-phase', onGameFlowPhaseChanged)

# 订阅英雄选择消息
wllp.subscription_filter_endpoint(
allEventSubscription, '/lol-champ-select/v1/session', onChampSelectChanged)

# print("[INFO] Event listener initialized.")
while True:
await asyncio.sleep(10)
Expand Down
28 changes: 25 additions & 3 deletions app/view/game_info_interface.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from PyQt5.QtCore import pyqtSignal, Qt
from typing import Dict

from PyQt5.QtCore import pyqtSignal, Qt, QPropertyAnimation, QRect
from PyQt5.QtWidgets import (QHBoxLayout, QLabel, QFrame, QVBoxLayout,
QSpacerItem, QSizePolicy, QStackedWidget,
QGridLayout, QSplitter)
from PyQt5.QtGui import QPixmap, QFont, QPainter, QColor, QPalette
QGridLayout, QSplitter, QApplication)
from PyQt5.QtGui import QPixmap, QFont, QPainter, QColor, QPalette, QImage

from qfluentwidgets import (SmoothScrollArea, TransparentTogglePushButton,
ToolTipFilter, ToolTipPosition)
Expand All @@ -21,14 +23,18 @@ class GameInfoInterface(SmoothScrollArea):
enemySummonerInfoReady = pyqtSignal(dict)
summonerViewClicked = pyqtSignal(str)
summonerGamesClicked = pyqtSignal(str)
pageSwitchSignal = pyqtSignal()
gameEnd = pyqtSignal()

def __init__(self, parent=None):
super().__init__(parent)
self.pageState = 1

self.hBoxLayout = QHBoxLayout(self)

self.summonersView = SummonersView()
self.summonersGamesView = QStackedWidget()
# TODO 动画 行为

self.allySummonerGamesView = SummonersGamesView()
self.enemySummonerGamesView = SummonersGamesView()
Expand Down Expand Up @@ -186,6 +192,7 @@ class TeamSummoners(QFrame):
def __init__(self, parent=None):
super().__init__(parent)

self.items: Dict[str, SummonerInfoView] = {}
self.vBoxLayout = QVBoxLayout(self)

self.__initLayout()
Expand All @@ -199,6 +206,7 @@ def updateSummoners(self, summoners):

for summoner in summoners:
summonerView = SummonerInfoView(summoner)
self.items[summoner["summonerId"]] = summonerView # 用 summonerId 避免空字符串
self.vBoxLayout.addWidget(summonerView, stretch=1)

if len(summoners) < 5:
Expand Down Expand Up @@ -396,6 +404,20 @@ def __setColor(self, teamId):
background-color: rgba({r1}, {g1}, {b1}, 0.2);
}}""")

def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
(self.parent().parent().parent().parent().parent().parent()
.parent().gameInfoInterface.pageSwitchSignal.emit())

def enterEvent(self, event):
QApplication.setOverrideCursor(Qt.PointingHandCursor)

def leaveEvent(self, event):
QApplication.restoreOverrideCursor()

def updateIcon(self, iconPath: str):
self.icon.updateIcon(iconPath)


class SummonersGamesView(QFrame):

Expand Down
41 changes: 37 additions & 4 deletions app/view/main_window.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import json
import os
import sys
import traceback
import time
from collections import Counter

from PyQt5.QtCore import Qt, pyqtSignal, QSize
from PyQt5.QtCore import Qt, pyqtSignal, QSize, QAbstractAnimation
from PyQt5.QtGui import QIcon, QImage, QCursor
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon
from qfluentwidgets import (NavigationItemPosition, InfoBar, InfoBarPosition, Action,
Expand Down Expand Up @@ -126,6 +127,10 @@ def __conncetSignalToSlot(self):
self.eventListener.gameStatusChanged.connect(
self.__onGameStatusChanged)

self.eventListener.champSelectChanged.connect(
self.__onChampSelectChanged
)

self.nameOrIconChanged.connect(self.__onNameOrIconChanged)
self.lolInstallFolderChanged.connect(self.__onLolInstallFolderChanged)

Expand All @@ -147,6 +152,8 @@ def __conncetSignalToSlot(self):
self.__onSearchInterfaceSummonerNameClicked)
self.gameInfoInterface.summonerGamesClicked.connect(
self.__onGameInfoInterfaceGamesSummonerNameClicked)
self.gameInfoInterface.pageSwitchSignal.connect(
self.__onGameInfoPageSwitch)
self.settingInterface.careerGamesCount.pushButton.clicked.connect(
self.__onCareerInterfaceRefreshButtonClicked)
self.settingInterface.micaCard.checkedChanged.connect(
Expand Down Expand Up @@ -493,6 +500,14 @@ def __onGameInfoInterfaceGamesSummonerNameClicked(self, name):

self.checkAndSwitchTo(self.searchInterface)

def __onGameInfoPageSwitch(self):
if self.gameInfoInterface.pageState == 1:
# TODO 动画 行为
self.gameInfoInterface.pageState = 2
else:
# TODO 动画 行为
self.gameInfoInterface.pageState = 1

def __onSearchInterfaceCareerButtonClicked(self):
self.careerInterface.showLoadingPage.emit()
name = self.searchInterface.currentSummonerName
Expand Down Expand Up @@ -687,6 +702,17 @@ def _():
if switch:
self.checkAndSwitchTo(self.careerInterface)

def __onChampSelectChanged(self, data):
# FIXME 可能存在调用频繁影响性能, 可以通过判断当前IconId来避免重复更新
for t in data["myTeam"]:
if t['championId']:
championIconPath = connector.getChampionIcon(t['championId'])

# 控件可能未绘制, 判断一下避免报错
summonersView = self.gameInfoInterface.summonersView.allySummoners.items.get(t["summonerId"])
if summonersView:
summonersView.updateIcon(championIconPath)

def __onGameStatusChanged(self, status):
title = None
isGaming = False
Expand Down Expand Up @@ -870,15 +896,22 @@ def _():

def process_item(item):
# 跟 __onChampionSelectBegin 函数里面的处理方法一样,这里使用 puuid
puuid = item["puuid"]
puuid = item.get("puuid")

# AI是没有该字段的, 避免报错
if not puuid:
return None

if puuid == '00000000-0000-0000-0000-000000000000':
return None

summoner = connector.getSummonerByPuuid(puuid)

iconId = summoner["profileIconId"]
icon = connector.getProfileIcon(iconId)
# iconId = summoner["profileIconId"]
# icon = connector.getProfileIcon(iconId)

iconId = item["championId"]
icon = connector.getChampionIcon(iconId)

origRankInfo = connector.getRankedStatsByPuuid(puuid)
rankInfo = processRankInfo(origRankInfo)
Expand Down
2 changes: 2 additions & 0 deletions app/view/setting_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ def __connectSignalToSlot(self):
self.themeColorCard.colorChanged.connect(setThemeColor)

cfg.appRestartSig.connect(self.__showRestartToolTip)
self.careerGamesCount.pushButton.clicked.connect(
self.__showUpdatedSuccessfullyToolTip)
self.teamGamesNumberCard.pushButton.clicked.connect(
self.__showUpdatedSuccessfullyToolTip)
self.feedbackCard.clicked.connect(
Expand Down

0 comments on commit 96ad4b6

Please sign in to comment.