Add drag & drop to texture import.

This commit is contained in:
Ottermandias 2023-08-18 17:16:38 +02:00
parent 0c07d4bec6
commit 53b36f2597
3 changed files with 69 additions and 37 deletions

View file

@ -8,7 +8,6 @@ using Penumbra.Interop.Structs;
using Penumbra.Meta.Manipulations; using Penumbra.Meta.Manipulations;
using Penumbra.Mods; using Penumbra.Mods;
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;

View file

@ -1,4 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
@ -37,30 +39,36 @@ public partial class ModEditWindow
private void DrawInputChild(string label, Texture tex, Vector2 size, Vector2 imageSize) private void DrawInputChild(string label, Texture tex, Vector2 size, Vector2 imageSize)
{ {
using var child = ImRaii.Child(label, size, true); using (var child = ImRaii.Child(label, size, true))
if (!child) {
return; if (!child)
return;
using var id = ImRaii.PushId(label); using var id = ImRaii.PushId(label);
ImGuiUtil.DrawTextButton(label, new Vector2(-1, 0), ImGui.GetColorU32(ImGuiCol.FrameBg)); ImGuiUtil.DrawTextButton(label, new Vector2(-1, 0), ImGui.GetColorU32(ImGuiCol.FrameBg));
ImGui.NewLine(); ImGui.NewLine();
TextureDrawer.PathInputBox(_textures, tex, ref tex.TmpPath, "##input", "Import Image...", TextureDrawer.PathInputBox(_textures, tex, ref tex.TmpPath, "##input", "Import Image...",
"Can import game paths as well as your own files.", _mod!.ModPath.FullName, _fileDialog, _config.DefaultModImportPath); "Can import game paths as well as your own files.", _mod!.ModPath.FullName, _fileDialog, _config.DefaultModImportPath);
if (_textureSelectCombo.Draw("##combo", if (_textureSelectCombo.Draw("##combo",
"Select the textures included in this mod on your drive or the ones they replace from the game files.", tex.Path, "Select the textures included in this mod on your drive or the ones they replace from the game files.", tex.Path,
_mod.ModPath.FullName.Length + 1, out var newPath) && newPath != tex.Path) _mod.ModPath.FullName.Length + 1, out var newPath)
tex.Load(_textures, newPath); && newPath != tex.Path)
tex.Load(_textures, newPath);
if (tex == _left) if (tex == _left)
_center.DrawMatrixInputLeft(size.X); _center.DrawMatrixInputLeft(size.X);
else else
_center.DrawMatrixInputRight(size.X); _center.DrawMatrixInputRight(size.X);
ImGui.NewLine(); ImGui.NewLine();
using var child2 = ImRaii.Child("image"); using var child2 = ImRaii.Child("image");
if (child2) if (child2)
TextureDrawer.Draw(tex, imageSize); TextureDrawer.Draw(tex, imageSize);
}
if (_dragDropManager.CreateImGuiTarget("TextureDragDrop", out var files, out _) && GetFirstTexture(files, out var file))
tex.Load(_textures, file);
} }
private void SaveAsCombo() private void SaveAsCombo()
@ -229,6 +237,15 @@ public partial class ModEditWindow
try try
{ {
_dragDropManager.CreateImGuiSource("TextureDragDrop",
m => m.Extensions.Any(e => ValidTextureExtensions.Contains(e.ToLowerInvariant())), m =>
{
if (!GetFirstTexture(m.Files, out var file))
return false;
ImGui.TextUnformatted($"Dragging texture for editing: {Path.GetFileName(file)}");
return true;
});
var childWidth = GetChildWidth(); var childWidth = GetChildWidth();
var imageSize = new Vector2(childWidth.X - ImGui.GetStyle().FramePadding.X * 2); var imageSize = new Vector2(childWidth.X - ImGui.GetStyle().FramePadding.X * 2);
DrawInputChild("Input Texture", _left, childWidth, imageSize); DrawInputChild("Input Texture", _left, childWidth, imageSize);
@ -259,4 +276,17 @@ public partial class ModEditWindow
ImGuiUtil.HoverTooltip(tooltip); ImGuiUtil.HoverTooltip(tooltip);
} }
private static bool GetFirstTexture(IEnumerable<string> files, [NotNullWhen(true)] out string? file)
{
file = files.FirstOrDefault(f => ValidTextureExtensions.Contains(Path.GetExtension(f).ToLowerInvariant()));
return file != null;
}
private static readonly string[] ValidTextureExtensions =
{
".png",
".dds",
".tex",
};
} }

View file

@ -5,6 +5,7 @@ using System.Numerics;
using System.Text; using System.Text;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Components; using Dalamud.Interface.Components;
using Dalamud.Interface.DragDrop;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using ImGuiNET; using ImGuiNET;
@ -40,6 +41,7 @@ public partial class ModEditWindow : Window, IDisposable
private readonly StainService _stainService; private readonly StainService _stainService;
private readonly ModMergeTab _modMergeTab; private readonly ModMergeTab _modMergeTab;
private readonly CommunicatorService _communicator; private readonly CommunicatorService _communicator;
private readonly IDragDropManager _dragDropManager;
private Mod? _mod; private Mod? _mod;
private Vector2 _iconSize = Vector2.Zero; private Vector2 _iconSize = Vector2.Zero;
@ -303,7 +305,7 @@ public partial class ModEditWindow : Window, IDisposable
new Vector2(300 * UiHelpers.Scale, ImGui.GetFrameHeight()), new Vector2(300 * UiHelpers.Scale, ImGui.GetFrameHeight()),
$"{_editor.ModNormalizer.Step} / {_editor.ModNormalizer.TotalSteps}"); $"{_editor.ModNormalizer.Step} / {_editor.ModNormalizer.TotalSteps}");
} }
else if(ImGuiUtil.DrawDisabledButton("Re-Duplicate and Normalize Mod", Vector2.Zero, tt, !_allowReduplicate && !modifier)) else if (ImGuiUtil.DrawDisabledButton("Re-Duplicate and Normalize Mod", Vector2.Zero, tt, !_allowReduplicate && !modifier))
{ {
_editor.ModNormalizer.Normalize(_mod!); _editor.ModNormalizer.Normalize(_mod!);
_editor.ModNormalizer.Worker.ContinueWith(_ => _editor.LoadMod(_mod!, _editor.GroupIdx, _editor.OptionIdx)); _editor.ModNormalizer.Worker.ContinueWith(_ => _editor.LoadMod(_mod!, _editor.GroupIdx, _editor.OptionIdx));
@ -521,21 +523,22 @@ public partial class ModEditWindow : Window, IDisposable
public ModEditWindow(PerformanceTracker performance, FileDialogService fileDialog, ItemSwapTab itemSwapTab, IDataManager gameData, public ModEditWindow(PerformanceTracker performance, FileDialogService fileDialog, ItemSwapTab itemSwapTab, IDataManager gameData,
Configuration config, ModEditor editor, ResourceTreeFactory resourceTreeFactory, MetaFileManager metaFileManager, Configuration config, ModEditor editor, ResourceTreeFactory resourceTreeFactory, MetaFileManager metaFileManager,
StainService stainService, ActiveCollections activeCollections, DalamudServices dalamud, ModMergeTab modMergeTab, StainService stainService, ActiveCollections activeCollections, DalamudServices dalamud, ModMergeTab modMergeTab,
CommunicatorService communicator, TextureManager textures) CommunicatorService communicator, TextureManager textures, IDragDropManager dragDropManager)
: base(WindowBaseLabel) : base(WindowBaseLabel)
{ {
_performance = performance; _performance = performance;
_itemSwapTab = itemSwapTab; _itemSwapTab = itemSwapTab;
_config = config; _config = config;
_editor = editor; _editor = editor;
_metaFileManager = metaFileManager; _metaFileManager = metaFileManager;
_stainService = stainService; _stainService = stainService;
_activeCollections = activeCollections; _activeCollections = activeCollections;
_dalamud = dalamud; _dalamud = dalamud;
_modMergeTab = modMergeTab; _modMergeTab = modMergeTab;
_communicator = communicator; _communicator = communicator;
_textures = textures; _dragDropManager = dragDropManager;
_fileDialog = fileDialog; _textures = textures;
_fileDialog = fileDialog;
_materialTab = new FileEditor<MtrlTab>(this, gameData, config, _fileDialog, "Materials", ".mtrl", _materialTab = new FileEditor<MtrlTab>(this, gameData, config, _fileDialog, "Materials", ".mtrl",
() => _editor.Files.Mtrl, DrawMaterialPanel, () => _mod?.ModPath.FullName ?? string.Empty, () => _editor.Files.Mtrl, DrawMaterialPanel, () => _mod?.ModPath.FullName ?? string.Empty,
bytes => new MtrlTab(this, new MtrlFile(bytes))); bytes => new MtrlTab(this, new MtrlFile(bytes)));