/// <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)); }
/// <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"); }
private void OnConfirmed(ModalStatusCode status, string tag) { string sceneName = SceneManager.GetActiveScene().name; if (sceneName == "MainMenuScene") { SceneManager.LoadScene(sceneName); } }
/// <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); } }
/// <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"); } }
/// <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)); }
/// <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)); }
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(); }
public ConfirmModalResult(ModalStatusCode status, bool result) { Status = status; Result = result; }
public QuantityModalResult(ModalStatusCode status, int quantity) { Status = status; Quantity = quantity; }
static void TestConfirmModalCallback(ModalStatusCode status, string tag, bool result) { ConsoleModule.WriteLine(string.Format("Confirm Modal Returned \"{0}\",{2} [{1}]", tag, status, result)); }
static void TestQuantityModalCallback(ModalStatusCode status, string tag, int quantity) { ConsoleModule.WriteLine(string.Format("Quantity Modal Returned \"{0}\",{2} [{1}]", tag, status, quantity)); }
static void TestMessageModalCallback(ModalStatusCode status, string tag) { ConsoleModule.WriteLine(string.Format("Message Modal Returned \"{0}\" [{1}]", tag, status)); }
public MessageModalResult(ModalStatusCode status) { Status = status; }