WoWInterface SVN KuiNameplates

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /trunk
    from Rev 152 to Rev 155
    Reverse comparison

Rev 152 → Rev 155

Kui_Nameplates_Auras/auras.lua
3,17 → 3,14
local kui = LibStub('Kui-1.0')
local mod = addon:NewModule('Auras', 'AceEvent-3.0')
 
local currentFrame = nil
-- combat log events to listen to for fading auras
local auraEvents = {
-- ['SPELL_DISPEL'] = true,
['SPELL_AURA_REMOVED'] = true,
['SPELL_AURA_BROKEN'] = true,
['SPELL_AURA_BROKEN_SPELL'] = true,
}
 
--[[ TODO
 
Make work on mouseover
 
If only two containers are ever displayed, just make two containers and
move them around rather than making 1 container for every nameplate
 
]]
 
local function ArrangeButtons(self)
local pv, pc
self.visible = 0
81,7 → 78,7
end
 
if timeLeft <= 0 then
self:Hide()
self.time:SetText('0')
end
 
self.elapsed = .5
210,31 → 207,42
end
 
-------------------------------------------------------------- event handlers --
function mod:PLAYER_TARGET_CHANGED()
local frame = addon:GetNameplate(UnitGUID('target'), nil)
function mod:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
local castTime, event, _, guid, name, _, _, targetGUID, targetName = ...
if not guid then return end
if not auraEvents[event] then return end
if guid ~= UnitGUID('player') then return end
 
if currentFrame and (not frame or frame ~= currentFrame) then
-- hide auras on the previous target
currentFrame.auras:Hide()
end
--print(event..' from '..name..' on '..targetName)
 
if frame ~= currentFrame then
currentFrame = frame
end
-- fetch the subject's nameplate
local f = addon:GetNameplate(targetGUID, targetName)
if not f or not f.auras then return end
 
if frame then
-- scan auras on the new target
self:UNIT_AURA('UNIT_AURA', 'target')
--print('(frame for guid: '..targetGUID..')')
 
local spId = select(12, ...)
 
if f.auras.spellIds[spId] then
f.auras.spellIds[spId]:Hide()
end
end
 
function mod:PLAYER_TARGET_CHANGED()
self:UNIT_AURA('UNIT_AURA', 'target')
end
 
function mod:UPDATE_MOUSEOVER_UNIT()
self:UNIT_AURA('UNIT_AURA', 'mouseover')
end
 
function mod:UNIT_AURA(event, unit)
if unit ~= 'target' then return end
 
-- select the targeted nameplate
local frame = addon:GetNameplate(UnitGUID(unit), nil)
if not frame or not frame.auras then return end
if not frame or not frame.auras or frame.trivial then return end
 
--print('Scan auras on unit: '..unit)
 
local filter = 'PLAYER '
if UnitIsFriend(unit, 'player') then
filter = filter..'HELPFUL'
242,13 → 250,18
filter = filter..'HARMFUL'
end
 
-- hide currently displayed auras
local _,button
for _,button in pairs(frame.auras.spellIds) do
button:Hide()
end
 
for i = 0,40 do
-- TODO optimise
-- TODO find auras which are no longer present
local name, _, icon, count, _, duration, expirationTime, _, _, _, spellId = UnitAura('target', i, filter)
local name, _, icon, count, _, duration, expirationTime, _, _, _, spellId = UnitAura(unit, i, filter)
 
if name and
(not self.db.profile.display.useWhitelist or
(not self.db.profile.behav.useWhitelist or
whitelist[spellId]) and
(duration >= self.db.profile.display.lengthMin) and
(self.db.profile.display.lengthMax == -1 or
259,13 → 272,6
button:Show()
end
end
 
if frame ~= currentFrame then
if currentFrame then
currentFrame.auras:Hide()
end
currentFrame = frame
end
end
 
---------------------------------------------------- Post db change functions --
300,6 → 306,7
name = 'Timer threshold (s)',
desc = 'Timer text will be displayed on auras when their remaining length is less than or equal to this value. -1 to always display timer.',
type = 'range',
order = 10,
min = -1,
softMax = 180,
step = 1
308,6 → 315,7
name = 'Effect length minimum (s)',
desc = 'Auras with a total duration of less than this value will never be displayed. 0 to disable.',
type = 'range',
order = 20,
min = 0,
softMax = 60,
step = 1
316,14 → 324,27
name = 'Effect length maximum (s)',
desc = 'Auras with a total duration greater than this value will never be displayed. -1 to disable.',
type = 'range',
order = 30,
min = -1,
softMax= 1800,
step = 1
},
 
}
},
behav = {
name = 'Behaviour',
type = 'group',
inline = true,
disabled = function()
return not self.db.profile.enabled
end,
args = {
useWhitelist = {
name = 'Use whitelist',
desc = 'Only display spells which your class needs to keep track of for PVP or an effective DPS rotation. Most passive effects are excluded.',
type = 'toggle'
type = 'toggle',
order = 0,
},
}
}
338,6 → 359,8
timerThreshold = 20,
lengthMin = 0,
lengthMax = -1,
},
behav = {
useWhitelist = true,
}
}
357,6 → 380,8
 
