-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSettingsWidget.py
executable file
·1288 lines (1077 loc) · 46.2 KB
/
SettingsWidget.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
from PySide import QtGui, QtCore
from ObjectImageSettings import ObjectImageSettings
from ImageCache import ImageCache
import localizer
# # TODO: remove useTypes[4], set it only in container instead
# # TODO: locked container is unfinished/buggy (Legendan kaappi)
# # TODO: Closed door image is buggy (Suihkun ovi, vessan ovi room2) (?)
# # TODO: Add ending checkbox to generic objects
# # TODO: Duplicate images when changing newly added image
# # (copy generic attribute dict instead of using it as is)
# # TODO: Door state is initially closed even though should be open
# # (Vessan ovi wc2)
# # TODO: Fix names in unnameable objects (start menu images)
# # TODO: Adding new sequence images is buggy
# # (doesn't create new sequence entry in the object despite the image)
# # TODO: When removing sequence images remove the entry too
# # TODO: Hiuskeepperi has correct use target but no outcome
# the poster_withglue is not listed in the outcome combobox
# # TODO: Old images/xxx_plceholder.png sources
# # TODO: Are new items added to comboboxes?
# # TODO: Removing view
# TODO: Save view texts too in addition to their objects
# # TODO: Adding new item from combo should focus on the new item?
# TODO: Click "All texts" button
# # TODO: Useless text in rooms (there should be combo too)
# TODO: Glow for different views
# TODO: Object types should be exactly as they are in the object!
# TODO: "X ei ole nimeä" common delegate
# Item and room settings widget used in editor
class SettingsWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(SettingsWidget, self).__init__(parent)
self.currentObject = None
self.lastObjectType = None
## TODO: change to translation file
self.useTypes = {
0: localizer.translate('classSettingsWidget', 'noUse'),
1: localizer.translate('classSettingsWidget', 'useToOtherObject'),
2: localizer.translate('classSettingsWidget', 'openSth'),
3: localizer.translate('classSettingsWidget', 'putSmwh'),
4: localizer.translate('classSettingsWidget', 'deleteObstacle')
}
self.fadeTypes = {0: localizer.translate(
'classSettingsWidget', 'instantly'), 1: localizer.translate(
'classSettingsWidget', 'fade')}
self.layout = QtGui.QVBoxLayout()
self.setLayout(self.layout)
self.setSizePolicy(QtGui.QSizePolicy(
QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed))
self.editor = parent
self.imageCache = ImageCache()
self.createOptionFields()
def displayOptions(self, gameObject):
self.currentObject = gameObject
objectType = gameObject.__class__.__name__
self.showWidgets(objectType)
self.lastObjectType = objectType
if (objectType == "Room"):
self.setRoomOptions(gameObject)
elif (objectType == "Sequence"):
self.setSequenceOptions(gameObject)
elif (objectType == "SequenceImage"):
self.setSequenceImageOptions(gameObject)
elif (objectType == "Start"):
self.setStartOptions(gameObject)
elif (objectType == "End"):
self.setEndOptions(gameObject)
elif (objectType == "Text"):
self.setTextOptions(gameObject)
elif (objectType == "Item"):
self.setItemOptions(gameObject)
elif (objectType == "Object"):
self.setGenericOptions(gameObject)
elif (objectType == "Door"):
self.setDoorOptions(gameObject)
elif (objectType == "Container"):
self.setContainerOptions(gameObject)
elif (objectType == "Obstacle"):
self.setObstacleOptions(gameObject)
elif (objectType == "JSONImage"):
self.setJSONImageOptions(gameObject)
elif (objectType == "MenuImage"):
self.setJSONImageOptions(gameObject)
elif (objectType == "BeginningImage"):
self.setJSONImageOptions(gameObject)
def showWidgets(self, objectType):
if (self.lastObjectType):
for item in self.itemSettings[self.lastObjectType]:
item.hide()
for item in self.itemSettings[objectType]:
item.show()
# Settings for the object view
def createOptionFields(self):
# Name
self.nameLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'name'))
self.objectNameEdit = QtGui.QLineEdit()
self.objectNameEdit.editingFinished.connect(self.changeName)
# General image
self.imgTextLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'image'))
self.objectImage = QtGui.QLabel(self)
self.objectImage.mousePressEvent =\
lambda s: self.showImageDialog(self.changeObjectImage)
self.useTextEdit = QtGui.QTextEdit()
self.useTextEdit.setMaximumHeight(50)
self.useTextEdit.focusOutEvent = lambda s: self.changeUseText()
# Ending checkbox
self.endingCheckbox = QtGui.QCheckBox() # Set text afterwards
self.endingCheckbox.setText(localizer.translate(
'classSettingsWidget', 'gameEndsIfClicked'))
self.endingCheckbox.stateChanged.connect(self.changeEndingCheckbox)
# Music
self.musicLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'music'))
self.musicBtn = QtGui.QPushButton(localizer.translate(
'classSettingsWidget', 'browse'), self)
self.musicBtn.setToolTip(localizer.translate(
'classSettingsWidget', 'chooseMusicFile'))
self.musicBtn.resize(self.musicBtn.sizeHint())
self.musicBtn.clicked.connect(
lambda: self.showMusicDialog(self.changeMusic))
self.musicTextEdit = QtGui.QLineEdit()
self.musicTextEdit.setReadOnly(True)
self.musicClear = QtGui.QPushButton(localizer.translate(
'classSettingsWidget', 'noMusic'), self)
self.musicClear.clicked.connect(self.clearMusic)
# Where from dropdown box
# self.whereFromLabel = QtGui.QLabel(
# "Mistä kulkureiteistä tänne pääsee?")
# TODO: whereFromCombo
self.examineTextLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'textAsClicked'))
self.examineTextEdit = QtGui.QTextEdit()
self.examineTextEdit.setMaximumHeight(50)
self.examineTextEdit.focusOutEvent = lambda s: self.changeExamineText()
# Pickup text section
self.pickupLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'picked'))
self.pickupLabelLine = self.createSeparator()
self.pickupLabelLine.setFrameStyle(
QtGui.QFrame.HLine | QtGui.QFrame.Raised)
self.pickupTextLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'textIfPicked'))
self.pickupTextEdit = QtGui.QTextEdit()
self.pickupTextEdit.setMaximumHeight(50)
self.pickupTextEdit.focusOutEvent = lambda s: self.changePickupText()
# Object usage
self.useLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'usage'))
self.useLabelLine = self.createSeparator()
# Object type of usage
self.useTypeCombo = QtGui.QComboBox(self)
for i in self.useTypes:
self.useTypeCombo.addItem(self.useTypes[i])
self.useTypeCombo.activated.connect(self.changeItemUseType)
self.useTextLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'textIfUsed'))
# Use target
self.useTargetCombo = self.createCombobox()
self.updateUseTargetCombo()
self.allTextsButton = QtGui.QPushButton(localizer.translate(
'classSettingsWidget', 'theseAndOtherTexts'))
self.allTextsButton.clicked.connect(self.showAllTexts)
# Door widgets
self.doorTransitionLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'whereItGoes'))
self.doorTransitionCombo = self.createCombobox()
self.updateDoorTransitionCombo()
self.doorInitialStateLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'spaceAtStart'))
self.doorInitialStateCombo = QtGui.QComboBox(self)
self.doorInitialStateCombo.addItem(localizer.translate(
'classSettingsWidget', 'shut'))
self.doorInitialStateCombo.addItem(localizer.translate(
'classSettingsWidget', 'open'))
self.doorInitialStateCombo.activated.connect(
lambda s: self.objectComboboxHandler(
self.doorInitialStateCombo, self.changeDoorInitialState))
self.openDoorImage = ObjectImageSettings(
localizer.translate(
'classSettingsWidget', 'openDoor'),
localizer.translate('classSettingsWidget', 'openDoorName'),
parent=self)
self.closedDoorImage = ObjectImageSettings(
localizer.translate(
'classSettingsWidget', 'closedDoor'),
localizer.translate(
'classSettingsWidget', 'closedDoorName'),
parent=self)
self.lockedDoorImage = ObjectImageSettings(
localizer.translate(
'classSettingsWidget', 'lockedDoor'),
localizer.translate(
'classSettingsWidget', 'lockedDoorName'),
True,
localizer.translate('classSettingsWidget', 'locked'),
parent=self)
# Container widgets
self.lockedContainerImage = ObjectImageSettings(
localizer.translate(
'classSettingsWidget', 'lockedContainer'),
localizer.translate(
'classSettingsWidget', 'lockedContainerName'),
True,
localizer.translate(
'classSettingsWidget', 'locked'),
parent=self)
self.fullContainerImage = ObjectImageSettings(
localizer.translate(
'classSettingsWidget', 'openContainer'),
localizer.translate(
'classSettingsWidget', 'openContainerName'),
parent=self)
self.emptyContainerImage = ObjectImageSettings(
localizer.translate(
'classSettingsWidget', 'emptyContainer'),
localizer.translate(
'classSettingsWidget', 'emptyContainerName'),
parent=self)
# Obstacle widgets
self.obstacleImage = ObjectImageSettings(
None, localizer.translate(
'classSettingsWidget', 'whatObstructs'),
False, parent=self)
self.obstacleBlocksLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'whatObstructs'))
self.obstacleBlocksCombo = self.createCombobox()
self.updateObstacleBlocksCombo()
self.whatGoesLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'whatGoesToContainer'))
self.whatGoesCombo = self.createCombobox()
self.updateWhatGoesCombo()
self.whatComesLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'whatComesFromContainer')
)
self.whatComesCombo = self.createCombobox()
self.updateWhatComesCombo()
self.useConsumeCheckbox = QtGui.QCheckBox() # Set text afterwards
self.useConsumeCheckbox.stateChanged.connect(self.changeUseConsume)
self.outcomeLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'endResult')
)
self.outcomeCombobox = self.createCombobox()
self.updateOutcomeCombobox()
# Sequence
self.sequenceTimeLabel = QtGui.QLabel(
localizer.translate(
'classSettingsWidget', 'imageShowTime'))
self.sequenceTimeEdit = QtGui.QLineEdit()
self.sequenceTimeEdit.setInputMask("9,9")
self.sequenceTimeEdit.focusOutEvent =\
lambda s: self.changeSequenceTime()
self.sequenceFadeLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'fadeType'))
self.sequenceFadeCombo = QtGui.QComboBox(self)
for i in self.fadeTypes:
self.sequenceFadeCombo.addItem(self.fadeTypes[i])
self.sequenceFadeCombo.activated.connect(self.changeSequenceFadeCombo)
# End
self.textObjectTextLabel = QtGui.QLabel(localizer.translate(
'classSettingsWidget', 'text'))
self.textObjectTextEdit = QtGui.QLineEdit()
self.textObjectTextEdit.focusOutEvent =\
lambda s: self.changeTextObjectText()
self.layout.addWidget(self.textObjectTextLabel)
self.layout.addWidget(self.textObjectTextEdit)
self.layout.addWidget(self.nameLabel)
self.layout.addWidget(self.objectNameEdit)
self.layout.addWidget(self.imgTextLabel)
self.layout.addWidget(self.objectImage)
self.layout.addWidget(self.musicLabel)
self.layout.addWidget(self.musicTextEdit)
self.layout.addWidget(self.musicBtn)
self.layout.addWidget(self.musicClear)
#self.layout.addWidget(self.whereFromLabel)
self.layout.addWidget(self.endingCheckbox)
self.layout.addWidget(self.examineTextLabel)
self.layout.addWidget(self.examineTextEdit)
self.layout.addWidget(self.pickupLabelLine)
self.layout.addWidget(self.pickupLabel)
self.layout.addWidget(self.pickupTextLabel)
self.layout.addWidget(self.pickupTextEdit)
self.layout.addWidget(self.useLabelLine)
self.layout.addWidget(self.useLabel)
self.layout.addWidget(self.useTypeCombo)
self.layout.addWidget(self.useTargetCombo)
self.layout.addWidget(self.useConsumeCheckbox)
self.layout.addWidget(self.outcomeLabel)
self.layout.addWidget(self.outcomeCombobox)
self.layout.addWidget(self.useTextLabel)
self.layout.addWidget(self.useTextEdit)
self.layout.addWidget(self.allTextsButton)
#self.layout.addWidget(self.doorTransitionLabelLine)
self.layout.addWidget(self.doorTransitionLabel)
self.layout.addWidget(self.doorTransitionCombo)
self.layout.addWidget(self.doorInitialStateLabel)
self.layout.addWidget(self.doorInitialStateCombo)
self.layout.addWidget(self.openDoorImage)
self.layout.addWidget(self.lockedDoorImage)
self.layout.addWidget(self.closedDoorImage)
self.layout.addWidget(self.whatGoesLabel)
self.layout.addWidget(self.whatGoesCombo)
self.layout.addWidget(self.whatComesLabel)
self.layout.addWidget(self.whatComesCombo)
self.layout.addWidget(self.fullContainerImage)
self.layout.addWidget(self.lockedContainerImage)
self.layout.addWidget(self.emptyContainerImage)
self.layout.addWidget(self.obstacleBlocksLabel)
self.layout.addWidget(self.obstacleBlocksCombo)
self.layout.addWidget(self.obstacleImage)
self.layout.addWidget(self.sequenceTimeLabel)
self.layout.addWidget(self.sequenceTimeEdit)
self.layout.addWidget(self.sequenceFadeLabel)
self.layout.addWidget(self.sequenceFadeCombo)
# Removebuttons
self.removeObjectButton = QtGui.QPushButton(
localizer.translate(
'classSettingsWidget', 'removeObject'))
self.layout.addWidget(self.removeObjectButton)
self.removeObjectButton.clicked.connect(lambda: self.removeObject())
self.removeViewButton = QtGui.QPushButton(
localizer.translate(
'classSettingsWidget', 'removeView'))
self.layout.addWidget(self.removeViewButton)
self.removeViewButton.clicked.connect(lambda: self.removeView())
# Which widgets are shown with each object
self.itemSettings = {
"Room": [
self.imgTextLabel,
self.objectImage,
self.nameLabel,
self.objectNameEdit,
self.musicLabel,
self.musicTextEdit,
self.musicBtn,
self.musicClear,
self.removeViewButton
#self.whereFromLabel
# TODO: doorCombo for "where from" values
],
"Sequence": [
self.nameLabel,
self.objectNameEdit,
self.musicLabel,
self.musicTextEdit,
self.musicBtn,
self.musicClear,
self.removeViewButton
],
"SequenceImage": [
self.imgTextLabel,
self.objectImage,
self.sequenceTimeLabel,
self.sequenceTimeEdit,
self.sequenceFadeLabel,
self.sequenceFadeCombo,
self.removeViewButton
],
"End": [
self.imgTextLabel,
self.objectImage,
self.nameLabel,
self.objectNameEdit,
self.musicLabel,
self.musicTextEdit,
self.musicBtn,
self.musicClear,
],
"Text": [
self.textObjectTextLabel,
self.textObjectTextEdit
],
"BeginningImage": [
self.imgTextLabel,
self.objectImage,
],
"JSONImage": [
self.imgTextLabel,
self.objectImage,
],
"Start": [
self.musicLabel,
self.musicTextEdit,
self.musicBtn,
self.musicClear,
],
"MenuImage": [
self.imgTextLabel,
self.objectImage,
],
"Item": [
self.nameLabel,
self.objectNameEdit,
self.imgTextLabel,
self.objectImage,
self.examineTextLabel,
self.examineTextEdit,
self.pickupLabelLine,
self.pickupLabel,
self.pickupTextLabel,
self.pickupTextEdit,
self.useLabelLine,
self.useLabel,
self.useTypeCombo,
self.useTargetCombo,
self.useTextLabel,
self.useTextEdit,
self.allTextsButton,
self.useConsumeCheckbox,
self.outcomeLabel,
self.outcomeCombobox,
self.removeObjectButton
],
"Object": [
self.nameLabel,
self.objectNameEdit,
self.imgTextLabel,
self.objectImage,
self.endingCheckbox,
self.examineTextLabel,
self.examineTextEdit,
self.removeObjectButton
],
"Door": [
#self.doorTransitionLabelLine,
self.doorTransitionLabel,
self.doorTransitionCombo,
self.doorInitialStateLabel,
self.doorInitialStateCombo,
self.openDoorImage,
self.closedDoorImage,
self.lockedDoorImage,
self.removeObjectButton
],
"Container": [
self.lockedContainerImage,
self.fullContainerImage,
self.emptyContainerImage,
self.whatGoesLabel,
self.whatGoesCombo,
self.whatComesLabel,
self.whatComesCombo,
self.removeObjectButton
],
"Obstacle": [
self.obstacleImage,
self.obstacleBlocksLabel,
self.obstacleBlocksCombo,
self.removeObjectButton
]
}
# Hide every widget
for key in self.itemSettings:
for item in self.itemSettings[key]:
item.hide()
# Update comboboxes having objectType objects
def updateComboboxes(self, objectType):
objectType = objectType.lower()
if (objectType == "room"):
self.updateDoorTransitionCombo()
elif (objectType == "door"):
self.updateObstacleBlocksCombo()
elif (objectType == "item"):
self.updateWhatGoesCombo()
self.updateWhatComesCombo()
self.updateOutcomeCombobox()
elif (objectType == "object"):
self.updateOutcomeCombobox()
# Update every time
self.updateUseTargetCombo()
# Update other widgets
self.lockedDoorImage.updateComboboxes(objectType)
self.lockedContainerImage.updateComboboxes(objectType)
def updateUseTargetCombo(self):
self.updateItemCombobox(
self.useTargetCombo, localizer.translate(
'classSettingsWidget', 'notSelected'),
connectTo=self.changeUseTarget)
def updateDoorTransitionCombo(self):
self.updateItemCombobox(
self.doorTransitionCombo, localizer.translate(
'classSettingsWidget', 'notAnywhere'),
"room", connectTo=self.changeDoorTransition)
def updateObstacleBlocksCombo(self):
self.updateItemCombobox(
self.obstacleBlocksCombo, localizer.translate(
'classSettingsWidget', 'noNothing'), ("door",), ("door",),
noChoiceMethod=self.clearObstacleBlock,
connectTo=self.changeObstacleBlock)
def updateWhatGoesCombo(self):
self.updateItemCombobox(
self.whatGoesCombo, localizer.translate(
'classSettingsWidget', 'notAnything'),
("item",), ("item",),
connectTo=self.changeWhatGoes)
def updateWhatComesCombo(self):
self.updateItemCombobox(
self.whatComesCombo, localizer.translate(
'classSettingsWidget', 'noNothing'),
("item",), ("item",),
connectTo=self.changeWhatComes)
def updateOutcomeCombobox(self):
self.updateItemCombobox(
self.outcomeCombobox, localizer.translate(
'classSettingsWidget', 'notSelected'),
("object", "item"), ("object", "item"),
noChoiceMethod=self.clearOutcome,
connectTo=self.changeOutcome)
def changeSequenceTime(self):
time = int(float(self.sequenceTimeEdit.text().replace(",", "."))*1000)
self.currentObject.setShowTime(time)
def changeSequenceFadeCombo(self):
doFade = (self.sequenceFadeCombo.currentIndex() is True)
self.currentObject.setDoFade(doFade)
def changeTextObjectText(self):
self.currentObject.setText(self.textObjectTextEdit.text())
def changeEndingCheckbox(self):
self.currentObject.setIsEnding(self.endingCheckbox.isChecked())
# Start menu
def setStartOptions(self, startObject):
# Start music
self.setObjectMusic(startObject)
# End view
def setEndOptions(self, endObject):
# End name
self.setObjectName(overrideText=endObject.generalName)
# End image
self.setObjectImage(
endObject.getRepresentingImage().getRepresentingImage()
.absoluteImagePath)
# Text object
def setTextOptions(self, textObject):
self.textObjectTextEdit.setText(textObject.getText())
# Set either currentObject or the given object's music
def setObjectMusic(self, gameObject=None):
if not (gameObject):
gameObject = self.currentObject
# Music may return None which doesn't have split
try:
music = gameObject.getMusic().split("/")[-1]
except AttributeError:
music = ""
self.musicTextEdit.setText(music)
# Generic JSON images
def setJSONImageOptions(self, imageObject):
# Image
self.setObjectImage(
imageObject.getRepresentingImage()
.getRepresentingImage().absoluteImagePath)
# Set the input field values for rooms
def setRoomOptions(self, room):
# Room name
self.setObjectName(room, room.generalName)
# Room background
self.setObjectImage(
room.getRepresentingImage()
.getRepresentingImage().absoluteImagePath)
# Room music
self.setObjectMusic(room)
def setSequenceOptions(self, sequence):
# Sequence name
self.setObjectName(sequence, sequence.generalNameAdessive)
# Sequence background
self.setObjectImage(
sequence.getRepresentingImage()
.getRepresentingImage().absoluteImagePath)
# Sequence music
self.setObjectMusic(sequence)
def setSequenceImageOptions(self, sequenceImage):
# Image
self.setObjectImage(
sequenceImage.getRepresentingImage()
.getRepresentingImage().absoluteImagePath)
# Set image display time. Convert into str and replace dots
showTime = self.currentObject.getShowTime()
if (showTime):
time = str(showTime/1000).replace(".", ",")
else:
time = "0,0"
self.sequenceTimeEdit.setText(time)
# Image fade type
doFade = self.currentObject.getDoFade()
if not (doFade):
doFade = False
self.sequenceFadeCombo.setCurrentIndex(doFade)
# Set the input field values for items
def setItemOptions(self, item):
imageObject = item.getRepresentingImage().getRepresentingImage()
# Object name
self.setObjectName(imageObject, item.generalNameAdessive)
# Item image
self.setObjectImage(imageObject.absoluteImagePath)
# Examine text
self.setExamineText(self.currentObject)
# Pickup text
pickupText = item.getPickupText()
if not (pickupText):
pickupText = ""
self.pickupTextEdit.setText(pickupText)
# Use type of the item
itemTarget = self.editor.getItemUse(item)
itemTargetType = itemTarget.__class__.__name__
useType = 0
if (itemTargetType in ("Object", "Item")):
useType = 1
elif (itemTargetType == "Obstacle"):
useType = 5
elif (itemTargetType in ("Door", "Container")):
# Item may unlock door or container or may go into a container
if (itemTarget.key == item):
useType = 2
else:
try:
if (itemTarget.inItem == item):
useType = 3
except AttributeError:
pass
self.setUseConsume()
self.setItemUseType(useType)
self.setItemUseTarget(itemTarget)
self.setItemOutcome(self.currentObject.outcome)
self.setUseText()
# Set the input field values for generic objects
def setGenericOptions(self, genericObject):
# Object name
self.setObjectName(genericObject, genericObject.generalNameAdessive)
# Object image
imageObject = genericObject.getRepresentingImage()\
.getRepresentingImage()
self.setObjectImage(imageObject.absoluteImagePath)
# Ending
if (self.currentObject.getIsEnding()):
self.endingCheckbox.setCheckState(QtCore.Qt.CheckState.Checked)
else:
self.endingCheckbox.setCheckState(QtCore.Qt.CheckState.Unchecked)
# Examine text
self.setExamineText(self.currentObject)
# Set the input field values for containers
def setContainerOptions(self, container):
# Set image settings for each image
self.fullContainerImage.setSettings(container, container.fullImage)
self.lockedContainerImage.setSettings(container, container.lockedImage)
self.emptyContainerImage.setSettings(container, container.emptyImage)
# Set what goes, what comes from the container
self.setComboboxIndex(container.inItem, self.whatGoesCombo)
self.setComboboxIndex(container.outItem, self.whatComesCombo)
# Set the input field values for obstacles
def setObstacleOptions(self, obstacle):
self.obstacleImage.setSettings(obstacle, obstacle.blockingImage)
def setObjectImage(self, imagePath, objectImage=None):
imgPixmap = self.imageCache.createPixmap(imagePath)
# TODO: Have spacing for smaller items
if (imgPixmap.size().height() > 200):
imgPixmap = imgPixmap.scaled(200, 200, QtCore.Qt.KeepAspectRatio)
if (objectImage):
objectImage.setPixmap(imgPixmap)
else:
self.objectImage.setPixmap(imgPixmap)
# Set item use type
def setItemUseType(self, typeIndex):
self.useTypeCombo.setCurrentIndex(typeIndex)
self.updateUseTargetCombobox(typeIndex, self.useTargetCombo)
# Show extra options when selecting use on other object
if (typeIndex == 1):
self.useConsumeCheckbox.setText(
localizer.translate(
'classSettingsWidget', 'vanishDuringUse')
)
self.useConsumeCheckbox.show()
self.outcomeLabel.show()
self.outcomeCombobox.show()
else:
self.useConsumeCheckbox.hide()
self.outcomeLabel.hide()
self.outcomeCombobox.hide()
# When no use, hide and clear elements
if (typeIndex == 0):
self.useTargetCombo.hide()
self.useTextLabel.hide()
self.useTextEdit.hide()
self.useTextEdit.clear()
self.changeUseText()
self.allTextsButton.hide()
self.currentObject.clearTarget()
else:
self.useTargetCombo.show()
self.useTextLabel.show()
self.useTextEdit.show()
self.allTextsButton.show()
# Set item use target
def setItemUseTarget(self, useItem):
if (useItem):
# Find the combobox item with the given item
for i in range(self.useTargetCombo.count()):
if (self.useTargetCombo.itemData(i) == useItem):
self.useTargetCombo.setCurrentIndex(i)
return
self.useTargetCombo.setCurrentIndex(0)
def setItemOutcome(self, outcomeItem):
if (outcomeItem):
# Find the combobox item with the given item
for i in range(self.outcomeCombobox.count()):
if (self.outcomeCombobox.itemData(i) == outcomeItem):
self.outcomeCombobox.setCurrentIndex(i)
return
self.outcomeCombobox.setCurrentIndex(0)
def setDoorInitialState(self):
# Door open
if (self.currentObject.closedImage or self.currentObject.lockedImage):
self.doorInitialStateCombo.setCurrentIndex(0)
# Door closed
else:
self.doorInitialStateCombo.setCurrentIndex(1)
self.changeDoorInitialState()
def setDoorOptions(self, doorObject):
# Set each image's settings
self.closedDoorImage.setSettings(doorObject, doorObject.closedImage)
self.lockedDoorImage.setSettings(doorObject, doorObject.lockedImage)
self.openDoorImage.setSettings(doorObject, doorObject.openImage)
# Door transition room
self.setComboboxIndex(doorObject.transition, self.doorTransitionCombo)
# Set door open or closed in the beginning
self.setDoorInitialState()
# Set use item for items
def setUseText(self, textEdit=None, item=None):
if (self.useTypeCombo.currentIndex() == 0):
return
if not (item):
item = self.currentObject
useText = item.getUseText()
if not (useText):
useText = ""
if (textEdit):
textEdit.setText(useText)
else:
self.useTextEdit.setText(useText)
# Set examine text for the given object
def setExamineText(self, gameObject, textEdit=None):
try:
text = gameObject.getExamineText()
except AttributeError:
text = ""
if (textEdit):
textEdit.setText(text)
else:
self.examineTextEdit.setText(text)
# Set any game object name
def setObjectName(self, gameObject=None, textStart="Object",
textEdit=None, overrideText=None):
if not (gameObject):
gameObject = self.currentObject
if (overrideText):
name = overrideText
else:
# Given image may be None
try:
name = gameObject.getName()
except AttributeError:
name = ""
if (name is None):
name = localizer.translate(
'classSettingsWidget', 'objectHasNoName')
# If textEdit is defined, set its text instead
if (textEdit):
textEdit.setText(name)
else:
self.objectNameEdit.setText(name)
def setUseConsume(self):
isConsumed = self.useConsumeCheckbox.isChecked()
self.currentObject.setConsume(isConsumed)
if (isConsumed):
self.useConsumeCheckbox.setCheckState(QtCore.Qt.CheckState.Checked)
else:
self.useConsumeCheckbox.setCheckState(
QtCore.Qt.CheckState.Unchecked)
def changeWhereLocated(self, combobox):
# What is this used for?
print("Change where located to", combobox.itemData(
combobox.currentIndex()))
# Text that comes after using an item
def changeUseText(self):
# TODO: Disable text field if no target is selected
self.currentObject.setUseText(
self.useTextEdit.toPlainText())
def changePickupText(self):
self.currentObject.setPickupText(self.pickupTextEdit.toPlainText())
def changeExamineText(self, textEdit=None, gameObject=None):
if not (gameObject):
gameObject = self.currentObject
if not (textEdit):
textEdit = self.examineTextEdit
gameObject.setExamineText(textEdit.toPlainText())
def changeDoorInitialState(self):
# Initially closed, all states (closed, locked, open) are possible
if (self.doorInitialStateCombo.currentIndex() == 0):
self.closedDoorImage.setDisabled(False)
self.lockedDoorImage.setDisabled(False)
self.openDoorImage.setDisabled(False)
# Add door's closed image
self.currentObject.setClosed(True)
self.currentObject.closedImage.placeholderImage.setSource(
self.editor.getPlaceholderImagePath("Door"))
# Initially open, only "open" state is possible
else:
self.closedDoorImage.setDisabled(True)
self.lockedDoorImage.setDisabled(True)
self.openDoorImage.setDisabled(False)
# Remove door's closed and locked images
self.currentObject.setClosed(False)
self.currentObject.setLocked(False)
# Change the image of a gameobject
def changeObjectImage(self, imagePath, image=None, gameObject=None):
# If no image, a default image var will be used
# TODO: Copy the chosen image to the 'images' folder of the scenario?
self.currentObject.getRepresentingImage().setSource(imagePath)
self.setObjectImage(imagePath, image)
print(imagePath)
if not (gameObject):
gameObject = self.currentObject
self.editor.drawRoomItems()
self.updateParent()
self.editor.updateSpaceTab()
# Change music
def changeMusic(self, imagePath):
self.currentObject.setMusic(imagePath)
def changeUseConsume(self):
self.currentObject.setConsume(self.useConsumeCheckbox.isChecked())
def changeOutcome(self):
self.currentObject.setOutcome(
self.outcomeCombobox.itemData(self.outcomeCombobox.currentIndex()))
def clearOutcome(self):
self.currentObject.setOutcome(None)
def clearUseTarget(self):
print("Clear useTarget!")
# TODO: This is run even when populating the combobox
#self.currentObject.clearTarget()
def changeObstacleBlock(self):
self.currentObject.setBlockTarget(
self.obstacleBlocksCombo.itemData(
self.obstacleBlocksCombo.currentIndex()))
def clearObstacleBlock(self):