tModLoader v0.11.8.9
A mod to make and play Terraria mods
DrawLayer.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3
4namespace 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}
This class represents a layer of the drawing of an object, using a certain type of InfoType to help w...
Definition: DrawLayer.cs:11
readonly string Name
The name which identifies this DrawLayer.
Definition: DrawLayer.cs:19
bool ShouldDraw< T >(IList< T > layers)
Whether or not this layer should be drawn. Returns false if visible is false. If layerList is of type...
Definition: DrawLayer.cs:66
virtual void Draw(ref InfoType drawInfo)
Invokes this DrawLayer's layer action.
Definition: DrawLayer.cs:84
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 mod
The name of the mod to which this DrawLayer belongs.
Definition: DrawLayer.cs:15
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
readonly Action< InfoType > layer
The delegate of this method, which can either do the actual drawing or add draw data,...
Definition: DrawLayer.cs:27
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
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
This class represents a DrawLayer for the player's map icon, and uses PlayerDrawHeadInfo as its InfoT...
Definition: DrawLayer.cs:233
static readonly PlayerHeadLayer AltHair
Draws the player's alternate (hat) hair.
Definition: DrawLayer.cs:245
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
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
static readonly PlayerHeadLayer Head
Draws the player's face and eyes.
Definition: DrawLayer.cs:237
static readonly PlayerHeadLayer Armor
Draws the player's head armor.
Definition: DrawLayer.cs:249
static PlayerHeadLayer CreateVanillaLayer(string name)
Definition: DrawLayer.cs:276
static readonly PlayerHeadLayer FaceAcc
Draws the player's face accessory.
Definition: DrawLayer.cs:253
static readonly PlayerHeadLayer Hair
Draws the player's hair.
Definition: DrawLayer.cs:241
This class represents a DrawLayer for the player, and uses PlayerDrawInfo as its InfoType....
Definition: DrawLayer.cs:93
static readonly PlayerLayer Legs
Draws the player's leg armor or pants and shoes.
Definition: DrawLayer.cs:125
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
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
static readonly PlayerLayer MountBack
Draws the back textures of the player's mount. Also draws the player's magic carpet.
Definition: DrawLayer.cs:101
static readonly PlayerLayer MiscEffectsFront
Draws miscellaneous effects in front of the player.
Definition: DrawLayer.cs:201
static readonly PlayerLayer Face
Draws the player's face and eyes.
Definition: DrawLayer.cs:149
static readonly PlayerLayer SolarShield
Draws the player's solar shield if the player has one.
Definition: DrawLayer.cs:173
static readonly PlayerLayer NeckAcc
Draws the player's neck accessory.
Definition: DrawLayer.cs:145
static readonly PlayerLayer FrontAcc
Draws the player's front accessory.
Definition: DrawLayer.cs:197
static readonly PlayerLayer BackAcc
Draws the player's back accessory and held item's backpack.
Definition: DrawLayer.cs:109
static readonly PlayerLayer FaceAcc
Draws the player's face accessory.
Definition: DrawLayer.cs:161
static PlayerLayer CreateVanillaLayer(string name)
Definition: DrawLayer.cs:224
static readonly PlayerLayer Wings
Draws the layer's wings.
Definition: DrawLayer.cs:113
static readonly PlayerLayer Hair
Draws the player's hair.
Definition: DrawLayer.cs:153
static readonly PlayerLayer HeldProjFront
Draws the player's held projectile if it should be drawn in front of the held item and arms.
Definition: DrawLayer.cs:193
static readonly PlayerLayer HairBack
Draws the player's hair. To be honest this layer seems kind of useless.
Definition: DrawLayer.cs:97
static readonly PlayerLayer Arms
Draws the player's arms (including the armor's arms if applicable).
Definition: DrawLayer.cs:185
static readonly PlayerLayer Head
Draws the player's head armor.
Definition: DrawLayer.cs:157
static readonly PlayerLayer WaistAcc
Draws the player's waist accessory.
Definition: DrawLayer.cs:141
static readonly PlayerLayer BalloonAcc
Draws the player's balloon accessory.
Definition: DrawLayer.cs:117
static readonly PlayerLayer ShieldAcc
Draws the player's shield accessory.
Definition: DrawLayer.cs:169
static readonly PlayerLayer HeldItem
Draws the player's held item.
Definition: DrawLayer.cs:181
static readonly PlayerLayer Body
Draws the player's body armor or shirts.
Definition: DrawLayer.cs:133
static readonly PlayerLayer HandOnAcc
Draws the player's hand on accessory. Also draws the player's held item if the player is in the middl...
Definition: DrawLayer.cs:189
static readonly PlayerLayer ShoeAcc
Draws the player's shoe accessory.
Definition: DrawLayer.cs:129
static readonly PlayerLayer HandOffAcc
Draws the player's hand off accessory.
Definition: DrawLayer.cs:137
static readonly PlayerLayer Skin
Draws the player's body and leg skin.
Definition: DrawLayer.cs:121
static readonly PlayerLayer HeldProjBack
Draws the player's held projectile if it should be drawn behind the held item and arms.
Definition: DrawLayer.cs:177
static readonly PlayerLayer MiscEffectsBack
Draws miscellaneous effects behind the player.
Definition: DrawLayer.cs:105
static readonly PlayerLayer MountFront
Draws the front textures of the player's mount. Also draws the pulley if the player is hanging on a r...
Definition: DrawLayer.cs:165