public void SetInitial(string heading, string text, string continueText, string cancelText, string tag, ConfirmModalCallback callback)
        {
            if (IsSet)
            {
                CDebug.LogEx("ConfirmModal was set more than once!", LogLevel.Warning, this);
            }

            if (!string.IsNullOrEmpty(heading))
            {
                HeadingText.text = Sub.Macro(heading);
            }

            if (!string.IsNullOrEmpty(text))
            {
                MainText.text = Sub.Macro(text);
            }

            if (!string.IsNullOrEmpty(continueText))
            {
                ContinueButtonText.text = Sub.Macro(continueText);
            }

            if (!string.IsNullOrEmpty(cancelText))
            {
                CancelButtonText.text = Sub.Macro(cancelText);
            }

            ResultTag = tag;

            if (callback == null)
            {
                CDebug.LogEx("ConfirmModal was passed null callback!", LogLevel.Warning, this);
            }
            else
            {
                Callback = callback;
            }

            IsSet = true;
        }
Beispiel #2
0
        /// <summary>
        /// Pushes a confirm modal and allows it to be awaited
        /// </summary>
        public static async Task <ConfirmModalResult> PushConfirmModalAsync(string text, string heading, string yesText, string noText, bool ephemeral, CancellationToken?token)
        {
            bool            finished = false;
            ModalStatusCode status   = ModalStatusCode.Undefined;
            bool            result   = false;

            ConfirmModalCallback callback = (s, t, r) => { finished = true; status = s; result = r; };

            var go = GameObject.Instantiate <GameObject>(CoreUtils.LoadResource <GameObject>(ConfirmModalPrefab), ephemeral ? GetEphemeralOrUIRoot() : CoreUtils.GetUIRoot());

            go.GetComponent <ConfirmModalController>().SetInitial(heading, text, yesText, noText, null, callback);

            while (!(finished || go == null))
            {
                if (token != null && token.Value.IsCancellationRequested)
                {
                    if (go != null)
                    {
                        UnityEngine.Object.Destroy(go);
                    }

                    break;
                }

                await Task.Yield();
            }

            await Task.Yield(); //let the callback run, hopefully

            if (status == ModalStatusCode.Undefined)
            {
                status = ModalStatusCode.Aborted;
            }

            return(new ConfirmModalResult(status, result));
        }
Beispiel #3
0
        /// <summary>
        /// Pushes a confirm modal and invokes the callback when dismissed
        /// </summary>
        public static void PushConfirmModal(string text, string heading, string yesText, string noText, string tag, ConfirmModalCallback callback, bool ephemeral)
        {
            var go = GameObject.Instantiate <GameObject>(CoreUtils.LoadResource <GameObject>(ConfirmModalPrefab), ephemeral ? GetEphemeralOrUIRoot() : CoreUtils.GetUIRoot());

            go.GetComponent <ConfirmModalController>().SetInitial(heading, text, yesText, noText, tag, callback);
        }
Beispiel #4
0
 /// <summary>
 /// Pushes a confirm modal and invokes the callback when dismissed
 /// </summary>
 public static void PushConfirmModal(string text, string heading, string yesText, string noText, string tag, ConfirmModalCallback callback)
 {
     PushConfirmModal(text, heading, yesText, noText, tag, callback, false);
 }