-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: compat with Kaeno-TraderScrolling
- Loading branch information
Trap
committed
Dec 26, 2024
1 parent
d95de79
commit 743e487
Showing
4 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |