Chat channel switching improvements (#4000)

* IC is default when joining;
switch to IC channel if IC channel becomes unavailable before trying OOC

* Allow channel cycling while the textbox is focused

* Fix focus channel keybinds not actually focusing

* Whitespess

* Fix duplicate radio

* Smol CycleChatChannel cleanup

* Revert style change
This commit is contained in:
Clyybber
2021-05-15 12:28:04 +02:00
committed by GitHub
parent 8bfd9f9090
commit 914e49f867
5 changed files with 56 additions and 32 deletions

View File

@@ -7,6 +7,7 @@ using Content.Client.UserInterface;
using Content.Client.UserInterface.Stylesheets; using Content.Client.UserInterface.Stylesheets;
using Content.Client.Utility; using Content.Client.Utility;
using Content.Shared.Chat; using Content.Shared.Chat;
using Content.Shared.Input;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.ResourceManagement; using Robust.Client.ResourceManagement;
using Robust.Client.State; using Robust.Client.State;
@@ -59,7 +60,7 @@ namespace Content.Client.Chat
/// <summary> /// <summary>
/// Will be Unspecified if set to Console /// Will be Unspecified if set to Console
/// </summary> /// </summary>
public ChatChannel SelectedChannel; public ChatChannel SelectedChannel = ChatChannel.Unspecified;
/// <summary> /// <summary>
/// Default formatting string for the ClientChatConsole. /// Default formatting string for the ClientChatConsole.
@@ -279,7 +280,7 @@ namespace Content.Client.Chat
/// entries (which should not be presented to the user)</param> /// entries (which should not be presented to the user)</param>
/// <param name="unreadMessages">unread message counts for each disabled channel, values 10 or higher will show as 9+</param> /// <param name="unreadMessages">unread message counts for each disabled channel, values 10 or higher will show as 9+</param>
public void SetChannelPermissions(List<ChatChannel> selectableChannels, IReadOnlySet<ChatChannel> filterableChannels, public void SetChannelPermissions(List<ChatChannel> selectableChannels, IReadOnlySet<ChatChannel> filterableChannels,
IReadOnlyDictionary<ChatChannel, bool> channelFilters, IReadOnlyDictionary<ChatChannel, byte> unreadMessages) IReadOnlyDictionary<ChatChannel, bool> channelFilters, IReadOnlyDictionary<ChatChannel, byte> unreadMessages, bool switchIfConsole)
{ {
SelectableChannels = selectableChannels; SelectableChannels = selectableChannels;
// update the channel selector // update the channel selector
@@ -305,10 +306,15 @@ namespace Content.Client.Chat
_savedSelectedChannel = null; _savedSelectedChannel = null;
} }
if (!selectableChannels.Contains(SelectedChannel) && SelectedChannel != ChatChannel.Unspecified) if (!selectableChannels.Contains(SelectedChannel) && (switchIfConsole || SelectedChannel != ChatChannel.Unspecified))
{ {
// our previously selected channel no longer exists, default back to OOC, which should always be available // our previously selected channel no longer exists or we are still on console channel because we just joined
if (selectableChannels.Contains(ChatChannel.OOC)) if ((SelectedChannel & ChatChannel.IC) != 0 || SelectedChannel == ChatChannel.Unspecified)
{
if (!SafelySelectChannel(ChatChannel.Local))
SafelySelectChannel(ChatChannel.Dead);
}
else if (selectableChannels.Contains(ChatChannel.OOC))
{ {
SafelySelectChannel(ChatChannel.OOC); SafelySelectChannel(ChatChannel.OOC);
} }
@@ -498,6 +504,24 @@ namespace Content.Client.Chat
UserInterfaceManager.KeyboardFocused?.ReleaseKeyboardFocus(); UserInterfaceManager.KeyboardFocused?.ReleaseKeyboardFocus();
} }
public void CycleChatChannel(bool forward)
{
Input.IgnoreNext = true;
var channels = SelectableChannels;
var idx = channels.IndexOf(SelectedChannel);
if (forward)
{
idx++;
}
else
{
idx--;
}
idx = MathHelper.Mod(idx, channels.Count);
SelectChannel(channels[idx]);
}
private void InputKeyBindDown(GUIBoundKeyEventArgs args) private void InputKeyBindDown(GUIBoundKeyEventArgs args)
{ {
if (args.Function == EngineKeyFunctions.TextReleaseFocus) if (args.Function == EngineKeyFunctions.TextReleaseFocus)
@@ -507,9 +531,22 @@ namespace Content.Client.Chat
return; return;
} }
if (args.Function == ContentKeyFunctions.CycleChatChannelForward)
{
CycleChatChannel(true);
args.Handle();
return;
}
if (args.Function == ContentKeyFunctions.CycleChatChannelBackward)
{
CycleChatChannel(false);
args.Handle();
return;
}
// if we temporarily selected another channel via a prefx, undo that when we backspace on an empty input // if we temporarily selected another channel via a prefx, undo that when we backspace on an empty input
if (Input.Text.Length == 0 && _savedSelectedChannel.HasValue && if (args.Function == EngineKeyFunctions.TextBackspace && Input.Text.Length == 0 && _savedSelectedChannel.HasValue)
args.Function == EngineKeyFunctions.TextBackspace)
{ {
SafelySelectChannel(_savedSelectedChannel.Value); SafelySelectChannel(_savedSelectedChannel.Value);
_savedSelectedChannel = null; _savedSelectedChannel = null;

View File

@@ -242,7 +242,7 @@ namespace Content.Client.Chat
} }
// let our chatbox know all the new settings // let our chatbox know all the new settings
CurrentChatBox?.SetChannelPermissions(_selectableChannels, _filterableChannels, _channelFilters, _unreadMessages); CurrentChatBox?.SetChannelPermissions(_selectableChannels, _filterableChannels, _channelFilters, _unreadMessages, true);
} }
/// <summary> /// <summary>
@@ -311,7 +311,7 @@ namespace Content.Client.Chat
CurrentChatBox.FilterToggled += OnFilterButtonToggled; CurrentChatBox.FilterToggled += OnFilterButtonToggled;
CurrentChatBox.OnResized += ChatBoxOnResized; CurrentChatBox.OnResized += ChatBoxOnResized;
CurrentChatBox.SetChannelPermissions(_selectableChannels, _filterableChannels, _channelFilters, _unreadMessages); CurrentChatBox.SetChannelPermissions(_selectableChannels, _filterableChannels, _channelFilters, _unreadMessages, false);
} }
RepopulateChat(_filteredHistory); RepopulateChat(_filteredHistory);

