Ejemplo n.º 1
0
        public IEnumerator InitializeUI()
        {
            MelonLogger.Msg("Initializing DiscordMute UI...");
            var parentObject = QuickMenu.Find("Container").Find("Window").transform;
            var originalMic  = parentObject.Find("MicButton").gameObject;

            DiscordButton      = UnityEngine.Object.Instantiate(originalMic, originalMic.transform);
            DiscordButton.name = "DiscordButton";
            DiscordButton.transform.SetParent(parentObject);

            DiscordButton.SetActive(true);
            DiscordButton.transform.localPosition += new Vector3(30, 97, 0);


            MelonLogger.Msg("Initializing Bind Manager");
            BindManager.Initialize();

            void ShowBindManager()
            {
                BindManager.Show("Press your mute key in keyboard", new Action <List <Keys> >(selectedKeys =>
                {
                    string stringKeys = "";
                    if (selectedKeys.Count > 0)
                    {
                        stringKeys = string.Join(",", selectedKeys);
                    }

                    MelonPreferences.SetEntryValue("DiscordMute", nameof(MuteKey), stringKeys);
                    MelonPreferences.Save();
                }), null);
            }

            ExpansionKitApi.GetExpandedMenu(ExpandedMenu.SettingsMenu).AddSimpleButton("Discord Bind", () => ShowBindManager());

            UnityEngine.Object.Destroy(DiscordButton.GetComponent <MicToggle>());
            UnityEngine.Object.Destroy(DiscordButton.GetComponent <Toggle>());

            yield return(null); // Wait object destroy

            var tooltip = DiscordButton.GetComponent <UiToggleTooltip>();

            tooltip.field_Public_String_0 = "Discord";
            tooltip.field_Public_String_1 = "Discord";

            var toggle = DiscordButton.AddComponent <Toggle>();

            yield return(null); // Wait component

            toggle.onValueChanged.RemoveAllListeners();

            toggle.isOn = true;
            toggle.onValueChanged.AddListener(new Action <bool>(value =>
            {
                if (!string.IsNullOrEmpty(MuteKey))
                {
                    List <Keys> selectedKeys = new List <Keys>();
                    if (!string.IsNullOrEmpty(MuteKey))
                    {
                        string[] stringKeys = MuteKey.Split(',');
                        foreach (var stringKey in stringKeys)
                        {
                            selectedKeys.Add((Keys)Enum.Parse(typeof(Keys), stringKey));
                        }
                    }

                    // Hold and Release the selected keys
                    foreach (var key in selectedKeys)
                    {
                        HoldKey(key);
                    }
                    foreach (var key in selectedKeys)
                    {
                        ReleaseKey(key);
                    }
                }
                else
                {
                    ShowBindManager();
                }
            }));

            yield break;
        }
Ejemplo n.º 2
0
        public override void VRChat_OnUiManagerInit()
        {
            BindManager.Initialize();

            void ShowBindManager()
            {
                BindManager.Show("Press your mute key in keyboard", new Action <List <Keys> >(selectedKeys =>
                {
                    string stringKeys = "";
                    if (selectedKeys.Count > 0)
                    {
                        stringKeys = string.Join(",", selectedKeys);
                    }

                    MelonPreferences.SetEntryValue("DiscordMute", nameof(MuteKey), stringKeys);
                    MelonPreferences.Save();
                }), null);
            }

            ExpansionKitApi.GetExpandedMenu(ExpandedMenu.SettingsMenu).AddSimpleButton("Discord Bind", () => ShowBindManager());

            var originalMic = GameObject.Find("/UserInterface/QuickMenu/MicControls");

            DiscordButton      = GameObject.Instantiate(originalMic, originalMic.transform);
            DiscordButton.name = "Discord";

            DiscordButton.SetActive(true);
            DiscordButton.transform.localPosition -= new Vector3(420, 7);

            DiscordButton.GetComponentInChildren <Text>().text = "Discord";

            var button = DiscordButton.GetComponentInChildren <Button>();

            button.onClick = new Button.ButtonClickedEvent();
            button.onClick.AddListener(new Action(() => {
                bool isEnabled = !GameObject.Find("/UserInterface/QuickMenu/MicControls/Discord/MicButton/MicEnabled").activeSelf;

                GameObject.Find("/UserInterface/QuickMenu/MicControls/Discord/MicButton/MicEnabled").gameObject.SetActive(isEnabled);
                GameObject.Find("/UserInterface/QuickMenu/MicControls/Discord/MicButton/MicDisabled").gameObject.SetActive(!isEnabled);

                if (!string.IsNullOrEmpty(MuteKey))
                {
                    List <Keys> selectedKeys = new List <Keys>();
                    if (!string.IsNullOrEmpty(MuteKey))
                    {
                        string[] stringKeys = MuteKey.Split(',');
                        foreach (var stringKey in stringKeys)
                        {
                            selectedKeys.Add((Keys)Enum.Parse(typeof(Keys), stringKey));
                        }
                    }

                    // Hold and Release the selected keys
                    foreach (var key in selectedKeys)
                    {
                        HoldKey(key);
                    }
                    foreach (var key in selectedKeys)
                    {
                        ReleaseKey(key);
                    }
                }
                else
                {
                    ShowBindManager();
                }
            }));
        }