Quantcast
--[[
##############################################################################
_____/\\\\\\\\\\\____/\\\________/\\\__/\\\________/\\\__/\\\\\\\\\\\_       #
 ___/\\\/////////\\\_\/\\\_______\/\\\_\/\\\_______\/\\\_\/////\\\///__      #
  __\//\\\______\///__\//\\\______/\\\__\/\\\_______\/\\\_____\/\\\_____     #
   ___\////\\\__________\//\\\____/\\\___\/\\\_______\/\\\_____\/\\\_____    #
    ______\////\\\________\//\\\__/\\\____\/\\\_______\/\\\_____\/\\\_____   #
     _________\////\\\______\//\\\/\\\_____\/\\\_______\/\\\_____\/\\\_____  #
      __/\\\______\//\\\______\//\\\\\______\//\\\______/\\\______\/\\\_____ #
       _\///\\\\\\\\\\\/________\//\\\________\///\\\\\\\\\/____/\\\\\\\\\\\_#
        ___\///////////___________\///___________\/////////_____\///////////_#
##############################################################################
S U P E R - V I L L A I N - U I   By: Munglunch                              #
##############################################################################
##########################################################
LOCALIZED LUA FUNCTIONS
##########################################################
]]--
--[[ GLOBALS ]]--
local _G = _G;
local unpack 	= _G.unpack;
local select 	= _G.select;
local pairs 	= _G.pairs;
local error 	= _G.error;
local pcall 	= _G.pcall;
local tinsert 	= _G.tinsert;
local string 	= _G.string;
local table 	= _G.table;
--[[ STRING METHODS ]]--
local lower, upper, find = string.lower, string.upper, string.find;
--[[ TABLE METHODS ]]--
local twipe = table.wipe;
--[[
##########################################################
GET ADDON DATA
##########################################################
]]--
local SuperVillain, L = unpack(SVUI);
local STYLE = _G.StyleVillain;
--[[
##########################################################
LOCAL FUNCTIONS
##########################################################
]]--
local function Button_OnEnter(this)
    this:SetBackdropColor(unpack(SuperVillain.Media.color.highlight))
end

local function Button_OnLeave(this)
    this:SetBackdropColor(unpack(SuperVillain.Media.color.default))
end

local function Button_OnEnter2(this)
    this:SetBackdropColor(unpack(SuperVillain.Media.color.highlight))
    this:SetBackdropBorderColor(unpack(SuperVillain.Media.color.highlight))
end

local function Button_OnLeave2(this)
    this:SetBackdropColor(unpack(SuperVillain.Media.color.default))
    this:SetBackdropBorderColor(0,0,0,1)
end

local function Tab_OnEnter(this)
	this.backdrop:SetPanelColor("highlight")
	this.backdrop:SetBackdropBorderColor(unpack(SuperVillain.Media.color.highlight))
end

local function Tab_OnLeave(this)
	this.backdrop:SetPanelColor("dark")
	this.backdrop:SetBackdropBorderColor(0,0,0,1)
end

local function DD_OnClick(btn)
    btn.func()
    btn:GetParent():Hide()
end

local function DD_OnEnter(btn)
    btn.hoverTex:Show()
end

local function DD_OnLeave(btn)
    btn.hoverTex:Hide()
end

local function CloseButton_OnEnter(this)
    this:SetBackdropBorderColor(unpack(SuperVillain.Media.color.highlight))
end

local function CloseButton_OnLeave(this)
    this:SetBackdropBorderColor(0,0,0,1)
end
--[[
##########################################################
CORE FUNCTIONS
##########################################################
]]--
function STYLE:SetBasicBG(this)
	if(not this or (this and this.BasicBG)) then return end

	local currentLevel = this:GetFrameLevel()
	if(currentLevel == 0) then
		currentLevel = 1
	end

	local bg = CreateFrame("Frame", nil, this)
	bg:SetAllPoints(this)
	bg:SetFrameLevel(currentLevel - 1)
	bg:SetBackdrop({
        bgFile = [[Interface\BUTTONS\WHITE8X8]],
        edgeFile = [[Interface\BUTTONS\WHITE8X8]],
        tile = false,
        tileSize = 0,
        edgeSize = 1,
        insets =
        {
            left = 1,
            right = 1,
            top = 1,
            bottom = 1,
        },
    })
    bg:SetBackdropColor(0,0,0,0.5)
    bg:SetBackdropBorderColor(0,0,0)

    this.BasicBG = true
end

function STYLE:ApplyFrameStyle(this, template, noStripping, fullStripping)
	if(not this or (this and this.Panel)) then return end
	if not noStripping then this:Formula409(fullStripping) end
	template = template or "Transparent"
	this:SetPanelTemplate(template)
end

function STYLE:ApplyUnderlayStyle(this, template, noStripping, fullStripping)
	if(not this or (this and this.Panel)) then return end
	if not noStripping then this:Formula409(fullStripping) end
	template = template or "Transparent"
    this:SetFixedPanelTemplate(template)
end

function STYLE:ApplyButtonStyle(this)
	if not this then return end
    this:SetButtonTemplate()
end

function STYLE:ApplyEditBoxStyle(this, width, height)
	if not this then return end
    this:SetEditboxTemplate()
    if width then this:Width(width) end
	if height then this:Height(height) end
end

function STYLE:ApplyTextureStyle(this)
	if not this then return end
	this:SetTexCoord(0.1, 0.9, 0.1, 0.9)
	local parent = this:GetParent()
	if(parent) then
		this:FillInner(parent, 1, 1)
	end
end

function STYLE:ApplyCloseButtonStyle(this, anchor)
	if not this then return end
    if not this.hookedColors then
        this:HookScript("OnEnter", CloseButton_OnEnter)
        this:HookScript("OnLeave", CloseButton_OnLeave)
        this.hookedColors = true
    end
    if anchor then
    	this:SetPoint("TOPRIGHT", anchor, "TOPRIGHT", 2, 2)
    end
end

function STYLE:ApplyRotateStyle(this)
	-- Do stuff
end

function STYLE:ApplyScrollStyle(this)
	if(not this or (this and this.appliedStyle)) then return end
	if _G[this:GetName().."BG"]then
		_G[this:GetName().."BG"]:SetTexture(0,0,0,0)
	end
	if _G[this:GetName().."Track"]then
		_G[this:GetName().."Track"]:SetTexture(0,0,0,0)
	end
	if _G[this:GetName().."Top"]then
		_G[this:GetName().."Top"]:SetTexture(0,0,0,0)
	end
	if _G[this:GetName().."Bottom"]then
		_G[this:GetName().."Bottom"]:SetTexture(0,0,0,0)
	end
	if _G[this:GetName().."Middle"]then
		_G[this:GetName().."Middle"]:SetTexture(0,0,0,0)
	end
	if _G[this:GetName().."ScrollUpButton"] and _G[this:GetName().."ScrollDownButton"]then
		_G[this:GetName().."ScrollUpButton"]:Formula409()
		if not _G[this:GetName().."ScrollUpButton"].icon then
			STYLE:ApplyPaginationStyle(_G[this:GetName().."ScrollUpButton"])
			SquareButton_SetIcon(_G[this:GetName().."ScrollUpButton"], "UP")
			_G[this:GetName().."ScrollUpButton"]:Size(_G[this:GetName().."ScrollUpButton"]:GetWidth() + 7, _G[this:GetName().."ScrollUpButton"]:GetHeight() + 7)
		end
		_G[this:GetName().."ScrollDownButton"]:Formula409()
		if not _G[this:GetName().."ScrollDownButton"].icon then
			STYLE:ApplyPaginationStyle(_G[this:GetName().."ScrollDownButton"])
			SquareButton_SetIcon(_G[this:GetName().."ScrollDownButton"], "DOWN")
			_G[this:GetName().."ScrollDownButton"]:Size(_G[this:GetName().."ScrollDownButton"]:GetWidth() + 7, _G[this:GetName().."ScrollDownButton"]:GetHeight() + 7)
		end
		if not this.styledBackground then
			this.styledBackground = CreateFrame("Frame", nil, this)
			this.styledBackground:Point("TOPLEFT", _G[this:GetName().."ScrollUpButton"], "BOTTOMLEFT", 0, -1)
			this.styledBackground:Point("BOTTOMRIGHT", _G[this:GetName().."ScrollDownButton"], "TOPRIGHT", 0, 1)
			STYLE:SetBasicBG(this.styledBackground)
		end
		this:SetThumbTexture("Interface\\Buttons\\UI-ScrollBar-Knob")
	end
	this.appliedStyle = true
end

function STYLE:ApplyScrollbarStyle(this)
	if(not this or (this and this.appliedStyle)) then return end

	this:Formula409()
	this:SetThumbTexture("Interface\\Buttons\\UI-ScrollBar-Knob")

	if(this:GetOrientation() == "VERTICAL") then
		this:Width(12)
	else
		this:Height(12)
		for i=1, this:GetNumRegions() do
			local child = select(i, this:GetRegions())
			if(child and child:GetObjectType() == "FontString") then
				local anchor, parent, relative, x, y = child:GetPoint()
				if relative:find("BOTTOM") then
					child:Point(anchor, parent, relative, x, y - 4)
				end
			end
		end
	end

	local currentLevel = this:GetFrameLevel()
	if(currentLevel == 0) then
		currentLevel = 1
	end

	local bg = CreateFrame("Frame", nil, this)
	bg:SetAllPoints(this)
	bg:SetFrameLevel(currentLevel)
	bg:SetBackdrop({
        bgFile = [[Interface\BUTTONS\WHITE8X8]],
        edgeFile = [[Interface\BUTTONS\WHITE8X8]],
        tile = false,
        tileSize = 0,
        edgeSize = 1,
        insets =
        {
            left = 1,
            right = 1,
            top = 1,
            bottom = 1,
        },
    })
    bg:SetBackdropColor(0,0,0)
    bg:SetBackdropBorderColor(0.2,0.2,0.2)

	this.appliedStyle = true
end

local function TabHelper(this)
	this:Formula409()
	local nTex = this:GetNormalTexture()
	if(nTex) then
		nTex:SetTexCoord(0.1, 0.9, 0.1, 0.9)
		nTex:FillInner()
	end
	this.pushed = true;
	this.backdrop = CreateFrame("Frame", nil, this)
	this.backdrop:WrapOuter(this,1,1)
	this.backdrop:SetFrameLevel(0)
	this.backdrop:SetBackdrop({
		bgFile = [[Interface\BUTTONS\WHITE8X8]],
        tile = false,
        tileSize = 0,
        edgeFile = [[Interface\AddOns\SVUI\assets\artwork\Template\GLOW]],
        edgeSize = 3,
        insets = {
            left = 0,
            right = 0,
            top = 0,
            bottom = 0
        }
    });
    this.backdrop:SetBackdropColor(0,0,0,1)
	this.backdrop:SetBackdropBorderColor(0,0,0,1)
	this:HookScript("OnEnter",Tab_OnEnter)
    this:HookScript("OnLeave",Tab_OnLeave)

	local a,b,c,d,e = this:GetPoint()
	this:Point(a,b,c,1,e)
end;

function STYLE:ApplyTabStyle(this, full)
	if(not this or (this and this.appliedStyle)) then return end

	local tab = this:GetName();
	if _G[tab.."Left"] then _G[tab.."Left"]:SetTexture(0,0,0,0) end
	if _G[tab.."LeftDisabled"] then _G[tab.."LeftDisabled"]:SetTexture(0,0,0,0) end
	if _G[tab.."Right"] then _G[tab.."Right"]:SetTexture(0,0,0,0) end
	if _G[tab.."RightDisabled"] then _G[tab.."RightDisabled"]:SetTexture(0,0,0,0) end
	if _G[tab.."Middle"] then _G[tab.."Middle"]:SetTexture(0,0,0,0) end
	if _G[tab.."MiddleDisabled"] then _G[tab.."MiddleDisabled"]:SetTexture(0,0,0,0) end

	if this.GetHighlightTexture and this:GetHighlightTexture()then
		this:GetHighlightTexture():SetTexture(0,0,0,0)
	else
		this:Formula409()
	end

	if(full) then
		TabHelper(this)
	end

	local text = _G[tab.."Text"]
	this.backdrop = CreateFrame("Frame", nil, this)
	this.backdrop:FillInner(this, 10, 3)
	this.backdrop:SetFixedPanelTemplate("Component", true)
	this.backdrop:SetPanelColor("dark")
	if(this:GetFrameLevel() > 0) then
		this.backdrop:SetFrameLevel(this:GetFrameLevel() - 1)
	end
	this:HookScript("OnEnter",Tab_OnEnter)
    this:HookScript("OnLeave",Tab_OnLeave)
    this.appliedStyle = true
end

