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(); }
// Configuration item selected private void listconfigs_SelectedIndexChanged(object sender, EventArgs e) { // Item selected? if (listconfigs.SelectedItems.Count > 0) { // Enable panels tabs.Enabled = true; preventchanges = true; //mxd. Store current engine name if (configinfo != null && !String.IsNullOrEmpty(cbEngineSelector.Text)) { configinfo.TestProgramName = cbEngineSelector.Text; } // Get config info of selected item configinfo = listconfigs.SelectedItems[0].Tag as ConfigurationInfo; //mxd. Load the game configuration gameconfig = new GameConfiguration(configinfo.Configuration); // Set defaults configinfo.ApplyDefaults(gameconfig); // Fill resources list configdata.EditResourceLocationList(configinfo.Resources); // Go for all nodebuilder save items nodebuildersave.SelectedIndex = -1; for (int i = 0; i < nodebuildersave.Items.Count; i++) { // Get item NodebuilderInfo ni = nodebuildersave.Items[i] as NodebuilderInfo; // Item matches configuration setting? if (String.CompareOrdinal(ni.Name, configinfo.NodebuilderSave) == 0) { // Select this item nodebuildersave.SelectedIndex = i; break; } } // Go for all nodebuilder test items nodebuildertest.SelectedIndex = -1; for (int i = 0; i < nodebuildertest.Items.Count; i++) { // Get item NodebuilderInfo ni = nodebuildertest.Items[i] as NodebuilderInfo; // Item matches configuration setting? if (String.CompareOrdinal(ni.Name, configinfo.NodebuilderTest) == 0) { // Select this item nodebuildertest.SelectedIndex = i; break; } } // Fill skills list skill.ClearInfo(); skill.AddInfo(gameconfig.Skills.ToArray()); //mxd. Fill engines list cbEngineSelector.Items.Clear(); foreach (EngineInfo info in configinfo.TestEngines) { cbEngineSelector.Items.Add(info.TestProgramName); } cbEngineSelector.SelectedIndex = configinfo.CurrentEngineIndex; btnRemoveEngine.Enabled = configinfo.TestEngines.Count > 1; // Fill texture sets list listtextures.Items.Clear(); foreach (DefinedTextureSet ts in configinfo.TextureSets) { ListViewItem item = listtextures.Items.Add(ts.Name); item.Tag = ts; item.ImageIndex = 0; } listtextures.Sort(); // Go for all the editing modes in the list foreach (ListViewItem lvi in listmodes.Items) { EditModeInfo emi = (lvi.Tag as EditModeInfo); //mxd. Disable item if the mode does not support current map format if (emi.Attributes.SupportedMapFormats != null && Array.IndexOf(emi.Attributes.SupportedMapFormats, gameconfig.FormatInterface) == -1) { lvi.Text = emi.Attributes.DisplayName + " (map format not supported)"; lvi.ForeColor = SystemColors.GrayText; lvi.BackColor = SystemColors.InactiveBorder; lvi.Checked = false; } else { lvi.Text = emi.Attributes.DisplayName; lvi.ForeColor = SystemColors.WindowText; lvi.BackColor = SystemColors.Window; lvi.Checked = (configinfo.EditModes.ContainsKey(emi.Type.FullName) && configinfo.EditModes[emi.Type.FullName]); } } // Update listmodes columns width (mxd) listmodes.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); // Fill start modes RefillStartModes(); // Done preventchanges = false; } }
// Configuration item selected private void listconfigs_SelectedIndexChanged(object sender, EventArgs e) { NodebuilderInfo ni; // Item selected? if (listconfigs.SelectedItems.Count > 0) { // Enable panels tabs.Enabled = true; preventchanges = true; // Get config info of selected item configinfo = listconfigs.SelectedItems[0].Tag as ConfigurationInfo; // Load the game configuration gameconfig = new GameConfiguration(General.LoadGameConfiguration(configinfo.Filename)); // Set defaults configinfo.ApplyDefaults(gameconfig); // Fill resources list configdata.EditResourceLocationList(configinfo.Resources); // Go for all nodebuilder save items nodebuildersave.SelectedIndex = -1; for (int i = 0; i < nodebuildersave.Items.Count; i++) { // Get item ni = nodebuildersave.Items[i] as NodebuilderInfo; // Item matches configuration setting? if (string.Compare(ni.Name, configinfo.NodebuilderSave, false) == 0) { // Select this item nodebuildersave.SelectedIndex = i; break; } } // Go for all nodebuilder test items nodebuildertest.SelectedIndex = -1; for (int i = 0; i < nodebuildertest.Items.Count; i++) { // Get item ni = nodebuildertest.Items[i] as NodebuilderInfo; // Item matches configuration setting? if (string.Compare(ni.Name, configinfo.NodebuilderTest, false) == 0) { // Select this item nodebuildertest.SelectedIndex = i; break; } } // Fill skills list skill.ClearInfo(); skill.AddInfo(gameconfig.Skills.ToArray()); // Set test application and parameters if (!configinfo.CustomParameters) { configinfo.TestParameters = gameconfig.TestParameters; configinfo.TestShortPaths = gameconfig.TestShortPaths; } testapplication.Text = configinfo.TestProgram; testparameters.Text = configinfo.TestParameters; shortpaths.Checked = configinfo.TestShortPaths; int skilllevel = configinfo.TestSkill; skill.Value = skilllevel - 1; skill.Value = skilllevel; customparameters.Checked = configinfo.CustomParameters; // Fill texture sets list listtextures.Items.Clear(); foreach (DefinedTextureSet ts in configinfo.TextureSets) { ListViewItem item = listtextures.Items.Add(ts.Name); item.Tag = ts; item.ImageIndex = 0; } listtextures.Sort(); // Go for all the editing modes in the list foreach (ListViewItem lvi in listmodes.Items) { EditModeInfo emi = (lvi.Tag as EditModeInfo); lvi.Checked = (configinfo.EditModes.ContainsKey(emi.Type.FullName) && configinfo.EditModes[emi.Type.FullName]); } // Fill start modes RefillStartModes(); // Done preventchanges = false; } }
// 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); }
// 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); }
// Configuration item selected private void listconfigs_SelectedIndexChanged(object sender, EventArgs e) { // Item selected? if (listconfigs.SelectedItems.Count > 0) { // Enable panels tabs.Enabled = true; preventchanges = true; // Get config info of selected item configinfo = listconfigs.SelectedItems[0].Tag as ConfigurationInfo; // Load the game configuration gameconfig = new GameConfiguration(General.LoadGameConfiguration(configinfo.Filename)); // Set defaults configinfo.ApplyDefaults(gameconfig); // Fill skills list //skill.ClearInfo(); //skill.AddInfo(gameconfig.Skills.ToArray()); skill.Items.Clear(); skill.Items.AddRange(gameconfig.Skills.ToArray()); // Set test application and parameters if (!configinfo.CustomParameters) { configinfo.TestParameters = gameconfig.TestParameters; } testapplication.Text = configinfo.TestProgram; testparameters.Text = configinfo.TestParameters; int skilllevel = configinfo.TestSkill; //skill.Value = skilllevel - 1; //skill.Value = skilllevel; skill.SelectedIndex = skilllevel; customparameters.Checked = configinfo.CustomParameters; // Fill texture sets list listtextures.Items.Clear(); foreach (DefinedImageSet ts in configinfo.TextureSets) { ListViewItem item = listtextures.Items.Add(ts.Name); item.Tag = ts; item.ImageIndex = 0; } listtextures.Sort(); // Go for all the editing modes in the list foreach (ListViewItem lvi in listmodes.Items) { EditModeInfo emi = (lvi.Tag as EditModeInfo); lvi.Checked = (configinfo.EditModes.ContainsKey(emi.Type.FullName) && configinfo.EditModes[emi.Type.FullName]); } // Fill start modes RefillStartModes(); // Done preventchanges = false; } }