Merge pull request #95 from Caraxi/update-associated-design

Add ability to update configuration of associated mod
This commit is contained in:
Ottermandias 2024-02-15 16:32:54 +01:00 committed by GitHub
commit a2843c1298
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 57 additions and 3 deletions

View file

@ -273,6 +273,16 @@ public sealed class DesignManager : DesignEditor
DesignChanged.Invoke(DesignChanged.Type.RemovedMod, design, (mod, settings));
}
public void UpdateMod(Design design, Mod mod, ModSettings settings) {
if (!design.AssociatedMods.ContainsKey(mod))
return;
design.AssociatedMods[mod] = settings;
design.LastEdit = DateTimeOffset.UtcNow;
SaveService.QueueSave(design);
Glamourer.Log.Debug($"Updated associated mod {mod.DirectoryName} from design {design.Identifier}.");
DesignChanged.Invoke(DesignChanged.Type.AddedMod, design, (mod, settings));
}
/// <summary> Set the write protection status of a design. </summary>
public void SetWriteProtection(Design design, bool value)
{

View file

@ -66,11 +66,12 @@ public class ModAssociationsTab
private void DrawTable()
{
using var table = ImRaii.Table("Mods", 6, ImGuiTableFlags.RowBg);
using var table = ImRaii.Table("Mods", 7, ImGuiTableFlags.RowBg);
if (!table)
return;
ImGui.TableSetupColumn("##Delete", ImGuiTableColumnFlags.WidthFixed, ImGui.GetFrameHeight());
ImGui.TableSetupColumn("##Update", ImGuiTableColumnFlags.WidthFixed, ImGui.GetFrameHeight());
ImGui.TableSetupColumn("Mod Name", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableSetupColumn("Directory Name", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableSetupColumn("State", ImGuiTableColumnFlags.WidthFixed, ImGui.CalcTextSize("State").X);
@ -79,28 +80,70 @@ public class ModAssociationsTab
ImGui.TableHeadersRow();
Mod? removedMod = null;
(Mod mod, ModSettings settings)? updatedMod = null;
foreach (var ((mod, settings), idx) in _selector.Selected!.AssociatedMods.WithIndex())
{
using var id = ImRaii.PushId(idx);
DrawAssociatedModRow(mod, settings, out var removedModTmp);
DrawAssociatedModRow(mod, settings, out var removedModTmp, out var updatedModTmp);
if (removedModTmp.HasValue)
removedMod = removedModTmp;
if (updatedModTmp.HasValue)
updatedMod = updatedModTmp;
}
DrawNewModRow();
if (removedMod.HasValue)
_manager.RemoveMod(_selector.Selected!, removedMod.Value);
if (updatedMod.HasValue)
_manager.UpdateMod(_selector.Selected!, updatedMod.Value.mod, updatedMod.Value.settings);
}
private void DrawAssociatedModRow(Mod mod, ModSettings settings, out Mod? removedMod)
private void DrawAssociatedModRow(Mod mod, ModSettings settings, out Mod? removedMod, out (Mod, ModSettings)? updatedMod)
{
removedMod = null;
updatedMod = null;
ImGui.TableNextColumn();
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Trash.ToIconString(), new Vector2(ImGui.GetFrameHeight()),
"Delete this mod from associations", false, true))
removedMod = mod;
ImGui.TableNextColumn();
ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.RedoAlt.ToIconString(), new Vector2(ImGui.GetFrameHeight()),
"Update the settings of this mod association", false, true);
if (ImGui.IsItemHovered())
{
var (_, newSettings) = _penumbra.GetMods().FirstOrDefault(m => m.Mod == mod);
if (ImGui.IsItemClicked())
updatedMod = (mod, newSettings);
using var style = ImRaii.PushStyle(ImGuiStyleVar.PopupBorderSize, 2 * ImGuiHelpers.GlobalScale);
using var tt = ImRaii.Tooltip();
ImGui.Separator();
var namesDifferent = mod.Name != mod.DirectoryName;
ImGui.Dummy(new Vector2(300 * ImGuiHelpers.GlobalScale, 0));
using (var group = ImRaii.Group())
{
if (namesDifferent)
ImGui.TextUnformatted("Directory Name");
ImGui.TextUnformatted("Enabled");
ImGui.TextUnformatted("Priority");
ModCombo.DrawSettingsLeft(newSettings);
}
ImGui.SameLine(Math.Max(ImGui.GetItemRectSize().X + 3 * ImGui.GetStyle().ItemSpacing.X, 150 * ImGuiHelpers.GlobalScale));
using (var group = ImRaii.Group())
{
if (namesDifferent)
ImGui.TextUnformatted(mod.DirectoryName);
ImGui.TextUnformatted(newSettings.Enabled.ToString());
ImGui.TextUnformatted(newSettings.Priority.ToString());
ModCombo.DrawSettingsRight(newSettings);
}
}
ImGui.TableNextColumn();
var selected = ImGui.Selectable($"{mod.Name}##name");
var hovered = ImGui.IsItemHovered();
@ -156,6 +199,7 @@ public class ModAssociationsTab
{
var currentName = _modCombo.CurrentSelection.Mod.Name;
ImGui.TableNextColumn();
ImGui.TableNextColumn();
var tt = currentName.IsNullOrEmpty()
? "Please select a mod first."
: _selector.Selected!.AssociatedMods.ContainsKey(_modCombo.CurrentSelection.Mod)