Add empty option for single select groups with empty options. More Editor stuff.

This commit is contained in:
Ottermandias 2022-05-01 18:06:21 +02:00
parent 81e93e0664
commit e2a6274b33
21 changed files with 937 additions and 336 deletions

View file

@ -0,0 +1,322 @@
using System;
using System.Linq;
using System.Numerics;
using Dalamud.Interface;
using Dalamud.Interface.Windowing;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using Penumbra.Meta.Manipulations;
using Penumbra.Mods;
namespace Penumbra.UI.Classes;
public class ModEditWindow : Window, IDisposable
{
private const string WindowBaseLabel = "###SubModEdit";
private Mod.Editor? _editor;
private Mod? _mod;
public void ChangeMod( Mod mod )
{
if( mod == _mod )
{
return;
}
_editor?.Dispose();
_editor = new Mod.Editor( mod );
_mod = mod;
WindowName = $"{mod.Name}{WindowBaseLabel}";
}
public void ChangeOption( int groupIdx, int optionIdx )
=> _editor?.SetSubMod( groupIdx, optionIdx );
public override bool DrawConditions()
=> _editor != null;
public override void Draw()
{
using var tabBar = ImRaii.TabBar( "##tabs" );
if( !tabBar )
{
return;
}
DrawFileTab();
DrawMetaTab();
DrawSwapTab();
DrawMissingFilesTab();
DrawUnusedFilesTab();
DrawDuplicatesTab();
}
private void DrawMissingFilesTab()
{
using var tab = ImRaii.TabItem( "Missing Files" );
if( !tab )
{
return;
}
if( _editor!.MissingPaths.Count == 0 )
{
ImGui.TextUnformatted( "No missing files detected." );
}
else
{
if( ImGui.Button( "Remove Missing Files from Mod" ) )
{
_editor.RemoveMissingPaths();
}
using var table = ImRaii.Table( "##missingFiles", 1, ImGuiTableFlags.RowBg, -Vector2.One );
if( !table )
{
return;
}
foreach( var path in _editor.MissingPaths )
{
ImGui.TableNextColumn();
ImGui.TextUnformatted( path.FullName );
}
}
}
private void DrawDuplicatesTab()
{
using var tab = ImRaii.TabItem( "Duplicates" );
if( !tab )
{
return;
}
var buttonText = _editor!.DuplicatesFinished ? "Scan for Duplicates###ScanButton" : "Scanning for Duplicates...###ScanButton";
if( ImGuiUtil.DrawDisabledButton( buttonText, Vector2.Zero, "Search for identical files in this mod. This may take a while.",
!_editor.DuplicatesFinished ) )
{
_editor.StartDuplicateCheck();
}
if( !_editor.DuplicatesFinished )
{
ImGui.SameLine();
if( ImGui.Button( "Cancel" ) )
{
_editor.Cancel();
}
return;
}
if( _editor.Duplicates.Count == 0 )
{
ImGui.TextUnformatted( "No duplicates found." );
}
if( ImGui.Button( "Delete and Redirect Duplicates" ) )
{
_editor.DeleteDuplicates();
}
if( _editor.SavedSpace > 0 )
{
ImGui.SameLine();
ImGui.TextUnformatted( $"Frees up {Functions.HumanReadableSize( _editor.SavedSpace )} from your hard drive." );
}
using var child = ImRaii.Child( "##duptable", -Vector2.One, true );
if( !child )
{
return;
}
using var table = ImRaii.Table( "##duplicates", 3, ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingFixedFit, -Vector2.One );
if( !table )
{
return;
}
var width = ImGui.CalcTextSize( "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN " ).X;
ImGui.TableSetupColumn( "file", ImGuiTableColumnFlags.WidthStretch );
ImGui.TableSetupColumn( "size", ImGuiTableColumnFlags.WidthFixed, ImGui.CalcTextSize( "NNN.NNN " ).X );
ImGui.TableSetupColumn( "hash", ImGuiTableColumnFlags.WidthFixed,
ImGui.GetWindowWidth() > 2 * width ? width : ImGui.CalcTextSize( "NNNNNNNN... " ).X );
foreach( var (set, size, hash) in _editor.Duplicates.Where( s => s.Paths.Length > 1 ) )
{
ImGui.TableNextColumn();
using var tree = ImRaii.TreeNode( set[ 0 ].FullName[ ( _mod!.BasePath.FullName.Length + 1 ).. ],
ImGuiTreeNodeFlags.NoTreePushOnOpen );
ImGui.TableNextColumn();
ImGuiUtil.RightAlign( Functions.HumanReadableSize( size ) );
ImGui.TableNextColumn();
using( var font = ImRaii.PushFont( UiBuilder.MonoFont ) )
{
if( ImGui.GetWindowWidth() > 2 * width )
{
ImGuiUtil.RightAlign( string.Concat( hash.Select( b => b.ToString( "X2" ) ) ) );
}
else
{
ImGuiUtil.RightAlign( string.Concat( hash.Take( 4 ).Select( b => b.ToString( "X2" ) ) ) + "..." );
}
}
if( !tree )
{
continue;
}
using var indent = ImRaii.PushIndent();
foreach( var duplicate in set.Skip( 1 ) )
{
ImGui.TableNextColumn();
ImGui.TableSetBgColor( ImGuiTableBgTarget.CellBg, 0x40000080 );
using var node = ImRaii.TreeNode( duplicate.FullName[ ( _mod!.BasePath.FullName.Length + 1 ).. ], ImGuiTreeNodeFlags.Leaf );
ImGui.TableNextColumn();
ImGui.TableSetBgColor( ImGuiTableBgTarget.CellBg, 0x40000080 );
ImGui.TableNextColumn();
ImGui.TableSetBgColor( ImGuiTableBgTarget.CellBg, 0x40000080 );
}
}
}
private void DrawUnusedFilesTab()
{
using var tab = ImRaii.TabItem( "Unused Files" );
if( !tab )
{
return;
}
if( _editor!.UnusedFiles.Count == 0 )
{
ImGui.TextUnformatted( "No unused files detected." );
}
else
{
if( ImGui.Button( "Add Unused Files to Default" ) )
{
_editor.AddUnusedPathsToDefault();
}
if( ImGui.Button( "Delete Unused Files from Filesystem" ) )
{
_editor.DeleteUnusedPaths();
}
using var table = ImRaii.Table( "##unusedFiles", 1, ImGuiTableFlags.RowBg, -Vector2.One );
if( !table )
{
return;
}
foreach( var path in _editor.UnusedFiles )
{
ImGui.TableNextColumn();
ImGui.TextUnformatted( path.FullName );
}
}
}
private void DrawFileTab()
{
using var tab = ImRaii.TabItem( "File Redirections" );
if( !tab )
{
return;
}
using var list = ImRaii.Table( "##files", 2 );
if( !list )
{
return;
}
foreach( var (gamePath, file) in _editor!.CurrentFiles )
{
ImGui.TableNextColumn();
ConfigWindow.Text( gamePath.Path );
ImGui.TableNextColumn();
ImGui.TextUnformatted( file.FullName );
}
}
private void DrawMetaTab()
{
using var tab = ImRaii.TabItem( "Meta Manipulations" );
if( !tab )
{
return;
}
using var list = ImRaii.Table( "##meta", 3 );
if( !list )
{
return;
}
foreach( var manip in _editor!.CurrentManipulations )
{
ImGui.TableNextColumn();
ImGui.TextUnformatted( manip.ManipulationType.ToString() );
ImGui.TableNextColumn();
ImGui.TextUnformatted( manip.ManipulationType switch
{
MetaManipulation.Type.Imc => manip.Imc.ToString(),
MetaManipulation.Type.Eqdp => manip.Eqdp.ToString(),
MetaManipulation.Type.Eqp => manip.Eqp.ToString(),
MetaManipulation.Type.Est => manip.Est.ToString(),
MetaManipulation.Type.Gmp => manip.Gmp.ToString(),
MetaManipulation.Type.Rsp => manip.Rsp.ToString(),
_ => string.Empty,
} );
ImGui.TableNextColumn();
ImGui.TextUnformatted( manip.ManipulationType switch
{
MetaManipulation.Type.Imc => manip.Imc.Entry.ToString(),
MetaManipulation.Type.Eqdp => manip.Eqdp.Entry.ToString(),
MetaManipulation.Type.Eqp => manip.Eqp.Entry.ToString(),
MetaManipulation.Type.Est => manip.Est.Entry.ToString(),
MetaManipulation.Type.Gmp => manip.Gmp.Entry.ToString(),
MetaManipulation.Type.Rsp => manip.Rsp.Entry.ToString(),
_ => string.Empty,
} );
}
}
private void DrawSwapTab()
{
using var tab = ImRaii.TabItem( "File Swaps" );
if( !tab )
{
return;
}
using var list = ImRaii.Table( "##swaps", 3 );
if( !list )
{
return;
}
foreach( var (gamePath, file) in _editor!.CurrentSwaps )
{
ImGui.TableNextColumn();
ConfigWindow.Text( gamePath.Path );
ImGui.TableNextColumn();
ImGui.TextUnformatted( file.FullName );
}
}
public ModEditWindow()
: base( WindowBaseLabel )
{ }
public void Dispose()
{
_editor?.Dispose();
}
}

View file

@ -1,225 +0,0 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Dalamud.Interface.Windowing;
using ImGuiNET;
using OtterGui.Raii;
using Penumbra.GameData.ByteString;
using Penumbra.Meta.Manipulations;
using Penumbra.Mods;
using Penumbra.Util;
namespace Penumbra.UI.Classes;
public class SubModEditWindow : Window
{
private const string WindowBaseLabel = "###SubModEdit";
private Mod? _mod;
private int _groupIdx = -1;
private int _optionIdx = -1;
private IModGroup? _group;
private ISubMod? _subMod;
private readonly List< FilePathInfo > _availableFiles = new();
private readonly struct FilePathInfo
{
public readonly FullPath File;
public readonly Utf8RelPath RelFile;
public readonly long Size;
public readonly List< (int, int, Utf8GamePath) > SubMods;
public FilePathInfo( FileInfo file, Mod mod )
{
File = new FullPath( file );
RelFile = Utf8RelPath.FromFile( File, mod.BasePath, out var f ) ? f : Utf8RelPath.Empty;
Size = file.Length;
SubMods = new List< (int, int, Utf8GamePath) >();
var path = File;
foreach( var (group, groupIdx) in mod.Groups.WithIndex() )
{
foreach( var (subMod, optionIdx) in group.WithIndex() )
{
SubMods.AddRange( subMod.Files.Where( kvp => kvp.Value.Equals( path ) ).Select( kvp => ( groupIdx, optionIdx, kvp.Key ) ) );
}
}
SubMods.AddRange( mod.Default.Files.Where( kvp => kvp.Value.Equals( path ) ).Select( kvp => (-1, 0, kvp.Key) ) );
}
}
private readonly HashSet< MetaManipulation > _manipulations = new();
private readonly Dictionary< Utf8GamePath, FullPath > _files = new();
private readonly Dictionary< Utf8GamePath, FullPath > _fileSwaps = new();
public void Activate( Mod mod, int groupIdx, int optionIdx )
{
IsOpen = true;
_mod = mod;
_groupIdx = groupIdx;
_group = groupIdx >= 0 ? mod.Groups[ groupIdx ] : null;
_optionIdx = optionIdx;
_subMod = groupIdx >= 0 ? _group![ optionIdx ] : _mod.Default;
_availableFiles.Clear();
_availableFiles.AddRange( mod.BasePath.EnumerateDirectories()
.SelectMany( d => d.EnumerateFiles( "*.*", SearchOption.AllDirectories ) )
.Select( f => new FilePathInfo( f, _mod ) ) );
_manipulations.Clear();
_manipulations.UnionWith( _subMod.Manipulations );
_files.SetTo( _subMod.Files );
_fileSwaps.SetTo( _subMod.FileSwaps );
WindowName = $"{_mod.Name}: {(_group != null ? $"{_group.Name} - " : string.Empty)}{_subMod.Name}";
}
public override bool DrawConditions()
=> _subMod != null;
public override void Draw()
{
using var tabBar = ImRaii.TabBar( "##tabs" );
if( !tabBar )
{
return;
}
DrawFileTab();
DrawMetaTab();
DrawSwapTab();
}
private void Save()
{
if( _mod != null )
{
Penumbra.ModManager.OptionUpdate( _mod, _groupIdx, _optionIdx, _files, _manipulations, _fileSwaps );
}
}
public override void OnClose()
{
_subMod = null;
}
private void DrawFileTab()
{
using var tab = ImRaii.TabItem( "File Redirections" );
if( !tab )
{
return;
}
using var list = ImRaii.Table( "##files", 3 );
if( !list )
{
return;
}
foreach( var file in _availableFiles )
{
ImGui.TableNextColumn();
ConfigWindow.Text( file.RelFile.Path );
ImGui.TableNextColumn();
ImGui.TextUnformatted( file.Size.ToString() );
ImGui.TableNextColumn();
if( file.SubMods.Count == 0 )
{
ImGui.TextUnformatted( "Unused" );
}
foreach( var (groupIdx, optionIdx, gamePath) in file.SubMods )
{
ImGui.TableNextColumn();
ImGui.TableNextColumn();
var group = groupIdx >= 0 ? _mod!.Groups[ groupIdx ] : null;
var option = groupIdx >= 0 ? group![ optionIdx ] : _mod!.Default;
var text = groupIdx >= 0
? $"{group!.Name} - {option.Name}"
: option.Name;
ImGui.TextUnformatted( text );
ImGui.TableNextColumn();
ConfigWindow.Text( gamePath.Path );
}
}
ImGui.TableNextRow();
foreach( var (gamePath, fullPath) in _files )
{
ImGui.TableNextColumn();
ConfigWindow.Text( gamePath.Path );
ImGui.TableNextColumn();
ImGui.TextUnformatted( fullPath.FullName );
ImGui.TableNextColumn();
}
}
private void DrawMetaTab()
{
using var tab = ImRaii.TabItem( "Meta Manipulations" );
if( !tab )
{
return;
}
using var list = ImRaii.Table( "##meta", 3 );
if( !list )
{
return;
}
foreach( var manip in _manipulations )
{
ImGui.TableNextColumn();
ImGui.TextUnformatted( manip.ManipulationType.ToString() );
ImGui.TableNextColumn();
ImGui.TextUnformatted( manip.ManipulationType switch
{
MetaManipulation.Type.Imc => manip.Imc.ToString(),
MetaManipulation.Type.Eqdp => manip.Eqdp.ToString(),
MetaManipulation.Type.Eqp => manip.Eqp.ToString(),
MetaManipulation.Type.Est => manip.Est.ToString(),
MetaManipulation.Type.Gmp => manip.Gmp.ToString(),
MetaManipulation.Type.Rsp => manip.Rsp.ToString(),
_ => string.Empty,
} );
ImGui.TableNextColumn();
ImGui.TextUnformatted( manip.ManipulationType switch
{
MetaManipulation.Type.Imc => manip.Imc.Entry.ToString(),
MetaManipulation.Type.Eqdp => manip.Eqdp.Entry.ToString(),
MetaManipulation.Type.Eqp => manip.Eqp.Entry.ToString(),
MetaManipulation.Type.Est => manip.Est.Entry.ToString(),
MetaManipulation.Type.Gmp => manip.Gmp.Entry.ToString(),
MetaManipulation.Type.Rsp => manip.Rsp.Entry.ToString(),
_ => string.Empty,
} );
}
}
private void DrawSwapTab()
{
using var tab = ImRaii.TabItem( "File Swaps" );
if( !tab )
{
return;
}
using var list = ImRaii.Table( "##swaps", 3 );
if( !list )
{
return;
}
foreach( var (from, to) in _fileSwaps )
{
ImGui.TableNextColumn();
ConfigWindow.Text( from.Path );
ImGui.TableNextColumn();
ImGui.TextUnformatted( to.FullName );
ImGui.TableNextColumn();
}
}
public SubModEditWindow()
: base( WindowBaseLabel )
{ }
}

View file

@ -158,7 +158,9 @@ public partial class ConfigWindow
if( ImGui.Button( "Edit Default Mod", reducedSize ) )
{
_window.SubModPopup.Activate( _mod, -1, 0 );
_window.ModEditPopup.ChangeMod( _mod );
_window.ModEditPopup.ChangeOption( -1, 0 );
_window.ModEditPopup.IsOpen = true;
}
ImGui.SameLine();
@ -180,6 +182,7 @@ public partial class ConfigWindow
private int _currentField = -1;
private int _optionIndex = -1;
private int _newOptionNameIdx = -1;
private string _newGroupName = string.Empty;
private string _newOptionName = string.Empty;
private string _newDescription = string.Empty;
@ -287,10 +290,15 @@ public partial class ConfigWindow
ImGui.TableNextColumn();
ImGui.TableNextColumn();
ImGui.SetNextItemWidth( -1 );
ImGui.InputTextWithHint( "##newOption", "Add new option...", ref _newOptionName, 256 );
var tmp = _newOptionNameIdx == groupIdx ? _newOptionName : string.Empty;
if( ImGui.InputTextWithHint( "##newOption", "Add new option...", ref tmp, 256 ) )
{
_newOptionName = tmp;
_newOptionNameIdx = groupIdx;
}
ImGui.TableNextColumn();
if( ImGuiUtil.DrawDisabledButton( FontAwesomeIcon.Plus.ToIconString(), _window._iconButtonSize,
"Add a new option to this group.", _newOptionName.Length == 0, true ) )
"Add a new option to this group.", _newOptionName.Length == 0 || _newOptionNameIdx != groupIdx, true ) )
{
Penumbra.ModManager.AddOption( _mod, groupIdx, _newOptionName );
_newOptionName = string.Empty;
@ -385,7 +393,9 @@ public partial class ConfigWindow
if( ImGuiUtil.DrawDisabledButton( FontAwesomeIcon.Edit.ToIconString(), _window._iconButtonSize,
"Edit this option.", false, true ) )
{
_window.SubModPopup.Activate( _mod, groupIdx, optionIdx );
_window.ModEditPopup.ChangeMod( _mod );
_window.ModEditPopup.ChangeOption( groupIdx, optionIdx );
_window.ModEditPopup.IsOpen = true;
}
ImGui.TableNextColumn();

View file

@ -105,6 +105,7 @@ public partial class ConfigWindow
ImGui.SetNextItemWidth( 50 * ImGuiHelpers.GlobalScale );
if( ImGui.InputInt( "##Priority", ref priority, 0, 0 ) )
{
_currentPriority = priority;
}

View file

@ -21,7 +21,7 @@ public sealed partial class ConfigWindow : Window, IDisposable
private readonly EffectiveTab _effectiveTab;
private readonly DebugTab _debugTab;
private readonly ResourceTab _resourceTab;
public readonly SubModEditWindow SubModPopup = new();
public readonly ModEditWindow ModEditPopup = new();
public ConfigWindow( Penumbra penumbra )
: base( GetLabel() )
@ -70,6 +70,7 @@ public sealed partial class ConfigWindow : Window, IDisposable
{
_selector.Dispose();
_modPanel.Dispose();
ModEditPopup.Dispose();
}
private static string GetLabel()