View Single Post
04-06-19, 03:49 PM   #1
tkle
A Defias Bandit
Join Date: Apr 2019
Posts: 2
Itemlevel in Character Panel

Hi.

I have a problem showing itemlevel in Syiana's UI, SUI 7.2. Since he has discontinued the project(stopped playing), I'm trying to fix some few bugs for personal use

I posted the same in the PTR API/Graphic changes.

Here's the code for showing iLvL in the characterpanel and bags(bags work). Does not work after 8.1.5:
Lua Code:
  1. --[[SUI ITEMLEVEL v1.0]]
  2.  
  3. --FIX LIBSTUB
  4.  
  5. local CF=CreateFrame("Frame")
  6. CF:RegisterEvent("PLAYER_LOGIN")
  7. CF:SetScript("OnEvent", function(self, event)
  8.  
  9. if not SUIDB.A_ITEMLEVEL then return end
  10.  
  11. local MAJOR, MINOR = "ItemLevel", 1
  12. local lib = LibStub:NewLibrary(MAJOR, MINOR)
  13.  
  14. if not lib then
  15.     return
  16. end
  17.  
  18. local ItemLevelPattern = gsub(ITEM_LEVEL, "%%d", "(%%d+)")
  19.  
  20. local tooltip = CreateFrame("GameTooltip", "LibItemLevelTooltip1", UIParent, "GameTooltipTemplate")
  21. local unittip = CreateFrame("GameTooltip", "LibItemLevelTooltip2", UIParent, "GameTooltipTemplate")
  22.  
  23. function lib:hasLocally(ItemID)
  24.     if (not ItemID or ItemID == "" or ItemID == "0") then
  25.         return true
  26.     end
  27.     return select(10, GetItemInfo(tonumber(ItemID)))
  28. end
  29.  
  30. function lib:itemLocally(ItemLink)
  31.     local id, gem1, gem2, gem3 = string.match(ItemLink, "item:(%d+):[^:]*:(%d-):(%d-):(%d-):")
  32.     return (self:hasLocally(id) and self:hasLocally(gem1) and self:hasLocally(gem2) and self:hasLocally(gem3))
  33. end
  34.  
  35. function lib:GetItemInfo(ItemLink)
  36.     if (not ItemLink or ItemLink == "") then
  37.         return 0, 0
  38.     end
  39.     if (not string.match(ItemLink, "item:%d+:")) then
  40.         return -1, 0
  41.     end
  42.     if (not self:itemLocally(ItemLink)) then
  43.         return 1, 0
  44.     end
  45.     local level, text
  46.     tooltip:SetOwner(UIParent, "ANCHOR_NONE")
  47.     tooltip:ClearLines()
  48.     tooltip:SetHyperlink(ItemLink)
  49.     for i = 2, 5 do
  50.         text = _G[tooltip:GetName() .. "TextLeft" .. i]:GetText() or ""
  51.         level = string.match(text, ItemLevelPattern)
  52.         if (level) then
  53.             break
  54.         end
  55.     end
  56.     return 0, tonumber(level) or 0, GetItemInfo(ItemLink)
  57. end
  58.  
  59. LibItemLevel = LibStub:GetLibrary("ItemLevel")
  60.  
  61. function lib:GetUnitItemInfo(unit, index)
  62.     if (not UnitExists(unit)) then
  63.         return 1, 0
  64.     end
  65.     unittip:SetOwner(UIParent, "ANCHOR_NONE")
  66.     unittip:ClearLines()
  67.     unittip:SetInventoryItem(unit, index)
  68.     local ItemLink = select(2, unittip:GetItem())
  69.     if (not ItemLink or ItemLink == "") then
  70.         return 0, 0
  71.     end
  72.     if (not self:itemLocally(ItemLink)) then
  73.         return 1, 0
  74.     end
  75.     local level, text
  76.     for i = 2, 5 do
  77.         text = _G[unittip:GetName() .. "TextLeft" .. i]:GetText() or ""
  78.         level = string.match(text, ItemLevelPattern)
  79.         if (level) then
  80.             break
  81.         end
  82.     end
  83.     return 0, tonumber(level) or 0, GetItemInfo(ItemLink)
  84. end
  85.  
  86. function lib:GetUnitItemLevel(unit)
  87.     local total, counts = 0, 0
  88.     local _, count, level
  89.     for i = 1, 15 do
  90.         if (i ~= 4) then
  91.             count, level = self:GetUnitItemInfo(unit, i)
  92.             total = total + level
  93.             counts = counts + count
  94.         end
  95.     end
  96.     local mcount, mlevel, mquality, mslot, ocount, olevel, oquality, oslot
  97.     mcount, mlevel, _, _, mquality, _, _, _, _, _, mslot = self:GetUnitItemInfo(unit, 16)
  98.     ocount, olevel, _, _, oquality, _, _, _, _, _, oslot = self:GetUnitItemInfo(unit, 17)
  99.     counts = counts + mcount + ocount
  100.  
  101.     if
  102.         (mquality == 6 or oslot == "INVTYPE_2HWEAPON" or mslot == "INVTYPE_2HWEAPON" or mslot == "INVTYPE_RANGED" or
  103.             mslot == "INVTYPE_RANGEDRIGHT")
  104.      then
  105.         total = total + max(mlevel, olevel) * 2
  106.     else
  107.         total = total + mlevel + olevel
  108.     end
  109.     return counts, total / (16 - counts), total
  110. end
  111.  
  112. function ShowPaperDollItemLevel(self, unit)
  113.     result = ""
  114.     id = self:GetID()
  115.     if id == 4 or id > 17 then
  116.         return
  117.     end
  118.     if not self.levelString then
  119.         self.levelString = self:CreateFontString(nil, "OVERLAY")
  120.         self.levelString:SetFont(STANDARD_TEXT_FONT, 12, "OUTLINE")
  121.         self.levelString:SetPoint("TOP")
  122.         self.levelString:SetTextColor(1, 0.82, 0)
  123.     end
  124.     if unit and self.hasItem then
  125.         _, level, _, _, quality = LibItemLevel:GetUnitItemInfo(unit, id)
  126.         if level > 0 and quality > 2 then
  127.             self.levelString:SetText(level)
  128.             result = true
  129.         end
  130.     else
  131.         self.levelString:SetText("")
  132.         result = true
  133.     end
  134.     if id == 16 or id == 17 then
  135.         _, offhand, _, _, quality = LibItemLevel:GetUnitItemInfo(unit, 17)
  136.         if quality == 6 then
  137.             _, mainhand = LibItemLevel:GetUnitItemInfo(unit, 16)
  138.             self.levelString:SetText(math.max(mainhand, offhand))
  139.         end
  140.     end
  141.     return result
  142. end
  143. hooksecurefunc(
  144.     "PaperDollItemSlotButton_Update",
  145.     function(self)
  146.         ShowPaperDollItemLevel(self, "player")
  147.     end
  148. )
  149.  
  150. function SetContainerItemLevel(button, ItemLink)
  151.     if not button then
  152.         return
  153.     end
  154.     if not button.levelString then
  155.         button.levelString = button:CreateFontString(nil, "OVERLAY")
  156.         button.levelString:SetFont(STANDARD_TEXT_FONT, 12, "THICKOUTLINE")
  157.         button.levelString:SetPoint("TOP")
  158.     end
  159.     if button.origItemLink ~= ItemLink then
  160.         button.origItemLink = ItemLink
  161.     else
  162.         return
  163.     end
  164.     if ItemLink then
  165.         count, level, _, _, quality, _, _, class, subclass, _, _ = LibItemLevel:GetItemInfo(ItemLink)
  166.         name, _ = GetItemSpell(ItemLink)
  167.         _, equipped, _ = GetAverageItemLevel()
  168.         if level >= (98 * equipped / 100) then
  169.             button.levelString:SetTextColor(0, 1, 0)
  170.         else
  171.             button.levelString:SetTextColor(1, 1, 1)
  172.         end
  173.         if count == 0 and level > 0 and quality > 1 then
  174.             button.levelString:SetText(level)
  175.         else
  176.             button.levelString:SetText("")
  177.         end
  178.     else
  179.         button.levelString:SetText("")
  180.     end
  181. end
  182. hooksecurefunc(
  183.     "ContainerFrame_Update",
  184.     function(self)
  185.         local name = self:GetName()
  186.         for i = 1, self.size do
  187.             local button = _G[name .. "Item" .. i]
  188.             SetContainerItemLevel(button, GetContainerItemLink(self:GetID(), button:GetID()))
  189.         end
  190.     end
  191. )
  192.  
  193. end)

Hope someone can help
  Reply With Quote