Add an option to automatically select the collection assigned to the current character on login.

This commit is contained in:
Ottermandias 2024-12-16 17:52:57 +01:00
parent 510b9a5f1f
commit cc97ea0ce9
5 changed files with 92 additions and 6 deletions

View file

@ -0,0 +1,75 @@
using Dalamud.Plugin.Services;
using OtterGui.Services;
using Penumbra.Collections.Manager;
using Penumbra.GameData.Interop;
using Penumbra.Interop.PathResolving;
namespace Penumbra.Collections;
public sealed class CollectionAutoSelector : IService, IDisposable
{
private readonly Configuration _config;
private readonly ActiveCollections _collections;
private readonly IClientState _clientState;
private readonly CollectionResolver _resolver;
private readonly ObjectManager _objects;
public CollectionAutoSelector(Configuration config, ActiveCollections collections, IClientState clientState, CollectionResolver resolver,
ObjectManager objects)
{
_config = config;
_collections = collections;
_clientState = clientState;
_resolver = resolver;
_objects = objects;
if (_config.AutoSelectCollection)
Attach();
}
public bool Disposed { get; private set; }
public void SetAutomaticSelection(bool value)
{
_config.AutoSelectCollection = value;
if (value)
Attach();
else
Detach();
}
private void Attach()
{
if (Disposed)
return;
_clientState.Login += OnLogin;
Select();
}
private void OnLogin()
=> Select();
private void Detach()
=> _clientState.Login -= OnLogin;
private void Select()
{
if (!_objects[0].IsCharacter)
return;
var collection = _resolver.PlayerCollection();
Penumbra.Log.Debug($"Setting current collection to {collection.Identifier} through automatic collection selection.");
_collections.SetCollection(collection, CollectionType.Current);
}
public void Dispose()
{
if (Disposed)
return;
Disposed = true;
Detach();
}
}

View file

@ -56,6 +56,8 @@ public class Configuration : IPluginConfiguration, ISavable, IService
public bool HideUiWhenUiHidden { get; set; } = false; public bool HideUiWhenUiHidden { get; set; } = false;
public bool UseDalamudUiTextureRedirection { get; set; } = true; public bool UseDalamudUiTextureRedirection { get; set; } = true;
public bool AutoSelectCollection { get; set; } = false;
public bool ShowModsInLobby { get; set; } = true; public bool ShowModsInLobby { get; set; } = true;
public bool UseCharacterCollectionInMainWindow { get; set; } = true; public bool UseCharacterCollectionInMainWindow { get; set; } = true;
public bool UseCharacterCollectionsInCards { get; set; } = true; public bool UseCharacterCollectionsInCards { get; set; } = true;
@ -100,7 +102,7 @@ public class Configuration : IPluginConfiguration, ISavable, IService
public bool UseFileSystemCompression { get; set; } = true; public bool UseFileSystemCompression { get; set; } = true;
public bool EnableHttpApi { get; set; } = true; public bool EnableHttpApi { get; set; } = true;
public bool MigrateImportedModelsToV6 { get; set; } = true; public bool MigrateImportedModelsToV6 { get; set; } = true;
public bool MigrateImportedMaterialsToLegacy { get; set; } = true; public bool MigrateImportedMaterialsToLegacy { get; set; } = true;
public string DefaultModImportPath { get; set; } = string.Empty; public string DefaultModImportPath { get; set; } = string.Empty;

View file

@ -7,6 +7,7 @@ using Dalamud.Plugin.Services;
using Lumina.Excel.Sheets; using Lumina.Excel.Sheets;
using OtterGui.Log; using OtterGui.Log;
using OtterGui.Services; using OtterGui.Services;
using Penumbra.GameData.Data;
using Penumbra.Mods.Manager; using Penumbra.Mods.Manager;
using Penumbra.String.Classes; using Penumbra.String.Classes;
using Notification = OtterGui.Classes.Notification; using Notification = OtterGui.Classes.Notification;
@ -29,7 +30,7 @@ public class MessageService(Logger log, IUiBuilder builder, IChatGui chat, INoti
new TextPayload($"{(char)SeIconChar.LinkMarker}"), new TextPayload($"{(char)SeIconChar.LinkMarker}"),
new UIForegroundPayload(0), new UIForegroundPayload(0),
new UIGlowPayload(0), new UIGlowPayload(0),
new TextPayload(item.Name.ExtractText()), new TextPayload(item.Name.ExtractTextExtended()),
new RawPayload([0x02, 0x27, 0x07, 0xCF, 0x01, 0x01, 0x01, 0xFF, 0x01, 0x03]), new RawPayload([0x02, 0x27, 0x07, 0xCF, 0x01, 0x01, 0x01, 0xFF, 0x01, 0x03]),
new RawPayload([0x02, 0x13, 0x02, 0xEC, 0x03]), new RawPayload([0x02, 0x13, 0x02, 0xEC, 0x03]),
}; };

View file

@ -92,7 +92,6 @@ public class PenumbraChangelog : IUiService
private static void Add1_3_0_0(Changelog log) private static void Add1_3_0_0(Changelog log)
=> log.NextVersion("Version 1.3.0.0") => log.NextVersion("Version 1.3.0.0")
.RegisterHighlight("The textures tab in the advanced editing window can now import and export .tga files.") .RegisterHighlight("The textures tab in the advanced editing window can now import and export .tga files.")
.RegisterEntry("BC4 and BC6 textures can now also be imported.", 1) .RegisterEntry("BC4 and BC6 textures can now also be imported.", 1)
.RegisterHighlight("Added item swapping from and to the Glasses slot.") .RegisterHighlight("Added item swapping from and to the Glasses slot.")

View file

@ -12,6 +12,7 @@ using OtterGui.Raii;
using OtterGui.Services; using OtterGui.Services;
using OtterGui.Widgets; using OtterGui.Widgets;
using Penumbra.Api; using Penumbra.Api;
using Penumbra.Collections;
using Penumbra.Interop.Services; using Penumbra.Interop.Services;
using Penumbra.Mods.Manager; using Penumbra.Mods.Manager;
using Penumbra.Services; using Penumbra.Services;
@ -46,6 +47,7 @@ public class SettingsTab : ITab, IUiService
private readonly PredefinedTagManager _predefinedTagManager; private readonly PredefinedTagManager _predefinedTagManager;
private readonly CrashHandlerService _crashService; private readonly CrashHandlerService _crashService;
private readonly MigrationSectionDrawer _migrationDrawer; private readonly MigrationSectionDrawer _migrationDrawer;
private readonly CollectionAutoSelector _autoSelector;
private int _minimumX = int.MaxValue; private int _minimumX = int.MaxValue;
private int _minimumY = int.MaxValue; private int _minimumY = int.MaxValue;
@ -57,7 +59,7 @@ public class SettingsTab : ITab, IUiService
CharacterUtility characterUtility, ResidentResourceManager residentResources, ModExportManager modExportManager, HttpApi httpApi, CharacterUtility characterUtility, ResidentResourceManager residentResources, ModExportManager modExportManager, HttpApi httpApi,
DalamudSubstitutionProvider dalamudSubstitutionProvider, FileCompactor compactor, DalamudConfigService dalamudConfig, DalamudSubstitutionProvider dalamudSubstitutionProvider, FileCompactor compactor, DalamudConfigService dalamudConfig,
IDataManager gameData, PredefinedTagManager predefinedTagConfig, CrashHandlerService crashService, IDataManager gameData, PredefinedTagManager predefinedTagConfig, CrashHandlerService crashService,
MigrationSectionDrawer migrationDrawer) MigrationSectionDrawer migrationDrawer, CollectionAutoSelector autoSelector)
{ {
_pluginInterface = pluginInterface; _pluginInterface = pluginInterface;
_config = config; _config = config;
@ -80,6 +82,7 @@ public class SettingsTab : ITab, IUiService
_predefinedTagManager = predefinedTagConfig; _predefinedTagManager = predefinedTagConfig;
_crashService = crashService; _crashService = crashService;
_migrationDrawer = migrationDrawer; _migrationDrawer = migrationDrawer;
_autoSelector = autoSelector;
} }
public void DrawHeader() public void DrawHeader()
@ -421,6 +424,10 @@ public class SettingsTab : ITab, IUiService
/// <summary> Draw all settings that do not fit into other categories. </summary> /// <summary> Draw all settings that do not fit into other categories. </summary>
private void DrawMiscSettings() private void DrawMiscSettings()
{ {
Checkbox("Automatically Select Character-Associated Collection",
"On every login, automatically select the collection associated with the current character as the current collection for editing.",
_config.AutoSelectCollection, _autoSelector.SetAutomaticSelection);
Checkbox("Print Chat Command Success Messages to Chat", Checkbox("Print Chat Command Success Messages to Chat",
"Chat Commands usually print messages on failure but also on success to confirm your action. You can disable this here.", "Chat Commands usually print messages on failure but also on success to confirm your action. You can disable this here.",
_config.PrintSuccessfulCommandsToChat, v => _config.PrintSuccessfulCommandsToChat = v); _config.PrintSuccessfulCommandsToChat, v => _config.PrintSuccessfulCommandsToChat = v);
@ -816,13 +823,15 @@ public class SettingsTab : ITab, IUiService
if (ImGuiUtil.DrawDisabledButton("Compress Existing Files", Vector2.Zero, if (ImGuiUtil.DrawDisabledButton("Compress Existing Files", Vector2.Zero,
"Try to compress all files in your root directory. This will take a while.", "Try to compress all files in your root directory. This will take a while.",
_compactor.MassCompactRunning || !_modManager.Valid)) _compactor.MassCompactRunning || !_modManager.Valid))
_compactor.StartMassCompact(_modManager.BasePath.EnumerateFiles("*.*", SearchOption.AllDirectories), CompressionAlgorithm.Xpress8K, true); _compactor.StartMassCompact(_modManager.BasePath.EnumerateFiles("*.*", SearchOption.AllDirectories), CompressionAlgorithm.Xpress8K,
true);
ImGui.SameLine(); ImGui.SameLine();
if (ImGuiUtil.DrawDisabledButton("Decompress Existing Files", Vector2.Zero, if (ImGuiUtil.DrawDisabledButton("Decompress Existing Files", Vector2.Zero,
"Try to decompress all files in your root directory. This will take a while.", "Try to decompress all files in your root directory. This will take a while.",
_compactor.MassCompactRunning || !_modManager.Valid)) _compactor.MassCompactRunning || !_modManager.Valid))
_compactor.StartMassCompact(_modManager.BasePath.EnumerateFiles("*.*", SearchOption.AllDirectories), CompressionAlgorithm.None, true); _compactor.StartMassCompact(_modManager.BasePath.EnumerateFiles("*.*", SearchOption.AllDirectories), CompressionAlgorithm.None,
true);
if (_compactor.MassCompactRunning) if (_compactor.MassCompactRunning)
{ {