Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CaptureInterface.cs
Go to the documentation of this file.
1using System;
3using System.IO;
12
14
15public class CaptureInterface
16{
17 public static class Settings
18 {
19 public static bool PackImage = true;
20
21 public static bool IncludeEntities = true;
22
23 public static bool TransparentBackground;
24
25 public static int BiomeChoiceIndex = -1;
26
27 public static int ScreenAnchor = 0;
28
29 public static Color MarkedAreaColor = new Color(0.8f, 0.8f, 0.8f, 0f) * 0.3f;
30 }
31
32 private abstract class CaptureInterfaceMode
33 {
34 public bool Selected;
35
36 public abstract void Update();
37
38 public abstract void Draw(SpriteBatch sb);
39
40 public abstract void ToggleActive(bool tickedOn);
41
42 public abstract bool UsingMap();
43 }
44
46 {
47 public override void Update()
48 {
49 if (Selected)
50 {
52 Vector2 mouse = new Vector2(Main.mouseX, Main.mouseY);
53 EdgePlacement(mouse);
54 }
55 }
56
71
72 public override void ToggleActive(bool tickedOn)
73 {
74 }
75
76 public override bool UsingMap()
77 {
78 return true;
79 }
80
81 private void EdgePlacement(Vector2 mouse)
82 {
83 if (JustActivated)
84 {
85 return;
86 }
87 Point result;
89 {
90 if (Main.mouseLeft)
91 {
92 EdgeAPinned = true;
93 EdgeA = Main.MouseWorld.ToTileCoordinates();
94 }
95 if (Main.mouseRight)
96 {
97 EdgeBPinned = true;
98 EdgeB = Main.MouseWorld.ToTileCoordinates();
99 }
100 }
101 else if (GetMapCoords((int)mouse.X, (int)mouse.Y, 0, out result))
102 {
103 if (Main.mouseLeft)
104 {
105 EdgeAPinned = true;
106 EdgeA = result;
107 }
108 if (Main.mouseRight)
109 {
110 EdgeBPinned = true;
111 EdgeB = result;
112 }
113 }
115 }
116
118 {
119 if (!EdgeAPinned || !EdgeBPinned)
120 {
121 return;
122 }
123 int num = Math.Min(EdgeA.X, EdgeB.X);
124 int num2 = Math.Min(EdgeA.Y, EdgeB.Y);
125 int num3 = Math.Abs(EdgeA.X - EdgeB.X);
126 int num4 = Math.Abs(EdgeA.Y - EdgeB.Y);
127 if (!Main.mapFullscreen)
128 {
129 Rectangle value = Main.ReverseGravitySupport(new Rectangle(num * 16, num2 * 16, (num3 + 1) * 16, (num4 + 1) * 16));
132 if (result.Width != 0 && result.Height != 0)
133 {
134 result.Offset(-value2.X, -value2.Y);
136 for (int i = 0; i < 2; i++)
137 {
138 sb.Draw(TextureAssets.MagicPixel.Value, new Rectangle(result.X, result.Y + ((i == 1) ? result.Height : (-2)), result.Width, 2), Color.White);
139 sb.Draw(TextureAssets.MagicPixel.Value, new Rectangle(result.X + ((i == 1) ? result.Width : (-2)), result.Y, 2, result.Height), Color.White);
140 }
141 }
142 return;
143 }
144 GetMapCoords(num, num2, 1, out var result2);
145 GetMapCoords(num + num3 + 1, num2 + num4 + 1, 1, out var result3);
149 if (result4.Width != 0 && result4.Height != 0)
150 {
151 result4.Offset(-value4.X, -value4.Y);
153 for (int j = 0; j < 2; j++)
154 {
155 sb.Draw(TextureAssets.MagicPixel.Value, new Rectangle(result4.X, result4.Y + ((j == 1) ? result4.Height : (-2)), result4.Width, 2), Color.White);
156 sb.Draw(TextureAssets.MagicPixel.Value, new Rectangle(result4.X + ((j == 1) ? result4.Width : (-2)), result4.Y, 2, result4.Height), Color.White);
157 }
158 }
159 }
160
161 private void DrawCursors(SpriteBatch sb)
162 {
163 float num = 1f / Main.cursorScale;
164 float num2 = 0.8f / num;
165 Vector2 vector = Main.screenPosition + new Vector2(30f);
168 {
171 }
173 Color color = Main.hslToRgb((vector2.X + 0.33f) % 1f, vector2.Y, vector2.Z);
174 Color color2 = Main.hslToRgb((vector2.X - 0.33f) % 1f, vector2.Y, vector2.Z);
175 color = (color2 = Color.White);
176 bool flag = Main.player[Main.myPlayer].gravDir == -1f;
177 if (!EdgeAPinned)
178 {
179 Utils.DrawCursorSingle(sb, color, 3.926991f, Main.cursorScale * num * num2, new Vector2((float)Main.mouseX - 5f + 12f, (float)Main.mouseY + 2.5f + 12f), 4);
180 }
181 else
182 {
183 int specialMode = 0;
184 float num3 = 0f;
186 if (!Main.mapFullscreen)
187 {
188 Vector2 vector3 = EdgeA.ToVector2() * 16f;
189 if (!EdgeBPinned)
190 {
191 specialMode = 1;
192 vector3 += Vector2.One * 8f;
193 zero = vector3;
195 if (flag)
196 {
197 num3 = 0f - num3;
198 }
200 if (zero != vector3)
201 {
202 num3 = (vector3 - zero).ToRotation();
203 }
204 }
205 else
206 {
207 Vector2 vector4 = new Vector2((EdgeA.X > EdgeB.X).ToInt() * 16, (EdgeA.Y > EdgeB.Y).ToInt() * 16);
208 vector3 += vector4;
210 num3 = (EdgeB.ToVector2() * 16f + new Vector2(16f) - vector4 - zero).ToRotation();
211 if (zero != vector3)
212 {
213 num3 = (vector3 - zero).ToRotation();
214 specialMode = 1;
215 }
216 if (flag)
217 {
218 num3 *= -1f;
219 }
220 }
221 Utils.DrawCursorSingle(sb, color, num3 - (float)Math.PI / 2f, Main.cursorScale * num, Main.ReverseGravitySupport(zero - Main.screenPosition), 4, specialMode);
222 }
223 else
224 {
225 Point result = EdgeA;
226 if (EdgeBPinned)
227 {
228 int num4 = (EdgeA.X > EdgeB.X).ToInt();
229 int num5 = (EdgeA.Y > EdgeB.Y).ToInt();
230 result.X += num4;
231 result.Y += num5;
232 GetMapCoords(result.X, result.Y, 1, out result);
234 result2.X += 1 - num4;
235 result2.Y += 1 - num5;
237 zero = result.ToVector2();
239 num3 = (result2.ToVector2() - zero).ToRotation();
240 }
241 else
242 {
243 GetMapCoords(result.X, result.Y, 1, out result);
244 }
245 Utils.DrawCursorSingle(sb, color, num3 - (float)Math.PI / 2f, Main.cursorScale * num, result.ToVector2(), 4);
246 }
247 }
248 if (!EdgeBPinned)
249 {
250 Utils.DrawCursorSingle(sb, color2, 0.7853981f, Main.cursorScale * num * num2, new Vector2((float)Main.mouseX + 2.5f + 12f, (float)Main.mouseY - 5f + 12f), 5);
251 return;
252 }
253 int specialMode2 = 0;
254 float num6 = 0f;
256 if (!Main.mapFullscreen)
257 {
258 Vector2 vector5 = EdgeB.ToVector2() * 16f;
259 if (!EdgeAPinned)
260 {
261 specialMode2 = 1;
262 vector5 += Vector2.One * 8f;
263 zero2 = vector5;
265 if (flag)
266 {
267 num6 = 0f - num6;
268 }
270 if (zero2 != vector5)
271 {
272 num6 = (vector5 - zero2).ToRotation();
273 }
274 }
275 else
276 {
277 Vector2 vector6 = new Vector2((EdgeB.X >= EdgeA.X).ToInt() * 16, (EdgeB.Y >= EdgeA.Y).ToInt() * 16);
278 vector5 += vector6;
280 num6 = (EdgeA.ToVector2() * 16f + new Vector2(16f) - vector6 - zero2).ToRotation();
281 if (zero2 != vector5)
282 {
283 num6 = (vector5 - zero2).ToRotation();
284 specialMode2 = 1;
285 }
286 if (flag)
287 {
288 num6 *= -1f;
289 }
290 }
291 Utils.DrawCursorSingle(sb, color2, num6 - (float)Math.PI / 2f, Main.cursorScale * num, Main.ReverseGravitySupport(zero2 - Main.screenPosition), 5, specialMode2);
292 }
293 else
294 {
296 if (EdgeAPinned)
297 {
298 int num7 = (EdgeB.X >= EdgeA.X).ToInt();
299 int num8 = (EdgeB.Y >= EdgeA.Y).ToInt();
300 result3.X += num7;
301 result3.Y += num8;
304 result4.X += 1 - num7;
305 result4.Y += 1 - num8;
307 zero2 = result3.ToVector2();
309 num6 = (result4.ToVector2() - zero2).ToRotation();
310 }
311 else
312 {
314 }
315 Utils.DrawCursorSingle(sb, color2, num6 - (float)Math.PI / 2f, Main.cursorScale * num, result3.ToVector2(), 5);
316 }
317 }
318 }
319
321 {
322 public int currentAim = -1;
323
324 private bool dragging;
325
326 private int caughtEdge = -1;
327
328 private bool inMap;
329
330 public override void Update()
331 {
332 if (Selected && !JustActivated)
333 {
335 Vector2 mouse = new Vector2(Main.mouseX, Main.mouseY);
336 DragBounds(mouse);
337 }
338 }
339
353
354 public override void ToggleActive(bool tickedOn)
355 {
356 if (!tickedOn)
357 {
358 currentAim = -1;
359 }
360 }
361
362 public override bool UsingMap()
363 {
364 return caughtEdge != -1;
365 }
366
367 private void DragBounds(Vector2 mouse)
368 {
369 if (!EdgeAPinned || !EdgeBPinned)
370 {
371 bool flag = false;
372 if (Main.mouseLeft)
373 {
374 flag = true;
375 }
376 if (flag)
377 {
378 bool flag2 = true;
379 Point result;
380 if (!Main.mapFullscreen)
381 {
382 result = (Main.screenPosition + mouse).ToTileCoordinates();
383 }
384 else
385 {
386 flag2 = GetMapCoords((int)mouse.X, (int)mouse.Y, 0, out result);
387 }
388 if (flag2)
389 {
390 if (!EdgeAPinned)
391 {
392 EdgeAPinned = true;
393 EdgeA = result;
394 }
395 if (!EdgeBPinned)
396 {
397 EdgeBPinned = true;
398 EdgeB = result;
399 }
400 }
401 currentAim = 3;
402 caughtEdge = 1;
403 }
404 }
405 int num = Math.Min(EdgeA.X, EdgeB.X);
406 int num2 = Math.Min(EdgeA.Y, EdgeB.Y);
407 int num3 = Math.Abs(EdgeA.X - EdgeB.X);
408 int num4 = Math.Abs(EdgeA.Y - EdgeB.Y);
409 bool value = Main.player[Main.myPlayer].gravDir == -1f;
410 int num5 = 1 - value.ToInt();
411 int num6 = value.ToInt();
415 if (!Main.mapFullscreen)
416 {
417 value2 = Main.ReverseGravitySupport(new Rectangle(num * 16, num2 * 16, (num3 + 1) * 16, (num4 + 1) * 16));
420 if (result2.Width == 0 || result2.Height == 0)
421 {
422 return;
423 }
424 result2.Offset(-value3.X, -value3.Y);
425 }
426 else
427 {
428 GetMapCoords(num, num2, 1, out var result3);
429 GetMapCoords(num + num3 + 1, num2 + num4 + 1, 1, out var result4);
430 value2 = new Rectangle(result3.X, result3.Y, result4.X - result3.X, result4.Y - result3.Y);
431 value3 = new Rectangle(0, 0, Main.screenWidth + 1, Main.screenHeight + 1);
433 if (result2.Width == 0 || result2.Height == 0)
434 {
435 return;
436 }
437 result2.Offset(-value3.X, -value3.Y);
438 }
439 dragging = false;
440 if (!Main.mouseLeft)
441 {
442 currentAim = -1;
443 }
444 if (currentAim != -1)
445 {
446 dragging = true;
447 Point point = default(Point);
448 if (!Main.mapFullscreen)
449 {
450 point = Main.MouseWorld.ToTileCoordinates();
451 }
452 else
453 {
454 if (!GetMapCoords((int)mouse.X, (int)mouse.Y, 0, out var result5))
455 {
456 return;
457 }
458 point = result5;
459 }
460 switch (currentAim)
461 {
462 case 0:
463 case 1:
464 if (caughtEdge == 0)
465 {
466 EdgeA.Y = point.Y;
467 }
468 if (caughtEdge == 1)
469 {
470 EdgeB.Y = point.Y;
471 }
472 break;
473 case 2:
474 case 3:
475 if (caughtEdge == 0)
476 {
477 EdgeA.X = point.X;
478 }
479 if (caughtEdge == 1)
480 {
481 EdgeB.X = point.X;
482 }
483 break;
484 }
485 }
486 else
487 {
488 caughtEdge = -1;
490 drawbox.Offset(-value3.X, -value3.Y);
491 inMap = drawbox.Contains(mouse.ToPoint());
492 for (int i = 0; i < 4; i++)
493 {
495 bound.Inflate(8, 8);
496 if (!bound.Contains(mouse.ToPoint()))
497 {
498 continue;
499 }
500 currentAim = i;
501 switch (i)
502 {
503 case 0:
504 if (EdgeA.Y < EdgeB.Y)
505 {
507 }
508 else
509 {
511 }
512 break;
513 case 1:
514 if (EdgeA.Y >= EdgeB.Y)
515 {
517 }
518 else
519 {
521 }
522 break;
523 case 2:
524 if (EdgeA.X < EdgeB.X)
525 {
526 caughtEdge = 0;
527 }
528 else
529 {
530 caughtEdge = 1;
531 }
532 break;
533 case 3:
534 if (EdgeA.X >= EdgeB.X)
535 {
536 caughtEdge = 0;
537 }
538 else
539 {
540 caughtEdge = 1;
541 }
542 break;
543 }
544 break;
545 }
546 }
548 }
549
551 {
552 return boundIndex switch
553 {
554 0 => new Rectangle(drawbox.X, drawbox.Y - 2, drawbox.Width, 2),
555 1 => new Rectangle(drawbox.X, drawbox.Y + drawbox.Height, drawbox.Width, 2),
556 2 => new Rectangle(drawbox.X - 2, drawbox.Y, 2, drawbox.Height),
557 3 => new Rectangle(drawbox.X + drawbox.Width, drawbox.Y, 2, drawbox.Height),
558 _ => Rectangle.Empty,
559 };
560 }
561
563 {
564 if (!EdgeAPinned || !EdgeBPinned)
565 {
566 return;
567 }
568 int num = Math.Min(EdgeA.X, EdgeB.X);
569 int num2 = Math.Min(EdgeA.Y, EdgeB.Y);
570 int num3 = Math.Abs(EdgeA.X - EdgeB.X);
571 int num4 = Math.Abs(EdgeA.Y - EdgeB.Y);
572 Rectangle result;
573 if (!Main.mapFullscreen)
574 {
575 Rectangle value = Main.ReverseGravitySupport(new Rectangle(num * 16, num2 * 16, (num3 + 1) * 16, (num4 + 1) * 16));
578 if (result.Width == 0 || result.Height == 0)
579 {
580 return;
581 }
582 result.Offset(-value2.X, -value2.Y);
583 }
584 else
585 {
586 GetMapCoords(num, num2, 1, out var result2);
587 GetMapCoords(num + num3 + 1, num2 + num4 + 1, 1, out var result3);
591 if (result.Width == 0 || result.Height == 0)
592 {
593 return;
594 }
595 result.Offset(-value2.X, -value2.Y);
596 }
599 for (int i = 0; i < 2; i++)
600 {
601 if (currentAim != i)
602 {
603 DrawBound(sb, new Rectangle(result.X, result.Y + ((i == 1) ? result.Height : (-2)), result.Width, 2), 0);
604 }
605 else
606 {
607 rectangle = new Rectangle(result.X, result.Y + ((i == 1) ? result.Height : (-2)), result.Width, 2);
608 }
609 if (currentAim != i + 2)
610 {
611 DrawBound(sb, new Rectangle(result.X + ((i == 1) ? result.Width : (-2)), result.Y, 2, result.Height), 0);
612 }
613 else
614 {
615 rectangle = new Rectangle(result.X + ((i == 1) ? result.Width : (-2)), result.Y, 2, result.Height);
616 }
617 }
619 {
620 DrawBound(sb, rectangle, 1 + dragging.ToInt());
621 }
622 }
623
624 private void DrawBound(SpriteBatch sb, Rectangle r, int mode)
625 {
626 switch (mode)
627 {
628 case 0:
630 break;
631 case 1:
632 sb.Draw(destinationRectangle: new Rectangle(r.X - 2, r.Y, r.Width + 4, r.Height), texture: TextureAssets.MagicPixel.Value, color: Color.White);
633 sb.Draw(destinationRectangle: new Rectangle(r.X, r.Y - 2, r.Width, r.Height + 4), texture: TextureAssets.MagicPixel.Value, color: Color.White);
635 break;
636 case 2:
637 sb.Draw(destinationRectangle: new Rectangle(r.X - 2, r.Y, r.Width + 4, r.Height), texture: TextureAssets.MagicPixel.Value, color: Color.Gold);
638 sb.Draw(destinationRectangle: new Rectangle(r.X, r.Y - 2, r.Width, r.Height + 4), texture: TextureAssets.MagicPixel.Value, color: Color.Gold);
640 break;
641 }
642 }
643 }
644
646 {
647 private const int ButtonsCount = 7;
648
649 private int hoveredButton = -1;
650
651 private bool inUI;
652
654 {
655 Rectangle result = new Rectangle(0, 0, 224, 170);
656 if (Settings.ScreenAnchor == 0)
657 {
658 result.X = 227 - result.Width / 2;
659 result.Y = 80;
660 }
661 return result;
662 }
663
664 private void ButtonDraw(int button, ref string key, ref string value)
665 {
666 switch (button)
667 {
668 case 0:
669 key = Lang.inter[74].Value;
670 value = Lang.inter[73 - Settings.PackImage.ToInt()].Value;
671 break;
672 case 1:
673 key = Lang.inter[75].Value;
674 value = Lang.inter[73 - Settings.IncludeEntities.ToInt()].Value;
675 break;
676 case 2:
677 key = Lang.inter[76].Value;
678 value = Lang.inter[73 - (!Settings.TransparentBackground).ToInt()].Value;
679 break;
680 case 6:
681 key = " " + Lang.menu[86].Value;
682 value = "";
683 break;
684 case 3:
685 case 4:
686 case 5:
687 break;
688 }
689 }
690
691 private void PressButton(int button)
692 {
693 bool flag = false;
694 switch (button)
695 {
696 case 0:
697 Settings.PackImage = !Settings.PackImage;
698 flag = true;
699 break;
700 case 1:
701 Settings.IncludeEntities = !Settings.IncludeEntities;
702 flag = true;
703 break;
704 case 2:
705 Settings.TransparentBackground = !Settings.TransparentBackground;
706 flag = true;
707 break;
708 case 6:
709 Settings.PackImage = true;
710 Settings.IncludeEntities = true;
711 Settings.TransparentBackground = false;
712 Settings.BiomeChoiceIndex = -1;
713 flag = true;
714 break;
715 }
716 if (flag)
717 {
719 }
720 }
721
723 {
724 Rectangle r = new Rectangle(0, 0, 20, 20);
725 for (int i = 0; i < 2; i++)
726 {
727 for (int j = 0; j < 7; j++)
728 {
729 if (i == 1 && j == 6)
730 {
731 continue;
732 }
733 int num = j + i * 7;
734 r.X = start.X + 24 * j + 12 * i;
735 r.Y = start.Y + 24 * i;
736 int num2 = num;
737 int num3 = 0;
738 if (r.Contains(mouse))
739 {
741 {
743 Settings.BiomeChoiceIndex = num2;
744 }
745 Main.instance.MouseText(Language.GetTextValue("CaptureBiomeChoice." + num2), 0, 0);
746 num3++;
747 }
749 {
750 num3 += 2;
751 }
752 Texture2D value = TextureAssets.Extra[130].Value;
753 int x = num * 18;
754 _ = Color.White;
755 float num4 = 1f;
756 if (num3 < 2)
757 {
758 num4 *= 0.5f;
759 }
760 if (num3 % 2 == 1)
761 {
762 spritebatch.Draw(TextureAssets.MagicPixel.Value, r.TopLeft(), new Rectangle(0, 0, 1, 1), Color.Gold, 0f, Vector2.Zero, new Vector2(20f), SpriteEffects.None, 0f);
763 }
764 else
765 {
766 spritebatch.Draw(TextureAssets.MagicPixel.Value, r.TopLeft(), new Rectangle(0, 0, 1, 1), Color.White * num4, 0f, Vector2.Zero, new Vector2(20f), SpriteEffects.None, 0f);
767 }
768 spritebatch.Draw(value, r.TopLeft() + new Vector2(2f), new Rectangle(x, 0, 16, 16), Color.White * num4);
769 }
770 }
771 }
772
774 {
775 switch (index)
776 {
777 case 0:
778 return -1;
779 case 1:
780 return 0;
781 case 2:
782 return 2;
783 case 3:
784 case 4:
785 case 5:
786 case 6:
787 case 7:
788 case 8:
789 return index;
790 case 9:
791 return 10;
792 case 10:
793 return 12;
794 case 11:
795 return 13;
796 case 12:
797 return 14;
798 default:
799 return 0;
800 }
801 }
802
803 public override void Update()
804 {
805 if (!Selected || JustActivated)
806 {
807 return;
808 }
811 hoveredButton = -1;
814 rect.Inflate(-20, -20);
815 rect.Height = 16;
816 int y = rect.Y;
817 for (int i = 0; i < 7; i++)
818 {
819 rect.Y = y + i * 20;
820 if (rect.Contains(value))
821 {
822 hoveredButton = i;
823 break;
824 }
825 }
827 {
829 }
830 }
831
832 public override void Draw(SpriteBatch sb)
833 {
834 if (!Selected)
835 {
836 return;
837 }
838 sb.End();
841 ((ModeDragBounds)Modes[1]).currentAim = -1;
842 ((ModeDragBounds)Modes[1]).DrawMarkedArea(sb);
843 sb.End();
847 Utils.DrawInvBG(sb, rect, new Color(63, 65, 151, 255) * 0.485f);
848 for (int i = 0; i < 7; i++)
849 {
850 string key = "";
851 string value = "";
854 if (i == hoveredButton)
855 {
857 }
858 ChatManager.DrawColorCodedStringWithShadow(sb, FontAssets.ItemStack.Value, key, rect.TopLeft() + new Vector2(20f, 20 + 20 * i), baseColor, 0f, Vector2.Zero, Vector2.One);
859 ChatManager.DrawColorCodedStringWithShadow(sb, FontAssets.ItemStack.Value, value, rect.TopRight() + new Vector2(-20f, 20 + 20 * i), baseColor, 0f, FontAssets.ItemStack.Value.MeasureString(value) * Vector2.UnitX, Vector2.One);
860 }
861 DrawWaterChoices(sb, (rect.TopLeft() + new Vector2(rect.Width / 2 - 84, 90f)).ToPoint(), Main.MouseScreen.ToPoint());
862 }
863
864 public override void ToggleActive(bool tickedOn)
865 {
866 if (tickedOn)
867 {
868 hoveredButton = -1;
869 }
870 }
871
872 public override bool UsingMap()
873 {
874 return inUI;
875 }
876 }
877
879
880 public bool Active;
881
882 public static bool JustActivated;
883
885
886 public int SelectedMode;
887
888 public int HoveredMode;
889
890 public static bool EdgeAPinned;
891
892 public static bool EdgeBPinned;
893
894 public static Point EdgeA;
895
896 public static Point EdgeB;
897
898 public static bool CameraLock;
899
900 private static float CameraFrame;
901
902 private static float CameraWaiting;
903
904 private const float CameraMaxFrame = 5f;
905
906 private const float CameraMaxWait = 60f;
907
909
911 {
913 {
914 {
915 0,
917 },
918 {
919 1,
920 new ModeDragBounds()
921 },
922 {
923 2,
925 }
926 };
927 }
928
929 public static Rectangle GetArea()
930 {
931 int x = Math.Min(EdgeA.X, EdgeB.X);
932 int y = Math.Min(EdgeA.Y, EdgeB.Y);
933 int num = Math.Abs(EdgeA.X - EdgeB.X);
934 int num2 = Math.Abs(EdgeA.Y - EdgeB.Y);
935 return new Rectangle(x, y, num + 1, num2 + 1);
936 }
937
938 public void Update()
939 {
941 UpdateCamera();
942 if (CameraLock)
943 {
944 return;
945 }
946 bool toggleCameraMode = PlayerInput.Triggers.Current.ToggleCameraMode;
948 {
950 }
952 if (!Active)
953 {
954 return;
955 }
956 Main.blockMouse = true;
958 {
959 JustActivated = false;
960 }
961 Vector2 mouse = new Vector2(Main.mouseX, Main.mouseY);
962 if (UpdateButtons(mouse) && Main.mouseLeft)
963 {
964 return;
965 }
967 {
968 mode.Value.Selected = mode.Key == SelectedMode;
969 mode.Value.Update();
970 }
972 }
973
974 public void Draw(SpriteBatch sb)
975 {
976 if (!Active)
977 {
978 return;
979 }
980 sb.End();
983 foreach (CaptureInterfaceMode value in Modes.Values)
984 {
985 value.Draw(sb);
986 }
987 sb.End();
990 Main.mouseText = false;
991 Main.instance.GUIBarsDraw();
992 DrawButtons(sb);
993 Main.instance.DrawMouseOver();
994 Utils.DrawBorderStringBig(sb, Lang.inter[81].Value, new Vector2((float)Main.screenWidth * 0.5f, 100f), Color.White, 1f, 0.5f, 0.5f);
996 DrawCameraLock(sb);
997 sb.End();
998 sb.Begin();
999 }
1000
1001 public void ToggleCamera(bool On = true)
1002 {
1003 if (CameraLock)
1004 {
1005 return;
1006 }
1007 bool active = Active;
1008 Active = Modes.ContainsKey(SelectedMode) && On;
1009 if (active != Active)
1010 {
1011 SoundEngine.PlaySound(On ? 10 : 11);
1012 }
1014 {
1015 mode.Value.ToggleActive(Active && mode.Key == SelectedMode);
1016 }
1017 if (On && !active)
1018 {
1019 JustActivated = true;
1020 }
1021 }
1022
1023 private bool UpdateButtons(Vector2 mouse)
1024 {
1025 HoveredMode = -1;
1026 bool flag = !Main.graphics.IsFullScreen;
1027 int num = 9;
1028 for (int i = 0; i < num; i++)
1029 {
1030 if (!new Rectangle(24 + 46 * i, 24, 42, 42).Contains(mouse.ToPoint()))
1031 {
1032 continue;
1033 }
1034 HoveredMode = i;
1035 bool flag2 = Main.mouseLeft && Main.mouseLeftRelease;
1036 int num2 = 0;
1037 if (i == num2++ && flag2)
1038 {
1040 }
1041 if (i == num2++ && flag2 && EdgeAPinned && EdgeBPinned)
1042 {
1044 {
1045 Area = GetArea(),
1047 CaptureBackground = !Settings.TransparentBackground,
1048 CaptureEntities = Settings.IncludeEntities,
1049 UseScaling = Settings.PackImage,
1050 CaptureMech = WiresUI.Settings.DrawWires
1051 };
1052 if (obj.Biome.WaterStyle != 13)
1053 {
1054 Main.liquidAlpha[13] = 0f;
1055 }
1057 }
1058 if (i == num2++ && flag2 && SelectedMode != 0)
1059 {
1061 SelectedMode = 0;
1062 ToggleCamera();
1063 }
1064 if (i == num2++ && flag2 && SelectedMode != 1)
1065 {
1067 SelectedMode = 1;
1068 ToggleCamera();
1069 }
1070 if (i == num2++ && flag2)
1071 {
1073 ResetFocus();
1074 }
1075 if (i == num2++ && flag2 && Main.mapEnabled)
1076 {
1078 Main.mapFullscreen = !Main.mapFullscreen;
1079 }
1080 if (i == num2++ && flag2 && SelectedMode != 2)
1081 {
1083 SelectedMode = 2;
1084 ToggleCamera();
1085 }
1086 if (i == num2++ && flag2 && flag)
1087 {
1089 Utils.OpenFolder(Path.Combine(Main.SavePath, "Captures"));
1090 }
1091 if (i == num2++ && flag2)
1092 {
1093 ToggleCamera(On: false);
1094 Main.blockMouse = true;
1095 Main.mouseLeftRelease = false;
1096 }
1097 return true;
1098 }
1099 return false;
1100 }
1101
1102 public static void QuickScreenshot()
1103 {
1104 Point point = Main.ViewPosition.ToTileCoordinates();
1105 Point point2 = (Main.ViewPosition + Main.ViewSize).ToTileCoordinates();
1107 {
1108 Area = new Rectangle(point.X, point.Y, point2.X - point.X + 1, point2.Y - point.Y + 1),
1110 CaptureBackground = !Settings.TransparentBackground,
1111 CaptureEntities = Settings.IncludeEntities,
1112 UseScaling = Settings.PackImage,
1113 CaptureMech = WiresUI.Settings.DrawWires
1114 });
1115 }
1116
1117 private void DrawButtons(SpriteBatch sb)
1118 {
1120 int num = 9;
1121 for (int i = 0; i < num; i++)
1122 {
1124 float num2 = 0.8f;
1125 Vector2 vector = new Vector2(24 + 46 * i, 24f);
1126 Color color = Main.inventoryBack * 0.8f;
1127 if (SelectedMode == 0 && i == 2)
1128 {
1130 }
1131 else if (SelectedMode == 1 && i == 3)
1132 {
1134 }
1135 else if (SelectedMode == 2 && i == 6)
1136 {
1138 }
1139 else if (i >= 2 && i <= 3)
1140 {
1142 }
1143 sb.Draw(texture2D, vector, null, color, 0f, default(Vector2), num2, SpriteEffects.None, 0f);
1144 switch (i)
1145 {
1146 case 0:
1147 texture2D = TextureAssets.Camera[7].Value;
1148 break;
1149 case 1:
1150 texture2D = TextureAssets.Camera[0].Value;
1151 break;
1152 case 2:
1153 case 3:
1154 case 4:
1155 texture2D = TextureAssets.Camera[i].Value;
1156 break;
1157 case 5:
1158 texture2D = (Main.mapFullscreen ? TextureAssets.MapIcon[0].Value : TextureAssets.MapIcon[4].Value);
1159 break;
1160 case 6:
1161 texture2D = TextureAssets.Camera[1].Value;
1162 break;
1163 case 7:
1164 texture2D = TextureAssets.Camera[6].Value;
1165 break;
1166 case 8:
1167 texture2D = TextureAssets.Camera[5].Value;
1168 break;
1169 }
1170 sb.Draw(texture2D, vector + new Vector2(26f) * num2, null, Color.White, 0f, texture2D.Size() / 2f, 1f, SpriteEffects.None, 0f);
1171 bool flag = false;
1172 switch (i)
1173 {
1174 case 1:
1175 if (!EdgeAPinned || !EdgeBPinned)
1176 {
1177 flag = true;
1178 }
1179 break;
1180 case 7:
1181 if (Main.graphics.IsFullScreen)
1182 {
1183 flag = true;
1184 }
1185 break;
1186 case 5:
1187 if (!Main.mapEnabled)
1188 {
1189 flag = true;
1190 }
1191 break;
1192 }
1193 if (flag)
1194 {
1195 sb.Draw(TextureAssets.Cd.Value, vector + new Vector2(26f) * num2, null, Color.White * 0.65f, 0f, TextureAssets.Cd.Value.Size() / 2f, 1f, SpriteEffects.None, 0f);
1196 }
1197 }
1198 string text = "";
1199 switch (HoveredMode)
1200 {
1201 case 0:
1202 text = Lang.inter[111].Value;
1203 break;
1204 case 1:
1205 text = Lang.inter[67].Value;
1206 break;
1207 case 2:
1208 text = Lang.inter[69].Value;
1209 break;
1210 case 3:
1211 text = Lang.inter[70].Value;
1212 break;
1213 case 4:
1214 text = Lang.inter[78].Value;
1215 break;
1216 case 5:
1217 text = (Main.mapFullscreen ? Lang.inter[109].Value : Lang.inter[108].Value);
1218 break;
1219 case 6:
1220 text = Lang.inter[68].Value;
1221 break;
1222 case 7:
1223 text = Lang.inter[110].Value;
1224 break;
1225 case 8:
1226 text = Lang.inter[71].Value;
1227 break;
1228 default:
1229 text = "???";
1230 break;
1231 case -1:
1232 break;
1233 }
1234 switch (HoveredMode)
1235 {
1236 case 1:
1237 if (!EdgeAPinned || !EdgeBPinned)
1238 {
1239 text = text + "\n" + Lang.inter[112].Value;
1240 }
1241 break;
1242 case 7:
1243 if (Main.graphics.IsFullScreen)
1244 {
1245 text = text + "\n" + Lang.inter[113].Value;
1246 }
1247 break;
1248 case 5:
1249 if (!Main.mapEnabled)
1250 {
1251 text = text + "\n" + Lang.inter[114].Value;
1252 }
1253 break;
1254 }
1255 if (text != "")
1256 {
1257 Main.instance.MouseText(text, 0, 0);
1258 }
1259 }
1260
1261 private static bool GetMapCoords(int PinX, int PinY, int Goal, out Point result)
1262 {
1263 if (!Main.mapFullscreen)
1264 {
1265 result = new Point(-1, -1);
1266 return false;
1267 }
1268 float num = 0f;
1269 float num2 = 0f;
1270 float num3 = 2f;
1271 _ = Main.maxTilesX / Main.textureMaxWidth;
1272 _ = Main.maxTilesY / Main.textureMaxHeight;
1273 float num4 = 10f;
1274 float num5 = 10f;
1275 float num6 = Main.maxTilesX - 10;
1276 float num7 = Main.maxTilesY - 10;
1277 num = 200f;
1278 num2 = 300f;
1280 float num8 = (float)Main.screenWidth / (float)Main.maxTilesX * 0.8f;
1282 {
1283 Main.mapFullscreenScale = num8;
1284 }
1285 if (Main.mapFullscreenScale > 16f)
1286 {
1287 Main.mapFullscreenScale = 16f;
1288 }
1290 if (Main.mapFullscreenPos.X < num4)
1291 {
1292 Main.mapFullscreenPos.X = num4;
1293 }
1294 if (Main.mapFullscreenPos.X > num6)
1295 {
1296 Main.mapFullscreenPos.X = num6;
1297 }
1298 if (Main.mapFullscreenPos.Y < num5)
1299 {
1300 Main.mapFullscreenPos.Y = num5;
1301 }
1302 if (Main.mapFullscreenPos.Y > num7)
1303 {
1304 Main.mapFullscreenPos.Y = num7;
1305 }
1306 float x = Main.mapFullscreenPos.X;
1307 float y = Main.mapFullscreenPos.Y;
1308 float num9 = x * num3;
1309 y *= num3;
1310 num = 0f - num9 + (float)(Main.screenWidth / 2);
1311 num2 = 0f - y + (float)(Main.screenHeight / 2);
1312 num += num4 * num3;
1313 num2 += num5 * num3;
1314 float num10 = Main.maxTilesX / 840;
1316 float num11 = num;
1317 float num12 = num2;
1318 float num13 = TextureAssets.Map.Width();
1319 float num14 = TextureAssets.Map.Height();
1320 if (Main.maxTilesX == 8400)
1321 {
1322 num10 *= 0.999f;
1323 num11 -= 40.6f * num10;
1324 num12 = num2 - 5f * num10;
1325 num13 -= 8.045f;
1326 num13 *= num10;
1327 num14 += 0.12f;
1328 num14 *= num10;
1329 if ((double)num10 < 1.2)
1330 {
1331 num14 += 1f;
1332 }
1333 }
1334 else if (Main.maxTilesX == 6400)
1335 {
1336 num10 *= 1.09f;
1337 num11 -= 38.8f * num10;
1338 num12 = num2 - 3.85f * num10;
1339 num13 -= 13.6f;
1340 num13 *= num10;
1341 num14 -= 6.92f;
1342 num14 *= num10;
1343 if ((double)num10 < 1.2)
1344 {
1345 num14 += 2f;
1346 }
1347 }
1348 else if (Main.maxTilesX == 6300)
1349 {
1350 num10 *= 1.09f;
1351 num11 -= 39.8f * num10;
1352 num12 = num2 - 4.08f * num10;
1353 num13 -= 26.69f;
1354 num13 *= num10;
1355 num14 -= 6.92f;
1356 num14 *= num10;
1357 if ((double)num10 < 1.2)
1358 {
1359 num14 += 2f;
1360 }
1361 }
1362 else if (Main.maxTilesX == 4200)
1363 {
1364 num10 *= 0.998f;
1365 num11 -= 37.3f * num10;
1366 num12 -= 1.7f * num10;
1367 num13 -= 16f;
1368 num13 *= num10;
1369 num14 -= 8.31f;
1370 num14 *= num10;
1371 }
1372 switch (Goal)
1373 {
1374 case 0:
1375 {
1376 int num15 = (int)((0f - num + (float)PinX) / num3 + num4);
1377 int num16 = (int)((0f - num2 + (float)PinY) / num3 + num5);
1378 bool flag = false;
1379 if ((float)num15 < num4)
1380 {
1381 flag = true;
1382 }
1383 if ((float)num15 >= num6)
1384 {
1385 flag = true;
1386 }
1387 if ((float)num16 < num5)
1388 {
1389 flag = true;
1390 }
1391 if ((float)num16 >= num7)
1392 {
1393 flag = true;
1394 }
1395 if (!flag)
1396 {
1397 result = new Point(num15, num16);
1398 return true;
1399 }
1400 result = new Point(-1, -1);
1401 return false;
1402 }
1403 case 1:
1404 {
1405 Vector2 vector = new Vector2(num, num2);
1406 Vector2 vector2 = new Vector2(PinX, PinY) * num3 - new Vector2(10f * num3);
1407 result = (vector + vector2).ToPoint();
1408 return true;
1409 }
1410 default:
1411 result = new Point(-1, -1);
1412 return false;
1413 }
1414 }
1415
1416 private static void ConstraintPoints()
1417 {
1419 if (EdgeAPinned)
1420 {
1422 }
1423 if (EdgeBPinned)
1424 {
1426 }
1427 }
1428
1429 private static void PointWorldClamp(ref Point point, int fluff)
1430 {
1431 if (point.X < fluff)
1432 {
1433 point.X = fluff;
1434 }
1435 if (point.X > Main.maxTilesX - 1 - fluff)
1436 {
1437 point.X = Main.maxTilesX - 1 - fluff;
1438 }
1439 if (point.Y < fluff)
1440 {
1441 point.Y = fluff;
1442 }
1443 if (point.Y > Main.maxTilesY - 1 - fluff)
1444 {
1445 point.Y = Main.maxTilesY - 1 - fluff;
1446 }
1447 }
1448
1449 public bool UsingMap()
1450 {
1451 if (CameraLock)
1452 {
1453 return true;
1454 }
1455 return Modes[SelectedMode].UsingMap();
1456 }
1457
1458 public static void ResetFocus()
1459 {
1460 EdgeAPinned = false;
1461 EdgeBPinned = false;
1462 EdgeA = new Point(-1, -1);
1463 EdgeB = new Point(-1, -1);
1464 }
1465
1466 public void Scrolling()
1467 {
1468 int num = PlayerInput.ScrollWheelDelta / 120;
1469 num %= 30;
1470 if (num < 0)
1471 {
1472 num += 30;
1473 }
1475 SelectedMode -= num;
1476 while (SelectedMode < 0)
1477 {
1478 SelectedMode += 2;
1479 }
1480 while (SelectedMode > 2)
1481 {
1482 SelectedMode -= 2;
1483 }
1485 {
1487 }
1488 }
1489
1490 private void UpdateCamera()
1491 {
1492 if (CameraLock && CameraFrame == 4f)
1493 {
1495 }
1496 CameraFrame += CameraLock.ToDirectionInt();
1497 if (CameraFrame < 0f)
1498 {
1499 CameraFrame = 0f;
1500 }
1501 if (CameraFrame > 5f)
1502 {
1503 CameraFrame = 5f;
1504 }
1505 if (CameraFrame == 5f)
1506 {
1507 CameraWaiting += 1f;
1508 }
1509 if (CameraWaiting > 60f)
1510 {
1511 CameraWaiting = 60f;
1512 }
1513 }
1514
1516 {
1517 if (CameraFrame == 0f)
1518 {
1519 return;
1520 }
1521 sb.Draw(TextureAssets.MagicPixel.Value, new Rectangle(0, 0, Main.screenWidth, Main.screenHeight), new Rectangle(0, 0, 1, 1), Color.Black * (CameraFrame / 5f));
1522 if (CameraFrame != 5f)
1523 {
1524 return;
1525 }
1526 float num = CameraWaiting - 60f + 5f;
1527 if (!(num <= 0f))
1528 {
1529 num /= 5f;
1530 float num2 = CaptureManager.Instance.GetProgress() * 100f;
1531 if (num2 > 100f)
1532 {
1533 num2 = 100f;
1534 }
1535 string text = num2.ToString("##") + " ";
1536 string text2 = "/ 100%";
1537 Vector2 vector = FontAssets.DeathText.Value.MeasureString(text);
1538 Vector2 vector2 = FontAssets.DeathText.Value.MeasureString(text2);
1539 Vector2 vector3 = new Vector2(0f - vector.X, (0f - vector.Y) / 2f);
1540 Vector2 vector4 = new Vector2(0f, (0f - vector2.Y) / 2f);
1543 }
1544 }
1545
1546 public static void StartCamera(CaptureSettings settings)
1547 {
1549 CameraSettings = settings;
1550 CameraLock = true;
1551 CameraWaiting = 0f;
1552 }
1553
1554 public static void EndCamera()
1555 {
1556 CameraLock = false;
1557 }
1558}
static readonly BlendState AlphaBlend
Definition BlendState.cs:36
static readonly RasterizerState CullCounterClockwise
static readonly SamplerState LinearClamp
void Draw(Texture2D texture, Vector2 position, Color color)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
static string Combine(string path1, string path2)
Definition Path.cs:304
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Abs(double value)
const double PI
Definition Math.cs:16
static void PlaySound(int type, Vector2 position, int style=1)
static Asset< DynamicSpriteFont > ItemStack
Definition FontAssets.cs:8
static Asset< DynamicSpriteFont > DeathText
Definition FontAssets.cs:12
static Asset< Texture2D > Map
static Asset< Texture2D > InventoryBack
static Asset< Texture2D > Cd
static Asset< Texture2D > InventoryBack14
static Asset< Texture2D >[] MapIcon
static Asset< Texture2D >[] Extra
static Asset< Texture2D >[] Camera
static Asset< Texture2D > InventoryBack2
static Asset< Texture2D > MagicPixel
static TriggersPack Triggers
static CaptureBiome GetCaptureBiome(int biomeChoice)
void ButtonDraw(int button, ref string key, ref string value)
void DrawWaterChoices(SpriteBatch spritebatch, Point start, Point mouse)
void DrawBound(SpriteBatch sb, Rectangle r, int mode)
Rectangle GetBound(Rectangle drawbox, int boundIndex)
static void StartCamera(CaptureSettings settings)
static void PointWorldClamp(ref Point point, int fluff)
static Dictionary< int, CaptureInterfaceMode > Modes
static bool GetMapCoords(int PinX, int PinY, int Goal, out Point result)
static Dictionary< int, CaptureInterfaceMode > FillModes()
static LocalizedText[] inter
Definition Lang.cs:28
static LocalizedText[] menu
Definition Lang.cs:19
static int OffScreenTiles
Definition Lighting.cs:17
static string GetTextValue(string key)
Definition Language.cs:15
static float mapFullscreenScale
Definition Main.cs:936
static int maxTilesY
Definition Main.cs:1116
static Microsoft.Xna.Framework.Color cursorColor
Definition Main.cs:2205
static float[] liquidAlpha
Definition Main.cs:1206
static int myPlayer
Definition Main.cs:1801
static Vector2 ReverseGravitySupport(Vector2 pos, float height=0f)
Definition Main.cs:3005
static Vector2 ViewSize
Definition Main.cs:2615
static bool mouseRight
Definition Main.cs:616
static bool mouseLeftRelease
Definition Main.cs:1755
static Main instance
Definition Main.cs:283
static Vector2 MouseWorld
Definition Main.cs:2776
static int screenHeight
Definition Main.cs:1721
static Vector2 screenPosition
Definition Main.cs:1715
static Vector2 MouseScreen
Definition Main.cs:2773
static Item mouseItem
Definition Main.cs:1773
static Matrix UIScaleMatrix
Definition Main.cs:2619
static int maxTilesX
Definition Main.cs:1114
static string SavePath
Definition Main.cs:2680
static Matrix CurrentWantedZoomMatrix
Definition Main.cs:2617
static Vector2 mapFullscreenPos
Definition Main.cs:938
static int textureMaxHeight
Definition Main.cs:870
static int textureMaxWidth
Definition Main.cs:868
static Vector2 ViewPosition
Definition Main.cs:2613
static float cursorScale
Definition Main.cs:2211
static Vector3 rgbToHsl(Microsoft.Xna.Framework.Color newColor)
Definition Main.cs:44972
static bool CaptureModeDisabled
Definition Main.cs:279
static bool mapEnabled
Definition Main.cs:906
static int screenWidth
Definition Main.cs:1719
static Microsoft.Xna.Framework.Color hslToRgb(Vector3 hslVector)
Definition Main.cs:44913
static int mouseY
Definition Main.cs:606
static bool mapFullscreen
Definition Main.cs:932
static Player[] player
Definition Main.cs:1803
static int mouseX
Definition Main.cs:604
static GraphicsDeviceManager graphics
Definition Main.cs:972
static bool mouseLeft
Definition Main.cs:614
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 void DrawCursorSingle(SpriteBatch sb, Color color, float rot=float.NaN, float scale=1f, Vector2 manualPosition=default(Vector2), int cursorSlot=0, int specialMode=0)
Definition Utils.cs:2111
static void DrawInvBG(SpriteBatch sb, Rectangle R, Color c=default(Color))
Definition Utils.cs:1921
static void OpenFolder(string folderPath)
Definition Utils.cs:772
static Vector2 DrawBorderStringBig(SpriteBatch spriteBatch, string text, Vector2 pos, Color color, float scale=1f, float anchorx=0f, float anchory=0f, int maxCharactersDisplayed=-1)
Definition Utils.cs:1903
static Rectangle Intersect(Rectangle value1, Rectangle value2)
Definition Rectangle.cs:143
static Vector2 Clamp(Vector2 value1, Vector2 min, Vector2 max)
Definition Vector2.cs:201