Skip to content

Commit

Permalink
实现单独的自动禁用英雄功能卡片
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzaphkiel committed Feb 11, 2024
1 parent 75d9f5b commit e862f16
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 134 deletions.
3 changes: 2 additions & 1 deletion app/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class Config(QConfig):
autoSelectChampion = ConfigItem("Functions",
"AutoSelectChampion", "")

enableAutoBanChampion = ConfigItem("Functions", "EnableAutoBanChampion", True, BoolValidator())
enableAutoBanChampion = ConfigItem(
"Functions", "EnableAutoBanChampion", False, BoolValidator())
autoBanChampion = ConfigItem("Functions", "AutoBanChampion", "")

lastNoticeSha = ConfigItem("Other", "LastNoticeSha", "")
Expand Down
1 change: 1 addition & 0 deletions app/common/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Icon(FluentIconBase, Enum):
CIRCLE = 'Circle'
PLANE = 'Plane'
APPLIST = 'AppList'
SQUARECROSS = "SquareCross"

def path(self, theme=Theme.AUTO):
return f'./app/resource/icons/{self.value}_{getIconColor(theme)}.svg'
Binary file modified app/resource/i18n/Seraphine.zh_CN.qm
Binary file not shown.
246 changes: 142 additions & 104 deletions app/resource/i18n/Seraphine.zh_CN.ts

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions app/resource/icons/SquareCross_black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/resource/icons/SquareCross_white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 125 additions & 27 deletions app/view/auxiliary_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import stat

from ..common.qfluentwidgets import (SettingCardGroup, SwitchSettingCard, ExpandLayout,
SmoothScrollArea, SettingCard, LineEdit, setCustomStyleSheet,
PushButton, ComboBox, SwitchButton, ConfigItem, qconfig,
IndicatorPosition, InfoBar, InfoBarPosition, SpinBox, ExpandGroupSettingCard)
SmoothScrollArea, SettingCard, LineEdit, setCustomStyleSheet,
PushButton, ComboBox, SwitchButton, ConfigItem, qconfig,
IndicatorPosition, InfoBar, InfoBarPosition, SpinBox, ExpandGroupSettingCard)

from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtWidgets import QWidget, QLabel, QCompleter, QVBoxLayout, QHBoxLayout, QGridLayout
Expand Down Expand Up @@ -88,10 +88,14 @@ def __init__(self, parent=None):
)
self.autoSelectChampionCard = AutoSelectChampionCard(
self.tr("Auto select champion"),
self.tr("Auto select champion when blind selection begin"),
cfg.enableAutoBanChampion, cfg.autoBanChampion,
self.tr("Auto select champion when your selection begin"),
cfg.enableAutoSelectChampion, cfg.autoSelectChampion,
self.gameGroup)
self.autoBanChampionCard = AutoBanChampionCard(
self.tr("Auto ban champion"),
self.tr("Auto ban champion when your ban section begin"),
cfg.enableAutoBanChampion, cfg.autoBanChampion,
self.gameGroup)

# self.copyPlayersInfoCard = SwitchSettingCard(
# Icon.COPY, self.tr("Auto copy players' info"),
Expand Down Expand Up @@ -129,6 +133,7 @@ def __initLayout(self):
self.gameGroup.addSettingCard(self.autoAcceptMatchingCard)
self.gameGroup.addSettingCard(self.autoReconnectCard)
self.gameGroup.addSettingCard(self.autoSelectChampionCard)
self.gameGroup.addSettingCard(self.autoBanChampionCard)
self.gameGroup.addSettingCard(self.createPracticeLobbyCard)
self.gameGroup.addSettingCard(self.spectateCard)
self.gameGroup.addSettingCard(self.lockConfigCard)
Expand Down Expand Up @@ -171,8 +176,16 @@ def setEnabled(self, a0: bool) -> None:

self.removeTokensCard.pushButton.setEnabled(a0)

if a0 and cfg.get(cfg.enableAutoSelectChampion):
self.autoSelectChampionCard.switchButton.setEnabled(True)
if a0 and cfg.get(cfg.enableAutoBanChampion):
self.autoBanChampionCard.switchButton.setEnabled(True)

