hedgewars/uChat.pas
changeset 10312 eda8d563f677
parent 10308 7350be35b335
child 10314 6691ebaa4f3a
equal deleted inserted replaced
10311:30b5fab302f6 10312:eda8d563f677
    30 procedure DrawChat;
    30 procedure DrawChat;
    31 procedure KeyPressChat(Key, Sym: Longword);
    31 procedure KeyPressChat(Key, Sym: Longword);
    32 procedure SendHogSpeech(s: shortstring);
    32 procedure SendHogSpeech(s: shortstring);
    33 
    33 
    34 implementation
    34 implementation
    35 uses SDLh, uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO;
    35 uses SDLh, uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO, uScript, uConsole;
    36 
    36 
    37 const MaxStrIndex = 27;
    37 const MaxStrIndex = 27;
    38 
    38 
    39 type TChatLine = record
    39 type TChatLine = record
    40     Tex: PTexture;
    40     Tex: PTexture;
    55     visibleCount: LongWord;
    55     visibleCount: LongWord;
    56     InputStr: TChatLine;
    56     InputStr: TChatLine;
    57     InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char
    57     InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char
    58     ChatReady: boolean;
    58     ChatReady: boolean;
    59     showAll: boolean;
    59     showAll: boolean;
       
    60     liveLua: boolean;
    60 
    61 
    61 const
    62 const
    62     colors: array[#0..#6] of TSDL_Color = (
    63     colors: array[#0..#6] of TSDL_Color = (
    63             (r:$FF; g:$FF; b:$FF; a:$FF), // unused, feel free to take it for anything
    64             (r:$FF; g:$FF; b:$FF; a:$FF), // unused, feel free to take it for anything
    64             (r:$FF; g:$FF; b:$FF; a:$FF), // chat message [White]
    65             (r:$FF; g:$FF; b:$FF; a:$FF), // chat message [White]
   285     exit
   286     exit
   286     end;
   287     end;
   287 
   288 
   288 if (s[1] = '/') then
   289 if (s[1] = '/') then
   289     begin
   290     begin
       
   291     // put in input history
       
   292     localLastStr:= (localLastStr + 1) mod MaxStrIndex;
       
   293     LocalStrs[localLastStr]:= s;
       
   294 
   290     // These 3 are same as above, only are to make the hedgehog say it on next attack
   295     // These 3 are same as above, only are to make the hedgehog say it on next attack
   291     if (copy(s, 2, 4) = 'hsa ') then
   296     if (copy(s, 2, 4) = 'hsa ') then
   292         begin
   297         begin
   293         if CurrentTeam^.ExtDriven then
   298         if CurrentTeam^.ExtDriven then
   294             ParseCommand('/say ' + copy(s, 6, Length(s)-5), true)
   299             ParseCommand('/say ' + copy(s, 6, Length(s)-5), true)
   333         cViewLimitsDebug:= (not cViewLimitsDebug);
   338         cViewLimitsDebug:= (not cViewLimitsDebug);
   334         UpdateViewLimits();
   339         UpdateViewLimits();
   335         exit
   340         exit
   336         end;
   341         end;
   337 
   342 
       
   343     if (copy(s, 2, 3) = 'lua') then
       
   344         begin
       
   345         AddFileLog('/lua issued');
       
   346         if gameType <> gmtNet then
       
   347             begin
       
   348             liveLua:= (not liveLua);
       
   349             if liveLua then
       
   350                 begin
       
   351                 AddFileLog('[Lua] chat input string parsing enabled');
       
   352                 AddChatString(#3 + 'Lua parsing: ON');
       
   353                 end
       
   354             else
       
   355                 begin
       
   356                 AddFileLog('[Lua] chat input string parsing disabled');
       
   357                 AddChatString(#3 + 'Lua parsing: OFF');
       
   358                 end;
       
   359             end;
       
   360         exit
       
   361         end;
       
   362 
       
   363     // hedghog animations/taunts and engine commands
   338     if (not CurrentTeam^.ExtDriven) and (CurrentTeam^.Hedgehogs[0].BotLevel = 0) then
   364     if (not CurrentTeam^.ExtDriven) and (CurrentTeam^.Hedgehogs[0].BotLevel = 0) then
   339         begin
   365         begin
   340         for i:= Low(TWave) to High(TWave) do
   366         for i:= Low(TWave) to High(TWave) do
   341             if (s = Wavez[i].cmd) then
   367             if (s = Wavez[i].cmd) then
   342                 begin
   368                 begin
   350                 ParseCommand(ChatCommandz[j].ProcedureCallChatCmd, true);
   376                 ParseCommand(ChatCommandz[j].ProcedureCallChatCmd, true);
   351                 exit
   377                 exit
   352                 end;
   378                 end;
   353         end
   379         end
   354     end
   380     end
       
   381 else
       
   382     begin
       
   383     if liveLua then
       
   384         LuaParseString(s)
   355     else
   385     else
   356         ParseCommand('/say ' + s, true);
   386         ParseCommand('/say ' + s, true);
       
   387     end;
   357 end;
   388 end;
   358 
   389 
   359 procedure CleanupInput;
   390 procedure CleanupInput;
   360 begin
   391 begin
   361     FreezeEnterKey;
   392     FreezeEnterKey;
   508     history:= 0;
   539     history:= 0;
   509     visibleCount:= 0;
   540     visibleCount:= 0;
   510     showAll:= false;
   541     showAll:= false;
   511     ChatReady:= false;
   542     ChatReady:= false;
   512     missedCount:= 0;
   543     missedCount:= 0;
       
   544     liveLua:= false;
   513 
   545 
   514     inputStr.Tex := nil;
   546     inputStr.Tex := nil;
   515     for i:= 0 to MaxStrIndex do
   547     for i:= 0 to MaxStrIndex do
   516         Strs[i].Tex := nil;
   548         Strs[i].Tex := nil;
   517 end;
   549 end;