Example #1
0
        protected internal override VertexArray _ToVertexArray()
        {
            if (this._NeedsUpdate && this.Visible && this.Color.A > 0 && this.TextColor.A > 0)
            {
                this._NeedsUpdate = false;

                if (this.Texture != null)
                {
                    this.Texture.Dispose();
                }
                this.Texture = this.Font.GetImage(this.Content, this.TextColor, this.TabLength, this.SymbolTab, this.SymbolSpace);
            }

            Vector p = this.Origin * this.Size;

            this.Offset = (p % 1) * -1;

            VertexArray @out = new VertexArray(VertexArrayType.Quads);

            @out.Add(new Vertex(0, 0));
            @out.Add(new Vertex(this.Size.OnlyX, this.Size.OnlyX));
            @out.Add(new Vertex(this.Size, this.Size));
            @out.Add(new Vertex(this.Size.OnlyY, this.Size.OnlyY));
            return(@out);
        }
Example #2
0
        public override void Update()
        {
            double v = Meth.Limit(0, LocalMousePosition.X / Size.X * Sections, Sections);

            if (this.MouseArea.IsClicked)
            {
                this._Value = v;
            }

            this.Progress += ((this.MouseArea.IsHovered && !this.MouseArea.IsClicked ? 1 : 0) - this.Progress) * 0.3;

            this.Text.Color   ^= (byte)((255 - this.Progress * 255) * (this.MouseArea.IsClicked ? 1 : 0));
            this.Text.Origin   = new Vector(this.Value, 1);
            this.Text.Position = new Vector(this.Value * this.Size.X, this.Size.Y - this.Value * this.Size.Y - 6 + this.Value * 3);
            this.Text.Content  = this.ValueDisplay(this.Value);

            for (int i = 0; i < Sections; i++)
            {
                Progresses[i] += ((this._Value > i ? 1 : 0) - Progresses[i]) * 0.4;
            }

            this.VertexArray.Vertices.Clear();
            this.VertexArray.Add(0);
            this.VertexArray.Add(new Vector(Size.X, 0));
            for (int i = 0; i < Sections; i++)
            {
                double d = Meth.Abs((v - i) / Sections * Size.X);
                double f = (d <= Size.X / 4) ? 1 - Meth.RSmooth(d / (Size.X / 4)) * 0.2 * this.Progress : 1;

                VertexArray.Add(new Vector((i + 0.5) / (double)Sections * Size.X, -1));
                VertexArray.Add(new Vector((i + 0.5) / (double)Sections * Size.X, (Progresses[i] + (i > this._Value ? 1 - f : 0)) * i / Sections * -(Size.Y - 2) * f - 3));
            }
        }
Example #3
0
        protected internal override VertexArray _ToVertexArray()
        {
            VertexArray v = new VertexArray(VertexArrayType.TrianglesFan);

            v.Add(this.Radius, this.InnerColor.HasValue ? this.InnerColor.Value : Color.White);
            for (int i = 0; i < Quality; i++)
            {
                v.Add(this.Radius + Vector.FromAngle(i / (double)(Quality - 1) * Meth.Tau, this.Radius), this.OuterColor.HasValue ? this.OuterColor.Value : Color.White);
            }
            return(v);
        }
Example #4
0
        protected internal override VertexArray _ToVertexArray()
        {
            VertexArray @out = new VertexArray(VertexArrayType.TrianglesStrip);

            for (int i = 0; i <= Quality; i++)
            {
                @out.Add(this.Position + Vector.FromAngle(i / (double)Quality * Meth.Tau) * HoleRadius + this.HoleRadius);
                @out.Add(this.Position + Vector.FromAngle(i / (double)Quality * Meth.Tau) * Radius + this.Radius);
            }
            return(@out);
        }
Example #5
0
            public Rack(bool _fixedres)
            {
                double[] ls = new double[] { 15, 15, 30 };
                double[] ds = new double[] { 0.2, 0.1 };

                VertexArray lines = new VertexArray(VertexArrayType.LinesStrip)
                {
                    Color = Color.White * 0.25, /*Position = _fixedres ? 0.5 : 0, */ LockToGrid = _fixedres
                };

                lines.Add(new Vector(0, ls[2] * 7), new Vector(0, 0), new Vector(0, 0));

                for (int i = 0; i < 7; i++)
                {
                    Bunch <Vector> vs = new Bunch <Vector>();

                    vs.Add(new Vector(0, i * ls[2]));
                    //lines0.Add(new Vector(0, i * ls[2]), new Vector(0, (i + 1) * ls[2]));

                    Action <Vector> add = v =>
                    {
                        vs.Add(v);
                        lines.Add(v);
                    };

                    add(new Vector(ls[0], i * ls[2]));

                    //vs.Add(new Vector(ls[0] + ls[1], (i + 0.5) * ls[2]));
                    for (int n = 0; n <= 3; n++)
                    {
                        add(new Vector(ls[0] + Meth.Smooth(n / 3.0) * ls[1], i * ls[2] + ls[2] * ds[0] + ls[2] * ds[1] * (n / 3.0)));
                    }
                    for (int n = 0; n <= 3; n++)
                    {
                        add(new Vector(ls[0] + Meth.Smooth((3 - n) / 3.0) * ls[1], i * ls[2] + ls[2] * (1 - ds[0] - ds[1]) + ls[2] * ds[1] * (n / 3.0)));
                    }

                    add(new Vector(ls[0], (i + 1) * ls[2]));

                    vs.Add(new Vector(0, (i + 1) * ls[2]));

                    this.Graphics.Add(new VertexArray(VertexArrayType.TrianglesFan)
                    {
                        Vertices = new Vertex(new Vector(0, (i + 0.5) * ls[2]), Color.White) + vs.Select(item => (Vertex)item), Color = Color.White, LockToGrid = _fixedres
                    });
                }

                lines.Add(new Vector(0, ls[2] * 7));

                this.Graphics.Add(lines);
            }
Example #6
0
        internal override VertexArray _ToShapeVertexArray()
        {
            VertexArray @out = new VertexArray(VertexArrayType.Polygon);

            for (int i = 0; i <= Quality; i++)
            {
                @out.Add(this.Position + Vector.FromAngle(i / (double)Quality * Meth.Tau) * HoleRadius + HoleRadius);
            }
            for (int i = Quality; i >= 0; i--)
            {
                @out.Add(this.Position + Vector.FromAngle(i / (double)Quality * Meth.Tau) * Radius + Radius);
            }
            return(@out);
        }
Example #7
0
        public static VertexArray Draw(Vector _start, Vector _end, double _thickness, Color _color)
        {
            VertexArray @out = new VertexArray(VertexArrayType.Quads);

            double a = (_end - _start).Angle;

            for (int i = -1; i <= 1; i += 2)
            {
                @out.Add(_start + Vector.FromAngle(a + Meth.Tau / 4 * i, _thickness / 2), _color);
            }
            for (int i = 1; i >= -1; i -= 2)
            {
                @out.Add(_end + Vector.FromAngle(a + Meth.Tau / 4 * i, _thickness / 2), _color);
            }

            return(@out);
        }
Example #8
0
        internal VertexArray _GetPrimitive()
        {
            VertexArray v = new VertexArray(this._GetType())
            {
                Texture = this.Texture, BlendMode = this.BlendMode, Runtime = this.Runtime, SmoothTexture = this.SmoothTexture, Color = this.Color, Shader = this.Shader
            };

            foreach (Vertex vx in this._GetTransformedVertices())
            {
                v.Add(vx);
            }
            return(v);
        }
Example #9
0
        protected internal override VertexArray _ToVertexArray()
        {
            VertexArray @out = new VertexArray(VertexArrayType.Polygon);

            Vector         s  = this.Size - this.Edge * 2;
            Bunch <Vector> ps = new Bunch <Vector>(this.Edge, this.Edge + s.OnlyX, this.Edge + s, this.Edge + s.OnlyY);

            for (int n = 0; n < 4; n++)
            {
                for (int i = 0; i <= this.Quality; i++)
                {
                    @out.Add(ps[(n + 2) % 4] + Vector.FromAngle(i / (double)this.Quality * Meth.Tau / 4 + Meth.Tau / 4 * n) * this.Edge);
                }
            }

            return(@out);
        }
Example #10
0
            public Gear(bool _fixedres)
            {
                double[] ls = new double[] { 20, 20, 20, 15 };
                double[] fs = new double[] { 0.1, 0.15 };

                VertexArray lines0 = new VertexArray(VertexArrayType.LinesStrip)
                {
                    Color = Color.White * 0.25, LockToGrid = _fixedres
                };
                VertexArray lines1 = new VertexArray(VertexArrayType.LinesStrip)
                {
                    Color = Color.White * 0.25, LockToGrid = _fixedres
                };

                for (int i = 0; i < 10; i++)
                {
                    Bunch <Vector> vs = new Bunch <Vector>();

                    double a0 = Meth.Tau / 10 * i;
                    double a1 = Meth.Tau / 10 * (i + 1);

                    //vs.Add(Vector.FromAngle(a1, ls[0]), Vector.FromAngle(a0, ls[0]));

                    //double ag = (a0 + a1) / 2;
                    //Vector vg = Vector.FromAngle(ag, ls[2]);
                    //Vector va = Vector.FromAngle(ag + Meth.Tau / 4);

                    Action <Vector> add = v =>
                    {
                        vs.Add(v);
                        lines1.Add(v);
                    };

                    for (int n = 0; n <= 2; n++)
                    {
                        vs.Add(Vector.FromAngle(a1 - (a1 - a0) / 2 * n, ls[0]));
                    }
                    for (int n = 2; n >= 0; n--)
                    {
                        lines0.Add(Vector.FromAngle(a1 - (a1 - a0) / 2 * n, ls[0]));
                    }

                    Vector va0 = Vector.FromAngle(a0, ls[0] + ls[1]);
                    Vector va1 = Vector.FromAngle(a1, ls[0] + ls[1]);

                    Vector dif = Vector.FromAngle(a1, ls[0] + ls[1]) - Vector.FromAngle(a0, ls[0] + ls[1]);

                    for (int n = 0; n <= 2; n++)
                    {
                        add(Vector.FromAngle(a0 + ((va0 + dif * fs[0]).Angle - a0) / 2 * n, ls[0] + ls[1]));
                    }

                    for (int n = 0; n <= 3; n++)
                    {
                        add(va0 + dif * fs[0] + dif * (n / 3.0) * fs[1] + Vector.FromAngle(dif.Angle - Meth.Tau / 4, Meth.Smooth(n / 3.0) * ls[3]));
                    }
                    for (int n = 0; n <= 3; n++)
                    {
                        add(va0 + dif * (1 - fs[0] - fs[1]) + dif * (n / 3.0) * fs[1] + Vector.FromAngle(dif.Angle - Meth.Tau / 4, Meth.Smooth((3 - n) / 3.0) * ls[3]));
                    }

                    //vs.Add(Vector.FromAngle(a1, ls[0] + ls[1]));

                    for (int n = 0; n <= 2; n++)
                    {
                        add(Vector.FromAngle((va0 + dif * (1 - fs[0])).Angle + (a1 - (va0 + dif * (1 - fs[0])).Angle) / 2 * n, ls[0] + ls[1]));
                    }

                    //vs.Add(va1);

                    //for (int s = -1; s <= -1; s += 2)
                    //{
                    //	Vector p = Vector.FromAngle((s == 1) ? a1 : a0, ls[0] + ls[1]);
                    //	for (int n = 0; n <= 10; n++)
                    //		vs.Add(p + (vg * Meth.Smooth(n / 10.0) + va * ls[3] * (n / 10.0)) * s);
                    //}

                    this.Graphics.Add(new VertexArray(VertexArrayType.Polygon)
                    {
                        Vertices = vs.Select(item => (Vertex)item), Color = Color.White, LockToGrid = _fixedres
                    });
                }

                this.Graphics.Add(lines0, lines1);
            }
Example #11
0
        public override void OnInitialization()
        {
            if (this.LoadInfo == null)
            {
                this.EntityZ = (this.Type.Name == "Decoration") ? -1 : 0;

                if (this.Type.Name != "Decoration")
                {
                    this.Properties.First(item => item.Name == "Identifier").Value = this.Type.Name + this.Parents[0].Children.GetTypes <EntityIcon>().Count(item => item.Type.Name == this.Type.Name).ToString();
                }
            }
            else
            {
                this.LoadFromItem(this.LoadInfo);
            }

            ImageSource src = this.Type.Name == "Decoration" ? this.Parent.Areasets.First(item => item.Value.Name == this.Properties.First(prop => prop.Name == "Areaset").Value).Value.Decorations[this.Properties.First(item => item.Name == "Name").Value] : this.Type.Icon;

            Image img0 = (new Image(src)
            {
                Origin = this.Type.Origin
            }).Extend();

            img0.Shader = Shader.Outline;
            this.Graphics.Add(this.Icon = img0);

            Image img1 = (new Image(src)
            {
                Origin = this.Type.Origin
            }).Extend();

            img1.Shader = Shader.Outline;
            img1.Z      = 8;
            this.Graphics.Add(this.IconOverlay = img1);

            if (this.Type.Entrance)
            {
                VertexArray v = new VertexArray(VertexArrayType.Triangles);
                v.Add(new Vector(0, -8), new Vector(6, -4), new Vector(0, 0));
                v.Position = new Vector(this.Icon.Scale.X * this.Icon.Width * this.Icon.Origin.X * -1, this.Icon.Scale.Y * this.Icon.Height * (1 - this.Icon.Origin.Y)) + new Vector(1, -1);
                v.Z        = 8;

                this.Graphics.Add(this.TestButton = v);
                this.AddMouseArea(this.TestArea   = new MouseArea(v)
                {
                    Z = 8, OnClick = key => { this.LevelEditor.Test(this.Properties.First(item => item.Name == "Identifier").Value); this.TestArea._ClickedKey = null; }
                });
            }



            this.AddMouseArea(this.Area = new MouseArea(this.Icon)
            {
                _IsDragged = this.Dragged, Draggable = true, ClickableBy = new Bunch <Key>(Key.MouseLeft, Key.MouseDown, Key.MouseUp), OnClick = key =>
                {
                    if (key == Key.MouseLeft)
                    {
                        this.LevelEditor.EntityEditor.Select(this);
                    }
                    else
                    {
                        this.LevelEditor.LevelPreview.Zoom((key == Key.MouseDown) ? 0.5 : 2, this.TileEditor.LocalMousePosition);
                    }
                }
            });

            this._IsDragged = this.Dragged;
        }
