Prevent ENTER focus if disabled input, exception is to unhide chat

This commit is contained in:
Infi
2024-05-01 23:11:47 +02:00
parent 4161e8e378
commit 7bd5f0302b
2 changed files with 21 additions and 17 deletions
+6
View File
@@ -377,6 +377,9 @@ internal sealed unsafe class Chat : IDisposable
LastRefresh = Environment.TickCount64; LastRefresh = Environment.TickCount64;
} }
if (Plugin.ChatLogWindow is { CurrentTab.InputDisabled: true, IsHidden: false })
return;
var modifierState = (ModifierFlag) 0; var modifierState = (ModifierFlag) 0;
foreach (var modifier in Enum.GetValues<ModifierFlag>()) foreach (var modifier in Enum.GetValues<ModifierFlag>())
{ {
@@ -460,6 +463,9 @@ internal sealed unsafe class Chat : IDisposable
private byte ChatLogRefreshDetour(IntPtr log, ushort eventId, AtkValue* value) private byte ChatLogRefreshDetour(IntPtr log, ushort eventId, AtkValue* value)
{ {
if (Plugin.ChatLogWindow.CurrentTab is { InputDisabled: true })
return ChatLogRefreshHook!.Original(log, eventId, value);
if (eventId != 0x31 || value == null || value->UInt is not (0x05 or 0x0C)) if (eventId != 0x31 || value == null || value->UInt is not (0x05 or 0x0C))
return ChatLogRefreshHook!.Original(log, eventId, value); return ChatLogRefreshHook!.Original(log, eventId, value);
+15 -17
View File
@@ -253,18 +253,18 @@ public sealed class ChatLogWindow : Window
switch (parts[1]) switch (parts[1])
{ {
case "hide": case "hide":
_hideState = HideState.User; CurrentHideState = HideState.User;
break; break;
case "show": case "show":
_hideState = HideState.None; CurrentHideState = HideState.None;
break; break;
case "toggle": case "toggle":
_hideState = _hideState switch CurrentHideState = CurrentHideState switch
{ {
HideState.User or HideState.CutsceneOverride => HideState.None, HideState.User or HideState.CutsceneOverride => HideState.None,
HideState.Cutscene => HideState.CutsceneOverride, HideState.Cutscene => HideState.CutsceneOverride,
HideState.None => HideState.User, HideState.None => HideState.User,
_ => _hideState, _ => CurrentHideState,
}; };
break; break;
} }
@@ -420,28 +420,28 @@ public sealed class ChatLogWindow : Window
User, User,
} }
private HideState _hideState = HideState.None; private HideState CurrentHideState = HideState.None;
public bool IsHidden; public bool IsHidden;
public void HideStateCheck() public void HideStateCheck()
{ {
// if the chat has no hide state and in a cutscene, set the hide state to cutscene // if the chat has no hide state and in a cutscene, set the hide state to cutscene
if (Plugin.Config.HideDuringCutscenes && _hideState == HideState.None && (CutsceneActive || GposeActive)) if (Plugin.Config.HideDuringCutscenes && CurrentHideState == HideState.None && (CutsceneActive || GposeActive))
_hideState = HideState.Cutscene; CurrentHideState = HideState.Cutscene;
// if the chat is hidden because of a cutscene and no longer in a cutscene, set the hide state to none // if the chat is hidden because of a cutscene and no longer in a cutscene, set the hide state to none
if (_hideState is HideState.Cutscene or HideState.CutsceneOverride && !CutsceneActive && !GposeActive) if (CurrentHideState is HideState.Cutscene or HideState.CutsceneOverride && !CutsceneActive && !GposeActive)
_hideState = HideState.None; CurrentHideState = HideState.None;
// if the chat is hidden because of a cutscene and the chat has been activated, show chat // if the chat is hidden because of a cutscene and the chat has been activated, show chat
if (_hideState == HideState.Cutscene && Activate) if (CurrentHideState == HideState.Cutscene && Activate)
_hideState = HideState.CutsceneOverride; CurrentHideState = HideState.CutsceneOverride;
// if the user hid the chat and is now activating chat, reset the hide state // if the user hid the chat and is now activating chat, reset the hide state
if (_hideState == HideState.User && Activate) if (CurrentHideState == HideState.User && Activate)
_hideState = HideState.None; CurrentHideState = HideState.None;
if (_hideState is HideState.Cutscene or HideState.User || (Plugin.Config.HideWhenNotLoggedIn && !Plugin.ClientState.IsLoggedIn)) if (CurrentHideState is HideState.Cutscene or HideState.User || (Plugin.Config.HideWhenNotLoggedIn && !Plugin.ClientState.IsLoggedIn))
{ {
IsHidden = true; IsHidden = true;
return; return;
@@ -664,8 +664,6 @@ public sealed class ChatLogWindow : Window
var isChatEnabled = activeTab is { InputDisabled: false }; var isChatEnabled = activeTab is { InputDisabled: false };
using (ImRaii.Disabled(!isChatEnabled)) using (ImRaii.Disabled(!isChatEnabled))
{ {
// TODO: Prevent ENTER key focusing chat while input is disabled
var flags = InputFlags | (!isChatEnabled ? ImGuiInputTextFlags.ReadOnly : ImGuiInputTextFlags.None); var flags = InputFlags | (!isChatEnabled ? ImGuiInputTextFlags.ReadOnly : ImGuiInputTextFlags.None);
ImGui.SetNextItemWidth(inputWidth); ImGui.SetNextItemWidth(inputWidth);
ImGui.InputTextWithHint("##chat2-input", isChatEnabled ? "": Language.ChatLog_DisabledInput, ref Chat, 500, flags, Callback); ImGui.InputTextWithHint("##chat2-input", isChatEnabled ? "": Language.ChatLog_DisabledInput, ref Chat, 500, flags, Callback);
@@ -822,7 +820,7 @@ public sealed class ChatLogWindow : Window
internal void UserHide() internal void UserHide()
{ {
_hideState = HideState.User; CurrentHideState = HideState.User;
} }
internal void DrawMessageLog(Tab tab, PayloadHandler handler, float childHeight, bool switchedTab) internal void DrawMessageLog(Tab tab, PayloadHandler handler, float childHeight, bool switchedTab)