public void SetMap(Map Map) { this.MapData = Map; Cursor.SetPosition(21, 39); AutotileIndex = -1; AutotileCombination = -1; TilesetIndex = 0; TileStartX = 0; TileStartY = 0; TileEndX = 0; TileEndY = 0; for (int i = 0; i < this.AutotileContainers.Count; i++) { if (this.AutotileContainers[i] is CollapsibleContainer) { (this.AutotileContainers[i] as CollapsibleContainer).Dispose(); } } this.AutotileContainers.Clear(); if (SingleAutotileContainer is CollapsibleContainer) { SingleAutotileContainer.Dispose(); } SingleAutotileContainer = null; Bitmap singles = null; SingleAutotileCount = MapData.AutotileIDs.FindAll(id => Data.Autotiles[id].Format == AutotileFormat.Single).Count; if (SingleAutotileCount > 0) { SingleAutotileContainer = new CollapsibleContainer(MainStackPanel); SingleAutotileContainer.SetText("Single Autotiles"); SingleAutotileContainer.SetMargin(0, 0, 0, 8); SingleAutotileContainer.OnCollapsedChanged += delegate(BaseEventArgs e) { UpdateCursor(); }; singles = new Bitmap(263, 33 + 33 * (int)Math.Floor(SingleAutotileCount / 8d)); singles.Unlock(); SingleAutotileContainer.SetSize(MainContainer.Size.Width - 13, singles.Height + 23); PictureBox image = new PictureBox(SingleAutotileContainer); image.SetPosition(0, 23); image.Sprite.Bitmap = singles; image.SetSize(image.Sprite.Bitmap.Width, image.Sprite.Bitmap.Height); } int SingleIndex = 0; for (int i = 0; i < MapData.AutotileIDs.Count; i++) { int autotileid = MapData.AutotileIDs[i]; Autotile autotile = Data.Autotiles[autotileid]; if (autotile.Format == AutotileFormat.Single) { int x = 33 * (SingleIndex % 8); int y = 33 * (int)Math.Floor(SingleIndex / 8d); singles.Build(x, y, autotile.AutotileBitmap, new Rect(0, 0, 32, 32)); AutotileContainers.Add(SingleIndex); SingleIndex++; continue; } CollapsibleContainer c = new CollapsibleContainer(MainStackPanel); c.SetText(autotile.Name); c.SetMargin(0, 0, 0, 8); c.OnCollapsedChanged += delegate(BaseEventArgs e) { UpdateCursor(); }; c.SetSize(MainContainer.Size.Width - 13, 87); c.ObjectData = i; AutotileContainers.Add(c); PictureBox image = new PictureBox(c); image.SetPosition(0, 23); AutotileFormat f = autotile.Format; Bitmap bmp = new Bitmap(263, 64); bmp.Unlock(); for (int j = 0; j < 4; j++) { // Constructs a bitmap with the four corner autotile pieces. int x = 0, y = 0; if (j == 0) { y = 32; } else if (j == 1) { x = (f == AutotileFormat.RMVX ? 32 : 64); y = 32; } else if (j == 2) { y = (f == AutotileFormat.RMVX ? 64 : 96); } else if (j == 3) { x = (f == AutotileFormat.RMVX ? 32 : 64); y = (f == AutotileFormat.RMVX ? 64 : 96); } bmp.Build(32 * (j % 2), 32 * (int)Math.Floor(j / 2d), autotile.AutotileBitmap, new Rect(x, y, 32, 32)); } image.Sprite.Bitmap = bmp; image.SetSize(image.Sprite.Bitmap.Width, image.Sprite.Bitmap.Height); DrawQuickAutotiles(i); bmp.Lock(); } if (singles != null) { singles.Lock(); } for (int i = 0; i < this.TilesetContainers.Count; i++) { this.TilesetContainers[i].Dispose(); } this.TilesetContainers.Clear(); this.TilesetImages.Clear(); for (int i = 0; i < MapData.TilesetIDs.Count; i++) { int tilesetid = MapData.TilesetIDs[i]; Tileset tileset = Data.Tilesets[tilesetid]; CollapsibleContainer c = new CollapsibleContainer(MainStackPanel); c.SetText(tileset.Name); c.SetMargin(0, 0, 0, 8); c.OnCollapsedChanged += delegate(BaseEventArgs e) { UpdateCursor(); }; c.SetSize(MainContainer.Size.Width - 13, tileset.TilesetListBitmap.Height + 23); TilesetContainers.Add(c); PictureBox image = new PictureBox(c); image.SetPosition(0, 23); image.Sprite.Bitmap = tileset.TilesetListBitmap; image.Sprite.DestroyBitmap = false; image.SetSize(image.Sprite.Bitmap.Width, image.Sprite.Bitmap.Height); TilesetImages.Add(image); } }
public Autotile(Dictionary <string, object> Data) { if (Data.ContainsKey("^c")) { if ((string)Data["^c"] != "MKD::Autotile") { throw new Exception("Invalid class - Expected class of type MKD::Autotile but got " + (string)Data["^c"] + "."); } } else { throw new Exception("Could not find a ^c key to identify this class."); } this.ID = Convert.ToInt32(Data["@id"]); this.Name = (string)Data["@name"]; this.GraphicName = (string)Data["@graphic_name"]; string format = (string)Data["@format"]; if (format == ":legacy") { this.Format = AutotileFormat.Legacy; } else if (format == ":full_corners") { this.Format = AutotileFormat.FullCorners; } else if (format == ":single") { this.Format = AutotileFormat.Single; } else if (format == ":rmvx") { this.Format = AutotileFormat.RMVX; } else { throw new Exception("Invalid autotile format."); } Priorities = new List <int?>(); foreach (object o in ((JArray)Data["@priorities"]).ToObject <List <object> >()) { if (o is null) { Priorities.Add(null); } else { Priorities.Add(Convert.ToInt32(o)); } } Passabilities = new List <Passability>(); foreach (object o in ((JArray)Data["@passabilities"]).ToObject <List <object> >()) { Passabilities.Add((Passability)Convert.ToInt32(o)); } Tags = new List <int?>(); foreach (object o in ((JArray)Data["@tags"]).ToObject <List <object> >()) { if (o is null) { Tags.Add(null); } else { Tags.Add(Convert.ToInt32(o)); } } this.AnimateSpeed = Convert.ToInt32(Data["@animate_speed"]); QuickIDs = new List <int?>() { null, null, null, null, null, null }; if (Data.ContainsKey("@quick_ids")) { List <object> ids = ((JArray)Data["@quick_ids"]).ToObject <List <object> >(); for (int i = 0; i < 6; i++) { if (ids[i] != null) { QuickIDs[i] = Convert.ToInt32(ids[i]); } } } // Make sure the three arrays are just as big; trailing nulls may be left out if the data is edited externally int maxcount = Math.Max(Math.Max(Passabilities.Count, Priorities.Count), Tags.Count); this.Passabilities.AddRange(new Passability[maxcount - Passabilities.Count]); this.Priorities.AddRange(new int?[maxcount - Priorities.Count]); this.Tags.AddRange(new int?[maxcount - Tags.Count]); this.CreateBitmap(); }