Skip to content

Commit

Permalink
Update Hide Chat Automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Caraxi committed Sep 1, 2024
1 parent ae09187 commit 7fb33cc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 57 deletions.
1 change: 0 additions & 1 deletion SimpleTweaksPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<Compile Remove="Tweaks\SanctuarySprintReplacer.cs"/>
<Compile Remove="Tweaks\ScreenshotFileName.cs"/>
<Compile Remove="Tweaks\TreasureHuntTargets.cs"/>
<Compile Remove="Tweaks\Chat\HideChatAuto.cs"/>
<Compile Remove="Tweaks\Chat\RenameChatTabs.cs"/>
<Compile Remove="Tweaks\Chat\ZoomedChatCustomization.cs"/>
<Compile Remove="Tweaks\JokeTweak\Fools2023.cs"/>
Expand Down
87 changes: 31 additions & 56 deletions Tweaks/Chat/HideChatAuto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,30 @@
using SimpleTweaksPlugin.TweakSystem;
using SimpleTweaksPlugin.Utility;
using System;
using SimpleTweaksPlugin.Events;

namespace SimpleTweaksPlugin.Tweaks.Chat;

public unsafe class HideChatAuto : ChatTweaks.SubTweak
{
public class HideChatAutoConfig : TweakConfig
{
[TweakName("Hide Chat Automatically")]
[TweakDescription("Hides chat automatically except when typing.")]
[TweakAuthor("@dookssh")]
[TweakAutoConfig]
public unsafe class HideChatAuto : ChatTweaks.SubTweak {
public class HideChatAutoConfig : TweakConfig {
public bool Everywhere = true;
public bool InInstance = false;
public bool InCombat = false;
public bool InCutscene = false;
public bool InInstance;
public bool InCombat;
public bool InCutscene;
}

public HideChatAutoConfig Config { get; private set; }

public override string Name => "Hide Chat Automatically";
public override string Description => $"Hides chat automatically except when typing.";
protected override string Author => "@dookssh";
public HideChatAutoConfig Config { get; set; }

// If the plugin is failing, most likely you will need to update these IDs
private readonly uint TextInputNodeID = 5;
private readonly uint TextInputCursorID = 2;
private readonly string[] ChatLogNodeNames = { "ChatLog", "ChatLogPanel_0", "ChatLogPanel_1", "ChatLogPanel_2", "ChatLogPanel_3" };
private const uint TextInputNodeID = 5;
private const uint TextInputCursorID = 2;
private readonly string[] chatLogNodeNames = ["ChatLog", "ChatLogPanel_0", "ChatLogPanel_1", "ChatLogPanel_2", "ChatLogPanel_3"];

protected override DrawConfigDelegate DrawConfigTree => (ref bool hasChanged) =>
{
protected void DrawConfig(ref bool hasChanged) {
hasChanged |= ImGui.Checkbox("Everywhere", ref Config.Everywhere);

if (Config.Everywhere) ImGui.BeginDisabled();
Expand All @@ -38,61 +36,40 @@ public class HideChatAutoConfig : TweakConfig
hasChanged |= ImGui.Checkbox("In Cutscenes", ref Config.InCutscene);
if (Config.Everywhere) ImGui.EndDisabled();

if (hasChanged)
{
if (hasChanged) {
SetVisibility(true);
}
};

protected override void Enable()
{
Config = LoadConfig<HideChatAutoConfig>() ?? new HideChatAutoConfig();
Common.FrameworkUpdate += FrameworkUpdate;
base.Enable();
}

protected override void Disable()
{
SaveConfig(Config);
Common.FrameworkUpdate -= FrameworkUpdate;
protected override void Disable() {
SetVisibility(true);
base.Disable();
}

private void FrameworkUpdate()
{
try
{
[FrameworkUpdate]
private void FrameworkUpdate() {
try {
// Always show chat when actively typing
var inputCursorNode = GetChatInputCursorNode();
if (inputCursorNode == null) return;

var visibility = inputCursorNode->IsVisible;
if (visibility)
{
var visibility = inputCursorNode->IsVisible();
if (visibility) {
SetVisibility(true);
return;
}

var isEverywhere = Config.Everywhere;
var isInInstance = Config.InInstance && (
Service.Condition[ConditionFlag.BoundByDuty] ||
Service.Condition[ConditionFlag.BoundByDuty56] ||
Service.Condition[ConditionFlag.BoundByDuty95]
);
var isInInstance = Config.InInstance && (Service.Condition[ConditionFlag.BoundByDuty] || Service.Condition[ConditionFlag.BoundByDuty56] || Service.Condition[ConditionFlag.BoundByDuty95]);
var isInCutscene = Config.InCutscene && Service.Condition[ConditionFlag.OccupiedInCutSceneEvent];
var isInCombat = Config.InCombat && Service.Condition[ConditionFlag.InCombat];

if (isEverywhere || isInInstance || isInCombat || isInCutscene) SetVisibility(false);
}
catch (Exception ex)
{
} catch (Exception ex) {
SimpleLog.Error(ex);
}
}

private AtkResNode* GetChatInputCursorNode()
{
private AtkResNode* GetChatInputCursorNode() {
var baseNode = Common.GetUnitBase("ChatLog");
if (baseNode == null) return null;

Expand All @@ -102,18 +79,16 @@ private void FrameworkUpdate()
var textInputBaseNode = textInputComponentNode->Component;
if (textInputBaseNode == null) return null;

AtkUldManager uldManager = textInputBaseNode->UldManager;
var uldManager = textInputBaseNode->UldManager;

return Common.GetNodeByID(&uldManager, TextInputCursorID);
}

private void SetVisibility(bool visibility)
{
foreach (string name in ChatLogNodeNames)
{
AtkUnitBase* node = Common.GetUnitBase(name);
if (node == null) continue;
private void SetVisibility(bool visibility) {
foreach (var name in chatLogNodeNames) {
var node = Common.GetUnitBase(name);
if (node == null || node->RootNode == null) continue;
node->RootNode->ToggleVisibility(visibility);
};
}
}
}

0 comments on commit 7fb33cc

Please sign in to comment.