@@ -168,8 +168,14 @@ def __init__(self, parent):
168
168
'image' : '' ,
169
169
},
170
170
},
171
- 'visualization ' : {
171
+ 'view ' : {
172
172
'radius' : True ,
173
+ 'PlatinumType' : {
174
+ 'platinum' : True ,
175
+ 'normal' : True ,
176
+ 'note' : True ,
177
+ 'none' : True ,
178
+ }
173
179
}
174
180
}
175
181
)
@@ -608,31 +614,27 @@ def updateLayers(self):
608
614
if len (objects ) < 0 :
609
615
return
610
616
617
+ def raise_tag (bottom , top ):
618
+ objects = self .level_canvas .find_withtag (top )
619
+ if len (objects ):
620
+ self .level_canvas .tag_raise (top , bottom )
621
+ return top
622
+ return bottom
623
+
611
624
last_tag = 'level'
612
- for visualization_tag in self .settings .get ('visualization' , {}):
613
- visualizations = self .level_canvas .find_withtag (visualization_tag )
614
- if len (visualizations ):
615
- self .level_canvas .tag_raise (visualization_tag , last_tag )
616
- last_tag = visualization_tag
617
-
618
- self .level_canvas .tag_raise ('object' , last_tag )
619
-
620
- background = self .level_canvas .find_withtag ('background' )
621
- foreground = self .level_canvas .find_withtag ('foreground' )
622
- if len (background ) > 0 :
623
- background = 'background'
624
- else :
625
- background = 'level'
626
625
627
- if len (foreground ) > 0 :
628
- foreground = 'foreground'
629
- else :
630
- return
626
+ for obj in self .level .objects :
627
+ obj_id = f'object-{ obj .id } '
628
+ last_tag = raise_tag (last_tag , obj_id )
629
+
630
+ last_tag = raise_tag (last_tag , 'background' )
631
+ last_tag = raise_tag (last_tag , 'foreground' )
631
632
632
- self .level_canvas .tag_raise (foreground , background )
633
+ for visualization_tag in self .settings .get ('view' , {}):
634
+ last_tag = raise_tag (last_tag , visualization_tag )
633
635
634
636
if len (self .level_canvas .find_withtag ('selection' )) > 0 :
635
- self . level_canvas . tag_raise ( 'selection ' , 'object ' )
637
+ raise_tag ( 'object ' , 'selection ' )
636
638
637
639
SELECTION_BORDER_WIDTH = 2
638
640
@@ -644,6 +646,14 @@ def updateSelectionRectangle(self, obj : wmwpy.classes.Object = None):
644
646
# logging.info('deleted selection')
645
647
return
646
648
649
+ obj_id = f'object-{ str (obj .id )} '
650
+
651
+ platinum_type = obj .properties .get ('PlatinumType' , obj .defaultProperties .get ('PlatinumType' , 'none' ))
652
+
653
+ if not self .settings .get (['view.PlatinumType' , platinum_type ], True ):
654
+ self .level_canvas .delete ('selection' )
655
+ return
656
+
647
657
pos = numpy .array (obj .pos )
648
658
size = numpy .maximum (numpy .array (obj .size ), [1 ,1 ])
649
659
logging .debug (f'object size: { size } ' )
@@ -654,9 +664,9 @@ def updateSelectionRectangle(self, obj : wmwpy.classes.Object = None):
654
664
logging .debug (f'rectangle size: { (0 ,0 ) + tuple (numpy .array (selectionImage .size ) - (self .SELECTION_BORDER_WIDTH - 1 ))} ' )
655
665
selectionImageDraw .rectangle (
656
666
(0 ,0 ) + tuple (numpy .array (selectionImage .size ) - (self .SELECTION_BORDER_WIDTH - 1 )),
657
- fill = 'transparent' ,
658
- outline = 'black' ,
659
- width = self .SELECTION_BORDER_WIDTH ,
667
+ fill = 'transparent' ,
668
+ outline = 'black' ,
669
+ width = self .SELECTION_BORDER_WIDTH ,
660
670
)
661
671
selectionImage = obj .rotateImage (selectionImage )
662
672
self .selectionPhotoImage = ImageTk .PhotoImage (selectionImage )
@@ -679,8 +689,9 @@ def updateSelectionRectangle(self, obj : wmwpy.classes.Object = None):
679
689
* pos
680
690
)
681
691
682
- self .bindObject (id , obj )
683
692
693
+ self .bindObject (id , obj )
694
+
684
695
def getObjectPosition (self , pos = (0 ,0 ), offset = (0 ,0 )):
685
696
pos = numpy .array (pos )
686
697
offset = numpy .array (offset )
@@ -710,6 +721,12 @@ def updateObject(self, obj : wmwpy.classes.Object):
710
721
711
722
id = f'object-{ str (obj .id )} '
712
723
724
+ platinum_type = obj .properties .get ('PlatinumType' , obj .defaultProperties .get ('PlatinumType' , 'none' ))
725
+
726
+ if not self .settings .get (['view.PlatinumType' , platinum_type ], True ):
727
+ self .level_canvas .delete (id )
728
+ return
729
+
713
730
items = self .level_canvas .find_withtag (id )
714
731
715
732
logging .debug (f'items: { items } ' )
@@ -768,7 +785,7 @@ def updateObject(self, obj : wmwpy.classes.Object):
768
785
tags = ('object' , 'foreground' , id )
769
786
)
770
787
771
- if self .settings .get ('visualization .radius' , True ) and obj .Type is not None :
788
+ if self .settings .get ('view .radius' , True ) and obj .Type is not None :
772
789
properties = deepcopy (obj .defaultProperties )
773
790
properties .update (obj .properties )
774
791
for property in properties :
@@ -787,7 +804,7 @@ def updateObject(self, obj : wmwpy.classes.Object):
787
804
radius_canvas_size ,
788
805
fill = '' ,
789
806
outline = 'red' ,
790
- width = 1 ,
807
+ width = self . OBJECT_MULTIPLIER ,
791
808
tags = ('radius' , property , id )
792
809
)
793
810
@@ -1760,25 +1777,50 @@ def createMenubar(self):
1760
1777
self .view_menu : dict [
1761
1778
typing .Literal [
1762
1779
'menu' ,
1780
+ 'sub' ,
1763
1781
'vars' ,
1764
1782
],
1765
1783
tk .Menu | dict [typing .Literal [
1766
- 'radius'
1767
- ], tk .BooleanVar ]
1784
+ 'radius' ,
1785
+ 'PlatinumType' ,
1786
+ ], tk .BooleanVar ] | dict [str , tk .Menu ]
1768
1787
] = {
1769
1788
'menu' : tk .Menu (self .menubar , tearoff = 0 ),
1789
+ 'sub' : {
1790
+ 'PlatinumType' : None ,
1791
+ },
1770
1792
'vars' : {
1771
- 'radius' : tk .BooleanVar (value = self .settings .get ('visualization.radius' , True ))
1793
+ 'radius' : tk .BooleanVar (value = self .settings .get ('view.radius' , True )),
1794
+ 'PlatinumType' : {
1795
+ 'platinum' : tk .BooleanVar (value = self .settings .get ('view.PlatinumType.platinum' , True )),
1796
+ 'normal' : tk .BooleanVar (value = self .settings .get ('view.PlatinumType.normal' , True )),
1797
+ 'note' : tk .BooleanVar (value = self .settings .get ('view.PlatinumType.note' , True )),
1798
+ 'none' : tk .BooleanVar (value = self .settings .get ('view.PlatinumType.none' , True )),
1799
+ }
1772
1800
}
1773
1801
}
1774
1802
1775
1803
self .view_menu ['vars' ]['radius' ].trace_add ('write' , lambda * args : self .updateView ('radius' , self .view_menu ['vars' ]['radius' ].get ()))
1776
1804
self .view_menu ['menu' ].add_checkbutton (label = 'radius' , onvalue = True , offvalue = False , variable = self .view_menu ['vars' ]['radius' ])
1777
1805
1806
+ self .view_menu ['sub' ]['PlatinumType' ] = tk .Menu (self .view_menu ['menu' ], tearoff = 0 )
1807
+
1808
+ self .view_menu ['vars' ]['PlatinumType' ]['platinum' ].trace_add ('write' , lambda * args : self .updateView ('PlatinumType.platinum' , self .view_menu ['vars' ]['PlatinumType' ]['platinum' ].get ()))
1809
+ self .view_menu ['sub' ]['PlatinumType' ].add_checkbutton (label = 'platinum' , onvalue = True , offvalue = False , variable = self .view_menu ['vars' ]['PlatinumType' ]['platinum' ])
1810
+ self .view_menu ['vars' ]['PlatinumType' ]['normal' ].trace_add ('write' , lambda * args : self .updateView ('PlatinumType.normal' , self .view_menu ['vars' ]['PlatinumType' ]['normal' ].get ()))
1811
+ self .view_menu ['sub' ]['PlatinumType' ].add_checkbutton (label = 'normal' , onvalue = True , offvalue = False , variable = self .view_menu ['vars' ]['PlatinumType' ]['normal' ])
1812
+ self .view_menu ['vars' ]['PlatinumType' ]['note' ].trace_add ('write' , lambda * args : self .updateView ('PlatinumType.note' , self .view_menu ['vars' ]['PlatinumType' ]['note' ].get ()))
1813
+ self .view_menu ['sub' ]['PlatinumType' ].add_checkbutton (label = 'note' , onvalue = True , offvalue = False , variable = self .view_menu ['vars' ]['PlatinumType' ]['note' ])
1814
+ self .view_menu ['vars' ]['PlatinumType' ]['none' ].trace_add ('write' , lambda * args : self .updateView ('PlatinumType.none' , self .view_menu ['vars' ]['PlatinumType' ]['none' ].get ()))
1815
+ self .view_menu ['sub' ]['PlatinumType' ].add_checkbutton (label = 'none' , onvalue = True , offvalue = False , variable = self .view_menu ['vars' ]['PlatinumType' ]['none' ])
1816
+
1817
+ self .view_menu ['menu' ].add_cascade (label = 'platinum type' , menu = self .view_menu ['sub' ]['PlatinumType' ])
1818
+
1819
+
1778
1820
self .menubar .add_cascade (label = 'View' , menu = self .view_menu ['menu' ])
1779
1821
1780
1822
def updateView (self , view : str , state : bool = True ):
1781
- self .settings .set (['visualization ' , view ], state )
1823
+ self .settings .set (['view ' , view ], state )
1782
1824
self .updateLevel ()
1783
1825
1784
1826
def showAbout (self ):
@@ -1995,6 +2037,7 @@ def loadLevel(self, xml : str, image : str):
1995
2037
1996
2038
if isinstance (self .level , wmwpy .classes .Level ):
1997
2039
self .level_canvas .delete ('object' )
2040
+ self .level_canvas .delete ('radius' )
1998
2041
self .level_canvas .delete ('selection' )
1999
2042
2000
2043
self .resetProperties ()
0 commit comments