GCI2012: Sound Option, Hear Only Music
authorkoda
Thu, 06 Dec 2012 00:52:50 +0100
changeset 8254 eeaf3e1773c6
parent 8252 db3bccd784c9 (current diff)
parent 8249 9ffb156902f6 (diff)
child 8256 19dbb3209f46
GCI2012: Sound Option, Hear Only Music
--- a/QTfrontend/gameuiconfig.cpp	Thu Dec 06 00:44:27 2012 +0100
+++ b/QTfrontend/gameuiconfig.cpp	Thu Dec 06 00:52:50 2012 +0100
@@ -50,7 +50,7 @@
 
     setIniCodec("UTF-8");
 
-    connect(Form->ui.pageOptions->CBEnableFrontendMusic, SIGNAL(toggled(bool)), Form, SLOT(Music(bool)));
+    connect(Form->ui.pageOptions->CBFrontendMusic, SIGNAL(toggled(bool)), Form, SLOT(Music(bool)));
 
     //Form->resize(value("frontend/width", 640).toUInt(), value("frontend/height", 450).toUInt());
     resizeToConfigValues();
@@ -80,10 +80,10 @@
     Form->ui.pageOptions->SLQuality->setValue(value("video/quality", 5).toUInt());
     Form->ui.pageOptions->CBStereoMode->setCurrentIndex(value("video/stereo", 0).toUInt());
     Form->ui.pageOptions->CBFrontendEffects->setChecked(value("frontend/effects", true).toBool());
-    Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool());
-    Form->ui.pageOptions->CBEnableFrontendSound->setChecked(value("frontend/sound", true).toBool());
-    Form->ui.pageOptions->CBEnableMusic->setChecked(value("audio/music", true).toBool());
-    Form->ui.pageOptions->CBEnableFrontendMusic->setChecked(value("frontend/music", true).toBool());
+    Form->ui.pageOptions->CBSound->setChecked(value("audio/sound", true).toBool());
+    Form->ui.pageOptions->CBFrontendSound->setChecked(value("frontend/sound", true).toBool());
+    Form->ui.pageOptions->CBMusic->setChecked(value("audio/music", true).toBool());
+    Form->ui.pageOptions->CBFrontendMusic->setChecked(value("frontend/music", true).toBool());
     Form->ui.pageOptions->volumeBox->setValue(value("audio/volume", 100).toUInt());
 
     QString netNick = value("net/nick", "").toString();
@@ -397,20 +397,20 @@
 
 bool GameUIConfig::isSoundEnabled()
 {
-    return Form->ui.pageOptions->CBEnableSound->isChecked();
+    return Form->ui.pageOptions->CBSound->isChecked();
 }
 bool GameUIConfig::isFrontendSoundEnabled()
 {
-    return Form->ui.pageOptions->CBEnableFrontendSound->isChecked();
+    return Form->ui.pageOptions->CBFrontendSound->isChecked();
 }
 
 bool GameUIConfig::isMusicEnabled()
 {
-    return Form->ui.pageOptions->CBEnableMusic->isChecked();
+    return Form->ui.pageOptions->CBMusic->isChecked();
 }
 bool GameUIConfig::isFrontendMusicEnabled()
 {
-    return Form->ui.pageOptions->CBEnableFrontendMusic->isChecked();
+    return Form->ui.pageOptions->CBFrontendMusic->isChecked();
 }
 
 bool GameUIConfig::isShowFPSEnabled()
--- a/QTfrontend/hwform.cpp	Thu Dec 06 00:44:27 2012 +0100
+++ b/QTfrontend/hwform.cpp	Thu Dec 06 00:52:50 2012 +0100
@@ -1463,7 +1463,7 @@
             //setVisible(true);
             setFocusPolicy(Qt::StrongFocus);
             if (id == ID_PAGE_INGAME) GoBack();
-            Music(ui.pageOptions->CBEnableFrontendMusic->isChecked());
+            Music(ui.pageOptions->CBFrontendMusic->isChecked());
             if (wBackground) wBackground->startAnimation();
             GoToPage(ID_PAGE_GAMESTATS);
             if (hwnet && (!game || !game->netSuspend)) hwnet->gameFinished(true);
