From 668371dae8da40596dfccaf82432a50287a891a9 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Tue, 20 Apr 2021 16:32:03 +0200 Subject: [PATCH] Some further interface improvements. --- Penumbra/UI/Custom/ImGuiRenameableCombo.cs | 2 +- Penumbra/UI/Custom/ImGuiUtil.cs | 17 +++ Penumbra/UI/MenuTabs/TabEffective.cs | 48 +++--- .../TabInstalled/TabInstalledDetails.cs | 48 +++--- .../TabInstalled/TabInstalledDetailsEdit.cs | 144 +++++++++--------- .../TabInstalled/TabInstalledModPanel.cs | 2 - .../TabInstalled/TabInstalledSelector.cs | 1 - Penumbra/UI/MenuTabs/TabSettings.cs | 1 - Penumbra/UI/SettingsInterface.cs | 1 - Penumbra/UI/SettingsMenu.cs | 2 +- 10 files changed, 128 insertions(+), 138 deletions(-) diff --git a/Penumbra/UI/Custom/ImGuiRenameableCombo.cs b/Penumbra/UI/Custom/ImGuiRenameableCombo.cs index 0e1f49ba..c26c8a1a 100644 --- a/Penumbra/UI/Custom/ImGuiRenameableCombo.cs +++ b/Penumbra/UI/Custom/ImGuiRenameableCombo.cs @@ -33,7 +33,7 @@ namespace Penumbra.UI } 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; newName = newOption; diff --git a/Penumbra/UI/Custom/ImGuiUtil.cs b/Penumbra/UI/Custom/ImGuiUtil.cs index 6e473b0c..0403dd64 100644 --- a/Penumbra/UI/Custom/ImGuiUtil.cs +++ b/Penumbra/UI/Custom/ImGuiUtil.cs @@ -1,7 +1,24 @@ +using System.Windows.Forms; using ImGuiNET; 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 void VerticalDistance( float distance ) diff --git a/Penumbra/UI/MenuTabs/TabEffective.cs b/Penumbra/UI/MenuTabs/TabEffective.cs index a5e7e3c9..8df660f5 100644 --- a/Penumbra/UI/MenuTabs/TabEffective.cs +++ b/Penumbra/UI/MenuTabs/TabEffective.cs @@ -1,5 +1,5 @@ using System.IO; -using System.Linq; +using Dalamud.Interface; using ImGuiNET; using Penumbra.Mods; using Penumbra.Util; @@ -13,36 +13,21 @@ namespace Penumbra.UI private const string LabelTab = "Effective File List"; private const float TextSizePadding = 5f; - private ModManager _mods => Service< ModManager >.Get(); - private float _maxGamePath; + private ModManager _mods + => 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 ) - { - if( advanced ) - { - _maxGamePath = TextSizePadding + ( _mods.ResolvedFiles.Count > 0 - ? _mods.ResolvedFiles.Keys.Max( f => ImGui.CalcTextSize( f ).X ) - : 0f ); - } - else - { - _maxGamePath = 0f; - } - } + ImGui.TableNextColumn(); + ImGui.PushFont( UiBuilder.IconFont ); + ImGui.TextUnformatted( $"{( char )FontAwesomeIcon.LongArrowAltLeft}" ); + ImGui.PopFont(); - private void DrawFileLine( FileInfo file, GamePath path ) - { - ImGui.Selectable( path ); - ImGui.SameLine(); - ImGui.SetCursorPosX( _maxGamePath ); - ImGui.TextUnformatted( " <-- " ); - ImGui.SameLine(); - ImGui.Selectable( file.FullName ); + ImGui.TableNextColumn(); + ImGuiCustom.CopyOnClickSelectable( file.FullName ); } public void Draw() @@ -53,14 +38,17 @@ namespace Penumbra.UI 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 ); + ImGui.TableNextRow(); } - ImGui.EndListBox(); + ImGui.EndTable(); } ImGui.EndTabItem(); diff --git a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetails.cs b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetails.cs index 2822e633..10f9b1f1 100644 --- a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetails.cs +++ b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetails.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.IO; +using Dalamud.Interface; using ImGuiNET; using Penumbra.Models; using Penumbra.Mods; @@ -61,7 +62,6 @@ namespace Penumbra.UI private int _selectedOptionIndex; private Option? _selectedOption; private (string label, string name)[]? _changedItemsList; - private float? _fileSwapOffset; private string _currentGamePaths = ""; private (FileInfo name, bool selected, uint color, RelPath relName)[]? _fullFilenameList; @@ -116,7 +116,6 @@ namespace Penumbra.UI public void ResetState() { _changedItemsList = null; - _fileSwapOffset = null; _fullFilenameList = null; SelectGroup(); SelectOption(); @@ -141,7 +140,6 @@ namespace Penumbra.UI var modManager = Service< ModManager >.Get(); modManager.Mods?.Save(); modManager.CalculateEffectiveFileList(); - _base._menu.EffectiveTab.RebuildFileList( _base._plugin!.Configuration!.ShowAdvanced ); } private void DrawAboutTab() @@ -275,38 +273,36 @@ namespace Penumbra.UI return; } - if( !Meta.FileSwaps.Any() ) + if( !Meta.FileSwaps.Any() || !ImGui.BeginTabItem( LabelFileSwapTab ) ) { 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 - .Max( P => ImGui.CalcTextSize( P.Key ).X ) - + TextSizePadding; - - ImGui.SetNextItemWidth( -1 ); - if( ImGui.BeginListBox( LabelFileSwapHeader, AutoFillSize ) ) + foreach( var file in Meta.FileSwaps ) { - foreach( var file in Meta.FileSwaps ) - { - ImGui.Selectable( file.Key ); - ImGui.SameLine( _fileSwapOffset ?? 0 ); - ImGui.TextUnformatted( " -> " ); - ImGui.SameLine(); - ImGui.Selectable( file.Value ); - } + ImGui.TableNextColumn(); + ImGuiCustom.CopyOnClickSelectable( file.Key ); - 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(); - } - else - { - _fileSwapOffset = null; + ImGui.EndTable(); } + + ImGui.EndTabItem(); } private void UpdateFilenameList() @@ -480,8 +476,6 @@ namespace Penumbra.UI private void DrawGamePathInput() { - ImGui.TextUnformatted( LabelGamePathsEdit ); - ImGui.SameLine(); ImGui.SetNextItemWidth( -1 ); ImGui.InputTextWithHint( LabelGamePathsEditBox, "Hover for help...", ref _currentGamePaths, 128 ); if( ImGui.IsItemHovered() ) diff --git a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetailsEdit.cs b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetailsEdit.cs index e4fd80af..a0f0f84f 100644 --- a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetailsEdit.cs +++ b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetailsEdit.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; +using Dalamud.Interface; using ImGuiNET; using Penumbra.Models; using Penumbra.Util; @@ -12,10 +13,8 @@ namespace Penumbra.UI private partial class PluginDetails { private const string LabelDescEdit = "##descedit"; - private const string LabelNewSingleGroup = "New Single Group"; private const string LabelNewSingleGroupEdit = "##newSingleGroup"; - private const string LabelNewMultiGroup = "New Multi Group"; - private const string LabelGamePathsEdit = "Game Paths"; + private const string LabelNewMultiGroup = "##newMultiGroup"; private const string LabelGamePathsEditBox = "##gamePathsEdit"; private const string ButtonAddToGroup = "Add to Group"; private const string ButtonRemoveFromGroup = "Remove from Group"; @@ -318,22 +317,15 @@ namespace Penumbra.UI { const string hint = "Add new Single Group..."; var newGroup = ""; + ImGui.SetCursorPosX( labelEditPos ); if( labelEditPos == CheckMarkSize ) { - ImGui.SetCursorPosX( CheckMarkSize ); 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 ); - if( ImGui.InputTextWithHint( LabelNewSingleGroupEdit, hint, ref newGroup, 64, ImGuiInputTextFlags.EnterReturnsTrue ) ) - { - AddNewGroup( newGroup, SelectType.Single ); - } + AddNewGroup( newGroup, SelectType.Single ); } } @@ -342,7 +334,8 @@ namespace Penumbra.UI var newGroup = ""; ImGui.SetCursorPosX( CheckMarkSize ); 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 ); } @@ -368,41 +361,72 @@ namespace Penumbra.UI private void DrawFileSwapTabEdit() { - const string arrow = " -> "; - - if( ImGui.BeginTabItem( LabelFileSwapTab ) ) + if( !ImGui.BeginTabItem( LabelFileSwapTab ) ) { - ImGui.SetNextItemWidth( -1 ); - if( ImGui.BeginListBox( LabelFileSwapHeader, AutoFillSize ) ) - { - var swaps = Meta.FileSwaps.Keys.ToArray(); + return; + } - var arrowWidth = ImGui.CalcTextSize( arrow ).X; - var width = ( ImGui.GetWindowWidth() - arrowWidth - 4 * ImGui.GetStyle().ItemSpacing.X ) / 2; - for( var idx = 0; idx < swaps.Length + 1; ++idx ) + ImGui.SetNextItemWidth( -1 ); + if( ImGui.BeginListBox( LabelFileSwapHeader, AutoFillSize ) ) + { + 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 value = idx == swaps.Length ? GamePath.GenerateUnchecked( "" ) : Meta.FileSwaps[ key ]; - string keyString = key; - string valueString = value; + var newKey = new GamePath( keyString ); + if( newKey.CompareTo( key ) != 0 ) + { + 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 ); - if( ImGui.InputTextWithHint( $"##swapLhs_{idx}", "Enter new file to be replaced...", ref keyString, - GamePath.MaxGamePathLength, ImGuiInputTextFlags.EnterReturnsTrue ) ) + if( ImGui.InputTextWithHint( $"##swapRhs_{idx}", "Enter new replacement path...", ref valueString, + GamePath.MaxGamePathLength, + ImGuiInputTextFlags.EnterReturnsTrue ) ) { - var newKey = new GamePath( keyString ); - if( newKey.CompareTo( key ) != 0 ) + var newValue = new GamePath( valueString ); + if( newValue.CompareTo( value ) != 0 ) { - if( idx < swaps.Length ) - { - Meta.FileSwaps.Remove( key ); - } - - if( newKey != string.Empty ) - { - Meta.FileSwaps[ newKey ] = value; - } - + Meta.FileSwaps[ key ] = newValue; _selector.SaveCurrentMod(); 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(); - } - else - { - _fileSwapOffset = null; + ImGui.EndListBox(); } + + ImGui.EndTabItem(); } } } diff --git a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledModPanel.cs b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledModPanel.cs index 6858db68..b48c6cae 100644 --- a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledModPanel.cs +++ b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledModPanel.cs @@ -188,7 +188,6 @@ namespace Penumbra.UI var modManager = Service< ModManager >.Get(); modManager.Mods!.Save(); modManager.CalculateEffectiveFileList(); - _base._menu.EffectiveTab.RebuildFileList( _base._plugin!.Configuration!.ShowAdvanced ); } } @@ -244,7 +243,6 @@ namespace Penumbra.UI _selector.SaveCurrentMod(); Mod.Mod.RefreshModFiles(); Service< ModManager >.Get().CalculateEffectiveFileList(); - _base._menu.EffectiveTab.RebuildFileList( _base._plugin!.Configuration!.ShowAdvanced ); } if( ImGui.IsItemHovered() ) diff --git a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledSelector.cs b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledSelector.cs index fb74739a..d62e6c0f 100644 --- a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledSelector.cs +++ b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledSelector.cs @@ -316,7 +316,6 @@ namespace Penumbra.UI _mod!.Mod.RefreshModFiles(); Service< ModManager >.Get().CalculateEffectiveFileList(); - _base._menu.EffectiveTab.RebuildFileList( _base._plugin!.Configuration!.ShowAdvanced ); ResetModNamesLower(); } diff --git a/Penumbra/UI/MenuTabs/TabSettings.cs b/Penumbra/UI/MenuTabs/TabSettings.cs index 8b5ccc57..ccea3a30 100644 --- a/Penumbra/UI/MenuTabs/TabSettings.cs +++ b/Penumbra/UI/MenuTabs/TabSettings.cs @@ -87,7 +87,6 @@ namespace Penumbra.UI { _config.ShowAdvanced = showAdvanced; _configChanged = true; - _base._menu.EffectiveTab.RebuildFileList( showAdvanced ); } } diff --git a/Penumbra/UI/SettingsInterface.cs b/Penumbra/UI/SettingsInterface.cs index 362c44b3..6a17bd9b 100644 --- a/Penumbra/UI/SettingsInterface.cs +++ b/Penumbra/UI/SettingsInterface.cs @@ -43,7 +43,6 @@ namespace Penumbra.UI var modManager = Service< ModManager >.Get(); modManager.DiscoverMods( _plugin.Configuration.CurrentCollection ); - _menu.EffectiveTab.RebuildFileList( _plugin.Configuration.ShowAdvanced ); _menu.InstalledTab.Selector.ResetModNamesLower(); } } diff --git a/Penumbra/UI/SettingsMenu.cs b/Penumbra/UI/SettingsMenu.cs index 947ca81f..b01b684f 100644 --- a/Penumbra/UI/SettingsMenu.cs +++ b/Penumbra/UI/SettingsMenu.cs @@ -26,7 +26,7 @@ namespace Penumbra.UI _importTab = new TabImport( _base ); _browserTab = new TabBrowser(); InstalledTab = new TabInstalled( _base ); - EffectiveTab = new TabEffective( _base ); + EffectiveTab = new TabEffective(); } #if DEBUG