Skip to content

Commit

Permalink
Add DTR bar entry by Nopileos2
Browse files Browse the repository at this point in the history
  • Loading branch information
PrincessRTFM authored Jan 14, 2024
2 parents af91ea2 + 7bc6275 commit aadbb97
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions PositionalGuide/ConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class ConfigWindow: Window, IDisposable {
private bool disposed;

private readonly Configuration conf;
public delegate void SettingsUpdate();
public event SettingsUpdate? OnSettingsUpdate;

public ConfigWindow(Plugin core) : base(core.Name, flags) {
this.RespectCloseHotkey = true;
Expand Down Expand Up @@ -313,6 +315,7 @@ public override void Draw() {
this.conf.DrawGuides = drawing;
this.conf.LineColours = colours;
Plugin.Interface.SavePluginConfig(this.conf);
this.OnSettingsUpdate?.Invoke();
}

for (int i = 0; i < ptrs.Length; ++i)
Expand Down
24 changes: 23 additions & 1 deletion PositionalGuide/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace PrincessRTFM.PositionalGuide;
using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Game.Gui.Dtr;
using Dalamud.Interface.Internal.Notifications;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing;
Expand All @@ -29,6 +30,7 @@ private enum CircleTypes { Target, Outer };
private bool disposed;

public string Name { get; } = "Positional Assistant";
public const string DTRDisplayName = "Guidelines";

[PluginService] public static IGameGui Gui { get; private set; } = null!;
[PluginService] public static IChatGui Chat { get; private set; } = null!;
Expand All @@ -42,24 +44,41 @@ private enum CircleTypes { Target, Outer };

private readonly WindowSystem windowSystem;
private readonly ConfigWindow configWindow;
private readonly DtrBarEntry dtrEntry;

public Plugin() {
public Plugin(IDtrBar dtrBar) {
this.Config = Interface.GetPluginConfig() as Configuration ?? new();
this.Config.Update();

this.configWindow = new(this);
this.configWindow.OnSettingsUpdate += this.settingsUpdated;
this.windowSystem = new(this.GetType().Namespace!);
this.windowSystem.AddWindow(this.configWindow);

Commands.AddHandler(Command, new(this.onPluginCommand) {
HelpMessage = $"Open {this.Name}'s config window",
ShowInHelp = true,
});

this.dtrEntry = dtrBar.Get(this.Name);
this.setDtrText();
this.dtrEntry.OnClick = this.dtrClickHandler;

Interface.UiBuilder.OpenConfigUi += this.toggleConfigUi;
Interface.UiBuilder.Draw += this.draw;
}

private void settingsUpdated() {
this.setDtrText();
}

private void dtrClickHandler() {
this.Config.Enabled = !this.Config.Enabled;
this.setDtrText();
}

private void setDtrText() => this.dtrEntry.Text = $"{DTRDisplayName}: {(this.Config.Enabled ? "On" : "Off")}";

internal void draw() {
this.windowSystem.Draw();

Expand Down Expand Up @@ -438,6 +457,7 @@ internal void onPluginCommand(string command, string arguments) {
return;
}

this.settingsUpdated();
Interface.SavePluginConfig(this.Config);
}

Expand All @@ -459,10 +479,12 @@ protected virtual void Dispose(bool disposing) {
if (disposing) {
Interface.UiBuilder.OpenConfigUi -= this.toggleConfigUi;
Interface.UiBuilder.Draw -= this.draw;
this.configWindow.OnSettingsUpdate -= this.settingsUpdated;

Commands.RemoveHandler(Command);

this.configWindow.Dispose();
this.dtrEntry.Remove();
}
}

Expand Down
2 changes: 1 addition & 1 deletion PositionalGuide/PositionalGuide.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Product>PositionalGuide</Product>
<Version>4.2.0</Version>
<Version>4.3.0</Version>
<Description>Provides drawn guidelines to see where you need to stand to hit enemies with positionals</Description>
<Copyright>Copyleft VariableVixen 2022</Copyright>
<PackageProjectUrl>https://github.com/PrincessRTFM/PositionalAssistant</PackageProjectUrl>
Expand Down

0 comments on commit aadbb97

Please sign in to comment.