2020-07-29 16:01:00 +00:00
|
|
|
|
using Dalamud.Plugin;
|
2020-07-30 02:42:57 +00:00
|
|
|
|
using System;
|
2020-07-29 16:01:00 +00:00
|
|
|
|
|
|
|
|
|
namespace HudSwap {
|
|
|
|
|
public class HudSwapPlugin : IDalamudPlugin {
|
|
|
|
|
public string Name => "HudSwap";
|
|
|
|
|
|
|
|
|
|
private DalamudPluginInterface pi;
|
|
|
|
|
private PluginUI ui;
|
2020-07-31 17:58:56 +00:00
|
|
|
|
public HUD Hud { get; private set; }
|
|
|
|
|
public PluginConfig Config { get; private set; }
|
2020-07-29 16:01:00 +00:00
|
|
|
|
|
2020-07-31 17:58:56 +00:00
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "nah")]
|
2020-07-29 16:01:00 +00:00
|
|
|
|
public void Initialize(DalamudPluginInterface pluginInterface) {
|
2020-07-31 17:58:56 +00:00
|
|
|
|
this.pi = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface cannot be null");
|
2020-07-30 02:42:57 +00:00
|
|
|
|
try {
|
2020-07-31 17:58:56 +00:00
|
|
|
|
this.Config = this.pi.GetPluginConfig() as PluginConfig ?? new PluginConfig();
|
2020-07-30 02:42:57 +00:00
|
|
|
|
} catch (Exception) {
|
|
|
|
|
this.pi.UiBuilder.OnBuildUi += PluginUI.ConfigError;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-07-31 17:58:56 +00:00
|
|
|
|
this.Config.Initialize(this.pi);
|
2020-07-29 16:01:00 +00:00
|
|
|
|
|
|
|
|
|
this.ui = new PluginUI(this, this.pi);
|
2020-07-31 17:58:56 +00:00
|
|
|
|
this.Hud = new HUD(this.pi);
|
2020-07-29 16:01:00 +00:00
|
|
|
|
|
2020-07-31 17:58:56 +00:00
|
|
|
|
if (this.Config.FirstRun) {
|
|
|
|
|
this.Config.FirstRun = false;
|
|
|
|
|
if (this.Config.Layouts.Count == 0) {
|
2020-07-30 17:53:13 +00:00
|
|
|
|
foreach (HudSlot slot in Enum.GetValues(typeof(HudSlot))) {
|
|
|
|
|
this.ui.ImportSlot(slot, $"Auto-import {(int)slot + 1}", false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-31 17:58:56 +00:00
|
|
|
|
this.Config.Save();
|
2020-07-30 17:53:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-29 16:01:00 +00:00
|
|
|
|
this.pi.UiBuilder.OnBuildUi += this.ui.Draw;
|
|
|
|
|
this.pi.UiBuilder.OnOpenConfigUi += this.ui.ConfigUI;
|
|
|
|
|
|
|
|
|
|
this.pi.CommandManager.AddHandler("/phudswap", new Dalamud.Game.Command.CommandInfo(OnCommand) {
|
|
|
|
|
HelpMessage = "Open the HudSwap settings"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 17:58:56 +00:00
|
|
|
|
protected virtual void Dispose(bool all) {
|
2020-07-29 16:01:00 +00:00
|
|
|
|
this.pi.UiBuilder.OnBuildUi -= this.ui.Draw;
|
|
|
|
|
this.pi.UiBuilder.OnOpenConfigUi -= this.ui.ConfigUI;
|
|
|
|
|
this.pi.CommandManager.RemoveHandler("/phudswap");
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 17:58:56 +00:00
|
|
|
|
public void Dispose() {
|
|
|
|
|
this.Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-29 16:01:00 +00:00
|
|
|
|
private void OnCommand(string command, string args) {
|
|
|
|
|
this.ui.SettingsVisible = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|