Esempio n. 1
0
            static public GameObject CreatePanelSize(Transform givenParent)
            {
                List <Image> images = new List <Image>();

                ElementCreator.SpawnImageSize(images, givenParent.gameObject, Resources.panelTextures[7], new Color(0.357f, 0.373f, 0.471f, 1), new Vector2(0, 1), new Vector2(100, 100), new Vector3(0, 0, 0));
                Image background = ElementCreator.SpawnImageOffset(new List <Image>(), images[0].gameObject, null, new Color(0, 0, 0, 0.8f), new Vector2(0, 1), new Vector2(UIConfig.panelPadding, UIConfig.panelPadding), new Vector2(-UIConfig.panelPadding, -UIConfig.panelPadding));

                background.gameObject.AddComponent <RectMask2D>();
                return(images[0].gameObject);
            }
Esempio n. 2
0
            static public RectTransform SpawnItemButton(GameObject root, int textCount, int givenID, Dictionary <int, List <Image> > images, Dictionary <int, List <TMPro.TextMeshProUGUI> > texts, bool isFallback = false)
            {
                images.Add(givenID, new List <Image>());
                texts.Add(givenID, new List <TMPro.TextMeshProUGUI>());

                ColorBlock colourBlockA = new ColorBlock();

                colourBlockA.colorMultiplier  = 1;
                colourBlockA.disabledColor    = new Color(0, 0, 0, 0);
                colourBlockA.highlightedColor = new Color(0, 0, 0, 0);
                colourBlockA.normalColor      = new Color(0, 0, 0, 0);
                colourBlockA.pressedColor     = new Color(0, 0, 0, 0);

                Vector2 size = new Vector2();

                size.x = UIConfig.itemButtonWidth + UIConfig.itemPaddingOuter * 2;
                size.y = UIConfig.itemButtonWidth + textCount * UIConfig.itemTextHeight + UIConfig.itemPaddingOuter * 2;
                GameObject item   = ElementCreator.SpawnButtonSize(root, null, colourBlockA, new Vector2(0, 1), size, isFallback);
                GameObject scaler = ElementCreator.SpawnImageOffset(new List <Image>(), item, null, new Color(0, 0, 0, 0), new Vector2(0, 1), new Vector2(UIConfig.itemPaddingOuter, UIConfig.itemPaddingOuter), new Vector2(-UIConfig.itemPaddingOuter, -UIConfig.itemPaddingOuter)).gameObject;

                ElementCreator.SpawnImageOffset(new List <Image>(), scaler, Resources.panelTextures[1], new Color(0.286f, 0.286f, 0.286f, 1), new Vector2(0, 1), new Vector2(-2, textCount * UIConfig.itemTextHeight - 2), new Vector2(2, 2));
                for (int textIndex = 0; textIndex < textCount; textIndex++)
                {
                    ElementCreator.SpawnImageOffset(new List <Image>(), scaler, Resources.panelTextures[1], new Color(0.286f, 0.286f, 0.286f, 1), new Vector2(0, 1), new Vector2(-2, textIndex * UIConfig.itemTextHeight - 2), new Vector2(2, -UIConfig.itemButtonWidth - (textCount - 1 - textIndex) * UIConfig.itemTextHeight + UIConfig.itemPaddingInner + 2));
                    ElementCreator.SpawnImageOffset(new List <Image>(), scaler, Resources.panelTextures[0], new Color(0.120f, 0.120f, 0.120f, 1), new Vector2(0, 1), new Vector2(-2, textIndex * UIConfig.itemTextHeight - 2), new Vector2(2, -UIConfig.itemButtonWidth - (textCount - 1 - textIndex) * UIConfig.itemTextHeight + UIConfig.itemPaddingInner + 2));
                }

                ElementCreator.SpawnImageOffset(images[givenID], scaler, Resources.tierTextures[Data.GetItemTier(givenID)], new Color(1, 1, 1), new Vector2(0, 1), new Vector2(UIConfig.itemPaddingInner, textCount * UIConfig.itemTextHeight + UIConfig.itemPaddingInner), new Vector2(-UIConfig.itemPaddingInner, -UIConfig.itemPaddingInner));
                Sprite itemImage = null;

                if (Data.allItemIDs.ContainsKey(givenID))
                {
                    itemImage = RoR2.ItemCatalog.GetItemDef(Data.allItemIDs[givenID]).pickupIconSprite;
                }
                else if (Data.allEquipmentIDs.ContainsKey(givenID))
                {
                    itemImage = RoR2.EquipmentCatalog.GetEquipmentDef(Data.allEquipmentIDs[givenID]).pickupIconSprite;
                }
                ElementCreator.SpawnImageOffset(images[givenID], scaler, itemImage, new Color(1, 1, 1), new Vector2(0, 1), new Vector2(UIConfig.itemPaddingInner, textCount * UIConfig.itemTextHeight + UIConfig.itemPaddingInner), new Vector2(-UIConfig.itemPaddingInner, -UIConfig.itemPaddingInner));

                ElementCreator.SpawnImageOffset(images[givenID], scaler, Resources.panelTextures[1], new Color(0.988f, 1.000f, 0.693f, 0.733f), new Vector2(0.5f, 0), new Vector2(1, textCount * UIConfig.itemTextHeight + 1), new Vector2(-1, -1));
                ElementCreator.SpawnImageSize(images[givenID], images[givenID][images[givenID].Count - 1].gameObject, Resources.panelTextures[6], new Color(0.988f, 1.000f, 0.693f, 0.733f), new Vector2(0.5f, 0.5f), new Vector2(20, 20), new Vector3(0, 3, 0));

                for (int textIndex = 0; textIndex < textCount; textIndex++)
                {
                    ElementCreator.SpawnTextOffset(texts[givenID], scaler, new Color(1, 1, 1), 24, 1, new Vector2(UIConfig.itemPaddingInner, textIndex * UIConfig.itemTextHeight + UIConfig.itemPaddingInner), new Vector2(-UIConfig.itemPaddingInner, -UIConfig.itemButtonWidth - (textCount - 1 - textIndex) * UIConfig.itemTextHeight - UIConfig.itemPaddingInner));
                    texts[givenID][texts[givenID].Count - 1].text = "";
                }

                ColorBlock colourBlockB = new ColorBlock();

                colourBlockB.colorMultiplier  = 1;
                colourBlockB.disabledColor    = new Color(1, 1, 1, 1);
                colourBlockB.highlightedColor = new Color(1, 1, 1, 1);
                colourBlockB.normalColor      = new Color(1, 1, 1, 1);
                colourBlockB.pressedColor     = new Color(0.8f, 0.8f, 0.8f, 1);

                /*
                 * GameObject highlight = ElementCreator.SpawnButtonOffset(item, Resources.resources.panelTextures[5], colourBlockB);
                 * highlight.GetComponent<RoR2.UI.HGButton>().showImageOnHover = false;
                 * RectTransform highlightTransform = highlight.GetComponent<RectTransform>();
                 * highlightTransform.offsetMin = new Vector2(-5, -5);
                 * highlightTransform.offsetMax = new Vector2(5, 5);
                 * item.GetComponent<RoR2.UI.HGButton>().imageOnHover = highlight.GetComponent<Image>();
                 */

                Image highlight = ElementCreator.SpawnImageOffset(new List <Image>(), scaler, Resources.panelTextures[5], new Color(1, 1, 1, 1), new Vector2(0.5f, 0.5f), new Vector2(-5, -5), new Vector2(5, 5));

                item.GetComponent <RoR2.UI.HGButton>().imageOnHover = highlight.GetComponent <Image>();

                RoR2.UI.TooltipProvider tooltipProvider = item.AddComponent <RoR2.UI.TooltipProvider>();
                tooltipProvider.titleColor = Resources.colours[Data.GetItemTier(givenID)];
                tooltipProvider.bodyColor  = Resources.colours[6];
                if (Data.allItemIDs.ContainsKey(givenID))
                {
                    tooltipProvider.titleToken = RoR2.ItemCatalog.GetItemDef(Data.allItemIDs[givenID]).nameToken;
                    tooltipProvider.bodyToken  = RoR2.ItemCatalog.GetItemDef(Data.allItemIDs[givenID]).descriptionToken;
                }
                else if (Data.allEquipmentIDs.ContainsKey(givenID))
                {
                    tooltipProvider.titleToken = RoR2.EquipmentCatalog.GetEquipmentDef(Data.allEquipmentIDs[givenID]).nameToken;
                    tooltipProvider.bodyToken  = RoR2.EquipmentCatalog.GetEquipmentDef(Data.allEquipmentIDs[givenID]).descriptionToken;
                }

                PointerClick pointerClick = item.AddComponent <PointerClick>();

                pointerClick.eventSystem = item.GetComponent <RoR2.UI.MPEventSystemLocator>().eventSystem;
                pointerClick.onLeftClick.AddListener(() => {
                    Data.LeftClick(givenID);
                });
                pointerClick.onRightClick.AddListener(() => {
                    Data.RightClick(givenID);
                });
                return(item.GetComponent <RectTransform>());
            }
            static public GameObject CreateScroll(RectTransform rootTransform, int rows, int textCount, List <int> items, float width, Vector3 position, Dictionary <int, List <Image> > images, Dictionary <int, List <TMPro.TextMeshProUGUI> > texts)
            {
                Vector2 size = new Vector2();

                size.x = width;
                size.y = (UIConfig.itemButtonWidth + textCount * UIConfig.itemTextHeight + UIConfig.itemPaddingOuter * 2) * rows + UIConfig.scrollPadding * 2 + UIConfig.panelPadding * 2;
                GameObject itemsScroll = ElementCreator.SpawnImageSize(new List <Image>(), rootTransform.gameObject, null, new Color(0, 0, 0, 0), new Vector2(0, 1), size, position);

                itemsScroll.name = "Scroll";
                ScrollRect itemsScrollScroll = itemsScroll.AddComponent <ScrollRect>();

                itemsScrollScroll.horizontal          = true;
                itemsScrollScroll.vertical            = false;
                itemsScrollScroll.horizontalScrollbar = null;
                itemsScrollScroll.verticalScrollbar   = null;
                itemsScrollScroll.movementType        = ScrollRect.MovementType.Clamped;
                itemsScrollScroll.inertia             = false;
                itemsScrollScroll.scrollSensitivity   = 50;
                itemsScroll.AddComponent <RoR2.UI.MPEventSystemLocator>();
                itemsScroll.AddComponent <RoR2.UI.ScrollToSelection>();

                GameObject scrollbar = new GameObject("Scroll Bar");

                scrollbar.transform.parent = itemsScroll.transform;
                CanvasGroup canvasGroup = scrollbar.AddComponent <CanvasGroup>();

                canvasGroup.blocksRaycasts = false;
                canvasGroup.interactable   = false;
                scrollbar.AddComponent <RoR2.UI.MPEventSystemLocator>();
                RoR2.UI.MPScrollbar scrollbarScrollbar = scrollbar.AddComponent <RoR2.UI.MPScrollbar>();
                scrollbarScrollbar.direction          = Scrollbar.Direction.LeftToRight;
                itemsScrollScroll.horizontalScrollbar = scrollbarScrollbar;

                GameObject panel = PanelCreator.CreatePanel(itemsScroll.transform);

                itemsScrollScroll.viewport = panel.transform.GetChild(0).GetComponent <RectTransform>();

                Image itemsContentImage = ElementCreator.SpawnImageOffset(new List <Image>(), panel.transform.GetChild(0).gameObject, null, new Color(0, 0, 0, 0), new Vector2(0, 1), new Vector2(0, 0), new Vector2(0, 0));

                itemsContentImage.raycastTarget = true;
                GameObject itemsContent = itemsContentImage.gameObject;

                RectTransform itemsContentTransform = itemsContentImage.GetComponent <RectTransform>();
                int           itemsPerRow           = Mathf.CeilToInt(items.Count * 1f / rows);
                int           itemsInBottomRow      = items.Count - itemsPerRow * (rows - 1);

                itemsContentTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Max(UIConfig.scrollPadding * 2 + (UIConfig.itemButtonWidth + UIConfig.itemPaddingOuter * 2) * itemsPerRow, itemsScrollScroll.viewport.rect.width));

                List <RectTransform> itemButtons = new List <RectTransform>();

                for (int index = 0; index < items.Count; index++)
                {
                    itemButtons.Add(ButtonCreator.SpawnItemButton(itemsContent, textCount, items[index], images, texts));
                }

                itemsScrollScroll.content = itemsContentTransform;
                itemsScrollScroll.horizontalNormalizedPosition = 0.5f;

                for (int row = 0; row < rows; row++)
                {
                    for (int collumn = 0; collumn < itemsPerRow; collumn++)
                    {
                        if (row * itemsPerRow + collumn < itemButtons.Count)
                        {
                            float offset = (itemsContentTransform.rect.width - UIConfig.scrollPadding * 2 - (UIConfig.itemButtonWidth + UIConfig.itemPaddingOuter * 2) * itemsPerRow) / 2f;
                            if (row == rows - 1)
                            {
                                offset += (itemsPerRow - itemsInBottomRow) * (UIConfig.itemButtonWidth + UIConfig.itemPaddingOuter * 2) / 2f;
                            }
                            itemButtons[row * itemsPerRow + collumn].localPosition = new Vector3(UIConfig.scrollPadding + collumn * (UIConfig.itemButtonWidth + UIConfig.itemPaddingOuter * 2) + offset, -UIConfig.scrollPadding - row * (UIConfig.itemButtonWidth + textCount * UIConfig.itemTextHeight + UIConfig.itemPaddingOuter * 2), 0);
                        }
                    }
                }

                return(itemsScroll);
            }