public void DrawAutotile(int Layer, int X, int Y, int AutotileID, int TileID, int Frame)
        {
            Autotile autotile = Data.Autotiles[AutotileID];
            int      AnimX    = 0;

            if (autotile.Format == AutotileFormat.Single)
            {
                AnimX = (Frame * 32) % autotile.AutotileBitmap.Width;
                this.Sprites[Layer.ToString()].Bitmap.Build(new Rect(32 * X, 32 * Y, 32, 32), autotile.AutotileBitmap,
                                                            new Rect(AnimX, 0, 32, 32));
            }
            else
            {
                AnimX = (Frame * 96) % autotile.AutotileBitmap.Width;
                List <int> Tiles = Autotile.AutotileCombinations[autotile.Format][TileID];
                for (int i = 0; i < 4; i++)
                {
                    this.Sprites[Layer.ToString()].Bitmap.Build(
                        new Rect(
                            32 * X + 16 * (i % 2),
                            32 * Y + 16 * (int)Math.Floor(i / 2d),
                            16,
                            16
                            ),
                        autotile.AutotileBitmap,
                        new Rect(
                            16 * (Tiles[i] % 6) + AnimX,
                            16 * (int)Math.Floor(Tiles[i] / 6d),
                            16,
                            16
                            )
                        );
                }
            }
        }
Exemple #2
0
 public void SetAutotile(Autotile Autotile)
 {
     if (this.Autotile != Autotile)
     {
         this.Autotile = Autotile;
         Redraw();
     }
 }
Exemple #3
0
        public void DrawQuickAutotiles(int AutotileIndex)
        {
            int      autotileid = MapData.AutotileIDs[AutotileIndex];
            Autotile autotile   = Data.Autotiles[autotileid];
            bool     locked     = ((AutotileContainers[AutotileIndex] as CollapsibleContainer).Widgets[0] as PictureBox).Sprite.Bitmap.Locked;

            if (locked)
            {
                ((AutotileContainers[AutotileIndex] as CollapsibleContainer).Widgets[0] as PictureBox).Sprite.Bitmap.Unlock();
            }
            if (autotile.Format == AutotileFormat.Single)
            {
                throw new Exception("Can't draw quick autotiles for autotiles with a format of 'Single'");
            }
            for (int i = 0; i < autotile.QuickIDs.Count; i++)
            {
                int    x   = 66 + 33 * i;
                int    y   = 16;
                Bitmap bmp = new Bitmap(32, 32);
                bmp.Unlock();
                if (autotile.QuickIDs[i] == null)
                {
                    bmp.DrawRect(0, 0, 32, 32, new Color(19, 36, 55));
                    bmp.DrawRect(1, 1, 30, 30, new Color(19, 36, 55));
                    bmp.FillRect(7, 21, 3, 3, new Color(19, 36, 55));
                    bmp.FillRect(14, 21, 3, 3, new Color(19, 36, 55));
                    bmp.FillRect(21, 21, 3, 3, new Color(19, 36, 55));
                }
                else
                {
                    List <int> Tiles = Autotile.AutotileCombinations[autotile.Format][(int)autotile.QuickIDs[i]];
                    for (int j = 0; j < 4; j++)
                    {
                        bmp.Build(new Rect(16 * (j % 2), 16 * (int)Math.Floor(j / 2d), 16, 16), autotile.AutotileBitmap,
                                  new Rect(16 * (Tiles[j] % 6), 16 * (int)Math.Floor(Tiles[j] / 6d), 16, 16));
                    }
                }
                bmp.Lock();
                ((AutotileContainers[AutotileIndex] as CollapsibleContainer).Widgets[0] as PictureBox).Sprite.Bitmap.Build(x, y, bmp);
                bmp.Dispose();
            }
            if (locked)
            {
                ((AutotileContainers[AutotileIndex] as CollapsibleContainer).Widgets[0] as PictureBox).Sprite.Bitmap.Lock();
            }
        }
Exemple #4
0
        public static Bitmap CreateMapPreview(Map Map)
        {
            Bitmap bmp = new Bitmap(Map.Width * 32, Map.Height * 32);

            bmp.Unlock();
            for (int layer = 0; layer < Map.Layers.Count; layer++)
            {
                for (int y = 0; y < Map.Height; y++)
                {
                    for (int x = 0; x < Map.Width; x++)
                    {
                        TileData tile = Map.Layers[layer].Tiles[x + y * Map.Width];
                        if (tile == null)
                        {
                            continue;
                        }
                        if (tile.TileType == TileType.Tileset)
                        {
                            Bitmap tilesetimage = Data.Tilesets[Map.TilesetIDs[tile.Index]].TilesetBitmap;
                            int    tilesetx     = tile.ID % 8;
                            int    tilesety     = (int)Math.Floor(tile.ID / 8d);
                            bmp.Build(new Rect(x * 32, y * 32, 32, 32), tilesetimage, new Rect(tilesetx * 32, tilesety * 32, 32, 32));
                        }
                        else if (tile.TileType == TileType.Autotile)
                        {
                            Autotile autotile = Data.Autotiles[Map.AutotileIDs[tile.Index]];
                            if (autotile.Format == AutotileFormat.Single)
                            {
                                bmp.Build(new Rect(x * 32, y * 32, 32, 32), autotile.AutotileBitmap, new Rect(0, 0, 32, 32));
                            }
                            else
                            {
                                List <int> Tiles = Autotile.AutotileCombinations[autotile.Format][tile.ID];
                                for (int i = 0; i < 4; i++)
                                {
                                    bmp.Build(new Rect(x * 32 + 16 * (i % 2), y * 32 + 16 * (int)Math.Floor(i / 2d), 16, 16), autotile.AutotileBitmap,
                                              new Rect(16 * (Tiles[i] % 6), 16 * (int)Math.Floor(Tiles[i] / 6d), 16, 16));
                                }
                            }
                        }
                    }
                }
            }
            bmp.Lock();
            return(bmp);
        }
        public void AddAutotile(BaseEventArgs e)
        {
            AutotilePicker picker = new AutotilePicker(Map);

            picker.OnClosed += delegate(BaseEventArgs e2)
            {
                bool update = false;
                if (Map.AutotileIDs.Count != picker.ResultIDs.Count)
                {
                    update = true;
                }
                if (!update)
                {
                    for (int i = 0; i < picker.ResultIDs.Count; i++)
                    {
                        if (picker.ResultIDs[i] != Map.AutotileIDs[i])
                        {
                            update = true;
                            break;
                        }
                    }
                }
                if (update)
                {
                    Map.AutotileIDs = picker.ResultIDs;
                    List <ListItem> autotileitems = new List <ListItem>();
                    for (int i = 0; i < this.Map.AutotileIDs.Count; i++)
                    {
                        int      id       = this.Map.AutotileIDs[i];
                        Autotile autotile = Data.Autotiles[id];
                        autotileitems.Add(new ListItem(autotile));
                    }
                    Autotiles.SetItems(autotileitems);
                }
            };
        }
Exemple #6
0
 public void SelectTile(int ContainerIndex, int TileX, int TileY)
 {
     if (ContainerIndex < AutotileContainers.Count) // Autotile
     {
         if (ContainerIndex == 0 && SingleAutotileCount > 0)
         {
             if (TileX + TileY * 8 >= SingleAutotileCount)
             {
                 return;
             }
             for (int i = 0; i < AutotileContainers.Count; i++)
             {
                 if (AutotileContainers[i] is int && (int)AutotileContainers[i] == TileX + TileY * 8)
                 {
                     this.AutotileIndex = i;
                 }
             }
         }
         else
         {
             int  container = SingleAutotileCount == 0 ? 0 : 1;
             int  idx       = -1;
             bool found     = false;
             for (int i = 0; i < AutotileContainers.Count; i++)
             {
                 if (AutotileContainers[i] is CollapsibleContainer)
                 {
                     if (container == ContainerIndex)
                     {
                         found = true;
                         idx   = (int)(AutotileContainers[i] as CollapsibleContainer).ObjectData;
                         break;
                     }
                     else
                     {
                         container++;
                     }
                 }
             }
             if (found)
             {
                 if (TileX > 1)
                 {
                     Autotile autotile = Data.Autotiles[MapData.AutotileIDs[idx]];
                     if (autotile.QuickIDs[TileX - 2] is null)
                     {
                         AutotilePickerMap atp = new AutotilePickerMap();
                         atp.SetAutotile(autotile);
                         atp.OnClosed += delegate(BaseEventArgs e)
                         {
                             if (atp.SelectedTileID != -1)
                             {
                                 this.AutotileIndex           = idx;
                                 this.AutotileCombination     = TileX - 2;
                                 autotile.QuickIDs[TileX - 2] = atp.SelectedTileID;
                                 DrawQuickAutotiles(idx);
                                 UpdateCursor();
                             }
                         };
                     }
                     else
                     {
                         if (TimerExists("double") && !TimerPassed("double") && DoubleClickIndex == idx && DoubleClickX == TileX)
                         {
                             AutotilePickerMap atp = new AutotilePickerMap();
                             atp.SetAutotile(autotile);
                             atp.OnClosed += delegate(BaseEventArgs e)
                             {
                                 if (atp.SelectedTileID != -1)
                                 {
                                     this.AutotileIndex           = idx;
                                     this.AutotileCombination     = TileX - 2;
                                     autotile.QuickIDs[TileX - 2] = atp.SelectedTileID;
                                     DrawQuickAutotiles(idx);
                                     UpdateCursor();
                                 }
                             };
                         }
                         if (TimerExists("double"))
                         {
                             DestroyTimer("double");
                         }
                         if (!TimerExists("double"))
                         {
                             SetTimer("double", 300);
                             DoubleClickIndex         = idx;
                             DoubleClickX             = TileX;
                             this.AutotileIndex       = idx;
                             this.AutotileCombination = TileX - 2;
                         }
                     }
                 }
                 else
                 {
                     this.AutotileIndex       = idx;
                     this.AutotileCombination = -1;
                 }
             }
             else
             {
                 throw new Exception("Couldn't find autotile index of the selected container.");
             }
         }
         this.TilesetIndex = this.TileStartX = this.TileEndX = this.TileStartY = this.TileEndY = -1;
     }
     else // Tileset
     {
         this.AutotileIndex       = -1;
         this.AutotileCombination = -1;
         this.TilesetIndex        = ContainerIndex - AutotileContainers.Count;
         this.TileStartX          = this.TileEndX = TileX;
         this.TileStartY          = this.TileEndY = TileY;
     }
     MapViewer.SelectionOnMap = false;
     if (EraserButton.Selected)
     {
         EraserButton.SetSelected(false);
     }
     if (SelectButton.Selected)
     {
         SelectButton.SetSelected(false);
         PencilButton.SetSelected(true);
     }
     UpdateCursor();
 }
Exemple #7
0
        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 MapPropertiesWindow(Map Map)
        {
            this.OldMap = Map;
            this.Map    = Map.Clone();
            this.SetTitle($"Map Properties - {Utilities.Digits(Map.ID, 3)}: {Map.DevName}");
            MinimumSize = MaximumSize = new Size(540, 460);
            SetSize(MaximumSize);
            this.Center();
            Label settings = new Label(this);

            settings.SetText("Info");
            settings.SetFont(Font.Get("Fonts/Ubuntu-B", 14));
            settings.SetPosition(12, 26);

            GroupBox box1 = new GroupBox(this);

            box1.SetPosition(19, 47);
            box1.SetSize(450, 203);

            Font f = Font.Get("Fonts/ProductSans-M", 12);

            Label namelabel = new Label(box1);

            namelabel.SetText("Working Name:");
            namelabel.SetFont(f);
            namelabel.SetPosition(7, 6);
            MapName = new TextBox(box1);
            MapName.SetPosition(6, 22);
            MapName.SetSize(136, 27);
            MapName.SetInitialText(Map.DevName);
            MapName.OnTextChanged += delegate(BaseEventArgs e)
            {
                this.Map.DevName = MapName.Text;
            };

            Label displaynamelabel = new Label(box1);

            displaynamelabel.SetText("In-game Name:");
            displaynamelabel.SetFont(f);
            displaynamelabel.SetPosition(7, 52);
            DisplayName = new TextBox(box1);
            DisplayName.SetPosition(6, 68);
            DisplayName.SetSize(136, 27);
            DisplayName.SetInitialText(Map.DisplayName);
            DisplayName.OnTextChanged += delegate(BaseEventArgs e)
            {
                this.Map.DisplayName = DisplayName.Text;
            };

            Label widthlabel = new Label(box1);

            widthlabel.SetText("Width:");
            widthlabel.SetFont(f);
            widthlabel.SetPosition(7, 99);
            Width = new NumericBox(box1);
            Width.SetPosition(6, 115);
            Width.MinValue = 1;
            Width.MaxValue = 255;
            Width.SetSize(66, 27);
            Width.SetValue(this.Map.Width);
            Width.OnValueChanged += delegate(BaseEventArgs e)
            {
                this.Map.Width = Width.Value;
            };

            Label heightlabel = new Label(box1);

            heightlabel.SetText("Height:");
            heightlabel.SetFont(f);
            heightlabel.SetPosition(78, 99);
            Height = new NumericBox(box1);
            Height.SetPosition(77, 115);
            Height.MinValue = 1;
            Height.MaxValue = 255;
            Height.SetSize(66, 27);
            Height.SetValue(this.Map.Height);
            Height.OnValueChanged += delegate(BaseEventArgs e)
            {
                this.Map.Height = Height.Value;
            };

            Tilesets = new ListBox(box1);
            Tilesets.SetPosition(162, 22);
            List <ListItem> tilesetitems = new List <ListItem>();

            for (int i = 0; i < this.Map.TilesetIDs.Count; i++)
            {
                int     id      = this.Map.TilesetIDs[i];
                Tileset tileset = Data.Tilesets[id];
                tilesetitems.Add(new ListItem(tileset));
            }
            Tilesets.SetItems(tilesetitems);
            Tilesets.SetButtonText("Add Tileset");
            Tilesets.ListDrawer.OnButtonClicked += AddTileset;

            Autotiles = new ListBox(box1);
            Autotiles.SetPosition(312, 22);
            List <ListItem> autotileitems = new List <ListItem>();

            for (int i = 0; i < this.Map.AutotileIDs.Count; i++)
            {
                int      id       = this.Map.AutotileIDs[i];
                Autotile autotile = Data.Autotiles[id];
                autotileitems.Add(new ListItem(autotile));
            }
            Autotiles.SetItems(autotileitems);
            Autotiles.SetButtonText("Add Autotile");
            Autotiles.ListDrawer.OnButtonClicked += AddAutotile;

            Label tilesetslabel = new Label(box1);

            tilesetslabel.SetText("Tilesets:");
            tilesetslabel.SetFont(f);
            tilesetslabel.SetPosition(163, 6);

            Label autotileslabel = new Label(box1);

            autotileslabel.SetText("Autotiles:");
            autotileslabel.SetFont(f);
            autotileslabel.SetPosition(313, 6);

            CreateButton("Cancel", Cancel);
            CreateButton("OK", OK);
        }
Exemple #9
0
        public void LoadGame(string path)
        {
            bool flag = false;

            // First we f**k current scene
            ClearAll();


            // Load layers
            if (lt.dtv.Nodes.Count > 0)
            {
                lt.dtv.Nodes[0].Nodes.Clear();
            }

            // Prepare XML serializer
            // Then we load raw data
            Root          root    = new Root();
            XmlSerializer ser     = new XmlSerializer(typeof(Root), Form1.reflectedTypes.ToArray());
            StreamReader  w       = new StreamReader(path);
            Root          rawData = (Root)ser.Deserialize(w);

            // First load back room itself
            Form1.width           = (int)rawData.Room.Size.X;
            Form1.height          = (int)rawData.Room.Size.Y;
            Form1.ActiveForm.Text = "Simplex RPG Engine / " + rawData.Room.Name;

            currentRoom = rawData.Room;

            // if (currentRoom != null)
            // {
            GameRoom gr = (GameRoom)Activator.CreateInstance(currentRoom.GetType());

            selectedLayer = gr.Layers[0];
            int currentDepth = 0;

            foreach (RoomLayer rl in gr.Layers)
            {
                DarkTreeNode dtn = new DarkTreeNode(rl.Name);
                dtn.Tag = dtn;
                dtn.Tag = "";

                if (rl.LayerType == RoomLayer.LayerTypes.typeObject)
                {
                    dtn.Icon = (System.Drawing.Bitmap)Properties.Resources.ResourceManager.GetObject("WorldLocal_16x");
                }
                else if (rl.LayerType == RoomLayer.LayerTypes.typeAsset)
                {
                    dtn.Icon = (System.Drawing.Bitmap)Properties.Resources.ResourceManager.GetObject("Image_16x");
                }
                else
                {
                    dtn.Icon = (System.Drawing.Bitmap)Properties.Resources.ResourceManager.GetObject("MapLineLayer_16x");
                }

                rl.Depth      = currentDepth;
                currentDepth += 100;
                roomLayers.Add(rl);
                lt?.dtv.Nodes[0].Nodes.Add(dtn);
            }

            // we need to initialize layers by type
            foreach (RoomLayer rl in roomLayers)
            {
                if (rl.LayerType == RoomLayer.LayerTypes.typeTile)
                {
                    // Start with empty cell data and load stuff later on
                    ((TileLayer)rl).Data = new int[(int)currentRoom.Size.X / 32, (int)currentRoom.Size.Y / 32];

                    // Now select correct tileset and assign it to this.. well tileset
                    Tileset tl = tilesets.FirstOrDefault(x => x.Name == ((TileLayer)rl).TilelistName);

                    // this can fail so check for that
                    if (tl != null)
                    {
                        // also we need to load textures for the tileset
                        // tl.AutotileLib =

                        // all good
                        ((TileLayer)rl).Tileset = tl;
                    }
                }
            }


            // Time to load babies
            foreach (GameObject g in rawData.Objects)
            {
                Spritesheet s = Sprites.FirstOrDefault(x => x.Name == g.Sprite.TextureSource);

                g.Sprite.Texture            = s.Texture;
                g.Sprite.ImageRectangle     = new Microsoft.Xna.Framework.Rectangle(0, 0, s.CellWidth, s.CellHeight);
                g.Sprite.TextureRows        = s.Rows;
                g.Sprite.TextureCellsPerRow = s.Texture.Width / s.CellWidth;
                g.Sprite.ImageSize          = new Vector2(s.CellWidth, s.CellHeight);
                g.Sprite.FramesCount        = (s.Texture.Width / s.CellWidth) * (s.Texture.Height / s.CellHeight) - 1;
                g.FramesCount  = g.Sprite.FramesCount - 1;
                g.Sprite.cellW = s.CellHeight;
                g.Sprite.cellH = s.CellWidth;

                RoomLayer rt = roomLayers.FirstOrDefault(x => x.Name == g.LayerName);
                g.Layer = (ObjectLayer)rt;

                g.Sprite.UpdateImageRectangle();
                g.UpdateState();
                g.UpdateColliders();

                // Need to give object OriginalType !!!
                g.OriginalType = Type.GetType(g.TypeString);

                g.EvtCreate();
                g.EvtLoad();

                g.Layer.Objects.Add(g);
                sh.RegisterObject(g);
            }

            // Load tiles
            foreach (Tile t in rawData.Tiles)
            {
                RoomLayer correctLayer = roomLayers.FirstOrDefault(x => x.Name == t.TileLayerName);

                if (correctLayer != null)
                {
                    TileLayer crt = (TileLayer)correctLayer;
                    t.TileLayer = crt;
                    crt.Tiles.Add(t);
                }
                else
                {
                    Debug.WriteLine("Tile could not be loaded - TileLayerName is wrong");
                }
            }

            // Now update all tiles
            Texture2D ttt = Editor.Content.Load <Texture2D>(Path.GetFullPath("../../../SimplexRpgEngine3/Content/bin/Windows/Sprites/Tilesets/" + "tileset0"));

            foreach (RoomLayer rl in roomLayers)
            {
                if (rl is TileLayer)
                {
                    TileLayer crt = (TileLayer)rl;

                    foreach (Tile t in crt.Tiles)
                    {
                        t.SourceTexture = ttt;
                        Autotile.UpdateTile(t, crt);
                    }
                }
            }

            w.Close();
        }
