예제 #1
0
        public void UpdateHook(On.RoR2.UI.SkillIcon.orig_Update orig, SkillIcon self)
        {
            orig.Invoke(self);

            if (self.targetSkill && self.targetSkillSlot == SkillSlot.Primary)
            {
                if (self.targetSkill.characterBody.baseNameToken == "BANDIT2_BODY_NAME")
                {
                    if (!modeLabel)
                    {
                        var pos = self.stockText.transform.position;

                        modeLabel = CreateLabel(
                            self.stockText.transform.parent,
                            "ModeLabel",
                            fireMode.ToString(),
                            new Vector2(pos.x - 7.5f, pos.y + 20f)
                            );

                        modeLabel.transform.rotation = self.stockText.transform.rotation;
                        modeLabel.color     = self.stockText.color;
                        modeLabel.alignment = self.stockText.alignment;
                    }

                    modeLabel.SetText(fireMode.ToString());
                }
            }
        }
예제 #2
0
        private HGTextMeshProUGUI CreateLabel(Transform parent, String name, String text, Vector2 position)
        {
            GameObject textContainer = new GameObject(name);

            textContainer.transform.parent = parent;

            textContainer.AddComponent <CanvasRenderer>();

            RectTransform     rectTransform     = textContainer.AddComponent <RectTransform>();
            HGTextMeshProUGUI hgtextMeshProUGUI = textContainer.AddComponent <HGTextMeshProUGUI>();

            hgtextMeshProUGUI.text               = text;
            hgtextMeshProUGUI.fontSize           = 12f;
            hgtextMeshProUGUI.color              = Color.white;
            hgtextMeshProUGUI.alignment          = TMPro.TextAlignmentOptions.Center;
            hgtextMeshProUGUI.enableWordWrapping = false;

            rectTransform.localPosition    = Vector2.zero;
            rectTransform.anchorMin        = Vector2.zero;
            rectTransform.anchorMax        = Vector2.one;
            rectTransform.localScale       = Vector3.one;
            rectTransform.sizeDelta        = Vector2.zero;
            rectTransform.anchoredPosition = position;

            return(hgtextMeshProUGUI);
        }
예제 #3
0
        //public bool validateOnSubmit;

        protected override void Awake()
        {
            _previewLanguage       = transform.Find("Text Preview").GetComponentInChildren <LanguageTextMeshController>();
            _previewLanguage.token = $"{settingToken}.VALUE";

            _previewLabel = _previewLanguage.GetComponentInChildren <HGTextMeshProUGUI>();

            nameLabel       = GetComponent <LanguageTextMeshController>();
            nameLabel.token = nameToken;

            base.Awake();

            if (!inputField)
            {
                return;
            }

            var button = transform.Find("Text Preview").GetComponentInChildren <HGButton>();

            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(AttemptShow);
            button.disablePointerClick = false;

            inputField.onSubmit.AddListener(GetInput);
            inputField.onValueChanged.AddListener(OnValueChanged);

            inputField.text = GetCurrentValue();
            _previewLanguage.InvokeMethod("Start");
        }
예제 #4
0
 void Awake()
 {
     this.parent    = RoR2Application.instance.mainCanvas.transform;
     this.compass   = new GameObject(CompassPlugin.Guid + ".compass");
     this.compassUI = this.compass.AddComponent <HGTextMeshProUGUI>();
     this.compassUI.transform.SetParent(this.parent);
 }
예제 #5
0
        internal static void Init()
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            var notifPanel = PrefabAPI.InstantiateClone(Addressables.LoadAssetAsync <GameObject>("RoR2/Base/UI/NotificationPanel2.prefab").WaitForCompletion(), "MysticsRisky2Utils_NotificationPanel", false);

            notifTitleTmp       = notifPanel.transform.Find("CanvasGroup/TextArea/Title").GetComponent <HGTextMeshProUGUI>();
            notifDescriptionTmp = notifPanel.transform.Find("CanvasGroup/TextArea/Description").GetComponent <HGTextMeshProUGUI>();
        }
        private void HideRestartWarning()
        {
            RectTransform modListScrollViewRT = _panel.ModListPanel.transform.Find("Scroll View").GetComponent <RectTransform>();
            RectTransform warningPanelRT      = _panel.WarningPanel.GetComponent <RectTransform>();

            if (_animateRoutine != null)
            {
                StopCoroutine(_animateRoutine);
            }

            HGTextMeshProUGUI warningText = warningPanelRT.GetComponentInChildren <HGTextMeshProUGUI>();

            Color hideColor = new Color(warningText.color.r, warningText.color.b, warningText.color.g, 0f);

            _animateRoutine = AnimateWarningPanel(modListScrollViewRT, new Vector2(0f, 0f), warningPanelRT, new Vector2(1f, 0f), hideColor, degreesPerSecond, -360f);

            StartCoroutine(_animateRoutine);
        }
