示例#1
0
        public void LoadMap()
        {
            if (String.IsNullOrEmpty(this._tilesetPath) == false)
            {
                string name   = _tilesetPath.Substring(_tilesetPath.LastIndexOf('\\'));
                var    result = MessageBox.Show(
                    "Do you want save " + name + "?",
                    "Save TileSet", MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Question,
                    MessageBoxDefaultButton.Button2,
                    MessageBoxOptions.ServiceNotification);
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    TilesMap.Save(_mapController.TilesMap, _tilesetPath);
                }
                _tilesetPath = String.Empty;
            }
            var openfiledialog = new OpenFileDialog();

            openfiledialog.Filter = "XML Files (*.xml)|*.xml";
            var rs = openfiledialog.ShowDialog();

            if (rs != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            Cursor.Current          = Cursors.WaitCursor;
            _mapController.TilesMap = TilesMap.Load(openfiledialog.FileName);
            this._tilesetPath       = openfiledialog.FileName;

            listView1.LargeImageList = _mapController.getImageList();
            listView1.Items.AddRange(_mapController.getListViewItems().ToArray());

            this.InitTableLayout();

            // Khởi tạo ObjectEditor
            this._mapController.InitObjectEditor();
            this._mapController.ObjectEditor.Bind(this.listBoxObject);
            this._mapController.ObjectEditor.ListItem.ListChanged += (object s, ListChangedEventArgs arg) =>
            {
                this.enableSaveButton();
                var mapbound = new Rectangle(0, 0,
                                             this._mapController.TilesMap.GetMapWidth(),
                                             this._mapController.TilesMap.GetMapHeight());
                this._mapController.ObjectEditor.InitQuadTree(0, mapbound);
                _mapController.Draw(mapbound);
                if (toolbar.QuadTree.Pushed)
                {
                    this._mapController.RenderQuadTree();
                }
            };
            _mapController.Draw(getVisibleMap());
            Cursor.Current = Cursors.Default;
            this.disableSaveButton();
        }