Skip to content

Commit

Permalink
Make the bar toggleable
Browse files Browse the repository at this point in the history
  • Loading branch information
s5bug committed Nov 17, 2023
1 parent f93ac7a commit 1c183fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
27 changes: 20 additions & 7 deletions AutoTimer/AutoTimerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace AutoTimer;

public sealed partial class AutoTimerPlugin : IDalamudPlugin {
public string Name => "Auto Timer";
private const string CommandName = "/autotimer";
private const string ToggleTimerCommand = "/autotimer";
private const string ConfigTimerCommand = "/autotimerconfig";

private DalamudPluginInterface PluginInterface { get; init; }
private ICommandManager CommandManager { get; init; }
Expand Down Expand Up @@ -65,14 +66,17 @@ public AutoTimerPlugin(
WindowSystem.AddWindow(ConfigWindow);
WindowSystem.AddWindow(MainWindow);

this.CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand) {
HelpMessage = "A useful message to display in /xlhelp"
this.CommandManager.AddHandler(ToggleTimerCommand, new CommandInfo(this.OnCommand) {
HelpMessage = "Toggles the autotimer bar"
});
this.CommandManager.AddHandler(ConfigTimerCommand, new CommandInfo(this.OnCommand) {
HelpMessage = "Toggles the autotimer configuration window"
});

this.PluginInterface.UiBuilder.Draw += DrawUI;
this.PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI;

this.MainWindow.IsOpen = true;
this.MainWindow.IsOpen = this.Configuration.BarOpen;
}

public void Dispose() {
Expand All @@ -82,12 +86,21 @@ public void Dispose() {
MainWindow.Dispose();
this.Hooks.Dispose();

this.CommandManager.RemoveHandler(CommandName);
this.CommandManager.RemoveHandler(ToggleTimerCommand);
}

private void OnCommand(string command, string args) {
// in response to the slash command, just display our main ui
MainWindow.IsOpen = true;
switch (command) {
case "/autotimer":
this.MainWindow.IsOpen = !this.MainWindow.IsOpen;
this.Configuration.BarOpen = this.MainWindow.IsOpen;
this.Configuration.Save();
break;
case "/autotimerconfig":
this.ConfigWindow.IsOpen = true;
this.ConfigWindow.BringToFront();
break;
}
}

private void DrawUI() {
Expand Down
1 change: 1 addition & 0 deletions AutoTimer/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Configuration : IPluginConfiguration {

public bool UseMonkGauge { get; set; } = true;
public bool LockBar { get; set; } = true;
public bool BarOpen { get; set; } = false;

// the below exist just to make saving less cumbersome
[NonSerialized]
Expand Down

0 comments on commit 1c183fc

Please sign in to comment.