From 60e22f58ee680b7a1a41eeb14c20ccd3be14061d Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 1 Feb 2022 00:20:20 -0500 Subject: [PATCH] feat: allow hiding --- ChatTwo/Configuration.cs | 1 + ChatTwo/Plugin.cs | 4 ++ ChatTwo/PluginUi.cs | 12 ++++-- ChatTwo/Ui/ChatLog.cs | 65 ++++++++++++++++++++++++++++++ ChatTwo/Ui/SettingsTabs/Display.cs | 3 +- 5 files changed, 81 insertions(+), 4 deletions(-) diff --git a/ChatTwo/Configuration.cs b/ChatTwo/Configuration.cs index 308c346..9669231 100755 --- a/ChatTwo/Configuration.cs +++ b/ChatTwo/Configuration.cs @@ -8,6 +8,7 @@ internal class Configuration : IPluginConfiguration { public int Version { get; set; } = 1; public bool HideChat = true; + public bool HideDuringCutscenes = true; public bool NativeItemTooltips = true; public bool PrettierTimestamps = true; public bool MoreCompactPretty; diff --git a/ChatTwo/Plugin.cs b/ChatTwo/Plugin.cs index 27d1220..65ccce4 100755 --- a/ChatTwo/Plugin.cs +++ b/ChatTwo/Plugin.cs @@ -1,6 +1,7 @@ using Dalamud.Data; using Dalamud.Game; using Dalamud.Game.ClientState; +using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Keys; using Dalamud.Game.ClientState.Objects; using Dalamud.Game.ClientState.Party; @@ -28,6 +29,9 @@ public sealed class Plugin : IDalamudPlugin { [PluginService] internal CommandManager CommandManager { get; init; } + [PluginService] + internal Condition Condition { get; init; } + [PluginService] internal DataManager DataManager { get; init; } diff --git a/ChatTwo/PluginUi.cs b/ChatTwo/PluginUi.cs index 9086498..35d0562 100755 --- a/ChatTwo/PluginUi.cs +++ b/ChatTwo/PluginUi.cs @@ -88,10 +88,16 @@ internal sealed class PluginUi : IDisposable { gameSym.Length ); - this.Plugin.Interface.UiBuilder.BuildFonts += this.BuildFonts; - this.Plugin.Interface.UiBuilder.Draw += this.Draw; + var uiBuilder = this.Plugin.Interface.UiBuilder; + uiBuilder.DisableAutomaticUiHide = true; + uiBuilder.DisableCutsceneUiHide = true; + uiBuilder.DisableGposeUiHide = true; + uiBuilder.DisableUserUiHide = true; - this.Plugin.Interface.UiBuilder.RebuildFonts(); + uiBuilder.BuildFonts += this.BuildFonts; + uiBuilder.Draw += this.Draw; + + uiBuilder.RebuildFonts(); } public void Dispose() { diff --git a/ChatTwo/Ui/ChatLog.cs b/ChatTwo/Ui/ChatLog.cs index b1c63d3..4b4c793 100755 --- a/ChatTwo/Ui/ChatLog.cs +++ b/ChatTwo/Ui/ChatLog.cs @@ -3,6 +3,7 @@ using System.Numerics; using ChatTwo.Code; using ChatTwo.GameFunctions.Types; using ChatTwo.Util; +using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Keys; using Dalamud.Game.Command; using Dalamud.Game.Text.SeStringHandling; @@ -237,7 +238,55 @@ internal sealed class ChatLog : IUiComponent { } } + private bool CutsceneActive { + get { + var condition = this.Ui.Plugin.Condition; + return condition[ConditionFlag.OccupiedInCutSceneEvent] + || condition[ConditionFlag.WatchingCutscene78]; + } + } + + private bool GposeActive { + get { + var condition = this.Ui.Plugin.Condition; + return condition[ConditionFlag.WatchingCutscene]; + } + } + + private enum HideState { + None, + Cutscene, + CutsceneOverride, + User, + } + + private HideState _hideState = HideState.None; + public unsafe void Draw() { + // if the chat has no hide state and in a cutscene, set the hide state to cutscene + if (this.Ui.Plugin.Config.HideDuringCutscenes && this._hideState == HideState.None && (this.CutsceneActive || this.GposeActive)) { + this._hideState = HideState.Cutscene; + } + + // if the chat is hidden because of a cutscene and no longer in a cutscene, set the hide state to none + if (this._hideState is HideState.Cutscene or HideState.CutsceneOverride && !this.CutsceneActive && !this.GposeActive) { + this._hideState = HideState.None; + } + + // if the chat is hidden because of a cutscene and the chat has been activated, show chat + if (this._hideState == HideState.Cutscene && this.Activate) { + this._hideState = HideState.CutsceneOverride; + } + + // if the user hid the chat and is now activating chat, reset the hide state + if (this._hideState == HideState.User && this.Activate) { + this._hideState = HideState.None; + } + + if (this._hideState is HideState.Cutscene or HideState.User) { + return; + } + var flags = ImGuiWindowFlags.None; if (!this.Ui.Plugin.Config.CanMove) { flags |= ImGuiWindowFlags.NoMove; @@ -360,6 +409,8 @@ internal sealed class ChatLog : IUiComponent { } } + var normalColour = *ImGui.GetStyleColorVec4(ImGuiCol.Text); + var inputColour = this.Ui.Plugin.Config.ChatColours.TryGetValue(inputType, out var inputCol) ? inputCol : inputType.DefaultColour(); @@ -422,6 +473,20 @@ internal sealed class ChatLog : IUiComponent { this._tempChannel = null; } + if (ImGui.BeginPopupContextItem()) { + ImGui.PushStyleColor(ImGuiCol.Text, normalColour); + + try { + if (ImGui.Selectable("Hide chat")) { + this._hideState = HideState.User; + } + } finally { + ImGui.PopStyleColor(); + } + + ImGui.EndPopup(); + } + if (inputColour != null) { ImGui.PopStyleColor(); } diff --git a/ChatTwo/Ui/SettingsTabs/Display.cs b/ChatTwo/Ui/SettingsTabs/Display.cs index a9a1353..ab864d2 100755 --- a/ChatTwo/Ui/SettingsTabs/Display.cs +++ b/ChatTwo/Ui/SettingsTabs/Display.cs @@ -12,7 +12,8 @@ internal sealed class Display : ISettingsTab { } public void Draw() { - ImGui.Checkbox("Hide chat", ref this.Mutable.HideChat); + ImGui.Checkbox("Hide vanilla chat", ref this.Mutable.HideChat); + ImGui.Checkbox("Hide chat during cutscenes", ref this.Mutable.HideDuringCutscenes); ImGui.Checkbox("Show native item tooltips", ref this.Mutable.NativeItemTooltips); ImGui.Checkbox("Show tabs in a sidebar", ref this.Mutable.SidebarTabView); ImGui.Checkbox("Use modern timestamp layout", ref this.Mutable.PrettierTimestamps);