Skip to content

Commit

Permalink
Update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ntowle committed Dec 16, 2023
1 parent 562192f commit 2a350b4
Showing 1 changed file with 48 additions and 56 deletions.
104 changes: 48 additions & 56 deletions MapPinTimers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local fullAlpha = true -- this should be user configurable eventually
-- set up event frame
local eventFrame = CreateFrame("Frame")
eventFrame:SetScript('OnEvent', function(self, event, ...)
if self[event] then return self[event](...) end
if self[event] then return self[event](...) end
end)

-- anchor time text
Expand All @@ -21,68 +21,60 @@ SuperTrackedFrame.TimeText:SetPoint("TOP", SuperTrackedFrame.Icon, "BOTTOM", 0,
-- auto-track new map pins
eventFrame:RegisterEvent("USER_WAYPOINT_UPDATED")
function eventFrame:USER_WAYPOINT_UPDATED()
if C_Map.HasUserWaypoint() then
C_Timer.After(0, function()
C_SuperTrack.SetSuperTrackedUserWaypoint(true)
end)
end
if C_Map.HasUserWaypoint() then
C_Timer.After(0, function()
C_SuperTrack.SetSuperTrackedUserWaypoint(true)
end)
end
end

-- override frame alpha to full opacity so the timer is useful
do
local oldAlpha = SuperTrackedFrame.GetTargetAlphaBaseValue
function SuperTrackedFrame:GetTargetAlphaBaseValue()
return fullAlpha and 1 or oldAlpha(self)
end
local oldAlpha = SuperTrackedFrame.GetTargetAlphaBaseValue
function SuperTrackedFrame:GetTargetAlphaBaseValue()
return fullAlpha and 1 or oldAlpha(self)
end
end

-- replaces UpdateDistanceText from Blizzard_QuestNavigation/SuperTrackedFrame.lua
do
local throttle = 0
local lastDistance = nil
local function UpdateDistanceTextWithTimer(self, elapsed)
self.DistanceText:SetShown(not self.isClamped)
local throttle = 0
local lastDistance = nil
local function UpdateDistanceTextWithTimer(self, elapsed)
self.DistanceText:SetShown(not self.isClamped)
if not self.isClamped then
local distance = C_Navigation.GetDistance()
throttle = throttle + elapsed
if throttle >= .5 then
local speed = lastDistance and ((lastDistance - distance) / throttle) or 0
lastDistance = distance
if speed > 0 then
local time = abs(distance / speed)
self.TimeText:SetText(TIMER_MINUTES_DISPLAY:format(floor(time / 60), floor(time % 60)))
self.TimeText:SetShown(true)
else
self.TimeText:SetShown(false)
end
throttle = 0
end
self.DistanceText:SetText(IN_GAME_NAVIGATION_RANGE:format(Round(distance)))
else
self.TimeText:SetShown(false)
lastDistance = nil
end
end

if not self.isClamped then
local distance = C_Navigation.GetDistance()

throttle = throttle + elapsed
if throttle >= .5 then
local speed = lastDistance and ((lastDistance - distance) / throttle) or 0
lastDistance = distance

if speed > 0 then
local time = abs(distance / speed)
self.TimeText:SetText(TIMER_MINUTES_DISPLAY:format(floor(time / 60), floor(time % 60)))
self.TimeText:SetShown(true)
else
self.TimeText:SetShown(false)
end

throttle = 0
end

self.DistanceText:SetText(IN_GAME_NAVIGATION_RANGE:format(Round(distance)))
else
self.TimeText:SetShown(false)
lastDistance = nil
end
end

-- replaces OnUpdate from Blizzard_QuestNavigation/SuperTrackedFrame.lua
local function OnUpdateTimer(self, elapsed)
self:CheckInitializeNavigationFrame(false)

if self.navFrame then
self:UpdateClampedState()
self:UpdatePosition()
self:UpdateArrow()

-- this replaces the original self:UpdateDistanceText
UpdateDistanceTextWithTimer(self, elapsed)

self:UpdateAlpha()
end
end
SuperTrackedFrame:SetScript("OnUpdate", OnUpdateTimer)
-- replaces OnUpdate from Blizzard_QuestNavigation/SuperTrackedFrame.lua
local function OnUpdateTimer(self, elapsed)
self:CheckInitializeNavigationFrame(false)
if self.navFrame then
self:UpdateClampedState()
self:UpdatePosition()
self:UpdateArrow()
-- this replaces the original self:UpdateDistanceText
UpdateDistanceTextWithTimer(self, elapsed)
self:UpdateAlpha()
end
end
SuperTrackedFrame:SetScript("OnUpdate", OnUpdateTimer)
end

0 comments on commit 2a350b4

Please sign in to comment.