hedgewars/uChat.pas
changeset 8740 3eb1891f81ef
parent 8739 bbab7e35eaf2
child 8741 c98ec6865631
equal deleted inserted replaced
8739:bbab7e35eaf2 8740:3eb1891f81ef
    43     end;
    43     end;
    44     TChatCmd = (quit, pause, finish, fullscreen);
    44     TChatCmd = (quit, pause, finish, fullscreen);
    45 
    45 
    46 var Strs: array[0 .. MaxStrIndex] of TChatLine;
    46 var Strs: array[0 .. MaxStrIndex] of TChatLine;
    47     MStrs: array[0 .. MaxStrIndex] of shortstring;
    47     MStrs: array[0 .. MaxStrIndex] of shortstring;
       
    48     LocalStrs: array[0 .. MaxStrIndex] of shortstring;
    48     missedCount: LongWord;
    49     missedCount: LongWord;
    49     lastStr: LongWord;
    50     lastStr: LongWord;
       
    51     localLastStr: LongWord;
    50     history: LongWord;
    52     history: LongWord;
    51     visibleCount: LongWord;
    53     visibleCount: LongWord;
    52     InputStr: TChatLine;
    54     InputStr: TChatLine;
    53     InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char
    55     InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char
    54     ChatReady: boolean;
    56     ChatReady: boolean;
   302 end;
   304 end;
   303 
   305 
   304 procedure KeyPressChat(Key: Longword);
   306 procedure KeyPressChat(Key: Longword);
   305 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0);
   307 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0);
   306 var i, btw, index: integer;
   308 var i, btw, index: integer;
   307     utf8, chatLine: shortstring;
   309     utf8: shortstring;
   308 begin
   310 begin
   309     if Key <> 0 then
   311     if Key <> 0 then
   310     case Key of
   312     case Key of
   311         {Backspace}
   313         {Backspace}
   312         8, 127: if Length(InputStr.s) > 0 then
   314         8, 127: if Length(InputStr.s) > 0 then
   327             CleanupInput;
   329             CleanupInput;
   328             end;
   330             end;
   329         {arrow keys (up, down)}
   331         {arrow keys (up, down)}
   330         63232, 63233: begin
   332         63232, 63233: begin
   331 
   333 
   332             if (Key = 63232) and (history < lastStr) then inc(history);
   334             if (Key = 63232) and (history < localLastStr) then inc(history);
   333             if (Key = 63233) and (history > 0) then dec(history);
   335             if (Key = 63233) and (history > 0) then dec(history);
   334 
   336 
   335             index:= lastStr - history + 1;
   337             index:= localLastStr - history + 1;
   336             if (index > lastStr) then
   338             if (index > localLastStr) then
   337                 SetLine(InputStr, '', true)
   339                 SetLine(InputStr, '', true)
   338             else
   340             else
   339                 begin
   341                 SetLine(InputStr, LocalStrs[index], true);
   340                 btw:= Pos(': ', Strs[index].s) + 2; // remove the nick
       
   341                 chatLine:= copy(Strs[index].s, btw, Length(Strs[index].s));
       
   342                 SetLine(InputStr, chatLine, true);
       
   343                 end;
       
   344             end;
   342             end;
   345         {arrow keys (left, right)}
   343         {arrow keys (left, right)}
   346         63234, 63235: begin end;
   344         63234, 63235: begin end;
   347         else
   345         else
   348             if (Key < $80) then
   346             if (Key < $80) then
   382     SendIPC('s' + s);
   380     SendIPC('s' + s);
   383 
   381 
   384     if copy(s, 1, 4) = '/me ' then
   382     if copy(s, 1, 4) = '/me ' then
   385         s:= #2 + '* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4)
   383         s:= #2 + '* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4)
   386     else
   384     else
       
   385         begin
       
   386         localLastStr:= (localLastStr + 1) mod MaxStrIndex;
       
   387         LocalStrs[localLastStr]:= s;
   387         s:= #1 + UserNick + ': ' + s;
   388         s:= #1 + UserNick + ': ' + s;
       
   389         end;
   388 
   390 
   389     AddChatString(s)
   391     AddChatString(s)
   390 end;
   392 end;
   391 
   393 
   392 procedure chTeamSay(var s: shortstring);
   394 procedure chTeamSay(var s: shortstring);
   423     RegisterVariable('team', @chTeamSay, true);
   425     RegisterVariable('team', @chTeamSay, true);
   424     RegisterVariable('history', @chHistory, true );
   426     RegisterVariable('history', @chHistory, true );
   425     RegisterVariable('chat', @chChat, true );
   427     RegisterVariable('chat', @chChat, true );
   426 
   428 
   427     lastStr:= 0;
   429     lastStr:= 0;
       
   430     localLastStr:= 0;
   428     history:= 0;
   431     history:= 0;
   429     visibleCount:= 0;
   432     visibleCount:= 0;
   430     showAll:= false;
   433     showAll:= false;
   431     ChatReady:= false;
   434     ChatReady:= false;
   432     missedCount:= 0;
   435     missedCount:= 0;