/// <summary>
        ///     Initializes a new instance of this class.
        /// </summary>
        /// <param name="startNode">Starting node of the path to follow.</param>
        /// <param name="entity">Entity to follow the path.</param>
        public PathFollowProcess(PathMarkerNode startNode, EntityNode entity)
        {
            _entity = entity;
            _startNode = startNode;
            _currentNode = startNode;

            AdvanceOneNode();
        }
 /// <summary>
 ///     Initializes a new instance of this class.
 /// </summary>
 public EntityFadeProcess(EntityNode node, int fromColor, int toColor, int duration)
 {
     _entity = node;
     ColorMethods.SplitColor(ColorFormats.A8R8G8B8, fromColor, out _fromColorRed, out _fromColorGreen, out _fromColorBlue, out _fromColorAlpha);
     ColorMethods.SplitColor(ColorFormats.A8R8G8B8, toColor, out _toColorRed, out _toColorGreen, out _toColorBlue, out _toColorAlpha);
     _duration = duration;
     _timer.Restart();
 }
 /// <summary>
 ///     Initializes a new instance of this class.
 /// </summary>
 /// <param name="entity">Entity that will be following.</param>
 /// <param name="targetEntity">Entity that be followed.</param>
 /// <param name="bufferRadius">Buffer radius around target in which no movement is produced.</param>
 /// <param name="speed">Speed at which entity moves.</param>
 public EntityFollowProcess(EntityNode entity, EntityNode targetEntity, float bufferRadius, float speed)
 {
     _priority = 2; // Right at the start, before things start to move :P.
     _entity = entity;
     _targetEntity = targetEntity;
     _bufferZoneRadius = bufferRadius;
     _followSpeed = speed;
 }
        public ScriptExecutionProcess(EntityNode entity)
        {
            _entity = entity;

            _eventListener = new EventListener(ProcessEvent);
            EventManager.AttachListener(_eventListener);

            _priority = 1; // We always want to be executed before other processes.
        }
        public AnimationProcess(EntityNode entity, AnimationMode mode, int frameDelay, int startFrame, int endFrame)
        {
            _entity = entity;
            _mode = mode;
            _frameDelay = frameDelay;

            _frames = new int[(endFrame - startFrame) + 1];
            for (int i = startFrame; i <= endFrame; i++)
                _frames[i - startFrame] = i;
        }
        /// <summary>
        ///     Initializes a new instance of this class.
        /// </summary>
        /// <param name="entity">Entity that will be moving.</param>
        /// <param name="x">X position to move to.</param>
        /// <param name="y">Y position to move to.</param>
        /// <param name="speed">Speed at which entity moves.</param>
        public EntityMoveToProcess(EntityNode entity, float x, float y, StartFinishF speed)
        {
            _entity = entity;
            _followSpeed = speed;
            _x = x;
            _y = y;

            Transformation entityTransform = _entity.CalculateTransformation();
            float vectorX = entityTransform.X - _x;
            float vectorY = entityTransform.Y - _y;
            _originalDistance = (float)Math.Sqrt(vectorX * vectorX + vectorY * vectorY);
        }
        /// <summary>
        ///		Loads the next node in the given binary reader and returns it.
        /// </summary>
        /// <param name="reader">Binary reader to read node from.</param>
        /// <param name="getProgress">If set to true this node is used to judge the current progress.</param>
        /// <returns>Scene node that was loaded from the binary reader.</returns>
        private SceneNode LoadNode(BinaryReader reader, bool getProgress)
        {
            // Read in the name of this node's class.
            string name = reader.ReadString();

            //HighPreformanceTimer timer = new HighPreformanceTimer();

            // Create a new instance of this entity and tell it to load itself.
            // (See if its a known object first as its quicker to get it without reflection)
            SceneNode node = null;
            if (name.ToLower().EndsWith("binaryphoenix.fusion.engine.entitys.entitynode"))
                node = new EntityNode();
            else if (name.ToLower().EndsWith("binaryphoenix.fusion.engine.entitys.scriptedentitynode"))
                node = new ScriptedEntityNode();
            else if (name.ToLower().EndsWith("binaryphoenix.fusion.engine.scenenode"))
                node = new SceneNode();
            else if (name.ToLower().EndsWith("binaryphoenix.fusion.engine.entitys.groupnode"))
                node = new GroupNode();
            else if (name.ToLower().EndsWith("binaryphoenix.fusion.engine.entitys.emitternode"))
                node = new EmitterNode();
            else if (name.ToLower().EndsWith("binaryphoenix.fusion.engine.entitys.tilemapsegmentnode"))
                node = new TilemapSegmentNode();
            else if (name.ToLower().EndsWith("binaryphoenix.fusion.engine.entitys.pathmarkernode"))
                node = new PathMarkerNode();
            else if (name.ToLower().EndsWith("binaryphoenix.fusion.engine.entitys.tilenode"))
                node = new TileNode();
            else
                node = (SceneNode)ReflectionMethods.CreateObject(name);

            //DebugLogger.WriteLog("Created scene graph node " + name + " in " + timer.DurationMillisecond + ".\n");
            //timer.Restart();

            // Load in this nodes details.
            node.UniqueID = (_uniqueIDTracker++);
            node.Load(reader);

            //DebugLogger.WriteLog("Loaded scene graph node " + name + " in " + timer.DurationMillisecond + ".\n");

            // Read in all the children of this node, and attach
            // them to this node.
            DebugLogger.IncreaseIndent();
            int childCount = reader.ReadInt32();
            for (int i = 0; i < childCount; i++)
            {
                SceneNode childNode = LoadNode(reader);
                node.AddChild(childNode);

                if (getProgress == true)
                    _loadingProgress = (int)(((float)(i + 1) / (float)childCount) * 100.0f);
            }
            DebugLogger.DecreaseIndent();

            return node;
        }
