From 819264045b5c3fd409713248892b1b965385e7fe Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Thu, 22 Sep 2022 14:25:19 +0200 Subject: [PATCH] Add signal that a game path can not be added to file redirections, maybe fix some UsedGamePath bugs. --- Penumbra/Mods/Editor/Mod.Editor.Edit.cs | 9 +-------- Penumbra/Mods/Editor/Mod.Editor.Files.cs | 9 +++++++-- Penumbra/UI/Classes/ModEditWindow.Files.cs | 20 +++++++++++++++++++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Penumbra/Mods/Editor/Mod.Editor.Edit.cs b/Penumbra/Mods/Editor/Mod.Editor.Edit.cs index 3b27f573..29f5389b 100644 --- a/Penumbra/Mods/Editor/Mod.Editor.Edit.cs +++ b/Penumbra/Mods/Editor/Mod.Editor.Edit.cs @@ -37,14 +37,7 @@ public partial class Mod } Penumbra.ModManager.OptionSetFiles( _mod, _subMod.GroupIdx, _subMod.OptionIdx, dict ); - if( num > 0 ) - { - RevertFiles(); - } - else - { - FileChanges = false; - } + UpdateFiles(); return num; } diff --git a/Penumbra/Mods/Editor/Mod.Editor.Files.cs b/Penumbra/Mods/Editor/Mod.Editor.Files.cs index 9f1d8fa5..f9505f9d 100644 --- a/Penumbra/Mods/Editor/Mod.Editor.Files.cs +++ b/Penumbra/Mods/Editor/Mod.Editor.Files.cs @@ -94,7 +94,7 @@ public partial class Mod { void HandleSubMod( ISubMod mod, int groupIdx, int optionIdx ) { - var newDict = mod.Files.Where( kvp => CheckAgainstMissing( kvp.Value, kvp.Key ) ) + var newDict = mod.Files.Where( kvp => CheckAgainstMissing( kvp.Value, kvp.Key, mod == _subMod ) ) .ToDictionary( kvp => kvp.Key, kvp => kvp.Value ); if( newDict.Count != mod.Files.Count ) { @@ -106,13 +106,18 @@ public partial class Mod _missingFiles.Clear(); } - private bool CheckAgainstMissing( FullPath file, Utf8GamePath key ) + private bool CheckAgainstMissing( FullPath file, Utf8GamePath key, bool removeUsed ) { if( !_missingFiles.Contains( file ) ) { return true; } + if( removeUsed ) + { + _usedPaths.Remove( key ); + } + Penumbra.Log.Debug( $"[RemoveMissingPaths] Removing {key} -> {file} from {_mod.Name}." ); return false; } diff --git a/Penumbra/UI/Classes/ModEditWindow.Files.cs b/Penumbra/UI/Classes/ModEditWindow.Files.cs index 74a5b6e9..dff8eaa6 100644 --- a/Penumbra/UI/Classes/ModEditWindow.Files.cs +++ b/Penumbra/UI/Classes/ModEditWindow.Files.cs @@ -8,6 +8,7 @@ using OtterGui; using OtterGui.Classes; using OtterGui.Raii; using Penumbra.GameData.ByteString; +using Penumbra.GameData.Util; using Penumbra.Mods; namespace Penumbra.UI.Classes; @@ -230,7 +231,7 @@ public partial class ModEditWindow using var id = ImRaii.PushId( j ); ImGui.TableNextColumn(); var tmp = _fileIdx == i && _pathIdx == j ? _gamePathEdit : gamePath.ToString(); - + var pos = ImGui.GetCursorPosX() - ImGui.GetFrameHeight(); ImGui.SetNextItemWidth( -1 ); if( ImGui.InputText( string.Empty, ref tmp, Utf8GamePath.MaxGamePathLength ) ) { @@ -251,11 +252,20 @@ public partial class ModEditWindow _fileIdx = -1; _pathIdx = -1; } + else if( _fileIdx == i && _pathIdx == j && ( !Utf8GamePath.FromString( _gamePathEdit, out var path, false ) + || !path.IsEmpty && !path.Equals( gamePath ) && !_editor!.CanAddGamePath( path )) ) + { + ImGui.SameLine(); + ImGui.SetCursorPosX( pos ); + using var font = ImRaii.PushFont( UiBuilder.IconFont ); + ImGuiUtil.TextColored( 0xFF0000FF, FontAwesomeIcon.TimesCircle.ToIconString() ); + } } private void PrintNewGamePath( int i, Mod.Editor.FileRegistry registry, ISubMod subMod ) { var tmp = _fileIdx == i && _pathIdx == -1 ? _gamePathEdit : string.Empty; + var pos = ImGui.GetCursorPosX() - ImGui.GetFrameHeight(); ImGui.SetNextItemWidth( -1 ); if( ImGui.InputTextWithHint( "##new", "Add New Path...", ref tmp, Utf8GamePath.MaxGamePathLength ) ) { @@ -274,6 +284,14 @@ public partial class ModEditWindow _fileIdx = -1; _pathIdx = -1; } + else if( _fileIdx == i && _pathIdx == -1 && (!Utf8GamePath.FromString( _gamePathEdit, out var path, false ) + || !path.IsEmpty && !_editor!.CanAddGamePath( path )) ) + { + ImGui.SameLine(); + ImGui.SetCursorPosX( pos ); + using var font = ImRaii.PushFont( UiBuilder.IconFont ); + ImGuiUtil.TextColored( 0xFF0000FF, FontAwesomeIcon.TimesCircle.ToIconString() ); + } } private void DrawButtonHeader()