Skip to content

Commit

Permalink
feat: merge_immersifier_limit moesnow#165
Browse files Browse the repository at this point in the history
  • Loading branch information
moesnow committed Mar 15, 2024
1 parent accaec9 commit 534a421
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
45 changes: 44 additions & 1 deletion app/card/switchsettingcard1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from qfluentwidgets import (SettingCard, FluentIconBase, SwitchButton, IndicatorPosition)
from qfluentwidgets import (SettingCard, FluentIconBase, SwitchButton, IndicatorPosition, ComboBox)
from typing import Union
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QIcon
Expand Down Expand Up @@ -33,3 +33,46 @@ def __onCheckedChanged(self, isChecked: bool):
def setValue(self, isChecked: bool):
self.switchButton.setChecked(isChecked)
self.switchButton.setText(self.tr('开') if isChecked else self.tr('关'))


class SwitchSettingCardImmersifier(SettingCard):
""" Setting card with switch button """

checkedChanged = pyqtSignal(bool)

def __init__(self, icon: Union[str, QIcon, FluentIconBase], title, content=None, configname: str = None, parent=None):
super().__init__(icon, title, content, parent)
self.configname = configname

self.comboBox = ComboBox(self)
self.hBoxLayout.addWidget(self.comboBox, 0, Qt.AlignRight)
self.hBoxLayout.addSpacing(10)

texts = ['1', '2', '3', '4', '5', '6', '7', '8']
for text, option in zip(texts, texts):
self.comboBox.addItem(text, userData=option)

self.comboBox.setCurrentText(cfg.get_value("merge_immersifier_limit"))
self.comboBox.currentIndexChanged.connect(self._onCurrentIndexChanged)

self.switchButton = SwitchButton(self.tr('关'), self, IndicatorPosition.RIGHT)

self.setValue(cfg.get_value(self.configname))

# add switch button to layout
self.hBoxLayout.addWidget(self.switchButton, 0, Qt.AlignRight)
self.hBoxLayout.addSpacing(16)

self.switchButton.checkedChanged.connect(self.__onCheckedChanged)

def __onCheckedChanged(self, isChecked: bool):
""" switch button checked state changed slot """
self.setValue(isChecked)
cfg.set_value(self.configname, isChecked)

def setValue(self, isChecked: bool):
self.switchButton.setChecked(isChecked)
self.switchButton.setText(self.tr('开') if isChecked else self.tr('关'))

def _onCurrentIndexChanged(self, index: int):
cfg.set_value("merge_immersifier_limit", self.comboBox.itemData(index))
6 changes: 3 additions & 3 deletions app/setting_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .common.style_sheet import StyleSheet
from .card.comboboxsettingcard1 import ComboBoxSettingCard1
from .card.comboboxsettingcard2 import ComboBoxSettingCard2, ComboBoxSettingCardLog
from .card.switchsettingcard1 import SwitchSettingCard1
from .card.switchsettingcard1 import SwitchSettingCard1, SwitchSettingCardImmersifier
from .card.rangesettingcard1 import RangeSettingCard1
from .card.pushsettingcard1 import PushSettingCardInstance, PushSettingCardEval, PushSettingCardDate, PushSettingCardKey, PushSettingCardTeam
from module.config import cfg
Expand Down Expand Up @@ -85,10 +85,10 @@ def __initCard(self):
None,
texts=['3', '4', '5', '6', '7']
)
self.mergeImmersifierEnableCard = SwitchSettingCard1(
self.mergeImmersifierEnableCard = SwitchSettingCardImmersifier(
FIF.BASKETBALL,
self.tr('优先合成沉浸器'),
"达到上限八个后停止,可搭配每天一定次数的模拟宇宙实现循环",
"达到指定上限后停止,可搭配每天一定次数的模拟宇宙实现循环",
"merge_immersifier"
)
self.useReservedTrailblazePowerEnableCard = SwitchSettingCard1(
Expand Down
1 change: 1 addition & 0 deletions assets/config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ instance_team_number: "5" # 自动切换的队伍编号。

# 合成设置
merge_immersifier: False # 是否优先合成沉浸器。true 开启,false 关闭。
merge_immersifier_limit: "8" # 沉浸器上限。

# 开拓力使用设置
use_reserved_trailblaze_power: False # 是否使用后备开拓力。true 使用,false 不使用。
Expand Down
1 change: 1 addition & 0 deletions assets/docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v2.0.6

### 新功能
- 自定义每日合成沉浸器的个数 [#165](https://github.com/moesnow/March7thAssistant/pull/165)
- 在 “完整运行” 清体力前增加一次 “委托奖励检测” [#171](https://github.com/moesnow/March7thAssistant/pull/171)
- 快捷查看日志按钮 [#150](https://github.com/moesnow/March7thAssistant/pull/150)

Expand Down
7 changes: 4 additions & 3 deletions tasks/power/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def move_button_and_confirm():
def merge(type):
if type == "immersifier":
log.hr("准备合成沉浸器", 2)
limit = int(cfg.merge_immersifier_limit)
screen.change_to("guide3")

immersifier_crop = (1623.0 / 1920, 40.0 / 1080, 162.0 / 1920, 52.0 / 1080)
Expand All @@ -158,14 +159,14 @@ def merge(type):

immersifier_count = int(text.split("/")[0])
log.info(f"🟣沉浸器: {immersifier_count}/8")
if immersifier_count >= 8:
log.info("沉浸器已满")
if immersifier_count >= limit:
log.info("沉浸器已达到上限")
return

screen.change_to("guide3")
power = Power.get()

count = min(power // 40, 8 - immersifier_count)
count = min(power // 40, limit - immersifier_count)
if count <= 0:
log.info("体力不足")
return
Expand Down

0 comments on commit 534a421

Please sign in to comment.