Let SubMods know their location in a mod.

This commit is contained in:
Ottermandias 2022-07-27 10:37:45 +02:00
parent 0b2b0d1beb
commit d6c0362404
18 changed files with 223 additions and 121 deletions

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using Dalamud.Interface;
@ -23,6 +24,7 @@ public partial class ModEditWindow
private int _fileIdx = -1;
private int _pathIdx = -1;
private int _folderSkip = 0;
private bool _overviewMode = false;
private bool CheckFilter( Mod.Editor.FileRegistry registry )
=> _fileFilter.IsEmpty || registry.File.FullName.Contains( _fileFilter.Lower, StringComparison.OrdinalIgnoreCase );
@ -47,7 +49,73 @@ public partial class ModEditWindow
return;
}
if( _overviewMode )
DrawFilesOverviewMode();
else
DrawFilesNormalMode();
}
private void DrawFilesOverviewMode()
{
using var list = ImRaii.Table( "##table", 3, ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingFixedFit );
if( !list )
{
return;
}
var idx = 0;
void Draw( Mod.Editor.FileRegistry registry )
{
if( registry.SubModUsage.Count == 0 )
{
using var id = ImRaii.PushId( idx++ );
ImGui.TableNextColumn();
ImGui.TableSetBgColor( ImGuiTableBgTarget.CellBg, 0x40000080 );
ImGui.Selectable( registry.RelPath.ToString() );
ImGui.TableNextColumn();
ImGui.TableSetBgColor( ImGuiTableBgTarget.CellBg, 0x40000080 );
ImGui.TextUnformatted( "Unused" );
ImGui.TableSetBgColor( ImGuiTableBgTarget.CellBg, 0x40000080 );
ImGui.TableNextColumn();
}
else
{
foreach( var (mod, path) in registry.SubModUsage )
{
using var id = ImRaii.PushId( idx++ );
var color = mod == _editor.CurrentOption && _mod!.HasOptions;
ImGui.TableNextColumn();
if( color )
ImGui.TableSetBgColor( ImGuiTableBgTarget.CellBg, 0x40008000 );
ImGui.Selectable( registry.RelPath.ToString() );
ImGui.TableNextColumn();
if( color )
ImGui.TableSetBgColor( ImGuiTableBgTarget.CellBg, 0x40008000 );
ImGui.Selectable( path.ToString() );
ImGui.TableNextColumn();
if( color )
ImGui.TableSetBgColor( ImGuiTableBgTarget.CellBg, 0x40008000 );
ImGui.TextUnformatted( mod.Name );
}
}
}
bool Filter( Mod.Editor.FileRegistry registry )
{
return true;
}
var skips = ImGuiClip.GetNecessarySkips( ImGui.GetTextLineHeight() );
var end = ImGuiClip.FilteredClippedDraw( _editor!.AvailableFiles, skips, Filter, Draw, 0 );
ImGuiClip.DrawEndDummy( end, ImGui.GetTextLineHeight() );
}
private void DrawFilesNormalMode()
{
using var list = ImRaii.Table( "##table", 1 );
if( !list )
{
return;
@ -68,7 +136,7 @@ public partial class ModEditWindow
using var indent = ImRaii.PushIndent( 50f );
for( var j = 0; j < registry.SubModUsage.Count; ++j )
{
var (subMod, gamePath) = registry.SubModUsage[ j ];
var (subMod, gamePath) = registry.SubModUsage[j];
if( subMod != _editor.CurrentOption )
{
continue;
@ -158,6 +226,7 @@ public partial class ModEditWindow
{
_editor!.SetGamePath( _fileIdx, _pathIdx, path );
}
_fileIdx = -1;
_pathIdx = -1;
}
@ -180,6 +249,7 @@ public partial class ModEditWindow
{
_editor!.SetGamePath( _fileIdx, _pathIdx, path );
}
_fileIdx = -1;
_pathIdx = -1;
}
@ -241,6 +311,13 @@ public partial class ModEditWindow
ImGuiUtil.HoverTooltip( "Revert all revertible changes since the last file or option reload or data refresh." );
ImGui.SameLine();
ImGui.Checkbox( "Overview Mode", ref _overviewMode );
if( _overviewMode )
{
return;
}
ImGui.SetNextItemWidth( 250 * ImGuiHelpers.GlobalScale );
LowerString.InputWithHint( "##filter", "Filter paths...", ref _fileFilter, Utf8GamePath.MaxGamePathLength );
ImGui.SameLine();

View file

@ -31,7 +31,7 @@ public partial class ModEditWindow : Window, IDisposable
}
_editor?.Dispose();
_editor = new Editor( mod, -1, 0 );
_editor = new Editor( mod, mod.Default );
_mod = mod;
SizeConstraints = new WindowSizeConstraints
@ -42,8 +42,8 @@ public partial class ModEditWindow : Window, IDisposable
_selectedFiles.Clear();
}
public void ChangeOption( int groupIdx, int optionIdx )
=> _editor?.SetSubMod( groupIdx, optionIdx );
public void ChangeOption( ISubMod? subMod )
=> _editor?.SetSubMod( subMod );
public override bool DrawConditions()
=> _editor != null;
@ -437,56 +437,34 @@ public partial class ModEditWindow : Window, IDisposable
private void DrawOptionSelectHeader()
{
const string defaultOption = "Default Option";
using var style = ImRaii.PushStyle( ImGuiStyleVar.ItemSpacing, Vector2.Zero ).Push( ImGuiStyleVar.FrameRounding, 0 );
var width = new Vector2( ImGui.GetWindowWidth() / 3, 0 );
var isDefaultOption = _editor!.GroupIdx == -1 && _editor!.OptionIdx == 0;
const string defaultOption = "Default Option";
using var style = ImRaii.PushStyle( ImGuiStyleVar.ItemSpacing, Vector2.Zero ).Push( ImGuiStyleVar.FrameRounding, 0 );
var width = new Vector2( ImGui.GetWindowWidth() / 3, 0 );
if( ImGuiUtil.DrawDisabledButton( defaultOption, width, "Switch to the default option for the mod.\nThis resets unsaved changes.",
isDefaultOption ) )
_editor!.CurrentOption.IsDefault ) )
{
_editor.SetSubMod( -1, 0 );
isDefaultOption = true;
_editor.SetSubMod( _mod!.Default );
}
ImGui.SameLine();
if( ImGuiUtil.DrawDisabledButton( "Refresh Data", width, "Refresh data for the current option.\nThis resets unsaved changes.", false ) )
{
_editor.SetSubMod( _editor.GroupIdx, _editor.OptionIdx );
_editor.SetSubMod( _editor.CurrentOption );
}
ImGui.SameLine();
string GetLabel()
{
if( isDefaultOption )
{
return defaultOption;
}
var group = _mod!.Groups[ _editor!.GroupIdx ];
return $"{group.Name}: {group[ _editor.OptionIdx ].Name}";
}
using var combo = ImRaii.Combo( "##optionSelector", GetLabel(), ImGuiComboFlags.NoArrowButton );
using var combo = ImRaii.Combo( "##optionSelector", _editor.CurrentOption.FullName, ImGuiComboFlags.NoArrowButton );
if( !combo )
{
return;
}
if( ImGui.Selectable( $"{defaultOption}###-1_0", isDefaultOption ) )
foreach( var option in _mod!.AllSubMods )
{
_editor.SetSubMod( -1, 0 );
}
foreach( var (group, groupIdx) in _mod!.Groups.WithIndex() )
{
foreach( var (option, optionIdx) in group.WithIndex() )
if( ImGui.Selectable( option.FullName, option == _editor.CurrentOption ) )
{
var name = $"{group.Name}: {option.Name}###{groupIdx}_{optionIdx}";
if( ImGui.Selectable( name, groupIdx == _editor.GroupIdx && optionIdx == _editor.OptionIdx ) )
{
_editor.SetSubMod( groupIdx, optionIdx );
}
_editor.SetSubMod( option );
}
}
}

View file

@ -61,7 +61,7 @@ public partial class ConfigWindow
if( ImGui.TabItemButton( "Advanced Editing", ImGuiTabItemFlags.Trailing | ImGuiTabItemFlags.NoTooltip ) )
{
_window.ModEditPopup.ChangeMod( _mod );
_window.ModEditPopup.ChangeOption( -1, 0 );
_window.ModEditPopup.ChangeOption( _mod.Default );
_window.ModEditPopup.IsOpen = true;
}
@ -142,7 +142,7 @@ public partial class ConfigWindow
{
var priority = conflict.Mod2.Index < 0
? conflict.Mod2.Priority
: Penumbra.CollectionManager.Current[conflict.Mod2.Index].Settings!.Priority;
: Penumbra.CollectionManager.Current[ conflict.Mod2.Index ].Settings!.Priority;
ImGui.TextUnformatted( $"(Priority {priority})" );
}