| 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 | // DallasSoundDlg.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "stdafx.h" |
| 23 | #include "editor.h" |
| 24 | #include "hlsoundlib.h" |
| 25 | #include "soundload.h" |
| 26 | #include "DallasSoundDlg.h" |
| 27 | |
| 28 | #ifdef _DEBUG |
| 29 | #define new DEBUG_NEW |
| 30 | #undef THIS_FILE |
| 31 | static char THIS_FILE[] = __FILE__; |
| 32 | #endif |
| 33 | |
| 34 | ///////////////////////////////////////////////////////////////////////////// |
| 35 | // CDallasSoundDlg dialog |
| 36 | |
| 37 | CDallasSoundDlg::CDallasSoundDlg(CWnd *pParent /*=NULL*/) : CDialog(CDallasSoundDlg::IDD, pParent) { |
| 38 | //{{AFX_DATA_INIT(CDallasSoundDlg) |
| 39 | // NOTE: the ClassWizard will add member initialization here |
| 40 | //}}AFX_DATA_INIT |
| 41 | |
| 42 | m_SoundName = ""; |
| 43 | m_SoundIndex = -1; |
| 44 | } |
| 45 | |
| 46 | void CDallasSoundDlg::DoDataExchange(CDataExchange *pDX) { |
| 47 | CDialog::DoDataExchange(pDX); |
| 48 | //{{AFX_DATA_MAP(CDallasSoundDlg) |
| 49 | DDX_Control(pDX, IDC_SOUND_LIST, m_SoundList); |
| 50 | //}}AFX_DATA_MAP |
| 51 | } |
| 52 | |
| 53 | BEGIN_MESSAGE_MAP(CDallasSoundDlg, CDialog) |
| 54 | //{{AFX_MSG_MAP(CDallasSoundDlg) |
| 55 | ON_BN_CLICKED(IDC_PLAY_SOUND_BUTTON, OnPlaySoundButton) |
| 56 | ON_BN_CLICKED(IDC_STOP_SOUNDS_BUTTON, OnStopSoundsButton) |
| 57 | ON_LBN_DBLCLK(IDC_SOUND_LIST, OnDblclkSoundList) |
| 58 | //}}AFX_MSG_MAP |
| 59 | END_MESSAGE_MAP() |
| 60 | |
| 61 | ///////////////////////////////////////////////////////////////////////////// |
| 62 | // CDallasSoundDlg message handlers |
| 63 | |
| 64 | BOOL CDallasSoundDlg::OnInitDialog() { |
| 65 | CDialog::OnInitDialog(); |
| 66 | |
| 67 | FillSoundList(); |
| 68 | |
| 69 | if (!m_SoundName.IsEmpty()) |
| 70 | m_SoundList.SelectString(-1, m_SoundName.GetBuffer(0)); |
| 71 | |
| 72 | Sound_system.BeginSoundFrame(FALSE); |
| 73 | |
| 74 | return TRUE; // return TRUE unless you set the focus to a control |
| 75 | // EXCEPTION: OCX Property Pages should return FALSE |
| 76 | } |
| 77 | |
| 78 | void CDallasSoundDlg::OnOK() { |
| 79 | int index = m_SoundList.GetCurSel(); |
| 80 | if (index == LB_ERR) |
| 81 | return; |
| 82 | |
| 83 | m_SoundIndex = m_SoundList.GetItemData(index); |
| 84 | Sound_system.StopAllSounds(); |
| 85 | Sound_system.EndSoundFrame(); |
| 86 | |
| 87 | CDialog::OnOK(); |
| 88 | } |
| 89 | |
| 90 | void CDallasSoundDlg::OnCancel() { |
| 91 | Sound_system.StopAllSounds(); |
| 92 | Sound_system.EndSoundFrame(); |
| 93 | |
| 94 | CDialog::OnCancel(); |
| 95 | } |
| 96 | |
| 97 | void CDallasSoundDlg::OnPlaySoundButton() { |
| 98 | int index; |
| 99 | index = m_SoundList.GetCurSel(); |
| 100 | if (index == LB_ERR) |
| 101 | return; |
| 102 | |
| 103 | CString sound_name; |
| 104 | m_SoundList.GetText(index, sound_name); |
| 105 | |
| 106 | Sound_system.BeginSoundFrame(FALSE); |
| 107 | Sound_system.Play2dSound(FindSoundName(sound_name.GetBuffer(0)), MAX_GAME_VOLUME); |
| 108 | Sound_system.EndSoundFrame(); |
| 109 | } |
| 110 | |
| 111 | void CDallasSoundDlg::OnStopSoundsButton() { Sound_system.StopAllSounds(); } |
| 112 | |
| 113 | void CDallasSoundDlg::FillSoundList(void) { |
| 114 | int i; |
| 115 | |
| 116 | // Fill the menus with sounds |
| 117 | for (i = 0; i < MAX_SOUNDS; i++) { |
| 118 | if ((Sounds[i].used) && (strlen(Sounds[i].name) > 0)) { |
| 119 | int index; |
| 120 | index = m_SoundList.AddString(Sounds[i].name); |
| 121 | if (index != LB_ERR) { |
| 122 | m_SoundList.SetItemData(index, i); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | void CDallasSoundDlg::OnDblclkSoundList() { OnPlaySoundButton(); } |