Exemple #1
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);
                    }
                }
            });
        }
Exemple #2
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);
                }
            }
        }
Exemple #3
0
 public void Shuffle()
 {
     for (int i = 0; i < this._Objects.Count; i++)
     {
         int n = Meth.Down(Meth.Random * this._Objects.Count);
         T   o = this[n];
         this[n] = this[i];
         this[i] = o;
     }
 }
Exemple #4
0
        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);
                }
            }
        }
Exemple #5
0
        public override void Update()
        {
            if (this.Icon != null)
            {
                double tx = this.XBox.Value;
                double ty = this.YBox.Value;

                if (!this.XBox._TextBox.IsEdited && !this.Icon.IsDragged && this.Icon.X != tx)
                {
                    this.Icon.X          = tx;
                    this.ChangedPosition = true;
                }
                if (!this.YBox._TextBox.IsEdited && !this.Icon.IsDragged && this.Icon.Y != ty)
                {
                    this.Icon.Y          = ty;
                    this.ChangedPosition = true;
                }

                if (!this.XBox.IsEdited)
                {
                    this.XBox.Value = Meth.Down(this.Icon.X);
                }
                if (!this.YBox.IsEdited && this.YBox.Value != Meth.Down(this.Icon.Y))
                {
                    this.YBox.Value = Meth.Down(this.Icon.Y);
                }

                if (!this.XBox.IsEdited && !this.YBox.IsEdited && this.ChangedPosition)
                {
                    this.ChangedPosition = false;
                    this.Icon.LevelEditor.LevelPreview.NeedsUpdate = true;
                }

                this.Icon.EntityZ = this.ZBox.Value;
            }

            if (this.Icon != null && this.Icon.Type.Name != "Decoration" && !this.PropertyEditor.IsEdited)
            {
                this.UpdateValues();
            }

            if (this.NeedsToDeselect)
            {
                this.NeedsToDeselect = false;
                this.Select(null);
            }
        }
Exemple #6
0
        public Areaset(MekaItem _file, Point _tilesize, Point _tilecollisionresolution)
        {
            if (_file["Info"]["Tilesize"].To <Point>() != _tilesize || _file["Info"]["Colsize"].To <Point>() != _tilecollisionresolution)
            {
                throw new Exception("Tilesize and/or Colsize don't match up with this game's.");
            }

            ImageSource tileset = GameBase.LoadImageSource(_file["Tileset"].Data);

            ImageSource[,] tiles = tileset.Split(tileset.Size / _tilesize);
            ImageSource colset = GameBase.LoadImageSource(_file["Colset"].Data);

            int pixelcount = Meth.Up(_tilecollisionresolution.X * _tilecollisionresolution.Y / 4.0);

            this.Size = new Point(tiles.GetLength(0), tiles.GetLength(1));

            for (int y = 0; y < this.Size.Y; y++)
            {
                for (int x = 0; x < this.Size.X; x++)
                {
                    this.Tiles.Add(tiles[x, y]);

                    Bunch <Color> cs = new Bunch <Color>();
                    for (int i = 0; i < pixelcount; i++)
                    {
                        cs.Add(colset[x * pixelcount + i, y]);
                    }

                    Bunch <byte> bs = new Bunch <byte>();
                    foreach (Color c in cs)
                    {
                        bs.Add(c.Bytes);
                    }

                    bs           = bs.SubBunch(0, _tilecollisionresolution.X * _tilecollisionresolution.Y);
                    bool[,] cols = new bool[_tilecollisionresolution.X, _tilecollisionresolution.Y];
                    for (int i = 0; i < bs.Count; i++)
                    {
                        cols[i % _tilecollisionresolution.X, Meth.Down(i / _tilecollisionresolution.X)] = bs[i] == 1;
                    }
                    this.Cols.Add(cols);
                }
            }
        }
Exemple #7
0
        public override void Update()
        {
            this.Z = this.StartedDragging ? 10 : (3.5 + Meth.InfToOne(this.EntityZ) / 2);

            if (TileEditor.Editor.TabListRight.CurName == "Entities")
            {
                this.Area.Enabled = true;

                this.Icon.Color = this.IsInsideLevel ? Color.White : Color.White ^ 170;
                this.Icon.Shader["Selected"] = (this.Selected && !this.StartedDragging) ? 1 : 0;
                this.Icon.Shader["Color0"]   = Meth.Down(this.Runtime / 20.0) % 2 == 0 ? Color.Black : Color.White;
                this.Icon.Shader["Color1"]   = Meth.Down(this.Runtime / 20.0) % 2 == 1 ? Color.Black : Color.White;

                this.IconOverlay.Color = Color.White ^ 85;
                this.IconOverlay.Shader["Selected"] = (this.Selected && !this.StartedDragging) ? 1 : 0;
                this.IconOverlay.Shader["Color0"]   = Meth.Down(this.Runtime / 20.0) % 2 == 0 ? Color.Black : Color.White;
                this.IconOverlay.Shader["Color1"]   = Meth.Down(this.Runtime / 20.0) % 2 == 1 ? Color.Black : Color.White;

                if (this.Type.Entrance)
                {
                    this.TestArea.Enabled   = true;
                    this.TestButton.Visible = true;
                    this.TestButton.Color   = Color.Green * (this.TestArea.IsHovered ? 1 : 0.7);
                }
            }
            else
            {
                this.Area.Enabled = false;

                this.Icon.Color = Color.Transparent;
                this.Icon.Shader["Selected"] = 0;

                this.IconOverlay.Color = Color.White ^ 85;
                this.IconOverlay.Shader["Selected"] = 0;

                if (this.Type.Entrance)
                {
                    this.TestArea.Enabled   = false;
                    this.TestButton.Visible = false;
                }
            }
        }
Exemple #8
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);
        }
Exemple #9
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;
                    }
                }
            }
        }
Exemple #10
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;
            }
        }
Exemple #11
0
        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);
                    }
                }
            });
        }