public override void Update() { Vector size = this.Editor.TileEditor.Size * this.Parent.TileSize * this.Editor.TileEditor.Scale; Vector esize = this.Editor.EditorSize; if (this.MouseArea.IsClicked) { this.Editor.TileEditor.Position = -(this.LocalMousePosition - this.FitPosition) / this.FitRect.Size * size + this.Editor.EditorSize / 2 + new Vector(this.Editor.TabListLeft.TotalSize.X, 20); } this.Editor.TileEditor.X = Meth.Limit(this.Editor.TabListLeft.TotalSize.X - size.X + this.Editor.EditorSize.X, this.Editor.TileEditor.X, this.Editor.TabListLeft.TotalSize.X); this.Editor.TileEditor.Y = Meth.Limit(-size.Y + this.Editor.EditorSize.Y + 20, this.Editor.TileEditor.Y, 20); if (size.X < esize.X) { this.Editor.TileEditor.X = this.Editor.TabListLeft.TotalSize.X + (esize.X - size.X) / 2; } if (size.Y < esize.Y) { this.Editor.TileEditor.Y = (esize.Y - size.Y) / 2 + 20; } if (this.NeedsUpdate && this.UpdateTimer < 10) { this.NeedsUpdate = false; this.UpdateTimer = 10; } if (this.UpdateTimer > 0) { this.UpdateTimer--; if (this.UpdateTimer == 0) { this.UpdatePreview(); } } if (this.Updated) { this.Updated = false; this.Graphics.Remove(this.Image); this.Image = this.UpdatedImage; this.Graphics.Add(this.Image); this.Frame.Vertices.Clear(); this.Frame.Add(this.FitPosition, this.FitPosition + this.FitRect.Size.OnlyX, this.FitPosition + this.FitRect.Size, this.FitPosition + this.FitRect.Size.OnlyY, this.FitPosition); } Vector topleft = this.FitRect.Size * ((this.Editor.TileEditor.Position - new Vector(this.Editor.TabListLeft.TotalSize.X, 20)) / this.Editor.TileEditor.Scale / this.Parent.TileSize / -this.Editor.TileEditor.Size); Vector botright = topleft + this.FitRect.Size * this.Editor.EditorSize / this.Editor.TileEditor.Scale / this.Parent.TileSize / this.Editor.TileEditor.Size; topleft.X = Meth.Max(topleft.X, 0); topleft.Y = Meth.Max(topleft.Y, 0); botright.X = Meth.Min(botright.X, FitRect.Width); botright.Y = Meth.Min(botright.Y, FitRect.Height); this.Viewpoint.Position = FitPosition + topleft; this.Viewpoint.Scale = botright - topleft; }
public override void Update() { if (this.CurrentSource != null) { if (Meth.Sign(this.TimePassed - 1) != Meth.Sign(this.SpeedModifier)) { this._Stopped = false; } if (!this._Stopped) { this.TimePassed += this.SpeedModifier; if (this.TimePassed > this.CurrentSource.Speed * this.CurrentSource.Sprites.Count || (this.SpeedModifier < 0 && this.TimePassed <= 0)) { if (this.CurrentSource.Repeated) { if (this.SpeedModifier > 0) { if (this._StopSmooth) { this._StopSmooth = false; this._Stopped = true; this.TimePassed = this.CurrentSource.Speed * this.CurrentSource.Sprites.Count; } else { this.TimePassed %= (this.CurrentSource.Speed * this.CurrentSource.Sprites.Count); } } else { if (this._StopSmooth) { this._StopSmooth = false; this._Stopped = true; this.TimePassed = 0; } else { this.TimePassed = (this.TimePassed + (this.CurrentSource.Speed * this.CurrentSource.Sprites.Count)) % (this.CurrentSource.Speed * this.CurrentSource.Sprites.Count); } } } else { this.TimePassed = (this.SpeedModifier > 0) ? this.CurrentSource.Speed * this.CurrentSource.Sprites.Count : 0; this._Stopped = true; this._StopSmooth = false; } } this.CurFrame = Meth.Min(Meth.Down(this.TimePassed / this.CurrentSource.Speed), this.CurrentSource.Sprites.LastIndex); } } }
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; }
public override Tuple <int, int> GetRange(string _content, int _pos) { int l = 0; for (int i = Meth.Min(_pos, _content.Length - 1); i >= 0; i--) { if (this.Chars.Contains(_content[i])) { _pos = i; } else { break; } } for (int i = _pos; i < _content.Length; i++) { if (i == _content.Length) { l++; } else { if (this.Chars.Contains(_content[i])) { l = i - _pos + 1; } else { break; } } } return(new Tuple <int, int>(_pos, l)); }
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)); }
public static int Limit(int _min, int _num, int _max) { return(Meth.Min(Meth.Max(_num, _min), _max)); }
public static double Limit(double _min, double _num, double _max) { return(Meth.Min(Meth.Max(_num, _min), _max)); }
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)); }
public override void OnInitialization() { Renderer r = new Renderer(this.Parent.TileSize * this.Size * 2); Bunch <Graphic> gs = new Bunch <Graphic>(); for (int i = 0; i < this.Types.Count; i++) { gs.Add(new Image(this.Types[i].Icon) { Origin = 0.5, Position = (this.Parent.TileSize / 2 + this.Parent.TileSize * new Vector(i % this.Size.X, Meth.Down(i / (double)this.Size.X))) * 2, Scale = Meth.Min(this.Parent.TileSize.X / (double)this.Types[i].Icon.Width, this.Parent.TileSize.Y / (double)this.Types[i].Icon.Height) * 2 }); } r.Draw(gs); this.Graphics.Add(new Image(r.ImageSource)); this.AddMouseArea(new MouseArea(new Rectangle(0, this.Size * this.Parent.TileSize * 2)) { OnClick = key => { Point p = this.LocalMousePosition / this.Parent.TileSize / 2; int i = p.X + p.Y * this.Size.X; if (i < this.Types.Count) { EntityIcon icon = this.Types[i].GetIcon(this.TileEditor.Layer); icon.Position = this.TileEditor.LocalMousePosition; this.TileEditor.Layer.Entities.Add(icon); this.TileEditor.Children.Add(icon); Vector s = this.Types[i].Icon.Size; Rect n = (new Rect(0, this.Parent.TileSize)).MakeFit(s); icon._DragPoint = ((this.LocalMousePosition % ((Vector)this.Parent.TileSize * 2)) / 2 - n.Position) / n.Size * s - s * icon.Type.Origin; this.EntityEditor.Select(icon); } } }); }
public int GetLeft() { return(Meth.Min(this.CursorPosition, this.CursorPosition + this.SelectionLength)); }