Rebind chat hotkeys to prevent Tab changing chat mode

Enter/Shift+Enter now toggle team/all chat respectively and Shift+Tab switches chat mode instead of Tab
This commit is contained in:
Abdurrahmaan Iqbal
2019-12-15 14:50:12 +00:00
committed by Paul Chote
parent 6967c1fff3
commit a8900d9860
16 changed files with 70 additions and 24 deletions

View File

@@ -88,7 +88,6 @@ namespace OpenRA.Mods.Common.Widgets
Keycode.RCTRL, Keycode.LCTRL,
Keycode.RALT, Keycode.LALT,
Keycode.RGUI, Keycode.LGUI,
Keycode.RETURN, Keycode.KP_ENTER
};
public override bool HandleKeyPress(KeyInput e)

View File

@@ -13,6 +13,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Commands;
using OpenRA.Mods.Common.Lint;
using OpenRA.Mods.Common.Traits;
using OpenRA.Network;
using OpenRA.Primitives;
@@ -20,6 +21,7 @@ using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
{
[ChromeLogicArgsHotkeys("OpenTeamChat", "OpenGeneralChat")]
public class IngameChatLogic : ChromeLogic
{
readonly OrderManager orderManager;
@@ -135,14 +137,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return true;
};
chatText.OnTabKey = _ =>
chatText.OnTabKey = e =>
{
var previousText = chatText.Text;
chatText.Text = tabCompletion.Complete(chatText.Text);
chatText.CursorPosition = chatText.Text.Length;
if (chatText.Text == previousText && !disableTeamChat)
teamChat ^= true;
if (!chatMode.Key.IsActivatedBy(e) || chatMode.IsDisabled())
{
chatText.Text = tabCompletion.Complete(chatText.Text);
chatText.CursorPosition = chatText.Text.Length;
}
else
chatMode.OnKeyPress(e);
return true;
};
@@ -159,6 +162,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (!isMenuChat)
{
var openTeamChatKey = new HotkeyReference();
if (logicArgs.TryGetValue("OpenTeamChatKey", out var hotkeyArg))
openTeamChatKey = modData.Hotkeys[hotkeyArg.Value];
var openGeneralChatKey = new HotkeyReference();
if (logicArgs.TryGetValue("OpenGeneralChatKey", out hotkeyArg))
openGeneralChatKey = modData.Hotkeys[hotkeyArg.Value];
var chatClose = chatChrome.Get<ButtonWidget>("CHAT_CLOSE");
chatClose.OnClick += CloseChat;
@@ -167,8 +178,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (e.Event == KeyInputEvent.Up)
return false;
if (!chatChrome.IsVisible() && (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER))
if (!chatChrome.IsVisible() && (openTeamChatKey.IsActivatedBy(e) || openGeneralChatKey.IsActivatedBy(e)))
{
teamChat = !disableTeamChat && !openGeneralChatKey.IsActivatedBy(e);
OpenChat();
return true;
}
@@ -229,6 +242,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
chatChrome.Visible = false;
chatText.YieldKeyboardFocus();
chatOverlay.Visible = true;
Ui.ResetTooltips();
}
public void AddChatLineWrapper(string name, Color nameColor, string text, Color textColor)

View File

@@ -423,16 +423,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return true;
};
chatTextField.OnTabKey = _ =>
chatTextField.OnTabKey = e =>
{
var previousText = chatTextField.Text;
chatTextField.Text = tabCompletion.Complete(chatTextField.Text);
chatTextField.CursorPosition = chatTextField.Text.Length;
if (chatTextField.Text == previousText)
return SwitchTeamChat();
if (!chatMode.Key.IsActivatedBy(e) || chatMode.IsDisabled())
{
chatTextField.Text = tabCompletion.Complete(chatTextField.Text);
chatTextField.CursorPosition = chatTextField.Text.Length;
}
else
return true;
chatMode.OnKeyPress(e);
return true;
};
chatTextField.OnEscKey = _ => { chatTextField.Text = ""; return true; };
@@ -501,13 +502,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Game.Sound.PlayNotification(modRules, null, "Sounds", chatLineSound, null);
}
bool SwitchTeamChat()
{
if (!disableTeamChat)
teamChat ^= true;
return true;
}
void UpdateCurrentMap()
{
mapStatus = orderManager.LobbyInfo.GlobalSettings.MapStatus;