Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ChestUI.cs
Go to the documentation of this file.
4using Microsoft.Xna.Framework.Input;
12
13namespace Terraria.UI;
14
15public class ChestUI
16{
17 public class ButtonID
18 {
19 public const int LootAll = 0;
20
21 public const int DepositAll = 1;
22
23 public const int QuickStack = 2;
24
25 public const int Restock = 3;
26
27 public const int Sort = 4;
28
29 public const int RenameChest = 5;
30
31 public const int RenameChestCancel = 6;
32
33 public const int ToggleVacuum = 7;
34
35 public static readonly int Count = 7;
36 }
37
38 public const float buttonScaleMinimum = 0.75f;
39
40 public const float buttonScaleMaximum = 1f;
41
42 public static float[] ButtonScale = new float[ButtonID.Count];
43
44 public static bool[] ButtonHovered = new bool[ButtonID.Count];
45
46 public static void UpdateHover(int ID, bool hovering)
47 {
48 if (hovering)
49 {
50 if (!ButtonHovered[ID])
51 {
53 }
54 ButtonHovered[ID] = true;
55 ButtonScale[ID] += 0.05f;
56 if (ButtonScale[ID] > 1f)
57 {
58 ButtonScale[ID] = 1f;
59 }
60 }
61 else
62 {
63 ButtonHovered[ID] = false;
64 ButtonScale[ID] -= 0.05f;
65 if (ButtonScale[ID] < 0.75f)
66 {
67 ButtonScale[ID] = 0.75f;
68 }
69 }
70 }
71
72 public static void Draw(SpriteBatch spritebatch)
73 {
74 if (Main.player[Main.myPlayer].chest != -1 && !Main.recBigList)
75 {
76 Main.inventoryScale = 0.755f;
77 if (Utils.FloatIntersect(Main.mouseX, Main.mouseY, 0f, 0f, 73f, Main.instance.invBottom, 560f * Main.inventoryScale, 224f * Main.inventoryScale))
78 {
79 Main.player[Main.myPlayer].mouseInterface = true;
80 }
84 }
85 else
86 {
87 for (int i = 0; i < ButtonID.Count; i++)
88 {
89 ButtonScale[i] = 0.75f;
90 ButtonHovered[i] = false;
91 }
92 }
93 }
94
95 private static void DrawName(SpriteBatch spritebatch)
96 {
97 Player player = Main.player[Main.myPlayer];
98 string text = string.Empty;
99 if (Main.editChest)
100 {
101 text = Main.npcChatText;
102 Main.instance.textBlinkerCount++;
103 if (Main.instance.textBlinkerCount >= 20)
104 {
105 if (Main.instance.textBlinkerState == 0)
106 {
107 Main.instance.textBlinkerState = 1;
108 }
109 else
110 {
111 Main.instance.textBlinkerState = 0;
112 }
113 Main.instance.textBlinkerCount = 0;
114 }
115 if (Main.instance.textBlinkerState == 1)
116 {
117 text += "|";
118 }
119 Main.instance.DrawWindowsIMEPanel(new Vector2(120f, 518f));
120 }
121 else if (player.chest > -1)
122 {
123 if (Main.chest[player.chest] == null)
124 {
125 Main.chest[player.chest] = new Chest();
126 }
127 Chest chest = Main.chest[player.chest];
128 if (chest.name != "")
129 {
130 text = chest.name;
131 }
132 else
133 {
134 Tile tile = Main.tile[player.chestX, player.chestY];
135 if (tile.type == 21)
136 {
137 text = Lang.chestType[tile.frameX / 36].Value;
138 }
139 else if (tile.type == 467 && tile.frameX / 36 == 4)
140 {
141 text = Lang.GetItemNameValue(3988);
142 }
143 else if (tile.type == 467)
144 {
145 text = Lang.chestType2[tile.frameX / 36].Value;
146 }
147 else if (tile.type == 88)
148 {
149 text = Lang.dresserType[tile.frameX / 54].Value;
150 }
151 }
152 }
153 else if (player.chest == -2)
154 {
155 text = Lang.inter[32].Value;
156 }
157 else if (player.chest == -3)
158 {
159 text = Lang.inter[33].Value;
160 }
161 else if (player.chest == -4)
162 {
163 text = Lang.GetItemNameValue(3813);
164 }
165 else if (player.chest == -5)
166 {
167 text = Lang.GetItemNameValue(4076);
168 }
170 color = Color.White * (1f - (255f - (float)(int)Main.mouseTextColor) / 255f * 0.5f);
171 color.A = byte.MaxValue;
173 lineAmount++;
174 for (int i = 0; i < lineAmount; i++)
175 {
176 ChatManager.DrawColorCodedStringWithShadow(spritebatch, FontAssets.MouseText.Value, text, new Vector2(504f, Main.instance.invBottom + i * 26), color, 0f, Vector2.Zero, Vector2.One, -1f, 1.5f);
177 }
178 }
179
181 {
182 for (int i = 0; i < ButtonID.Count; i++)
183 {
184 DrawButton(spritebatch, i, 506, Main.instance.invBottom + 40);
185 }
186 }
187
188 private static void DrawButton(SpriteBatch spriteBatch, int ID, int X, int Y)
189 {
190 Player player = Main.player[Main.myPlayer];
191 if ((ID == 5 && player.chest < -1) || (ID == 6 && !Main.editChest))
192 {
193 UpdateHover(ID, hovering: false);
194 return;
195 }
196 if (ID == 7 && player.chest != -5)
197 {
198 UpdateHover(ID, hovering: false);
199 return;
200 }
201 int num = ID;
202 if (ID == 7)
203 {
204 num = 5;
205 }
206 Y += num * 26;
207 float num2 = ButtonScale[ID];
208 string text = "";
209 switch (ID)
210 {
211 case 0:
212 text = Lang.inter[29].Value;
213 break;
214 case 1:
215 text = Lang.inter[30].Value;
216 break;
217 case 2:
218 text = Lang.inter[31].Value;
219 break;
220 case 3:
221 text = Lang.inter[82].Value;
222 break;
223 case 5:
224 text = Lang.inter[Main.editChest ? 47 : 61].Value;
225 break;
226 case 6:
227 text = Lang.inter[63].Value;
228 break;
229 case 4:
230 text = Lang.inter[122].Value;
231 break;
232 case 7:
233 text = ((!player.IsVoidVaultEnabled) ? Language.GetTextValue("UI.ToggleBank4VacuumIsOff") : Language.GetTextValue("UI.ToggleBank4VacuumIsOn"));
234 break;
235 }
236 Vector2 vector = FontAssets.MouseText.Value.MeasureString(text);
238 color = Color.White * 0.97f * (1f - (255f - (float)(int)Main.mouseTextColor) / 255f * 0.5f);
239 color.A = byte.MaxValue;
240 X += (int)(vector.X * num2 / 2f);
241 bool flag = Utils.FloatIntersect(Main.mouseX, Main.mouseY, 0f, 0f, (float)X - vector.X / 2f, Y - 12, vector.X, 24f);
242 if (ButtonHovered[ID])
243 {
244 flag = Utils.FloatIntersect(Main.mouseX, Main.mouseY, 0f, 0f, (float)X - vector.X / 2f - 10f, Y - 12, vector.X + 16f, 24f);
245 }
246 if (flag)
247 {
248 color = Main.OurFavoriteColor;
249 }
250 ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.MouseText.Value, text, new Vector2(X, Y), color, 0f, vector / 2f, new Vector2(num2), -1f, 1.5f);
251 vector *= num2;
252 switch (ID)
253 {
254 case 0:
255 UILinkPointNavigator.SetPosition(500, new Vector2((float)X - vector.X * num2 / 2f * 0.8f, Y));
256 break;
257 case 1:
258 UILinkPointNavigator.SetPosition(501, new Vector2((float)X - vector.X * num2 / 2f * 0.8f, Y));
259 break;
260 case 2:
261 UILinkPointNavigator.SetPosition(502, new Vector2((float)X - vector.X * num2 / 2f * 0.8f, Y));
262 break;
263 case 5:
265 break;
266 case 6:
268 break;
269 case 3:
270 UILinkPointNavigator.SetPosition(503, new Vector2((float)X - vector.X * num2 / 2f * 0.8f, Y));
271 break;
272 case 4:
273 UILinkPointNavigator.SetPosition(505, new Vector2((float)X - vector.X * num2 / 2f * 0.8f, Y));
274 break;
275 case 7:
276 UILinkPointNavigator.SetPosition(506, new Vector2((float)X - vector.X * num2 / 2f * 0.8f, Y));
277 break;
278 }
279 if (!flag)
280 {
281 UpdateHover(ID, hovering: false);
282 return;
283 }
284 UpdateHover(ID, hovering: true);
286 {
287 return;
288 }
289 player.mouseInterface = true;
291 {
292 switch (ID)
293 {
294 case 0:
295 LootAll();
296 break;
297 case 1:
299 break;
300 case 2:
302 break;
303 case 5:
304 RenameChest();
305 break;
306 case 6:
308 break;
309 case 3:
310 Restock();
311 break;
312 case 4:
314 break;
315 case 7:
316 ToggleVacuum();
317 break;
318 }
320 }
321 }
322
323 private static void ToggleVacuum()
324 {
326 obj.IsVoidVaultEnabled = !obj.IsVoidVaultEnabled;
327 }
328
329 private static void DrawSlots(SpriteBatch spriteBatch)
330 {
331 Player player = Main.player[Main.myPlayer];
332 int context = 0;
333 Item[] inv = null;
334 if (player.chest > -1)
335 {
336 context = 3;
337 inv = Main.chest[player.chest].item;
338 }
339 if (player.chest == -2)
340 {
341 context = 4;
342 inv = player.bank.item;
343 }
344 if (player.chest == -3)
345 {
346 context = 4;
347 inv = player.bank2.item;
348 }
349 if (player.chest == -4)
350 {
351 context = 4;
352 inv = player.bank3.item;
353 }
354 if (player.chest == -5)
355 {
356 context = 32;
357 inv = player.bank4.item;
358 }
359 Main.inventoryScale = 0.755f;
361 {
362 player.mouseInterface = true;
363 }
364 for (int i = 0; i < 10; i++)
365 {
366 for (int j = 0; j < 4; j++)
367 {
368 int num = (int)(73f + (float)(i * 56) * Main.inventoryScale);
369 int num2 = (int)((float)Main.instance.invBottom + (float)(j * 56) * Main.inventoryScale);
370 int slot = i + j * 10;
371 new Color(100, 100, 100, 100);
373 {
374 player.mouseInterface = true;
375 ItemSlot.Handle(inv, context, slot);
376 }
377 ItemSlot.Draw(spriteBatch, inv, context, slot, new Vector2(num, num2));
378 }
379 }
380 }
381
382 public static void LootAll()
383 {
385 Player player = Main.player[Main.myPlayer];
386 if (player.chest > -1)
387 {
389 Chest chest = Main.chest[player.chest];
390 for (int i = 0; i < 40; i++)
391 {
392 if (chest.item[i].type > 0)
393 {
394 chest.item[i].position = player.Center;
395 chest.item[i] = player.GetItem(Main.myPlayer, chest.item[i], lootAllSettingsRegularChest);
396 if (Main.netMode == 1)
397 {
398 NetMessage.SendData(32, -1, -1, null, player.chest, i);
399 }
400 }
401 }
402 return;
403 }
404 if (player.chest == -3)
405 {
406 for (int j = 0; j < 40; j++)
407 {
408 if (player.bank2.item[j].type > 0)
409 {
410 player.bank2.item[j].position = player.Center;
411 player.bank2.item[j] = player.GetItem(Main.myPlayer, player.bank2.item[j], lootAllSettings);
412 }
413 }
414 return;
415 }
416 if (player.chest == -4)
417 {
418 for (int k = 0; k < 40; k++)
419 {
420 if (player.bank3.item[k].type > 0)
421 {
422 player.bank3.item[k].position = player.Center;
423 player.bank3.item[k] = player.GetItem(Main.myPlayer, player.bank3.item[k], lootAllSettings);
424 }
425 }
426 return;
427 }
428 if (player.chest == -5)
429 {
430 for (int l = 0; l < 40; l++)
431 {
432 if (player.bank4.item[l].type > 0 && !player.bank4.item[l].favorited)
433 {
434 player.bank4.item[l].position = player.Center;
435 player.bank4.item[l] = player.GetItem(Main.myPlayer, player.bank4.item[l], lootAllSettings);
436 }
437 }
438 return;
439 }
440 for (int m = 0; m < 40; m++)
441 {
442 if (player.bank.item[m].type > 0)
443 {
444 player.bank.item[m].position = player.Center;
445 player.bank.item[m] = player.GetItem(Main.myPlayer, player.bank.item[m], lootAllSettings);
446 }
447 }
448 }
449
450 public static void DepositAll(ContainerTransferContext context)
451 {
452 Player player = Main.player[Main.myPlayer];
453 if (player.chest > -1)
454 {
455 MoveCoins(player.inventory, Main.chest[player.chest].item, context);
456 }
457 else if (player.chest == -3)
458 {
459 MoveCoins(player.inventory, player.bank2.item, context);
460 }
461 else if (player.chest == -4)
462 {
463 MoveCoins(player.inventory, player.bank3.item, context);
464 }
465 else if (player.chest == -5)
466 {
467 MoveCoins(player.inventory, player.bank4.item, context);
468 }
469 else
470 {
471 MoveCoins(player.inventory, player.bank.item, context);
472 }
473 for (int num = 49; num >= 10; num--)
474 {
475 if (player.inventory[num].stack > 0 && player.inventory[num].type > 0 && !player.inventory[num].favorited)
476 {
477 if (player.inventory[num].maxStack > 1)
478 {
479 for (int i = 0; i < 40; i++)
480 {
481 if (player.chest > -1)
482 {
483 Chest chest = Main.chest[player.chest];
484 if (chest.item[i].stack >= chest.item[i].maxStack || !player.inventory[num].IsTheSameAs(chest.item[i]))
485 {
486 continue;
487 }
488 int num2 = player.inventory[num].stack;
489 if (player.inventory[num].stack + chest.item[i].stack > chest.item[i].maxStack)
490 {
491 num2 = chest.item[i].maxStack - chest.item[i].stack;
492 }
493 player.inventory[num].stack -= num2;
494 chest.item[i].stack += num2;
496 if (player.inventory[num].stack <= 0)
497 {
498 player.inventory[num].SetDefaults();
499 if (Main.netMode == 1)
500 {
501 NetMessage.SendData(32, -1, -1, null, player.chest, i);
502 }
503 break;
504 }
505 if (chest.item[i].type == 0)
506 {
507 chest.item[i] = player.inventory[num].Clone();
508 player.inventory[num].SetDefaults();
509 }
510 if (Main.netMode == 1)
511 {
512 NetMessage.SendData(32, -1, -1, null, player.chest, i);
513 }
514 }
515 else if (player.chest == -3)
516 {
517 if (player.bank2.item[i].stack < player.bank2.item[i].maxStack && player.inventory[num].IsTheSameAs(player.bank2.item[i]))
518 {
519 int num3 = player.inventory[num].stack;
520 if (player.inventory[num].stack + player.bank2.item[i].stack > player.bank2.item[i].maxStack)
521 {
522 num3 = player.bank2.item[i].maxStack - player.bank2.item[i].stack;
523 }
524 player.inventory[num].stack -= num3;
525 player.bank2.item[i].stack += num3;
527 if (player.inventory[num].stack <= 0)
528 {
529 player.inventory[num].SetDefaults();
530 break;
531 }
532 if (player.bank2.item[i].type == 0)
533 {
534 player.bank2.item[i] = player.inventory[num].Clone();
535 player.inventory[num].SetDefaults();
536 }
537 }
538 }
539 else if (player.chest == -4)
540 {
541 if (player.bank3.item[i].stack < player.bank3.item[i].maxStack && player.inventory[num].IsTheSameAs(player.bank3.item[i]))
542 {
543 int num4 = player.inventory[num].stack;
544 if (player.inventory[num].stack + player.bank3.item[i].stack > player.bank3.item[i].maxStack)
545 {
546 num4 = player.bank3.item[i].maxStack - player.bank3.item[i].stack;
547 }
548 player.inventory[num].stack -= num4;
549 player.bank3.item[i].stack += num4;
551 if (player.inventory[num].stack <= 0)
552 {
553 player.inventory[num].SetDefaults();
554 break;
555 }
556 if (player.bank3.item[i].type == 0)
557 {
558 player.bank3.item[i] = player.inventory[num].Clone();
559 player.inventory[num].SetDefaults();
560 }
561 }
562 }
563 else if (player.chest == -5)
564 {
565 if (player.bank4.item[i].stack < player.bank4.item[i].maxStack && player.inventory[num].IsTheSameAs(player.bank4.item[i]))
566 {
567 int num5 = player.inventory[num].stack;
568 if (player.inventory[num].stack + player.bank4.item[i].stack > player.bank4.item[i].maxStack)
569 {
570 num5 = player.bank4.item[i].maxStack - player.bank4.item[i].stack;
571 }
572 player.inventory[num].stack -= num5;
573 player.bank4.item[i].stack += num5;
575 if (player.inventory[num].stack <= 0)
576 {
577 player.inventory[num].SetDefaults();
578 break;
579 }
580 if (player.bank4.item[i].type == 0)
581 {
582 player.bank4.item[i] = player.inventory[num].Clone();
583 player.inventory[num].SetDefaults();
584 }
585 }
586 }
587 else if (player.bank.item[i].stack < player.bank.item[i].maxStack && player.inventory[num].IsTheSameAs(player.bank.item[i]))
588 {
589 int num6 = player.inventory[num].stack;
590 if (player.inventory[num].stack + player.bank.item[i].stack > player.bank.item[i].maxStack)
591 {
592 num6 = player.bank.item[i].maxStack - player.bank.item[i].stack;
593 }
594 player.inventory[num].stack -= num6;
595 player.bank.item[i].stack += num6;
597 if (player.inventory[num].stack <= 0)
598 {
599 player.inventory[num].SetDefaults();
600 break;
601 }
602 if (player.bank.item[i].type == 0)
603 {
604 player.bank.item[i] = player.inventory[num].Clone();
605 player.inventory[num].SetDefaults();
606 }
607 }
608 }
609 }
610 if (player.inventory[num].stack > 0)
611 {
612 if (player.chest > -1)
613 {
614 for (int j = 0; j < 40; j++)
615 {
616 if (Main.chest[player.chest].item[j].stack == 0)
617 {
619 Main.chest[player.chest].item[j] = player.inventory[num].Clone();
620 player.inventory[num].SetDefaults();
621 if (Main.netMode == 1)
622 {
623 NetMessage.SendData(32, -1, -1, null, player.chest, j);
624 }
625 break;
626 }
627 }
628 }
629 else if (player.chest == -3)
630 {
631 for (int k = 0; k < 40; k++)
632 {
633 if (player.bank2.item[k].stack == 0)
634 {
636 player.bank2.item[k] = player.inventory[num].Clone();
637 player.inventory[num].SetDefaults();
638 break;
639 }
640 }
641 }
642 else if (player.chest == -4)
643 {
644 for (int l = 0; l < 40; l++)
645 {
646 if (player.bank3.item[l].stack == 0)
647 {
649 player.bank3.item[l] = player.inventory[num].Clone();
650 player.inventory[num].SetDefaults();
651 break;
652 }
653 }
654 }
655 else if (player.chest == -5)
656 {
657 for (int m = 0; m < 40; m++)
658 {
659 if (player.bank4.item[m].stack == 0)
660 {
662 player.bank4.item[m] = player.inventory[num].Clone();
663 player.inventory[num].SetDefaults();
664 break;
665 }
666 }
667 }
668 else
669 {
670 for (int n = 0; n < 40; n++)
671 {
672 if (player.bank.item[n].stack == 0)
673 {
675 player.bank.item[n] = player.inventory[num].Clone();
676 player.inventory[num].SetDefaults();
677 break;
678 }
679 }
680 }
681 }
682 }
683 }
684 }
685
686 public static void QuickStack(ContainerTransferContext context, bool voidStack = false)
687 {
688 Player player = Main.player[Main.myPlayer];
689 Item[] array = player.inventory;
690 if (voidStack)
691 {
692 array = player.bank4.item;
693 }
694 Vector2 center = player.Center;
697 if (!voidStack && player.chest == -5)
698 {
699 long coinsMoved = MoveCoins(array, player.bank4.item, context);
701 {
703 }
704 }
705 else if (player.chest == -4)
706 {
707 long coinsMoved2 = MoveCoins(array, player.bank3.item, context);
709 {
711 }
712 }
713 else if (player.chest == -3)
714 {
715 long coinsMoved3 = MoveCoins(array, player.bank2.item, context);
717 {
719 }
720 }
721 else if (player.chest == -2)
722 {
723 long coinsMoved4 = MoveCoins(array, player.bank.item, context);
725 {
727 }
728 }
729 Item[] item = player.bank.item;
730 if (player.chest > -1)
731 {
732 item = Main.chest[player.chest].item;
733 }
734 else if (player.chest == -2)
735 {
736 item = player.bank.item;
737 }
738 else if (player.chest == -3)
739 {
740 item = player.bank2.item;
741 }
742 else if (player.chest == -4)
743 {
744 item = player.bank3.item;
745 }
746 else if (!voidStack && player.chest == -5)
747 {
748 item = player.bank4.item;
749 }
750 List<int> list = new List<int>();
751 List<int> list2 = new List<int>();
752 List<int> list3 = new List<int>();
754 List<int> list4 = new List<int>();
755 bool[] array2 = new bool[item.Length];
756 for (int i = 0; i < 40; i++)
757 {
758 if (item[i].type > 0 && item[i].stack > 0 && (item[i].type < 71 || item[i].type > 74))
759 {
760 list2.Add(i);
761 list.Add(item[i].netID);
762 }
763 if (item[i].type == 0 || item[i].stack <= 0)
764 {
765 list3.Add(i);
766 }
767 }
768 int num = 50;
769 int num2 = 10;
770 if (player.chest <= -2)
771 {
772 num += 4;
773 }
774 if (voidStack)
775 {
776 num2 = 0;
777 num = 40;
778 }
779 for (int j = num2; j < num; j++)
780 {
781 if (list.Contains(array[j].netID) && !array[j].favorited)
782 {
783 dictionary.Add(j, array[j].netID);
784 }
785 }
786 for (int k = 0; k < list2.Count; k++)
787 {
788 int num3 = list2[k];
789 int netID = item[num3].netID;
790 foreach (KeyValuePair<int, int> item2 in dictionary)
791 {
792 if (item2.Value == netID && array[item2.Key].netID == netID)
793 {
794 int num4 = array[item2.Key].stack;
795 int num5 = item[num3].maxStack - item[num3].stack;
796 if (num5 == 0)
797 {
798 break;
799 }
800 if (num4 > num5)
801 {
802 num4 = num5;
803 }
806 {
808 }
809 item[num3].stack += num4;
810 array[item2.Key].stack -= num4;
811 if (array[item2.Key].stack == 0)
812 {
813 array[item2.Key].SetDefaults();
814 }
815 array2[num3] = true;
816 }
817 }
818 }
819 foreach (KeyValuePair<int, int> item3 in dictionary)
820 {
821 if (array[item3.Key].stack == 0)
822 {
823 list4.Add(item3.Key);
824 }
825 }
826 foreach (int item4 in list4)
827 {
828 dictionary.Remove(item4);
829 }
830 for (int l = 0; l < list3.Count; l++)
831 {
832 int num6 = list3[l];
833 bool flag = true;
834 int num7 = item[num6].netID;
835 if (num7 >= 71 && num7 <= 74)
836 {
837 continue;
838 }
839 foreach (KeyValuePair<int, int> item5 in dictionary)
840 {
841 if ((item5.Value != num7 || array[item5.Key].netID != num7) && (!flag || array[item5.Key].stack <= 0))
842 {
843 continue;
844 }
846 if (flag)
847 {
848 num7 = item5.Value;
849 item[num6] = array[item5.Key];
850 array[item5.Key] = new Item();
852 {
854 }
855 }
856 else
857 {
858 int num8 = array[item5.Key].stack;
859 int num9 = item[num6].maxStack - item[num6].stack;
860 if (num9 == 0)
861 {
862 break;
863 }
864 if (num8 > num9)
865 {
866 num8 = num9;
867 }
869 {
871 }
872 item[num6].stack += num8;
873 array[item5.Key].stack -= num8;
874 if (array[item5.Key].stack == 0)
875 {
876 array[item5.Key] = new Item();
877 }
878 }
879 array2[num6] = true;
880 flag = false;
881 }
882 }
883 if (Main.netMode == 1 && player.chest >= 0)
884 {
885 for (int m = 0; m < array2.Length; m++)
886 {
887 NetMessage.SendData(32, -1, -1, null, player.chest, m);
888 }
889 }
890 list.Clear();
891 list2.Clear();
892 list3.Clear();
893 dictionary.Clear();
894 list4.Clear();
895 }
896
897 public static void RenameChest()
898 {
899 Player player = Main.player[Main.myPlayer];
900 if (!Main.editChest)
901 {
903 }
904 else
905 {
906 RenameChestSubmit(player);
907 }
908 }
909
910 public static void RenameChestSubmit(Player player)
911 {
913 Main.editChest = false;
914 int chest = player.chest;
915 if (chest < 0)
916 {
917 return;
918 }
920 {
921 Main.npcChatText = "";
922 }
923 if (Main.chest[chest].name != Main.npcChatText)
924 {
925 Main.chest[chest].name = Main.npcChatText;
926 if (Main.netMode == 1)
927 {
928 player.editedChestName = true;
929 }
930 }
931 }
932
933 public static void RenameChestCancel()
934 {
936 Main.editChest = false;
937 Main.npcChatText = string.Empty;
938 Main.blockKey = Keys.Escape.ToString();
939 }
940
941 public static void Restock()
942 {
943 Player player = Main.player[Main.myPlayer];
944 Item[] inventory = player.inventory;
945 Item[] item = player.bank.item;
946 if (player.chest > -1)
947 {
948 item = Main.chest[player.chest].item;
949 }
950 else if (player.chest == -2)
951 {
952 item = player.bank.item;
953 }
954 else if (player.chest == -3)
955 {
956 item = player.bank2.item;
957 }
958 else if (player.chest == -4)
959 {
960 item = player.bank3.item;
961 }
962 else if (player.chest == -5)
963 {
964 item = player.bank4.item;
965 }
967 List<int> list = new List<int>();
968 List<int> list2 = new List<int>();
969 for (int num = 57; num >= 0; num--)
970 {
971 if ((num < 50 || num >= 54) && (inventory[num].type < 71 || inventory[num].type > 74))
972 {
973 if (inventory[num].stack > 0 && inventory[num].maxStack > 1 && inventory[num].prefix == 0)
974 {
975 hashSet.Add(inventory[num].netID);
976 if (inventory[num].stack < inventory[num].maxStack)
977 {
978 list.Add(num);
979 }
980 }
981 else if (inventory[num].stack == 0 || inventory[num].netID == 0 || inventory[num].type == 0)
982 {
983 list2.Add(num);
984 }
985 }
986 }
987 bool flag = false;
988 for (int i = 0; i < item.Length; i++)
989 {
990 if (item[i].stack < 1 || item[i].prefix != 0 || !hashSet.Contains(item[i].netID))
991 {
992 continue;
993 }
994 bool flag2 = false;
995 for (int j = 0; j < list.Count; j++)
996 {
997 int num2 = list[j];
998 int context = 0;
999 if (num2 >= 50)
1000 {
1001 context = 2;
1002 }
1003 if (inventory[num2].netID != item[i].netID || ItemSlot.PickItemMovementAction(inventory, context, num2, item[i]) == -1)
1004 {
1005 continue;
1006 }
1007 int num3 = item[i].stack;
1008 if (inventory[num2].maxStack - inventory[num2].stack < num3)
1009 {
1010 num3 = inventory[num2].maxStack - inventory[num2].stack;
1011 }
1012 inventory[num2].stack += num3;
1013 item[i].stack -= num3;
1014 flag = true;
1015 if (inventory[num2].stack == inventory[num2].maxStack)
1016 {
1017 if (Main.netMode == 1 && Main.player[Main.myPlayer].chest > -1)
1018 {
1019 NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, i);
1020 }
1021 list.RemoveAt(j);
1022 j--;
1023 }
1024 if (item[i].stack == 0)
1025 {
1026 item[i] = new Item();
1027 flag2 = true;
1028 if (Main.netMode == 1 && Main.player[Main.myPlayer].chest > -1)
1029 {
1030 NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, i);
1031 }
1032 break;
1033 }
1034 }
1035 if (flag2 || list2.Count <= 0 || item[i].ammo == 0)
1036 {
1037 continue;
1038 }
1039 for (int k = 0; k < list2.Count; k++)
1040 {
1041 int context2 = 0;
1042 if (list2[k] >= 50)
1043 {
1044 context2 = 2;
1045 }
1046 if (ItemSlot.PickItemMovementAction(inventory, context2, list2[k], item[i]) != -1)
1047 {
1048 Utils.Swap(ref inventory[list2[k]], ref item[i]);
1049 if (Main.netMode == 1 && Main.player[Main.myPlayer].chest > -1)
1050 {
1051 NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, i);
1052 }
1053 list.Add(list2[k]);
1054 list2.RemoveAt(k);
1055 flag = true;
1056 break;
1057 }
1058 }
1059 }
1060 if (flag)
1061 {
1063 }
1064 }
1065
1066 public static long MoveCoins(Item[] pInv, Item[] cInv, ContainerTransferContext context)
1067 {
1068 bool flag = false;
1069 int[] array = new int[4];
1070 List<int> list = new List<int>();
1071 List<int> list2 = new List<int>();
1072 bool flag2 = false;
1073 int[] array2 = new int[40];
1074 bool overFlowing;
1075 long num = Utils.CoinsCount(out overFlowing, pInv);
1076 for (int i = 0; i < cInv.Length; i++)
1077 {
1078 array2[i] = -1;
1079 if (cInv[i].stack < 1 || cInv[i].type < 1)
1080 {
1081 list2.Add(i);
1082 cInv[i] = new Item();
1083 }
1084 if (cInv[i] != null && cInv[i].stack > 0)
1085 {
1086 int num2 = 0;
1087 if (cInv[i].type == 71)
1088 {
1089 num2 = 1;
1090 }
1091 if (cInv[i].type == 72)
1092 {
1093 num2 = 2;
1094 }
1095 if (cInv[i].type == 73)
1096 {
1097 num2 = 3;
1098 }
1099 if (cInv[i].type == 74)
1100 {
1101 num2 = 4;
1102 }
1103 array2[i] = num2 - 1;
1104 if (num2 > 0)
1105 {
1106 array[num2 - 1] += cInv[i].stack;
1107 list2.Add(i);
1108 cInv[i] = new Item();
1109 flag2 = true;
1110 }
1111 }
1112 }
1113 if (!flag2)
1114 {
1115 return 0L;
1116 }
1117 for (int j = 0; j < pInv.Length; j++)
1118 {
1119 if (j != 58 && pInv[j] != null && pInv[j].stack > 0 && !pInv[j].favorited)
1120 {
1121 int num3 = 0;
1122 if (pInv[j].type == 71)
1123 {
1124 num3 = 1;
1125 }
1126 if (pInv[j].type == 72)
1127 {
1128 num3 = 2;
1129 }
1130 if (pInv[j].type == 73)
1131 {
1132 num3 = 3;
1133 }
1134 if (pInv[j].type == 74)
1135 {
1136 num3 = 4;
1137 }
1138 if (num3 > 0)
1139 {
1140 flag = true;
1141 array[num3 - 1] += pInv[j].stack;
1142 list.Add(j);
1143 pInv[j] = new Item();
1144 }
1145 }
1146 }
1147 for (int k = 0; k < 3; k++)
1148 {
1149 while (array[k] >= 100)
1150 {
1151 array[k] -= 100;
1152 array[k + 1]++;
1153 }
1154 }
1155 for (int l = 0; l < 40; l++)
1156 {
1157 if (array2[l] < 0 || cInv[l].type != 0)
1158 {
1159 continue;
1160 }
1161 int num4 = l;
1162 int num5 = array2[l];
1163 if (array[num5] > 0)
1164 {
1165 cInv[num4].SetDefaults(71 + num5);
1166 cInv[num4].stack = array[num5];
1167 if (cInv[num4].stack > cInv[num4].maxStack)
1168 {
1169 cInv[num4].stack = cInv[num4].maxStack;
1170 }
1171 array[num5] -= cInv[num4].stack;
1172 array2[l] = -1;
1173 }
1174 if (Main.netMode == 1 && Main.player[Main.myPlayer].chest > -1)
1175 {
1176 NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, num4);
1177 }
1178 list2.Remove(num4);
1179 }
1180 for (int m = 0; m < 40; m++)
1181 {
1182 if (array2[m] < 0 || cInv[m].type != 0)
1183 {
1184 continue;
1185 }
1186 int num6 = m;
1187 int num7 = 3;
1188 while (num7 >= 0)
1189 {
1190 if (array[num7] > 0)
1191 {
1192 cInv[num6].SetDefaults(71 + num7);
1193 cInv[num6].stack = array[num7];
1194 if (cInv[num6].stack > cInv[num6].maxStack)
1195 {
1196 cInv[num6].stack = cInv[num6].maxStack;
1197 }
1198 array[num7] -= cInv[num6].stack;
1199 array2[m] = -1;
1200 break;
1201 }
1202 if (array[num7] == 0)
1203 {
1204 num7--;
1205 }
1206 }
1207 if (Main.netMode == 1 && Main.player[Main.myPlayer].chest > -1)
1208 {
1209 NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, num6);
1210 }
1211 list2.Remove(num6);
1212 }
1213 while (list2.Count > 0)
1214 {
1215 int num8 = list2[0];
1216 int num9 = 3;
1217 while (num9 >= 0)
1218 {
1219 if (array[num9] > 0)
1220 {
1221 cInv[num8].SetDefaults(71 + num9);
1222 cInv[num8].stack = array[num9];
1223 if (cInv[num8].stack > cInv[num8].maxStack)
1224 {
1225 cInv[num8].stack = cInv[num8].maxStack;
1226 }
1227 array[num9] -= cInv[num8].stack;
1228 break;
1229 }
1230 if (array[num9] == 0)
1231 {
1232 num9--;
1233 }
1234 }
1235 if (Main.netMode == 1 && Main.player[Main.myPlayer].chest > -1)
1236 {
1237 NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, list2[0]);
1238 }
1239 list2.RemoveAt(0);
1240 }
1241 int num10 = 3;
1242 while (num10 >= 0 && list.Count > 0)
1243 {
1244 int num11 = list[0];
1245 if (array[num10] > 0)
1246 {
1247 pInv[num11].SetDefaults(71 + num10);
1248 pInv[num11].stack = array[num10];
1249 if (pInv[num11].stack > pInv[num11].maxStack)
1250 {
1251 pInv[num11].stack = pInv[num11].maxStack;
1252 }
1253 array[num10] -= pInv[num11].stack;
1254 flag = false;
1255 list.RemoveAt(0);
1256 }
1257 if (array[num10] == 0)
1258 {
1259 num10--;
1260 }
1261 }
1262 if (flag)
1263 {
1265 }
1266 bool overFlowing2;
1269 {
1270 return 0L;
1271 }
1272 return num - num12;
1273 }
1274
1275 public static bool TryPlacingInChest(Item I, bool justCheck, int itemSlotContext)
1276 {
1279 {
1280 return false;
1281 }
1282 Player player = Main.player[Main.myPlayer];
1283 bool flag = false;
1284 if (I.maxStack > 1)
1285 {
1286 for (int i = 0; i < 40; i++)
1287 {
1288 if (chestinv[i].stack >= chestinv[i].maxStack || !I.IsTheSameAs(chestinv[i]))
1289 {
1290 continue;
1291 }
1292 int num = I.stack;
1293 if (I.stack + chestinv[i].stack > chestinv[i].maxStack)
1294 {
1295 num = chestinv[i].maxStack - chestinv[i].stack;
1296 }
1297 if (justCheck)
1298 {
1299 flag = flag || num > 0;
1300 break;
1301 }
1302 I.stack -= num;
1303 chestinv[i].stack += num;
1305 if (I.stack <= 0)
1306 {
1307 I.SetDefaults();
1308 if (sync)
1309 {
1310 NetMessage.SendData(32, -1, -1, null, player.chest, i);
1311 }
1312 break;
1313 }
1314 if (chestinv[i].type == 0)
1315 {
1316 chestinv[i] = I.Clone();
1317 I.SetDefaults();
1318 }
1319 if (sync)
1320 {
1321 NetMessage.SendData(32, -1, -1, null, player.chest, i);
1322 }
1323 }
1324 }
1325 if (I.stack > 0)
1326 {
1327 for (int j = 0; j < 40; j++)
1328 {
1329 if (chestinv[j].stack != 0)
1330 {
1331 continue;
1332 }
1333 if (justCheck)
1334 {
1335 flag = true;
1336 break;
1337 }
1339 chestinv[j] = I.Clone();
1340 I.SetDefaults();
1342 if (sync)
1343 {
1344 NetMessage.SendData(32, -1, -1, null, player.chest, j);
1345 }
1346 break;
1347 }
1348 }
1349 return flag;
1350 }
1351
1352 public static void GetContainerUsageInfo(out bool sync, out Item[] chestinv)
1353 {
1354 sync = false;
1355 Player player = Main.player[Main.myPlayer];
1356 chestinv = player.bank.item;
1357 if (player.chest > -1)
1358 {
1359 chestinv = Main.chest[player.chest].item;
1360 sync = Main.netMode == 1;
1361 }
1362 else if (player.chest == -2)
1363 {
1364 chestinv = player.bank.item;
1365 }
1366 else if (player.chest == -3)
1367 {
1368 chestinv = player.bank2.item;
1369 }
1370 else if (player.chest == -4)
1371 {
1372 chestinv = player.bank3.item;
1373 }
1374 else if (player.chest == -5)
1375 {
1376 chestinv = player.bank4.item;
1377 }
1378 }
1379
1380 public static bool IsBlockedFromTransferIntoChest(Item item, Item[] container)
1381 {
1382 if (item.type == 3213 && item.favorited && container == Main.LocalPlayer.bank.item)
1383 {
1384 return true;
1385 }
1386 if ((item.type == 4131 || item.type == 5325) && item.favorited && container == Main.LocalPlayer.bank4.item)
1387 {
1388 return true;
1389 }
1390 return false;
1391 }
1392}
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static void PlaySound(int type, Vector2 position, int style=1)
Item[] item
Definition Chest.cs:41
static void VisualizeChestTransfer_CoinsBatch(Vector2 position, Vector2 chestPosition, long coinsMoved)
Definition Chest.cs:357
string name
Definition Chest.cs:49
static void VisualizeChestTransfer(Vector2 position, Vector2 chestPosition, Item item, int amountMoved)
Definition Chest.cs:347
Vector2 Center
Definition Entity.cs:43
Vector2 position
Definition Entity.cs:14
static Asset< DynamicSpriteFont > MouseText
Definition FontAssets.cs:10
static Asset< Texture2D > InventoryBack
Item Clone()
Definition Item.cs:49916
int stack
Definition Item.cs:149
int maxStack
Definition Item.cs:151
bool IsTheSameAs(Item compareItem)
Definition Item.cs:49926
bool favorited
Definition Item.cs:135
void SetDefaults(int Type=0)
Definition Item.cs:47332
static LocalizedText[] inter
Definition Lang.cs:28
static LocalizedText[] dresserType
Definition Lang.cs:40
static LocalizedText[] chestType2
Definition Lang.cs:43
static LocalizedText[] chestType
Definition Lang.cs:37
static string GetItemNameValue(int id)
Definition Lang.cs:185
static string GetTextValue(string key)
Definition Language.cs:15
static string npcChatText
Definition Main.cs:1825
static Chest[] chest
Definition Main.cs:1699
static int myPlayer
Definition Main.cs:1801
static int netMode
Definition Main.cs:2095
static bool mouseLeftRelease
Definition Main.cs:1755
static Main instance
Definition Main.cs:283
static byte mouseTextColor
Definition Main.cs:1751
static Microsoft.Xna.Framework.Color OurFavoriteColor
Definition Main.cs:902
static float inventoryScale
Definition Main.cs:1779
static Tile[,] tile
Definition Main.cs:1675
static bool editChest
Definition Main.cs:1817
static string defaultChestName
Definition Main.cs:1823
static bool recBigList
Definition Main.cs:1787
static int mouseY
Definition Main.cs:606
static Player LocalPlayer
Definition Main.cs:2829
static Player[] player
Definition Main.cs:1803
static int mouseX
Definition Main.cs:604
static bool mouseLeft
Definition Main.cs:614
static void SendData(int msgType, int remoteClient=-1, int ignoreClient=-1, NetworkText text=null, int number=0, float number2=0f, float number3=0f, float number4=0f, int number5=0, int number6=0, int number7=0)
Definition NetMessage.cs:88
bool IsVoidVaultEnabled
Definition Player.cs:3376
Item GetItem(int plr, Item newItem, GetItemSettings settings)
Definition Player.cs:37130
Item[] inventory
Definition Player.cs:1257
static void FindRecipes(bool canDelayCheck=false)
Definition Recipe.cs:453
ushort type
Definition Tile.cs:8
short frameX
Definition Tile.cs:22
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 readonly int Count
Definition ChestUI.cs:35
static float[] ButtonScale
Definition ChestUI.cs:42
static bool[] ButtonHovered
Definition ChestUI.cs:44
static void DepositAll(ContainerTransferContext context)
Definition ChestUI.cs:450
const float buttonScaleMaximum
Definition ChestUI.cs:40
static void DrawButtons(SpriteBatch spritebatch)
Definition ChestUI.cs:180
static void RenameChestCancel()
Definition ChestUI.cs:933
const float buttonScaleMinimum
Definition ChestUI.cs:38
static bool IsBlockedFromTransferIntoChest(Item item, Item[] container)
Definition ChestUI.cs:1380
static void DrawName(SpriteBatch spritebatch)
Definition ChestUI.cs:95
static void RenameChestSubmit(Player player)
Definition ChestUI.cs:910
static void LootAll()
Definition ChestUI.cs:382
static long MoveCoins(Item[] pInv, Item[] cInv, ContainerTransferContext context)
Definition ChestUI.cs:1066
static void Draw(SpriteBatch spritebatch)
Definition ChestUI.cs:72
static void DrawButton(SpriteBatch spriteBatch, int ID, int X, int Y)
Definition ChestUI.cs:188
static void QuickStack(ContainerTransferContext context, bool voidStack=false)
Definition ChestUI.cs:686
static void GetContainerUsageInfo(out bool sync, out Item[] chestinv)
Definition ChestUI.cs:1352
static void RenameChest()
Definition ChestUI.cs:897
static bool TryPlacingInChest(Item I, bool justCheck, int itemSlotContext)
Definition ChestUI.cs:1275
static void ToggleVacuum()
Definition ChestUI.cs:323
static void DrawSlots(SpriteBatch spriteBatch)
Definition ChestUI.cs:329
static void UpdateHover(int ID, bool hovering)
Definition ChestUI.cs:46
static void Restock()
Definition ChestUI.cs:941
static void SetPosition(int ID, Vector2 Position)
static void OpenVirtualKeyboard(int keyboardContext)
static void Draw(SpriteBatch spriteBatch, ref Item inv, int context, Vector2 position, Color lightColor=default(Color))
Definition ItemSlot.cs:1777
static int PickItemMovementAction(Item[] inv, int context, int slot, Item checkItem)
Definition ItemSlot.cs:1158
static void AnnounceTransfer(ItemTransferInfo info)
Definition ItemSlot.cs:241
static void Handle(ref Item inv, int context=0)
Definition ItemSlot.cs:302
static string[] WordwrapString(string text, DynamicSpriteFont font, int maxWidth, int maxLines, out int lineAmount)
Definition Utils.cs:522
static bool FloatIntersect(float r1StartX, float r1StartY, float r1Width, float r1Height, float r2StartX, float r2StartY, float r2Width, float r2Height)
Definition Utils.cs:627
static long CoinsCount(out bool overFlowing, Item[] inv, params int[] ignoreSlots)
Definition Utils.cs:636
static ContainerTransferContext FromUnknown(Player player)
static GetItemSettings LootAllSettings
static GetItemSettings LootAllSettingsRegularChest