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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
|
/* ScummVM - Scumm Interpreter
* Copyright (C) 2002-2005 The ScummVM project
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*/
#include "stdafx.h"
#include "gui/browser.h"
#include "gui/chooser.h"
#include "gui/newgui.h"
#include "gui/options.h"
#include "gui/PopUpWidget.h"
#include "gui/TabWidget.h"
#include "backends/fs/fs.h"
#include "common/config-manager.h"
#include "common/scaler.h"
#include "common/system.h"
#include "sound/mididrv.h"
#include "sound/mixer.h"
#if (!( defined(__PALM_OS__) || defined(__DC__) || defined(__GP32__)) && !defined(_MSC_VER))
#include <sys/param.h>
#include <unistd.h>
#endif
#if !(defined(MAXPATHLEN))
#ifndef __PALM_OS__
#define MAXPATHLEN 1024
#else
#define MAXPATHLEN 256
#endif
#endif
namespace GUI {
// TODO - allow changing options for:
// - the save path (use _dirBrowser!)
// - music & graphics driver (but see also the comments on EditGameDialog
// for some techincal difficulties with this)
// - default volumes (sfx/speech/music)
// - aspect ratio, language, platform, subtitles, debug mode/level, cd drive, joystick, multi midi, native mt32
enum {
kMusicVolumeChanged = 'muvc',
kSfxVolumeChanged = 'sfvc',
kSpeechVolumeChanged = 'vcvc',
kChooseSoundFontCmd = 'chsf',
kChooseSaveDirCmd = 'chos',
kChooseExtraDirCmd = 'chex'
};
#ifdef _WIN32_WCE
enum {
kChooseKeyMappingCmd = 'chma'
};
#endif
OptionsDialog::OptionsDialog(const String &domain, int x, int y, int w, int h)
: Dialog(x, y, w, h),
_domain(domain),
_enableGraphicSettings(false),
_gfxPopUp(0), _renderModePopUp(0), _fullscreenCheckbox(0), _aspectCheckbox(0),
_enableAudioSettings(false),
_subCheckbox(0),
_enableMIDISettings(false),
_multiMidiCheckbox(0), _mt32Checkbox(0), _enableGSCheckbox(0),
_enableVolumeSettings(false),
_musicVolumeSlider(0), _musicVolumeLabel(0),
_sfxVolumeSlider(0), _sfxVolumeLabel(0),
_speechVolumeSlider(0), _speechVolumeLabel(0) {
}
void OptionsDialog::open() {
Dialog::open();
// Reset result value
setResult(0);
if (_fullscreenCheckbox) {
_gfxPopUp->setSelected(0);
if (ConfMan.hasKey("gfx_mode", _domain)) {
const OSystem::GraphicsMode *gm = g_system->getSupportedGraphicsModes();
String gfxMode = ConfMan.get("gfx_mode", _domain);
int gfxCount = 1;
while (gm->name) {
gfxCount++;
if (scumm_stricmp(gm->name, gfxMode.c_str()) == 0)
_gfxPopUp->setSelected(gfxCount);
gm++;
}
}
_renderModePopUp->setSelected(0);
if (ConfMan.hasKey("render_mode", _domain)) {
const Common::RenderModeDescription *p = Common::g_renderModes;
const Common::RenderMode renderMode = Common::parseRenderMode(ConfMan.get("render_mode", _domain));
int sel = 0;
for (int i = 0; p->code; ++p, ++i) {
if (renderMode == p->id)
sel = i + 2;
}
_renderModePopUp->setSelected(sel);
}
#ifndef _WIN32_WCE
// Fullscreen setting
_fullscreenCheckbox->setState(ConfMan.getBool("fullscreen", _domain));
// Aspect ratio setting
_aspectCheckbox->setState(ConfMan.getBool("aspect_ratio", _domain));
#endif
}
if (_subCheckbox) {
// Music driver
const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers();
int i = 0;
const int midiDriver =
ConfMan.hasKey("music_driver", _domain)
? MidiDriver::parseMusicDriver(ConfMan.get("music_driver", _domain))
: MD_AUTO;
while (md->name && md->id != midiDriver) {
i++;
md++;
}
_midiPopUp->setSelected(md->name ? i : 0);
// Subtitles setting
_subCheckbox->setState(ConfMan.getBool("subtitles", _domain));
}
if (_multiMidiCheckbox) {
// Multi midi setting
_multiMidiCheckbox->setState(ConfMan.getBool("multi_midi", _domain));
// Native mt32 setting
_mt32Checkbox->setState(ConfMan.getBool("native_mt32", _domain));
// GS extensions setting
_enableGSCheckbox->setState(ConfMan.getBool("enable_gs", _domain));
}
if (_musicVolumeSlider) {
int vol;
vol = ConfMan.getInt("music_volume", _domain);
_musicVolumeSlider->setValue(vol);
_musicVolumeLabel->setValue(vol);
vol = ConfMan.getInt("sfx_volume", _domain);
_sfxVolumeSlider->setValue(vol);
_sfxVolumeLabel->setValue(vol);
vol = ConfMan.getInt("speech_volume", _domain);
_speechVolumeSlider->setValue(vol);
_speechVolumeLabel->setValue(vol);
}
}
void OptionsDialog::close() {
if (getResult()) {
if (_fullscreenCheckbox) {
if (_enableGraphicSettings) {
ConfMan.set("fullscreen", _fullscreenCheckbox->getState(), _domain);
ConfMan.set("aspect_ratio", _aspectCheckbox->getState(), _domain);
if ((int32)_gfxPopUp->getSelectedTag() >= 0)
ConfMan.set("gfx_mode", _gfxPopUp->getSelectedString(), _domain);
if ((int32)_renderModePopUp->getSelectedTag() >= 0)
ConfMan.set("render_mode", Common::getRenderModeCode((Common::RenderMode)_renderModePopUp->getSelectedTag()), _domain);
} else {
ConfMan.removeKey("fullscreen", _domain);
ConfMan.removeKey("aspect_ratio", _domain);
ConfMan.removeKey("gfx_mode", _domain);
ConfMan.removeKey("render_mode", _domain);
}
}
if (_musicVolumeSlider) {
if (_enableVolumeSettings) {
ConfMan.set("music_volume", _musicVolumeSlider->getValue(), _domain);
ConfMan.set("sfx_volume", _sfxVolumeSlider->getValue(), _domain);
ConfMan.set("speech_volume", _speechVolumeSlider->getValue(), _domain);
} else {
ConfMan.removeKey("music_volume", _domain);
ConfMan.removeKey("sfx_volume", _domain);
ConfMan.removeKey("speech_volume", _domain);
}
}
if (_subCheckbox) {
if (_enableAudioSettings) {
ConfMan.set("subtitles", _subCheckbox->getState(), _domain);
const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers();
while (md->name && md->id != (int)_midiPopUp->getSelectedTag())
md++;
if (md->name)
ConfMan.set("music_driver", md->name, _domain);
else
ConfMan.removeKey("music_driver", _domain);
} else {
ConfMan.removeKey("music_driver", _domain);
ConfMan.removeKey("subtitles", _domain);
}
}
if (_multiMidiCheckbox) {
if (_enableMIDISettings) {
ConfMan.set("multi_midi", _multiMidiCheckbox->getState(), _domain);
ConfMan.set("native_mt32", _mt32Checkbox->getState(), _domain);
ConfMan.set("enable_gs", _enableGSCheckbox->getState(), _domain);
} else {
ConfMan.removeKey("multi_midi", _domain);
ConfMan.removeKey("native_mt32", _domain);
ConfMan.removeKey("enable_gs", _domain);
}
}
// Save config file
ConfMan.flushToDisk();
}
Dialog::close();
}
void OptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kMusicVolumeChanged:
_musicVolumeLabel->setValue(_musicVolumeSlider->getValue());
_musicVolumeLabel->draw();
break;
case kSfxVolumeChanged:
_sfxVolumeLabel->setValue(_sfxVolumeSlider->getValue());
_sfxVolumeLabel->draw();
break;
case kSpeechVolumeChanged:
_speechVolumeLabel->setValue(_speechVolumeSlider->getValue());
_speechVolumeLabel->draw();
break;
case kOKCmd:
setResult(1);
close();
break;
default:
Dialog::handleCommand(sender, cmd, data);
}
}
void OptionsDialog::setGraphicSettingsState(bool enabled) {
_enableGraphicSettings = enabled;
_gfxPopUp->setEnabled(enabled);
_renderModePopUp->setEnabled(enabled);
#ifndef _WIN32_WCE
_fullscreenCheckbox->setEnabled(enabled);
_aspectCheckbox->setEnabled(enabled);
#endif
}
void OptionsDialog::setAudioSettingsState(bool enabled) {
_enableAudioSettings = enabled;
_midiPopUp->setEnabled(enabled);
_subCheckbox->setEnabled(enabled);
}
void OptionsDialog::setMIDISettingsState(bool enabled) {
_enableMIDISettings = enabled;
_multiMidiCheckbox->setEnabled(enabled);
_mt32Checkbox->setEnabled(enabled);
_enableGSCheckbox->setEnabled(enabled);
}
void OptionsDialog::setVolumeSettingsState(bool enabled) {
_enableVolumeSettings = enabled;
_musicVolumeSlider->setEnabled(enabled);
_musicVolumeLabel->setEnabled(enabled);
_sfxVolumeSlider->setEnabled(enabled);
_sfxVolumeLabel->setEnabled(enabled);
_speechVolumeSlider->setEnabled(enabled);
_speechVolumeLabel->setEnabled(enabled);
}
int OptionsDialog::addGraphicControls(GuiObject *boss, int yoffset) {
const int x = 10;
const int w = _w - 2 * 10;
const OSystem::GraphicsMode *gm = g_system->getSupportedGraphicsModes();
// The GFX mode popup
_gfxPopUp = new PopUpWidget(boss, x-5, yoffset, w+5, kLineHeight, "Graphics mode: ", 100);
yoffset += 16;
_gfxPopUp->appendEntry("<default>");
_gfxPopUp->appendEntry("");
while (gm->name) {
_gfxPopUp->appendEntry(gm->name, gm->id);
gm++;
}
// RenderMode popup
_renderModePopUp = new PopUpWidget(boss, x-5, yoffset, w+5, kLineHeight, "Render mode: ", 100);
yoffset += 16;
_renderModePopUp->appendEntry("<default>", Common::kRenderDefault);
_renderModePopUp->appendEntry("");
const Common::RenderModeDescription *rm = Common::g_renderModes;
for (; rm->code; ++rm) {
_renderModePopUp->appendEntry(rm->description, rm->id);
}
// Fullscreen checkbox
_fullscreenCheckbox = new CheckboxWidget(boss, x, yoffset, w, 16, "Fullscreen mode");
yoffset += 16;
// Aspect ratio checkbox
_aspectCheckbox = new CheckboxWidget(boss, x, yoffset, w, 16, "Aspect ratio correction");
yoffset += 16;
#ifdef _WIN32_WCE
_fullscreenCheckbox->setState(TRUE);
_fullscreenCheckbox->setEnabled(FALSE);
_aspectCheckbox->setEnabled(FALSE);
#endif
_enableGraphicSettings = true;
return yoffset;
}
int OptionsDialog::addAudioControls(GuiObject *boss, int yoffset) {
const int x = 10;
const int w = _w - 20;
// The MIDI mode popup & a label
_midiPopUp = new PopUpWidget(boss, x-5, yoffset, w+5, kLineHeight, "Music driver: ", 100);
yoffset += 18;
// Populate it
const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers();
while (md->name) {
_midiPopUp->appendEntry(md->description, md->id);
md++;
}
// Subtitles on/off
_subCheckbox = new CheckboxWidget(boss, x, yoffset, w, 16, "Display subtitles");
yoffset += 16;
yoffset += 18;
_enableAudioSettings = true;
return yoffset;
}
int OptionsDialog::addMIDIControls(GuiObject *boss, int yoffset) {
const int x = 10;
const int w = _w - 20;
// SoundFont
new ButtonWidget(boss, x, yoffset, kButtonWidth + 14, 16, "SoundFont: ", kChooseSoundFontCmd, 0);
_soundFont = new StaticTextWidget(boss, x + kButtonWidth + 20, yoffset + 3, _w - (x + kButtonWidth + 20) - 10, kLineHeight, "None", kTextAlignLeft);
yoffset += 18;
// Multi midi setting
_multiMidiCheckbox = new CheckboxWidget(boss, x, yoffset, w, 16, "Mixed Adlib/MIDI mode");
yoffset += 16;
// Native mt32 setting
_mt32Checkbox = new CheckboxWidget(boss, x, yoffset, w, 16, "True Roland MT-32 (disable GM emulation)");
yoffset += 16;
// GS Extensions setting
_enableGSCheckbox = new CheckboxWidget(boss, x, yoffset, w, 16, "Enable Roland GS Mode");
yoffset += 16;
_enableMIDISettings = true;
return yoffset;
}
int OptionsDialog::addVolumeControls(GuiObject *boss, int yoffset) {
// Volume controllers
_musicVolumeSlider = new SliderWidget(boss, 5, yoffset, 185, 12, "Music volume: ", 100, kMusicVolumeChanged);
_musicVolumeLabel = new StaticTextWidget(boss, 200, yoffset + 2, 24, kLineHeight, "100%", kTextAlignLeft);
_musicVolumeSlider->setMinValue(0); _musicVolumeSlider->setMaxValue(SoundMixer::kMaxMixerVolume);
_musicVolumeLabel->setFlags(WIDGET_CLEARBG);
yoffset += 16;
_sfxVolumeSlider = new SliderWidget(boss, 5, yoffset, 185, 12, "SFX volume: ", 100, kSfxVolumeChanged);
_sfxVolumeLabel = new StaticTextWidget(boss, 200, yoffset + 2, 24, kLineHeight, "100%", kTextAlignLeft);
_sfxVolumeSlider->setMinValue(0); _sfxVolumeSlider->setMaxValue(SoundMixer::kMaxMixerVolume);
_sfxVolumeLabel->setFlags(WIDGET_CLEARBG);
yoffset += 16;
_speechVolumeSlider = new SliderWidget(boss, 5, yoffset, 185, 12, "Speech volume: ", 100, kSpeechVolumeChanged);
_speechVolumeLabel = new StaticTextWidget(boss, 200, yoffset + 2, 24, kLineHeight, "100%", kTextAlignLeft);
_speechVolumeSlider->setMinValue(0); _speechVolumeSlider->setMaxValue(SoundMixer::kMaxMixerVolume);
_speechVolumeLabel->setFlags(WIDGET_CLEARBG);
yoffset += 16;
_enableVolumeSettings = true;
return yoffset;
}
#pragma mark -
GlobalOptionsDialog::GlobalOptionsDialog()
: OptionsDialog(Common::ConfigManager::kApplicationDomain, 10, 20, 320 - 2 * 10, 200 - 1 * 20) {
const int vBorder = 4;
int yoffset;
// The tab widget
TabWidget *tab = new TabWidget(this, 0, vBorder, _w, _h - 24 - 2 * vBorder);
//
// 1) The graphics tab
//
tab->addTab("Graphics");
yoffset = vBorder;
yoffset = addGraphicControls(tab, yoffset);
//
// 2) The audio tab
//
tab->addTab("Audio");
yoffset = vBorder;
yoffset = addAudioControls(tab, yoffset);
yoffset = addVolumeControls(tab, yoffset);
// TODO: cd drive setting
//
// 3) The MIDI tab
//
tab->addTab("MIDI");
yoffset = vBorder;
yoffset = addMIDIControls(tab, yoffset);
//
// 4) The miscellaneous tab
//
tab->addTab("Paths");
yoffset = vBorder;
#if !( defined(__DC__) || defined(__GP32__) )
// Save game path
new ButtonWidget(tab, 5, yoffset, kButtonWidth + 14, 16, "Save Path: ", kChooseSaveDirCmd, 0);
_savePath = new StaticTextWidget(tab, 5 + kButtonWidth + 20, yoffset + 3, _w - (5 + kButtonWidth + 20) - 10, kLineHeight, "/foo/bar", kTextAlignLeft);
yoffset += 18;
new ButtonWidget(tab, 5, yoffset, kButtonWidth + 14, 16, "Extra Path:", kChooseExtraDirCmd, 0);
_extraPath = new StaticTextWidget(tab, 5 + kButtonWidth + 20, yoffset + 3, _w - (5 + kButtonWidth + 20) - 10, kLineHeight, "None", kTextAlignLeft);
yoffset += 18;
#endif
#ifdef _WIN32_WCE
new ButtonWidget(tab, 5, yoffset, kButtonWidth + 14, 16, "Keys", kChooseKeyMappingCmd, 0);
yoffset += 18;
#endif
// TODO: joystick setting
// Activate the first tab
tab->setActiveTab(0);
// Add OK & Cancel buttons
addButton(_w - 2 * (kButtonWidth + 10), _h - 24, "Cancel", kCloseCmd, 0);
addButton(_w - (kButtonWidth + 10), _h - 24, "OK", kOKCmd, 0);
// Create file browser dialogs
_dirBrowser = new BrowserDialog("Select directory for savegames", true);
_fileBrowser = new BrowserDialog("Select SoundFont", false);
#ifdef _WIN32_WCE
_keysDialog = new CEKeysDialog();
#endif
}
GlobalOptionsDialog::~GlobalOptionsDialog() {
delete _dirBrowser;
delete _fileBrowser;
#ifdef _WIN32_WCE
delete _keysDialog;
#endif
}
void GlobalOptionsDialog::open() {
OptionsDialog::open();
#if !( defined(__DC__) || defined(__GP32__) || defined(__PLAYSTATION2__) )
// Set _savePath to the current save path
Common::String dir(ConfMan.get("savepath", _domain));
Common::String extraPath(ConfMan.get("extrapath", _domain));
Common::String soundFont(ConfMan.get("soundfont", _domain));
if (!dir.isEmpty()) {
_savePath->setLabel(dir);
} else {
// Default to the current directory...
char buf[MAXPATHLEN];
getcwd(buf, sizeof(buf));
_savePath->setLabel(buf);
}
if (extraPath.isEmpty() || !ConfMan.hasKey("extrapath", _domain)) {
_extraPath->setLabel("None");
} else {
_extraPath->setLabel(extraPath);
}
if (soundFont.isEmpty() || !ConfMan.hasKey("soundfont", _domain)) {
_soundFont->setLabel("None");
} else {
_soundFont->setLabel(soundFont);
}
#endif
}
void GlobalOptionsDialog::close() {
if (getResult()) {
// Savepath
ConfMan.set("savepath", _savePath->getLabel(), _domain);
String extraPath = _extraPath->getLabel();
if (!extraPath.isEmpty() && (extraPath != "None"))
ConfMan.set("extrapath", extraPath, _domain);
String soundFont = _soundFont->getLabel();
if (!soundFont.isEmpty() && (soundFont != "None"))
ConfMan.set("soundfont", soundFont, _domain);
}
OptionsDialog::close();
}
void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kChooseSaveDirCmd:
if (_dirBrowser->runModal() > 0) {
// User made his choice...
FilesystemNode dir(_dirBrowser->getResult());
_savePath->setLabel(dir.path());
draw();
// TODO - we should check if the directory is writeable before accepting it
}
break;
case kChooseExtraDirCmd:
if (_dirBrowser->runModal() > 0) {
// User made his choice...
FilesystemNode dir(_dirBrowser->getResult());
_extraPath->setLabel(dir.path());
draw();
}
break;
case kChooseSoundFontCmd:
if (_fileBrowser->runModal() > 0) {
// User made his choice...
FilesystemNode file(_fileBrowser->getResult());
_soundFont->setLabel(file.path());
draw();
}
break;
#ifdef _WIN32_WCE
case kChooseKeyMappingCmd:
_keysDialog->runModal();
break;
#endif
default:
OptionsDialog::handleCommand(sender, cmd, data);
}
}
} // End of namespace GUI
|