
-------------------------------------------------------
-- BigFootPatch.lua
-- AndyXiao@BigFoot
-- 本文件是用来修正一些来自WoW本身Interface的问题
-------------------------------------------------------
-- patch 2.4.2 去掉的Global String
if (GetLocale() == "zhCN") then
	GOLD = "金币";
	SILVER = "银币";
	COPPER = "铜币";

	HANDY_TOOLKIT_TITLE = "便捷功能";
elseif (GetLocale() == "zhTW") then
	GOLD = "金幣";
	SILVER = "銀幣";
	COPPER = "銅幣";
else
	GOLD = "gold";
	SILVER = "silver";
	COPPER = "copper";
end

function BPatch_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 BPatch_WatchPetActionBar()
	PetActionBarFrame:SetAttribute("unit", "pet");
	RegisterUnitWatch(PetActionBarFrame);
end

bf_watcher = CreateFrame("Frame");
bf_watcher:RegisterEvent("VARIABLES_LOADED");
bf_watcher:RegisterEvent("ADDON_LOADED");
bf_watcher:RegisterEvent("PLAYER_TARGET_CHANGED");
bf_watcher:SetScript("OnEvent", function()
	if (event == "ADDON_LOADED" and arg1 == "Blizzard_RaidUI") then
		if (InCombatLockdown()) then
			BigFoot_DelayCall(BPatch_WatchRaidGroupButtons, 1);
		else
			BPatch_WatchRaidGroupButtons();
		end
	elseif (event == "VARIABLES_LOADED") then
		if (InCombatLockdown()) then
			BigFoot_DelayCall(BPatch_WatchPetActionBar, 1);
		else
			BPatch_WatchPetActionBar();
		end
	end
end);

-------------------
-- 和谐难看的字体
-------------------
SetTextStatusBarTextPrefix(PlayerFrameHealthBar, "");
SetTextStatusBarTextPrefix(PlayerFrameManaBar, "");
SetTextStatusBarTextPrefix(MainMenuExpBar, "");
--SetTextStatusBarTextPrefix(PartyMemberFrame1HealthBar, "");
--SetTextStatusBarTextPrefix(PartyMemberFrame2HealthBar, "");
--SetTextStatusBarTextPrefix(PartyMemberFrame3HealthBar, "");
--SetTextStatusBarTextPrefix(PartyMemberFrame4HealthBar, "");
hooksecurefunc("UnitFrame_UpdateManaType", function(unitFrame)	
	if (unitFrame) then
		SetTextStatusBarTextPrefix(unitFrame.manabar, "");
		TextStatusBar_UpdateTextString(unitFrame.manabar);
	end	
end);

TextStatusBarText:SetFont(STANDARD_TEXT_FONT, 14, "OUTLINE");
-------------------
-- 修正Talent UI报错问题
-------------------
local blz_TalentE = BLibrary("BEvent");

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

local function fixTalentBug()
	-- create dummy frames
	-- Talent tabs
	for i=1, 5 do
		getglobal("PlayerTalentFrameTab"..i.."Text"):SetPoint("CENTER", "PlayerTalentFrameTab"..i, "CENTER", 0, 5);
	end

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

blz_TalentE:RegisterEvent("ADDON_LOADED");

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


-- 屏蔽界面失效的提醒
UIParent:UnregisterEvent("ADDON_ACTION_BLOCKED");

-------------------
-- 修正玩家进入战场后会出现脚本错误的问题。(BLZ the idiot)
-------------------
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, "([^%-]+)%-?.*") or 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, "([^%-]+)%-?.*") or playerName;
				SUBTRACTED_PLAYERS[playerName] = true;
				return true;
			end
		end
	end
	return false;
end

