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: Nenue@133: local events = { Nenue@133: 'CHAT_MSG_LOOT', Nenue@133: "ZONE_CHANGED_NEW_AREA", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED", Nenue@133: 'BAG_UPDATE', 'CURRENCY_DISPLAY_UPDATE', 'CHAT_MSG_CURRENCY', 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@128: ["Broken Shore"] = true Nenue@125: } Nenue@116: }, Nenue@116: ["Nethershard"] = { Nenue@116: currencyID = 1226, Nenue@125: zones = { Nenue@128: ["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@128: self:Reanchor() Nenue@125: end Nenue@125: Nick@113: function module:OnLoad () Nenue@115: Veneer:AddHandler(self) Nick@113: Nenue@133: for _, event in ipairs(events) do Nenue@133: self:RegisterEvent(event) Nenue@133: end Nenue@133: Nenue@133: 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: Nenue@133: block:SetScript('OnEnter', itemBlock.OnEnter or block.OnEnter) Nenue@133: block:SetScript('OnLeave', itemBlock.OnLeave or block.OnLeave) 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: elseif info.currencyID then Nick@113: local currencyID = info.currencyID Nenue@125: block.Update = currencyBlock.Update Nick@113: end Nenue@123: Nenue@123: Nenue@123: Nick@113: if info.zones then Nick@113: local zones = info.zones Nenue@125: local of = block.Update Nenue@128: function block:Update() Nenue@126: Nenue@126: local zone = GetRealZoneText() Nenue@126: local subZone = GetSubZoneText() Nenue@125: local canShow = ((zone and self.zones[zone]) or (subZone and self.zones[subZone])) and true or false Nenue@128: block.debug('Zone Check', zone, subZone, canShow) 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 Nenue@131: Nenue@131: self:RegisterEvent('PLAYER_REGEN_ENABLED') Nenue@131: self:RegisterEvent('PLAYER_REGEN_DISABLED') Nick@113: end Nick@113: Nick@113: function module:OnEvent (event, arg) Nenue@131: --print(self:GetName(), 'OnEvent', event, arg) Nenue@128: self:Update() Nick@113: end Nenue@126: Nenue@128: function module:Update() Nenue@131: --print(self:GetName(), 'Reanchor()') 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@126: Nick@113: local canShow = false Nenue@128: if BagBrother then Nenue@128: for i, bag in pairs(BagBrother.Player) do Nenue@128: if type(bag) == 'table' then Nenue@128: --print(i) Nenue@128: for j, item in pairs(bag) do Nenue@128: local itemID, count = string.match(item ,"^(%d+):.+;(%d*)") Nenue@128: itemID = tonumber(itemID) Nenue@128: if itemID then Nenue@128: --print(j, itemID) Nenue@128: count = tonumber(count) Nenue@128: if count and count >= 1 then Nenue@128: local texture = GetItemIcon(itemID) Nenue@128: --print(itemID) Nenue@128: Nenue@128: if items[itemID] then Nenue@128: items[itemID].count = items[itemID].count + (count or 1) Nenue@128: if not items[itemID].texture then Nenue@128: items[itemID].texture = texture Nenue@128: --print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t') Nenue@128: items[itemID].frame.Icon:SetTexture(texture) Nenue@128: end Nenue@128: end Nenue@128: end Nenue@128: end Nenue@128: end Nenue@128: end Nenue@128: Nenue@128: end Nenue@128: else Nenue@128: for i = 0, NUM_BAG_SLOTS do Nenue@128: local numSlots = GetContainerNumSlots(i) Nenue@128: for j = 1, numSlots do Nenue@128: local itemID = GetContainerItemID(i, j) Nenue@128: local texture, count = GetContainerItemInfo(i,j) Nenue@128: if items[itemID] then Nenue@133: Nenue@128: items[itemID].count = items[itemID].count + (count or 1) Nenue@128: if not items[itemID].texture then Nenue@128: items[itemID].texture = texture Nenue@128: print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t') Nenue@128: items[itemID].frame.Icon:SetTexture(texture) Nenue@128: end 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@128: local blockIsShown = block:Update() Nenue@128: print(block.name, blockIsShown) 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 Nenue@126: print('|cFF0088FF'..block.name..'|r', block:IsShown(), 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: Nenue@126: function itemBlock:Update() 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@126: function currencyBlock:Update() 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: return true Nenue@123: end