Skip to content

Commit

Permalink
fix: compat with Kaeno-TraderScrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
Trap committed Dec 26, 2024
1 parent d95de79 commit 743e487
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
6 changes: 6 additions & 0 deletions PTT-Plugin/PTT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(PathToSPT)\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>$(PathToSPT)\EscapeFromTarkov_Data\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIModule">
<HintPath>$(PathToSPT)\EscapeFromTarkov_Data\Managed\UnityEngine.UIModule.dll</HintPath>
</Reference>
<Reference Include="Sirenix.Serialization">
<HintPath>$(PathToSPT)\EscapeFromTarkov_Data\Managed\Sirenix.Serialization.dll</HintPath>
</Reference>
Expand Down
30 changes: 30 additions & 0 deletions PTT-Plugin/Patches/KaenoTraderScrollingCompatPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Reflection;
using SPT.Reflection.Patching;
using EFT.UI;
using HarmonyLib;
using UnityEngine;

using PTT.Scripts;

namespace PTT.Patches;


public class KaenoTraderScrollingCompatPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(TraderScreensGroup), nameof(TraderScreensGroup.Show));
}

[PatchPostfix]
public static void PatchPostFix()
{
GameObject gameObject = GameObject.Find("Menu UI");
var script = gameObject.GetComponentInChildren<KaenoTraderScrollingCompatScript>();

if (script == null)
{
gameObject.AddComponent<KaenoTraderScrollingCompatScript>();
}
}
}
13 changes: 11 additions & 2 deletions PTT-Plugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ namespace PTT;
public class Plugin : BaseUnityPlugin
{
public static bool FikaIsInstalled { get; private set; }
private static bool InteractableExfilsApiIsInstalled { get; set; }
private static bool KaenoTraderScrollingIsInstalled { get; set; }
public static ManualLogSource LogSource { get; private set; }
public static ExfilsTargetsService ExfilsTargetsService;

private static bool InteractableExfilsApiIsInstalled { get; set; }

protected void Awake()
{
Expand All @@ -23,6 +24,9 @@ protected void Awake()
LogSource = Logger;
FikaIsInstalled = Chainloader.PluginInfos.ContainsKey("com.fika.core");
InteractableExfilsApiIsInstalled = Chainloader.PluginInfos.ContainsKey("Jehree.InteractableExfilsAPI");
KaenoTraderScrollingIsInstalled = Chainloader.PluginInfos.ContainsKey("com.kaeno.TraderScrolling");

Settings.Config.Init(Config);

ExfilsTargetsService = new ExfilsTargetsService();

Expand All @@ -31,7 +35,12 @@ protected void Awake()
Helpers.Logger.Info($"Fika.Core plugin detected");
}

Settings.Config.Init(Config);
if (KaenoTraderScrollingIsInstalled)
{
Helpers.Logger.Info($"Kaeno-TraderScrolling detected");
new Patches.KaenoTraderScrollingCompatPatch().Enable();
}

new Patches.HideLockedTraderCardPatch().Enable();
new Patches.HideLockedTraderPanelPatch().Enable();
new Patches.InitAllExfiltrationPointsPatch().Enable();
Expand Down
52 changes: 52 additions & 0 deletions PTT-Plugin/Scripts/KaenoTraderScrollingCompatScript.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Comfort.Common;
using EFT.UI;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

namespace PTT.Scripts;

public class KaenoTraderScrollingCompatScript : MonoBehaviour
{
private GameObject _traderCards;
private RectTransform _traderCardsRect;
private int _countCards;

protected void Awake()
{
_traderCards = GameObject.Find("TraderCards");
_traderCardsRect = _traderCards.GetComponent<RectTransform>();
_countCards = _traderCards.transform.ActiveChildCount();

RecomputeAnchorMin();
}

protected void FixedUpdate()
{
if (_traderCards == null || _traderCardsRect == null)
{
return;
}

int newCountCards = _traderCards.transform.ActiveChildCount();
if (_countCards != newCountCards)
{
_countCards = newCountCards;
RecomputeAnchorMin();
}
}

private void RecomputeAnchorMin()
{
int count = _countCards - 10;

//THIS IS DEFAULT anchorMin For anything below 11
_traderCardsRect.anchorMin = new Vector2(0.595f, 1f);

if (count > 0)
{
var offset = 0.065f * count;
_traderCardsRect.anchorMin = new Vector2(0.595f - offset, 1f);
}
}
}

0 comments on commit 743e487

Please sign in to comment.