From 7454c62ff2252a0850c16bb1e1d04cb3fd465ff5 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Mon, 5 Aug 2019 22:59:37 -0700 Subject: [PATCH] Upgraded ChatBox and fixed FocusChat hotkey Upgraded ChatBox to use Keybinds. Put cursor at the end of text of ChatBox history. Fixed FocusChat hotkey getting called when typing in a LineEdit. Added Keybinds. --- Content.Client/Chat/ChatBox.cs | 21 ++++++------ .../GameTicking/ClientGameTicker.cs | 29 ++++++++-------- Resources/keybinds.yml | 33 ++++++++++++++++++- RobustToolbox | 2 +- 4 files changed, 60 insertions(+), 25 deletions(-) diff --git a/Content.Client/Chat/ChatBox.cs b/Content.Client/Chat/ChatBox.cs index 74717204fe..50b095833d 100644 --- a/Content.Client/Chat/ChatBox.cs +++ b/Content.Client/Chat/ChatBox.cs @@ -8,6 +8,7 @@ using Robust.Shared.Maths; using Robust.Shared.Utility; using Robust.Shared.Localization; using Robust.Shared.IoC; +using Robust.Shared.Input; namespace Content.Client.Chat { @@ -84,7 +85,7 @@ namespace Content.Client.Chat vBox.AddChild(contentMargin); Input = new LineEdit(); - Input.OnKeyDown += InputKeyDown; + Input.OnKeyBindDown += InputKeyBindDown; Input.OnTextEntered += Input_OnTextEntered; vBox.AddChild(Input); @@ -133,16 +134,15 @@ namespace Content.Client.Chat Input.GrabKeyboardFocus(); } - private void InputKeyDown(GUIKeyEventArgs e) + private void InputKeyBindDown(GUIBoundKeyEventArgs args) { - if (e.Key == Keyboard.Key.Escape) + if (args.Function == EngineKeyFunctions.TextReleaseFocus) { Input.ReleaseKeyboardFocus(); - e.Handle(); + args.Handle(); return; } - - if (e.Key == Keyboard.Key.Up) + else if (args.Function == EngineKeyFunctions.TextHistoryPrev) { if (_inputIndex == -1 && _inputHistory.Count != 0) { @@ -158,12 +158,12 @@ namespace Content.Client.Chat { Input.Text = _inputHistory[_inputIndex]; } + Input.CursorPos = Input.Text.Length; - e.Handle(); + args.Handle(); return; } - - if (e.Key == Keyboard.Key.Down) + else if (args.Function == EngineKeyFunctions.TextHistoryNext) { if (_inputIndex == 0) { @@ -176,8 +176,9 @@ namespace Content.Client.Chat _inputIndex--; Input.Text = _inputHistory[_inputIndex]; } + Input.CursorPos = Input.Text.Length; - e.Handle(); + args.Handle(); } } diff --git a/Content.Client/GameTicking/ClientGameTicker.cs b/Content.Client/GameTicking/ClientGameTicker.cs index 59cce13532..a112b66431 100644 --- a/Content.Client/GameTicking/ClientGameTicker.cs +++ b/Content.Client/GameTicking/ClientGameTicker.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using Content.Client.Chat; using Content.Client.Interfaces; @@ -18,6 +18,7 @@ using Robust.Shared.Input; using Robust.Shared.Interfaces.Network; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Players; using Robust.Shared.Timing; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -188,11 +189,7 @@ namespace Content.Client.GameTicking _lobby.ServerName.Text = _baseClient.GameInfo.ServerName; _inputManager.SetInputCommand(ContentKeyFunctions.FocusChat, - InputCmdHandler.FromDelegate(session => - { - _lobby.Chat.Input.IgnoreNext = true; - _lobby.Chat.Input.GrabKeyboardFocus(); - })); + InputCmdHandler.FromDelegate(s => _focusChat(_lobby.Chat))); _updateLobbyUi(); @@ -237,19 +234,25 @@ namespace Content.Client.GameTicking _lobby = null; } - _inputManager.SetInputCommand(ContentKeyFunctions.FocusChat, - InputCmdHandler.FromDelegate(session => - { - _gameChat.Input.IgnoreNext = true; - _gameChat.Input.GrabKeyboardFocus(); - })); - _gameChat = new ChatBox(); _userInterfaceManager.StateRoot.AddChild(_gameChat); _userInterfaceManager.StateRoot.AddChild(_gameHud.RootControl); _chatManager.SetChatBox(_gameChat); _gameChat.DefaultChatFormat = "say \"{0}\""; _gameChat.Input.PlaceHolder = _localization.GetString("Say something! [ for OOC"); + + _inputManager.SetInputCommand(ContentKeyFunctions.FocusChat, + InputCmdHandler.FromDelegate(s => _focusChat(_gameChat))); + } + + private void _focusChat(ChatBox chat) + { + if (_userInterfaceManager.KeyboardFocused != null) + { + return; + } + chat.Input.IgnoreNext = true; + chat.Input.GrabKeyboardFocus(); } private enum TickerState diff --git a/Resources/keybinds.yml b/Resources/keybinds.yml index b72e6baf7c..a7b5a94466 100644 --- a/Resources/keybinds.yml +++ b/Resources/keybinds.yml @@ -99,4 +99,35 @@ binds: - function: MouseMiddle type: state key: MouseMiddle - canFocus: true \ No newline at end of file + canFocus: true +- function: TextCursorLeft + type: state + key: Left +- function: TextCursorRight + type: state + key: Right +- function: TextBackspace + type: state + key: BackSpace +- function: TextSubmit + type: state + key: Return +- function: TextSubmit + type: state + key: NumpadEnter +- function: TextPaste + type: state + key: V + mod1: Control +- function: TextHistoryPrev + type: state + key: Up +- function: TextHistoryNext + type: state + key: Down +- function: TextReleaseFocus + type: state + key: Escape +- function: TextScrollToBottom + type: state + key: PageDown \ No newline at end of file diff --git a/RobustToolbox b/RobustToolbox index 6c6764593b..7374fc5894 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit 6c6764593b6c1df6a3be03f3e8c2c1aea0fe9448 +Subproject commit 7374fc5894fb81ae8581e0bf66c734b455337c8b