mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 10:17:23 +01:00
Allow undoing overwriting designs.
This commit is contained in:
parent
36f6c48f7a
commit
859c738080
2 changed files with 45 additions and 7 deletions
|
|
@ -25,6 +25,7 @@ public class DesignManager
|
|||
private readonly SaveService _saveService;
|
||||
private readonly DesignChanged _event;
|
||||
private readonly List<Design> _designs = new();
|
||||
private readonly Dictionary<Guid, DesignData> _undoStore = new();
|
||||
|
||||
public IReadOnlyList<Design> Designs
|
||||
=> _designs;
|
||||
|
|
@ -83,6 +84,10 @@ public class DesignManager
|
|||
_event.Invoke(DesignChanged.Type.ReloadedAll, null!);
|
||||
}
|
||||
|
||||
/// <summary> Whether an Undo for the given design is possible. </summary>
|
||||
public bool CanUndo(Design? design)
|
||||
=> design != null && _undoStore.ContainsKey(design.Identifier);
|
||||
|
||||
/// <summary> Create a new temporary design without adding it to the manager. </summary>
|
||||
public DesignBase CreateTemporary()
|
||||
=> new(_items);
|
||||
|
|
@ -463,6 +468,7 @@ public class DesignManager
|
|||
/// <summary> Apply an entire design based on its appliance rules piece by piece. </summary>
|
||||
public void ApplyDesign(Design design, DesignBase other)
|
||||
{
|
||||
_undoStore[design.Identifier] = design.DesignData;
|
||||
if (other.DoApplyWetness())
|
||||
design.DesignData.SetIsWet(other.DesignData.IsWet());
|
||||
if (other.DoApplyHatVisible())
|
||||
|
|
@ -503,6 +509,16 @@ public class DesignManager
|
|||
ChangeStain(design, EquipSlot.OffHand, other.DesignData.Stain(EquipSlot.OffHand));
|
||||
}
|
||||
|
||||
public void UndoDesignChange(Design design)
|
||||
{
|
||||
if (!_undoStore.Remove(design.Identifier, out var otherData))
|
||||
return;
|
||||
|
||||
var other = CreateTemporary();
|
||||
other.DesignData = otherData;
|
||||
ApplyDesign(design, other);
|
||||
}
|
||||
|
||||
private void MigrateOldDesigns()
|
||||
{
|
||||
if (!File.Exists(_saveService.FileNames.MigrationDesignFile))
|
||||
|
|
|
|||
|
|
@ -84,6 +84,16 @@ public class DesignPanel
|
|||
Disabled = _selector.Selected?.WriteProtected() ?? true,
|
||||
};
|
||||
|
||||
private HeaderDrawer.Button UndoButton()
|
||||
=> new()
|
||||
{
|
||||
Description = "Undo the last change if you accidentally overwrote your design with a different one.",
|
||||
Icon = FontAwesomeIcon.Undo,
|
||||
OnClick = UndoOverwrite,
|
||||
Visible = _selector.Selected != null,
|
||||
Disabled = !_manager.CanUndo(_selector.Selected),
|
||||
};
|
||||
|
||||
private HeaderDrawer.Button ExportToClipboardButton()
|
||||
=> new()
|
||||
{
|
||||
|
|
@ -95,7 +105,7 @@ public class DesignPanel
|
|||
|
||||
private void DrawHeader()
|
||||
=> HeaderDrawer.Draw(SelectionName, 0, ImGui.GetColorU32(ImGuiCol.FrameBg),
|
||||
2, SetFromClipboardButton(), ExportToClipboardButton(), LockButton(),
|
||||
3, SetFromClipboardButton(), UndoButton(), ExportToClipboardButton(), LockButton(),
|
||||
HeaderDrawer.Button.IncognitoButton(_selector.IncognitoMode, v => _selector.IncognitoMode = v));
|
||||
|
||||
private string SelectionName
|
||||
|
|
@ -411,6 +421,18 @@ public class DesignPanel
|
|||
}
|
||||
}
|
||||
|
||||
private void UndoOverwrite()
|
||||
{
|
||||
try
|
||||
{
|
||||
_manager.UndoDesignChange(_selector.Selected!);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Glamourer.Messager.NotificationMessage(ex, $"Could not undo last changes to {_selector.Selected!.Name}.", NotificationType.Error, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExportToClipboard()
|
||||
{
|
||||
try
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue