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:
@@ -7,6 +7,7 @@ using Content.Client.UserInterface;
|
||||
using Content.Client.UserInterface.Stylesheets;
|
||||
using Content.Client.Utility;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.Input;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.State;
|
||||
@@ -59,7 +60,7 @@ namespace Content.Client.Chat
|
||||
/// <summary>
|
||||
/// Will be Unspecified if set to Console
|
||||
/// </summary>
|
||||
public ChatChannel SelectedChannel;
|
||||
public ChatChannel SelectedChannel = ChatChannel.Unspecified;
|
||||
|
||||
/// <summary>
|
||||
/// Default formatting string for the ClientChatConsole.
|
||||
@@ -279,7 +280,7 @@ namespace Content.Client.Chat
|
||||
/// 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>
|
||||
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;
|
||||
// update the channel selector
|
||||
@@ -305,10 +306,15 @@ namespace Content.Client.Chat
|
||||
_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
|
||||
if (selectableChannels.Contains(ChatChannel.OOC))
|
||||
// our previously selected channel no longer exists or we are still on console channel because we just joined
|
||||
if ((SelectedChannel & ChatChannel.IC) != 0 || SelectedChannel == ChatChannel.Unspecified)
|
||||
{
|
||||
if (!SafelySelectChannel(ChatChannel.Local))
|
||||
SafelySelectChannel(ChatChannel.Dead);
|
||||
}
|
||||
else if (selectableChannels.Contains(ChatChannel.OOC))
|
||||
{
|
||||
SafelySelectChannel(ChatChannel.OOC);
|
||||
}
|
||||
@@ -498,6 +504,24 @@ namespace Content.Client.Chat
|
||||
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)
|
||||
{
|
||||
if (args.Function == EngineKeyFunctions.TextReleaseFocus)
|
||||
@@ -507,9 +531,22 @@ namespace Content.Client.Chat
|
||||
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 (Input.Text.Length == 0 && _savedSelectedChannel.HasValue &&
|
||||
args.Function == EngineKeyFunctions.TextBackspace)
|
||||
if (args.Function == EngineKeyFunctions.TextBackspace && Input.Text.Length == 0 && _savedSelectedChannel.HasValue)
|
||||
{
|
||||
SafelySelectChannel(_savedSelectedChannel.Value);
|
||||
_savedSelectedChannel = null;
|
||||
|
||||
@@ -242,7 +242,7 @@ namespace Content.Client.Chat
|
||||
}
|
||||
|
||||
// let our chatbox know all the new settings
|
||||
CurrentChatBox?.SetChannelPermissions(_selectableChannels, _filterableChannels, _channelFilters, _unreadMessages);
|
||||
CurrentChatBox?.SetChannelPermissions(_selectableChannels, _filterableChannels, _channelFilters, _unreadMessages, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -311,7 +311,7 @@ namespace Content.Client.Chat
|
||||
CurrentChatBox.FilterToggled += OnFilterButtonToggled;
|
||||
CurrentChatBox.OnResized += ChatBoxOnResized;
|
||||
|
||||
CurrentChatBox.SetChannelPermissions(_selectableChannels, _filterableChannels, _channelFilters, _unreadMessages);
|
||||
CurrentChatBox.SetChannelPermissions(_selectableChannels, _filterableChannels, _channelFilters, _unreadMessages, false);
|
||||
}
|
||||
|
||||
RepopulateChat(_filteredHistory);
|
||||
|
||||
@@ -79,10 +79,10 @@ namespace Content.Client.State
|
||||
InputCmdHandler.FromDelegate(_ => FocusChannel(_gameChat, ChatChannel.AdminChat)));
|
||||
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.CycleChatChannelForward,
|
||||
InputCmdHandler.FromDelegate(_ => CycleChatChannel(_gameChat, true)));
|
||||
InputCmdHandler.FromDelegate(_ => _gameChat.CycleChatChannel(true)));
|
||||
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.CycleChatChannelBackward,
|
||||
InputCmdHandler.FromDelegate(_ => CycleChatChannel(_gameChat, false)));
|
||||
InputCmdHandler.FromDelegate(_ => _gameChat.CycleChatChannel(false)));
|
||||
|
||||
SetupPresenters();
|
||||
|
||||
@@ -136,27 +136,9 @@ namespace Content.Client.State
|
||||
return;
|
||||
}
|
||||
|
||||
chat.Input.IgnoreNext = true;
|
||||
chat.SelectChannel(channel);
|
||||
}
|
||||
|
||||
internal static void CycleChatChannel(ChatBox chat, bool forward)
|
||||
{
|
||||
chat.Input.IgnoreNext = true;
|
||||
var channels = chat.SelectableChannels;
|
||||
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]);
|
||||
chat.Input.GrabKeyboardFocus();
|
||||
}
|
||||
|
||||
public override void FrameUpdate(FrameEventArgs e)
|
||||
|
||||
@@ -83,10 +83,10 @@ namespace Content.Client.State
|
||||
InputCmdHandler.FromDelegate(_ => GameScreen.FocusChannel(_lobby.Chat, ChatChannel.AdminChat)));
|
||||
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.CycleChatChannelForward,
|
||||
InputCmdHandler.FromDelegate(_ => GameScreen.CycleChatChannel(_lobby.Chat, true)));
|
||||
InputCmdHandler.FromDelegate(_ => _lobby.Chat.CycleChatChannel(true)));
|
||||
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.CycleChatChannelBackward,
|
||||
InputCmdHandler.FromDelegate(_ => GameScreen.CycleChatChannel(_lobby.Chat, false)));
|
||||
InputCmdHandler.FromDelegate(_ => _lobby.Chat.CycleChatChannel(false)));
|
||||
|
||||
UpdateLobbyUi();
|
||||
|
||||
|
||||
@@ -61,5 +61,10 @@ namespace Content.Shared.Chat
|
||||
/// Unspecified.
|
||||
/// </summary>
|
||||
Unspecified = 512,
|
||||
|
||||
/// <summary>
|
||||
/// Channels considered to be IC.
|
||||
/// </summary>
|
||||
IC = Local | Radio | Dead | Emotes | Damage | Visual,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user