This commit is contained in:
Anna 2022-09-04 01:10:48 -04:00
parent ea4875c297
commit d5ffdd41e7
3 changed files with 22 additions and 18 deletions

View File

@ -55,7 +55,7 @@ internal class Messages : IDisposable {
this.SpawnVfx();
}
private void SpawnVfx() {
internal void SpawnVfx() {
var territory = this.Plugin.ClientState.TerritoryType;
if (territory == 0) {
return;

View File

@ -19,11 +19,16 @@ internal class MessageList : ITab {
if (ImGui.Button("Refresh")) {
this.Refresh();
}
this.MessagesMutex.Wait();
foreach (var message in this.Messages) {
ImGui.TextUnformatted(message.Text);
ImGui.TextUnformatted($"Likes: {message.PositiveVotes}");
ImGui.TextUnformatted($"Dislikes: {message.NegativeVotes}");
if (ImGui.Button($"Delete##{message.Id}")) {
this.Delete(message.Id);
}
}
this.MessagesMutex.Release();
@ -45,6 +50,21 @@ internal class MessageList : ITab {
});
}
private void Delete(Guid id) {
Task.Run(async () => {
var resp = await ServerHelper.SendRequest(
this.Plugin.Config.ApiKey,
HttpMethod.Delete,
$"/messages/{id}"
);
if (resp.IsSuccessStatusCode) {
this.Refresh();
this.Plugin.Messages.SpawnVfx();
}
});
}
internal void Add(MessageWithTerritory message) {
this.Messages.Clear();
this.Messages.Add(message);

View File

@ -1,7 +1,6 @@
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using Dalamud.Game;
using Dalamud.Utility.Signatures;
namespace OrangeGuidanceTomestone;
@ -21,37 +20,22 @@ internal unsafe class Vfx : IDisposable {
private delegate* unmanaged<VfxStruct*, void> _staticVfxRemove;
private List<IntPtr> Spawned { get; } = new();
private Queue<IntPtr> NeedToRun { get; } = new();
internal Vfx(Plugin plugin) {
this.Plugin = plugin;
SignatureHelper.Initialise(this);
this.Plugin.Framework.Update += this.Run;
}
public void Dispose() {
this.Plugin.Framework.Update -= this.Run;
this.RemoveAll();
}
private void Run(Framework framework) {
if (!this.NeedToRun.TryDequeue(out var ptr)) {
return;
}
if (this._staticVfxRun((VfxStruct*) ptr, 0.0f, 0xFFFFFFFF) != 0) {
this.NeedToRun.Enqueue(ptr);
}
}
internal void RemoveAll() {
foreach (var spawned in this.Spawned) {
this.RemoveStatic((VfxStruct*) spawned);
}
this.Spawned.Clear();
this.NeedToRun.Clear();
}
internal VfxStruct* SpawnStatic(string path, Vector3 pos) {