hedgewars/uChat.pas
changeset 3539 c3d1fccbe0ed
parent 3407 dcc129c4352e
child 3676 fa29572fa56a
equal deleted inserted replaced
3537:8f5b3108f29c 3539:c3d1fccbe0ed
    28 procedure AddChatString(s: shortstring);
    28 procedure AddChatString(s: shortstring);
    29 procedure DrawChat;
    29 procedure DrawChat;
    30 procedure KeyPressChat(Key: Longword);
    30 procedure KeyPressChat(Key: Longword);
    31 
    31 
    32 var UserNick: shortstring;
    32 var UserNick: shortstring;
       
    33     ChatReady: boolean;
    33     showAll: boolean;
    34     showAll: boolean;
    34 
    35 
    35 implementation
    36 implementation
    36 uses uMisc, uStore, uConsts, SDLh, uConsole, uKeys, uTeams;
    37 uses uMisc, uStore, uConsts, SDLh, uConsole, uKeys, uTeams;
    37 
    38 
    43         Width: LongInt;
    44         Width: LongInt;
    44         s: shortstring;
    45         s: shortstring;
    45         end;
    46         end;
    46 
    47 
    47 var Strs: array[0 .. MaxStrIndex] of TChatLine;
    48 var Strs: array[0 .. MaxStrIndex] of TChatLine;
       
    49     MStrs: array[0 .. MaxStrIndex] of shortstring;
       
    50     missedCount: LongWord;
    48     lastStr: LongWord;
    51     lastStr: LongWord;
    49     visibleCount: LongWord;
    52     visibleCount: LongWord;
    50     InputStr: TChatLine;
    53     InputStr: TChatLine;
    51     InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char
    54     InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char
    52 
    55 
    53 const colors: array[#1..#4] of TSDL_Color = (
    56 const colors: array[#1..#5] of TSDL_Color = (
    54     (r:$FF; g:$FF; b:$FF; unused:$FF), // chat message [White]
    57     (r:$FF; g:$FF; b:$FF; unused:$FF), // chat message [White]
    55     (r:$FF; g:$00; b:$FF; unused:$FF), // action message [Purple]
    58     (r:$FF; g:$00; b:$FF; unused:$FF), // action message [Purple]
    56     (r:$90; g:$FF; b:$90; unused:$FF), // join/leave message [Lime]
    59     (r:$90; g:$FF; b:$90; unused:$FF), // join/leave message [Lime]
    57     (r:$FF; g:$FF; b:$A0; unused:$FF)  // team message [Light Yellow]
    60     (r:$FF; g:$FF; b:$A0; unused:$FF), // team message [Light Yellow]
       
    61     (r:$FF; g:$00; b:$00; unused:$ff)  // error messages [Red]
    58     );
    62     );
    59 
    63 
    60 procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean);
    64 procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean);
    61 var strSurface, resSurface: PSDL_Surface;
    65 var strSurface, resSurface: PSDL_Surface;
    62     w, h: LongInt;
    66     w, h: LongInt;
   101 SDL_FreeSurface(resSurface)
   105 SDL_FreeSurface(resSurface)
   102 end;
   106 end;
   103 
   107 
   104 procedure AddChatString(s: shortstring);
   108 procedure AddChatString(s: shortstring);
   105 begin
   109 begin
       
   110 if not ChatReady then
       
   111     begin
       
   112     if MissedCount < MaxStrIndex - 1 then
       
   113         MStrs[MissedCount]:= s
       
   114     else if MissedCount < MaxStrIndex then
       
   115         MStrs[MissedCount]:= #5 + '[...]';
       
   116     inc(MissedCount);
       
   117     exit
       
   118     end;
       
   119 
   106 lastStr:= (lastStr + 1) mod (MaxStrIndex + 1);
   120 lastStr:= (lastStr + 1) mod (MaxStrIndex + 1);
   107 
   121 
   108 SetLine(Strs[lastStr], s, false);
   122 SetLine(Strs[lastStr], s, false);
   109 
   123 
   110 inc(visibleCount)
   124 inc(visibleCount)
   112 
   126 
   113 procedure DrawChat;
   127 procedure DrawChat;
   114 var i, t, cnt: Longword;
   128 var i, t, cnt: Longword;
   115     r: TSDL_Rect;
   129     r: TSDL_Rect;
   116 begin
   130 begin
       
   131 ChatReady:= true; // maybe move to somewhere else?
       
   132 if MissedCount <> 0 then // there are chat strings we missed, so print them now
       
   133     begin
       
   134     for i:= 0 to MissedCount - 1 do
       
   135         AddChatString(MStrs[i]);
       
   136     MissedCount:= 0;
       
   137     end;
   117 cnt:= 0;
   138 cnt:= 0;
   118 t:= 0;
   139 t:= 0;
   119 i:= lastStr;
   140 i:= lastStr;
   120 
   141 
   121 r.x:= 6 - cScreenWidth div 2;
   142 r.x:= 6 - cScreenWidth div 2;
   295 begin
   316 begin
   296     lastStr:= 0;
   317     lastStr:= 0;
   297     visibleCount:= 0;
   318     visibleCount:= 0;
   298     UserNick:= '';
   319     UserNick:= '';
   299     showAll:= false;
   320     showAll:= false;
       
   321     ChatReady:= false;
       
   322     missedCount:= 0;
   300 end;
   323 end;
   301 
   324 
   302 procedure freeModule;
   325 procedure freeModule;
   303 begin
   326 begin
   304 
   327