public override void Instantiate() { //We have to find our own target //TODO: Clean up time complexity issue. This is called for each new option StandardLevelDetailViewController _sldvc = Resources.FindObjectsOfTypeAll <StandardLevelDetailViewController>().First(); GameplayOptionsViewController _govc = _sldvc.GetField <GameplayOptionsViewController>("_gameplayOptionsViewController"); RectTransform container = (RectTransform)_govc.transform.Find("Switches").Find("Container"); var volumeSettings = Resources.FindObjectsOfTypeAll <VolumeSettingsController>().FirstOrDefault(); gameObject = UnityEngine.Object.Instantiate(volumeSettings.gameObject, container); gameObject.name = optionName; gameObject.GetComponentInChildren <TMP_Text>().text = optionName; //Slim down the toggle option so it fits in the space we have before the divider (gameObject.transform as RectTransform).sizeDelta = new Vector2(50, (gameObject.transform as RectTransform).sizeDelta.y); //This magical nonsense is courtesy of Taz and his SettingsUI class VolumeSettingsController volume = gameObject.GetComponent <VolumeSettingsController>(); ListViewController newListSettingsController = (ListViewController)ReflectionUtil.CopyComponent(volume, typeof(ListSettingsController), typeof(ListViewController), gameObject); UnityEngine.Object.DestroyImmediate(volume); newListSettingsController.values = _options.Keys.ToList(); newListSettingsController.SetValue = OnChange; newListSettingsController.GetValue = () => { if (GetValue != null) { return(GetValue.Invoke()); } return(_options.Keys.ElementAt(0)); }; newListSettingsController.GetTextForValue = (v) => { if (_options.ContainsKey(v)) { return(_options[v]); } return("UNKNOWN"); }; //Initialize the controller, as if we had just opened the settings menu newListSettingsController.Init(); gameObject.SetActive(false); }
private void AddModMenuButton() { GameplayOptionsViewController _gameplayOptionsViewController = _levelDetailViewController.GetPrivateField <GameplayOptionsViewController>("_gameplayOptionsViewController"); _gameplayOptionsViewController.transform.Find("InfoText").gameObject.SetActive(false); RectTransform container = (RectTransform)_gameplayOptionsViewController.transform.Find("Switches").Find("Container"); //DumpChildren(_gameplayOptionsViewController.transform); //Console.WriteLine("container.sizeDelta.x : " + container.sizeDelta.x + " container.sizeDelta.y : " + container.sizeDelta.y); container.sizeDelta = new Vector2(container.sizeDelta.x, container.sizeDelta.y + 14f); container.Translate(new Vector3(0, -0.1f, 0)); Transform noEnergy = container.Find("NoEnergy"); bool IsDarthModeOn = Plugin.IsDarthModeOn; bool IsOneHanded = Plugin.IsOneHanded; darthModeToggle = new GameOptionToggle(container.gameObject, noEnergy.gameObject, Plugin.KeyDarthMode, Icons["NoteCutInfoIcon"], "DMaul Mode", IsDarthModeOn); oneHandedToggle = new GameOptionToggle(container.gameObject, noEnergy.gameObject, Plugin.KeyOneHanded, Icons["SingleSaberIcon"], "DM Onehanded", IsOneHanded); darthModeToggle.OnToggle += OnDarthMualModeToggle; oneHandedToggle.OnToggle += OnOneHandedToggle; }
public override void Instantiate() { //We have to find our own target //TODO: Clean up time complexity issue. This is called for each new option StandardLevelDetailViewController _sldvc = Resources.FindObjectsOfTypeAll <StandardLevelDetailViewController>().First(); GameplayOptionsViewController _govc = _sldvc.GetField <GameplayOptionsViewController>("_gameplayOptionsViewController"); RectTransform container = (RectTransform)_govc.transform.Find("Switches").Find("Container"); //TODO: Can probably slim this down a bit gameObject = UnityEngine.Object.Instantiate(container.Find("NoEnergy").gameObject, container); gameObject.GetComponentInChildren <TextMeshProUGUI>().text = optionName; gameObject.name = optionName; gameObject.layer = container.gameObject.layer; gameObject.transform.parent = container; gameObject.transform.localPosition = Vector3.zero; gameObject.transform.localScale = Vector3.one; gameObject.transform.rotation = Quaternion.identity; gameObject.SetActive(false); //All options start disabled gameObject.GetComponentInChildren <HMUI.Toggle>().isOn = GetValue; gameObject.GetComponentInChildren <HMUI.Toggle>().didSwitchEvent += (_, e) => { OnToggle?.Invoke(e); }; }
public static void Build() { //Grab necessary references StandardLevelDetailViewController _sldvc = Resources.FindObjectsOfTypeAll <StandardLevelDetailViewController>().First(); GameplayOptionsViewController _govc = _sldvc.GetField <GameplayOptionsViewController>("_gameplayOptionsViewController"); //Get reference to the switch container RectTransform container = (RectTransform)_govc.transform.Find("Switches").Find("Container"); container.sizeDelta = new Vector2(container.sizeDelta.x, container.sizeDelta.y + 7f); //Grow container so it aligns properly with text //Get references to the original switches, so we can later duplicate then destroy them Transform noEnergyOriginal = container.Find("NoEnergy"); Transform noObstaclesOriginal = container.Find("NoObstacles"); Transform mirrorOriginal = container.Find("Mirror"); Transform staticLightsOriginal = container.Find("StaticLights"); //Get references to other UI elements we need to hide //Transform divider = (RectTransform)_govc.transform.Find("Switches").Find("Separator"); //Transform defaults = (RectTransform)_govc.transform.Find("Switches").Find("DefaultsButton"); //Future duplicated switches Transform noEnergy = null; Transform noObstacles = null; Transform mirror = null; Transform staticLights = null; //Future down button Button _pageDownButton = null; //Create up button Button _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), container); _pageUpButton.transform.parent = container; _pageUpButton.transform.localScale = Vector3.one; (_pageUpButton.transform as RectTransform).sizeDelta = new Vector2((_pageUpButton.transform.parent as RectTransform).sizeDelta.x, 3.5f); _pageUpButton.onClick.AddListener(delegate() { Instance.ChangePage(--Instance._listIndex, container, noEnergy, noObstacles, mirror, staticLights); //Nice responsive scroll buttons if (Instance._listIndex <= 0) { _pageUpButton.interactable = false; } if (Instance.customOptions.Count > 0) { _pageDownButton.interactable = true; } }); _pageUpButton.interactable = false; //Duplicate and delete default toggles so that the up button is on the top noEnergy = Instantiate(noEnergyOriginal, container); noObstacles = Instantiate(noObstaclesOriginal, container); mirror = Instantiate(mirrorOriginal, container); staticLights = Instantiate(staticLightsOriginal, container); //Create custom options foreach (object option in Instance.customOptions) { //Due to possible "different" types (due to cross-plugin support), we need to do this through reflection option.InvokeMethod("Instantiate"); } //Destroy original toggles and set their corresponding references to the new toggles DestroyImmediate(noEnergyOriginal.gameObject); DestroyImmediate(noObstaclesOriginal.gameObject); DestroyImmediate(mirrorOriginal.gameObject); DestroyImmediate(staticLightsOriginal.gameObject); _govc.SetField("_noEnergyToggle", noEnergy.gameObject.GetComponentInChildren <HMUI.Toggle>()); _govc.SetField("_noObstaclesToggle", noObstacles.gameObject.GetComponentInChildren <HMUI.Toggle>()); _govc.SetField("_mirrorToggle", mirror.gameObject.GetComponentInChildren <HMUI.Toggle>()); _govc.SetField("_staticLightsToggle", staticLights.gameObject.GetComponentInChildren <HMUI.Toggle>()); //Create down button _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), container); _pageDownButton.transform.parent = container; _pageDownButton.transform.localScale = Vector3.one; (_pageDownButton.transform as RectTransform).sizeDelta = new Vector2((_pageDownButton.transform.parent as RectTransform).sizeDelta.x, (_pageDownButton.transform as RectTransform).sizeDelta.y); _pageDownButton.onClick.AddListener(delegate() { Instance.ChangePage(++Instance._listIndex, container, noEnergy, noObstacles, mirror, staticLights); //Nice responsive scroll buttons if (Instance._listIndex >= 0) { _pageUpButton.interactable = true; } if (((Instance.customOptions.Count + 4 - 1) / 4) - Instance._listIndex <= 0) { _pageDownButton.interactable = false; } }); _pageDownButton.interactable = Instance.customOptions.Count > 0; //Unfortunately, due to weird object creation for versioning, this doesn't always //happen when the scene changes Instance._listIndex = 0; }