local p=LibStub("\065\099\101\071\085\073-\051\046\048")local K,a=select,assert local w=PlaySound local R=CreateFrame local function H(p,...)local a=1 local w=K(a,...)while w do w:SetFrameLevel(p:GetFrameLevel()+1)H(w,w:GetChildren())a=a+1 w=K(a,...)end end local function C(p,a,...)local w=1 local R=K(w,...)a:SetFrameStrata(p)while R do C(p,R,R:GetChildren())w=w+1 R=K(w,...)end end local c={version=2000,counter=0}function c.Frame_OnEnter(p)local K=p.obj if K.useHighlight then K.highlight:Show()end K:Fire("\079\110\069\110\116\101\114")if K.specialOnEnter then K.specialOnEnter(K)end end function c.Frame_OnLeave(p)local K=p.obj K.highlight:Hide()K:Fire("\079\110\076\101\097\118\101")if K.specialOnLeave then K.specialOnLeave(K)end end function c.OnAcquire(p)p.frame:SetToplevel(true)p.frame:SetFrameStrata("\070\085\076\076\083\067\082\069\069\078\095\068\073\065\076\079\071")end function c.OnRelease(p)p:SetDisabled(false)p.pullout=nil p.frame:SetParent(nil)p.frame:ClearAllPoints()p.frame:Hide()end function c.SetPullout(p,K)p.pullout=K p.frame:SetParent(nil)p.frame:SetParent(K.itemFrame)p.parent=K.itemFrame H(K.itemFrame,K.itemFrame:GetChildren())end function c.SetText(p,K)p.text:SetText(K or"")end function c.GetText(p)return p.text:GetText()end function c.SetPoint(p,...)p.frame:SetPoint(...)end function c.Show(p)p.frame:Show()end function c.Hide(p)p.frame:Hide()end function c.SetDisabled(p,K)p.disabled=K if K then p.useHighlight=false p.text:SetTextColor(.5,.5,.5)else p.useHighlight=true p.text:SetTextColor(1,1,1)end end function c.SetOnLeave(p,K)p.specialOnLeave=K end function c.SetOnEnter(p,K)p.specialOnEnter=K end function c.Create(K)local a=p:GetNextWidgetNum(K)local w=R("\066\117\116\116\111\110","\065\099\101\071\085\073\051\048\068\114\111\112\068\111\119\110\073\116\101\109"..a)local H={}H.frame=w w.obj=H H.type=K H.useHighlight=true w:SetHeight(17)w:SetFrameStrata("\070\085\076\076\083\067\082\069\069\078\095\068\073\065\076\079\071")local C=w:CreateFontString(nil,"\079\086\069\082\076\065\089","\071\097\109\101\070\111\110\116\078\111\114\109\097\108\083\109\097\108\108")C:SetTextColor(1,1,1)C:SetJustifyH("\076\069\070\084")C:SetPoint("\084\079\080\076\069\070\084",w,"\084\079\080\076\069\070\084",18,0)C:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",w,"\066\079\084\084\079\077\082\073\071\072\084",-8,0)H.text=C local f=w:CreateTexture(nil,"\079\086\069\082\076\065\089")f:SetTexture(136810)f:SetBlendMode("\065\068\068")f:SetHeight(14)f:ClearAllPoints()f:SetPoint("\082\073\071\072\084",w,"\082\073\071\072\084",-3,0)f:SetPoint("\076\069\070\084",w,"\076\069\070\084",5,0)f:Hide()H.highlight=f local U=w:CreateTexture(nil,"\079\086\069\082\076\065\089")U:SetWidth(16)U:SetHeight(16)U:SetPoint("\076\069\070\084",w,"\076\069\070\084",3,-1)U:SetTexture(130751)U:Hide()H.check=U local W=w:CreateTexture(nil,"\079\086\069\082\076\065\089")W:SetWidth(16)W:SetHeight(16)W:SetPoint("\082\073\071\072\084",w,"\082\073\071\072\084",-3,-1)W:SetTexture(130940)W:Hide()H.sub=W w:SetScript("\079\110\069\110\116\101\114",c.Frame_OnEnter)w:SetScript("\079\110\076\101\097\118\101",c.Frame_OnLeave)H.OnAcquire=c.OnAcquire H.OnRelease=c.OnRelease H.SetPullout=c.SetPullout H.GetText=c.GetText H.SetText=c.SetText H.SetDisabled=c.SetDisabled H.SetPoint=c.SetPoint H.Show=c.Show H.Hide=c.Hide H.SetOnLeave=c.SetOnLeave H.SetOnEnter=c.SetOnEnter return H end local f=LibStub:NewLibrary("\065\099\101\071\085\073-\051\046\048-\068\114\111\112\068\111\119\110-\073\116\101\109\066\097\115\101",c.version)if f then f.GetItemBase=function()return c end end do local K="\068\114\111\112\100\111\119\110-\073\116\101\109-\072\101\097\100\101\114"local a=1 local function w(p)local K=p.obj K:Fire("\079\110\069\110\116\101\114")if K.specialOnEnter then K.specialOnEnter(K)end end local function R(p)local K=p.obj K:Fire("\079\110\076\101\097\118\101")if K.specialOnLeave then K.specialOnLeave(K)end end local function H(p,K)c.SetDisabled(p,K)if not K then p.text:SetTextColor(1,1,0)end end local function C()local a=c.Create(K)a.SetDisabled=H a.frame:SetScript("\079\110\069\110\116\101\114",w)a.frame:SetScript("\079\110\076\101\097\118\101",R)a.text:SetTextColor(1,1,0)p:RegisterAsWidget(a)return a end p:RegisterWidgetType(K,C,a+c.version)end do local K="\068\114\111\112\100\111\119\110-\073\116\101\109-\069\120\101\099\117\116\101"local a=1 local function w(p,K)local a=p.obj if a.disabled then return end a:Fire("\079\110\067\108\105\099\107")if a.pullout then a.pullout:Close()end end local function R()local a=c.Create(K)a.frame:SetScript("\079\110\067\108\105\099\107",w)p:RegisterAsWidget(a)return a end p:RegisterWidgetType(K,R,a+c.version)end do local K="\068\114\111\112\100\111\119\110-\073\116\101\109-\084\111\103\103\108\101"local a=4 local function R(p)if p.value then p.check:Show()else p.check:Hide()end end local function H(p)c.OnRelease(p)p:SetValue(nil)end local function C(p,K)local a=p.obj if a.disabled then return end a.value=not a.value if a.value then w(856)else w(857)end R(a)a:Fire("\079\110\086\097\108\117\101\067\104\097\110\103\101\100",a.value)end local function f(p,K)p.value=K R(p)end local function U(p)return p.value end local function W()local a=c.Create(K)a.frame:SetScript("\079\110\067\108\105\099\107",C)a.SetValue=f a.GetValue=U a.OnRelease=H p:RegisterAsWidget(a)return a end p:RegisterWidgetType(K,W,a+c.version)end do local K="\068\114\111\112\100\111\119\110-\073\116\101\109-\077\101\110\117"local w=2 local function R(p)local K=p.obj K:Fire("\079\110\069\110\116\101\114")if K.specialOnEnter then K.specialOnEnter(K)end K.highlight:Show()if not K.disabled and K.submenu then K.submenu:Open("\084\079\080\076\069\070\084",K.frame,"\084\079\080\082\073\071\072\084",K.pullout:GetRightBorderWidth(),0,K.frame:GetFrameLevel()+100)end end local function H(p)local K=p.obj if K.submenu then K.submenu:Close()end end local function C(p,K)a(K.type=="\068\114\111\112\100\111\119\110-\080\117\108\108\111\117\116")p.submenu=K end local function f(p)p.submenu:Close()end local function U()local a=c.Create(K)a.sub:Show()a.frame:SetScript("\079\110\069\110\116\101\114",R)a.frame:SetScript("\079\110\072\105\100\101",H)a.SetMenu=C a.CloseMenu=f p:RegisterAsWidget(a)return a end p:RegisterWidgetType(K,U,w+c.version)end do local K="\068\114\111\112\100\111\119\110-\073\116\101\109-\083\101\112\097\114\097\116\111\114"local a=2 local function w(p,K)c.SetDisabled(p,K)p.useHighlight=false end local function R()local a=c.Create(K)a.SetDisabled=w local R=a.frame:CreateTexture(nil,"\079\086\069\082\076\065\089")R:SetHeight(1)R:SetColorTexture(.5,.5,.5)R:SetPoint("\076\069\070\084",a.frame,"\076\069\070\084",10,0)R:SetPoint("\082\073\071\072\084",a.frame,"\082\073\071\072\084",-10,0)a.text:Hide()a.useHighlight=false p:RegisterAsWidget(a)return a end p:RegisterWidgetType(K,R,a+c.version)end
--[[ $Id: AceGUIWidget-DropDown-Items.lua 1272 2022-08-29 15:56:35Z nevcairiel $ ]]--

