Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

功能更新: 实现了上一盘队友(对手)的显示 #154

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion app/components/summoner_name_button.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from PyQt5.QtWidgets import QLabel
from PyQt5.QtCore import Qt, pyqtSignal
from qfluentwidgets import ToolTipPosition, ToolTipFilter


class SummonerName(QLabel):
clicked = pyqtSignal(bool)

def __init__(self, text, parent=None):
def __init__(self, text, color=None, parent=None):
super().__init__(parent)
self.setCursor(Qt.PointingHandCursor)
self.setText(text)
Expand All @@ -14,6 +15,17 @@ def __init__(self, text, parent=None):

self.setWordWrap(True)
self.setProperty('pressed', False)
if color:
self.setStyleSheet(f"color: {color}")

if color == "#bf242a":
self.setToolTip(self.tr("Former enemy"))
else:
self.setToolTip(self.tr("Former ally"))

self.installEventFilter(
ToolTipFilter(self, 0, ToolTipPosition.BOTTOM))


def mousePressEvent(self, ev) -> None:
self.setProperty('pressed', True)
Expand Down
27 changes: 21 additions & 6 deletions app/lol/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@ def processGameDetailData(puuid, game):


def getTeammates(game, targetPuuid):
"""
通过game信息获取目标召唤师的队友

@param game: @see connector.getGameDetailByGameId
@param targetPuuid: 目标召唤师puuid
@return: @see res
"""
targetParticipantId = None

for participant in game['participantIdentities']:
Expand All @@ -420,8 +427,13 @@ def getTeammates(game, targetPuuid):

break

res = {'queueId': game['queueId'], 'win': win,
'remake': remake, 'summoners': []}
res = {
'queueId': game['queueId'],
'win': win,
'remake': remake,
'summoners': [], # 队友召唤师 (由于兼容性, 未修改字段名)
'enemies': [] # 对面召唤师, 若有多个队伍会全放这里面
}

for player in game['participants']:

Expand All @@ -430,14 +442,17 @@ def getTeammates(game, targetPuuid):
else:
cmp = player['stats']['subteamPlacement']

if cmp == tid:

p = player['participantId']
s = game['participantIdentities'][p - 1]['player']
p = player['participantId']
s = game['participantIdentities'][p - 1]['player']

if cmp == tid:
if s['puuid'] != targetPuuid:
res['summoners'].append(
{'summonerId': s['summonerId'], 'name': s['summonerName'], 'puuid': s['puuid'], 'icon': s['profileIcon']})
else:
res['enemies'].append(
{'summonerId': s['summonerId'], 'name': s['summonerName'], 'puuid': s['puuid'],
'icon': s['profileIcon']})

return res

Expand Down
12 changes: 10 additions & 2 deletions app/view/game_info_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ def __init__(self, info: dict, parent=None):
self.infoVBoxLayout = QVBoxLayout()

name = info['name']
self.summonerName = SummonerName(name)
fateFlag = info["fateFlag"]
nameColor = None
if fateFlag:
nameColor = "#bf242a" if fateFlag == "enemy" else "#057748"
self.summonerName = SummonerName(name, nameColor)
self.summonerName.clicked.connect(lambda: self.parent().parent(
).parent().parent().summonerViewClicked.emit(info['puuid']))

Expand Down Expand Up @@ -522,7 +526,11 @@ def __init__(self, summoner, parent=None):
# QSizePolicy.Policy.Fixed)

name: str = summoner['name']
self.summonerName = SummonerName(name)
fateFlag = summoner["fateFlag"]
nameColor = None
if fateFlag:
nameColor = "#bf242a" if fateFlag == "enemy" else "#057748"
self.summonerName = SummonerName(name, nameColor)
self.summonerName.setObjectName("summonerName")
self.summonerName.clicked.connect(lambda: self.parent().parent(
).parent().summonerGamesClicked.emit(self.summonerName.text()))
Expand Down
26 changes: 22 additions & 4 deletions app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ def process_item(item):
origGamesInfo["games"] = [
game for game in origGamesInfo["games"] if game["queueId"] in (420, 440)]
begIdx = 15
while len(origGamesInfo["games"]) < 11:
while len(origGamesInfo["games"]) < 11: # FIXME 老玩家打排位, 会死锁
endIdx = begIdx + 5
origGamesInfo["games"].extend([
game for game in connector.getSummonerGamesByPuuid(puuid, begIdx, endIdx)["games"]
Expand Down Expand Up @@ -1075,6 +1075,14 @@ def process_item(item):
if sId in [x['summonerId'] for x in data['myTeam']] and cnt >= cfg.get(cfg.teamGamesNumber)
]

fateFlag = None
if self.currentSummoner.summonerId in [t['summonerId'] for t in teammatesInfo[0]['summoners']]:
# 上把队友
fateFlag = "ally"
elif self.currentSummoner.summonerId in [t['summonerId'] for t in teammatesInfo[0]['enemies']]:
# 上把对面
fateFlag = "enemy"

return {
"name": summoner["displayName"],
"icon": icon,
Expand All @@ -1087,7 +1095,8 @@ def process_item(item):
"summonerId": summonerId,
"teammatesMarker": teammatesMarker,
"kda": [kill, deaths, assists],
"cellId": item["cellId"]
"cellId": item["cellId"],
"fateFlag": fateFlag
}

with ThreadPoolExecutor() as executor:
Expand Down Expand Up @@ -1190,7 +1199,7 @@ def process_item(item, isAllys=False):
origGamesInfo["games"] = [
game for game in origGamesInfo["games"] if game["queueId"] in (420, 440)]
begIdx = 15
while len(origGamesInfo["games"]) < 11:
while len(origGamesInfo["games"]) < 11: # FIXME 老玩家打排位, 会死锁
endIdx = begIdx + 5
origGamesInfo["games"].extend([
game for game in connector.getSummonerGamesByPuuid(puuid, begIdx, endIdx)["games"]
Expand Down Expand Up @@ -1243,6 +1252,14 @@ def process_item(item, isAllys=False):
if sId in [x.get('summonerId') for x in teamMember] and cnt >= cfg.get(cfg.teamGamesNumber)
]

fateFlag = None
if self.currentSummoner.summonerId in [t['summonerId'] for t in teammatesInfo[0]['summoners']]:
# 上把队友
fateFlag = "ally"
elif self.currentSummoner.summonerId in [t['summonerId'] for t in teammatesInfo[0]['enemies']]:
# 上把对面
fateFlag = "enemy"

return {
"name": summoner["displayName"],
"icon": icon,
Expand All @@ -1256,7 +1273,8 @@ def process_item(item, isAllys=False):
"teammatesMarker": teammatesMarker,
"kda": [kill, deaths, assists],
# 上野中辅下
"order": pos.index(item.get('selectedPosition')) if item.get('selectedPosition') in pos else len(pos)
"order": pos.index(item.get('selectedPosition')) if item.get('selectedPosition') in pos else len(pos),
"fateFlag": fateFlag
}

with ThreadPoolExecutor() as executor:
Expand Down