Commit 4cc9d577 authored by Merathilis's avatar Merathilis

Update ItemLevel function.

parent b9214e23
......@@ -5,9 +5,9 @@ local MER, E, L, V, P, G = unpack(select(2, ...))
local _G = _G
local assert, pairs, print, select, tonumber, type, unpack = assert, pairs, print, select, tonumber, type, unpack
local getmetatable = getmetatable
local find, format, match, split = string.find, string.format, string.match, string.split
local find, format, match, split, strfind = string.find, string.format, string.match, string.split, strfind
local strmatch = strmatch
local tconcat = table.concat
local tconcat, twipe = table.concat, table.wipe
-- WoW API / Variables
local CreateFrame = CreateFrame
local GetAchievementInfo = GetAchievementInfo
......@@ -149,33 +149,88 @@ function MER:GetSpell(id)
return name
end
-- Tooltip scanning stuff
-- Tooltip scanning stuff. Credits siweia, with permission.
local iLvlDB = {}
local itemLevelString = _G["ITEM_LEVEL"]:gsub("%%d", "")
local itemLevelString = gsub(ITEM_LEVEL, "%%d", "")
local enchantString = gsub(ENCHANTED_TOOLTIP_LINE, "%%s", "(.+)")
local essenceTextureID = 2975691
local tip = CreateFrame("GameTooltip", "mUI_iLvlTooltip", nil, "GameTooltipTemplate")
function MER:GetItemLevel(link, arg1, arg2)
if iLvlDB[link] then return iLvlDB[link] end
local texturesDB, essencesDB = {}, {}
function MER:InspectItemTextures(clean, grabTextures)
twipe(texturesDB)
twipe(essencesDB)
for i = 1, 5 do
local tex = _G[tip:GetName().."Texture"..i]
local texture = tex and tex:GetTexture()
if texture then
if grabTextures then
if texture == essenceTextureID then
local selected = (texturesDB[i-1] ~= essenceTextureID and texturesDB[i-1]) or nil
essencesDB[i] = {selected, tex:GetAtlas(), texture}
if selected then texturesDB[i-1] = nil end
else
texturesDB[i] = texture
end
end
if clean then tex:SetTexture() end
end
end
return texturesDB, essencesDB
end
function MER:InspectItemInfo(text, iLvl, enchantText)
local itemLevel = strfind(text, itemLevelString) and strmatch(text, "(%d+)%)?$")
if itemLevel then iLvl = tonumber(itemLevel) end
local enchant = strmatch(text, enchantString)
if enchant then enchantText = enchant end
return iLvl, enchantText
end
tip:SetOwner(UIParent, "ANCHOR_NONE")
if arg1 and type(arg1) == "string" then
function MER:GetItemLevel(link, arg1, arg2, fullScan)
if fullScan then
MER:InspectItemTextures(true)
tip:SetOwner(UIParent, "ANCHOR_NONE")
tip:SetInventoryItem(arg1, arg2)
elseif arg1 and type(arg1) == "number" then
tip:SetBagItem(arg1, arg2)
local iLvl, enchantText, gems, essences
gems, essences = MER:InspectItemTextures(nil, true)
for i = 1, tip:NumLines() do
local text = _G[tip:GetName().."TextLeft"..i]:GetText() or ""
iLvl, enchantText = MER:InspectItemInfo(text, iLvl, enchantText)
if enchantText then break end
end
return iLvl, enchantText, gems, essences
else
tip:SetHyperlink(link)
end
if iLvlDB[link] then return iLvlDB[link] end
for i = 2, 5 do
local text = _G[tip:GetName().."TextLeft"..i]:GetText() or ""
local found = text:find(itemLevelString)
if found then
local level = text:match("(%d+)%)?$")
iLvlDB[link] = tonumber(level)
break
tip:SetOwner(UIParent, "ANCHOR_NONE")
if arg1 and type(arg1) == "string" then
tip:SetInventoryItem(arg1, arg2)
elseif arg1 and type(arg1) == "number" then
tip:SetBagItem(arg1, arg2)
else
tip:SetHyperlink(link)
end
for i = 2, 5 do
local text = _G[tip:GetName().."TextLeft"..i]:GetText() or ""
local found = strfind(text, itemLevelString)
if found then
local level = strmatch(text, "(%d+)%)?$")
iLvlDB[link] = tonumber(level)
break
end
end
return iLvlDB[link]
end
return iLvlDB[link]
end
function MER:CheckPlayerBuff(spell)
......@@ -212,7 +267,6 @@ function MER:UpdateRegisteredDBs()
end
end
function MER:UpdateAll()
self:UpdateRegisteredDBs()
for _, module in ipairs(self:GetRegisteredModules()) do
......
......@@ -13,7 +13,7 @@ local ITEM_QUALITY_COLORS = ITEM_QUALITY_COLORS
-- GLOBALS: BAG_ITEM_QUALITY_COLORS
-- ItemLevel on Flyoutbuttons
local function SetupFlyoutLevel(button, bag, slot, quality)
local function UpdateFlyoutLevel(button, bag, slot, quality)
if not button.iLvl then
button.iLvl = MER:CreateText(button, "OVERLAY", E.db.general.fontSize or 11, E.db.general.fontStyle or "OUTLINE")
button.iLvl:SetPoint("BOTTOMRIGHT", 0, 2)
......@@ -35,7 +35,23 @@ local function SetupFlyoutLevel(button, bag, slot, quality)
end
end
--ItemLevel on Scrapping Machine
local function SetupFlyoutLevel(self)
local location = self.location
if not location or location >= EQUIPMENTFLYOUT_FIRST_SPECIAL_LOCATION then
if self.iLvl then self.iLvl:SetText("") end
return
end
local _, _, bags, voidStorage, slot, bag = EquipmentManager_UnpackLocation(location)
if voidStorage then return end
local quality = select(13, EquipmentManager_GetItemInfoByLocation(location))
if bags then
UpdateFlyoutLevel(self, bag, slot, quality)
else
UpdateFlyoutLevel(self, nil, slot, quality)
end
end
local function ScrappingMachineUpdate(self)
if not self.iLvl then
self.iLvl = MER:CreateText(self, "OVERLAY", E.db.general.fontSize or 11, E.db.general.fontStyle or "OUTLINE")
......@@ -68,24 +84,9 @@ local function ScrappingiLvL(event, addon)
end
function MI:ItemLevel()
MER:RegisterEvent("ADDON_LOADED", ScrappingiLvL)
-- iLvl on FlyoutButtons
hooksecurefunc("EquipmentFlyout_DisplayButton", SetupFlyoutLevel)
hooksecurefunc("EquipmentFlyout_DisplayButton", function(button)
local location = button.location
if not location or location >= _G.EQUIPMENTFLYOUT_FIRST_SPECIAL_LOCATION then
if button.iLvl then button.iLvl:SetText("") end
return
end
local _, _, bags, voidStorage, slot, bag = EquipmentManager_UnpackLocation(location)
if voidStorage then return end
local quality = select(13, EquipmentManager_GetItemInfoByLocation(location))
if bags then
SetupFlyoutLevel(button, bag, slot, quality)
else
SetupFlyoutLevel(button, nil, slot, quality)
end
end)
--ItemLevel on Scrapping Machine
MER:RegisterEvent("ADDON_LOADED", ScrappingiLvL)
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment