Пример #1
0
        /// <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);
            }
        }
Пример #2
0
        /// <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;
            }
        }
        private void Event_ButtonClick(object sender, EventArgs e)
        {
            if (VoiceComboBox.Items.Count == 0)
            {
                return;
            }

            RadioMsgMaker.Speed            = SpeedTrackBar.Value;
            RadioMsgMaker.RadioFXIntensity = RadioFXTrackBar.Value;

            if (sender == PlayButton)
            {
                StopSound();

                byte[] bytes = RadioMsgMaker.GenerateRadioMessageWavBytes(MessageTextbox.Text, GetVoiceNameOnlyFromCombobox());

                WaveStream = new MemoryStream(bytes);
                WaveFile   = new WaveFileReader(WaveStream);

                WavePlayer = new WaveOutEvent();
                WavePlayer.Init(WaveFile);
                WavePlayer.Play();
                return;
            }
            else if ((sender == SaveToWavButton) || (sender == SaveToOggButton))
            {
                using (SaveFileDialog sfd = new SaveFileDialog())
                {
                    string fileName = HQTools.RemoveInvalidFileNameCharacters(MessageTextbox.Text).ToLowerInvariant();
                    fileName = fileName.Replace(" ", "").Replace(".", "").Replace(",", "");
                    if (string.IsNullOrEmpty(fileName))
                    {
                        fileName = "NewRadioMessage";
                    }

                    sfd.InitialDirectory = LastSavePath;
                    if (sender == SaveToOggButton)
                    {
                        sfd.Filter = "Ogg Vorbis files (*.ogg)|*.ogg"; sfd.FileName = $"{fileName}.ogg";
                    }
                    else
                    {
                        sfd.Filter = "PCM Wav files (*.wav)|*.wav"; sfd.FileName = $"{fileName}.wav";
                    }
                    if (sfd.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    byte[] bytes = RadioMsgMaker.GenerateRadioMessageWavBytes(MessageTextbox.Text, GetVoiceNameOnlyFromCombobox());

                    if (sender == SaveToOggButton)
                    {
                        using (TTSWavToOgg wav2oggConverter = new TTSWavToOgg())
                        { bytes = wav2oggConverter.ConvertWaveBytes(bytes); }
                    }

                    File.WriteAllBytes(sfd.FileName, bytes);
                    LastSavePath = Path.GetDirectoryName(sfd.FileName);
                }
                return;
            }
        }