tModLoader How to create a tooltip that changes based on stats?

MistaLOD

Terrarian
I found a mod that changes the tooltip to reflect how many kills you got with a certain weapon and all the stats that it changes, but instead of just changing the tooltip to the right number, it just "adds" another tooltip on top of the one in place. This means two things: the tooltip extends above the screen because it keeps adding, and after a few seconds, the tooltip becomes so long that the game lags substantially.

I want to fix this pretty much on my own so that I can use the item without fear of the game lagging out when I roll over the item and activate the tooltip.

C#:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Utilities;
using Terraria.ModLoader.IO;
using Microsoft.Xna.Framework;
using KillCharm.Projectiles;

namespace KillCharm.Items
{
    class MurderRifle : ModItem
    {
        enum MurderRifleStats { Damage, Speed, SpeedCount, SpeedCountNeed, ShotSpeed, Penetrate, PenetrateCount, PenetrateCountNeed }
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Murder Rifle");
            Tooltip.SetDefault("Rifle for murdering\n" + "Stats:");
        }
        //public override string Texture => "Terraria/Item_" + ItemID.Musket;
        public override void SetDefaults()
        {
            item.scale = 0.8f;
            item.damage = 5;
            item.ranged = true;
            item.useTime = 201;
            item.useAnimation = 201;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 3;
            item.value = 50000;
            item.rare = 2;
            item.UseSound = SoundID.Item11;
            item.autoReuse = true;
            item.shootSpeed = 1f;//16
            item.shoot = mod.ProjectileType("RifleBulletProjectile");
        }


        public override void ModifyTooltips(List<TooltipLine> tooltips)
        {
            foreach (var line in tooltips)
            {
                if (line.mod.Equals("Terraria") && line.Name.Equals("Tooltip1"))
                {
                    line.text = MakeToolTip();
                }
            }
        }

        private StringBuilder builder = new StringBuilder();

        private string MakeToolTip()
        {
            var mp = Main.LocalPlayer.GetModPlayer<MyPlayer>();

            builder.Append("Stats: ");

            builder.Append("\nDamage: ");
            builder.Append(mp.MurderRifleStat[(int)MurderRifleStats.Damage]);

            builder.Append("\nShell Speed: ");
            builder.Append(mp.MurderRifleStat[(int)MurderRifleStats.ShotSpeed]);

            builder.Append("\nShoot Speed: ");
            builder.Append(mp.MurderRifleStat[(int)MurderRifleStats.Speed]);
            builder.Append("  -  Shots: ");
            builder.Append(mp.MurderRifleStat[(int)MurderRifleStats.SpeedCount]);
            builder.Append("  -  Need Shots to up: ");
            builder.Append(mp.MurderRifleStat[(int)MurderRifleStats.SpeedCountNeed]);

            builder.Append("\nPenetrate: ");
            builder.Append(mp.MurderRifleStat[(int)MurderRifleStats.Penetrate]-1);
            builder.Append("  -  Kills: ");
            builder.Append(mp.MurderRifleStat[(int)MurderRifleStats.PenetrateCount]);
            builder.Append("  -  Need Kills to up: ");
            builder.Append(mp.MurderRifleStat[(int)MurderRifleStats.PenetrateCountNeed]);
            return builder.ToString();
            /*    */
        }
        /*
            builder.Append("Stats: ");
            builder.Append("\nDamage: " + mp.MurderRifleStat[(int)MurderRifleStats.Damage]);
            builder.Append("\nShoot Speed: " + mp.MurderRifleStat[(int)MurderRifleStats.Speed]);
            builder.Append("\nShell Speed: " + mp.MurderRifleStat[(int)MurderRifleStats.ShotSpeed]);
            return builder.ToString();
        }*/
        public override bool CanUseItem(Player player)
        {
            var mp = player.GetModPlayer<MyPlayer>();

            mp.MurderRifleStat[(int)MurderRifleStats.SpeedCount]++;
            if ((mp.MurderRifleStat[(int)MurderRifleStats.SpeedCount] >= mp.MurderRifleStat[(int)MurderRifleStats.SpeedCountNeed]) && (201 - ((int)(mp.MurderRifleStat[(int)MurderRifleStats.Speed]) + 1) >= 1))
            {
                mp.MurderRifleStat[(int)MurderRifleStats.SpeedCount] = 0;
                mp.MurderRifleStat[(int)MurderRifleStats.Speed]++;
                CombatText.NewText(new Rectangle((int)player.position.X, (int)player.position.Y, player.width, player.height), CombatText.LifeRegenNegative, "Murder Rifle Speed Up!", true);

                if (mp.MurderRifleStat[(int)MurderRifleStats.Speed] >= 150)
                {
                    
                    if (mp.MurderRifleStat[(int)MurderRifleStats.Speed] >= 180)
                    {
                        if (mp.MurderRifleStat[(int)MurderRifleStats.Speed] >= 190)
                        {
                            mp.MurderRifleStat[(int)MurderRifleStats.SpeedCountNeed] += 1000;
                        }
                        else { mp.MurderRifleStat[(int)MurderRifleStats.SpeedCountNeed] += 100; }
                    }
                    else { mp.MurderRifleStat[(int)MurderRifleStats.SpeedCountNeed] += 10; }
                }
            }
            item.damage = (int)mp.MurderRifleStat[(int)MurderRifleStats.Damage];
            item.useTime = 201 - (int)mp.MurderRifleStat[(int)MurderRifleStats.Speed];
            item.useAnimation = 201 - (int)mp.MurderRifleStat[(int)MurderRifleStats.Speed];
            item.shootSpeed = mp.MurderRifleStat[(int)MurderRifleStats.ShotSpeed];

            return true;
        }
        public override Vector2? HoldoutOffset()
        {
            return new Vector2(-7, 3);
        }
    }
}

If anybody can help it'd be very much appreciated. If not, than I can honestly deal with this issue.
 
Back
Top Bottom