local AceGUI = LibStub("AceGUI-3.0")

-- Lua APIs
local select, assert = select, assert

-- WoW APIs
local PlaySound = PlaySound
local CreateFrame = CreateFrame

local function fixlevels(parent,...)
	local i = 1
	local child = select(i, ...)
	while child do
		child:SetFrameLevel(parent:GetFrameLevel()+1)
		fixlevels(child, child:GetChildren())
		i = i + 1
		child = select(i, ...)
	end
end

local function fixstrata(strata, parent, ...)
	local i = 1
	local child = select(i, ...)
	parent:SetFrameStrata(strata)
	while child do
		fixstrata(strata, child, child:GetChildren())
		i = i + 1
		child = select(i, ...)
	end
end

-- ItemBase is the base "class" for all dropdown items.
-- Each item has to use ItemBase.Create(widgetType) to
-- create an initial 'self' value.
-- ItemBase will add common functions and ui event handlers.
-- Be sure to keep basic usage when you override functions.

local ItemBase = {
	-- NOTE: The ItemBase version is added to each item's version number
	--       to ensure proper updates on ItemBase changes.
	--       Use at least 1000er steps.
	version = 2000,
	counter = 0,
}

function ItemBase.Frame_OnEnter(this)
	local self = this.obj

	if self.useHighlight then
		self.highlight:Show()
	end
	self:Fire("OnEnter")

	if self.specialOnEnter then
		self.specialOnEnter(self)
	end
