annotate Modules/Currency.lua @ 123:b3c0258b419d v7.3.0-1

ArtifactPower: - XP progress bar fixes Currency: - More argus stuff - Block dimensions are calculated more consistently TalkingHead - Aesthetic changes - Default right-click behaviour restored (hides the text box)
author Nenue
date Tue, 05 Sep 2017 02:56:33 -0400
parents ddfe19d70a34
children 3f4794dca91b
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
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,
Nick@113 33 ["Sashj'tar Ruins"] = true,
Nenue@116 34 ["Faronaar Ruins"] = true,
Nenue@116 35 ["Halls of the Eclipse"] = true,
Nenue@116 36 ["Shal'aran"] = true,
Nenue@116 37 ["The Fel Breach"] = true,
Nenue@116 38 },
Nick@113 39 },
Nick@113 40 ["Blood of Sargeras"] = {
Nick@113 41 itemID = 124124,
Nenue@116 42 },
Nenue@116 43 ["Legionfall War Supplies"] = {
Nenue@116 44 currencyID = 1342,
Nenue@116 45 },
Nenue@116 46 ["Nethershard"] = {
Nenue@116 47 currencyID = 1226,
Nenue@123 48 },
Nenue@123 49 ["Veiled Argunite"] = {
Nenue@123 50 currencyID = 1508,
Nenue@123 51 },
Nenue@123 52 ["Argus Waystone"] = {
Nenue@123 53 currencyID = 1506,
Nick@113 54 }
Nick@113 55 }
Nenue@115 56 local items, currencies = {}, {}
Nick@113 57
Nick@113 58
Nenue@115 59 VeneerCurrencyMixin = {
Nenue@115 60 Blocks = {},
Nenue@115 61 HideCombat = true,
Nenue@115 62 EventList = {'PLAYER_ENTERING_WORLD'},
Nenue@115 63 moduleName = 'Currency Watch',
Nenue@115 64 anchorPoint = 'TOP',
Nenue@116 65 anchorPriority = 2,
Nenue@115 66 }
Nenue@115 67 VeneerCurrencyBlockMixin = {}
Nenue@115 68 local module = VeneerCurrencyMixin
Nenue@115 69 local block = VeneerCurrencyBlockMixin
Nick@113 70
Nick@113 71
Nick@113 72
Nick@113 73 local function RegisterEvents (frame, events)
Nick@113 74 for _, event in ipairs(events) do
Nick@113 75 print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event)
Nick@113 76 frame:RegisterEvent(event)
Nick@113 77 end
Nick@113 78 end
Nick@113 79
Nick@113 80 function module:OnLoad ()
Nenue@115 81 Veneer:AddHandler(self)
Nick@113 82
Nick@113 83 for name, info in pairs(blocks) do
Nick@113 84 local frame = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate')
Nick@113 85 frame.name = name
Nick@113 86 for k,v in pairs(info) do
Nick@113 87 print(name, k, '=', v)
Nick@113 88 frame[k] = v
Nick@113 89 end
Nick@113 90
Nenue@123 91 frame.debug = function(...)
Nick@113 92 print('|cFF0088FF<'..frame.name..'>|r', ...)
Nick@113 93 end
Nenue@123 94 frame.id = info.itemID or info.currencyID
Nenue@123 95
Nick@113 96
Nick@113 97 if info.itemID then
Nick@113 98 local itemID = info.itemID
Nick@113 99 items[itemID] = {
Nick@113 100 count = 0,
Nick@113 101 frame = frame
Nick@113 102 }
Nenue@123 103 frame.Update = itemBlock.Update
Nick@113 104 RegisterEvents(self, itemEvents)
Nick@113 105 elseif info.currencyID then
Nick@113 106 local currencyID = info.currencyID
Nenue@123 107 frame.Update = currencyBlock.Update
Nick@113 108 RegisterEvents(frame, currencyEvents)
Nick@113 109 end
Nenue@123 110
Nenue@123 111
Nenue@123 112
Nick@113 113 if info.zones then
Nick@113 114 RegisterEvents(frame, zoneEvents)
Nick@113 115 local zones = info.zones
Nick@113 116 local of = frame.Update
Nick@113 117 frame.Update = function(block)
Nenue@123 118 frame.debug('Update [Zone]')
Nick@113 119 local zone = self.zoneText
Nick@113 120 local canShow = (zone and block.zones[zone]) and true or false
Nick@113 121 if of then
Nick@113 122 canShow = canShow and of(frame)
Nick@113 123 end
Nick@113 124 return canShow
Nick@113 125 end
Nick@113 126 end
Nick@113 127 end
Nick@113 128 end
Nick@113 129
Nick@113 130 function module:OnEvent (event, arg)
Nick@113 131 print(self:GetName(), 'OnEvent', event, arg)
Nick@113 132 self:Update()
Nick@113 133 end
Nick@113 134 local toUpdate = {}
Nick@113 135 local wipe = table.wipe
Nick@113 136 function module:Update(isBatchUpdate)
Nick@113 137 print(self:GetName(), 'Update()')
Nick@113 138 if InCombatLockdown() then
Nick@113 139 self:SetShown(false)
Nick@113 140 return
Nick@113 141 end
Nick@113 142
Nick@113 143
Nick@113 144 for itemID in pairs(items) do
Nick@113 145 items[itemID].count = 0
Nick@113 146 end
Nick@113 147 self.zoneText = GetRealZoneText()
Nick@113 148 local canShow = false
Nick@113 149
Nick@113 150 for i = 0, NUM_BAG_SLOTS do
Nick@113 151 local numSlots = GetContainerNumSlots(i)
Nick@113 152 for j = 1, numSlots do
Nick@113 153 local itemID = GetContainerItemID(i, j)
Nick@113 154 local texture, count = GetContainerItemInfo(i,j)
Nick@113 155 if items[itemID] then
Nick@113 156 items[itemID].count = items[itemID].count + (count or 1)
Nenue@115 157 if not items[itemID].texture then
Nenue@115 158 items[itemID].texture = texture
Nenue@115 159 print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
Nenue@115 160 items[itemID].frame.Icon:SetTexture(texture)
Nenue@115 161 end
Nick@113 162 end
Nick@113 163 end
Nick@113 164 end
Nick@113 165
Nenue@115 166
Nick@113 167
Nick@113 168 local lastBlock
Nick@113 169 local totalWidth = 0
Nick@113 170 for _, block in ipairs(self.Blocks) do
Nick@113 171 local blockIsShown = block:Update() or false
Nick@113 172 block:SetShown(blockIsShown)
Nick@113 173 canShow = canShow or blockIsShown
Nick@113 174
Nick@113 175
Nick@113 176 if block:IsShown() then
Nick@113 177 block:ClearAllPoints()
Nick@113 178 if lastBlock then
Nick@113 179 block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT')
Nick@113 180 else
Nick@113 181 block:SetPoint('TOPLEFT', self, 'TOPLEFT')
Nick@113 182 end
Nick@113 183 lastBlock = block
Nick@113 184
Nick@113 185 block:SetHeight(24)
Nenue@123 186 block:SetWidth(block.Icon:GetWidth() + block.Label:GetStringWidth()+4)
Nick@113 187 totalWidth = totalWidth + block:GetWidth()
Nick@113 188 end
Nick@113 189 print(block:IsShown(), '|cFF0088FF'..block.name..'|r', block:GetSize())
Nick@113 190 end
Nick@113 191
Nenue@115 192 self:UpdateProfile()
Nick@113 193 self:SetWidth(totalWidth)
Nick@113 194
Nenue@115 195 needsUpdate = nil
Nick@113 196 print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize())
Nick@113 197 self:SetShown(canShow)
Nenue@115 198 Veneer:DynamicReanchor()
Nenue@115 199 end
Nenue@115 200
Nenue@115 201 function module:UpdateProfile()
Nenue@115 202 if not self.profile then
Nenue@115 203 profileUpdate = true
Nenue@115 204 return
Nenue@115 205 end
Nenue@115 206
Nenue@115 207 for itemID, info in pairs(items) do
Nenue@115 208 self.profile.Items = self.profile.Items or {}
Nenue@115 209 self.profile.Items[itemID] = info
Nenue@115 210 end
Nick@113 211 end
Nick@113 212
Nick@113 213 function module:OnUpdate()
Nenue@115 214 if needsUpdate then
Nick@113 215 self:Update()
Nenue@115 216 elseif profileUpdate then
Nenue@115 217 self:UpdateProfile()
Nick@113 218 end
Nenue@115 219
Nick@113 220 end
Nick@113 221
Nick@114 222 function block:OnEnter()
Nick@114 223 if not InCombatLockdown() then
Nick@114 224 GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT");
Nick@114 225 if self.currencyID then
Nick@114 226 GameTooltip:SetCurrencyTokenByID(self.currencyID);
Nick@114 227 else
Nick@114 228 GameTooltip:SetItemByID(self.itemID);
Nick@114 229 end
Nick@114 230 GameTooltip:Show();
Nick@114 231 end
Nick@114 232 end
Nick@114 233 function block:OnLeave()
Nick@114 234 if GameTooltip:IsOwned(self) then
Nick@114 235 GameTooltip_Hide()
Nick@114 236 end
Nick@114 237 end
Nick@114 238
Nick@113 239 function block:OnEvent(event, ...)
Nick@113 240 print('|cFF0088FF<'..self.name..'>|r', 'OnEvent', event, ...)
Nick@113 241 self:Update()
Nick@113 242 end
Nick@113 243
Nick@113 244 function block:Setup()
Nick@113 245
Nick@113 246 end
Nenue@123 247 function itemBlock:Update()
Nenue@123 248 self.debug('Update [Item]')
Nenue@123 249 if items[self.itemID].count >= 1 then
Nenue@123 250 self.Icon:SetTexture(GetItemIcon(self.id))
Nenue@123 251 self.Label:SetFormattedText("%d", items[self.id].count)
Nenue@123 252 return true
Nenue@123 253 end
Nenue@123 254 end
Nenue@123 255
Nenue@123 256 function currencyBlock:Update()
Nenue@123 257 self.debug('Update [Currency]')
Nenue@123 258 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(self.id)
Nenue@123 259
Nenue@123 260 self.Icon:SetTexture(texture)
Nenue@123 261 if self.showMax then
Nenue@123 262 self.Label:SetFormattedText("%d / %d", earned, totalMax)
Nenue@123 263 else
Nenue@123 264 self.Label:SetFormattedText("%d", earned)
Nenue@123 265 end
Nenue@123 266
Nenue@123 267 --self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6)
Nenue@123 268 return true
Nenue@123 269 end