Skip to content

Commit 01624a3

Browse files
committed
Groot 增加 popupLayer 用于指定弹窗的父容器,用于自定义弹出层的展示
1 parent 2791924 commit 01624a3

File tree

1 file changed

+42
-35
lines changed

1 file changed

+42
-35
lines changed

Assets/Scripts/UI/GRoot.cs

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ public static int contentScaleLevel
3333
GObject _tooltipWin;
3434
GObject _defaultTooltipWin;
3535

36+
GComponent _popupLayer;
37+
public GComponent popupLayer
38+
{
39+
get { return _popupLayer != null ? _popupLayer : this; }
40+
set { _popupLayer = value; }
41+
}
42+
3643
internal static GRoot _inst;
3744
public static GRoot inst
3845
{
@@ -130,7 +137,7 @@ public void ApplyContentScaleFactor()
130137
/// <param name="win"></param>
131138
public void ShowWindow(Window win)
132139
{
133-
AddChild(win);
140+
popupLayer.AddChild(win);
134141
AdjustModalLayer();
135142
}
136143

@@ -162,8 +169,8 @@ public void HideWindowImmediately(Window win)
162169
/// <param name="dispose">True to dispose the window.</param>
163170
public void HideWindowImmediately(Window win, bool dispose)
164171
{
165-
if (win.parent == this)
166-
RemoveChild(win, dispose);
172+
if (win.parent == popupLayer)
173+
popupLayer.RemoveChild(win, dispose);
167174
else if (dispose)
168175
win.Dispose();
169176

@@ -176,24 +183,24 @@ public void HideWindowImmediately(Window win, bool dispose)
176183
/// <param name="win"></param>
177184
public void BringToFront(Window win)
178185
{
179-
int cnt = this.numChildren;
186+
int cnt = popupLayer.numChildren;
180187
int i;
181188
if (_modalLayer != null && _modalLayer.parent != null && !win.modal)
182-
i = GetChildIndex(_modalLayer) - 1;
189+
i = popupLayer.GetChildIndex(_modalLayer) - 1;
183190
else
184191
i = cnt - 1;
185192

186193
for (; i >= 0; i--)
187194
{
188-
GObject g = GetChildAt(i);
195+
GObject g = popupLayer.GetChildAt(i);
189196
if (g == win)
190197
return;
191198
if (g is Window)
192199
break;
193200
}
194201

195202
if (i >= 0)
196-
SetChildIndex(win, i);
203+
popupLayer.SetChildIndex(win, i);
197204
}
198205

199206
/// <summary>
@@ -208,12 +215,12 @@ public void ShowModalWait()
208215
if (_modalWaitPane == null || _modalWaitPane.isDisposed)
209216
{
210217
_modalWaitPane = UIPackage.CreateObjectFromURL(UIConfig.globalModalWaiting);
211-
_modalWaitPane.SetHome(this);
218+
_modalWaitPane.SetHome(popupLayer);
212219
}
213-
_modalWaitPane.SetSize(this.width, this.height);
214-
_modalWaitPane.AddRelation(this, RelationType.Size);
220+
_modalWaitPane.SetSize(popupLayer.width, popupLayer.height);
221+
_modalWaitPane.AddRelation(popupLayer, RelationType.Size);
215222

216-
AddChild(_modalWaitPane);
223+
popupLayer.AddChild(_modalWaitPane);
217224
}
218225
}
219226

@@ -223,7 +230,7 @@ public void ShowModalWait()
223230
public void CloseModalWait()
224231
{
225232
if (_modalWaitPane != null && _modalWaitPane.parent != null)
226-
RemoveChild(_modalWaitPane);
233+
popupLayer.RemoveChild(_modalWaitPane);
227234
}
228235

229236
/// <summary>
@@ -258,10 +265,10 @@ public void CloseAllWindows()
258265
/// <returns></returns>
259266
public Window GetTopWindow()
260267
{
261-
int cnt = this.numChildren;
268+
int cnt = popupLayer.numChildren;
262269
for (int i = cnt - 1; i >= 0; i--)
263270
{
264-
GObject g = this.GetChildAt(i);
271+
GObject g = popupLayer.GetChildAt(i);
265272
if (g is Window)
266273
{
267274
return (Window)(g);
@@ -288,10 +295,10 @@ public GGraph modalLayer
288295
void CreateModalLayer()
289296
{
290297
_modalLayer = new GGraph();
291-
_modalLayer.DrawRect(this.width, this.height, 0, Color.white, UIConfig.modalLayerColor);
292-
_modalLayer.AddRelation(this, RelationType.Size);
298+
_modalLayer.DrawRect(popupLayer.width, popupLayer.height, 0, Color.white, UIConfig.modalLayerColor);
299+
_modalLayer.AddRelation(popupLayer, RelationType.Size);
293300
_modalLayer.name = _modalLayer.gameObjectName = "ModalLayer";
294-
_modalLayer.SetHome(this);
301+
_modalLayer.SetHome(popupLayer);
295302
}
296303

297304
/// <summary>
@@ -346,26 +353,26 @@ private void AdjustModalLayer()
346353
if (_modalLayer == null || _modalLayer.isDisposed)
347354
CreateModalLayer();
348355

349-
int cnt = this.numChildren;
356+
int cnt = popupLayer.numChildren;
350357

351358
if (_modalWaitPane != null && _modalWaitPane.parent != null)
352-
SetChildIndex(_modalWaitPane, cnt - 1);
359+
popupLayer.SetChildIndex(_modalWaitPane, cnt - 1);
353360

354361
for (int i = cnt - 1; i >= 0; i--)
355362
{
356-
GObject g = this.GetChildAt(i);
363+
GObject g = popupLayer.GetChildAt(i);
357364
if ((g is Window) && (g as Window).modal)
358365
{
359366
if (_modalLayer.parent == null)
360-
AddChildAt(_modalLayer, i);
367+
popupLayer.AddChildAt(_modalLayer, i);
361368
else
362-
SetChildIndexBefore(_modalLayer, i);
369+
popupLayer.SetChildIndexBefore(_modalLayer, i);
363370
return;
364371
}
365372
}
366373

367374
if (_modalLayer.parent != null)
368-
RemoveChild(_modalLayer);
375+
_modalLayer.RemoveFromParent();
369376
}
370377

371378
/// <summary>
@@ -448,7 +455,7 @@ public void ShowPopup(GObject popup, GObject target, PopupDirection dir, bool cl
448455
GObject p = target;
449456
while (p != null)
450457
{
451-
if (p.parent == this)
458+
if (p.parent == popupLayer)
452459
{
453460
if (popup.sortingOrder < p.sortingOrder)
454461
{
@@ -460,7 +467,7 @@ public void ShowPopup(GObject popup, GObject target, PopupDirection dir, bool cl
460467
}
461468
}
462469

463-
AddChild(popup);
470+
popupLayer.AddChild(popup);
464471
AdjustModalLayer();
465472

466473
if ((popup is Window) && target == null && dir == PopupDirection.Auto)
@@ -495,14 +502,14 @@ public Vector2 GetPoupPosition(GObject popup, GObject target, PopupDirection dir
495502
}
496503
else
497504
{
498-
pos = this.GlobalToLocal(Stage.inst.touchPosition);
505+
pos = popupLayer.GlobalToLocal(Stage.inst.touchPosition);
499506
}
500507
float xx, yy;
501508
xx = pos.x;
502-
if (xx + popup.width > this.width)
509+
if (xx + popup.width > popupLayer.width)
503510
xx = xx + size.x - popup.width;
504511
yy = pos.y + size.y;
505-
if ((dir == PopupDirection.Auto && yy + popup.height > this.height)
512+
if ((dir == PopupDirection.Auto && yy + popup.height > popupLayer.height)
506513
|| dir == PopupDirection.Up)
507514
{
508515
yy = pos.y - popup.height - 1;
@@ -622,7 +629,7 @@ void ClosePopup(GObject target)
622629
if (target is Window)
623630
((Window)target).Hide();
624631
else
625-
RemoveChild(target);
632+
target.RemoveFromParent();
626633
}
627634
}
628635

@@ -652,7 +659,7 @@ public void ShowTooltips(string msg, float delay)
652659
}
653660

654661
_defaultTooltipWin = UIPackage.CreateObjectFromURL(resourceURL);
655-
_defaultTooltipWin.SetHome(this);
662+
_defaultTooltipWin.SetHome(popupLayer);
656663
_defaultTooltipWin.touchable = false;
657664
}
658665

@@ -690,13 +697,13 @@ void __showTooltipsWin(object param)
690697
float xx = Stage.inst.touchPosition.x + 10;
691698
float yy = Stage.inst.touchPosition.y + 20;
692699

693-
Vector2 pt = this.GlobalToLocal(new Vector2(xx, yy));
700+
Vector2 pt = popupLayer.GlobalToLocal(new Vector2(xx, yy));
694701
xx = pt.x;
695702
yy = pt.y;
696703

697-
if (xx + _tooltipWin.width > this.width)
704+
if (xx + _tooltipWin.width > popupLayer.width)
698705
xx = xx - _tooltipWin.width;
699-
if (yy + _tooltipWin.height > this.height)
706+
if (yy + _tooltipWin.height > popupLayer.height)
700707
{
701708
yy = yy - _tooltipWin.height - 1;
702709
if (yy < 0)
@@ -705,7 +712,7 @@ void __showTooltipsWin(object param)
705712

706713
_tooltipWin.x = Mathf.RoundToInt(xx);
707714
_tooltipWin.y = Mathf.RoundToInt(yy);
708-
AddChild(_tooltipWin);
715+
popupLayer.AddChild(_tooltipWin);
709716
}
710717

711718
/// <summary>
@@ -716,7 +723,7 @@ public void HideTooltips()
716723
if (_tooltipWin != null)
717724
{
718725
if (_tooltipWin.parent != null)
719-
RemoveChild(_tooltipWin);
726+
_tooltipWin.RemoveFromParent();
720727
_tooltipWin = null;
721728
}
722729
}

0 commit comments

Comments
 (0)