annotate Modules/Currency.lua @ 133:86621c60512b v7.3.2-20171222

- Fixed AP calc tooltip appearing while hidden - Fixed PaperDoll relic tooltips missing nether crucible info
author Nenue
date Fri, 22 Dec 2017 20:36:40 -0500
parents 15a7f27b11e6
children 414e37af1b1b
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
Nenue@125 9 local print = DEVIAN_WORKSPACE and function(...) print('Currency', ...) end or nop
Nenue@115 10 local profileUpdate, needsUpdate
Nick@113 11
Nenue@123 12
Nenue@123 13 local itemBlock = {}
Nenue@123 14 local currencyBlock = {}
Nenue@123 15
Nenue@123 16
Nenue@133 17 local events = {
Nenue@133 18 'CHAT_MSG_LOOT',
Nenue@133 19 "ZONE_CHANGED_NEW_AREA", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED",
Nenue@133 20 'BAG_UPDATE', 'CURRENCY_DISPLAY_UPDATE', 'CHAT_MSG_CURRENCY',
Nick@113 21 }
Nick@113 22
Nick@113 23 local blocks = {
Nick@113 24 ["Ancient Mana"] = {
Nick@113 25 currencyID = 1155,
Nenue@116 26 showMax = true,
Nick@113 27 zones = {
Nick@113 28 ['Suramar'] = true,
Nenue@116 29 },
Nick@113 30 },
Nick@113 31 ["Blood of Sargeras"] = {
Nick@113 32 itemID = 124124,
Nenue@116 33 },
Nenue@116 34 ["Legionfall War Supplies"] = {
Nenue@116 35 currencyID = 1342,
Nenue@125 36 zones = {
Nenue@128 37 ["Broken Shore"] = true
Nenue@125 38 }
Nenue@116 39 },
Nenue@116 40 ["Nethershard"] = {
Nenue@116 41 currencyID = 1226,
Nenue@125 42 zones = {
Nenue@128 43 ["Broken Shore"] = true
Nenue@125 44 }
Nenue@123 45 },
Nenue@123 46 ["Veiled Argunite"] = {
Nenue@123 47 currencyID = 1508,
Nenue@125 48 zones = {
Nenue@125 49 ["Antoran Wastes"] = true,
Nenue@125 50 ["Krokuun"] = true,
Nenue@125 51 ["MacAree"] = true,
Nenue@125 52 }
Nenue@123 53 },
Nick@113 54 }
Nenue@115 55 local items, currencies = {}, {}
Nick@113 56
Nick@113 57
Nenue@115 58 VeneerCurrencyMixin = {
Nenue@115 59 Blocks = {},
Nenue@115 60 HideCombat = true,
Nenue@115 61 EventList = {'PLAYER_ENTERING_WORLD'},
Nenue@115 62 moduleName = 'Currency Watch',
Nenue@115 63 anchorPoint = 'TOP',
Nenue@116 64 anchorPriority = 2,
Nenue@115 65 }
Nenue@115 66 VeneerCurrencyBlockMixin = {}
Nenue@115 67 local module = VeneerCurrencyMixin
Nenue@115 68 local block = VeneerCurrencyBlockMixin
Nick@113 69
Nick@113 70
Nick@113 71
Nick@113 72 local function RegisterEvents (frame, events)
Nick@113 73 for _, event in ipairs(events) do
Nick@113 74 print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event)
Nick@113 75 frame:RegisterEvent(event)
Nick@113 76 end
Nick@113 77 end
Nick@113 78
Nenue@125 79 function module:Setup()
Nenue@128 80 self:Reanchor()
Nenue@125 81 end
Nenue@125 82
Nick@113 83 function module:OnLoad ()
Nenue@115 84 Veneer:AddHandler(self)
Nick@113 85
Nenue@133 86 for _, event in ipairs(events) do
Nenue@133 87 self:RegisterEvent(event)
Nenue@133 88 end
Nenue@133 89
Nenue@133 90
Nick@113 91 for name, info in pairs(blocks) do
Nenue@125 92 local block = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate')
Nenue@125 93 block.name = name
Nick@113 94 for k,v in pairs(info) do
Nick@113 95 print(name, k, '=', v)
Nenue@125 96 block[k] = v
Nick@113 97 end
Nick@113 98
Nenue@125 99 block.debug = function(...)
Nenue@125 100 print('|cFF0088FF<'..block.name..'>|r', ...)
Nick@113 101 end
Nenue@125 102 block.id = info.itemID or info.currencyID
Nenue@123 103
Nenue@133 104 block:SetScript('OnEnter', itemBlock.OnEnter or block.OnEnter)
Nenue@133 105 block:SetScript('OnLeave', itemBlock.OnLeave or block.OnLeave)
Nick@113 106
Nick@113 107 if info.itemID then
Nick@113 108 local itemID = info.itemID
Nick@113 109 items[itemID] = {
Nick@113 110 count = 0,
Nenue@125 111 frame = block
Nick@113 112 }
Nenue@125 113 block.Update = itemBlock.Update
Nick@113 114 elseif info.currencyID then
Nick@113 115 local currencyID = info.currencyID
Nenue@125 116 block.Update = currencyBlock.Update
Nick@113 117 end
Nenue@123 118
Nenue@123 119
Nenue@123 120
Nick@113 121 if info.zones then
Nick@113 122 local zones = info.zones
Nenue@125 123 local of = block.Update
Nenue@128 124 function block:Update()
Nenue@126 125
Nenue@126 126 local zone = GetRealZoneText()
Nenue@126 127 local subZone = GetSubZoneText()
Nenue@125 128 local canShow = ((zone and self.zones[zone]) or (subZone and self.zones[subZone])) and true or false
Nenue@128 129 block.debug('Zone Check', zone, subZone, canShow)
Nick@113 130 if of then
Nenue@125 131 canShow = canShow and of(self)
Nick@113 132 end
Nick@113 133 return canShow
Nick@113 134 end
Nick@113 135 end
Nick@113 136 end
Nenue@131 137
Nenue@131 138 self:RegisterEvent('PLAYER_REGEN_ENABLED')
Nenue@131 139 self:RegisterEvent('PLAYER_REGEN_DISABLED')
Nick@113 140 end
Nick@113 141
Nick@113 142 function module:OnEvent (event, arg)
Nenue@131 143 --print(self:GetName(), 'OnEvent', event, arg)
Nenue@128 144 self:Update()
Nick@113 145 end
Nenue@126 146
Nenue@128 147 function module:Update()
Nenue@131 148 --print(self:GetName(), 'Reanchor()')
Nick@113 149 if InCombatLockdown() then
Nick@113 150 self:SetShown(false)
Nick@113 151 return
Nick@113 152 end
Nick@113 153
Nick@113 154
Nick@113 155 for itemID in pairs(items) do
Nick@113 156 items[itemID].count = 0
Nick@113 157 end
Nenue@126 158
Nick@113 159 local canShow = false
Nenue@128 160 if BagBrother then
Nenue@128 161 for i, bag in pairs(BagBrother.Player) do
Nenue@128 162 if type(bag) == 'table' then
Nenue@128 163 --print(i)
Nenue@128 164 for j, item in pairs(bag) do
Nenue@128 165 local itemID, count = string.match(item ,"^(%d+):.+;(%d*)")
Nenue@128 166 itemID = tonumber(itemID)
Nenue@128 167 if itemID then
Nenue@128 168 --print(j, itemID)
Nenue@128 169 count = tonumber(count)
Nenue@128 170 if count and count >= 1 then
Nenue@128 171 local texture = GetItemIcon(itemID)
Nenue@128 172 --print(itemID)
Nenue@128 173
Nenue@128 174 if items[itemID] then
Nenue@128 175 items[itemID].count = items[itemID].count + (count or 1)
Nenue@128 176 if not items[itemID].texture then
Nenue@128 177 items[itemID].texture = texture
Nenue@128 178 --print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
Nenue@128 179 items[itemID].frame.Icon:SetTexture(texture)
Nenue@128 180 end
Nenue@128 181 end
Nenue@128 182 end
Nenue@128 183 end
Nenue@128 184 end
Nenue@128 185 end
Nenue@128 186
Nenue@128 187 end
Nenue@128 188 else
Nenue@128 189 for i = 0, NUM_BAG_SLOTS do
Nenue@128 190 local numSlots = GetContainerNumSlots(i)
Nenue@128 191 for j = 1, numSlots do
Nenue@128 192 local itemID = GetContainerItemID(i, j)
Nenue@128 193 local texture, count = GetContainerItemInfo(i,j)
Nenue@128 194 if items[itemID] then
Nenue@133 195
Nenue@128 196 items[itemID].count = items[itemID].count + (count or 1)
Nenue@128 197 if not items[itemID].texture then
Nenue@128 198 items[itemID].texture = texture
Nenue@128 199 print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
Nenue@128 200 items[itemID].frame.Icon:SetTexture(texture)
Nenue@128 201 end
Nenue@115 202 end
Nick@113 203 end
Nick@113 204 end
Nick@113 205 end
Nick@113 206
Nenue@115 207
Nick@113 208
Nick@113 209 local lastBlock
Nick@113 210 local totalWidth = 0
Nick@113 211 for _, block in ipairs(self.Blocks) do
Nenue@128 212 local blockIsShown = block:Update()
Nenue@128 213 print(block.name, blockIsShown)
Nick@113 214 block:SetShown(blockIsShown)
Nick@113 215 canShow = canShow or blockIsShown
Nick@113 216
Nick@113 217
Nenue@125 218 if blockIsShown then
Nick@113 219 block:ClearAllPoints()
Nick@113 220 if lastBlock then
Nick@113 221 block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT')
Nick@113 222 else
Nick@113 223 block:SetPoint('TOPLEFT', self, 'TOPLEFT')
Nick@113 224 end
Nick@113 225 lastBlock = block
Nick@113 226
Nick@113 227 block:SetHeight(24)
Nenue@123 228 block:SetWidth(block.Icon:GetWidth() + block.Label:GetStringWidth()+4)
Nick@113 229 totalWidth = totalWidth + block:GetWidth()
Nick@113 230 end
Nenue@126 231 print('|cFF0088FF'..block.name..'|r', block:IsShown(), block:GetSize())
Nick@113 232 end
Nick@113 233
Nenue@115 234 self:UpdateProfile()
Nick@113 235 self:SetWidth(totalWidth)
Nick@113 236
Nenue@115 237 needsUpdate = nil
Nick@113 238 print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize())
Nick@113 239 self:SetShown(canShow)
Nenue@115 240 Veneer:DynamicReanchor()
Nenue@115 241 end
Nenue@115 242
Nenue@115 243 function module:UpdateProfile()
Nenue@115 244 if not self.profile then
Nenue@115 245 profileUpdate = true
Nenue@115 246 return
Nenue@115 247 end
Nenue@115 248
Nenue@115 249 for itemID, info in pairs(items) do
Nenue@115 250 self.profile.Items = self.profile.Items or {}
Nenue@115 251 self.profile.Items[itemID] = info
Nenue@115 252 end
Nick@113 253 end
Nick@113 254
Nick@113 255 function module:OnUpdate()
Nenue@115 256 if needsUpdate then
Nenue@125 257 self:Update(GetRealZoneText(), GetSubZoneText())
Nenue@115 258 elseif profileUpdate then
Nenue@115 259 self:UpdateProfile()
Nick@113 260 end
Nenue@115 261
Nick@113 262 end
Nick@113 263
Nick@114 264 function block:OnEnter()
Nick@114 265 if not InCombatLockdown() then
Nick@114 266 GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT");
Nick@114 267 if self.currencyID then
Nick@114 268 GameTooltip:SetCurrencyTokenByID(self.currencyID);
Nick@114 269 else
Nick@114 270 GameTooltip:SetItemByID(self.itemID);
Nick@114 271 end
Nick@114 272 GameTooltip:Show();
Nick@114 273 end
Nick@114 274 end
Nick@114 275 function block:OnLeave()
Nick@114 276 if GameTooltip:IsOwned(self) then
Nick@114 277 GameTooltip_Hide()
Nick@114 278 end
Nick@114 279 end
Nick@114 280
Nick@113 281
Nenue@126 282 function itemBlock:Update()
Nenue@123 283 if items[self.itemID].count >= 1 then
Nenue@123 284 self.Icon:SetTexture(GetItemIcon(self.id))
Nenue@123 285 self.Label:SetFormattedText("%d", items[self.id].count)
Nenue@123 286 return true
Nenue@123 287 end
Nenue@125 288 return false
Nenue@123 289 end
Nenue@123 290
Nenue@126 291 function currencyBlock:Update()
Nenue@123 292 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(self.id)
Nenue@123 293
Nenue@123 294 self.Icon:SetTexture(texture)
Nenue@123 295 if self.showMax then
Nenue@123 296 self.Label:SetFormattedText("%d / %d", earned, totalMax)
Nenue@123 297 else
Nenue@123 298 self.Label:SetFormattedText("%d", earned)
Nenue@123 299 end
Nenue@123 300 return true
Nenue@123 301 end