示例#1
0
        /// <summary>
        /// Handles the Click event of the saveToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MapForm activeForm = (MapForm)this.ActiveMdiChild;

            if (activeForm == null)
            {
                return;
            }
            if (activeForm.Map.Levelfilename == null)
            {
                SaveAsToolStripMenuItem_Click(sender, e);
            }
            else
            {
                MapManagerXML MapManager = new MapManagerXML();
                MapManager.Save(activeForm.Map.Levelfilename, activeForm.Map, null);
            }
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// Runs the actual map in the emulator
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void runMap_Click(object sender, EventArgs e)
        {
            // Get path of the executable
            String appDir = Path.GetDirectoryName(Application.ExecutablePath);

            // Export actual view to .\level\StartLevel.map
            MapManagerBinary MapManager = new MapManagerBinary();
            MapForm          activeForm = (MapForm)this.ActiveMdiChild;

            if (activeForm == null)
            {
                return;
            }
            Directory.CreateDirectory(appDir + "\\level");
            MapManager.Save(appDir + "\\level\\StartLevel.map", activeForm.Map, tilesetToolbox.TileControl.Tilesets);


            // Run zip program to add level-data to .jar archive
            try
            {
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.EnableRaisingEvents              = false;
                proc.StartInfo.WorkingDirectory       = appDir;
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.FileName       = "zip.exe";
                proc.StartInfo.Arguments      = "-r prototype.jar level";
                proc.StartInfo.CreateNoWindow = true;
                proc.Start();
                proc.WaitForExit();
            }
            catch (Exception ex)
            {
                string message = "I am not able to find a compression tool in your program folder." + System.Environment.NewLine;
                message += "Verify that you have zip.exe in your programfolder!";
                message += System.Environment.NewLine + ex.Message;
                MessageBox.Show(message, "We have a Problem:", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }


            if (!File.Exists(appDir + "\\prototype.jar"))
            {
                MessageBox.Show("Error while compiling the map.", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Create .jad-file with correct size of .jar-file
            FileInfo f       = new FileInfo(appDir + "\\prototype.jar");
            string   strText = "MIDlet-1: javy prototype, , GameMIDlet\nMIDlet-Jar-Size: " + f.Length;

            strText += "\nMIDlet-Jar-URL: prototype.jar\nMIDlet-Name: GameMIDlet\nMIDlet-Vendor: Midlet Suite Vendor\n";
            strText += "MIDlet-Version: 1.0.0\nMicroEdition-Configuration: CLDC-1.1\nMicroEdition-Profile: MIDP-2.0";
            File.WriteAllText(appDir + "\\prototype.jad", strText);

            // Finally run the emulater from the wtk directory
            try
            {
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc = new System.Diagnostics.Process();
                proc.EnableRaisingEvents        = false;
                proc.StartInfo.WorkingDirectory = appDir;
                proc.StartInfo.UseShellExecute  = false;
                proc.StartInfo.CreateNoWindow   = true;
                proc.StartInfo.FileName         = Javy.Properties.Settings.Default.wtkDirectory +
                                                  "\\bin\\emulator.exe";
                proc.StartInfo.Arguments = "-Xdescriptor \"" + appDir + "\\prototype.jad\"";
                proc.Start();
            }
            catch (Exception ex)
            {
                string message = "I can't find the emulator of the Java WTK!" + System.Environment.NewLine;
                message += "Verify that you have setup the correct path for the WTK25 in your Leveleditor.exe.config file.";
                message += System.Environment.NewLine + ex.Message;
                MessageBox.Show(message, "We have a Problem:", MessageBoxButtons.OK, MessageBoxIcon.Information);
                OptionsForm options = new OptionsForm();
                options.ShowDialog();
            }
        }
示例#4
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.
            }
        }