addons: use internal dropdown system api

This commit is contained in:
shagu
2020-05-01 15:15:14 +02:00
parent 1d901d39c1
commit aa446efe18
+53 -52
View File
@@ -32,7 +32,6 @@ pfUI:RegisterModule("addons", "vanilla:tbc", function ()
CreateBackdropShadow(pfUI.addons) CreateBackdropShadow(pfUI.addons)
pfUI.addons:SetScript("OnHide", function() pfUI.addons:SetScript("OnHide", function()
UIDropDownMenu_ClearAll(this.profile.dropdown)
if this.hasChanged then if this.hasChanged then
pfUI.gui:Reload() pfUI.gui:Reload()
this.hasChanged = nil this.hasChanged = nil
@@ -84,13 +83,14 @@ pfUI:RegisterModule("addons", "vanilla:tbc", function ()
end end
local function SetAddonProfile(profile) local function SetAddonProfile(profile)
UIDropDownMenu_SetText(profile, pfUI.addons.profile.dropdown)
-- create new profile if not existing -- create new profile if not existing
if not pfUI_addon_profiles[profile] then if not pfUI_addon_profiles[profile] then
pfUI_addon_profiles[profile] = GetSelectedAddonsList() pfUI_addon_profiles[profile] = GetSelectedAddonsList()
end end
-- set dropdown to profile
pfUI.addons.profile.dropdown:SetSelectionByText(profile)
-- load profile -- load profile
local selected_list = pfUI_addon_profiles[profile] local selected_list = pfUI_addon_profiles[profile]
for i=1, GetNumAddOns() do for i=1, GetNumAddOns() do
@@ -120,7 +120,7 @@ pfUI:RegisterModule("addons", "vanilla:tbc", function ()
pfUI.addons.profile = CreateFrame("Frame", "pfAddonListProfile", pfUI.addons) pfUI.addons.profile = CreateFrame("Frame", "pfAddonListProfile", pfUI.addons)
pfUI.addons.profile:SetScript("OnShow", function() pfUI.addons.profile:SetScript("OnShow", function()
pfUI_addon_profiles[T["Current"]] = GetSelectedAddonsList() pfUI_addon_profiles[T["Current"]] = GetSelectedAddonsList()
UIDropDownMenu_SetText(T["Current"], pfUI.addons.profile.dropdown) SetAddonProfile(T["Current"])
end) end)
pfUI.addons.profile:SetPoint("TOP", pfUI.addons, "TOP", 0, -34) pfUI.addons.profile:SetPoint("TOP", pfUI.addons, "TOP", 0, -34)
@@ -132,40 +132,37 @@ pfUI:RegisterModule("addons", "vanilla:tbc", function ()
pfUI.addons.profile.caption = pfUI.addons.profile:CreateFontString("Status", "LOW", "GameFontNormal") pfUI.addons.profile.caption = pfUI.addons.profile:CreateFontString("Status", "LOW", "GameFontNormal")
pfUI.addons.profile.caption:SetFontObject(GameFontWhite) pfUI.addons.profile.caption:SetFontObject(GameFontWhite)
pfUI.addons.profile.caption:SetFont(pfUI.font_default, C.global.font_size, "OUTLINE") pfUI.addons.profile.caption:SetFont(pfUI.font_default, C.global.font_size, "OUTLINE")
pfUI.addons.profile.caption:SetPoint("TOPLEFT", 10, -12) pfUI.addons.profile.caption:SetPoint("LEFT", 10, 0)
pfUI.addons.profile.caption:SetText(T["Addon Profile"]) pfUI.addons.profile.caption:SetText(T["Addon Profile"])
-- addon profile: dropdown -- addon profile: delete
pfUI.addons.profile.dropdown = CreateFrame("Frame", "pfAddonListProfileList", pfUI.addons.profile, "UIDropDownMenuTemplate") pfUI.addons.profile.del = CreateFrame("Button", nil, pfUI.addons.profile, "UIPanelButtonTemplate")
pfUI.addons.profile.dropdown:ClearAllPoints() SkinButton(pfUI.addons.profile.del)
pfUI.addons.profile.dropdown:SetPoint("TOPRIGHT", -51, -5) pfUI.addons.profile.del:SetWidth(16)
SkinDropDown(pfUI.addons.profile.dropdown) pfUI.addons.profile.del:SetHeight(16)
UIDropDownMenu_SetWidth(220, pfUI.addons.profile.dropdown) pfUI.addons.profile.del:SetPoint("RIGHT", -10, 0)
UIDropDownMenu_SetButtonWidth(220, pfUI.addons.profile.dropdown) pfUI.addons.profile.del:GetFontString():SetPoint("CENTER", 1, 0)
UIDropDownMenu_Initialize(pfUI.addons.profile.dropdown, function() pfUI.addons.profile.del:SetText("-")
local info = {} pfUI.addons.profile.del:SetTextColor(1,.5,.5,1)
for name, list in pairs(pfUI_addon_profiles) do pfUI.addons.profile.del:SetScript("OnClick", function() -- TODO
info.text = name local id, name = pfUI.addons.profile.dropdown:GetSelection()
info.checked = false if not name then return end
info.func = function() CreateQuestionDialog(T["Delete profile"] .. " '|cff33ffcc" .. name .. "|r'?", function()
UIDropDownMenu_SetSelectedID(pfUI.addons.profile.dropdown, this:GetID(), 0) pfUI_addon_profiles[name] = nil
SetAddonProfile(this:GetText()) SetAddonProfile(T["Current"])
end end)
UIDropDownMenu_AddButton(info)
end
end) end)
-- addon profile: create -- addon profile: create
pfUI.addons.profile.create = CreateFrame("Button", "pfAddonListProfileCreate", pfUI.addons.profile, "UIPanelButtonTemplate") pfUI.addons.profile.add = CreateFrame("Button", nil, pfUI.addons.profile, "UIPanelButtonTemplate")
CreateBackdrop(pfUI.addons.profile.create, nil, true) SkinButton(pfUI.addons.profile.add)
SkinButton(pfUI.addons.profile.create) pfUI.addons.profile.add:SetWidth(16)
pfUI.addons.profile.create:SetWidth(25) pfUI.addons.profile.add:SetHeight(16)
pfUI.addons.profile.create:SetHeight(25) pfUI.addons.profile.add:SetPoint("RIGHT", pfUI.addons.profile.del, "LEFT", -4, 0)
pfUI.addons.profile.create:SetPoint("LEFT", pfUI.addons.profile.dropdown.backdrop, "RIGHT", 35, 0) pfUI.addons.profile.add:GetFontString():SetPoint("CENTER", 1, 0)
pfUI.addons.profile.create:GetFontString():SetPoint("CENTER", 1, 0) pfUI.addons.profile.add:SetText("+")
pfUI.addons.profile.create:SetText("+") pfUI.addons.profile.add:SetTextColor(.5,1,.5,1)
pfUI.addons.profile.create:SetTextColor(.5,1,.5,1) pfUI.addons.profile.add:SetScript("OnClick", function()
pfUI.addons.profile.create:SetScript("OnClick", function()
CreateQuestionDialog(T["Please enter a name for the new profile."], CreateQuestionDialog(T["Please enter a name for the new profile."],
function() function()
local profile_name = this:GetParent().input:GetText() local profile_name = this:GetParent().input:GetText()
@@ -178,24 +175,26 @@ pfUI:RegisterModule("addons", "vanilla:tbc", function ()
end, false, true) end, false, true)
end) end)
-- addon profile: delete -- addon profile: dropdown
pfUI.addons.profile.delete = CreateFrame("Button", "pfAddonListProfileDelete", pfUI.addons.profile, "UIPanelButtonTemplate") pfUI.addons.profile.dropdown = CreateDropDownButton("pfAddonListProfileList", pfUI.addons.profile)
CreateBackdrop(pfUI.addons.profile.delete, nil, true) pfUI.addons.profile.dropdown:SetBackdrop(nil)
SkinButton(pfUI.addons.profile.delete) pfUI.addons.profile.dropdown:ClearAllPoints()
pfUI.addons.profile.delete:SetWidth(25) pfUI.addons.profile.dropdown:SetPoint("RIGHT", pfUI.addons.profile.add, "LEFT", -2, 0)
pfUI.addons.profile.delete:SetHeight(25) pfUI.addons.profile.dropdown:SetWidth(220)
pfUI.addons.profile.delete:SetPoint("LEFT", pfUI.addons.profile.dropdown.backdrop, "RIGHT", 5, 0) pfUI.addons.profile.dropdown:SetMenu(function()
pfUI.addons.profile.delete:GetFontString():SetPoint("CENTER", 0, 0) local menu = {}
pfUI.addons.profile.delete:SetText("-")
pfUI.addons.profile.delete:SetTextColor(1,.5,.5,1) for name, list in pairs(pfUI_addon_profiles) do
pfUI.addons.profile.delete:SetScript("OnClick", function() local entry = {}
local profile_name = UIDropDownMenu_GetText(pfUI.addons.profile.dropdown) entry.text = name
if profile_name then entry.checked = false
CreateQuestionDialog(T["Delete profile"] .. " '|cff33ffcc" .. profile_name .. "|r'?", function() entry.func = function()
pfUI_addon_profiles[profile_name] = nil SetAddonProfile(name)
SetAddonProfile(T["Current"]) end
end) table.insert(menu, entry)
end end
return menu
end) end)
-- addon list: scroll frame -- addon list: scroll frame
@@ -273,8 +272,10 @@ pfUI:RegisterModule("addons", "vanilla:tbc", function ()
DisableAddOn(this:GetID()) DisableAddOn(this:GetID())
end end
pfUI.addons.hasChanged = true pfUI.addons.hasChanged = true
local profile_name = UIDropDownMenu_GetText(pfUI.addons.profile.dropdown) or T["Current"]
pfUI_addon_profiles[profile_name] = GetSelectedAddonsList() local id, name = pfUI.addons.profile.dropdown:GetSelection()
name = name or T["Current"]
pfUI_addon_profiles[name] = GetSelectedAddonsList()
end) end)
end end