-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTooltipToSimc.lua
More file actions
343 lines (292 loc) · 9.69 KB
/
TooltipToSimc.lua
File metadata and controls
343 lines (292 loc) · 9.69 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
local name, tpSimc = ...
local hooked, db = false
local equipLocToSlot = {
INVTYPE_HEAD='head',
INVTYPE_NECK='neck',
INVTYPE_SHOULDER='shoulder',
INVTYPE_CLOAK='back',
INVTYPE_CHEST='chest',
INVTYPE_ROBE='chest',
INVTYPE_BODY='shirt',
INVTYPE_TABARD='tabard',
INVTYPE_WRIST='wrist',
INVTYPE_HAND='hands',
INVTYPE_WAIST='waist',
INVTYPE_LEGS='legs',
INVTYPE_FEET='feet',
INVTYPE_FINGER='finger1',
INVTYPE_TRINKET='trinket1',
INVTYPE_WEAPON='main_hand',
INVTYPE_2HWEAPON='main_hand',
INVTYPE_RANGED='main_hand',
INVTYPE_RANGEDRIGHT='main_hand',
INVTYPE_SHIELD='off_hand',
INVTYPE_HOLDABLE='off_hand',
}
local oneHandWeapons = {
[0] = LE_ITEM_WEAPON_AXE1H,
[4] = LE_ITEM_WEAPON_MACE1H,
[7] = LE_ITEM_WEAPON_SWORD1H,
[9] = LE_ITEM_WEAPON_WARGLAIVE,
[13] = LE_ITEM_WEAPON_UNARMED,
[15] = LE_ITEM_WEAPON_DAGGER,
}
local nyalothaCorruptions = {
--[[
[itemId] = bonusId
]]
[172187] = 6539, -- Devastation's Hour
[172189] = 6548, -- Eyestalk of Il'gynoth
[172191] = 6567, -- An'zig Vra
[172193] = 6568, -- Whispering Eldritch Bow
[172196] = 6541, -- Vorzz Yoq'al
[172197] = 6569, -- Unguent Caress
[172198] = 6570, -- Mar'kowa, the Mindpiercer
[172199] = 6571, -- Faralos, Empire's Dream
[172200] = 6572, -- Sk'shuul Vaz
[172227] = 6544, -- Shard of the Black Empire
[174106] = 6550, -- Qwor N'lyeth
[174108] = 6553, -- Shgla'yos, Astral Malignity
}
local function getItemSplit(itemString)
local itemSplit = {}
for _, v in ipairs({strsplit(":", itemString)}) do
if v == "" then
itemSplit[#itemSplit + 1] = 0
else
itemSplit[#itemSplit + 1] = tonumber(v)
end
end
return itemSplit
end
local function getItemInfo(itemSplit, slot, itemLink, itemLevel)
-- code mostly copied from the Simulationcraft AddOn
-- https://www.curseforge.com/wow/addons/simulationcraft
local itemInfo = {}
local itemId = itemSplit[1]
itemInfo[#itemInfo + 1] = ',id=' .. itemId
-- New style item suffix, old suffix style not supported
if itemSplit[7] ~= 0 then
itemInfo[#itemInfo + 1] = 'suffix=' .. itemSplit[7]
end
local bonuses = {}
for index=1, itemSplit[13] do
bonuses[#bonuses + 1] = itemSplit[13 + index]
end
if nyalothaCorruptions[itemId] and itemSplit[14] == 3524 then
bonuses[#bonuses + 1] = nyalothaCorruptions[itemId]
end
if #bonuses > 0 then
itemInfo[#itemInfo + 1] = 'bonus_id=' .. table.concat(bonuses, '/')
end
-- Get item creation context. Can be used to determine unlock/availability of azerite tiers for 3rd parties
if itemSplit[12] ~= 0 then
itemInfo[#itemInfo + 1] = 'context=' .. itemSplit[12]
end
local linkOffset = 13 + #bonuses + 1
local craftedStats = {}
local numPairs = itemSplit[linkOffset]
for index=1, numPairs do
local pairOffset = 1 + linkOffset + (2 * (index - 1))
local pairType = itemSplit[pairOffset]
local pairValue = itemSplit[pairOffset + 1]
if pairType == 9 then
itemInfo[#itemInfo + 1] = 'drop_level=' .. pairValue
elseif pairType == 29 or pairType == 30 then
craftedStats[#craftedStats + 1] = pairValue
end
end
if #craftedStats > 0 then
itemInfo[#itemInfo + 1] = 'crafted_stats=' .. table.concat(craftedStats, '/')
end
if itemLevel then
itemInfo[#itemInfo + 1] = 'ilevel=' .. itemLevel
end
local str = '# '
str = str .. slot .. "=" .. table.concat(itemInfo, ',')
return str
end
local function setupDialogBox(itemInfo)
local text
if itemInfo then
local itemInfoCF = tpSimc.itemInfo or CreateFrame("ScrollFrame", name .. "ItemInfo", nil, "InputScrollFrameTemplate")
if not tpSimc.itemInfo then
tpSimc.itemInfo = itemInfoCF
itemInfoCF:SetMovable(true)
itemInfoCF:EnableMouse(true)
itemInfoCF:RegisterForDrag("LeftButton")
itemInfoCF:SetScript("OnDragStart", itemInfoCF.StartMoving)
itemInfoCF:SetScript("OnDragStop", itemInfoCF.StopMovingOrSizing)
itemInfoCF:SetToplevel(true)
itemInfoCF:SetWidth(450)
itemInfoCF:SetHeight(60)
itemInfoCF:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
itemInfoCF.CharCount:Hide()
itemInfoCF.EditBox:SetFont("Fonts/FRIZQT__.TTF", 9)
itemInfoCF.EditBox:SetPoint("TOPLEFT", 1, -2)
local button = CreateFrame("Button", nil, itemInfoCF, "StaticPopupButtonTemplate")
button:SetPoint("BOTTOM", itemInfoCF, "BOTTOM",-5)
button:SetWidth(60)
button:SetHeight(15)
button:SetText("Okay")
button.Text:SetFont("Fonts/FRIZQT__.TTF", 8)
button:SetScript("OnClick", function() itemInfoCF:Hide() end)
end
if db.offHand and tpSimc.addOffHand:IsShown() then
local offHandInfo = tpSimc.addOffHand.itemInfo
text = itemInfo .. "\n" .. offHandInfo
else
text = itemInfo
end
itemInfoCF.EditBox:SetText(text)
itemInfoCF.EditBox:HighlightText()
itemInfoCF.EditBox:SetFocus()
itemInfoCF.EditBox:SetSize(itemInfoCF:GetWidth(), itemInfoCF:GetHeight()-10)
itemInfoCF.EditBox:SetScript("OnEscapePressed", function(self) itemInfoCF:Hide() end)
itemInfoCF:Show()
end
if tpSimc.itemInfo then
tpSimc.itemInfo.EditBox:HookScript("OnTextChanged", function(self)
self:SetText(text)
self:HighlightText()
self:SetFocus()
end)
end
end
local function createButton(type, suffix, parent, template)
local button = CreateFrame(type, name..suffix, parent, template)
return button
end
local function getTooltipItem(tooltip, button)
local locItemName, itemLink = tooltip:GetItem()
if not itemLink then return end
local equipLoc, _, _, _, subId = select(9, GetItemInfo(itemLink))
local item = Item:CreateFromItemLink(itemLink)
if item:IsItemEmpty() then return end
local itemLevel = item:GetCurrentItemLevel()
if equipLoc and equipLoc ~= '' then
local itemString = string.match(itemLink, "item:([%-?%d:]+)")
local slot = equipLocToSlot[equipLoc]
local itemSplit = getItemSplit(itemString)
local itemInfo = getItemInfo(itemSplit, slot, itemLink, itemLevel)
return equipLoc, itemLink, itemLevel, subId, itemInfo, locItemName, itemSplit
end
end
local function createSimc(itemInfo, itemName)
if not db.onlyItem then
if SimcFrame and SimcFrame:IsShown() then
SimcFrame:Hide()
end
setupDialogBox(itemInfo)
else
if tpSimc.itemInfo and tpSimc.itemInfo:IsShown() then
tpSimc.itemInfo:Hide()
end
SlashCmdList["ACECONSOLE_SIMC"]("")
local item = "#\n"
item = item .. "# " .. itemName .. "\n"
item = item .. itemInfo
if db.offHand and tpSimc.addOffHand and tpSimc.addOffHand:IsShown() then
local offHandInfo = tpSimc.addOffHand.itemInfo
item = item .. "\n#\n"
item = item .. "# " .. itemName .. "\n"
item = item .. offHandInfo
end
if SimcEditBox then
hooked = true
local text = SimcEditBox:GetText()
SimcEditBox:SetCursorPosition(SimcEditBox:GetNumLetters())
SimcEditBox:HighlightText(0,0)
SimcEditBox:Insert(item)
SimcEditBox:HighlightText()
SimcEditBox:SetFocus()
SimcEditBox:HookScript("OnTextChanged", function(self)
if hooked then
self:SetText(text .. item)
self:HighlightText()
end
end)
SimcEditBox:HookScript("OnHide", function(self)
hooked = false
end)
end
end
end
local function buttonAboveTooltip(self, link)
local tooltipType = string.match(link,"^(%a+):")
if tooltipType and tooltipType == "item" then
local equipLoc, itemLink, itemLevel, subId, itemInfo, itemName, itemSplit = getTooltipItem(self)
if equipLoc and equipLoc ~= "" then
tpSimc.button:SetScript("OnClick", function() createSimc(itemInfo, itemName) end)
tpSimc.button:SetParent(self)
tpSimc.button:SetPoint("BOTTOM", self, "TOP")
tpSimc.button:Show()
tpSimc.onlyItem:SetParent(tpSimc.button)
tpSimc.onlyItem:SetPoint("LEFT", tpSimc.button, "RIGHT", 2)
tpSimc.onlyItem:Show()
if equipLoc == "INVTYPE_WEAPON" and oneHandWeapons[subId] then
tpSimc.addOffHand:SetParent(tpSimc.button)
tpSimc.addOffHand:SetPoint("BOTTOM", tpSimc.onlyItem, "TOP")
tpSimc.addOffHand.itemInfo = getItemInfo(itemSplit, "off_hand", itemLink, itemLevel)
tpSimc.addOffHand:Show()
db.offHand = tpSimc.addOffHand:GetChecked()
elseif tpSimc.addOffHand:IsShown() then
tpSimc.addOffHand:Hide()
end
elseif tpSimc.button:IsShown() then
tpSimc.button:Hide()
end
else
tpSimc.button:Hide()
end
end
function tpSimcCurrentTooltip()
if GameTooltip then
local itemInfo, itemName = select(5, getTooltipItem(GameTooltip, false))
if itemInfo then
createSimc(itemInfo, itemName)
end
end
end
local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, e, a)
if e == "ADDON_LOADED" and a == name then
local default = {
offHand = true,
onlyItem = true
}
tooltipToSimcDB = tooltipToSimcDB or default
db = tooltipToSimcDB
local button = createButton("Button", "button", nil, "StaticPopupButtonTemplate")
tpSimc.button = button
button:SetWidth(150)
button:SetHeight(25)
button:SetText("Generate SimC String")
button:Hide()
local addOffHand = createButton("CheckButton", "addOffHandButton", nil, "ChatConfigCheckButtonTemplate")
tpSimc.addOffHand = addOffHand
addOffHand.Text:SetText("+ Off Hand")
addOffHand:SetChecked(db.offHand)
addOffHand:Hide()
addOffHand:SetScript("OnClick", function(self)
db.offHand = self:GetChecked()
end)
if IsAddOnLoaded("Simulationcraft") then
local onlyItem = createButton("CheckButton", "onlyItemButton", nil, "ChatConfigCheckButtonTemplate")
tpSimc.onlyItem = onlyItem
onlyItem.Text:SetText("Simc Integration")
onlyItem:SetChecked(db.onlyItem)
onlyItem:Hide()
onlyItem:SetScript("OnClick", function(self)
db.onlyItem = self:GetChecked()
end)
else
db.onlyItem = true
end
end
end)
BINDING_HEADER_TOOLTIPSIMC1 = "TooltipToSimc"
hooksecurefunc(ItemRefTooltip, "SetHyperlink", buttonAboveTooltip)
-- WeakAuras :(
hooksecurefunc(ItemRefTooltip, "ClearLines", function() if tpSimc.button and tpSimc.button:IsShown() then tpSimc.button:Hide() end end)