Change folder handling and introduce drag & drop for folders

This commit is contained in:
Ottermandias 2021-08-08 12:43:12 +02:00
parent ec99887387
commit 2532e73f9d
21 changed files with 1690 additions and 651 deletions

View file

@ -14,6 +14,7 @@ namespace Penumbra.UI
{
private class TabCollections
{
public const string LabelCurrentCollection = "Current Collection";
private readonly Selector _selector;
private readonly ModManager _manager;
private string _collectionNames = null!;
@ -130,11 +131,11 @@ namespace Penumbra.UI
}
}
private void DrawCurrentCollectionSelector()
public void DrawCurrentCollectionSelector(bool tooltip)
{
var index = _currentCollectionIndex;
var combo = ImGui.Combo( "Current Collection", ref index, _collectionNames );
if( ImGui.IsItemHovered() )
var combo = ImGui.Combo( LabelCurrentCollection, ref index, _collectionNames );
if( tooltip && ImGui.IsItemHovered() )
{
ImGui.SetTooltip(
"This collection will be modified when using the Installed Mods tab and making changes. It does not apply to anything by itself." );
@ -145,6 +146,7 @@ namespace Penumbra.UI
_manager.Collections.SetCurrentCollection( _collections[ index + 1 ] );
_currentCollectionIndex = index;
_selector.ReloadSelection();
_selector.Cache.ResetModList();
}
}
@ -277,7 +279,7 @@ namespace Penumbra.UI
return;
}
DrawCurrentCollectionSelector();
DrawCurrentCollectionSelector(true);
ImGui.Dummy( new Vector2( 0, 10 ) );
DrawNewCollectionInput();

View file

@ -0,0 +1,46 @@
using System;
namespace Penumbra.UI
{
[Flags]
public enum ModFilter
{
Enabled = 1 << 0,
Disabled = 1 << 1,
NoConflict = 1 << 2,
SolvedConflict = 1 << 3,
UnsolvedConflict = 1 << 4,
HasNoMetaManipulations = 1 << 5,
HasMetaManipulations = 1 << 6,
HasNoFileSwaps = 1 << 7,
HasFileSwaps = 1 << 8,
HasConfig = 1 << 9,
HasNoConfig = 1 << 10,
HasNoFiles = 1 << 11,
HasFiles = 1 << 12,
};
public static class ModFilterExtensions
{
public const ModFilter UnfilteredStateMods = ( ModFilter )( ( 1 << 13 ) - 1 );
public static string ToName( this ModFilter filter )
=> filter switch
{
ModFilter.Enabled => "Enabled",
ModFilter.Disabled => "Disabled",
ModFilter.NoConflict => "No Conflicts",
ModFilter.SolvedConflict => "Solved Conflicts",
ModFilter.UnsolvedConflict => "Unsolved Conflicts",
ModFilter.HasNoMetaManipulations => "No Meta Manipulations",
ModFilter.HasMetaManipulations => "Meta Manipulations",
ModFilter.HasNoFileSwaps => "No File Swaps",
ModFilter.HasFileSwaps => "File Swaps",
ModFilter.HasNoConfig => "No Configuration",
ModFilter.HasConfig => "Configuration",
ModFilter.HasNoFiles => "No Files",
ModFilter.HasFiles => "Files",
_ => throw new ArgumentOutOfRangeException( nameof( filter ), filter, null ),
};
}
}

View file

@ -0,0 +1,262 @@
using System.Collections.Generic;
using System.Linq;
using Dalamud.Plugin;
using Penumbra.Mods;
namespace Penumbra.UI
{
public class ModListCache
{
public const uint DisabledModColor = 0xFF666666u;
public const uint ConflictingModColor = 0xFFAAAAFFu;
public const uint HandledConflictModColor = 0xFF88DDDDu;
private readonly ModManager _manager;
private readonly List< Mod.Mod > _modsInOrder = new();
private readonly List< (bool visible, uint color) > _visibleMods = new();
private readonly Dictionary< ModFolder, (bool visible, bool enabled) > _visibleFolders = new();
private string _modFilter = "";
private string _modFilterChanges = "";
private string _modFilterAuthor = "";
private ModFilter _stateFilter = ModFilterExtensions.UnfilteredStateMods;
public ModFilter StateFilter
{
get => _stateFilter;
set
{
var diff = _stateFilter != value;
_stateFilter = value;
if( diff )
{
ResetFilters();
}
}
}
public ModListCache( ModManager manager )
{
_manager = manager;
ResetModList();
}
public int Count
=> _modsInOrder.Count;
public void RemoveMod( Mod.Mod mod )
{
var idx = _modsInOrder.IndexOf( mod );
if( idx >= 0 )
{
_modsInOrder.RemoveAt( idx );
_visibleMods.RemoveAt( idx );
UpdateFolders();
}
}
private void UpdateFolders()
{
_visibleFolders.Clear();
for( var i = 0; i < _modsInOrder.Count; ++i )
{
if( _visibleMods[ i ].visible )
{
_visibleFolders[ _modsInOrder[ i ].Data.SortOrder.ParentFolder ] = ( true, true );
}
}
}
public void SetTextFilter( string filter )
{
var lower = filter.ToLowerInvariant();
if( lower.StartsWith( "c:" ) )
{
_modFilterChanges = lower.Substring( 2 );
_modFilter = string.Empty;
_modFilterAuthor = string.Empty;
}
else if( lower.StartsWith( "a:" ) )
{
_modFilterAuthor = lower.Substring( 2 );
_modFilter = string.Empty;
_modFilterChanges = string.Empty;
}
else
{
_modFilter = lower;
_modFilterAuthor = string.Empty;
_modFilterChanges = string.Empty;
}
ResetFilters();
}
public void ResetModList()
{
_modsInOrder.Clear();
_visibleMods.Clear();
_visibleFolders.Clear();
PluginLog.Verbose( "Resetting mod selector list..." );
if( !_modsInOrder.Any() )
{
foreach( var modData in _manager.StructuredMods.AllMods( _manager.Config.SortFoldersFirst ) )
{
var mod = _manager.Collections.CurrentCollection.GetMod( modData );
_modsInOrder.Add( mod );
_visibleMods.Add( CheckFilters( mod ) );
}
}
}
public void ResetFilters()
{
_visibleMods.Clear();
_visibleFolders.Clear();
PluginLog.Verbose( "Resetting mod selector filters..." );
foreach( var mod in _modsInOrder )
{
_visibleMods.Add( CheckFilters( mod ) );
}
}
public (Mod.Mod? mod, int idx) GetModByName( string name )
{
for( var i = 0; i < Count; ++i )
{
if( _modsInOrder[ i ].Data.Meta.Name == name )
{
return ( _modsInOrder[ i ], i );
}
}
return ( null, 0 );
}
public (Mod.Mod? mod, int idx) GetModByBasePath( string basePath )
{
for( var i = 0; i < Count; ++i )
{
if( _modsInOrder[ i ].Data.BasePath.Name == basePath )
{
return ( _modsInOrder[ i ], i );
}
}
return ( null, 0 );
}
public (bool visible, bool enabled) GetFolder( ModFolder folder )
=> _visibleFolders.TryGetValue( folder, out var ret ) ? ret : ( false, false );
public (Mod.Mod?, bool visible, uint color) GetMod( int idx )
=> idx >= 0 && idx < _modsInOrder.Count
? ( _modsInOrder[ idx ], _visibleMods[ idx ].visible, _visibleMods[ idx ].color )
: ( null, false, 0 );
private bool CheckFlags( int count, ModFilter hasNoFlag, ModFilter hasFlag )
{
if( count == 0 )
{
if( StateFilter.HasFlag( hasNoFlag ) )
{
return false;
}
}
else if( StateFilter.HasFlag( hasFlag ) )
{
return false;
}
return true;
}
private (bool, uint) CheckFilters( Mod.Mod mod )
{
var ret = ( false, 0u );
if( _modFilter.Any() && !mod.Data.Meta.LowerName.Contains( _modFilter ) )
{
return ret;
}
if( _modFilterAuthor.Any() && !mod.Data.Meta.LowerAuthor.Contains( _modFilterAuthor ) )
{
return ret;
}
if( _modFilterChanges.Any() && !mod.Data.LowerChangedItemsString.Contains( _modFilterChanges ) )
{
return ret;
}
if( CheckFlags( mod.Data.Resources.ModFiles.Count, ModFilter.HasNoFiles, ModFilter.HasFiles ) )
{
return ret;
}
if( CheckFlags( mod.Data.Meta.FileSwaps.Count, ModFilter.HasNoFileSwaps, ModFilter.HasFileSwaps ) )
{
return ret;
}
if( CheckFlags( mod.Data.Resources.MetaManipulations.Count, ModFilter.HasNoMetaManipulations,
ModFilter.HasMetaManipulations ) )
{
return ret;
}
if( CheckFlags( mod.Data.Meta.HasGroupsWithConfig ? 1 : 0, ModFilter.HasNoConfig, ModFilter.HasConfig ) )
{
return ret;
}
if( !mod.Settings.Enabled )
{
if( !StateFilter.HasFlag( ModFilter.Disabled ) || !StateFilter.HasFlag( ModFilter.NoConflict ) )
{
return ret;
}
ret.Item2 = ret.Item2 == 0 ? DisabledModColor : ret.Item2;
}
if( mod.Settings.Enabled && !StateFilter.HasFlag( ModFilter.Enabled ) )
{
return ret;
}
if( mod.Cache.Conflicts.Any() )
{
if( mod.Cache.Conflicts.Keys.Any( m => m.Settings.Priority == mod.Settings.Priority ) )
{
if( !StateFilter.HasFlag( ModFilter.UnsolvedConflict ) )
{
return ret;
}
ret.Item2 = ret.Item2 == 0 ? ConflictingModColor : ret.Item2;
}
else
{
if( !StateFilter.HasFlag( ModFilter.SolvedConflict ) )
{
return ret;
}
ret.Item2 = ret.Item2 == 0 ? HandledConflictModColor : ret.Item2;
}
}
else if( !StateFilter.HasFlag( ModFilter.NoConflict ) )
{
return ret;
}
ret.Item1 = true;
_visibleFolders[ mod.Data.SortOrder.ParentFolder ] = ( true, true );
return ret;
}
}
}

View file

@ -431,6 +431,19 @@ namespace Penumbra.UI
if( changed )
{
_selector.SaveCurrentMod();
// Since files may have changed, we need to recompute effective files.
foreach( var collection in _modManager.Collections.Collections.Values
.Where( c => c.Cache != null && c.Settings[ Mod!.Data.BasePath.Name ].Enabled ) )
{
collection.CalculateEffectiveFileList( _modManager.BasePath, false,
collection == _modManager.Collections.ActiveCollection );
}
// If the mod is enabled in the current collection, its conflicts may have changed.
if( Mod!.Settings.Enabled )
{
_selector.Cache.ResetFilters();
}
}
}
@ -558,14 +571,12 @@ namespace Penumbra.UI
if( ImGui.Checkbox( label, ref enabled ) && oldEnabled != enabled )
{
Mod.Settings.Settings[ group.GroupName ] ^= 1 << idx;
if( Mod.Settings.Enabled && _modManager.Collections.CurrentCollection.Cache != null )
{
_modManager.Collections.CurrentCollection.CalculateEffectiveFileList( Mod.Data.BasePath,
Mod.Data.Resources.MetaManipulations.Count > 0,
_modManager.Collections.CurrentCollection == _modManager.Collections.ActiveCollection );
}
Save();
// If the mod is enabled, recalculate files and filters.
if( Mod.Settings.Enabled )
{
_base.RecalculateCurrent( Mod.Data.Resources.MetaManipulations.Count > 0 );
}
}
}
@ -599,14 +610,12 @@ namespace Penumbra.UI
&& code != Mod.Settings.Settings[ group.GroupName ] )
{
Mod.Settings.Settings[ group.GroupName ] = code;
if( Mod.Settings.Enabled && _modManager.Collections.CurrentCollection.Cache != null )
{
_modManager.Collections.CurrentCollection.CalculateEffectiveFileList( Mod.Data.BasePath,
Mod.Data.Resources.MetaManipulations.Count > 0,
_modManager.Collections.CurrentCollection == _modManager.Collections.ActiveCollection );
}
Save();
// If the mod is enabled, recalculate files and filters.
if( Mod.Settings.Enabled )
{
_base.RecalculateCurrent( Mod.Data.Resources.MetaManipulations.Count > 0 );
}
}
}

View file

@ -111,7 +111,10 @@ namespace Penumbra.UI
var groupName = group.GroupName;
if( Custom.ImGuiCustom.BeginFramedGroupEdit( ref groupName ) )
{
_modManager.ChangeModGroup( group.GroupName, groupName, Mod.Data );
if( _modManager.ChangeModGroup( group.GroupName, groupName, Mod.Data ) && Mod.Data.Meta.RefreshHasGroupsWithConfig() )
{
_selector.Cache.ResetFilters();
}
}
}
@ -127,6 +130,10 @@ namespace Penumbra.UI
group.Options.Add( new Option()
{ OptionName = newOption, OptionDesc = "", OptionFiles = new Dictionary< RelPath, HashSet< GamePath > >() } );
_selector.SaveCurrentMod();
if( Mod!.Data.Meta.RefreshHasGroupsWithConfig() )
{
_selector.Cache.ResetFilters();
}
}
}
@ -163,6 +170,11 @@ namespace Penumbra.UI
{ OptionName = newName, OptionDesc = opt.OptionDesc, OptionFiles = opt.OptionFiles };
_selector.SaveCurrentMod();
}
if( Mod!.Data.Meta.RefreshHasGroupsWithConfig() )
{
_selector.Cache.ResetFilters();
}
}
}
@ -176,7 +188,10 @@ namespace Penumbra.UI
var groupName = group.GroupName;
if( ImGui.InputText( $"##{groupName}_add", ref groupName, 64, ImGuiInputTextFlags.EnterReturnsTrue ) )
{
_modManager.ChangeModGroup( group.GroupName, groupName, Mod.Data );
if( _modManager.ChangeModGroup( group.GroupName, groupName, Mod.Data ) && Mod.Data.Meta.RefreshHasGroupsWithConfig() )
{
_selector.Cache.ResetFilters();
}
}
}
@ -220,6 +235,11 @@ namespace Penumbra.UI
}
}
}
if( Mod.Data.Meta.RefreshHasGroupsWithConfig() )
{
_selector.Cache.ResetFilters();
}
}
if( code != oldSetting )
@ -247,6 +267,7 @@ namespace Penumbra.UI
ImGuiInputTextFlags.EnterReturnsTrue ) )
{
_modManager.ChangeModGroup( "", newGroup, Mod.Data, SelectType.Single );
// Adds empty group, so can not change filters.
}
}
@ -259,6 +280,7 @@ namespace Penumbra.UI
ImGuiInputTextFlags.EnterReturnsTrue ) )
{
_modManager.ChangeModGroup( "", newGroup, Mod.Data, SelectType.Multi );
// Adds empty group, so can not change filters.
}
}
@ -298,7 +320,6 @@ namespace Penumbra.UI
var arrowWidth = ImGui.CalcTextSize( arrow ).X;
ImGui.PopFont();
var width = ( ImGui.GetWindowWidth() - arrowWidth - 4 * ImGui.GetStyle().ItemSpacing.X ) / 2;
for( var idx = 0; idx < swaps.Length + 1; ++idx )
{
@ -325,10 +346,8 @@ namespace Penumbra.UI
}
_selector.SaveCurrentMod();
if( Mod.Settings.Enabled )
{
_selector.ReloadCurrentMod();
}
_selector.ReloadCurrentMod();
_selector.Cache.ResetModList();
}
}
@ -350,10 +369,8 @@ namespace Penumbra.UI
{
Meta.FileSwaps[ key ] = newValue;
_selector.SaveCurrentMod();
if( Mod.Settings.Enabled )
{
_selector.ReloadCurrentMod();
}
_selector.ReloadCurrentMod();
_selector.Cache.ResetModList();
}
}
}

View file

