From dc636c7f6a507f10f718da25a9f56c307cc4fb5e Mon Sep 17 00:00:00 2001 From: DDAkebono Date: Sat, 21 May 2022 21:41:06 -0500 Subject: [PATCH 1/4] Added implementation of radio toggle menu --- UI/QuickMenu/ReRadioTogglePage.cs | 139 ++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 UI/QuickMenu/ReRadioTogglePage.cs diff --git a/UI/QuickMenu/ReRadioTogglePage.cs b/UI/QuickMenu/ReRadioTogglePage.cs new file mode 100644 index 0000000..64df847 --- /dev/null +++ b/UI/QuickMenu/ReRadioTogglePage.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using ReMod.Core.Unity; +using ReMod.Core.VRChat; +using TMPro; +using UnityEngine; +using UnityEngine.UI; +using VRC.UI.Elements; +using VRC.UI.Elements.Controls; +using ListBinding = MonoBehaviourPublicTrGaBoObAcObDi2GaBoUnique; //DataModel.dll +using Object = Il2CppSystem.Object; + +namespace ReMod.Core.UI.QuickMenu +{ + public class ReRadioTogglePage : UiElement + { + private static GameObject _menuPrefab; + + private static GameObject MenuPrefab + { + get + { + if (_menuPrefab == null) + { + _menuPrefab = QuickMenuEx.Instance.field_Public_Transform_0.Find("Window/QMParent/Menu_ChangeAudioInputDevice").gameObject; + } + return _menuPrefab; + } + } + + private static int SiblingIndex => QuickMenuEx.Instance.field_Public_Transform_0.Find("Window/QMParent/Modal_AddMessage").GetSiblingIndex(); + + public event Action OnOpen; + public event Action OnClose; + public event Action OnSelect; + public ListBinding ListBinding; + public GameObject RadioButtonPrefab; + public RadioButtonSelectorGroup RadioButtonSelectorGroup; + public TextMeshProUGUI TitleText; + + private Dictionary> _radioElementSource = new(); + private bool _isUpdated; + + private readonly bool _isRoot; + + private readonly Transform _container; + + public UIPage UiPage { get; } + + public ReRadioTogglePage(string name) : base(MenuPrefab, QuickMenuEx.MenuParent, $"Menu_{name}", false) + { + var headerTransform = RectTransform.GetChild(0); + + TitleText = headerTransform.GetComponentInChildren(); + TitleText.text = name; + TitleText.richText = true; + + _container = RectTransform.GetComponentInChildren().content; + + var inputMenu = RectTransform.GetComponent(); + RadioButtonPrefab = inputMenu.field_Public_GameObject_0; + ListBinding = inputMenu.field_Public_MonoBehaviourPublicTrGaBoObAcObDi2GaBoUnique_0; + RadioButtonSelectorGroup = ListBinding.gameObject.GetComponent(); + + ListBinding.field_Private_Dictionary_2_Object_GameObject_0 = new Il2CppSystem.Collections.Generic.Dictionary(); + + //Get rid of the AudioInputDeviceMenu component + UnityEngine.Object.DestroyImmediate(inputMenu); + + // Set up UIPage + UiPage = GameObject.GetComponent(); + UiPage.field_Public_String_0 = $"QuickMenuReMod{GetCleanName(name)}"; + UiPage.field_Private_Boolean_1 = true; + UiPage.field_Protected_MenuStateController_0 = QuickMenuEx.MenuStateCtrl; + UiPage.field_Private_List_1_UIPage_0 = new Il2CppSystem.Collections.Generic.List(); + UiPage.field_Private_List_1_UIPage_0.Add(UiPage); + + QuickMenuEx.MenuStateCtrl.field_Private_Dictionary_2_String_UIPage_0.Add(UiPage.field_Public_String_0, UiPage); + + EnableDisableListener.RegisterSafe(); + var listener = GameObject.AddComponent(); + listener.OnEnableEvent += () => OnOpen?.Invoke(); + listener.OnDisableEvent += () => OnClose?.Invoke(); + } + + public void Open() + { + QuickMenuEx.MenuStateCtrl.PushPage(UiPage.field_Public_String_0); + + if (!_isUpdated) + return; + + _isUpdated = false; + + foreach(var element in ListBinding.field_Private_Dictionary_2_Object_GameObject_0) + UnityEngine.Object.DestroyImmediate(element.value); + ListBinding.field_Private_Dictionary_2_Object_GameObject_0.Clear(); + + foreach (var newElement in _radioElementSource) + { + var radioButton = UnityEngine.Object.Instantiate(RadioButtonPrefab, ListBinding.gameObject.transform); + radioButton.active = true; + var radioButtonSelector = radioButton.GetComponent(); + radioButtonSelector.field_Public_TextMeshProUGUI_0 = radioButtonSelector.GetComponentInChildren(); + radioButtonSelector.field_Private_Button_0 = radioButtonSelector.GetComponent