예제 #7
0
        protected override void Awake()
        {
            base.Awake();
            _eventSystemLocator = GetComponent <MPEventSystemLocator>();

            _label = transform.Find("Label").GetComponent <HGTextMeshProUGUI>();

            _defaultColors = CheckBoxPrefab.GetComponentInChildren <HGButton>().colors;

            _selectedColors                  = _defaultColors;
            _selectedColors.normalColor      = new Color(0.3f, 0.3f, 0.3f, 1);
            _selectedColors.highlightedColor = new Color(0.3f, 0.3f, 0.3f, 1);

            SetupTemplate();

            if (CheckBoxPrefab && !_dropDownChoicePrefab)
            {
                CreatePrefab();
            }
        }
        private void ShowRestartWarning()
        {
            RectTransform modListScrollViewRT = _panel.ModListPanel.transform.Find("Scroll View").GetComponent <RectTransform>();
            RectTransform warningPanelRT      = _panel.WarningPanel.GetComponent <RectTransform>();

            warningPanelRT.gameObject.SetActive(true);

            warningPanelRT.GetComponentInChildren <HGTextMeshProUGUI>().SetText($"Restart Required!");

            if (_animateRoutine != null)
            {
                StopCoroutine(_animateRoutine);
            }

            HGTextMeshProUGUI warningText = warningPanelRT.GetComponentInChildren <HGTextMeshProUGUI>();

            Color showColor = new Color(warningText.color.r, warningText.color.b, warningText.color.g);

            _animateRoutine = AnimateWarningPanel(modListScrollViewRT, new Vector2(0f, 0.074f), warningPanelRT, new Vector2(1f, 0.08f), showColor, degreesPerSecond, 720f);

            StartCoroutine(_animateRoutine);
        }
        private void CreateNumberLabel(Transform parent, ItemIndex itemIndex, int count)
        {
            string textContainerName = $"TextContainer_{(int)itemIndex}";

            Transform old = parent.Find(textContainerName);

            if (old != null)
            {
                Destroy(old.gameObject);
            }

            if (!Display0.Value && count == 0)
            {
                return;
            }

            GameObject textContainer = new GameObject(textContainerName);

            textContainer.transform.parent = parent;

            textContainer.AddComponent <CanvasRenderer>();

            RectTransform     rectTransform     = textContainer.AddComponent <RectTransform>();
            HGTextMeshProUGUI hgtextMeshProUGUI = textContainer.AddComponent <HGTextMeshProUGUI>();

            hgtextMeshProUGUI.text               = (DisplayX.Value ? "x" : "") + count;
            hgtextMeshProUGUI.fontSize           = GetSize();
            hgtextMeshProUGUI.color              = Color.white;
            hgtextMeshProUGUI.alignment          = GetAlignment();
            hgtextMeshProUGUI.enableWordWrapping = false;

            rectTransform.localPosition    = Vector2.zero;
            rectTransform.anchorMin        = Vector2.zero;
            rectTransform.anchorMax        = Vector2.one;
            rectTransform.localScale       = Vector3.one;
            rectTransform.sizeDelta        = Vector2.zero;
            rectTransform.anchoredPosition = GetPosition();
        }
예제 #10
0
        public void SetChoice(int index)
        {
            bool cacheIsValid = _buttonCache != null && _buttonCache.Length != 0;

            if (cacheIsValid)
            {
                _buttonCache[_currentIndex].GetComponentInChildren <HGButton>().colors = _defaultColors;
            }


            _currentIndex = index;

            if (!_label)
            {
                _label = transform.Find("Label").GetComponent <HGTextMeshProUGUI>();
            }

            _label.SetText(choices[_currentIndex]);

            if (cacheIsValid)
            {
                _buttonCache[_currentIndex].GetComponentInChildren <HGButton>().colors = _selectedColors;
            }
        }
예제 #11
0
        public void PickupPickerPanel_OnCreateButton(On.RoR2.UI.PickupPickerPanel.orig_OnCreateButton orig, RoR2.UI.PickupPickerPanel self, int index, MPButton button)
        {
            orig(self, optionMap[0] >= 0 ? optionMap[index] : index, button);

            if (mod.config.CommandTooltipsShow.Value || mod.config.CommandCountersShow.Value)
            {
                CharacterMaster master    = LocalUserManager.GetFirstLocalUser().cachedMasterController.master;
                PickupDef       pickupDef = PickupCatalog.GetPickupDef(self.pickerController.options[optionMap[0] >= 0 ? optionMap[index] : index].pickupIndex);

                if (pickupDef.itemIndex != ItemIndex.None && mod.config.CommandCountersShow.Value)
                {
                    int count = master.inventory.itemStacks[(int)pickupDef.itemIndex];
                    if (!mod.config.CommandCountersHideOnZero.Value || count > 0)
                    {
                        GameObject textGameObject = new GameObject("StackText");
                        textGameObject.transform.SetParent(button.transform);
                        textGameObject.layer = 5;

                        RectTransform counterRect = textGameObject.AddComponent <RectTransform>();

                        HGTextMeshProUGUI counterText = textGameObject.AddComponent <HGTextMeshProUGUI>();
                        counterText.enableWordWrapping = false;
                        counterText.alignment          = mod.config.CommandCountersTextAlignmentOption;
                        counterText.fontSize           = mod.config.CommandCountersFontSize.Value;
                        counterText.faceColor          = Color.white;
                        counterText.outlineWidth       = 0.2f;
                        counterText.text = mod.config.CommandCountersPrefix.Value + count;

                        counterRect.localPosition    = Vector3.zero;
                        counterRect.anchorMin        = Vector2.zero;
                        counterRect.anchorMax        = Vector2.one;
                        counterRect.localScale       = Vector3.one;
                        counterRect.sizeDelta        = new Vector2(-10, -4);
                        counterRect.anchoredPosition = Vector2.zero;
                    }
                }

                if (mod.config.CommandTooltipsShow.Value)
                {
                    TooltipProvider tooltipProvider = button.gameObject.AddComponent <TooltipProvider>();

                    if (pickupDef.itemIndex != ItemIndex.None)
                    {
                        ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex);

                        if (mod.ItemStatsModIntegration)
                        {
                            int    count    = master.inventory.itemStacks[(int)pickupDef.itemIndex];
                            string bodyText = Language.GetString(itemDef.descriptionToken);
                            if (self.pickerController.contextString == "ARTIFACT_COMMAND_CUBE_INTERACTION_PROMPT" && mod.config.CommandTooltipsItemStatsBeforeAfter.Value && count > 0)
                            {
                                bodyText += String.Format("\n\n<align=left>Before ({0} Stack" + (count > 1 ? "s" : "") + "):", count);
                                String[] descLines = ModCompat.statsFromItemStats(itemDef.itemIndex, count, master).Split(new String[] { "\n", "<br>" }, StringSplitOptions.None);
                                bodyText += String.Join("\n", descLines.Take(descLines.Length - 1).Skip(1));
                                bodyText += String.Format("\n\n<align=left>After ({0} Stacks):", count + 1);
                                descLines = ModCompat.statsFromItemStats(itemDef.itemIndex, count + 1, master).Split(new String[] { "\n", "<br>" }, StringSplitOptions.None);
                                bodyText += String.Join("\n", descLines.Take(descLines.Length - 1).Skip(1));
                            }
                            else
                            {
                                if (self.pickerController.contextString == "ARTIFACT_COMMAND_CUBE_INTERACTION_PROMPT")
                                {
                                    count += 1;
                                }
                                bodyText += ModCompat.statsFromItemStats(itemDef.itemIndex, count, master);
                            }

                            tooltipProvider.overrideBodyText = bodyText;
                        }
                        else
                        {
                            tooltipProvider.bodyToken = itemDef.descriptionToken;
                        }

                        tooltipProvider.titleToken = itemDef.nameToken;
                        tooltipProvider.titleColor = ColorCatalog.GetColor(itemDef.darkColorIndex);;
                        tooltipProvider.bodyColor  = new Color(0.6f, 0.6f, 0.6f, 1f);
                    }
                    else if (pickupDef.equipmentIndex != EquipmentIndex.None)
                    {
                        EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(pickupDef.equipmentIndex);

                        tooltipProvider.titleToken = equipmentDef.nameToken;
                        tooltipProvider.bodyToken  = equipmentDef.descriptionToken;
                        tooltipProvider.titleColor = ColorCatalog.GetColor(equipmentDef.colorIndex);
                        tooltipProvider.bodyColor  = Color.gray;
                    }
                }
            }
        }
