mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +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.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;
|
||||||
|
|
|
||||||
|
|
@ -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,7 +39,8 @@ 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)
|
if (!child)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -49,7 +52,8 @@ public partial class ModEditWindow
|
||||||
"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)
|
||||||
|
&& newPath != tex.Path)
|
||||||
tex.Load(_textures, newPath);
|
tex.Load(_textures, newPath);
|
||||||
|
|
||||||
if (tex == _left)
|
if (tex == _left)
|
||||||
|
|
@ -63,6 +67,10 @@ public partial class ModEditWindow
|
||||||
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()
|
||||||
{
|
{
|
||||||
var (text, desc) = SaveAsStrings[_currentSaveAs];
|
var (text, desc) = SaveAsStrings[_currentSaveAs];
|
||||||
|
|
@ -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",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -521,7 +523,7 @@ 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;
|
||||||
|
|
@ -534,6 +536,7 @@ public partial class ModEditWindow : Window, IDisposable
|
||||||
_dalamud = dalamud;
|
_dalamud = dalamud;
|
||||||
_modMergeTab = modMergeTab;
|
_modMergeTab = modMergeTab;
|
||||||
_communicator = communicator;
|
_communicator = communicator;
|
||||||
|
_dragDropManager = dragDropManager;
|
||||||
_textures = textures;
|
_textures = textures;
|
||||||
_fileDialog = fileDialog;
|
_fileDialog = fileDialog;
|
||||||
_materialTab = new FileEditor<MtrlTab>(this, gameData, config, _fileDialog, "Materials", ".mtrl",
|
_materialTab = new FileEditor<MtrlTab>(this, gameData, config, _fileDialog, "Materials", ".mtrl",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue