forked from SamsonAllen13/ClickerClass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeadLayer.cs
76 lines (65 loc) · 2.16 KB
/
HeadLayer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;
namespace ClickerClass.DrawLayers
{
//Items manually register data which this layer is using
public sealed class HeadLayer : PlayerDrawLayer
{
private static Dictionary<int, DrawLayerData> HeadLayerData { get; set; }
/// <summary>
/// Add data associated with the head equip slot here, usually in <see cref="ModType.SetStaticDefaults"/>.
/// <para>Don't forget the !Main.dedServ check!</para>
/// </summary>
/// <param name="headSlot">Head equip slot</param>
/// <param name="data">Data</param>
public static void RegisterData(int headSlot, DrawLayerData data)
{
if (!HeadLayerData.ContainsKey(headSlot))
{
HeadLayerData.Add(headSlot, data);
}
}
public override void Load()
{
HeadLayerData = new Dictionary<int, DrawLayerData>();
}
public override void Unload()
{
HeadLayerData = null;
}
public override Position GetDefaultPosition()
{
return new AfterParent(PlayerDrawLayers.Head);
}
public override bool GetDefaultVisibility(PlayerDrawSet drawInfo)
{
Player drawPlayer = drawInfo.drawPlayer;
if (drawPlayer.dead || drawPlayer.invis || drawPlayer.head == -1)
{
return false;
}
return true;
}
protected override void Draw(ref PlayerDrawSet drawInfo)
{
Player drawPlayer = drawInfo.drawPlayer;
if (!HeadLayerData.TryGetValue(drawPlayer.head, out DrawLayerData data))
{
return;
}
Color color = drawPlayer.GetImmuneAlphaPure(data.Color(drawInfo), drawInfo.shadow);
Texture2D texture = data.Texture.Value;
Vector2 drawPos = drawInfo.Position - Main.screenPosition + new Vector2(drawPlayer.width / 2 - drawPlayer.bodyFrame.Width / 2, drawPlayer.height - drawPlayer.bodyFrame.Height + 4f) + drawPlayer.headPosition;
Vector2 headVect = drawInfo.headVect;
DrawData drawData = new DrawData(texture, drawPos.Floor() + headVect, drawPlayer.bodyFrame, color, drawPlayer.headRotation, headVect, 1f, drawInfo.playerEffect, 0)
{
shader = drawInfo.cHead
};
drawInfo.DrawDataCache.Add(drawData);
}
}
}