# HG changeset patch # User Wuzzy # Date 1684965298 -7200 # Node ID 6a985a680c448c87e2447198b00a8270797a0b61 # Parent 416bca0a172cd3767679ad6734ad598704677e75 Don't destroy chat when window loses focus (bug 623) diff -r 416bca0a172c -r 6a985a680c44 hedgewars/uChat.pas --- a/hedgewars/uChat.pas Wed May 24 21:23:33 2023 +0200 +++ b/hedgewars/uChat.pas Wed May 24 23:54:58 2023 +0200 @@ -28,6 +28,7 @@ procedure ReloadLines; procedure CleanupInput; procedure CloseChat; +procedure RestoreChat; procedure AddChatString(s: shortstring); procedure DrawChat; procedure KeyPressChat(keysym: TSDL_Keysym); @@ -55,6 +56,7 @@ var Strs: array[0 .. MaxStrIndex] of TChatLine; MStrs: array[0 .. MaxStrIndex] of shortstring; LocalStrs: array[0 .. MaxStrIndex] of shortstring; + oldInput: shortstring; missedCount: LongWord; lastStr: LongWord; localLastStr: LongInt; @@ -783,13 +785,43 @@ ResetKbd; end; +procedure OpenChat(s: shortstring); +var i: Integer; +begin + isInChatMode:= true; + SDL_StopTextInput(); + SDL_StartTextInput(); + //Make REALLY sure unexpected events are flushed (1 time is insufficient as of SDL 2.0.7) + for i := 1 to 2 do + begin + SDL_PumpEvents(); + SDL_FlushEvent(SDL_TEXTINPUT); + end; + if length(s) = 0 then + SetLine(InputStr, '', true) + else + begin + SetLine(InputStr, s, true); + cursorPos:= length(s); + UpdateCursorCoords(); + end; +end; + procedure CloseChat; begin + oldInput:= InputStr.s; SetLine(InputStr, '', true); ResetCursor(); CleanupInput(); end; +procedure RestoreChat; +begin + if length(oldInput) > 0 then + OpenChat(oldInput); + oldInput:= ''; +end; + procedure DelBytesFromInputStrBack(endIdx: integer; count: byte); var startIdx: integer; begin @@ -1070,7 +1102,9 @@ SetLine(InputStr, '', true); ResetCursor(); end - else CleanupInput + else + CleanupInput; + oldInput:= ''; end; SDL_SCANCODE_RETURN, SDL_SCANCODE_KP_ENTER: begin @@ -1345,27 +1379,12 @@ end; procedure chChat(var s: shortstring); -var i: Integer; begin s:= s; // avoid compiler hint - isInChatMode:= true; - SDL_StopTextInput(); - SDL_StartTextInput(); - //Make REALLY sure unexpected events are flushed (1 time is insufficient as of SDL 2.0.7) - for i := 1 to 2 do - begin - SDL_PumpEvents(); - SDL_FlushEvent(SDL_TEXTINPUT); - end; - //SDL_EnableKeyRepeat(200,45); if length(s) = 0 then - SetLine(InputStr, '', true) + OpenChat('') else - begin - SetLine(InputStr, '/clan ', true); - cursorPos:= 6; - UpdateCursorCoords(); - end; + OpenChat('/clan '); end; procedure initModule; diff -r 416bca0a172c -r 6a985a680c44 hedgewars/uCommandHandlers.pas --- a/hedgewars/uCommandHandlers.pas Wed May 24 21:23:33 2023 +0200 +++ b/hedgewars/uCommandHandlers.pas Wed May 24 23:54:58 2023 +0200 @@ -49,15 +49,16 @@ begin s:= s; // avoid compiler hint if (GameState = gsGame) then - begin + begin CloseChat; GameState:= gsConfirm; - end - else begin + end + else if GameState = gsConfirm then + begin GameState:= gsGame; - end; - + RestoreChat; + end; updateCursorVisibility; end;