Beispiel #1
0
        private void MarkComponentInInspector(SEntityComponentId componentId, bool bMark)
        {
            bool bMarkEverything = componentId == SEntityComponentId.Invalid;

            void Mark(CInspectorSceneComponentViewModel sceneVm)
            {
                if (sceneVm.ComponentId == componentId || bMarkEverything)
                {
                    sceneVm.SetViewModelMarked(bMark);
                }

                foreach (var child in sceneVm.Children)
                {
                    Mark(child);
                }
            }

            if (SceneComponents.Count > 0)
            {
                Mark(SceneComponents[0]);
            }

            foreach (var entComp in EntityComponents)
            {
                if (entComp.ComponentId == componentId || bMarkEverything)
                {
                    entComp.SetViewModelMarked(bMark);
                }
            }
        }
Beispiel #2
0
        public static void DetachEntityFromAllParents(SEntityId entityId)
        {
            CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
            {
                CEntity target = entityId.GetEntity();
                if (target == null || target.RootComponent == null || target.RootComponent.ParentComponent == null)
                {
                    return;
                }

                SEntityComponentId oldRootParent = new SEntityComponentId(target.RootComponent.ParentComponent);

                void Do()
                {
                    CWorld world   = CEngine.Instance.CurrentWorld;
                    CEntity entity = entityId.GetEntity();

                    if (entity != null)
                    {
                        entity.Detach();
                    }
                }

                void Undo()
                {
                    CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                    {
                        CWorld world              = CEngine.Instance.CurrentWorld;
                        CEntity entity            = entityId.GetEntity();
                        CSceneComponent oldParent = oldRootParent.GetComponent <CSceneComponent>();

                        if (oldParent == null)
                        {
                            LogUtility.Log("[UndoRedo] The old parent is invalid! Undo stack has been corrupted and cleared.");
                            UndoRedoUtility.Purge(null);
                            return;
                        }

                        if (entity != null)
                        {
                            entity.AttachToComponent(oldParent);
                        }
                    });
                }

                void Redo()
                {
                    CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                    {
                        Do();
                    });
                }

                Do();

                CRelayUndoItem item = new CRelayUndoItem(Undo, Redo);
                UndoRedoUtility.Record(item);
            });
        }
Beispiel #3
0
        public static void PickComponent(SEntityComponentId id)
        {
            CWorldOutlinerViewModel worldOutliner = CWorkspace.Instance.GetTool <CWorldOutlinerViewModel>();

            if (worldOutliner != null)
            {
                CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                {
                    worldOutliner.PickingComponentId.GetComponent <CScenePickingComponent>()?.Pick(id.GetComponent <CSceneComponent>());
                });
            }
        }
Beispiel #4
0
        public CInspectorEntityComponentViewModel(IInspectorViewModel viewModel, string name, SEntityComponentId componentId)
            : base(viewModel, name)
        {
            ComponentId = componentId;

            DeleteComponentCommand = new CRelayCommand(arg =>
            {
                EditorEntityUtility.DestroyComponent(ComponentId);

                m_viewModel.QueueEntityInformationUpdate(ComponentId.EntityId, true);
            });
        }
Beispiel #5
0
        public void AttachComponent(SEntityComponentId child, SEntityComponentId parent)
        {
            CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
            {
                CSceneComponent parentObj = parent.GetComponent <CSceneComponent>();
                CSceneComponent childObj  = child.GetComponent <CSceneComponent>();

                if (parentObj != null && childObj != null)
                {
                    CSceneComponent oldParent      = childObj.ParentComponent;
                    SEntityComponentId oldParentid = new SEntityComponentId(oldParent);

                    if (childObj.AttachToComponent(parentObj))
                    {
                        UpdateEntityInformation_EngineThread(m_selectedObject.GetTargetEntityId(), true);

                        void Undo()
                        {
                            CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                            {
                                CSceneComponent oldParentInst = oldParentid.GetComponent <CSceneComponent>();
                                CSceneComponent childInst     = child.GetComponent <CSceneComponent>();

                                if (oldParentInst != null && childInst != null)
                                {
                                    childInst.AttachToComponent(oldParentInst);
                                    UpdateEntityInformation_EngineThread(child.EntityId, true);
                                }
                            });
                        }

                        void Redo()
                        {
                            CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                            {
                                CSceneComponent newParentInst = parent.GetComponent <CSceneComponent>();
                                CSceneComponent childInst     = child.GetComponent <CSceneComponent>();

                                if (newParentInst != null && childInst != null)
                                {
                                    childInst.AttachToComponent(newParentInst);
                                    UpdateEntityInformation_EngineThread(child.EntityId, true);
                                }
                            });
                        }

                        CRelayUndoItem item = new CRelayUndoItem(Undo, Redo);
                        UndoRedoUtility.Record(item);
                    }
                }
            });
        }