@@ -1481,7 +1481,7 @@
                      (gameState == gsInterrupted || gameState == gsStopped || gameState == gsDestroyed || gameState == gsHalted)))
             {
                 if (id == ID_PAGE_INGAME) GoBack();
-                Music(ui.pageOptions->CBEnableFrontendMusic->isChecked());
+                Music(ui.pageOptions->CBFrontendMusic->isChecked());
                 if (wBackground) wBackground->startAnimation();
                 if (hwnet) hwnet->gameFinished(false);
             }
--- a/QTfrontend/ui/page/pageoptions.cpp	Thu Dec 06 00:44:27 2012 +0100
+++ b/QTfrontend/ui/page/pageoptions.cpp	Thu Dec 06 00:52:50 2012 +0100
@@ -245,25 +245,33 @@
             AGGroupBox->setTitle(QGroupBox::tr("Audio/Graphic options"));
 
             QVBoxLayout * GBAlayout = new QVBoxLayout(AGGroupBox);
+            QGridLayout * GBAfrontendlayout = new QGridLayout(0);
             QHBoxLayout * GBAreslayout = new QHBoxLayout(0);
             QHBoxLayout * GBAstereolayout = new QHBoxLayout(0);
             QHBoxLayout * GBAqualayout = new QHBoxLayout(0);
 
+            QLabel * frontend = new QLabel(AGGroupBox);
+            frontend->setText(QLabel::tr("Frontend"));
+            frontend->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+            GBAfrontendlayout->addWidget(frontend, 0, 0, 1, 2);
+
             CBFrontendFullscreen = new QCheckBox(AGGroupBox);
-            CBFrontendFullscreen->setText(QCheckBox::tr("Frontend fullscreen"));
-            GBAlayout->addWidget(CBFrontendFullscreen);
+            CBFrontendFullscreen->setText(QCheckBox::tr("Fullscreen"));
+            GBAfrontendlayout->addWidget(CBFrontendFullscreen, 1, 0);
 
             CBFrontendEffects = new QCheckBox(AGGroupBox);
-            CBFrontendEffects->setText(QCheckBox::tr("Frontend effects"));
-            GBAlayout->addWidget(CBFrontendEffects);
+            CBFrontendEffects->setText(QCheckBox::tr("Visual effects"));
+            GBAfrontendlayout->addWidget(CBFrontendEffects, 2, 0);
 
-            CBEnableFrontendSound = new QCheckBox(AGGroupBox);
-            CBEnableFrontendSound->setText(QCheckBox::tr("Enable frontend sounds"));
-            GBAlayout->addWidget(CBEnableFrontendSound);
+            CBFrontendSound = new QCheckBox(AGGroupBox);
+            CBFrontendSound->setText(QCheckBox::tr("Sound"));
+            GBAfrontendlayout->addWidget(CBFrontendSound, 1, 1);
 
-            CBEnableFrontendMusic = new QCheckBox(AGGroupBox);
-            CBEnableFrontendMusic->setText(QCheckBox::tr("Enable frontend music"));
-            GBAlayout->addWidget(CBEnableFrontendMusic);
+            CBFrontendMusic = new QCheckBox(AGGroupBox);
+            CBFrontendMusic->setText(QCheckBox::tr("Music"));
+            GBAfrontendlayout->addWidget(CBFrontendMusic, 2, 1);
+
+            GBAlayout->addLayout(GBAfrontendlayout);
 
             QFrame * hr = new QFrame(AGGroupBox);
             hr->setFrameStyle(QFrame::HLine);
@@ -337,13 +345,15 @@
             volumeBox->setSingleStep(5);
             GBAvollayout->addWidget(volumeBox, 0, 2);
 
-            CBEnableSound = new QCheckBox(AGGroupBox);
-            CBEnableSound->setText(QCheckBox::tr("Enable sound"));
-            GBAvollayout->addWidget(CBEnableSound, 1, 0, 1, 1);
+            CBSound = new QCheckBox(AGGroupBox);
+            CBSound->setText(QCheckBox::tr("Sound"));
+            CBSound->setWhatsThis(QCheckBox::tr("In-game sound effects"));
+            GBAvollayout->addWidget(CBSound, 1, 0);
 
