/**
         * Called when the mouse moves into a new tile. If the mouse is clicked down and dragging, it will erase anything within the radius of the eraser circle.
         *
         * @param position The position that the mouse moved to
         */
        public override void moveAction(Vector2 position)
        {
            if (isDragging)
            {
                Vector2 worldPos = editor.engine.graphicsComponent.camera.screen2World(position);

                IEnumerable <Actor> actorsToErase = editor.engine.world.getActorsInCone(worldPos, (floatingPic.size.x / 2) / (editor.engine.graphicsComponent.camera.scale), new Vector2(16, 16), 360, null);

                foreach (Actor target in actorsToErase)
                {
                    Mapfile.ActorData w = new Mapfile.ActorData();
                    w.id = (byte)editor.engine.world.actorFactory.names[target.actorName];
                    w.x  = target.spawn.x;
                    w.y  = target.spawn.y;
                    w.z  = 0;
                    editor.engine.world.file.worldActorData.Remove(w);
                    editor.engine.world.actors.Remove(target);
                }
            }
        }
        /**
         * This function is called when the mouse button is pressed down.
         *
         * @param button The MouseKeyBinding.MouseButton that was clicked down
         */
        public override void downAction(MouseKeyBinding.MouseButton button)
        {
            Vector2 screenPos = editor.engine.inputComponent.getMousePosition();
            Vector2 worldPos  = editor.engine.graphicsComponent.camera.screen2World(screenPos);

            IEnumerable <Actor> actorsToErase = editor.engine.world.getActorsInCone(worldPos, (floatingPic.size.x / 2) / (editor.engine.graphicsComponent.camera.scale), new Vector2(16, 16), 360, null);

            foreach (Actor target in actorsToErase)
            {
                Mapfile.ActorData w = new Mapfile.ActorData();
                w.id = (byte)editor.engine.world.actorFactory.names[target.actorName];
                w.x  = target.spawn.x;
                w.y  = target.spawn.y;
                w.z  = 0;
                editor.engine.world.file.worldActorData.Remove(w);
                editor.engine.world.actors.Remove(target);
                target.removeMe = true;
            }

            isDragging = true;
        }
Exemplo n.º 3
0
        /**
         * desc here
         *
         * @param paramsdeschere
         *
         * @return returndeschere
         */
        public override void downAction(MouseKeyBinding.MouseButton button)
        {
            Vector2 screenPos = editor.engine.inputComponent.getMousePosition();;
            Vector2 worldPos  = editor.engine.graphicsComponent.camera.screen2World(screenPos);

            Tile victim = editor.engine.world.getTileAt(editor.engine.graphicsComponent.camera.screen2World(screenPos));

            if (victim != null)
            {
                Actor p = editor.engine.world.actorFactory.createActor(currentActorIndex, new Vector2(worldPos.x, worldPos.y), new Vector2(0, 0));
                editor.engine.world.addActor(p);

                Mapfile.ActorData w = new Mapfile.ActorData();
                w.id = (byte)currentActorIndex;
                w.x  = worldPos.x;
                w.y  = worldPos.y;
                w.z  = 0;
                editor.engine.world.file.worldActorData.Add(w);

                undos.Clear();

                toolAction.Push(new ActorToolAction(w, this));
            }
        }
            public Mapfile.ActorData actor; //The actor that an action was performed on

            /**
             * Builds the EraserToolAction
             *
             * @param actor The actor that an action was performed on
             * @param parent The editor tool that the action originated from
             */
            public EraserToolAction(Mapfile.ActorData actor, Tool parent)
                : base(parent)
            {
                this.actor = actor;
            }
 /**
  * Called when an EraserTool action has been redone
  *
  * @param action The action being redone
  */
 public override void redoAction(ToolAction action)
 {
     Mapfile.ActorData w = (action as EraserToolAction).actor;
     editor.engine.world.file.worldActorData.Remove(w);
 }
        private void resize()
        {
            if (widthBox.text.Length == 0 || heightBox.text.Length == 0)
            {
                return;
            }

            //Get dimensions
            int width;
            int height;

            try
            {
                width  = Convert.ToInt32(widthBox.text);
                height = Convert.ToInt32(heightBox.text);
            }
            catch (Exception e) { return; }

            World   tempWorld = editor.engine.world;
            Mapfile tempFile  = tempWorld.file;

            Mapfile.TileData emptyTileData = new Mapfile.TileData("");

            //Create new arrays
            Tile[,] newTileArray = new Tile[width, height];
            Mapfile.TileData[, ,] newTileData = new Mapfile.TileData[1, width, height];

            //Transfer tiles
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (x < tempWorld.width && y < tempWorld.height)
                    {
                        newTileArray[x, y]   = tempWorld.tileArray[x, y];
                        newTileData[0, x, y] = tempFile.worldTileData[0, x, y];
                    }
                    else
                    {
                        newTileData[0, x, y] = emptyTileData;
                        newTileArray[x, y]   = new Tile(tempWorld, x, y, emptyTileData);
                    }
                }
            }

            //Erase actors
            List <Actor> actorsToErase = new List <Actor>();

            foreach (Actor a in tempWorld.actors)
            {
                if (tempWorld.getTileAt(a.position.x, a.position.y) == null)
                {
                    actorsToErase.Add(a);
                }
            }
            foreach (Actor a in actorsToErase)
            {
                Mapfile.ActorData w = new Mapfile.ActorData();
                w.id = (byte)editor.engine.world.actorFactory.names[a.actorName];
                w.x  = a.spawn.x;
                w.y  = a.spawn.y;
                w.z  = 0;
                editor.engine.world.file.worldActorData.Remove(w);
                editor.engine.world.actors.Remove(a);
            }

            //Overwrite
            tempFile.worldTileData = newTileData;
            tempWorld.tileArray    = newTileArray;
            tempWorld.width        = width;
            tempWorld.height       = height;
        }