Esempio n. 1
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));
        }
Esempio n. 2
0
 /// <summary>
 /// Handler for when the user acknowledges there was an error, sends them back to the main menu
 /// </summary>
 private void OnErrorConfirmed(ModalStatusCode status, string tag)
 {
     GameState.Reset();
     MetaState.Reset();
     GC.Collect();
     SceneManager.LoadScene("MainMenuScene");
 }
Esempio n. 3
0
        private void OnConfirmed(ModalStatusCode status, string tag)
        {
            string sceneName = SceneManager.GetActiveScene().name;

            if (sceneName == "MainMenuScene")
            {
                SceneManager.LoadScene(sceneName);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Handler for when the user acknowledges there was an error, sends them back
 /// </summary>
 private void OnErrorConfirmed(ModalStatusCode status, string tag, bool result)
 {
     if (result)
     {
         GameState.Clear();
         MetaState.Instance.Clear();
         SceneManager.LoadScene(CoreParams.MainMenuScene);
     }
     else
     {
         MetaState.Instance.NextScene = MetaState.Instance.PreviousScene;
         SceneManager.LoadScene(CoreParams.LoadingScene);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Handler for when the user acknowledges there was an error, sends them back
 /// </summary>
 private void OnErrorConfirmed(ModalStatusCode status, string tag, bool result)
 {
     if (result)
     {
         GameState.Clear();
         MetaState.Reset();
         GC.Collect();
         SceneManager.LoadScene("MainMenuScene");
     }
     else
     {
         MetaState.Instance.NextScene = MetaState.Instance.PreviousScene;
         SceneManager.LoadScene("LoadingScene");
     }
 }
Esempio n. 6
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));
        }
Esempio n. 7
0
        /// <summary>
        /// Pushes a quantity modal and allows it to be awaited
        /// </summary>
        public static async Task <QuantityModalResult> PushQuantityModalAsync(string heading, int min, int max, int initial, bool allowCancel, bool ephemeral, CancellationToken?token)
        {
            bool            finished = false;
            ModalStatusCode status   = ModalStatusCode.Undefined;
            int             quantity = initial;

            QuantityModalCallback callback = (s, t, q) => { finished = true; status = s; quantity = q; };

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

            go.GetComponent <QuantityModalController>().SetInitial(heading, min, max, initial, allowCancel, 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 QuantityModalResult(status, quantity));
        }
Esempio n. 8
0
        private void CompleteItemDrop(InventoryItemInstance itemInstance, InventoryItemModel itemModel, int quantity, ModalStatusCode status)
        {
            if (quantity == 0 || status != ModalStatusCode.Complete)
            {
                return;
            }

            GameState.Instance.PlayerRpgState.Inventory.RemoveItem(itemInstance, quantity);
            Transform playerT = WorldUtils.GetPlayerObject().transform;
            Vector3   dropPos = (playerT.position + (playerT.forward.normalized * 1.0f));

            RpgWorldUtils.DropItem(itemModel, quantity, dropPos);

            SignalPaint();
        }
Esempio n. 9
0
 public ConfirmModalResult(ModalStatusCode status, bool result)
 {
     Status = status;
     Result = result;
 }
Esempio n. 10
0
 public QuantityModalResult(ModalStatusCode status, int quantity)
 {
     Status   = status;
     Quantity = quantity;
 }
Esempio n. 11
0
 static void TestConfirmModalCallback(ModalStatusCode status, string tag, bool result)
 {
     ConsoleModule.WriteLine(string.Format("Confirm Modal Returned \"{0}\",{2} [{1}]", tag, status, result));
 }
Esempio n. 12
0
 static void TestQuantityModalCallback(ModalStatusCode status, string tag, int quantity)
 {
     ConsoleModule.WriteLine(string.Format("Quantity Modal Returned \"{0}\",{2} [{1}]", tag, status, quantity));
 }
Esempio n. 13
0
 static void TestMessageModalCallback(ModalStatusCode status, string tag)
 {
     ConsoleModule.WriteLine(string.Format("Message Modal Returned \"{0}\" [{1}]", tag, status));
 }
Esempio n. 14
0
 public MessageModalResult(ModalStatusCode status)
 {
     Status = status;
 }