-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtexture_manager_gui.py
More file actions
1366 lines (1096 loc) · 61.9 KB
/
texture_manager_gui.py
File metadata and controls
1366 lines (1096 loc) · 61.9 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import sys
import tkinter as tk
from tkinter import filedialog, messagebox, ttk, scrolledtext
import threading
import traceback
import time
import platform
import subprocess
import json
import shutil
import glob
import webbrowser
from texture_analyzer import TextureAnalyzer, convert_numatb_to_json, convert_numdlb_to_text
import re
def check_ultimate_tex_cli():
"""Check if ultimate_tex_cli.exe exists in the same directory"""
exe_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ultimate_tex_cli.exe")
if not os.path.exists(exe_path):
root = tk.Tk()
root.withdraw()
messagebox.showerror("Missing Dependency",
"ultimate_tex_cli.exe is required but was not found!\n\n"
"Please download it from:\n"
"https://github.com/ScanMountGoat/ultimate-tex-cli/releases\n\n"
"Place ultimate_tex_cli.exe in the same folder as this program.")
webbrowser.open("https://github.com/ScanMountGoat/ultimate-tex-cli/releases")
sys.exit(1)
class TextureManagerApp:
def __init__(self, root):
"""Initialize the Texture Manager application"""
# Check for ultimate_tex_cli.exe before proceeding
check_ultimate_tex_cli()
self.root = root
self.root.title("Texture Manager")
self.root.geometry("1400x850")
# Set window close protocol
self.root.protocol("WM_DELETE_WINDOW", self.quit_application)
# Set application icon if available
try:
self.root.iconbitmap("icon.ico")
except:
pass
# Initialize variables
self.mod_dir = ""
self.selected_fighter = None
self.selected_alt = None
self.selected_optimizer_fighter = None
self.selected_optimizer_alt = None
# Configure styles
style = ttk.Style()
style.configure("TButton", padding=(5, 5))
style.configure("TLabel", padding=(5, 5))
style.configure("TFrame", padding=(5, 5))
# Variables for analyzer
self.mod_dir_var = tk.StringVar()
self.output_dir_var = tk.StringVar(value="texture_analysis")
self.analyze_numdlb_var = tk.BooleanVar(value=True)
self.analyze_txt_var = tk.BooleanVar(value=True)
self.analyze_json_var = tk.BooleanVar(value=True)
self.all_alts_var = tk.BooleanVar(value=False)
self.show_details_var = tk.BooleanVar(value=True)
self.selected_fighter_var = tk.StringVar()
self.selected_alt_var = tk.StringVar()
# Variables for optimizer
self.junk_dir = None
self.fighters = []
self.fighters_alts = {}
# Estado interno
self.analyzer_thread = None
self.mod_directory = None
self.cancel_requested = False
# Create menubar
self.menubar = tk.Menu(self.root)
self.filemenu = tk.Menu(self.menubar, tearoff=0)
self.filemenu.add_command(label="Open Mod Folder", command=self.on_mod_dir_select)
self.filemenu.add_separator()
self.filemenu.add_command(label="Exit", command=self.quit_application)
self.menubar.add_cascade(label="File", menu=self.filemenu)
# Add Help menu
self.helpmenu = tk.Menu(self.menubar, tearoff=0)
self.helpmenu.add_command(label="Open README", command=self.open_readme)
self.menubar.add_cascade(label="Help", menu=self.helpmenu)
self.root.config(menu=self.menubar)
# Crear la interfaz
self.setup_ui()
# Disable tabs until a mod directory is selected
self.notebook.tab(self.analyzer_tab, state="disabled")
self.notebook.tab(self.optimizer_tab, state="disabled")
# Center the window
self.root.update_idletasks()
width = self.root.winfo_width()
height = self.root.winfo_height()
x = (self.root.winfo_screenwidth() // 2) - (width // 2)
y = (self.root.winfo_screenheight() // 2) - (height // 2)
self.root.geometry(f"{width}x{height}+{x}+{y}")
def setup_ui(self):
# Marco principal
main_frame = ttk.Frame(self.root, padding=(10, 10))
main_frame.pack(fill=tk.BOTH, expand=True)
# Título
title_label = ttk.Label(main_frame, text="Texture Manager for Smash Ultimate",
font=("Segoe UI", 14, "bold"))
title_label.pack(pady=(0, 15))
# Sección para seleccionar directorios
dirs_frame = ttk.LabelFrame(main_frame, text="Directories", padding=(10, 5))
dirs_frame.pack(fill=tk.X, pady=5)
# Directorio del mod
mod_dir_frame = ttk.Frame(dirs_frame)
mod_dir_frame.pack(fill=tk.X, pady=5)
ttk.Label(mod_dir_frame, text="Mod directory:").pack(side=tk.LEFT, padx=(0, 5))
ttk.Entry(mod_dir_frame, textvariable=self.mod_dir_var, width=50).pack(side=tk.LEFT, fill=tk.X, expand=True, padx=(0, 5))
ttk.Button(mod_dir_frame, text="Browse...", command=self.on_mod_dir_select).pack(side=tk.LEFT)
ttk.Button(mod_dir_frame, text="Load", command=self.load_fighters).pack(side=tk.LEFT, padx=(5, 0))
# Notebook con pestañas
self.notebook = ttk.Notebook(main_frame)
self.notebook.pack(fill=tk.BOTH, expand=True, pady=5)
# Crear las pestañas
self.analyzer_tab = ttk.Frame(self.notebook)
self.optimizer_tab = ttk.Frame(self.notebook)
self.notebook.add(self.analyzer_tab, text="NUMATB Analyzer")
self.notebook.add(self.optimizer_tab, text="Texture Optimizer")
# Configurar cada pestaña
self.setup_analyzer_tab()
self.setup_optimizer_tab()
# Barra de progreso y estado (compartida)
status_frame = ttk.Frame(main_frame)
status_frame.pack(fill=tk.X, pady=5)
self.status_label = ttk.Label(status_frame, text="Ready")
self.status_label.pack(anchor=tk.W, pady=(0, 2))
self.progress_bar = ttk.Progressbar(status_frame, length=100, mode='determinate')
self.progress_bar.pack(fill=tk.X)
def on_mod_dir_select(self):
"""Handle the selection of the mod directory"""
directory = filedialog.askdirectory(title="Select Mod Directory")
if directory:
self.mod_dir = directory
self.mod_dir_var.set(directory)
# Create junk directory if it doesn't exist
self.junk_dir = os.path.join(directory, "junk")
os.makedirs(self.junk_dir, exist_ok=True)
# Log to both consoles
try:
self.update_console(f"Mod directory set to: {directory}")
except:
pass
try:
self.log_to_optimizer(f"Mod directory set to: {directory}")
except:
pass
# Clear previous data
self.fighter_listbox.delete(0, tk.END)
self.alt_listbox.delete(0, tk.END)
self.optimizer_fighter_listbox.delete(0, tk.END)
self.optimizer_alt_listbox.delete(0, tk.END)
# Load fighters
fighters = self.load_fighters()
for fighter in fighters:
self.fighter_listbox.insert(tk.END, fighter)
self.optimizer_fighter_listbox.insert(tk.END, fighter)
# Enable tabs if we have fighters
if fighters:
self.notebook.tab(self.analyzer_tab, state="normal")
self.notebook.tab(self.optimizer_tab, state="normal")
self.update_console(f"Loaded {len(fighters)} fighters")
self.log_to_optimizer(f"Loaded {len(fighters)} fighters")
else:
self.update_console("No fighters found in the mod directory")
self.log_to_optimizer("No fighters found in the mod directory")
def load_fighters(self):
"""Load all fighters from the mod directory"""
fighters = []
fighter_path = os.path.join(self.mod_dir, "fighter")
if not os.path.exists(fighter_path):
messagebox.showwarning("Invalid Directory", "No fighter directory found in the selected mod directory.")
return []
for fighter in os.listdir(fighter_path):
fighter_dir = os.path.join(fighter_path, fighter)
if os.path.isdir(fighter_dir):
model_dir = os.path.join(fighter_dir, "model")
if os.path.exists(model_dir):
fighters.append(fighter)
return sorted(fighters)
def get_alts(self, fighter):
"""Get all available alts for a fighter"""
alts = []
body_path = os.path.join(self.mod_dir, "fighter", fighter, "model", "body")
if os.path.exists(body_path):
for alt in os.listdir(body_path):
if alt.startswith("c") and alt[1:].isdigit():
alts.append(alt[1:]) # Remove the 'c' prefix
return sorted(alts, key=int)
def on_fighter_select(self, event):
"""Handle fighter selection in the analyzer tab"""
selection = self.fighter_listbox.curselection()
if not selection:
return
fighter = self.fighter_listbox.get(selection[0])
self.selected_fighter_var.set(fighter)
# Update alt list
self.alt_listbox.delete(0, tk.END)
alts = self.get_alts(fighter)
for alt in alts:
self.alt_listbox.insert(tk.END, alt)
def on_alt_select(self, event):
"""Handle alt selection in the analyzer tab"""
selection = self.alt_listbox.curselection()
if not selection:
return
alt = self.alt_listbox.get(selection[0])
self.selected_alt_var.set(alt)
def start_analysis(self):
"""Start texture analysis process"""
mod_dir = self.mod_dir_var.get()
if not mod_dir or not os.path.exists(mod_dir):
messagebox.showerror("Error", "Please select a valid mod directory.")
return
# Verify that it's a Smash mod
fighter_dir = os.path.join(mod_dir, "fighter")
if not os.path.exists(fighter_dir) or not os.path.isdir(fighter_dir):
messagebox.showerror("Error", "The selected directory doesn't appear to be a valid Smash Ultimate mod.")
return
# Verify fighter/alt selection
if not self.all_alts_var.get() and not self.selected_fighter_var.get():
messagebox.showerror("Error", "You must select a fighter to analyze, or enable the 'Include all alts' option.")
return
# Verify alt selection
if not self.all_alts_var.get() and not self.selected_alt_var.get() and self.selected_fighter_var.get():
messagebox.showerror("Error", "You must select an alt to analyze, or enable the 'Include all alts' option.")
return
# Check if analysis is already in progress
if self.analyzer_thread and self.analyzer_thread.is_alive():
messagebox.showinfo("Information", "An analysis is already in progress.")
return
# Reset state
self.cancel_requested = False
# Clear previous results
self.update_console("Starting texture analysis...")
for item in self.results_tree.get_children():
self.results_tree.delete(item)
# Start analysis in a separate thread
self.analyzer_thread = threading.Thread(target=self.analyze_thread)
self.analyzer_thread.daemon = True
self.analyzer_thread.start()
def cancel_analysis(self):
"""Cancel ongoing analysis"""
if self.analyzer_thread and self.analyzer_thread.is_alive():
self.cancel_requested = True
self.update_console("Requesting analysis cancellation...")
else:
messagebox.showinfo("Information", "No analysis in progress.")
def analyze_thread(self):
"""Thread for texture analysis"""
try:
start_time = time.time()
# Prepare output directory
output_dir = self.output_dir_var.get()
if not os.path.isabs(output_dir):
output_dir = os.path.join(self.mod_dir, output_dir)
# Create directory if it doesn't exist
os.makedirs(output_dir, exist_ok=True)
self.update_console(f"Output directory: {output_dir}")
# Determine what to analyze
fighters_to_analyze = {}
if self.all_alts_var.get():
# Analyze all fighters and their alts
fighters = self.load_fighters()
for fighter in fighters:
alts = self.get_alts(fighter)
fighters_to_analyze[fighter] = [f"c{alt}" for alt in alts] # Add the 'c' prefix back
self.update_console(f"Analyzing all fighters ({len(fighters_to_analyze)}) and their alts.")
else:
# Analyze only the selected fighter and alt
selected_fighter = self.selected_fighter_var.get()
selected_alt = self.selected_alt_var.get()
if selected_fighter and selected_alt:
fighters_to_analyze = {selected_fighter: [f"c{selected_alt}"]} # Add the 'c' prefix back
self.update_console(f"Analyzing only {selected_fighter} - alt c{selected_alt}")
else:
self.update_console("Error: No valid fighter/alt selected.")
self.update_status("Analysis cancelled - Invalid selection")
return
# Initialize analyzer with the mod directory
analyzer = TextureAnalyzer(self.mod_dir)
# Analysis results
analysis_results = []
# Count total paths for progress
total_paths = sum(len(alts) for alts in fighters_to_analyze.values())
current_path = 0
self.update_progress(0, total_paths)
# Process each fighter
for fighter, alts in fighters_to_analyze.items():
self.update_console(f"\nAnalyzing fighter: {fighter}")
for alt in alts:
if self.cancel_requested:
self.update_console("Analysis cancelled by user.")
self.update_status("Analysis cancelled")
return
self.update_status(f"Analyzing {fighter} - {alt}...")
self.update_console(f" Processing alt: {alt}")
# Create directory for results
alt_output_dir = os.path.join(output_dir, fighter, alt)
os.makedirs(alt_output_dir, exist_ok=True)
# Collect files for this alt
model_paths, etc_paths = self.get_alt_files(fighter, alt)
numatb_files = [f for f in model_paths if f.endswith('.numatb')]
numdlb_files = [f for f in model_paths if f.endswith('.numdlb')]
self.update_console(f" - NUMATB files found: {len(numatb_files)}")
self.update_console(f" - NUMDLB files found: {len(numdlb_files)}")
# Convert files to readable formats
if numatb_files and self.analyze_json_var.get():
self.update_console(" Converting NUMATB files to JSON...")
for matl_file in numatb_files:
json_path = convert_numatb_to_json(matl_file, alt_output_dir)
if json_path:
rel_path = os.path.relpath(json_path, output_dir)
self.update_console(f" ✓ {os.path.basename(matl_file)} → {os.path.basename(json_path)}")
analysis_results.append({
"fighter": fighter,
"file": os.path.basename(matl_file),
"type": "Material (JSON)",
"path": rel_path
})
if numdlb_files and self.analyze_numdlb_var.get() and self.analyze_txt_var.get():
self.update_console(" Converting NUMDLB files to TXT...")
for modl_file in numdlb_files:
txt_path = convert_numdlb_to_text(modl_file, alt_output_dir)
if txt_path:
rel_path = os.path.relpath(txt_path, output_dir)
self.update_console(f" ✓ {os.path.basename(modl_file)} → {os.path.basename(txt_path)}")
analysis_results.append({
"fighter": fighter,
"file": os.path.basename(modl_file),
"type": "Model (TXT)",
"path": rel_path
})
# Analyze to find texture references (optional)
if self.show_details_var.get():
self.update_console(" Analyzing texture references...")
refs, texture_files = analyzer.analyze_alt(
fighter,
model_paths,
etc_paths,
analyze_numatb=True,
analyze_nuanmb=False,
analyze_numdlb=self.analyze_numdlb_var.get(),
convert_to_json=self.analyze_json_var.get() and alt_output_dir,
convert_to_txt=self.analyze_txt_var.get() and alt_output_dir
)
self.update_console(f" - Texture references found: {len(refs)}")
# Show file types found
if texture_files:
file_types = {}
for file_path in texture_files:
ext = os.path.splitext(file_path)[1].lower()
file_types[ext] = file_types.get(ext, 0) + 1
self.update_console(" - File types found:")
for ext, count in sorted(file_types.items()):
self.update_console(f" {ext}: {count}")
# Update progress
current_path += 1
self.update_progress(current_path, total_paths)
# Calculate elapsed time
elapsed_time = time.time() - start_time
# Update results table
self.update_results_table(analysis_results)
# Final message
if analysis_results:
self.update_console(f"\nAnalysis completed in {elapsed_time:.2f} seconds.")
self.update_console(f"Processed {len(analysis_results)} files.")
self.update_console(f"Converted files are in: {output_dir}")
self.update_status(f"Analysis completed - {len(analysis_results)} files")
else:
self.update_console("\nNo files were processed. Check the selected options.")
self.update_status("Analysis completed - No files processed")
except Exception as e:
error_msg = f"Analysis error: {str(e)}\n{traceback.format_exc()}"
self.update_console(error_msg)
self.update_status("Analysis error")
finally:
self.set_ui_state(True) # Re-enable controls
def update_status(self, message):
"""Update the status label"""
self.status_label.config(text=message)
self.root.update_idletasks()
def update_progress(self, current, total):
"""Update the progress bar"""
if total > 0:
progress = (current / total) * 100
self.progress_bar["value"] = progress
else:
self.progress_bar["value"] = 0
self.root.update_idletasks()
def update_console(self, message):
"""Update the console in the analyzer tab"""
try:
self.analyzer_console.config(state=tk.NORMAL)
self.analyzer_console.insert(tk.END, message + "\n")
self.analyzer_console.see(tk.END)
self.analyzer_console.config(state=tk.DISABLED)
self.root.update_idletasks()
except Exception as e:
print(f"Error updating console: {e}")
def update_results_table(self, results):
# Limpiar tabla
for item in self.results_tree.get_children():
self.results_tree.delete(item)
# Insertar resultados
for result in results:
self.results_tree.insert("", "end", values=(
result["fighter"],
result["file"],
result["type"],
result["path"]
))
def open_file_from_results(self, event):
"""Open the selected file from results tree"""
selected = self.results_tree.selection()
if not selected:
return
item_values = self.results_tree.item(selected, "values")
if len(item_values) < 4:
return
# Get the full path
output_dir = self.output_dir_var.get()
if not os.path.isabs(output_dir):
output_dir = os.path.join(self.mod_dir, output_dir)
file_path = os.path.join(output_dir, item_values[3])
# Verify file exists
if os.path.exists(file_path):
# Open with default application
if platform.system() == 'Windows':
os.startfile(file_path)
elif platform.system() == 'Darwin': # macOS
subprocess.call(('open', file_path))
else: # Linux
subprocess.call(('xdg-open', file_path))
else:
self.update_console(f"Error: Could not find file {file_path}")
def set_ui_state(self, enabled):
"""Enable or disable UI elements during processing"""
state = tk.NORMAL if enabled else tk.DISABLED
# Try to update UI elements safely
try:
# Update analyzer tab controls
widgets = [
self.fighter_listbox,
self.alt_listbox,
self.analyzer_console,
self.results_tree
]
for widget in widgets:
if hasattr(widget, 'state'):
# For ttk widgets, use '!disabled' or 'disabled'
widget.state(['!disabled' if enabled else 'disabled'])
elif hasattr(widget, 'config'):
try:
widget.config(state=state)
except:
pass
except Exception as e:
print(f"Error updating UI state: {e}")
def detect_fighters_and_alts(self):
"""Detectar luchadores y alts en el mod"""
fighters_alts = {}
fighter_dir = os.path.join(self.mod_directory, "fighter")
# Verificar que existe el directorio fighter
if not os.path.exists(fighter_dir):
return fighters_alts
# Buscar directorios de luchadores
for fighter in os.listdir(fighter_dir):
fighter_path = os.path.join(fighter_dir, fighter)
if not os.path.isdir(fighter_path):
continue
model_dir = os.path.join(fighter_path, "model")
if not os.path.exists(model_dir):
continue
# Buscar alts basados en carpetas dentro del directorio model
alts = []
for root, dirs, files in os.walk(model_dir):
dir_name = os.path.basename(root)
# Patrones comunes para alts
if dir_name.startswith("c") and dir_name[1:].isdigit():
if dir_name not in alts:
alts.append(dir_name)
# Si no se encontraron alts con el patrón, buscar archivos
if not alts:
alt_patterns = set()
for root, dirs, files in os.walk(model_dir):
for file in files:
if file.endswith((".numatb", ".numdlb")):
parts = file.split("/")
for part in parts:
if part.startswith("c") and len(part) > 1 and part[1:].isdigit():
alt_patterns.add(part)
alts = sorted(list(alt_patterns))
# Si aún no hay alts, usar "c00" como predeterminado
if not alts:
alts = ["c00"]
fighters_alts[fighter] = sorted(alts)
return fighters_alts
def get_alt_files(self, fighter, alt):
"""Get all files for a specific alt"""
model_paths = []
etc_paths = []
fighter_dir = os.path.join(self.mod_dir, "fighter", fighter)
model_dir = os.path.join(fighter_dir, "model")
# Look for model files
for root, dirs, files in os.walk(model_dir):
if alt in root:
for file in files:
if file.endswith(".numatb"):
model_paths.append(os.path.join(root, file))
elif file.endswith(".numdlb") and self.analyze_numdlb_var.get():
model_paths.append(os.path.join(root, file))
# If no files found in alt folders, look for files with alt in the name
if not model_paths:
for root, dirs, files in os.walk(model_dir):
for file in files:
if alt in file:
if file.endswith(".numatb"):
model_paths.append(os.path.join(root, file))
elif file.endswith(".numdlb") and self.analyze_numdlb_var.get():
model_paths.append(os.path.join(root, file))
# Look for other files like textures
for root, dirs, files in os.walk(fighter_dir):
if alt in root and "model" not in root:
for file in files:
if file.endswith((".nutexb", ".numshb")):
etc_paths.append(os.path.join(root, file))
return model_paths, etc_paths
def setup_analyzer_tab(self):
"""Configura la pestaña del analizador de texturas"""
analyzer_frame = ttk.Frame(self.analyzer_tab, padding=(10, 5))
analyzer_frame.pack(fill=tk.BOTH, expand=True)
# Directorio de salida
output_dir_frame = ttk.Frame(analyzer_frame)
output_dir_frame.pack(fill=tk.X, pady=5)
ttk.Label(output_dir_frame, text="Output directory:").pack(side=tk.LEFT, padx=(0, 5))
ttk.Entry(output_dir_frame, textvariable=self.output_dir_var, width=50).pack(side=tk.LEFT, fill=tk.X, expand=True, padx=(0, 5))
ttk.Button(output_dir_frame, text="Browse...", command=self.browse_output_dir).pack(side=tk.LEFT)
# Sección para selección de personaje/alt
fighter_frame = ttk.LabelFrame(analyzer_frame, text="Fighter and Alt Selection", padding=(10, 5))
fighter_frame.pack(fill=tk.X, pady=5)
# Layout con dos columnas para listas
fighter_lists_frame = ttk.Frame(fighter_frame)
fighter_lists_frame.pack(fill=tk.X, pady=5)
# Lista de luchadores (izquierda)
fighter_list_frame = ttk.Frame(fighter_lists_frame)
fighter_list_frame.pack(side=tk.LEFT, fill=tk.X, expand=True, padx=(0, 5))
ttk.Label(fighter_list_frame, text="Fighter:").pack(anchor=tk.W)
# Lista y scrollbar
fighter_select_frame = ttk.Frame(fighter_list_frame)
fighter_select_frame.pack(fill=tk.BOTH, expand=True)
self.fighter_listbox = tk.Listbox(fighter_select_frame, height=5)
fighter_scrollbar = ttk.Scrollbar(fighter_select_frame, orient=tk.VERTICAL, command=self.fighter_listbox.yview)
self.fighter_listbox.configure(yscrollcommand=fighter_scrollbar.set)
self.fighter_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
fighter_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# Vincular selección
self.fighter_listbox.bind("<<ListboxSelect>>", self.on_fighter_select)
# Lista de alts (derecha)
alt_list_frame = ttk.Frame(fighter_lists_frame)
alt_list_frame.pack(side=tk.RIGHT, fill=tk.X, expand=True, padx=(5, 0))
ttk.Label(alt_list_frame, text="Alt:").pack(anchor=tk.W)
# Lista y scrollbar
alt_select_frame = ttk.Frame(alt_list_frame)
alt_select_frame.pack(fill=tk.BOTH, expand=True)
self.alt_listbox = tk.Listbox(alt_select_frame, height=5)
alt_scrollbar = ttk.Scrollbar(alt_select_frame, orient=tk.VERTICAL, command=self.alt_listbox.yview)
self.alt_listbox.configure(yscrollcommand=alt_scrollbar.set)
self.alt_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
alt_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# Vincular selección
self.alt_listbox.bind("<<ListboxSelect>>", self.on_alt_select)
# Opciones de análisis
options_frame = ttk.LabelFrame(analyzer_frame, text="Analysis Options", padding=(10, 5))
options_frame.pack(fill=tk.X, pady=5)
# Primera fila - Tipos de archivos
file_types_frame = ttk.Frame(options_frame)
file_types_frame.pack(fill=tk.X, pady=5)
ttk.Label(file_types_frame, text="Analyze files:").pack(side=tk.LEFT, padx=(0, 10))
ttk.Checkbutton(file_types_frame, text="NUMATB (Materials)", state=tk.DISABLED, variable=tk.BooleanVar(value=True)).pack(side=tk.LEFT, padx=5)
ttk.Checkbutton(file_types_frame, text="NUMDLB (Models)", variable=self.analyze_numdlb_var).pack(side=tk.LEFT, padx=5)
# Segunda fila - Formatos de salida
output_types_frame = ttk.Frame(options_frame)
output_types_frame.pack(fill=tk.X, pady=5)
ttk.Label(output_types_frame, text="Generate:").pack(side=tk.LEFT, padx=(0, 10))
ttk.Checkbutton(output_types_frame, text="TXT Files", variable=self.analyze_txt_var).pack(side=tk.LEFT, padx=5)
ttk.Checkbutton(output_types_frame, text="JSON Files", variable=self.analyze_json_var).pack(side=tk.LEFT, padx=5)
# Tercera fila - Otras opciones
other_options_frame = ttk.Frame(options_frame)
other_options_frame.pack(fill=tk.X, pady=5)
ttk.Checkbutton(other_options_frame, text="Include all alts", variable=self.all_alts_var).pack(side=tk.LEFT, padx=5)
ttk.Checkbutton(other_options_frame, text="Show details", variable=self.show_details_var).pack(side=tk.LEFT, padx=5)
# Nota informativa
note_text = "Note: This analyzer processes .numatb and .numdlb files, generating readable versions for analysis."
note_label = ttk.Label(options_frame, text=note_text, font=("Segoe UI", 9, "italic"), foreground="gray")
note_label.pack(fill=tk.X, pady=5)
# Botones de acción
buttons_frame = ttk.Frame(analyzer_frame)
buttons_frame.pack(fill=tk.X, pady=10)
ttk.Button(buttons_frame, text="Analyze Files", command=self.start_analysis).pack(side=tk.LEFT, padx=5)
ttk.Button(buttons_frame, text="Cancel", command=self.cancel_analysis).pack(side=tk.LEFT, padx=5)
# Tabla de resultados y consola
results_frame = ttk.Frame(analyzer_frame)
results_frame.pack(fill=tk.BOTH, expand=True, pady=5)
# Tabla de resultados (izquierda)
table_frame = ttk.LabelFrame(results_frame, text="Results", padding=(5, 5))
table_frame.pack(fill=tk.BOTH, expand=True, side=tk.LEFT, padx=(0, 5))
# Crear tabla
self.results_tree = ttk.Treeview(table_frame, columns=("fighter", "file", "type", "path"),
show="headings", selectmode="browse")
# Configurar columnas
self.results_tree.heading("fighter", text="Fighter")
self.results_tree.heading("file", text="File")
self.results_tree.heading("type", text="Type")
self.results_tree.heading("path", text="Path")
self.results_tree.column("fighter", width=100)
self.results_tree.column("file", width=150)
self.results_tree.column("type", width=100)
self.results_tree.column("path", width=200)
# Doble clic para abrir archivo
self.results_tree.bind("<Double-1>", self.open_file_from_results)
# Scrollbar para la tabla
table_scroll = ttk.Scrollbar(table_frame, orient=tk.VERTICAL, command=self.results_tree.yview)
self.results_tree.configure(yscrollcommand=table_scroll.set)
table_scroll.pack(side=tk.RIGHT, fill=tk.Y)
self.results_tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# Consola de salida (derecha)
console_frame = ttk.LabelFrame(results_frame, text="Console", padding=(5, 5))
console_frame.pack(fill=tk.BOTH, expand=True, side=tk.RIGHT, padx=(5, 0))
self.analyzer_console = scrolledtext.ScrolledText(console_frame, wrap=tk.WORD, height=10)
self.analyzer_console.pack(fill=tk.BOTH, expand=True)
self.analyzer_console.config(state=tk.DISABLED)
def setup_optimizer_tab(self):
"""Configura la pestaña del optimizador de texturas"""
optimizer_frame = ttk.Frame(self.optimizer_tab, padding=(10, 5))
optimizer_frame.pack(fill=tk.BOTH, expand=True)
# Panel de selección (izquierda)
selection_frame = ttk.LabelFrame(optimizer_frame, text="Fighter and Alt Selection", padding=(10, 5))
selection_frame.pack(side=tk.LEFT, fill=tk.Y, padx=(0, 5), pady=5)
# Lista de luchadores
fighter_frame = ttk.Frame(selection_frame)
fighter_frame.pack(fill=tk.BOTH, expand=True, pady=5)
ttk.Label(fighter_frame, text="Fighter:").pack(anchor=tk.W)
self.optimizer_fighter_listbox = tk.Listbox(fighter_frame, height=10, width=20)
self.optimizer_fighter_listbox.pack(fill=tk.BOTH, expand=True)
self.optimizer_fighter_listbox.bind("<<ListboxSelect>>", self.on_optimizer_fighter_select)
# Lista de alts
alt_frame = ttk.Frame(selection_frame)
alt_frame.pack(fill=tk.BOTH, expand=True, pady=5)
ttk.Label(alt_frame, text="Alt:").pack(anchor=tk.W)
self.optimizer_alt_listbox = tk.Listbox(alt_frame, height=10, width=20)
self.optimizer_alt_listbox.pack(fill=tk.BOTH, expand=True)
self.optimizer_alt_listbox.bind("<<ListboxSelect>>", self.on_optimizer_alt_select)
# Botones de acción
actions_frame = ttk.Frame(selection_frame)
actions_frame.pack(fill=tk.X, pady=10)
ttk.Button(actions_frame, text="Analyze", command=self.analyze_optimizer_selected).pack(fill=tk.X, pady=2)
ttk.Button(actions_frame, text="Optimize", command=self.optimize_selected).pack(fill=tk.X, pady=2)
ttk.Button(actions_frame, text="Optimize All Alts", command=self.optimize_all_alts).pack(fill=tk.X, pady=2)
ttk.Button(actions_frame, text="Restore", command=self.restore_junk).pack(fill=tk.X, pady=2)
ttk.Button(actions_frame, text="Delete Files for Analysis", command=self.clean_analysis_files).pack(fill=tk.X, pady=2)
# Panel de resultados (derecha)
results_frame = ttk.Frame(optimizer_frame)
results_frame.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True, padx=(5, 0), pady=5)
# Tabla de texturas
table_frame = ttk.LabelFrame(results_frame, text="Textures", padding=(5, 5))
table_frame.pack(fill=tk.BOTH, expand=True, pady=5)
columns = ("texture", "status", "size")
self.texture_tree = ttk.Treeview(table_frame, columns=columns, show="headings", selectmode="browse")
self.texture_tree.heading("texture", text="Texture")
self.texture_tree.heading("status", text="Status")
self.texture_tree.heading("size", text="Size")
self.texture_tree.column("texture", width=300)
self.texture_tree.column("status", width=100)
self.texture_tree.column("size", width=80)
# Scrollbars para la tabla
tree_scroll_y = ttk.Scrollbar(table_frame, orient=tk.VERTICAL, command=self.texture_tree.yview)
self.texture_tree.configure(yscrollcommand=tree_scroll_y.set)
tree_scroll_x = ttk.Scrollbar(table_frame, orient=tk.HORIZONTAL, command=self.texture_tree.xview)
self.texture_tree.configure(xscrollcommand=tree_scroll_x.set)
tree_scroll_y.pack(side=tk.RIGHT, fill=tk.Y)
tree_scroll_x.pack(side=tk.BOTTOM, fill=tk.X)
self.texture_tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# Consola de salida
console_frame = ttk.LabelFrame(results_frame, text="Console", padding=(5, 5))
console_frame.pack(fill=tk.BOTH, expand=True, pady=5)
self.optimizer_console = scrolledtext.ScrolledText(console_frame, wrap=tk.WORD, height=10)
self.optimizer_console.pack(fill=tk.BOTH, expand=True)
self.optimizer_console.config(state=tk.DISABLED)
# Estadísticas
stats_frame = ttk.LabelFrame(results_frame, text="Statistics")
stats_frame.pack(fill=tk.X, pady=5)
self.stats_text = ttk.Label(stats_frame, text="No data available")
self.stats_text.pack(fill=tk.X, pady=5, padx=5)
def on_optimizer_fighter_select(self, event):
"""Handle fighter selection in the optimizer tab"""
selection = self.optimizer_fighter_listbox.curselection()
if not selection:
return
self.optimizer_alt_listbox.delete(0, tk.END)
fighter = self.optimizer_fighter_listbox.get(selection[0])
self.selected_optimizer_fighter = fighter
for alt in self.get_alts(fighter):
self.optimizer_alt_listbox.insert(tk.END, alt)
# Select the first alt by default
if self.optimizer_alt_listbox.size() > 0:
self.optimizer_alt_listbox.selection_set(0)
self.on_optimizer_alt_select(None)
def on_optimizer_alt_select(self, event):
"""Handle alt selection in the optimizer tab"""
selection = self.optimizer_alt_listbox.curselection()
if not selection:
return
alt = self.optimizer_alt_listbox.get(selection[0])
self.selected_optimizer_alt = alt
def analyze_optimizer_selected(self):
"""Analyze textures for the selected fighter and alt in optimizer tab"""
if not hasattr(self, 'selected_optimizer_fighter') or not hasattr(self, 'selected_optimizer_alt'):
messagebox.showwarning("Selection Required", "Please select a fighter and alt first.")
return
if not self.selected_optimizer_fighter or not self.selected_optimizer_alt:
messagebox.showwarning("Selection Required", "Please select a fighter and alt first.")
return
# Clear previous results
self.texture_tree.delete(*self.texture_tree.get_children())
self.optimizer_console.config(state=tk.NORMAL)
self.optimizer_console.delete(1.0, tk.END)
self.optimizer_console.config(state=tk.DISABLED)
# Clear statistics
self.stats_text.config(text="No data available")
self.log_to_optimizer(f"Analyzing textures for {self.selected_optimizer_fighter} (alt {self.selected_optimizer_alt})...")
# Check if texture analysis data exists
output_dir = self.output_dir_var.get()
if not os.path.isabs(output_dir):
output_dir = os.path.join(self.mod_dir, output_dir)
fighter = self.selected_optimizer_fighter
alt = f"c{self.selected_optimizer_alt}"
analysis_dir = os.path.join(output_dir, fighter, alt)
if not os.path.exists(analysis_dir) or not glob.glob(os.path.join(analysis_dir, "*.json")):
self.log_to_optimizer(f"No texture analysis data found for {fighter}/{alt}")
self.log_to_optimizer("--------------------------------------------")
self.log_to_optimizer("Please run the NUMATB Analyzer first:")
self.log_to_optimizer("1. Switch to the NUMATB Analyzer tab")
self.log_to_optimizer(f"2. Select {fighter} and alt {self.selected_optimizer_alt}")
self.log_to_optimizer("3. Click 'Analyze Files'")
self.log_to_optimizer("4. Come back to this tab and try again")
self.log_to_optimizer("--------------------------------------------")
return
# Path to model/body for this alt
body_dir = os.path.join(self.mod_dir, "fighter", self.selected_optimizer_fighter, "model", "body", f"c{self.selected_optimizer_alt}")
# Check if the directory exists
if not os.path.exists(body_dir):
self.log_to_optimizer(f"Directory not found: {body_dir}")
self.log_to_optimizer("This alt might not have specific textures. Trying other locations...")
# Look for textures in other locations like model/
model_dir = os.path.join(self.mod_dir, "fighter", self.selected_optimizer_fighter, "model")
if os.path.exists(model_dir):
self.log_to_optimizer(f"Searching in {model_dir}...")
textures = []
for root, dirs, files in os.walk(model_dir):
for file in files:
if file.endswith(".nutexb") and f"c{self.selected_optimizer_alt}" in root:
textures.append(os.path.join(root, file))
if not textures:
# If still no textures found, check if filenames contain the alt number
for root, dirs, files in os.walk(model_dir):
for file in files:
if file.endswith(".nutexb") and f"c{self.selected_optimizer_alt}" in file:
textures.append(os.path.join(root, file))
if textures:
self.log_to_optimizer(f"Found {len(textures)} textures in other locations")
else:
self.log_to_optimizer("No textures found for this alt. Please select a different fighter or alt.")
return
else:
self.log_to_optimizer("No valid model directory found for this fighter.")
return
else:
# Get textures from the fighter directory
textures = self.get_textures_in_directory(body_dir)
self.log_to_optimizer(f"Found {len(textures)} textures in {body_dir}")
if not textures:
self.log_to_optimizer("No textures found for this alt. Please select a different fighter or alt.")
return
# Get NUMATB files to identify actually used textures
model_files = self.get_model_files(self.selected_optimizer_fighter, self.selected_optimizer_alt)
used_textures = self.get_used_textures(model_files)
# Update the treeview
total_size = 0
used_size = 0
unused_size = 0
for texture in textures:
texture_name = os.path.basename(texture)
texture_size = os.path.getsize(texture)
total_size += texture_size
# Check if this texture is used by any material
is_used = any(used_name == texture_name for used_name in used_textures)
if not is_used:
# Try partial matching with texture base name (without extension)
texture_basename = os.path.splitext(texture_name)[0]
is_used = any(used_name.startswith(texture_basename) for used_name in used_textures)