From 9b22b14265eeacd8186d58626476d7510820ab36 Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 10 Apr 2024 22:08:15 -0400 Subject: [PATCH] feat: implement suggestions --- client/EorzeaVotes/Commands.cs | 4 +++- client/EorzeaVotes/EorzeaVotes.csproj | 2 +- client/EorzeaVotes/EorzeaVotes.yaml | 5 +++++ client/EorzeaVotes/QuestionManager.cs | 4 ++-- client/EorzeaVotes/Ui/ImGuiHelper.cs | 17 +++++++++++++++ client/EorzeaVotes/Ui/PluginUi.cs | 26 +++++++++++++++++++---- client/EorzeaVotes/Ui/TabId.cs | 7 ++++++ client/EorzeaVotes/Ui/Tabs/Questions.cs | 4 ++-- client/EorzeaVotes/Ui/Tabs/SettingsTab.cs | 4 ++-- client/EorzeaVotes/Ui/Tabs/SuggestTab.cs | 6 +++--- client/EorzeaVotes/packages.lock.json | 2 +- 11 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 client/EorzeaVotes/Ui/TabId.cs diff --git a/client/EorzeaVotes/Commands.cs b/client/EorzeaVotes/Commands.cs index 4c1c3d5..e241794 100644 --- a/client/EorzeaVotes/Commands.cs +++ b/client/EorzeaVotes/Commands.cs @@ -14,7 +14,9 @@ internal class Commands : IDisposable { this.Plugin = plugin; foreach (var name in CommandNames) { - this.Plugin.CommandManager.AddHandler(name, new CommandInfo(this.Handler)); + this.Plugin.CommandManager.AddHandler(name, new CommandInfo(this.Handler) { + HelpMessage = "Toggle the main interface", + }); } } diff --git a/client/EorzeaVotes/EorzeaVotes.csproj b/client/EorzeaVotes/EorzeaVotes.csproj index 4c7f98b..d4dff33 100644 --- a/client/EorzeaVotes/EorzeaVotes.csproj +++ b/client/EorzeaVotes/EorzeaVotes.csproj @@ -2,7 +2,7 @@ 1.3.1 - net7.0-windows + net8.0-windows enable enable true diff --git a/client/EorzeaVotes/EorzeaVotes.yaml b/client/EorzeaVotes/EorzeaVotes.yaml index 35e5a07..475d0c8 100755 --- a/client/EorzeaVotes/EorzeaVotes.yaml +++ b/client/EorzeaVotes/EorzeaVotes.yaml @@ -3,3 +3,8 @@ author: Anna punchline: Cast your vote in daily lighthearted opinion polls! Is a hot dog a sandwich? description: | Cast your vote in daily lighthearted opinion polls! +tags: + - vote + - voting + - questions + - eorzea diff --git a/client/EorzeaVotes/QuestionManager.cs b/client/EorzeaVotes/QuestionManager.cs index 749a9e4..a2adc7a 100644 --- a/client/EorzeaVotes/QuestionManager.cs +++ b/client/EorzeaVotes/QuestionManager.cs @@ -11,7 +11,7 @@ internal class QuestionManager : IDisposable, IReadOnlyList { private HttpClient Http { get; } private QuestionsResponse _questions = new() { - Page = new(), + Page = [], }; private Guid _lastSeenActive = Guid.Empty; @@ -151,7 +151,7 @@ internal class QuestionManager : IDisposable, IReadOnlyList { var json = await resp.Content.ReadAsStringAsync(); this._questions = JsonConvert.DeserializeObject(json, Plugin.SerializerSettings) ?? new QuestionsResponse { Current = null, - Page = new(), + Page = [], HasNext = false, }; await this.OpenIfNew(); diff --git a/client/EorzeaVotes/Ui/ImGuiHelper.cs b/client/EorzeaVotes/Ui/ImGuiHelper.cs index f84e6c2..9604264 100644 --- a/client/EorzeaVotes/Ui/ImGuiHelper.cs +++ b/client/EorzeaVotes/Ui/ImGuiHelper.cs @@ -1,3 +1,4 @@ +using System.Text; using Dalamud.Interface; using EorzeaVotes.Utilities; using ImGuiNET; @@ -187,4 +188,20 @@ internal static class ImGuiHelper { return ImGui.Button(label); } + + internal static unsafe bool BeginTabItem(string label, bool forceOpen = false) { + var flags = forceOpen + ? ImGuiTabItemFlags.SetSelected + : ImGuiTabItemFlags.None; + + var bufSize = Encoding.UTF8.GetByteCount(label); + var labelBuf = stackalloc byte[bufSize + 1]; + fixed (char* labelPtr = label) { + Encoding.UTF8.GetBytes(labelPtr, label.Length, labelBuf, bufSize); + } + + labelBuf[bufSize] = 0; + + return ImGuiNative.igBeginTabItem(labelBuf, null, flags) > 0u; + } } diff --git a/client/EorzeaVotes/Ui/PluginUi.cs b/client/EorzeaVotes/Ui/PluginUi.cs index 0afd0f5..d29ac9a 100644 --- a/client/EorzeaVotes/Ui/PluginUi.cs +++ b/client/EorzeaVotes/Ui/PluginUi.cs @@ -19,7 +19,8 @@ internal class PluginUi : IDisposable { #endif private string _dateScratch = string.Empty; - private readonly List _drawables = new(); + private readonly List _drawables = []; + private TabId? _forceOpen; private QuestionsTab QuestionsTab { get; } private SettingsTab SettingsTab { get; } @@ -32,12 +33,26 @@ internal class PluginUi : IDisposable { this.UpdateDateScratch(); this.Plugin.Interface.UiBuilder.Draw += this.Draw; + this.Plugin.Interface.UiBuilder.OpenConfigUi += this.OpenConfigUi; + this.Plugin.Interface.UiBuilder.OpenMainUi += this.OpenMainUi; } public void Dispose() { + this.Plugin.Interface.UiBuilder.OpenMainUi -= this.OpenMainUi; + this.Plugin.Interface.UiBuilder.OpenConfigUi -= this.OpenConfigUi; this.Plugin.Interface.UiBuilder.Draw -= this.Draw; } + private void OpenConfigUi() { + this.Visible = true; + this._forceOpen = TabId.Settings; + } + + private void OpenMainUi() { + this.Visible = true; + this._forceOpen = TabId.Questions; + } + private void UpdateDateScratch() { this._dateScratch = this.Plugin.Config.BirthDate?.ToString("O") ?? string.Empty; } @@ -209,8 +224,11 @@ internal class PluginUi : IDisposable { using var endTabBar = new OnDispose(ImGui.EndTabBar); - this.QuestionsTab.Draw(); - this.SettingsTab.Draw(); - SuggestTab.Draw(); + var forceOpen = this._forceOpen; + this._forceOpen = null; + + this.QuestionsTab.Draw(forceOpen == TabId.Questions); + this.SettingsTab.Draw(forceOpen == TabId.Settings); + SuggestTab.Draw(forceOpen == TabId.Suggestions); } } diff --git a/client/EorzeaVotes/Ui/TabId.cs b/client/EorzeaVotes/Ui/TabId.cs new file mode 100644 index 0000000..03c32c2 --- /dev/null +++ b/client/EorzeaVotes/Ui/TabId.cs @@ -0,0 +1,7 @@ +namespace EorzeaVotes.Ui; + +internal enum TabId { + Questions, + Settings, + Suggestions, +} diff --git a/client/EorzeaVotes/Ui/Tabs/Questions.cs b/client/EorzeaVotes/Ui/Tabs/Questions.cs index 637c1c9..fdefc7b 100644 --- a/client/EorzeaVotes/Ui/Tabs/Questions.cs +++ b/client/EorzeaVotes/Ui/Tabs/Questions.cs @@ -15,8 +15,8 @@ internal class QuestionsTab { this.Plugin = plugin; } - internal void Draw() { - if (!ImGui.BeginTabItem("Questions")) { + internal void Draw(bool forceOpen) { + if (!ImGuiHelper.BeginTabItem("Questions", forceOpen)) { return; } diff --git a/client/EorzeaVotes/Ui/Tabs/SettingsTab.cs b/client/EorzeaVotes/Ui/Tabs/SettingsTab.cs index c1992a7..483d365 100644 --- a/client/EorzeaVotes/Ui/Tabs/SettingsTab.cs +++ b/client/EorzeaVotes/Ui/Tabs/SettingsTab.cs @@ -12,8 +12,8 @@ internal class SettingsTab { this.Plugin = plugin; } - internal void Draw() { - if (!ImGui.BeginTabItem("Settings")) { + internal void Draw(bool forceOpen) { + if (!ImGuiHelper.BeginTabItem("Settings", forceOpen)) { return; } diff --git a/client/EorzeaVotes/Ui/Tabs/SuggestTab.cs b/client/EorzeaVotes/Ui/Tabs/SuggestTab.cs index 32ef3c3..8d9b81d 100644 --- a/client/EorzeaVotes/Ui/Tabs/SuggestTab.cs +++ b/client/EorzeaVotes/Ui/Tabs/SuggestTab.cs @@ -5,8 +5,8 @@ using ImGuiNET; namespace EorzeaVotes.Ui.Tabs; internal class SuggestTab { - internal static void Draw() { - if (!ImGui.BeginTabItem("Suggest a question")) { + internal static void Draw(bool forceOpen) { + if (!ImGuiHelper.BeginTabItem("Suggest a question", forceOpen)) { return; } @@ -19,4 +19,4 @@ internal class SuggestTab { }); } } -} \ No newline at end of file +} diff --git a/client/EorzeaVotes/packages.lock.json b/client/EorzeaVotes/packages.lock.json index 71563b8..bca93a9 100644 --- a/client/EorzeaVotes/packages.lock.json +++ b/client/EorzeaVotes/packages.lock.json @@ -1,7 +1,7 @@ { "version": 1, "dependencies": { - "net7.0-windows7.0": { + "net8.0-windows7.0": { "DalamudPackager": { "type": "Direct", "requested": "[2.1.12, )",