hedgewars/uChat.pas
changeset 10866 c1f75780c56f
parent 10863 9d3e1123bd43
child 10868 acb03a9712c3
--- 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;