Ammo menu now works!
authorunc0rr
Sun, 24 Sep 2006 18:29:14 +0000
changeset 162 4822f6face35
parent 161 d8870bbf960e
child 163 f864a68e512c
Ammo menu now works!
hedgewars/CCHandlers.inc
hedgewars/uConsts.pas
hedgewars/uGame.pas
hedgewars/uTeams.pas
hedgewars/uWorld.pas
share/hedgewars/Data/Graphics/AmmoMenu/CMakeLists.txt
share/hedgewars/Data/Graphics/AmmoMenu/Selection.png
--- a/hedgewars/CCHandlers.inc	Sat Sep 23 19:26:07 2006 +0000
+++ b/hedgewars/CCHandlers.inc	Sun Sep 24 18:29:14 2006 +0000
@@ -306,7 +306,6 @@
                 caSlot^:= slot;
                 caAmmo^:= 0;
                 end;
-          TargetPoint.X:= NoPointX;
           end;
      ApplyAmmoChanges(Hedgehogs[CurrHedgehog])
      end
@@ -315,6 +314,11 @@
 procedure chPut(var s: shortstring);
 begin
 if CheckNoTeamOrHH then exit;
+if bShowAmmoMenu then
+   begin
+   bSelected:= true;
+   exit
+   end;
 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do
      if (State and gstHHChooseTarget) <> 0 then
         begin
@@ -375,6 +379,7 @@
 with CurrentTeam^ do
      with Hedgehogs[CurrHedgehog] do
           begin
+          bSelected:= false;
           if bShowAmmoMenu then bShowAmmoMenu:= false
           else if ((Gear.State and (gstAttacking or gstAttacked)) <> 0) or (AttacksNum > 0)
                or ((Gear.State and gstHHDriven) = 0) then else bShowAmmoMenu:= true
--- a/hedgewars/uConsts.pas	Sat Sep 23 19:26:07 2006 +0000
+++ b/hedgewars/uConsts.pas	Sun Sep 24 18:29:14 2006 +0000
@@ -48,7 +48,7 @@
                    sprMineOn, sprCase, sprFAid, sprDynamite, sprPower,
                    sprClusterBomb, sprClusterParticle, sprFlame, sprHorizont,
                    sprSky, sprAMBorders, sprAMSlot, sprAMSlotName, sprAMAmmos,
-                   sprAMSlotKeys);
+                   sprAMSlotKeys, sprAMSelection);
      TGearType  = (gtCloud, gtAmmo_Bomb, gtHedgehog, gtAmmo_Grenade, gtHealthTag,
                    gtGrave, gtUFO, gtShotgunShot, gtPickHammer, gtRope,
                    gtSmokeTrace, gtExplosion, gtMine, gtCase, gtDEagleShot, gtDynamite,
@@ -256,7 +256,8 @@
                      (FileName:      'Slot'; Path: ptAmmoMenu; Width: 202; Height: 33; hasAlpha: false),// sprAMSlot
                      (FileName:  'AmmoName'; Path: ptAmmoMenu; Width: 202; Height: 33; hasAlpha: false),// sprAMSlotName
                      (FileName:     'Ammos'; Path: ptAmmoMenu; Width:  32; Height: 32; hasAlpha: false),// sprAMAmmos
-                     (FileName:  'SlotKeys'; Path: ptAmmoMenu; Width:  32; Height: 32; hasAlpha: false) // sprAMSlotKeys
+                     (FileName:  'SlotKeys'; Path: ptAmmoMenu; Width:  32; Height: 32; hasAlpha: false),// sprAMSlotKeys
+                     (FileName: 'Selection'; Path: ptAmmoMenu; Width:  32; Height: 32; hasAlpha: false) // sprAMSelection
                      );
       Soundz: array[TSound] of record
                                        FileName: String[31];
--- a/hedgewars/uGame.pas	Sat Sep 23 19:26:07 2006 +0000
+++ b/hedgewars/uGame.pas	Sun Sep 24 18:29:14 2006 +0000
@@ -94,9 +94,7 @@
           else ProcessGears
        end;
     inc(i)
-    end;
-
-MoveCamera
+    end
 end;
 
 end.
--- a/hedgewars/uTeams.pas	Sat Sep 23 19:26:07 2006 +0000
+++ b/hedgewars/uTeams.pas	Sun Sep 24 18:29:14 2006 +0000
@@ -243,6 +243,8 @@
 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
 var s: shortstring;
 begin
+TargetPoint.X:= NoPointX;
+
 with Hedgehog do
      begin
      if Ammo[CurSlot, CurAmmo].Count = 0 then
--- a/hedgewars/uWorld.pas	Sat Sep 23 19:26:07 2006 +0000
+++ b/hedgewars/uWorld.pas	Sun Sep 24 18:29:14 2006 +0000
@@ -41,7 +41,6 @@
 procedure InitWorld;
 procedure DrawWorld(Lag: integer; Surface: PSDL_Surface);
 procedure AddCaption(s: string; Color: Longword; Group: TCapGroup);
-procedure MoveCamera;
 
 {$IFDEF COUNTTICKS}
 var cntTicks: LongWord;
@@ -49,9 +48,10 @@
 var FollowGear: PGear = nil;
     WindBarWidth: integer = 0;
     bShowAmmoMenu: boolean = false;
+    bSelected: boolean = false;
 
 implementation
-uses uStore, uMisc, uTeams, uIO, uConsole, uKeys;
+uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale;
 const RealTicks: Longword = 0;
       Frames: Longword = 0;
       FPS: Longword = 0;
@@ -67,7 +67,7 @@
 
 var cWaterSprCount: integer;
     Captions: array[0..Pred(cMaxCaptions)] of TCaptionStr;
-    AMxLeft, AMxCurr: integer;
+    AMxLeft, AMxCurr, SlotsNum: integer;
 
 procedure InitWorld;
 begin
@@ -85,15 +85,19 @@
 procedure ShowAmmoMenu(Surface: PSDL_Surface);
 const MENUSPEED = 15;
 var x, y, i, t: integer;
+    Slot, Pos: integer;
 begin
 if (TurnTimeLeft = 0) or KbdKeyPressed then bShowAmmoMenu:= false;
 if      bShowAmmoMenu  and (AMxCurr > AMxLeft)      then dec(AMxCurr, MENUSPEED);
 if (not bShowAmmoMenu) and (AMxCurr < cScreenWidth) then inc(AMxCurr, MENUSPEED);
 
 if CurrentTeam = nil then exit;
+Slot:= 0;
+Pos:= -1;
 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
      begin
      if Ammo = nil then exit;
+     SlotsNum:= 0;
      x:= AMxCurr;
      y:= cScreenHeight - 40;
      dec(y);
@@ -105,21 +109,48 @@
      for i:= cMaxSlotIndex downto 0 do
          if Ammo[i, 0].Count > 0 then
             begin
+            if (CursorPoint.Y >= y - 33) and (CursorPoint.Y < y) then Slot:= i;
             dec(y, 33);
+            inc(SlotsNum);
             DrawSprite(sprAMSlot, x, y, 0, Surface);
             DrawSprite(sprAMSlotKeys, x + 2, y + 1, i, Surface);
             t:= 0;
             while (t <= cMaxSlotAmmoIndex) and (Ammo[i, t].Count > 0) do
                   begin
                   DrawSprite(sprAMAmmos, x + t * 33 + 35, y + 1, integer(Ammo[i, t].AmmoType), Surface);
+                  if (Slot = i) and (CursorPoint.X >= x + t * 33 + 35) and (CursorPoint.X < x + t * 33 + 68) then
+                     begin
+                     DrawSprite(sprAMSelection, x + t * 33 + 35, y + 1, 0, Surface);
+                     Pos:= t;
+                     end;
                   inc(t)
                   end
             end;
      dec(y, 1);
-     DrawSprite(sprAMBorders, x, y, 0, Surface)
-     end
+     DrawSprite(sprAMBorders, x, y, 0, Surface);
+
+     if (Pos >= 0) then
+        if Ammo[Slot, Pos].Count > 0 then
+           begin
+           DXOutText(AMxCurr + 10, cScreenHeight - 68, fnt16, trAmmo[Ammoz[Ammo[Slot, Pos].AmmoType].NameId], Surface);
+           if Ammo[Slot, Pos].Count < 10 then
+              DXOutText(AMxCurr + 175, cScreenHeight - 68, fnt16, chr(Ammo[Slot, Pos].Count + 48) + 'x', Surface);
+           if bSelected then
+              begin
+              CurSlot:= Slot;
+              CurAmmo:= Pos;
+              ApplyAmmoChanges(CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog]);
+              bShowAmmoMenu:= false
+              end;
+           end;
+     end;
+
+bSelected:= false;
+DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface)
 end;
 
+procedure MoveCamera; forward;
+
 procedure DrawWorld(Lag: integer; Surface: PSDL_Surface);
 var i, t: integer;
     r: TSDL_Rect;
@@ -139,6 +170,8 @@
     end;
 
 begin
+MoveCamera;
+
 // Sky
 inc(RealTicks, Lag);
 if WorldDy > 0 then
@@ -406,6 +439,17 @@
 
 if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit;
 
+if AMxCurr < cScreenWidth then
+   begin
+   if CursorPoint.X < AMxCurr + 35 then CursorPoint.X:= AMxCurr + 35;
+   if CursorPoint.X > AMxCurr + 200 then CursorPoint.X:= AMxCurr + 200;
+   if CursorPoint.Y < cScreenHeight - 75 - SlotsNum * 33 then CursorPoint.Y:= cScreenHeight - 75 - SlotsNum * 33;
+   if CursorPoint.Y > cScreenHeight - 76 then CursorPoint.Y:= cScreenHeight - 76;
+   prevPoint:= CursorPoint;
+   SDL_WarpMouse(CursorPoint.X, CursorPoint.Y);
+   exit
+   end;
+
 if isCursorVisible then
    begin
    if (not CurrentTeam.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
--- a/share/hedgewars/Data/Graphics/AmmoMenu/CMakeLists.txt	Sat Sep 23 19:26:07 2006 +0000
+++ b/share/hedgewars/Data/Graphics/AmmoMenu/CMakeLists.txt	Sun Sep 24 18:29:14 2006 +0000
@@ -1,5 +1,8 @@
 install(FILES
 	AmmoName.png
+	Ammos.png
 	BrdrLines.png
+	Selection.png
 	Slot.png
+	SlotKeys.png
 	DESTINATION ${SHAREPATH}Data/Graphics/AmmoMenu)
\ No newline at end of file
Binary file share/hedgewars/Data/Graphics/AmmoMenu/Selection.png has changed