예제 #12
0
            //public Transform difficultySection;

            private void RepositionHUD()
            {
                Transform leftHandPanel = characterSelectController.transform.Find("SafeArea/LeftHandPanel (Layer: Main)");

                leftHandPanel.GetComponent <VerticalLayoutGroup>().enabled = false;
                leftHandPanel.Find("BorderImage").gameObject.SetActive(false);
                leftHandPanel.eulerAngles = Vector3.zero;
                Transform survivorChoiceGrid = leftHandPanel.Find("SurvivorChoiceGrid, Panel");

                survivorChoiceGrid.eulerAngles = Vector3.zero;
                survivorChoiceGrid.position    = new Vector3(0f, -45f, 100f);
                Transform survivorInfoPanel = leftHandPanel.Find("SurvivorInfoPanel, Active (Layer: Secondary)");

                survivorInfoPanel.GetComponent <VerticalLayoutGroup>().enabled = false;
                survivorInfoPanel.transform.position = new Vector3(30, 32.14879f, 100);
                Transform survivorNamePanel      = survivorInfoPanel.Find("SurvivorNamePanel");
                Transform survivorNamePanelClone = null;

                if (!theTMP || !hgTMP)
                {
                    survivorNamePanelClone = Instantiate(survivorNamePanel, characterSelectController.transform);
                }
                survivorInfoPanel.Find("ContentPanel (Overview, Skills, Loadout)/SkillScrollContainer/DescriptionPanel, Skill").position =
                    new Vector3(-50, 19.66f, 100);

                if (!theTMP)
                {
                    Transform theText = UnityEngine.Object.Instantiate(survivorNamePanelClone, survivorNamePanel);
                    theText.localPosition = new Vector3(70, 20, 0);
                    theText.name          = "TheText";
                    theTMP      = theText.Find("SurvivorName").GetComponent <HGTextMeshProUGUI>();
                    theTMP.text = "The";
                    theTMP.transform.localPosition = Vector3.zero;
                }

                Transform subheaderPanel = survivorInfoPanel.Find("SubheaderPanel (Overview, Skills, Loadout)");

                subheaderPanel.eulerAngles = new Vector3(0, 0, 270);
                subheaderPanel.position    = new Vector3(100, 27, 100);

                RectTransform rightHandPanel = (RectTransform)characterSelectController.transform.Find("SafeArea/RightHandPanel");

                //rightHandPanel.position = new Vector3(0f, 63f, 100f);
                rightHandPanel.rotation   = Quaternion.identity;
                rightHandPanel.localScale = Vector3.one * 0.8f;
                //rightHandPanel.position = new Vector3(20, -20, 100);
                Transform ruleVerticalLayout = rightHandPanel.Find("RuleVerticalLayout");

                ruleVerticalLayout.position = new Vector3(-75, 20, 100); //new Vector3(0f, 23f, 100f);
                ruleVerticalLayout.Find("BlurPanel").gameObject.SetActive(false);
                ruleVerticalLayout.Find("BorderImage").gameObject.SetActive(false);

                var ruleVerticalLayoutVertical = ruleVerticalLayout.Find("RuleBookViewerVertical");

                ruleVerticalLayoutVertical.GetComponent <Image>().enabled = false;
                //var difficultySection = ruleVerticalLayoutVertical.Find("Viewport/Content/RulebookCategoryPrefab(Clone)");
                //difficultySection.Find("/Header").gameObject.SetActive(false);
                ruleVerticalLayoutVertical.Find("Viewport/Content/RulebookCategoryPrefab(Clone)/Header").gameObject.SetActive(false);
                //difficultySection.parent = difficultySection.parent.parent; //(needs permanent reference)

                Transform readyPanel = characterSelectController.transform.Find("SafeArea/ReadyPanel");

                readyPanel.position = new Vector3(80, -45, 100);
                if (!hgTMP)
                {
                    Transform teamText = UnityEngine.Object.Instantiate(survivorNamePanelClone, readyPanel.Find("ReadyButton"));
                    teamText.localPosition = new Vector3(-730, 20, 0);
                    teamText.name          = "TeamText";
                    hgTMP = teamText.Find("SurvivorName").GetComponent <HGTextMeshProUGUI>();
                }

                var survivorTMP = survivorNamePanel.Find("SurvivorName").GetComponent <HGTextMeshProUGUI>();

                survivorTMP.transform.localScale = Vector3.one * 2f;

                Transform chatBox = characterSelectController.transform.Find("SafeArea/ChatboxPanel");

                chatBox.localPosition = new Vector3(-700, 305, 0);

                if (!compat_LobbyAppearanceImprovements)
                {
                    leftHandPanel.Find("BlurPanel").gameObject.SetActive(false);
                }

                if (survivorNamePanelClone)
                {
                    Destroy(survivorNamePanelClone.gameObject);
                }
            }
예제 #13
0
        public SaveButton(string name, SaveData save) : base(name)
        {
            if (save == null)
            {
                throw new Exception($"Error loading save data for savegame '{name}'");
            }
            this.name = name;
            this.time = save.time;

            container = new GameObject("Container");
            container.AddComponent <RectTransform>().localScale = Vector3.one;
            container.AddComponent <HorizontalLayoutGroup>().childForceExpandWidth = false;
            container.AddComponent <LayoutElement>();

            gameObject.transform.SetParent(container.transform);
            gameObject.GetComponent <LayoutElement>().flexibleWidth = 1.0f;

            GameObject timeTextObject = new GameObject("Time Text");

            timeTextObject.transform.SetParent(gameObject.transform);
            GameObject statTextObject = new GameObject("Game Stats");

            statTextObject.transform.SetParent(gameObject.transform);

            // Position the time in the top right with a slight offset
            RectTransform timeRect = timeTextObject.AddComponent <RectTransform>();

            timeRect.anchorMin        = new Vector2(0, 1);
            timeRect.anchorMax        = new Vector2(0, 1);
            timeRect.pivot            = new Vector2(0, 1);
            timeRect.anchoredPosition = new Vector2(10, -10);

            //Position stats in the top right
            RectTransform statRect = statTextObject.AddComponent <RectTransform>();

            statRect.anchorMin        = new Vector2(1, 1);
            statRect.anchorMax        = new Vector2(1, 1);
            statRect.pivot            = new Vector2(1, 1);
            statRect.anchoredPosition = new Vector2(-10, -10);

            string date = DateTimeOffset.FromUnixTimeMilliseconds(time).Add(TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow)).ToString();

            // Format the time text and align it properly
            HGTextMeshProUGUI timeText = timeTextObject.AddComponent <HGTextMeshProUGUI>();

            timeText.text  = "Created\n" + date.Substring(0, date.IndexOfAny(new char[] { '+', '-' }));
            timeText.color = Color.white;
            timeText.enableWordWrapping = false;
            timeText.alignment          = TextAlignmentOptions.TopLeft;
            timeText.fontSize           = 22;

            HGTextMeshProUGUI statText = statTextObject.AddComponent <HGTextMeshProUGUI>();

            statText.text = $"{save.run.stageClearCount} stages cleared\n" +
                            $"{difficulties[save.run.difficulty]} difficulty\n" +
                            $"{TimeSpan.FromSeconds(save.run.fixedTime).ToString("mm':'ss")} time\n" +
                            $"{SavedGames.levelNames[save.run.sceneName] ?? save.run.sceneName}";
            statText.color = Color.white;
            statText.enableWordWrapping = false;
            statText.alignment          = TextAlignmentOptions.TopRight;
            statText.fontSize           = 22;

            if (File.Exists($"{SavedGames.directory}{name}.png"))
            {
                GameObject screenshot = new GameObject("Screenshot");
                screenshot.transform.SetParent(container.transform);
                screenshot.AddComponent <LayoutElement>().preferredWidth = 355;
                screenshot.GetComponent <LayoutElement>().flexibleWidth  = 0;
                screenshot.transform.SetAsFirstSibling();

                Texture2D image = new Texture2D(2, 2);
                image.LoadImage(File.ReadAllBytes($"{SavedGames.directory}{name}.png"));

                screenshot.AddComponent <Image>().sprite = Sprite.Create(image, new Rect(0, 0, image.width, image.height), new Vector2(0, 0));
            }

            ModButton deleteButton = new ModButton("Delete");

            deleteButton.gameObject.transform.SetParent(container.transform);
            deleteButton.gameObject.GetComponent <LayoutElement>().preferredWidth = 200;
            deleteButton.gameObject.GetComponent <LayoutElement>().flexibleWidth  = 0;
            deleteButton.gameObject.transform.SetAsLastSibling();

            deleteButton.customButtonTransition.onClick.AddListener(() => {
                SimpleDialogBox box       = SimpleDialogBox.Create();
                box.headerLabel.text      = "Delete save '" + name + "'";
                box.descriptionLabel.text = "Once you delete this save, the run will no longer be recoverable. Are you sure?";
                box.AddActionButton(() => {
                    File.Delete($"{SavedGames.directory}{name}.json");
                    UnityEngine.Object.Destroy(container.gameObject);
                    SavedGames.saveButtons.Remove(this);
                }, "Delete");
                box.AddCancelButton("Cancel");
            });

            GameObject iconContainer = new GameObject("Icon container");

            iconContainer.transform.SetParent(gameObject.transform);
            RectTransform iconContainerRect = iconContainer.AddComponent <RectTransform>();

            iconContainerRect.anchorMin        = new Vector2(0, 0);
            iconContainerRect.anchorMax        = new Vector2(1, 0);
            iconContainerRect.pivot            = new Vector2(0, 0);
            iconContainerRect.anchoredPosition = new Vector2(10, 3);
            iconContainer.AddComponent <HorizontalLayoutGroup>().childForceExpandWidth = false;

            foreach (PlayerData pd in save.players)
            {
                GameObject bodyPrefab = BodyCatalog.FindBodyPrefab(pd.characterBodyName);
                Texture    texture    = bodyPrefab.GetComponent <CharacterBody>().portraitIcon;

                GameObject icon = new GameObject("Icon");
                icon.transform.SetParent(iconContainer.transform);
                icon.AddComponent <RectTransform>().anchorMin = new Vector2(0, 0);
                icon.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0);
                icon.GetComponent <RectTransform>().pivot     = new Vector2(0, 0);
                icon.AddComponent <RawImage>().texture        = texture;
                icon.GetComponent <RawImage>().gameObject.AddComponent <AspectRatioFitter>().aspectMode  = AspectRatioFitter.AspectMode.WidthControlsHeight;
                icon.GetComponent <RawImage>().gameObject.GetComponent <AspectRatioFitter>().aspectRatio = 1;
                icon.AddComponent <LayoutElement>().flexibleWidth  = 0;
                icon.GetComponent <LayoutElement>().preferredWidth = 60;
            }

            // Modify colors to make the button look more like a button you shouldn't press unless you're sure
            ColorBlock colors = deleteButton.gameObject.GetComponent <CustomButtonTransition>().colors;

            colors.normalColor      = new Color32(244, 67, 54, 255);
            colors.highlightedColor = new Color32(239, 83, 80, 187);
            colors.pressedColor     = new Color32(211, 47, 47, 255);
            deleteButton.gameObject.GetComponent <CustomButtonTransition>().colors = colors;
        }
