diff --git a/Penumbra/Mods/Manager/Mod.Manager.Options.cs b/Penumbra/Mods/Manager/Mod.Manager.Options.cs index 7c159820..b2ecdc54 100644 --- a/Penumbra/Mods/Manager/Mod.Manager.Options.cs +++ b/Penumbra/Mods/Manager/Mod.Manager.Options.cs @@ -87,7 +87,7 @@ public sealed partial class Mod { foreach( var (group, groupIdx) in mod._groups.WithIndex().Skip( fromGroup ) ) { - foreach( var (o, optionIdx) in group.OfType().WithIndex() ) + foreach( var (o, optionIdx) in group.OfType< SubMod >().WithIndex() ) { o.SetPosition( groupIdx, optionIdx ); } @@ -175,18 +175,19 @@ public sealed partial class Mod public void AddOption( Mod mod, int groupIdx, string newName ) { - var group = mod._groups[groupIdx]; + var group = mod._groups[ groupIdx ]; + var subMod = new SubMod( mod ) { Name = newName }; + subMod.SetPosition( groupIdx, group.Count ); switch( group ) { case SingleModGroup s: - s.OptionData.Add( new SubMod(mod) { Name = newName } ); + s.OptionData.Add( subMod ); break; case MultiModGroup m: - m.PrioritizedOptions.Add( ( new SubMod(mod) { Name = newName }, 0 ) ); + m.PrioritizedOptions.Add( ( subMod, 0 ) ); break; } - group.UpdatePositions( group.Count - 1 ); ModOptionChanged.Invoke( ModOptionChangeType.OptionAdded, mod, groupIdx, group.Count - 1, -1 ); } @@ -206,6 +207,8 @@ public sealed partial class Mod return; } + o.SetPosition( groupIdx, group.Count ); + switch( group ) { case SingleModGroup s: @@ -215,13 +218,13 @@ public sealed partial class Mod m.PrioritizedOptions.Add( ( o, priority ) ); break; } - group.UpdatePositions( group.Count - 1 ); + ModOptionChanged.Invoke( ModOptionChangeType.OptionAdded, mod, groupIdx, group.Count - 1, -1 ); } public void DeleteOption( Mod mod, int groupIdx, int optionIdx ) { - var group = mod._groups[groupIdx]; + var group = mod._groups[ groupIdx ]; ModOptionChanged.Invoke( ModOptionChangeType.PrepareChange, mod, groupIdx, optionIdx, -1 ); switch( group ) { @@ -233,6 +236,7 @@ public sealed partial class Mod m.PrioritizedOptions.RemoveAt( optionIdx ); break; } + group.UpdatePositions( optionIdx ); ModOptionChanged.Invoke( ModOptionChangeType.OptionDeleted, mod, groupIdx, optionIdx, -1 ); } @@ -332,6 +336,11 @@ public sealed partial class Mod private static void OnModOptionChange( ModOptionChangeType type, Mod mod, int groupIdx, int _, int _2 ) { + if( type == ModOptionChangeType.PrepareChange ) + { + return; + } + // File deletion is handled in the actual function. if( type is ModOptionChangeType.GroupDeleted or ModOptionChangeType.GroupMoved ) { diff --git a/Penumbra/UI/ConfigWindow.ModPanel.Edit.cs b/Penumbra/UI/ConfigWindow.ModPanel.Edit.cs index 10bb3bd4..4a3fec24 100644 --- a/Penumbra/UI/ConfigWindow.ModPanel.Edit.cs +++ b/Penumbra/UI/ConfigWindow.ModPanel.Edit.cs @@ -477,7 +477,7 @@ public partial class ConfigWindow EditOption( panel, group, groupIdx, optionIdx ); } - DrawNewOption( panel._mod, groupIdx, panel._window._iconButtonSize ); + DrawNewOption( panel, groupIdx, panel._window._iconButtonSize ); } // Draw a line for a single option. @@ -518,9 +518,14 @@ public partial class ConfigWindow } // Draw the line to add a new option. - private static void DrawNewOption( Mod mod, int groupIdx, Vector2 iconButtonSize ) + private static void DrawNewOption( ModPanel panel, int groupIdx, Vector2 iconButtonSize ) { + var mod = panel._mod; + var group = mod.Groups[ groupIdx ]; ImGui.TableNextColumn(); + ImGui.AlignTextToFramePadding(); + ImGui.Selectable( $"Option #{group.Count + 1}" ); + Target( panel, group, groupIdx, group.Count ); ImGui.TableNextColumn(); ImGui.SetNextItemWidth( -1 ); var tmp = _newOptionNameIdx == groupIdx ? _newOptionName : string.Empty; @@ -564,14 +569,13 @@ public partial class ConfigWindow private static void Target( ModPanel panel, IModGroup group, int groupIdx, int optionIdx ) { - // TODO drag options to other groups without options. using var target = ImRaii.DragDropTarget(); if( !target.Success || !ImGuiUtil.IsDropping( DragDropLabel ) ) { return; } - if( _dragDropGroupIdx >= 0 && _dragDropOptionIdx >= 0 ) + if( _dragDropGroupIdx >= 0 && _dragDropOptionIdx >= 0 ) { if( _dragDropGroupIdx == groupIdx ) { @@ -580,15 +584,18 @@ public partial class ConfigWindow } else { - // Move from one group to another by deleting, then adding the option. - var sourceGroup = _dragDropGroupIdx; - var sourceOption = _dragDropOptionIdx; - var option = group[ _dragDropOptionIdx ]; - var priority = group.OptionPriority( _dragDropGroupIdx ); + // Move from one group to another by deleting, then adding, then moving the option. + var sourceGroupIdx = _dragDropGroupIdx; + var sourceOption = _dragDropOptionIdx; + var sourceGroup = panel._mod.Groups[ sourceGroupIdx ]; + var currentCount = group.Count; + var option = sourceGroup[sourceOption]; + var priority = sourceGroup.OptionPriority( _dragDropGroupIdx ); panel._delayedActions.Enqueue( () => { - Penumbra.ModManager.DeleteOption( panel._mod, sourceGroup, sourceOption ); + Penumbra.ModManager.DeleteOption( panel._mod, sourceGroupIdx, sourceOption ); Penumbra.ModManager.AddOption( panel._mod, groupIdx, option, priority ); + Penumbra.ModManager.MoveOption( panel._mod, groupIdx, currentCount, optionIdx ); } ); } }