Skip to content

Commit

Permalink
enhancement: chat log tools (#1798)
Browse files Browse the repository at this point in the history
- This QoL update adds a handy way to show/hide the chat log by pressing a button.
- You may also optionally allow it (via game settings) to auto-show the chat log when pressing enter to chat or auto-hide it when pressing esc to un-focus the chat box.
- This QoL update also adds the ability to clear the entire chat log by pressing a button.
- Chore: fixed some code typos in Chatbox.cs
- Chore (GetDefaultInputText): removed unnecessary "else" keywords, these conditions already *return* by their own.
- Fix (GetDefaultInputText): properly uses the previously unused localized string "Chatbox.enterchat2" - this is used for whenever the user has two configured keys for chatting.
  • Loading branch information
Arufonsu committed May 6, 2023
1 parent 2f08c03 commit e6af5d8
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Intersect.Client.Framework/Database/GameDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public abstract partial class GameDatabase

public bool HideOthersOnWindowOpen { get; set; }

public bool AutoToggleChatLog { get; set; }

public bool TargetAccountDirection { get; set; }

public int MusicVolume { get; set; }
Expand Down Expand Up @@ -106,6 +108,7 @@ public virtual void LoadPreferences()
FullScreen = LoadPreference(nameof(FullScreen), false);
EnableLighting = LoadPreference(nameof(EnableLighting), true);
HideOthersOnWindowOpen = LoadPreference(nameof(HideOthersOnWindowOpen), true);
AutoToggleChatLog = LoadPreference(nameof(AutoToggleChatLog), false);
TargetAccountDirection = LoadPreference(nameof(TargetAccountDirection), false);
StickyTarget = LoadPreference(nameof(StickyTarget), false);
AutoTurnToTarget = LoadPreference(nameof(AutoTurnToTarget), false);
Expand Down Expand Up @@ -139,6 +142,7 @@ public virtual void SavePreferences()
SavePreference(nameof(FullScreen), FullScreen);
SavePreference(nameof(EnableLighting), EnableLighting);
SavePreference(nameof(HideOthersOnWindowOpen), HideOthersOnWindowOpen);
SavePreference(nameof(AutoToggleChatLog), AutoToggleChatLog);
SavePreference(nameof(TargetAccountDirection), TargetAccountDirection);
SavePreference(nameof(StickyTarget), StickyTarget);
SavePreference(nameof(AutoTurnToTarget), AutoTurnToTarget);
Expand Down
90 changes: 80 additions & 10 deletions Intersect.Client/Interface/Game/Chat/Chatbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public partial class Chatbox

private Button mChatboxSendButton;

private Button _chatboxToggleLogButton;

private Button _chatboxClearLogButton;

private readonly GameTexture _chatboxTexture;

private Label mChatboxText;

private Label mChatboxTitle;
Expand Down Expand Up @@ -117,9 +123,9 @@ public Chatbox(Canvas gameCanvas, GameInterface gameUi)
mChatbar.IsHidden = true;

mChatboxInput = new TextBox(mChatboxWindow, "ChatboxInputField");
mChatboxInput.SubmitPressed += ChatBoxInput_SubmitPressed;
mChatboxInput.SubmitPressed += ChatboxInput_SubmitPressed;
mChatboxInput.Text = GetDefaultInputText();
mChatboxInput.Clicked += ChatBoxInput_Clicked;
mChatboxInput.Clicked += ChatboxInput_Clicked;
mChatboxInput.IsTabable = false;
mChatboxInput.SetMaxLength(Options.MaxChatLength);
Interface.FocusElements.Add(mChatboxInput);
Expand Down Expand Up @@ -150,10 +156,19 @@ public Chatbox(Canvas gameCanvas, GameInterface gameUi)

mChatboxSendButton = new Button(mChatboxWindow, "ChatboxSendButton");
mChatboxSendButton.Text = Strings.Chatbox.send;
mChatboxSendButton.Clicked += ChatBoxSendBtn_Clicked;
mChatboxSendButton.Clicked += ChatboxSendBtn_Clicked;

_chatboxToggleLogButton = new Button(mChatboxWindow, "ChatboxToggleLogButton");
_chatboxToggleLogButton.SetToolTipText(Strings.Chatbox.ToggleLogButtonToolTip);
_chatboxToggleLogButton.Clicked += ChatboxToggleLogBtn_Clicked;

_chatboxClearLogButton = new Button(mChatboxWindow, "ChatboxClearLogButton");
_chatboxClearLogButton.SetToolTipText(Strings.Chatbox.ClearLogButtonToolTip);
_chatboxClearLogButton.Clicked += ChatboxClearLogBtn_Clicked;

mChatboxWindow.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());

_chatboxTexture = mChatboxWindow.Texture; // store chatbox texture here so we can re-use it later.
mChatboxText.IsHidden = true;

// Disable this to start, since this is the default tab we open the client on.
Expand Down Expand Up @@ -346,7 +361,6 @@ public void Update()
mChatboxMessages.GetHorizontalScrollBar().SetScrollAmount(0);
mMessageIndex = 0;
mReceivedMessage = true;

mLastTab = mCurrentTab;
}

Expand Down Expand Up @@ -443,6 +457,10 @@ public void Focus()
{
mChatboxInput.Text = string.Empty;
mChatboxInput.Focus();
if (Globals.Database.AutoToggleChatLog)
{
ShowChatLog();
}
}
}

Expand All @@ -455,29 +473,79 @@ public void UnFocus()
{
mChatboxInput.Text = GetDefaultInputText();
mChatboxMessages.Focus();
if (Globals.Database.AutoToggleChatLog)
{
HideChatLog();
}
}
}

//Input Handlers
//Chatbox Window
void ChatBoxInput_Clicked(Base sender, ClickedEventArgs arguments)
void ChatboxInput_Clicked(Base sender, ClickedEventArgs arguments)
{
if (mChatboxInput.Text == GetDefaultInputText())
{
mChatboxInput.Text = "";
}
}

void ChatBoxInput_SubmitPressed(Base sender, EventArgs arguments)
void ChatboxInput_SubmitPressed(Base sender, EventArgs arguments)
{
TrySendMessage();
}

void ChatBoxSendBtn_Clicked(Base sender, ClickedEventArgs arguments)
void ChatboxSendBtn_Clicked(Base sender, ClickedEventArgs arguments)
{
TrySendMessage();
}

void ChatboxClearLogBtn_Clicked(Base sender, ClickedEventArgs arguments)
{
ChatboxMsg.ClearMessages();
mChatboxMessages.Clear();
mChatboxMessages.GetHorizontalScrollBar().SetScrollAmount(0);
mMessageIndex = 0;
mReceivedMessage = true;
mLastTab = mCurrentTab;
}

void ChatboxToggleLogBtn_Clicked(Base sender, ClickedEventArgs arguments)
{
if (mChatboxWindow.Texture != null)
{
HideChatLog();
}
else
{
ShowChatLog();
}
}

private void ShowChatLog()
{
mTabButtons[ChatboxTab.All].Show();
mTabButtons[ChatboxTab.Local].Show();
mTabButtons[ChatboxTab.Party].Show();
mTabButtons[ChatboxTab.Guild].Show();
mTabButtons[ChatboxTab.Global].Show();
mTabButtons[ChatboxTab.System].Show();
mChatboxMessages.Show();
mChatboxWindow.Texture = _chatboxTexture;
}

private void HideChatLog()
{
mTabButtons[ChatboxTab.All].Hide();
mTabButtons[ChatboxTab.Local].Hide();
mTabButtons[ChatboxTab.Party].Hide();
mTabButtons[ChatboxTab.Guild].Hide();
mTabButtons[ChatboxTab.Global].Hide();
mTabButtons[ChatboxTab.System].Hide();
mChatboxMessages.Hide();
mChatboxWindow.Texture = null;
}

void TrySendMessage()
{
var msg = mChatboxInput.Text.Trim();
Expand Down Expand Up @@ -515,15 +583,17 @@ string GetDefaultInputText()
Strings.Keys.keydict[Enum.GetName(typeof(Keys), key2.Key).ToLower()]
);
}
else if (key1.Key != Keys.None && key2.Key == Keys.None)

if (key1.Key != Keys.None && key2.Key == Keys.None)
{
return Strings.Chatbox.enterchat1.ToString(
Strings.Keys.keydict[Enum.GetName(typeof(Keys), key1.Key).ToLower()]
);
}
else if (key1.Key != Keys.None && key2.Key != Keys.None)

