Skip to content

Commit

Permalink
add support for NPC music and drawing-related hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
blushiemagic committed Aug 18, 2015
1 parent 76a9dad commit 483328d
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 47 deletions.
15 changes: 15 additions & 0 deletions patches/tModLoader/Terraria.ModLoader/GlobalNPC.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;

Expand Down Expand Up @@ -125,5 +126,19 @@ public virtual void BossHeadRotation(NPC npc, ref float rotation)
public virtual void BossHeadSpriteEffects(NPC npc, ref SpriteEffects spriteEffects)
{
}

public virtual Color? GetAlpha(NPC npc, Color drawColor)
{
return null;
}

public virtual bool PreDraw(NPC npc, SpriteBatch spriteBatch, Color drawColor)
{
return true;
}

public virtual void PostDraw(NPC npc, SpriteBatch spriteBatch, Color drawColor)
{
}
}
}
20 changes: 20 additions & 0 deletions patches/tModLoader/Terraria.ModLoader/ModNPC.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;

Expand All @@ -24,6 +25,11 @@ public Mod mod
public int aiType = 0;
public int animationType = 0;
public int bossBag = -1;
//make changes to Terraria.Main.UpdateMusic (see patch files)
public int music = -1;
//in Terraria.Main.NPCAddHeight at end of else if chain add
// else if(Main.npc[i].modNPC != null) { num = Main.npc[i].modNPC.drawOffsetY; }
public float drawOffsetY = 0f;

public ModNPC()
{
Expand Down Expand Up @@ -154,5 +160,19 @@ public virtual void BossHeadRotation(ref float rotation)
public virtual void BossHeadSpriteEffects(ref SpriteEffects spriteEffects)
{
}

public virtual Color? GetAlpha(Color drawColor)
{
return null;
}

public virtual bool PreDraw(SpriteBatch spriteBatch, Color drawColor)
{
return true;
}

public virtual void PostDraw(SpriteBatch spriteBatch, Color drawColor)
{
}
}
}
48 changes: 48 additions & 0 deletions patches/tModLoader/Terraria.ModLoader/NPCLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,5 +510,53 @@ internal static void BossHeadSpriteEffects(NPC npc, ref SpriteEffects spriteEffe
globalNPC.BossHeadSpriteEffects(npc, ref spriteEffects);
}
}
//at beginning of Terraria.NPC.GetAlpha add
// Color? modColor = NPCLoader.GetAlpha(this, new Color); if(modColor.HasValue) { return modColor.Value; }
internal static Color? GetAlpha(NPC npc, Color lightColor)
{
foreach (GlobalNPC globalNPC in globalNPCs)
{
Color? color = globalNPC.GetAlpha(npc, lightColor);
if (color.HasValue)
{
return color.Value;
}
}
if (IsModNPC(npc))
{
return npc.modNPC.GetAlpha(lightColor);
}
return null;
}
//in Terraria.Main.DrawNPC after modifying draw color add
// if(!NPCLoader.PreDraw(Main.npc[i], Main.spriteBatch, color9))
// { NPCLoader.PostDraw(Main.npc[k], Main.spriteBatch, color9); return; }
internal static bool PreDraw(NPC npc, SpriteBatch spriteBatch, Color drawColor)
{
foreach (GlobalNPC globalNPC in globalNPCs)
{
if (!globalNPC.PreDraw(npc, spriteBatch, drawColor))
{
return false;
}
}
if (IsModNPC(npc))
{
return npc.modNPC.PreDraw(spriteBatch, drawColor);
}
return true;
}
//call this at end of Terraria.Main.DrawNPC
internal static void PostDraw(NPC npc, SpriteBatch spriteBatch, Color drawColor)
{
if (IsModNPC(npc))
{
npc.modNPC.PostDraw(spriteBatch, drawColor);
}
foreach (GlobalNPC globalNPC in globalNPCs)
{
globalNPC.PostDraw(npc, spriteBatch, drawColor);
}
}
}
}
Loading

0 comments on commit 483328d

Please sign in to comment.