public override bool OnMouseOver(Pointer e)
        {
            if (Editor == null) return false;

            var scalex = Width / Editor.AssetFrame.Width;
            var scaley = Height / Editor.AssetFrame.Height;

            var pos = new Point(( e.X / scalex ), ( e.Y / scaley ));
            Editor.ShowHurtMap = ShowHurtMap;
            Editor.ShowCollideMap = ShowCollideMap;

            if (Clicking) {
                if (!Editable) {
                    if (Click != null)
                        Click(pos);
                } else {
                    ClickHandled = true;
                    if (ShowHurtMap || ShowCollideMap)
                        Editor.CurrentColor = e.Right ? 0 : 1;
                    Editor.DrawLine(pos, LastPosition);
                    LastPosition = pos;
                }
            }
            return base.OnMouseOver(e);
        }
        public override bool OnClick(Pointer e)
        {
            if (!Visible) return false;
            if (Editor == null) return false;
            Clicking = true;
            ClickHandled = false;
            var scalex = Width / Editor.AssetFrame.Width;
            var scaley = Height / Editor.AssetFrame.Height;
            Editor.ShowHurtMap = ShowHurtMap;
            Editor.ShowCollideMap = ShowCollideMap;

            var pos = new Point(( e.X / scalex ), ( e.Y / scaley ));
            if (!Editable) {
                if (Click != null)
                    Click(pos);
            } else {
                LastPosition = pos;
                if (PaletteEditor != null)
                    Editor.CurrentColor = PaletteEditor.SelectedIndex;

                if (ShowHurtMap || ShowCollideMap)
                    Editor.CurrentColor = e.Right ? 0 : 1;

                Editor.DrawPixel(pos);
            }

            return base.OnClick(e);
        }
 public PieceLayoutEditor(int x, int y, Point size) : base(x, y)
 {
     Size = size;
     ShowHurtMap = false;
     ShowCollideMap = false;
     Visible = true;
     Size = size;
     Clicking = false;
     PieceLayoutMaker = null;
 }
Example #4
0
        public void DrawBase(CanvasRenderingContext2D canvas, Point pos, bool xflip, bool yflip, int palette, bool isAnimatedTile = false)
        {

            //we dont predraw animated tiles
            if (AnimatedTileIndexes != null && (!isAnimatedTile && AnimatedTileIndexes.Count > 0)) return;

            var baseCacheIndex = getBaseCacheIndex(xflip, yflip, palette);

            CanvasInformation baseCache = baseCaches[baseCacheIndex];

            if (baseCache == null)
            {

                var squareSize = Colors.Length;
                CanvasInformation j;
                j = CanvasInformation.Create(squareSize, squareSize, false);

                if (pos.X < 0 || pos.Y < 0)
                    return;
                var oPos = new Point(0, 0);
                if (xflip)
                {
                    oPos.X = -squareSize;
                    j.Context.Scale(-1, 1);
                }
                if (yflip)
                {
                    oPos.Y = -squareSize;
                    j.Context.Scale(1, -1);
                }
                var palette_ = SonicManager.Instance.SonicLevel.Palette;

                int colorPaletteIndex = (palette + SonicManager.Instance.IndexedPalette) % palette_.Length;
                var x = oPos.X;
                var y = oPos.Y;

                for (int _x = 0; _x < squareSize; _x++)
                {
                    for (int _y = 0; _y < squareSize; _y++)
                    {
                        var colorIndex = Colors[_x][_y];
                        if (colorIndex == 0) continue;

                        j.Context.FillStyle = palette_[colorPaletteIndex][colorIndex];
                        j.Context.FillRect(x + _x, y + _y,1,1);
                    }
                }
                baseCaches[baseCacheIndex] = baseCache = j;
            }


            canvas.DrawImage(baseCache.Canvas, pos.X, pos.Y);


        }
 public PieceLayoutMaker(LevelObjectPieceLayout pieceLayout)
 {
     PieceLayout = pieceLayout;
     LineWidth = 1;
     CurrentColor = 0;
     ShowOutline = true;
     ShowImages = false;
     SelectedPieceIndex = 0;
     DraggingIndex = -1;
     ZeroPosition = new Point(0, 0);
 }
        public override bool OnMouseOver(Pointer e)
        {
            if (PieceLayoutMaker == null) return false;

            if (Clicking) {
                ClickHandled = true;
                PieceLayoutMaker.PlaceItem(e, LastPosition);
                LastPosition = new Point(e.X, e.Y);
            }
            return base.OnMouseOver(e);
        }
        public void PlaceItem(Point position, Point lastPosition)
        {
            var goodPosition = position;
            if (lastPosition != null) {
                goodPosition = position;
                position = lastPosition;
            }

            for (var i = 0; i < PieceLayout.Pieces.Count; i++) {
                var j = PieceLayout.Pieces[i];
                var piece = SonicManager.Instance.UIManager.UIManagerAreas.ObjectFrameworkArea.objectFrameworkArea.Data.ObjectFramework.Pieces[j.PieceIndex];
                var asset = SonicManager.Instance.UIManager.UIManagerAreas.ObjectFrameworkArea.objectFrameworkArea.Data.ObjectFramework.Assets[piece.AssetIndex];
                var size = new Point(10, 10);
                if (asset.Frames.Count > 0) {
                    var frm = asset.Frames[0];
                    size.X = frm.Width / 2 + 10;
                    size.Y = frm.Height / 2 + 10;
                }

                if (position.X - ZeroPosition.X > j.X - size.X &&
                    position.X - ZeroPosition.X < j.X + size.X &&
                    position.Y - ZeroPosition.Y > j.Y - size.Y &&
                    position.Y - ZeroPosition.Y < j.Y + size.Y) {
                    if (!( DraggingIndex == -1 || DraggingIndex == i ))
                        continue;

                    j.X = goodPosition.X - ZeroPosition.X;
                    j.Y = goodPosition.Y - ZeroPosition.Y;
                    SelectedPieceIndex = i;
                    DraggingIndex = i;

                    var cj = SonicManager.Instance.UIManager.UIManagerAreas.ObjectFrameworkArea.objectFrameworkArea.Data.MainPanel.Data.SelectPieceScroll.Controls;

                    for (var ci = 0; ci < cj.Count; ci++) {
                        if (ci == j.PieceIndex)
                            ( (ImageButton) cj[ci] ).Toggled = true;
                        else
                            ( (ImageButton) cj[ci] ).Toggled = false;
                    }
                    PieceLayout.Update();
                    return;
                }
            }

            if (lastPosition != null) {
                ZeroPosition.X += goodPosition.X - lastPosition.X;
                ZeroPosition.Y += goodPosition.Y - lastPosition.Y;
            }

            //sonicManager.uiManager.objectFrameworkArea.mainPanel.updatePieces();
        }
