-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabSpeech.cpp
223 lines (172 loc) · 5.59 KB
/
TabSpeech.cpp
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// TabSpeech.cpp : implementation file
//
#include "stdafx.h"
#ifdef FS2_SPEECH
#include <sapi.h>
#include <sphelper.h>
#include <spuihelp.h>
#endif
#include "launcher.h"
#include "TabSpeech.h"
#include "win32func.h"
#include "speech.h"
#include "launcher_settings.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTabSpeech dialog
CTabSpeech::CTabSpeech(CWnd* pParent /*=NULL*/)
: CDialog(CTabSpeech::IDD, pParent)
{
//{{AFX_DATA_INIT(CTabSpeech)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CTabSpeech::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTabSpeech)
DDX_Control(pDX, IDC_VOLUME_SLIDER, m_volume_control);
DDX_Control(pDX, IDC_SPEECH_TECHROOM, m_checkbox_techroom);
DDX_Control(pDX, IDC_SPEECH_INGAME, m_checkbox_ingame);
DDX_Control(pDX, IDC_SPEECH_BRIEFINGS, m_checkbox_briefings);
DDX_Control(pDX, IDC_EDIT, m_edit_box);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTabSpeech, CDialog)
//{{AFX_MSG_MAP(CTabSpeech)
ON_BN_CLICKED(IDC_PLAY, OnPlay)
ON_WM_HSCROLL()
ON_CBN_SELCHANGE(IDC_VOICE_COMBO, OnSelchangeVoiceCombo)
ON_BN_CLICKED(IDC_GET_VOICES, OnGetVoices)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTabSpeech message handlers
BOOL CTabSpeech::OnInitDialog()
{
CDialog::OnInitDialog();
m_speech_supported = speech_init();
if(m_speech_supported == false)
{
EnableWindow(FALSE);
m_edit_box.SetWindowText("Speech API 5.1 not installed");
m_checkbox_techroom.SetCheck(0);
m_checkbox_briefings.SetCheck(0);
m_checkbox_ingame.SetCheck(0);
} else {
m_edit_box.SetWindowText("Press play to test this string.");
#if FS2_SPEECH
// Offer the user a choice of voices
SpInitTokenComboBox( GetDlgItem(IDC_VOICE_COMBO )->GetSafeHwnd(), SPCAT_VOICES );
#endif
}
// Setup the volume
m_volume_control.SetRange(0, 100);
m_volume_control.SetPos(100);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CTabSpeech::OnApply()
{
if(m_speech_supported == false) return;
// Set the basic use of speech
const int CHECKED = 1;
DWORD use;
use = (m_checkbox_techroom.GetCheck() == CHECKED);
reg_set_dword(LauncherSettings::get_reg_path(), "SpeechTechRoom", use);
use = (m_checkbox_briefings.GetCheck() == CHECKED);
reg_set_dword(LauncherSettings::get_reg_path(), "SpeechBriefings", use);
use = (m_checkbox_ingame.GetCheck() == CHECKED);
reg_set_dword(LauncherSettings::get_reg_path(), "SpeechIngame", use);
reg_set_dword(LauncherSettings::get_reg_path(), "SpeechVolume", m_speech_volume);
// Get the selected voice num in the combo box
int selected = ((CComboBox *) GetDlgItem(IDC_VOICE_COMBO))->GetCurSel();
if(selected == CB_ERR) selected = -1;
// Set the voice name as number (sorry, you wouldnt believe how complicated text would be!)
reg_set_dword(LauncherSettings::get_reg_path(), "SpeechVoice", selected);
}
void CTabSpeech::LoadSettings()
{
if(m_speech_supported == false) return;
const int CHECKED = 1;
// Set the basic use of speech parameters
m_checkbox_techroom.SetCheck(CHECKED);
m_checkbox_briefings.SetCheck(CHECKED);
m_checkbox_ingame.SetCheck(CHECKED);
DWORD use;
if(reg_get_dword(LauncherSettings::get_reg_path(), "SpeechTechRoom", &use) && use == 0) {
m_checkbox_techroom.SetCheck(0);
}
if(reg_get_dword(LauncherSettings::get_reg_path(), "SpeechBriefings", &use) && use == 0) {
m_checkbox_briefings.SetCheck(0);
}
if(reg_get_dword(LauncherSettings::get_reg_path(), "SpeechIngame", &use) && use == 0) {
m_checkbox_ingame.SetCheck(0);
}
if(reg_get_dword(LauncherSettings::get_reg_path(), "SpeechVolume", &m_speech_volume) == false) {
m_speech_volume = 100;
}
m_volume_control.SetPos(m_speech_volume);
speech_set_volume(m_speech_volume);
// Get the voice name as number
DWORD selected;
reg_get_dword(LauncherSettings::get_reg_path(), "SpeechVoice", &selected);
if(selected == -1) return;
((CComboBox *) GetDlgItem(IDC_VOICE_COMBO))->SetCurSel(selected);
}
void CTabSpeech::OnPlay()
{
// Make sure we are using the right voice
UpdateVoiceFromCombo();
const int MAX_CHARS = 1024;
char text_to_play[MAX_CHARS];
m_edit_box.GetWindowText(text_to_play, MAX_CHARS);
speech_play(text_to_play);
}
// Free everything here
BOOL CTabSpeech::DestroyWindow()
{
if(m_speech_supported)
{
#ifdef FS2_SPEECH
SpDestroyTokenComboBox( GetDlgItem(IDC_VOICE_COMBO )->GetSafeHwnd() );
#endif
speech_deinit();
}
return CDialog::DestroyWindow();
}
// User has changed volume control
void CTabSpeech::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if(pScrollBar)
{
m_speech_volume = m_volume_control.GetPos();
speech_set_volume(m_speech_volume);
}
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
// User has selected new voice from combo box
void CTabSpeech::OnSelchangeVoiceCombo()
{
UpdateVoiceFromCombo();
OnPlay();
}
void CTabSpeech::UpdateVoiceFromCombo()
{
#if FS2_SPEECH
ISpObjectToken* pToken = SpGetCurSelComboBoxToken( GetDlgItem(IDC_VOICE_COMBO )->GetSafeHwnd() );
if( pToken )
{
speech_set_voice(pToken);
}
#endif
}
void CTabSpeech::OnGetVoices()
{
MessageBox("The fs2_open project is not responsible for the content of this site or the functionality of the installer on it", "Warning", MB_ICONWARNING);
open_web_page("http://www.microsoft.com/downloads/details.aspx?FamilyId=5E86EC97-40A7-453F-B0EE-6583171B4530&displaylang=en");
}