hedgewars/uChat.pas
changeset 10852 9e5763cb805e
parent 10851 f25dad9c3136
child 10853 287634baf7ba
--- a/hedgewars/uChat.pas	Sun Mar 08 01:51:27 2015 +0100
+++ b/hedgewars/uChat.pas	Sun Mar 08 02:40:32 2015 +0100
@@ -65,11 +65,12 @@
     liveLua: boolean;
     ChatHidden: boolean;
     firstDraw: boolean;
-    InputLinePrefix: shortstring;
+    InputLinePrefix: TChatLine;
     // cursor
     cursorPos, cursorX, selectedPos, selectionDx: LongInt;
     LastKeyPressTick: LongWord;
 
+
 const
     InputStrLNoPred: byte = 255;
 
@@ -112,12 +113,12 @@
 
     // calculate cursor offset
 
-    str:= InputLinePrefix + InputStr.s;
+    str:= InputStr.s;
     font:= CheckCJKFont(ansistring(str), fnt16);
 
     // get only substring before cursor to determine length
-    // SetLength(str, Length(InputLinePrefix) + cursorPos); // makes pas2c unhappy
-    str[0]:= char(Length(InputLinePrefix) + cursorPos);
+    // SetLength(str, cursorPos); // makes pas2c unhappy
+    str[0]:= char(cursorPos);
     // get render size of text
     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(str), @coff, nil);
 
@@ -127,9 +128,9 @@
     if selectedPos >= 0 then
         begin
         if selectedPos > cursorPos then
-            str:= InputLinePrefix + InputStr.s;
-        // SetLength(str, Length(InputLinePrefix) + selectedPos); // makes pas2c unhappy
-        str[0]:= char(Length(InputLinePrefix) + selectedPos);
+            str:= InputStr.s;
+        // SetLength(str, selectedPos); // makes pas2c unhappy
+        str[0]:= char(selectedPos);
         TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(str), @soff, nil);
         selectionDx:= soff - coff;
         end
@@ -199,8 +200,7 @@
     begin
     cl.s:= str;
     color:= colors[#6];
-    // TODO FIX render InputLinePrefix seperately so that it doesn't mess up max len
-    str:= InputLinePrefix + str + ' ';
+    str:= str + ' ';
     end
 else
     begin
@@ -253,6 +253,22 @@
 
 procedure CheckPasteBuffer(); forward;
 
+procedure UpdateInputLinePrefix();
+begin
+if liveLua then
+    begin
+    InputLinePrefix.color:= colors[#1];
+    InputLinePrefix.s:= '[Lua] >';
+    end
+else
+    begin
+    InputLinePrefix.color:= colors[#6];
+    InputLinePrefix.s:= UserNick + '>';
+    end;
+
+FreeAndNilTexture(InputLinePrefix.Tex);
+end;
+
 procedure DrawChat;
 var i, t, left, top, cnt: LongInt;
     selRect: TSDL_Rect;
@@ -271,13 +287,19 @@
     begin
     CheckPasteBuffer();
 
+    if InputLinePrefix.Tex = nil then
+        RenderChatLineTex(InputLinePrefix, InputLinePrefix.s);
+
+    DrawTexture(left, top, InputLinePrefix.Tex);
+    inc(left, InputLinePrefix.Width);
+    DrawTexture(left, top, InputStr.Tex);
+
     if firstDraw then
         begin
         UpdateCursorCoords();
         firstDraw:= false;
         end;
 
-    DrawTexture(left, top, InputStr.Tex);
     if selectedPos < 0 then
         begin
         // draw cursor
@@ -301,9 +323,10 @@
 
         DrawRect(selRect, $FF, $FF, $FF, $40, true);
         end;
+
+    dec(left, InputLinePrefix.Width);
     end;
 
-
 // draw chat lines
 if ((not ChatHidden) or showAll) and (UIDisplay <> uiNone) then
     begin
@@ -465,6 +488,7 @@
                 AddFileLog('[Lua] chat input string parsing disabled');
                 AddChatString(#3 + 'Lua parsing: OFF');
                 end;
+            UpdateInputLinePrefix();
             end;
         exit
         end;
@@ -1081,7 +1105,8 @@
     ChatHidden:= false;
     firstDraw:= true;
 
-    InputLinePrefix:= '';
+    InputLinePrefix.Tex:= nil;
+    UpdateInputLinePrefix();
     inputStr.s:= '';
     inputStr.Tex := nil;
     for i:= 0 to MaxStrIndex do
@@ -1096,6 +1121,7 @@
 procedure freeModule;
 var i: ShortInt;
 begin
+    FreeAndNilTexture(InputLinePrefix.Tex);
     FreeAndNilTexture(InputStr.Tex);
     for i:= 0 to MaxStrIndex do
         FreeAndNilTexture(Strs[i].Tex);