self:RegisterEvent('UNIT_AURA')
self:RegisterEvent('PLAYER_TARGET_CHANGED')
self:RegisterEvent('UPDATE_MOUSEOVER_UNIT')
self:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED')
 
local _, frame
for _, frame in pairs(addon.frameList) do
369,6 → 394,8
function mod:OnDisable()
self:UnregisterEvent('UNIT_AURA')
self:UnregisterEvent('PLAYER_TARGET_CHANGED')
self:UnregisterEvent('UPDATE_MOUSEOVER_UNIT')
self:UnregisterEvent('COMBAT_LOG_EVENT_UNFILTERED')
 
local _, frame
for _, frame in pairs(addon.frameList) do
Kui_Nameplates/lib/embeds.xml
9,6 → 9,7
<Include file="Ace3\AceDBOptions-3.0\AceDBOptions-3.0.xml"/>
<Include file="Ace3\AceGUI-3.0\AceGUI-3.0.xml"/>
<Include file="Ace3\AceConfig-3.0\AceConfig-3.0.xml"/>
<Include file="Ace3\AceTimer-3.0\AceTimer-3.0.xml"/>
 
<Include file="LibSharedMedia-3.0\lib.xml"/>
<Include file="Ace3\AceGUI-3.0-SharedMediaWidgets\widget.xml"/>
Kui_Nameplates/lib/Ace3/AceTimer-3.0/AceTimer-3.0.xml New file
0,0 → 1,4
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="AceTimer-3.0.lua"/>
</Ui>
\ No newline at end of file
Kui_Nameplates/lib/Ace3/AceTimer-3.0/AceTimer-3.0.lua New file
0,0 → 1,274
--- **AceTimer-3.0** provides a central facility for registering timers.
-- AceTimer supports one-shot timers and repeating timers. All timers are stored in an efficient
-- data structure that allows easy dispatching and fast rescheduling. Timers can be registered
-- or canceled at any time, even from within a running timer, without conflict or large overhead.\\
-- AceTimer is currently limited to firing timers at a frequency of 0.01s. This constant may change
-- in the future, but for now it's required as animations with lower frequencies are buggy.
--
-- All `:Schedule` functions will return a handle to the current timer, which you will need to store if you
-- need to cancel the timer you just registered.
--
-- **AceTimer-3.0** can be embeded into your addon, either explicitly by calling AceTimer:Embed(MyAddon) or by
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
-- and can be accessed directly, without having to explicitly call AceTimer itself.\\
-- It is recommended to embed AceTimer, otherwise you'll have to specify a custom `self` on all calls you
-- make into AceTimer.
-- @class file
-- @name AceTimer-3.0
-- @release $Id: AceTimer-3.0.lua 1079 2013-02-17 19:56:06Z funkydude $
 
local MAJOR, MINOR = "AceTimer-3.0", 16 -- Bump minor on changes
local AceTimer, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
 
if not AceTimer then return end -- No upgrade needed
 
AceTimer.frame = AceTimer.frame or CreateFrame("Frame", "AceTimer30Frame") -- Animation parent
AceTimer.inactiveTimers = AceTimer.inactiveTimers or {} -- Timer recycling storage
AceTimer.activeTimers = AceTimer.activeTimers or {} -- Active timer list
 
-- Lua APIs
local type, unpack, next, error, pairs, tostring, select = type, unpack, next, error, pairs, tostring, select
 
-- Upvalue our private data
local inactiveTimers = AceTimer.inactiveTimers
local activeTimers = AceTimer.activeTimers
 