Beispiel #6
0
        public CInspectorSceneComponentViewModel(IInspectorViewModel viewModel, string name, SEntityComponentId componentId, string dragIdentifier)
            : base(viewModel, name)
        {
            ComponentId = componentId;

            MakeRootCommand        = new CRelayCommand(OnMakeRoot);
            DeleteComponentCommand = new CRelayCommand(OnDeleteComponent);
            DragEnterCommand       = new CRelayCommand(OnDragEnter);
            DragOverCommand        = new CRelayCommand(OnDragOver);
            DropCommand            = new CRelayCommand(OnDrop);

            m_dragIdentifier = dragIdentifier;
        }
Beispiel #7
0
        private void InspectComponent(SEntityComponentId componentId)
        {
            bool bUpdateInspectorObjectList = ShouldUpdateInspectorList(componentId);

            CEngine engine = CEngine.Instance;
            CWorldOutlinerViewModel worldOutliner = CWorkspace.Instance.GetTool <CWorldOutlinerViewModel>();

            engine.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
            {
                CUpdateScheduler scheduler = engine.CurrentWorld.UpdateScheduler;
                if (m_updateScope != null && m_updateScope.IsConnected())
                {
                    scheduler.Disconnect(m_updateScope);
                }

                CEntityComponent component = componentId.GetComponent();
                if (component != null)
                {
                    m_selectedObject = new CEditableObject(componentId);
                    m_updateScope    = scheduler.Connect(UpdateCallback, EUpdatePriority.ResourceLoading);

                    if (bUpdateInspectorObjectList)
                    {
                        UpdateEntityInformation_EngineThread(new SEntityId(component.Owner.Id));
                    }

                    worldOutliner.PickingComponentId.GetComponent <CScenePickingComponent>().Pick(component as CSceneComponent);

                    Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() =>
                    {
                        m_desiredTarget = new CEditableObject(componentId);
                        UnmarkEverything();
                        MarkComponentInInspector(componentId, true);
                    }));
                }
                else
                {
                    Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() =>
                    {
                        m_desiredTarget = null;
                        UnmarkEverything();
                    }));
                }
            });
        }
Beispiel #8
0
        public static void DestroyComponent(SEntityComponentId id)
        {
            if (id.OverrideComponent == null)
            {
                CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                {
                    CEntityComponent component = id.GetComponent <CEntityComponent>();
                    if (component != null)
                    {
                        component.Destroy();
                    }
                });
            }
            else
            {
                CEntityComponent component = id.GetComponent <CEntityComponent>();
                if (component != null)
                {
                    component.Destroy();
                }
            }

            UndoRedoUtility.Purge(null);
        }
Beispiel #9
0
        private bool ShouldUpdateInspectorList(SEntityComponentId inspectedComponent)
        {
            if (m_desiredTarget == null)
            {
                return(true);
            }

            if (inspectedComponent == m_desiredTarget.ComponentId)
            {
                return(true);
            }

            if (m_desiredTarget.EntityId == inspectedComponent.EntityId)
            {
                return(false);
            }

            if (m_desiredTarget.ComponentId.EntityId == inspectedComponent.EntityId)
            {
                return(false);
            }

            return(true);
        }
        public override void PostWorldLoad()
        {
            base.PostWorldLoad();

            CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
            {
                Action <CEntity> callback = (entity) =>
                {
                    CHierarchyEntry root = EditorHelpers.FillLevelHierarchy();
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        UpdateOutliner(root);
                    });
                };

                Action <CAssetReference <CLevelAsset>, CLevel> levelChanged = (levelAsset, level) =>
                {
                    CHierarchyEntry root           = EditorHelpers.FillLevelHierarchy();
                    SEntityComponentId newPickerId = SpawnScenePicker_EngineThread(CEngine.Instance.CurrentWorld);
                    CWorkspace.Instance.PostLevelLoad(levelAsset);
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        PickingComponentId = newPickerId;
                        UpdateOutliner(root);
                    });
                };

                CWorld currentWorld              = CEngine.Instance.CurrentWorld;
                currentWorld.OnEntitySpawned    += callback;
                currentWorld.OnEntityDestroyed  += callback;
                currentWorld.OnEntityRevived    += callback;
                currentWorld.OnLevelChanged     += levelChanged;
                currentWorld.OnHierarchyChanged += (child, oldParent, newParent) =>
                {
                    if (child == child.Owner?.RootComponent)
                    {
                        callback(null);
                    }
                };
                SEntityComponentId pickerId = SpawnScenePicker_EngineThread(currentWorld);
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { PickingComponentId = pickerId; }));

                CScenePickingComponent.OnComponentPicked += (component) =>
                {
                    if (component == null)
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            CWorkspace.Instance.SetSelectedObject(null);
                        });
                    }
                    else
                    {
                        CEntity entity          = component.Owner;
                        CEditableObject editObj = null;

                        if (entity.RootComponent == null)
                        {
                            editObj = new CEditableObject(new SEntityId(entity.Id));
                        }
                        else
                        {
                            editObj = new CEditableObject(new SEntityComponentId(entity.RootComponent));
                        }

                        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                        {
                            CWorkspace.Instance.SetSelectedObject(editObj);
                        }));
                    }
                };

                callback(null);
            });
        }
Beispiel #11
0
        public static void MakeComponentRoot(SEntityComponentId id, bool bDispatch = true)
        {
            void Command()
            {
                CSceneComponent newRoot = id.GetComponent <CSceneComponent>();

                if (newRoot == null)
                {
                    return;
                }

                CSceneComponent oldRoot = newRoot.Owner.RootComponent;

                if (oldRoot == null)
                {
                    return;
                }

                SEntityComponentId oldId = new SEntityComponentId(oldRoot);

                void Do()
                {
                    CSceneComponent component = id.GetComponent <CSceneComponent>();

                    if (component != null)
                    {
                        CEntity owner = component.Owner;
                        owner.SetRootComponent(component);
                    }
                }

                void Redo()
                {
                    CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                    {
                        Do();

                        Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() =>
                        {
                            CWorkspace space = CWorkspace.Instance;
                            space.SetSelectedObject(space.SelectedEditableObject, true);
                        }));
                    });
                }

                void Undo()
                {
                    CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                    {
                        CSceneComponent component = oldId.GetComponent <CSceneComponent>();

                        if (component != null)
                        {
                            CEntity owner = component.Owner;
                            owner.SetRootComponent(component);

                            Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() =>
                            {
                                CWorkspace space = CWorkspace.Instance;
                                space.SetSelectedObject(space.SelectedEditableObject, true);
                            }));
                        }
                    });
                }

                Do();

                CUndoItem item = new CRelayUndoItem(Undo, Redo);

                UndoRedoUtility.Record(item);
            }

            if (bDispatch)
            {
                CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                {
                    Command();
                });
            }
            else
            {
                Command();
            }
        }
Beispiel #12
0
 public CEditableObject(SEntityComponentId componentId)
 {
     m_componentId = componentId;
     Type          = EObjectType.Component;
 }
Beispiel #13
0
        private void UpdateEntityInformation_EngineThread(SEntityId entityId, bool bReselectTarget = false)
        {
            void CreateViewModel(CSceneComponent component, CInspectorSceneComponentViewModel parent, CEntity owner)
            {
                if (component.Owner != owner || !component.ShowInInspector || component.MarkedForDestruction)
                {
                    return;
                }

                SEntityComponentId id = new SEntityComponentId(component, false);

                CInspectorSceneComponentViewModel vm = new CInspectorSceneComponentViewModel(this, component.Name, id, "sceneComponent");

                parent.Children.Add(vm);

                foreach (var child in component.Children)
                {
                    CreateViewModel(child, vm, owner);
                }
            }

            CEntity entity = entityId.GetEntity();

            if (entity != null)
            {
                CInspectorEntityViewModel                 entityInfo           = null;
                CInspectorSceneComponentViewModel         sceneComponentsInfo  = null;
                List <CInspectorEntityComponentViewModel> entityComponentsInfo = null;

                sceneComponentsInfo = null;
                if (entity.RootComponent != null)
                {
                    sceneComponentsInfo = new CInspectorSceneComponentViewModel(this, entity.RootComponent.Name, new SEntityComponentId(entity.RootComponent, false), "sceneComponent");
                    foreach (var child in entity.RootComponent.Children)
                    {
                        CreateViewModel(child, sceneComponentsInfo, entity);
                    }
                }

                List <CEntityComponent> components = new List <CEntityComponent>(8);
                entityComponentsInfo = new List <CInspectorEntityComponentViewModel>(4);
                entity.GetComponents(components);

                for (int i = components.Count - 1; i >= 0; i--)
                {
                    if (!(components[i] is CSceneComponent) && components[i].ShowInInspector && !components[i].MarkedForDestruction)
                    {
                        entityComponentsInfo.Add(new CInspectorEntityComponentViewModel(this, components[i].Name, new SEntityComponentId(components[i], false)));
                    }
                }

                entityInfo = new CInspectorEntityViewModel(this, entity.Name, new SEntityId(entity.Id));

                string entityName = entity.Name;

                Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() =>
                {
                    m_view?.LockInspector(false);
                    UpdateEntityInformation_EditorThread(sceneComponentsInfo, entityComponentsInfo, entityInfo);

                    m_entityName = entityName;
                    RaisePropertyChanged(nameof(EntityName));
                    m_view.SetEntityName(entityName);

                    if (bReselectTarget)
                    {
                        CWorkspace.Instance.SetSelectedObject(m_selectedObject, true);
                    }
                }));
            }
            else
            {
                //Clear component list when selecting invalid entity
                Application.Current.Dispatcher.BeginInvoke((Action)(() =>
                {
                    UpdateEntityInformation_EditorThread(null, null, null);
                }));
            }
        }