2022-09-07 17:49:14 +00:00
|
|
|
using System.Numerics;
|
2022-09-05 08:02:34 +00:00
|
|
|
using ImGuiNET;
|
2022-09-05 08:21:45 +00:00
|
|
|
using OrangeGuidanceTomestone.Helpers;
|
2022-09-05 08:02:34 +00:00
|
|
|
|
|
|
|
namespace OrangeGuidanceTomestone.Ui.MainWindowTabs;
|
|
|
|
|
|
|
|
internal class Settings : ITab {
|
|
|
|
public string Name => "Settings";
|
|
|
|
|
|
|
|
private Plugin Plugin { get; }
|
2022-09-07 17:42:43 +00:00
|
|
|
private int _tab = 0;
|
2022-09-05 08:21:45 +00:00
|
|
|
private string _extraCode = string.Empty;
|
2022-09-05 08:02:34 +00:00
|
|
|
|
2022-09-07 17:42:43 +00:00
|
|
|
private delegate void DrawSettingsDelegate(ref bool anyChanged, ref bool vfx);
|
|
|
|
|
|
|
|
private IReadOnlyList<(string, DrawSettingsDelegate)> Tabs { get; }
|
|
|
|
|
2022-09-05 08:02:34 +00:00
|
|
|
internal Settings(Plugin plugin) {
|
|
|
|
this.Plugin = plugin;
|
2022-09-07 17:42:43 +00:00
|
|
|
|
|
|
|
this.Tabs = new List<(string, DrawSettingsDelegate)> {
|
|
|
|
("General", this.DrawGeneral),
|
|
|
|
("Writer", this.DrawWriter),
|
|
|
|
("Viewer", this.DrawViewer),
|
|
|
|
("Unlocks", this.DrawUnlocks),
|
|
|
|
("Account", this.DrawAccount),
|
|
|
|
};
|
2022-09-05 08:02:34 +00:00
|
|
|
}
|
|
|
|
|
2022-09-06 07:37:03 +00:00
|
|
|
public void Dispose() {
|
|
|
|
}
|
|
|
|
|
2022-09-05 08:02:34 +00:00
|
|
|
public void Draw() {
|
2022-09-05 09:05:14 +00:00
|
|
|
ImGui.PushTextWrapPos();
|
|
|
|
|
2022-09-05 08:02:34 +00:00
|
|
|
var anyChanged = false;
|
|
|
|
var vfx = false;
|
|
|
|
|
2022-09-07 17:42:43 +00:00
|
|
|
var widestTabName = this.Tabs
|
|
|
|
.Select(entry => ImGui.CalcTextSize(entry.Item1).X)
|
|
|
|
.Max();
|
2022-09-05 08:02:34 +00:00
|
|
|
|
2022-09-07 17:42:43 +00:00
|
|
|
var leftOver = ImGui.GetContentRegionAvail().X - widestTabName - ImGui.GetStyle().ItemSpacing.X - ImGui.GetStyle().FrameBorderSize;
|
2022-09-07 17:49:14 +00:00
|
|
|
var childHeight = ImGui.GetContentRegionAvail().Y - ImGui.GetStyle().ItemSpacing.Y * 2;
|
2022-09-07 17:42:43 +00:00
|
|
|
if (ImGui.BeginTable("##settings-tabs", 2)) {
|
|
|
|
ImGui.TableSetupColumn("##names", ImGuiTableColumnFlags.None, widestTabName + ImGui.GetStyle().ItemSpacing.X);
|
|
|
|
ImGui.TableSetupColumn("##content", ImGuiTableColumnFlags.None, leftOver);
|
2022-09-06 07:57:38 +00:00
|
|
|
|
2022-09-07 17:42:43 +00:00
|
|
|
ImGui.TableNextRow();
|
2022-09-07 17:25:05 +00:00
|
|
|
|
2022-09-07 17:42:43 +00:00
|
|
|
if (ImGui.TableSetColumnIndex(0)) {
|
|
|
|
for (var i = 0; i < this.Tabs.Count; i++) {
|
|
|
|
var (name, _) = this.Tabs[i];
|
|
|
|
if (ImGui.Selectable($"{name}##tab-{i}", i == this._tab)) {
|
|
|
|
this._tab = i;
|
|
|
|
}
|
|
|
|
}
|
2022-09-07 17:25:05 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 17:42:43 +00:00
|
|
|
if (ImGui.TableSetColumnIndex(1)) {
|
2022-09-07 17:49:14 +00:00
|
|
|
if (ImGui.BeginChild("##tab-content-child", new Vector2(-1, childHeight))) {
|
2022-09-07 17:42:43 +00:00
|
|
|
var (_, draw) = this.Tabs[this._tab];
|
|
|
|
draw(ref anyChanged, ref vfx);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui.EndChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui.EndTable();
|
2022-09-07 17:25:05 +00:00
|
|
|
}
|
|
|
|
|
2022-09-05 08:02:34 +00:00
|
|
|
if (anyChanged) {
|
|
|
|
this.Plugin.SaveConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vfx) {
|
|
|
|
this.Plugin.Messages.RemoveVfx();
|
|
|
|
this.Plugin.Messages.Clear();
|
2022-09-05 10:38:00 +00:00
|
|
|
this.Plugin.Messages.SpawnVfx();
|
2022-09-05 08:02:34 +00:00
|
|
|
}
|
2022-09-05 08:21:45 +00:00
|
|
|
|
2022-09-07 17:42:43 +00:00
|
|
|
ImGui.PopTextWrapPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DrawGeneral(ref bool anyChanged, ref bool vfx) {
|
|
|
|
anyChanged |= vfx |= ImGui.Checkbox("Disable in trials", ref this.Plugin.Config.DisableTrials);
|
|
|
|
anyChanged |= vfx |= ImGui.Checkbox("Disable in Deep Dungeons", ref this.Plugin.Config.DisableDeepDungeon);
|
|
|
|
anyChanged |= vfx |= ImGui.Checkbox("Remove glow effect from signs", ref this.Plugin.Config.RemoveGlow);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DrawWriter(ref bool anyChanged, ref bool vfx) {
|
|
|
|
var glyph = this.Plugin.Config.DefaultGlyph + 1;
|
|
|
|
if (ImGui.InputInt("Default glyph", ref glyph)) {
|
|
|
|
this.Plugin.Config.DefaultGlyph = Math.Min(4, Math.Max(0, glyph - 1));
|
|
|
|
anyChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DrawViewer(ref bool anyChanged, ref bool vfx) {
|
|
|
|
anyChanged |= ImGui.SliderFloat("Viewer opacity", ref this.Plugin.Config.ViewerOpacity, 0f, 100.0f, $"{this.Plugin.Config.ViewerOpacity:N3}%%");
|
|
|
|
anyChanged |= ImGui.Checkbox("Open the viewer automatically when near a sign", ref this.Plugin.Config.AutoViewer);
|
|
|
|
anyChanged |= ImGui.Checkbox("Close the viewer automatically when no signs are nearby", ref this.Plugin.Config.AutoViewerClose);
|
|
|
|
|
|
|
|
if (this.Plugin.Config.AutoViewerClose) {
|
|
|
|
ImGui.TreePush();
|
|
|
|
anyChanged |= ImGui.Checkbox("Hide viewer titlebar", ref this.Plugin.Config.HideTitlebar);
|
|
|
|
ImGui.TreePop();
|
|
|
|
}
|
|
|
|
|
|
|
|
anyChanged |= ImGui.Checkbox("Lock viewer in place", ref this.Plugin.Config.LockViewer);
|
|
|
|
anyChanged |= ImGui.Checkbox("Click through viewer", ref this.Plugin.Config.ClickThroughViewer);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DrawUnlocks(ref bool anyChanged, ref bool vfx) {
|
2022-09-05 08:21:45 +00:00
|
|
|
this.ExtraCodeInput();
|
2022-09-07 17:42:43 +00:00
|
|
|
}
|
2022-09-05 09:05:14 +00:00
|
|
|
|
2022-09-07 17:42:43 +00:00
|
|
|
private void DrawAccount(ref bool anyChanged, ref bool vfx) {
|
|
|
|
this.DeleteAccountButton();
|
2022-09-05 08:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2022-09-05 08:35:28 +00:00
|
|
|
this.Plugin.Ui.ShowModal($"Code claimed.\n\nYou can now post up to {10 + extra:N0} messages.");
|
2022-09-05 08:21:45 +00:00
|
|
|
} else {
|
2022-09-05 08:35:28 +00:00
|
|
|
this.Plugin.Ui.ShowModal("Code claimed but the server gave an unexpected response.");
|
2022-09-05 08:21:45 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-09-05 08:35:28 +00:00
|
|
|
this.Plugin.Ui.ShowModal("Invalid code.");
|
2022-09-05 08:21:45 +00:00
|
|
|
}
|
|
|
|
});
|
2022-09-05 08:02:34 +00:00
|
|
|
}
|
2022-09-07 06:18:12 +00:00
|
|
|
|
|
|
|
private void DeleteAccountButton() {
|
|
|
|
var ctrl = ImGui.GetIO().KeyCtrl;
|
|
|
|
if (!ctrl) {
|
|
|
|
ImGui.BeginDisabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui.Button("Delete account")) {
|
|
|
|
Task.Run(async () => {
|
|
|
|
var resp = await ServerHelper.SendRequest(
|
|
|
|
this.Plugin.Config.ApiKey,
|
|
|
|
HttpMethod.Delete,
|
|
|
|
"/account"
|
|
|
|
);
|
|
|
|
|
|
|
|
if (resp.IsSuccessStatusCode) {
|
|
|
|
this.Plugin.Config.ApiKey = string.Empty;
|
|
|
|
this.Plugin.SaveConfig();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ctrl) {
|
|
|
|
ImGui.EndDisabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui.SameLine();
|
|
|
|
ImGuiExt.HelpIcon("Hold Ctrl to enable delete button.");
|
|
|
|
|
|
|
|
ImGui.TextUnformatted("This will delete all your messages and votes.");
|
|
|
|
}
|
2022-09-05 08:02:34 +00:00
|
|
|
}
|