forked from aly/qstbak
132 lines
4.5 KiB
C#
132 lines
4.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using Dalamud.Bindings.ImGui;
|
|
using Dalamud.Interface.Utility.Raii;
|
|
using Dalamud.Interface.Windowing;
|
|
using Dalamud.Plugin;
|
|
using LLib.ImGui;
|
|
using Questionable.Data;
|
|
using Questionable.Model.Changelog;
|
|
using Questionable.Windows.ChangelogComponents;
|
|
|
|
namespace Questionable.Windows;
|
|
|
|
internal sealed class ChangelogWindow : LWindow
|
|
{
|
|
private readonly Configuration _configuration;
|
|
|
|
private readonly IDalamudPluginInterface _pluginInterface;
|
|
|
|
private readonly ChangelogHeaderComponent _headerComponent;
|
|
|
|
private readonly ChangelogFooterComponent _footerComponent;
|
|
|
|
private int _windowOpenCount;
|
|
|
|
private bool _hasSetInitialState;
|
|
|
|
private float _headerAnimationTime;
|
|
|
|
public ChangelogWindow(Configuration configuration, IDalamudPluginInterface pluginInterface)
|
|
: base("Questionable Changelog###QuestionableChangelog", ImGuiWindowFlags.NoTitleBar)
|
|
{
|
|
_configuration = configuration;
|
|
_pluginInterface = pluginInterface;
|
|
_headerComponent = new ChangelogHeaderComponent();
|
|
_footerComponent = new ChangelogFooterComponent();
|
|
base.Size = new Vector2(900f, 650f);
|
|
base.SizeCondition = ImGuiCond.FirstUseEver;
|
|
base.SizeConstraints = new WindowSizeConstraints
|
|
{
|
|
MinimumSize = new Vector2(700f, 500f),
|
|
MaximumSize = new Vector2(float.MaxValue, float.MaxValue)
|
|
};
|
|
}
|
|
|
|
public override void DrawContent()
|
|
{
|
|
_headerComponent.Draw(delegate(bool isOpen)
|
|
{
|
|
base.IsOpen = isOpen;
|
|
});
|
|
DrawChangelogEntries();
|
|
ChangelogFooterComponent.Draw(delegate
|
|
{
|
|
MarkAllAsRead();
|
|
base.IsOpen = false;
|
|
});
|
|
ImDrawListPtr windowDrawList = ImGui.GetWindowDrawList();
|
|
Vector2 windowPos = ImGui.GetWindowPos();
|
|
Vector2 windowSize = ImGui.GetWindowSize();
|
|
windowDrawList.AddRect(windowPos, windowPos + windowSize, ImGui.ColorConvertFloat4ToU32(new Vector4(0.65f, 0.55f, 0.85f, 0.3f)), 0f, ImDrawFlags.None, 2f);
|
|
}
|
|
|
|
public override void OnOpen()
|
|
{
|
|
base.OnOpen();
|
|
_windowOpenCount++;
|
|
_hasSetInitialState = false;
|
|
_headerAnimationTime = 0f;
|
|
_headerComponent.Reset();
|
|
}
|
|
|
|
private void DrawChangelogEntries()
|
|
{
|
|
_headerAnimationTime += ImGui.GetIO().DeltaTime;
|
|
using (ImRaii.PushColor(ImGuiCol.ScrollbarBg, new Vector4(0.1f, 0.08f, 0.14f, 0.6f)))
|
|
{
|
|
using (ImRaii.PushColor(ImGuiCol.ScrollbarGrab, new Vector4(0.55f, 0.45f, 0.75f, 0.4f)))
|
|
{
|
|
using (ImRaii.PushColor(ImGuiCol.ScrollbarGrabHovered, new Vector4(0.65f, 0.55f, 0.85f, 0.6f)))
|
|
{
|
|
using (ImRaii.PushColor(ImGuiCol.ScrollbarGrabActive, new Vector4(0.75f, 0.55f, 0.95f, 0.8f)))
|
|
{
|
|
float num = ImGui.GetFrameHeightWithSpacing() + ImGui.GetStyle().ItemSpacing.Y * 2f;
|
|
using ImRaii.IEndObject endObject = ImRaii.Child("ChangelogScroll", new Vector2(0f, 0f - num), border: false, ImGuiWindowFlags.NoScrollbar);
|
|
if (!endObject)
|
|
{
|
|
return;
|
|
}
|
|
using ImRaii.IEndObject endObject2 = ImRaii.Child("ChangelogScrollInner", Vector2.Zero, border: false);
|
|
if (!endObject2)
|
|
{
|
|
return;
|
|
}
|
|
List<ChangelogEntry> changelogs = ChangelogData.Changelogs;
|
|
ChangelogEntry changelogEntry = changelogs.FirstOrDefault();
|
|
if (changelogs.Count == 0)
|
|
{
|
|
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + 40f);
|
|
Vector2 vector = ImGui.CalcTextSize("No changelog entries available.");
|
|
ImGui.SetCursorPosX((ImGui.GetContentRegionAvail().X - vector.X) * 0.5f);
|
|
ImGui.TextDisabled("No changelog entries available.");
|
|
return;
|
|
}
|
|
ChangelogEntryComponent changelogEntryComponent = new ChangelogEntryComponent(_configuration, _windowOpenCount, _headerAnimationTime);
|
|
foreach (ChangelogEntry item in changelogs)
|
|
{
|
|
changelogEntryComponent.Draw(item, item == changelogEntry, _hasSetInitialState);
|
|
Vector2 cursorScreenPos = ImGui.GetCursorScreenPos();
|
|
float num2 = ImGui.GetContentRegionAvail().X * 0.5f;
|
|
float num3 = (ImGui.GetContentRegionAvail().X - num2) * 0.5f;
|
|
ImGui.GetWindowDrawList().AddLine(cursorScreenPos + new Vector2(num3, 0f), cursorScreenPos + new Vector2(num3 + num2, 0f), ImGui.ColorConvertFloat4ToU32(new Vector4(0.55f, 0.45f, 0.75f, 0.1f)), 1f);
|
|
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + 4f);
|
|
}
|
|
_hasSetInitialState = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void MarkAllAsRead()
|
|
{
|
|
string text = ChangelogData.Changelogs.FirstOrDefault()?.Version;
|
|
if (text != null)
|
|
{
|
|
_configuration.LastViewedChangelogVersion = text;
|
|
_pluginInterface.SavePluginConfig(_configuration);
|
|
}
|
|
}
|
|
}
|