ToolsCommonButton = {
	Version = "07.07.01_R6",
	Color = {
		Pushed = {0,1,0},
		Checked = {1,1,0},
		Highlight = {0,1,1},
		Border = {0,0.5,1},
	},
	value = {
		-- {"이름", "파일명"},
		{"없음", ""},
		{"기본", "Interface\\Buttons\\UI-Quickslot2"},
		{"Serenity", "Circle1"},
		{"Sprocket", "Circle2"},
		{"Square", "Square1"},
		{"Devil C D.Gray", "Devil1"},
		{"Devil Crystal", "Devil_Cristal"},
		{"Devil S White 1", "Devil_Square1"},
		{"Devil S White 2", "Devil_Square4"},
		{"Devil S Thin Gray", "Devil_Square2"},
		{"Devil S Thick Gray", "Devil_Square5"},
		{"Devil S D.Gray 1", "Devil2"},
		{"Devil S D.Gray 2", "Devil3"},
		{"Devil S Thin Black 1", "Devil_Square3"},
		{"Devil S Thin Black 2", "Devil_Square6"},
		{"Devil S Thick Black", "Devil_Square7"},
		{"Hekerc Circle 1", "hekerc1"},
		{"Hekerc Circle 2", "hekerc2"},
		{"Hekerc 기본", "Hekerc_standard"},
		{"Devil UI 기본", "Devil_standard"},
	}
}
local function getpath(t)
	t = ToolsCommonButton.value[t] and t or 1
	return t <= 2 and ToolsCommonButton.value[t][2] or "interface\\AddOns\\ToolsButtonTexture\\Button\\"..ToolsCommonButton.value[t][2]
end
local function texture(chk, t, btn)
	btn = btn or this
	if (chk) then
		btn.n:SetTexture(btn.toolstexture)
		btn.n:SetAlpha(1)
	else
		btn.n:SetTexture("Interface\\Buttons\\UI-Quickslot")
		btn.n:SetAlpha(0.5)
	end
end
local function petupdate()
	for i = 1, NUM_PET_ACTION_SLOTS do
		local b = getglobal("PetActionButton"..i)
		if not b.toolstexture then return end
		if b.toolstexture == "" or b.toolstexture == "Interface\\Buttons\\UI-Quickslot2" then
			texture(GetPetActionInfo(i), nil, b)
		else
			b.n:SetTexture(getglobal("PetActionButton"..i).toolstexture)
			b.n:SetAlpha(1)
		end
	end
end
local function update()
	if not this.toolstexture then return end
	if this.border and this.border:IsShown() then
		this.border:SetVertexColor(unpack(ToolsCommonButton.Color.Border))
		this.border:SetAlpha(0.8)
	end
	if this.toolstexture == "" or this.toolstexture == "Interface\\Buttons\\UI-Quickslot2" then
		if ( string.find(this:GetName(), "PetActionButton") ) then
			--texture(GetPetActionInfo(this:GetID()))
		elseif ( string.find(this:GetName(), "ShapeshiftButton") ) then
			texture(GetShapeshiftFormInfo(this:GetID()))
		else
			texture(HasAction(ActionButton_GetPagedID(this)))
		end
		this.n:SetAlpha(0.5)
	else
		this.n:SetTexture(this.toolstexture)
		this.n:SetAlpha(1)
	end
end

