diff Modules/PaperDoll.lua @ 80:bb6b532c5d2f

- added "world state" frame for zone-specific currencies and context-based artifact/experience progress
author Nenue
date Tue, 11 Oct 2016 08:03:41 -0400
parents 83b3cdaae6a5
children 65ec88b30eb8
line wrap: on
line diff
--- a/Modules/PaperDoll.lua	Sun Sep 11 18:46:30 2016 -0400
+++ b/Modules/PaperDoll.lua	Tue Oct 11 08:03:41 2016 -0400
@@ -2,8 +2,7 @@
 -- PaperDoll.lua
 -- Created: 8/16/2016 8:18 AM
 -- %file-revision%
--- Displays item levels by equipment slots
--- Requires tooltip scraping to obtain these numbers, meaning any currently active tooltip will be cleared.
+-- Displays the item level and modifications of character sheet equipment, including artifact power
 
 local plugin = CreateFrame('Frame', 'VeneerPaper', UIParent)
 local vn, print = LibStub("LibKraken").register(Veneer, plugin)
@@ -54,61 +53,105 @@
 local pendingSlots = {}
 
 
+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;
+
+
+  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(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()
+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
+end
+
+
+artifactBar:EnableMouse(true)
+artifactBar:SetScript('OnMouseUp', function()
+  SocketInventoryItem(16)
+end)
+
 local UpdateVeneer = function(itemslot, frame)
   local slot = itemslot:GetID()
   if itemslot.hasItem then
-    frame.link = GetInventoryItemLink('player', slot)
+    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 name, link, something, ilevel = GetItemInfo(frame.link)
-    frame.label:SetText(ilevel)
-    -- todo: test GetExtendedItemInfo()
+      local ilvl
+      if _G['VeneerTooltipTextLeft2'] then
+        ilvl = _G['VeneerTooltipTextLeft2']:GetText():match("Item Level (%d+)")
+        --print('l2', ilvl)
+      end
 
-    local item = {strsplit(":", link)}
-    local _, itemId, enchantId, jewelId1, jewelId2, jewelId3, jewelId4, suffixId,
-    uniqueId, linkLevel, specializationID, instanceDifficultyId, numBonusIds, bonusId1, bonusId2, upgradeValue
+      if _G['VeneerTooltipTextLeft3'] then
+        if  not ilvl then
+        ilvl = _G['VeneerTooltipTextLeft3']:GetText():match("Item Level (%d+)")
+          --print('l3', ilvl)
+        end
+      end
 
-    specializationID, instanceDifficultyId, numBonusIds = item[11], item[12], item[13]
-    jewel[1], jewel[2], jewel[3], jewel[4] = item[4], item[5], item[6], item[7]
-    --vn:print(jewelId1, jewelId2, jewelId3, jewelId4)
-    for i = 1, 4 do
-      local gemslot = frame.gemslot[i]
-      if tonumber(jewel[i]) ~= nil then
-        if not gemslot then
-          gemslot = frame:CreateTexture(itemslot:GetName()..'Gem'..i, 'ARTWORK')
-          gemslot:SetSize(16,16)
-          local posx = 3 + (i-1)*16
-          if slot_anchors[slot]:match('RIGHT') then
-            posx = posx * -1
-          end
-          gemslot:SetPoint(slot_anchors[slot], frame.label, slot_relative[slot], posx, 0)
-          frame.gemslot[i] = gemslot
-        end
-        gemslot:SetTexture(GetItemIcon(jewel[i]))
-        gemslot:Show()
-      else
-        if gemslot then
-          gemslot:Hide()
-        end
-
+      if ilvl then
+        frame.label:SetText(ilvl)
       end
     end
---[[
-    print(link)
-    local difftag = '?'
-    if tonumber(numBonusIds) ~= nil then
-      local name, groupType, isHeroic, isChallengeMode, displayHeroic, displayMythic, toggleDifficultyID = GetDifficultyInfo(numBonusIds)
-      difftag = (name or '??') .. (isHeroic and ' (Heroic)' or '')
+
+    local quality = GetInventoryItemQuality(unit, slot)
+    if slot == 16 and quality == LE_ITEM_QUALITY_ARTIFACT then
+      artifactBar_OnEvent(plugin.artifactBar)
     end
 
-    print(instanceDifficultyId, '|cFF00FFFF',  difftag, numBonusIds)
-    --if tonumber(numBonusIds) ~= nil then
-      for i = 8, #item do
-        print(i..'-', item[i])
-      end
-    --end
 
---]]
+
 
     frame:Show()
   else
@@ -142,7 +185,7 @@
   if not slot_anchors[slot] then
     return
   end
-
+  print(self:GetName())
 
   local frame = _G[name .. 'Veneer']
 
@@ -154,36 +197,34 @@
     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.target = self
     frame.gemslot = {}
-    frame:SetPoint(anchor, self, relative, x, y)
-    frame:SetSize(200,24)
-    frame.label:ClearAllPoints()
-    frame.label:SetPoint(slot_anchors[slot], frame, slot_anchors[slot])
+    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
 
 
 
 plugin.event = function(self, event, ...)
-  print(self, event, flag, slot)
+  print(self, event, ...)
 
   if event == 'PLAYER_EQUIPMENT_CHANGED' then
     local slot, hasItem = ...
     if vnslot[slot] then
       UpdateVeneer(vnslot[slot]:GetParent(), vnslot[slot])
-      plugin.ticker()
+
     end
 
   elseif event == 'PLAYER_ENTERING_WORLD' then
@@ -192,10 +233,16 @@
   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')
 
 
---hooksecurefunc("PaperDollItemSlotButton_Update", PaperDollItemSlotButton_Update)
+hooksecurefunc("PaperDollItemSlotButton_Update", PaperDollItemSlotButton_Update)
+
+hooksecurefunc("PaperDollFrame_UpdateStats", PaperDollFrame_UpdateStats)
\ No newline at end of file