Ejemplo n.º 1
0
        public void SetInitial(string heading, string text, string next, string tag, MessageModalCallback callback)
        {
            if (IsSet)
            {
                CDebug.LogEx("MessageModal 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(next))
            {
                ButtonText.text = Sub.Macro(next);
            }

            ResultTag = tag;

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

            IsSet = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Pushes a message modal and allows it to be awaited
        /// </summary>
        public static async Task <MessageModalResult> PushMessageModalAsync(string text, string heading, bool ephemeral, CancellationToken?token)
        {
            //we could probably switch this to a TaskCompletionSource

            bool            finished = false;
            ModalStatusCode status   = ModalStatusCode.Undefined;

            MessageModalCallback callback = (s, t) => { finished = true; status = s; };

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

            go.GetComponent <MessageModalController>().SetInitial(heading, text, null, null, callback);

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

                    break;
                }

                await Task.Yield();
            }

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

            return(new MessageModalResult(status));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Pushes a message modal and invokes the callback when dismissed
        /// </summary>
        public static void PushMessageModal(string text, string heading, string tag, MessageModalCallback callback, bool ephemeral)
        {
            var go = GameObject.Instantiate <GameObject>(CoreUtils.LoadResource <GameObject>(MessageModalPrefab), ephemeral ? GetEphemeralOrUIRoot() : CoreUtils.GetUIRoot());

            go.GetComponent <MessageModalController>().SetInitial(heading, text, null, tag, callback);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Pushes a message modal and invokes the callback when dismissed
 /// </summary>
 public static void PushMessageModal(string text, string heading, string tag, MessageModalCallback callback)
 {
     PushMessageModal(text, heading, tag, callback, false);
 }