示例#1
0
        internal static void Process(List <Node> nodes)
        {
            if (nodes.Count == 0)
            {
                return;
            }

            //Debug.Log(string.Format("Processing {0} top level removals in edit mode.", nodes.Count));

            foreach (Node node in nodes)
            {
                if (null == node.ParentTransform)
                {
                    continue;
                }

                GroupAdapter parentGroupAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter;
                if (null != parentGroupAdapter)
                {
                    /**
                     * Important: the removal could happen when we *move* components outside of the Stage hierarchy
                     * From group's standpoint, these components have been *removed*
                     * However, the adapters are not null, so the consolidation without a prior
                     * removal would do nothing to the parent collection (e.g. the moved adapter
                     * would still be on the list)
                     * */
                    parentGroupAdapter.RemoveChild(node.Adapter);

                    ChildGroupPack pack = ChildGroupPack.Read(parentGroupAdapter);
                    pack.Consolidate(); // there is a null slot here. We have to re-render children
                }
            }
        }
示例#2
0
// ReSharper restore UnassignedField.Global
#endif

        internal static void Process(List <Node> removals)
        {
            if (0 == removals.Count)
            {
                return;
            }

#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format("Processing {0} removals.", removals.Count));
            }
#endif
            //Debug.Log(string.Format("Processing {0} removals.", removals.Count));
            // TODO: do removals bottom up! nesting level should be used here

            foreach (Node node in removals)
            {
                //if (null == node.Transform)
                //    continue; // ROOT

                node.RemoveFromHierarchy();

                //Debug.Log("node.ParentTransform: " + node.ParentTransform);
                if (null == node.ParentTransform) //|| /*!*/(adapter is StageAdapter))
                {
                    continue;                     // not a stage, return (if stage, should process)
                }
                // consolidate parent transform

                ComponentAdapter adapter = node.Adapter;

                GroupAdapter parentGroupAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter;
                if (null != parentGroupAdapter)
                {
                    /**
                     * Stop monitoring
                     * */
                    PersistenceManager.Instance.Unwatch(node.AdapterId);

                    //PersistenceManager.Instance.RemoveAdapter(node.AdapterId);

                    /**
                     * Note: if object removed from the hierarchy, the adapter is destroyed
                     * In that case following command doesn nothing (doesn not remove the slot from the parent)
                     * Thus we have the consolidation below (removing null)
                     * */
                    parentGroupAdapter.RemoveChild(adapter);

                    // TODO: consolidate only for top level removals (add parameter)

                    /*parentContainerAdapter.RemoveChild(adapter);*/
                    //parentContainerAdapter.RemoveAllChildren();
                    ChildGroupPack pack = ChildGroupPack.Read(parentGroupAdapter);
                    pack.Consolidate(); // there is a null slot here. We have to re-render children
                    //Debug.Log("*pack: " + pack);
                    parentGroupAdapter.InstantiateChildren(true);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Checks the flags and executes the change received via the slots
        /// (the change that is not healthy to do inside the Render method)
        /// </summary>
        public override void Update()
        {
            if (null != _positionChangedParms)
            {
                //Debug.Log(string.Format("PositionChangedSlot: {0}, {1}", parameters[0], parameters[1]));
                DraggableItem draggableItem = (DraggableItem)_positionChangedParms[0];
                int           newItemIndex  = (int)_positionChangedParms[1];
                int           newGroupIndex = (int)_positionChangedParms[2];

                _positionChangedParms = null;

                ComponentAdapter adapter = (ComponentAdapter)draggableItem.Data;

                // Note: this actually applies changes to collections
                var pack = _groupManager.Reorder(adapter, newGroupIndex, newItemIndex);

                ParentChildLinker.Instance.Update(GroupAdapter, pack);

                //Refresh();

                if (Application.isPlaying)
                {
                    //ParentChildLinker.Instance.Update(ContainerAdapter, pack); // TODO: calling ParentChildLinker from here messes the thing
                    RedrawComponentsInGameView(pack);
                }

                //HierarchyState.Instance.Rebuild();
                EditorState.Instance.HierarchyChange();

                /**
                 * Emit for debugging purposes
                 * */
                CollectionChangedSignal.Emit();
            }

            else if (null != _removedParms)
            {
                //Debug.Log(string.Format("RemovedSlot: {0}", parameters[0]));
                DraggableItem draggableItem = (DraggableItem)_removedParms[0];
                //int groupIndex = (int)_removedParms[1];
                //int itemIndex = (int)_removedParms[2];

                _removedParms = null;

                ComponentAdapter adapter = draggableItem.Data as ComponentAdapter;

                if (null == adapter)
                {
                    return;
                }

                //Debug.Log(string.Format("groupIndex: {0}, itemIndex: {1}", groupIndex, itemIndex));

                /**
                 * 1. Remove the adapter from the collection
                 * */
                var pack = _groupManager.Remove(adapter);

                /**
                 * NOTE: We should not call the linker directly
                 * That is because if we remove adapter from stage, the linker could not find it
                 * We call the EditorState.Instance.HierarchyChange() below, so the
                 * hierarchy change mechanism handles the removal stuff
                 * */
                //ParentChildLinker.Instance.Update(GroupAdapter, pack);

                if (Application.isPlaying)
                {
                    RedrawComponentsInGameView(pack);
                }

                if (adapter.transform.parent != GroupAdapter.transform)
                {
                    return;
                }

                //Refresh();

                /**
                 * 2. Check if the same adapter present in other collections
                 * If not, remove the transform
                 * */
                var group = _groupManager.GetGroupContainingAdapter(adapter);
                //Debug.Log("group: " + group);
                if (null == group)
                {
                    // this adapter is not present in any of the groups
                    // remove the transform now
                    OrderDisplayRow orderDisplayRow = (OrderDisplayRow)draggableItem;

                    Transform    transform    = orderDisplayRow.Adapter.transform;
                    GroupAdapter groupAdapter = transform.parent.GetComponent <GroupAdapter>();
                    groupAdapter.RemoveChild(orderDisplayRow.Adapter);

                    //int instanceId = transform.GetInstanceID();
                    Object.DestroyImmediate(transform.gameObject);
                }

                // apply the change, for not to get the "ArgumentException: Getting control 3's position in a group with only 3 controls when doing Repaint Aborting" error
                Refresh();

                //EditorState.Instance.HierarchyChange();

                /**
                 * Emit for debugging purposes
                 * */
                CollectionChangedSignal.Emit();
            }

            if (null != _depthChangedParms)
            {
                //Debug.Log("OrderDisplay: changing depth");
                // apply the change, for not to get the "ArgumentException: Getting control 3's position in a group with only 3 controls when doing Repaint Aborting" error
                //Refresh();

                _depthChangedParms = null;
            }
        }
示例#4
0
        internal static void Process(List <Node> nodes)
        {
            if (nodes.Count == 0)
            {
                return;
            }

            //Debug.Log(string.Format("Processing {0} moves in edit mode.", nodes.Count));

            foreach (Node node in nodes)
            {
                /**
                 * 1. Process transforms
                 * */
                Transform transform = node.Transform;
                if (null == node.Transform)
                {
                    throw new Exception("Transform is null");
                }

                /*if (null == transform)
                 *  continue; // ROOT*/

                //Debug.Log("node.Transform: " + transform);

                ComponentAdapter adapter = GuiLookup.GetAdapter(transform);
                bool             isStage = adapter is StageAdapter;

                Transform oldParentTransform = node.OldParentTransform;
                Transform newParentTransform = node.ParentTransform;

                /* This happens when a stage moved to root */
                if (null == newParentTransform && !isStage)
                {
                    continue; // not a stage, return (if stage, should process) - only stage could be added to root
                }

                /**
                 * The adapter was moved
                 * It is still placed on the same (moved) transform
                 * We are accessing the old and the new parent adapter via transforms:
                 * 1. old parent transform could be referenced using the node.OldParentTransform
                 * 2. new parent transform could be referenced using the node.ParentTransform
                 * */
                GroupAdapter oldParentAdapter = null != oldParentTransform?
                                                GuiLookup.GetAdapter(oldParentTransform) as GroupAdapter:
                                                null;

                GroupAdapter newParentAdapter = null != newParentTransform?
                                                GuiLookup.GetAdapter(newParentTransform) as GroupAdapter:
                                                null;

                Debug.Log(string.Format("[{0}] -> moving from [{1}] to [{2}]",
                                        adapter,
                                        null == oldParentAdapter ? "-" : oldParentAdapter.ToString(),
                                        null == newParentAdapter ? "-" : newParentAdapter.ToString()
                                        ));

                /**
                 * 2. Sanity check
                 * */
                if (null == newParentAdapter && !isStage)
                {
                    throw new Exception("eDriven.Gui components could be added to containers only");
                }

                /**
                 * 3. Process adapters
                 * */
                if (null != oldParentAdapter)
                {
                    oldParentAdapter.RemoveChild(adapter);
                    ParentChildLinker.Instance.Update(oldParentAdapter);
                }

                if (null != newParentAdapter)
                {
                    newParentAdapter.AddChild(adapter, true);
                    ParentChildLinker.Instance.Update(newParentAdapter);
                }

                /**
                 * 4. Set transform
                 * */
                node.Transform.parent = newParentTransform;
            }
        }
示例#5
0
// ReSharper restore UnassignedField.Global
#endif

        internal static void Process(List <Node> moves)
        {
#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format("Processing {0} moves.", moves.Count));
            }
#endif

            foreach (Node node in moves)
            {
                /**
                 * 1. Process transforms
                 * */
                Transform transform = node.Transform;

                Transform parentTransform = node.ParentTransform;

                if (null == transform)
                {
                    continue; // ROOT
                }
                //Debug.Log("node.Transform: " + transform);

                ComponentAdapter adapter     = GuiLookup.GetAdapter(transform);
                bool             thisIsStage = adapter is StageAdapter;

                /**
                 * The adapter has been moved
                 * It is still placed on the same (moved) transform
                 * We are accessing the old and the new parent adapter via transforms:
                 * - the old parent transform could be referenced using the node.OldParentTransform
                 * - the new parent transform could be referenced using the node.ParentTransform
                 * */

                if (null == node.Transform)
                {
                    throw new Exception("Transform is null");
                }

                GroupAdapter oldParentAdapter = GuiLookup.GetAdapter(node.OldParentTransform) as GroupAdapter;
                GroupAdapter newParentAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter;

                //Debug.Log(string.Format("  -> moving from [{0}] to [{1}]", oldParentAdapter, newParentAdapter));

                /**
                 * 2. Process adapters
                 * */
                if (null != oldParentAdapter)
                {
                    oldParentAdapter.RemoveChild(adapter);
                    ParentChildLinker.Instance.Update(oldParentAdapter);
                }

                if (null == newParentAdapter)
                {
                    if (!thisIsStage)
                    {
                        const string txt = "eDriven.Gui components could be added to containers only";
                        //Debug.LogWarning(txt);
                        throw new Exception(txt);
                    }
                }
                else
                {
                    newParentAdapter.AddChild(adapter, true);
                    ParentChildLinker.Instance.Update(newParentAdapter);
                }

                /**
                 * 3. If adapter stuff went without a problem...
                 * */
                node.Transform.parent = parentTransform;

                //ComponentAdapter adapter = GuiLookup.GetAdapter(transform);
                //bool thisIsStage = adapter is StageAdapter;

                ////Debug.Log("done.");

                //Transform parentTransform = node.ParentTransform;

                //if (null == parentTransform && !thisIsStage)
                //    continue; // not a stage, return (if stage, should process) - only stage could be added to root

                //ContainerAdapter newParentAdapter = null;

                //if (null != parentTransform)
                //    newParentAdapter = GuiLookup.GetAdapter(parentTransform) as ContainerAdapter;

                //    /**
                //     * 2. Process adapters
                //     * */
                //    if (null != adapter)
                //    {
                //        // this is eDriven.Gui component. process it properly
                //        if (null == newParentAdapter)
                //        {
                //            if (!thisIsStage) {
                //                const string txt = "eDriven.Gui components could be added to containers only";
                //                //Debug.LogWarning(txt);
                //                throw new Exception(txt);
                //                //return;
                //            }
                //        }
                //        else
                //        {
                //            ContainerAdapter oldParentAdapter = node.OldParentTransform.GetComponent<ContainerAdapter>();

                //            //Debug.Log("oldParentAdapter: " + oldParentAdapter);
                //            //Debug.Log("newParentAdapter: " + newParentAdapter);

                //            oldParentAdapter.RemoveChild(adapter);

                //            newParentAdapter.AddChild(adapter, true);

                //            ////if (!PrefabUtil.IsCreatedFromPrefab(oldParentAdapter)) // TODO: Need this?
                //            //    ParentChildLinker.Instance.Update(oldParentAdapter);

                //            ////if (!PrefabUtil.IsCreatedFromPrefab(newParentAdapter)) // TODO: Need this?
                //            //    ParentChildLinker.Instance.Update(newParentAdapter);

                //            if (EditorApplication.isPlaying)
                //            {
                //                if (!adapter.Instantiated)
                //                    adapter.DoInstantiate(true);
                //                //Debug.Log(string.Format("OnHierarchyChange: Component instantiated: {0} [{1}]", adapter.Component, adapter.transform.GetInstanceID()));
                //            }

                //            var cmp = adapter.Component;
                //            if (null == cmp)
                //            {
                //                throw new Exception("Component not found on ComponentAdapter: " + adapter);
                //            }
                //        }
                //    }

                //    /**
                //     * 3. If adapter stuff went without a problem...
                //     * */
                //    node.Transform.parent = parentTransform;
            }
        }