Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
* Add `OverrideQueuedBackground` to the `PixelCardBehaviours`.
* This is used for overriding the Queued Background of a card.
* Upgraded the API's `.csproj`'s, and TCLI Build system.
* Publicized the `_originalColor`, `_enterColor`, and `_selectedColor` used within `ActivatedAbilityIconInteractable` of the Community Patch.
* Fixed activated abilities outside Act 2 not updating their icon colours to indicate interactability
* Added `ModifyOnEnterColour` and `ModifyOnSelectColour` event hooks to community patch's `ActivatedAbilityIconInteractable` class
* Update the API to use Latest BepInEx.

# 2.24.1
Expand Down
74 changes: 45 additions & 29 deletions InscryptionCommunityPatch/Card/ActivatedAbilityHandler3D.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using DiskCardGame;
using HarmonyLib;
using Sirenix.Utilities;
using UnityEngine;

namespace InscryptionCommunityPatch.Card;

/// <summary>
/// Fixes the Activated Ability handler in 3D Environments.
/// Handles activated abilities outside Act 2 to make them function correctly.
/// </summary>
public class ActivatedAbilityHandler3D : ManagedBehaviour
{
public class ActivatedAbilityHandler3D : ManagedBehaviour {
/// <summary>
/// The current Icon Group of <see cref="AbilityIconInteractable"/>.
/// </summary>
Expand All @@ -30,41 +31,56 @@ public void AddInteractable(ActivatedAbilityIconInteractable interactable)
/// <summary>
/// Updates the List of <see cref="interactables"/> to the passed in List.
/// </summary>
/// <param name="controllerActiveIcons">The list of Interactable used to replace the current <see cref="interactables"/> list.</param>
public void UpdateInteractableList(List<AbilityIconInteractable> controllerActiveIcons)
{
/// <param name="activeIconsCard">The list of ability interactables to replace the current <see cref="interactables"/> list.</param>
/// /// <param name="activeIconsRender">The list of ability interactables used by the game to render ability icons.</param>
public void UpdateInteractableList(List<AbilityIconInteractable> activeIconsCard, List<AbilityIconInteractable> activeIconsRender) {
interactables.Clear();
currentIconGroup = controllerActiveIcons;
controllerActiveIcons
.Where(elem => AbilitiesUtil.GetInfo(elem.Ability).activated)
.Do(abIcon =>
{
ActivatedAbilityIconInteractable currentIcon = abIcon.gameObject.GetComponent<ActivatedAbilityIconInteractable>();
if (currentIcon)
{
currentIcon.AssignAbility(abIcon.Ability);
AddInteractable(currentIcon);
currentIconGroup = activeIconsCard;
//PatchPlugin.Logger.LogInfo($"{activeIconsCard.Count} {activeIconsRender.Count}");
for (int i = 0; i < activeIconsCard.Count; i++) {
// if this active icon is for an activated sigil
if (AbilitiesUtil.GetInfo(activeIconsCard[0].Ability).activated) {
ActivatedAbilityIconInteractable currentIcon = activeIconsCard[0].gameObject.GetComponent<ActivatedAbilityIconInteractable>();
// if there is no activated interactable, add one
if (currentIcon.SafeIsUnityNull()) {
GameObject obj = activeIconsCard[0].gameObject;
obj.layer = 0;

currentIcon = obj.AddComponent<ActivatedAbilityIconInteractable>();
}
else
{
var go = abIcon.gameObject;
go.layer = 0;

var interactable = go.AddComponent<ActivatedAbilityIconInteractable>();
interactable.AssignAbility(abIcon.Ability);
currentIcon.AssignAbility(activeIconsCard[0].Ability);

AddInteractable(interactable);
// if there is a corresponding render interactable object, connect it to the active interactable object
if (i >= 0 && i < activeIconsRender.Count && activeIconsRender.Count > 0) {
ActivatedAbilityIconInteractable renderIcon = activeIconsRender[i].gameObject.GetComponent<ActivatedAbilityIconInteractable>();
if (renderIcon.SafeIsUnityNull()) {
renderIcon = activeIconsRender[i].gameObject.AddComponent<ActivatedAbilityIconInteractable>();
}
renderIcon.AssignAbility(currentIcon.Ability);

currentIcon.SetRenderIcon(renderIcon);
}
});
AddInteractable(currentIcon);
}
}

if (PatchPlugin.configDisplayCompleteDebugLogsInConsole.Value)
if (PatchPlugin.configDisplayCompleteDebugLogsInConsole.Value) {
PatchPlugin.Logger.LogDebug($"[Handler3D] Updated interactable list: [{interactables.Join(interactable => $"GO [{interactable.gameObject}] Ability [{interactable.Ability}]")}]");
}
}

private void OnDestroy()
{
foreach (var interactable in interactables)
{
/// <summary>
/// Updates the List of <see cref="interactables"/> to the passed in List.
/// </summary>
/// <param name="controllerActiveIcons">The list of Interactable used to replace the current <see cref="interactables"/> list.</param>
[Obsolete("Does not update icon rendering. Use UpdateInteractableList(List, List) instead.")]
public void UpdateInteractableList(List<AbilityIconInteractable> controllerActiveIcons) {
UpdateInteractableList(controllerActiveIcons, new(1));
}

private void OnDestroy() {
foreach (var interactable in interactables) {
Destroy(interactable);
}
}
Expand Down
57 changes: 53 additions & 4 deletions InscryptionCommunityPatch/Card/ActivatedAbilityIconFix.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using DiskCardGame;
using HarmonyLib;
using InscryptionAPI.Helpers;
using Sirenix.Utilities;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;

namespace InscryptionCommunityPatch.Card;

/// <summary>
/// Fixes related to Activated Ability Icons.
/// Fixes activated abilities not working outside Act 2.
/// </summary>
[HarmonyPatch]
public static class ActivatedAbilityIconFix
Expand Down Expand Up @@ -35,8 +39,7 @@ private static void FixActivatedAbilitiesOnAnyChange(ref PlayableCard __instance

ActivatedAbilityHandler3D abilityHandler3D = __instance.GetComponent<ActivatedAbilityHandler3D>();

if (abilityHandler3D.SafeIsUnityNull())
{
if (abilityHandler3D.SafeIsUnityNull()) {
if (PatchPlugin.configDisplayCompleteDebugLogsInConsole.Value)
PatchPlugin.Logger.LogDebug($"[PlayableCard.OnStatsChanged] Adding activated ability handler to card [{__instance.Info.displayedName}]");

Expand All @@ -48,7 +51,53 @@ private static void FixActivatedAbilitiesOnAnyChange(ref PlayableCard __instance
if (PatchPlugin.configDisplayCompleteDebugLogsInConsole.Value)
PatchPlugin.Logger.LogDebug($"[PlayableCard.OnStatsChanged] -> Resetting icon list for [{__instance.Info.displayedName}]");

abilityHandler3D.UpdateInteractableList(__instance.AbilityIcons.abilityIcons);
abilityHandler3D.UpdateInteractableList(
__instance.AbilityIcons.abilityIcons,
(CardRenderCamera.Instance.cardDisplayer as CardDisplayer3D).AbilityIcons.abilityIcons
);
}
}

/// <summary>
/// Determines the colour of the given <see cref="AbilityIconInteractable"/>'s icon, while supporting dynamic colouring for 3D activated sigil icons.
/// </summary>
/// <param name="abilityIconInteractable">The <see cref="AbilityIconInteractable"/> whose icon we're colouring.</param>
/// <param name="color">The default ability colour. This will be used if no override conditions are met.</param>
/// <param name="inConduitCircuit">Whether the card with this ability is in a conduit circuit.</param>
public static void SetAbilityIconDefaultColour(AbilityIconInteractable abilityIconInteractable, Color color, bool inConduitCircuit) {
AbilityInfo info = AbilitiesUtil.GetInfo(abilityIconInteractable.Ability);
ActivatedAbilityIconInteractable act = abilityIconInteractable.GetComponent<ActivatedAbilityIconInteractable>();

if (info.hasColorOverride && !(info.conduitCell && inConduitCircuit)) {
abilityIconInteractable.SetColor(info.colorOverride);
}
else if (act?.CurrentColourOverride != null) {
abilityIconInteractable.SetColor((Color)act.CurrentColourOverride);
}
else {
abilityIconInteractable.SetColor(color);
}
}

[HarmonyTranspiler, HarmonyPatch(typeof(CardAbilityIcons), nameof(CardAbilityIcons.SetColorOfDefaultIcons))]
private static IEnumerable<CodeInstruction> FixActivatedIconSetColour(IEnumerable<CodeInstruction> instructions) {
List<CodeInstruction> codes = new(instructions);

CodeInstruction startCode = codes.Find(x => x.opcode == OpCodes.Stloc_S && x.operand.ToString() == "DiskCardGame.AbilityIconInteractable (4)");
object operand = startCode.operand;
int startIndex = codes.FindIndex(x => x.opcode == OpCodes.Stloc_S && x.operand.ToString() == "DiskCardGame.AbilityInfo (5)") - 2;
int endIndex = codes.FindLastIndex(x => x.opcode == OpCodes.Add) - 3;

MethodBase customMethod = AccessTools.Method(
typeof(ActivatedAbilityIconFix), nameof(ActivatedAbilityIconFix.SetAbilityIconDefaultColour),
new Type[] { typeof(AbilityIconInteractable), typeof(Color), typeof(bool) });

codes.RemoveRange(startIndex, endIndex - startIndex + 1);
codes.Insert(startIndex, new(OpCodes.Callvirt, customMethod));
codes.Insert(startIndex, new(OpCodes.Ldarg_2));
codes.Insert(startIndex, new(OpCodes.Ldarg_1));
codes.Insert(startIndex, new(OpCodes.Ldloc_S, operand));

return codes;
}
}
Loading
Loading