hooksecurefunc("ShowPetActionBar",	function() petupdate()	end)
hooksecurefunc("PetActionBar_ShowGrid", function() petupdate()	end)
hooksecurefunc("PetActionBar_HideGrid", function() petupdate()	end)
hooksecurefunc("PetActionBar_Update",	function() petupdate()	end)
hooksecurefunc("ActionButton_ShowGrid", function() update()	end)
hooksecurefunc("ActionButton_HideGrid", function() update()	end)
hooksecurefunc("ActionButton_Update",	function() update()	end)
hooksecurefunc("MultiActionBar_UpdateGrid", function (barName, show)
	for i=1, 12 do
		local btn = getglobal(barName.."Button"..i)
		if not btn.toolstexture then return end
		if show then
			if btn.toolstexture ~= "" and btn.toolstexture ~= "Interface\\Buttons\\UI-Quickslot2" then
				btn.n:SetAlpha(1)
			elseif not HasAction(ActionButton_GetPagedID(btn)) then
				btn.n:SetTexture("Interface\\Buttons\\UI-Quickslot")
				btn.n:SetAlpha(0.5)
			end
		else
			if btn.toolstexture == "Interface\\Buttons\\UI-Quickslot2" then
				if HasAction(ActionButton_GetPagedID(btn)) then
					btn.n:SetTexture(btn.toolstexture)
					btn.n:SetAlpha(1)
				end
			end
		end
	end
end)
function ToolsCommonButton:SetButtonTexture(btn, t, show, size, icon)
	-- btn, t, show, size, icon = 버튼, 텍스쳐 번호, bt3레이어, 사이즈가 틀린것일시, 아이콘텍스쳐이름
	btn = type(btn)=="string" and getglobal(btn) or btn
	if not btn.GetFrameType then
		return
	end
	btn.bt = show
	if not btn.f then
		btn.n = btn:GetNormalTexture()
		btn.p = btn:GetPushedTexture()
		if btn:GetFrameType() == "CheckButton" then
			btn.c = btn:GetCheckedTexture()
		end
		btn.h = btn:GetHighlightTexture()
		btn.f = CreateFrame("Frame", nil, btn)
		btn.f:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", edgeFile = "",
					tile = true, tileSize = 5, edgeSize = 0, insets={left = 0, right = 0, top = 0, bottom = 0}})
		btn.f:SetFrameStrata("BACKGROUND")
		btn.f:SetFrameLevel(0)
	end

	local allpoint = (t <= 2) and (icon or getglobal(btn:GetName().."Icon")) or btn.n
	local coord = (t <= 2) and {0.2,0.8,0.2,0.8} or {0,1,0,1}
	local xw, yw = btn:GetWidth(), btn:GetHeight()
	size = size or 13

	btn.n:ClearAllPoints()
	btn.n:SetPoint("TOPLEFT", btn, "TOPLEFT", -size, size)
	btn.n:SetPoint("BOTTOMRIGHT", btn, "BOTTOMRIGHT", size, -size)

	btn.toolstexture = getpath(t)
	btn.border = getglobal(btn:GetName().."Border")

	if btn.border then
		btn.border:SetVertexColor(unpack(ToolsCommonButton.Color.Border))
		btn.border:SetAlpha(0.8)
		getglobal(btn:GetName().."Border"):SetTexture((t <= 2) and "Interface\\Buttons\\UI-ActionButton-Border" or getpath(t))
		getglobal(btn:GetName().."Border"):SetBlendMode("ADD")
		getglobal(btn:GetName().."Border"):SetTexCoord(unpack(coord))
		getglobal(btn:GetName().."Border"):SetAllPoints(allpoint)
	end

	btn.n:SetTexture(btn.toolstexture)
	btn.p:SetTexture(t <= 2 and "Interface\\Buttons\\UI-Quickslot-Depress" or btn.toolstexture)
	btn.h:SetTexture(t <= 2 and "Interface\\Buttons\\ButtonHilight-Square" or btn.toolstexture)

	btn.p:SetVertexColor(unpack(self.Color.Pushed))
	btn.h:SetVertexColor(unpack(self.Color.Highlight))

	btn.p:SetAllPoints(allpoint)
	btn.h:SetAllPoints(allpoint)

	if btn.c then
		btn.c:SetTexture(t <= 2 and "Interface\\Buttons\\CheckButtonHilight" or btn.toolstexture)
		btn.c:SetBlendMode("ADD")
		btn.c:SetVertexColor(unpack(self.Color.Checked))
		btn.c:SetAllPoints(allpoint)
	end

	icon = icon or getglobal(btn:GetName().."Icon")

	if icon then
		if t == 2 then
			icon:SetTexCoord(0,1,0,1)
		else
			icon:SetTexCoord(0.06,0.94,0.09,0.94)
		end
	end

	btn.n:SetAlpha(1)

	btn.f:SetPoint("CENTER", btn)
	btn.f:SetBackdropColor(0, 0, 0, (btn.bt and t <= 2) and .8 or 0)
	btn.f:SetWidth((btn.bt and t <=2) and xw + 10 or 1)
	btn.f:SetHeight((btn.bt and t <=2) and yw + 10 or 1)
end