#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#include "vgui_TeamFortressViewport.h"

#define BAR_OFFSET640 4
#define BAR_OFFSET320 2
// Moved by Pcjoe
/*char *Forms[][10] = 
{	//base class
	{"normal",""},
	//buu
	{"fat","skinny","adult","kid",""},
	//goku
	{"saiyan","ssj","ssj2","ssj3",""},
	//gohan
	{"saiyan","ssj","ssj2",""},
	//krillin
	{"form1","form2",""},
	//frieza
	{"form1","form2",""},
	//piccolo
	{"form1","form2","form2",""},
	//trunks
	{"saiyan","ssj","ussj",""},
	//vegeta
	{"saiyan","ssj","ssj2",""},
	//cell
	{"form1","form2","form3",""},	
};*/
enum transformation
{	NORMAL,
	//saiyan
	SSJ,
	USSJ,
	SSJ2,
	SSJ3,
	//krillin
	MYSTIC,
	//piccolo
	//frieza
	FORM_2,
	FORM_3,
	//cell
	//buu
	FAT,
	ADULT,
	BUU,
	//
};

DECLARE_MESSAGE(m_Transform, Transform);

int CHudTransform::Init(void)
{	HOOK_MESSAGE(Transform);
	
	m_iMaxTransform = 1000000;

	gHUD.AddHudElem(this);
	m_iFlags |= HUD_ACTIVE;
	return 1;
}

int CHudTransform::VidInit(void)
{	m_HUD_mainbar = gHUD.GetSpriteIndex( "transformbar" );
	m_HUD_transformline = gHUD.GetSpriteIndex( "transformline" );
	m_HUD_cffront = gHUD.GetSpriteIndex("cffront");
	for (int i = 1;i<PC_RANDOM;i++)
	{	
	}
	return 1;
}

int CHudTransform::Draw(float fltime)
{	if (!(gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT)) ))
		return 1;

	if ( (gHUD.m_iHideHUDDisplay & ( HIDEHUD_WEAPONS | HIDEHUD_ALL )) )
		return 1;

	int r,g,b,x,y;
	UnpackRGB(r,g,b, RGB_WHITEISH);
	
	int iWidth = gHUD.GetSpriteRect(m_HUD_cffront).right - gHUD.GetSpriteRect(m_HUD_cffront).left;
	m_iWidth = iWidth;
	int iHeigth = gHUD.GetSpriteRect(m_HUD_cffront).bottom - gHUD.GetSpriteRect(m_HUD_cffront).top;
	
	//y = ScreenHeight - iHeigth * 3; //assume KiHeigth==HealthHeigth==PowerLevelHeigth
	y = ScreenHeight - iHeigth * 4; //assume KiHeigth==HealthHeigth==PowerLevelHeigth
	x = 0;

	SPR_Set(gHUD.GetSprite(m_HUD_cffront), r, g, b);
	SPR_Draw(0, x, y, &gHUD.GetSpriteRect(m_HUD_cffront));

	x += iWidth;	
	iWidth = gHUD.GetSpriteRect(m_HUD_mainbar).right - gHUD.GetSpriteRect(m_HUD_mainbar).left;
	m_iWidth += iWidth;
	
	SPR_Set(gHUD.GetSprite(m_HUD_mainbar), r, g, b);
	SPR_Draw(0, x, y, &gHUD.GetSpriteRect(m_HUD_mainbar));

	// draw line
	if (ScreenWidth<640)
	{	iWidth = iWidth - 2 * BAR_OFFSET320;
		x += BAR_OFFSET320;
	}
	else
	{	iWidth = iWidth - 2 * BAR_OFFSET640;
		x += BAR_OFFSET640;
	}
	
	float flFill = (float)gHUD.m_PowerLevel.m_iPowerLevel / (float)m_iMaxTransform;
	
	if (flFill>1)
	{	flFill = 1;
	}
	int iBarFill = iWidth * flFill;
	
	for (int i = 0;i<iBarFill;i++)
	{	SPR_Set(gHUD.GetSprite(m_HUD_transformline), r, g, b);
		SPR_DrawHoles(0, x + i, y, &gHUD.GetSpriteRect(m_HUD_transformline));
	}
	
	return 1;
}

int CHudTransform::MsgFunc_Transform(const char *pszName, int iSize, void *pbuf)
{	BEGIN_READ( pbuf, iSize );
	m_iTransformation = READ_BYTE();	
	m_iMaxTransform = READ_LONG();	
	return 1;
}