if not cfg.get(cfg.enableAutoBanChampion):
self.autoBanChampionCard.lineEdit.setEnabled(a0)
if a0:
self.autoBanChampionCard.validate()

if a0 and cfg.get(cfg.enableAutoBanChampion):
self.autoBanChampionCard.switchButton.setEnabled(True)

self.lockConfigCard.setEnabled(a0)
self.autoReconnectCard.setEnabled(a0)
Expand Down Expand Up @@ -919,17 +932,12 @@ def __setStatusLableText(self, delay, isChecked):

# 自动选择英雄卡片
class AutoSelectChampionCard(ExpandGroupSettingCard):
def __init__(self, title, content=None, enableBanChampion: ConfigItem = None, banChampion: ConfigItem= None, enableConfigItem: ConfigItem = None,
def __init__(self, title, content=None, enableConfigItem: ConfigItem = None,
championConfigItem: ConfigItem = None, parent=None):
super().__init__(Icon.CHECK, title, content, parent)

self.statusLabel = QLabel(self)

self.banLayout = QHBoxLayout(QWidget(self.view))
self.banLabel = QLabel("自动禁用(亚索):")
self.banEdit = LineEdit()
# self.banSwitch = SwitchButton(indicatorPos=IndicatorPosition.RIGHT)

self.inputWidget = QWidget(self.view)
self.inputLayout = QHBoxLayout(self.inputWidget)

Expand All @@ -944,9 +952,6 @@ def __init__(self, title, content=None, enableBanChampion: ConfigItem = None, ba
self.completer = None
self.champions = []

self.enableBanChampion = enableBanChampion
self.banChampion = banChampion

self.enableConfigItem = enableConfigItem
self.championConfigItem = championConfigItem

Expand All @@ -956,10 +961,6 @@ def __init__(self, title, content=None, enableBanChampion: ConfigItem = None, ba
def __initLayout(self):
self.addWidget(self.statusLabel)

self.inputLayout.addWidget(self.banLabel, alignment=Qt.AlignLeft)
self.inputLayout.addWidget(self.banEdit, alignment=Qt.AlignLeft)
self.inputLayout.addWidget(self.switchButton, alignment=Qt.AlignLeft)

self.inputLayout.setSpacing(19)
self.inputLayout.setAlignment(Qt.AlignTop)
self.inputLayout.setContentsMargins(48, 18, 44, 18)
Expand All @@ -978,11 +979,6 @@ def __initLayout(self):
self.addGroupWidget(self.switchButtonWidget)

def __initWidget(self):
self.banEdit.setPlaceholderText("疾风剑豪")
self.banEdit.setMinimumWidth(250)
self.banEdit.setClearButtonEnabled(True)
self.banEdit.setEnabled(False)

self.lineEdit.setPlaceholderText(self.tr("Champion name"))
self.lineEdit.setMinimumWidth(250)
self.lineEdit.setClearButtonEnabled(True)
Expand Down Expand Up @@ -1011,9 +1007,111 @@ def updateCompleter(self):
self.validate()

def setValue(self, championName: str, isChecked: bool):
qconfig.set(self.banChampion, "疾风剑豪")
qconfig.set(self.enableBanChampion, True)
qconfig.set(self.championConfigItem, championName)
qconfig.set(self.enableConfigItem, isChecked)

self.lineEdit.setText(championName)
self.switchButton.setChecked(isChecked)

self.__setStatusLabelText(championName, isChecked)

def validate(self):
text = self.lineEdit.text()

if text not in self.champions and self.switchButton.checked:
self.setValue("", False)

self.__onLineEditTextChanged(text)

def __onLineEditTextChanged(self, text):
enable = text in self.champions

self.switchButton.setEnabled(enable)

self.setValue(text, self.switchButton.isChecked())

def __onCheckedChanged(self, isChecked: bool):
self.lineEdit.setEnabled(not isChecked)
self.setValue(self.lineEdit.text(), isChecked)


# 自动 ban 英雄卡片
class AutoBanChampionCard(ExpandGroupSettingCard):
def __init__(self, title, content=None, enableConfigItem: ConfigItem = None,
championConfigItem: ConfigItem = None, parent=None):
super().__init__(Icon.SQUARECROSS, title, content, parent)

self.statusLabel = QLabel(self)

self.inputWidget = QWidget(self.view)
self.inputLayout = QHBoxLayout(self.inputWidget)

self.championLabel = QLabel(
self.tr("Champion will be banned automatically:"))
self.lineEdit = LineEdit()

self.switchButtonWidget = QWidget(self.view)
self.switchButtonLayout = QHBoxLayout(self.switchButtonWidget)
self.switchButton = SwitchButton(indicatorPos=IndicatorPosition.RIGHT)

self.completer = None
self.champions = []

self.enableConfigItem = enableConfigItem
self.championConfigItem = championConfigItem

self.__initLayout()
self.__initWidget()

def __initLayout(self):
self.addWidget(self.statusLabel)

self.inputLayout.setSpacing(19)
self.inputLayout.setAlignment(Qt.AlignTop)
self.inputLayout.setContentsMargins(48, 18, 44, 18)

self.inputLayout.addWidget(self.championLabel, alignment=Qt.AlignLeft)
self.inputLayout.addWidget(self.lineEdit, alignment=Qt.AlignRight)
self.inputLayout.setSizeConstraint(QHBoxLayout.SetMinimumSize)

self.switchButtonLayout.setContentsMargins(48, 18, 44, 18)
self.switchButtonLayout.addWidget(self.switchButton, 0, Qt.AlignRight)
self.switchButtonLayout.setSizeConstraint(QHBoxLayout.SetMinimumSize)

self.viewLayout.setSpacing(0)
self.viewLayout.setContentsMargins(0, 0, 0, 0)
self.addGroupWidget(self.inputWidget)
self.addGroupWidget(self.switchButtonWidget)

def __initWidget(self):
self.lineEdit.setPlaceholderText(self.tr("Champion name"))
self.lineEdit.setMinimumWidth(250)
self.lineEdit.setClearButtonEnabled(True)
self.lineEdit.setEnabled(False)

self.switchButton.setEnabled(False)

self.setValue(qconfig.get(self.championConfigItem),
qconfig.get(self.enableConfigItem))

self.lineEdit.textChanged.connect(self.__onLineEditTextChanged)
self.switchButton.checkedChanged.connect(self.__onCheckedChanged)

def __setStatusLabelText(self, champion, isChecked):
if isChecked:
self.statusLabel.setText(self.tr("Enabled, champion: ") + champion)
else:
self.statusLabel.setText(self.tr("Disabled"))

def updateCompleter(self):
self.champions = connector.manager.getChampionList()
self.completer = QCompleter(self.champions)
self.completer.setFilterMode(Qt.MatchContains)
self.lineEdit.setCompleter(self.completer)

self.validate()

def setValue(self, championName: str, isChecked: bool):
qconfig.set(self.championConfigItem, championName)
qconfig.set(self.enableConfigItem, isChecked)

Expand Down
7 changes: 5 additions & 2 deletions app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ def _():

self.auxiliaryFuncInterface.profileBackgroundCard.updateCompleter()
self.auxiliaryFuncInterface.autoSelectChampionCard.updateCompleter()
self.auxiliaryFuncInterface.autoBanChampionCard.updateCompleter()
self.auxiliaryFuncInterface.lockConfigCard.loadNowMode.emit()

status = connector.getGameStatus()
Expand Down Expand Up @@ -978,12 +979,14 @@ def __onChampSelectChanged(self, data):
actionId = action["id"]
if action["type"] == "pick":
if (cfg.get(cfg.enableAutoSelectChampion)):
championId = connector.manager.getChampionIdByName(cfg.get(cfg.autoSelectChampion))
championId = connector.manager.getChampionIdByName(
cfg.get(cfg.autoSelectChampion))
connector.selectChampion(action["id"], championId)
break
elif action["type"] == "ban":
if (cfg.get(cfg.enableAutoBanChampion) and data["data"]["bans"]["numBans"] > 0):
championId = connector.manager.getChampionIdByName(cfg.get(cfg.autoBanChampion))
championId = connector.manager.getChampionIdByName(
cfg.get(cfg.autoBanChampion))
connector.banChampion(actionId, championId)
return

Expand Down

0 comments on commit e862f16

Please sign in to comment.