Make IMC handling even better.

This commit is contained in:
Ottermandias 2024-05-24 16:15:04 +02:00
parent 65627b5002
commit 4743acf767
15 changed files with 437 additions and 459 deletions

View file

@ -19,9 +19,6 @@ public partial class ModEditWindow
private const string ModelSetIdTooltip =
"Model Set ID - You can usually find this as the 'e####' part of an item path.\nThis should generally not be left <= 1 unless you explicitly want that.";
private const string PrimaryIdTooltip =
"Primary ID - You can usually find this as the 'x####' part of an item path.\nThis should generally not be left <= 1 unless you explicitly want that.";
private const string ModelSetIdTooltipShort = "Model Set ID";
private const string EquipSlotTooltip = "Equip Slot";
private const string ModelRaceTooltip = "Model Race";
@ -316,7 +313,7 @@ public partial class ModEditWindow
private static class ImcRow
{
private static ImcManipulation _new = new(EquipSlot.Head, 1, 1, new ImcEntry());
private static ImcIdentifier _newIdentifier = ImcIdentifier.Default;
private static float IdWidth
=> 80 * UiHelpers.Scale;
@ -324,75 +321,60 @@ public partial class ModEditWindow
private static float SmallIdWidth
=> 45 * UiHelpers.Scale;
/// <summary> Convert throwing to null-return if the file does not exist. </summary>
private static ImcEntry? GetDefault(MetaFileManager metaFileManager, ImcManipulation imc)
{
try
{
return ImcFile.GetDefault(metaFileManager, imc.GamePath(), imc.EquipSlot, imc.Variant, out _);
}
catch
{
return null;
}
}
public static void DrawNew(MetaFileManager metaFileManager, ModEditor editor, Vector2 iconSize)
{
ImGui.TableNextColumn();
CopyToClipboardButton("Copy all current IMC manipulations to clipboard.", iconSize,
editor.MetaEditor.Imc.Select(m => (MetaManipulation)m));
ImGui.TableNextColumn();
var defaultEntry = GetDefault(metaFileManager, _new);
var canAdd = defaultEntry != null && editor.MetaEditor.CanAdd(_new);
var tt = canAdd ? "Stage this edit." : defaultEntry == null ? "This IMC file does not exist." : "This entry is already edited.";
defaultEntry ??= new ImcEntry();
var (defaultEntry, fileExists, _) = metaFileManager.ImcChecker.GetDefaultEntry(_newIdentifier, true);
var manip = (MetaManipulation)new ImcManipulation(_newIdentifier, defaultEntry);
var canAdd = fileExists && editor.MetaEditor.CanAdd(manip);
var tt = canAdd ? "Stage this edit." : !fileExists ? "This IMC file does not exist." : "This entry is already edited.";
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Plus.ToIconString(), iconSize, tt, !canAdd, true))
editor.MetaEditor.Add(_new.Copy(defaultEntry.Value));
editor.MetaEditor.Add(manip);
// Identifier
ImGui.TableNextColumn();
var change = ImcManipulationDrawer.DrawObjectType(ref _new);
var change = ImcManipulationDrawer.DrawObjectType(ref _newIdentifier);
ImGui.TableNextColumn();
change |= ImcManipulationDrawer.DrawPrimaryId(ref _new);
change |= ImcManipulationDrawer.DrawPrimaryId(ref _newIdentifier);
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing,
new Vector2(3 * UiHelpers.Scale, ImGui.GetStyle().ItemSpacing.Y));
ImGui.TableNextColumn();
// Equipment and accessories are slightly different imcs than other types.
if (_new.ObjectType is ObjectType.Equipment or ObjectType.Accessory)
change |= ImcManipulationDrawer.DrawSlot(ref _new);
if (_newIdentifier.ObjectType is ObjectType.Equipment or ObjectType.Accessory)
change |= ImcManipulationDrawer.DrawSlot(ref _newIdentifier);
else
change |= ImcManipulationDrawer.DrawSecondaryId(ref _new);
change |= ImcManipulationDrawer.DrawSecondaryId(ref _newIdentifier);
ImGui.TableNextColumn();
change |= ImcManipulationDrawer.DrawVariant(ref _new);
change |= ImcManipulationDrawer.DrawVariant(ref _newIdentifier);
ImGui.TableNextColumn();
if (_new.ObjectType is ObjectType.DemiHuman)
change |= ImcManipulationDrawer.DrawSlot(ref _new, 70);
if (_newIdentifier.ObjectType is ObjectType.DemiHuman)
change |= ImcManipulationDrawer.DrawSlot(ref _newIdentifier, 70);
else
ImGui.Dummy(new Vector2(70 * UiHelpers.Scale, 0));
if (change)
_new = _new.Copy(GetDefault(metaFileManager, _new) ?? new ImcEntry());
defaultEntry = metaFileManager.ImcChecker.GetDefaultEntry(_newIdentifier, true).Entry;
// Values
using var disabled = ImRaii.Disabled();
var entry = defaultEntry.Value;
ImGui.TableNextColumn();
ImcManipulationDrawer.DrawMaterialId(entry, ref entry, false);
ImcManipulationDrawer.DrawMaterialId(defaultEntry, ref defaultEntry, false);
ImGui.SameLine();
ImcManipulationDrawer.DrawMaterialAnimationId(entry, ref entry, false);
ImcManipulationDrawer.DrawMaterialAnimationId(defaultEntry, ref defaultEntry, false);
ImGui.TableNextColumn();
ImcManipulationDrawer.DrawDecalId(entry, ref entry, false);
ImcManipulationDrawer.DrawDecalId(defaultEntry, ref defaultEntry, false);
ImGui.SameLine();
ImcManipulationDrawer.DrawVfxId(entry, ref entry, false);
ImcManipulationDrawer.DrawVfxId(defaultEntry, ref defaultEntry, false);
ImGui.SameLine();
ImcManipulationDrawer.DrawSoundId(entry, ref entry, false);
ImcManipulationDrawer.DrawSoundId(defaultEntry, ref defaultEntry, false);
ImGui.TableNextColumn();
ImcManipulationDrawer.DrawAttributes(entry, ref entry);
ImcManipulationDrawer.DrawAttributes(defaultEntry, ref defaultEntry);
}
public static void Draw(MetaFileManager metaFileManager, ImcManipulation meta, ModEditor editor, Vector2 iconSize)
@ -439,10 +421,9 @@ public partial class ModEditWindow
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing,
new Vector2(3 * UiHelpers.Scale, ImGui.GetStyle().ItemSpacing.Y));
ImGui.TableNextColumn();
var defaultEntry = GetDefault(metaFileManager, meta) ?? new ImcEntry();
var defaultEntry = metaFileManager.ImcChecker.GetDefaultEntry(meta.Identifier, true).Entry;
var newEntry = meta.Entry;
var changes = ImcManipulationDrawer.DrawMaterialId(defaultEntry, ref newEntry, true);
var changes = ImcManipulationDrawer.DrawMaterialId(defaultEntry, ref newEntry, true);
ImGui.SameLine();
changes |= ImcManipulationDrawer.DrawMaterialAnimationId(defaultEntry, ref newEntry, true);
ImGui.TableNextColumn();

