Quantcast

Catchup with elv

Darthpred [09-20-13 - 03:18]
Catchup with elv
Filename
ElvUI_SLE/modules/datatexts/time.lua
diff --git a/ElvUI_SLE/modules/datatexts/time.lua b/ElvUI_SLE/modules/datatexts/time.lua
index 5275898..2730a5d 100755
--- a/ElvUI_SLE/modules/datatexts/time.lua
+++ b/ElvUI_SLE/modules/datatexts/time.lua
@@ -71,23 +71,6 @@ local function CalculateTimeLeft(time)
 	return hour, min, sec
 end

-local function formatResetTime(sec)
-	local d,h,m,s = ChatFrame_TimeBreakDown(floor(sec))
-	if not type(d) == 'number' or not type(h)== 'number' or not type(m) == 'number' or not type(s) == 'number' then
-		return 'N/A'
-	end
-
-	if d > 0 and lockoutFormatString[h>10 and 1 or 2] then
-		return format(lockoutFormatString[h>10 and 1 or 2], d, h, m)
-	end
-	if h > 0 and lockoutFormatString[h>10 and 3 or 4] then
-		return format(lockoutFormatString[h>10 and 3 or 4], h, m)
-	end
-	if m > 0 and lockoutFormatString[m>10 and 5 or 6] then
-		return format(lockoutFormatString[m>10 and 5 or 6], m)
-	end
-end
-
 local function Click()
 	GameTimeFrame:Click();
 end
@@ -97,10 +80,20 @@ local function OnLeave(self)
 	enteredFrame = false;
 end

+local function OnEvent()
+	if event == "UPDATE_INSTANCE_INFO" and enteredFrame then
+		RequestRaidInfo()
+	end
+end
+
 local function OnEnter(self)
 	DT:SetupTooltip(self)
-	enteredFrame = true;
-
+
+	if(not enteredFrame) then
+		enteredFrame = true;
+		RequestRaidInfo()
+	end
+
 	DT.tooltip:AddLine(VOICE_CHAT_BATTLEGROUND);
 	for i = 1, GetNumWorldPVPAreas() do
 		_, localizedName, isActive, canQueue, startTime, canEnter = GetWorldPVPAreaInfo(i)
@@ -110,16 +103,11 @@ local function OnEnter(self)
 			elseif startTime == nil then
 				startTime = QUEUE_TIME_UNAVAILABLE
 			else
-				local h, m, s = CalculateTimeLeft(startTime)
-				if h > 0 then
-					startTime = format(timerLongFormat, h, m, s)
-				else
-					startTime = format(timerShortFormat, m, s)
-				end
+				startTime = SecondsToTime(startTime, false, nil, 3)
 			end
 			DT.tooltip:AddDoubleLine(format(formatBattleGroundInfo, localizedName), startTime, 1, 1, 1, lockoutColorNormal.r, lockoutColorNormal.g, lockoutColorNormal.b)
 		end
-	end
+	end

 	--LFR lockout text
 	if E.db.sle.lfrshow.enabled then
@@ -128,21 +116,25 @@ local function OnEnter(self)

 	local oneraid, lockoutColor
 	for i = 1, GetNumSavedInstances() do
-		name, _, reset, _, locked, extended, _, isRaid, maxPlayers, difficulty, numEncounters, encounterProgress  = GetSavedInstanceInfo(i)
+		name, _, reset, difficultyId, locked, extended, _, isRaid, maxPlayers, difficulty, numEncounters, encounterProgress  = GetSavedInstanceInfo(i)
 		if isRaid and (locked or extended) and name then
-			local tr,tg,tb,diff
 			if not oneraid then
 				DT.tooltip:AddLine(" ")
 				DT.tooltip:AddLine(L["Saved Raid(s)"])
 				oneraid = true
 			end
-			if extended then lockoutColor = lockoutColorExtended else lockoutColor = lockoutColorNormal end
+			if extended then
+				lockoutColor = lockoutColorExtended
+			else
+				lockoutColor = lockoutColorNormal
+			end

+			local _, _, isHeroic, _ = GetDifficultyInfo(difficultyId)
 			if (numEncounters and numEncounters > 0) and (encounterProgress and encounterProgress > 0) then
-				DT.tooltip:AddDoubleLine(format(lockoutInfoFormat, maxPlayers, (difficulty:match("Heroic") and "H" or "N"), name, encounterProgress, numEncounters), formatResetTime(reset), 1,1,1, lockoutColor.r,lockoutColor.g,lockoutColor.b)
+				DT.tooltip:AddDoubleLine(format(lockoutInfoFormat, maxPlayers, (isHeroic and "H" or "N"), name, encounterProgress, numEncounters), SecondsToTime(reset, false, nil, 3), 1, 1, 1, lockoutColor.r, lockoutColor.g, lockoutColor.b)
 			else
-				DT.tooltip:AddDoubleLine(format(lockoutInfoFormatNoEnc, maxPlayers, (difficulty:match("Heroic") and "H" or "N"), name), formatResetTime(reset), 1,1,1, lockoutColor.r,lockoutColor.g,lockoutColor.b)
-			end
+				DT.tooltip:AddDoubleLine(format(lockoutInfoFormatNoEnc, maxPlayers, (isHeroic and "H" or "N"), name), SecondsToTime(reset, false, nil, 3), 1, 1, 1, lockoutColor.r, lockoutColor.g, lockoutColor.b)
+			end
 		end
 	end

@@ -185,19 +177,19 @@ end
 local int = 3
 function Update(self, t)
 	int = int - t
-
-	if enteredFrame then
-		OnEnter(self)
-	end
+
+	if int > 0 then return end

 	if GameTimeFrame.flashInvite then
 		E:Flash(self, 0.53)
 	else
 		E:StopFlash(self)
+	end
+
+	if enteredFrame then
+		OnEnter(self)
 	end
-
-	if int > 0 then return end
-
+
 	local Hr, Min, AmPm = CalculateTimeValues(false)

 	-- no update quick exit
@@ -218,7 +210,6 @@ function Update(self, t)
 	lastPanel = self
 	int = 5
 end
-
 --[[
 	DT:RegisterDatatext(name, events, eventFunc, updateFunc, clickFunc, onEnterFunc, onLeaveFunc)

@@ -230,4 +221,4 @@ end
 	onEnterFunc - function to fire OnEnter
 	onLeaveFunc - function to fire OnLeave, if not provided one will be set for you that hides the tooltip.
 ]]
-DT:RegisterDatatext('Time', nil, nil, Update, Click, OnEnter, OnLeave)
\ No newline at end of file
+DT:RegisterDatatext('Time', {"UPDATE_INSTANCE_INFO"}, OnEvent, Update, Click, OnEnter, OnLeave)
\ No newline at end of file