mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 18:27:24 +01:00
Add counts to multi design selection.
This commit is contained in:
parent
02bfd17794
commit
c83ddf054a
1 changed files with 64 additions and 51 deletions
|
|
@ -3,79 +3,95 @@ using Dalamud.Interface.Utility;
|
|||
using Glamourer.Designs;
|
||||
using ImGuiNET;
|
||||
using OtterGui;
|
||||
using OtterGui.Filesystem;
|
||||
using OtterGui.Raii;
|
||||
using OtterGui.Text;
|
||||
|
||||
namespace Glamourer.Gui.Tabs.DesignTab;
|
||||
|
||||
public class MultiDesignPanel(DesignFileSystemSelector _selector, DesignManager _editor, DesignColors _colors)
|
||||
public class MultiDesignPanel(DesignFileSystemSelector selector, DesignManager editor, DesignColors colors)
|
||||
{
|
||||
private readonly DesignColorCombo _colorCombo = new(_colors, true);
|
||||
private readonly DesignColorCombo _colorCombo = new(colors, true);
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
if (_selector.SelectedPaths.Count == 0)
|
||||
if (selector.SelectedPaths.Count == 0)
|
||||
return;
|
||||
|
||||
var width = ImGuiHelpers.ScaledVector2(145, 0);
|
||||
ImGui.NewLine();
|
||||
DrawDesignList();
|
||||
var treeNodePos = ImGui.GetCursorPos();
|
||||
_numDesigns = DrawDesignList();
|
||||
DrawCounts(treeNodePos);
|
||||
var offset = DrawMultiTagger(width);
|
||||
DrawMultiColor(width, offset);
|
||||
DrawMultiQuickDesignBar(offset);
|
||||
}
|
||||
|
||||
private void DrawDesignList()
|
||||
private void DrawCounts(Vector2 treeNodePos)
|
||||
{
|
||||
using var tree = ImRaii.TreeNode("Currently Selected Objects", ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.NoTreePushOnOpen);
|
||||
var startPos = ImGui.GetCursorPos();
|
||||
var numFolders = selector.SelectedPaths.Count - _numDesigns;
|
||||
var text = (_numDesigns, numFolders) switch
|
||||
{
|
||||
(0, 0) => string.Empty, // should not happen
|
||||
(> 0, 0) => $"{_numDesigns} Designs",
|
||||
(0, > 0) => $"{numFolders} Folders",
|
||||
_ => $"{_numDesigns} Designs, {numFolders} Folders",
|
||||
};
|
||||
ImGui.SetCursorPos(treeNodePos);
|
||||
ImUtf8.TextRightAligned(text);
|
||||
ImGui.SetCursorPos(startPos);
|
||||
}
|
||||
|
||||
private int DrawDesignList()
|
||||
{
|
||||
using var tree = ImUtf8.TreeNode("Currently Selected Objects"u8, ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.NoTreePushOnOpen);
|
||||
ImGui.Separator();
|
||||
if (!tree)
|
||||
return;
|
||||
return selector.SelectedPaths.Count(l => l is DesignFileSystem.Leaf);
|
||||
|
||||
var sizeType = ImGui.GetFrameHeight();
|
||||
var availableSizePercent = (ImGui.GetContentRegionAvail().X - sizeType - 4 * ImGui.GetStyle().CellPadding.X) / 100;
|
||||
var sizeType = new Vector2(ImGui.GetFrameHeight());
|
||||
var availableSizePercent = (ImGui.GetContentRegionAvail().X - sizeType.X - 4 * ImGui.GetStyle().CellPadding.X) / 100;
|
||||
var sizeMods = availableSizePercent * 35;
|
||||
var sizeFolders = availableSizePercent * 65;
|
||||
|
||||
_numQuickDesignEnabled = 0;
|
||||
_numDesigns = 0;
|
||||
using (var table = ImRaii.Table("mods", 3, ImGuiTableFlags.RowBg))
|
||||
var numDesigns = 0;
|
||||
using (var table = ImUtf8.Table("mods"u8, 3, ImGuiTableFlags.RowBg))
|
||||
{
|
||||
if (!table)
|
||||
return;
|
||||
return selector.SelectedPaths.Count(l => l is DesignFileSystem.Leaf);
|
||||
|
||||
ImGui.TableSetupColumn("type", ImGuiTableColumnFlags.WidthFixed, sizeType);
|
||||
ImGui.TableSetupColumn("mod", ImGuiTableColumnFlags.WidthFixed, sizeMods);
|
||||
ImGui.TableSetupColumn("path", ImGuiTableColumnFlags.WidthFixed, sizeFolders);
|
||||
ImUtf8.TableSetupColumn("type"u8, ImGuiTableColumnFlags.WidthFixed, sizeType.X);
|
||||
ImUtf8.TableSetupColumn("mod"u8, ImGuiTableColumnFlags.WidthFixed, sizeMods);
|
||||
ImUtf8.TableSetupColumn("path"u8, ImGuiTableColumnFlags.WidthFixed, sizeFolders);
|
||||
|
||||
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))
|
||||
{
|
||||
using var id = ImRaii.PushId(i++);
|
||||
var (icon, text) = path is DesignFileSystem.Leaf l
|
||||
? (FontAwesomeIcon.FileCircleMinus, l.Value.Name.Text)
|
||||
: (FontAwesomeIcon.FolderMinus, string.Empty);
|
||||
ImGui.TableNextColumn();
|
||||
var icon = (path is DesignFileSystem.Leaf ? FontAwesomeIcon.FileCircleMinus : FontAwesomeIcon.FolderMinus).ToIconString();
|
||||
if (ImGuiUtil.DrawDisabledButton(icon, new Vector2(sizeType), "Remove from selection.", false, true))
|
||||
_selector.RemovePathFromMultiSelection(path);
|
||||
if (ImUtf8.IconButton(icon, "Remove from selection."u8, sizeType))
|
||||
selector.RemovePathFromMultiSelection(path);
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted(path is DesignFileSystem.Leaf l ? l.Value.Name : string.Empty);
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted(fullName);
|
||||
ImUtf8.DrawFrameColumn(text);
|
||||
ImUtf8.DrawFrameColumn(fullName);
|
||||
|
||||
if (path is not DesignFileSystem.Leaf l2)
|
||||
continue;
|
||||
|
||||
++_numDesigns;
|
||||
++numDesigns;
|
||||
if (l2.Value.QuickDesign)
|
||||
++_numQuickDesignEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
return numDesigns;
|
||||
}
|
||||
|
||||
private string _tag = string.Empty;
|
||||
|
|
@ -86,12 +102,11 @@ public class MultiDesignPanel(DesignFileSystemSelector _selector, DesignManager
|
|||
|
||||
private float DrawMultiTagger(Vector2 width)
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted("Multi Tagger:");
|
||||
ImUtf8.TextFrameAligned("Multi Tagger:"u8);
|
||||
ImGui.SameLine();
|
||||
var offset = ImGui.GetItemRectSize().X;
|
||||
ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X - 2 * (width.X + ImGui.GetStyle().ItemSpacing.X));
|
||||
ImGui.InputTextWithHint("##tag", "Tag Name...", ref _tag, 128);
|
||||
ImUtf8.InputText("##tag"u8, ref _tag, "Tag Name..."u8);
|
||||
|
||||
UpdateTagCache();
|
||||
var label = _addDesigns.Count > 0
|
||||
|
|
@ -103,9 +118,9 @@ public class MultiDesignPanel(DesignFileSystemSelector _selector, DesignManager
|
|||
: $"All designs selected already contain the tag \"{_tag}\"."
|
||||
: $"Add the tag \"{_tag}\" to {_addDesigns.Count} designs as a local tag:\n\n\t{string.Join("\n\t", _addDesigns.Select(m => m.Name.Text))}";
|
||||
ImGui.SameLine();
|
||||
if (ImGuiUtil.DrawDisabledButton(label, width, tooltip, _addDesigns.Count == 0))
|
||||
if (ImUtf8.ButtonEx(label, tooltip, width, _addDesigns.Count == 0))
|
||||
foreach (var design in _addDesigns)
|
||||
_editor.AddTag(design, _tag);
|
||||
editor.AddTag(design, _tag);
|
||||
|
||||
label = _removeDesigns.Count > 0
|
||||
? $"Remove from {_removeDesigns.Count} Designs"
|
||||
|
|
@ -116,41 +131,39 @@ public class MultiDesignPanel(DesignFileSystemSelector _selector, DesignManager
|
|||
: $"No selected design contains the tag \"{_tag}\" locally."
|
||||
: $"Remove the local tag \"{_tag}\" from {_removeDesigns.Count} designs:\n\n\t{string.Join("\n\t", _removeDesigns.Select(m => m.Item1.Name.Text))}";
|
||||
ImGui.SameLine();
|
||||
if (ImGuiUtil.DrawDisabledButton(label, width, tooltip, _removeDesigns.Count == 0))
|
||||
if (ImUtf8.ButtonEx(label, tooltip, width, _removeDesigns.Count == 0))
|
||||
foreach (var (design, index) in _removeDesigns)
|
||||
_editor.RemoveTag(design, index);
|
||||
editor.RemoveTag(design, index);
|
||||
ImGui.Separator();
|
||||
return offset;
|
||||
}
|
||||
|
||||
private void DrawMultiQuickDesignBar(float offset)
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted("Multi QDB:");
|
||||
ImUtf8.TextFrameAligned("Multi QDB:"u8);
|
||||
ImGui.SameLine(offset, ImGui.GetStyle().ItemSpacing.X);
|
||||
var buttonWidth = new Vector2((ImGui.GetContentRegionAvail().X - ImGui.GetStyle().ItemSpacing.X) / 2, 0);
|
||||
var diff = _numDesigns - _numQuickDesignEnabled;
|
||||
var tt = diff == 0
|
||||
? $"All {_numDesigns} selected designs are already displayed in the quick design bar."
|
||||
: $"Display all {_numDesigns} selected designs in the quick design bar. Changes {diff} designs.";
|
||||
if (ImGuiUtil.DrawDisabledButton("Display Selected Designs in QDB", buttonWidth, tt, diff == 0))
|
||||
foreach(var design in _selector.SelectedPaths.OfType<DesignFileSystem.Leaf>())
|
||||
_editor.SetQuickDesign(design.Value, true);
|
||||
if (ImUtf8.ButtonEx("Display Selected Designs in QDB"u8, tt, buttonWidth, diff == 0))
|
||||
foreach (var design in selector.SelectedPaths.OfType<DesignFileSystem.Leaf>())
|
||||
editor.SetQuickDesign(design.Value, true);
|
||||
|
||||
ImGui.SameLine();
|
||||
tt = _numQuickDesignEnabled == 0
|
||||
? $"All {_numDesigns} selected designs are already hidden in the quick design bar."
|
||||
: $"Hide all {_numDesigns} selected designs in the quick design bar. Changes {_numQuickDesignEnabled} designs.";
|
||||
if (ImGuiUtil.DrawDisabledButton("Hide Selected Designs in QDB", buttonWidth, tt, _numQuickDesignEnabled == 0))
|
||||
foreach (var design in _selector.SelectedPaths.OfType<DesignFileSystem.Leaf>())
|
||||
_editor.SetQuickDesign(design.Value, false);
|
||||
if (ImUtf8.ButtonEx("Hide Selected Designs in QDB"u8, tt, buttonWidth, _numQuickDesignEnabled == 0))
|
||||
foreach (var design in selector.SelectedPaths.OfType<DesignFileSystem.Leaf>())
|
||||
editor.SetQuickDesign(design.Value, false);
|
||||
ImGui.Separator();
|
||||
}
|
||||
|
||||
private void DrawMultiColor(Vector2 width, float offset)
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted("Multi Colors:");
|
||||
ImUtf8.TextFrameAligned("Multi Colors:");
|
||||
ImGui.SameLine(offset, ImGui.GetStyle().ItemSpacing.X);
|
||||
_colorCombo.Draw("##color", _colorCombo.CurrentSelection ?? string.Empty, "Select a design color.",
|
||||
ImGui.GetContentRegionAvail().X - 2 * (width.X + ImGui.GetStyle().ItemSpacing.X), ImGui.GetTextLineHeight());
|
||||
|
|
@ -168,9 +181,9 @@ public class MultiDesignPanel(DesignFileSystemSelector _selector, DesignManager
|
|||
}
|
||||
: $"Set the color of {_addDesigns.Count} designs to \"{_colorCombo.CurrentSelection}\"\n\n\t{string.Join("\n\t", _addDesigns.Select(m => m.Name.Text))}";
|
||||
ImGui.SameLine();
|
||||
if (ImGuiUtil.DrawDisabledButton(label, width, tooltip, _addDesigns.Count == 0))
|
||||
if (ImUtf8.ButtonEx(label, tooltip, width, _addDesigns.Count == 0))
|
||||
foreach (var design in _addDesigns)
|
||||
_editor.ChangeColor(design, _colorCombo.CurrentSelection!);
|
||||
editor.ChangeColor(design, _colorCombo.CurrentSelection!);
|
||||
|
||||
label = _removeDesigns.Count > 0
|
||||
? $"Unset {_removeDesigns.Count} Designs"
|
||||
|
|
@ -179,9 +192,9 @@ public class MultiDesignPanel(DesignFileSystemSelector _selector, DesignManager
|
|||
? "No selected design is set to a non-automatic color."
|
||||
: $"Set {_removeDesigns.Count} designs to use automatic color again:\n\n\t{string.Join("\n\t", _removeDesigns.Select(m => m.Item1.Name.Text))}";
|
||||
ImGui.SameLine();
|
||||
if (ImGuiUtil.DrawDisabledButton(label, width, tooltip, _removeDesigns.Count == 0))
|
||||
if (ImUtf8.ButtonEx(label, tooltip, width, _removeDesigns.Count == 0))
|
||||
foreach (var (design, _) in _removeDesigns)
|
||||
_editor.ChangeColor(design, string.Empty);
|
||||
editor.ChangeColor(design, string.Empty);
|
||||
|
||||
ImGui.Separator();
|
||||
}
|
||||
|
|
@ -193,7 +206,7 @@ public class MultiDesignPanel(DesignFileSystemSelector _selector, DesignManager
|
|||
if (_tag.Length == 0)
|
||||
return;
|
||||
|
||||
foreach (var leaf in _selector.SelectedPaths.OfType<DesignFileSystem.Leaf>())
|
||||
foreach (var leaf in selector.SelectedPaths.OfType<DesignFileSystem.Leaf>())
|
||||
{
|
||||
var index = leaf.Value.Tags.IndexOf(_tag);
|
||||
if (index >= 0)
|
||||
|
|
@ -208,7 +221,7 @@ public class MultiDesignPanel(DesignFileSystemSelector _selector, DesignManager
|
|||
_addDesigns.Clear();
|
||||
_removeDesigns.Clear();
|
||||
var selection = _colorCombo.CurrentSelection ?? DesignColors.AutomaticName;
|
||||
foreach (var leaf in _selector.SelectedPaths.OfType<DesignFileSystem.Leaf>())
|
||||
foreach (var leaf in selector.SelectedPaths.OfType<DesignFileSystem.Leaf>())
|
||||
{
|
||||
if (leaf.Value.Color.Length > 0)
|
||||
_removeDesigns.Add((leaf.Value, 0));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue