mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +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 System.Linq;
|
||||
using System.Reflection;
|
||||
using Dalamud.Interface.DragDrop;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Local
|
||||
|
|
@ -76,6 +77,7 @@ public class DalamudServices
|
|||
services.AddSingleton(SigScanner);
|
||||
services.AddSingleton(this);
|
||||
services.AddSingleton(UiBuilder);
|
||||
services.AddSingleton(DragDropManager);
|
||||
}
|
||||
|
||||
// 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 KeyState KeyState { 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
|
||||
|
||||
public UiBuilder UiBuilder
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using Dalamud.Game.ClientState.Keys;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.DragDrop;
|
||||
using Dalamud.Interface.Internal.Notifications;
|
||||
using ImGuiNET;
|
||||
using OtterGui;
|
||||
|
|
@ -33,12 +35,13 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
|
|||
private readonly CollectionManager _collectionManager;
|
||||
private readonly TutorialService _tutorial;
|
||||
private readonly ModImportManager _modImportManager;
|
||||
private readonly IDragDropManager _dragDrop;
|
||||
public ModSettings SelectedSettings { get; private set; } = ModSettings.Empty;
|
||||
public ModCollection SelectedSettingCollection { get; private set; } = ModCollection.Empty;
|
||||
|
||||
public ModFileSystemSelector(KeyState keyState, CommunicatorService communicator, ModFileSystem fileSystem, ModManager modManager,
|
||||
CollectionManager collectionManager, Configuration config, TutorialService tutorial, FileDialogService fileDialog, ChatService chat,
|
||||
ModImportManager modImportManager)
|
||||
ModImportManager modImportManager, IDragDropManager dragDrop)
|
||||
: base(fileSystem, keyState, HandleException)
|
||||
{
|
||||
_communicator = communicator;
|
||||
|
|
@ -49,6 +52,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
|
|||
_fileDialog = fileDialog;
|
||||
_chat = chat;
|
||||
_modImportManager = modImportManager;
|
||||
_dragDrop = dragDrop;
|
||||
|
||||
// @formatter:off
|
||||
SubscribeRightClickFolder(EnableDescendants, 10);
|
||||
|
|
@ -82,6 +86,28 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
|
|||
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()
|
||||
{
|
||||
base.Dispose();
|
||||
|
|
@ -655,7 +681,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
|
|||
private bool DrawFilterCombo(ref bool everything)
|
||||
{
|
||||
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);
|
||||
if (!combo)
|
||||
return ret;
|
||||
|
|
@ -695,12 +721,12 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
|
|||
|
||||
ImGui.SetCursorPos(comboPos);
|
||||
// Draw combo button
|
||||
using var color = ImRaii.PushColor(ImGuiCol.Button, Colors.FilterActive, !everything);
|
||||
var rightClick = DrawFilterCombo(ref everything);
|
||||
using var color = ImRaii.PushColor(ImGuiCol.Button, Colors.FilterActive, !everything);
|
||||
var rightClick = DrawFilterCombo(ref everything);
|
||||
_tutorial.OpenTutorial(BasicTutorialSteps.ModFilters);
|
||||
if (rightClick)
|
||||
{
|
||||
_stateFilter = ModFilterExtensions.UnfilteredStateMods;
|
||||
_stateFilter = ModFilterExtensions.UnfilteredStateMods;
|
||||
SetFilterDirty();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using ImGuiNET;
|
||||
using OtterGui;
|
||||
using OtterGui.Raii;
|
||||
using Penumbra.Collections;
|
||||
using Penumbra.UI.Classes;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
|
@ -13,11 +12,9 @@ using Penumbra.Api.Enums;
|
|||
using Penumbra.Interop.Services;
|
||||
using Penumbra.Mods;
|
||||
using Penumbra.Mods.Manager;
|
||||
using Penumbra.Services;
|
||||
using Penumbra.UI.ModsTab;
|
||||
using ModFileSystemSelector = Penumbra.UI.ModsTab.ModFileSystemSelector;
|
||||
using Penumbra.Collections.Manager;
|
||||
using Penumbra.UI.CollectionTab;
|
||||
|
||||
namespace Penumbra.UI.Tabs;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue