HUDManager/HudSwap/Plugin.cs

55 lines
1.8 KiB
C#
Raw Normal View History

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;
public HUD hud;
public Configuration config;
public void Initialize(DalamudPluginInterface pluginInterface) {
this.pi = pluginInterface;
2020-07-30 02:42:57 +00:00
try {
this.config = this.pi.GetPluginConfig() as Configuration ?? new Configuration();
} catch (Exception) {
this.pi.UiBuilder.OnBuildUi += PluginUI.ConfigError;
return;
}
2020-07-29 16:01:00 +00:00
this.config.Initialize(this.pi);
this.ui = new PluginUI(this, this.pi);
this.hud = new HUD(this.pi);
if (this.config.FirstRun) {
this.config.FirstRun = false;
if (this.config.Layouts.Count == 0) {
foreach (HudSlot slot in Enum.GetValues(typeof(HudSlot))) {
this.ui.ImportSlot(slot, $"Auto-import {(int)slot + 1}", false);
}
}
this.config.Save();
}
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"
});
}
public void Dispose() {
this.pi.UiBuilder.OnBuildUi -= this.ui.Draw;
this.pi.UiBuilder.OnOpenConfigUi -= this.ui.ConfigUI;
this.pi.CommandManager.RemoveHandler("/phudswap");
}
private void OnCommand(string command, string args) {
this.ui.SettingsVisible = true;
}
}
}