| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | // BriefSoundEdit.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "stdafx.h" |
| 23 | #include "editor.h" |
| 24 | #include "BriefSoundEdit.h" |
| 25 | #include "BriefMissionFlagsDlg.h" |
| 26 | |
| 27 | #ifdef _DEBUG |
| 28 | #define new DEBUG_NEW |
| 29 | #undef THIS_FILE |
| 30 | static char THIS_FILE[] = __FILE__; |
| 31 | #endif |
| 32 | |
| 33 | ///////////////////////////////////////////////////////////////////////////// |
| 34 | // CBriefSoundEdit dialog |
| 35 | |
| 36 | CBriefSoundEdit::CBriefSoundEdit(TCSNDDESC *d, CWnd *pParent /*=NULL*/) : CDialog(CBriefSoundEdit::IDD, pParent) { |
| 37 | //{{AFX_DATA_INIT(CBriefSoundEdit) |
| 38 | m_sFilename = _T(""); |
| 39 | m_bPlayOnce = FALSE; |
| 40 | m_fStartTime = 0.0f; |
| 41 | m_sDesc = _T(""); |
| 42 | //}}AFX_DATA_INIT |
| 43 | |
| 44 | memset(&desc, 0, sizeof(TCSNDDESC)); |
| 45 | |
| 46 | // Set defaults |
| 47 | desc.waittime = 0; |
| 48 | desc.once = false; |
| 49 | desc.mission_mask_set = 0; |
| 50 | desc.mission_mask_unset = 0; |
| 51 | |
| 52 | if (d) { |
| 53 | // fill in values |
| 54 | strcpy(desc.filename, d->filename); |
| 55 | if (d->caps & TCSD_WAITTIME) |
| 56 | desc.waittime = d->waittime; |
| 57 | if (d->caps & TCSD_ONCE) |
| 58 | desc.once = d->once; |
| 59 | |
| 60 | desc.caps = d->caps; |
| 61 | desc.type = d->type; |
| 62 | desc.mission_mask_set = d->mission_mask_set; |
| 63 | desc.mission_mask_unset = d->mission_mask_unset; |
| 64 | } |
| 65 | |
| 66 | // Setup Window dialog |
| 67 | m_sFilename = desc.filename; |
| 68 | m_bPlayOnce = desc.once; |
| 69 | m_fStartTime = desc.waittime; |
| 70 | } |
| 71 | |
| 72 | void CBriefSoundEdit::DoDataExchange(CDataExchange *pDX) { |
| 73 | CDialog::DoDataExchange(pDX); |
| 74 | //{{AFX_DATA_MAP(CBriefSoundEdit) |
| 75 | DDX_Text(pDX, IDC_BRIEF_S_FILENAME, m_sFilename); |
| 76 | DDX_Check(pDX, IDC_BRIEF_S_PLAYONCE, m_bPlayOnce); |
| 77 | DDX_Text(pDX, IDC_BRIEF_S_STARTTIME, m_fStartTime); |
| 78 | DDV_MinMaxFloat(pDX, m_fStartTime, 0.f, 99999.f); |
| 79 | DDX_Text(pDX, IDC_BRIEF_S_DESC, m_sDesc); |
| 80 | //}}AFX_DATA_MAP |
| 81 | } |
| 82 | |
| 83 | BEGIN_MESSAGE_MAP(CBriefSoundEdit, CDialog) |
| 84 | //{{AFX_MSG_MAP(CBriefSoundEdit) |
| 85 | ON_BN_CLICKED(IDC_BRIEF_S_CHOOSE, OnBriefSChoose) |
| 86 | ON_BN_CLICKED(IDC_MISSIONFLAGS, OnMissionflags) |
| 87 | //}}AFX_MSG_MAP |
| 88 | END_MESSAGE_MAP() |
| 89 | |
| 90 | ///////////////////////////////////////////////////////////////////////////// |
| 91 | // CBriefSoundEdit message handlers |
| 92 | |
| 93 | void CBriefSoundEdit::OnBriefSChoose() { |
| 94 | UpdateData(true); |
| 95 | char szFilter[] = "WAV File (*.wav)|*.wav||"; |
| 96 | CFileDialog dlg(true, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, szFilter); |
| 97 | |
| 98 | if (dlg.DoModal() == IDOK) { |
| 99 | // handle |
| 100 | m_sFilename = dlg.GetFileName(); |
| 101 | UpdateData(false); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | void CBriefSoundEdit::OnOK() { |
| 106 | if (!cfexist(m_sFilename.GetBuffer(1))) { |
| 107 | MessageBox("Invalid Filename, Please Enter A Valid Filename", "Error"); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | UpdateData(true); |
| 112 | |
| 113 | desc.caps = TCSD_WAITTIME | TCSD_ONCE; |
| 114 | strcpy(desc.filename, m_sFilename.GetBuffer(0)); |
| 115 | desc.once = (bool)(m_bPlayOnce != 0); |
| 116 | desc.waittime = m_fStartTime; |
| 117 | |
| 118 | CDialog::OnOK(); |
| 119 | } |
| 120 | |
| 121 | BOOL CBriefSoundEdit::OnInitDialog() { |
| 122 | CDialog::OnInitDialog(); |
| 123 | |
| 124 | UpdateData(false); |
| 125 | |
| 126 | return TRUE; |
| 127 | } |
| 128 | |
| 129 | void CBriefSoundEdit::OnMissionflags() { |
| 130 | CBriefMissionFlagsDlg dlg(desc.mission_mask_set, desc.mission_mask_unset); |
| 131 | |
| 132 | if (dlg.DoModal()) { |
| 133 | desc.mission_mask_set = dlg.m_Set; |
| 134 | desc.mission_mask_unset = dlg.m_UnSet; |
| 135 | } |
| 136 | } |