/// <summary> /// Exports the mission briefing to an HTML or image file. /// </summary> /// <param name="fileFormat">The file format to export to.</param> private void ExportBriefing(BriefingExportFileFormat fileFormat) { if (Mission == null) { return; // No mission has been generated, nothing to export. } string defaultFileName = HQTools.RemoveInvalidFileNameCharacters(Mission.BriefingName ?? ""); if (string.IsNullOrEmpty(defaultFileName)) { defaultFileName = "NewMission"; } string briefingFilePath = GUITools.ShowSaveFileDialog( fileFormat.ToString().ToLowerInvariant(), HQTools.GetDCSMissionPath(), defaultFileName, $"{fileFormat.ToString().ToUpperInvariant()} files"); if (briefingFilePath == null) { return; } bool result; using (HTMLExporter briefingExporter = new HTMLExporter()) { switch (fileFormat) { default: return; case BriefingExportFileFormat.Html: result = briefingExporter.ExportToHTML(briefingFilePath, Mission.BriefingHTML); break; case BriefingExportFileFormat.Jpg: result = briefingExporter.ExportToJPEG(briefingFilePath, Mission.BriefingHTML); break; case BriefingExportFileFormat.Png: result = briefingExporter.ExportToPNG(briefingFilePath, Mission.BriefingHTML); break; } } if (!result) { MessageBox.Show("Failed to export briefing", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Event raised when any menu or toolbar item is clicked, apart from the "new mission" theater subitems. /// (These are handled by Event_MenuFileNewDropDownItemClicked) /// </summary> /// <param name="sender">Sender control.</param> /// <param name="e">Event arguments.</param> private void Event_MenuClick(object sender, EventArgs e) { string senderName = ((ToolStripItem)sender).Name; switch (senderName) { case "MenuFileNew": case "ToolStripButtonFileNew": Template.Clear(); return; case "MenuFileOpen": case "ToolStripButtonFileOpen": string fileToLoad = GUITools.ShowOpenFileDialog("hqt", HQTools.PATH_TEMPLATES, "HQ4DCS mission templates"); if (fileToLoad == null) { return; } Template.LoadFromFile(fileToLoad); LastSaveFilePath = fileToLoad; UpdateFormTitle(); return; case "MenuFileSave": case "ToolStripButtonFileSave": if (string.IsNullOrEmpty(LastSaveFilePath)) { Event_MenuClick(MenuFileSaveAs, e); return; } Template.SaveToFile(LastSaveFilePath); return; case "MenuFileSaveAs": case "ToolStripButtonFileSaveAs": string fileToSave = GUITools.ShowSaveFileDialog( "hqt", HQTools.PATH_TEMPLATES, string.IsNullOrEmpty(LastSaveFilePath) ? "NewMission.hqt" : Path.GetFileName(LastSaveFilePath), "HQ4DCS mission templates"); if (fileToSave == null) { return; } Template.SaveToFile(fileToSave); LastSaveFilePath = fileToSave; UpdateFormTitle(); return; case "MenuFileExit": Close(); return; case "MenuMissionGenerate": case "ToolStripButtonMissionGenerate": GenerateMission(); return; case "MenuToolsRadioMessageGenerator": ShowDevToolWarningMessage(); using (FormRadioMessageGenerator rmgForm = new FormRadioMessageGenerator()) { rmgForm.ShowDialog(); } return; case "MenuMissionExportMIZ": case "ToolStripButtonMissionExportMIZ": if (Mission == null) { return; } string defaultFileName = HQTools.RemoveInvalidFileNameCharacters(Mission.BriefingName ?? ""); if (string.IsNullOrEmpty(defaultFileName)) { defaultFileName = "New mission"; } #if DEBUG using (MizExporter mizExporter = new MizExporter()) { if (mizExporter.CreateMizFile(Mission, $"{HQTools.PATH_DEBUG}DebugMission.miz")) { MessageBox.Show($"Mission exported to (DebugOutput)\\DebugMission.miz", "Debug export", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show($"Failed to export mission to (DebugOutput)\\DebugMission.miz", "Debug export", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } #else string mizFilePath = GUITools.ShowSaveFileDialog( "miz", HQTools.GetDCSMissionPath(), defaultFileName, "DCS World mission files"); if (!string.IsNullOrEmpty(mizFilePath)) { using (MizExporter mizExporter = new MizExporter()) { mizExporter.CreateMizFile(Mission, mizFilePath); } } #endif return; case "MenuMissionExportBriefingHTML": case "ToolStripButtonMissionExportBriefingHTML": ExportBriefing(BriefingExportFileFormat.Html); return; case "MenuMissionExportBriefingJPG": case "ToolStripButtonMissionExportBriefingJPG": ExportBriefing(BriefingExportFileFormat.Jpg); return; case "MenuMissionExportBriefingPNG": case "ToolStripButtonMissionExportBriefingPNG": ExportBriefing(BriefingExportFileFormat.Png); return; } }