@ -74,8 +74,11 @@ namespace Penumbra.UI
var name = Meta!.Name;
if( Custom.ImGuiCustom.InputOrText( _editMode, LabelEditName, ref name, 64 ) && _modManager.RenameMod( name, Mod!.Data ) )
{
_selector.RenameCurrentModLower( name );
_selector.SelectModByDir( Mod.Data.BasePath.Name );
if( !_modManager.Config.ModSortOrder.ContainsKey( Mod!.Data.BasePath.Name ) && Mod.Data.Rename( name ) )
{
_selector.Cache.ResetModList();
}
}
}
@ -119,6 +122,7 @@ namespace Penumbra.UI
{
Meta.Author = author;
_selector.SaveCurrentMod();
_selector.Cache.ResetFilters();
}
ImGui.EndGroup();
@ -200,13 +204,8 @@ namespace Penumbra.UI
if( ImGui.InputInt( "Priority", ref priority, 0 ) && priority != Mod!.Settings.Priority )
{
Mod.Settings.Priority = priority;
var collection = _modManager.Collections.CurrentCollection;
collection.Save( _base._plugin.PluginInterface! );
if( collection.Cache != null )
{
collection.CalculateEffectiveFileList( _modManager.BasePath, Mod.Data.Resources.MetaManipulations.Count > 0,
collection == _modManager.Collections.ActiveCollection );
}
_selector.Cache.ResetFilters();
_base.SaveCurrentCollection( Mod.Data.Resources.MetaManipulations.Count > 0 );
}
if( ImGui.IsItemHovered() )
@ -222,23 +221,19 @@ namespace Penumbra.UI
if( ImGui.Checkbox( LabelModEnabled, ref enabled ) )
{
Mod.Settings.Enabled = enabled;
var collection = _modManager.Collections.CurrentCollection;
collection.Save( _base._plugin.PluginInterface! );
if( collection.Cache != null )
{
collection.CalculateEffectiveFileList( _modManager.BasePath, Mod.Data.Resources.MetaManipulations.Count > 0,
collection == _modManager.Collections.ActiveCollection );
}
_selector.Cache.ResetFilters();
_base.SaveCurrentCollection( Mod.Data.Resources.MetaManipulations.Count > 0 );
}
}
public static bool DrawSortOrder( ModData mod, ModManager manager, Selector selector )
{
var currentSortOrder = mod.SortOrder;
var currentSortOrder = mod.SortOrder.FullPath;
ImGui.SetNextItemWidth( 300 );
if( ImGui.InputText( "Sort Order", ref currentSortOrder, 256, ImGuiInputTextFlags.EnterReturnsTrue ) )
{
manager.ChangeSortOrder( mod, currentSortOrder );
selector.Cache.ResetModList();
selector.SelectModByDir( mod.BasePath.Name );
return true;
}
@ -337,7 +332,6 @@ namespace Penumbra.UI
{
Service< ModManager >.Get()!.RenameModFolder( Mod.Data, newDir, false );
_selector.ResetModNamesLower();
_selector.SelectModByDir( _newName );
closeParent = true;
@ -400,7 +394,6 @@ namespace Penumbra.UI
}
}
private void DrawRenameModFolderButton()
{
DrawRenameModFolderPopup();
@ -452,7 +445,9 @@ namespace Penumbra.UI
if( ImGui.IsItemHovered() )
{
ImGui.SetTooltip(
"Force a recomputation of the metadata_manipulations.json file from all .meta files in the folder.\nAlso reloads the mod.\nBe aware that this removes all manually added metadata changes." );
"Force a recomputation of the metadata_manipulations.json file from all .meta files in the folder.\n"
+ "Also reloads the mod.\n"
+ "Be aware that this removes all manually added metadata changes." );
}
}
@ -507,11 +502,6 @@ namespace Penumbra.UI
public void Draw()
{
if( Mod == null )
{
return;
}
try
{
var ret = ImGui.BeginChild( LabelModPanel, AutoFillSize, true );
@ -520,6 +510,12 @@ namespace Penumbra.UI
return;
}
if( Mod == null )
{
ImGui.EndChild();
return;
}
DrawHeaderLine();
// Next line with fixed distance.

File diff suppressed because it is too large Load diff

View file

@ -22,6 +22,7 @@ namespace Penumbra.UI
private const string LabelEnabled = "Enable Mods";
private const string LabelEnabledPlayerWatch = "Enable automatic Character Redraws";
private const string LabelWaitFrames = "Wait Frames";
private const string LabelSortFoldersFirst = "Sort Mod Folders Before Mods";
private const string LabelScaleModSelector = "Scale Mod Selector With Window Size";
private const string LabelShowAdvanced = "Show Advanced Settings";
private const string LabelLogLoadedFiles = "Log all loaded files";
@ -100,6 +101,17 @@ namespace Penumbra.UI
}
}
private void DrawSortFoldersFirstBox()
{
var foldersFirst = _config.SortFoldersFirst;
if( ImGui.Checkbox( LabelSortFoldersFirst, ref foldersFirst ) )
{
_config.SortFoldersFirst = foldersFirst;
_base._menu.InstalledTab.Selector.Cache.ResetModList();
_configChanged = true;
}
}
private void DrawScaleModSelectorBox()
{
var scaleModSelector = _config.ScaleModSelector;
@ -238,6 +250,7 @@ namespace Penumbra.UI
Custom.ImGuiCustom.VerticalDistance( DefaultVerticalSpace );
DrawScaleModSelectorBox();
DrawSortFoldersFirstBox();
DrawShowAdvancedBox();
if( _config.ShowAdvanced )

View file

@ -16,6 +16,7 @@ namespace Penumbra.UI
private readonly ManageModsButton _manageModsButton;
private readonly MenuBar _menuBar;
private readonly SettingsMenu _menu;
private readonly ModManager _modManager;
public SettingsInterface( Plugin plugin )
{
@ -23,6 +24,7 @@ namespace Penumbra.UI
_manageModsButton = new ManageModsButton( this );
_menuBar = new MenuBar( this );
_menu = new SettingsMenu( this );
_modManager = Service< ModManager >.Get();
}
public void FlipVisibility()
@ -40,12 +42,27 @@ namespace Penumbra.UI
private void ReloadMods()
{
_menu.InstalledTab.Selector.ResetModNamesLower();
_menu.InstalledTab.Selector.ClearSelection();
_modManager.DiscoverMods( _plugin.Configuration.ModDirectory );
_menu.InstalledTab.Selector.Cache.ResetModList();
}
var modManager = Service< ModManager >.Get();
modManager.DiscoverMods( _plugin.Configuration.ModDirectory );
_menu.InstalledTab.Selector.ResetModNamesLower();
private void SaveCurrentCollection( bool recalculateMeta )
{
var current = _modManager.Collections.CurrentCollection;
current.Save( _plugin.PluginInterface );
RecalculateCurrent( recalculateMeta );
}
private void RecalculateCurrent( bool recalculateMeta )
{
var current = _modManager.Collections.CurrentCollection;
if( current.Cache != null )
{
current.CalculateEffectiveFileList( _modManager.BasePath, recalculateMeta,
current == _modManager.Collections.ActiveCollection );
_menu.InstalledTab.Selector.Cache.ResetFilters();
}
}
}
}

