1
+ from PySide6 .QtCore import Signal
2
+ from PySide6 .QtWidgets import QWidget
3
+ from qfluentwidgets import PushButton , FluentIcon , SettingCardGroup , HyperlinkCard
4
+ from typing import Optional , List
5
+
6
+ from one_dragon .base .config .config_item import ConfigItem
7
+ from one_dragon .gui .widgets .setting_card .multi_push_setting_card import MultiPushSettingCard
8
+ from one_dragon .gui .widgets .vertical_scroll_interface import VerticalScrollInterface
9
+ from one_dragon .utils .i18_utils import gt
10
+ from phosdeiz .gui .widgets import Column , ComboBox , Row
11
+ from zzz_od .application .battle_assistant .auto_battle_config import get_auto_battle_op_config_list
12
+ from zzz_od .auto_battle .auto_battle_operator import AutoBattleOperator
13
+ from zzz_od .context .zzz_context import ZContext
14
+ from zzz_od .game_data .agent import AgentEnum , AgentTypeEnum
15
+
16
+
17
+ class TeamSettingCard (MultiPushSettingCard ):
18
+
19
+ value_changed = Signal (List [str ])
20
+
21
+ def __init__ (self ):
22
+ config_list = [ConfigItem (i .value .agent_name ) for i in AgentEnum ] + [ConfigItem (i .value ) for i in AgentTypeEnum if i != AgentTypeEnum .UNKNOWN ]
23
+ self .btn_list : List [ComboBox ] = []
24
+ for i in range (3 ):
25
+ opt = ComboBox ()
26
+ opt .set_items (config_list )
27
+ opt .currentIndexChanged .connect (self .on_character_chosen )
28
+ opt .setDisabled (True )
29
+ self .btn_list .append (opt )
30
+
31
+ MultiPushSettingCard .__init__ (self , title = '配队' , btn_list = self .btn_list )
32
+
33
+ def init_team (self , character_list : List [str ]) -> None :
34
+ """
35
+ 初始化
36
+ :param character_list:
37
+ :return:
38
+ """
39
+ if character_list is None :
40
+ return
41
+ for i in range (3 ):
42
+ if i >= len (character_list ):
43
+ self .btn_list [i ].init_with_value (None )
44
+ else :
45
+ self .btn_list [i ].init_with_value (character_list [i ])
46
+
47
+ def on_character_chosen (self ) -> None :
48
+ self .value_changed .emit ([opt .currentData () for opt in self .btn_list ])
49
+
50
+
51
+ class AutoBattleEditorInterface (VerticalScrollInterface ):
52
+
53
+ def __init__ (self , ctx : ZContext , parent = None ):
54
+ VerticalScrollInterface .__init__ (
55
+ self ,
56
+ object_name = 'auto_battle_editor_interface' ,
57
+ parent = parent ,
58
+ content_widget = None ,
59
+ nav_text_cn = '配置编辑'
60
+ )
61
+
62
+ self .ctx : ZContext = ctx
63
+ self .chosen_config : Optional [AutoBattleOperator ] = None
64
+
65
+ def get_content_widget (self ) -> QWidget :
66
+ content_widget = Row ()
67
+
68
+ content_widget .add_widget (self .init_left_part (), stretch = 1 )
69
+ content_widget .add_widget (self .init_right_part (), stretch = 1 )
70
+
71
+ return content_widget
72
+
73
+ def init_left_part (self ) -> QWidget :
74
+ widget = Column ()
75
+
76
+ info_opt = HyperlinkCard (icon = FluentIcon .INFO , title = '当前仅用于信息展示' ,
77
+ content = '角色顺序 朱青妮 跟 青妮朱 是一样的' ,
78
+ text = '' , url = '' )
79
+ info_opt .setFixedHeight (50 )
80
+ widget .add_widget (info_opt )
81
+
82
+ btn_row = Row ()
83
+ widget .add_widget (btn_row )
84
+
85
+ self .existed_yml_btn = ComboBox ()
86
+ self .existed_yml_btn .setPlaceholderText (gt ('选择已有' , 'ui' ))
87
+ self .existed_yml_btn .currentIndexChanged .connect (self .on_config_chosen )
88
+ btn_row .add_widget (self .existed_yml_btn )
89
+
90
+ self .create_btn = PushButton (text = gt ('新建' , 'ui' ))
91
+ # self.create_btn.clicked.connect(self._on_create_clicked)
92
+ btn_row .add_widget (self .create_btn )
93
+
94
+ self .copy_btn = PushButton (text = gt ('复制' , 'ui' ))
95
+ # self.copy_btn.clicked.connect(self._on_copy_clicked)
96
+ btn_row .add_widget (self .copy_btn )
97
+
98
+ self .delete_btn = PushButton (text = gt ('删除' , 'ui' ))
99
+ # self.delete_btn.clicked.connect(self._on_delete_clicked)
100
+ btn_row .add_widget (self .delete_btn )
101
+
102
+ self .cancel_btn = PushButton (text = gt ('取消' , 'ui' ))
103
+ self .cancel_btn .clicked .connect (self .on_cancel_clicked )
104
+ btn_row .add_widget (self .cancel_btn )
105
+
106
+ btn_row .add_stretch (1 )
107
+
108
+ basic_group = SettingCardGroup ('基础信息' )
109
+ widget .add_widget (basic_group )
110
+ self .author_opt = HyperlinkCard (icon = FluentIcon .PEOPLE , title = '作者' , text = '作者' ,
111
+ url = self .ctx .project_config .qq_link )
112
+ basic_group .addSettingCard (self .author_opt )
113
+ self .version_opt = HyperlinkCard (icon = FluentIcon .INFO , title = '版本' , text = '1.0' , url = '' )
114
+ basic_group .addSettingCard (self .version_opt )
115
+ self .introduction_opt = HyperlinkCard (icon = FluentIcon .INFO , title = '简介' , text = '' , url = '' )
116
+ basic_group .addSettingCard (self .introduction_opt )
117
+
118
+ self .team_group = SettingCardGroup ('适用配队' )
119
+ self .team_opt_list : List [TeamSettingCard ] = []
120
+ widget .add_widget (self .team_group )
121
+
122
+ widget .add_stretch (1 )
123
+ return widget
124
+
125
+ def init_right_part (self ) -> QWidget :
126
+ widget = Column ()
127
+
128
+ widget .add_stretch (1 )
129
+
130
+ return widget
131
+
132
+ def on_interface_shown (self ) -> None :
133
+ VerticalScrollInterface .on_interface_shown (self )
134
+
135
+ self .update_auto_battle_config_opts ()
136
+ self .update_display_by_config ()
137
+
138
+ def update_auto_battle_config_opts (self ) -> None :
139
+ self .existed_yml_btn .set_items (
140
+ get_auto_battle_op_config_list ('auto_battle' ),
141
+ target_value = self .chosen_config .module_name if self .chosen_config is not None else None
142
+ )
143
+
144
+ def update_display_by_config (self ) -> None :
145
+ chosen = self .chosen_config is not None
146
+
147
+ self .existed_yml_btn .setDisabled (chosen )
148
+ self .create_btn .setDisabled (True )
149
+ self .copy_btn .setDisabled (True )
150
+ self .delete_btn .setDisabled (True )
151
+ self .cancel_btn .setDisabled (not chosen )
152
+
153
+ self .update_team_group_display ()
154
+
155
+ if chosen :
156
+ self .author_opt .setContent (
157
+ f'感谢 { self .chosen_config .thanks } ' if self .chosen_config .thanks != '' else ''
158
+ )
159
+ self .author_opt .linkButton .setText (self .chosen_config .author )
160
+ self .author_opt .linkButton .setUrl (self .chosen_config .homepage )
161
+ self .version_opt .linkButton .setText (self .chosen_config .version )
162
+ self .introduction_opt .setContent (self .chosen_config .introduction )
163
+ else :
164
+ self .author_opt .setContent ('' )
165
+ self .author_opt .linkButton .setText ('作者' )
166
+ self .author_opt .linkButton .setUrl (self .ctx .project_config .qq_link )
167
+ self .version_opt .linkButton .setText ('1.0' )
168
+ self .introduction_opt .setContent ('' )
169
+
170
+ def update_team_group_display (self ) -> None :
171
+ if self .chosen_config is None :
172
+ for i in self .team_opt_list :
173
+ i .setVisible (False )
174
+ else :
175
+ # 删除多余的卡片
176
+ while len (self .team_opt_list ) > len (self .chosen_config .team_list ):
177
+ opt = self .team_opt_list .pop ()
178
+ self .team_group .cardLayout .removeWidget (opt )
179
+ self .team_group .adjustSize ()
180
+
181
+ # 增加不足的卡片
182
+ while len (self .team_opt_list ) < len (self .chosen_config .team_list ):
183
+ opt = TeamSettingCard ()
184
+ # opt.value_changed.connect(self.on_team_changed)
185
+ self .team_group .addSettingCard (opt )
186
+ self .team_opt_list .append (opt )
187
+
188
+ # 初始化数据
189
+ for i in range (len (self .team_opt_list )):
190
+ self .team_opt_list [i ].init_team (self .chosen_config .team_list [i ])
191
+ self .team_opt_list [i ].setVisible (True )
192
+
193
+ def on_config_chosen (self , idx : int ) -> None :
194
+ module_name = self .existed_yml_btn .currentData ()
195
+ self .chosen_config = AutoBattleOperator (self .ctx , 'auto_battle' , module_name )
196
+ self .update_display_by_config ()
197
+
198
+ def on_cancel_clicked (self ) -> None :
199
+ self .chosen_config = None
200
+ self .existed_yml_btn .blockSignals (True )
201
+ self .existed_yml_btn .setCurrentIndex (- 1 )
202
+ self .existed_yml_btn .blockSignals (False )
203
+ self .update_display_by_config ()
0 commit comments