annotate Modules/Currency.lua @ 131:15a7f27b11e6 v7.3.2-20111027

- Fixed an infinite loop occurring with Artifact XP calculations on fresh 110 toons - Fixed combat state response - Mask out redundant cheevos (Cutting Edge/AotC and end boss)
author Nenue
date Mon, 20 Nov 2017 12:01:52 -0500
parents 799ec6dce9c3
children 86621c60512b
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
Nick@113 17 local zoneEvents = {
Nick@113 18 "ZONE_CHANGED_NEW_AREA", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED"
Nick@113 19 }
Nick@113 20 local currencyEvents = {
Nick@113 21 'CURRENCY_DISPLAY_UPDATE', 'CHAT_MSG_CURRENCY'
Nick@113 22 }
Nick@113 23 local itemEvents = {
Nick@113 24 'CHAT_MSG_LOOT', 'BAG_UPDATE'
Nick@113 25 }
Nick@113 26
Nick@113 27 local blocks = {
Nick@113 28 ["Ancient Mana"] = {
Nick@113 29 currencyID = 1155,
Nenue@116 30 showMax = true,
Nick@113 31 zones = {
Nick@113 32 ['Suramar'] = true,
Nenue@116 33 },
Nick@113 34 },
Nick@113 35 ["Blood of Sargeras"] = {
Nick@113 36 itemID = 124124,
Nenue@116 37 },
Nenue@116 38 ["Legionfall War Supplies"] = {
Nenue@116 39 currencyID = 1342,
Nenue@125 40 zones = {
Nenue@128 41 ["Broken Shore"] = true
Nenue@125 42 }
Nenue@116 43 },
Nenue@116 44 ["Nethershard"] = {
Nenue@116 45 currencyID = 1226,
Nenue@125 46 zones = {
Nenue@128 47 ["Broken Shore"] = true
Nenue@125 48 }
Nenue@123 49 },
Nenue@123 50 ["Veiled Argunite"] = {
Nenue@123 51 currencyID = 1508,
Nenue@125 52 zones = {
Nenue@125 53 ["Antoran Wastes"] = true,
Nenue@125 54 ["Krokuun"] = true,
Nenue@125 55 ["MacAree"] = true,
Nenue@125 56 }
Nenue@123 57 },
Nick@113 58 }
Nenue@115 59 local items, currencies = {}, {}
Nick@113 60
Nick@113 61
Nenue@115 62 VeneerCurrencyMixin = {
Nenue@115 63 Blocks = {},
Nenue@115 64 HideCombat = true,
Nenue@115 65 EventList = {'PLAYER_ENTERING_WORLD'},
Nenue@115 66 moduleName = 'Currency Watch',
Nenue@115 67 anchorPoint = 'TOP',
Nenue@116 68 anchorPriority = 2,
Nenue@115 69 }
Nenue@115 70 VeneerCurrencyBlockMixin = {}
Nenue@115 71 local module = VeneerCurrencyMixin
Nenue@115 72 local block = VeneerCurrencyBlockMixin
Nick@113 73
Nick@113 74
Nick@113 75
Nick@113 76 local function RegisterEvents (frame, events)
Nick@113 77 for _, event in ipairs(events) do
Nick@113 78 print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event)
Nick@113 79 frame:RegisterEvent(event)
Nick@113 80 end
Nick@113 81 end
Nick@113 82
Nenue@125 83 function module:Setup()
Nenue@128 84 self:Reanchor()
Nenue@125 85 end
Nenue@125 86
Nick@113 87 function module:OnLoad ()
Nenue@115 88 Veneer:AddHandler(self)
Nick@113 89
Nick@113 90 for name, info in pairs(blocks) do
Nenue@125 91 local block = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate')
Nenue@125 92 block.name = name
Nick@113 93 for k,v in pairs(info) do
Nick@113 94 print(name, k, '=', v)
Nenue@125 95 block[k] = v
Nick@113 96 end
Nick@113 97
Nenue@125 98 block.debug = function(...)
Nenue@125 99 print('|cFF0088FF<'..block.name..'>|r', ...)
Nick@113 100 end
Nenue@125 101 block.id = info.itemID or info.currencyID
Nenue@123 102
Nick@113 103
Nick@113 104 if info.itemID then
Nick@113 105 local itemID = info.itemID
Nick@113 106 items[itemID] = {
Nick@113 107 count = 0,
Nenue@125 108 frame = block
Nick@113 109 }
Nenue@125 110 block.Update = itemBlock.Update
Nenue@128 111 RegisterEvents(block, itemEvents)
Nick@113 112 elseif info.currencyID then
Nick@113 113 local currencyID = info.currencyID
Nenue@125 114 block.Update = currencyBlock.Update
Nenue@128 115 RegisterEvents(self, currencyEvents)
Nick@113 116 end
Nenue@123 117
Nenue@123 118
Nenue@123 119
Nick@113 120 if info.zones then
Nenue@128 121 RegisterEvents(self, zoneEvents)
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
Nick@113 160
Nenue@128 161 if BagBrother then
Nenue@128 162 for i, bag in pairs(BagBrother.Player) do
Nenue@128 163 if type(bag) == 'table' then
Nenue@128 164 --print(i)
Nenue@128 165 for j, item in pairs(bag) do
Nenue@128 166 local itemID, count = string.match(item ,"^(%d+):.+;(%d*)")
Nenue@128 167 itemID = tonumber(itemID)
Nenue@128 168 if itemID then
Nenue@128 169 --print(j, itemID)
Nenue@128 170 count = tonumber(count)
Nenue@128 171 if count and count >= 1 then
Nenue@128 172 local texture = GetItemIcon(itemID)
Nenue@128 173 --print(itemID)
Nenue@128 174
Nenue@128 175 if items[itemID] then
Nenue@128 176 items[itemID].count = items[itemID].count + (count or 1)
Nenue@128 177 if not items[itemID].texture then
Nenue@128 178 items[itemID].texture = texture
Nenue@128 179 --print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
Nenue@128 180 items[itemID].frame.Icon:SetTexture(texture)
Nenue@128 181 end
Nenue@128 182 end
Nenue@128 183 end
Nenue@128 184 end
Nenue@128 185 end
Nenue@128 186 end
Nenue@128 187
Nenue@128 188 end
Nenue@128 189 else
Nenue@128 190 for i = 0, NUM_BAG_SLOTS do
Nenue@128 191 local numSlots = GetContainerNumSlots(i)
Nenue@128 192 for j = 1, numSlots do
Nenue@128 193 local itemID = GetContainerItemID(i, j)
Nenue@128 194 local texture, count = GetContainerItemInfo(i,j)
Nenue@128 195 if items[itemID] then
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 function block:OnEvent(event, ...)
Nenue@126 282 self.debug('OnEvent', event, ...)
Nenue@126 283 self:Update()
Nick@113 284 end
Nick@113 285
Nick@113 286 function block:Setup()
Nenue@126 287 end
Nick@113 288
Nenue@126 289 function itemBlock:Update()
Nenue@123 290 if items[self.itemID].count >= 1 then
Nenue@123 291 self.Icon:SetTexture(GetItemIcon(self.id))
Nenue@123 292 self.Label:SetFormattedText("%d", items[self.id].count)
Nenue@123 293 return true
Nenue@123 294 end
Nenue@125 295 return false
Nenue@123 296 end
Nenue@123 297
Nenue@126 298 function currencyBlock:Update()
Nenue@123 299 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(self.id)
Nenue@123 300
Nenue@123 301 self.Icon:SetTexture(texture)
Nenue@123 302 if self.showMax then
Nenue@123 303 self.Label:SetFormattedText("%d / %d", earned, totalMax)
Nenue@123 304 else
Nenue@123 305 self.Label:SetFormattedText("%d", earned)
Nenue@123 306 end
Nenue@123 307 return true
Nenue@123 308 end