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 missedCount: LongWord; |
48 missedCount: LongWord; |
49 lastStr: LongWord; |
49 lastStr: LongWord; |
|
50 history: LongWord; |
50 visibleCount: LongWord; |
51 visibleCount: LongWord; |
51 InputStr: TChatLine; |
52 InputStr: TChatLine; |
52 InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char |
53 InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char |
53 ChatReady: boolean; |
54 ChatReady: boolean; |
54 showAll: boolean; |
55 showAll: boolean; |
291 ParseCommand('/say ' + s, true); |
292 ParseCommand('/say ' + s, true); |
292 end; |
293 end; |
293 |
294 |
294 procedure KeyPressChat(Key: Longword); |
295 procedure KeyPressChat(Key: Longword); |
295 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0); |
296 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0); |
296 var i, btw: integer; |
297 var i, btw, index: integer; |
297 utf8: shortstring; |
298 utf8, chatLine: shortstring; |
298 begin |
299 begin |
299 if Key <> 0 then |
300 if Key <> 0 then |
300 case Key of |
301 case Key of |
301 {Backspace} |
302 {Backspace} |
302 8, 127: if Length(InputStr.s) > 0 then |
303 8, 127: if Length(InputStr.s) > 0 then |
303 begin |
304 begin |
|
305 history:= 0; |
304 InputStr.s[0]:= InputStrL[byte(InputStr.s[0])]; |
306 InputStr.s[0]:= InputStrL[byte(InputStr.s[0])]; |
305 SetLine(InputStr, InputStr.s, true) |
307 SetLine(InputStr, InputStr.s, true) |
306 end; |
308 end; |
307 {Esc} |
309 {Esc} |
308 27: if Length(InputStr.s) > 0 then SetLine(InputStr, '', true) |
310 27: if Length(InputStr.s) > 0 then SetLine(InputStr, '', true) |
309 else |
311 else |
310 begin |
312 begin |
311 FreezeEnterKey; |
313 FreezeEnterKey; |
|
314 history:= 0; |
312 SDL_EnableKeyRepeat(0,0); |
315 SDL_EnableKeyRepeat(0,0); |
313 GameState:= gsGame; |
316 GameState:= gsGame; |
314 ResetKbd; |
317 ResetKbd; |
315 end; |
318 end; |
316 {Return} |
319 {Return} |
319 begin |
322 begin |
320 AcceptChatString(InputStr.s); |
323 AcceptChatString(InputStr.s); |
321 SetLine(InputStr, '', false) |
324 SetLine(InputStr, '', false) |
322 end; |
325 end; |
323 FreezeEnterKey; |
326 FreezeEnterKey; |
|
327 history:= 0; |
324 SDL_EnableKeyRepeat(0,0); |
328 SDL_EnableKeyRepeat(0,0); |
325 GameState:= gsGame; |
329 GameState:= gsGame; |
326 ResetKbd; |
330 ResetKbd; |
327 end; |
331 end; |
328 {arrow keys} |
332 {arrow keys (up, down)} |
329 63232, 63233, 63234, 63235: begin end; |
333 63232, 63233: begin |
|
334 |
|
335 if (Key = 63232) and (history < lastStr) then inc(history); |
|
336 if (Key = 63233) and (history > 0) then dec(history); |
|
337 |
|
338 index:= lastStr - history + 1; |
|
339 if (index > lastStr) then |
|
340 SetLine(InputStr, '', true) |
|
341 else |
|
342 begin |
|
343 btw:= Pos(': ', Strs[index].s) + 2; // remove the nick |
|
344 chatLine:= copy(Strs[index].s, btw, Length(Strs[index].s)); |
|
345 SetLine(InputStr, chatLine, true); |
|
346 end; |
|
347 end; |
|
348 {arrow keys (left, right)} |
|
349 63234, 63235: begin end; |
330 else |
350 else |
331 if (Key < $80) then |
351 if (Key < $80) then |
332 btw:= 1 |
352 btw:= 1 |
333 else if (Key < $800) then |
353 else if (Key < $800) then |
334 btw:= 2 |
354 btw:= 2 |
414 RegisterVariable('team', @chTeamSay, true); |
434 RegisterVariable('team', @chTeamSay, true); |
415 RegisterVariable('history', @chHistory, true ); |
435 RegisterVariable('history', @chHistory, true ); |
416 RegisterVariable('chat', @chChat, true ); |
436 RegisterVariable('chat', @chChat, true ); |
417 |
437 |
418 lastStr:= 0; |
438 lastStr:= 0; |
|
439 history:= 0; |
419 visibleCount:= 0; |
440 visibleCount:= 0; |
420 showAll:= false; |
441 showAll:= false; |
421 ChatReady:= false; |
442 ChatReady:= false; |
422 missedCount:= 0; |
443 missedCount:= 0; |
423 |
444 |