-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapPinTimers.lua
87 lines (80 loc) · 2.86 KB
/
MapPinTimers.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
-- globals
local C_Map, C_Navigation, C_SuperTrack, C_Timer = C_Map, C_Navigation, C_SuperTrack, C_Timer
local abs, floor, Round, CreateFrame, AbbreviateNumbers = abs, floor, Round, CreateFrame, AbbreviateNumbers
local SuperTrackedFrame, TIMER_MINUTES_DISPLAY, IN_GAME_NAVIGATION_RANGE = SuperTrackedFrame, TIMER_MINUTES_DISPLAY, IN_GAME_NAVIGATION_RANGE
-- locals
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
end)
-- anchor time text
SuperTrackedFrame.TimeText = SuperTrackedFrame:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
SuperTrackedFrame.TimeText:SetJustifyV("TOP")
SuperTrackedFrame.TimeText:SetSize(0, 20)
SuperTrackedFrame.TimeText:SetPoint("TOP", SuperTrackedFrame.Icon, "BOTTOM", 0, -22)
-- 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
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
end
-- replaces UpdateDistanceText from Blizzard_QuestNavigation/SuperTrackedFrame.lua
do
local function GetDistanceString(distance)
if distance < 1000 then
return tostring(distance)
else
return AbbreviateNumbers(distance)
end
end
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(GetDistanceString(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)
end