상속: ITileBrush
예제 #1
0
        /// <summary>
        /// Draws the brush onto the given screen at the given tile location.
        /// Returns an "undo brush" - a brush of all tiles that were overwritten.
        /// Returns null if no tiles were changed.
        /// </summary>
        public ITileBrush DrawOn(ScreenDocument screen, int tile_x, int tile_y)
        {
            TileBrush undo    = new TileBrush(Width, Height);
            bool      changed = false;

            foreach (TileBrushCell[] col in cells)
            {
                foreach (TileBrushCell cell in col)
                {
                    var old = screen.TileAt(cell.x + tile_x, cell.y + tile_y);

                    if (old == null)
                    {
                        continue;
                    }
                    undo.AddTile(old, cell.x, cell.y);
                    if (old.Id != cell.tile.Id)
                    {
                        changed = true;
                        screen.ChangeTile(cell.x + tile_x, cell.y + tile_y, cell.tile.Id);
                    }
                }
            }

            if (changed)
            {
                return(undo);
            }
            return(null);
        }
예제 #2
0
        private void buttonNewBrush_Click(object sender, EventArgs e)
        {
            if (Tileset == null || brushes == null)
            {
                return;
            }

            creatingBrush = new TileBrush(2, 2);

            splitter.Panel1Collapsed = false;

            ResetNewBrush(2, 2);
        }
예제 #3
0
        public void Copy()
        {
            if (ActiveSurface != null && ActiveSurface.Selection != null)
            {
                var selection = ActiveSurface.Selection.Value;
                copyBrush = new TileBrush(selection.Width, selection.Height);

                for (int ty = selection.Y; ty < selection.Bottom; ty++)
                {
                    for (int tx = selection.X; tx < selection.Right; tx++)
                    {
                        copyBrush.AddTile(ActiveSurface.Screen.TileAt(tx, ty), tx - selection.X, ty - selection.Y);
                    }
                }
            }
        }
예제 #4
0
        public void Copy()
        {
            if (ActiveSurface != null && ActiveSurface.Selection != null)
            {
                var selection = ActiveSurface.Selection.Value;
                copyBrush = new TileBrush(selection.Width, selection.Height);

                for (int ty = selection.Y; ty < selection.Bottom; ty++)
                {
                    for (int tx = selection.X; tx < selection.Right; tx++)
                    {
                        copyBrush.AddTile(ActiveSurface.Screen.TileAt(tx, ty), tx - selection.X, ty - selection.Y);
                    }
                }
            }
        }
예제 #5
0
        private void LoadBrushes()
        {
            string dir  = System.IO.Path.GetDirectoryName(Tileset.FilePath.Absolute);
            string file = System.IO.Path.GetFileNameWithoutExtension(Tileset.FilePath.Absolute);
            string path = System.IO.Path.Combine(dir, file + "_brushes.xml");

            if (!System.IO.File.Exists(path))
            {
                return;
            }

            using (var stream = new System.IO.StreamReader(path))
            {
                while (!stream.EndOfStream)
                {
                    string line = stream.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    string[] info = line.Split(' ');

                    TileBrush brush = new TileBrush(int.Parse(info[0]), int.Parse(info[1]));

                    int x = 0; int y = 0;
                    for (int i = 2; i < info.Length; i++)
                    {
                        int id = int.Parse(info[i]);
                        if (id >= 0)
                        {
                            brush.AddTile(Tileset[id], x, y);
                        }

                        y++;
                        if (y >= brush.Height)
                        {
                            y = 0;
                            x++;
                        }
                    }

                    brushes.Add(brush);
                }
            }
        }
예제 #6
0
 private void CancelNewBrush(object sender, EventArgs e)
 {
     creatingBrush            = null;
     splitter.Panel1Collapsed = true;
 }
예제 #7
0
 private void SaveNewBrush(object sender, EventArgs e)
 {
     AddBrush(creatingBrush);
     creatingBrush            = null;
     splitter.Panel1Collapsed = true;
 }
예제 #8
0
 private void SaveNewBrush(object sender, EventArgs e)
 {
     AddBrush(creatingBrush);
     creatingBrush = null;
     splitter.Panel1Collapsed = true;
 }
예제 #9
0
        private void LoadBrushes()
        {
            string dir = System.IO.Path.GetDirectoryName(Tileset.FilePath.Absolute);
            string file = System.IO.Path.GetFileNameWithoutExtension(Tileset.FilePath.Absolute);
            string path = System.IO.Path.Combine(dir, file + "_brushes.xml");

            if (!System.IO.File.Exists(path)) return;

            using (var stream = new System.IO.StreamReader(path))
            {
                while (!stream.EndOfStream)
                {
                    string line = stream.ReadLine();
                    if (line == null) break;

                    string[] info = line.Split(' ');

                    TileBrush brush = new TileBrush(int.Parse(info[0]), int.Parse(info[1]));

                    int x = 0; int y = 0;
                    for (int i = 2; i < info.Length; i++)
                    {
                        int id = int.Parse(info[i]);
                        if (id >= 0) brush.AddTile(Tileset[id], x, y);

                        y++;
                        if (y >= brush.Height)
                        {
                            y = 0;
                            x++;
                        }
                    }

                    brushes.Add(brush);
                }
            }
        }
예제 #10
0
 private void CancelNewBrush(object sender, EventArgs e)
 {
     creatingBrush = null;
     splitter.Panel1Collapsed = true;
 }
예제 #11
0
        private void buttonNewBrush_Click(object sender, EventArgs e)
        {
            if (Tileset == null || brushes == null) return;

            creatingBrush = new TileBrush(2, 2);

            splitter.Panel1Collapsed = false;

            ResetNewBrush(2, 2);
        }
예제 #12
0
        /// <summary>
        /// Draws the brush onto the given screen at the given tile location.
        /// Returns an "undo brush" - a brush of all tiles that were overwritten.
        /// Returns null if no tiles were changed.
        /// </summary>
        public ITileBrush DrawOn(ScreenDocument screen, int tile_x, int tile_y)
        {
            TileBrush undo = new TileBrush(Width, Height);
            bool changed = false;
            foreach (TileBrushCell[] col in cells) {
                foreach (TileBrushCell cell in col) {
                    var old = screen.TileAt(cell.x + tile_x, cell.y + tile_y);

                    if (old == null)
                        continue;
                    undo.AddTile(old, cell.x, cell.y);
                    if (old.Id != cell.tile.Id) {
                        changed = true;
                        screen.ChangeTile(cell.x + tile_x, cell.y + tile_y, cell.tile.Id);
                    }
                }
            }

            if (changed) return undo;
            return null;
        }