Esempio n. 1
0
        public static Bunch <Point> Trace(Point _start, Point _end)
        {
            Bunch <Point> @out = new Bunch <Point>();

            Point dif = _end - _start;

            if (dif.X != 0 || dif.Y != 0)
            {
                if (Meth.Abs(dif.X) > Meth.Abs(dif.Y))
                {
                    for (int x = 0; x <= Meth.Abs(dif.X); x++)
                    {
                        int nx = _start.X + x * Meth.Sign(dif.X);
                        int ny = Meth.Round(_start.Y + dif.Y * (x * Math.Sign(dif.X) / (float)dif.X));
                        @out.Add(new Point(nx, ny));
                    }
                }
                else
                {
                    for (int y = 0; y <= Meth.Abs(dif.Y); y++)
                    {
                        int nx = Meth.Round(_start.X + dif.X * (y * Meth.Sign(dif.Y) / (float)dif.Y));
                        int ny = _start.Y + y * Meth.Sign(dif.Y);
                        @out.Add(new Point(nx, ny));
                    }
                }
            }
            else
            {
                @out.Add(_start);
            }

            return(@out);
        }
Esempio n. 2
0
        public void Draw(Bunch <Graphic> _graphics)
        {
            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.Enable(EnableCap.Texture2D);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, this._FramebufferId);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Viewport(0, 0, this.Resolution.X, this.Resolution.Y);

            if (this._RenderToWindow)
            {
                GL.Ortho(0, this.Resolution.X, this.Resolution.Y, 0, 0, 4);
            }
            else
            {
                GL.Ortho(0, this.Resolution.X, 0, this.Resolution.Y, 0, 4);
            }

            foreach (Graphic g in _graphics)
            {
                Renderer._Draw(g);
            }

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
        }
Esempio n. 3
0
        private void _UpdateGraphics()
        {
            this.Graphics.Clear();
            this.Graphics.Add(this.CollapseArrow);

            double d = Border / 2;

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

            vs.Add(0);
            vs.Add(new Vector(0, d + this.InnerSize.Y));
            vs.Add(new Vector(d, d + this.InnerSize.Y + d));
            vs.Add(new Vector(d + this.InnerSize.X, d + this.InnerSize.Y + d));
            vs.Add(new Vector(d + this.InnerSize.X + d, d + this.InnerSize.Y));
            vs.Add(new Vector(d + this.InnerSize.X + d, d));
            vs.Add(new Vector(d + this.InnerSize.X, 0));
            vs.Add(0);

            if (this.AlignRight)
            {
                vs = vs.Select(item => new Vector(this.OuterSize.X - item.X, item.Y));
            }

            this.Graphics.Add(this.Inline = new VertexArray(VertexArrayType.Polygon)
            {
                Color = Color.White, Vertices = vs.Select(item => new Vertex(item, Color.White)), Position = new Vector(0, this.TabOffset), Z = 1
            });
            this.Graphics.Add(this.Outline = new VertexArray(VertexArrayType.LinesStrip)
            {
                Color = Color.Black, Vertices = vs.Select(item => new Vertex(item, Color.White)), Position = new Vector(0, this.TabOffset), Z = 1
            });
        }
Esempio n. 4
0
        public Tab(string _content)
        {
            this.Interfacial = true;
            this.Content     = _content;

            //this.Cutoff = Font.Consolas.GetLineSpacing(14) / 4;
            this.Cutoff = FontBase.Consolas.CharSize / 4;
            this.Label  = new Label(this.Content)
            {
                Z = 0.000001, Position = new Vector(this.Cutoff * 0.5, 0)
            };

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

            double w = this.Label.Width + this.Cutoff * 3;

            vs.Add(0);
            vs.Add(new Vector(0, this.Label.Height - this.Cutoff));
            vs.Add(new Vector(this.Cutoff, this.Label.Height));
            vs.Add(new Vector(w - this.Cutoff, this.Label.Height));
            vs.Add(new Vector(w, this.Label.Height - this.Cutoff));
            vs.Add(new Vector(w, 0));

            this.Graphics.Add(new VertexArray(VertexArrayType.Polygon)
            {
                Color = Color.White, Position = new Vector(-this.Cutoff, 0), Vertices = vs.Select(item => new Vertex(new Vector(item.X, this.Label.Height - item.Y), Color.White))
            });
            this.Graphics.Add(new VertexArray(VertexArrayType.LinesStrip)
            {
                Color = Color.Black, Position = new Vector(-this.Cutoff, 0), Vertices = vs.Select(item => new Vertex(new Vector(item.X, this.Label.Height - item.Y), Color.White))
            });
        }
Esempio n. 5
0
        public override ImageSource GetImage(string _content, Color _color, int _tablength = 4, string _symboltab = null, char?_symbolspace = default(char?))
        {
            Point size = this.GetSize(_content);

            if (this._Renderer == null)
            {
                this._Renderer = new Renderer(size);
            }
            else if (this._Renderer.Resolution != size)
            {
                this._Renderer.Resolution = size;
            }

            this._Renderer.Clear();

            Bunch <string> lines = this._SplitText(_content, _tablength, _symboltab, _symbolspace);

            for (int y = 0; y < lines.Count; y++)
            {
                for (int x = 0; x < lines[y].Length; x++)
                {
                    if (lines[y][x] != ' ')
                    {
                        this._Renderer.Draw(new Image(this.Chars[lines[y][x]])
                        {
                            Position = new Vector(x, y) * this.CharSize, Color = _color, BlendMode = BlendMode.None
                        });
                    }
                }
            }

            return(this._Renderer.ImageSource.Clone());
        }
Esempio n. 6
0
        public override void OnInitialization()
        {
            Renderer        c  = new Renderer(this.Parent.TileSize * this.Size * 2);
            Bunch <Graphic> gs = new Bunch <Graphic>();

            for (int i = 0; i < this.Areaset.Tiles.Count; i++)
            {
                gs.Add(new Image(this.Areaset.Tiles[i])
                {
                    Position = this.Parent.TileSize * new Vector(i % this.Size.X, Meth.Down(i / (double)this.Size.X)) * 2, Scale = 2
                });
            }
            c.Draw(gs);
            this.Graphics.Add(new Image(c.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.Areaset.Tiles.Count)
                    {
                        this.TileEditor.CurTile = new Tuple <string, int>(this.Areaset.Name, i);
                    }
                }
            });
        }
Esempio n. 7
0
        public void ExecuteScript(Script _script, bool _includeentities, params Variable[] _vars)
        {
            Bunch <Variable> vars = new Bunch <Variable>(this._WrappedThis, Misc.Mekanik);

            vars.Add(_vars);

            if (_includeentities)
            {
                foreach (Entity e in this.Parent.RealEntities.Where(item => item.Identifier != null))
                {
                    vars.Add(new Variable(new string(e.Identifier.Select(item => (item == ' ') ? '_' : item).ToArray()), e._WrappedThis.Value));
                }
            }

            Program p = new Program(_script)
            {
                OnCrash = cr =>
                {
                    if (cr.Error.ErrorCode != Error.Execution.AbortedByUser.ErrorCode)
                    {
                        throw cr.Error;
                    }
                }
            };

            p.Start(new Permissions(Permission.DllUsage), vars);
            this._Programs.Add(p);
        }
