hedgewars/uChat.pas
changeset 15984 6a985a680c44
parent 15983 416bca0a172c
child 15985 a4630009e733
equal deleted inserted replaced
15983:416bca0a172c 15984:6a985a680c44
    26 procedure initModule;
    26 procedure initModule;
    27 procedure freeModule;
    27 procedure freeModule;
    28 procedure ReloadLines;
    28 procedure ReloadLines;
    29 procedure CleanupInput;
    29 procedure CleanupInput;
    30 procedure CloseChat;
    30 procedure CloseChat;
       
    31 procedure RestoreChat;
    31 procedure AddChatString(s: shortstring);
    32 procedure AddChatString(s: shortstring);
    32 procedure DrawChat;
    33 procedure DrawChat;
    33 procedure KeyPressChat(keysym: TSDL_Keysym);
    34 procedure KeyPressChat(keysym: TSDL_Keysym);
    34 procedure SendHogSpeech(s: shortstring);
    35 procedure SendHogSpeech(s: shortstring);
    35 procedure CopyToClipboard(var newContent: shortstring);
    36 procedure CopyToClipboard(var newContent: shortstring);
    53     TChatCmd = (ccQuit, ccPause, ccShowHistory, ccFullScreen);
    54     TChatCmd = (ccQuit, ccPause, ccShowHistory, ccFullScreen);
    54 
    55 
    55 var Strs: array[0 .. MaxStrIndex] of TChatLine;
    56 var Strs: array[0 .. MaxStrIndex] of TChatLine;
    56     MStrs: array[0 .. MaxStrIndex] of shortstring;
    57     MStrs: array[0 .. MaxStrIndex] of shortstring;
    57     LocalStrs: array[0 .. MaxStrIndex] of shortstring;
    58     LocalStrs: array[0 .. MaxStrIndex] of shortstring;
       
    59     oldInput: shortstring;
    58     missedCount: LongWord;
    60     missedCount: LongWord;
    59     lastStr: LongWord;
    61     lastStr: LongWord;
    60     localLastStr: LongInt;
    62     localLastStr: LongInt;
    61     history: LongInt;
    63     history: LongInt;
    62     visibleCount: LongWord;
    64     visibleCount: LongWord;
   781     //SDL_EnableKeyRepeat(0,0);
   783     //SDL_EnableKeyRepeat(0,0);
   782     isInChatMode:= false;
   784     isInChatMode:= false;
   783     ResetKbd;
   785     ResetKbd;
   784 end;
   786 end;
   785 
   787 
       
   788 procedure OpenChat(s: shortstring);
       
   789 var i: Integer;
       
   790 begin
       
   791     isInChatMode:= true;
       
   792     SDL_StopTextInput();
       
   793     SDL_StartTextInput();
       
   794     //Make REALLY sure unexpected events are flushed (1 time is insufficient as of SDL 2.0.7)
       
   795     for i := 1 to 2 do
       
   796     begin
       
   797         SDL_PumpEvents();
       
   798         SDL_FlushEvent(SDL_TEXTINPUT);
       
   799     end;
       
   800     if length(s) = 0 then
       
   801         SetLine(InputStr, '', true)
       
   802     else
       
   803         begin
       
   804         SetLine(InputStr, s, true);
       
   805         cursorPos:= length(s);
       
   806         UpdateCursorCoords();
       
   807         end;
       
   808 end;
       
   809 
   786 procedure CloseChat;
   810 procedure CloseChat;
   787 begin
   811 begin
       
   812     oldInput:= InputStr.s;
   788     SetLine(InputStr, '', true);
   813     SetLine(InputStr, '', true);
   789     ResetCursor();
   814     ResetCursor();
   790     CleanupInput();
   815     CleanupInput();
       
   816 end;
       
   817 
       
   818 procedure RestoreChat;
       
   819 begin
       
   820     if length(oldInput) > 0 then
       
   821         OpenChat(oldInput);
       
   822     oldInput:= '';
   791 end;
   823 end;
   792 
   824 
   793 procedure DelBytesFromInputStrBack(endIdx: integer; count: byte);
   825 procedure DelBytesFromInputStrBack(endIdx: integer; count: byte);
   794 var startIdx: integer;
   826 var startIdx: integer;
   795 begin
   827 begin
  1068             if Length(InputStr.s) > 0 then
  1100             if Length(InputStr.s) > 0 then
  1069                 begin
  1101                 begin
  1070                 SetLine(InputStr, '', true);
  1102                 SetLine(InputStr, '', true);
  1071                 ResetCursor();
  1103                 ResetCursor();
  1072                 end
  1104                 end
  1073             else CleanupInput
  1105             else
       
  1106                 CleanupInput;
       
  1107             oldInput:= '';
  1074             end;
  1108             end;
  1075         SDL_SCANCODE_RETURN, SDL_SCANCODE_KP_ENTER:
  1109         SDL_SCANCODE_RETURN, SDL_SCANCODE_KP_ENTER:
  1076             begin
  1110             begin
  1077             if Length(InputStr.s) > 0 then
  1111             if Length(InputStr.s) > 0 then
  1078                 begin
  1112                 begin
  1343                 inc(visibleCount);
  1377                 inc(visibleCount);
  1344             end;
  1378             end;
  1345 end;
  1379 end;
  1346 
  1380 
  1347 procedure chChat(var s: shortstring);
  1381 procedure chChat(var s: shortstring);
  1348 var i: Integer;
       
  1349 begin
  1382 begin
  1350     s:= s; // avoid compiler hint
  1383     s:= s; // avoid compiler hint
  1351     isInChatMode:= true;
       
  1352     SDL_StopTextInput();
       
  1353     SDL_StartTextInput();
       
  1354     //Make REALLY sure unexpected events are flushed (1 time is insufficient as of SDL 2.0.7)
       
  1355     for i := 1 to 2 do
       
  1356     begin
       
  1357         SDL_PumpEvents();
       
  1358         SDL_FlushEvent(SDL_TEXTINPUT);
       
  1359     end;
       
  1360     //SDL_EnableKeyRepeat(200,45);
       
  1361     if length(s) = 0 then
  1384     if length(s) = 0 then
  1362         SetLine(InputStr, '', true)
  1385         OpenChat('')
  1363     else
  1386     else
  1364         begin
  1387         OpenChat('/clan ');
  1365         SetLine(InputStr, '/clan ', true);
       
  1366         cursorPos:= 6;
       
  1367         UpdateCursorCoords();
       
  1368         end;
       
  1369 end;
  1388 end;
  1370 
  1389 
  1371 procedure initModule;
  1390 procedure initModule;
  1372 var i: ShortInt;
  1391 var i: ShortInt;
  1373 begin
  1392 begin