This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
forked from markol/machines
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ctxoptns.cpp
864 lines (729 loc) · 32.2 KB
/
ctxoptns.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
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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
/*
* C T X O P T N S . C P P
* (c) Charybdis Limited, 1998. All Rights Reserved
*/
// Definitions of non-inline non-template methods and global functions
#include "machgui/ctxoptns.hpp"
#include "stdlib/string.hpp"
#include "ctl/list.hpp"
#include "system/pathname.hpp"
#include "system/registry.hpp"
#include "system/memcaps.hpp"
#include "sound/soundmix.hpp"
#include "device/cd.hpp"
#include "world4d/soundman.hpp"
#include "world4d/manager.hpp"
#include "world4d/scenemgr.hpp"
#include "render/device.hpp"
#include "render/display.hpp"
#include "render/capable.hpp"
#include "render/drivsel.hpp"
#include "gui/restring.hpp"
#include "gui/font.hpp"
#include "gui/image.hpp"
#include "machgui/ddrawdrop.hpp"
#include "machphys/compmgr.hpp"
#include "machphys/compitem.hpp"
#include "machgui/menubutn.hpp"
#include "machgui/menutext.hpp"
#include "machgui/msgbox.hpp"
#include "machgui/startup.hpp"
#include "machgui/strtdata.hpp"
#include "machgui/slidebar.hpp"
#include "machgui/optlayout.hpp"
#include "machgui/dropdwnc.hpp"
#include "machgui/chckbox.hpp"
#include "machgui/internal/mgsndman.hpp"
#include "machgui/internal/strings.hpp"
#include "machlog/races.hpp"
#include "machlog/actor.hpp"
#define OPTIONS_AREA_MINX 95
#define OPTIONS_AREA_MINY 50
#define OPTIMISATIONS_AREA_MINX OPTIONS_AREA_MINX
#define OPTIMISATIONS_AREA_MINY 239
const char c_ScaleFactorOptionKey[] = "Options\\Scale Factor";
const char c_GrabCursorOptionKey[] = "Options\\Grab Cursor";
class MachGuiCtxOptions;
class MachGuiDDrawDropDownCallback : public MachGuiDropDownCallback
{
public:
MachGuiDDrawDropDownCallback(MachGuiCtxOptions& optionsScreen)
: optionsScreen_(optionsScreen)
{
}
void callBack() override { optionsScreen_.showDirect3DDrivers(); }
private:
MachGuiCtxOptions& optionsScreen_;
};
class MachGuiOptionsExitMessageBoxResponder : public MachGuiMessageBoxResponder
{
public:
MachGuiOptionsExitMessageBoxResponder(MachGuiCtxOptions* pOptionsCtx)
: pOptionsCtx_(pOptionsCtx)
{
}
bool okPressed() override
{
pOptionsCtx_->exitFromOptions();
return true;
}
private:
MachGuiCtxOptions* pOptionsCtx_;
};
MachGuiCtxOptions::MachGuiCtxOptions(MachGuiStartupScreens* pStartupScreens)
: MachGuiStartupScreenContext(pStartupScreens)
, animations_(pStartupScreens, SysPathName("gui/menu/sf_anims.anm"))
{
// Bitmap background
changeBackdrop("gui/menu/sf.bmp");
pStartupScreens->cursorOn(true);
pStartupScreens->desiredCdTrack(MachGuiStartupScreens::MENU_MUSIC);
// Get the display, required for things like gamma correction, display drivers etc
RenDisplay* pDisplay_ = W4dManager::instance().sceneManager()->pDevice()->display();
// Load the layout information
MachGuiOptionsLayout screenLayout(SysPathName("gui/layout/options.dat"));
// Create buttons
MachGuiMenuButton* pOkBtn = new MachGuiMenuButton(
pStartupScreens,
pStartupScreens,
Gui::Box(85, 377, 291, 423),
IDS_MENUBTN_OK,
MachGuiStartupScreens::BE_DUMMY_OK);
MachGuiMenuButton* pCancelBtn = new MachGuiMenuButton(
pStartupScreens,
pStartupScreens,
Gui::Box(337, 377, 543, 423),
IDS_MENUBTN_CANCEL,
MachGuiStartupScreens::BE_DUMMY_EXIT);
pCancelBtn->escapeControl(true);
pOkBtn->defaultControl(true);
// Display large headings
GuiBmpFont font = GuiBmpFont::getFont(SysPathName("gui/menu/largefnt.bmp"));
GuiBmpFont smallFont = GuiBmpFont::getFont(SysPathName("gui/menu/smallfnt.bmp"));
GuiResourceString optionsHeading(IDS_MENULB_OPTIONS);
new MachGuiMenuText(
pStartupScreens,
Gui::Box(
Gui::Coord(OPTIONS_AREA_MINX, OPTIONS_AREA_MINY),
font.textWidth(optionsHeading.asString()),
font.charHeight() + 2),
IDS_MENULB_OPTIONS,
"gui/menu/largefnt.bmp");
GuiResourceString optimisationsHeading(IDS_MENULB_OPTIMISATIONS);
new MachGuiMenuText(
pStartupScreens,
Gui::Box(
Gui::Coord(OPTIMISATIONS_AREA_MINX, OPTIMISATIONS_AREA_MINY),
font.textWidth(optimisationsHeading.asString()),
font.charHeight() + 2),
IDS_MENULB_OPTIMISATIONS,
"gui/menu/largefnt.bmp");
// Initialise gui items
const MachGuiOptionsLayout::SlidebarInfo& musicVolSl = screenLayout.slidebarInfo(0);
const MachGuiOptionsLayout::SlidebarInfo& soundVolSl = screenLayout.slidebarInfo(1);
const MachGuiOptionsLayout::SlidebarInfo& gammaCorrectionSl = screenLayout.slidebarInfo(2);
const MachGuiOptionsLayout::MenuTextInfo& musicVolTxt = screenLayout.menuTextInfo(0);
const MachGuiOptionsLayout::MenuTextInfo& soundVolTxt = screenLayout.menuTextInfo(1);
const MachGuiOptionsLayout::MenuTextInfo& gammaCorrectionTxt = screenLayout.menuTextInfo(2);
const MachGuiOptionsLayout::MenuTextInfo& screenSizeTxt = screenLayout.menuTextInfo(3);
const MachGuiOptionsLayout::MenuTextInfo& directDrawTxt = screenLayout.menuTextInfo(4);
const MachGuiOptionsLayout::MenuTextInfo& direct3DTxt = screenLayout.menuTextInfo(5);
const MachGuiOptionsLayout::MenuTextInfo& scaleFactorTxt = screenLayout.menuTextInfo(5);
const MachGuiOptionsLayout::CheckBoxInfo& sound3dCB = screenLayout.checkBoxInfo(0);
const MachGuiOptionsLayout::CheckBoxInfo& transitionsCB = screenLayout.checkBoxInfo(1);
const MachGuiOptionsLayout::CheckBoxInfo& screenResolutionLock = screenLayout.checkBoxInfo(2);
const MachGuiOptionsLayout::CheckBoxInfo& cursorType = screenLayout.checkBoxInfo(3);
const MachGuiOptionsLayout::CheckBoxInfo& reverseKeys = screenLayout.checkBoxInfo(4);
const MachGuiOptionsLayout::CheckBoxInfo& reverseMouse = screenLayout.checkBoxInfo(5);
const MachGuiOptionsLayout::CheckBoxInfo& grabMouse = screenLayout.checkBoxInfo(6);
// Create control labels
new MachGuiMenuText(
pStartupScreens,
Gui::Box(musicVolTxt.topLeft, musicVolTxt.bottomRight),
musicVolTxt.idsStringId,
musicVolTxt.font,
MachGuiMenuText::RIGHT_JUSTIFY);
new MachGuiMenuText(
pStartupScreens,
Gui::Box(soundVolTxt.topLeft, soundVolTxt.bottomRight),
soundVolTxt.idsStringId,
soundVolTxt.font,
MachGuiMenuText::RIGHT_JUSTIFY);
new MachGuiMenuText(
pStartupScreens,
Gui::Box(screenSizeTxt.topLeft, screenSizeTxt.bottomRight),
screenSizeTxt.idsStringId,
screenSizeTxt.font,
MachGuiMenuText::RIGHT_JUSTIFY);
new MachGuiMenuText(
pStartupScreens,
Gui::Box(directDrawTxt.topLeft, directDrawTxt.bottomRight),
directDrawTxt.idsStringId,
directDrawTxt.font,
MachGuiMenuText::RIGHT_JUSTIFY);
// new MachGuiMenuText( pStartupScreens, Gui::Box( direct3DTxt.topLeft, direct3DTxt.bottomRight ),
// direct3DTxt.idsStringId, direct3DTxt.font, MachGuiMenuText::RIGHT_JUSTIFY );
new MachGuiMenuText(
pStartupScreens,
Gui::Box(scaleFactorTxt.topLeft, scaleFactorTxt.bottomRight),
scaleFactorTxt.idsStringId,
scaleFactorTxt.font,
MachGuiMenuText::RIGHT_JUSTIFY);
// Create check boxes
pSound3d_ = new MachGuiCheckBox(pStartupScreens, pStartupScreens, sound3dCB.topLeft, sound3dCB.stringId);
pTransitions_
= new MachGuiCheckBox(pStartupScreens, pStartupScreens, transitionsCB.topLeft, transitionsCB.stringId);
pScreenResolutionLock_ = new
MachGuiCheckBox(pStartupScreens, pStartupScreens, screenResolutionLock.topLeft, screenResolutionLock.stringId);
pCursorType_ = new MachGuiCheckBox(pStartupScreens, pStartupScreens, cursorType.topLeft, cursorType.stringId);
pReverseKeys_ = new MachGuiCheckBox(pStartupScreens, pStartupScreens, reverseKeys.topLeft, reverseKeys.stringId);
pReverseMouse_
= new MachGuiCheckBox(pStartupScreens, pStartupScreens, reverseMouse.topLeft, reverseMouse.stringId);
pGrabMouse_
= new MachGuiCheckBox(pStartupScreens, pStartupScreens, grabMouse.topLeft, grabMouse.stringId);
// Create volume sliders
pMusicVolume_ = new MachGuiSlideBar(pStartupScreens, pStartupScreens, musicVolSl.topLeft, musicVolSl.range);
pMusicVolume_->minMax(0, 100);
pMusicVolume_->setValueChangedHandler([](float newValue) {
DevCD::instance().volume(newValue + 0.5 /*stop rounding errors from slowly reducing volume*/);
});
pSoundVolume_ = new MachGuiSlideBar(pStartupScreens, pStartupScreens, soundVolSl.topLeft, soundVolSl.range);
pSoundVolume_->minMax(0, 100);
pSoundVolume_->setValueChangedHandler([](float newValue) {
SndMixer::instance().masterSampleVolume(newValue + 0.5 /*stop rounding errors from slowly reducing volume*/);
});
const RenCapabilities& caps = W4dManager::instance().sceneManager()->pDevice()->capabilities();
// Get current resolution
int inGameResolutionWidth = pDisplay_->currentMode().width();
int inGameResolutionHeight = pDisplay_->currentMode().height();
int inGameResolutionRefresh = pDisplay_->currentMode().refreshRate();
// Check that minimum resolution is specified
if (inGameResolutionWidth < 640 || inGameResolutionHeight < 480)
{
inGameResolutionWidth = 640;
inGameResolutionHeight = 480;
}
GuiStrings strings;
MachGuiDropDownListBoxCreator::DropDownListBoxItems modeList;
strings.reserve(4);
modeList.reserve(4);
// Iterate through screen modes selecting compatible ones ( i.e. conform to minimum size and colour bit depth ).
const RenDisplay::Modes& modes = pDisplay_->modeList();
const RenDisplay::Mode& lowestMode = pDisplay_->lowestAllowedMode();
const RenDisplay::Mode& highestMode = pDisplay_->highestAllowedMode();
for (const RenDisplay::Mode& mode : modes)
{
// I'd like to use the highest allowed mode to decide whether a mode is accepted or
// not (instead of testing the memory required versus the available video memory)
// unfortunately I can't since the modes are sorted by number of pixels and not by memory
// requirement.
// if ( mode >= lowestMode and mode.bitDepth() == 16 and
if (mode >= lowestMode
&& caps.maxAvailableDisplayMemoryAfterTextures() >= 3 * mode.memoryRequired())
{
// Construct a string to go in the drop down list box ( e.g. "640x480" )
char buffer[30];
// string resolutionStr = itoa( mode.width(), buffer, 10 );
// resolutionStr += itoa( mode.height(), buffer, 10 );
sprintf(buffer, "%dx%d %d hz", mode.width(), mode.height(), mode.refreshRate());
string resolutionStr = buffer;
// If this mode is the current mode for ingame then make sure it appears first in the
// drop down list box
if (inGameResolutionWidth == mode.width() && inGameResolutionHeight == mode.height()
&& (inGameResolutionRefresh == 0 || inGameResolutionRefresh == mode.refreshRate()))
{
strings.insert(strings.begin(), resolutionStr);
modeList.insert(modeList.begin(), (void*)&mode);
}
else
{
strings.push_back(resolutionStr);
modeList.push_back((void*)&mode);
}
}
}
pScreenSize_ = new MachGuiDropDownListBoxCreator(
pStartupScreens,
pStartupScreens,
Gui::Coord(353, 119),
153,
strings,
false,
true);
pScreenSize_->items(modeList);
// Create list of avaliable direct draw drivers/direct 3d drivers
pDriverSelector_ = new RenDriverSelector(pDisplay_);
MachGuiDropDownListBoxCreator::DropDownListBoxItems dDrawDrivers;
GuiStrings dDrawDriverNames;
dDrawDriverNames.reserve(4);
dDrawDrivers.reserve(4);
const RenDriverSelector::RenDrivers& dDrawDriversList = pDriverSelector_->dDrawDrivers();
for (RenDriverSelector::RenDrivers::const_iterator i = dDrawDriversList.begin(); i != dDrawDriversList.end(); ++i)
{
dDrawDrivers.push_back((MachGuiDropDownListBoxCreator::DropDownListBoxItem) & (*i));
dDrawDriverNames.push_back((*i)->name());
}
dDrawDriverNames.push_back("default");
pDirectDrawDrivers_ = new MachGuiDDrawDropDownListBoxCreator(
pStartupScreens,
pStartupScreens,
Gui::Coord(353, 139),
153,
dDrawDriverNames,
false,
true,
new MachGuiDDrawDropDownCallback(*this));
pDirectDrawDrivers_->items(dDrawDrivers);
// pDirectDrawDrivers_->text( pDriverSelector_->currentDDrawDriver()->name() );
// showDirect3DDrivers();
// Only display gamma correction slider if gamma correction is supported
if (pDisplay_->supportsGammaCorrection())
{
new MachGuiMenuText(
pStartupScreens,
Gui::Box(gammaCorrectionTxt.topLeft, gammaCorrectionTxt.bottomRight),
gammaCorrectionTxt.idsStringId,
gammaCorrectionTxt.font,
MachGuiMenuText::RIGHT_JUSTIFY);
pGammaCorrection_ = new MachGuiSlideBar(
pStartupScreens,
pStartupScreens,
gammaCorrectionSl.topLeft,
gammaCorrectionSl.range,
GAMMA_LOWER_LIMIT,
GAMMA_UPPER_LIMIT);
// Store initial value
pGammaCorrection_->setValueChangedHandler([](float newValue) {
W4dManager::instance().sceneManager()->pDevice()->display()->gammaCorrection(newValue);
});
gammaCorrection_ = W4dManager::instance().sceneManager()->pDevice()->display()->gammaCorrection();
pGammaCorrection_->setValue(gammaCorrection_);
// Show gamma correction image (helps get gamma setting correct)
new GuiImage(pStartupScreens, Gui::Coord(353, 198), Gui::bitmap("gui/menu/gammacal.bmp"));
}
const MachPhysComplexityManager::BooleanItems& boolItems = MachPhysComplexityManager::instance().booleanItems();
// Access boolean items
uint index = 0;
for (MachPhysComplexityManager::BooleanItems::const_iterator it = boolItems.begin(); it != boolItems.end(); ++it)
{
uint id = (*it)->id();
booleanOptimisations_.push_back(new MachGuiCheckBox(
pStartupScreens,
pStartupScreens,
Gui::Coord(240, OPTIMISATIONS_AREA_MINY + 33 + (20 * index)),
id));
++index;
}
// Access all the choices items, their id and # of choice per id
const MachPhysComplexityManager::ChoiceItems& chItems = MachPhysComplexityManager::instance().choiceItems();
index = 0;
for (MachPhysComplexityManager::ChoiceItems::const_iterator it = chItems.begin(); it != chItems.end(); ++it)
{
uint id = (*it)->id();
uint nch = (*it)->nChoices();
GuiStrings choices;
MachGuiDropDownListBoxCreator::DropDownListBoxItems choiceIds;
choices.reserve(4);
choiceIds.reserve(4);
for (uint ch = 0; ch < nch; ++ch)
{
GuiResourceString choice(ch + id + 1);
string choiceString = choice.asString();
choices.push_back(choiceString);
choiceIds.push_back((MachGuiDropDownListBoxCreator::DropDownListBoxItem)(ch + 1));
}
GuiResourceString choiceTitle(id);
new MachGuiMenuText(
pStartupScreens,
Gui::Box(
Gui::Coord(
347 - smallFont.textWidth(choiceTitle.asString()),
OPTIMISATIONS_AREA_MINY + 33 + (20 * index)),
smallFont.textWidth(choiceTitle.asString()),
smallFont.charHeight() + 8),
id,
"gui/menu/smallfnt.bmp");
choicesOptimisations_.push_back(new MachGuiDropDownListBoxCreator(
pStartupScreens,
pStartupScreens,
Gui::Coord(353, OPTIMISATIONS_AREA_MINY + 35 + (20 * index)),
153,
choices,
false,
true));
(*(choicesOptimisations_.end() - 1))->items(choiceIds);
++index;
}
// Retain original settings in case user cancels subsequent settings
musicVolume_ = pMusicVolume_->value();
soundVolume_ = pSoundVolume_->value();
initialDDrawDriver_ = pDriverSelector_->currentDDrawDriver();
GuiResourceString defaultStr(IDS_MENU_DEFAULT);
GuiStrings scaleNames = {
defaultStr.asString(),
"100%",
"200%",
};
static const int scaleValues[] = {
0,
100,
200,
};
pScaleFactorSelector_ = new MachGuiDropDownListBoxCreator(
pStartupScreens,
pStartupScreens,
Gui::Coord(353, 159),
153,
scaleNames,
false,
true);
auto items = MachGuiDropDownListBoxCreator::createBoxItems(scaleValues);
pScaleFactorSelector_->items(items);
readFromConfig();
pGrabMouse_->setCallback([](MachGuiCheckBox* pCheckBox) {
RenDisplay* pDisplay_ = W4dManager::instance().sceneManager()->pDevice()->display();
pDisplay_->setCursorGrabEnabled(pCheckBox->isChecked());
});
TEST_INVARIANT;
}
MachGuiCtxOptions::~MachGuiCtxOptions()
{
TEST_INVARIANT;
}
void MachGuiCtxOptions::CLASS_INVARIANT
{
INVARIANT(this != nullptr);
}
std::ostream& operator<<(std::ostream& o, const MachGuiCtxOptions& t)
{
o << "MachGuiCtxOptions " << static_cast<const void*>(&t) << " start" << std::endl;
o << "MachGuiCtxOptions " << static_cast<const void*>(&t) << " end" << std::endl;
return o;
}
// virtual
void MachGuiCtxOptions::update()
{
if (exitFromOptions_)
{
pStartupScreens_->buttonAction(MachGuiStartupScreens::BE_OK);
}
else
{
animations_.update();
}
}
// virtual
bool MachGuiCtxOptions::okayToSwitchContext()
{
return true;
}
// virtual
void MachGuiCtxOptions::buttonEvent(MachGuiStartupScreens::ButtonEvent buttonEvent)
{
if (buttonEvent == MachGuiStartupScreens::BE_DUMMY_OK)
{
int currentScaleFactorValue = SysRegistry::instance().queryIntegerValue(c_ScaleFactorOptionKey, "Value");
writeToConfig();
SysRegistry::instance().reload();
uint idsMessage;
bool bDisplayMessageBox = false;
// Determine if the video driver settings have changed
/*if( ( pDriverSelector_->currentDDrawDriver()->name() != initialDDrawDriver_->name() ) or
( pDriverSelector_->currentDDrawDriver()->description() != initialDDrawDriver_->description() ) )
{
idsMessage = IDS_MENUMSG_DISPLAYDRIVER;
bDisplayMessageBox = true;
}*/
// Determine if the 2D selection boxes are enabled and screen resolution has changed
const RenDisplay::Mode* pNewMode = (const RenDisplay::Mode*)pScreenSize_->item();
const RenDisplay::Mode& pCurrentMode
= W4dManager::instance().sceneManager()->pDevice()->display()->currentMode();
int newScaleFactorValue = SysRegistry::instance().queryIntegerValue(c_ScaleFactorOptionKey, "Value");
if (pScreenResolutionLock_->isChecked()
&& ((pNewMode->width() != pCurrentMode.width()) || (pNewMode->height() != pCurrentMode.height())))
{
// If we already have a message to display from the previous settings change, then use a combined message
if (bDisplayMessageBox)
{
idsMessage = IDS_MENUMESSAGE_DRIVER_RESOLUTION;
}
else
{
idsMessage = IDS_MENUMESSAGE_RESOLUTION;
}
bDisplayMessageBox = true;
}
if (!bDisplayMessageBox && (currentScaleFactorValue != newScaleFactorValue))
{
idsMessage = IDS_MENUMESSAGE_SCALE_FACTOR;
bDisplayMessageBox = true;
}
if (bDisplayMessageBox)
{
// Inform user that changes will not take effect until the machine is rebooted
pStartupScreens_->displayOKMsgBox(idsMessage, new MachGuiOptionsExitMessageBoxResponder(this));
}
else
{
pStartupScreens_->buttonAction(MachGuiStartupScreens::BE_OK);
}
}
else if (buttonEvent == MachGuiStartupScreens::BE_DUMMY_EXIT)
{
pMusicVolume_->setValue(musicVolume_);
pSoundVolume_->setValue(soundVolume_);
pDriverSelector_->useDDrawDriver(initialDDrawDriver_);
// Only restore gamma correction if gamma correction is supported
if (pGammaCorrection_)
{
pGammaCorrection_->setValue(gammaCorrection_);
}
pStartupScreens_->buttonAction(MachGuiStartupScreens::EXIT);
const bool grabCursorEnabled = SysRegistry::instance().queryBooleanValue(c_GrabCursorOptionKey, "on", true);
pGrabMouse_->setChecked(grabCursorEnabled);
}
}
void MachGuiCtxOptions::writeToConfig()
{
// Used to set current game settings to be that of gui items
if (pSound3d_->isChecked() != SysRegistry::instance().queryIntegerValue("Options\\3DSound", "on"))
{
SOUND_STREAM("Updating sounds" << std::endl);
// //It is necessary to clear all sounds from the system
// //before loading a new set.
MachGuiSoundManager::instance().clearAll();
W4dSoundManager::instance().stopAll();
load3dSoundFiles(pSound3d_->isChecked());
// We now have to change all the in game sounds to the correct
// number of dimensions
if (pSound3d_->isChecked())
{
W4dSoundManager::instance().convertSoundDimensions(Snd::THREE_D);
}
else
{
W4dSoundManager::instance().convertSoundDimensions(Snd::TWO_D);
}
SysRegistry::instance().setIntegerValue("Options\\3DSound", "on", pSound3d_->isChecked());
}
pStartupScreens_->startupData()->transitionFlicsOn(pTransitions_->isChecked());
SysRegistry::instance().setIntegerValue(
"Options\\transitions",
"on",
pStartupScreens_->startupData()->transitionFlicsOn());
// Store the new screen size in the registry
const RenDisplay::Mode* pNewMode = (const RenDisplay::Mode*)pScreenSize_->item();
SysRegistry::instance().setIntegerValue("Screen Resolution", "Width", pNewMode->width());
SysRegistry::instance().setIntegerValue("Screen Resolution", "Height", pNewMode->height());
SysRegistry::instance().setIntegerValue("Screen Resolution", "Refresh Rate", pNewMode->refreshRate());
// Store sound and CD settings
SysRegistry::instance().setIntegerValue(
"Options\\CD",
"Volume",
pMusicVolume_->value() + 0.5 /*stop rounding errors*/);
SysRegistry::instance().setIntegerValue(
"Options\\Sound",
"Volume",
pSoundVolume_->value() + 0.5 /*stop rounding errors*/);
// Store gamma correction value
if (pGammaCorrection_)
{
SysRegistry::instance().setIntegerValue(
"Options\\Gamma Correction",
"Value",
static_cast<double>(pGammaCorrection_->value()) * GAMMA_REG_MULTIPLIER);
}
// Store option to maintain screen res of in-game menus in menus
SysRegistry::instance().setIntegerValue("Screen Resolution", "Lock Resolution", pScreenResolutionLock_->isChecked());
// Store cursor type (2D/3D)
SysRegistry::instance().setIntegerValue("Options\\Cursor Type", "2D", pCursorType_->isChecked());
// If cursor type has changed then refresh all selection boxes
if (cursorType2d_ != pCursorType_->isChecked())
{
MachLogRaces::Objects& allObjects = MachLogRaces::instance().objects();
for (MachLogRaces::Objects::iterator iter = allObjects.begin(); iter != allObjects.end(); ++iter)
{
MachActor* pActor = *iter;
if (pActor->selectionState() == MachLog::SELECTED)
{
// Deselect, then reselect to refresh bounding box
pActor->selectionState(MachLog::NOT_SELECTED);
pActor->selectionState(MachLog::SELECTED);
}
else if (pActor->selectionState() == MachLog::HIGHLIGHTED)
{
// Deselect, then reselect to refresh bounding box
pActor->selectionState(MachLog::NOT_SELECTED);
pActor->selectionState(MachLog::HIGHLIGHTED);
}
}
}
// Store reverse direction of up/down keys/mouse
SysRegistry::instance().setIntegerValue("Options\\Reverse UpDown Keys", "on", pReverseKeys_->isChecked());
SysRegistry::instance().setIntegerValue("Options\\Reverse BackForward Mouse", "on", pReverseMouse_->isChecked());
SysRegistry::instance().setIntegerValue(c_GrabCursorOptionKey, "on", pGrabMouse_->isChecked());
// Access all the boolean optimisations
const MachPhysComplexityManager::BooleanItems& boolItems = MachPhysComplexityManager::instance().booleanItems();
uint index = 0;
for (MachPhysComplexityManager::BooleanItems::const_iterator it = boolItems.begin(); it != boolItems.end(); ++it)
{
uint id = (*it)->id();
MachPhysComplexityManager::instance().changeBooleanItem(id, booleanOptimisations_[index]->isChecked());
++index;
}
index = 0;
// Access all the choices items, their id and # of choice per id
const MachPhysComplexityManager::ChoiceItems& chItems = MachPhysComplexityManager::instance().choiceItems();
for (MachPhysComplexityManager::ChoiceItems::const_iterator it = chItems.begin(); it != chItems.end(); ++it)
{
uint id = (*it)->id();
// TODO: void* to uint??, this ptr value is stored simply as number?
// MachPhysComplexityManager::instance().changeChoiceItem( id, ( uint ) choicesOptimisations_[index]->item() - 1
// );
MachPhysComplexityManager::instance().changeChoiceItem(id, (size_t)choicesOptimisations_[index]->item() - 1);
++index;
}
// Set Direct3DDriver to be the one selected in the list of available Direct3DDrivers
// CtlCountedPtr<RenDriver> const & newDriver = ( CtlCountedPtr<RenDriver> const & ) *(pDirect3DDrivers_->item());
// CtlCountedPtr<RenDriver> const & newDriver =
// ( CtlCountedPtr<RenDriver> const & ) *((CtlCountedPtr<RenDriver>*)pDirect3DDrivers_->item());
// pDriverSelector_->useD3dDriver( newDriver );
// Save display driver info in registry
// pDriverSelector_->updateDriverRegistries();
{
MachGuiDropDownListBoxCreator::DropDownListBoxItem currentItem = pScaleFactorSelector_->item();
int ScaleValue = *static_cast<const int*>(currentItem);
SysRegistry::instance().setIntegerValue(c_ScaleFactorOptionKey, "Value", ScaleValue);
}
}
void MachGuiCtxOptions::readFromConfig()
{
// Used to set gui items to reflect current game settings
SysRegistry::KeyHandle handle;
if (SysRegistry::instance().onlyOpenKey("Options\\3DSound", &handle) == SysRegistry::SUCCESS)
{
pSound3d_->setChecked(SysRegistry::instance().queryIntegerValue("Options\\3DSound", "on"));
}
else
{
pSound3d_->setChecked(SndMixer::instance().is3dMixer());
}
musicVolume_ = DevCD::instance().volume();
soundVolume_ = SndMixer::instance().masterSampleVolume();
pMusicVolume_->setValue(musicVolume_);
pSoundVolume_->setValue(soundVolume_);
// Set resolution lock on if it the first time the game is being run
SysRegistry::KeyHandle resolutionHandle;
if (SysRegistry::instance().onlyOpenKey("Screen Resolution\\Lock Resolution", &resolutionHandle)
!= SysRegistry::SUCCESS)
{
SysRegistry::instance().setIntegerValue(
"Screen Resolution",
"Lock Resolution",
MachGuiStartupScreens::getDefaultLockScreenResolutionValue());
}
pScreenResolutionLock_->setChecked(SysRegistry::instance().queryIntegerValue("Screen Resolution", "Lock Resolution"));
pCursorType_->setChecked(SysRegistry::instance().queryIntegerValue("Options\\Cursor Type", "2D"));
pReverseKeys_->setChecked(SysRegistry::instance().queryIntegerValue("Options\\Reverse UpDown Keys", "on"));
pReverseMouse_->setChecked(SysRegistry::instance().queryIntegerValue("Options\\Reverse BackForward Mouse", "on"));
const bool grabCursorEnabled = SysRegistry::instance().queryBooleanValue(c_GrabCursorOptionKey, "on", true);
pGrabMouse_->setChecked(grabCursorEnabled);
pTransitions_->setChecked(pStartupScreens_->startupData()->transitionFlicsOn());
// Access all the boolean optimisations
const MachPhysComplexityManager::BooleanItems& boolItems = MachPhysComplexityManager::instance().booleanItems();
uint index = 0;
for (MachPhysComplexityManager::BooleanItems::const_iterator it = boolItems.begin(); it != boolItems.end(); ++it)
{
uint id = (*it)->id();
booleanOptimisations_[index]->setChecked((*it)->enabled());
++index;
}
index = 0;
// Access all the choices items, their id and # of choice per id
const MachPhysComplexityManager::ChoiceItems& chItems = MachPhysComplexityManager::instance().choiceItems();
for (MachPhysComplexityManager::ChoiceItems::const_iterator it = chItems.begin(); it != chItems.end(); ++it)
{
uint id = (*it)->id();
GuiResourceString choice(id + (*it)->choice() + 1);
choicesOptimisations_[index]->text(choice.asString());
++index;
}
cursorType2d_ = pCursorType_->isChecked();
{
int scaleFactorValue = SysRegistry::instance().queryIntegerValue(c_ScaleFactorOptionKey, "Value");
const MachGuiDropDownListBoxCreator::DropDownListBoxItems& scaleItems = pScaleFactorSelector_->items();
size_t scaleItemIndex = 0;
for (size_t i = 0; i < scaleItems.size(); ++i)
{
const int* scale = static_cast<const int*>(scaleItems.at(i));
if (scaleFactorValue == *scale)
{
scaleItemIndex = i;
break;
}
}
pScaleFactorSelector_->setCurrentItem(scaleItems.at(scaleItemIndex));
}
}
// static
void MachGuiCtxOptions::load3dSoundFiles(bool enabled)
{
// Load the sound definition file depending on 3d sound enabled and the bit rate currently being used
unsigned int totalMem = SysMemoryCaps::totalPhysicalMem();
// World4d needs to know what sounds we are operating with.
enabled ? W4dSoundManager::instance().currentSoundDimensions(Snd::THREE_D)
: W4dSoundManager::instance().currentSoundDimensions(Snd::TWO_D);
if (enabled)
{
if (totalMem > 64000000)
W4dSoundManager::instance().readSoundDefinitionFile("sounds/snddef64.dat");
else if (totalMem > 32000000)
W4dSoundManager::instance().readSoundDefinitionFile("sounds/snddef32.dat");
else
W4dSoundManager::instance().readSoundDefinitionFile("sounds/snddef16.dat");
}
else
{
if (totalMem > 64000000)
W4dSoundManager::instance().readSoundDefinitionFile("sounds/sd2d64.dat");
else if (totalMem > 32000000)
W4dSoundManager::instance().readSoundDefinitionFile("sounds/sd2d32.dat");
else
W4dSoundManager::instance().readSoundDefinitionFile("sounds/sd2d16.dat");
}
}
void MachGuiCtxOptions::showDirect3DDrivers()
{
if (!pDirectDrawDrivers_->hasItems())
return;
// CtlCountedPtr<RenDriver> const & newDriver = ( CtlCountedPtr<RenDriver> const & ) *(pDirectDrawDrivers_->item());
CtlCountedPtr<RenDriver> const& newDriver
= (CtlCountedPtr<RenDriver> const&)*((CtlCountedPtr<RenDriver>*)pDirectDrawDrivers_->item());
pDriverSelector_->useDDrawDriver(newDriver);
delete pDirect3DDrivers_;
const RenDriverSelector::RenDrivers& d3dDriversList = pDriverSelector_->d3dDrivers();
MachGuiDropDownListBoxCreator::DropDownListBoxItems d3dDrivers;
GuiStrings d3dDriverNames;
d3dDriverNames.reserve(4);
d3dDrivers.reserve(4);
for (RenDriverSelector::RenDrivers::const_iterator i = d3dDriversList.begin(); i != d3dDriversList.end(); ++i)
{
d3dDrivers.push_back((MachGuiDropDownListBoxCreator::DropDownListBoxItem) & (*i));
d3dDriverNames.push_back((*i)->name());
}
pDirect3DDrivers_ = new MachGuiDropDownListBoxCreator(
pStartupScreens_,
pStartupScreens_,
Gui::Coord(353, 159),
153,
d3dDriverNames,
false,
true);
pDirect3DDrivers_->items(d3dDrivers);
pDirect3DDrivers_->text(pDriverSelector_->currentD3dDriver()->name());
}
void MachGuiCtxOptions::exitFromOptions()
{
exitFromOptions_ = true;
}
/* End CTXOPTNS.CPP *************************************************/