Exemplo n.º 1
0
        private void weMapControl1_WEMouseMove(object sender, Point Location)
        {
            WEPoint location = WEMapTools.ToMapPoint(Location);

            tss2.Text = "X: " + location.X.ToString("0.0000") + ", Y: " + location.Y.ToString("0.0000");
            statusStrip1.Refresh();
        }
Exemplo n.º 2
0
        private static WEPoint[,] CreateStatueLetter(char Letter)
        {
            WEPoint[,] letter = new WEPoint[2, 3];
            short leftTop, a = 0;

            if ((Letter > 47) && (Letter < 58))
            {
                leftTop = (short)((Letter - 48) * 36);
            }
            else if ((Letter > 96) && (Letter < 123))
            {
                leftTop = (short)((Letter - 87) * 36);
            }
            else
            {
                return(letter);
            }

            for (short i = leftTop; i <= (leftTop + 18); i += 18)
            {
                int b = 0;
                for (short j = 0; j <= 36; j += 18)
                {
                    letter[a, b++] = new WEPoint(i, j);
                }
                a++;
            }
            return(letter);
        }
Exemplo n.º 3
0
        public static WEPoint[] CreateEllipseOutline(int x1, int y1, int x2, int y2)
        {
            Vector2 center = new Vector2((float)(x2 - x1) / 2, (float)(y2 - y1) / 2);
            float   rMax = Math.Max(center.X, center.Y), rMin = Math.Min(center.X, center.Y);

            if (center.Y > center.X)
            {
                float temp = rMax;
                rMax = rMin;
                rMin = temp;
            }

            List <WEPoint> points = new List <WEPoint>();

            for (int i = x1; i <= (x2 - ((x2 - x1) / 2)); i++)
            {
                for (int j = y1; j <= (y2 - ((y2 - y1) / 2)); j++)
                {
                    if (InEllipse(x1, y1, center.X, center.Y, rMax, rMin, i, j))
                    {
                        if (points.Count > 0)
                        {
                            WEPoint point = points.Last();
                            int     e     = j;
                            while (point.Y - e >= 1)
                            {
                                addPoint(points, x1, y1, x2, y2, i, e++);
                            }
                        }
                        else
                        {
                            int a = y1 + ((y2 - y1) / 2) - j;
                            if (a > 0)
                            {
                                int e = j;
                                while (a-- >= 0)
                                {
                                    addPoint(points, x1, y1, x2, y2, i, e++);
                                }
                            }
                        }
                        addPoint(points, x1, y1, x2, y2, i, j);
                        break;
                    }
                }
            }

            return(points.ToArray());
        }
Exemplo n.º 4
0
        public static WEPoint[,] CreateStatueText(string Text, int Width, int Height)
        {
            WEPoint[,] text = new WEPoint[Width, Height];
            if (string.IsNullOrWhiteSpace(Text))
            {
                return(text);
            }
            List <Tuple <WEPoint[, ], int> > rows = new List <Tuple <WEPoint[, ], int> >();

            string[] sRows  = Text.ToLower().Replace("\\n", "\n").Split('\n');
            int      height = 0;

            for (int i = 0; i < sRows.Length; i++)
            {
                Tuple <WEPoint[, ], int> row = CreateStatueRow(sRows[i], Width, i == 0);
                if ((height += (row.Item1.GetLength(1) + row.Item2)) > Height)
                {
                    break;
                }
                rows.Add(row);
            }

            int y = 0;

            foreach (Tuple <WEPoint[, ], int> row in rows)
            {
                y += row.Item2;
                int w = row.Item1.GetLength(0), h = row.Item1.GetLength(1);
                for (int i = 0; i < w; i++)
                {
                    for (int j = 0; j < h; j++)
                    {
                        if (j + y > Height)
                        {
                            break;
                        }
                        text[i, j + y] = row.Item1[i, j];
                    }
                }
                y += h;
            }
            return(text);
        }
Exemplo n.º 5
0
        private static Tuple <WEPoint[, ], int> CreateStatueRow(string Row, int Width, bool FirstRow)
        {
            Tuple <string, int, int, int> settings = RowSettings(Row, FirstRow);

            WEPoint[,] text = new WEPoint[Width, settings.Item4];
            List <char> letters = settings.Item1.ToCharArray().ToList();

            int diff = (int)Math.Ceiling((letters.Count * 2 - Width) / 2d), x = 0;

            if (diff > 0)
            {
                letters.RemoveRange(letters.Count - diff, diff);
            }

            if (settings.Item2 == 1 && letters.Count * 2 <= Width)
            {
                x = ((Width - (letters.Count * 2)) / 2);
            }
            else if (settings.Item2 == 2 && letters.Count * 2 <= Width)
            {
                x = (Width - (letters.Count * 2));
            }

            for (int k = 0; k < letters.Count; k++)
            {
                WEPoint[,] letter = CreateStatueLetter(letters[k]);
                for (int i = 0; i < 2; i++)
                {
                    if (i + x > Width)
                    {
                        break;
                    }
                    for (int j = 0; j < settings.Item4; j++)
                    {
                        text[x, j] = letter[i, j];
                    }
                    x++;
                }
            }
            return(new Tuple <WEPoint[, ], int>(text, settings.Item3));
        }
