Quantcast

- Updated LibUIDropDownMenu to fix drop down staying active in certain conditions

urnati [06-15-21 - 18:03]
- Updated LibUIDropDownMenu to fix drop down staying active in certain conditions
Filename
TitanClassic/libs/!LibUIDropDownMenu/!LibUIDropDownMenu.toc
TitanClassic/libs/!LibUIDropDownMenu/Docs/Revision.txt
TitanClassic/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.lua
diff --git a/TitanClassic/libs/!LibUIDropDownMenu/!LibUIDropDownMenu.toc b/TitanClassic/libs/!LibUIDropDownMenu/!LibUIDropDownMenu.toc
index 4b13267..160ceb4 100755
--- a/TitanClassic/libs/!LibUIDropDownMenu/!LibUIDropDownMenu.toc
+++ b/TitanClassic/libs/!LibUIDropDownMenu/!LibUIDropDownMenu.toc
@@ -1,7 +1,7 @@
 ## Interface: 90005
 ## Title: Lib: UIDropDownMenu
 ## Notes: A Replacement for standard UIDropDownMenu
-## Version: v4.03.9000538556
+## Version: v4.05.9000538556
 ## X-Category: Libraries
 ## X-Website: https://www.wowace.com/projects/libuidropdownmenu
 ## OptionalDeps: LibStub
diff --git a/TitanClassic/libs/!LibUIDropDownMenu/Docs/Revision.txt b/TitanClassic/libs/!LibUIDropDownMenu/Docs/Revision.txt
index bdd0e89..42ab569 100755
--- a/TitanClassic/libs/!LibUIDropDownMenu/Docs/Revision.txt
+++ b/TitanClassic/libs/!LibUIDropDownMenu/Docs/Revision.txt
@@ -1,8 +1,17 @@
-$Id: Revision.txt 73 2021-05-18 17:04:17Z arithmandar $
+$Id: Revision.txt 78 2021-06-14 08:29:17Z arithmandar $

 Revision History:
 =================

+v4.05.9000538556 (2021/06/14)
+-----------------------------
+- Rework on dropdown menu's audo-hide
+
+v4.04.9000538556 (2021/06/14)
+-----------------------------
+- Allowing dropdown frame to be wihout a name (nil) given (for an anonymous frame)
+- Added timeout for classic (both classic era and TBC) so that dropdown menu will auto-hide when mouse is away (thanks to DahkCeles)
+
 v4.03.9000538556 (2021/05/19)
 -----------------------------
 - Added codes for fixing Tainting UIMenus and CloseMenus() (thanks to DahkCeles)
diff --git a/TitanClassic/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.lua b/TitanClassic/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.lua
index 52eddba..fdcb4dd 100755
--- a/TitanClassic/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.lua
+++ b/TitanClassic/libs/!LibUIDropDownMenu/LibUIDropDownMenu/LibUIDropDownMenu.lua
@@ -1,4 +1,4 @@
--- $Id: LibUIDropDownMenu.lua 73 2021-05-18 17:04:17Z arithmandar $
+-- $Id: LibUIDropDownMenu.lua 78 2021-06-14 08:29:17Z arithmandar $
 -- ----------------------------------------------------------------------------
 -- Localized Lua globals.
 -- ----------------------------------------------------------------------------
@@ -18,7 +18,7 @@ local GameTooltip_SetTitle, GameTooltip_AddInstructionLine, GameTooltip_AddNorma

 -- ----------------------------------------------------------------------------
 local MAJOR_VERSION = "LibUIDropDownMenu-4.0"
-local MINOR_VERSION = 90000 + tonumber(("$Rev: 73 $"):match("%d+"))
+local MINOR_VERSION = 90000 + tonumber(("$Rev: 78 $"):match("%d+"))


 local LibStub = _G.LibStub
@@ -27,18 +27,20 @@ local lib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
 if not lib then return end

 -- Determine WoW TOC Version
-local WoWClassic, WoWRetail
+local WoWClassicEra, WoWClassicTBC, WoWRetail
 local wowtocversion  = select(4, GetBuildInfo())
-if wowtocversion < 30000 then
-	WoWClassic = true
+if wowtocversion < 20000 then
+	WoWClassicEra = true
+elseif wowtocversion > 19999 and wowtocversion < 90000 then
+	WoWClassicTBC = true
 else
 	WoWRetail = true
 end

-if WoWClassic then
+if WoWClassicEra or WoWClassicTBC then
 	GameTooltip = _G.GameTooltip
 	tooltip = GameTooltip
-else -- Shadowlands
+else -- Retail
 	GetAppropriateTooltip = _G.GetAppropriateTooltip
 	tooltip = GetAppropriateTooltip()
 	GetValueOrCallFunction = _G.GetValueOrCallFunction
@@ -135,14 +137,10 @@ local function create_MenuButton(name, parent)

 	-- ColorSwatch
 	local fcw
-	if WoWClassic then
-		fcw = CreateFrame("Button", name.."ColorSwatch", f)
-	else
-		fcw = CreateFrame("Button", name.."ColorSwatch", f, BackdropTemplateMixin and "ColorSwatchTemplate" or nil)
-	end
+	fcw = CreateFrame("Button", name.."ColorSwatch", f, BackdropTemplateMixin and DropDownMenuButtonMixin and "BackdropTemplate,ColorSwatchTemplate" or BackdropTemplateMixin and "BackdropTemplate" or nil)
 	fcw:SetPoint("RIGHT", f, -6, 0)
 	fcw:Hide()
