mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-14 12:44:19 +01:00
Add counts to multi mod selection.
This commit is contained in:
parent
415e15f3b1
commit
82689467aa
1 changed files with 56 additions and 34 deletions
|
|
@ -4,65 +4,88 @@ using ImGuiNET;
|
||||||
using OtterGui;
|
using OtterGui;
|
||||||
using OtterGui.Raii;
|
using OtterGui.Raii;
|
||||||
using OtterGui.Services;
|
using OtterGui.Services;
|
||||||
|
using OtterGui.Text;
|
||||||
using Penumbra.Mods;
|
using Penumbra.Mods;
|
||||||
using Penumbra.Mods.Manager;
|
using Penumbra.Mods.Manager;
|
||||||
|
|
||||||
namespace Penumbra.UI.ModsTab;
|
namespace Penumbra.UI.ModsTab;
|
||||||
|
|
||||||
public class MultiModPanel(ModFileSystemSelector _selector, ModDataEditor _editor) : IUiService
|
public class MultiModPanel(ModFileSystemSelector selector, ModDataEditor editor) : IUiService
|
||||||
{
|
{
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
if (_selector.SelectedPaths.Count == 0)
|
if (selector.SelectedPaths.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ImGui.NewLine();
|
ImGui.NewLine();
|
||||||
DrawModList();
|
var treeNodePos = ImGui.GetCursorPos();
|
||||||
|
var numLeaves = DrawModList();
|
||||||
|
DrawCounts(treeNodePos, numLeaves);
|
||||||
DrawMultiTagger();
|
DrawMultiTagger();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawModList()
|
private void DrawCounts(Vector2 treeNodePos, int numLeaves)
|
||||||
{
|
{
|
||||||
using var tree = ImRaii.TreeNode("Currently Selected Objects", ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.NoTreePushOnOpen);
|
var startPos = ImGui.GetCursorPos();
|
||||||
ImGui.Separator();
|
var numFolders = selector.SelectedPaths.Count - numLeaves;
|
||||||
if (!tree)
|
var text = (numLeaves, numFolders) switch
|
||||||
return;
|
{
|
||||||
|
(0, 0) => string.Empty, // should not happen
|
||||||
|
(> 0, 0) => $"{numLeaves} Mods",
|
||||||
|
(0, > 0) => $"{numFolders} Folders",
|
||||||
|
_ => $"{numLeaves} Mods, {numFolders} Folders",
|
||||||
|
};
|
||||||
|
ImGui.SetCursorPos(treeNodePos);
|
||||||
|
ImUtf8.TextRightAligned(text);
|
||||||
|
ImGui.SetCursorPos(startPos);
|
||||||
|
}
|
||||||
|
|
||||||
var sizeType = ImGui.GetFrameHeight();
|
private int DrawModList()
|
||||||
var availableSizePercent = (ImGui.GetContentRegionAvail().X - sizeType - 4 * ImGui.GetStyle().CellPadding.X) / 100;
|
{
|
||||||
|
using var tree = ImUtf8.TreeNode("Currently Selected Objects###Selected"u8,
|
||||||
|
ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.NoTreePushOnOpen);
|
||||||
|
ImGui.Separator();
|
||||||
|
|
||||||
|
|
||||||
|
if (!tree)
|
||||||
|
return selector.SelectedPaths.Count(l => l is ModFileSystem.Leaf);
|
||||||
|
|
||||||
|
var sizeType = new Vector2(ImGui.GetFrameHeight());
|
||||||
|
var availableSizePercent = (ImGui.GetContentRegionAvail().X - sizeType.X - 4 * ImGui.GetStyle().CellPadding.X) / 100;
|
||||||
var sizeMods = availableSizePercent * 35;
|
var sizeMods = availableSizePercent * 35;
|
||||||
var sizeFolders = availableSizePercent * 65;
|
var sizeFolders = availableSizePercent * 65;
|
||||||
|
|
||||||
using (var table = ImRaii.Table("mods", 3, ImGuiTableFlags.RowBg))
|
var leaves = 0;
|
||||||
|
using (var table = ImUtf8.Table("mods"u8, 3, ImGuiTableFlags.RowBg))
|
||||||
{
|
{
|
||||||
if (!table)
|
if (!table)
|
||||||
return;
|
return selector.SelectedPaths.Count(l => l is ModFileSystem.Leaf);
|
||||||
|
|
||||||
ImGui.TableSetupColumn("type", ImGuiTableColumnFlags.WidthFixed, sizeType);
|
ImUtf8.TableSetupColumn("type"u8, ImGuiTableColumnFlags.WidthFixed, sizeType.X);
|
||||||
ImGui.TableSetupColumn("mod", ImGuiTableColumnFlags.WidthFixed, sizeMods);
|
ImUtf8.TableSetupColumn("mod"u8, ImGuiTableColumnFlags.WidthFixed, sizeMods);
|
||||||
ImGui.TableSetupColumn("path", ImGuiTableColumnFlags.WidthFixed, sizeFolders);
|
ImUtf8.TableSetupColumn("path"u8, ImGuiTableColumnFlags.WidthFixed, sizeFolders);
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
foreach (var (fullName, path) in _selector.SelectedPaths.Select(p => (p.FullName(), p))
|
foreach (var (fullName, path) in selector.SelectedPaths.Select(p => (p.FullName(), p))
|
||||||
.OrderBy(p => p.Item1, StringComparer.OrdinalIgnoreCase))
|
.OrderBy(p => p.Item1, StringComparer.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
using var id = ImRaii.PushId(i++);
|
using var id = ImRaii.PushId(i++);
|
||||||
|
var (icon, text) = path is ModFileSystem.Leaf l
|
||||||
|
? (FontAwesomeIcon.FileCircleMinus, l.Value.Name.Text)
|
||||||
|
: (FontAwesomeIcon.FolderMinus, string.Empty);
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
var icon = (path is ModFileSystem.Leaf ? FontAwesomeIcon.FileCircleMinus : FontAwesomeIcon.FolderMinus).ToIconString();
|
if (ImUtf8.IconButton(icon, "Remove from selection."u8, sizeType))
|
||||||
if (ImGuiUtil.DrawDisabledButton(icon, new Vector2(sizeType), "Remove from selection.", false, true))
|
selector.RemovePathFromMultiSelection(path);
|
||||||
_selector.RemovePathFromMultiSelection(path);
|
|
||||||
|
|
||||||
ImGui.TableNextColumn();
|
ImUtf8.DrawFrameColumn(text);
|
||||||
ImGui.AlignTextToFramePadding();
|
ImUtf8.DrawFrameColumn(fullName);
|
||||||
ImGui.TextUnformatted(path is ModFileSystem.Leaf l ? l.Value.Name : string.Empty);
|
if (path is ModFileSystem.Leaf)
|
||||||
|
++leaves;
|
||||||
ImGui.TableNextColumn();
|
|
||||||
ImGui.AlignTextToFramePadding();
|
|
||||||
ImGui.TextUnformatted(fullName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
|
return leaves;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string _tag = string.Empty;
|
private string _tag = string.Empty;
|
||||||
|
|
@ -72,11 +95,10 @@ public class MultiModPanel(ModFileSystemSelector _selector, ModDataEditor _edito
|
||||||
private void DrawMultiTagger()
|
private void DrawMultiTagger()
|
||||||
{
|
{
|
||||||
var width = ImGuiHelpers.ScaledVector2(150, 0);
|
var width = ImGuiHelpers.ScaledVector2(150, 0);
|
||||||
ImGui.AlignTextToFramePadding();
|
ImUtf8.TextFrameAligned("Multi Tagger:"u8);
|
||||||
ImGui.TextUnformatted("Multi Tagger:");
|
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X - 2 * (width.X + ImGui.GetStyle().ItemSpacing.X));
|
ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X - 2 * (width.X + ImGui.GetStyle().ItemSpacing.X));
|
||||||
ImGui.InputTextWithHint("##tag", "Local Tag Name...", ref _tag, 128);
|
ImUtf8.InputText("##tag"u8, ref _tag, "Local Tag Name..."u8);
|
||||||
|
|
||||||
UpdateTagCache();
|
UpdateTagCache();
|
||||||
var label = _addMods.Count > 0
|
var label = _addMods.Count > 0
|
||||||
|
|
@ -88,9 +110,9 @@ public class MultiModPanel(ModFileSystemSelector _selector, ModDataEditor _edito
|
||||||
: $"All mods selected already contain the tag \"{_tag}\", either locally or as mod data."
|
: $"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))}";
|
: $"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();
|
ImGui.SameLine();
|
||||||
if (ImGuiUtil.DrawDisabledButton(label, width, tooltip, _addMods.Count == 0))
|
if (ImUtf8.ButtonEx(label, tooltip, width, _addMods.Count == 0))
|
||||||
foreach (var mod in _addMods)
|
foreach (var mod in _addMods)
|
||||||
_editor.ChangeLocalTag(mod, mod.LocalTags.Count, _tag);
|
editor.ChangeLocalTag(mod, mod.LocalTags.Count, _tag);
|
||||||
|
|
||||||
label = _removeMods.Count > 0
|
label = _removeMods.Count > 0
|
||||||
? $"Remove from {_removeMods.Count} Mods"
|
? $"Remove from {_removeMods.Count} Mods"
|
||||||
|
|
@ -101,9 +123,9 @@ public class MultiModPanel(ModFileSystemSelector _selector, ModDataEditor _edito
|
||||||
: $"No selected mod contains the tag \"{_tag}\" locally."
|
: $"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))}";
|
: $"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();
|
ImGui.SameLine();
|
||||||
if (ImGuiUtil.DrawDisabledButton(label, width, tooltip, _removeMods.Count == 0))
|
if (ImUtf8.ButtonEx(label, tooltip, width, _removeMods.Count == 0))
|
||||||
foreach (var (mod, index) in _removeMods)
|
foreach (var (mod, index) in _removeMods)
|
||||||
_editor.ChangeLocalTag(mod, index, string.Empty);
|
editor.ChangeLocalTag(mod, index, string.Empty);
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +136,7 @@ public class MultiModPanel(ModFileSystemSelector _selector, ModDataEditor _edito
|
||||||
if (_tag.Length == 0)
|
if (_tag.Length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var leaf in _selector.SelectedPaths.OfType<ModFileSystem.Leaf>())
|
foreach (var leaf in selector.SelectedPaths.OfType<ModFileSystem.Leaf>())
|
||||||
{
|
{
|
||||||
var index = leaf.Value.LocalTags.IndexOf(_tag);
|
var index = leaf.Value.LocalTags.IndexOf(_tag);
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue