private void CreateTooltip(Transform parent, PickupDef pickupDefinition, int count)
        {
            ItemDef      itemDefinition = ItemCatalog.GetItemDef(pickupDefinition.itemIndex);
            EquipmentDef equipmentDef   = EquipmentCatalog.GetEquipmentDef(pickupDefinition.equipmentIndex);
            bool         isItem         = itemDefinition != null;

            TooltipContent content = new TooltipContent();

            content.titleColor = pickupDefinition.darkColor;
            content.titleToken = isItem ? itemDefinition.nameToken : equipmentDef.nameToken;
            content.bodyToken  = isItem ? itemDefinition.descriptionToken : equipmentDef.descriptionToken;

            if (isItem && ItemStatsMod.enabled)
            {
                CharacterMaster master = PlayerCharacterMasterController.instances[0].master;

                string stats = ItemStatsMod.GetStats(itemDefinition.itemIndex, count, master);

                if (stats != null)
                {
                    content.overrideBodyText = $"{Language.GetString(content.bodyToken)}{stats}";
                }
            }

            TooltipProvider tooltipProvider = parent.gameObject.AddComponent <TooltipProvider>();

            tooltipProvider.SetContent(content);
        }
Example #2
0
        public void UpdatePickupTooltip(TooltipProvider tooltip, PickupIndex pickupIdx, int itemCount = 1)
        {
            PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIdx);

            string descToken;

            if (pickupDef.itemIndex != ItemIndex.None)
            {
                descToken = ItemCatalog.GetItemDef(pickupDef.itemIndex).descriptionToken;
            }
            else if (pickupDef.equipmentIndex != EquipmentIndex.None)
            {
                descToken = EquipmentCatalog.GetEquipmentDef(pickupDef.equipmentIndex).descriptionToken;
            }
            else
            {
                return;
            }

            string pickupDesc = Language.IsTokenInvalid(descToken) ? Language.GetString(pickupDef.nameToken) : Language.GetString(descToken);

            pickupDesc += "\n\n" + PickupStatsProvider.GetStatsForPickup(pickupIdx, itemCount);

            tooltip.overrideBodyText = pickupDesc;
        }
Example #3
0
        internal void LoadoutPanelController_Row_AddButton(On.RoR2.UI.LoadoutPanelController.Row.orig_AddButton orig, object self, LoadoutPanelController owner, Sprite icon, string titleToken, string bodyToken, Color tooltipColor, UnityEngine.Events.UnityAction callback, string unlockableName, ViewablesCatalog.Node viewableNode, bool isWIP = false)
        {
            orig(self, owner, icon, titleToken, bodyToken, tooltipColor, callback, unlockableName, viewableNode, isWIP);

            LoadoutPanelController.Row selfRow = (LoadoutPanelController.Row)self;
            UserProfile userProfile            = selfRow.userProfile;

            if (mod.config.AdvancedIconsSkillShowProcCoefficient.Value || mod.config.AdvancedIconsSkillShowBaseCooldown.Value)
            {
                if (userProfile != null && userProfile.HasUnlockable(unlockableName))
                {
                    BetterUI.sharedStringBuilder.Clear();
                    BetterUI.sharedStringBuilder.Append(Language.GetString(bodyToken));
                    if (mod.config.AdvancedIconsSkillShowBaseCooldown.Value)
                    {
                        BetterUI.print(titleToken);
                        var skillDef = RoR2.Skills.SkillCatalog.GetSkillDef(Utils.TheREALFindSkillIndexByName(titleToken));
                        if (skillDef)
                        {
                            BetterUI.sharedStringBuilder.Append("\n\nCooldown: <style=cIsDamage>");
                            BetterUI.sharedStringBuilder.Append(skillDef.baseRechargeInterval);
                            BetterUI.sharedStringBuilder.Append("</style> second");
                            if (skillDef.baseRechargeInterval != 1)
                            {
                                BetterUI.sharedStringBuilder.Append("s");
                            }
                        }
                    }

                    if (mod.config.AdvancedIconsSkillShowProcCoefficient.Value)
                    {
                        List <ProcCoefficientCatalog.ProcCoefficientInfo> procCoefficientInfos = ProcCoefficientCatalog.GetProcCoefficientInfo(titleToken);

                        if (procCoefficientInfos != null)
                        {
                            foreach (var info in procCoefficientInfos)
                            {
                                BetterUI.sharedStringBuilder.Append("\n\n<size=110%>");
                                BetterUI.sharedStringBuilder.Append(info.name);
                                BetterUI.sharedStringBuilder.Append(":</size>");
                                if (mod.config.AdvancedIconsSkillShowProcCoefficient.Value)
                                {
                                    BetterUI.sharedStringBuilder.Append("\n <style=cIsUtility>Proc Coefficient: ");
                                    BetterUI.sharedStringBuilder.Append(info.procCoefficient);
                                    BetterUI.sharedStringBuilder.Append("</style>");
                                }
                            }
                        }
                    }
                    TooltipProvider tooltipProvider = selfRow.buttons[selfRow.buttons.Count - 1].GetComponent <TooltipProvider>();
                    if (tooltipProvider != null)
                    {
                        tooltipProvider.overrideBodyText = BetterUI.sharedStringBuilder.ToString();
                    }
                }
            }
        }
		public ProjectedTooltipProvider (Projection projection, TooltipProvider projectedTooltipProvider)
		{
			if (projection == null)
				throw new ArgumentNullException ("projection");
			if (projectedTooltipProvider == null)
				throw new ArgumentNullException ("projectedTooltipProvider");
			this.projectedTooltipProvider = projectedTooltipProvider;
			this.projection = projection;
		}
 public ProjectedTooltipProvider(Projection projection, TooltipProvider projectedTooltipProvider)
 {
     if (projection == null)
     {
         throw new ArgumentNullException("projection");
     }
     if (projectedTooltipProvider == null)
     {
         throw new ArgumentNullException("projectedTooltipProvider");
     }
     this.projectedTooltipProvider = projectedTooltipProvider;
     this.projection = projection;
 }
		public ProjectedTooltipProvider (TextEditor editor, DocumentContext ctx, Projection projection, TooltipProvider projectedTooltipProvider)
		{
			if (editor == null)
				throw new ArgumentNullException ("editor");
			if (ctx == null)
				throw new ArgumentNullException ("ctx");
			if (projection == null)
				throw new ArgumentNullException ("projection");
			if (projectedTooltipProvider == null)
				throw new ArgumentNullException ("projectedTooltipProvider");
			this.projectedTooltipProvider = projectedTooltipProvider;
			this.projection = projection;
		}
