Repository navigation
Expand file tree
/
Copy pathhandler.lua
More file actions
226 lines (203 loc) · 6.99 KB
/
Copy pathhandler.lua
File metadata and controls
226 lines (203 loc) · 6.99 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
local myname, ns = ...
local HandyNotes = LibStub("AceAddon-3.0"):GetAddon("HandyNotes")
local HL = LibStub("AceAddon-3.0"):NewAddon(myname, "AceEvent-3.0")
-- local L = LibStub("AceLocale-3.0"):GetLocale(myname, true)
ns.HL = HL
local next = next
local GameTooltip = GameTooltip
local WorldMapTooltip = WorldMapTooltip
local HandyNotes = HandyNotes
local DEFAULT_LABEL = "."
local icon_cache = {}
local function poi_texture(poi)
if not icon_cache[poi] then
local left, right, top, bottom = GetPOITextureCoords(poi)
icon_cache[poi] = {
icon = [[Interface\Addons\HandyNotes_DMF_basic\dmf.tga]],
tCoordLeft = left,
tCoordRight = right,
tCoordTop = top,
tCoordBottom = bottom,
r = 1, g = 0, b = 1,
}
end
return icon_cache[poi]
end
local function atlas_texture(atlas, scale)
if not icon_cache[atlas] then
local texture, _, _, left, right, top, bottom = GetAtlasInfo(atlas)
icon_cache[atlas] = {
icon = texture,
tCoordLeft = left,
tCoordRight = right,
tCoordTop = top,
tCoordBottom = bottom,
scale = scale or 1,
r = 0.8, g = 0, b = 1,
}
end
return icon_cache[atlas]
end
local function work_out_texture(point)
if point.atlas then
return atlas_texture(point.atlas)
end
if point.poi then
return poi_texture(point.poi)
end
if point.npc then
return atlas_texture("DungeonSkull", 1.5)
end
return atlas_texture("MantidTower")
end
local get_point_info = function(point)
if point then
return point.label or DEFAULT_LABEL, work_out_texture(point), point.scale
end
end
local get_point_info_by_coord = function(uiMapID, coord)
return get_point_info(ns.points[uiMapID] and ns.points[uiMapID][coord])
end
local function handle_tooltip(tooltip, point)
if point then
tooltip:AddLine(point.label or DEFAULT_LABEL)
if point.quest and not IsQuestFlaggedCompleted(point.quest) then
tooltip:AddLine(NEED, 1, 0, 0)
end
if point.note then
tooltip:AddLine(point.note, nil, nil, nil, true)
end
else
tooltip:SetText(UNKNOWN)
end
tooltip:Show()
end
local handle_tooltip_by_coord = function(tooltip, uiMapID, coord)
return handle_tooltip(tooltip, ns.points[uiMapID] and ns.points[uiMapID][coord])
end
---------------------------------------------------------
-- Plugin Handlers to HandyNotes
local HLHandler = {}
local info = {}
function HLHandler:OnEnter(uiMapID, coord)
local tooltip = self:GetParent() == WorldMapButton and WorldMapTooltip or GameTooltip
if ( self:GetCenter() > UIParent:GetCenter() ) then -- compare X coordinate
tooltip:SetOwner(self, "ANCHOR_LEFT")
else
tooltip:SetOwner(self, "ANCHOR_RIGHT")
end
handle_tooltip_by_coord(tooltip, uiMapID, coord)
end
local function createWaypoint(button, uiMapID, coord)
if TomTom then
local x, y = HandyNotes:getXY(coord)
TomTom:AddWaypoint(uiMapID, x, y, {
title = get_point_info_by_coord(uiMapID, coord),
persistent = nil,
minimap = true,
world = true
})
end
end
local function hideNode(button, uiMapID, coord)
ns.hidden[uiMapID][coord] = true
HL:Refresh()
end
local function closeAllDropdowns()
CloseDropDownMenus(1)
end
do
local currentZone, currentCoord
local function generateMenu(button, level)
if (not level) then return end
wipe(info)
if (level == 1) then
-- Create the title of the menu
info.isTitle = 1
info.text = "HandyNotes - " .. myname:gsub("HandyNotes_", "")
info.notCheckable = 1
UIDropDownMenu_AddButton(info, level)
wipe(info)
if TomTom then
-- Waypoint menu item
info.text = "Create waypoint"
info.notCheckable = 1
info.func = createWaypoint
info.arg1 = currentZone
info.arg2 = currentCoord
UIDropDownMenu_AddButton(info, level)
wipe(info)
end
-- Hide menu item
info.text = "Hide node"
info.notCheckable = 1
info.func = hideNode
info.arg1 = currentZone
info.arg2 = currentCoord
UIDropDownMenu_AddButton(info, level)
wipe(info)
-- Close menu item
info.text = "Close"
info.func = closeAllDropdowns
info.notCheckable = 1
UIDropDownMenu_AddButton(info, level)
wipe(info)
end
end
local HL_Dropdown = CreateFrame("Frame", myname.."DropdownMenu")
HL_Dropdown.displayMode = "MENU"
HL_Dropdown.initialize = generateMenu
function HLHandler:OnClick(button, down, uiMapID, coord)
if button == "RightButton" and not down then
currentZone = uiMapID
currentCoord = coord
ToggleDropDownMenu(1, nil, HL_Dropdown, self, 0, 0)
end
end
end
function HLHandler:OnLeave(uiMapID, coord)
if self:GetParent() == WorldMapButton then
WorldMapTooltip:Hide()
else
GameTooltip:Hide()
end
end
do
local currentZone
-- This is a custom iterator we use to iterate over every node in a given zone
local function iter(t, prestate)
if not t then return nil end
local state, value = next(t, prestate)
while state do -- Have we reached the end of this zone?
if value and not ns.hidden[currentZone][state] then
local label, icon, scale = get_point_info(value)
scale = (scale or 1) * (icon and icon.scale or 1) * ns.db.icon_scale
return state, nil, icon, scale, ns.db.icon_alpha
end
state, value = next(t, state) -- Get next data
end
return nil, nil, nil, nil
end
function HLHandler:GetNodes2(uiMapID, minimap)
currentZone = uiMapID
return iter, ns.points[uiMapID], nil
end
end
---------------------------------------------------------
-- Addon initialization, enabling and disabling
function HL:OnInitialize()
-- Set up our database
self.db = LibStub("AceDB-3.0"):New(myname.."DB", ns.defaults)
ns.db = self.db.profile
ns.hidden = self.db.char.hidden
-- Initialize our database with HandyNotes
HandyNotes:RegisterPluginDB(myname:gsub("HandyNotes_", ""), HLHandler, ns.options)
-- watch for LOOT_CLOSED
self:RegisterEvent("LOOT_CLOSED")
end
function HL:Refresh()
self:SendMessage("HandyNotes_NotifyUpdate", myname:gsub("HandyNotes_", ""))
end
function HL:LOOT_CLOSED()
self:Refresh()
end