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: Nick@113: local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) 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, Nick@113: ["Sashj'tar Ruins"] = true, Nenue@116: ["Faronaar Ruins"] = true, Nenue@116: ["Halls of the Eclipse"] = true, Nenue@116: ["Shal'aran"] = true, Nenue@116: ["The Fel Breach"] = 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@116: }, Nenue@116: ["Nethershard"] = { Nenue@116: currencyID = 1226, Nenue@123: }, Nenue@123: ["Veiled Argunite"] = { Nenue@123: currencyID = 1508, Nenue@123: }, Nenue@123: ["Argus Waystone"] = { Nenue@123: currencyID = 1506, Nick@113: } 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: Nick@113: function module:OnLoad () Nenue@115: Veneer:AddHandler(self) Nick@113: Nick@113: for name, info in pairs(blocks) do Nick@113: local frame = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate') Nick@113: frame.name = name Nick@113: for k,v in pairs(info) do Nick@113: print(name, k, '=', v) Nick@113: frame[k] = v Nick@113: end Nick@113: Nenue@123: frame.debug = function(...) Nick@113: print('|cFF0088FF<'..frame.name..'>|r', ...) Nick@113: end Nenue@123: frame.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, Nick@113: frame = frame Nick@113: } Nenue@123: frame.Update = itemBlock.Update Nick@113: RegisterEvents(self, itemEvents) Nick@113: elseif info.currencyID then Nick@113: local currencyID = info.currencyID Nenue@123: frame.Update = currencyBlock.Update Nick@113: RegisterEvents(frame, currencyEvents) Nick@113: end Nenue@123: Nenue@123: Nenue@123: Nick@113: if info.zones then Nick@113: RegisterEvents(frame, zoneEvents) Nick@113: local zones = info.zones Nick@113: local of = frame.Update Nick@113: frame.Update = function(block) Nenue@123: frame.debug('Update [Zone]') Nick@113: local zone = self.zoneText Nick@113: local canShow = (zone and block.zones[zone]) and true or false Nick@113: if of then Nick@113: canShow = canShow and of(frame) 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 Nick@113: self.zoneText = GetRealZoneText() 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 Nick@113: local blockIsShown = block:Update() or false Nick@113: block:SetShown(blockIsShown) Nick@113: canShow = canShow or blockIsShown Nick@113: Nick@113: Nick@113: if block:IsShown() 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 Nick@113: self:Update() 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, ...) Nick@113: self:Update() Nick@113: end Nick@113: Nick@113: function block:Setup() Nick@113: Nick@113: end Nenue@123: function itemBlock:Update() Nenue@123: self.debug('Update [Item]') 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@123: end Nenue@123: Nenue@123: function currencyBlock:Update() Nenue@123: self.debug('Update [Currency]') 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