Example #7
0
 public ProjectedTooltipProvider(TextEditor editor, DocumentContext ctx, Projection projection, TooltipProvider projectedTooltipProvider)
 {
     if (editor == null)
     {
         throw new ArgumentNullException("editor");
     }
     if (ctx == null)
     {
         throw new ArgumentNullException("ctx");
     }
     if (projection == null)
     {
         throw new ArgumentNullException("projection");
     }
     if (projectedTooltipProvider == null)
     {
         throw new ArgumentNullException("projectedTooltipProvider");
     }
     this.projectedTooltipProvider = projectedTooltipProvider;
     this.projection = projection;
 }
Example #8
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;
                    }
                }
            }
        }
Example #9
0
        private static void MatchTooltipToCanvas(On.RoR2.UI.TooltipController.orig_SetTooltip orig, MPEventSystem eventSystem, TooltipProvider newTooltipProvider, Vector2 tooltipPosition)
        {
            orig(eventSystem, newTooltipProvider, tooltipPosition);

            if (!eventSystem.currentTooltip || !lastHitCanvas)
            {
                return;
            }

            if (cursorInstance)
            {
                Vector3 relativeCursorPosition = lastHitCanvas.transform.InverseTransformPoint(cursorInstance.transform.position);

                Vector2 vector2 = new Vector2(0f, 0f);
                vector2.x = ((relativeCursorPosition.x > 0f) ? 1f : 0f);
                vector2.y = ((relativeCursorPosition.y > 0f) ? 1f : 0f);
                eventSystem.currentTooltip.tooltipFlipTransform.anchorMin = vector2;
                eventSystem.currentTooltip.tooltipFlipTransform.anchorMax = vector2;
                eventSystem.currentTooltip.tooltipFlipTransform.pivot     = vector2;
            }

            Canvas canvas = eventSystem.currentTooltip.GetComponent <Canvas>();

            canvas.renderMode = RenderMode.WorldSpace;

            RectTransform canvasTransform  = canvas.transform as RectTransform;
            RectTransform lastHitTransform = lastHitCanvas.transform as RectTransform;

            canvasTransform.sizeDelta  = lastHitTransform.sizeDelta;
            canvasTransform.pivot      = lastHitTransform.pivot;
            canvasTransform.position   = lastHitTransform.position;
            canvasTransform.rotation   = lastHitTransform.rotation;
            canvasTransform.localScale = lastHitTransform.localScale;
        }