-
Notifications
You must be signed in to change notification settings - Fork 0
/
tab_avatars.py
245 lines (202 loc) · 9.68 KB
/
tab_avatars.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# tab_avatars.py
import tkinter as tk
from tkinter import ttk
from tkinter import VERTICAL, RIGHT, LEFT, Y, StringVar, IntVar, messagebox
class AvatarsTab:
def __init__(self, notebook, avatars_list, command_manager, localization):
self.notebook = notebook
self.avatars_list = avatars_list
self.command_manager = command_manager
self.localization = localization
self.frame = ttk.Frame(notebook)
self.init_tab()
def init_tab(self):
# Create sub-tabs
self.sub_notebook = ttk.Notebook(self.frame)
self.sub_notebook.pack(fill=tk.BOTH, expand=True)
# Create 'Lineup & Properties' tab
self.create_lineup_properties_tab()
# Create 'Give' tab (this can be implemented later)
# self.create_give_tab()
def create_lineup_properties_tab(self):
tab_frame = ttk.Frame(self.sub_notebook)
self.sub_notebook.add(tab_frame, text='Lineup & Properties')
# Main frame
main_frame = tk.Frame(tab_frame)
main_frame.pack(fill=tk.BOTH, expand=True)
# Left frame for Lineup section
lineup_frame = tk.Frame(main_frame)
lineup_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# Right frame for Properties section
properties_frame = tk.Frame(main_frame)
properties_frame.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)
# Lineup Section
self.create_lineup_section(lineup_frame)
# Properties Section
self.create_properties_section(properties_frame)
def create_lineup_section(self, parent_frame):
# Title
lineup_label = tk.Label(parent_frame, text=self.localization["Lineup"], font=("Arial", 12, "bold"))
lineup_label.pack(pady=5)
# Warning label
warning_label = tk.Label(parent_frame, text=self.localization["USE_AT_YOUR_OWN_RISK"], fg="red", font=("Arial", 14, "bold"))
warning_label.pack(pady=5)
# Search functionality
search_var = StringVar()
search_label = tk.Label(parent_frame, text=self.localization["Search"])
search_label.pack()
search_entry = tk.Entry(parent_frame, textvariable=search_var)
search_entry.pack()
search_var.trace('w', lambda *args: update_avatar_list())
# Avatar listbox
avatar_frame = tk.Frame(parent_frame)
avatar_frame.pack(fill=tk.BOTH, expand=True)
scrollbar = tk.Scrollbar(avatar_frame, orient=VERTICAL)
avatar_listbox = tk.Listbox(avatar_frame, width=30, height=15, yscrollcommand=scrollbar.set, exportselection=False)
scrollbar.config(command=avatar_listbox.yview)
scrollbar.pack(side=RIGHT, fill=Y)
avatar_listbox.pack(side=LEFT, fill=tk.BOTH, expand=True)
# Lineup listbox
lineup_list_label = tk.Label(parent_frame, text=self.localization["Lineup_List"])
lineup_list_label.pack(pady=5)
lineup_listbox = tk.Listbox(parent_frame, width=30, height=10, exportselection=False)
lineup_listbox.pack(fill=tk.BOTH, expand=True)
# Buttons
buttons_frame = tk.Frame(parent_frame)
buttons_frame.pack(pady=5)
add_button = tk.Button(buttons_frame, text=self.localization["Add"], command=lambda: add_to_lineup())
add_button.pack(side=LEFT, padx=5)
remove_button = tk.Button(buttons_frame, text=self.localization["Remove"], command=lambda: remove_from_lineup())
remove_button.pack(side=LEFT, padx=5)
clear_button = tk.Button(buttons_frame, text=self.localization["Clear"], command=lambda: clear_lineup())
clear_button.pack(side=LEFT, padx=5)
# Initialize variables
selected_avatar_id = None
lineup_ids = []
# Function to update avatar list based on search
def update_avatar_list():
search_text = search_var.get().lower()
# Clear the listbox
avatar_listbox.delete(0, tk.END)
# Populate the listbox
for entry in self.avatars_list:
display_text = f"{entry['name']} ({entry['id']})"
if search_text in entry['name'].lower() or search_text in entry['id']:
avatar_listbox.insert(tk.END, display_text)
# Bind selection event
def on_avatar_select(event):
nonlocal selected_avatar_id
selected_indices = avatar_listbox.curselection()
if selected_indices:
index = selected_indices[0]
selected_avatar = avatar_listbox.get(index)
if '(' in selected_avatar and ')' in selected_avatar:
id_str = selected_avatar.split('(')[-1].split(')')[0]
selected_avatar_id = id_str
else:
selected_avatar_id = None
else:
selected_avatar_id = None
avatar_listbox.bind('<<ListboxSelect>>', on_avatar_select)
# Function to add selected avatar to lineup
def add_to_lineup():
if selected_avatar_id:
#if selected_avatar_id not in lineup_ids:
lineup_ids.append(selected_avatar_id)
lineup_listbox.insert(tk.END, selected_avatar_id)
update_lineup_command()
#else:
#messagebox.showinfo("Info", "Avatar already in lineup.")
else:
messagebox.showwarning(self.localization["Warning"], "No avatar selected.")
# Function to remove selected avatar from lineup
def remove_from_lineup():
selected_indices = lineup_listbox.curselection()
if selected_indices:
index = selected_indices[0]
avatar_id = lineup_listbox.get(index)
lineup_listbox.delete(index)
lineup_ids.remove(avatar_id)
update_lineup_command()
else:
messagebox.showwarning(self.localization["Warning"], "No avatar selected in lineup.")
# Function to clear the lineup
def clear_lineup():
lineup_listbox.delete(0, tk.END)
lineup_ids.clear()
update_lineup_command()
# Function to update the lineup command
def update_lineup_command():
if lineup_ids:
command = f"/lineup {' '.join(lineup_ids)}"
self.command_manager.update_command(command)
else:
self.command_manager.update_command('')
# Initialize the avatar list
update_avatar_list()
def create_properties_section(self, parent_frame):
# Title
properties_label = tk.Label(parent_frame, text=self.localization["Properties"], font=("Arial", 12, "bold"))
properties_label.pack(pady=5)
# Target selection
target_label = tk.Label(parent_frame, text=self.localization["Target"])
target_label.pack()
target_var = StringVar(value='cur')
target_options = ['cur', 'all', 'lineup']
target_menu = ttk.OptionMenu(parent_frame, target_var, target_options[0], *target_options, command=lambda _: update_properties_command())
target_menu.pack()
# Level
level_label = tk.Label(parent_frame, text=self.localization["Level_(1_80)"])
level_label.pack()
level_var = StringVar(value='1')
level_entry = tk.Entry(parent_frame, textvariable=level_var)
level_entry.pack()
level_var.trace('w', lambda *args: update_properties_command())
# Ascension
ascension_label = tk.Label(parent_frame, text=self.localization["Ascension_(0_6)"])
ascension_label.pack()
ascension_var = StringVar(value='0')
ascension_entry = tk.Entry(parent_frame, textvariable=ascension_var)
ascension_entry.pack()
ascension_var.trace('w', lambda *args: update_properties_command())
# Eidolon
eidolon_label = tk.Label(parent_frame, text=self.localization["Eidolon_(0_6)"])
eidolon_label.pack()
eidolon_var = StringVar(value='0')
eidolon_entry = tk.Entry(parent_frame, textvariable=eidolon_var)
eidolon_entry.pack()
eidolon_var.trace('w', lambda *args: update_properties_command())
# Skill Levels
skill_label = tk.Label(parent_frame, text=self.localization["Skill_Levels_(1_12)"])
skill_label.pack()
skill_var = StringVar(value='1')
skill_entry = tk.Entry(parent_frame, textvariable=skill_var)
skill_entry.pack()
skill_var.trace('w', lambda *args: update_properties_command())
# Function to update the properties command
def update_properties_command():
target = target_var.get()
level = level_var.get()
ascension = ascension_var.get()
eidolon = eidolon_var.get()
skill = skill_var.get()
# Validate inputs
if not level.isdigit() or not (1 <= int(level) <= 80):
self.command_manager.update_command('')
return
if not ascension.isdigit() or not (0 <= int(ascension) <= 6):
self.command_manager.update_command('')
return
if not eidolon.isdigit() or not (0 <= int(eidolon) <= 6):
self.command_manager.update_command('')
return
if not skill.isdigit() or not (1 <= int(skill) <= 12):
self.command_manager.update_command('')
return
command = f"/avatar {target} lv{level} p{ascension} e{eidolon} s{skill}"
self.command_manager.update_command(command)
# Initialize the properties command
update_properties_command()
# Placeholder for 'Give' tab (can be implemented as needed)
# def create_give_tab(self):
# pass