annotate Modules/Currency.lua @ 113:2105b6e5095f

- Added Blood of Sargeras to currency list - Fixed panel ordering issues when a module is loaded on the fly.
author Nick@Zahhak
date Sun, 26 Mar 2017 06:25:18 -0400
parents
children 6748c98a6c6c
rev   line source
Nick@113 1 --
Nick@113 2 -- Created by IntelliJ IDEA.
Nick@113 3 -- User: Nick
Nick@113 4 -- Date: 3/25/2017
Nick@113 5 -- Time: 7:07 PM
Nick@113 6 -- To change this template use File | Settings | File Templates.
Nick@113 7 --
Nick@113 8
Nick@113 9 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop
Nick@113 10
Nick@113 11 local zoneEvents = {
Nick@113 12 "ZONE_CHANGED_NEW_AREA", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED"
Nick@113 13 }
Nick@113 14 local currencyEvents = {
Nick@113 15 'CURRENCY_DISPLAY_UPDATE', 'CHAT_MSG_CURRENCY'
Nick@113 16 }
Nick@113 17 local itemEvents = {
Nick@113 18 'CHAT_MSG_LOOT', 'BAG_UPDATE'
Nick@113 19 }
Nick@113 20
Nick@113 21 local blocks = {
Nick@113 22 ["Ancient Mana"] = {
Nick@113 23 currencyID = 1155,
Nick@113 24 zones = {
Nick@113 25 ['Suramar'] = true,
Nick@113 26 ["Sashj'tar Ruins"] = true,
Nick@113 27 ["Faronaar Ruins"] = true
Nick@113 28 }
Nick@113 29 },
Nick@113 30 ["Blood of Sargeras"] = {
Nick@113 31 itemID = 124124,
Nick@113 32 }
Nick@113 33 }
Nick@113 34 local items = {}
Nick@113 35
Nick@113 36
Nick@113 37 VeneerWorldStateCurrencyMixin = { Blocks = {} }
Nick@113 38 VeneerWorldStateCurrencyBlockMixin = {}
Nick@113 39 local module = VeneerWorldStateCurrencyMixin
Nick@113 40 local block = VeneerWorldStateCurrencyBlockMixin
Nick@113 41
Nick@113 42
Nick@113 43
Nick@113 44 local function RegisterEvents (frame, events)
Nick@113 45 for _, event in ipairs(events) do
Nick@113 46 print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event)
Nick@113 47 frame:RegisterEvent(event)
Nick@113 48 end
Nick@113 49 end
Nick@113 50
Nick@113 51 function module:OnLoad ()
Nick@113 52 self:RegisterEvent("PLAYER_ENTERING_WORLD");
Nick@113 53 self:RegisterEvent('PLAYER_REGEN_ENABLED')
Nick@113 54 self:RegisterEvent('PLAYER_REGEN_DISABLED')
Nick@113 55
Nick@113 56 for name, info in pairs(blocks) do
Nick@113 57 local frame = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate')
Nick@113 58 frame.name = name
Nick@113 59 for k,v in pairs(info) do
Nick@113 60 print(name, k, '=', v)
Nick@113 61 frame[k] = v
Nick@113 62 end
Nick@113 63
Nick@113 64 local debug = function(...)
Nick@113 65 print('|cFF0088FF<'..frame.name..'>|r', ...)
Nick@113 66 end
Nick@113 67
Nick@113 68 if info.itemID then
Nick@113 69 local itemID = info.itemID
Nick@113 70 items[itemID] = {
Nick@113 71 count = 0,
Nick@113 72 frame = frame
Nick@113 73 }
Nick@113 74 frame.Update = function(block)
Nick@113 75 debug('Update [Item]')
Nick@113 76 if items[itemID].count >= 1 then
Nick@113 77 block.Icon:SetTexture(GetItemIcon(itemID))
Nick@113 78 block.Label:SetFormattedText("%d", items[itemID].count)
Nick@113 79 return true
Nick@113 80 end
Nick@113 81 end
Nick@113 82 RegisterEvents(self, itemEvents)
Nick@113 83 elseif info.currencyID then
Nick@113 84 local currencyID = info.currencyID
Nick@113 85 frame.Update = function (block)
Nick@113 86 debug('Update [Currency]')
Nick@113 87 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(currencyID)
Nick@113 88 block.Icon:SetTexture(texture)
Nick@113 89 block.Label:SetFormattedText("%d / %d", earned, totalMax)
Nick@113 90 block:SetWidth(block.Icon:GetWidth() + block.Label:GetStringWidth() + 6)
Nick@113 91 return true
Nick@113 92 end
Nick@113 93
Nick@113 94 RegisterEvents(frame, currencyEvents)
Nick@113 95 end
Nick@113 96 if info.zones then
Nick@113 97 RegisterEvents(frame, zoneEvents)
Nick@113 98 local zones = info.zones
Nick@113 99 local of = frame.Update
Nick@113 100 frame.Update = function(block)
Nick@113 101 debug('Update [Zone]')
Nick@113 102 local zone = self.zoneText
Nick@113 103 local canShow = (zone and block.zones[zone]) and true or false
Nick@113 104 if of then
Nick@113 105 canShow = canShow and of(frame)
Nick@113 106 end
Nick@113 107 return canShow
Nick@113 108 end
Nick@113 109 end
Nick@113 110 end
Nick@113 111 end
Nick@113 112
Nick@113 113 function module:OnEvent (event, arg)
Nick@113 114 print(self:GetName(), 'OnEvent', event, arg)
Nick@113 115 self:Update()
Nick@113 116 end
Nick@113 117 local toUpdate = {}
Nick@113 118 local wipe = table.wipe
Nick@113 119 function module:Update(isBatchUpdate)
Nick@113 120 print(self:GetName(), 'Update()')
Nick@113 121 if InCombatLockdown() then
Nick@113 122 self:SetShown(false)
Nick@113 123 return
Nick@113 124 end
Nick@113 125
Nick@113 126
Nick@113 127 for itemID in pairs(items) do
Nick@113 128 items[itemID].count = 0
Nick@113 129 end
Nick@113 130 self.zoneText = GetRealZoneText()
Nick@113 131 local canShow = false
Nick@113 132
Nick@113 133 for i = 0, NUM_BAG_SLOTS do
Nick@113 134 local numSlots = GetContainerNumSlots(i)
Nick@113 135 for j = 1, numSlots do
Nick@113 136 local itemID = GetContainerItemID(i, j)
Nick@113 137 local texture, count = GetContainerItemInfo(i,j)
Nick@113 138 if items[itemID] then
Nick@113 139 items[itemID].count = items[itemID].count + (count or 1)
Nick@113 140 items[itemID].texture = texture
Nick@113 141 print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
Nick@113 142 items[itemID].frame.Icon:SetTexture(texture)
Nick@113 143 end
Nick@113 144 end
Nick@113 145 end
Nick@113 146
Nick@113 147 for itemID, info in pairs(items) do
Nick@113 148 end
Nick@113 149
Nick@113 150 local lastBlock
Nick@113 151 local totalWidth = 0
Nick@113 152 for _, block in ipairs(self.Blocks) do
Nick@113 153 local blockIsShown = block:Update() or false
Nick@113 154 block:SetShown(blockIsShown)
Nick@113 155 canShow = canShow or blockIsShown
Nick@113 156
Nick@113 157
Nick@113 158 if block:IsShown() then
Nick@113 159 block:ClearAllPoints()
Nick@113 160 if lastBlock then
Nick@113 161 block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT')
Nick@113 162 else
Nick@113 163 block:SetPoint('TOPLEFT', self, 'TOPLEFT')
Nick@113 164 end
Nick@113 165 lastBlock = block
Nick@113 166
Nick@113 167 block:SetHeight(24)
Nick@113 168 block:SetWidth(block.Icon:GetWidth() + block.Label:GetWidth()+4)
Nick@113 169 totalWidth = totalWidth + block:GetWidth()
Nick@113 170 end
Nick@113 171 print(block:IsShown(), '|cFF0088FF'..block.name..'|r', block:GetSize())
Nick@113 172
Nick@113 173 end
Nick@113 174
Nick@113 175 self:SetWidth(totalWidth)
Nick@113 176
Nick@113 177 self.needsUpdate = nil
Nick@113 178 print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize())
Nick@113 179 self:SetShown(canShow)
Nick@113 180 VeneerWorldState:Reanchor(true)
Nick@113 181 end
Nick@113 182
Nick@113 183 function module:OnUpdate()
Nick@113 184 if self.needsUpdate then
Nick@113 185 self:Update()
Nick@113 186 end
Nick@113 187 end
Nick@113 188
Nick@113 189 function block:OnEvent(event, ...)
Nick@113 190 print('|cFF0088FF<'..self.name..'>|r', 'OnEvent', event, ...)
Nick@113 191 self:Update()
Nick@113 192 end
Nick@113 193
Nick@113 194 function block:Setup()
Nick@113 195
Nick@113 196 end