Exemplo n.º 1
0
        // Linedef flags
        private void LoadLinedefFlags()
        {
            IDictionary dic;

            // Get linedef flags
            dic = cfg.ReadSetting("linedefflags", new Hashtable());
            foreach (DictionaryEntry de in dic)
            {
                linedefflags.Add(de.Key.ToString(), de.Value.ToString());
            }

            // ano
            dic = cfg.ReadSetting("linedefflagtooltips", new Hashtable());
            foreach (DictionaryEntry de in dic)
            {
                linedefflagtooltips.Add(de.Key.ToString(), de.Value.ToString());
            }

            // Get translations
            dic = cfg.ReadSetting("linedefflagstranslation", new Hashtable());
            foreach (DictionaryEntry de in dic)
            {
                linedefflagstranslation.Add(new FlagTranslation(de));
            }

            // Sort flags?
            MapSetIO io = MapSetIO.Create(formatinterface);

            if (io.HasNumericLinedefFlags)
            {
                // Make list for integers that we can sort
                List <int> sortlist = new List <int>(linedefflags.Count);
                foreach (KeyValuePair <string, string> f in linedefflags)
                {
                    int num;
                    if (int.TryParse(f.Key, NumberStyles.Integer, CultureInfo.InvariantCulture, out num))
                    {
                        sortlist.Add(num);
                    }
                }

                // Sort
                sortlist.Sort();

                // Make list of strings
                foreach (int i in sortlist)
                {
                    sortedlinedefflags.Add(i.ToString(CultureInfo.InvariantCulture));
                }
            }

            // Sort the flags, because they must be compared highest first!
            linedefflagstranslation.Sort();
        }
Exemplo n.º 2
0
        internal void ShowMapOptions()
        {
            // Cancel volatile mode, if any
            General.Editing.DisengageVolatileMode();

            // Show map options dialog
            MapOptionsForm optionsform = new MapOptionsForm(options);

            if (optionsform.ShowDialog(General.MainWindow) == DialogResult.OK)
            {
                // Update interface
                General.MainWindow.UpdateInterface();

                // Stop data manager
                data.Dispose();

                // Apply new options
                this.options = optionsform.Options;

                // Load new game configuration
                General.WriteLogLine("Loading game configuration...");
                configinfo = General.GetConfigurationInfo(options.ConfigFile);
                config     = new GameConfiguration(General.LoadGameConfiguration(options.ConfigFile));
                configinfo.ApplyDefaults(config);
                General.Editing.UpdateCurrentEditModes();

                // Setup new map format IO
                General.WriteLogLine("Initializing map format interface " + config.FormatInterface + "...");
                io = MapSetIO.Create(config.FormatInterface, this);

                // Let the plugins know
                General.Plugins.MapReconfigure();

                // Update interface
                General.MainWindow.SetupInterface();
                General.MainWindow.UpdateThingsFilters();
                General.MainWindow.UpdateInterface();

                // Reload resources
                ReloadResources();

                // Done
                General.MainWindow.DisplayReady();
            }

            // Done
            optionsform.Dispose();
        }
