mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-15 17:50:48 +00:00
gui: replace dropdown menus with custom ones
This commit is contained in:
+65
-137
@@ -1,5 +1,5 @@
|
|||||||
pfUI:RegisterModule("gui", "vanilla:tbc", function ()
|
pfUI:RegisterModule("gui", "vanilla:tbc", function ()
|
||||||
local Reload, U, PrepareDropDownButton, CreateConfig, CreateTabFrame, CreateArea, CreateGUIEntry, EntryUpdate
|
local Reload, U, CreateConfig, CreateTabFrame, CreateArea, CreateGUIEntry, EntryUpdate
|
||||||
|
|
||||||
-- "searchDB" gets populated when CreateConfig is called. The table holds
|
-- "searchDB" gets populated when CreateConfig is called. The table holds
|
||||||
-- information about the title, its parent buttons and the frame itself:
|
-- information about the title, its parent buttons and the frame itself:
|
||||||
@@ -29,19 +29,17 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
|
|||||||
end
|
end
|
||||||
end})
|
end})
|
||||||
|
|
||||||
function PrepareDropDownButton(index)
|
|
||||||
if index > _G.UIDROPDOWNMENU_MAXBUTTONS then
|
|
||||||
for i=1,3 do
|
|
||||||
local name = "DropDownList" .. i .. "Button" .. index
|
|
||||||
local parent = _G["DropDownList" .. i]
|
|
||||||
_G.UIDROPDOWNMENU_MAXBUTTONS = index
|
|
||||||
_G[name] = CreateFrame("Button", name, parent, "UIDropDownMenuButtonTemplate")
|
|
||||||
_G[name]:SetID(index)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function EntryUpdate()
|
function EntryUpdate()
|
||||||
|
-- detect and skip during dropdowns
|
||||||
|
local focus = GetMouseFocus()
|
||||||
|
if focus and focus.parent and focus.parent.menu then
|
||||||
|
if this.over then
|
||||||
|
this.tex:Hide()
|
||||||
|
this.over = nil
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if MouseIsOver(this) and not this.over then
|
if MouseIsOver(this) and not this.over then
|
||||||
this.tex:Show()
|
this.tex:Show()
|
||||||
this.over = true
|
this.over = true
|
||||||
@@ -336,140 +334,91 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
|
|||||||
|
|
||||||
-- use dropdown widget
|
-- use dropdown widget
|
||||||
if widget == "dropdown" and values then
|
if widget == "dropdown" and values then
|
||||||
if not pfUI.gui.ddc then pfUI.gui.ddc = 1 else pfUI.gui.ddc = pfUI.gui.ddc + 1 end
|
frame.input = CreateDropDownButton(nil, frame)
|
||||||
local name = pfUI.gui.ddc
|
frame.input:SetBackdrop(nil)
|
||||||
if named then name = named end
|
frame.input.menuframe:SetParent(pfUI.gui)
|
||||||
|
|
||||||
frame.input = CreateFrame("Frame", "pfUIDropDownMenu" .. name, frame, "UIDropDownMenuTemplate")
|
frame.input:SetPoint("RIGHT", frame, "RIGHT", 0, 0)
|
||||||
frame.input:ClearAllPoints()
|
frame.input:SetWidth(180)
|
||||||
frame.input:SetPoint("RIGHT", 16, -3)
|
frame.input:SetMenu(function()
|
||||||
|
local menu = {}
|
||||||
UIDropDownMenu_SetWidth(160, frame.input)
|
|
||||||
UIDropDownMenu_SetButtonWidth(160, frame.input)
|
|
||||||
UIDropDownMenu_JustifyText("RIGHT", frame.input)
|
|
||||||
UIDropDownMenu_Initialize(frame.input, function()
|
|
||||||
local info = {}
|
|
||||||
frame.input.values = _G.type(values)=="function" and values() or values
|
|
||||||
for i, k in pairs(frame.input.values) do
|
|
||||||
-- create new dropdown buttons when we reach the limit
|
|
||||||
PrepareDropDownButton(i)
|
|
||||||
|
|
||||||
|
for i, k in pairs(_G.type(values) == "function" and values() or values) do
|
||||||
|
local entry = {}
|
||||||
-- get human readable
|
-- get human readable
|
||||||
local value, text = strsplit(":", k)
|
local value, text = strsplit(":", k)
|
||||||
text = text or value
|
text = text or value
|
||||||
|
|
||||||
info.text = text
|
entry.text = text
|
||||||
info.checked = false
|
entry.func = function()
|
||||||
info.func = function()
|
|
||||||
UIDropDownMenu_SetSelectedID(frame.input, this:GetID(), 0)
|
|
||||||
UIDropDownMenu_SetText(this:GetText(), frame.input)
|
|
||||||
if category[config] ~= value then
|
if category[config] ~= value then
|
||||||
category[config] = value
|
category[config] = value
|
||||||
if ufunc then ufunc() else pfUI.gui.settingChanged = true end
|
if ufunc then ufunc() else pfUI.gui.settingChanged = true end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
UIDropDownMenu_AddButton(info)
|
|
||||||
if category[config] == value then
|
if category[config] == value then
|
||||||
frame.input.current = i
|
frame.input.current = i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
table.insert(menu, entry)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return menu
|
||||||
end)
|
end)
|
||||||
UIDropDownMenu_SetSelectedID(frame.input, frame.input.current)
|
|
||||||
|
|
||||||
SkinDropDown(frame.input)
|
frame.input:SetSelection(frame.input.current)
|
||||||
frame.input.backdrop:Hide()
|
|
||||||
frame.input.button.icon:SetParent(frame.input.button.backdrop)
|
|
||||||
|
|
||||||
-- hide shadows on wrong stratas
|
|
||||||
if frame.input.backdrop_shadow then
|
|
||||||
frame.input.backdrop_shadow:Hide()
|
|
||||||
frame.input.button.backdrop_shadow:Hide()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- use list widget
|
-- use list widget
|
||||||
if widget == "list" then
|
if widget == "list" then
|
||||||
if not pfUI.gui.ddc then pfUI.gui.ddc = 1 else pfUI.gui.ddc = pfUI.gui.ddc + 1 end
|
frame.del = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
|
||||||
local name = pfUI.gui.ddc
|
|
||||||
if named then name = named end
|
|
||||||
|
|
||||||
frame.input = CreateFrame("Frame", "pfUIDropDownMenu" .. name, frame, "UIDropDownMenuTemplate")
|
|
||||||
frame.input:ClearAllPoints()
|
|
||||||
frame.input:SetPoint("RIGHT" , -22, -3)
|
|
||||||
frame.category = category
|
|
||||||
frame.config = config
|
|
||||||
|
|
||||||
frame.input.Refresh = function()
|
|
||||||
local function CreateValues()
|
|
||||||
for i, val in pairs({strsplit("#", category[config])}) do
|
|
||||||
-- create new dropdown buttons when we reach the limit
|
|
||||||
PrepareDropDownButton(i)
|
|
||||||
|
|
||||||
UIDropDownMenu_AddButton({
|
|
||||||
["text"] = val,
|
|
||||||
["checked"] = false,
|
|
||||||
["func"] = function()
|
|
||||||
UIDropDownMenu_SetSelectedID(frame.input, this:GetID(), 0)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
UIDropDownMenu_Initialize(frame.input, CreateValues)
|
|
||||||
UIDropDownMenu_SetText("", frame.input)
|
|
||||||
end
|
|
||||||
|
|
||||||
frame.input:Refresh()
|
|
||||||
|
|
||||||
UIDropDownMenu_SetWidth(160, frame.input)
|
|
||||||
UIDropDownMenu_SetButtonWidth(160, frame.input)
|
|
||||||
UIDropDownMenu_JustifyText("RIGHT", frame.input)
|
|
||||||
UIDropDownMenu_SetSelectedID(frame.input, frame.input.current)
|
|
||||||
|
|
||||||
SkinDropDown(frame.input)
|
|
||||||
frame.input.backdrop:Hide()
|
|
||||||
frame.input.button.icon:SetParent(frame.input.button.backdrop)
|
|
||||||
|
|
||||||
frame.add = CreateFrame("Button", "pfUIDropDownMenu" .. name .. "Add", frame, "UIPanelButtonTemplate")
|
|
||||||
SkinButton(frame.add)
|
|
||||||
frame.add:SetWidth(18)
|
|
||||||
frame.add:SetHeight(18)
|
|
||||||
frame.add:SetPoint("RIGHT", -21, 0)
|
|
||||||
frame.add:GetFontString():SetPoint("CENTER", 1, 0)
|
|
||||||
frame.add:SetText("+")
|
|
||||||
frame.add:SetTextColor(.5,1,.5,1)
|
|
||||||
frame.add:SetScript("OnClick", function()
|
|
||||||
CreateQuestionDialog(T["New entry:"], function()
|
|
||||||
category[config] = category[config] .. "#" .. this:GetParent().input:GetText()
|
|
||||||
end, false, true)
|
|
||||||
end)
|
|
||||||
|
|
||||||
frame.del = CreateFrame("Button", "pfUIDropDownMenu" .. name .. "Del", frame, "UIPanelButtonTemplate")
|
|
||||||
SkinButton(frame.del)
|
SkinButton(frame.del)
|
||||||
frame.del:SetWidth(18)
|
frame.del:SetWidth(16)
|
||||||
frame.del:SetHeight(18)
|
frame.del:SetHeight(16)
|
||||||
frame.del:SetPoint("RIGHT", -2, 0)
|
frame.del:SetPoint("RIGHT", -4, 0)
|
||||||
frame.del:GetFontString():SetPoint("CENTER", 1, 0)
|
frame.del:GetFontString():SetPoint("CENTER", 1, 0)
|
||||||
frame.del:SetText("-")
|
frame.del:SetText("-")
|
||||||
frame.del:SetTextColor(1,.5,.5,1)
|
frame.del:SetTextColor(1,.5,.5,1)
|
||||||
frame.del:SetScript("OnClick", function()
|
frame.del:SetScript("OnClick", function()
|
||||||
local sel = UIDropDownMenu_GetSelectedID(frame.input)
|
local sel = frame.input:GetSelection()
|
||||||
local newconf = ""
|
local newconf = ""
|
||||||
for id, val in pairs({strsplit("#", category[config])}) do
|
for id, val in pairs({strsplit("#", category[config])}) do
|
||||||
if id ~= sel then newconf = newconf .. "#" .. val end
|
if id ~= sel then newconf = newconf .. "#" .. val end
|
||||||
end
|
end
|
||||||
category[config] = newconf
|
category[config] = newconf
|
||||||
frame.input:Refresh()
|
if ufunc then ufunc() else pfUI.gui.settingChanged = true end
|
||||||
|
frame.input:UpdateMenu()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- hide shadows on wrong stratas
|
frame.add = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
|
||||||
if frame.input.backdrop_shadow then
|
SkinButton(frame.add)
|
||||||
frame.input.backdrop_shadow:Hide()
|
frame.add:SetWidth(16)
|
||||||
frame.input.button.backdrop_shadow:Hide()
|
frame.add:SetHeight(16)
|
||||||
frame.add.backdrop_shadow:Hide()
|
frame.add:SetPoint("RIGHT", frame.del, "LEFT", -4, 0)
|
||||||
frame.del.backdrop_shadow:Hide()
|
frame.add:GetFontString():SetPoint("CENTER", 1, 0)
|
||||||
end
|
frame.add:SetText("+")
|
||||||
|
frame.add:SetTextColor(.5,1,.5,1)
|
||||||
|
frame.add:SetScript("OnClick", function()
|
||||||
|
CreateQuestionDialog(T["New entry:"], function()
|
||||||
|
category[config] = category[config] .. "#" .. this:GetParent().input:GetText()
|
||||||
|
if ufunc then ufunc() else pfUI.gui.settingChanged = true end
|
||||||
|
frame.input:UpdateMenu()
|
||||||
|
end, false, true)
|
||||||
|
end)
|
||||||
|
|
||||||
|
frame.input = CreateDropDownButton(nil, frame)
|
||||||
|
frame.input:SetBackdrop(nil)
|
||||||
|
frame.input.menuframe:SetParent(pfUI.gui)
|
||||||
|
frame.input:SetPoint("RIGHT", frame.add, "LEFT", -2, 0)
|
||||||
|
frame.input:SetWidth(140)
|
||||||
|
frame.input:SetMenu(function()
|
||||||
|
local menu = {}
|
||||||
|
for i, val in pairs({strsplit("#", category[config])}) do
|
||||||
|
table.insert(menu, { text = val })
|
||||||
|
end
|
||||||
|
return menu
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
@@ -1335,30 +1284,11 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
|
|||||||
header:GetParent().objectCount = header:GetParent().objectCount - 1
|
header:GetParent().objectCount = header:GetParent().objectCount - 1
|
||||||
header:SetHeight(20)
|
header:SetHeight(20)
|
||||||
|
|
||||||
local values = {}
|
CreateConfig(function() return end, T["Select profile"], C.global, "profile", "dropdown", function()
|
||||||
for name, config in pairs(pfUI_profiles) do table.insert(values, name) end
|
|
||||||
|
|
||||||
local function ReloadProfiles()
|
|
||||||
local oldval = UIDropDownMenu_GetText(pfUIDropDownMenuProfile)
|
|
||||||
local values = {}
|
local values = {}
|
||||||
local exists
|
for name, config in pairs(pfUI_profiles) do table.insert(values, name) end
|
||||||
|
|
||||||
for name, config in pairs(pfUI_profiles) do
|
|
||||||
table.insert(values, name)
|
|
||||||
if name == oldval then
|
|
||||||
exists = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not exists then
|
|
||||||
UIDropDownMenu_SetText("", pfUIDropDownMenuProfile)
|
|
||||||
UIDropDownMenu_SetSelectedID(pfUIDropDownMenuProfile, 0, 0)
|
|
||||||
end
|
|
||||||
|
|
||||||
return values
|
return values
|
||||||
end
|
end, false, "Profile")
|
||||||
|
|
||||||
CreateConfig(function() return end, T["Select profile"], C.global, "profile", "dropdown", ReloadProfiles, false, "Profile")
|
|
||||||
|
|
||||||
-- load profile
|
-- load profile
|
||||||
CreateConfig(nil, T["Load profile"], C.global, "profile", "button", function()
|
CreateConfig(nil, T["Load profile"], C.global, "profile", "button", function()
|
||||||
@@ -1378,7 +1308,6 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
|
|||||||
if C.global.profile and pfUI_profiles[C.global.profile] then
|
if C.global.profile and pfUI_profiles[C.global.profile] then
|
||||||
CreateQuestionDialog(T["Delete profile"] .. " '|cff33ffcc" .. C.global.profile .. "|r'?", function()
|
CreateQuestionDialog(T["Delete profile"] .. " '|cff33ffcc" .. C.global.profile .. "|r'?", function()
|
||||||
pfUI_profiles[C.global.profile] = nil
|
pfUI_profiles[C.global.profile] = nil
|
||||||
ReloadProfiles()
|
|
||||||
this:GetParent():Hide()
|
this:GetParent():Hide()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -1409,7 +1338,6 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
|
|||||||
if profile and profile ~= "" then
|
if profile and profile ~= "" then
|
||||||
pfUI_profiles[profile] = CopyTable(C)
|
pfUI_profiles[profile] = CopyTable(C)
|
||||||
this:GetParent():Hide()
|
this:GetParent():Hide()
|
||||||
ReloadProfiles()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end, false, true)
|
end, false, true)
|
||||||
|
|||||||
Reference in New Issue
Block a user