Mercurial > wow > buffalo2
comparison Modules/Currency.lua @ 113:2105b6e5095f
- Added Blood of Sargeras to currency list
- Fixed panel ordering issues when a module is loaded on the fly.
| author | Nick@Zahhak |
|---|---|
| date | Sun, 26 Mar 2017 06:25:18 -0400 |
| parents | |
| children | 6748c98a6c6c |
comparison
equal
deleted
inserted
replaced
| 112:7c77fde36287 | 113:2105b6e5095f |
|---|---|
| 1 -- | |
| 2 -- Created by IntelliJ IDEA. | |
| 3 -- User: Nick | |
| 4 -- Date: 3/25/2017 | |
| 5 -- Time: 7:07 PM | |
| 6 -- To change this template use File | Settings | File Templates. | |
| 7 -- | |
| 8 | |
| 9 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop | |
| 10 | |
| 11 local zoneEvents = { | |
| 12 "ZONE_CHANGED_NEW_AREA", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED" | |
| 13 } | |
| 14 local currencyEvents = { | |
| 15 'CURRENCY_DISPLAY_UPDATE', 'CHAT_MSG_CURRENCY' | |
| 16 } | |
| 17 local itemEvents = { | |
| 18 'CHAT_MSG_LOOT', 'BAG_UPDATE' | |
| 19 } | |
| 20 | |
| 21 local blocks = { | |
| 22 ["Ancient Mana"] = { | |
| 23 currencyID = 1155, | |
| 24 zones = { | |
| 25 ['Suramar'] = true, | |
| 26 ["Sashj'tar Ruins"] = true, | |
| 27 ["Faronaar Ruins"] = true | |
| 28 } | |
| 29 }, | |
| 30 ["Blood of Sargeras"] = { | |
| 31 itemID = 124124, | |
| 32 } | |
| 33 } | |
| 34 local items = {} | |
| 35 | |
| 36 | |
| 37 VeneerWorldStateCurrencyMixin = { Blocks = {} } | |
| 38 VeneerWorldStateCurrencyBlockMixin = {} | |
| 39 local module = VeneerWorldStateCurrencyMixin | |
| 40 local block = VeneerWorldStateCurrencyBlockMixin | |
| 41 | |
| 42 | |
| 43 | |
| 44 local function RegisterEvents (frame, events) | |
| 45 for _, event in ipairs(events) do | |
| 46 print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event) | |
| 47 frame:RegisterEvent(event) | |
| 48 end | |
| 49 end | |
| 50 | |
| 51 function module:OnLoad () | |
| 52 self:RegisterEvent("PLAYER_ENTERING_WORLD"); | |
| 53 self:RegisterEvent('PLAYER_REGEN_ENABLED') | |
| 54 self:RegisterEvent('PLAYER_REGEN_DISABLED') | |
| 55 | |
| 56 for name, info in pairs(blocks) do | |
| 57 local frame = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate') | |
| 58 frame.name = name | |
| 59 for k,v in pairs(info) do | |
| 60 print(name, k, '=', v) | |
| 61 frame[k] = v | |
| 62 end | |
| 63 | |
| 64 local debug = function(...) | |
| 65 print('|cFF0088FF<'..frame.name..'>|r', ...) | |
| 66 end | |
| 67 | |
| 68 if info.itemID then | |
| 69 local itemID = info.itemID | |
| 70 items[itemID] = { | |
| 71 count = 0, | |
| 72 frame = frame | |
| 73 } | |
| 74 frame.Update = function(block) | |
| 75 debug('Update [Item]') | |
| 76 if items[itemID].count >= 1 then | |
| 77 block.Icon:SetTexture(GetItemIcon(itemID)) | |
| 78 block.Label:SetFormattedText("%d", items[itemID].count) | |
| 79 return true | |
| 80 end | |
| 81 end | |
| 82 RegisterEvents(self, itemEvents) | |
| 83 elseif info.currencyID then | |
| 84 local currencyID = info.currencyID | |
| 85 frame.Update = function (block) | |
| 86 debug('Update [Currency]') | |
| 87 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(currencyID) | |
| 88 block.Icon:SetTexture(texture) | |
| 89 block.Label:SetFormattedText("%d / %d", earned, totalMax) | |
| 90 block:SetWidth(block.Icon:GetWidth() + block.Label:GetStringWidth() + 6) | |
| 91 return true | |
| 92 end | |
| 93 | |
| 94 RegisterEvents(frame, currencyEvents) | |
| 95 end | |
| 96 if info.zones then | |
| 97 RegisterEvents(frame, zoneEvents) | |
| 98 local zones = info.zones | |
| 99 local of = frame.Update | |
| 100 frame.Update = function(block) | |
| 101 debug('Update [Zone]') | |
| 102 local zone = self.zoneText | |
| 103 local canShow = (zone and block.zones[zone]) and true or false | |
| 104 if of then | |
| 105 canShow = canShow and of(frame) | |
| 106 end | |
| 107 return canShow | |
| 108 end | |
| 109 end | |
| 110 end | |
| 111 end | |
| 112 | |
| 113 function module:OnEvent (event, arg) | |
| 114 print(self:GetName(), 'OnEvent', event, arg) | |
| 115 self:Update() | |
| 116 end | |
| 117 local toUpdate = {} | |
| 118 local wipe = table.wipe | |
| 119 function module:Update(isBatchUpdate) | |
| 120 print(self:GetName(), 'Update()') | |
| 121 if InCombatLockdown() then | |
| 122 self:SetShown(false) | |
| 123 return | |
| 124 end | |
| 125 | |
| 126 | |
| 127 for itemID in pairs(items) do | |
| 128 items[itemID].count = 0 | |
| 129 end | |
| 130 self.zoneText = GetRealZoneText() | |
| 131 local canShow = false | |
| 132 | |
| 133 for i = 0, NUM_BAG_SLOTS do | |
| 134 local numSlots = GetContainerNumSlots(i) | |
| 135 for j = 1, numSlots do | |
| 136 local itemID = GetContainerItemID(i, j) | |
| 137 local texture, count = GetContainerItemInfo(i,j) | |
| 138 if items[itemID] then | |
| 139 items[itemID].count = items[itemID].count + (count or 1) | |
| 140 items[itemID].texture = texture | |
| 141 print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t') | |
| 142 items[itemID].frame.Icon:SetTexture(texture) | |
| 143 end | |
| 144 end | |
| 145 end | |
| 146 | |
| 147 for itemID, info in pairs(items) do | |
| 148 end | |
| 149 | |
| 150 local lastBlock | |
| 151 local totalWidth = 0 | |
| 152 for _, block in ipairs(self.Blocks) do | |
| 153 local blockIsShown = block:Update() or false | |
| 154 block:SetShown(blockIsShown) | |
| 155 canShow = canShow or blockIsShown | |
| 156 | |
| 157 | |
| 158 if block:IsShown() then | |
| 159 block:ClearAllPoints() | |
| 160 if lastBlock then | |
| 161 block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT') | |
| 162 else | |
| 163 block:SetPoint('TOPLEFT', self, 'TOPLEFT') | |
| 164 end | |
| 165 lastBlock = block | |
| 166 | |
| 167 block:SetHeight(24) | |
| 168 block:SetWidth(block.Icon:GetWidth() + block.Label:GetWidth()+4) | |
| 169 totalWidth = totalWidth + block:GetWidth() | |
| 170 end | |
| 171 print(block:IsShown(), '|cFF0088FF'..block.name..'|r', block:GetSize()) | |
| 172 | |
| 173 end | |
| 174 | |
| 175 self:SetWidth(totalWidth) | |
| 176 | |
| 177 self.needsUpdate = nil | |
| 178 print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize()) | |
| 179 self:SetShown(canShow) | |
| 180 VeneerWorldState:Reanchor(true) | |
| 181 end | |
| 182 | |
| 183 function module:OnUpdate() | |
| 184 if self.needsUpdate then | |
| 185 self:Update() | |
| 186 end | |
| 187 end | |
| 188 | |
| 189 function block:OnEvent(event, ...) | |
| 190 print('|cFF0088FF<'..self.name..'>|r', 'OnEvent', event, ...) | |
| 191 self:Update() | |
| 192 end | |
| 193 | |
| 194 function block:Setup() | |
| 195 | |
| 196 end |
