Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
GlowmaskEntity.cs
Go to the documentation of this file.
1 using Loot.Api.ModContent;
2 using Microsoft.Xna.Framework;
3 using Microsoft.Xna.Framework.Graphics;
4 using Terraria;
5 
6 namespace Loot.Api.Graphics.Glowmask
7 {
15  public class GlowmaskEntity : GraphicsEntity<GlowmaskGraphicsProperties>
16  {
17  public bool DrawHitbox { get; set; } // mostly for debug purposes
18  public Texture2D GlowmaskTexture { get; protected set; }
19 
20  public GlowmaskEntity(object subjectIdentity, bool drawHitbox = false, short order = 0, Color? drawColor = null,
21  GlowmaskGraphicsProperties props = null)
22  : base(subjectIdentity)
23  {
24  DrawHitbox = drawHitbox;
25  Order = order;
26  DrawColor = drawColor ?? Color.White;
27  Properties = props ?? GlowmaskGraphicsProperties.Builder.Build();
28  }
29 
30  protected override void LoadAssets(Item item)
31  {
32  if (GlowmaskTexture != null) return;
33  var graphicsContent = Loot.ModContentManager.GetContent<GraphicsModContent>();
34  graphicsContent?.Prepare(item);
35  GlowmaskTexture = graphicsContent?.GetPreparedGlowmask(item.type.ToString()) ?? Main.itemTexture[item.type];
36  }
37 
41  public void DoDrawGlowmask(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI, Texture2D suppliedGlowmask = null)
42  {
43  if (!Properties.SkipDrawing || !Properties.SkipDrawingGlowmask) return;
44 
45  TryGettingDrawData(rotation, scale);
46  if (Entity is Item item) LoadAssets(item);
47  else Loot.Logger.Warn("Could not identify shader entity identity as item");
48  Texture2D useGlowmaskTexture = suppliedGlowmask ?? GlowmaskTexture;
49 
50  if (useGlowmaskTexture != null)
51  {
52  var drawDataTexture = DrawData.texture;
53  var drawDataColor = DrawData.color;
54  var drawDataDestinationRectangle = DrawData.destinationRectangle;
55  DrawData.texture = useGlowmaskTexture;
56  DrawData.color = lightColor;
57  TryUpdatingDrawData(useGlowmaskTexture);
58  DrawEntity(spriteBatch);
59  DrawData.texture = drawDataTexture;
60  DrawData.color = drawDataColor;
61  DrawData.destinationRectangle = drawDataDestinationRectangle;
62  }
63 
64  Properties.SkipUpdatingDrawData = false;
65  }
66 
70  public void DoDrawHitbox(SpriteBatch spriteBatch)
71  {
72  if (!DrawHitbox) return;
73  Rectangle hitbox = Entity.Hitbox;
74  hitbox.Offset((int)-Main.screenPosition.X, (int)-Main.screenPosition.Y);
75  spriteBatch.Draw(Main.magicPixel, hitbox, Color.White);
76  }
77  }
78 }
void DoDrawGlowmask(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI, Texture2D suppliedGlowmask=null)
Will draw the glowmask texture
Defines the GraphicsProperties for GlowmaskEntitys which derives from GraphicsProperties ...
static new GlowmaskGraphicsPropertiesBuilder Builder
GlowmaskEntity(object subjectIdentity, bool drawHitbox=false, short order=0, Color?drawColor=null, GlowmaskGraphicsProperties props=null)
Defines the base abstract of a GraphicsEntity
void DoDrawHitbox(SpriteBatch spriteBatch)
Will draw the hitbox around the entity
Defines a Glowmask entity, part of GraphicsEntity The entity defines a particular &#39;glowmask&#39; "of" the...
This class stores glowmask and shader textures that can be looked up during drawing ...