-------------------------------------------------------------------------------
--
--  Mod Name : BlinkRogueHelper 2.1
--  Author   : Blink
--  Date     : 2004/10/11
--  LastUpdate : 2007/02/06
--
-------------------------------------------------------------------------------

BRH_ComboSkill = 40;

BRH_FinishSkill = 35;

BlinkRogueHelper_FontSizePixel = 70;


function BlinkRogueHelperFrame_OnLoad()
	this:RegisterEvent("PLAYER_COMBO_POINTS");
	this:RegisterEvent("UNIT_ENERGY");
	this:RegisterEvent("VARIABLES_LOADED");

	this.fadeInTime = 0.2;		-- 숫자가 화면에 나타나는 시간(초)
	this.holdTime = 1.0;		-- 숫자가 화면에서 유지되는 시간(초)
	this.fadeOutTime = 0.8;		-- 숫자가 화면에서 사라지는 시간(초)
	this.flowTime = this.fadeInTime + this.holdTime + this.fadeOutTime;
	this.PI = 3.141592;

	this:Hide();

	BubbleTextString:SetTextHeight(BlinkRogueHelper_FontSizePixel);
end

function BlinkRogueHelperFrame_OnEvent(event)
	if ( event == "VARIABLES_LOADED" ) then
		if ( not BlinkRogueHelper_Enabled ) then
			BlinkRogueHelper_Enabled = 1;
		end
		if ( not BlinkRogueHelper_Type ) then
			BlinkRogueHelper_Type = 1;
		end
		BlinkRogueHelper_Register();
		BlinkRogueHelper_BM_Register();
		this:UnregisterEvent("VARIABLES_LOADED");
	end
	if ( event == "UNIT_ENERGY" ) then
		if ( arg1 == "player" and this:IsVisible() ) then
			SetBubbleTextColor();
		end
	elseif ( event == "PLAYER_COMBO_POINTS" and BlinkRogueHelper_Enabled == 1 ) then
		if( GetComboPoints()>0 )then
			SetBubbleText();
			BlinkRogueHelper_Show();
		else
			this:Hide();
		end
	end
end

function BlinkRogueHelper_OnUpdate()
	if ( BlinkRogueHelper_Enabled == 1 ) then
		if( BlinkRogueHelper_Type == 2 ) then
			BlinkRogueHelper_Type2();
		elseif( BlinkRogueHelper_Type == 3 ) then
			BlinkRogueHelper_Type3();
		elseif( BlinkRogueHelper_Type == 4 ) then
			BlinkRogueHelper_Type4();
		else
			BlinkRogueHelper_Type1();
		end
	end
end

function BlinkRogueHelper_Type1()
	local elapsed = GetTime() - this.startTime;

	local fadeInTime = this.fadeInTime;
	if ( elapsed < fadeInTime ) then
		local alpha = (elapsed / fadeInTime);
		this:SetAlpha(alpha);
		BubbleTextString:SetTextHeight(BlinkRogueHelper_FontSizePixel * alpha + 1);
		this:SetPoint("CENTER", "UIParent", "CENTER", 0, BlinkRogueHelper_FontSizePixel*alpha );
		return;
	end
	local holdTime = this.holdTime;
	if ( elapsed < (fadeInTime + holdTime) ) then
		this:SetAlpha(1.0);
		BubbleTextString:SetTextHeight(BlinkRogueHelper_FontSizePixel + 1);
		this:SetPoint("CENTER", "UIParent", "CENTER", 0, BlinkRogueHelper_FontSizePixel );
		return;
	end
	local fadeOutTime = this.fadeOutTime;
	if ( elapsed < (fadeInTime + holdTime + fadeOutTime) ) then
		local alpha = 1.0 - ((elapsed - holdTime - fadeInTime) / fadeOutTime);
		this:SetAlpha(alpha);
		BubbleTextString:SetTextHeight(BlinkRogueHelper_FontSizePixel * alpha + 1);
		this:SetPoint("CENTER", "UIParent", "CENTER", 0, BlinkRogueHelper_FontSizePixel*alpha );
		return;
	end
	this:Hide();
end

function BlinkRogueHelper_Type2()
	local elapsed = GetTime() - this.startTime;
	local flowTime = elapsed / this.flowTime;
	this:SetPoint("CENTER", "UIParent", "CENTER", 0, (BlinkRogueHelper_FontSizePixel*10)*flowTime-50 );

	local fadeInTime = this.fadeInTime;
	if ( elapsed < fadeInTime ) then
		local alpha = (elapsed / fadeInTime);
		this:SetAlpha(alpha);
		return;
	end
	local holdTime = this.holdTime;
	if ( elapsed < (fadeInTime + holdTime) ) then
		this:SetAlpha(1.0);
		return;
	end
	local fadeOutTime = this.fadeOutTime;
	if ( elapsed < (fadeInTime + holdTime + fadeOutTime) ) then
		local alpha = 1.0 - ((elapsed - holdTime - fadeInTime) / fadeOutTime);
		this:SetAlpha(alpha);
		return;
	end
	this:Hide();
end

function BlinkRogueHelper_Type3()
	local elapsed = GetTime() - this.startTime;
	local flowTime = elapsed / this.flowTime;
	local xpos = math.sin(this.PI*2*flowTime) * 40;

	this:SetPoint("CENTER", "UIParent", "CENTER", xpos, (BlinkRogueHelper_FontSizePixel*4)*flowTime-60 );

	local fadeInTime = this.fadeInTime;
	if ( elapsed < fadeInTime ) then
		local alpha = (elapsed / fadeInTime);
		this:SetAlpha(alpha);
		return;
	end
	local holdTime = this.holdTime;
	if ( elapsed < (fadeInTime + holdTime) ) then
		this:SetAlpha(1.0);
		return;
	end
	local fadeOutTime = this.fadeOutTime;
	if ( elapsed < (fadeInTime + holdTime + fadeOutTime) ) then
		local alpha = 1.0 - ((elapsed - holdTime - fadeInTime) / fadeOutTime);
		this:SetAlpha(alpha);
		return;
	end
	this:Hide();
end

function BlinkRogueHelper_Type4()
	local elapsed = GetTime() - this.startTime;
	local flowTime = elapsed / this.flowTime;
	local xpos = math.sin(this.PI*2*flowTime) * 40;

	this:SetPoint("CENTER", "UIParent", "CENTER", (BlinkRogueHelper_FontSizePixel*4)*flowTime-(BlinkRogueHelper_FontSizePixel*2), 60 );

	local fadeInTime = this.fadeInTime;
	if ( elapsed < fadeInTime ) then
		local alpha = (elapsed / fadeInTime);
		this:SetAlpha(alpha);
		return;
	end
	local holdTime = this.holdTime;
	if ( elapsed < (fadeInTime + holdTime) ) then
		this:SetAlpha(1.0);
		return;
	end
	local fadeOutTime = this.fadeOutTime;
	if ( elapsed < (fadeInTime + holdTime + fadeOutTime) ) then
		local alpha = 1.0 - ((elapsed - holdTime - fadeInTime) / fadeOutTime);
		this:SetAlpha(alpha);
		return;
	end
	this:Hide();
end

function SetBubbleTextColor()
	local mana = UnitMana("player");
	local r,g,b;

	if( mana >= BRH_ComboSkill )then
		r = 0.1;
		g = 1.0;
		b = 0.1; -- 녹색
	elseif( mana >= BRH_FinishSkill )then
		r = 0.0;
		g = 0.39;
		b = 0.88; -- 파란색
	else
		r = 1.0;
		g = 0.1;
		b = 0.1; -- 빨간색
	end

	BubbleTextString:SetTextColor(r, g, b);
end

function SetBubbleText()
	local combo = GetComboPoints();
	BubbleTextString:SetText(combo);
	SetBubbleTextColor();
end

function BlinkRogueHelper_Show()
	this.startTime = GetTime();
	this:Show();
end

function BlinkRogueHelper_Register()
	SlashCmdList["BLINKROGUEHELPERSLASHENABLE"] = BlinkRogueHelper_Toggle;
	SLASH_BLINKROGUEHELPERSLASHENABLE1 = "/도적도우미";
	SLASH_BLINKROGUEHELPERSLASHENABLE2 = "/blinkroguehelper";
	SLASH_BLINKROGUEHELPERSLASHENABLE3 = "/brh";

	SlashCmdList["BLINKROGUEHELPERSELECT1"] = BlinkRogueHelper_SelectType1;
	SLASH_BLINKROGUEHELPERSELECT11 = "/도적도우미1";
	SLASH_BLINKROGUEHELPERSELECT12 = "/blinkroguehelper1";
	SLASH_BLINKROGUEHELPERSELECT13 = "/brh1";

	SlashCmdList["BLINKROGUEHELPERSELECT2"] = BlinkRogueHelper_SelectType2;
	SLASH_BLINKROGUEHELPERSELECT21 = "/도적도우미2";
	SLASH_BLINKROGUEHELPERSELECT22 = "/blinkroguehelper2";
	SLASH_BLINKROGUEHELPERSELECT23 = "/brh2";

	SlashCmdList["BLINKROGUEHELPERSELECT3"] = BlinkRogueHelper_SelectType3;
	SLASH_BLINKROGUEHELPERSELECT31 = "/도적도우미3";
	SLASH_BLINKROGUEHELPERSELECT32 = "/blinkroguehelper3";
	SLASH_BLINKROGUEHELPERSELECT33 = "/brh3";

	SlashCmdList["BLINKROGUEHELPERSELECT4"] = BlinkRogueHelper_SelectType4;
	SLASH_BLINKROGUEHELPERSELECT41 = "/도적도우미4";
	SLASH_BLINKROGUEHELPERSELECT42 = "/blinkroguehelper4";
	SLASH_BLINKROGUEHELPERSELECT43 = "/brh4";

end

function BlinkRogueHelper_BM_Register()
	if ( not BlinkMod_RegisterMenu ) then
		return;
	end
	local info;

	-- tier 1
	info = {};
	info.parentkey = "SELF";
	info.key = "BRHROOT";
	info.text = "도적 도우미";
	info.hasArrow = 1;
	info.tooltipTitle = "도적 도우미";
	info.tooltipText = "도적과 표범(드루이드)의 연계포인트를 표시해줍니다.";
	info.notCheckable = 1;
	BlinkMod_RegisterMenu( info, 1 );

		-- tier 2 : parent = BRHROOT
		info = {};
		info.parentkey = "BRHROOT";
		info.key = "BRHTITLE";
		info.text = "도적 도우미";
		info.isTitle = 1;
		info.notCheckable = 1;
		BlinkMod_RegisterMenu( info, 2 );

		info = {};
		info.parentkey = "BRHROOT";
		info.key = "BRHENABLE";
		info.text = "도적 도우미 사용";
		info.tooltipTitle = "도적 도우미 사용/사용안함";
		info.tooltipText = "도적 도우미를 사용할지 안할지 결정합니다.";
		info.ClickFunction = BRH_BM_EnableClick;
		info.CheckFunction = BRH_BM_EnableCheck;
		BlinkMod_RegisterMenu( info, 2 );

		info = {};
		info.parentkey = "BRHROOT";
		info.key = "BRHTYPE1";
		info.text = "움직임 타입1";
		info.tooltipTitle = "움직임 타입1";
		info.tooltipText = "연계포인트 숫자의 움직임 타입1";
		info.ClickFunction = BRH_BM_Type1Click;
		info.CheckFunction = BRH_BM_Type1Check;
		BlinkMod_RegisterMenu( info, 2 );

		info = {};
		info.parentkey = "BRHROOT";
		info.key = "BRHTYPE2";
		info.text = "움직임 타입2";
		info.tooltipTitle = "움직임 타입2";
		info.tooltipText = "연계포인트 숫자의 움직임 타입2";
		info.ClickFunction = BRH_BM_Type2Click;
		info.CheckFunction = BRH_BM_Type2Check;
		BlinkMod_RegisterMenu( info, 2 );

		info = {};
		info.parentkey = "BRHROOT";
		info.key = "BRHTYPE3";
		info.text = "움직임 타입3";
		info.tooltipTitle = "움직임 타입3";
		info.tooltipText = "연계포인트 숫자의 움직임 타입3";
		info.ClickFunction = BRH_BM_Type3Click;
		info.CheckFunction = BRH_BM_Type3Check;
		BlinkMod_RegisterMenu( info, 2 );

		info = {};
		info.parentkey = "BRHROOT";
		info.key = "BRHTYPE4";
		info.text = "움직임 타입4";
		info.tooltipTitle = "움직임 타입4";
		info.tooltipText = "연계포인트 숫자의 움직임 타입4";
		info.ClickFunction = BRH_BM_Type4Click;
		info.CheckFunction = BRH_BM_Type4Check;
		BlinkMod_RegisterMenu( info, 2 );

