Fix some stuff, add Saving.

This commit is contained in:
Ottermandias 2022-09-23 15:21:30 +02:00
parent 47f5e14972
commit 1f2d5246fe
5 changed files with 248 additions and 139 deletions

View file

@ -2,6 +2,7 @@ using System;
using System.IO;
using System.Linq;
using System.Numerics;
using Dalamud.Interface;
using Dalamud.Interface.ImGuiFileDialog;
using ImGuiNET;
using OtterGui;
@ -19,7 +20,20 @@ public partial class ModEditWindow
private readonly FileDialogManager _dialogManager = ConfigWindow.SetupFileManager();
private bool _overlayCollapsed = true;
private DXGIFormat _currentFormat = DXGIFormat.R8G8B8A8UNorm;
private bool _addMipMaps = true;
private int _currentSaveAs = 0;
private static readonly (string, string)[] SaveAsStrings =
{
( "As Is", "Save the current texture with its own format without additional conversion or compression, if possible." ),
( "RGBA (Uncompressed)",
"Save the current texture as an uncompressed BGRA bitmap. This requires the most space but technically offers the best quality." ),
( "BC3 (Simple Compression)",
"Save the current texture compressed via BC3/DXT5 compression. This offers a 4:1 compression ratio and is quick with acceptable quality." ),
( "BC7 (Complex Compression)",
"Save the current texture compressed via BC7 compression. This offers a 4:1 compression ratio and has almost indistinguishable quality, but may take a while." ),
};
private void DrawInputChild( string label, Texture tex, Vector2 size, Vector2 imageSize )
{
@ -37,7 +51,8 @@ public partial class ModEditWindow
_dialogManager );
var files = _editor!.TexFiles.Select( f => f.File.FullName )
.Concat( _editor.TexFiles.SelectMany( f => f.SubModUsage.Select( p => p.Item2.ToString() ) ) );
tex.PathSelectBox( "##combo", "Select the textures included in this mod on your drive or the ones they replace from the game files.", files);
tex.PathSelectBox( "##combo", "Select the textures included in this mod on your drive or the ones they replace from the game files.",
files );
if( tex == _left )
{
@ -52,6 +67,35 @@ public partial class ModEditWindow
tex.Draw( imageSize );
}
private void SaveAsCombo()
{
var (text, desc) = SaveAsStrings[ _currentSaveAs ];
ImGui.SetNextItemWidth( -ImGui.GetFrameHeight() - ImGui.GetStyle().ItemSpacing.X );
using var combo = ImRaii.Combo( "##format", text );
ImGuiUtil.HoverTooltip( desc );
if( !combo )
{
return;
}
foreach( var ((newText, newDesc), idx) in SaveAsStrings.WithIndex() )
{
if( ImGui.Selectable( newText, idx == _currentSaveAs ) )
{
_currentSaveAs = idx;
}
ImGuiUtil.HoverTooltip( newDesc );
}
}
private void MipMapInput()
{
ImGui.Checkbox( "##mipMaps", ref _addMipMaps );
ImGuiUtil.HoverTooltip(
"Add the appropriate number of MipMaps to the file." );
}
private void DrawOutputChild( Vector2 size, Vector2 imageSize )
{
using var child = ImRaii.Child( "Output", size, true );
@ -62,27 +106,57 @@ public partial class ModEditWindow
if( _center.IsLoaded )
{
SaveAsCombo();
ImGui.SameLine();
MipMapInput();
if( ImGui.Button( "Save as TEX", -Vector2.UnitX ) )
{
var fileName = Path.GetFileNameWithoutExtension( _left.Path.Length > 0 ? _left.Path : _right.Path );
_dialogManager.SaveFileDialog( "Save Texture as TEX...", ".tex", fileName, ".tex", ( a, b ) => { }, _mod!.ModPath.FullName );
_dialogManager.SaveFileDialog( "Save Texture as TEX...", ".tex", fileName, ".tex", ( a, b ) =>
{
if( a )
{
_center.SaveAsTex( b, ( CombinedTexture.TextureSaveType )_currentSaveAs, _addMipMaps );
}
}, _mod!.ModPath.FullName );
}
if( ImGui.Button( "Save as DDS", -Vector2.UnitX ) )
{
var fileName = Path.GetFileNameWithoutExtension( _right.Path.Length > 0 ? _right.Path : _left.Path );
_dialogManager.SaveFileDialog( "Save Texture as DDS...", ".dds", fileName, ".dds", ( a, b ) => { if( a ) _center.SaveAsDDS( b, _currentFormat, false ); }, _mod!.ModPath.FullName );
_dialogManager.SaveFileDialog( "Save Texture as DDS...", ".dds", fileName, ".dds", ( a, b ) =>
{
if( a )
{
_center.SaveAsDds( b, ( CombinedTexture.TextureSaveType )_currentSaveAs, _addMipMaps );
}
}, _mod!.ModPath.FullName );
}
ImGui.NewLine();
if( ImGui.Button( "Save as PNG", -Vector2.UnitX ) )
{
var fileName = Path.GetFileNameWithoutExtension( _right.Path.Length > 0 ? _right.Path : _left.Path );
_dialogManager.SaveFileDialog( "Save Texture as PNG...", ".png", fileName, ".png", ( a, b ) => { if (a) _center.SaveAsPng( b ); }, _mod!.ModPath.FullName );
_dialogManager.SaveFileDialog( "Save Texture as PNG...", ".png", fileName, ".png", ( a, b ) =>
{
if( a )
{
_center.SaveAsPng( b );
}
}, _mod!.ModPath.FullName );
}
ImGui.NewLine();
}
if( _center.SaveException != null )
{
ImGui.TextUnformatted( "Could not save file:" );
using var color = ImRaii.PushColor( ImGuiCol.Text, 0xFF0000FF );
ImGuiUtil.TextWrapped( _center.SaveException.ToString() );
}
_center.Draw( imageSize );
}