Ejemplo n.º 1
0
 public void RefreshInfo()
 {
     if (m_EditorCamera != null)
     {
         zoomTextBox.Text = ((int)(m_EditorCamera.GetComponent <Cv_CameraComponent>().Zoom * 100)).ToString() + "%";
     }
 }
Ejemplo n.º 2
0
        public void Initialize(EditorApp app)
        {
            m_EditorApp = app;
            var sceneRoot = m_EditorApp.Logic.GetSceneRoot(m_EditorApp.Logic.GetSceneID("/Root"));

            m_EditorCamera = sceneRoot.GetEntity("/_editorCamera");

            if (m_EditorCamera != null)
            {
                zoomTextBox.Text = ((int)(m_EditorCamera.GetComponent <Cv_CameraComponent>().Zoom * 100)).ToString() + "%";
            }
        }
Ejemplo n.º 3
0
        protected override Cv_EntityComponent[] ModifyEntity(Cv_Entity entity, XmlNodeList overrides)
        {
            var components = new List <Cv_EntityComponent>();

            foreach (XmlElement componentNode in overrides)
            {
                var componentID = Cv_EntityComponent.GetID(componentNode.Name);
                var component   = entity.GetComponent(componentID);

                if (component != null)
                {
                    component.VInitialize(componentNode);
                    component.VOnChanged();
                    components.Add(component);
                }
                else
                {
                    component = CreateComponent(componentNode);
                    if (component != null)
                    {
                        if (component is GameComponent)
                        {
                            entity.AddComponent(((GameComponent)component).ComponentName, component);
                        }
                        else
                        {
                            entity.AddComponent(component.GetType().Name, component);
                        }

                        components.Add(component);
                        //component.VPostInitialize();
                    }
                }
            }

            return(components.ToArray());
        }
Ejemplo n.º 4
0
        protected override void VGameOnUpdate(float time, float timeElapsed)
        {
            var cam = GetEntity(EditorView.EditorCamera);

            if (cam == null)
            {
                return;
            }

            var camTransf   = cam.GetComponent <Cv_TransformComponent>();
            var camSettings = cam.GetComponent <Cv_CameraComponent>();

            var mouseState    = Mouse.GetState();
            var keyboardState = Keyboard.GetState();
            var editorApp     = ((EditorApp)Caravel);
            var mousePos      = Cv_InputManager.Instance.GetMouseValues().MousePos;
            var mouseScroll   = Cv_InputManager.Instance.GetMouseValues().MouseWheelVal;

            //MOUSE ACTIONS
            if (Cv_InputManager.Instance.CommandActive("mouseLeftClick", Cv_Player.One))
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EWindow != null &&
                        editorApp.EWindow.Focused &&
                        editorApp.EWindow.EditorForm.CanSelectEntities &&
                        mousePos.X > 0 && mousePos.Y > 0)
                    {
                        Cv_EntityID[] entities;
                        EditorView.Pick(mousePos, out entities);

                        if (Cv_InputManager.Instance.CommandActivated("mouseLeftClick", Cv_Player.One))
                        {
                            if (!Cv_InputManager.Instance.CommandActive("alternateMode", Cv_Player.One))
                            {
                                if (entities.Length > 0)
                                {
                                    if (entities[0] != editorApp.EForm.CurrentEntity)
                                    {
                                        editorApp.EForm.SetSelectedEntity(entities[0]);
                                    }

                                    if (!m_bMovingEntity)
                                    {
                                        m_EntityBeingMoved = GetEntity(editorApp.EForm.CurrentEntity);
                                    }
                                }
                                else
                                {
                                    var timer = new Cv_TimerProcess(100, DeselectEntity);
                                    Caravel.ProcessManager.AttachProcess(timer);
                                }
                            }
                            else if (editorApp.EForm.CurrentEntity != Cv_EntityID.INVALID_ENTITY)
                            {
                                if (!m_bMovingEntity)
                                {
                                    m_EntityBeingMoved = GetEntity(editorApp.EForm.CurrentEntity);
                                }
                            }
                        }

                        if (Cv_InputManager.Instance.CommandActive("mouseMove", Cv_Player.One) && m_EntityBeingMoved != null)
                        {
                            m_bMovingEntity = true;
                            var trasnfComp = m_EntityBeingMoved.GetComponent <Cv_TransformComponent>();

                            if (trasnfComp == null)
                            {
                                m_bMovingEntity    = false;
                                m_EntityBeingMoved = null;
                            }
                            else
                            {
                                var delta       = m_DeltaBuffer + (mousePos - m_PrevMousePos);
                                var deltaXscale = delta / (float)EditorView.EditorRenderer.Scale;
                                var entityDelta = deltaXscale / camSettings.Zoom;

                                var numStepsX = ((int)entityDelta.X) / EntityDragStepX;
                                var numStepsY = ((int)entityDelta.Y) / EntityDragStepY;

                                var finalDelta = new Vector3(numStepsX * EntityDragStepX, numStepsY * EntityDragStepY, 0);


                                m_DeltaBuffer = delta;
                                if (finalDelta != Vector3.Zero)
                                {
                                    trasnfComp.SetPosition(trasnfComp.Position + finalDelta);

                                    if (finalDelta.X != 0)
                                    {
                                        m_DeltaBuffer = new Vector2(0, m_DeltaBuffer.Y);
                                    }

                                    if (finalDelta.Y != 0)
                                    {
                                        m_DeltaBuffer = new Vector2(m_DeltaBuffer.X, 0);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (editorApp.Mode == EditorApp.EditorMode.CAMERA &&
                         editorApp.EWindow != null &&
                         editorApp.EWindow.Focused && m_PrevMousePos.X != -1)
                {
                    var delta = m_PrevMousePos - mousePos;

                    camTransf.SetPosition(camTransf.Position + new Vector3(delta, 0) / (camSettings.Zoom * (float)EditorView.EditorRenderer.Scale));
                }
                else if (editorApp.Mode == EditorApp.EditorMode.CREATE)
                {
                    if (Cv_InputManager.Instance.CommandActivated("mouseLeftClick", Cv_Player.One))
                    {
                        var timer = new Cv_TimerProcess(100, PaintEntity);
                        Caravel.ProcessManager.AttachProcess(timer);
                    }
                }
            }
            else
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (m_bMovingEntity)
                    {
                        m_bMovingEntity    = false;
                        m_EntityBeingMoved = null;
                        m_DeltaBuffer      = Vector2.Zero;
                        editorApp.EForm.UpdateEntityXml();
                    }
                }
            }

            if (Cv_InputManager.Instance.CommandActive("mouseWheelUp", Cv_Player.One) || Cv_InputManager.Instance.CommandActive("mouseWheelDown", Cv_Player.One))
            {
                m_iIdleTime = 0;
                var delta = mouseScroll - m_iPreviousScrollValue;

                if (editorApp.Mode == EditorApp.EditorMode.CAMERA)
                {
                    camSettings.Zoom += delta / 3000f;
                    editorApp.EForm.UpdateTools();
                }
                else if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EWindow != null &&
                        editorApp.EWindow.Focused &&
                        editorApp.EWindow.EditorForm.CanSelectEntities)
                    {
                        var entity = GetEntity(editorApp.EForm.CurrentEntity);

                        if (entity != null)
                        {
                            var trasnfComp = entity.GetComponent <Cv_TransformComponent>();

                            if (trasnfComp != null)
                            {
                                m_bRotatingEntity = true;
                                trasnfComp.SetRotation(trasnfComp.Rotation + delta / 3000f);
                            }
                        }
                    }
                }
            }
            else if (m_bRotatingEntity)
            {
                if (m_iIdleTime > 1000)
                {
                    m_bRotatingEntity = false;
                    editorApp.EForm.UpdateEntityXml();
                    m_iIdleTime = 0;
                }
                else
                {
                    m_iIdleTime += (int)(timeElapsed);
                }
            }

            //SAVE SHORTCUT
            if (Cv_InputManager.Instance.CommandActive("alternateMode", Cv_Player.One) && Cv_InputManager.Instance.CommandDeactivated("save", Cv_Player.One))
            {
                if (editorApp.EForm.CurrentSceneFile != null && editorApp.EForm.CurrentSceneFile != "")
                {
                    editorApp.EForm.SaveScene();
                }
            }


            //MOVE ENTITIES WITH ARROWS
            if (Cv_InputManager.Instance.CommandActivated("Left", Cv_Player.One))
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EForm.CurrentEntity != Cv_EntityID.INVALID_ENTITY)
                    {
                        var e = GetEntity(editorApp.EForm.CurrentEntity);

                        if (e != null && e.GetComponent <Cv_TransformComponent>() != null)
                        {
                            var pos = e.GetComponent <Cv_TransformComponent>().Position;

                            e.GetComponent <Cv_TransformComponent>().SetPosition(new Vector3(pos.X - 1, pos.Y, pos.Z));
                        }
                    }
                }
            }

            if (Cv_InputManager.Instance.CommandActivated("Right", Cv_Player.One))
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EForm.CurrentEntity != Cv_EntityID.INVALID_ENTITY)
                    {
                        var e = GetEntity(editorApp.EForm.CurrentEntity);

                        if (e != null && e.GetComponent <Cv_TransformComponent>() != null)
                        {
                            var pos = e.GetComponent <Cv_TransformComponent>().Position;

                            e.GetComponent <Cv_TransformComponent>().SetPosition(new Vector3(pos.X + 1, pos.Y, pos.Z));
                        }
                    }
                }
            }

            if (Cv_InputManager.Instance.CommandActivated("Up", Cv_Player.One))
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EForm.CurrentEntity != Cv_EntityID.INVALID_ENTITY)
                    {
                        var e = GetEntity(editorApp.EForm.CurrentEntity);

                        if (e != null && e.GetComponent <Cv_TransformComponent>() != null)
                        {
                            var pos = e.GetComponent <Cv_TransformComponent>().Position;

                            e.GetComponent <Cv_TransformComponent>().SetPosition(new Vector3(pos.X, pos.Y - 1, pos.Z));
                        }
                    }
                }
            }

            if (Cv_InputManager.Instance.CommandActivated("Down", Cv_Player.One))
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EForm.CurrentEntity != Cv_EntityID.INVALID_ENTITY)
                    {
                        var e = GetEntity(editorApp.EForm.CurrentEntity);

                        if (e != null && e.GetComponent <Cv_TransformComponent>() != null)
                        {
                            var pos = e.GetComponent <Cv_TransformComponent>().Position;

                            e.GetComponent <Cv_TransformComponent>().SetPosition(new Vector3(pos.X, pos.Y + 1, pos.Z));
                        }
                    }
                }
            }

            //DELETE KEY
            if (Cv_InputManager.Instance.CommandActivated("Delete", Cv_Player.One))
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EForm.CurrentEntity != Cv_EntityID.INVALID_ENTITY)
                    {
                        editorApp.EForm.RemoveEntityFromEditor(editorApp.EForm.CurrentEntity);
                        editorApp.EForm.SetSelectedEntity(Cv_EntityID.INVALID_ENTITY);
                    }
                }
            }

            m_PrevMousePos         = mousePos;
            m_iPreviousScrollValue = mouseScroll;
        }
