mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Add drag & drop to texture import.
This commit is contained in:
parent
0c07d4bec6
commit
53b36f2597
3 changed files with 69 additions and 37 deletions
|
|
@ -8,7 +8,6 @@ using Penumbra.Interop.Structs;
|
|||
using Penumbra.Meta.Manipulations;
|
||||
using Penumbra.Mods;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
|
@ -37,30 +39,36 @@ public partial class ModEditWindow
|
|||
|
||||
private void DrawInputChild(string label, Texture tex, Vector2 size, Vector2 imageSize)
|
||||
{
|
||||
using var child = ImRaii.Child(label, size, true);
|
||||
if (!child)
|
||||
return;
|
||||
using (var child = ImRaii.Child(label, size, true))
|
||||
{
|
||||
if (!child)
|
||||
return;
|
||||
|
||||
using var id = ImRaii.PushId(label);
|
||||
ImGuiUtil.DrawTextButton(label, new Vector2(-1, 0), ImGui.GetColorU32(ImGuiCol.FrameBg));
|
||||
ImGui.NewLine();
|
||||
using var id = ImRaii.PushId(label);
|
||||
ImGuiUtil.DrawTextButton(label, new Vector2(-1, 0), ImGui.GetColorU32(ImGuiCol.FrameBg));
|
||||
ImGui.NewLine();
|
||||
|
||||
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);
|
||||
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,
|
||||
_mod.ModPath.FullName.Length + 1, out var newPath) && newPath != tex.Path)
|
||||
tex.Load(_textures, newPath);
|
||||
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);
|
||||
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,
|
||||
_mod.ModPath.FullName.Length + 1, out var newPath)
|
||||
&& newPath != tex.Path)
|
||||
tex.Load(_textures, newPath);
|
||||
|
||||
if (tex == _left)
|
||||
_center.DrawMatrixInputLeft(size.X);
|
||||
else
|
||||
_center.DrawMatrixInputRight(size.X);
|
||||
if (tex == _left)
|
||||
_center.DrawMatrixInputLeft(size.X);
|
||||
else
|
||||
_center.DrawMatrixInputRight(size.X);
|
||||
|
||||
ImGui.NewLine();
|
||||
using var child2 = ImRaii.Child("image");
|
||||
if (child2)
|
||||
TextureDrawer.Draw(tex, imageSize);
|
||||
ImGui.NewLine();
|
||||
using var child2 = ImRaii.Child("image");
|
||||
if (child2)
|
||||
TextureDrawer.Draw(tex, imageSize);
|
||||
}
|
||||
|
||||
if (_dragDropManager.CreateImGuiTarget("TextureDragDrop", out var files, out _) && GetFirstTexture(files, out var file))
|
||||
tex.Load(_textures, file);
|
||||
}
|
||||
|
||||
private void SaveAsCombo()
|
||||
|
|
@ -229,6 +237,15 @@ public partial class ModEditWindow
|
|||
|
||||
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 imageSize = new Vector2(childWidth.X - ImGui.GetStyle().FramePadding.X * 2);
|
||||
DrawInputChild("Input Texture", _left, childWidth, imageSize);
|
||||
|
|
@ -259,4 +276,17 @@ public partial class ModEditWindow
|
|||
|
||||
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",
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System.Numerics;
|
|||
using System.Text;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Components;
|
||||
using Dalamud.Interface.DragDrop;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Plugin.Services;
|
||||
using ImGuiNET;
|
||||
|
|
@ -40,6 +41,7 @@ public partial class ModEditWindow : Window, IDisposable
|
|||
private readonly StainService _stainService;
|
||||
private readonly ModMergeTab _modMergeTab;
|
||||
private readonly CommunicatorService _communicator;
|
||||
private readonly IDragDropManager _dragDropManager;
|
||||
|
||||
private Mod? _mod;
|
||||
private Vector2 _iconSize = Vector2.Zero;
|
||||
|
|
@ -303,7 +305,7 @@ public partial class ModEditWindow : Window, IDisposable
|
|||
new Vector2(300 * UiHelpers.Scale, ImGui.GetFrameHeight()),
|
||||
$"{_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.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,
|
||||
Configuration config, ModEditor editor, ResourceTreeFactory resourceTreeFactory, MetaFileManager metaFileManager,
|
||||
StainService stainService, ActiveCollections activeCollections, DalamudServices dalamud, ModMergeTab modMergeTab,
|
||||
CommunicatorService communicator, TextureManager textures)
|
||||
CommunicatorService communicator, TextureManager textures, IDragDropManager dragDropManager)
|
||||
: base(WindowBaseLabel)
|
||||
{
|
||||
_performance = performance;
|
||||
_itemSwapTab = itemSwapTab;
|
||||
_config = config;
|
||||
_editor = editor;
|
||||
_metaFileManager = metaFileManager;
|
||||
_stainService = stainService;
|
||||
_activeCollections = activeCollections;
|
||||
_dalamud = dalamud;
|
||||
_modMergeTab = modMergeTab;
|
||||
_communicator = communicator;
|
||||
_textures = textures;
|
||||
_fileDialog = fileDialog;
|
||||
_performance = performance;
|
||||
_itemSwapTab = itemSwapTab;
|
||||
_config = config;
|
||||
_editor = editor;
|
||||
_metaFileManager = metaFileManager;
|
||||
_stainService = stainService;
|
||||
_activeCollections = activeCollections;
|
||||
_dalamud = dalamud;
|
||||
_modMergeTab = modMergeTab;
|
||||
_communicator = communicator;
|
||||
_dragDropManager = dragDropManager;
|
||||
_textures = textures;
|
||||
_fileDialog = fileDialog;
|
||||
_materialTab = new FileEditor<MtrlTab>(this, gameData, config, _fileDialog, "Materials", ".mtrl",
|
||||
() => _editor.Files.Mtrl, DrawMaterialPanel, () => _mod?.ModPath.FullName ?? string.Empty,
|
||||
bytes => new MtrlTab(this, new MtrlFile(bytes)));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue