Mercurial > wow > buffalo2
diff Modules/PaperDoll.lua @ 93:caded2668701
Curseforge migration and source tree cleaning
author | Nenue |
---|---|
date | Sun, 01 Jan 2017 18:25:26 -0500 |
parents | 74e714637d6a |
children | bb38bc0e787f |
line wrap: on
line diff
--- a/Modules/PaperDoll.lua Tue Oct 25 12:33:20 2016 -0400 +++ b/Modules/PaperDoll.lua Sun Jan 01 18:25:26 2017 -0500 @@ -3,248 +3,418 @@ -- Created: 8/16/2016 8:18 AM -- %file-revision% -- Displays the item level and modifications of character sheet equipment, including artifact power +local print = DEVIAN_WORKSPACE and function(...) print('PaperDoll', ...) end or nop -local plugin = CreateFrame('Frame', 'VeneerPaper', UIParent) -local vn, print = LibStub("LibKraken").register(Veneer, plugin) +local slot_overlays = {} +VeneerPaperDollMixin = { + anchorFrame = 'CharacterFrame', + anchorPoint = 'TOPLEFT', + KnownRelics = {}, +} + +local relic_slot_paths = { + Arcane = {"Relic-Arcane-Slot", [[Interface\Artifacts\Artifacts.BLP]], 72, 72, 0.849609375, 0.919921875, 0.1181640625, 0.1884765625, false, false}, + Blood = {"Relic-Blood-Slot", [[Interface\Artifacts\Artifacts.BLP]], 72, 72, 0.921875, 0.9921875, 0.1181640625, 0.1884765625, false, false}, + Fel = {"Relic-Fel-Slot", [[Interface\Artifacts\Artifacts.BLP]], 72, 72, 0.59765625, 0.66796875, 0.572265625, 0.642578125, false, false}, + Fire = {"Relic-Fire-Slot", [[Interface\Artifacts\Artifacts.BLP]], 72, 72, 0.669921875, 0.740234375, 0.572265625, 0.642578125, false, false}, + Frost = {"Relic-Frost-Slot", [[Interface\Artifacts\Artifacts.BLP]], 72, 72, 0.7421875, 0.8125, 0.572265625, 0.642578125, false, false}, + Holy = {"Relic-Holy-Slot", [[Interface\Artifacts\Artifacts.BLP]], 72, 72, 0.814453125, 0.884765625, 0.572265625, 0.642578125, false, false}, + Iron = {"Relic-Iron-Slot", [[Interface\Artifacts\Artifacts.BLP]], 72, 72, 0.88671875, 0.95703125, 0.572265625, 0.642578125, false, false}, + Life = {"Relic-Life-Slot", [[Interface\Artifacts\Artifacts.BLP]], 72, 72, 0.59765625, 0.66796875, 0.64453125, 0.71484375, false, false}, + Shadow = {"Relic-Shadow-Slot", [[Interface\Artifacts\Artifacts.BLP]], 72, 72, 0.59765625, 0.66796875, 0.716796875, 0.787109375, false, false}, + Water = {"Relic-Water-Slot", [[Interface\Artifacts\Artifacts.BLP]], 72, 72, 0.59765625, 0.66796875, 0.7890625, 0.859375, false, false}, + Wind = {"Relic-Wind-Slot", [[Interface\Artifacts\Artifacts.BLP]], 72, 72, 0.59765625, 0.66796875, 0.861328125, 0.931640625, false, false}, +} + +local slots_left = {'TOPLEFT', 'TOPRIGHT', 1, 0, 'TOPLEFT', 'BOTTOMLEFT', 0, -1} +local slots_right = {'TOPRIGHT', 'TOPLEFT', -1, 0, 'TOPRIGHT', 'BOTTOMRIGHT', 0, -1} +local slots_bottomleft = {'BOTTOMRIGHT', 'TOPRIGHT', 0, 1, 'BOTTOMRIGHT', 'TOPRIGHT', 0, 1 } +local slots_bottomright = {'BOTTOMLEFT', 'TOPLEFT', 0, -1, 'BOTTOMLEFT', 'TOPLEFT', 0, 1} local slot_anchors = { - [1] = 'TOPLEFT', - [2] = 'TOPLEFT', - [3] = 'TOPLEFT', - [15] = 'TOPLEFT', - [5] = 'TOPLEFT', - [9] = 'TOPLEFT', + [1] = slots_left, + [2] = slots_left, + [3] = slots_left, + [15] = slots_left, + [5] = slots_left, + [9] = slots_left, - [10] = 'TOPRIGHT', - [6] = 'TOPRIGHT', - [7] = 'TOPRIGHT', - [8] = 'TOPRIGHT', - [11] = 'TOPRIGHT', - [12] = 'TOPRIGHT', - [13] = 'TOPRIGHT', - [14] = 'TOPRIGHT', + [10] = slots_right, + [6] = slots_right, + [7] = slots_right, + [8] = slots_right, + [11] = slots_right, + [12] = slots_right, + [13] = slots_right, + [14] = slots_right, - [16] = 'BOTTOMRIGHT', - [17] = 'BOTTOMLEFT', + [16] = slots_bottomleft, + [17] = slots_bottomright, } -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', +function VeneerPaperDollMixin:OnLoad() + hooksecurefunc("PaperDollItemSlotButton_Update", function(...) + self:GetSlotButton(PaperDollItemsFrame, ...) + end) - [16] = 'TOPRIGHT', - [17] = 'TOPLEFT', -} -local ticker -local vnslot = {} -local pendingSlots = {} + hooksecurefunc("PaperDollFrame_UpdateStats", function(...) + self:GetStats(PaperDollItemsFrame, ...) + end) + self:RegisterEvent('ADDON_LOADED') + self:RegisterEvent('INSPECT_READY') -local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo -local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank -local tooltip = CreateFrame('GameTooltip', 'VeneerTooltip', UIParent, 'GameTooltipTemplate') -local jewel = {} - -local artifactBar_OnEvent = function (self) - local itemID, altItemID, name, icon, totalXP, pointsSpent = GetEquippedArtifactInfo() - if not itemID then - self:Hide() - return - end - - local numRelicSlots = C_ArtifactUI.GetNumRelicSlots() or 0; - for i = 1, numRelicSlots do - - end - - local pointsAvailable = 0 - local nextRankCost = GetCostForPointAtRank(pointsSpent + pointsAvailable) or 0 - - while totalXP >= nextRankCost do - totalXP = totalXP - nextRankCost - pointsAvailable = pointsAvailable + 1 - nextRankCost = GetCostForPointAtRank(pointsSpent + pointsAvailable) or 0 - end - self.Header:SetText(name) - self.Level:SetText((pointsAvailable >= 1) and (pointsSpent .. ' ('.. pointsAvailable..')') or (pointsSpent)) - self.ProgressText:SetFormattedText("|cFF00FFFF%d|r / %d", totalXP, nextRankCost) - - self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self:GetWidth()*(totalXP/nextRankCost), 0) - self.ProgressBar:SetColorTexture(1,.5,0) - - self:Show() + self.SocketType = {} end - -local artifactBar = CreateFrame('Frame', 'VnPaperDollArtifact', CharacterModelFrame, 'VeneerStatusBarTemplate') -artifactBar:ClearAllPoints() -artifactBar:SetHeight(28) -artifactBar:SetPoint('LEFT', CharacterModelFrame, 'LEFT', 30, 0) -artifactBar:SetPoint('RIGHT', CharacterModelFrame, 'RIGHT', -30, 0) -artifactBar:SetPoint('BOTTOM', CharacterMainHandSlotFrame, 'TOP', 0, 1) -artifactBar.ProgressBG:SetColorTexture(0.5, 0.5, 0.5) -artifactBar.Header:Show() -artifactBar:RegisterEvent('ARTIFACT_UPDATE') -artifactBar:SetScript('OnEvent', artifactBar_OnEvent) - -plugin.artifactBar = artifactBar -print(CharacterMainHandSlotFrame:GetPoint(1)) -print(artifactBar:GetPoint(3)) - -for i = 1, 3 do - local relicSlot = CreateFrame('Frame', 'VnPaperDollRelic'..i, artifactBar) - relicSlot:SetSize(40,40) - relicSlot:SetPoint('BOTTOM', artifactBar, 'TOP', (i-2)*40, 24) - relicSlot.relicArt = relicSlot:CreateTexture(nil, 'BACKGROUND') - artifactBar['RelicSlot'..i] = relicSlot +function VeneerPaperDollMixin:SetupInspectFrame() + hooksecurefunc("InspectPaperDollItemSlotButton_Update", function(...) + self:GetSlotButton(InspectFrame, ...) + end) + self:RegisterEvent('INSPECT_READY') +end +function VeneerPaperDollMixin:SetupArtifactUI() + self:RegisterEvent('ARTIFACT_UPDATE') end +function VeneerPaperDollMixin:Setup() + VeneerData.PaperDoll = VeneerData.PaperDoll or {} + VeneerData.PaperDoll.KnownRelics = VeneerData.PaperDoll.KnownRelics or {} + self.KnownRelics = VeneerData.PaperDoll.KnownRelics -artifactBar:EnableMouse(true) -artifactBar:SetScript('OnMouseUp', function() - SocketInventoryItem(16) -end) + self:RegisterEvent('UNIT_INVENTORY_CHANGED') + self:RegisterEvent('PLAYER_EQUIPMENT_CHANGED') + self:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED') -local UpdateVeneer = function(itemslot, frame) - local slot = itemslot:GetID() - if itemslot.hasItem then - local unit = frame.target.unit or 'player' - frame.link = GetInventoryItemLink(unit, slot) - tooltip:SetOwner(frame, 'ANCHOR_NONE') - tooltip:SetInventoryItem(unit, slot) - tooltip:Show() - --print(tooltip:NumLines()) - if tooltip:NumLines() >= 3 then - - local ilvl - if _G['VeneerTooltipTextLeft2'] then - ilvl = _G['VeneerTooltipTextLeft2']:GetText():match("Item Level (%d+)") - --print('l2', ilvl) - end - - if _G['VeneerTooltipTextLeft3'] then - if not ilvl then - ilvl = _G['VeneerTooltipTextLeft3']:GetText():match("Item Level (%d+)") - --print('l3', ilvl) - end - end - - if ilvl then - frame.label:SetText(ilvl) - end - end - - local quality = GetInventoryItemQuality(unit, slot) - if slot == 16 and quality == LE_ITEM_QUALITY_ARTIFACT then - artifactBar_OnEvent(plugin.artifactBar) - end - - - - - frame:Show() - else - frame:Hide() - end + self:MarkForUpdate() end -local UpdateNext = function(frame) - - plugin.next(function() - print('updating', frame:GetName()) - UpdateVeneer(frame:GetParent(), frame) - end) -end - - -local UpdateAll = function() - for index, frame in pairs(vnslot) do - if frame:IsVisible() then - print('forcing', index, frame:GetName()) - UpdateNext(frame) +function VeneerPaperDollMixin:MarkForUpdate() + for frame, overlays in pairs(slot_overlays) do + for slot, overlay in pairs(overlays) do + if overlay:IsVisible() then + overlay:Update() + else + overlay.isDirty = true + end end end end +function VeneerPaperDollMixin:GetStats() +end +function VeneerPaperDollMixin:GetSlotButton(panel, frame) + print('|cFF00FF88'..self:GetName()..':GetSlotButton()', frame:GetName(), frame:GetID()) + local slot = frame:GetID() + local unit = panel.unit or 'player' + if slot_anchors[slot] then + slot_overlays[panel] = slot_overlays[panel] or {} + local overlay = slot_overlays[panel][slot] + if not overlay then + overlay = CreateFrame('Frame', 'VeneerPaperDollSlot' .. unit .. slot, frame, 'VeneerPaperDollSlotInfoTemplate') + overlay:SetID(slot) + slot_overlays[panel][slot] = overlay + overlay.checkRelic = frame.checkRelic --- 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 + local anchorPoint, relativePoint, dX, dY, statPoint, statRelative, statdX, statdY = unpack(slot_anchors[slot]) + local offset = 7 + overlay:SetPoint(anchorPoint, frame, relativePoint, dX * offset, dY * offset) + overlay:SetSize(frame:GetWidth()*3, frame:GetHeight()) + + local relativeFrame = overlay + for i, region in ipairs(overlay.StatsLeft) do + region:ClearAllPoints() + print(statPoint, relativeFrame, (i == 1) and statPoint or statRelative) + region:SetPoint(statPoint, relativeFrame, (i == 1) and statPoint or statRelative, 0, 0) + relativeFrame = region + end + if slot == 16 then + overlay.Sockets:ClearAllPoints() + overlay.Sockets:SetPoint('BOTTOM', CharacterFrameInsetBg, 'BOTTOM', 0, frame:GetHeight() + 14) + overlay.ItemLevel:SetFontObject(VeneerNumberFontLarge) + overlay.ItemLevel:ClearAllPoints() + overlay.ItemLevel:SetPoint('BOTTOM', overlay.Sockets, 'TOP', 0, 4) + end + + print(overlay.Sockets:GetPoint(1)) + overlay.anchors = slot_anchors[slot] + end + + overlay.unit = unit + overlay.checkRelic = (unit == 'player' and slot == 16) + + + if frame.hasItem then + overlay.isDirty = true + overlay:Show() + else + overlay:Hide() + end end - print(self:GetName()) - - 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 = {} - - - frame.target = self - frame.gemslot = {} - frame:SetAllPoints(self) - frame:SetParent(self) - frame.label:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', 2, 2) - - tinsert(pendingSlots, frame) - end - - UpdateVeneer(self, frame) - end -local PaperDollFrame_UpdateStats = function() -end +function VeneerPaperDollMixin:OnEvent(event, arg) + print(event, arg) + if event == 'ADDON_LOADED' then + if IsLoggedIn() and not self.initialized then + self:Setup() + self.initialized = true + end -plugin.event = function(self, event, ...) - print(self, event, ...) - - if event == 'PLAYER_EQUIPMENT_CHANGED' then - local slot, hasItem = ... - if vnslot[slot] then - UpdateVeneer(vnslot[slot]:GetParent(), vnslot[slot]) + if arg == 'Blizzard_InspectUI' then + self:SetupInspectFrame() + end + if arg == 'Blizzard_ArtifactUI' then + self:SetupArtifactUI() + self:MarkForUpdate() + end + elseif event == 'ARTIFACT_UPDATE' then + self:MarkForUpdate() + else + if (event == 'PLAYER_SPECIALIZATION_CHANGED' or event == 'UNIT_INVENTORY_CHANGED') then + if arg ~= 'player' then + return + end + elseif event == 'INSPECT_READY' then end - elseif event == 'PLAYER_ENTERING_WORLD' then - UpdateAll() + self:MarkForUpdate() end - -end -local artifactBarCreated -plugin.init = function() - LoadAddOn('Blizzard_ArtifactUI') end ---plugin:SetScript('OnEvent', plugin.event) -plugin:RegisterEvent('PLAYER_EQUIPMENT_CHANGED') -plugin:RegisterEvent('PLAYER_ENTERING_WORLD') +VeneerPaperDollSlotMixin = {} -hooksecurefunc("PaperDollItemSlotButton_Update", PaperDollItemSlotButton_Update) +function VeneerPaperDollSlotMixin:OnLoad() + self.SocketText = {} + self.SocketType = {} + self.SocketLink = {} +end +function VeneerPaperDollSlotMixin:OnShow() + if self.isDirty then + self:Update() + end +end +function VeneerPaperDollSlotMixin:OnUpdate() + if self.isDirty then + --print('|cFF00FF00pushing update for', self:GetID()) + self:Update() + end -hooksecurefunc("PaperDollFrame_UpdateStats", PaperDollFrame_UpdateStats) \ No newline at end of file + if self.checkRelic then + self.tooltipLink = nil + for i = 1, 3 do + if self.SocketLink[i] and self.Sockets.SocketIcon[i]:IsMouseOver() then + self.tooltipLink = self.SocketLink[i] + end + end + + if self.tooltipLink then + if not GameTooltip:IsOwned(self) then + GameTooltip:SetOwner(self, 'ANCHOR_CURSOR') + GameTooltip:SetHyperlink(self.tooltipLink) + + GameTooltip:Show() + end + else + if GameTooltip:IsOwned(self) then + GameTooltip:Hide() + end + end + end +end + +function VeneerPaperDollSlotMixin:UpdateRelicInfo() + + + local itemID = GetInventoryItemID(self.unit, 16) + if not itemID then + return + end + print('|cFF00FFFFRelic Sweep:', itemID) + + + local guid = UnitGUID(self.unit or 'player') + local relicCache = VeneerPaperDoll.KnownRelics[guid] and VeneerPaperDoll.KnownRelics[guid][itemID] + if VeneerPaperDoll.KnownRelics[guid] then + for k, v in pairs(VeneerPaperDoll.KnownRelics[guid]) do + if tonumber(k) and tonumber(k) < 72 then + VeneerPaperDoll.KnownRelics[guid][k] = nil + end + end + end + + + if not relicCache then + relicCache = {} + VeneerPaperDoll.KnownRelics[guid] = VeneerPaperDoll.KnownRelics[guid] or {} + VeneerPaperDoll.KnownRelics[guid][itemID] = relicCache + end + + local numRelics = C_ArtifactUI.GetNumRelicSlots() + local isEquipped = C_ArtifactUI.IsViewedArtifactEquipped() + local tooltip = VeneerPaperDollTooltip + tooltip:SetOwner(self, 'ANCHOR_NONE') + self.hasRelicSlots = true + if numRelics and isEquipped then + print('Relic Query:', itemID, numRelics) + self.checkRelic = nil + for i = 1, numRelics do + local lockedReason, relicName, relicIcon, relicLink = C_ArtifactUI.GetRelicInfo(i); + local relicType = C_ArtifactUI.GetRelicSlotType(i); + if relicIcon then + tooltip:SetHyperlink(relicLink) + print(tooltip:NumLines()) + + local line1 = _G['VeneerPaperDollTooltipTextLeft2'] + local line2 = _G['VeneerPaperDollTooltipTextLeft3'] + local text1 = line1 and line1:GetText() + local text2 = line2 and line2:GetText() + if text1 or text2 then + self.SocketText[i] = text1:match('Item Level (%d+)') or text2:match('Item Level (%d+)') + end + + self.SocketInfo[i] = relicIcon + self.SocketType[i] = relicType + self.SocketLink[i] = relicLink + print('storing', i, self.SocketInfo[i], self.SocketText[i], self.SocketType[i], self.SocketLink[i]) + else + + self.SocketInfo[i] = "Interface\\CharacterFrame\\TempPortraitAlphaMask" + self.SocketType[i] = relicType + self.SocketLink[i] = nil + end + + relicCache[i] = {self.SocketInfo[i], self.SocketText[i], self.SocketType[i], self.SocketLink[i]} + end + end + + for i = 1, 3 do + if relicCache[i] then + local relicIcon, relicLevel, relicType, relicLink = unpack(relicCache[i]) + + print('loading', i, relicIcon, relicLevel, relicType, relicLink) + self.SocketInfo[i] = relicIcon + self.SocketText[i] = relicLevel + self.SocketType[i] = relicType + self.SocketLink[i] = relicLink + end + end +end + +local SocketIcon_Update = function(frame) +end + +function VeneerPaperDollSlotMixin:Update() + local id = self:GetID() + + self.SocketInfo = self.SocketInfo or {} + table.wipe(self.SocketInfo) + self.ItemLevel:SetText(nil) + + local tooltip = VeneerPaperDollTooltip + tooltip:SetOwner(self, 'ANCHOR_NONE') + print('refresh', self.unit, id) + tooltip:SetInventoryItem(self.unit or 'player', id) + tooltip:Show() + + local numLines = tooltip:NumLines() + local numTextures = 0 + local itemLevel + local itemLevelLine + print('|cFFFFFF00Sockets scan:', numLines) + for i = 1, numLines do + local line = _G['VeneerPaperDollTooltipTextLeft'..i] + local text = line and line:GetText() + if text then + itemLevel = text:match('Item Level (%d+)') + if itemLevel then + self.ItemLevel:SetText(itemLevel) + break + end + end + + local texture = _G['VeneerPaperDollTooltipTexture'..i] + if texture and texture:IsShown() then + numTextures = numTextures + 1 + print('picked up socket', numTextures, texture:GetTexture()) + self.SocketInfo[numTextures] = texture:GetTexture() + end + end + if self.checkRelic then + self:UpdateRelicInfo() + end + + + local relativeIcon + local socketsWidth = 0 + local socketsHeight = 24 + for index, icon in ipairs(self.Sockets.SocketIcon) do + if self.SocketInfo[index] then + print('|cFF0088FFsocketInfo|r', index, self.SocketInfo[index]) + icon:ClearAllPoints() + + icon:SetTexture(self.SocketInfo[index]) + icon:SetSize(16, 16) + icon:Show() + if index == 1 then + icon:SetPoint('LEFT', self.Sockets, 'LEFT', 0, 0) + socketsWidth = socketsWidth + icon:GetWidth() + socketsHeight = icon:GetHeight() + else + if id == 16 then + icon:SetPoint('LEFT', relativeIcon, 'RIGHT', 14, 0) + socketsWidth = socketsWidth + 14 + else + icon:SetPoint('LEFT', relativeIcon, 'RIGHT', 2, 0) + socketsWidth = socketsWidth + 2 + end + socketsWidth = socketsWidth + icon:GetWidth() + end + + local label = self.Sockets.SocketLabel[index] + label:ClearAllPoints() + label:SetPoint('BOTTOM', icon, 'TOP',0, 2) + label:SetFontObject(VeneerNumberFont) + label:SetText(self.SocketText[index]) + + if self.checkRelic then + local relicAtlasName = ("Relic-%s-Slot"):format(self.SocketType[index]); + self.Sockets.SocketBg = self.Sockets.SocketBg or {} + self.Sockets.SocketBg[index] = self.Sockets.SocketBg[index] or self.Sockets:CreateTexture() + self.Sockets.SocketBg[index]:SetAtlas(relicAtlasName) + self.Sockets.SocketBg[index]:SetPoint('TOPRIGHT', icon, 'TOPRIGHT', 12, 12) + self.Sockets.SocketBg[index]:SetPoint('BOTTOMLEFT', icon, 'BOTTOMLEFT', -12,-12) + print('', self.SocketType[index], relicAtlasName) + + socketsHeight = self.Sockets.SocketBg[index]:GetHeight() + end + + + relativeIcon = icon + else + if self.checkRelic and self.Sockets.SocketBg and self.Sockets.SocketBg[index] then + self.Sockets.SocketBg[index]:SetTexture(nil) + self.Sockets.SocketLabel[index]:SetText(nil) + end + + icon:Hide() + end + + + end + self.Sockets:SetWidth(socketsWidth) + self.Sockets:SetHeight(socketsHeight) + + + + + + self.isDirty = nil +end \ No newline at end of file