if (key1.Key != Keys.None && key2.Key != Keys.None)
{
return Strings.Chatbox.enterchat1.ToString(
return Strings.Chatbox.enterchat2.ToString(
Strings.Keys.keydict[Enum.GetName(typeof(Keys), key1.Key).ToLower()],
Strings.Keys.keydict[Enum.GetName(typeof(Keys), key2.Key).ToLower()]
);
Expand Down
8 changes: 8 additions & 0 deletions Intersect.Client/Interface/Shared/SettingsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public partial class SettingsWindow

private readonly LabeledCheckBox mAutoCloseWindowsCheckbox;

private readonly LabeledCheckBox mAutoToggleChatLogCheckbox;

private readonly LabeledCheckBox mShowExperienceAsPercentageCheckbox;

private readonly LabeledCheckBox mShowHealthAsPercentageCheckbox;
Expand Down Expand Up @@ -195,6 +197,10 @@ public SettingsWindow(Base parent, MainMenu mainMenu, EscapeMenu escapeMenu)
mAutoCloseWindowsCheckbox = new LabeledCheckBox(mInterfaceSettings, "AutoCloseWindowsCheckbox");
mAutoCloseWindowsCheckbox.Text = Strings.Settings.AutoCloseWindows;

// Game Settings - Interface: Auto-toggle chat log visibility.
mAutoToggleChatLogCheckbox = new LabeledCheckBox(mInterfaceSettings, "AutoToggleChatLogCheckbox");
mAutoToggleChatLogCheckbox.Text = Strings.Settings.AutoToggleChatLog;

// Game Settings - Interface: Show EXP/HP/MP as Percentage.
mShowExperienceAsPercentageCheckbox =
new LabeledCheckBox(mInterfaceSettings, "ShowExperienceAsPercentageCheckbox");
Expand Down Expand Up @@ -671,6 +677,7 @@ public void Show(bool returnToMenu = false)

// Game Settings.
mAutoCloseWindowsCheckbox.IsChecked = Globals.Database.HideOthersOnWindowOpen;
mAutoToggleChatLogCheckbox.IsChecked = Globals.Database.AutoToggleChatLog;
mShowHealthAsPercentageCheckbox.IsChecked = Globals.Database.ShowHealthAsPercentage;
mShowManaAsPercentageCheckbox.IsChecked = Globals.Database.ShowManaAsPercentage;
mShowExperienceAsPercentageCheckbox.IsChecked = Globals.Database.ShowExperienceAsPercentage;
Expand Down Expand Up @@ -851,6 +858,7 @@ private void SettingsApplyBtn_Clicked(Base sender, ClickedEventArgs arguments)

// Game Settings.
Globals.Database.HideOthersOnWindowOpen = mAutoCloseWindowsCheckbox.IsChecked;
Globals.Database.AutoToggleChatLog = mAutoToggleChatLogCheckbox.IsChecked;
Globals.Database.ShowExperienceAsPercentage = mShowExperienceAsPercentageCheckbox.IsChecked;
Globals.Database.ShowHealthAsPercentage = mShowHealthAsPercentageCheckbox.IsChecked;
Globals.Database.ShowManaAsPercentage = mShowManaAsPercentageCheckbox.IsChecked;
Expand Down
7 changes: 7 additions & 0 deletions Intersect.Client/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ public partial struct Chatbox

public static LocalizedString toofast = @"You are chatting too fast!";

public static LocalizedString ToggleLogButtonToolTip = @"Toggle chat log visibility";

public static LocalizedString ClearLogButtonToolTip = @"Clear chat log messages";

public static Dictionary<ChatboxTab, LocalizedString> ChatTabButtons = new Dictionary<Enums.ChatboxTab, LocalizedString>() {
{ ChatboxTab.All, @"All" },
{ ChatboxTab.Local, @"Local" },
Expand Down Expand Up @@ -1706,6 +1710,9 @@ public partial struct Settings

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public static LocalizedString AutoCloseWindows = @"Auto-close Windows";

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public static LocalizedString AutoToggleChatLog = @"Auto-toggle chat log visibility";

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public static LocalizedString Cancel = @"Cancel";
Expand Down

0 comments on commit e6af5d8

Please sign in to comment.