Beispiel #1
0
        private async Task <TWidget> GetInstance <TWidget>(string widgetPath, UIMessage message,
                                                           IWidgetFactory factory = null)
            where TWidget : Widget
        {
            if (PoolingWidgets.ContainsKey(widgetPath))
            {
                var pool = PoolingWidgets[widgetPath];
                if (pool.Count > 0)
                {
                    var instance = pool.Pop();
                    return(instance as TWidget);
                }
            }

            if (factory == null)
            {
                factory = DefaultFactory;
            }

            TWidget widget;

            try { widget = (TWidget)await factory.CreateInstance(this, widgetPath, message); }
            catch (Exception e)
            {
                Her.Error(e);
                throw;
            }

            // mark widget factory
            FactoryLookup.Add(widget.ViewId, factory);

            return(widget);
        }
Beispiel #2
0
        public async Task <Widget> CreateInstance(IUIStack manager, string name, UIMessage message)
        {
            var loader = Her.Resolve <IViewLoader>();
            var prefab = await loader.LoadView(name);

            if (prefab == null)
            {
                throw new Exception($"Load view: {name} failed");
            }

            var instance = Object.Instantiate(prefab).GetComponent <Widget>();

            instance.SetManagerInfo(name, manager, message);
            return(instance);
        }
Beispiel #3
0
        public async Task <ulong> PushAsync <TWidget>(string widgetName, UIMessage message,
                                                      IWidgetFactory factory = null)
            where TWidget : Widget
        {
            var instance = await GetInstance <TWidget>(widgetName, message, factory);

            var parent = LayerLookup[instance.Layer];

            instance.transform.SetParent(parent.transform, false);

            switch (instance.Layer)
            {
            case UILayer.Popup:
                Popups.Add(instance.ViewId);
                break;
            }

            if (StackedWindows.Count > 0)
            {
                var prevWidget = StackedWindows.Peek();

                if (prevWidget != null)
                {
                    await prevWidget.OnFreeze();

                    // Window will overlay previous windows.
                    if (instance.Layer == UILayer.Window && WindowsInDisplay.Contains(prevWidget.ViewId))
                    {
                        WindowsInDisplay.Remove(prevWidget.ViewId);
                    }
                }
            }

            await instance.OnShow();

            StackedWindows.Push(instance);
            WindowsInDisplay.Add(instance.ViewId);

            return(instance.ViewId);
        }
Beispiel #4
0
 public async Task <ulong> PushAsync(string widgetName, UIMessage message,
                                     IWidgetFactory factory = null)
 {
     return(await PushAsync <Widget>(widgetName, message, factory));
 }
Beispiel #5
0
 public virtual void SetManagerInfo(string path, IUIStack manager, UIMessage message)
 {
     Path     = path;
     IuiStack = manager;
     Message  = message;
 }