Custom Rarity

This commit is contained in:
doze-zoze committed 2026-04-07 20:59:09 -05:00
1 parent 9847892d9f
commit 9b5269fa6d
4 files changed
+171 -14

No files matched your search

+3
View File
@@ -1,4 +1,5 @@
using System;
using CalamityMod.Items.Accessories.Wings;
using CalamityMod.NPCs.DevourerofGods;
using CalamityMod.Rarities;
using CalamityMod.Utilities.Daybreak;
@@ -35,6 +36,8 @@ namespace CalamityMod.ChatTags
return new CalamityRed.CustomTextSnippet(text);
if (options.Equals("exo", StringComparison.OrdinalIgnoreCase))
return new ExoticRainbow.CustomTextSnippet(text);
if (options.Equals("doze", StringComparison.OrdinalIgnoreCase))
return new TiredTailTextEffects(text);
return new TextSnippet(text);
}
}
+102 -3
View File
@@ -19,11 +19,14 @@ using CalamityMod.Utilities.Daybreak;
using CalamityMod.Utilities.Daybreak.Buffers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Graphics;
using Terraria;
using Terraria.DataStructures;
using Terraria.GameContent;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.UI.Chat;
using static Terraria.ModLoader.ModContent;
namespace CalamityMod.Items.Accessories.Wings
@@ -55,7 +58,7 @@ namespace CalamityMod.Items.Accessories.Wings
Item.width = 22;
Item.height = 20;
Item.value = CalamityGlobalItem.RarityTurquoiseBuyPrice;
Item.rare = ModContent.RarityType<Turquoise>();
Item.rare = ModContent.RarityType<HotPink>();
Item.Calamity().devItem = true;
}
@@ -112,6 +115,18 @@ namespace CalamityMod.Items.Accessories.Wings
public List<(Vector2 pos, float rot)> tailPos;
public override void ResetEffects()
{
//Handled here to prevent issues with instancing of chat tags
if (TiredTailTextEffects.displayTimer > 0)
{
TiredTailTextEffects.expansionFactor += 0.033f;
TiredTailTextEffects.displayTimer -= 1;
}
else
{
TiredTailTextEffects.expansionFactor = 0f;
}
tiredTailDraw = false;
}
public override void PostUpdate()
@@ -172,7 +187,7 @@ namespace CalamityMod.Items.Accessories.Wings
Main.QueueMainThreadAction(() =>
{
//Load palettes automatically
var texture = ModContent.Request<Texture2D>("CalamityMod/Items/Accessories/Wings/TiredTailPallette",ReLogic.Content.AssetRequestMode.ImmediateLoad).Value;
var texture = ModContent.Request<Texture2D>("CalamityMod/Items/Accessories/Wings/TiredTailPallette", ReLogic.Content.AssetRequestMode.ImmediateLoad).Value;
var BaseArray = new Color[texture.Width * texture.Height];
texture.GetData(BaseArray);
List<Vector4> pal = new();
@@ -271,7 +286,7 @@ namespace CalamityMod.Items.Accessories.Wings
ColorPallettes[17]),
];
});
}
List<(List<int> heads, List<int> bodies, List<int> legs, Vector4[] pallette)> ArmorPallettes = [];
@@ -429,4 +444,88 @@ namespace CalamityMod.Items.Accessories.Wings
}
}
public sealed class TiredTailTextEffects(string text) : TextSnippet
{
//Handled by TiredTailPlayer as this effect is for TiredTail
public static float expansionFactor = 0;
public static int displayTimer = 0;
public override bool UniqueDraw(bool justCheckingString, out Vector2 size, SpriteBatch spriteBatch, Vector2 position = new Vector2(), Color color = new Color(), float scale = 1)
{
//size = new Vector2(GetStringLength(FontAssets.MouseText.Value), FontAssets.MouseText.Value.MeasureString(" ").Y * scale);
if (color == default || color == Main.MouseTextColorReal)
{
color = Colors.AlphaDarken(HotPink.TextColor);
}
var textarray = text.ToArray();
for (var i = 0; i < textarray.Length; i++)
{
if (expansionFactor - 10 > i)
{
textarray[i] = (i == 0 ? 'ɔ' : '»');
}
}
var textToDraw = new string(textarray);
size = FontAssets.MouseText.Value.MeasureString(textToDraw)*scale;
if (!justCheckingString && (color.R != 0 || color.G != 0 || color.B != 0))
{
var pos = position;
using var lease = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice);
string txt = "";
var matrix = spriteBatch.transformMatrix;
using (spriteBatch.Scope())
{
using (lease.Scope(clearColor: Color.Transparent))
{
var max = FontAssets.MouseText.Value.MeasureString(text) * Math.Min(1f,expansionFactor);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, matrix);
foreach (var item in textarray)
{//new(92,83,117)
pos = position;
pos.X += Math.Min(FontAssets.MouseText.Value.MeasureString(txt).X,max.X+9999);
float sin = (MathF.Sin(pos.X * 0.02f + Main.GlobalTimeWrappedHourly * -1.5f) + 1) * 0.5f;
float sin2 = (MathF.Sin(pos.X * 0.02f + Main.GlobalTimeWrappedHourly * -0.9f) + 1) * 0.5f;
float sin3 = MathF.Sin(pos.X * 0.02f + Main.GlobalTimeWrappedHourly * -1.5f + MathHelper.PiOver2);
var c = new Color(171, 153, 204);
if (txt.Length == 0 || txt.Length == text.Length-1)
c = Color.Cyan;
else if (txt.Length % 4 == 3)
{
c = Color.HotPink;
}
c = Color.Lerp(Colors.AlphaDarken(new Color(0, 255, 200)), c, MathHelper.Clamp(expansionFactor - 2, 0, 1));
float posMult = Math.Max(MathHelper.Clamp((expansionFactor - 10) * 0.5f, 0, 3), MathHelper.Clamp((expansionFactor - 2) * 0.5f, 0, 1));
var origin = FontAssets.MouseText.Value.MeasureString(item.ToString()) * 0.5f;
ChatManager.DrawColorCodedString(spriteBatch, FontAssets.MouseText.Value, item.ToString(), origin + pos + new Vector2(0, item == 'ɔ' ? -1 : 0) + new Vector2((-2f + 4*sin2) * posMult, (-2 + sin * 4) * posMult), c, sin3*posMult * 0.1f, origin, new Vector2(scale));
txt += item;
}
spriteBatch.End();
}
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Matrix.Identity);
foreach (var item in ChatManager.ShadowDirections)
{
spriteBatch.Draw(lease.Target, Vector2.Zero + Vector2.TransformNormal(item * 2, matrix), null, Color.Black, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
}
spriteBatch.Draw(lease.Target, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
spriteBatch.End();
}
}
return true;
}
public override void Update()
{
displayTimer = 10;
}
public override float GetStringLength(DynamicSpriteFont font)
{
float size = font.MeasureString(text).X;
return size * Scale;
}
}
}
+6
View File
@@ -10,6 +10,7 @@ namespace CalamityMod.Rarities
public static int RarityBurnishedAuric => ModContent.GetInstance<BurnishedAuric>().Type;
public static int RarityCalamityRed => ModContent.GetInstance<CalamityRed>().Type;
public static int RarityExoticRainbow => ModContent.GetInstance<ExoticRainbow>().Type;
public static int RarityCustomDev => ModContent.GetInstance<HotPink>().Type;
public override bool PreDrawTooltipLine(Item Item, DrawableTooltipLine line, ref int yOffset)
@@ -37,6 +38,11 @@ namespace CalamityMod.Rarities
ExoticRainbow.Draw(Item, line);
return false;
}
if (Item.rare == RarityCustomDev)
{
HotPink.Draw(Item, line);
return false;
}
}
return true;
}
+60 -11
View File
@@ -1,21 +1,70 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using CalamityMod.Items.Accessories.Wings;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Graphics;
using Terraria;
using Terraria.GameContent;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.UI.Chat;
namespace CalamityMod.Rarities
{
public class HotPink : ModRarity
{
// Hot Pink is Rarity 16
public override Color RarityColor => new Color(255, 0, 255);
// Hot Pink is used for developer items. Has a system built in for custom rarity effects.
public override Color RarityColor => TextColor;
public static Color TextColor => new Color(255, 0, 255);
// Hot Pink cannot turn into other rarities via prefix
/*public override int GetPrefixedRarity(int offset, float valueMult) => offset switch
public static Dictionary<int, Func<string, TextSnippet>> CustomRarities = new()
{
-2 => ModContent.RarityType<CosmicPurple>(),
-1 => ModContent.RarityType<BurnishedAuric>(),
1 => ModContent.RarityType<CalamityRed>(),
2 => ModContent.RarityType<CalamityRed>(),
_ => Type,
};*/
{ ModContent.ItemType<TiredTail>(), text => new TiredTailTextEffects(text) }
};
public static void Draw(Item Item, SpriteBatch spriteBatch, string text, int X, int Y, Color textColor, Color lightColor, float rotation,
Vector2 origin, Vector2 baseScale, float time, bool renderTextSparkles, DynamicSpriteFont font)
{
TextSnippet[] snippets = ChatManager.ParseMessage(text, textColor).ToArray();
if (CustomRarities.ContainsKey(Item.type)) //For items in the custom rarity table, give them custom rarity effects.
{
for (int i = 0; i < snippets.Length; i++)
{
TextSnippet textSnippet = snippets[i];
if (snippets[i].GetType() == typeof(TextSnippet))
{
snippets[i] = CustomRarities[Item.type].Invoke(textSnippet.Text);
continue;
}
}
}
else
ChatManager.ConvertNormalSnippets(snippets);
ChatManager.DrawColorCodedString(spriteBatch, font, snippets, new(X, Y), textColor, 0, Vector2.Zero, baseScale, out _, -1, true);
}
public static void Draw(Item Item, string text, int X, int Y, float rotation, Vector2 origin, Vector2 baseScale, Color? textColor = null, Color? lightColor = null, bool? renderTextSparkles = null)
{
Draw(Item, Main.spriteBatch, text, X, Y, Colors.AlphaDarken(textColor ?? TextColor), lightColor ?? Color.White, rotation, origin, baseScale, Main.GlobalTimeWrappedHourly,
renderTextSparkles ?? CalamityClientConfig.Instance.TextEffects, FontAssets.MouseText.Value);
}
public static void Draw(Item Item, DrawableTooltipLine line)
{
Draw(Item, line.Text, line.X, line.Y, line.Rotation, line.Origin, line.BaseScale);
}
#region Custom Draw Effects
#region Doze's Effect
#endregion
#endregion
}
}