local _,ns = ...
ns.ADDUIEVENT("PLAYER_LOGIN", function()
if AddUIDB.icon ==  false  then return end

--目标头像旁边标记助手
local function Event(event, handler)
    if _G.event == nil then
        _G.event = CreateFrame("Frame")
        _G.event.handler = {}
        _G.event.OnEvent = function(frame, event, ...)
            for key, handler in pairs(_G.event.handler[event]) do
                handler(...)
            end
        end
        _G.event:SetScript("OnEvent", _G.event.OnEvent)
    end
    if _G.event.handler[event] == nil then
        _G.event.handler[event] = {}
        _G.event:RegisterEvent(event)
    end
    table.insert(_G.event.handler[event], handler)
end

local raids = {
    { index = 1, icon = "Interface\\TargetingFrame\\UI-RaidTargetingIcons", left = 0,    right = 0.25, top = 0,    bottom = 0.25 },
    { index = 2, icon = "Interface\\TargetingFrame\\UI-RaidTargetingIcons", left = 0.25, right = 0.5,  top = 0,    bottom = 0.25 },
    { index = 3, icon = "Interface\\TargetingFrame\\UI-RaidTargetingIcons", left = 0.5,  right = 0.75, top = 0,    bottom = 0.25 },
    { index = 4, icon = "Interface\\TargetingFrame\\UI-RaidTargetingIcons", left = 0.75, right = 1,    top = 0,    bottom = 0.25 },
    { index = 5, icon = "Interface\\TargetingFrame\\UI-RaidTargetingIcons", left = 0,    right = 0.25, top = 0.25, bottom = 0.5  },
    { index = 6, icon = "Interface\\TargetingFrame\\UI-RaidTargetingIcons", left = 0.25, right = 0.5,  top = 0.25, bottom = 0.5  },
    { index = 7, icon = "Interface\\TargetingFrame\\UI-RaidTargetingIcons", left = 0.5,  right = 0.75, top = 0.25, bottom = 0.5  },
    { index = 8, icon = "Interface\\TargetingFrame\\UI-RaidTargetingIcons", left = 0.75, right = 1,    top = 0.25, bottom = 0.5  },
}

local function CreateRaidButton(frame,raid, width, height, x, y)
    local button = CreateFrame("Button", "Raid"..raid.index, frame.TargetFrameContent.TargetFrameContentMain)
    button:SetPoint("TOPRIGHT", frame,"TOPRIGHT",x,y)
    button:SetSize(width, height)
	--button:SetFrameLevel(TargetFrame.healthbar:GetFrameLevel() + 5)
    local icon = button:CreateTexture()
    icon:SetTexture(raid.icon,true)
    icon:SetTexCoord(raid.left, raid.right, raid.top, raid.bottom)
    icon:SetAllPoints(button)
    button:SetNormalTexture(icon)
    button:SetScript("OnClick",function(self) SetRaidTarget(frame.unit, raid.index) end)
end

Event("PLAYER_ENTERING_WORLD", function()
    for i,raid in pairs(raids) do
        --CreateRaidButton(raid, 16, 16, 16*(i-1), 0)		--全部显示
		CreateRaidButton(TargetFrame,raids[8], 20, 20, -15, -20)
		CreateRaidButton(TargetFrame,raids[7], 20, 20, 5, -20)
		CreateRaidButton(TargetFrame,raids[5], 16, 16, -12, -42)
		--CreateRaidButton(raids[2], 20, 20, -13, -62)
		CreateRaidButton(TargetFrame,raids[4], 16, 16, 5, -42)
		
		CreateRaidButton(FocusFrame,raids[8], 16, 16, -18, -20)
		CreateRaidButton(FocusFrame,raids[7], 16, 16, -2, -20)
		CreateRaidButton(FocusFrame,raids[5], 16, 16, -12, -40)
		CreateRaidButton(FocusFrame,raids[4], 16, 16, -12, -60)
    end
end)

end)