Terraria ModLoader  0.11.7.8
A mod to make and play Terraria mods
DrawLayer.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 
4 namespace Terraria.ModLoader
5 {
10  public abstract class DrawLayer<InfoType>
11  {
15  public readonly string mod;
19  public readonly string Name;
23  public readonly DrawLayer<InfoType> parent;
27  public readonly Action<InfoType> layer;
31  public bool visible = true;
32 
39  protected DrawLayer(string mod, string name, Action<InfoType> layer) {
40  this.mod = mod;
41  this.Name = name;
42  this.parent = null;
43  this.layer = layer;
44  }
45 
53  protected DrawLayer(string mod, string name, DrawLayer<InfoType> parent, Action<InfoType> layer) {
54  this.mod = mod;
55  this.Name = name;
56  this.parent = parent;
57  this.layer = layer;
58  }
59 
66  public bool ShouldDraw<T>(IList<T> layers) where T : DrawLayer<InfoType> {
67  if (!this.visible) {
68  return false;
69  }
70  DrawLayer<InfoType> parentLayer = this.parent;
71  while (parentLayer != null) {
72  if (!parentLayer.visible || !layers.Contains((T)parentLayer)) {
73  return false;
74  }
75  parentLayer = parentLayer.parent;
76  }
77  return true;
78  }
79 
84  public virtual void Draw(ref InfoType drawInfo) {
85  this.layer(drawInfo);
86  }
87  }
88 
92  public class PlayerLayer : DrawLayer<PlayerDrawInfo>
93  {
97  public static readonly PlayerLayer HairBack = CreateVanillaLayer("HairBack");
101  public static readonly PlayerLayer MountBack = CreateVanillaLayer("MountBack");
105  public static readonly PlayerLayer MiscEffectsBack = CreateVanillaLayer("MiscEffectsBack");
109  public static readonly PlayerLayer BackAcc = CreateVanillaLayer("BackAcc");
113  public static readonly PlayerLayer Wings = CreateVanillaLayer("Wings");
117  public static readonly PlayerLayer BalloonAcc = CreateVanillaLayer("BalloonAcc");
121  public static readonly PlayerLayer Skin = CreateVanillaLayer("Skin");
125  public static readonly PlayerLayer Legs = CreateVanillaLayer("Legs");
129  public static readonly PlayerLayer ShoeAcc = CreateVanillaLayer("ShoeAcc");
133  public static readonly PlayerLayer Body = CreateVanillaLayer("Body");
137  public static readonly PlayerLayer HandOffAcc = CreateVanillaLayer("HandOffAcc");
141  public static readonly PlayerLayer WaistAcc = CreateVanillaLayer("WaistAcc");
145  public static readonly PlayerLayer NeckAcc = CreateVanillaLayer("NeckAcc");
149  public static readonly PlayerLayer Face = CreateVanillaLayer("Face");
153  public static readonly PlayerLayer Hair = CreateVanillaLayer("Hair");
157  public static readonly PlayerLayer Head = CreateVanillaLayer("Head");
161  public static readonly PlayerLayer FaceAcc = CreateVanillaLayer("FaceAcc");
165  public static readonly PlayerLayer MountFront = CreateVanillaLayer("MountFront");
169  public static readonly PlayerLayer ShieldAcc = CreateVanillaLayer("ShieldAcc");
173  public static readonly PlayerLayer SolarShield = CreateVanillaLayer("SolarShield");
177  public static readonly PlayerLayer HeldProjBack = CreateVanillaLayer("HeldProjBack");
181  public static readonly PlayerLayer HeldItem = CreateVanillaLayer("HeldItem");
185  public static readonly PlayerLayer Arms = CreateVanillaLayer("Arms");
189  public static readonly PlayerLayer HandOnAcc = CreateVanillaLayer("HandOnAcc");
193  public static readonly PlayerLayer HeldProjFront = CreateVanillaLayer("HeldProjFront");
197  public static readonly PlayerLayer FrontAcc = CreateVanillaLayer("FrontAcc");
201  public static readonly PlayerLayer MiscEffectsFront = CreateVanillaLayer("MiscEffectsFront");
202 
209  public PlayerLayer(string mod, string name, Action<PlayerDrawInfo> layer)
210  : base(mod, name, layer) {
211  }
212 
220  public PlayerLayer(string mod, string name, PlayerLayer parent, Action<PlayerDrawInfo> layer)
221  : base(mod, name, parent, layer) {
222  }
223 
224  private static PlayerLayer CreateVanillaLayer(string name) {
225  return new PlayerLayer("Terraria", name, _ => { });
226  }
227  }
228 
232  public class PlayerHeadLayer : DrawLayer<PlayerHeadDrawInfo>
233  {
237  public static readonly PlayerHeadLayer Head = CreateVanillaLayer("Head");
241  public static readonly PlayerHeadLayer Hair = CreateVanillaLayer("Hair");
245  public static readonly PlayerHeadLayer AltHair = CreateVanillaLayer("AltHair");
249  public static readonly PlayerHeadLayer Armor = CreateVanillaLayer("Armor");
253  public static readonly PlayerHeadLayer FaceAcc = CreateVanillaLayer("FaceAcc");
254 
261  public PlayerHeadLayer(string mod, string name, Action<PlayerHeadDrawInfo> layer)
262  : base(mod, name, layer) {
263  }
264 
272  public PlayerHeadLayer(string mod, string name, PlayerHeadLayer parent, Action<PlayerHeadDrawInfo> layer)
273  : base(mod, name, parent, layer) {
274  }
275 
276  private static PlayerHeadLayer CreateVanillaLayer(string name) {
277  return new PlayerHeadLayer("Terraria", name, _ => { });
278  }
279  }
280 }
static PlayerHeadLayer CreateVanillaLayer(string name)
Definition: DrawLayer.cs:276
DrawLayer(string mod, string name, Action< InfoType > layer)
Creates a DrawLayer with the given mod name, identifier name, and drawing action. ...
Definition: DrawLayer.cs:39
readonly string Name
The name which identifies this DrawLayer.
Definition: DrawLayer.cs:19
DrawLayer(string mod, string name, DrawLayer< InfoType > parent, Action< InfoType > layer)
Creates a DrawLayer with the given mod name, identifier name, parent layer, and drawing action...
Definition: DrawLayer.cs:53
PlayerLayer(string mod, string name, Action< PlayerDrawInfo > layer)
Creates a PlayerLayer with the given mod name, identifier name, and drawing action.
Definition: DrawLayer.cs:209
This class represents a layer of the drawing of an object, using a certain type of InfoType to help w...
Definition: DrawLayer.cs:10
PlayerLayer(string mod, string name, PlayerLayer parent, Action< PlayerDrawInfo > layer)
Creates a PlayerLayer with the given mod name, identifier name, parent layer, and drawing action...
Definition: DrawLayer.cs:220
PlayerHeadLayer(string mod, string name, PlayerHeadLayer parent, Action< PlayerHeadDrawInfo > layer)
Creates a PlayerHeadLayer with the given mod name, identifier name, parent layer, and drawing action...
Definition: DrawLayer.cs:272
bool visible
Whether or not this DrawLayer should be drawn. For vanilla layers, this will be set to true before al...
Definition: DrawLayer.cs:31
readonly Action< InfoType > layer
The delegate of this method, which can either do the actual drawing or add draw data, depending on what kind of layer this is.
Definition: DrawLayer.cs:27
readonly string mod
The name of the mod to which this DrawLayer belongs.
Definition: DrawLayer.cs:15
This class represents a DrawLayer for the player&#39;s map icon, and uses PlayerDrawHeadInfo as its InfoT...
Definition: DrawLayer.cs:232
readonly DrawLayer< InfoType > parent
The parent of this DrawLayer. If the parent is not drawn, this layer will not be drawn either...
Definition: DrawLayer.cs:23
PlayerHeadLayer(string mod, string name, Action< PlayerHeadDrawInfo > layer)
Creates a PlayerHeadLayer with the given mod name, identifier name, and drawing action.
Definition: DrawLayer.cs:261
static PlayerLayer CreateVanillaLayer(string name)
Definition: DrawLayer.cs:224
This class represents a DrawLayer for the player, and uses PlayerDrawInfo as its InfoType. Drawing should be done by adding Terraria.DataStructures.DrawData objects to Main.playerDrawData.
Definition: DrawLayer.cs:92
virtual void Draw(ref InfoType drawInfo)
Invokes this DrawLayer&#39;s layer action.
Definition: DrawLayer.cs:84