annotate Modules/Currency.lua @ 117:589045559484 v720.0

ArtifactPower: - cleanup of tooltip stats - green = available with XP currently invested, blue = available with XP from inventory
author Nenue
date Wed, 17 May 2017 08:23:27 -0400
parents ddfe19d70a34
children b3c0258b419d
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
Nenue@115 10 local profileUpdate, needsUpdate
Nick@113 11
Nick@113 12 local zoneEvents = {
Nick@113 13 "ZONE_CHANGED_NEW_AREA", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED"
Nick@113 14 }
Nick@113 15 local currencyEvents = {
Nick@113 16 'CURRENCY_DISPLAY_UPDATE', 'CHAT_MSG_CURRENCY'
Nick@113 17 }
Nick@113 18 local itemEvents = {
Nick@113 19 'CHAT_MSG_LOOT', 'BAG_UPDATE'
Nick@113 20 }
Nick@113 21
Nick@113 22 local blocks = {
Nick@113 23 ["Ancient Mana"] = {
Nick@113 24 currencyID = 1155,
Nenue@116 25 showMax = true,
Nick@113 26 zones = {
Nick@113 27 ['Suramar'] = true,
Nick@113 28 ["Sashj'tar Ruins"] = true,
Nenue@116 29 ["Faronaar Ruins"] = true,
Nenue@116 30 ["Halls of the Eclipse"] = true,
Nenue@116 31 ["Shal'aran"] = true,
Nenue@116 32 ["The Fel Breach"] = 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@116 40 },
Nenue@116 41 ["Nethershard"] = {
Nenue@116 42 currencyID = 1226,
Nick@113 43 }
Nick@113 44 }
Nenue@115 45 local items, currencies = {}, {}
Nick@113 46
Nick@113 47
Nenue@115 48 VeneerCurrencyMixin = {
Nenue@115 49 Blocks = {},
Nenue@115 50 HideCombat = true,
Nenue@115 51 EventList = {'PLAYER_ENTERING_WORLD'},
Nenue@115 52 moduleName = 'Currency Watch',
Nenue@115 53 anchorPoint = 'TOP',
Nenue@116 54 anchorPriority = 2,
Nenue@115 55 }
Nenue@115 56 VeneerCurrencyBlockMixin = {}
Nenue@115 57 local module = VeneerCurrencyMixin
Nenue@115 58 local block = VeneerCurrencyBlockMixin
Nick@113 59
Nick@113 60
Nick@113 61
Nick@113 62 local function RegisterEvents (frame, events)
Nick@113 63 for _, event in ipairs(events) do
Nick@113 64 print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event)
Nick@113 65 frame:RegisterEvent(event)
Nick@113 66 end
Nick@113 67 end
Nick@113 68
Nick@113 69 function module:OnLoad ()
Nenue@115 70 Veneer:AddHandler(self)
Nick@113 71
Nick@113 72 for name, info in pairs(blocks) do
Nick@113 73 local frame = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate')
Nick@113 74 frame.name = name
Nick@113 75 for k,v in pairs(info) do
Nick@113 76 print(name, k, '=', v)
Nick@113 77 frame[k] = v
Nick@113 78 end
Nick@113 79
Nick@113 80 local debug = function(...)
Nick@113 81 print('|cFF0088FF<'..frame.name..'>|r', ...)
Nick@113 82 end
Nick@113 83
Nick@113 84 if info.itemID then
Nick@113 85 local itemID = info.itemID
Nick@113 86 items[itemID] = {
Nick@113 87 count = 0,
Nick@113 88 frame = frame
Nick@113 89 }
Nick@113 90 frame.Update = function(block)
Nick@113 91 debug('Update [Item]')
Nick@113 92 if items[itemID].count >= 1 then
Nick@113 93 block.Icon:SetTexture(GetItemIcon(itemID))
Nick@113 94 block.Label:SetFormattedText("%d", items[itemID].count)
Nick@113 95 return true
Nick@113 96 end
Nick@113 97 end
Nick@113 98 RegisterEvents(self, itemEvents)
Nick@113 99 elseif info.currencyID then
Nick@113 100 local currencyID = info.currencyID
Nick@113 101 frame.Update = function (block)
Nick@113 102 debug('Update [Currency]')
Nick@113 103 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(currencyID)
Nick@114 104
Nick@113 105 block.Icon:SetTexture(texture)
Nenue@116 106 if self.showMax then
Nenue@116 107 block.Label:SetFormattedText("%d / %d", earned, totalMax)
Nenue@116 108 else
Nenue@116 109 block.Label:SetFormattedText("%d", earned)
Nenue@116 110 end
Nenue@116 111
Nick@113 112 block:SetWidth(block.Icon:GetWidth() + block.Label:GetStringWidth() + 6)
Nick@113 113 return true
Nick@113 114 end
Nick@113 115
Nick@113 116 RegisterEvents(frame, currencyEvents)
Nick@113 117 end
Nick@113 118 if info.zones then
Nick@113 119 RegisterEvents(frame, zoneEvents)
Nick@113 120 local zones = info.zones
Nick@113 121 local of = frame.Update
Nick@113 122 frame.Update = function(block)
Nick@113 123 debug('Update [Zone]')
Nick@113 124 local zone = self.zoneText
Nick@113 125 local canShow = (zone and block.zones[zone]) and true or false
Nick@113 126 if of then
Nick@113 127 canShow = canShow and of(frame)
Nick@113 128 end
Nick@113 129 return canShow
Nick@113 130 end
Nick@113 131 end
Nick@113 132 end
Nick@113 133 end
Nick@113 134
Nick@113 135 function module:OnEvent (event, arg)
Nick@113 136 print(self:GetName(), 'OnEvent', event, arg)
Nick@113 137 self:Update()
Nick@113 138 end
Nick@113 139 local toUpdate = {}
Nick@113 140 local wipe = table.wipe
Nick@113 141 function module:Update(isBatchUpdate)
Nick@113 142 print(self:GetName(), 'Update()')
Nick@113 143 if InCombatLockdown() then
Nick@113 144 self:SetShown(false)
Nick@113 145 return
Nick@113 146 end
Nick@113 147
Nick@113 148
Nick@113 149 for itemID in pairs(items) do
Nick@113 150 items[itemID].count = 0
Nick@113 151 end
Nick@113 152 self.zoneText = GetRealZoneText()
Nick@113 153 local canShow = false
Nick@113 154
Nick@113 155 for i = 0, NUM_BAG_SLOTS do
Nick@113 156 local numSlots = GetContainerNumSlots(i)
Nick@113 157 for j = 1, numSlots do
Nick@113 158 local itemID = GetContainerItemID(i, j)
Nick@113 159 local texture, count = GetContainerItemInfo(i,j)
Nick@113 160 if items[itemID] then
Nick@113 161 items[itemID].count = items[itemID].count + (count or 1)
Nenue@115 162 if not items[itemID].texture then
Nenue@115 163 items[itemID].texture = texture
Nenue@115 164 print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
Nenue@115 165 items[itemID].frame.Icon:SetTexture(texture)
Nenue@115 166 end
Nick@113 167 end
Nick@113 168 end
Nick@113 169 end
Nick@113 170
Nenue@115 171
Nick@113 172
Nick@113 173 local lastBlock
Nick@113 174 local totalWidth = 0
Nick@113 175 for _, block in ipairs(self.Blocks) do
Nick@113 176 local blockIsShown = block:Update() or false
Nick@113 177 block:SetShown(blockIsShown)
Nick@113 178 canShow = canShow or blockIsShown
Nick@113 179
Nick@113 180
Nick@113 181 if block:IsShown() then
Nick@113 182 block:ClearAllPoints()
Nick@113 183 if lastBlock then
Nick@113 184 block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT')
Nick@113 185 else
Nick@113 186 block:SetPoint('TOPLEFT', self, 'TOPLEFT')
Nick@113 187 end
Nick@113 188 lastBlock = block
Nick@113 189
Nick@113 190 block:SetHeight(24)
Nick@113 191 block:SetWidth(block.Icon:GetWidth() + block.Label:GetWidth()+4)
Nick@113 192 totalWidth = totalWidth + block:GetWidth()
Nick@113 193 end
Nick@113 194 print(block:IsShown(), '|cFF0088FF'..block.name..'|r', block:GetSize())
Nick@113 195 end
Nick@113 196
Nenue@115 197 self:UpdateProfile()
Nick@113 198 self:SetWidth(totalWidth)
Nick@113 199
Nenue@115 200 needsUpdate = nil
Nick@113 201 print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize())
Nick@113 202 self:SetShown(canShow)
Nenue@115 203 Veneer:DynamicReanchor()
Nenue@115 204 end
Nenue@115 205
Nenue@115 206 function module:UpdateProfile()
Nenue@115 207 if not self.profile then
Nenue@115 208 profileUpdate = true
Nenue@115 209 return
Nenue@115 210 end
Nenue@115 211
Nenue@115 212 for itemID, info in pairs(items) do
Nenue@115 213 self.profile.Items = self.profile.Items or {}
Nenue@115 214 self.profile.Items[itemID] = info
Nenue@115 215 end
Nick@113 216 end
Nick@113 217
Nick@113 218 function module:OnUpdate()
Nenue@115 219 if needsUpdate then
Nick@113 220 self:Update()
Nenue@115 221 elseif profileUpdate then
Nenue@115 222 self:UpdateProfile()
Nick@113 223 end
Nenue@115 224
Nick@113 225 end
Nick@113 226
Nick@114 227 function block:OnEnter()
Nick@114 228 if not InCombatLockdown() then
Nick@114 229 GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT");
Nick@114 230 if self.currencyID then
Nick@114 231 GameTooltip:SetCurrencyTokenByID(self.currencyID);
Nick@114 232 else
Nick@114 233 GameTooltip:SetItemByID(self.itemID);
Nick@114 234 end
Nick@114 235 GameTooltip:Show();
Nick@114 236 end
Nick@114 237 end
Nick@114 238 function block:OnLeave()
Nick@114 239 if GameTooltip:IsOwned(self) then
Nick@114 240 GameTooltip_Hide()
Nick@114 241 end
Nick@114 242 end
Nick@114 243
Nick@113 244 function block:OnEvent(event, ...)
Nick@113 245 print('|cFF0088FF<'..self.name..'>|r', 'OnEvent', event, ...)
Nick@113 246 self:Update()
Nick@113 247 end
Nick@113 248
Nick@113 249 function block:Setup()
Nick@113 250
Nick@113 251 end