Example #8
0
 public static IntersectingRectangle DefaultWindowLocation(GameState state, CanvasInformation canvas, Point scale)
 {
     switch (state) {
         case GameState.Playing:
             return new IntersectingRectangle(0, 0, 320, 224);
         case GameState.Editing:
             var x = 0;
             var y = 0;
             if (SonicManager.Instance.SonicLevel.Truthy() && SonicManager.Instance.SonicLevel.StartPositions.Truthy() &&
                 SonicManager.Instance.SonicLevel.StartPositions[0].Truthy()) {
                 x = SonicManager.Instance.SonicLevel.StartPositions[0].X - 128 * scale.X;
                 y = SonicManager.Instance.SonicLevel.StartPositions[0].Y - 128 * scale.Y;
             }
             return new IntersectingRectangle(x, y, Window.InnerWidth , Window.InnerHeight);
     }
     return null;
 }
        public void Draw(CanvasRenderingContext2D canvas, Point pos, Point scale)
        {
//            PieceLayout.DrawUI(canvas, pos, ShowImages, SelectedPieceIndex, ZeroPosition, largeScale);
        }
        public override void Draw(CanvasRenderingContext2D canv)
        {
            if (!Visible) return;
            if (PieceLayoutMaker == null) return;
            var pos = new Point(TotalX, TotalY);

            PieceLayoutMaker.Draw(canv, pos, Size);

            base.Draw(canv);
        }
 public static bool IntersectsRect(Rectangle r, Point p)
 {
     return r.X < p.X && r.X + r.Width > p.X && r.Y < p.Y && r.Y + r.Height > p.Y;
 }
 public bool Intersects(Point p)
 {
     return X < p.X && X + Width > p.X && Y < p.Y && Y + Height > p.Y;
 }
        public override void Draw(CanvasRenderingContext2D canv)
        {
            base.Draw(canv);

            if (!Visible) return;
            if (Editor == null) return;
            var pos = new Point(TotalX, y: TotalY);

            Editor.Draw(canv, pos, new Point(Width, Height), ShowCollideMap, ShowHurtMap);
        }
        public override bool OnMouseUp(Pointer e)
        {
            if (!Visible) return false;

            LastPosition = null;
            ClickHandled = false;
            Clicking = false;
            return base.OnMouseUp(e);
        }
Example #15
0
 public void Draw(CanvasRenderingContext2D canvas, Point point, int wOffset) {}
Example #16
0
        public void DrawAnimatedTile(CanvasRenderingContext2D canvas, Point pos, bool xflip, bool yflip, int palette, int animatedTileIndex)
        {
            if (AnimatedTileIndexes.IndexOfFast(animatedTileIndex) == -1) return;
            var tileAnimationFrame = SonicManager.Instance.TileAnimationManager.GetCurrentFrame(animatedTileIndex);
            var tileAnimation = tileAnimationFrame.Animation;
            var tileAnimationData = tileAnimation.AnimatedTileData;
            var animationIndex = tileAnimationData.AnimationTileIndex;

            var frame = tileAnimationFrame.FrameData();
            if (frame.Falsey())
            {
                frame = tileAnimation.AnimatedTileData.DataFrames[0];
                //todo throw
            }

            var file = tileAnimationData.GetAnimationFile();
            var va = file[frame.StartingTileIndex + (Index - animationIndex)];
            if (va != null)
            {
                va.DrawBase(canvas, pos, xflip, yflip, palette, true);
            }
            else
            {
                //todo throw
            }
        }