Use different chatbox placeholder when dependent keys unbound (#22747)

This commit is contained in:
LordCarve
2023-12-22 20:39:29 +01:00
committed by GitHub
parent 524dbf9a78
commit 7d69055291
3 changed files with 20 additions and 1 deletions

View File

@@ -13,6 +13,11 @@ public static class BoundKeyHelper
return TryGetShortKeyName(keyFunction, out var name) ? Loc.GetString(name) : " "; return TryGetShortKeyName(keyFunction, out var name) ? Loc.GetString(name) : " ";
} }
public static bool IsBound(BoundKeyFunction keyFunction)
{
return TryGetShortKeyName(keyFunction, out _);
}
private static string? DefaultShortKeyName(BoundKeyFunction keyFunction) private static string? DefaultShortKeyName(BoundKeyFunction keyFunction)
{ {
var name = FormattedMessage.EscapeText(IoCManager.Resolve<IInputManager>().GetKeyFunctionButtonString(keyFunction)); var name = FormattedMessage.EscapeText(IoCManager.Resolve<IInputManager>().GetKeyFunctionButtonString(keyFunction));

View File

@@ -33,7 +33,7 @@ public class ChatInputBox : PanelContainer
Input = new HistoryLineEdit Input = new HistoryLineEdit
{ {
Name = "Input", Name = "Input",
PlaceHolder = Loc.GetString("hud-chatbox-info", ("talk-key", BoundKeyHelper.ShortKeyName(ContentKeyFunctions.FocusChat)), ("cycle-key", BoundKeyHelper.ShortKeyName(ContentKeyFunctions.CycleChatChannelForward))), PlaceHolder = GetChatboxInfoPlaceholder(),
HorizontalExpand = true, HorizontalExpand = true,
StyleClasses = {"chatLineEdit"} StyleClasses = {"chatLineEdit"}
}; };
@@ -51,4 +51,15 @@ public class ChatInputBox : PanelContainer
{ {
ActiveChannel = (ChatChannel) selectedChannel; ActiveChannel = (ChatChannel) selectedChannel;
} }
private static string GetChatboxInfoPlaceholder()
{
return (BoundKeyHelper.IsBound(ContentKeyFunctions.FocusChat), BoundKeyHelper.IsBound(ContentKeyFunctions.CycleChatChannelForward)) switch
{
(true, true) => Loc.GetString("hud-chatbox-info", ("talk-key", BoundKeyHelper.ShortKeyName(ContentKeyFunctions.FocusChat)), ("cycle-key", BoundKeyHelper.ShortKeyName(ContentKeyFunctions.CycleChatChannelForward))),
(true, false) => Loc.GetString("hud-chatbox-info-talk", ("talk-key", BoundKeyHelper.ShortKeyName(ContentKeyFunctions.FocusChat))),
(false, true) => Loc.GetString("hud-chatbox-info-cycle", ("cycle-key", BoundKeyHelper.ShortKeyName(ContentKeyFunctions.CycleChatChannelForward))),
(false, false) => Loc.GetString("hud-chatbox-info-unbound")
};
}
} }

View File

@@ -1,4 +1,7 @@
hud-chatbox-info = {$talk-key} to talk, {$cycle-key} to cycle channels. hud-chatbox-info = {$talk-key} to talk, {$cycle-key} to cycle channels.
hud-chatbox-info-talk = {$talk-key} to talk.
hud-chatbox-info-cycle = Click here to talk, {$cycle-key} to cycle channels.
hud-chatbox-info-unbound = Click here to talk.
hud-chatbox-select-name-prefixed = {$prefix} {$name} hud-chatbox-select-name-prefixed = {$prefix} {$name}
hud-chatbox-select-channel-Admin = Admin hud-chatbox-select-channel-Admin = Admin