/*
*	Created:			17.01.10
*	Author:				009
*	Last Modifed:		-
*	Description:		Электронный спидометр
*						1 тип: есть спидометр и бензометр, в виде цифр
*						2 тип: есть спидометр и бензометр, в виде строки символов ( |||||| либо ______ )
*						3 тип: есть спидометр и бензометр и "турбо", в виде цифр
*						4 тип: есть спидометр и бензометр и "турбо", в виде строки символов ( |||||| либо ______ )
*/

#if defined _electro_included
  #endinput
#endif

#define _electro_included
#pragma library electro

// --------------------------------------------------
// includes
// --------------------------------------------------
#include "mode_property"

// --------------------------------------------------
// defines
// --------------------------------------------------


// --------------------------------------------------
// enums
// --------------------------------------------------
// тип 1, тип 2
enum E_SET1 {
	Float:sBackground[4],
	sBackgroundColor,
	Float:sSpeedoPos[2],
	sSpeedoColor,
	Float:sFuelPos[2],
	sFuelColor,
	sTextStyle
};
// тип 3, тип 4
enum E_SET2 {
	Float:sBackground[4],
	sBackgroundColor,
	Float:sSpeedoPos[2],
	sSpeedoColor,
	Float:sFuelPos[2],
	sFuelColor,
	Float:sTurboPos[2],
	sTurboColor,
	sTextStyle
};

// --------------------------------------------------
// news
// --------------------------------------------------
static SpeedoType1[][E_SET1] = {
	{{460.0,375.0,150.0,5.0},0xFFFF00AA,{160.0,380.0},0x33AAFFFF,{160.0,390.0},0x33AAFFFF,1},
	{{460.0,375.0,150.0,5.0},0xFFFF00AA,{160.0,380.0},0x33AAFFFF,{160.0,390.0},0x33AAFFFF,2}
};
static SpeedoType2[][E_SET1] = {
	{{460.0,375.0,150.0,5.0},0xFFFF00AA,{160.0,380.0},0x33AAFFFF,{160.0,390.0},0x33AAFFFF,'_'},
	{{460.0,375.0,150.0,5.0},0xFFFF00AA,{160.0,380.0},0x33AAFFFF,{160.0,390.0},0x33AAFFFF,'|'}
};
static SpeedoType3[][E_SET2] = {
	{{460.0,375.0,150.0,5.0},0xFFFF00AA,{160.0,380.0},0x33AAFFFF,{160.0,390.0},0x33AAFFFF,{160.0,400.0},0x33AAFFFF,1},
	{{460.0,375.0,150.0,5.0},0xFFFF00AA,{160.0,380.0},0x33AAFFFF,{160.0,390.0},0x33AAFFFF,{160.0,400.0},0x33AAFFFF,2}
};
static SpeedoType4[][E_SET2] = {
	{{460.0,375.0,150.0,5.0},0xFFFF00AA,{160.0,380.0},0x33AAFFFF,{160.0,390.0},0x33AAFFFF,{160.0,400.0},0x33AAFFFF,'_'},
	{{460.0,375.0,150.0,5.0},0xFFFF00AA,{160.0,380.0},0x33AAFFFF,{160.0,390.0},0x33AAFFFF,{160.0,400.0},0x33AAFFFF,'|'}
};

// --------------------------------------------------
// natives list (for pawno functions list)
// --------------------------------------------------
/*
native SpeedometerElectroLoad();
native SpeedometerElectroShow(playerid,type,speedoid);
native SpeedometerElectroHide(playerid,type,speedoid);
native SpeedometerElectroUpdate(playerid,type,speedoid,data[3]);
*/

// --------------------------------------------------
// stocks
// --------------------------------------------------
stock SpeedometerElectroLoad()
{
	new Text:tid;
	// Создание текстов 1 типа
	for(new speedoid = 0;speedoid < sizeof(SpeedoType1);speedoid++)
	{
		tid = TextDrawCreate(SpeedoType1[speedoid][sBackground][0],SpeedoType1[speedoid][sBackground][1],"_");
		TextDrawUseBox(tid,1);
		TextDrawTextSize(tid,SpeedoType1[speedoid][sBackground][2],0.0);
		TextDrawLetterSize(tid,0.0,SpeedoType1[speedoid][sBackground][3]);
		TextDrawBoxColor(tid,SpeedoType1[speedoid][sBackgroundColor]);
		SetModePropertyInt("SET1","BG",speedoid,0,int:tid);
	}
	// Создание текстов 2 типа
	for(new speedoid = 0;speedoid < sizeof(SpeedoType2);speedoid++)
	{
		tid = TextDrawCreate(SpeedoType2[speedoid][sBackground][0],SpeedoType2[speedoid][sBackground][1],"_");
		TextDrawUseBox(tid,1);
		TextDrawTextSize(tid,SpeedoType2[speedoid][sBackground][2],0.0);
		TextDrawLetterSize(tid,0.0,SpeedoType2[speedoid][sBackground][3]);
		TextDrawBoxColor(tid,SpeedoType2[speedoid][sBackgroundColor]);
		SetModePropertyInt("SET2","BG",speedoid,0,int:tid);
	}
	// Создание текстов 3 типа
	for(new speedoid = 0;speedoid < sizeof(SpeedoType3);speedoid++)
	{
		tid = TextDrawCreate(SpeedoType3[speedoid][sBackground][0],SpeedoType3[speedoid][sBackground][1],"_");
		TextDrawUseBox(tid,1);
		TextDrawTextSize(tid,SpeedoType3[speedoid][sBackground][2],0.0);
		TextDrawLetterSize(tid,0.0,SpeedoType3[speedoid][sBackground][3]);
		TextDrawBoxColor(tid,SpeedoType3[speedoid][sBackgroundColor]);
		SetModePropertyInt("SET3","BG",speedoid,0,int:tid);
	}
	// Создание текстов 4 типа
	for(new speedoid = 0;speedoid < sizeof(SpeedoType4);speedoid++)
	{
		tid = TextDrawCreate(SpeedoType4[speedoid][sBackground][0],SpeedoType4[speedoid][sBackground][1],"_");
		TextDrawUseBox(tid,1);
		TextDrawTextSize(tid,SpeedoType4[speedoid][sBackground][2],0.0);
		TextDrawLetterSize(tid,0.0,SpeedoType4[speedoid][sBackground][3]);
		TextDrawBoxColor(tid,SpeedoType4[speedoid][sBackgroundColor]);
		SetModePropertyInt("SET4","BG",speedoid,0,int:tid);
	}
}

stock SpeedometerElectroShow(playerid,type,speedoid)
{
	switch(type)
	{
		case 0: TextDrawShowForPlayer(playerid,Text:GetModePropertyInt("SET1","BG",speedoid,0));
		case 1: TextDrawShowForPlayer(playerid,Text:GetModePropertyInt("SET2","BG",speedoid,0));
		case 2: TextDrawShowForPlayer(playerid,Text:GetModePropertyInt("SET3","BG",speedoid,0));
		case 3: TextDrawShowForPlayer(playerid,Text:GetModePropertyInt("SET4","BG",speedoid,0));
	}
}

stock SpeedometerElectroHide(playerid,type,speedoid)
{
	if(ExistModeProperty("SE","PIS",playerid,1)) {TextDrawDestroy(Text:GetModePropertyInt("SE","PIS",playerid,1));DeleteModeProperty("SE","PIS",playerid,1);}
	if(ExistModeProperty("SE","PIS",playerid,0)) DeleteModeProperty("SE","PIS",playerid,0);
	if(ExistModeProperty("SE","PIF",playerid,1)) {TextDrawDestroy(Text:GetModePropertyInt("SE","PIF",playerid,1));DeleteModeProperty("SE","PIF",playerid,1);}
	if(ExistModeProperty("SE","PIF",playerid,0)) DeleteModeProperty("SE","PIF",playerid,0);
	if(ExistModeProperty("SE","PIT",playerid,1)) {TextDrawDestroy(Text:GetModePropertyInt("SE","PIT",playerid,1));DeleteModeProperty("SE","PIT",playerid,1);}
	if(ExistModeProperty("SE","PIT",playerid,0)) DeleteModeProperty("SE","PIT",playerid,0);
	switch(type)
	{
		case 0: TextDrawHideForPlayer(playerid,Text:GetModePropertyInt("SET1","BG",speedoid,0));
		case 1: TextDrawHideForPlayer(playerid,Text:GetModePropertyInt("SET2","BG",speedoid,0));
		case 2: TextDrawHideForPlayer(playerid,Text:GetModePropertyInt("SET3","BG",speedoid,0));
		case 3: TextDrawHideForPlayer(playerid,Text:GetModePropertyInt("SET4","BG",speedoid,0));
	}
}

stock SpeedometerElectroUpdate(playerid,type,speedoid,data[3])
{
	switch(type)
	{
		case 0:
		{
			ShowIdentSpeed(playerid,0,SpeedoType1[speedoid][sSpeedoPos][0],SpeedoType1[speedoid][sSpeedoPos][1],SpeedoType1[speedoid][sSpeedoColor],SpeedoType1[speedoid][sTextStyle],data[0]);
			ShowIdentFuel(playerid,0,SpeedoType1[speedoid][sFuelPos][0],SpeedoType1[speedoid][sFuelPos][1],SpeedoType1[speedoid][sFuelColor],SpeedoType1[speedoid][sTextStyle],data[1]);
		}
		case 1:
		{
			ShowIdentSpeed(playerid,1,SpeedoType2[speedoid][sSpeedoPos][0],SpeedoType2[speedoid][sSpeedoPos][1],SpeedoType2[speedoid][sSpeedoColor],SpeedoType2[speedoid][sTextStyle],data[0]);
			ShowIdentFuel(playerid,1,SpeedoType2[speedoid][sFuelPos][0],SpeedoType2[speedoid][sFuelPos][1],SpeedoType2[speedoid][sFuelColor],SpeedoType2[speedoid][sTextStyle],data[1]);
		}
		case 2:
		{
			ShowIdentSpeed(playerid,0,SpeedoType3[speedoid][sSpeedoPos][0],SpeedoType3[speedoid][sSpeedoPos][1],SpeedoType3[speedoid][sSpeedoColor],SpeedoType3[speedoid][sTextStyle],data[0]);
			ShowIdentFuel(playerid,0,SpeedoType3[speedoid][sFuelPos][0],SpeedoType3[speedoid][sFuelPos][1],SpeedoType3[speedoid][sFuelColor],SpeedoType3[speedoid][sTextStyle],data[1]);
			ShowIdentTurbo(playerid,0,SpeedoType3[speedoid][sTurboPos][0],SpeedoType3[speedoid][sTurboPos][1],SpeedoType3[speedoid][sTurboColor],SpeedoType3[speedoid][sTextStyle],data[2]);
		
		}
		case 3:
		{
			ShowIdentSpeed(playerid,1,SpeedoType4[speedoid][sSpeedoPos][0],SpeedoType4[speedoid][sSpeedoPos][1],SpeedoType4[speedoid][sSpeedoColor],SpeedoType4[speedoid][sTextStyle],data[0]);
			ShowIdentFuel(playerid,1,SpeedoType4[speedoid][sFuelPos][0],SpeedoType4[speedoid][sFuelPos][1],SpeedoType4[speedoid][sFuelColor],SpeedoType4[speedoid][sTextStyle],data[1]);
			ShowIdentTurbo(playerid,1,SpeedoType4[speedoid][sTurboPos][0],SpeedoType4[speedoid][sTurboPos][1],SpeedoType4[speedoid][sTurboColor],SpeedoType4[speedoid][sTextStyle],data[2]);
		}
	}
}

