@@ -9,13 +9,11 @@ enum WindowAlign {
99
1010class Window extends dn. Process {
1111 public static var ALL : Array <Window > = [];
12- static var MODAL_COUNT = 0 ;
1312
1413 public var content : h2d. Flow ;
1514
1615 var ca : ControllerAccess <GameAction >;
1716 var mask : Null <h2d. Flow >;
18- var modalIdx = 0 ;
1917
2018 public var isModal (default , null ) = false ;
2119 public var canBeClosedManually = true ;
@@ -50,23 +48,42 @@ class Window extends dn.Process {
5048 makeModal ();
5149 }
5250
51+ function getModalIndex () {
52+ if ( ! isModal )
53+ return - 1 ;
54+
55+ var i = 0 ;
56+ for ( w in ALL )
57+ if ( w .isModal ) {
58+ if ( w == this )
59+ return i ;
60+ i ++ ;
61+ }
62+ Console .ME .error (' $this has no valid modalIndex' );
63+ return - 1 ;
64+ }
65+
5366 function set_horizontalAlign (v : WindowAlign ) {
54- switch horizontalAlign {
55- case Fill : content .minWidth = content .maxWidth = null ; // clear previous constraint from onResize()
56- case _ :
67+ if ( v != horizontalAlign ) {
68+ switch horizontalAlign {
69+ case Fill : content .minWidth = content .maxWidth = null ; // clear previous constraint from onResize()
70+ case _ :
71+ }
72+ horizontalAlign = v ;
73+ emitResizeAtEndOfFrame ();
5774 }
58- horizontalAlign = v ;
59- emitResizeAtEndOfFrame ();
6075 return v ;
6176 }
6277
6378 function set_verticalAlign (v : WindowAlign ) {
64- switch verticalAlign {
65- case Fill : content .minHeight = content .maxHeight = null ; // clear previous constraint from onResize()
66- case _ :
79+ if ( v != verticalAlign ) {
80+ switch verticalAlign {
81+ case Fill : content .minHeight = content .maxHeight = null ; // clear previous constraint from onResize()
82+ case _ :
83+ }
84+ verticalAlign = v ;
85+ emitResizeAtEndOfFrame ();
6786 }
68- verticalAlign = v ;
69- emitResizeAtEndOfFrame ();
7087 return v ;
7188 }
7289
@@ -76,25 +93,24 @@ class Window extends dn.Process {
7693
7794 public function makeTransparent () {
7895 content .backgroundTile = null ;
79- content .enableInteractive = false ;
8096 }
8197
8298 override function onDispose () {
8399 super .onDispose ();
84100
85101 ALL .remove (this );
86- if ( isModal )
87- MODAL_COUNT -- ;
88102
89103 ca .dispose ();
90104 ca = null ;
91105
92106 if ( ! hasAnyModal () )
93107 Game .ME .resume ();
108+
109+ emitResizeAtEndOfFrame ();
94110 }
95111
96112 @:keep override function toString (): String {
97- return isModal ? ' ModalWin ${isActive ()? " *" : " " }( $modalIdx )' : ' Win' ;
113+ return isModal ? ' ModalWin ${isActive ()? " *" : " " }( ${ getModalIndex ()} )' : ' Win' ;
98114 }
99115
100116 function makeModal () {
@@ -103,8 +119,7 @@ class Window extends dn.Process {
103119
104120 isModal = true ;
105121
106- modalIdx = MODAL_COUNT ++ ;
107- if ( modalIdx == 0 )
122+ if ( getModalIndex ()== 0 )
108123 Game .ME .pause ();
109124
110125 mask = new h2d. Flow (root );
@@ -160,7 +175,7 @@ class Window extends dn.Process {
160175 switch horizontalAlign {
161176 case Start : content .x = 0 ;
162177 case End : content .x = wid - content .outerWidth ;
163- case Center : content .x = Std .int ( wid * 0.5 - content .outerWidth * 0.5 + modalIdx * 8 );
178+ case Center : content .x = Std .int ( wid * 0.5 - content .outerWidth * 0.5 + getModalIndex () * 8 );
164179 case Fill : content .x = 0 ; content .minWidth = content .maxWidth = wid ;
165180 }
166181
@@ -171,7 +186,7 @@ class Window extends dn.Process {
171186 switch verticalAlign {
172187 case Start : content .y = 0 ;
173188 case End : content .y = hei - content .outerHeight ;
174- case Center : content .y = Std .int ( hei * 0.5 - content .outerHeight * 0.5 + modalIdx * 4 );
189+ case Center : content .y = Std .int ( hei * 0.5 - content .outerHeight * 0.5 + getModalIndex () * 4 );
175190 case Fill : content .y = 0 ; content .minHeight = content .maxHeight = hei ;
176191 }
177192
0 commit comments