-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.lua
More file actions
483 lines (421 loc) · 17.6 KB
/
core.lua
File metadata and controls
483 lines (421 loc) · 17.6 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
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
local addonName, ns = ...
ns.version = C_AddOns.GetAddOnMetadata(..., "Version")
local HandyNotes = LibStub("AceAddon-3.0"):GetAddon("HandyNotes")
local HL = LibStub("AceAddon-3.0"):NewAddon("UniversalExplorer", "AceEvent-3.0")
ns.HL = HL
ns.icon = "Interface\\Addons\\" .. addonName .. "\\icon"
---------------------------------------------------------------------------------------------------
-- Plugin Handlers to HandyNotes
---------------------------------------------------------------------------------------------------
local HLHandler = {}
local tip = {}
local info = {}
ns.points = {}
local horizontal_line = CreateAtlasMarkup("Timer-Fill", 275, 1)
local db
local defaults = {profile = {icon_scale = 1.0, icon_alpha = 1.0}}
local options = {
type = "group",
name = "UniversalExplorer",
desc = "UniversalExplorer",
get = function(info) return db[info[#info]] end,
set = function(info, v)
db[info[#info]] = v
HL:SendMessage("HandyNotes_NotifyUpdate", "UniversalExplorer")
end,
args = {
desc = {
name = "These settings control the look and feel of the icon.",
type = "description",
order = 0
},
icon_scale = {
type = "range",
name = "Icon Scale",
desc = "The scale of the icons",
min = 0.25,
max = 2,
step = 0.01,
arg = "icon_scale",
order = 10
},
icon_alpha = {
type = "range",
name = "Icon Alpha",
desc = "The alpha transparency of the icons",
min = 0,
max = 1,
step = 0.01,
arg = "icon_alpha",
order = 20
}
}
}
---------------------------------------------------------------------------------------------------
-- Debug functions
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
-- Print text to the General Chat
---------------------------------------------------------------------------------------------------
local function DebugPrint(message)
-- enable these line for debugging information
-- if DEFAULT_CHAT_FRAME then
-- DEFAULT_CHAT_FRAME:AddMessage("|cff33ff99[" .. addonName .. "]|r: " ..
-- message)
-- end
end
---------------------------------------------------------------------------------------------------
-- Turn any Table into something printable
---------------------------------------------------------------------------------------------------
local function TableToString(tbl, indent)
if not indent then indent = 0 end
local toprint = string.rep(" ", indent) .. "{\n"
indent = indent + 2
for k, v in pairs(tbl) do
toprint = toprint .. string.rep(" ", indent)
if (type(k) == "number") then
toprint = toprint .. "[" .. k .. "] = "
elseif (type(k) == "string") then
toprint = toprint .. k .. "= "
end
if (type(v) == "number") then
toprint = toprint .. v .. ",\n"
elseif (type(v) == "string") then
toprint = toprint .. "\"" .. v .. "\",\n"
elseif (type(v) == "table") then
toprint = toprint .. TableToString(v, indent + 2) .. ",\n"
else
toprint = toprint .. "\"" .. tostring(v) .. "\",\n"
end
end
toprint = toprint .. string.rep(" ", indent - 2) .. "}"
return toprint
end
---------------------------------------------------------------------------------------------------
-- Plugin Functions
---------------------------------------------------------------------------------------------------
------------------------------------------
-- Create TomTom Way Point
------------------------------------------
local function addTomTomWaypoint(button, uiMapID, coord)
DebugPrint("Adding TomTom Waypoint")
if TomTom then
local x, y = HandyNotes:getXY(coord)
TomTom:AddWaypoint(uiMapID, x, y, {
title = tip.title,
persistent = nil,
minimap = true,
world = true
})
end
end
------------------------------------------
-- Create Blizzard Way Point
------------------------------------------
local function addBlizzardWaypoint(button, uMapID, coord)
DebugPrint("Adding Blizzard Waypoint")
local x, y = HandyNotes:getXY(coord)
local parentMapID = C_Map.GetMapInfo(uMapID)["parentMapID"]
if (not C_Map.CanSetUserWaypointOnMap(uMapID)) then
local wx, wy = HBD:GetWorldCoordinatesFromZone(x, y, uMapID)
uMapID = parentMapID
x, y = HBD:GetZoneCoordinatesFromWorld(wx, wy, parentMapID)
end
C_Map.SetUserWaypoint(UiMapPoint.CreateFromCoordinates(uMapID, x, y))
C_SuperTrack.SetSuperTrackedUserWaypoint(true)
end
------------------------------------------
-- Close Context Menu
------------------------------------------
local function closeAllDropdowns() CloseDropDownMenus(1) end
------------------------------------------
-- Create Context Menu
------------------------------------------
do
DebugPrint("Creating Context Menu")
local currentMapID, currentCoord = nil, nil
local function generateMenu(button, level)
if (not level) then return end
wipe(info)
if (level == 1) then
------------------------------------------
-- Create Context Menu Title
------------------------------------------
info.isTitle = 1
info.text =
"|cff3399ff" .. "HandyNotes Universal Explorer" .. "|r" ..
"|cffFFFFFF " .. ns.version .. "|r"
info.notCheckable = 1
UIDropDownMenu_AddButton(info, level)
wipe(info)
------------------------------------------
-- Create Blizzard Waypoint Menu item
------------------------------------------
info.text = "Create Blizzard Waypoint"
info.notCheckable = 1
info.func = addBlizzardWaypoint
info.arg1 = currentMapID
info.arg2 = currentCoord
UIDropDownMenu_AddButton(info, level)
wipe(info)
------------------------------------------
-- Create TomTom Waypoint Menu item
------------------------------------------
if (C_AddOns.IsAddOnLoaded("TomTom")) then
info.text = "Create TomTom Waypoint"
info.notCheckable = 1
info.func = addTomTomWaypoint
info.arg1 = currentMapID
info.arg2 = currentCoord
UIDropDownMenu_AddButton(info, level)
wipe(info)
end
------------------------------------------
-- Close Menu
------------------------------------------
info.text = "Close"
info.notCheckable = 1
info.func = closeAllDropdowns
info.arg1 = currentMapID
info.arg2 = currentCoord
UIDropDownMenu_AddButton(info, level)
wipe(info)
end
end
------------------------------------------
-- Initialize Context Menu
------------------------------------------
local HL_Dropdown = CreateFrame("Frame", addonName .. "DropdownMenu")
HL_Dropdown.displayMode = "MENU"
HL_Dropdown.initialize = generateMenu
------------------------------------------
-- Initialize Context Menu
------------------------------------------
function HLHandler:OnClick(button, down, uiMapID, coord)
DebugPrint("Clicking Event")
currentMapID, currentCoord = uiMapID, coord
if button == "RightButton" and not down then
ToggleDropDownMenu(1, nil, HL_Dropdown, self, 0, 0)
end
end
end
------------------------------------------
-- Create Pin Point
------------------------------------------
do
DebugPrint("Creating Pin Point")
local function iter(t, prestate)
if not t then return nil end
local state, value = next(t, prestate)
while state do
if value then
------------------------------------------
-- Create Icon
------------------------------------------
local icon, alpha, scale
scale = (value.scale or 1) * db.icon_scale
alpha = (value.alpha or 1) * db.icon_alpha
if value.achievement then
local playerName = UnitName("player") or nil
local playerNameFromAchievement = select(6,
GetAchievementCriteriaInfoByID(
value.achievement,
value.criteria)) or
nil
if (playerName ~= playerNameFromAchievement) then
DebugPrint("setting icon")
icon = ns.icon
end
end
------------------------------------------
-- Get next data
------------------------------------------
return state, nil, icon, scale, alpha
end
state, value = next(t, state)
end
return nil, nil, nil, nil
end
------------------------------------------
-- Get Nodes
------------------------------------------
function HLHandler:GetNodes2(uiMapID, minimap)
DebugPrint("GetNodes2")
return iter, ns.points[uiMapID], nil
end
end
------------------------------------------
-- Create Tooltip
------------------------------------------
function HLHandler:OnEnter(uiMapID, coord)
DebugPrint("OnEnter")
local tooltip = GameTooltip
if (self:GetCenter() > UIParent:GetCenter()) then -- compare X coordinate
tooltip:SetOwner(self, "ANCHOR_LEFT")
else
tooltip:SetOwner(self, "ANCHOR_RIGHT")
end
local value = ns.points[uiMapID][coord]
if not value then return nil end
if value.achievement then
tip.x = tonumber(string.sub(coord, 1, 4)) / 100
tip.y = tonumber(string.sub(coord, 5, 8)) / 100
tip.criteriaid = value.criteria
tip.criteriaidText = WrapTextInColorCode(
" id: " .. value.criteria .. "",
"ff" .. "FFCC00")
tip.cirteria = select(1, GetAchievementCriteriaInfoByID(
value.achievement, value.criteria))
tip.achievementid = value.achievement
tip.achievementidText = WrapTextInColorCode(
" id: " .. value.achievement .. "",
"ff" .. "FFFFFF")
tip.achievement = select(2, GetAchievementInfo(value.achievement))
tip.description = value.description or
"Revealing the covered areas of the world map."
tip.coord = value.coord or tip.x .. "," .. tip.y
tip.note = value.note
tip.source = value.source or "Wowhead"
tip.thanks = value.thanks or "Tykes"
end
------------------------------------------------------------------------------------
if tip.criteriaid then
if (value.criteria == 0) then tip.cirteria = value.criteriaName end
if tip.coord then
tooltip:AddDoubleLine(tip.cirteria, tip.coord, 0.2, 0.6, 1, 1, 1, 1)
else
tooltip:AddLine(tip.cirteria, 0.2, 0.6, 1, true)
end
tooltip:AddLine(horizontal_line)
if tip.achievement then
tooltip:AddLine(tip.achievement, 0.2, 0.6, 1)
end
if tip.description then
tooltip:AddLine(" ")
tooltip:AddLine(tip.description .. " ", 1, 1, 1, true)
end
tooltip:AddLine(" ")
tooltip:AddLine("Right click to open menu")
tooltip:AddLine(horizontal_line)
tooltip:AddDoubleLine("|cffFFFFFFAchievement id:|r " ..
tip.achievementid, (value.criteria == 0) and
"" or "|cffFFFFFFCriteria id:|r " ..
tip.criteriaid)
tooltip:AddLine(" ")
if tip.source then
tooltip:AddDoubleLine("Source:", tip.source, 1, 1, 1, 0.2, 0.6, 1)
end
if tip.thanks then
tooltip:AddDoubleLine("Thanks to:", tip.thanks, 1, 1, 1)
end
end
tooltip:Show()
end
function HLHandler:OnLeave(uiMapID, coord)
DebugPrint("OnLeave")
GameTooltip:Hide() -- This will hide the tooltip when the mouse leaves the node
end
---------------------------------------------------------------------------------------------------
-- Handle Minimap Icons (Zone Map)
---------------------------------------------------------------------------------------------------
function HL:RefreshZoneMap()
if not Minimap or not Minimap:IsShown() then return end
local mapID = C_Map.GetBestMapForUnit("player")
if not mapID then return end
-- Remove any existing icons
if self.minimapPins then
for _, pin in pairs(self.minimapPins) do
pin:Hide()
pin:SetParent(nil)
end
else
self.minimapPins = {}
end
for coord, data in pairs(ns.points[mapID] or {}) do
local x, y = HandyNotes:getXY(coord)
local pin = CreateFrame("Frame", nil, Minimap)
pin:SetSize(12 * db.icon_scale, 12 * db.icon_scale)
local texture = pin:CreateTexture(nil, "OVERLAY")
texture:SetAllPoints(pin)
texture:SetTexture(ns.icon)
pin.texture = texture
pin:SetAlpha(db.icon_alpha)
pin:SetPoint("CENTER", Minimap, "CENTER", x * Minimap:GetWidth(),
-y * Minimap:GetHeight())
pin:Show()
table.insert(self.minimapPins, pin)
end
end
function HL:RefreshBattleMap()
local mapID = C_Map.GetBestMapForUnit("player")
if not mapID then return end
if not BattlefieldMapFrame or not BattlefieldMapFrame:IsShown() then return end
-- Remove any existing icons
if self.battleMapPins then
for _, pin in pairs(self.battleMapPins) do
pin:Hide()
pin:SetParent(nil)
end
else
self.battleMapPins = {}
end
local zoneMapFrame = BattlefieldMapFrame.ScrollContainer
if not zoneMapFrame then return end
for coord, data in pairs(ns.points[mapID] or {}) do
local x, y = HandyNotes:getXY(coord)
local pin = CreateFrame("Frame", nil, zoneMapFrame)
pin:SetSize(16 * db.icon_scale, 16 * db.icon_scale)
local texture = pin:CreateTexture(nil, "OVERLAY")
texture:SetAllPoints(pin)
texture:SetTexture(ns.icon)
pin.texture = texture
pin:SetAlpha(db.icon_alpha)
pin:SetPoint("CENTER", zoneMapFrame, "TOPLEFT", x * zoneMapFrame:GetWidth(),
-y * zoneMapFrame:GetHeight())
pin:Show()
table.insert(self.battleMapPins, pin)
end
end
---------------------------------------------------------------------------------------------------
-- Safely interact with BattlefieldMapFrame when it's available
---------------------------------------------------------------------------------------------------
local function SetupBattlefieldMapHooks()
if not BattlefieldMapFrame then
-- Delay until BattlefieldMapFrame is available
C_Timer.After(1, SetupBattlefieldMapHooks)
return
end
BattlefieldMapFrame:HookScript("OnShow", function() HL:RefreshBattleMap() end)
BattlefieldMapFrame.ScrollContainer:HookScript("OnSizeChanged", function() HL:RefreshBattleMap() end)
BattlefieldMapFrame.ScrollContainer:HookScript("OnMouseWheel", function() HL:RefreshBattleMap() end)
end
---------------------------------------------------------------------------------------------------
-- Plugin initialization, enabling and disabling
---------------------------------------------------------------------------------------------------
function HL:OnInitialize()
DebugPrint("OnInitialize")
-- Set up our database
self.db = LibStub("AceDB-3.0"):New(addonName .. "DB", defaults)
db = self.db.profile
ns.hidden = self.db.char.hidden
-- Initialize our database with HandyNotes
HandyNotes:RegisterPluginDB("UniversalExplorer", HLHandler, options)
self:RegisterEvent("ZONE_CHANGED", "Refresh")
self:RegisterEvent("ZONE_CHANGED_NEW_AREA", "Refresh")
self:RegisterEvent("ZONE_CHANGED_INDOORS", "Refresh")
self:RegisterEvent("CRITERIA_UPDATE", "Refresh")
self:RegisterEvent("CRITERIA_EARNED", "Refresh")
self:RegisterEvent("CRITERIA_COMPLETE", "Refresh")
self:RegisterEvent("ACHIEVEMENT_EARNED", "Refresh")
self:RegisterEvent("MINIMAP_UPDATE_ZOOM", "RefreshZoneMap")
self:RegisterEvent("MINIMAP_UPDATE_TRACKING", "RefreshZoneMap")
-- Safely set up hooks for the BattlefieldMapFrame
SetupBattlefieldMapHooks()
end
function HL:Refresh()
DebugPrint("Refresh")
self:SendMessage("HandyNotes_NotifyUpdate",
addonName:gsub("HandyNotes_", ""))
self:RefreshZoneMap()
self:RefreshBattleMap()
end