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.RCTRL, Keycode.LCTRL,
Keycode.RALT, Keycode.LALT, Keycode.RALT, Keycode.LALT,
Keycode.RGUI, Keycode.LGUI, Keycode.RGUI, Keycode.LGUI,
Keycode.RETURN, Keycode.KP_ENTER
}; };
public override bool HandleKeyPress(KeyInput e) public override bool HandleKeyPress(KeyInput e)

View File

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

View File

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

View File

@@ -4,6 +4,8 @@ Container@CHAT_PANEL:
Width: 550 Width: 550
Height: 194 Height: 194
Logic: IngameChatLogic Logic: IngameChatLogic
OpenTeamChatKey: OpenTeamChat
OpenGeneralChatKey: OpenGeneralChat
Children: Children:
Container@CHAT_OVERLAY: Container@CHAT_OVERLAY:
Width: PARENT_RIGHT - 24 Width: PARENT_RIGHT - 24
@@ -25,6 +27,9 @@ Container@CHAT_PANEL:
Height: 25 Height: 25
Text: Team Text: Team
Font: Bold Font: Bold
Key: Tab SHIFT
TooltipText: Toggle chat mode
TooltipContainer: TOOLTIP_CONTAINER
TextField@CHAT_TEXTFIELD: TextField@CHAT_TEXTFIELD:
X: 55 X: 55
Y: PARENT_BOTTOM - HEIGHT Y: PARENT_BOTTOM - HEIGHT

View File

@@ -15,6 +15,9 @@ Container@CHAT_CONTAINER:
Height: 25 Height: 25
Text: Team Text: Team
Font: Bold Font: Bold
Key: Tab SHIFT
TooltipText: Toggle chat mode
TooltipContainer: TOOLTIP_CONTAINER
TextField@CHAT_TEXTFIELD: TextField@CHAT_TEXTFIELD:
X: 55 X: 55
Y: PARENT_BOTTOM - HEIGHT Y: PARENT_BOTTOM - HEIGHT

View File

@@ -128,6 +128,9 @@ Container@SERVER_LOBBY:
Height: 25 Height: 25
Text: Team Text: Team
Font: Bold Font: Bold
Key: Tab SHIFT
TooltipText: Toggle chat mode
TooltipContainer: TOOLTIP_CONTAINER
TextField@CHAT_TEXTFIELD: TextField@CHAT_TEXTFIELD:
X: 55 X: 55
Y: PARENT_BOTTOM - HEIGHT Y: PARENT_BOTTOM - HEIGHT

View File

@@ -25,6 +25,9 @@ Container@HOTKEYS_PANEL:
Music Commands: Music Commands:
Template: TWO_COLUMN Template: TWO_COLUMN
Types: Music Types: Music
Chat Commands:
Template: TWO_COLUMN
Types: Chat
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: PARENT_BOTTOM Height: PARENT_BOTTOM
Children: Children:

View File

@@ -153,6 +153,7 @@ Hotkeys:
common|hotkeys/production-peractor.yaml common|hotkeys/production-peractor.yaml
common|hotkeys/supportpowers.yaml common|hotkeys/supportpowers.yaml
common|hotkeys/viewport.yaml common|hotkeys/viewport.yaml
common|hotkeys/chat.yaml
cnc|hotkeys.yaml cnc|hotkeys.yaml
LoadScreen: CncLoadScreen LoadScreen: CncLoadScreen

View File

@@ -4,6 +4,8 @@ Container@CHAT_PANEL:
Width: 550 Width: 550
Height: 194 Height: 194
Logic: IngameChatLogic Logic: IngameChatLogic
OpenTeamChatKey: OpenTeamChat
OpenGeneralChatKey: OpenGeneralChat
Children: Children:
Container@CHAT_OVERLAY: Container@CHAT_OVERLAY:
Width: PARENT_RIGHT - 24 Width: PARENT_RIGHT - 24
@@ -25,6 +27,9 @@ Container@CHAT_PANEL:
Height: 25 Height: 25
Text: Team Text: Team
Font: Bold Font: Bold
Key: Tab SHIFT
TooltipText: Toggle chat mode
TooltipContainer: TOOLTIP_CONTAINER
TextField@CHAT_TEXTFIELD: TextField@CHAT_TEXTFIELD:
X: 55 X: 55
Y: PARENT_BOTTOM - HEIGHT Y: PARENT_BOTTOM - HEIGHT

View File

@@ -15,6 +15,9 @@ Container@CHAT_CONTAINER:
Height: 25 Height: 25
Text: Team Text: Team
Font: Bold Font: Bold
Key: Tab SHIFT
TooltipText: Toggle chat mode
TooltipContainer: TOOLTIP_CONTAINER
TextField@CHAT_TEXTFIELD: TextField@CHAT_TEXTFIELD:
X: 55 X: 55
Y: PARENT_BOTTOM - HEIGHT Y: PARENT_BOTTOM - HEIGHT

View File

@@ -131,6 +131,9 @@ Background@SERVER_LOBBY:
Height: 25 Height: 25
Text: Team Text: Team
Font: Bold Font: Bold
Key: Tab SHIFT
TooltipText: Toggle chat mode
TooltipContainer: TOOLTIP_CONTAINER
TextField@CHAT_TEXTFIELD: TextField@CHAT_TEXTFIELD:
X: 55 X: 55
Y: PARENT_BOTTOM - HEIGHT Y: PARENT_BOTTOM - HEIGHT

View File

@@ -25,6 +25,9 @@ Container@HOTKEYS_PANEL:
Music Commands: Music Commands:
Template: TWO_COLUMN Template: TWO_COLUMN
Types: Music Types: Music
Chat Commands:
Template: TWO_COLUMN
Types: Chat
Width: PARENT_RIGHT - 10 Width: PARENT_RIGHT - 10
Height: PARENT_BOTTOM Height: PARENT_BOTTOM
Children: Children:

View File

@@ -0,0 +1,7 @@
OpenTeamChat: Return
Description: Open Team Chat
Types: Chat, Player, Spectator
OpenGeneralChat: Return Shift
Description: Open General Chat
Types: Chat, Player, Spectator

View File

@@ -138,6 +138,7 @@ Hotkeys:
common|hotkeys/production-common.yaml common|hotkeys/production-common.yaml
common|hotkeys/supportpowers.yaml common|hotkeys/supportpowers.yaml
common|hotkeys/viewport.yaml common|hotkeys/viewport.yaml
common|hotkeys/chat.yaml
d2k|hotkeys.yaml d2k|hotkeys.yaml
LoadScreen: LogoStripeLoadScreen LoadScreen: LogoStripeLoadScreen

View File

@@ -159,6 +159,7 @@ Hotkeys:
common|hotkeys/production-common.yaml common|hotkeys/production-common.yaml
common|hotkeys/supportpowers.yaml common|hotkeys/supportpowers.yaml
common|hotkeys/viewport.yaml common|hotkeys/viewport.yaml
common|hotkeys/chat.yaml
ra|hotkeys.yaml ra|hotkeys.yaml
LoadScreen: LogoStripeLoadScreen LoadScreen: LogoStripeLoadScreen

View File

@@ -196,6 +196,7 @@ Hotkeys:
common|hotkeys/production-common.yaml common|hotkeys/production-common.yaml
common|hotkeys/supportpowers.yaml common|hotkeys/supportpowers.yaml
common|hotkeys/viewport.yaml common|hotkeys/viewport.yaml
common|hotkeys/chat.yaml
ts|hotkeys.yaml ts|hotkeys.yaml
LoadScreen: LogoStripeLoadScreen LoadScreen: LogoStripeLoadScreen