fix: run swap logic in framework update handler
This commit is contained in:
parent
8614c19835
commit
2655671682
|
@ -79,6 +79,7 @@
|
|||
<Compile Include="PluginUI.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Statuses.cs" />
|
||||
<Compile Include="Swapper.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="HudSwap.json" />
|
||||
|
|
|
@ -10,7 +10,10 @@ namespace HudSwap {
|
|||
|
||||
private DalamudPluginInterface pi;
|
||||
private PluginUI ui;
|
||||
private Swapper swapper;
|
||||
|
||||
public HUD Hud { get; private set; }
|
||||
public Statuses Statuses { get; private set; }
|
||||
public GameFunctions GameFunctions { get; private set; }
|
||||
public PluginConfig Config { get; private set; }
|
||||
|
||||
|
@ -27,8 +30,11 @@ namespace HudSwap {
|
|||
|
||||
this.ui = new PluginUI(this, this.pi);
|
||||
this.Hud = new HUD(this.pi);
|
||||
this.Statuses = new Statuses(this, this.pi);
|
||||
this.GameFunctions = new GameFunctions(this.pi);
|
||||
|
||||
this.swapper = new Swapper(this, this.pi);
|
||||
|
||||
if (this.Config.FirstRun) {
|
||||
this.Config.FirstRun = false;
|
||||
if (this.Config.Layouts2.Count == 0) {
|
||||
|
@ -41,6 +47,7 @@ namespace HudSwap {
|
|||
|
||||
this.pi.UiBuilder.OnBuildUi += this.ui.Draw;
|
||||
this.pi.UiBuilder.OnOpenConfigUi += this.ui.ConfigUI;
|
||||
this.pi.Framework.OnUpdateEvent += this.swapper.OnFrameworkUpdate;
|
||||
|
||||
this.pi.CommandManager.AddHandler("/phudswap", new CommandInfo(OnSettingsCommand) {
|
||||
HelpMessage = "Open the HudSwap settings"
|
||||
|
@ -53,6 +60,7 @@ namespace HudSwap {
|
|||
protected virtual void Dispose(bool all) {
|
||||
this.pi.UiBuilder.OnBuildUi -= this.ui.Draw;
|
||||
this.pi.UiBuilder.OnOpenConfigUi -= this.ui.ConfigUI;
|
||||
this.pi.Framework.OnUpdateEvent -= this.swapper.OnFrameworkUpdate;
|
||||
this.pi.CommandManager.RemoveHandler("/phudswap");
|
||||
this.pi.CommandManager.RemoveHandler("/phud");
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ namespace HudSwap {
|
|||
|
||||
private readonly HudSwapPlugin plugin;
|
||||
private readonly DalamudPluginInterface pi;
|
||||
private readonly Statuses statuses;
|
||||
|
||||
private bool _settingsVisible = false;
|
||||
public bool SettingsVisible { get => this._settingsVisible; set => this._settingsVisible = value; }
|
||||
|
@ -31,7 +30,6 @@ namespace HudSwap {
|
|||
public PluginUI(HudSwapPlugin plugin, DalamudPluginInterface pi) {
|
||||
this.plugin = plugin;
|
||||
this.pi = pi;
|
||||
this.statuses = new Statuses(this.plugin, this.pi);
|
||||
}
|
||||
|
||||
public void ConfigUI(object sender, EventArgs args) {
|
||||
|
@ -244,7 +242,7 @@ namespace HudSwap {
|
|||
this.plugin.Config.StatusLayouts[status] = newLayout;
|
||||
this.plugin.Config.Save();
|
||||
if (this.plugin.Config.SwapsEnabled) {
|
||||
this.statuses.SetHudLayout(player, true);
|
||||
this.plugin.Statuses.SetHudLayout(player, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -279,7 +277,7 @@ namespace HudSwap {
|
|||
this.plugin.Config.JobLayouts[job.Abbreviation] = newLayout;
|
||||
this.plugin.Config.Save();
|
||||
if (this.plugin.Config.SwapsEnabled) {
|
||||
this.statuses.SetHudLayout(player, true);
|
||||
this.plugin.Statuses.SetHudLayout(player, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -295,7 +293,7 @@ namespace HudSwap {
|
|||
this.plugin.Config.JobsCombatOnly = combatOnlyJobs;
|
||||
this.plugin.Config.Save();
|
||||
if (this.plugin.Config.SwapsEnabled) {
|
||||
this.statuses.SetHudLayout(player, true);
|
||||
this.plugin.Statuses.SetHudLayout(player, true);
|
||||
}
|
||||
}
|
||||
ImGui.SameLine();
|
||||
|
@ -306,7 +304,7 @@ namespace HudSwap {
|
|||
this.plugin.Config.HighPriorityJobs = highPriorityJobs;
|
||||
this.plugin.Config.Save();
|
||||
if (this.plugin.Config.SwapsEnabled) {
|
||||
this.statuses.SetHudLayout(player, true);
|
||||
this.plugin.Statuses.SetHudLayout(player, true);
|
||||
}
|
||||
}
|
||||
ImGui.SameLine();
|
||||
|
@ -344,19 +342,6 @@ namespace HudSwap {
|
|||
|
||||
public void Draw() {
|
||||
this.DrawSettings();
|
||||
|
||||
if (!(this.plugin.Config.SwapsEnabled && this.plugin.Config.UnderstandsRisks)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerCharacter player = this.pi.ClientState.LocalPlayer;
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.statuses.Update(player)) {
|
||||
this.statuses.SetHudLayout(null);
|
||||
}
|
||||
}
|
||||
|
||||
private bool LayoutBox(string name, Guid currentLayout, out Guid newLayout) {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
using Dalamud.Game.ClientState.Actors.Types;
|
||||
using Dalamud.Game.Internal;
|
||||
using Dalamud.Plugin;
|
||||
using System;
|
||||
|
||||
namespace HudSwap {
|
||||
public class Swapper {
|
||||
private readonly HudSwapPlugin plugin;
|
||||
private readonly DalamudPluginInterface pi;
|
||||
|
||||
public Swapper(HudSwapPlugin plugin, DalamudPluginInterface pi) {
|
||||
this.plugin = plugin;
|
||||
this.pi = pi;
|
||||
}
|
||||
|
||||
public void OnFrameworkUpdate(Framework framework) {
|
||||
if (framework == null) {
|
||||
throw new ArgumentNullException(nameof(framework), "Framework cannot be null");
|
||||
}
|
||||
|
||||
if (!(this.plugin.Config.SwapsEnabled && this.plugin.Config.UnderstandsRisks)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerCharacter player = this.pi.ClientState.LocalPlayer;
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.plugin.Statuses.Update(player)) {
|
||||
this.plugin.Statuses.SetHudLayout(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue