Make everything services.

This commit is contained in:
Ottermandias 2024-06-18 21:59:04 +02:00
parent cf1dcfcb7c
commit e05dbe9885
81 changed files with 220 additions and 317 deletions

View file

@ -8,6 +8,7 @@ using OtterGui.Classes;
using OtterGui.Filesystem;
using OtterGui.FileSystem.Selector;
using OtterGui.Raii;
using OtterGui.Services;
using Penumbra.Api.Enums;
using Penumbra.Collections;
using Penumbra.Collections.Manager;
@ -21,7 +22,7 @@ using MessageService = Penumbra.Services.MessageService;
namespace Penumbra.UI.ModsTab;
public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSystemSelector.ModState>
public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSystemSelector.ModState>, IUiService
{
private readonly CommunicatorService _communicator;
private readonly MessageService _messager;
@ -33,9 +34,9 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
private readonly ModImportManager _modImportManager;
private readonly IDragDropManager _dragDrop;
private readonly ModSearchStringSplitter Filter = new();
public ModSettings SelectedSettings { get; private set; } = ModSettings.Empty;
public ModCollection SelectedSettingCollection { get; private set; } = ModCollection.Empty;
public ModSettings SelectedSettings { get; private set; } = ModSettings.Empty;
public ModCollection SelectedSettingCollection { get; private set; } = ModCollection.Empty;
public ModFileSystemSelector(IKeyState keyState, CommunicatorService communicator, ModFileSystem fileSystem, ModManager modManager,

View file

@ -1,13 +1,14 @@
using Dalamud.Interface.Utility.Raii;
using Dalamud.Plugin;
using ImGuiNET;
using OtterGui.Services;
using Penumbra.Mods;
using Penumbra.Services;
using Penumbra.UI.AdvancedWindow;
namespace Penumbra.UI.ModsTab;
public class ModPanel : IDisposable
public class ModPanel : IDisposable, IUiService
{
private readonly MultiModPanel _multiModPanel;
private readonly ModFileSystemSelector _selector;

View file

@ -2,39 +2,29 @@ using ImGuiNET;
using OtterGui;
using OtterGui.Classes;
using OtterGui.Raii;
using OtterGui.Services;
using OtterGui.Widgets;
namespace Penumbra.UI.ModsTab;
public class ModPanelChangedItemsTab : ITab
public class ModPanelChangedItemsTab(ModFileSystemSelector selector, ChangedItemDrawer drawer) : ITab, IUiService
{
private readonly ModFileSystemSelector _selector;
private readonly ChangedItemDrawer _drawer;
private ChangedItemDrawer.ChangedItemIcon _filter = Enum.GetValues<ChangedItemDrawer.ChangedItemIcon>().Aggregate((a, b) => a | b);
public ReadOnlySpan<byte> Label
=> "Changed Items"u8;
public ModPanelChangedItemsTab(ModFileSystemSelector selector, ChangedItemDrawer drawer)
{
_selector = selector;
_drawer = drawer;
}
public bool IsVisible
=> _selector.Selected!.ChangedItems.Count > 0;
=> selector.Selected!.ChangedItems.Count > 0;
public void DrawContent()
{
_drawer.DrawTypeFilter();
drawer.DrawTypeFilter();
ImGui.Separator();
using var table = ImRaii.Table("##changedItems", 1, ImGuiTableFlags.RowBg | ImGuiTableFlags.ScrollY,
new Vector2(ImGui.GetContentRegionAvail().X, -1));
if (!table)
return;
var zipList = ZipList.FromSortedList((SortedList<string, object?>)_selector.Selected!.ChangedItems);
var zipList = ZipList.FromSortedList((SortedList<string, object?>)selector.Selected!.ChangedItems);
var height = ImGui.GetFrameHeightWithSpacing();
ImGui.TableNextColumn();
var skips = ImGuiClip.GetNecessarySkips(height);
@ -43,14 +33,14 @@ public class ModPanelChangedItemsTab : ITab
}
private bool CheckFilter((string Name, object? Data) kvp)
=> _drawer.FilterChangedItem(kvp.Name, kvp.Data, LowerString.Empty);
=> drawer.FilterChangedItem(kvp.Name, kvp.Data, LowerString.Empty);
private void DrawChangedItem((string Name, object? Data) kvp)
{
ImGui.TableNextColumn();
_drawer.DrawCategoryIcon(kvp.Name, kvp.Data);
drawer.DrawCategoryIcon(kvp.Name, kvp.Data);
ImGui.SameLine();
_drawer.DrawChangedItem(kvp.Name, kvp.Data);
_drawer.DrawModelData(kvp.Data);
drawer.DrawChangedItem(kvp.Name, kvp.Data);
drawer.DrawModelData(kvp.Data);
}
}

View file

@ -2,6 +2,7 @@ using Dalamud.Interface.Utility;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using OtterGui.Services;
using OtterGui.Widgets;
using Penumbra.Collections;
using Penumbra.Collections.Manager;
@ -10,25 +11,16 @@ using Penumbra.UI.Classes;
namespace Penumbra.UI.ModsTab;
public class ModPanelCollectionsTab : ITab
public class ModPanelCollectionsTab(CollectionStorage storage, ModFileSystemSelector selector) : ITab, IUiService
{
private readonly ModFileSystemSelector _selector;
private readonly CollectionStorage _collections;
private readonly List<(ModCollection, ModCollection, uint, string)> _cache = new();
public ModPanelCollectionsTab(CollectionStorage storage, ModFileSystemSelector selector)
{
_collections = storage;
_selector = selector;
}
private readonly List<(ModCollection, ModCollection, uint, string)> _cache = [];
public ReadOnlySpan<byte> Label
=> "Collections"u8;
public void DrawContent()
{
var (direct, inherited) = CountUsage(_selector.Selected!);
var (direct, inherited) = CountUsage(selector.Selected!);
ImGui.NewLine();
if (direct == 1)
ImGui.TextUnformatted("This Mod is directly configured in 1 collection.");
@ -80,7 +72,7 @@ public class ModPanelCollectionsTab : ITab
var disInherited = ColorId.InheritedDisabledMod.Value();
var directCount = 0;
var inheritedCount = 0;
foreach (var collection in _collections)
foreach (var collection in storage)
{
var (settings, parent) = collection[mod.Index];
var (color, text) = settings == null

View file

@ -3,6 +3,7 @@ using Dalamud.Interface.Utility;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using OtterGui.Services;
using OtterGui.Text;
using OtterGui.Widgets;
using Penumbra.Collections.Cache;
@ -16,7 +17,7 @@ using Penumbra.UI.Classes;
namespace Penumbra.UI.ModsTab;
public class ModPanelConflictsTab(CollectionManager collectionManager, ModFileSystemSelector selector) : ITab
public class ModPanelConflictsTab(CollectionManager collectionManager, ModFileSystemSelector selector) : ITab, IUiService
{
private int? _currentPriority;

View file

@ -2,6 +2,7 @@ using Dalamud.Interface.Utility;
using ImGuiNET;
using OtterGui.Raii;
using OtterGui;
using OtterGui.Services;
using OtterGui.Widgets;
using Penumbra.Mods.Manager;
@ -12,7 +13,7 @@ public class ModPanelDescriptionTab(
TutorialService tutorial,
ModManager modManager,
PredefinedTagManager predefinedTagsConfig)
: ITab
: ITab, IUiService
{
private readonly TagButtons _localTags = new();
private readonly TagButtons _modTags = new();

View file

@ -6,13 +6,13 @@ using OtterGui;
using OtterGui.Raii;
using OtterGui.Widgets;
using OtterGui.Classes;
using OtterGui.Services;
using Penumbra.Mods;
using Penumbra.Mods.Editor;
using Penumbra.Mods.Manager;
using Penumbra.Services;
using Penumbra.UI.AdvancedWindow;
using Penumbra.Mods.Settings;
using Penumbra.Mods.Manager.OptionEditor;
using Penumbra.UI.ModsTab.Groups;
namespace Penumbra.UI.ModsTab;
@ -31,7 +31,7 @@ public class ModPanelEditTab(
ModGroupEditDrawer groupEditDrawer,
DescriptionEditPopup descriptionPopup,
AddGroupDrawer addGroupDrawer)
: ITab
: ITab, IUiService
{
private readonly TagButtons _modTags = new();

View file

@ -2,6 +2,7 @@ using Dalamud.Interface;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using OtterGui.Services;
using OtterGui.Widgets;
using Penumbra.Mods;
using Penumbra.Mods.Manager;
@ -9,7 +10,7 @@ using Penumbra.UI.AdvancedWindow;
namespace Penumbra.UI.ModsTab;
public class ModPanelTabBar
public class ModPanelTabBar : IUiService
{
private enum ModPanelTabType
{
@ -33,7 +34,7 @@ public class ModPanelTabBar
public readonly ITab[] Tabs;
private ModPanelTabType _preferredTab = ModPanelTabType.Settings;
private Mod? _lastMod = null;
private Mod? _lastMod;
public ModPanelTabBar(ModEditWindow modEditWindow, ModPanelSettingsTab settings, ModPanelDescriptionTab description,
ModPanelConflictsTab conflicts, ModPanelChangedItemsTab changedItems, ModPanelEditTab edit, ModManager modManager,
@ -49,15 +50,15 @@ public class ModPanelTabBar
_tutorial = tutorial;
Collections = collections;
Tabs = new ITab[]
{
Tabs =
[
Settings,
Description,
Conflicts,
ChangedItems,
Collections,
Edit,
};
];
}
public void Draw(Mod mod)

View file

@ -3,12 +3,13 @@ using Dalamud.Interface.Utility;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using OtterGui.Services;
using Penumbra.Mods;
using Penumbra.Mods.Manager;
namespace Penumbra.UI.ModsTab;
public class MultiModPanel(ModFileSystemSelector _selector, ModDataEditor _editor)
public class MultiModPanel(ModFileSystemSelector _selector, ModDataEditor _editor) : IUiService
{
public void Draw()
{
@ -65,8 +66,8 @@ public class MultiModPanel(ModFileSystemSelector _selector, ModDataEditor _edito
}
private string _tag = string.Empty;
private readonly List<Mod> _addMods = [];
private readonly List<(Mod, int)> _removeMods = [];
private readonly List<Mod> _addMods = [];
private readonly List<(Mod, int)> _removeMods = [];
private void DrawMultiTagger()
{