Esempio n. 1
0
        public static Color FromHsv(double _hue, double _saturation, double _value)
        {
            double c = _value * _saturation;
            double h = Meth.RMod(_hue, 1) * 6;
            double x = c * (1 - Meth.Abs(h % 2 - 1));

            double r = 0, g = 0, b = 0;

            if (0 <= h && h < 1)
            {
                r = c;
                g = x;
            }
            else if (1 <= h && h < 2)
            {
                r = x;
                g = c;
            }
            else if (2 <= h && h < 3)
            {
                g = c;
                b = x;
            }
            else if (3 <= h && h < 4)
            {
                g = x;
                b = c;
            }
            else if (4 <= h && h < 5)
            {
                b = c;
                r = x;
            }
            else if (5 <= h && h < 6)
            {
                b = x;
                r = c;
            }

            double m = _value - c;

            return(new Color((byte)((r + m) * 255), (byte)((g + m) * 255), (byte)((b + m) * 255)));
        }
Esempio n. 2
0
        public int GetCharPosition(Vector _pos)
        {
            string c = this.Content;

            int y = (int)Meth.Limit(0, Meth.Down((_pos.Y - this.Edge.Y) / this.Font.CharSize), this.Lines.Length - 1);

            string[] lines = c.Split('\n');
            string   line  = lines[y];

            int  pos = 0;
            bool b   = false;

            for (int i = 0; i < line.Length; i++)
            {
                this._Text._Text.Content = line.Substring(0, i);
                double first = this._Text.Width;
                this._Text._Text.Content = line.Substring(0, i + 1);
                double second = this._Text.Width;

                if (_pos.X - this.Edge.X < first + (second - first) / 2 - 3)
                {
                    pos = i;
                    b   = true;
                    break;
                }
            }

            if (!b)
            {
                pos = line.Length;
            }

            int p = 0;

            for (int i = 0; i < y; i++)
            {
                p += lines[i].Length + 1;
            }
            p += pos;
            this._Text._Text.Content = c;
            return(p);
        }
Esempio n. 3
0
        public override void OnInitialization()
        {
            base.OnInitialization();

            this.Parent.Background = Color.Black;

            this.Scale = Meth.Min(this.Parent.Resolution.X / 960.0, this.Parent.Resolution.Y / 480.0);

            this.Children.Add(this._Sides = new Rack[] { new Rack(this.Parent.FixedResolution)
                                                         {
                                                             Position = new Vector(-75, -75)
                                                         }, new Rack(this.Parent.FixedResolution)
                                                         {
                                                             Position = new Vector(75, -75), Scale = new Vector(-1, 1)
                                                         } });
            this.Children.Add(this._Middle = new Gear(this.Parent.FixedResolution)
            {
                X = -1
            });

            this.Graphics.Add(this._Cutoffs = new Rectangle[] { new Rectangle(-80, 70, 160, 200)
                                                                {
                                                                    Color = Color.Black, Z = 1
                                                                }, new Rectangle(-80, -70, 160, -200)
                                                                {
                                                                    Color = Color.Black, Z = 1
                                                                } });

            FontBase f = FontBase.Consolas;

            f.CharSize = 150;
            for (int i = 0; i < 6; i++)
            {
                this.Graphics.Add(this._Letters[i] = new Text(f)
                {
                    Content = "ekanik"[i].ToString(), TextColor = Color.Black, Position = new Vector(50, -5) + new Vector(70, 0) * i
                });
            }

            this.Position = this.Parent.Resolution / 2;
        }
Esempio n. 4
0
        public override void OnInitialization()
        {
            this.Children.Add(this.EntityEditor);

            Dictionary <string, Bunch <EntityTile> > groups = new Dictionary <string, Bunch <EntityTile> >();

            foreach (EntityType t in this.Entities.Where(item => item.Name != "Decoration"))
            {
                if (!groups.ContainsKey(t.Group))
                {
                    groups[t.Group] = new Bunch <EntityTile>();
                }
                groups[t.Group].Add(new EntityTileNormal(t)
                {
                    Types = this.Entities
                });
            }

            foreach (Areaset a in this.Parent.Areasets.Select(item => item.Value).Where(item => item.Decorations.Count > 0))
            {
                groups["Decoration " + a.Name] = new Bunch <EntityTile>();
                foreach (KeyValuePair <string, ImageSource> decoration in a.Decorations)
                {
                    groups["Decoration " + a.Name].Add(new EntityTileDecoration(a, decoration.Key)
                    {
                        Types = this.Entities
                    });
                }
            }

            foreach (KeyValuePair <string, Bunch <EntityTile> > g in groups.OrderBy(item => item.Key.GetAlphabetIndex()))
            {
                int           height = Meth.Up(g.Value.Count / (double)this.Size.X);
                CollapseGroup c      = new CollapseGroup(FontBase.Consolas, g.Key, new EntityGroup(g.Value, this.Editor.TileEditor, this.EntityEditor, new Point(this.Size.X, height)))
                {
                    InnerHeight = height * this.Parent.TileSize.Y * 2, Width = this.Size.X * this.Parent.TileSize.X * 2
                };
                this.Groups.Add(c);
                this.Children.Add(c);
            }
        }
Esempio n. 5
0
        public static double GetRadialDifference(Vector _one, Vector _two)
        {
            Bunch <double> diffs = new Bunch <double>()
            {
                _two.Angle - _one.Angle - Meth.Tau, _two.Angle - _one.Angle, _two.Angle - _one.Angle + Meth.Tau
            };
            double min = double.MaxValue;

            foreach (double diff in diffs)
            {
                if (Meth.Abs(diff) < Meth.Abs(min))
                {
                    min = diff;
                }
            }
            if (min == Meth.Tau / -2)
            {
                return(Meth.Tau / 2);
            }
            return(min);
        }
Esempio n. 6
0
        public void Load(MekaItem _file)
        {
            Areaset a = new Areaset(_file, this.Parent.TileSize, this.Parent.TileCollisionResolution);

            this.TilesetSource = GameBase.LoadImageSource(_file["Tileset"].Data);
            this.Colset        = new byte[this.TileCount.X * this.Parent.TileCollisionResolution.X, this.TileCount.Y * this.Parent.TileCollisionResolution.Y][, ];

            for (int i = 0; i < a.Cols.Count; i++)
            {
                Point p = new Point(i % this.TileCount.X, Meth.Down(i / this.TileCount.X));
                this.Colset[p.X, p.Y] = a.Cols[i].Select(item => (byte)(item ? 1 : 0));

                for (int cx = 0; cx < this.Parent.TileCollisionResolution.X; cx++)
                {
                    for (int cy = 0; cy < this.Parent.TileCollisionResolution.Y; cy++)
                    {
                        this.ColPreviewSource[p.X * this.Parent.TileCollisionResolution.X + cx, p.Y *this.Parent.TileCollisionResolution.Y + cy] = (this.Colset[p.X, p.Y][cx, cy] == 1) ? Color.White : Color.Transparent;
                    }
                }
            }
        }
Esempio n. 7
0
        //public Tuple<Point, Point> GetMousePosition()
        //{
        //	Point tile = this.LocalMousePosition / this.Parent.Tilesize;
        //	Point col = (this.LocalMousePosition - tile * this.Parent.Tilesize) / (this.Parent.Tilesize / this.Parent.TileCollisionResolution);
        //	return new Tuple<Point, Point>(tile, col);
        //}

        public override void Update()
        {
            if (this.MouseArea.IsClicked)
            {
                bool key = this.MouseArea.ClickedBy(Key.MouseLeft);

                Point m = (this.LocalMousePosition - new Vector(this.AlignmentZoom.RectSize.X, 0)) / (this.Parent.TileSize / this.Parent.TileCollisionResolution) / this.Zoom;
                foreach (Point p in Line.Trace(this.LastPosition, m).Where(item => (new Rect(0, this.TileCount * this.Parent.TileCollisionResolution)).Contains(item)))
                {
                    Point tile = p / this.Parent.TileCollisionResolution;
                    Point col  = p % this.Parent.TileCollisionResolution;

                    this.Colset[tile.X, tile.Y][col.X, col.Y] = (byte)(key ? 1 : 0);
                    this.ColPreviewSource[tile.X * this.Parent.TileCollisionResolution.X + col.X, tile.Y *this.Parent.TileCollisionResolution.Y + col.Y] = key ? Color.White : Color.Transparent;
                }
                this.LastPosition = m;
            }

            byte b = (byte)((Meth.Sin(this.Runtime / 120.0 * Meth.Tau) + 1) / 2 * 85);

            this.ColPreview.Color = new Color(b) ^ 170;
        }
