Ejemplo n.º 1
0
        ViewPool <TView, TData> Pool(PrefabRef <TView> prefabRef)
        {
            ViewPool <TView, TData> pool;

            if (pools.TryGetValue(prefabRef, out pool) == false)
            {
                var prefab = prefabRef.ExtractPrefab(parent);

                // if we have pool for this concrete prefab already we use that pool
                // and also make this pool default for this prefab key
                if (pools.TryGetValue(prefab, out pool) == false)
                {
                    pool          = new ViewPool <TView, TData>(parent, prefab);
                    pools[prefab] = pool;
                }
                pools[prefabRef] = pool;

                // TODO implement proper prefab logic here
                if (options.Has(PresentOptions.UseLoadedViews))
                {
                    Rui.FillPoolWithChildrenViews(pool, parent, prefabRef, prefab, options);
                }
                recycleAction.ForEach(a => pool.AddRecycleAction(a));
                if (instantiateAction != null)
                {
                    pool.AddInstantiateAction(instantiateAction);
                }
            }
            return(pool);
        }
Ejemplo n.º 2
0
        ViewPool <TView, TData> Pool(PrefabRef <TView> prefabRef)
        {
            ViewPool <TView, TData> pool;

            if (pools.TryGetValue(prefabRef, out pool) == false)
            {
                var prefab = prefabRef.ExtractPrefab(parent);

                // if we have pool for this concrete prefab already we use that pool
                // and also make this pool default for this prefab key
                if (pools.TryGetValue(prefab, out pool) == false)
                {
                    pool          = new ViewPool <TView, TData>(parent, prefab);
                    pools[prefab] = pool;
                }
                pools[prefabRef] = pool;

                // TODO wft fix this!
                //if (loadViewsFromParent) Rui.FillPoolWithChildrenViews(pool, parent, prefab.GetType());
                recycleAction.ForEach(a => pool.AddRecycleAction(a));
                if (instantiateAction != null)
                {
                    pool.AddInstantiateAction(instantiateAction);
                }
            }
            return(pool);
        }
Ejemplo n.º 3
0
        // Searches prefab in parents children
        public static IViewPool <TView, TData> SimpleViewPool <TView, TData>(this RectTransform parent) where TView : ReusableView
        {
            var views = parent.GetComponentsInChildren <TView>();

            if (views.Length == 0)
            {
                throw new ZergRushException($"cant find {typeof(TView)} in {parent}'s children");
            }

            var prefab = views[0];
            var pool   = new ViewPool <TView, TData>(parent, prefab);

            foreach (var view in views)
            {
                pool.AddViewToUse(prefab, view);
            }
            return(pool);
        }
Ejemplo n.º 4
0
        // Creates everithing except viewport.
        public static TableConnectionsAndComponents <TView, TData> CreateBasicTableComponents <TData, TView>(
            IReactiveCollection <TData> data,
            Transform parent,
            Action <TData, TView> show,
            IViewPool <TView, TData> pool = null,
            PrefabRef <TView> prefab      = default,
            Func <TData, PrefabRef <TView> > prefabSelector = null,
            IScrollViewLayout layout           = null, // Linear layout is default
            TableDelegates <TView> delegates   = null,
            Func <TData, IEventStream> updater = null,
            PresentOptions options             = PresentOptions.None
            ) where TView : ReusableView
        {
            var components = new TableConnectionsAndComponents <TView, TData>();

            if (pool == null)
            {
                if (prefabSelector != null)
                {
                    pool = new DistinctivePool <TView, TData>(parent, prefabSelector, options);
                }
                else
                {
                    var actualPrefab = prefab.ExtractPrefab(parent);
                    pool = new ViewPool <TView, TData>(parent, actualPrefab);
                    if (options.Has(PresentOptions.UseLoadedViews))
                    {
                        FillPoolWithChildrenViews(pool, parent, prefab, actualPrefab, options);
                    }
                }
            }

            if (updater != null)
            {
                var showCopy = show;
                Action <TData, TView> showAndSubscribe = (item, view) =>
                {
                    showCopy(item, view);
                    view.connections += updater(item).Subscribe(() => showCopy(item, view));
                };
                show = showAndSubscribe;
            }
            delegates = delegates ?? new TableDelegates <TView>();
            if (delegates.onInsert != null)
            {
                show += (d, view) =>
                {
                    if (components.animationsEnabled)
                    {
                        delegates.onInsert(view);
                    }
                }
            }
            ;
            if (options.Has(PresentOptions.PreserveSiblingOrder))
            {
                show += (d, view) => { view.tr.SetSiblingIndex(view.indexInModel); };
            }
            components.viewLoader = new LinearViewLoader <TView, TData>(pool, show, delegates.onRemove);
            components.delegates  = delegates;
            components.collection = data;

            if (options.Has(PresentOptions.NeedLayout) && layout == null)
            {
                layout = LinearLayout();
            }
            components.layout = layout;
            return(components);
        }