// --------------------------------------------------
// local utils
// --------------------------------------------------
static ShowIdentSpeed(playerid,type,Float:X,Float:Y,color,style,data)
{
	if((!ExistModeProperty("SE","PIS",playerid,0)) || (GetModePropertyInt("SE","PIS",playerid,0) != data))
	{
		new val[40],
			Text:tid;
		switch(type)
		{
			case 0: valstr(val,data);
			case 1: {for(new i = 0;i < (data / 10);i++) format(val,sizeof(val),"%s%c",val,style);}
		}
		if(ExistModeProperty("SE","PIS",playerid,1))
		{
			TextDrawDestroy(Text:GetModePropertyInt("SE","PIS",playerid,1));
			DeleteModeProperty("SE","PIS",playerid,1);
		}
		tid = TextDrawCreate(X,Y,val);
		TextDrawSetShadow(tid , 0);
		TextDrawSetOutline(tid , 1);
		TextDrawColor(tid , color);
		TextDrawFont(tid, style);
		TextDrawShowForPlayer(playerid,tid);
		SetModePropertyInt("SE","PIS",playerid,1,int:tid);
		if(ExistModeProperty("SE","PIS",playerid,0)) DeleteModeProperty("SE","PIS",playerid,0);
		SetModePropertyInt("SE","PIS",playerid,0,data);
	}
}

static ShowIdentFuel(playerid,type,Float:X,Float:Y,color,style,data)
{
	if((!ExistModeProperty("SE","PIF",playerid,0)) || (GetModePropertyInt("SE","PIF",playerid,0) != data))
	{
		new val[40],
			Text:tid;
		switch(type)
		{
			case 0: valstr(val,(data * 10));
			case 1: {for(new i = 0;i < data;i++) format(val,sizeof(val),"%s%c",val,style);}
		}
		if(ExistModeProperty("SE","PIF",playerid,1))
		{
			TextDrawDestroy(Text:GetModePropertyInt("SE","PIF",playerid,1));
			DeleteModeProperty("SE","PIF",playerid,1);
		}
		tid = TextDrawCreate(X,Y,val);
		TextDrawSetShadow(tid , 0);
		TextDrawSetOutline(tid , 1);
		TextDrawColor(tid , color);
		TextDrawFont(tid, style);
		TextDrawShowForPlayer(playerid,tid);
		SetModePropertyInt("SE","PIF",playerid,1,int:tid);
		if(ExistModeProperty("SE","PIF",playerid,0)) DeleteModeProperty("SE","PIF",playerid,0);
		SetModePropertyInt("SE","PIF",playerid,0,data);
	}
}

static ShowIdentTurbo(playerid,type,Float:X,Float:Y,color,style,data)
{
	if((!ExistModeProperty("SE","PIT",playerid,0)) || (GetModePropertyInt("SE","PIT",playerid,0) != data))
	{
		new val[40],
			Text:tid;
		switch(type)
		{
			case 0: valstr(val,(data * 10));
			case 1: {for(new i = 0;i < data;i++) format(val,sizeof(val),"%s%c",val,style);}
		}
		if(ExistModeProperty("SE","PIT",playerid,1))
		{
			TextDrawDestroy(Text:GetModePropertyInt("SE","PIT",playerid,1));
			DeleteModeProperty("SE","PIT",playerid,1);
		}
		tid = TextDrawCreate(X,Y,val);
		TextDrawSetShadow(tid , 0);
		TextDrawSetOutline(tid , 1);
		TextDrawColor(tid , color);
		TextDrawFont(tid, style);
		TextDrawShowForPlayer(playerid,tid);
		SetModePropertyInt("SE","PIT",playerid,1,int:tid);
		if(ExistModeProperty("SE","PIT",playerid,0)) DeleteModeProperty("SE","PIT",playerid,0);
		SetModePropertyInt("SE","PIT",playerid,0,data);
	}
}