62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
|
using System;
|
|||
|
using Dalamud.Game;
|
|||
|
using Dalamud.Plugin.Services;
|
|||
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
|||
|
// ReSharper disable ConditionIsAlwaysTrueOrFalse
|
|||
|
|
|||
|
namespace KamiLib.UserInterface;
|
|||
|
|
|||
|
public unsafe class GameUserInterface : IDisposable
|
|||
|
{
|
|||
|
public event EventHandler? UiHidden;
|
|||
|
public event EventHandler? UiShown;
|
|||
|
|
|||
|
private static GameUserInterface? _instance;
|
|||
|
public static GameUserInterface Instance => _instance ??= new GameUserInterface();
|
|||
|
|
|||
|
public bool IsVisible => !lastState;
|
|||
|
private bool lastState;
|
|||
|
|
|||
|
private GameUserInterface()
|
|||
|
{
|
|||
|
Service.Framework.Update += FrameworkUpdate;
|
|||
|
}
|
|||
|
|
|||
|
public static void Cleanup()
|
|||
|
{
|
|||
|
_instance?.Dispose();
|
|||
|
}
|
|||
|
|
|||
|
public void Dispose()
|
|||
|
{
|
|||
|
Service.Framework.Update -= FrameworkUpdate;
|
|||
|
}
|
|||
|
|
|||
|
private void FrameworkUpdate(IFramework framework)
|
|||
|
{
|
|||
|
var partyList = (AtkUnitBase*) Service.GameGui.GetAddonByName("_PartyList", 1);
|
|||
|
var todoList = (AtkUnitBase*) Service.GameGui.GetAddonByName("_ToDoList", 1);
|
|||
|
var enemyList = (AtkUnitBase*) Service.GameGui.GetAddonByName("_EnemyList", 1);
|
|||
|
|
|||
|
var partyListVisible = partyList != null && partyList->IsVisible;
|
|||
|
var todoListVisible = todoList != null && todoList->IsVisible;
|
|||
|
var enemyListVisible = enemyList != null && enemyList->IsVisible;
|
|||
|
|
|||
|
var shouldHideUi = !partyListVisible && !todoListVisible && !enemyListVisible;
|
|||
|
|
|||
|
if (lastState != shouldHideUi)
|
|||
|
{
|
|||
|
if (shouldHideUi)
|
|||
|
{
|
|||
|
UiHidden?.Invoke(this, EventArgs.Empty);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
UiShown?.Invoke(this, EventArgs.Empty);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
lastState = shouldHideUi;
|
|||
|
}
|
|||
|
}
|