| 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 | // TerrainSoundDialog.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "stdafx.h" |
| 23 | #include "editor.h" |
| 24 | #include "TerrainSoundDialog.h" |
| 25 | |
| 26 | #ifdef _DEBUG |
| 27 | #define new DEBUG_NEW |
| 28 | #undef THIS_FILE |
| 29 | static char THIS_FILE[] = __FILE__; |
| 30 | #endif |
| 31 | |
| 32 | ///////////////////////////////////////////////////////////////////////////// |
| 33 | // CTerrainSoundDialog dialog |
| 34 | |
| 35 | CTerrainSoundDialog::CTerrainSoundDialog(CWnd *pParent /*=NULL*/) : CDialog(CTerrainSoundDialog::IDD, pParent) { |
| 36 | //{{AFX_DATA_INIT(CTerrainSoundDialog) |
| 37 | m_high_alt = 0; |
| 38 | m_low_alt = 0; |
| 39 | m_high_volume = 0.0f; |
| 40 | m_low_volume = 0.0f; |
| 41 | //}}AFX_DATA_INIT |
| 42 | |
| 43 | for (int b = 0; b < NUM_TERRAIN_SOUND_BANDS; b++) |
| 44 | m_bands[b] = Terrain_sound_bands[b]; |
| 45 | } |
| 46 | |
| 47 | void CTerrainSoundDialog::DoDataExchange(CDataExchange *pDX) { |
| 48 | CDialog::DoDataExchange(pDX); |
| 49 | //{{AFX_DATA_MAP(CTerrainSoundDialog) |
| 50 | DDX_Control(pDX, IDC_TERRAIN_SOUND_COMBO, m_sound_combo); |
| 51 | DDX_Text(pDX, IDC_TERRAIN_SOUND_HIGH_ALT, m_high_alt); |
| 52 | DDV_MinMaxInt(pDX, m_high_alt, 0, 255); |
| 53 | DDX_Text(pDX, IDC_TERRAIN_SOUND_LOW_ALT, m_low_alt); |
| 54 | DDV_MinMaxInt(pDX, m_low_alt, 0, 255); |
| 55 | DDX_Text(pDX, IDC_TERRAIN_SOUND_HIGH_VOLUME, m_high_volume); |
| 56 | DDV_MinMaxFloat(pDX, m_high_volume, 0.f, 1.f); |
| 57 | DDX_Text(pDX, IDC_TERRAIN_SOUND_LOW_VOLUME, m_low_volume); |
| 58 | DDV_MinMaxFloat(pDX, m_low_volume, 0.f, 1.f); |
| 59 | //}}AFX_DATA_MAP |
| 60 | } |
| 61 | |
| 62 | BEGIN_MESSAGE_MAP(CTerrainSoundDialog, CDialog) |
| 63 | //{{AFX_MSG_MAP(CTerrainSoundDialog) |
| 64 | ON_BN_CLICKED(IDC_TERRAIN_SOUND_NEXT, OnTerrainSoundNext) |
| 65 | ON_BN_CLICKED(IDC_TERRAIN_SOUND_PREV, OnTerrainSoundPrev) |
| 66 | ON_CBN_SELCHANGE(IDC_TERRAIN_SOUND_COMBO, OnSelchangeTerrainSoundCombo) |
| 67 | ON_EN_KILLFOCUS(IDC_TERRAIN_SOUND_HIGH_ALT, OnKillfocusTerrainSoundHighAlt) |
| 68 | ON_EN_KILLFOCUS(IDC_TERRAIN_SOUND_HIGH_VOLUME, OnKillfocusTerrainSoundHighVolume) |
| 69 | ON_EN_KILLFOCUS(IDC_TERRAIN_SOUND_LOW_ALT, OnKillfocusTerrainSoundLowAlt) |
| 70 | ON_EN_KILLFOCUS(IDC_TERRAIN_SOUND_LOW_VOLUME, OnKillfocusTerrainSoundLowVolume) |
| 71 | //}}AFX_MSG_MAP |
| 72 | END_MESSAGE_MAP() |
| 73 | |
| 74 | ///////////////////////////////////////////////////////////////////////////// |
| 75 | // CTerrainSoundDialog message handlers |
| 76 | |
| 77 | BOOL CTerrainSoundDialog::OnInitDialog() { |
| 78 | CDialog::OnInitDialog(); |
| 79 | |
| 80 | m_sound_combo.Init(Terrain_sound_bands[0].sound_index); |
| 81 | m_current = 0; |
| 82 | CopyToControls(); |
| 83 | UpdateDialog(); |
| 84 | |
| 85 | return TRUE; // return TRUE unless you set the focus to a control |
| 86 | // EXCEPTION: OCX Property Pages should return FALSE |
| 87 | } |
| 88 | |
| 89 | void CTerrainSoundDialog::EnableDisableAll(int flag) { |
| 90 | ((CButton *)GetDlgItem(IDC_TERRAIN_SOUND_LOW_ALT))->EnableWindow(flag); |
| 91 | ((CButton *)GetDlgItem(IDC_TERRAIN_SOUND_HIGH_ALT))->EnableWindow(flag); |
| 92 | ((CButton *)GetDlgItem(IDC_TERRAIN_SOUND_LOW_VOLUME))->EnableWindow(flag); |
| 93 | ((CButton *)GetDlgItem(IDC_TERRAIN_SOUND_HIGH_VOLUME))->EnableWindow(flag); |
| 94 | } |
| 95 | |
| 96 | void CTerrainSoundDialog::UpdateDialog() { |
| 97 | // Enabled/disable edit boxes |
| 98 | EnableDisableAll(m_bands[m_current].sound_index != -1); |
| 99 | |
| 100 | // Show which band |
| 101 | PrintToDlgItem(this, IDC_TERRAIN_SOUND_BAND_TEXT, "Band %d:", m_current); |
| 102 | |
| 103 | // Enable/disable next & prev |
| 104 | ((CButton *)GetDlgItem(IDC_TERRAIN_SOUND_NEXT))->EnableWindow(m_current < NUM_TERRAIN_SOUND_BANDS - 1); |
| 105 | ((CButton *)GetDlgItem(IDC_TERRAIN_SOUND_PREV))->EnableWindow(m_current > 0); |
| 106 | } |
| 107 | |
| 108 | void CTerrainSoundDialog::CopyToControls() { |
| 109 | m_low_alt = m_bands[m_current].low_alt; |
| 110 | m_high_alt = m_bands[m_current].high_alt; |
| 111 | m_low_volume = m_bands[m_current].low_volume; |
| 112 | m_high_volume = m_bands[m_current].high_volume; |
| 113 | m_sound_combo.SetSelected(m_bands[m_current].sound_index); |
| 114 | |
| 115 | UpdateData(false); |
| 116 | } |
| 117 | |
| 118 | void CTerrainSoundDialog::CopyFromControls() { |
| 119 | UpdateData(true); |
| 120 | |
| 121 | m_bands[m_current].low_alt = m_low_alt; |
| 122 | m_bands[m_current].high_alt = m_high_alt; |
| 123 | m_bands[m_current].low_volume = m_low_volume; |
| 124 | m_bands[m_current].high_volume = m_high_volume; |
| 125 | m_bands[m_current].sound_index = m_sound_combo.GetSelected(); |
| 126 | } |
| 127 | |
| 128 | void CTerrainSoundDialog::OnTerrainSoundNext() { |
| 129 | ASSERT(m_current < NUM_TERRAIN_SOUND_BANDS - 1); |
| 130 | |
| 131 | CopyFromControls(); |
| 132 | |
| 133 | if (m_low_alt > m_high_alt) { |
| 134 | OutrageMessageBox("High elevation must be greater than or equal to low elevation."); |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | m_current++; |
| 139 | |
| 140 | CopyToControls(); |
| 141 | |
| 142 | UpdateDialog(); |
| 143 | } |
| 144 | |
| 145 | void CTerrainSoundDialog::OnTerrainSoundPrev() { |
| 146 | ASSERT(m_current > 0); |
| 147 | |
| 148 | CopyFromControls(); |
| 149 | |
| 150 | if (m_low_alt > m_high_alt) { |
| 151 | OutrageMessageBox("High elevation must be greater than or equal to low elevation."); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | m_current--; |
| 156 | |
| 157 | CopyToControls(); |
| 158 | |
| 159 | UpdateDialog(); |
| 160 | } |
| 161 | |
| 162 | void CTerrainSoundDialog::OnOK() { |
| 163 | // Validate and make sure values ok |
| 164 | if (UpdateData(true)) { |
| 165 | |
| 166 | // Make sure high/low alt values are ok |
| 167 | if (m_low_alt > m_high_alt) { |
| 168 | OutrageMessageBox("High elevation must be greater than or equal to low elevation."); |
| 169 | } else { // everything ok, so bail |
| 170 | |
| 171 | CDialog::OnOK(); |
| 172 | |
| 173 | // Copy the new data into our original struct |
| 174 | for (int b = 0; b < NUM_TERRAIN_SOUND_BANDS; b++) |
| 175 | Terrain_sound_bands[b] = m_bands[b]; |
| 176 | |
| 177 | // It's possible that nothing has changed, but we'll assume something has |
| 178 | World_changed = 1; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | void CTerrainSoundDialog::OnSelchangeTerrainSoundCombo() { |
| 184 | CopyFromControls(); |
| 185 | UpdateDialog(); |
| 186 | } |
| 187 | |
| 188 | void CTerrainSoundDialog::OnKillfocusTerrainSoundHighAlt() { |
| 189 | // Force validation |
| 190 | UpdateData(true); |
| 191 | } |
| 192 | |
| 193 | void CTerrainSoundDialog::OnKillfocusTerrainSoundHighVolume() { |
| 194 | // Force validation |
| 195 | UpdateData(true); |
| 196 | } |
| 197 | |
| 198 | void CTerrainSoundDialog::OnKillfocusTerrainSoundLowAlt() { |
| 199 | // Force validation |
| 200 | UpdateData(true); |
| 201 | } |
| 202 | |
| 203 | void CTerrainSoundDialog::OnKillfocusTerrainSoundLowVolume() { |
| 204 | // Force validation |
| 205 | UpdateData(true); |
| 206 | } |