diff --git a/Titan/libs/!LibUIDropDownMenu/!LibUIDropDownMenu.toc b/Titan/libs/!LibUIDropDownMenu/!LibUIDropDownMenu.toc index dcb9c35..0828d84 100755 --- a/Titan/libs/!LibUIDropDownMenu/!LibUIDropDownMenu.toc +++ b/Titan/libs/!LibUIDropDownMenu/!LibUIDropDownMenu.toc @@ -1,7 +1,7 @@ -## Interface: 80100 +## Interface: 90002 ## Title: Lib: UIDropDownMenu ## Notes: A Replacement for standard UIDropDownMenu -## Version: v2.00.8010028833 +## Version: v4.00.9000236639 ## X-Category: Libraries ## X-Website: https://www.wowace.com/projects/libuidropdownmenu ## OptionalDeps: LibStub @@ -9,4 +9,4 @@ #@no-lib-strip@ LibStub\LibStub.lua #@end-no-lib-strip@ -LibUIDropDownMenu\LibUIDropDownMenu.xml +LibUIDropDownMenu\LibUIDropDownMenu.lua diff --git a/Titan/libs/!LibUIDropDownMenu/Docs/Readme.txt b/Titan/libs/!LibUIDropDownMenu/Docs/Readme.txt index 7e23b95..53674f6 100755 --- a/Titan/libs/!LibUIDropDownMenu/Docs/Readme.txt +++ b/Titan/libs/!LibUIDropDownMenu/Docs/Readme.txt @@ -1,3 +1,5 @@ +$Id: Readme.txt 64 2020-11-18 13:13:15Z arithmandar $ + == About == Standard UIDropDownMenu global functions using protected frames and causing taints when used by third-party addons. But it is possible to avoid taints by using same @@ -11,11 +13,61 @@ and functions renamed to: * functions: "L_" added at the start == How to use it (for addon developer) == -* Embed LibUIDropDownMenu to your addon, you can specify to the folder to - LibUIDropDownMenu\LibUIDropDownMenu if you feel this keep the folder cleaner. -* Add LibUIDropDownMenu.xml to your toc or your embeds.xml / libs.xml. -* If your addon doesn't embed LibStub, you will need it. -* Like ordinal code for UIDropDownMenu with "L_" instead. +=== Initial Preparation === +Assuming your addon is using all the UIDropDownMenu functions from the WoW's +built in function calls, then it is suggested that you have below preparation +in your lua codes: + local LibDD = LibStub:GetLibrary("LibUIDropDownMenu-4.0") + +=== Function Call Replacement === +Depends on which UIDropDownMenu's function calls you have used in your addon, +you will need below similar replacement: + + UIDropDownMenu_Initialize => LibDD:UIDropDownMenu_Initialize + UIDropDownMenu_CreateInfo => LibDD:UIDropDownMenu_CreateInfo + UIDropDownMenu_AddButton => LibDD:UIDropDownMenu_AddButton + + UIDropDownMenu_AddSeparator => LibDD:UIDropDownMenu_AddSeparator + UIDropDownMenu_AddSpace=> LibDD:UIDropDownMenu_AddSpace + + UIDropDownMenu_SetSelectedValue => LibDD:UIDropDownMenu_SetSelectedValue + UIDropDownMenu_SetSelectedName=> LibDD:UIDropDownMenu_SetSelectedName + + UIDropDownMenu_SetSelectedID => LibDD:UIDropDownMenu_SetSelectedID + UIDropDownMenu_SetWidth => LibDD:UIDropDownMenu_SetWidth + + CloseDropDownMenus => LibDD:CloseDropDownMenus + +=== Creating new UIDropDownMenu === +Traditionally you will either create a new frame in your lua codes or with +XML by setting the frame to inherit from "UIDropDownMenuTemplate". + +By using this library, you will need to create your menu from like below: + local frame = LibDD:Create_UIDropDownMenu("MyDropDownMenu", parent_frame) + +== Button Name == +As you (the developers) might be aware that at some point you might need to +manipulate the dropdowns by accessing the button names. For example, you have +multiple levels of menus and you would like to hide or show some level's menu +button. In that case, you need to make sure you also revise the button name +used in your original codes when you are migrating to use LibUIDropDownMenu. + + "L_DropDownList"..i + +Example: + + for i = 1, L_UIDROPDOWNMENU_MAXLEVELS, 1 do + dropDownList = _G["L_DropDownList"..i]; + if ( i >= L_UIDROPDOWNMENU_MENU_LEVEL or frame ~= L_UIDROPDOWNMENU_OPEN_MENU ) then + dropDownList.numButtons = 0; + dropDownList.maxWidth = 0; + for j=1, L_UIDROPDOWNMENU_MAXBUTTONS, 1 do + button = _G["L_DropDownList"..i.."Button"..j]; + button:Hide(); + end + dropDownList:Hide(); + end + end == Constants == * L_UIDROPDOWNMENU_MINBUTTONS @@ -32,60 +84,60 @@ and functions renamed to: * L_OPEN_DROPDOWNMENUS == Functions == -* L_EasyMenu -* L_EasyMenu_Initialize - -* L_UIDropDownMenuDelegate_OnAttributeChanged -* L_UIDropDownMenu_InitializeHelper -* L_UIDropDownMenu_Initialize -* L_UIDropDownMenu_SetInitializeFunction -* L_UIDropDownMenu_RefreshDropDownSize -* L_UIDropDownMenu_OnUpdate -* L_UIDropDownMenu_StartCounting -* L_UIDropDownMenu_StopCounting -* L_UIDropDownMenu_CheckAddCustomFrame -* L_UIDropDownMenu_CreateInfo -* L_UIDropDownMenu_CreateFrames -* L_UIDropDownMenu_AddSeparator -* L_UIDropDownMenu_AddButton -* L_UIDropDownMenu_AddSeparator -* L_UIDropDownMenu_GetMaxButtonWidth -* L_UIDropDownMenu_GetButtonWidth -* L_UIDropDownMenu_Refresh -* L_UIDropDownMenu_RefreshAll -* L_UIDropDownMenu_RegisterCustomFrame -* L_UIDropDownMenu_SetIconImage -* L_UIDropDownMenu_SetSelectedName -* L_UIDropDownMenu_SetSelectedValue -* L_UIDropDownMenu_SetSelectedID -* L_UIDropDownMenu_GetSelectedName -* L_UIDropDownMenu_GetSelectedID -* L_UIDropDownMenu_GetSelectedValue -* L_UIDropDownMenuButton_OnClick -* L_HideDropDownMenu -* L_ToggleDropDownMenu -* L_CloseDropDownMenus -* L_UIDropDownMenu_OnHide -* L_UIDropDownMenu_SetWidth -* L_UIDropDownMenu_SetButtonWidth -* L_UIDropDownMenu_SetText -* L_UIDropDownMenu_GetText -* L_UIDropDownMenu_ClearAll -* L_UIDropDownMenu_JustifyText -* L_UIDropDownMenu_SetAnchor -* L_UIDropDownMenu_GetCurrentDropDown -* L_UIDropDownMenuButton_GetChecked -* L_UIDropDownMenuButton_GetName -* L_UIDropDownMenuButton_OpenColorPicker -* L_UIDropDownMenu_DisableButton -* L_UIDropDownMenu_EnableButton -* L_UIDropDownMenu_SetButtonText -* L_UIDropDownMenu_SetButtonNotClickable -* L_UIDropDownMenu_SetButtonClickable -* L_UIDropDownMenu_DisableDropDown -* L_UIDropDownMenu_EnableDropDown -* L_UIDropDownMenu_IsEnabled -* L_UIDropDownMenu_GetValue +* lib:EasyMenu +* lib:EasyMenu_Initialize + +* lib:UIDropDownMenuDelegate_OnAttributeChanged +* lib:UIDropDownMenu_InitializeHelper +* lib:UIDropDownMenu_Initialize +* lib:UIDropDownMenu_SetInitializeFunction +* lib:UIDropDownMenu_RefreshDropDownSize +* lib:UIDropDownMenu_OnUpdate +* lib:UIDropDownMenu_StartCounting +* lib:UIDropDownMenu_StopCounting +* lib:UIDropDownMenu_CheckAddCustomFrame +* lib:UIDropDownMenu_CreateInfo +* lib:UIDropDownMenu_CreateFrames +* lib:UIDropDownMenu_AddSeparator +* lib:UIDropDownMenu_AddButton +* lib:UIDropDownMenu_AddSeparator +* lib:UIDropDownMenu_GetMaxButtonWidth +* lib:UIDropDownMenu_GetButtonWidth +* lib:UIDropDownMenu_Refresh +* lib:UIDropDownMenu_RefreshAll +* lib:UIDropDownMenu_RegisterCustomFrame +* lib:UIDropDownMenu_SetIconImage +* lib:UIDropDownMenu_SetSelectedName +* lib:UIDropDownMenu_SetSelectedValue +* lib:UIDropDownMenu_SetSelectedID +* lib:UIDropDownMenu_GetSelectedName +* lib:UIDropDownMenu_GetSelectedID +* lib:UIDropDownMenu_GetSelectedValue +* lib:UIDropDownMenuButton_OnClick +* lib:HideDropDownMenu +* lib:ToggleDropDownMenu +* lib:CloseDropDownMenus +* lib:UIDropDownMenu_OnHide +* lib:UIDropDownMenu_SetWidth +* lib:UIDropDownMenu_SetButtonWidth +* lib:UIDropDownMenu_SetText +* lib:UIDropDownMenu_GetText +* lib:UIDropDownMenu_ClearAll +* lib:UIDropDownMenu_JustifyText +* lib:UIDropDownMenu_SetAnchor +* lib:UIDropDownMenu_GetCurrentDropDown +* lib:UIDropDownMenuButton_GetChecked +* lib:UIDropDownMenuButton_GetName +* lib:UIDropDownMenuButton_OpenColorPicker +* lib:UIDropDownMenu_DisableButton +* lib:UIDropDownMenu_EnableButton +* lib:UIDropDownMenu_SetButtonText +* lib:UIDropDownMenu_SetButtonNotClickable +* lib:UIDropDownMenu_SetButtonClickable +* lib:UIDropDownMenu_DisableDropDown +* lib:UIDropDownMenu_EnableDropDown +* lib:UIDropDownMenu_IsEnabled +* lib:UIDropDownMenu_GetValue == List of button attributes == * info.text = [STRING] -- The text of the button diff --git a/Titan/libs/!LibUIDropDownMenu/Docs/Revision.txt b/Titan/libs/!LibUIDropDownMenu/Docs/Revision.txt index 5b8596c..9e29829 100755 --- a/Titan/libs/!LibUIDropDownMenu/Docs/Revision.txt +++ b/Titan/libs/!LibUIDropDownMenu/Docs/Revision.txt @@ -1,7 +1,43 @@ -$Id: Revision.txt 41 2018-12-26 17:41:59Z arith $ +$Id: Revision.txt 66 2020-11-22 15:25:00Z arithmandar $ + Revision History: ================= +v4.00.9000236639 (2020/11/22) +----------------------------- +- Toc update to suppport WoW 9.0.2 +- LibUIDropDownMenu + - Set major version to 4.0 + - Migrate all global functions to be under library tables + - Insert "L_DropDownList1" and "L_DropDownList2" to global UIMenus + - UIDropDownMenu_HandleGlobalMouseEvent (thanks to SLOKnightFall) +- LibEasyMenu + - Move function calls to under LibUIDropDownMenu and under library tables +- LibUIDropDownMenuTemplates + - Move codes to under LibUIDropDownMenu so that thet can de under one single library + +v3.02.9000136272.01 (2020/10/20) +----------------------------- +- Fixed version detection while setting ColorSwatch's backdrop template. It should now be correctly detecting the retail (as well as ShadowLands) version + +v3.02.9000136272 (2020/10/18) +----------------------------- +- Update to sync with 9.0.1 build 36272 +- ToC update to support WoW 9.0.1 + +v3.01.9000135522 (2020/09/07) +----------------------------- +- Updated Backdrop's handling + +v3.00.9000135522 (2020/08/19) +----------------------------- +- Shadowlands support and backward compatibility for both WoW classic and BFA + +v2.01.8020031429 (2019/08/12) +----------------------------- +- Update to sync with 8.2.0 build 31429 +- ToC update + v2.00.8010028833 (2018/12/27) ----------------------------- - Migrate template to Lua function call diff --git a/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibEasyMenu.lua b/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibEasyMenu.lua index 5cf69f6..731b6bb 100755 --- a/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibEasyMenu.lua +++ b/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibEasyMenu.lua @@ -1,4 +1,13 @@ ---$Id: LibEasyMenu.lua 30 2018-04-24 06:44:39Z arith $ +--$Id: LibEasyMenu.lua 64 2020-11-18 13:13:15Z arithmandar $ +-- ////////////////////////////////////////////////////////////// +-- Notes: +-- Functions have been moved to under LibUIDropDownMenu.lua +-- New function calls are as below: +-- +-- - lib:EasyMenu(menuList, menuFrame, anchor, x, y, displayMode, autoHideDelay ) +-- - lib:EasyMenu_Initialize( frame, level, menuList ) +-- +-- ////////////////////////////////////////////////////////////// -- Simplified Menu Display System -- This is a basic system for displaying a menu from a structure table. -- @@ -14,34 +23,22 @@ -- autoHideDelay - how long until the menu disappears -- -- --- ---------------------------------------------------------------------------- --- Localized Lua globals. --- ---------------------------------------------------------------------------- -local _G = getfenv(0) --- ---------------------------------------------------------------------------- -local MAJOR_VERSION = "LibEasyMenu" -local MINOR_VERSION = 90000 + tonumber(("$Rev: 30 $"):match("%d+")) - -local LibStub = _G.LibStub -if not LibStub then error(MAJOR_VERSION .. " requires LibStub.") end -local Lib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION) -if not Lib then return end - -function L_EasyMenu(menuList, menuFrame, anchor, x, y, displayMode, autoHideDelay ) +--[[ +function EasyMenu(menuList, menuFrame, anchor, x, y, displayMode, autoHideDelay ) if ( displayMode == "MENU" ) then menuFrame.displayMode = displayMode; end - L_UIDropDownMenu_Initialize(menuFrame, L_EasyMenu_Initialize, displayMode, nil, menuList); - L_ToggleDropDownMenu(1, nil, menuFrame, anchor, x, y, menuList, nil, autoHideDelay); + UIDropDownMenu_Initialize(menuFrame, EasyMenu_Initialize, displayMode, nil, menuList); + ToggleDropDownMenu(1, nil, menuFrame, anchor, x, y, menuList, nil, autoHideDelay); end -function L_EasyMenu_Initialize( frame, level, menuList ) +function EasyMenu_Initialize( frame, level, menuList ) for index = 1, #menuList do local value = menuList[index] if (value.text) then value.index = index; - L_UIDropDownMenu_AddButton( value, level ); + UIDropDownMenu_AddButton( value, level ); end end end - +]] diff --git a/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.lua b/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.lua index 68d1f6e..c2b18f2 100755 --- a/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.lua +++ b/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.lua @@ -1,25 +1,48 @@ --- $Id: LibUIDropDownMenu.lua 40 2018-12-23 16:14:03Z arith $ +-- $Id: LibUIDropDownMenu.lua 65 2020-11-18 14:13:49Z arithmandar $ -- ---------------------------------------------------------------------------- -- Localized Lua globals. -- ---------------------------------------------------------------------------- local _G = getfenv(0) local tonumber, type, string, table = _G.tonumber, _G.type, _G.string, _G.table +local tinsert = table.insert local strsub, strlen, strmatch, gsub = _G.strsub, _G.strlen, _G.strmatch, _G.gsub local max, match = _G.max, _G.match local securecall, issecure = _G.securecall, _G.issecure local wipe = table.wipe -- WoW local CreateFrame, GetCursorPosition, GetCVar, GetScreenHeight, GetScreenWidth, PlaySound = _G.CreateFrame, _G.GetCursorPosition, _G.GetCVar, _G.GetScreenHeight, _G.GetScreenWidth, _G.PlaySound +local GetBuildInfo = _G.GetBuildInfo +local GameTooltip, GetAppropriateTooltip, tooltip, GetValueOrCallFunction +local CloseMenus, ShowUIPanel = _G.CloseMenus, _G.ShowUIPanel +local GameTooltip_SetTitle, GameTooltip_AddInstructionLine, GameTooltip_AddNormalLine, GameTooltip_AddColoredLine = _G.GameTooltip_SetTitle, _G.GameTooltip_AddInstructionLine, _G.GameTooltip_AddNormalLine, _G.GameTooltip_AddColoredLine -- ---------------------------------------------------------------------------- -local MAJOR_VERSION = "LibUIDropDownMenu-2.0" -local MINOR_VERSION = 90000 + tonumber(("$Rev: 40 $"):match("%d+")) +local MAJOR_VERSION = "LibUIDropDownMenu-4.0" +local MINOR_VERSION = 90000 + tonumber(("$Rev: 65 $"):match("%d+")) local LibStub = _G.LibStub if not LibStub then error(MAJOR_VERSION .. " requires LibStub.") end local lib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION) if not lib then return end +-- Determine WoW TOC Version +local WoWClassic, WoWRetail +local wowtocversion = select(4, GetBuildInfo()) +if wowtocversion < 19999 then + WoWClassic = true +else + WoWRetail = true +end + +if WoWClassic then + GameTooltip = _G.GameTooltip + tooltip = GameTooltip +else -- Shadowlands + GetAppropriateTooltip = _G.GetAppropriateTooltip + tooltip = GetAppropriateTooltip() + GetValueOrCallFunction = _G.GetValueOrCallFunction +end + -- ////////////////////////////////////////////////////////////// L_UIDROPDOWNMENU_MAXBUTTONS = 1; L_UIDROPDOWNMENU_MAXLEVELS = 2; @@ -40,28 +63,27 @@ L_UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT = nil; -- List of open menus L_OPEN_DROPDOWNMENUS = {}; -local L_UIDropDownMenuDelegate = CreateFrame("FRAME"); +local L_DropDownList1, L_DropDownList2 -function L_UIDropDownMenuDelegate_OnAttributeChanged (self, attribute, value) +local delegateFrame = CreateFrame("FRAME"); +delegateFrame:SetScript("OnAttributeChanged", function(self, attribute, value) if ( attribute == "createframes" and value == true ) then - L_UIDropDownMenu_CreateFrames(self:GetAttribute("createframes-level"), self:GetAttribute("createframes-index")); + lib:UIDropDownMenu_CreateFrames(self:GetAttribute("createframes-level"), self:GetAttribute("createframes-index")); elseif ( attribute == "initmenu" ) then L_UIDROPDOWNMENU_INIT_MENU = value; elseif ( attribute == "openmenu" ) then L_UIDROPDOWNMENU_OPEN_MENU = value; end -end +end); -L_UIDropDownMenuDelegate:SetScript("OnAttributeChanged", L_UIDropDownMenuDelegate_OnAttributeChanged); - -function L_UIDropDownMenu_InitializeHelper (frame) +function lib:UIDropDownMenu_InitializeHelper(frame) -- This deals with the potentially tainted stuff! if ( frame ~= L_UIDROPDOWNMENU_OPEN_MENU ) then L_UIDROPDOWNMENU_MENU_LEVEL = 1; end -- Set the frame that's being intialized - L_UIDropDownMenuDelegate:SetAttribute("initmenu", frame); + delegateFrame:SetAttribute("initmenu", frame); -- Hide all the buttons local button, dropDownList; @@ -79,10 +101,9 @@ function L_UIDropDownMenu_InitializeHelper (frame) end frame:SetHeight(L_UIDROPDOWNMENU_BUTTON_HEIGHT * 2); end - -- ////////////////////////////////////////////////////////////// -- L_UIDropDownMenuButtonTemplate -local function create_UIDropDownMenuButton(name, parent) +local function create_MenuButton(name, parent) local f = CreateFrame("Button", name, parent or nil) f:SetWidth(100) f:SetHeight(16) @@ -112,36 +133,37 @@ local function create_UIDropDownMenuButton(name, parent) f.Icon:Hide() -- ColorSwatch - local fcw = CreateFrame("Button", name.."ColorSwatch", f) - fcw:SetSize(16, 16) + local fcw = CreateFrame("Button", name.."ColorSwatch", f, BackdropTemplateMixin and "ColorSwatchTemplate" or nil) fcw:SetPoint("RIGHT", f, -6, 0) fcw:Hide() - fcw.SwatchBg = fcw:CreateTexture(name.."ColorSwatchSwatchBg", "BACKGROUND") - fcw.SwatchBg:SetVertexColor(1, 1, 1) - fcw.SwatchBg:SetWidth(14) - fcw.SwatchBg:SetHeight(14) - fcw.SwatchBg:SetPoint("CENTER", fcw, 0, 0) - local button1NormalTexture = fcw:CreateTexture(name.."ColorSwatchNormalTexture") - button1NormalTexture:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch") - button1NormalTexture:SetAllPoints() - fcw:SetNormalTexture(button1NormalTexture) + if WoWClassic then + fcw:SetSize(16, 16) + fcw.SwatchBg = fcw:CreateTexture(name.."ColorSwatchSwatchBg", "BACKGROUND") + fcw.SwatchBg:SetVertexColor(1, 1, 1) + fcw.SwatchBg:SetWidth(14) + fcw.SwatchBg:SetHeight(14) + fcw.SwatchBg:SetPoint("CENTER", fcw, 0, 0) + local button1NormalTexture = fcw:CreateTexture(name.."ColorSwatchNormalTexture") + button1NormalTexture:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch") + button1NormalTexture:SetAllPoints() + fcw:SetNormalTexture(button1NormalTexture) + end fcw:SetScript("OnClick", function(self, button, down) CloseMenus() - L_UIDropDownMenuButton_OpenColorPicker(self:GetParent()) + lib:UIDropDownMenuButton_OpenColorPicker(self:GetParent()) end) fcw:SetScript("OnEnter", function(self, motion) - L_CloseDropDownMenus(self:GetParent():GetParent():GetID() + 1) + lib:CloseDropDownMenus(self:GetParent():GetParent():GetID() + 1) _G[self:GetName().."SwatchBg"]:SetVertexColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b) - L_UIDropDownMenu_StopCounting(self:GetParent():GetParent()) end) fcw:SetScript("OnLeave", function(self, motion) _G[self:GetName().."SwatchBg"]:SetVertexColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b); - L_UIDropDownMenu_StartCounting(self:GetParent():GetParent()) end) f.ColorSwatch = fcw -- ExpandArrow local fea = CreateFrame("Button", name.."ExpandArrow", f) + fea:SetSize(16, 16) fea:SetPoint("RIGHT", f, 0, 0) fea:Hide() @@ -149,22 +171,21 @@ local function create_UIDropDownMenuButton(name, parent) button2NormalTexture:SetTexture("Interface\\ChatFrame\\ChatFrameExpandArrow") button2NormalTexture:SetAllPoints() fea:SetNormalTexture(button2NormalTexture) - fea:SetScript("OnClick", function(self, button, down) - L_ToggleDropDownMenu(self:GetParent():GetParent():GetID() + 1, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self) + fea:SetScript("OnMouseDown", function(self, button) + if self:IsEnabled() then + lib:ToggleDropDownMenu(self:GetParent():GetParent():GetID() + 1, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self); + PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON); + end end) fea:SetScript("OnEnter", function(self, motion) local level = self:GetParent():GetParent():GetID() + 1 - L_CloseDropDownMenus(level) + lib:CloseDropDownMenus(level) if self:IsEnabled() then local listFrame = _G["L_DropDownList"..level]; if ( not listFrame or not listFrame:IsShown() or select(2, listFrame:GetPoint()) ~= self ) then - L_ToggleDropDownMenu(level, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self) + lib:ToggleDropDownMenu(level, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self) end end - L_UIDropDownMenu_StopCounting(self:GetParent():GetParent()) - end) - fea:SetScript("OnLeave", function(self, motion) - L_UIDropDownMenu_StartCounting(self:GetParent():GetParent()) end) f.ExpandArrow = fea @@ -175,22 +196,131 @@ local function create_UIDropDownMenuButton(name, parent) fib:SetPoint("BOTTOMLEFT", f, 0, 0) fib:SetPoint("RIGHT", fcw, "LEFT", 0, 0) fib:SetScript("OnEnter", function(self, motion) - L_UIDropDownMenuButtonInvisibleButton_OnEnter(self) + lib:CloseDropDownMenus(self:GetParent():GetParent():GetID() + 1); + local parent = self:GetParent(); + if ( parent.tooltipTitle and parent.tooltipWhileDisabled) then + if ( parent.tooltipOnButton ) then + tooltip:SetOwner(parent, "ANCHOR_RIGHT"); + GameTooltip_SetTitle(tooltip, parent.tooltipTitle); + if parent.tooltipInstruction then + GameTooltip_AddInstructionLine(tooltip, parent.tooltipInstruction); + end + if parent.tooltipText then + GameTooltip_AddNormalLine(tooltip, parent.tooltipText, true); + end + if parent.tooltipWarning then + GameTooltip_AddColoredLine(tooltip, parent.tooltipWarning, RED_FONT_COLOR, true); + end + tooltip:Show(); + end + end end) fib:SetScript("OnLeave", function(self, motion) - L_UIDropDownMenuButtonInvisibleButton_OnLeave(self) + tooltip:Hide(); end) f.invisibleButton = fib -- UIDropDownMenuButton Scripts + local function button_OnEnter(self) + if ( self.hasArrow ) then + local level = self:GetParent():GetID() + 1; + local listFrame = _G["L_DropDownList"..level]; + if ( not listFrame or not listFrame:IsShown() or select(2, listFrame:GetPoint()) ~= self ) then + lib:ToggleDropDownMenu(self:GetParent():GetID() + 1, self.value, nil, nil, nil, nil, self.menuList, self); + end + else + lib:CloseDropDownMenus(self:GetParent():GetID() + 1); + end + self.Highlight:Show(); + if ( self.tooltipTitle and not self.noTooltipWhileEnabled ) then + if ( self.tooltipOnButton ) then + tooltip:SetOwner(self, "ANCHOR_RIGHT"); + GameTooltip_SetTitle(tooltip, self.tooltipTitle); + if self.tooltipText then + GameTooltip_AddNormalLine(tooltip, self.tooltipText, true); + end + tooltip:Show(); + end + end + + if ( self.mouseOverIcon ~= nil ) then + self.Icon:SetTexture(self.mouseOverIcon); + self.Icon:Show(); + end + if WoWRetail then + GetValueOrCallFunction(self, "funcOnEnter", self); + end + end + + local function button_OnLeave(self) + self.Highlight:Hide(); + tooltip:Hide(); + + if ( self.mouseOverIcon ~= nil ) then + if ( self.icon ~= nil ) then + self.Icon:SetTexture(self.icon); + else + self.Icon:Hide(); + end + end + + if WoWRetail then + GetValueOrCallFunction(self, "funcOnLeave", self); + end + end + + local function button_OnClick(self) + local checked = self.checked; + if ( type (checked) == "function" ) then + checked = checked(self); + end + + if ( self.keepShownOnClick ) then + if not self.notCheckable then + if ( checked ) then + _G[self:GetName().."Check"]:Hide(); + _G[self:GetName().."UnCheck"]:Show(); + checked = false; + else + _G[self:GetName().."Check"]:Show(); + _G[self:GetName().."UnCheck"]:Hide(); + checked = true; + end + end + else + self:GetParent():Hide(); + end + + if ( type (self.checked) ~= "function" ) then + self.checked = checked; + end + + -- saving this here because func might use a dropdown, changing this self's attributes + local playSound = true; + if ( self.noClickSound ) then + playSound = false; + end + + local func = self.func; + if ( func ) then + func(self, self.arg1, self.arg2, checked); + else + return; + end + + if ( playSound ) then + PlaySound(SOUNDKIT.U_CHAT_SCROLL_BUTTON); + end + end + f:SetScript("OnClick", function(self, button, down) - L_UIDropDownMenuButton_OnClick(self, button, down) + button_OnClick(self, button, down) end) f:SetScript("OnEnter", function(self, motion) - L_UIDropDownMenuButton_OnEnter(self) + button_OnEnter(self) end) f:SetScript("OnLeave", function(self, motion) - L_UIDropDownMenuButton_OnLeave(self) + button_OnLeave(self) end) f:SetScript("OnEnable", function(self) self.invisibleButton:Hide() @@ -211,68 +341,87 @@ end -- ////////////////////////////////////////////////////////////// -- L_UIDropDownListTemplate -local function creatre_UIDropDownList(name, parent) - local f = _G[name] or CreateFrame("Button", name) - f:SetParent(parent or nil) - f:Hide() - f:SetFrameStrata("DIALOG") - f:EnableMouse(true) - - f.Backdrop = _G[name.."Backdrop"] or CreateFrame("Frame", name.."Backdrop", f, BackdropTemplateMixin and "BackdropTemplate") - f.Backdrop:SetAllPoints() - f.Backdrop:SetBackdrop({ +local BACKDROP_DIALOG_DARK = { bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background-Dark", edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", tile = true, tileSize = 32, edgeSize = 32, insets = { left = 11, right = 12, top = 12, bottom = 9, }, - }) +} +local function creatre_DropDownList(name, parent) + local f = _G[name] or CreateFrame("Button", name) + f:SetParent(parent or nil) + f:Hide() + f:SetFrameStrata("DIALOG") + f:EnableMouse(true) - f.MenuBackdrop= _G[name.."MenuBackdrop"] or CreateFrame("Frame", name.."MenuBackdrop", f, BackdropTemplateMixin and "BackdropTemplate") - f.MenuBackdrop:SetAllPoints() - f.MenuBackdrop:SetBackdrop({ - bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", - edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", - tile = true, - tileSize = 16, - edgeSize = 16, - insets = { left = 5, right = 4, top = 4, bottom = 4, }, - }) - f.MenuBackdrop:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b) - f.MenuBackdrop:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b) + --local fbd = _G[name.."Border"] or CreateFrame("Frame", name.."Border", f, BackdropTemplateMixin and "DialogBorderDarkTemplate" or nil) + local fbd = _G[name.."Border"] or CreateFrame("Frame", name.."Border", f, BackdropTemplateMixin and "BackdropTemplate" or nil) + fbd:SetAllPoints() + fbd:SetBackdrop(BACKDROP_DIALOG_DARK) + f.Border = fbd + + --local fmb = _G[name.."MenuBackdrop"] or CreateFrame("Frame", name.."MenuBackdrop", f, BackdropTemplateMixin and "TooltipBackdropTemplate" or nil) + local fmb = _G[name.."MenuBackdrop"] or CreateFrame("Frame", name.."MenuBackdrop", f, BackdropTemplateMixin and "BackdropTemplate" or nil) + fmb:SetAllPoints() + fmb:SetBackdrop(BACKDROP_TOOLTIP_16_16_5555) + fmb:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b) + fmb:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b) + f.MenuBackdrop = fmb - f.Button1 = _G[name.."Button1"] or create_UIDropDownMenuButton(name.."Button1", f) + f.Button1 = _G[name.."Button1"] or create_MenuButton(name.."Button1", f) f.Button1:SetID(1) f:SetScript("OnClick", function(self) self:Hide() end) - f:SetScript("OnEnter", function(self, motion) - L_UIDropDownMenu_StopCounting(self, motion) - end) - f:SetScript("OnLeave", function(self, motion) - L_UIDropDownMenu_StartCounting(self, motion) - end) + -- If dropdown is visible then see if its timer has expired, if so hide the frame f:SetScript("OnUpdate", function(self, elapsed) - L_UIDropDownMenu_OnUpdate(self, elapsed) + if ( self.shouldRefresh ) then + lib:UIDropDownMenu_RefreshDropDownSize(self); + self.shouldRefresh = false; + end end) f:SetScript("OnShow", function(self) + if ( self.onShow ) then + self.onShow(); + self.onShow = nil; + end + for i=1, L_UIDROPDOWNMENU_MAXBUTTONS do if (not self.noResize) then _G[self:GetName().."Button"..i]:SetWidth(self.maxWidth); end end + if (not self.noResize) then self:SetWidth(self.maxWidth+25); end - self.showTimer = nil; + if ( self:GetID() > 1 ) then self.parent = _G["L_DropDownList"..(self:GetID() - 1)]; end end) f:SetScript("OnHide", function(self) - L_UIDropDownMenu_OnHide(self) + local id = self:GetID() + if ( self.onHide ) then + self.onHide(id+1); + self.onHide = nil; + end + lib:CloseDropDownMenus(id+1); + L_OPEN_DROPDOWNMENUS[id] = nil; + if (id == 1) then + L_UIDROPDOWNMENU_OPEN_MENU = nil; + end + + if self.customFrames then + for index, frame in ipairs(self.customFrames) do + frame:Hide(); + end + + self.customFrames = nil; + end end) return f @@ -280,7 +429,7 @@ end -- ////////////////////////////////////////////////////////////// -- L_UIDropDownMenuTemplate -local function create_UIDropDownMenu(name, parent) +local function create_DropDownMenu(name, parent) local f if type(name) == "table" then f = name @@ -364,14 +513,17 @@ local function create_UIDropDownMenu(name, parent) myscript(parent) end end) - f.Button:SetScript("OnClick", function(self, button, down) - L_ToggleDropDownMenu(nil, nil, self:GetParent()) + f.Button:SetScript("OnMouseDown", function(self, button) + if self:IsEnabled() then + local parent = self:GetParent() + lib:ToggleDropDownMenu(nil, nil, parent) PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON) + end end) -- UIDropDownMenu Script f:SetScript("OnHide", function(self) - L_CloseDropDownMenus() + lib:CloseDropDownMenus() end) return f @@ -381,47 +533,59 @@ end -- ////////////////////////////////////////////////////////////// -- Handling two frames from LibUIDropDownMenu.xml -local L_DropDownList1, L_DropDownList2 -do - L_DropDownList1 = creatre_UIDropDownList("L_DropDownList1") +local function create_DropDownButtons() + L_DropDownList1 = creatre_DropDownList("L_DropDownList1") L_DropDownList1:SetToplevel(true) L_DropDownList1:SetFrameStrata("FULLSCREEN_DIALOG") L_DropDownList1:Hide() L_DropDownList1:SetID(1) L_DropDownList1:SetSize(180, 10) - local fontName, fontHeight, fontFlags = _G["L_DropDownList1Button1NormalText"]:GetFont() + local _, fontHeight, _ = _G["L_DropDownList1Button1NormalText"]:GetFont() L_UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT = fontHeight - L_DropDownList2 = creatre_UIDropDownList("L_DropDownList2") + L_DropDownList2 = creatre_DropDownList("L_DropDownList2") L_DropDownList2:SetToplevel(true) L_DropDownList2:SetFrameStrata("FULLSCREEN_DIALOG") L_DropDownList2:Hide() L_DropDownList2:SetID(2) L_DropDownList2:SetSize(180, 10) + + -- UIParent integration; since we customize the name of DropDownList, we need to add it to golbal UIMenus table. + tinsert(UIMenus, "L_DropDownList1"); + tinsert(UIMenus, "L_DropDownList2"); +end + +do + if lib then + create_DropDownButtons() + end end -- ////////////////////////////////////////////////////////////// -- Global function to replace L_UIDropDownMenuTemplate -function L_Create_UIDropDownMenu(name, parent) - return create_UIDropDownMenu(name, parent) +function lib:Create_UIDropDownMenu(name, parent) + return create_DropDownMenu(name, parent) end local function GetChild(frame, name, key) if (frame[key]) then return frame[key]; - else + elseif name then return _G[name..key]; end + + return nil; end -function L_UIDropDownMenu_Initialize(frame, initFunction, displayMode, level, menuList) +function lib:UIDropDownMenu_Initialize(frame, initFunction, displayMode, level, menuList) frame.menuList = menuList; - securecall("L_UIDropDownMenu_InitializeHelper", frame); + --securecall("initializeHelper", frame); + lib:UIDropDownMenu_InitializeHelper(frame) -- Set the initialize function and call it. The initFunction populates the dropdown list. if ( initFunction ) then - L_UIDropDownMenu_SetInitializeFunction(frame, initFunction); + lib:UIDropDownMenu_SetInitializeFunction(frame, initFunction); initFunction(frame, level, frame.menuList); end @@ -434,14 +598,14 @@ function L_UIDropDownMenu_Initialize(frame, initFunction, displayMode, level, me dropDownList.dropdown = frame; dropDownList.shouldRefresh = true; - L_UIDropDownMenu_SetDisplayMode(frame, displayMode); + lib:UIDropDownMenu_SetDisplayMode(frame, displayMode); end -function L_UIDropDownMenu_SetInitializeFunction(frame, initFunction) +function lib:UIDropDownMenu_SetInitializeFunction(frame, initFunction) frame.initialize = initFunction; end -function L_UIDropDownMenu_SetDisplayMode(frame, displayMode) +function lib:UIDropDownMenu_SetDisplayMode(frame, displayMode) -- Change appearance based on the displayMode -- Note: this is a one time change based on previous behavior. if ( displayMode == "MENU" ) then @@ -464,8 +628,8 @@ function L_UIDropDownMenu_SetDisplayMode(frame, displayMode) end end -function L_UIDropDownMenu_RefreshDropDownSize(self) - self.maxWidth = L_UIDropDownMenu_GetMaxButtonWidth(self); +function lib:UIDropDownMenu_RefreshDropDownSize(self) + self.maxWidth = lib:UIDropDownMenu_GetMaxButtonWidth(self); self:SetWidth(self.maxWidth + 25); for i=1, L_UIDROPDOWNMENU_MAXBUTTONS, 1 do @@ -477,117 +641,6 @@ function L_UIDropDownMenu_RefreshDropDownSize(self) end end --- If dropdown is visible then see if its timer has expired, if so hide the frame -function L_UIDropDownMenu_OnUpdate(self, elapsed) - if ( self.shouldRefresh ) then - L_UIDropDownMenu_RefreshDropDownSize(self); - self.shouldRefresh = false; - end - - if ( not self.showTimer or not self.isCounting ) then - return; - elseif ( self.showTimer < 0 ) then - self:Hide(); - self.showTimer = nil; - self.isCounting = nil; - else - self.showTimer = self.showTimer - elapsed; - end -end - --- Start the countdown on a frame -function L_UIDropDownMenu_StartCounting(frame) - if ( frame.parent ) then - L_UIDropDownMenu_StartCounting(frame.parent); - else - frame.showTimer = L_UIDROPDOWNMENU_SHOW_TIME; - frame.isCounting = 1; - end -end - --- Stop the countdown on a frame -function L_UIDropDownMenu_StopCounting(frame) - if ( frame.parent ) then - L_UIDropDownMenu_StopCounting(frame.parent); - else - frame.isCounting = nil; - end -end - -function L_UIDropDownMenuButtonInvisibleButton_OnEnter(self) - L_UIDropDownMenu_StopCounting(self:GetParent():GetParent()); - L_CloseDropDownMenus(self:GetParent():GetParent():GetID() + 1); - local parent = self:GetParent(); - if ( parent.tooltipTitle and parent.tooltipWhileDisabled) then - if ( parent.tooltipOnButton ) then - GameTooltip:SetOwner(parent, "ANCHOR_RIGHT"); - GameTooltip_SetTitle(GameTooltip, parent.tooltipTitle); - if parent.tooltipInstruction then - GameTooltip_AddInstructionLine(GameTooltip, parent.tooltipInstruction); - end - if parent.tooltipText then - GameTooltip_AddNormalLine(GameTooltip, parent.tooltipText, true); - end - if parent.tooltipWarning then - GameTooltip_AddColoredLine(GameTooltip, parent.tooltipWarning, RED_FONT_COLOR, true); - end - GameTooltip:Show(); - else - GameTooltip_AddNewbieTip(parent, parent.tooltipTitle, 1.0, 1.0, 1.0, parent.tooltipText, 1); - end - end -end - -function L_UIDropDownMenuButtonInvisibleButton_OnLeave(self) - L_UIDropDownMenu_StartCounting(self:GetParent():GetParent()); - GameTooltip:Hide(); -end - -function L_UIDropDownMenuButton_OnEnter(self) - if ( self.hasArrow ) then - local level = self:GetParent():GetID() + 1; - local listFrame = _G["L_DropDownList"..level]; - if ( not listFrame or not listFrame:IsShown() or select(2, listFrame:GetPoint()) ~= self ) then - L_ToggleDropDownMenu(self:GetParent():GetID() + 1, self.value, nil, nil, nil, nil, self.menuList, self); - end - else - L_CloseDropDownMenus(self:GetParent():GetID() + 1); - end - self.Highlight:Show(); - L_UIDropDownMenu_StopCounting(self:GetParent()); - if ( self.tooltipTitle and not self.noTooltipWhileEnabled ) then - if ( self.tooltipOnButton ) then - GameTooltip:SetOwner(self, "ANCHOR_RIGHT"); - GameTooltip_SetTitle(GameTooltip, self.tooltipTitle); - if self.tooltipText then - GameTooltip_AddNormalLine(GameTooltip, self.tooltipText, true); - end - GameTooltip:Show(); - else - GameTooltip_AddNewbieTip(self, self.tooltipTitle, 1.0, 1.0, 1.0, self.tooltipText, 1); - end - end - - if ( self.mouseOverIcon ~= nil ) then - self.Icon:SetTexture(self.mouseOverIcon); - self.Icon:Show(); - end -end - -function L_UIDropDownMenuButton_OnLeave(self) - self.Highlight:Hide(); - L_UIDropDownMenu_StartCounting(self:GetParent()); - GameTooltip:Hide(); - - if ( self.mouseOverIcon ~= nil ) then - if ( self.icon ~= nil ) then - self.Icon:SetTexture(self.icon); - else - self.Icon:Hide(); - end - end -end - --[[ List of button attributes ====================================================== @@ -626,20 +679,22 @@ info.noClickSound = [nil, 1] -- Set to 1 to suppress the sound when clicking t info.padding = [nil, NUMBER] -- Number of pixels to pad the text on the right side info.leftPadding = [nil, NUMBER] -- Number of pixels to pad the button on the left side info.minWidth = [nil, NUMBER] -- Minimum width for this line -info.customFrame = frame -- Allows this button to be a completely custom frame, should inherit from L_UIDropDownCustomMenuEntryTemplate and override appropriate methods. +info.customFrame = frame -- Allows this button to be a completely custom frame, should inherit from UIDropDownCustomMenuEntryTemplate and override appropriate methods. info.icon = [TEXTURE] -- An icon for the button. info.mouseOverIcon = [TEXTURE] -- An override icon when a button is moused over. +info.ignoreAsMenuSelection [nil, true] -- Never set the menu text/icon to this, even when this button is checked ]] -function L_UIDropDownMenu_CreateInfo() +-- Create (return) empty table +function lib:UIDropDownMenu_CreateInfo() return {}; end -function L_UIDropDownMenu_CreateFrames(level, index) +function lib:UIDropDownMenu_CreateFrames(level, index) while ( level > L_UIDROPDOWNMENU_MAXLEVELS ) do L_UIDROPDOWNMENU_MAXLEVELS = L_UIDROPDOWNMENU_MAXLEVELS + 1; --local newList = CreateFrame("Button", "L_DropDownList"..L_UIDROPDOWNMENU_MAXLEVELS, nil, "L_UIDropDownListTemplate"); - local newList = creatre_UIDropDownList("L_DropDownList"..L_UIDROPDOWNMENU_MAXLEVELS) + local newList = creatre_DropDownList("L_DropDownList"..L_UIDROPDOWNMENU_MAXLEVELS) newList:SetFrameStrata("FULLSCREEN_DIALOG"); newList:SetToplevel(true); newList:Hide(); @@ -648,7 +703,7 @@ function L_UIDropDownMenu_CreateFrames(level, index) newList:SetHeight(10) for i=1, L_UIDROPDOWNMENU_MAXBUTTONS do --local newButton = CreateFrame("Button", "L_DropDownList"..L_UIDROPDOWNMENU_MAXLEVELS.."Button"..i, newList, "L_UIDropDownMenuButtonTemplate"); - local newButton = create_UIDropDownMenuButton("L_DropDownList"..L_UIDROPDOWNMENU_MAXLEVELS.."Button"..i, newList) + local newButton = create_MenuButton("L_DropDownList"..L_UIDROPDOWNMENU_MAXLEVELS.."Button"..i, newList) newButton:SetID(i); end end @@ -657,13 +712,13 @@ function L_UIDropDownMenu_CreateFrames(level, index) L_UIDROPDOWNMENU_MAXBUTTONS = L_UIDROPDOWNMENU_MAXBUTTONS + 1; for i=1, L_UIDROPDOWNMENU_MAXLEVELS do --local newButton = CreateFrame("Button", "L_DropDownList"..i.."Button"..L_UIDROPDOWNMENU_MAXBUTTONS, _G["L_DropDownList"..i], "L_UIDropDownMenuButtonTemplate"); - local newButton = create_UIDropDownMenuButton("L_DropDownList"..i.."Button"..L_UIDROPDOWNMENU_MAXBUTTONS, _G["L_DropDownList"..i]) + local newButton = create_MenuButton("L_DropDownList"..i.."Button"..L_UIDROPDOWNMENU_MAXBUTTONS, _G["L_DropDownList"..i]) newButton:SetID(L_UIDROPDOWNMENU_MAXBUTTONS); end end end -function L_UIDropDownMenu_AddSeparator(level) +function lib:UIDropDownMenu_AddSeparator(level) local separatorInfo = { hasArrow = false; dist = 0; @@ -690,10 +745,22 @@ function L_UIDropDownMenu_AddSeparator(level) }, }; - L_UIDropDownMenu_AddButton(separatorInfo, level); + lib:UIDropDownMenu_AddButton(separatorInfo, level); +end + +function lib:UIDropDownMenu_AddSpace(level) + local spaceInfo = { + hasArrow = false, + dist = 0, + isTitle = true, + isUninteractable = true, + notCheckable = true, + }; + + lib:UIDropDownMenu_AddButton(spaceInfo, level); end -function L_UIDropDownMenu_AddButton(info, level) +function lib:UIDropDownMenu_AddButton(info, level) --[[ Might to uncomment this if there are performance issues if ( not L_UIDROPDOWNMENU_OPEN_MENU ) then @@ -705,12 +772,18 @@ function L_UIDropDownMenu_AddButton(info, level) end local listFrame = _G["L_DropDownList"..level]; - local index = listFrame and (listFrame.numButtons + 1) or 1; + local index; + if (listFrame) then + index = listFrame.numButtons and (listFrame.numButtons + 1) or 1 + else + index = 0 + end + --local index = listFrame and (listFrame.numButtons + 1) or 1; local width; - L_UIDropDownMenuDelegate:SetAttribute("createframes-level", level); - L_UIDropDownMenuDelegate:SetAttribute("createframes-index", index); - L_UIDropDownMenuDelegate:SetAttribute("createframes", true); + delegateFrame:SetAttribute("createframes-level", level); + delegateFrame:SetAttribute("createframes-index", index); + delegateFrame:SetAttribute("createframes", true); listFrame = listFrame or _G["L_DropDownList"..level]; local listFrameName = listFrame:GetName(); @@ -807,13 +880,15 @@ function L_UIDropDownMenu_AddButton(info, level) button.icon = info.icon; button.iconInfo = info.iconInfo; - L_UIDropDownMenu_SetIconImage(icon, info.icon, info.iconInfo); + lib:UIDropDownMenu_SetIconImage(icon, info.icon, info.iconInfo); icon:ClearAllPoints(); icon:SetPoint("LEFT"); end -- Pass through attributes button.func = info.func; + button.funcOnEnter = info.funcOnEnter; + button.funcOnLeave = info.funcOnLeave; button.owner = info.owner; button.hasOpacity = info.hasOpacity; button.opacity = info.opacity; @@ -838,6 +913,7 @@ function L_UIDropDownMenu_AddButton(info, level) button.padding = info.padding; button.icon = info.icon; button.mouseOverIcon = info.mouseOverIcon; + button.ignoreAsMenuSelection = info.ignoreAsMenuSelection; if ( info.value ) then button.value = info.value; @@ -891,16 +967,16 @@ function L_UIDropDownMenu_AddButton(info, level) -- See if button is selected by id or name if ( frame ) then - if ( L_UIDropDownMenu_GetSelectedName(frame) ) then - if ( button:GetText() == L_UIDropDownMenu_GetSelectedName(frame) ) then + if ( lib:UIDropDownMenu_GetSelectedName(frame) ) then + if ( button:GetText() == lib:UIDropDownMenu_GetSelectedName(frame) ) then info.checked = 1; end - elseif ( L_UIDropDownMenu_GetSelectedID(frame) ) then - if ( button:GetID() == L_UIDropDownMenu_GetSelectedID(frame) ) then + elseif ( lib:UIDropDownMenu_GetSelectedID(frame) ) then + if ( button:GetID() == lib:UIDropDownMenu_GetSelectedID(frame) ) then info.checked = 1; end - elseif ( L_UIDropDownMenu_GetSelectedValue(frame) ) then - if ( button.value == L_UIDropDownMenu_GetSelectedValue(frame) ) then + elseif ( lib:UIDropDownMenu_GetSelectedValue(frame) ) then + if ( button.value == lib:UIDropDownMenu_GetSelectedValue(frame) ) then info.checked = 1; end end @@ -969,7 +1045,11 @@ function L_UIDropDownMenu_AddButton(info, level) -- If has a colorswatch, show it and vertex color it local colorSwatch = _G[listFrameName.."Button"..index.."ColorSwatch"]; if ( info.hasColorSwatch ) then - _G["L_DropDownList"..level.."Button"..index.."ColorSwatch".."NormalTexture"]:SetVertexColor(info.r, info.g, info.b); + if WoWClassic then + _G["L_DropDownList"..level.."Button"..index.."ColorSwatch".."NormalTexture"]:SetVertexColor(info.r, info.g, info.b); + else + _G["L_DropDownList"..level.."Button"..index.."ColorSwatch"].Color:SetVertexColor(info.r, info.g, info.b); + end button.r = info.r; button.g = info.g; button.b = info.b; @@ -978,15 +1058,15 @@ function L_UIDropDownMenu_AddButton(info, level) colorSwatch:Hide(); end - L_UIDropDownMenu_CheckAddCustomFrame(listFrame, button, info); + lib:UIDropDownMenu_CheckAddCustomFrame(listFrame, button, info); button:SetShown(button.customFrame == nil); button.minWidth = info.minWidth; - width = max(L_UIDropDownMenu_GetButtonWidth(button), info.minWidth or 0); + width = max(lib:UIDropDownMenu_GetButtonWidth(button), info.minWidth or 0); --Set maximum button width - if ( width > listFrame.maxWidth ) then + if ( width > (listFrame and listFrame.maxWidth or 0) ) then listFrame.maxWidth = width; end @@ -994,7 +1074,7 @@ function L_UIDropDownMenu_AddButton(info, level) listFrame:SetHeight((index * L_UIDROPDOWNMENU_BUTTON_HEIGHT) + (L_UIDROPDOWNMENU_BORDER_HEIGHT * 2)); end -function L_UIDropDownMenu_CheckAddCustomFrame(self, button, info) +function lib:UIDropDownMenu_CheckAddCustomFrame(self, button, info) local customFrame = info.customFrame; button.customFrame = customFrame; if customFrame then @@ -1003,20 +1083,20 @@ function L_UIDropDownMenu_CheckAddCustomFrame(self, button, info) customFrame:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0); customFrame:Show(); - L_UIDropDownMenu_RegisterCustomFrame(self, customFrame); + lib:UIDropDownMenu_RegisterCustomFrame(self, customFrame); end end -function L_UIDropDownMenu_RegisterCustomFrame(self, customFrame) +function lib:UIDropDownMenu_RegisterCustomFrame(self, customFrame) self.customFrames = self.customFrames or {} table.insert(self.customFrames, customFrame); end -function L_UIDropDownMenu_GetMaxButtonWidth(self) +function lib:UIDropDownMenu_GetMaxButtonWidth(self) local maxWidth = 0; for i=1, self.numButtons do local button = _G[self:GetName().."Button"..i]; - local width = L_UIDropDownMenu_GetButtonWidth(button); + local width = lib:UIDropDownMenu_GetButtonWidth(button); if ( width > maxWidth ) then maxWidth = width; end @@ -1024,7 +1104,7 @@ function L_UIDropDownMenu_GetMaxButtonWidth(self) return maxWidth; end -function L_UIDropDownMenu_GetButtonWidth(button) +function lib:UIDropDownMenu_GetButtonWidth(button) local minWidth = button.minWidth or 0; if button.customFrame and button.customFrame:IsShown() then return math.max(minWidth, button.customFrame:GetPreferredEntryWidth()); @@ -1066,7 +1146,7 @@ function L_UIDropDownMenu_GetButtonWidth(button) return math.max(minWidth, width); end -function L_UIDropDownMenu_Refresh(frame, useValue, dropdownLevel) +function lib:UIDropDownMenu_Refresh(frame, useValue, dropdownLevel) local maxWidth = 0; local somethingChecked = nil; if ( not dropdownLevel ) then @@ -1082,16 +1162,16 @@ function L_UIDropDownMenu_Refresh(frame, useValue, dropdownLevel) if(i <= listFrame.numButtons) then -- See if checked or not - if ( L_UIDropDownMenu_GetSelectedName(frame) ) then - if ( button:GetText() == L_UIDropDownMenu_GetSelectedName(frame) ) then + if ( lib:UIDropDownMenu_GetSelectedName(frame) ) then + if ( button:GetText() == lib:UIDropDownMenu_GetSelectedName(frame) ) then checked = 1; end - elseif ( L_UIDropDownMenu_GetSelectedID(frame) ) then - if ( button:GetID() == L_UIDropDownMenu_GetSelectedID(frame) ) then + elseif ( lib:UIDropDownMenu_GetSelectedID(frame) ) then + if ( button:GetID() == lib:UIDropDownMenu_GetSelectedID(frame) ) then checked = 1; end - elseif ( L_UIDropDownMenu_GetSelectedValue(frame) ) then - if ( button.value == L_UIDropDownMenu_GetSelectedValue(frame) ) then + elseif ( lib:UIDropDownMenu_GetSelectedValue(frame) ) then + if ( button.value == lib:UIDropDownMenu_GetSelectedValue(frame) ) then checked = 1; end end @@ -1105,16 +1185,18 @@ function L_UIDropDownMenu_Refresh(frame, useValue, dropdownLevel) local checkImage = _G["L_DropDownList"..dropdownLevel.."Button"..i.."Check"]; local uncheckImage = _G["L_DropDownList"..dropdownLevel.."Button"..i.."UnCheck"]; if ( checked ) then - somethingChecked = true; - local icon = GetChild(frame, frame:GetName(), "Icon"); - if (button.iconOnly and icon and button.icon) then - L_UIDropDownMenu_SetIconImage(icon, button.icon, button.iconInfo); - elseif ( useValue ) then - L_UIDropDownMenu_SetText(frame, button.value); - icon:Hide(); - else - L_UIDropDownMenu_SetText(frame, button:GetText()); - icon:Hide(); + if not button.ignoreAsMenuSelection then + somethingChecked = true; + local icon = GetChild(frame, frame:GetName(), "Icon"); + if (button.iconOnly and icon and button.icon) then + lib:UIDropDownMenu_SetIconImage(icon, button.icon, button.iconInfo); + elseif ( useValue ) then + lib:UIDropDownMenu_SetText(frame, button.value); + icon:Hide(); + else + lib:UIDropDownMenu_SetText(frame, button:GetText()); + icon:Hide(); + end end button:LockHighlight(); checkImage:Show(); @@ -1127,36 +1209,38 @@ function L_UIDropDownMenu_Refresh(frame, useValue, dropdownLevel) end if ( button:IsShown() ) then - local width = L_UIDropDownMenu_GetButtonWidth(button); + local width = lib:UIDropDownMenu_GetButtonWidth(button); if ( width > maxWidth ) then maxWidth = width; end end end if(somethingChecked == nil) then - L_UIDropDownMenu_SetText(frame, VIDEO_QUALITY_LABEL6); + lib:UIDropDownMenu_SetText(frame, VIDEO_QUALITY_LABEL6); + local icon = GetChild(frame, frame:GetName(), "Icon"); + icon:Hide(); end if (not frame.noResize) then for i=1, L_UIDROPDOWNMENU_MAXBUTTONS do local button = _G["L_DropDownList"..dropdownLevel.."Button"..i]; button:SetWidth(maxWidth); end - L_UIDropDownMenu_RefreshDropDownSize(_G["L_DropDownList"..dropdownLevel]); + lib:UIDropDownMenu_RefreshDropDownSize(_G["L_DropDownList"..dropdownLevel]); end end -function L_UIDropDownMenu_RefreshAll(frame, useValue) +function lib:UIDropDownMenu_RefreshAll(frame, useValue) for dropdownLevel = L_UIDROPDOWNMENU_MENU_LEVEL, 2, -1 do local listFrame = _G["L_DropDownList"..dropdownLevel]; if ( listFrame:IsShown() ) then - L_UIDropDownMenu_Refresh(frame, nil, dropdownLevel); + lib:UIDropDownMenu_Refresh(frame, nil, dropdownLevel); end end -- useValue is the text on the dropdown, only needs to be set once - L_UIDropDownMenu_Refresh(frame, useValue, 1); + lib:UIDropDownMenu_Refresh(frame, useValue, 1); end -function L_UIDropDownMenu_SetIconImage(icon, texture, info) +function lib:UIDropDownMenu_SetIconImage(icon, texture, info) icon:SetTexture(texture); if ( info.tCoordLeft ) then icon:SetTexCoord(info.tCoordLeft, info.tCoordRight, info.tCoordTop, info.tCoordBottom); @@ -1176,33 +1260,33 @@ function L_UIDropDownMenu_SetIconImage(icon, texture, info) icon:Show(); end -function L_UIDropDownMenu_SetSelectedName(frame, name, useValue) +function lib:UIDropDownMenu_SetSelectedName(frame, name, useValue) frame.selectedName = name; frame.selectedID = nil; frame.selectedValue = nil; - L_UIDropDownMenu_Refresh(frame, useValue); + lib:UIDropDownMenu_Refresh(frame, useValue); end -function L_UIDropDownMenu_SetSelectedValue(frame, value, useValue) +function lib:UIDropDownMenu_SetSelectedValue(frame, value, useValue) -- useValue will set the value as the text, not the name frame.selectedName = nil; frame.selectedID = nil; frame.selectedValue = value; - L_UIDropDownMenu_Refresh(frame, useValue); + lib:UIDropDownMenu_Refresh(frame, useValue); end -function L_UIDropDownMenu_SetSelectedID(frame, id, useValue) +function lib:UIDropDownMenu_SetSelectedID(frame, id, useValue) frame.selectedID = id; frame.selectedName = nil; frame.selectedValue = nil; - L_UIDropDownMenu_Refresh(frame, useValue); + lib:UIDropDownMenu_Refresh(frame, useValue); end -function L_UIDropDownMenu_GetSelectedName(frame) +function lib:UIDropDownMenu_GetSelectedName(frame) return frame.selectedName; end -function L_UIDropDownMenu_GetSelectedID(frame) +function lib:UIDropDownMenu_GetSelectedID(frame) if ( frame.selectedID ) then return frame.selectedID; else @@ -1211,12 +1295,12 @@ function L_UIDropDownMenu_GetSelectedID(frame) for i=1, listFrame.numButtons do local button = _G["L_DropDownList"..L_UIDROPDOWNMENU_MENU_LEVEL.."Button"..i]; -- See if checked or not - if ( L_UIDropDownMenu_GetSelectedName(frame) ) then - if ( button:GetText() == L_UIDropDownMenu_GetSelectedName(frame) ) then + if ( lib:UIDropDownMenu_GetSelectedName(frame) ) then + if ( button:GetText() == lib:UIDropDownMenu_GetSelectedName(frame) ) then return i; end - elseif ( L_UIDropDownMenu_GetSelectedValue(frame) ) then - if ( button.value == L_UIDropDownMenu_GetSelectedValue(frame) ) then + elseif ( lib:UIDropDownMenu_GetSelectedValue(frame) ) then + if ( button.value == lib:UIDropDownMenu_GetSelectedValue(frame) ) then return i; end end @@ -1224,71 +1308,26 @@ function L_UIDropDownMenu_GetSelectedID(frame) end end -function L_UIDropDownMenu_GetSelectedValue(frame) +function lib:UIDropDownMenu_GetSelectedValue(frame) return frame.selectedValue; end -function L_UIDropDownMenuButton_OnClick(self) - local checked = self.checked; - if ( type (checked) == "function" ) then - checked = checked(self); - end - - - if ( self.keepShownOnClick ) then - if not self.notCheckable then - if ( checked ) then - _G[self:GetName().."Check"]:Hide(); - _G[self:GetName().."UnCheck"]:Show(); - checked = false; - else - _G[self:GetName().."Check"]:Show(); - _G[self:GetName().."UnCheck"]:Hide(); - checked = true; - end - end - else - self:GetParent():Hide(); - end - - if ( type (self.checked) ~= "function" ) then - self.checked = checked; - end - - -- saving this here because func might use a dropdown, changing this self's attributes - local playSound = true; - if ( self.noClickSound ) then - playSound = false; - end - - local func = self.func; - if ( func ) then - func(self, self.arg1, self.arg2, checked); - else - return; - end - - if ( playSound ) then - PlaySound(SOUNDKIT.U_CHAT_SCROLL_BUTTON); - end -end - -function L_HideDropDownMenu(level) +function lib:HideDropDownMenu(level) local listFrame = _G["L_DropDownList"..level]; listFrame:Hide(); end -function L_ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, yOffset, menuList, button, autoHideDelay) +function lib:ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, yOffset, menuList, button, autoHideDelay) if ( not level ) then level = 1; end - L_UIDropDownMenuDelegate:SetAttribute("createframes-level", level); - L_UIDropDownMenuDelegate:SetAttribute("createframes-index", 0); - L_UIDropDownMenuDelegate:SetAttribute("createframes", true); + delegateFrame:SetAttribute("createframes-level", level); + delegateFrame:SetAttribute("createframes-index", 0); + delegateFrame:SetAttribute("createframes", true); L_UIDROPDOWNMENU_MENU_LEVEL = level; L_UIDROPDOWNMENU_MENU_VALUE = value; - local listFrame = _G["L_DropDownList"..level]; local listFrameName = "L_DropDownList"..level; + local listFrame = _G[listFrameName]; local tempFrame; local point, relativePoint, relativeTo; if ( not dropDownFrame ) then @@ -1321,7 +1360,7 @@ function L_ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, -- Display stuff -- Level specific stuff if ( level == 1 ) then - L_UIDropDownMenuDelegate:SetAttribute("openmenu", dropDownFrame); + delegateFrame:SetAttribute("openmenu", dropDownFrame); listFrame:ClearAllPoints(); -- If there's no specified anchorName then use left side of the dropdown menu if ( not anchorName ) then @@ -1406,19 +1445,21 @@ function L_ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, -- Change list box appearance depending on display mode if ( dropDownFrame and dropDownFrame.displayMode == "MENU" ) then - _G[listFrameName.."Backdrop"]:Hide(); + _G[listFrameName.."Border"]:Hide(); _G[listFrameName.."MenuBackdrop"]:Show(); else - _G[listFrameName.."Backdrop"]:Show(); + _G[listFrameName.."Border"]:Show(); _G[listFrameName.."MenuBackdrop"]:Hide(); end dropDownFrame.menuList = menuList; - L_UIDropDownMenu_Initialize(dropDownFrame, dropDownFrame.initialize, nil, level, menuList); + lib:UIDropDownMenu_Initialize(dropDownFrame, dropDownFrame.initialize, nil, level, menuList); -- If no items in the drop down don't show it if ( listFrame.numButtons == 0 ) then return; end + listFrame.onShow = dropDownFrame.listFrameOnShow; + -- Check to see if the dropdownlist is off the screen, if it is anchor it to the top of the dropdown button listFrame:Show(); -- Hack since GetCenter() is returning coords relative to 1024x768 @@ -1495,44 +1536,61 @@ function L_ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, listFrame:SetPoint(point, anchorFrame, relativePoint, xOffset, yOffset); end - if ( autoHideDelay and tonumber(autoHideDelay)) then - listFrame.showTimer = autoHideDelay; - listFrame.isCounting = 1; - end end end -function L_CloseDropDownMenus(level) +function lib:CloseDropDownMenus(level) if ( not level ) then level = 1; end for i=level, L_UIDROPDOWNMENU_MAXLEVELS do _G["L_DropDownList"..i]:Hide(); end + -- yes, we also want to close the menus which created by built-in UIDropDownMenus + for i=level, UIDROPDOWNMENU_MAXLEVELS do + _G["DropDownList"..i]:Hide(); + end end -function L_UIDropDownMenu_OnHide(self) - local id = self:GetID() - if ( self.onHide ) then - self.onHide(id+1); - self.onHide = nil; +local function containsMouse() + local result = false + + for i = 1, L_UIDROPDOWNMENU_MAXLEVELS do + local dropdown = _G["L_DropDownList"..i]; + if dropdown:IsShown() and dropdown:IsMouseOver() then + result = true; + end end - L_CloseDropDownMenus(id+1); - L_OPEN_DROPDOWNMENUS[id] = nil; - if (id == 1) then - L_UIDROPDOWNMENU_OPEN_MENU = nil; + for i = 1, UIDROPDOWNMENU_MAXLEVELS do + local dropdown = _G["DropDownList"..i]; + if dropdown:IsShown() and dropdown:IsMouseOver() then + result = true; + end end - if self.customFrames then - for index, frame in ipairs(self.customFrames) do - frame:Hide(); + + return result; +end + +function lib:UIDropDownMenu_HandleGlobalMouseEvent(button, event) + if event == "GLOBAL_MOUSE_DOWN" and (button == "LeftButton" or button == "RightButton") then + if not containsMouse() then + lib:CloseDropDownMenus(); end + end +end + +-- hooking UIDropDownMenu_HandleGlobalMouseEvent +do + if lib then + hooksecurefunc("UIDropDownMenu_HandleGlobalMouseEvent", function(button, event) + lib:UIDropDownMenu_HandleGlobalMouseEvent(button, event) + end) - self.customFrames = nil; end end -function L_UIDropDownMenu_SetWidth(frame, width, padding) +function lib:UIDropDownMenu_SetWidth(frame, width, padding) local frameName = frame:GetName(); GetChild(frame, frameName, "Middle"):SetWidth(width); local defaultPadding = 25; @@ -1549,7 +1607,7 @@ function L_UIDropDownMenu_SetWidth(frame, width, padding) frame.noResize = 1; end -function L_UIDropDownMenu_SetButtonWidth(frame, width) +function lib:UIDropDownMenu_SetButtonWidth(frame, width) local frameName = frame:GetName(); if ( width == "TEXT" ) then width = GetChild(frame, frameName, "Text"):GetWidth(); @@ -1559,22 +1617,22 @@ function L_UIDropDownMenu_SetButtonWidth(frame, width) frame.noResize = 1; end -function L_UIDropDownMenu_SetText(frame, text) +function lib:UIDropDownMenu_SetText(frame, text) local frameName = frame:GetName(); GetChild(frame, frameName, "Text"):SetText(text); end -function L_UIDropDownMenu_GetText(frame) +function lib:UIDropDownMenu_GetText(frame) local frameName = frame:GetName(); return GetChild(frame, frameName, "Text"):GetText(); end -function L_UIDropDownMenu_ClearAll(frame) +function lib:UIDropDownMenu_ClearAll(frame) -- Previous code refreshed the menu quite often and was a performance bottleneck frame.selectedID = nil; frame.selectedName = nil; frame.selectedValue = nil; - L_UIDropDownMenu_SetText(frame, ""); + lib:UIDropDownMenu_SetText(frame, ""); local button, checkImage, uncheckImage; for i=1, L_UIDROPDOWNMENU_MAXBUTTONS do @@ -1588,23 +1646,23 @@ function L_UIDropDownMenu_ClearAll(frame) end end -function L_UIDropDownMenu_JustifyText(frame, justification) +function lib:UIDropDownMenu_JustifyText(frame, justification, customXOffset) local frameName = frame:GetName(); local text = GetChild(frame, frameName, "Text"); text:ClearAllPoints(); if ( justification == "LEFT" ) then - text:SetPoint("LEFT", GetChild(frame, frameName, "Left"), "LEFT", 27, 2); + text:SetPoint("LEFT", GetChild(frame, frameName, "Left"), "LEFT", customXOffset or 27, 2); text:SetJustifyH("LEFT"); elseif ( justification == "RIGHT" ) then - text:SetPoint("RIGHT", GetChild(frame, frameName, "Right"), "RIGHT", -43, 2); + text:SetPoint("RIGHT", GetChild(frame, frameName, "Right"), "RIGHT", customXOffset or -43, 2); text:SetJustifyH("RIGHT"); elseif ( justification == "CENTER" ) then - text:SetPoint("CENTER", GetChild(frame, frameName, "Middle"), "CENTER", -5, 2); + text:SetPoint("CENTER", GetChild(frame, frameName, "Middle"), "CENTER", customXOffset or -5, 2); text:SetJustifyH("CENTER"); end end -function L_UIDropDownMenu_SetAnchor(dropdown, xOffset, yOffset, point, relativeTo, relativePoint) +function lib:UIDropDownMenu_SetAnchor(dropdown, xOffset, yOffset, point, relativeTo, relativePoint) dropdown.xOffset = xOffset; dropdown.yOffset = yOffset; dropdown.point = point; @@ -1612,7 +1670,7 @@ function L_UIDropDownMenu_SetAnchor(dropdown, xOffset, yOffset, point, relativeT dropdown.relativePoint = relativePoint; end -function L_UIDropDownMenu_GetCurrentDropDown() +function lib:UIDropDownMenu_GetCurrentDropDown() if ( L_UIDROPDOWNMENU_OPEN_MENU ) then return L_UIDROPDOWNMENU_OPEN_MENU; elseif ( L_UIDROPDOWNMENU_INIT_MENU ) then @@ -1620,32 +1678,32 @@ function L_UIDropDownMenu_GetCurrentDropDown() end end -function L_UIDropDownMenuButton_GetChecked(self) +function lib:UIDropDownMenuButton_GetChecked(self) return _G[self:GetName().."Check"]:IsShown(); end -function L_UIDropDownMenuButton_GetName(self) +function lib:UIDropDownMenuButton_GetName(self) return _G[self:GetName().."NormalText"]:GetText(); end -function L_UIDropDownMenuButton_OpenColorPicker(self, button) +function lib:UIDropDownMenuButton_OpenColorPicker(self, button) securecall("CloseMenus"); if ( not button ) then button = self; end L_UIDROPDOWNMENU_MENU_VALUE = button.value; - L_OpenColorPicker(button); + lib:OpenColorPicker(button); end -function L_UIDropDownMenu_DisableButton(level, id) +function lib:UIDropDownMenu_DisableButton(level, id) _G["L_DropDownList"..level.."Button"..id]:Disable(); end -function L_UIDropDownMenu_EnableButton(level, id) +function lib:UIDropDownMenu_EnableButton(level, id) _G["L_DropDownList"..level.."Button"..id]:Enable(); end -function L_UIDropDownMenu_SetButtonText(level, id, text, colorCode) +function lib:UIDropDownMenu_SetButtonText(level, id, text, colorCode) local button = _G["L_DropDownList"..level.."Button"..id]; if ( colorCode) then button:SetText(colorCode..text.."|r"); @@ -1654,41 +1712,43 @@ function L_UIDropDownMenu_SetButtonText(level, id, text, colorCode) end end -function L_UIDropDownMenu_SetButtonNotClickable(level, id) +function lib:UIDropDownMenu_SetButtonNotClickable(level, id) _G["L_DropDownList"..level.."Button"..id]:SetDisabledFontObject(GameFontHighlightSmallLeft); end -function L_UIDropDownMenu_SetButtonClickable(level, id) +function lib:UIDropDownMenu_SetButtonClickable(level, id) _G["L_DropDownList"..level.."Button"..id]:SetDisabledFontObject(GameFontDisableSmallLeft); end -function L_UIDropDownMenu_DisableDropDown(dropDown) +function lib:UIDropDownMenu_DisableDropDown(dropDown) local dropDownName = dropDown:GetName(); local label = GetChild(dropDown, dropDownName, "Label"); - if ( label ) then - label:SetVertexColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b); + if label then + label:SetVertexColor(GRAY_FONT_COLOR:GetRGB()); end - GetChild(dropDown, dropDownName, "Text"):SetVertexColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b); + GetChild(dropDown, dropDownName, "Icon"):SetVertexColor(GRAY_FONT_COLOR:GetRGB()); + GetChild(dropDown, dropDownName, "Text"):SetVertexColor(GRAY_FONT_COLOR:GetRGB()); GetChild(dropDown, dropDownName, "Button"):Disable(); dropDown.isDisabled = 1; end -function L_UIDropDownMenu_EnableDropDown(dropDown) +function lib:UIDropDownMenu_EnableDropDown(dropDown) local dropDownName = dropDown:GetName(); local label = GetChild(dropDown, dropDownName, "Label"); - if ( label ) then - label:SetVertexColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b); + if label then + label:SetVertexColor(NORMAL_FONT_COLOR:GetRGB()); end - GetChild(dropDown, dropDownName, "Text"):SetVertexColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b); + GetChild(dropDown, dropDownName, "Icon"):SetVertexColor(HIGHLIGHT_FONT_COLOR:GetRGB()); + GetChild(dropDown, dropDownName, "Text"):SetVertexColor(HIGHLIGHT_FONT_COLOR:GetRGB()); GetChild(dropDown, dropDownName, "Button"):Enable(); dropDown.isDisabled = nil; end -function L_UIDropDownMenu_IsEnabled(dropDown) +function lib:UIDropDownMenu_IsEnabled(dropDown) return not dropDown.isDisabled; end -function L_UIDropDownMenu_GetValue(id) +function lib:UIDropDownMenu_GetValue(id) --Only works if the dropdown has just been initialized, lame, I know =( local button = _G["L_DropDownList1Button"..id]; if ( button ) then @@ -1698,7 +1758,7 @@ function L_UIDropDownMenu_GetValue(id) end end -function L_OpenColorPicker(info) +function lib:OpenColorPicker(info) ColorPickerFrame.func = info.swatchFunc; ColorPickerFrame.hasOpacity = info.hasOpacity; ColorPickerFrame.opacityFunc = info.opacityFunc; @@ -1711,6 +1771,171 @@ function L_OpenColorPicker(info) ShowUIPanel(ColorPickerFrame); end -function L_ColorPicker_GetPreviousValues() +function lib:ColorPicker_GetPreviousValues() return ColorPickerFrame.previousValues.r, ColorPickerFrame.previousValues.g, ColorPickerFrame.previousValues.b; end + +-- ////////////////////////////////////////////////////////////// +-- LibUIDropDownMenuTemplates +-- ////////////////////////////////////////////////////////////// + +-- Custom dropdown buttons are instantiated by some external system. +-- When calling L_UIDropDownMenu_AddButton that system sets info.customFrame to the instance of the frame it wants to place on the menu. +-- The dropdown menu creates its button for the entry as it normally would, but hides all elements. The custom frame is then anchored +-- to that button and assumes responsibility for all relevant dropdown menu operations. +-- The hidden button will request a size that it should become from the custom frame. + +lib.DropDownMenuButtonMixin = {} + +function lib.DropDownMenuButtonMixin:OnEnter(...) + ExecuteFrameScript(self:GetParent(), "OnEnter", ...); +end + +function lib.DropDownMenuButtonMixin:OnLeave(...) + ExecuteFrameScript(self:GetParent(), "OnLeave", ...); +end + +function lib.DropDownMenuButtonMixin:OnMouseDown(button) + if self:IsEnabled() then + lib:ToggleDropDownMenu(nil, nil, self:GetParent()); + PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON); + end +end + +lib.LargeDropDownMenuButtonMixin = CreateFromMixins(lib.DropDownMenuButtonMixin); + +function lib.LargeDropDownMenuButtonMixin:OnMouseDown(button) + if self:IsEnabled() then + local parent = self:GetParent(); + lib:ToggleDropDownMenu(nil, nil, parent, parent, -8, 8); + PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON); + end +end + +lib.DropDownExpandArrowMixin = {}; + +function lib.DropDownExpandArrowMixin:OnEnter() + local level = self:GetParent():GetParent():GetID() + 1; + + lib:CloseDropDownMenus(level); + + if self:IsEnabled() then + local listFrame = _G["L_DropDownList"..level]; + if ( not listFrame or not listFrame:IsShown() or select(2, listFrame:GetPoint()) ~= self ) then + lib:ToggleDropDownMenu(level, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self); + end + end +end + +function lib.DropDownExpandArrowMixin:OnMouseDown(button) + if self:IsEnabled() then + lib:ToggleDropDownMenu(self:GetParent():GetParent():GetID() + 1, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self); + PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON); + end +end + +lib.UIDropDownCustomMenuEntryMixin = {}; + +function lib.UIDropDownCustomMenuEntryMixin:GetPreferredEntryWidth() + -- NOTE: Only width is currently supported, dropdown menus size vertically based on how many buttons are present. + return self:GetWidth(); +end + +function lib.UIDropDownCustomMenuEntryMixin:OnSetOwningButton() + -- for derived objects to implement +end + +function lib.UIDropDownCustomMenuEntryMixin:SetOwningButton(button) + self:SetParent(button:GetParent()); + self.owningButton = button; + self:OnSetOwningButton(); +end + +function lib.UIDropDownCustomMenuEntryMixin:GetOwningDropdown() + return self.owningButton:GetParent(); +end + +function lib.UIDropDownCustomMenuEntryMixin:SetContextData(contextData) + self.contextData = contextData; +end + +function lib.UIDropDownCustomMenuEntryMixin:GetContextData() + return self.contextData; +end + +-- ////////////////////////////////////////////////////////////// +-- L_UIDropDownCustomMenuEntryTemplate +function lib:Create_UIDropDownCustomMenuEntry(name, parent) + local f = _G[name] or CreateFrame("Frame", name, parent or nil) + f:EnableMouse(true) + f:Hide() + + -- I am not 100% sure if below works for replacing the mixins + f:SetScript("GetPreferredEntryWidth", function(self) + return self:GetWidth() + end) + f:SetScript("SetOwningButton", function(self, button) + self:SetParent(button:GetParent()) + self.owningButton = button + self:OnSetOwningButton() + end) + f:SetScript("GetOwningDropdown", function(self) + return self.owningButton:GetParent() + end) + f:SetScript("SetContextData", function(self, contextData) + self.contextData = contextData + end) + f:SetScript("GetContextData", function(self) + return self.contextData + end) + + return f +end + +-- ////////////////////////////////////////////////////////////// +-- UIDropDownMenuButtonScriptTemplate +-- +-- TBD +-- + +-- ////////////////////////////////////////////////////////////// +-- LargeUIDropDownMenuTemplate +-- +-- TBD +-- + +-- ////////////////////////////////////////////////////////////// +-- EasyMenu +-- Simplified Menu Display System +-- This is a basic system for displaying a menu from a structure table. +-- +-- Args: +-- menuList - menu table +-- menuFrame - the UI frame to populate +-- anchor - where to anchor the frame (e.g. CURSOR) +-- x - x offset +-- y - y offset +-- displayMode - border type +-- autoHideDelay - how long until the menu disappears +local function easyMenu_Initialize( frame, level, menuList ) + for index = 1, #menuList do + local value = menuList[index] + if (value.text) then + value.index = index; + lib:UIDropDownMenu_AddButton( value, level ); + end + end +end + +function lib:EasyMenu(menuList, menuFrame, anchor, x, y, displayMode, autoHideDelay ) + if ( displayMode == "MENU" ) then + menuFrame.displayMode = displayMode; + end + lib:UIDropDownMenu_Initialize(menuFrame, easyMenu_Initialize, displayMode, nil, menuList); + lib:ToggleDropDownMenu(1, nil, menuFrame, anchor, x, y, menuList, nil, autoHideDelay); +end + +function lib:EasyMenu_Initialize( frame, level, menuList ) + easyMenu_Initialize( frame, level, menuList ) +end + diff --git a/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.xml b/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.xml index dc97e9d..bc7d69e 100755 --- a/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.xml +++ b/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.xml @@ -1,10 +1,9 @@ -<!-- $Id: LibUIDropDownMenu.xml 40 2018-12-23 16:14:03Z arith $ --> +<!-- $Id: LibUIDropDownMenu.xml 64 2020-11-18 13:13:15Z arithmandar $ --> <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd"> <Script file="LibUIDropDownMenu.lua"/> - <Include file="LibUIDropDownMenuTemplates.xml"/> - <Script file="LibEasyMenu.lua"/> -<!-- +<!-- <Include file="LibUIDropDownMenuTemplates.xml"/> + <Button name="L_DropDownList1" toplevel="true" frameStrata="FULLSCREEN_DIALOG" inherits="L_UIDropDownListTemplate" hidden="true" id="1"> <Size> <AbsDimension x="180" y="10"/> diff --git a/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenuTemplates.lua b/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenuTemplates.lua index 615f41d..28c8b8f 100755 --- a/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenuTemplates.lua +++ b/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenuTemplates.lua @@ -1,11 +1,11 @@ --- $Id: LibUIDropDownMenuTemplates.lua 40 2018-12-23 16:14:03Z arith $ +-- $Id: LibUIDropDownMenuTemplates.lua 64 2020-11-18 13:13:15Z arithmandar $ -- ---------------------------------------------------------------------------- -- Localized Lua globals. -- ---------------------------------------------------------------------------- -local _G = getfenv(0) +--[[local _G = getfenv(0) -- ---------------------------------------------------------------------------- -local MAJOR_VERSION = "LibUIDropDownMenuTemplates-2.0" -local MINOR_VERSION = 90000 + tonumber(("$Rev: 40 $"):match("%d+")) +local MAJOR_VERSION = "LibUIDropDownMenuTemplates-3.0" +local MINOR_VERSION = 90000 + tonumber(("$Rev: 64 $"):match("%d+")) local LibStub = _G.LibStub if not LibStub then error(MAJOR_VERSION .. " requires LibStub.") end @@ -18,6 +18,53 @@ if not Lib then return end -- to that button and assumes responsibility for all relevant dropdown menu operations. -- The hidden button will request a size that it should become from the custom frame. +L_DropDownMenuButtonMixin = {} + +function L_DropDownMenuButtonMixin:OnEnter(...) + ExecuteFrameScript(self:GetParent(), "OnEnter", ...); +end + +function L_DropDownMenuButtonMixin:OnLeave(...) + ExecuteFrameScript(self:GetParent(), "OnLeave", ...); +end + +function L_DropDownMenuButtonMixin:OnMouseDown(button) + if self:IsEnabled() then + L_ToggleDropDownMenu(nil, nil, self:GetParent()); + PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON); + end +end + +L_LargeDropDownMenuButtonMixin = CreateFromMixins(L_DropDownMenuButtonMixin); + +function L_LargeDropDownMenuButtonMixin:OnMouseDown(button) + if self:IsEnabled() then + local parent = self:GetParent(); + L_ToggleDropDownMenu(nil, nil, parent, parent, -8, 8); + PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON); + end +end + +L_DropDownExpandArrowMixin = {}; + +function L_DropDownExpandArrowMixin:OnEnter() + local level = self:GetParent():GetParent():GetID() + 1; + + L_CloseDropDownMenus(level); + + if self:IsEnabled() then + local listFrame = _G["L_DropDownList"..level]; + if ( not listFrame or not listFrame:IsShown() or select(2, listFrame:GetPoint()) ~= self ) then + L_ToggleDropDownMenu(level, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self); + end + end +end + +function L_DropDownExpandArrowMixin:OnMouseDown(button) + if self:IsEnabled() then + L_ToggleDropDownMenu(self:GetParent():GetParent():GetID() + 1, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self); + end +end L_UIDropDownCustomMenuEntryMixin = {}; @@ -48,14 +95,6 @@ function L_UIDropDownCustomMenuEntryMixin:GetContextData() return self.contextData; end -function L_UIDropDownCustomMenuEntryMixin:OnEnter() - L_UIDropDownMenu_StopCounting(self:GetOwningDropdown()); -end - -function L_UIDropDownCustomMenuEntryMixin:OnLeave() - L_UIDropDownMenu_StartCounting(self:GetOwningDropdown()); -end - -- ////////////////////////////////////////////////////////////// -- L_UIDropDownCustomMenuEntryTemplate function L_Create_UIDropDownCustomMenuEntry(name, parent) @@ -63,13 +102,6 @@ function L_Create_UIDropDownCustomMenuEntry(name, parent) f:EnableMouse(true) f:Hide() - f:SetScript("OnEnter", function(self) - L_UIDropDownMenu_StopCounting(self:GetOwningDropdown()) - end) - f:SetScript("OnLeave", function(self) - L_UIDropDownMenu_StartCounting(self:GetOwningDropdown()) - end) - -- I am not 100% sure if below works for replacing the mixins f:SetScript("GetPreferredEntryWidth", function(self) return self:GetWidth() @@ -91,3 +123,4 @@ function L_Create_UIDropDownCustomMenuEntry(name, parent) return f end +]] diff --git a/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenuTemplates.xml b/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenuTemplates.xml index c2ac300..bf89718 100755 --- a/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenuTemplates.xml +++ b/Titan/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenuTemplates.xml @@ -1,14 +1,49 @@ -<!-- $Id: LibUIDropDownMenuTemplates.xml 40 2018-12-23 16:14:03Z arith $ --> +<!-- $Id: LibUIDropDownMenuTemplates.xml 64 2020-11-18 13:13:15Z arithmandar $ --> <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd"> <Include file="LibUIDropDownMenuTemplates.lua"/> <!-- - <Frame name="L_UIDropDownCustomMenuEntryTemplate" enableMouse="true" hidden="true" mixin="L_UIDropDownCustomMenuEntryMixin" virtual="true"> + <Frame name="L_UIDropDownCustomMenuEntryTemplate" enableMouse="true" hidden="true" mixin="L_UIDropDownCustomMenuEntryMixin" virtual="true/"> + + <Button name="ColorSwatchTemplate" virtual="true"> + <Size x="16" y="16"/> + <Layers> + <Layer level="BACKGROUND" textureSubLevel="-3"> + <Texture name="$parentSwatchBg" parentKey="SwatchBg" texelSnappingBias="0.0" snapToPixelGrid="false"> + <Size x="14" y="14"/> + <Anchors> + <Anchor point="CENTER"/> + </Anchors> + <Color color="HIGHLIGHT_FONT_COLOR"/> + </Texture> + </Layer> + <Layer level="BACKGROUND" textureSubLevel="-2"> + <Texture parentKey="InnerBorder" texelSnappingBias="0.0" snapToPixelGrid="false"> + <Size x="12" y="12"/> + <Anchors> + <Anchor point="CENTER"/> + </Anchors> + <Color color="BLACK_FONT_COLOR"/> + </Texture> + </Layer> + <Layer level="BACKGROUND" textureSubLevel="-1"> + <Texture parentKey="Color" texelSnappingBias="0.0" snapToPixelGrid="false"> + <Size x="10" y="10"/> + <Anchors> + <Anchor point="CENTER"/> + </Anchors> + <Color color="HIGHLIGHT_FONT_COLOR"/> + </Texture> + </Layer> + </Layers> <Scripts> - <OnEnter method="OnEnter"/> - <OnLeave method="OnLeave"/> + <OnShow inherit="prepend"> + PixelUtil.SetSize(self.SwatchBg, 14, 14); + PixelUtil.SetSize(self.InnerBorder, 12, 12); + PixelUtil.SetSize(self.Color, 10, 10); + </OnShow> </Scripts> - </Frame> + </Button> <Button name="L_UIDropDownMenuButtonTemplate" virtual="true"> <Size x="100" y="16"/> <Layers>