Almost there...

This commit is contained in:
Ottermandias 2022-04-18 16:14:13 +02:00
parent f3b906007d
commit 65bd1d1b52
59 changed files with 4733 additions and 6194 deletions

View file

@ -1,29 +1,57 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using Dalamud.Interface;
using Dalamud.Interface.ImGuiFileDialog;
using Dalamud.Interface.Components;
using Dalamud.Logging;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using Penumbra.GameData.ByteString;
using OtterGui.Widgets;
using Penumbra.UI.Classes;
using Penumbra.UI.Custom;
namespace Penumbra.UI;
public partial class ConfigWindow
{
private string _newModDirectory = string.Empty;
private string _settingsNewModDirectory = string.Empty;
private readonly FileDialogManager _dialogManager = new();
private bool _dialogOpen;
private static bool DrawPressEnterWarning( string old )
private static bool DrawPressEnterWarning( string old, float width )
{
using var color = ImRaii.PushColor( ImGuiCol.Button, Colors.PressEnterWarningBg );
var w = new Vector2( ImGui.CalcItemWidth(), 0 );
var w = new Vector2( width, 0 );
return ImGui.Button( $"Press Enter or Click Here to Save (Current Directory: {old})", w );
}
private void DrawDirectoryPickerButton()
{
if( ImGuiUtil.DrawDisabledButton( FontAwesomeIcon.Folder.ToIconString(), ImGui.GetFrameHeight() * Vector2.One,
"Select a directory via dialog.", false, true ) )
{
if( _dialogOpen )
{
_dialogManager.Reset();
_dialogOpen = false;
}
else
{
//_dialogManager.OpenFolderDialog( "Choose Mod Directory", ( b, s ) =>
//{
// _newModDirectory = b ? s : _newModDirectory;
// _dialogOpen = false;
//}, _newModDirectory, false);
_dialogOpen = true;
}
}
_dialogManager.Draw();
}
private static void DrawOpenDirectoryButton( int id, DirectoryInfo directory, bool condition )
{
using var _ = ImRaii.PushId( id );
@ -40,41 +68,54 @@ public partial class ConfigWindow
private void DrawRootFolder()
{
using var group = ImRaii.Group();
ImGui.SetNextItemWidth( _inputTextWidth.X );
var save = ImGui.InputText( "Root Directory", ref _newModDirectory, 255, ImGuiInputTextFlags.EnterReturnsTrue );
// Initialize first time.
if( _settingsNewModDirectory.Length == 0 )
{
_settingsNewModDirectory = Penumbra.Config.ModDirectory;
}
var spacing = 3 * ImGuiHelpers.GlobalScale;
using var group = ImRaii.Group();
ImGui.SetNextItemWidth( _inputTextWidth.X - spacing - ImGui.GetFrameHeight() );
var save = ImGui.InputText( "##rootDirectory", ref _settingsNewModDirectory, 255, ImGuiInputTextFlags.EnterReturnsTrue );
using var style = ImRaii.PushStyle( ImGuiStyleVar.ItemSpacing, new Vector2( spacing, 0 ) );
ImGui.SameLine();
ImGuiComponents.HelpMarker( "This is where Penumbra will store your extracted mod files.\n"
DrawDirectoryPickerButton();
style.Pop();
ImGui.SameLine();
ImGuiUtil.LabeledHelpMarker( "Root Directory", "This is where Penumbra will store your extracted mod files.\n"
+ "TTMP files are not copied, just extracted.\n"
+ "This directory needs to be accessible and you need write access here.\n"
+ "It is recommended that this directory is placed on a fast hard drive, preferably an SSD.\n"
+ "It should also be placed near the root of a logical drive - the shorter the total path to this folder, the better.\n"
+ "Definitely do not place it in your Dalamud directory or any sub-directory thereof." );
ImGui.SameLine();
DrawOpenDirectoryButton( 0, Penumbra.ModManager.BasePath, Penumbra.ModManager.Valid );
group.Dispose();
ImGui.SameLine();
var pos = ImGui.GetCursorPosX();
ImGui.NewLine();
if( Penumbra.Config.ModDirectory == _newModDirectory || _newModDirectory.Length == 0 )
if( Penumbra.Config.ModDirectory == _settingsNewModDirectory || _settingsNewModDirectory.Length == 0 )
{
return;
}
if( save || DrawPressEnterWarning( Penumbra.Config.ModDirectory ) )
if( save || DrawPressEnterWarning( Penumbra.Config.ModDirectory, pos ) )
{
Penumbra.ModManager.DiscoverMods( _newModDirectory );
Penumbra.ModManager.DiscoverMods( _settingsNewModDirectory );
}
}
private void DrawRediscoverButton()
private static void DrawRediscoverButton()
{
DrawOpenDirectoryButton( 0, Penumbra.ModManager.BasePath, Penumbra.ModManager.Valid );
ImGui.SameLine();
if( ImGui.Button( "Rediscover Mods" ) )
{
Penumbra.ModManager.DiscoverMods();
}
ImGui.SameLine();
ImGuiComponents.HelpMarker( "Force Penumbra to completely re-scan your root directory as if it was restarted." );
ImGuiUtil.HoverTooltip( "Force Penumbra to completely re-scan your root directory as if it was restarted." );
}
private void DrawEnabledBox()
@ -86,190 +127,41 @@ public partial class ConfigWindow
}
}
private void DrawShowAdvancedBox()
private static void DrawShowAdvancedBox()
{
var showAdvanced = Penumbra.Config.ShowAdvanced;
if( ImGui.Checkbox( "Show Advanced Settings", ref showAdvanced ) )
if( ImGui.Checkbox( "##showAdvanced", ref showAdvanced ) )
{
Penumbra.Config.ShowAdvanced = showAdvanced;
Penumbra.Config.Save();
}
ImGui.SameLine();
ImGuiComponents.HelpMarker( "Enable some advanced options in this window and in the mod selector.\n"
ImGuiUtil.LabeledHelpMarker( "Show Advanced Settings", "Enable some advanced options in this window and in the mod selector.\n"
+ "This is required to enable manually editing any mod information." );
}
private void DrawFolderSortType()
private static void DrawColorSettings()
{
// TODO provide all options
var foldersFirst = Penumbra.Config.SortFoldersFirst;
if( ImGui.Checkbox( "Sort Mod-Folders Before Mods", ref foldersFirst ) )
if( !ImGui.CollapsingHeader( "Colors" ) )
{
Penumbra.Config.SortFoldersFirst = foldersFirst;
Selector.SetFilterDirty();
Penumbra.Config.Save();
return;
}
ImGui.SameLine();
ImGuiComponents.HelpMarker(
"Prioritizes all mod-folders in the mod-selector in the Installed Mods tab so that folders come before single mods, instead of being sorted completely alphabetically" );
}
private void DrawScaleModSelectorBox()
{
// TODO set scale
var scaleModSelector = Penumbra.Config.ScaleModSelector;
if( ImGui.Checkbox( "Scale Mod Selector With Window Size", ref scaleModSelector ) )
foreach( var color in Enum.GetValues< ColorId >() )
{
Penumbra.Config.ScaleModSelector = scaleModSelector;
Penumbra.Config.Save();
}
ImGui.SameLine();
ImGuiComponents.HelpMarker(
"Instead of keeping the mod-selector in the Installed Mods tab a fixed width, this will let it scale with the total size of the Penumbra window." );
}
private void DrawDisableSoundStreamingBox()
{
var tmp = Penumbra.Config.DisableSoundStreaming;
if( ImGui.Checkbox( "Disable Audio Streaming", ref tmp ) && tmp != Penumbra.Config.DisableSoundStreaming )
{
Penumbra.Config.DisableSoundStreaming = tmp;
Penumbra.Config.Save();
if( tmp )
var (defaultColor, name, description) = color.Data();
var currentColor = Penumbra.Config.Colors.TryGetValue( color, out var current ) ? current : defaultColor;
if( Widget.ColorPicker( name, description, currentColor, c => Penumbra.Config.Colors[ color ] = c, defaultColor ) )
{
_penumbra.MusicManager.DisableStreaming();
Penumbra.Config.Save();
}
else
{
_penumbra.MusicManager.EnableStreaming();
}
Penumbra.ModManager.DiscoverMods();
}
ImGui.SameLine();
ImGuiComponents.HelpMarker(
"Disable streaming in the games audio engine.\n"
+ "If you do not disable streaming, you can not replace sound files in the game (*.scd files), they will be ignored by Penumbra.\n\n"
+ "Only touch this if you experience sound problems.\n"
+ "If you toggle this, make sure no modified or to-be-modified sound file is currently playing or was recently playing, else you might crash." );
ImGui.NewLine();
}
private void DrawEnableHttpApiBox()
{
var http = Penumbra.Config.EnableHttpApi;
if( ImGui.Checkbox( "Enable HTTP API", ref http ) )
{
if( http )
{
_penumbra.CreateWebServer();
}
else
{
_penumbra.ShutdownWebServer();
}
Penumbra.Config.EnableHttpApi = http;
Penumbra.Config.Save();
}
ImGui.SameLine();
ImGuiComponents.HelpMarker(
"Enables other applications, e.g. Anamnesis, to use some Penumbra functions, like requesting redraws." );
}
private static void DrawReloadResourceButton()
{
if( ImGui.Button( "Reload Resident Resources" ) )
{
Penumbra.ResidentResources.Reload();
}
ImGui.SameLine();
ImGuiComponents.HelpMarker( "Reload some specific files that the game keeps in memory at all times.\n"
+ "You usually should not need to do this." );
}
private void DrawEnableFullResourceLoggingBox()
{
var tmp = Penumbra.Config.EnableFullResourceLogging;
if( ImGui.Checkbox( "Enable Full Resource Logging", ref tmp ) && tmp != Penumbra.Config.EnableFullResourceLogging )
{
if( tmp )
{
Penumbra.ResourceLoader.EnableFullLogging();
}
else
{
Penumbra.ResourceLoader.DisableFullLogging();
}
Penumbra.Config.EnableFullResourceLogging = tmp;
Penumbra.Config.Save();
}
ImGui.SameLine();
ImGuiComponents.HelpMarker( "[DEBUG] Enable the logging of all ResourceLoader events indiscriminately." );
}
private void DrawEnableDebugModeBox()
{
var tmp = Penumbra.Config.DebugMode;
if( ImGui.Checkbox( "Enable Debug Mode", ref tmp ) && tmp != Penumbra.Config.DebugMode )
{
if( tmp )
{
Penumbra.ResourceLoader.EnableDebug();
}
else
{
Penumbra.ResourceLoader.DisableDebug();
}
Penumbra.Config.DebugMode = tmp;
Penumbra.Config.Save();
}
ImGui.SameLine();
ImGuiComponents.HelpMarker( "[DEBUG] Enable the Debug Tab and Resource Manager Tab as well as some additional data collection." );
}
private void DrawRequestedResourceLogging()
{
var tmp = Penumbra.Config.EnableResourceLogging;
if( ImGui.Checkbox( "Enable Requested Resource Logging", ref tmp ) )
{
_penumbra.ResourceLogger.SetState( tmp );
}
ImGui.SameLine();
ImGuiComponents.HelpMarker( "Log all game paths FFXIV requests to the plugin log.\n"
+ "You can filter the logged paths for those containing the entered string or matching the regex, if the entered string compiles to a valid regex.\n"
+ "Red boundary indicates invalid regex." );
ImGui.SameLine();
var tmpString = Penumbra.Config.ResourceLoggingFilter;
using var color = ImRaii.PushColor( ImGuiCol.Border, 0xFF0000B0, !_penumbra.ResourceLogger.ValidRegex );
using var style = ImRaii.PushStyle( ImGuiStyleVar.FrameBorderSize, ImGuiHelpers.GlobalScale, !_penumbra.ResourceLogger.ValidRegex );
if( ImGui.InputTextWithHint( "##ResourceLogFilter", "Filter...", ref tmpString, Utf8GamePath.MaxGamePathLength ) )
{
_penumbra.ResourceLogger.SetFilter( tmpString );
}
}
private void DrawAdvancedSettings()
{
DrawRequestedResourceLogging();
DrawDisableSoundStreamingBox();
DrawEnableHttpApiBox();
DrawReloadResourceButton();
DrawEnableDebugModeBox();
DrawEnableFullResourceLoggingBox();
}
public void DrawSettingsTab()
{
using var tab = ImRaii.TabItem( "Settings" );
@ -284,34 +176,15 @@ public partial class ConfigWindow
return;
}
DrawRootFolder();
DrawRediscoverButton();
ImGui.Dummy( _verticalSpace );
DrawEnabledBox();
ImGui.Dummy( _verticalSpace );
DrawFolderSortType();
DrawScaleModSelectorBox();
DrawShowAdvancedBox();
ImGui.NewLine();
DrawRootFolder();
DrawRediscoverButton();
ImGui.NewLine();
if( Penumbra.Config.ShowAdvanced )
{
DrawAdvancedSettings();
}
if( ImGui.CollapsingHeader( "Colors" ) )
{
foreach( var color in Enum.GetValues< ColorId >() )
{
var (defaultColor, name, description) = color.Data();
var currentColor = Penumbra.Config.Colors.TryGetValue( color, out var current ) ? current : defaultColor;
if( ImGuiUtil.ColorPicker( name, description, currentColor, c => Penumbra.Config.Colors[ color ] = c, defaultColor ) )
{
Penumbra.Config.Save();
}
}
}
DrawModSelectorSettings();
DrawColorSettings();
DrawAdvancedSettings();
}
}