mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-22 08:29:19 +01:00
Improve some things and fix bugs in Option editing.
This commit is contained in:
parent
72ef666d51
commit
7c955cc236
2 changed files with 33 additions and 17 deletions
|
|
@ -87,7 +87,7 @@ public sealed partial class Mod
|
||||||
{
|
{
|
||||||
foreach( var (group, groupIdx) in mod._groups.WithIndex().Skip( fromGroup ) )
|
foreach( var (group, groupIdx) in mod._groups.WithIndex().Skip( fromGroup ) )
|
||||||
{
|
{
|
||||||
foreach( var (o, optionIdx) in group.OfType<SubMod>().WithIndex() )
|
foreach( var (o, optionIdx) in group.OfType< SubMod >().WithIndex() )
|
||||||
{
|
{
|
||||||
o.SetPosition( groupIdx, optionIdx );
|
o.SetPosition( groupIdx, optionIdx );
|
||||||
}
|
}
|
||||||
|
|
@ -175,18 +175,19 @@ public sealed partial class Mod
|
||||||
|
|
||||||
public void AddOption( Mod mod, int groupIdx, string newName )
|
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 )
|
switch( group )
|
||||||
{
|
{
|
||||||
case SingleModGroup s:
|
case SingleModGroup s:
|
||||||
s.OptionData.Add( new SubMod(mod) { Name = newName } );
|
s.OptionData.Add( subMod );
|
||||||
break;
|
break;
|
||||||
case MultiModGroup m:
|
case MultiModGroup m:
|
||||||
m.PrioritizedOptions.Add( ( new SubMod(mod) { Name = newName }, 0 ) );
|
m.PrioritizedOptions.Add( ( subMod, 0 ) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
group.UpdatePositions( group.Count - 1 );
|
|
||||||
ModOptionChanged.Invoke( ModOptionChangeType.OptionAdded, mod, groupIdx, group.Count - 1, -1 );
|
ModOptionChanged.Invoke( ModOptionChangeType.OptionAdded, mod, groupIdx, group.Count - 1, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,6 +207,8 @@ public sealed partial class Mod
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
o.SetPosition( groupIdx, group.Count );
|
||||||
|
|
||||||
switch( group )
|
switch( group )
|
||||||
{
|
{
|
||||||
case SingleModGroup s:
|
case SingleModGroup s:
|
||||||
|
|
@ -215,13 +218,13 @@ public sealed partial class Mod
|
||||||
m.PrioritizedOptions.Add( ( o, priority ) );
|
m.PrioritizedOptions.Add( ( o, priority ) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
group.UpdatePositions( group.Count - 1 );
|
|
||||||
ModOptionChanged.Invoke( ModOptionChangeType.OptionAdded, mod, groupIdx, group.Count - 1, -1 );
|
ModOptionChanged.Invoke( ModOptionChangeType.OptionAdded, mod, groupIdx, group.Count - 1, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteOption( Mod mod, int groupIdx, int optionIdx )
|
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 );
|
ModOptionChanged.Invoke( ModOptionChangeType.PrepareChange, mod, groupIdx, optionIdx, -1 );
|
||||||
switch( group )
|
switch( group )
|
||||||
{
|
{
|
||||||
|
|
@ -233,6 +236,7 @@ public sealed partial class Mod
|
||||||
m.PrioritizedOptions.RemoveAt( optionIdx );
|
m.PrioritizedOptions.RemoveAt( optionIdx );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
group.UpdatePositions( optionIdx );
|
group.UpdatePositions( optionIdx );
|
||||||
ModOptionChanged.Invoke( ModOptionChangeType.OptionDeleted, mod, groupIdx, optionIdx, -1 );
|
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 )
|
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.
|
// File deletion is handled in the actual function.
|
||||||
if( type is ModOptionChangeType.GroupDeleted or ModOptionChangeType.GroupMoved )
|
if( type is ModOptionChangeType.GroupDeleted or ModOptionChangeType.GroupMoved )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -477,7 +477,7 @@ public partial class ConfigWindow
|
||||||
EditOption( panel, group, groupIdx, optionIdx );
|
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.
|
// Draw a line for a single option.
|
||||||
|
|
@ -518,9 +518,14 @@ public partial class ConfigWindow
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the line to add a new option.
|
// 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.TableNextColumn();
|
||||||
|
ImGui.AlignTextToFramePadding();
|
||||||
|
ImGui.Selectable( $"Option #{group.Count + 1}" );
|
||||||
|
Target( panel, group, groupIdx, group.Count );
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
ImGui.SetNextItemWidth( -1 );
|
ImGui.SetNextItemWidth( -1 );
|
||||||
var tmp = _newOptionNameIdx == groupIdx ? _newOptionName : string.Empty;
|
var tmp = _newOptionNameIdx == groupIdx ? _newOptionName : string.Empty;
|
||||||
|
|
@ -564,7 +569,6 @@ public partial class ConfigWindow
|
||||||
|
|
||||||
private static void Target( ModPanel panel, IModGroup group, int groupIdx, int optionIdx )
|
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();
|
using var target = ImRaii.DragDropTarget();
|
||||||
if( !target.Success || !ImGuiUtil.IsDropping( DragDropLabel ) )
|
if( !target.Success || !ImGuiUtil.IsDropping( DragDropLabel ) )
|
||||||
{
|
{
|
||||||
|
|
@ -580,15 +584,18 @@ public partial class ConfigWindow
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Move from one group to another by deleting, then adding the option.
|
// Move from one group to another by deleting, then adding, then moving the option.
|
||||||
var sourceGroup = _dragDropGroupIdx;
|
var sourceGroupIdx = _dragDropGroupIdx;
|
||||||
var sourceOption = _dragDropOptionIdx;
|
var sourceOption = _dragDropOptionIdx;
|
||||||
var option = group[ _dragDropOptionIdx ];
|
var sourceGroup = panel._mod.Groups[ sourceGroupIdx ];
|
||||||
var priority = group.OptionPriority( _dragDropGroupIdx );
|
var currentCount = group.Count;
|
||||||
|
var option = sourceGroup[sourceOption];
|
||||||
|
var priority = sourceGroup.OptionPriority( _dragDropGroupIdx );
|
||||||
panel._delayedActions.Enqueue( () =>
|
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.AddOption( panel._mod, groupIdx, option, priority );
|
||||||
|
Penumbra.ModManager.MoveOption( panel._mod, groupIdx, currentCount, optionIdx );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue