public ClipboardBuffer GetBufferedRegion(World world, Int32Rect area) { var buffer = new ClipboardBuffer(new PointInt32(area.Width, area.Height)); for (int x = 0; x < area.Width; x++) { for (int y = 0; y < area.Height; y++) { Tile curTile = (Tile)world.Tiles[x + area.X, y + area.Y].Clone(); if (curTile.Type == 21) // 21 Chest , 55 sign { if (buffer.GetChestAtTile(x, y) == null) { var data = world.GetChestAtTile(x + area.X, y + area.Y); if (data != null) { var newChest = Utility.DeepCopy(data); newChest.Location = new PointInt32(x, y); buffer.Chests.Add(newChest); } } } if (curTile.Type == 55 || curTile.Type == 85) // 21 Chest , 55 sign { if (buffer.GetSignAtTile(x, y) == null) { var data = world.GetSignAtTile(x + area.X, y + area.Y); if (data != null) { var newSign = Utility.DeepCopy(data); newSign.Location = new PointInt32(x, y); buffer.Signs.Add(newSign); } } } buffer.Tiles[x, y] = curTile; } } return buffer; }
private void RemoveSchematicFile(ClipboardBuffer buffer) { ClipboardMan.LoadedBuffers.Remove(buffer); }
private void ExportSchematicFile(ClipboardBuffer buffer) { var sfd = new SaveFileDialog(); sfd.Filter = "TEdit Schematic File|*.TEditSch"; sfd.Title = "Export Schematic File"; sfd.InitialDirectory = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"My Games\Terraria\Worlds"); if ((bool)sfd.ShowDialog()) { buffer.Save(sfd.FileName); } }
public static ClipboardBuffer Load(string filename) { using (var stream = new FileStream(filename, FileMode.Open)) { using (var reader = new BinaryReader(stream)) { int maxx = reader.ReadInt32(); int maxy = reader.ReadInt32(); var buffer = new ClipboardBuffer(new PointInt32(maxx, maxy)); buffer.Name = Path.GetFileNameWithoutExtension(filename); for (int x = 0; x < buffer.Size.W; x++) { for (int y = 0; y < buffer.Size.H; y++) { var tile = new Tile(); tile.IsActive = reader.ReadBoolean(); if (tile.IsActive) { tile.Type = reader.ReadByte(); if (WorldSettings.Tiles[tile.Type].IsFramed) tile.Frame = new PointShort(reader.ReadInt16(), reader.ReadInt16()); else tile.Frame = new PointShort(-1, -1); } tile.IsLighted = reader.ReadBoolean(); if (reader.ReadBoolean()) { tile.Wall = reader.ReadByte(); } if (reader.ReadBoolean()) { tile.Liquid = reader.ReadByte(); tile.IsLava = reader.ReadBoolean(); } buffer.Tiles[x, y] = tile; } } for (int chestIndex = 0; chestIndex < World.MaxChests; chestIndex++) { if (reader.ReadBoolean()) { var chest = new Chest(); chest.Location = new PointInt32(reader.ReadInt32(), reader.ReadInt32()); for (int slot = 0; slot < Chest.MaxItems; slot++) { var item = new Item(); byte stackSize = reader.ReadByte(); if (stackSize > 0) { string itemName = reader.ReadString(); item.ItemName = itemName; item.StackSize = stackSize; } chest.Items.Add(item); } //Chests[chestIndex] = chest; buffer.Chests.Add(chest); } } for (int signIndex = 0; signIndex < World.MaxSigns; signIndex++) { if (reader.ReadBoolean()) { string signText = reader.ReadString(); int x = reader.ReadInt32(); int y = reader.ReadInt32(); if (buffer.Tiles[x, y].IsActive && (buffer.Tiles[x, y].Type == 55 || buffer.Tiles[x, y].Type == 85)) // validate tile location { var sign = new Sign(); sign.Location = new PointInt32(x, y); sign.Text = signText; //Signs[signIndex] = sign; buffer.Signs.Add(sign); } } } int checkx = reader.ReadInt32(); int checky = reader.ReadInt32(); if (checkx == maxx && checky == maxy) return buffer; } } return null; }
public WriteableBitmap RenderBuffer(ClipboardBuffer buffer) { int width = buffer.Size.X; int height = buffer.Size.Y; var wbmap = new WriteableBitmap( width, height, 96, 96, PixelFormats.Bgr32, null); int stride = wbmap.BackBufferStride; int numpixelbytes = wbmap.PixelHeight * wbmap.PixelWidth * wbmap.Format.BitsPerPixel / 8; var pixels = new byte[numpixelbytes]; for (int x = 0; x < width; x++) { OnProgressChanged(this, new ProgressChangedEventArgs( (int)(x / (double)width * 100.0), "Rendering Buffer...")); for (int y = 0; y < height; y++) { Tile tile = buffer.Tiles[x, y]; if (tile != null) { Color c = GetTileColor(y, tile); pixels[x * 4 + y * stride] = c.B; pixels[x * 4 + y * stride + 1] = c.G; pixels[x * 4 + y * stride + 2] = c.R; pixels[x * 4 + y * stride + 3] = c.A; //bmp.SetPixel(x - area.Left, y - area.Top, c); } } } wbmap.WritePixels(new Int32Rect(0, 0, wbmap.PixelWidth, wbmap.PixelHeight), pixels, wbmap.PixelWidth * wbmap.Format.BitsPerPixel / 8, 0); OnProgressChanged(this, new ProgressChangedEventArgs(0, "Render Complete.")); return wbmap; }
public void PasteBufferIntoWorld(World world, ClipboardBuffer buffer, PointInt32 anchor) { for (int x = 0; x < buffer.Size.W; x++) { for (int y = 0; y < buffer.Size.H; y++) { if (world.IsPointInWorld(x + anchor.X, y + anchor.Y)) { HistMan.AddTileToBuffer(x + anchor.X, y + anchor.Y, ref world.Tiles[x + anchor.X, y + anchor.Y]); Tile curTile = (Tile)buffer.Tiles[x, y].Clone(); // Remove overwritten chests data if (world.Tiles[x + anchor.X, y + anchor.Y].Type == 21) { var data = world.GetChestAtTile(x + anchor.X, y + anchor.Y); if (data != null) { world.Chests.Remove(data); } } // Remove overwritten sign data if (world.Tiles[x + anchor.X, y + anchor.Y].Type == 55 || world.Tiles[x + anchor.X, y + anchor.Y].Type == 85) { var data = world.GetSignAtTile(x + anchor.X, y + anchor.Y); if (data != null) { world.Signs.Remove(data); } } // Add new chest data if (curTile.Type == 21) { if (world.GetChestAtTile(x + anchor.X, y + anchor.Y) == null) { var data = buffer.GetChestAtTile(x, y); if (data != null) // allow? chest copying may not work... { // Copied chest var newChest = Utility.DeepCopy(data); newChest.Location = new PointInt32(x + anchor.X, y + anchor.Y); world.Chests.Add(newChest); } else { // Empty chest world.Chests.Add(new Chest(new PointInt32(x + anchor.X, y + anchor.Y))); } } } // Add new sign data if (curTile.Type == 55 || curTile.Type == 85) { if (world.GetSignAtTile(x + anchor.X, y + anchor.Y) == null) { var data = buffer.GetSignAtTile(x, y); if (data != null) { // Copied sign var newSign = Utility.DeepCopy(data); newSign.Location = new PointInt32(x + anchor.X, y + anchor.Y); world.Signs.Add(newSign); } else { world.Signs.Add(new Sign("", new PointInt32(x + anchor.X, y + anchor.Y))); } } } world.Tiles[x + anchor.X, y + anchor.Y] = curTile; } } } HistMan.AddBufferToHistory(); }
public WriteableBitmap RenderBuffer(ClipboardBuffer buffer, bool isRenderedLayer = false) { int width = buffer.Size.W; int height = buffer.Size.H; var wbmap = new WriteableBitmap( width, height, 96, 96, System.Windows.Media.PixelFormats.Bgr32, null); UpdateWorldImage(new RectI(0, 0, buffer.Size), isRenderedLayer, "Buffer Render Complete.", wbmap); return wbmap; }
public static ClipboardBuffer Load(string filename) { using (var stream = new FileStream(filename, FileMode.Open)) { using (var reader = new BinaryReader(stream)) { int maxx = reader.ReadInt32(); int maxy = reader.ReadInt32(); var buffer = new ClipboardBuffer(new PointInt32(maxx, maxy)); buffer.Name = Path.GetFileNameWithoutExtension(filename); for (int x = 0; x < buffer.Size.W; x++) { for (int y = 0; y < buffer.Size.H; y++) { var tile = new Tile(); tile.IsActive = reader.ReadBoolean(); if (tile.IsActive) { tile.Type = reader.ReadByte(); if (WorldSettings.Tiles[tile.Type].IsFramed) { tile.Frame = new PointShort(reader.ReadInt16(), reader.ReadInt16()); } else { tile.Frame = new PointShort(-1, -1); } } tile.IsLighted = reader.ReadBoolean(); if (reader.ReadBoolean()) { tile.Wall = reader.ReadByte(); } if (reader.ReadBoolean()) { tile.Liquid = reader.ReadByte(); tile.IsLava = reader.ReadBoolean(); } buffer.Tiles[x, y] = tile; } } for (int chestIndex = 0; chestIndex < World.MaxChests; chestIndex++) { if (reader.ReadBoolean()) { var chest = new Chest(); chest.Location = new PointInt32(reader.ReadInt32(), reader.ReadInt32()); for (int slot = 0; slot < Chest.MaxItems; slot++) { var item = new Item(); byte stackSize = reader.ReadByte(); if (stackSize > 0) { string itemName = reader.ReadString(); item.ItemName = itemName; item.StackSize = stackSize; } chest.Items.Add(item); } //Chests[chestIndex] = chest; buffer.Chests.Add(chest); } } for (int signIndex = 0; signIndex < World.MaxSigns; signIndex++) { if (reader.ReadBoolean()) { string signText = reader.ReadString(); int x = reader.ReadInt32(); int y = reader.ReadInt32(); if (buffer.Tiles[x, y].IsActive && (buffer.Tiles[x, y].Type == 55 || buffer.Tiles[x, y].Type == 85)) // validate tile location { var sign = new Sign(); sign.Location = new PointInt32(x, y); sign.Text = signText; //Signs[signIndex] = sign; buffer.Signs.Add(sign); } } } int checkx = reader.ReadInt32(); int checky = reader.ReadInt32(); if (checkx == maxx && checky == maxy) { return(buffer); } } } return(null); }
public void PasteBufferIntoWorld(World world, ClipboardBuffer buffer, PointInt32 anchor) { for (int x = 0; x < buffer.Size.X; x++) { for (int y = 0; y < buffer.Size.Y; y++) { if (world.IsPointInWorld(x + anchor.X, y + anchor.Y)) { HistMan.AddTileToBuffer(x + anchor.X, y + anchor.Y, ref world.Tiles[x + anchor.X, y + anchor.Y]); Tile curTile = (Tile)buffer.Tiles[x, y].Clone(); // Remove overwritten chests data if (world.Tiles[x + anchor.X, y + anchor.Y].Type == 21) { var data = world.GetChestAtTile(x + anchor.X, y + anchor.Y); if (data != null) world.Chests.Remove(data); } // Remove overwritten sign data if (world.Tiles[x + anchor.X, y + anchor.Y].Type == 55 || world.Tiles[x + anchor.X, y + anchor.Y].Type == 85) { var data = world.GetSignAtTile(x + anchor.X, y + anchor.Y); if (data != null) world.Signs.Remove(data); } // Add new chest data if (curTile.Type == 21) { if (world.GetChestAtTile(x + anchor.X, y + anchor.Y) == null) { var data = buffer.GetChestAtTile(x, y); if (data != null) // allow? chest copying may not work... { // Copied chest var newChest = Utility.DeepCopy(data); newChest.Location = new PointInt32(x + anchor.X, y + anchor.Y); world.Chests.Add(newChest); } else { // Empty chest world.Chests.Add(new Chest(new PointInt32(x + anchor.X, y + anchor.Y))); } } } // Add new sign data if (curTile.Type == 55 || curTile.Type == 85) { if (world.GetSignAtTile(x + anchor.X, y + anchor.Y) == null) { var data = buffer.GetSignAtTile(x, y); if (data != null) { // Copied sign var newSign = Utility.DeepCopy(data); newSign.Location = new PointInt32(x + anchor.X, y + anchor.Y); world.Signs.Add(newSign); } else { world.Signs.Add(new Sign("", new PointInt32(x + anchor.X, y + anchor.Y))); } } } world.Tiles[x + anchor.X, y + anchor.Y] = curTile; } } } HistMan.AddBufferToHistory(); }