Exemplo n.º 3
0
        // Initializes for an existing map
        internal bool InitializeOpenMap(string filepathname, MapOptions options)
        {
            // Apply settings
            this.filename     = Path.GetFileName(filepathname);
            this.filepathname = filepathname;
            this.filepath     = Path.GetDirectoryName(filepathname);
            this.changed      = false;
            this.options      = options;

            General.WriteLogLine("Opening map \"" + this.filename + "\" with configuration \"" + options.ConfigFile + "\"");

            // Initiate graphics
            General.WriteLogLine("Initializing graphics device...");
            graphics = new D3DDevice(General.MainWindow.Display);
            if (!graphics.Initialize())
            {
                return(false);
            }

            // Create renderers
            renderer2d = new Renderer2D(graphics);
            renderer3d = new Renderer3D(graphics);

            // Load game configuration
            General.WriteLogLine("Loading game configuration...");
            configinfo = General.GetConfigurationInfo(options.ConfigFile);
            config     = new GameConfiguration(General.LoadGameConfiguration(options.ConfigFile));
            configinfo.ApplyDefaults(config);
            General.Editing.UpdateCurrentEditModes();

            // Create map data
            bool maprestored = false;             //mxd

            map = new MapSet();

            string mapname = Path.GetFileNameWithoutExtension(filepathname);

            if (!string.IsNullOrEmpty(mapname))
            {
                string hash       = MurmurHash2.Hash(mapname + File.GetLastWriteTime(filepathname)).ToString();
                string backuppath = Path.Combine(General.MapRestorePath, mapname + "." + hash + ".restore");

                // Backup exists and it's newer than the map itself?
                if (File.Exists(backuppath) && File.GetLastWriteTime(backuppath) > File.GetLastWriteTime(filepathname))
                {
                    if (General.ShowWarningMessage("Looks like your previous editing session has gone terribly wrong." + Environment.NewLine
                                                   + "Would you like to restore the map from the backup?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        General.WriteLogLine("Initializing map format interface " + config.FormatInterface + "...");
                        io = MapSetIO.Create(config.FormatInterface, this);
                        General.WriteLogLine("Restoring map from \"" + backuppath + "\"...");

#if DEBUG
                        // Restore map
                        map.Deserialize(new MemoryStream(File.ReadAllBytes(backuppath)));
#else
                        try
                        {
                            // Restore map
                            map.Deserialize(new MemoryStream(File.ReadAllBytes(backuppath)));

                            // Delete the backup
                            File.Delete(backuppath);
                        }
                        catch (Exception e)
                        {
                            General.ErrorLogger.Add(ErrorType.Error, "Unable to restore the map data structures from the backup. " + e.GetType().Name + ": " + e.Message);
                            General.ShowErrorMessage("Unable to restore the map data structures from the backup.", MessageBoxButtons.OK);
                            return(false);
                        }
#endif
                        maprestored = true;
                    }
                }
            }

            // Read the map from file
            if (!maprestored)
            {
                map.BeginAddRemove();

                General.WriteLogLine("Initializing map format interface " + config.FormatInterface + "...");
                io = MapSetIO.Create(config.FormatInterface, this);
                General.WriteLogLine("Reading map data structures from file...");

#if !DEBUG
                try
                {
#endif
                using (FileStream stream = File.OpenRead(filepathname))
                {
                    io.Read(map, stream);
                }
#if !DEBUG
            }
            catch (Exception e)
            {
                General.ErrorLogger.Add(ErrorType.Error, "Unable to read the map data structures with the specified configuration. " + e.GetType().Name + ": " + e.Message);
                General.ShowErrorMessage("Unable to read the map data structures with the specified configuration.", MessageBoxButtons.OK);
                return(false);
            }
#endif

                map.EndAddRemove();
            }


            // Load data manager
            General.WriteLogLine("Loading data resources...");
            data = new DataManager();
            data.Load(CreateResourcesList());

            // Remove unused sectors
            map.RemoveUnusedSectors(true);

            // Update structures
            options.ApplyGridSettings();
            map.UpdateConfiguration();
            //map.SnapAllToAccuracy();
            map.Update();
            thingsfilter.Update();

            // Bind any methods
            General.Actions.BindMethods(this);

            // Set defaults
            this.visualcamera = new VisualCamera();
            General.Editing.ChangeMode(configinfo.StartMode);
            renderer2d.SetViewMode((ViewMode)General.Settings.DefaultViewMode);

            // Center map in screen
            if (General.Editing.Mode is ClassicMode)
            {
                (General.Editing.Mode as ClassicMode).CenterInScreen();
            }

            // Success
            this.changed = maprestored;             //mxd
            General.WriteLogLine("Map loading done");
            General.MainWindow.UpdateTitle();       //mxd
            return(true);
        }
Exemplo n.º 4
0
        // Initializes for a new map
        internal bool InitializeNewMap(MapOptions options)
        {
            // Apply settings
            this.filename     = "unnamed.map";
            this.filepathname = string.Empty;
            this.filepath     = string.Empty;
            this.changed      = false;
            this.options      = options;

            General.WriteLogLine("Creating new map with configuration \"" + options.ConfigFile + "\"");

            // Initiate graphics
            General.WriteLogLine("Initializing graphics device...");
            graphics = new D3DDevice(General.MainWindow.Display);
            if (!graphics.Initialize())
            {
                return(false);
            }

            // Create renderers
            renderer2d = new Renderer2D(graphics);
            renderer3d = new Renderer3D(graphics);

            // Load game configuration
            General.WriteLogLine("Loading game configuration...");
            configinfo = General.GetConfigurationInfo(options.ConfigFile);
            config     = new GameConfiguration(General.LoadGameConfiguration(options.ConfigFile));
            configinfo.ApplyDefaults(config);
            General.Editing.UpdateCurrentEditModes();

            // Create map data
            map = new MapSet();

            // Initialize map format interface
            General.WriteLogLine("Initializing map format interface " + config.FormatInterface + "...");
            io = MapSetIO.Create(config.FormatInterface, this);

            // Load data manager
            General.WriteLogLine("Loading data resources...");
            data = new DataManager();
            data.Load(CreateResourcesList());

            // Update structures
            options.ApplyGridSettings();
            map.UpdateConfiguration();
            map.Update();
            thingsfilter.Update();

            // Bind any methods
            General.Actions.BindMethods(this);

            // Set defaults
            this.visualcamera = new VisualCamera();
            General.Editing.ChangeMode(configinfo.StartMode);
            ClassicMode cmode = (General.Editing.Mode as ClassicMode);

            if (cmode != null)
            {
                cmode.SetZoom(Rendering.Renderer2D.DEFAULT_ZOOM);
            }
            renderer2d.SetViewMode((ViewMode)General.Settings.DefaultViewMode);

            // Success
            this.changed = false;
            General.WriteLogLine("Map creation done");
            General.MainWindow.UpdateTitle();             //mxd
            return(true);
        }