Mercurial > wow > buffalo2
diff Modules/PaperDoll.lua @ 64:ba9c13261bb2
- parametrize buff button customizations
author | Nenue |
---|---|
date | Wed, 17 Aug 2016 15:26:54 -0400 |
parents | ef4116179e2f |
children | 4fe16cb3f5d6 |
line wrap: on
line diff
--- a/Modules/PaperDoll.lua Tue Aug 16 08:37:26 2016 -0400 +++ b/Modules/PaperDoll.lua Wed Aug 17 15:26:54 2016 -0400 @@ -7,24 +7,66 @@ local plugin = CreateFrame('Frame', 'VeneerPaper', UIParent) local vn, print = LibStub("LibKraken").register(VeneerController, plugin) --- PaperDollFrame is separate from InspectUI handlers -local PaperDollItemSlotButton_Update = function(self) - local name = self:GetName() - local slot = self:GetID() - local frame = _G[name .. 'Veneer'] - if not frame then - frame = CreateFrame('Frame', name..'Veneer', self) - frame.label = frame:CreateFontString(nil, 'OVERLAY', 'GameFontNormal') - frame.gemslot = {} - frame:SetPoint('LEFT', self, 'RIGHT') - end +local slot_anchors = { + [1] = 'TOPLEFT', + [2] = 'TOPLEFT', + [3] = 'TOPLEFT', + [15] = 'TOPLEFT', + [5] = 'TOPLEFT', + [9] = 'TOPLEFT', - if self.hasItem then + [10] = 'TOPRIGHT', + [6] = 'TOPRIGHT', + [7] = 'TOPRIGHT', + [8] = 'TOPRIGHT', + [11] = 'TOPRIGHT', + [12] = 'TOPRIGHT', + [13] = 'TOPRIGHT', + [14] = 'TOPRIGHT', + + [16] = 'BOTTOMRIGHT', + [17] = 'BOTTOMLEFT', +} + +local slot_relative = { + [1] = 'TOPRIGHT', + [2] = 'TOPRIGHT', + [3] = 'TOPRIGHT', + [15] = 'TOPRIGHT', + [5] = 'TOPRIGHT', + [9] = 'TOPRIGHT', + + [10] = 'TOPLEFT', + [6] = 'TOPLEFT', + [7] = 'TOPLEFT', + [8] = 'TOPLEFT', + [11] = 'TOPLEFT', + [12] = 'TOPLEFT', + [13] = 'TOPLEFT', + [14] = 'TOPLEFT', + + [16] = 'TOPRIGHT', + [17] = 'TOPLEFT', +} +local ticker +local vnslot = {} +local pendingSlots = {} + +local UpdateVeneer = function(itemslot, frame) + local slot = itemslot:GetID() + if itemslot.hasItem then frame.link = GetInventoryItemLink('player', slot) - frame.gem1, frame.gem2, frame.gem3 = GetInventoryItemGems('player', slot) - frame.label:SetText(GetInventoryItemLink('player', slot)) + --print(frame.link) + local name, link, something, ilevel = GetItemInfo(frame.link) + frame.label:SetText(ilevel) -- todo: test GetExtendedItemInfo() + local lastOwner = GameTooltip:GetOwner() + print(lastOwner) + + GameTooltip:SetOwner(plugin) + GameTooltip:SetInventoryItem('player', slot) + for i = 1, 3 do local gname = 'gem'..i if frame[gname] then @@ -38,7 +80,91 @@ end end -plugin.init = function() - hooksecurefunc("PaperDollItemSlotButton_Update", PaperDollItemSlotButton_Update) +local UpdateAll = function() + for index, frame in pairs(vnslot) do + if frame:IsVisible() then + print('forcing', index, frame:GetName()) + tinsert(pendingSlots, frame) + end + end + plugin.ticker() end +local UpdateNext = function() + + local frame = tremove(pendingSlots) + if frame and frame:IsVisible() then + print('updating', frame:GetName()) + UpdateVeneer(frame:GetParent(), frame) + else + ticker:Cancel() + ticker = nil + end + +end + +-- PaperDollFrame is separate from InspectUI handlers +local PaperDollItemSlotButton_Update = function(self) + local name = self:GetName() + local slot = self:GetID() + if not slot_anchors[slot] then + return + end + + + local frame = _G[name .. 'Veneer'] + + if not frame then + + frame = CreateFrame('Frame', name..'Veneer', self) + vnslot[slot] = frame + + frame.label = frame:CreateFontString(nil, 'OVERLAY', 'VeneerNumberFont') + frame.gemslot = {} + + local anchor, relative, x, y = slot_anchors[slot], slot_relative[slot], 8, -4 + if anchor:match('RIGHT') then + x = -x + end + if anchor:match('BOTTOM') then + y = 4 + end + + + frame:SetPoint(anchor, self, relative, x, y) + frame:SetSize(200,24) + frame.label:ClearAllPoints() + frame.label:SetPoint(slot_anchors[slot], frame, slot_anchors[slot]) + + tinsert(pendingSlots, frame) + end +end + + +plugin.ticker = function() + if (not ticker) and #pendingSlots >= 1 then + ticker = C_Timer.NewTicker(0, UpdateNext) + end +end + + +plugin.event = function(self, event, flag, slot) + print(self, event, flag, slot) + + + plugin.ticker() +end +plugin:SetScript('OnEvent', plugin.event) +plugin:RegisterUnitEvent('UNIT_INVENTORY_CHANGED', 'player') + +hooksecurefunc("ToggleCharacter", UpdateAll) +hooksecurefunc("PaperDollItemSlotButton_Update", PaperDollItemSlotButton_Update) + +hooksecurefunc(GameTooltip, "SetInventoryItem", function(self, unit, slot) + if self:GetOwner() == plugin then + if unit == 'player' and vnslot[slot] then + vnslot[slot].label:SetText(GameTooltipTextLeft3:GetText():match('%d+')) + end + end +end) +