示例#1
0
            // Token: 0x060023A6 RID: 9126 RVA: 0x0009B8F8 File Offset: 0x00099AF8
            private Row(LoadoutPanelController owner, int bodyIndex, string titleToken)
            {
                this.owner                          = owner;
                this.userProfile                    = owner.currentDisplayData.userProfile;
                this.rowPanelTransform              = (RectTransform)UnityEngine.Object.Instantiate <GameObject>(LoadoutPanelController.rowPrefab, owner.rowContainer).transform;
                this.buttonContainerTransform       = (RectTransform)this.rowPanelTransform.Find("ButtonContainer");
                this.choiceHighlightRect            = (RectTransform)this.rowPanelTransform.Find("ChoiceHighlightRect");
                UserProfile.onLoadoutChangedGlobal += this.OnLoadoutChangedGlobal;
                SurvivorDef survivorDef = SurvivorCatalog.FindSurvivorDefFromBody(BodyCatalog.GetBodyPrefab(bodyIndex));

                if (survivorDef != null)
                {
                    this.primaryColor = survivorDef.primaryColor;
                }
                float num;
                float s;
                float v;

                Color.RGBToHSV(this.primaryColor, out num, out s, out v);
                num += 0.5f;
                if (num > 1f)
                {
                    num -= 1f;
                }
                this.complementaryColor = Color.HSVToRGB(num, s, v);
                RectTransform rectTransform = (RectTransform)this.rowPanelTransform.Find("SlotLabel");

                rectTransform.GetComponent <LanguageTextMeshController>().token = titleToken;
                rectTransform.GetComponent <HGTextMeshProUGUI>().color          = this.primaryColor;
                this.choiceHighlightRect.GetComponent <Image>().color           = this.complementaryColor;
            }
示例#2
0
            // Token: 0x060023A8 RID: 9128 RVA: 0x0009BA40 File Offset: 0x00099C40
            public static LoadoutPanelController.Row FromSkillSlot(LoadoutPanelController owner, int bodyIndex, int skillSlotIndex, GenericSkill skillSlot)
            {
                SkillFamily  skillFamily = skillSlot.skillFamily;
                SkillLocator component   = BodyCatalog.GetBodyPrefabBodyComponent(bodyIndex).GetComponent <SkillLocator>();
                bool         addWIPIcons = true;
                string       titleToken;

                switch (component.FindSkillSlot(skillSlot))
                {
                case SkillSlot.None:
                    titleToken  = "LOADOUT_SKILL_MISC";
                    addWIPIcons = false;
                    break;

                case SkillSlot.Primary:
                    titleToken  = "LOADOUT_SKILL_PRIMARY";
                    addWIPIcons = false;
                    break;

                case SkillSlot.Secondary:
                    titleToken = "LOADOUT_SKILL_SECONDARY";
                    break;

                case SkillSlot.Utility:
                    titleToken = "LOADOUT_SKILL_UTILITY";
                    break;

                case SkillSlot.Special:
                    titleToken = "LOADOUT_SKILL_SPECIAL";
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                LoadoutPanelController.Row row = new LoadoutPanelController.Row(owner, bodyIndex, titleToken);
                for (int i = 0; i < skillFamily.variants.Length; i++)
                {
                    ref SkillFamily.Variant ptr    = ref skillFamily.variants[i];
                    uint skillVariantIndexToAssign = (uint)i;
                    row.AddButton(ptr.skillDef.icon, ptr.skillDef.skillNameToken, ptr.skillDef.skillDescriptionToken, row.primaryColor, delegate
                    {
                        Loadout loadout = new Loadout();
                        row.userProfile.CopyLoadout(loadout);
                        loadout.bodyLoadoutManager.SetSkillVariant(bodyIndex, skillSlotIndex, skillVariantIndexToAssign);
                        row.userProfile.SetLoadout(loadout);
                    }, ptr.unlockableName, ptr.viewableNode, false);
                }
        internal static void LoadoutPanelControllerRowCtor(On.RoR2.UI.LoadoutPanelController.Row.orig_ctor orig, object selfObject, RoR2.UI.LoadoutPanelController owner, BodyIndex bodyIndex, string titleToken)
        {
            var self = selfObject as RoR2.UI.LoadoutPanelController.Row;

            orig(self, owner, bodyIndex, titleToken);

            //Disabling sorting override because it not work with mask
            var highlightRect = self.choiceHighlightRect;

            highlightRect.GetComponent <RefreshCanvasDrawOrder>().enabled = false;
            highlightRect.GetComponent <Canvas>().overrideSorting         = false;

            var buttonContainer = self.buttonContainerTransform;
            var rowPanel        = self.rowPanelTransform;

            var rowHorizontalLayout = rowPanel.gameObject.AddComponent <HorizontalLayoutGroup>();

            var panel     = rowPanel.Find("Panel");
            var slotLabel = rowPanel.Find("SlotLabel");

            var labelContainer = new GameObject("LabelContainer");

            labelContainer.transform.SetParent(rowPanel, false);
            panel.SetParent(labelContainer.transform, false);
            slotLabel.SetParent(labelContainer.transform, false);

            var slotLabelRect = slotLabel.GetComponent <RectTransform>();

            slotLabelRect.anchoredPosition = new Vector2(0, 0);

            var labelContainerLayout = labelContainer.AddComponent <LayoutElement>();

            labelContainerLayout.minHeight       = 0;
            labelContainerLayout.preferredHeight = 96;
            labelContainerLayout.minWidth        = 128;

            var labelContainerRect = labelContainer.GetComponent <RectTransform>();

            labelContainerRect.anchorMin = new Vector2(0, 0);
            labelContainerRect.anchorMax = new Vector2(1, 1);
            labelContainerRect.pivot     = new Vector2(0, 0F);

            var scrollPanel = new GameObject("RowScrollPanel");

            scrollPanel.transform.SetParent(rowPanel, false);

            var scrollViewport = new GameObject("Viewport");

            scrollViewport.transform.SetParent(scrollPanel.transform, false);

            var scrollViewportRectTransform = scrollViewport.AddComponent <RectTransform>();

            scrollViewportRectTransform.pivot     = new Vector2(0.5F, 0.5F);
            scrollViewportRectTransform.anchorMin = new Vector2(0, 0);
            scrollViewportRectTransform.anchorMax = new Vector2(1, 1);
            scrollViewportRectTransform.sizeDelta = new Vector2(0, 0);

            buttonContainer.SetParent(scrollViewport.transform, false);
            highlightRect.SetParent(scrollViewport.transform, false);

            var mask = scrollPanel.AddComponent <RectMask2D>();

            var scrollPanelLayout = scrollPanel.AddComponent <LayoutElement>();

            scrollPanelLayout.preferredWidth = 100000;

            var scrollRect = scrollPanel.AddComponent <ConstrainedScrollRect>();

            scrollRect.horizontal          = true;
            scrollRect.vertical            = false;
            scrollRect.viewport            = scrollViewportRectTransform;
            scrollRect.content             = buttonContainer;
            scrollRect.scrollSensitivity   = -30;
            scrollRect.movementType        = ScrollRect.MovementType.Clamped;
            scrollRect.scrollConstraint    = ConstrainedScrollRect.Constraint.OnlyDrag;
            scrollRect.redirectConstrained = rowPanel.GetComponentInParent <ConstrainedScrollRect>();

            var scrollPanelRectTransform = scrollPanel.GetComponent <RectTransform>();

            scrollPanelRectTransform.pivot     = new Vector2(1, 0.5F);
            scrollPanelRectTransform.anchorMin = new Vector2(0, 0);
            scrollPanelRectTransform.anchorMax = new Vector2(1, 1);

            //Adding ContentSizeFilter, otherwise childs would have been wrong size
            var buttonContainerSizeFilter = buttonContainer.gameObject.AddComponent <ContentSizeFitter>();

            buttonContainerSizeFilter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            buttonContainerSizeFilter.verticalFit   = ContentSizeFitter.FitMode.Unconstrained;

            buttonContainer.pivot = new Vector2(0, 0.5F);

            buttonContainer.Find("Spacer").gameObject.SetActive(false);

            var buttonContainerHorizontalLayout = buttonContainer.GetComponent <HorizontalLayoutGroup>();

            buttonContainerHorizontalLayout.padding = new RectOffset(8, 8, 8, 8);

            var rightButton = SetupButton("Right", scrollPanelRectTransform, MoveDirection.Right, 1);
            var leftButton  = SetupButton("Left", scrollPanelRectTransform, MoveDirection.Left, 0);

            var scrollButtonsController = scrollPanel.AddComponent <ScrollButtonsController>();

            scrollButtonsController.left  = leftButton;
            scrollButtonsController.right = rightButton;

            GameObject SetupButton(string buttonPrefix, Transform parent, MoveDirection moveDirection, float xNormalized)
            {
                var scrollButton = GameObject.Instantiate(Resources.Load <GameObject>($"prefabs/ui/controls/buttons/{buttonPrefix}Button"), parent, false);

                scrollButton.name  = $"{buttonPrefix}ScrollButton";
                scrollButton.layer = 5;


                var hgButton = scrollButton.GetComponent <RoR2.UI.HGButton>();

                var arrowObject = new GameObject("Arrow");

                arrowObject.transform.SetParent(scrollButton.transform, false);

                var arrowObjectRectTransform = arrowObject.AddComponent <RectTransform>();

                arrowObjectRectTransform.pivot     = new Vector2(0.5F, 0.5F);
                arrowObjectRectTransform.anchorMin = new Vector2(0, 0);
                arrowObjectRectTransform.anchorMax = new Vector2(1, 1);
                arrowObjectRectTransform.sizeDelta = new Vector2(-8, 0);

                var targetGraphic = hgButton.targetGraphic as Image;

                var arrowImage = arrowObject.AddComponent <Image>();

                arrowImage.sprite = targetGraphic.sprite;

                GameObject.DestroyImmediate(hgButton.targetGraphic);
                var translucentImage = scrollButton.AddComponent <TranslucentImage>();

                translucentImage.material = defaultTranslucentMaterial;
                translucentImage.color    = Color.black;

                hgButton.targetGraphic = arrowImage;

                var scrollOnPress = scrollButton.AddComponent <ContinuousScrollOnPress>();

                scrollOnPress.scrollRect    = scrollRect;
                scrollOnPress.sensitivity   = -400;
                scrollOnPress.moveDirection = moveDirection;

                GameObject.DestroyImmediate(scrollButton.GetComponent <LayoutElement>());

                var rectTransform = scrollButton.GetComponent <RectTransform>();

                rectTransform.anchorMin = new Vector2(xNormalized, 0F);
                rectTransform.anchorMax = new Vector2(xNormalized, 1F);
                rectTransform.pivot     = new Vector2(xNormalized, 0.5F);
                rectTransform.sizeDelta = new Vector2(24, 0);

                scrollButton.SetActive(false);

                return(scrollButton);
            }
        }
        internal static void LoadoutPanelControllerAwake(On.RoR2.UI.LoadoutPanelController.orig_Awake orig, RoR2.UI.LoadoutPanelController self)
        {
            orig(self);

            var uiLayerKey = self.GetComponentInParent <RoR2.UI.UILayerKey>();

            //Disabling buttons navigation if selected right panel,
            //so extremely long rows in loadout will not interfere in artifacts selection
            var loadoutHelper = uiLayerKey.gameObject.AddComponent <ButtonsNavigationController>();

            loadoutHelper.requiredTopLayer = uiLayerKey;
            loadoutHelper.loadoutPanel     = self;

            //Adding container on top of LoadoutPanelController
            var loadoutScrollPanel = AddScrollPanel(self.transform, "LoadoutScrollPanel");
            //Adding container on top of SkillPanel
            var skillScrollPanel = AddScrollPanel(self.transform.parent.parent.Find("SkillPanel"), "SkillsScrollPanel");

            //Adding container on top of OverviewPanel
            var overviewPanel       = self.transform.parent.parent.Find("OverviewPanel");
            var overviewScrollPanel = AddScrollPanel(overviewPanel, "OverviewScrollPanel");
            var overviewLayoutGroup = overviewPanel.gameObject.AddComponent <VerticalLayoutGroup>();

            overviewLayoutGroup.childControlHeight     = true;
            overviewLayoutGroup.childControlWidth      = true;
            overviewLayoutGroup.childForceExpandHeight = true;
            overviewLayoutGroup.childForceExpandWidth  = true;

            var overviewScrollHelper = overviewScrollPanel.AddComponent <GamepadScrollRectHelper>();

            overviewScrollHelper.requiredTopLayer = uiLayerKey;

            var survivorDescriptionPanel = self.transform.parent.parent.parent.parent.Find("SurvivorInfoPanel, Inactive/DescriptionPanel, Naked");

            survivorDescriptionPanel.gameObject.AddComponent <RectMask2D>();

            //Moving out descriptionPanel, so it will not be hidden by mask
            MoveUpDescription("DescriptionPanel, Loadout", "LoadoutScrollContainer", loadoutScrollPanel);
            MoveUpDescription("DescriptionPanel, Skill", "SkillScrollContainer", skillScrollPanel);

            GameObject AddScrollPanel(Transform panel, string name)
            {
                var scrollPanel = new GameObject(name);

                scrollPanel.layer = 5;
                scrollPanel.transform.SetParent(panel.transform.parent, false);
                panel.transform.SetParent(scrollPanel.transform, false);

                scrollPanel.AddComponent <RoR2.UI.MPEventSystemLocator>();

                var scrollPanelMask = scrollPanel.AddComponent <RectMask2D>();

                var scrollPanelRect = scrollPanel.AddComponent <ConstrainedScrollRect>();

                scrollPanelRect.horizontal        = false;
                scrollPanelRect.content           = panel.GetComponent <RectTransform>();
                scrollPanelRect.scrollSensitivity = 30;
                scrollPanelRect.movementType      = ScrollRect.MovementType.Clamped;
                scrollPanelRect.scrollConstraint  = ConstrainedScrollRect.Constraint.OnlyScroll;

                //Adding ContentSizeFilter, otherwise childs would have been wrong size
                var panelContentSizeFilter = panel.gameObject.AddComponent <ContentSizeFitter>();

                panelContentSizeFilter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
                panelContentSizeFilter.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;

                var scrollPanelRectTransform = scrollPanelRect.GetComponent <RectTransform>();

                scrollPanelRectTransform.pivot     = new Vector2(0.5F, 1F);
                scrollPanelRectTransform.anchorMin = new Vector2(0, 0);
                scrollPanelRectTransform.anchorMax = new Vector2(1, 1);
                scrollPanelRectTransform.sizeDelta = new Vector2(0, 0);

                panel.GetComponent <RectTransform>().pivot = new Vector2(0.5F, 1);

                //Enabling Image component, so you can scroll from any point in panel
                var panelImage = panel.GetComponent <Image>();

                if (!panelImage)
                {
                    panelImage = panel.gameObject.AddComponent <Image>();
                }
                panelImage.enabled       = true;
                panelImage.color         = new Color(0, 0, 0, 0);
                panelImage.raycastTarget = true;

                return(scrollPanel);
            }

            void MoveUpDescription(string descriptionPanelName, string parentName, GameObject panel)
            {
                var descriptionPanel = panel.transform.GetChild(0).Find(descriptionPanelName);

                var parentScrollContainer = new GameObject(parentName);

                parentScrollContainer.transform.SetParent(panel.transform.parent, false);
                panel.transform.SetParent(parentScrollContainer.transform, false);
                descriptionPanel.SetParent(parentScrollContainer.transform, false);

                var rect = parentScrollContainer.AddComponent <RectTransform>();

                rect.anchorMin = new Vector2(0, 0);
                rect.anchorMax = new Vector2(1, 1);
                rect.pivot     = new Vector2(0.5F, 1);
                rect.sizeDelta = new Vector2(0, 0);

                var clearTextOnDisable = panel.transform.GetChild(0).gameObject.AddComponent <ClearTextOnDisable>();

                clearTextOnDisable.textObjects = new List <TextMeshProUGUI> {
                    descriptionPanel.GetComponent <RoR2.UI.DisableIfTextIsEmpty>().tmpUGUI
                };
            }
        }
 internal static void LoadoutPanelControllerOnDestroy(On.RoR2.UI.LoadoutPanelController.orig_OnDestroy orig, RoR2.UI.LoadoutPanelController self)
 {
     orig(self);
     buttonsWithListeners.Clear();
 }