Add Shift/Ctrl modifiers to Apply Design buttons.

This commit is contained in:
Ottermandias 2023-10-01 00:20:01 +02:00
parent 5cd7d607ef
commit 49768e797d
2 changed files with 48 additions and 10 deletions

View file

@ -157,6 +157,31 @@ public class DesignBase
public void FixCustomizeApplication(CustomizationSet set, CustomizeFlag flags) public void FixCustomizeApplication(CustomizationSet set, CustomizeFlag flags)
=> ApplyCustomize = flags.FixApplication(set); => ApplyCustomize = flags.FixApplication(set);
internal FlagRestrictionResetter TemporarilyRestrictApplication(EquipFlag equipFlags, CustomizeFlag customizeFlags)
=> new(this, equipFlags, customizeFlags);
internal readonly struct FlagRestrictionResetter : IDisposable
{
private readonly DesignBase _design;
private readonly EquipFlag _oldEquipFlags;
private readonly CustomizeFlag _oldCustomizeFlags;
public FlagRestrictionResetter(DesignBase d, EquipFlag equipFlags, CustomizeFlag customizeFlags)
{
_design = d;
_oldEquipFlags = d.ApplyEquip;
_oldCustomizeFlags = d.ApplyCustomize;
d.ApplyEquip &= equipFlags;
d.ApplyCustomize &= customizeFlags;
}
public void Dispose()
{
_design.ApplyEquip = _oldEquipFlags;
_design.ApplyCustomize = _oldCustomizeFlags;
}
}
#endregion #endregion
#region Serialization #region Serialization
@ -349,7 +374,9 @@ public class DesignBase
void PrintWarning(string msg) void PrintWarning(string msg)
{ {
if (msg.Length > 0) if (msg.Length > 0)
Glamourer.Chat.NotificationMessage($"{msg} ({name})\n\nThis change is not saved automatically. If you want this replacement to stick and the warning to stop appearing, please save the design manually once by changing something in it.", "Warning", NotificationType.Warning); Glamourer.Chat.NotificationMessage(
$"{msg} ({name})\n\nThis change is not saved automatically. If you want this replacement to stick and the warning to stop appearing, please save the design manually once by changing something in it.",
"Warning", NotificationType.Warning);
} }
var wetness = QuadBool.FromJObject(json["Wetness"], "Value", "Apply", QuadBool.NullFalse); var wetness = QuadBool.FromJObject(json["Wetness"], "Value", "Apply", QuadBool.NullFalse);

View file

@ -75,11 +75,12 @@ public class DesignPanel
private HeaderDrawer.Button SetFromClipboardButton() private HeaderDrawer.Button SetFromClipboardButton()
=> new() => new()
{ {
Description = "Try to apply a design from your clipboard over this design.\nHold Control to only apply gear.\nHold Shift to only apply customizations.", Description =
Icon = FontAwesomeIcon.Clipboard, "Try to apply a design from your clipboard over this design.\nHold Control to only apply gear.\nHold Shift to only apply customizations.",
OnClick = SetFromClipboard, Icon = FontAwesomeIcon.Clipboard,
Visible = _selector.Selected != null, OnClick = SetFromClipboard,
Disabled = _selector.Selected?.WriteProtected() ?? true, Visible = _selector.Selected != null,
Disabled = _selector.Selected?.WriteProtected() ?? true,
}; };
private HeaderDrawer.Button ExportToClipboardButton() private HeaderDrawer.Button ExportToClipboardButton()
@ -396,9 +397,10 @@ public class DesignPanel
{ {
try try
{ {
var text = ImGui.GetClipboardText(); var text = ImGui.GetClipboardText();
var (applyEquip, applyCustomize) = UiHelpers.ConvertKeysToBool(); var (applyEquip, applyCustomize) = UiHelpers.ConvertKeysToBool();
var design = _converter.FromBase64(text, applyEquip, applyCustomize, out _) ?? throw new Exception("The clipboard did not contain valid data."); var design = _converter.FromBase64(text, applyEquip, applyCustomize, out _)
?? throw new Exception("The clipboard did not contain valid data.");
_manager.ApplyDesign(_selector.Selected!, design); _manager.ApplyDesign(_selector.Selected!, design);
} }
catch (Exception ex) catch (Exception ex)
@ -425,12 +427,17 @@ public class DesignPanel
private void DrawApplyToSelf() private void DrawApplyToSelf()
{ {
var (id, data) = _objects.PlayerData; var (id, data) = _objects.PlayerData;
if (!ImGuiUtil.DrawDisabledButton("Apply to Yourself", Vector2.Zero, "Apply the current design with its settings to your character.", if (!ImGuiUtil.DrawDisabledButton("Apply to Yourself", Vector2.Zero,
"Apply the current design with its settings to your character.\nHold Control to only apply gear.\nHold Shift to only apply customizations.",
!data.Valid)) !data.Valid))
return; return;
if (_state.GetOrCreate(id, data.Objects[0], out var state)) if (_state.GetOrCreate(id, data.Objects[0], out var state))
{
var (applyGear, applyCustomize) = UiHelpers.ConvertKeysToFlags();
using var _ = _selector.Selected!.TemporarilyRestrictApplication(applyGear, applyCustomize);
_state.ApplyDesign(_selector.Selected!, state, StateChanged.Source.Manual); _state.ApplyDesign(_selector.Selected!, state, StateChanged.Source.Manual);
}
} }
private void DrawApplyToTarget() private void DrawApplyToTarget()
@ -438,14 +445,18 @@ public class DesignPanel
var (id, data) = _objects.TargetData; var (id, data) = _objects.TargetData;
var tt = id.IsValid var tt = id.IsValid
? data.Valid ? data.Valid
? "Apply the current design with its settings to your current target." ? "Apply the current design with its settings to your current target.\nHold Control to only apply gear.\nHold Shift to only apply customizations."
: "The current target can not be manipulated." : "The current target can not be manipulated."
: "No valid target selected."; : "No valid target selected.";
if (!ImGuiUtil.DrawDisabledButton("Apply to Target", Vector2.Zero, tt, !data.Valid || _objects.IsInGPose)) if (!ImGuiUtil.DrawDisabledButton("Apply to Target", Vector2.Zero, tt, !data.Valid || _objects.IsInGPose))
return; return;
if (_state.GetOrCreate(id, data.Objects[0], out var state)) if (_state.GetOrCreate(id, data.Objects[0], out var state))
{
var (applyGear, applyCustomize) = UiHelpers.ConvertKeysToFlags();
using var _ = _selector.Selected!.TemporarilyRestrictApplication(applyGear, applyCustomize);
_state.ApplyDesign(_selector.Selected!, state, StateChanged.Source.Manual); _state.ApplyDesign(_selector.Selected!, state, StateChanged.Source.Manual);
}
} }
private void DrawSaveToDat() private void DrawSaveToDat()