コード例 #1
0
        public override Brush Construct(BrushArgs args)
        {
            if (args.Message == "")
            {
                if (!DrawCmd.CheckBlock(args.Player, args.Block))
                {
                    return(null);
                }
                return(new CheckeredBrush(args.Block, args.ExtBlock, 0, 0));
            }
            string[] parts = args.Message.Split(' ');

            byte extBlock1;
            int  block1 = DrawCmd.GetBlockIfAllowed(args.Player, parts[0], out extBlock1);

            if (block1 == -1)
            {
                return(null);
            }
            if (parts.Length == 1)
            {
                return(new CheckeredBrush((byte)block1, extBlock1, Block.Invalid, 0));
            }

            byte extBlock2;
            int  block2 = DrawCmd.GetBlockIfAllowed(args.Player, parts[1], out extBlock2);

            if (block2 == -1)
            {
                return(null);
            }
            return(new CheckeredBrush((byte)block1, extBlock1, (byte)block2, extBlock2));
        }
コード例 #2
0
ファイル: CheckeredBrush.cs プロジェクト: Peteys93/MCGalaxy
        public static Brush Process(BrushArgs args)
        {
            if (args.Message == "")
            {
                return(new CheckeredBrush(args.Type, args.ExtType, 0, 0));
            }
            string[] parts = args.Message.Split(' ');
            byte     extType1;
            byte     type1 = DrawCmd.GetBlock(args.Player, parts[0], out extType1);

            if (type1 == Block.Zero)
            {
                return(null);
            }
            if (parts.Length == 1)
            {
                return(new CheckeredBrush(type1, extType1, Block.Zero, 0));
            }

            byte extType2;
            byte type2 = DrawCmd.GetBlock(args.Player, parts[1], out extType2);

            if (type2 == Block.Zero)
            {
                return(null);
            }
            return(new CheckeredBrush(type1, extType1, type2, extType2));
        }
コード例 #3
0
        private void btnAddLine_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ReDraw();
            btnPanorama_ItemClick(sender, e);

            if (drawCmd != DrawCmd.None)
            {
                return;
            }
            btnAddLine.Visibility  = DevExpress.XtraBars.BarItemVisibility.Never;
            btnClose.Visibility    = DevExpress.XtraBars.BarItemVisibility.Never;
            btnBkColor.Visibility  = DevExpress.XtraBars.BarItemVisibility.Never;
            btnZoomIn.Visibility   = DevExpress.XtraBars.BarItemVisibility.Never;
            btnZoomOut.Visibility  = DevExpress.XtraBars.BarItemVisibility.Never;
            btnPanorama.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;


            btnOK.Visibility     = DevExpress.XtraBars.BarItemVisibility.Always;
            btnCancel.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
            btnRecall.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;

            drawCmd = DrawCmd.DrawLine;
            Cursor  = Cursors.Cross;
            screenLines.Add(new ScreenLine());
            statusStrip1.Visible = true;
        }
コード例 #4
0
        static ExtBlock[] GetBlocks(Player p, int max, string[] parts, int[] count)
        {
            ExtBlock[] blocks = new ExtBlock[max];
            for (int i = 0; i < blocks.Length; i++)
            {
                blocks[i].Type = Block.Zero;
                count[i]       = 1;
            }

            for (int i = 0; i < max; i++)
            {
                byte   extType  = 0;
                int    sepIndex = parts[i].IndexOf('/');
                string block    = sepIndex >= 0 ? parts[i].Substring(0, sepIndex) : parts[i];
                byte   type     = DrawCmd.GetBlock(p, block, out extType);
                if (type == Block.Zero)
                {
                    return(null);
                }

                blocks[i].Type = type; blocks[i].ExtType = extType;
                if (sepIndex < 0)
                {
                    continue;
                }
                int chance;
                if (!int.TryParse(parts[i].Substring(sepIndex + 1), out chance) || chance <= 0 || chance > 10000)
                {
                    Player.SendMessage(p, "frequency must be an integer between 1 and 10,000."); return(null);
                }
                count[i] = chance;
            }
            return(blocks);
        }
コード例 #5
0
ファイル: FrequencyBrushes.cs プロジェクト: Benedani/MCGalaxy
        public static ExtBlock[] GetBlocks(BrushArgs args, out int[] count,
                                           Predicate <string> filter, Predicate <string> handler)
        {
            string[] parts = args.Message.Split(' ');
            Player   p     = args.Player;

            ExtBlock[] blocks;
            GetRaw(parts, filter, args, out blocks, out count);

            // check if we're allowed to place the held block
            if (blocks[0].Block != Block.Invalid &&
                !DrawCmd.CheckBlock(p, blocks[0].Block))
            {
                return(null);
            }

            for (int i = 0, j = 0; i < parts.Length; i++)
            {
                if (parts[i] == "")
                {
                    continue;
                }

                // Brush specific args
                if (!filter(parts[i]))
                {
                    if (!handler(parts[i]))
                    {
                        return(null);
                    }
                    continue;
                }

                byte   extBlock  = 0;
                int    sepIndex  = parts[i].IndexOf('/');
                string blockName = sepIndex >= 0 ? parts[i].Substring(0, sepIndex) : parts[i];
                int    block     = DrawCmd.GetBlockIfAllowed(p, blockName, out extBlock);
                if (block == -1)
                {
                    return(null);
                }

                blocks[j].Block = (byte)block; blocks[j].Ext = extBlock;
                if (sepIndex < 0)
                {
                    j++; continue;
                }

                int chance;
                if (!int.TryParse(parts[i].Substring(sepIndex + 1), out chance) ||
                    chance <= 0 || chance > 10000)
                {
                    Player.Message(p, "frequency must be an integer between 1 and 10,000."); return(null);
                }
                count[j] = chance;
                j++;
            }
            return(blocks);
        }
コード例 #6
0
        public override bool Validate(BrushArgs args)
        {
            if (args.Message == "")
            {
                return(true);
            }
            byte extBlock;

            return(DrawCmd.GetBlockIfAllowed(args.Player, args.Message, out extBlock) != -1);
        }
コード例 #7
0
ファイル: FrmDrawEx.cs プロジェクト: shiwm/FieldGeo3D
        private void ExitDrawLine()
        {
            btnAddLine.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
            btnClose.Visibility   = DevExpress.XtraBars.BarItemVisibility.Always;
            btnBkColor.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
            btnZoomIn.Visibility  = DevExpress.XtraBars.BarItemVisibility.Always;
            btnZoomOut.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;

            btnOK.Visibility     = DevExpress.XtraBars.BarItemVisibility.Never;
            btnCancel.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;

            drawCmd = DrawCmd.None;
            Cursor  = Cursors.Arrow;
        }
コード例 #8
0
ファイル: SolidBrush.cs プロジェクト: Peteys93/MCGalaxy
        public static Brush Process(BrushArgs args)
        {
            if (args.Message == "")
            {
                return(new SolidBrush(args.Type, args.ExtType));
            }
            byte extType;
            byte type = DrawCmd.GetBlock(args.Player, args.Message, out extType);

            if (type == Block.Zero)
            {
                return(null);
            }
            return(new SolidBrush(type, extType));
        }
コード例 #9
0
ファイル: StripedBrush.cs プロジェクト: Peteys93/MCGalaxy
 public static Brush Process(BrushArgs args) {
     if (args.Message == "")
         return new StripedBrush(args.Type, args.ExtType, 0, 0);
     string[] parts = args.Message.Split(' ');
     byte extType1;
     byte type1 = DrawCmd.GetBlock(args.Player, parts[0], out extType1);
     if (type1 == Block.Zero) return null;
     if (parts.Length == 1)
         return new StripedBrush(type1, extType1, 0, 0);
     
     byte extType2;
     byte type2 = DrawCmd.GetBlock(args.Player, parts[1], out extType2);
     if (type2 == Block.Zero) return null;
     return new StripedBrush(type1, extType1, type2, extType2);
 }
コード例 #10
0
ファイル: ReplaceBrush.cs プロジェクト: Peteys93/MCGalaxy
        public static Brush Process(BrushArgs args)
        {
            string[] parts = args.Message.Split(' ');
            if (parts.Length < 2)
            {
                args.Player.SendMessage("You need to provide a target block, and at least one block to replace."); return(null);
            }

            ExtBlock[] toAffect = GetBlocks(args.Player, 0, parts.Length - 1, parts);
            ExtBlock   target;

            target.Type = DrawCmd.GetBlock(args.Player, parts[parts.Length - 1], out target.ExtType);
            if (target.Type == Block.Zero)
            {
                return(null);
            }
            return(target.Type == Block.Zero ? null : new ReplaceBrush(toAffect, target));
        }
コード例 #11
0
ファイル: FrmDrawEx.cs プロジェクト: shiwm/FieldGeo3D
        private void btnAddLine_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (drawCmd != DrawCmd.None)
            {
                return;
            }
            btnAddLine.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            btnClose.Visibility   = DevExpress.XtraBars.BarItemVisibility.Never;
            btnBkColor.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            btnZoomIn.Visibility  = DevExpress.XtraBars.BarItemVisibility.Never;
            btnZoomOut.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;

            btnOK.Visibility     = DevExpress.XtraBars.BarItemVisibility.Always;
            btnCancel.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;

            drawCmd = DrawCmd.DrawLine;
            Cursor  = Cursors.Cross;
        }
コード例 #12
0
 static bool CheckBlock(Player p, string value, string variable, ref int modify) {
     byte extBlock = 0;
     byte block = (byte)DrawCmd.GetBlock(p, value, out extBlock);
     if (block == Block.Invalid) return false;
     if (block >= Block.CpeCount && block != Block.custom_block) {
         Player.Message(p, "Cannot use physics block ids for /env."); return false;
     }
     
     if (block == Block.shrub || block == Block.yellowflower || block == Block.redflower ||
         block == Block.mushroom || block == Block.redmushroom || block == Block.rope || block == Block.fire) {
         Player.Message(p, "Env: Cannot use {0} for {1}.", block, variable);
     } else {
         modify = block == Block.custom_block ? extBlock : block;
         Player.Message(p, "Set {0} for {1} %Sto {2}", variable, p.level.ColoredName, modify);
         return true;
     }
     return false;
 }
コード例 #13
0
 internal static ExtBlock[] GetBlocks(Player p, int start, int max, string[] parts)
 {
     ExtBlock[] blocks = new ExtBlock[max - start];
     for (int i = 0; i < blocks.Length; i++)
     {
         blocks[i].Block = Block.Invalid;
     }
     for (int i = 0; start < max; start++, i++)
     {
         byte extBlock = 0;
         int  block    = DrawCmd.GetBlockIfAllowed(p, parts[start], out extBlock);
         if (block == -1)
         {
             return(null);
         }
         blocks[i].Block = (byte)block; blocks[i].Ext = extBlock;
     }
     return(blocks);
 }
コード例 #14
0
        private void ExitDrawLine()
        {
            btnAddLine.Visibility  = DevExpress.XtraBars.BarItemVisibility.Always;
            btnClose.Visibility    = DevExpress.XtraBars.BarItemVisibility.Always;
            btnBkColor.Visibility  = DevExpress.XtraBars.BarItemVisibility.Never;
            btnZoomIn.Visibility   = DevExpress.XtraBars.BarItemVisibility.Always;
            btnZoomOut.Visibility  = DevExpress.XtraBars.BarItemVisibility.Always;
            btnPanorama.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;

            btnOK.Visibility     = DevExpress.XtraBars.BarItemVisibility.Never;
            btnCancel.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            btnRecall.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            statusStrip1.Visible = false;

            valueX.Text = "";
            valueY.Text = "";
            drawCmd     = DrawCmd.None;
            Cursor      = Cursors.Arrow;
        }
コード例 #15
0
ファイル: ReplaceBrush.cs プロジェクト: Peteys93/MCGalaxy
 internal static ExtBlock[] GetBlocks(Player p, int start, int max, string[] parts)
 {
     ExtBlock[] blocks = new ExtBlock[max - start];
     for (int i = 0; i < blocks.Length; i++)
     {
         blocks[i].Type = Block.Zero;
     }
     for (int i = 0; start < max; start++, i++)
     {
         byte extType = 0;
         byte type    = DrawCmd.GetBlock(p, parts[start], out extType);
         if (type == Block.Zero)
         {
             continue;
         }
         blocks[i].Type = type; blocks[i].ExtType = extType;
     }
     return(blocks);
 }
