yeeeeeeeeeehaw
This commit is contained in:
parent
305b2bed4a
commit
a4751ca288
|
@ -57,3 +57,17 @@ internal class MessageWithTerritory {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
|
||||
internal class ErrorMessage {
|
||||
public string Code { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
|
||||
internal class MyMessages {
|
||||
public uint Extra { get; set; }
|
||||
public MessageWithTerritory[] Messages { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using ImGuiNET;
|
||||
using OrangeGuidanceTomestone.Ui;
|
||||
|
||||
namespace OrangeGuidanceTomestone;
|
||||
|
@ -9,6 +10,8 @@ public class PluginUi : IDisposable {
|
|||
internal Viewer Viewer { get; }
|
||||
internal ViewerButton ViewerButton { get; }
|
||||
|
||||
private List<(string, string)> Modals { get; } = new();
|
||||
|
||||
internal PluginUi(Plugin plugin) {
|
||||
this.Plugin = plugin;
|
||||
this.MainWindow = new MainWindow(this.Plugin);
|
||||
|
@ -26,5 +29,39 @@ public class PluginUi : IDisposable {
|
|||
this.MainWindow.Draw();
|
||||
this.ViewerButton.Draw();
|
||||
this.Viewer.Draw();
|
||||
this.DrawModals();
|
||||
}
|
||||
|
||||
private void DrawModals() {
|
||||
var toRemove = -1;
|
||||
for (var i = 0; i < this.Modals.Count; i++) {
|
||||
var (id, text) = this.Modals[i];
|
||||
if (!ImGui.BeginPopupModal(id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ImGui.TextUnformatted(text);
|
||||
ImGui.Separator();
|
||||
|
||||
ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X);
|
||||
if (ImGui.Button("Close")) {
|
||||
ImGui.CloseCurrentPopup();
|
||||
toRemove = i;
|
||||
}
|
||||
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
|
||||
if (toRemove > -1) {
|
||||
this.Modals.RemoveAt(toRemove);
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddModal(string text) {
|
||||
this.AddModal(Guid.NewGuid().ToString(), text);
|
||||
}
|
||||
|
||||
internal void AddModal(string id, string text) {
|
||||
this.Modals.Add((id, text));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ internal class MainWindow {
|
|||
private List<ITab> Tabs { get; }
|
||||
|
||||
internal bool Visible;
|
||||
internal uint ExtraMessages;
|
||||
|
||||
internal MainWindow(Plugin plugin) {
|
||||
this.Plugin = plugin;
|
||||
|
|
|
@ -24,6 +24,10 @@ internal class MessageList : ITab {
|
|||
|
||||
this.MessagesMutex.Wait();
|
||||
|
||||
ImGui.TextUnformatted($"Messages: {this.Messages.Count:N0} / {10 + this.Plugin.Ui.MainWindow.ExtraMessages:N0}");
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
foreach (var message in this.Messages) {
|
||||
var territory = this.Plugin.DataManager.GetExcelSheet<TerritoryType>()?.GetRow(message.Territory);
|
||||
var territoryName = territory?.PlaceName.Value?.Name?.ToDalamudString().TextValue ?? "???";
|
||||
|
@ -50,13 +54,14 @@ internal class MessageList : ITab {
|
|||
var resp = await ServerHelper.SendRequest(
|
||||
this.Plugin.Config.ApiKey,
|
||||
HttpMethod.Get,
|
||||
"/messages"
|
||||
"/messages?v=2"
|
||||
);
|
||||
var json = await resp.Content.ReadAsStringAsync();
|
||||
var messages = JsonConvert.DeserializeObject<MessageWithTerritory[]>(json)!;
|
||||
var messages = JsonConvert.DeserializeObject<MyMessages>(json)!;
|
||||
await this.MessagesMutex.WaitAsync();
|
||||
this.Plugin.Ui.MainWindow.ExtraMessages = messages.Extra;
|
||||
this.Messages.Clear();
|
||||
this.Messages.AddRange(messages);
|
||||
this.Messages.AddRange(messages.Messages);
|
||||
this.MessagesMutex.Release();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using ImGuiNET;
|
||||
using OrangeGuidanceTomestone.Helpers;
|
||||
|
||||
namespace OrangeGuidanceTomestone.Ui.MainWindowTabs;
|
||||
|
||||
|
@ -6,6 +7,7 @@ internal class Settings : ITab {
|
|||
public string Name => "Settings";
|
||||
|
||||
private Plugin Plugin { get; }
|
||||
private string _extraCode = string.Empty;
|
||||
|
||||
internal Settings(Plugin plugin) {
|
||||
this.Plugin = plugin;
|
||||
|
@ -27,5 +29,38 @@ internal class Settings : ITab {
|
|||
this.Plugin.Messages.RemoveVfx();
|
||||
this.Plugin.Messages.Clear();
|
||||
}
|
||||
|
||||
this.ExtraCodeInput();
|
||||
}
|
||||
|
||||
private void ExtraCodeInput() {
|
||||
ImGui.InputText("Extra code", ref this._extraCode, 128);
|
||||
if (!ImGui.Button("Claim")) {
|
||||
return;
|
||||
}
|
||||
|
||||
var code = this._extraCode;
|
||||
Task.Run(async () => {
|
||||
var resp = await ServerHelper.SendRequest(
|
||||
this.Plugin.Config.ApiKey,
|
||||
HttpMethod.Post,
|
||||
"/claim",
|
||||
null,
|
||||
new StringContent(code)
|
||||
);
|
||||
|
||||
if (resp.IsSuccessStatusCode) {
|
||||
this._extraCode = string.Empty;
|
||||
var text = await resp.Content.ReadAsStringAsync();
|
||||
if (uint.TryParse(text, out var extra)) {
|
||||
this.Plugin.Ui.MainWindow.ExtraMessages = extra;
|
||||
this.Plugin.Ui.AddModal($"Code claimed.\n\nYou can now post up to {10 + extra:N0} messages.");
|
||||
} else {
|
||||
this.Plugin.Ui.AddModal("Code claimed but the server gave an unexpected response.");
|
||||
}
|
||||
} else {
|
||||
this.Plugin.Ui.AddModal("Invalid code.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,10 +171,10 @@ internal class Write : ITab {
|
|||
"application/json",
|
||||
new StringContent(json)
|
||||
);
|
||||
var id = await resp.Content.ReadAsStringAsync();
|
||||
var content = await resp.Content.ReadAsStringAsync();
|
||||
if (resp.IsSuccessStatusCode) {
|
||||
var newMsg = new Message {
|
||||
Id = Guid.Parse(id),
|
||||
Id = Guid.Parse(content),
|
||||
X = player.Position.X,
|
||||
Y = player.Position.Y,
|
||||
Z = player.Position.Z,
|
||||
|
@ -187,6 +187,9 @@ internal class Write : ITab {
|
|||
this.Plugin.Messages.Add(newMsg);
|
||||
this.ResetWriter();
|
||||
this.Plugin.Ui.MainWindow.Visible = false;
|
||||
} else {
|
||||
var error = JsonConvert.DeserializeObject<ErrorMessage>(content);
|
||||
this.Plugin.Ui.AddModal($"Error writing message.\n\nMessage from server:\n{error?.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue