- Some improvements to volume control
authorunc0rr
Wed, 27 Sep 2006 20:52:22 +0000
changeset 175 d226d976d836
parent 174 0b2c5b22f644
child 176 533d03041dcd
- Some improvements to volume control - Simplified captions
hedgewars/CCHandlers.inc
hedgewars/uConsole.pas
hedgewars/uKeys.pas
hedgewars/uLocale.pas
hedgewars/uSound.pas
hedgewars/uWorld.pas
share/hedgewars/Data/Locale/en.txt
share/hedgewars/Data/Locale/ru.txt
--- a/hedgewars/CCHandlers.inc	Wed Sep 27 20:13:29 2006 +0000
+++ b/hedgewars/CCHandlers.inc	Wed Sep 27 20:52:22 2006 +0000
@@ -402,23 +402,13 @@
 SDL_ShowCursor(0)
 end;
 
-procedure chVolUp_p(var s: shortstring);
+procedure chVol_p(var s: shortstring);
 begin
-cVolumeDelta:= 3
-end;
-
-procedure chVolUp_m(var s: shortstring);
-begin
-cVolumeDelta:= 0
+inc(cVolumeDelta, 3)
 end;
 
-procedure chVolDown_p(var s: shortstring);
+procedure chVol_m(var s: shortstring);
 begin
-cVolumeDelta:= -3
+dec(cVolumeDelta, 3)
 end;
 
-procedure chVolDown_m(var s: shortstring);
-begin
-cVolumeDelta:= 0
-end;
-
--- a/hedgewars/uConsole.pas	Wed Sep 27 20:13:29 2006 +0000
+++ b/hedgewars/uConsole.pas	Wed Sep 27 20:52:22 2006 +0000
@@ -312,10 +312,10 @@
 RegisterVariable('ljump'   , vtCommand, @chLJump        , false);
 RegisterVariable('hjump'   , vtCommand, @chHJump        , false);
 RegisterVariable('fullscr' , vtCommand, @chFullScr      , true );
-RegisterVariable('+volup'  , vtCommand, @chVolUp_p      , true );
-RegisterVariable('-volup'  , vtCommand, @chVolUp_m      , true );
-RegisterVariable('+voldown', vtCommand, @chVolDown_p    , true );
-RegisterVariable('-voldown', vtCommand, @chVolDown_m    , true );
+RegisterVariable('+volup'  , vtCommand, @chVol_p        , true );
+RegisterVariable('-volup'  , vtCommand, @chVol_m        , true );
+RegisterVariable('+voldown', vtCommand, @chVol_m        , true );
+RegisterVariable('-voldown', vtCommand, @chVol_p        , true );
 
 finalization
 FreeVariablesList
--- a/hedgewars/uKeys.pas	Wed Sep 27 20:13:29 2006 +0000
+++ b/hedgewars/uKeys.pas	Wed Sep 27 20:52:22 2006 +0000
@@ -127,6 +127,8 @@
     end;
 
 DefaultBinds[ 27]:= 'quit';
+DefaultBinds[ 48]:= '+volup';
+DefaultBinds[ 57]:= '+voldown';
 DefaultBinds[ 99]:= 'capture';
 DefaultBinds[102]:= 'fullscr';
 SetDefaultBinds
--- a/hedgewars/uLocale.pas	Wed Sep 27 20:13:29 2006 +0000
+++ b/hedgewars/uLocale.pas	Wed Sep 27 20:52:22 2006 +0000
@@ -36,7 +36,7 @@
 type TAmmoStrId = (sidGrenade, sidClusterBomb, sidBazooka, sidUFO, sidShotgun,
                    sidPickHammer, sidSkip, sidRope, sidMine, sidDEagle,
                    sidDynamite, sidBaseballBat, sidFirePunch, sidSeconds);
-     TMsgStrId = (sidStartFight, sidDraw, sidWinner);
+     TMsgStrId = (sidStartFight, sidDraw, sidWinner, sidVolume);
 var trammo: array[TAmmoStrId] of string;
     trmsg: array[TMsgStrId] of string;
 
--- a/hedgewars/uSound.pas	Wed Sep 27 20:13:29 2006 +0000
+++ b/hedgewars/uSound.pas	Wed Sep 27 20:52:22 2006 +0000
@@ -122,7 +122,9 @@
 begin
 inc(Volume, voldelta);
 if Volume < 0 then Volume:= 0;
-Volume:= Mix_Volume(-1, Volume);
+Mix_Volume(-1, Volume);
+Volume:= Mix_Volume(-1, -1);
+Mix_VolumeMusic(Volume * 3 div 8);
 Result:= Volume * 100 div MIX_MAX_VOLUME
 end;
 
--- a/hedgewars/uWorld.pas	Wed Sep 27 20:13:29 2006 +0000
+++ b/hedgewars/uWorld.pas	Wed Sep 27 20:52:22 2006 +0000
@@ -61,12 +61,11 @@
 
 type TCaptionStr = record
                    Surf: PSDL_Surface;
-                   Group: TCapGroup;
                    EndTime: LongWord;
                    end;
 
 var cWaterSprCount: integer;
-    Captions: array[0..Pred(cMaxCaptions)] of TCaptionStr;
+    Captions: array[TCapGroup] of TCaptionStr;
     AMxLeft, AMxCurr, SlotsNum: integer;
 
 procedure InitWorld;
@@ -169,6 +168,7 @@
     r: TSDL_Rect;
     team: PTeam;
     tdx, tdy: Double;
+    grp: TCapGroup;
     s: string[15];
 
     procedure DrawRepeated(spr: TSprite; Shift: integer);
@@ -303,22 +303,20 @@
 if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0, Surface);
 
 // Captions
-i:= 0;
-while (i < cMaxCaptions) do
-    begin
-    with Captions[i] do
+i:= 8;
+for grp:= Low(TCapGroup) to High(TCapGroup) do
+    with Captions[grp] do
          if EndTime > 0 then
-            DrawCentered(cScreenWidth div 2, 8 + i * (Surf.h + 2) + cConsoleYAdd, Surf, Surface);
-    inc(i)
-    end;
-while (Captions[0].EndTime > 0) and (Captions[0].EndTime <= RealTicks) do
-    begin
-    SDL_FreeSurface(Captions[0].Surf);
-    Captions[0].Surf:= nil;
-    for i:= 1 to Pred(cMaxCaptions) do
-        Captions[Pred(i)]:= Captions[i];
-    Captions[Pred(cMaxCaptions)].EndTime:= 0
-    end;
+            begin
+            DrawCentered(cScreenWidth div 2, i + cConsoleYAdd, Surf, Surface);
+            inc(i, Surf.h + 2);
+            if EndTime <= RealTicks then
+               begin
+               SDL_FreeSurface(Surf);
+               Surf:= nil;
+               EndTime:= 0
+               end
+            end;
 
 // Teams Healths
 team:= TeamsList;
@@ -401,45 +399,18 @@
    if cVolumeDelta <> 0 then
       begin
       str(ChangeVolume(cVolumeDelta), s);
-      AddCaption(Format('Volume %1%', s), $FFFFFF, capgrpVolume)
+      AddCaption(Format(trmsg[sidVolume], s), $FFFFFF, capgrpVolume)
       end
    end
 end;
 
 procedure AddCaption(s: string; Color: Longword; Group: TCapGroup);
-var i, m: LongWord;
 begin
 if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s);
-i:= 0;
-while (i < cMaxCaptions) and (Captions[i].Group <> Group) do inc(i);
-if i < cMaxCaptions then
-   begin
-   SDL_FreeSurface(Captions[i].Surf);
-   while (i < Pred(cMaxCaptions)) do
-         begin
-         Captions[i]:= Captions[Succ(i)];
-         inc(i)
-         end;
-   Captions[Pred(cMaxCaptions)].EndTime:= 0
-   end;
-   
-if Captions[Pred(cMaxCaptions)].EndTime > 0 then
-   begin
-   SDL_FreeSurface(Captions[0].Surf);
-   m:= Pred(cMaxCaptions);
-   for i:= 1 to m do
-       Captions[Pred(i)]:= Captions[i];
-   Captions[m].EndTime:= 0
-   end else
-   begin
-   m:= 0;
-   while (m < cMaxCaptions)and(Captions[m].EndTime > 0) do inc(m)
-   end;
+if Captions[Group].Surf <> nil then SDL_FreeSurface(Captions[Group].Surf);
 
-
-Captions[m].Surf:= RenderString(s, Color, fntBig);
-Captions[m].Group:= Group;
-Captions[m].EndTime:= RealTicks + 1200
+Captions[Group].Surf:= RenderString(s, Color, fntBig);
+Captions[Group].EndTime:= RealTicks + 1200
 end;
 
 procedure MoveCamera;
--- a/share/hedgewars/Data/Locale/en.txt	Wed Sep 27 20:13:29 2006 +0000
+++ b/share/hedgewars/Data/Locale/en.txt	Wed Sep 27 20:52:22 2006 +0000
@@ -17,4 +17,5 @@
 
 01:00=Let's fight!
 01:01=Round draw
-01:02=%1 wins!
\ No newline at end of file
+01:02=%1 wins!
+01:03=Volume %1%
\ No newline at end of file
--- a/share/hedgewars/Data/Locale/ru.txt	Wed Sep 27 20:13:29 2006 +0000
+++ b/share/hedgewars/Data/Locale/ru.txt	Wed Sep 27 20:52:22 2006 +0000
@@ -17,4 +17,5 @@
 
 01:00=Вперёд к победе!
 01:01=Ничья
-01:02=Победила команда %1!
\ No newline at end of file
+01:02=Победила команда %1!
+01:03=Громкость %1%
\ No newline at end of file