public static async Task SimulateManyChangesInModel(DataStore <CellsModel> store, int nrOfChanges = 100) { var t = Log.MethodEnteredWith("nrOfChanges=" + nrOfChanges); var random = new Random(); var ops = new string[] { "+", "-", "*", "/" }; var progress = ProgressUi.NewProgress(nrOfChanges); for (int i = 0; i < nrOfChanges; i++) { progress.IncrementCount(); try { int column = random.Next(1, 26 * 2); int row = random.Next(1, 26 * 2); string rndFormula = RndVar(random, store) + random.NextRndChild(ops) + RndVar(random, store); store.Dispatch(new MyActions.SetCell(CellPos.ToColumnName(column), row, rndFormula)); } catch (Exception e) { Log.e(e); } if (i % 10 == 0) { await TaskV2.Delay(20); } // Every few mutations wait to let the UI catch UI } progress.SetComplete(); Log.MethodDone(t); }
private static ProgressUi ShowBlockingProgressUiFor(ViewStack self, string blockingProgressViewPrefabName, ProgressManager prManager) { GameObject prGo = self.ShowView(blockingProgressViewPrefabName); ProgressUi prUi = prGo.GetComponentInChildren <ProgressUi>(); prUi.onProgressUiComplete += () => { prGo.GetViewStack().SwitchBackToLastView(prGo); }; prUi.progressManager = prManager; return(prUi); }
/// <summary> Displays a progress UI that is blocking so that the user cant do input /// while the progress is showing, useful for loading screens etc </summary> private async Task SetupBlockingProgressButton() { await gameObject.GetLinkMap().Get <Button>("BlockingProgressButton").SetOnClickAction(async delegate { ProgressManager prManager = new ProgressManager(); ProgressUi progressUi = gameObject.GetViewStack().ShowBlockingProgressUiFor(prManager); IProgress progress = prManager.GetOrAddProgress("DemoLoadingProgress", 200, true); await SimulateProgressOn(progressUi, progress, 15); AssertV2.IsTrue(progressUi.IsDestroyed(), "Blocking progress not destroyed after it completed"); }); }
private static async Task SimulateProgressOn(ProgressUi progressUi, IProgress progress, int delayInMsPerUpdate) { progressUi.progressDetailsInfoText?.textLocalized("I am a progress UI, I hope I wont take to long!"); for (int i = 0; i < progress.totalCount - 1; i++) { progress.IncrementCount(); await TaskV2.Delay(delayInMsPerUpdate); } progressUi.progressDetailsInfoText?.textLocalized("The last % is always the hardest!"); await TaskV2.Delay(2000); progress.IncrementCount(); await TaskV2.Delay(15); }
/// <summary> Displays a progress UI that is blocking so that the user cant do input /// while the progress is showing, useful for loading screens etc </summary> private async Task SetupBlockingProgressButton() { await gameObject.GetLinkMap().Get <Button>("BlockingProgressButton").SetOnClickAction(async delegate { ProgressManager prManager = new ProgressManager(); ProgressUi progressUi = gameObject.GetViewStack().ShowBlockingProgressUiFor(prManager); IProgress progress = prManager.GetOrAddProgress("DemoLoadingProgress", 200, true); progressUi.progressDetailsInfoText?.textLocalized("I am a progress UI, I hope I wont take to long!"); for (int i = 0; i < progress.totalCount - 1; i++) { progress.IncrementCount(); await TaskV2.Delay(15); } progressUi.progressDetailsInfoText?.textLocalized("The last % is always the hardest!"); await TaskV2.Delay(2000); progress.IncrementCount(); await TaskV2.Delay(15); AssertV2.IsTrue(progressUi.IsDestroyed(), "Blocking progress not destroyed after it completed"); }); }