Skip to content

Commit

Permalink
add tracker configs to settings window (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
dit-zy authored Aug 11, 2024
1 parent 44fb5b0 commit 01731d5
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 45 deletions.
50 changes: 25 additions & 25 deletions ScoutHelper/Config/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ public class Configuration : IPluginConfiguration {

public int Version { get; set; } = 0;

public string BearApiBaseUrl { get; set; } = "https://tracker.beartoolkit.com/api/";
public string BearApiTrainPath { get; set; } = "hunttrain";
public TimeSpan BearApiTimeout { get; set; } = TimeSpan.FromSeconds(5);
public string BearSiteTrainUrl { get; set; } = "https://tracker.beartoolkit.com/train";
public string BearTrainName { get; set; } = "Scout Helper Train";
public string BearApiBaseUrl = "https://tracker.beartoolkit.com/api/";
public string BearApiTrainPath = "hunttrain";
public TimeSpan BearApiTimeout = TimeSpan.FromSeconds(5);
public string BearSiteTrainUrl = "https://tracker.beartoolkit.com/train";
public string BearTrainName = "Scout Helper Train";

public string SirenBaseUrl { get; set; } = "https://sirenhunts.com/scouting/";
public string SirenBaseUrl = "https://sirenhunts.com/scouting/";

public string TurtleBaseUrl { get; set; } = "https://scout.wobbuffet.net";
public string TurtleTrainPath { get; set; } = "/scout";
public string TurtleApiBaseUrl { get; set; } = "https://scout.wobbuffet.net";
public string TurtleApiTrainPath { get; set; } = "/api/v1/scout";
public TimeSpan TurtleApiTimeout { get; set; } = TimeSpan.FromSeconds(5);
public string TurtleBaseUrl = "https://scout.wobbuffet.net";
public string TurtleTrainPath = "/scout";
public string TurtleApiBaseUrl = "https://scout.wobbuffet.net";
public string TurtleApiTrainPath = "/api/v1/scout";
public TimeSpan TurtleApiTimeout = TimeSpan.FromSeconds(5);

public string CopyTemplate { get; set; } = Constants.DefaultCopyTemplate;
public bool IsCopyModeFullText { get; set; } = false;
public string CopyTemplate = Constants.DefaultCopyTemplate;
public bool IsCopyModeFullText = false;

[NotManaged] public DateTime LastPluginUpdate { get; set; } = DateTime.UnixEpoch;
[NotManaged] public DateTime LastNoticeAcknowledged { get; set; } = DateTime.UnixEpoch;
[NotManaged] public DateTime LastPluginUpdate = DateTime.UnixEpoch;
[NotManaged] public DateTime LastNoticeAcknowledged = DateTime.UnixEpoch;

[NotManaged]
[Obsolete("field no longer needed, but must remain for backwards compatibility")]
public DateTime LastInstancePatchUpdate { get; set; } = DateTime.UnixEpoch;
public DateTime LastInstancePatchUpdate = DateTime.UnixEpoch;

[NotManaged] public Dictionary<uint, uint> Instances { get; set; } = new();
[NotManaged] public (Territory, uint)[] LatestPatchInstances { get; set; } = Constants.LatestPatchInstances;
[NotManaged] public Dictionary<uint, uint> Instances = new();
[NotManaged] public (Territory, uint)[] LatestPatchInstances = Constants.LatestPatchInstances;

[NotManaged] public Dictionary<string, string?> ConfigDefaults { get; set; } = new();
[NotManaged] public Dictionary<string, string?> ConfigDefaults = new();

public void Initialize(IPluginLog log, IDalamudPluginInterface pluginInterface) {
_pluginInterface = pluginInterface;
Expand All @@ -56,13 +56,13 @@ private void ManageDefaults(IPluginLog log) {
var defaultConf = new Configuration();

typeof(Configuration)
.GetProperties()
.Where(propInfo => propInfo.CustomAttributes.All(attrData => attrData.AttributeType != typeof(NotManaged)))
.GetFields()
.Where(info => info.CustomAttributes.All(attrData => attrData.AttributeType != typeof(NotManaged)))
.ForEach(
propInfo => {
var currentDefault = propInfo.GetValue(defaultConf);
info => {
var currentDefault = info.GetValue(defaultConf);
var currentDefaultStr = currentDefault?.ToString();
var propName = propInfo.Name;
var propName = info.Name;
if (ConfigDefaults.TryGetValue(propName, out var prevDefault)
&& ActualValuesEqualBecauseMicrosoftHasBrainDamage(prevDefault, currentDefaultStr)
Expand All @@ -73,7 +73,7 @@ private void ManageDefaults(IPluginLog log) {
log.Debug("updating config [{0:l}] to the new default.", propName);
ConfigDefaults[propName] = currentDefaultStr;
propInfo.SetValue(this, currentDefault);
info.SetValue(this, currentDefault);
}
);

Expand Down
9 changes: 0 additions & 9 deletions ScoutHelper/Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,13 @@
using System.Text;
using System.Text.RegularExpressions;
using CSharpFunctionalExtensions;
using ImGuiNET;
using Lumina.Text;
using Newtonsoft.Json;
using ScoutHelper.Models;

namespace ScoutHelper.Utils;

public static partial class Utils {
public static void CreateTooltip(string text, float width = 12f) {
ImGui.BeginTooltip();
ImGui.PushTextWrapPos(ImGui.GetFontSize() * width);
ImGui.TextUnformatted(text);
ImGui.PopTextWrapPos();
ImGui.EndTooltip();
}

public static Vector2 V2(float x) => new(x, x);

public static Vector2 V2(float x, float y) => new(x, y);
Expand Down
74 changes: 71 additions & 3 deletions ScoutHelper/Windows/ConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using CSharpFunctionalExtensions;
using Dalamud.Interface;
using Dalamud.Interface.Components;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services;
Expand All @@ -29,6 +31,7 @@ public class ConfigWindow : Window, IDisposable {
.ToImmutableList();

private static readonly uint InputScalarStep = 1U;
private static readonly Configuration DefaultConf = new();

private readonly IClientState _clientState;
private readonly IPluginLog _log;
Expand Down Expand Up @@ -109,14 +112,79 @@ private void DrawTemplateTab() {
}

private void DrawTweaksTab() {
DrawTweaksTrackerConfigs();
ImGuiPlus.Separator();
DrawTweaksInstances();
}

private void DrawTweaksTrackerConfigs() {
ImGuiPlus.Heading("TRACKERS");
DrawParagraphSpacing();

ImGui.TextWrapped("reconfigure various internal values associated with the different trackers.");
DrawParagraphSpacing();
ImGui.TextWrapped(
"NOTE: when scout helper updates one of these values in a new version, those new values will override any customizations you have here."
);
DrawParagraphSpacing();

if (ImGui.Button("RESET ALL")) {
_conf.BearApiBaseUrl = DefaultConf.BearApiBaseUrl;
_conf.BearApiTrainPath = DefaultConf.BearApiTrainPath;
_conf.BearSiteTrainUrl = DefaultConf.BearSiteTrainUrl;
_conf.BearTrainName = DefaultConf.BearTrainName;
_conf.SirenBaseUrl = DefaultConf.SirenBaseUrl;
_conf.TurtleApiBaseUrl = DefaultConf.TurtleApiBaseUrl;
_conf.TurtleApiTrainPath = DefaultConf.TurtleApiTrainPath;
_conf.TurtleBaseUrl = DefaultConf.TurtleBaseUrl;
_conf.TurtleTrainPath = DefaultConf.TurtleTrainPath;
}
if (ImGui.IsItemHovered()) ImGuiPlus.CreateTooltip("reset all tracker configs to their defaults.");

if (ImGui.TreeNode("BEAR")) {
DrawConfigTextInput(nameof(Configuration.BearApiBaseUrl), ref _conf.BearApiBaseUrl);
DrawConfigTextInput(nameof(Configuration.BearApiTrainPath), ref _conf.BearApiTrainPath);
DrawConfigTextInput(nameof(Configuration.BearSiteTrainUrl), ref _conf.BearSiteTrainUrl);
DrawConfigTextInput(nameof(Configuration.BearTrainName), ref _conf.BearTrainName);
ImGui.TreePop();
}

if (ImGui.TreeNode("SIREN")) {
DrawConfigTextInput(nameof(Configuration.SirenBaseUrl), ref _conf.SirenBaseUrl);
ImGui.TreePop();
}

if (ImGui.TreeNode("TURTLE")) {
DrawConfigTextInput(nameof(Configuration.TurtleApiBaseUrl), ref _conf.TurtleApiBaseUrl);
DrawConfigTextInput(nameof(Configuration.TurtleApiTrainPath), ref _conf.TurtleApiTrainPath);
DrawConfigTextInput(nameof(Configuration.TurtleBaseUrl), ref _conf.TurtleBaseUrl);
DrawConfigTextInput(nameof(Configuration.TurtleTrainPath), ref _conf.TurtleTrainPath);
ImGui.TreePop();
}
}

private static void DrawConfigTextInput(string configName, ref string configRef) {
var defaultValue = (string)typeof(Configuration).GetField(configName)!.GetValue(DefaultConf)!;
ImGui.BeginDisabled(defaultValue == configRef);
if (ImGuiComponents.IconButton(FontAwesomeIcon.Undo)) {
configRef = defaultValue;
}
ImGui.EndDisabled();
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
ImGuiPlus.CreateTooltip($"reset to default:\n{defaultValue}", 20);
ImGui.SameLine();
ImGui.InputText(configName, ref configRef, 256);
}

private void DrawTweaksInstances() {
ImGuiPlus.Heading(Strings.ConfigWindowTweaksSectionLabelInstances);
DrawParagraphSpacing();

ImGui.TextWrapped(Strings.ConfigWindowTweaksInstanceDescription);
DrawParagraphSpacing();
ImGui.TextWrapped(Strings.ConfigWindowTweaksInstanceDescriptionNote);
DrawParagraphSpacing();

if (ImGui.Button(Strings.ConfigWindowTweaksInstanceResetButton)) {
GetEnumValues<Territory>()
.SelectResults(
Expand All @@ -129,7 +197,7 @@ private void DrawTweaksTab() {
.UseToUpdate(_conf.Instances);
}
if (ImGui.IsItemHovered()) {
CreateTooltip(Strings.ConfigWindowTweaksInstanceResetTooltip);
ImGuiPlus.CreateTooltip(Strings.ConfigWindowTweaksInstanceResetTooltip);
}

var textSize = ImGui.CalcTextSize("8 ");
Expand Down Expand Up @@ -186,7 +254,7 @@ private void DrawTextInput() {
UpdateConfig();
}
if (ImGui.IsItemHovered()) {
CreateTooltip($"{Strings.ConfigWindowTemplateResetTooltip}:\n {Constants.DefaultCopyTemplate}");
ImGuiPlus.CreateTooltip($"{Strings.ConfigWindowTemplateResetTooltip}:\n {Constants.DefaultCopyTemplate}");
}
}

Expand Down
8 changes: 8 additions & 0 deletions ScoutHelper/Windows/ImGuiPlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ public static void Separator() {
ImGui.Dummy(dummySize);
}

public static void CreateTooltip(string text, float width = 12f) {
ImGui.BeginTooltip();
ImGui.PushTextWrapPos(ImGui.GetFontSize() * width);
ImGui.TextUnformatted(text);
ImGui.PopTextWrapPos();
ImGui.EndTooltip();
}

public static void Heading(string text, float scale = 1.25f, bool centered = false) {
var font = ImGui.GetFont();
var originalScale = font.Scale;
Expand Down
31 changes: 23 additions & 8 deletions ScoutHelper/Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Numerics;
using System.Threading.Tasks;
using CSharpFunctionalExtensions;
using Dalamud.Interface;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services;
Expand Down Expand Up @@ -95,6 +96,14 @@ ConfigWindow configWindow
MinimumSize = new Vector2(64, 32),
MaximumSize = new Vector2(float.MaxValue, float.MaxValue),
};
TitleBarButtons.Add(
new TitleBarButton() {
Click = _ => _configWindow.IsOpen = true,
Icon = FontAwesomeIcon.Cog,
IconOffset = V2(2, 1),
ShowTooltip = () => ImGuiPlus.CreateTooltip("open the scout helper settings window"),
}
);

_buttonSize = new Lazy<Vector2>(
() => {
Expand Down Expand Up @@ -234,7 +243,7 @@ private unsafe void DrawNotices() {
ImGuiPlus.WithStyle(ImGuiCol.Text, textColor).Do(
() => {
if (ImGui.IsItemHovered()) {
CreateTooltip(Strings.MainWindowNoticesAckTooltip);
ImGuiPlus.CreateTooltip(Strings.MainWindowNoticesAckTooltip);
_noticeAckButtonColor = DangerBgColor;
} else {
_noticeAckButtonColor = DangerFgColor;
Expand All @@ -253,7 +262,9 @@ private void DrawModeButtons() {
ImGuiHelpers.CenteredText(Strings.MainWindowSectionLabelMode);

ImGui.SameLine();
if (ImGuiPlus.ClickableHelpMarker(DrawModeTooltipContents)) _configWindow.IsOpen = true;
if (ImGuiPlus.ClickableHelpMarker(DrawModeTooltipContents)) {
_configWindow.IsOpen = true;
}

var modes = new[] { Strings.CopyModeLinkButton, Strings.CopyModeFullTextButton };
if (ImGuiPlus.ToggleBar("mode", ref _selectedMode, _buttonSize.Value, modes))
Expand Down Expand Up @@ -292,7 +303,7 @@ private void DrawGeneratorButtons() {
}
);
}
if (ImGui.IsItemHovered()) CreateTooltip(Strings.BearButtonTooltip);
if (ImGui.IsItemHovered()) ImGuiPlus.CreateTooltip(Strings.BearButtonTooltip);

if (ImGui.Button(Strings.SirenButton, _buttonSize.Value)) {
_chat.TaggedPrint("Generating Siren link...");
Expand All @@ -306,7 +317,7 @@ private void DrawGeneratorButtons() {
}
);
}
if (ImGui.IsItemHovered()) CreateTooltip(Strings.SirenButtonTooltip);
if (ImGui.IsItemHovered()) ImGuiPlus.CreateTooltip(Strings.SirenButtonTooltip);

DrawTurtleButtons();
if (ImGui.BeginPopup("turtle collab popup")) {
Expand Down Expand Up @@ -336,7 +347,9 @@ private unsafe void DrawTurtleButtons() {
ImDrawFlags.RoundCornersLeft
);
if (ImGui.IsItemHovered())
CreateTooltip(_isTurtleCollabbing ? Strings.TurtleButtonActiveCollabTooltip : Strings.TurtleButtonTooltip);
ImGuiPlus.CreateTooltip(
_isTurtleCollabbing ? Strings.TurtleButtonActiveCollabTooltip : Strings.TurtleButtonTooltip
);
if (turtlePressed) {
if (_isTurtleCollabbing) {
PushLatestMobsToTurtle();
Expand Down Expand Up @@ -369,7 +382,9 @@ private unsafe void DrawTurtleButtons() {
)
);
if (ImGui.IsItemHovered())
CreateTooltip(_isTurtleCollabbing ? Strings.TurtleCollabButtonActiveTooltip : Strings.TurtleCollabButtonTooltip);
ImGuiPlus.CreateTooltip(
_isTurtleCollabbing ? Strings.TurtleCollabButtonActiveTooltip : Strings.TurtleCollabButtonTooltip
);
if (turtleCollabPressed) {
if (_isTurtleCollabbing) _isTurtleCollabbing = false;
else {
Expand Down Expand Up @@ -398,7 +413,7 @@ private void DrawTurtleCollabPopup() {
);
}
if (ImGui.IsItemHovered())
CreateTooltip(
ImGuiPlus.CreateTooltip(
"generate a link to a new session, and immediately join it so you can start contributing. share the link with other scouters so they can also contribute :3"
);

Expand All @@ -414,7 +429,7 @@ private void DrawTurtleCollabPopup() {
ImGuiInputTextFlags.AutoSelectAll | ImGuiInputTextFlags.EnterReturnsTrue
);
if (ImGui.IsItemHovered())
CreateTooltip("paste a collaborator link here and join the session to start contributing marks.");
ImGuiPlus.CreateTooltip("paste a collaborator link here and join the session to start contributing marks.");
ImGui.SameLine();
linkInputted = linkInputted || ImGui.Button("JOIN");
if (linkInputted) {
Expand Down

0 comments on commit 01731d5

Please sign in to comment.