Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Segments.cs
Go to the documentation of this file.
10
12
13public class Segments
14{
16 {
17 private const int PixelsForALine = 120;
18
20
21 private float _timeToShowPeak;
22
24
25 public float DedicatedTimeNeeded => 240f;
26
32
39
40 public void Draw(ref GameAnimationSegment info)
41 {
42 float num = 250f;
43 float num2 = 250f;
44 int timeInAnimation = info.TimeInAnimation;
46 if (!(num3 <= 0f))
47 {
48 float num4 = _timeToShowPeak - (float)timeInAnimation;
49 Vector2 position = info.AnchorPositionOnScreen + new Vector2(0f, num4 * 0.5f);
50 position += _anchorOffset;
51 Vector2 baseScale = new Vector2(0.7f);
52 float num5 = Main.GlobalTimeWrappedHourly * 0.02f % 1f;
53 if (num5 < 0f)
54 {
55 num5 += 1f;
56 }
57 Color color = Main.hslToRgb(num5, 1f, 0.5f);
58 string value = _text.Value;
59 Vector2 origin = FontAssets.DeathText.Value.MeasureString(value);
60 origin *= 0.5f;
61 float num6 = 1f - (1f - num3) * (1f - num3);
62 ChatManager.DrawColorCodedStringShadow(info.SpriteBatch, FontAssets.DeathText.Value, value, position, color * num6 * num6 * 0.25f * info.DisplayOpacity, 0f, origin, baseScale);
63 ChatManager.DrawColorCodedString(info.SpriteBatch, FontAssets.DeathText.Value, value, position, Color.White * num6 * info.DisplayOpacity, 0f, origin, baseScale);
64 }
65 }
66 }
67
69 {
71
73
74 protected int _targetTime;
75
77
79
85
86 protected void ProcessActions(T obj, float localTimeForObject)
87 {
88 for (int i = 0; i < _actions.Count; i++)
89 {
90 _actions[i].ApplyTo(obj, localTimeForObject);
91 }
92 }
93
95 {
96 Bind(act);
97 act.SetDelay(_dedicatedTimeNeeded);
100 _dedicatedTimeNeeded += act.ExpectedLengthOfActionInFrames;
101 return this;
102 }
103
111
112 protected abstract void Bind(IAnimationSegmentAction<T> act);
113
114 public abstract void Draw(ref GameAnimationSegment info);
115 }
116
118 {
119 public interface IShaderEffect
120 {
122
124 }
125
140
142
144
146
148
149 private static Item _blankItem = new Item();
150
158
164
165 protected override void Bind(IAnimationSegmentAction<Player> act)
166 {
167 act.BindTo(_player);
168 }
169
170 public override void Draw(ref GameAnimationSegment info)
171 {
172 if ((float)info.TimeInAnimation > (float)_targetTime + base.DedicatedTimeNeeded || info.TimeInAnimation < _targetTime)
173 {
174 return;
175 }
177 float localTimeForObject = info.TimeInAnimation - _targetTime;
179 if (info.DisplayOpacity != 0f)
180 {
186 _player.socialIgnoreLight = true;
187 _player.position += Main.screenPosition;
188 _player.position -= new Vector2(_player.width / 2, _player.height);
189 _player.opacityForAnimation *= info.DisplayOpacity;
192 float num = 1f - _player.opacityForAnimation;
193 num = 0f;
194 if (_shaderEffect != null)
195 {
197 }
199 if (_shaderEffect != null)
200 {
202 }
204 }
205 }
206
208 {
210 _player.position = info.AnchorPositionOnScreen + _anchorOffset;
211 _player.opacityForAnimation = 1f;
212 }
213 }
214
216 {
217 private NPC _npc;
218
220
222
225 {
226 _npc = new NPC();
228 {
229 gameModeData = Main.RegisteredGameModes[0],
230 playerCountForMultiplayerDifficultyOverride = 1,
231 sizeScaleOverride = null,
232 strengthMultiplierOverride = 1f
233 });
234 _npc.IsABestiaryIconDummy = true;
237 }
238
239 protected override void Bind(IAnimationSegmentAction<NPC> act)
240 {
241 act.BindTo(_npc);
242 }
243
244 public override void Draw(ref GameAnimationSegment info)
245 {
246 if ((float)info.TimeInAnimation > (float)_targetTime + base.DedicatedTimeNeeded || info.TimeInAnimation < _targetTime)
247 {
248 return;
249 }
251 float localTimeForObject = info.TimeInAnimation - _targetTime;
253 if (_npc.alpha < 255)
254 {
255 _npc.FindFrame();
257 {
258 TextureAssets.Npc[_npc.type] = profile.GetTextureNPCShouldUse(_npc);
259 }
260 _npc.Opacity *= info.DisplayOpacity;
261 Main.instance.DrawNPCDirect(info.SpriteBatch, _npc, _npc.behindTiles, Vector2.Zero);
262 }
263 }
264
266 {
267 _npc.position = info.AnchorPositionOnScreen + _anchorOffset - _npc.Size * _normalizedOriginForHitbox;
268 _npc.alpha = 0;
269 _npc.velocity = Vector2.Zero;
270 }
271 }
272
273 public class LooseSprite
274 {
276
278
280
281 public float CurrentOpacity;
282
284 {
285 _originalDrawData = data;
286 _asset = asset;
287 Reset();
288 }
289
290 public void Reset()
291 {
292 _originalDrawData.texture = _asset.Value;
294 CurrentOpacity = 1f;
295 }
296 }
297
298 public class SpriteSegment : AnimationSegmentWithActions<LooseSprite>
299 {
306
308 {
310
311 private readonly string _shaderKey;
312
313 private readonly int _verticalFrameCount;
314
315 private readonly int _verticalFrameWait;
316
317 private Panning _panX;
318
319 private Panning _panY;
320
321 private GetMatrixAction _fetchMatrix;
322
323 public MaskedFadeEffect(GetMatrixAction fetchMatrixMethod = null, string shaderKey = "MaskedFade", int verticalFrameCount = 1, int verticalFrameWait = 1)
324 {
328 if (verticalFrameWait < 1)
329 {
331 }
333 if (_fetchMatrix == null)
334 {
336 }
337 }
338
343
345 {
346 info.SpriteBatch.End();
349 miscShaderData.UseShaderSpecificData(new Vector4(y: (float)(info.TimeInAnimation / _verticalFrameWait % _verticalFrameCount) / (float)_verticalFrameCount, x: 1f / (float)_verticalFrameCount, z: _panX.GetPanAmount(info.TimeInAnimation), w: _panY.GetPanAmount(info.TimeInAnimation)));
351 }
352
354 {
355 _panX = panning;
356 return this;
357 }
358
360 {
361 _panY = panning;
362 return this;
363 }
364
366 {
367 Main.pixelShader.CurrentTechnique.Passes[0].Apply();
368 info.SpriteBatch.End();
370 }
371 }
372
374
376
378
381 {
382 _sprite = new LooseSprite(data, asset);
384 }
385
387 {
388 act.BindTo(_sprite);
389 }
390
396
397 public override void Draw(ref GameAnimationSegment info)
398 {
399 if (!((float)info.TimeInAnimation > (float)_targetTime + base.DedicatedTimeNeeded) && info.TimeInAnimation >= _targetTime)
400 {
402 float localTimeForObject = info.TimeInAnimation - _targetTime;
405 drawData.position += info.AnchorPositionOnScreen + _anchorOffset;
406 drawData.color *= _sprite.CurrentOpacity * info.DisplayOpacity;
407 if (_shaderEffect != null)
408 {
410 }
411 drawData.Draw(info.SpriteBatch);
412 if (_shaderEffect != null)
413 {
415 }
416 }
417 }
418
420 {
421 _sprite.Reset();
422 }
423 }
424
425 public struct Panning
426 {
427 public float AmountOverTime;
428
429 public float StartAmount;
430
431 public float Delay;
432
433 public float Duration;
434
435 public float GetPanAmount(float time)
436 {
437 float num = MathHelper.Clamp((time - Delay) / Duration, 0f, 1f);
438 return StartAmount + num * AmountOverTime;
439 }
440 }
441
443 {
444 private int _targetTime;
445
447
449
450 private int _emoteId;
451
453
454 public float DedicatedTimeNeeded { get; private set; }
455
456 public EmoteSegment(int emoteId, int targetTime, int timeToPlay, Vector2 position, SpriteEffects drawEffect, Vector2 velocity = default(Vector2))
457 {
461 _offset = position;
462 _velocity = velocity;
464 }
465
466 public void Draw(ref GameAnimationSegment info)
467 {
468 int num = info.TimeInAnimation - _targetTime;
469 if (num < 0 || (float)num >= DedicatedTimeNeeded)
470 {
471 return;
472 }
473 Vector2 vec = info.AnchorPositionOnScreen + _offset + _velocity * num;
474 vec = vec.Floor();
475 bool flag = num < 6 || (float)num >= DedicatedTimeNeeded - 6f;
476 Texture2D value = TextureAssets.Extra[48].Value;
477 Rectangle value2 = value.Frame(8, EmoteBubble.EMOTE_SHEET_VERTICAL_FRAMES, (!flag) ? 1 : 0);
478 Vector2 origin = new Vector2(value2.Width / 2, value2.Height);
480 info.SpriteBatch.Draw(value, vec, value2, Color.White * info.DisplayOpacity, 0f, origin, 1f, spriteEffects, 0f);
481 if (!flag)
482 {
483 int emoteId = _emoteId;
484 if ((emoteId == 87 || emoteId == 89) && spriteEffects.HasFlag(SpriteEffects.FlipHorizontally))
485 {
486 spriteEffects &= ~SpriteEffects.FlipHorizontally;
487 vec.X += 4f;
488 }
489 info.SpriteBatch.Draw(value, vec, GetFrame(num % 20), Color.White, 0f, origin, 1f, spriteEffects, 0f);
490 }
491 }
492
494 {
495 int num = ((wrappedTime >= 10) ? 1 : 0);
496 return TextureAssets.Extra[48].Value.Frame(8, EmoteBubble.EMOTE_SHEET_VERTICAL_FRAMES, _emoteId % 4 * 2 + num, _emoteId / 4 + 1);
497 }
498 }
499
500 private const float PixelsToRollUpPerFrame = 0.5f;
501}
static readonly BlendState AlphaBlend
Definition BlendState.cs:36
static readonly SamplerState LinearClamp
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
void Add(TKey key, TValue value)
Vector2 position
Definition Entity.cs:14
AnimationSegmentWithActions< T > With(IAnimationSegmentAction< T > act)
Definition Segments.cs:104
AnimationSegmentWithActions< T > Then(IAnimationSegmentAction< T > act)
Definition Segments.cs:94
void Draw(ref GameAnimationSegment info)
Definition Segments.cs:466
EmoteSegment(int emoteId, int targetTime, int timeToPlay, Vector2 position, SpriteEffects drawEffect, Vector2 velocity=default(Vector2))
Definition Segments.cs:456
LocalizedTextSegment(float timeInAnimation, LocalizedText textObject, Vector2 anchorOffset)
Definition Segments.cs:33
LocalizedTextSegment(float timeInAnimation, string textKey)
Definition Segments.cs:27
LooseSprite(DrawData data, Asset< Texture2D > asset)
Definition Segments.cs:283
NPCSegment(int targetTime, int npcId, Vector2 anchorOffset, Vector2 normalizedNPCHitboxOrigin)
Definition Segments.cs:223
void ResetNPCAnimation(ref GameAnimationSegment info)
Definition Segments.cs:265
override void Bind(IAnimationSegmentAction< NPC > act)
Definition Segments.cs:239
override void Draw(ref GameAnimationSegment info)
Definition Segments.cs:244
PlayerSegment UseShaderEffect(IShaderEffect shaderEffect)
Definition Segments.cs:159
override void Draw(ref GameAnimationSegment info)
Definition Segments.cs:170
void ResetPlayerAnimation(ref GameAnimationSegment info)
Definition Segments.cs:207
PlayerSegment(int targetTime, Vector2 anchorOffset, Vector2 normalizedHitboxOrigin)
Definition Segments.cs:151
override void Bind(IAnimationSegmentAction< Player > act)
Definition Segments.cs:165
void AfterDrawing(ref GameAnimationSegment info, ref DrawData drawData)
Definition Segments.cs:365
MaskedFadeEffect(GetMatrixAction fetchMatrixMethod=null, string shaderKey="MaskedFade", int verticalFrameCount=1, int verticalFrameWait=1)
Definition Segments.cs:323
void BeforeDrawing(ref GameAnimationSegment info, ref DrawData drawData)
Definition Segments.cs:344
void ResetSpriteAnimation(ref GameAnimationSegment info)
Definition Segments.cs:419
override void Bind(IAnimationSegmentAction< LooseSprite > act)
Definition Segments.cs:386
override void Draw(ref GameAnimationSegment info)
Definition Segments.cs:397
SpriteSegment UseShaderEffect(IShaderEffect shaderEffect)
Definition Segments.cs:391
SpriteSegment(Asset< Texture2D > asset, int targetTime, DrawData data, Vector2 anchorOffset)
Definition Segments.cs:379
static Asset< DynamicSpriteFont > DeathText
Definition FontAssets.cs:12
static Asset< Texture2D >[] Npc
static Asset< Texture2D >[] Extra
static readonly int EMOTE_SHEET_VERTICAL_FRAMES
static Dictionary< string, MiscShaderData > Misc
static LocalizedText GetText(string key)
Definition Language.cs:10
static Matrix CurrentBackgroundMatrixForCreditsRoll
Definition Main.cs:86
static Effect pixelShader
Definition Main.cs:2764
static IPlayerRenderer PlayerRenderer
Definition Main.cs:291
static Main instance
Definition Main.cs:283
static Vector2 screenPosition
Definition Main.cs:1715
static Camera Camera
Definition Main.cs:289
static SamplerState DefaultSamplerState
Definition Main.cs:2814
static RasterizerState Rasterizer
Definition Main.cs:552
static Microsoft.Xna.Framework.Color hslToRgb(Vector3 hslVector)
Definition Main.cs:44913
static Player LocalPlayer
Definition Main.cs:2829
static Dictionary< int, GameModeData > RegisteredGameModes
Definition Main.cs:315
void SetDefaults(int Type, NPCSpawnParams spawnparams=default(NPCSpawnParams))
Definition NPC.cs:2523
void FindFrame()
Definition NPC.cs:59052
int type
Definition NPC.cs:445
int alpha
Definition NPC.cs:489
bool behindTiles
Definition NPC.cs:519
void ResetEffects()
Definition Player.cs:17886
float opacityForAnimation
Definition Player.cs:1501
void ResetVisibleAccessories()
Definition Player.cs:28887
void CopyVisuals(Player other)
Definition Player.cs:50885
void UpdateDyes()
Definition Player.cs:9096
void UpdateMiscCounter()
Definition Player.cs:27566
Vector2 fullRotationOrigin
Definition Player.cs:1293
Item[] inventory
Definition Player.cs:1257
void PlayerFrame()
Definition Player.cs:33978
static void DrawColorCodedStringShadow(SpriteBatch spriteBatch, DynamicSpriteFont font, TextSnippet[] snippets, Vector2 position, Color baseColor, float rotation, Vector2 origin, Vector2 baseScale, float maxWidth=-1f, float spread=2f)
static Vector2 DrawColorCodedString(SpriteBatch spriteBatch, DynamicSpriteFont font, TextSnippet[] snippets, Vector2 position, Color baseColor, float rotation, Vector2 origin, Vector2 baseScale, out int hoveredSnippet, float maxWidth, bool ignoreColors=false)
static float GetLerpValue(float from, float to, float t, bool clamped=false)
Definition Utils.cs:203
void AfterDrawing(ref GameAnimationSegment info, ref DrawData drawData)
void BeforeDrawing(ref GameAnimationSegment info, ref DrawData drawData)