-- Info: 修复BLZ遗留的自身插件错误
-- Last Updater: 2008-05-20
-- WebSite: http://cwowaddon.com

 --fix Talent Ui bug
function KEKEWAWA_OnLoad()
	this:RegisterEvent ("ADDON_LOADED");
end

		local KEKEWAWA = {};
			KEKEWAWA.frame = CreateFrame("Frame", "TalentFrame", UIParent);
			KEKEWAWA.frame:CreateFontString("TalentFrameTalentPointsText");
			KEKEWAWA.frame:CreateFontString("TalentFrameTalentPoints");
			KEKEWAWA.frame:CreateFontString("TalentFrameSpentPoints");
			KEKEWAWA.frame:CreateTexture("TalentFramePointsMiddle");
		for i=1, 5 do
			KEKEWAWA.tab = CreateFrame("Frame", "TalentFrameTab" .. i, KEKEWAWA.frame);
			KEKEWAWA.tab:CreateFontString("TalentFrameTab" .. i .. "Text");
		end

local function fixTalentBug()
		for i=1, 5 do
			getglobal("PlayerTalentFrameTab"..i.."Text"):SetPoint("CENTER", "PlayerTalentFrameTab"..i, "CENTER", 0, 5);
	end

	PlayerTalentFrameTalentPoints:SetPoint("RIGHT", "PlayerTalentFrameTalentPointsText", "LEFT", -3, 0);
	PlayerTalentFrameTalentPointsText:SetPoint("BOTTOMRIGHT", "PlayerTalentFrame", "BOTTOMLEFT", 252, 85);
	PlayerTalentFrameSpentPoints:SetPoint("TOP", "PlayerTalentFramePointsMiddle", "TOP", 0, -2);
end

function ADDON_LOADED()
	if arg1 == "Blizzard_TalentUI" then
			fixTalentBug();
	end
end

