changeset 111:1196c2bad31c

- obtain World Quest AP via WorldPlan - artifact button text adjustments - removed from UISpecialFrames to fix hiding on map open
author Nick@Zahhak
date Tue, 21 Mar 2017 16:33:51 -0400
parents 73316951ce73
children 7c77fde36287
files Modules/ArtifactPower.lua Modules/ArtifactPower.xml Modules/TalkingHead.lua Modules/WorldState.lua
diffstat 4 files changed, 199 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/Modules/ArtifactPower.lua	Mon Mar 06 02:31:15 2017 -0500
+++ b/Modules/ArtifactPower.lua	Tue Mar 21 16:33:51 2017 -0400
@@ -35,7 +35,9 @@
   3115000, 3270000, 3435000, 3605000, 3785000,
   3975000, 4175000, 4385000, 4605000
 }
-
+local FISHING_MAX_TRAITS = 24
+local WEAPON_MAX_TRAITS = 54
+local BUTTON_SIZE = 48
 local FRAME_LIST = {'ContainerFrame1', 'BankFrame'}
 local BAG_FRAMES = {'ContainerFrame1'}
 local BANK_FRAMES = {'BankFrame'}
@@ -76,7 +78,6 @@
   end
 
   self.tooltip = CreateFrame('GameTooltip', TOOLTIP_NAME, self, 'GameTooltipTemplate')
-  tinsert(UISpecialFrames, self:GetName())
 
 
 end
@@ -119,7 +120,17 @@
   if not InCombatLockdown() then
     local info = tremove(queued_hooks)
     while info do
-      print('hooking', unpack(info))
+      --[[local oFunc = tremove(info, #info)
+      local args = info
+
+      local func = function(...)
+        print('|cFFFF0088Callback:|r', unpack(args))
+
+        oFunc(...)
+      end
+      print('hooking', unpack(info), oFunc, func)
+      hooksecurefunc(unpack(info), func)
+      --]]
       hooksecurefunc(unpack(info))
       info = tremove(queued_hooks)
     end
@@ -131,6 +142,7 @@
   for funcName, func in pairs(args.FrameMethods) do
     print('binding', frame:GetName(), funcName, 'to', tostring(func))
     CreateHook(frame, funcName, function()
+      print(frame:GetName(), funcName, 'hook')
       VeneerArtifactPower:TryToShow()
     end)
   end
@@ -182,6 +194,7 @@
   end)
 
   local DoTryToShow = function()
+
     self:TryToShow()
   end
   CreateHook("OpenBackpack", DoTryToShow)
@@ -227,6 +240,14 @@
 
 local UNDERLIGHT_ANGLER_ID = 133755
 
+function ap:ResetCache()
+  table.wipe(self.cache.items)
+  table.wipe(self.cache.fishing)
+  table.wipe(self.cache.bags)
+  table.wipe(self.cache.bagItems)
+  self:ScanAllBags()
+end
+
 function ap:QueueBag(containerID)
   containerID = tonumber(containerID)
   if not containerID then
@@ -261,7 +282,7 @@
   self:Reanchor()
 end
 function ap:OnHide()
-  print('|cFF88FF00OnHide()|r')
+  print('|cFF88FF00OnHide()|r', debugstack())
   self:Reanchor()
 end
 function ap:OnEnter()
@@ -281,7 +302,7 @@
   if not InCombatLockdown() then
     for _, name in ipairs(FRAME_LIST) do
       print('test:', name, (_G[name] and _G[name]:IsShown()))
-      if _G[name] and _G[name]:IsShown() then
+      if _G[name] and _G[name]:IsVisible() then
         if self:IsShown() then
           self:Update()
         else
@@ -292,7 +313,7 @@
     end
   end
 
-
+  print('failed tests')
   self:Hide()
 end
 
@@ -359,8 +380,13 @@
 function ap:OnUpdate()
   if #self.scanQueue >= 1 then
     local scanInfo = tremove(self.scanQueue, 1)
+  end
+  if IsShiftKeyDown() then
+    self.Refresh:Show()
+  else
+    self.Refresh:Hide()
+  end
 
-  end
 end
 
 function ap:OnMouseDown()
@@ -381,30 +407,58 @@
   elseif not (self.bankAP and self.bagAP) then
     bankText = '|cFFFF0000Open bank frame to count all AP|r '
   else
-    if (self.bagAP + self.bankAP) == 0 then
-      bankText = '|cFFFF4400No Artifact Power tokens on hand|r'
-    else
-      if self.bagAP and (self.bagAP > 0) then
-        bankText = '|cFFFFFFFF' .. tostring(self.bagAP) .. '|r'
-      end
-      if self.bankAP and (self.bankAP > 0) then
-        bankText = (bankText and (bankText .. ' | ') or '') .. '|cFFFFFF00'..tostring(self.bankAP)..'|r'
+
+    if self.bagAP and (self.bagAP > 0) then
+      bankText = 'Inventory: |cFFFFFFFF' .. ShortNumberString(self.bagAP) .. '|r'
+    end
+    if self.bankAP and (self.bankAP > 0) then
+      bankText = (bankText and (bankText .. ' | ') or '') .. '|cFFFFFF00'..ShortNumberString(self.bankAP)..' banked|r'
+    end
+    if self.fishingAP and self.fishingAP > 0 then
+      bankText = (bankText and (bankText .. ' | ') or '') .. '|cFF0088FF' .. ShortNumberString(self.fishingAP) .. ' fishing|r'
+    end
+  end
+
+  self.worldQuestAP = 0
+  if WorldPlan then
+
+    if not self.worldPlanHooked then
+      WorldPlan:RegisterDataCallback(function()
+        self:Update()
+      end)
+    end
+
+
+    local showWQ
+    print('world plan is loaded')
+    local worldQuests = WorldPlan:GetQuestPins()
+    for index, pin in ipairs(worldQuests) do
+      if pin.dataLoaded and (pin.rewardType == WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER) then
+        showWQ = true
+        print(pin.itemNumber)
+        self.worldQuestAP = self.worldQuestAP + pin.itemNumber
       end
     end
-  end
-  if self.fishingAP and self.fishingAP > 0 then
-    bankText = (bankText and (bankText .. ' ') or '') .. '|cFF0088FF' .. tostring(self.fishingAP) .. ' fishing AP|r'
+
+    if showWQ then
+      bankText = (bankText and (bankText .. '\n') or '') .. '|cFFFFBB00World Quests:|r |cFFFFFFFF' .. ShortNumberString(self.worldQuestAP) .. ''
+    end
+
   end
 
   self.SummaryHeader:SetText(bankText)
 
   local numButtons = 0
-  local contentsHeight = 16 + self.SummaryHeader:GetHeight() + 64
-  local contentsWidth = 64
+  local contentsHeight = 16 + self.SummaryHeader:GetHeight()
+  local contentsWidth = self.SummaryHeader:GetWidth() + 16
   if self.profile.knowledgeMultiplier then
     numButtons = self:UpdateArtifactButtons()
 
-    contentsWidth = 64*numButtons + 4 * (numButtons+1)
+    if numButtons ~= 0 then
+      contentsHeight = contentsHeight + 64
+    end
+
+    contentsWidth = max(contentsWidth, 64*numButtons + 4 * (numButtons+1))
 
     local itemsWidth, itemsHeight = self:UpdateItemButtons()
     contentsHeight = contentsHeight + itemsHeight
@@ -412,6 +466,10 @@
   end
 
 
+  if not self.hasArtifacts then
+    self:SetShown(false)
+  end
+
 
   self:SetWidth(contentsWidth)
   self:SetHeight(contentsHeight)
@@ -422,6 +480,9 @@
 
   -- Artifact icons, in no particular order
   self.equippedID = C_ArtifactUI.GetEquippedArtifactInfo()
