/// <summary> Shows the given popup with the given settings and returns a reference to it </summary> /// <param name="popupName"> The popup name to search for in the PopupDatabase linked to a UIPopup prefab. If the prefab is found, a clone of it will get instantiated and then shown </param> /// <param name="addToPopupQueue"> If the popup is added to the PopupQueue, it will be shown when its turn comes up. Until then it will remain hidden </param> /// <param name="instantAction"> When shown, should the popup animate instantly? (in zero seconds) </param> public static UIPopup ShowPopup(string popupName, bool addToPopupQueue, bool instantAction) { UIPopup popup = GetPopup(popupName); ShowPopup(popup, addToPopupQueue, instantAction); return(popup); }
/// <summary> Removes the first UIPopup registered with the given popupName from the PopupQueue (if it exists) </summary> /// <param name="popupName"> The popup name to search for </param> /// <param name="showNextInQueue"> After removing the corresponding UIPopup from the PopupQueue, should the next popup in queue be shown? </param> public static void RemoveFromQueue(string popupName, bool showNextInQueue = true) { if (!IsInQueue(popupName)) { return; } UIPopupQueueData data = GetPopupData(popupName); if (data == null) { return; } PopupQueue.Remove(data); if (Instance.DebugComponent) { DDebug.Log("UIPopup '" + data.PopupName + "' removed from the PopupQueue", Instance); } if (data.Popup == null) { return; } data.Popup.AddedToQueue = false; if (CurrentVisibleQueuePopup != data.Popup) { return; } CurrentVisibleQueuePopup = null; if (showNextInQueue) { ShowNextInQueue(); } }
/// <summary> Shows the given popup with the given settings </summary> /// <param name="popup"> Target popup that needs to be shown </param> /// <param name="addToPopupQueue"> If the popup is added to the PopupQueue, it will be shown when its turn comes up. Until then it will remain hidden. </param> /// <param name="instantAction"> When shown, should the popup animate instantly? (in zero seconds) </param> /// <param name="targetCanvasName"> Sets a new UICanvas target by looking for an UICanvas with the given name (also re-parents the popup to it) </param> public static void ShowPopup(UIPopup popup, bool addToPopupQueue, bool instantAction, string targetCanvasName) { if (popup == null) { return; } popup.SetTargetCanvasName(targetCanvasName); ShowPopup(popup, addToPopupQueue, instantAction); }
/// <summary> Returns TRUE if the prefab has a reference in the database </summary> /// <param name="prefab"> Prefab to search for </param> public bool Contains(UIPopup prefab) { if (prefab == null) { return(false); } foreach (UIPopupLink reference in Popups) { if (reference.Prefab == prefab.gameObject) { return(true); } } return(false); }
/// <summary> /// Returns the popup name defined for the given prefab. /// <para /> /// Returns null if the prefab has not been referenced in the database. /// </summary> /// <param name="prefab"> Prefab to search for (null will get ignored and return NULL)</param> public string GetPopupName(UIPopup prefab) { if (prefab == null) { return(null); } foreach (UIPopupLink reference in Popups) { if (reference.Prefab == prefab.gameObject) { return(reference.PopupName); } } return(null); }
/// <summary> /// Iterates through the database and returns the index where the prefab reference is found. /// Returns -1 if the prefab reference was not found. /// </summary> /// <param name="prefab"> Prefab to search for (null will get ignored and return -1) </param> public int IndexOf(UIPopup prefab) { if (!Contains(prefab)) { return(-1); } for (int i = 0; i < Popups.Count; i++) { if (Popups[i].Prefab == prefab.gameObject) { return(i); } } return(-1); }
/// <summary> Returns TRUE if at least one entry of the given popup is found in the PopupQueue </summary> /// <param name="popup"> Target popup to search for </param> public static bool IsInQueue(UIPopup popup) { if (popup == null || QueueIsEmpty) { return(false); } foreach (UIPopupQueueData link in PopupQueue) { if (link.Popup == popup) { return(true); } } return(false); }
/// <summary> Retrieves the first UIPopupQueueData registered in the PopupQueue with the giver popup reference </summary> /// <param name="popup"> Target popup to search for </param> private static UIPopupQueueData GetPopupData(UIPopup popup) { if (popup == null || QueueIsEmpty) { return(null); } foreach (UIPopupQueueData link in PopupQueue) { if (link.Popup == popup) { return(link); } } return(null); }
/// <summary> Add the passed UIPopup to the PopupQueue </summary> /// <param name="popup"> Target UIPopup to be added to the PopupQueue </param> /// <param name="instantAction"> When shown, should the popup animate instantly? (in zero seconds) </param> public static void AddToQueue(UIPopup popup, bool instantAction = false) { var data = new UIPopupQueueData(popup, instantAction); PopupQueue.Add(data); popup.AddedToQueue = true; if (Instance.DebugComponent) { DDebug.Log("UIPopup '" + popup.PopupName + "' added to the PopupQueue", Instance); } if (CurrentVisibleQueuePopup != null) { return; } ShowNextInQueue(); }
/// <summary> Shows the given popup with the given settings </summary> /// <param name="popup"> Target popup that needs to be shown </param> /// <param name="addToPopupQueue"> If the popup is added to the PopupQueue, it will be shown when its turn comes up. Until then it will remain hidden. </param> /// <param name="instantAction"> When shown, should the popup animate instantly? (in zero seconds) </param> public static void ShowPopup(UIPopup popup, bool addToPopupQueue, bool instantAction) { if (popup == null) { return; } if (addToPopupQueue) { AddToQueue(popup, instantAction); return; } if (Instance.DebugComponent) { DDebug.Log("Showing UIPopup '" + popup.PopupName + "'", Instance); } popup.Show(instantAction); }
/// <summary> Shows the next popup in the PopupQueue (if any) </summary> public static void ShowNextInQueue() { while (true) { if (QueueIsEmpty) { return; } if (PopupQueue[0].Popup == null) { PopupQueue.RemoveAt(0); continue; } CurrentVisibleQueuePopup = PopupQueue[0].Show(); break; } }
/// <summary> Removes the given popup reference from the PopupQueue (if it exists) </summary> /// <param name="popup"> Target popup to search for </param> /// <param name="showNextInQueue"> After removing the corresponding UIPopup from the PopupQueue, should the next popup in queue be shown? </param> public static void RemoveFromQueue(UIPopup popup, bool showNextInQueue = true) { if (!IsInQueue(popup)) { return; } PopupQueue.Remove(GetPopupData(popup)); if (Instance.DebugComponent) { DDebug.Log("UIPopup '" + popup.PopupName + "' added to the PopupQueue", Instance); } popup.AddedToQueue = false; if (CurrentVisibleQueuePopup != popup) { return; } CurrentVisibleQueuePopup = null; if (showNextInQueue) { ShowNextInQueue(); } }
/// <summary> /// Initializes a new instance of the class with a reference to the UIPopup and AnimationType, /// of the UIPopupBehavior, that triggered that sent this message /// </summary> /// <param name="popup"> Reference to the UIPopup that sent this message </param> /// <param name="animationType"> AnimationType of the UIPopupBehavior that triggered the UIPopup to send this message </param> public UIPopupMessage(UIPopup popup, AnimationType animationType) { Popup = popup; AnimationType = animationType; }
/// <summary> /// Initializes a new instance of the class with a reference to the UIPopup that triggered that sent this message /// (AnimationType = AnimationType.Undefined) /// </summary> /// <param name="popup"> Reference to the UIPopup that sent this message </param> public UIPopupMessage(UIPopup popup) { Popup = popup; AnimationType = AnimationType.Undefined; }
/// <summary> Initializes a new instance of the class with the given settings </summary> /// <param name="popupName"> Designated popup name </param> /// <param name="popup"> Reference to an UIPopup in the scene (that is hidden and awaits to be shown) </param> /// <param name="instantAction"> Should the show animation happen instantly? (zero seconds) </param> public UIPopupQueueData(string popupName, UIPopup popup, bool instantAction = false) { PopupName = popupName; Popup = popup; InstantAction = instantAction; }
private static void RunOnStart() { ApplicationIsQuitting = false; CurrentVisibleQueuePopup = null; PopupQueue.Clear(); }