--- a/QTfrontend/binds.cpp Fri Jul 20 09:09:17 2012 +0400
+++ b/QTfrontend/binds.cpp Fri Jul 20 12:25:53 2012 +0100
@@ -62,6 +62,7 @@
{"confirm", "y", QT_TRANSLATE_NOOP("binds", "confirmation"), NULL, NULL},
{"+voldown", "9", QT_TRANSLATE_NOOP("binds", "volume down"), NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Modify the game's volume while playing:")},
{"+volup", "0", QT_TRANSLATE_NOOP("binds", "volume up"), NULL, NULL},
+ {"mute", "8", QT_TRANSLATE_NOOP("binds", "mute audio"), NULL, NULL},
{"fullscr", "f12", QT_TRANSLATE_NOOP("binds", "change mode"), NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Toggle fullscreen mode:")},
{"capture", "c", QT_TRANSLATE_NOOP("binds", "capture"), NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Take a screenshot:")},
{"rotmask", "delete", QT_TRANSLATE_NOOP("binds", "hedgehogs\ninfo"), NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Toggle labels above hedgehogs:")}
--- a/QTfrontend/binds.h Fri Jul 20 09:09:17 2012 +0400
+++ b/QTfrontend/binds.h Fri Jul 20 12:25:53 2012 +0100
@@ -21,7 +21,7 @@
#include <QString>
-#define BINDS_NUMBER 44
+#define BINDS_NUMBER 45
struct BindAction
{
--- a/hedgewars/uCommandHandlers.pas Fri Jul 20 09:09:17 2012 +0400
+++ b/hedgewars/uCommandHandlers.pas Fri Jul 20 12:25:53 2012 +0100
@@ -856,7 +856,7 @@
RegisterVariable('-volup' , @chVol_m , true );
RegisterVariable('+voldown', @chVol_m , true );
RegisterVariable('-voldown', @chVol_p , true );
- RegisterVariable('findhh' , @chFindhh , true );
+ RegisterVariable('findhh' , @chFindhh , true );
RegisterVariable('pause' , @chPause , true );
RegisterVariable('+cur_u' , @chCurU_p , true );
RegisterVariable('-cur_u' , @chCurU_m , true );
--- a/hedgewars/uInputHandler.pas Fri Jul 20 09:09:17 2012 +0400
+++ b/hedgewars/uInputHandler.pas Fri Jul 20 12:25:53 2012 +0100
@@ -248,6 +248,7 @@
DefaultBinds[KeyNameToCode(_S'0')]:= '+volup';
DefaultBinds[KeyNameToCode(_S'9')]:= '+voldown';
+DefaultBinds[KeyNameToCode(_S'8')]:= 'mute';
DefaultBinds[KeyNameToCode(_S'c')]:= 'capture';
DefaultBinds[KeyNameToCode(_S'h')]:= 'findhh';
DefaultBinds[KeyNameToCode(_S'p')]:= 'pause';
--- a/hedgewars/uSound.pas Fri Jul 20 09:09:17 2012 +0400
+++ b/hedgewars/uSound.pas Fri Jul 20 12:25:53 2012 +0100
@@ -47,7 +47,7 @@
// Obvious music commands for music track
procedure SetMusic(enabled: boolean); // Enable/disable music.
-procedure SetMusicName(musicname: shortstring); // Enable/disable music and set name of musicfile to play.
+procedure SetMusicName(musicname: shortstring); // Enable/disable music and set name of the file to play.
procedure PlayMusic; // Play music from the start.
procedure PauseMusic; // Pause music.
procedure ResumeMusic; // Resume music from pause point.
@@ -82,6 +82,16 @@
procedure PlayNextVoice;
+// GLOBAL FUNCTIONS
+
+// Drastically lower the volume when we lose focus (and restore the previous value).
+procedure DampenAudio;
+procedure UndampenAudio;
+
+// Mute/Unmute audio
+procedure MuteAudio;
+
+
// MISC
// Set the initial volume
@@ -93,25 +103,22 @@
// Returns a pointer to the voicepack with the given name.
function AskForVoicepack(name: shortstring): Pointer;
-// Drastically lower the volume when we lose focus (and restore the previous value).
-procedure DampenAudio;
-procedure UndampenAudio;
implementation
uses uVariables, uConsole, uUtils, uCommands, uDebug;
const chanTPU = 32;
var Volume: LongInt;
+ cInitVolume: LongInt;
+ previousVolume: LongInt; // cached volume value
lastChan: array [TSound] of LongInt;
voicepacks: array[0..cMaxTeams] of TVoicepack;
defVoicepack: PVoicepack;
- Mus: PMixMusic = nil;
+ Mus: PMixMusic = nil; // music pointer
MusicFN: shortstring; // music file name
- previousVolume: LongInt; // cached volume value
isMusicEnabled: boolean;
isSoundEnabled: boolean;
isSEBackup: boolean;
- cInitVolume: LongInt;
function AskForVoicepack(name: shortstring): Pointer;
@@ -180,7 +187,7 @@
WriteLnToConsole(msgOK);
Mix_AllocateChannels(Succ(chanTPU));
- ChangeVolume(cInitVolume);
+ ChangeVolume(cInitVolume);
end;
procedure ResetSound;
@@ -446,7 +453,7 @@
function ChangeVolume(voldelta: LongInt): LongInt;
begin
ChangeVolume:= 0;
- if not isSoundEnabled then
+ if (not isSoundEnabled) or (voldelta = 0) then
exit;
inc(Volume, voldelta);
@@ -458,20 +465,52 @@
Volume:= Mix_Volume(-1, -1);
if isMusicEnabled then
Mix_VolumeMusic(Volume * 4 div 8);
- ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME
+ ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME;
+
+ if (isMusicEnabled) then
+ if (Volume = 0) then
+ PauseMusic
+ else
+ ResumeMusic;
+
+ isAudioMuted:= (Volume = 0);
end;
procedure DampenAudio;
begin
+ if (isAudioMuted) then
+ exit;
previousVolume:= Volume;
ChangeVolume(-Volume * 7 div 9);
end;
procedure UndampenAudio;
begin
+ if (isAudioMuted) then
+ exit;
ChangeVolume(previousVolume - Volume);
end;
+procedure MuteAudio;
+begin
+ if (not isSoundEnabled) then
+ exit;
+
+ if (isAudioMuted) then
+ begin
+ ResumeMusic;
+ ChangeVolume(previousVolume);
+ end
+ else
+ begin
+ PauseMusic;
+ previousVolume:= Volume;
+ ChangeVolume(-Volume);
+ end;
+
+ // isAudioMuted is updated in ChangeVolume
+end;
+
procedure SetMusic(enabled: boolean);
begin
isMusicEnabled:= enabled;
@@ -534,15 +573,23 @@
CurrentTeam^.voicepack:= AskForVoicepack(s)
end;
+procedure chMute(var s: shortstring);
+begin
+ s:= s; // avoid compiler hint
+ MuteAudio;
+end;
+
procedure initModule;
var t: LongInt;
i: TSound;
begin
RegisterVariable('voicepack', @chVoicepack, false);
+ RegisterVariable('mute' , @chMute , true );
MusicFN:='';
isMusicEnabled:= true;
isSoundEnabled:= true;
+ isAudioMuted:= false;
isSEBackup:= isSoundEnabled;
cInitVolume:= 100;
Volume:= 0;
--- a/hedgewars/uTypes.pas Fri Jul 20 09:09:17 2012 +0400
+++ b/hedgewars/uTypes.pas Fri Jul 20 12:25:53 2012 +0100
@@ -408,12 +408,13 @@
sidLaserSight, sidVampiric, sidSniperRifle, sidJetpack,
sidMolotov, sidBirdy, sidPortalGun, sidPiano, sidGasBomb, sidSineGun, sidFlamethrower,
sidSMine, sidHammer, sidResurrector, sidDrillStrike, sidSnowball, sidNothing, sidTardis,
- sidStructure, sidLandGun, sidIceGun);
+ sidStructure, sidLandGun, sidIceGun);
TMsgStrId = (sidStartFight, sidDraw, sidWinner, sidVolume, sidPaused,
sidConfirm, sidSuddenDeath, sidRemaining, sidFuel, sidSync,
sidNoEndTurn, sidNotYetAvailable, sidRoundSD, sidRoundsSD, sidReady,
- sidBounce1, sidBounce2, sidBounce3, sidBounce4, sidBounce5, sidBounce);
+ sidBounce1, sidBounce2, sidBounce3, sidBounce4, sidBounce5, sidBounce,
+ sidMute);
// Events that are important for the course of the game or at least interesting for other reasons
TEventId = (eidDied, eidDrowned, eidRoundStart, eidRoundWin, eidRoundDraw,
@@ -423,7 +424,8 @@
TGoalStrId = (gidCaption, gidSubCaption, gidForts, gidLowGravity, gidInvulnerable,
gidVampiric, gidKarma, gidKing, gidPlaceHog, gidArtillery,
gidSolidLand, gidSharedAmmo, gidMineTimer, gidNoMineTimer, gidRandomMineTimer,
- gidDamageModifier, gidResetHealth, gidAISurvival, gidInfAttack, gidResetWeps, gidPerHogAmmo, gidTagTeam);
+ gidDamageModifier, gidResetHealth, gidAISurvival, gidInfAttack, gidResetWeps,
+ gidPerHogAmmo, gidTagTeam);
TLandArray = packed array of array of LongWord;
TCollisionArray = packed array of array of Word;
--- a/hedgewars/uVariables.pas Fri Jul 20 09:09:17 2012 +0400
+++ b/hedgewars/uVariables.pas Fri Jul 20 12:25:53 2012 +0100
@@ -99,6 +99,7 @@
cWaterLine : Word;
cGearScrEdgesDist: LongInt;
+ isAudioMuted : boolean;
// originally typed consts
ExplosionBorderColor: LongWord;
--- a/hedgewars/uWorld.pas Fri Jul 20 09:09:17 2012 +0400
+++ b/hedgewars/uWorld.pas Fri Jul 20 12:25:53 2012 +0100
@@ -1114,6 +1114,7 @@
highlight: Boolean;
smallScreenOffset, offsetX, offsetY, screenBottom: LongInt;
VertexBuffer: array [0..3] of TVertex2f;
+ volume: LongInt;
begin
if (cReducedQuality and rqNoBackground) = 0 then
begin
@@ -1526,14 +1527,18 @@
end;
if SoundTimerTicks >= 50 then
- begin
- SoundTimerTicks:= 0;
- if cVolumeDelta <> 0 then
- begin
- str(ChangeVolume(cVolumeDelta), s);
- AddCaption(Format(trmsg[sidVolume], s), cWhiteColor, capgrpVolume)
- end
- end;
+begin
+ SoundTimerTicks:= 0;
+ if cVolumeDelta <> 0 then
+ begin
+ str(ChangeVolume(cVolumeDelta), s);
+ AddCaption(Format(trmsg[sidVolume], s), cWhiteColor, capgrpVolume);
+ end;
+ if isAudioMuted then
+ AddCaption(trmsg[sidMute], cWhiteColor, capgrpVolume)
+ else
+ FreeTexture(Captions[capgrpVolume].Tex)
+end;
if GameState = gsConfirm then
DrawTextureCentered(0, (cScreenHeight shr 1), ConfirmTexture);
--- a/share/hedgewars/Data/Locale/en.txt Fri Jul 20 09:09:17 2012 +0400
+++ b/share/hedgewars/Data/Locale/en.txt Fri Jul 20 12:25:53 2012 +0100
@@ -79,6 +79,7 @@
01:18=High
01:19=Extreme
01:20=%1 Bounce
+01:21=Audio Muted
; Event messages
; Hog (%1) died