View file

@ -5,7 +5,6 @@ using Penumbra.Api.Enums;
using Penumbra.GameData.Enums;
using Penumbra.GameData.Structs;
using Penumbra.Meta;
using Penumbra.Meta.Files;
using Penumbra.Meta.Manipulations;
using Penumbra.Mods;
using Penumbra.Mods.Manager;
@ -17,20 +16,20 @@ namespace Penumbra.UI.ModsTab.Groups;
public class AddGroupDrawer : IUiService
{
private string _groupName = string.Empty;
private bool _groupNameValid = false;
private bool _groupNameValid;
private ImcManipulation _imcManip = new(EquipSlot.Head, 1, 1, new ImcEntry());
private ImcEntry _defaultEntry;
private bool _imcFileExists;
private bool _entryExists;
private bool _entryInvalid;
private readonly MetaFileManager _metaManager;
private readonly ModManager _modManager;
private ImcIdentifier _imcIdentifier = ImcIdentifier.Default;
private ImcEntry _defaultEntry;
private bool _imcFileExists;
private bool _entryExists;
private bool _entryInvalid;
private readonly ImcChecker _imcChecker;
private readonly ModManager _modManager;
public AddGroupDrawer(MetaFileManager metaManager, ModManager modManager)
public AddGroupDrawer(ModManager modManager, ImcChecker imcChecker)
{
_metaManager = metaManager;
_modManager = modManager;
_imcChecker = imcChecker;
UpdateEntry();
}
@ -61,7 +60,7 @@ public class AddGroupDrawer : IUiService
return;
_modManager.OptionEditor.AddModGroup(mod, GroupType.Single, _groupName);
_groupName = string.Empty;
_groupName = string.Empty;
_groupNameValid = false;
}
@ -74,35 +73,35 @@ public class AddGroupDrawer : IUiService
return;
_modManager.OptionEditor.AddModGroup(mod, GroupType.Multi, _groupName);
_groupName = string.Empty;
_groupName = string.Empty;
_groupNameValid = false;
}
private void DrawImcInput(float width)
{
var change = ImcManipulationDrawer.DrawObjectType(ref _imcManip, width);
var change = ImcManipulationDrawer.DrawObjectType(ref _imcIdentifier, width);
ImUtf8.SameLineInner();
change |= ImcManipulationDrawer.DrawPrimaryId(ref _imcManip, width);
if (_imcManip.ObjectType is ObjectType.Weapon or ObjectType.Monster)
change |= ImcManipulationDrawer.DrawPrimaryId(ref _imcIdentifier, width);
if (_imcIdentifier.ObjectType is ObjectType.Weapon or ObjectType.Monster)
{
change |= ImcManipulationDrawer.DrawSecondaryId(ref _imcManip, width);
change |= ImcManipulationDrawer.DrawSecondaryId(ref _imcIdentifier, width);
ImUtf8.SameLineInner();
change |= ImcManipulationDrawer.DrawVariant(ref _imcManip, width);
change |= ImcManipulationDrawer.DrawVariant(ref _imcIdentifier, width);
}
else if (_imcManip.ObjectType is ObjectType.DemiHuman)
else if (_imcIdentifier.ObjectType is ObjectType.DemiHuman)
{
var quarterWidth = (width - ImUtf8.ItemInnerSpacing.X / ImUtf8.GlobalScale) / 2;
change |= ImcManipulationDrawer.DrawSecondaryId(ref _imcManip, width);
change |= ImcManipulationDrawer.DrawSecondaryId(ref _imcIdentifier, width);
ImUtf8.SameLineInner();
change |= ImcManipulationDrawer.DrawSlot(ref _imcManip, quarterWidth);
change |= ImcManipulationDrawer.DrawSlot(ref _imcIdentifier, quarterWidth);
ImUtf8.SameLineInner();
change |= ImcManipulationDrawer.DrawVariant(ref _imcManip, quarterWidth);
change |= ImcManipulationDrawer.DrawVariant(ref _imcIdentifier, quarterWidth);
}
else
{
change |= ImcManipulationDrawer.DrawSlot(ref _imcManip, width);
change |= ImcManipulationDrawer.DrawSlot(ref _imcIdentifier, width);
ImUtf8.SameLineInner();
change |= ImcManipulationDrawer.DrawVariant(ref _imcManip, width);
change |= ImcManipulationDrawer.DrawVariant(ref _imcIdentifier, width);
}
if (change)
@ -125,8 +124,8 @@ public class AddGroupDrawer : IUiService
: "Add a new multi selection option group to this mod."u8,
width, !_groupNameValid || _entryInvalid))
{
_modManager.OptionEditor.ImcEditor.AddModGroup(mod, _groupName, _imcManip);
_groupName = string.Empty;
_modManager.OptionEditor.ImcEditor.AddModGroup(mod, _groupName, _imcIdentifier, _defaultEntry);
_groupName = string.Empty;
_groupNameValid = false;
}
@ -142,20 +141,7 @@ public class AddGroupDrawer : IUiService
private void UpdateEntry()
{
try
{
_defaultEntry = ImcFile.GetDefault(_metaManager, _imcManip.GamePath(), _imcManip.EquipSlot, _imcManip.Variant,
out _entryExists);
_imcFileExists = true;
}
catch (Exception)
{
_defaultEntry = new ImcEntry();
_imcFileExists = false;
_entryExists = false;
}
_imcManip = _imcManip.Copy(_entryExists ? _defaultEntry : new ImcEntry());
_entryInvalid = !_imcManip.Validate(true);
(_defaultEntry, _imcFileExists, _entryExists) = _imcChecker.GetDefaultEntry(_imcIdentifier, false);
_entryInvalid = !_imcIdentifier.Validate() || _defaultEntry.MaterialId == 0 || !_entryExists;
}
}

