Пример #1
0
        private void OK_Click(object sender, EventArgs e)
        {
            Map replaceMap   = mapControl.Map.CopyRegion();
            int count        = 0;
            int missingCount = MissingTilesetBox.Items.Count;

            for (int i = 0; i < missingCount; i++)
            {
                count = count + replaceMap.ReplaceTilesets(replacement[i, 0], replacement[i, 1]);
                foreach (IMapObject obj in replaceMap.GetObjects())
                {
                    if (obj is StaticMapObject)  // Static object
                    {
                        StaticMapObject obj2 = (StaticMapObject)obj;
                        count = count + obj2.Tiles.ReplaceTilesets(replacement[i, 0], replacement[i, 1]);
                    }
                    if (obj is DoorMapObject)   // Door object
                    {
                        DoorMapObject obj2 = (DoorMapObject)obj;
                        count = count + obj2.Tiles.ReplaceTilesets(replacement[i, 0], replacement[i, 1]);
                    }
                    if (obj is ContainerMapObject)   // Container object
                    {
                        ContainerMapObject obj2 = (ContainerMapObject)obj;
                        count = count + obj2.Tiles.ReplaceTilesets(replacement[i, 0], replacement[i, 1]);
                    }
                    if (obj is BreakableMapObject)   // Breakable object
                    {
                        BreakableMapObject obj2 = (BreakableMapObject)obj;
                        count = count + obj2.Tiles.ReplaceTilesets(replacement[i, 0], replacement[i, 1]);
                    }
                    if (obj is MovableMapObject)   // Movable object
                    {
                        MovableMapObject obj2 = (MovableMapObject)obj;
                        count = count + obj2.Tiles.ReplaceTilesets(replacement[i, 0], replacement[i, 1]);
                    }
                }
            }
            mapControl.Map = replaceMap;        // Done replacing map tiles


            MessageBox.Show(count + " Tiles have been replaced.", "Tileset successfully replaced!",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);

            DialogResult = DialogResult.OK;
        }
Пример #2
0
        private void ReplaceButton_Click(object sender, EventArgs e)
        {
            if (MapComboBox.SelectedItem != null && ReplaceComboBox.SelectedItem != null)
            {
                // Before / After State for UndoManager
                Map replaceMap = mapControl.Map.CopyRegion();
                int count      = replaceMap.ReplaceTilesets((uint)MapComboBox.SelectedItem, (uint)ReplaceComboBox.SelectedItem);

                foreach (IMapObject obj in replaceMap.GetObjects())
                {
                    if (obj is StaticMapObject)  // Static object
                    {
                        StaticMapObject obj2 = (StaticMapObject)obj;
                        count = count + obj2.Tiles.ReplaceTilesets((uint)MapComboBox.SelectedItem, (uint)ReplaceComboBox.SelectedItem);
                    }
                    if (obj is DoorMapObject)   // Door object
                    {
                        DoorMapObject obj2 = (DoorMapObject)obj;
                        count = count + obj2.Tiles.ReplaceTilesets((uint)MapComboBox.SelectedItem, (uint)ReplaceComboBox.SelectedItem);
                    }
                    if (obj is ContainerMapObject)   // Container object
                    {
                        ContainerMapObject obj2 = (ContainerMapObject)obj;
                        count = count + obj2.Tiles.ReplaceTilesets((uint)MapComboBox.SelectedItem, (uint)ReplaceComboBox.SelectedItem);
                    }
                    if (obj is BreakableMapObject)   // Breakable object
                    {
                        BreakableMapObject obj2 = (BreakableMapObject)obj;
                        count = count + obj2.Tiles.ReplaceTilesets((uint)MapComboBox.SelectedItem, (uint)ReplaceComboBox.SelectedItem);
                    }
                    if (obj is MovableMapObject)   // Movable object
                    {
                        MovableMapObject obj2 = (MovableMapObject)obj;
                        count = count + obj2.Tiles.ReplaceTilesets((uint)MapComboBox.SelectedItem, (uint)ReplaceComboBox.SelectedItem);
                    }
                }


                MessageBox.Show(count + " Tiles have been replaced.", "Tileset successfully replaced!",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                mapControl.Map = replaceMap;    // Assign new Map with replacements and refresh map control
                DialogResult   = DialogResult.OK;
            }
        }
Пример #3
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.
            }
        }
Пример #4
0
        public MissingTilesetForm(MapControl mapControl, TileControl tileControl)
        {
            InitializeComponent();
            this.mapControl = mapControl;
            List <uint> list = mapControl.Map.UsedTilesetIDs;
            int         ind;

            IMapObject[] mapobjects = mapControl.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
            foreach (uint id in list)
            {
                if (!tileControl.isLoaded((int)id))
                {
                    MissingTilesetBox.Items.Add(id);      // Get missing tilesets
                }
            }
            // Get available Tilesets
            foreach (uint id in tileControl.AvaibleTilesetIds)
            {
                MapTilesetBox.Items.Add(id);
            }
            int missingCount = MissingTilesetBox.Items.Count;

            replacement = new uint[missingCount, 2];
            for (int i = 0; i < missingCount; i++)
            {
                replacement[i, 0]          = (uint)MissingTilesetBox.Items[i];
                replacement[i, 1]          = 0;
                MissingTilesetBox.Items[i] = MissingTilesetBox.Items[i].ToString() + " -> " + MapTilesetBox.Items[(int)replacement[i, 1]].ToString();
            }
            MissingTilesetBox.SelectedIndex = 0;
            MapTilesetBox.SelectedIndex     = (int)replacement[0, 1];
        }
Пример #5
0
        private IMapObject RandomObject(Random rnd)
        {
            int        type = rnd.Next(17);
            IMapObject obj;

            switch (type)
            {
            case 0:
                obj = new BreakableMapObject();
                break;

            case 1:
                obj = new ContainerMapObject();
                break;

            case 2:
                obj = new DamagerMapObject();
                break;

            case 3:
                obj = new DoorMapObject();
                break;

            case 4:
                obj = new EnemyMapObject();
                break;

            case 5:
                obj = new MovableMapObject();
                break;

            case 6:
                obj = new SoundMapObject();
                break;

            case 7:
                obj = new StaticMapObject();
                break;

            case 8:
                obj = new TriggerCommentMapObject();
                break;

            case 9:
                obj = new TriggerContainerMapObject();
                break;

            case 10:
                obj = new TriggerContainerSoundMapObject();
                break;

            case 11:
                obj = new TriggerDoorMapObject();
                break;

            case 12:
                obj = new TriggerDoorSoundMapObject();
                break;

            case 13:
                obj = new TriggerEnablerMapObject();
                break;

            case 14:
                obj = new TriggerExitMapObject();
                break;

            case 15:
                obj = new TriggerMapObject();
                break;

            case 16:
                obj = new TriggerTeleportMapObject();
                break;

            default:
                obj = new StaticMapObject();
                break;
            }
            return(obj);
        }
Пример #6
0
        /// <summary>
        /// Creates a randomized map.
        /// </summary>
        /// <param name="width">The width of the map.</param>
        /// <param name="height">The height of the map.</param>
        /// <param name="objects">The number of objects to be inserted.</param>
        /// <returns></returns>
        private Map CreateRandomMap(int width, int height, int objects)
        {
            Console.WriteLine("  - Creating randomized map: " + width.ToString() + "x" + height.ToString());
            Map           map = new Map(width, height);
            InternalField fld = new InternalField();
            Collision     col = new Collision();
            Random        rnd = new Random();

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    fld = new InternalField();
                    col = new Collision((rnd.Next(2) == 1), (rnd.Next(2) == 1), (rnd.Next(2) == 1), (rnd.Next(2) == 1));
                    fld.SetCollision(col);
                    fld.SetGraphicID((uint)(rnd.Next(int.MaxValue)));
                    map.SetField(x, y, fld);
                }
            }

            int        type;
            IMapObject obj;

            Console.Write("  - Creating objects");
            for (int i = 0; i < objects; i++)
            {
                if (i % 1000 == 0)
                {
                    Console.Write(".");
                }
                type = rnd.Next(17);
                switch (type)
                {
                case 0:
                    obj = new BreakableMapObject();
                    break;

                case 1:
                    obj = new ContainerMapObject();
                    break;

                case 2:
                    obj = new DamagerMapObject();
                    break;

                case 3:
                    obj = new DoorMapObject();
                    break;

                case 4:
                    obj = new EnemyMapObject();
                    break;

                case 5:
                    obj = new MovableMapObject();
                    break;

                case 6:
                    obj = new SoundMapObject();
                    break;

                case 7:
                    obj = new StaticMapObject();
                    break;

                case 8:
                    obj = new TriggerCommentMapObject();
                    break;

                case 9:
                    obj = new TriggerContainerMapObject();
                    break;

                case 10:
                    obj = new TriggerContainerSoundMapObject();
                    break;

                case 11:
                    obj = new TriggerDoorMapObject();
                    break;

                case 12:
                    obj = new TriggerDoorSoundMapObject();
                    break;

                case 13:
                    obj = new TriggerEnablerMapObject();
                    break;

                case 14:
                    obj = new TriggerExitMapObject();
                    break;

                case 15:
                    obj = new TriggerMapObject();
                    break;

                case 16:
                    obj = new TriggerTeleportMapObject();
                    break;

                default:
                    obj = new StaticMapObject();
                    break;
                }
                obj.PosX  = rnd.Next(width);
                obj.PosY  = rnd.Next(height);
                obj.SizeX = 1;
                obj.SizeY = 1;

                map.InsertObject(obj);

                obj = null;
            }
            Console.WriteLine();
            Console.WriteLine("  - Map created.");
            return(map);
        }
Пример #7
0
        public IMapObject GenerateObject()
        {
            IMapObject obj = null;

            if (objectType.SelectedItem.ToString() == ObjectStatic)
            {
                obj = new StaticMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTrigger)
            {
                obj = new TriggerMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectEnemy)
            {
                obj = new EnemyMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectDoor)
            {
                obj = new DoorMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectContainer)
            {
                obj = new ContainerMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectBreakable)
            {
                obj = new BreakableMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectMovable)
            {
                obj = new MovableMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectItem)
            {
                obj = new ItemMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectSound)
            {
                obj = new SoundMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectDamager)
            {
                obj = new DamagerMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectEnemy)
            {
                obj = new EnemyMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerDoor)
            {
                obj = new TriggerDoorMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerContainer)
            {
                obj = new TriggerContainerMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerDoorSound)
            {
                obj = new TriggerDoorSoundMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerContainerSound)
            {
                obj = new TriggerContainerSoundMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerExit)
            {
                obj = new TriggerExitMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerTeleport)
            {
                obj = new TriggerTeleportMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerEnabler)
            {
                obj = new TriggerEnablerMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerComment)
            {
                obj = new TriggerCommentMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectMapStart)
            {
                obj = new MapStart();
            }
            obj.SizeX = 1;
            obj.SizeY = 1;
            return(obj);
        }