-	if WoWClassic then
+	if not DropDownMenuButtonMixin then
 		fcw:SetSize(16, 16)
 		fcw.SwatchBg = fcw:CreateTexture(name.."ColorSwatchSwatchBg", "BACKGROUND")
 		fcw.SwatchBg:SetVertexColor(1, 1, 1)
@@ -161,9 +159,11 @@ local function create_MenuButton(name, parent)
 	fcw:SetScript("OnEnter", function(self, motion)
 		lib:CloseDropDownMenus(self:GetParent():GetParent():GetID() + 1)
 		_G[self:GetName().."SwatchBg"]:SetVertexColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
+		lib: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);
+		lib:UIDropDownMenu_StartCounting(self:GetParent():GetParent())
 	end)
 	f.ColorSwatch = fcw

@@ -192,6 +192,10 @@ local function create_MenuButton(name, parent)
 				lib:ToggleDropDownMenu(level, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self)
 			end
 		end
+		lib:UIDropDownMenu_StopCounting(self:GetParent():GetParent())
+	end)
+	fea:SetScript("OnLeave", function(self, motion)
+		lib:UIDropDownMenu_StartCounting(self:GetParent():GetParent())
 	end)
 	f.ExpandArrow = fea

@@ -222,6 +226,7 @@ local function create_MenuButton(name, parent)
 		end
 	end)
 	fib:SetScript("OnLeave", function(self, motion)
+		lib:UIDropDownMenu_StartCounting(self:GetParent():GetParent());
 		tooltip:Hide();
 	end)
 	f.invisibleButton = fib
@@ -238,6 +243,8 @@ local function create_MenuButton(name, parent)
 			lib:CloseDropDownMenus(self:GetParent():GetID() + 1);
 		end
 		self.Highlight:Show();
+	    	lib:UIDropDownMenu_StopCounting(self:GetParent());
+
 		if ( self.tooltipTitle and not self.noTooltipWhileEnabled ) then
 			if ( self.tooltipOnButton ) then
 				tooltip:SetOwner(self, "ANCHOR_RIGHT");
@@ -260,6 +267,8 @@ local function create_MenuButton(name, parent)

 	local function button_OnLeave(self)
 		self.Highlight:Hide();
+		lib:UIDropDownMenu_StartCounting(self:GetParent());
+
 		tooltip:Hide();

 		if ( self.mouseOverIcon ~= nil ) then
@@ -382,12 +391,27 @@ local function creatre_DropDownList(name, parent)
 	f:SetScript("OnClick", function(self)
 		self:Hide()
 	end)
+	f:SetScript("OnEnter", function(self, motion)
+		lib:UIDropDownMenu_StopCounting(self, motion)
+	end)
+	f:SetScript("OnLeave", function(self, motion)
+		lib: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)
 		if ( self.shouldRefresh ) then
 			lib: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)
 	f:SetScript("OnShow", function(self)
 		if ( self.onShow ) then
@@ -404,10 +428,20 @@ local function creatre_DropDownList(name, parent)
 		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
+--[[
+		-- codes by DahkCeles
+		if (WoWClassicEra or WoWClassicTBC) then
+			self.hideTimer = self.hideTimer or C_Timer.NewTicker(L_UIDROPDOWNMENU_SHOW_TIME, function()
+				if (GetMouseFocus() ~= self) then
+					self:Hide();
+				end
+			end)
+		end
+]]
 	end)
 	f:SetScript("OnHide", function(self)
 		local id = self:GetID()
@@ -428,6 +462,13 @@ local function creatre_DropDownList(name, parent)

 			self.customFrames = nil;
 		end
+--[[
+		-- codes by DahkCeles
+		if (self.hideTimer) then
+			self.hideTimer:Cancel();
+			self.hideTimer = nil;
+		end
+]]
 	end)

 	return f
@@ -443,6 +484,9 @@ local function create_DropDownMenu(name, parent)
 	else
 		f = CreateFrame("Frame", name, parent or nil)
 	end
+
+	if not name then name = "" end
+
 	f:SetSize(40, 32)

 	f.Left = f:CreateTexture(name.."Left", "ARTWORK")
@@ -653,6 +697,26 @@ function lib:UIDropDownMenu_RefreshDropDownSize(self)
 	end
 end

+-- Start the countdown on a frame
+function lib:UIDropDownMenu_StartCounting(frame)
+	if ( frame.parent ) then
+		lib:UIDropDownMenu_StartCounting(frame.parent);
+	else
+		frame.showTimer = L_UIDROPDOWNMENU_SHOW_TIME;
+		frame.isCounting = 1;
+	end
+end
+
+-- Stop the countdown on a frame
+function lib:UIDropDownMenu_StopCounting(frame)
+	if ( frame.parent ) then
+		lib:UIDropDownMenu_StopCounting(frame.parent);
+	else
+		frame.isCounting = nil;
+	end
+end
+
+
 --[[
 List of button attributes
 ======================================================
@@ -1057,7 +1121,7 @@ function lib: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
-		if WoWClassic then
+		if (WoWClassicEra or WoWClassicTBC) 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);
@@ -1548,6 +1612,10 @@ function lib: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

@@ -1584,6 +1652,11 @@ local function containsMouse()
 	return result;
 end

+function lib:containsMouse()
+	containsMouse()
+end
+
+-- GLOBAL_MOUSE_DOWN event is only available in retail, not classic
 function lib:UIDropDownMenu_HandleGlobalMouseEvent(button, event)
 	if event == "GLOBAL_MOUSE_DOWN" and (button == "LeftButton" or button == "RightButton") then
 		if not containsMouse() then