allow TAB to switch team/all chat when nothing is auto-completed

This commit is contained in:
Matthias Mailänder
2014-11-30 17:32:44 +01:00
parent 93ef16d657
commit 70e1ceaa04
2 changed files with 32 additions and 18 deletions

View File

@@ -35,6 +35,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
readonly TabCompletionLogic tabCompletion = new TabCompletionLogic();
bool disableTeamChat;
bool teamChat;
bool inDialog;
@@ -47,7 +48,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
chatTraits = world.WorldActor.TraitsImplementing<INotifyChat>().ToList();
var players = world.Players.Where(p => p != world.LocalPlayer && !p.NonCombatant && !p.IsBot);
var disableTeamChat = world.LocalPlayer == null || world.LobbyInfo.IsSinglePlayer || !players.Any(p => p.IsAlliedWith(world.LocalPlayer));
disableTeamChat = world.LocalPlayer == null || world.LobbyInfo.IsSinglePlayer || !players.Any(p => p.IsAlliedWith(world.LocalPlayer));
teamChat = !disableTeamChat;
tabCompletion.Commands = chatTraits.OfType<ChatCommands>().SelectMany(x => x.Commands.Keys).ToList();
@@ -72,12 +73,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
chatMode.IsDisabled = () => disableTeamChat;
chatText = chatChrome.Get<TextFieldWidget>("CHAT_TEXTFIELD");
chatText.OnAltKey = () =>
{
if (!disableTeamChat)
teamChat ^= true;
return true;
};
chatText.OnEnterKey = () =>
{
var team = teamChat && !disableTeamChat;
@@ -98,11 +93,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
};
chatText.OnTabKey = () =>
{
var previousText = chatText.Text;
chatText.Text = tabCompletion.Complete(chatText.Text);
chatText.CursorPosition = chatText.Text.Length;
return true;
};
if (chatText.Text == previousText)
return SwitchTeamChat();
else
return true;
};
chatText.OnEscKey = () => { CloseChat(); return true; };
if (!inDialog)
@@ -138,6 +137,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
CloseChat();
}
bool SwitchTeamChat()
{
if (!disableTeamChat)
teamChat ^= true;
return true;
}
void UnregisterEvents()
{
orderManager.AddChatLine -= AddChatLineWrapper;

View File

@@ -55,6 +55,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
readonly TabCompletionLogic tabCompletion = new TabCompletionLogic();
readonly LabelWidget chatLabel;
bool teamChat;
// Listen for connection failures
void ConnectionStateChanged(OrderManager om)
{
@@ -487,8 +490,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (skirmishMode)
disconnectButton.Text = "Cancel";
var teamChat = false;
var chatLabel = lobby.Get<LabelWidget>("LABEL_CHATTYPE");
chatLabel = lobby.Get<LabelWidget>("LABEL_CHATTYPE");
var chatTextField = lobby.Get<TextFieldWidget>("CHAT_TEXTFIELD");
chatTextField.TakeKeyboardFocus();
@@ -505,17 +507,16 @@ namespace OpenRA.Mods.RA.Widgets.Logic
chatTextField.Text = "";
return true;
};
chatTextField.OnAltKey = () =>
{
teamChat ^= true;
chatLabel.Text = teamChat ? "Team:" : "Chat:";
return true;
};
chatTextField.OnTabKey = () =>
{
var previousText = chatTextField.Text;
chatTextField.Text = tabCompletion.Complete(chatTextField.Text);
chatTextField.CursorPosition = chatTextField.Text.Length;
return true;
if (chatTextField.Text == previousText)
return SwitchTeamChat();
else
return true;
};
chatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY");
@@ -592,6 +593,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
Sound.PlayNotification(modRules, null, "Sounds", "ChatLine", null);
}
bool SwitchTeamChat()
{
teamChat ^= true;
chatLabel.Text = teamChat ? "Team:" : "Chat:";
return true;
}
void UpdateCurrentMap()
{
var uid = orderManager.LobbyInfo.GlobalSettings.Map;