annotate Modules/Currency.lua @ 114:6748c98a6c6c

- Reworked OrderHallHandler triggers - OrderHallHandler minimializes hud info - WorldState currency headers have a unified font
author Nick@Zahhak
date Mon, 27 Mar 2017 00:39:29 -0400
parents 2105b6e5095f
children 8c94bee4fdfc
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
Nick@113 10
Nick@113 11 local zoneEvents = {
Nick@113 12 "ZONE_CHANGED_NEW_AREA", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED"
Nick@113 13 }
Nick@113 14 local currencyEvents = {
Nick@113 15 'CURRENCY_DISPLAY_UPDATE', 'CHAT_MSG_CURRENCY'
Nick@113 16 }
Nick@113 17 local itemEvents = {
Nick@113 18 'CHAT_MSG_LOOT', 'BAG_UPDATE'
Nick@113 19 }
Nick@113 20
Nick@113 21 local blocks = {
Nick@113 22 ["Ancient Mana"] = {
Nick@113 23 currencyID = 1155,
Nick@113 24 zones = {
Nick@113 25 ['Suramar'] = true,
Nick@113 26 ["Sashj'tar Ruins"] = true,
Nick@113 27 ["Faronaar Ruins"] = true
Nick@113 28 }
Nick@113 29 },
Nick@113 30 ["Blood of Sargeras"] = {
Nick@113 31 itemID = 124124,
Nick@113 32 }
Nick@113 33 }
Nick@113 34 local items = {}
Nick@113 35
Nick@113 36
Nick@113 37 VeneerWorldStateCurrencyMixin = { Blocks = {} }
Nick@113 38 VeneerWorldStateCurrencyBlockMixin = {}
Nick@113 39 local module = VeneerWorldStateCurrencyMixin
Nick@113 40 local block = VeneerWorldStateCurrencyBlockMixin
Nick@113 41
Nick@113 42
Nick@113 43
Nick@113 44 local function RegisterEvents (frame, events)
Nick@113 45 for _, event in ipairs(events) do
Nick@113 46 print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event)
Nick@113 47 frame:RegisterEvent(event)
Nick@113 48 end
Nick@113 49 end
Nick@113 50
Nick@113 51 function module:OnLoad ()
Nick@113 52 self:RegisterEvent("PLAYER_ENTERING_WORLD");
Nick@113 53 self:RegisterEvent('PLAYER_REGEN_ENABLED')
Nick@113 54 self:RegisterEvent('PLAYER_REGEN_DISABLED')
Nick@113 55
Nick@113 56 for name, info in pairs(blocks) do
Nick@113 57 local frame = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate')
Nick@113 58 frame.name = name
Nick@113 59 for k,v in pairs(info) do
Nick@113 60 print(name, k, '=', v)
Nick@113 61 frame[k] = v
Nick@113 62 end
Nick@113 63
Nick@113 64 local debug = function(...)
Nick@113 65 print('|cFF0088FF<'..frame.name..'>|r', ...)
Nick@113 66 end
Nick@113 67
Nick@113 68 if info.itemID then
Nick@113 69 local itemID = info.itemID
Nick@113 70 items[itemID] = {
Nick@113 71 count = 0,
Nick@113 72 frame = frame
Nick@113 73 }
Nick@113 74 frame.Update = function(block)
Nick@113 75 debug('Update [Item]')
Nick@113 76 if items[itemID].count >= 1 then
Nick@113 77 block.Icon:SetTexture(GetItemIcon(itemID))
Nick@113 78 block.Label:SetFormattedText("%d", items[itemID].count)
Nick@113 79 return true
Nick@113 80 end
Nick@113 81 end
Nick@113 82 RegisterEvents(self, itemEvents)
Nick@113 83 elseif info.currencyID then
Nick@113 84 local currencyID = info.currencyID
Nick@113 85 frame.Update = function (block)
Nick@113 86 debug('Update [Currency]')
Nick@113 87 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(currencyID)
Nick@114 88
Nick@113 89 block.Icon:SetTexture(texture)
Nick@113 90 block.Label:SetFormattedText("%d / %d", earned, totalMax)
Nick@113 91 block:SetWidth(block.Icon:GetWidth() + block.Label:GetStringWidth() + 6)
Nick@113 92 return true
Nick@113 93 end
Nick@113 94
Nick@113 95 RegisterEvents(frame, currencyEvents)
Nick@113 96 end
Nick@113 97 if info.zones then
Nick@113 98 RegisterEvents(frame, zoneEvents)
Nick@113 99 local zones = info.zones
Nick@113 100 local of = frame.Update
Nick@113 101 frame.Update = function(block)
Nick@113 102 debug('Update [Zone]')
Nick@113 103 local zone = self.zoneText
Nick@113 104 local canShow = (zone and block.zones[zone]) and true or false
Nick@113 105 if of then
Nick@113 106 canShow = canShow and of(frame)
Nick@113 107 end
Nick@113 108 return canShow
Nick@113 109 end
Nick@113 110 end
Nick@113 111 end
Nick@113 112 end
Nick@113 113
Nick@113 114 function module:OnEvent (event, arg)
Nick@113 115 print(self:GetName(), 'OnEvent', event, arg)
Nick@113 116 self:Update()
Nick@113 117 end
Nick@113 118 local toUpdate = {}
Nick@113 119 local wipe = table.wipe
Nick@113 120 function module:Update(isBatchUpdate)
Nick@113 121 print(self:GetName(), 'Update()')
Nick@113 122 if InCombatLockdown() then
Nick@113 123 self:SetShown(false)
Nick@113 124 return
Nick@113 125 end
Nick@113 126
Nick@113 127
Nick@113 128 for itemID in pairs(items) do
Nick@113 129 items[itemID].count = 0
Nick@113 130 end
Nick@113 131 self.zoneText = GetRealZoneText()
Nick@113 132 local canShow = false
Nick@113 133
Nick@113 134 for i = 0, NUM_BAG_SLOTS do
Nick@113 135 local numSlots = GetContainerNumSlots(i)
Nick@113 136 for j = 1, numSlots do
Nick@113 137 local itemID = GetContainerItemID(i, j)
Nick@113 138 local texture, count = GetContainerItemInfo(i,j)
Nick@113 139 if items[itemID] then
Nick@113 140 items[itemID].count = items[itemID].count + (count or 1)
Nick@113 141 items[itemID].texture = texture
Nick@113 142 print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
Nick@113 143 items[itemID].frame.Icon:SetTexture(texture)
Nick@113 144 end
Nick@113 145 end
Nick@113 146 end
Nick@113 147
Nick@113 148 for itemID, info in pairs(items) do
Nick@113 149 end
Nick@113 150
Nick@113 151 local lastBlock
Nick@113 152 local totalWidth = 0
Nick@113 153 for _, block in ipairs(self.Blocks) do
Nick@113 154 local blockIsShown = block:Update() or false
Nick@113 155 block:SetShown(blockIsShown)
Nick@113 156 canShow = canShow or blockIsShown
Nick@113 157
Nick@113 158
Nick@113 159 if block:IsShown() then
Nick@113 160 block:ClearAllPoints()
Nick@113 161 if lastBlock then
Nick@113 162 block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT')
Nick@113 163 else
Nick@113 164 block:SetPoint('TOPLEFT', self, 'TOPLEFT')
Nick@113 165 end
Nick@113 166 lastBlock = block
Nick@113 167
Nick@113 168 block:SetHeight(24)
Nick@113 169 block:SetWidth(block.Icon:GetWidth() + block.Label:GetWidth()+4)
Nick@113 170 totalWidth = totalWidth + block:GetWidth()
Nick@113 171 end
Nick@113 172 print(block:IsShown(), '|cFF0088FF'..block.name..'|r', block:GetSize())
Nick@113 173
Nick@113 174 end
Nick@113 175
Nick@113 176 self:SetWidth(totalWidth)
Nick@113 177
Nick@113 178 self.needsUpdate = nil
Nick@113 179 print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize())
Nick@113 180 self:SetShown(canShow)
Nick@113 181 VeneerWorldState:Reanchor(true)
Nick@113 182 end
Nick@113 183
Nick@113 184 function module:OnUpdate()
Nick@113 185 if self.needsUpdate then
Nick@113 186 self:Update()
Nick@113 187 end
Nick@113 188 end
Nick@113 189
Nick@114 190 function block:OnEnter()
Nick@114 191 if not InCombatLockdown() then
Nick@114 192 GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT");
Nick@114 193 if self.currencyID then
Nick@114 194 GameTooltip:SetCurrencyTokenByID(self.currencyID);
Nick@114 195 else
Nick@114 196 GameTooltip:SetItemByID(self.itemID);
Nick@114 197 end
Nick@114 198 GameTooltip:Show();
Nick@114 199 end
Nick@114 200 end
Nick@114 201 function block:OnLeave()
Nick@114 202 if GameTooltip:IsOwned(self) then
Nick@114 203 GameTooltip_Hide()
Nick@114 204 end
Nick@114 205 end
Nick@114 206
Nick@113 207 function block:OnEvent(event, ...)
Nick@113 208 print('|cFF0088FF<'..self.name..'>|r', 'OnEvent', event, ...)
Nick@113 209 self:Update()
Nick@113 210 end
Nick@113 211
Nick@113 212 function block:Setup()
Nick@113 213
Nick@113 214 end