Use new functionality.

This commit is contained in:
Ottermandias 2024-01-26 15:04:36 +01:00
parent a4de13f228
commit 2219d9293f
9 changed files with 163 additions and 136 deletions

View file

@ -2,6 +2,7 @@ using Glamourer.Designs.Links;
using Glamourer.Events; using Glamourer.Events;
using Glamourer.GameData; using Glamourer.GameData;
using Glamourer.Services; using Glamourer.Services;
using Glamourer.State;
using Penumbra.GameData.Enums; using Penumbra.GameData.Enums;
using Penumbra.GameData.Structs; using Penumbra.GameData.Structs;
@ -22,7 +23,7 @@ public class DesignEditor(
protected readonly Configuration Config = config; protected readonly Configuration Config = config;
protected readonly Dictionary<Guid, DesignData> UndoStore = []; protected readonly Dictionary<Guid, DesignData> UndoStore = [];
private bool _forceFullItemOff = false; private bool _forceFullItemOff;
/// <summary> Whether an Undo for the given design is possible. </summary> /// <summary> Whether an Undo for the given design is possible. </summary>
public bool CanUndo(Design? design) public bool CanUndo(Design? design)
@ -31,11 +32,8 @@ public class DesignEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeCustomize(object data, CustomizeIndex idx, CustomizeValue value, ApplySettings _ = default) public void ChangeCustomize(object data, CustomizeIndex idx, CustomizeValue value, ApplySettings _ = default)
{ {
if (data is not Design design) var design = (Design)data;
return;
var oldValue = design.DesignData.Customize[idx]; var oldValue = design.DesignData.Customize[idx];
switch (idx) switch (idx)
{ {
case CustomizeIndex.Race: case CustomizeIndex.Race:
@ -80,9 +78,7 @@ public class DesignEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeEntireCustomize(object data, in CustomizeArray customize, CustomizeFlag apply, ApplySettings _ = default) public void ChangeEntireCustomize(object data, in CustomizeArray customize, CustomizeFlag apply, ApplySettings _ = default)
{ {
if (data is not Design design) var design = (Design)data;
return;
var (newCustomize, applied, changed) = Customizations.Combine(design.DesignData.Customize, customize, apply, true); var (newCustomize, applied, changed) = Customizations.Combine(design.DesignData.Customize, customize, apply, true);
if (changed == 0) if (changed == 0)
return; return;
@ -98,9 +94,7 @@ public class DesignEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeCustomizeParameter(object data, CustomizeParameterFlag flag, CustomizeParameterValue value, ApplySettings _ = default) public void ChangeCustomizeParameter(object data, CustomizeParameterFlag flag, CustomizeParameterValue value, ApplySettings _ = default)
{ {
if (data is not Design design) var design = (Design)data;
return;
var old = design.DesignData.Parameters[flag]; var old = design.DesignData.Parameters[flag];
if (!design.GetDesignDataRef().Parameters.Set(flag, value)) if (!design.GetDesignDataRef().Parameters.Set(flag, value))
return; return;
@ -115,9 +109,7 @@ public class DesignEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeItem(object data, EquipSlot slot, EquipItem item, ApplySettings _ = default) public void ChangeItem(object data, EquipSlot slot, EquipItem item, ApplySettings _ = default)
{ {
if (data is not Design design) var design = (Design)data;
return;
switch (slot) switch (slot)
{ {
case EquipSlot.MainHand: case EquipSlot.MainHand:
@ -176,9 +168,7 @@ public class DesignEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeStain(object data, EquipSlot slot, StainId stain, ApplySettings _ = default) public void ChangeStain(object data, EquipSlot slot, StainId stain, ApplySettings _ = default)
{ {
if (data is not Design design) var design = (Design)data;
return;
if (Items.ValidateStain(stain, out var _, false).Length > 0) if (Items.ValidateStain(stain, out var _, false).Length > 0)
return; return;
@ -204,9 +194,7 @@ public class DesignEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeCrest(object data, CrestFlag slot, bool crest, ApplySettings _ = default) public void ChangeCrest(object data, CrestFlag slot, bool crest, ApplySettings _ = default)
{ {
if (data is not Design design) var design = (Design)data;
return;
var oldCrest = design.DesignData.Crest(slot); var oldCrest = design.DesignData.Crest(slot);
if (!design.GetDesignDataRef().SetCrest(slot, crest)) if (!design.GetDesignDataRef().SetCrest(slot, crest))
return; return;
@ -220,9 +208,7 @@ public class DesignEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeMetaState(object data, MetaIndex metaIndex, bool value, ApplySettings _ = default) public void ChangeMetaState(object data, MetaIndex metaIndex, bool value, ApplySettings _ = default)
{ {
if (data is not Design design) var design = (Design)data;
return;
if (!design.GetDesignDataRef().SetMeta(metaIndex, value)) if (!design.GetDesignDataRef().SetMeta(metaIndex, value))
return; return;
@ -239,9 +225,7 @@ public class DesignEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ApplyDesign(object data, DesignBase other, ApplySettings _ = default) public void ApplyDesign(object data, DesignBase other, ApplySettings _ = default)
{ {
if (data is not Design design) var design = (Design)data;
return;
UndoStore[design.Identifier] = design.DesignData; UndoStore[design.Identifier] = design.DesignData;
foreach (var index in MetaExtensions.AllRelevant.Where(other.DoApplyMeta)) foreach (var index in MetaExtensions.AllRelevant.Where(other.DoApplyMeta))
design.GetDesignDataRef().SetMeta(index, other.DesignData.GetMeta(index)); design.GetDesignDataRef().SetMeta(index, other.DesignData.GetMeta(index));
@ -269,7 +253,7 @@ public class DesignEditor(
} }
/// <summary> Change a mainhand weapon and either fix or apply appropriate offhand and potentially gauntlets. </summary> /// <summary> Change a mainhand weapon and either fix or apply appropriate offhand and potentially gauntlets. </summary>
private bool ChangeMainhandPeriphery(Design design, EquipItem currentMain, EquipItem currentOff, EquipItem newMain, out EquipItem? newOff, private bool ChangeMainhandPeriphery(DesignBase design, EquipItem currentMain, EquipItem currentOff, EquipItem newMain, out EquipItem? newOff,
out EquipItem? newGauntlets) out EquipItem? newGauntlets)
{ {
newOff = null; newOff = null;

View file

@ -301,7 +301,7 @@ public sealed class DesignManager : DesignEditor
} }
/// <summary> Change whether to apply a specific equipment piece. </summary> /// <summary> Change whether to apply a specific equipment piece. </summary>
public void ChangeApplyEquip(Design design, EquipSlot slot, bool value) public void ChangeApplyItem(Design design, EquipSlot slot, bool value)
{ {
if (!design.SetApplyEquip(slot, value)) if (!design.SetApplyEquip(slot, value))
return; return;

View file

@ -1,19 +1,28 @@
using Glamourer.Designs; using Glamourer.Designs;
using Glamourer.Events;
using Glamourer.GameData; using Glamourer.GameData;
using Glamourer.State; using Glamourer.State;
namespace Glamourer.Gui.Customization; namespace Glamourer.Gui.Customization;
public ref struct CustomizeParameterDrawData(CustomizeParameterFlag flag, in DesignData data) public struct CustomizeParameterDrawData(CustomizeParameterFlag flag, in DesignData data)
{ {
private IDesignEditor _editor;
private object _object;
public readonly CustomizeParameterFlag Flag = flag; public readonly CustomizeParameterFlag Flag = flag;
public bool Locked; public bool Locked;
public bool DisplayApplication; public bool DisplayApplication;
public bool AllowRevert; public bool AllowRevert;
public Action<CustomizeParameterValue> ValueSetter = null!; public readonly void ChangeParameter(CustomizeParameterValue value)
public Action<bool> ApplySetter = null!; => _editor.ChangeCustomizeParameter(_object, Flag, value, ApplySettings.Manual);
public readonly void ChangeApplyParameter(bool value)
{
var manager = (DesignManager)_editor;
var design = (Design)_object;
manager.ChangeApplyParameter(design, Flag, value);
}
public CustomizeParameterValue CurrentValue = data.Parameters[flag]; public CustomizeParameterValue CurrentValue = data.Parameters[flag];
public CustomizeParameterValue GameValue; public CustomizeParameterValue GameValue;
public bool CurrentApply; public bool CurrentApply;
@ -21,19 +30,20 @@ public ref struct CustomizeParameterDrawData(CustomizeParameterFlag flag, in Des
public static CustomizeParameterDrawData FromDesign(DesignManager manager, Design design, CustomizeParameterFlag flag) public static CustomizeParameterDrawData FromDesign(DesignManager manager, Design design, CustomizeParameterFlag flag)
=> new(flag, design.DesignData) => new(flag, design.DesignData)
{ {
_editor = manager,
_object = design,
Locked = design.WriteProtected(), Locked = design.WriteProtected(),
DisplayApplication = true, DisplayApplication = true,
CurrentApply = design.DoApplyParameter(flag), CurrentApply = design.DoApplyParameter(flag),
ValueSetter = v => manager.ChangeCustomizeParameter(design, flag, v),
ApplySetter = v => manager.ChangeApplyParameter(design, flag, v),
}; };
public static CustomizeParameterDrawData FromState(StateManager manager, ActorState state, CustomizeParameterFlag flag) public static CustomizeParameterDrawData FromState(StateManager manager, ActorState state, CustomizeParameterFlag flag)
=> new(flag, state.ModelData) => new(flag, state.ModelData)
{ {
_editor = manager,
_object = state,
Locked = state.IsLocked, Locked = state.IsLocked,
DisplayApplication = false, DisplayApplication = false,
ValueSetter = v => manager.ChangeCustomizeParameter(state, flag, v, ApplySettings.Manual),
GameValue = state.BaseData.Parameters[flag], GameValue = state.BaseData.Parameters[flag],
AllowRevert = true, AllowRevert = true,
}; };

View file

@ -195,7 +195,7 @@ public class CustomizeParameterDrawer(Configuration config, PaletteImport import
using (_ = ImRaii.Disabled(data.Locked || noHighlights)) using (_ = ImRaii.Disabled(data.Locked || noHighlights))
{ {
if (ImGui.ColorEdit3("##value", ref value, GetFlags())) if (ImGui.ColorEdit3("##value", ref value, GetFlags()))
data.ValueSetter(new CustomizeParameterValue(value)); data.ChangeParameter(new CustomizeParameterValue(value));
} }
if (noHighlights) if (noHighlights)
@ -215,7 +215,7 @@ public class CustomizeParameterDrawer(Configuration config, PaletteImport import
using (_ = ImRaii.Disabled(data.Locked)) using (_ = ImRaii.Disabled(data.Locked))
{ {
if (ImGui.ColorEdit4("##value", ref value, GetFlags() | ImGuiColorEditFlags.AlphaPreviewHalf)) if (ImGui.ColorEdit4("##value", ref value, GetFlags() | ImGuiColorEditFlags.AlphaPreviewHalf))
data.ValueSetter(new CustomizeParameterValue(value)); data.ChangeParameter(new CustomizeParameterValue(value));
} }
DrawRevert(data); DrawRevert(data);
@ -231,7 +231,7 @@ public class CustomizeParameterDrawer(Configuration config, PaletteImport import
using (_ = ImRaii.Disabled(data.Locked)) using (_ = ImRaii.Disabled(data.Locked))
{ {
if (ImGui.InputFloat("##value", ref value, 0.1f, 0.5f)) if (ImGui.InputFloat("##value", ref value, 0.1f, 0.5f))
data.ValueSetter(new CustomizeParameterValue(value)); data.ChangeParameter(new CustomizeParameterValue(value));
} }
DrawRevert(data); DrawRevert(data);
@ -247,7 +247,7 @@ public class CustomizeParameterDrawer(Configuration config, PaletteImport import
using (_ = ImRaii.Disabled(data.Locked)) using (_ = ImRaii.Disabled(data.Locked))
{ {
if (ImGui.SliderFloat("##value", ref value, -100f, 300, "%.2f")) if (ImGui.SliderFloat("##value", ref value, -100f, 300, "%.2f"))
data.ValueSetter(new CustomizeParameterValue(value / 100f)); data.ChangeParameter(new CustomizeParameterValue(value / 100f));
ImGuiUtil.HoverTooltip("You can control-click this to enter arbitrary values by hand instead of dragging."); ImGuiUtil.HoverTooltip("You can control-click this to enter arbitrary values by hand instead of dragging.");
} }
@ -262,7 +262,7 @@ public class CustomizeParameterDrawer(Configuration config, PaletteImport import
return; return;
if (ImGui.IsItemClicked(ImGuiMouseButton.Right) && ImGui.GetIO().KeyCtrl) if (ImGui.IsItemClicked(ImGuiMouseButton.Right) && ImGui.GetIO().KeyCtrl)
data.ValueSetter(data.GameValue); data.ChangeParameter(data.GameValue);
ImGuiUtil.HoverTooltip("Hold Control and Right-click to revert to game values."); ImGuiUtil.HoverTooltip("Hold Control and Right-click to revert to game values.");
} }
@ -271,7 +271,7 @@ public class CustomizeParameterDrawer(Configuration config, PaletteImport import
{ {
if (UiHelpers.DrawCheckbox("##apply", "Apply this custom parameter when applying the Design.", data.CurrentApply, out var enabled, if (UiHelpers.DrawCheckbox("##apply", "Apply this custom parameter when applying the Design.", data.CurrentApply, out var enabled,
data.Locked)) data.Locked))
data.ApplySetter(enabled); data.ChangeApplyParameter(enabled);
} }
private void DrawApplyAndLabel(in CustomizeParameterDrawData data) private void DrawApplyAndLabel(in CustomizeParameterDrawData data)
@ -310,6 +310,6 @@ public class CustomizeParameterDrawer(Configuration config, PaletteImport import
ImGui.SameLine(0, ImGui.GetStyle().ItemInnerSpacing.X); ImGui.SameLine(0, ImGui.GetStyle().ItemInnerSpacing.X);
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Paste.ToIconString(), new Vector2(ImGui.GetFrameHeight()), if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Paste.ToIconString(), new Vector2(ImGui.GetFrameHeight()),
_copy.HasValue ? "Paste the currently copied value." : "No value copied yet.", locked || !_copy.HasValue, true)) _copy.HasValue ? "Paste the currently copied value." : "No value copied yet.", locked || !_copy.HasValue, true))
data.ValueSetter(_copy!.Value); data.ChangeParameter(_copy!.Value);
} }
} }

View file

@ -1,29 +1,45 @@
using Dalamud.Game.Inventory; using Glamourer.Designs;
using Glamourer.Designs;
using Glamourer.Events;
using Glamourer.State; using Glamourer.State;
using Penumbra.GameData.Enums; using Penumbra.GameData.Enums;
using Penumbra.GameData.Structs; using Penumbra.GameData.Structs;
namespace Glamourer.Gui.Equipment; namespace Glamourer.Gui.Equipment;
public ref struct EquipDrawData(EquipSlot slot, in DesignData designData) public struct EquipDrawData(EquipSlot slot, in DesignData designData)
{ {
public readonly EquipSlot Slot = slot; private IDesignEditor _editor;
public bool Locked; private object _object;
public bool DisplayApplication; public readonly EquipSlot Slot = slot;
public bool AllowRevert; public bool Locked;
public bool DisplayApplication;
public bool AllowRevert;
public Action<EquipItem> ItemSetter = null!; public readonly void SetItem(EquipItem item)
public Action<StainId> StainSetter = null!; => _editor.ChangeItem(_object, Slot, item, ApplySettings.Manual);
public Action<bool> ApplySetter = null!;
public Action<bool> ApplyStainSetter = null!; public readonly void SetStain(StainId stain)
public EquipItem CurrentItem = designData.Item(slot); => _editor.ChangeStain(_object, Slot, stain, ApplySettings.Manual);
public StainId CurrentStain = designData.Stain(slot);
public EquipItem GameItem = default; public readonly void SetApplyItem(bool value)
public StainId GameStain = default; {
public bool CurrentApply; var manager = (DesignManager)_editor;
public bool CurrentApplyStain; var design = (Design)_object;
manager.ChangeApplyItem(design, Slot, value);
}
public readonly void SetApplyStain(bool value)
{
var manager = (DesignManager)_editor;
var design = (Design)_object;
manager.ChangeApplyStain(design, Slot, value);
}
public EquipItem CurrentItem = designData.Item(slot);
public StainId CurrentStain = designData.Stain(slot);
public EquipItem GameItem = default;
public StainId GameStain = default;
public bool CurrentApply;
public bool CurrentApplyStain;
public readonly Gender CurrentGender = designData.Customize.Gender; public readonly Gender CurrentGender = designData.Customize.Gender;
public readonly Race CurrentRace = designData.Customize.Race; public readonly Race CurrentRace = designData.Customize.Race;
@ -31,10 +47,8 @@ public ref struct EquipDrawData(EquipSlot slot, in DesignData designData)
public static EquipDrawData FromDesign(DesignManager manager, Design design, EquipSlot slot) public static EquipDrawData FromDesign(DesignManager manager, Design design, EquipSlot slot)
=> new(slot, design.DesignData) => new(slot, design.DesignData)
{ {
ItemSetter = i => manager.ChangeItem(design, slot, i), _editor = manager,
StainSetter = i => manager.ChangeStain(design, slot, i), _object = design,
ApplySetter = b => manager.ChangeApplyEquip(design, slot, b),
ApplyStainSetter = b => manager.ChangeApplyStain(design, slot, b),
CurrentApply = design.DoApplyEquip(slot), CurrentApply = design.DoApplyEquip(slot),
CurrentApplyStain = design.DoApplyStain(slot), CurrentApplyStain = design.DoApplyStain(slot),
Locked = design.WriteProtected(), Locked = design.WriteProtected(),
@ -44,8 +58,8 @@ public ref struct EquipDrawData(EquipSlot slot, in DesignData designData)
public static EquipDrawData FromState(StateManager manager, ActorState state, EquipSlot slot) public static EquipDrawData FromState(StateManager manager, ActorState state, EquipSlot slot)
=> new(slot, state.ModelData) => new(slot, state.ModelData)
{ {
ItemSetter = i => manager.ChangeItem(state, slot, i, ApplySettings.Manual), _editor = manager,
StainSetter = i => manager.ChangeStain(state, slot, i, ApplySettings.Manual), _object = state,
Locked = state.IsLocked, Locked = state.IsLocked,
DisplayApplication = false, DisplayApplication = false,
GameItem = state.BaseData.Item(slot), GameItem = state.BaseData.Item(slot),

View file

@ -205,7 +205,7 @@ public class EquipmentDrawer
{ {
var newSetId = (PrimaryId)Math.Clamp(setId, 0, ushort.MaxValue); var newSetId = (PrimaryId)Math.Clamp(setId, 0, ushort.MaxValue);
if (newSetId.Id != current.CurrentItem.PrimaryId.Id) if (newSetId.Id != current.CurrentItem.PrimaryId.Id)
current.ItemSetter(_items.Identify(current.Slot, newSetId, current.CurrentItem.SecondaryId, current.CurrentItem.Variant)); current.SetItem(_items.Identify(current.Slot, newSetId, current.CurrentItem.SecondaryId, current.CurrentItem.Variant));
} }
ImGui.SameLine(); ImGui.SameLine();
@ -214,7 +214,7 @@ public class EquipmentDrawer
{ {
var newType = (SecondaryId)Math.Clamp(type, 0, ushort.MaxValue); var newType = (SecondaryId)Math.Clamp(type, 0, ushort.MaxValue);
if (newType.Id != current.CurrentItem.SecondaryId.Id) if (newType.Id != current.CurrentItem.SecondaryId.Id)
current.ItemSetter(_items.Identify(current.Slot, current.CurrentItem.PrimaryId, newType, current.CurrentItem.Variant)); current.SetItem(_items.Identify(current.Slot, current.CurrentItem.PrimaryId, newType, current.CurrentItem.Variant));
} }
ImGui.SameLine(); ImGui.SameLine();
@ -223,7 +223,7 @@ public class EquipmentDrawer
{ {
var newVariant = (Variant)Math.Clamp(variant, 0, byte.MaxValue); var newVariant = (Variant)Math.Clamp(variant, 0, byte.MaxValue);
if (newVariant.Id != current.CurrentItem.Variant.Id) if (newVariant.Id != current.CurrentItem.Variant.Id)
current.ItemSetter(_items.Identify(current.Slot, current.CurrentItem.PrimaryId, current.CurrentItem.SecondaryId, current.SetItem(_items.Identify(current.Slot, current.CurrentItem.PrimaryId, current.CurrentItem.SecondaryId,
newVariant)); newVariant));
} }
} }
@ -239,7 +239,7 @@ public class EquipmentDrawer
var newStainId = (StainId)Math.Clamp(stainId, 0, byte.MaxValue); var newStainId = (StainId)Math.Clamp(stainId, 0, byte.MaxValue);
if (newStainId != data.CurrentStain.Id) if (newStainId != data.CurrentStain.Id)
data.StainSetter(newStainId); data.SetStain(newStainId);
} }
/// <summary> Draw an input for armor that can set arbitrary values instead of choosing items. </summary> /// <summary> Draw an input for armor that can set arbitrary values instead of choosing items. </summary>
@ -252,7 +252,7 @@ public class EquipmentDrawer
{ {
var newSetId = (PrimaryId)Math.Clamp(setId, 0, ushort.MaxValue); var newSetId = (PrimaryId)Math.Clamp(setId, 0, ushort.MaxValue);
if (newSetId.Id != data.CurrentItem.PrimaryId.Id) if (newSetId.Id != data.CurrentItem.PrimaryId.Id)
data.ItemSetter(_items.Identify(data.Slot, newSetId, data.CurrentItem.Variant)); data.SetItem(_items.Identify(data.Slot, newSetId, data.CurrentItem.Variant));
} }
ImGui.SameLine(); ImGui.SameLine();
@ -261,7 +261,7 @@ public class EquipmentDrawer
{ {
var newVariant = (byte)Math.Clamp(variant, 0, byte.MaxValue); var newVariant = (byte)Math.Clamp(variant, 0, byte.MaxValue);
if (newVariant != data.CurrentItem.Variant) if (newVariant != data.CurrentItem.Variant)
data.ItemSetter(_items.Identify(data.Slot, data.CurrentItem.PrimaryId, newVariant)); data.SetItem(_items.Identify(data.Slot, data.CurrentItem.PrimaryId, newVariant));
} }
} }
@ -365,7 +365,7 @@ public class EquipmentDrawer
mainhand.CurrentItem.DrawIcon(_textures, _iconSize, EquipSlot.MainHand); mainhand.CurrentItem.DrawIcon(_textures, _iconSize, EquipSlot.MainHand);
var left = ImGui.IsItemClicked(ImGuiMouseButton.Left); var left = ImGui.IsItemClicked(ImGuiMouseButton.Left);
ImGui.SameLine(); ImGui.SameLine();
using (var group = ImRaii.Group()) using (ImRaii.Group())
{ {
DrawMainhand(ref mainhand, ref offhand, out var mainhandLabel, allWeapons, false, left); DrawMainhand(ref mainhand, ref offhand, out var mainhandLabel, allWeapons, false, left);
if (mainhand.DisplayApplication) if (mainhand.DisplayApplication)
@ -391,7 +391,7 @@ public class EquipmentDrawer
var right = ImGui.IsItemClicked(ImGuiMouseButton.Right); var right = ImGui.IsItemClicked(ImGuiMouseButton.Right);
left = ImGui.IsItemClicked(ImGuiMouseButton.Left); left = ImGui.IsItemClicked(ImGuiMouseButton.Left);
ImGui.SameLine(); ImGui.SameLine();
using (var group = ImRaii.Group()) using (ImRaii.Group())
{ {
DrawOffhand(mainhand, offhand, out var offhandLabel, false, right, left); DrawOffhand(mainhand, offhand, out var offhandLabel, false, right, left);
if (offhand.DisplayApplication) if (offhand.DisplayApplication)
@ -420,12 +420,12 @@ public class EquipmentDrawer
: _stainCombo.Draw($"##stain{data.Slot}", stain.RgbaColor, stain.Name, found, stain.Gloss, _comboLength); : _stainCombo.Draw($"##stain{data.Slot}", stain.RgbaColor, stain.Name, found, stain.Gloss, _comboLength);
if (change) if (change)
if (_stainData.TryGetValue(_stainCombo.CurrentSelection.Key, out stain)) if (_stainData.TryGetValue(_stainCombo.CurrentSelection.Key, out stain))
data.StainSetter(stain.RowIndex); data.SetStain(stain.RowIndex);
else if (_stainCombo.CurrentSelection.Key == Stain.None.RowIndex) else if (_stainCombo.CurrentSelection.Key == Stain.None.RowIndex)
data.StainSetter(Stain.None.RowIndex); data.SetStain(Stain.None.RowIndex);
if (ResetOrClear(data.Locked, false, data.AllowRevert, true, data.CurrentStain, data.GameStain, Stain.None.RowIndex, out var id)) if (ResetOrClear(data.Locked, false, data.AllowRevert, true, data.CurrentStain, data.GameStain, Stain.None.RowIndex, out _))
data.StainSetter(Stain.None.RowIndex); data.SetStain(Stain.None.RowIndex);
} }
private void DrawItem(in EquipDrawData data, out string label, bool small, bool clear, bool open) private void DrawItem(in EquipDrawData data, out string label, bool small, bool clear, bool open)
@ -441,13 +441,13 @@ public class EquipmentDrawer
var change = combo.Draw(data.CurrentItem.Name, data.CurrentItem.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength, var change = combo.Draw(data.CurrentItem.Name, data.CurrentItem.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength,
_requiredComboWidth); _requiredComboWidth);
if (change) if (change)
data.ItemSetter(combo.CurrentSelection); data.SetItem(combo.CurrentSelection);
else if (combo.CustomVariant.Id > 0) else if (combo.CustomVariant.Id > 0)
data.ItemSetter(_items.Identify(data.Slot, combo.CustomSetId, combo.CustomVariant)); data.SetItem(_items.Identify(data.Slot, combo.CustomSetId, combo.CustomVariant));
if (ResetOrClear(data.Locked, clear, data.AllowRevert, true, data.CurrentItem, data.GameItem, ItemManager.NothingItem(data.Slot), if (ResetOrClear(data.Locked, clear, data.AllowRevert, true, data.CurrentItem, data.GameItem, ItemManager.NothingItem(data.Slot),
out var item)) out var item))
data.ItemSetter(item); data.SetItem(item);
} }
private static bool ResetOrClear<T>(bool locked, bool clicked, bool allowRevert, bool allowClear, private static bool ResetOrClear<T>(bool locked, bool clicked, bool allowRevert, bool allowClear,
@ -467,9 +467,9 @@ public class EquipmentDrawer
(true, true, true) => ("Right-click to clear. Control and Right-Click to revert to game.", revertItem, true), (true, true, true) => ("Right-click to clear. Control and Right-Click to revert to game.", revertItem, true),
(true, true, false) => ("Right-click to clear. Control and Right-Click to revert to game.", clearItem, true), (true, true, false) => ("Right-click to clear. Control and Right-Click to revert to game.", clearItem, true),
(true, false, true) => ("Control and Right-Click to revert to game.", revertItem, true), (true, false, true) => ("Control and Right-Click to revert to game.", revertItem, true),
(true, false, false) => ("Control and Right-Click to revert to game.", (T?)default, false), (true, false, false) => ("Control and Right-Click to revert to game.", default, false),
(false, true, _) => ("Right-click to clear.", clearItem, true), (false, true, _) => ("Right-click to clear.", clearItem, true),
(false, false, _) => (string.Empty, (T?)default, false), (false, false, _) => (string.Empty, default, false),
}; };
ImGuiUtil.HoverTooltip(tt); ImGuiUtil.HoverTooltip(tt);
@ -502,11 +502,11 @@ public class EquipmentDrawer
if (changedItem != null) if (changedItem != null)
{ {
mainhand.ItemSetter(changedItem.Value); mainhand.SetItem(changedItem.Value);
if (changedItem.Value.Type.ValidOffhand() != mainhand.CurrentItem.Type.ValidOffhand()) if (changedItem.Value.Type.ValidOffhand() != mainhand.CurrentItem.Type.ValidOffhand())
{ {
offhand.CurrentItem = _items.GetDefaultOffhand(changedItem.Value); offhand.CurrentItem = _items.GetDefaultOffhand(changedItem.Value);
offhand.ItemSetter(offhand.CurrentItem); offhand.SetItem(offhand.CurrentItem);
} }
mainhand.CurrentItem = changedItem.Value; mainhand.CurrentItem = changedItem.Value;
@ -533,18 +533,18 @@ public class EquipmentDrawer
UiHelpers.OpenCombo($"##{combo.Label}"); UiHelpers.OpenCombo($"##{combo.Label}");
if (combo.Draw(offhand.CurrentItem.Name, offhand.CurrentItem.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength, if (combo.Draw(offhand.CurrentItem.Name, offhand.CurrentItem.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength,
_requiredComboWidth)) _requiredComboWidth))
offhand.ItemSetter(combo.CurrentSelection); offhand.SetItem(combo.CurrentSelection);
var defaultOffhand = _items.GetDefaultOffhand(mainhand.CurrentItem); var defaultOffhand = _items.GetDefaultOffhand(mainhand.CurrentItem);
if (ResetOrClear(locked, open, offhand.AllowRevert, true, offhand.CurrentItem, offhand.GameItem, defaultOffhand, out var item)) if (ResetOrClear(locked, clear, offhand.AllowRevert, true, offhand.CurrentItem, offhand.GameItem, defaultOffhand, out var item))
offhand.ItemSetter(item); offhand.SetItem(item);
} }
private static void DrawApply(in EquipDrawData data) private static void DrawApply(in EquipDrawData data)
{ {
if (UiHelpers.DrawCheckbox($"##apply{data.Slot}", "Apply this item when applying the Design.", data.CurrentApply, out var enabled, if (UiHelpers.DrawCheckbox($"##apply{data.Slot}", "Apply this item when applying the Design.", data.CurrentApply, out var enabled,
data.Locked)) data.Locked))
data.ApplySetter(enabled); data.SetApplyItem(enabled);
} }
private static void DrawApplyStain(in EquipDrawData data) private static void DrawApplyStain(in EquipDrawData data)
@ -552,7 +552,7 @@ public class EquipmentDrawer
if (UiHelpers.DrawCheckbox($"##applyStain{data.Slot}", "Apply this item when applying the Design.", data.CurrentApplyStain, if (UiHelpers.DrawCheckbox($"##applyStain{data.Slot}", "Apply this item when applying the Design.", data.CurrentApplyStain,
out var enabled, out var enabled,
data.Locked)) data.Locked))
data.ApplyStainSetter(enabled); data.SetApplyStain(enabled);
} }
#endregion #endregion

View file

@ -256,7 +256,7 @@ public class DesignPanel(
{ {
var apply = bigChange ? ((EquipFlag)flags).HasFlag(slot.ToFlag()) : _selector.Selected!.DoApplyEquip(slot); var apply = bigChange ? ((EquipFlag)flags).HasFlag(slot.ToFlag()) : _selector.Selected!.DoApplyEquip(slot);
if (ImGui.Checkbox($"Apply {slot.ToName()}", ref apply) || bigChange) if (ImGui.Checkbox($"Apply {slot.ToName()}", ref apply) || bigChange)
_manager.ChangeApplyEquip(_selector.Selected!, slot, apply); _manager.ChangeApplyItem(_selector.Selected!, slot, apply);
} }
} }

View file

@ -4,74 +4,109 @@ using Penumbra.GameData.Enums;
namespace Glamourer.Gui; namespace Glamourer.Gui;
public ref struct ToggleDrawData public struct ToggleDrawData
{ {
private IDesignEditor _editor = null!;
private object _data = null!;
private StateIndex _index;
public bool Locked; public bool Locked;
public bool DisplayApplication; public bool DisplayApplication;
public bool CurrentValue; public bool CurrentValue;
public bool CurrentApply; public bool CurrentApply;
public Action<bool> SetValue = null!;
public Action<bool> SetApply = null!;
public string Label = string.Empty; public string Label = string.Empty;
public string Tooltip = string.Empty; public string Tooltip = string.Empty;
public ToggleDrawData() public ToggleDrawData()
{ } { }
public readonly void SetValue(bool value)
{
switch (_index.GetFlag())
{
case MetaIndex index:
_editor.ChangeMetaState(_data, index, value, ApplySettings.Manual);
break;
case CrestFlag flag:
_editor.ChangeCrest(_data, flag, value, ApplySettings.Manual);
break;
}
}
public readonly void SetApply(bool value)
{
var manager = (DesignManager)_editor;
var design = (Design)_data;
switch (_index.GetFlag())
{
case MetaIndex index:
manager.ChangeApplyMeta(design, index, value);
break;
case CrestFlag flag:
manager.ChangeApplyCrest(design, flag, value);
break;
}
}
public static ToggleDrawData FromDesign(MetaIndex index, DesignManager manager, Design design) public static ToggleDrawData FromDesign(MetaIndex index, DesignManager manager, Design design)
=> new() => new()
{ {
_index = index,
_editor = manager,
_data = design,
Label = index.ToName(), Label = index.ToName(),
Tooltip = string.Empty, Tooltip = string.Empty,
Locked = design.WriteProtected(), Locked = design.WriteProtected(),
DisplayApplication = true, DisplayApplication = true,
CurrentValue = design.DesignData.GetMeta(index), CurrentValue = design.DesignData.GetMeta(index),
CurrentApply = design.DoApplyMeta(index), CurrentApply = design.DoApplyMeta(index),
SetValue = b => manager.ChangeMetaState(design, index, b), };
SetApply = b => manager.ChangeApplyMeta(design, index, b),
public static ToggleDrawData FromState(MetaIndex index, StateManager manager, ActorState state)
=> new()
{
_index = index,
_editor = manager,
_data = state,
Label = index.ToName(),
Tooltip = index.ToTooltip(),
Locked = state.IsLocked,
CurrentValue = state.ModelData.GetMeta(index),
}; };
public static ToggleDrawData CrestFromDesign(CrestFlag slot, DesignManager manager, Design design) public static ToggleDrawData CrestFromDesign(CrestFlag slot, DesignManager manager, Design design)
=> new() => new()
{ {
_index = slot,
_editor = manager,
_data = design,
Label = $"{slot.ToLabel()} Crest", Label = $"{slot.ToLabel()} Crest",
Tooltip = string.Empty, Tooltip = string.Empty,
Locked = design.WriteProtected(), Locked = design.WriteProtected(),
DisplayApplication = true, DisplayApplication = true,
CurrentValue = design.DesignData.Crest(slot), CurrentValue = design.DesignData.Crest(slot),
CurrentApply = design.DoApplyCrest(slot), CurrentApply = design.DoApplyCrest(slot),
SetValue = v => manager.ChangeCrest(design, slot, v),
SetApply = v => manager.ChangeApplyCrest(design, slot, v),
}; };
public static ToggleDrawData CrestFromState(CrestFlag slot, StateManager manager, ActorState state) public static ToggleDrawData CrestFromState(CrestFlag slot, StateManager manager, ActorState state)
=> new() => new()
{ {
_index = slot,
_editor = manager,
_data = state,
Label = $"{slot.ToLabel()} Crest", Label = $"{slot.ToLabel()} Crest",
Tooltip = "Hide or show your free company crest on this piece of gear.", Tooltip = "Hide or show your free company crest on this piece of gear.",
Locked = state.IsLocked, Locked = state.IsLocked,
CurrentValue = state.ModelData.Crest(slot), CurrentValue = state.ModelData.Crest(slot),
SetValue = v => manager.ChangeCrest(state, slot, v, ApplySettings.Manual),
}; };
public static ToggleDrawData FromState(MetaIndex index, StateManager manager, ActorState state)
{
return new ToggleDrawData
{
Label = index.ToName(),
Tooltip = index.ToTooltip(),
Locked = state.IsLocked,
CurrentValue = state.ModelData.GetMeta(index),
SetValue = b => manager.ChangeMetaState(state, index, b, ApplySettings.Manual),
};
}
public static ToggleDrawData FromValue(MetaIndex index, bool value) public static ToggleDrawData FromValue(MetaIndex index, bool value)
=> new() => new()
{ {
_index = index,
Label = index.ToName(), Label = index.ToName(),
Tooltip = index.ToTooltip(), Tooltip = index.ToTooltip(),
Locked = true, Locked = true,

View file

@ -39,9 +39,7 @@ public class StateEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeCustomize(object data, CustomizeIndex idx, CustomizeValue value, ApplySettings settings) public void ChangeCustomize(object data, CustomizeIndex idx, CustomizeValue value, ApplySettings settings)
{ {
if (data is not ActorState state) var state = (ActorState)data;
return;
if (!Editor.ChangeCustomize(state, idx, value, settings.Source, out var old, settings.Key)) if (!Editor.ChangeCustomize(state, idx, value, settings.Source, out var old, settings.Key))
return; return;
@ -54,9 +52,7 @@ public class StateEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeEntireCustomize(object data, in CustomizeArray customizeInput, CustomizeFlag apply, ApplySettings settings) public void ChangeEntireCustomize(object data, in CustomizeArray customizeInput, CustomizeFlag apply, ApplySettings settings)
{ {
if (data is not ActorState state) var state = (ActorState)data;
return;
if (!Editor.ChangeHumanCustomize(state, customizeInput, apply, _ => settings.Source, out var old, out var applied, settings.Key)) if (!Editor.ChangeHumanCustomize(state, customizeInput, apply, _ => settings.Source, out var old, out var applied, settings.Key))
return; return;
@ -69,9 +65,7 @@ public class StateEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeItem(object data, EquipSlot slot, EquipItem item, ApplySettings settings = default) public void ChangeItem(object data, EquipSlot slot, EquipItem item, ApplySettings settings = default)
{ {
if (data is not ActorState state) var state = (ActorState)data;
return;
if (!Editor.ChangeItem(state, slot, item, settings.Source, out var old, settings.Key)) if (!Editor.ChangeItem(state, slot, item, settings.Source, out var old, settings.Key))
return; return;
@ -103,9 +97,7 @@ public class StateEditor(
return; return;
} }
if (data is not ActorState state) var state = (ActorState)data;
return;
if (!Editor.ChangeEquip(state, slot, item ?? state.ModelData.Item(slot), stain ?? state.ModelData.Stain(slot), settings.Source, if (!Editor.ChangeEquip(state, slot, item ?? state.ModelData.Item(slot), stain ?? state.ModelData.Stain(slot), settings.Source,
out var old, out var oldStain, settings.Key)) out var old, out var oldStain, settings.Key))
return; return;
@ -128,9 +120,7 @@ public class StateEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeStain(object data, EquipSlot slot, StainId stain, ApplySettings settings) public void ChangeStain(object data, EquipSlot slot, StainId stain, ApplySettings settings)
{ {
if (data is not ActorState state) var state = (ActorState)data;
return;
if (!Editor.ChangeStain(state, slot, stain, settings.Source, out var old, settings.Key)) if (!Editor.ChangeStain(state, slot, stain, settings.Source, out var old, settings.Key))
return; return;
@ -143,9 +133,7 @@ public class StateEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeCrest(object data, CrestFlag slot, bool crest, ApplySettings settings) public void ChangeCrest(object data, CrestFlag slot, bool crest, ApplySettings settings)
{ {
if (data is not ActorState state) var state = (ActorState)data;
return;
if (!Editor.ChangeCrest(state, slot, crest, settings.Source, out var old, settings.Key)) if (!Editor.ChangeCrest(state, slot, crest, settings.Source, out var old, settings.Key))
return; return;
@ -178,9 +166,7 @@ public class StateEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ChangeMetaState(object data, MetaIndex index, bool value, ApplySettings settings) public void ChangeMetaState(object data, MetaIndex index, bool value, ApplySettings settings)
{ {
if (data is not ActorState state) var state = (ActorState)data;
return;
if (!Editor.ChangeMetaState(state, index, value, settings.Source, out var old, settings.Key)) if (!Editor.ChangeMetaState(state, index, value, settings.Source, out var old, settings.Key))
return; return;
@ -193,9 +179,7 @@ public class StateEditor(
/// <inheritdoc/> /// <inheritdoc/>
public void ApplyDesign(object data, MergedDesign mergedDesign, ApplySettings settings) public void ApplyDesign(object data, MergedDesign mergedDesign, ApplySettings settings)
{ {
if (data is not ActorState state) var state = (ActorState)data;
return;
if (!Editor.ChangeModelId(state, mergedDesign.Design.DesignData.ModelId, mergedDesign.Design.DesignData.Customize, if (!Editor.ChangeModelId(state, mergedDesign.Design.DesignData.ModelId, mergedDesign.Design.DesignData.Customize,
mergedDesign.Design.GetDesignDataRef().GetEquipmentPtr(), settings.Source, out var oldModelId, settings.Key)) mergedDesign.Design.GetDesignDataRef().GetEquipmentPtr(), settings.Source, out var oldModelId, settings.Key))
return; return;