annotate Modules/Currency.lua @ 138:6e2f20230190 tip

- 8.1 TOC - disabled Currency and WorldState modules for lack of use - BoD progress link buttons for group finder
author Nenue
date Fri, 22 Feb 2019 17:34:58 -0500
parents 414e37af1b1b
children
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@136 66 VeneerCurrencyBlockMixin = {
Nenue@136 67 OnLoad = function() end,
Nenue@136 68 OnEvent = function() end,
Nenue@136 69 OnShow = function() end,
Nenue@136 70 OnHide = function() end,
Nenue@136 71 }
Nenue@115 72 local module = VeneerCurrencyMixin
Nenue@115 73 local block = VeneerCurrencyBlockMixin
Nick@113 74
Nick@113 75
Nick@113 76
Nick@113 77 local function RegisterEvents (frame, events)
Nick@113 78 for _, event in ipairs(events) do
Nick@113 79 print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event)
Nick@113 80 frame:RegisterEvent(event)
Nick@113 81 end
Nick@113 82 end
Nick@113 83
Nenue@125 84 function module:Setup()
Nenue@128 85 self:Reanchor()
Nenue@125 86 end
Nenue@125 87
Nick@113 88 function module:OnLoad ()
Nenue@115 89 Veneer:AddHandler(self)
Nick@113 90
Nenue@133 91 for _, event in ipairs(events) do
Nenue@133 92 self:RegisterEvent(event)
Nenue@133 93 end
Nenue@133 94
Nenue@133 95
Nick@113 96 for name, info in pairs(blocks) do
Nenue@125 97 local block = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate')
Nenue@125 98 block.name = name
Nick@113 99 for k,v in pairs(info) do
Nick@113 100 print(name, k, '=', v)
Nenue@125 101 block[k] = v
Nick@113 102 end
Nick@113 103
Nenue@125 104 block.debug = function(...)
Nenue@125 105 print('|cFF0088FF<'..block.name..'>|r', ...)
Nick@113 106 end
Nenue@125 107 block.id = info.itemID or info.currencyID
Nenue@123 108
Nenue@133 109 block:SetScript('OnEnter', itemBlock.OnEnter or block.OnEnter)
Nenue@133 110 block:SetScript('OnLeave', itemBlock.OnLeave or block.OnLeave)
Nick@113 111
Nick@113 112 if info.itemID then
Nick@113 113 local itemID = info.itemID
Nick@113 114 items[itemID] = {
Nick@113 115 count = 0,
Nenue@125 116 frame = block
Nick@113 117 }
Nenue@125 118 block.Update = itemBlock.Update
Nick@113 119 elseif info.currencyID then
Nick@113 120 local currencyID = info.currencyID
Nenue@125 121 block.Update = currencyBlock.Update
Nick@113 122 end
Nenue@123 123
Nenue@123 124
Nenue@123 125
Nick@113 126 if info.zones then
Nick@113 127 local zones = info.zones
Nenue@125 128 local of = block.Update
Nenue@128 129 function block:Update()
Nenue@126 130
Nenue@126 131 local zone = GetRealZoneText()
Nenue@126 132 local subZone = GetSubZoneText()
Nenue@125 133 local canShow = ((zone and self.zones[zone]) or (subZone and self.zones[subZone])) and true or false
Nenue@128 134 block.debug('Zone Check', zone, subZone, canShow)
Nick@113 135 if of then
Nenue@125 136 canShow = canShow and of(self)
Nick@113 137 end
Nick@113 138 return canShow
Nick@113 139 end
Nick@113 140 end
Nick@113 141 end
Nenue@131 142
Nenue@131 143 self:RegisterEvent('PLAYER_REGEN_ENABLED')
Nenue@131 144 self:RegisterEvent('PLAYER_REGEN_DISABLED')
Nick@113 145 end
Nick@113 146
Nick@113 147 function module:OnEvent (event, arg)
Nenue@131 148 --print(self:GetName(), 'OnEvent', event, arg)
Nenue@128 149 self:Update()
Nick@113 150 end
Nenue@126 151
Nenue@128 152 function module:Update()
Nenue@131 153 --print(self:GetName(), 'Reanchor()')
Nick@113 154 if InCombatLockdown() then
Nick@113 155 self:SetShown(false)
Nick@113 156 return
Nick@113 157 end
Nick@113 158
Nick@113 159
Nick@113 160 for itemID in pairs(items) do
Nick@113 161 items[itemID].count = 0
Nick@113 162 end
Nenue@126 163
Nick@113 164 local canShow = false
Nenue@128 165 if BagBrother then
Nenue@128 166 for i, bag in pairs(BagBrother.Player) do
Nenue@128 167 if type(bag) == 'table' then
Nenue@128 168 --print(i)
Nenue@128 169 for j, item in pairs(bag) do
Nenue@128 170 local itemID, count = string.match(item ,"^(%d+):.+;(%d*)")
Nenue@128 171 itemID = tonumber(itemID)
Nenue@128 172 if itemID then
Nenue@128 173 --print(j, itemID)
Nenue@128 174 count = tonumber(count)
Nenue@128 175 if count and count >= 1 then
Nenue@128 176 local texture = GetItemIcon(itemID)
Nenue@128 177 --print(itemID)
Nenue@128 178
Nenue@128 179 if items[itemID] then
Nenue@128 180 items[itemID].count = items[itemID].count + (count or 1)
Nenue@128 181 if not items[itemID].texture then
Nenue@128 182 items[itemID].texture = texture
Nenue@128 183 --print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
Nenue@128 184 items[itemID].frame.Icon:SetTexture(texture)
Nenue@128 185 end
Nenue@128 186 end
Nenue@128 187 end
Nenue@128 188 end
Nenue@128 189 end
Nenue@128 190 end
Nenue@128 191
Nenue@128 192 end
Nenue@128 193 else
Nenue@128 194 for i = 0, NUM_BAG_SLOTS do
Nenue@128 195 local numSlots = GetContainerNumSlots(i)
Nenue@128 196 for j = 1, numSlots do
Nenue@128 197 local itemID = GetContainerItemID(i, j)
Nenue@128 198 local texture, count = GetContainerItemInfo(i,j)
Nenue@128 199 if items[itemID] then
Nenue@133 200
Nenue@128 201 items[itemID].count = items[itemID].count + (count or 1)
Nenue@128 202 if not items[itemID].texture then
Nenue@128 203 items[itemID].texture = texture
Nenue@128 204 print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
Nenue@128 205 items[itemID].frame.Icon:SetTexture(texture)
Nenue@128 206 end
Nenue@115 207 end
Nick@113 208 end
Nick@113 209 end
Nick@113 210 end
Nick@113 211
Nenue@115 212
Nick@113 213
Nick@113 214 local lastBlock
Nick@113 215 local totalWidth = 0
Nick@113 216 for _, block in ipairs(self.Blocks) do
Nenue@128 217 local blockIsShown = block:Update()
Nenue@128 218 print(block.name, blockIsShown)
Nick@113 219 block:SetShown(blockIsShown)
Nick@113 220 canShow = canShow or blockIsShown
Nick@113 221
Nick@113 222
Nenue@125 223 if blockIsShown then
Nick@113 224 block:ClearAllPoints()
Nick@113 225 if lastBlock then
Nick@113 226 block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT')
Nick@113 227 else
Nick@113 228 block:SetPoint('TOPLEFT', self, 'TOPLEFT')
Nick@113 229 end
Nick@113 230 lastBlock = block
Nick@113 231
Nick@113 232 block:SetHeight(24)
Nenue@123 233 block:SetWidth(block.Icon:GetWidth() + block.Label:GetStringWidth()+4)
Nick@113 234 totalWidth = totalWidth + block:GetWidth()
Nick@113 235 end
Nenue@126 236 print('|cFF0088FF'..block.name..'|r', block:IsShown(), block:GetSize())
Nick@113 237 end
Nick@113 238
Nenue@115 239 self:UpdateProfile()
Nick@113 240 self:SetWidth(totalWidth)
Nick@113 241
Nenue@115 242 needsUpdate = nil
Nick@113 243 print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize())
Nick@113 244 self:SetShown(canShow)
Nenue@115 245 Veneer:DynamicReanchor()
Nenue@115 246 end
Nenue@115 247
Nenue@115 248 function module:UpdateProfile()
Nenue@115 249 if not self.profile then
Nenue@115 250 profileUpdate = true
Nenue@115 251 return
Nenue@115 252 end
Nenue@115 253
Nenue@115 254 for itemID, info in pairs(items) do
Nenue@115 255 self.profile.Items = self.profile.Items or {}
Nenue@115 256 self.profile.Items[itemID] = info
Nenue@115 257 end
Nick@113 258 end
Nick@113 259
Nick@113 260 function module:OnUpdate()
Nenue@115 261 if needsUpdate then
Nenue@125 262 self:Update(GetRealZoneText(), GetSubZoneText())
Nenue@115 263 elseif profileUpdate then
Nenue@115 264 self:UpdateProfile()
Nick@113 265 end
Nenue@115 266
Nick@113 267 end
Nick@113 268
Nick@114 269 function block:OnEnter()
Nick@114 270 if not InCombatLockdown() then
Nick@114 271 GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT");
Nick@114 272 if self.currencyID then
Nick@114 273 GameTooltip:SetCurrencyTokenByID(self.currencyID);
Nick@114 274 else
Nick@114 275 GameTooltip:SetItemByID(self.itemID);
Nick@114 276 end
Nick@114 277 GameTooltip:Show();
Nick@114 278 end
Nick@114 279 end
Nick@114 280 function block:OnLeave()
Nick@114 281 if GameTooltip:IsOwned(self) then
Nick@114 282 GameTooltip_Hide()
Nick@114 283 end
Nick@114 284 end
Nick@114 285
Nick@113 286
Nenue@126 287 function itemBlock:Update()
Nenue@123 288 if items[self.itemID].count >= 1 then
Nenue@123 289 self.Icon:SetTexture(GetItemIcon(self.id))
Nenue@123 290 self.Label:SetFormattedText("%d", items[self.id].count)
Nenue@123 291 return true
Nenue@123 292 end
Nenue@125 293 return false
Nenue@123 294 end
Nenue@123 295
Nenue@126 296 function currencyBlock:Update()
Nenue@123 297 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(self.id)
Nenue@123 298
Nenue@123 299 self.Icon:SetTexture(texture)
Nenue@123 300 if self.showMax then
Nenue@123 301 self.Label:SetFormattedText("%d / %d", earned, totalMax)
Nenue@123 302 else
Nenue@123 303 self.Label:SetFormattedText("%d", earned)
Nenue@123 304 end
Nenue@123 305 return true
Nenue@123 306 end