Esempio n. 8
0
        //public static bool Contains(this Bunch<Rect> @this, Vector _vector)
        //{
        //	foreach (Rect rect in @this)
        //	{
        //		if (rect.Contains(_vector))
        //			return true;
        //	}
        //	return false;
        //}

        //public static bool Contains(this Bunch<Collider> @this, Vector _vector)
        //{
        //	return @this.Select(item => item.Rect).Contains(_vector);
        //}

        //public static bool IntersectsWith(this Bunch<Rect> @this, Bunch<Rect> _rects)
        //{
        //	foreach (Rect rect1 in _rects)
        //	{
        //		foreach (Rect rect2 in @this)
        //		{
        //			if (rect2.IntersectsWith(rect1))
        //				return true;
        //		}
        //	}
        //	return false;
        //}

        //public static bool IntersectsWith(this Bunch<Collider> @this, Bunch<Collider> _colliders) { return @this.Select(item => item.Rect).IntersectsWith(_colliders.Select(item => item.Rect)); }

        //public static bool Contains(this Bunch<Rect> @this, Bunch<Rect> _rects)
        //{
        //	foreach (Rect rect1 in _rects)
        //	{
        //		bool contains = false;
        //		foreach (Rect rect2 in @this)
        //		{
        //			if (rect2.Contains(rect1))
        //			{
        //				contains = true;
        //				break;
        //			}
        //		}
        //		if (!contains)
        //			return false;
        //	}
        //	return true;
        //}

        //public static bool Contains(this Bunch<Collider> @this, Bunch<Collider> _colliders)
        //{
        //	return @this.Select(item => item.Rect).Contains(_colliders.Select(item => item.Rect));
        //}

        //public static bool Contains(this Bunch<Area> @this, Vector _point)
        //{
        //	return @this.WhereFirst(item => item.Contains(_point)) != null;
        //}

        //public static bool Contains(this Bunch<Rect> @this, Bunch<Rect> _rects)
        //{
        //	foreach (Rect rect1 in _rects)
        //	{
        //		bool contains = false;
        //		foreach (Rect rect2 in @this)
        //		{
        //			if (rect2.Contains(rect1))
        //			{
        //				contains = true;
        //				break;
        //			}
        //		}
        //		if (!contains)
        //			return false;
        //	}
        //	return true;
        //}



        public static Rect GetRect(this Bunch <Rect> @this)
        {
            Vector topleft  = new Vector(double.MaxValue, double.MaxValue);
            Vector botright = new Vector(double.MinValue, double.MinValue);

            foreach (Rect rect in @this)
            {
                if (rect.X < topleft.X)
                {
                    topleft.X = rect.X;
                }
                if (rect.Y < topleft.Y)
                {
                    topleft.Y = rect.Y;
                }

                if (rect.X + rect.Width > botright.X)
                {
                    botright.X = rect.X + rect.Width;
                }
                if (rect.Y + rect.Height > botright.Y)
                {
                    botright.Y = rect.Y + rect.Height;
                }
            }
            return(new Rect(topleft, botright - topleft));
        }
Esempio n. 9
0
        public ImageSource GetColset()
        {
            int         pixelcount = Meth.Up(this.Parent.TileCollisionResolution.X * this.Parent.TileCollisionResolution.Y / 4.0);
            ImageSource @out       = new ImageSource(this.TileCount.X * pixelcount, this.TileCount.Y);

            for (int x = 0; x < this.TileCount.X; x++)
            {
                for (int y = 0; y < this.TileCount.Y; y++)
                {
                    Bunch <byte> bs = new Bunch <byte>();
                    for (int ty = 0; ty < this.Parent.TileCollisionResolution.Y; ty++)
                    {
                        for (int tx = 0; tx < this.Parent.TileCollisionResolution.X; tx++)
                        {
                            bs.Add(this.Colset[x, y][tx, ty]);
                        }
                    }
                    Bunch <Color> ps = new Bunch <Color>();
                    while (bs.Count > 0)
                    {
                        while (bs.Count < 4)
                        {
                            bs.Add(0);
                        }
                        ps.Add(new Color(bs.SubBunch(0, 4)));
                        bs = bs.SubBunch(4);
                    }
                    for (int i = 0; i < pixelcount; i++)
                    {
                        @out[x * pixelcount + i, y] = ps[i];
                    }
                }
            }
            return(@out);
        }
Esempio n. 10
0
        public LevelPreview(LevelEditor _editor)
        {
            this.Editor      = _editor;
            this.Interfacial = true;

            this.UpdateSize();

            this.Graphics.Add(this.Image = new Image(new ImageSource(1, 1)));
            this.Graphics.Add(this.Frame = new VertexArray(VertexArrayType.LinesStrip)
            {
                Color = Color.Black
            });
            this.Graphics.Add(this.Viewpoint = new VertexArray(VertexArrayType.LinesStrip)
            {
                Color = Color.White * 0.5, Z = 1
            });
            this.Frame.Add(this.FitPosition, this.FitPosition + this.FitRect.Size.OnlyX, this.FitPosition + this.FitRect.Size, this.FitPosition + this.FitRect.Size.OnlyY, this.FitPosition);
            this.Viewpoint.Add(0, new Vector(1, 0), 1, new Vector(0, 1), 0);

            Bunch <Vector> vs = new Bunch <Vector>(new Vector(4, 0), new Vector(this.Size.X - 4, 0), new Vector(this.Size.X, 4), new Vector(this.Size.X, this.Size.Y - 4), new Vector(this.Size.X - 4, this.Size.Y), new Vector(4, this.Size.Y), new Vector(0, this.Size.Y - 4), new Vector(0, 4));

            this.Graphics.Add(new VertexArray(VertexArrayType.Polygon)
            {
                Vertices = vs.Select(item => (Vertex)item)
            });
            this.Graphics.Add(new VertexArray(VertexArrayType.LinesStrip)
            {
                Vertices = vs.Select(item => (Vertex)item) + (Vertex)vs[0], Color = Color.Black
            });
        }
Esempio n. 11
0
        internal Bunch <Graphic> _GetGraphics()
        {
            if (!this.Visible)
            {
                return(new Bunch <Graphic>());
            }
            else
            {
                this._UpdateRealPosition();
                this._UpdateScale();

                foreach (Graphic g in this.Graphics)
                {
                    g._Set(this);
                }

                Bunch <Graphic> @out = this.Graphics.Where(item => item.Visible);
                Bunch <Graphic> ns   = new Bunch <Graphic>();

                foreach (Entity c in this.Children)
                {
                    @out.Add(c._GetGraphics());
                }

                foreach (Graphic g in @out)
                {
                    this._UpdateGraphic(g);
                }

                return(@out);
            }
        }
Esempio n. 12
0
        public static Bunch <T> operator +(Bunch <T> _one, Bunch <T> _two)
        {
            Bunch <T> @out = _one;

            _one.Add(_two);
            return(@out);
        }
Esempio n. 13
0
        //public TOut Sum<TOut>(Func<T, TOut> _func)
        //{
        //	MethodInfo plus = _func.GetType().GetMethod("op_Addition");
        //	if (plus == null)
        //		throw new Exception("The type has to have a + method!");

        //	TOut sum = default(TOut);
        //	foreach (T t in this)
        //		sum = (TOut)plus.Invoke(sum, new object[] { sum, _func(t) });

        //	return sum;
        //}

        //public static bool operator ==(Bunch<T> _one, string _two)
        //{
        //	if (typeof(T) != typeof(string))
        //		return false;

        //	string[] parts = _two.Split(',');
        //	for (int i = 1; i < parts.Length; i++)
        //	{
        //		if (parts[i][0] == ' ')
        //			parts[i] = parts[i].Substring(1);
        //	}

        //	if (_one.Count != parts.Length)
        //		return false;

        //	for (int i = 0; i < parts.Length; i++)
        //	{
        //		object o = _one[i];
        //		if (parts[i] != (string)o)
        //			return false;
        //	}

        //	return true;
        //}
        //public static bool operator !=(Bunch<T> _one, string _two) { return !(_one == _two); }

        public static Bunch <T> operator +(Bunch <T> _one, T _two)
        {
            Bunch <T> @out = _one.Clone();

            @out.Add(_two);
            return(@out);
        }
Esempio n. 14
0
        //public int IndexOf(T _item)
        //{
        //	for (int i = 0; i < this.Count; i++)
        //	{
        //		if (this[i].Equals(_item))
        //			return i;
        //	}
        //	return -1;
        //}

        public Bunch <T> Merge(Bunch <T> _bunch)
        {
            Bunch <T> @out = this.Clone();

            @out.Add(_bunch.Where(item => [email protected](item)));
            return(@out);
        }
Esempio n. 15
0
        public Bunch <T> MoveTo(T _item, int _index)
        {
            Bunch <T> @out = this.Clone();

            @out.Remove(_item);
            return(@out.SubBunch(0, _index) + _item + @out.SubBunch(_index));
        }
Esempio n. 16
0
        internal SaveFile(GameBase _game, string _path)
            : this(_game)
        {
            MekaItem file = MekaItem.LoadFromFile(_path);

            this.PlayTime = file["Play Time"].Content.To <int>();

            int[] ds = file["Last Played"].Content.Split('.').ToArray().Select(item => item.To <int>()).ToArray();
            this.LastPlayed = new DateTime(ds[2], ds[1], ds[0]);

            this._PositionRegion   = file["Position Region"].Content;
            this._PositionEntrance = file["Position Entrance"].Content;

            foreach (MekaItem level in file["Levels"].Children)
            {
                this._Levels[level.Name] = new Bunch <SavedEntity>();
                foreach (MekaItem entity in level.Children)
                {
                    this._Levels[level.Name].Add(new SavedEntity(entity));
                }
            }

            foreach (MekaItem achievement in file["Achievements"].Children)
            {
                this.Achievements[achievement.Name] = achievement.Children[0];
            }

            this.CustomInfo = file["Custom Info"];

            string n = File.GetName(_path);
            n        = n.Substring(n.IndexOf('#') + 1);
            this._Id = n.To <int>();
        }
Esempio n. 17
0
            public void Tick()
            {
                Bunch <Tuple <Action, int> > adds = new Bunch <Tuple <Action, int> >();
                Dictionary <int, Bunch <Tuple <Action, int> > > ncodes = new Dictionary <int, Bunch <Tuple <Action, int> > >();

                foreach (KeyValuePair <int, Bunch <Tuple <Action, int> > > b in this._Codes)
                {
                    if (b.Key == 1)
                    {
                        foreach (Tuple <Action, int> d in b.Value)
                        {
                            d.Item1();
                            if (d.Item2 > 0)
                            {
                                adds.Add(d);
                            }
                        }
                    }
                    else
                    {
                        ncodes[b.Key - 1] = b.Value;
                    }
                }
                this._Codes = ncodes;

                foreach (Tuple <Action, int> add in adds)
                {
                    Add(add.Item2, add.Item1, add.Item2);
                }
            }
Esempio n. 18
0
 public void Add <TType>(Bunch <TType> _bunch) where TType : T
 {
     foreach (TType obj in _bunch)
     {
         this._OnAdd(obj);
         this.Add(obj);
     }
 }
Esempio n. 19
0
 public ColorPattern(string _name, Color _color, bool _range, bool _endline, params string[] _symbols)
 {
     this.Name    = _name;
     this._Color  = _color;
     this.Range   = _range;
     this.EndLine = _endline;
     this.Symbols = new Bunch <string>(_symbols);
 }
Esempio n. 20
0
 public void Remove(Bunch <T> _objects)
 {
     foreach (T obj in _objects)
     {
         this._OnRemove(obj);
         this._Objects.Remove(obj);
     }
 }
Esempio n. 21
0
 public void Update(Bunch <Vector> _points)
 {
     this._InitialPoints = _points;
     this.Points         = new Bunch <Vector>();
     for (int i = 0; i <= 20; i++)
     {
         this.Points.Add(Bezier.GetSingle(_points, i / 20.0));
     }
 }
Esempio n. 22
0
        public EntityGroup(Bunch <EntityTile> _types, TileEditor _tileeditor, EntityEditor _entityeditor, Point _size)
        {
            this.Interfacial = true;

            this.Types        = _types;
            this.TileEditor   = _tileeditor;
            this.EntityEditor = _entityeditor;
            this.Size         = _size;
        }
Esempio n. 23
0
        public void Select(EntityIcon _entity)
        {
            if (this.Icon != _entity)
            {
                if (this.Icon != null)
                {
                    this.UpdateValues();
                    this.Icon.Selected = false;
                }

                this.Icon = _entity;
                if (this.Icon != null)
                {
                    this.Icon.Selected = true;
                }

                foreach (Entity c in this.Children)
                {
                    c.Kill();
                }
                //this.Properties = new Dictionary<string, Func<string>>();

                Bunch <Alignable> als = new Bunch <Alignable>();

                if (_entity != null)
                {
                    als.Add(new Alignment(new Label("X:"), this.XBox = new NumBox(Meth.Down(_entity.X))));
                    als.Add(new Alignment(new Label("Y:"), this.YBox = new NumBox(Meth.Down(_entity.Y))));
                    als.Add(new Alignment(new Label("Z:"), this.ZBox = new NumBox(Meth.Down(_entity.EntityZ))
                    {
                        MinValue = -9999
                    }));
                }

                if (_entity == null)
                {
                    this.PropertyEditor = new PropertyEditor(new Dictionary <string, Type>());
                }
                else if (_entity.Type.Name != "Decoration")
                {
                    als.Add(this.PropertyEditor = new PropertyEditor(this.Icon.Properties.ToDictionary(item => item.Name, item => item.Type), this.Icon.Properties.ToDictionary(item => item.Name, item => (object)item.Value)));
                }

                this.Children.Add(new Alignment(als)
                {
                    Vertical = true
                });

                if (_entity != null)
                {
                    Button b = new Button("Delete", () => this.Icon.RemoveFromLevel());
                    b.Position = new Vector(((TabList)this.Parents[2]).InnerSize.X - b.RectSize.X, 0);
                    this.Children.Add(b);
                }
            }
        }
Esempio n. 24
0
        public Bunch <T> SubBunch(int _start)
        {
            Bunch <T> @out = new Bunch <T>();

            for (int i = _start; i < this.Count; i++)
            {
                @out.Add(this[i]);
            }
            return(@out);
        }
Esempio n. 25
0
        public Bunch <T> Clone()
        {
            Bunch <T> @out = new Bunch <T>();

            foreach (T obj in this)
            {
                @out.Add(obj);
            }
            return(@out);
        }
Esempio n. 26
0
        public static Bunch <T> operator +(T _one, Bunch <T> _two)
        {
            Bunch <T> @out = new Bunch <T>()
            {
                _one
            };

            @out.Add(_two);
            return(@out);
        }
Esempio n. 27
0
        public Bunch <T> SubBunch(int _start, int _length)
        {
            Bunch <T> @out = new Bunch <T>();

            for (int i = _start; i < _start + _length; i++)
            {
                @out.Add(this[i]);
            }
            return(@out);
        }
Esempio n. 28
0
        public static Bunch <T> ToBunch <T>(this IEnumerable <T> @this)
        {
            Bunch <T> @out = new Bunch <T>();

            foreach (T t in @this)
            {
                @out.Add(t);
            }
            return(@out);
        }
Esempio n. 29
0
        public void AddLayer(int _pos)
        {
            Layer l = new Layer(this.Areasets, this.Parent.TileSize, this.DefaultTile)
            {
                Size = this.Size
            };

            this.Layers   = this.Layers.SubBunch(0, _pos) + l + this.Layers.SubBunch(_pos);
            this.CurLayer = _pos;
        }
Esempio n. 30
0
        public CollapseGroup(FontBase _font, string _name, params Entity[] _children)
        {
            this.Interfacial = true;
            this.Contents    = _children;

            this.Graphics.Add(this.Text = new Text(_font)
            {
                Content = _name, Z = 1
            });
        }