Skip to content

Commit

Permalink
Penumbra collection support
Browse files Browse the repository at this point in the history
  • Loading branch information
Limiana committed Mar 23, 2024
1 parent 44cb12e commit 2a5b3fe
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 12 deletions.
1 change: 1 addition & 0 deletions DynamicBridge/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Config : IEzConfig
public bool EnableGlamourer = true;
public bool EnableCustomize = true;
public bool EnableHonorific = true;
public bool EnablePenumbra = true;
public GlamourerNoRuleBehavior GlamNoRuleBehaviour = GlamourerNoRuleBehavior.RevertToNormal;
public bool RevertBeforeAutomationRestore = false;
public bool RevertGlamourerBeforeApply = false;
Expand Down
1 change: 1 addition & 0 deletions DynamicBridge/Configuration/Preset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Preset
public List<string> Honorific = [];
public List<string> Palette = [];
public List<string> Customize = [];
public List<string> Penumbra = [];
public bool IsStatic = false;
}
}
35 changes: 34 additions & 1 deletion DynamicBridge/DynamicBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using DynamicBridge.IPC.Customize;
using DynamicBridge.IPC.Glamourer;
using DynamicBridge.IPC.Honorific;
using DynamicBridge.IPC.Penumbra;
using ECommons.Automation;
using ECommons.ChatMethods;
using ECommons.Configuration;
Expand Down Expand Up @@ -32,7 +33,7 @@ public unsafe class DynamicBridge : IDalamudPlugin
public bool ForceUpdate = false;
public bool SoftForceUpdate = false;
public string MyOldDesign = null;
public Random Random = new();
public Random Random => Random.Shared;
public TaskManager TaskManager;
public const int DelayMS = 100;
public static ApplyRule StaticRule = new();
Expand All @@ -44,6 +45,7 @@ public unsafe class DynamicBridge : IDalamudPlugin

public GlamourerManager GlamourerManager;
public CustomizePlusManager CustomizePlusManager;
public PenumbraManager PenumbraManager;

public NeoTabs NeoTabs;

Expand Down Expand Up @@ -91,6 +93,7 @@ public DynamicBridge(DalamudPluginInterface pi)
ProperOnLogin.RegisterInteractable(OnLogin, true);
Memory = new();
NeoTabs = new();
PenumbraManager = new();
});
}

Expand Down Expand Up @@ -176,6 +179,10 @@ void Logout()
if (C.EnableCustomize) TaskManager.Enqueue(() => CustomizePlusManager.RestoreState());
LastJob = 0;
LastItems = [];
if (C.EnablePenumbra)
{
PenumbraManager.UnsetAssignmentIfNeeded();
}
//LastGS = -1;
}

Expand Down Expand Up @@ -273,6 +280,7 @@ private void OnUpdate()
var DoNullGlamourer = true;
var DoNullCustomize = true;
var DoNullHonorific = true;
var DoNullPenumbra = true;
for (int i = 0; i < newRule.Count; i++)
{
var rule = newRule[i];
Expand All @@ -284,6 +292,10 @@ private void OnUpdate()
var preset = profile.GetPresetsUnion().FirstOrDefault(s => s.Name == rule.SelectedPresets[index]);
if (preset != null)
{
if (C.EnablePenumbra)
{
ApplyPresetPenumbra(preset, ref DoNullPenumbra);
}
if (C.EnableGlamourer)
{
ApplyPresetGlamourer(preset, isFirst, ref DoNullGlamourer);
Expand All @@ -300,6 +312,11 @@ private void OnUpdate()
}
}

if (DoNullPenumbra)
{
ApplyPresetPenumbra(profile.FallbackPreset, ref DoNullPenumbra);
if (DoNullPenumbra) NullPenumbra();
}
if (DoNullGlamourer)
{
ApplyPresetGlamourer(profile.FallbackPreset, true, ref DoNullGlamourer);
Expand All @@ -316,6 +333,12 @@ private void OnUpdate()
if(DoNullHonorific) NullHonorific();
}

void NullPenumbra()
{
if (!C.EnablePenumbra) return;
PenumbraManager.UnsetAssignmentIfNeeded();
}

void NullHonorific()
{
if (!C.EnableHonorific) return;
Expand Down Expand Up @@ -398,6 +421,16 @@ void TerritoryChanged(ushort id)
SoftForceUpdate = true;
}

void ApplyPresetPenumbra(Preset preset, ref bool DoNullPenumbra)
{
if (preset.Penumbra.Count > 0)
{
var randomAssignment = preset.Penumbra[Random.Next(preset.Penumbra.Count)];
PenumbraManager.SetAssignment(randomAssignment);
DoNullPenumbra = false;
}
}

void ApplyPresetGlamourer(Preset preset, bool isFirst, ref bool DoNullGlamourer)
{
if (preset.Glamourer.Count > 0 || preset.ComplexGlamourer.Count > 0)
Expand Down
4 changes: 2 additions & 2 deletions DynamicBridge/DynamicBridge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>NightmareXIV</Authors>
<Version>1.0.4.9</Version>
<Version>1.0.5.0</Version>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows7.0</TargetFramework>
<Platforms>x64</Platforms>
<LangVersion>preview</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
13 changes: 13 additions & 0 deletions DynamicBridge/Gui/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using DynamicBridge.IPC.Customize;
using DynamicBridge.IPC.Glamourer;
using DynamicBridge.IPC.Honorific;
using DynamicBridge.IPC.Penumbra;
using ECommons.GameHelpers;
using ECommons.Reflection;
using Lumina.Excel.GeneratedSheets;
Expand All @@ -28,6 +29,18 @@ public static unsafe class Debug
static List<string> TestData = null;
public static void Draw()
{
if (ImGui.CollapsingHeader("Penumbra"))
{
ImGuiEx.Text(EColor.Green, $"Current: {P.PenumbraManager.GetCollectionForType(PenumbraManager.ApiCollectionType.Yourself) ?? "(null)"}");
foreach(var x in P.PenumbraManager.GetCollections())
{
if (ImGui.Selectable($"{x}"))
{
var ret = P.PenumbraManager.SetCollectionForType(PenumbraManager.ApiCollectionType.Yourself, x, true, true);
DuoLog.Information($"Error: {ret.Error}, old: {ret.OldCollection}");
}
}
}
if(ImGui.CollapsingHeader("Pathes"))
{
foreach(var x in Utils.GetCombinedPathes())
Expand Down
37 changes: 37 additions & 0 deletions DynamicBridge/Gui/GuiPresets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ static void DrawPresets(Profile currentProfile, List<Preset> presetList, out Act
if (C.EnableHonorific) cnt++;
if (C.EnableCustomize) cnt++;
if (C.EnableGlamourer) cnt++;
if (C.EnablePenumbra) cnt++;
List<(Vector2 RowPos, Vector2 ButtonPos, Action BeginDraw, Action AcceptDraw)> MoveCommands = [];
ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, Utils.CellPadding);
if (ImGui.BeginTable($"##presets{extraID}", cnt, ImGuiTableFlags.RowBg | ImGuiTableFlags.Borders | ImGuiTableFlags.Resizable | ImGuiTableFlags.Reorderable))
Expand All @@ -236,6 +237,7 @@ static void DrawPresets(Profile currentProfile, List<Preset> presetList, out Act
if(C.EnableGlamourer) ImGui.TableSetupColumn("Glamourer");
if (C.EnableCustomize) ImGui.TableSetupColumn("Customize+");
if (C.EnableHonorific) ImGui.TableSetupColumn("Honorific");
if (C.EnablePenumbra) ImGui.TableSetupColumn("Penumbra");
ImGui.TableSetupColumn(" ", ImGuiTableColumnFlags.NoResize | ImGuiTableColumnFlags.WidthFixed);
ImGui.TableHeadersRow();

Expand Down Expand Up @@ -518,6 +520,41 @@ void FiltersSelection()
filterCnt++;
}
}

//Penumbra
{
if (C.EnablePenumbra)
{
ImGui.TableNextColumn();
ImGuiEx.SetNextItemFullWidth();
if (ImGui.BeginCombo("##penumbra", preset.Penumbra.PrintRange(out var fullList, "- None -"), C.ComboSize))
{
FiltersSelection();
var collections = P.PenumbraManager.GetCollections().Order();
var index = 0;
foreach (var x in collections)
{
index++;
ImGui.PushID(index);
var name = x;
if (Filters[filterCnt].Length > 0 && !name.Contains(Filters[filterCnt], StringComparison.OrdinalIgnoreCase)) continue;
if (OnlySelected[filterCnt] && !preset.Penumbra.Contains(name)) continue;
ImGuiEx.CollectionCheckbox($"{name}", x, preset.Penumbra);
ImGui.PopID();
}
foreach (var x in preset.Penumbra)
{
if (collections.Contains(x)) continue;
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
ImGuiEx.CollectionCheckbox($"{x}", x, preset.Penumbra, false, true);
ImGui.PopStyleColor();
}
ImGui.EndCombo();
}
if (fullList != null) ImGuiEx.Tooltip(UI.RandomNotice + fullList);
filterCnt++;
}
}

ImGui.TableNextColumn();

Expand Down
91 changes: 91 additions & 0 deletions DynamicBridge/IPC/Penumbra/PenumbraManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using ECommons.EzIpcManager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DynamicBridge.IPC.Penumbra;
public class PenumbraManager
{
[EzIPC] public readonly Func<IList<string>> GetCollections;
[EzIPC] public readonly Func<ApiCollectionType, string> GetCollectionForType;
[EzIPC] public readonly Func<ApiCollectionType, string, bool, bool, (PenumbraApiEc Error, string OldCollection)> SetCollectionForType;

string OldAssignment;

public PenumbraManager()
{
EzIPC.Init(this, "Penumbra");
}

public void SetAssignment(string newAssignment)
{
try
{
var result = SetCollectionForType(ApiCollectionType.Yourself, newAssignment, true, true);
if (!result.Error.EqualsAny(PenumbraApiEc.Success, PenumbraApiEc.NothingChanged))
{
var e = $"Error setting Penumbra assignment: {result.Error}";
PluginLog.Error(e);
Notify.Error(e);
}
else
{
OldAssignment = result.OldCollection;
}
}
catch(Exception e)
{
e.Log();
}
}

public void UnsetAssignmentIfNeeded()
{
if (OldAssignment == null) return;
try
{
SetCollectionForType(ApiCollectionType.Yourself, OldAssignment, true, true);
OldAssignment = null;
}
catch(Exception e)
{
e.Log();
}
}

public enum ApiCollectionType : byte
{
Yourself = 0,
Default = 0xE0,
Interface = 0xE1,
Current = 0xE2,
}

public enum PenumbraApiEc
{
Success = 0,
NothingChanged = 1,
CollectionMissing = 2,
ModMissing = 3,
OptionGroupMissing = 4,
OptionMissing = 5,

CharacterCollectionExists = 6,
LowerPriority = 7,
InvalidGamePath = 8,
FileMissing = 9,
InvalidManipulation = 10,
InvalidArgument = 11,
PathRenameFailed = 12,
CollectionExists = 13,
AssignmentCreationDisallowed = 14,
AssignmentDeletionDisallowed = 15,
InvalidIdentifier = 16,
SystemDisposed = 17,
AssignmentDeletionFailed = 18,
UnknownError = 255,
}

}
14 changes: 7 additions & 7 deletions DynamicBridge/packages.lock.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": 1,
"dependencies": {
"net7.0-windows7.0": {
"net8.0-windows7.0": {
"DalamudPackager": {
"type": "Direct",
"requested": "[2.1.12, )",
Expand All @@ -10,24 +10,24 @@
},
"Microsoft.Extensions.DependencyInjection": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "elNeOmkeX3eDVG6pYVeV82p29hr+UKDaBhrZyWvWLw/EVZSYEkZlQdkp0V39k/Xehs2Qa0mvoCvkVj3eQxNQ1Q==",
"resolved": "8.0.0",
"contentHash": "V8S3bsm50ig6JSyrbcJJ8bW2b9QLGouz+G1miK3UTaOWmMtFwNNNzUf4AleyDWUmTrWMLNnFSLEQtxmxgNQnNQ==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0"
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0"
}
},
"Microsoft.Extensions.DependencyInjection.Abstractions": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "h3j/QfmFN4S0w4C2A6X7arXij/M/OVw3uQHSOFxnND4DyAzO1F9eMX7Eti7lU/OkSthEE0WzRsfT/Dmx86jzCw=="
"resolved": "8.0.0",
"contentHash": "cjWrLkJXK0rs4zofsK4bSdg+jhDLTaxrkXu4gS6Y7MAlCvRyNNgwY/lJi5RDlQOnSZweHqoyvgvbdvQsRIW+hg=="
},
"ecommons": {
"type": "Project"
},
"ottergui": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.DependencyInjection": "[7.0.0, )"
"Microsoft.Extensions.DependencyInjection": "[8.0.0, )"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ECommons

0 comments on commit 2a5b3fe

Please sign in to comment.