/// <inheritdoc cref="IUIController.ChangeSceneGraph"/> public IPromise ChangeSceneGraph(string sceneName, bool precacheIfNot = true) { Promise promise = new Promise(); if (!_dataController.IsLoaded()) { promise.Fail(new Exception("UISystem is not initialized")); return(promise); } if (!_dataController.TryGetSceneGraph(sceneName, out UISceneGraph graph)) { promise.Fail(new Exception($"There is no graph for {sceneName} scene.")); return(promise); } return(_dataController.PrecacheSceneUI(sceneName).Then(() => { _screenStack.Clear(); _currentScreen = null; _currentGraph = graph; UIScreenNode startNode = _currentGraph.GetStartNode(); RequestScreen(startNode.Name).Then(promise.Resolve); })); }
public List <UIElement> GetUIElements(UIScreenNode node) { if (_cachedUIElementsForScreen.TryGetValue(node.Name, out List <UIElement> list)) { return(list); } list = new List <UIElement>(); foreach (string name in node.ElementIdsList) { if (UIElements.TryGetValue(name, out UIElement value)) { list.Add(value); } } _cachedUIElementsForScreen.Add(node.Name, list); return(list); }
/// <inheritdoc cref="IUIController.RequestScreen"/> public IPromise RequestScreen(string screenName, object arg = null) { Promise promise = new Promise(); if (!_dataController.IsLoaded()) { promise.Fail(new Exception("UISystem is not initialized")); return(promise); } if (_currentScreen != null && _currentScreen.Name == screenName) { promise.Resolve(); return(promise); } UIScreenNode screen = _currentGraph.GetScreenNode(screenName); if (screen == null) { promise.Fail(new Exception($"There is no screen named {screenName}")); return(promise); } List <UIElement> elements = _currentGraph.GetUIElements(screen); return(_viewHandler.TransitionScreen(screen.Layer, elements, arg).Then(() => { while (_screenStack.Count > 0 && _screenStack.Peek().Layer >= screen.Layer) { _screenStack.Pop(); } _screenStack.Push(screen); _currentScreen = _currentGraph.GetScreenNode(screenName); })); }