View file

@ -14,23 +14,23 @@ namespace Penumbra.UI
public static readonly Vector2 MinSettingsSize = new( 800, 450 );
public static readonly Vector2 MaxSettingsSize = new( 69420, 42069 );
private readonly SettingsInterface _base;
private readonly TabSettings _settingsTab;
private readonly TabImport _importTab;
private readonly TabBrowser _browserTab;
private readonly TabCollections _collectionsTab;
public readonly TabInstalled InstalledTab;
private readonly TabEffective _effectiveTab;
private readonly SettingsInterface _base;
private readonly TabSettings _settingsTab;
private readonly TabImport _importTab;
private readonly TabBrowser _browserTab;
internal readonly TabCollections CollectionsTab;
internal readonly TabInstalled InstalledTab;
private readonly TabEffective _effectiveTab;
public SettingsMenu( SettingsInterface ui )
{
_base = ui;
_settingsTab = new TabSettings( _base );
_importTab = new TabImport( _base );
_browserTab = new TabBrowser();
InstalledTab = new TabInstalled( _base );
_collectionsTab = new TabCollections( InstalledTab.Selector );
_effectiveTab = new TabEffective();
_base = ui;
_settingsTab = new TabSettings( _base );
_importTab = new TabImport( _base );
_browserTab = new TabBrowser();
InstalledTab = new TabInstalled( _base );
CollectionsTab = new TabCollections( InstalledTab.Selector );
_effectiveTab = new TabEffective();
}
#if DEBUG
@ -62,7 +62,7 @@ namespace Penumbra.UI
ImGui.BeginTabBar( PenumbraSettingsLabel );
_settingsTab.Draw();
_collectionsTab.Draw();
CollectionsTab.Draw();
_importTab.Draw();
if( Service< ModManager >.Get().Valid && !_importTab.IsImporting() )