Inheritance: AbstractFile
Exemple #1
0
        public MapEditor(MapFile file)
            : base(file)
        {
            map = file;
            this.tileset = map.TilesetFile[map.TilesetID];

            mapPanel = new MapPanel(map.Layers, tileset);
            mapPanel.Dock = System.Windows.Forms.DockStyle.Fill;
            this.Controls.Add(mapPanel);
            this.KeyPreview = true;
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(MapEditor_KeyDown);

            this.mapPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(mapPanel_MouseDown);
            this.mapPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(mapPanel_MouseMove);

            tilePanel = new TilePanel(tileset);
            tilePanel.TileSelected += new EventHandler<TilePanel.TileSelectedArgs>(tilePanel_TileSelected);
            tilePanel.Dock = System.Windows.Forms.DockStyle.Fill;

            toolstrip = new System.Windows.Forms.ToolStrip();
            toolstrip.Dock = System.Windows.Forms.DockStyle.Top;
            toolstrip.Stretch = true;
            toolstrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;

            buttonSelected = new System.Windows.Forms.ToolStripButton();
            buttonSelected.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.SizeToFit;
            buttonSelected.AutoSize = true;
            buttonSelected.Image = tileset[0];
            buttonSelected.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;

            toolstrip.Items.Add(buttonSelected);
            toolstrip.Items.Add(new System.Windows.Forms.ToolStripSeparator());

            buttonLayers = new List<System.Windows.Forms.ToolStripButton>();
            for (int i = 0; i < this.map.Layers.Count; i++)
            {
                var laybtn = new System.Windows.Forms.ToolStripButton();
                laybtn.Text = string.Format("{0}", i + 1);
                laybtn.Tag = i;
                laybtn.Click += new EventHandler(laybtn_Click);
                if (this.map.Layers[i].Type == MapLayerType.HalfBlockShadow)
                {
                    laybtn.Text = "阴影";
                }
                toolstrip.Items.Add(laybtn);
                buttonLayers.Add(laybtn);
            }

            toolboxPanel = new System.Windows.Forms.Panel();
            this.toolboxPanel.Controls.Add(tilePanel);
            this.toolboxPanel.Controls.Add(toolstrip);
        }
Exemple #2
0
        public MapInfoFile(Dictionary <string, object> node)
            : base(
                System.IO.Path.Combine(
                    ProjectManager.ProjectDir,
                    node["FileName"].ToString()
                    )
                )
        {
            this.maps = new Dictionary <string, MapFile>();
            this.IsSubfileProvider = true;

            this.TilesetFile = ProjectManager.Components[node["TilesetProvider"].ToString()] as TilesetFile;

            RubyHash mapHash = NekoKun.Serialization.RubyMarshal.RubyMarshal.Load(
                new System.IO.FileStream(this.filename, System.IO.FileMode.Open, System.IO.FileAccess.Read)
                ) as RubyHash;

            foreach (var item in mapHash)
            {
                string  key = null;
                string  filename;
                MapFile map = null;
                if (item.Key is int)
                {
                    key      = item.Key.ToString();
                    filename = String.Format(node["FileNameFormat"].ToString(), (int)item.Key);
                    map      = new MapFile(System.IO.Path.Combine(ProjectManager.ProjectDir, filename), this.TilesetFile);
                }
                else
                {
                    this.MakeDirty();
                    continue;
                }
                this.maps.Add(key, map);

                RubyObject info = item.Value as RubyObject;
                map.Title    = (info.InstanceVariable["@name"] as RubyString).Text;
                map.ParentID = info.InstanceVariable["@parent_id"].ToString();
                map.Order    = (int)info.InstanceVariable["@order"];

                /*
                 *  parent_id
                 *  The parent map ID.
                 *
                 *  order
                 *  The map tree display order, which is used internally.
                 *
                 *  expanded
                 *  The map tree expansion flag, which is used internally.
                 *
                 *  scroll_x
                 *  The x-axis scroll position, which is used internally.
                 *
                 *  scroll_y
                 *  The y-axis scroll position, which is used internally.
                 */
            }
            this.maps.ToString();



            nodes = new Dictionary <string, System.Windows.Forms.TreeNode>();
            List <System.Windows.Forms.TreeNode> order = new List <System.Windows.Forms.TreeNode>();

            foreach (var item in maps)
            {
                System.Windows.Forms.TreeNode node2 = new System.Windows.Forms.TreeNode(item.Value.Title);
                node2.Tag = item.Value;
                nodes.Add(item.Key, node2);
                order.Add(node2);
            }

            order.Sort(
                delegate(System.Windows.Forms.TreeNode me, System.Windows.Forms.TreeNode other)
            {
                return((me.Tag as MapFile).Order.CompareTo((other.Tag as MapFile).Order));
            }
                );

            foreach (System.Windows.Forms.TreeNode item in order)
            {
                MapFile map = item.Tag as MapFile;
                if (map.ParentID != null && nodes.ContainsKey(map.ParentID))
                {
                    nodes[map.ParentID].Nodes.Add(item);
                }
            }
        }
Exemple #3
0
        public MapInfoFile(Dictionary<string, object> node)
            : base(System.IO.Path.Combine(
                    ProjectManager.ProjectDir,
                    node["FileName"].ToString()
                ))
        {
            this.maps = new Dictionary<string, MapFile>();
            this.IsSubfileProvider = true;

            this.TilesetFile = ProjectManager.Components[node["TilesetProvider"].ToString()] as TilesetFile;

            RubyHash mapHash = NekoKun.Serialization.RubyMarshal.RubyMarshal.Load(
                new System.IO.FileStream(this.filename,  System.IO.FileMode.Open, System.IO.FileAccess.Read)
            ) as RubyHash;
            foreach (var item in mapHash)
            {
                string key = null;
                string filename;
                MapFile map = null;
                if (item.Key is int)
                {
                    key = item.Key.ToString();
                    filename = String.Format(node["FileNameFormat"].ToString(), (int)item.Key);
                    map = new MapFile(System.IO.Path.Combine(ProjectManager.ProjectDir, filename), this.TilesetFile);
                }
                else
                {
                    this.MakeDirty();
                    continue;
                }
                this.maps.Add(key, map);

                RubyObject info = item.Value as RubyObject;
                map.Title = (info.InstanceVariable["@name"] as RubyString).Text;
                map.ParentID = info.InstanceVariable["@parent_id"].ToString();
                map.Order = (int)info.InstanceVariable["@order"];
                /*
                    parent_id
                    The parent map ID.

                    order
                    The map tree display order, which is used internally.

                    expanded
                    The map tree expansion flag, which is used internally.

                    scroll_x
                    The x-axis scroll position, which is used internally.

                    scroll_y
                    The y-axis scroll position, which is used internally.
                */
            }
            this.maps.ToString();

            nodes = new Dictionary<string, System.Windows.Forms.TreeNode>();
            List<System.Windows.Forms.TreeNode> order = new List<System.Windows.Forms.TreeNode>();

            foreach (var item in maps)
            {
                System.Windows.Forms.TreeNode node2 = new System.Windows.Forms.TreeNode(item.Value.Title);
                node2.Tag = item.Value;
                nodes.Add(item.Key, node2);
                order.Add(node2);
            }

            order.Sort(
                delegate(System.Windows.Forms.TreeNode me, System.Windows.Forms.TreeNode other)
                {
                    return (me.Tag as MapFile).Order.CompareTo((other.Tag as MapFile).Order);
                }
            );

            foreach (System.Windows.Forms.TreeNode item in order)
            {
                MapFile map = item.Tag as MapFile;
                if (map.ParentID != null && nodes.ContainsKey(map.ParentID))
                    nodes[map.ParentID].Nodes.Add(item);
            }
        }