Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIAchievementListItem.cs
Go to the documentation of this file.
1using System;
7using Terraria.UI;
9
11
13{
15
17
19
20 private const int _iconSize = 64;
21
22 private const int _iconSizeWithSpace = 66;
23
24 private const int _iconsPerRow = 8;
25
26 private int _iconIndex;
27
29
31
33
35
37
39
40 private bool _locked;
41
42 private bool _large;
43
44 public UIAchievementListItem(Achievement achievement, bool largeForOtherLanguages)
45 {
46 _large = largeForOtherLanguages;
47 BackgroundColor = new Color(26, 40, 89) * 0.8f;
48 BorderColor = new Color(13, 20, 44) * 0.8f;
49 float num = 16 + _large.ToInt() * 20;
50 float num2 = _large.ToInt() * 6;
51 float num3 = _large.ToInt() * 12;
52 _achievement = achievement;
53 Height.Set(66f + num, 0f);
54 Width.Set(0f, 1f);
55 PaddingTop = 8f;
56 PaddingLeft = 9f;
57 int num4 = (_iconIndex = Main.Achievements.GetIconIndex(achievement.Name));
58 _iconFrameUnlocked = new Rectangle(num4 % 8 * 66, num4 / 8 * 66, 64, 64);
60 _iconFrameLocked.X += 528;
63 _achievementIcon = new UIImageFramed(Main.Assets.Request<Texture2D>("Images/UI/Achievements", (AssetRequestMode)1), _iconFrame);
64 _achievementIcon.Left.Set(num2, 0f);
65 _achievementIcon.Top.Set(num3, 0f);
67 _achievementIconBorders = new UIImage(Main.Assets.Request<Texture2D>("Images/UI/Achievement_Borders", (AssetRequestMode)1));
68 _achievementIconBorders.Left.Set(-4f + num2, 0f);
69 _achievementIconBorders.Top.Set(-4f + num3, 0f);
71 _innerPanelTopTexture = Main.Assets.Request<Texture2D>("Images/UI/Achievement_InnerPanelTop", (AssetRequestMode)1);
72 if (_large)
73 {
74 _innerPanelBottomTexture = Main.Assets.Request<Texture2D>("Images/UI/Achievement_InnerPanelBottom_Large", (AssetRequestMode)1);
75 }
76 else
77 {
78 _innerPanelBottomTexture = Main.Assets.Request<Texture2D>("Images/UI/Achievement_InnerPanelBottom", (AssetRequestMode)1);
79 }
80 _categoryTexture = Main.Assets.Request<Texture2D>("Images/UI/Achievement_Categories", (AssetRequestMode)1);
81 }
82
83 protected override void DrawSelf(SpriteBatch spriteBatch)
84 {
85 base.DrawSelf(spriteBatch);
86 int num = _large.ToInt() * 6;
87 Vector2 vector = new Vector2(num, 0f);
90 CalculatedStyle innerDimensions = GetInnerDimensions();
92 float num2 = dimensions.X + dimensions.Width;
93 Vector2 vector2 = new Vector2(num2 + 7f, innerDimensions.Y);
95 bool flag = false;
96 if ((!(trackerValues.Item1 == 0m) || !(trackerValues.Item2 == 0m)) && _locked)
97 {
98 flag = true;
99 }
100 float num3 = innerDimensions.Width - dimensions.Width + 1f - (float)(num * 2);
101 Vector2 baseScale = new Vector2(0.85f);
102 Vector2 baseScale2 = new Vector2(0.92f);
103 string text = FontAssets.ItemStack.Value.CreateWrappedText(_achievement.Description.Value, (num3 - 20f) * (1f / baseScale2.X), Language.ActiveCulture.CultureInfo);
104 Vector2 stringSize = ChatManager.GetStringSize(FontAssets.ItemStack.Value, text, baseScale2, num3);
105 if (!_large)
106 {
107 stringSize = ChatManager.GetStringSize(FontAssets.ItemStack.Value, _achievement.Description.Value, baseScale2, num3);
108 }
109 float num4 = 38f + (float)(_large ? 20 : 0);
110 if (stringSize.Y > num4)
111 {
112 baseScale2.Y *= num4 / stringSize.Y;
113 }
114 Color value = (_locked ? Color.Silver : Color.Gold);
115 value = Color.Lerp(value, Color.White, base.IsMouseHovering ? 0.5f : 0f);
116 Color value2 = (_locked ? Color.DarkGray : Color.Silver);
117 value2 = Color.Lerp(value2, Color.White, base.IsMouseHovering ? 1f : 0f);
118 Color color = (base.IsMouseHovering ? Color.White : Color.Gray);
119 Vector2 vector3 = vector2 - Vector2.UnitY * 2f + vector;
120 DrawPanelTop(spriteBatch, vector3, num3, color);
122 vector3.Y += 2f;
123 vector3.X += 4f;
124 spriteBatch.Draw(_categoryTexture.Value, vector3, _categoryTexture.Frame(4, 2, (int)category), base.IsMouseHovering ? Color.White : Color.Silver, 0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0f);
125 vector3.X += 4f;
126 vector3.X += 17f;
128 vector3.X -= 17f;
129 Vector2 position = vector2 + Vector2.UnitY * 27f + vector;
130 DrawPanelBottom(spriteBatch, position, num3, color);
131 position.X += 8f;
132 position.Y += 4f;
133 ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.ItemStack.Value, text, position, value2, 0f, Vector2.Zero, baseScale2);
134 if (flag)
135 {
136 Vector2 vector4 = vector3 + Vector2.UnitX * num3 + Vector2.UnitY;
137 string text2 = (int)trackerValues.Item1 + "/" + (int)trackerValues.Item2;
138 Vector2 baseScale3 = new Vector2(0.75f);
139 Vector2 stringSize2 = ChatManager.GetStringSize(FontAssets.ItemStack.Value, text2, baseScale3);
140 float progress = (float)(trackerValues.Item1 / trackerValues.Item2);
141 float num5 = 80f;
142 Color color2 = new Color(100, 255, 100);
143 if (!base.IsMouseHovering)
144 {
145 color2 = Color.Lerp(color2, Color.Black, 0.25f);
146 }
147 Color color3 = new Color(255, 255, 255);
148 if (!base.IsMouseHovering)
149 {
150 color3 = Color.Lerp(color3, Color.Black, 0.25f);
151 }
152 DrawProgressBar(spriteBatch, progress, vector4 - Vector2.UnitX * num5 * 0.7f, num5, color3, color2, color2.MultiplyRGBA(new Color(new Vector4(1f, 1f, 1f, 0.5f))));
153 vector4.X -= num5 * 1.4f + stringSize2.X;
154 ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.ItemStack.Value, text2, vector4, value, 0f, new Vector2(0f, 0f), baseScale3, 90f);
155 }
156 }
157
158 private void UpdateIconFrame()
159 {
160 if (!_locked)
161 {
163 }
164 else
165 {
167 }
168 if (_achievementIcon != null)
169 {
171 }
172 }
173
174 private void DrawPanelTop(SpriteBatch spriteBatch, Vector2 position, float width, Color color)
175 {
176 spriteBatch.Draw(_innerPanelTopTexture.Value, position, new Rectangle(0, 0, 2, _innerPanelTopTexture.Height()), color);
177 spriteBatch.Draw(_innerPanelTopTexture.Value, new Vector2(position.X + 2f, position.Y), new Rectangle(2, 0, 2, _innerPanelTopTexture.Height()), color, 0f, Vector2.Zero, new Vector2((width - 4f) / 2f, 1f), SpriteEffects.None, 0f);
178 spriteBatch.Draw(_innerPanelTopTexture.Value, new Vector2(position.X + width - 2f, position.Y), new Rectangle(4, 0, 2, _innerPanelTopTexture.Height()), color);
179 }
180
181 private void DrawPanelBottom(SpriteBatch spriteBatch, Vector2 position, float width, Color color)
182 {
183 spriteBatch.Draw(_innerPanelBottomTexture.Value, position, new Rectangle(0, 0, 6, _innerPanelBottomTexture.Height()), color);
184 spriteBatch.Draw(_innerPanelBottomTexture.Value, new Vector2(position.X + 6f, position.Y), new Rectangle(6, 0, 7, _innerPanelBottomTexture.Height()), color, 0f, Vector2.Zero, new Vector2((width - 12f) / 7f, 1f), SpriteEffects.None, 0f);
185 spriteBatch.Draw(_innerPanelBottomTexture.Value, new Vector2(position.X + width - 6f, position.Y), new Rectangle(13, 0, 6, _innerPanelBottomTexture.Height()), color);
186 }
187
188 public override void MouseOver(UIMouseEvent evt)
189 {
190 base.MouseOver(evt);
191 BackgroundColor = new Color(46, 60, 119);
192 BorderColor = new Color(20, 30, 56);
193 }
194
195 public override void MouseOut(UIMouseEvent evt)
196 {
197 base.MouseOut(evt);
198 BackgroundColor = new Color(26, 40, 89) * 0.8f;
199 BorderColor = new Color(13, 20, 44) * 0.8f;
200 }
201
203 {
204 return _achievement;
205 }
206
208 {
210 {
211 return Tuple.Create(0m, 0m);
212 }
214 if (tracker.GetTrackerType() == TrackerType.Int)
215 {
216 AchievementTracker<int> achievementTracker = (AchievementTracker<int>)tracker;
217 return Tuple.Create((decimal)achievementTracker.Value, (decimal)achievementTracker.MaxValue);
218 }
219 if (tracker.GetTrackerType() == TrackerType.Float)
220 {
221 AchievementTracker<float> achievementTracker2 = (AchievementTracker<float>)tracker;
222 return Tuple.Create((decimal)achievementTracker2.Value, (decimal)achievementTracker2.MaxValue);
223 }
224 return Tuple.Create(0m, 0m);
225 }
226
227 private void DrawProgressBar(SpriteBatch spriteBatch, float progress, Vector2 spot, float Width = 169f, Color BackColor = default(Color), Color FillingColor = default(Color), Color BlipColor = default(Color))
228 {
229 if (BlipColor == Color.Transparent)
230 {
231 BlipColor = new Color(255, 165, 0, 127);
232 }
233 if (FillingColor == Color.Transparent)
234 {
235 FillingColor = new Color(255, 241, 51);
236 }
237 if (BackColor == Color.Transparent)
238 {
239 FillingColor = new Color(255, 255, 255);
240 }
242 _ = TextureAssets.ColorBlip.Value;
243 Texture2D value2 = TextureAssets.MagicPixel.Value;
244 float num = MathHelper.Clamp(progress, 0f, 1f);
245 float num2 = Width * 1f;
246 float num3 = 8f;
247 float num4 = num2 / 169f;
248 Vector2 position = spot + Vector2.UnitY * num3 + Vector2.UnitX * 1f;
249 spriteBatch.Draw(value, spot, new Rectangle(5, 0, value.Width - 9, value.Height), BackColor, 0f, new Vector2(84.5f, 0f), new Vector2(num4, 1f), SpriteEffects.None, 0f);
250 spriteBatch.Draw(value, spot + new Vector2((0f - num4) * 84.5f - 5f, 0f), new Rectangle(0, 0, 5, value.Height), BackColor, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
251 spriteBatch.Draw(value, spot + new Vector2(num4 * 84.5f, 0f), new Rectangle(value.Width - 4, 0, 4, value.Height), BackColor, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
252 position += Vector2.UnitX * (num - 0.5f) * num2;
253 position.X -= 1f;
254 spriteBatch.Draw(value2, position, new Rectangle(0, 0, 1, 1), FillingColor, 0f, new Vector2(1f, 0.5f), new Vector2(num2 * num, num3), SpriteEffects.None, 0f);
255 if (progress != 0f)
256 {
257 spriteBatch.Draw(value2, position, new Rectangle(0, 0, 1, 1), BlipColor, 0f, new Vector2(1f, 0.5f), new Vector2(2f, num3), SpriteEffects.None, 0f);
258 }
259 spriteBatch.Draw(value2, position, new Rectangle(0, 0, 1, 1), Color.Black, 0f, new Vector2(0f, 0.5f), new Vector2(num2 * (1f - num), num3), SpriteEffects.None, 0f);
260 }
261
262 public override int CompareTo(object obj)
263 {
264 if (!(obj is UIAchievementListItem uIAchievementListItem))
265 {
266 return 0;
267 }
268 if (_achievement.IsCompleted && !uIAchievementListItem._achievement.IsCompleted)
269 {
270 return -1;
271 }
272 if (!_achievement.IsCompleted && uIAchievementListItem._achievement.IsCompleted)
273 {
274 return 1;
275 }
276 return _achievement.Id.CompareTo(uIAchievementListItem._achievement.Id);
277 }
278}
void Draw(Texture2D texture, Vector2 position, Color color)
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
readonly LocalizedText Description
readonly LocalizedText FriendlyName
IAchievementTracker GetTracker()
static Asset< DynamicSpriteFont > ItemStack
Definition FontAssets.cs:8
static Asset< Texture2D > ColorBlip
static Asset< Texture2D > MagicPixel
static Asset< Texture2D > ColorBar
UIAchievementListItem(Achievement achievement, bool largeForOtherLanguages)
void DrawProgressBar(SpriteBatch spriteBatch, float progress, Vector2 spot, float Width=169f, Color BackColor=default(Color), Color FillingColor=default(Color), Color BlipColor=default(Color))
void DrawPanelBottom(SpriteBatch spriteBatch, Vector2 position, float width, Color color)
void DrawPanelTop(SpriteBatch spriteBatch, Vector2 position, float width, Color color)
static GameCulture ActiveCulture
Definition Language.cs:8
static AchievementManager Achievements
Definition Main.cs:2756
static IAssetRepository Assets
Definition Main.cs:209
static Vector2 DrawColorCodedStringWithShadow(SpriteBatch spriteBatch, DynamicSpriteFont font, TextSnippet[] snippets, Vector2 position, float rotation, Vector2 origin, Vector2 baseScale, out int hoveredSnippet, float maxWidth=-1f, float spread=2f)
static Vector2 GetStringSize(DynamicSpriteFont font, string text, Vector2 baseScale, float maxWidth=-1f)
StyleDimension Height
Definition UIElement.cs:29
void Append(UIElement element)
Definition UIElement.cs:166
CalculatedStyle GetInnerDimensions()
Definition UIElement.cs:377
StyleDimension Left
Definition UIElement.cs:25
StyleDimension Width
Definition UIElement.cs:27
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
StyleDimension Top
Definition UIElement.cs:23
static Color Transparent
Definition Color.cs:76
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491
void Set(float pixels, float precent)