Some further interface improvements.

This commit is contained in:
Ottermandias 2021-04-20 16:32:03 +02:00
parent 234712ca99
commit 668371dae8
10 changed files with 128 additions and 138 deletions

View file

@ -33,7 +33,7 @@ namespace Penumbra.UI
} }
ImGui.SetNextItemWidth( -1 ); ImGui.SetNextItemWidth( -1 );
if( ImGui.InputText( $"##{label}_new", ref newOption, 64, ImGuiInputTextFlags.EnterReturnsTrue ) ) if( ImGui.InputTextWithHint( $"##{label}_new", "Add new item...", ref newOption, 64, ImGuiInputTextFlags.EnterReturnsTrue ) )
{ {
currentItem = numItems; currentItem = numItems;
newName = newOption; newName = newOption;

View file

@ -1,7 +1,24 @@
using System.Windows.Forms;
using ImGuiNET; using ImGuiNET;
namespace Penumbra.UI namespace Penumbra.UI
{ {
public static partial class ImGuiCustom
{
public static void CopyOnClickSelectable( string text )
{
if( ImGui.Selectable( text ) )
{
Clipboard.SetText( text );
}
if( ImGui.IsItemHovered() )
{
ImGui.SetTooltip( "Click to copy to clipboard." );
}
}
}
public static partial class ImGuiCustom public static partial class ImGuiCustom
{ {
public static void VerticalDistance( float distance ) public static void VerticalDistance( float distance )

View file

@ -1,5 +1,5 @@
using System.IO; using System.IO;
using System.Linq; using Dalamud.Interface;
using ImGuiNET; using ImGuiNET;
using Penumbra.Mods; using Penumbra.Mods;
using Penumbra.Util; using Penumbra.Util;
@ -13,36 +13,21 @@ namespace Penumbra.UI
private const string LabelTab = "Effective File List"; private const string LabelTab = "Effective File List";
private const float TextSizePadding = 5f; private const float TextSizePadding = 5f;
private ModManager _mods => Service< ModManager >.Get(); private ModManager _mods
private float _maxGamePath; => Service< ModManager >.Get();
public TabEffective( SettingsInterface ui ) private static void DrawFileLine( FileInfo file, GamePath path )
{ {
RebuildFileList( ui._plugin!.Configuration!.ShowAdvanced ); ImGui.TableNextColumn();
} ImGuiCustom.CopyOnClickSelectable( path );
public void RebuildFileList( bool advanced ) ImGui.TableNextColumn();
{ ImGui.PushFont( UiBuilder.IconFont );
if( advanced ) ImGui.TextUnformatted( $"{( char )FontAwesomeIcon.LongArrowAltLeft}" );
{ ImGui.PopFont();
_maxGamePath = TextSizePadding + ( _mods.ResolvedFiles.Count > 0
? _mods.ResolvedFiles.Keys.Max( f => ImGui.CalcTextSize( f ).X )
: 0f );
}
else
{
_maxGamePath = 0f;
}
}
private void DrawFileLine( FileInfo file, GamePath path ) ImGui.TableNextColumn();
{ ImGuiCustom.CopyOnClickSelectable( file.FullName );
ImGui.Selectable( path );
ImGui.SameLine();
ImGui.SetCursorPosX( _maxGamePath );
ImGui.TextUnformatted( " <-- " );
ImGui.SameLine();
ImGui.Selectable( file.FullName );
} }
public void Draw() public void Draw()
@ -53,14 +38,17 @@ namespace Penumbra.UI
return; return;
} }
if( ImGui.BeginListBox( "##effective_files", AutoFillSize ) ) const ImGuiTableFlags flags = ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.RowBg | ImGuiTableFlags.ScrollX;
if( ImGui.BeginTable( "##effective_files", 3, flags, AutoFillSize ) )
{ {
foreach( var file in _mods.ResolvedFiles ) foreach ( var file in _mods.ResolvedFiles )
{ {
DrawFileLine( file.Value, file.Key ); DrawFileLine( file.Value, file.Key );
ImGui.TableNextRow();
} }
ImGui.EndListBox(); ImGui.EndTable();
} }
ImGui.EndTabItem(); ImGui.EndTabItem();

View file

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.IO; using System.IO;
using Dalamud.Interface;
using ImGuiNET; using ImGuiNET;
using Penumbra.Models; using Penumbra.Models;
using Penumbra.Mods; using Penumbra.Mods;
@ -61,7 +62,6 @@ namespace Penumbra.UI
private int _selectedOptionIndex; private int _selectedOptionIndex;
private Option? _selectedOption; private Option? _selectedOption;
private (string label, string name)[]? _changedItemsList; private (string label, string name)[]? _changedItemsList;
private float? _fileSwapOffset;
private string _currentGamePaths = ""; private string _currentGamePaths = "";
private (FileInfo name, bool selected, uint color, RelPath relName)[]? _fullFilenameList; private (FileInfo name, bool selected, uint color, RelPath relName)[]? _fullFilenameList;
@ -116,7 +116,6 @@ namespace Penumbra.UI
public void ResetState() public void ResetState()
{ {
_changedItemsList = null; _changedItemsList = null;
_fileSwapOffset = null;
_fullFilenameList = null; _fullFilenameList = null;
SelectGroup(); SelectGroup();
SelectOption(); SelectOption();
@ -141,7 +140,6 @@ namespace Penumbra.UI
var modManager = Service< ModManager >.Get(); var modManager = Service< ModManager >.Get();
modManager.Mods?.Save(); modManager.Mods?.Save();
modManager.CalculateEffectiveFileList(); modManager.CalculateEffectiveFileList();
_base._menu.EffectiveTab.RebuildFileList( _base._plugin!.Configuration!.ShowAdvanced );
} }
private void DrawAboutTab() private void DrawAboutTab()
@ -275,38 +273,36 @@ namespace Penumbra.UI
return; return;
} }
if( !Meta.FileSwaps.Any() ) if( !Meta.FileSwaps.Any() || !ImGui.BeginTabItem( LabelFileSwapTab ) )
{ {
return; return;
} }
if( ImGui.BeginTabItem( LabelFileSwapTab ) ) const ImGuiTableFlags flags = ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.RowBg | ImGuiTableFlags.ScrollX;
ImGui.SetNextItemWidth( -1 );
if( ImGui.BeginTable( LabelFileSwapHeader, 3, flags, AutoFillSize ) )
{ {
_fileSwapOffset ??= Meta.FileSwaps foreach( var file in Meta.FileSwaps )
.Max( P => ImGui.CalcTextSize( P.Key ).X )
+ TextSizePadding;
ImGui.SetNextItemWidth( -1 );
if( ImGui.BeginListBox( LabelFileSwapHeader, AutoFillSize ) )
{ {
foreach( var file in Meta.FileSwaps ) ImGui.TableNextColumn();
{ ImGuiCustom.CopyOnClickSelectable( file.Key );
ImGui.Selectable( file.Key );
ImGui.SameLine( _fileSwapOffset ?? 0 );
ImGui.TextUnformatted( " -> " );
ImGui.SameLine();
ImGui.Selectable( file.Value );
}
ImGui.EndListBox(); ImGui.TableNextColumn();
ImGui.PushFont( UiBuilder.IconFont );
ImGui.TextUnformatted( $"{( char )FontAwesomeIcon.LongArrowAltRight}" );
ImGui.PopFont();
ImGui.TableNextColumn();
ImGuiCustom.CopyOnClickSelectable( file.Value );
ImGui.TableNextRow();
} }
ImGui.EndTabItem(); ImGui.EndTable();
}
else
{
_fileSwapOffset = null;
} }
ImGui.EndTabItem();
} }
private void UpdateFilenameList() private void UpdateFilenameList()
@ -480,8 +476,6 @@ namespace Penumbra.UI
private void DrawGamePathInput() private void DrawGamePathInput()
{ {
ImGui.TextUnformatted( LabelGamePathsEdit );
ImGui.SameLine();
ImGui.SetNextItemWidth( -1 ); ImGui.SetNextItemWidth( -1 );
ImGui.InputTextWithHint( LabelGamePathsEditBox, "Hover for help...", ref _currentGamePaths, 128 ); ImGui.InputTextWithHint( LabelGamePathsEditBox, "Hover for help...", ref _currentGamePaths, 128 );
if( ImGui.IsItemHovered() ) if( ImGui.IsItemHovered() )

View file

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using Dalamud.Interface;
using ImGuiNET; using ImGuiNET;
using Penumbra.Models; using Penumbra.Models;
using Penumbra.Util; using Penumbra.Util;
@ -12,10 +13,8 @@ namespace Penumbra.UI
private partial class PluginDetails private partial class PluginDetails
{ {
private const string LabelDescEdit = "##descedit"; private const string LabelDescEdit = "##descedit";
private const string LabelNewSingleGroup = "New Single Group";
private const string LabelNewSingleGroupEdit = "##newSingleGroup"; private const string LabelNewSingleGroupEdit = "##newSingleGroup";
private const string LabelNewMultiGroup = "New Multi Group"; private const string LabelNewMultiGroup = "##newMultiGroup";
private const string LabelGamePathsEdit = "Game Paths";
private const string LabelGamePathsEditBox = "##gamePathsEdit"; private const string LabelGamePathsEditBox = "##gamePathsEdit";
private const string ButtonAddToGroup = "Add to Group"; private const string ButtonAddToGroup = "Add to Group";
private const string ButtonRemoveFromGroup = "Remove from Group"; private const string ButtonRemoveFromGroup = "Remove from Group";
@ -318,22 +317,15 @@ namespace Penumbra.UI
{ {
const string hint = "Add new Single Group..."; const string hint = "Add new Single Group...";
var newGroup = ""; var newGroup = "";
ImGui.SetCursorPosX( labelEditPos );
if( labelEditPos == CheckMarkSize ) if( labelEditPos == CheckMarkSize )
{ {
ImGui.SetCursorPosX( CheckMarkSize );
ImGui.SetNextItemWidth( MultiEditBoxWidth ); ImGui.SetNextItemWidth( MultiEditBoxWidth );
if( ImGui.InputTextWithHint( LabelNewSingleGroup, hint, ref newGroup, 64, ImGuiInputTextFlags.EnterReturnsTrue ) )
{
AddNewGroup( newGroup, SelectType.Single );
}
} }
else
if( ImGui.InputTextWithHint( LabelNewSingleGroupEdit, hint, ref newGroup, 64, ImGuiInputTextFlags.EnterReturnsTrue ) )
{ {
ImGuiCustom.RightJustifiedLabel( labelEditPos, LabelNewSingleGroup ); AddNewGroup( newGroup, SelectType.Single );
if( ImGui.InputTextWithHint( LabelNewSingleGroupEdit, hint, ref newGroup, 64, ImGuiInputTextFlags.EnterReturnsTrue ) )
{
AddNewGroup( newGroup, SelectType.Single );
}
} }
} }
@ -342,7 +334,8 @@ namespace Penumbra.UI
var newGroup = ""; var newGroup = "";
ImGui.SetCursorPosX( CheckMarkSize ); ImGui.SetCursorPosX( CheckMarkSize );
ImGui.SetNextItemWidth( MultiEditBoxWidth ); ImGui.SetNextItemWidth( MultiEditBoxWidth );
if( ImGui.InputTextWithHint( LabelNewMultiGroup, "Add new Multi Group...", ref newGroup, 64, ImGuiInputTextFlags.EnterReturnsTrue ) ) if( ImGui.InputTextWithHint( LabelNewMultiGroup, "Add new Multi Group...", ref newGroup, 64,
ImGuiInputTextFlags.EnterReturnsTrue ) )
{ {
AddNewGroup( newGroup, SelectType.Multi ); AddNewGroup( newGroup, SelectType.Multi );
} }
@ -368,41 +361,72 @@ namespace Penumbra.UI
private void DrawFileSwapTabEdit() private void DrawFileSwapTabEdit()
{ {
const string arrow = " -> "; if( !ImGui.BeginTabItem( LabelFileSwapTab ) )
if( ImGui.BeginTabItem( LabelFileSwapTab ) )
{ {
ImGui.SetNextItemWidth( -1 ); return;
if( ImGui.BeginListBox( LabelFileSwapHeader, AutoFillSize ) ) }
{
var swaps = Meta.FileSwaps.Keys.ToArray();
var arrowWidth = ImGui.CalcTextSize( arrow ).X; ImGui.SetNextItemWidth( -1 );
var width = ( ImGui.GetWindowWidth() - arrowWidth - 4 * ImGui.GetStyle().ItemSpacing.X ) / 2; if( ImGui.BeginListBox( LabelFileSwapHeader, AutoFillSize ) )
for( var idx = 0; idx < swaps.Length + 1; ++idx ) {
var swaps = Meta.FileSwaps.Keys.ToArray();
var arrow = $"{( char )FontAwesomeIcon.LongArrowAltRight}";
ImGui.PushFont( UiBuilder.IconFont );
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 )
{
var key = idx == swaps.Length ? GamePath.GenerateUnchecked( "" ) : swaps[ idx ];
var value = idx == swaps.Length ? GamePath.GenerateUnchecked( "" ) : Meta.FileSwaps[ key ];
string keyString = key;
string valueString = value;
ImGui.SetNextItemWidth( width );
if( ImGui.InputTextWithHint( $"##swapLhs_{idx}", "Enter new file to be replaced...", ref keyString,
GamePath.MaxGamePathLength, ImGuiInputTextFlags.EnterReturnsTrue ) )
{ {
var key = idx == swaps.Length ? GamePath.GenerateUnchecked( "" ) : swaps[ idx ]; var newKey = new GamePath( keyString );
var value = idx == swaps.Length ? GamePath.GenerateUnchecked( "" ) : Meta.FileSwaps[ key ]; if( newKey.CompareTo( key ) != 0 )
string keyString = key; {
string valueString = value; if( idx < swaps.Length )
{
Meta.FileSwaps.Remove( key );
}
if( newKey != string.Empty )
{
Meta.FileSwaps[ newKey ] = value;
}
_selector.SaveCurrentMod();
if( Mod.Enabled )
{
_selector.ReloadCurrentMod();
}
}
}
if( idx < swaps.Length )
{
ImGui.SameLine();
ImGui.PushFont( UiBuilder.IconFont );
ImGui.TextUnformatted( arrow );
ImGui.PopFont();
ImGui.SameLine();
ImGui.SetNextItemWidth( width ); ImGui.SetNextItemWidth( width );
if( ImGui.InputTextWithHint( $"##swapLhs_{idx}", "Enter new file to be replaced...", ref keyString, if( ImGui.InputTextWithHint( $"##swapRhs_{idx}", "Enter new replacement path...", ref valueString,
GamePath.MaxGamePathLength, ImGuiInputTextFlags.EnterReturnsTrue ) ) GamePath.MaxGamePathLength,
ImGuiInputTextFlags.EnterReturnsTrue ) )
{ {
var newKey = new GamePath( keyString ); var newValue = new GamePath( valueString );
if( newKey.CompareTo( key ) != 0 ) if( newValue.CompareTo( value ) != 0 )
{ {
if( idx < swaps.Length ) Meta.FileSwaps[ key ] = newValue;
{
Meta.FileSwaps.Remove( key );
}
if( newKey != string.Empty )
{
Meta.FileSwaps[ newKey ] = value;
}
_selector.SaveCurrentMod(); _selector.SaveCurrentMod();
if( Mod.Enabled ) if( Mod.Enabled )
{ {
@ -410,41 +434,13 @@ namespace Penumbra.UI
} }
} }
} }
if( idx < swaps.Length )
{
ImGui.SameLine();
ImGui.TextUnformatted( arrow );
ImGui.SameLine();
ImGui.SetNextItemWidth( width );
if( ImGui.InputTextWithHint( $"##swapRhs_{idx}", "Enter new replacement path...", ref valueString,
GamePath.MaxGamePathLength,
ImGuiInputTextFlags.EnterReturnsTrue ) )
{
var newValue = new GamePath( valueString );
if( newValue.CompareTo( value ) != 0 )
{
Meta.FileSwaps[ key ] = newValue;
_selector.SaveCurrentMod();
if( Mod.Enabled )
{
_selector.ReloadCurrentMod();
}
}
}
}
} }
ImGui.EndListBox();
} }
ImGui.EndTabItem(); ImGui.EndListBox();
}
else
{
_fileSwapOffset = null;
} }
ImGui.EndTabItem();
} }
} }
} }

View file

@ -188,7 +188,6 @@ namespace Penumbra.UI
var modManager = Service< ModManager >.Get(); var modManager = Service< ModManager >.Get();
modManager.Mods!.Save(); modManager.Mods!.Save();
modManager.CalculateEffectiveFileList(); modManager.CalculateEffectiveFileList();
_base._menu.EffectiveTab.RebuildFileList( _base._plugin!.Configuration!.ShowAdvanced );
} }
} }
@ -244,7 +243,6 @@ namespace Penumbra.UI
_selector.SaveCurrentMod(); _selector.SaveCurrentMod();
Mod.Mod.RefreshModFiles(); Mod.Mod.RefreshModFiles();
Service< ModManager >.Get().CalculateEffectiveFileList(); Service< ModManager >.Get().CalculateEffectiveFileList();
_base._menu.EffectiveTab.RebuildFileList( _base._plugin!.Configuration!.ShowAdvanced );
} }
if( ImGui.IsItemHovered() ) if( ImGui.IsItemHovered() )

View file

@ -316,7 +316,6 @@ namespace Penumbra.UI
_mod!.Mod.RefreshModFiles(); _mod!.Mod.RefreshModFiles();
Service< ModManager >.Get().CalculateEffectiveFileList(); Service< ModManager >.Get().CalculateEffectiveFileList();
_base._menu.EffectiveTab.RebuildFileList( _base._plugin!.Configuration!.ShowAdvanced );
ResetModNamesLower(); ResetModNamesLower();
} }

View file

@ -87,7 +87,6 @@ namespace Penumbra.UI
{ {
_config.ShowAdvanced = showAdvanced; _config.ShowAdvanced = showAdvanced;
_configChanged = true; _configChanged = true;
_base._menu.EffectiveTab.RebuildFileList( showAdvanced );
} }
} }

View file

@ -43,7 +43,6 @@ namespace Penumbra.UI
var modManager = Service< ModManager >.Get(); var modManager = Service< ModManager >.Get();
modManager.DiscoverMods( _plugin.Configuration.CurrentCollection ); modManager.DiscoverMods( _plugin.Configuration.CurrentCollection );
_menu.EffectiveTab.RebuildFileList( _plugin.Configuration.ShowAdvanced );
_menu.InstalledTab.Selector.ResetModNamesLower(); _menu.InstalledTab.Selector.ResetModNamesLower();
} }
} }

View file

@ -26,7 +26,7 @@ namespace Penumbra.UI
_importTab = new TabImport( _base ); _importTab = new TabImport( _base );
_browserTab = new TabBrowser(); _browserTab = new TabBrowser();
InstalledTab = new TabInstalled( _base ); InstalledTab = new TabInstalled( _base );
EffectiveTab = new TabEffective( _base ); EffectiveTab = new TabEffective();
} }
#if DEBUG #if DEBUG