end

function ItemBase.Frame_OnLeave(this)
	local self = this.obj

	self.highlight:Hide()
	self:Fire("OnLeave")

	if self.specialOnLeave then
		self.specialOnLeave(self)
	end
end

-- exported, AceGUI callback
function ItemBase.OnAcquire(self)
	self.frame:SetToplevel(true)
	self.frame:SetFrameStrata("FULLSCREEN_DIALOG")
end

-- exported, AceGUI callback
function ItemBase.OnRelease(self)
	self:SetDisabled(false)
	self.pullout = nil
	self.frame:SetParent(nil)
	self.frame:ClearAllPoints()
	self.frame:Hide()
end

-- exported
-- NOTE: this is called by a Dropdown-Pullout.
--       Do not call this method directly
function ItemBase.SetPullout(self, pullout)
	self.pullout = pullout

	self.frame:SetParent(nil)
	self.frame:SetParent(pullout.itemFrame)
	self.parent = pullout.itemFrame
	fixlevels(pullout.itemFrame, pullout.itemFrame:GetChildren())
end

-- exported
function ItemBase.SetText(self, text)
	self.text:SetText(text or "")
end

-- exported
function ItemBase.GetText(self)
	return self.text:GetText()
end

-- exported
function ItemBase.SetPoint(self, ...)
	self.frame:SetPoint(...)
end

-- exported
function ItemBase.Show(self)
	self.frame:Show()
end

-- exported
function ItemBase.Hide(self)
	self.frame:Hide()
end

-- exported
function ItemBase.SetDisabled(self, disabled)
	self.disabled = disabled
	if disabled then
		self.useHighlight = false
		self.text:SetTextColor(.5, .5, .5)
	else
		self.useHighlight = true
		self.text:SetTextColor(1, 1, 1)
	end
end

-- exported
-- NOTE: this is called by a Dropdown-Pullout.
--       Do not call this method directly
function ItemBase.SetOnLeave(self, func)
	self.specialOnLeave = func
end

-- exported
-- NOTE: this is called by a Dropdown-Pullout.
--       Do not call this method directly
function ItemBase.SetOnEnter(self, func)
	self.specialOnEnter = func
end

function ItemBase.Create(type)
	-- NOTE: Most of the following code is copied from AceGUI-3.0/Dropdown widget
	local count = AceGUI:GetNextWidgetNum(type)
	local frame = CreateFrame("Button", "AceGUI30DropDownItem"..count)
	local self = {}
	self.frame = frame
	frame.obj = self
	self.type = type

	self.useHighlight = true

	frame:SetHeight(17)
	frame:SetFrameStrata("FULLSCREEN_DIALOG")

	local text = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall")
	text:SetTextColor(1,1,1)
	text:SetJustifyH("LEFT")
	text:SetPoint("TOPLEFT",frame,"TOPLEFT",18,0)
	text:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-8,0)
	self.text = text

	local highlight = frame:CreateTexture(nil, "OVERLAY")
	highlight:SetTexture(136810) -- Interface\\QuestFrame\\UI-QuestTitleHighlight
	highlight:SetBlendMode("ADD")
	highlight:SetHeight(14)
	highlight:ClearAllPoints()
	highlight:SetPoint("RIGHT",frame,"RIGHT",-3,0)
	highlight:SetPoint("LEFT",frame,"LEFT",5,0)
	highlight:Hide()
	self.highlight = highlight

	local check = frame:CreateTexture(nil, "OVERLAY")
	check:SetWidth(16)
	check:SetHeight(16)
	check:SetPoint("LEFT",frame,"LEFT",3,-1)
	check:SetTexture(130751) -- Interface\\Buttons\\UI-CheckBox-Check
	check:Hide()
	self.check = check

	local sub = frame:CreateTexture(nil, "OVERLAY")
	sub:SetWidth(16)
	sub:SetHeight(16)
	sub:SetPoint("RIGHT",frame,"RIGHT",-3,-1)
	sub:SetTexture(130940) -- Interface\\ChatFrame\\ChatFrameExpandArrow
	sub:Hide()
	self.sub = sub

	frame:SetScript("OnEnter", ItemBase.Frame_OnEnter)
	frame:SetScript("OnLeave", ItemBase.Frame_OnLeave)

	self.OnAcquire = ItemBase.OnAcquire
	self.OnRelease = ItemBase.OnRelease

	self.SetPullout = ItemBase.SetPullout
	self.GetText    = ItemBase.GetText
	self.SetText    = ItemBase.SetText
	self.SetDisabled = ItemBase.SetDisabled

	self.SetPoint   = ItemBase.SetPoint
	self.Show       = ItemBase.Show
	self.Hide       = ItemBase.Hide

	self.SetOnLeave = ItemBase.SetOnLeave
	self.SetOnEnter = ItemBase.SetOnEnter

	return self
end

-- Register a dummy LibStub library to retrieve the ItemBase, so other addons can use it.
local IBLib = LibStub:NewLibrary("AceGUI-3.0-DropDown-ItemBase", ItemBase.version)
if IBLib then
	IBLib.GetItemBase = function() return ItemBase end
end

--[[
	Template for items:

-- Item:
--
do
	local widgetType = "Dropdown-Item-"
	local widgetVersion = 1

	local function Constructor()
		local self = ItemBase.Create(widgetType)

		AceGUI:RegisterAsWidget(self)
		return self
	end

	AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
end
--]]

-- Item: Header
-- A single text entry.
-- Special: Different text color and no highlight
do
	local widgetType = "Dropdown-Item-Header"
	local widgetVersion = 1

	local function OnEnter(this)
		local self = this.obj
		self:Fire("OnEnter")

		if self.specialOnEnter then
			self.specialOnEnter(self)
		end
	end

	local function OnLeave(this)
		local self = this.obj
		self:Fire("OnLeave")

		if self.specialOnLeave then
			self.specialOnLeave(self)
		end
	end

	-- exported, override
	local function SetDisabled(self, disabled)
		ItemBase.SetDisabled(self, disabled)
		if not disabled then
			self.text:SetTextColor(1, 1, 0)
		end
	end

	local function Constructor()
		local self = ItemBase.Create(widgetType)

		self.SetDisabled = SetDisabled

		self.frame:SetScript("OnEnter", OnEnter)
		self.frame:SetScript("OnLeave", OnLeave)

		self.text:SetTextColor(1, 1, 0)

		AceGUI:RegisterAsWidget(self)
		return self
	end

	AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
