Exemple #1
0
        internal void OnCallBack(bool leftButtonClicked)
        {
            uGUI_SceneConfirmation confirmation = uGUI.main.confirmation;

            // Run actions based on which button was pressed
            if (leftButtonClicked)
            {
                leftButton.Action?.Invoke();
            }
            else
            {
                rightButton.Action?.Invoke();
            }

            // Revert everything to its original state
            if (confirmation.yes.gameObject.activeSelf && !confirmation.no.gameObject.activeSelf)
            {
                confirmation.yes.transform.localPosition = new Vector3(
                    pos,
                    confirmation.yes.transform.localPosition.y,
                    confirmation.yes.transform.localPosition.z);
            }
            if (!confirmation.yes.gameObject.activeSelf && confirmation.no.gameObject.activeSelf)
            {
                confirmation.no.transform.localPosition = new Vector3(
                    pos,
                    confirmation.no.transform.localPosition.y,
                    confirmation.no.transform.localPosition.z);
            }

            confirmation.yes.gameObject.SetActive(true);
            confirmation.no.gameObject.SetActive(true);

            SetText(confirmation.yes.gameObject, "Yes");
            SetText(confirmation.no.gameObject, "No");

            confirmation.gameObject.GetComponentInChildren <Image>().sprite = Sprite;

            ChangeAllFontSizes(confirmation.gameObject, 4f);

            // Re-open the dialog if the button pressed was not close
            bool closeButtonClicked = (leftButtonClicked && leftButton == Button.Close) || (!leftButtonClicked && rightButton == Button.Close);

            if (!closeButtonClicked)
            {
                Show();
            }
            else
            {
                UnityEngine.Object.Destroy(coroutineHandler);
            }
        }
Exemple #2
0
        private IEnumerator ShowDialogEnumerator()
        {
            while (uGUI._main == null)
            {
                yield return(null);
            }

            uGUI_SceneConfirmation confirmation = uGUI.main.confirmation;

            // Disable buttons if their action is null
            if (leftButton.Action == null)
            {
                confirmation.yes.gameObject.SetActive(false);
            }
            if (rightButton.Action == null)
            {
                confirmation.no.gameObject.SetActive(false);
            }

            // Disable buttons if their text is null, otherwise set their button text
            if (string.IsNullOrEmpty(leftButton.Text))
            {
                confirmation.yes.gameObject.SetActive(false);
            }
            else
            {
                SetText(confirmation.yes.gameObject, leftButton.Text);
            }
            if (string.IsNullOrEmpty(rightButton.Text))
            {
                confirmation.no.gameObject.SetActive(false);
            }
            else
            {
                SetText(confirmation.no.gameObject, rightButton.Text);
            }

            // If one button is disabled, center the other
            float pos = 0;

            if (confirmation.yes.gameObject.activeSelf && !confirmation.no.gameObject.activeSelf)
            {
                pos = confirmation.yes.transform.localPosition.x;
                confirmation.yes.transform.localPosition = new Vector3(
                    (confirmation.yes.transform.localPosition.x + confirmation.no.transform.localPosition.x) / 2,
                    confirmation.yes.transform.localPosition.y,
                    confirmation.yes.transform.localPosition.z);
            }
            if (!confirmation.yes.gameObject.activeSelf && confirmation.no.gameObject.activeSelf)
            {
                pos = confirmation.no.transform.localPosition.x;
                confirmation.no.transform.localPosition = new Vector3(
                    (confirmation.no.transform.localPosition.x + confirmation.yes.transform.localPosition.x) / 2,
                    confirmation.no.transform.localPosition.y,
                    confirmation.no.transform.localPosition.z);
            }

            // Turn the dialog blue if the blue parameter is true
            Sprite sprite = confirmation.gameObject.GetComponentInChildren <Image>().sprite;

            if (color == DialogColor.Blue)
            {
                confirmation.gameObject.GetComponentInChildren <Image>().sprite = confirmation.gameObject.GetComponentsInChildren <Image>()[1].sprite;
            }

            // Reduce the text size on the buttons
            object[] texts = ChangeAllFontSizes(confirmation.gameObject, -4f);

            // Show dialog
            confirmation.Show(message, delegate(bool leftButtonClicked)
            {
                // Run actions based on which button was pressed
                if (leftButtonClicked)
                {
                    leftButton.Action?.Invoke();
                }
                else
                {
                    rightButton.Action?.Invoke();
                }

                // Revert everything to its original state
                if (confirmation.yes.gameObject.activeSelf && !confirmation.no.gameObject.activeSelf)
                {
                    confirmation.yes.transform.localPosition = new Vector3(
                        pos,
                        confirmation.yes.transform.localPosition.y,
                        confirmation.yes.transform.localPosition.z);
                }
                if (!confirmation.yes.gameObject.activeSelf && confirmation.no.gameObject.activeSelf)
                {
                    confirmation.no.transform.localPosition = new Vector3(
                        pos,
                        confirmation.no.transform.localPosition.y,
                        confirmation.no.transform.localPosition.z);
                }

                confirmation.yes.gameObject.SetActive(true);
                confirmation.no.gameObject.SetActive(true);

                SetText(confirmation.yes.gameObject, "Yes");
                SetText(confirmation.no.gameObject, "No");

                confirmation.gameObject.GetComponentInChildren <Image>().sprite = sprite;

                ChangeAllFontSizes(texts, 4f);

                UnityEngine.Object.Destroy(coroutineHandler);

                // Re-open the dialog if the button pressed was not close
                bool closeButtonClicked = (leftButtonClicked && leftButton == Button.Close) || (!leftButtonClicked && rightButton == Button.Close);
                if (!closeButtonClicked)
                {
                    Show();
                }
            });

            // Focus popup
            while (confirmation.selected)
            {
                yield return(new WaitForSecondsRealtime(0.25f));
            }

            confirmation.Select();
        }
Exemple #3
0
        internal static IEnumerator ShowDialogEnumerator(string error, Action onLeftButtonPressed, Action onRightButtonPressed, string leftButtonText, string rightButtonText, bool blue, GameObject couroutineHandler)
        {
            while (typeof(uGUI).GetField("_main", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null) == null)
            {
                yield return(null);
            }

            yield return(new WaitForSecondsRealtime(2));

            uGUI_SceneConfirmation confirmation = uGUI.main.confirmation;

            // Disable buttons if their action is null
            if (onLeftButtonPressed == null)
            {
                confirmation.yes.gameObject.SetActive(false);
            }
            if (onRightButtonPressed == null)
            {
                confirmation.no.gameObject.SetActive(false);
            }

            // Disable buttons if their text is null, otherwise set their button text
            if (string.IsNullOrEmpty(leftButtonText))
            {
                confirmation.yes.gameObject.SetActive(false);
            }
            else
            {
                confirmation.yes.gameObject.GetComponentInChildren <Text>().text = leftButtonText;
            }
            if (string.IsNullOrEmpty(rightButtonText))
            {
                confirmation.no.gameObject.SetActive(false);
            }
            else
            {
                confirmation.no.gameObject.GetComponentInChildren <Text>().text = rightButtonText;
            }

            // Turn the dialog blue if the blue parameter is true
            Sprite sprite = confirmation.gameObject.GetComponentInChildren <Image>().sprite;

            if (blue)
            {
                confirmation.gameObject.GetComponentInChildren <Image>().sprite = confirmation.gameObject.GetComponentsInChildren <Image>()[1].sprite;
            }

            // Reduce the text size on the buttons by two pts
            List <Text> texts = confirmation.gameObject.GetComponentsInChildren <Text>().ToList();

            texts.RemoveAt(0);
            texts.Do(t => t.fontSize = t.fontSize - 2);

            // Revert everything after the popup was closed
            confirmation.Show(error, delegate(bool leftButtonClicked)
            {
                if (leftButtonClicked)
                {
                    onLeftButtonPressed?.Invoke();
                }
                else
                {
                    onRightButtonPressed?.Invoke();
                }

                confirmation.yes.gameObject.SetActive(true);
                confirmation.no.gameObject.SetActive(true);

                confirmation.yes.gameObject.GetComponentInChildren <Text>().text = "Yes";
                confirmation.no.gameObject.GetComponentInChildren <Text>().text  = "No";

                confirmation.gameObject.GetComponentInChildren <Image>().sprite = sprite;

                texts.Do(t => t.fontSize = t.fontSize + 2);

                UnityEngine.Object.Destroy(couroutineHandler);
            });

            yield return(null);
        }
Exemple #4
0
        private IEnumerator ShowDialogEnumerator()
        {
            //Must have at least one button with an action
            if (leftButton.Action is null && rightButton.Action is null)
            {
                UnityEngine.Object.Destroy(coroutineHandler);
                yield break;
            }

            //Ensures a new dialog is not created until the main menu has fully loaded or it will break;
            while (uGUI_MainMenu.main is null || FPSInputModule.current is null || FPSInputModule.current.lastGroup != uGUI_MainMenu.main)
            {
                yield return(null);
            }

            uGUI_SceneConfirmation confirmation = uGUI.main.confirmation;

            // Show dialog
            //Had to move this before the code to change its values as the values are reset during the showing in BelowZero.
            confirmation.Show(message, OnCallBack);

            // Disable left button if its text or action is null, otherwise set their button text
            if (leftButton.Action == null || string.IsNullOrEmpty(leftButton.Text))
            {
                confirmation.yes.gameObject.SetActive(false);
            }
            else
            {
                SetText(confirmation.yes.gameObject, leftButton.Text);
            }

            // Disable right button if its text or action is null, otherwise set their button text
            if (rightButton.Action == null || string.IsNullOrEmpty(rightButton.Text))
            {
                confirmation.no.gameObject.SetActive(false);
            }
            else
            {
                SetText(confirmation.no.gameObject, rightButton.Text);
            }

            // Reduce the text size on the buttons
            ChangeAllFontSizes(confirmation.gameObject, -4f);

            // If one button is disabled, center the other
            if (confirmation.yes.gameObject.activeSelf && !confirmation.no.gameObject.activeSelf)
            {
                pos = confirmation.yes.transform.localPosition.x;
                confirmation.yes.transform.localPosition = new Vector3(
                    (confirmation.yes.transform.localPosition.x + confirmation.no.transform.localPosition.x) / 2,
                    confirmation.yes.transform.localPosition.y,
                    confirmation.yes.transform.localPosition.z);
            }
            else if (!confirmation.yes.gameObject.activeSelf && confirmation.no.gameObject.activeSelf)
            {
                pos = confirmation.no.transform.localPosition.x;
                confirmation.no.transform.localPosition = new Vector3(
                    (confirmation.no.transform.localPosition.x + confirmation.yes.transform.localPosition.x) / 2,
                    confirmation.no.transform.localPosition.y,
                    confirmation.no.transform.localPosition.z);
            }

            // Turn the dialog blue if the blue parameter is true
            Sprite = confirmation.gameObject.GetComponentInChildren <Image>().sprite;
            if (color == DialogColor.Blue)
            {
                confirmation.gameObject.GetComponentInChildren <Image>().sprite = confirmation.gameObject.GetComponentsInChildren <Image>()[1].sprite;
            }
        }