Penumbra attachment made semi-optional and restartable.

This commit is contained in:
Ottermandias 2021-08-22 00:13:53 +02:00
parent dbccddcc39
commit cd1a39ffe4
4 changed files with 78 additions and 45 deletions

View file

@ -13,6 +13,7 @@ namespace Glamourer
public bool FoldersFirst { get; set; } = false; public bool FoldersFirst { get; set; } = false;
public bool ColorDesigns { get; set; } = true; public bool ColorDesigns { get; set; } = true;
public bool ShowLocks { get; set; } = true; public bool ShowLocks { get; set; } = true;
public bool AttachToPenumbra { get; set; } = true;
public uint CustomizationColor { get; set; } = DefaultCustomizationColor; public uint CustomizationColor { get; set; } = DefaultCustomizationColor;
public uint StateColor { get; set; } = DefaultStateColor; public uint StateColor { get; set; } = DefaultStateColor;

View file

@ -43,6 +43,27 @@ namespace Glamourer.Gui
ImGui.SetTooltip(tooltip); ImGui.SetTooltip(tooltip);
} }
private void DrawRestorePenumbraButton()
{
const string buttonLabel = "Re-Register Penumbra";
if (!Glamourer.Config.AttachToPenumbra)
{
using var raii = new ImGuiRaii().PushStyle(ImGuiStyleVar.Alpha, 0.5f);
ImGui.Button(buttonLabel);
return;
}
if (ImGui.Button(buttonLabel) && _plugin.GetPenumbra())
{
_plugin.UnregisterFunctions();
_plugin.RegisterFunctions();
}
if (ImGui.IsItemHovered())
ImGui.SetTooltip(
"If Penumbra did not register the functions for some reason, pressing this button might help restore functionality.");
}
private void DrawConfigTab() private void DrawConfigTab()
{ {
using var raii = new ImGuiRaii(); using var raii = new ImGuiRaii();
@ -59,6 +80,24 @@ namespace Glamourer.Gui
v => cfg.ColorDesigns = v); v => cfg.ColorDesigns = v);
DrawConfigCheckMark("Show Locks", "Write-protected Designs show a lock besides their name in the selector.", cfg.ShowLocks, DrawConfigCheckMark("Show Locks", "Write-protected Designs show a lock besides their name in the selector.", cfg.ShowLocks,
v => cfg.ShowLocks = v); v => cfg.ShowLocks = v);
DrawConfigCheckMark("Attach to Penumbra",
"Allows you to right-click items in the Changed Items tab of a mod in Penumbra to apply them to your player character.",
cfg.AttachToPenumbra,
v =>
{
cfg.AttachToPenumbra = v;
if (v)
{
if (_plugin.GetPenumbra())
_plugin.RegisterFunctions();
}
else
{
_plugin.UnregisterFunctions();
}
});
ImGui.SameLine();
DrawRestorePenumbraButton();
ImGui.Dummy(Vector2.UnitY * ImGui.GetTextLineHeightWithSpacing() / 2); ImGui.Dummy(Vector2.UnitY * ImGui.GetTextLineHeightWithSpacing() / 2);

View file