end

-- Item: Execute
-- A simple button
do
	local widgetType = "Dropdown-Item-Execute"
	local widgetVersion = 1

	local function Frame_OnClick(this, button)
		local self = this.obj
		if self.disabled then return end
		self:Fire("OnClick")
		if self.pullout then
			self.pullout:Close()
		end
	end

	local function Constructor()
		local self = ItemBase.Create(widgetType)

		self.frame:SetScript("OnClick", Frame_OnClick)

		AceGUI:RegisterAsWidget(self)
		return self
	end

	AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
end

-- Item: Toggle
-- Some sort of checkbox for dropdown menus.
-- Does not close the pullout on click.
do
	local widgetType = "Dropdown-Item-Toggle"
	local widgetVersion = 4

	local function UpdateToggle(self)
		if self.value then
			self.check:Show()
		else
			self.check:Hide()
		end
	end

	local function OnRelease(self)
		ItemBase.OnRelease(self)
		self:SetValue(nil)
	end

	local function Frame_OnClick(this, button)
		local self = this.obj
		if self.disabled then return end
		self.value = not self.value
		if self.value then
			PlaySound(856) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
		else
			PlaySound(857) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF
		end
		UpdateToggle(self)
		self:Fire("OnValueChanged", self.value)
	end

	-- exported
	local function SetValue(self, value)
		self.value = value
		UpdateToggle(self)
	end

	-- exported
	local function GetValue(self)
		return self.value
	end

	local function Constructor()
		local self = ItemBase.Create(widgetType)

		self.frame:SetScript("OnClick", Frame_OnClick)

		self.SetValue = SetValue
		self.GetValue = GetValue
		self.OnRelease = OnRelease

		AceGUI:RegisterAsWidget(self)
		return self
	end

	AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
end

-- Item: Menu
-- Shows a submenu on mouse over
-- Does not close the pullout on click
do
	local widgetType = "Dropdown-Item-Menu"
	local widgetVersion = 2

	local function OnEnter(this)
		local self = this.obj
		self:Fire("OnEnter")

		if self.specialOnEnter then
			self.specialOnEnter(self)
		end

		self.highlight:Show()

		if not self.disabled and self.submenu then
			self.submenu:Open("TOPLEFT", self.frame, "TOPRIGHT", self.pullout:GetRightBorderWidth(), 0, self.frame:GetFrameLevel() + 100)
		end
	end

	local function OnHide(this)
		local self = this.obj
		if self.submenu then
			self.submenu:Close()
		end
	end

	-- exported
	local function SetMenu(self, menu)
		assert(menu.type == "Dropdown-Pullout")
		self.submenu = menu
	end

	-- exported
	local function CloseMenu(self)
		self.submenu:Close()
	end

	local function Constructor()
		local self = ItemBase.Create(widgetType)

		self.sub:Show()

		self.frame:SetScript("OnEnter", OnEnter)
		self.frame:SetScript("OnHide", OnHide)

		self.SetMenu   = SetMenu
		self.CloseMenu = CloseMenu

		AceGUI:RegisterAsWidget(self)
		return self
	end

	AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
end

-- Item: Separator
-- A single line to separate items
do
	local widgetType = "Dropdown-Item-Separator"
	local widgetVersion = 2

	-- exported, override
	local function SetDisabled(self, disabled)
		ItemBase.SetDisabled(self, disabled)
		self.useHighlight = false
	end

	local function Constructor()
		local self = ItemBase.Create(widgetType)

		self.SetDisabled = SetDisabled

		local line = self.frame:CreateTexture(nil, "OVERLAY")
		line:SetHeight(1)
		line:SetColorTexture(.5, .5, .5)
		line:SetPoint("LEFT", self.frame, "LEFT", 10, 0)
		line:SetPoint("RIGHT", self.frame, "RIGHT", -10, 0)

		self.text:Hide()

		self.useHighlight = false

		AceGUI:RegisterAsWidget(self)
		return self
	end

	AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
end
