diff Modules/Currency.lua @ 125:3f4794dca91b

template load order and Script handlers linkage
author Nenue
date Sun, 15 Oct 2017 16:47:22 -0400
parents b3c0258b419d
children 3de635cda288
line wrap: on
line diff
--- a/Modules/Currency.lua	Tue Sep 05 02:57:08 2017 -0400
+++ b/Modules/Currency.lua	Sun Oct 15 16:47:22 2017 -0400
@@ -6,7 +6,7 @@
 -- To change this template use File | Settings | File Templates.
 --
 
-local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop
+local print = DEVIAN_WORKSPACE and function(...) print('Currency', ...) end or nop
 local profileUpdate, needsUpdate
 
 
@@ -30,11 +30,6 @@
     showMax = true,
     zones = {
       ['Suramar'] = true,
-      ["Sashj'tar Ruins"] = true,
-      ["Faronaar Ruins"] = true,
-      ["Halls of the Eclipse"] = true,
-      ["Shal'aran"] = true,
-      ["The Fel Breach"] = true,
     },
   },
   ["Blood of Sargeras"] = {
@@ -42,16 +37,24 @@
   },
   ["Legionfall War Supplies"] = {
     currencyID = 1342,
+    zones = {
+      ["The Broken Shore"] = true
+    }
   },
   ["Nethershard"] = {
     currencyID = 1226,
+    zones = {
+      ["The Broken Shore"] = true
+    }
   },
   ["Veiled Argunite"] = {
     currencyID = 1508,
+    zones = {
+      ["Antoran Wastes"] = true,
+      ["Krokuun"] = true,
+      ["MacAree"] = true,
+    }
   },
-  ["Argus Waystone"] = {
-    currencyID = 1506,
-  }
 }
 local items, currencies = {}, {}
 
@@ -77,49 +80,52 @@
   end
 end
 
+function module:Setup()
+  self:Update()
+end
+
 function module:OnLoad ()
   Veneer:AddHandler(self)
 
   for name, info in pairs(blocks) do
-    local frame = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate')
-    frame.name = name
+    local block = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate')
+    block.name = name
     for k,v in pairs(info) do
       print(name, k, '=', v)
-      frame[k] = v
+      block[k] = v
     end
 
-    frame.debug = function(...)
-      print('|cFF0088FF<'..frame.name..'>|r', ...)
+    block.debug = function(...)
+      print('|cFF0088FF<'..block.name..'>|r', ...)
     end
-    frame.id = info.itemID or info.currencyID
+    block.id = info.itemID or info.currencyID
 
 
     if info.itemID then
       local itemID = info.itemID
       items[itemID] = {
         count = 0,
-        frame = frame
+        frame = block
       }
-      frame.Update = itemBlock.Update
+      block.Update = itemBlock.Update
       RegisterEvents(self, itemEvents)
     elseif info.currencyID then
       local currencyID = info.currencyID
-      frame.Update = currencyBlock.Update
-      RegisterEvents(frame, currencyEvents)
+      block.Update = currencyBlock.Update
+      RegisterEvents(block, currencyEvents)
     end
 
 
 
     if info.zones then
-      RegisterEvents(frame, zoneEvents)
+      RegisterEvents(block, zoneEvents)
       local zones = info.zones
-      local of = frame.Update
-      frame.Update = function(block)
-        frame.debug('Update [Zone]')
-        local zone = self.zoneText
-        local canShow = (zone and block.zones[zone]) and true or false
+      local of = block.Update
+      function block:Update(zone, subZone)
+        block.debug('Update [Zone]', zone, subZone)
+        local canShow = ((zone and self.zones[zone]) or (subZone and self.zones[subZone])) and true or false
         if of then
-          canShow = canShow and of(frame)
+          canShow = canShow and of(self)
         end
         return canShow
       end
@@ -144,7 +150,8 @@
   for itemID in pairs(items) do
     items[itemID].count = 0
   end
-  self.zoneText = GetRealZoneText()
+  self.realZoneText = GetRealZoneText()
+  self.subZoneText = GetSubZoneText()
   local canShow = false
 
   for i = 0, NUM_BAG_SLOTS do
@@ -168,12 +175,12 @@
   local lastBlock
   local totalWidth = 0
   for _, block in ipairs(self.Blocks) do
-    local blockIsShown = block:Update() or false
+    local blockIsShown = block:Update(self.realZoneText, self.subZoneText) or false
     block:SetShown(blockIsShown)
     canShow = canShow or blockIsShown
 
 
-    if block:IsShown() then
+    if blockIsShown then
       block:ClearAllPoints()
       if lastBlock then
         block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT')
@@ -212,7 +219,7 @@
 
 function module:OnUpdate()
   if needsUpdate then
-    self:Update()
+    self:Update(GetRealZoneText(), GetSubZoneText())
   elseif profileUpdate then
     self:UpdateProfile()
   end
@@ -238,23 +245,25 @@
 
 function block:OnEvent(event, ...)
   print('|cFF0088FF<'..self.name..'>|r', 'OnEvent', event, ...)
-  self:Update()
+
+  self:Update(GetRealZoneText(), GetSubZoneText())
 end
 
 function block:Setup()
 
 end
-function itemBlock:Update()
-  self.debug('Update [Item]')
+function itemBlock:Update(zone, subZone)
+  self.debug('Update [Item]', zone, subZone)
   if items[self.itemID].count >= 1 then
     self.Icon:SetTexture(GetItemIcon(self.id))
     self.Label:SetFormattedText("%d", items[self.id].count)
     return true
   end
+  return false
 end
 
-function currencyBlock:Update()
-  self.debug('Update [Currency]')
+function currencyBlock:Update(zone, subZone)
+  self.debug('Update [Currency]', zone, subZone)
   local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(self.id)
 
   self.Icon:SetTexture(texture)