コード例 #1
0
 private static void ScrollToButton(On.RoR2.UI.HGButton.orig_OnSelect orig, HGButton self, BaseEventData eventData)
 {
     orig(self, eventData);
     if (self.gameObject.name.Contains("VRModSetting"))
     {
         HGScrollRectHelper scrollHelper = self.GetComponentInParent <HGScrollRectHelper>();
         scrollHelper.ScrollToShowMe(self);
     }
 }
コード例 #2
0
        private void CreateModListButton()
        {
            ModListButton = Object.Instantiate(_verticalLayout !.transform.Find("SettingsEntryButton, Bool (Audio Focus)").gameObject);

            Object.DestroyImmediate(ModListButton.GetComponentInChildren <CarouselController>());
            Object.DestroyImmediate(ModListButton.GetComponentInChildren <ButtonSkinController>());
            Object.DestroyImmediate(ModListButton.transform.Find("CarouselRect").gameObject);


            HGButton   oldButton            = ModListButton.GetComponent <HGButton>();
            bool       allowAllEventSystems = oldButton.allowAllEventSystems;
            bool       submitOnPointerUp    = oldButton.submitOnPointerUp;
            UILayerKey requiredTopLayer     = oldButton.requiredTopLayer;

            UnityEngine.Events.UnityEvent onFindSelectableLeft  = oldButton.onFindSelectableLeft;
            UnityEngine.Events.UnityEvent onFindSelectableRight = oldButton.onFindSelectableRight;
            UnityEngine.Events.UnityEvent onSelect   = oldButton.onSelect;
            UnityEngine.Events.UnityEvent onDeselect = oldButton.onDeselect;
            bool defaultFallbackButton = oldButton.defaultFallbackButton;

            Button.ButtonClickedEvent buttonClickedEvent = oldButton.onClick;
            ColorBlock colors              = oldButton.colors;
            bool       showImageOnHover    = oldButton.showImageOnHover;
            Image      imageOnHover        = oldButton.imageOnHover;
            Image      imageOnInteractable = oldButton.imageOnInteractable;
            bool       updateTextOnHover   = oldButton.updateTextOnHover;
            LanguageTextMeshController hoverLanguageTextMeshController = oldButton.hoverLanguageTextMeshController;
            string hoverToken           = oldButton.hoverToken;
            string uiClickSoundOverride = oldButton.uiClickSoundOverride;

            Object.DestroyImmediate(oldButton);

            colors.disabledColor = ModOptionsHeaderButton.GetComponent <HGButton>().colors.disabledColor;

            ModListButton newButton = ModListButton.AddComponent <ModListButton>();

            newButton.allowAllEventSystems  = allowAllEventSystems;
            newButton.submitOnPointerUp     = submitOnPointerUp;
            newButton.requiredTopLayer      = requiredTopLayer;
            newButton.onFindSelectableLeft  = onFindSelectableLeft;
            newButton.onFindSelectableRight = onFindSelectableRight;
            newButton.onSelect              = onSelect;
            newButton.onDeselect            = onDeselect;
            newButton.defaultFallbackButton = defaultFallbackButton;
            newButton.onClick                         = buttonClickedEvent;
            newButton.colors                          = colors;
            newButton.showImageOnHover                = showImageOnHover;
            newButton.imageOnHover                    = imageOnHover;
            newButton.imageOnInteractable             = imageOnInteractable;
            newButton.updateTextOnHover               = updateTextOnHover;
            newButton.hoverLanguageTextMeshController = hoverLanguageTextMeshController;
            newButton.hoverToken                      = hoverToken;
            newButton.uiClickSoundOverride            = uiClickSoundOverride;
            newButton.interactable                    = true;
            newButton.enabled                         = true;
            newButton.disablePointerClick             = false;
            newButton.onClick.RemoveAllListeners();

            RectTransform buttonTextRectTransform = ModListButton.transform.Find("ButtonText").GetComponent <RectTransform>();

            buttonTextRectTransform.anchorMin = new Vector2(0.19f, 0);
            buttonTextRectTransform.anchorMax = new Vector2(1, 1);

            GameObject modIconGameObject = new GameObject("ModIcon");

            RectTransform modIconRectTransform = modIconGameObject.AddComponent <RectTransform>();

            modIconGameObject.AddComponent <CanvasRenderer>();
            modIconGameObject.AddComponent <Image>().preserveAspect = true;
            modIconRectTransform.anchorMin = new Vector2(0.04f, 0.13f);
            modIconRectTransform.anchorMax = new Vector2(0.19f, 0.86f);
            modIconRectTransform.pivot     = new Vector2(0.5f, 0.5f);
            modIconGameObject.transform.SetParent(ModListButton.transform);


            GameObject    iconOutline = Object.Instantiate(ModListButton.transform.Find("BaseOutline").gameObject, modIconRectTransform);
            RectTransform iconOutlineRectTransform = iconOutline.GetComponent <RectTransform>();

            iconOutlineRectTransform.sizeDelta        = Vector2.zero;
            iconOutlineRectTransform.anchoredPosition = Vector2.zero;
            iconOutlineRectTransform.localScale       = new Vector3(0.94f, 1.16f, 1);

            ModListButton.SetActive(false);
        }
        private void SetupPagingStuff()
        {
            var mpEventSystemLocator = GetComponent <MPEventSystemLocator>();
            var survivorChoiseGrid   = transform.parent.gameObject;
            var uiLayerKey           = survivorChoiseGrid.GetComponentInParent <UILayerKey>();


            previousButtonComponent = SetupPagingButton("Previous", "Left", SelectPreviousPage, nameof(RewiredConsts.Action.UITabLeft), 0, 2);
            nextButtonComponent     = SetupPagingButton("Next", "Right", SelectNextPage, nameof(RewiredConsts.Action.UITabRight), 10, 6);

            HGButton SetupPagingButton(string prefix, string buttonPrefix, System.Action action, string actionName, int siblingIndex, int glyphIndex)
            {
                var buttonContainer = new GameObject($"{prefix}ButtonContainer");

                buttonContainer.transform.SetParent(transform.parent, false);
                buttonContainer.transform.SetSiblingIndex(siblingIndex);
                buttonContainer.layer = 5;

                var buttonVerticalLayout = buttonContainer.AddComponent <VerticalLayoutGroup>();

                buttonVerticalLayout.childControlHeight = true;
                buttonVerticalLayout.childControlWidth  = true;

                var buttonContainerLayout = buttonContainer.AddComponent <LayoutElement>();

                buttonContainerLayout.preferredHeight = 156;

                var button = GameObject.Instantiate(Resources.Load <GameObject>($"prefabs/ui/controls/buttons/{buttonPrefix}Button"), buttonContainer.transform, false);

                button.name  = $"{prefix}Page";
                button.layer = 5;

                var buttonComponent = button.GetComponent <HGButton>();

                buttonComponent.onClick = new Button.ButtonClickedEvent();
                buttonComponent.onClick.AddListener(new UnityEngine.Events.UnityAction(action));

                var buttonLayout = button.GetComponent <LayoutElement>();

                buttonLayout.preferredWidth = buttonSide;
                buttonLayout.minWidth       = buttonSide;

                //var glyph = subheaderPanel.Find($"GenericGlyph ({buttonPrefix})").gameObject.InstantiateClone($"{prefix}Glyph");
                var glyph = new GameObject($"{prefix}Glyph");

                glyph.transform.SetParent(buttonContainer.transform, false);
                glyph.layer = 5;
                glyph.transform.SetSiblingIndex(0);
                glyph.SetActive(mpEventSystemLocator.eventSystem && mpEventSystemLocator.eventSystem.currentInputSource == MPEventSystem.InputSource.Gamepad);

                var glyphTransform = glyph.AddComponent <RectTransform>();

                glyphTransform.anchoredPosition3D = new Vector3(0, 0, 0);
                glyphTransform.localScale         = new Vector3(1, 1, 1);
                glyphTransform.sizeDelta          = new Vector2(0, 0);

                var glyphImage = glyph.AddComponent <Image>();

                glyphImage.color   = Color.white;
                glyphImage.enabled = false;

                var glyphLayout = glyph.AddComponent <LayoutElement>();

                glyphLayout.minWidth = buttonSide;

                //var glyphText = glyph.transform.Find("Text").gameObject;
                var glyphText = new GameObject($"Text");

                glyphText.transform.SetParent(glyph.transform);
                glyphText.layer = 5;

                var glyphTextTransform = glyphText.AddComponent <RectTransform>();

                glyphTextTransform.anchorMin          = new Vector2(0, 0);
                glyphTextTransform.anchorMax          = new Vector2(1, 1);
                glyphTextTransform.anchoredPosition3D = new Vector3(0, 0, 0);
                glyphTextTransform.localScale         = new Vector3(1, 1, 1);
                glyphTextTransform.sizeDelta          = new Vector2(48, 48);

                glyphText.AddComponent <MPEventSystemLocator>();

                var inputBindingDisplayController = glyphText.AddComponent <InputBindingDisplayController>();

                inputBindingDisplayController.actionName             = actionName;
                inputBindingDisplayController.axisRange              = Rewired.AxisRange.Full;
                inputBindingDisplayController.useExplicitInputSource = true;
                inputBindingDisplayController.explicitInputSource    = MPEventSystem.InputSource.Gamepad;
                inputBindingDisplayController.Awake();


                var glyphTextLayout = glyphText.AddComponent <LayoutElement>();

                glyphTextLayout.preferredHeight = buttonSide;
                glyphTextLayout.preferredWidth  = buttonSide;

                var tmpBombDropShadows = Resources.Load <TMP_FontAsset>("tmpfonts/bombardier/tmpbombdropshadow.asset");
                var hgTextMeshPro      = glyphText.AddComponent <HGTextMeshProUGUI>();

                hgTextMeshPro.raycastTarget = false;
                hgTextMeshPro.text          = $"<sprite=\"tmpsprXboxOneGlyphs\" name=\"texXBoxOneGlyphs_{glyphIndex}\">";
                hgTextMeshPro.UpdateFontAsset();
                hgTextMeshPro.fontSize            = 24;
                hgTextMeshPro.fontSizeMin         = 18;
                hgTextMeshPro.fontSizeMax         = 72;
                hgTextMeshPro.fontWeight          = FontWeight.Regular;
                hgTextMeshPro.alignment           = TextAlignmentOptions.Center;
                hgTextMeshPro.wordWrappingRatios  = 0.4F;
                hgTextMeshPro.overflowMode        = TextOverflowModes.Overflow;
                hgTextMeshPro.enableKerning       = true;
                hgTextMeshPro.richText            = true;
                hgTextMeshPro.parseCtrlCharacters = true;
                hgTextMeshPro.isOrthographic      = true;

                var glyphTMP = new GameObject("TMP SubMeshUI");

                glyphTMP.transform.SetParent(glyphText.transform);
                glyphTMP.layer = 5;

                var glyphTMPTransform = glyphTMP.AddComponent <RectTransform>();

                glyphTMPTransform.anchoredPosition3D = new Vector3(0, 0, 0);
                glyphTMPTransform.localScale         = new Vector3(1, 1, 1);
                glyphTMPTransform.sizeDelta          = new Vector2(0, 0);

                var material = new Material(Shader.Find("TextMeshPro/Sprite"));
                var texture  = Resources.Load <Texture>("sprite assets/texXBoxOneGlyphs.png");

                var glyphTMPCanvasRenderer = glyphTMP.AddComponent <CanvasRenderer>();

                glyphTMPCanvasRenderer.SetMaterial(material, texture);

                var glyphTMPSubMesh = glyphTMP.AddComponent <TMP_SubMeshUI>();

                glyphTMPSubMesh.fontAsset   = tmpBombDropShadows;
                glyphTMPSubMesh.spriteAsset = Resources.Load <TMP_SpriteAsset>("sprite assets/tmpsprXboxOneGlyphs.asset");
                typeof(TMP_SubMeshUI).GetField("m_TextComponent", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(glyphTMPSubMesh, hgTextMeshPro);

                var pageEvent = survivorChoiseGrid.AddComponent <HGGamepadInputEvent>();

                pageEvent.requiredTopLayer       = uiLayerKey;
                pageEvent.actionName             = actionName;
                pageEvent.enabledObjectsIfActive = new GameObject[] { glyph };
                pageEvent.actionEvent            = new UnityEngine.Events.UnityEvent();
                pageEvent.actionEvent.AddListener(new UnityEngine.Events.UnityAction(action));

                return(buttonComponent);
            }
        }
コード例 #4
0
 private void Awake()
 {
     button = GetComponent <HGButton>();
 }
コード例 #5
0
        private static GameObject SetupSubPanel(Transform parent)
        {
            GameObject subPanelToInstantiate = parent.Find("SettingsSubPanel, Controls (Gamepad)").gameObject;

            GameObject subPanelInstance = GameObject.Instantiate(subPanelToInstantiate, parent);

            Transform instanceLayout = subPanelInstance.transform.Find("Scroll View/Viewport/VerticalLayout");

            foreach (Transform child in instanceLayout)
            {
                GameObject.Destroy(child.gameObject);
            }

            GameObject sliderSetting   = subPanelToInstantiate.transform.Find("Scroll View/Viewport/VerticalLayout/SettingsEntryButton, Slider (Look Scale X)").gameObject;
            GameObject boolSetting     = subPanelToInstantiate.transform.Find("Scroll View/Viewport/VerticalLayout/SettingsEntryButton, Bool (Invert X)").gameObject;
            GameObject carouselSetting = parent.transform.Find("SettingsSubPanel, Video/Scroll View/Viewport/VerticalLayout/SettingsEntryButton, Carousel (Vsync)").gameObject;

            LanguageTextMeshController descriptionText = parent.transform.Find("GenericDescriptionPanel/ContentSizeFitter/DescriptionText").GetComponent <LanguageTextMeshController>();

            bool first = true;

            foreach (KeyValuePair <string, ModConfig.ConfigSetting> keyValuePair in ModConfig.settings)
            {
                ModConfig.ConfigSetting setting = keyValuePair.Value;

                BaseSettingsControl settingInstance;
                if (setting.entry.SettingType == typeof(float) || setting.entry.SettingType == typeof(int))
                {
                    settingInstance = GameObject.Instantiate(sliderSetting, instanceLayout).GetComponent <BaseSettingsControl>();

                    SettingsSlider slider = settingInstance as SettingsSlider;
                    slider.minValue     = setting.minValue;
                    slider.maxValue     = setting.maxValue;
                    slider.formatString = setting.entry.SettingType == typeof(float) ? "{0:0.00}" : "{0:N0}";
                }
                else if (setting.entry.SettingType == typeof(bool))
                {
                    settingInstance = GameObject.Instantiate(boolSetting, instanceLayout).GetComponent <BaseSettingsControl>();
                }
                else
                {
                    settingInstance = GameObject.Instantiate(carouselSetting, instanceLayout).GetComponent <BaseSettingsControl>();

                    CarouselController carousel = settingInstance as CarouselController;
                    List <CarouselController.Choice> choices = new List <CarouselController.Choice>();
                    if (keyValuePair.Key == "vr_ray_color")
                    {
                        string[] choiceStrings = new string[]
                        {
                            "White",
                            "Green",
                            "Red",
                            "Blue",
                            "Yellow",
                            "Magenta",
                            "Cyan",
                            "Lime",
                            "Black"
                        };

                        string[] hexStrings = new string[]
                        {
                            "#FFFFFF",
                            "#008000",
                            "#FF0000",
                            "#0000FF",
                            "#FFFF00",
                            "#FF00FF",
                            "#00FFFF",
                            "#00FF00",
                            "#000000"
                        };

                        for (int i = 0; i < choiceStrings.Length; i++)
                        {
                            CarouselController.Choice choice = new CarouselController.Choice();
                            choice.convarValue           = hexStrings[i];
                            choice.suboptionDisplayToken = choiceStrings[i];
                            choices.Add(choice);
                        }
                    }

                    carousel.choices = choices.ToArray();
                }

                settingInstance.settingSource   = BaseSettingsControl.SettingSource.ConVar;
                settingInstance.nameToken       = setting.entry.Definition.Key;
                settingInstance.settingName     = keyValuePair.Key;
                settingInstance.gameObject.name = "VRModSetting, " + settingInstance.nameToken;

                HGButton button = settingInstance.GetComponent <HGButton>();
                if (button)
                {
                    string prefixString = "";

                    if (setting.settingUpdate == ModConfig.ConfigSetting.SettingUpdate.NextStage)
                    {
                        prefixString = "[WILL APPLY NEXT STAGE] ";
                    }
                    else if (setting.settingUpdate == ModConfig.ConfigSetting.SettingUpdate.AfterRestart)
                    {
                        prefixString = "[RESTART REQUIRED] ";
                    }

                    button.updateTextOnHover = true;
                    button.hoverToken        = prefixString + setting.entry.Description.Description;
                    button.hoverLanguageTextMeshController = descriptionText;

                    button.defaultFallbackButton = first;
                    first = false;
                }
            }

            GameObject controllerBindingSetting = subPanelToInstantiate.transform.Find("Scroll View/Viewport/VerticalLayout/SettingsEntryButton, Binding (Jump)").gameObject;
            GameObject keyboardBindingSetting   = parent.Find("SettingsSubPanel, Controls (M&KB)/Scroll View/Viewport/VerticalLayout/SettingsEntryButton, Binding (Jump)").gameObject;

            ActionAddons.ActionDef[] actionDefs = ActionAddons.actionDefs;
            foreach (var actionDef in actionDefs)
            {
                if (actionDef.keyboardMap != KeyboardKeyCode.None)
                {
                    AddBindingSetting(actionDef, keyboardBindingSetting, instanceLayout);
                }
                if (actionDef.joystickMap != ActionAddons.ControllerInput.None)
                {
                    AddBindingSetting(actionDef, controllerBindingSetting, instanceLayout);
                }
            }

            subPanelInstance.transform.Find("Scroll View").gameObject.AddComponent <ScrollToSelection>();

            return(subPanelInstance);
        }