/// <summary> /// Handles the <see cref="CommandLineSwitch.SaveMaps"/> switch. /// </summary> /// <param name="values">The values passed to the switch at the command line.</param> /// <returns>True if completed without errors; false if there were any errors.</returns> static bool HandleSwitch_SaveMaps(string[] values) { var ret = true; var camera = new Camera2D(GameData.ScreenSize); var dynamicEntityFactory = EditorDynamicEntityFactory.Instance; var contentPath = ContentPaths.Dev; // Get the maps var mapInfos = MapHelper.FindAllMaps(); // For each map, load it then save it foreach (var mapInfo in mapInfos) { // Load EditorMap map; try { map = new EditorMap(mapInfo.ID, camera, GetTimeDummy.Instance); map.Load(contentPath, true, dynamicEntityFactory); } catch (Exception ex) { const string errmsg = "Failed to load map ID `{0}`. Exception: {1}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, mapInfo.ID, ex); } Debug.Fail(string.Format(errmsg, mapInfo.ID, ex)); map = null; ret = false; } // Save try { if (map != null) { MapHelper.SaveMap(map, false); } } catch (Exception ex) { const string errmsg = "Failed to save map `{0}`. Exception: {1}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, mapInfo, ex); } Debug.Fail(string.Format(errmsg, mapInfo, ex)); ret = false; } } return(ret); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Form.Load"/> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (DesignMode) { return; } tssInfo.Text = string.Empty; UpdateCursorPos(Vector2.Zero, Vector2.Zero); Show(); // Set the ToolBarVisibility values. Do it here instead of setting the properties to avoid messing up // the controls order. tbGlobal.ToolBarVisibility = ToolBarVisibility.Global; tbMap.ToolBarVisibility = ToolBarVisibility.Map; // Auto-update GrhDatas SetStatusMessageLoading("Updating GrhData"); GlobalState.Instance.AutoUpdateGrhDatas(); GlobalState.Instance.AutoUpdateMusic(); GlobalState.Instance.AutoUpdateSounds(); SetStatusMessageLoading("Updating cached GrhData sizes"); AutomaticGrhDataSizeUpdater.Instance.UpdateSizes(); // Enable the update timer GlobalState.Instance.IsTickEnabled = true; // Create the child form instances SetStatusMessageLoading("Creating child forms"); _frmGrhTreeView = new GrhTreeViewForm(); _frmGrhTreeView.VisibleChanged += _frmGrhTreeView_VisibleChanged; _frmSelectedMapObjs = new SelectedMapObjectsForm(); _frmSelectedMapObjs.VisibleChanged += _frmSelectedMapObjs_VisibleChanged; _frmNPCChatEditor = new NPCChatEditorForm(); _frmNPCChatEditor.VisibleChanged += _frmNPCChatEditor_VisibleChanged; _frmSkeletonEditor = new SkeletonEditorForm(); _frmSkeletonEditor.VisibleChanged += _frmSkeletonEditor_VisibleChanged; _frmDbEditor = new DbEditorForm(); _frmDbEditor.VisibleChanged += _frmDbEditor_VisibleChanged; _frmMusicEditor = new MusicEditorForm(); _frmMusicEditor.VisibleChanged += _frmMusicEditor_VisibleChanged; _frmBodyEditor = new BodyEditorForm(); _frmBodyEditor.VisibleChanged += _frmBodyEditor_VisibleChanged; _frmSoundEditor = new SoundEditorForm(); _frmSoundEditor.VisibleChanged += _frmSoundEditor_VisibleChanged; _frmGrhTilesetForm = new GrhTilesetForm(); _frmGrhTilesetForm.VisibleChanged += new EventHandler(_frmGrhTilesetForm_VisibleChanged); // Set up some other stuff var mapPropertiesTool = ToolManager.Instance.TryGetTool <MapPropertiesTool>(); if (mapPropertiesTool != null) { mapPropertiesTool.DockPanel = dockPanel; } else { const string errmsg = "Unable to set DockPanel on MapPropertiesTool - couldn't find tool instance."; Debug.Fail(errmsg); } // Load the settings SetStatusMessageLoading("Loading user settings"); LoadDockSettings("User"); // Set up map state control listeners & display initial values SetStatusMessageLoading("Hooking up map events"); GlobalState.Instance.Map.LayerDepthChanged -= Map_LayerDepthChanged; GlobalState.Instance.Map.LayerDepthChanged += Map_LayerDepthChanged; GlobalState.Instance.Map.LayerChanged -= Map_LayerChanged; GlobalState.Instance.Map.LayerChanged += Map_LayerChanged; Map_LayerChanged(GlobalState.Instance, EventArgs.Empty); Map_LayerDepthChanged(GlobalState.Instance, EventArgs.Empty); // Clean up bad maps SetStatusMessageLoading("Validating map ids"); MapHelper.DeleteMissingMapIds(); // Load the initial map SetStatusMessageLoading("Loading the initial map"); var validMaps = MapHelper.FindAllMaps().ToArray(); if (validMaps.Length > 0) { MapID initialMapId = (MapID)EditorSettings.Default.InitialMapId; IMapTable initialMap = validMaps.FirstOrDefault(x => x.ID == initialMapId); if (initialMap == null) { initialMap = validMaps.MinElement(x => x.ID); } CreateEditMapForm(initialMap); } // Global not currently used... tbGlobal.Visible = false; // Bind help SetStatusMessageLoading("Setting up F1 help"); var helpManager = EditorHelpManager.Instance; helpManager.StatusLabel = tssInfo; helpManager.Add(cmbLayer, "Map Layers", "Map layers"); helpManager.Add(trackBarDepth, "Layer Depth", "Layer depth"); SetStatusMessage(string.Empty); }