using System.Collections.Generic; using System.Linq; using System.Numerics; using Dalamud.Bindings.ImGui; using Dalamud.Interface; using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Windowing; using Dalamud.Plugin; using Questionable.Data; using Questionable.Model.Changelog; using Questionable.Windows.ChangelogComponents; namespace Questionable.Windows; internal sealed class ChangelogWindow : ThemedWindow { 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) { if (!isOpen) { RequestClose(); } }); DrawChangelogEntries(); ChangelogFooterComponent.Draw(base.RequestClose); ImDrawListPtr windowDrawList = ImGui.GetWindowDrawList(); Vector2 windowPos = ImGui.GetWindowPos(); Vector2 windowSize = ImGui.GetWindowSize(); Vector2 pMax = windowPos + windowSize; Vector4 accentColor = UiThemeUtils.AccentColor; accentColor.W = 0.3f; windowDrawList.AddRect(windowPos, pMax, ImGui.ColorConvertFloat4ToU32(accentColor), 0f, ImDrawFlags.None, 2f); } public override void OnOpen() { base.OnOpen(); _windowOpenCount++; _hasSetInitialState = false; _headerAnimationTime = 0f; _headerComponent.Reset(); } public override void OnClose() { base.OnClose(); MarkAllAsRead(); } private void DrawChangelogEntries() { _headerAnimationTime += ImGui.GetIO().DeltaTime; float num = ImGui.GetFrameHeightWithSpacing() + ImGui.GetStyle().ItemSpacing.Y * 2f; using ImRaii.ChildDisposable childDisposable = ImRaii.Child("ChangelogScroll", new Vector2(0f, 0f - num), border: false, ImGuiWindowFlags.NoScrollbar); if (!childDisposable) { return; } using ImRaii.ChildDisposable childDisposable2 = ImRaii.Child("ChangelogScrollInner", Vector2.Zero, border: false); if (!childDisposable2) { return; } List changelogs = ChangelogData.Changelogs; ChangelogEntry changelogEntry = changelogs.FirstOrDefault(); if (changelogs.Count == 0) { ImGui.SetCursorPosY(ImGui.GetCursorPosY() + 40f); UiThemeUtils.EmptyState(FontAwesomeIcon.FileAlt, "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; ImDrawListPtr windowDrawList = ImGui.GetWindowDrawList(); Vector2 p = cursorScreenPos + new Vector2(num3, 0f); Vector2 p2 = cursorScreenPos + new Vector2(num3 + num2, 0f); Vector4 accentColor = UiThemeUtils.AccentColor; accentColor.W = 0.1f; windowDrawList.AddLine(p, p2, ImGui.ColorConvertFloat4ToU32(accentColor), 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); } } }