Example #12
0
        private void CreateColliders()
        {
            int width  = this.Size.X - 2;
            int height = this.Size.Y - 2;

            Point dir = Point.Right;

            for (int d = 0; d < 4; d++)
            {
                dir = dir.NextClockwise;
                Point up = dir.NextAntiClockwise;

                bool[,] done = new bool[width + 2, height + 2];

                while (true)
                {
                    bool b = true;
                    for (int x = 0; x < width + 2; x++)
                    {
                        for (int y = 0; y < height + 2; y++)
                        {
                            if (!done[x, y])
                            {
                                b = false;
                            }
                        }
                    }

                    if (b)
                    {
                        break;
                    }
                    else
                    {
                        for (int x = 0; x < width + 2; x++)
                        {
                            for (int y = 0; y < height + 2; y++)
                            {
                                if (!done[x, y] && this.Collisions[x, y] && !this.Collisions[x + up.X, y + up.Y])
                                {
                                    int  wr = 0;
                                    int  wl = 0;
                                    bool er = false;
                                    bool el = false;

                                    while (true)
                                    {
                                        wr++;

                                        if (!this.Collisions[x + dir.X * wr, y + dir.Y * wr])
                                        {
                                            wr--;
                                            er = true;
                                            break;
                                        }
                                        else if (this.Collisions[x + dir.X * wr + up.X, y + dir.Y * wr + up.Y])
                                        {
                                            break;
                                        }
                                    }
                                    while (true)
                                    {
                                        wl++;

                                        if (!this.Collisions[x - dir.X * wl, y - dir.Y * wl])
                                        {
                                            wl--;
                                            el = true;
                                            break;
                                        }
                                        else if (this.Collisions[x - dir.X * wl + up.X, y - dir.Y * wl + up.Y])
                                        {
                                            break;
                                        }
                                    }

                                    VertexArray v = new VertexArray(VertexArrayType.Quads)
                                    {
                                        Color = Color.Green ^ 170, Scale = this._Game.TileSize / this._Game.TileCollisionResolution, Z = 1000
                                    };

                                    Vector endlu = new Vector(el ? -0.5 : 0.5, -0.5);
                                    endlu.Angle += dir.Angle;

                                    Vector endru = new Vector(er ? 0.5 : -0.5, -0.5);
                                    endru.Angle += dir.Angle;

                                    Vector p = new Vector(x + 0.5, y + 0.5);
                                    v.Add(p - wl * (Vector)dir + endlu - 1);
                                    v.Add(p - wl * (Vector)dir - 1);
                                    v.Add(p + wr * (Vector)dir - 1);
                                    v.Add(p + wr * (Vector)dir + endru - 1);

                                    //v.Add(p - wl * 0.9 * (Vector)dir + endlu - 1);
                                    //v.Add(p - wl * (Vector)dir + endlu * 0.9 - 1);
                                    //v.Add(p - wl * (Vector)dir + endlu * 0.1 - 1);
                                    //v.Add(p - wl * 0.9 * (Vector)dir + endlu * 0.1 - 1);
                                    //v.Add(p + wr * 0.9 * (Vector)dir - 1);
                                    //v.Add(p + wr * (Vector)dir + endru * 0.1 - 1);
                                    //v.Add(p + wr * (Vector)dir + endru * 0.9 - 1);
                                    //v.Add(p + wr * 0.9 * (Vector)dir + endru - 1);

                                    this.Colliders.Add(new Collider(v));

                                    for (int i = -wl; i <= wr; i++)
                                    {
                                        done[x + i * dir.X, y + i * dir.Y] = true;
                                    }
                                }
                                else
                                {
                                    done[x, y] = true;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #13
0
        public static VertexArray DrawMultiple(Vector[] _points, double _thickness, FrameCurve _curve, FrameCurve _r, FrameCurve _g, FrameCurve _b)
        {
            Bunch <Vector>[] npoints = new Bunch <Vector>[] { new Bunch <Vector>(), new Bunch <Vector>() };

            for (int i = 0; i < _points.Length - 1; i++)
            {
                double a = (_points[i + 1] - _points[i]).Angle;
                for (int x = 0; x < 2; x++)
                {
                    for (int y = 0; y < 2; y++)
                    {
                        npoints[y].Add(_points[i + x] + Vector.FromAngle(a + Meth.Tau / 4 + Meth.Tau / 2 * y, _curve.GetValue((i + x) / (double)(_points.Length - 1)) / 2 * _thickness));
                    }
                }
            }

            //VertexArray v = new VertexArray(VertexArrayType.Quads);
            //for (int i = 0; i < npoints[0].LastIndex; i++)
            //{
            //	Color c1 = GetColor(i / (double)npoints[0].LastIndex, _r, _g, _b);
            //	Color c2 = GetColor((i + 1) / (double)npoints[0].LastIndex, _r, _g, _b);

            //	v.Add(npoints[0][i], c1);
            //	v.Add(npoints[1][i], c1);
            //	v.Add(npoints[1][i + 1], c2);
            //	v.Add(npoints[0][i + 1], c2);
            //}

            VertexArray v = new VertexArray(VertexArrayType.Triangles)
            {
                Color = Color.Black
            };

            for (int i = 0; i < npoints[0].LastIndex; i++)
            {
                Color c1 = GetColor(i / (double)npoints[0].LastIndex, _r, _g, _b);
                Color c2 = GetColor((i + 1) / (double)npoints[0].LastIndex, _r, _g, _b);

                v.Add(npoints[0][i], c1);
                v.Add(npoints[1][i], c1);
                v.Add(npoints[1][i + 1], c2);

                v.Add(npoints[1][i + 1], c2);
                v.Add(npoints[0][i + 1], c2);
                v.Add(npoints[0][i], c1);
            }

            if (_points.Length > 1)
            {
                for (int n = 0; n < 2; n++)
                {
                    Vector p = _points[n * (_points.Length - 1)];
                    int    q = Meth.Up(_points.Length / 2.0);

                    Color  c = GetColor(n, _r, _g, _b);
                    double t = _thickness * _curve.GetValue(n) / 2;

                    double a = ((n == 0) ? (_points[0] - _points[1]).Angle : (_points[_points.Length - 1] - _points[_points.Length - 2]).Angle) - Meth.Tau / 4;

                    for (int i = 0; i < q; i++)
                    {
                        v.Add(p, c);
                        v.Add(p + Vector.FromAngle(a + i / (double)q * Meth.Tau / 2, t), c);
                        v.Add(p + Vector.FromAngle(a + (i + 1) / (double)q * Meth.Tau / 2, t), c);
                    }
                }
            }

            return(v);
        }