Debian Codegraph @

editor/LevelDialog.cpp

raw symbols SCIP
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 // LevelDialog.cpp : implementation file
20 //
21
22 #include "stdafx.h"
23 #include "editor.h"
24 #include "d3edit.h"
25 #include "LevelDialog.h"
26
27 #include "room.h"
28 #include "ambient.h"
29 #include "hlsoundlib.h"
30
31 #ifdef _DEBUG
32 #define new DEBUG_NEW
33 #undef THIS_FILE
34 static char THIS_FILE[] = __FILE__;
35 #endif
36
37 extern const char *EnvAudio_PresetNames[N_ENVAUDIO_PRESETS];
38
39 /////////////////////////////////////////////////////////////////////////////
40 // CLevelDialog dialog
41
42 CLevelDialog::CLevelDialog(CWnd *pParent /*=NULL*/) : CDialog(CLevelDialog::IDD, pParent) {
43 //{{AFX_DATA_INIT(CLevelDialog)
44 // NOTE: the ClassWizard will add member initialization here
45 //}}AFX_DATA_INIT
46 }
47
48 void CLevelDialog::DoDataExchange(CDataExchange *pDX) {
49 CDialog::DoDataExchange(pDX);
50 //{{AFX_DATA_MAP(CLevelDialog)
51 // NOTE: the ClassWizard will add DDX and DDV calls here
52 //}}AFX_DATA_MAP
53 }
54
55 BEGIN_MESSAGE_MAP(CLevelDialog, CDialog)
56 //{{AFX_MSG_MAP(CLevelDialog)
57 //}}AFX_MSG_MAP
58 END_MESSAGE_MAP()
59
60 /////////////////////////////////////////////////////////////////////////////
61 // CLevelDialog message handlers
62
63 #define NULL_NAME "<none>"
64
65 BOOL CLevelDialog::OnInitDialog() {
66 CDialog::OnInitDialog();
67
68 // set up reverb dropdown listbox
69 CComboBox *cbox = (CComboBox *)GetDlgItem(IDC_ENVAUD_LIST);
70 int i;
71
72 cbox->ResetContent();
73 for (i = 0; i < N_ENVAUDIO_PRESETS; i++) {
74 cbox->AddString(EnvAudio_PresetNames[i]);
75 }
76
77 cbox = (CComboBox *)GetDlgItem(IDC_AMBIENT_SOUND);
78 cbox->ResetContent();
79 cbox->AddString(NULL_NAME);
80 for (i = 0; i < Num_ambient_sound_patterns; i++) {
81 if (Ambient_sound_patterns[i].name[0]) {
82 cbox->AddString((LPCTSTR)AmbientSoundPatternName(i));
83 }
84 }
85
86 // select based off of selected rooms.
87 bool single_ambient_sel = true, single_env_sel = true;
88
89 if (N_selected_rooms) {
90 room *rp = &Rooms[Selected_rooms[0]];
91 int amb_sound = rp->ambient_sound;
92 uint8_t env_preset = rp->env_reverb;
93
94 for (i = 1; i < N_selected_rooms; i++) {
95 rp = &Rooms[Selected_rooms[i]];
96 if (rp->ambient_sound != amb_sound) {
97 single_ambient_sel = false;
98 }
99 if (rp->env_reverb != env_preset) {
100 single_env_sel = false;
101 }
102 }
103
104 rp = &Rooms[Selected_rooms[0]];
105
106 cbox = (CComboBox *)GetDlgItem(IDC_AMBIENT_SOUND);
107 if (single_ambient_sel) {
108 cbox->SelectString(-1, (rp->ambient_sound == -1) ? NULL_NAME : AmbientSoundPatternName(rp->ambient_sound));
109 } else {
110 cbox->SetCurSel(-1);
111 }
112
113 cbox = (CComboBox *)GetDlgItem(IDC_ENVAUD_LIST);
114 if (single_env_sel) {
115 cbox->SelectString(-1, EnvAudio_PresetNames[(rp->env_reverb < N_ENVAUDIO_PRESETS) ? rp->env_reverb : 0]);
116 } else {
117 cbox->SetCurSel(-1);
118 }
119 } else {
120 ((CComboBox *)GetDlgItem(IDC_AMBIENT_SOUND))
121 ->SelectString(-1,
122 (Curroomp->ambient_sound == -1) ? NULL_NAME : AmbientSoundPatternName(Curroomp->ambient_sound));
123 ((CComboBox *)GetDlgItem(IDC_ENVAUD_LIST))
124 ->SelectString(-1,
125 EnvAudio_PresetNames[(Curroomp->env_reverb < N_ENVAUDIO_PRESETS) ? Curroomp->env_reverb : 0]);
126 }
127
128 return TRUE; // return TRUE unless you set the focus to a control
129 // EXCEPTION: OCX Property Pages should return FALSE
130 }
131
132 void CLevelDialog::OnOK() {
133 // if there's a current selection for each of the dropdown lists, set each room's properties via
134 // the selected room list.
135 CComboBox *cbox = (CComboBox *)GetDlgItem(IDC_ENVAUD_LIST);
136 CString selection;
137 int i;
138 room *rp;
139
140 if (cbox->GetCurSel() != CB_ERR) {
141 uint8_t env_reverb = 0;
142
143 cbox->GetLBText(cbox->GetCurSel(), selection);
144 for (i = 0; i < N_ENVAUDIO_PRESETS; i++) {
145 if (selection == EnvAudio_PresetNames[i]) {
146 env_reverb = i;
147 break;
148 }
149 }
150 if (i == N_ENVAUDIO_PRESETS) {
151 Int3(); // Samir!
152 }
153
154 if (N_selected_rooms) {
155 for (i = 0; i < N_selected_rooms; i++) {
156 rp = &Rooms[Selected_rooms[i]];
157 rp->env_reverb = env_reverb;
158 }
159 } else {
160 Curroomp->env_reverb = env_reverb;
161 }
162 }
163
164 cbox = (CComboBox *)GetDlgItem(IDC_AMBIENT_SOUND);
165 if (cbox->GetCurSel() != CB_ERR) {
166 int amb_sound = -1;
167
168 cbox->GetLBText(cbox->GetCurSel(), selection);
169 if (selection != NULL_NAME) {
170 for (i = 0; i < Num_ambient_sound_patterns; i++) {
171 if (Ambient_sound_patterns[i].name[0]) {
172 if (selection == AmbientSoundPatternName(i)) {
173 amb_sound = i;
174 break;
175 }
176 }
177 }
178 if (i == Num_ambient_sound_patterns) {
179 Int3(); // Samir!
180 }
181 }
182
183 if (N_selected_rooms) {
184 for (i = 0; i < N_selected_rooms; i++) {
185 rp = &Rooms[Selected_rooms[i]];
186 rp->ambient_sound = amb_sound;
187 }
188 } else {
189 Curroomp->ambient_sound = amb_sound;
190 }
191 }
192
193 Mine_changed = 1;
194
195 CDialog::OnOK();
196 }