Skip to content

Commit

Permalink
Improve Multi Mod selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Nov 18, 2023
1 parent 3e69670 commit 85500f0
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 66 deletions.
28 changes: 8 additions & 20 deletions Penumbra/Services/FilenameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,15 @@

namespace Penumbra.Services;

public class FilenameService
public class FilenameService(DalamudPluginInterface pi)
{
public readonly string ConfigDirectory;
public readonly string CollectionDirectory;
public readonly string LocalDataDirectory;
public readonly string ConfigFile;
public readonly string EphemeralConfigFile;
public readonly string FilesystemFile;
public readonly string ActiveCollectionsFile;

public FilenameService(DalamudPluginInterface pi)
{
ConfigDirectory = pi.ConfigDirectory.FullName;
CollectionDirectory = Path.Combine(pi.ConfigDirectory.FullName, "collections");
LocalDataDirectory = Path.Combine(pi.ConfigDirectory.FullName, "mod_data");
ConfigFile = pi.ConfigFile.FullName;
FilesystemFile = Path.Combine(pi.ConfigDirectory.FullName, "sort_order.json");
ActiveCollectionsFile = Path.Combine(pi.ConfigDirectory.FullName, "active_collections.json");
EphemeralConfigFile = Path.Combine(pi.ConfigDirectory.FullName, "ephemeral_config.json");
}
public readonly string ConfigDirectory = pi.ConfigDirectory.FullName;
public readonly string CollectionDirectory = Path.Combine(pi.ConfigDirectory.FullName, "collections");
public readonly string LocalDataDirectory = Path.Combine(pi.ConfigDirectory.FullName, "mod_data");
public readonly string ConfigFile = pi.ConfigFile.FullName;
public readonly string EphemeralConfigFile = Path.Combine(pi.ConfigDirectory.FullName, "ephemeral_config.json");
public readonly string FilesystemFile = Path.Combine(pi.ConfigDirectory.FullName, "sort_order.json");
public readonly string ActiveCollectionsFile = Path.Combine(pi.ConfigDirectory.FullName, "active_collections.json");

/// <summary> Obtain the path of a collection file given its name.</summary>
public string CollectionFile(ModCollection collection)
Expand All @@ -34,7 +23,6 @@ public string CollectionFile(ModCollection collection)
public string CollectionFile(string collectionName)
=> Path.Combine(CollectionDirectory, $"{collectionName}.json");


/// <summary> Obtain the path of the local data file given a mod directory. Returns an empty string if the mod is temporary. </summary>
public string LocalDataFile(Mod mod)
=> LocalDataFile(mod.ModPath.FullName);
Expand Down
1 change: 1 addition & 0 deletions Penumbra/Services/ServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ private static IServiceCollection AddInterface(this IServiceCollection services)
.AddSingleton<CommandHandler>()
.AddSingleton<SettingsTab>()
.AddSingleton<ModsTab>()
.AddSingleton<MultiModPanel>()
.AddSingleton<ModPanel>()
.AddSingleton<ModFileSystemSelector>()
.AddSingleton<CollectionSelectHeader>()
Expand Down
51 changes: 5 additions & 46 deletions Penumbra/UI/ModsTab/ModPanel.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
using Dalamud.Interface;
using Dalamud.Plugin;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using Penumbra.Mods;
using Penumbra.Mods.Manager;
using Penumbra.UI.AdvancedWindow;

namespace Penumbra.UI.ModsTab;

public class ModPanel : IDisposable
{
private readonly MultiModPanel _multiModPanel;
private readonly ModFileSystemSelector _selector;
private readonly ModEditWindow _editWindow;
private readonly ModPanelHeader _header;
private readonly ModPanelTabBar _tabs;

public ModPanel(DalamudPluginInterface pi, ModFileSystemSelector selector, ModEditWindow editWindow, ModPanelTabBar tabs)
public ModPanel(DalamudPluginInterface pi, ModFileSystemSelector selector, ModEditWindow editWindow, ModPanelTabBar tabs,
MultiModPanel multiModPanel)
{
_selector = selector;
_editWindow = editWindow;
_tabs = tabs;
_multiModPanel = multiModPanel;
_header = new ModPanelHeader(pi);
_selector.SelectionChanged += OnSelectionChange;
}
Expand All @@ -29,7 +27,7 @@ public void Draw()
{
if (!_valid)
{
DrawMultiSelection();
_multiModPanel.Draw();
return;
}

Expand All @@ -43,45 +41,6 @@ public void Dispose()
_header.Dispose();
}

private void DrawMultiSelection()
{
if (_selector.SelectedPaths.Count == 0)
return;

var sizeType = ImGui.GetFrameHeight();
var availableSizePercent = (ImGui.GetContentRegionAvail().X - sizeType - 4 * ImGui.GetStyle().CellPadding.X) / 100;
var sizeMods = availableSizePercent * 35;
var sizeFolders = availableSizePercent * 65;

ImGui.NewLine();
ImGui.TextUnformatted("Currently Selected Objects");
ImGui.Separator();
using var table = ImRaii.Table("mods", 3, ImGuiTableFlags.RowBg);
ImGui.TableSetupColumn("type", ImGuiTableColumnFlags.WidthFixed, sizeType);
ImGui.TableSetupColumn("mod", ImGuiTableColumnFlags.WidthFixed, sizeMods);
ImGui.TableSetupColumn("path", ImGuiTableColumnFlags.WidthFixed, sizeFolders);

var i = 0;
foreach (var (fullName, path) in _selector.SelectedPaths.Select(p => (p.FullName(), p))
.OrderBy(p => p.Item1, StringComparer.OrdinalIgnoreCase))
{
using var id = ImRaii.PushId(i++);
ImGui.TableNextColumn();
var icon = (path is ModFileSystem.Leaf ? FontAwesomeIcon.FileCircleMinus : FontAwesomeIcon.FolderMinus).ToIconString();
if (ImGuiUtil.DrawDisabledButton(icon, new Vector2(sizeType), "Remove from selection.", false, true))
_selector.RemovePathFromMultiselection(path);

ImGui.TableNextColumn();
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted(path is ModFileSystem.Leaf l ? l.Value.Name : string.Empty);

ImGui.TableNextColumn();
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted(fullName);
}
}


private bool _valid;
private Mod _mod = null!;

Expand Down
125 changes: 125 additions & 0 deletions Penumbra/UI/ModsTab/MultiModPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using Dalamud.Interface;
using Dalamud.Interface.Utility;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using Penumbra.Mods;
using Penumbra.Mods.Manager;

namespace Penumbra.UI.ModsTab;

public class MultiModPanel(ModFileSystemSelector _selector, ModDataEditor _editor)
{
public void Draw()
{
if (_selector.SelectedPaths.Count == 0)
return;

ImGui.NewLine();
DrawModList();
DrawMultiTagger();
}

private void DrawModList()
{
using var tree = ImRaii.TreeNode("Currently Selected Objects", ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.NoTreePushOnOpen);
ImGui.Separator();
if (!tree)
return;

var sizeType = ImGui.GetFrameHeight();
var availableSizePercent = (ImGui.GetContentRegionAvail().X - sizeType - 4 * ImGui.GetStyle().CellPadding.X) / 100;
var sizeMods = availableSizePercent * 35;
var sizeFolders = availableSizePercent * 65;

using (var table = ImRaii.Table("mods", 3, ImGuiTableFlags.RowBg))
{
if (!table)
return;

ImGui.TableSetupColumn("type", ImGuiTableColumnFlags.WidthFixed, sizeType);
ImGui.TableSetupColumn("mod", ImGuiTableColumnFlags.WidthFixed, sizeMods);
ImGui.TableSetupColumn("path", ImGuiTableColumnFlags.WidthFixed, sizeFolders);

var i = 0;
foreach (var (fullName, path) in _selector.SelectedPaths.Select(p => (p.FullName(), p))
.OrderBy(p => p.Item1, StringComparer.OrdinalIgnoreCase))
{
using var id = ImRaii.PushId(i++);
ImGui.TableNextColumn();
var icon = (path is ModFileSystem.Leaf ? FontAwesomeIcon.FileCircleMinus : FontAwesomeIcon.FolderMinus).ToIconString();
if (ImGuiUtil.DrawDisabledButton(icon, new Vector2(sizeType), "Remove from selection.", false, true))
_selector.RemovePathFromMultiselection(path);

ImGui.TableNextColumn();
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted(path is ModFileSystem.Leaf l ? l.Value.Name : string.Empty);

ImGui.TableNextColumn();
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted(fullName);
}
}

ImGui.Separator();
}

private string _tag = string.Empty;
private readonly List<Mod> _addMods = [];
private readonly List<(Mod, int)> _removeMods = [];

private void DrawMultiTagger()
{
var width = ImGuiHelpers.ScaledVector2(150, 0);
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted("Multi Tagger:");
ImGui.SameLine();
ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X - 2 * (width.X + ImGui.GetStyle().ItemSpacing.X));
ImGui.InputTextWithHint("##tag", "Local Tag Name...", ref _tag, 128);

UpdateTagCache();
var label = _addMods.Count > 0
? $"Add to {_addMods.Count} Mods"
: "Add";
var tooltip = _addMods.Count == 0
? _tag.Length == 0
? "No tag specified."
: $"All mods selected already contain the tag \"{_tag}\", either locally or as mod data."
: $"Add the tag \"{_tag}\" to {_addMods.Count} mods as a local tag:\n\n\t{string.Join("\n\t", _addMods.Select(m => m.Name.Text))}";
ImGui.SameLine();
if (ImGuiUtil.DrawDisabledButton(label, width, tooltip, _addMods.Count == 0))
foreach (var mod in _addMods)
_editor.ChangeLocalTag(mod, mod.LocalTags.Count, _tag);

label = _removeMods.Count > 0
? $"Remove from {_removeMods.Count} Mods"
: "Remove";
tooltip = _removeMods.Count == 0
? _tag.Length == 0
? "No tag specified."
: $"No selected mod contains the tag \"{_tag}\" locally."
: $"Remove the local tag \"{_tag}\" from {_removeMods.Count} mods:\n\n\t{string.Join("\n\t", _removeMods.Select(m => m.Item1.Name.Text))}";
ImGui.SameLine();
if (ImGuiUtil.DrawDisabledButton(label, width, tooltip, _removeMods.Count == 0))
foreach (var (mod, index) in _removeMods)
_editor.ChangeLocalTag(mod, index, string.Empty);
ImGui.Separator();
}

private void UpdateTagCache()
{
_addMods.Clear();
_removeMods.Clear();
if (_tag.Length == 0)
return;

foreach (var leaf in _selector.SelectedPaths.OfType<ModFileSystem.Leaf>())
{
var index = leaf.Value.LocalTags.IndexOf(_tag);
if (index >= 0)
_removeMods.Add((leaf.Value, index));
else if (!leaf.Value.ModTags.Contains(_tag))
_addMods.Add(leaf.Value);
}
}
}

0 comments on commit 85500f0

Please sign in to comment.