Exemple #1
0
        public override void doMoveAction()
        {
            if (isDragging)
            {
                Tile victim = getMouseWorldPos();
                if (victim != null)
                {
                    MapFile.TileData td = (editor.world as EditorWorld).file.tiles[0, victim.xIndex, victim.yIndex];
                    if (td.tileIndex == (toolAction.Peek() as PencilToolAction).texture[1] &&
                        td.tileSetIndex == (toolAction.Peek() as PencilToolAction).texture[0])
                    {
                        return;
                    }
                    (toolAction.Peek() as PencilToolAction).changed.AddLast(new TextureData(victim.xIndex, victim.yIndex, td.tileSetIndex, td.tileIndex));

                    td.tileSetIndex = (toolAction.Peek() as PencilToolAction).texture[0];
                    td.tileIndex    = (toolAction.Peek() as PencilToolAction).texture[1];

                    (editor.world as EditorWorld).file.tiles[0, victim.xIndex, victim.yIndex] = td;

                    editor.world.tileArray[victim.xIndex, victim.yIndex].imgIndex =
                        (this.editor.world as EditorWorld).currentTile.tileIndex;
                }
                //editor.world.initTiles();
            }
        }
Exemple #2
0
        public override void doLeftDownAction()
        {
            Tile victim = getMouseWorldPos();

            if (victim != null && !isDragging)
            {
                MapFile.TileData td = (editor.world as EditorWorld).file.tiles[0, victim.xIndex, victim.yIndex];
                if (td.tileIndex == (this.editor.world as EditorWorld).currentTile.tileIndex &&
                    td.tileSetIndex == (this.editor.world as EditorWorld).currentTile.tileIndex)
                {
                    return;
                }
                LinkedList <TextureData> changed = new LinkedList <TextureData>();
                changed.AddLast(new TextureData(victim.xIndex, victim.yIndex, td.tileSetIndex, td.tileIndex));
                undos.Clear();

                td.tileIndex    = (this.editor.world as EditorWorld).currentTile.tileIndex;
                td.tileSetIndex = (this.editor.world as EditorWorld).currentTile.tileSetIndex;
                (editor.world as EditorWorld).file.tiles[0, victim.xIndex, victim.yIndex] = td;

                toolAction.Push(new PencilToolAction(changed, new byte[] { td.tileSetIndex, td.tileIndex }, this));

                editor.world.tileArray[victim.xIndex, victim.yIndex].imgIndex =
                    (this.editor.world as EditorWorld).currentTile.tileIndex;
                isDragging = true;
            }

            //editor.world.initTiles();
        }
Exemple #3
0
        // Apply's brush to map location (xIndex, yIndex)
        private void applyBrush(int xIndex, int yIndex)
        {
            Brush currentBrush = (gui as StampToolGUI).currentBrush;

            // brushwidth, brushheight
            int brushW = currentBrush.values.GetLength(0), brushH = currentBrush.values.GetLength(1);

            // Loop to apply brush to tiles (i and j are brush indices)
            for (int x = xIndex, i = 0; i < brushW && x < editor.world.width; x++, i++)
            {
                for (int y = yIndex, j = 0; j < brushH && y < editor.world.height; y++, j++)
                {
                    Tile             t  = editor.world.tileArray[x, y];                      // Current tile being considered
                    MapFile.TileData td = (editor.world as EditorWorld).file.tiles[0, x, y]; // Data for current tile being considered

                    // Retrieve value from brush
                    int brushVal = currentBrush.values[i, j];  // Brush value for the current tile
                    if (brushVal < 0)
                    {
                        continue;
                    }

                    // Write tile data
                    td.tileIndex    = (byte)brushVal;
                    td.tileSetIndex = 0;   // NOTE: This may not be true in the future. May have to alter brushes to support multiple tilesets
                    (editor.world as EditorWorld).file.tiles[0, x, y] = td;

                    // Write to world
                    editor.world.tileArray[x, y].imgIndex = brushVal;
                }
            }
        }
 public EditorWorld(MirrorEngine theEngine, String theMap) : base(theEngine, theMap)
 {
     tileTextureSet           = tileEngine.resourceComponent.getTextureSet("Tiles");
     currentTile              = new MapFile.TileData();
     currentTile.tileSetIndex = 0;
     currentTile.tileIndex    = 0;
     currentActor             = 0;
     editor = theEngine as Editor;
 }
Exemple #5
0
        public FillToolAction fill(byte[] texture, Tile startTile)
        {
            LinkedList <TextureData> changed = new LinkedList <TextureData>(); // for undo

            MapFile.TileData replace = editor.world.file.tiles[0, startTile.xIndex, startTile.yIndex];
            if (replace.tileSetIndex == texture[0] && replace.tileIndex == texture[1])
            {
                return(null); // not sure if want to count do-nothing action as action
            }
            Queue <Tile> applyToMe = new Queue <Tile>();

            MapFile.TileData d;

            applyToMe.Enqueue(startTile);

            d = editor.world.file.tiles[0, startTile.xIndex, startTile.yIndex];
            changed.AddLast(new TextureData(startTile.xIndex, startTile.yIndex, d.tileSetIndex, d.tileIndex));
            editor.world.file.tiles[0, startTile.xIndex, startTile.yIndex].tileSetIndex = texture[0];
            editor.world.file.tiles[0, startTile.xIndex, startTile.yIndex].tileIndex    = texture[1];

            while (applyToMe.Count() > 0)
            {
                Tile mid = applyToMe.Dequeue();
                foreach (Tile tile in mid.adjacent)
                {
                    if (tile != null)
                    {
                        d = editor.world.file.tiles[0, tile.xIndex, tile.yIndex];
                        if (d.tileSetIndex == replace.tileSetIndex && d.tileIndex == replace.tileIndex)
                        {
                            applyToMe.Enqueue(tile);
                            changed.AddLast(new TextureData(tile.xIndex, tile.yIndex, d.tileSetIndex, d.tileIndex));
                            editor.world.file.tiles[0, tile.xIndex, tile.yIndex].tileSetIndex = texture[0];
                            editor.world.file.tiles[0, tile.xIndex, tile.yIndex].tileIndex    = texture[1];
                        }
                    }
                }
            }
            return(new FillToolAction(changed, texture, startTile, this));
        }