Exemple #1
0
        public void GetTilePosition(MouseEventArgs e, out int ContainerIndex, out int X, out int Y)
        {
            ContainerIndex = -1;
            X = -1;
            Y = -1;
            if (!e.LeftButton && !e.RightButton)
            {
                return;
            }
            if (Parent.VScrollBar != null && (Parent.VScrollBar.SliderDragging || Parent.VScrollBar.SliderHovering))
            {
                return;
            }
            Container cont = MainContainer;
            int       rx   = e.X - cont.Viewport.X;
            int       ry   = e.Y - cont.Viewport.Y;

            if (rx < 0 || ry < 0 || rx >= cont.Viewport.Width || ry >= cont.Viewport.Height)
            {
                return;                                                                              // Off the widget
            }
            rx += cont.ScrolledX;
            ry += cont.ScrolledY;
            if (rx < 8 || ry < 3 || rx >= 264)
            {
                return;       // Not over an autotile/tileset
            }
            int crx = rx - 8; // container (c) relative (r) x (x)

            for (int i = 0; i < MainStackPanel.Widgets.Count; i++)
            {
                CollapsibleContainer cc = MainStackPanel.Widgets[i] as CollapsibleContainer;
                int height = cc.Position.Y;
                if (ry < height)
                {
                    break;              // Somehow already gone past the container it's in
                }
                if (ry > height + cc.Size.Height)
                {
                    continue;
                }
                // By now we know ry is inside this CollapsibleContainer.
                // So we now need to determine the y coordinate relative to this container
                // To determine which tile we're over.
                int cry = ry - cc.Position.Y; // container (c) relative (r) y (y)
                if (cry < 26)
                {
                    continue;           // In the name part of the container
                }
                cry -= 26;
                int tilex = (int)Math.Floor(crx / 33d);
                int tiley = (int)Math.Floor(cry / 33d);
                ContainerIndex = i;
                X = tilex;
                Y = tiley;
                break;
            }
        }
Exemple #2
0
 public void UpdateCursor()
 {
     if (MapViewer.SelectionOnMap)
     {
         AutotileIndex = AutotileCombination = TilesetIndex = TileStartX = TileEndX = TileStartY = TileEndY = -1;
     }
     if (AutotileIndex == -1 && (TilesetIndex == -1 || TileStartX == -1 || TileEndX == -1 || TileStartY == -1 || TileEndY == -1) ||
         SelectButton.Selected)
     {
         Cursor.SetPosition(0, 0);
         Cursor.SetVisible(false);
         MainContainer.UpdateAutoScroll();
         return;
     }
     if (SelectButton.Selected)
     {
         SelectButton.SetSelected(false);
         PencilButton.SetSelected(true);
     }
     if (AutotileIndex != -1) // Autotile selected
     {
         object image = AutotileContainers[AutotileIndex];
         if (image is int) // Single autotile
         {
             CollapsibleContainer cc = SingleAutotileContainer;
             if (cc.Collapsed || EraserButton.Selected || MapViewer.SelectionOnMap)
             {
                 Cursor.SetVisible(false);
                 Cursor.SetPosition(0, 0);
                 MainContainer.UpdateAutoScroll();
             }
             else
             {
                 Cursor.SetVisible(true);
                 Cursor.SetPosition(1 + 33 * (((int)image) % 8), cc.Position.Y + 19 + 33 * (int)Math.Floor(((int)image) / 8d));
                 Cursor.SetSize(32 + 14, 32 + 14);
             }
         }
         else if (image is CollapsibleContainer) // Other autotile format
         {
             CollapsibleContainer cc = image as CollapsibleContainer;
             if (cc.Collapsed || EraserButton.Selected || MapViewer.SelectionOnMap)
             {
                 Cursor.SetVisible(false);
                 Cursor.SetPosition(0, 0);
                 MainContainer.UpdateAutoScroll();
             }
             else
             {
                 Cursor.SetVisible(true);
                 if (AutotileCombination != -1)
                 {
                     Cursor.SetPosition(67 + 33 * AutotileCombination, cc.Position.Y + 19 + 16);
                     Cursor.SetSize(32 + 14, 32 + 14);
                 }
                 else
                 {
                     Cursor.SetPosition(1, cc.Position.Y + 19);
                     Cursor.SetSize(64 + 14, 64 + 14);
                 }
             }
         }
         MapViewer.CursorOrigin = Location.TopLeft;
         MapViewer.TileDataList.Clear();
         MapViewer.CursorWidth    = 0;
         MapViewer.CursorHeight   = 0;
         MapViewer.SelectionOnMap = false;
         MapViewer.UpdateCursorPosition();
         int tileid = -1;
         if (AutotileCombination != -1)
         {
             tileid = (int)Data.Autotiles[MapData.AutotileIDs[AutotileIndex]].QuickIDs[AutotileCombination];
         }
         MapViewer.TileDataList = new List <TileData>()
         {
             new TileData()
             {
                 TileType = TileType.Autotile, Index = AutotileIndex, ID = tileid
             }
         };
     }
     else // Tileset selected
     {
         int      DiffX    = TileEndX - TileStartX;
         int      DiffY    = TileEndY - TileStartY;
         int      PosDiffX = 0;
         int      PosDiffY = 0;
         Location origin   = Location.BottomRight;
         // If the origin is bottom right instead of top left
         if (DiffX < 0)
         {
             DiffX    = -DiffX;
             PosDiffX = 33 * DiffX;
             origin   = Location.BottomLeft;
         }
         if (DiffY < 0)
         {
             DiffY    = -DiffY;
             PosDiffY = 33 * DiffY;
             if (origin == Location.BottomLeft)
             {
                 origin = Location.TopLeft;
             }
             else
             {
                 origin = Location.TopRight;
             }
         }
         MapViewer.CursorOrigin = origin;
         MapViewer.TileDataList.Clear();
         MapViewer.CursorWidth    = DiffX;
         MapViewer.CursorHeight   = DiffY;
         MapViewer.SelectionOnMap = false;
         MapViewer.UpdateCursorPosition();
         int sx = TileStartX < TileEndX ? TileStartX : TileEndX;
         int ex = TileStartX < TileEndX ? TileEndX : TileStartX;
         int sy = TileStartY < TileEndY ? TileStartY : TileEndY;
         int ey = TileStartY < TileEndY ? TileEndY : TileStartY;
         for (int y = sy; y <= ey; y++)
         {
             for (int x = sx; x <= ex; x++)
             {
                 int tileid = y * 8 + x;
                 MapViewer.TileDataList.Add(new TileData()
                 {
                     TileType = TileType.Tileset, Index = TilesetIndex, ID = tileid
                 });
             }
         }
         CollapsibleContainer cc = TilesetContainers[TilesetIndex];
         if (cc.Collapsed || EraserButton.Selected || MapViewer.SelectionOnMap)
         {
             Cursor.SetPosition(0, 0);
             Cursor.SetVisible(false);
             MainContainer.UpdateAutoScroll();
         }
         else
         {
             Cursor.SetVisible(true);
             Cursor.SetPosition(1 + TileStartX * 33 - PosDiffX, 19 + cc.Position.Y + TileStartY * 33 - PosDiffY);
             Cursor.SetSize(32 * (DiffX + 1) + DiffX + 14, 32 * (DiffY + 1) + DiffY + 14);
         }
     }
 }
Exemple #3
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);
            }
        }