Fix volume caption not being shown when hitting mute key
authorWuzzy <Wuzzy2@mail.ru>
Tue, 20 Feb 2018 17:52:22 +0100
changeset 13039 aed4b25ff242
parent 13038 356995c8c48b
child 13040 a87d3119c962
Fix volume caption not being shown when hitting mute key
ChangeLog.txt
hedgewars/uCommandHandlers.pas
hedgewars/uGame.pas
hedgewars/uSound.pas
hedgewars/uVariables.pas
--- a/ChangeLog.txt	Tue Feb 20 15:37:36 2018 +0100
+++ b/ChangeLog.txt	Tue Feb 20 17:52:22 2018 +0100
@@ -12,6 +12,7 @@
  + Hedgehog tag translucency is now changed with [Switch] + [Change hedgehog tags]
  * Fix time box being usable in Sudden Death with 0 health decrease
  * Fix chat input key being sometimes registered twice
+ * Fix not displaying current volume status after pressing mute key
 
 Frontend:
  + Schemes are now stored in separate files under Schemes
--- a/hedgewars/uCommandHandlers.pas	Tue Feb 20 15:37:36 2018 +0100
+++ b/hedgewars/uCommandHandlers.pas	Tue Feb 20 17:52:22 2018 +0100
@@ -569,6 +569,12 @@
 dec(cVolumeDelta, 3)
 end;
 
+procedure chMute(var s: shortstring);
+begin
+s:= s; // avoid compiler hint
+cMuteToggle:= true;
+end;
+
 procedure chFindhh(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
@@ -901,6 +907,7 @@
     RegisterVariable('-volup'  , @chVol_m        , true );
     RegisterVariable('+voldown', @chVol_m        , true );
     RegisterVariable('-voldown', @chVol_p        , true );
+    RegisterVariable('mute'    , @chMute         , true );
     RegisterVariable('findhh'  , @chFindhh       , true );
     RegisterVariable('pause'   , @chPause        , true );
     RegisterVariable('+cur_u'  , @chCurU_p       , true );
--- a/hedgewars/uGame.pas	Tue Feb 20 15:37:36 2018 +0100
+++ b/hedgewars/uGame.pas	Tue Feb 20 17:52:22 2018 +0100
@@ -93,6 +93,18 @@
             s:= ansistring(inttostr(i));
             AddCaption(FormatA(trmsg[sidVolume], s), cWhiteColor, capgrpVolume)
             end
+        end
+    else if cMuteToggle then
+        begin
+        MuteAudio;
+        if isAudioMuted then
+            AddCaption(trmsg[sidMute], cWhiteColor, capgrpVolume)
+        else
+            begin
+            s:= ansistring(inttostr(GetVolumePercent()));
+            AddCaption(FormatA(trmsg[sidVolume], s), cWhiteColor, capgrpVolume);
+            end;
+        cMuteToggle:= false;
         end;
     end;
 PlayNextVoice;
--- a/hedgewars/uSound.pas	Tue Feb 20 15:37:36 2018 +0100
+++ b/hedgewars/uSound.pas	Tue Feb 20 17:52:22 2018 +0100
@@ -101,6 +101,9 @@
 // Modifies the sound volume of the game by voldelta and returns the new volume level.
 function  ChangeVolume(voldelta: LongInt): LongInt;
 
+// Returns the current volume in percent
+function  GetVolumePercent(): LongInt;
+
 // Returns a pointer to the voicepack with the given name.
 function  AskForVoicepack(name: shortstring): Pointer;
 
@@ -672,6 +675,11 @@
     cInitVolume:= vol;
 end;
 
+function GetVolumePercent(): LongInt;
+begin
+    GetVolumePercent:= Volume * 100 div MIX_MAX_VOLUME;
+end;
+
 function ChangeVolume(voldelta: LongInt): LongInt;
 begin
     ChangeVolume:= 0;
@@ -687,7 +695,7 @@
     Volume:= Mix_Volume(-1, -1);
     if isMusicEnabled then
         Mix_VolumeMusic(Volume * 4 div 8);
-    ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME;
+    ChangeVolume:= GetVolumePercent();
 
     if (isMusicEnabled) then
         if (Volume = 0) then
@@ -793,12 +801,6 @@
     CurrentTeam^.voicepack:= AskForVoicepack(s)
 end;
 
-procedure chMute(var s: shortstring);
-begin
-    s:= s; // avoid compiler hint
-    MuteAudio;
-end;
-
 procedure preInitModule;
 begin
     isMusicEnabled:= true;
@@ -811,7 +813,6 @@
     i: TSound;
 begin
     RegisterVariable('voicepack', @chVoicepack, false);
-    RegisterVariable('mute'     , @chMute     , true );
 
     MusicFN:='';
     SDMusicFN:= 'sdmusic.ogg';
--- a/hedgewars/uVariables.pas	Tue Feb 20 15:37:36 2018 +0100
+++ b/hedgewars/uVariables.pas	Tue Feb 20 17:52:22 2018 +0100
@@ -166,6 +166,7 @@
     cScriptParam    : shortstring;
     cSeed           : shortstring;
     cVolumeDelta    : LongInt;
+    cMuteToggle     : boolean; // Mute toggle requested
     cHasFocus       : boolean;
     cInactDelay     : Longword;
 
@@ -2837,6 +2838,7 @@
     autoCameraOn    := true;
     cSeed           := '';
     cVolumeDelta    := 0;
+    cMuteToggle     := false;
     cHasFocus       := true;
     cInactDelay     := 100;
     ReadyTimeLeft   := 0;