Nick@113: -- Nick@113: -- Created by IntelliJ IDEA. Nick@113: -- User: Nick Nick@113: -- Date: 3/25/2017 Nick@113: -- Time: 7:07 PM Nick@113: -- To change this template use File | Settings | File Templates. Nick@113: -- Nick@113: Nenue@125: local print = DEVIAN_WORKSPACE and function(...) print('Currency', ...) end or nop Nenue@115: local profileUpdate, needsUpdate Nick@113: Nenue@123: Nenue@123: local itemBlock = {} Nenue@123: local currencyBlock = {} Nenue@123: Nenue@123: Nick@113: local zoneEvents = { Nick@113: "ZONE_CHANGED_NEW_AREA", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED" Nick@113: } Nick@113: local currencyEvents = { Nick@113: 'CURRENCY_DISPLAY_UPDATE', 'CHAT_MSG_CURRENCY' Nick@113: } Nick@113: local itemEvents = { Nick@113: 'CHAT_MSG_LOOT', 'BAG_UPDATE' Nick@113: } Nick@113: Nick@113: local blocks = { Nick@113: ["Ancient Mana"] = { Nick@113: currencyID = 1155, Nenue@116: showMax = true, Nick@113: zones = { Nick@113: ['Suramar'] = true, Nenue@116: }, Nick@113: }, Nick@113: ["Blood of Sargeras"] = { Nick@113: itemID = 124124, Nenue@116: }, Nenue@116: ["Legionfall War Supplies"] = { Nenue@116: currencyID = 1342, Nenue@125: zones = { Nenue@125: ["The Broken Shore"] = true Nenue@125: } Nenue@116: }, Nenue@116: ["Nethershard"] = { Nenue@116: currencyID = 1226, Nenue@125: zones = { Nenue@125: ["The Broken Shore"] = true Nenue@125: } Nenue@123: }, Nenue@123: ["Veiled Argunite"] = { Nenue@123: currencyID = 1508, Nenue@125: zones = { Nenue@125: ["Antoran Wastes"] = true, Nenue@125: ["Krokuun"] = true, Nenue@125: ["MacAree"] = true, Nenue@125: } Nenue@123: }, Nick@113: } Nenue@115: local items, currencies = {}, {} Nick@113: Nick@113: Nenue@115: VeneerCurrencyMixin = { Nenue@115: Blocks = {}, Nenue@115: HideCombat = true, Nenue@115: EventList = {'PLAYER_ENTERING_WORLD'}, Nenue@115: moduleName = 'Currency Watch', Nenue@115: anchorPoint = 'TOP', Nenue@116: anchorPriority = 2, Nenue@115: } Nenue@115: VeneerCurrencyBlockMixin = {} Nenue@115: local module = VeneerCurrencyMixin Nenue@115: local block = VeneerCurrencyBlockMixin Nick@113: Nick@113: Nick@113: Nick@113: local function RegisterEvents (frame, events) Nick@113: for _, event in ipairs(events) do Nick@113: print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event) Nick@113: frame:RegisterEvent(event) Nick@113: end Nick@113: end Nick@113: Nenue@125: function module:Setup() Nenue@125: self:Update() Nenue@125: end Nenue@125: Nick@113: function module:OnLoad () Nenue@115: Veneer:AddHandler(self) Nick@113: Nick@113: for name, info in pairs(blocks) do Nenue@125: local block = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate') Nenue@125: block.name = name Nick@113: for k,v in pairs(info) do Nick@113: print(name, k, '=', v) Nenue@125: block[k] = v Nick@113: end Nick@113: Nenue@125: block.debug = function(...) Nenue@125: print('|cFF0088FF<'..block.name..'>|r', ...) Nick@113: end Nenue@125: block.id = info.itemID or info.currencyID Nenue@123: Nick@113: Nick@113: if info.itemID then Nick@113: local itemID = info.itemID Nick@113: items[itemID] = { Nick@113: count = 0, Nenue@125: frame = block Nick@113: } Nenue@125: block.Update = itemBlock.Update Nick@113: RegisterEvents(self, itemEvents) Nick@113: elseif info.currencyID then Nick@113: local currencyID = info.currencyID Nenue@125: block.Update = currencyBlock.Update Nenue@125: RegisterEvents(block, currencyEvents) Nick@113: end Nenue@123: Nenue@123: Nenue@123: Nick@113: if info.zones then Nenue@125: RegisterEvents(block, zoneEvents) Nick@113: local zones = info.zones Nenue@125: local of = block.Update Nenue@125: function block:Update(zone, subZone) Nenue@125: block.debug('Update [Zone]', zone, subZone) Nenue@125: local canShow = ((zone and self.zones[zone]) or (subZone and self.zones[subZone])) and true or false Nick@113: if of then Nenue@125: canShow = canShow and of(self) Nick@113: end Nick@113: return canShow Nick@113: end Nick@113: end Nick@113: end Nick@113: end Nick@113: Nick@113: function module:OnEvent (event, arg) Nick@113: print(self:GetName(), 'OnEvent', event, arg) Nick@113: self:Update() Nick@113: end Nick@113: local toUpdate = {} Nick@113: local wipe = table.wipe Nick@113: function module:Update(isBatchUpdate) Nick@113: print(self:GetName(), 'Update()') Nick@113: if InCombatLockdown() then Nick@113: self:SetShown(false) Nick@113: return Nick@113: end Nick@113: Nick@113: Nick@113: for itemID in pairs(items) do Nick@113: items[itemID].count = 0 Nick@113: end Nenue@125: self.realZoneText = GetRealZoneText() Nenue@125: self.subZoneText = GetSubZoneText() Nick@113: local canShow = false Nick@113: Nick@113: for i = 0, NUM_BAG_SLOTS do Nick@113: local numSlots = GetContainerNumSlots(i) Nick@113: for j = 1, numSlots do Nick@113: local itemID = GetContainerItemID(i, j) Nick@113: local texture, count = GetContainerItemInfo(i,j) Nick@113: if items[itemID] then Nick@113: items[itemID].count = items[itemID].count + (count or 1) Nenue@115: if not items[itemID].texture then Nenue@115: items[itemID].texture = texture Nenue@115: print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t') Nenue@115: items[itemID].frame.Icon:SetTexture(texture) Nenue@115: end Nick@113: end Nick@113: end Nick@113: end Nick@113: Nenue@115: Nick@113: Nick@113: local lastBlock Nick@113: local totalWidth = 0 Nick@113: for _, block in ipairs(self.Blocks) do Nenue@125: local blockIsShown = block:Update(self.realZoneText, self.subZoneText) or false Nick@113: block:SetShown(blockIsShown) Nick@113: canShow = canShow or blockIsShown Nick@113: Nick@113: Nenue@125: if blockIsShown then Nick@113: block:ClearAllPoints() Nick@113: if lastBlock then Nick@113: block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT') Nick@113: else Nick@113: block:SetPoint('TOPLEFT', self, 'TOPLEFT') Nick@113: end Nick@113: lastBlock = block Nick@113: Nick@113: block:SetHeight(24) Nenue@123: block:SetWidth(block.Icon:GetWidth() + block.Label:GetStringWidth()+4) Nick@113: totalWidth = totalWidth + block:GetWidth() Nick@113: end Nick@113: print(block:IsShown(), '|cFF0088FF'..block.name..'|r', block:GetSize()) Nick@113: end Nick@113: Nenue@115: self:UpdateProfile() Nick@113: self:SetWidth(totalWidth) Nick@113: Nenue@115: needsUpdate = nil Nick@113: print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize()) Nick@113: self:SetShown(canShow) Nenue@115: Veneer:DynamicReanchor() Nenue@115: end Nenue@115: Nenue@115: function module:UpdateProfile() Nenue@115: if not self.profile then Nenue@115: profileUpdate = true Nenue@115: return Nenue@115: end Nenue@115: Nenue@115: for itemID, info in pairs(items) do Nenue@115: self.profile.Items = self.profile.Items or {} Nenue@115: self.profile.Items[itemID] = info Nenue@115: end Nick@113: end Nick@113: Nick@113: function module:OnUpdate() Nenue@115: if needsUpdate then Nenue@125: self:Update(GetRealZoneText(), GetSubZoneText()) Nenue@115: elseif profileUpdate then Nenue@115: self:UpdateProfile() Nick@113: end Nenue@115: Nick@113: end Nick@113: Nick@114: function block:OnEnter() Nick@114: if not InCombatLockdown() then Nick@114: GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT"); Nick@114: if self.currencyID then Nick@114: GameTooltip:SetCurrencyTokenByID(self.currencyID); Nick@114: else Nick@114: GameTooltip:SetItemByID(self.itemID); Nick@114: end Nick@114: GameTooltip:Show(); Nick@114: end Nick@114: end Nick@114: function block:OnLeave() Nick@114: if GameTooltip:IsOwned(self) then Nick@114: GameTooltip_Hide() Nick@114: end Nick@114: end Nick@114: Nick@113: function block:OnEvent(event, ...) Nick@113: print('|cFF0088FF<'..self.name..'>|r', 'OnEvent', event, ...) Nenue@125: Nenue@125: self:Update(GetRealZoneText(), GetSubZoneText()) Nick@113: end Nick@113: Nick@113: function block:Setup() Nick@113: Nick@113: end Nenue@125: function itemBlock:Update(zone, subZone) Nenue@125: self.debug('Update [Item]', zone, subZone) Nenue@123: if items[self.itemID].count >= 1 then Nenue@123: self.Icon:SetTexture(GetItemIcon(self.id)) Nenue@123: self.Label:SetFormattedText("%d", items[self.id].count) Nenue@123: return true Nenue@123: end Nenue@125: return false Nenue@123: end Nenue@123: Nenue@125: function currencyBlock:Update(zone, subZone) Nenue@125: self.debug('Update [Currency]', zone, subZone) Nenue@123: local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(self.id) Nenue@123: Nenue@123: self.Icon:SetTexture(texture) Nenue@123: if self.showMax then Nenue@123: self.Label:SetFormattedText("%d / %d", earned, totalMax) Nenue@123: else Nenue@123: self.Label:SetFormattedText("%d", earned) Nenue@123: end Nenue@123: Nenue@123: --self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6) Nenue@123: return true Nenue@123: end