-
Notifications
You must be signed in to change notification settings - Fork 4
/
Waypoints.lua
457 lines (377 loc) · 14.1 KB
/
Waypoints.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
local tooltip = CreateFrame("GameTooltip", "TomTomTooltip", UIParent, "GameTooltipTemplate")
-- Store a reference to the minimap parent
local minimapParent = Minimap
-- Create a local table used as a frame pool
local pool = {}
local all_points = {}
-- Local declarations
local Minimap_OnEnter,Minimap_OnLeave,Minimap_OnUpdate,Minimap_OnClick,Minimap_OnEvent
local Arrow_OnUpdate
local World_OnEnter,World_OnLeave,World_OnClick
local square_half = math.sqrt(0.5)
local rad_135 = math.rad(135)
local function rotateArrow(self)
if self.disabled then return end
local angle = Astrolabe:GetDirectionToIcon(self)
if not angle then return self:Hide() end
angle = math.rad(angle) + rad_135
-- why the hell is this in degrees from atan2 method?
-- if GetCVar("rotateMinimap") == "1" then
-- --local cring = MiniMapCompassRing:GetFacing()
-- local cring = self:GetPlayerFacing()
-- angle = angle - cring
-- end
local sin,cos = math.sin(angle), math.cos(angle) -- math.sin(angle) * square_half, math.cos(angle) * square_half
self.arrow:SetTexCoord(0.5-sin, 0.5+cos, 0.5+cos, 0.5+sin, 0.5-cos, 0.5-sin, 0.5+sin, 0.5-cos)
end
function TomTom:ReparentMinimap(minimap)
minimapParent = minimap
for idx, waypoint in ipairs(all_points) do
waypoint:SetParent(minimap)
end
end
local waypointMap = {}
function TomTom:SetWaypoint(waypoint, callbacks, show_minimap, show_world)
if waypointMap[waypoint] then return end
local m, f, x, y = waypoint.continent, waypoint.zone, waypoint.x, waypoint.y
-- Try to acquire a waypoint from the frame pool
local point = table.remove(pool)
if not point then
point = {}
local minimap = CreateFrame("Button", nil, minimapParent)
minimap:SetHeight(20)
minimap:SetWidth(20)
minimap:RegisterForClicks("RightButtonUp")
-- Add to the "All points" table so we can reparent easily
table.insert(all_points, minimap)
minimap.icon = minimap:CreateTexture("BACKGROUND")
minimap.icon:SetTexture("Interface\\AddOns\\TomTom\\Images\\GoldGreenDot")
minimap.icon:SetPoint("CENTER", 0, 0)
minimap.icon:SetHeight(12)
minimap.icon:SetWidth(12)
minimap.arrow = minimap:CreateTexture("BACKGROUND")
minimap.arrow:SetTexture("Interface\\AddOns\\TomTom\\Images\\MinimapArrow-Green")
minimap.arrow:SetPoint("CENTER", 0 ,0)
minimap.arrow:SetHeight(40)
minimap.arrow:SetWidth(40)
minimap.arrow:Hide()
-- Add the behavior scripts
minimap:SetScript("OnEnter", Minimap_OnEnter)
minimap:SetScript("OnLeave", Minimap_OnLeave)
minimap:SetScript("OnUpdate", Minimap_OnUpdate)
minimap:SetScript("OnClick", Minimap_OnClick)
minimap:RegisterEvent("PLAYER_ENTERING_WORLD")
minimap:SetScript("OnEvent", Minimap_OnEvent)
if not TomTomMapOverlay then
local overlay = CreateFrame("Frame", "TomTomMapOverlay", WorldMapButton)
overlay:SetAllPoints(true)
overlay:SetScript("OnUpdate", self.RedrawWorldMapIcons)
overlay:SetFrameLevel(WorldMapButton:GetFrameLevel() + 1)
end
local worldmap = CreateFrame("Button", nil, TomTomMapOverlay)
worldmap:SetHeight(12)
worldmap:SetWidth(12)
worldmap:RegisterForClicks("RightButtonUp")
worldmap.icon = worldmap:CreateTexture("ARTWORK")
worldmap.icon:SetAllPoints()
worldmap.icon:SetTexture("Interface\\AddOns\\TomTom\\Images\\GoldGreenDot")
worldmap:RegisterEvent("WORLD_MAP_UPDATE")
worldmap:SetScript("OnEnter", World_OnEnter)
worldmap:SetScript("OnLeave", World_OnLeave)
worldmap:SetScript("OnClick", World_OnClick)
point.worldmap = worldmap
point.minimap = minimap
end
waypointMap[waypoint] = point
point.m = m
point.f = f
point.x = x
point.y = y
point.show_world = show_world
point.show_minimap = show_minimap
point.callbacks = callbacks
point.worldmap.callbacks = callbacks and callbacks.world
point.minimap.callbacks = callbacks and callbacks.minimap
-- Process the callbacks table to put distances in a consumable format
if callbacks and callbacks.distance then
point.dlist = {}
for k,v in pairs(callbacks.distance) do
table.insert(point.dlist, k)
end
table.sort(point.dlist)
end
-- Clear the state for callbacks
point.state = nil
point.lastdist = nil
-- Link the actual frames back to the waypoint object
point.minimap.point = point
point.worldmap.point = point
point.uid = waypoint
-- Place the waypoint
Astrolabe:PlaceIconOnMinimap(point.minimap, m, f, x, y)
--hbdp:AddMinimapIconMF(self, point.minimap, m, f, x, y, true)
if show_world then
point.worldmap.disabled = false
local xx, yy = Astrolabe:PlaceIconOnWorldMap(WorldMapButton, point.worldmap, point.m, point.f, point.x, point.y)
if(xx and yy and xx > 0 and xx < 1 and yy > 0 and yy < 1) then
point.worldmap:Show()
else
point.worldmap:Hide()
end
--hbdp:AddWorldMapIconMF(self, point.worldmap, m, f, x, y)
else
point.worldmap.disabled = true
end
if not show_minimap then
-- Hide the minimap icon/arrow if minimap is off
point.minimap:EnableMouse(false)
point.minimap.icon:Hide()
point.minimap.arrow:Hide()
point.minimap.disabled = true
rotateArrow(point.minimap)
else
point.minimap:EnableMouse(true)
point.minimap.disabled = false
rotateArrow(point.minimap)
end
end
local LastMapContinent = nil;
local LastMapZone = nil;
function TomTom:RedrawWorldMapIcons()
local c, z = GetCurrentMapContinent(), GetCurrentMapZone();
if(c ~= LastMapContinent or LastMapZone ~= z) then
LastMapContinent = c;
LastMapZone = z;
for uid, point in waypointMap do
if point.worldmap.disabled == false then
local xx, yy = Astrolabe:PlaceIconOnWorldMap(WorldMapButton, point.worldmap, point.m, point.f, point.x, point.y)
if(xx and yy and xx > 0 and xx < 1 and yy > 0 and yy < 1) then
point.worldmap:Show()
else
point.worldmap:Hide()
end
end
end
end
end
function TomTom:HideWaypoint(uid, minimap, worldmap)
local point = waypointMap[uid]
if point then
if minimap then
point.minimap.disabled = true
point.minimap:Hide()
end
if worldmap then
point.worldmap.disabled = true
point.worldmap:Hide()
end
end
end
function TomTom:ShowWaypoint(uid)
local point = waypointMap[uid]
if point then
point.minimap.disabled = not point.data.show_minimap
point.minimap:Show()
point.worldmap.disabled = not point.data.show_worldmap
point.worldmap:Show()
end
end
-- This function removes the waypoint from the active set
function TomTom:ClearWaypoint(uid)
local point = waypointMap[uid]
if point then
Astrolabe:RemoveIconFromMinimap(point.minimap)
--hbdp:RemoveMinimapIcon(self, point.minimap)
--hbdp:RemoveWorldMapIcon(self, point.worldmap)
point.minimap:Hide()
point.worldmap:Hide()
-- Clear our handles to the callback tables
point.callbacks = nil
point.minimap.callbacks = nil
point.worldmap.callbacks = nil
-- Clear disabled flags
point.minimap.disabled = nil
point.worldmap.disabled = nil
point.dlist = nil
point.uid = nil
table.insert(pool, point)
waypointMap[uid] = nil
end
end
function TomTom:GetDistanceToWaypoint(uid)
local point = waypointMap[uid]
return point and Astrolabe:GetDistanceToIcon(point.minimap)
end
function TomTom:GetDirectionToWaypoint(uid)
local point = waypointMap[uid]
return point and Astrolabe:GetDirectionToIcon(point.minimap)
end
function TomTom:IsMinimapIconOnEdge(icon)
--local function placeIconOnMinimap( minimap, minimapZoom, mapWidth, mapHeight, icon, dist, xDist, yDist )
local minimapZoom = Minimap:GetZoom();
local mapWidth = Minimap:GetWidth();
local mapHeight = Minimap:GetHeight();
local data = Astrolabe.MinimapIcons[icon]
local mapDiameter;
if ( Astrolabe.minimapOutside ) then
mapDiameter = MinimapSize.outdoor[minimapZoom];
else
mapDiameter = MinimapSize.indoor[minimapZoom];
end
local mapRadius = mapDiameter / 2;
local xScale = mapDiameter / mapWidth;
local yScale = mapDiameter / mapHeight;
local iconDiameter = ((icon:GetWidth() / 2) -3) * xScale; -- LaYt +3
-- Adding square map support by LaYt
if (Squeenix or (simpleMinimap_Skins and simpleMinimap_Skins:GetShape() == "square")) then
if (math.abs(data.xDist) > (mapWidth/2*xScale)) then
return true
end
if (math.abs(data.yDist) > (mapHeight/2*yScale)) then
return true
end
elseif ( (data.dist + iconDiameter) > mapRadius ) then
-- position along the outside of the Minimap
return true
end
return false
end
do
local tooltip_uid,tooltip_callbacks
local function tooltip_onupdate(self, elapsed)
if tooltip_callbacks and tooltip_callbacks.tooltip_update then
local dist = TomTom:GetDistanceToWaypoint(tooltip_uid)
tooltip_callbacks.tooltip_update("tooltip_update", tooltip, tooltip_uid, dist)
end
end
function Minimap_OnClick(self, button)
local self = this
local data = self.callbacks
if data and data.onclick then
data.onclick("onclick", self.point.uid, self, button)
end
end
function Minimap_OnEnter()
local self = this
local data = self.callbacks
if data and data.tooltip_show then
local uid = self.point.uid
local dist = TomTom:GetDistanceToWaypoint(uid)
tooltip_uid = uid
tooltip_callbacks = data
-- Parent to UIParent, unless it's hidden
if UIParent:IsVisible() then
tooltip:SetParent(UIParent)
else
tooltip:SetParent(self)
end
tooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT")
data.tooltip_show("tooltip_show", tooltip, uid, dist)
tooltip:Show()
-- Set the update script if there is one
if data.tooltip_update then
tooltip:SetScript("OnUpdate", tooltip_onupdate)
else
tooltip:SetScript("OnUpdate", nil)
end
end
end
function Minimap_OnLeave(self, motion)
tooltip_uid,tooltip_callbacks = nil,nil
tooltip:Hide()
end
World_OnEnter = Minimap_OnEnter
World_OnLeave = Minimap_OnLeave
World_OnClick = Minimap_OnClick
local minimap_count = 0
function Minimap_OnUpdate()
local self = this
local elapsed = 1/GetFramerate()
local angle, dist = Astrolabe:GetDirectionToIcon(self), Astrolabe:GetDistanceToIcon(self)
local disabled = self.disabled
if not dist then
self:Hide()
return
end
minimap_count = minimap_count + elapsed
if minimap_count < 0.1 then return end
-- Reset the counter
minimap_count = 0
local edge = TomTom:IsMinimapIconOnEdge(self)
local data = self.point
local callbacks = data.callbacks
if edge then
-- Check to see if this is a transition
if not disabled then
self.icon:Hide()
self.arrow:Show()
-- Rotate the icon, as required
angle = math.rad(angle) + rad_135
-- why the hell is this in degrees from atan2 method?
-- if GetCVar("rotateMinimap") == "1" then
-- --local cring = MiniMapCompassRing:GetFacing()
-- local cring = GetPlayerFacing()
-- angle = angle - cring
-- end
local sin,cos = math.sin(angle) * square_half, math.cos(angle) * square_half
self.arrow:SetTexCoord(0.5-sin, 0.5+cos, 0.5+cos, 0.5+sin, 0.5-cos, 0.5-sin, 0.5+sin, 0.5-cos)
end
else
if not disabled then
self.icon:Show()
self.arrow:Hide()
end
end
if callbacks and callbacks.distance then
local list = data.dlist
local state = data.state
local newstate
-- Calculate the initial state
if not state then
for i=1,table.getn(list) do
if dist <= list[i] then
state = i
break
end
end
-- Handle the case where we're outside the largest circle
if not state then state = -1 end
data.state = state
else
-- Calculate the new state
for i=1,table.getn(list) do
if dist <= list[i] then
newstate = i
break
end
end
-- Handle the case where we're outside the largest circle
if not newstate then newstate = -1 end
end
-- If newstate is set, then this is a transition
-- If only state is set, this is the initial state
if state ~= newstate then
-- Handle the initial state
newstate = newstate or state
local distance = list[newstate]
local callback = callbacks.distance[distance]
if callback then
callback("distance", data.uid, distance, dist, data.lastdist)
end
data.state = newstate
end
-- Update the last distance with the current distance
data.lastdist = dist
end
end
function Minimap_OnEvent(self, event, ...)
local self = this
if event == "PLAYER_ENTERING_WORLD" then
local data = self.point
if data and data.uid and waypointMap[data.uid] then
--hbdp:AddMinimapIconMF(TomTom, self, data.m, data.f, data.x, data.y, true)
Astrolabe:PlaceIconOnMinimap(self, data.m, data.f, data.x, data.y)
end
end
end
end