--/********************************************************************************\
do
	for i, control in pairs(InterfaceOptionsCameraPanel.controls) do
		if control.event == "MAX_FOLLOW_DIST" then
			control:SetMinMaxValues(1.0, 3.4)
			control:SetValue(GetCVar("cameraDistanceMaxFactor"))

			control.tooltipText = OPTION_TOOLTIP_MAX_FOLLOW_DIST
				.."\n|cff00CC33增强最大镜头跟随距离30-50"

			break
		end
	end
end

-----
--    RAID
-----
function cwdg_WatchRaidGroupButtons()
	local i;
	local button;
	for i=1, 40 do
		button = getglobal("RaidGroupButton"..i);
		button:SetAttribute("type", "target");
		button:SetAttribute("unit", button.unit);
	end
end

function cwdg_WatchPetActionBar()
	PetActionBarFrame:SetAttribute("unit", "pet");
	RegisterUnitWatch(PetActionBarFrame);
end

cwdg_button = CreateFrame("Frame");
local b = cwdg_button;
b:RegisterEvent("VARIABLES_LOADED");
b:RegisterEvent("ADDON_LOADED");
b:RegisterEvent("PLAYER_TARGET_CHANGED");
b:SetScript("OnEvent", function()
	if (event == "ADDON_LOADED" and arg1 == "Blizzard_RaidUI") then
		if (InCombatLockdown()) then
			--调用
		else
			cwdg_WatchRaidGroupButtons();
		end
	elseif (event == "VARIABLES_LOADED") then
		if (InCombatLockdown()) then
			--
		else
			cwdg_WatchPetActionBar();
		end
	end
end);

UIParent:UnregisterEvent("ADDON_ACTION_BLOCKED")


function WorldStateAlwaysUpFrame_FilterChatMsgSystem (message)
	local playerName;
	
	if ( GetBattlefieldWinner() ) then
		-- Filter out leaving messages when the battleground is over.
		for i, str in next, FILTERED_BG_CHAT_SUBTRACT do
			playerName = string.match(message, str);
			if ( playerName ) then
				return true;
			end
		end
	elseif ( WORLDSTATEALWAYSUPFRAME_TIMESINCESTART < WORLDSTATEALWAYSUPFRAME_TIMETORUN ) then
		-- Filter out leaving and joining messages when the battleground starts.
		for i, str in next, FILTERED_BG_CHAT_ADD do
			playerName = string.match(message, str);
			if ( playerName ) then
				-- Trim realm names
				playerName = string.match(playerName, "([^%-]+)%-?.*");
				ADDED_PLAYERS[playerName] = true;
				return true;
			end
		end
		
		for i, str in next, FILTERED_BG_CHAT_SUBTRACT do
			playerName = string.match(message, str);
			if ( playerName ) then
				playerName = string.match(playerName, "([^%-]+)%-?.*");
				SUBTRACTED_PLAYERS[playerName] = true;
				return true;
			end
		end
	end
	return false;
end 


--
-- GUI
CWDGLibPack = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer)
CWDGLibPack.name = "!!!CWDGLibPack";
InterfaceOptions_AddCategory(CWDGLibPack)

local f = CWDGLibPack
fTitle = f:CreateFontString(nil, "ARTWORK", "GameFontNormalHuge");
fTitle:SetJustifyH("LEFT");
fTitle:SetJustifyV("TOP");
fTitle:SetPoint("TOPLEFT", 12, -10);
local temp, temp2
local temp = GetAddOnMetadata("!!!CWDGLibPack", "Title")
local temp2 = GetAddOnMetadata("!!!CWDGLibPack", "Version")
fTitle:SetText(temp..temp2);

fSubText = f:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall");
fSubText:SetJustifyH("LEFT");
fSubText:SetJustifyV("TOP");
fSubText:SetPoint("TOPLEFT", 16, -38);
fSubText:SetNonSpaceWrap(true)
fSubText:SetWidth(300)
local tmp3 = GetAddOnMetadata("!!!CWDGLibPack", "Notes")
fSubText:SetText(tmp3);


CreateFrame("Frame", "CsOptionsFrame", CWDGLibPack, "OptionFrameBoxTemplate");
CsOptionsFrame:SetPoint("TOPLEFT", 10, -75);
CsOptionsFrame:SetWidth(360);
CsOptionsFrame:SetHeight(320);
CsOptionsFrame:SetBackdropBorderColor(0.4, 0.4, 0.4);
CsOptionsFrame:SetBackdropColor(0.15, 0.15, 0.15);


--Create Scroll frame
local CWDGScrollFrame = CreateFrame("ScrollFrame", "CWDGScrollFrame", CsOptionsFrame)
local CWDGScrollChild = CreateFrame("Frame", "CWDGScrollChild", CWDGScrollFrame)
local CWDGScrollBar = CreateFrame("Slider", "CWDGScrollBar", CWDGScrollFrame, "UIPanelScrollBarTemplate")
CWDGScrollFrame:SetScrollChild(CWDGScrollChild)
CWDGScrollFrame:EnableMouseWheel(true)
CWDGScrollFrame:SetScript("OnMouseWheel", function(this, change)
		local childHeight = 1000
		local frameHeight = CWDGScrollFrame:GetHeight()
		if childHeight <= frameHeight then
			return
		end

		nextFreeScroll = GetTime() + 1

		local diff = childHeight - frameHeight

		local delta = 1
		if change > 0 then
			delta = -1
		end

		local value = CWDGScrollBar:GetValue() + delta*24/diff
		if value < 0 then
			value = 0
		elseif value > 1 then
			value = 1
		end
		CWDGScrollBar:SetValue(value) -- will trigger OnValueChanged
	end)


CWDGScrollFrame:SetPoint("TOPLEFT", CsOptionsFrame, "TOPLEFT", 9, -9)
CWDGScrollFrame:SetPoint("BOTTOMRIGHT", CsOptionsFrame, "BOTTOMRIGHT", -28, 12)

CWDGScrollChild:SetHeight(10)
CWDGScrollChild:SetWidth(10)

CWDGScrollBar:SetPoint("TOPLEFT", CWDGScrollFrame, "TOPRIGHT", 0, -16)
CWDGScrollBar:SetPoint("BOTTOMLEFT", CWDGScrollFrame, "BOTTOMRIGHT", 0, 16)
CWDGScrollBar:SetMinMaxValues(0, 1)
CWDGScrollBar:SetValueStep(1e-5)
CWDGScrollBar:SetValue(0)
CWDGScrollBar:SetWidth(16)
CWDGScrollBar:SetScript("OnValueChanged", function(this)
		local max = 1000 - CWDGScrollFrame:GetHeight()

		local val = CWDGScrollBar:GetValue() * max

		if math.abs(CWDGScrollFrame:GetVerticalScroll() - val) < 1 then
			return
		end

		CWDGScrollFrame:SetVerticalScroll(val)

		CWDGScrollFrame:UpdateScrollChildRect()
	end)
CWDGScrollBar:EnableMouseWheel(true)
CWDGScrollBar:SetScript("OnMouseWheel", function(this, ...)
		CWDGScrollFrame:GetScript("OnMouseWheel")(CWDGScrollFrame, ...)
	end)
--
--html text
CWDGNotes = CreateFrame("SimpleHTML", "CWDGNotes", CWDGScrollChild);
CWDGNotes:SetFontObject('p', GameFontNormal)
CWDGNotes:SetSpacing('p', 3)
CWDGNotes:SetFontObject('h1', GameFontHighlightLarge)
	local font, height, flags = GameFontHighlightLarge:GetFont()
	height = height * 1.25
CWDGNotes:SetFont('h1', font, height, flags)
CWDGNotes:SetSpacing('h1', height/2)

CWDGNotes:SetFontObject('h2', GameFontHighlightLarge)
	local _, height = GameFontHighlightLarge:GetFont()
CWDGNotes:SetSpacing('h2', height/2)

CWDGNotes:SetFontObject('h3', GameFontHighlightLarge)
	local _, height = GameFontHighlightLarge:GetFont()
	height = height * 14/16
CWDGNotes:SetFont('h3', font, height, flags)
CWDGNotes:SetSpacing('h3', 0)

CWDGNotes:SetHeight(1)
CWDGNotes:SetWidth(300)
CWDGNotes:SetPoint("TOPLEFT", 5, -5)
CWDGNotes:SetJustifyH("LEFT")
CWDGNotes:SetJustifyV("TOP")

--li Interface\Buttons\WHITE8X8 小方块
--[[

 1. h1, h2, h3, p
    <(h1|h2|h3|p) [align="(left|center|right)"]>...</(h1|h2|h3|p)> 

2. img
    <img src="IMAGE_SOURCE" [align="(left|center|right)"] [width="NUM"] [height="NUM"] /> 

3.  a
    <a href="LINK">TEXT</a> 

4. br
    <br /> 

]]

CWDGNotes:SetText([=[<html><body>
<h1 align="center">关于CWDG</h1>
<h2>中国魔兽世界插件开发团队</h2>
<p>获取最新汉化插件</p>
<p>CWDG站点 插件下载 "http://file.cwowaddon.com" </p>
<p></p>
<p>欢迎访问<a href="http://cwowaddon.com">CWDG站点http://cwowaddon.com</a></p>
<br />
<h2>关于整合库</h2>
<p>适用于CWOW所有ACE,rock,eva插件的整合函数库.方便 简单 易用.</p>
<p></p><p></p>
<p>如果觉得整合库所占用的资源比较大，您可以运行整合库目录中的split.bat批处理程序分解整合库为单体库。</p>
<p></p><p></p>
<p>当您需要更新整合库的时候，运行整合库目录下的unsplit.bat批处理程序合并单体库。进行升级</p>
<p></p><p></p>
<p>整合库与单体库在使用内存使用量上并无明显差异。</p>
<p></p>
<p>Ver: Loli </p>
<p></p>

</body></html>]=])
