Add some copy functionality for mod associations.

This commit is contained in:
Ottermandias 2024-04-15 23:30:45 +02:00
parent 4900ccb75a
commit dfb3ef3d79
2 changed files with 58 additions and 26 deletions

View file

@ -273,13 +273,13 @@ public sealed class DesignManager : DesignEditor
DesignChanged.Invoke(DesignChanged.Type.RemovedMod, design, (mod, settings)); DesignChanged.Invoke(DesignChanged.Type.RemovedMod, design, (mod, settings));
} }
public void UpdateMod(Design design, Mod mod, ModSettings settings) { /// <summary> Add or update an associated mod to a design. </summary>
if (!design.AssociatedMods.ContainsKey(mod)) public void UpdateMod(Design design, Mod mod, ModSettings settings)
return; {
design.AssociatedMods[mod] = settings; design.AssociatedMods[mod] = settings;
design.LastEdit = DateTimeOffset.UtcNow; design.LastEdit = DateTimeOffset.UtcNow;
SaveService.QueueSave(design); SaveService.QueueSave(design);
Glamourer.Log.Debug($"Updated associated mod {mod.DirectoryName} from design {design.Identifier}."); Glamourer.Log.Debug($"Updated (or added) associated mod {mod.DirectoryName} from design {design.Identifier}.");
DesignChanged.Invoke(DesignChanged.Type.AddedMod, design, (mod, settings)); DesignChanged.Invoke(DesignChanged.Type.AddedMod, design, (mod, settings));
} }
@ -302,7 +302,8 @@ public sealed class DesignManager : DesignEditor
design.QuickDesign = value; design.QuickDesign = value;
SaveService.QueueSave(design); SaveService.QueueSave(design);
Glamourer.Log.Debug($"Set design {design.Identifier} to {(!value ? "no longer be " : string.Empty)} displayed in the quick design bar."); Glamourer.Log.Debug(
$"Set design {design.Identifier} to {(!value ? "no longer be " : string.Empty)} displayed in the quick design bar.");
DesignChanged.Invoke(DesignChanged.Type.QuickDesignBar, design, value); DesignChanged.Invoke(DesignChanged.Type.QuickDesignBar, design, value);
} }

View file

@ -14,6 +14,7 @@ namespace Glamourer.Gui.Tabs.DesignTab;
public class ModAssociationsTab(PenumbraService penumbra, DesignFileSystemSelector selector, DesignManager manager) public class ModAssociationsTab(PenumbraService penumbra, DesignFileSystemSelector selector, DesignManager manager)
{ {
private readonly ModCombo _modCombo = new(penumbra, Glamourer.Log); private readonly ModCombo _modCombo = new(penumbra, Glamourer.Log);
private (Mod, ModSettings)[]? _copy;
public void Draw() public void Draw()
{ {
@ -28,6 +29,36 @@ public class ModAssociationsTab(PenumbraService penumbra, DesignFileSystemSelect
DrawApplyAllButton(); DrawApplyAllButton();
DrawTable(); DrawTable();
DrawCopyButtons();
}
private void DrawCopyButtons()
{
var size = new Vector2((ImGui.GetContentRegionAvail().X - 2 * ImGui.GetStyle().ItemSpacing.X) / 3, 0);
if (ImGui.Button("Copy All to Clipboard", size))
_copy = selector.Selected!.AssociatedMods.Select(kvp => (kvp.Key, kvp.Value)).ToArray();
ImGui.SameLine();
if (ImGuiUtil.DrawDisabledButton("Add from Clipboard", size,
_copy != null
? $"Add {_copy.Length} mod association(s) from clipboard."
: "Copy some mod associations to the clipboard, first.", _copy == null))
foreach (var (mod, setting) in _copy!)
manager.UpdateMod(selector.Selected!, mod, setting);
ImGui.SameLine();
if (ImGuiUtil.DrawDisabledButton("Set from Clipboard", size,
_copy != null
? $"Set {_copy.Length} mod association(s) from clipboard and discard existing."
: "Copy some mod associations to the clipboard, first.", _copy == null))
{
while (selector.Selected!.AssociatedMods.Count > 0)
manager.RemoveMod(selector.Selected!, selector.Selected!.AssociatedMods.Keys[0]);
foreach (var (mod, setting) in _copy!)
manager.AddMod(selector.Selected!, mod, setting);
}
} }
private void DrawApplyAllButton() private void DrawApplyAllButton()
@ -55,17 +86,16 @@ public class ModAssociationsTab(PenumbraService penumbra, DesignFileSystemSelect
private void DrawTable() private void DrawTable()
{ {
using var table = ImRaii.Table("Mods", 7, ImGuiTableFlags.RowBg); using var table = ImRaii.Table("Mods", 5, ImGuiTableFlags.RowBg);
if (!table) if (!table)
return; return;
ImGui.TableSetupColumn("##Delete", ImGuiTableColumnFlags.WidthFixed, ImGui.GetFrameHeight()); ImGui.TableSetupColumn("##Buttons", ImGuiTableColumnFlags.WidthFixed,
ImGui.TableSetupColumn("##Update", ImGuiTableColumnFlags.WidthFixed, ImGui.GetFrameHeight()); ImGui.GetFrameHeight() * 3 + ImGui.GetStyle().ItemInnerSpacing.X * 2);
ImGui.TableSetupColumn("Mod Name", ImGuiTableColumnFlags.WidthStretch); ImGui.TableSetupColumn("Mod Name", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableSetupColumn("Directory Name", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableSetupColumn("State", ImGuiTableColumnFlags.WidthFixed, ImGui.CalcTextSize("State").X); ImGui.TableSetupColumn("State", ImGuiTableColumnFlags.WidthFixed, ImGui.CalcTextSize("State").X);
ImGui.TableSetupColumn("Priority", ImGuiTableColumnFlags.WidthFixed, ImGui.CalcTextSize("Priority").X); ImGui.TableSetupColumn("Priority", ImGuiTableColumnFlags.WidthFixed, ImGui.CalcTextSize("Priority").X);
ImGui.TableSetupColumn("##Options", ImGuiTableColumnFlags.WidthFixed, ImGui.CalcTextSize("Try Applyingm").X); ImGui.TableSetupColumn("##Options", ImGuiTableColumnFlags.WidthFixed, ImGui.CalcTextSize("Applym").X);
ImGui.TableHeadersRow(); ImGui.TableHeadersRow();
Mod? removedMod = null; Mod? removedMod = null;
@ -94,14 +124,20 @@ public class ModAssociationsTab(PenumbraService penumbra, DesignFileSystemSelect
removedMod = null; removedMod = null;
updatedMod = null; updatedMod = null;
ImGui.TableNextColumn(); ImGui.TableNextColumn();
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Trash.ToIconString(), new Vector2(ImGui.GetFrameHeight()), var buttonSize = new Vector2(ImGui.GetFrameHeight());
"Delete this mod from associations", false, true)) var spacing = ImGui.GetStyle().ItemInnerSpacing.X;
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Trash.ToIconString(), buttonSize,
"Delete this mod from associations.", false, true))
removedMod = mod; removedMod = mod;
ImGui.TableNextColumn(); ImGui.SameLine(0, spacing);
ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.RedoAlt.ToIconString(), new Vector2(ImGui.GetFrameHeight()), if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Clipboard.ToIconString(), buttonSize,
"Update the settings of this mod association", false, true); "Copy this mod setting to clipboard.", false, true))
_copy = [(mod, settings)];
ImGui.SameLine(0, spacing);
ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.RedoAlt.ToIconString(), buttonSize,
"Update the settings of this mod association.", false, true);
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
{ {
var newSettings = penumbra.GetModSettings(mod); var newSettings = penumbra.GetModSettings(mod);
@ -134,15 +170,11 @@ public class ModAssociationsTab(PenumbraService penumbra, DesignFileSystemSelect
} }
ImGui.TableNextColumn(); ImGui.TableNextColumn();
var selected = ImGui.Selectable($"{mod.Name}##name");
var hovered = ImGui.IsItemHovered(); if (ImGui.Selectable($"{mod.Name}##name"))
ImGui.TableNextColumn();
selected |= ImGui.Selectable($"{mod.DirectoryName}##directory");
hovered |= ImGui.IsItemHovered();
if (selected)
penumbra.OpenModPage(mod); penumbra.OpenModPage(mod);
if (hovered) if (ImGui.IsItemHovered())
ImGui.SetTooltip("Click to open mod page in Penumbra."); ImGui.SetTooltip($"Mod Directory: {mod.DirectoryName}\n\nClick to open mod page in Penumbra.");
ImGui.TableNextColumn(); ImGui.TableNextColumn();
using (var font = ImRaii.PushFont(UiBuilder.IconFont)) using (var font = ImRaii.PushFont(UiBuilder.IconFont))
{ {
@ -152,7 +184,7 @@ public class ModAssociationsTab(PenumbraService penumbra, DesignFileSystemSelect
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGuiUtil.RightAlign(settings.Priority.ToString()); ImGuiUtil.RightAlign(settings.Priority.ToString());
ImGui.TableNextColumn(); ImGui.TableNextColumn();
if (ImGuiUtil.DrawDisabledButton("Try Applying", new Vector2(ImGui.GetContentRegionAvail().X, 0), string.Empty, if (ImGuiUtil.DrawDisabledButton("Apply", new Vector2(ImGui.GetContentRegionAvail().X, 0), string.Empty,
!penumbra.Available)) !penumbra.Available))
{ {
var text = penumbra.SetMod(mod, settings); var text = penumbra.SetMod(mod, settings);
@ -188,7 +220,6 @@ public class ModAssociationsTab(PenumbraService penumbra, DesignFileSystemSelect
{ {
var currentName = _modCombo.CurrentSelection.Mod.Name; var currentName = _modCombo.CurrentSelection.Mod.Name;
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.TableNextColumn();
var tt = currentName.IsNullOrEmpty() var tt = currentName.IsNullOrEmpty()
? "Please select a mod first." ? "Please select a mod first."
: selector.Selected!.AssociatedMods.ContainsKey(_modCombo.CurrentSelection.Mod) : selector.Selected!.AssociatedMods.ContainsKey(_modCombo.CurrentSelection.Mod)