mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Add DragDropManager.
This commit is contained in:
parent
344defca8e
commit
808dabf600
3 changed files with 34 additions and 8 deletions
|
|
@ -12,6 +12,7 @@ using Dalamud.IoC;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Dalamud.Interface.DragDrop;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Local
|
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Local
|
||||||
|
|
@ -76,6 +77,7 @@ public class DalamudServices
|
||||||
services.AddSingleton(SigScanner);
|
services.AddSingleton(SigScanner);
|
||||||
services.AddSingleton(this);
|
services.AddSingleton(this);
|
||||||
services.AddSingleton(UiBuilder);
|
services.AddSingleton(UiBuilder);
|
||||||
|
services.AddSingleton(DragDropManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove static
|
// TODO remove static
|
||||||
|
|
@ -93,6 +95,7 @@ public class DalamudServices
|
||||||
[PluginService][RequiredVersion("1.0")] public GameGui GameGui { get; private set; } = null!;
|
[PluginService][RequiredVersion("1.0")] public GameGui GameGui { get; private set; } = null!;
|
||||||
[PluginService][RequiredVersion("1.0")] public KeyState KeyState { get; private set; } = null!;
|
[PluginService][RequiredVersion("1.0")] public KeyState KeyState { get; private set; } = null!;
|
||||||
[PluginService][RequiredVersion("1.0")] public SigScanner SigScanner { get; private set; } = null!;
|
[PluginService][RequiredVersion("1.0")] public SigScanner SigScanner { get; private set; } = null!;
|
||||||
|
[PluginService][RequiredVersion("1.0")] public IDragDropManager DragDropManager { get; private set; } = null!;
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
public UiBuilder UiBuilder
|
public UiBuilder UiBuilder
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Dalamud.Game.ClientState.Keys;
|
using Dalamud.Game.ClientState.Keys;
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
|
using Dalamud.Interface.DragDrop;
|
||||||
using Dalamud.Interface.Internal.Notifications;
|
using Dalamud.Interface.Internal.Notifications;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using OtterGui;
|
using OtterGui;
|
||||||
|
|
@ -33,12 +35,13 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
|
||||||
private readonly CollectionManager _collectionManager;
|
private readonly CollectionManager _collectionManager;
|
||||||
private readonly TutorialService _tutorial;
|
private readonly TutorialService _tutorial;
|
||||||
private readonly ModImportManager _modImportManager;
|
private readonly ModImportManager _modImportManager;
|
||||||
|
private readonly IDragDropManager _dragDrop;
|
||||||
public ModSettings SelectedSettings { get; private set; } = ModSettings.Empty;
|
public ModSettings SelectedSettings { get; private set; } = ModSettings.Empty;
|
||||||
public ModCollection SelectedSettingCollection { get; private set; } = ModCollection.Empty;
|
public ModCollection SelectedSettingCollection { get; private set; } = ModCollection.Empty;
|
||||||
|
|
||||||
public ModFileSystemSelector(KeyState keyState, CommunicatorService communicator, ModFileSystem fileSystem, ModManager modManager,
|
public ModFileSystemSelector(KeyState keyState, CommunicatorService communicator, ModFileSystem fileSystem, ModManager modManager,
|
||||||
CollectionManager collectionManager, Configuration config, TutorialService tutorial, FileDialogService fileDialog, ChatService chat,
|
CollectionManager collectionManager, Configuration config, TutorialService tutorial, FileDialogService fileDialog, ChatService chat,
|
||||||
ModImportManager modImportManager)
|
ModImportManager modImportManager, IDragDropManager dragDrop)
|
||||||
: base(fileSystem, keyState, HandleException)
|
: base(fileSystem, keyState, HandleException)
|
||||||
{
|
{
|
||||||
_communicator = communicator;
|
_communicator = communicator;
|
||||||
|
|
@ -49,6 +52,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
|
||||||
_fileDialog = fileDialog;
|
_fileDialog = fileDialog;
|
||||||
_chat = chat;
|
_chat = chat;
|
||||||
_modImportManager = modImportManager;
|
_modImportManager = modImportManager;
|
||||||
|
_dragDrop = dragDrop;
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
SubscribeRightClickFolder(EnableDescendants, 10);
|
SubscribeRightClickFolder(EnableDescendants, 10);
|
||||||
|
|
@ -82,6 +86,28 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
|
||||||
OnCollectionChange(CollectionType.Current, null, _collectionManager.Active.Current, "");
|
OnCollectionChange(CollectionType.Current, null, _collectionManager.Active.Current, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly string[] ValidModExtensions = new[]
|
||||||
|
{
|
||||||
|
".ttmp",
|
||||||
|
".ttmp2",
|
||||||
|
".pmp",
|
||||||
|
".zip",
|
||||||
|
".rar",
|
||||||
|
".7z",
|
||||||
|
};
|
||||||
|
|
||||||
|
public new void Draw(float width)
|
||||||
|
{
|
||||||
|
_dragDrop.CreateImGuiSource("ModDragDrop", m => m.Extensions.Any(e => ValidModExtensions.Contains(e.ToLowerInvariant())), m =>
|
||||||
|
{
|
||||||
|
ImGui.TextUnformatted($"Dragging mods for import:\n\t{string.Join("\n\t", m.Files.Select(Path.GetFileName))}");
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
base.Draw(width);
|
||||||
|
if (_dragDrop.CreateImGuiTarget("ModDragDrop", out var files, out _))
|
||||||
|
_modImportManager.AddUnpack(files.Where(f => ValidModExtensions.Contains(Path.GetExtension(f.ToLowerInvariant()))));
|
||||||
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
|
|
@ -655,7 +681,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
|
||||||
private bool DrawFilterCombo(ref bool everything)
|
private bool DrawFilterCombo(ref bool everything)
|
||||||
{
|
{
|
||||||
using var combo = ImRaii.Combo("##filterCombo", string.Empty,
|
using var combo = ImRaii.Combo("##filterCombo", string.Empty,
|
||||||
ImGuiComboFlags.NoPreview | ImGuiComboFlags.PopupAlignLeft | ImGuiComboFlags.HeightLargest);
|
ImGuiComboFlags.NoPreview | ImGuiComboFlags.PopupAlignLeft | ImGuiComboFlags.HeightLargest);
|
||||||
var ret = ImGui.IsItemClicked(ImGuiMouseButton.Right);
|
var ret = ImGui.IsItemClicked(ImGuiMouseButton.Right);
|
||||||
if (!combo)
|
if (!combo)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -695,12 +721,12 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
|
||||||
|
|
||||||
ImGui.SetCursorPos(comboPos);
|
ImGui.SetCursorPos(comboPos);
|
||||||
// Draw combo button
|
// Draw combo button
|
||||||
using var color = ImRaii.PushColor(ImGuiCol.Button, Colors.FilterActive, !everything);
|
using var color = ImRaii.PushColor(ImGuiCol.Button, Colors.FilterActive, !everything);
|
||||||
var rightClick = DrawFilterCombo(ref everything);
|
var rightClick = DrawFilterCombo(ref everything);
|
||||||
_tutorial.OpenTutorial(BasicTutorialSteps.ModFilters);
|
_tutorial.OpenTutorial(BasicTutorialSteps.ModFilters);
|
||||||
if (rightClick)
|
if (rightClick)
|
||||||
{
|
{
|
||||||
_stateFilter = ModFilterExtensions.UnfilteredStateMods;
|
_stateFilter = ModFilterExtensions.UnfilteredStateMods;
|
||||||
SetFilterDirty();
|
SetFilterDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using OtterGui;
|
using OtterGui;
|
||||||
using OtterGui.Raii;
|
using OtterGui.Raii;
|
||||||
using Penumbra.Collections;
|
|
||||||
using Penumbra.UI.Classes;
|
using Penumbra.UI.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -13,11 +12,9 @@ using Penumbra.Api.Enums;
|
||||||
using Penumbra.Interop.Services;
|
using Penumbra.Interop.Services;
|
||||||
using Penumbra.Mods;
|
using Penumbra.Mods;
|
||||||
using Penumbra.Mods.Manager;
|
using Penumbra.Mods.Manager;
|
||||||
using Penumbra.Services;
|
|
||||||
using Penumbra.UI.ModsTab;
|
using Penumbra.UI.ModsTab;
|
||||||
using ModFileSystemSelector = Penumbra.UI.ModsTab.ModFileSystemSelector;
|
using ModFileSystemSelector = Penumbra.UI.ModsTab.ModFileSystemSelector;
|
||||||
using Penumbra.Collections.Manager;
|
using Penumbra.Collections.Manager;
|
||||||
using Penumbra.UI.CollectionTab;
|
|
||||||
|
|
||||||
namespace Penumbra.UI.Tabs;
|
namespace Penumbra.UI.Tabs;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue