-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpuzzle.py
More file actions
7558 lines (5719 loc) · 295 KB
/
puzzle.py
File metadata and controls
7558 lines (5719 loc) · 295 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
#!/usr/bin/env python
import archive
import lz77
from QCodeEditor import QCodeEditor
import json
import os, os.path
import shutil
import struct
import sys
import threading
import time
from xml.etree import ElementTree as etree
from ctypes import create_string_buffer
from widgets.grass_widget import FlowerGrassWidget
from widgets.prof_widget import ProfileOverrideWidget
try:
from PyQt5 import QtCore, QtGui, QtWidgets
except ImportError:
from PySide2 import QtCore, QtGui, QtWidgets
Qt = QtCore.Qt
#try:
# from PIL import Image
#except ImportError:
# print("You have to install Pillow!")
# os._exit(0)
try:
import nsmblib
HaveNSMBLib = True
except ImportError:
HaveNSMBLib = False
SplitWindow = False
if hasattr(QtCore, 'pyqtSlot'): # PyQt
QtCoreSlot = QtCore.pyqtSlot
QtCoreSignal = QtCore.pyqtSignal
else: # PySide2
QtCoreSlot = QtCore.Slot
QtCoreSignal = QtCore.Signal
########################################################
# To Do:
#
# - Object Editor
# - Moving objects around
#
# - Make UI simpler for Pop
# - fix up conflicts with different types of parameters
# - C speed saving
# - quick settings for applying to mulitple slopes
#
########################################################
Tileset = None
def module_path():
"""
This will get us the program's directory, even if we are frozen
using PyInstaller
"""
if hasattr(sys, 'frozen') and hasattr(sys, '_MEIPASS'): # PyInstaller
if sys.platform == 'darwin': # macOS
# sys.executable is /x/y/z/puzzle.app/Contents/MacOS/puzzle
# We need to return /x/y/z/puzzle.app/Contents/Resources/
macos = os.path.dirname(sys.executable)
if os.path.basename(macos) != 'MacOS':
return None
return os.path.join(os.path.dirname(macos), 'Resources')
if __name__ == '__main__':
return os.path.dirname(os.path.abspath(sys.argv[0]))
return None
#############################################################################################
########################## Tileset Class and Tile/Object Subclasses #########################
class TilesetClass():
'''Contains Tileset data. Inits itself to a blank tileset.
Methods: addTile, removeTile, addObject, removeObject, clear'''
class Tile():
def __init__(self, image, noalpha, bytelist):
'''Tile Constructor'''
self.image = image
self.noalpha = noalpha
self.byte0 = bytelist[0]
self.byte1 = bytelist[1]
self.byte2 = bytelist[2]
self.byte3 = bytelist[3]
self.byte4 = bytelist[4]
self.byte5 = bytelist[5]
self.byte6 = bytelist[6]
self.byte7 = bytelist[7]
class Object():
def __init__(self, height, width, uslope, lslope, tilelist):
'''Tile Constructor'''
self.upperslope = uslope
self.lowerslope = lslope
assert (width, height) != 0
self.height = height
self.width = width
self.tiles = tilelist
self.determineRepetition()
if self.repeatX or self.repeatY:
height = len(self.tiles)
if self.height != height:
print("WARNING: Object height mismatches with the number of rows in the object.")
self.height = height
width = max(len(self.tiles[y]) for y in range(self.height))
if self.width != width:
print("WARNING: Object width mismatches with the maximum number of columns in the object.")
self.width = width
if self.repeatX:
self.determineRepetitionFinalize()
else:
# Fix a bug from a previous version of Puzzle
# where the actual width and height would
# mismatch with the number of tiles for the object
self.fillMissingTiles()
self.tilingMethodIdx = self.determineTilingMethod()
def determineRepetition(self):
self.repeatX = []
self.repeatY = []
if self.upperslope[0] != 0:
return
#### Find X Repetition ####
# You can have different X repetitions between rows, so we have to account for that
for y in range(self.height):
repeatXBn = -1
repeatXEd = -1
for x in range(len(self.tiles[y])):
if self.tiles[y][x][0] & 1 and repeatXBn == -1:
repeatXBn = x
elif not self.tiles[y][x][0] & 1 and repeatXBn != -1:
repeatXEd = x
break
if repeatXBn != -1:
if repeatXEd == -1:
repeatXEd = len(self.tiles[y])
self.repeatX.append((y, repeatXBn, repeatXEd))
#### Find Y Repetition ####
repeatYBn = -1
repeatYEd = -1
for y in range(self.height):
if len(self.tiles[y]) and self.tiles[y][0][0] & 2:
if repeatYBn == -1:
repeatYBn = y
elif repeatYBn != -1:
repeatYEd = y
break
if repeatYBn != -1:
if repeatYEd == -1:
repeatYEd = self.height
self.repeatY = [repeatYBn, repeatYEd]
def determineRepetitionFinalize(self):
if self.repeatX:
# If any X repetition is present, fill in rows which didn't have X repetition set
## Should never happen, unless the tileset is broken
## Additionally, sort the list
repeatX = []
for y in range(self.height):
for row, start, end in self.repeatX:
if y == row:
repeatX.append([start, end])
break
else:
# Get the start and end X offsets for the row
start = 0
end = len(self.tiles[y])
repeatX.append([start, end])
self.repeatX = repeatX
def fillMissingTiles(self):
realH = len(self.tiles)
while realH > self.height:
del self.tiles[-1]
realH -= 1
for row in self.tiles:
realW = len(row)
while realW > self.width:
del row[-1]
realW -= 1
for row in self.tiles:
realW = len(row)
while realW < self.width:
row.append((0, 0, 0))
realW += 1
while realH < self.height:
self.tiles.append([(0, 0, 0) for _ in range(self.width)])
realH += 1
def createRepetitionX(self):
self.repeatX = []
for y in range(self.height):
for x in range(len(self.tiles[y])):
self.tiles[y][x] = (self.tiles[y][x][0] | 1, self.tiles[y][x][1], self.tiles[y][x][2])
self.repeatX.append([0, len(self.tiles[y])])
def createRepetitionY(self, y1, y2):
self.clearRepetitionY()
for y in range(y1, y2):
for x in range(len(self.tiles[y])):
self.tiles[y][x] = (self.tiles[y][x][0] | 2, self.tiles[y][x][1], self.tiles[y][x][2])
self.repeatY = [y1, y2]
def clearRepetitionX(self):
self.fillMissingTiles()
for y in range(self.height):
for x in range(self.width):
self.tiles[y][x] = (self.tiles[y][x][0] & ~1, self.tiles[y][x][1], self.tiles[y][x][2])
self.repeatX = []
def clearRepetitionY(self):
for y in range(self.height):
for x in range(len(self.tiles[y])):
self.tiles[y][x] = (self.tiles[y][x][0] & ~2, self.tiles[y][x][1], self.tiles[y][x][2])
self.repeatY = []
def clearRepetitionXY(self):
self.clearRepetitionX()
self.clearRepetitionY()
def determineTilingMethod(self):
if self.upperslope[0] == 0x93:
return 7
elif self.upperslope[0] == 0x92:
return 6
elif self.upperslope[0] == 0x91:
return 5
elif self.upperslope[0] == 0x90:
return 4
elif self.repeatX and self.repeatY:
return 3
elif self.repeatY:
return 2
elif self.repeatX:
return 1
return 0
def __init__(self):
'''Constructor'''
self.tiles = []
self.objects = []
self.animdata = {}
self.unknownFiles = {}
self.animTilesBin = 0
self.randTilesBin = 0
self.slot = 0
self.placeNullChecked = False
def addTile(self, image, noalpha, bytelist = (0, 0, 0, 0, 0, 0, 0, 0)):
'''Adds an tile class to the tile list with the passed image or parameters'''
self.tiles.append(self.Tile(image, noalpha, bytelist))
def getUsedTiles(self):
usedTiles = []
for object in self.objects:
for i in range(len(object.tiles)):
for tile in object.tiles[i]:
if not tile[2] & 3 and Tileset.slot: # Pa0 tile 0 used in another slot, don't count it
continue
if tile[1] not in usedTiles:
usedTiles.append(tile[1])
return usedTiles
def addObject(self, height = 1, width = 1, uslope = [0, 0], lslope = [0, 0], tilelist = None, new = False):
'''Adds a new object'''
global Tileset
if new:
tilelist = [[(0, 0, Tileset.slot)]]
self.objects.append(self.Object(height, width, uslope, lslope, tilelist))
def removeObject(self, index):
'''Removes an Object by Index number. Don't use this much, because we want objects to preserve their ID.'''
self.objects.pop(index)
def clear(self):
'''Clears the tileset for a new file'''
self.tiles = []
self.objects = []
self.animdata = {}
self.unknownFiles = {}
self.animTilesBin = 0
self.randTilesBin = 0
#############################################################################################
###################################### AnimTiles Class ######################################
def readNullTerminated(data, pos):
end = data.find(b'\0', pos)
if end == -1:
return data[pos:]
return data[pos:end]
def readString(data, pos):
return readNullTerminated(data, pos).decode('utf8')
class AnimTilesClass():
'''Contains animation data'''
def __init__(self):
'''Constructor'''
self.animations = []
def addAnimation(self, animation):
'''Adds animation data'''
self.animations.append(animation)
def clear(self):
'''Clears everything for a new file'''
self.animations = []
#############################################################################################
###################################### RandTiles Class ######################################
class RandTilesClass():
'''Contains randomization data'''
def __init__(self):
'''Constructor'''
self.sections = []
def clear(self):
'''Clears everything for a new file'''
self.sections = []
#############################################################################################
######################### Palette for painting behaviours to tiles ##########################
class paletteWidget(QtWidgets.QWidget):
def __init__(self, window):
super(paletteWidget, self).__init__(window)
# Core Types Radio Buttons and Tooltips
self.coreType = QtWidgets.QGroupBox()
self.coreType.setTitle('Core Type:')
self.coreWidgets = []
coreLayout = QtWidgets.QVBoxLayout()
rowA = QtWidgets.QHBoxLayout()
rowB = QtWidgets.QHBoxLayout()
rowC = QtWidgets.QHBoxLayout()
rowD = QtWidgets.QHBoxLayout()
rowE = QtWidgets.QHBoxLayout()
rowF = QtWidgets.QHBoxLayout()
path = 'Icons/'
self.coreTypes = [['Default', QtGui.QIcon(path + 'Core/Default.png'), 'The standard type for tiles.\n\nAny regular terrain or backgrounds\nshould be of generic type. It has no\n collision properties.'],
['Slope', QtGui.QIcon(path + 'Core/Slope.png'), 'Defines a sloped tile\n\nSloped tiles have sloped collisions,\nwhich Mario can slide on.\n\nNote: Do NOT set slopes to have solid collision.'],
['Reverse Slope', QtGui.QIcon(path + 'Core/RSlope.png'), 'Defines an upside-down slope.\n\nSloped tiles have sloped collisions,\nwhich Mario can slide on.\n\nNote: Do NOT set slopes to have solid collision.'],
['Partial Block', QtGui.QIcon(path + 'Partial/Full.png'), 'Used for blocks with partial collisions.\n\nVery useful for Mini-Mario secret\nareas, but also for providing a more\naccurate collision map for your tiles.'],
['Coin', QtGui.QIcon(path + 'Core/Coin.png'), 'Creates a coin.\n\nCoins have no solid collision,\nand when touched will disappear\nand increment the coin counter.'],
['Explodable Block', QtGui.QIcon(path + 'Core/Explode.png'), 'Specifies blocks which can explode.\n\nThese blocks will shatter into componenent\npieces when hit by a bom-omb or meteor.\nThe pieces themselves may be hardcoded\nand must be included in the tileset.\nBehaviour may be sporadic.'],
['Climable Grid', QtGui.QIcon(path + 'Core/Climb.png'), 'Creates terrain that can be climbed on.\n\nClimable terrain cannot be walked on.\nWhen Mario is overtop of a climable\ntile and the player presses up,\nMario will enter a climbing state.'],
['Spike', QtGui.QIcon(path + 'Core/Spike.png'), 'Dangerous Spikey spikes.\n\nSpike tiles will damage Mario one hit\nwhen they are touched.'],
['Pipe', QtGui.QIcon(path + 'Core/Pipe.png'), "Denotes a pipe tile.\n\nPipe tiles are specified according to\nthe part of the pipe. It's important\nto specify the right parts or\nentrances will not function correctly."],
['Rails', QtGui.QIcon(path + 'Core/Rails.png'), 'Used for all types of rails.\n\nPlease note that Pa3_rail.arc is hardcoded\nto replace rails with 3D models.'],
['Conveyor Belt', QtGui.QIcon(path + 'Core/Conveyor.png'), 'Defines moving tiles.\n\nMoving tiles will move Mario in one\ndirection or another. Parameters are\nlargely unknown at this time.'],
['Question Block', QtGui.QIcon(path + 'Core/Qblock.png'), 'Creates question blocks.']]
i = 0
for item in range(len(self.coreTypes)):
self.coreWidgets.append(QtWidgets.QRadioButton())
if i == 0:
self.coreWidgets[item].setText('Default')
else:
self.coreWidgets[item].setIcon(self.coreTypes[item][1])
self.coreWidgets[item].setIconSize(QtCore.QSize(24, 24))
self.coreWidgets[item].setToolTip(self.coreTypes[item][2])
self.coreWidgets[item].clicked.connect(self.swapParams)
if i < 2:
rowA.addWidget(self.coreWidgets[item])
elif i < 4:
rowB.addWidget(self.coreWidgets[item])
elif i < 6:
rowC.addWidget(self.coreWidgets[item])
elif i < 8:
rowD.addWidget(self.coreWidgets[item])
elif i < 10:
rowE.addWidget(self.coreWidgets[item])
else:
rowF.addWidget(self.coreWidgets[item])
i += 1
coreLayout.addLayout(rowA)
coreLayout.addLayout(rowB)
coreLayout.addLayout(rowC)
coreLayout.addLayout(rowD)
coreLayout.addLayout(rowE)
coreLayout.addLayout(rowF)
self.coreType.setLayout(coreLayout)
# Properties Buttons. I hope this works well!
self.propertyGroup = QtWidgets.QGroupBox()
self.propertyGroup.setTitle('Properties:')
propertyLayout = QtWidgets.QVBoxLayout()
self.propertyWidgets = []
propertyList = [['Solid', QtGui.QIcon(path + 'Prop/Solid.png'), 'Tiles you can walk on.\n\nThe tiles we be a solid basic square\nthrough which Mario can not pass.'],
['Block', QtGui.QIcon(path + 'Prop/Break.png'), 'This denotes breakable tiles such\nas brick blocks. It is likely that these\nare subject to the same issues as\nexplodable blocks. They emit a coin\nwhen hit.'],
['Falling Block', QtGui.QIcon(path + 'Prop/Fall.png'), 'Sets the block to fall after a set period. The\nblock is sadly replaced with a donut lift model.'],
['Ledge', QtGui.QIcon(path + 'Prop/Ledge.png'), 'A ledge tile with unique properties.\n\nLedges can be shimmied along or\nhung from, but not walked along\nas with normal terrain. Must have the\nledge terrain type set as well.'],
['Meltable', QtGui.QIcon(path + 'Prop/Melt.png'), 'Supposedly allows melting the tile?']]
for item in range(len(propertyList)):
self.propertyWidgets.append(QtWidgets.QCheckBox(propertyList[item][0]))
self.propertyWidgets[item].setIcon(propertyList[item][1])
self.propertyWidgets[item].setIconSize(QtCore.QSize(24, 24))
self.propertyWidgets[item].setToolTip(propertyList[item][2])
propertyLayout.addWidget(self.propertyWidgets[item])
self.PassThrough = QtWidgets.QRadioButton('Pass-Through')
self.PassDown = QtWidgets.QRadioButton('Pass-Down')
self.PassNone = QtWidgets.QRadioButton('No Passing')
self.PassThrough.setIcon(QtGui.QIcon(path + 'Prop/Pup.png'))
self.PassDown.setIcon(QtGui.QIcon(path + 'Prop/Pdown.png'))
self.PassNone.setIcon(QtGui.QIcon(path + 'Prop/Pnone.png'))
self.PassThrough.setIconSize(QtCore.QSize(24, 24))
self.PassDown.setIconSize(QtCore.QSize(24, 24))
self.PassNone.setIconSize(QtCore.QSize(24, 24))
self.PassThrough.setToolTip('Allows Mario to jump through the bottom\nof the tile and land on the top.')
self.PassDown.setToolTip("Allows Mario to fall through the tile but\nbe able to jump up through it. Doesn't seem to actually do anything, though?")
self.PassNone.setToolTip('Default setting')
propertyLayout.addWidget(self.PassNone)
propertyLayout.addWidget(self.PassThrough)
propertyLayout.addWidget(self.PassDown)
self.propertyGroup.setLayout(propertyLayout)
# Terrain Type ComboBox
self.terrainType = QtWidgets.QComboBox()
self.terrainLabel = QtWidgets.QLabel('Terrain Type')
self.terrainTypes = [['Default', QtGui.QIcon(path + 'Core/Default.png')],
['Ice', QtGui.QIcon(path + 'Terrain/Ice.png')],
['Snow', QtGui.QIcon(path + 'Terrain/Snow.png')],
['Quicksand', QtGui.QIcon(path + 'Terrain/Quicksand.png')],
['Conveyor Belt Right', QtGui.QIcon(path + 'Core/Conveyor.png')],
['Conveyor Belt Left', QtGui.QIcon(path + 'Core/Conveyor.png')],
['Horiz. Climbing Rope', QtGui.QIcon(path + 'Terrain/Rope.png')],
['Anti Wall Jumps', QtGui.QIcon(path + 'Terrain/Spike.png')],
['Ledge', QtGui.QIcon(path + 'Terrain/Ledge.png')],
['Ladder', QtGui.QIcon(path + 'Terrain/Ladder.png')],
['Staircase', QtGui.QIcon(path + 'Terrain/Stairs.png')],
['Carpet', QtGui.QIcon(path + 'Terrain/Carpet.png')],
['Dusty', QtGui.QIcon(path + 'Terrain/Dust.png')],
['Grass', QtGui.QIcon(path + 'Terrain/Grass.png')],
['Muffled', QtGui.QIcon(path + 'Unknown.png')],
['Beach Sand', QtGui.QIcon(path + 'Terrain/Sand.png')]]
for item in range(len(self.terrainTypes)):
self.terrainType.addItem(self.terrainTypes[item][1], self.terrainTypes[item][0])
self.terrainType.setIconSize(QtCore.QSize(24, 24))
self.terrainType.setToolTip('Set the various types of terrain.'
'<ul>'
'<li><b>Default:</b><br>'
'Terrain with no particular properties.</li>'
'<li><b>Ice:</b><br>'
'Will be slippery.</li>'
'<li><b>Snow:</b><br>'
'Will emit puffs of snow and snow noises.</li>'
'<li><b>Quicksand:</b><br>'
'Will slowly swallow Mario. Required for creating the quicksand effect.</li>'
'<li><b>Conveyor Belt Right:</b><br>'
'Mario moves rightwards.</li>'
'<li><b>Conveyor Belt Left:</b><br>'
'Mario moves leftwards.</li>'
'<li><b>Horiz. Rope:</b><br>'
'Must be solid to function. Mario will move hand-over-hand along the rope.</li>'
'<li><b>Anti Wall Jumps:</b><br>'
'Mario cannot wall-jump off of the tile.</li>'
'<li><b>Ledge:</b><br>'
'Must have ledge property set as well.</li>'
'<li><b>Ladder:</b><br>'
'Acts as a pole. Mario will face right or left as he climbs.</li>'
'<li><b>Staircase:</b><br>'
'Does not allow Mario to slide.</li>'
'<li><b>Carpet:</b><br>'
'Will muffle footstep noises.</li>'
'<li><b>Dusty:</b><br>'
'Will emit puffs of dust.</li>'
'<li><b>Muffled:</b><br>'
'Mostly muffles footstep noises.</li>'
'<li><b>Grass:</b><br>'
'Will emit grass-like footstep noises.</li>'
'<li><b>Beach Sand:</b><br>'
"Will create sand tufts around Mario's feet.</li>"
'</ul>'
)
# Parameters ComboBox
self.parameters = QtWidgets.QComboBox()
self.parameterLabel = QtWidgets.QLabel('Parameters')
self.parameters.addItem('None')
GenericParams = [['None', QtGui.QIcon(path + 'Core/Default.png')],
['Beanstalk Stop', QtGui.QIcon(path + '/Generic/Beanstopper.png')],
['Dash Coin', QtGui.QIcon(path + 'Generic/Outline.png')],
['Battle Coin', QtGui.QIcon(path + 'Generic/Outline.png')],
['Red Block Outline A', QtGui.QIcon(path + 'Generic/RedBlock.png')],
['Red Block Outline B', QtGui.QIcon(path + 'Generic/RedBlock.png')],
['Cave Entrance Right', QtGui.QIcon(path + 'Generic/Cave-Right.png')],
['Cave Entrance Left', QtGui.QIcon(path + 'Generic/Cave-Left.png')],
['Unknown', QtGui.QIcon(path + 'Unknown.png')],
['Layer 0 Pit', QtGui.QIcon(path + 'Unknown.png')]]
RailParams = [['None', QtGui.QIcon(path + 'Core/Default.png')],
['Rail: Upslope', QtGui.QIcon(path + '')],
['Rail: Downslope', QtGui.QIcon(path + '')],
['Rail: 90 degree Corner Fill', QtGui.QIcon(path + '')],
['Rail: 90 degree Corner', QtGui.QIcon(path + '')],
['Rail: Horizontal Rail', QtGui.QIcon(path + '')],
['Rail: Vertical Rail', QtGui.QIcon(path + '')],
['Rail: Unknown', QtGui.QIcon(path + 'Unknown.png')],
['Rail: Gentle Upslope 2', QtGui.QIcon(path + '')],
['Rail: Gentle Upslope 1', QtGui.QIcon(path + '')],
['Rail: Gentle Downslope 2', QtGui.QIcon(path + '')],
['Rail: Gentle Downslope 1', QtGui.QIcon(path + '')],
['Rail: Steep Upslope 2', QtGui.QIcon(path + '')],
['Rail: Steep Upslope 1', QtGui.QIcon(path + '')],
['Rail: Steep Downslope 2', QtGui.QIcon(path + '')],
['Rail: Steep Downslope 1', QtGui.QIcon(path + '')],
['Rail: One Panel Circle', QtGui.QIcon(path + '')],
['Rail: 2x2 Circle Upper Right', QtGui.QIcon(path + '')],
['Rail: 2x2 Circle Upper Left', QtGui.QIcon(path + '')],
['Rail: 2x2 Circle Lower Right', QtGui.QIcon(path + '')],
['Rail: 2x2 Circle Lower Left', QtGui.QIcon(path + '')],
['Rail: 4x4 Circle Top Left Corner', QtGui.QIcon(path + '')],
['Rail: 4x4 Circle Top Left', QtGui.QIcon(path + '')],
['Rail: 4x4 Circle Top Right', QtGui.QIcon(path + '')],
['Rail: 4x4 Circle Top Right Corner', QtGui.QIcon(path + '')],
['Rail: 4x4 Circle Upper Left Side', QtGui.QIcon(path + '')],
['Rail: 4x4 Circle Upper Right Side', QtGui.QIcon(path + '')],
['Rail: 4x4 Circle Lower Left Side', QtGui.QIcon(path + '')],
['Rail: 4x4 Circle Lower Right Side', QtGui.QIcon(path + '')],
['Rail: 4x4 Circle Bottom Left Corner', QtGui.QIcon(path + '')],
['Rail: 4x4 Circle Bottom Left', QtGui.QIcon(path + '')],
['Rail: 4x4 Circle Bottom Right', QtGui.QIcon(path + '')],
['Rail: 4x4 Circle Bottom Right Corner', QtGui.QIcon(path + '')],
['Rail: Unknown', QtGui.QIcon(path + 'Unknown.png')],
['Rail: End Stop', QtGui.QIcon(path + '')]]
ClimableGridParams = [['None', QtGui.QIcon(path + 'Core/Default.png')],
['Free Move', QtGui.QIcon(path + 'Climb/Center.png')],
['Upper Left Corner', QtGui.QIcon(path + 'Climb/UpperLeft.png')],
['Top', QtGui.QIcon(path + 'Climb/Top.png')],
['Upper Right Corner', QtGui.QIcon(path + 'Climb/UpperRight.png')],
['Left Side', QtGui.QIcon(path + 'Climb/Left.png')],
['Center', QtGui.QIcon(path + 'Climb/Center.png')],
['Right Side', QtGui.QIcon(path + 'Climb/Right.png')],
['Lower Left Corner', QtGui.QIcon(path + 'Climb/LowerLeft.png')],
['Bottom', QtGui.QIcon(path + 'Climb/Bottom.png')],
['Lower Right Corner', QtGui.QIcon(path + 'Climb/LowerRight.png')]]
CoinParams = [['Generic Coin', QtGui.QIcon(path + 'QBlock/Coin.png')],
['Coin', QtGui.QIcon(path + 'Unknown.png')],
['Nothing', QtGui.QIcon(path + 'Unknown.png')],
['Coin', QtGui.QIcon(path + 'Unknown.png')],
['Pow Block Coin', QtGui.QIcon(path + 'Coin/POW.png')]]
ExplodableBlockParams = [['None', QtGui.QIcon(path + 'Core/Default.png')],
['Stone Block', QtGui.QIcon(path + 'Explode/Stone.png')],
['Wooden Block', QtGui.QIcon(path + 'Explode/Wooden.png')],
['Red Block', QtGui.QIcon(path + 'Explode/Red.png')],
['Unknown', QtGui.QIcon(path + 'Unknown.png')],
['Unknown', QtGui.QIcon(path + 'Unknown.png')],
['Unknown', QtGui.QIcon(path + 'Unknown.png')]]
PipeParams = [['Vert. Top Entrance Left', QtGui.QIcon(path + 'Pipes/')],
['Vert. Top Entrance Right', QtGui.QIcon(path + '')],
['Vert. Bottom Entrance Left', QtGui.QIcon(path + '')],
['Vert. Bottom Entrance Right', QtGui.QIcon(path + '')],
['Vert. Center Left', QtGui.QIcon(path + '')],
['Vert. Center Right', QtGui.QIcon(path + '')],
['Vert. On Top Junction Left', QtGui.QIcon(path + '')],
['Vert. On Top Junction Right', QtGui.QIcon(path + '')],
['Horiz. Left Entrance Top', QtGui.QIcon(path + '')],
['Horiz. Left Entrance Bottom', QtGui.QIcon(path + '')],
['Horiz. Right Entrance Top', QtGui.QIcon(path + '')],
['Horiz. Right Entrance Bottom', QtGui.QIcon(path + '')],
['Horiz. Center Left', QtGui.QIcon(path + '')],
['Horiz. Center Right', QtGui.QIcon(path + '')],
['Horiz. On Top Junction Top', QtGui.QIcon(path + '')],
['Horiz. On Top Junction Bottom', QtGui.QIcon(path + '')],
['Vert. Mini Pipe Top', QtGui.QIcon(path + '')],
['Unknown', QtGui.QIcon(path + 'Unknown.png')],
['Vert. Mini Pipe Bottom', QtGui.QIcon(path + '')],
['Unknown', QtGui.QIcon(path + 'Unknown.png')],
['Unknown', QtGui.QIcon(path + 'Unknown.png')],
['Unknown', QtGui.QIcon(path + 'Unknown.png')],
['Vert. On Top Mini-Junction', QtGui.QIcon(path + '')],
['Unknown', QtGui.QIcon(path + 'Unknown.png')],
['Horiz. Mini Pipe Left', QtGui.QIcon(path + '')],
['Unknown', QtGui.QIcon(path + 'Unknown.png')],
['Horiz. Mini Pipe Right', QtGui.QIcon(path + '')],
['Unknown', QtGui.QIcon(path + 'Unknown.png')],
['Vert. Mini Pipe Center', QtGui.QIcon(path + '')],
['Horiz. Mini Pipe Center', QtGui.QIcon(path + '')],
['Horiz. On Top Mini-Junction', QtGui.QIcon(path + '')],
['Block Covered Corner', QtGui.QIcon(path + '')]]
PartialBlockParams = [['None', QtGui.QIcon(path + 'Core/Default.png')],
['Upper Left', QtGui.QIcon(path + 'Partial/UpLeft.png')],
['Upper Right', QtGui.QIcon(path + 'Partial/UpRight.png')],
['Top Half', QtGui.QIcon(path + 'Partial/TopHalf.png')],
['Lower Left', QtGui.QIcon(path + 'Partial/LowLeft.png')],
['Left Half', QtGui.QIcon(path + 'Partial/LeftHalf.png')],
['Diagonal Downwards', QtGui.QIcon(path + 'Partial/DiagDn.png')],
['Upper Left 3/4', QtGui.QIcon(path + 'Partial/UpLeft3-4.png')],
['Lower Right', QtGui.QIcon(path + 'Partial/LowRight.png')],
['Diagonal Downwards', QtGui.QIcon(path + 'Partial/DiagDn.png')],
['Right Half', QtGui.QIcon(path + 'Partial/RightHalf.png')],
['Upper Right 3/4', QtGui.QIcon(path + 'Partial/UpRig3-4.png')],
['Lower Half', QtGui.QIcon(path + 'Partial/LowHalf.png')],
['Lower Left 3/4', QtGui.QIcon(path + 'Partial/LowLeft3-4.png')],
['Lower Right 3/4', QtGui.QIcon(path + 'Partial/LowRight3-4.png')],
['Full Brick', QtGui.QIcon(path + 'Partial/Full.png')]]
SlopeParams = [['Steep Upslope', QtGui.QIcon(path + 'Slope/steepslopeleft.png')],
['Steep Downslope', QtGui.QIcon(path + 'Slope/steepsloperight.png')],
['Upslope 1', QtGui.QIcon(path + 'Slope/slopeleft.png')],
['Upslope 2', QtGui.QIcon(path + 'Slope/slope3left.png')],
['Downslope 1', QtGui.QIcon(path + 'Slope/slope3right.png')],
['Downslope 2', QtGui.QIcon(path + 'Slope/sloperight.png')],
['Steep Upslope 1', QtGui.QIcon(path + 'Slope/vsteepup1.png')],
['Steep Upslope 2', QtGui.QIcon(path + 'Slope/vsteepup2.png')],
['Steep Downslope 1', QtGui.QIcon(path + 'Slope/vsteepdown1.png')],
['Steep Downslope 2', QtGui.QIcon(path + 'Slope/vsteepdown2.png')],
['Slope Edge (solid)', QtGui.QIcon(path + 'Slope/edge.png')],
['Gentle Upslope 1', QtGui.QIcon(path + 'Slope/gentleupslope1.png')],
['Gentle Upslope 2', QtGui.QIcon(path + 'Slope/gentleupslope2.png')],
['Gentle Upslope 3', QtGui.QIcon(path + 'Slope/gentleupslope3.png')],
['Gentle Upslope 4', QtGui.QIcon(path + 'Slope/gentleupslope4.png')],
['Gentle Downslope 1', QtGui.QIcon(path + 'Slope/gentledownslope1.png')],
['Gentle Downslope 2', QtGui.QIcon(path + 'Slope/gentledownslope2.png')],
['Gentle Downslope 3', QtGui.QIcon(path + 'Slope/gentledownslope3.png')],
['Gentle Downslope 4', QtGui.QIcon(path + 'Slope/gentledownslope4.png')]]
ReverseSlopeParams = [['Steep Downslope', QtGui.QIcon(path + 'Slope/Rsteepslopeleft.png')],
['Steep Upslope', QtGui.QIcon(path + 'Slope/Rsteepsloperight.png')],
['Downslope 1', QtGui.QIcon(path + 'Slope/Rslopeleft.png')],
['Downslope 2', QtGui.QIcon(path + 'Slope/Rslope3left.png')],
['Upslope 1', QtGui.QIcon(path + 'Slope/Rslope3right.png')],
['Upslope 2', QtGui.QIcon(path + 'Slope/Rsloperight.png')],
['Steep Downslope 1', QtGui.QIcon(path + 'Slope/Rvsteepdown1.png')],
['Steep Downslope 2', QtGui.QIcon(path + 'Slope/Rvsteepdown2.png')],
['Steep Upslope 1', QtGui.QIcon(path + 'Slope/Rvsteepup1.png')],
['Steep Upslope 2', QtGui.QIcon(path + 'Slope/Rvsteepup2.png')],
['Slope Edge (solid)', QtGui.QIcon(path + 'Slope/edge.png')],
['Gentle Downslope 1', QtGui.QIcon(path + 'Slope/Rgentledownslope1.png')],
['Gentle Downslope 2', QtGui.QIcon(path + 'Slope/Rgentledownslope2.png')],
['Gentle Downslope 3', QtGui.QIcon(path + 'Slope/Rgentledownslope3.png')],
['Gentle Downslope 4', QtGui.QIcon(path + 'Slope/Rgentledownslope4.png')],
['Gentle Upslope 1', QtGui.QIcon(path + 'Slope/Rgentleupslope1.png')],
['Gentle Upslope 2', QtGui.QIcon(path + 'Slope/Rgentleupslope2.png')],
['Gentle Upslope 3', QtGui.QIcon(path + 'Slope/Rgentleupslope3.png')],
['Gentle Upslope 4', QtGui.QIcon(path + 'Slope/Rgentleupslope4.png')]]
SpikeParams = [['Double Left Spikes', QtGui.QIcon(path + 'Spike/Left.png')],
['Double Right Spikes', QtGui.QIcon(path + 'Spike/Right.png')],
['Double Upwards Spikes', QtGui.QIcon(path + 'Spike/Up.png')],
['Double Downwards Spikes', QtGui.QIcon(path + 'Spike/Down.png')],
['Long Spike Down 1', QtGui.QIcon(path + 'Spike/LongDown1.png')],
['Long Spike Down 2', QtGui.QIcon(path + 'Spike/LongDown2.png')],
['Single Downwards Spike', QtGui.QIcon(path + 'Spike/SingDown.png')],
['Spike Block', QtGui.QIcon(path + 'Unknown.png')]]
ConveyorBeltParams = [['Slow', QtGui.QIcon(path + 'Unknown.png')],
['Fast', QtGui.QIcon(path + 'Unknown.png')]]
QBlockParams = [['Fire Flower', QtGui.QIcon(path + 'Qblock/Fire.png')],
['Star', QtGui.QIcon(path + 'Qblock/Star.png')],
['Coin', QtGui.QIcon(path + 'Qblock/Coin.png')],
['Vine', QtGui.QIcon(path + 'Qblock/Vine.png')],
['1-Up', QtGui.QIcon(path + 'Qblock/1up.png')],
['Mini Mushroom', QtGui.QIcon(path + 'Qblock/Mini.png')],
['Propeller Suit', QtGui.QIcon(path + 'Qblock/Prop.png')],
['Penguin Suit', QtGui.QIcon(path + 'Qblock/Peng.png')],
['Ice Flower', QtGui.QIcon(path + 'Qblock/IceF.png')]]
self.ParameterList = [GenericParams,
SlopeParams,
ReverseSlopeParams,
PartialBlockParams,
CoinParams,
ExplodableBlockParams,
ClimableGridParams,
SpikeParams,
PipeParams,
RailParams,
ConveyorBeltParams,
QBlockParams]
layout = QtWidgets.QGridLayout()
layout.addWidget(self.coreType, 0, 1)
layout.addWidget(self.propertyGroup, 0, 0, 3, 1)
layout.addWidget(self.terrainType, 2, 1)
layout.addWidget(self.parameters, 1, 1)
self.setLayout(layout)
def swapParams(self):
for item in range(len(self.ParameterList)):
if self.coreWidgets[item].isChecked():
self.parameters.clear()
for option in self.ParameterList[item]:
self.parameters.addItem(option[1], option[0])
#############################################################################################
######################### InfoBox Custom Widget to display info to ##########################
class InfoBox(QtWidgets.QWidget):
def __init__(self, window):
super(InfoBox, self).__init__(window)
# InfoBox
superLayout = QtWidgets.QGridLayout()
infoLayout = QtWidgets.QFormLayout()
self.imageBox = QtWidgets.QGroupBox()
imageLayout = QtWidgets.QHBoxLayout()
pix = QtGui.QPixmap(24, 24)
pix.fill(Qt.transparent)
self.coreImage = QtWidgets.QLabel()
self.coreImage.setPixmap(pix)
self.terrainImage = QtWidgets.QLabel()
self.terrainImage.setPixmap(pix)
self.parameterImage = QtWidgets.QLabel()
self.parameterImage.setPixmap(pix)
def updateAllTiles():
for i in range(256):
window.tileDisplay.update(window.tileDisplay.model().index(i, 0))
self.collisionOverlay = QtWidgets.QCheckBox('Overlay Collision')
self.collisionOverlay.clicked.connect(updateAllTiles)
self.toggleAlpha = QtWidgets.QCheckBox('Toggle Alpha')
self.toggleAlpha.clicked.connect(window.toggleAlpha)
class QScreenshot(QtWidgets.QSplashScreen):
def __init__(self, screenshot):
super().__init__(screenshot)
def showScreenshot():
self.image = window.tileDisplay.grab()
self.image = self.image.scaled(self.image.width()*2, self.image.height()*2)
self.screenshotWindow = QScreenshot(self.image)
self.screenshotWindow.show()
self.screenshotButton = QtWidgets.QPushButton('View enlarged screenshot')
self.screenshotButton.released.connect(showScreenshot)
self.coreInfo = QtWidgets.QLabel()
self.terrainInfo = QtWidgets.QLabel()
self.paramInfo = QtWidgets.QLabel()
self.propertyBox = QtWidgets.QGroupBox()
self.propertyInfo = QtWidgets.QLabel('Properties:\nNone \n\n\n\n\n')
self.propertyInfo.setWordWrap(True)
self.propertyInfo.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum)
Font = self.font()
Font.setPointSize(9)
self.coreInfo.setFont(Font)
self.propertyInfo.setFont(Font)
self.terrainInfo.setFont(Font)
self.paramInfo.setFont(Font)
self.hexdata = QtWidgets.QLabel('Hex Data: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00')
self.hexdata.setFont(Font)
self.numInfo = QtWidgets.QLabel('Slot: 0 Row: 0 Column: 0')
self.numInfo.setFont(Font)
coreLayout = QtWidgets.QVBoxLayout()
terrLayout = QtWidgets.QVBoxLayout()
paramLayout = QtWidgets.QVBoxLayout()
coreLayout.setGeometry(QtCore.QRect(0,0,40,40))
terrLayout.setGeometry(QtCore.QRect(0,0,40,40))
paramLayout.setGeometry(QtCore.QRect(0,0,40,40))
label = QtWidgets.QLabel('Core')
label.setFont(Font)
coreLayout.addWidget(label, 0, Qt.AlignCenter)
label = QtWidgets.QLabel('Terrain')
label.setFont(Font)
terrLayout.addWidget(label, 0, Qt.AlignCenter)
label = QtWidgets.QLabel('Parameters')
label.setFont(Font)
paramLayout.addWidget(label, 0, Qt.AlignCenter)
coreLayout.addWidget(self.coreImage, 0, Qt.AlignCenter)
terrLayout.addWidget(self.terrainImage, 0, Qt.AlignCenter)
paramLayout.addWidget(self.parameterImage, 0, Qt.AlignCenter)
coreLayout.addWidget(self.coreInfo, 0, Qt.AlignCenter)
terrLayout.addWidget(self.terrainInfo, 0, Qt.AlignCenter)
paramLayout.addWidget(self.paramInfo, 0, Qt.AlignCenter)
imageLayout.setContentsMargins(0,4,4,4)
imageLayout.addLayout(coreLayout)
imageLayout.addStretch()
imageLayout.addLayout(terrLayout)
imageLayout.addStretch()
imageLayout.addLayout(paramLayout)
self.imageBox.setLayout(imageLayout)
infoLayout.setContentsMargins(0,4,4,4)
infoLayout.addRow(self.propertyInfo)
self.propertyBox.setLayout(infoLayout)
self.setMinimumWidth(800)
#self.setMaximumWidth(1000)
superLayout.addWidget(self.imageBox, 0, 2, 1, 2)
superLayout.addWidget(self.propertyBox, 0, 0, 1, 2)
superLayout.addWidget(self.hexdata, 1, 0, 1, 4, Qt.AlignCenter)
superLayout.addWidget(self.numInfo, 2, 0, 1, 4, Qt.AlignCenter)
superLayout.addWidget(self.collisionOverlay, 3, 0, 1, 1)
superLayout.addWidget(self.toggleAlpha, 3, 1, 1, 2, Qt.AlignCenter)
superLayout.addWidget(self.screenshotButton, 3, 3, 1, 1, Qt.AlignRight)
self.setLayout(superLayout)
#############################################################################################
##################### Framesheet List Widget and Model Setup with Painter #######################
class framesheetList(QtWidgets.QListView):
def __init__(self, parent=None):
super(framesheetList, self).__init__(parent)
self.setViewMode(QtWidgets.QListView.IconMode)
self.setHeight()
self.setMovement(QtWidgets.QListView.Static)
self.setBackgroundRole(QtGui.QPalette.BrightText)
self.setWrapping(False)
self.setMinimumHeight(512)
self.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
def setHeight(self):
height = getFramesheetGridSize()
self.setIconSize(QtCore.QSize(32, height))
self.setGridSize(QtCore.QSize(200,height+50))
def getFramesheetGridSize():
global Tileset
max = 0
for key in list(Tileset.animdata.keys()):
t = len(Tileset.animdata[key])//64
if t > max:
max = t
return max
def SetupFramesheetModel(self, animdata):
global Tileset
self.framesheetList.setHeight()
self.framesheetmodel.clear()
self.frames = {}
frames = []
count = 0
for key in list(animdata.keys()):
height = len(animdata[key])//64
image = QtGui.QImage(32, height, QtGui.QImage.Format_ARGB32)
frame = QtGui.QImage(32, 32, QtGui.QImage.Format_ARGB32)
bytes = animdata[key]
bits = ''.join(format(byte, '08b') for byte in bytes)
Xoffset = 0