示例#8
0
        /// <summary>
        ///     Called when this entity is triggered by another entities event.
        /// </summary>
        /// <param name="node">The node that triggered this one.</param>
        protected virtual void OnTrigger(EntityNode node)
        {
            if (_enabled == false)
                _enabled = true;

            TriggerEvents();
        }
 /// <summary>
 ///		Initializes a new instance of this window.
 /// </summary>
 /// <param name="entity">The entity this window should be bound to.</param>
 public EntityPropertiesWindow(EntityNode entity)
 {
     _entity = entity;
     InitializeComponent();
     SyncronizeData();
     propertyListView.SetValueDelegate += new PropertyListViewSetValueDelegate(SetValue);
 }
 /// <summary>
 ///     Initializes a new instance of this class.
 /// </summary>
 /// <param name="entity">Entity that will be following.</param>
 /// <param name="boundry">Entity to be used as boundry.</param>
 public EntityBoundryProcess(EntityNode entity, EntityNode boundry)
 {
     _entity = entity;
     _entityBoundry = boundry;
     _priority = -1; // Try and do us last.
 }
 /// <summary>
 ///		Removes the given entity from the selection.
 /// </summary>
 /// <param name="node">Entity node to remove.</param>
 private void RemoveEntityFromSelection(EntityNode node)
 {
     if (_supressSelection == true) return;
     _selectedEntityList.Remove(node);
     node.IsBoundingBoxVisible = _viewBoundingBoxs;
     node.IsCollisionBoxVisible = _viewCollisionBoxs;
     node.IsEventLinesVisible = _viewEventLines;
     node.IsSizingPointsVisible = false;
     if (_entityPropertiesWindow != null && node == _entityPropertiesWindow.Entity)
     {
         _entityPropertiesWindow.Entity = null;
         if (_selectedEntityList.Count == 1 && _entityPropertiesWindow != null && _entityPropertiesWindow.Visible == true) ShowEntityProperties((EntityNode)_selectedEntityList[0]);
     }
     SyncronizeWindow();
 }
        /// <summary>
        ///		Inserts the current object into the map at the cursors position (or center-screen - 
        ///     - if this is not the active window) at the highest level on the scene graph
        /// </summary>
        private void InsertCurrentObject(bool inCenter, string overrideObjectURL)
        {
            string objectURL = overrideObjectURL != "" ? overrideObjectURL : _assetManagerWindow.SelectedObjectURL;
            EntityNode entity = null;

            // Keep a log of this insertion.
            DebugLogger.WriteLog("Inserting object of type '" + objectURL + "' into map");

            // Check the extension to see if this is a built-in object or not.
            if (objectURL.IndexOf(".fso") >= 0)
            {
                // Compile the script.
                ScriptCompiler compiler = new ScriptCompiler();
                bool errorOccured = false;
                string errorDescription = "\t";
                if (compiler.Compile(objectURL) > 0)
                    foreach (CompileError error in compiler.ErrorList)
                        if (error.AlertLevel == ErrorAlertLevel.Error || error.AlertLevel == ErrorAlertLevel.FatalError)
                        {
                            errorDescription += (errorDescription == "" ? "" : "\n\t") + error.ToString();
                            errorOccured = true;
                        }

                // If an error occured notify the user if not then
                // insert a new scripted entity into the map.
                if (errorOccured == true)
                {
                    MessageBox.Show("Unable to insert object into map, the following error(s) occured while attempt to compile this objects script.\n\n"+errorDescription,"Compile Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    DebugLogger.WriteLog("Object insertion aborted. The following error(s) occured while attempting to compile this objects script.\n\n" + errorDescription, LogAlertLevel.Warning);
                }
                else
                {
                    // Dump the compiled code into a memory stream.
                    MemoryStream memStream = new MemoryStream();
                    BinaryWriter writer = new BinaryWriter(memStream);
                    BinaryReader reader = new BinaryReader(memStream);
                    compiler.DumpExecutableFile(writer);
                    memStream.Position = 0;

                    // Create a new scripted entity with the given script attached to it.
                    ScriptedEntityNode scriptedEntity = new ScriptedEntityNode();
                    entity = scriptedEntity;
                    entity.RenderMode = EntityRenderMode.Rectangle;
                    entity.BoundingRectangle = new Rectangle(0, 0, 16, 16);
                    entity.Width = 16;
                    entity.Height = 16;
                    entity.Name = Path.GetFileNameWithoutExtension(objectURL);

                    ScriptProcess process = new ScriptProcess(VirtualMachine.GlobalInstance, reader);
                    process.Url = objectURL;
                    if (process.DefaultEditorState != null)
                        process.ChangeState(process.DefaultEditorState.Identifier);
                    else
                        process.State = null;
                    scriptedEntity.ScriptProcess = process;

                    // Are we allowed to place the entity?
                    bool canPlace = true;
                    string placeError = "This entity has been flagged as unplaceable. Please choose another or check this objects script.";
                    foreach (Define define in process.Defines)
                    {
                        switch (define.Ident.ToUpper())
                        {
                            case "UNPLACEABLE":
                                canPlace = false;
                                break;
                            case "UNPLACEABLE_ERROR":
                                placeError = define.Value;
                                break;
                        }
                    }
                    if (canPlace == false)
                    {
                        MessageBox.Show(placeError, "Unplaceable", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    Engine.Engine.GlobalInstance.Map.SceneGraph.RootNode.AddChild(entity);

                    // Invoke OnCreate event.
                    scriptedEntity.ScriptProcess[0].InvokeFunction("OnCreate", true, false);

                    // Free up the streams.
                    memStream.Close();
                    reader.Close();
                    writer.Close();
                }
            }

            // Its built in so create the object requested.
            else
            {
                switch (objectURL.ToLower())
                {
                    case "tilemap segment":
                        TilemapSegmentNode segment = new TilemapSegmentNode(8, 8, 16, 16);
                        Engine.Engine.GlobalInstance.Map.SceneGraph.RootNode.AddChild(segment);
                        segment.IsGridVisible = true;
                        entity = segment;
                        break;

                    case "emitter":
                        entity = new EmitterNode();
                        Engine.Engine.GlobalInstance.Map.SceneGraph.RootNode.AddChild(entity);
                        entity.BoundingRectangle = new Rectangle(0, 0, 16, 16);
                        entity.Width = 16;
                        entity.Height = 16;
                        break;

                    case "entity":
                        entity = new EntityNode();
                        Engine.Engine.GlobalInstance.Map.SceneGraph.RootNode.AddChild(entity);
                        entity.BoundingRectangle = new Rectangle(0, 0, 16, 16);
                        entity.Width = 16;
                        entity.Height = 16;
                        break;

                    case "path marker":
                        entity = new PathMarkerNode();
                        Engine.Engine.GlobalInstance.Map.SceneGraph.RootNode.AddChild(entity);
                        entity.BoundingRectangle = new Rectangle(0, 0, 16, 16);
                        entity.Width = 16;
                        entity.Height = 16;
                        entity.Image = _pathMarkerImage;
                        entity.RenderMode = EntityRenderMode.Image;
                        entity.Name = "Path Marker " + MathMethods.Random(MathMethods.Random(0, 10000), MathMethods.Random(10000, 10000000));

                        foreach (EntityNode selEntity in _selectedEntityList)
                            if (selEntity is PathMarkerNode && ((PathMarkerNode)selEntity).NextNodeName == "")
                            {
                                ((PathMarkerNode)selEntity).NextNode = (PathMarkerNode)entity;
                                ((PathMarkerNode)selEntity).NextNodeName = entity.Name;
                            }

                        break;
                }
            }

            if (entity == null) return;

            // Find the correct position for our new entity.
            int mapX, mapY;
            if (inCenter == false)
            {
                mapX = (int)Editor.GlobalInstance.CameraNode.Transformation.X + (int)((mousePositionBeforeRightClick[0] / Editor.GlobalInstance.CameraNode.Zoom));
                mapY = (int)Editor.GlobalInstance.CameraNode.Transformation.Y + (int)((mousePositionBeforeRightClick[1] / Editor.GlobalInstance.CameraNode.Zoom));
            }
            else
            {
                mapX = (int)Editor.GlobalInstance.CameraNode.Transformation.X + (int)(((mapPanel.ClientSize.Width - entity.BoundingRectangle.Width) / 2) / Editor.GlobalInstance.CameraNode.Zoom);
                mapY = (int)Editor.GlobalInstance.CameraNode.Transformation.Y + (int)(((mapPanel.ClientSize.Height - entity.BoundingRectangle.Height) / 2) / Editor.GlobalInstance.CameraNode.Zoom);
            }

            if (_snapToGrid == true)
            {
                mapX = (mapX / _gridWidth) * _gridWidth;
                mapY = (mapY / _gridHeight) * _gridHeight;
            }

            entity.Position(mapX, mapY, 0.0f);
            entity.IsBoundingBoxVisible = _viewBoundingBoxs;
            entity.IsEventLinesVisible = _viewEventLines;
            entity.IsCollisionBoxVisible = _viewCollisionBoxs;
            entity.ForceVisibility = true;

            ClearSelection();
            AddEntityToSelection(entity);

            // Update the scene graph window if it exists.
            if (_sceneGraphWindow != null) _sceneGraphWindow.SyncronizeData();

            // Update this entitys event nodes and the event nodes of others.
            foreach (SceneNode node in Engine.Engine.GlobalInstance.Map.SceneGraph.EnumerateNodes())
            {
                EntityNode subNode = node as EntityNode;
                if (subNode == null) continue;
                if (subNode.Event.ToLower() == entity.Name.ToString().ToLower()) subNode.EventNodes.Add(entity);
            }

            PushUndoOperation(new InsertNodesUndoOperation(new SceneNode[] { entity }));
            SyncronizeWindow();

            _mapChangedSinceSave = true;
        }
 private void AddEntityToSelection(EntityNode node)
 {
     AddEntityToSelection(node, false);
 }
 /// <summary>
 ///		Adds the given entity to the selection.
 /// </summary>
 /// <param name="node">Entity node to add.</param>
 /// <param name="doNotShowProperties">IF set to true the entitsy properties will not be shown in the entity properties window.</param>
 private void AddEntityToSelection(EntityNode node, bool doNotShowProperties)
 {
     if (_supressSelection == true) return;
     _selectedEntityList.Add(node);
     node.IsBoundingBoxVisible = true;
     node.IsSizingPointsVisible = true;
     if (doNotShowProperties == false && _selectedEntityList.Count == 1 && _entityPropertiesWindow != null && _entityPropertiesWindow.Visible == true) ShowEntityProperties((EntityNode)_selectedEntityList[0]);
     SyncronizeWindow();
 }
        /// <summary>
        ///		Called when the selector tool is selected and an event has been recieved.
        /// </summary>
        /// <param name="firedEvent">Event that caused this update to be called.</param>
        public void UpdateSelector(Event firedEvent)
        {
            if (firedEvent.ID == "mouse_move" && InputManager.KeyDown(KeyCodes.LeftMouse))
            {
                if (_toolMoving == true)
                {
                    _toolMovementDimensions.Width = InputManager.MouseX - _toolMovementDimensions.X;
                    _toolMovementDimensions.Height = InputManager.MouseY - _toolMovementDimensions.Y;
                }
                else if (_movingObject == true)
                {
                    ArrayList groupsMoved = new ArrayList();
                    foreach (EntityNode iterationEntity in _selectedEntityList)
                    {
                        if (iterationEntity.Parent != null && iterationEntity.Parent as GroupNode != null && groupsMoved.Contains(iterationEntity.Parent) == true) continue;
                        EntityNode entity = (iterationEntity.Parent != null && iterationEntity.Parent as GroupNode != null) ? (GroupNode)iterationEntity.Parent : iterationEntity;

                        entity.Move(_xAxisLocked == true ? 0.0f : ((InputManager.MouseX - _moveObjectDimensions.X) / Editor.GlobalInstance.CameraNode.Zoom), _yAxisLocked == true ? 0.0f : ((InputManager.MouseY - _moveObjectDimensions.Y) / Editor.GlobalInstance.CameraNode.Zoom), 0.0f);

                        if (iterationEntity.Parent != null && iterationEntity.Parent as GroupNode != null)
                            groupsMoved.Add(iterationEntity.Parent);
                    }
                    _moveObjectDimensions.X = InputManager.MouseX;
                    _moveObjectDimensions.Y = InputManager.MouseY;
                    _mapChangedSinceSave = true;
                }
                else if (_sizingObject == true)
                {
                    int movementX = _xAxisLocked == true ? 0 : (int)((InputManager.MouseX - _moveObjectDimensions.X) / Editor.GlobalInstance.CameraNode.Zoom), movementY = _yAxisLocked == true ? 0 : (int)((InputManager.MouseY - _moveObjectDimensions.Y) / Editor.GlobalInstance.CameraNode.Zoom);
                    _objectToSize.BoundingRectangle = _objectSizeOriginalBoundingBox;
                    _objectToSize.Transformation = _objectSizeOriginalTransformation;

                    if ((_sizingDirection & SizingDirection.Top) != 0)
                    {
                        _objectToSize.Resize(_objectToSize.BoundingRectangle.Width, Math.Max(_objectToSize.BoundingRectangle.Height + -movementY,_gridHeight));
                        _objectToSize.Position(_objectToSize.Transformation.X, _objectToSize.Transformation.Y + -(_objectToSize.BoundingRectangle.Height - _objectSizeOriginalBoundingBox.Height), _objectToSize.Transformation.Z);
                    }
                    if ((_sizingDirection & SizingDirection.Left) != 0)
                    {
                        _objectToSize.Resize(Math.Max(_objectToSize.BoundingRectangle.Width + -movementX, _gridWidth), _objectToSize.BoundingRectangle.Height);
                        _objectToSize.Position(_objectToSize.Transformation.X + -(_objectToSize.BoundingRectangle.Width - _objectSizeOriginalBoundingBox.Width), _objectToSize.Transformation.Y, _objectToSize.Transformation.Z);
                    }

                    if ((_sizingDirection & SizingDirection.Bottom) != 0)
                        _objectToSize.Resize(_objectToSize.BoundingRectangle.Width, Math.Max(_objectToSize.BoundingRectangle.Height + movementY, _gridHeight));
                    if ((_sizingDirection & SizingDirection.Right) != 0)
                        _objectToSize.Resize(Math.Max(_objectToSize.BoundingRectangle.Width + movementX, _gridWidth), _objectToSize.BoundingRectangle.Height);
                    _mapChangedSinceSave = true;
                }
            }
            else if (firedEvent.ID == "key_pressed" && ((InputEventData)firedEvent.Data).KeyCode == KeyCodes.LeftMouse)
            {
                bool touchingSizingPoint = false;
                Rectangle mouseRectangle = new Rectangle(InputManager.MouseX, InputManager.MouseY, 1, 1);
                foreach (EntityNode node in _selectedEntityList)
                    if (node.RectangleSizingPointsIntersect(mouseRectangle, Editor.GlobalInstance.CameraNode))
                        touchingSizingPoint = true;

                // Was last click in same spot? If so we want to select the new object.
                if (touchingSizingPoint == false && ((_toolMovementDimensions.X == InputManager.MouseX && _toolMovementDimensions.Y == InputManager.MouseY) || (_toolMovementDimensions.Width == 0 || _toolMovementDimensions.Height == 0)))
                {
                    if (InputManager.KeyDown(KeyCodes.LeftControl))
                    {
                        Rectangle intersectRectangle = new Rectangle(InputManager.MouseX, InputManager.MouseY, 1, 1);
                        foreach (SceneNode node in Engine.Engine.GlobalInstance.Map.SceneGraph.EnumerateNodes())
                        {
                            EntityNode entity = node as EntityNode;
                            if (entity == null) continue;

                            if (entity.RectangleBoundingBoxIntersect(intersectRectangle, Editor.GlobalInstance.CameraNode) == true)
                            {
                                if (_selectedEntityList.Contains(entity))
                                    RemoveEntityFromSelection(entity);
                                else
                                    AddEntityToSelection(entity);
                                break;
                            }
                        }

                        SyncronizeWindow();
                    }
                    else
                    {
                        Rectangle intersectRectangle = new Rectangle(InputManager.MouseX, InputManager.MouseY, 1, 1);
                        bool canSelect = (_selectedEntityList.Count == 0);
                        EntityNode selectEntity = null, firstEntity = null;

                        foreach (SceneNode node in Engine.Engine.GlobalInstance.Map.SceneGraph.EnumerateNodes())
                        {
                            EntityNode entity = node as EntityNode;
                            if (entity == null) continue;

                            if (entity.RectangleBoundingBoxIntersect(intersectRectangle, Editor.GlobalInstance.CameraNode) == true)
                            {
                                if (canSelect == true)
                                {
                                    selectEntity = entity;
                                    break;
                                }
                                else if (firstEntity != null)
                                    firstEntity = entity;

                                if (_selectedEntityList.Contains(entity))
                                    canSelect = true;
                            }
                        }
                        if (selectEntity == null)
                            selectEntity = firstEntity;

                        ClearSelection();

                        if (selectEntity != null)
                        {
                            AddEntityToSelection(selectEntity);
                            SyncronizeWindow();
                        }

                        _movingObject = true;
                        _moveObjectDimensions.X = InputManager.MouseX;
                        _moveObjectDimensions.Y = InputManager.MouseY;
                    }
                }
                else
                {
                    ArrayList removeList = new ArrayList();
                    Rectangle intersectRectangle = new Rectangle(InputManager.MouseX, InputManager.MouseY, 1, 1);
                    foreach (SceneNode node in Engine.Engine.GlobalInstance.Map.SceneGraph.EnumerateNodes())
                    {
                        EntityNode entity = node as EntityNode;
                        if (entity == null) continue;
                        if (entity.RectangleBoundingBoxIntersect(intersectRectangle, Editor.GlobalInstance.CameraNode) == false &&
                            entity.RectangleSizingPointsIntersect(intersectRectangle, Editor.GlobalInstance.CameraNode) == false)
                            removeList.Add(entity);
                    }
                    if (!InputManager.KeyDown(KeyCodes.LeftControl))
                    {
                        foreach (EntityNode entity in removeList)
                            RemoveEntityFromSelection(entity);
                    }

                    _movingObject = true;
                    _moveObjectDimensions.X = InputManager.MouseX;
                    _moveObjectDimensions.Y = InputManager.MouseY;
                }

                // Lets select an object or size one.
                foreach (EntityNode entity in _selectedEntityList)
                {
                    Transformation transformation = entity.CalculateTransformation(Editor.GlobalInstance.CameraNode);
                    int x = (int)(transformation.X - (entity.SizingPointsSize / 2)), y = (int)(transformation.Y - (entity.SizingPointsSize / 2));
                    int w = (int)(entity.BoundingRectangle.Width * Editor.GlobalInstance.CameraNode.Zoom), h = (int)(entity.BoundingRectangle.Height * Editor.GlobalInstance.CameraNode.Zoom);

                    bool previousMoving = _movingObject;
                    _movingObject = false;
                    _sizingObject = true;
                    _objectToSize = entity;
                    _objectSizeOriginalBoundingBox = _objectToSize.BoundingRectangle;
                    _objectSizeOriginalTransformation = _objectToSize.Transformation;
                    if (mouseRectangle.IntersectsWith(new Rectangle(x, y, entity.SizingPointsSize, entity.SizingPointsSize)))
                    {
                        _sizingDirection = SizingDirection.Top | SizingDirection.Left;
                        Cursor = Cursors.SizeNWSE;
                    }
                    else if (mouseRectangle.IntersectsWith(new Rectangle(x + w, y, entity.SizingPointsSize, entity.SizingPointsSize)))
                    {
                        _sizingDirection = SizingDirection.Top | SizingDirection.Right;
                        Cursor = Cursors.SizeNESW;
                    }
                    else if (mouseRectangle.IntersectsWith(new Rectangle(x, y + h, entity.SizingPointsSize, entity.SizingPointsSize)))
                    {
                        _sizingDirection = SizingDirection.Bottom | SizingDirection.Left;
                        Cursor = Cursors.SizeNESW;
                    }
                    else if (mouseRectangle.IntersectsWith(new Rectangle(x + w, y + h, entity.SizingPointsSize, entity.SizingPointsSize)))
                    {
                        _sizingDirection = SizingDirection.Bottom | SizingDirection.Right;
                        Cursor = Cursors.SizeNWSE;
                    }
                    else if (mouseRectangle.IntersectsWith(new Rectangle(x + (w / 2), y, entity.SizingPointsSize, entity.SizingPointsSize)))
                    {
                        _sizingDirection = SizingDirection.Top;
                        Cursor = Cursors.SizeNS;
                    }
                    else if (mouseRectangle.IntersectsWith(new Rectangle(x + (w / 2), y + h, entity.SizingPointsSize, entity.SizingPointsSize)))
                    {
                        _sizingDirection = SizingDirection.Bottom;
                        Cursor = Cursors.SizeNS;
                    }
                    else if (mouseRectangle.IntersectsWith(new Rectangle(x, y + (h / 2), entity.SizingPointsSize, entity.SizingPointsSize)))
                    {
                        _sizingDirection = SizingDirection.Left;
                        Cursor = Cursors.SizeWE;
                    }
                    else if (mouseRectangle.IntersectsWith(new Rectangle(x + w, y + (h / 2), entity.SizingPointsSize, entity.SizingPointsSize)))
                    {
                        _sizingDirection = SizingDirection.Right;
                        Cursor = Cursors.SizeWE;
                    }
                    else
                    {
                        _sizingObject = false;
                        _objectToSize = null;
                        _movingObject = previousMoving;
                    }
                }

                // If we are holding shift then we want to select multiple objects.
                if (InputManager.KeyDown(KeyCodes.LeftShift))
                {
                    _movingObject = false;
                    _sizingObject = false;
                    _toolMoving = true;
                }

                // Log the original transformations of the selected nodes.
                _originalEntityTransformations.Clear();
                _originalEntityBoundingBoxs.Clear();
                foreach (EntityNode entity in _selectedEntityList)
                {
                    _originalEntityTransformations.Add(entity, entity.Transformation);
                    _originalEntityBoundingBoxs.Add(entity, entity.BoundingRectangle);
                }

                _toolMovementDimensions.X = InputManager.MouseX;
                _toolMovementDimensions.Y = InputManager.MouseY;
                _toolMovementDimensions.Width = _selectedEntityList.Count > 0 ? 1 : 0;
                _toolMovementDimensions.Height = _selectedEntityList.Count > 0 ? 1 : 0;
            }
            else if (firedEvent.ID == "key_released" && ((InputEventData)firedEvent.Data).KeyCode == KeyCodes.LeftMouse)
            {
                if (_toolMoving == true)
                {
                    _toolMoving = false;

                    // Create a rectangle from which we can check intersection against.
                    Rectangle intersectRectangle = new Rectangle();

                    // If we have a negative width then make it positive.
                    if (_toolMovementDimensions.Width < 0)
                    {
                        intersectRectangle.X = _toolMovementDimensions.X + _toolMovementDimensions.Width;
                        intersectRectangle.Width = Math.Abs(_toolMovementDimensions.Width);
                    }
                    else
                    {
                        intersectRectangle.X = _toolMovementDimensions.X;
                        intersectRectangle.Width = _toolMovementDimensions.Width;
                    }

                    // If we have a negative height then make it positive.
                    if (_toolMovementDimensions.Height < 0)
                    {
                        intersectRectangle.Y = _toolMovementDimensions.Y + _toolMovementDimensions.Height;
                        intersectRectangle.Height = Math.Abs(_toolMovementDimensions.Height);
                    }
                    else
                    {
                        intersectRectangle.Y = _toolMovementDimensions.Y;
                        intersectRectangle.Height = _toolMovementDimensions.Height;
                    }

                    // Unselect all the pervious entitys.
                    ArrayList oldSelectionList = new ArrayList();
                    oldSelectionList.AddRange(_selectedEntityList);

                    // Clear out old selection.
                    if (InputManager.KeyDown(KeyCodes.LeftControl) == false)
                        ClearSelection();

                    // Grab all the entitys within our selection rectangle and select them.
                    bool canSelect = (oldSelectionList.Count == 0 || !(intersectRectangle.Width < 2 && intersectRectangle.Height < 2));
                    EntityNode selectEntity = null;
                    foreach (SceneNode node in Engine.Engine.GlobalInstance.Map.SceneGraph.EnumerateNodes())
                    {
                        EntityNode entity = node as EntityNode;
                        if (entity == null) continue;

                        if (entity.RectangleBoundingBoxIntersect(intersectRectangle, Editor.GlobalInstance.CameraNode) == true)
                        {
                            if (canSelect == true)
                            {
                                AddEntityToSelection(entity);
                                if (intersectRectangle.Width < 2 && intersectRectangle.Height < 2)
                                    break;
                            }
                            else if (selectEntity == null)
                                selectEntity = entity;

                            if (oldSelectionList.Contains(entity))
                                canSelect = true;
                        }
                    }
                    if (canSelect == false && selectEntity != null)
                        AddEntityToSelection(selectEntity);
                }
                else if (_movingObject == true)
                {
                    // Snap the objects to the grid.
                    if (_snapToGrid == true)
                    {
                        foreach (EntityNode entity in _selectedEntityList)
                        {
                            entity.Position(((int)entity.Transformation.X / _gridWidth) * _gridWidth, ((int)entity.Transformation.Y / _gridHeight) * _gridHeight, entity.Transformation.Z);

                            // Create a new transformation undo operation if transformation has changed.
                            Transformation originalTransformation = (Transformation)_originalEntityTransformations[entity];
                            if (originalTransformation != entity.Transformation)
                                PushUndoOperation(new TransformNodeUndoOperation(entity, originalTransformation, entity.Transformation));
                        }
                        _originalEntityTransformations.Clear();
                        if (_entityPropertiesWindow != null && _entityPropertiesWindow.Entity != null)
                            _entityPropertiesWindow.UpdateProperty("location", new Point((int)_entityPropertiesWindow.Entity.Transformation.X, (int)_entityPropertiesWindow.Entity.Transformation.Y));
                    }
                    _movingObject = false;
                    _mapChangedSinceSave = true;
                }
                else if (_sizingObject == true)
                {
                    if (_snapToGrid == true)
                    {
                        _objectToSize.Position(((int)_objectToSize.Transformation.X / _gridWidth) * _gridWidth, ((int)_objectToSize.Transformation.Y / _gridHeight) * _gridHeight, _objectToSize.Transformation.Z);
                        _objectToSize.BoundingRectangle = new Rectangle(_objectToSize.BoundingRectangle.X, _objectToSize.BoundingRectangle.Y, ((int)_objectToSize.BoundingRectangle.Width / _gridWidth) * _gridWidth, ((int)_objectToSize.BoundingRectangle.Height / _gridHeight) * _gridHeight);

                        Rectangle newBoundingRectangle = _objectToSize.BoundingRectangle;
                        if (newBoundingRectangle.Width < _gridWidth) newBoundingRectangle.Width = _gridWidth;
                        if (newBoundingRectangle.Height < _gridHeight) newBoundingRectangle.Height = _gridHeight;
                        _objectToSize.BoundingRectangle = newBoundingRectangle;

                        // Create a new sizing undo operation if size has changed.
                        Rectangle originalBoundingBox = (Rectangle)_originalEntityBoundingBoxs[_objectToSize];
                        if (!_objectToSize.BoundingRectangle.Equals(originalBoundingBox))
                            PushUndoOperation(new ResizeNodeUndoOperation(_objectToSize, originalBoundingBox, (Transformation)_originalEntityTransformations[_objectToSize], _objectToSize.BoundingRectangle, _objectToSize.Transformation));
                    }
                    if (_entityPropertiesWindow != null && _entityPropertiesWindow.Entity != null)
                    {
                        _entityPropertiesWindow.UpdateProperty("bounding rectangle", new Rectangle(_entityPropertiesWindow.Entity.BoundingRectangle.X, _entityPropertiesWindow.Entity.BoundingRectangle.Y, _entityPropertiesWindow.Entity.BoundingRectangle.Width, _entityPropertiesWindow.Entity.BoundingRectangle.Height));
                        _entityPropertiesWindow.UpdateProperty("collision rectangle", new Rectangle(_entityPropertiesWindow.Entity.CollisionRectangle.X, _entityPropertiesWindow.Entity.CollisionRectangle.Y, _entityPropertiesWindow.Entity.CollisionRectangle.Width, _entityPropertiesWindow.Entity.CollisionRectangle.Height));
                    }
                    Cursor = Cursors.Arrow;
                    _sizingObject = false;
                    _mapChangedSinceSave = true;
                }

                SyncronizeWindow();
            }
        }
 /// <summary>
 ///		Initializes a new instance of this class with the specified parameters.
 /// </summary>
 /// <param name="entity">Entity to associate this animation with.</param>
 /// <param name="mode">Mode of animation to animate entity with.</param>
 /// <param name="frameDelay">Delay between each animation frame.</param>
 /// <param name="frames">Array of frame indexs to animate entity with.</param>
 /// <param name="loopLimit">Maximum amount of loops before this process has to finish. 0 is equal to infinite.</param>
 public AnimationProcess(EntityNode entity, AnimationMode mode, int frameDelay, int[] frames, int loopLimit)
 {
     _entity = entity;
     _mode = mode;
     _frameDelay = frameDelay;
     _loopLimit = loopLimit;
     _frames = frames;
 }
 /// <summary>
 ///     Initializes a new instance of this class.
 /// </summary>
 /// <param name="entity">Entity to shake.</param>
 /// <param name="intensity">Intensity to shake entity by.</param>
 public EntityShakeProcess(EntityNode entity, float intensity)
 {
     _entity = entity;
     _shakeIntensity = intensity;
 }
 /// <summary>
 ///		Shows the entity properties window.
 /// </summary>
 private void ShowEntityProperties(EntityNode entity)
 {
     if (_entityPropertiesWindow == null || _entityPropertiesWindow.IsDisposed == true)
     {
         _entityPropertiesWindow = new EntityPropertiesWindow(entity);
         _entityPropertiesWindow.Show(this);
         _entityPropertiesWindow.PropertyChangedDelegate += new PropertyChangedEventHandler(EntityPropertiesWindow_PropertyChanged);
         _supressSelection = true;
         _supressSelectionTimer.Restart();
     }
     else
     {
         if (_entityPropertiesWindow.Visible == false)
         {
             _entityPropertiesWindow.Show(this);
             _supressSelection = true;
             _supressSelectionTimer.Restart();
         }
         _entityPropertiesWindow.Focus();
         _entityPropertiesWindow.Entity = entity;
     }
 }
 /// <summary>
 ///     Called when this entity is triggered by another entities event.
 /// </summary>
 /// <param name="node">The node that triggered this one.</param>
 protected override void OnTrigger(EntityNode node)
 {
     if (node == null) return;
     if (_process != null && _process.Process != null && _enabled == true)
     {
         _process.Process[0].PassParameter(new SceneNodeScriptObject(node));
         _process.Process[0].InvokeFunction("OnTrigger", true, false);
     }
     TriggerEvents();
 }
 /// <summary>
 ///     Initializes a new instance of this class.
 /// </summary>
 /// <param name="node">Node that was transformed.</param>
 /// <param name="originalBoundingBox">Nodes original bounding box.</param>
 /// <param name="originalTransformation">Nodes original transformation.</param>
 /// <param name="newBoundingBox">Nodes new bounding box.</param>
 /// <param name="newTransformation">Nodes new transformation.</param>
 public ResizeNodeUndoOperation(EntityNode node, Rectangle originalBoundingBox, Transformation originalTransformation, Rectangle newBoundingBox, Transformation newTransformation)
 {
     _node = node;
     _newBoundingBox = newBoundingBox;
     _newTransformation = newTransformation;
     _originalBoundingBox = originalBoundingBox;
     _originalTransformation = originalTransformation;
 }
 /// <summary>
 ///     Called when this process needs to be destroyed.
 /// </summary>
 public override void Dispose()
 {
     if (_eventListener != null) EventManager.DetachListener(_eventListener);
     if (_process != null)
         _process.Dispose();
     _eventListener = null;
     _process = null;
     _entity = null;
 }
示例#22
0
 public void CreateEntity(ScriptThread thread)
 {
     EntityNode node = new EntityNode();
     thread.SetReturnValue(new SceneNodeScriptObject(node));
 }