Quantcast

Fix ticket 246 - Option to disable in pet battles

Johnny C. Lam [09-28-13 - 12:50]
Fix ticket 246 - Option to disable in pet battles

Instead of an option, always hide Ovale when the Pet Battle UI is active.
This should match player expectations.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1038 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
Ovale.lua
OvaleFrame.lua
diff --git a/Ovale.lua b/Ovale.lua
index 877e027..a9f471a 100644
--- a/Ovale.lua
+++ b/Ovale.lua
@@ -165,27 +165,31 @@ function Ovale:UpdateLastSpellcast(spellcast)
 end

 function Ovale:UpdateVisibility()
+	local visible = true
 	local profile = OvaleOptions:GetProfile()

-	if not profile.display then
-		self.frame:Hide()
-		return
+	if not self.frame.hider:IsVisible() then
+		visible = false
+	elseif not profile.display then
+		visible = false
+	else
+		if profile.apparence.hideVehicule and API_UnitHasVehicleUI("player") then
+			visible = false
+		end
+		if profile.apparence.avecCible and not API_UnitExists("target") then
+			visible = false
+		end
+		if profile.apparence.enCombat and not Ovale.enCombat then
+			visible = false
+		end
+		if profile.apparence.targetHostileOnly and (API_UnitIsDead("target") or not API_UnitCanAttack("player", "target")) then
+			visible = false
+		end
 	end

-	self.frame:Show()
-	if profile.apparence.hideVehicule and API_UnitHasVehicleUI("player") then
-		self.frame:Hide()
-	end
-
-	if profile.apparence.avecCible and not API_UnitExists("target") then
-		self.frame:Hide()
-	end
-
-	if profile.apparence.enCombat and not Ovale.enCombat then
-		self.frame:Hide()
-	end
-
-	if profile.apparence.targetHostileOnly and (API_UnitIsDead("target") or not API_UnitCanAttack("player", "target")) then
+	if visible then
+		self.frame:Show()
+	else
 		self.frame:Hide()
 	end
 end
diff --git a/OvaleFrame.lua b/OvaleFrame.lua
index ffaa159..43e03fc 100644
--- a/OvaleFrame.lua
+++ b/OvaleFrame.lua
@@ -31,6 +31,7 @@ do
 	local API_GetSpellInfo = GetSpellInfo
 	local API_GetSpellTexture = GetSpellTexture
 	local API_GetTime = GetTime
+	local API_RegisterStateDriver = RegisterStateDriver
 --</private-static-properties>

 --<public-methods>
@@ -423,7 +424,12 @@ do
 	end

 	local function Constructor()
-		local frame = API_CreateFrame("Frame",nil,UIParent)
+		-- Create parent frame for Ovale that auto-hides/shows based on whether the Pet Battle UI is active.
+		local hider = API_CreateFrame("Frame", "OvalePetBattleFrameHider", UIParent, "SecureHandlerStateTemplate")
+		hider:SetAllPoints(true)
+		API_RegisterStateDriver(hider, "visibility", "[petbattle] hide; show")
+
+		local frame = API_CreateFrame("Frame", nil, hider)
 		local self = {}
 		local profile = OvaleOptions:GetProfile()

@@ -444,6 +450,7 @@ do
 		self.localstatus = {}
 		self.actions = {}
 		self.frame = frame
+		self.hider = hider
 		self.updateFrame = API_CreateFrame("Frame")
 		self.barre = self.frame:CreateTexture();
 		self.content = API_CreateFrame("Frame",nil,frame)