Skip to content

Commit

Permalink
Add option to apply designs to player with doubl click.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Mar 1, 2024
1 parent 64c1f75 commit bfe50f4
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 8 deletions.
1 change: 1 addition & 0 deletions Glamourer/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Configuration : IPluginConfiguration, ISavable
public bool ShowColorConfig { get; set; } = true;
public bool ChangeEntireItem { get; set; } = false;
public bool AlwaysApplyAssociatedMods { get; set; } = false;
public bool AllowDoubleClickToApply { get; set; } = false;
public ModifiableHotkey ToggleQuickDesignBar { get; set; } = new(VirtualKey.NO_KEY);
public DoubleModifier DeleteDesignModifier { get; set; } = new(ModifierHotkey.Control, ModifierHotkey.Shift);
public ChangeLogDisplayType ChangeLogDisplayType { get; set; } = ChangeLogDisplayType.New;
Expand Down
8 changes: 7 additions & 1 deletion Glamourer/Gui/Tabs/DesignTab/DesignFileSystemSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Dalamud.Plugin.Services;
using Glamourer.Designs;
using Glamourer.Events;
using Glamourer.Services;
using ImGuiNET;
using OtterGui;
using OtterGui.Classes;
Expand All @@ -21,6 +22,7 @@ public sealed class DesignFileSystemSelector : FileSystemSelector<Design, Design
private readonly DesignConverter _converter;
private readonly TabSelected _selectionEvent;
private readonly DesignColors _designColors;
private readonly DesignApplier _designApplier;

private string? _clipboardText;
private Design? _cloneDesign;
Expand All @@ -43,7 +45,8 @@ public record struct DesignState(uint Color)
{ }

public DesignFileSystemSelector(DesignManager designManager, DesignFileSystem fileSystem, IKeyState keyState, DesignChanged @event,
Configuration config, DesignConverter converter, TabSelected selectionEvent, Logger log, DesignColors designColors)
Configuration config, DesignConverter converter, TabSelected selectionEvent, Logger log, DesignColors designColors,
DesignApplier designApplier)
: base(fileSystem, keyState, log, allowMultipleSelection: true)
{
_designManager = designManager;
Expand All @@ -52,6 +55,7 @@ public DesignFileSystemSelector(DesignManager designManager, DesignFileSystem fi
_converter = converter;
_selectionEvent = selectionEvent;
_designColors = designColors;
_designApplier = designApplier;
_event.Subscribe(OnDesignChange, DesignChanged.Priority.DesignFileSystemSelector);
_selectionEvent.Subscribe(OnTabSelected, TabSelected.Priority.DesignSelector);
_designColors.ColorChanged += SetFilterDirty;
Expand Down Expand Up @@ -92,6 +96,8 @@ protected override void DrawLeafName(FileSystem<Design>.Leaf leaf, in DesignStat
var name = IncognitoMode ? leaf.Value.Incognito : leaf.Value.Name.Text;
using var color = ImRaii.PushColor(ImGuiCol.Text, state.Color);
using var _ = ImRaii.TreeNode(name, flag);
if (_config.AllowDoubleClickToApply && ImGui.IsItemHovered() && ImGui.IsMouseDoubleClicked(ImGuiMouseButton.Left))
_designApplier.ApplyToPlayer(leaf.Value);
}

public override void Dispose()
Expand Down
15 changes: 8 additions & 7 deletions Glamourer/Gui/Tabs/SettingsTab/SettingsTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ private void DrawInterfaceSettings()
ImGui.Separator();
ImGui.Dummy(Vector2.Zero);

Checkbox("Allow Double-Clicking Designs to Apply",
"Tries to apply a design to the current player character When double-clicking it in the design selector.",
config.AllowDoubleClickToApply, v => config.AllowDoubleClickToApply = v);
Checkbox("Show all Application Rule Checkboxes for Automation",
"Show multiple separate application rule checkboxes for automated designs, instead of a single box for enabling or disabling.",
config.ShowAllAutomatedApplicationRules, v => config.ShowAllAutomatedApplicationRules = v);
Expand All @@ -183,9 +186,6 @@ private void DrawInterfaceSettings()
config.ShowUnlockedItemWarnings, v => config.ShowUnlockedItemWarnings = v);
if (config.UseAdvancedParameters)
{
//Checkbox("Show Revert Advanced Customizations Button in Quick Design Bar",
// "Show a button to revert only advanced customizations on your character or a target in the quick design bar.",
// config.ShowRevertAdvancedParametersButton, v => config.ShowRevertAdvancedParametersButton = v);
Checkbox("Show Color Display Config", "Show the Color Display configuration options in the Advanced Customization panels.",
config.ShowColorConfig, v => config.ShowColorConfig = v);
Checkbox("Show Palette+ Import Button",
Expand All @@ -207,13 +207,14 @@ private void DrawInterfaceSettings()

private void DrawQuickDesignBoxes()
{
var showAuto = config.EnableAutoDesigns;
var showAdvanced = config.UseAdvancedParameters || config.UseAdvancedDyes;
var numColumns = 6 - (showAuto ? 0 : 1) - (showAdvanced ? 0 : 1);
var showAuto = config.EnableAutoDesigns;
var showAdvanced = config.UseAdvancedParameters || config.UseAdvancedDyes;
var numColumns = 6 - (showAuto ? 0 : 1) - (showAdvanced ? 0 : 1);
ImGui.NewLine();
ImGui.TextUnformatted("Show the Following Buttons in the Quick Design Bar:");
ImGui.Dummy(Vector2.Zero);
using var table = ImRaii.Table("##tableQdb", numColumns, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.Borders | ImGuiTableFlags.NoHostExtendX);
using var table = ImRaii.Table("##tableQdb", numColumns,
ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.Borders | ImGuiTableFlags.NoHostExtendX);
if (!table)
return;

Expand Down
61 changes: 61 additions & 0 deletions Glamourer/Services/DesignApplier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Glamourer.Designs;
using Glamourer.Interop;
using Glamourer.Interop.Structs;
using Glamourer.State;
using OtterGui.Services;
using Penumbra.GameData.Actors;

namespace Glamourer.Services;

public sealed class DesignApplier(StateManager stateManager, ObjectManager objects) : IService
{
public void ApplyToPlayer(DesignBase design)
{
var (player, data) = objects.PlayerData;
if (!data.Valid)
return;

if (!stateManager.GetOrCreate(player, data.Objects[0], out var state))
return;

stateManager.ApplyDesign(state, design, ApplySettings.ManualWithLinks);
}

public void ApplyToTarget(DesignBase design)
{
var (player, data) = objects.TargetData;
if (!data.Valid)
return;

if (!stateManager.GetOrCreate(player, data.Objects[0], out var state))
return;

stateManager.ApplyDesign(state, design, ApplySettings.ManualWithLinks);
}

public void Apply(ActorIdentifier actor, DesignBase design)
{
objects.Update();
Apply(actor, objects.TryGetValue(actor, out var d) ? d : ActorData.Invalid, design, ApplySettings.ManualWithLinks);
}

public void Apply(ActorIdentifier actor, DesignBase design, ApplySettings settings)
{
objects.Update();
Apply(actor, objects.TryGetValue(actor, out var d) ? d : ActorData.Invalid, design, settings);
}

public void Apply(ActorIdentifier actor, ActorData data, DesignBase design)
=> Apply(actor, data, design, ApplySettings.ManualWithLinks);

public void Apply(ActorIdentifier actor, ActorData data, DesignBase design, ApplySettings settings)
{
if (!actor.IsValid || !data.Valid)
return;

if (!stateManager.GetOrCreate(actor, data.Objects[0], out var state))
return;

stateManager.ApplyDesign(state, design, ApplySettings.ManualWithLinks);
}
}
3 changes: 3 additions & 0 deletions Glamourer/State/StateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public unsafe bool GetOrCreate(ActorIdentifier identifier, Actor actor, [NotNull
if (TryGetValue(identifier, out state))
return true;

if (!actor.Valid)
return false;

try
{
// Initial Creation, use the actors data for the base data,
Expand Down

0 comments on commit bfe50f4

Please sign in to comment.