class UIUVTesterWnd extends UICommonAPI;

var WindowHandle SteerTexBody;
var TextureHandle texture0;
var TextureHandle Texture1;
var TextureHandle SteerTex;
var TextureHandle MainBG_texAni00;
var TextureHandle SteerTexInner;
var TextBoxHandle secText;
var EditBoxHandle speedText;
var L2UITimerObject tObject;
var float nU;
var float nV;
var INT64 lastAppMilliSeconds;
var float Time;
var float Speed;

event OnRegisterEvent()
{
	RegisterEvent(EV_GamingStateEnter);	
}

event OnLoad()
{
	SetClosingOnESC();
	texture0 = GetTextureHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".texture0");
	Texture1 = GetTextureHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".texture1");
	SteerTex = GetTextureHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".SteerTex");
	SteerTexBody = GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".SteerTexBody");
	SteerTexInner = GetTextureHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".SteerTexBody.SteerTex");
	MainBG_texAni00 = GetTextureHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".MainBG_texAni00");
	secText = GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".secText");
	speedText = GetEditBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".speedText");
	SetTextureStartSetting();	
}

event OnClickButton(string btnName)
{
	switch(btnName)
	{
		case "ResetButton":
			nU = 0.0f;
			nV = 0.0f;
			Time = 0.0f;
			break;
	}	
}

event OnChangeEditBox(string strID)
{
	Speed = float(speedText.GetString());	
}

private function SetTextureStartSetting();

private function HandleOnTick()
{
	local float DeltaTime, deltaSpeed;

	DeltaTime = float(GetDeltaMilliTime()) / 1000;
	lastAppMilliSeconds = GetAppMilliSeconds();
	Time += DeltaTime;
	secText.SetText(string(Time));
	deltaSpeed = DeltaTime * Speed;
	nU = nU + deltaSpeed;
	texture0.SetUV(int(nU), int(nV));
	Texture1.SetUV(int(nU), int(nV));
	texture0.SetRotationAngle(nU);
	MainBG_texAni00.SetUV(int(nU / 4), int(nV));	
}

event OnShow()
{
	tObject._Play();
	lastAppMilliSeconds = GetAppMilliSeconds();
	m_hOwnerWnd.EnableTick();	
}

event OnHide()
{
	tObject._Stop();
	m_hOwnerWnd.DisableTick();	
}

event OnTick()
{
	HandleOnTick();	
}

event OnMouseMove(WindowHandle wHandle, int X, int Y)
{
	HandleSteerTex(X, Y);
	HandleSteerTexBody(X, Y);	
}

private function HandleSteerTex(int X, int Y)
{
	local Rect rectWnd;
	local int mX, mY;
	local float ang;

	rectWnd = SteerTex.GetRect();
	mX = (X - rectWnd.nX) - (rectWnd.nWidth / 2);
	mY = (Y - rectWnd.nY) - (rectWnd.nHeight / 2);
	ang = (Atan(float(mX), float(- mY)) * 180) / 3.1415930f;
	SteerTex.SetRotationAngle(ang);	
}

private function HandleSteerTexBody(int X, int Y)
{
	local Rect rectWnd;
	local int mX, mY;
	local float ang;

	rectWnd = SteerTexInner.GetRect();
	mX = (X - rectWnd.nX) - (rectWnd.nWidth / 2);
	mY = (Y - rectWnd.nY) - (rectWnd.nHeight / 2);
	ang = (Atan(float(mX), float(- mY)) * 180) / 3.1415930f;
	SteerTexBody.SetRotationAngle(ang);
	SteerTexInner.SetRotationAngle(ang);	
}

private function INT64 GetDeltaMilliTime()
{
	return (GetAppMilliSeconds()) - lastAppMilliSeconds;	
}

private function API_GetClientCursorPos(out int X, out int Y)
{
	GetClientCursorPos(X, Y);	
}

function OnReceivedCloseUI()
{
	PlayConsoleSound(IFST_WINDOW_CLOSE);
	m_hOwnerWnd.HideWindow();	
}