Exemplo n.º 6
0
        public override void Execute()
        {
            if (!CanUseCommand())
            {
                return;
            }
            if (shapeType != 0)
            {
                Position(true);
                Tools.PrepareUndo(x, y, x2, y2, plr);
            }
            else
            {
                Tools.PrepareUndo(Math.Min(x, x2), Math.Min(y, y2),
                                  Math.Max(x, x2), Math.Max(y, y2), plr);
            }
            int edits = 0;

            switch (shapeType)
            {
                #region Line

            case 0:
            {
                WEPoint[] points = Tools.CreateLine(x, y, x2, y2);
                if (wall)
                {
                    foreach (WEPoint p in points)
                    {
                        var tile = Main.tile[p.X, p.Y];
                        if (Tools.CanSet(false, Main.tile[p.X, p.Y], materialType,
                                         select, expression, magicWand, p.X, p.Y, plr))
                        {
                            Main.tile[p.X, p.Y].wall = (byte)materialType;
                            edits++;
                        }
                    }
                }
                else
                {
                    foreach (WEPoint p in points)
                    {
                        var tile = Main.tile[p.X, p.Y];
                        if (Tools.CanSet(true, Main.tile[p.X, p.Y], materialType,
                                         select, expression, magicWand, p.X, p.Y, plr))
                        {
                            SetTile(p.X, p.Y, materialType);
                            edits++;
                        }
                    }
                }
                break;
            }

                #endregion
                #region Rectangle

            case 1:
            {
                if (wall)
                {
                    for (int i = x; i <= x2; i++)
                    {
                        for (int j = y; j <= y2; j++)
                        {
                            if (Tools.CanSet(false, Main.tile[i, j], materialType,
                                             select, expression, magicWand, i, j, plr) &&
                                (filled ? true : WorldEdit.Selections["border"](i, j, plr)))
                            {
                                Main.tile[i, j].wall = (byte)materialType;
                                edits++;
                            }
                        }
                    }
                }
                else
                {
                    for (int i = x; i <= x2; i++)
                    {
                        for (int j = y; j <= y2; j++)
                        {
                            if (Tools.CanSet(true, Main.tile[i, j], materialType,
                                             select, expression, magicWand, i, j, plr) &&
                                (filled ? true : WorldEdit.Selections["border"](i, j, plr)))
                            {
                                SetTile(i, j, materialType);
                                edits++;
                            }
                        }
                    }
                }
                break;
            }

                #endregion
                #region Ellipse

            case 2:
            {
                #region Filled

                if (filled)
                {
                    if (wall)
                    {
                        for (int i = x; i <= x2; i++)
                        {
                            for (int j = y; j <= y2; j++)
                            {
                                if (Tools.CanSet(false, Main.tile[i, j], materialType,
                                                 select, expression, magicWand, i, j, plr) &&
                                    WorldEdit.Selections["ellipse"](i, j, plr))
                                {
                                    Main.tile[i, j].wall = (byte)materialType;
                                    edits++;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int i = x; i <= x2; i++)
                        {
                            for (int j = y; j <= y2; j++)
                            {
                                if (Tools.CanSet(true, Main.tile[i, j], materialType,
                                                 select, expression, magicWand, i, j, plr) &&
                                    WorldEdit.Selections["ellipse"](i, j, plr))
                                {
                                    SetTile(i, j, materialType);
                                    edits++;
                                }
                            }
                        }
                    }
                }

                #endregion
                #region NotFilled

                else
                {
                    WEPoint[] points = Tools.CreateEllipseOutline(x, y, x2, y2);
                    if (wall)
                    {
                        foreach (WEPoint p in points)
                        {
                            if (Tools.CanSet(false, Main.tile[p.X, p.Y], materialType,
                                             select, expression, magicWand, p.X, p.Y, plr))
                            {
                                Main.tile[p.X, p.Y].wall = (byte)materialType;
                                edits++;
                            }
                        }
                    }
                    else
                    {
                        foreach (WEPoint p in points)
                        {
                            if (Tools.CanSet(true, Main.tile[p.X, p.Y], materialType,
                                             select, expression, magicWand, p.X, p.Y, plr))
                            {
                                SetTile(p.X, p.Y, materialType);
                                edits++;
                            }
                        }
                    }
                }

                #endregion
                break;
            }

                #endregion
                #region IsoscelesTriangle, RightTriangle

            case 3:
            case 4:
            {
                WEPoint[] points, line1, line2;
                if (shapeType == 3)
                {
                    switch (rotateType)
                    {
                        #region Up

                    case 0:
                    {
                        int center = x + ((x2 - x) / 2);
                        points = Tools.CreateLine(center, y, x, y2)
                                 .Concat(Tools.CreateLine(center + ((x2 - x) % 2), y, x2, y2))
                                 .ToArray();
                        line1 = new WEPoint[]
                        {
                            new WEPoint((short)x, (short)y2),
                            new WEPoint((short)x2, (short)y2)
                        };
                        line2 = null;
                        break;
                    }

                        #endregion
                        #region Down

                    case 1:
                    {
                        int center = x + ((x2 - x) / 2);
                        points = Tools.CreateLine(center, y2, x, y)
                                 .Concat(Tools.CreateLine(center + ((x2 - x) % 2), y2, x2, y))
                                 .ToArray();
                        line1 = new WEPoint[]
                        {
                            new WEPoint((short)x, (short)y),
                            new WEPoint((short)x2, (short)y)
                        };
                        line2 = null;
                        break;
                    }

                        #endregion
                        #region Left

                    case 2:
                    {
                        int center = y + ((y2 - y) / 2);
                        points = Tools.CreateLine(x, center, x2, y)
                                 .Concat(Tools.CreateLine(x, center + ((y2 - y) % 2), x2, y2))
                                 .ToArray();
                        line1 = new WEPoint[]
                        {
                            new WEPoint((short)x2, (short)y),
                            new WEPoint((short)x2, (short)y2)
                        };
                        line2 = null;
                        break;
                    }

                        #endregion
                        #region Right

                    case 3:
                    {
                        int center = y + ((y2 - y) / 2);
                        points = Tools.CreateLine(x2, center, x, y)
                                 .Concat(Tools.CreateLine(x2, center + ((x2 - x) % 2), x, y2))
                                 .ToArray();
                        line1 = new WEPoint[]
                        {
                            new WEPoint((short)x, (short)y),
                            new WEPoint((short)x, (short)y2)
                        };
                        line2 = null;
                        break;
                    }

                        #endregion
                    default: return;
                    }
                }
                else
                {
                    switch (flipType)
                    {
                        #region Left

                    case 0:
                    {
                        switch (rotateType)
                        {
                            #region Up

                        case 0:
                        {
                            points = Tools.CreateLine(x, y2, x2, y);
                            line1  = new WEPoint[]
                            {
                                new WEPoint((short)x, (short)y2),
                                new WEPoint((short)x2, (short)y2)
                            };
                            line2 = new WEPoint[]
                            {
                                new WEPoint((short)x2, (short)y),
                                new WEPoint((short)x2, (short)y2)
                            };
                            break;
                        }

                            #endregion
                            #region Down

                        case 1:
                        {
                            points = Tools.CreateLine(x, y, x2, y2);
                            line1  = new WEPoint[]
                            {
                                new WEPoint((short)x, (short)y),
                                new WEPoint((short)x2, (short)y)
                            };
                            line2 = new WEPoint[]
                            {
                                new WEPoint((short)x2, (short)y),
                                new WEPoint((short)x2, (short)y2)
                            };
                            break;
                        }

                            #endregion
                        default: return;
                        }
                        break;
                    }

                        #endregion
                        #region Right

                    case 1:
                    {
                        switch (rotateType)
                        {
                            #region Up

                        case 0:
                        {
                            points = Tools.CreateLine(x, y, x2, y2);
                            line1  = new WEPoint[]
                            {
                                new WEPoint((short)x, (short)y),
                                new WEPoint((short)x, (short)y2)
                            };
                            line2 = new WEPoint[]
                            {
                                new WEPoint((short)x, (short)y2),
                                new WEPoint((short)x2, (short)y2)
                            };
                            break;
                        }

                            #endregion
                            #region Down

                        case 1:
                        {
                            points = Tools.CreateLine(x, y2, x2, y);
                            line1  = new WEPoint[]
                            {
                                new WEPoint((short)x, (short)y),
                                new WEPoint((short)x, (short)y2)
                            };
                            line2 = new WEPoint[]
                            {
                                new WEPoint((short)x, (short)y),
                                new WEPoint((short)x2, (short)y)
                            };
                            break;
                        }

                            #endregion
                        default: return;
                        }
                        break;
                    }

                        #endregion
                    default: return;
                    }
                }

                if (filled)
                {
                    switch (rotateType)
                    {
                        #region Up

                    case 0:
                    {
                        if (wall)
                        {
                            foreach (WEPoint p in points)
                            {
                                for (int y = p.Y; y <= y2; y++)
                                {
                                    var tile = Main.tile[p.X, y];
                                    if (Tools.CanSet(false, Main.tile[p.X, y], materialType,
                                                     select, expression, magicWand, p.X, y, plr))
                                    {
                                        Main.tile[p.X, y].wall = (byte)materialType;
                                        edits++;
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreach (WEPoint p in points)
                            {
                                for (int y = p.Y; y <= y2; y++)
                                {
                                    var tile = Main.tile[p.X, y];
                                    if (Tools.CanSet(true, Main.tile[p.X, y], materialType,
                                                     select, expression, magicWand, p.X, y, plr))
                                    {
                                        SetTile(p.X, y, materialType);
                                        edits++;
                                    }
                                }
                            }
                        }
                        break;
                    }

                        #endregion
                        #region Down

                    case 1:
                    {
                        if (wall)
                        {
                            foreach (WEPoint p in points)
                            {
                                for (int y = p.Y; y >= this.y; y--)
                                {
                                    var tile = Main.tile[p.X, y];
                                    if (Tools.CanSet(false, Main.tile[p.X, y], materialType,
                                                     select, expression, magicWand, p.X, y, plr))
                                    {
                                        Main.tile[p.X, y].wall = (byte)materialType;
                                        edits++;
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreach (WEPoint p in points)
                            {
                                for (int y = p.Y; y >= this.y; y--)
                                {
                                    var tile = Main.tile[p.X, y];
                                    if (Tools.CanSet(true, Main.tile[p.X, y], materialType,
                                                     select, expression, magicWand, p.X, y, plr))
                                    {
                                        SetTile(p.X, y, materialType);
                                        edits++;
                                    }
                                }
                            }
                        }
                        break;
                    }

                        #endregion
                        #region Left

                    case 2:
                    {
                        if (wall)
                        {
                            foreach (WEPoint p in points)
                            {
                                for (int x = p.X; x <= x2; x++)
                                {
                                    var tile = Main.tile[x, p.Y];
                                    if (Tools.CanSet(false, Main.tile[x, p.Y], materialType,
                                                     select, expression, magicWand, x, p.Y, plr))
                                    {
                                        Main.tile[x, p.Y].wall = (byte)materialType;
                                        edits++;
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreach (WEPoint p in points)
                            {
                                for (int x = p.X; x <= x2; x++)
                                {
                                    var tile = Main.tile[x, p.Y];
                                    if (Tools.CanSet(true, Main.tile[x, p.Y], materialType,
                                                     select, expression, magicWand, x, p.Y, plr))
                                    {
                                        SetTile(x, p.Y, materialType);
                                        edits++;
                                    }
                                }
                            }
                        }
                        break;
                    }

                        #endregion
                        #region Right

                    case 3:
                    {
                        if (wall)
                        {
                            foreach (WEPoint p in points)
                            {
                                for (int x = p.X; x >= this.x; x--)
                                {
                                    var tile = Main.tile[x, p.Y];
                                    if (Tools.CanSet(false, Main.tile[x, p.Y], materialType,
                                                     select, expression, magicWand, x, p.Y, plr))
                                    {
                                        Main.tile[x, p.Y].wall = (byte)materialType;
                                        edits++;
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreach (WEPoint p in points)
                            {
                                for (int x = p.X; x >= this.x; x++)
                                {
                                    var tile = Main.tile[x, p.Y];
                                    if (Tools.CanSet(true, Main.tile[x, p.Y], materialType,
                                                     select, expression, magicWand, x, p.Y, plr))
                                    {
                                        SetTile(x, p.Y, materialType);
                                        edits++;
                                    }
                                }
                            }
                        }
                        break;
                    }

                        #endregion
                    default: return;
                    }
                }
                else
                {
                    #region Wall

                    if (wall)
                    {
                        foreach (WEPoint p in points)
                        {
                            var tile = Main.tile[p.X, p.Y];
                            if (Tools.CanSet(false, Main.tile[p.X, p.Y], materialType,
                                             select, expression, magicWand, p.X, p.Y, plr))
                            {
                                Main.tile[p.X, p.Y].wall = (byte)materialType;
                                edits++;
                            }
                        }
                        for (int x = line1[0].X; x <= line1[1].X; x++)
                        {
                            for (int y = line1[0].Y; y <= line1[1].Y; y++)
                            {
                                var tile = Main.tile[x, y];
                                if (Tools.CanSet(true, Main.tile[x, y], materialType,
                                                 select, expression, magicWand, x, y, plr))
                                {
                                    Main.tile[x, y].wall = (byte)materialType;
                                    edits++;
                                }
                            }
                        }
                        if (line2 != null)
                        {
                            for (int x = line2[0].X; x <= line2[1].X; x++)
                            {
                                for (int y = line2[0].Y; y <= line2[1].Y; y++)
                                {
                                    var tile = Main.tile[x, y];
                                    if (Tools.CanSet(true, Main.tile[x, y], materialType,
                                                     select, expression, magicWand, x, y, plr))
                                    {
                                        Main.tile[x, y].wall = (byte)materialType;
                                        edits++;
                                    }
                                }
                            }
                        }
                    }

                    #endregion
                    #region Tile

                    else
                    {
                        foreach (WEPoint p in points)
                        {
                            var tile = Main.tile[p.X, p.Y];
                            if (Tools.CanSet(true, Main.tile[p.X, p.Y], materialType,
                                             select, expression, magicWand, p.X, p.Y, plr))
                            {
                                SetTile(p.X, p.Y, materialType);
                                edits++;
                            }
                        }
                        for (int x = line1[0].X; x <= line1[1].X; x++)
                        {
                            for (int y = line1[0].Y; y <= line1[1].Y; y++)
                            {
                                var tile = Main.tile[x, y];
                                if (Tools.CanSet(true, Main.tile[x, y], materialType,
                                                 select, expression, magicWand, x, y, plr))
                                {
                                    SetTile(x, y, materialType);
                                    edits++;
                                }
                            }
                        }
                        if (line2 != null)
                        {
                            for (int x = line2[0].X; x <= line2[1].X; x++)
                            {
                                for (int y = line2[0].Y; y <= line2[1].Y; y++)
                                {
                                    var tile = Main.tile[x, y];
                                    if (Tools.CanSet(true, Main.tile[x, y], materialType,
                                                     select, expression, magicWand, x, y, plr))
                                    {
                                        SetTile(x, y, materialType);
                                        edits++;
                                    }
                                }
                            }
                        }
                    }

                    #endregion
                }

                break;
            }

                #endregion
            }

            ResetSection();
            plr.SendSuccessMessage("Set {0}{1} shape. ({2})", filled ? "filled " : "", wall ? "wall" : "tile", edits);
        }