WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Background of DropDown menu (https://www.wowinterface.com/forums/showthread.php?t=59128)

Limbopo 05-13-22 01:42 PM

Background of DropDown menu
 
Hello.
For example we have this dropdown menu.


Lua Code:
  1. HWGA = {}
  2.  
  3. HWGA.Checkboxes = {
  4.    title = "Select checkboxes",
  5.    menu = {
  6.       Key_1 = "Value 1",
  7.       Key_2 = "Value 2",
  8.       Key_3 = "Value 3",
  9.       Key_4 = "Value 4",
  10.       Key_5 = "Value 5",
  11.    }
  12. }
  13.  
  14. HWGA.ActiveCheckboxes = {}
  15.  
  16.  
  17. function HWGADropDown_SetFlag(self, flag_name)
  18.    if HWGA.ActiveCheckboxes[flag_name] then
  19.       HWGA.ActiveCheckboxes[flag_name] = nil;
  20.       self.checked = false;
  21.    else
  22.       HWGA.ActiveCheckboxes[flag_name] = true;
  23.       self.checked = true;
  24.    end
  25. end
  26.  
  27. function HWGADropDown_Initialize(self)
  28.    local info = UIDropDownMenu_CreateInfo();
  29.    
  30.    info.text = HWGA.Checkboxes .title;
  31.    info.isTitle = true;
  32.    info.notCheckable = true;
  33.    UIDropDownMenu_AddButton(info);
  34.    
  35.    for flag_name, flag_value in pairs(HWGA.Checkboxes.menu) do
  36.       info = UIDropDownMenu_CreateInfo();
  37.       info.text = flag_name;
  38.       info.value = flag_value;
  39.       info.checked = HWGA.ActiveCheckboxes[flag_name];
  40.       info.func = HWGADropDown_SetFlag;
  41.       info.arg1 = flag_name;
  42.       info.isNotRadio = true;
  43.       info.keepShownOnClick = true;
  44.       UIDropDownMenu_AddButton(info);
  45.    end
  46. end
  47.  
  48. local drp_dwn_button = CreateFrame("Button", "HereWeGoAgainDropDownButton", UIParent, "TooltipBackdropTemplate");
  49. drp_dwn_button:SetSize(200, 40);
  50. drp_dwn_button:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
  51. drp_dwn_button:SetScript("OnMouseDown", function(self) ToggleDropDownMenu(1, nil, HereWeGoAgainMenuDropDown, self, 0, 0) end);
  52.  
  53. local text = drp_dwn_button:CreateFontString(nil, "OVERLAY", "GameFontNormal");
  54. text:SetPoint("CENTER", drp_dwn_button, "CENTER", 0, 0);
  55. text:SetText(HWGA.Checkboxes.title);
  56.  
  57. local drp_dwn_frame = CreateFrame("Frame", "HereWeGoAgainMenuDropDown", nil, "UIDropDownMenuTemplate");
  58. UIDropDownMenu_Initialize(drp_dwn_frame, HWGADropDown_Initialize, "MENU")

Is there is any simple way to change background color/opacity only for this dropdown?
In example, I want this:


I've found only one way to do it, but it changes every dropdown in a game, because it's in dependecies with DropDownList:
Lua Code:
  1. local BlackLayout = {
  2.         ["TopRightCorner"] = {atlas = "Tooltip-NineSlice-CornerTopRight"},
  3.         ["TopLeftCorner"] = {atlas = "Tooltip-NineSlice-CornerTopLeft"},
  4.         ["BottomLeftCorner"] = {atlas = "Tooltip-NineSlice-CornerBottomLeft"},
  5.         ["BottomRightCorner"] = {atlas = "Tooltip-NineSlice-CornerBottomRight"},
  6.         ["TopEdge"] = {atlas = "_Tooltip-NineSlice-EdgeTop"},
  7.         ["BottomEdge"] = {atlas = "_Tooltip-NineSlice-EdgeBottom"},
  8.         ["LeftEdge"] = {atlas = "!Tooltip-NineSlice-EdgeLeft"},
  9.         ["RightEdge"] = {atlas = "!Tooltip-NineSlice-EdgeRight"},
  10.         ["Center"] = {layer = "BACKGROUND", atlas = "ui-frame-party-backgroundtile", x = -4, y = 4, x1 = 4, y1 = -4}
  11.     }
  12.  
  13.     NineSliceUtil.ApplyLayout(DropDownList1MenuBackdrop, BlackLayout )

I didn't find any similar threads, but it seems to me that this question was of interest to many people.

I've tried SetBackdrop/different layouts, but it is not working. What I'm doing wrong?

Xrystal 05-14-22 07:07 AM

Hopefully someone has successfully done what you want and get throw suggestions on what might need changing for you but based on their description of the nineslicelayout system it sounds like it is designed to work with all frames of that type for theming purposes.

`Nine-slice utility for creating themed background frames without rewriting a lot of boilerplate code.`

Fizzlemizz 05-14-22 11:44 AM

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:
  1. HWGA = {}
  2.      
  3.     HWGA.Checkboxes = {
  4.        title = "Select checkboxes",
  5.        menu = {
  6.           Key_1 = "Value 1",
  7.           Key_2 = "Value 2",
  8.           Key_3 = "Value 3",
  9.           Key_4 = "Value 4",
  10.           Key_5 = "Value 5",
  11.        }
  12.     }
  13.      
  14.     HWGA.ActiveCheckboxes = {}
  15.      
  16.      
  17.     function HWGADropDown_SetFlag(self, flag_name)
  18.        if HWGA.ActiveCheckboxes[flag_name] then
  19.           HWGA.ActiveCheckboxes[flag_name] = nil;
  20.           self.checked = false;
  21.        else
  22.           HWGA.ActiveCheckboxes[flag_name] = true;
  23.           self.checked = true;
  24.        end
  25.     end
  26.      
  27.     function HWGADropDown_Initialize(self)
  28.        local info = UIDropDownMenu_CreateInfo();
  29.        
  30.        info.text = HWGA.Checkboxes .title;
  31.        info.isTitle = true;
  32.        info.notCheckable = true;
  33.        UIDropDownMenu_AddButton(info);
  34.        
  35.        for flag_name, flag_value in pairs(HWGA.Checkboxes.menu) do
  36.           info = UIDropDownMenu_CreateInfo();
  37.           info.text = flag_name;
  38.           info.value = flag_value;
  39.           info.checked = HWGA.ActiveCheckboxes[flag_name];
  40.           info.func = HWGADropDown_SetFlag;
  41.           info.arg1 = flag_name;
  42.           info.isNotRadio = true;
  43.           info.keepShownOnClick = true;
  44.           UIDropDownMenu_AddButton(info);
  45.        end
  46.  
  47.        -- Check which menu we are and change the backdrop colour (or not) accordingly
  48.        if self == HereWeGoAgainMenuDropDown then
  49.           DropDownList1MenuBackdrop:SetBackdropColor(1, 0, 0)
  50.        end
  51.     end
  52.      
  53.     local drp_dwn_button = CreateFrame("Button", "HereWeGoAgainDropDownButton", UIParent, "TooltipBackdropTemplate");
  54.     drp_dwn_button:SetSize(200, 40);
  55.     drp_dwn_button:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
  56.     drp_dwn_button:SetScript("OnMouseDown", function(self) ToggleDropDownMenu(1, nil, HereWeGoAgainMenuDropDown, self, 0, 0) end);
  57.      
  58.     local text = drp_dwn_button:CreateFontString(nil, "OVERLAY", "GameFontNormal");
  59.     text:SetPoint("CENTER", drp_dwn_button, "CENTER", 0, 0);
  60.     text:SetText(HWGA.Checkboxes.title);
  61.      
  62.     local drp_dwn_frame = CreateFrame("Frame", "HereWeGoAgainMenuDropDown", nil, "UIDropDownMenuTemplate");
  63.     UIDropDownMenu_Initialize(drp_dwn_frame, HWGADropDown_Initialize, "MENU")
  64.  
  65.     local drp_dwn_button2 = CreateFrame("Button", "HereWeGoAgainDropDownButton", UIParent, "TooltipBackdropTemplate");
  66.     drp_dwn_button2:SetSize(200, 40);
  67.     drp_dwn_button2:SetPoint("LEFT", drp_dwn_button, "RIGHT", 5, 0);
  68.     drp_dwn_button2:SetScript("OnMouseDown", function(self) ToggleDropDownMenu(1, nil, HereWeGoAgainMenuDropDown2, self, 0, 0) end);
  69.      
  70.     local text = drp_dwn_button:CreateFontString(nil, "OVERLAY", "GameFontNormal");
  71.     text:SetPoint("CENTER", drp_dwn_button, "CENTER", 0, 0);
  72.     text:SetText(HWGA.Checkboxes.title);
  73.      
  74.     local drp_dwn_frame2 = CreateFrame("Frame", "HereWeGoAgainMenuDropDown2", nil, "UIDropDownMenuTemplate");
  75.     UIDropDownMenu_Initialize(drp_dwn_frame2, HWGADropDown_Initialize, "MENU")
  76.  
  77.     ---- Hook DropDownList1s OnHide
  78.     DropDownList1MenuBackdrop:HookScript("OnHide", function(self)
  79.         self:SetBackdropColor(0, 0, 0)
  80.     end)
  81.  
  82.     -- Reset the BackdropColor because the first UIDropDownMenu_Initialize will have set it to red
  83.     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

Limbopo 05-19-22 07:29 PM

I got that trick.Thank you for explanations


All times are GMT -6. The time now is 07:56 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI