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 );
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;

View file

@ -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 )

View file

@ -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();

View file

@ -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() )

View file

@ -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();
}
}
}

View file

@ -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() )

View file

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

View file

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

View file

@ -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();
}
}

View file

@ -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