Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ItemTagHandler.cs
Go to the documentation of this file.
4using Terraria.ID;
5using Terraria.UI;
7
9
11{
12 private class ItemSnippet : TextSnippet
13 {
14 private Item _item;
15
16 public ItemSnippet(Item item)
17 {
18 _item = item;
19 Color = ItemRarity.GetColor(item.rare);
20 }
21
22 public override void OnHover()
23 {
24 Main.HoverItem = _item.Clone();
25 Main.instance.MouseText(_item.Name, _item.rare, 0);
26 }
27
28 public override bool UniqueDraw(bool justCheckingString, out Vector2 size, SpriteBatch spriteBatch, Vector2 position = default(Vector2), Color color = default(Color), float scale = 1f)
29 {
30 float num = 1f;
31 float num2 = 1f;
32 if (Main.netMode != 2 && !Main.dedServ)
33 {
34 Main.instance.LoadItem(_item.type);
35 Texture2D value = TextureAssets.Item[_item.type].Value;
36 if (Main.itemAnimations[_item.type] != null)
37 {
38 Main.itemAnimations[_item.type].GetFrame(value);
39 }
40 else
41 {
42 value.Frame();
43 }
44 }
45 num2 *= scale;
46 num *= num2;
47 if (num > 0.75f)
48 {
49 num = 0.75f;
50 }
51 if (!justCheckingString && color != Color.Black)
52 {
53 float inventoryScale = Main.inventoryScale;
54 Main.inventoryScale = scale * num;
55 ItemSlot.Draw(spriteBatch, ref _item, 14, position - new Vector2(10f) * scale * num, Color.White);
56 Main.inventoryScale = inventoryScale;
57 }
58 size = new Vector2(32f) * scale * num;
59 return true;
60 }
61
62 public override float GetStringLength(DynamicSpriteFont font)
63 {
64 return 32f * Scale * 0.65f;
65 }
66 }
67
68 TextSnippet ITagHandler.Parse(string text, Color baseColor, string options)
69 {
70 Item item = new Item();
71 if (int.TryParse(text, out var result))
72 {
73 item.netDefaults(result);
74 }
75 if (item.type <= 0)
76 {
77 return new TextSnippet(text);
78 }
79 item.stack = 1;
80 if (options != null)
81 {
82 string[] array = options.Split(',');
83 for (int i = 0; i < array.Length; i++)
84 {
85 if (array[i].Length == 0)
86 {
87 continue;
88 }
89 switch (array[i][0])
90 {
91 case 's':
92 case 'x':
93 {
94 if (int.TryParse(array[i].Substring(1), out var result3))
95 {
96 item.stack = Utils.Clamp(result3, 1, item.maxStack);
97 }
98 break;
99 }
100 case 'p':
101 {
102 if (int.TryParse(array[i].Substring(1), out var result2))
103 {
104 item.Prefix((byte)Utils.Clamp(result2, 0, PrefixID.Count));
105 }
106 break;
107 }
108 }
109 }
110 }
111 string text2 = "";
112 if (item.stack > 1)
113 {
114 text2 = " (" + item.stack + ")";
115 }
116 return new ItemSnippet(item)
117 {
118 Text = "[" + item.AffixName() + text2 + "]",
119 CheckForHover = true,
120 DeleteWhole = true
121 };
122 }
123
124 public static string GenerateTag(Item I)
125 {
126 string text = "[i";
127 if (I.prefix != 0)
128 {
129 text = text + "/p" + I.prefix;
130 }
131 if (I.stack != 1)
132 {
133 text = text + "/s" + I.stack;
134 }
135 return text + ":" + I.netID + "]";
136 }
137}
static Asset< Texture2D >[] Item
override float GetStringLength(DynamicSpriteFont font)
override bool UniqueDraw(bool justCheckingString, out Vector2 size, SpriteBatch spriteBatch, Vector2 position=default(Vector2), Color color=default(Color), float scale=1f)
static Color GetColor(int rarity)
Definition ItemRarity.cs:27
static readonly int Count
Definition PrefixID.cs:180
Item Clone()
Definition Item.cs:49916
string Name
Definition Item.cs:326
static int netMode
Definition Main.cs:2095
static DrawAnimation[] itemAnimations
Definition Main.cs:1707
static bool dedServ
Definition Main.cs:1226
static Main instance
Definition Main.cs:283
static float inventoryScale
Definition Main.cs:1779
static void Draw(SpriteBatch spriteBatch, ref Item inv, int context, Vector2 position, Color lightColor=default(Color))
Definition ItemSlot.cs:1777
TextSnippet Parse(string text, Color baseColor=default(Color), string options=null)