forked from DRGN-DRC/Melee-Modding-Wizard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stageManager.py
3492 lines (2759 loc) · 153 KB
/
stageManager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
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
#!/usr/bin/python
# This file's encoding: UTF-8, so that non-ASCII characters can be used in strings.
#
# ███╗ ███╗ ███╗ ███╗ ██╗ ██╗ ------- -------
# ████╗ ████║ ████╗ ████║ ██║ ██║ # -=======---------------------------------------------------=======- #
# ██╔████╔██║ ██╔████╔██║ ██║ █╗ ██║ # ~ ~ Written by DRGN of SmashBoards (Daniel R. Cappel); May, 2020 ~ ~ #
# ██║╚██╔╝██║ ██║╚██╔╝██║ ██║███╗██║ # [ Built with Python v2.7.16 and Tkinter 8.5 ] #
# ██║ ╚═╝ ██║ ██║ ╚═╝ ██║ ╚███╔███╔╝ # -======---------------------------------------------------======- #
# ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══╝╚══╝ ------ ------
# - - Melee Modding Wizard - -
# External dependencies
import os
import ttk
import time
import struct
import Tkinter as Tk
from binascii import hexlify
# from direct.task import Task
# from panda3d.core import WindowProperties
# from direct.showbase.ShowBase import ShowBase
from PIL import Image, ImageTk, ImageDraw, ImageFont
# Internal dependencies
import globalData
from RenderEngine2 import RenderEngine, Triangle
from FileSystem import StageFile
from FileSystem.hsdStructures import MapMusicTable, MapPointTypesArray
from basicFunctions import uHex, hex2rgb, humansize, msg, printStatus, reverseDictLookup
from guiSubComponents import (
LabelButton, exportSingleTexture, getColoredShape, importGameFiles, exportSingleFileWithGui,
importSingleFileWithGui, importSingleTexture, getNewNameFromUser, BasicWindow, ToolTip,
ToolTipEditor, ToolTipButton, HexEditEntry, ColorSwatch, VerticalScrolledFrame, NeoTreeview )
from audioManager import AudioControlModule
class StageSwapTable( object ):
""" Data table for 20XX HP's Stage Engine. This table is 0x5D0 bytes long, and located at
the 'tableOffset' value below. It is composed of 31 entries, each 0x30 bytes long.
Each entry is of this form:
B 0x0: Stage name (ASCII; only used as identifier in this table)
B 0x8: New Stage ID; SSS, page 1
B 0x9: New Stage ID; SSS, page 2
B 0xA: New Stage ID; SSS, page 3
B 0xB: New Stage ID; SSS, page 4
B 0xC: Stage Flags; SSS, page 1
B 0xD: Stage Flags; SSS, page 2
B 0xE: Stage Flags; SSS, page 3
B 0xF: Stage Flags; SSS, page 4
I 0x10: RAM Pointer for Byte Replacement; SSS, page 1
I 0x14: RAM Pointer for Byte Replacement; SSS, page 2
I 0x18: RAM Pointer for Byte Replacement; SSS, page 3
I 0x1C: RAM Pointer for Byte Replacement; SSS, page 4
B 0x20: Byte Replacement at Pointer Address; SSS, page 1
B 0x21: Byte Replacement at Pointer Address; SSS, page 2
B 0x22: Byte Replacement at Pointer Address; SSS, page 3
B 0x23: Byte Replacement at Pointer Address; SSS, page 4
I 0x24: Random Byte Replacements at Pointer Address (if above is 0xFF); SSS, page 2
I 0x28: Random Byte Replacements at Pointer Address (if above is 0xFF); SSS, page 3
I 0x2C: Random Byte Replacements at Pointer Address (if above is 0xFF); SSS, page 4
"""
stageOffsets = { # Key = internalStageId, value=tableEntryOffset
0x0C: 0x0, # Fountain of Dreams
0x10: 0x30, # Pokemon Stadium
0x02: 0x60, # Peach's Castle
0x04: 0x90, # Kongo Jungle
0x08: 0xC0, # Brinstar
0x0E: 0xF0, # Corneria
0x0A: 0x120, # Yoshi's Story
0x14: 0x150, # Onett
0x12: 0x180, # Mute City
0x03: 0x1B0, # Rainbow Cruise
0x05: 0x1E0, # Jungle Japes
0x06: 0x210, # Great Bay
0x07: 0x240, # Hyrule Temple
0x09: 0x270, # Brinstar Depths
0x0B: 0x2A0, # Yoshi's Island
0x0D: 0x2D0, # Green Greens
0x15: 0x300, # Fourside
0x18: 0x330, # Mushroom Kingdom I
0x19: 0x360, # Mushroom Kingdom II
0x0F: 0x3C0, # Venom
0x11: 0x3F0, # Poke Floats
0x13: 0x420, # Big Blue
0x16: 0x450, # Icicle Mountain
0x1B: 0x4B0, # Flatzone
0x1C: 0x4E0, # Dream Land (N64)
0x1D: 0x510, # Yoshi's Island (N64)
0x1E: 0x540, # Kongo Jungle (N64)
0x24: 0x570, # Battlefield
0x25: 0x5A0 # Final Destination
}
def __init__( self ):
# Get the DOL, and check for a file in the disc filesystem specifically for the stage swap table
self.dol = globalData.disc.dol
self.sstFile = globalData.disc.files.get( globalData.disc.gameId + '/StageSwapTable.bin' )
if self.sstFile: # Newer versions of 20XX
self.tableOffset = 0x0
else:
self.tableOffset = 0x3F8C80 # Offset/location within the DOL
def getEntryValues( self, internalStageId ):
""" Gets all values for a given stage ID. This includes data for each SSS page.
Returns 28 values; 0x28 bytes of data (doesn't get stage name identifier). """
# Get the offset, data, and values for this entry
entryOffset = self.stageOffsets[internalStageId]
dataOffset = self.tableOffset + entryOffset + 8
if self.sstFile:
entryData = self.sstFile.getData( dataOffset, 0x28 )
else:
entryData = self.dol.getData( dataOffset, 0x28 )
return struct.unpack( '>BBBBBBBBIIIIBBBBBBBBBBBBBBBB', entryData )
def getEntryInfo( self, internalStageId, page ):
""" Retrieves the values for a given stage, for a given page.
The provided page value is expected to be a 1-indexed int. """
# Get the offset, data, and values for this entry
values = self.getEntryValues( internalStageId )
# Index the returned values for the given page
page -= 1 # Count 0-indexed
newStageId = values[page] # External Stage ID
stageFlags = values[page+4]
byteReplacePointer = values[page+8]
byteReplacement = values[page+12]
if page == 0: # No random byte values for first SSS page
randomByteValues = ( 0, 0, 0, 0 )
else:
randomByteValuesIndex = 12 + ( 4 * page )
randomByteValues = tuple( values[randomByteValuesIndex:randomByteValuesIndex+4] )
return newStageId, stageFlags, byteReplacePointer, byteReplacement, randomByteValues
def setEntryInfo( self, internalStageId, page, newStageId, stageFlags, byteReplacePointer, byteReplacement, randomByteValues ):
""" Sets the values for a given stage, for a given page.
The provided page value is expected to be 1-indexed. """
# Get the values for this entry
values = self.getEntryValues( internalStageId )
newValues = list( values )
page -= 1 # Count 0-indexed
newValues[page] = newStageId
newValues[page+4] = stageFlags
newValues[page+8] = byteReplacePointer
newValues[page+12] = byteReplacement
if page == 0:
# Make sure not trying to use byte replacement on first page of SSS
assert byteReplacement != 0xFF, 'Invalid Stage Swap Table values; cannot use random byte values on SSS page 1.'
else:
randomByteValuesIndex = 12 + ( 4 * page )
newValues[randomByteValuesIndex:randomByteValuesIndex+4] = randomByteValues
# Check if this is actually new (changed data)
if values == tuple( newValues ):
globalData.gui.updateProgramStatus( 'No changes to submit to the Stage Swap Table' )
else:
# Calculate the offset for the data, and pack the values to bytes
entryOffset = self.stageOffsets[internalStageId]
dataOffset = self.tableOffset + entryOffset + 8
newData = struct.pack( '>BBBBBBBBIIIIBBBBBBBBBBBBBBBB', *newValues ) # Using '*' to expand the list into pack's args
# Build a user message
stageName = globalData.internalStageIds[internalStageId]
updateMsg = 'Stage Swap Table updated for {} icon slot, on page {}'.format( stageName, page+1 )
# Determine the file to update, and set the data packed above
if self.sstFile:
fileToModify = self.sstFile
else:
fileToModify = self.dol
fileToModify.setData( dataOffset, newData )
# Remember this change, and update the program's status bar
if updateMsg not in fileToModify.unsavedChanges:
fileToModify.unsavedChanges.append( updateMsg )
globalData.gui.updateProgramStatus( updateMsg )
def determineStageFiles( self, internalStageId, page, byteReplacePointer, byteReplacement, randomByteValues ):
""" Determines the stage filenames that are expected to be loaded for a given stage icon on the Stage Select Screen.
Used to determine the filenames to search for in the disc, to populate the Variations treeview and other GUI elements.
Returns two values:
- An int; DOL offset of the filename string that will be used for stage file loading
- A list; of all filenames that may be loaded by the currently selected icon. """
# Get the filename and its offset
dolFilenameOffset, dolStageFilename = self.dol.getStageFileName( internalStageId )
if dolFilenameOffset == -1:
return -1, ()
# Check for 20XX random neutrals
if page == 1 and internalStageId in ( 0xC, 0x24, 0x25, 0x1C, 0x10, 0xA ): # FoD, Battlefield, FD, DreamLand, Stadium, Yoshi's Story
filenames = []
for char in '0123456789abcde': # F reserved for random stage
if internalStageId == 0x10: # Pokemon Stadium; use .usd file extension
filenames.append( 'GrP{}.usd'.format(char) )
else:
filenames.append( '{}.{}at'.format(dolStageFilename[:-4], char) )
# One variation; no byte replacements
elif byteReplacePointer == 0:
if dolStageFilename == 'GrNSr.0at': # Not changed by stage swap table?!
dolStageFilename = 'GrNSr.1at'
filenames = [dolStageFilename]
# Multiple variations; byte(s) will be replaced in the stage filename
else:
# Get the DOL offset of the byte to be replaced
dolByteReplaceOffset = self.dol.offsetInDOL( byteReplacePointer ) # Convert from a RAM address to a DOL offset
relativeOffset = dolByteReplaceOffset - dolFilenameOffset
if byteReplacement == 0xFF:
filenames = []
for byte in randomByteValues:
if byte == 0: continue
newFilename = dolStageFilename[:relativeOffset] + chr( byte ) + dolStageFilename[relativeOffset+1:]
filenames.append( newFilename )
else:
newFilename = dolStageFilename[:relativeOffset] + chr( byteReplacement ) + dolStageFilename[relativeOffset+1:]
filenames = [newFilename]
return dolFilenameOffset, filenames
class ScrollArrows( object ):
""" These are for scrolling the canvases which contain the stage icons for each SSS page. """
def __init__( self, canvas ):
self.canvas = canvas
canvas.scrollPosition = 0
canvas.scrollHeight = 300
self.scrollAmount = 150 # Positive values scroll up; negative scrolls down
# Get/create the arrow images
downArrowImage = getColoredShape( 'arrowDown', '#7077ac', getAsPilImage=True )
downArrowImageHovered = getColoredShape( 'arrowDown', '#8089ff', getAsPilImage=True )
# Copy and flip them to create the up arrows
upArrowImage = downArrowImage.transpose( Image.FLIP_TOP_BOTTOM )
upArrowImageHovered = downArrowImageHovered.transpose( Image.FLIP_TOP_BOTTOM )
# Convert these into a type of image Tkinger can display
self.downArrowImage = ImageTk.PhotoImage( downArrowImage )
self.downArrowImageHovered = ImageTk.PhotoImage( downArrowImageHovered )
self.upArrowImage = ImageTk.PhotoImage( upArrowImage )
self.upArrowImageHovered = ImageTk.PhotoImage( upArrowImageHovered )
self.addDownArrow()
self.upArrowId = None
# Add the arrow button click and hover event handlers
canvas.tag_bind( 'downArrow', '<1>', lambda event: self.scrollItems(-self.scrollAmount) )
canvas.tag_bind( 'downArrow', '<Enter>', self.downArrowHovered )
canvas.tag_bind( 'downArrow', '<Leave>', self.downArrowUnhovered )
canvas.tag_bind( 'upArrow', '<1>', lambda event: self.scrollItems(self.scrollAmount) )
canvas.tag_bind( 'upArrow', '<Enter>', self.upArrowHovered )
canvas.tag_bind( 'upArrow', '<Leave>', self.upArrowUnhovered )
canvas.yview_scroll = self.onMouseWheelScroll
def addUpArrow( self ): self.upArrowId = self.canvas.create_image( 600, 10, image=self.upArrowImage, anchor='ne', tags='upArrow' )
def addDownArrow( self ): self.downArrowId = self.canvas.create_image( 600, 140, image=self.downArrowImage, anchor='se', tags='downArrow' )
def removeUpArrow( self ):
self.canvas.delete( self.upArrowId )
self.upArrowId = None
self.canvas['cursor'] = ''
def removeDownArrow( self ):
self.canvas.delete( self.downArrowId )
self.downArrowId = None
self.canvas['cursor'] = ''
def downArrowHovered( self, event ):
self.canvas['cursor'] = 'hand2'
self.canvas.itemconfigure( self.downArrowId, image=self.downArrowImageHovered )
def downArrowUnhovered( self, event ):
self.canvas['cursor'] = ''
self.canvas.itemconfigure( self.downArrowId, image=self.downArrowImage )
def upArrowHovered( self, event ):
self.canvas['cursor'] = 'hand2'
self.canvas.itemconfigure( self.upArrowId, image=self.upArrowImageHovered )
def upArrowUnhovered( self, event ):
self.canvas['cursor'] = ''
self.canvas.itemconfigure( self.upArrowId, image=self.upArrowImage )
def scrollItems( self, distance ):
""" Negative scrollPosition means the icons are moving up. """
newScrollPosition = self.canvas.scrollPosition + distance
if newScrollPosition >= 0: # Upper scroll bounds reached
distance -= newScrollPosition # Subtract however much it was overshot
self.removeUpArrow()
elif newScrollPosition <= -self.canvas.scrollHeight: # Lower scroll bounds reached
distance += abs( newScrollPosition + self.canvas.scrollHeight )
self.removeDownArrow()
else: # Not hitting a boundary; make sure both scroll arrows are present
if not self.canvas.find_withtag( 'upArrow' ):
self.addUpArrow()
if not self.canvas.find_withtag( 'downArrow' ):
self.addDownArrow()
self.canvas.move( 'icons', 0, distance )
self.canvas.move( 'selectionBorder', 0, distance )
self.canvas.scrollPosition += distance
def onMouseWheelScroll( self, amount, units ):
# Multiply the amount a bit, since it will be 4 for each mouseWheel movement. And reverse it
self.scrollItems( amount * -6 )
class MusicToolTip( ToolTip ):
""" Subclass of the ToolTip class in order to provide an ACM (Audio Control Module),
for controlling or editing music selections, which behaves like a hoverable tooltip.
Also, unlike with the tooltip class, this module will wait a second before
disappearing, and should not disappear if the user's mouse is over it.
Note that the ACM used here shares the same Audio Engine as the main program GUI,
meaning that music played from these tooltip modules will first stop other music. """
def __init__( self, master, valueIndex, mainTab, *args, **kwargs ):
ToolTip.__init__( self, master, *args, **kwargs )
self.valueIndex = valueIndex
self.mainTab = mainTab
self.acm = None # Audio Control Module
def _hasText(self):
return True # Makes sure the module thinks the tooltip (entry) is worth showing
def leave(self, event=None):
""" Instead of the usual tooltip behavior of unscheduling the creation method
(if it's queued) and destroying the window, we first wait a second to destroy it. """
self._unschedule()
self.master.after( 1000, self.queueHide )
def queueHide(self):
""" Overriding this method to first see if the entry widget is being
hovered over or is focused, implying the user intends to use it. """
# Check if the tooltip window exists
if not self._tipwindow:
return
elif self.mousedOver():
return
self._hide()
def mousedOver( self ):
# Get the widget currently beneath the mouse
x, y = self.master.winfo_pointerxy()
hoveredWidget = globalData.gui.root.winfo_containing( x, y )
if not hoveredWidget:
return False
elif hoveredWidget == self._tipwindow:
return True
# Traverse upwards in the widget heirarchy
parent = hoveredWidget.master
while parent:
if parent == self._tipwindow:
return True
parent = parent.master # Will eventually become '' after root
return False
def create_contents( self ):
# Get the music ID and associated audio file
musicId = self.getMusicId()
musicFile = globalData.disc.getMusicFile( musicId )
self.acm = AudioControlModule( self._tipwindow, self.mainTab.audioEngine, musicFile )
self.acm.pack( side='left' )
self.acm.bind( "<Leave>", self.leave, '+' ) # Hide again when user leaves the module
LabelButton(self._tipwindow, 'configButton', self.edit, 'Edit' ).pack( side='left', padx=6 )
def getMusicId( self ):
""" Accesses the currently selected file's music table struct (for the music table
entry currently selected) and gets the music ID to be used for this tooltip. """
# Get the index of the currently selected table entry, and the values for just this particular entry
entryIndex = self.mainTab.getMusicTableEntryIndex()
values = self.mainTab.musicTableStruct.getEntryValues( entryIndex )
musicId = values[self.valueIndex]
return musicId
def edit( self, event=None ):
""" Called by the 'Edit' button on the tooltip. Prompts the user
with a new window for choosing a new track for this song slot. """
if not self.mainTab.musicTableStruct: # Failsafe; might not be possible
globalData.gui.updateProgramStatus( 'No stage is selected', warning=True )
return
SongChooser( self.mainTab, self.valueIndex, self.getMusicId() )
self._hide()
def _show(self):
# Hide any other tooltips currently shown
for toolTip in self.mainTab.toolTips.itervalues():
if toolTip._tipwindow and toolTip != self:
toolTip._unschedule()
toolTip._hide()
if self._opts['state'] == 'disabled' or not self._hasText():
self._unschedule()
print( 'state disabled. unscheduling ' + str(self.valueIndex) )
return
if not self._tipwindow:
self._tipwindow = Tk.Toplevel(self.master)
# hide the window until we know the geometry
self._tipwindow.withdraw()
self._tipwindow.wm_overrideredirect(1)
if self._tipwindow.tk.call("tk", "windowingsystem") == 'aqua':
self._tipwindow.tk.call("::tk::unsupported::MacWindowStyle", "style", self._tipwindow._w, "help", "none")
self.create_contents()
self._tipwindow.update_idletasks()
# x, y = self.coords()
# self._tipwindow.wm_geometry("+%d+%d" % (x, y))
# self._tipwindow.deiconify()
#print 'deiconify after creation', self.valueIndex
#else:
#print 'deiconify', self.valueIndex
x, y = self.coords()
self._tipwindow.wm_geometry("+%d+%d" % (x, y))
self._tipwindow.deiconify()
def _hide(self):
#print 'hiding', self.valueIndex
tw = self._tipwindow
#self._tipwindow = None
if tw:
#tw.destroy()
#print 'withdraw'
tw.withdraw()
class SongChooser( BasicWindow ):
def __init__( self, stageTab, valueIndex, initialSelection=-1 ):
BasicWindow.__init__( self, globalData.gui.root, "Song Chooser", resizable=True )
self.stageTab = stageTab
self.valueIndex = valueIndex # Index into the music table structure, relative to table entry
self.lineDict = {} # Tracks which song is on which line; key=lineNumber, value=musicFileObj
# Create the listbox, with a scrollbar
scrollbar = Tk.Scrollbar( self.window, )
self.listbox = Tk.Listbox( self.window, width=40, height=20, exportselection=0, activestyle='none', yscrollcommand=scrollbar.set )
self.listbox.bind( '<<ListboxSelect>>', self.selectionChanged )
self.listbox.grid( column=0, row=0, sticky='ns', padx=(6, 0) )
scrollbar.config( command=self.listbox.yview )
scrollbar.grid( column=1, row=0, sticky='ns', padx=(0, 6) )
# Construct a list of music file objects from the disc; start with vanilla songs
musicFiles = []
for musicId in range( 0, 0x62 ):
musicFile = globalData.disc.getMusicFile( musicId )
if not musicFile: continue
# Exclude fanfare (victory) audio clips and other short tracks most likely not wanted for music
elif musicFile.size < 0xF0000 or musicFile.filename == 'howto.hps':
if musicFile.filename not in ( '10.hps', 'inis2_02.hps' ): # Allow this track through (both are for MK2 Finale)
#print ' - skipping', hex(musicId), '|', musicFile.filename, '-', musicFile.longDescription
continue
musicFiles.append( musicFile )
# Add Hex Tracks if this is 20XX
if stageTab.stageSwapTable:
# Hex track number doesn't correspond to music ID, so tracks 0x30-0x62 haven't been included yet either
for musicId in range( 0x10030, 0x10100 ):
musicFile = globalData.disc.getMusicFile( musicId )
if musicFile:
musicFiles.append( musicFile )
# Populate the listbox
self.listbox.insert( 'end', 'None' )
self.lineDict[0] = None
lineToSelect = -1
for musicFile in musicFiles:
if musicFile.longDescription:
self.listbox.insert( 'end', musicFile.longDescription )
else:
self.listbox.insert( 'end', 'No description (' + musicFile.filename + ')' )
self.lineDict[len(self.lineDict)] = musicFile
if musicFile.musicId == initialSelection:
lineToSelect = len( self.lineDict ) - 1
# Create an ACM for this window
self.acm = AudioControlModule( self.window, self.stageTab.audioEngine )
self.acm.grid( column=0, columnspan=2, row=1, pady=4 )
self.listbox.bind( '<Double-1>', self.acm.playAudio )
# Select the current/initially set song
if lineToSelect != -1:
self.listbox.selection_set( lineToSelect )
self.acm.audioFile = self.lineDict[lineToSelect]
buttonsCell = ttk.Frame( self.window )
ttk.Button( buttonsCell, text='Select', command=self.selectSong ).grid( column=0, row=1, padx=10 )
ttk.Button( buttonsCell, text='Cancel', command=self.close ).grid( column=1, row=1, padx=10 )
buttonsCell.grid( column=0, columnspan=2, row=2, pady=4 )
self.window.columnconfigure( 0, weight=1 )
self.window.columnconfigure( (1,2), weight=0 )
self.window.rowconfigure( 'all', weight=1 )
def selectionChanged( self, event ):
""" Changes the file currently assigned to the ACM. """
lineNumber = self.listbox.curselection()[0]
self.acm.audioFile = self.lineDict[lineNumber]
def selectSong( self ):
""" Confirms the current selection, and sets the song's music ID in the stage file.
If Main Music or Alt. Main Music are changed, also update Sudden Death and Alt.
Sudden Death Music to be the same (this is the probable usual case, and can still
be changed independantly afterwards if the user wishes. """
# Get the song ID and name
lineNumber = self.listbox.curselection()[0]
musicFile = self.lineDict[lineNumber]
if musicFile:
musicId = musicFile.musicId
newSongName = musicFile.longDescription
else:
musicId = -1
newSongName = 'None'
# Get the index of the currently selected music table entry
entryIndex = self.stageTab.getMusicTableEntryIndex()
# Get the name of the target music selection, and its GUI label widget (the one displaying name info, not the description label)
if self.valueIndex == 1:
targetMusic = 'Main Music and Sudden Death Music'
labels = ( self.stageTab.mainMusicLabel, self.stageTab.suddenDeathMusicLabel )
toolTips = ( self.stageTab.toolTips['mainMusic'], self.stageTab.toolTips['suddenMusic'] )
elif self.valueIndex == 2:
targetMusic = 'Alt. Music and Sudden Death Alt. Music'
labels = ( self.stageTab.altMusicLabel, self.stageTab.altSuddenDeathLabel )
toolTips = ( self.stageTab.toolTips['altMusic'], self.stageTab.toolTips['altSuddenMusic'] )
elif self.valueIndex == 3:
targetMusic = 'Sudden Death Music'
labels = ( self.stageTab.suddenDeathMusicLabel, )
toolTips = ( self.stageTab.toolTips['suddenMusic'], )
elif self.valueIndex == 4:
targetMusic = 'Sudden Death Alt. Music'
labels = ( self.stageTab.altSuddenDeathLabel, )
toolTips = ( self.stageTab.toolTips['altSuddenMusic'], )
else:
raise Exception( 'Invalid valueIndex given to Song Chooser module: ' + str(self.valueIndex) )
# Construct a description for the change (for file.unsavedChanges, and for the program status bar)
origSongName = labels[0]['text'].split( '|' )[-1].strip()
userMessage = '{} of Music Table entry {} updated from {} to {}'.format(targetMusic, entryIndex+1, origSongName, newSongName)
# Update the value in the file structure
if self.valueIndex == 1 or self.valueIndex == 2: # Update both the main/alt music and the super sudden death main/alt music
self.stageTab.musicTableStruct.setEntryValue( entryIndex, self.valueIndex, musicId ) # Ignores extra steps which will be handled below
self.stageTab.selectedStage.updateStructValue( self.stageTab.musicTableStruct, self.valueIndex+2, musicId, userMessage, 'Music updated', entryIndex=entryIndex )
else:
self.stageTab.selectedStage.updateStructValue( self.stageTab.musicTableStruct, self.valueIndex, musicId, userMessage, 'Music updated', entryIndex=entryIndex )
# Update the GUI
globalData.gui.updateProgramStatus( userMessage )
for label in labels:
#label['text'] = '0x{:X} | {}'.format( musicId, newSongName )
label['text'] = uHex( musicId ) + ' | ' + newSongName
# Destroy the music control module (it may just be hidden). This will cause it to be recreated on next mouse-over
for toolTip in toolTips:
if toolTip._tipwindow:
toolTip._tipwindow.destroy()
toolTip._tipwindow = None
# Close this Song Chooser interface
self.close()
class StageManager( ttk.Frame ):
""" Info viewer and editor interface for stages in SSBM. """
stageTextureOffsets = { # Key=internalStageId, value=( icon, previewText, insignia )
0x02: ( 0xE2C0, 0x3C840, 0x2EB40 ), # Princess Peach's Castle
0x03: ( 0xF2E0, 0x3E0C0, 0x2EB40 ), # Rainbow Cruise
0x04: ( 0x10300, 0x3F940, 0x2F340 ), # Kongo Jungle
0x05: ( 0x11320, 0x411C0, 0x2F340 ), # Jungle Japes
0x06: ( 0x12340, 0x42A40, 0x2FB40 ), # Great Bay
0x07: ( 0x13360, 0x442C0, 0x2FB40 ), # Hyrule Temple
0x08: ( 0x14380, 0x45B40, 0x30340 ), # Brinstar
0x09: ( 0x153A0, 0x473C0, 0x30340 ), # Brinstar Depths
0x0A: ( 0x163C0, 0x48C40, 0x30B40 ), # Yoshi's Story
0x0B: ( 0x173E0, 0x4A4C0, 0x30B40 ), # Yoshi's Island
0x0C: ( 0x18400, 0x4BD40, 0x31340 ), # Fountain of Dreams
0x0D: ( 0x19420, 0x4D5C0, 0x31340 ), # Green Greens
0x0E: ( 0x1A440, 0x4EE40, 0x31B40 ), # Corneria
0x0F: ( 0x1B460, 0x506C0, 0x31B40 ), # Venom
0x10: ( 0x1C480, 0x51F40, 0x32340 ), # Pokemon Stadium
0x11: ( 0x1D4A0, 0x537C0, 0x32340 ), # Poke Floats
0x12: ( 0x1E4C0, 0x55040, 0x32B40 ), # Mute City
0x13: ( 0x1F4E0, 0x568C0, 0x32B40 ), # Big Blue
0x14: ( 0x20500, 0x58140, 0x33340 ), # Onett
0x15: ( 0x21520, 0x599C0, 0x33340 ), # Fourside
0x16: ( 0x24580, 0x5E340, 0x33B40 ), # Icicle Mountain
#0x17: ( 0x, 0x, 0x ), # Unused?
0x18: ( 0x22540, 0x5B240, 0x2EB40 ), # Mushroom Kingdom
0x19: ( 0x23560, 0x5CAC0, 0x2EB40 ), # Mushroom Kingdom II
#0x1A: ( 0x, 0x, 0x ), # Akaneia (Deleted Stage)
0x1B: ( 0x255A0, 0x5FBC0, 0x34340 ), # Flat Zone
0x1C: ( 0x28600, 0x64540, 0x31340 ), # Dream Land (N64)
0x1D: ( 0x29120, 0x65DC0, 0x30B40 ), # Yoshi's Island (N64)
0x1E: ( 0x29C40, 0x67640, 0x2F340 ), # Kongo Jungle (N64)
0x24: ( 0x265C0, 0x61440, 0x34B40 ), # Battlefield
0x25: ( 0x275E0, 0x62CC0, 0x35340 ), # Final Destination
}
def __init__( self, parent, mainGui ):
ttk.Frame.__init__( self, parent ) #, padding="11 0 0 11" ) # Padding order: Left, Top, Right, Bottom.
# Add this tab to the main GUI
mainGui.mainTabFrame.add( self, text=' Stage Manager ' )
# Create the primary set of tabs for the Stage Manager interface
# mainGui.style.configure( 'TNotebook', configure={"tabmargins": [2, 5, 2, 0]}, borderwidth=0 )
# mainGui.style.configure( 'TNotebook.Tab', configure={
# "borderwidth": 0,
# "bordercolor" : 'blue',
# "darkcolor" : 'blue',
# "lightcolor" : 'blue',
# "padding": [5, 1],
# "background": 'blue'
# } )
# "TNotebook": {
# "configure": {"tabmargins": [2, 5, 2, 0]},
# "borderwidth": 0
# }
# "TNotebook.Tab": {
# "configure": {
# "borderwidth": 0,
# "bordercolor" : BG_COLOUR,
# "darkcolor" : BG_COLOUR,
# "lightcolor" : BG_COLOUR,
# "padding": [5, 1], "background": BG_COLOUR
# }
# }
mainGui.style.configure( 'TNotebook', borderwidth=4 )
mainGui.style.configure( 'TNotebook.Tab', borderwidth=4 )
self.tabManager = ttk.Notebook( self, )
self.tabManager.pack( fill='both', expand=1 )
# Create the SSS tab as the main tab of the above notebook
sssTabFrame = ttk.Frame( self, borderwidth=0 )
self.tabManager.add( sssTabFrame, text='Stage Selection' )
self.selectedStage = None
self.selectedStageSlotId = -1 # Internal Stage ID for the vanilla slot, not necessarily the stage the slot is set to load
self.musicTableStruct = None
self.stageSwapTable = None # For use with 20XX
self.audioEngine = mainGui.audioEngine
self.toolTips = {}
padding = 6
# Add SSS page tabs
self.pagesNotebook = ttk.Notebook( sssTabFrame )
self.pagesNotebook.grid( column=0, row=0, pady=12 )
variationsLabelFrame = ttk.Frame( sssTabFrame ) # Padding order: Left, Top, Right, Bottom.
ttk.Label( variationsLabelFrame, text='- - Variations - -', foreground='blue' ).grid( column=0, row=0, pady=4 )
treeScroller = Tk.Scrollbar( variationsLabelFrame )
self.variationsTreeview = ttk.Treeview( variationsLabelFrame, selectmode='browse', show='tree', columns=('filename'), yscrollcommand=treeScroller.set, height=7 )
self.variationsTreeview.column( '#0', width=200 )
self.variationsTreeview.column( 'filename', width=90 )
self.variationsTreeview.tag_configure( 'fileNotFound', foreground='red' )
self.variationsTreeview.tag_configure( 'warning', foreground='#A0A000' ) # Shade of yellow
self.variationsTreeview.grid( column=0, row=1, sticky='ns' )
treeScroller.config( command=self.variationsTreeview.yview )
treeScroller.grid( column=1, row=1, sticky='ns' )
variationsLabelFrame.grid( column=1, row=0, padx=padding, pady=padding )
# Add treeview event handlers
self.variationsTreeview.bind( '<<TreeviewSelect>>', self.stageVariationSelected )
# self.variationsTreeview.bind( '<Double-1>', onFileTreeDoubleClick )
#self.variationsTreeview.bind( "<3>", self.createContextMenu ) # Right-click
# Construct the right-hand side of the interface, the info panels
row1 = ttk.Frame( sssTabFrame )
# Basic Info
basicLabelFrame = ttk.LabelFrame( row1, text=' Basic Info ', labelanchor='n', padding=8 )
ttk.Label( basicLabelFrame, text=('RSSS Name:\n'
'File Size:\n'
'Init Function:\n'
'OnGo Function:') ).grid( column=0, row=0, padx=(0, 5) )
self.basicInfoLabel = ttk.Label( basicLabelFrame, width=25 )
self.basicInfoLabel.grid( column=1, row=0 )
ttk.Button( basicLabelFrame, text='Edit Basic Properties', width=24, command=self.editBasicProperties ).grid( column=0, columnspan=2, row=1, pady=(3, 0) )
basicLabelFrame.grid( column=0, row=0, padx=(padding, 0), pady=padding )
# Stage Swap Details
fileLoadLabelFrame = ttk.LabelFrame( row1, text=' 20XX HP Stage Swap Details ', labelanchor='n', padding=8 )
ttk.Label( fileLoadLabelFrame, text=('Orig. Internal Stage ID:\n'
'New Internal Stage ID:\n'
'New External Stage ID:\n'
'Filename Offset:\n'
'Byte Replacement Offset:\n'
'Byte Replacement:\n'
'Stage Flags:') ).grid( column=0, row=0, padx=(0, 5) )
self.stageSwapDetailsLabel = ttk.Label( fileLoadLabelFrame, width=38 )
self.stageSwapDetailsLabel.grid( column=1, row=0 )
self.editStageSwapDetailsBtn = ttk.Button( fileLoadLabelFrame, text='Edit', width=8, command=self.editSwapDetails )
self.editStageSwapDetailsBtn.place( anchor='se', relx=1, rely=1 )
fileLoadLabelFrame.grid( column=1, columnspan=2, row=0, padx=0, pady=padding )
# Controls (basic functions like import/export)
#emptyWidget = Tk.Frame( relief='flat' ) # This is used as a simple workaround for the labelframe, so we can have no text label with no label gap.
#self.controlsFrame = ttk.Labelframe( row1, labelwidget=emptyWidget, padding=(20, 4) )
self.controlsFrame = ttk.LabelFrame( row1, text=' Stage File Operations ', labelanchor='n', padding=8 )
ttk.Button( self.controlsFrame, text='Export', command=self.exportStage ).grid( column=0, row=0, padx=4, pady=4 )
ttk.Button( self.controlsFrame, text='Import', command=self.importStage ).grid( column=1, row=0, padx=4, pady=4 )
ttk.Button( self.controlsFrame, text='Delete', command=self.deleteStage ).grid( column=0, row=2, padx=4, pady=4 )
ttk.Button( self.controlsFrame, text='Add Variation', command=self.addStageVariation ).grid( column=1, row=2, padx=4, ipadx=7, pady=4 )
ttk.Button( self.controlsFrame, text='Test', command=self.testStage ).grid( column=0, row=3, padx=4, pady=4 )
ttk.Button( self.controlsFrame, text='Rename', command=self.renameStage ).grid( column=1, row=3, padx=4, pady=4 )
rsssBtn = ttk.Button( self.controlsFrame, text='Rename RSSS Name', command=self.renameRsssName )
ToolTip( rsssBtn, 'Name shown on the\nRandom Stage Select Screen.', justify='center' )
rsssBtn.grid( column=0, columnspan=2, row=4, padx=4, pady=4, ipadx=9 )
self.controlsFrame.grid( column=3, row=0, padx=(0, padding), pady=padding )
row1.grid( column=0, columnspan=2, row=1, sticky='nsew' )
row1.columnconfigure( 'all', weight=1 )
row1.rowconfigure( 'all', weight=1 )
row2 = ttk.Frame( sssTabFrame )
# Music (entry selector and edit button)
musicLabelFrame = ttk.LabelFrame( row2, text=' Music Table ', labelanchor='n', padding=8 )
ttk.Label( musicLabelFrame, text='Music Table Entry: ' ).grid( column=0, row=0 )
self.musicTableEntry = Tk.StringVar()
self.musicTableOptionMenu = ttk.OptionMenu( musicLabelFrame, self.musicTableEntry, '', *[], command=self.selectMusicTableEntry )
self.musicTableOptionMenu['state'] = 'disabled'
self.musicTableOptionMenu.grid( column=0, columnspan=2, row=1, pady=(0, 8) )
#ttk.Button( musicLabelFrame, text='TEST', command=self.test ).place( anchor='ne', relx=1.0, rely=0 )
# Music (song labels)
ttk.Label( musicLabelFrame, text='External Stage ID:' ).grid( column=0, row=2, padx=(0, 5), sticky='w' )
self.extStageIdLabel = ttk.Label( musicLabelFrame, width=50 )
self.extStageIdLabel.grid( column=1, row=2, sticky='w' )
ttk.Label( musicLabelFrame, text='Main Music:' ).grid( column=0, row=3, padx=(0, 5), sticky='w' )
self.mainMusicLabel = ttk.Label( musicLabelFrame )
self.toolTips['mainMusic'] = MusicToolTip( self.mainMusicLabel, 1, self, delay=500, location='e' )
self.mainMusicLabel.grid( column=1, row=3, sticky='w' )
ttk.Label( musicLabelFrame, text='Alt. Music:' ).grid( column=0, row=4, padx=(0, 5), sticky='w' )
self.altMusicLabel = ttk.Label( musicLabelFrame )
self.toolTips['altMusic'] = MusicToolTip( self.altMusicLabel, 2, self, delay=500, location='e' )
self.altMusicLabel.grid( column=1, row=4, sticky='w' )
ttk.Label( musicLabelFrame, text='Sudden Death Music:' ).grid( column=0, row=5, padx=(0, 5), sticky='w' )
self.suddenDeathMusicLabel = ttk.Label( musicLabelFrame )
self.toolTips['suddenMusic'] = MusicToolTip( self.suddenDeathMusicLabel, 3, self, delay=500, location='e' )
self.suddenDeathMusicLabel.grid( column=1, row=5, sticky='w' )
ttk.Label( musicLabelFrame, text='Sudden Death Alt. Music:' ).grid( column=0, row=6, padx=(0, 5), sticky='w' )
self.altSuddenDeathLabel = ttk.Label( musicLabelFrame )
self.toolTips['altSuddenMusic'] = MusicToolTip( self.altSuddenDeathLabel, 4, self, delay=500, location='e' )
self.altSuddenDeathLabel.grid( column=1, row=6, sticky='w' )
# Music (behavior and alt music chance)
ttk.Label( musicLabelFrame, text='Music Behavior:' ).grid( column=0, row=7, padx=(0, 5), sticky='w' )
self.songBehaviorLabel = ttk.Label( musicLabelFrame )
self.toolTips['musicBehaviorEditor'] = ToolTipButton( self.songBehaviorLabel, self, delay=500, location='e', width=4 )
self.songBehaviorToolTipText = Tk.StringVar()
self.toolTips['musicBehavior'] = ToolTip( self.songBehaviorLabel, textvariable=self.songBehaviorToolTipText, delay=500, wraplength=350, location='e', offset=55 )
self.songBehaviorLabel.grid( column=1, row=7, sticky='w' )
ttk.Label( musicLabelFrame, text='Alt. Music % Chance:' ).grid( column=0, row=8, padx=(0, 5), sticky='w' )
self.altMusicChanceLabel = ttk.Label( musicLabelFrame )
self.toolTips['altChanceEditor'] = ToolTipEditor( self.altMusicChanceLabel, self, delay=500, location='e', width=4 )
self.altMusicChanceLabel.grid( column=1, row=8, sticky='w' )
musicLabelFrame.grid( column=0, columnspan=2, row=1, padx=(35, 0), pady=padding, sticky='ew' )
# Preview Text
previewTextLabelFrame = ttk.LabelFrame( row2, text=' Preview Text ', labelanchor='n', padding=8 )
self.previewTextCanvas = Tk.Canvas( previewTextLabelFrame, width=224, height=56, borderwidth=0, highlightthickness=0 )
self.previewTextCanvas.image = None # Used to store an image for this canvas, to prevent garbage collection
self.previewTextCanvas.pilImage = None
def noScroll( arg1, arg2 ): pass
self.previewTextCanvas.yview_scroll = noScroll
self.previewTextCanvas.grid( column=0, columnspan=3, row=0, pady=(2, 6) )
ttk.Label( previewTextLabelFrame, text='Top Text:' ).grid( column=0, row=1 )
self.previewTextTopTextEntry = ttk.Entry( previewTextLabelFrame, width=22 )
self.previewTextTopTextEntry.bind( '<Return>', self.generatePreviewText )
self.previewTextTopTextEntry.grid( column=1, columnspan=2, row=1, pady=3 )
ttk.Label( previewTextLabelFrame, text='Bottom Text:' ).grid( column=0, row=2 )
self.previewTextBottomTextEntry = ttk.Entry( previewTextLabelFrame, width=22 )
self.previewTextBottomTextEntry.bind( '<Return>', self.generatePreviewText )
self.previewTextBottomTextEntry.grid( column=1, columnspan=2, row=2, pady=3 )
previewBtn = ttk.Button( previewTextLabelFrame, text='Preview Texture', command=self.generatePreviewText )
previewBtn.grid( column=0, columnspan=2, row=3, pady=3, ipadx=7 )
ToolTip( previewBtn, text='Generates a new texture from the text entered above. Does not automatically save the texture to file; for that, hit Save.' )
saveBtn = ttk.Button( previewTextLabelFrame, text='Save', command=self.savePreviewText )
saveBtn.grid( column=2, row=3, pady=3 )
ToolTip( saveBtn, text='Saves the texture shown above to the current stage select screen file.' )
exportBtn = ttk.Button( previewTextLabelFrame, text='Export', command=self.exportPreviewText )
exportBtn.grid( column=0, columnspan=2, row=4, pady=3 )
ToolTip( exportBtn, text='Export the texture shown above to an external PNG/TPL file.' )
importBtn = ttk.Button( previewTextLabelFrame, text='Import', command=self.importPreviewText )
importBtn.grid( column=2, row=4, pady=3 )
ToolTip( importBtn, text='Import an external PNG/TPL file to the current stage select screen file.' )
previewTextLabelFrame.grid( columnspan=2, column=2, row=1, padx=35, pady=padding, sticky='ew' )
row2.grid( column=0, columnspan=2, row=2, sticky='nsew' )
row2.columnconfigure( 'all', weight=1 )
row2.rowconfigure( 'all', weight=1 )
# Configure window resize behavior
sssTabFrame.columnconfigure( 0, weight=3 )
sssTabFrame.columnconfigure( 1, weight=1 )
sssTabFrame.rowconfigure( 0, weight=0 )
sssTabFrame.rowconfigure( 1, weight=1 )
sssTabFrame.rowconfigure( 2, weight=1 )
def test( self ):
importGameFiles( multiple=False )
importGameFiles( multiple=True )
def clear( self ):
""" Clears and resets this tab's GUI contents. """
self.selectedStage = None
# Delete the current items in the canvases notebook
for tab in self.pagesNotebook.winfo_children():
tab.destroy()
# Delete the current items in the stage variations treeview
for item in self.variationsTreeview.get_children():
self.variationsTreeview.delete( item )
# Clear labels
self.basicInfoLabel['text'] = ''
self.stageSwapDetailsLabel['text'] = ''
# Clear the preview text canvas
self.previewTextCanvas.delete( 'all' )
self.previewTextCanvas.image = None
self.previewTextCanvas.pilImage = None
# Disable the controls for stages until a stage is selected
self.editStageSwapDetailsBtn['state'] = 'disabled'
for widget in self.controlsFrame.winfo_children():
widget['state'] = 'disabled'
self.clearMusicSection()
# Empty the text entry widgets for Preview Text
self.previewTextTopTextEntry.delete( 0, 'end' )
self.previewTextBottomTextEntry.delete( 0, 'end' )
def clearMusicSection( self ):
# Clear labels
self.basicInfoLabel['text'] = ''
self.extStageIdLabel['text'] = ''
self.mainMusicLabel['text'] = ''
self.altMusicLabel['text'] = ''
self.suddenDeathMusicLabel['text'] = ''
self.altSuddenDeathLabel['text'] = ''
self.songBehaviorLabel['text'] = ''
self.altMusicChanceLabel['text'] = ''
# Clear the music dropdown menu
self.musicTableOptionMenu['state'] = 'disabled'
self.musicTableOptionMenu.set_menu( None )
self.musicTableOptionMenu._variable.set( '' )
def getRsssName( self, stageSlotId ):
""" Gets the name for this stage used on the Random Stage Select Screen. """
# Construct the filename to pull the string from
if self.stageSwapTable: # Means it's 20XX
canvas = self.getCurrentCanvas()
filename = '/SdMenu.{}sd'.format( canvas.pageNumber )
else:
filename = '/SdMenu.usd'
sisFile = globalData.disc.files.get( globalData.disc.gameId + filename )
return sisFile.getStageMenuName( stageSlotId )
def updateBasicInfo( self, stageFile ):
rsssName = self.getRsssName( self.selectedStageSlotId ).encode( 'utf8' )
readableSize = humansize( stageFile.size )
self.basicInfoLabel['text'] = '{}\n{}\n{:X}\n{:X}'.format( rsssName, readableSize, stageFile.initFunction, stageFile.onGoFunction )
def editBasicProperties( self ):
""" Creates a new tab in the Textures Editor interface for the given file. """
# Create the new tab for the given file
stageFile = self.getSelectedStage()
if not stageFile:
msg( 'Please first select a stage to edit!', 'No Stage Selected', warning=True )
return
# Open the editor
newTab = StagePropertyEditor( self, stageFile )
self.tabManager.add( newTab, text=stageFile.filename )
# Switch to and populate the new tab
self.tabManager.select( newTab )
def updateSwapDetails( self, newIntStageId, newExtStageId, iFilenameOffset, byteReplacePointer, byteReplacement, randByteReplacements, stageFlags ):
""" Assesses values from the 20XX Stage Stap Table, and filenames from the DOL, to construct
strings to be displayed in the GUI for the Stage Swap Details information display panel. """
# Create a string for the original stage to load
origStageName = globalData.internalStageIds[self.selectedStageSlotId]
filename = self.dol.getStageFileName( self.selectedStageSlotId )[1]
origBaseStage = '0x{:X} | {} ({})'.format( self.selectedStageSlotId, origStageName, filename )
# Create a string for the new stage to load
# Check if the new stage is the same as the original stage (no file swap on the base stage)
if self.selectedStageSlotId == newIntStageId or newIntStageId == 0:
newBaseStage = '0x{:X} | {} (same)'.format( newIntStageId, origStageName ) # Use the same file description as above
elif newIntStageId == 0x1A: # i.e. external stage ID 0x15, Akaneia (a deleted stage)
newBaseStage = '0x1A | Akaneia (deleted stage)'
elif newIntStageId == 0x16: # i.e. external stage ID 0x1A, Icicle Mountain (anticipating no hacked stages of this); switch to current Target Test stage
newBaseStage = '0x16 | Current Target Test stage'
else:
# Use the internal ID to get the new stage name and file name
stageName = globalData.internalStageIds.get( newIntStageId, 'Unknown' )
#filename = globalData.stageFileNames.get( newIntStageId, 'Unknown' )
filename = self.dol.getStageFileName( newIntStageId )[1]
if stageName == 'Unknown':
print( 'Unable to find a stage name for internal stage ID ' + hex(newIntStageId) )
elif filename == 'Unknown':
print( 'Unable to find a stage filename for internal stage ID ' + hex(newIntStageId) )
newBaseStage = '0x{:X} | {} ({})'.format( newIntStageId, stageName, filename )
# Check for stKind (external stage ID description)
if newExtStageId == 0:
stkindString = 'N/A (no swap)'
else:
stkindDescription = globalData.externalStageIds.get( newExtStageId, 'Unidentified Ext. ID' )
stkindString = '0x{:X} | {}'.format( newExtStageId, stkindDescription )
# Create a string for the filename offset
sFilenameOffset = '0x{:X} | 0x{:X}'.format( self.dol.offsetInRAM(iFilenameOffset), iFilenameOffset )
# Create a string for the byte replacement offset and values
if byteReplacePointer == 0:
sByteReplaceOffset = 'N/A'
byteReplacement = 'N/A'
else:
dolByteReplaceOffset = self.dol.offsetInDOL( byteReplacePointer ) # Convert from a RAM address to a DOL offset
sByteReplaceOffset = '0x{:X} | 0x{:X}'.format( byteReplacePointer, dolByteReplaceOffset )
relativeOffset = dolByteReplaceOffset - iFilenameOffset