Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SettingsForCharacterPreview.cs
Go to the documentation of this file.
2
4
6{
7 public delegate void CustomAnimationCode(Projectile proj, bool walking);
8
10 {
11 public int StartFrame;
12
13 public int FrameCount;
14
15 public int DelayPerFrame;
16
17 public bool BounceLoop;
18
19 public void ApplyTo(Projectile proj)
20 {
21 if (FrameCount != 0)
22 {
23 if (proj.frame < StartFrame)
24 {
25 proj.frame = StartFrame;
26 }
27 int num = proj.frame - StartFrame;
28 int num2 = FrameCount * DelayPerFrame;
29 int num3 = num2;
30 if (BounceLoop)
31 {
32 num3 = num2 * 2 - DelayPerFrame * 2;
33 }
34 if (++proj.frameCounter >= num3)
35 {
36 proj.frameCounter = 0;
37 }
38 num = proj.frameCounter / DelayPerFrame;
39 if (BounceLoop && num >= FrameCount)
40 {
41 num = FrameCount * 2 - num - 2;
42 }
43 proj.frame = StartFrame + num;
44 }
45 }
46 }
47
49
51
53
54 public int SpriteDirection = 1;
55
56 public CustomAnimationCode CustomAnimation;
57
58 public void ApplyTo(Projectile proj, bool walking)
59 {
60 proj.position += Offset;
61 proj.spriteDirection = SpriteDirection;
62 proj.direction = SpriteDirection;
63 if (walking)
64 {
65 Selected.ApplyTo(proj);
66 }
67 else
68 {
69 NotSelected.ApplyTo(proj);
70 }
71 if (CustomAnimation != null)
72 {
73 CustomAnimation(proj, walking);
74 }
75 }
76
77 public SettingsForCharacterPreview WhenSelected(int? startFrame = null, int? frameCount = null, int? delayPerFrame = null, bool? bounceLoop = null)
78 {
79 Modify(ref Selected, startFrame, frameCount, delayPerFrame, bounceLoop);
80 return this;
81 }
82
83 public SettingsForCharacterPreview WhenNotSelected(int? startFrame = null, int? frameCount = null, int? delayPerFrame = null, bool? bounceLoop = null)
84 {
85 Modify(ref NotSelected, startFrame, frameCount, delayPerFrame, bounceLoop);
86 return this;
87 }
88
89 private static void Modify(ref SelectionBasedSettings target, int? startFrame, int? frameCount, int? delayPerFrame, bool? bounceLoop)
90 {
91 if (frameCount.HasValue && frameCount.Value < 1)
92 {
93 frameCount = 1;
94 }
95 target.StartFrame = (startFrame.HasValue ? startFrame.Value : target.StartFrame);
96 target.FrameCount = (frameCount.HasValue ? frameCount.Value : target.FrameCount);
97 target.DelayPerFrame = (delayPerFrame.HasValue ? delayPerFrame.Value : target.DelayPerFrame);
98 target.BounceLoop = (bounceLoop.HasValue ? bounceLoop.Value : target.BounceLoop);
99 }
100
102 {
103 Offset = offset;
104 return this;
105 }
106
108 {
109 Offset = new Vector2(x, y);
110 return this;
111 }
112
114 {
115 SpriteDirection = spriteDirection;
116 return this;
117 }
118
119 public SettingsForCharacterPreview WithCode(CustomAnimationCode customAnimation)
120 {
121 CustomAnimation = customAnimation;
122 return this;
123 }
124}
SettingsForCharacterPreview WithOffset(float x, float y)
static void Modify(ref SelectionBasedSettings target, int? startFrame, int? frameCount, int? delayPerFrame, bool? bounceLoop)
SettingsForCharacterPreview WithCode(CustomAnimationCode customAnimation)
SettingsForCharacterPreview WithSpriteDirection(int spriteDirection)
SettingsForCharacterPreview WithOffset(Vector2 offset)
delegate void CustomAnimationCode(Projectile proj, bool walking)
SettingsForCharacterPreview WhenSelected(int? startFrame=null, int? frameCount=null, int? delayPerFrame=null, bool? bounceLoop=null)
SettingsForCharacterPreview WhenNotSelected(int? startFrame=null, int? frameCount=null, int? delayPerFrame=null, bool? bounceLoop=null)