This commit is contained in:
Anna 2022-09-07 13:42:43 -04:00
parent 08c1752182
commit dfb50aae2d
1 changed files with 75 additions and 21 deletions

View File

@ -7,10 +7,23 @@ internal class Settings : ITab {
public string Name => "Settings";
private Plugin Plugin { get; }
private int _tab = 0;
private string _extraCode = string.Empty;
private delegate void DrawSettingsDelegate(ref bool anyChanged, ref bool vfx);
private IReadOnlyList<(string, DrawSettingsDelegate)> Tabs { get; }
internal Settings(Plugin plugin) {
this.Plugin = plugin;
this.Tabs = new List<(string, DrawSettingsDelegate)> {
("General", this.DrawGeneral),
("Writer", this.DrawWriter),
("Viewer", this.DrawViewer),
("Unlocks", this.DrawUnlocks),
("Account", this.DrawAccount),
};
}
public void Dispose() {
@ -22,29 +35,36 @@ internal class Settings : ITab {
var anyChanged = false;
var vfx = false;
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);
var widestTabName = this.Tabs
.Select(entry => ImGui.CalcTextSize(entry.Item1).X)
.Max();
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;
}
var leftOver = ImGui.GetContentRegionAvail().X - widestTabName - ImGui.GetStyle().ItemSpacing.X - ImGui.GetStyle().FrameBorderSize;
if (ImGui.BeginTable("##settings-tabs", 2)) {
ImGui.TableSetupColumn("##names", ImGuiTableColumnFlags.None, widestTabName + ImGui.GetStyle().ItemSpacing.X);
ImGui.TableSetupColumn("##content", ImGuiTableColumnFlags.None, leftOver);
if (ImGui.CollapsingHeader("Viewer settings")) {
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);
ImGui.TableNextRow();
if (this.Plugin.Config.AutoViewerClose) {
ImGui.TreePush();
anyChanged |= ImGui.Checkbox("Hide viewer titlebar", ref this.Plugin.Config.HideTitlebar);
ImGui.TreePop();
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;
}
}
}
anyChanged |= ImGui.Checkbox("Lock viewer in place", ref this.Plugin.Config.LockViewer);
anyChanged |= ImGui.Checkbox("Click through viewer", ref this.Plugin.Config.ClickThroughViewer);
if (ImGui.TableSetColumnIndex(1)) {
if (ImGui.BeginChild("##tab-content-child")) {
var (_, draw) = this.Tabs[this._tab];
draw(ref anyChanged, ref vfx);
}
ImGui.EndChild();
}
ImGui.EndTable();
}
if (anyChanged) {
@ -57,12 +77,46 @@ internal class Settings : ITab {
this.Plugin.Messages.SpawnVfx();
}
this.ExtraCodeInput();
this.DeleteAccountButton();
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) {
this.ExtraCodeInput();
}
private void DrawAccount(ref bool anyChanged, ref bool vfx) {
this.DeleteAccountButton();
}
private void ExtraCodeInput() {
ImGui.InputText("Extra code", ref this._extraCode, 128);
if (!ImGui.Button("Claim")) {