Redesigned dropdowns
This commit is contained in:
parent
9423171d54
commit
cfdef3cc26
2 changed files with 36 additions and 24 deletions
53
UI.lua
53
UI.lua
|
|
@ -29,7 +29,7 @@ local function BuildSkillOptions()
|
|||
return options
|
||||
end
|
||||
|
||||
-- Helper: Create a modern dropdown (WowStyle1DropdownTemplate)
|
||||
-- Helper: Create a flat dark dropdown with optional label (reuses shared CreateFlatDropdown)
|
||||
local function CreateDropdown(parent, name, labelText, options, defaultIndex, onSelect, labelFont)
|
||||
local container = CreateFrame("Frame", nil, parent)
|
||||
container:SetHeight(ROW_HEIGHT)
|
||||
|
|
@ -44,28 +44,32 @@ local function CreateDropdown(parent, name, labelText, options, defaultIndex, on
|
|||
|
||||
local selectedIndex = defaultIndex or 1
|
||||
|
||||
local dropdown = CreateFrame("DropdownButton", name, container, "WowStyle1DropdownTemplate")
|
||||
local dropdown = AltSystem.CreateFlatDropdown(name, container, 190)
|
||||
if label then
|
||||
dropdown:SetPoint("RIGHT", container, "RIGHT", 0, 0)
|
||||
else
|
||||
dropdown:SetPoint("LEFT", container, "LEFT", 0, 0)
|
||||
end
|
||||
dropdown:SetWidth(190)
|
||||
|
||||
dropdown:SetupMenu(function(dropdown, rootDescription)
|
||||
-- Set initial label text
|
||||
if options[selectedIndex] then
|
||||
dropdown.label:SetText(options[selectedIndex].text)
|
||||
end
|
||||
|
||||
dropdown:SetupMenu(function(owner, rootDescription)
|
||||
for i, option in ipairs(options) do
|
||||
rootDescription:CreateRadio(
|
||||
option.text,
|
||||
function(data)
|
||||
return data == selectedIndex
|
||||
function()
|
||||
return i == selectedIndex
|
||||
end,
|
||||
function(data)
|
||||
selectedIndex = data
|
||||
function()
|
||||
selectedIndex = i
|
||||
dropdown.label:SetText(option.text)
|
||||
if onSelect then
|
||||
onSelect(data, options[data])
|
||||
onSelect(i, option)
|
||||
end
|
||||
end,
|
||||
i
|
||||
end
|
||||
)
|
||||
end
|
||||
end)
|
||||
|
|
@ -74,6 +78,9 @@ local function CreateDropdown(parent, name, labelText, options, defaultIndex, on
|
|||
return selectedIndex
|
||||
end, function(idx)
|
||||
selectedIndex = idx
|
||||
if options[idx] then
|
||||
dropdown.label:SetText(options[idx].text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -573,24 +580,28 @@ function AltSystem:RefreshSkillDropdown()
|
|||
-- Rebuild the dropdown menu with the new skill list
|
||||
if AltSystem.SkillDropdown then
|
||||
local skillOptions = BuildSkillOptions()
|
||||
AltSystem.SkillDropdown:SetupMenu(function(dropdown, rootDescription)
|
||||
-- Update the displayed label text
|
||||
if skillOptions[newIndex] then
|
||||
AltSystem.SkillDropdown.label:SetText(skillOptions[newIndex].text)
|
||||
end
|
||||
AltSystem.SkillDropdown:SetupMenu(function(owner, rootDescription)
|
||||
for i, option in ipairs(skillOptions) do
|
||||
rootDescription:CreateRadio(
|
||||
option.text,
|
||||
function(data)
|
||||
return data == AltSystem.State.selectedSkillIndex
|
||||
function()
|
||||
return i == AltSystem.State.selectedSkillIndex
|
||||
end,
|
||||
function(data)
|
||||
AltSystem.State.selectedSkillIndex = data
|
||||
AltSystem.State.selectedSkillName = AltSystem.Data.Skills[data] and AltSystem.Data.Skills[data].name or nil
|
||||
function()
|
||||
AltSystem.State.selectedSkillIndex = i
|
||||
AltSystem.State.selectedSkillName = AltSystem.Data.Skills[i] and AltSystem.Data.Skills[i].name or nil
|
||||
AltSystem.SkillDropdown.label:SetText(option.text)
|
||||
if AltSystem.SetSkillIndex then
|
||||
AltSystem.SetSkillIndex(data)
|
||||
AltSystem.SetSkillIndex(i)
|
||||
end
|
||||
if AltSystem.UpdateSkillWarning then
|
||||
AltSystem.UpdateSkillWarning(data)
|
||||
AltSystem.UpdateSkillWarning(i)
|
||||
end
|
||||
end,
|
||||
i
|
||||
end
|
||||
)
|
||||
end
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue