hedgewars/uChat.pas
branchqmlfrontend
changeset 10515 7705784902e1
parent 10514 a1423588a4e4
child 10588 6189bb1c903d
--- a/hedgewars/uChat.pas	Sun Nov 09 23:02:21 2014 +0300
+++ b/hedgewars/uChat.pas	Tue Nov 18 23:39:30 2014 +0300
@@ -58,6 +58,7 @@
     ChatReady: boolean;
     showAll: boolean;
     liveLua: boolean;
+    ChatHidden: boolean;
 
 const
     colors: array[#0..#6] of TSDL_Color = (
@@ -204,20 +205,22 @@
 end;
 
 procedure DrawChat;
-var i, t, left, top, cnt: Longword;
+var i, t, left, top, cnt: LongInt;
 begin
 ChatReady:= true; // maybe move to somewhere else?
 
+if ChatHidden and (not showAll) then
+    visibleCount:= 0;
+
+// draw chat lines with some distance from screen border
 left:= 4 - cScreenWidth div 2;
-top := 10;
+top := 10 + visibleCount * ClHeight; // we start with input line (if any)
 
+// draw chat input line first and under all other lines
 if (GameState = gsChat) and (InputStr.Tex <> nil) then
-    begin
-    // draw under all other lines
-    DrawTexture(left, top + visibleCount * ClHeight, InputStr.Tex);
-    end;
+    DrawTexture(left, top, InputStr.Tex);
 
-if UIDisplay <> uiNone then
+if ((not ChatHidden) or showAll) and (UIDisplay <> uiNone) then
     begin
     if MissedCount <> 0 then // there are chat strings we missed, so print them now
         begin
@@ -231,11 +234,13 @@
     t  := 1; // # of current line processed
 
     // draw lines in reverse order
-    while (((t < 7) and (Strs[i].Time > RealTicks)) or ((t < MaxStrIndex) and showAll))
+    while (((t < 7) and (Strs[i].Time > RealTicks)) or ((t <= MaxStrIndex + 1) and showAll))
     and (Strs[i].Tex <> nil) do
         begin
-        // draw lines 4px away from left screen border and 2px away from top
-        DrawTexture(left, top + (visibleCount - t) * ClHeight, Strs[i].Tex);
+        top:= top - ClHeight;
+        // draw chatline only if not offscreen
+        if top > 0 then
+            DrawTexture(left, top, Strs[i].Tex);
 
         if i = 0 then
             i:= MaxStrIndex
@@ -268,6 +273,13 @@
     c, t: LongInt;
     x: byte;
 begin
+if s <> LocalStrs[localLastStr] then
+    begin
+    // put in input history
+    localLastStr:= (localLastStr + 1) mod MaxStrIndex;
+    LocalStrs[localLastStr]:= s;
+    end;
+
 t:= LocalTeam;
 x:= 0;
 if (s[1] = '"') and (s[Length(s)] = '"')
@@ -295,10 +307,6 @@
 
 if (s[1] = '/') then
     begin
-    // put in input history
-    localLastStr:= (localLastStr + 1) mod MaxStrIndex;
-    LocalStrs[localLastStr]:= s;
-
     // These 3 are same as above, only are to make the hedgehog say it on next attack
     if (copy(s, 2, 4) = 'hsa ') then
         begin
@@ -339,6 +347,14 @@
         exit
         end;
 
+    if (copy(s, 2, 10) = 'togglechat') then
+        begin
+        ChatHidden:= (not ChatHidden);
+        if ChatHidden then
+           showAll:= false;
+        exit
+        end;
+
     // debugging commands
     if (copy(s, 2, 7) = 'debugvl') then
         begin
@@ -498,11 +514,7 @@
     if copy(s, 1, 4) = '/me ' then
         s:= #2 + '* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4)
     else
-        begin
-        localLastStr:= (localLastStr + 1) mod MaxStrIndex;
-        LocalStrs[localLastStr]:= s;
         s:= #1 + UserNick + ': ' + s;
-        end;
 
     AddChatString(s)
 end;
@@ -517,9 +529,18 @@
 end;
 
 procedure chHistory(var s: shortstring);
+var i: LongInt;
 begin
     s:= s; // avoid compiler hint
-    showAll:= not showAll
+    showAll:= not showAll;
+    // immediatly recount
+    visibleCount:= 0;
+    if showAll or (not ChatHidden) then
+        for i:= 0 to MaxStrIndex do
+            begin
+            if (Strs[i].Tex <> nil) and (showAll or (Strs[i].Time > RealTicks)) then
+                inc(visibleCount);
+            end;
 end;
 
 procedure chChat(var s: shortstring);
@@ -552,6 +573,7 @@
     ChatReady:= false;
     missedCount:= 0;
     liveLua:= false;
+    ChatHidden:= false;
 
     inputStr.Tex := nil;
     for i:= 0 to MaxStrIndex do