hedgewars/uChat.pas
changeset 2376 ece7b87f1334
parent 2290 bf87ca44782e
child 2390 57fb33ab04a4
equal deleted inserted replaced
2375:99f05a01a6a3 2376:ece7b87f1334
    40 		end;
    40 		end;
    41 
    41 
    42 var Strs: array[0 .. MaxStrIndex] of TChatLine;
    42 var Strs: array[0 .. MaxStrIndex] of TChatLine;
    43 	lastStr: Longword = 0;
    43 	lastStr: Longword = 0;
    44 	visibleCount: Longword = 0;
    44 	visibleCount: Longword = 0;
    45 	
    45 
    46 	InputStr: TChatLine;
    46 	InputStr: TChatLine;
    47 	InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char
    47 	InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char
    48 
    48 
    49 procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean);
    49 procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean);
    50 var strSurface, resSurface: PSDL_Surface;
    50 var strSurface, resSurface: PSDL_Surface;
   118 	begin
   118 	begin
   119 	r.w:= Strs[i].Width;
   119 	r.w:= Strs[i].Width;
   120 	DrawFillRect(r);
   120 	DrawFillRect(r);
   121 	DrawTexture(8 - cScreenWidth div 2, (visibleCount - t) * 16 - 6, Strs[i].Tex);
   121 	DrawTexture(8 - cScreenWidth div 2, (visibleCount - t) * 16 - 6, Strs[i].Tex);
   122 	dec(r.y, 16);
   122 	dec(r.y, 16);
   123 	
   123 
   124 	if i = 0 then i:= MaxStrIndex else dec(i);
   124 	if i = 0 then i:= MaxStrIndex else dec(i);
   125 	inc(cnt);
   125 	inc(cnt);
   126 	inc(t)
   126 	inc(t)
   127 	end;
   127 	end;
   128 
   128 
   132 procedure AcceptChatString(s: shortstring);
   132 procedure AcceptChatString(s: shortstring);
   133 var i: TWave;
   133 var i: TWave;
   134 
   134 
   135 begin
   135 begin
   136 // "Make hedgehog say something"
   136 // "Make hedgehog say something"
   137 if (s[1] = '"') and (s[Length(s)] = '"') then 
   137 if (s[1] = '"') and (s[Length(s)] = '"') then
   138     begin
   138     begin
   139     if CurrentTeam^.ExtDriven then
   139     if CurrentTeam^.ExtDriven then
   140         ParseCommand('/say ' + copy(s, 2, Length(s)-2), true)
   140         ParseCommand('/say ' + copy(s, 2, Length(s)-2), true)
   141     else
   141     else
   142         ParseCommand('/hogsay '#1 + copy(s, 2, Length(s)-2), true);
   142         ParseCommand('/hogsay '#1 + copy(s, 2, Length(s)-2), true);
   143     exit
   143     exit
   144     end;
   144     end;
   145 // 'Make hedgehog think something'
   145 // 'Make hedgehog think something'
   146 if (s[1] = '''') and (s[Length(s)] = '''') then 
   146 if (s[1] = '''') and (s[Length(s)] = '''') then
   147     begin
   147     begin
   148     if CurrentTeam^.ExtDriven then
   148     if CurrentTeam^.ExtDriven then
   149         ParseCommand('/say ' + copy(s, 2, Length(s)-2), true)
   149         ParseCommand('/say ' + copy(s, 2, Length(s)-2), true)
   150     else
   150     else
   151         ParseCommand('/hogsay '#2 + copy(s, 2, Length(s)-2), true);
   151         ParseCommand('/hogsay '#2 + copy(s, 2, Length(s)-2), true);
   152     exit
   152     exit
   153     end;
   153     end;
   154 // -Make hedgehog yell something-
   154 // -Make hedgehog yell something-
   155 if (s[1] = '-') and (s[Length(s)] = '-') then 
   155 if (s[1] = '-') and (s[Length(s)] = '-') then
   156     begin
   156     begin
   157     if CurrentTeam^.ExtDriven then
   157     if CurrentTeam^.ExtDriven then
   158         ParseCommand('/say ' + copy(s, 2, Length(s)-2), true)
   158         ParseCommand('/say ' + copy(s, 2, Length(s)-2), true)
   159     else
   159     else
   160         ParseCommand('/hogsay '#3 + copy(s, 2, Length(s)-2), true);
   160         ParseCommand('/hogsay '#3 + copy(s, 2, Length(s)-2), true);
   192     exit
   192     exit
   193     end;
   193     end;
   194 if (s[1] = '/') and (copy(s, 1, 4) <> '/me ') then
   194 if (s[1] = '/') and (copy(s, 1, 4) <> '/me ') then
   195 	begin
   195 	begin
   196 	if CurrentTeam^.ExtDriven then exit;
   196 	if CurrentTeam^.ExtDriven then exit;
   197 	
   197 
   198 	for i:= Low(TWave) to High(TWave) do
   198 	for i:= Low(TWave) to High(TWave) do
   199 		if (s = Wavez[i].cmd) then
   199 		if (s = Wavez[i].cmd) then
   200 			begin
   200 			begin
   201 			ParseCommand('/taunt ' + char(i), true);
   201 			ParseCommand('/taunt ' + char(i), true);
   202 			exit
   202 			exit
   249 	else
   249 	else
   250 	if (Key < $80) then btw:= 1
   250 	if (Key < $80) then btw:= 1
   251 	else if (Key < $800) then btw:= 2
   251 	else if (Key < $800) then btw:= 2
   252 	else if (Key < $10000) then btw:= 3
   252 	else if (Key < $10000) then btw:= 3
   253 	else btw:= 4;
   253 	else btw:= 4;
   254 	
   254 
   255 	utf8:= '';
   255 	utf8:= '';
   256 
   256 
   257 	for i:= btw downto 2 do
   257 	for i:= btw downto 2 do
   258 		begin
   258 		begin
   259 		utf8:= char((Key or $80) and $BF) + utf8;
   259 		utf8:= char((Key or $80) and $BF) + utf8;
   260 		Key:= Key shr 6
   260 		Key:= Key shr 6
   261 		end;
   261 		end;
   262 	
   262 
   263 	utf8:= char(Key or firstByteMark[btw]) + utf8;
   263 	utf8:= char(Key or firstByteMark[btw]) + utf8;
   264 
   264 
   265 	if byte(InputStr.s[0]) + btw > 240 then exit;
   265 	if byte(InputStr.s[0]) + btw > 240 then exit;
   266 
   266 
   267 	InputStrL[byte(InputStr.s[0]) + btw]:= InputStr.s[0];
   267 	InputStrL[byte(InputStr.s[0]) + btw]:= InputStr.s[0];