make using hog speech a bit more comfortable
authorsheepluva
Sun, 22 Mar 2015 21:40:16 +0100
changeset 10866 c1f75780c56f
parent 10865 a587145ced34
child 10867 36ca7a39f34d
make using hog speech a bit more comfortable
hedgewars/uChat.pas
hedgewars/uGears.pas
hedgewars/uGearsRender.pas
hedgewars/uVariables.pas
--- a/hedgewars/uChat.pas	Fri Mar 20 15:00:52 2015 -0400
+++ b/hedgewars/uChat.pas	Sun Mar 22 21:40:16 2015 +0100
@@ -98,6 +98,11 @@
 const Padding  = 2;
       ClHeight = 2 * Padding + 16; // font height
 
+function charIsForHogSpeech(c: char): boolean;
+begin
+exit((c = '"') or (c = '''') or (c = '-'));
+end;
+
 procedure ResetSelection();
 begin
     selectedPos:= -1;
@@ -279,6 +284,7 @@
 procedure DrawChat;
 var i, t, left, top, cnt: LongInt;
     selRect: TSDL_Rect;
+    c: char;
 begin
 ChatReady:= true; // maybe move to somewhere else?
 
@@ -332,7 +338,27 @@
         end;
 
     dec(left, InputLinePrefix.Width);
-    end;
+
+
+    if (Length(InputStr.s) > 0) and ((CursorPos = 1) or (CursorPos = 2)) then
+        begin
+        c:= InputStr.s[1];
+        if charIsForHogSpeech(c) then
+            begin
+            SpeechHogNumber:= 1;
+            if Length(InputStr.s) > 1 then
+                begin
+                c:= InputStr.s[2];
+                if (c > '0') and (c < '9') then
+                    SpeechHogNumber:= byte(c) - 48;
+                end;
+            end;
+        end
+    else
+        SpeechHogNumber:= 0;
+    end
+else
+    SpeechHogNumber:= 0;
 
 // draw chat lines
 if ((not ChatHidden) or showAll) and (UIDisplay <> uiNone) then
@@ -1028,7 +1054,15 @@
         if Length(InputStr.s) + btw > MaxInputStrLen then
             exit;
 
-        InsertIntoInputStr(utf8);
+        if (Length(InputStr.s) = 0) and (Length(utf8) = 1) and (charIsForHogSpeech(utf8[1])) then
+            begin
+            InsertIntoInputStr(utf8);
+            InsertIntoInputStr(utf8);
+            cursorPos:= 1;
+            UpdateCursorCoords();
+            end
+        else
+            InsertIntoInputStr(utf8);
         end
 end;
 
--- a/hedgewars/uGears.pas	Fri Mar 20 15:00:52 2015 -0400
+++ b/hedgewars/uGears.pas	Sun Mar 22 21:40:16 2015 +0100
@@ -551,6 +551,9 @@
         end;
     Gear:= Gear^.NextGear
     end;
+
+if SpeechHogNumber > 0 then
+    DrawHHOrder();
 end;
 
 procedure FreeGearsList;
--- a/hedgewars/uGearsRender.pas	Fri Mar 20 15:00:52 2015 -0400
+++ b/hedgewars/uGearsRender.pas	Sun Mar 22 21:40:16 2015 +0100
@@ -36,6 +36,7 @@
             rounded   : array[0..MAXROPEPOINTS + 2] of TVertex2f;
          end;
 procedure RenderGear(Gear: PGear; x, y: LongInt);
+procedure DrawHHOrder();
 
 var RopePoints: record
                 Count: Longword;
@@ -215,6 +216,48 @@
     end;
 end;
 
+procedure DrawHHOrder();
+var HHGear: PGear;
+    hh: PHedgehog;
+    c, i, t, x, y, sprH, sprW, fSprOff: LongInt;
+begin
+t:= LocalTeam;
+
+if not CurrentTeam^.ExtDriven then
+    for i:= 0 to Pred(TeamsCount) do
+        if (TeamsArray[i] = CurrentTeam) then
+            t:= i;
+
+if TeamsArray[t] <> nil then
+    begin
+    sprH:= SpritesData[sprBigDigit].Height;
+    sprW:= SpritesData[sprBigDigit].Width;
+    fSprOff:= sprW div 4 + SpritesData[sprFrame].Width div 4 - 1; // - 1 for overlap to avoid artifacts
+    i:= 0;
+    c:= 0;
+        repeat
+        hh:= @TeamsArray[t]^.Hedgehogs[i];
+        inc(i);
+        if (hh <> nil) and (hh^.Gear <> nil) then
+            begin
+            inc(c);
+            HHGear:= hh^.Gear;
+            x:= hwRound(HHGear^.X) + WorldDx;
+            y:= hwRound(HHGear^.Y) + WorldDy - 2;
+            if (SpeechHogNumber <> c) or ((RealTicks and 512) < 256) then
+                begin
+                DrawTextureF(SpritesData[sprFrame].Texture, 0.5, x - fSprOff, y, 0, 1, SpritesData[sprFrame].Width, SpritesData[sprFrame].Height);
+                DrawTextureF(SpritesData[sprFrame].Texture, 0.5, x + fSprOff, y, 1, 1, SpritesData[sprFrame].Width, SpritesData[sprFrame].Height);
+                DrawTextureF(SpritesData[sprBigDigit].Texture, 0.5, x, y, c, 1, sprW, sprH);
+                end
+            else
+                DrawCircle(x, y, 20, 3, 0, $FF, 0, $60);
+            end;
+        until (i > cMaxHHIndex);
+    end
+
+end;
+
 
 procedure DrawHH(Gear: PGear; ox, oy: LongInt);
 var i, t: LongInt;
--- a/hedgewars/uVariables.pas	Fri Mar 20 15:00:52 2015 -0400
+++ b/hedgewars/uVariables.pas	Sun Mar 22 21:40:16 2015 +0100
@@ -217,6 +217,8 @@
     WorldDx: LongInt;
     WorldDy: LongInt;
 
+    SpeechHogNumber: LongInt;
+
     // for tracking the limits of the visible grid based on cScaleFactor
     ViewLeftX, ViewRightX, ViewBottomY, ViewTopY, ViewWidth, ViewHeight: LongInt;
 
@@ -2675,6 +2677,7 @@
     if cFullscreenHeight = 0 then
         cFullscreenHeight:= min(cWindowedHeight, 480);
 
+    SpeechHogNumber:= -1;
 
     LuaGoals:= '';
     cMapName:= '';