diff Modules/Currency.lua @ 128:799ec6dce9c3

- use BagBrother for inventory items, fixes bank stuff not being counted
author Nenue
date Thu, 19 Oct 2017 10:39:04 -0400
parents 3de635cda288
children 15a7f27b11e6
line wrap: on
line diff
--- a/Modules/Currency.lua	Tue Oct 17 17:24:27 2017 -0400
+++ b/Modules/Currency.lua	Thu Oct 19 10:39:04 2017 -0400
@@ -38,13 +38,13 @@
   ["Legionfall War Supplies"] = {
     currencyID = 1342,
     zones = {
-      ["The Broken Shore"] = true
+      ["Broken Shore"] = true
     }
   },
   ["Nethershard"] = {
     currencyID = 1226,
     zones = {
-      ["The Broken Shore"] = true
+      ["Broken Shore"] = true
     }
   },
   ["Veiled Argunite"] = {
@@ -81,7 +81,7 @@
 end
 
 function module:Setup()
-  self:Update()
+  self:Reanchor()
 end
 
 function module:OnLoad ()
@@ -108,25 +108,25 @@
         frame = block
       }
       block.Update = itemBlock.Update
-      RegisterEvents(self, itemEvents)
+      RegisterEvents(block, itemEvents)
     elseif info.currencyID then
       local currencyID = info.currencyID
       block.Update = currencyBlock.Update
-      RegisterEvents(block, currencyEvents)
+      RegisterEvents(self, currencyEvents)
     end
 
 
 
     if info.zones then
-      RegisterEvents(block, zoneEvents)
+      RegisterEvents(self, zoneEvents)
       local zones = info.zones
       local of = block.Update
-      function block:Update(zone, subZone)
+      function block:Update()
 
         local zone = GetRealZoneText()
         local subZone = GetSubZoneText()
-        block.debug('Zone Check', zone, subZone)
         local canShow = ((zone and self.zones[zone]) or (subZone and self.zones[subZone])) and true or false
+        block.debug('Zone Check', zone, subZone, canShow)
         if of then
           canShow = canShow and of(self)
         end
@@ -138,10 +138,11 @@
 
 function module:OnEvent (event, arg)
   print(self:GetName(), 'OnEvent', event, arg)
+  self:Update()
 end
 
-function module:Update(isBatchUpdate)
-  print(self:GetName(), 'Update()')
+function module:Update()
+  print(self:GetName(), 'Reanchor()')
   if InCombatLockdown() then
     self:SetShown(false)
     return
@@ -154,17 +155,47 @@
 
   local canShow = false
 
-  for i = 0, NUM_BAG_SLOTS do
-    local numSlots = GetContainerNumSlots(i)
-    for j = 1, numSlots do
-      local itemID = GetContainerItemID(i, j)
-      local texture, count = GetContainerItemInfo(i,j)
-      if items[itemID] then
-        items[itemID].count = items[itemID].count + (count or 1)
-        if not items[itemID].texture then
-          items[itemID].texture = texture
-          print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
-          items[itemID].frame.Icon:SetTexture(texture)
+  if BagBrother then
+    for i, bag in pairs(BagBrother.Player) do
+      if type(bag) == 'table' then
+        --print(i)
+        for j, item in pairs(bag) do
+          local itemID, count = string.match(item ,"^(%d+):.+;(%d*)")
+          itemID = tonumber(itemID)
+                if itemID then
+                  --print(j, itemID)
+            count = tonumber(count)
+            if count and count >= 1 then
+              local texture = GetItemIcon(itemID)
+              --print(itemID)
+
+              if items[itemID] then
+                items[itemID].count = items[itemID].count + (count or 1)
+                if not items[itemID].texture then
+                  items[itemID].texture = texture
+                  --print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
+                  items[itemID].frame.Icon:SetTexture(texture)
+                end
+              end
+            end
+          end
+        end
+      end
+
+    end
+  else
+    for i = 0, NUM_BAG_SLOTS do
+      local numSlots = GetContainerNumSlots(i)
+      for j = 1, numSlots do
+        local itemID = GetContainerItemID(i, j)
+        local texture, count = GetContainerItemInfo(i,j)
+        if items[itemID] then
+          items[itemID].count = items[itemID].count + (count or 1)
+          if not items[itemID].texture then
+            items[itemID].texture = texture
+            print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
+            items[itemID].frame.Icon:SetTexture(texture)
+          end
         end
       end
     end
@@ -175,7 +206,8 @@
   local lastBlock
   local totalWidth = 0
   for _, block in ipairs(self.Blocks) do
-    local blockIsShown = block:Update(self.realZoneText, self.subZoneText) or false
+    local blockIsShown = block:Update()
+    print(block.name, blockIsShown)
     block:SetShown(blockIsShown)
     canShow = canShow or blockIsShown