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

Add fight extends configs #238

Merged
merged 3 commits into from
Apr 24, 2024
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
22 changes: 22 additions & 0 deletions app/setting_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,25 @@ def __initCard(self):
self.tr("上次运行锄大地的时间"),
"fight_timestamp"
)
self.fightAllowMapBuyCard = SwitchSettingCard1(
FIF.BUS,
self.tr('购买代币与过期邮包'),
"",
"fight_allow_map_buy"
)
self.fightAllowSnackBuyCard = SwitchSettingCard1(
FIF.BUS,
self.tr('购买秘技零食并合成零食'),
"",
"fight_allow_snack_buy"
)
self.fightMainMapCard = ComboBoxSettingCard2(
"fight_main_map",
FIF.GLOBE,
self.tr('优先星球'),
'',
texts={"空间站": "1", "雅利洛": "2", "仙舟": "3", "匹诺康尼": "4"}
)

self.UniverseGroup = SettingCardGroup(self.tr("模拟宇宙"), self.scrollWidget)
self.universeEnableCard = SwitchSettingCard1(
Expand Down Expand Up @@ -595,6 +614,9 @@ def __initLayout(self):
self.FightGroup.addSettingCard(self.fightTeamEnableCard)
# self.FightGroup.addSettingCard(self.fightTeamNumberCard)
self.FightGroup.addSettingCard(self.FightRunTimeCard)
self.FightGroup.addSettingCard(self.fightAllowMapBuyCard)
self.FightGroup.addSettingCard(self.fightAllowSnackBuyCard)
self.FightGroup.addSettingCard(self.fightMainMapCard)

self.UniverseGroup.addSettingCard(self.universeEnableCard)
self.UniverseGroup.addSettingCard(self.universeFateCard)
Expand Down
119 changes: 119 additions & 0 deletions app/sub_interfaces/push_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QToolBox, QWidget, QVBoxLayout, QTabBar, QInputDialog
from PyQt5.QtWidgets import QFrame
from qfluentwidgets import FluentStyleSheet
from qfluentwidgets import FluentIcon as FIF
from app.card.pushsettingcard1 import PushSettingCard
from app.card.switchsettingcard1 import SwitchSettingCard1
from module.config import cfg

class PushToolsBox(QWidget):
def __init__(self, parent: QWidget | None = ..., flags: Qt.WindowFlags | Qt.WindowType = ...):
super().__init__(parent=parent)
self.windowPushCard = WindowsPushCard(parent=self)
self.telegramPushCard = TelegramPushCard(parent=self)
self.smtpPushCard = SmtpPushCard(parent=self)
self.pushCars = [self.windowPushCard, self.telegramPushCard, self.smtpPushCard]
style_sheet = """
QTabBar::tab {
background-color: #0078d4;
color: white;
padding: 8px 20px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
QTabBar::tab:selected {
background-color: white;
color: #0078d4;
}
QTabBar::tab:!selected {
margin-top: 2px;
}
QTabBar::tab:first:selected {
margin-left: 0;
}
QTabBar::tab:last:selected {
margin-right: 0;
}
"""
self.tabBar = QTabBar(parent=self)
self.tabBar.setStyleSheet(style_sheet)
FluentStyleSheet.TAB_VIEW.apply(self.tabBar)
self.tabBar.addTab(self.tr('Windows'))
self.tabBar.addTab(self.tr('Telegram'))
self.tabBar.addTab(self.tr('Smtp'))
self.vLayout = QVBoxLayout()
self.vLayout.addWidget(self.tabBar)
for card in self.pushCars:
self.vLayout.addWidget(card)
card.hide()
self.windowPushCard.show()
_self = self
def currentChanged(self):
for card in _self.pushCars:
if (card.isVisible()):
hCard = card
idx = _self.tabBar.currentIndex()
_self.pushCars[idx].show()
hCard.hide()
_self.adjustSize()
_self.parent().adjustSize()
self.tabBar.currentChanged.connect(currentChanged)
self.setLayout(self.vLayout)
self.adjustSize()

class WindowsPushCard(QWidget):
def __init__(self, parent: QWidget | None = ..., flags: Qt.WindowFlags | Qt.WindowType = ...):
super().__init__(parent=parent)
self.winotifyEnableCard = SwitchSettingCard1(
FIF.BACK_TO_WINDOW,
self.tr('启用 Windows 通知'),
None,
"notify_winotify_enable"
)
self.vLayout = QVBoxLayout()
self.vLayout.addWidget(self.winotifyEnableCard)
self.setLayout(self.vLayout)


class TelegramPushCard(QWidget):
def __init__(self, parent: QWidget | None = ..., flags: Qt.WindowFlags | Qt.WindowType = ...):
super().__init__(parent=parent)
self.winotifyEnableCard = SwitchSettingCard1(
FIF.BACK_TO_WINDOW,
self.tr('启用 Telegram 通知'),
None,
"notify_telegram_enable"
)
self.telegramTokenCard = PushSettingCard(
self.tr('修改'),
FIF.GAME,
self.tr("Telegram Token"),
"notify_telegram_token",
cfg.notify_telegram_token,
self,
)
self.telegramTokenCard.clicked.connect(self.inputToken)
self.vLayout = QVBoxLayout()
self.vLayout.addWidget(self.winotifyEnableCard)
self.vLayout.addWidget(self.telegramTokenCard)
self.setLayout(self.vLayout)

def inputToken(self):
token = QInputDialog.getText(self, "输入 Telegram Token", "Token")
if not token is None:
cfg.set_value("notify_telegram_token", token)
self.telegramTokenCard.setContent(token)

class SmtpPushCard(QFrame):
def __init__(self, parent: QWidget | None = ..., flags: Qt.WindowFlags | Qt.WindowType = ...):
super().__init__(parent=parent)
self.winotifyEnableCard = SwitchSettingCard1(
FIF.BACK_TO_WINDOW,
self.tr('启用 Smtp 通知'),
None,
"notify_smtp_enable"
)
self.vLayout = QVBoxLayout()
self.vLayout.addWidget(self.winotifyEnableCard)
self.setLayout(self.vLayout)
3 changes: 3 additions & 0 deletions assets/config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ fight_team_enable: false # 是否在锄大地时自动切换队伍。true 开启
fight_team_number: "6" # 自动切换到的队伍编号。
fight_requirements: false # 是否已安装锄大地依赖。true 表示已安装,false 表示未安装或需要重新安装。
fight_timestamp: 0 # 上次运行锄大地的时间戳,用于记录和控制运行频率。
fight_allow_map_buy: false # 购买代币与过期邮包
fight_allow_snack_buy: false # 购买秘技零食并合成零食
fight_main_map: "1" # 优先星球 {"空间站": "1", "雅利洛": "2", "仙舟": "3", "匹诺康尼": "4"},

# 模拟宇宙配置
universe_enable: false # 是否启用模拟宇宙功能。true 开启,false 关闭。
Expand Down
45 changes: 45 additions & 0 deletions module/config/fhoe_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
import shutil

import json
from module.config import cfg


def auto_config():
if not os.path.exists(os.path.join(cfg.fight_path, "config.json")):
config = {
"version": "2.1.18",
"real_width": 0,
"real_height": 0,
"map_debug": False,
"github_proxy": "",
"rawgithub_proxy": "",
"webhook_url": "",
"start": False,
"picture_version": "0",
"star_version": "0",
"open_map": "m",
"script_debug": False,
"auto_shutdown": 0,
"taskkill_name": "",
"auto_final_fight_e": False,
"auto_final_fight_e_cnt": 20,
"allow_fight_e_buy_prop": False,
"auto_run_in_map": True,
"detect_fight_status_time": 5,
"map_version": "default",
"main_map": "1",
"allow_run_again": False,
"allow_run_next_day": False,
"allow_map_buy": False,
"allow_snack_buy": False
}
else:
with open(os.path.join(cfg.fight_path, "config.json"), 'r', encoding='utf-8') as f:
config = json.load(f)
if config['allow_map_buy'] != cfg.fight_allow_map_buy or config['allow_snack_buy'] != cfg.fight_allow_snack_buy or config['main_map'] != cfg.fight_main_map:
config['allow_map_buy'] = cfg.fight_allow_map_buy
config['allow_snack_buy'] = cfg.fight_allow_snack_buy
config['main_map'] = cfg.fight_main_map
with open(os.path.join(cfg.fight_path, "config.json"), 'w', encoding='utf-8') as f:
json.dump(config, f, ensure_ascii=False, indent=4)
4 changes: 3 additions & 1 deletion tasks/daily/fight.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import subprocess
import sys
import os
from module.config import fhoe_config


class Fight:
Expand Down Expand Up @@ -87,7 +88,8 @@ def start():
# 切换队伍
if cfg.fight_team_enable:
Team.change_to(cfg.fight_team_number)


fhoe_config.auto_config()
log.info("开始锄大地")
screen.change_to('main')

Expand Down
Loading