2020-08-04 02:13:29 +00:00
|
|
|
|
using Dalamud.Game.Command;
|
|
|
|
|
using Dalamud.Plugin;
|
2020-07-30 02:42:57 +00:00
|
|
|
|
using System;
|
2020-08-04 02:13:29 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
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-08-06 16:04:47 +00:00
|
|
|
|
private Swapper swapper;
|
|
|
|
|
|
2020-07-31 17:58:56 +00:00
|
|
|
|
public HUD Hud { get; private set; }
|
2020-08-06 16:04:47 +00:00
|
|
|
|
public Statuses Statuses { get; private set; }
|
2020-08-04 02:13:29 +00:00
|
|
|
|
public GameFunctions GameFunctions { get; private set; }
|
2020-07-31 17:58:56 +00:00
|
|
|
|
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-08-06 16:04:47 +00:00
|
|
|
|
this.Statuses = new Statuses(this, this.pi);
|
2020-08-04 02:13:29 +00:00
|
|
|
|
this.GameFunctions = new GameFunctions(this.pi);
|
2020-07-29 16:01:00 +00:00
|
|
|
|
|
2020-08-06 16:04:47 +00:00
|
|
|
|
this.swapper = new Swapper(this, this.pi);
|
|
|
|
|
|
2020-07-31 17:58:56 +00:00
|
|
|
|
if (this.Config.FirstRun) {
|
|
|
|
|
this.Config.FirstRun = false;
|
2020-08-04 02:13:29 +00:00
|
|
|
|
if (this.Config.Layouts2.Count == 0) {
|
2020-07-30 17:53:13 +00:00
|
|
|
|
foreach (HudSlot slot in Enum.GetValues(typeof(HudSlot))) {
|
2020-08-04 02:13:29 +00:00
|
|
|
|
this.ui.ImportSlot($"Auto-import {(int)slot + 1}", slot, false);
|
2020-07-30 17:53:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
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;
|
2020-08-06 16:04:47 +00:00
|
|
|
|
this.pi.Framework.OnUpdateEvent += this.swapper.OnFrameworkUpdate;
|
2020-07-29 16:01:00 +00:00
|
|
|
|
|
2020-08-04 02:13:29 +00:00
|
|
|
|
this.pi.CommandManager.AddHandler("/phudswap", new CommandInfo(OnSettingsCommand) {
|
2020-07-29 16:01:00 +00:00
|
|
|
|
HelpMessage = "Open the HudSwap settings"
|
|
|
|
|
});
|
2020-08-04 02:13:29 +00:00
|
|
|
|
this.pi.CommandManager.AddHandler("/phud", new CommandInfo(OnSwapCommand) {
|
|
|
|
|
HelpMessage = "/phud <name> - Swap to HUD layout called <name>"
|
|
|
|
|
});
|
2020-07-29 16:01:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
2020-08-06 16:04:47 +00:00
|
|
|
|
this.pi.Framework.OnUpdateEvent -= this.swapper.OnFrameworkUpdate;
|
2020-07-29 16:01:00 +00:00
|
|
|
|
this.pi.CommandManager.RemoveHandler("/phudswap");
|
2020-08-04 02:13:29 +00:00
|
|
|
|
this.pi.CommandManager.RemoveHandler("/phud");
|
2020-07-29 16:01:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 17:58:56 +00:00
|
|
|
|
public void Dispose() {
|
|
|
|
|
this.Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-04 02:13:29 +00:00
|
|
|
|
private void OnSettingsCommand(string command, string args) {
|
2020-07-29 16:01:00 +00:00
|
|
|
|
this.ui.SettingsVisible = true;
|
|
|
|
|
}
|
2020-08-04 02:13:29 +00:00
|
|
|
|
|
|
|
|
|
private void OnSwapCommand(string command, string args) {
|
|
|
|
|
KeyValuePair<Guid, Layout> entry = this.Config.Layouts2.FirstOrDefault(e => e.Value.Name == args);
|
|
|
|
|
if (entry.Equals(default(KeyValuePair<Guid, Layout>))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Layout layout = entry.Value;
|
|
|
|
|
|
|
|
|
|
this.Hud.WriteLayout(this.Config.StagingSlot, layout.Hud);
|
|
|
|
|
this.Hud.SelectSlot(this.Config.StagingSlot, true);
|
|
|
|
|
}
|
2020-07-29 16:01:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|