Nenue@62: -- Veneer Nenue@62: -- PaperDoll.lua Nenue@62: -- Created: 8/16/2016 8:18 AM Nenue@62: -- %file-revision% Nenue@65: -- Displays item levels by equipment slots Nenue@65: -- Requires tooltip scraping to obtain these numbers, meaning any currently active tooltip will be cleared. Nenue@62: Nenue@62: local plugin = CreateFrame('Frame', 'VeneerPaper', UIParent) Nenue@62: local vn, print = LibStub("LibKraken").register(VeneerController, plugin) Nenue@62: Nenue@64: local slot_anchors = { Nenue@64: [1] = 'TOPLEFT', Nenue@64: [2] = 'TOPLEFT', Nenue@64: [3] = 'TOPLEFT', Nenue@64: [15] = 'TOPLEFT', Nenue@64: [5] = 'TOPLEFT', Nenue@64: [9] = 'TOPLEFT', Nenue@62: Nenue@64: [10] = 'TOPRIGHT', Nenue@64: [6] = 'TOPRIGHT', Nenue@64: [7] = 'TOPRIGHT', Nenue@64: [8] = 'TOPRIGHT', Nenue@64: [11] = 'TOPRIGHT', Nenue@64: [12] = 'TOPRIGHT', Nenue@64: [13] = 'TOPRIGHT', Nenue@64: [14] = 'TOPRIGHT', Nenue@64: Nenue@64: [16] = 'BOTTOMRIGHT', Nenue@64: [17] = 'BOTTOMLEFT', Nenue@64: } Nenue@64: Nenue@64: local slot_relative = { Nenue@64: [1] = 'TOPRIGHT', Nenue@64: [2] = 'TOPRIGHT', Nenue@64: [3] = 'TOPRIGHT', Nenue@64: [15] = 'TOPRIGHT', Nenue@64: [5] = 'TOPRIGHT', Nenue@64: [9] = 'TOPRIGHT', Nenue@64: Nenue@64: [10] = 'TOPLEFT', Nenue@64: [6] = 'TOPLEFT', Nenue@64: [7] = 'TOPLEFT', Nenue@64: [8] = 'TOPLEFT', Nenue@64: [11] = 'TOPLEFT', Nenue@64: [12] = 'TOPLEFT', Nenue@64: [13] = 'TOPLEFT', Nenue@64: [14] = 'TOPLEFT', Nenue@64: Nenue@64: [16] = 'TOPRIGHT', Nenue@64: [17] = 'TOPLEFT', Nenue@64: } Nenue@64: local ticker Nenue@64: local vnslot = {} Nenue@64: local pendingSlots = {} Nenue@64: Nenue@65: Nenue@65: Nenue@64: local UpdateVeneer = function(itemslot, frame) Nenue@64: local slot = itemslot:GetID() Nenue@64: if itemslot.hasItem then Nenue@62: frame.link = GetInventoryItemLink('player', slot) Nenue@64: --print(frame.link) Nenue@64: local name, link, something, ilevel = GetItemInfo(frame.link) Nenue@64: frame.label:SetText(ilevel) Nenue@62: -- todo: test GetExtendedItemInfo() Nenue@62: Nenue@64: GameTooltip:SetOwner(plugin) Nenue@64: GameTooltip:SetInventoryItem('player', slot) Nenue@65: GameTooltip:Hide() Nenue@64: Nenue@62: for i = 1, 3 do Nenue@62: local gname = 'gem'..i Nenue@62: if frame[gname] then Nenue@62: frame.gemslot[i] = frame.gemslot[i] or frame:CreateTexture(nil, 'ARTWORK') Nenue@62: print(frame[gname]) Nenue@62: end Nenue@62: end Nenue@62: frame:Show() Nenue@62: else Nenue@62: frame:Hide() Nenue@62: end Nenue@62: end Nenue@62: Nenue@64: local UpdateAll = function() Nenue@64: for index, frame in pairs(vnslot) do Nenue@64: if frame:IsVisible() then Nenue@64: print('forcing', index, frame:GetName()) Nenue@64: tinsert(pendingSlots, frame) Nenue@64: end Nenue@64: end Nenue@64: plugin.ticker() Nenue@62: end Nenue@62: Nenue@64: local UpdateNext = function() Nenue@64: Nenue@64: local frame = tremove(pendingSlots) Nenue@64: if frame and frame:IsVisible() then Nenue@64: print('updating', frame:GetName()) Nenue@64: UpdateVeneer(frame:GetParent(), frame) Nenue@64: else Nenue@65: Nenue@64: ticker:Cancel() Nenue@64: ticker = nil Nenue@64: end Nenue@64: Nenue@64: end Nenue@64: Nenue@64: -- PaperDollFrame is separate from InspectUI handlers Nenue@64: local PaperDollItemSlotButton_Update = function(self) Nenue@64: local name = self:GetName() Nenue@64: local slot = self:GetID() Nenue@64: if not slot_anchors[slot] then Nenue@64: return Nenue@64: end Nenue@64: Nenue@64: Nenue@64: local frame = _G[name .. 'Veneer'] Nenue@64: Nenue@64: if not frame then Nenue@64: Nenue@64: frame = CreateFrame('Frame', name..'Veneer', self) Nenue@64: vnslot[slot] = frame Nenue@64: Nenue@64: frame.label = frame:CreateFontString(nil, 'OVERLAY', 'VeneerNumberFont') Nenue@64: frame.gemslot = {} Nenue@64: Nenue@64: local anchor, relative, x, y = slot_anchors[slot], slot_relative[slot], 8, -4 Nenue@64: if anchor:match('RIGHT') then Nenue@64: x = -x Nenue@64: end Nenue@64: if anchor:match('BOTTOM') then Nenue@64: y = 4 Nenue@64: end Nenue@64: Nenue@64: Nenue@64: frame:SetPoint(anchor, self, relative, x, y) Nenue@64: frame:SetSize(200,24) Nenue@64: frame.label:ClearAllPoints() Nenue@64: frame.label:SetPoint(slot_anchors[slot], frame, slot_anchors[slot]) Nenue@64: Nenue@64: tinsert(pendingSlots, frame) Nenue@64: end Nenue@66: Nenue@66: plugin.ticker() Nenue@64: end Nenue@64: Nenue@64: Nenue@64: plugin.ticker = function() Nenue@64: if (not ticker) and #pendingSlots >= 1 then Nenue@64: ticker = C_Timer.NewTicker(0, UpdateNext) Nenue@64: end Nenue@64: end Nenue@64: Nenue@64: Nenue@65: plugin.event = function(self, event, ...) Nenue@64: print(self, event, flag, slot) Nenue@64: Nenue@65: if event == 'PLAYER_EQUIPMENT_CHANGED' then Nenue@65: local slot, hasItem = ... Nenue@65: if vnslot[slot] then Nenue@65: UpdateVeneer(vnslot[slot]:GetParent(), vnslot[slot]) Nenue@65: plugin.ticker() Nenue@65: end Nenue@64: Nenue@66: elseif event == 'PLAYER_ENTERING_WORLD' then Nenue@66: UpdateAll() Nenue@66: Nenue@65: end Nenue@65: Nenue@64: end Nenue@66: Nenue@64: plugin:SetScript('OnEvent', plugin.event) Nenue@65: plugin:RegisterEvent('PLAYER_EQUIPMENT_CHANGED') Nenue@66: plugin:RegisterEvent('PLAYER_ENTERING_WORLD') Nenue@64: Nenue@66: Nenue@64: hooksecurefunc("PaperDollItemSlotButton_Update", PaperDollItemSlotButton_Update) Nenue@64: Nenue@64: hooksecurefunc(GameTooltip, "SetInventoryItem", function(self, unit, slot) Nenue@64: if self:GetOwner() == plugin then Nenue@64: if unit == 'player' and vnslot[slot] then Nenue@65: Nenue@66: local text Nenue@66: for i = 1, 3 do Nenue@66: text = _G['GameTooltipTextLeft'..i]:GetText() Nenue@66: text = text:match('Item Level (%d+)') Nenue@66: if text then Nenue@66: break Nenue@66: end Nenue@65: end Nenue@65: vnslot[slot].label:SetText(text or '???') Nenue@64: end Nenue@64: end Nenue@64: end) Nenue@64: