The problem being the dropdown menu is a common widget that gets updated depending on the initialise function.
This should work but because it's hooking the dropdown menus OnHide you never know what someone else might be doing.
This is the same code duplicated to create two dropdowns. The initialise function checks which menu (based on UIDropDownMenuTemplate) it is and changes the backdrop colour.
It doesn't do sub-menus...
Lua Code:
HWGA = {}
HWGA.Checkboxes = {
title = "Select checkboxes",
menu = {
Key_1 = "Value 1",
Key_2 = "Value 2",
Key_3 = "Value 3",
Key_4 = "Value 4",
Key_5 = "Value 5",
}
}
HWGA.ActiveCheckboxes = {}
function HWGADropDown_SetFlag(self, flag_name)
if HWGA.ActiveCheckboxes[flag_name] then
HWGA.ActiveCheckboxes[flag_name] = nil;
self.checked = false;
else
HWGA.ActiveCheckboxes[flag_name] = true;
self.checked = true;
end
end
function HWGADropDown_Initialize(self)
local info = UIDropDownMenu_CreateInfo();
info.text = HWGA.Checkboxes .title;
info.isTitle = true;
info.notCheckable = true;
UIDropDownMenu_AddButton(info);
for flag_name, flag_value in pairs(HWGA.Checkboxes.menu) do
info = UIDropDownMenu_CreateInfo();
info.text = flag_name;
info.value = flag_value;
info.checked = HWGA.ActiveCheckboxes[flag_name];
info.func = HWGADropDown_SetFlag;
info.arg1 = flag_name;
info.isNotRadio = true;
info.keepShownOnClick = true;
UIDropDownMenu_AddButton(info);
end
-- Check which menu we are and change the backdrop colour (or not) accordingly
if self == HereWeGoAgainMenuDropDown then
DropDownList1MenuBackdrop:SetBackdropColor(1, 0, 0)
end
end
local drp_dwn_button = CreateFrame("Button", "HereWeGoAgainDropDownButton", UIParent, "TooltipBackdropTemplate");
drp_dwn_button:SetSize(200, 40);
drp_dwn_button:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
drp_dwn_button:SetScript("OnMouseDown", function(self) ToggleDropDownMenu(1, nil, HereWeGoAgainMenuDropDown, self, 0, 0) end);
local text = drp_dwn_button:CreateFontString(nil, "OVERLAY", "GameFontNormal");
text:SetPoint("CENTER", drp_dwn_button, "CENTER", 0, 0);
text:SetText(HWGA.Checkboxes.title);
local drp_dwn_frame = CreateFrame("Frame", "HereWeGoAgainMenuDropDown", nil, "UIDropDownMenuTemplate");
UIDropDownMenu_Initialize(drp_dwn_frame, HWGADropDown_Initialize, "MENU")
local drp_dwn_button2 = CreateFrame("Button", "HereWeGoAgainDropDownButton", UIParent, "TooltipBackdropTemplate");
drp_dwn_button2:SetSize(200, 40);
drp_dwn_button2:SetPoint("LEFT", drp_dwn_button, "RIGHT", 5, 0);
drp_dwn_button2:SetScript("OnMouseDown", function(self) ToggleDropDownMenu(1, nil, HereWeGoAgainMenuDropDown2, self, 0, 0) end);
local text = drp_dwn_button:CreateFontString(nil, "OVERLAY", "GameFontNormal");
text:SetPoint("CENTER", drp_dwn_button, "CENTER", 0, 0);
text:SetText(HWGA.Checkboxes.title);
local drp_dwn_frame2 = CreateFrame("Frame", "HereWeGoAgainMenuDropDown2", nil, "UIDropDownMenuTemplate");
UIDropDownMenu_Initialize(drp_dwn_frame2, HWGADropDown_Initialize, "MENU")
---- Hook DropDownList1s OnHide
DropDownList1MenuBackdrop:HookScript("OnHide", function(self)
self:SetBackdropColor(0, 0, 0)
end)
-- Reset the BackdropColor because the first UIDropDownMenu_Initialize will have set it to red
DropDownList1MenuBackdrop:SetBackdropColor(0, 0, 0)
The
if self == HereWeGoAgainMenuDropDown then check shouldn't be needed if the function was only being used on a single frame (UIDropDownMenu_Initialize(...) call), just set the required BackdropColor