Esempio n. 8
0
        public static string CreateTempFile(byte[] _bytes, string _name = "", string _extension = "")
        {
            if (!File.Exists(GameBase.TempPath))
            {
                File.CreateFolder(GameBase.TempPath);
            }

            if (_extension != "")
            {
                _extension = "." + _extension;
            }

            string n    = _name;
            string path = GameBase.TempPath + _name + _extension;

            while (File.Exists(path) || n == "")
            {
                path = GameBase.TempPath + (n = _name + Meth.Abs(Meth.RandomInt).ToString()) + _extension;
            }

            File.Write(path, _bytes);
            return(path);
        }
Esempio n. 9
0
        public override void Update()
        {
            bool rebind = (this.Progress != 0 && this.Progress != 1);

            this.Progress += ((this.Opened ? 1 : 0) - this.Progress) / 3;
            if (Meth.Abs(this.Progress - (this.Opened ? 1 : 0)) < 0.01)
            {
                this.Progress = this.Opened ? 1 : 0;
            }

            this.Text.Position.Y   = BarHeight / 2 + this.InnerHeight * this.Progress - this.Text.Height / 2;
            this.Bar.Position.Y    = this.InnerHeight * this.Progress;
            this.Triangle.Position = new Vector(this.Width - this.BarHeight / 2, this.BarHeight / 2 + this.InnerHeight * this.Progress);

            this.ChildArea.Scale = new Vector(1, this.Progress);

            if (rebind)
            {
                this.BarArea.Shape = this.Bar;
            }

            this.Triangle.Scale = new Vector(1, (this.Progress * 2 - 1) * -1);
        }
Esempio n. 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);
            }
Esempio n. 11
0
        public override void Update()
        {
            this._Sides[0].Y = -75 - ((this._Middle.Rotation / Meth.Tau * 10 * 30 + 5) % 30 - 5);
            this._Sides[1].Y = -75 + (this._Middle.Rotation / Meth.Tau * 10 * 30 + 25) % 30 - 25;

            if (this.Runtime == 330)
            {
                this._Done        = true;
                this._Middle.Done = true;
            }

            if (this._Done && this._DoneProgress0 < 100)
            {
                this._DoneProgress0++;

                this._Cutoffs[0].Position.Y += 1;
                this._Cutoffs[1].Position.Y -= 0.5;

                this.Position = this.Parent.Resolution / 2 - (Point)(new Vector(220, 70) * Meth.Smooth(this._DoneProgress0 / 100.0) * this.Scale);
            }

            if (this._Done && this._DoneProgress0 >= 50 && this._DoneProgress1 < 80)
            {
                this._DoneProgress1++;

                for (int i = 0; i < 6; i++)
                {
                    this._Letters[i].Color = Color.White * Meth.Limit(0, Meth.Smooth(this._DoneProgress1 / 80.0) * 6 - i, 1);
                }
            }

            this.Parent.Title = this.Parent.Fps.ToString();
        }
Esempio n. 12
0
        public Rect MakeFit(Vector _size)
        {
            double s = Meth.Min(this.Width / _size.X, this.Height / _size.Y);

            return(new Rect((this.Size - _size * s) / 2, _size * s));
        }
Esempio n. 13
0
 public int GetLeft()
 {
     return(Meth.Min(this.CursorPosition, this.CursorPosition + this.SelectionLength));
 }
Esempio n. 14
0
 internal override double _GetRectHeight() => Meth.Max((this.FixedSize != 0) ? this.FixedSize.Y : this._Text.Height + this.Edge.Y * 2, this.MinSize.Y);
Esempio n. 15
0
 public static Vector FromAngle(double _angle, double _length = 1) => new Vector(Meth.Cos(_angle), Meth.Sin(_angle)) * _length;
Esempio n. 16
0
 internal override double _GetRectHeight() => Meth.Max(this.Bottom.Y + this.Bottom.RectSize.Y, this.Spritesheet.Height * this.Spritesheet.Scale.Y * 2);
Esempio n. 17
0
 public static Vector operator %(Vector _one, Vector _two) => new Vector(Meth.RMod(_one.X, _two.X), Meth.RMod(_one.Y, _two.Y));
Esempio n. 18
0
        public override void Update()
        {
            base.Update();

            this._Sides[0].Y = -75 - Meth.Up((this._Middle.Rotation / Meth.Tau * 10 * 30 + 5) % 30 - 5);
            this._Sides[1].Y = -75 + Meth.Up((this._Middle.Rotation / Meth.Tau * 10 * 30 + 25) % 30 - 25);

            DateTime start = DateTime.Now;

            while ((DateTime.Now - start).TotalMilliseconds < 3 && this._Loadables.Count > 0)
            {
                if (this._Loadables[0].FinishedLoading)
                {
                    this._Loadables.RemoveAt(0);
                    if (this._Loadables.Count == 0)
                    {
                        this._DoneLoading = true;
                        this.Skippable    = true;
                    }
                }
                else
                {
                    this._Loadables[0].LoadStep();
                }
            }

            if (this.Runtime % 110 == 0 && this._DoneLoading)
            {
                this._Done        = true;
                this._Middle.Done = true;
                this.Skippable    = true;
            }

            if (this._Done && this._DoneProgress0 < 100)
            {
                this._DoneProgress0++;

                this._Cutoffs[0].Position.Y += 1;
                this._Cutoffs[1].Position.Y -= 0.5;

                this.Position = this.Parent.Resolution / 2 - (Point)(new Vector(220, 70) * Meth.Smooth(this._DoneProgress0 / 100.0) * this.Scale);
            }

            if (this._Done && this._DoneProgress0 >= 50 && this._DoneProgress1 < 80)
            {
                this._DoneProgress1++;

                for (int i = 0; i < 6; i++)
                {
                    this._Letters[i].TextColor = Color.White * Meth.Limit(0, Meth.Smooth(this._DoneProgress1 / 80.0) * 6 - i, 1);
                }
            }

            if (this._DoneProgress1 >= 80 && this._DoneProgress1 < 120)
            {
                this._DoneProgress1++;
            }

            if (this._DoneProgress1 == 120)
            {
                this._DoneProgress2++;
                this.Color = Color.White * Meth.Smooth(1 - this._DoneProgress2 * 3 / 255.0);
                if (this._DoneProgress2 == 85)
                {
                    this.Kill();
                }
            }
        }
Esempio n. 19
0
 public int GetRight()
 {
     return(Meth.Max(this.CursorPosition, this.CursorPosition + this.SelectionLength));
 }
Esempio n. 20
0
        public override void Update()
        {
            if (this.Scrolling && (this.LocalMousePosition - this.ScrollStart).Length >= 2)
            {
                this.Scrolling = false;
            }
            //if (this.Scrolling)
            //	Parent.CursorVisible = false;

            this.Index     += (this.TargetIndex - this.Index) / 5;
            this.Expansion += ((this.MouseArea.IsHovered ? 1 : 0) - this.Expansion) / 5;

            this.Quad.Rotation += ((this.TargetQuadRot * Meth.Tau / -4) - this.Quad.Rotation) / 5;
            if (Meth.Abs(this.Quad.Rotation - this.TargetQuadRot * Meth.Tau / -4) < 0.1)
            {
                this.Quad.Rotation = this.TargetQuadRot * Meth.Tau / -4;
            }

            this.Quad.Scale = new Vector(1, 2 / 3.0 + this.Expansion / 3.0);
            if (Meth.Abs(this.TargetQuadRot % 2) == 1)
            {
                this.Quad.Scale.Angle += Meth.Tau / 4;
            }

            if (this.LastHovered != this.MouseArea.IsHovered)
            {
                this.LastHovered = this.MouseArea.IsHovered;

                if (!this.MouseArea.IsHovered)
                {
                    this.MouseArea.Shape = new Rectangle(this.Labels[this.TargetIndex].Position, this.Labels[this.TargetIndex].Size);
                }
            }

            if (Meth.Abs(this.TargetIndex - this.Index) < 0.05)
            {
                this.Index = this.TargetIndex;
            }

            for (int i = 0; i < this.Labels.Count; i++)
            {
                byte a = (byte)(Meth.Pow(Meth.Limit(0, 3 - Meth.Abs(i - this.Index), 3) / 3.0 * ((i == this.TargetIndex) ? 1 : this.Expansion), 0.4) * 255);

                //if (a != 0 && !this.Labels[i].Visible)
                //{
                //	this.Labels[i].Visible = true;
                //	//this.Labels[i].Shader = Shader.TextOutline;
                //	//this.Labels[i].Shader["Color"] = Color.Red;

                //	//this.Labels[i].RenderIntermediately = true;
                //	//this.Labels[i].RenderGraphicsIntermediately = true;
                //	//this.Labels[i].IntermediateSize = this.Labels[i].Size;
                //	//this.Labels[i].IntermediateShader = Shader.TextOutline;
                //}

                //if (this.Labels[i].Visible)
                //{
                double dis = Meth.Limit(0, Meth.Abs(i - this.Index) - 2, 1);

                this.Labels[i].Color ^= (byte)(((i == this.TargetIndex) ? 255 : this.Expansion * 255) * (1 - dis));
                //this.Labels[i].Shader["Alpha"] = (a / 255.0);

                this.Labels[i].Z = a / 255.0 * this.Expansion;

                Vector p = this.GetPosition(i - this.Index);
                double r = p.Angle.ToHalfTau() / 4;
                this.Labels[i].Rotation = r;
                this.Labels[i].Position = p;
                //}
            }
        }
Esempio n. 21
0
        public override void Update()
        {
            double         y        = this.Spacing;
            Bunch <double> pos      = new Bunch <double>();
            Bunch <double> threshes = new Bunch <double>();
            Bunch <double> middles  = new Bunch <double>();

            foreach (T item in this.Items)
            {
                pos.Add(y);
                threshes.Add(y + item.GetHeight() + this.Spacing / 2);
                middles.Add(y + item.GetHeight() / 2);
                y += item.GetHeight() + this.Spacing;
            }

            double lheight = 0;

            if (this.Items.Count > 0)
            {
                middles.Add(y + this.Items.Last.GetHeight() / 2);

                T d = this.Items.First(item => item._BeingDragged);
                if (d != null)
                {
                    int    index = d._ListIndex;
                    double p     = d.Y + d.GetHeight() / 2;

                    if (p < threshes[0])
                    {
                        index = 0;
                    }
                    else if (p > threshes.Last)
                    {
                        index = threshes.Count - 1;
                    }
                    else
                    {
                        for (int i = 0; i < threshes.Count; i++)
                        {
                            if (p < threshes[i])
                            {
                                index = i;
                                break;
                            }
                        }
                    }

                    T[] items = this.Items.ToArray();

                    int dif = index - d._ListIndex;
                    if (dif > 0)
                    {
                        for (int i = d._ListIndex + 1; i <= index; i++)
                        {
                            items[i]._ListIndex--;
                        }
                    }
                    else if (dif < 0)
                    {
                        for (int i = index; i < d._ListIndex; i++)
                        {
                            items[i]._ListIndex++;
                        }
                    }

                    d._ListIndex = index;

                    if (dif != 0)
                    {
                        this.OnOrderChange();
                    }
                }

                foreach (T item in this.Items)
                {
                    if (!item._BeingDragged)
                    {
                        item.Y += (pos[item._ListIndex] - item.Y) / 2;
                        if (Meth.Abs(item.Y - pos[item._ListIndex]) < 1)
                        {
                            item.Y            = pos[item._ListIndex];
                            item._NeedsUpdate = false;
                        }
                    }
                    else
                    {
                        item.Y += item.LocalMousePosition.Y - item._DragStart.Y;
                    }

                    item.Y = Meth.Limit(0, item.Y, this.Height - item.GetHeight());
                    item.Z = item._BeingDragged ? 1 : 0;
                }

                lheight = this.Items.Last.GetHeight();
            }
            else
            {
                pos.Add(0);
                middles.Add(double.MaxValue);
            }

            if (this.LocalMousePosition.X >= 0 && this.LocalMousePosition.X < this.Width && this.LocalMousePosition.Y >= 0 && this.LocalMousePosition.Y < pos.Last + lheight + this.Spacing && !this.Items.Any(item => item._BeingDragged))
            {
                this._MousePos = threshes.IndexOf((this.Spacing / 2 + threshes).Last(t => t < middles.First(m => m > this.LocalMousePosition.Y))) + 1;
                Vector v = new Vector(this.Width / 2, (this.Spacing / 2 + threshes)[this._MousePos]);
                if (this.Plus.Position != v)
                {
                    this.Plus.Position  = v;
                    this.PlusArea.Shape = new Rectangle(this.Plus.Position - this.Spacing / 2, this.Spacing);
                }
                this.Plus.Visible = true;
            }
            else
            {
                this.Plus.Visible = false;
            }

            this.Plus.Color = this.PlusArea.IsHovered ? Color.White * 0.5 : Color.Black;
        }
Esempio n. 22
0
        public override void Update()
        {
            if (this.Enabled)
            {
                if (this.Progress < 0.01)
                {
                    this.Progress = 0;
                }
                if (this.Progress > 0.99)
                {
                    this.Progress = 1;
                }

                if (this.MouseArea.IsHovered)
                {
                    if (!this.MouseArea.IsClicked)
                    {
                        this.Progress -= (this.Progress - (this.Checked ? 0.7 : 0.2)) * 0.4;
                    }
                    else
                    {
                        this.Progress -= (this.Progress - (this.Checked ? 1 : 0)) * 0.5;
                    }
                }
                else
                {
                    this.JustClicked = false;
                    this.Progress   -= (this.Progress - (this.Checked ? 1 : 0)) * 0.5;
                }
            }
            else
            {
                this.Progress = this.Checked ? 1 : 0;
            }

            this.VertexArray.Vertices.Clear();
            for (int i = 0; i < 4; i++)
            {
                this.VertexArray.Vertices.Add(Size / 2 + 0.5 + Vector.FromAngle(i * Meth.Tau / 4 - Meth.Tau / 8, Size / 3 * Meth.Root(2)));
                this.VertexArray.Vertices.Add(Size / 2 + 0.5 + Vector.FromAngle(i * Meth.Tau / 4 - Meth.Tau / 8, Size / 3 * Meth.Root(2)) + Vector.FromAngle(i * Meth.Tau / 4 + Meth.Tau / 4 + Progress * Meth.Tau / 8, Size / 1.5 * (1 - Meth.Pow(Progress, 1.2)) + Size / 3 * Meth.Root(2) * Progress * 1.05));
                //this.VertexArray.Vertices.Add(new Vertex(Size / 2 + 0.5 + Vector.FromAngle(i * Meth.Tau / 4 + Meth.Tau / 8, Size / 3 * Meth.Root(2) * (1 - Progress)) + Vector.FromAngle(i * Meth.Tau / 4 - Meth.Tau / 8, -1 * Meth.Root(2) * Progress), Color.Black));
            }
        }
Esempio n. 23
0
        public override void Update()
        {
            this.Overlay.Visible = this.TileEditor.CurTile.Item1 == this.Areaset.Name;
            if (this.Overlay.Visible)
            {
                this.Overlay.Position = new Vector(this.TileEditor.CurTile.Item2 % this.Size.X, Meth.Down(this.TileEditor.CurTile.Item2 / (double)this.Size.X)) * this.Parent.TileSize * 2;
                this.OverlayTime++;

                if (this.OverlayTime == 12)
                {
                    this.OverlayTime   = 0;
                    this.OverlayStatus = !this.OverlayStatus;
                }

                if (this.OverlayStatus)
                {
                    this.Overlay.Position.X += this.Parent.TileSize.X * 2;
                }
                this.Overlay.Scale.X = (this.OverlayStatus ? -1 : 1) * 2;
            }
        }
Esempio n. 24
0
 internal override double _GetRectHeight() => Meth.Max(this.AlignmentZoom.RectSize.Y, this.Tileset.Height * this.Zoom) + this.AlignmentButtons.RectSize.Y;
Esempio n. 25
0
 public void UpdateMouseArea()
 {
     this.MouseArea.Shape           = new Rectangle(new Vector(this.AlignmentZoom.RectSize.X, 0), this.TilesetSource.Size * this.Zoom);
     this.AlignmentButtons.Position = new Vector(0, Meth.Max(this.AlignmentZoom.RectSize.Y, this.TilesetSource.Height * this.Zoom));
 }
Esempio n. 26
0
 internal override double _GetRectWidth() => Meth.Max((this.FixedSize != 0) ? this.FixedSize.X : this._Text.Width + this.Edge.X * 2, this.MinSize.X);
Esempio n. 27
0
 internal override double _GetRectWidth() => Meth.Max(this.Bottom.RectSize.X + this.Spritesheet.Width / this.AnimSprites * this.Spritesheet.Scale.X, this.Spritesheet.Width * this.Spritesheet.Scale.X);
Esempio n. 28
0
 internal override double _GetRectWidth() => Meth.Max(this.AlignmentZoom.RectSize.X + this.Tileset.Width * this.Zoom, this.AlignmentButtons.RectSize.X);
Esempio n. 29
0
        public override void Update()
        {
            if (this.ProgressIndefinitely)
            {
                this.Progress += (1 - this.Progress) / 200;
            }

            if (this.Started)
            {
                if (!this.Finished)
                {
                    this.RealProgress += (this.TargetProgress - this.RealProgress) * 0.1;
                    //if (this.TargetProgress == 1)
                    //{
                    //	this.Finished = true;
                    //	this.Kill();
                    //}

                    if ((this.Runtime - 20) % 120 < 60)
                    {
                        this.LineProgress = 0;
                    }
                    else
                    {
                        this.LineProgress = Meth.Smooth(((this.Runtime - 20) % 120 - 60) / 60.0);
                    }
                }
                else
                {
                    this.RealProgress *= 0.9;
                    this.LineProgress -= 1 / 10.0;

                    this.Graphics.Remove(this.OuterRing);
                    Bunch <Vector> vs = new Bunch <Vector>();
                    for (int i = 0; i <= 20; i++)
                    {
                        vs.Add(Vector.FromAngle(i / 20.0 * Meth.Tau, 8 * Meth.Root(this.RealProgress)));
                    }
                    this.OuterRing = Line.DrawMultiple(vs, Color.Black, 1);
                    this.Graphics.Add(this.OuterRing);

                    this.Text.Scale      = new Vector(Meth.Square(this.RealProgress), this.RealProgress);
                    this.Text.Position.X = this.RealProgress * 10;

                    if (this.RealProgress < 0.001)
                    {
                        this.Kill();
                    }
                }
            }
            else
            {
                this.LineProgress += (1 - this.LineProgress) * 0.1;

                this.RealProgress += (this.TargetProgress - this.RealProgress) * 0.1;
                this.RealProgress  = Meth.Min(this.LineProgress, this.RealProgress);

                this.Graphics.Remove(this.OuterRing);
                Bunch <Vector> vs = new Bunch <Vector>();
                for (int i = 0; i <= 20; i++)
                {
                    vs.Add(Vector.FromAngle(i / 20.0 * Meth.Tau, 8 * this.LineProgress));
                }
                this.OuterRing = Line.DrawMultiple(vs, Color.Black, 1);
                this.Graphics.Add(this.OuterRing);

                this.Text.Scale      = new Vector(Meth.Square(this.LineProgress), this.LineProgress);
                this.Text.Position.X = this.LineProgress * 10;

                if (this.LineProgress > 0.99)
                {
                    this.LineProgress = 1;
                    this.Started      = true;
                }
            }

            this.Graphics.Remove(this.InnerRing);

            Bunch <Vector> ps = new Bunch <Vector>();

            for (int i = 0; i <= 20; i++)
            {
                ps.Add(Vector.FromAngle(i / 20.0 * Meth.Tau, 8 * this.RealProgress));
            }
            this.InnerRing = Line.DrawMultiple(ps, Color.Black, 1);
            this.Graphics.Add(this.InnerRing);

            this.Lines.Vertices.Clear();
            this.Lines.Add(0);
            this.Lines.Add(Vector.FromAngle(this.LineProgress * Meth.Tau, 8 * this.RealProgress));
            this.Lines.Add(Vector.FromAngle(this.LineProgress * -Meth.Tau - Meth.Tau / 2, 8 * this.RealProgress));
            this.Lines.Add(Vector.FromAngle(this.LineProgress * -Meth.Tau - Meth.Tau / 2, this.Finished ? 8 * Meth.Root(this.RealProgress) : 8));
        }
