hedgewars/uVisualGears.pas
changeset 2042 905c554d62e6
parent 2014 c028362c5d72
child 2044 8548f5be2d72
--- a/hedgewars/uVisualGears.pas	Sat May 09 11:57:47 2009 +0000
+++ b/hedgewars/uVisualGears.pas	Mon May 11 18:56:55 2009 +0000
@@ -44,6 +44,8 @@
 		Kind: TVisualGearType;
 		doStep: TVGearStepProcedure;
 		Tex: PTexture;
+        Hedgehog: pointer;
+        Text: shortstring
 		end;
 
 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear;
@@ -240,6 +242,47 @@
 //doStepTeamHealthSorterWork(Gear, Steps)
 end;
 
+procedure doStepSpeechBubbleWork(Gear: PVisualGear; Steps: Longword);
+var t: LongWord;
+begin
+for t:= 1 to Steps do
+    begin
+    dec(Gear^.Timer);
+
+    if (PHedgehog(Gear^.Hedgehog)^.Gear <> nil) then
+        begin
+        Gear^.X:= PHedgehog(Gear^.Hedgehog)^.Gear^.X+int2hwFloat(Gear^.Tex^.w div 2  - Gear^.FrameTicks);
+        Gear^.Y:= PHedgehog(Gear^.Hedgehog)^.Gear^.Y-int2hwFloat(16+Gear^.Tex^.h);
+        end;
+
+    if Gear^.Timer = 0 then
+        begin
+        CurrentHedgehog^.SpeechGear:= nil;
+        DeleteVisualGear(Gear)
+        end;
+    end
+end;
+
+procedure doStepSpeechBubble(Gear: PVisualGear; Steps: Longword);
+begin
+if (CurrentHedgehog^.SpeechGear <> nil) then DeleteVisualGear(CurrentHedgehog^.SpeechGear);
+CurrentHedgehog^.SpeechGear:= Gear;
+
+Gear^.Timer:= max(Length(Gear^.Text)*150,3000);
+
+Gear^.Tex:= RenderSpeechBubbleTex(Gear^.Text, Gear^.FrameTicks, fnt16);
+
+case Gear^.FrameTicks of
+    1: Gear^.FrameTicks:= SpritesData[sprSpeechTail].Width-28;
+    2: Gear^.FrameTicks:= SpritesData[sprThoughtTail].Width-20;
+    3: Gear^.FrameTicks:= SpritesData[sprShoutTail].Width-10;
+    end;
+
+Gear^.doStep:= @doStepSpeechBubbleWork;
+
+Gear^.Y:= Gear^.Y - int2hwFloat(Gear^.Tex^.h)
+end;
+
 // ==================================================================
 const doStepHandlers: array[TVisualGearType] of TVGearStepProcedure =
 		(
@@ -249,7 +292,8 @@
 			@doStepExpl,
 			@doStepFire,
 			@doStepSmallDamage,
-			@doStepTeamHealthSorter
+			@doStepTeamHealthSorter,
+			@doStepSpeechBubble
 		);
 
 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear;
@@ -264,7 +308,7 @@
 		exit
 		end;
 
-if cReducedQuality and (Kind <> vgtTeamHealthSorter) then
+if cReducedQuality and (Kind <> vgtTeamHealthSorter) and (Kind <> vgtSpeechBubble) then
 	begin
 	AddVisualGear:= nil;
 	exit
@@ -382,6 +426,7 @@
 			vgtExplPart2: DrawSprite(sprExplPart2, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 7 - Gear^.Frame);
 			vgtFire: DrawSprite(sprFlame, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, (RealTicks div 64 + Gear^.Frame) mod 8);
 			vgtSmallDamageTag: DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Tex);
+            vgtSpeechBubble: if Gear^.Tex <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Tex);
 			end;
 		Gear:= Gear^.NextGear
 		end