示例#1
0
        public override EntityIcon GetIcon(Layer _layer)
        {
            EntityIcon i = new EntityIcon(_layer, this.Types.First(item => item.Name == "Decoration"), _dragged: true);

            i.Properties.First(item => item.Name == "Areaset").Value = this.Areaset.Name;
            i.Properties.First(item => item.Name == "Name").Value    = this.Name;
            return(i);
        }
示例#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);
                }
            }
        }
示例#3
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);
                    }
                }
            });
        }
示例#4
0
        internal void _Load(byte[] _bytes)
        {
            foreach (Entity c in this.Children)
            {
                c.Kill();
            }

            MekaItem level = MekaItem.FromBytesEncrypted(_bytes);

            this.Layers = new Bunch <Layer>();

            Bunch <string> areasets = level["Areasets"].Children.Select(item => item.Content).ToBunch();

            foreach (MekaItem layer in level["Layers"].Children)
            {
                Layer l = new Layer(this.Areasets, this.Parent.TileSize, this.DefaultTile)
                {
                    SizeChangedLayer = true
                };
                l.LoadFromImage(GameBase.LoadImageSource(layer["Tiles"].Data), areasets);

                foreach (MekaItem entity in layer["Entities"].Children)
                {
                    EntityIcon i = new EntityIcon(l, Editor.EntityTypes.First(item => item.Name == entity.Name), _dragged: false)
                    {
                        LoadInfo = entity
                    };
                    //i.LoadFromItem(entity);
                    l.Entities.Add(i);
                    this.Children.Add(i);
                }

                this.Layers.Add(l);

                if (layer.Contains("Main"))
                {
                    this.MainLayer = l;
                }
            }

            this.SwitchToLayer(this.Layers.IndexOf(this.MainLayer));

            this.Editor.LayerList.NeedsUpdate    = true;
            this.Editor.LevelPreview.NeedsUpdate = true;

            this.UpdateFrame();

            //ImageSource tiles = new ImageSource(level["Tiles"].Data);
            //this.Size = tiles.Size;

            //for (int x = 0; x < tiles.Size.X; x++)
            //{
            //	for (int y = 0; y < tiles.Size.Y; y++)
            //		//this.Draw(new Point(x, y), Beth.FromEndian(tiles[x, y].Bytes.Sub(0, 3)));
            //		this.Layer[x, y] = Beth.FromEndian(tiles[x, y].Bytes.Sub(0, 3));
            //}

            //this.Editor.EntityEditor.Select(null);

            //foreach (MekaItem entity in level["Entities"].Children)
            //{
            //	EntityIcon e = new EntityIcon(Editor.EntityTypes.First(item => item.Name == entity.Name), _dragged: false);

            //	e.Position = entity["Settings"]["Position"].To<Vector>();

            //	foreach (MekaItem property in entity["Properties"].Children)
            //		e.Properties.First(item => item.Name == property.Name).Value = property.Content;

            //	this.Children.Add(e);
            //}
        }