Esempio n. 30
0
        public ScriptBox(Script _script)
            : base(_script.ToString())
        {
            this.TabAllowed = true;
            this.MultiLine  = true;

            this.TextColor        = new Color(220);
            this.SelectColor      = new Color(220);
            this.Background.Color = new Color(30);

            this.ColorTheme = new ColorTheme
                              (
                new ColorPattern("String", ColorString, true, true, "\"", "\""),
                new ColorPattern("Char", ColorString, true, true, "\'", "\'"),
                new ColorPattern("Comment", ColorComment, true, true, "#", "#"),
                new ColorPattern("Script", ColorScript, true, true, "@\"", "\""),

                new ColorPattern("NoScopeOperator", ColorNoScopeOperator, Helper.NoScopeOperatorSymbols),
                new ColorPattern("ScopeOperator", ColorScopeOperator, Helper.ScopeOperatorSymbols),
                new ColorPattern("OneLineScopeOperator", ColorOneLineScopeOperator, Helper.OneLineScopeOperators),
                new ColorPattern("ObjectOperator", ColorObjectOperator, Helper.ObjectOperators),
                new ColorPattern("FlowOperator", ColorFlowOperator, Helper.FlowOperators),

                new ColorPattern("Number", ColorNumber, text =>
            {
                int @out = 0;
                for (int i = 0; i < text.Length; i++)
                {
                    if (Ext.IsDouble(text.Substring(0, i + 1)) || (i + 1 < text.Length && Ext.IsDouble(text.Substring(0, i)) && Ext.IsDouble(text.Substring(0, i + 2))))
                    {
                        @out++;
                    }
                    else
                    {
                        return(@out);
                    }
                }
                return(@out);
            }),
                new ColorPattern("Variable", new Color(220), text =>
            {
                string alpha = "abcdefghijklmnopqrstuvwxyz_";

                if (!alpha.Contains(text[0].ToString().ToLower()[0]))
                {
                    return(0);
                }
                else
                {
                    alpha += "0123456789";

                    int @out = 1;
                    for (int i = 1; i < text.Length; i++)
                    {
                        if (alpha.Contains(text[i].ToString().ToLower()[0]))
                        {
                            @out++;
                        }
                        else
                        {
                            return(@out);
                        }
                    }
                    return(@out);
                }
            })
                              );

            this.SelectPatterns.Add(new TextSelectPattern.Keywords(Helper.Symbols));

            this.AfterInput = input =>
            {
                if (input == "\n")
                {
                    int    l    = this.GetCharPos(this.CursorPosition).Y - 1;
                    string line = this.Lines[l];

                    int tabs = Helper.GetNextIndents(line);

                    for (int i = 0; i < tabs; i++)
                    {
                        this.EnterText("\t");
                    }
                }
            };

            this.BeforeInput = input =>
            {
                if (input == "\t")
                {
                    bool shift = this.Parent.IsKeyPressed(Key.LShift);
                    if (shift || (!shift && this.GetSelectedLines().Length > 1))
                    {
                        int[]  sl   = this.GetSelectedLines();
                        string tx   = "";
                        int    tabs = 0;

                        bool firsttab = !shift;

                        for (int i = 0; i < sl[0]; i++)
                        {
                            tx += this.Lines[i] + "\n";
                        }

                        foreach (int i in this.GetSelectedLines())
                        {
                            string line = this.Lines[i];
                            if (shift)
                            {
                                if (line.StartsWith("\t"))
                                {
                                    tx += line.Substring(1) + "\n";
                                    tabs--;

                                    if (i == this.GetCharPos(this.GetLeft()).Y)
                                    {
                                        firsttab = true;
                                    }
                                }
                                else
                                {
                                    tx += (line.StartsWith("\t") ? line.Substring(1) : line) + "\n";
                                }
                            }
                            else
                            {
                                tx += "\t" + line + "\n";
                                tabs++;
                            }
                        }

                        for (int i = sl[sl.Length - 1] + 1; i < this.Lines.Length; i++)
                        {
                            tx += this.Lines[i] + "\n";
                        }

                        int c = this.CursorPosition;

                        tx           = tx.Substring(0, tx.Length - 1);
                        this.Content = tx;

                        if (tabs != 0)
                        {
                            if (this.SelectionLength > 0)
                            {
                                if (firsttab)
                                {
                                    this.CursorPosition = c + Meth.Sign(tabs);
                                }
                                this.SelectionLength += tabs - (firsttab ? Meth.Sign(tabs) : 0);
                            }
                            else if (this.SelectionLength < 0)
                            {
                                this.CursorPosition   = c + tabs;
                                this.SelectionLength -= tabs - (firsttab ? Meth.Sign(tabs) : 0);
                            }
                            else
                            {
                                this.CursorPosition = c - 1;
                            }
                        }

                        return(false);
                    }
                }
                return(true);
            };

            this.BeforeBackspace = () =>
            {
                if (this.SelectionLength > 0 || this.CursorPosition == 0)
                {
                    return(true);
                }
                else
                {
                    Point p = this.GetCharPos(this.CursorPosition);
                    if (p.Y > 0)
                    {
                        int    x = p.X;
                        string l = this.Lines[this.CurrentLine];

                        string st = l.Substring(0, x);

                        if (!st.Any(item => item != '\t'))
                        {
                            int tabs = st.Count(item => item == '\t');
                            int c    = this.CursorPosition;
                            this.Content        = this.Content.Substring(0, this.CursorPosition - tabs - 1) + this.Content.Substring(this.CursorPosition);
                            this.CursorPosition = c - tabs - 1;
                            return(false);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        return(true);
                    }
                }
            };

            //this.OnDefocus = this._TryParse;
        }