View file

@ -1,10 +1,8 @@
using Dalamud.Interface;
using ImGuiNET;
using OtterGui;
using OtterGui.Classes;
using OtterGui.Raii;
using OtterGui.Text;
using Penumbra.GameData.Enums;
using Penumbra.GameData.Structs;
using Penumbra.Mods.Groups;
using Penumbra.Mods.Manager.OptionEditor;
@ -16,59 +14,75 @@ public readonly struct ImcModGroupEditDrawer(ModGroupEditDrawer editor, ImcModGr
{
public void Draw()
{
var identifier = group.Identifier;
var defaultEntry = editor.ImcChecker.GetDefaultEntry(identifier, true).Entry;
var entry = group.DefaultEntry;
var changes = false;
ImUtf8.TextFramed(identifier.ToString(), 0, editor.AvailableWidth, borderColor: ImGui.GetColorU32(ImGuiCol.Border));
using (ImUtf8.Group())
{
ImUtf8.Text("Object Type"u8);
if (group.ObjectType is ObjectType.Equipment or ObjectType.Accessory or ObjectType.DemiHuman)
ImUtf8.Text("Slot"u8);
ImUtf8.Text("Primary ID");
if (group.ObjectType is not ObjectType.Equipment and not ObjectType.Accessory)
ImUtf8.Text("Secondary ID");
ImUtf8.Text("Variant"u8);
ImUtf8.TextFrameAligned("Material ID"u8);
ImUtf8.TextFrameAligned("Material Animation ID"u8);
ImUtf8.TextFrameAligned("Decal ID"u8);
ImUtf8.TextFrameAligned("VFX ID"u8);
ImUtf8.TextFrameAligned("Decal ID"u8);
}
ImGui.SameLine();
using (ImUtf8.Group())
{
changes |= ImcManipulationDrawer.DrawMaterialId(defaultEntry, ref entry, true);
changes |= ImcManipulationDrawer.DrawVfxId(defaultEntry, ref entry, true);
changes |= ImcManipulationDrawer.DrawDecalId(defaultEntry, ref entry, true);
}
ImGui.SameLine(0, editor.PriorityWidth);
using (ImUtf8.Group())
{
ImUtf8.TextFrameAligned("Material Animation ID"u8);
ImUtf8.TextFrameAligned("Sound ID"u8);
ImUtf8.TextFrameAligned("Can Be Disabled"u8);
ImUtf8.TextFrameAligned("Default Attributes"u8);
}
ImGui.SameLine();
using (ImUtf8.Group())
{
changes |= ImcManipulationDrawer.DrawMaterialAnimationId(defaultEntry, ref entry, true);
changes |= ImcManipulationDrawer.DrawSoundId(defaultEntry, ref entry, true);
var canBeDisabled = group.CanBeDisabled;
if (ImUtf8.Checkbox("##disabled"u8, ref canBeDisabled))
editor.ModManager.OptionEditor.ImcEditor.ChangeCanBeDisabled(group, canBeDisabled);
}
if (changes)
editor.ModManager.OptionEditor.ImcEditor.ChangeDefaultEntry(group, entry);
ImGui.Dummy(Vector2.Zero);
DrawOptions();
var attributeCache = new ImcAttributeCache(group);
DrawNewOption(attributeCache);
ImGui.Dummy(Vector2.Zero);
using (ImUtf8.Group())
{
ImUtf8.Text(group.ObjectType.ToName());
if (group.ObjectType is ObjectType.Equipment or ObjectType.Accessory or ObjectType.DemiHuman)
ImUtf8.Text(group.EquipSlot.ToName());
ImUtf8.Text($"{group.PrimaryId.Id}");
if (group.ObjectType is not ObjectType.Equipment and not ObjectType.Accessory)
ImUtf8.Text($"{group.SecondaryId.Id}");
ImUtf8.Text($"{group.Variant.Id}");
ImUtf8.TextFrameAligned($"{group.DefaultEntry.MaterialId}");
ImUtf8.TextFrameAligned($"{group.DefaultEntry.MaterialAnimationId}");
ImUtf8.TextFrameAligned($"{group.DefaultEntry.DecalId}");
ImUtf8.TextFrameAligned($"{group.DefaultEntry.VfxId}");
ImUtf8.TextFrameAligned($"{group.DefaultEntry.SoundId}");
var canBeDisabled = group.CanBeDisabled;
if (ImUtf8.Checkbox("##disabled"u8, ref canBeDisabled))
editor.ModManager.OptionEditor.ImcEditor.ChangeCanBeDisabled(group, canBeDisabled, SaveType.Queue);
var defaultDisabled = group.DefaultDisabled;
ImUtf8.SameLineInner();
if (ImUtf8.Checkbox("##defaultDisabled"u8, ref defaultDisabled))
editor.ModManager.OptionEditor.ChangeModGroupDefaultOption(group,
group.DefaultSettings.SetBit(ImcModGroup.DisabledIndex, defaultDisabled));
DrawAttributes(editor.ModManager.OptionEditor.ImcEditor, attributeCache, group.DefaultEntry.AttributeMask, group);
ImUtf8.TextFrameAligned("Default Attributes"u8);
foreach (var option in group.OptionData.Where(o => !o.IsDisableSubMod))
ImUtf8.TextFrameAligned(option.Name);
}
ImUtf8.SameLineInner();
using (ImUtf8.Group())
{
DrawAttributes(editor.ModManager.OptionEditor.ImcEditor, attributeCache, group.DefaultEntry.AttributeMask, group);
foreach (var option in group.OptionData.Where(o => !o.IsDisableSubMod))
DrawAttributes(editor.ModManager.OptionEditor.ImcEditor, attributeCache, option.AttributeMask, option);
}
}
private void DrawOptions()
{
foreach (var (option, optionIdx) in group.OptionData.WithIndex())
{
using var id = ImRaii.PushId(optionIdx);
@ -83,56 +97,51 @@ public readonly struct ImcModGroupEditDrawer(ModGroupEditDrawer editor, ImcModGr
ImUtf8.SameLineInner();
editor.DrawOptionDescription(option);
ImUtf8.SameLineInner();
editor.DrawOptionDelete(option);
ImUtf8.SameLineInner();
ImGui.Dummy(new Vector2(editor.PriorityWidth, 0));
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + editor.OptionIdxSelectable.X + ImUtf8.ItemInnerSpacing.X * 2 + ImUtf8.FrameHeight);
DrawAttributes(editor.ModManager.OptionEditor.ImcEditor, attributeCache, option.AttributeMask, option);
}
DrawNewOption(attributeCache);
return;
static void DrawAttributes(ImcModGroupEditor editor, in ImcAttributeCache cache, ushort mask, object data)
{
for (var i = 0; i < ImcEntry.NumAttributes; ++i)
if (!option.IsDisableSubMod)
{
using var id = ImRaii.PushId(i);
var value = (mask & 1 << i) != 0;
using (ImRaii.Disabled(!cache.CanChange(i)))
{
if (ImUtf8.Checkbox(TerminatedByteString.Empty, ref value))
{
if (data is ImcModGroup g)
editor.ChangeDefaultAttribute(g, cache, i, value);
else
editor.ChangeOptionAttribute((ImcSubMod)data, cache, i, value);
}
}
ImUtf8.HoverTooltip($"{(char)('A' + i)}");
if (i != 9)
ImUtf8.SameLineInner();
ImUtf8.SameLineInner();
editor.DrawOptionDelete(option);
}
}
}
private void DrawNewOption(in ImcAttributeCache cache)
{
if (cache.LowestUnsetMask == 0)
return;
var name = editor.DrawNewOptionBase(group, group.Options.Count);
var dis = cache.LowestUnsetMask == 0;
var name = editor.DrawNewOptionBase(group, group.Options.Count);
var validName = name.Length > 0;
if (ImUtf8.IconButton(FontAwesomeIcon.Plus, validName
var tt = dis
? "No Free Attribute Slots for New Options..."u8
: validName
? "Add a new option to this group."u8
: "Please enter a name for the new option."u8, !validName))
: "Please enter a name for the new option."u8;
if (ImUtf8.IconButton(FontAwesomeIcon.Plus, tt, !validName || dis))
{
editor.ModManager.OptionEditor.ImcEditor.AddOption(group, cache, name);
editor.NewOptionName = null;
}
}
private static void DrawAttributes(ImcModGroupEditor editor, in ImcAttributeCache cache, ushort mask, object data)
{
for (var i = 0; i < ImcEntry.NumAttributes; ++i)
{
using var id = ImRaii.PushId(i);
var value = (mask & (1 << i)) != 0;
using (ImRaii.Disabled(!cache.CanChange(i)))
{
if (ImUtf8.Checkbox(TerminatedByteString.Empty, ref value))
{
if (data is ImcModGroup g)
editor.ChangeDefaultAttribute(g, cache, i, value);
else
editor.ChangeOptionAttribute((ImcSubMod)data, cache, i, value);
}
}
ImUtf8.HoverTooltip("ABCDEFGHIJ"u8.Slice(i, 1));
if (i != 9)
ImUtf8.SameLineInner();
}
}
}

View file

@ -7,6 +7,7 @@ using OtterGui.Raii;
using OtterGui.Services;
using OtterGui.Text;
using OtterGui.Text.EndObjects;
using Penumbra.Meta;
using Penumbra.Mods;
using Penumbra.Mods.Groups;
using Penumbra.Mods.Manager;
@ -22,11 +23,16 @@ public sealed class ModGroupEditDrawer(
ModManager modManager,
Configuration config,
FilenameService filenames,
DescriptionEditPopup descriptionPopup) : IUiService
DescriptionEditPopup descriptionPopup,
ImcChecker imcChecker) : IUiService
{
private static ReadOnlySpan<byte> DragDropLabel
=> "##DragOption"u8;
private static ReadOnlySpan<byte> AcrossGroupsLabel
=> "##DragOptionAcross"u8;
private static ReadOnlySpan<byte> InsideGroupLabel
=> "##DragOptionInside"u8;
internal readonly ImcChecker ImcChecker = imcChecker;
internal readonly ModManager ModManager = modManager;
internal readonly Queue<Action> ActionQueue = new();
@ -50,6 +56,7 @@ public sealed class ModGroupEditDrawer(
private IModGroup? _dragDropGroup;
private IModOption? _dragDropOption;
private bool _draggingAcross;
public void Draw(Mod mod)
{
@ -292,32 +299,30 @@ public sealed class ModGroupEditDrawer(
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Source(IModOption option)
{
if (option.Group is not ITexToolsGroup)
return;
using var source = ImUtf8.DragDropSource();
if (!source)
return;
if (!DragDropSource.SetPayload(DragDropLabel))
var across = option.Group is ITexToolsGroup;
if (!DragDropSource.SetPayload(across ? AcrossGroupsLabel : InsideGroupLabel))
{
_dragDropGroup = option.Group;
_dragDropOption = option;
_draggingAcross = across;
}
ImGui.TextUnformatted($"Dragging option {option.Name} from group {option.Group.Name}...");
ImUtf8.Text($"Dragging option {option.Name} from group {option.Group.Name}...");
}
private void Target(IModGroup group, int optionIdx)
{
if (group is not ITexToolsGroup)
return;
if (_dragDropGroup != group && _dragDropGroup != null && group is MultiModGroup { Options.Count: >= IModGroup.MaxMultiOptions })
if (_dragDropGroup != group
&& (!_draggingAcross || (_dragDropGroup != null && group is MultiModGroup { Options.Count: >= IModGroup.MaxMultiOptions })))
return;
using var target = ImRaii.DragDropTarget();
if (!target.Success || !DragDropTarget.CheckPayload(DragDropLabel))
if (!target.Success || !DragDropTarget.CheckPayload(_draggingAcross ? AcrossGroupsLabel : InsideGroupLabel))
return;
if (_dragDropGroup != null && _dragDropOption != null)
@ -342,6 +347,7 @@ public sealed class ModGroupEditDrawer(
_dragDropGroup = null;
_dragDropOption = null;
_draggingAcross = false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,8 +1,6 @@
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using OtterGui.Text;
using OtterGui.Text.HelperObjects;
using Penumbra.GameData.Enums;
using Penumbra.GameData.Structs;
using Penumbra.Meta.Manipulations;
@ -12,79 +10,78 @@ namespace Penumbra.UI.ModsTab;
public static class ImcManipulationDrawer
{
public static bool DrawObjectType(ref ImcManipulation manip, float width = 110)
public static bool DrawObjectType(ref ImcIdentifier identifier, float width = 110)
{
var ret = Combos.ImcType("##imcType", manip.ObjectType, out var type, width);
var ret = Combos.ImcType("##imcType", identifier.ObjectType, out var type, width);
ImUtf8.HoverTooltip("Object Type"u8);
if (ret)
{
var equipSlot = type switch
{
ObjectType.Equipment => manip.EquipSlot.IsEquipment() ? manip.EquipSlot : EquipSlot.Head,
ObjectType.DemiHuman => manip.EquipSlot.IsEquipment() ? manip.EquipSlot : EquipSlot.Head,
ObjectType.Accessory => manip.EquipSlot.IsAccessory() ? manip.EquipSlot : EquipSlot.Ears,
ObjectType.Equipment => identifier.EquipSlot.IsEquipment() ? identifier.EquipSlot : EquipSlot.Head,
ObjectType.DemiHuman => identifier.EquipSlot.IsEquipment() ? identifier.EquipSlot : EquipSlot.Head,
ObjectType.Accessory => identifier.EquipSlot.IsAccessory() ? identifier.EquipSlot : EquipSlot.Ears,
_ => EquipSlot.Unknown,
};
manip = new ImcManipulation(type, manip.BodySlot, manip.PrimaryId, manip.SecondaryId == 0 ? 1 : manip.SecondaryId,
manip.Variant.Id, equipSlot, manip.Entry);
identifier = identifier with
{
EquipSlot = equipSlot,
SecondaryId = identifier.SecondaryId == 0 ? 1 : identifier.SecondaryId,
};
}
return ret;
}
public static bool DrawPrimaryId(ref ImcManipulation manip, float unscaledWidth = 80)
public static bool DrawPrimaryId(ref ImcIdentifier identifier, float unscaledWidth = 80)
{
var ret = IdInput("##imcPrimaryId"u8, unscaledWidth, manip.PrimaryId.Id, out var newId, 0, ushort.MaxValue,
manip.PrimaryId.Id <= 1);
var ret = IdInput("##imcPrimaryId"u8, unscaledWidth, identifier.PrimaryId.Id, out var newId, 0, ushort.MaxValue,
identifier.PrimaryId.Id <= 1);
ImUtf8.HoverTooltip("Primary ID - You can usually find this as the 'x####' part of an item path.\n"u8
+ "This should generally not be left <= 1 unless you explicitly want that."u8);
if (ret)
manip = new ImcManipulation(manip.ObjectType, manip.BodySlot, newId, manip.SecondaryId, manip.Variant.Id, manip.EquipSlot,
manip.Entry);
identifier = identifier with { PrimaryId = newId };
return ret;
}
public static bool DrawSecondaryId(ref ImcManipulation manip, float unscaledWidth = 100)
public static bool DrawSecondaryId(ref ImcIdentifier identifier, float unscaledWidth = 100)
{
var ret = IdInput("##imcSecondaryId"u8, unscaledWidth, manip.SecondaryId.Id, out var newId, 0, ushort.MaxValue, false);
var ret = IdInput("##imcSecondaryId"u8, unscaledWidth, identifier.SecondaryId.Id, out var newId, 0, ushort.MaxValue, false);
ImUtf8.HoverTooltip("Secondary ID"u8);
if (ret)
manip = new ImcManipulation(manip.ObjectType, manip.BodySlot, manip.PrimaryId, newId, manip.Variant.Id, manip.EquipSlot,
manip.Entry);
identifier = identifier with { SecondaryId = newId };
return ret;
}
public static bool DrawVariant(ref ImcManipulation manip, float unscaledWidth = 45)
public static bool DrawVariant(ref ImcIdentifier identifier, float unscaledWidth = 45)
{
var ret = IdInput("##imcVariant"u8, unscaledWidth, manip.Variant.Id, out var newId, 0, byte.MaxValue, false);
var ret = IdInput("##imcVariant"u8, unscaledWidth, identifier.Variant.Id, out var newId, 0, byte.MaxValue, false);
ImUtf8.HoverTooltip("Variant ID"u8);
if (ret)
manip = new ImcManipulation(manip.ObjectType, manip.BodySlot, manip.PrimaryId, manip.SecondaryId, (byte)newId, manip.EquipSlot,
manip.Entry);
identifier = identifier with { Variant = (byte)newId };
return ret;
}
public static bool DrawSlot(ref ImcManipulation manip, float unscaledWidth = 100)
public static bool DrawSlot(ref ImcIdentifier identifier, float unscaledWidth = 100)
{
bool ret;
EquipSlot slot;
switch (manip.ObjectType)
switch (identifier.ObjectType)
{
case ObjectType.Equipment:
case ObjectType.DemiHuman:
ret = Combos.EqpEquipSlot("##slot", manip.EquipSlot, out slot, unscaledWidth);
ret = Combos.EqpEquipSlot("##slot", identifier.EquipSlot, out slot, unscaledWidth);
break;
case ObjectType.Accessory:
ret = Combos.AccessorySlot("##slot", manip.EquipSlot, out slot, unscaledWidth);
ret = Combos.AccessorySlot("##slot", identifier.EquipSlot, out slot, unscaledWidth);
break;
default: return false;
}
ImUtf8.HoverTooltip("Equip Slot"u8);
if (ret)
manip = new ImcManipulation(manip.ObjectType, manip.BodySlot, manip.PrimaryId, manip.SecondaryId, manip.Variant.Id, slot,
manip.Entry);
identifier = identifier with { EquipSlot = slot };
return ret;
}