end

function BlinkRogueHelper_Toggle()
	if( not BlinkRogueHelper_Enabled or BlinkRogueHelper_Enabled ~= 1 ) then
		BlinkRogueHelper_Enabled = 1;
		ChatFrame1:AddMessage("도적 연계포인트 도우미를 활성화 합니다.");
	else
		BlinkRogueHelper_Enabled = 0;
		ChatFrame1:AddMessage("도적 연계포인트 도우미를 비활성화 합니다.");
	end
end

function BlinkRogueHelper_SelectType1() BlinkRogueHelper_Type = 1; end
function BlinkRogueHelper_SelectType2()
	BlinkRogueHelper_Type = 2;
	BlinkRogueHelper_FontSizePixel=70;
	BubbleTextString:SetTextHeight(BlinkRogueHelper_FontSizePixel);
end
function BlinkRogueHelper_SelectType3()
	BlinkRogueHelper_Type = 3;
	BlinkRogueHelper_FontSizePixel=70;
	BubbleTextString:SetTextHeight(BlinkRogueHelper_FontSizePixel);
end
function BlinkRogueHelper_SelectType4()
	BlinkRogueHelper_Type = 4;
	BlinkRogueHelper_FontSizePixel=70;
	BubbleTextString:SetTextHeight(BlinkRogueHelper_FontSizePixel);
end

-------------------------------------------------------------------------------
function BRH_BM_EnableClick()
	BlinkRogueHelper_Toggle();
end
function BRH_BM_EnableCheck()
	if( not BlinkRogueHelper_Enabled or BlinkRogueHelper_Enabled ~= 1 ) then
		BlinkRogueHelper_Enabled = 0;
		return false;
	else
		return true;
	end
end

function BRH_BM_TypeClick(t)
	if ( t == 2 ) then
		BlinkRogueHelper_SelectType2();
	elseif ( t == 3 ) then
		BlinkRogueHelper_SelectType3();
	elseif ( t == 4 ) then
		BlinkRogueHelper_SelectType4();
	else
		BlinkRogueHelper_SelectType1();
	end
end
function BRH_BM_TypeCheck(t)
	if ( not BlinkRogueHelper_Type ) then
		BlinkRogueHelper_Type = 1;
	end
	if ( tonumber(BlinkRogueHelper_Type) == tonumber(t) ) then
		return true;
	end
end

function BRH_BM_Type1Click() BRH_BM_TypeClick(1); end
function BRH_BM_Type2Click() BRH_BM_TypeClick(2); end
function BRH_BM_Type3Click() BRH_BM_TypeClick(3); end
function BRH_BM_Type4Click() BRH_BM_TypeClick(4); end

function BRH_BM_Type1Check(d) BRH_BM_TypeCheck(1); end
function BRH_BM_Type2Check(d) BRH_BM_TypeCheck(2); end
function BRH_BM_Type3Check(d) BRH_BM_TypeCheck(3); end
function BRH_BM_Type4Check(d) BRH_BM_TypeCheck(4); end
