# HG changeset patch # User Nick@Zahhak # Date 1490523918 14400 # Node ID 2105b6e5095f8dc1ad44d6edee397cb156c602aa # Parent 7c77fde3628749bd4edbfa3802d0b64b120d9710 - Added Blood of Sargeras to currency list - Fixed panel ordering issues when a module is loaded on the fly. diff -r 7c77fde36287 -r 2105b6e5095f Modules/Currency.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Modules/Currency.lua Sun Mar 26 06:25:18 2017 -0400 @@ -0,0 +1,196 @@ +-- +-- Created by IntelliJ IDEA. +-- User: Nick +-- Date: 3/25/2017 +-- Time: 7:07 PM +-- To change this template use File | Settings | File Templates. +-- + +local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop + +local zoneEvents = { + "ZONE_CHANGED_NEW_AREA", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED" +} +local currencyEvents = { + 'CURRENCY_DISPLAY_UPDATE', 'CHAT_MSG_CURRENCY' +} +local itemEvents = { + 'CHAT_MSG_LOOT', 'BAG_UPDATE' +} + +local blocks = { + ["Ancient Mana"] = { + currencyID = 1155, + zones = { + ['Suramar'] = true, + ["Sashj'tar Ruins"] = true, + ["Faronaar Ruins"] = true + } + }, + ["Blood of Sargeras"] = { + itemID = 124124, + } +} +local items = {} + + +VeneerWorldStateCurrencyMixin = { Blocks = {} } +VeneerWorldStateCurrencyBlockMixin = {} +local module = VeneerWorldStateCurrencyMixin +local block = VeneerWorldStateCurrencyBlockMixin + + + +local function RegisterEvents (frame, events) + for _, event in ipairs(events) do + print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event) + frame:RegisterEvent(event) + end +end + +function module:OnLoad () + self:RegisterEvent("PLAYER_ENTERING_WORLD"); + self:RegisterEvent('PLAYER_REGEN_ENABLED') + self:RegisterEvent('PLAYER_REGEN_DISABLED') + + for name, info in pairs(blocks) do + local frame = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate') + frame.name = name + for k,v in pairs(info) do + print(name, k, '=', v) + frame[k] = v + end + + local debug = function(...) + print('|cFF0088FF<'..frame.name..'>|r', ...) + end + + if info.itemID then + local itemID = info.itemID + items[itemID] = { + count = 0, + frame = frame + } + frame.Update = function(block) + debug('Update [Item]') + if items[itemID].count >= 1 then + block.Icon:SetTexture(GetItemIcon(itemID)) + block.Label:SetFormattedText("%d", items[itemID].count) + return true + end + end + RegisterEvents(self, itemEvents) + elseif info.currencyID then + local currencyID = info.currencyID + frame.Update = function (block) + debug('Update [Currency]') + local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(currencyID) + block.Icon:SetTexture(texture) + block.Label:SetFormattedText("%d / %d", earned, totalMax) + block:SetWidth(block.Icon:GetWidth() + block.Label:GetStringWidth() + 6) + return true + end + + RegisterEvents(frame, currencyEvents) + end + if info.zones then + RegisterEvents(frame, zoneEvents) + local zones = info.zones + local of = frame.Update + frame.Update = function(block) + debug('Update [Zone]') + local zone = self.zoneText + local canShow = (zone and block.zones[zone]) and true or false + if of then + canShow = canShow and of(frame) + end + return canShow + end + end + end +end + +function module:OnEvent (event, arg) + print(self:GetName(), 'OnEvent', event, arg) + self:Update() +end +local toUpdate = {} +local wipe = table.wipe +function module:Update(isBatchUpdate) + print(self:GetName(), 'Update()') + if InCombatLockdown() then + self:SetShown(false) + return + end + + + for itemID in pairs(items) do + items[itemID].count = 0 + end + self.zoneText = GetRealZoneText() + local canShow = false + + for i = 0, NUM_BAG_SLOTS do + local numSlots = GetContainerNumSlots(i) + for j = 1, numSlots do + local itemID = GetContainerItemID(i, j) + local texture, count = GetContainerItemInfo(i,j) + if items[itemID] then + items[itemID].count = items[itemID].count + (count or 1) + items[itemID].texture = texture + print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t') + items[itemID].frame.Icon:SetTexture(texture) + end + end + end + + for itemID, info in pairs(items) do + end + + local lastBlock + local totalWidth = 0 + for _, block in ipairs(self.Blocks) do + local blockIsShown = block:Update() or false + block:SetShown(blockIsShown) + canShow = canShow or blockIsShown + + + if block:IsShown() then + block:ClearAllPoints() + if lastBlock then + block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT') + else + block:SetPoint('TOPLEFT', self, 'TOPLEFT') + end + lastBlock = block + + block:SetHeight(24) + block:SetWidth(block.Icon:GetWidth() + block.Label:GetWidth()+4) + totalWidth = totalWidth + block:GetWidth() + end + print(block:IsShown(), '|cFF0088FF'..block.name..'|r', block:GetSize()) + + end + + self:SetWidth(totalWidth) + + self.needsUpdate = nil + print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize()) + self:SetShown(canShow) + VeneerWorldState:Reanchor(true) +end + +function module:OnUpdate() + if self.needsUpdate then + self:Update() + end +end + +function block:OnEvent(event, ...) + print('|cFF0088FF<'..self.name..'>|r', 'OnEvent', event, ...) + self:Update() +end + +function block:Setup() + +end diff -r 7c77fde36287 -r 2105b6e5095f Modules/Currency.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Modules/Currency.xml Sun Mar 26 06:25:18 2017 -0400 @@ -0,0 +1,39 @@ + + +