namespace Fungus
{
///
/// Fungus Priority event signalling system.
/// A common point for Fungus core systems and user Commands to signal to external code that a
/// Fungus system is currently doing something important.
///
/// One intended use case for this system is to have your code listen to this to know when to
/// stop player movement or camera movement etc. when the player is engaged in a conversation
/// with an NPC.
///
public static class FungusPrioritySignals
{
#region Public members
///
/// used by increase and decrease active depth functions.
///
private static int activeDepth;
public static int CurrentPriorityDepth
{
get
{
return activeDepth;
}
}
public static event FungusPriorityStartHandler OnFungusPriorityStart;
public delegate void FungusPriorityStartHandler();
public static event FungusPriorityEndHandler OnFungusPriorityEnd;
public delegate void FungusPriorityEndHandler();
public static event FungusPriorityChangeHandler OnFungusPriorityChange;
public delegate void FungusPriorityChangeHandler(int previousActiveDepth, int newActiveDepth);
///
/// Adds 1 to the theactiveDepth. If it was zero causes the OnFungusPriorityStart
///
public static void DoIncreasePriorityDepth()
{
if(activeDepth == 0)
{
if (OnFungusPriorityStart != null)
{
OnFungusPriorityStart();
}
}
if(OnFungusPriorityChange != null)
{
OnFungusPriorityChange(activeDepth, activeDepth + 1);
}
activeDepth++;
}
///
/// Subtracts 1 to the theactiveDepth. If it reaches zero causes the OnFungusPriorityEnd
///
public static void DoDecreasePriorityDepth()
{
if (OnFungusPriorityChange != null)
{
OnFungusPriorityChange(activeDepth, activeDepth - 1);
}
if(activeDepth == 1)
{
if(OnFungusPriorityEnd != null)
{
OnFungusPriorityEnd();
}
}
activeDepth--;
}
///
/// Forces active depth back to 0. If already 0 fires no signals.
///
public static void DoResetPriority()
{
if (activeDepth == 0)
return;
if (OnFungusPriorityChange != null)
{
OnFungusPriorityChange(activeDepth, 0);
}
if (OnFungusPriorityEnd != null)
{
OnFungusPriorityEnd();
}
activeDepth = 0;
}
#endregion
}
}