#include "Dvar.h"
struct hudelem_color_t{
	byte r;
	byte g;
	byte b;
	byte a;
};
struct hudelem_s{
	int type;
	float y;
	float x;
	float z;
	int targetEntNum;
	float fontScale;
	float fromFontScale;
	int fontScaleStartTime;
	int fontScaleTime;
	int label;
	int font;
	int alignOrg;
	int alignScreen;
	hudelem_color_t color;
	hudelem_color_t fromColor;
	int fadeStartTime;
	int fadeTime;
	int height;
	int width;
	int materialIndex;
	int fromHeight;
	int fromWidth;
	int scaleStartTime;
	int scaleTime;
	float fromY;
	float fromX;
	int fromAlignOrg;
	int fromAlignScreen;
	int moveStartTime;
	int moveTime;
	float value;
	int time;
	int duration;
	int text;
	float sort;
	hudelem_color_t glowColor;
	int fxBirthTime;
	int fxLetterTime;
	int fxDecayStartTime;
	int fxDecayDuration;
	int soundID;
	int flags;
};
typedef enum{
	y = 0x04,
	x = 0x08,
	UP = 0x5820,
	DOWN = 0x5821,
	LEFT = 0x5822,
	RIGHT = 0x5823,
	fontScale = 0x14,
	font = 0x28,
	alignOrg = 0x2C,
	alignScreen = 0x30,
	colour = 0x34,
	height = 0x44,
	width = 0x48,
	materialIndex = 0x4C,
	text = 0x84,
	sort = 0x88,
	glow = 0x8C,
} hudelements_t;
struct game_hudelem_s{
	hudelem_s elem;
	int clientNum;
	int teamNum;
	int archived;
};
void (_cdecl* Free)(game_hudelem_s* hud) = (void(*)(game_hudelem_s*))0x821DFA58;
void (_cdecl* Scr_FreeHudElem)(game_hudelem_s* hud) = (void(*)(game_hudelem_s*))0x82209680;
game_hudelem_s* (_cdecl* Alloc)(int ClientNum, int TeamNum) = (game_hudelem_s*(*)(int, int))0x821DF9C0;
int (_cdecl *G_LocalizedStringIndex)(const char* String) = (int(*)(const char*))0x8220C838;
int (_cdecl *G_MaterialIndex)(const char* name) = (int(*)(const char*))0x8220C9F8;

void HudElem_Free(game_hudelem_s *Hud){
	Free(Hud);
	Hud->elem.type = 0;
}
int LevelTime(){
	return *(int*)0x8310A12C;
}
void ChangeFontScaleOverTime(game_hudelem_s *elem, int Time, float Scale){
	elem->elem.fromFontScale = elem->elem.fontScale;
	elem->elem.fontScaleStartTime = LevelTime();
	elem->elem.fontScaleTime = Time;
	elem->elem.fontScale = Scale;
}
game_hudelem_s *spawnElem(int clientNum){
	game_hudelem_s * elem = Alloc(0,0);
	elem->clientNum = clientNum;
	elem->elem.targetEntNum = clientNum;
	return elem;
}
game_hudelem_s* spawnElemAll(){
	return spawnElem(0x7FF);
}

game_hudelem_s *DoHeart, *Text[6];

void setText(game_hudelem_s *elem, const char* Text, int font, float fontScale, float x, float y, int alignOrg, int alignScreen, float sort = 1, byte r = 255, byte g = 255, byte b = 255, byte a = 255){
	elem->elem.type = 0x1;
	elem->elem.alignOrg = alignOrg;
	elem->elem.alignScreen = alignScreen;
	elem->elem.font = font;
	elem->elem.fontScale = fontScale;
	elem->elem.x = x;
	elem->elem.y = y;
	elem->elem.color.r = r;
	elem->elem.color.g = g;
	elem->elem.color.b = b;
	elem->elem.color.a = a;
	elem->elem.sort = sort;
	elem->elem.text = G_LocalizedStringIndex(Text);
}
void setShader(game_hudelem_s *elem, const char* Shader, float x, float y, int width, int height, int alignOrg, int alignScreen, float sort = 0, byte r = 255, byte g = 255, byte b = 255, byte a = 255){
	elem->elem.type = 0x4;
	elem->elem.alignOrg = alignOrg;
	elem->elem.alignScreen = alignScreen;
	elem->elem.x = x;elem->elem.y = y;
	elem->elem.color.r = r;
	elem->elem.color.g = g;
	elem->elem.color.b = b;
	elem->elem.color.a = a;
	elem->elem.width = width;
	elem->elem.height = height;
	elem->elem.sort = sort;
	elem->elem.materialIndex = G_MaterialIndex(Shader);
}
void ScaleOverTime(game_hudelem_s *elem, int time, float width, float height){
	elem->elem.fromHeight = elem->elem.height;
	elem->elem.fromWidth = elem->elem.width;
	elem->elem.scaleStartTime = LevelTime();
	elem->elem.scaleTime = time;
	elem->elem.height = height;
	elem->elem.width = width;
}
void MoveOverTime(game_hudelem_s *elem, int time, float x, float y){
	elem->elem.fromX = elem->elem.x;
	elem->elem.fromY = elem->elem.y;
	elem->elem.fromAlignOrg = elem->elem.alignOrg;
	elem->elem.fromAlignScreen = elem->elem.alignScreen;
	elem->elem.moveStartTime = LevelTime();
	elem->elem.moveTime = time;
	elem->elem.x = x;
	elem->elem.y = y;
}
void scaleOverTime(game_hudelem_s *elem, float fromSize, float toSize, int scaleTime){
	elem->elem.fontScaleStartTime = LevelTime();
	elem->elem.fontScaleTime = scaleTime; 
	elem->elem.fromFontScale = fromSize;
	elem->elem.fontScale = toSize;
}
void FadeOverTime(game_hudelem_s *elem, int time, byte red, byte green, byte blue, byte alpha){
	elem->elem.fromColor = elem->elem.color;
	elem->elem.fadeStartTime = LevelTime();
	elem->elem.fadeTime = time;
	elem->elem.color.r = red;
	elem->elem.color.g = green;
	elem->elem.color.b = blue;
	elem->elem.color.a = alpha;
}