hedgewars/uChat.pas
branchui-scaling
changeset 15283 c4fd2813b127
parent 13389 24b531dcebe7
parent 15267 22f2fd8a3d2c
child 15664 0b99e220568a
equal deleted inserted replaced
13390:0135e64c6c66 15283:c4fd2813b127
    33 procedure SendHogSpeech(s: shortstring);
    33 procedure SendHogSpeech(s: shortstring);
    34 procedure CopyToClipboard(var newContent: shortstring);
    34 procedure CopyToClipboard(var newContent: shortstring);
    35 procedure TextInput(var event: TSDL_TextInputEvent);
    35 procedure TextInput(var event: TSDL_TextInputEvent);
    36 
    36 
    37 implementation
    37 implementation
    38 uses uConsts, uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO, uScript, uRenderUtils, uStore;
    38 uses uConsts, uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO, uScript, uRenderUtils, uStore, uLocale
       
    39      {$IFDEF USE_VIDEO_RECORDING}, uVideoRec{$ENDIF};
    39 
    40 
    40 const MaxStrIndex = 27;
    41 const MaxStrIndex = 27;
    41       MaxInputStrLen = 200;
    42       MaxInputStrLen = 200;
    42 
    43 
    43 type TChatLine = record
    44 type TChatLine = record
    69     LastKeyPressTick: LongWord;
    70     LastKeyPressTick: LongWord;
    70 
    71 
    71 
    72 
    72 const
    73 const
    73     colors: array[#0..#9] of TSDL_Color = (
    74     colors: array[#0..#9] of TSDL_Color = (
    74             (r:$FF; g:$FF; b:$FF; a:$FF), // #0 unused, feel free to take it for anything
    75             (r:$FF; g:$FF; b:$00; a:$FF), // #0 warning message [Yellow]
    75             (r:$FF; g:$FF; b:$FF; a:$FF), // #1 chat message [White]
    76             (r:$FF; g:$FF; b:$FF; a:$FF), // #1 chat message [White]
    76             (r:$FF; g:$00; b:$FF; a:$FF), // #2 action message [Purple]
    77             (r:$FF; g:$00; b:$FF; a:$FF), // #2 action message [Purple]
    77             (r:$90; g:$FF; b:$90; a:$FF), // #3 join/leave message [Lime]
    78             (r:$90; g:$FF; b:$90; a:$FF), // #3 join/leave message [Lime]
    78             (r:$FF; g:$FF; b:$A0; a:$FF), // #4 team message [Light Yellow]
    79             (r:$FF; g:$FF; b:$A0; a:$FF), // #4 team message [Light Yellow]
    79             (r:$FF; g:$00; b:$00; a:$FF), // #5 error messages [Red]
    80             (r:$FF; g:$00; b:$00; a:$FF), // #5 error messages [Red]
   385 
   386 
   386 if ChatHidden and (not showAll) then
   387 if ChatHidden and (not showAll) then
   387     visibleCount:= 0;
   388     visibleCount:= 0;
   388 
   389 
   389 // draw chat lines with some distance from screen border
   390 // draw chat lines with some distance from screen border
       
   391 {$IFDEF USE_TOUCH_INTERFACE}
       
   392 left:= 4 - cScreenWidth div 2;
       
   393 top := 55 + visibleCount * ClHeight; // we start with input line (if any)
       
   394 {$ELSE}
   390 left:= 4 - cScreenWidth div 2;
   395 left:= 4 - cScreenWidth div 2;
   391 top := 10 + visibleCount * ClHeight; // we start with input line (if any)
   396 top := 10 + visibleCount * ClHeight; // we start with input line (if any)
       
   397 {$ENDIF}
   392 
   398 
   393 // draw chat input line first and under all other lines
   399 // draw chat input line first and under all other lines
   394 if isInChatMode and (InputStr.Tex <> nil) then
   400 if isInChatMode and (InputStr.Tex <> nil) then
   395     begin
   401     begin
   396 
   402 
   447                     SpeechHogNumber:= byte(c) - 48;
   453                     SpeechHogNumber:= byte(c) - 48;
   448                 end;
   454                 end;
   449             // default to current hedgehog (if own) or first hedgehog
   455             // default to current hedgehog (if own) or first hedgehog
   450             if SpeechHogNumber = 0 then
   456             if SpeechHogNumber = 0 then
   451                 begin
   457                 begin
   452                 if not CurrentTeam^.ExtDriven then
   458                 if (not CurrentTeam^.ExtDriven) and (not CurrentHedgehog^.Unplaced) then
   453                     SpeechHogNumber:= CurrentTeam^.CurrHedgehog + 1
   459                     SpeechHogNumber:= CurrentTeam^.CurrHedgehog + 1
   454                 else
   460                 else
   455                     SpeechHogNumber:= 1;
   461                     SpeechHogNumber:= 1;
   456                 end;
   462                 end;
   457             end;
   463             end;
   523     LocalStrs[localLastStr]:= s;
   529     LocalStrs[localLastStr]:= s;
   524     end;
   530     end;
   525 
   531 
   526 t:= LocalTeam;
   532 t:= LocalTeam;
   527 x:= 0;
   533 x:= 0;
       
   534 // speech bubble
   528 if (s[1] = '"') and (s[Length(s)] = '"')
   535 if (s[1] = '"') and (s[Length(s)] = '"')
   529     then x:= 1
   536     then x:= 1
   530 
   537 
       
   538 // thinking bubble
   531 else if (s[1] = '''') and (s[Length(s)] = '''') then
   539 else if (s[1] = '''') and (s[Length(s)] = '''') then
   532     x:= 2
   540     x:= 2
   533 
   541 
       
   542 // yelling bubble
   534 else if (s[1] = '-') and (s[Length(s)] = '-') then
   543 else if (s[1] = '-') and (s[Length(s)] = '-') then
   535     x:= 3;
   544     x:= 3;
   536 
   545 
   537 if (not CurrentTeam^.ExtDriven) and (x <> 0) then
   546 if (not CurrentTeam^.ExtDriven) and (x <> 0) then
   538     for c:= 0 to Pred(TeamsCount) do
   547     for c:= 0 to Pred(TeamsCount) do
   548     exit
   557     exit
   549     end;
   558     end;
   550 
   559 
   551 if (s[1] = '/') then
   560 if (s[1] = '/') then
   552     begin
   561     begin
   553     // These 3 are same as above, only are to make the hedgehog say it on next attack
   562     if (Length(s) <= 1) then
       
   563         begin
       
   564         // empty chat command
       
   565         AddChatString(#0 + shortstring(trcmd[sidCmdUnknown]));
       
   566         exit;
       
   567         end;
       
   568 
       
   569     // Ignore message-type commands with empty argument list
       
   570     if (copy(s, 2, 2) = 'me') and (Length(s) = 3) then
       
   571         exit;
       
   572     if ((copy(s, 2, 3) = 'hsa') or (copy(s, 2, 3) = 'hta') or (copy(s, 2, 3) = 'hya')) and (Length(s) = 4) then
       
   573         exit;
       
   574     if ((copy(s, 2, 4) = 'team') or (copy(s, 2, 4) = 'clan')) and (Length(s) = 5) then
       
   575         exit;
       
   576 
       
   577     // Speech bubble, but on next attack
   554     if (copy(s, 2, 4) = 'hsa ') then
   578     if (copy(s, 2, 4) = 'hsa ') then
   555         begin
   579         begin
   556         if CurrentTeam^.ExtDriven then
   580         if CurrentTeam^.ExtDriven then
   557             ParseCommand('/say ' + copy(s, 6, Length(s)-5), true)
   581             ParseCommand('/say ' + copy(s, 6, Length(s)-5), true)
   558         else
   582         else
   559             SendHogSpeech(#4 + copy(s, 6, Length(s)-5));
   583             SendHogSpeech(#4 + copy(s, 6, Length(s)-5));
   560         exit
   584         exit
   561         end;
   585         end;
   562 
   586 
       
   587     // Thinking bubble, but on next attack
   563     if (copy(s, 2, 4) = 'hta ') then
   588     if (copy(s, 2, 4) = 'hta ') then
   564         begin
   589         begin
   565         if CurrentTeam^.ExtDriven then
   590         if CurrentTeam^.ExtDriven then
   566             ParseCommand('/say ' + copy(s, 6, Length(s)-5), true)
   591             ParseCommand('/say ' + copy(s, 6, Length(s)-5), true)
   567         else
   592         else
   568             SendHogSpeech(#5 + copy(s, 6, Length(s)-5));
   593             SendHogSpeech(#5 + copy(s, 6, Length(s)-5));
   569         exit
   594         exit
   570         end;
   595         end;
   571 
   596 
       
   597     // Yelling bubble, but on next attack
   572     if (copy(s, 2, 4) = 'hya ') then
   598     if (copy(s, 2, 4) = 'hya ') then
   573         begin
   599         begin
   574         if CurrentTeam^.ExtDriven then
   600         if CurrentTeam^.ExtDriven then
   575             ParseCommand('/say ' + copy(s, 6, Length(s)-5), true)
   601             ParseCommand('/say ' + copy(s, 6, Length(s)-5), true)
   576         else
   602         else
   577             SendHogSpeech(#6 + copy(s, 6, Length(s)-5));
   603             SendHogSpeech(#6 + copy(s, 6, Length(s)-5));
   578         exit
   604         exit
   579         end;
   605         end;
   580 
   606 
   581     if (copy(s, 2, 5) = 'team ') and (length(s) > 6) then
   607     // "/clan" or "/team" ("/team" is an alias for "/clan")
   582         begin
   608     if ((copy(s, 2, 5) = 'clan ') or (copy(s, 2, 5) = 'team ')) then
   583         ParseCommand(s, true);
   609         begin
       
   610         if (Length(s) > 6) then
       
   611             ParseCommand('team ' + copy(s, 7, Length(s) - 6), true);
   584         exit
   612         exit
   585         end;
   613         end;
   586 
   614 
   587     if (copy(s, 2, 3) = 'me ') then
   615     if (copy(s, 2, 3) = 'me ') then
   588         begin
   616         begin
   598         exit
   626         exit
   599         end;
   627         end;
   600 
   628 
   601     // debugging commands
   629     // debugging commands
   602     if (copy(s, 2, 7) = 'debugvl') then
   630     if (copy(s, 2, 7) = 'debugvl') then
       
   631         // This command intentionally not documented in /help
   603         begin
   632         begin
   604         cViewLimitsDebug:= (not cViewLimitsDebug);
   633         cViewLimitsDebug:= (not cViewLimitsDebug);
   605         UpdateViewLimits();
   634         UpdateViewLimits();
   606         exit
   635         exit
   607         end;
   636         end;
   608 
   637 
   609     if (copy(s, 2, 3) = 'lua') then
   638     if (copy(s, 2, 3) = 'lua') then
   610         begin
   639         begin
       
   640         LuaCmdUsed:= true;
   611         AddFileLog('/lua issued');
   641         AddFileLog('/lua issued');
       
   642 {$IFDEF USE_VIDEO_RECORDING}
       
   643         if flagPrerecording then
       
   644             begin
       
   645             AddFileLog('Force-stopping prerecording! Lua commands can not be recorded');
       
   646             StopPreRecording;
       
   647             end;
       
   648 {$ENDIF}
   612         if gameType <> gmtNet then
   649         if gameType <> gmtNet then
   613             begin
   650             begin
   614             liveLua:= (not liveLua);
   651             liveLua:= (not liveLua);
   615             if liveLua then
   652             if liveLua then
   616                 begin
   653                 begin
   617                 AddFileLog('[Lua] chat input string parsing enabled');
   654                 AddFileLog('[Lua] chat input string parsing enabled');
   618                 AddChatString(#3 + 'Lua parsing: ON');
   655                 AddChatString(#3 + shortstring(trmsg[sidLuaParsingOn]));
   619                 end
   656                 end
   620             else
   657             else
   621                 begin
   658                 begin
   622                 AddFileLog('[Lua] chat input string parsing disabled');
   659                 AddFileLog('[Lua] chat input string parsing disabled');
   623                 AddChatString(#3 + 'Lua parsing: OFF');
   660                 AddChatString(#3 + shortstring(trmsg[sidLuaParsingOff]));
   624                 end;
   661                 end;
   625             UpdateInputLinePrefix();
   662             UpdateInputLinePrefix();
   626             end;
   663             end
       
   664         else
       
   665             AddChatString(#5 + shortstring(trmsg[sidLuaParsingDenied]));
       
   666         exit
       
   667         end;
       
   668 
       
   669     // Help commands
       
   670     if (copy(s, 2, 11) = 'help taunts') then
       
   671         begin
       
   672         AddChatString(#3 + shortstring(trcmd[sidCmdHeaderTaunts]));
       
   673         AddChatString(#3 + shortstring(trcmd[sidCmdSpeech]));
       
   674         AddChatString(#3 + shortstring(trcmd[sidCmdThink]));
       
   675         AddChatString(#3 + shortstring(trcmd[sidCmdYell]));
       
   676         AddChatString(#3 + shortstring(trcmd[sidCmdSpeechNumberHint]));
       
   677         AddChatString(#3 + shortstring(trcmd[sidCmdHsa]));
       
   678         AddChatString(#3 + shortstring(trcmd[sidCmdHta]));
       
   679         AddChatString(#3 + shortstring(trcmd[sidCmdHya]));
       
   680         AddChatString(#3 + shortstring(trcmd[sidCmdHurrah]));
       
   681         AddChatString(#3 + shortstring(trcmd[sidCmdIlovelotsoflemonade]));
       
   682         AddChatString(#3 + shortstring(trcmd[sidCmdJuggle]));
       
   683         AddChatString(#3 + shortstring(trcmd[sidCmdRollup]));
       
   684         AddChatString(#3 + shortstring(trcmd[sidCmdShrug]));
       
   685         AddChatString(#3 + shortstring(trcmd[sidCmdWave]));
       
   686         exit
       
   687         end;
       
   688 
       
   689     if (copy(s, 2, 9) = 'help room') then
       
   690         begin
       
   691         if (gameType = gmtNet) then
       
   692             SendConsoleCommand('/help')
       
   693         else
       
   694             AddChatString(#0 + shortstring(trcmd[sidCmdHelpRoomFail]));
       
   695         exit;
       
   696         end;
       
   697 
       
   698     if (copy(s, 2, 4) = 'help') then
       
   699         begin
       
   700         AddChatString(#3 + shortstring(trcmd[sidCmdHeaderBasic]));
       
   701         if gameType = gmtNet then
       
   702             AddChatString(#3 + shortstring(trcmd[sidCmdPauseNet]))
       
   703         else
       
   704             AddChatString(#3 + shortstring(trcmd[sidCmdPause]));
       
   705         AddChatString(#3 + shortstring(trcmd[sidCmdFullscreen]));
       
   706         AddChatString(#3 + shortstring(trcmd[sidCmdQuit]));
       
   707         if gameType <> gmtNet then
       
   708             AddChatString(#3 + shortstring(trcmd[sidLua]));
       
   709         // history and help commands needs to be close to the end because they are always visible
       
   710         // with a short chat history length.
       
   711         AddChatString(#3 + shortstring(trcmd[sidCmdTeam]));
       
   712         AddChatString(#3 + shortstring(trcmd[sidCmdMe]));
       
   713         AddChatString(#3 + shortstring(trcmd[sidCmdTogglechat]));
       
   714         AddChatString(#3 + shortstring(trcmd[sidCmdHistory]));
       
   715         AddChatString(#3 + shortstring(trcmd[sidCmdHelp]));
       
   716         AddChatString(#3 + shortstring(trcmd[sidCmdHelpTaunts]));
       
   717         if gameType = gmtNet then
       
   718             AddChatString(#3 + shortstring(trcmd[sidCmdHelpRoom]));
   627         exit
   719         exit
   628         end;
   720         end;
   629 
   721 
   630     // hedghog animations/taunts and engine commands
   722     // hedghog animations/taunts and engine commands
   631     if (not CurrentTeam^.ExtDriven) and (CurrentTeam^.Hedgehogs[0].BotLevel = 0) then
   723     if (not CurrentTeam^.ExtDriven) and (CurrentTeam^.Hedgehogs[0].BotLevel = 0) then
   645             exit
   737             exit
   646             end;
   738             end;
   647 
   739 
   648     if (gameType = gmtNet) then
   740     if (gameType = gmtNet) then
   649         SendConsoleCommand(s)
   741         SendConsoleCommand(s)
       
   742     else
       
   743         AddChatString(#0 + shortstring(trcmd[sidCmdUnknown]));
   650     end
   744     end
   651 else
   745 else
   652     begin
   746     begin
   653     if liveLua then
   747     if liveLua then
   654         LuaParseString(s)
   748         LuaParseString(s)
  1190     SendIPC('s' + s);
  1284     SendIPC('s' + s);
  1191 
  1285 
  1192     if copy(s, 1, 4) = '/me ' then
  1286     if copy(s, 1, 4) = '/me ' then
  1193         s:= #2 + '* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4)
  1287         s:= #2 + '* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4)
  1194     else
  1288     else
  1195         s:= #1 + UserNick + ': ' + s;
  1289         s:= #1 + Format(shortstring(trmsg[sidChat]), UserNick, s);
  1196 
  1290 
  1197     AddChatString(s)
  1291     AddChatString(s)
  1198 end;
  1292 end;
  1199 
  1293 
  1200 procedure chTeamSay(var s: shortstring);
  1294 procedure chTeamSay(var s: shortstring);
  1201 begin
  1295 begin
  1202     SendIPC('b' + s);
  1296     SendIPC('b' + s);
  1203 
  1297 
  1204     s:= #4 + '[Team] ' + UserNick + ': ' + s;
  1298     s:= #4 + Format(shortstring(trmsg[sidChatTeam]), UserNick, s);
  1205 
  1299 
  1206     AddChatString(s)
  1300     AddChatString(s)
  1207 end;
  1301 end;
  1208 
  1302 
  1209 procedure chHistory(var s: shortstring);
  1303 procedure chHistory(var s: shortstring);
  1237     //SDL_EnableKeyRepeat(200,45);
  1331     //SDL_EnableKeyRepeat(200,45);
  1238     if length(s) = 0 then
  1332     if length(s) = 0 then
  1239         SetLine(InputStr, '', true)
  1333         SetLine(InputStr, '', true)
  1240     else
  1334     else
  1241         begin
  1335         begin
  1242         SetLine(InputStr, '/team ', true);
  1336         SetLine(InputStr, '/clan ', true);
  1243         cursorPos:= 6;
  1337         cursorPos:= 6;
  1244         UpdateCursorCoords();
  1338         UpdateCursorCoords();
  1245         end;
  1339         end;
  1246 end;
  1340 end;
  1247 
  1341