function STYLE:ApplyPaginationStyle(button, isVertical)
	if(not button or (button and not button:GetName()) or (button and button.appliedStyle)) then return end

	local bName = button:GetName()
	local testName = bName:lower()
	local leftDown = ((bName and testName:find('left')) or testName:find('prev') or testName:find('decrement')) or false

	button:Formula409()
	button:SetNormalTexture(0,0,0,0)
	button:SetPushedTexture(0,0,0,0)
	button:SetHighlightTexture(0,0,0,0)
	button:SetDisabledTexture(0,0,0,0)

	button:SetButtonTemplate()
	button:Size((button:GetWidth() - 7), (button:GetHeight() - 7))

	if not button.icon then
		button.icon = button:CreateTexture(nil,'ARTWORK')
		button.icon:Size(13)
		button.icon:SetPoint('CENTER')
		button.icon:SetTexture([[Interface\Buttons\SquareButtonTextures]])
		button.icon:SetTexCoord(0.02, 0.2, 0.02, 0.2)

		button:SetScript('OnMouseDown',function(self)
			if self:IsEnabled() then
				self.icon:SetPoint("CENTER",-1,-1)
			end
		end)

		button:SetScript('OnMouseUp',function(self)
			self.icon:SetPoint("CENTER",0,0)
		end)

		button:SetScript('OnDisable',function(self)
			SetDesaturation(self.icon, true)
			self.icon:SetAlpha(0.5)
		end)

		button:SetScript('OnEnable',function(self)
			SetDesaturation(self.icon, false)
			self.icon:SetAlpha(1.0)
		end)

		if not button:IsEnabled() then
			button:GetScript('OnDisable')(button)
		end
	end

	if isVertical then
		if leftDown then SquareButton_SetIcon(button,'UP') else SquareButton_SetIcon(button,'DOWN')end
	else
		if leftDown then SquareButton_SetIcon(button,'LEFT') else SquareButton_SetIcon(button,'RIGHT')end
	end

	button.appliedStyle = true
end

function STYLE:ApplyDropdownStyle(this, width)
	if(not this or (this and this.appliedStyle)) then return end

	local ddName = this:GetName();
	local ddText = _G[ddName.."Text"]
	local ddButton = _G[ddName.."Button"]

	if not width then width = 155 end

	this:Formula409()
	this:Width(width)

	if(ddButton) then
		if(ddText) then
			ddText:SetPoint("RIGHT", ddButton, "LEFT", -2, 0)
		end

		ddButton:ClearAllPoints()
		ddButton:Point("RIGHT", this, "RIGHT", -10, 3)
		ddButton.AnchorParent = this

		hooksecurefunc(ddButton, "SetPoint", function(self, _, _, _, _, _, breaker)
			if not breaker then
				self:Point("RIGHT", self.AnchorParent, "RIGHT", -10, 3, true)
			end
		end)

		STYLE:ApplyPaginationStyle(ddButton, true)

		local currentLevel = this:GetFrameLevel()
		if(currentLevel == 0) then
			currentLevel = 1
		end

		local bg = CreateFrame("Frame", nil, this)
		bg:Point("TOPLEFT", this, "TOPLEFT", 20, -2)
		bg:Point("BOTTOMRIGHT", ddButton, "BOTTOMRIGHT", 2, -2)
		bg:SetFrameLevel(currentLevel - 1)
		bg:SetBackdrop({
	        bgFile = [[Interface\BUTTONS\WHITE8X8]],
	        edgeFile = [[Interface\BUTTONS\WHITE8X8]],
	        tile = false,
	        tileSize = 0,
	        edgeSize = 1,
	        insets =
	        {
	            left = 1,
	            right = 1,
	            top = 1,
	            bottom = 1,
	        },
	    })
	    bg:SetBackdropColor(0,0,0,0.75)
	    bg:SetBackdropBorderColor(0.2,0.2,0.2)
	end

	this.appliedStyle = true
end

function STYLE:ApplyLinkButtonStyle(this, adjust, shrink)
	if(not this or (this and this.appliedStyle)) then return end

	local link = this:GetName()
	this:Formula409()

	if shrink then
		this:SetPanelTemplate("Button", true, 1, -2, -2)
	else
		this:SetFixedPanelTemplate("Button")
	end
	if link then
		if _G[link.."Name"] then
			_G[link.."Name"]:SetParent(this.Panel)
		end
		local icon = this.icon or this.IconTexture;
		if _G[link.."IconTexture"] then
			icon = _G[link.."IconTexture"]
		elseif _G[link.."Icon"]then
			icon = _G[link.."Icon"]
		end
		if icon then
			icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
			if adjust then
				icon:FillInner(this, 2, 2)
			end
			local bg = CreateFrame("Frame", nil, this)
			bg:WrapOuter(icon)
			bg:SetFixedPanelTemplate("Transparent")
			icon:SetParent(bg)
			this.IconShadow = bg
		end
		if(_G[link.."Count"]) then
			local fg = CreateFrame("Frame", nil, this)
			fg:SetSize(120, 22)
			fg:SetPoint("BOTTOMLEFT", this, "BOTTOMLEFT", 0, -11)
			fg:SetFrameLevel(this:GetFrameLevel() + 30)
			_G[link.."Count"]:SetParent(fg)
			_G[link.."Count"]:SetAllPoints(fg)
			_G[link.."Count"]:SetFontTemplate(SuperVillain.Media.font.numbers, 12, "OUTLINE", "LEFT")
			_G[link.."Count"]:SetDrawLayer("ARTWORK",7)
		end
	end
	this:HookScript("OnEnter",Button_OnEnter)
    this:HookScript("OnLeave",Button_OnLeave)
	this.appliedStyle = true
end

function STYLE:ApplyTooltipStyle(frame)
	if(not frame or (frame and frame.appliedStyle)) then return end
	frame:HookScript('OnShow',function(this)
		this:SetBackdrop({
			bgFile = [[Interface\AddOns\SVUI\assets\artwork\Template\DEFAULT]],
			edgeFile = [[Interface\BUTTONS\WHITE8X8]],
			tile = false,
			edgeSize=1
		})
		this:SetBackdropColor(0,0,0,0.8)
		this:SetBackdropBorderColor(0,0,0)
	end)
	frame.appliedStyle = true
end

function STYLE:ApplyAlertStyle(frame)
	if(not frame or (frame and frame.appliedStyle)) then return end
    local alertpanel = CreateFrame("Frame", nil, frame)
    alertpanel:SetAllPoints(frame)
    alertpanel:SetFrameLevel(frame:GetFrameLevel() - 1)
    alertpanel:SetBackdrop({
        bgFile = "Interface\\AddOns\\SVUI\\assets\\artwork\\Template\\Alert\\ALERT-BG"
    })
    alertpanel:SetBackdropColor(0.8, 0.2, 0.2)
    --[[ LEFT ]]--
    local left = alertpanel:CreateTexture(nil, "BORDER")
    left:SetTexture("Interface\\AddOns\\SVUI\\assets\\artwork\\Template\\Alert\\ALERT-LEFT")
    left:Point("TOPRIGHT", alertpanel,"TOPLEFT", 0, 0)
    left:Point("BOTTOMRIGHT", alertpanel, "BOTTOMLEFT", 0, 0)
    left:Width(frame:GetHeight())
    --[[ RIGHT ]]--
    local right = alertpanel:CreateTexture(nil, "BORDER")
    right:SetTexture("Interface\\AddOns\\SVUI\\assets\\artwork\\Template\\Alert\\ALERT-RIGHT")
    right:SetVertexColor(0.8, 0.2, 0.2)
    right:Point("TOPLEFT", alertpanel,"TOPRIGHT", -1, 0)
    right:Point("BOTTOMLEFT", alertpanel, "BOTTOMRIGHT", -1, 0)
    right:Width(frame:GetHeight() * 2)
    --[[ TOP ]]--
    local top = alertpanel:CreateTexture(nil, "BORDER")
    top:SetTexture("Interface\\AddOns\\SVUI\\assets\\artwork\\Template\\Alert\\ALERT-TOP")
    top:Point("BOTTOMLEFT", alertpanel,"TOPLEFT", 0, 0)
    top:Point("BOTTOMRIGHT", alertpanel, "TOPRIGHT", 0, 0)
    top:Height(frame:GetHeight() * 0.5)
    --[[ BOTTOM ]]--
    local bottom = alertpanel:CreateTexture(nil, "BORDER")
    bottom:SetTexture("Interface\\AddOns\\SVUI\\assets\\artwork\\Template\\Alert\\ALERT-BOTTOM")
    bottom:Point("TOPLEFT", alertpanel,"BOTTOMLEFT", 0, 0)
    bottom:Point("TOPRIGHT", alertpanel, "BOTTOMRIGHT", 0, 0)
    bottom:Width(frame:GetHeight() * 0.5)

    frame.appliedStyle = true
end