#include "MW4Headers.hpp"
#include "hudcomp.hpp"
#include "hudhelp.hpp"
#include "objective.hpp"

using namespace MechWarrior4;

HUDHelp::HUDHelp()
{
	Location (Point3D (0.5f,0.29f,0.9f));
	Size (Point3D (0.32f,0.25f,0.9f));
	Color (25,25,25,250);
	
	m_Message = new HUDText ();
	m_Message->UpdateText ("");
	m_Message->Justification(HUDText::LEFT_ALIGN);
	m_Message->Color (255,255,255,255);
	m_FlashTime = 0;
}

HUDHelp::~HUDHelp()
{
	delete m_Message;
}

void HUDHelp::NewMessage (Objective *mesg)
{
	Check_Object (mesg);
	m_Message->UpdateText (mesg->CurrentText ());
	m_FlashCount = 0;
}

void HUDHelp::Update (Stuff::Time till)
{
	if (m_FlashTime == 0)
		m_FlashTime = till;

	while ((m_FlashTime <= till) && (m_FlashCount < 25))
	{
		m_Flash = !m_Flash;
		m_FlashTime += 1.0/6.0;
		m_FlashCount++;
	}

	inherited::Update (till);
}

void HUDHelp::Reset (void)
{
	m_Message->UpdateText ("");
}
void HUDHelp::DrawImplementation(void)
{
	Point3D loc,size;

	if (m_Message->Empty ())
		return;
	loc = Location ();
	size = Size ();
	if (m_FlashCount >= 25)
		m_Flash = true;
	
	DWORD x,y;
	m_Message->TopLeft (100,175);
	m_Message->BottomRight (700,500);
	m_Message->DrawSize (x,y);

	size.x = x+6.0f;
	size.y = y+6.0f;
	loc.x -= size.x / 2.0f;
	DrawRect (loc,size,Color ());
	if (m_Flash)
	{
		DrawFrame (loc,size,MakeColor (255,255,255,255));
	}

	loc.x += 3;
	size.x -= 6;
	m_Message->TopLeft (loc.x,loc.y);
	m_Message->BottomRight (loc.x+size.x,loc.y+size.y);
	m_Message->Draw (Point3D (loc.x,loc.y+2,0.9f));
}