+  self.canAddAP = nil
+  self.canAddFishingAP = nil
+  local hasArtifacts
   local numButtons = 0
   local lastFrame = self
   local fishingID, fishingData
@@ -433,55 +494,83 @@
         fishingData = artifact
       end
 
+      if artifact.level < FISHING_MAX_TRAITS then
+        if itemID == self.equippedID then
+          self.canAddFishingAP = true
+        end
+      end
+
+
     else
-      if artifact.level ~= 54 then
+      if artifact.level < WEAPON_MAX_TRAITS then
+
+        if itemID == self.equippedID then
+          self.canAddAP = true
+        end
+        hasArtifacts = true
         numButtons = numButtons + 1
         button = self.Artifact[numButtons]
         button.relativeFrame = lastFrame
-        lastFrame = button:SetButton(itemID, artifact, numButtons, (self.equippedID == itemID))
+        lastFrame = button:SetButton(itemID, artifact, numButtons, (self.equippedID == itemID), nil)
       end
     end
+  end
 
-  end
 
   if fishingData and (self.fishingAP and self.fishingAP > 0) then
     numButtons = numButtons + 1
+    hasArtifacts = true
     local button = self.Artifact[numButtons]
     button.relativeFrame = lastFrame
+    button.isFishing = true
     button:SetButton(fishingID, fishingData, numButtons, self.equippedID == fishingID)
   end
 
+  self.hasArtifacts = hasArtifacts
   for i = numButtons+ 1, #self.Artifact do
     print('hide', i)
     self.Artifact[i]:Hide()
   end
 
+
   return numButtons
 end
 
 
 function ap:UpdateItemButtons()
   print('|cFF00FFFFUpdateItemButtons()|r')
+
+  local apType
+  if self.canAddFishingAP then
+    apType = true
+  elseif not self.canAddAP then
+    for index, button in ipairs(self.Tokens) do
+      button:Hide()
+    end
+    return 0, 0
+  end
+
+
   local lastFrame, upFrame
   local numButtons = 0
   local buttonsHeight = 0
   local buttonsWidth = 0
+
   for index, button in ipairs(self.Tokens) do
-    if button.numItems >= 1 then
+    if (button.numItems >= 1) and (button.isFishingAP == apType) then
       if button.itemName then
         self:SetItemAction(button)
       end
 
       button:ClearAllPoints()
       numButtons = numButtons + 1
+      local col = mod(numButtons,8)
       print(index, button:GetID(), button.Icon:GetTexture())
       if numButtons == 1 then
         button:SetPoint('TOPLEFT', self, 'TOPLEFT', 4, -76)
         upFrame = button
         buttonsHeight = 52
-        buttonsWidth = 50
       else
-        local col = mod(numButtons,8)
         if col == 1 then
           button:SetPoint('TOPLEFT', upFrame, 'BOTTOMLEFT', 0, -2)
           upFrame = button
@@ -491,14 +580,21 @@
           button:SetPoint('TOPLEFT', lastFrame, 'TOPRIGHT', 2, 0)
 
         end
-        buttonsWidth = max(buttonsWidth, col * 50)
       end
+
       button.Count:SetText(button.numItems)
       lastFrame = button
       button:Show()
     else
       button:Hide()
     end
+    buttonsWidth = min(numButtons, 8) * (BUTTON_SIZE)
+  end
+
+
+
+  if buttonsWidth ~= 0 then
+    buttonsWidth = buttonsWidth + 8+ ((min(numButtons, 8)-1)*2)
   end
 
 
@@ -517,7 +613,7 @@
   end
 end
 
-function ap:GetItemButton(itemID, texture, itemAP)
+function ap:GetItemButton(itemID, texture, itemAP, fishing)
   print('|cFF00FFFFGetItemButton()|r', itemID, texture, itemAP)
   local button = self.ItemButtons[itemID]
 
@@ -531,6 +627,7 @@
     button.numItems = 0
     button.Icon:SetTexture(texture)
     button:RegisterForClicks("AnyUp")
+    button.isFishingAP = fishing
     self:SetItemAction(button, GetItemInfo(itemID))
 
     print('  created')
@@ -553,36 +650,36 @@
 function ap:GetItemAP(itemID, itemLink, bagData)
   if not self.cache.items[itemID] then
 
-    print('doing tooltip scan')
+    print('doing tooltip scan', itemLink, itemID)
     self.tooltip:SetOwner(self, 'ANCHOR_NONE')
     self.tooltip:SetHyperlink(itemLink)
     self.tooltip:Show()
     local numLines = self.tooltip:NumLines()
     if numLines >= 3 then
-      local subText = _G[TOOLTIP_NAME .. 'TextLeft2']:GetText()
-      if subText and subText:match(ARTIFACT_POWER) then
         for i = 3, numLines do
           local text = _G[TOOLTIP_NAME .. 'TextLeft'.. i]:GetText()
-          if text and text:match(ARTIFACT_POWER) then
-            text = text:gsub('[,%D]', '')
-            print(itemLink, '-', tonumber(text))
-            local itemAP = tonumber(text)
-            if itemAP then
-              itemAP = itemAP
-              self.cache.items[itemID] = itemAP
+          if text then
+
+            text = text:lower():gsub(',', '')
+            if text:match('equipped artifact') then
+              print(itemLink, '-', tonumber(text))
+              local itemAP = text:match('%d+')
+              if itemAP then
+                itemAP = itemAP
+                self.cache.items[itemID] = tonumber(itemAP)
+              end
+            end
+            if text:match('fishing artifact') then
+              local fishingAP = text:match("%d+")
+              fishingAP = fishingAP
+              print(itemLink, 'fishing', tonumber(text))
+              if fishingAP then
+                self.cache.items[itemID] = tonumber(fishingAP)
+                self.cache.fishing[itemID] = true
+              end
             end
           end
         end
-      end
-      local fishingText = _G[TOOLTIP_NAME .. 'TextLeft3']:GetText()
-      if fishingText and fishingText:match('fishing artifact') then
-        local fishingAP = fishingText:match("%d+")
-        fishingAP = tonumber(fishingAP)
-        if fishingAP then
-          self.cache.items[itemID] = fishingAP
-          self.cache.fishing[itemID] = true
-        end
-      end
     else
 
       self.cache.items[itemID] = 0
@@ -655,10 +752,11 @@
   bagData.fishingAP = 0
   bagData.items = bagData.items or {}
   table.wipe(bagData.items)
+  local c = self.cache
 
-  self.cache.bagItems[id] = self.cache.bagItems[id] or {}
-  self.cache.bags[id] = self.cache.bags[id] or {}
-  self.cache.fishing[id] = self.cache.fishing[id] or {}
+  c.bagItems[id] = c.bagItems[id] or {}
+  c.bags[id] = c.bags[id] or {}
+  c.fishing[id] = c.fishing[id] or {}
 
   for slotID = 1, numSlots do
     local texture, count, locked, quality, readable, lootable, link = GetContainerItemInfo(id, slotID)
@@ -666,23 +764,24 @@
       local itemID = GetContainerItemID(id, slotID)
       local name, _, quality, iLevel, reqLevel, class, subclass = GetItemInfo(link)
 
-      if class == 'Consumable' and subclass == 'Other' then
+      if class == 'Consumable' or subclass == 'Cooking' then
         --print(GetItemInfo(link))
         local itemAP, isFishingAP
-        if self.cache.bags[id][slotID] and (self.cache.bagItems[id][slotID] == itemID) then
-          print('slot cache data', id, slotID)
-          itemAP = self.cache.bags[id][slotID]
+        if c.bags[id][slotID] and (c.bagItems[id][slotID] == itemID) then
+          --print('cached slot', id, slotID, name)
+          itemAP = c.bags[id][slotID]
+          isFishingAP = c.fishing[id] and c.fishing[id][slotID]
         else
           itemAP, isFishingAP = self:GetItemAP(itemID, link)
-          self.cache.bagItems[id][slotID] = itemID
-          self.cache.bags[id][slotID] = itemAP
-          self.cache.fishing[id][slotID] = isFishingAP
+          c.bagItems[id][slotID] = itemID
+          c.bags[id][slotID] = itemAP
+          c.fishing[id][slotID] = isFishingAP
         end
 
 
         --print(itemAP, isFishingAP)
         if itemAP and (itemAP > 0) then
-          local itemButton = self:GetItemButton(itemID, texture, itemAP)
+          local itemButton = self:GetItemButton(itemID, texture, itemAP, isFishingAP)
 
           if isFishingAP then
             bagData.fishingItems = (bagData.fishingItems or 0) + 1
@@ -695,9 +794,11 @@
           bagData.items[itemID] = (bagData.items[itemID] or 0) + 1
         end
       elseif self.profile.artifacts[itemID] then
-        print('artfiact weapon', itemID, link, id, slotID)
+        --print('artifact weapon', itemID, link, id, slotID)
         self.profile.artifacts[itemID].containerID = id
         self.profile.artifacts[itemID].slotID = slotID
+      else
+        --print('skipping', class, subclass, link)
       end
 
     end
@@ -744,7 +845,7 @@
 
   table.wipe(ItemCounts)
   for id, bagData in pairs(self.profile.bagslots) do
-    print(id, GetBagName(id), bagData.totalAP)
+    print(id, GetBagName(id), bagData.totalAP, bagData.fishingAP)
     id = tonumber(id)
     if bagData.totalAP then
       if (id == BANK_CONTAINER) or (id >= 5) then
@@ -765,7 +866,7 @@
 
 VeneerArtifactButtonMixin = {}
 
-function VeneerArtifactButtonMixin:SetButton(itemID, artifact, index, equipped)
+function VeneerArtifactButtonMixin:SetButton(itemID, artifact, index, equipped, fishing)
   print(itemID, index)
   print(artifact.name, artifact.texture, artifact.currentXP)
   self:SetID(itemID)
@@ -778,6 +879,7 @@
     self[k] = v
   end
 
+  self.isFishing = fishing
   -- this can change between artifact parses
   local potentialPoints = self.actualLevel
   local totalAP = (itemID ~= UNDERLIGHT_ANGLER_ID) and ((self:GetParent().bankAP or 0) + (self:GetParent().bagAP or 0)) or (self:GetParent().fishingAP or 0)
@@ -819,20 +921,21 @@
   local r, g, b = 1, 1, 1
   local lR, lG, lB = 1, 1, 0
   local levelText = self.level
-  local xpValue = self.currentXP
+  local xpValue = ShortNumberString(self.currentXP)
   local costValue = self.currentCost
   if self.actualLevel ~= self.level then
     levelText, r,g,b = self.actualLevel, 0,1,0
-    xpValue, costValue, lR, lG, lB = self.actualXP, self.actualCost, 0, 1, 0
+    xpValue, costValue, lR, lG, lB = ShortNumberString(self.potentialXP) .. '\n' .. ShortNumberString(self.potentialCost-self.potentialXP), self.actualCost, 0, 1, 0
   elseif self.potentialLevel ~= self.level then
     levelText, r, g, b = self.potentialLevel, 0,1,1
-    xpValue, costValue, lR, lG, lB = self.potentialAdjustedXP, self.potentialCost, 0,1,0
-
+    xpValue, costValue, lR, lG, lB = ShortNumberString(self.potentialXP) .. '\n' .. ShortNumberString(self.potentialCost-self.potentialXP), self.potentialCost, 0,1,1
+  else
+    xpValue, lR, lG, lB = ShortNumberString(self.actualXP) .. '\n|cFFFFFF00' .. ShortNumberString(self.actualCost-self.actualXP)..'|r', 1, 1, 1
   end
 
   self.Level:SetText(levelText)
   self.Level:SetTextColor(r, g, b)
-  self.CurrentXP:SetText(ShortNumberString( xpValue))
+  self.CurrentXP:SetText( xpValue)
   self.CurrentXP:SetTextColor(lR, lG, lB)
 
   if self.isEquipped then
--- a/Modules/ArtifactPower.xml	Mon Mar 06 02:31:15 2017 -0500
+++ b/Modules/ArtifactPower.xml	Tue Mar 21 16:33:51 2017 -0400
@@ -110,7 +110,7 @@
         </Texture>
       </Layer>
       <Layer level="OVERLAY">
-        <FontString name="$parentSummaryHeader" parentKey="SummaryHeader" inherits="VeneerNumberFont" text="">
+        <FontString name="$parentSummaryHeader" parentKey="SummaryHeader" inherits="VeneerNumberFont" text="" justifyH="LEFT">
           <Anchors>
             <Anchor point="BOTTOMLEFT" x="4" y="4"  />
           </Anchors>
@@ -124,6 +124,23 @@
       <Button name="$parentArtifactButton3" inherits="VeneerArtifactButton" />
       <Button name="$parentArtifactButton4" inherits="VeneerArtifactButton" />
       <Button name="$parentArtifactButton5" inherits="VeneerArtifactButton" />
+
+      <Button name="$parentRefresh" text="Refresh" parentKey="Refresh">
+        <Size x="72" y="32" />
+        <Anchors>
+          <Anchor point="TOPRIGHT" relativePoint="BOTTOMRIGHT" x="0" y="0" />
+        </Anchors>
+        <Scripts>
+          <OnClick>
+            self:GetParent():ResetCache()
+          </OnClick>
+        </Scripts>
+
+        <NormalTexture>
+          <Color a="1" r="0" g="0" b="0" />
+        </NormalTexture>
+        <NormalFont style="GameFontNormal" />
+      </Button>
     </Frames>
   </Frame>
 </Ui>
--- a/Modules/TalkingHead.lua	Mon Mar 06 02:31:15 2017 -0500
+++ b/Modules/TalkingHead.lua	Tue Mar 21 16:33:51 2017 -0400
@@ -4,7 +4,6 @@
 -- %file-revision%
 --
 
-
 local print = DEVIAN_WORKSPACE and function(...) print('VnTalkingHead', ...) end or nop
 
 VeneerTalkingHeadMixin = {
--- a/Modules/WorldState.lua	Mon Mar 06 02:31:15 2017 -0500
+++ b/Modules/WorldState.lua	Tue Mar 21 16:33:51 2017 -0400
@@ -96,13 +96,19 @@
 
 function VeneerWorldStateMixin:Update(isBatchUpdate)
   print('|cFFFFFF00All:Update()|r')
+  local canShow = false
   for index, frame in ipairs(self.modules) do
     if frame.Update then
       print('  '..index..' |cFFFF00FFUpdate:|r '.. frame:GetName())
       frame:Update(isBatchUpdate)
       print('    ', frame:IsVisible(), frame:IsShown())
+      if frame:IsShown() then
+        canShow = true
+      end
+
     end
   end
+  self:SetShown(canShow)
 end
 
 function VeneerWorldStateMixin:OnShow()
@@ -230,18 +236,20 @@
 }
 function VeneerWorldStateCurrencyMixin:Update(isBatchUpdate)
   local zoneText = GetRealZoneText()
+  local canShow = false
   if zoneText then
     local currency = zoneCurrency[zoneText]
     if currency then
       local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(zoneCurrency[zoneText])
       self.Icon:SetTexture(texture)
       self.Label:SetFormattedText("%d / %d", earned, totalMax)
-      self:Show()
       self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6)
+      canShow = true
     end
   else
-    self:Hide()
   end
+  self:SetShown(canShow)
+  VeneerWorldState:Reanchor(true)
 end
 
 function VeneerWorldStateProgressMixin:OnUpdate(sinceLast)