Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
GraphicsGlobalItem.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 using System.Linq;
3 using Loot.Api.Core;
5 using Loot.Api.Graphics.Shader;
6 using Microsoft.Xna.Framework;
7 using Microsoft.Xna.Framework.Graphics;
8 using Terraria;
9 using Terraria.ModLoader;
10 
11 namespace Loot.Api.Graphics
12 {
18  {
19  public List<ShaderEntity> ShaderEntities { get; internal set; } = new List<ShaderEntity>();
20  public List<GlowmaskEntity> GlowmaskEntities { get; internal set; } = new List<GlowmaskEntity>();
21 
22  public override bool InstancePerEntity => true;
23  public override bool CloneNewInstances => true;
24 
25  public static GraphicsGlobalItem GetInfo(Item item) => item.GetGlobalItem<GraphicsGlobalItem>();
26 
27  public bool HasShaders => ShaderEntities.Count(x => x != null) > 0;
28  public bool HasGlowmasks => GlowmaskEntities.Count(x => x != null) > 0;
29 
30  public static void UpdateGraphicsEntities(List<Modifier> modifiers, Item item)
31  {
32  var info = item.GetGlobalItem<GraphicsGlobalItem>();
33  info.ShaderEntities = modifiers.Select(mod => mod.GetShaderEntity(item)).OrderBy(mod => mod?.Order ?? 0).ToList();
34  info.GlowmaskEntities = modifiers.Select(mod => mod.GetGlowmaskEntity(item)).OrderBy(mod => mod?.Order ?? 0).ToList();
35  var clone = item.Clone();
36  info.ShaderEntities.ForEach(mod => mod?.SetIdentity(clone));
37  info.GlowmaskEntities.ForEach(mod => mod?.SetIdentity(clone));
38  }
39 
40  public override void UpdateEquip(Item item, Player player)
41  {
42  UpdateIdentity(item);
43  }
44 
45  public override void UpdateInventory(Item item, Player player)
46  {
47  UpdateIdentity(item);
48  }
49 
50  public void UpdateIdentity(Item item)
51  {
52  ShaderEntities.ForEach(entity => entity?.SetIdentity(item));
53  GlowmaskEntities.ForEach(entity => entity?.SetIdentity(item));
54  }
55 
56  public override bool PreDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI)
57  {
58  bool flag = true;
59  UpdateIdentity(item);
60 
61  for (int i = 0; i < ShaderEntities.Count; i++)
62  {
63  ShaderEntity entity = ShaderEntities[i];
64  if (entity != null)
65  {
66  flag = false;
67  entity.DoDrawLayeredEntity(spriteBatch, lightColor, alphaColor, scale, rotation, GlowmaskEntities[i]);
68  }
69  }
70 
71  return flag;
72  }
73 
74  public override void PostDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI)
75  {
76  if (HasShaders) return;
77 
78  foreach (var entity in GlowmaskEntities)
79  {
80  if (entity != null)
81  {
82  entity.DoDrawGlowmask(spriteBatch, lightColor, alphaColor, rotation, scale, whoAmI);
83  entity.DoDrawHitbox(spriteBatch);
84  }
85  }
86  }
87  }
88 }
static void UpdateGraphicsEntities(List< Modifier > modifiers, Item item)
override void UpdateEquip(Item item, Player player)
This class is responsible for handling ShaderEntity and GlowmaskEntity that come from the Modifiers o...
Defines a Shader entity, part of GraphicsEntity<T> The entity defines a particular &#39;shader&#39; "of" the ...
Definition: ShaderEntity.cs:16
override void UpdateInventory(Item item, Player player)
override void PostDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI)
override bool PreDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI)
void DoDrawLayeredEntity(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float scale, float rotation, GlowmaskEntity glowmaskEntity=null, Texture2D suppliedShaderTexture=null, Texture2D suppliedSubjectTexture=null, Texture2D suppliedGlowmaskTexture=null)
Will draw all the layers (subject, glowmask, shader) in the proper order
Definition: ShaderEntity.cs:52