2024-03-20 18:10:35 +00:00
|
|
|
|
using System.Diagnostics;
|
2024-05-10 22:26:44 +00:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2024-03-20 18:10:35 +00:00
|
|
|
|
using System.Numerics;
|
2024-05-10 22:26:44 +00:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2024-03-20 18:10:35 +00:00
|
|
|
|
using Dalamud.Interface;
|
|
|
|
|
using Dalamud.Interface.Windowing;
|
|
|
|
|
using ImGuiNET;
|
|
|
|
|
using IG = ImGuiNET.ImGui;
|
|
|
|
|
|
|
|
|
|
namespace LLib.ImGui;
|
|
|
|
|
|
2024-05-10 22:26:44 +00:00
|
|
|
|
[SuppressMessage("ReSharper", "SuspiciousTypeConversion.Global")]
|
2024-03-20 18:10:35 +00:00
|
|
|
|
public abstract class LWindow : Window
|
|
|
|
|
{
|
2024-05-10 22:26:44 +00:00
|
|
|
|
private bool _initializedConfig;
|
2024-03-20 18:10:35 +00:00
|
|
|
|
|
2024-09-22 11:46:38 +00:00
|
|
|
|
protected LWindow(string windowName, ImGuiWindowFlags flags = ImGuiWindowFlags.None, bool forceMainWindow = false)
|
|
|
|
|
: base(windowName, flags, forceMainWindow)
|
2024-03-20 18:10:35 +00:00
|
|
|
|
{
|
|
|
|
|
TitleBarButtons.Add(new TitleBarButton
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesomeIcon.Heart,
|
|
|
|
|
ShowTooltip = () =>
|
|
|
|
|
{
|
|
|
|
|
IG.BeginTooltip();
|
|
|
|
|
IG.Text("Go to patreon.com/lizac");
|
|
|
|
|
IG.EndTooltip();
|
|
|
|
|
},
|
|
|
|
|
Priority = int.MinValue,
|
|
|
|
|
IconOffset = new Vector2(1.5f, 1),
|
|
|
|
|
Click = _ =>
|
|
|
|
|
{
|
|
|
|
|
// when you make a window click-through, `Click` is triggered on each individual frame the mouse button is held down.
|
|
|
|
|
ClickedHeaderCurrentFrame = true;
|
|
|
|
|
if (ClickedHeaderLastFrame)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Process.Start(new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = "https://www.patreon.com/lizac",
|
|
|
|
|
UseShellExecute = true,
|
|
|
|
|
Verb = string.Empty,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// not sure what to do anyway
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
AvailableClickthrough = true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-10 22:26:44 +00:00
|
|
|
|
|
|
|
|
|
protected bool ClickedHeaderLastFrame { get; private set; }
|
|
|
|
|
protected bool ClickedHeaderCurrentFrame { get; private set; }
|
|
|
|
|
|
|
|
|
|
protected bool IsPinned
|
|
|
|
|
{
|
|
|
|
|
get => InternalIsPinned(this);
|
|
|
|
|
set => InternalIsPinned(this) = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected bool IsClickthrough
|
|
|
|
|
{
|
|
|
|
|
get => InternalIsClickthrough(this);
|
|
|
|
|
set => InternalIsClickthrough(this) = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected int? Alpha
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
float? value = InternalAlpha(this);
|
|
|
|
|
return (int?)(10_0000 * value);
|
|
|
|
|
}
|
|
|
|
|
set => InternalAlpha(this) = value / 10_0000f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadWindowConfig()
|
|
|
|
|
{
|
|
|
|
|
if (this is IPersistableWindowConfig pwc)
|
|
|
|
|
{
|
|
|
|
|
WindowConfig? config = pwc.WindowConfig;
|
|
|
|
|
if (config != null)
|
|
|
|
|
{
|
|
|
|
|
if (AllowPinning)
|
|
|
|
|
IsPinned = config.IsPinned;
|
|
|
|
|
|
|
|
|
|
if (AllowClickthrough)
|
|
|
|
|
IsClickthrough = config.IsClickthrough;
|
|
|
|
|
|
|
|
|
|
Alpha = config.Alpha;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_initializedConfig = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateWindowConfig()
|
|
|
|
|
{
|
|
|
|
|
if (this is IPersistableWindowConfig pwc && !IG.IsAnyMouseDown())
|
|
|
|
|
{
|
|
|
|
|
WindowConfig? config = pwc.WindowConfig;
|
|
|
|
|
if (config != null)
|
|
|
|
|
{
|
|
|
|
|
bool changed = false;
|
|
|
|
|
if (AllowPinning && config.IsPinned != IsPinned)
|
|
|
|
|
{
|
|
|
|
|
config.IsPinned = IsPinned;
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (AllowClickthrough && config.IsClickthrough != IsClickthrough)
|
|
|
|
|
{
|
|
|
|
|
config.IsClickthrough = IsClickthrough;
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config.Alpha != Alpha)
|
|
|
|
|
{
|
|
|
|
|
config.Alpha = Alpha;
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
|
{
|
|
|
|
|
pwc.SaveWindowConfig();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 18:10:35 +00:00
|
|
|
|
public override void PreDraw()
|
|
|
|
|
{
|
2024-05-10 22:26:44 +00:00
|
|
|
|
if (!_initializedConfig)
|
|
|
|
|
LoadWindowConfig();
|
|
|
|
|
|
2024-03-20 18:10:35 +00:00
|
|
|
|
base.PreDraw();
|
|
|
|
|
|
|
|
|
|
ClickedHeaderLastFrame = ClickedHeaderCurrentFrame;
|
|
|
|
|
ClickedHeaderCurrentFrame = false;
|
|
|
|
|
}
|
2024-05-10 22:26:44 +00:00
|
|
|
|
|
|
|
|
|
public override void PostDraw()
|
|
|
|
|
{
|
|
|
|
|
base.PostDraw();
|
|
|
|
|
|
|
|
|
|
if (_initializedConfig)
|
|
|
|
|
UpdateWindowConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "internalIsPinned")]
|
|
|
|
|
private static extern ref bool InternalIsPinned(Window @this);
|
|
|
|
|
|
|
|
|
|
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "internalIsClickthrough")]
|
|
|
|
|
private static extern ref bool InternalIsClickthrough(Window @this);
|
|
|
|
|
|
|
|
|
|
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "internalAlpha")]
|
|
|
|
|
private static extern ref float? InternalAlpha(Window @this);
|
2024-03-20 18:10:35 +00:00
|
|
|
|
}
|