-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMME_NDS.py
More file actions
5153 lines (4808 loc) · 334 KB
/
MME_NDS.py
File metadata and controls
5153 lines (4808 loc) · 334 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
from PyQt6 import QtGui, QtWidgets, QtCore#, QtMultimedia Qt6, Qt6.qsci
from pathlib import Path
import sys, os, platform, re, math
import argparse
import traceback
import bisect
#import logging, time, random
import ndspy
#import ndspy.graphics2D
#import ndspy.model
import ndspy.lz10
import ndspy.rom, ndspy.codeCompression, ndspy.code
import ndspy.soundArchive
import ndspy.soundSequenceArchive
import lib
try:
import matplotlib.pyplot as pyplt#, matplotlib.backends.backend_qtagg as qtagg
except ImportError:
pass
PATH_ROOT = Path(__file__).resolve().parent
lib.ini_rw.ini_dir = PATH_ROOT
parser = argparse.ArgumentParser()
parser.add_argument("-R", "--ROM", help="NDS ROM to open using the editor.", dest="openPath")
args = parser.parse_args()
"""
class ThreadSignals(QtCore.QObject): # signals can omly be emmited by QObject
valueChanged = QtCore.pyqtSignal(int)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class RunnableDisplayProgress(QtCore.QRunnable):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.signals = ThreadSignals()
def run(self):
print("runnable active")
value = 0
while value < 100:
self.signals.valueChanged.emit(value)
time.sleep(0.5)
value += 10
QtCore.QMetaObject.invokeMethod(w.progress, "close", QtCore.Qt.ConnectionType.QueuedConnection)
QtCore.QMetaObject.invokeMethod(w.progress, "setValue", QtCore.Qt.ConnectionType.QueuedConnection, QtCore.Q_ARG(int, 0))
print("runnable finish")
"""
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
# expected module versions
self.VERSION_EDITOR = "0.4.6" # objective, feature, WIP
self.VERSION_PYTHON = "3.14.3"
self.VERSION_PYQT = "6.11.0"
self.VERSION_NDSPY = "4.2.0"
self.window_width = 1024
self.window_height = 720
self.setWindowIcon(QtGui.QIcon(str(PATH_ROOT / 'icons/appicon')))
self.setWindowTitle("Mega Man ZX Editor")
self.temp_path = str(PATH_ROOT / "temp/")
self.rom = None #ndspy.rom.NintendoDSRom # placeholder definitions
self.isGameSupported = False
self.gamedat = None
self.rom_fat = [] # list of file addresses (see loadFat())
self.sdats: list[ndspy.soundArchive.SDAT] = [] #ndspy.soundArchive.SDAT
self.base_address = 0
self.relative_address = 0
self.romToEdit_name = ''
self.romToEdit_ext = ''
self.romToEdit_path = '' # for overwrite save
self.fileToEdit_name = ''
self.fileDisplayRaw = False # Display file in 'raw'(hex) format. Else, displayed in readable format
self.fileDisplayMode = "Adapt" # Modes: Adapt, Binary, Dialogue, Graphics, Font, Sound, Movie, Code
self.fileDisplayState = "None" # Same states as mode
self.widget_set = "Empty" # Empty, Text, Graphics, Font, Sound, VX
self.GFX_PALETTES = [
[0xff000000+((0x0b7421*i)%0x1000000) for i in range(256)], # default
[0xff000000, 0xffffffff]*128, # font
[0xff639c6b, 0xff426b9c, 0xff42a5c6, 0xff84c6e7, 0xffbdefff, 0xffdeffef, 0xffb58cff, 0xffefc6ff, # generic
0xffffdeff, 0xfff70010, 0xfff76310, 0xfff79410, 0xfff7c600, 0xfff7f710, 0xfff7f794, 0xffffffff,
0xff7b8463, 0xff102163, 0xff395294, 0xff949cc6, 0xffd6def7, 0xffffffff, 0xff9c0029, 0xfff7394a, # ZX
0xffff9484, 0xff108c73, 0xffffce18, 0xffffff8c, 0xffffd6bd, 0xffd68410, 0xff8c4a00, 0xff39e7c6,
0xff000000, 0xffc6f7ff, 0xffbdd6ff, 0xffa5adf7, 0xff8c7be7, 0xff7352de, 0xff5a29ce, 0xff4200c6, # PX shield
0xff6b10ce, 0xff8c21de, 0xffb531ef, 0xffde4aff, 0xfff763ff, 0xffff9cff, 0xffffd6ff, 0xffffffff,
0xff000000, 0xffc6f7ff, 0xffbdd6ff, 0xffa5adf7, 0xff8c7be7, 0xff7352de, 0xff5a29ce, 0xff4200c6, # PX shield
0xff6b10ce, 0xff8c21de, 0xffb531ef, 0xffde4aff, 0xfff763ff, 0xffff9cff, 0xffffd6ff, 0xffffffff]*4, # sprites
[0xff000000+((0x010101*i)%0x1000000) for i in range(256)], # 8bpp
[0xff000000+((0x010101*i)%0x1000000) if i not in [0,255] else 0xffff00dd if i != 255 else 0xff000000 for i in range(256)], # cutscene
]
self.gfx_palette = self.GFX_PALETTES[0]
self.fileEdited_object = None
self.levelEdited_ovlTable = {"entity slot": [], "entity coord": [], "level": []}
self.levelEdited_ovl_object = None
self.levelEdited_object = None
self.resize(self.window_width, self.window_height)
# Default Preferences
self.theme_index = 0
self.displayBase = 16
self.displayBase_old = 16
self.displayAlphanumeric = True
self.firstLaunch = True
self.fastLevel = False
self.load_preferences()
self.UiComponents()
self.show()
if args.openPath != None:
self.loadROM(args.openPath)
def load_preferences(self):
lib.ini_rw.read(self, "SETTINGS", property_type="int", exc=["displayAlphanumeric"])
lib.ini_rw.read(self, "SETTINGS", property_type="bool", inc=["displayAlphanumeric"])
lib.ini_rw.read(self, "PERFORMANCE", property_type="bool", inc=["fastLevel"])
lib.ini_rw.read(self, "MISC", property_type="bool")
if self.firstLaunch:
firstLaunch_dialog = QtWidgets.QMessageBox()
firstLaunch_dialog.setWindowTitle("Mega Man ZX Editor - First Launch")
firstLaunch_dialog.setWindowIcon(QtGui.QIcon(str(PATH_ROOT / 'icons/information')))
firstLaunch_dialog.setTextFormat(QtCore.Qt.TextFormat.MarkdownText)
firstLaunch_dialog.setText(f"""Thank you for trying out Mega Man ZX Editor!
\rThe current version is {self.VERSION_EDITOR}."""
)
firstLaunch_dialog.setInformativeText(f"""Editor's current features ({self.VERSION_EDITOR.split('.')[1]}):
\r- Dialogue text editor
\r- Patcher(not many patches available yet)
\r- Graphics editor
\r- Font editor
\rWIP ({self.VERSION_EDITOR.split('.')[2]}):
\r- Sound data editor
\r- VX file editor
\r- OAM editor
\r- Level editor
\r- Dialogue name editor
\r- 3D Model editor""")
#firstLaunch_dialog.setDetailedText("abc")
firstLaunch_dialog.exec()
def widgetIcon_update(self, widget: QtWidgets.QWidget, checkedicon: QtGui.QImage, uncheckedicon: QtGui.QImage):
if widget.isChecked():
widget.setIcon(checkedicon)
else:
widget.setIcon(uncheckedicon)
def UiComponents(self):
# reusable
self.window_progress = QtWidgets.QMdiSubWindow()
self.window_progress.setWindowFlags(QtCore.Qt.WindowType.Window | QtCore.Qt.WindowType.CustomizeWindowHint | QtCore.Qt.WindowType.WindowStaysOnTopHint | QtCore.Qt.WindowType.FramelessWindowHint)
self.window_progress.resize(250, 35)
self.window_progress.setWindowTitle("Progress")
#self.window_progress.layout().addWidget(self.label_progress)
self.progress = QtWidgets.QProgressBar(self.window_progress)
self.layout_progress_title = QtWidgets.QHBoxLayout()
self.label_progress_title = QtWidgets.QLabel(self.window_progress)
self.label_progress_icon = QtWidgets.QLabel(self.window_progress)
self.label_progress = QtWidgets.QLabel(self.window_progress)
self.layout_progress_title.addWidget(self.label_progress_icon)
self.layout_progress_title.addWidget(self.label_progress_title)
self.window_progress.layout().addItem(self.layout_progress_title)
self.window_progress.layout().addWidget(self.progress)
self.window_progress.layout().addWidget(self.label_progress)
# Menus
self.openAction = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/folder-horizontal-open')), '&Open', self)
self.openAction.setShortcut('Ctrl+O')
self.openAction.setStatusTip('Open ROM')
self.openAction.triggered.connect(self.openCall)
self.saveAction = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/disk')), '&Save', self)
self.saveAction.setShortcut('Ctrl+S')
self.saveAction.setStatusTip('Save ROM')
self.saveAction.triggered.connect(self.saveCall)
self.saveAction.setDisabled(True)
self.exportAction = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/blueprint--arrow')), '&Export...', self)
self.exportAction.setShortcut('Ctrl+E')
self.exportAction.setStatusTip('Export file in binary or converted format')
self.exportAction.triggered.connect(lambda: self.exportCall(self.tree.currentItem()))
self.exportAction.setDisabled(True)
self.replaceAction = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/blue-document-import')), '&Replace...', self)
self.replaceAction.setShortcut('Ctrl+R')
self.replaceAction.setStatusTip('Replace with file in binary or converted format')
self.replaceAction.triggered.connect(lambda: self.replaceCall(self.tree.currentItem()))
self.replaceAction.setDisabled(True)
self.replacebynameAction = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/blue-document-import')), '&Replace by name...', self)
self.replacebynameAction.setStatusTip('Replace with file of same name in binary or converted format')
self.replacebynameAction.triggered.connect(self.replacebynameCall)
self.menu_bar = self.menuBar()
self.fileMenu = self.menu_bar.addMenu('&File')
self.fileMenu.addActions([self.openAction, self.saveAction, self.exportAction])
self.importSubmenu = self.fileMenu.addMenu('&Import...')
#self.importSubmenu.setStatusTip('Use external file to replace a file in ROM')
self.importSubmenu.setIcon(QtGui.QIcon(str(PATH_ROOT / 'icons/blue-document-import')))
self.importSubmenu.addActions([self.replaceAction, self.replacebynameAction])
self.importSubmenu.setDisabled(True)
self.dialog_about = QtWidgets.QDialog(self)
self.dialog_about.setWindowIcon(QtGui.QIcon(str(PATH_ROOT / 'icons/information')))
self.dialog_about.setWindowTitle("About Mega Man ZX Editor")
self.dialog_about.resize(500, 500)
self.text_about = QtWidgets.QTextBrowser(self.dialog_about)
self.text_about.resize(self.dialog_about.width(), self.dialog_about.height())
self.text_about.setText(f"""Supports:\
\rMEGAMANZX (Mega Man ZX)\
\rROCKMANZX (ロックマン ゼクス)\
\rMEGAMANZXA (Mega Man ZX Advent)\
\rROCKMANZXA (ロックマンゼクス アドベント)\
\rVersionning:\
\rEditor version: {self.VERSION_EDITOR} (final objective(s) completed, major functional features, WIP features)\
\rPython version: {self.VERSION_PYTHON} (your version is {platform.python_version()})\
\rPyQt version: {self.VERSION_PYQT} (your version is {QtCore.PYQT_VERSION_STR})\
\rNDSPy version: {self.VERSION_NDSPY} (your version is {list(ndspy.VERSION)[0]}.{list(ndspy.VERSION)[1]}.{list(ndspy.VERSION)[2]})""")
self.aboutAction = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/information')), '&About', self)
self.aboutAction.setStatusTip('Show information about the application')
self.aboutAction.triggered.connect(lambda: self.dialog_about.exec())
self.dialog_settings = QtWidgets.QDialog(self)
self.dialog_settings.setWindowTitle("Settings")
self.dialog_settings.resize(250, 50)
self.dialog_settings.setLayout(QtWidgets.QGridLayout())
self.tabs_settings = QtWidgets.QTabWidget(self.dialog_settings)
self.page_settings_general = QtWidgets.QWidget(self.tabs_settings)
self.page_settings_general.setLayout(QtWidgets.QGridLayout())
self.page_settings_performance = QtWidgets.QWidget(self.tabs_settings)
self.page_settings_performance.setLayout(QtWidgets.QGridLayout())
self.tabs_settings.addTab(self.page_settings_general, "General")
self.tabs_settings.addTab(self.page_settings_performance, "Performance")
# General Settings
self.label_theme = QtWidgets.QLabel("Theme", self.page_settings_general)
self.dropdown_theme = QtWidgets.QComboBox(self.page_settings_general)
self.dropdown_theme.addItems(QtWidgets.QStyleFactory.keys())
self.dropdown_theme.addItem("Custom")
self.switch_theme(True) # Update theme dropdown with current option
self.dropdown_theme.activated.connect(lambda: self.switch_theme())
self.label_base = QtWidgets.QLabel("Numeric Base", self.page_settings_general)
self.field_base = QtWidgets.QSpinBox(self.page_settings_general)
self.field_base.setValue(self.displayBase)
self.field_base.setRange(-1000, 1000)
self.field_base.editingFinished.connect(lambda: setattr(self, "displayBase", self.field_base.value()))
self.field_base.editingFinished.connect(self.reloadCall)
self.checkbox_alphanumeric = QtWidgets.QCheckBox(self.page_settings_general)
self.checkbox_alphanumeric.setText("Alphanumeric Numbers")
self.checkbox_alphanumeric.setChecked(self.displayAlphanumeric)
self.checkbox_alphanumeric.toggled.connect(lambda: setattr(self, "displayAlphanumeric", not self.displayAlphanumeric))
self.checkbox_alphanumeric.toggled.connect(self.reloadCall)
# Performance Settings
self.checkbox_fastLevel = QtWidgets.QCheckBox(self.page_settings_performance)
self.checkbox_fastLevel.checkStateChanged.connect(lambda: setattr(self, "fastLevel", self.checkbox_fastLevel.isChecked()))
self.checkbox_fastLevel.setChecked(self.fastLevel)
self.checkbox_fastLevel.setText("Disable LevelTileItem coordinate cache")
self.checkbox_fastLevel.setToolTip("Sacrifices some graphical fidelity in favor of faster rendering when zooming in/out")
self.checkbox_fastLevel.setToolTipDuration(10000)
self.dialog_settings.layout().addWidget(self.tabs_settings)
self.page_settings_general.layout().addWidget(self.label_theme)
self.page_settings_general.layout().addWidget(self.dropdown_theme)
self.page_settings_general.layout().addWidget(self.label_base)
self.page_settings_general.layout().addWidget(self.field_base)
self.page_settings_general.layout().addWidget(self.checkbox_alphanumeric)
self.page_settings_performance.layout().addWidget(self.checkbox_fastLevel)
self.settingsAction = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/gear')), '&Settings', self)
self.settingsAction.setStatusTip('Settings')
self.settingsAction.triggered.connect(lambda: self.dialog_settings.exec())
self.exitAction = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/door')), '&Exit', self)
self.exitAction.setStatusTip('Exit application')
self.exitAction.triggered.connect(self.close)
self.appMenu = self.menu_bar.addMenu('&Application')
self.appMenu.addActions([self.aboutAction, self.settingsAction, self.exitAction])
self.displayRawAction = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/brain')), '&Converted formats', self)
self.displayRawAction.setStatusTip('Displays files in a readable format instead of hex format.')
self.displayRawAction.setCheckable(True)
self.displayRawAction.setChecked(True)
self.displayRawAction.triggered.connect(self.display_format_toggleCall)
self.viewAdaptAction = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/document-node')), '&Adapt', self)
self.viewAdaptAction.setStatusTip('Files will be decrypted on a case per case basis.')
self.viewAdaptAction.setCheckable(True)
self.viewAdaptAction.setChecked(True)
self.viewAdaptAction.triggered.connect(lambda: setattr(self, "fileDisplayMode", "Adapt"))
self.viewAdaptAction.triggered.connect(lambda: self.treeCall())
self.viewDialogueAction = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/document-text')), '&Dialogue', self)
self.viewDialogueAction.setStatusTip('Files will be decrypted as in-game dialogues.')
self.viewDialogueAction.setCheckable(True)
self.viewDialogueAction.triggered.connect(lambda: setattr(self, "fileDisplayMode", "Dialogue"))
self.viewDialogueAction.triggered.connect(lambda: self.treeCall())
self.viewGraphicAction = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/appicon')), '&Graphics', self)
self.viewGraphicAction.setStatusTip('Files will be decrypted as graphics.')
self.viewGraphicAction.setCheckable(True)
self.viewGraphicAction.triggered.connect(lambda: setattr(self, "fileDisplayMode", "Graphics"))
self.viewGraphicAction.triggered.connect(lambda: self.treeCall())
self.viewFormatsGroup = QtGui.QActionGroup(self) #group for mutually exclusive togglable items
self.viewFormatsGroup.addAction(self.viewAdaptAction)
self.viewFormatsGroup.addAction(self.viewDialogueAction)
self.viewFormatsGroup.addAction(self.viewGraphicAction)
self.viewMenu = self.menu_bar.addMenu('&View')
self.viewMenu.addAction(self.displayRawAction)
self.displayFormatSubmenu = self.viewMenu.addMenu(QtGui.QIcon(str(PATH_ROOT / 'icons/document-convert')), '&Set edit mode...')
self.displayFormatSubmenu.addAction(self.viewAdaptAction)
self.displayFormatSubmenu.addSeparator()
self.displayFormatSubmenu.addActions(self.viewFormatsGroup.actions()[1:])
#Toolbar
self.toolbar = lib.widget.Toolbar("Main Toolbar", span=[23, self.width()])
self.toolbar.setSizePolicy(QtWidgets.QSizePolicy.Policy.Ignored, QtWidgets.QSizePolicy.Policy.Ignored)
self.addToolBar(self.toolbar)
self.action_open = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/folder-horizontal-open')), "Load ROM from Disk", self)
self.action_open.setStatusTip("Open NDS or SRL file to be able to edit its contents.")
self.action_open.triggered.connect(self.openCall)
self.action_save = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/disk')), "Save ROM to Disk", self)
self.action_save.setStatusTip("Generate ROM with saved changes; unsaved changes will remain unsaved.")
self.action_save.triggered.connect(self.saveCall)
self.action_save.setDisabled(True)
self.button_playtest = lib.widget.HoldButton(QtGui.QIcon(str(PATH_ROOT / 'icons/control')), "", self)
self.button_playtest.setToolTip("Playtest ROM (Hold for options)")
self.button_playtest.setStatusTip("Create a temporary ROM to test saved changes")
self.button_playtest.allow_repeat = False
self.button_playtest.allow_press = True
self.button_playtest.pressed_quick.connect(lambda: self.testCall(True))
self.button_playtest.held.connect(lambda: self.testCall(False))
self.button_playtest.setDisabled(True)
self.button_reload = lib.widget.HoldButton(QtGui.QIcon(str(PATH_ROOT / 'icons/arrow-circle-315')), "", self)
self.button_reload.setToolTip("Reload Interface (Hold for deep reload)")
self.button_reload.setStatusTip("Reload the displayed data(all changes that aren't saved will be lost)")
self.button_reload.allow_repeat = False
self.button_reload.allow_press = True
self.button_reload.pressed_quick.connect(lambda: self.reloadCall(1))
self.button_reload.held.connect(lambda: self.reloadCall(2))
self.action_sdat = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/speaker-volume')), "Open Sound Data Archive", self)
self.action_sdat.setStatusTip("Show the contents of this ROM's sdat file")
self.action_sdat.triggered.connect(lambda: self.dialogOpenCall("dialog_sdat"))
self.action_sdat.setDisabled(True)
self.action_arm9 = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/processor-num-9')), "Open ARM9", self)
self.action_arm9.setStatusTip("Show the contents of this ROM's ARM9")
self.action_arm9.triggered.connect(lambda: self.dialogOpenCall("dialog_arm9"))
self.action_arm9.setDisabled(True)
self.action_arm7 = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/processor-num-7')), "Open ARM7", self)
self.action_arm7.setStatusTip("Show the contents of this ROM's ARM7")
self.action_arm7.triggered.connect(lambda: self.dialogOpenCall("dialog_arm7"))
self.action_arm7.setDisabled(True)
#self.button_codeedit = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/document-text')), "Open code", self)
#self.button_codeedit.setStatusTip("Edit the ROM's code")
#self.button_codeedit.triggered.connect(self.codeeditCall)
#self.button_codeedit.setDisabled(True)
self.toolbar.addActions([self.action_open, self.action_save, self.action_arm9, self.action_arm7, self.action_sdat])
self.toolbar.insertWidget(self.action_arm9, self.button_playtest)
self.toolbar.addWidget(self.button_reload)
self.toolbar.addSeparator()
#Tabs
self.tabs = QtWidgets.QTabWidget(self)
self.setCentralWidget(self.tabs)
self.page_explorer = QtWidgets.QWidget(self.tabs)
self.page_explorer.setLayout(QtWidgets.QHBoxLayout())
self.page_leveleditor = QtWidgets.QWidget(self.tabs)
self.page_leveleditor.setLayout(QtWidgets.QHBoxLayout())
self.page_leveleditor.layout().setContentsMargins(0,0,0,0)
self.page_tweaks = QtWidgets.QWidget(self.tabs)
self.page_tweaks.setLayout(QtWidgets.QVBoxLayout())
self.page_tweaks.layout().setContentsMargins(0,0,0,0)
self.page_patches = QtWidgets.QWidget(self.tabs)
self.page_patches.setLayout(QtWidgets.QGridLayout())
self.tabs.addTab(self.page_explorer, "File Explorer")
self.tabs.addTab(self.page_leveleditor, "Level Editor") # Coming Soon™
self.tabs.addTab(self.page_tweaks, "Tweaks") # Coming Soon™
self.tabs.addTab(self.page_patches, "Patches") # Coming Soon™
self.tabs.currentChanged.connect(self.tabChangeCall)
# ROM-related
# ARM
self.dialog_arm9 = QtWidgets.QMainWindow(self) # "independent" window: can move anywhere on screen, but still affected by main window
self.dialog_arm9.setWindowTitle("ARM9")
self.dialog_arm9.setWindowIcon(QtGui.QIcon(str(PATH_ROOT / 'icons/processor-num-9')))
self.dialog_arm9.resize(600, 400)
self.tabs_arm9 = QtWidgets.QTabWidget(self.dialog_arm9)
self.dialog_arm9.setCentralWidget(self.tabs_arm9)
self.page_arm9 = QtWidgets.QWidget(self.tabs_arm9)
self.page_arm9.setLayout(QtWidgets.QVBoxLayout())
self.page_arm9Ovltable = QtWidgets.QWidget(self.tabs_arm9)
self.page_arm9Ovltable.setLayout(QtWidgets.QHBoxLayout())
self.dialog_arm9_dialogueNames = QtWidgets.QMainWindow(self)
self.dialog_arm9_dialogueNames.setWindowTitle("ARM9 - Dialogue Names")
self.dialog_arm9_dialogueNames.setWindowIcon(QtGui.QIcon(str(PATH_ROOT / 'icons/document-text')))
self.page_dialoguenames = QtWidgets.QWidget(self.dialog_arm9_dialogueNames)
self.page_dialoguenames.setLayout(QtWidgets.QGridLayout())
self.button_dialogueNames_save = QtWidgets.QPushButton("Save Name", self.page_dialoguenames)
self.button_dialogueNames_save.pressed.connect(self.saveDialogueName)
self.button_dialogueNames_save.setDisabled(True)
self.dropdown_dialogueNames = QtWidgets.QComboBox(self.page_dialoguenames)
self.dropdown_dialogueNames.setPlaceholderText("Select name index...")
self.dropdown_dialogueNames.currentIndexChanged.connect(self.loadDialogueName)
self.dropdown_dialogueNames_lang = QtWidgets.QComboBox(self.page_dialoguenames)
self.dropdown_dialogueNames_lang.addItems(["jp", "en"])
self.dropdown_dialogueNames_lang.currentIndexChanged.connect(lambda: self.dropdown_dialogueNames.setCurrentIndex(-1))
self.textEdit_dialogueNames = lib.widget.LongTextEdit(self.page_dialoguenames, charmap=lib.dialogue.CHARMAP_DIALOGUENAME_ZX_EN)
self.textEdit_dialogueNames.textChanged.connect(lambda: self.button_dialogueNames_save.setDisabled(False))
self.textEdit_dialogueNames.setMaximumHeight(30)
self.dialog_arm9_dialogueNames.setCentralWidget(self.page_dialoguenames)
self.page_dialoguenames.layout().addWidget(self.button_dialogueNames_save, 0,0,1,2)
self.page_dialoguenames.layout().addWidget(self.dropdown_dialogueNames, 1,0,1,1)
self.page_dialoguenames.layout().addWidget(self.dropdown_dialogueNames_lang, 1,1,1,1)
self.page_dialoguenames.layout().addWidget(self.textEdit_dialogueNames, 2,0,1,2)
self.tabs_arm9.addTab(self.page_arm9, "Main Code")
self.tabs_arm9.addTab(self.page_arm9Ovltable, "Overlays")
self.action_arm9_dialogueNames = QtGui.QAction(QtGui.QIcon(str(PATH_ROOT / 'icons/document-text')), "Dialogue Names", self.dialog_arm9)
self.action_arm9_dialogueNames.triggered.connect(lambda: self.dialogOpenCall("dialog_arm9_dialogueNames"))
self.toolbar_arm9 = lib.widget.Toolbar("ARM9 Toolbar")
self.toolbar_arm9.addActions([self.action_arm9_dialogueNames])
self.tree_arm9 = lib.widget.EditorTree(self.page_arm9)
self.tree_arm9.ContextNameType = "code-section at "
self.tree_arm9.setColumnCount(3)
self.tree_arm9.setHeaderLabels(["RAM Address", "Name", "Implicit", "BSS Size"])
self.tree_arm9.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.CustomContextMenu)
self.page_arm9.layout().addWidget(self.toolbar_arm9)
self.page_arm9.layout().addWidget(self.tree_arm9)
self.tree_arm9Ovltable = lib.widget.EditorTree(self.page_arm9Ovltable)
self.tree_arm9Ovltable.ContextNameType = "overlay "
self.tree_arm9Ovltable.setColumnCount(10)
self.tree_arm9Ovltable.setHeaderLabels(["File ID", "RAM Address", "Compressed", "Size", "RAM Size", "BSS Size", "StaticInit Start", "StaticInit End", "Flags", "Verify Hash"])
self.tree_arm9Ovltable.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.CustomContextMenu)
self.page_arm9Ovltable.layout().addWidget(self.tree_arm9Ovltable)
self.dialog_arm7 = QtWidgets.QMainWindow(self)
self.dialog_arm7.setWindowTitle("ARM7")
self.dialog_arm7.setWindowIcon(QtGui.QIcon(str(PATH_ROOT / 'icons/processor-num-7')))
self.dialog_arm7.resize(600, 400)
self.tabs_arm7 = QtWidgets.QTabWidget(self.dialog_arm7)
self.dialog_arm7.setCentralWidget(self.tabs_arm7)
self.page_arm7 = QtWidgets.QWidget(self.tabs_arm7)
self.page_arm7.setLayout(QtWidgets.QHBoxLayout())
self.page_arm7Ovltable = QtWidgets.QWidget(self.tabs_arm7)
self.page_arm7Ovltable.setLayout(QtWidgets.QHBoxLayout())
self.tabs_arm7.addTab(self.page_arm7, "Main Code")
self.tabs_arm7.addTab(self.page_arm7Ovltable, "Overlays")
self.tree_arm7 = lib.widget.EditorTree(self.page_arm7)
self.page_arm7.layout().addWidget(self.tree_arm7)
self.tree_arm7.ContextNameType = "code-section at "
self.tree_arm7.setColumnCount(3)
self.tree_arm7.setHeaderLabels(["RAM Address", "Name", "Implicit", "BSS Size"])
self.tree_arm7.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.CustomContextMenu)
self.tree_arm7Ovltable = lib.widget.EditorTree(self.page_arm7Ovltable)
self.page_arm7Ovltable.layout().addWidget(self.tree_arm7Ovltable)
self.tree_arm7Ovltable.ContextNameType = "overlay "
self.tree_arm7Ovltable.setColumnCount(10)
self.tree_arm7Ovltable.setHeaderLabels(["File ID", "RAM Address", "Compressed", "Size", "RAM Size", "BSS Size", "StaticInit Start", "StaticInit End", "Flags", "Verify Hash"])
self.tree_arm7Ovltable.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.CustomContextMenu)
# File explorer
self.tree = lib.widget.EditorTree(self.page_explorer)
self.tree.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
self.page_explorer.layout().addWidget(self.tree, 0)
self.tree.setMaximumWidth(450)
self.tree.setColumnCount(3)
self.tree.setHeaderLabels(["File ID", "Name", "Type"])
self.tree.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.CustomContextMenu)
self.tree_called = False
self.tree.itemSelectionChanged.connect(lambda: self.treeCall(addr_reset=True))
self.layout_editzone = QtWidgets.QVBoxLayout()
self.page_explorer.layout().addItem(self.layout_editzone)
self.layout_editzone_row0 = QtWidgets.QHBoxLayout()
self.layout_editzone_row1 = QtWidgets.QHBoxLayout()
self.layout_editzone_row2 = QtWidgets.QHBoxLayout()
self.layout_editzone_row3 = QtWidgets.QHBoxLayout()
self.widget_colorpick = QtWidgets.QWidget(self.page_explorer)
self.layout_colorpick = lib.widget.GridLayout()
self.layout_colorpick.setAlignment(QtCore.Qt.AlignmentFlag.AlignLeft)
self.layout_colorpick.setContentsMargins(0,2,5,0)
self.layout_colorpick.setSpacing(0)
self.widget_colorpick.setLayout(self.layout_colorpick)
self.button_file_save = QtWidgets.QPushButton("Save changes", self.page_explorer)
self.button_file_save.setMaximumWidth(100)
self.button_file_save.setToolTip("save this file's changes")
self.button_file_save.pressed.connect(self.save_filecontent)
self.button_file_save.setDisabled(True)
self.button_file_save.hide()
self.file_content = QtWidgets.QGridLayout()
self.file_content_text = lib.widget.LongTextEdit(self.page_explorer)
self.file_content_text.setSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Expanding)
font = QtGui.QFont("Monospace")
font.setStyleHint(QtGui.QFont.StyleHint.TypeWriter)
self.file_content_text.setFont(font)
self.file_content_text.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.NoContextMenu)
self.file_content_text.textChanged.connect(lambda: self.button_file_save.setDisabled(False))
self.file_content_text.setDisabled(True)
self.dropdown_textindex = QtWidgets.QComboBox(self.page_explorer)
self.dropdown_textindex.setSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Fixed)
self.dropdown_textindex.previousIndex = self.dropdown_textindex.currentIndex()
self.dropdown_textindex.currentIndexChanged.connect(lambda: self.treeCall())
self.checkbox_textoverwite = QtWidgets.QCheckBox("Overwite\n existing text", self.page_explorer)
self.checkbox_textoverwite.setStatusTip("With this enabled, writing text won't change filesize")
self.checkbox_textoverwite.clicked.connect(lambda: self.file_content_text.setOverwriteMode(not self.file_content_text.overwriteMode()))
self.layout_editzone_row1.addWidget(self.checkbox_textoverwite)
self.layout_editzone_row1.addWidget(self.dropdown_textindex)
self.file_content_gfx = lib.widget.GFXView(self.page_explorer)
self.file_content_gfx.setSizePolicy(QtWidgets.QSizePolicy.Policy.Ignored, QtWidgets.QSizePolicy.Policy.Expanding)
self.file_content.addWidget(self.file_content_gfx)
self.file_content.addWidget(self.file_content_text)
self.dropdown_gfx_depth = QtWidgets.QComboBox(self.page_explorer)
self.dropdown_gfx_depth.addItems(["1bpp", "4bpp", "8bpp"])# order of names is determined by the enum in dataconverter
self.dropdown_gfx_depth.currentIndexChanged.connect(lambda: self.treeCall())# Update gfx with current depth
self.font_caps = QtGui.QFont()
self.font_caps.setCapitalization(QtGui.QFont.Capitalization.AllUppercase)
#Address bar
self.field_address = lib.widget.BetterSpinBox(self.page_explorer)
self.field_address.numfill = 8
self.field_address.setFont(self.font_caps)
self.field_address.setValue(self.base_address+self.relative_address)
self.field_address.isInt = True
#self.field_address.setPrefix("0x")
self.field_address.numbase = self.displayBase
#self.field_address.textChanged.connect(lambda: self.value_update_Call("relative_address", library.dataconverter.baseToInt(library.dataconverter.strToBase(self.field_address.text()), self.field_address.displayIntegerBase()) - self.base_address, True))
self.field_address.textChanged.connect(lambda: self.value_update_Call("relative_address", int(self.field_address.valueFromText(self.field_address.text()) - self.base_address), True))
self.field_address.setDisabled(True)
self.field_address.hide()
#notes
self.label_file_size = QtWidgets.QLabel(self.page_explorer)
self.label_file_size.setContentsMargins(5,0,0,0)
self.label_file_size.setText("Size: N/A")
self.label_file_size.hide()
self.button_view_save = QtWidgets.QPushButton(QtGui.QIcon(str(PATH_ROOT / 'icons/blueprint--arrow')), "", self.page_explorer)
self.button_view_save.setMaximumWidth(25)
self.button_view_save.setToolTip("Save to bmp")
self.button_view_save.setStatusTip("Generate BMP from view")
self.button_view_save.pressed.connect(self.save_viewImage)
self.button_view_load = QtWidgets.QPushButton(QtGui.QIcon(str(PATH_ROOT / 'icons/blue-document-import')), "", self.page_explorer)
self.button_view_load.setMaximumWidth(25)
self.button_view_load.setToolTip("Load from bmp")
self.button_view_load.setStatusTip("Load BMP into view")
self.button_view_load.pressed.connect(self.load_viewImage)
#Tile Wifth
self.tile_width = 8
self.field_tile_width = lib.widget.BetterSpinBox(self.page_explorer)
self.field_tile_width.setStatusTip(f"Set tile width to {lib.datconv.numToStr(16, self.displayBase, self.displayAlphanumeric)}, {lib.datconv.numToStr(32, self.displayBase, self.displayAlphanumeric)} or {lib.datconv.numToStr(64, self.displayBase, self.displayAlphanumeric)} for some ZXA sprites")
self.field_tile_width.setFont(self.font_caps)
self.field_tile_width.setValue(self.tile_width)
self.field_tile_width.setMinimum(1)
self.field_tile_width.numbase = self.displayBase
self.field_tile_width.isInt = True
self.field_tile_width.valueChanged.connect(lambda: self.value_update_Call("tile_width", int(self.field_tile_width.value()), True))
self.field_tile_width.valueChanged.connect(self.file_content_gfx.fitInView2)
self.label_tile_width = QtWidgets.QLabel(self.page_explorer)
self.label_tile_width.setText(" width")
self.layout_tile_width = QtWidgets.QVBoxLayout()
self.layout_tile_width.addWidget(self.field_tile_width)
self.layout_tile_width.addWidget(self.label_tile_width)
self.layout_tile_width.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)
#Tile Height
self.tile_height = 8
self.field_tile_height = lib.widget.BetterSpinBox(self.page_explorer)
self.field_tile_height.setFont(self.font_caps)
self.field_tile_height.setValue(self.tile_height)
self.field_tile_height.setMinimum(1)
self.field_tile_height.numbase = self.displayBase
self.field_tile_height.isInt = True
self.field_tile_height.valueChanged.connect(lambda: self.value_update_Call("tile_height", int(self.field_tile_height.value()), True))
self.field_tile_height.valueChanged.connect(self.file_content_gfx.fitInView2)
self.label_tile_height = QtWidgets.QLabel(self.page_explorer)
self.label_tile_height.setText(" height")
self.layout_tile_height = QtWidgets.QVBoxLayout()
self.layout_tile_height.addWidget(self.field_tile_height)
self.layout_tile_height.addWidget(self.label_tile_height)
self.layout_tile_height.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)
#Tiles Per row
self.tiles_per_row = 8
self.field_tiles_per_row = lib.widget.BetterSpinBox(self.page_explorer)
self.field_tiles_per_row.setSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Fixed)
self.field_tiles_per_row.setFont(self.font_caps)
self.field_tiles_per_row.setValue(self.tiles_per_row)
self.field_tiles_per_row.setMinimum(1)
self.field_tiles_per_row.isInt = True
self.field_tiles_per_row.numbase = self.displayBase
self.field_tiles_per_row.valueChanged.connect(lambda: self.value_update_Call("tiles_per_row", int(self.field_tiles_per_row.value()), True))
self.field_tiles_per_row.valueChanged.connect(self.file_content_gfx.fitInView2)
self.label_tiles_per_row = QtWidgets.QLabel(self.page_explorer)
self.label_tiles_per_row.setText(" columns")
self.layout_tiles_per_row = QtWidgets.QVBoxLayout()
self.layout_tiles_per_row.addWidget(self.field_tiles_per_row)
self.layout_tiles_per_row.addWidget(self.label_tiles_per_row)
self.layout_tiles_per_row.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)
#Tiles Per Column
self.tiles_per_column = 8
self.field_tiles_per_column = lib.widget.BetterSpinBox(self.page_explorer)
self.field_tiles_per_column.setSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Fixed)
self.field_tiles_per_column.setFont(self.font_caps)
self.field_tiles_per_column.setValue(self.tiles_per_column)
self.field_tiles_per_column.setMinimum(1)
self.field_tiles_per_column.isInt = True
self.field_tiles_per_column.numbase = self.displayBase
self.field_tiles_per_column.valueChanged.connect(lambda: self.value_update_Call("tiles_per_column", int(self.field_tiles_per_column.value()), True))
self.field_tiles_per_column.valueChanged.connect(self.file_content_gfx.fitInView2)
self.label_tiles_per_column = QtWidgets.QLabel(self.page_explorer)
self.label_tiles_per_column.setText(" rows")
self.layout_tiles_per_column = QtWidgets.QVBoxLayout()
self.layout_tiles_per_column.addWidget(self.field_tiles_per_column)
self.layout_tiles_per_column.addWidget(self.label_tiles_per_column)
self.layout_tiles_per_column.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)
self.layout_tile_settings = QtWidgets.QHBoxLayout()
self.layout_tile_settings.addItem(self.layout_tile_width)
self.layout_tile_settings.addItem(self.layout_tile_height)
self.layout_tile_settings.addItem(self.layout_tiles_per_row)
self.layout_tile_settings.addItem(self.layout_tiles_per_column)
self.dropdown_gfx_index = QtWidgets.QComboBox(self.page_explorer)
self.dropdown_gfx_index.setPlaceholderText("no section entries")
self.dropdown_gfx_index.setToolTip("Choose index")
self.dropdown_gfx_index.setStatusTip("Select the object index to go to in gfx file")
self.dropdown_gfx_index.currentIndexChanged.connect(lambda: self.treeCall())
self.dropdown_gfx_subindex = QtWidgets.QComboBox(self.page_explorer)
self.dropdown_gfx_subindex.setPlaceholderText("no sub-entries")
self.dropdown_gfx_subindex.setToolTip("Choose sub-index")
self.dropdown_gfx_subindex.setStatusTip("Select the image index to go to in gfx object")
self.dropdown_gfx_subindex.currentIndexChanged.connect(lambda: self.treeCall())
self.checkbox_depthUpdate = QtWidgets.QCheckBox(self.page_explorer)
self.checkbox_depthUpdate.setStatusTip("Update depth to match palette size")
self.checkbox_depthUpdate.setChecked(True)
self.checkbox_depthUpdate.checkStateChanged.connect(lambda: self.treeCall())
self.label_depthUpdate = QtWidgets.QLabel(self.page_explorer)
self.label_depthUpdate.setText("Guess correct depth")
self.layout_other_settings = QtWidgets.QGridLayout()
self.layout_other_settings.addWidget(self.checkbox_depthUpdate, 0,0, QtCore.Qt.AlignmentFlag.AlignRight)
self.layout_other_settings.addWidget(self.label_depthUpdate, 0,1)
self.layout_other_settings.addWidget(self.dropdown_gfx_index, 1,0)
self.layout_other_settings.addWidget(self.dropdown_gfx_subindex, 1,1)
#Palettes
for i in range(256): #setup default palette
setattr(self, f"button_palettepick_{i}", lib.widget.HoldButton(self.page_explorer))
button_palettepick: lib.widget.HoldButton = getattr(self, f"button_palettepick_{i}")
button_palettepick.allow_press = True
button_palettepick.press_quick_threshold = 1
button_palettepick.setStyleSheet(f"background-color: #{self.gfx_palette[i]:08x}; color: white;")
button_palettepick.setMaximumSize(10, 10)
self.layout_colorpick.addWidget(button_palettepick, int(i/16), int(i%16))
button_palettepick.held.connect(lambda hold, press=None, color_index=i: self.colorpickCall(color_index, press, hold))
button_palettepick.pressed_quick.connect(lambda press, hold=None, color_index=i: self.colorpickCall(color_index, press, hold))
self.dropdown_gfx_palette = QtWidgets.QComboBox(self.page_explorer)
self.dropdown_gfx_palette.addItems(["Default Palette", "Font Palette", "Sprites Palette", "Grayscale", "Grayscale Alt"]) # order of names is determined by self.GFX_PALETTES
self.dropdown_gfx_palette.setToolTip("Choose palette")
self.dropdown_gfx_palette.setStatusTip("Select the color palette preset that you want to use to render images")
self.dropdown_gfx_palette.currentIndexChanged.connect(lambda: self.setPalette(self.GFX_PALETTES[self.dropdown_gfx_palette.currentIndex()])) # Update gfx with current depth
self.dropdown_gfx_palette.currentIndexChanged.connect(lambda: self.treeCall())
self.layout_palette_settings = QtWidgets.QHBoxLayout()
self.layout_palette_settings.addWidget(self.dropdown_gfx_palette)
self.layout_gfx_settings = QtWidgets.QVBoxLayout()
self.layout_gfx_settings.addItem(self.layout_tile_settings)
self.layout_gfx_settings.addItem(self.layout_other_settings)
self.layout_gfx_settings.addItem(self.layout_palette_settings)
#OAM
self.dropdown_oam_entry = QtWidgets.QComboBox(self.page_explorer)
self.dropdown_oam_entry.setPlaceholderText("no oam entries")
self.dropdown_oam_entry.setToolTip("Choose entry")
self.dropdown_oam_entry.setStatusTip("Select the OAM entry to load")
self.dropdown_oam_entry.currentIndexChanged.connect(lambda: self.treeCall(addr_disabled=True))
self.tabs_oam = QtWidgets.QTabWidget(self.page_explorer)
self.page_oam_frames = QtWidgets.QWidget(self.tabs_oam)
self.page_oam_frames.setLayout(QtWidgets.QGridLayout())
self.page_oam_anims = QtWidgets.QWidget(self.tabs_oam)
self.page_oam_anims.setLayout(QtWidgets.QGridLayout())
self.tabs_oam.addTab(self.page_oam_frames, "Frames")
self.tabs_oam.addTab(self.page_oam_anims, "Animations")
self.tabs_oam.currentChanged.connect(lambda: self.treeCall(addr_disabled=True))
self.dropdown_oam_anim = QtWidgets.QComboBox(self.page_oam_anims)
self.dropdown_oam_anim.setPlaceholderText("no animation entries")
self.dropdown_oam_anim.setToolTip("Choose animation")
self.dropdown_oam_anim.setStatusTip("Select the animation to load")
self.dropdown_oam_anim.currentIndexChanged.connect(lambda: self.treeCall(addr_disabled=True))
self.dropdown_oam_animFrame = QtWidgets.QComboBox(self.page_explorer)
self.dropdown_oam_animFrame.setPlaceholderText("no animation frames")
self.dropdown_oam_animFrame.setToolTip("Choose frame")
self.dropdown_oam_animFrame.setStatusTip("Select the animation frame to load")
self.dropdown_oam_animFrame.currentIndexChanged.connect(lambda: self.treeCall(addr_disabled=True))
self.field_oam_animFrameId = lib.widget.BetterSpinBox(self.page_oam_anims)
self.field_oam_animFrameId.setToolTip("Frame Id")
self.field_oam_animFrameId.setStatusTip("Frame index as seen in the frame editing tab")
self.field_oam_animFrameId.isInt = True
self.field_oam_animFrameId.setRange(0, 0xFF)
self.field_oam_animFrameId.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.field_oam_animFrameId.valueChanged.connect(lambda: self.treeCall(addr_disabled=True))
self.field_oam_animFrameDuration = lib.widget.BetterSpinBox(self.page_oam_anims)
self.field_oam_animFrameDuration.setToolTip("Duration (Frames)")
self.field_oam_animFrameDuration.setStatusTip("Duration of current frame; After the first frame, 0xFE and 0xFF are treated as loop and end")
self.field_oam_animFrameDuration.isInt = True
self.field_oam_animFrameDuration.setRange(0, 0xFF)
self.field_oam_animFrameDuration.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.field_oam_animFrameDuration.valueChanged.connect(lambda: self.treeCall(addr_disabled=True))
self.button_oam_animFrameAdd = QtWidgets.QPushButton("Add Frame", self.page_oam_anims)
self.button_oam_animFrameAdd.pressed.connect(lambda: self.treeCall(addr_disabled=True))
self.button_oam_animFrameRemove = QtWidgets.QPushButton("Remove Frame", self.page_oam_anims)
self.button_oam_animFrameRemove.pressed.connect(lambda: self.treeCall(addr_disabled=True))
self.checkbox_oam_animLoop = QtWidgets.QCheckBox(self.page_oam_anims)
self.checkbox_oam_animLoop.setText("Loop")
self.checkbox_oam_animLoop.setToolTip("Loop")
self.checkbox_oam_animLoop.setStatusTip("Enable/Disable animation loop point")
self.checkbox_oam_animLoop.checkStateChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.checkbox_oam_animLoop.checkStateChanged.connect(lambda: self.field_oam_animLoopStart.setEnabled(self.checkbox_oam_animLoop.isChecked()))
self.field_oam_animLoopStart = lib.widget.BetterSpinBox(self.page_oam_anims)
self.field_oam_animLoopStart.setToolTip("Loop Start")
self.field_oam_animLoopStart.setStatusTip("Frame index to jump to at the end of animation")
self.field_oam_animLoopStart.isInt = True
self.field_oam_animLoopStart.setRange(0, 0xFF)
self.field_oam_animLoopStart.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.button_oam_animToStart = QtWidgets.QPushButton(self.page_oam_anims)
self.button_oam_animToStart.setIcon(QtGui.QIcon(str(PATH_ROOT / 'icons/control-skip-180')))
self.button_oam_animToStart.setToolTip("To Start")
self.button_oam_animToStart.pressed.connect(lambda: self.button_oam_animPlay.autoPause())
self.button_oam_animToStart.pressed.connect(lambda: self.dropdown_oam_animFrame.setCurrentIndex(0))
self.button_oam_animPlay = lib.widget.PlayButton(self.page_oam_anims)
self.button_oam_animPlay.setToolTip("Play/Pause")
self.button_oam_animPlay.frameRequested.connect(self.OAM_playAnimFrame)
self.button_oam_animToEnd = QtWidgets.QPushButton(self.page_oam_anims)
self.button_oam_animToEnd.setIcon(QtGui.QIcon(str(PATH_ROOT / 'icons/control-skip')))
self.button_oam_animToEnd.setToolTip("To End")
self.button_oam_animToEnd.pressed.connect(lambda: self.button_oam_animPlay.autoPause())
self.button_oam_animToEnd.pressed.connect(lambda: self.dropdown_oam_animFrame.setCurrentIndex(self.dropdown_oam_animFrame.count()-1))
self.dropdown_oam_objFrame = QtWidgets.QComboBox(self.page_explorer)
self.dropdown_oam_objFrame.setPlaceholderText("no OAM frames")
self.dropdown_oam_objFrame.setToolTip("Choose frame")
self.dropdown_oam_objFrame.setStatusTip("Select the OAM frame to load")
self.dropdown_oam_objFrame.currentIndexChanged.connect(lambda: self.treeCall(addr_disabled=True))
self.dropdown_oam_obj = QtWidgets.QComboBox(self.page_oam_frames) #temporary until gfx interface implemented
self.dropdown_oam_obj.previousIndex = 0
self.dropdown_oam_obj.setPlaceholderText("no objects")
self.dropdown_oam_obj.setToolTip("Choose object")
self.dropdown_oam_obj.setStatusTip("Select the object to edit")
self.dropdown_oam_obj.currentIndexChanged.connect(lambda: self.treeCall(addr_disabled=True))
self.button_oam_objSelect = QtWidgets.QPushButton(self.page_oam_frames)
self.button_oam_objSelect.setText("Select current object")
self.button_oam_objSelect.pressed.connect(lambda: self.treeCall(addr_disabled=True))
self.button_oam_objAdd = QtWidgets.QPushButton(self.page_oam_frames)
self.button_oam_objAdd.setText("Add object")
self.button_oam_objAdd.pressed.connect(lambda: self.treeCall(addr_disabled=True))
self.button_oam_objRemove = QtWidgets.QPushButton(self.page_oam_frames)
self.button_oam_objRemove.setText("Remove object")
self.button_oam_objRemove.pressed.connect(lambda: self.treeCall(addr_disabled=True))
self.field_objTileId = lib.widget.BetterSpinBox(self.page_oam_frames)
self.field_objTileId.setToolTip("Tile Id (OAM)")
self.field_objTileId.setStatusTip("OAM tile id is half the value of VRAM tile id")
self.field_objTileId.isInt = True
self.field_objTileId.setRange(0, 0x3FF)
self.field_objTileId.numbase = self.displayBase
self.field_objTileId.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.field_objTileId.valueChanged.connect(lambda: self.OAM_updateItemGFX(self.dropdown_oam_obj.currentIndex(), item=self.file_content_oam.item_current))
self.checkbox_objFlipH = QtWidgets.QCheckBox(self.page_oam_frames)
self.checkbox_objFlipH.setText("Flip H")
self.checkbox_objFlipH.checkStateChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.checkbox_objFlipH.checkStateChanged.connect(lambda: self.file_content_oam.item_current.setPixmap(
self.file_content_oam.item_current.pixmap().transformed(QtGui.QTransform().scale(-1,1))))
self.checkbox_objFlipV = QtWidgets.QCheckBox(self.page_oam_frames)
self.checkbox_objFlipV.setText("Flip V")
self.checkbox_objFlipV.checkStateChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.checkbox_objFlipV.checkStateChanged.connect(lambda: self.file_content_oam.item_current.setPixmap(
self.file_content_oam.item_current.pixmap().transformed(QtGui.QTransform().scale(1,-1))))
self.slider_objSizeIndex = lib.widget.LabeledSlider(self.page_oam_frames, 0, 3, interval=1, orientation=QtCore.Qt.Orientation.Horizontal, labels=["1x1", "2x2", "4x4", "8x8"])
self.slider_objSizeIndex.setMaximumSize(260, 60)
self.slider_objSizeIndex.setToolTip("Size increment")
self.slider_objSizeIndex.sl.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.slider_objSizeIndex.sl.valueChanged.connect(lambda: self.OAM_updateItemGFX(self.dropdown_oam_obj.currentIndex(), item=self.file_content_oam.item_current))
self.radio_objShapeSquare = QtWidgets.QRadioButton()
self.radio_objShapeSquare.setText("Square")
self.radio_objShapeSquare.toggled.connect(lambda: self.button_file_save.setEnabled(True))
self.radio_objShapeWide = QtWidgets.QRadioButton()
self.radio_objShapeWide.setText("Wide")
self.radio_objShapeWide.toggled.connect(lambda: self.button_file_save.setEnabled(True))
self.radio_objShapeTall = QtWidgets.QRadioButton()
self.radio_objShapeTall.setText("Tall")
self.radio_objShapeTall.toggled.connect(lambda: self.button_file_save.setEnabled(True))
self.radio_objShapeProhibit = QtWidgets.QRadioButton()
self.radio_objShapeProhibit.setText("Prohibited")
self.radio_objShapeProhibit.toggled.connect(lambda: self.button_file_save.setEnabled(True))
self.buttonGroup_oam_objShape = QtWidgets.QButtonGroup(self.page_oam_frames)
self.buttonGroup_oam_objShape.addButton(self.radio_objShapeSquare, 0)
self.buttonGroup_oam_objShape.addButton(self.radio_objShapeWide, 1)
self.buttonGroup_oam_objShape.addButton(self.radio_objShapeTall, 2)
self.buttonGroup_oam_objShape.addButton(self.radio_objShapeProhibit, 3)
self.buttonGroup_oam_objShape.idReleased.connect(lambda: self.slider_objSizeIndex.setLabels(lib.oam.SPRITE_DIMENSIONS[self.buttonGroup_oam_objShape.checkedId()]))
self.buttonGroup_oam_objShape.idReleased.connect(lambda: self.OAM_updateItemGFX(self.dropdown_oam_obj.currentIndex(), item=self.file_content_oam.item_current))
self.group_oam_objShape = QtWidgets.QGroupBox(self.page_oam_frames)
self.group_oam_objShape.setTitle("Shape")
self.group_oam_objShape.setLayout(QtWidgets.QVBoxLayout())
self.group_oam_objShape.layout().addWidget(self.radio_objShapeSquare)
self.group_oam_objShape.layout().addWidget(self.radio_objShapeWide)
self.group_oam_objShape.layout().addWidget(self.radio_objShapeTall)
self.group_oam_objShape.layout().addWidget(self.radio_objShapeProhibit)
self.slider_obj3DHeightIndex = lib.widget.LabeledSlider(self.page_oam_frames, 0, 3, interval=1, orientation=QtCore.Qt.Orientation.Horizontal, labels=["0x1", "0x2", "0x4", "0x8"])
self.slider_obj3DHeightIndex.setMaximumSize(260, 60)
self.slider_obj3DHeightIndex.setToolTip("Height increment")
self.slider_obj3DHeightIndex.sl.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.slider_obj3DHeightIndex.sl.valueChanged.connect(lambda: self.OAM_updateItemGFX(self.dropdown_oam_obj.currentIndex(), item=self.file_content_oam.item_current))
self.slider_obj3DHeightIndex.hide()
self.slider_obj3DTileWidth = lib.widget.LabeledSlider(self.page_oam_frames, 0, 3, interval=1, orientation=QtCore.Qt.Orientation.Horizontal, labels=["0x8", "0x10", "0x20", "0x40"])
self.slider_obj3DTileWidth.setMaximumSize(260, 60)
self.slider_obj3DTileWidth.setToolTip("Tile width increment")
self.slider_obj3DTileWidth.sl.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.slider_obj3DTileWidth.sl.valueChanged.connect(lambda: self.OAM_updateItemGFX(self.dropdown_oam_obj.currentIndex(), item=self.file_content_oam.item_current))
self.slider_obj3DTileWidth.hide()
self.field_objX = lib.widget.BetterSpinBox(self.page_oam_frames)
self.field_objX.setToolTip("X")
self.field_objX.isInt = True
self.field_objX.setRange(-128, 127)
self.field_objX.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.field_objX.valueChanged.connect(lambda: self.file_content_oam.item_current.setX(self.field_objX.value()))
self.field_objY = lib.widget.BetterSpinBox(self.page_oam_frames)
self.field_objY.setToolTip("Y")
self.field_objY.isInt = True
self.field_objY.setRange(-128, 127)
self.field_objY.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.field_objY.valueChanged.connect(lambda: self.file_content_oam.item_current.setY(self.field_objY.value()))
self.file_content_oam = lib.widget.OAMView(self.page_explorer)
self.file_content_oam.setSizePolicy(QtWidgets.QSizePolicy.Policy.Ignored, QtWidgets.QSizePolicy.Policy.Expanding)
self.file_content.addWidget(self.file_content_oam)
self.layout_oam_navigation = QtWidgets.QGridLayout()
self.layout_oam_navigation.addWidget(self.dropdown_oam_entry, 0, 0)
self.page_oam_anims.layout().addWidget(self.dropdown_oam_anim, 0, 0, 1, 3)
self.page_oam_anims.layout().addWidget(self.dropdown_oam_animFrame, 0, 3)
self.page_oam_anims.layout().addWidget(self.field_oam_animFrameId, 1, 3)
self.page_oam_anims.layout().addWidget(self.button_oam_animFrameAdd, 1, 4, 1, 2)
self.page_oam_anims.layout().addWidget(self.field_oam_animFrameDuration, 2, 3)
self.page_oam_anims.layout().addWidget(self.button_oam_animFrameRemove, 2, 4, 1, 2)
self.page_oam_anims.layout().addWidget(self.checkbox_oam_animLoop, 1, 0)
self.page_oam_anims.layout().addWidget(self.field_oam_animLoopStart, 2, 0)
self.page_oam_anims.layout().addWidget(self.button_oam_animToStart, 3, 0, 1, 2)
self.page_oam_anims.layout().addWidget(self.button_oam_animPlay, 3, 2, 1, 2)
self.page_oam_anims.layout().addWidget(self.button_oam_animToEnd, 3, 4, 1, 2)
self.page_oam_frames.layout().addWidget(self.dropdown_oam_objFrame, 0, 0, 1, 2)
self.page_oam_frames.layout().addWidget(self.dropdown_oam_obj, 0, 2)
self.page_oam_frames.layout().addWidget(self.button_oam_objAdd, 0, 3)
self.page_oam_frames.layout().addWidget(self.field_objTileId, 1, 0, 1, 2)
self.page_oam_frames.layout().addWidget(self.button_oam_objSelect, 1, 2)
self.page_oam_frames.layout().addWidget(self.button_oam_objRemove, 1, 3)
self.page_oam_frames.layout().addWidget(self.checkbox_objFlipH, 2, 0, 1, 2)
self.page_oam_frames.layout().addWidget(self.checkbox_objFlipV, 3, 0, 1, 2)
self.page_oam_frames.layout().addWidget(self.slider_objSizeIndex, 4, 0, 1, 2)
self.page_oam_frames.layout().addWidget(self.group_oam_objShape, 4, 2, 1, 2)
self.page_oam_frames.layout().addWidget(self.slider_obj3DHeightIndex, 4, 0, 1, 2)
self.page_oam_frames.layout().addWidget(self.slider_obj3DTileWidth, 4, 2, 1, 2)
self.page_oam_frames.layout().addWidget(self.field_objX, 5, 0, 1, 2)
self.page_oam_frames.layout().addWidget(self.field_objY, 5, 2, 1, 2)
#Palette Animation
self.dropdown_panm_entry = QtWidgets.QComboBox(self.page_explorer)
self.dropdown_panm_entry.setPlaceholderText("no animations")
self.dropdown_panm_entry.setToolTip("Choose palette animation")
self.dropdown_panm_entry.setStatusTip("Palette animations for mavericks. 0=evil; 1=patrol; 2=alert")
self.dropdown_panm_entry.currentIndexChanged.connect(lambda: self.treeCall(addr_disabled=True))
self.dropdown_panm_oamEntry = QtWidgets.QComboBox(self.page_explorer)
self.dropdown_panm_oamEntry.setPlaceholderText("no entries to preview")
self.dropdown_panm_oamEntry.setToolTip("Choose oam entry")
self.dropdown_panm_oamEntry.setStatusTip("OAM entry to use when previewing palette.")
self.dropdown_panm_oamEntry.currentIndexChanged.connect(lambda: self.treeCall(addr_disabled=True))
self.dropdown_panm_frame = QtWidgets.QComboBox(self.page_explorer)
self.dropdown_panm_frame.setPlaceholderText("no frames")
self.dropdown_panm_frame.setToolTip("Choose animation frame")
self.dropdown_panm_frame.setStatusTip("Each frame overwrites two colors from a 16-color palette")
self.dropdown_panm_frame.currentIndexChanged.connect(lambda: self.treeCall(addr_disabled=True))
self.layout_panm = QtWidgets.QGridLayout()
self.field_panm_frameId = lib.widget.BetterSpinBox(self.page_explorer)
self.field_panm_frameId.setToolTip("Frame")
self.field_panm_frameId.isInt = True
self.field_panm_frameId.setRange(0x00, 0xFF)
self.field_panm_frameId.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.field_panm_frameDuration = lib.widget.BetterSpinBox(self.page_explorer)
self.field_panm_frameDuration.setToolTip("Duration")
self.field_panm_frameDuration.isInt = True
self.field_panm_frameDuration.setRange(0x00, 0xFF)
self.field_panm_frameDuration.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.checkbox_panm_loop = QtWidgets.QCheckBox(self.page_explorer)
self.checkbox_panm_loop.setText("Loop")
self.checkbox_panm_loop.setToolTip("Loop On/Off")
self.checkbox_panm_loop.checkStateChanged.connect(lambda: self.field_panm_loopStart.setEnabled(self.checkbox_panm_loop.isChecked()))
self.checkbox_panm_loop.checkStateChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.field_panm_loopStart = lib.widget.BetterSpinBox(self.page_explorer)
self.field_panm_loopStart.setToolTip("Loop Start")
self.field_panm_loopStart.isInt = True
self.field_panm_loopStart.setRange(0x00, 0xFF)
self.field_panm_loopStart.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.label_panm_colorSlots = QtWidgets.QLabel("Color slots", self.page_explorer)
self.label_panm_colorSlots.setMaximumHeight(50)
self.label_panm_colorSlots.setAlignment(QtCore.Qt.AlignmentFlag.AlignBottom)
self.field_panm_colorSlot0 = lib.widget.BetterSpinBox(self.page_explorer)
self.field_panm_colorSlot0.setToolTip("Color Slot 0")
self.field_panm_colorSlot0.setStatusTip("The index of the first color to overwrite in a 16-color palette")
self.field_panm_colorSlot0.isInt = True
self.field_panm_colorSlot0.setRange(0x00, 0xFF)
self.field_panm_colorSlot0.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.field_panm_colorSlot1 = lib.widget.BetterSpinBox(self.page_explorer)
self.field_panm_colorSlot1.setStatusTip("The index of the second color to overwrite in a 16-color palette")
self.field_panm_colorSlot1.setToolTip("Color Slot 1")
self.field_panm_colorSlot1.isInt = True
self.field_panm_colorSlot1.setRange(0x00, 0xFF)
self.field_panm_colorSlot1.valueChanged.connect(lambda: self.button_file_save.setEnabled(True))
self.gfx_scene_panm = lib.widget.View(self.page_explorer)
self.gfx_scene_panm.hide()
self.layout_panm.addWidget(self.dropdown_panm_oamEntry, 0, 0)
self.layout_panm.addWidget(self.dropdown_panm_entry, 0, 1)