local function OnFinished(self)
local id = self.id
if type(self.func) == "string" then
-- We manually set the unpack count to prevent issues with an arg set that contains nil and ends with nil
-- e.g. local t = {1, 2, nil, 3, nil} print(#t) will result in 2, instead of 5. This fixes said issue.
self.object[self.func](self.object, unpack(self.args, 1, self.argsCount))
else
self.func(unpack(self.args, 1, self.argsCount))
end
 
-- If the id is different it means that the timer was already cancelled
-- and has been used to create a new timer during the OnFinished callback.
if not self.looping and id == self.id then
activeTimers[self.id] = nil
self.args = nil
inactiveTimers[self] = true
end
end
 
local function new(self, loop, func, delay, ...)
local timer = next(inactiveTimers)
if timer then
inactiveTimers[timer] = nil
else
local anim = AceTimer.frame:CreateAnimationGroup()
timer = anim:CreateAnimation()
timer:SetScript("OnFinished", OnFinished)
end
 
-- Very low delays cause the animations to fail randomly.
-- A limited resolution of 0.01 seems reasonable.
if delay < 0.01 then
delay = 0.01
end
 
timer.object = self
timer.func = func
timer.looping = loop
timer.args = {...}
timer.argsCount = select("#", ...)
 
local anim = timer:GetParent()
if loop then
anim:SetLooping("REPEAT")
else
anim:SetLooping("NONE")
end
timer:SetDuration(delay)
 
local id = tostring(timer.args)
timer.id = id
activeTimers[id] = timer
 
anim:Play()
return id
end
 
--- Schedule a new one-shot timer.
-- The timer will fire once in `delay` seconds, unless canceled before.
-- @param callback Callback function for the timer pulse (funcref or method name).
-- @param delay Delay for the timer, in seconds.
-- @param ... An optional, unlimited amount of arguments to pass to the callback function.
-- @usage
-- MyAddOn = LibStub("AceAddon-3.0"):NewAddon("MyAddOn", "AceTimer-3.0")
--
-- function MyAddOn:OnEnable()
-- self:ScheduleTimer("TimerFeedback", 5)
-- end
--
-- function MyAddOn:TimerFeedback()
-- print("5 seconds passed")
-- end
function AceTimer:ScheduleTimer(func, delay, ...)
if not func or not delay then
error(MAJOR..": ScheduleTimer(callback, delay, args...): 'callback' and 'delay' must have set values.", 2)
end
if type(func) == "string" then
if type(self) ~= "table" then
error(MAJOR..": ScheduleTimer(callback, delay, args...): 'self' - must be a table.", 2)
elseif not self[func] then
error(MAJOR..": ScheduleTimer(callback, delay, args...): Tried to register '"..func.."' as the callback, but it doesn't exist in the module.", 2)
end
end
return new(self, nil, func, delay, ...)
end
 
--- Schedule a repeating timer.
-- The timer will fire every `delay` seconds, until canceled.
-- @param callback Callback function for the timer pulse (funcref or method name).
-- @param delay Delay for the timer, in seconds.
-- @param ... An optional, unlimited amount of arguments to pass to the callback function.
-- @usage
-- MyAddOn = LibStub("AceAddon-3.0"):NewAddon("MyAddOn", "AceTimer-3.0")
--
-- function MyAddOn:OnEnable()
-- self.timerCount = 0
-- self.testTimer = self:ScheduleRepeatingTimer("TimerFeedback", 5)
-- end
--
-- function MyAddOn:TimerFeedback()
-- self.timerCount = self.timerCount + 1
-- print(("%d seconds passed"):format(5 * self.timerCount))
-- -- run 30 seconds in total
-- if self.timerCount == 6 then
-- self:CancelTimer(self.testTimer)
-- end
-- end
function AceTimer:ScheduleRepeatingTimer(func, delay, ...)
if not func or not delay then
error(MAJOR..": ScheduleRepeatingTimer(callback, delay, args...): 'callback' and 'delay' must have set values.", 2)
end
if type(func) == "string" then
if type(self) ~= "table" then
error(MAJOR..": ScheduleRepeatingTimer(callback, delay, args...): 'self' - must be a table.", 2)
elseif not self[func] then
error(MAJOR..": ScheduleRepeatingTimer(callback, delay, args...): Tried to register '"..func.."' as the callback, but it doesn't exist in the module.", 2)
end
end
return new(self, true, func, delay, ...)
end
 
--- Cancels a timer with the given id, registered by the same addon object as used for `:ScheduleTimer`
-- Both one-shot and repeating timers can be canceled with this function, as long as the `id` is valid
-- and the timer has not fired yet or was canceled before.
-- @param id The id of the timer, as returned by `:ScheduleTimer` or `:ScheduleRepeatingTimer`
function AceTimer:CancelTimer(id)
local timer = activeTimers[id]
if not timer then return false end
 
local anim = timer:GetParent()
anim:Stop()
 
activeTimers[id] = nil
timer.args = nil
inactiveTimers[timer] = true
return true
end
 
--- Cancels all timers registered to the current addon object ('self')
function AceTimer:CancelAllTimers()
for k,v in pairs(activeTimers) do
if v.object == self then
AceTimer.CancelTimer(self, k)
end
end
end
 
--- Returns the time left for a timer with the given id, registered by the current addon object ('self').
-- This function will return 0 when the id is invalid.
-- @param id The id of the timer, as returned by `:ScheduleTimer` or `:ScheduleRepeatingTimer`
-- @return The time left on the timer.
function AceTimer:TimeLeft(id)
local timer = activeTimers[id]
if not timer then return 0 end
return timer:GetDuration() - timer:GetElapsed()
end
 
 
-- ---------------------------------------------------------------------
-- Upgrading
 
-- Upgrade from old hash-bucket based timers to animation timers
if oldminor and oldminor < 10 then
-- disable old timer logic
AceTimer.frame:SetScript("OnUpdate", nil)
AceTimer.frame:SetScript("OnEvent", nil)
AceTimer.frame:UnregisterAllEvents()
-- convert timers
for object,timers in pairs(AceTimer.selfs) do
for handle,timer in pairs(timers) do
if type(timer) == "table" and timer.callback then
local id
if timer.delay then
id = AceTimer.ScheduleRepeatingTimer(timer.object, timer.callback, timer.delay, timer.arg)
else
id = AceTimer.ScheduleTimer(timer.object, timer.callback, timer.when - GetTime(), timer.arg)
end
-- change id to the old handle
local t = activeTimers[id]
activeTimers[id] = nil
activeTimers[handle] = t
t.id = handle
end
end
end
AceTimer.selfs = nil
AceTimer.hash = nil
AceTimer.debug = nil
elseif oldminor and oldminor < 13 then
for handle, id in pairs(AceTimer.hashCompatTable) do
local t = activeTimers[id]
if t then
activeTimers[id] = nil
activeTimers[handle] = t
t.id = handle
end
end
AceTimer.hashCompatTable = nil
end
 
-- upgrade existing timers to the latest OnFinished
for timer in pairs(inactiveTimers) do
timer:SetScript("OnFinished", OnFinished)
end
 
for _,timer in pairs(activeTimers) do
timer:SetScript("OnFinished", OnFinished)
end
 
-- ---------------------------------------------------------------------
-- Embed handling
 
AceTimer.embeds = AceTimer.embeds or {}
 
local mixins = {
"ScheduleTimer", "ScheduleRepeatingTimer",
"CancelTimer", "CancelAllTimers",
"TimeLeft"
}
 
function AceTimer:Embed(target)
AceTimer.embeds[target] = true
for _,v in pairs(mixins) do
target[v] = AceTimer[v]
end
return target
end
 
-- AceTimer:OnEmbedDisable(target)
-- target (object) - target object that AceTimer is embedded in.
--
-- cancel all timers registered for the object
function AceTimer:OnEmbedDisable(target)
target:CancelAllTimers()
end
 
for addon in pairs(AceTimer.embeds) do
AceTimer:Embed(addon)
end
Kui_Nameplates/core.lua
2,7 → 2,7
Kui Nameplates
Kesava-Auchindoun EU
]]
local addon = LibStub('AceAddon-3.0'):NewAddon('KuiNameplates', 'AceEvent-3.0')
local addon = LibStub('AceAddon-3.0'):NewAddon('KuiNameplates', 'AceEvent-3.0', 'AceTimer-3.0')
local kui = LibStub('Kui-1.0')
local LSM = LibStub('LibSharedMedia-3.0')
 