Ejemplo n.º 5
0
        internal Cv_Entity InstantiateNewEntity(bool isSceneRoot, string entityTypeResource, string name, string resourceBundle,
                                                bool visible, Cv_EntityID parentID, XmlElement overrides,
                                                Cv_Transform?transform, Cv_SceneID sceneID, Cv_EntityID serverEntityID)
        {
            if (!CanCreateEntity(name, serverEntityID))
            {
                return(null);
            }

            var scene     = sceneID == Cv_SceneID.INVALID_SCENE ? m_SceneManager.MainScene : sceneID;
            var sceneName = m_SceneManager.GetSceneName(scene);

            Cv_Debug.Assert(sceneName != null, "Trying to add an entity to an invalid scene [" + scene + ", " + name + "]");

            var path = "/" + name;

            if (isSceneRoot) //Scene roots are named after the scene id
            {
                path = "/" + sceneName;
                name = sceneName;
            }

            if (parentID == Cv_EntityID.INVALID_ENTITY)
            {
                if (!isSceneRoot)
                {
                    var sceneRoot = m_SceneManager.GetSceneRoot(scene);
                    path = sceneRoot.EntityPath + path;
                    Cv_Debug.Assert(sceneRoot != null, "Trying to add an entity to an invalid scene [" + scene + ", " + name + "]");
                    parentID = sceneRoot.ID;
                }
            }
            else
            {
                var parent = GetEntity(parentID);
                if (parent == null)
                {
                    Cv_Debug.Warning("Attempting to add an entity to a parent that doesn't exist.");
                    return(null);
                }

                if (parent.SceneID != scene && !isSceneRoot)
                {
                    scene     = parent.SceneID;
                    sceneName = parent.SceneName;

                    Cv_Debug.Warning("Attempting to add an entity of a scene to a parent that is not of the same scene [" + scene + ", " + name + "]. Adding to parent scene instead.");
                }

                path = parent.EntityPath + path;
            }

            Cv_Debug.Assert(!EntitiesByPath.ContainsKey(path), "All entities with the same parent must have a unique ID. Trying to add repeated entity [" + scene + ", " + name + "]");

            Cv_Entity entity = null;

            if (entityTypeResource != null)
            {
                entity = m_EntityFactory.CreateEntity(entityTypeResource, parentID, serverEntityID, resourceBundle, scene, sceneName);
            }
            else
            {
                entity = m_EntityFactory.CreateEmptyEntity(parentID, serverEntityID, resourceBundle, scene, sceneName);
            }

            if (entity != null)
            {
                entity.EntityName = name;
                entity.EntityPath = path;
                entity.Visible    = visible;
                entity.SceneRoot  = isSceneRoot;
                m_EntitiesToAdd.Enqueue(entity);

                lock (Entities)
                {
                    Entities.Add(entity.ID, entity);
                    EntitiesByPath.Add(entity.EntityPath, entity);
                }

                if (overrides != null)
                {
                    m_EntityFactory.ModifyEntity(entity, overrides.SelectNodes("./*[not(self::Entity|self::Scene)]"));
                }

                var tranformComponent = entity.GetComponent <Cv_TransformComponent>();
                if (tranformComponent != null && transform != null)
                {
                    tranformComponent.Transform = transform.Value;
                }

                LastEntityID = entity.ID;

                entity.PostInitialize();

                if (!IsProxy && State == Cv_GameState.Running)
                {
                    var requestNewEntityEvent = new Cv_Event_RequestNewEntity(null, scene, sceneName, entity.EntityName, resourceBundle, visible, parentID, transform, entity.ID);
                    Cv_EventManager.Instance.TriggerEvent(requestNewEntityEvent);
                }

                var newEntityEvent = new Cv_Event_NewEntity(entity.ID, this);
                Cv_EventManager.Instance.TriggerEvent(newEntityEvent);

                return(entity);
            }

            Cv_Debug.Error("Could not create entity with resource [" + resourceBundle + "].");
            return(null);
        }