File: LevelDialog.cpp

package info (click to toggle)
descent3 1.5.0%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 35,256 kB
  • sloc: cpp: 416,147; ansic: 3,233; sh: 10; makefile: 8
file content (196 lines) | stat: -rw-r--r-- 5,580 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * Descent 3
 * Copyright (C) 2024 Parallax Software
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// LevelDialog.cpp : implementation file
//

#include "stdafx.h"
#include "editor.h"
#include "d3edit.h"
#include "LevelDialog.h"

#include "room.h"
#include "ambient.h"
#include "hlsoundlib.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern const char *EnvAudio_PresetNames[N_ENVAUDIO_PRESETS];

/////////////////////////////////////////////////////////////////////////////
// CLevelDialog dialog

CLevelDialog::CLevelDialog(CWnd *pParent /*=NULL*/) : CDialog(CLevelDialog::IDD, pParent) {
  //{{AFX_DATA_INIT(CLevelDialog)
  // NOTE: the ClassWizard will add member initialization here
  //}}AFX_DATA_INIT
}

void CLevelDialog::DoDataExchange(CDataExchange *pDX) {
  CDialog::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(CLevelDialog)
  // NOTE: the ClassWizard will add DDX and DDV calls here
  //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CLevelDialog, CDialog)
//{{AFX_MSG_MAP(CLevelDialog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLevelDialog message handlers

#define NULL_NAME "<none>"

BOOL CLevelDialog::OnInitDialog() {
  CDialog::OnInitDialog();

  // set up reverb dropdown listbox
  CComboBox *cbox = (CComboBox *)GetDlgItem(IDC_ENVAUD_LIST);
  int i;

  cbox->ResetContent();
  for (i = 0; i < N_ENVAUDIO_PRESETS; i++) {
    cbox->AddString(EnvAudio_PresetNames[i]);
  }

  cbox = (CComboBox *)GetDlgItem(IDC_AMBIENT_SOUND);
  cbox->ResetContent();
  cbox->AddString(NULL_NAME);
  for (i = 0; i < Num_ambient_sound_patterns; i++) {
    if (Ambient_sound_patterns[i].name[0]) {
      cbox->AddString((LPCTSTR)AmbientSoundPatternName(i));
    }
  }

  //	select based off of selected rooms.
  bool single_ambient_sel = true, single_env_sel = true;

  if (N_selected_rooms) {
    room *rp = &Rooms[Selected_rooms[0]];
    int amb_sound = rp->ambient_sound;
    uint8_t env_preset = rp->env_reverb;

    for (i = 1; i < N_selected_rooms; i++) {
      rp = &Rooms[Selected_rooms[i]];
      if (rp->ambient_sound != amb_sound) {
        single_ambient_sel = false;
      }
      if (rp->env_reverb != env_preset) {
        single_env_sel = false;
      }
    }

    rp = &Rooms[Selected_rooms[0]];

    cbox = (CComboBox *)GetDlgItem(IDC_AMBIENT_SOUND);
    if (single_ambient_sel) {
      cbox->SelectString(-1, (rp->ambient_sound == -1) ? NULL_NAME : AmbientSoundPatternName(rp->ambient_sound));
    } else {
      cbox->SetCurSel(-1);
    }

    cbox = (CComboBox *)GetDlgItem(IDC_ENVAUD_LIST);
    if (single_env_sel) {
      cbox->SelectString(-1, EnvAudio_PresetNames[(rp->env_reverb < N_ENVAUDIO_PRESETS) ? rp->env_reverb : 0]);
    } else {
      cbox->SetCurSel(-1);
    }
  } else {
    ((CComboBox *)GetDlgItem(IDC_AMBIENT_SOUND))
        ->SelectString(-1,
                       (Curroomp->ambient_sound == -1) ? NULL_NAME : AmbientSoundPatternName(Curroomp->ambient_sound));
    ((CComboBox *)GetDlgItem(IDC_ENVAUD_LIST))
        ->SelectString(-1,
                       EnvAudio_PresetNames[(Curroomp->env_reverb < N_ENVAUDIO_PRESETS) ? Curroomp->env_reverb : 0]);
  }

  return TRUE; // return TRUE unless you set the focus to a control
               // EXCEPTION: OCX Property Pages should return FALSE
}

void CLevelDialog::OnOK() {
  //	if there's a current selection for each of the dropdown lists, set each room's properties via
  //	the selected room list.
  CComboBox *cbox = (CComboBox *)GetDlgItem(IDC_ENVAUD_LIST);
  CString selection;
  int i;
  room *rp;

  if (cbox->GetCurSel() != CB_ERR) {
    uint8_t env_reverb = 0;

    cbox->GetLBText(cbox->GetCurSel(), selection);
    for (i = 0; i < N_ENVAUDIO_PRESETS; i++) {
      if (selection == EnvAudio_PresetNames[i]) {
        env_reverb = i;
        break;
      }
    }
    if (i == N_ENVAUDIO_PRESETS) {
      Int3(); // Samir!
    }

    if (N_selected_rooms) {
      for (i = 0; i < N_selected_rooms; i++) {
        rp = &Rooms[Selected_rooms[i]];
        rp->env_reverb = env_reverb;
      }
    } else {
      Curroomp->env_reverb = env_reverb;
    }
  }

  cbox = (CComboBox *)GetDlgItem(IDC_AMBIENT_SOUND);
  if (cbox->GetCurSel() != CB_ERR) {
    int amb_sound = -1;

    cbox->GetLBText(cbox->GetCurSel(), selection);
    if (selection != NULL_NAME) {
      for (i = 0; i < Num_ambient_sound_patterns; i++) {
        if (Ambient_sound_patterns[i].name[0]) {
          if (selection == AmbientSoundPatternName(i)) {
            amb_sound = i;
            break;
          }
        }
      }
      if (i == Num_ambient_sound_patterns) {
        Int3(); // Samir!
      }
    }

    if (N_selected_rooms) {
      for (i = 0; i < N_selected_rooms; i++) {
        rp = &Rooms[Selected_rooms[i]];
        rp->ambient_sound = amb_sound;
      }
    } else {
      Curroomp->ambient_sound = amb_sound;
    }
  }

  Mine_changed = 1;

  CDialog::OnOK();
}