diff --git a/Penumbra/Api/IpcTester.cs b/Penumbra/Api/IpcTester.cs index 1044581f..d1124847 100644 --- a/Penumbra/Api/IpcTester.cs +++ b/Penumbra/Api/IpcTester.cs @@ -40,22 +40,21 @@ public class IpcTester : IDisposable private readonly ModSettings _modSettings; private readonly Temporary _temporary; - public IpcTester(Configuration config, DalamudPluginInterface pi, PenumbraIpcProviders ipcProviders, ModManager modManager, - CollectionManager collections, - TempModManager tempMods, TempCollectionManager tempCollections, SaveService saveService) + public IpcTester(Configuration config, DalamudServices dalamud, PenumbraIpcProviders ipcProviders, ModManager modManager, + CollectionManager collections, TempModManager tempMods, TempCollectionManager tempCollections, SaveService saveService) { _ipcProviders = ipcProviders; - _pluginState = new PluginState(pi); - _ipcConfiguration = new IpcConfiguration(pi); - _ui = new Ui(pi); - _redrawing = new Redrawing(pi); - _gameState = new GameState(pi); - _resolve = new Resolve(pi); - _collections = new Collections(pi); - _meta = new Meta(pi); - _mods = new Mods(pi); - _modSettings = new ModSettings(pi); - _temporary = new Temporary(pi, modManager, collections, tempMods, tempCollections, saveService, config); + _pluginState = new PluginState(dalamud.PluginInterface); + _ipcConfiguration = new IpcConfiguration(dalamud.PluginInterface); + _ui = new Ui(dalamud.PluginInterface); + _redrawing = new Redrawing(dalamud); + _gameState = new GameState(dalamud.PluginInterface); + _resolve = new Resolve(dalamud.PluginInterface); + _collections = new Collections(dalamud.PluginInterface); + _meta = new Meta(dalamud.PluginInterface); + _mods = new Mods(dalamud.PluginInterface); + _modSettings = new ModSettings(dalamud.PluginInterface); + _temporary = new Temporary(dalamud.PluginInterface, modManager, collections, tempMods, tempCollections, saveService, config); UnsubscribeEvents(); } @@ -395,17 +394,17 @@ public class IpcTester : IDisposable private class Redrawing { - private readonly DalamudPluginInterface _pi; + private readonly DalamudServices _dalamud; public readonly EventSubscriber Redrawn; private string _redrawName = string.Empty; private int _redrawIndex = 0; private string _lastRedrawnString = "None"; - public Redrawing(DalamudPluginInterface pi) - { - _pi = pi; - Redrawn = Ipc.GameObjectRedrawn.Subscriber(pi, SetLastRedrawn); + public Redrawing(DalamudServices dalamud) + { + _dalamud = dalamud; + Redrawn = Ipc.GameObjectRedrawn.Subscriber(_dalamud.PluginInterface, SetLastRedrawn); } public void Draw() @@ -423,25 +422,25 @@ public class IpcTester : IDisposable ImGui.InputTextWithHint("##redrawName", "Name...", ref _redrawName, 32); ImGui.SameLine(); if (ImGui.Button("Redraw##Name")) - Ipc.RedrawObjectByName.Subscriber(_pi).Invoke(_redrawName, RedrawType.Redraw); + Ipc.RedrawObjectByName.Subscriber(_dalamud.PluginInterface).Invoke(_redrawName, RedrawType.Redraw); DrawIntro(Ipc.RedrawObject.Label, "Redraw Player Character"); - if (ImGui.Button("Redraw##pc") && DalamudServices.SClientState.LocalPlayer != null) - Ipc.RedrawObject.Subscriber(_pi).Invoke(DalamudServices.SClientState.LocalPlayer, RedrawType.Redraw); + if (ImGui.Button("Redraw##pc") && _dalamud.ClientState.LocalPlayer != null) + Ipc.RedrawObject.Subscriber(_dalamud.PluginInterface).Invoke(_dalamud.ClientState.LocalPlayer, RedrawType.Redraw); DrawIntro(Ipc.RedrawObjectByIndex.Label, "Redraw by Index"); var tmp = _redrawIndex; ImGui.SetNextItemWidth(100 * UiHelpers.Scale); - if (ImGui.DragInt("##redrawIndex", ref tmp, 0.1f, 0, DalamudServices.SObjects.Length)) - _redrawIndex = Math.Clamp(tmp, 0, DalamudServices.SObjects.Length); + if (ImGui.DragInt("##redrawIndex", ref tmp, 0.1f, 0, _dalamud.Objects.Length)) + _redrawIndex = Math.Clamp(tmp, 0, _dalamud.Objects.Length); ImGui.SameLine(); if (ImGui.Button("Redraw##Index")) - Ipc.RedrawObjectByIndex.Subscriber(_pi).Invoke(_redrawIndex, RedrawType.Redraw); + Ipc.RedrawObjectByIndex.Subscriber(_dalamud.PluginInterface).Invoke(_redrawIndex, RedrawType.Redraw); DrawIntro(Ipc.RedrawAll.Label, "Redraw All"); if (ImGui.Button("Redraw##All")) - Ipc.RedrawAll.Subscriber(_pi).Invoke(RedrawType.Redraw); + Ipc.RedrawAll.Subscriber(_dalamud.PluginInterface).Invoke(RedrawType.Redraw); DrawIntro(Ipc.GameObjectRedrawn.Label, "Last Redrawn Object:"); ImGui.TextUnformatted(_lastRedrawnString); @@ -450,12 +449,12 @@ public class IpcTester : IDisposable private void SetLastRedrawn(IntPtr address, int index) { if (index < 0 - || index > DalamudServices.SObjects.Length + || index > _dalamud.Objects.Length || address == IntPtr.Zero - || DalamudServices.SObjects[index]?.Address != address) + || _dalamud.Objects[index]?.Address != address) _lastRedrawnString = "Invalid"; - _lastRedrawnString = $"{DalamudServices.SObjects[index]!.Name} (0x{address:X}, {index})"; + _lastRedrawnString = $"{_dalamud.Objects[index]!.Name} (0x{address:X}, {index})"; } } diff --git a/Penumbra/Api/PenumbraIpcProviders.cs b/Penumbra/Api/PenumbraIpcProviders.cs index e8139453..7ccd7e20 100644 --- a/Penumbra/Api/PenumbraIpcProviders.cs +++ b/Penumbra/Api/PenumbraIpcProviders.cs @@ -7,6 +7,7 @@ using Penumbra.Api.Enums; using Penumbra.Api.Helpers; using Penumbra.Collections.Manager; using Penumbra.Mods.Manager; +using Penumbra.Services; using Penumbra.Util; namespace Penumbra.Api; @@ -115,9 +116,10 @@ public class PenumbraIpcProviders : IDisposable internal readonly FuncProvider RemoveTemporaryModAll; internal readonly FuncProvider RemoveTemporaryMod; - public PenumbraIpcProviders(DalamudPluginInterface pi, IPenumbraApi api, ModManager modManager, CollectionManager collections, + public PenumbraIpcProviders(DalamudServices dalamud, IPenumbraApi api, ModManager modManager, CollectionManager collections, TempModManager tempMods, TempCollectionManager tempCollections, SaveService saveService, Configuration config) { + var pi = dalamud.PluginInterface; Api = api; // Plugin State @@ -228,7 +230,7 @@ public class PenumbraIpcProviders : IDisposable RemoveTemporaryModAll = Ipc.RemoveTemporaryModAll.Provider(pi, Api.RemoveTemporaryModAll); RemoveTemporaryMod = Ipc.RemoveTemporaryMod.Provider(pi, Api.RemoveTemporaryMod); - Tester = new IpcTester(config, pi, this, modManager, collections, tempMods, tempCollections, saveService); + Tester = new IpcTester(config, dalamud, this, modManager, collections, tempMods, tempCollections, saveService); Initialized.Invoke(); } diff --git a/Penumbra/Import/Textures/CombinedTexture.cs b/Penumbra/Import/Textures/CombinedTexture.cs index bd9154a0..fcfbc3ee 100644 --- a/Penumbra/Import/Textures/CombinedTexture.cs +++ b/Penumbra/Import/Textures/CombinedTexture.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Numerics; +using Dalamud.Interface; using Lumina.Data.Files; using OtterTex; using Penumbra.Services; @@ -43,13 +44,13 @@ public partial class CombinedTexture : IDisposable public Exception? SaveException { get; private set; } = null; - public void Draw( Vector2 size ) + public void Draw( UiBuilder builder, Vector2 size ) { if( _mode == Mode.Custom && !_centerStorage.IsLoaded ) { var (width, height) = CombineImage(); _centerStorage.TextureWrap = - DalamudServices.PluginInterface.UiBuilder.LoadImageRaw( _centerStorage.RGBAPixels, width, height, 4 ); + builder.LoadImageRaw( _centerStorage.RGBAPixels, width, height, 4 ); } _current?.Draw( size ); diff --git a/Penumbra/Import/Textures/Texture.cs b/Penumbra/Import/Textures/Texture.cs index 3a576028..22096b37 100644 --- a/Penumbra/Import/Textures/Texture.cs +++ b/Penumbra/Import/Textures/Texture.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Numerics; +using Dalamud.Data; using Dalamud.Interface; using ImGuiNET; using ImGuiScene; @@ -121,7 +122,7 @@ public sealed class Texture : IDisposable public event Action? Loaded; - private void Load(string path) + private void Load(DalamudServices dalamud, string path) { _tmpPath = null; if (path == Path) @@ -136,9 +137,9 @@ public sealed class Texture : IDisposable { var _ = System.IO.Path.GetExtension(Path).ToLowerInvariant() switch { - ".dds" => LoadDds(), - ".png" => LoadPng(), - ".tex" => LoadTex(), + ".dds" => LoadDds(dalamud), + ".png" => LoadPng(dalamud), + ".tex" => LoadTex(dalamud), _ => throw new Exception($"Extension {System.IO.Path.GetExtension(Path)} unknown."), }; Loaded?.Invoke(true); @@ -150,18 +151,18 @@ public sealed class Texture : IDisposable } } - private bool LoadDds() + private bool LoadDds(DalamudServices dalamud) { Type = FileType.Dds; var scratch = ScratchImage.LoadDDS(Path); BaseImage = scratch; var rgba = scratch.GetRGBA(out var f).ThrowIfError(f); RGBAPixels = rgba.Pixels[..(f.Meta.Width * f.Meta.Height * f.Meta.Format.BitsPerPixel() / 8)].ToArray(); - CreateTextureWrap(f.Meta.Width, f.Meta.Height); + CreateTextureWrap(dalamud.UiBuilder, f.Meta.Width, f.Meta.Height); return true; } - private bool LoadPng() + private bool LoadPng(DalamudServices dalamud) { Type = FileType.Png; BaseImage = null; @@ -169,37 +170,37 @@ public sealed class Texture : IDisposable using var png = Image.Load(stream); RGBAPixels = new byte[png.Height * png.Width * 4]; png.CopyPixelDataTo(RGBAPixels); - CreateTextureWrap(png.Width, png.Height); + CreateTextureWrap(dalamud.UiBuilder, png.Width, png.Height); return true; } - private bool LoadTex() + private bool LoadTex(DalamudServices dalamud) { Type = FileType.Tex; - using var stream = OpenTexStream(); + using var stream = OpenTexStream(dalamud.GameData); var scratch = TexFileParser.Parse(stream); BaseImage = scratch; var rgba = scratch.GetRGBA(out var f).ThrowIfError(f); RGBAPixels = rgba.Pixels[..(f.Meta.Width * f.Meta.Height * f.Meta.Format.BitsPerPixel() / 8)].ToArray(); - CreateTextureWrap(scratch.Meta.Width, scratch.Meta.Height); + CreateTextureWrap(dalamud.UiBuilder, scratch.Meta.Width, scratch.Meta.Height); return true; } - private Stream OpenTexStream() + private Stream OpenTexStream(DataManager gameData) { if (System.IO.Path.IsPathRooted(Path)) return File.OpenRead(Path); - var file = DalamudServices.SGameData.GetFile(Path); + var file = gameData.GetFile(Path); return file != null ? new MemoryStream(file.Data) : throw new Exception($"Unable to obtain \"{Path}\" from game files."); } - private void CreateTextureWrap(int width, int height) - => TextureWrap = DalamudServices.PluginInterface.UiBuilder.LoadImageRaw(RGBAPixels, width, height, 4); + private void CreateTextureWrap(UiBuilder builder, int width, int height) + => TextureWrap = builder.LoadImageRaw(RGBAPixels, width, height, 4); private string? _tmpPath; - public void PathSelectBox(string label, string tooltip, IEnumerable<(string, bool)> paths, int skipPrefix) + public void PathSelectBox(DalamudServices dalamud, string label, string tooltip, IEnumerable<(string, bool)> paths, int skipPrefix) { ImGui.SetNextItemWidth(-0.0001f); var startPath = Path.Length > 0 ? Path : "Choose a modded texture from this mod here..."; @@ -209,7 +210,7 @@ public sealed class Texture : IDisposable { if (game) { - if (!DalamudServices.SGameData.FileExists(path)) + if (!dalamud.GameData.FileExists(path)) continue; } else if (!File.Exists(path)) @@ -222,7 +223,7 @@ public sealed class Texture : IDisposable { var p = game ? $"--> {path}" : path[skipPrefix..]; if (ImGui.Selectable(p, path == startPath) && path != startPath) - Load(path); + Load(dalamud, path); } ImGuiUtil.HoverTooltip(game @@ -233,7 +234,7 @@ public sealed class Texture : IDisposable ImGuiUtil.HoverTooltip(tooltip); } - public void PathInputBox(string label, string hint, string tooltip, string startPath, FileDialogService fileDialog, + public void PathInputBox(DalamudServices dalamud, string label, string hint, string tooltip, string startPath, FileDialogService fileDialog, string defaultModImportPath) { _tmpPath ??= Path; @@ -242,7 +243,7 @@ public sealed class Texture : IDisposable ImGui.SetNextItemWidth(-2 * ImGui.GetFrameHeight() - 7 * UiHelpers.Scale); ImGui.InputTextWithHint(label, hint, ref _tmpPath, Utf8GamePath.MaxGamePathLength); if (ImGui.IsItemDeactivatedAfterEdit()) - Load(_tmpPath); + Load(dalamud, _tmpPath); ImGuiUtil.HoverTooltip(tooltip); ImGui.SameLine(); @@ -257,7 +258,7 @@ public sealed class Texture : IDisposable void UpdatePath(bool success, List paths) { if (success && paths.Count > 0) - texture.Load(paths[0]); + texture.Load(dalamud, paths[0]); } fileDialog.OpenFilePicker("Open Image...", "Textures{.png,.dds,.tex}", UpdatePath, 1, startPath, false); @@ -270,7 +271,7 @@ public sealed class Texture : IDisposable { var path = Path; Path = string.Empty; - Load(path); + Load(dalamud, path); } } } diff --git a/Penumbra/Interop/Services/RedrawService.cs b/Penumbra/Interop/Services/RedrawService.cs index d85204b1..f78d6dca 100644 --- a/Penumbra/Interop/Services/RedrawService.cs +++ b/Penumbra/Interop/Services/RedrawService.cs @@ -293,10 +293,10 @@ public sealed unsafe partial class RedrawService : IDisposable } } - private static GameObject? GetLocalPlayer() + private GameObject? GetLocalPlayer() { - var gPosePlayer = DalamudServices.SObjects[GPosePlayerIdx]; - return gPosePlayer ?? DalamudServices.SObjects[0]; + var gPosePlayer = _objects[GPosePlayerIdx]; + return gPosePlayer ?? _objects[0]; } public bool GetName(string lowerName, out GameObject? actor) diff --git a/Penumbra/Meta/Files/ImcFile.cs b/Penumbra/Meta/Files/ImcFile.cs index 79313a6f..d47bf387 100644 --- a/Penumbra/Meta/Files/ImcFile.cs +++ b/Penumbra/Meta/Files/ImcFile.cs @@ -130,7 +130,7 @@ public unsafe class ImcFile : MetaBaseFile public override void Reset() { - var file = DalamudServices.SGameData.GetFile(Path.ToString()); + var file = Manager.GameData.GetFile(Path.ToString()); fixed (byte* ptr = file!.Data) { MemoryUtility.MemCpyUnchecked(Data, ptr, file.Data.Length); diff --git a/Penumbra/Mods/ItemSwap/Swaps.cs b/Penumbra/Mods/ItemSwap/Swaps.cs index d689c2cf..36ca77cf 100644 --- a/Penumbra/Mods/ItemSwap/Swaps.cs +++ b/Penumbra/Mods/ItemSwap/Swaps.cs @@ -141,7 +141,7 @@ public sealed class FileSwap : Swap swap.SwapToModded = redirections(swap.SwapToRequestPath); swap.SwapToModdedExistsInGame = - !swap.SwapToModded.IsRooted && DalamudServices.SGameData.FileExists(swap.SwapToModded.InternalName.ToString()); + !swap.SwapToModded.IsRooted && manager.GameData.FileExists(swap.SwapToModded.InternalName.ToString()); swap.SwapToModdedEqualsOriginal = !swap.SwapToModded.IsRooted && swap.SwapToModded.InternalName.Equals(swap.SwapFromRequestPath.Path); swap.FileData = type switch diff --git a/Penumbra/Services/DalamudServices.cs b/Penumbra/Services/DalamudServices.cs index 7320822d..a75f3e4a 100644 --- a/Penumbra/Services/DalamudServices.cs +++ b/Penumbra/Services/DalamudServices.cs @@ -63,49 +63,41 @@ public class DalamudServices { services.AddSingleton(PluginInterface); services.AddSingleton(Commands); - services.AddSingleton(SGameData); - services.AddSingleton(SClientState); + services.AddSingleton(GameData); + services.AddSingleton(ClientState); services.AddSingleton(Chat); services.AddSingleton(Framework); services.AddSingleton(Conditions); services.AddSingleton(Targets); - services.AddSingleton(SObjects); + services.AddSingleton(Objects); services.AddSingleton(TitleScreenMenu); services.AddSingleton(GameGui); services.AddSingleton(KeyState); services.AddSingleton(SigScanner); services.AddSingleton(this); + services.AddSingleton(UiBuilder); } // TODO remove static // @formatter:off - [PluginService][RequiredVersion("1.0")] public static DalamudPluginInterface PluginInterface { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static CommandManager Commands { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static DataManager SGameData { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static ClientState SClientState { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static ChatGui Chat { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static Framework Framework { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static Condition Conditions { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static TargetManager Targets { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static ObjectTable SObjects { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static TitleScreenMenu TitleScreenMenu { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static GameGui GameGui { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static KeyState KeyState { get; private set; } = null!; - [PluginService][RequiredVersion("1.0")] public static SigScanner SigScanner { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public DalamudPluginInterface PluginInterface { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public CommandManager Commands { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public DataManager GameData { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public ClientState ClientState { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public ChatGui Chat { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public Framework Framework { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public Condition Conditions { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public TargetManager Targets { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public ObjectTable Objects { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public TitleScreenMenu TitleScreenMenu { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public GameGui GameGui { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public KeyState KeyState { get; private set; } = null!; + [PluginService][RequiredVersion("1.0")] public SigScanner SigScanner { get; private set; } = null!; // @formatter:on public UiBuilder UiBuilder => PluginInterface.UiBuilder; - public ObjectTable Objects - => SObjects; - - public ClientState ClientState - => SClientState; - - public DataManager GameData - => SGameData; - public const string WaitingForPluginsOption = "IsResumeGameAfterPluginLoad"; private readonly object? _dalamudConfig; diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.Materials.MtrlTab.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.Materials.MtrlTab.cs index a0028a6e..2b607280 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.Materials.MtrlTab.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.Materials.MtrlTab.cs @@ -81,7 +81,7 @@ public partial class ModEditWindow LoadedShpkPath = path; var data = LoadedShpkPath.IsRooted ? File.ReadAllBytes( LoadedShpkPath.FullName ) - : DalamudServices.SGameData.GetFile( LoadedShpkPath.InternalName.ToString() )?.Data; + : _edit._dalamud.GameData.GetFile( LoadedShpkPath.InternalName.ToString() )?.Data; AssociatedShpk = data?.Length > 0 ? new ShpkFile( data ) : throw new Exception( "Failure to load file data." ); LoadedShpkPathName = path.ToPath(); } diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.QuickImport.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.QuickImport.cs index b90d607e..29647c53 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.QuickImport.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.QuickImport.cs @@ -50,7 +50,7 @@ public partial class ModEditWindow } else { - var file = _gameData.GetFile(path); + var file = _dalamud.GameData.GetFile(path); writable = file == null ? null : new RawGameFileWritable(file); } diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.Textures.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.Textures.cs index 6ec0d3b6..514dcb02 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.Textures.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.Textures.cs @@ -41,11 +41,11 @@ public partial class ModEditWindow ImGuiUtil.DrawTextButton(label, new Vector2(-1, 0), ImGui.GetColorU32(ImGuiCol.FrameBg)); ImGui.NewLine(); - tex.PathInputBox("##input", "Import Image...", "Can import game paths as well as your own files.", _mod!.ModPath.FullName, + tex.PathInputBox(_dalamud, "##input", "Import Image...", "Can import game paths as well as your own files.", _mod!.ModPath.FullName, _fileDialog, _config.DefaultModImportPath); var files = _editor.Files.Tex.SelectMany(f => f.SubModUsage.Select(p => (p.Item2.ToString(), true)) .Prepend((f.File.FullName, false))); - tex.PathSelectBox("##combo", "Select the textures included in this mod on your drive or the ones they replace from the game files.", + tex.PathSelectBox(_dalamud, "##combo", "Select the textures included in this mod on your drive or the ones they replace from the game files.", files, _mod.ModPath.FullName.Length + 1); if (tex == _left) @@ -139,7 +139,7 @@ public partial class ModEditWindow using var child2 = ImRaii.Child("image"); if (child2) - _center.Draw(imageSize); + _center.Draw(_dalamud.UiBuilder, imageSize); } private Vector2 GetChildWidth() diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.cs index 517118c9..b8a2590c 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.cs @@ -31,7 +31,7 @@ public partial class ModEditWindow : Window, IDisposable private readonly ModEditor _editor; private readonly Configuration _config; private readonly ItemSwapTab _itemSwapTab; - private readonly DataManager _gameData; + private readonly DalamudServices _dalamud; private readonly MetaFileManager _metaFileManager; private readonly ActiveCollections _activeCollections; private readonly StainService _stainService; @@ -498,18 +498,18 @@ public partial class ModEditWindow : Window, IDisposable public ModEditWindow(PerformanceTracker performance, FileDialogService fileDialog, ItemSwapTab itemSwapTab, DataManager gameData, Configuration config, ModEditor editor, ResourceTreeFactory resourceTreeFactory, MetaFileManager metaFileManager, - StainService stainService, ActiveCollections activeCollections) + StainService stainService, ActiveCollections activeCollections, UiBuilder uiBuilder, DalamudServices dalamud) : base(WindowBaseLabel) { - _performance = performance; - _itemSwapTab = itemSwapTab; - _config = config; - _editor = editor; - _metaFileManager = metaFileManager; - _stainService = stainService; + _performance = performance; + _itemSwapTab = itemSwapTab; + _config = config; + _editor = editor; + _metaFileManager = metaFileManager; + _stainService = stainService; _activeCollections = activeCollections; - _gameData = gameData; - _fileDialog = fileDialog; + _dalamud = dalamud; + _fileDialog = fileDialog; _materialTab = new FileEditor(this, gameData, config, _fileDialog, "Materials", ".mtrl", () => _editor.Files.Mtrl, DrawMaterialPanel, () => _mod?.ModPath.FullName ?? string.Empty, bytes => new MtrlTab(this, new MtrlFile(bytes))); diff --git a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs index 2b4ce7e4..e151faa8 100644 --- a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs +++ b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs @@ -2,6 +2,7 @@ using System; using System.Linq; using System.Numerics; using System.Runtime.InteropServices; +using Dalamud.Game.ClientState.Keys; using Dalamud.Interface; using Dalamud.Interface.Internal.Notifications; using ImGuiNET; @@ -34,10 +35,10 @@ public sealed class ModFileSystemSelector : FileSystemSelectorObjectIndex}"); ImGuiUtil.DrawTableColumn($"0x{obj.Address:X}"); diff --git a/Penumbra/UI/Tabs/ModsTab.cs b/Penumbra/UI/Tabs/ModsTab.cs index 47d6dbdc..b926c2c5 100644 --- a/Penumbra/UI/Tabs/ModsTab.cs +++ b/Penumbra/UI/Tabs/ModsTab.cs @@ -6,6 +6,7 @@ using Penumbra.UI.Classes; using System; using System.Linq; using System.Numerics; +using Dalamud.Game.ClientState; using Dalamud.Interface; using OtterGui.Widgets; using Penumbra.Api.Enums; @@ -29,10 +30,11 @@ public class ModsTab : ITab private readonly ActiveCollections _activeCollections; private readonly RedrawService _redrawService; private readonly Configuration _config; - private readonly CollectionCombo _collectionCombo; + private readonly CollectionCombo _collectionCombo; + private readonly ClientState _clientState; public ModsTab(ModManager modManager, CollectionManager collectionManager, ModFileSystemSelector selector, ModPanel panel, - TutorialService tutorial, RedrawService redrawService, Configuration config) + TutorialService tutorial, RedrawService redrawService, Configuration config, ClientState clientState) { _modManager = modManager; _activeCollections = collectionManager.Active; @@ -41,6 +43,7 @@ public class ModsTab : ITab _tutorial = tutorial; _redrawService = redrawService; _config = config; + _clientState = clientState; _collectionCombo = new CollectionCombo(collectionManager, () => collectionManager.Storage.OrderBy(c => c.Name).ToList()); } @@ -56,7 +59,7 @@ public class ModsTab : ITab public Mod SelectMod { set => _selector.SelectByValue(value); - } + } public void DrawContent() { @@ -148,7 +151,7 @@ public class ModsTab : ITab ImGuiUtil.HoverTooltip(lower.Length > 0 ? $"Execute '/penumbra redraw {lower}'." : $"Execute '/penumbra redraw'."); } - using var disabled = ImRaii.Disabled(DalamudServices.SClientState.LocalPlayer == null); + using var disabled = ImRaii.Disabled(_clientState.LocalPlayer == null); ImGui.SameLine(); var buttonWidth = frameHeight with { X = ImGui.GetContentRegionAvail().X / 4 }; DrawButton(buttonWidth, "All", string.Empty); diff --git a/Penumbra/UI/Tabs/SettingsTab.cs b/Penumbra/UI/Tabs/SettingsTab.cs index 0da6a407..029e03cd 100644 --- a/Penumbra/UI/Tabs/SettingsTab.cs +++ b/Penumbra/UI/Tabs/SettingsTab.cs @@ -10,12 +10,10 @@ using OtterGui; using OtterGui.Raii; using OtterGui.Widgets; using Penumbra.Interop.Services; -using Penumbra.Mods; using Penumbra.Mods.Manager; using Penumbra.Services; using Penumbra.UI.Classes; -using CharacterUtility = Penumbra.Interop.Services.CharacterUtility; -using ModFileSystemSelector = Penumbra.UI.ModsTab.ModFileSystemSelector; +using Penumbra.UI.ModsTab; namespace Penumbra.UI.Tabs; @@ -104,7 +102,7 @@ public class SettingsTab : ITab /// Do not change the directory without explicitly pressing enter or this button. /// Shows up only if the current input does not correspond to the current directory. /// - private static bool DrawPressEnterWarning(string newName, string old, float width, bool saved, bool selected) + private bool DrawPressEnterWarning(string newName, string old, float width, bool saved, bool selected) { using var color = ImRaii.PushColor(ImGuiCol.Button, Colors.PressEnterWarningBg); var w = new Vector2(width, 0); @@ -114,7 +112,7 @@ public class SettingsTab : ITab } /// Check a potential new root directory for validity and return the button text and whether it is valid. - private static (string Text, bool Valid) CheckRootDirectoryPath(string newName, string old, bool selected) + private (string Text, bool Valid) CheckRootDirectoryPath(string newName, string old, bool selected) { static bool IsSubPathOf(string basePath, string subPath) { @@ -140,14 +138,14 @@ public class SettingsTab : ITab if (IsSubPathOf(programFiles, newName) || IsSubPathOf(programFilesX86, newName)) return ("Path is not allowed to be in ProgramFiles.", false); - var dalamud = DalamudServices.PluginInterface.ConfigDirectory.Parent!.Parent!; + var dalamud = _dalamud.PluginInterface.ConfigDirectory.Parent!.Parent!; if (IsSubPathOf(dalamud.FullName, newName)) return ("Path is not allowed to be inside your Dalamud directories.", false); if (Functions.GetDownloadsFolder(out var downloads) && IsSubPathOf(downloads, newName)) return ("Path is not allowed to be inside your Downloads folder.", false); - var gameDir = DalamudServices.SGameData.GameData.DataPath.Parent!.Parent!.FullName; + var gameDir = _dalamud.GameData.GameData.DataPath.Parent!.Parent!.FullName; if (IsSubPathOf(gameDir, newName)) return ("Path is not allowed to be inside your game folder.", false);