Change RecipeNote code into utility
This commit is contained in:
@@ -1,12 +1,9 @@
|
|||||||
using Craftimizer.Plugin.Windows;
|
using Craftimizer.Plugin.Windows;
|
||||||
using Craftimizer.Simulator;
|
using Craftimizer.Simulator;
|
||||||
using Craftimizer.Utils;
|
using Craftimizer.Utils;
|
||||||
using Dalamud.Hooking;
|
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
using Dalamud.IoC;
|
using Dalamud.IoC;
|
||||||
using Dalamud.Logging;
|
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Dalamud.Utility.Signatures;
|
|
||||||
using Lumina.Excel.GeneratedSheets;
|
using Lumina.Excel.GeneratedSheets;
|
||||||
using ClassJob = Craftimizer.Simulator.ClassJob;
|
using ClassJob = Craftimizer.Simulator.ClassJob;
|
||||||
|
|
||||||
@@ -22,7 +19,8 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
public Craft SynthesisWindow { get; }
|
public Craft SynthesisWindow { get; }
|
||||||
public Windows.Simulator? SimulatorWindow { get; set; }
|
public Windows.Simulator? SimulatorWindow { get; set; }
|
||||||
|
|
||||||
public Hooks Hook { get; }
|
public Hooks Hooks { get; }
|
||||||
|
public RecipeNote RecipeNote { get; }
|
||||||
|
|
||||||
public Plugin([RequiredVersion("1.0")] DalamudPluginInterface pluginInterface)
|
public Plugin([RequiredVersion("1.0")] DalamudPluginInterface pluginInterface)
|
||||||
{
|
{
|
||||||
@@ -30,6 +28,8 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
pluginInterface.Create<Service>();
|
pluginInterface.Create<Service>();
|
||||||
Service.Configuration = pluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
|
Service.Configuration = pluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
|
||||||
|
|
||||||
|
Hooks = new();
|
||||||
|
RecipeNote = new();
|
||||||
WindowSystem = new(Name);
|
WindowSystem = new(Name);
|
||||||
|
|
||||||
SettingsWindow = new();
|
SettingsWindow = new();
|
||||||
@@ -38,8 +38,6 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
|
|
||||||
Service.PluginInterface.UiBuilder.Draw += WindowSystem.Draw;
|
Service.PluginInterface.UiBuilder.Draw += WindowSystem.Draw;
|
||||||
Service.PluginInterface.UiBuilder.OpenConfigUi += OpenSettingsWindow;
|
Service.PluginInterface.UiBuilder.OpenConfigUi += OpenSettingsWindow;
|
||||||
|
|
||||||
Hook = new();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenSimulatorWindow(Item item, bool isExpert, SimulationInput input, ClassJob classJob, Macro? macro)
|
public void OpenSimulatorWindow(Item item, bool isExpert, SimulationInput input, ClassJob classJob, Macro? macro)
|
||||||
@@ -61,6 +59,8 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
SimulatorWindow?.Dispose();
|
SimulatorWindow?.Dispose();
|
||||||
Hook.Dispose();
|
SynthesisWindow.Dispose();
|
||||||
|
RecipeNote.Dispose();
|
||||||
|
Hooks.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public sealed class Service
|
|||||||
[PluginService] public static DataManager DataManager { get; private set; }
|
[PluginService] public static DataManager DataManager { get; private set; }
|
||||||
[PluginService] public static TargetManager TargetManager { get; private set; }
|
[PluginService] public static TargetManager TargetManager { get; private set; }
|
||||||
[PluginService] public static Condition Condition { get; private set; }
|
[PluginService] public static Condition Condition { get; private set; }
|
||||||
|
[PluginService] public static Framework Framework { get; private set; }
|
||||||
|
|
||||||
public static Plugin Plugin { get; internal set; }
|
public static Plugin Plugin { get; internal set; }
|
||||||
public static Configuration Configuration { get; internal set; }
|
public static Configuration Configuration { get; internal set; }
|
||||||
|
|||||||
@@ -1,25 +1,29 @@
|
|||||||
using Craftimizer.Plugin;
|
using Craftimizer.Plugin;
|
||||||
using Craftimizer.Simulator;
|
using Craftimizer.Simulator;
|
||||||
using FFXIVClientStructs.FFXIV.Client.Game.UI;
|
using Dalamud.Game;
|
||||||
|
using Dalamud.Logging;
|
||||||
using FFXIVClientStructs.FFXIV.Client.Game;
|
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.Game.Object;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.Game.UI;
|
||||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
|
||||||
using Lumina.Excel.GeneratedSheets;
|
using Lumina.Excel.GeneratedSheets;
|
||||||
using System.Linq;
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using ActionType = Craftimizer.Simulator.Actions.ActionType;
|
||||||
using ClassJob = Craftimizer.Simulator.ClassJob;
|
using ClassJob = Craftimizer.Simulator.ClassJob;
|
||||||
using CSRecipeNote = FFXIVClientStructs.FFXIV.Client.Game.UI.RecipeNote;
|
using CSRecipeNote = FFXIVClientStructs.FFXIV.Client.Game.UI.RecipeNote;
|
||||||
using ActionType = Craftimizer.Simulator.Actions.ActionType;
|
|
||||||
using FFXIVClientStructs.FFXIV.Client.Game.Object;
|
|
||||||
|
|
||||||
namespace Craftimizer.Utils;
|
namespace Craftimizer.Utils;
|
||||||
|
|
||||||
public unsafe class RecipeNote
|
public sealed unsafe class RecipeNote : IDisposable
|
||||||
{
|
{
|
||||||
public AddonRecipeNote* AddonRecipe { get; private set; }
|
public AddonRecipeNote* AddonRecipe { get; private set; }
|
||||||
public AddonSynthesis* AddonSynthesis { get; private set; }
|
public AddonSynthesis* AddonSynthesis { get; private set; }
|
||||||
public CSRecipeNote* State { get; private set; }
|
public bool IsCrafting { get; private set; }
|
||||||
public ushort RecipeId { get; private set; }
|
public ushort RecipeId { get; private set; }
|
||||||
public Recipe Recipe { get; private set; } = null!;
|
public Recipe Recipe { get; private set; } = null!;
|
||||||
|
public bool HasValidRecipe { get; private set; }
|
||||||
|
|
||||||
public RecipeLevelTable Table { get; private set; } = null!;
|
public RecipeLevelTable Table { get; private set; } = null!;
|
||||||
public RecipeInfo Info { get; private set; } = null!;
|
public RecipeInfo Info { get; private set; } = null!;
|
||||||
@@ -31,34 +35,45 @@ public unsafe class RecipeNote
|
|||||||
|
|
||||||
public RecipeNote()
|
public RecipeNote()
|
||||||
{
|
{
|
||||||
|
Service.Framework.Update += FrameworkUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Update(out bool isNewRecipe)
|
private void FrameworkUpdate(Framework f)
|
||||||
{
|
{
|
||||||
isNewRecipe = false;
|
HasValidRecipe = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HasValidRecipe = Update();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
PluginLog.LogError(e, "RecipeNote framework update failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update()
|
||||||
|
{
|
||||||
if (Service.ClientState.LocalPlayer == null)
|
if (Service.ClientState.LocalPlayer == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
AddonRecipe = (AddonRecipeNote*)Service.GameGui.GetAddonByName("RecipeNote");
|
AddonRecipe = (AddonRecipeNote*)Service.GameGui.GetAddonByName("RecipeNote");
|
||||||
AddonSynthesis = (AddonSynthesis*)Service.GameGui.GetAddonByName("Synthesis");
|
AddonSynthesis = (AddonSynthesis*)Service.GameGui.GetAddonByName("Synthesis");
|
||||||
|
|
||||||
State = CSRecipeNote.Instance();
|
var recipeId = GetRecipeIdFromList();
|
||||||
|
if (recipeId == null)
|
||||||
var list = State->RecipeList;
|
{
|
||||||
|
recipeId = GetRecipeIdFromAgent();
|
||||||
if (list == null)
|
if (recipeId == null)
|
||||||
return false;
|
return false;
|
||||||
|
else
|
||||||
|
IsCrafting = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
IsCrafting = false;
|
||||||
|
|
||||||
var recipeEntry = list->SelectedRecipe;
|
var isNewRecipe = RecipeId != recipeId.Value;
|
||||||
|
|
||||||
if (recipeEntry == null)
|
RecipeId = recipeId.Value;
|
||||||
return false;
|
|
||||||
|
|
||||||
isNewRecipe = RecipeId != recipeEntry->RecipeId;
|
|
||||||
|
|
||||||
RecipeId = recipeEntry->RecipeId;
|
|
||||||
|
|
||||||
var recipe = LuminaSheets.RecipeSheet.GetRow(RecipeId);
|
var recipe = LuminaSheets.RecipeSheet.GetRow(RecipeId);
|
||||||
|
|
||||||
@@ -73,6 +88,35 @@ public unsafe class RecipeNote
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ushort? GetRecipeIdFromList()
|
||||||
|
{
|
||||||
|
var instance = CSRecipeNote.Instance();
|
||||||
|
|
||||||
|
var list = instance->RecipeList;
|
||||||
|
|
||||||
|
if (list == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var recipeEntry = list->SelectedRecipe;
|
||||||
|
|
||||||
|
if (recipeEntry == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return recipeEntry->RecipeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ushort? GetRecipeIdFromAgent()
|
||||||
|
{
|
||||||
|
var instance = AgentRecipeNote.Instance();
|
||||||
|
|
||||||
|
var recipeId = instance->ActiveCraftRecipeId;
|
||||||
|
|
||||||
|
if (recipeId == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return (ushort)recipeId;
|
||||||
|
}
|
||||||
|
|
||||||
private void CalculateStats()
|
private void CalculateStats()
|
||||||
{
|
{
|
||||||
Table = Recipe.RecipeLevelTable.Value!;
|
Table = Recipe.RecipeLevelTable.Value!;
|
||||||
@@ -104,4 +148,9 @@ public unsafe class RecipeNote
|
|||||||
ProgressModifier = Table.ProgressModifier,
|
ProgressModifier = Table.ProgressModifier,
|
||||||
ProgressDivider = Table.ProgressDivider,
|
ProgressDivider = Table.ProgressDivider,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Service.Framework.Update -= FrameworkUpdate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user