コード例 #16
0
        public override Brush Construct(BrushArgs args)
        {
            if (args.Message == "")
            {
                if (!DrawCmd.CheckBlock(args.Player, args.Block))
                {
                    return(null);
                }
                return(new SolidBrush(args.Block, args.ExtBlock));
            }

            byte extBlock;
            int  block = DrawCmd.GetBlockIfAllowed(args.Player, args.Message, out extBlock);

            if (block == -1)
            {
                return(null);
            }
            return(new SolidBrush((byte)block, extBlock));
        }
コード例 #17
0
        static bool GetTargetBlock(BrushArgs args, string[] parts, out ExtBlock target)
        {
            target = default(ExtBlock);
            if (parts.Length == 1)
            {
                if (!DrawCmd.CheckBlock(args.Player, args.Block))
                {
                    return(false);
                }
                target = new ExtBlock(args.Block, args.ExtBlock);
                return(true);
            }

            int block = DrawCmd.GetBlockIfAllowed(args.Player, parts[parts.Length - 1], out target.Ext);

            if (block == -1)
            {
                return(false);
            }
            target.Block = (byte)block;
            return(true);
        }
コード例 #18
0
        static byte GetFallback(Player p, string value)
        {
            byte extBlock;
            int  block = DrawCmd.GetBlock(p, value, out extBlock);

            if (block == Block.custom_block)
            {
                Player.Message(p, "&cCustom blocks cannot be used as fallback blocks.");
                return(Block.Invalid);
            }
            if (block >= Block.CpeCount)
            {
                Player.Message(p, "&cPhysics block cannot be used as fallback blocks.");
                return(Block.Invalid);
            }
            if (block == Block.Invalid)
            {
                Player.Message(p, "&cCannot use 'skip block' as fallback block.");
                return(Block.Invalid);
            }
            return((byte)block);
        }
コード例 #19
0
ファイル: picture.cs プロジェクト: ragdollKB/2dFighter
        public void addDrawCmd(DrawCmd drawCmd)
        {
            this._drawCmds.Add(drawCmd);

            switch (drawCmd)
            {
            case DrawSave _:
                this._states.Add(this._getState().copy());
                break;

            case DrawSaveLayer cmd: {
                this._states.Add(new CanvasState {
                        xform       = Matrix3.I(),
                        scissor     = cmd.rect.shift(-cmd.rect.topLeft),
                        saveLayer   = true,
                        layerOffset = cmd.rect.topLeft,
                        paintBounds = Rect.zero,
                    });
                break;
            }

            case DrawRestore _: {
                var stateToRestore = this._getState();
                this._states.RemoveAt(this._states.Count - 1);
                var state = this._getState();

                if (!stateToRestore.saveLayer)
                {
                    state.paintBounds = stateToRestore.paintBounds;
                }
                else
                {
                    var paintBounds = stateToRestore.paintBounds.shift(stateToRestore.layerOffset);
                    paintBounds = state.xform.mapRect(paintBounds);
                    this._addPaintBounds(paintBounds);
                }
                break;
            }

            case DrawTranslate cmd: {
                var state = this._getState();
                state.xform = new Matrix3(state.xform);
                state.xform.preTranslate(cmd.dx, cmd.dy);
                break;
            }

            case DrawScale cmd: {
                var state = this._getState();
                state.xform = new Matrix3(state.xform);
                state.xform.preScale(cmd.sx, (cmd.sy ?? cmd.sx));
                break;
            }

            case DrawRotate cmd: {
                var state = this._getState();
                state.xform = new Matrix3(state.xform);
                if (cmd.offset == null)
                {
                    state.xform.preRotate(cmd.radians);
                }
                else
                {
                    state.xform.preRotate(cmd.radians,
                                          cmd.offset.dx,
                                          cmd.offset.dy);
                }
                break;
            }

            case DrawSkew cmd: {
                var state = this._getState();
                state.xform = new Matrix3(state.xform);
                state.xform.preSkew(cmd.sx, cmd.sy);
                break;
            }

            case DrawConcat cmd: {
                var state = this._getState();
                state.xform = new Matrix3(state.xform);
                state.xform.preConcat(cmd.matrix);
                break;
            }

            case DrawResetMatrix _: {
                var state = this._getState();
                state.xform = Matrix3.I();
                break;
            }

            case DrawSetMatrix cmd: {
                var state = this._getState();
                state.xform = new Matrix3(cmd.matrix);
                break;
            }

            case DrawClipRect cmd: {
                var state = this._getState();

                var rect = state.xform.mapRect(cmd.rect);
                state.scissor = state.scissor == null ? rect : state.scissor.intersect(rect);
                break;
            }

            case DrawClipRRect cmd: {
                var state = this._getState();

                var rect = state.xform.mapRect(cmd.rrect.outerRect);
                state.scissor = state.scissor == null ? rect : state.scissor.intersect(rect);
                break;
            }

            case DrawClipPath cmd: {
                var state = this._getState();
                var scale = XformUtils.getScale(state.xform);

                var rect = cmd.path.flatten(
                    scale * Window.instance.devicePixelRatio
                    ).getFillMesh(out _).transform(state.xform).bounds;
                state.scissor = state.scissor == null ? rect : state.scissor.intersect(rect);
                break;
            }

            case DrawPath cmd: {
                var state            = this._getState();
                var scale            = XformUtils.getScale(state.xform);
                var path             = cmd.path;
                var paint            = cmd.paint;
                var devicePixelRatio = Window.instance.devicePixelRatio;

                MeshMesh mesh;
                if (paint.style == PaintingStyle.fill)
                {
                    var cache = path.flatten(scale * devicePixelRatio);
                    mesh = cache.getFillMesh(out _).transform(state.xform);
                }
                else
                {
                    float strokeWidth = (paint.strokeWidth * scale).clamp(0, 200.0f);
                    float fringeWidth = 1 / devicePixelRatio;

                    if (strokeWidth < fringeWidth)
                    {
                        strokeWidth = fringeWidth;
                    }

                    var cache = path.flatten(scale * devicePixelRatio);
                    mesh = cache.getStrokeMesh(
                        strokeWidth / scale * 0.5f,
                        paint.strokeCap,
                        paint.strokeJoin,
                        paint.strokeMiterLimit).transform(state.xform);
                }

                if (paint.maskFilter != null && paint.maskFilter.sigma != 0)
                {
                    float sigma  = scale * paint.maskFilter.sigma;
                    float sigma3 = 3 * sigma;
                    this._addPaintBounds(mesh.bounds.inflate(sigma3));
                }
                else
                {
                    this._addPaintBounds(mesh.bounds);
                }
                break;
            }

            case DrawImage cmd: {
                var state = this._getState();
                var rect  = Rect.fromLTWH(cmd.offset.dx, cmd.offset.dy,
                                          cmd.image.width, cmd.image.height);
                rect = state.xform.mapRect(rect);
                this._addPaintBounds(rect);
                break;
            }

            case DrawImageRect cmd: {
                var state = this._getState();
                var rect  = state.xform.mapRect(cmd.dst);
                this._addPaintBounds(rect);
                break;
            }

            case DrawImageNine cmd: {
                var state = this._getState();
                var rect  = state.xform.mapRect(cmd.dst);
                this._addPaintBounds(rect);
                break;
            }

            case DrawPicture cmd: {
                var state = this._getState();
                var rect  = state.xform.mapRect(cmd.picture.paintBounds);
                this._addPaintBounds(rect);
                break;
            }

            case DrawTextBlob cmd: {
                var state = this._getState();
                var scale = XformUtils.getScale(state.xform);
                var rect  = cmd.textBlob.boundsInText.shift(cmd.offset);
                rect = state.xform.mapRect(rect);

                var paint = cmd.paint;
                if (paint.maskFilter != null && paint.maskFilter.sigma != 0)
                {
                    float sigma  = scale * paint.maskFilter.sigma;
                    float sigma3 = 3 * sigma;
                    this._addPaintBounds(rect.inflate(sigma3));
                }
                else
                {
                    this._addPaintBounds(rect);
                }

                break;
            }

            default:
                throw new Exception("unknown drawCmd: " + drawCmd);
            }
        }