Kui_Nameplates/layout.lua
10,9 → 10,6
 
--KuiNameplatesDebug=true
 
-- frame to run OnUpdate
kn.f = CreateFrame('Frame')
 
kn.font = ''
kn.fontSizes = {}
kn.sizes = {}
852,29 → 849,25
local WorldFrame, lastUpdate
= WorldFrame, 1
 
function kn.f:OnUpdate(elapsed)
lastUpdate = lastUpdate + elapsed
function kn:OnUpdate()
local frames = select('#', WorldFrame:GetChildren())
 
if lastUpdate >= .1 then
lastUpdate = 0
if frames ~= self.numFrames then
local i, f
 
local frames = select('#', WorldFrame:GetChildren())
 
if frames ~= kn.numFrames then
local i, f
 
for i = 1, frames do
f = select(i, WorldFrame:GetChildren())
if kn:IsNameplate(f) and not f.init then
kn:InitFrame(f)
tinsert(kn.frameList, f)
end
for i = 1, frames do
f = select(i, WorldFrame:GetChildren())
if self:IsNameplate(f) and not f.init then
self:InitFrame(f)
tinsert(self.frameList, f)
end
 
kn.numFrames = frames
end
 
self.numFrames = frames
end
end
 
kn:ScheduleRepeatingTimer('OnUpdate', .1)
end
 
function kn:ToggleCombatEvents(io)
1050,7 → 1043,6
end)
end
 
self.f:SetScript('OnUpdate', self.f.OnUpdate)
self:RegisterEvent('PLAYER_TARGET_CHANGED')
self.ToggleCombatEvents(profile.general.combat)
end