2021-03-08 15:03:11 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Dalamud.Game.Command;
|
|
|
|
|
using Dalamud.Plugin;
|
|
|
|
|
using HUD_Manager.Configuration;
|
2021-03-10 19:08:28 +00:00
|
|
|
|
using Resourcer;
|
|
|
|
|
using YamlDotNet.Serialization;
|
|
|
|
|
using YamlDotNet.Serialization.NamingConventions;
|
2021-03-08 15:03:11 +00:00
|
|
|
|
|
|
|
|
|
namespace HUD_Manager {
|
|
|
|
|
public class Plugin : IDalamudPlugin {
|
|
|
|
|
public string Name => "HUD Manager";
|
|
|
|
|
|
|
|
|
|
private PluginUi Ui { get; set; } = null!;
|
|
|
|
|
private Swapper Swapper { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
public DalamudPluginInterface Interface { get; private set; } = null!;
|
|
|
|
|
public Hud Hud { get; private set; } = null!;
|
|
|
|
|
public Statuses Statuses { get; private set; } = null!;
|
|
|
|
|
public GameFunctions GameFunctions { get; private set; } = null!;
|
|
|
|
|
public Config Config { get; private set; } = null!;
|
2021-03-10 19:08:28 +00:00
|
|
|
|
public HelpFile Help { get; private set; } = null!;
|
2021-03-08 15:03:11 +00:00
|
|
|
|
|
|
|
|
|
public void Initialize(DalamudPluginInterface pluginInterface) {
|
|
|
|
|
this.Interface = pluginInterface;
|
|
|
|
|
|
|
|
|
|
this.Config = Migrator.LoadConfig(this);
|
|
|
|
|
this.Config.Initialize(this.Interface);
|
|
|
|
|
this.Config.Save();
|
|
|
|
|
|
2021-03-10 19:08:28 +00:00
|
|
|
|
var deserializer = new DeserializerBuilder()
|
|
|
|
|
.WithNamingConvention(UnderscoredNamingConvention.Instance)
|
|
|
|
|
.Build();
|
|
|
|
|
this.Help = deserializer.Deserialize<HelpFile>(Resource.AsString("help.yaml"));
|
|
|
|
|
|
2021-03-08 15:03:11 +00:00
|
|
|
|
this.Ui = new PluginUi(this);
|
|
|
|
|
this.Hud = new Hud(this);
|
|
|
|
|
this.Statuses = new Statuses(this);
|
|
|
|
|
this.GameFunctions = new GameFunctions(this);
|
|
|
|
|
this.Swapper = new Swapper(this);
|
|
|
|
|
|
|
|
|
|
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($"Auto-import {(int) slot + 1}", slot, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Config.Save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Interface.UiBuilder.OnBuildUi += this.Ui.Draw;
|
|
|
|
|
this.Interface.UiBuilder.OnOpenConfigUi += this.Ui.ConfigUi;
|
|
|
|
|
this.Interface.Framework.OnUpdateEvent += this.Swapper.OnFrameworkUpdate;
|
|
|
|
|
|
2021-03-10 19:08:28 +00:00
|
|
|
|
this.Interface.CommandManager.AddHandler("/hudman", new CommandInfo(this.OnCommand) {
|
2021-03-08 15:03:11 +00:00
|
|
|
|
HelpMessage = "Open the HUD Manager settings or swap to layout name",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose() {
|
|
|
|
|
this.Interface.UiBuilder.OnBuildUi -= this.Ui.Draw;
|
|
|
|
|
this.Interface.UiBuilder.OnOpenConfigUi -= this.Ui.ConfigUi;
|
|
|
|
|
this.Interface.Framework.OnUpdateEvent -= this.Swapper.OnFrameworkUpdate;
|
2021-03-10 19:08:28 +00:00
|
|
|
|
this.Interface.CommandManager.RemoveHandler("/hudman");
|
2021-03-08 15:03:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCommand(string command, string args) {
|
|
|
|
|
if (string.IsNullOrWhiteSpace(args)) {
|
|
|
|
|
this.Ui.SettingsVisible = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var entry = this.Config.Layouts.FirstOrDefault(e => e.Value.Name == args);
|
|
|
|
|
if (entry.Equals(default(KeyValuePair<Guid, SavedLayout>))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var layout = entry.Value;
|
|
|
|
|
|
|
|
|
|
this.Hud.WriteLayout(this.Config.StagingSlot, layout.ToLayout());
|
|
|
|
|
this.Hud.SelectSlot(this.Config.StagingSlot, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|