|
1 | 1 | using Cpp2IL.Core.Extensions; |
2 | 2 | using HarmonyLib; |
| 3 | +using Il2CppInterop.Runtime; |
3 | 4 | using TMPro; |
4 | 5 | using UnityEngine; |
5 | 6 | using UnityEngine.EventSystems; |
@@ -43,37 +44,67 @@ private static void PopupButtonContainer_SetButtonData(PopupButtonContainer __in |
43 | 44 | [HarmonyPatch(typeof(StartScreen), nameof(StartScreen.Start))] |
44 | 45 | private static void StartScreen_Start() |
45 | 46 | { |
46 | | - GameObject originalText = GameObject.Find("SettingsButton/DescriptionText"); |
47 | | - GameObject text = GameObject.Instantiate(originalText, originalText.transform.parent.parent.parent); |
48 | | - text.name = "PolyModVersion"; |
49 | | - RectTransform rect = text.GetComponent<RectTransform>(); |
50 | | - rect.anchoredPosition = new(265, 40); |
51 | | - rect.sizeDelta = new(500, rect.sizeDelta.y); |
52 | | - rect.anchorMax = new(0, 0); |
53 | | - rect.anchorMin = new(0, 0); |
54 | | - text.GetComponent<TextMeshProUGUI>().fontSize = 18; |
55 | | - text.GetComponent<TextMeshProUGUI>().alignment = TextAlignmentOptions.BottomLeft; |
56 | | - text.GetComponent<TMPLocalizer>().Text = $"PolyMod {Plugin.VERSION}"; |
57 | | - text.AddComponent<LayoutElement>().ignoreLayout = true; |
58 | | - |
59 | | - GameObject originalButton = GameObject.Find("StartScreen/NewsButton"); |
60 | | - GameObject button = GameObject.Instantiate(originalButton, originalButton.transform.parent); |
61 | | - button.gameObject.name = "PolyModHubButton"; |
62 | | - button.transform.position = originalButton.transform.position - new Vector3(90, 0, 0); |
63 | | - button.active = true; |
64 | | - |
65 | | - Transform descriptionText = button.transform.Find("DescriptionText"); |
66 | | - descriptionText.gameObject.SetActive(true); |
67 | | - descriptionText.GetComponentInChildren<TMPLocalizer>().Key = "polymod.hub"; |
68 | | - |
69 | | - UIRoundButton buttonObject = button.GetComponent<UIRoundButton>(); |
70 | | - buttonObject.bg.sprite = Visual.BuildSprite(Plugin.GetResource("polymod_icon.png").ReadBytes()); |
71 | | - buttonObject.bg.transform.localScale = new Vector3(1.2f, 1.2f, 0); |
72 | | - buttonObject.bg.color = Color.white; |
73 | | - |
74 | | - buttonObject.outline.gameObject.SetActive(false); |
75 | | - buttonObject.iconContainer.gameObject.SetActive(false); |
76 | | - buttonObject.OnClicked += (UIButtonBase.ButtonAction)PolyModHubButtonClicked; |
| 47 | + Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppReferenceArray<UnityEngine.Object> allLocalizers = GameObject.FindObjectsOfTypeAll(Il2CppType.From(typeof(TMPLocalizer))); |
| 48 | + |
| 49 | + foreach (UnityEngine.Object item in allLocalizers) |
| 50 | + { |
| 51 | + TMPLocalizer? localizer = item.TryCast<TMPLocalizer>(); |
| 52 | + if (localizer == null) |
| 53 | + { |
| 54 | + continue; |
| 55 | + } |
| 56 | + |
| 57 | + Transform? parent = localizer?.gameObject?.transform?.parent; |
| 58 | + if (parent == null) |
| 59 | + { |
| 60 | + continue; |
| 61 | + } |
| 62 | + |
| 63 | + string parentName = parent.name; |
| 64 | + |
| 65 | + if (parentName == "SettingsButton") |
| 66 | + { |
| 67 | + Transform? textTransform = parent.FindChild("DescriptionText"); |
| 68 | + if (textTransform == null) |
| 69 | + { |
| 70 | + return; |
| 71 | + } |
| 72 | + |
| 73 | + GameObject originalText = textTransform.gameObject; |
| 74 | + GameObject text = GameObject.Instantiate(originalText, originalText.transform.parent.parent.parent); |
| 75 | + text.name = "PolyModVersion"; |
| 76 | + |
| 77 | + RectTransform rect = text.GetComponent<RectTransform>(); |
| 78 | + rect.anchoredPosition = new Vector2(265, 40); |
| 79 | + rect.sizeDelta = new Vector2(500, rect.sizeDelta.y); |
| 80 | + rect.anchorMax = Vector2.zero; |
| 81 | + rect.anchorMin = Vector2.zero; |
| 82 | + |
| 83 | + TextMeshProUGUI textComponent = text.GetComponent<TextMeshProUGUI>(); |
| 84 | + textComponent.fontSize = 18; |
| 85 | + textComponent.alignment = TextAlignmentOptions.BottomLeft; |
| 86 | + |
| 87 | + text.GetComponent<TMPLocalizer>().Text = $"PolyMod {Plugin.VERSION}"; |
| 88 | + text.AddComponent<LayoutElement>().ignoreLayout = true; |
| 89 | + } |
| 90 | + else if (parentName == "NewsButton") |
| 91 | + { |
| 92 | + GameObject originalButton = parent.gameObject; |
| 93 | + GameObject button = GameObject.Instantiate(originalButton, originalButton.transform.parent); |
| 94 | + button.name = "PolyModHubButton"; |
| 95 | + button.transform.position = originalButton.transform.position - new Vector3(90, 0, 0); |
| 96 | + |
| 97 | + UIRoundButton buttonComponent = button.GetComponent<UIRoundButton>(); |
| 98 | + buttonComponent.bg.sprite = Visual.BuildSprite(Plugin.GetResource("polymod_icon.png").ReadBytes()); |
| 99 | + buttonComponent.bg.transform.localScale = new Vector3(1.2f, 1.2f, 0); |
| 100 | + buttonComponent.bg.color = Color.white; |
| 101 | + |
| 102 | + GameObject.Destroy(buttonComponent.icon.gameObject); |
| 103 | + GameObject.Destroy(buttonComponent.outline.gameObject); |
| 104 | + |
| 105 | + buttonComponent.OnClicked += (UIButtonBase.ButtonAction)PolyModHubButtonClicked; |
| 106 | + } |
| 107 | + } |
77 | 108 |
|
78 | 109 | static void PolyModHubButtonClicked(int buttonId, BaseEventData eventData) |
79 | 110 | { |
|
0 commit comments