View File

@@ -79,10 +79,10 @@ namespace Content.Client.State
InputCmdHandler.FromDelegate(_ => FocusChannel(_gameChat, ChatChannel.AdminChat))); InputCmdHandler.FromDelegate(_ => FocusChannel(_gameChat, ChatChannel.AdminChat)));
_inputManager.SetInputCommand(ContentKeyFunctions.CycleChatChannelForward, _inputManager.SetInputCommand(ContentKeyFunctions.CycleChatChannelForward,
InputCmdHandler.FromDelegate(_ => CycleChatChannel(_gameChat, true))); InputCmdHandler.FromDelegate(_ => _gameChat.CycleChatChannel(true)));
_inputManager.SetInputCommand(ContentKeyFunctions.CycleChatChannelBackward, _inputManager.SetInputCommand(ContentKeyFunctions.CycleChatChannelBackward,
InputCmdHandler.FromDelegate(_ => CycleChatChannel(_gameChat, false))); InputCmdHandler.FromDelegate(_ => _gameChat.CycleChatChannel(false)));
SetupPresenters(); SetupPresenters();
@@ -136,27 +136,9 @@ namespace Content.Client.State
return; return;
} }
chat.Input.IgnoreNext = true;
chat.SelectChannel(channel); chat.SelectChannel(channel);
}
internal static void CycleChatChannel(ChatBox chat, bool forward)
{
chat.Input.IgnoreNext = true; chat.Input.IgnoreNext = true;
var channels = chat.SelectableChannels; chat.Input.GrabKeyboardFocus();
var idx = channels.IndexOf(chat.SelectedChannel);
if (forward)
{
idx++;
idx = MathHelper.Mod(idx, channels.Count());
}
else
{
idx--;
idx = MathHelper.Mod(idx, channels.Count());
}
chat.SelectChannel(channels[idx]);
} }
public override void FrameUpdate(FrameEventArgs e) public override void FrameUpdate(FrameEventArgs e)

View File

@@ -83,10 +83,10 @@ namespace Content.Client.State
InputCmdHandler.FromDelegate(_ => GameScreen.FocusChannel(_lobby.Chat, ChatChannel.AdminChat))); InputCmdHandler.FromDelegate(_ => GameScreen.FocusChannel(_lobby.Chat, ChatChannel.AdminChat)));
_inputManager.SetInputCommand(ContentKeyFunctions.CycleChatChannelForward, _inputManager.SetInputCommand(ContentKeyFunctions.CycleChatChannelForward,
InputCmdHandler.FromDelegate(_ => GameScreen.CycleChatChannel(_lobby.Chat, true))); InputCmdHandler.FromDelegate(_ => _lobby.Chat.CycleChatChannel(true)));
_inputManager.SetInputCommand(ContentKeyFunctions.CycleChatChannelBackward, _inputManager.SetInputCommand(ContentKeyFunctions.CycleChatChannelBackward,
InputCmdHandler.FromDelegate(_ => GameScreen.CycleChatChannel(_lobby.Chat, false))); InputCmdHandler.FromDelegate(_ => _lobby.Chat.CycleChatChannel(false)));
UpdateLobbyUi(); UpdateLobbyUi();

View File

@@ -61,5 +61,10 @@ namespace Content.Shared.Chat
/// Unspecified. /// Unspecified.
/// </summary> /// </summary>
Unspecified = 512, Unspecified = 512,
/// <summary>
/// Channels considered to be IC.
/// </summary>
IC = Local | Radio | Dead | Emotes | Damage | Visual,
} }
} }