@ -387,13 +387,15 @@ namespace Glamourer.Gui
case CharaMakeParams.MenuType.ListSelector: return DrawListSelector(set.OptionName[(int) id], "", ref customization, id, set); case CharaMakeParams.MenuType.ListSelector: return DrawListSelector(set.OptionName[(int) id], "", ref customization, id, set);
case CharaMakeParams.MenuType.IconSelector: return DrawIconSelector(set.OptionName[(int) id], "", ref customization, id, set); case CharaMakeParams.MenuType.IconSelector: return DrawIconSelector(set.OptionName[(int) id], "", ref customization, id, set);
case CharaMakeParams.MenuType.MultiIconSelector: return DrawMultiSelector(ref customization, set); case CharaMakeParams.MenuType.MultiIconSelector: return DrawMultiSelector(ref customization, set);
case CharaMakeParams.MenuType.Percentage: return DrawPercentageSelector(set.OptionName[(int)id], "", ref customization, id, set); case CharaMakeParams.MenuType.Percentage:
return DrawPercentageSelector(set.OptionName[(int) id], "", ref customization, id, set);
} }
return false; return false;
} }
private static readonly CustomizationId[] AllCustomizations = (CustomizationId[]) Enum.GetValues(typeof(CustomizationId)); private static readonly CustomizationId[] AllCustomizations = (CustomizationId[]) Enum.GetValues(typeof(CustomizationId));
private bool DrawCustomization(ref ActorCustomization custom) private bool DrawCustomization(ref ActorCustomization custom)
{ {
if (!ImGui.CollapsingHeader("Character Customization")) if (!ImGui.CollapsingHeader("Character Customization"))

View file

@ -75,7 +75,7 @@ namespace Glamourer
} }
} }
private void RegisterFunctions() public void RegisterFunctions()
{ {
if (Penumbra == null || !Penumbra.Valid) if (Penumbra == null || !Penumbra.Valid)
return; return;
@ -84,7 +84,7 @@ namespace Glamourer
Penumbra!.ChangedItemClicked += PenumbraRightClick; Penumbra!.ChangedItemClicked += PenumbraRightClick;
} }
private void UnregisterFunctions() public void UnregisterFunctions()
{ {
if (Penumbra == null || !Penumbra.Valid) if (Penumbra == null || !Penumbra.Valid)
return; return;
@ -111,7 +111,7 @@ namespace Glamourer
_plugins = pluginsList ?? throw new Exception("Could not obtain Dalamud."); _plugins = pluginsList ?? throw new Exception("Could not obtain Dalamud.");
} }
private bool GetPenumbra() public bool GetPenumbra()
{ {
if (Penumbra?.Valid ?? false) if (Penumbra?.Valid ?? false)
return true; return true;
@ -123,14 +123,9 @@ namespace Glamourer
var penumbra = (IPenumbraApiBase?) plugin?.GetType().GetProperty("Api", BindingFlags.Instance | BindingFlags.Public) var penumbra = (IPenumbraApiBase?) plugin?.GetType().GetProperty("Api", BindingFlags.Instance | BindingFlags.Public)
?.GetValue(plugin); ?.GetValue(plugin);
if (penumbra != null && penumbra.Valid && penumbra.ApiVersion >= RequiredPenumbraShareVersion) if (penumbra != null && penumbra.Valid && penumbra.ApiVersion >= RequiredPenumbraShareVersion)
{
Penumbra = (IPenumbraApi) penumbra!; Penumbra = (IPenumbraApi) penumbra!;
RegisterFunctions();
}
else else
{
Penumbra = null; Penumbra = null;
}
return Penumbra != null; return Penumbra != null;
} }
@ -144,7 +139,8 @@ namespace Glamourer
SetDalamud(PluginInterface); SetDalamud(PluginInterface);
SetPlugins(PluginInterface); SetPlugins(PluginInterface);
Designs = new DesignManager(PluginInterface); Designs = new DesignManager(PluginInterface);
GetPenumbra(); if (GetPenumbra() && Config.AttachToPenumbra)
RegisterFunctions();
PlayerWatcher = PlayerWatchFactory.Create(PluginInterface); PlayerWatcher = PlayerWatchFactory.Create(PluginInterface);
PluginInterface.CommandManager.AddHandler("/glamourer", new CommandInfo(OnGlamourer) PluginInterface.CommandManager.AddHandler("/glamourer", new CommandInfo(OnGlamourer)
@ -181,7 +177,6 @@ namespace Glamourer
}; };
} }
public void CopyToClipboard(Actor actor) public void CopyToClipboard(Actor actor)
{ {
var save = new CharacterSave(); var save = new CharacterSave();
@ -193,7 +188,6 @@ namespace Glamourer
{ {
CharacterSave? save = null; CharacterSave? save = null;
if (target.ToLowerInvariant() == "clipboard") if (target.ToLowerInvariant() == "clipboard")
{
try try
{ {
save = CharacterSave.FromString(Clipboard.GetText()); save = CharacterSave.FromString(Clipboard.GetText());
@ -202,15 +196,10 @@ namespace Glamourer
{ {
PluginInterface.Framework.Gui.Chat.PrintError("Clipboard does not contain a valid customization string."); PluginInterface.Framework.Gui.Chat.PrintError("Clipboard does not contain a valid customization string.");
} }
}
else if (!Designs.FileSystem.Find(target, out var child) || child is not Design d) else if (!Designs.FileSystem.Find(target, out var child) || child is not Design d)
{
PluginInterface.Framework.Gui.Chat.PrintError("The given path to a saved design does not exist or does not point to a design."); PluginInterface.Framework.Gui.Chat.PrintError("The given path to a saved design does not exist or does not point to a design.");
}
else else
{
save = d.Data; save = d.Data;
}
save?.Apply(actor); save?.Apply(actor);
UpdateActors(actor); UpdateActors(actor);
@ -280,6 +269,7 @@ namespace Glamourer
PluginInterface.Framework.Gui.Chat.Print("Applying requires a name for the save to be applied or 'clipboard'."); PluginInterface.Framework.Gui.Chat.Print("Applying requires a name for the save to be applied or 'clipboard'.");
return; return;
} }
ApplyCommand(actor, split[2]); ApplyCommand(actor, split[2]);
return; return;
@ -291,6 +281,7 @@ namespace Glamourer
PluginInterface.Framework.Gui.Chat.Print("Saving requires a name for the save."); PluginInterface.Framework.Gui.Chat.Print("Saving requires a name for the save.");
return; return;
} }
SaveCommand(actor, split[2]); SaveCommand(actor, split[2]);
return; return;
} }