feat: implement suggestions
This commit is contained in:
parent
24152d62a1
commit
9b22b14265
|
@ -14,7 +14,9 @@ internal class Commands : IDisposable {
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
|
|
||||||
foreach (var name in CommandNames) {
|
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",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>1.3.1</Version>
|
<Version>1.3.1</Version>
|
||||||
<TargetFramework>net7.0-windows</TargetFramework>
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
|
|
@ -3,3 +3,8 @@ author: Anna
|
||||||
punchline: Cast your vote in daily lighthearted opinion polls! Is a hot dog a sandwich?
|
punchline: Cast your vote in daily lighthearted opinion polls! Is a hot dog a sandwich?
|
||||||
description: |
|
description: |
|
||||||
Cast your vote in daily lighthearted opinion polls!
|
Cast your vote in daily lighthearted opinion polls!
|
||||||
|
tags:
|
||||||
|
- vote
|
||||||
|
- voting
|
||||||
|
- questions
|
||||||
|
- eorzea
|
||||||
|
|
|
@ -11,7 +11,7 @@ internal class QuestionManager : IDisposable, IReadOnlyList<IQuestion> {
|
||||||
private HttpClient Http { get; }
|
private HttpClient Http { get; }
|
||||||
|
|
||||||
private QuestionsResponse _questions = new() {
|
private QuestionsResponse _questions = new() {
|
||||||
Page = new(),
|
Page = [],
|
||||||
};
|
};
|
||||||
|
|
||||||
private Guid _lastSeenActive = Guid.Empty;
|
private Guid _lastSeenActive = Guid.Empty;
|
||||||
|
@ -151,7 +151,7 @@ internal class QuestionManager : IDisposable, IReadOnlyList<IQuestion> {
|
||||||
var json = await resp.Content.ReadAsStringAsync();
|
var json = await resp.Content.ReadAsStringAsync();
|
||||||
this._questions = JsonConvert.DeserializeObject<QuestionsResponse>(json, Plugin.SerializerSettings) ?? new QuestionsResponse {
|
this._questions = JsonConvert.DeserializeObject<QuestionsResponse>(json, Plugin.SerializerSettings) ?? new QuestionsResponse {
|
||||||
Current = null,
|
Current = null,
|
||||||
Page = new(),
|
Page = [],
|
||||||
HasNext = false,
|
HasNext = false,
|
||||||
};
|
};
|
||||||
await this.OpenIfNew();
|
await this.OpenIfNew();
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Text;
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
using EorzeaVotes.Utilities;
|
using EorzeaVotes.Utilities;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
@ -187,4 +188,20 @@ internal static class ImGuiHelper {
|
||||||
|
|
||||||
return ImGui.Button(label);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,8 @@ internal class PluginUi : IDisposable {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private string _dateScratch = string.Empty;
|
private string _dateScratch = string.Empty;
|
||||||
private readonly List<IDrawable> _drawables = new();
|
private readonly List<IDrawable> _drawables = [];
|
||||||
|
private TabId? _forceOpen;
|
||||||
|
|
||||||
private QuestionsTab QuestionsTab { get; }
|
private QuestionsTab QuestionsTab { get; }
|
||||||
private SettingsTab SettingsTab { get; }
|
private SettingsTab SettingsTab { get; }
|
||||||
|
@ -32,12 +33,26 @@ internal class PluginUi : IDisposable {
|
||||||
this.UpdateDateScratch();
|
this.UpdateDateScratch();
|
||||||
|
|
||||||
this.Plugin.Interface.UiBuilder.Draw += this.Draw;
|
this.Plugin.Interface.UiBuilder.Draw += this.Draw;
|
||||||
|
this.Plugin.Interface.UiBuilder.OpenConfigUi += this.OpenConfigUi;
|
||||||
|
this.Plugin.Interface.UiBuilder.OpenMainUi += this.OpenMainUi;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
|
this.Plugin.Interface.UiBuilder.OpenMainUi -= this.OpenMainUi;
|
||||||
|
this.Plugin.Interface.UiBuilder.OpenConfigUi -= this.OpenConfigUi;
|
||||||
this.Plugin.Interface.UiBuilder.Draw -= this.Draw;
|
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() {
|
private void UpdateDateScratch() {
|
||||||
this._dateScratch = this.Plugin.Config.BirthDate?.ToString("O") ?? string.Empty;
|
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);
|
using var endTabBar = new OnDispose(ImGui.EndTabBar);
|
||||||
|
|
||||||
this.QuestionsTab.Draw();
|
var forceOpen = this._forceOpen;
|
||||||
this.SettingsTab.Draw();
|
this._forceOpen = null;
|
||||||
SuggestTab.Draw();
|
|
||||||
|
this.QuestionsTab.Draw(forceOpen == TabId.Questions);
|
||||||
|
this.SettingsTab.Draw(forceOpen == TabId.Settings);
|
||||||
|
SuggestTab.Draw(forceOpen == TabId.Suggestions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace EorzeaVotes.Ui;
|
||||||
|
|
||||||
|
internal enum TabId {
|
||||||
|
Questions,
|
||||||
|
Settings,
|
||||||
|
Suggestions,
|
||||||
|
}
|
|
@ -15,8 +15,8 @@ internal class QuestionsTab {
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Draw() {
|
internal void Draw(bool forceOpen) {
|
||||||
if (!ImGui.BeginTabItem("Questions")) {
|
if (!ImGuiHelper.BeginTabItem("Questions", forceOpen)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@ internal class SettingsTab {
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Draw() {
|
internal void Draw(bool forceOpen) {
|
||||||
if (!ImGui.BeginTabItem("Settings")) {
|
if (!ImGuiHelper.BeginTabItem("Settings", forceOpen)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ using ImGuiNET;
|
||||||
namespace EorzeaVotes.Ui.Tabs;
|
namespace EorzeaVotes.Ui.Tabs;
|
||||||
|
|
||||||
internal class SuggestTab {
|
internal class SuggestTab {
|
||||||
internal static void Draw() {
|
internal static void Draw(bool forceOpen) {
|
||||||
if (!ImGui.BeginTabItem("Suggest a question")) {
|
if (!ImGuiHelper.BeginTabItem("Suggest a question", forceOpen)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,4 +19,4 @@ internal class SuggestTab {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"net7.0-windows7.0": {
|
"net8.0-windows7.0": {
|
||||||
"DalamudPackager": {
|
"DalamudPackager": {
|
||||||
"type": "Direct",
|
"type": "Direct",
|
||||||
"requested": "[2.1.12, )",
|
"requested": "[2.1.12, )",
|
||||||
|
|
Loading…
Reference in New Issue