Skip to content

Commit 144658c

Browse files
committed
Clarified GetNextAvailablePopupPanel
1 parent d7ba27c commit 144658c

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

Assets/BossRoom/Scripts/Client/UI/PopupManager.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using UnityEngine;
45

@@ -55,30 +56,33 @@ void DisplayPopupPanel(string titleText, string mainText)
5556

5657
PopupPanel GetNextAvailablePopupPanel()
5758
{
58-
PopupPanel popupPanel = null;
59-
foreach (var popup in m_PopupPanels)
59+
int nextAvailablePopupIndex = 0;
60+
// Find the index of the first PopupPanel that is not displaying and has no popups after it that are currently displaying
61+
for (int i = 0; i < m_PopupPanels.Count; i++)
6062
{
61-
if (popupPanel == null && !popup.IsDisplaying)
63+
if (m_PopupPanels[i].IsDisplaying)
6264
{
63-
popupPanel = popup;
64-
}
65-
else if (popup.IsDisplaying)
66-
{
67-
popupPanel = null;
65+
nextAvailablePopupIndex = i + 1;
6866
}
6967
}
7068

71-
if (popupPanel == null)
69+
if (nextAvailablePopupIndex < m_PopupPanels.Count)
70+
{
71+
return m_PopupPanels[nextAvailablePopupIndex];
72+
}
73+
74+
// None of the current PopupPanels are available, so instantiate a new one
75+
var popupGameObject = Instantiate(m_PopupPanelPrefab, gameObject.transform);
76+
popupGameObject.transform.position += new Vector3(1, -1) * (k_Offset * m_PopupPanels.Count % k_MaxOffset);
77+
var popupPanel = popupGameObject.GetComponent<PopupPanel>();
78+
if (popupPanel != null)
7279
{
73-
var popupGameObject = Instantiate(m_PopupPanelPrefab, gameObject.transform);
74-
popupGameObject.transform.position += new Vector3(1, -1) * (k_Offset * m_PopupPanels.Count % k_MaxOffset);
75-
popupPanel = popupGameObject.GetComponent<PopupPanel>();
76-
if (popupPanel == null)
77-
{
78-
Debug.LogError("PopupPanel prefab does not have a PopupPanel component!");
79-
}
8080
m_PopupPanels.Add(popupPanel);
8181
}
82+
else
83+
{
84+
Debug.LogError("PopupPanel prefab does not have a PopupPanel component!");
85+
}
8286

8387
return popupPanel;
8488
}

0 commit comments

Comments
 (0)