예제 #14
0
        public void Start()
        {
            BarInstances.Add(player, this);

            container = new GameObject("container");
            container.transform.SetParent(gameObject.transform);

            RectTransform containerRect = container.AddComponent <RectTransform>();

            containerRect.sizeDelta = new Vector2(300, 22);
            containerRect.anchorMin = new Vector2(0, 0);
            containerRect.anchorMax = new Vector2(1, 1);
            containerRect.pivot     = new Vector2(0, 0);
            LayoutElement containerLayout = container.AddComponent <LayoutElement>();

            containerLayout.preferredWidth  = 300;
            containerLayout.preferredHeight = 22;
            VerticalLayoutGroup containerGroup = container.AddComponent <VerticalLayoutGroup>();

            containerGroup.childControlWidth      = true;
            containerGroup.childForceExpandWidth  = false;
            containerGroup.childControlHeight     = true;
            containerGroup.childForceExpandHeight = false;

            bar = new GameObject("bar");
            bar.transform.SetParent(container.transform);
            RectTransform barRect = bar.AddComponent <RectTransform>();

            barRect.anchorMin = new Vector2(0, 0);
            barRect.anchorMax = new Vector2(1, 1);
            barRect.pivot     = new Vector2(0, 0);
            barRect.sizeDelta = new Vector2(300, 22);
            Image barImage = bar.AddComponent <Image>();

            barImage.sprite     = Resources.Load <GameObject>("Prefabs/UI/Tooltip").GetComponentInChildren <TranslucentImage>(true).sprite;
            barImage.color      = colors[new System.Random().Next(colors.Count)];
            barImage.type       = Image.Type.Sliced;
            barImage.fillCenter = true;
            LayoutElement barLayout = bar.AddComponent <LayoutElement>();

            barLayout.preferredWidth  = 300;
            barLayout.preferredHeight = 22;

            nameTextObject = new GameObject("name");
            nameTextObject.transform.SetParent(container.transform);
            RectTransform nameRect = nameTextObject.AddComponent <RectTransform>();

            nameRect.anchorMin = new Vector2(0, 0);
            nameRect.anchorMax = new Vector2(1, 1);
            nameRect.pivot     = new Vector2(0, 0.5f);
            HGTextMeshProUGUI nameMesh = nameTextObject.AddComponent <HGTextMeshProUGUI>();

            nameMesh.fontSize     = 16;
            nameMesh.color        = LocalUserManager.GetFirstLocalUser().cachedMasterController.GetDisplayName().Equals(NameText) ? Color.yellow : Color.white;
            nameMesh.outlineWidth = 0.5f;
            nameMesh.text         = player.GetDisplayName();
            nameMesh.alignment    = TMPro.TextAlignmentOptions.MidlineLeft;
            nameMesh.margin       = new Vector4(3, 0, 0, 0);
            nameTextObject.AddComponent <LayoutElement>().ignoreLayout = true;

            valueTextObject = new GameObject("value");
            valueTextObject.transform.SetParent(container.transform);
            RectTransform valueRect = valueTextObject.AddComponent <RectTransform>();

            valueRect.anchorMin = new Vector2(0, 0);
            valueRect.anchorMax = new Vector2(1, 1);
            valueRect.pivot     = new Vector2(1, 0.5f);
            HGTextMeshProUGUI valueMesh = valueTextObject.AddComponent <HGTextMeshProUGUI>();

            valueMesh.fontSize  = 16;
            valueMesh.color     = Color.white;
            valueMesh.text      = ValueText;
            valueMesh.alignment = TMPro.TextAlignmentOptions.MidlineRight;
            valueMesh.margin    = new Vector4(0, 0, 3, 0);
            valueTextObject.AddComponent <LayoutElement>().ignoreLayout = true;

            foreach (TrackingDef def in RoRecount.TrackingDefs)
            {
                BaseTrackingStat stat = container.AddComponent(def.type) as BaseTrackingStat;
                if (!trackers.ContainsKey(stat.type))
                {
                    trackers.Add(stat.type, new List <BaseTrackingStat>());
                }
                trackers[stat.type].Add(stat);
            }
        }
        private IEnumerator AnimateWarningPanel(RectTransform modListTransform, Vector2 newModListPos, RectTransform warningTransform, Vector2 newWarningPos, Color textColor, float angleIncrement, float maxAngleRotation)
        {
            bool animating = true;

            float animSpeed = 2.25f;

            HGTextMeshProUGUI warningText = warningTransform.GetComponentInChildren <HGTextMeshProUGUI>();

            Image restartIcon = warningText.transform.parent.Find("RestartIcon").GetComponent <Image>();

            RectTransform restartRectTransform = restartIcon.GetComponent <RectTransform>();

            float max = Mathf.Abs(maxAngleRotation);

            while (animating)
            {
                //modListTransform.anchorMin = Vector2.Lerp(modListTransform.anchorMin, newModListPos, animSpeed * Time.deltaTime);

                //warningTransform.anchorMax = Vector2.Lerp(warningTransform.anchorMax, newWarningPos, animSpeed * Time.deltaTime);

                modListTransform.anchorMin = ExtensionMethods.SmoothStep(modListTransform.anchorMin, newModListPos, (animSpeed * 5.25f) * Time.deltaTime);

                warningTransform.anchorMax = ExtensionMethods.SmoothStep(warningTransform.anchorMax, newWarningPos, (animSpeed * 5.25f) * Time.deltaTime);

                float angle = Mathf.Clamp(Mathf.Lerp(angleIncrement * Time.deltaTime, max, 1f * Time.deltaTime), 90 * Time.deltaTime, Math.Abs(maxAngleRotation));

                if (angle > 90 * Time.deltaTime)
                {
                    max -= angle;
                }

                restartRectTransform.localRotation *= Quaternion.AngleAxis(maxAngleRotation > 0 ? angle : -angle, Vector3.forward);

                switch (textColor.a)
                {
                case 1f:
                    warningText.color = Color.Lerp(warningText.color, textColor, (animSpeed * 2) * Time.deltaTime);
                    restartIcon.color = Color.Lerp(restartIcon.color, textColor, (animSpeed * 2) * Time.deltaTime);
                    break;

                case 0f:
                    warningText.color = Color.Lerp(warningText.color, textColor, (animSpeed * 4) * Time.deltaTime);
                    restartIcon.color = Color.Lerp(restartIcon.color, textColor, (animSpeed * 4) * Time.deltaTime);
                    break;
                }

                if (ExtensionMethods.CloseEnough(modListTransform.anchorMin, newModListPos) &&
                    ExtensionMethods.CloseEnough(warningTransform.anchorMax, newWarningPos) &&
                    ExtensionMethods.CloseEnough(warningText.color, textColor) &&
                    ExtensionMethods.CloseEnough(restartIcon.color, textColor))
                {
                    modListTransform.anchorMin = newModListPos;
                    warningTransform.anchorMax = newWarningPos;

                    warningText.color = textColor;
                    restartIcon.color = textColor;
                }

                yield return(new WaitForEndOfFrame());
            }
        }
        public void Awake()
        {
            canvas = new GameObject("Recount Canvas")
            {
                layer = 5
            };
            canvas.transform.SetParent(gameObject.transform);
            canvas.AddComponent <Canvas>().renderMode   = RenderMode.ScreenSpaceOverlay;
            canvas.GetComponent <Canvas>().sortingOrder = -1;
            canvas.AddComponent <GraphicRaycaster>();

            Debug.Log("Create ui");
            container = new GameObject("Recount container");
            container.transform.SetParent(canvas.transform, false);

            RectTransform containerRect = container.AddComponent <RectTransform>();

            containerRect.anchorMin        = new Vector2(1, 0.5f);
            containerRect.anchorMax        = new Vector2(1, 0.5f);
            containerRect.pivot            = new Vector2(0, 0);
            containerRect.anchoredPosition = new Vector2(-400, 0);
            containerRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 300);
            VerticalLayoutGroup containerGroup = container.AddComponent <VerticalLayoutGroup>();

            containerGroup.childControlWidth      = true;
            containerGroup.childForceExpandWidth  = false;
            containerGroup.childControlHeight     = true;
            containerGroup.childForceExpandHeight = false;
            containerGroup.padding = new RectOffset(5, 5, 5, 5);
            containerGroup.spacing = 4;
            Image containerImage = container.AddComponent <Image>();

            containerImage.sprite     = Resources.FindObjectsOfTypeAll <Sprite>().Where((sprite) => sprite.name.Equals("texUIPopupRect")).First();
            containerImage.type       = Image.Type.Sliced;
            containerImage.color      = new Color32(41, 43, 45, 241);
            containerImage.fillCenter = true;
            container.AddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;

            header = new GameObject("Recount header");
            header.transform.SetParent(container.transform);
            RectTransform headerRect = header.AddComponent <RectTransform>();

            headerRect.anchorMin = new Vector2(0, 0);
            headerRect.anchorMax = new Vector2(1, 1);
            headerRect.pivot     = new Vector2(0, 0.5f);
            HorizontalLayoutGroup headerGroup = header.AddComponent <HorizontalLayoutGroup>();

            headerGroup.childForceExpandWidth = false;
            headerGroup.padding = new RectOffset(3, 3, 3, 3);

            headerText = new GameObject("Recount header text");
            headerText.transform.SetParent(header.transform);
            HGTextMeshProUGUI headerMesh = headerText.AddComponent <HGTextMeshProUGUI>();

            headerMesh.fontSize  = 20;
            headerMesh.color     = Color.white;
            headerMesh.text      = CurrentTrackingDef.display;
            headerMesh.alignment = TMPro.TextAlignmentOptions.MidlineLeft;
            headerMesh.margin    = new Vector4(3, 0, 0, 0);
            LayoutElement headerLayout = headerText.AddComponent <LayoutElement>();

            headerLayout.flexibleWidth = 1.0f;

            GameObject buttonContainer = new GameObject("Buttons container");

            buttonContainer.transform.SetParent(header.transform);
            HorizontalLayoutGroup buttonContainerGroup = buttonContainer.AddComponent <HorizontalLayoutGroup>();

            buttonContainerGroup.childControlWidth     = true;
            buttonContainerGroup.childForceExpandWidth = false;
            buttonContainerGroup.padding = new RectOffset(0, 0, 5, 0);
            buttonContainer.AddComponent <LayoutElement>().flexibleWidth = 0;
            buttonContainer.AddComponent <ContentSizeFitter>();

            GameObject previousButtonObject = new GameObject("Next button");

            previousButtonObject.transform.SetParent(buttonContainer.transform);
            Button previousButton = previousButtonObject.AddComponent <Button>();

            previousButton.onClick.AddListener(() => {
                PreviousCycle();
            });
            HGTextMeshProUGUI previousText = previousButton.gameObject.AddComponent <HGTextMeshProUGUI>();

            previousText.fontSize  = 20;
            previousText.color     = Color.white;
            previousText.text      = "<-";
            previousText.alignment = TMPro.TextAlignmentOptions.MidlineRight;
            previousText.margin    = new Vector4(3, 0, 3, 0);
            previousButtonObject.AddComponent <LayoutElement>().flexibleWidth = 0;
            previousButtonObject.AddComponent <ContentSizeFitter>();

            GameObject nextButtonObject = new GameObject("Next button");

            nextButtonObject.transform.SetParent(buttonContainer.transform);
            Button nextButton = nextButtonObject.AddComponent <Button>();

            nextButton.onClick.AddListener(() => {
                NextCycle();
            });
            HGTextMeshProUGUI nextText = nextButton.gameObject.AddComponent <HGTextMeshProUGUI>();

            nextText.fontSize  = 20;
            nextText.color     = Color.white;
            nextText.text      = "->";
            nextText.alignment = TMPro.TextAlignmentOptions.MidlineRight;
            nextText.margin    = new Vector4(3, 0, 3, 0);
            nextButtonObject.AddComponent <LayoutElement>().flexibleWidth = 0;
            nextButtonObject.AddComponent <ContentSizeFitter>();

            GameObject info = new GameObject("Recount info");

            info.transform.SetParent(container.transform);
            RectTransform infoRect = info.AddComponent <RectTransform>();

            infoRect.anchorMin = new Vector2(0, 0);
            infoRect.anchorMax = new Vector2(1, 1);
            infoRect.pivot     = new Vector2(0, 0.5f);
            HGTextMeshProUGUI infoMesh = info.AddComponent <HGTextMeshProUGUI>();

            infoMesh.fontSize  = 12;
            infoMesh.color     = Color.white;
            infoMesh.text      = "(Press F2 & F3 to cycle display stat)";
            infoMesh.alignment = TMPro.TextAlignmentOptions.MidlineLeft;
            infoMesh.margin    = new Vector4(3, 0, 0, 0);

            barsContainer = new GameObject("Bars container");
            barsContainer.transform.SetParent(container.transform);
            RectTransform barsContainerRect = barsContainer.AddComponent <RectTransform>();

            barsContainerRect.sizeDelta = new Vector2(300, 22);
            barsContainerRect.anchorMin = new Vector2(0, 0);
            barsContainerRect.anchorMax = new Vector2(1, 1);
            barsContainerRect.pivot     = new Vector2(0, 0);
            VerticalLayoutGroup barsContainerGroup = barsContainer.AddComponent <VerticalLayoutGroup>();

            barsContainerGroup.childControlWidth      = true;
            barsContainerGroup.childForceExpandWidth  = false;
            barsContainerGroup.childControlHeight     = true;
            barsContainerGroup.childForceExpandHeight = false;
            barsContainerGroup.spacing = 4;
            barsContainer.AddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
        }
예제 #17
0
        public ModButton(string text)
        {
            gameObject = new GameObject("Button");
            GameObject hoverOutline = new GameObject("Hover Outline");
            GameObject baseOutline  = new GameObject("Base Outline");
            GameObject textObject   = new GameObject("Text");


            rectTransform            = gameObject.AddComponent <RectTransform>();
            rectTransform.localScale = Vector3.one;

            RectTransform        hoverRect     = hoverOutline.AddComponent <RectTransform>();
            RectTransform        baseRect      = baseOutline.AddComponent <RectTransform>();
            RectTransform        textRect      = textObject.AddComponent <RectTransform>();
            MPEventSystemLocator systemLocator = gameObject.AddComponent <MPEventSystemLocator>();
            LayoutElement        layoutElement = gameObject.AddComponent <LayoutElement>();

            customButtonTransition = gameObject.AddComponent <CustomButtonTransition>();
            buttonSkinController   = gameObject.AddComponent <ButtonSkinController>();
            image = gameObject.AddComponent <Image>();
            customButtonTransition.targetGraphic = image;

            ColorBlock c = customButtonTransition.colors;

            hoverImage = hoverOutline.AddComponent <Image>();
            baseImage  = baseOutline.AddComponent <Image>();

            hoverOutline.transform.SetParent(gameObject.transform);
            baseOutline.transform.SetParent(gameObject.transform);
            textObject.transform.SetParent(gameObject.transform);

            hoverRect.anchorMin = new Vector2(0, 0);
            hoverRect.anchorMax = new Vector2(1, 1);
            hoverRect.sizeDelta = new Vector2(0, 0);

            baseRect.anchorMin = new Vector2(0, 0);
            baseRect.anchorMax = new Vector2(1, 1);
            baseRect.sizeDelta = new Vector2(0, 0);

            tmpText      = textObject.AddComponent <HGTextMeshProUGUI>();
            tmpText.text = text;

            textRect.anchorMin = new Vector2(0, 0);
            textRect.anchorMax = new Vector2(1, 1);
            textRect.sizeDelta = new Vector2(0, 0);

            image.sprite      = Generic.FindResource <Sprite>("texUICleanButton");
            hoverImage.sprite = Generic.FindResource <Sprite>("texUIHighlightBoxOutline");
            baseImage.sprite  = Generic.FindResource <Sprite>("texUIOutlineOnly");

            image.type      = Image.Type.Sliced;
            hoverImage.type = Image.Type.Sliced;
            baseImage.type  = Image.Type.Sliced;

            customButtonTransition.imageOnHover         = hoverImage;
            customButtonTransition.imageOnInteractable  = baseImage;
            customButtonTransition.scaleButtonOnHover   = false;
            customButtonTransition.showImageOnHover     = true;
            customButtonTransition.allowAllEventSystems = true;
            customButtonTransition.pointerClickOnly     = true;

            buttonSkinController.skinData = Generic.FindResource <UISkinData>("skinMenu");

            c.normalColor                 = new Color32(83, 102, 120, 255);
            c.highlightedColor            = new Color32(251, 255, 176, 187);
            c.pressedColor                = new Color32(188, 192, 113, 251);
            c.disabledColor               = new Color32(64, 51, 51, 182);
            customButtonTransition.colors = c;
        }