-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapPinTimers.lua
More file actions
177 lines (165 loc) · 6.58 KB
/
MapPinTimers.lua
File metadata and controls
177 lines (165 loc) · 6.58 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
local addonName, MapPinTimers = ...
-- 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, DEFAULT_CHAT_FRAME = SuperTrackedFrame, TIMER_MINUTES_DISPLAY, IN_GAME_NAVIGATION_RANGE, DEFAULT_CHAT_FRAME
-- set up event frame
local EventFrame = CreateFrame("Frame")
EventFrame:SetScript("OnEvent", function(self, event, ...)
if self[event] then return self[event](self, event, ...) end
end)
function MapPinTimers:AddMessage(message)
DEFAULT_CHAT_FRAME:AddMessage(("|cFF00FF98MapPinTimers:|r %s"):format(message))
end
-- set up and validate db, init
function EventFrame:PLAYER_LOGIN(event)
self:UnregisterEvent(event)
if not MapPinTimersDB then
MapPinTimersDB = {}
end
if type(MapPinTimersDB.fullAlpha) ~= "boolean" then
MapPinTimersDB.fullAlpha = true
end
if type(MapPinTimersDB.showDestination) ~= "boolean" then
MapPinTimersDB.showDestination = true
end
self:SUPER_TRACKING_CHANGED()
end
EventFrame:RegisterEvent("PLAYER_LOGIN")
-- register slash commands
function EventFrame:ADDON_LOADED(event, loadedAddon)
if loadedAddon ~= addonName then
return
end
self:UnregisterEvent(event)
SlashCmdList.MapPinTimers = function(text)
if text == "fullAlpha" then
MapPinTimersDB.fullAlpha = not MapPinTimersDB.fullAlpha
MapPinTimers:AddMessage("fullAlpha: "..(MapPinTimersDB.fullAlpha and "true" or "false"))
elseif text == "showDestination" then
MapPinTimersDB.showDestination = not MapPinTimersDB.showDestination
MapPinTimers:AddMessage("showDestination: "..(MapPinTimersDB.showDestination and "true" or "false"))
self:SUPER_TRACKING_CHANGED()
else
MapPinTimers:AddMessage("/mpt [fullAlpha|showDestination]")
end
end
SLASH_MapPinTimers1 = "/mpt"
SLASH_MapPinTimers2 = "/mappintimers"
end
EventFrame:RegisterEvent("ADDON_LOADED")
-- 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)
-- anchor destination text
SuperTrackedFrame.DestinationText = SuperTrackedFrame:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
SuperTrackedFrame.DestinationText:SetJustifyV("TOP")
SuperTrackedFrame.DestinationText:SetSize(0, 20)
SuperTrackedFrame.DestinationText:SetPoint("TOP", SuperTrackedFrame.Icon, "TOP", 0, 22)
-- auto-track new map pins
function EventFrame:USER_WAYPOINT_UPDATED()
if C_Map.HasUserWaypoint() then
C_Timer.After(0, function()
C_SuperTrack.SetSuperTrackedUserWaypoint(true)
end)
end
end
EventFrame:RegisterEvent("USER_WAYPOINT_UPDATED")
-- update destination text
function EventFrame:SUPER_TRACKING_CHANGED()
if not MapPinTimersDB.showDestination then
SuperTrackedFrame.DestinationText:SetText("")
elseif C_SuperTrack.IsSuperTrackingContent() then
local pinType = C_SuperTrack.GetSuperTrackedContent() -- TODO 2nd return?
if pinType == 0 then -- Enum.ContentTrackingType.Appearance
SuperTrackedFrame.DestinationText:SetText("Content: Appearance")
elseif pinType == 1 then -- Enum.ContentTrackingType.Mount
SuperTrackedFrame.DestinationText:SetText("Content: Mount")
elseif pinType == 2 then -- Enum.ContentTrackingType.Achievement
SuperTrackedFrame.DestinationText:SetText("Content: Achievement")
else
SuperTrackedFrame.DestinationText:SetText("Content")
end
elseif C_SuperTrack.IsSuperTrackingCorpse() then
SuperTrackedFrame.DestinationText:SetText("Corpse")
elseif C_SuperTrack.IsSuperTrackingMapPin() then
local pinType = C_SuperTrack.GetSuperTrackedMapPin() -- TODO 2nd return?
if pinType == 0 then -- Enum.SuperTrackingMapPinType.AreaPOI
SuperTrackedFrame.DestinationText:SetText("Map Pin: Area POI")
elseif pinType == 1 then -- Enum.SuperTrackingMapPinType.QuestOffer
SuperTrackedFrame.DestinationText:SetText("Map Pin: Quest Offer")
elseif pinType == 2 then -- Enum.SuperTrackingMapPinType.TaxiNode
SuperTrackedFrame.DestinationText:SetText("Map Pin: Taxi Node")
elseif pinType == 3 then -- Enum.SuperTrackingMapPinType.DigSite
SuperTrackedFrame.DestinationText:SetText("Map Pin: Dig Site")
else
SuperTrackedFrame.DestinationText:SetText("Map Pin")
end
elseif C_SuperTrack.IsSuperTrackingQuest() then
local questID = C_SuperTrack.GetSuperTrackedQuestID()
local questTitle = C_QuestLog.GetTitleForQuestID(questID)
if questTitle then
SuperTrackedFrame.DestinationText:SetText(questTitle)
else
SuperTrackedFrame.DestinationText:SetText("Quest")
end
elseif C_SuperTrack.IsSuperTrackingUserWaypoint() then
SuperTrackedFrame.DestinationText:SetText("Waypoint")
elseif C_SuperTrack.IsSuperTrackingAnything() then
-- TODO what else? Vignette? Item?
SuperTrackedFrame.DestinationText:SetText("Other")
end
end
EventFrame:RegisterEvent("SUPER_TRACKING_CHANGED")
-- override frame alpha to full opacity so the timer is useful
do
local oldAlpha = SuperTrackedFrame.GetTargetAlphaBaseValue
function SuperTrackedFrame:GetTargetAlphaBaseValue()
return MapPinTimersDB.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)
local distance = C_Navigation.GetDistance()
self.DistanceText:SetShown(true)
self.DistanceText:SetText(IN_GAME_NAVIGATION_RANGE:format(GetDistanceString(Round(distance))))
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
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