feat: implement suggestions
This commit is contained in:
parent
24152d62a1
commit
9b22b14265
|
@ -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",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Version>1.3.1</Version>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -11,7 +11,7 @@ internal class QuestionManager : IDisposable, IReadOnlyList<IQuestion> {
|
|||
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<IQuestion> {
|
|||
var json = await resp.Content.ReadAsStringAsync();
|
||||
this._questions = JsonConvert.DeserializeObject<QuestionsResponse>(json, Plugin.SerializerSettings) ?? new QuestionsResponse {
|
||||
Current = null,
|
||||
Page = new(),
|
||||
Page = [],
|
||||
HasNext = false,
|
||||
};
|
||||
await this.OpenIfNew();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@ internal class PluginUi : IDisposable {
|
|||
#endif
|
||||
|
||||
private string _dateScratch = string.Empty;
|
||||
private readonly List<IDrawable> _drawables = new();
|
||||
private readonly List<IDrawable> _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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
namespace EorzeaVotes.Ui;
|
||||
|
||||
internal enum TabId {
|
||||
Questions,
|
||||
Settings,
|
||||
Suggestions,
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"version": 1,
|
||||
"dependencies": {
|
||||
"net7.0-windows7.0": {
|
||||
"net8.0-windows7.0": {
|
||||
"DalamudPackager": {
|
||||
"type": "Direct",
|
||||
"requested": "[2.1.12, )",
|
||||
|
|
Loading…
Reference in New Issue