From 711b0b6f4df27a1bc261992e77036f3d6f67942e Mon Sep 17 00:00:00 2001 From: Kaeno Date: Sun, 8 Oct 2023 16:48:28 +0100 Subject: [PATCH] Traderscrolling --- Live/TraderScrolling/PlayerCardPatch.cs | 35 ++++++++++++++ Live/TraderScrolling/PlayerCardScript.cs | 48 +++++++++++++++++++ Live/TraderScrolling/TraderScrolling.cs | 4 +- Live/TraderScrolling/TraderScrollingPatch.cs | 48 ++++--------------- Live/TraderScrolling/TraderScrollingScript.cs | 40 +++++++++++++--- 5 files changed, 127 insertions(+), 48 deletions(-) create mode 100644 Live/TraderScrolling/PlayerCardPatch.cs create mode 100644 Live/TraderScrolling/PlayerCardScript.cs diff --git a/Live/TraderScrolling/PlayerCardPatch.cs b/Live/TraderScrolling/PlayerCardPatch.cs new file mode 100644 index 0000000..24df702 --- /dev/null +++ b/Live/TraderScrolling/PlayerCardPatch.cs @@ -0,0 +1,35 @@ +using Aki.Reflection.Patching; +using Aki.Reflection.Utils; +using EFT.UI; +using JetBrains.Annotations; +using System.Linq; +using System.Reflection; +using UnityEngine; +using UnityEngine.UI; + +namespace TraderScrolling +{ + public class PlayerCardPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + Logger.LogError("Patching Show"); + return typeof(DisplayMoneyPanelTMPText).GetMethod("Show", PatchConstants.PublicFlags); + } + + [PatchPostfix] + public static void PatchPostFix() + { + var go = GameObject.Find("Menu UI"); + var check = go.GetComponentInChildren(); + + + if (check != null) + { + return; + } + + go.AddComponent(); + } + } +} diff --git a/Live/TraderScrolling/PlayerCardScript.cs b/Live/TraderScrolling/PlayerCardScript.cs new file mode 100644 index 0000000..4957788 --- /dev/null +++ b/Live/TraderScrolling/PlayerCardScript.cs @@ -0,0 +1,48 @@ +using System.Linq; +using UnityEngine; +using UnityEngine.UI; +using BepInEx.Logging; +using EFT.UI; +using EFT.UI.Ragfair; + +namespace TraderScrolling +{ + public class PlayerCardScript : MonoBehaviour + { + + private void Awake() + { + //Adjusts Money position + var rightPerson = GameObject.Find("Right Person"); + var list = rightPerson.GetComponentsInChildren(true).ToList(); + var money = list.FirstOrDefault(x => x.name == "Money"); + var moneyRect = money.RectTransform(); + moneyRect.anchoredPosition = new Vector2(moneyRect.anchoredPosition.x + 60f, moneyRect.anchoredPosition.y); + //End of Money position Change + + // Change spacing + var list2 = rightPerson.GetComponentsInChildren(true).ToList(); + var money2 = list2.FirstOrDefault(x => x.name == "Money"); + money2.spacing = 10; + // End of Money Spacing + + // Make tile simple + var tile = rightPerson.GetComponentsInChildren(true).ToList(); + var tileImage = tile.FirstOrDefault(x => x.name == "Background Tile"); + tileImage.type = Image.Type.Simple; + + var foundObject = rightPerson.transform.Find("Background Tile"); + foundObject.gameObject.SetActive(true); + + var tileList = rightPerson.GetComponentsInChildren(true).ToList(); + var tileRect = tileList.FirstOrDefault(x => x.name == "Background Tile"); + tileRect.sizeDelta = new Vector2(500f, 0); + + + var background = tile.FirstOrDefault(x => x.name == "Background"); + background.color = new Color(0, 0, 0, 1); + // Change Colour alpha to max for background + + } + } +} diff --git a/Live/TraderScrolling/TraderScrolling.cs b/Live/TraderScrolling/TraderScrolling.cs index b877141..c8e3bcf 100644 --- a/Live/TraderScrolling/TraderScrolling.cs +++ b/Live/TraderScrolling/TraderScrolling.cs @@ -1,14 +1,14 @@ using BepInEx; -using System; namespace TraderScrolling { [BepInPlugin("com.kaeno.TraderScrolling", "Kaeno-TraderScrolling", "1.0.0")] public class TraderScrolling : BaseUnityPlugin { - public void awake() + private void Awake() { new TraderScrollingPatch().Enable(); + new PlayerCardPatch().Enable(); } } } diff --git a/Live/TraderScrolling/TraderScrollingPatch.cs b/Live/TraderScrolling/TraderScrollingPatch.cs index 2055939..d1e86b4 100644 --- a/Live/TraderScrolling/TraderScrollingPatch.cs +++ b/Live/TraderScrolling/TraderScrollingPatch.cs @@ -1,12 +1,4 @@ -using Aki.Reflection.Patching; -using Aki.Reflection.Utils; -using EFT.UI; -using System.Linq; -using System.Reflection; -using UnityEngine; -using UnityEngine.UI; - -namespace TraderScrolling +namespace TraderScrolling { public class TraderScrollingPatch : ModulePatch { @@ -18,38 +10,14 @@ namespace TraderScrolling [PatchPostfix] public static void PatchPostFix() { - Debug.LogError("test 1"); - var traderCards = GameObject.Find("TraderCards"); + var go = GameObject.Find("Menu UI"); + var check = go.GetComponentInChildren(); + if (check != null) + { + return; + } - Debug.LogError(traderCards); - var traderCardsRect = traderCards.RectTransform(); - Debug.LogError(traderCardsRect); - - traderCardsRect.anchorMax = new Vector2(1f, 1f); - traderCardsRect.anchorMin = new Vector2(0.385f, 1f); - - var menuUI = GameObject.Find("Menu UI"); - Debug.LogError(menuUI); - - var list = menuUI.GetComponentsInChildren(true).ToList(); - Debug.LogError(list.Count); - - var container = list.FirstOrDefault(x => x.name == "Container"); - Debug.LogError(container); - - var containerRect = container.RectTransform(); - Debug.LogError(containerRect); - - containerRect.anchorMin = new Vector2(1f, 1f); - containerRect.anchorMax = new Vector2(0.01f, 0f); - - var scrollrect = traderCards.AddComponent(); - Debug.LogError(scrollrect); - - scrollrect.content = traderCardsRect; - scrollrect.vertical = false; - scrollrect.movementType = ScrollRect.MovementType.Elastic; - scrollrect.viewport = containerRect; + go.AddComponent(); } } } diff --git a/Live/TraderScrolling/TraderScrollingScript.cs b/Live/TraderScrolling/TraderScrollingScript.cs index 7872a3e..094a9f9 100644 --- a/Live/TraderScrolling/TraderScrollingScript.cs +++ b/Live/TraderScrolling/TraderScrollingScript.cs @@ -1,12 +1,40 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Linq; +using UnityEngine; +using UnityEngine.UI; namespace TraderScrolling { - public class TraderScrollingScript + public class TraderScrollingScript : MonoBehaviour { + private void Awake() + { + var traderCards = GameObject.Find("TraderCards"); + var menuUI = GameObject.Find("Menu UI"); + var list = menuUI.GetComponentsInChildren(true).ToList(); + var container = list.FirstOrDefault(x => x.name == "Container"); + var scrollrect = traderCards.AddComponent(); + var traderCardsRect = traderCards.RectTransform(); + var containerRect = container.RectTransform(); + + var countCards = traderCards.transform.childCount; + + var 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); + } + + traderCardsRect.anchorMax = new Vector2(1f, 1f); + containerRect.anchorMax = new Vector2(1f, 1f); + containerRect.anchorMin = new Vector2(0.01f, 0f); + scrollrect.content = traderCardsRect; + scrollrect.vertical = false; + scrollrect.movementType = ScrollRect.MovementType.Elastic; + scrollrect.viewport = containerRect; + } } }