Mercurial > wow > buffalo2
view Modules/Currency.lua @ 122:ea2c616a3b4f
Standardize anchor variables
- anchorGroup sets general position, defers to anchorPoint
- anchorPoint and anchorFrom are used in SetPoint, deferring to anchorGroup and its inverse
Artifact Power:
- scan and update triggers trimmed down
BuffFrame:
- extra values can be right clicked to hide for particular auras
LFG:
- Desolate Host link placed above Sisters when searching for best cheevos
TalkingHead
- Re-enable TalkingHeadFrame click behaviour
author | Nenue |
---|---|
date | Mon, 21 Aug 2017 22:15:46 -0400 |
parents | ddfe19d70a34 |
children | b3c0258b419d |
line wrap: on
line source
-- -- 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 profileUpdate, needsUpdate 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, showMax = true, zones = { ['Suramar'] = true, ["Sashj'tar Ruins"] = true, ["Faronaar Ruins"] = true, ["Halls of the Eclipse"] = true, ["Shal'aran"] = true, ["The Fel Breach"] = true, }, }, ["Blood of Sargeras"] = { itemID = 124124, }, ["Legionfall War Supplies"] = { currencyID = 1342, }, ["Nethershard"] = { currencyID = 1226, } } local items, currencies = {}, {} VeneerCurrencyMixin = { Blocks = {}, HideCombat = true, EventList = {'PLAYER_ENTERING_WORLD'}, moduleName = 'Currency Watch', anchorPoint = 'TOP', anchorPriority = 2, } VeneerCurrencyBlockMixin = {} local module = VeneerCurrencyMixin local block = VeneerCurrencyBlockMixin 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 () Veneer:AddHandler(self) 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) if self.showMax then block.Label:SetFormattedText("%d / %d", earned, totalMax) else block.Label:SetFormattedText("%d", earned) end 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) if not items[itemID].texture then 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 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:UpdateProfile() self:SetWidth(totalWidth) needsUpdate = nil print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize()) self:SetShown(canShow) Veneer:DynamicReanchor() end function module:UpdateProfile() if not self.profile then profileUpdate = true return end for itemID, info in pairs(items) do self.profile.Items = self.profile.Items or {} self.profile.Items[itemID] = info end end function module:OnUpdate() if needsUpdate then self:Update() elseif profileUpdate then self:UpdateProfile() end end function block:OnEnter() if not InCombatLockdown() then GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT"); if self.currencyID then GameTooltip:SetCurrencyTokenByID(self.currencyID); else GameTooltip:SetItemByID(self.itemID); end GameTooltip:Show(); end end function block:OnLeave() if GameTooltip:IsOwned(self) then GameTooltip_Hide() end end function block:OnEvent(event, ...) print('|cFF0088FF<'..self.name..'>|r', 'OnEvent', event, ...) self:Update() end function block:Setup() end