Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameengine): leave only the volumes in game on windows

Olcay Seyganfee908764406
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 34023cdc9..7f6603e9a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1157,6 +1157,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
## The options screen has pages
+- On Windows every setting lives in the launcher now, where you set it before the game starts. The main menu has no Options button any more, and Credits and Exit move up into its place. In a match, Esc and then Options still opens the sound: music, effects, voices and ambience, nothing else. Accept there saves those four and leaves the rest of your settings file alone, so the resolution or detail preset you picked in the launcher stays exactly as you left it. On a Mac and on Linux, which have no launcher, the options screen is the whole of what follows.
- Display, graphics, effects, audio, controls, interface and network, behind seven buttons across the top. The original screen was one panel with everything on it at once, and it was already full the day it shipped: the language filter, the keyboard button and four camera checkboxes are all still in there, parked off the right edge where nobody can reach them, because there was nowhere left to put them.
- Every setting sits with the ones that do the same kind of job. Display is the screen and its brightness. Graphics is what the picture costs and how sharp it is, with the glow and the lighting in a group of their own instead of mixed in with the anti-aliasing. Effects is what stands in the world: all seven shadow boxes together, cloud shadows included, then the scenery, then smoke. Controls splits the camera, the orders, building placement and the mouse into four groups, and Interface holds the command bar size, the income readout, the health bars, the colours, the order lines and the language. In Classic the screen leaves out the few boxes Classic ignores anyway, from smooth motion to the HUD size and the order lines, and closes the gaps they leave, so a box on that screen always does something.
- Classic Graphics, on the Graphics page, puts the game back the way it looked in 2003 in one click: its own textures and ground in place of the upscaled ones, the old hard shadows, the round dark patch under every tree where Reforged lays the tree's own outline on the ground, and no glow or sharpening over the picture. Leave it off and you have Reforged. The rest of the options stay yours either way, and the box takes effect the next time the game starts.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GUICallbacks.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GUICallbacks.h
index 92c5730af..fd3eb6fbc 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GUICallbacks.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GUICallbacks.h
@@ -64,6 +64,9 @@ extern WindowMsgHandledType OptionsMenuSystem( GameWindow *window, UnsignedInt m
extern WindowMsgHandledType OptionsMenuInput( GameWindow *window, UnsignedInt msg, WindowMsgData mData1, WindowMsgData mData2 );
/// -resdrill: the options menu's own in-match resolution change, driven from the update loop
extern void ResolutionDrillApply( Int xres, Int yres );
+#if defined(_WIN32)
+extern void OpenVolumeOptions( void ); ///< the options layout with the Audio page alone; the launcher owns the rest
+#endif
/// and the answer to the box it leaves behind, a few frames later, the way a player answers it
extern void ResolutionDrillDismiss( Bool accept );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp
index 2bfc6b64c..27b5eadd3 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp
@@ -570,7 +570,34 @@ void MainMenuInit( WindowLayout *layout, void *userData )
dropDownWindows[i]->winHide(TRUE);
initialHide();
-
+
+#if defined(_WIN32)
+ //
+ // The launcher owns every setting on Windows, so the main menu has no Options button. It is
+ // destroyed rather than hidden because the menu's transitions show every window they name; a
+ // destroyed one is not found and they skip it. Credits and Exit move up into the gap and the
+ // panel behind them gives up the row. The shell runs this init again on the same windows each
+ // time a screen above the main menu is popped, and then the button is already gone.
+ //
+ if( buttonOptions )
+ {
+ Int x, optionsY, creditsY, exitY, width, height;
+ buttonOptions->winGetPosition( &x, &optionsY );
+ buttonCredits->winGetPosition( &x, &creditsY );
+ buttonExit->winGetPosition( &x, &exitY );
+ const Int row = creditsY - optionsY;
+ buttonCredits->winSetPosition( x, optionsY );
+ buttonExit->winSetPosition( x, creditsY );
+ GameWindow *panel = buttonExit->winGetParent();
+ panel->winGetSize( &width, &height );
+ panel->winSetSize( width, height - row );
+ dropDownWindows[DROPDOWN_MAIN]->winGetSize( &width, &height );
+ dropDownWindows[DROPDOWN_MAIN]->winSetSize( width, height - row );
+ TheWindowManager->winDestroy( buttonOptions );
+ buttonOptions = NULL;
+ }
+#endif
+
showSelectiveButtons(SHOW_NONE);
// Set up the version number
#if defined _DEBUG || defined _INTERNAL || defined _PROFILE
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
index 49e58d4bb..70fb93d10 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -1248,6 +1248,104 @@ static void updateResolutionNote( void )
GadgetStaticTextSetText( note, supported ? TheGameText->fetch( "GUI:ResolutionNote0" ) : UnicodeString::TheEmptyString );
}
+//-------------------------------------------------------------------------------------------------
+/** Music, effects and voice: from their sliders into GlobalData, the audio manager and out. */
+//-------------------------------------------------------------------------------------------------
+static void saveVolumeOptions( OptionPreferences &out )
+{
+ Int val;
+
+ //-------------------------------------------------------------------------------------------------
+ // slider music volume
+ val = GadgetSliderGetPosition(sliderMusicVolume);
+ if(val != -1)
+ {
+ TheWritableGlobalData->m_musicVolumeFactor = val;
+ AsciiString prefString;
+ prefString.format("%d", val);
+ out["MusicVolume"] = prefString;
+ TheAudio->setVolume(val / 100.0f, (AudioAffect) (AudioAffect_Music | AudioAffect_SystemSetting));
+ }
+
+ //-------------------------------------------------------------------------------------------------
+ // slider SFX volume
+ val = GadgetSliderGetPosition(sliderSFXVolume);
+ if(val != -1)
+ {
+ //Both 2D and 3D sound effects are sharing the same slider. However, there is a
+ //relative slider that gets applied to one of these values to lower that sound volume.
+ Real sound2DVolume = val / 100.0f;
+ Real sound3DVolume = val / 100.0f;
+ Real relative2DVolume = TheAudio->getAudioSettings()->m_relative2DVolume;
+ relative2DVolume = MIN( 1.0f, MAX( -1.0, relative2DVolume ) );
+ if( relative2DVolume < 0.0f )
+ {
+ //Lower the 2D volume
+ sound2DVolume *= 1.0f + relative2DVolume;
+ }
+ else
+ {
+ //Lower the 3D volume
+ sound3DVolume *= 1.0f - relative2DVolume;
+ }
+
+ //Apply the sound volumes in the audio system now.
+ TheAudio->setVolume( sound2DVolume, (AudioAffect) (AudioAffect_Sound | AudioAffect_SystemSetting) );
+ TheAudio->setVolume( sound3DVolume, (AudioAffect) (AudioAffect_Sound3D | AudioAffect_SystemSetting) );
+
+ //Save the settings in the options.ini.
+ TheWritableGlobalData->m_SFXVolumeFactor = val;
+ AsciiString prefString;
+ prefString.format("%d", REAL_TO_INT( sound2DVolume * 100.0f ) );
+ out["SFXVolume"] = prefString;
+ prefString.format("%d", REAL_TO_INT( sound3DVolume * 100.0f ) );
+ out["SFX3DVolume"] = prefString;
+ }
+
+ //-------------------------------------------------------------------------------------------------
+ // slider Voice volume
+ val = GadgetSliderGetPosition(sliderVoiceVolume);
+ if(val != -1)
+ {
+ TheWritableGlobalData->m_voiceVolumeFactor = val;
+ AsciiString prefString;
+ prefString.format("%d", val);
+ out["VoiceVolume"] = prefString;
+ TheAudio->setVolume(val / 100.0f, (AudioAffect) (AudioAffect_Speech | AudioAffect_SystemSetting));
+ }
+}
+
+#if defined(_WIN32)
+//-------------------------------------------------------------------------------------------------
+// The volume view. On Windows the launcher owns every setting but the four volumes, so the quit
+// menu's Options button opens the Audio page alone (OpenVolumeOptions), and its Accept writes those
+// four onto Options.ini as it is on disk right now. Nothing the menu loaded for the other pages is
+// written back, so a resolution or a detail preset the launcher saved stays what the launcher said.
+// -optionsmenu and -resdrill still open the whole menu; they are how a script reaches it.
+//-------------------------------------------------------------------------------------------------
+static Bool volumeOnly = FALSE;
+
+static void saveVolumeOnly( void )
+{
+ delete pref;
+ pref = NEW OptionPreferences;
+ saveVolumeOptions( *pref );
+
+ // ambience is a catalog row; its setter applies it to the audio manager as well
+ const OptionDef *ambient = findOptionDef( "AmbientVolume" );
+ ambient->set( clampOptionValue( *ambient, GadgetSliderGetPosition( findOptionWidget( *ambient ) ) ) );
+ (*pref)[ "AmbientVolume" ] = formatOptionValue( *ambient, ambient->get() );
+}
+
+void OpenVolumeOptions( void )
+{
+ WindowLayout *optLayout = TheShell->getOptionsLayout( TRUE );
+ optLayout->runInit( &volumeOnly );
+ optLayout->hide( FALSE );
+ optLayout->bringForward();
+}
+#endif
+
static void saveOptions( void )
{
Int index;
@@ -1591,64 +1689,7 @@ static void saveOptions( void )
(*pref)["ScrollFactor"] = prefString;
}
- //-------------------------------------------------------------------------------------------------
- // slider music volume
- val = GadgetSliderGetPosition(sliderMusicVolume);
- if(val != -1)
- {
- TheWritableGlobalData->m_musicVolumeFactor = val;
- AsciiString prefString;
- prefString.format("%d", val);
- (*pref)["MusicVolume"] = prefString;
- TheAudio->setVolume(val / 100.0f, (AudioAffect) (AudioAffect_Music | AudioAffect_SystemSetting));
- }
-
- //-------------------------------------------------------------------------------------------------
- // slider SFX volume
- val = GadgetSliderGetPosition(sliderSFXVolume);
- if(val != -1)
- {
- //Both 2D and 3D sound effects are sharing the same slider. However, there is a
- //relative slider that gets applied to one of these values to lower that sound volume.
- Real sound2DVolume = val / 100.0f;
- Real sound3DVolume = val / 100.0f;
- Real relative2DVolume = TheAudio->getAudioSettings()->m_relative2DVolume;
- relative2DVolume = MIN( 1.0f, MAX( -1.0, relative2DVolume ) );
- if( relative2DVolume < 0.0f )
- {
- //Lower the 2D volume
- sound2DVolume *= 1.0f + relative2DVolume;
- }
- else
- {
- //Lower the 3D volume
- sound3DVolume *= 1.0f - relative2DVolume;
- }
-
- //Apply the sound volumes in the audio system now.
- TheAudio->setVolume( sound2DVolume, (AudioAffect) (AudioAffect_Sound | AudioAffect_SystemSetting) );
- TheAudio->setVolume( sound3DVolume, (AudioAffect) (AudioAffect_Sound3D | AudioAffect_SystemSetting) );
-
- //Save the settings in the options.ini.
- TheWritableGlobalData->m_SFXVolumeFactor = val;
- AsciiString prefString;
- prefString.format("%d", REAL_TO_INT( sound2DVolume * 100.0f ) );
- (*pref)["SFXVolume"] = prefString;
- prefString.format("%d", REAL_TO_INT( sound3DVolume * 100.0f ) );
- (*pref)["SFX3DVolume"] = prefString;
- }
-
- //-------------------------------------------------------------------------------------------------
- // slider Voice volume
- val = GadgetSliderGetPosition(sliderVoiceVolume);
- if(val != -1)
- {
- TheWritableGlobalData->m_voiceVolumeFactor = val;
- AsciiString prefString;
- prefString.format("%d", val);
- (*pref)["VoiceVolume"] = prefString;
- TheAudio->setVolume(val / 100.0f, (AudioAffect) (AudioAffect_Speech | AudioAffect_SystemSetting));
- }
+ saveVolumeOptions( *pref );
//-------------------------------------------------------------------------------------------------
// slider Gamma
@@ -2669,6 +2710,17 @@ void OptionsMenuInit( WindowLayout *layout, void *userData )
updateDetailNote();
showOptionsPage( 0 );
+#if defined(_WIN32)
+ // the volume view: the Audio page and no tabs to leave it by
+ volumeOnly = ( userData == &volumeOnly );
+ if( volumeOnly )
+ {
+ showOptionsPage( 3 );
+ for( Int page = 0; page < OPTIONS_PAGE_COUNT; ++page )
+ optionsTab[ page ]->winHide( TRUE );
+ }
+#endif
+
// show menu
layout->hide( FALSE );
@@ -2937,6 +2989,11 @@ WindowMsgHandledType OptionsMenuSystem( GameWindow *window, UnsignedInt msg,
} // end if
else if (controlID == buttonAccept )
{
+#if defined(_WIN32)
+ if( volumeOnly )
+ saveVolumeOnly();
+ else
+#endif
saveOptions();
// the command bar rebuilds its grid letters on its next update
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/QuitMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/QuitMenu.cpp
index 50e466f5e..57f2247d2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/QuitMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/QuitMenu.cpp
@@ -614,11 +614,15 @@ WindowMsgHandledType QuitMenuSystem( GameWindow *window, UnsignedInt msg,
} // end else if
else if( buttonOptions == controlID )
{
+#if defined(_WIN32)
+ OpenVolumeOptions();
+#else
WindowLayout *optLayout = TheShell->getOptionsLayout(TRUE);
DEBUG_ASSERTCRASH(optLayout != NULL, ("options menu layout is NULL"));
optLayout->runInit();
optLayout->hide(FALSE);
optLayout->bringForward();
+#endif
}
// else if( controlID == buttonQuitToDesktop )
// {
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLWelcomeMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLWelcomeMenu.cpp
index fd4c82347..3373bf1c5 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLWelcomeMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLWelcomeMenu.cpp
@@ -439,6 +439,10 @@ void WOLWelcomeMenuInit( WindowLayout *layout, void *userData )
buttonBack = TheWindowManager->winGetWindowFromId( NULL, buttonBackID);
buttonOptionsID = TheNameKeyGenerator->nameToKey( "WOLWelcomeMenu.wnd:ButtonOptions" );
buttonbuttonOptions = TheWindowManager->winGetWindowFromId( NULL, buttonOptionsID);
+#if defined(_WIN32)
+ // the launcher owns every setting on Windows
+ buttonbuttonOptions->winHide( TRUE );
+#endif
listboxInfoID = TheNameKeyGenerator->nameToKey( AsciiString( "WOLWelcomeMenu.wnd:InfoListbox" ) );
listboxInfo = TheWindowManager->winGetWindowFromId( NULL, listboxInfoID);