Ejemplo n.º 1
0
        private void CreateMapForm(string Caption, Map Map)
        {
            // Create a new instance of the child form.
            MapForm childForm = new MapForm();

            // Make it a child of this MDI form before showing it.

            childForm.MdiParent          = this;
            childForm.Text               = Caption;
            childForm.EditorMDI          = this;
            childForm.BrushOptions       = brushToolbox.BrushOptions;
            childForm.TileControl        = tilesetToolbox.TileControl;
            childForm.MapObjectInspector = mapObjectInspectorToolbox.MapObjectInspector;

            childForm.Map         = Map;
            childForm.UndoControl = undoToolbox.UndoControl;
            childForm.Show(dockPanel);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Opens the file.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            //openFileDialog.InitialDirectory =
            //    SettingsManager.GetInstance()["OpenFileDialog-Path"].Get(
            //        Environment.GetFolderPath(Environment.SpecialFolder.Personal));
            // added correct .NET Property Settings
            openFileDialog.InitialDirectory = Properties.Settings.Default.PathToMaps;

            openFileDialog.Filter = "Level Files (*.lvl)|*.lvl|All Files (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
                //SettingsManager.GetInstance()["OpenFileDialog-Path"].Set(Path.GetDirectoryName(openFileDialog.FileName));

                // save the Open-Maps-Path to the settings
                Properties.Settings.Default.PathToMaps = Path.GetDirectoryName(openFileDialog.FileName);

                if (FileName.EndsWith("lvl"))
                {
                    MapManagerXML MapManager = new MapManagerXML();
                    Map           map        = MapManager.Load(FileName);
                    if (map != null)  // Error occured while loading
                    {
                        // Checking for tilesets

                        List <uint> list = new List <uint>();
                        for (int y = 0; y < map.Height; y++)        // Scan mapData for used tiles
                        {
                            for (int x = 0; x < map.Width; x++)
                            {
                                uint graphicID = (map.GetField(x, y).GetGraphicID()) >> 16;
                                int  index     = list.IndexOf(graphicID);
                                if (index == -1)            // Tile not yet in list
                                {
                                    list.Add(graphicID);
                                }
                            }
                        }
                        int ind;
                        // Scan map objects for used tiles
                        IMapObject[] mapobjects = map.GetObjects();
                        foreach (IMapObject obj in mapobjects)
                        {
                            byte[] data = obj.GetExportData(list);
                            if (data[0] == 1)  // Static object
                            {
                                StaticMapObject obj2 = (StaticMapObject)obj;
                                for (int y = 0; y < obj2.SizeY; y++)
                                {
                                    for (int x = 0; x < obj2.SizeX; x++)
                                    {
                                        uint graphicID = (obj2.Tiles.GetField(x, y).GetGraphicID()) >> 16;
                                        ind = list.IndexOf(graphicID);
                                        if (ind == -1)
                                        {
                                            list.Add(graphicID);
                                        }
                                    }
                                }
                            }
                            if (data[0] == 4)   // Door object
                            {
                                DoorMapObject obj2 = (DoorMapObject)obj;
                                ind = list.IndexOf((obj2.Graphic_id_open) >> 16);
                                if (ind == -1)
                                {
                                    list.Add((obj2.Graphic_id_open) >> 16);
                                }
                                ind = list.IndexOf((obj2.Graphic_id_closed) >> 16);
                                if (ind == -1)
                                {
                                    list.Add((obj2.Graphic_id_closed) >> 16);
                                }
                            }
                            if (data[0] == 5)   // Container object
                            {
                                ContainerMapObject obj2 = (ContainerMapObject)obj;
                                ind = list.IndexOf((obj2.Graphic_id_open) >> 16);
                                if (ind == -1)
                                {
                                    list.Add((obj2.Graphic_id_open) >> 16);
                                }
                                ind = list.IndexOf((obj2.Graphic_id_closed) >> 16);
                                if (ind == -1)
                                {
                                    list.Add((obj2.Graphic_id_closed) >> 16);
                                }
                            }
                            if (data[0] == 6)   // Breakable object
                            {
                                BreakableMapObject obj2 = (BreakableMapObject)obj;
                                ind = list.IndexOf((obj2.Graphic_id_open) >> 16);
                                if (ind == -1)
                                {
                                    list.Add((obj2.Graphic_id_open) >> 16);
                                }
                                ind = list.IndexOf((obj2.Graphic_id_closed) >> 16);
                                if (ind == -1)
                                {
                                    list.Add((obj2.Graphic_id_closed) >> 16);
                                }
                            }
                            if (data[0] == 7)   // Movable object
                            {
                                MovableMapObject obj2 = (MovableMapObject)obj;
                                ind = list.IndexOf((obj2.Graphic_id) >> 16);
                                if (ind == -1)
                                {
                                    list.Add((obj2.Graphic_id) >> 16);
                                }
                            }
                        }       // Done scanning used tilesets
                        string message = "";
                        bool   ready   = true;
                        foreach (uint tileset in list)
                        {
                            if (!(tilesetToolbox.TileControl.isLoaded((int)tileset)))
                            {
                                ready   = false;
                                message = message + tileset.ToString() + " ";
                            }
                        }
                        if (ready)                  // All tilesets l
                        {
                            CreateMapForm(FileName, map);

                            /*
                             *
                             * MapForm childForm = new MapForm();
                             *
                             * childForm.Map = map;
                             *
                             *
                             * childForm.MdiParent = this;
                             * childForm.Text = FileName;// "Map " + childFormNumber++;
                             * childForm.Show(dockPanel);
                             * childForm.EditorMDI = this;
                             * childForm.TileControl = tilesetToolbox.TileControl;
                             * childForm.BrushOptions = brushToolbox.BrushOptions;
                             * childForm.UndoControl = undoToolbox.UndoControl;
                             * childForm.MapObjectInspector = mapObjectInspectorToolbox.MapObjectInspector;
                             */
                        }
                        else                    // Missing tilesets
                        {
                            //MessageBox.Show("Missing tilesets:" + message);
                            // Todo: Add dialog to allow tileset substitution
                            MapForm childForm = new MapForm();
                            childForm.Map = map;
                            MissingTilesetForm missingTilesetForm = new MissingTilesetForm(childForm.MapControl, tilesetToolbox.TileControl);
                            DialogResult       result             = missingTilesetForm.ShowDialog();
                            if (result == DialogResult.OK)
                            {
                                childForm.MdiParent = this;
                                childForm.Text      = FileName;// "Map " + childFormNumber++;
                                childForm.Show(dockPanel);
                                childForm.EditorMDI          = this;
                                childForm.TileControl        = tilesetToolbox.TileControl;
                                childForm.BrushOptions       = brushToolbox.BrushOptions;
                                childForm.UndoControl        = undoToolbox.UndoControl;
                                childForm.MapObjectInspector = mapObjectInspectorToolbox.MapObjectInspector;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid file!");
                    }
                }
                else
                {
                    MessageBox.Show("Unsupported file format!");
                }
                // TODO: Add more file formats and error checking.
            }
        }