local function CreateDropDown(frame, parent, list)
frame = CreateFrame("Button", nil, parent)
frame:SetWidth(200)
frame:SetHeight(26)
frame:SetBackdrop({
bgFile = "Interface\\Buttons\\White8X8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 14,
insets = {left = 2, right = 2, top = 2, bottom = 2}
})
frame:SetBackdropColor(0, 0, 0, 1)
frame:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0)
frame:SetHitRectInsets(0, 0, 0, 0)
frame:SetScript("OnEnter", function(self)
self:SetBackdropBorderColor(0.5, 0.5, 0.5, 1.0)
end)
frame:SetScript("OnLeave", function(self)
self:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0)
end)
frame:SetScript("OnShow", function(self)
frame.Menu:Hide()
end)
frame.List = list
frame.Menu = CreateFrame("Frame", nil, frame)
frame.Menu:SetPoint("TopLeft", frame, "BottomLeft", 0, 2)
frame.Menu:SetWidth(frame:GetWidth())
frame.Menu:SetHeight(20 * #frame.List + 10)
frame.Menu:SetBackdrop({
bgFile = "Interface\\Buttons\\White8X8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 14,
insets = {left = 2, right = 2, top = 2, bottom = 2}
})
frame.Menu:SetBackdropColor(0, 0, 0, 1)
frame.Menu:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0)
frame.Menu:SetScript("OnEnter", function(self)
self:SetBackdropBorderColor(0.5, 0.5, 0.5, 1.0)
end)
frame.Menu:SetScript("OnLeave", function(self)
self:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0)
end)
frame.Menu:SetScript("OnShow", function(self)
CloseDropDownMenus()
--[[frame:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollUp-Up")
frame:SetDisabledTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollUp-Disabled")
frame:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollUp-Down")]]
end)
--[[frame.Menu:SetScript("OnHide", function(self, button)
frame:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Up")
frame:SetDisabledTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Disabled")
frame:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Down")
end)]]
frame.Menu:Hide()
for i = 1, #frame.List do
frame.Menu[i] = CreateFrame("CheckButton", nil, frame.Menu)
if not frame.List.LastChild then
frame.Menu[i]:SetPoint("TopLeft", frame.Menu, "TopLeft", 5, -5)
else
frame.Menu[i]:SetPoint("TopLeft", frame.List.LastChild, "BottomLeft", 0, 0)
end
frame.Menu[i]:SetSize(20, 20)
frame.Menu[i]:SetHitRectInsets(0, -frame:GetWidth() + 10 + frame.Menu[i]:GetWidth(), 0, 0)
frame.Menu[i]:SetNormalFontObject(GameFontHighlightSmall)
frame.Menu[i]:SetDisabledFontObject(GameFontHighlightSmall)
frame.Menu[i]:SetHighlightFontObject(GameFontHighlightSmall)
frame.Menu[i]:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up")
--frame.Menu[i]:GetNormalTexture():SetSize(20, 20)
--frame.Menu[i]:GetNormalTexture():ClearAllPoints()
--frame.Menu[i]:GetNormalTexture():SetPoint("TOPLEFT", 0, 0)
frame.Menu[i]:SetCheckedTexture("Interface\\Buttons\\UI-Common-MouseHilight")
frame.Menu[i]:SetHighlightTexture("Interface\\Buttons\\UI-CheckBox-Highlight")
--frame.Menu[i]:GetCheckedTexture():SetSize(20, 20)
--frame.Menu[i]:GetCheckedTexture():ClearAllPoints()
--frame.Menu[i]:GetCheckedTexture():SetPoint("TOPLEFT", 0, 0)
frame.Menu[i].Text = frame.Menu[i]:CreateFontString(nil, "Overlay")
frame.Menu[i].Text:SetJustifyH("Left")
frame.Menu[i].Text:SetJustifyV("Middle")
frame.Menu[i].Text:SetWordWrap(false)
frame.Menu[i].Text:SetPoint("Left", frame.Menu[i], "Right", 5, 0)
--frame.Menu[i].Text:SetVertexColor(1, 1, 1)
frame.Menu[i]:SetFontString(frame.Menu[i].Text)
frame.Menu[i].Text:SetText(frame.List[i])
frame.List.LastChild = frame.Menu[i]
frame.Menu[i]:SetScript("OnEnter", function(self)
frame.Menu:SetBackdropBorderColor(0.5, 0.5, 0.5, 1.0)
self.Text:SetVertexColor(1, 0.82, 0)
end)
frame.Menu[i]:SetScript("OnLeave", function(self)
frame.Menu:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0)
self.Text:SetVertexColor(1, 1, 1)
end)
frame.Menu[i]:SetScript("OnClick", function(self, button)
if button == "LeftButton" then
for j = 1, #frame.Menu do
local k = frame.Menu[j]
if k ~= self then
k:SetChecked(false)
else
if not self:GetChecked() then
self:SetChecked(true)
end
end
end
frame.selected = frame.List[i]
frame.Text:SetText(frame.selected)
frame.Menu:Hide()
end
end)
end
frame.Title = frame:CreateFontString(nil, "Overlay")
frame.Title:SetFontObject(GameFontNormal)
frame.Title:SetJustifyV("Middle")
frame.Title:SetJustifyH("Left")
frame.Title:SetWordWrap(false)
frame.Title:SetSize(100, 20)
frame.Title:SetPoint("BottomLeft", frame, "TopLeft", 3, 0)
frame.Title:SetPoint("BottomRight", frame, "TopRight", -3, 0)
frame.Text = frame:CreateFontString(nil, "Overlay")
frame.Text:SetFontObject(GameFontHighlightSmall)
frame.Text:SetJustifyH("Left")
frame.Text:SetJustifyV("Middle")
frame.Text:SetWordWrap(false)
frame.Text:SetPoint("TOPLEFT", 8, -2)
frame.Text:SetPoint("BottomRight", -28, 2)
frame:SetFontString(frame.Text)
local t = frame:CreateTexture(nil, "Artwork")
t:SetTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Up")
t:SetPoint("TopRight")
t:SetPoint("BottomRight")
t:SetSize(26, 26)
frame:SetNormalTexture(t)
local t = frame:CreateTexture(nil, "Artwork")
t:SetTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Disabled")
t:SetPoint("TopRight")
t:SetPoint("BottomRight")
t:SetSize(26, 26)
frame:SetDisabledTexture(t)
local t = frame:CreateTexture(nil, "Artwork")
t:SetTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Down")
t:SetPoint("TopRight")
t:SetPoint("BottomRight")
t:SetSize(26, 26)
frame:SetPushedTexture(t)
local t = frame:CreateTexture(nil, "Artwork")
t:SetTexture("Interface\\ChatFrame\\UI-ChatIcon-BlinkHilight")
t:SetBlendMode("ADD")
t:SetPoint("TopRight")
t:SetPoint("BottomRight")
t:SetSize(26, 26)
frame:SetHighlightTexture(t)
frame:SetScript("OnClick", function(self, button)
if button == "LeftButton" then
if frame.Menu:IsShown() then
frame.Menu:Hide()
else
frame.Menu:Show()
end
end
end)
function frame:GetSelected()
return frame.selected
end
function frame:SetSelected(value)
frame.selected = value
for i = 1, #frame.List do
if frame.List[i] == value then
frame.Menu[i]:SetChecked(true)
else
frame.Menu[i]:SetChecked(false)
end
end
frame.Text:SetText(value)
end
return frame
end
local list = {
[1] = "First",
[2] = "Second",
[3] = "Third"
}
local dropdown = CreateDropDown(dropdown, UIParent, list)
dropdown:SetSelected("First")
dropdown:SetPoint("Center", UIParent, "Center", 0, 0)
dropdown.Title:SetText("Title")
dropdown.Menu:SetScript("OnHide", function(self)
-- Save Value
print(dropdown:GetSelected())
end)