-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
295 lines (240 loc) · 7.98 KB
/
main.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
if not LibStub then return end
local Dewdrop = LibStub('LibDewdrop-3.0', true)
local LibQTip = LibStub('LibQTip-1.0')
local LibSecureFrame = LibStub('LibSecureFrame-1.0')
local LibIcon = LibStub('LibDBIcon-1.0')
local LibDataBroker = LibStub:GetLibrary('LibDataBroker-1.1')
local _
local CreateFrame = CreateFrame
local GetBindLocation = GetBindLocation
local GetNumGroupMembers = GetNumGroupMembers
local SendChatMessage = SendChatMessage
local UnitInRaid = UnitInRaid
local UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT = UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT
local addonName, addonTable = ...
local L = addonTable.L
local items = addonTable.items
local scrolls = addonTable.scrolls
local challengeSpells = addonTable.challengeSpells
local whistles = addonTable.whistles
local portals = addonTable.portals
local itemLinks = addonTable.itemLinks
local updateItems = addonTable.updateItems
local updateClassSpells = addonTable.updateClassSpells
local updateChallengeSpells = addonTable.updateChallengeSpells
local getItemCD = addonTable.getItemCD
local getSpellCD = addonTable.getSpellCD
local getTextWithCooldown = addonTable.getTextWithCooldown
local LDB = LibDataBroker:NewDataObject(addonName, {
type = 'data source',
text = L['P'],
icon = 'Interface\\Icons\\INV_Misc_Rune_06',
})
local tooltip
local frame = CreateFrame('frame')
frame:SetScript('OnEvent', function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
frame:RegisterEvent('PLAYER_LOGIN')
frame:RegisterEvent('SKILL_LINES_CHANGED')
local function tableCount(table)
local count = 0
for _ in pairs(table) do count = count + 1 end
return count
end
local function ToggleMinimap()
local hide = not PortalsDB.minimap.hide
PortalsDB.minimap.hide = hide
if hide then
LibIcon:Hide('Broker_Portals')
else
LibIcon:Show('Broker_Portals')
end
end
local function UpdateIcon(icon)
LDB.icon = icon
end
local function AnnouncePortal(isPortal, text)
local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
if PortalsDB.announce and isPortal and chatType then
SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. text, chatType)
end
end
local function AddItemToMenu(itemID, location)
local link = itemLinks[itemID]
if (link ~= nil and link.hasItem) then
local cooldown = getItemCD(itemID)
local name
if location ~= nil then
name = link.name .. ": " .. location
else
name = link.name
end
local text = getTextWithCooldown(name, cooldown)
local lineIndex = tooltip:AddLine(("|T%s:16|t%s"):format(link.icon, ' '..text))
tooltip:SetCellScript(lineIndex, 1, "OnEnter", function(self)
LibSecureFrame:Activate(link.secure, self, tooltip)
end)
tooltip:SetCellScript(lineIndex, 1, "OnMouseDown", function(self)
UpdateIcon(link.icon)
end)
return true
else
return false
end
end
local function AddSpellToMenu(link)
local cooldown = getSpellCD(link.name)
local text = link.name;
if (link.location ~= nil) then
text = link.location
end
local text = getTextWithCooldown(text, cooldown)
local lineIndex = tooltip:AddLine(("|T%s:16|t%s"):format(link.icon, ' '..text))
tooltip:SetCellScript(lineIndex, 1, "OnEnter", function(self)
LibSecureFrame:Activate(link.secure, self, tooltip)
end)
tooltip:SetCellScript(lineIndex, 1, "OnMouseDown", function(self)
UpdateIcon(link.icon)
AnnouncePortal(link.isPortal, link.name)
end)
end
local function AddSpellsToMenu(links)
local addedItem = false
for _, link in pairs(links) do
AddSpellToMenu(link)
addedItem = true
end
return addedItem
end
local function AddItemsToMenu(itemIDs, text)
local addedItem = false
for i = 1, #itemIDs do
local itemID = itemIDs[i]
if (AddItemToMenu(itemID, text)) then
addedItem = true
end
end
return addedItem
end
local function ShowWhistles()
return AddItemsToMenu(whistles)
end
local function ShowHearthstones()
local bindLoc = GetBindLocation()
return AddItemsToMenu(scrolls, bindLoc)
end
local function ShowOtherItems()
if PortalsDB.showItems then
return AddItemsToMenu(items)
else
return false
end
end
local function ShowClassSpells()
local links = updateClassSpells()
return AddSpellsToMenu(links)
end
local function ShowChallengeSpells()
local links = updateChallengeSpells()
return AddSpellsToMenu(links)
end
local function ShowOptionsMenu()
Dewdrop:SetFontSize(UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT)
Dewdrop:AddLine(
'textHeight', UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT,
'text', L['SHOW_ITEMS'],
'checked', PortalsDB.showItems,
'func', function() PortalsDB.showItems = not PortalsDB.showItems end,
'closeWhenClicked', true)
Dewdrop:AddLine(
'textHeight', UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT,
'text', L['ATT_MINIMAP'],
'checked', not PortalsDB.minimap.hide,
'func', function() ToggleMinimap() end,
'closeWhenClicked', true)
Dewdrop:AddLine(
'textHeight', UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT,
'text', L['ANNOUNCE'],
'checked', PortalsDB.announce,
'func', function() PortalsDB.announce = not PortalsDB.announce end,
'closeWhenClicked', true)
end
local function IsOptionsMenuOpen(self)
return Dewdrop:IsOpen(self)
end
local function ToggleOptionsMenu(self)
if (self ~= nil and Dewdrop:IsOpen(self)) then
Dewdrop:Close()
else
Dewdrop:Open(self, 'children', ShowOptionsMenu)
end
end
local function ShowTooltip(self)
-- Acquire a tooltip with 1 columns, aligned to left
tooltip = LibQTip:Acquire(addonName.."tip", 1, "LEFT")
self.tooltip = tooltip
tooltip:EnableMouse(true)
tooltip:SetAutoHideDelay(.2, self)
-- Use smart anchoring code to anchor the tooltip to our frame
tooltip:SmartAnchorTo(self)
tooltip:Clear()
-- add content
if ShowChallengeSpells() then tooltip:AddLine(" ") end
if ShowOtherItems() then tooltip:AddLine(" ") end
if ShowClassSpells() then tooltip:AddLine(" ") end
if ShowHearthstones() then tooltip:AddLine(" ") end
if ShowWhistles() then --[[ tooltip:AddLine(" ") --]] end
tooltip:Show()
end
local function HideTooltip(self)
LibQTip:Release(self.tooltip)
end
function frame:PLAYER_LOGIN()
-- PortalsDB.minimap is there for smooth upgrade of SVs from old version
if (not PortalsDB) or (PortalsDB.version == nil) then
PortalsDB = {}
PortalsDB.minimap = {}
PortalsDB.minimap.hide = false
PortalsDB.showItems = true
PortalsDB.announce = false
PortalsDB.version = 5
end
-- upgrade from versions
if PortalsDB.version == 4 then
PortalsDB.fontSize = UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT
PortalsDB.version = 5
elseif PortalsDB.version == 3 then
PortalsDB.announce = false
PortalsDB.version = 4
elseif PortalsDB.version == 2 then
PortalsDB.showItemCooldowns = true
PortalsDB.announce = false
PortalsDB.version = 4
elseif PortalsDB.version < 2 then
PortalsDB.showItems = true
PortalsDB.showItemCooldowns = true
PortalsDB.announce = false
PortalsDB.version = 4
end
if LibIcon then
LibIcon:Register('Broker_Portals', LDB, PortalsDB.minimap)
end
updateItems()
self:UnregisterEvent('PLAYER_LOGIN')
end
function frame:SKILL_LINES_CHANGED()
updateClassSpells()
updateChallengeSpells()
end
function LDB.OnClick(self, button)
if button == "RightButton" then
HideTooltip(self)
ToggleOptionsMenu(self)
end
end
function LDB.OnEnter(self)
if (IsOptionsMenuOpen(self)) then return end
ShowTooltip(self)
end
-- slash command definition
SlashCmdList['BROKER_PORTALS'] = function() ToggleMinimap() end
SLASH_BROKER_PORTALS1 = '/portals'