Advertisement
Guest User

Core.Lua

a guest
Dec 23rd, 2012
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.89 KB | None | 0 0
  1. -- InspectEquip
  2.  
  3. InspectEquip = LibStub("AceAddon-3.0"):NewAddon("InspectEquip", "AceConsole-3.0", "AceHook-3.0", "AceTimer-3.0", "AceEvent-3.0")
  4. local L = LibStub("AceLocale-3.0"):GetLocale("InspectEquip")
  5. local IE = InspectEquip
  6. local IS = InspectEquip_ItemSources --> ItemSources.lua
  7. local WIN = InspectEquip_InfoWindow --> InfoWindow.xml
  8. local TITLE = InspectEquip_InfoWindowTitle
  9. local AVGIL = InspectEquip_InfoWindowAvgItemLevel
  10. local exMod = nil
  11.  
  12. local mop = select(4, GetBuildInfo()) >= 50000
  13.  
  14. local ReforgingInfo = LibStub("LibReforgingInfo-1.0")
  15.  
  16. local slots = { "HeadSlot", "NeckSlot", "ShoulderSlot", "BackSlot", "ChestSlot",
  17.                 "WristSlot", "HandsSlot", "WaistSlot", "LegsSlot", "FeetSlot",
  18.                 "Finger0Slot", "Finger1Slot", "Trinket0Slot", "Trinket1Slot", "MainHandSlot",
  19.                 "SecondaryHandSlot" } -- TabardSlot, ShirtSlot
  20. local noEnchantWarningSlots = {
  21.     ["NeckSlot"] = true, ["WaistSlot"] = true, ["Finger0Slot"] = true, ["Finger1Slot"] = true,
  22.     ["Trinket0Slot"] = true, ["Trinket1Slot"] = true, ["SecondaryHandSlot"] = true, ["RangedSlot"] = true,
  23.     ["HeadSlot"] = true  -- Added ch1.00
  24. }
  25.  
  26. local lines = {}
  27. local numlines = 0
  28. local curline = 0
  29. local curUnit = nil
  30. local curUnitName = nil
  31. local curUser = nil
  32. local curGUID = nil
  33. local cached = false
  34.  
  35. local headers = {}
  36. local numheaders = 0
  37.  
  38. local yoffset = -40
  39. local hooked = false
  40. local autoHidden = false
  41.  
  42. local origInspectUnit
  43.  
  44. local tonumber = tonumber
  45. local gmatch = string.gmatch
  46. local tinsert = table.insert
  47. local tsort = table.sort
  48. local band = bit.band
  49. local Examiner = Examiner
  50.  
  51. --local _,_,_,gameToc = GetBuildInfo()
  52.  
  53. local tooltipTimer = nil
  54. local retryTimer = nil
  55.  
  56. if not mop then
  57.     tinsert(slots, "RangedSlot")
  58. end
  59.  
  60.  
  61. --------------------------------------------------------------------------------------
  62.  
  63. InspectEquipConfig = {}
  64. local defaults = {
  65.     tooltips = true,
  66.     showUnknown = true,
  67.     inspectWindow = true,
  68.     charWindow = true,
  69.     checkEnchants = true,
  70.     listItemLevels = true,
  71.     showAvgItemLevel = true,
  72.     ttR = 1.0,
  73.     ttG = 0.75,
  74.     ttB = 0.0,
  75.     maxSourceCount = 5,
  76. }
  77.  
  78. local options = {
  79.     name = "InspectEquip",
  80.     type = "group",
  81.     args = {
  82.         tooltips = {
  83.             order = 1, type = "toggle", width = "full",
  84.             name = L["Add drop information to tooltips"],
  85.             desc = L["Add item drop information to all item tooltips"],
  86.             get = function() return InspectEquipConfig.tooltips end,
  87.             set = function(_,v) InspectEquipConfig.tooltips = v; if v then IE:HookTooltips() end end,
  88.         },
  89.         showunknown = {
  90.             order = 2, type = "toggle", width = "full",
  91.             name = L["Include unknown items in overview"],
  92.             desc = L["Show items that cannot be categorized in a seperate category"],
  93.             get = function() return InspectEquipConfig.showUnknown end,
  94.             set = function(_,v) InspectEquipConfig.showUnknown = v end,
  95.         },
  96.         inspectwindow = {
  97.             order = 3, type = "toggle", width = "full",
  98.             name = L["Attach to inspect window"],
  99.             desc = L["Show the equipment list when inspecting other characters"],
  100.             get = function() return InspectEquipConfig.inspectWindow end,
  101.             set = function(_,v) InspectEquipConfig.inspectWindow = v end,
  102.         },
  103.         charwindow = {
  104.             order = 4, type = "toggle", width = "full",
  105.             name = L["Attach to character window"],
  106.             desc = L["Also show the InspectEquip panel when opening the character window"],
  107.             get = function() return InspectEquipConfig.charWindow end,
  108.             set = function(_,v) InspectEquipConfig.charWindow = v end,
  109.         },
  110.         checkenchants = {
  111.             order = 5, type = "toggle", width = "full",
  112.             name = L["Check for unenchanted items"],
  113.             desc = L["Display a warning for unenchanted items"],
  114.             get = function() return InspectEquipConfig.checkEnchants end,
  115.             set = function(_,v) InspectEquipConfig.checkEnchants = v end,
  116.         },
  117.         listitemlevels = {
  118.             order = 6, type = "toggle", width = "full",
  119.             name = L["Show item level in equipment list"],
  120.             desc = L["Show the item level of each item in the equipment panel"],
  121.             get = function() return InspectEquipConfig.listItemLevels end,
  122.             set = function(_,v) InspectEquipConfig.listItemLevels = v end,
  123.         },
  124.         showavgitemlevel = {
  125.             order = 7, type = "toggle", width = "full",
  126.             name = L["Show average item level in equipment list"],
  127.             desc = L["Show the average item level of all items in the equipment panel"],
  128.             get = function() return InspectEquipConfig.showAvgItemLevel end,
  129.             set = function(_,v) InspectEquipConfig.showAvgItemLevel = v end,
  130.         },
  131.         tooltipcolor = {
  132.             order = 8, type = "color",
  133.             name = L["Tooltip text color"],
  134.             width = "full",
  135.             get = function() return InspectEquipConfig.ttR, InspectEquipConfig.ttG, InspectEquipConfig.ttB, 1.0 end,
  136.             set = function(_,r,g,b,a)
  137.                 InspectEquipConfig.ttR = r
  138.                 InspectEquipConfig.ttG = g
  139.                 InspectEquipConfig.ttB = b
  140.             end,
  141.         },
  142.         maxsourcecount = {
  143.             order = 9, type = "range",
  144.             min = 1, max = 20, softMax = 10, step = 1,
  145.             width = "double",
  146.             name = L["Max. amount of sources in tooltips"],
  147.             desc = L["The maximum amount of sources that are displayed in item tooltips"],
  148.             get = function() return InspectEquipConfig.maxSourceCount end,
  149.             set = function(_,v) InspectEquipConfig.maxSourceCount = v end,
  150.         },
  151.         database = {
  152.             order = 10, type = "group", inline = true,
  153.             name = L["Database"],
  154.             args = {
  155.                 resetdb = {
  156.                     order = 1, type = "execute",
  157.                     width = "double",
  158.                     name = L["Reset database"],
  159.                     desc = L["Recreate the database"],
  160.                     func = function() IE:CreateLocalDatabase() end,
  161.                 },
  162.             },
  163.         }
  164.     },
  165. }
  166.  
  167. LibStub("AceConfig-3.0"):RegisterOptionsTable("InspectEquip", options, "/inspectequip")
  168. LibStub("AceConfigDialog-3.0"):AddToBlizOptions("InspectEquip")
  169.  
  170. --------------------------------------------------------------------------------------
  171.  
  172. function IE:OnInitialize()
  173.     setmetatable(InspectEquipConfig, {__index = defaults})
  174.  
  175.     self:SetParent(Examiner or InspectFrame)
  176.     WIN:Hide()
  177.     TITLE:SetText("InspectEquip")
  178.  
  179.     if Examiner and Examiner.CreateModule then
  180.         exMod = Examiner:CreateModule("InspectEquip")
  181.         exMod.OnCacheLoaded = function(s, entry, unit)
  182.             if InspectEquipConfig.inspectWindow then
  183.                 IE:Inspect("cache", entry)
  184.             end
  185.         end
  186.         exMod.OnClearInspect = function(s) WIN:Hide() end
  187.         exMod.OnInspect = function(s, unit)
  188.             if InspectEquipConfig.inspectWindow then
  189.                 IE:SetParent(Examiner); IE:Inspect(unit)
  190.             end
  191.         end
  192.     end
  193.  
  194.     self:RegisterEvent("PLAYER_ENTERING_WORLD")
  195.     self:RegisterEvent("ADDON_LOADED")
  196.  
  197.     --self:InitLocalDatabase()
  198. end
  199.  
  200. function IE:OnEnable()
  201.     origInspectUnit = origInspectUnit or InspectUnit
  202.     InspectUnit = function(...) IE:InspectUnit(...) end
  203.     self:SecureHookScript(PaperDollFrame, "OnShow", "PaperDollFrame_OnShow")
  204.     self:SecureHookScript(PaperDollFrame, "OnHide", "PaperDollFrame_OnHide")
  205.     if GearManagerDialog then -- 4.0
  206.         self:SecureHookScript(GearManagerDialog, "OnShow", "GearManagerDialog_OnShow")
  207.         self:SecureHookScript(GearManagerDialog, "OnHide", "GearManagerDialog_OnHide")
  208.     end
  209.     if OutfitterFrame then
  210.         self:SecureHookScript(OutfitterFrame, "OnShow", "GearManagerDialog_OnShow")
  211.         self:SecureHookScript(OutfitterFrame, "OnHide", "GearManagerDialog_OnHide")
  212.     end
  213.     self:RegisterEvent("UNIT_INVENTORY_CHANGED")
  214.     self:RegisterEvent("INSPECT_READY")
  215. end
  216.  
  217. function IE:OnDisable()
  218.     InspectUnit = origInspectUnit
  219.     if hooked then
  220.         hooked = false
  221.         self:Unhook("InspectFrame_UnitChanged")
  222.     end
  223.     self:UnhookAll()
  224.     self:UnregisterEvent("UNIT_INVENTORY_CHANGED")
  225.     self:UnregisterEvent("INSPECT_READY")
  226.     self:CancelAllTimers()
  227.     WIN:Hide()
  228. end
  229.  
  230. local entered = false
  231.  
  232. function IE:PLAYER_ENTERING_WORLD()
  233.     entered = true
  234.     self:ScheduleTooltipHook()
  235.     self:InitLocalDatabase()
  236.     self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  237. end
  238.  
  239. function IE:ADDON_LOADED(e, name)
  240.     if entered then
  241.         self:ScheduleTooltipHook()
  242.     end
  243. end
  244.  
  245. -- Ugly hack, but some addons override the OnTooltipSetItem handler on
  246. -- ItemRefTooltip, breaking IE. Using this timer, IE hopefully hooks after them.
  247. function IE:ScheduleTooltipHook()
  248.     if InspectEquipConfig.tooltips then
  249.         if tooltipTimer then
  250.             self:CancelTimer(tooltipTimer, true)
  251.         end
  252.         tooltipTimer = self:ScheduleTimer('HookTooltips', 3)
  253.     end
  254. end
  255.  
  256. function IE:SetParent(frame)
  257.     WIN:SetParent(frame)
  258.     WIN:ClearAllPoints()
  259.     if not (frame == Examiner) then
  260.         WIN:SetPoint("TOPLEFT", frame, "TOPRIGHT", 5, 0)
  261.     else
  262.         WIN:SetPoint("TOPLEFT", frame, "TOPRIGHT", -25, -13)
  263.     end
  264. end
  265.  
  266. function IE:NewLine()
  267.     local row = CreateFrame("Frame", nil, WIN)
  268.     row:SetHeight(12)
  269.     row:SetWidth(200)
  270.     row:SetPoint("TOPLEFT", WIN, "TOPLEFT", 15, yoffset)
  271.  
  272.     local txt = row:CreateFontString(nil, "ARTWORK")
  273.     txt:SetJustifyH("LEFT")
  274.     txt:SetFontObject(GameFontHighlightSmall)
  275.     txt:SetPoint("TOPLEFT", row, "TOPLEFT", 0, 0)
  276.  
  277.     row.text = txt
  278.     yoffset = yoffset - 15
  279.     numlines = numlines + 1
  280.     lines[numlines] = row
  281.  
  282.     row:EnableMouse(true)
  283.     row:SetScript("OnEnter", IE.Line_OnEnter)
  284.     row:SetScript("OnLeave", IE.Line_OnLeave)
  285.     row:SetScript("OnMouseDown", IE.Line_OnClick)
  286. end
  287.  
  288. function IE:ResetDisplay()
  289.     for i = 1, numlines do
  290.         lines[i].text:SetText("")
  291.         lines[i]:Hide()
  292.     end
  293.     curline = 0
  294. end
  295.  
  296. function IE:AddLine(text, link, item)
  297.     curline = curline + 1
  298.     if curline > numlines then
  299.         self:NewLine()
  300.     end
  301.     local line = lines[curline]
  302.     line.link = link
  303.     line.item = item
  304.     line.text:SetText(text)
  305.     line:SetWidth(line.text:GetStringWidth())
  306.     line:SetFrameLevel(WIN:GetFrameLevel() + 1)
  307.     line:Show()
  308. end
  309.  
  310. function IE:FullUnitName(name, realm)
  311.     if realm and realm ~= "" then
  312.         return name .. "-" .. realm
  313.     else
  314.         return name
  315.     end
  316. end
  317.  
  318. function IE:GetExaminerCache(unit)
  319.     local name, realm = UnitName(unit)
  320.     return Examiner_Cache and Examiner_Cache[self:FullUnitName(name, realm)]
  321. end
  322.  
  323. function IE:InspectUnit(unit, ...)
  324.     origInspectUnit(unit, ...)
  325.  
  326.     if InspectEquipConfig.inspectWindow then
  327.         self:SetParent(Examiner or InspectFrame)
  328.         WIN:Hide()
  329.         if not hooked and InspectFrame_UnitChanged then
  330.             hooked = true
  331.             self:SecureHook("InspectFrame_UnitChanged")
  332.         end
  333.  
  334.         self:Inspect(unit)
  335.     end
  336. end
  337.  
  338. function IE:InspectFrame_UnitChanged()
  339.     if InspectFrame.unit and InspectEquipConfig.inspectWindow then
  340.         self:InspectUnit(InspectFrame.unit)
  341.     else
  342.         WIN:Hide()
  343.     end
  344. end
  345.  
  346. function IE:PaperDollFrame_OnShow()
  347.     if InspectEquipConfig.charWindow then
  348.         IE:SetParent(CharacterFrame)
  349.         IE:Inspect("player")
  350.     end
  351. end
  352.  
  353. function IE:PaperDollFrame_OnHide()
  354.     if WIN:GetParent() == CharacterFrame then
  355.         WIN:Hide()
  356.         autoHidden = false
  357.     end
  358. end
  359.  
  360. function IE:GearManagerDialog_OnShow()
  361.     if WIN:GetParent() == CharacterFrame and WIN:IsShown() then
  362.         WIN:Hide()
  363.         autoHidden = true
  364.     end
  365. end
  366.  
  367. function IE:GearManagerDialog_OnHide()
  368.     if autoHidden and WIN:GetParent() == CharacterFrame then
  369.         WIN:Show()
  370.         autoHidden = false
  371.     end
  372. end
  373.  
  374. function IE:UNIT_INVENTORY_CHANGED(event, unit)
  375.     if (unit == "player") and (WIN:IsVisible() or autoHidden) and (WIN:GetParent() == CharacterFrame) then
  376.         IE:Inspect("player")
  377.     elseif (unit == curUnit) and (UnitName(unit) == curUnitName) and (WIN:IsVisible()) then
  378.         IE:Inspect(curUnit)
  379.     end
  380. end
  381.  
  382. function IE:INSPECT_READY(event, guid)
  383.     if (guid == curGUID) and (UnitName(curUnit) == curUnitName) then
  384.         IE:Inspect(curUnit)
  385.     else
  386.         -- probably mouseover changed... nothing we can do apparently :(
  387.         -- (inspect by unit name / guid does not work)
  388.     end
  389. end
  390.  
  391. function IE:Inspect(unit, entry)
  392.     local unitName, unitRealm
  393.     cached = (unit == "cache")
  394.  
  395.     if retryTimer then
  396.         -- stop retry timer if present
  397.         self:CancelTimer(retryTimer, true)
  398.         retryTimer = nil
  399.     end
  400.  
  401.     if (cached and (not entry)) or (not self:IsEnabled()) then
  402.         WIN:Hide()
  403.         return
  404.     end
  405.  
  406.     local cacheItems = cached and entry.Items or nil
  407.  
  408.     if cached then
  409.         unitName, unitRealm = entry.name, entry.realm
  410.         curGUID = nil
  411.     else
  412.         if (not unit or not UnitExists(unit)) then
  413.             unit = "player"
  414.         end
  415.         unitName, unitRealm = UnitName(unit)
  416.         curGUID = UnitGUID(unit)
  417.  
  418.         if not CanInspect(unit) then
  419.             entry = self:GetExaminerCache(unit)
  420.             if entry then
  421.                 cached = true
  422.                 cacheItems = entry.Items
  423.             end
  424.         else
  425.             --ClearInspectPlayer()
  426.             --NotifyInspect(unit)
  427.         end
  428.     end
  429.     if unitRealm == "" then unitRealm = nil end
  430.     curUnit = unit
  431.     curUnitName = unitName
  432.     curUser = self:FullUnitName(unitName, unitRealm)
  433.     TITLE:SetText("InspectEquip: " .. curUser .. (cached and " (Cache)" or ""))
  434.  
  435.     self:ResetDisplay()
  436.  
  437.     local items = { cats = {}, items = {} }
  438.     local itemsFound = false
  439.     local getItem
  440.     if cached then
  441.         getItem = function(slot)
  442.             local istr = cacheItems[slot]
  443.             if istr then
  444.                 local itemId = tonumber(istr:match("item:(%d+)"))
  445.                 return select(2, GetItemInfo(istr)) or ("[" .. itemId .. "]")
  446.             else
  447.                 return nil
  448.             end
  449.         end
  450.     else
  451.         getItem = function(slot) return GetInventoryItemLink(unit, GetInventorySlotInfo(slot)) end
  452.     end
  453.  
  454.     local calciv = InspectEquipConfig.showAvgItemLevel
  455.     local iLevelSum, iCount = 0,0
  456.  
  457.     for _,slot in pairs(slots) do
  458.         local itemLink = getItem(slot)
  459.         if itemLink then
  460.             -- get source
  461.             local source = self:GetItemSourceCategories(itemLink)
  462.             if (not source) and InspectEquipConfig.showUnknown then
  463.                 local _,_,rar = GetItemInfo(itemLink)
  464.                 if rar >= 2 then
  465.                     source = {L["Unknown"]}
  466.                 end
  467.             end
  468.  
  469.             if source then
  470.                 local enchantId = tonumber(itemLink:match("Hitem:%d+:(%d+):"))
  471.                 local reforgeId = nil
  472.                 reforgeId = ReforgingInfo:GetReforgeID(itemLink)
  473.                 itemsFound = true
  474.  
  475.                 -- find category
  476.                 local cat = items
  477.                 local entry
  478.                 for _, entry in pairs(source) do
  479.                     if cat.cats[entry] == nil then
  480.                         cat.cats[entry] = { count = 0, cats = {}, items = {} }
  481.                     end
  482.                     cat = cat.cats[entry]
  483.                     cat.count = cat.count + 1
  484.                 end
  485.  
  486.                 -- add item to category
  487.                 cat.hasItems = true
  488.                 cat.items[cat.count] = {link = itemLink, enchant = enchantId, reforged = reforgeId, slot = slot}
  489.             end
  490.  
  491.             -- calculate avg ilvl
  492.             if calciv then
  493.                 local _,_,rar,lvl = GetItemInfo(itemLink)
  494.                 if lvl then
  495.                     lvl = self:GetActualItemLevel(itemLink) -- ch1.00
  496.                     iLevelSum = iLevelSum + self:GetActualItemLevel(itemLink)
  497.                     iCount = iCount + 1
  498.                 end
  499.             end
  500.         elseif not cached then
  501.             local texture = GetInventoryItemTexture(unit, GetInventorySlotInfo(slot))
  502.             if texture and not retryTimer then
  503.                 -- item link is not yet available, but item texture is, i.e. the slot is not empty
  504.                 -- item link data will become available shortly, so we just try it again in a sec
  505.                 retryTimer = self:ScheduleTimer("Inspect", 1, unit)
  506.             end
  507.         end
  508.     end
  509.  
  510.     if itemsFound then
  511.         self:AddCategory(items, "")
  512.         if calciv and iCount > 0 then
  513.             local avgLvl = iLevelSum / iCount
  514.             AVGIL:SetText(L["Avg. Item Level"] .. ": " .. string.format("%.2f", avgLvl))
  515.             AVGIL:Show()
  516.         else
  517.             AVGIL:Hide()
  518.         end
  519.         self:FixWindowSize()
  520.         if WIN:GetParent() == CharacterFrame and ((GearManagerDialog and GearManagerDialog:IsVisible()) or (OutfitterFrame and OutfitterFrame:IsVisible())) then
  521.             autoHidden = true
  522.         else
  523.             WIN:Show()
  524.         end
  525.     else
  526.         WIN:Hide()
  527.     end
  528. end
  529.  
  530. function IE:AddCategory(cat, prefix)
  531.     -- add items
  532.     if cat.hasItems then
  533.         self:AddItems(cat.items, prefix .. "  ")
  534.     end
  535.  
  536.     -- sort subcategories by item count
  537.     local t = {}
  538.     for name, subcat in pairs(cat.cats) do
  539.         tinsert(t, {name = name, subcat = subcat})
  540.     end
  541.     tsort(t, function(a,b) return a.subcat.count > b.subcat.count end)
  542.  
  543.     -- add subcategories
  544.     for i = 1, #t do
  545.         local name = t[i].name
  546.         local subcat = t[i].subcat
  547.         self:AddLine(prefix .. name .. " (" .. subcat.count .. ")")
  548.         self:AddCategory(subcat, prefix .. "  ")
  549.     end
  550. end
  551.  
  552. function IE:AddItems(tab, padding)
  553.     for _, item in pairs(tab) do
  554.         local suffix = ""
  555.         local prefix = padding
  556.         if InspectEquipConfig.listItemLevels then
  557.             local ilvl = self:GetActualItemLevel(item.link) -- ch1.00
  558.             if ilvl then
  559.                 prefix = padding .. "|cffaaaaaa[" .. ilvl .. "]|r "
  560.             end
  561.         end
  562.         if InspectEquipConfig.checkEnchants and (item.enchant == 0) and (not noEnchantWarningSlots[item.slot]) then
  563.             suffix = "|cffff0000*|r"
  564.         end
  565.     if item.reforged and (item.reforged ~= 0) then
  566.         suffix = suffix .. " |cff00cc00[R]|r"
  567.     end
  568.         self:AddLine(prefix .. item.link .. suffix, item.link, item)
  569.     end
  570. end
  571.  
  572. function IE:GetItemData(item)
  573.     local id
  574.     if type(item) == "number" then
  575.         id = item
  576.     else -- item string/link
  577.         id = tonumber(item:match("item:(%d+)"))
  578.     end
  579.  
  580.     if id then
  581.         local isSrc = IS.Items[id]
  582.         local locSrc = InspectEquipLocalDB.Items[id]
  583.         if isSrc and locSrc then
  584.             -- combine results
  585.             return locSrc .. ";" .. isSrc
  586.         else
  587.             return isSrc or locSrc
  588.         end
  589.     else
  590.         return nil
  591.     end
  592. end
  593.  
  594. function IE:GetZoneName(id)
  595.     return IS.Zones[id] or InspectEquipLocalDB.Zones[id]
  596. end
  597.  
  598. function IE:GetBossName(id)
  599.     return IS.Bosses[id] or InspectEquipLocalDB.Bosses[id]
  600. end
  601.  
  602. function IE:GetItemSourceCategories(itemLink)
  603.     local data = IE:GetItemData(itemLink)
  604.     if data then
  605.         for entry in gmatch(data, "[^;]+") do
  606.             local next_field = gmatch(entry, "[^_]+")
  607.             local cat = next_field()
  608.  
  609.             if cat == "r" or cat == "d" then
  610.                 -- raid/dungeon
  611.                 local zone = IE:GetZoneName(tonumber(next_field()))
  612.                 local mode = next_field()
  613.                 local zoneType
  614.                 if cat == "r" then zoneType = L["Raid"] else zoneType = L["Instances"] end
  615.                 return {zoneType, zone}
  616.             elseif cat == "v" or cat == "g" then
  617.                 -- vendor
  618.                 local mainCat
  619.                 if cat == "v" then mainCat = L["Vendor"] else mainCat = L["Guild Vendor"] end
  620.                 local typ = next_field()
  621.                 while typ do
  622.                     if typ == "c" then
  623.                         -- currency
  624.                         local currency = tonumber(next_field())
  625.                         next_field()
  626.                         local curName = GetCurrencyInfo(currency)
  627.                         return {mainCat, curName}
  628.                     elseif typ == "i" then
  629.                         -- item
  630.                         next_field()
  631.                     elseif typ == "m" then
  632.                         -- money
  633.                         next_field()
  634.                     end
  635.                     typ = next_field()
  636.                 end
  637.                 return {mainCat}
  638.             elseif cat == "f" then
  639.                 -- reputation rewards
  640.                 return {L["Reputation rewards"]}
  641.             elseif cat == "m" then
  642.                 -- darkmoon cards
  643.                 return {L["Darkmoon Faire"]}
  644.             elseif cat == "w" then
  645.                 -- world drops
  646.                 return {L["World drops"]}
  647.             elseif cat == "c" then
  648.                 -- crafted
  649.                 return {L["Crafted"]}
  650.             end
  651.  
  652.         end
  653.     end
  654.     return nil
  655. end
  656.  
  657. function IE:FixWindowSize()
  658.     local maxwidth = TITLE:GetStringWidth()
  659.     for i = 1, numlines do
  660.         local width = lines[i].text:GetStringWidth()
  661.         if maxwidth < width then maxwidth = width end
  662.     end
  663.     local height = (curline * 15) + 55
  664.     if InspectEquipConfig.showAvgItemLevel then
  665.         height = height + 15
  666.     end
  667.     WIN:SetWidth(maxwidth + 40)
  668.     WIN:SetHeight(height)
  669. end
  670.  
  671. function IE.Line_OnEnter(row)
  672.     if row.link then
  673.         GameTooltip:SetOwner(row, "ANCHOR_TOPLEFT")
  674.         if (not cached) and (UnitName(curUnit) == curUnitName) then
  675.             row.link = GetInventoryItemLink(curUnit, GetInventorySlotInfo(row.item.slot)) or row.link
  676.         end
  677.         GameTooltip:SetHyperlink(row.link)
  678.         if row.item and InspectEquipConfig.checkEnchants and (row.item.enchant == 0) and (not noEnchantWarningSlots[row.item.slot]) then
  679.             GameTooltip:AddLine(" ")
  680.             GameTooltip:AddLine("|cffff0000" .. L["Item is not enchanted"] .. "|r")
  681.         end
  682.         GameTooltip:Show()
  683.     end
  684. end
  685.  
  686. function IE.Line_OnLeave(row)
  687.     GameTooltip:Hide()
  688. end
  689.  
  690. function IE.Line_OnClick(row, button)
  691.     if row.link then
  692.         if IsControlKeyDown() then
  693.             DressUpItemLink(row.link)
  694.         elseif IsShiftKeyDown() then
  695.             ChatEdit_InsertLink(row.link)
  696.         end
  697.     end
  698. end
  699.  
  700. function IE:GetActualItemLevel(link)
  701.     local levelAdjust={ -- 11th item:id field and level adjustment
  702.         ["0"]=0,["1"]=8,["373"]=4,["374"]=8,["375"]=4,["376"]=4,
  703.         ["377"]=4,["379"]=4,["380"]=4,["445"]=0,["446"]=4,["447"]=8,
  704.         ["451"]=0,["452"]=8,["453"]=0,["454"]=4,["455"]=8,["456"]=0,
  705.         ["457"]=8,["458"]=0,["459"]=4,["460"]=8,["461"]=12,["462"]=16}
  706.     local baseLevel = select(4,GetItemInfo(link))
  707.     local upgrade = link:match(":(%d+)\124h%[")
  708.     if baseLevel and upgrade then
  709.         return baseLevel + levelAdjust[upgrade]
  710.     else
  711.         return baseLevel
  712.     end
  713. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement