Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UICharacterListItem.cs
Go to the documentation of this file.
1using System;
7using Terraria.ID;
8using Terraria.IO;
10using Terraria.Social;
11using Terraria.UI;
12
14
16{
18
20
22
24
26
28
30
32
34
36
38
40
42
44
45 public bool IsFavorite => _data.IsFavorite;
46
47 public UICharacterListItem(PlayerFileData data, int snapPointIndex)
48 {
49 BorderColor = new Color(89, 116, 213) * 0.7f;
50 _dividerTexture = Main.Assets.Request<Texture2D>("Images/UI/Divider", (AssetRequestMode)1);
51 _innerPanelTexture = Main.Assets.Request<Texture2D>("Images/UI/InnerPanelBackground", (AssetRequestMode)1);
52 _buttonCloudActiveTexture = Main.Assets.Request<Texture2D>("Images/UI/ButtonCloudActive", (AssetRequestMode)1);
53 _buttonCloudInactiveTexture = Main.Assets.Request<Texture2D>("Images/UI/ButtonCloudInactive", (AssetRequestMode)1);
54 _buttonFavoriteActiveTexture = Main.Assets.Request<Texture2D>("Images/UI/ButtonFavoriteActive", (AssetRequestMode)1);
55 _buttonFavoriteInactiveTexture = Main.Assets.Request<Texture2D>("Images/UI/ButtonFavoriteInactive", (AssetRequestMode)1);
56 _buttonPlayTexture = Main.Assets.Request<Texture2D>("Images/UI/ButtonPlay", (AssetRequestMode)1);
57 _buttonRenameTexture = Main.Assets.Request<Texture2D>("Images/UI/ButtonRename", (AssetRequestMode)1);
58 _buttonDeleteTexture = Main.Assets.Request<Texture2D>("Images/UI/ButtonDelete", (AssetRequestMode)1);
59 Height.Set(96f, 0f);
60 Width.Set(0f, 1f);
61 SetPadding(6f);
62 _data = data;
63 _playerPanel = new UICharacter(data.Player, animated: false, hasBackPanel: true, 1f, useAClone: true);
64 _playerPanel.Left.Set(4f, 0f);
65 _playerPanel.OnLeftDoubleClick += PlayGame;
66 base.OnLeftDoubleClick += PlayGame;
68 float num = 4f;
70 uIImageButton.VAlign = 1f;
71 uIImageButton.Left.Set(num, 0f);
72 uIImageButton.OnLeftClick += PlayGame;
73 uIImageButton.OnMouseOver += PlayMouseOver;
74 uIImageButton.OnMouseOut += ButtonMouseOut;
75 Append(uIImageButton);
76 num += 24f;
78 uIImageButton2.VAlign = 1f;
79 uIImageButton2.Left.Set(num, 0f);
80 uIImageButton2.OnLeftClick += FavoriteButtonClick;
81 uIImageButton2.OnMouseOver += FavoriteMouseOver;
82 uIImageButton2.OnMouseOut += ButtonMouseOut;
83 uIImageButton2.SetVisibility(1f, _data.IsFavorite ? 0.8f : 0.4f);
84 Append(uIImageButton2);
85 num += 24f;
86 if (SocialAPI.Cloud != null)
87 {
89 uIImageButton3.VAlign = 1f;
90 uIImageButton3.Left.Set(num, 0f);
91 uIImageButton3.OnLeftClick += CloudButtonClick;
92 uIImageButton3.OnMouseOver += CloudMouseOver;
93 uIImageButton3.OnMouseOut += ButtonMouseOut;
94 Append(uIImageButton3);
95 uIImageButton3.SetSnapPoint("Cloud", snapPointIndex);
96 num += 24f;
97 }
99 uIImageButton4.VAlign = 1f;
100 uIImageButton4.Left.Set(num, 0f);
101 uIImageButton4.OnLeftClick += RenameButtonClick;
102 uIImageButton4.OnMouseOver += RenameMouseOver;
103 uIImageButton4.OnMouseOut += ButtonMouseOut;
104 Append(uIImageButton4);
105 num += 24f;
107 {
108 VAlign = 1f,
109 HAlign = 1f
110 };
111 if (!_data.IsFavorite)
112 {
113 uIImageButton5.OnLeftClick += DeleteButtonClick;
114 }
115 uIImageButton5.OnMouseOver += DeleteMouseOver;
116 uIImageButton5.OnMouseOut += DeleteMouseOut;
117 _deleteButton = uIImageButton5;
118 Append(uIImageButton5);
119 num += 4f;
120 _buttonLabel = new UIText("");
121 _buttonLabel.VAlign = 1f;
122 _buttonLabel.Left.Set(num, 0f);
123 _buttonLabel.Top.Set(-3f, 0f);
125 _deleteButtonLabel = new UIText("");
126 _deleteButtonLabel.VAlign = 1f;
127 _deleteButtonLabel.HAlign = 1f;
128 _deleteButtonLabel.Left.Set(-30f, 0f);
129 _deleteButtonLabel.Top.Set(-3f, 0f);
131 uIImageButton.SetSnapPoint("Play", snapPointIndex);
132 uIImageButton2.SetSnapPoint("Favorite", snapPointIndex);
133 uIImageButton4.SetSnapPoint("Rename", snapPointIndex);
134 uIImageButton5.SetSnapPoint("Delete", snapPointIndex);
135 }
136
137 private void RenameMouseOver(UIMouseEvent evt, UIElement listeningElement)
138 {
140 }
141
142 private void FavoriteMouseOver(UIMouseEvent evt, UIElement listeningElement)
143 {
144 if (_data.IsFavorite)
145 {
146 _buttonLabel.SetText(Language.GetTextValue("UI.Unfavorite"));
147 }
148 else
149 {
151 }
152 }
153
154 private void CloudMouseOver(UIMouseEvent evt, UIElement listeningElement)
155 {
156 if (_data.IsCloudSave)
157 {
158 _buttonLabel.SetText(Language.GetTextValue("UI.MoveOffCloud"));
159 }
160 else
161 {
162 _buttonLabel.SetText(Language.GetTextValue("UI.MoveToCloud"));
163 }
164 }
165
166 private void PlayMouseOver(UIMouseEvent evt, UIElement listeningElement)
167 {
169 }
170
171 private void DeleteMouseOver(UIMouseEvent evt, UIElement listeningElement)
172 {
173 if (_data.IsFavorite)
174 {
175 _deleteButtonLabel.SetText(Language.GetTextValue("UI.CannotDeleteFavorited"));
176 }
177 else
178 {
180 }
181 }
182
183 private void DeleteMouseOut(UIMouseEvent evt, UIElement listeningElement)
184 {
186 }
187
188 private void ButtonMouseOut(UIMouseEvent evt, UIElement listeningElement)
189 {
191 }
192
193 private void RenameButtonClick(UIMouseEvent evt, UIElement listeningElement)
194 {
196 Main.clrInput();
197 UIVirtualKeyboard uIVirtualKeyboard = new UIVirtualKeyboard(Lang.menu[45].Value, "", OnFinishedSettingName, GoBackHere, 0, allowEmpty: true);
198 uIVirtualKeyboard.SetMaxInputLength(20);
199 Main.MenuUI.SetState(uIVirtualKeyboard);
200 if (base.Parent.Parent is UIList uIList)
201 {
202 uIList.UpdateOrder();
203 }
204 }
205
206 private void OnFinishedSettingName(string name)
207 {
208 string newName = name.Trim();
209 Main.menuMode = 10;
210 _data.Rename(newName);
212 }
213
214 private void GoBackHere()
215 {
217 }
218
219 private void CloudButtonClick(UIMouseEvent evt, UIElement listeningElement)
220 {
221 if (_data.IsCloudSave)
222 {
224 }
225 else
226 {
228 }
230 if (_data.IsCloudSave)
231 {
232 _buttonLabel.SetText(Language.GetTextValue("UI.MoveOffCloud"));
233 }
234 else
235 {
236 _buttonLabel.SetText(Language.GetTextValue("UI.MoveToCloud"));
237 }
238 }
239
240 private void DeleteButtonClick(UIMouseEvent evt, UIElement listeningElement)
241 {
242 for (int i = 0; i < Main.PlayerList.Count; i++)
243 {
244 if (Main.PlayerList[i] == _data)
245 {
247 Main.selectedPlayer = i;
248 Main.menuMode = 5;
249 break;
250 }
251 }
252 }
253
254 private void PlayGame(UIMouseEvent evt, UIElement listeningElement)
255 {
256 if (listeningElement == evt.Target && _data.Player.loadStatus == 0)
257 {
259 }
260 }
261
262 private void FavoriteButtonClick(UIMouseEvent evt, UIElement listeningElement)
263 {
266 ((UIImageButton)evt.Target).SetVisibility(1f, _data.IsFavorite ? 0.8f : 0.4f);
267 if (_data.IsFavorite)
268 {
269 _buttonLabel.SetText(Language.GetTextValue("UI.Unfavorite"));
270 _deleteButton.OnLeftClick -= DeleteButtonClick;
271 }
272 else
273 {
275 _deleteButton.OnLeftClick += DeleteButtonClick;
276 }
277 if (base.Parent.Parent is UIList uIList)
278 {
279 uIList.UpdateOrder();
280 }
281 }
282
283 public override int CompareTo(object obj)
284 {
285 if (obj is UICharacterListItem uICharacterListItem)
286 {
287 if (IsFavorite && !uICharacterListItem.IsFavorite)
288 {
289 return -1;
290 }
291 if (!IsFavorite && uICharacterListItem.IsFavorite)
292 {
293 return 1;
294 }
295 if (_data.Name.CompareTo(uICharacterListItem._data.Name) != 0)
296 {
297 return _data.Name.CompareTo(uICharacterListItem._data.Name);
298 }
299 return _data.GetFileName().CompareTo(uICharacterListItem._data.GetFileName());
300 }
301 return base.CompareTo(obj);
302 }
303
304 public override void MouseOver(UIMouseEvent evt)
305 {
306 base.MouseOver(evt);
307 BackgroundColor = new Color(73, 94, 171);
308 BorderColor = new Color(89, 116, 213);
309 _playerPanel.SetAnimated(animated: true);
310 }
311
312 public override void MouseOut(UIMouseEvent evt)
313 {
314 base.MouseOut(evt);
315 BackgroundColor = new Color(63, 82, 151) * 0.7f;
316 BorderColor = new Color(89, 116, 213) * 0.7f;
317 _playerPanel.SetAnimated(animated: false);
318 }
319
320 private void DrawPanel(SpriteBatch spriteBatch, Vector2 position, float width)
321 {
322 spriteBatch.Draw(_innerPanelTexture.Value, position, new Rectangle(0, 0, 8, _innerPanelTexture.Height()), Color.White);
323 spriteBatch.Draw(_innerPanelTexture.Value, new Vector2(position.X + 8f, position.Y), new Rectangle(8, 0, 8, _innerPanelTexture.Height()), Color.White, 0f, Vector2.Zero, new Vector2((width - 16f) / 8f, 1f), SpriteEffects.None, 0f);
324 spriteBatch.Draw(_innerPanelTexture.Value, new Vector2(position.X + width - 8f, position.Y), new Rectangle(16, 0, 8, _innerPanelTexture.Height()), Color.White);
325 }
326
327 protected override void DrawSelf(SpriteBatch spriteBatch)
328 {
329 base.DrawSelf(spriteBatch);
330 CalculatedStyle innerDimensions = GetInnerDimensions();
332 float num = dimensions.X + dimensions.Width;
333 Color color = Color.White;
334 string text = _data.Name;
335 if (_data.Player.loadStatus != 0)
336 {
337 color = Color.Gray;
338 string name = StatusID.Search.GetName(_data.Player.loadStatus);
339 text = "(" + name + ") " + text;
340 }
341 Utils.DrawBorderString(spriteBatch, text, new Vector2(num + 6f, dimensions.Y - 2f), color);
342 spriteBatch.Draw(_dividerTexture.Value, new Vector2(num, innerDimensions.Y + 21f), null, Color.White, 0f, Vector2.Zero, new Vector2((GetDimensions().X + GetDimensions().Width - num) / 8f, 1f), SpriteEffects.None, 0f);
343 Vector2 vector = new Vector2(num + 6f, innerDimensions.Y + 29f);
344 float num2 = 200f;
345 Vector2 vector2 = vector;
346 DrawPanel(spriteBatch, vector2, num2);
347 spriteBatch.Draw(TextureAssets.Heart.Value, vector2 + new Vector2(5f, 2f), Color.White);
348 vector2.X += 10f + (float)TextureAssets.Heart.Width();
349 Utils.DrawBorderString(spriteBatch, _data.Player.statLifeMax + Language.GetTextValue("GameUI.PlayerLifeMax"), vector2 + new Vector2(0f, 3f), Color.White);
350 vector2.X += 65f;
351 spriteBatch.Draw(TextureAssets.Mana.Value, vector2 + new Vector2(5f, 2f), Color.White);
352 vector2.X += 10f + (float)TextureAssets.Mana.Width();
353 Utils.DrawBorderString(spriteBatch, _data.Player.statManaMax + Language.GetTextValue("GameUI.PlayerManaMax"), vector2 + new Vector2(0f, 3f), Color.White);
354 vector.X += num2 + 5f;
355 Vector2 vector3 = vector;
356 float num3 = 140f;
358 {
359 num3 = 180f;
360 }
361 DrawPanel(spriteBatch, vector3, num3);
362 string text2 = "";
363 Color color2 = Color.White;
364 switch (_data.Player.difficulty)
365 {
366 case 0:
367 text2 = Language.GetTextValue("UI.Softcore");
368 break;
369 case 1:
370 text2 = Language.GetTextValue("UI.Mediumcore");
371 color2 = Main.mcColor;
372 break;
373 case 2:
374 text2 = Language.GetTextValue("UI.Hardcore");
375 color2 = Main.hcColor;
376 break;
377 case 3:
378 text2 = Language.GetTextValue("UI.Creative");
379 color2 = Main.creativeModeColor;
380 break;
381 }
382 vector3 += new Vector2(num3 * 0.5f - FontAssets.MouseText.Value.MeasureString(text2).X * 0.5f, 3f);
383 Utils.DrawBorderString(spriteBatch, text2, vector3, color2);
384 vector.X += num3 + 5f;
385 Vector2 vector4 = vector;
386 float num4 = innerDimensions.X + innerDimensions.Width - vector4.X;
387 DrawPanel(spriteBatch, vector4, num4);
388 TimeSpan playTime = _data.GetPlayTime();
389 int num5 = playTime.Days * 24 + playTime.Hours;
390 string text3 = ((num5 < 10) ? "0" : "") + num5 + playTime.ToString("\\:mm\\:ss");
391 vector4 += new Vector2(num4 * 0.5f - FontAssets.MouseText.Value.MeasureString(text3).X * 0.5f, 3f);
392 Utils.DrawBorderString(spriteBatch, text3, vector4, Color.White);
393 }
394}
void Draw(Texture2D texture, Vector2 position, Color color)
static void PlaySound(int type, Vector2 position, int style=1)
static Asset< DynamicSpriteFont > MouseText
Definition FontAssets.cs:10
static Asset< Texture2D > Mana
static Asset< Texture2D > Heart
void PlayGame(UIMouseEvent evt, UIElement listeningElement)
void FavoriteMouseOver(UIMouseEvent evt, UIElement listeningElement)
void DeleteMouseOut(UIMouseEvent evt, UIElement listeningElement)
void DeleteMouseOver(UIMouseEvent evt, UIElement listeningElement)
void FavoriteButtonClick(UIMouseEvent evt, UIElement listeningElement)
void PlayMouseOver(UIMouseEvent evt, UIElement listeningElement)
UICharacterListItem(PlayerFileData data, int snapPointIndex)
override void DrawSelf(SpriteBatch spriteBatch)
void ButtonMouseOut(UIMouseEvent evt, UIElement listeningElement)
void RenameButtonClick(UIMouseEvent evt, UIElement listeningElement)
void CloudButtonClick(UIMouseEvent evt, UIElement listeningElement)
void DrawPanel(SpriteBatch spriteBatch, Vector2 position, float width)
void RenameMouseOver(UIMouseEvent evt, UIElement listeningElement)
void DeleteButtonClick(UIMouseEvent evt, UIElement listeningElement)
void CloudMouseOver(UIMouseEvent evt, UIElement listeningElement)
void SetVisibility(float whenActive, float whenInactive)
static readonly IdDictionary Search
Definition StatusID.cs:21
string GetFileName(bool includeExtension=true)
Definition FileData.cs:43
void Rename(string newName)
static LocalizedText[] menu
Definition Lang.cs:19
static GameCulture FromCultureName(CultureName name)
static string GetTextValue(string key)
Definition Language.cs:15
static Microsoft.Xna.Framework.Color hcColor
Definition Main.cs:994
static UserInterface MenuUI
Definition Main.cs:381
static Microsoft.Xna.Framework.Color creativeModeColor
Definition Main.cs:996
static Microsoft.Xna.Framework.Color mcColor
Definition Main.cs:992
static List< PlayerFileData > PlayerList
Definition Main.cs:1938
static void SelectPlayer(PlayerFileData data)
Definition Main.cs:62943
static void OpenCharacterSelectUI()
Definition Main.cs:49236
static void clrInput()
Definition Main.cs:18584
static IAssetRepository Assets
Definition Main.cs:209
static Terraria.Social.Base.CloudSocialModule Cloud
Definition SocialAPI.cs:18
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
void SetSnapPoint(string name, int id, Vector2? anchor=null, Vector2? offset=null)
Definition UIElement.cs:122
StyleDimension Width
Definition UIElement.cs:27
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
void SetPadding(float pixels)
Definition UIElement.cs:361
StyleDimension Top
Definition UIElement.cs:23
readonly UIElement Target
Definition UIEvent.cs:5
static Vector2 DrawBorderString(SpriteBatch sb, string text, Vector2 pos, Color color, float scale=1f, float anchorx=0f, float anchory=0f, int maxCharactersDisplayed=-1)
Definition Utils.cs:1891
override string ToString()
Definition TimeSpan.cs:476
void Set(float pixels, float precent)