hedgewars/uChat.pas
branchui-scaling
changeset 15304 c4fd2813b127
parent 13389 24b531dcebe7
parent 15288 22f2fd8a3d2c
child 15686 0b99e220568a
--- a/hedgewars/uChat.pas	Wed May 16 18:22:28 2018 +0200
+++ b/hedgewars/uChat.pas	Wed Jul 31 23:14:27 2019 +0200
@@ -35,7 +35,8 @@
 procedure TextInput(var event: TSDL_TextInputEvent);
 
 implementation
-uses uConsts, uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO, uScript, uRenderUtils, uStore;
+uses uConsts, uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO, uScript, uRenderUtils, uStore, uLocale
+     {$IFDEF USE_VIDEO_RECORDING}, uVideoRec{$ENDIF};
 
 const MaxStrIndex = 27;
       MaxInputStrLen = 200;
@@ -71,7 +72,7 @@
 
 const
     colors: array[#0..#9] of TSDL_Color = (
-            (r:$FF; g:$FF; b:$FF; a:$FF), // #0 unused, feel free to take it for anything
+            (r:$FF; g:$FF; b:$00; a:$FF), // #0 warning message [Yellow]
             (r:$FF; g:$FF; b:$FF; a:$FF), // #1 chat message [White]
             (r:$FF; g:$00; b:$FF; a:$FF), // #2 action message [Purple]
             (r:$90; g:$FF; b:$90; a:$FF), // #3 join/leave message [Lime]
@@ -387,8 +388,13 @@
     visibleCount:= 0;
 
 // draw chat lines with some distance from screen border
+{$IFDEF USE_TOUCH_INTERFACE}
+left:= 4 - cScreenWidth div 2;
+top := 55 + visibleCount * ClHeight; // we start with input line (if any)
+{$ELSE}
 left:= 4 - cScreenWidth div 2;
 top := 10 + visibleCount * ClHeight; // we start with input line (if any)
+{$ENDIF}
 
 // draw chat input line first and under all other lines
 if isInChatMode and (InputStr.Tex <> nil) then
@@ -449,7 +455,7 @@
             // default to current hedgehog (if own) or first hedgehog
             if SpeechHogNumber = 0 then
                 begin
-                if not CurrentTeam^.ExtDriven then
+                if (not CurrentTeam^.ExtDriven) and (not CurrentHedgehog^.Unplaced) then
                     SpeechHogNumber:= CurrentTeam^.CurrHedgehog + 1
                 else
                     SpeechHogNumber:= 1;
@@ -525,12 +531,15 @@
 
 t:= LocalTeam;
 x:= 0;
+// speech bubble
 if (s[1] = '"') and (s[Length(s)] = '"')
     then x:= 1
 
+// thinking bubble
 else if (s[1] = '''') and (s[Length(s)] = '''') then
     x:= 2
 
+// yelling bubble
 else if (s[1] = '-') and (s[Length(s)] = '-') then
     x:= 3;
 
@@ -550,7 +559,22 @@
 
 if (s[1] = '/') then
     begin
-    // These 3 are same as above, only are to make the hedgehog say it on next attack
+    if (Length(s) <= 1) then
+        begin
+        // empty chat command
+        AddChatString(#0 + shortstring(trcmd[sidCmdUnknown]));
+        exit;
+        end;
+
+    // Ignore message-type commands with empty argument list
+    if (copy(s, 2, 2) = 'me') and (Length(s) = 3) then
+        exit;
+    if ((copy(s, 2, 3) = 'hsa') or (copy(s, 2, 3) = 'hta') or (copy(s, 2, 3) = 'hya')) and (Length(s) = 4) then
+        exit;
+    if ((copy(s, 2, 4) = 'team') or (copy(s, 2, 4) = 'clan')) and (Length(s) = 5) then
+        exit;
+
+    // Speech bubble, but on next attack
     if (copy(s, 2, 4) = 'hsa ') then
         begin
         if CurrentTeam^.ExtDriven then
@@ -560,6 +584,7 @@
         exit
         end;
 
+    // Thinking bubble, but on next attack
     if (copy(s, 2, 4) = 'hta ') then
         begin
         if CurrentTeam^.ExtDriven then
@@ -569,6 +594,7 @@
         exit
         end;
 
+    // Yelling bubble, but on next attack
     if (copy(s, 2, 4) = 'hya ') then
         begin
         if CurrentTeam^.ExtDriven then
@@ -578,9 +604,11 @@
         exit
         end;
 
-    if (copy(s, 2, 5) = 'team ') and (length(s) > 6) then
+    // "/clan" or "/team" ("/team" is an alias for "/clan")
+    if ((copy(s, 2, 5) = 'clan ') or (copy(s, 2, 5) = 'team ')) then
         begin
-        ParseCommand(s, true);
+        if (Length(s) > 6) then
+            ParseCommand('team ' + copy(s, 7, Length(s) - 6), true);
         exit
         end;
 
@@ -600,6 +628,7 @@
 
     // debugging commands
     if (copy(s, 2, 7) = 'debugvl') then
+        // This command intentionally not documented in /help
         begin
         cViewLimitsDebug:= (not cViewLimitsDebug);
         UpdateViewLimits();
@@ -608,22 +637,85 @@
 
     if (copy(s, 2, 3) = 'lua') then
         begin
+        LuaCmdUsed:= true;
         AddFileLog('/lua issued');
+{$IFDEF USE_VIDEO_RECORDING}
+        if flagPrerecording then
+            begin
+            AddFileLog('Force-stopping prerecording! Lua commands can not be recorded');
+            StopPreRecording;
+            end;
+{$ENDIF}
         if gameType <> gmtNet then
             begin
             liveLua:= (not liveLua);
             if liveLua then
                 begin
                 AddFileLog('[Lua] chat input string parsing enabled');
-                AddChatString(#3 + 'Lua parsing: ON');
+                AddChatString(#3 + shortstring(trmsg[sidLuaParsingOn]));
                 end
             else
                 begin
                 AddFileLog('[Lua] chat input string parsing disabled');
-                AddChatString(#3 + 'Lua parsing: OFF');
+                AddChatString(#3 + shortstring(trmsg[sidLuaParsingOff]));
                 end;
             UpdateInputLinePrefix();
-            end;
+            end
+        else
+            AddChatString(#5 + shortstring(trmsg[sidLuaParsingDenied]));
+        exit
+        end;
+
+    // Help commands
+    if (copy(s, 2, 11) = 'help taunts') then
+        begin
+        AddChatString(#3 + shortstring(trcmd[sidCmdHeaderTaunts]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdSpeech]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdThink]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdYell]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdSpeechNumberHint]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdHsa]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdHta]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdHya]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdHurrah]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdIlovelotsoflemonade]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdJuggle]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdRollup]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdShrug]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdWave]));
+        exit
+        end;
+
+    if (copy(s, 2, 9) = 'help room') then
+        begin
+        if (gameType = gmtNet) then
+            SendConsoleCommand('/help')
+        else
+            AddChatString(#0 + shortstring(trcmd[sidCmdHelpRoomFail]));
+        exit;
+        end;
+
+    if (copy(s, 2, 4) = 'help') then
+        begin
+        AddChatString(#3 + shortstring(trcmd[sidCmdHeaderBasic]));
+        if gameType = gmtNet then
+            AddChatString(#3 + shortstring(trcmd[sidCmdPauseNet]))
+        else
+            AddChatString(#3 + shortstring(trcmd[sidCmdPause]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdFullscreen]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdQuit]));
+        if gameType <> gmtNet then
+            AddChatString(#3 + shortstring(trcmd[sidLua]));
+        // history and help commands needs to be close to the end because they are always visible
+        // with a short chat history length.
+        AddChatString(#3 + shortstring(trcmd[sidCmdTeam]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdMe]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdTogglechat]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdHistory]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdHelp]));
+        AddChatString(#3 + shortstring(trcmd[sidCmdHelpTaunts]));
+        if gameType = gmtNet then
+            AddChatString(#3 + shortstring(trcmd[sidCmdHelpRoom]));
         exit
         end;
 
@@ -647,6 +739,8 @@
 
     if (gameType = gmtNet) then
         SendConsoleCommand(s)
+    else
+        AddChatString(#0 + shortstring(trcmd[sidCmdUnknown]));
     end
 else
     begin
@@ -1192,7 +1286,7 @@
     if copy(s, 1, 4) = '/me ' then
         s:= #2 + '* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4)
     else
-        s:= #1 + UserNick + ': ' + s;
+        s:= #1 + Format(shortstring(trmsg[sidChat]), UserNick, s);
 
     AddChatString(s)
 end;
@@ -1201,7 +1295,7 @@
 begin
     SendIPC('b' + s);
 
-    s:= #4 + '[Team] ' + UserNick + ': ' + s;
+    s:= #4 + Format(shortstring(trmsg[sidChatTeam]), UserNick, s);
 
     AddChatString(s)
 end;
@@ -1239,7 +1333,7 @@
         SetLine(InputStr, '', true)
     else
         begin
-        SetLine(InputStr, '/team ', true);
+        SetLine(InputStr, '/clan ', true);
         cursorPos:= 6;
         UpdateCursorCoords();
         end;