diff --git a/ReMod.Core.csproj b/ReMod.Core.csproj index 2a5d96f..61d7f84 100644 --- a/ReMod.Core.csproj +++ b/ReMod.Core.csproj @@ -3,6 +3,7 @@ C:/Program Files (x86)/Steam/steamapps/common/VRChat $(HOME)/.steam/steam/steamapps/common/VRChat S:\Games\steamapps\common\VRChat + G:\SteamLibrary\steamapps\common\VRChat @@ -109,6 +110,7 @@ + diff --git a/UI/QuickMenu/ReRadioTogglePage.cs b/UI/QuickMenu/ReRadioTogglePage.cs new file mode 100644 index 0000000..491851e --- /dev/null +++ b/UI/QuickMenu/ReRadioTogglePage.cs @@ -0,0 +1,140 @@ +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 string TitleText + { + set => _titleText.text = value; + } + + private TextMeshProUGUI _titleText; + private ListBinding ListBinding; + private GameObject RadioButtonPrefab; + private RadioButtonSelectorGroup RadioButtonSelectorGroup; + 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