-            CBEnableMusic = new QCheckBox(AGGroupBox);
-            CBEnableMusic->setText(QCheckBox::tr("Enable music"));
-            GBAvollayout->addWidget(CBEnableMusic, 1, 1, 1, 2);
+            CBMusic = new QCheckBox(AGGroupBox);
+            CBMusic->setText(QCheckBox::tr("Music"));
+            CBMusic->setWhatsThis(QCheckBox::tr("In-game music"));
+            GBAvollayout->addWidget(CBMusic, 1, 1, 1, 2);
 
             GBAvollayout->setSizeConstraint(QLayout::SetMinimumSize);
 
--- a/QTfrontend/ui/page/pageoptions.h	Thu Dec 06 00:44:27 2012 +0100
+++ b/QTfrontend/ui/page/pageoptions.h	Thu Dec 06 00:52:50 2012 +0100
@@ -58,10 +58,10 @@
         IconedGroupBox *AGGroupBox;
         QComboBox *CBResolution;
         QComboBox *CBStereoMode;
-        QCheckBox *CBEnableSound;
-        QCheckBox *CBEnableFrontendSound;
-        QCheckBox *CBEnableMusic;
-        QCheckBox *CBEnableFrontendMusic;
+        QCheckBox *CBFrontendSound;
+        QCheckBox *CBFrontendMusic;
+        QCheckBox *CBSound;
+        QCheckBox *CBMusic;
         QCheckBox *CBFullscreen;
         QCheckBox *CBFrontendFullscreen;
         QCheckBox *CBShowFPS;
--- a/hedgewars/uSound.pas	Thu Dec 06 00:44:27 2012 +0100
+++ b/hedgewars/uSound.pas	Thu Dec 06 00:52:50 2012 +0100
@@ -21,7 +21,7 @@
 unit uSound;
 (*
  * This unit controls the sounds and music of the game.
- * Doesn't really do anything if isSoundEnabled = false.
+ * Doesn't really do anything if isSoundEnabled = false and isMusicEnabled = false
  *
  * There are three basic types of sound controls:
  *    Music        - The background music of the game:
@@ -287,19 +287,24 @@
 
 procedure InitSound;
 const channels: LongInt = {$IFDEF MOBILE}1{$ELSE}2{$ENDIF};
+var success: boolean;
 begin
-    if not isSoundEnabled then
+    if not (isSoundEnabled or isMusicEnabled) then
         exit;
     WriteToConsole('Init sound...');
-    isSoundEnabled:= SDL_InitSubSystem(SDL_INIT_AUDIO) >= 0;
+    success:= SDL_InitSubSystem(SDL_INIT_AUDIO) >= 0;
 
-    if isSoundEnabled then
-        isSoundEnabled:= Mix_OpenAudio(44100, $8010, channels, 1024) = 0;
+    if success then
+        success:= Mix_OpenAudio(44100, $8010, channels, 1024) = 0;
 
-    if isSoundEnabled then
+    if success then
         WriteLnToConsole(msgOK)
     else
+    begin
         WriteLnToConsole(msgFailed);
+        isSoundEnabled:= false;
+        isMusicEnabled:= false;
+    end;
 
     WriteToConsole('Init SDL_mixer... ');
     SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, true);
@@ -543,7 +548,7 @@
 procedure PlayMusic;
 var s: shortstring;
 begin
-    if (not isSoundEnabled) or (MusicFN = '') or (not isMusicEnabled) then
+    if (MusicFN = '') or (not isMusicEnabled) then
         exit;
 
     s:= '/Music/' + MusicFN;
@@ -564,7 +569,7 @@
 function ChangeVolume(voldelta: LongInt): LongInt;
 begin
     ChangeVolume:= 0;
-    if (not isSoundEnabled) or ((voldelta = 0) and (not (cInitVolume = 0))) then
+    if not (isSoundEnabled or isMusicEnabled) or ((voldelta = 0) and (not (cInitVolume = 0))) then
         exit;
 
     inc(Volume, voldelta);
@@ -604,7 +609,7 @@
 
 procedure MuteAudio;
 begin
-    if not isSoundEnabled then
+    if not (isSoundEnabled or isMusicEnabled) then
         exit;
 
     if (isAudioMuted) then
@@ -727,7 +732,7 @@
 
 procedure freeModule;
 begin
-    if isSoundEnabled then
+    if isSoundEnabled or isMusicEnabled then
         ReleaseSound(true);
 end;