Exemple #10
0
        public void GameClicked(MouseEventArgs e, MouseButtons mb)
        {
            KeyboardState ks = Keyboard.GetState();

            if ((mb & MouseButtons.Left) != 0)
            {
                Input.PressedButtonsOnce[0] = 1; Sgml.LastButton = Sgml.MouseButtons.Left;
            }
            if ((mb & MouseButtons.Right) != 0)
            {
                Input.PressedButtonsOnce[1] = 1; Sgml.LastButton = Sgml.MouseButtons.mb_right;
            }
            if ((mb & MouseButtons.Middle) != 0)
            {
                Input.PressedButtonsOnce[2] = 1; Sgml.LastButton = Sgml.MouseButtons.Middle;
            }
            if ((mb & MouseButtons.None) != 0)
            {
                Input.PressedButtonsOnce[3] = 1;
            }
            if ((mb & MouseButtons.XButton1) != 0)
            {
                Input.PressedButtonsOnce[5] = 1; Sgml.LastButton = Sgml.MouseButtons.mb_x1;
            }
            if ((mb & MouseButtons.XButton2) != 0)
            {
                Input.PressedButtonsOnce[6] = 1; Sgml.LastButton = Sgml.MouseButtons.mb_x2;
            }


            Input.CheckAnyPressed();

            MousePositionTranslated = cam.Camera.ScreenToWorld(MousePosition);

            if (mb == MouseButtons.Left)
            {
                goodBoy = true;
                Vector2 vec = MousePositionTranslated;


                if (DrawGrid)
                {
                    vec = new Vector2((int)vec.X / 32 * 32, (int)vec.Y / 32 * 32);
                }

                if (ks.IsKeyDown(Keys.LeftControl))
                {
                    selectionRectangle.Width  = -selectionRectangle.X + vec.X;
                    selectionRectangle.Height = -selectionRectangle.Y + vec.Y;
                }
                else if (clickedObject == null)
                {
                    if (currentAutotile == null)
                    {
                        if (selectedRectangleObjects.Count > 0)
                        {
                            bool flag = true;

                            if (flag)
                            {
                                if (selectedRectangleObjects.Count > 0)
                                {
                                    foreach (GameObject o in selectedRectangleObjects)
                                    {
                                        o.Position += new Vector2(vec.X - MousePrevious.X, vec.Y - MousePrevious.Y);
                                    }
                                }
                            }
                            else
                            {
                                selectedRectangleObjects.Clear();
                            }
                        }
                        else
                        {
                            if (!ks.IsKeyDown(Keys.LeftShift) || Sgml.PlaceEmpty(vec))
                            {
                                if (Sgml.PlaceEmpty(vec))
                                {
                                    if (SelectedObject != null && selectedLayer.GetType() == typeof(ObjectLayer))
                                    {
                                        GameObject o = (GameObject)Activator.CreateInstance(SelectedObject);

                                        Spritesheet s = new Spritesheet();
                                        if (o.Sprite != null)
                                        {
                                            s = Sprites.FirstOrDefault(x => x.Name == o.Sprite.TextureSource);
                                        }

                                        if (!cmsOpen && SelectedObject != null)
                                        {
                                            if (stackedSteps.Count > 31)
                                            {
                                                stackedSteps.Pop();
                                            }

                                            stackedSteps.Push(SceneObjects.ToList());
                                            editorForm.updateStack(stackedSteps.Count);

                                            o.OriginalType = SelectedObject;
                                            o.TypeString   = SelectedObject.ToString();

                                            if (s == null)
                                            {
                                                Texture2D tx = ConvertToTexture(Properties.Resources.Question_16x,
                                                                                GraphicsDevice);


                                                o.Sprite                = new Sprite();
                                                o.Sprite.Texture        = tx;
                                                o.Sprite.ImageRectangle = new Microsoft.Xna.Framework.Rectangle(0, 0, 16, 16);
                                            }
                                            else
                                            {
                                                o.Sprite.Texture        = s.Texture;
                                                o.Sprite.ImageRectangle = new Microsoft.Xna.Framework.Rectangle(0, 0, s.CellWidth, s.CellHeight);
                                            }

                                            o.Sprite.TextureRows        = s.Rows;
                                            o.Sprite.TextureCellsPerRow = s.Texture.Width / s.CellWidth;
                                            o.Sprite.ImageSize          = new Vector2(s.CellWidth, s.CellHeight);
                                            o.Sprite.FramesCount        = Math.Max((s.Texture.Width / s.CellWidth) * (s.Texture.Height / s.CellHeight) - 1, 1);
                                            o.FramesCount  = Math.Max(o.Sprite.FramesCount - 1, 1);
                                            o.Sprite.cellW = s.CellHeight;
                                            o.Sprite.cellH = s.CellWidth;

                                            o.Position = new Vector2(vec.X - s.CellWidth / 2f, vec.Y - s.CellHeight / 2f);
                                            o.Sprite.ImageRectangle = new Microsoft.Xna.Framework.Rectangle(0, 0, s.CellWidth, s.CellHeight);
                                            o.LayerName             = selectedLayer.Name;
                                            o.Layer = (ObjectLayer)selectedLayer;

                                            Sgml.currentObject = o;
                                            o.EvtCreate();

                                            o.Layer.Objects.Add(o);
                                            SceneObjects.Add(o);
                                            sh.RegisterObject(o);
                                        }

                                        if (!ks.IsKeyDown(Keys.LeftShift))
                                        {
                                            clickedObject = o;
                                        }
                                    }
                                }
                            }

                            if (!Sgml.PlaceEmpty(vec) && !ks.IsKeyDown(Keys.LeftShift))
                            {
                                // there's something cool at the position already, time to grab it
                                GameObject collidingObject = Sgml.instance_place(vec);

                                if (collidingObject != null)
                                {
                                    clickedObject = collidingObject;
                                    helpVec       = new Vector2(-MousePositionTranslated.X + collidingObject.Position.X, -MousePositionTranslated.Y + collidingObject.Position.Y);
                                    clickedVec    = MousePositionTranslated;
                                }
                            }
                        }
                    }
                    else
                    {
                        Vector2 m = MousePositionTranslated;

                        Tile alreadyT = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == (int)m.X / 32 && x.PosY == (int)m.Y / 32);

                        if (alreadyT == null)
                        {
                            Tile t = new Tile();
                            t.Bits          = 16;
                            t.DrawRectangle = new Microsoft.Xna.Framework.Rectangle(0, 0, 32, 32);
                            t.SourceTexture = currentAutotile.Texture;
                            t.PosX          = (int)m.X / 32;
                            t.PosY          = (int)m.Y / 32;
                            t.TileLayer     = currentTileLayer;
                            t.TileLayerName = t.TileLayer.Name;

                            currentTileLayer.Tiles.Add(t);

                            t = Autotile.UpdateTile(t, currentTileLayer);

                            // basic 4
                            Tile t1 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX && x.PosY == t.PosY - 1); // N // 2
                            Tile t2 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX && x.PosY == t.PosY + 1); // S // 64
                            Tile t3 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX + 1 && x.PosY == t.PosY); // W // 16
                            Tile t4 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX - 1 && x.PosY == t.PosY); // S // 8

                            // extended 4
                            Tile t5 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX - 1 && x.PosY == t.PosY - 1); // EN // 1
                            Tile t6 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX + 1 && x.PosY == t.PosY - 1); // WN // 4
                            Tile t7 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX - 1 && x.PosY == t.PosY + 1); // ES // 32
                            Tile t8 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX + 1 && x.PosY == t.PosY + 1); // WS // 128

                            if (t1 != null)
                            {
                                Autotile.UpdateTile(t1, currentTileLayer);
                            }
                            if (t2 != null)
                            {
                                Autotile.UpdateTile(t2, currentTileLayer);
                            }
                            if (t3 != null)
                            {
                                Autotile.UpdateTile(t3, currentTileLayer);
                            }
                            if (t4 != null)
                            {
                                Autotile.UpdateTile(t4, currentTileLayer);
                            }

                            if (t5 != null)
                            {
                                Autotile.UpdateTile(t5, currentTileLayer);
                            }
                            if (t6 != null)
                            {
                                Autotile.UpdateTile(t6, currentTileLayer);
                            }
                            if (t7 != null)
                            {
                                Autotile.UpdateTile(t7, currentTileLayer);
                            }
                            if (t8 != null)
                            {
                                Autotile.UpdateTile(t8, currentTileLayer);
                            }
                        }
                    }
                }
                else
                {
                    vec = MousePositionTranslated;
                    vec = new Vector2(vec.X + helpVec.X, vec.Y + helpVec.Y);

                    if (DrawGrid)
                    {
                        vec    = MousePositionTranslated;
                        vec.X -= (int)(clickedObject.Sprite.ImageRectangle.Width - 32) / 2;//16;
                        vec.Y -= (int)(clickedObject.Sprite.ImageRectangle.Height - 32) / 2;

                        vec = new Vector2((int)vec.X / 32 * 32, (int)vec.Y / 32 * 32);
                    }

                    if (!cmsOpen)
                    {
                        clickedObject.Position = vec;
                    }
                }
            }
            else if (mb == MouseButtons.Right)
            {
                //  Debug.WriteLine("----");
                Vector2 vec = MousePositionTranslated;
                if (DrawGrid)
                {
                    vec = new Vector2((int)vec.X / 32 * 32, (int)vec.Y / 32 * 32);
                }

                foreach (RoomLayer rl in roomLayers)
                {
                    if (rl.Visible)
                    {
                        if (rl is ObjectLayer)
                        {
                            ObjectLayer ol = (ObjectLayer)rl;
                            for (var i = ol.Objects.Count - 1; i >= 0; i--)
                            {
                                Microsoft.Xna.Framework.Rectangle r = new Microsoft.Xna.Framework.Rectangle((int)ol.Objects[i].Position.X, (int)ol.Objects[i].Position.Y, ol.Objects[i].Sprite.ImageRectangle.Width, ol.Objects[i].Sprite.ImageRectangle.Height);

                                if (ks.IsKeyDown(Keys.LeftShift) && r.Contains(vec))
                                {
                                    SceneObjects.Remove(ol.Objects[i]);
                                    ol.Objects[i].EvtDelete();
                                    ol.Objects.Remove(ol.Objects[i]);
                                }
                            }
                        }
                    }
                }
            }

            MousePrevious = MousePositionTranslated;
        }
        public void UpdateAutotiles(int Layer, int X, int Y, int AutotileIndex, bool CheckNeighbouring = false, bool DeleteTile = false)
        {
            TileData     TileData  = MapData.Layers[Layer].Tiles[X + Y * MapData.Width];
            List <Point> Connected = new List <Point>()
            {
                new Point(X - 1, Y - 1), new Point(X, Y - 1), new Point(X + 1, Y - 1),
                new Point(X - 1, Y), new Point(X + 1, Y),
                new Point(X - 1, Y + 1), new Point(X, Y + 1), new Point(X + 1, Y + 1)
            };
            bool NWauto = Connected[0].X >= 0 && Connected[0].X < MapData.Width &&
                          Connected[0].Y >= 0 && Connected[0].Y < MapData.Height &&
                          MapData.Layers[Layer].Tiles[Connected[0].X + Connected[0].Y * MapData.Width] != null &&
                          MapData.Layers[Layer].Tiles[Connected[0].X + Connected[0].Y * MapData.Width].TileType == TileType.Autotile;
            bool NW    = NWauto && MapData.Layers[Layer].Tiles[Connected[0].X + Connected[0].Y * MapData.Width].Index == AutotileIndex;
            bool Nauto = Connected[1].X >= 0 && Connected[1].X < MapData.Width &&
                         Connected[1].Y >= 0 && Connected[1].Y < MapData.Height &&
                         MapData.Layers[Layer].Tiles[Connected[1].X + Connected[1].Y * MapData.Width] != null &&
                         MapData.Layers[Layer].Tiles[Connected[1].X + Connected[1].Y * MapData.Width].TileType == TileType.Autotile;
            bool N      = Nauto && MapData.Layers[Layer].Tiles[Connected[1].X + Connected[1].Y * MapData.Width].Index == AutotileIndex;
            bool NEauto = Connected[2].X >= 0 && Connected[2].X < MapData.Width &&
                          Connected[2].Y >= 0 && Connected[2].Y < MapData.Height &&
                          MapData.Layers[Layer].Tiles[Connected[2].X + Connected[2].Y * MapData.Width] != null &&
                          MapData.Layers[Layer].Tiles[Connected[2].X + Connected[2].Y * MapData.Width].TileType == TileType.Autotile;
            bool NE    = NEauto && MapData.Layers[Layer].Tiles[Connected[2].X + Connected[2].Y * MapData.Width].Index == AutotileIndex;
            bool Wauto = Connected[3].X >= 0 && Connected[3].X < MapData.Width &&
                         Connected[3].Y >= 0 && Connected[3].Y < MapData.Height &&
                         MapData.Layers[Layer].Tiles[Connected[3].X + Connected[3].Y * MapData.Width] != null &&
                         MapData.Layers[Layer].Tiles[Connected[3].X + Connected[3].Y * MapData.Width].TileType == TileType.Autotile;
            bool W     = Wauto && MapData.Layers[Layer].Tiles[Connected[3].X + Connected[3].Y * MapData.Width].Index == AutotileIndex;
            bool Eauto = Connected[4].X >= 0 && Connected[4].X < MapData.Width &&
                         Connected[4].Y >= 0 && Connected[4].Y < MapData.Height &&
                         MapData.Layers[Layer].Tiles[Connected[4].X + Connected[4].Y * MapData.Width] != null &&
                         MapData.Layers[Layer].Tiles[Connected[4].X + Connected[4].Y * MapData.Width].TileType == TileType.Autotile;
            bool E      = Eauto && MapData.Layers[Layer].Tiles[Connected[4].X + Connected[4].Y * MapData.Width].Index == AutotileIndex;
            bool SWauto = Connected[5].X >= 0 && Connected[5].X < MapData.Width &&
                          Connected[5].Y >= 0 && Connected[5].Y < MapData.Height &&
                          MapData.Layers[Layer].Tiles[Connected[5].X + Connected[5].Y * MapData.Width] != null &&
                          MapData.Layers[Layer].Tiles[Connected[5].X + Connected[5].Y * MapData.Width].TileType == TileType.Autotile;
            bool SW    = SWauto && MapData.Layers[Layer].Tiles[Connected[5].X + Connected[5].Y * MapData.Width].Index == AutotileIndex;
            bool Sauto = Connected[6].X >= 0 && Connected[6].X < MapData.Width &&
                         Connected[6].Y >= 0 && Connected[6].Y < MapData.Height &&
                         MapData.Layers[Layer].Tiles[Connected[6].X + Connected[6].Y * MapData.Width] != null &&
                         MapData.Layers[Layer].Tiles[Connected[6].X + Connected[6].Y * MapData.Width].TileType == TileType.Autotile;
            bool S      = Sauto && MapData.Layers[Layer].Tiles[Connected[6].X + Connected[6].Y * MapData.Width].Index == AutotileIndex;
            bool SEauto = Connected[7].X >= 0 && Connected[7].X < MapData.Width &&
                          Connected[7].Y >= 0 && Connected[7].Y < MapData.Height &&
                          MapData.Layers[Layer].Tiles[Connected[7].X + Connected[7].Y * MapData.Width] != null &&
                          MapData.Layers[Layer].Tiles[Connected[7].X + Connected[7].Y * MapData.Width].TileType == TileType.Autotile;
            bool SE = SEauto && MapData.Layers[Layer].Tiles[Connected[7].X + Connected[7].Y * MapData.Width].Index == AutotileIndex;

            if (CheckNeighbouring || TileData != null && TileData.TileType == TileType.Autotile && TileData.Index == AutotileIndex)
            // Only try to update the current tile if it's assignment (not deletion)
            // and if the current tile is also an autotile
            {
                int ID = -1;
                if (NW && NE && SE && SW && W && N && E && S)
                {
                    ID = 0;
                }
                else if (!NW && NE && SE && SW && W && N && E && S)
                {
                    ID = 1;
                }
                else if (NW && !NE && SE && SW && W && N && E && S)
                {
                    ID = 2;
                }
                else if (!NW && !NE && SE && SW & W && N && E && S)
                {
                    ID = 3;
                }
                else if (NW && NE && !SE && SW && W && N && E && S)
                {
                    ID = 4;
                }
                else if (!NW && NE && !SE && SW && W && N && E && S)
                {
                    ID = 5;
                }
                else if (NW && !NE && !SE && SW && W && N && E && S)
                {
                    ID = 6;
                }
                else if (!NW && !NE && !SE && SW && W && N && E && S)
                {
                    ID = 7;
                }
                else if (NW && NE && SE && !SW && W && N && E && S)
                {
                    ID = 8;
                }
                else if (!NW && NE && SE && !SW && W && N && E && S)
                {
                    ID = 9;
                }
                else if (NW && !NE && SE && !SW && W && N && E && S)
                {
                    ID = 10;
                }
                else if (!NW && !NE && SE && !SW && W && N && E && S)
                {
                    ID = 11;
                }
                else if (NW && NE && !SE && !SW && W && N && E && S)
                {
                    ID = 12;
                }
                else if (!NW && NE && !SE && !SW && W && N && E && S)
                {
                    ID = 13;
                }
                else if (NW && !NE && !SE && !SW && W && N && E && S)
                {
                    ID = 14;
                }
                else if (!NW && !NE && !SE && !SW && W && N && E && S)
                {
                    ID = 15;
                }
                else if (NE && SE && !W && N && E && S)
                {
                    ID = 16;
                }
                else if (!NE && SE && !W && N && E && S)
                {
                    ID = 17;
                }
                else if (NE && !SE && !W && N && E && S)
                {
                    ID = 18;
                }
                else if (!NE && !SE && !W && N && E && S)
                {
                    ID = 19;
                }
                else if (SE && SW && W && !N && E && S)
                {
                    ID = 20;
                }
                else if (!SE && SW && W && !N && E && S)
                {
                    ID = 21;
                }
                else if (SE && !SW && W && !N && E && S)
                {
                    ID = 22;
                }
                else if (!SE && !SW && W && !N && E && S)
                {
                    ID = 23;
                }
                else if (NW && SW && W && N && !E && S)
                {
                    ID = 24;
                }
                else if (NW && !SW && W && N && !E && S)
                {
                    ID = 25;
                }
                else if (!NW && SW && W && N && !E && S)
                {
                    ID = 26;
                }
                else if (!NW && !SW && W && N && !E && S)
                {
                    ID = 27;
                }
                else if (NW && NE && W && N && E && !S)
                {
                    ID = 28;
                }
                else if (!NW && NE && W && N && E && !S)
                {
                    ID = 29;
                }
                else if (NW && !NE && W && N && E && !S)
                {
                    ID = 30;
                }
                else if (!NW && !NE && W && N && E && !S)
                {
                    ID = 31;
                }
                else if (!W && N && !E && S)
                {
                    ID = 32;
                }
                else if (W && !N && E && !S)
                {
                    ID = 33;
                }
                else if (SE && !W && !N && E && S)
                {
                    ID = 34;
                }
                else if (!SE && !W && !N && E && S)
                {
                    ID = 35;
                }
                else if (SW && W && !N && !E && S)
                {
                    ID = 36;
                }
                else if (!SW && W && !N && !E && S)
                {
                    ID = 37;
                }
                else if (NW && W && N && !E && !S)
                {
                    ID = 38;
                }
                else if (!NW && W && N && !E && !S)
                {
                    ID = 39;
                }
                else if (NE && !W && N && E && !S)
                {
                    ID = 40;
                }
                else if (!NE && !W && N && E && !S)
                {
                    ID = 41;
                }
                else if (!W && !N && !E && S)
                {
                    ID = 42;
                }
                else if (!W && !N && E && !S)
                {
                    ID = 43;
                }
                else if (!W && N && !E && !S)
                {
                    ID = 44;
                }
                else if (W && !N && !E && !S)
                {
                    ID = 45;
                }
                else if (!W && !N && !E && !S)
                {
                    ID = 46;
                }
                if (ID != -1 && !DeleteTile)
                {
                    for (int i = 0; i < AnimatedAutotiles.Count; i++)
                    {
                        List <int> data = AnimatedAutotiles[i];
                        if (data[0] == Layer && data[1] == X && data[2] == Y)
                        {
                            AnimatedAutotiles.RemoveAt(i);
                            break;
                        }
                    }
                    MapData.Layers[Layer].Tiles[X + Y * MapData.Width].ID = ID;
                    Autotile autotile = Data.Autotiles[MapData.AutotileIDs[AutotileIndex]];
                    if (autotile.AnimateSpeed > 0)
                    {
                        AnimatedAutotiles.Add(new List <int>()
                        {
                            Layer, X, Y, Data.Autotiles.IndexOf(autotile), ID
                        });
                    }
                    int AnimX = 0;
                    if (autotile.Format == AutotileFormat.Single)
                    {
                        AnimX = ((int)Math.Floor((double)AnimateCount / autotile.AnimateSpeed) * 32) % autotile.AutotileBitmap.Width;
                        if (!Editor.GeneralSettings.ShowMapAnimations)
                        {
                            AnimX = 0;
                        }
                        this.Sprites[Layer.ToString()].Bitmap.Build(new Rect(32 * X, 32 * Y, 32, 32), autotile.AutotileBitmap,
                                                                    new Rect(AnimX, 0, 32, 32));
                    }
                    else
                    {
                        AnimX = ((int)Math.Floor((double)AnimateCount / autotile.AnimateSpeed) * 96) % autotile.AutotileBitmap.Width;
                        if (!Editor.GeneralSettings.ShowMapAnimations)
                        {
                            AnimX = 0;
                        }
                        List <int> Tiles = Autotile.AutotileCombinations[autotile.Format][ID];
                        for (int i = 0; i < 4; i++)
                        {
                            this.Sprites[Layer.ToString()].Bitmap.Build(new Rect(32 * X + 16 * (i % 2), 32 * Y + 16 * (int)Math.Floor(i / 2d), 16, 16), autotile.AutotileBitmap,
                                                                        new Rect(16 * (Tiles[i] % 6) + AnimX, 16 * (int)Math.Floor(Tiles[i] / 6d), 16, 16));
                        }
                    }
                }
            }
            // Whether or not to update neighbouring tiles
            if (CheckNeighbouring)
            {
                // Only update neighbours if they contain autotiles
                // (they don't need to be the same autotile; if autotile B is drawn over A, then surrounding A must also be updated)
                if (NWauto)
                {
                    UpdateAutotiles(Layer, Connected[0].X, Connected[0].Y, MapData.Layers[Layer].Tiles[Connected[0].X + Connected[0].Y * MapData.Width].Index);
                }
                if (Nauto)
                {
                    UpdateAutotiles(Layer, Connected[1].X, Connected[1].Y, MapData.Layers[Layer].Tiles[Connected[1].X + Connected[1].Y * MapData.Width].Index);
                }
                if (NEauto)
                {
                    UpdateAutotiles(Layer, Connected[2].X, Connected[2].Y, MapData.Layers[Layer].Tiles[Connected[2].X + Connected[2].Y * MapData.Width].Index);
                }
                if (Wauto)
                {
                    UpdateAutotiles(Layer, Connected[3].X, Connected[3].Y, MapData.Layers[Layer].Tiles[Connected[3].X + Connected[3].Y * MapData.Width].Index);
                }
                if (Eauto)
                {
                    UpdateAutotiles(Layer, Connected[4].X, Connected[4].Y, MapData.Layers[Layer].Tiles[Connected[4].X + Connected[4].Y * MapData.Width].Index);
                }
                if (SWauto)
                {
                    UpdateAutotiles(Layer, Connected[5].X, Connected[5].Y, MapData.Layers[Layer].Tiles[Connected[5].X + Connected[5].Y * MapData.Width].Index);
                }
                if (Sauto)
                {
                    UpdateAutotiles(Layer, Connected[6].X, Connected[6].Y, MapData.Layers[Layer].Tiles[Connected[6].X + Connected[6].Y * MapData.Width].Index);
                }
                if (SEauto)
                {
                    UpdateAutotiles(Layer, Connected[7].X, Connected[7].Y, MapData.Layers[Layer].Tiles[Connected[7].X + Connected[7].Y * MapData.Width].Index);
                }
            }
        }
        public Bitmap GetLayerBitmap(int Layer)
        {
            Bitmap bmp = new Bitmap(MapData.Width * 32, MapData.Height * 32, 16 * 32, 16 * 32); // 16x16 tile chunks

            bmp.Unlock();
            // Iterate through all vertical tiles
            for (int y = 0; y < MapData.Height; y++)
            {
                // Iterate through all horizontal tiles
                for (int x = 0; x < MapData.Width; x++)
                {
                    // Draw each individual tile
                    if (MapData.Layers[Layer] == null || MapData.Layers[Layer].Tiles == null ||
                        y * MapData.Width + x >= MapData.Layers[Layer].Tiles.Count ||
                        MapData.Layers[Layer].Tiles[y * MapData.Width + x] == null)
                    {
                        continue;
                    }
                    int mapx    = x * 32;
                    int mapy    = y * 32;
                    int tile_id = MapData.Layers[Layer].Tiles[y * MapData.Width + x].ID;
                    if (MapData.Layers[Layer].Tiles[y * MapData.Width + x].TileType == TileType.Tileset)
                    {
                        int    tileset_index = MapData.Layers[Layer].Tiles[y * MapData.Width + x].Index;
                        int    tileset_id    = MapData.TilesetIDs[tileset_index];
                        Bitmap tilesetimage  = Data.Tilesets[tileset_id].TilesetBitmap;
                        int    tilesetx      = tile_id % 8;
                        int    tilesety      = (int)Math.Floor(tile_id / 8d);
                        bmp.Build(new Rect(mapx, mapy, 32, 32), tilesetimage, new Rect(tilesetx * 32, tilesety * 32, 32, 32));
                    }
                    else if (MapData.Layers[Layer].Tiles[y * MapData.Width + x].TileType == TileType.Autotile)
                    {
                        int      autotile_index = MapData.Layers[Layer].Tiles[y * MapData.Width + x].Index;
                        int      autotile_id    = MapData.AutotileIDs[autotile_index];
                        Autotile autotile       = Data.Autotiles[autotile_id];
                        if (autotile.AnimateSpeed > 0)
                        {
                            AnimatedAutotiles.Add(new List <int>()
                            {
                                Layer, x, y, autotile_id, tile_id
                            });
                        }
                        Bitmap autotileimage = autotile.AutotileBitmap;
                        if (autotile.Format == AutotileFormat.Single)
                        {
                            int AnimX = 0;
                            bmp.Build(new Rect(mapx, mapy, 32, 32), autotileimage, new Rect(AnimX, 0, 32, 32));
                        }
                        else
                        {
                            int        AnimX = 0;
                            List <int> Tiles = Autotile.AutotileCombinations[autotile.Format][tile_id];
                            for (int i = 0; i < 4; i++)
                            {
                                bmp.Build(new Rect(mapx + 16 * (i % 2), mapy + 16 * (int)Math.Floor(i / 2d), 16, 16), autotileimage,
                                          new Rect(16 * (Tiles[i] % 6) + AnimX, 16 * (int)Math.Floor(Tiles[i] / 6d), 16, 16));
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Invalid tile type.");
                    }
                }
            }
            bmp.Lock();
            return(bmp);
        }