Debian Codegraph @

code/q3_ui/ui_sound.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 //
23 /*
24 =======================================================================
25
26 SOUND OPTIONS MENU
27
28 =======================================================================
29 */
30
31 #include "ui_local.h"
32
33
34 #define ART_FRAMEL "menu/art/frame2_l"
35 #define ART_FRAMER "menu/art/frame1_r"
36 #define ART_BACK0 "menu/art/back_0"
37 #define ART_BACK1 "menu/art/back_1"
38 #define ART_ACCEPT0 "menu/art/accept_0"
39 #define ART_ACCEPT1 "menu/art/accept_1"
40
41 #define ID_GRAPHICS 10
42 #define ID_DISPLAY 11
43 #define ID_SOUND 12
44 #define ID_NETWORK 13
45 #define ID_EFFECTSVOLUME 14
46 #define ID_MUSICVOLUME 15
47 #define ID_QUALITY 16
48 #define ID_SOUNDSYSTEM 17
49 //#define ID_A3D 18
50 #define ID_BACK 19
51 #define ID_APPLY 20
52
53 #define DEFAULT_SDL_SND_SPEED 22050
54
55 static const char *quality_items[] = {
56 "Low", "Medium", "High", NULL
57 };
58
59 #define UISND_SDL 0
60 #define UISND_OPENAL 1
61
62 static const char *soundSystem_items[] = {
63 "SDL", "OpenAL", NULL
64 };
65
66 typedef struct {
67 menuframework_s menu;
68
69 menutext_s banner;
70 menubitmap_s framel;
71 menubitmap_s framer;
72
73 menutext_s graphics;
74 menutext_s display;
75 menutext_s sound;
76 menutext_s network;
77
78 menuslider_s sfxvolume;
79 menuslider_s musicvolume;
80 menulist_s soundSystem;
81 menulist_s quality;
82 // menuradiobutton_s a3d;
83
84 menubitmap_s back;
85 menubitmap_s apply;
86
87 float sfxvolume_original;
88 float musicvolume_original;
89 int soundSystem_original;
90 int quality_original;
91 } soundOptionsInfo_t;
92
93 static soundOptionsInfo_t soundOptionsInfo;
94
95
96 /*
97 =================
98 UI_SoundOptionsMenu_Event
99 =================
100 */
101 static void UI_SoundOptionsMenu_Event( void* ptr, int event ) {
102 if( event != QM_ACTIVATED ) {
103 return;
104 }
105
106 switch( ((menucommon_s*)ptr)->id ) {
107 case ID_GRAPHICS:
108 UI_PopMenu();
109 UI_GraphicsOptionsMenu();
110 break;
111
112 case ID_DISPLAY:
113 UI_PopMenu();
114 UI_DisplayOptionsMenu();
115 break;
116
117 case ID_SOUND:
118 break;
119
120 case ID_NETWORK:
121 UI_PopMenu();
122 UI_NetworkOptionsMenu();
123 break;
124 /*
125 case ID_A3D:
126 if( soundOptionsInfo.a3d.curvalue ) {
127 trap_Cmd_ExecuteText( EXEC_NOW, "s_enable_a3d\n" );
128 }
129 else {
130 trap_Cmd_ExecuteText( EXEC_NOW, "s_disable_a3d\n" );
131 }
132 soundOptionsInfo.a3d.curvalue = (int)trap_Cvar_VariableValue( "s_usingA3D" );
133 break;
134 */
135 case ID_BACK:
136 UI_PopMenu();
137 break;
138
139 case ID_APPLY:
140 trap_Cvar_SetValue( "s_volume", soundOptionsInfo.sfxvolume.curvalue / 10 );
141 soundOptionsInfo.sfxvolume_original = soundOptionsInfo.sfxvolume.curvalue;
142
143 trap_Cvar_SetValue( "s_musicvolume", soundOptionsInfo.musicvolume.curvalue / 10 );
144 soundOptionsInfo.musicvolume_original = soundOptionsInfo.musicvolume.curvalue;
145
146 // Check if something changed that requires the sound system to be restarted.
147 if (soundOptionsInfo.quality_original != soundOptionsInfo.quality.curvalue
148 || soundOptionsInfo.soundSystem_original != soundOptionsInfo.soundSystem.curvalue)
149 {
150 int speed;
151
152 switch ( soundOptionsInfo.quality.curvalue )
153 {
154 default:
155 case 0:
156 speed = 11025;
157 break;
158 case 1:
159 speed = 22050;
160 break;
161 case 2:
162 speed = 44100;
163 break;
164 }
165
166 if (speed == DEFAULT_SDL_SND_SPEED)
167 speed = 0;
168
169 trap_Cvar_SetValue( "s_sdlSpeed", speed );
170 soundOptionsInfo.quality_original = soundOptionsInfo.quality.curvalue;
171
172 trap_Cvar_SetValue( "s_useOpenAL", (soundOptionsInfo.soundSystem.curvalue == UISND_OPENAL) );
173 soundOptionsInfo.soundSystem_original = soundOptionsInfo.soundSystem.curvalue;
174
175 UI_ForceMenuOff();
176 trap_Cmd_ExecuteText( EXEC_APPEND, "snd_restart\n" );
177 }
178 break;
179 }
180 }
181
182 /*
183 =================
184 SoundOptions_UpdateMenuItems
185 =================
186 */
187 static void SoundOptions_UpdateMenuItems( void )
188 {
189 if ( soundOptionsInfo.soundSystem.curvalue == UISND_SDL )
190 {
191 soundOptionsInfo.quality.generic.flags &= ~QMF_GRAYED;
192 }
193 else
194 {
195 soundOptionsInfo.quality.generic.flags |= QMF_GRAYED;
196 }
197
198 soundOptionsInfo.apply.generic.flags |= QMF_HIDDEN|QMF_INACTIVE;
199
200 if ( soundOptionsInfo.sfxvolume_original != soundOptionsInfo.sfxvolume.curvalue )
201 {
202 soundOptionsInfo.apply.generic.flags &= ~(QMF_HIDDEN|QMF_INACTIVE);
203 }
204 if ( soundOptionsInfo.musicvolume_original != soundOptionsInfo.musicvolume.curvalue )
205 {
206 soundOptionsInfo.apply.generic.flags &= ~(QMF_HIDDEN|QMF_INACTIVE);
207 }
208 if ( soundOptionsInfo.soundSystem_original != soundOptionsInfo.soundSystem.curvalue )
209 {
210 soundOptionsInfo.apply.generic.flags &= ~(QMF_HIDDEN|QMF_INACTIVE);
211 }
212 if ( soundOptionsInfo.quality_original != soundOptionsInfo.quality.curvalue )
213 {
214 soundOptionsInfo.apply.generic.flags &= ~(QMF_HIDDEN|QMF_INACTIVE);
215 }
216 }
217
218 /*
219 ================
220 SoundOptions_MenuDraw
221 ================
222 */
223 void SoundOptions_MenuDraw (void)
224 {
225 //APSFIX - rework this
226 SoundOptions_UpdateMenuItems();
227
228 Menu_Draw( &soundOptionsInfo.menu );
229 }
230
231 /*
232 ===============
233 UI_SoundOptionsMenu_Init
234 ===============
235 */
236 static void UI_SoundOptionsMenu_Init( void ) {
237 int y;
238 int speed;
239
240 memset( &soundOptionsInfo, 0, sizeof(soundOptionsInfo) );
241
242 UI_SoundOptionsMenu_Cache();
243 soundOptionsInfo.menu.wrapAround = qtrue;
244 soundOptionsInfo.menu.fullscreen = qtrue;
245 soundOptionsInfo.menu.draw = SoundOptions_MenuDraw;
246
247 soundOptionsInfo.banner.generic.type = MTYPE_BTEXT;
248 soundOptionsInfo.banner.generic.flags = QMF_CENTER_JUSTIFY;
249 soundOptionsInfo.banner.generic.x = 320;
250 soundOptionsInfo.banner.generic.y = 16;
251 soundOptionsInfo.banner.string = "SYSTEM SETUP";
252 soundOptionsInfo.banner.color = color_white;
253 soundOptionsInfo.banner.style = UI_CENTER;
254
255 soundOptionsInfo.framel.generic.type = MTYPE_BITMAP;
256 soundOptionsInfo.framel.generic.name = ART_FRAMEL;
257 soundOptionsInfo.framel.generic.flags = QMF_INACTIVE;
258 soundOptionsInfo.framel.generic.x = 0;
259 soundOptionsInfo.framel.generic.y = 78;
260 soundOptionsInfo.framel.width = 256;
261 soundOptionsInfo.framel.height = 329;
262
263 soundOptionsInfo.framer.generic.type = MTYPE_BITMAP;
264 soundOptionsInfo.framer.generic.name = ART_FRAMER;
265 soundOptionsInfo.framer.generic.flags = QMF_INACTIVE;
266 soundOptionsInfo.framer.generic.x = 376;
267 soundOptionsInfo.framer.generic.y = 76;
268 soundOptionsInfo.framer.width = 256;
269 soundOptionsInfo.framer.height = 334;
270
271 soundOptionsInfo.graphics.generic.type = MTYPE_PTEXT;
272 soundOptionsInfo.graphics.generic.flags = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
273 soundOptionsInfo.graphics.generic.id = ID_GRAPHICS;
274 soundOptionsInfo.graphics.generic.callback = UI_SoundOptionsMenu_Event;
275 soundOptionsInfo.graphics.generic.x = 216;
276 soundOptionsInfo.graphics.generic.y = 240 - 2 * PROP_HEIGHT;
277 soundOptionsInfo.graphics.string = "GRAPHICS";
278 soundOptionsInfo.graphics.style = UI_RIGHT;
279 soundOptionsInfo.graphics.color = color_red;
280
281 soundOptionsInfo.display.generic.type = MTYPE_PTEXT;
282 soundOptionsInfo.display.generic.flags = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
283 soundOptionsInfo.display.generic.id = ID_DISPLAY;
284 soundOptionsInfo.display.generic.callback = UI_SoundOptionsMenu_Event;
285 soundOptionsInfo.display.generic.x = 216;
286 soundOptionsInfo.display.generic.y = 240 - PROP_HEIGHT;
287 soundOptionsInfo.display.string = "DISPLAY";
288 soundOptionsInfo.display.style = UI_RIGHT;
289 soundOptionsInfo.display.color = color_red;
290
291 soundOptionsInfo.sound.generic.type = MTYPE_PTEXT;
292 soundOptionsInfo.sound.generic.flags = QMF_RIGHT_JUSTIFY;
293 soundOptionsInfo.sound.generic.id = ID_SOUND;
294 soundOptionsInfo.sound.generic.callback = UI_SoundOptionsMenu_Event;
295 soundOptionsInfo.sound.generic.x = 216;
296 soundOptionsInfo.sound.generic.y = 240;
297 soundOptionsInfo.sound.string = "SOUND";
298 soundOptionsInfo.sound.style = UI_RIGHT;
299 soundOptionsInfo.sound.color = color_red;
300
301 soundOptionsInfo.network.generic.type = MTYPE_PTEXT;
302 soundOptionsInfo.network.generic.flags = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
303 soundOptionsInfo.network.generic.id = ID_NETWORK;
304 soundOptionsInfo.network.generic.callback = UI_SoundOptionsMenu_Event;
305 soundOptionsInfo.network.generic.x = 216;
306 soundOptionsInfo.network.generic.y = 240 + PROP_HEIGHT;
307 soundOptionsInfo.network.string = "NETWORK";
308 soundOptionsInfo.network.style = UI_RIGHT;
309 soundOptionsInfo.network.color = color_red;
310
311 y = 240 - 2 * (BIGCHAR_HEIGHT + 2);
312 soundOptionsInfo.sfxvolume.generic.type = MTYPE_SLIDER;
313 soundOptionsInfo.sfxvolume.generic.name = "Effects Volume:";
314 soundOptionsInfo.sfxvolume.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
315 soundOptionsInfo.sfxvolume.generic.callback = UI_SoundOptionsMenu_Event;
316 soundOptionsInfo.sfxvolume.generic.id = ID_EFFECTSVOLUME;
317 soundOptionsInfo.sfxvolume.generic.x = 400;
318 soundOptionsInfo.sfxvolume.generic.y = y;
319 soundOptionsInfo.sfxvolume.minvalue = 0;
320 soundOptionsInfo.sfxvolume.maxvalue = 10;
321
322 y += BIGCHAR_HEIGHT+2;
323 soundOptionsInfo.musicvolume.generic.type = MTYPE_SLIDER;
324 soundOptionsInfo.musicvolume.generic.name = "Music Volume:";
325 soundOptionsInfo.musicvolume.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
326 soundOptionsInfo.musicvolume.generic.callback = UI_SoundOptionsMenu_Event;
327 soundOptionsInfo.musicvolume.generic.id = ID_MUSICVOLUME;
328 soundOptionsInfo.musicvolume.generic.x = 400;
329 soundOptionsInfo.musicvolume.generic.y = y;
330 soundOptionsInfo.musicvolume.minvalue = 0;
331 soundOptionsInfo.musicvolume.maxvalue = 10;
332
333 y += BIGCHAR_HEIGHT+2;
334 soundOptionsInfo.soundSystem.generic.type = MTYPE_SPINCONTROL;
335 soundOptionsInfo.soundSystem.generic.name = "Sound System:";
336 soundOptionsInfo.soundSystem.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
337 soundOptionsInfo.soundSystem.generic.callback = UI_SoundOptionsMenu_Event;
338 soundOptionsInfo.soundSystem.generic.id = ID_SOUNDSYSTEM;
339 soundOptionsInfo.soundSystem.generic.x = 400;
340 soundOptionsInfo.soundSystem.generic.y = y;
341 soundOptionsInfo.soundSystem.itemnames = soundSystem_items;
342
343 y += BIGCHAR_HEIGHT+2;
344 soundOptionsInfo.quality.generic.type = MTYPE_SPINCONTROL;
345 soundOptionsInfo.quality.generic.name = "SDL Sound Quality:";
346 soundOptionsInfo.quality.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
347 soundOptionsInfo.quality.generic.callback = UI_SoundOptionsMenu_Event;
348 soundOptionsInfo.quality.generic.id = ID_QUALITY;
349 soundOptionsInfo.quality.generic.x = 400;
350 soundOptionsInfo.quality.generic.y = y;
351 soundOptionsInfo.quality.itemnames = quality_items;
352
353 /*
354 y += BIGCHAR_HEIGHT+2;
355 soundOptionsInfo.a3d.generic.type = MTYPE_RADIOBUTTON;
356 soundOptionsInfo.a3d.generic.name = "A3D:";
357 soundOptionsInfo.a3d.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
358 soundOptionsInfo.a3d.generic.callback = UI_SoundOptionsMenu_Event;
359 soundOptionsInfo.a3d.generic.id = ID_A3D;
360 soundOptionsInfo.a3d.generic.x = 400;
361 soundOptionsInfo.a3d.generic.y = y;
362 */
363 soundOptionsInfo.back.generic.type = MTYPE_BITMAP;
364 soundOptionsInfo.back.generic.name = ART_BACK0;
365 soundOptionsInfo.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
366 soundOptionsInfo.back.generic.callback = UI_SoundOptionsMenu_Event;
367 soundOptionsInfo.back.generic.id = ID_BACK;
368 soundOptionsInfo.back.generic.x = 0;
369 soundOptionsInfo.back.generic.y = 480-64;
370 soundOptionsInfo.back.width = 128;
371 soundOptionsInfo.back.height = 64;
372 soundOptionsInfo.back.focuspic = ART_BACK1;
373
374 soundOptionsInfo.apply.generic.type = MTYPE_BITMAP;
375 soundOptionsInfo.apply.generic.name = ART_ACCEPT0;
376 soundOptionsInfo.apply.generic.flags = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS|QMF_HIDDEN|QMF_INACTIVE;
377 soundOptionsInfo.apply.generic.callback = UI_SoundOptionsMenu_Event;
378 soundOptionsInfo.apply.generic.id = ID_APPLY;
379 soundOptionsInfo.apply.generic.x = 640;
380 soundOptionsInfo.apply.generic.y = 480-64;
381 soundOptionsInfo.apply.width = 128;
382 soundOptionsInfo.apply.height = 64;
383 soundOptionsInfo.apply.focuspic = ART_ACCEPT1;
384
385 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.banner );
386 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.framel );
387 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.framer );
388 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.graphics );
389 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.display );
390 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.sound );
391 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.network );
392 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.sfxvolume );
393 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.musicvolume );
394 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.soundSystem );
395 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.quality );
396 // Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.a3d );
397 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.back );
398 Menu_AddItem( &soundOptionsInfo.menu, ( void * ) &soundOptionsInfo.apply );
399
400 soundOptionsInfo.sfxvolume.curvalue = soundOptionsInfo.sfxvolume_original = trap_Cvar_VariableValue( "s_volume" ) * 10;
401 soundOptionsInfo.musicvolume.curvalue = soundOptionsInfo.musicvolume_original = trap_Cvar_VariableValue( "s_musicvolume" ) * 10;
402
403 if (trap_Cvar_VariableValue( "s_useOpenAL" ))
404 soundOptionsInfo.soundSystem_original = UISND_OPENAL;
405 else
406 soundOptionsInfo.soundSystem_original = UISND_SDL;
407
408 soundOptionsInfo.soundSystem.curvalue = soundOptionsInfo.soundSystem_original;
409
410 speed = trap_Cvar_VariableValue( "s_sdlSpeed" );
411 if (!speed) // Check for default
412 speed = DEFAULT_SDL_SND_SPEED;
413
414 if (speed <= 11025)
415 soundOptionsInfo.quality_original = 0;
416 else if (speed <= 22050)
417 soundOptionsInfo.quality_original = 1;
418 else // 44100
419 soundOptionsInfo.quality_original = 2;
420 soundOptionsInfo.quality.curvalue = soundOptionsInfo.quality_original;
421
422 // soundOptionsInfo.a3d.curvalue = (int)trap_Cvar_VariableValue( "s_usingA3D" );
423 }
424
425
426 /*
427 ===============
428 UI_SoundOptionsMenu_Cache
429 ===============
430 */
431 void UI_SoundOptionsMenu_Cache( void ) {
432 trap_R_RegisterShaderNoMip( ART_FRAMEL );
433 trap_R_RegisterShaderNoMip( ART_FRAMER );
434 trap_R_RegisterShaderNoMip( ART_BACK0 );
435 trap_R_RegisterShaderNoMip( ART_BACK1 );
436 trap_R_RegisterShaderNoMip( ART_ACCEPT0 );
437 trap_R_RegisterShaderNoMip( ART_ACCEPT1 );
438 }
439
440
441 /*
442 ===============
443 UI_SoundOptionsMenu
444 ===============
445 */
446 void UI_SoundOptionsMenu( void ) {
447 UI_SoundOptionsMenu_Init();
448 UI_PushMenu( &soundOptionsInfo.menu );
449 Menu_SetCursorToItem( &soundOptionsInfo.menu, &soundOptionsInfo.sound );
450 }