-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathwidgets.py
5842 lines (4715 loc) · 233 KB
/
widgets.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/env python3
# -*- coding: utf-8 -*-
# Miyamoto! Level Editor - New Super Mario Bros. U Level Editor
# Copyright (C) 2009-2021 Treeki, Tempus, angelsl, JasonP27, Kinnay,
# MalStar1000, RoadrunnerWMC, MrRean, Grop, AboodXD, Gota7, John10v10,
# mrbengtsson
# This file is part of Miyamoto!.
# Miyamoto! is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Miyamoto! is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Miyamoto!. If not, see <http://www.gnu.org/licenses/>.
################################################################
################################################################
############ Imports ############
import json
from math import sqrt
import os
import re
import struct
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
Qt = QtCore.Qt
import globals
from items import ObjectItem, ZoneItem, LocationItem, SpriteItem
from items import EntranceItem, PathItem, NabbitPathItem
from items import PathEditorLineItem, NabbitPathEditorLineItem
from items import CommentItem
# from loading import LoadSpriteData, LoadSpriteListData
# from loading import LoadSpriteCategories, LoadEntranceNames
from misc import clipStr, setting, setSetting, drawForegroundGrid
from quickpaint import QuickPaintOperations
from stamp import StampListModel
from tileset import TilesetTile, ObjectDef, objFitsInTileset
from tileset import addObjToTilesetImpl, addObjToTileset, exportObject
from tileset import HandleTilesetEdited, DeleteObject, RenderObject
from tileset import RenderObjectAll, ProcessOverrides, SimpleTilesetNames
from ui import createHorzLine, createVertLine, GetIcon
from verifications import SetDirty
#################################
class LevelOverviewWidget(QtWidgets.QWidget):
"""
Widget that shows an overview of the level and can be clicked to move the view
"""
moveIt = QtCore.pyqtSignal(int, int)
def __init__(self):
"""
Constructor for the level overview widget
"""
super().__init__()
self.setSizePolicy(
QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding))
self.bgbrush = QtGui.QBrush(globals.theme.color('bg'))
self.objbrush = QtGui.QBrush(globals.theme.color('overview_object'))
self.viewbrush = QtGui.QBrush(globals.theme.color('overview_zone_fill'))
self.view = QtCore.QRectF(0, 0, 0, 0)
self.spritebrush = QtGui.QBrush(globals.theme.color('overview_sprite'))
self.entrancebrush = QtGui.QBrush(globals.theme.color('overview_entrance'))
self.locationbrush = QtGui.QBrush(globals.theme.color('overview_location_fill'))
self.Reset()
self.Xposlocator = 0
self.Yposlocator = 0
self.Hlocator = 50
self.Wlocator = 80
self.mainWindowScale = 1
def Reset(self):
"""
Resets the max and scale variables
"""
self.CalcSize()
self.Rescale()
def mouseMoveEvent(self, event):
"""
Handles mouse movement over the widget
"""
QtWidgets.QWidget.mouseMoveEvent(self, event)
if event.buttons() == Qt.LeftButton:
self.moveIt.emit(event.pos().x() * self.posmult, event.pos().y() * self.posmult)
def mousePressEvent(self, event):
"""
Handles mouse pressing events over the widget
"""
QtWidgets.QWidget.mousePressEvent(self, event)
if event.button() == Qt.LeftButton:
self.moveIt.emit(event.pos().x() * self.posmult, event.pos().y() * self.posmult)
def paintEvent(self, event):
"""
Paints the level overview widget
"""
if not hasattr(globals.Area, 'layers'):
# fixes race condition where this widget is painted after
# the level is created, but before it's loaded
return
painter = QtGui.QPainter(self)
painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
self.Reset()
painter.scale(self.scale, self.scale)
painter.fillRect(0, 0, 1024, 512, self.bgbrush)
dr = painter.drawRect
fr = painter.fillRect
transform = QtGui.QTransform() / globals.TileWidth
b = self.viewbrush
painter.setPen(QtGui.QPen(globals.theme.color('overview_zone_lines'), 1))
for zone in globals.Area.zones:
r = transform.mapRect(zone.sceneBoundingRect())
fr(r, b)
dr(r)
b = self.objbrush
for layer in globals.Area.layers:
for obj in layer:
fr(obj.LevelRect, b)
b = self.spritebrush
for sprite in globals.Area.sprites:
fr(sprite.LevelRect, b)
b = self.entrancebrush
for ent in globals.Area.entrances:
fr(ent.LevelRect, b)
b = self.locationbrush
painter.setPen(QtGui.QPen(globals.theme.color('overview_location_lines'), 1))
for location in globals.Area.locations:
r = transform.mapRect(location.sceneBoundingRect())
fr(r, b)
dr(r)
painter.setPen(QtGui.QPen(globals.theme.color('overview_viewbox'), 1))
painter.drawRect(QtCore.QRectF(
self.Xposlocator / globals.TileWidth / self.mainWindowScale,
self.Yposlocator / globals.TileWidth / self.mainWindowScale,
self.Wlocator / globals.TileWidth / self.mainWindowScale,
self.Hlocator / globals.TileWidth / self.mainWindowScale
))
def CalcSize(self):
"""
Calculates all the required sizes for this scale
"""
if not globals.Area:
self.maxX = 0
self.maxY = 0
return
transform = QtGui.QTransform() / globals.TileWidth
rect = QtCore.QRectF()
for zone in globals.Area.zones:
rect |= transform.mapRect(zone.sceneBoundingRect())
for layer in globals.Area.layers:
for obj in layer:
rect |= obj.LevelRect
for sprite in globals.Area.sprites:
rect |= sprite.LevelRect
for ent in globals.Area.entrances:
rect |= ent.LevelRect
for location in globals.Area.locations:
rect |= transform.mapRect(location.sceneBoundingRect())
self.maxX = rect.right()
self.maxY = rect.bottom()
def Rescale(self):
"""
Calculates self.scale and self.posmult
"""
self.scale = max(0.002, min(self.width() / (self.maxX + 45), self.height() / (self.maxY + 25)))
self.posmult = globals.TileWidth / self.scale
class QuickPaintConfigWidget(QtWidgets.QWidget):
"""
Widget that allows the user to configure tiles and objects for quick paint.
"""
moveIt = QtCore.pyqtSignal(int, int)
def __init__(self):
"""
Constructor for the quick paint confirmation widget
"""
QtWidgets.QWidget.__init__(self)
self.setSizePolicy(
QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding))
self.QuickPaintMode = None
self.gridLayout = QtWidgets.QGridLayout(self)
self.gridLayout.setObjectName("gridLayout")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.PaintModeCheck = QtWidgets.QPushButton(self)
self.PaintModeCheck.setMinimumSize(QtCore.QSize(0, 40))
self.PaintModeCheck.clicked.connect(self.SetPaintMode)
self.PaintModeCheck.setCheckable(True)
self.PaintModeCheck.setObjectName("PaintModeCheck")
self.horizontalLayout_2.addWidget(self.PaintModeCheck)
self.EraseModeCheck = QtWidgets.QPushButton(self)
self.EraseModeCheck.setMinimumSize(QtCore.QSize(0, 40))
self.EraseModeCheck.clicked.connect(self.SetEraseMode)
self.EraseModeCheck.setCheckable(True)
self.EraseModeCheck.setObjectName("EraseModeCheck")
self.horizontalLayout_2.addWidget(self.EraseModeCheck)
self.gridLayout.addLayout(self.horizontalLayout_2, 4, 0, 1, 1)
self.horizontalScrollBar = QtWidgets.QScrollBar(self)
self.horizontalScrollBar.setOrientation(Qt.Horizontal)
self.horizontalScrollBar.setValue(50)
self.horizontalScrollBar.valueChanged.connect(self.horizontalScrollBar_changed)
self.horizontalScrollBar.setObjectName("horizontalScrollBar")
self.gridLayout.addWidget(self.horizontalScrollBar, 2, 0, 1, 1)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setSpacing(5)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label_4 = QtWidgets.QLabel(self)
self.label_4.setMaximumSize(QtCore.QSize(60, 30))
self.label_4.setObjectName("label_4")
self.horizontalLayout.addWidget(self.label_4)
self.comboBox_4 = QtWidgets.QComboBox(self)
self.comboBox_4.activated.connect(self.currentPresetIndexChanged)
self.comboBox_4.setObjectName("comboBox_4")
self.horizontalLayout.addWidget(self.comboBox_4)
self.SaveToPresetButton = QtWidgets.QPushButton(self)
self.SaveToPresetButton.setMaximumSize(QtCore.QSize(60, 30))
self.SaveToPresetButton.setBaseSize(QtCore.QSize(0, 0))
self.SaveToPresetButton.setCheckable(False)
self.SaveToPresetButton.clicked.connect(self.saveToCurrentPresetConfirm)
self.SaveToPresetButton.setEnabled(False)
self.SaveToPresetButton.setObjectName("SaveToPresetButton")
self.horizontalLayout.addWidget(self.SaveToPresetButton)
self.AddPresetButton = QtWidgets.QPushButton(self)
self.AddPresetButton.setMaximumSize(QtCore.QSize(60, 30))
self.AddPresetButton.setBaseSize(QtCore.QSize(0, 0))
self.AddPresetButton.clicked.connect(self.openTextForm)
self.AddPresetButton.setObjectName("AddPresetButton")
self.horizontalLayout.addWidget(self.AddPresetButton)
self.RemovePresetButton = QtWidgets.QPushButton(self)
self.RemovePresetButton.setMaximumSize(QtCore.QSize(60, 30))
self.RemovePresetButton.clicked.connect(self.removeCurrentPresetConfirm)
self.RemovePresetButton.setObjectName("RemovePresetButton")
self.horizontalLayout.addWidget(self.RemovePresetButton)
self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 1)
self.graphicsView = self.QuickPaintView(None, self)
self.graphicsView.setObjectName("graphicsView")
self.reset()
self.gridLayout.addWidget(self.graphicsView, 1, 0, 1, 1)
self.verticalScrollBar = QtWidgets.QScrollBar(self)
self.verticalScrollBar.setOrientation(Qt.Vertical)
self.verticalScrollBar.valueChanged.connect(self.verticalScrollBar_changed)
self.verticalScrollBar.setValue(50)
self.verticalScrollBar.setObjectName("verticalScrollBar")
self.gridLayout.addWidget(self.verticalScrollBar, 1, 1, 1, 1)
self.ZoomButton = QtWidgets.QPushButton(self)
self.ZoomButton.setMinimumSize(QtCore.QSize(30, 30))
self.ZoomButton.setMaximumSize(QtCore.QSize(30, 30))
self.ZoomButton.setObjectName("ZoomButton")
self.ZoomButton.clicked.connect(self.zoom)
self.gridLayout.addWidget(self.ZoomButton, 0, 1, 1, 1)
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
self.setTabOrder(self.AddPresetButton, self.comboBox_4)
self.setTabOrder(self.comboBox_4, self.RemovePresetButton)
self.show_badObjWarning = False
def SetPaintMode(self):
"""
Sets the Quick-Paint Mode to paint or turn off.
"""
# self.SlopeModeCheck.setChecked(False)
self.EraseModeCheck.setChecked(False)
if self.PaintModeCheck.isChecked():
self.QuickPaintMode = 'PAINT'
else:
self.QuickPaintMode = None
globals.mainWindow.scene.update()
# I don't know if slopes will be supported in the future or not. But for now this function is useless.
"""
def SetSlopeMode(self):
self.PaintModeCheck.setChecked(False)
self.EraseModeCheck.setChecked(False)
if self.SlopeModeCheck.isChecked():
self.QuickPaintMode = 'SLOPE'
else:
self.QuickPaintMode = None
"""
def SetEraseMode(self):
"""
Sets the Quick-Paint Mode to erase or turn off.
"""
self.PaintModeCheck.setChecked(False)
# self.SlopeModeCheck.setChecked(False)
if self.EraseModeCheck.isChecked():
self.QuickPaintMode = 'ERASE'
else:
self.QuickPaintMode = None
globals.mainWindow.scene.update()
def reset(self):
setoffsets = False
if hasattr(self, 'scene'):
panoffsets = (self.scene.xoffset,self.scene.yoffset)
del self.scene
setoffsets = True
self.scene = self.QuickPaintScene(self)
if setoffsets:
self.scene.xoffset = panoffsets[0]
self.scene.yoffset = panoffsets[1]
self.graphicsView.setScene(self.scene)
self.comboBox_4.setCurrentIndex(-1)
def currentPresetIndexChanged(self, index):
"""
Handles the change of index of the saved presets context menu and loads the preset.
"""
self.SaveToPresetButton.setEnabled(index != -1)
name = self.comboBox_4.currentText()
no = False
try:
f = open("miyamotodata/qpsp/" + name + ".qpp", 'r')
except:
no = True
if not no and globals.ObjectDefinitions is not None:
try:
for line in f.readlines():
elements = line.split('\t')
if line != '\n':
self.scene.object_database[elements[0]]['x'] = int(elements[1])
self.scene.object_database[elements[0]]['y'] = int(elements[2])
self.scene.object_database[elements[0]]['w'] = int(elements[3])
self.scene.object_database[elements[0]]['h'] = int(elements[4])
self.scene.object_database[elements[0]]['ow'] = int(elements[3])
self.scene.object_database[elements[0]]['oh'] = int(elements[4])
if elements[5] == '\n':
self.scene.object_database[elements[0]]['i'] = None
else:
ln = globals.CurrentLayer
layer = globals.Area.layers[globals.CurrentLayer]
if len(layer) == 0:
z = (2 - ln) * 8192
else:
z = layer[-1].zValue() + 1
self.scene.object_database[elements[0]]['ts'] = int(elements[5])
self.scene.object_database[elements[0]]['t'] = int(elements[6])
self.scene.object_database[elements[0]]['i'] = ObjectItem(int(elements[5]),
int(elements[6]), -1,
self.scene.object_database[
elements[0]]['x'],
self.scene.object_database[
elements[0]]['y'],
int(elements[3]),
int(elements[4]), z, 0)
except:
print("Preset parse failed.")
f.close()
self.scene.fixAndUpdateObjects()
self.scene.invalidate()
def zoom(self):
"""
Zoom the view to half/full. Half is best for view when it's in a small region.
"""
if self.scene.zoom == 1:
self.scene.zoom = 0.5
self.ZoomButton.setIcon(GetIcon("zoomin", True))
else:
self.scene.zoom = 1
self.ZoomButton.setIcon(GetIcon("zoomout", True))
self.scene.invalidate()
def verticalScrollBar_changed(self):
"""
Handles vertical scroll movement, moving the view up and down.
"""
self.scene.setYoffset((50 - self.verticalScrollBar.value()) * 16)
def horizontalScrollBar_changed(self):
"""
Handles horizontal scroll movement, moving the view left and right.
"""
self.scene.setXoffset((50 - self.horizontalScrollBar.value()) * 16)
def retranslateUi(self):
"""
More UI construction.
"""
self.setWindowTitle(globals.trans.string('QuickPaint', 3))
self.PaintModeCheck.setText(globals.trans.string('QuickPaint', 4))
# self.SlopeModeCheck.setText(_translate("self", "Slope"))
self.EraseModeCheck.setText(globals.trans.string('QuickPaint', 5))
self.label_4.setText(globals.trans.string('QuickPaint', 6))
for fname in os.listdir("miyamotodata/qpsp/"):
if fname.endswith(".qpp"):
self.comboBox_4.addItem(fname[:-4])
self.comboBox_4.setCurrentIndex(-1)
self.SaveToPresetButton.setText(globals.trans.string('QuickPaint', 7))
self.AddPresetButton.setText(globals.trans.string('QuickPaint', 8))
self.RemovePresetButton.setText(globals.trans.string('QuickPaint', 9))
self.ZoomButton.setIcon(GetIcon("zoomin", True))
def ShowBadObjectWarning(self):
if self.show_badObjWarning:
QtWidgets.QMessageBox().warning(self,
globals.trans.string('QuickPaint', 1),
globals.trans.string('QuickPaint', 2))
self.show_badObjWarning = False
class ConfirmRemovePresetDialog(object):
"""
Dialog that asks the user for confirmation before removing a preset. We want to make sure the user didn't press the remove preset button by mistake.
"""
def __init__(self, Dialog):
"""
Dialog construction.
"""
Dialog.setObjectName("Dialog")
Dialog.resize(650, 109)
Dialog.setMinimumSize(QtCore.QSize(650, 109))
Dialog.setMaximumSize(QtCore.QSize(650, 109))
self.gridLayout = QtWidgets.QGridLayout(Dialog)
self.gridLayout.setObjectName("gridLayout")
self.label = QtWidgets.QLabel(Dialog)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setLayoutDirection(Qt.LeftToRight)
self.buttonBox.setAutoFillBackground(False)
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.No | QtWidgets.QDialogButtonBox.Yes)
self.buttonBox.setCenterButtons(True)
self.buttonBox.setObjectName("buttonBox")
self.gridLayout.addWidget(self.buttonBox, 1, 0, 1, 1)
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept)
self.buttonBox.rejected.connect(Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
"""
More dialog UI construction.
"""
Dialog.setWindowTitle(globals.trans.string('QuickPaint', 10))
self.label.setText(globals.trans.string('QuickPaint', 11))
class ConfirmOverwritePresetDialog(object):
"""
Dialog that asks the user for confirmation before overiting a preset. We want to make sure the user didn't press the save preset button by mistake.
"""
def __init__(self, Dialog):
"""
Dialog construction.
"""
Dialog.setObjectName("Dialog")
Dialog.resize(360, 109)
Dialog.setMinimumSize(QtCore.QSize(360, 109))
Dialog.setMaximumSize(QtCore.QSize(360, 109))
self.gridLayout = QtWidgets.QGridLayout(Dialog)
self.gridLayout.setObjectName("gridLayout")
self.label = QtWidgets.QLabel(Dialog)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setLayoutDirection(Qt.LeftToRight)
self.buttonBox.setAutoFillBackground(False)
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.No | QtWidgets.QDialogButtonBox.Yes)
self.buttonBox.setCenterButtons(True)
self.buttonBox.setObjectName("buttonBox")
self.gridLayout.addWidget(self.buttonBox, 1, 0, 1, 1)
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept)
self.buttonBox.rejected.connect(Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
"""
More dialog UI construction.
"""
Dialog.setWindowTitle(globals.trans.string('QuickPaint', 10))
self.label.setText(globals.trans.string('QuickPaint', 12))
class TextDialog(object):
"""
Dialog that asks for the name of the new preset and confirms the action.
"""
def __init__(self, Dialog, parent):
"""
Dialog construction.
"""
Dialog.setObjectName("Dialog")
Dialog.resize(380, 109)
Dialog.setMinimumSize(QtCore.QSize(380, 109))
Dialog.setMaximumSize(QtCore.QSize(380, 109))
self.gridLayout = QtWidgets.QGridLayout(Dialog)
self.gridLayout.setObjectName("gridLayout")
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.gridLayout.addWidget(self.buttonBox, 1, 0, 1, 1)
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setFrame(True)
self.lineEdit.setClearButtonEnabled(False)
self.lineEdit.setObjectName("lineEdit")
self.gridLayout.addWidget(self.lineEdit, 0, 0, 1, 1)
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(self.Accepted)
self.buttonBox.rejected.connect(Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
self.Dialog = Dialog
self.parent = parent
def Accepted(self):
"""
Yeah, I wrote the action in here because this was my first attempt to program a dialog in PyQt.
"""
if self.lineEdit.text() != "" and self.lineEdit.text() != self.parent.comboBox_4.currentText():
self.parent.saveCurrentPreset(self.lineEdit.text())
self.parent.comboBox_4.insertItem(0, self.lineEdit.text())
self.parent.comboBox_4.setCurrentIndex(0)
self.Dialog.accept()
def retranslateUi(self, Dialog):
"""
More dialog UI construction.
"""
Dialog.setWindowTitle(globals.trans.string('QuickPaint', 13))
class QuickPaintView(QtWidgets.QGraphicsView):
"""
Here we view the graphics that display the objects that will be arranged inside the user's quick paint strokes.
"""
def __init__(self, scene, parent):
"""
Constructs the quick paint view.
"""
QtWidgets.QGraphicsView.__init__(self, scene, parent)
self.parent = parent
def mousePressEvent(self, event):
"""
Handles mouse pressing events over the widget
"""
obj = self.parent.scene.HitObject(event.x(), event.y(), self.width(), self.height())
if obj is not None:
if event.button() == Qt.LeftButton:
if globals.CurrentPaintType not in [-1, 10] and globals.CurrentObject != -1:
odef = globals.ObjectDefinitions[globals.CurrentPaintType][globals.CurrentObject]
self.parent.scene.object_database[obj]['w'] = odef.width
self.parent.scene.object_database[obj]['h'] = odef.height
self.parent.scene.object_database[obj]['ow'] = odef.width
self.parent.scene.object_database[obj]['oh'] = odef.height
self.parent.scene.object_database[obj]['i'] = ObjectItem(globals.CurrentPaintType,
globals.CurrentObject, -1,
self.parent.scene.object_database[obj][
'x'],
self.parent.scene.object_database[obj][
'y'], odef.width, odef.height, 0,
0)
self.parent.scene.object_database[obj]['ts'] = globals.CurrentPaintType
self.parent.scene.object_database[obj]['t'] = globals.CurrentObject
self.parent.scene.invalidate()
elif event.button() == Qt.RightButton:
self.parent.scene.object_database[obj]['w'] = 1
self.parent.scene.object_database[obj]['h'] = 1
self.parent.scene.object_database[obj]['ow'] = 1
self.parent.scene.object_database[obj]['oh'] = 1
self.parent.scene.object_database[obj]['i'] = None
self.parent.scene.invalidate()
self.parent.scene.fixAndUpdateObjects()
class QuickPaintScene(QtWidgets.QGraphicsScene):
"""
This is the scene that contains the objects that will be arranged inside the user's quick paint strokes.
"""
def __init__(self, parent, *args):
"""
Constructs the quick paint scene.
"""
bgcolor = globals.theme.color('bg')
bghsv = bgcolor.getHsv()
self.xoffset = 0
self.yoffset = 0
self.zoom = 0.5
self.object_database = {
'base': {'x': 0, 'y': 0, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'i': None},
'top': {'x': 0, 'y': -1, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'p': 'base', 'i': None},
'topRight': {'x': 1, 'y': -1, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'p': 'base',
'i': None},
'topRightCorner': {'x': 4, 'y': 0, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'p': 'base',
'i': None},
'right': {'x': 1, 'y': 0, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'p': 'base', 'i': None},
'bottomRight': {'x': 1, 'y': 1, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'p': 'base',
'i': None},
'bottomRightCorner': {'x': 4, 'y': 0, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'p': 'base',
'i': None},
'bottom': {'x': 0, 'y': 1, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'p': 'base', 'i': None},
'bottomLeft': {'x': -1, 'y': 1, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'p': 'base',
'i': None},
'bottomLeftCorner': {'x': 4, 'y': 0, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'p': 'base',
'i': None},
'left': {'x': -1, 'y': 0, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'p': 'base', 'i': None},
'topLeft': {'x': -1, 'y': -1, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'p': 'base',
'i': None},
'topLeftCorner': {'x': 4, 'y': 0, 'w': 1, 'h': 1, 'ow': 1, 'oh': 1, 'ts': -1, 't': -1, 'p': 'base',
'i': None}
}
self.display_objects = []
self.BadObjectWarning = False
# I just feel like giving this widget a darker background than normal for some reason. Maybe it feels more empathetic.
bgcolor.setHsv(bghsv[0], min(round(bghsv[1] * 1.5), 255), round(bghsv[2] / 1.5), bghsv[3])
self.bgbrush = QtGui.QBrush(bgcolor)
QtWidgets.QGraphicsScene.__init__(self, *args)
self.parent = parent
def setXoffset(self, value):
"""
Sets the X view position.
"""
self.xoffset = value
self.invalidate()
def setYoffset(self, value):
"""
Sets the Y view position.
"""
self.yoffset = value
self.invalidate()
def HitObject(self, x, y, w, h):
"""
Looks to see if there is an object at this position.
"""
hitPoint = ((x - w / 2 - self.xoffset) / self.zoom, (y - h / 2 - self.yoffset) / self.zoom)
for obj in self.object_database:
if (self.object_database[obj] and
not (self.object_database[obj].get('p') is not None and self.object_database.get(
self.object_database[obj]['p']) is not None and
self.object_database[self.object_database[obj]['p']]['i'] is None) and
self.object_database[obj]['x'] * globals.TileWidth <= hitPoint[0] and
self.object_database[obj]['y'] * globals.TileWidth <= hitPoint[1] and
self.object_database[obj]['x'] * globals.TileWidth + self.object_database[obj][
'w'] * globals.TileWidth > hitPoint[0] and
self.object_database[obj]['y'] * globals.TileWidth + self.object_database[obj][
'h'] * globals.TileWidth > hitPoint[1]):
return obj
return None
def ArrangeMainIsland(self, maxbasewidth, maxleftwidth, maxrightwidth, maxbaseheight, maxtopheight,
maxbottomheight):
"""
Places the objects forming the main island correctly (or at least it should).
"""
self.object_database['top']['w'] = maxbasewidth
self.object_database['base']['w'] = maxbasewidth
self.object_database['bottom']['w'] = maxbasewidth
self.object_database['topLeft']['w'] = maxleftwidth
self.object_database['left']['w'] = maxleftwidth
self.object_database['bottomLeft']['w'] = maxleftwidth
self.object_database['top']['x'] = maxleftwidth - 1
self.object_database['base']['x'] = maxleftwidth - 1
self.object_database['bottom']['x'] = maxleftwidth - 1
self.object_database['topRight']['w'] = maxrightwidth
self.object_database['right']['w'] = maxrightwidth
self.object_database['bottomRight']['w'] = maxrightwidth
self.object_database['topRight']['x'] = maxbasewidth + maxleftwidth - 1
self.object_database['right']['x'] = maxbasewidth + maxleftwidth - 1
self.object_database['bottomRight']['x'] = maxbasewidth + maxleftwidth - 1
self.object_database['right']['h'] = maxbaseheight
self.object_database['base']['h'] = maxbaseheight
self.object_database['left']['h'] = maxbaseheight
self.object_database['topLeft']['h'] = maxtopheight
self.object_database['top']['h'] = maxtopheight
self.object_database['topRight']['h'] = maxtopheight
self.object_database['right']['y'] = maxtopheight - 1
self.object_database['base']['y'] = maxtopheight - 1
self.object_database['left']['y'] = maxtopheight - 1
self.object_database['bottomLeft']['h'] = maxbottomheight
self.object_database['bottom']['h'] = maxbottomheight
self.object_database['bottomRight']['h'] = maxbottomheight
self.object_database['bottomLeft']['y'] = maxbaseheight + maxtopheight - 1
self.object_database['bottom']['y'] = maxbaseheight + maxtopheight - 1
self.object_database['bottomRight']['y'] = maxbaseheight + maxtopheight - 1
displayObjects = []
for y in range(self.object_database['top']['h']):
for x in range(self.object_database['top']['w']):
displayObjects.append((self.AddDisplayObject('base', self.object_database['top']['x'] + x + 20, self.object_database['top']['y'] + 20 + y, 1,1), self.object_database['top']['i'] is None))
for y in range(self.object_database['base']['h']):
for x in range(self.object_database['base']['w']):
displayObjects.append((self.AddDisplayObject('base', self.object_database['base']['x'] + x + 20, self.object_database['base']['y'] + 20 + y, 1,1), self.object_database['base']['i'] is None))
for y in range(self.object_database['bottom']['h']):
for x in range(self.object_database['bottom']['w']):
displayObjects.append((self.AddDisplayObject('base', self.object_database['bottom']['x'] + x + 20, self.object_database['bottom']['y'] + 20 + y, 1,1), self.object_database['bottom']['i'] is None))
for y in range(self.object_database['topLeft']['h']):
for x in range(self.object_database['topLeft']['w']):
displayObjects.append((self.AddDisplayObject('base', self.object_database['topLeft']['x'] + x + 20, self.object_database['topLeft']['y'] + 20 + y, 1,1), self.object_database['topLeft']['i'] is None))
for y in range(self.object_database['left']['h']):
for x in range(self.object_database['left']['w']):
displayObjects.append((self.AddDisplayObject('base', self.object_database['left']['x'] + x + 20, self.object_database['left']['y'] + 20 + y, 1,1), self.object_database['left']['i'] is None))
for y in range(self.object_database['bottomLeft']['h']):
for x in range(self.object_database['bottomLeft']['w']):
displayObjects.append((self.AddDisplayObject('base', self.object_database['bottomLeft']['x'] + x + 20, self.object_database['bottomLeft']['y'] + 20 + y, 1,1), self.object_database['bottomLeft']['i'] is None))
for y in range(self.object_database['topRight']['h']):
for x in range(self.object_database['topRight']['w']):
displayObjects.append((self.AddDisplayObject('base', self.object_database['topRight']['x'] + x + 20, self.object_database['topRight']['y'] + 20 + y, 1,1), self.object_database['topRight']['i'] is None))
for y in range(self.object_database['bottomRight']['h']):
for x in range(self.object_database['bottomRight']['w']):
displayObjects.append((self.AddDisplayObject('base', self.object_database['bottomRight']['x'] + x + 20, self.object_database['bottomRight']['y'] + 20 + y, 1,1), self.object_database['bottomRight']['i'] is None))
for y in range(self.object_database['right']['h']):
for x in range(self.object_database['right']['w']):
displayObjects.append((self.AddDisplayObject('base', self.object_database['right']['x'] + x + 20, self.object_database['right']['y'] + 20 + y, 1,1), self.object_database['right']['i'] is None))
for obj in displayObjects:
if obj[0] is not None:
QuickPaintOperations.autoTileObj(-1, obj[0])
for obj in displayObjects:
if obj[0] is not None:
QuickPaintOperations.autoTileObj(-1, obj[0])
for obj in displayObjects:
if obj[1] and obj[0] in self.display_objects:
self.display_objects.remove(obj[0])
obj[0].RemoveFromSearchDatabase()
if obj[0] in QuickPaintOperations.object_optimize_database: QuickPaintOperations.object_optimize_database.remove(obj[0])
def ArrangeCornerSetterIsland(self, offsetX, maxbasewidth, maxleftwidth, maxrightwidth, maxbaseheight,
maxtopheight, maxbottomheight):
"""
Places the objects forming the corner setter island (the square doughnut-shaped island) correctly (or at least it should).
"""
displayObjects = []
for y in range(maxtopheight):
for x in range(maxleftwidth):
displayObjects.append((self.AddDisplayObject('base', maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + 20 + x, -3 + 20 + y,
1, 1), False))
tx = 0
for i in range(3 + maxrightwidth + maxleftwidth):
for y in range(maxtopheight):
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + i + offsetX + maxleftwidth + 20,
-3 + 20 + y, 1, 1), False))
tx += 1
for y in range(maxtopheight):
for x in range(self.object_database['topRight']['w']):
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + tx + 20 + x,
-3 + 20 + y, 1,1), False))
ty1 = 0
ty2 = 0
for i in range(3 + maxtopheight + maxbottomheight):
for x in range(maxleftwidth):
displayObjects.append((self.AddDisplayObject('base', maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + 20 + x,
-3 + i + maxtopheight + 20, 1, 1), False))
ty1 += 1
for i in range(3 + maxtopheight + maxbottomheight):
for x in range(maxrightwidth):
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + tx + 20 + x,
-3 + i + maxtopheight + 20, 1, 1), False))
ty2 += 1
ty = max(ty1, ty2)
for y in range(maxbottomheight):
for x in range(maxleftwidth):
displayObjects.append((self.AddDisplayObject('base', maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + 20 + x,
-3 + ty + maxtopheight + 20 + y, 1, 1), False))
for i in range(3 + maxrightwidth + maxleftwidth):
for y in range(maxbottomheight):
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + i + offsetX + maxleftwidth + 20,
-3 + ty + maxtopheight + 20 + y, 1, 1), False))
for y in range(maxbottomheight):
for x in range(self.object_database['bottomRight']['w']):
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + tx + 20 + x,
-3 + ty + maxtopheight + 20 + y, 1,
1), False))
for i in range(3):
for y in range(maxtopheight):
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + maxrightwidth + i + 20,
-3 + ty + 20 + y, 1, 1), False))
for i in range(3):
for y in range(maxbottomheight):
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + maxrightwidth + i + 20,
-3 + maxtopheight + 20 + y, 1, 1), False))
for i in range(3):
for x in range(maxrightwidth):
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + 20 + x,
-3 + maxtopheight + i + maxbottomheight + 20, 1, 1), False))
for i in range(3):
for x in range(maxleftwidth):
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + maxrightwidth + 3 + 20 + x,
-3 + maxtopheight + i + maxbottomheight + 20, 1, 1), False))
already_created_corner = False
for ix in range(maxrightwidth):
for iy in range(maxbottomheight):
if ix <= maxrightwidth - self.object_database['topLeftCorner']['w'] - 1 or iy <= maxbottomheight - \
self.object_database['topLeftCorner']['h'] - 1:
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + ix + 20,
-3 + iy + maxtopheight + 20, 1, 1), False))
else:
if not already_created_corner:
self.object_database['topLeftCorner'][
'x'] = maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + ix
self.object_database['topLeftCorner']['y'] = -3 + iy + maxtopheight
already_created_corner = True
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + ix + 20,
-3 + iy + maxtopheight + 20, 1, 1), self.object_database['topLeftCorner']['i'] is None))
already_created_corner = False
for ix in range(maxleftwidth):
for iy in range(maxbottomheight):
if ix >= self.object_database['topRightCorner']['w'] or iy <= maxbottomheight - \
self.object_database['topRightCorner']['h'] - 1:
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + maxrightwidth + 3 + ix + 20,
-3 + iy + maxtopheight + 20, 1, 1), False))
else:
if not already_created_corner:
self.object_database['topRightCorner'][
'x'] = maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + maxrightwidth + 3 + ix
self.object_database['topRightCorner']['y'] = -3 + iy + maxtopheight
already_created_corner = True
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + maxrightwidth + 3 + ix + 20,
-3 + iy + maxtopheight + 20, 1, 1), self.object_database['topRightCorner']['i'] is None))
already_created_corner = False
for ix in range(maxrightwidth):
for iy in range(maxtopheight):
if ix <= maxrightwidth - self.object_database['bottomLeftCorner']['w'] - 1 or iy >= \
self.object_database['bottomLeftCorner']['h']:
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + ix + 20,
-3 + iy + maxtopheight + 3 + maxbottomheight + 20, 1, 1), False))
else:
if not already_created_corner:
self.object_database['bottomLeftCorner'][
'x'] = maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + ix
self.object_database['bottomLeftCorner']['y'] = -3 + iy + maxtopheight + 3 + maxbottomheight
already_created_corner = True
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + ix + 20,
-3 + iy + maxtopheight + 3 + maxbottomheight + 20, 1, 1), self.object_database['bottomLeftCorner']['i'] is None))
already_created_corner = False
for ix in range(maxleftwidth):
for iy in range(maxtopheight):
if ix >= self.object_database['bottomRightCorner']['w'] or iy >= \
self.object_database['bottomRightCorner']['h']:
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + maxrightwidth + 3 + ix + 20,
-3 + iy + maxtopheight + 3 + maxbottomheight + 20, 1, 1), False))
else:
if not already_created_corner:
self.object_database['bottomRightCorner'][
'x'] = maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + maxrightwidth + 3 + ix
self.object_database['bottomRightCorner'][
'y'] = -3 + iy + maxtopheight + 3 + maxbottomheight
already_created_corner = True
displayObjects.append((self.AddDisplayObject('base',
maxbasewidth + maxleftwidth - 1 + maxrightwidth + offsetX + maxleftwidth + maxrightwidth + 3 + ix + 20,
-3 + iy + maxtopheight + 3 + maxbottomheight + 20, 1, 1), self.object_database['bottomRightCorner']['i'] is None))
for obj in displayObjects:
if obj[0] is not None:
QuickPaintOperations.autoTileObj(-1, obj[0])
for obj in displayObjects:
if obj[0] is not None:
QuickPaintOperations.autoTileObj(-1, obj[0])
for obj in displayObjects:
if obj[1] and obj[0] in self.display_objects:
self.display_objects.remove(obj[0])
obj[0].RemoveFromSearchDatabase()
if obj[0] in QuickPaintOperations.object_optimize_database: QuickPaintOperations.object_optimize_database.remove(obj[0])
def calculateBoundaries(self):
"""
Gets the maximum boundaries for all objects.
"""
# Fix Widths
maxbasewidth = max(
1 if self.object_database['top']['i'] is None else self.object_database['top']['i'].width,
1 if self.object_database['base']['i'] is None else self.object_database['base']['i'].width,
1 if self.object_database['bottom']['i'] is None else self.object_database['bottom']['i'].width) if \
self.object_database['base']['i'] is not None else 1
maxleftwidth = max(
1 if self.object_database['topLeft']['i'] is None else self.object_database['topLeft']['i'].width,
1 if self.object_database['bottomRightCorner']['i'] is None else
self.object_database['bottomRightCorner']['i'].width,