initial commit
This commit is contained in:
653
Libraries/Ace3/AceAddon-3.0/AceAddon-3.0.lua
Normal file
653
Libraries/Ace3/AceAddon-3.0/AceAddon-3.0.lua
Normal file
@@ -0,0 +1,653 @@
|
||||
--- **AceAddon-3.0** provides a template for creating addon objects.
|
||||
-- It'll provide you with a set of callback functions that allow you to simplify the loading
|
||||
-- process of your addon.\\
|
||||
-- Callbacks provided are:\\
|
||||
-- * **OnInitialize**, which is called directly after the addon is fully loaded.
|
||||
-- * **OnEnable** which gets called during the PLAYER_LOGIN event, when most of the data provided by the game is already present.
|
||||
-- * **OnDisable**, which is only called when your addon is manually being disabled.
|
||||
-- @usage
|
||||
-- -- A small (but complete) addon, that doesn't do anything,
|
||||
-- -- but shows usage of the callbacks.
|
||||
-- local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
|
||||
--
|
||||
-- function MyAddon:OnInitialize()
|
||||
-- -- do init tasks here, like loading the Saved Variables,
|
||||
-- -- or setting up slash commands.
|
||||
-- end
|
||||
--
|
||||
-- function MyAddon:OnEnable()
|
||||
-- -- Do more initialization here, that really enables the use of your addon.
|
||||
-- -- Register Events, Hook functions, Create Frames, Get information from
|
||||
-- -- the game that wasn't available in OnInitialize
|
||||
-- end
|
||||
--
|
||||
-- function MyAddon:OnDisable()
|
||||
-- -- Unhook, Unregister Events, Hide frames that you created.
|
||||
-- -- You would probably only use an OnDisable if you want to
|
||||
-- -- build a "standby" mode, or be able to toggle modules on/off.
|
||||
-- end
|
||||
-- @class file
|
||||
-- @name AceAddon-3.0.lua
|
||||
-- @release $Id$
|
||||
|
||||
local MAJOR, MINOR = "AceAddon-3.0", 13
|
||||
local AceAddon, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceAddon then return end -- No Upgrade needed.
|
||||
|
||||
AceAddon.frame = AceAddon.frame or CreateFrame("Frame", "AceAddon30Frame") -- Our very own frame
|
||||
AceAddon.addons = AceAddon.addons or {} -- addons in general
|
||||
AceAddon.statuses = AceAddon.statuses or {} -- statuses of addon.
|
||||
AceAddon.initializequeue = AceAddon.initializequeue or {} -- addons that are new and not initialized
|
||||
AceAddon.enablequeue = AceAddon.enablequeue or {} -- addons that are initialized and waiting to be enabled
|
||||
AceAddon.embeds = AceAddon.embeds or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end }) -- contains a list of libraries embedded in an addon
|
||||
|
||||
-- Lua APIs
|
||||
local tinsert, tconcat, tremove = table.insert, table.concat, table.remove
|
||||
local fmt, tostring = string.format, tostring
|
||||
local select, pairs, next, type, unpack = select, pairs, next, type, unpack
|
||||
local loadstring, assert, error = loadstring, assert, error
|
||||
local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: LibStub, IsLoggedIn, geterrorhandler
|
||||
|
||||
--[[
|
||||
xpcall safecall implementation
|
||||
]]
|
||||
local xpcall = xpcall
|
||||
|
||||
local function errorhandler(err)
|
||||
return geterrorhandler()(err)
|
||||
end
|
||||
|
||||
local function safecall(func, ...)
|
||||
-- we check to see if the func is passed is actually a function here and don't error when it isn't
|
||||
-- this safecall is used for optional functions like OnInitialize OnEnable etc. When they are not
|
||||
-- present execution should continue without hinderance
|
||||
if type(func) == "function" then
|
||||
return xpcall(func, errorhandler, ...)
|
||||
end
|
||||
end
|
||||
|
||||
-- local functions that will be implemented further down
|
||||
local Enable, Disable, EnableModule, DisableModule, Embed, NewModule, GetModule, GetName, SetDefaultModuleState, SetDefaultModuleLibraries, SetEnabledState, SetDefaultModulePrototype
|
||||
|
||||
-- used in the addon metatable
|
||||
local function addontostring( self ) return self.name end
|
||||
|
||||
-- Check if the addon is queued for initialization
|
||||
local function queuedForInitialization(addon)
|
||||
for i = 1, #AceAddon.initializequeue do
|
||||
if AceAddon.initializequeue[i] == addon then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- Create a new AceAddon-3.0 addon.
|
||||
-- Any libraries you specified will be embeded, and the addon will be scheduled for
|
||||
-- its OnInitialize and OnEnable callbacks.
|
||||
-- The final addon object, with all libraries embeded, will be returned.
|
||||
-- @paramsig [object ,]name[, lib, ...]
|
||||
-- @param object Table to use as a base for the addon (optional)
|
||||
-- @param name Name of the addon object to create
|
||||
-- @param lib List of libraries to embed into the addon
|
||||
-- @usage
|
||||
-- -- Create a simple addon object
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceEvent-3.0")
|
||||
--
|
||||
-- -- Create a Addon object based on the table of a frame
|
||||
-- local MyFrame = CreateFrame("Frame")
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon(MyFrame, "MyAddon", "AceEvent-3.0")
|
||||
function AceAddon:NewAddon(objectorname, ...)
|
||||
local object,name
|
||||
local i=1
|
||||
if type(objectorname)=="table" then
|
||||
object=objectorname
|
||||
name=...
|
||||
i=2
|
||||
else
|
||||
name=objectorname
|
||||
end
|
||||
if type(name)~="string" then
|
||||
error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2)
|
||||
end
|
||||
if self.addons[name] then
|
||||
error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon '%s' already exists."):format(name), 2)
|
||||
end
|
||||
|
||||
object = object or {}
|
||||
object.name = name
|
||||
|
||||
local addonmeta = {}
|
||||
local oldmeta = getmetatable(object)
|
||||
if oldmeta then
|
||||
for k, v in pairs(oldmeta) do addonmeta[k] = v end
|
||||
end
|
||||
addonmeta.__tostring = addontostring
|
||||
|
||||
setmetatable( object, addonmeta )
|
||||
self.addons[name] = object
|
||||
object.modules = {}
|
||||
object.orderedModules = {}
|
||||
object.defaultModuleLibraries = {}
|
||||
Embed( object ) -- embed NewModule, GetModule methods
|
||||
self:EmbedLibraries(object, select(i,...))
|
||||
|
||||
-- add to queue of addons to be initialized upon ADDON_LOADED
|
||||
tinsert(self.initializequeue, object)
|
||||
return object
|
||||
end
|
||||
|
||||
|
||||
--- Get the addon object by its name from the internal AceAddon registry.
|
||||
-- Throws an error if the addon object cannot be found (except if silent is set).
|
||||
-- @param name unique name of the addon object
|
||||
-- @param silent if true, the addon is optional, silently return nil if its not found
|
||||
-- @usage
|
||||
-- -- Get the Addon
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
function AceAddon:GetAddon(name, silent)
|
||||
if not silent and not self.addons[name] then
|
||||
error(("Usage: GetAddon(name): 'name' - Cannot find an AceAddon '%s'."):format(tostring(name)), 2)
|
||||
end
|
||||
return self.addons[name]
|
||||
end
|
||||
|
||||
-- - Embed a list of libraries into the specified addon.
|
||||
-- This function will try to embed all of the listed libraries into the addon
|
||||
-- and error if a single one fails.
|
||||
--
|
||||
-- **Note:** This function is for internal use by :NewAddon/:NewModule
|
||||
-- @paramsig addon, [lib, ...]
|
||||
-- @param addon addon object to embed the libs in
|
||||
-- @param lib List of libraries to embed into the addon
|
||||
function AceAddon:EmbedLibraries(addon, ...)
|
||||
for i=1,select("#", ... ) do
|
||||
local libname = select(i, ...)
|
||||
self:EmbedLibrary(addon, libname, false, 4)
|
||||
end
|
||||
end
|
||||
|
||||
-- - Embed a library into the addon object.
|
||||
-- This function will check if the specified library is registered with LibStub
|
||||
-- and if it has a :Embed function to call. It'll error if any of those conditions
|
||||
-- fails.
|
||||
--
|
||||
-- **Note:** This function is for internal use by :EmbedLibraries
|
||||
-- @paramsig addon, libname[, silent[, offset]]
|
||||
-- @param addon addon object to embed the library in
|
||||
-- @param libname name of the library to embed
|
||||
-- @param silent marks an embed to fail silently if the library doesn't exist (optional)
|
||||
-- @param offset will push the error messages back to said offset, defaults to 2 (optional)
|
||||
function AceAddon:EmbedLibrary(addon, libname, silent, offset)
|
||||
local lib = LibStub:GetLibrary(libname, true)
|
||||
if not lib and not silent then
|
||||
error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Cannot find a library instance of %q."):format(tostring(libname)), offset or 2)
|
||||
elseif lib and type(lib.Embed) == "function" then
|
||||
lib:Embed(addon)
|
||||
tinsert(self.embeds[addon], libname)
|
||||
return true
|
||||
elseif lib then
|
||||
error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Library '%s' is not Embed capable"):format(libname), offset or 2)
|
||||
end
|
||||
end
|
||||
|
||||
--- Return the specified module from an addon object.
|
||||
-- Throws an error if the addon object cannot be found (except if silent is set)
|
||||
-- @name //addon//:GetModule
|
||||
-- @paramsig name[, silent]
|
||||
-- @param name unique name of the module
|
||||
-- @param silent if true, the module is optional, silently return nil if its not found (optional)
|
||||
-- @usage
|
||||
-- -- Get the Addon
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- -- Get the Module
|
||||
-- MyModule = MyAddon:GetModule("MyModule")
|
||||
function GetModule(self, name, silent)
|
||||
if not self.modules[name] and not silent then
|
||||
error(("Usage: GetModule(name, silent): 'name' - Cannot find module '%s'."):format(tostring(name)), 2)
|
||||
end
|
||||
return self.modules[name]
|
||||
end
|
||||
|
||||
local function IsModuleTrue(self) return true end
|
||||
|
||||
--- Create a new module for the addon.
|
||||
-- The new module can have its own embeded libraries and/or use a module prototype to be mixed into the module.\\
|
||||
-- A module has the same functionality as a real addon, it can have modules of its own, and has the same API as
|
||||
-- an addon object.
|
||||
-- @name //addon//:NewModule
|
||||
-- @paramsig name[, prototype|lib[, lib, ...]]
|
||||
-- @param name unique name of the module
|
||||
-- @param prototype object to derive this module from, methods and values from this table will be mixed into the module (optional)
|
||||
-- @param lib List of libraries to embed into the addon
|
||||
-- @usage
|
||||
-- -- Create a module with some embeded libraries
|
||||
-- MyModule = MyAddon:NewModule("MyModule", "AceEvent-3.0", "AceHook-3.0")
|
||||
--
|
||||
-- -- Create a module with a prototype
|
||||
-- local prototype = { OnEnable = function(self) print("OnEnable called!") end }
|
||||
-- MyModule = MyAddon:NewModule("MyModule", prototype, "AceEvent-3.0", "AceHook-3.0")
|
||||
function NewModule(self, name, prototype, ...)
|
||||
if type(name) ~= "string" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) end
|
||||
if type(prototype) ~= "string" and type(prototype) ~= "table" and type(prototype) ~= "nil" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'prototype' - table (prototype), string (lib) or nil expected got '%s'."):format(type(prototype)), 2) end
|
||||
|
||||
if self.modules[name] then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - Module '%s' already exists."):format(name), 2) end
|
||||
|
||||
-- modules are basically addons. We treat them as such. They will be added to the initializequeue properly as well.
|
||||
-- NewModule can only be called after the parent addon is present thus the modules will be initialized after their parent is.
|
||||
local module = AceAddon:NewAddon(fmt("%s_%s", self.name or tostring(self), name))
|
||||
|
||||
module.IsModule = IsModuleTrue
|
||||
module:SetEnabledState(self.defaultModuleState)
|
||||
module.moduleName = name
|
||||
|
||||
if type(prototype) == "string" then
|
||||
AceAddon:EmbedLibraries(module, prototype, ...)
|
||||
else
|
||||
AceAddon:EmbedLibraries(module, ...)
|
||||
end
|
||||
AceAddon:EmbedLibraries(module, unpack(self.defaultModuleLibraries))
|
||||
|
||||
if not prototype or type(prototype) == "string" then
|
||||
prototype = self.defaultModulePrototype or nil
|
||||
end
|
||||
|
||||
if type(prototype) == "table" then
|
||||
local mt = getmetatable(module)
|
||||
mt.__index = prototype
|
||||
setmetatable(module, mt) -- More of a Base class type feel.
|
||||
end
|
||||
|
||||
safecall(self.OnModuleCreated, self, module) -- Was in Ace2 and I think it could be a cool thing to have handy.
|
||||
self.modules[name] = module
|
||||
tinsert(self.orderedModules, module)
|
||||
|
||||
return module
|
||||
end
|
||||
|
||||
--- Returns the real name of the addon or module, without any prefix.
|
||||
-- @name //addon//:GetName
|
||||
-- @paramsig
|
||||
-- @usage
|
||||
-- print(MyAddon:GetName())
|
||||
-- -- prints "MyAddon"
|
||||
function GetName(self)
|
||||
return self.moduleName or self.name
|
||||
end
|
||||
|
||||
--- Enables the Addon, if possible, return true or false depending on success.
|
||||
-- This internally calls AceAddon:EnableAddon(), thus dispatching a OnEnable callback
|
||||
-- and enabling all modules of the addon (unless explicitly disabled).\\
|
||||
-- :Enable() also sets the internal `enableState` variable to true
|
||||
-- @name //addon//:Enable
|
||||
-- @paramsig
|
||||
-- @usage
|
||||
-- -- Enable MyModule
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- MyModule = MyAddon:GetModule("MyModule")
|
||||
-- MyModule:Enable()
|
||||
function Enable(self)
|
||||
self:SetEnabledState(true)
|
||||
|
||||
-- nevcairiel 2013-04-27: don't enable an addon/module if its queued for init still
|
||||
-- it'll be enabled after the init process
|
||||
if not queuedForInitialization(self) then
|
||||
return AceAddon:EnableAddon(self)
|
||||
end
|
||||
end
|
||||
|
||||
--- Disables the Addon, if possible, return true or false depending on success.
|
||||
-- This internally calls AceAddon:DisableAddon(), thus dispatching a OnDisable callback
|
||||
-- and disabling all modules of the addon.\\
|
||||
-- :Disable() also sets the internal `enableState` variable to false
|
||||
-- @name //addon//:Disable
|
||||
-- @paramsig
|
||||
-- @usage
|
||||
-- -- Disable MyAddon
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- MyAddon:Disable()
|
||||
function Disable(self)
|
||||
self:SetEnabledState(false)
|
||||
return AceAddon:DisableAddon(self)
|
||||
end
|
||||
|
||||
--- Enables the Module, if possible, return true or false depending on success.
|
||||
-- Short-hand function that retrieves the module via `:GetModule` and calls `:Enable` on the module object.
|
||||
-- @name //addon//:EnableModule
|
||||
-- @paramsig name
|
||||
-- @usage
|
||||
-- -- Enable MyModule using :GetModule
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- MyModule = MyAddon:GetModule("MyModule")
|
||||
-- MyModule:Enable()
|
||||
--
|
||||
-- -- Enable MyModule using the short-hand
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- MyAddon:EnableModule("MyModule")
|
||||
function EnableModule(self, name)
|
||||
local module = self:GetModule( name )
|
||||
return module:Enable()
|
||||
end
|
||||
|
||||
--- Disables the Module, if possible, return true or false depending on success.
|
||||
-- Short-hand function that retrieves the module via `:GetModule` and calls `:Disable` on the module object.
|
||||
-- @name //addon//:DisableModule
|
||||
-- @paramsig name
|
||||
-- @usage
|
||||
-- -- Disable MyModule using :GetModule
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- MyModule = MyAddon:GetModule("MyModule")
|
||||
-- MyModule:Disable()
|
||||
--
|
||||
-- -- Disable MyModule using the short-hand
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
|
||||
-- MyAddon:DisableModule("MyModule")
|
||||
function DisableModule(self, name)
|
||||
local module = self:GetModule( name )
|
||||
return module:Disable()
|
||||
end
|
||||
|
||||
--- Set the default libraries to be mixed into all modules created by this object.
|
||||
-- Note that you can only change the default module libraries before any module is created.
|
||||
-- @name //addon//:SetDefaultModuleLibraries
|
||||
-- @paramsig lib[, lib, ...]
|
||||
-- @param lib List of libraries to embed into the addon
|
||||
-- @usage
|
||||
-- -- Create the addon object
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
|
||||
-- -- Configure default libraries for modules (all modules need AceEvent-3.0)
|
||||
-- MyAddon:SetDefaultModuleLibraries("AceEvent-3.0")
|
||||
-- -- Create a module
|
||||
-- MyModule = MyAddon:NewModule("MyModule")
|
||||
function SetDefaultModuleLibraries(self, ...)
|
||||
if next(self.modules) then
|
||||
error("Usage: SetDefaultModuleLibraries(...): cannot change the module defaults after a module has been registered.", 2)
|
||||
end
|
||||
self.defaultModuleLibraries = {...}
|
||||
end
|
||||
|
||||
--- Set the default state in which new modules are being created.
|
||||
-- Note that you can only change the default state before any module is created.
|
||||
-- @name //addon//:SetDefaultModuleState
|
||||
-- @paramsig state
|
||||
-- @param state Default state for new modules, true for enabled, false for disabled
|
||||
-- @usage
|
||||
-- -- Create the addon object
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
|
||||
-- -- Set the default state to "disabled"
|
||||
-- MyAddon:SetDefaultModuleState(false)
|
||||
-- -- Create a module and explicilty enable it
|
||||
-- MyModule = MyAddon:NewModule("MyModule")
|
||||
-- MyModule:Enable()
|
||||
function SetDefaultModuleState(self, state)
|
||||
if next(self.modules) then
|
||||
error("Usage: SetDefaultModuleState(state): cannot change the module defaults after a module has been registered.", 2)
|
||||
end
|
||||
self.defaultModuleState = state
|
||||
end
|
||||
|
||||
--- Set the default prototype to use for new modules on creation.
|
||||
-- Note that you can only change the default prototype before any module is created.
|
||||
-- @name //addon//:SetDefaultModulePrototype
|
||||
-- @paramsig prototype
|
||||
-- @param prototype Default prototype for the new modules (table)
|
||||
-- @usage
|
||||
-- -- Define a prototype
|
||||
-- local prototype = { OnEnable = function(self) print("OnEnable called!") end }
|
||||
-- -- Set the default prototype
|
||||
-- MyAddon:SetDefaultModulePrototype(prototype)
|
||||
-- -- Create a module and explicitly Enable it
|
||||
-- MyModule = MyAddon:NewModule("MyModule")
|
||||
-- MyModule:Enable()
|
||||
-- -- should print "OnEnable called!" now
|
||||
-- @see NewModule
|
||||
function SetDefaultModulePrototype(self, prototype)
|
||||
if next(self.modules) then
|
||||
error("Usage: SetDefaultModulePrototype(prototype): cannot change the module defaults after a module has been registered.", 2)
|
||||
end
|
||||
if type(prototype) ~= "table" then
|
||||
error(("Usage: SetDefaultModulePrototype(prototype): 'prototype' - table expected got '%s'."):format(type(prototype)), 2)
|
||||
end
|
||||
self.defaultModulePrototype = prototype
|
||||
end
|
||||
|
||||
--- Set the state of an addon or module
|
||||
-- This should only be called before any enabling actually happend, e.g. in/before OnInitialize.
|
||||
-- @name //addon//:SetEnabledState
|
||||
-- @paramsig state
|
||||
-- @param state the state of an addon or module (enabled=true, disabled=false)
|
||||
function SetEnabledState(self, state)
|
||||
self.enabledState = state
|
||||
end
|
||||
|
||||
|
||||
--- Return an iterator of all modules associated to the addon.
|
||||
-- @name //addon//:IterateModules
|
||||
-- @paramsig
|
||||
-- @usage
|
||||
-- -- Enable all modules
|
||||
-- for name, module in MyAddon:IterateModules() do
|
||||
-- module:Enable()
|
||||
-- end
|
||||
local function IterateModules(self) return pairs(self.modules) end
|
||||
|
||||
-- Returns an iterator of all embeds in the addon
|
||||
-- @name //addon//:IterateEmbeds
|
||||
-- @paramsig
|
||||
local function IterateEmbeds(self) return pairs(AceAddon.embeds[self]) end
|
||||
|
||||
--- Query the enabledState of an addon.
|
||||
-- @name //addon//:IsEnabled
|
||||
-- @paramsig
|
||||
-- @usage
|
||||
-- if MyAddon:IsEnabled() then
|
||||
-- MyAddon:Disable()
|
||||
-- end
|
||||
local function IsEnabled(self) return self.enabledState end
|
||||
local mixins = {
|
||||
NewModule = NewModule,
|
||||
GetModule = GetModule,
|
||||
Enable = Enable,
|
||||
Disable = Disable,
|
||||
EnableModule = EnableModule,
|
||||
DisableModule = DisableModule,
|
||||
IsEnabled = IsEnabled,
|
||||
SetDefaultModuleLibraries = SetDefaultModuleLibraries,
|
||||
SetDefaultModuleState = SetDefaultModuleState,
|
||||
SetDefaultModulePrototype = SetDefaultModulePrototype,
|
||||
SetEnabledState = SetEnabledState,
|
||||
IterateModules = IterateModules,
|
||||
IterateEmbeds = IterateEmbeds,
|
||||
GetName = GetName,
|
||||
}
|
||||
local function IsModule(self) return false end
|
||||
local pmixins = {
|
||||
defaultModuleState = true,
|
||||
enabledState = true,
|
||||
IsModule = IsModule,
|
||||
}
|
||||
-- Embed( target )
|
||||
-- target (object) - target object to embed aceaddon in
|
||||
--
|
||||
-- this is a local function specifically since it's meant to be only called internally
|
||||
function Embed(target, skipPMixins)
|
||||
for k, v in pairs(mixins) do
|
||||
target[k] = v
|
||||
end
|
||||
if not skipPMixins then
|
||||
for k, v in pairs(pmixins) do
|
||||
target[k] = target[k] or v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- - Initialize the addon after creation.
|
||||
-- This function is only used internally during the ADDON_LOADED event
|
||||
-- It will call the **OnInitialize** function on the addon object (if present),
|
||||
-- and the **OnEmbedInitialize** function on all embeded libraries.
|
||||
--
|
||||
-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing.
|
||||
-- @param addon addon object to intialize
|
||||
function AceAddon:InitializeAddon(addon)
|
||||
safecall(addon.OnInitialize, addon)
|
||||
|
||||
local embeds = self.embeds[addon]
|
||||
for i = 1, #embeds do
|
||||
local lib = LibStub:GetLibrary(embeds[i], true)
|
||||
if lib then safecall(lib.OnEmbedInitialize, lib, addon) end
|
||||
end
|
||||
|
||||
-- we don't call InitializeAddon on modules specifically, this is handled
|
||||
-- from the event handler and only done _once_
|
||||
end
|
||||
|
||||
-- - Enable the addon after creation.
|
||||
-- Note: This function is only used internally during the PLAYER_LOGIN event, or during ADDON_LOADED,
|
||||
-- if IsLoggedIn() already returns true at that point, e.g. for LoD Addons.
|
||||
-- It will call the **OnEnable** function on the addon object (if present),
|
||||
-- and the **OnEmbedEnable** function on all embeded libraries.\\
|
||||
-- This function does not toggle the enable state of the addon itself, and will return early if the addon is disabled.
|
||||
--
|
||||
-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing.
|
||||
-- Use :Enable on the addon itself instead.
|
||||
-- @param addon addon object to enable
|
||||
function AceAddon:EnableAddon(addon)
|
||||
if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end
|
||||
if self.statuses[addon.name] or not addon.enabledState then return false end
|
||||
|
||||
-- set the statuses first, before calling the OnEnable. this allows for Disabling of the addon in OnEnable.
|
||||
self.statuses[addon.name] = true
|
||||
|
||||
safecall(addon.OnEnable, addon)
|
||||
|
||||
-- make sure we're still enabled before continueing
|
||||
if self.statuses[addon.name] then
|
||||
local embeds = self.embeds[addon]
|
||||
for i = 1, #embeds do
|
||||
local lib = LibStub:GetLibrary(embeds[i], true)
|
||||
if lib then safecall(lib.OnEmbedEnable, lib, addon) end
|
||||
end
|
||||
|
||||
-- enable possible modules.
|
||||
local modules = addon.orderedModules
|
||||
for i = 1, #modules do
|
||||
self:EnableAddon(modules[i])
|
||||
end
|
||||
end
|
||||
return self.statuses[addon.name] -- return true if we're disabled
|
||||
end
|
||||
|
||||
-- - Disable the addon
|
||||
-- Note: This function is only used internally.
|
||||
-- It will call the **OnDisable** function on the addon object (if present),
|
||||
-- and the **OnEmbedDisable** function on all embeded libraries.\\
|
||||
-- This function does not toggle the enable state of the addon itself, and will return early if the addon is still enabled.
|
||||
--
|
||||
-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing.
|
||||
-- Use :Disable on the addon itself instead.
|
||||
-- @param addon addon object to enable
|
||||
function AceAddon:DisableAddon(addon)
|
||||
if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end
|
||||
if not self.statuses[addon.name] then return false end
|
||||
|
||||
-- set statuses first before calling OnDisable, this allows for aborting the disable in OnDisable.
|
||||
self.statuses[addon.name] = false
|
||||
|
||||
safecall( addon.OnDisable, addon )
|
||||
|
||||
-- make sure we're still disabling...
|
||||
if not self.statuses[addon.name] then
|
||||
local embeds = self.embeds[addon]
|
||||
for i = 1, #embeds do
|
||||
local lib = LibStub:GetLibrary(embeds[i], true)
|
||||
if lib then safecall(lib.OnEmbedDisable, lib, addon) end
|
||||
end
|
||||
-- disable possible modules.
|
||||
local modules = addon.orderedModules
|
||||
for i = 1, #modules do
|
||||
self:DisableAddon(modules[i])
|
||||
end
|
||||
end
|
||||
|
||||
return not self.statuses[addon.name] -- return true if we're disabled
|
||||
end
|
||||
|
||||
--- Get an iterator over all registered addons.
|
||||
-- @usage
|
||||
-- -- Print a list of all installed AceAddon's
|
||||
-- for name, addon in AceAddon:IterateAddons() do
|
||||
-- print("Addon: " .. name)
|
||||
-- end
|
||||
function AceAddon:IterateAddons() return pairs(self.addons) end
|
||||
|
||||
--- Get an iterator over the internal status registry.
|
||||
-- @usage
|
||||
-- -- Print a list of all enabled addons
|
||||
-- for name, status in AceAddon:IterateAddonStatus() do
|
||||
-- if status then
|
||||
-- print("EnabledAddon: " .. name)
|
||||
-- end
|
||||
-- end
|
||||
function AceAddon:IterateAddonStatus() return pairs(self.statuses) end
|
||||
|
||||
-- Following Iterators are deprecated, and their addon specific versions should be used
|
||||
-- e.g. addon:IterateEmbeds() instead of :IterateEmbedsOnAddon(addon)
|
||||
function AceAddon:IterateEmbedsOnAddon(addon) return pairs(self.embeds[addon]) end
|
||||
function AceAddon:IterateModulesOfAddon(addon) return pairs(addon.modules) end
|
||||
|
||||
-- Blizzard AddOns which can load very early in the loading process and mess with Ace3 addon loading
|
||||
local BlizzardEarlyLoadAddons = {
|
||||
Blizzard_DebugTools = true,
|
||||
Blizzard_TimeManager = true,
|
||||
Blizzard_BattlefieldMap = true,
|
||||
Blizzard_MapCanvas = true,
|
||||
Blizzard_SharedMapDataProviders = true,
|
||||
Blizzard_CombatLog = true,
|
||||
}
|
||||
|
||||
-- Event Handling
|
||||
local function onEvent(this, event, arg1)
|
||||
-- 2020-08-28 nevcairiel - ignore the load event of Blizzard addons which occur early in the loading process
|
||||
if (event == "ADDON_LOADED" and (arg1 == nil or not BlizzardEarlyLoadAddons[arg1])) or event == "PLAYER_LOGIN" then
|
||||
-- if a addon loads another addon, recursion could happen here, so we need to validate the table on every iteration
|
||||
while(#AceAddon.initializequeue > 0) do
|
||||
local addon = tremove(AceAddon.initializequeue, 1)
|
||||
-- this might be an issue with recursion - TODO: validate
|
||||
if event == "ADDON_LOADED" then addon.baseName = arg1 end
|
||||
AceAddon:InitializeAddon(addon)
|
||||
tinsert(AceAddon.enablequeue, addon)
|
||||
end
|
||||
|
||||
if IsLoggedIn() then
|
||||
while(#AceAddon.enablequeue > 0) do
|
||||
local addon = tremove(AceAddon.enablequeue, 1)
|
||||
AceAddon:EnableAddon(addon)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
AceAddon.frame:RegisterEvent("ADDON_LOADED")
|
||||
AceAddon.frame:RegisterEvent("PLAYER_LOGIN")
|
||||
AceAddon.frame:SetScript("OnEvent", onEvent)
|
||||
|
||||
-- upgrade embeded
|
||||
for name, addon in pairs(AceAddon.addons) do
|
||||
Embed(addon, true)
|
||||
end
|
||||
|
||||
-- 2010-10-27 nevcairiel - add new "orderedModules" table
|
||||
if oldminor and oldminor < 10 then
|
||||
for name, addon in pairs(AceAddon.addons) do
|
||||
addon.orderedModules = {}
|
||||
for module_name, module in pairs(addon.modules) do
|
||||
tinsert(addon.orderedModules, module)
|
||||
end
|
||||
end
|
||||
end
|
||||
4
Libraries/Ace3/AceAddon-3.0/AceAddon-3.0.xml
Normal file
4
Libraries/Ace3/AceAddon-3.0/AceAddon-3.0.xml
Normal 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="AceAddon-3.0.lua"/>
|
||||
</Ui>
|
||||
305
Libraries/Ace3/AceComm-3.0/AceComm-3.0.lua
Normal file
305
Libraries/Ace3/AceComm-3.0/AceComm-3.0.lua
Normal file
@@ -0,0 +1,305 @@
|
||||
--- **AceComm-3.0** allows you to send messages of unlimited length over the addon comm channels.
|
||||
-- It'll automatically split the messages into multiple parts and rebuild them on the receiving end.\\
|
||||
-- **ChatThrottleLib** is of course being used to avoid being disconnected by the server.
|
||||
--
|
||||
-- **AceComm-3.0** can be embeded into your addon, either explicitly by calling AceComm: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 AceComm itself.\\
|
||||
-- It is recommended to embed AceComm, otherwise you'll have to specify a custom `self` on all calls you
|
||||
-- make into AceComm.
|
||||
-- @class file
|
||||
-- @name AceComm-3.0
|
||||
-- @release $Id$
|
||||
|
||||
--[[ AceComm-3.0
|
||||
|
||||
TODO: Time out old data rotting around from dead senders? Not a HUGE deal since the number of possible sender names is somewhat limited.
|
||||
|
||||
]]
|
||||
|
||||
local CallbackHandler = LibStub("CallbackHandler-1.0")
|
||||
local CTL = assert(ChatThrottleLib, "AceComm-3.0 requires ChatThrottleLib")
|
||||
|
||||
local MAJOR, MINOR = "AceComm-3.0", 12
|
||||
local AceComm,oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceComm then return end
|
||||
|
||||
-- Lua APIs
|
||||
local type, next, pairs, tostring = type, next, pairs, tostring
|
||||
local strsub, strfind = string.sub, string.find
|
||||
local match = string.match
|
||||
local tinsert, tconcat = table.insert, table.concat
|
||||
local error, assert = error, assert
|
||||
|
||||
-- WoW APIs
|
||||
local Ambiguate = Ambiguate
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: LibStub, DEFAULT_CHAT_FRAME, geterrorhandler, RegisterAddonMessagePrefix
|
||||
|
||||
AceComm.embeds = AceComm.embeds or {}
|
||||
|
||||
-- for my sanity and yours, let's give the message type bytes some names
|
||||
local MSG_MULTI_FIRST = "\001"
|
||||
local MSG_MULTI_NEXT = "\002"
|
||||
local MSG_MULTI_LAST = "\003"
|
||||
local MSG_ESCAPE = "\004"
|
||||
|
||||
-- remove old structures (pre WoW 4.0)
|
||||
AceComm.multipart_origprefixes = nil
|
||||
AceComm.multipart_reassemblers = nil
|
||||
|
||||
-- the multipart message spool: indexed by a combination of sender+distribution+
|
||||
AceComm.multipart_spool = AceComm.multipart_spool or {}
|
||||
|
||||
--- Register for Addon Traffic on a specified prefix
|
||||
-- @param prefix A printable character (\032-\255) classification of the message (typically AddonName or AddonNameEvent), max 16 characters
|
||||
-- @param method Callback to call on message reception: Function reference, or method name (string) to call on self. Defaults to "OnCommReceived"
|
||||
function AceComm:RegisterComm(prefix, method)
|
||||
if method == nil then
|
||||
method = "OnCommReceived"
|
||||
end
|
||||
|
||||
if #prefix > 16 then -- TODO: 15?
|
||||
error("AceComm:RegisterComm(prefix,method): prefix length is limited to 16 characters")
|
||||
end
|
||||
if C_ChatInfo then
|
||||
C_ChatInfo.RegisterAddonMessagePrefix(prefix)
|
||||
else
|
||||
RegisterAddonMessagePrefix(prefix)
|
||||
end
|
||||
|
||||
return AceComm._RegisterComm(self, prefix, method) -- created by CallbackHandler
|
||||
end
|
||||
|
||||
local warnedPrefix=false
|
||||
|
||||
--- Send a message over the Addon Channel
|
||||
-- @param prefix A printable character (\032-\255) classification of the message (typically AddonName or AddonNameEvent)
|
||||
-- @param text Data to send, nils (\000) not allowed. Any length.
|
||||
-- @param distribution Addon channel, e.g. "RAID", "GUILD", etc; see SendAddonMessage API
|
||||
-- @param target Destination for some distributions; see SendAddonMessage API
|
||||
-- @param prio OPTIONAL: ChatThrottleLib priority, "BULK", "NORMAL" or "ALERT". Defaults to "NORMAL".
|
||||
-- @param callbackFn OPTIONAL: callback function to be called as each chunk is sent. receives 3 args: the user supplied arg (see next), the number of bytes sent so far, and the number of bytes total to send.
|
||||
-- @param callbackArg: OPTIONAL: first arg to the callback function. nil will be passed if not specified.
|
||||
function AceComm:SendCommMessage(prefix, text, distribution, target, prio, callbackFn, callbackArg)
|
||||
prio = prio or "NORMAL" -- pasta's reference implementation had different prio for singlepart and multipart, but that's a very bad idea since that can easily lead to out-of-sequence delivery!
|
||||
if not( type(prefix)=="string" and
|
||||
type(text)=="string" and
|
||||
type(distribution)=="string" and
|
||||
(target==nil or type(target)=="string" or type(target)=="number") and
|
||||
(prio=="BULK" or prio=="NORMAL" or prio=="ALERT")
|
||||
) then
|
||||
error('Usage: SendCommMessage(addon, "prefix", "text", "distribution"[, "target"[, "prio"[, callbackFn, callbackarg]]])', 2)
|
||||
end
|
||||
|
||||
local textlen = #text
|
||||
local maxtextlen = 255 -- Yes, the max is 255 even if the dev post said 256. I tested. Char 256+ get silently truncated. /Mikk, 20110327
|
||||
local queueName = prefix..distribution..(target or "")
|
||||
|
||||
local ctlCallback = nil
|
||||
if callbackFn then
|
||||
ctlCallback = function(sent)
|
||||
return callbackFn(callbackArg, sent, textlen)
|
||||
end
|
||||
end
|
||||
|
||||
local forceMultipart
|
||||
if match(text, "^[\001-\009]") then -- 4.1+: see if the first character is a control character
|
||||
-- we need to escape the first character with a \004
|
||||
if textlen+1 > maxtextlen then -- would we go over the size limit?
|
||||
forceMultipart = true -- just make it multipart, no escape problems then
|
||||
else
|
||||
text = "\004" .. text
|
||||
end
|
||||
end
|
||||
|
||||
if not forceMultipart and textlen <= maxtextlen then
|
||||
-- fits all in one message
|
||||
CTL:SendAddonMessage(prio, prefix, text, distribution, target, queueName, ctlCallback, textlen)
|
||||
else
|
||||
maxtextlen = maxtextlen - 1 -- 1 extra byte for part indicator in prefix(4.0)/start of message(4.1)
|
||||
|
||||
-- first part
|
||||
local chunk = strsub(text, 1, maxtextlen)
|
||||
CTL:SendAddonMessage(prio, prefix, MSG_MULTI_FIRST..chunk, distribution, target, queueName, ctlCallback, maxtextlen)
|
||||
|
||||
-- continuation
|
||||
local pos = 1+maxtextlen
|
||||
|
||||
while pos+maxtextlen <= textlen do
|
||||
chunk = strsub(text, pos, pos+maxtextlen-1)
|
||||
CTL:SendAddonMessage(prio, prefix, MSG_MULTI_NEXT..chunk, distribution, target, queueName, ctlCallback, pos+maxtextlen-1)
|
||||
pos = pos + maxtextlen
|
||||
end
|
||||
|
||||
-- final part
|
||||
chunk = strsub(text, pos)
|
||||
CTL:SendAddonMessage(prio, prefix, MSG_MULTI_LAST..chunk, distribution, target, queueName, ctlCallback, textlen)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
----------------------------------------
|
||||
-- Message receiving
|
||||
----------------------------------------
|
||||
|
||||
do
|
||||
local compost = setmetatable({}, {__mode = "k"})
|
||||
local function new()
|
||||
local t = next(compost)
|
||||
if t then
|
||||
compost[t]=nil
|
||||
for i=#t,3,-1 do -- faster than pairs loop. don't even nil out 1/2 since they'll be overwritten
|
||||
t[i]=nil
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
return {}
|
||||
end
|
||||
|
||||
local function lostdatawarning(prefix,sender,where)
|
||||
DEFAULT_CHAT_FRAME:AddMessage(MAJOR..": Warning: lost network data regarding '"..tostring(prefix).."' from '"..tostring(sender).."' (in "..where..")")
|
||||
end
|
||||
|
||||
function AceComm:OnReceiveMultipartFirst(prefix, message, distribution, sender)
|
||||
local key = prefix.."\t"..distribution.."\t"..sender -- a unique stream is defined by the prefix + distribution + sender
|
||||
local spool = AceComm.multipart_spool
|
||||
|
||||
--[[
|
||||
if spool[key] then
|
||||
lostdatawarning(prefix,sender,"First")
|
||||
-- continue and overwrite
|
||||
end
|
||||
--]]
|
||||
|
||||
spool[key] = message -- plain string for now
|
||||
end
|
||||
|
||||
function AceComm:OnReceiveMultipartNext(prefix, message, distribution, sender)
|
||||
local key = prefix.."\t"..distribution.."\t"..sender -- a unique stream is defined by the prefix + distribution + sender
|
||||
local spool = AceComm.multipart_spool
|
||||
local olddata = spool[key]
|
||||
|
||||
if not olddata then
|
||||
--lostdatawarning(prefix,sender,"Next")
|
||||
return
|
||||
end
|
||||
|
||||
if type(olddata)~="table" then
|
||||
-- ... but what we have is not a table. So make it one. (Pull a composted one if available)
|
||||
local t = new()
|
||||
t[1] = olddata -- add old data as first string
|
||||
t[2] = message -- and new message as second string
|
||||
spool[key] = t -- and put the table in the spool instead of the old string
|
||||
else
|
||||
tinsert(olddata, message)
|
||||
end
|
||||
end
|
||||
|
||||
function AceComm:OnReceiveMultipartLast(prefix, message, distribution, sender)
|
||||
local key = prefix.."\t"..distribution.."\t"..sender -- a unique stream is defined by the prefix + distribution + sender
|
||||
local spool = AceComm.multipart_spool
|
||||
local olddata = spool[key]
|
||||
|
||||
if not olddata then
|
||||
--lostdatawarning(prefix,sender,"End")
|
||||
return
|
||||
end
|
||||
|
||||
spool[key] = nil
|
||||
|
||||
if type(olddata) == "table" then
|
||||
-- if we've received a "next", the spooled data will be a table for rapid & garbage-free tconcat
|
||||
tinsert(olddata, message)
|
||||
AceComm.callbacks:Fire(prefix, tconcat(olddata, ""), distribution, sender)
|
||||
compost[olddata] = true
|
||||
else
|
||||
-- if we've only received a "first", the spooled data will still only be a string
|
||||
AceComm.callbacks:Fire(prefix, olddata..message, distribution, sender)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
----------------------------------------
|
||||
-- Embed CallbackHandler
|
||||
----------------------------------------
|
||||
|
||||
if not AceComm.callbacks then
|
||||
AceComm.callbacks = CallbackHandler:New(AceComm,
|
||||
"_RegisterComm",
|
||||
"UnregisterComm",
|
||||
"UnregisterAllComm")
|
||||
end
|
||||
|
||||
AceComm.callbacks.OnUsed = nil
|
||||
AceComm.callbacks.OnUnused = nil
|
||||
|
||||
local function OnEvent(self, event, prefix, message, distribution, sender)
|
||||
if event == "CHAT_MSG_ADDON" then
|
||||
sender = Ambiguate(sender, "none")
|
||||
local control, rest = match(message, "^([\001-\009])(.*)")
|
||||
if control then
|
||||
if control==MSG_MULTI_FIRST then
|
||||
AceComm:OnReceiveMultipartFirst(prefix, rest, distribution, sender)
|
||||
elseif control==MSG_MULTI_NEXT then
|
||||
AceComm:OnReceiveMultipartNext(prefix, rest, distribution, sender)
|
||||
elseif control==MSG_MULTI_LAST then
|
||||
AceComm:OnReceiveMultipartLast(prefix, rest, distribution, sender)
|
||||
elseif control==MSG_ESCAPE then
|
||||
AceComm.callbacks:Fire(prefix, rest, distribution, sender)
|
||||
else
|
||||
-- unknown control character, ignore SILENTLY (dont warn unnecessarily about future extensions!)
|
||||
end
|
||||
else
|
||||
-- single part: fire it off immediately and let CallbackHandler decide if it's registered or not
|
||||
AceComm.callbacks:Fire(prefix, message, distribution, sender)
|
||||
end
|
||||
else
|
||||
assert(false, "Received "..tostring(event).." event?!")
|
||||
end
|
||||
end
|
||||
|
||||
AceComm.frame = AceComm.frame or CreateFrame("Frame", "AceComm30Frame")
|
||||
AceComm.frame:SetScript("OnEvent", OnEvent)
|
||||
AceComm.frame:UnregisterAllEvents()
|
||||
AceComm.frame:RegisterEvent("CHAT_MSG_ADDON")
|
||||
|
||||
|
||||
----------------------------------------
|
||||
-- Base library stuff
|
||||
----------------------------------------
|
||||
|
||||
local mixins = {
|
||||
"RegisterComm",
|
||||
"UnregisterComm",
|
||||
"UnregisterAllComm",
|
||||
"SendCommMessage",
|
||||
}
|
||||
|
||||
-- Embeds AceComm-3.0 into the target object making the functions from the mixins list available on target:..
|
||||
-- @param target target object to embed AceComm-3.0 in
|
||||
function AceComm:Embed(target)
|
||||
for k, v in pairs(mixins) do
|
||||
target[v] = self[v]
|
||||
end
|
||||
self.embeds[target] = true
|
||||
return target
|
||||
end
|
||||
|
||||
function AceComm:OnEmbedDisable(target)
|
||||
target:UnregisterAllComm()
|
||||
end
|
||||
|
||||
-- Update embeds
|
||||
for target, v in pairs(AceComm.embeds) do
|
||||
AceComm:Embed(target)
|
||||
end
|
||||
5
Libraries/Ace3/AceComm-3.0/AceComm-3.0.xml
Normal file
5
Libraries/Ace3/AceComm-3.0/AceComm-3.0.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<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="ChatThrottleLib.lua"/>
|
||||
<Script file="AceComm-3.0.lua"/>
|
||||
</Ui>
|
||||
534
Libraries/Ace3/AceComm-3.0/ChatThrottleLib.lua
Normal file
534
Libraries/Ace3/AceComm-3.0/ChatThrottleLib.lua
Normal file
@@ -0,0 +1,534 @@
|
||||
--
|
||||
-- ChatThrottleLib by Mikk
|
||||
--
|
||||
-- Manages AddOn chat output to keep player from getting kicked off.
|
||||
--
|
||||
-- ChatThrottleLib:SendChatMessage/:SendAddonMessage functions that accept
|
||||
-- a Priority ("BULK", "NORMAL", "ALERT") as well as prefix for SendChatMessage.
|
||||
--
|
||||
-- Priorities get an equal share of available bandwidth when fully loaded.
|
||||
-- Communication channels are separated on extension+chattype+destination and
|
||||
-- get round-robinned. (Destination only matters for whispers and channels,
|
||||
-- obviously)
|
||||
--
|
||||
-- Will install hooks for SendChatMessage and SendAddonMessage to measure
|
||||
-- bandwidth bypassing the library and use less bandwidth itself.
|
||||
--
|
||||
--
|
||||
-- Fully embeddable library. Just copy this file into your addon directory,
|
||||
-- add it to the .toc, and it's done.
|
||||
--
|
||||
-- Can run as a standalone addon also, but, really, just embed it! :-)
|
||||
--
|
||||
-- LICENSE: ChatThrottleLib is released into the Public Domain
|
||||
--
|
||||
|
||||
local CTL_VERSION = 24
|
||||
|
||||
local _G = _G
|
||||
|
||||
if _G.ChatThrottleLib then
|
||||
if _G.ChatThrottleLib.version >= CTL_VERSION then
|
||||
-- There's already a newer (or same) version loaded. Buh-bye.
|
||||
return
|
||||
elseif not _G.ChatThrottleLib.securelyHooked then
|
||||
print("ChatThrottleLib: Warning: There's an ANCIENT ChatThrottleLib.lua (pre-wow 2.0, <v16) in an addon somewhere. Get the addon updated or copy in a newer ChatThrottleLib.lua (>=v16) in it!")
|
||||
-- ATTEMPT to unhook; this'll behave badly if someone else has hooked...
|
||||
-- ... and if someone has securehooked, they can kiss that goodbye too... >.<
|
||||
_G.SendChatMessage = _G.ChatThrottleLib.ORIG_SendChatMessage
|
||||
if _G.ChatThrottleLib.ORIG_SendAddonMessage then
|
||||
_G.SendAddonMessage = _G.ChatThrottleLib.ORIG_SendAddonMessage
|
||||
end
|
||||
end
|
||||
_G.ChatThrottleLib.ORIG_SendChatMessage = nil
|
||||
_G.ChatThrottleLib.ORIG_SendAddonMessage = nil
|
||||
end
|
||||
|
||||
if not _G.ChatThrottleLib then
|
||||
_G.ChatThrottleLib = {}
|
||||
end
|
||||
|
||||
ChatThrottleLib = _G.ChatThrottleLib -- in case some addon does "local ChatThrottleLib" above us and we're copypasted (AceComm-2, sigh)
|
||||
local ChatThrottleLib = _G.ChatThrottleLib
|
||||
|
||||
ChatThrottleLib.version = CTL_VERSION
|
||||
|
||||
|
||||
|
||||
------------------ TWEAKABLES -----------------
|
||||
|
||||
ChatThrottleLib.MAX_CPS = 800 -- 2000 seems to be safe if NOTHING ELSE is happening. let's call it 800.
|
||||
ChatThrottleLib.MSG_OVERHEAD = 40 -- Guesstimate overhead for sending a message; source+dest+chattype+protocolstuff
|
||||
|
||||
ChatThrottleLib.BURST = 4000 -- WoW's server buffer seems to be about 32KB. 8KB should be safe, but seen disconnects on _some_ servers. Using 4KB now.
|
||||
|
||||
ChatThrottleLib.MIN_FPS = 20 -- Reduce output CPS to half (and don't burst) if FPS drops below this value
|
||||
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local table_remove = table.remove
|
||||
local tostring = tostring
|
||||
local GetTime = GetTime
|
||||
local math_min = math.min
|
||||
local math_max = math.max
|
||||
local next = next
|
||||
local strlen = string.len
|
||||
local GetFramerate = GetFramerate
|
||||
local strlower = string.lower
|
||||
local unpack,type,pairs,wipe = unpack,type,pairs,wipe
|
||||
local UnitInRaid,UnitInParty = UnitInRaid,UnitInParty
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Double-linked ring implementation
|
||||
|
||||
local Ring = {}
|
||||
local RingMeta = { __index = Ring }
|
||||
|
||||
function Ring:New()
|
||||
local ret = {}
|
||||
setmetatable(ret, RingMeta)
|
||||
return ret
|
||||
end
|
||||
|
||||
function Ring:Add(obj) -- Append at the "far end" of the ring (aka just before the current position)
|
||||
if self.pos then
|
||||
obj.prev = self.pos.prev
|
||||
obj.prev.next = obj
|
||||
obj.next = self.pos
|
||||
obj.next.prev = obj
|
||||
else
|
||||
obj.next = obj
|
||||
obj.prev = obj
|
||||
self.pos = obj
|
||||
end
|
||||
end
|
||||
|
||||
function Ring:Remove(obj)
|
||||
obj.next.prev = obj.prev
|
||||
obj.prev.next = obj.next
|
||||
if self.pos == obj then
|
||||
self.pos = obj.next
|
||||
if self.pos == obj then
|
||||
self.pos = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Recycling bin for pipes
|
||||
-- A pipe is a plain integer-indexed queue of messages
|
||||
-- Pipes normally live in Rings of pipes (3 rings total, one per priority)
|
||||
|
||||
ChatThrottleLib.PipeBin = nil -- pre-v19, drastically different
|
||||
local PipeBin = setmetatable({}, {__mode="k"})
|
||||
|
||||
local function DelPipe(pipe)
|
||||
PipeBin[pipe] = true
|
||||
end
|
||||
|
||||
local function NewPipe()
|
||||
local pipe = next(PipeBin)
|
||||
if pipe then
|
||||
wipe(pipe)
|
||||
PipeBin[pipe] = nil
|
||||
return pipe
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Recycling bin for messages
|
||||
|
||||
ChatThrottleLib.MsgBin = nil -- pre-v19, drastically different
|
||||
local MsgBin = setmetatable({}, {__mode="k"})
|
||||
|
||||
local function DelMsg(msg)
|
||||
msg[1] = nil
|
||||
-- there's more parameters, but they're very repetetive so the string pool doesn't suffer really, and it's faster to just not delete them.
|
||||
MsgBin[msg] = true
|
||||
end
|
||||
|
||||
local function NewMsg()
|
||||
local msg = next(MsgBin)
|
||||
if msg then
|
||||
MsgBin[msg] = nil
|
||||
return msg
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- ChatThrottleLib:Init
|
||||
-- Initialize queues, set up frame for OnUpdate, etc
|
||||
|
||||
|
||||
function ChatThrottleLib:Init()
|
||||
|
||||
-- Set up queues
|
||||
if not self.Prio then
|
||||
self.Prio = {}
|
||||
self.Prio["ALERT"] = { ByName = {}, Ring = Ring:New(), avail = 0 }
|
||||
self.Prio["NORMAL"] = { ByName = {}, Ring = Ring:New(), avail = 0 }
|
||||
self.Prio["BULK"] = { ByName = {}, Ring = Ring:New(), avail = 0 }
|
||||
end
|
||||
|
||||
-- v4: total send counters per priority
|
||||
for _, Prio in pairs(self.Prio) do
|
||||
Prio.nTotalSent = Prio.nTotalSent or 0
|
||||
end
|
||||
|
||||
if not self.avail then
|
||||
self.avail = 0 -- v5
|
||||
end
|
||||
if not self.nTotalSent then
|
||||
self.nTotalSent = 0 -- v5
|
||||
end
|
||||
|
||||
|
||||
-- Set up a frame to get OnUpdate events
|
||||
if not self.Frame then
|
||||
self.Frame = CreateFrame("Frame")
|
||||
self.Frame:Hide()
|
||||
end
|
||||
self.Frame:SetScript("OnUpdate", self.OnUpdate)
|
||||
self.Frame:SetScript("OnEvent", self.OnEvent) -- v11: Monitor P_E_W so we can throttle hard for a few seconds
|
||||
self.Frame:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
self.OnUpdateDelay = 0
|
||||
self.LastAvailUpdate = GetTime()
|
||||
self.HardThrottlingBeginTime = GetTime() -- v11: Throttle hard for a few seconds after startup
|
||||
|
||||
-- Hook SendChatMessage and SendAddonMessage so we can measure unpiped traffic and avoid overloads (v7)
|
||||
if not self.securelyHooked then
|
||||
-- Use secure hooks as of v16. Old regular hook support yanked out in v21.
|
||||
self.securelyHooked = true
|
||||
--SendChatMessage
|
||||
hooksecurefunc("SendChatMessage", function(...)
|
||||
return ChatThrottleLib.Hook_SendChatMessage(...)
|
||||
end)
|
||||
--SendAddonMessage
|
||||
if _G.C_ChatInfo then
|
||||
hooksecurefunc(_G.C_ChatInfo, "SendAddonMessage", function(...)
|
||||
return ChatThrottleLib.Hook_SendAddonMessage(...)
|
||||
end)
|
||||
else
|
||||
hooksecurefunc("SendAddonMessage", function(...)
|
||||
return ChatThrottleLib.Hook_SendAddonMessage(...)
|
||||
end)
|
||||
end
|
||||
end
|
||||
self.nBypass = 0
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- ChatThrottleLib.Hook_SendChatMessage / .Hook_SendAddonMessage
|
||||
|
||||
local bMyTraffic = false
|
||||
|
||||
function ChatThrottleLib.Hook_SendChatMessage(text, chattype, language, destination, ...)
|
||||
if bMyTraffic then
|
||||
return
|
||||
end
|
||||
local self = ChatThrottleLib
|
||||
local size = strlen(tostring(text or "")) + strlen(tostring(destination or "")) + self.MSG_OVERHEAD
|
||||
self.avail = self.avail - size
|
||||
self.nBypass = self.nBypass + size -- just a statistic
|
||||
end
|
||||
function ChatThrottleLib.Hook_SendAddonMessage(prefix, text, chattype, destination, ...)
|
||||
if bMyTraffic then
|
||||
return
|
||||
end
|
||||
local self = ChatThrottleLib
|
||||
local size = tostring(text or ""):len() + tostring(prefix or ""):len();
|
||||
size = size + tostring(destination or ""):len() + self.MSG_OVERHEAD
|
||||
self.avail = self.avail - size
|
||||
self.nBypass = self.nBypass + size -- just a statistic
|
||||
end
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- ChatThrottleLib:UpdateAvail
|
||||
-- Update self.avail with how much bandwidth is currently available
|
||||
|
||||
function ChatThrottleLib:UpdateAvail()
|
||||
local now = GetTime()
|
||||
local MAX_CPS = self.MAX_CPS;
|
||||
local newavail = MAX_CPS * (now - self.LastAvailUpdate)
|
||||
local avail = self.avail
|
||||
|
||||
if now - self.HardThrottlingBeginTime < 5 then
|
||||
-- First 5 seconds after startup/zoning: VERY hard clamping to avoid irritating the server rate limiter, it seems very cranky then
|
||||
avail = math_min(avail + (newavail*0.1), MAX_CPS*0.5)
|
||||
self.bChoking = true
|
||||
elseif GetFramerate() < self.MIN_FPS then -- GetFrameRate call takes ~0.002 secs
|
||||
avail = math_min(MAX_CPS, avail + newavail*0.5)
|
||||
self.bChoking = true -- just a statistic
|
||||
else
|
||||
avail = math_min(self.BURST, avail + newavail)
|
||||
self.bChoking = false
|
||||
end
|
||||
|
||||
avail = math_max(avail, 0-(MAX_CPS*2)) -- Can go negative when someone is eating bandwidth past the lib. but we refuse to stay silent for more than 2 seconds; if they can do it, we can.
|
||||
|
||||
self.avail = avail
|
||||
self.LastAvailUpdate = now
|
||||
|
||||
return avail
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Despooling logic
|
||||
-- Reminder:
|
||||
-- - We have 3 Priorities, each containing a "Ring" construct ...
|
||||
-- - ... made up of N "Pipe"s (1 for each destination/pipename)
|
||||
-- - and each pipe contains messages
|
||||
|
||||
function ChatThrottleLib:Despool(Prio)
|
||||
local ring = Prio.Ring
|
||||
while ring.pos and Prio.avail > ring.pos[1].nSize do
|
||||
local msg = table_remove(ring.pos, 1)
|
||||
if not ring.pos[1] then -- did we remove last msg in this pipe?
|
||||
local pipe = Prio.Ring.pos
|
||||
Prio.Ring:Remove(pipe)
|
||||
Prio.ByName[pipe.name] = nil
|
||||
DelPipe(pipe)
|
||||
else
|
||||
Prio.Ring.pos = Prio.Ring.pos.next
|
||||
end
|
||||
local didSend=false
|
||||
local lowerDest = strlower(msg[3] or "")
|
||||
if lowerDest == "raid" and not UnitInRaid("player") then
|
||||
-- do nothing
|
||||
elseif lowerDest == "party" and not UnitInParty("player") then
|
||||
-- do nothing
|
||||
else
|
||||
Prio.avail = Prio.avail - msg.nSize
|
||||
bMyTraffic = true
|
||||
msg.f(unpack(msg, 1, msg.n))
|
||||
bMyTraffic = false
|
||||
Prio.nTotalSent = Prio.nTotalSent + msg.nSize
|
||||
DelMsg(msg)
|
||||
didSend = true
|
||||
end
|
||||
-- notify caller of delivery (even if we didn't send it)
|
||||
if msg.callbackFn then
|
||||
msg.callbackFn (msg.callbackArg, didSend)
|
||||
end
|
||||
-- USER CALLBACK MAY ERROR
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function ChatThrottleLib.OnEvent(this,event)
|
||||
-- v11: We know that the rate limiter is touchy after login. Assume that it's touchy after zoning, too.
|
||||
local self = ChatThrottleLib
|
||||
if event == "PLAYER_ENTERING_WORLD" then
|
||||
self.HardThrottlingBeginTime = GetTime() -- Throttle hard for a few seconds after zoning
|
||||
self.avail = 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function ChatThrottleLib.OnUpdate(this,delay)
|
||||
local self = ChatThrottleLib
|
||||
|
||||
self.OnUpdateDelay = self.OnUpdateDelay + delay
|
||||
if self.OnUpdateDelay < 0.08 then
|
||||
return
|
||||
end
|
||||
self.OnUpdateDelay = 0
|
||||
|
||||
self:UpdateAvail()
|
||||
|
||||
if self.avail < 0 then
|
||||
return -- argh. some bastard is spewing stuff past the lib. just bail early to save cpu.
|
||||
end
|
||||
|
||||
-- See how many of our priorities have queued messages (we only have 3, don't worry about the loop)
|
||||
local n = 0
|
||||
for prioname,Prio in pairs(self.Prio) do
|
||||
if Prio.Ring.pos or Prio.avail < 0 then
|
||||
n = n + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- Anything queued still?
|
||||
if n<1 then
|
||||
-- Nope. Move spillover bandwidth to global availability gauge and clear self.bQueueing
|
||||
for prioname, Prio in pairs(self.Prio) do
|
||||
self.avail = self.avail + Prio.avail
|
||||
Prio.avail = 0
|
||||
end
|
||||
self.bQueueing = false
|
||||
self.Frame:Hide()
|
||||
return
|
||||
end
|
||||
|
||||
-- There's stuff queued. Hand out available bandwidth to priorities as needed and despool their queues
|
||||
local avail = self.avail/n
|
||||
self.avail = 0
|
||||
|
||||
for prioname, Prio in pairs(self.Prio) do
|
||||
if Prio.Ring.pos or Prio.avail < 0 then
|
||||
Prio.avail = Prio.avail + avail
|
||||
if Prio.Ring.pos and Prio.avail > Prio.Ring.pos[1].nSize then
|
||||
self:Despool(Prio)
|
||||
-- Note: We might not get here if the user-supplied callback function errors out! Take care!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Spooling logic
|
||||
|
||||
function ChatThrottleLib:Enqueue(prioname, pipename, msg)
|
||||
local Prio = self.Prio[prioname]
|
||||
local pipe = Prio.ByName[pipename]
|
||||
if not pipe then
|
||||
self.Frame:Show()
|
||||
pipe = NewPipe()
|
||||
pipe.name = pipename
|
||||
Prio.ByName[pipename] = pipe
|
||||
Prio.Ring:Add(pipe)
|
||||
end
|
||||
|
||||
pipe[#pipe + 1] = msg
|
||||
|
||||
self.bQueueing = true
|
||||
end
|
||||
|
||||
function ChatThrottleLib:SendChatMessage(prio, prefix, text, chattype, language, destination, queueName, callbackFn, callbackArg)
|
||||
if not self or not prio or not prefix or not text or not self.Prio[prio] then
|
||||
error('Usage: ChatThrottleLib:SendChatMessage("{BULK||NORMAL||ALERT}", "prefix", "text"[, "chattype"[, "language"[, "destination"]]]', 2)
|
||||
end
|
||||
if callbackFn and type(callbackFn)~="function" then
|
||||
error('ChatThrottleLib:ChatMessage(): callbackFn: expected function, got '..type(callbackFn), 2)
|
||||
end
|
||||
|
||||
local nSize = text:len()
|
||||
|
||||
if nSize>255 then
|
||||
error("ChatThrottleLib:SendChatMessage(): message length cannot exceed 255 bytes", 2)
|
||||
end
|
||||
|
||||
nSize = nSize + self.MSG_OVERHEAD
|
||||
|
||||
-- Check if there's room in the global available bandwidth gauge to send directly
|
||||
if not self.bQueueing and nSize < self:UpdateAvail() then
|
||||
self.avail = self.avail - nSize
|
||||
bMyTraffic = true
|
||||
_G.SendChatMessage(text, chattype, language, destination)
|
||||
bMyTraffic = false
|
||||
self.Prio[prio].nTotalSent = self.Prio[prio].nTotalSent + nSize
|
||||
if callbackFn then
|
||||
callbackFn (callbackArg, true)
|
||||
end
|
||||
-- USER CALLBACK MAY ERROR
|
||||
return
|
||||
end
|
||||
|
||||
-- Message needs to be queued
|
||||
local msg = NewMsg()
|
||||
msg.f = _G.SendChatMessage
|
||||
msg[1] = text
|
||||
msg[2] = chattype or "SAY"
|
||||
msg[3] = language
|
||||
msg[4] = destination
|
||||
msg.n = 4
|
||||
msg.nSize = nSize
|
||||
msg.callbackFn = callbackFn
|
||||
msg.callbackArg = callbackArg
|
||||
|
||||
self:Enqueue(prio, queueName or (prefix..(chattype or "SAY")..(destination or "")), msg)
|
||||
end
|
||||
|
||||
|
||||
function ChatThrottleLib:SendAddonMessage(prio, prefix, text, chattype, target, queueName, callbackFn, callbackArg)
|
||||
if not self or not prio or not prefix or not text or not chattype or not self.Prio[prio] then
|
||||
error('Usage: ChatThrottleLib:SendAddonMessage("{BULK||NORMAL||ALERT}", "prefix", "text", "chattype"[, "target"])', 2)
|
||||
end
|
||||
if callbackFn and type(callbackFn)~="function" then
|
||||
error('ChatThrottleLib:SendAddonMessage(): callbackFn: expected function, got '..type(callbackFn), 2)
|
||||
end
|
||||
|
||||
local nSize = text:len();
|
||||
|
||||
if C_ChatInfo or RegisterAddonMessagePrefix then
|
||||
if nSize>255 then
|
||||
error("ChatThrottleLib:SendAddonMessage(): message length cannot exceed 255 bytes", 2)
|
||||
end
|
||||
else
|
||||
nSize = nSize + prefix:len() + 1
|
||||
if nSize>255 then
|
||||
error("ChatThrottleLib:SendAddonMessage(): prefix + message length cannot exceed 254 bytes", 2)
|
||||
end
|
||||
end
|
||||
|
||||
nSize = nSize + self.MSG_OVERHEAD;
|
||||
|
||||
-- Check if there's room in the global available bandwidth gauge to send directly
|
||||
if not self.bQueueing and nSize < self:UpdateAvail() then
|
||||
self.avail = self.avail - nSize
|
||||
bMyTraffic = true
|
||||
if _G.C_ChatInfo then
|
||||
_G.C_ChatInfo.SendAddonMessage(prefix, text, chattype, target)
|
||||
else
|
||||
_G.SendAddonMessage(prefix, text, chattype, target)
|
||||
end
|
||||
bMyTraffic = false
|
||||
self.Prio[prio].nTotalSent = self.Prio[prio].nTotalSent + nSize
|
||||
if callbackFn then
|
||||
callbackFn (callbackArg, true)
|
||||
end
|
||||
-- USER CALLBACK MAY ERROR
|
||||
return
|
||||
end
|
||||
|
||||
-- Message needs to be queued
|
||||
local msg = NewMsg()
|
||||
msg.f = _G.C_ChatInfo and _G.C_ChatInfo.SendAddonMessage or _G.SendAddonMessage
|
||||
msg[1] = prefix
|
||||
msg[2] = text
|
||||
msg[3] = chattype
|
||||
msg[4] = target
|
||||
msg.n = (target~=nil) and 4 or 3;
|
||||
msg.nSize = nSize
|
||||
msg.callbackFn = callbackFn
|
||||
msg.callbackArg = callbackArg
|
||||
|
||||
self:Enqueue(prio, queueName or (prefix..chattype..(target or "")), msg)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Get the ball rolling!
|
||||
|
||||
ChatThrottleLib:Init()
|
||||
|
||||
--[[ WoWBench debugging snippet
|
||||
if(WOWB_VER) then
|
||||
local function SayTimer()
|
||||
print("SAY: "..GetTime().." "..arg1)
|
||||
end
|
||||
ChatThrottleLib.Frame:SetScript("OnEvent", SayTimer)
|
||||
ChatThrottleLib.Frame:RegisterEvent("CHAT_MSG_SAY")
|
||||
end
|
||||
]]
|
||||
|
||||
|
||||
250
Libraries/Ace3/AceConsole-3.0/AceConsole-3.0.lua
Normal file
250
Libraries/Ace3/AceConsole-3.0/AceConsole-3.0.lua
Normal file
@@ -0,0 +1,250 @@
|
||||
--- **AceConsole-3.0** provides registration facilities for slash commands.
|
||||
-- You can register slash commands to your custom functions and use the `GetArgs` function to parse them
|
||||
-- to your addons individual needs.
|
||||
--
|
||||
-- **AceConsole-3.0** can be embeded into your addon, either explicitly by calling AceConsole: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 AceConsole itself.\\
|
||||
-- It is recommended to embed AceConsole, otherwise you'll have to specify a custom `self` on all calls you
|
||||
-- make into AceConsole.
|
||||
-- @class file
|
||||
-- @name AceConsole-3.0
|
||||
-- @release $Id$
|
||||
local MAJOR,MINOR = "AceConsole-3.0", 7
|
||||
|
||||
local AceConsole, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceConsole then return end -- No upgrade needed
|
||||
|
||||
AceConsole.embeds = AceConsole.embeds or {} -- table containing objects AceConsole is embedded in.
|
||||
AceConsole.commands = AceConsole.commands or {} -- table containing commands registered
|
||||
AceConsole.weakcommands = AceConsole.weakcommands or {} -- table containing self, command => func references for weak commands that don't persist through enable/disable
|
||||
|
||||
-- Lua APIs
|
||||
local tconcat, tostring, select = table.concat, tostring, select
|
||||
local type, pairs, error = type, pairs, error
|
||||
local format, strfind, strsub = string.format, string.find, string.sub
|
||||
local max = math.max
|
||||
|
||||
-- WoW APIs
|
||||
local _G = _G
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: DEFAULT_CHAT_FRAME, SlashCmdList, hash_SlashCmdList
|
||||
|
||||
local tmp={}
|
||||
local function Print(self,frame,...)
|
||||
local n=0
|
||||
if self ~= AceConsole then
|
||||
n=n+1
|
||||
tmp[n] = "|cff33ff99"..tostring( self ).."|r:"
|
||||
end
|
||||
for i=1, select("#", ...) do
|
||||
n=n+1
|
||||
tmp[n] = tostring(select(i, ...))
|
||||
end
|
||||
frame:AddMessage( tconcat(tmp," ",1,n) )
|
||||
end
|
||||
|
||||
--- Print to DEFAULT_CHAT_FRAME or given ChatFrame (anything with an .AddMessage function)
|
||||
-- @paramsig [chatframe ,] ...
|
||||
-- @param chatframe Custom ChatFrame to print to (or any frame with an .AddMessage function)
|
||||
-- @param ... List of any values to be printed
|
||||
function AceConsole:Print(...)
|
||||
local frame = ...
|
||||
if type(frame) == "table" and frame.AddMessage then -- Is first argument something with an .AddMessage member?
|
||||
return Print(self, frame, select(2,...))
|
||||
else
|
||||
return Print(self, DEFAULT_CHAT_FRAME, ...)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Formatted (using format()) print to DEFAULT_CHAT_FRAME or given ChatFrame (anything with an .AddMessage function)
|
||||
-- @paramsig [chatframe ,] "format"[, ...]
|
||||
-- @param chatframe Custom ChatFrame to print to (or any frame with an .AddMessage function)
|
||||
-- @param format Format string - same syntax as standard Lua format()
|
||||
-- @param ... Arguments to the format string
|
||||
function AceConsole:Printf(...)
|
||||
local frame = ...
|
||||
if type(frame) == "table" and frame.AddMessage then -- Is first argument something with an .AddMessage member?
|
||||
return Print(self, frame, format(select(2,...)))
|
||||
else
|
||||
return Print(self, DEFAULT_CHAT_FRAME, format(...))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Register a simple chat command
|
||||
-- @param command Chat command to be registered WITHOUT leading "/"
|
||||
-- @param func Function to call when the slash command is being used (funcref or methodname)
|
||||
-- @param persist if false, the command will be soft disabled/enabled when aceconsole is used as a mixin (default: true)
|
||||
function AceConsole:RegisterChatCommand( command, func, persist )
|
||||
if type(command)~="string" then error([[Usage: AceConsole:RegisterChatCommand( "command", func[, persist ]): 'command' - expected a string]], 2) end
|
||||
|
||||
if persist==nil then persist=true end -- I'd rather have my addon's "/addon enable" around if the author screws up. Having some extra slash regged when it shouldnt be isn't as destructive. True is a better default. /Mikk
|
||||
|
||||
local name = "ACECONSOLE_"..command:upper()
|
||||
|
||||
if type( func ) == "string" then
|
||||
SlashCmdList[name] = function(input, editBox)
|
||||
self[func](self, input, editBox)
|
||||
end
|
||||
else
|
||||
SlashCmdList[name] = func
|
||||
end
|
||||
_G["SLASH_"..name.."1"] = "/"..command:lower()
|
||||
AceConsole.commands[command] = name
|
||||
-- non-persisting commands are registered for enabling disabling
|
||||
if not persist then
|
||||
if not AceConsole.weakcommands[self] then AceConsole.weakcommands[self] = {} end
|
||||
AceConsole.weakcommands[self][command] = func
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--- Unregister a chatcommand
|
||||
-- @param command Chat command to be unregistered WITHOUT leading "/"
|
||||
function AceConsole:UnregisterChatCommand( command )
|
||||
local name = AceConsole.commands[command]
|
||||
if name then
|
||||
SlashCmdList[name] = nil
|
||||
_G["SLASH_" .. name .. "1"] = nil
|
||||
hash_SlashCmdList["/" .. command:upper()] = nil
|
||||
AceConsole.commands[command] = nil
|
||||
end
|
||||
end
|
||||
|
||||
--- Get an iterator over all Chat Commands registered with AceConsole
|
||||
-- @return Iterator (pairs) over all commands
|
||||
function AceConsole:IterateChatCommands() return pairs(AceConsole.commands) end
|
||||
|
||||
|
||||
local function nils(n, ...)
|
||||
if n>1 then
|
||||
return nil, nils(n-1, ...)
|
||||
elseif n==1 then
|
||||
return nil, ...
|
||||
else
|
||||
return ...
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Retreive one or more space-separated arguments from a string.
|
||||
-- Treats quoted strings and itemlinks as non-spaced.
|
||||
-- @param str The raw argument string
|
||||
-- @param numargs How many arguments to get (default 1)
|
||||
-- @param startpos Where in the string to start scanning (default 1)
|
||||
-- @return Returns arg1, arg2, ..., nextposition\\
|
||||
-- Missing arguments will be returned as nils. 'nextposition' is returned as 1e9 at the end of the string.
|
||||
function AceConsole:GetArgs(str, numargs, startpos)
|
||||
numargs = numargs or 1
|
||||
startpos = max(startpos or 1, 1)
|
||||
|
||||
local pos=startpos
|
||||
|
||||
-- find start of new arg
|
||||
pos = strfind(str, "[^ ]", pos)
|
||||
if not pos then -- whoops, end of string
|
||||
return nils(numargs, 1e9)
|
||||
end
|
||||
|
||||
if numargs<1 then
|
||||
return pos
|
||||
end
|
||||
|
||||
-- quoted or space separated? find out which pattern to use
|
||||
local delim_or_pipe
|
||||
local ch = strsub(str, pos, pos)
|
||||
if ch=='"' then
|
||||
pos = pos + 1
|
||||
delim_or_pipe='([|"])'
|
||||
elseif ch=="'" then
|
||||
pos = pos + 1
|
||||
delim_or_pipe="([|'])"
|
||||
else
|
||||
delim_or_pipe="([| ])"
|
||||
end
|
||||
|
||||
startpos = pos
|
||||
|
||||
while true do
|
||||
-- find delimiter or hyperlink
|
||||
local ch,_
|
||||
pos,_,ch = strfind(str, delim_or_pipe, pos)
|
||||
|
||||
if not pos then break end
|
||||
|
||||
if ch=="|" then
|
||||
-- some kind of escape
|
||||
|
||||
if strsub(str,pos,pos+1)=="|H" then
|
||||
-- It's a |H....|hhyper link!|h
|
||||
pos=strfind(str, "|h", pos+2) -- first |h
|
||||
if not pos then break end
|
||||
|
||||
pos=strfind(str, "|h", pos+2) -- second |h
|
||||
if not pos then break end
|
||||
elseif strsub(str,pos, pos+1) == "|T" then
|
||||
-- It's a |T....|t texture
|
||||
pos=strfind(str, "|t", pos+2)
|
||||
if not pos then break end
|
||||
end
|
||||
|
||||
pos=pos+2 -- skip past this escape (last |h if it was a hyperlink)
|
||||
|
||||
else
|
||||
-- found delimiter, done with this arg
|
||||
return strsub(str, startpos, pos-1), AceConsole:GetArgs(str, numargs-1, pos+1)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- search aborted, we hit end of string. return it all as one argument. (yes, even if it's an unterminated quote or hyperlink)
|
||||
return strsub(str, startpos), nils(numargs-1, 1e9)
|
||||
end
|
||||
|
||||
|
||||
--- embedding and embed handling
|
||||
|
||||
local mixins = {
|
||||
"Print",
|
||||
"Printf",
|
||||
"RegisterChatCommand",
|
||||
"UnregisterChatCommand",
|
||||
"GetArgs",
|
||||
}
|
||||
|
||||
-- Embeds AceConsole into the target object making the functions from the mixins list available on target:..
|
||||
-- @param target target object to embed AceBucket in
|
||||
function AceConsole:Embed( target )
|
||||
for k, v in pairs( mixins ) do
|
||||
target[v] = self[v]
|
||||
end
|
||||
self.embeds[target] = true
|
||||
return target
|
||||
end
|
||||
|
||||
function AceConsole:OnEmbedEnable( target )
|
||||
if AceConsole.weakcommands[target] then
|
||||
for command, func in pairs( AceConsole.weakcommands[target] ) do
|
||||
target:RegisterChatCommand( command, func, false, true ) -- nonpersisting and silent registry
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function AceConsole:OnEmbedDisable( target )
|
||||
if AceConsole.weakcommands[target] then
|
||||
for command, func in pairs( AceConsole.weakcommands[target] ) do
|
||||
target:UnregisterChatCommand( command ) -- TODO: this could potentially unregister a command from another application in case of command conflicts. Do we care?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for addon in pairs(AceConsole.embeds) do
|
||||
AceConsole:Embed(addon)
|
||||
end
|
||||
4
Libraries/Ace3/AceConsole-3.0/AceConsole-3.0.xml
Normal file
4
Libraries/Ace3/AceConsole-3.0/AceConsole-3.0.xml
Normal 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="AceConsole-3.0.lua"/>
|
||||
</Ui>
|
||||
744
Libraries/Ace3/AceDB-3.0/AceDB-3.0.lua
Normal file
744
Libraries/Ace3/AceDB-3.0/AceDB-3.0.lua
Normal file
@@ -0,0 +1,744 @@
|
||||
--- **AceDB-3.0** manages the SavedVariables of your addon.
|
||||
-- It offers profile management, smart defaults and namespaces for modules.\\
|
||||
-- Data can be saved in different data-types, depending on its intended usage.
|
||||
-- The most common data-type is the `profile` type, which allows the user to choose
|
||||
-- the active profile, and manage the profiles of all of his characters.\\
|
||||
-- The following data types are available:
|
||||
-- * **char** Character-specific data. Every character has its own database.
|
||||
-- * **realm** Realm-specific data. All of the players characters on the same realm share this database.
|
||||
-- * **class** Class-specific data. All of the players characters of the same class share this database.
|
||||
-- * **race** Race-specific data. All of the players characters of the same race share this database.
|
||||
-- * **faction** Faction-specific data. All of the players characters of the same faction share this database.
|
||||
-- * **factionrealm** Faction and realm specific data. All of the players characters on the same realm and of the same faction share this database.
|
||||
-- * **locale** Locale specific data, based on the locale of the players game client.
|
||||
-- * **global** Global Data. All characters on the same account share this database.
|
||||
-- * **profile** Profile-specific data. All characters using the same profile share this database. The user can control which profile should be used.
|
||||
--
|
||||
-- Creating a new Database using the `:New` function will return a new DBObject. A database will inherit all functions
|
||||
-- of the DBObjectLib listed here. \\
|
||||
-- If you create a new namespaced child-database (`:RegisterNamespace`), you'll get a DBObject as well, but note
|
||||
-- that the child-databases cannot individually change their profile, and are linked to their parents profile - and because of that,
|
||||
-- the profile related APIs are not available. Only `:RegisterDefaults` and `:ResetProfile` are available on child-databases.
|
||||
--
|
||||
-- For more details on how to use AceDB-3.0, see the [[AceDB-3.0 Tutorial]].
|
||||
--
|
||||
-- You may also be interested in [[libdualspec-1-0|LibDualSpec-1.0]] to do profile switching automatically when switching specs.
|
||||
--
|
||||
-- @usage
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("DBExample")
|
||||
--
|
||||
-- -- declare defaults to be used in the DB
|
||||
-- local defaults = {
|
||||
-- profile = {
|
||||
-- setting = true,
|
||||
-- }
|
||||
-- }
|
||||
--
|
||||
-- function MyAddon:OnInitialize()
|
||||
-- -- Assuming the .toc says ## SavedVariables: MyAddonDB
|
||||
-- self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, true)
|
||||
-- end
|
||||
-- @class file
|
||||
-- @name AceDB-3.0.lua
|
||||
-- @release $Id$
|
||||
local ACEDB_MAJOR, ACEDB_MINOR = "AceDB-3.0", 27
|
||||
local AceDB = LibStub:NewLibrary(ACEDB_MAJOR, ACEDB_MINOR)
|
||||
|
||||
if not AceDB then return end -- No upgrade needed
|
||||
|
||||
-- Lua APIs
|
||||
local type, pairs, next, error = type, pairs, next, error
|
||||
local setmetatable, rawset, rawget = setmetatable, rawset, rawget
|
||||
|
||||
-- WoW APIs
|
||||
local _G = _G
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: LibStub
|
||||
|
||||
AceDB.db_registry = AceDB.db_registry or {}
|
||||
AceDB.frame = AceDB.frame or CreateFrame("Frame")
|
||||
|
||||
local CallbackHandler
|
||||
local CallbackDummy = { Fire = function() end }
|
||||
|
||||
local DBObjectLib = {}
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
AceDB Utility Functions
|
||||
---------------------------------------------------------------------------]]
|
||||
|
||||
-- Simple shallow copy for copying defaults
|
||||
local function copyTable(src, dest)
|
||||
if type(dest) ~= "table" then dest = {} end
|
||||
if type(src) == "table" then
|
||||
for k,v in pairs(src) do
|
||||
if type(v) == "table" then
|
||||
-- try to index the key first so that the metatable creates the defaults, if set, and use that table
|
||||
v = copyTable(v, dest[k])
|
||||
end
|
||||
dest[k] = v
|
||||
end
|
||||
end
|
||||
return dest
|
||||
end
|
||||
|
||||
-- Called to add defaults to a section of the database
|
||||
--
|
||||
-- When a ["*"] default section is indexed with a new key, a table is returned
|
||||
-- and set in the host table. These tables must be cleaned up by removeDefaults
|
||||
-- in order to ensure we don't write empty default tables.
|
||||
local function copyDefaults(dest, src)
|
||||
-- this happens if some value in the SV overwrites our default value with a non-table
|
||||
--if type(dest) ~= "table" then return end
|
||||
for k, v in pairs(src) do
|
||||
if k == "*" or k == "**" then
|
||||
if type(v) == "table" then
|
||||
-- This is a metatable used for table defaults
|
||||
local mt = {
|
||||
-- This handles the lookup and creation of new subtables
|
||||
__index = function(t,k)
|
||||
if k == nil then return nil end
|
||||
local tbl = {}
|
||||
copyDefaults(tbl, v)
|
||||
rawset(t, k, tbl)
|
||||
return tbl
|
||||
end,
|
||||
}
|
||||
setmetatable(dest, mt)
|
||||
-- handle already existing tables in the SV
|
||||
for dk, dv in pairs(dest) do
|
||||
if not rawget(src, dk) and type(dv) == "table" then
|
||||
copyDefaults(dv, v)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- Values are not tables, so this is just a simple return
|
||||
local mt = {__index = function(t,k) return k~=nil and v or nil end}
|
||||
setmetatable(dest, mt)
|
||||
end
|
||||
elseif type(v) == "table" then
|
||||
if not rawget(dest, k) then rawset(dest, k, {}) end
|
||||
if type(dest[k]) == "table" then
|
||||
copyDefaults(dest[k], v)
|
||||
if src['**'] then
|
||||
copyDefaults(dest[k], src['**'])
|
||||
end
|
||||
end
|
||||
else
|
||||
if rawget(dest, k) == nil then
|
||||
rawset(dest, k, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Called to remove all defaults in the default table from the database
|
||||
local function removeDefaults(db, defaults, blocker)
|
||||
-- remove all metatables from the db, so we don't accidentally create new sub-tables through them
|
||||
setmetatable(db, nil)
|
||||
-- loop through the defaults and remove their content
|
||||
for k,v in pairs(defaults) do
|
||||
if k == "*" or k == "**" then
|
||||
if type(v) == "table" then
|
||||
-- Loop through all the actual k,v pairs and remove
|
||||
for key, value in pairs(db) do
|
||||
if type(value) == "table" then
|
||||
-- if the key was not explicitly specified in the defaults table, just strip everything from * and ** tables
|
||||
if defaults[key] == nil and (not blocker or blocker[key] == nil) then
|
||||
removeDefaults(value, v)
|
||||
-- if the table is empty afterwards, remove it
|
||||
if next(value) == nil then
|
||||
db[key] = nil
|
||||
end
|
||||
-- if it was specified, only strip ** content, but block values which were set in the key table
|
||||
elseif k == "**" then
|
||||
removeDefaults(value, v, defaults[key])
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif k == "*" then
|
||||
-- check for non-table default
|
||||
for key, value in pairs(db) do
|
||||
if defaults[key] == nil and v == value then
|
||||
db[key] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif type(v) == "table" and type(db[k]) == "table" then
|
||||
-- if a blocker was set, dive into it, to allow multi-level defaults
|
||||
removeDefaults(db[k], v, blocker and blocker[k])
|
||||
if next(db[k]) == nil then
|
||||
db[k] = nil
|
||||
end
|
||||
else
|
||||
-- check if the current value matches the default, and that its not blocked by another defaults table
|
||||
if db[k] == defaults[k] and (not blocker or blocker[k] == nil) then
|
||||
db[k] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- This is called when a table section is first accessed, to set up the defaults
|
||||
local function initSection(db, section, svstore, key, defaults)
|
||||
local sv = rawget(db, "sv")
|
||||
|
||||
local tableCreated
|
||||
if not sv[svstore] then sv[svstore] = {} end
|
||||
if not sv[svstore][key] then
|
||||
sv[svstore][key] = {}
|
||||
tableCreated = true
|
||||
end
|
||||
|
||||
local tbl = sv[svstore][key]
|
||||
|
||||
if defaults then
|
||||
copyDefaults(tbl, defaults)
|
||||
end
|
||||
rawset(db, section, tbl)
|
||||
|
||||
return tableCreated, tbl
|
||||
end
|
||||
|
||||
-- Metatable to handle the dynamic creation of sections and copying of sections.
|
||||
local dbmt = {
|
||||
__index = function(t, section)
|
||||
local keys = rawget(t, "keys")
|
||||
local key = keys[section]
|
||||
if key then
|
||||
local defaultTbl = rawget(t, "defaults")
|
||||
local defaults = defaultTbl and defaultTbl[section]
|
||||
|
||||
if section == "profile" then
|
||||
local new = initSection(t, section, "profiles", key, defaults)
|
||||
if new then
|
||||
-- Callback: OnNewProfile, database, newProfileKey
|
||||
t.callbacks:Fire("OnNewProfile", t, key)
|
||||
end
|
||||
elseif section == "profiles" then
|
||||
local sv = rawget(t, "sv")
|
||||
if not sv.profiles then sv.profiles = {} end
|
||||
rawset(t, "profiles", sv.profiles)
|
||||
elseif section == "global" then
|
||||
local sv = rawget(t, "sv")
|
||||
if not sv.global then sv.global = {} end
|
||||
if defaults then
|
||||
copyDefaults(sv.global, defaults)
|
||||
end
|
||||
rawset(t, section, sv.global)
|
||||
else
|
||||
initSection(t, section, section, key, defaults)
|
||||
end
|
||||
end
|
||||
|
||||
return rawget(t, section)
|
||||
end
|
||||
}
|
||||
|
||||
local function validateDefaults(defaults, keyTbl, offset)
|
||||
if not defaults then return end
|
||||
offset = offset or 0
|
||||
for k in pairs(defaults) do
|
||||
if not keyTbl[k] or k == "profiles" then
|
||||
error(("Usage: AceDBObject:RegisterDefaults(defaults): '%s' is not a valid datatype."):format(k), 3 + offset)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local preserve_keys = {
|
||||
["callbacks"] = true,
|
||||
["RegisterCallback"] = true,
|
||||
["UnregisterCallback"] = true,
|
||||
["UnregisterAllCallbacks"] = true,
|
||||
["children"] = true,
|
||||
}
|
||||
|
||||
local realmKey = GetRealmName()
|
||||
local charKey = UnitName("player") .. " - " .. realmKey
|
||||
local _, classKey = UnitClass("player")
|
||||
local _, raceKey = UnitRace("player")
|
||||
local factionKey = UnitFactionGroup("player")
|
||||
local factionrealmKey = factionKey .. " - " .. realmKey
|
||||
local localeKey = GetLocale():lower()
|
||||
|
||||
local regionTable = { "US", "KR", "EU", "TW", "CN" }
|
||||
local regionKey = regionTable[GetCurrentRegion()]
|
||||
local factionrealmregionKey = factionrealmKey .. " - " .. regionKey
|
||||
|
||||
-- Actual database initialization function
|
||||
local function initdb(sv, defaults, defaultProfile, olddb, parent)
|
||||
-- Generate the database keys for each section
|
||||
|
||||
-- map "true" to our "Default" profile
|
||||
if defaultProfile == true then defaultProfile = "Default" end
|
||||
|
||||
local profileKey
|
||||
if not parent then
|
||||
-- Make a container for profile keys
|
||||
if not sv.profileKeys then sv.profileKeys = {} end
|
||||
|
||||
-- Try to get the profile selected from the char db
|
||||
profileKey = sv.profileKeys[charKey] or defaultProfile or charKey
|
||||
|
||||
-- save the selected profile for later
|
||||
sv.profileKeys[charKey] = profileKey
|
||||
else
|
||||
-- Use the profile of the parents DB
|
||||
profileKey = parent.keys.profile or defaultProfile or charKey
|
||||
|
||||
-- clear the profileKeys in the DB, namespaces don't need to store them
|
||||
sv.profileKeys = nil
|
||||
end
|
||||
|
||||
-- This table contains keys that enable the dynamic creation
|
||||
-- of each section of the table. The 'global' and 'profiles'
|
||||
-- have a key of true, since they are handled in a special case
|
||||
local keyTbl= {
|
||||
["char"] = charKey,
|
||||
["realm"] = realmKey,
|
||||
["class"] = classKey,
|
||||
["race"] = raceKey,
|
||||
["faction"] = factionKey,
|
||||
["factionrealm"] = factionrealmKey,
|
||||
["factionrealmregion"] = factionrealmregionKey,
|
||||
["profile"] = profileKey,
|
||||
["locale"] = localeKey,
|
||||
["global"] = true,
|
||||
["profiles"] = true,
|
||||
}
|
||||
|
||||
validateDefaults(defaults, keyTbl, 1)
|
||||
|
||||
-- This allows us to use this function to reset an entire database
|
||||
-- Clear out the old database
|
||||
if olddb then
|
||||
for k,v in pairs(olddb) do if not preserve_keys[k] then olddb[k] = nil end end
|
||||
end
|
||||
|
||||
-- Give this database the metatable so it initializes dynamically
|
||||
local db = setmetatable(olddb or {}, dbmt)
|
||||
|
||||
if not rawget(db, "callbacks") then
|
||||
-- try to load CallbackHandler-1.0 if it loaded after our library
|
||||
if not CallbackHandler then CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0", true) end
|
||||
db.callbacks = CallbackHandler and CallbackHandler:New(db) or CallbackDummy
|
||||
end
|
||||
|
||||
-- Copy methods locally into the database object, to avoid hitting
|
||||
-- the metatable when calling methods
|
||||
|
||||
if not parent then
|
||||
for name, func in pairs(DBObjectLib) do
|
||||
db[name] = func
|
||||
end
|
||||
else
|
||||
-- hack this one in
|
||||
db.RegisterDefaults = DBObjectLib.RegisterDefaults
|
||||
db.ResetProfile = DBObjectLib.ResetProfile
|
||||
end
|
||||
|
||||
-- Set some properties in the database object
|
||||
db.profiles = sv.profiles
|
||||
db.keys = keyTbl
|
||||
db.sv = sv
|
||||
--db.sv_name = name
|
||||
db.defaults = defaults
|
||||
db.parent = parent
|
||||
|
||||
-- store the DB in the registry
|
||||
AceDB.db_registry[db] = true
|
||||
|
||||
return db
|
||||
end
|
||||
|
||||
-- handle PLAYER_LOGOUT
|
||||
-- strip all defaults from all databases
|
||||
-- and cleans up empty sections
|
||||
local function logoutHandler(frame, event)
|
||||
if event == "PLAYER_LOGOUT" then
|
||||
for db in pairs(AceDB.db_registry) do
|
||||
db.callbacks:Fire("OnDatabaseShutdown", db)
|
||||
db:RegisterDefaults(nil)
|
||||
|
||||
-- cleanup sections that are empty without defaults
|
||||
local sv = rawget(db, "sv")
|
||||
for section in pairs(db.keys) do
|
||||
if rawget(sv, section) then
|
||||
-- global is special, all other sections have sub-entrys
|
||||
-- also don't delete empty profiles on main dbs, only on namespaces
|
||||
if section ~= "global" and (section ~= "profiles" or rawget(db, "parent")) then
|
||||
for key in pairs(sv[section]) do
|
||||
if not next(sv[section][key]) then
|
||||
sv[section][key] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
if not next(sv[section]) then
|
||||
sv[section] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
AceDB.frame:RegisterEvent("PLAYER_LOGOUT")
|
||||
AceDB.frame:SetScript("OnEvent", logoutHandler)
|
||||
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
AceDB Object Method Definitions
|
||||
---------------------------------------------------------------------------]]
|
||||
|
||||
--- Sets the defaults table for the given database object by clearing any
|
||||
-- that are currently set, and then setting the new defaults.
|
||||
-- @param defaults A table of defaults for this database
|
||||
function DBObjectLib:RegisterDefaults(defaults)
|
||||
if defaults and type(defaults) ~= "table" then
|
||||
error(("Usage: AceDBObject:RegisterDefaults(defaults): 'defaults' - table or nil expected, got %q."):format(type(defaults)), 2)
|
||||
end
|
||||
|
||||
validateDefaults(defaults, self.keys)
|
||||
|
||||
-- Remove any currently set defaults
|
||||
if self.defaults then
|
||||
for section,key in pairs(self.keys) do
|
||||
if self.defaults[section] and rawget(self, section) then
|
||||
removeDefaults(self[section], self.defaults[section])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Set the DBObject.defaults table
|
||||
self.defaults = defaults
|
||||
|
||||
-- Copy in any defaults, only touching those sections already created
|
||||
if defaults then
|
||||
for section,key in pairs(self.keys) do
|
||||
if defaults[section] and rawget(self, section) then
|
||||
copyDefaults(self[section], defaults[section])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Changes the profile of the database and all of it's namespaces to the
|
||||
-- supplied named profile
|
||||
-- @param name The name of the profile to set as the current profile
|
||||
function DBObjectLib:SetProfile(name)
|
||||
if type(name) ~= "string" then
|
||||
error(("Usage: AceDBObject:SetProfile(name): 'name' - string expected, got %q."):format(type(name)), 2)
|
||||
end
|
||||
|
||||
-- changing to the same profile, dont do anything
|
||||
if name == self.keys.profile then return end
|
||||
|
||||
local oldProfile = self.profile
|
||||
local defaults = self.defaults and self.defaults.profile
|
||||
|
||||
-- Callback: OnProfileShutdown, database
|
||||
self.callbacks:Fire("OnProfileShutdown", self)
|
||||
|
||||
if oldProfile and defaults then
|
||||
-- Remove the defaults from the old profile
|
||||
removeDefaults(oldProfile, defaults)
|
||||
end
|
||||
|
||||
self.profile = nil
|
||||
self.keys["profile"] = name
|
||||
|
||||
-- if the storage exists, save the new profile
|
||||
-- this won't exist on namespaces.
|
||||
if self.sv.profileKeys then
|
||||
self.sv.profileKeys[charKey] = name
|
||||
end
|
||||
|
||||
-- populate to child namespaces
|
||||
if self.children then
|
||||
for _, db in pairs(self.children) do
|
||||
DBObjectLib.SetProfile(db, name)
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback: OnProfileChanged, database, newProfileKey
|
||||
self.callbacks:Fire("OnProfileChanged", self, name)
|
||||
end
|
||||
|
||||
--- Returns a table with the names of the existing profiles in the database.
|
||||
-- You can optionally supply a table to re-use for this purpose.
|
||||
-- @param tbl A table to store the profile names in (optional)
|
||||
function DBObjectLib:GetProfiles(tbl)
|
||||
if tbl and type(tbl) ~= "table" then
|
||||
error(("Usage: AceDBObject:GetProfiles(tbl): 'tbl' - table or nil expected, got %q."):format(type(tbl)), 2)
|
||||
end
|
||||
|
||||
-- Clear the container table
|
||||
if tbl then
|
||||
for k,v in pairs(tbl) do tbl[k] = nil end
|
||||
else
|
||||
tbl = {}
|
||||
end
|
||||
|
||||
local curProfile = self.keys.profile
|
||||
|
||||
local i = 0
|
||||
for profileKey in pairs(self.profiles) do
|
||||
i = i + 1
|
||||
tbl[i] = profileKey
|
||||
if curProfile and profileKey == curProfile then curProfile = nil end
|
||||
end
|
||||
|
||||
-- Add the current profile, if it hasn't been created yet
|
||||
if curProfile then
|
||||
i = i + 1
|
||||
tbl[i] = curProfile
|
||||
end
|
||||
|
||||
return tbl, i
|
||||
end
|
||||
|
||||
--- Returns the current profile name used by the database
|
||||
function DBObjectLib:GetCurrentProfile()
|
||||
return self.keys.profile
|
||||
end
|
||||
|
||||
--- Deletes a named profile. This profile must not be the active profile.
|
||||
-- @param name The name of the profile to be deleted
|
||||
-- @param silent If true, do not raise an error when the profile does not exist
|
||||
function DBObjectLib:DeleteProfile(name, silent)
|
||||
if type(name) ~= "string" then
|
||||
error(("Usage: AceDBObject:DeleteProfile(name): 'name' - string expected, got %q."):format(type(name)), 2)
|
||||
end
|
||||
|
||||
if self.keys.profile == name then
|
||||
error(("Cannot delete the active profile (%q) in an AceDBObject."):format(name), 2)
|
||||
end
|
||||
|
||||
if not rawget(self.profiles, name) and not silent then
|
||||
error(("Cannot delete profile %q as it does not exist."):format(name), 2)
|
||||
end
|
||||
|
||||
self.profiles[name] = nil
|
||||
|
||||
-- populate to child namespaces
|
||||
if self.children then
|
||||
for _, db in pairs(self.children) do
|
||||
DBObjectLib.DeleteProfile(db, name, true)
|
||||
end
|
||||
end
|
||||
|
||||
-- switch all characters that use this profile back to the default
|
||||
if self.sv.profileKeys then
|
||||
for key, profile in pairs(self.sv.profileKeys) do
|
||||
if profile == name then
|
||||
self.sv.profileKeys[key] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback: OnProfileDeleted, database, profileKey
|
||||
self.callbacks:Fire("OnProfileDeleted", self, name)
|
||||
end
|
||||
|
||||
--- Copies a named profile into the current profile, overwriting any conflicting
|
||||
-- settings.
|
||||
-- @param name The name of the profile to be copied into the current profile
|
||||
-- @param silent If true, do not raise an error when the profile does not exist
|
||||
function DBObjectLib:CopyProfile(name, silent)
|
||||
if type(name) ~= "string" then
|
||||
error(("Usage: AceDBObject:CopyProfile(name): 'name' - string expected, got %q."):format(type(name)), 2)
|
||||
end
|
||||
|
||||
if name == self.keys.profile then
|
||||
error(("Cannot have the same source and destination profiles (%q)."):format(name), 2)
|
||||
end
|
||||
|
||||
if not rawget(self.profiles, name) and not silent then
|
||||
error(("Cannot copy profile %q as it does not exist."):format(name), 2)
|
||||
end
|
||||
|
||||
-- Reset the profile before copying
|
||||
DBObjectLib.ResetProfile(self, nil, true)
|
||||
|
||||
local profile = self.profile
|
||||
local source = self.profiles[name]
|
||||
|
||||
copyTable(source, profile)
|
||||
|
||||
-- populate to child namespaces
|
||||
if self.children then
|
||||
for _, db in pairs(self.children) do
|
||||
DBObjectLib.CopyProfile(db, name, true)
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback: OnProfileCopied, database, sourceProfileKey
|
||||
self.callbacks:Fire("OnProfileCopied", self, name)
|
||||
end
|
||||
|
||||
--- Resets the current profile to the default values (if specified).
|
||||
-- @param noChildren if set to true, the reset will not be populated to the child namespaces of this DB object
|
||||
-- @param noCallbacks if set to true, won't fire the OnProfileReset callback
|
||||
function DBObjectLib:ResetProfile(noChildren, noCallbacks)
|
||||
local profile = self.profile
|
||||
|
||||
for k,v in pairs(profile) do
|
||||
profile[k] = nil
|
||||
end
|
||||
|
||||
local defaults = self.defaults and self.defaults.profile
|
||||
if defaults then
|
||||
copyDefaults(profile, defaults)
|
||||
end
|
||||
|
||||
-- populate to child namespaces
|
||||
if self.children and not noChildren then
|
||||
for _, db in pairs(self.children) do
|
||||
DBObjectLib.ResetProfile(db, nil, noCallbacks)
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback: OnProfileReset, database
|
||||
if not noCallbacks then
|
||||
self.callbacks:Fire("OnProfileReset", self)
|
||||
end
|
||||
end
|
||||
|
||||
--- Resets the entire database, using the string defaultProfile as the new default
|
||||
-- profile.
|
||||
-- @param defaultProfile The profile name to use as the default
|
||||
function DBObjectLib:ResetDB(defaultProfile)
|
||||
if defaultProfile and type(defaultProfile) ~= "string" then
|
||||
error(("Usage: AceDBObject:ResetDB(defaultProfile): 'defaultProfile' - string or nil expected, got %q."):format(type(defaultProfile)), 2)
|
||||
end
|
||||
|
||||
local sv = self.sv
|
||||
for k,v in pairs(sv) do
|
||||
sv[k] = nil
|
||||
end
|
||||
|
||||
initdb(sv, self.defaults, defaultProfile, self)
|
||||
|
||||
-- fix the child namespaces
|
||||
if self.children then
|
||||
if not sv.namespaces then sv.namespaces = {} end
|
||||
for name, db in pairs(self.children) do
|
||||
if not sv.namespaces[name] then sv.namespaces[name] = {} end
|
||||
initdb(sv.namespaces[name], db.defaults, self.keys.profile, db, self)
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback: OnDatabaseReset, database
|
||||
self.callbacks:Fire("OnDatabaseReset", self)
|
||||
-- Callback: OnProfileChanged, database, profileKey
|
||||
self.callbacks:Fire("OnProfileChanged", self, self.keys["profile"])
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Creates a new database namespace, directly tied to the database. This
|
||||
-- is a full scale database in it's own rights other than the fact that
|
||||
-- it cannot control its profile individually
|
||||
-- @param name The name of the new namespace
|
||||
-- @param defaults A table of values to use as defaults
|
||||
function DBObjectLib:RegisterNamespace(name, defaults)
|
||||
if type(name) ~= "string" then
|
||||
error(("Usage: AceDBObject:RegisterNamespace(name, defaults): 'name' - string expected, got %q."):format(type(name)), 2)
|
||||
end
|
||||
if defaults and type(defaults) ~= "table" then
|
||||
error(("Usage: AceDBObject:RegisterNamespace(name, defaults): 'defaults' - table or nil expected, got %q."):format(type(defaults)), 2)
|
||||
end
|
||||
if self.children and self.children[name] then
|
||||
error(("Usage: AceDBObject:RegisterNamespace(name, defaults): 'name' - a namespace called %q already exists."):format(name), 2)
|
||||
end
|
||||
|
||||
local sv = self.sv
|
||||
if not sv.namespaces then sv.namespaces = {} end
|
||||
if not sv.namespaces[name] then
|
||||
sv.namespaces[name] = {}
|
||||
end
|
||||
|
||||
local newDB = initdb(sv.namespaces[name], defaults, self.keys.profile, nil, self)
|
||||
|
||||
if not self.children then self.children = {} end
|
||||
self.children[name] = newDB
|
||||
return newDB
|
||||
end
|
||||
|
||||
--- Returns an already existing namespace from the database object.
|
||||
-- @param name The name of the new namespace
|
||||
-- @param silent if true, the addon is optional, silently return nil if its not found
|
||||
-- @usage
|
||||
-- local namespace = self.db:GetNamespace('namespace')
|
||||
-- @return the namespace object if found
|
||||
function DBObjectLib:GetNamespace(name, silent)
|
||||
if type(name) ~= "string" then
|
||||
error(("Usage: AceDBObject:GetNamespace(name): 'name' - string expected, got %q."):format(type(name)), 2)
|
||||
end
|
||||
if not silent and not (self.children and self.children[name]) then
|
||||
error(("Usage: AceDBObject:GetNamespace(name): 'name' - namespace %q does not exist."):format(name), 2)
|
||||
end
|
||||
if not self.children then self.children = {} end
|
||||
return self.children[name]
|
||||
end
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
AceDB Exposed Methods
|
||||
---------------------------------------------------------------------------]]
|
||||
|
||||
--- Creates a new database object that can be used to handle database settings and profiles.
|
||||
-- By default, an empty DB is created, using a character specific profile.
|
||||
--
|
||||
-- You can override the default profile used by passing any profile name as the third argument,
|
||||
-- or by passing //true// as the third argument to use a globally shared profile called "Default".
|
||||
--
|
||||
-- Note that there is no token replacement in the default profile name, passing a defaultProfile as "char"
|
||||
-- will use a profile named "char", and not a character-specific profile.
|
||||
-- @param tbl The name of variable, or table to use for the database
|
||||
-- @param defaults A table of database defaults
|
||||
-- @param defaultProfile The name of the default profile. If not set, a character specific profile will be used as the default.
|
||||
-- You can also pass //true// to use a shared global profile called "Default".
|
||||
-- @usage
|
||||
-- -- Create an empty DB using a character-specific default profile.
|
||||
-- self.db = LibStub("AceDB-3.0"):New("MyAddonDB")
|
||||
-- @usage
|
||||
-- -- Create a DB using defaults and using a shared default profile
|
||||
-- self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, true)
|
||||
function AceDB:New(tbl, defaults, defaultProfile)
|
||||
if type(tbl) == "string" then
|
||||
local name = tbl
|
||||
tbl = _G[name]
|
||||
if not tbl then
|
||||
tbl = {}
|
||||
_G[name] = tbl
|
||||
end
|
||||
end
|
||||
|
||||
if type(tbl) ~= "table" then
|
||||
error(("Usage: AceDB:New(tbl, defaults, defaultProfile): 'tbl' - table expected, got %q."):format(type(tbl)), 2)
|
||||
end
|
||||
|
||||
if defaults and type(defaults) ~= "table" then
|
||||
error(("Usage: AceDB:New(tbl, defaults, defaultProfile): 'defaults' - table expected, got %q."):format(type(defaults)), 2)
|
||||
end
|
||||
|
||||
if defaultProfile and type(defaultProfile) ~= "string" and defaultProfile ~= true then
|
||||
error(("Usage: AceDB:New(tbl, defaults, defaultProfile): 'defaultProfile' - string or true expected, got %q."):format(type(defaultProfile)), 2)
|
||||
end
|
||||
|
||||
return initdb(tbl, defaults, defaultProfile)
|
||||
end
|
||||
|
||||
-- upgrade existing databases
|
||||
for db in pairs(AceDB.db_registry) do
|
||||
if not db.parent then
|
||||
for name,func in pairs(DBObjectLib) do
|
||||
db[name] = func
|
||||
end
|
||||
else
|
||||
db.RegisterDefaults = DBObjectLib.RegisterDefaults
|
||||
db.ResetProfile = DBObjectLib.ResetProfile
|
||||
end
|
||||
end
|
||||
4
Libraries/Ace3/AceDB-3.0/AceDB-3.0.xml
Normal file
4
Libraries/Ace3/AceDB-3.0/AceDB-3.0.xml
Normal 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="AceDB-3.0.lua"/>
|
||||
</Ui>
|
||||
126
Libraries/Ace3/AceEvent-3.0/AceEvent-3.0.lua
Normal file
126
Libraries/Ace3/AceEvent-3.0/AceEvent-3.0.lua
Normal file
@@ -0,0 +1,126 @@
|
||||
--- AceEvent-3.0 provides event registration and secure dispatching.
|
||||
-- All dispatching is done using **CallbackHandler-1.0**. AceEvent is a simple wrapper around
|
||||
-- CallbackHandler, and dispatches all game events or addon message to the registrees.
|
||||
--
|
||||
-- **AceEvent-3.0** can be embeded into your addon, either explicitly by calling AceEvent: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 AceEvent itself.\\
|
||||
-- It is recommended to embed AceEvent, otherwise you'll have to specify a custom `self` on all calls you
|
||||
-- make into AceEvent.
|
||||
-- @class file
|
||||
-- @name AceEvent-3.0
|
||||
-- @release $Id$
|
||||
local CallbackHandler = LibStub("CallbackHandler-1.0")
|
||||
|
||||
local MAJOR, MINOR = "AceEvent-3.0", 4
|
||||
local AceEvent = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceEvent then return end
|
||||
|
||||
-- Lua APIs
|
||||
local pairs = pairs
|
||||
|
||||
AceEvent.frame = AceEvent.frame or CreateFrame("Frame", "AceEvent30Frame") -- our event frame
|
||||
AceEvent.embeds = AceEvent.embeds or {} -- what objects embed this lib
|
||||
|
||||
-- APIs and registry for blizzard events, using CallbackHandler lib
|
||||
if not AceEvent.events then
|
||||
AceEvent.events = CallbackHandler:New(AceEvent,
|
||||
"RegisterEvent", "UnregisterEvent", "UnregisterAllEvents")
|
||||
end
|
||||
|
||||
function AceEvent.events:OnUsed(target, eventname)
|
||||
AceEvent.frame:RegisterEvent(eventname)
|
||||
end
|
||||
|
||||
function AceEvent.events:OnUnused(target, eventname)
|
||||
AceEvent.frame:UnregisterEvent(eventname)
|
||||
end
|
||||
|
||||
|
||||
-- APIs and registry for IPC messages, using CallbackHandler lib
|
||||
if not AceEvent.messages then
|
||||
AceEvent.messages = CallbackHandler:New(AceEvent,
|
||||
"RegisterMessage", "UnregisterMessage", "UnregisterAllMessages"
|
||||
)
|
||||
AceEvent.SendMessage = AceEvent.messages.Fire
|
||||
end
|
||||
|
||||
--- embedding and embed handling
|
||||
local mixins = {
|
||||
"RegisterEvent", "UnregisterEvent",
|
||||
"RegisterMessage", "UnregisterMessage",
|
||||
"SendMessage",
|
||||
"UnregisterAllEvents", "UnregisterAllMessages",
|
||||
}
|
||||
|
||||
--- Register for a Blizzard Event.
|
||||
-- The callback will be called with the optional `arg` as the first argument (if supplied), and the event name as the second (or first, if no arg was supplied)
|
||||
-- Any arguments to the event will be passed on after that.
|
||||
-- @name AceEvent:RegisterEvent
|
||||
-- @class function
|
||||
-- @paramsig event[, callback [, arg]]
|
||||
-- @param event The event to register for
|
||||
-- @param callback The callback function to call when the event is triggered (funcref or method, defaults to a method with the event name)
|
||||
-- @param arg An optional argument to pass to the callback function
|
||||
|
||||
--- Unregister an event.
|
||||
-- @name AceEvent:UnregisterEvent
|
||||
-- @class function
|
||||
-- @paramsig event
|
||||
-- @param event The event to unregister
|
||||
|
||||
--- Register for a custom AceEvent-internal message.
|
||||
-- The callback will be called with the optional `arg` as the first argument (if supplied), and the event name as the second (or first, if no arg was supplied)
|
||||
-- Any arguments to the event will be passed on after that.
|
||||
-- @name AceEvent:RegisterMessage
|
||||
-- @class function
|
||||
-- @paramsig message[, callback [, arg]]
|
||||
-- @param message The message to register for
|
||||
-- @param callback The callback function to call when the message is triggered (funcref or method, defaults to a method with the event name)
|
||||
-- @param arg An optional argument to pass to the callback function
|
||||
|
||||
--- Unregister a message
|
||||
-- @name AceEvent:UnregisterMessage
|
||||
-- @class function
|
||||
-- @paramsig message
|
||||
-- @param message The message to unregister
|
||||
|
||||
--- Send a message over the AceEvent-3.0 internal message system to other addons registered for this message.
|
||||
-- @name AceEvent:SendMessage
|
||||
-- @class function
|
||||
-- @paramsig message, ...
|
||||
-- @param message The message to send
|
||||
-- @param ... Any arguments to the message
|
||||
|
||||
|
||||
-- Embeds AceEvent into the target object making the functions from the mixins list available on target:..
|
||||
-- @param target target object to embed AceEvent in
|
||||
function AceEvent:Embed(target)
|
||||
for k, v in pairs(mixins) do
|
||||
target[v] = self[v]
|
||||
end
|
||||
self.embeds[target] = true
|
||||
return target
|
||||
end
|
||||
|
||||
-- AceEvent:OnEmbedDisable( target )
|
||||
-- target (object) - target object that is being disabled
|
||||
--
|
||||
-- Unregister all events messages etc when the target disables.
|
||||
-- this method should be called by the target manually or by an addon framework
|
||||
function AceEvent:OnEmbedDisable(target)
|
||||
target:UnregisterAllEvents()
|
||||
target:UnregisterAllMessages()
|
||||
end
|
||||
|
||||
-- Script to fire blizzard events into the event listeners
|
||||
local events = AceEvent.events
|
||||
AceEvent.frame:SetScript("OnEvent", function(this, event, ...)
|
||||
events:Fire(event, ...)
|
||||
end)
|
||||
|
||||
--- Finally: upgrade our old embeds
|
||||
for target, v in pairs(AceEvent.embeds) do
|
||||
AceEvent:Embed(target)
|
||||
end
|
||||
4
Libraries/Ace3/AceEvent-3.0/AceEvent-3.0.xml
Normal file
4
Libraries/Ace3/AceEvent-3.0/AceEvent-3.0.xml
Normal 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="AceEvent-3.0.lua"/>
|
||||
</Ui>
|
||||
511
Libraries/Ace3/AceHook-3.0/AceHook-3.0.lua
Normal file
511
Libraries/Ace3/AceHook-3.0/AceHook-3.0.lua
Normal file
@@ -0,0 +1,511 @@
|
||||
--- **AceHook-3.0** offers safe Hooking/Unhooking of functions, methods and frame scripts.
|
||||
-- Using AceHook-3.0 is recommended when you need to unhook your hooks again, so the hook chain isn't broken
|
||||
-- when you manually restore the original function.
|
||||
--
|
||||
-- **AceHook-3.0** can be embeded into your addon, either explicitly by calling AceHook: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 AceHook itself.\\
|
||||
-- It is recommended to embed AceHook, otherwise you'll have to specify a custom `self` on all calls you
|
||||
-- make into AceHook.
|
||||
-- @class file
|
||||
-- @name AceHook-3.0
|
||||
-- @release $Id$
|
||||
local ACEHOOK_MAJOR, ACEHOOK_MINOR = "AceHook-3.0", 8
|
||||
local AceHook, oldminor = LibStub:NewLibrary(ACEHOOK_MAJOR, ACEHOOK_MINOR)
|
||||
|
||||
if not AceHook then return end -- No upgrade needed
|
||||
|
||||
AceHook.embeded = AceHook.embeded or {}
|
||||
AceHook.registry = AceHook.registry or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end })
|
||||
AceHook.handlers = AceHook.handlers or {}
|
||||
AceHook.actives = AceHook.actives or {}
|
||||
AceHook.scripts = AceHook.scripts or {}
|
||||
AceHook.onceSecure = AceHook.onceSecure or {}
|
||||
AceHook.hooks = AceHook.hooks or {}
|
||||
|
||||
-- local upvalues
|
||||
local registry = AceHook.registry
|
||||
local handlers = AceHook.handlers
|
||||
local actives = AceHook.actives
|
||||
local scripts = AceHook.scripts
|
||||
local onceSecure = AceHook.onceSecure
|
||||
|
||||
-- Lua APIs
|
||||
local pairs, next, type = pairs, next, type
|
||||
local format = string.format
|
||||
local assert, error = assert, error
|
||||
|
||||
-- WoW APIs
|
||||
local issecurevariable, hooksecurefunc = issecurevariable, hooksecurefunc
|
||||
local _G = _G
|
||||
|
||||
-- functions for later definition
|
||||
local donothing, createHook, hook
|
||||
|
||||
local protectedScripts = {
|
||||
OnClick = true,
|
||||
}
|
||||
|
||||
-- upgrading of embeded is done at the bottom of the file
|
||||
|
||||
local mixins = {
|
||||
"Hook", "SecureHook",
|
||||
"HookScript", "SecureHookScript",
|
||||
"Unhook", "UnhookAll",
|
||||
"IsHooked",
|
||||
"RawHook", "RawHookScript"
|
||||
}
|
||||
|
||||
-- AceHook:Embed( target )
|
||||
-- target (object) - target object to embed AceHook in
|
||||
--
|
||||
-- Embeds AceEevent into the target object making the functions from the mixins list available on target:..
|
||||
function AceHook:Embed( target )
|
||||
for k, v in pairs( mixins ) do
|
||||
target[v] = self[v]
|
||||
end
|
||||
self.embeded[target] = true
|
||||
-- inject the hooks table safely
|
||||
target.hooks = target.hooks or {}
|
||||
return target
|
||||
end
|
||||
|
||||
-- AceHook:OnEmbedDisable( target )
|
||||
-- target (object) - target object that is being disabled
|
||||
--
|
||||
-- Unhooks all hooks when the target disables.
|
||||
-- this method should be called by the target manually or by an addon framework
|
||||
function AceHook:OnEmbedDisable( target )
|
||||
target:UnhookAll()
|
||||
end
|
||||
|
||||
function createHook(self, handler, orig, secure, failsafe)
|
||||
local uid
|
||||
local method = type(handler) == "string"
|
||||
if failsafe and not secure then
|
||||
-- failsafe hook creation
|
||||
uid = function(...)
|
||||
if actives[uid] then
|
||||
if method then
|
||||
self[handler](self, ...)
|
||||
else
|
||||
handler(...)
|
||||
end
|
||||
end
|
||||
return orig(...)
|
||||
end
|
||||
-- /failsafe hook
|
||||
else
|
||||
-- all other hooks
|
||||
uid = function(...)
|
||||
if actives[uid] then
|
||||
if method then
|
||||
return self[handler](self, ...)
|
||||
else
|
||||
return handler(...)
|
||||
end
|
||||
elseif not secure then -- backup on non secure
|
||||
return orig(...)
|
||||
end
|
||||
end
|
||||
-- /hook
|
||||
end
|
||||
return uid
|
||||
end
|
||||
|
||||
function donothing() end
|
||||
|
||||
function hook(self, obj, method, handler, script, secure, raw, forceSecure, usage)
|
||||
if not handler then handler = method end
|
||||
|
||||
-- These asserts make sure AceHooks's devs play by the rules.
|
||||
assert(not script or type(script) == "boolean")
|
||||
assert(not secure or type(secure) == "boolean")
|
||||
assert(not raw or type(raw) == "boolean")
|
||||
assert(not forceSecure or type(forceSecure) == "boolean")
|
||||
assert(usage)
|
||||
|
||||
-- Error checking Battery!
|
||||
if obj and type(obj) ~= "table" then
|
||||
error(format("%s: 'object' - nil or table expected got %s", usage, type(obj)), 3)
|
||||
end
|
||||
if type(method) ~= "string" then
|
||||
error(format("%s: 'method' - string expected got %s", usage, type(method)), 3)
|
||||
end
|
||||
if type(handler) ~= "string" and type(handler) ~= "function" then
|
||||
error(format("%s: 'handler' - nil, string, or function expected got %s", usage, type(handler)), 3)
|
||||
end
|
||||
if type(handler) == "string" and type(self[handler]) ~= "function" then
|
||||
error(format("%s: 'handler' - Handler specified does not exist at self[handler]", usage), 3)
|
||||
end
|
||||
if script then
|
||||
if not obj or not obj.GetScript or not obj:HasScript(method) then
|
||||
error(format("%s: You can only hook a script on a frame object", usage), 3)
|
||||
end
|
||||
if not secure and obj.IsProtected and obj:IsProtected() and protectedScripts[method] then
|
||||
error(format("Cannot hook secure script %q; Use SecureHookScript(obj, method, [handler]) instead.", method), 3)
|
||||
end
|
||||
else
|
||||
local issecure
|
||||
if obj then
|
||||
issecure = onceSecure[obj] and onceSecure[obj][method] or issecurevariable(obj, method)
|
||||
else
|
||||
issecure = onceSecure[method] or issecurevariable(method)
|
||||
end
|
||||
if issecure then
|
||||
if forceSecure then
|
||||
if obj then
|
||||
onceSecure[obj] = onceSecure[obj] or {}
|
||||
onceSecure[obj][method] = true
|
||||
else
|
||||
onceSecure[method] = true
|
||||
end
|
||||
elseif not secure then
|
||||
error(format("%s: Attempt to hook secure function %s. Use `SecureHook' or add `true' to the argument list to override.", usage, method), 3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local uid
|
||||
if obj then
|
||||
uid = registry[self][obj] and registry[self][obj][method]
|
||||
else
|
||||
uid = registry[self][method]
|
||||
end
|
||||
|
||||
if uid then
|
||||
if actives[uid] then
|
||||
-- Only two sane choices exist here. We either a) error 100% of the time or b) always unhook and then hook
|
||||
-- choice b would likely lead to odd debuging conditions or other mysteries so we're going with a.
|
||||
error(format("Attempting to rehook already active hook %s.", method))
|
||||
end
|
||||
|
||||
if handlers[uid] == handler then -- turn on a decative hook, note enclosures break this ability, small memory leak
|
||||
actives[uid] = true
|
||||
return
|
||||
elseif obj then -- is there any reason not to call unhook instead of doing the following several lines?
|
||||
if self.hooks and self.hooks[obj] then
|
||||
self.hooks[obj][method] = nil
|
||||
end
|
||||
registry[self][obj][method] = nil
|
||||
else
|
||||
if self.hooks then
|
||||
self.hooks[method] = nil
|
||||
end
|
||||
registry[self][method] = nil
|
||||
end
|
||||
handlers[uid], actives[uid], scripts[uid] = nil, nil, nil
|
||||
uid = nil
|
||||
end
|
||||
|
||||
local orig
|
||||
if script then
|
||||
orig = obj:GetScript(method) or donothing
|
||||
elseif obj then
|
||||
orig = obj[method]
|
||||
else
|
||||
orig = _G[method]
|
||||
end
|
||||
|
||||
if not orig then
|
||||
error(format("%s: Attempting to hook a non existing target", usage), 3)
|
||||
end
|
||||
|
||||
uid = createHook(self, handler, orig, secure, not (raw or secure))
|
||||
|
||||
if obj then
|
||||
self.hooks[obj] = self.hooks[obj] or {}
|
||||
registry[self][obj] = registry[self][obj] or {}
|
||||
registry[self][obj][method] = uid
|
||||
|
||||
if not secure then
|
||||
self.hooks[obj][method] = orig
|
||||
end
|
||||
|
||||
if script then
|
||||
if not secure then
|
||||
obj:SetScript(method, uid)
|
||||
else
|
||||
obj:HookScript(method, uid)
|
||||
end
|
||||
else
|
||||
if not secure then
|
||||
obj[method] = uid
|
||||
else
|
||||
hooksecurefunc(obj, method, uid)
|
||||
end
|
||||
end
|
||||
else
|
||||
registry[self][method] = uid
|
||||
|
||||
if not secure then
|
||||
_G[method] = uid
|
||||
self.hooks[method] = orig
|
||||
else
|
||||
hooksecurefunc(method, uid)
|
||||
end
|
||||
end
|
||||
|
||||
actives[uid], handlers[uid], scripts[uid] = true, handler, script and true or nil
|
||||
end
|
||||
|
||||
--- Hook a function or a method on an object.
|
||||
-- The hook created will be a "safe hook", that means that your handler will be called
|
||||
-- before the hooked function ("Pre-Hook"), and you don't have to call the original function yourself,
|
||||
-- however you cannot stop the execution of the function, or modify any of the arguments/return values.\\
|
||||
-- This type of hook is typically used if you need to know if some function got called, and don't want to modify it.
|
||||
-- @paramsig [object], method, [handler], [hookSecure]
|
||||
-- @param object The object to hook a method from
|
||||
-- @param method If object was specified, the name of the method, or the name of the function to hook.
|
||||
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function)
|
||||
-- @param hookSecure If true, AceHook will allow hooking of secure functions.
|
||||
-- @usage
|
||||
-- -- create an addon with AceHook embeded
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0")
|
||||
--
|
||||
-- function MyAddon:OnEnable()
|
||||
-- -- Hook ActionButton_UpdateHotkeys, overwriting the secure status
|
||||
-- self:Hook("ActionButton_UpdateHotkeys", true)
|
||||
-- end
|
||||
--
|
||||
-- function MyAddon:ActionButton_UpdateHotkeys(button, type)
|
||||
-- print(button:GetName() .. " is updating its HotKey")
|
||||
-- end
|
||||
function AceHook:Hook(object, method, handler, hookSecure)
|
||||
if type(object) == "string" then
|
||||
method, handler, hookSecure, object = object, method, handler, nil
|
||||
end
|
||||
|
||||
if handler == true then
|
||||
handler, hookSecure = nil, true
|
||||
end
|
||||
|
||||
hook(self, object, method, handler, false, false, false, hookSecure or false, "Usage: Hook([object], method, [handler], [hookSecure])")
|
||||
end
|
||||
|
||||
--- RawHook a function or a method on an object.
|
||||
-- The hook created will be a "raw hook", that means that your handler will completly replace
|
||||
-- the original function, and your handler has to call the original function (or not, depending on your intentions).\\
|
||||
-- The original function will be stored in `self.hooks[object][method]` or `self.hooks[functionName]` respectively.\\
|
||||
-- This type of hook can be used for all purposes, and is usually the most common case when you need to modify arguments
|
||||
-- or want to control execution of the original function.
|
||||
-- @paramsig [object], method, [handler], [hookSecure]
|
||||
-- @param object The object to hook a method from
|
||||
-- @param method If object was specified, the name of the method, or the name of the function to hook.
|
||||
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function)
|
||||
-- @param hookSecure If true, AceHook will allow hooking of secure functions.
|
||||
-- @usage
|
||||
-- -- create an addon with AceHook embeded
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0")
|
||||
--
|
||||
-- function MyAddon:OnEnable()
|
||||
-- -- Hook ActionButton_UpdateHotkeys, overwriting the secure status
|
||||
-- self:RawHook("ActionButton_UpdateHotkeys", true)
|
||||
-- end
|
||||
--
|
||||
-- function MyAddon:ActionButton_UpdateHotkeys(button, type)
|
||||
-- if button:GetName() == "MyButton" then
|
||||
-- -- do stuff here
|
||||
-- else
|
||||
-- self.hooks.ActionButton_UpdateHotkeys(button, type)
|
||||
-- end
|
||||
-- end
|
||||
function AceHook:RawHook(object, method, handler, hookSecure)
|
||||
if type(object) == "string" then
|
||||
method, handler, hookSecure, object = object, method, handler, nil
|
||||
end
|
||||
|
||||
if handler == true then
|
||||
handler, hookSecure = nil, true
|
||||
end
|
||||
|
||||
hook(self, object, method, handler, false, false, true, hookSecure or false, "Usage: RawHook([object], method, [handler], [hookSecure])")
|
||||
end
|
||||
|
||||
--- SecureHook a function or a method on an object.
|
||||
-- This function is a wrapper around the `hooksecurefunc` function in the WoW API. Using AceHook
|
||||
-- extends the functionality of secure hooks, and adds the ability to unhook once the hook isn't
|
||||
-- required anymore, or the addon is being disabled.\\
|
||||
-- Secure Hooks should be used if the secure-status of the function is vital to its function,
|
||||
-- and taint would block execution. Secure Hooks are always called after the original function was called
|
||||
-- ("Post Hook"), and you cannot modify the arguments, return values or control the execution.
|
||||
-- @paramsig [object], method, [handler]
|
||||
-- @param object The object to hook a method from
|
||||
-- @param method If object was specified, the name of the method, or the name of the function to hook.
|
||||
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function)
|
||||
function AceHook:SecureHook(object, method, handler)
|
||||
if type(object) == "string" then
|
||||
method, handler, object = object, method, nil
|
||||
end
|
||||
|
||||
hook(self, object, method, handler, false, true, false, false, "Usage: SecureHook([object], method, [handler])")
|
||||
end
|
||||
|
||||
--- Hook a script handler on a frame.
|
||||
-- The hook created will be a "safe hook", that means that your handler will be called
|
||||
-- before the hooked script ("Pre-Hook"), and you don't have to call the original function yourself,
|
||||
-- however you cannot stop the execution of the function, or modify any of the arguments/return values.\\
|
||||
-- This is the frame script equivalent of the :Hook safe-hook. It would typically be used to be notified
|
||||
-- when a certain event happens to a frame.
|
||||
-- @paramsig frame, script, [handler]
|
||||
-- @param frame The Frame to hook the script on
|
||||
-- @param script The script to hook
|
||||
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked script)
|
||||
-- @usage
|
||||
-- -- create an addon with AceHook embeded
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0")
|
||||
--
|
||||
-- function MyAddon:OnEnable()
|
||||
-- -- Hook the OnShow of FriendsFrame
|
||||
-- self:HookScript(FriendsFrame, "OnShow", "FriendsFrameOnShow")
|
||||
-- end
|
||||
--
|
||||
-- function MyAddon:FriendsFrameOnShow(frame)
|
||||
-- print("The FriendsFrame was shown!")
|
||||
-- end
|
||||
function AceHook:HookScript(frame, script, handler)
|
||||
hook(self, frame, script, handler, true, false, false, false, "Usage: HookScript(object, method, [handler])")
|
||||
end
|
||||
|
||||
--- RawHook a script handler on a frame.
|
||||
-- The hook created will be a "raw hook", that means that your handler will completly replace
|
||||
-- the original script, and your handler has to call the original script (or not, depending on your intentions).\\
|
||||
-- The original script will be stored in `self.hooks[frame][script]`.\\
|
||||
-- This type of hook can be used for all purposes, and is usually the most common case when you need to modify arguments
|
||||
-- or want to control execution of the original script.
|
||||
-- @paramsig frame, script, [handler]
|
||||
-- @param frame The Frame to hook the script on
|
||||
-- @param script The script to hook
|
||||
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked script)
|
||||
-- @usage
|
||||
-- -- create an addon with AceHook embeded
|
||||
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0")
|
||||
--
|
||||
-- function MyAddon:OnEnable()
|
||||
-- -- Hook the OnShow of FriendsFrame
|
||||
-- self:RawHookScript(FriendsFrame, "OnShow", "FriendsFrameOnShow")
|
||||
-- end
|
||||
--
|
||||
-- function MyAddon:FriendsFrameOnShow(frame)
|
||||
-- -- Call the original function
|
||||
-- self.hooks[frame].OnShow(frame)
|
||||
-- -- Do our processing
|
||||
-- -- .. stuff
|
||||
-- end
|
||||
function AceHook:RawHookScript(frame, script, handler)
|
||||
hook(self, frame, script, handler, true, false, true, false, "Usage: RawHookScript(object, method, [handler])")
|
||||
end
|
||||
|
||||
--- SecureHook a script handler on a frame.
|
||||
-- This function is a wrapper around the `frame:HookScript` function in the WoW API. Using AceHook
|
||||
-- extends the functionality of secure hooks, and adds the ability to unhook once the hook isn't
|
||||
-- required anymore, or the addon is being disabled.\\
|
||||
-- Secure Hooks should be used if the secure-status of the function is vital to its function,
|
||||
-- and taint would block execution. Secure Hooks are always called after the original function was called
|
||||
-- ("Post Hook"), and you cannot modify the arguments, return values or control the execution.
|
||||
-- @paramsig frame, script, [handler]
|
||||
-- @param frame The Frame to hook the script on
|
||||
-- @param script The script to hook
|
||||
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked script)
|
||||
function AceHook:SecureHookScript(frame, script, handler)
|
||||
hook(self, frame, script, handler, true, true, false, false, "Usage: SecureHookScript(object, method, [handler])")
|
||||
end
|
||||
|
||||
--- Unhook from the specified function, method or script.
|
||||
-- @paramsig [obj], method
|
||||
-- @param obj The object or frame to unhook from
|
||||
-- @param method The name of the method, function or script to unhook from.
|
||||
function AceHook:Unhook(obj, method)
|
||||
local usage = "Usage: Unhook([obj], method)"
|
||||
if type(obj) == "string" then
|
||||
method, obj = obj, nil
|
||||
end
|
||||
|
||||
if obj and type(obj) ~= "table" then
|
||||
error(format("%s: 'obj' - expecting nil or table got %s", usage, type(obj)), 2)
|
||||
end
|
||||
if type(method) ~= "string" then
|
||||
error(format("%s: 'method' - expeting string got %s", usage, type(method)), 2)
|
||||
end
|
||||
|
||||
local uid
|
||||
if obj then
|
||||
uid = registry[self][obj] and registry[self][obj][method]
|
||||
else
|
||||
uid = registry[self][method]
|
||||
end
|
||||
|
||||
if not uid or not actives[uid] then
|
||||
-- Declining to error on an unneeded unhook since the end effect is the same and this would just be annoying.
|
||||
return false
|
||||
end
|
||||
|
||||
actives[uid], handlers[uid] = nil, nil
|
||||
|
||||
if obj then
|
||||
registry[self][obj][method] = nil
|
||||
registry[self][obj] = next(registry[self][obj]) and registry[self][obj] or nil
|
||||
|
||||
-- if the hook reference doesnt exist, then its a secure hook, just bail out and dont do any unhooking
|
||||
if not self.hooks[obj] or not self.hooks[obj][method] then return true end
|
||||
|
||||
if scripts[uid] and obj:GetScript(method) == uid then -- unhooks scripts
|
||||
obj:SetScript(method, self.hooks[obj][method] ~= donothing and self.hooks[obj][method] or nil)
|
||||
scripts[uid] = nil
|
||||
elseif obj and self.hooks[obj] and self.hooks[obj][method] and obj[method] == uid then -- unhooks methods
|
||||
obj[method] = self.hooks[obj][method]
|
||||
end
|
||||
|
||||
self.hooks[obj][method] = nil
|
||||
self.hooks[obj] = next(self.hooks[obj]) and self.hooks[obj] or nil
|
||||
else
|
||||
registry[self][method] = nil
|
||||
|
||||
-- if self.hooks[method] doesn't exist, then this is a SecureHook, just bail out
|
||||
if not self.hooks[method] then return true end
|
||||
|
||||
if self.hooks[method] and _G[method] == uid then -- unhooks functions
|
||||
_G[method] = self.hooks[method]
|
||||
end
|
||||
|
||||
self.hooks[method] = nil
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--- Unhook all existing hooks for this addon.
|
||||
function AceHook:UnhookAll()
|
||||
for key, value in pairs(registry[self]) do
|
||||
if type(key) == "table" then
|
||||
for method in pairs(value) do
|
||||
self:Unhook(key, method)
|
||||
end
|
||||
else
|
||||
self:Unhook(key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Check if the specific function, method or script is already hooked.
|
||||
-- @paramsig [obj], method
|
||||
-- @param obj The object or frame to unhook from
|
||||
-- @param method The name of the method, function or script to unhook from.
|
||||
function AceHook:IsHooked(obj, method)
|
||||
-- we don't check if registry[self] exists, this is done by evil magicks in the metatable
|
||||
if type(obj) == "string" then
|
||||
if registry[self][obj] and actives[registry[self][obj]] then
|
||||
return true, handlers[registry[self][obj]]
|
||||
end
|
||||
else
|
||||
if registry[self][obj] and registry[self][obj][method] and actives[registry[self][obj][method]] then
|
||||
return true, handlers[registry[self][obj][method]]
|
||||
end
|
||||
end
|
||||
|
||||
return false, nil
|
||||
end
|
||||
|
||||
--- Upgrade our old embeded
|
||||
for target, v in pairs( AceHook.embeded ) do
|
||||
AceHook:Embed( target )
|
||||
end
|
||||
4
Libraries/Ace3/AceHook-3.0/AceHook-3.0.xml
Normal file
4
Libraries/Ace3/AceHook-3.0/AceHook-3.0.xml
Normal 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="AceHook-3.0.lua"/>
|
||||
</Ui>
|
||||
165
Libraries/Ace3/AceLocale-3.0/AceLocale-3.0.lua
Normal file
165
Libraries/Ace3/AceLocale-3.0/AceLocale-3.0.lua
Normal file
@@ -0,0 +1,165 @@
|
||||
--- **AceLocale-3.0** manages localization in addons, allowing for multiple locale to be registered with fallback to the base locale for untranslated strings.
|
||||
-- @class file
|
||||
-- @name AceLocale-3.0
|
||||
-- @release $Id$
|
||||
local MAJOR,MINOR = "AceLocale-3.0-ElvUI", 8
|
||||
|
||||
local AceLocale, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceLocale then return end -- no upgrade needed
|
||||
|
||||
-- Lua APIs
|
||||
local assert, tostring, error, type, pairs = assert, tostring, error, type, pairs
|
||||
local getmetatable, setmetatable, rawset, rawget = getmetatable, setmetatable, rawset, rawget
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: GAME_LOCALE, geterrorhandler
|
||||
|
||||
local gameLocale = GetLocale()
|
||||
if gameLocale == "enGB" then
|
||||
gameLocale = "enUS"
|
||||
end
|
||||
|
||||
AceLocale.apps = AceLocale.apps or {} -- array of ["AppName"]=localetableref
|
||||
AceLocale.appnames = AceLocale.appnames or {} -- array of [localetableref]="AppName"
|
||||
|
||||
-- This metatable is used on all tables returned from GetLocale
|
||||
local readmeta = {
|
||||
__index = function(self, key) -- requesting totally unknown entries: fire off a nonbreaking error and return key
|
||||
rawset(self, key, key) -- only need to see the warning once, really
|
||||
geterrorhandler()(MAJOR..": "..tostring(AceLocale.appnames[self])..": Missing entry for '"..tostring(key).."'")
|
||||
return key
|
||||
end
|
||||
}
|
||||
|
||||
-- This metatable is used on all tables returned from GetLocale if the silent flag is true, it does not issue a warning on unknown keys
|
||||
local readmetasilent = {
|
||||
__index = function(self, key) -- requesting totally unknown entries: return key
|
||||
rawset(self, key, key) -- only need to invoke this function once
|
||||
return key
|
||||
end
|
||||
}
|
||||
|
||||
-- Remember the locale table being registered right now (it gets set by :NewLocale())
|
||||
-- NOTE: Do never try to register 2 locale tables at once and mix their definition.
|
||||
local registering
|
||||
|
||||
-- local assert false function
|
||||
local assertfalse = function() assert(false) end
|
||||
|
||||
-- This metatable proxy is used when registering nondefault locales
|
||||
local writeproxy = setmetatable({}, {
|
||||
__newindex = function(self, key, value)
|
||||
rawset(registering, key, value == true and key or value) -- assigning values: replace 'true' with key string
|
||||
end,
|
||||
__index = assertfalse
|
||||
})
|
||||
|
||||
-- This metatable proxy is used when registering the default locale.
|
||||
-- It refuses to overwrite existing values
|
||||
-- Reason 1: Allows loading locales in any order
|
||||
-- Reason 2: If 2 modules have the same string, but only the first one to be
|
||||
-- loaded has a translation for the current locale, the translation
|
||||
-- doesn't get overwritten.
|
||||
--
|
||||
local writedefaultproxy = setmetatable({}, {
|
||||
__newindex = function(self, key, value)
|
||||
if not rawget(registering, key) then
|
||||
rawset(registering, key, value == true and key or value)
|
||||
end
|
||||
end,
|
||||
__index = assertfalse
|
||||
})
|
||||
|
||||
-- ElvUI block
|
||||
local function BackfillTable(currentTable, defaultTable)
|
||||
if type(currentTable) ~= 'table' and type(defaultTable) ~= 'table' then
|
||||
return
|
||||
end
|
||||
|
||||
for option, value in pairs(defaultTable) do
|
||||
if type(value) == 'table' then
|
||||
value = BackfillTable(currentTable[option], value)
|
||||
end
|
||||
|
||||
if currentTable[option] ~= defaultTable[option] and currentTable[option] == option then
|
||||
currentTable[option] = value == true and option or value
|
||||
end
|
||||
end
|
||||
end
|
||||
-- end block
|
||||
|
||||
--- Register a new locale (or extend an existing one) for the specified application.
|
||||
-- :NewLocale will return a table you can fill your locale into, or nil if the locale isn't needed for the players
|
||||
-- game locale.
|
||||
-- @paramsig application, locale[, isDefault[, silent]]
|
||||
-- @param application Unique name of addon / module
|
||||
-- @param locale Name of the locale to register, e.g. "enUS", "deDE", etc.
|
||||
-- @param isDefault If this is the default locale being registered (your addon is written in this language, generally enUS)
|
||||
-- @param silent If true, the locale will not issue warnings for missing keys. Must be set on the first locale registered. If set to "raw", nils will be returned for unknown keys (no metatable used).
|
||||
-- @usage
|
||||
-- -- enUS.lua
|
||||
-- local L = LibStub("AceLocale-3.0"):NewLocale("TestLocale", "enUS", true)
|
||||
-- L["string1"] = true
|
||||
--
|
||||
-- -- deDE.lua
|
||||
-- local L = LibStub("AceLocale-3.0"):NewLocale("TestLocale", "deDE")
|
||||
-- if not L then return end
|
||||
-- L["string1"] = "Zeichenkette1"
|
||||
function AceLocale:NewLocale(application, locale, isDefault, silent)
|
||||
local app = AceLocale.apps[application]
|
||||
|
||||
if silent and app and getmetatable(app) ~= readmetasilent then
|
||||
geterrorhandler()("Usage: NewLocale(application, locale[, isDefault[, silent]]): 'silent' must be specified for the first locale registered")
|
||||
end
|
||||
|
||||
if not app then
|
||||
if silent=="raw" then
|
||||
app = {}
|
||||
else
|
||||
app = setmetatable({}, silent and readmetasilent or readmeta)
|
||||
end
|
||||
AceLocale.apps[application] = app
|
||||
AceLocale.appnames[app] = application
|
||||
end
|
||||
|
||||
-- ElvUI block
|
||||
if (not app[locale]) or (app[locale] and type(app[locale]) ~= 'table') then
|
||||
-- app[locale] = setmetatable({}, silent and readmetasilent or readmeta) -- To find missing keys
|
||||
app[locale] = setmetatable({}, readmetasilent)
|
||||
end
|
||||
|
||||
registering = app[locale] -- remember globally for writeproxy and writedefaultproxy
|
||||
-- end block
|
||||
|
||||
if isDefault and (not app.defaultLocale or app.defaultLocale == 'defaultLocale') then -- ElvUI
|
||||
app.defaultLocale = locale
|
||||
return writedefaultproxy
|
||||
end
|
||||
|
||||
return writeproxy
|
||||
end
|
||||
|
||||
--- Returns localizations for the current locale (or default locale if translations are missing).
|
||||
-- Errors if nothing is registered (spank developer, not just a missing translation)
|
||||
-- @param application Unique name of addon / module
|
||||
-- @param silent If true, the locale is optional, silently return nil if it's not found (defaults to false, optional)
|
||||
-- @return The locale table for the current language.
|
||||
--- Modified by ElvUI to add `locale` as second arg and the CopyTable section
|
||||
function AceLocale:GetLocale(application, locale, silent)
|
||||
if type(locale) == "boolean" then
|
||||
silent = locale
|
||||
locale = gameLocale
|
||||
end
|
||||
|
||||
if not silent and not AceLocale.apps[application] then
|
||||
error("Usage: GetLocale(application[,locale[, silent]]): 'application' - No locales registered for '"..tostring(application).."'", 2)
|
||||
end
|
||||
|
||||
if locale ~= AceLocale.apps[application].defaultLocale then
|
||||
BackfillTable(AceLocale.apps[application][locale], AceLocale.apps[application][AceLocale.apps[application].defaultLocale])
|
||||
end
|
||||
|
||||
return AceLocale.apps[application][locale] or AceLocale.apps[application][gameLocale] -- Just in case the table doesn't exist it reverts to default
|
||||
end
|
||||
4
Libraries/Ace3/AceLocale-3.0/AceLocale-3.0.xml
Normal file
4
Libraries/Ace3/AceLocale-3.0/AceLocale-3.0.xml
Normal 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="AceLocale-3.0.lua"/>
|
||||
</Ui>
|
||||
287
Libraries/Ace3/AceSerializer-3.0/AceSerializer-3.0.lua
Normal file
287
Libraries/Ace3/AceSerializer-3.0/AceSerializer-3.0.lua
Normal file
@@ -0,0 +1,287 @@
|
||||
--- **AceSerializer-3.0** can serialize any variable (except functions or userdata) into a string format,
|
||||
-- that can be send over the addon comm channel. AceSerializer was designed to keep all data intact, especially
|
||||
-- very large numbers or floating point numbers, and table structures. The only caveat currently is, that multiple
|
||||
-- references to the same table will be send individually.
|
||||
--
|
||||
-- **AceSerializer-3.0** can be embeded into your addon, either explicitly by calling AceSerializer: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 AceSerializer itself.\\
|
||||
-- It is recommended to embed AceSerializer, otherwise you'll have to specify a custom `self` on all calls you
|
||||
-- make into AceSerializer.
|
||||
-- @class file
|
||||
-- @name AceSerializer-3.0
|
||||
-- @release $Id$
|
||||
local MAJOR,MINOR = "AceSerializer-3.0", 5
|
||||
local AceSerializer, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceSerializer then return end
|
||||
|
||||
-- Lua APIs
|
||||
local strbyte, strchar, gsub, gmatch, format = string.byte, string.char, string.gsub, string.gmatch, string.format
|
||||
local assert, error, pcall = assert, error, pcall
|
||||
local type, tostring, tonumber = type, tostring, tonumber
|
||||
local pairs, select, frexp = pairs, select, math.frexp
|
||||
local tconcat = table.concat
|
||||
|
||||
-- quick copies of string representations of wonky numbers
|
||||
local inf = math.huge
|
||||
|
||||
local serNaN -- can't do this in 4.3, see ace3 ticket 268
|
||||
local serInf, serInfMac = "1.#INF", "inf"
|
||||
local serNegInf, serNegInfMac = "-1.#INF", "-inf"
|
||||
|
||||
|
||||
-- Serialization functions
|
||||
|
||||
local function SerializeStringHelper(ch) -- Used by SerializeValue for strings
|
||||
-- We use \126 ("~") as an escape character for all nonprints plus a few more
|
||||
local n = strbyte(ch)
|
||||
if n==30 then -- v3 / ticket 115: catch a nonprint that ends up being "~^" when encoded... DOH
|
||||
return "\126\122"
|
||||
elseif n<=32 then -- nonprint + space
|
||||
return "\126"..strchar(n+64)
|
||||
elseif n==94 then -- value separator
|
||||
return "\126\125"
|
||||
elseif n==126 then -- our own escape character
|
||||
return "\126\124"
|
||||
elseif n==127 then -- nonprint (DEL)
|
||||
return "\126\123"
|
||||
else
|
||||
assert(false) -- can't be reached if caller uses a sane regex
|
||||
end
|
||||
end
|
||||
|
||||
local function SerializeValue(v, res, nres)
|
||||
-- We use "^" as a value separator, followed by one byte for type indicator
|
||||
local t=type(v)
|
||||
|
||||
if t=="string" then -- ^S = string (escaped to remove nonprints, "^"s, etc)
|
||||
res[nres+1] = "^S"
|
||||
res[nres+2] = gsub(v,"[%c \94\126\127]", SerializeStringHelper)
|
||||
nres=nres+2
|
||||
|
||||
elseif t=="number" then -- ^N = number (just tostring()ed) or ^F (float components)
|
||||
local str = tostring(v)
|
||||
if tonumber(str)==v --[[not in 4.3 or str==serNaN]] then
|
||||
-- translates just fine, transmit as-is
|
||||
res[nres+1] = "^N"
|
||||
res[nres+2] = str
|
||||
nres=nres+2
|
||||
elseif v == inf or v == -inf then
|
||||
res[nres+1] = "^N"
|
||||
res[nres+2] = v == inf and serInf or serNegInf
|
||||
nres=nres+2
|
||||
else
|
||||
local m,e = frexp(v)
|
||||
res[nres+1] = "^F"
|
||||
res[nres+2] = format("%.0f",m*2^53) -- force mantissa to become integer (it's originally 0.5--0.9999)
|
||||
res[nres+3] = "^f"
|
||||
res[nres+4] = tostring(e-53) -- adjust exponent to counteract mantissa manipulation
|
||||
nres=nres+4
|
||||
end
|
||||
|
||||
elseif t=="table" then -- ^T...^t = table (list of key,value pairs)
|
||||
nres=nres+1
|
||||
res[nres] = "^T"
|
||||
for k,v in pairs(v) do
|
||||
nres = SerializeValue(k, res, nres)
|
||||
nres = SerializeValue(v, res, nres)
|
||||
end
|
||||
nres=nres+1
|
||||
res[nres] = "^t"
|
||||
|
||||
elseif t=="boolean" then -- ^B = true, ^b = false
|
||||
nres=nres+1
|
||||
if v then
|
||||
res[nres] = "^B" -- true
|
||||
else
|
||||
res[nres] = "^b" -- false
|
||||
end
|
||||
|
||||
elseif t=="nil" then -- ^Z = nil (zero, "N" was taken :P)
|
||||
nres=nres+1
|
||||
res[nres] = "^Z"
|
||||
|
||||
else
|
||||
error(MAJOR..": Cannot serialize a value of type '"..t.."'") -- can't produce error on right level, this is wildly recursive
|
||||
end
|
||||
|
||||
return nres
|
||||
end
|
||||
|
||||
|
||||
|
||||
local serializeTbl = { "^1" } -- "^1" = Hi, I'm data serialized by AceSerializer protocol rev 1
|
||||
|
||||
--- Serialize the data passed into the function.
|
||||
-- Takes a list of values (strings, numbers, booleans, nils, tables)
|
||||
-- and returns it in serialized form (a string).\\
|
||||
-- May throw errors on invalid data types.
|
||||
-- @param ... List of values to serialize
|
||||
-- @return The data in its serialized form (string)
|
||||
function AceSerializer:Serialize(...)
|
||||
local nres = 1
|
||||
|
||||
for i=1,select("#", ...) do
|
||||
local v = select(i, ...)
|
||||
nres = SerializeValue(v, serializeTbl, nres)
|
||||
end
|
||||
|
||||
serializeTbl[nres+1] = "^^" -- "^^" = End of serialized data
|
||||
|
||||
return tconcat(serializeTbl, "", 1, nres+1)
|
||||
end
|
||||
|
||||
-- Deserialization functions
|
||||
local function DeserializeStringHelper(escape)
|
||||
if escape<"~\122" then
|
||||
return strchar(strbyte(escape,2,2)-64)
|
||||
elseif escape=="~\122" then -- v3 / ticket 115: special case encode since 30+64=94 ("^") - OOPS.
|
||||
return "\030"
|
||||
elseif escape=="~\123" then
|
||||
return "\127"
|
||||
elseif escape=="~\124" then
|
||||
return "\126"
|
||||
elseif escape=="~\125" then
|
||||
return "\94"
|
||||
end
|
||||
error("DeserializeStringHelper got called for '"..escape.."'?!?") -- can't be reached unless regex is screwed up
|
||||
end
|
||||
|
||||
local function DeserializeNumberHelper(number)
|
||||
--[[ not in 4.3 if number == serNaN then
|
||||
return 0/0
|
||||
else]]if number == serNegInf or number == serNegInfMac then
|
||||
return -inf
|
||||
elseif number == serInf or number == serInfMac then
|
||||
return inf
|
||||
else
|
||||
return tonumber(number)
|
||||
end
|
||||
end
|
||||
|
||||
-- DeserializeValue: worker function for :Deserialize()
|
||||
-- It works in two modes:
|
||||
-- Main (top-level) mode: Deserialize a list of values and return them all
|
||||
-- Recursive (table) mode: Deserialize only a single value (_may_ of course be another table with lots of subvalues in it)
|
||||
--
|
||||
-- The function _always_ works recursively due to having to build a list of values to return
|
||||
--
|
||||
-- Callers are expected to pcall(DeserializeValue) to trap errors
|
||||
|
||||
local function DeserializeValue(iter,single,ctl,data)
|
||||
|
||||
if not single then
|
||||
ctl,data = iter()
|
||||
end
|
||||
|
||||
if not ctl then
|
||||
error("Supplied data misses AceSerializer terminator ('^^')")
|
||||
end
|
||||
|
||||
if ctl=="^^" then
|
||||
-- ignore extraneous data
|
||||
return
|
||||
end
|
||||
|
||||
local res
|
||||
|
||||
if ctl=="^S" then
|
||||
res = gsub(data, "~.", DeserializeStringHelper)
|
||||
elseif ctl=="^N" then
|
||||
res = DeserializeNumberHelper(data)
|
||||
if not res then
|
||||
error("Invalid serialized number: '"..tostring(data).."'")
|
||||
end
|
||||
elseif ctl=="^F" then -- ^F<mantissa>^f<exponent>
|
||||
local ctl2,e = iter()
|
||||
if ctl2~="^f" then
|
||||
error("Invalid serialized floating-point number, expected '^f', not '"..tostring(ctl2).."'")
|
||||
end
|
||||
local m=tonumber(data)
|
||||
e=tonumber(e)
|
||||
if not (m and e) then
|
||||
error("Invalid serialized floating-point number, expected mantissa and exponent, got '"..tostring(m).."' and '"..tostring(e).."'")
|
||||
end
|
||||
res = m*(2^e)
|
||||
elseif ctl=="^B" then -- yeah yeah ignore data portion
|
||||
res = true
|
||||
elseif ctl=="^b" then -- yeah yeah ignore data portion
|
||||
res = false
|
||||
elseif ctl=="^Z" then -- yeah yeah ignore data portion
|
||||
res = nil
|
||||
elseif ctl=="^T" then
|
||||
-- ignore ^T's data, future extensibility?
|
||||
res = {}
|
||||
local k,v
|
||||
while true do
|
||||
ctl,data = iter()
|
||||
if ctl=="^t" then break end -- ignore ^t's data
|
||||
k = DeserializeValue(iter,true,ctl,data)
|
||||
if k==nil then
|
||||
error("Invalid AceSerializer table format (no table end marker)")
|
||||
end
|
||||
ctl,data = iter()
|
||||
v = DeserializeValue(iter,true,ctl,data)
|
||||
if v==nil then
|
||||
error("Invalid AceSerializer table format (no table end marker)")
|
||||
end
|
||||
res[k]=v
|
||||
end
|
||||
else
|
||||
error("Invalid AceSerializer control code '"..ctl.."'")
|
||||
end
|
||||
|
||||
if not single then
|
||||
return res,DeserializeValue(iter)
|
||||
else
|
||||
return res
|
||||
end
|
||||
end
|
||||
|
||||
--- Deserializes the data into its original values.
|
||||
-- Accepts serialized data, ignoring all control characters and whitespace.
|
||||
-- @param str The serialized data (from :Serialize)
|
||||
-- @return true followed by a list of values, OR false followed by an error message
|
||||
function AceSerializer:Deserialize(str)
|
||||
str = gsub(str, "[%c ]", "") -- ignore all control characters; nice for embedding in email and stuff
|
||||
|
||||
local iter = gmatch(str, "(^.)([^^]*)") -- Any ^x followed by string of non-^
|
||||
local ctl,data = iter()
|
||||
if not ctl or ctl~="^1" then
|
||||
-- we purposefully ignore the data portion of the start code, it can be used as an extension mechanism
|
||||
return false, "Supplied data is not AceSerializer data (rev 1)"
|
||||
end
|
||||
|
||||
return pcall(DeserializeValue, iter)
|
||||
end
|
||||
|
||||
|
||||
----------------------------------------
|
||||
-- Base library stuff
|
||||
----------------------------------------
|
||||
|
||||
AceSerializer.internals = { -- for test scripts
|
||||
SerializeValue = SerializeValue,
|
||||
SerializeStringHelper = SerializeStringHelper,
|
||||
}
|
||||
|
||||
local mixins = {
|
||||
"Serialize",
|
||||
"Deserialize",
|
||||
}
|
||||
|
||||
AceSerializer.embeds = AceSerializer.embeds or {}
|
||||
|
||||
function AceSerializer:Embed(target)
|
||||
for k, v in pairs(mixins) do
|
||||
target[v] = self[v]
|
||||
end
|
||||
self.embeds[target] = true
|
||||
return target
|
||||
end
|
||||
|
||||
-- Update embeds
|
||||
for target, v in pairs(AceSerializer.embeds) do
|
||||
AceSerializer:Embed(target)
|
||||
end
|
||||
4
Libraries/Ace3/AceSerializer-3.0/AceSerializer-3.0.xml
Normal file
4
Libraries/Ace3/AceSerializer-3.0/AceSerializer-3.0.xml
Normal 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="AceSerializer-3.0.lua"/>
|
||||
</Ui>
|
||||
278
Libraries/Ace3/AceTimer-3.0/AceTimer-3.0.lua
Normal file
278
Libraries/Ace3/AceTimer-3.0/AceTimer-3.0.lua
Normal file
@@ -0,0 +1,278 @@
|
||||
--- **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 as this is what the WoW timer API
|
||||
-- restricts us to.
|
||||
--
|
||||
-- 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$
|
||||
|
||||
local MAJOR, MINOR = "AceTimer-3.0", 17 -- Bump minor on changes
|
||||
local AceTimer, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceTimer then return end -- No upgrade needed
|
||||
AceTimer.activeTimers = AceTimer.activeTimers or {} -- Active timer list
|
||||
local activeTimers = AceTimer.activeTimers -- Upvalue our private data
|
||||
|
||||
-- Lua APIs
|
||||
local type, unpack, next, error, select = type, unpack, next, error, select
|
||||
-- WoW APIs
|
||||
local GetTime, C_TimerAfter = GetTime, C_Timer.After
|
||||
|
||||
local function new(self, loop, func, delay, ...)
|
||||
if delay < 0.01 then
|
||||
delay = 0.01 -- Restrict to the lowest time that the C_Timer API allows us
|
||||
end
|
||||
|
||||
local timer = {
|
||||
object = self,
|
||||
func = func,
|
||||
looping = loop,
|
||||
argsCount = select("#", ...),
|
||||
delay = delay,
|
||||
ends = GetTime() + delay,
|
||||
...
|
||||
}
|
||||
|
||||
activeTimers[timer] = timer
|
||||
|
||||
-- Create new timer closure to wrap the "timer" object
|
||||
timer.callback = function()
|
||||
if not timer.cancelled then
|
||||
if type(timer.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.
|
||||
timer.object[timer.func](timer.object, unpack(timer, 1, timer.argsCount))
|
||||
else
|
||||
timer.func(unpack(timer, 1, timer.argsCount))
|
||||
end
|
||||
|
||||
if timer.looping and not timer.cancelled then
|
||||
-- Compensate delay to get a perfect average delay, even if individual times don't match up perfectly
|
||||
-- due to fps differences
|
||||
local time = GetTime()
|
||||
local delay = timer.delay - (time - timer.ends)
|
||||
-- Ensure the delay doesn't go below the threshold
|
||||
if delay < 0.01 then delay = 0.01 end
|
||||
C_TimerAfter(delay, timer.callback)
|
||||
timer.ends = time + delay
|
||||
else
|
||||
activeTimers[timer.handle or timer] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
C_TimerAfter(delay, timer.callback)
|
||||
return timer
|
||||
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
|
||||
else
|
||||
timer.cancelled = true
|
||||
activeTimers[id] = nil
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
--- Cancels all timers registered to the current addon object ('self')
|
||||
function AceTimer:CancelAllTimers()
|
||||
for k,v in next, 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
|
||||
else
|
||||
return timer.ends - GetTime()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Upgrading
|
||||
|
||||
-- Upgrade from old hash-bucket based timers to C_Timer.After 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 next, AceTimer.selfs do
|
||||
for handle,timer in next, timers do
|
||||
if type(timer) == "table" and timer.callback then
|
||||
local newTimer
|
||||
if timer.delay then
|
||||
newTimer = AceTimer.ScheduleRepeatingTimer(timer.object, timer.callback, timer.delay, timer.arg)
|
||||
else
|
||||
newTimer = AceTimer.ScheduleTimer(timer.object, timer.callback, timer.when - GetTime(), timer.arg)
|
||||
end
|
||||
-- Use the old handle for old timers
|
||||
activeTimers[newTimer] = nil
|
||||
activeTimers[handle] = newTimer
|
||||
newTimer.handle = handle
|
||||
end
|
||||
end
|
||||
end
|
||||
AceTimer.selfs = nil
|
||||
AceTimer.hash = nil
|
||||
AceTimer.debug = nil
|
||||
elseif oldminor and oldminor < 17 then
|
||||
-- Upgrade from old animation based timers to C_Timer.After timers.
|
||||
AceTimer.inactiveTimers = nil
|
||||
AceTimer.frame = nil
|
||||
local oldTimers = AceTimer.activeTimers
|
||||
-- Clear old timer table and update upvalue
|
||||
AceTimer.activeTimers = {}
|
||||
activeTimers = AceTimer.activeTimers
|
||||
for handle, timer in next, oldTimers do
|
||||
local newTimer
|
||||
-- Stop the old timer animation
|
||||
local duration, elapsed = timer:GetDuration(), timer:GetElapsed()
|
||||
timer:GetParent():Stop()
|
||||
if timer.looping then
|
||||
newTimer = AceTimer.ScheduleRepeatingTimer(timer.object, timer.func, duration, unpack(timer.args, 1, timer.argsCount))
|
||||
else
|
||||
newTimer = AceTimer.ScheduleTimer(timer.object, timer.func, duration - elapsed, unpack(timer.args, 1, timer.argsCount))
|
||||
end
|
||||
-- Use the old handle for old timers
|
||||
activeTimers[newTimer] = nil
|
||||
activeTimers[handle] = newTimer
|
||||
newTimer.handle = handle
|
||||
end
|
||||
|
||||
-- Migrate transitional handles
|
||||
if oldminor < 13 and AceTimer.hashCompatTable then
|
||||
for handle, id in next, AceTimer.hashCompatTable do
|
||||
local t = activeTimers[id]
|
||||
if t then
|
||||
activeTimers[id] = nil
|
||||
activeTimers[handle] = t
|
||||
t.handle = handle
|
||||
end
|
||||
end
|
||||
AceTimer.hashCompatTable = nil
|
||||
end
|
||||
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 next, 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 next, AceTimer.embeds do
|
||||
AceTimer:Embed(addon)
|
||||
end
|
||||
4
Libraries/Ace3/AceTimer-3.0/AceTimer-3.0.xml
Normal file
4
Libraries/Ace3/AceTimer-3.0/AceTimer-3.0.xml
Normal 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>
|
||||
212
Libraries/Ace3/CallbackHandler-1.0/CallbackHandler-1.0.lua
Normal file
212
Libraries/Ace3/CallbackHandler-1.0/CallbackHandler-1.0.lua
Normal file
@@ -0,0 +1,212 @@
|
||||
--[[ $Id$ ]]
|
||||
local MAJOR, MINOR = "CallbackHandler-1.0", 7
|
||||
local CallbackHandler = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not CallbackHandler then return end -- No upgrade needed
|
||||
|
||||
local meta = {__index = function(tbl, key) tbl[key] = {} return tbl[key] end}
|
||||
|
||||
-- Lua APIs
|
||||
local tconcat = table.concat
|
||||
local assert, error, loadstring = assert, error, loadstring
|
||||
local setmetatable, rawset, rawget = setmetatable, rawset, rawget
|
||||
local next, select, pairs, type, tostring = next, select, pairs, type, tostring
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: geterrorhandler
|
||||
|
||||
local xpcall = xpcall
|
||||
|
||||
local function errorhandler(err)
|
||||
return geterrorhandler()(err)
|
||||
end
|
||||
|
||||
local function Dispatch(handlers, ...)
|
||||
local index, method = next(handlers)
|
||||
if not method then return end
|
||||
repeat
|
||||
xpcall(method, errorhandler, ...)
|
||||
index, method = next(handlers, index)
|
||||
until not method
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
-- CallbackHandler:New
|
||||
--
|
||||
-- target - target object to embed public APIs in
|
||||
-- RegisterName - name of the callback registration API, default "RegisterCallback"
|
||||
-- UnregisterName - name of the callback unregistration API, default "UnregisterCallback"
|
||||
-- UnregisterAllName - name of the API to unregister all callbacks, default "UnregisterAllCallbacks". false == don't publish this API.
|
||||
|
||||
function CallbackHandler:New(target, RegisterName, UnregisterName, UnregisterAllName)
|
||||
|
||||
RegisterName = RegisterName or "RegisterCallback"
|
||||
UnregisterName = UnregisterName or "UnregisterCallback"
|
||||
if UnregisterAllName==nil then -- false is used to indicate "don't want this method"
|
||||
UnregisterAllName = "UnregisterAllCallbacks"
|
||||
end
|
||||
|
||||
-- we declare all objects and exported APIs inside this closure to quickly gain access
|
||||
-- to e.g. function names, the "target" parameter, etc
|
||||
|
||||
|
||||
-- Create the registry object
|
||||
local events = setmetatable({}, meta)
|
||||
local registry = { recurse=0, events=events }
|
||||
|
||||
-- registry:Fire() - fires the given event/message into the registry
|
||||
function registry:Fire(eventname, ...)
|
||||
if not rawget(events, eventname) or not next(events[eventname]) then return end
|
||||
local oldrecurse = registry.recurse
|
||||
registry.recurse = oldrecurse + 1
|
||||
|
||||
Dispatch(events[eventname], eventname, ...)
|
||||
|
||||
registry.recurse = oldrecurse
|
||||
|
||||
if registry.insertQueue and oldrecurse==0 then
|
||||
-- Something in one of our callbacks wanted to register more callbacks; they got queued
|
||||
for eventname,callbacks in pairs(registry.insertQueue) do
|
||||
local first = not rawget(events, eventname) or not next(events[eventname]) -- test for empty before. not test for one member after. that one member may have been overwritten.
|
||||
for self,func in pairs(callbacks) do
|
||||
events[eventname][self] = func
|
||||
-- fire OnUsed callback?
|
||||
if first and registry.OnUsed then
|
||||
registry.OnUsed(registry, target, eventname)
|
||||
first = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
registry.insertQueue = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- Registration of a callback, handles:
|
||||
-- self["method"], leads to self["method"](self, ...)
|
||||
-- self with function ref, leads to functionref(...)
|
||||
-- "addonId" (instead of self) with function ref, leads to functionref(...)
|
||||
-- all with an optional arg, which, if present, gets passed as first argument (after self if present)
|
||||
target[RegisterName] = function(self, eventname, method, ... --[[actually just a single arg]])
|
||||
if type(eventname) ~= "string" then
|
||||
error("Usage: "..RegisterName.."(eventname, method[, arg]): 'eventname' - string expected.", 2)
|
||||
end
|
||||
|
||||
method = method or eventname
|
||||
|
||||
local first = not rawget(events, eventname) or not next(events[eventname]) -- test for empty before. not test for one member after. that one member may have been overwritten.
|
||||
|
||||
if type(method) ~= "string" and type(method) ~= "function" then
|
||||
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): 'methodname' - string or function expected.", 2)
|
||||
end
|
||||
|
||||
local regfunc
|
||||
|
||||
if type(method) == "string" then
|
||||
-- self["method"] calling style
|
||||
if type(self) ~= "table" then
|
||||
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): self was not a table?", 2)
|
||||
elseif self==target then
|
||||
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): do not use Library:"..RegisterName.."(), use your own 'self'", 2)
|
||||
elseif type(self[method]) ~= "function" then
|
||||
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): 'methodname' - method '"..tostring(method).."' not found on self.", 2)
|
||||
end
|
||||
|
||||
if select("#",...)>=1 then -- this is not the same as testing for arg==nil!
|
||||
local arg=select(1,...)
|
||||
regfunc = function(...) self[method](self,arg,...) end
|
||||
else
|
||||
regfunc = function(...) self[method](self,...) end
|
||||
end
|
||||
else
|
||||
-- function ref with self=object or self="addonId" or self=thread
|
||||
if type(self)~="table" and type(self)~="string" and type(self)~="thread" then
|
||||
error("Usage: "..RegisterName.."(self or \"addonId\", eventname, method): 'self or addonId': table or string or thread expected.", 2)
|
||||
end
|
||||
|
||||
if select("#",...)>=1 then -- this is not the same as testing for arg==nil!
|
||||
local arg=select(1,...)
|
||||
regfunc = function(...) method(arg,...) end
|
||||
else
|
||||
regfunc = method
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if events[eventname][self] or registry.recurse<1 then
|
||||
-- if registry.recurse<1 then
|
||||
-- we're overwriting an existing entry, or not currently recursing. just set it.
|
||||
events[eventname][self] = regfunc
|
||||
-- fire OnUsed callback?
|
||||
if registry.OnUsed and first then
|
||||
registry.OnUsed(registry, target, eventname)
|
||||
end
|
||||
else
|
||||
-- we're currently processing a callback in this registry, so delay the registration of this new entry!
|
||||
-- yes, we're a bit wasteful on garbage, but this is a fringe case, so we're picking low implementation overhead over garbage efficiency
|
||||
registry.insertQueue = registry.insertQueue or setmetatable({},meta)
|
||||
registry.insertQueue[eventname][self] = regfunc
|
||||
end
|
||||
end
|
||||
|
||||
-- Unregister a callback
|
||||
target[UnregisterName] = function(self, eventname)
|
||||
if not self or self==target then
|
||||
error("Usage: "..UnregisterName.."(eventname): bad 'self'", 2)
|
||||
end
|
||||
if type(eventname) ~= "string" then
|
||||
error("Usage: "..UnregisterName.."(eventname): 'eventname' - string expected.", 2)
|
||||
end
|
||||
if rawget(events, eventname) and events[eventname][self] then
|
||||
events[eventname][self] = nil
|
||||
-- Fire OnUnused callback?
|
||||
if registry.OnUnused and not next(events[eventname]) then
|
||||
registry.OnUnused(registry, target, eventname)
|
||||
end
|
||||
end
|
||||
if registry.insertQueue and rawget(registry.insertQueue, eventname) and registry.insertQueue[eventname][self] then
|
||||
registry.insertQueue[eventname][self] = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- OPTIONAL: Unregister all callbacks for given selfs/addonIds
|
||||
if UnregisterAllName then
|
||||
target[UnregisterAllName] = function(...)
|
||||
if select("#",...)<1 then
|
||||
error("Usage: "..UnregisterAllName.."([whatFor]): missing 'self' or \"addonId\" to unregister events for.", 2)
|
||||
end
|
||||
if select("#",...)==1 and ...==target then
|
||||
error("Usage: "..UnregisterAllName.."([whatFor]): supply a meaningful 'self' or \"addonId\"", 2)
|
||||
end
|
||||
|
||||
|
||||
for i=1,select("#",...) do
|
||||
local self = select(i,...)
|
||||
if registry.insertQueue then
|
||||
for eventname, callbacks in pairs(registry.insertQueue) do
|
||||
if callbacks[self] then
|
||||
callbacks[self] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
for eventname, callbacks in pairs(events) do
|
||||
if callbacks[self] then
|
||||
callbacks[self] = nil
|
||||
-- Fire OnUnused callback?
|
||||
if registry.OnUnused and not next(callbacks) then
|
||||
registry.OnUnused(registry, target, eventname)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return registry
|
||||
end
|
||||
|
||||
|
||||
-- CallbackHandler purposefully does NOT do explicit embedding. Nor does it
|
||||
-- try to upgrade old implicit embeds since the system is selfcontained and
|
||||
-- relies on closures to work.
|
||||
|
||||
@@ -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="CallbackHandler-1.0.lua"/>
|
||||
</Ui>
|
||||
29
Libraries/Ace3/LICENSE.txt
Normal file
29
Libraries/Ace3/LICENSE.txt
Normal file
@@ -0,0 +1,29 @@
|
||||
Copyright (c) 2007, Ace3 Development Team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Redistribution of a stand alone version is strictly prohibited without
|
||||
prior written authorization from the Lead of the Ace3 Development Team.
|
||||
* Neither the name of the Ace3 Development Team nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
30
Libraries/Ace3/LibStub/LibStub.lua
Normal file
30
Libraries/Ace3/LibStub/LibStub.lua
Normal file
@@ -0,0 +1,30 @@
|
||||
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info
|
||||
-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
|
||||
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
|
||||
local LibStub = _G[LIBSTUB_MAJOR]
|
||||
|
||||
if not LibStub or LibStub.minor < LIBSTUB_MINOR then
|
||||
LibStub = LibStub or {libs = {}, minors = {} }
|
||||
_G[LIBSTUB_MAJOR] = LibStub
|
||||
LibStub.minor = LIBSTUB_MINOR
|
||||
|
||||
function LibStub:NewLibrary(major, minor)
|
||||
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
|
||||
minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")
|
||||
|
||||
local oldminor = self.minors[major]
|
||||
if oldminor and oldminor >= minor then return nil end
|
||||
self.minors[major], self.libs[major] = minor, self.libs[major] or {}
|
||||
return self.libs[major], oldminor
|
||||
end
|
||||
|
||||
function LibStub:GetLibrary(major, silent)
|
||||
if not self.libs[major] and not silent then
|
||||
error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
|
||||
end
|
||||
return self.libs[major], self.minors[major]
|
||||
end
|
||||
|
||||
function LibStub:IterateLibraries() return pairs(self.libs) end
|
||||
setmetatable(LibStub, { __call = LibStub.GetLibrary })
|
||||
end
|
||||
1779
Libraries/LibActionButton-1.0/LibActionButton-1.0.lua
Normal file
1779
Libraries/LibActionButton-1.0/LibActionButton-1.0.lua
Normal file
File diff suppressed because it is too large
Load Diff
5
Libraries/LibActionButton-1.0/LibActionButton-1.0.xml
Normal file
5
Libraries/LibActionButton-1.0/LibActionButton-1.0.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<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="LibButtonGlow-1.0\LibButtonGlow-1.0.lua"/>
|
||||
<Script file="LibActionButton-1.0.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,256 @@
|
||||
--[[
|
||||
Copyright (c) 2015-2020, Hendrik "nevcairiel" Leppkes <h.leppkes@gmail.com>
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the developer nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
]]
|
||||
local MAJOR_VERSION = "LibButtonGlow-1.0"
|
||||
local MINOR_VERSION = 7
|
||||
|
||||
if not LibStub then error(MAJOR_VERSION .. " requires LibStub.") end
|
||||
local lib, oldversion = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
|
||||
if not lib then return end
|
||||
|
||||
local Masque = LibStub("Masque", true)
|
||||
|
||||
lib.unusedOverlays = lib.unusedOverlays or {}
|
||||
lib.numOverlays = lib.numOverlays or 0
|
||||
|
||||
local tinsert, tremove, tostring = table.insert, table.remove, tostring
|
||||
|
||||
local function OverlayGlowAnimOutFinished(animGroup)
|
||||
local overlay = animGroup:GetParent()
|
||||
local frame = overlay:GetParent()
|
||||
overlay:Hide()
|
||||
tinsert(lib.unusedOverlays, overlay)
|
||||
frame.__LBGoverlay = nil
|
||||
end
|
||||
|
||||
local function OverlayGlow_OnHide(self)
|
||||
if self.animOut:IsPlaying() then
|
||||
self.animOut:Stop()
|
||||
OverlayGlowAnimOutFinished(self.animOut)
|
||||
end
|
||||
end
|
||||
|
||||
local function OverlayGlow_OnUpdate(self, elapsed)
|
||||
AnimateTexCoords(self.ants, 256, 256, 48, 48, 22, elapsed, 0.01)
|
||||
local cooldown = self:GetParent().cooldown
|
||||
-- we need some threshold to avoid dimming the glow during the gdc
|
||||
-- (using 1500 exactly seems risky, what if casting speed is slowed or something?)
|
||||
if cooldown and cooldown:IsShown() and cooldown:GetCooldownDuration() > 3000 then
|
||||
self:SetAlpha(0.5)
|
||||
else
|
||||
self:SetAlpha(1.0)
|
||||
end
|
||||
end
|
||||
|
||||
local function CreateScaleAnim(group, target, order, duration, x, y, delay)
|
||||
local scale = group:CreateAnimation("Scale")
|
||||
scale:SetTarget(target:GetName())
|
||||
scale:SetOrder(order)
|
||||
scale:SetDuration(duration)
|
||||
scale:SetScale(x, y)
|
||||
|
||||
if delay then
|
||||
scale:SetStartDelay(delay)
|
||||
end
|
||||
end
|
||||
|
||||
local function CreateAlphaAnim(group, target, order, duration, fromAlpha, toAlpha, delay)
|
||||
local alpha = group:CreateAnimation("Alpha")
|
||||
alpha:SetTarget(target:GetName())
|
||||
alpha:SetOrder(order)
|
||||
alpha:SetDuration(duration)
|
||||
alpha:SetFromAlpha(fromAlpha)
|
||||
alpha:SetToAlpha(toAlpha)
|
||||
|
||||
if delay then
|
||||
alpha:SetStartDelay(delay)
|
||||
end
|
||||
end
|
||||
|
||||
local function AnimIn_OnPlay(group)
|
||||
local frame = group:GetParent()
|
||||
local frameWidth, frameHeight = frame:GetSize()
|
||||
frame.spark:SetSize(frameWidth, frameHeight)
|
||||
frame.spark:SetAlpha(0.3)
|
||||
frame.innerGlow:SetSize(frameWidth / 2, frameHeight / 2)
|
||||
frame.innerGlow:SetAlpha(1.0)
|
||||
frame.innerGlowOver:SetAlpha(1.0)
|
||||
frame.outerGlow:SetSize(frameWidth * 2, frameHeight * 2)
|
||||
frame.outerGlow:SetAlpha(1.0)
|
||||
frame.outerGlowOver:SetAlpha(1.0)
|
||||
frame.ants:SetSize(frameWidth * 0.85, frameHeight * 0.85)
|
||||
frame.ants:SetAlpha(0)
|
||||
frame:Show()
|
||||
end
|
||||
|
||||
local function AnimIn_OnFinished(group)
|
||||
local frame = group:GetParent()
|
||||
local frameWidth, frameHeight = frame:GetSize()
|
||||
frame.spark:SetAlpha(0)
|
||||
frame.innerGlow:SetAlpha(0)
|
||||
frame.innerGlow:SetSize(frameWidth, frameHeight)
|
||||
frame.innerGlowOver:SetAlpha(0.0)
|
||||
frame.outerGlow:SetSize(frameWidth, frameHeight)
|
||||
frame.outerGlowOver:SetAlpha(0.0)
|
||||
frame.outerGlowOver:SetSize(frameWidth, frameHeight)
|
||||
frame.ants:SetAlpha(1.0)
|
||||
end
|
||||
|
||||
local function CreateOverlayGlow()
|
||||
lib.numOverlays = lib.numOverlays + 1
|
||||
|
||||
-- create frame and textures
|
||||
local name = "ButtonGlowOverlay" .. tostring(lib.numOverlays)
|
||||
local overlay = CreateFrame("Frame", name, UIParent)
|
||||
|
||||
-- spark
|
||||
overlay.spark = overlay:CreateTexture(name .. "Spark", "BACKGROUND")
|
||||
overlay.spark:SetPoint("CENTER")
|
||||
overlay.spark:SetAlpha(0)
|
||||
overlay.spark:SetTexture([[Interface\SpellActivationOverlay\IconAlert]])
|
||||
overlay.spark:SetTexCoord(0.00781250, 0.61718750, 0.00390625, 0.26953125)
|
||||
|
||||
-- inner glow
|
||||
overlay.innerGlow = overlay:CreateTexture(name .. "InnerGlow", "ARTWORK")
|
||||
overlay.innerGlow:SetPoint("CENTER")
|
||||
overlay.innerGlow:SetAlpha(0)
|
||||
overlay.innerGlow:SetTexture([[Interface\SpellActivationOverlay\IconAlert]])
|
||||
overlay.innerGlow:SetTexCoord(0.00781250, 0.50781250, 0.27734375, 0.52734375)
|
||||
|
||||
-- inner glow over
|
||||
overlay.innerGlowOver = overlay:CreateTexture(name .. "InnerGlowOver", "ARTWORK")
|
||||
overlay.innerGlowOver:SetPoint("TOPLEFT", overlay.innerGlow, "TOPLEFT")
|
||||
overlay.innerGlowOver:SetPoint("BOTTOMRIGHT", overlay.innerGlow, "BOTTOMRIGHT")
|
||||
overlay.innerGlowOver:SetAlpha(0)
|
||||
overlay.innerGlowOver:SetTexture([[Interface\SpellActivationOverlay\IconAlert]])
|
||||
overlay.innerGlowOver:SetTexCoord(0.00781250, 0.50781250, 0.53515625, 0.78515625)
|
||||
|
||||
-- outer glow
|
||||
overlay.outerGlow = overlay:CreateTexture(name .. "OuterGlow", "ARTWORK")
|
||||
overlay.outerGlow:SetPoint("CENTER")
|
||||
overlay.outerGlow:SetAlpha(0)
|
||||
overlay.outerGlow:SetTexture([[Interface\SpellActivationOverlay\IconAlert]])
|
||||
overlay.outerGlow:SetTexCoord(0.00781250, 0.50781250, 0.27734375, 0.52734375)
|
||||
|
||||
-- outer glow over
|
||||
overlay.outerGlowOver = overlay:CreateTexture(name .. "OuterGlowOver", "ARTWORK")
|
||||
overlay.outerGlowOver:SetPoint("TOPLEFT", overlay.outerGlow, "TOPLEFT")
|
||||
overlay.outerGlowOver:SetPoint("BOTTOMRIGHT", overlay.outerGlow, "BOTTOMRIGHT")
|
||||
overlay.outerGlowOver:SetAlpha(0)
|
||||
overlay.outerGlowOver:SetTexture([[Interface\SpellActivationOverlay\IconAlert]])
|
||||
overlay.outerGlowOver:SetTexCoord(0.00781250, 0.50781250, 0.53515625, 0.78515625)
|
||||
|
||||
-- ants
|
||||
overlay.ants = overlay:CreateTexture(name .. "Ants", "OVERLAY")
|
||||
overlay.ants:SetPoint("CENTER")
|
||||
overlay.ants:SetAlpha(0)
|
||||
overlay.ants:SetTexture([[Interface\SpellActivationOverlay\IconAlertAnts]])
|
||||
|
||||
-- setup antimations
|
||||
overlay.animIn = overlay:CreateAnimationGroup()
|
||||
CreateScaleAnim(overlay.animIn, overlay.spark, 1, 0.2, 1.5, 1.5)
|
||||
CreateAlphaAnim(overlay.animIn, overlay.spark, 1, 0.2, 0, 1)
|
||||
CreateScaleAnim(overlay.animIn, overlay.innerGlow, 1, 0.3, 2, 2)
|
||||
CreateScaleAnim(overlay.animIn, overlay.innerGlowOver, 1, 0.3, 2, 2)
|
||||
CreateAlphaAnim(overlay.animIn, overlay.innerGlowOver, 1, 0.3, 1, 0)
|
||||
CreateScaleAnim(overlay.animIn, overlay.outerGlow, 1, 0.3, 0.5, 0.5)
|
||||
CreateScaleAnim(overlay.animIn, overlay.outerGlowOver, 1, 0.3, 0.5, 0.5)
|
||||
CreateAlphaAnim(overlay.animIn, overlay.outerGlowOver, 1, 0.3, 1, 0)
|
||||
CreateScaleAnim(overlay.animIn, overlay.spark, 1, 0.2, 2/3, 2/3, 0.2)
|
||||
CreateAlphaAnim(overlay.animIn, overlay.spark, 1, 0.2, 1, 0, 0.2)
|
||||
CreateAlphaAnim(overlay.animIn, overlay.innerGlow, 1, 0.2, 1, 0, 0.3)
|
||||
CreateAlphaAnim(overlay.animIn, overlay.ants, 1, 0.2, 0, 1, 0.3)
|
||||
overlay.animIn:SetScript("OnPlay", AnimIn_OnPlay)
|
||||
overlay.animIn:SetScript("OnFinished", AnimIn_OnFinished)
|
||||
|
||||
overlay.animOut = overlay:CreateAnimationGroup()
|
||||
CreateAlphaAnim(overlay.animOut, overlay.outerGlowOver, 1, 0.2, 0, 1)
|
||||
CreateAlphaAnim(overlay.animOut, overlay.ants, 1, 0.2, 1, 0)
|
||||
CreateAlphaAnim(overlay.animOut, overlay.outerGlowOver, 2, 0.2, 1, 0)
|
||||
CreateAlphaAnim(overlay.animOut, overlay.outerGlow, 2, 0.2, 1, 0)
|
||||
overlay.animOut:SetScript("OnFinished", OverlayGlowAnimOutFinished)
|
||||
|
||||
-- scripts
|
||||
overlay:SetScript("OnUpdate", OverlayGlow_OnUpdate)
|
||||
overlay:SetScript("OnHide", OverlayGlow_OnHide)
|
||||
|
||||
overlay.__LBGVersion = MINOR_VERSION
|
||||
|
||||
return overlay
|
||||
end
|
||||
|
||||
local function GetOverlayGlow()
|
||||
local overlay = tremove(lib.unusedOverlays)
|
||||
if not overlay then
|
||||
overlay = CreateOverlayGlow()
|
||||
end
|
||||
return overlay
|
||||
end
|
||||
|
||||
function lib.ShowOverlayGlow(frame)
|
||||
if frame.__LBGoverlay then
|
||||
if frame.__LBGoverlay.animOut:IsPlaying() then
|
||||
frame.__LBGoverlay.animOut:Stop()
|
||||
frame.__LBGoverlay.animIn:Play()
|
||||
end
|
||||
else
|
||||
local overlay = GetOverlayGlow()
|
||||
local frameWidth, frameHeight = frame:GetSize()
|
||||
overlay:SetParent(frame)
|
||||
overlay:SetFrameLevel(frame:GetFrameLevel() + 5)
|
||||
overlay:ClearAllPoints()
|
||||
--Make the height/width available before the next frame:
|
||||
overlay:SetSize(frameWidth * 1.4, frameHeight * 1.4)
|
||||
overlay:SetPoint("TOPLEFT", frame, "TOPLEFT", -frameWidth * 0.2, frameHeight * 0.2)
|
||||
overlay:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", frameWidth * 0.2, -frameHeight * 0.2)
|
||||
overlay.animIn:Play()
|
||||
frame.__LBGoverlay = overlay
|
||||
|
||||
if Masque and Masque.UpdateSpellAlert and (not frame.overlay or not issecurevariable(frame, "overlay")) then
|
||||
local old_overlay = frame.overlay
|
||||
frame.overlay = overlay
|
||||
Masque:UpdateSpellAlert(frame)
|
||||
|
||||
frame.overlay = old_overlay
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function lib.HideOverlayGlow(frame)
|
||||
if frame.__LBGoverlay then
|
||||
if frame.__LBGoverlay.animIn:IsPlaying() then
|
||||
frame.__LBGoverlay.animIn:Stop()
|
||||
end
|
||||
if frame:IsVisible() then
|
||||
frame.__LBGoverlay.animOut:Play()
|
||||
else
|
||||
OverlayGlowAnimOutFinished(frame.__LBGoverlay.animOut)
|
||||
end
|
||||
end
|
||||
end
|
||||
1235
Libraries/LibAnim/LibAnim.lua
Normal file
1235
Libraries/LibAnim/LibAnim.lua
Normal file
File diff suppressed because it is too large
Load Diff
7
Libraries/LibAnim/LibAnim.toc
Normal file
7
Libraries/LibAnim/LibAnim.toc
Normal file
@@ -0,0 +1,7 @@
|
||||
## Interface: 60200
|
||||
## Author: Hydra
|
||||
## Version: 2.01
|
||||
## Title: LibAnim
|
||||
## Notes: Animations!
|
||||
|
||||
LibAnim.lua
|
||||
164
Libraries/LibBase64-1.0/LibBase64-1.0.lua
Normal file
164
Libraries/LibBase64-1.0/LibBase64-1.0.lua
Normal file
@@ -0,0 +1,164 @@
|
||||
--[[
|
||||
Name: LibBase64-1.0
|
||||
Author(s): ckknight (ckknight@gmail.com)
|
||||
Website: http://www.wowace.com/projects/libbase64-1-0/
|
||||
Description: A library to encode and decode Base64 strings
|
||||
License: MIT
|
||||
]]
|
||||
|
||||
local MAJOR, MINOR = 'LibBase64-1.0-ElvUI', 2
|
||||
local LibBase64 = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
if not LibBase64 then return end
|
||||
|
||||
local wipe, type, error, format, strsub, strchar, strbyte, tconcat = wipe, type, error, format, strsub, strchar, strbyte, table.concat
|
||||
local _chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||||
local byteToNum, numToChar = {}, {}
|
||||
for i = 1, #_chars do
|
||||
numToChar[i - 1] = strsub(_chars, i, i)
|
||||
byteToNum[strbyte(_chars, i)] = i - 1
|
||||
end
|
||||
|
||||
local t = {}
|
||||
local equals_byte = strbyte("=")
|
||||
local whitespace = {
|
||||
[strbyte(" ")] = true,
|
||||
[strbyte("\t")] = true,
|
||||
[strbyte("\n")] = true,
|
||||
[strbyte("\r")] = true,
|
||||
}
|
||||
|
||||
--- Encode a normal bytestring into a Base64-encoded string
|
||||
-- @param text a bytestring, can be binary data
|
||||
-- @param maxLineLength This should be a multiple of 4, greater than 0 or nil. If non-nil, it will break up the output into lines no longer than the given number of characters. 76 is recommended.
|
||||
-- @param lineEnding a string to end each line with. This is "\r\n" by default.
|
||||
-- @usage LibBase64.Encode("Hello, how are you doing today?") == "SGVsbG8sIGhvdyBhcmUgeW91IGRvaW5nIHRvZGF5Pw=="
|
||||
-- @return a Base64-encoded string
|
||||
function LibBase64:Encode(text, maxLineLength, lineEnding)
|
||||
if type(text) ~= "string" then
|
||||
error(format("Bad argument #1 to `Encode'. Expected string, got %q", type(text)), 2)
|
||||
end
|
||||
|
||||
if maxLineLength then
|
||||
if type(maxLineLength) ~= "number" then
|
||||
error(format("Bad argument #2 to `Encode'. Expected number or nil, got %q", type(maxLineLength)), 2)
|
||||
elseif (maxLineLength % 4) ~= 0 then
|
||||
error(format("Bad argument #2 to `Encode'. Expected a multiple of 4, got %s", maxLineLength), 2)
|
||||
elseif maxLineLength <= 0 then
|
||||
error(format("Bad argument #2 to `Encode'. Expected a number > 0, got %s", maxLineLength), 2)
|
||||
end
|
||||
end
|
||||
|
||||
if lineEnding == nil then
|
||||
lineEnding = "\r\n"
|
||||
elseif type(lineEnding) ~= "string" then
|
||||
error(format("Bad argument #3 to `Encode'. Expected string, got %q", type(lineEnding)), 2)
|
||||
end
|
||||
|
||||
local currentLength = 0
|
||||
for i = 1, #text, 3 do
|
||||
local a, b, c = strbyte(text, i, i+2)
|
||||
local nilNum = 0
|
||||
if not b then
|
||||
nilNum, b, c = 2, 0, 0
|
||||
elseif not c then
|
||||
nilNum, c = 1, 0
|
||||
end
|
||||
|
||||
local num = a * 2^16 + b * 2^8 + c
|
||||
local d = num % 2^6;num = (num - d) / 2^6
|
||||
c = num % 2^6;num = (num - c) / 2^6
|
||||
b = num % 2^6;num = (num - b) / 2^6
|
||||
a = num % 2^6
|
||||
|
||||
t[#t+1] = numToChar[a]
|
||||
t[#t+1] = numToChar[b]
|
||||
t[#t+1] = (nilNum >= 2) and "=" or numToChar[c]
|
||||
t[#t+1] = (nilNum >= 1) and "=" or numToChar[d]
|
||||
|
||||
currentLength = currentLength + 4
|
||||
if maxLineLength and (currentLength % maxLineLength) == 0 then
|
||||
t[#t+1] = lineEnding
|
||||
end
|
||||
end
|
||||
|
||||
local s = tconcat(t)
|
||||
wipe(t)
|
||||
|
||||
return s
|
||||
end
|
||||
|
||||
local t2 = {}
|
||||
|
||||
--- Decode a Base64-encoded string into a bytestring
|
||||
-- this will raise an error if the data passed in is not a Base64-encoded string
|
||||
-- this will ignore whitespace, but not invalid characters
|
||||
-- @param text a Base64-encoded string
|
||||
-- @usage LibBase64.Encode("SGVsbG8sIGhvdyBhcmUgeW91IGRvaW5nIHRvZGF5Pw==") == "Hello, how are you doing today?"
|
||||
-- @return a bytestring
|
||||
function LibBase64:Decode(text)
|
||||
if type(text) ~= "string" then
|
||||
error(format("Bad argument #1 to `Decode'. Expected string, got %q", type(text)), 2)
|
||||
end
|
||||
|
||||
for i = 1, #text do
|
||||
local byte = strbyte(text, i)
|
||||
if not (whitespace[byte] or byte == equals_byte) then
|
||||
local num = byteToNum[byte]
|
||||
if not num then
|
||||
wipe(t2)
|
||||
|
||||
error(format("Bad argument #1 to `Decode'. Received an invalid char: %q", strsub(text, i, i)), 2)
|
||||
end
|
||||
|
||||
t2[#t2+1] = num
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, #t2, 4 do
|
||||
local a, b, c, d = t2[i], t2[i+1], t2[i+2], t2[i+3]
|
||||
local nilNum = 0
|
||||
if not c then
|
||||
nilNum, c, d = 2, 0, 0
|
||||
elseif not d then
|
||||
nilNum, d = 1, 0
|
||||
end
|
||||
|
||||
local num = a * 2^18 + b * 2^12 + c * 2^6 + d
|
||||
c = num % 2^8;num = (num - c) / 2^8
|
||||
b = num % 2^8;num = (num - b) / 2^8
|
||||
a = num % 2^8
|
||||
|
||||
t[#t+1] = strchar(a)
|
||||
if nilNum < 2 then t[#t+1] = strchar(b) end
|
||||
if nilNum < 1 then t[#t+1] = strchar(c) end
|
||||
end
|
||||
|
||||
wipe(t2)
|
||||
|
||||
local s = tconcat(t)
|
||||
wipe(t)
|
||||
|
||||
return s
|
||||
end
|
||||
|
||||
function LibBase64:IsBase64(text)
|
||||
if type(text) ~= "string" then
|
||||
error(format("Bad argument #1 to `IsBase64'. Expected string, got %q", type(text)), 2)
|
||||
end
|
||||
|
||||
if #text % 4 ~= 0 then
|
||||
return false
|
||||
end
|
||||
|
||||
for i = 1, #text do
|
||||
local byte = strbyte(text, i)
|
||||
if not (whitespace[byte] or byte == equals_byte) then
|
||||
local num = byteToNum[byte]
|
||||
if not num then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
4
Libraries/LibBase64-1.0/lib.xml
Normal file
4
Libraries/LibBase64-1.0/lib.xml
Normal 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="LibBase64-1.0.lua" />
|
||||
</Ui>
|
||||
199
Libraries/LibChatAnims/LibChatAnims.lua
Normal file
199
Libraries/LibChatAnims/LibChatAnims.lua
Normal file
@@ -0,0 +1,199 @@
|
||||
|
||||
local MAJOR, MINOR = "LibChatAnims", 2 -- Bump minor on changes
|
||||
local LCA = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
if not LCA then return end -- No upgrade needed
|
||||
|
||||
LCA.animations = LCA.animations or {} -- Animation storage
|
||||
local anims = LCA.animations
|
||||
|
||||
----------------------------------------------------
|
||||
-- Note, most of this code is simply replicated from
|
||||
-- Blizzard's FloatingChatFrame.lua file.
|
||||
-- The only real changes are the creation and use
|
||||
-- of animations vs the use of UIFrameFlash.
|
||||
--
|
||||
|
||||
FCFDockOverflowButton_UpdatePulseState = function(self)
|
||||
local dock = self:GetParent()
|
||||
local shouldPulse = false
|
||||
for _, chatFrame in pairs(FCFDock_GetChatFrames(dock)) do
|
||||
local chatTab = _G[chatFrame:GetName().."Tab"]
|
||||
if ( not chatFrame.isStaticDocked and chatTab.alerting) then
|
||||
-- Make sure the rects are valid. (Not always the case when resizing the WoW client
|
||||
if ( not chatTab:GetRight() or not dock.scrollFrame:GetRight() ) then
|
||||
return false
|
||||
end
|
||||
-- Check if it's off the screen.
|
||||
local DELTA = 3 -- Chosen through experimentation
|
||||
if ( chatTab:GetRight() < (dock.scrollFrame:GetLeft() + DELTA) or chatTab:GetLeft() > (dock.scrollFrame:GetRight() - DELTA) ) then
|
||||
shouldPulse = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local tex = self:GetHighlightTexture()
|
||||
if shouldPulse then
|
||||
if not anims[tex] then
|
||||
anims[tex] = tex:CreateAnimationGroup()
|
||||
|
||||
local fade1 = anims[tex]:CreateAnimation("Alpha")
|
||||
fade1:SetDuration(1)
|
||||
fade1:SetFromAlpha(0)
|
||||
fade1:SetToAlpha(1)
|
||||
fade1:SetOrder(1)
|
||||
|
||||
local fade2 = anims[tex]:CreateAnimation("Alpha")
|
||||
fade2:SetDuration(1)
|
||||
fade2:SetFromAlpha(1)
|
||||
fade2:SetToAlpha(0)
|
||||
fade2:SetOrder(2)
|
||||
end
|
||||
tex:Show()
|
||||
tex:SetAlpha(0)
|
||||
anims[tex]:SetLooping("REPEAT")
|
||||
anims[tex]:Play()
|
||||
|
||||
self:LockHighlight()
|
||||
self.alerting = true
|
||||
else
|
||||
if anims[tex] then
|
||||
anims[tex]:Stop()
|
||||
end
|
||||
self:UnlockHighlight()
|
||||
tex:SetAlpha(1)
|
||||
tex:Show()
|
||||
self.alerting = false
|
||||
end
|
||||
|
||||
if self.list:IsShown() then
|
||||
FCFDockOverflowList_Update(self.list, dock)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
FCFDockOverflowListButton_SetValue = function(button, chatFrame)
|
||||
local chatTab = _G[chatFrame:GetName().."Tab"]
|
||||
button.chatFrame = chatFrame
|
||||
button:SetText(chatFrame.name)
|
||||
|
||||
local colorTable = chatTab.selectedColorTable or DEFAULT_TAB_SELECTED_COLOR_TABLE
|
||||
|
||||
if chatTab.selectedColorTable then
|
||||
button:GetFontString():SetTextColor(colorTable.r, colorTable.g, colorTable.b)
|
||||
else
|
||||
button:GetFontString():SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
|
||||
end
|
||||
|
||||
button.glow:SetVertexColor(colorTable.r, colorTable.g, colorTable.b)
|
||||
|
||||
if chatTab.conversationIcon then
|
||||
button.conversationIcon:SetVertexColor(colorTable.r, colorTable.g, colorTable.b)
|
||||
button.conversationIcon:Show()
|
||||
else
|
||||
button.conversationIcon:Hide()
|
||||
end
|
||||
|
||||
if chatTab.alerting then
|
||||
button.alerting = true
|
||||
if not anims[button.glow] then
|
||||
anims[button.glow] = button.glow:CreateAnimationGroup()
|
||||
|
||||
local fade1 = anims[button.glow]:CreateAnimation("Alpha")
|
||||
fade1:SetDuration(1)
|
||||
fade1:SetFromAlpha(0)
|
||||
fade1:SetToAlpha(1)
|
||||
fade1:SetOrder(1)
|
||||
|
||||
local fade2 = anims[button.glow]:CreateAnimation("Alpha")
|
||||
fade2:SetDuration(1)
|
||||
fade2:SetFromAlpha(1)
|
||||
fade2:SetToAlpha(0)
|
||||
fade2:SetOrder(2)
|
||||
end
|
||||
button.glow:Show()
|
||||
button.glow:SetAlpha(0)
|
||||
anims[button.glow]:SetLooping("REPEAT")
|
||||
anims[button.glow]:Play()
|
||||
else
|
||||
button.alerting = false
|
||||
if anims[button.glow] then
|
||||
anims[button.glow]:Stop()
|
||||
end
|
||||
button.glow:Hide()
|
||||
end
|
||||
button:Show()
|
||||
end
|
||||
|
||||
FCF_StartAlertFlash = function(chatFrame)
|
||||
local chatTab = _G[chatFrame:GetName().."Tab"]
|
||||
|
||||
if chatFrame.minFrame then
|
||||
if not anims[chatFrame.minFrame] then
|
||||
anims[chatFrame.minFrame] = chatFrame.minFrame.glow:CreateAnimationGroup()
|
||||
|
||||
local fade1 = anims[chatFrame.minFrame]:CreateAnimation("Alpha")
|
||||
fade1:SetDuration(1)
|
||||
fade1:SetFromAlpha(0)
|
||||
fade1:SetToAlpha(1)
|
||||
fade1:SetOrder(1)
|
||||
|
||||
local fade2 = anims[chatFrame.minFrame]:CreateAnimation("Alpha")
|
||||
fade2:SetDuration(1)
|
||||
fade2:SetFromAlpha(1)
|
||||
fade2:SetToAlpha(0)
|
||||
fade2:SetOrder(2)
|
||||
end
|
||||
chatFrame.minFrame.glow:Show()
|
||||
chatFrame.minFrame.glow:SetAlpha(0)
|
||||
anims[chatFrame.minFrame]:SetLooping("REPEAT")
|
||||
anims[chatFrame.minFrame]:Play()
|
||||
chatFrame.minFrame.alerting = true
|
||||
end
|
||||
|
||||
if not anims[chatTab.glow] then
|
||||
anims[chatTab.glow] = chatTab.glow:CreateAnimationGroup()
|
||||
|
||||
local fade1 = anims[chatTab.glow]:CreateAnimation("Alpha")
|
||||
fade1:SetDuration(1)
|
||||
fade1:SetFromAlpha(0)
|
||||
fade1:SetToAlpha(1)
|
||||
fade1:SetOrder(1)
|
||||
|
||||
local fade2 = anims[chatTab.glow]:CreateAnimation("Alpha")
|
||||
fade2:SetDuration(1)
|
||||
fade2:SetFromAlpha(1)
|
||||
fade2:SetToAlpha(0)
|
||||
fade2:SetOrder(2)
|
||||
end
|
||||
chatTab.glow:Show()
|
||||
chatTab.glow:SetAlpha(0)
|
||||
anims[chatTab.glow]:SetLooping("REPEAT")
|
||||
anims[chatTab.glow]:Play()
|
||||
chatTab.alerting = true
|
||||
|
||||
FCFTab_UpdateAlpha(chatFrame)
|
||||
FCFDockOverflowButton_UpdatePulseState(GENERAL_CHAT_DOCK.overflowButton)
|
||||
end
|
||||
|
||||
FCF_StopAlertFlash = function(chatFrame)
|
||||
local chatTab = _G[chatFrame:GetName().."Tab"]
|
||||
|
||||
if chatFrame.minFrame then
|
||||
if anims[chatFrame.minFrame] then
|
||||
anims[chatFrame.minFrame]:Stop()
|
||||
end
|
||||
chatFrame.minFrame.glow:Hide()
|
||||
chatFrame.minFrame.alerting = false
|
||||
end
|
||||
|
||||
if anims[chatTab.glow] then
|
||||
anims[chatTab.glow]:Stop()
|
||||
end
|
||||
chatTab.glow:Hide()
|
||||
chatTab.alerting = false
|
||||
|
||||
FCFTab_UpdateAlpha(chatFrame)
|
||||
FCFDockOverflowButton_UpdatePulseState(GENERAL_CHAT_DOCK.overflowButton)
|
||||
end
|
||||
|
||||
7
Libraries/LibChatAnims/LibChatAnims.xml
Normal file
7
Libraries/LibChatAnims/LibChatAnims.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<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="LibChatAnims.lua"/>
|
||||
|
||||
</Ui>
|
||||
|
||||
1259
Libraries/LibCompress/LibCompress.lua
Normal file
1259
Libraries/LibCompress/LibCompress.lua
Normal file
File diff suppressed because it is too large
Load Diff
4
Libraries/LibCompress/lib.xml
Normal file
4
Libraries/LibCompress/lib.xml
Normal 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="LibCompress.lua" />
|
||||
</Ui>
|
||||
90
Libraries/LibDataBroker/LibDataBroker-1.1.lua
Normal file
90
Libraries/LibDataBroker/LibDataBroker-1.1.lua
Normal file
@@ -0,0 +1,90 @@
|
||||
|
||||
assert(LibStub, "LibDataBroker-1.1 requires LibStub")
|
||||
assert(LibStub:GetLibrary("CallbackHandler-1.0", true), "LibDataBroker-1.1 requires CallbackHandler-1.0")
|
||||
|
||||
local lib, oldminor = LibStub:NewLibrary("LibDataBroker-1.1", 4)
|
||||
if not lib then return end
|
||||
oldminor = oldminor or 0
|
||||
|
||||
|
||||
lib.callbacks = lib.callbacks or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
|
||||
lib.attributestorage, lib.namestorage, lib.proxystorage = lib.attributestorage or {}, lib.namestorage or {}, lib.proxystorage or {}
|
||||
local attributestorage, namestorage, callbacks = lib.attributestorage, lib.namestorage, lib.callbacks
|
||||
|
||||
if oldminor < 2 then
|
||||
lib.domt = {
|
||||
__metatable = "access denied",
|
||||
__index = function(self, key) return attributestorage[self] and attributestorage[self][key] end,
|
||||
}
|
||||
end
|
||||
|
||||
if oldminor < 3 then
|
||||
lib.domt.__newindex = function(self, key, value)
|
||||
if not attributestorage[self] then attributestorage[self] = {} end
|
||||
if attributestorage[self][key] == value then return end
|
||||
attributestorage[self][key] = value
|
||||
local name = namestorage[self]
|
||||
if not name then return end
|
||||
callbacks:Fire("LibDataBroker_AttributeChanged", name, key, value, self)
|
||||
callbacks:Fire("LibDataBroker_AttributeChanged_"..name, name, key, value, self)
|
||||
callbacks:Fire("LibDataBroker_AttributeChanged_"..name.."_"..key, name, key, value, self)
|
||||
callbacks:Fire("LibDataBroker_AttributeChanged__"..key, name, key, value, self)
|
||||
end
|
||||
end
|
||||
|
||||
if oldminor < 2 then
|
||||
function lib:NewDataObject(name, dataobj)
|
||||
if self.proxystorage[name] then return end
|
||||
|
||||
if dataobj then
|
||||
assert(type(dataobj) == "table", "Invalid dataobj, must be nil or a table")
|
||||
self.attributestorage[dataobj] = {}
|
||||
for i,v in pairs(dataobj) do
|
||||
self.attributestorage[dataobj][i] = v
|
||||
dataobj[i] = nil
|
||||
end
|
||||
end
|
||||
dataobj = setmetatable(dataobj or {}, self.domt)
|
||||
self.proxystorage[name], self.namestorage[dataobj] = dataobj, name
|
||||
self.callbacks:Fire("LibDataBroker_DataObjectCreated", name, dataobj)
|
||||
return dataobj
|
||||
end
|
||||
end
|
||||
|
||||
if oldminor < 1 then
|
||||
function lib:DataObjectIterator()
|
||||
return pairs(self.proxystorage)
|
||||
end
|
||||
|
||||
function lib:GetDataObjectByName(dataobjectname)
|
||||
return self.proxystorage[dataobjectname]
|
||||
end
|
||||
|
||||
function lib:GetNameByDataObject(dataobject)
|
||||
return self.namestorage[dataobject]
|
||||
end
|
||||
end
|
||||
|
||||
if oldminor < 4 then
|
||||
local next = pairs(attributestorage)
|
||||
function lib:pairs(dataobject_or_name)
|
||||
local t = type(dataobject_or_name)
|
||||
assert(t == "string" or t == "table", "Usage: ldb:pairs('dataobjectname') or ldb:pairs(dataobject)")
|
||||
|
||||
local dataobj = self.proxystorage[dataobject_or_name] or dataobject_or_name
|
||||
assert(attributestorage[dataobj], "Data object not found")
|
||||
|
||||
return next, attributestorage[dataobj], nil
|
||||
end
|
||||
|
||||
local ipairs_iter = ipairs(attributestorage)
|
||||
function lib:ipairs(dataobject_or_name)
|
||||
local t = type(dataobject_or_name)
|
||||
assert(t == "string" or t == "table", "Usage: ldb:ipairs('dataobjectname') or ldb:ipairs(dataobject)")
|
||||
|
||||
local dataobj = self.proxystorage[dataobject_or_name] or dataobject_or_name
|
||||
assert(attributestorage[dataobj], "Data object not found")
|
||||
|
||||
return ipairs_iter, attributestorage[dataobj], 0
|
||||
end
|
||||
end
|
||||
431
Libraries/LibDualSpec-1.0/LibDualSpec-1.0.lua
Normal file
431
Libraries/LibDualSpec-1.0/LibDualSpec-1.0.lua
Normal file
@@ -0,0 +1,431 @@
|
||||
--[[
|
||||
LibDualSpec-1.0 - Adds dual spec support to individual AceDB-3.0 databases
|
||||
Copyright (C) 2009-2012 Adirelle
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Redistribution of a stand alone version is strictly prohibited without
|
||||
prior written authorization from the LibDualSpec project manager.
|
||||
* Neither the name of the LibDualSpec authors nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
--]]
|
||||
|
||||
local MAJOR, MINOR = "LibDualSpec-1.0", 17
|
||||
assert(LibStub, MAJOR.." requires LibStub")
|
||||
local lib, minor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
if not lib then return end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Library data
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
lib.eventFrame = lib.eventFrame or CreateFrame("Frame")
|
||||
|
||||
lib.registry = lib.registry or {}
|
||||
lib.options = lib.options or {}
|
||||
lib.mixin = lib.mixin or {}
|
||||
lib.upgrades = lib.upgrades or {}
|
||||
lib.currentSpec = lib.currentSpec or 0
|
||||
|
||||
if minor and minor < 15 then
|
||||
lib.talentsLoaded, lib.talentGroup = nil, nil
|
||||
lib.specLoaded, lib.specGroup = nil, nil
|
||||
lib.eventFrame:UnregisterAllEvents()
|
||||
wipe(lib.options)
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Locals
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
local registry = lib.registry
|
||||
local options = lib.options
|
||||
local mixin = lib.mixin
|
||||
local upgrades = lib.upgrades
|
||||
|
||||
-- "Externals"
|
||||
local AceDB3 = LibStub('AceDB-3.0', true)
|
||||
local AceDBOptions3 = LibStub('AceDBOptions-3.0', true)
|
||||
local AceConfigRegistry3 = LibStub('AceConfigRegistry-3.0', true)
|
||||
|
||||
-- classId specialization functions don't require player data to be loaded
|
||||
local _, _, classId = UnitClass("player")
|
||||
local numSpecs = GetNumSpecializationsForClassID(classId)
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Localization
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
local L_ENABLED = "Enable spec profiles"
|
||||
local L_ENABLED_DESC = "When enabled, your profile will be set to the specified profile when you change specialization."
|
||||
local L_CURRENT = "%s (Current)" -- maybe something like >> %s << and/or coloring to avoid localization?
|
||||
|
||||
do
|
||||
local locale = GetLocale()
|
||||
if locale == "frFR" then
|
||||
-- L_ENABLED = "Enable spec profiles"
|
||||
-- L_ENABLED_DESC = "When enabled, your profile will be set to the specified profile when you change specialization."
|
||||
-- L_CURRENT = "%s (Current)"
|
||||
elseif locale == "deDE" then
|
||||
L_ENABLED = "Spezialisierungsprofile aktivieren"
|
||||
L_ENABLED_DESC = "Falls diese Option aktiviert ist, wird dein Profil auf das angegebene Profil gesetzt, wenn du die Spezialisierung wechselst."
|
||||
L_CURRENT = "%s (Momentan)"
|
||||
elseif locale == "koKR" then
|
||||
-- L_ENABLED = "Enable spec profiles"
|
||||
-- L_ENABLED_DESC = "When enabled, your profile will be set to the specified profile when you change specialization."
|
||||
-- L_CURRENT = "%s (Current)"
|
||||
elseif locale == "ruRU" then
|
||||
L_ENABLED = "Включить профили специализации"
|
||||
L_ENABLED_DESC = "Если включено, ваш профиль будет зависеть от выбранной специализации."
|
||||
L_CURRENT = "%s (Текущий)"
|
||||
elseif locale == "zhCN" then
|
||||
L_ENABLED = "启用专精配置文件"
|
||||
L_ENABLED_DESC = "当启用后,当切换专精时配置文件将设置为专精配置文件。"
|
||||
L_CURRENT = "%s(当前)"
|
||||
elseif locale == "zhTW" then
|
||||
L_ENABLED = "啟用專精設定檔"
|
||||
L_ENABLED_DESC = "當啟用後,當你切換專精時設定檔會設定為專精設定檔。"
|
||||
L_CURRENT = "%s (目前) "
|
||||
elseif locale == "esES" or locale == "esMX" then
|
||||
-- L_ENABLED = "Enable spec profiles"
|
||||
-- L_ENABLED_DESC = "When enabled, your profile will be set to the specified profile when you change specialization."
|
||||
-- L_CURRENT = "%s (Current)"
|
||||
elseif locale == "ptBR" then
|
||||
-- L_ENABLED = "Enable spec profiles"
|
||||
-- L_ENABLED_DESC = "When enabled, your profile will be set to the specified profile when you change specialization."
|
||||
-- L_CURRENT = "%s (Current)"
|
||||
elseif locale == "itIT" then
|
||||
-- L_ENABLED = "Enable spec profiles"
|
||||
-- L_ENABLED_DESC = "When enabled, your profile will be set to the specified profile when you change specialization."
|
||||
-- L_CURRENT = "%s (Current)"
|
||||
end
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Mixin
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
--- Get dual spec feature status.
|
||||
-- @return (boolean) true is dual spec feature enabled.
|
||||
-- @name enhancedDB:IsDualSpecEnabled
|
||||
function mixin:IsDualSpecEnabled()
|
||||
return registry[self].db.char.enabled
|
||||
end
|
||||
|
||||
--- Enable/disabled dual spec feature.
|
||||
-- @param enabled (boolean) true to enable dual spec feature, false to disable it.
|
||||
-- @name enhancedDB:SetDualSpecEnabled
|
||||
function mixin:SetDualSpecEnabled(enabled)
|
||||
local db = registry[self].db.char
|
||||
db.enabled = not not enabled
|
||||
|
||||
local currentProfile = self:GetCurrentProfile()
|
||||
for i = 1, numSpecs do
|
||||
-- nil out entries on disable, set nil entries to the current profile on enable
|
||||
db[i] = enabled and (db[i] or currentProfile) or nil
|
||||
end
|
||||
|
||||
self:CheckDualSpecState()
|
||||
end
|
||||
|
||||
--- Get the profile assigned to a specialization.
|
||||
-- Defaults to the current profile.
|
||||
-- @param spec (number) the specialization index.
|
||||
-- @return (string) the profile name.
|
||||
-- @name enhancedDB:GetDualSpecProfile
|
||||
function mixin:GetDualSpecProfile(spec)
|
||||
return registry[self].db.char[spec or lib.currentSpec] or self:GetCurrentProfile()
|
||||
end
|
||||
|
||||
--- Set the profile assigned to a specialization.
|
||||
-- No validation are done to ensure the profile is valid.
|
||||
-- @param profileName (string) the profile name to use.
|
||||
-- @param spec (number) the specialization index.
|
||||
-- @name enhancedDB:SetDualSpecProfile
|
||||
function mixin:SetDualSpecProfile(profileName, spec)
|
||||
spec = spec or lib.currentSpec
|
||||
if spec < 1 or spec > numSpecs then return end
|
||||
|
||||
registry[self].db.char[spec] = profileName
|
||||
self:CheckDualSpecState()
|
||||
end
|
||||
|
||||
--- Check if a profile swap should occur.
|
||||
-- There is normally no reason to call this method directly as LibDualSpec
|
||||
-- takes care of calling it at the appropriate time.
|
||||
-- @name enhancedDB:CheckDualSpecState
|
||||
function mixin:CheckDualSpecState()
|
||||
if not registry[self].db.char.enabled then return end
|
||||
if lib.currentSpec == 0 then return end
|
||||
|
||||
local profileName = self:GetDualSpecProfile()
|
||||
if profileName ~= self:GetCurrentProfile() then
|
||||
self:SetProfile(profileName)
|
||||
end
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- AceDB-3.0 support
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
local function EmbedMixin(target)
|
||||
for k,v in next, mixin do
|
||||
rawset(target, k, v)
|
||||
end
|
||||
end
|
||||
|
||||
-- Upgrade settings from current/alternate system.
|
||||
-- This sets the current profile as the profile for your current spec and your
|
||||
-- swapped profile as the profile for the rest of your specs.
|
||||
local function UpgradeDatabase(target)
|
||||
if lib.currentSpec == 0 then
|
||||
upgrades[target] = true
|
||||
return
|
||||
end
|
||||
|
||||
local db = target:GetNamespace(MAJOR, true)
|
||||
if db and db.char.profile then
|
||||
for i = 1, numSpecs do
|
||||
if i == lib.currentSpec then
|
||||
db.char[i] = target:GetCurrentProfile()
|
||||
else
|
||||
db.char[i] = db.char.profile
|
||||
end
|
||||
end
|
||||
db.char.profile = nil
|
||||
db.char.specGroup = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- Reset a spec profile to the current one if its profile is deleted.
|
||||
function lib:OnProfileDeleted(event, target, profileName)
|
||||
local db = registry[target].db.char
|
||||
if not db.enabled then return end
|
||||
|
||||
for i = 1, numSpecs do
|
||||
if db[i] == profileName then
|
||||
db[i] = target:GetCurrentProfile()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Actually enhance the database
|
||||
-- This is used on first initialization and everytime the database is reset using :ResetDB
|
||||
function lib:_EnhanceDatabase(event, target)
|
||||
registry[target].db = target:GetNamespace(MAJOR, true) or target:RegisterNamespace(MAJOR)
|
||||
EmbedMixin(target)
|
||||
target:CheckDualSpecState()
|
||||
end
|
||||
|
||||
--- Embed dual spec feature into an existing AceDB-3.0 database.
|
||||
-- LibDualSpec specific methods are added to the instance.
|
||||
-- @name LibDualSpec:EnhanceDatabase
|
||||
-- @param target (table) the AceDB-3.0 instance.
|
||||
-- @param name (string) a user-friendly name of the database (best bet is the addon name).
|
||||
function lib:EnhanceDatabase(target, name)
|
||||
AceDB3 = AceDB3 or LibStub('AceDB-3.0', true)
|
||||
if type(target) ~= "table" then
|
||||
error("Usage: LibDualSpec:EnhanceDatabase(target, name): target should be a table.", 2)
|
||||
elseif type(name) ~= "string" then
|
||||
error("Usage: LibDualSpec:EnhanceDatabase(target, name): name should be a string.", 2)
|
||||
elseif not AceDB3 or not AceDB3.db_registry[target] then
|
||||
error("Usage: LibDualSpec:EnhanceDatabase(target, name): target should be an AceDB-3.0 database.", 2)
|
||||
elseif target.parent then
|
||||
error("Usage: LibDualSpec:EnhanceDatabase(target, name): cannot enhance a namespace.", 2)
|
||||
elseif registry[target] then
|
||||
return
|
||||
end
|
||||
registry[target] = { name = name }
|
||||
UpgradeDatabase(target)
|
||||
lib:_EnhanceDatabase("EnhanceDatabase", target)
|
||||
target.RegisterCallback(lib, "OnDatabaseReset", "_EnhanceDatabase")
|
||||
target.RegisterCallback(lib, "OnProfileDeleted")
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- AceDBOptions-3.0 support
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
options.new = {
|
||||
name = "New",
|
||||
type = "input",
|
||||
order = 30,
|
||||
get = false,
|
||||
set = function(info, value)
|
||||
local db = info.handler.db
|
||||
if db:IsDualSpecEnabled() then
|
||||
db:SetDualSpecProfile(value, lib.currentSpec)
|
||||
else
|
||||
db:SetProfile(value)
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
options.choose = {
|
||||
name = "Existing Profiles",
|
||||
type = "select",
|
||||
order = 40,
|
||||
get = "GetCurrentProfile",
|
||||
set = "SetProfile",
|
||||
values = "ListProfiles",
|
||||
arg = "common",
|
||||
disabled = function(info)
|
||||
return info.handler.db:IsDualSpecEnabled()
|
||||
end
|
||||
}
|
||||
|
||||
options.enabled = {
|
||||
name = "|cffffd200"..L_ENABLED.."|r",
|
||||
desc = L_ENABLED_DESC,
|
||||
descStyle = "inline",
|
||||
type = "toggle",
|
||||
order = 41,
|
||||
width = "full",
|
||||
get = function(info) return info.handler.db:IsDualSpecEnabled() end,
|
||||
set = function(info, value) info.handler.db:SetDualSpecEnabled(value) end,
|
||||
}
|
||||
|
||||
for i = 1, numSpecs do
|
||||
local _, specName = GetSpecializationInfoForClassID(classId, i)
|
||||
options["specProfile" .. i] = {
|
||||
type = "select",
|
||||
name = function() return lib.currentSpec == i and L_CURRENT:format(specName) or specName end,
|
||||
order = 42 + i,
|
||||
get = function(info) return info.handler.db:GetDualSpecProfile(i) end,
|
||||
set = function(info, value) info.handler.db:SetDualSpecProfile(value, i) end,
|
||||
values = "ListProfiles",
|
||||
arg = "common",
|
||||
disabled = function(info) return not info.handler.db:IsDualSpecEnabled() end,
|
||||
}
|
||||
end
|
||||
|
||||
--- Embed dual spec options into an existing AceDBOptions-3.0 option table.
|
||||
-- @name LibDualSpec:EnhanceOptions
|
||||
-- @param optionTable (table) The option table returned by AceDBOptions-3.0.
|
||||
-- @param target (table) The AceDB-3.0 the options operate on.
|
||||
function lib:EnhanceOptions(optionTable, target)
|
||||
AceDBOptions3 = AceDBOptions3 or LibStub('AceDBOptions-3.0', true)
|
||||
AceConfigRegistry3 = AceConfigRegistry3 or LibStub('AceConfigRegistry-3.0', true)
|
||||
if type(optionTable) ~= "table" then
|
||||
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): optionTable should be a table.", 2)
|
||||
elseif type(target) ~= "table" then
|
||||
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): target should be a table.", 2)
|
||||
elseif not AceDBOptions3 or not AceDBOptions3.optionTables[target] then
|
||||
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): optionTable is not an AceDBOptions-3.0 table.", 2)
|
||||
elseif optionTable.handler.db ~= target then
|
||||
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): optionTable must be the option table of target.", 2)
|
||||
elseif not registry[target] then
|
||||
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): EnhanceDatabase should be called before EnhanceOptions(optionTable, target).", 2)
|
||||
end
|
||||
|
||||
-- localize our replacements
|
||||
options.new.name = optionTable.args.new.name
|
||||
options.new.desc = optionTable.args.new.desc
|
||||
options.choose.name = optionTable.args.choose.name
|
||||
options.choose.desc = optionTable.args.choose.desc
|
||||
|
||||
-- add our new options
|
||||
if not optionTable.plugins then
|
||||
optionTable.plugins = {}
|
||||
end
|
||||
optionTable.plugins[MAJOR] = options
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Upgrade existing
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
for target in next, registry do
|
||||
UpgradeDatabase(target)
|
||||
EmbedMixin(target)
|
||||
target:CheckDualSpecState()
|
||||
local optionTable = AceDBOptions3 and AceDBOptions3.optionTables[target]
|
||||
if optionTable then
|
||||
lib:EnhanceOptions(optionTable, target)
|
||||
end
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Inspection
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
local function iterator(registry, key)
|
||||
local data
|
||||
key, data = next(registry, key)
|
||||
if key then
|
||||
return key, data.name
|
||||
end
|
||||
end
|
||||
|
||||
--- Iterate through enhanced AceDB3.0 instances.
|
||||
-- The iterator returns (instance, name) pairs where instance and name are the
|
||||
-- arguments that were provided to lib:EnhanceDatabase.
|
||||
-- @name LibDualSpec:IterateDatabases
|
||||
-- @return Values to be used in a for .. in .. do statement.
|
||||
function lib:IterateDatabases()
|
||||
return iterator, lib.registry
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Switching logic
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
local function eventHandler(self, event)
|
||||
lib.currentSpec = GetSpecialization() or 0
|
||||
|
||||
if event == "PLAYER_LOGIN" then
|
||||
self:UnregisterEvent(event)
|
||||
self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
|
||||
end
|
||||
|
||||
if lib.currentSpec > 0 and next(upgrades) then
|
||||
for target in next, upgrades do
|
||||
UpgradeDatabase(target)
|
||||
end
|
||||
wipe(upgrades)
|
||||
end
|
||||
|
||||
for target in next, registry do
|
||||
target:CheckDualSpecState()
|
||||
end
|
||||
|
||||
if AceConfigRegistry3 and next(registry) then
|
||||
-- Update the "Current" text in options
|
||||
-- We don't get the key for the actual registered options table, and we can't
|
||||
-- really check for our enhanced options without walking every options table,
|
||||
-- so just refresh anything.
|
||||
for appName in AceConfigRegistry3:IterateOptionsTables() do
|
||||
AceConfigRegistry3:NotifyChange(appName)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
lib.eventFrame:SetScript("OnEvent", eventHandler)
|
||||
if IsLoggedIn() then
|
||||
eventHandler(lib.eventFrame, "PLAYER_LOGIN")
|
||||
else
|
||||
lib.eventFrame:RegisterEvent("PLAYER_LOGIN")
|
||||
end
|
||||
|
||||
|
||||
329
Libraries/LibElvUIPlugin-1.0/LibElvUIPlugin-1.0.lua
Normal file
329
Libraries/LibElvUIPlugin-1.0/LibElvUIPlugin-1.0.lua
Normal file
@@ -0,0 +1,329 @@
|
||||
local MAJOR, MINOR = "LibElvUIPlugin-1.0", 36
|
||||
local lib = _G.LibStub:NewLibrary(MAJOR, MINOR)
|
||||
if not lib then return end
|
||||
-- GLOBALS: ElvUI
|
||||
|
||||
--[[----------------------------
|
||||
Plugin Table Format: (for reference only).
|
||||
{
|
||||
name - name of the plugin
|
||||
callback - callback to call when ElvUI_OptionsUI is loaded
|
||||
isLib - plugin is a library
|
||||
version - version of the plugin (pulls version info from metadata, libraries can define their own)
|
||||
|
||||
-- After new version recieved from another user:
|
||||
old - plugin is old version
|
||||
newversion - newer version number
|
||||
}
|
||||
|
||||
LibElvUIPlugin API:
|
||||
RegisterPlugin(name, callback, isLib, libVersion)
|
||||
-- Registers a module with the given name and option callback:
|
||||
name - name of plugin
|
||||
verion - version number
|
||||
isLib - plugin is a library
|
||||
libVersion - plugin library version (optional, defaults to 1)
|
||||
|
||||
HookInitialize(table, function)
|
||||
-- Posthook ElvUI Initialize function:
|
||||
table - addon table
|
||||
function - function to call after Initialize (may be a string, that exists on the addons table: table['string'])
|
||||
----------------------------]]--
|
||||
|
||||
local assert, pairs, ipairs, strlen = assert, pairs, ipairs, strlen
|
||||
local tonumber, strmatch, strsub, tinsert = tonumber, strmatch, strsub, tinsert
|
||||
local format, wipe, type, gmatch, gsub, ceil = format, wipe, type, gmatch, gsub, ceil
|
||||
|
||||
local hooksecurefunc = hooksecurefunc
|
||||
local GetAddOnMetadata = GetAddOnMetadata
|
||||
local GetNumGroupMembers = GetNumGroupMembers
|
||||
local GetLocale, IsInGuild = GetLocale, IsInGuild
|
||||
local CreateFrame, IsAddOnLoaded = CreateFrame, IsAddOnLoaded
|
||||
local IsInRaid, IsInGroup = IsInRaid, IsInGroup
|
||||
local C_ChatInfo_RegisterAddonMessagePrefix = C_ChatInfo.RegisterAddonMessagePrefix
|
||||
local C_ChatInfo_SendAddonMessage = C_ChatInfo.SendAddonMessage
|
||||
local LE_PARTY_CATEGORY_HOME = LE_PARTY_CATEGORY_HOME
|
||||
local LE_PARTY_CATEGORY_INSTANCE = LE_PARTY_CATEGORY_INSTANCE
|
||||
local UNKNOWN = UNKNOWN
|
||||
|
||||
lib.prefix = "ElvUIPluginVC"
|
||||
lib.plugins = {}
|
||||
lib.groupSize = 0
|
||||
lib.index = 0
|
||||
|
||||
local MSG_OUTDATED = "Your version of %s %s is out of date (latest is version %s). You can download the latest version from http://www.tukui.org"
|
||||
local HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - Plugins Loaded (Green means you have current version, Red means out of date)"
|
||||
local INFO_BY = "by"
|
||||
local INFO_VERSION = "Version:"
|
||||
local INFO_NEW = "Newest:"
|
||||
local LIBRARY = "Library"
|
||||
|
||||
local locale = GetLocale()
|
||||
if locale == "deDE" then
|
||||
MSG_OUTDATED = "Deine Version von %s %s ist veraltet (akutelle Version ist %s). Du kannst die aktuelle Version von http://www.tukui.org herunterrladen."
|
||||
HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - Plugins geladen (Grün bedeutet du hast die aktuelle Version, Rot bedeutet es ist veraltet)"
|
||||
INFO_BY = "von"
|
||||
INFO_VERSION = "Version:"
|
||||
INFO_NEW = "Neuste:"
|
||||
LIBRARY = "Bibliothek"
|
||||
elseif locale == "ruRU" then
|
||||
MSG_OUTDATED = "Ваша версия %s %s устарела (последняя версия %s). Вы можете скачать последнюю версию на http://www.tukui.org"
|
||||
HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - загруженные плагины (зеленый означает, что у вас последняя версия, красный - устаревшая)"
|
||||
INFO_BY = "от"
|
||||
INFO_VERSION = "Версия:"
|
||||
INFO_NEW = "Последняя:"
|
||||
LIBRARY = "Библиотека"
|
||||
elseif locale == "zhCN" then
|
||||
MSG_OUTDATED = "你的 %s %s 版本已经过期 (最新版本是 %s)。你可以从 http://www.tukui.org 下载最新版本"
|
||||
HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - 载入的插件 (绿色表示拥有当前版本, 红色表示版本已经过期)"
|
||||
INFO_BY = "作者"
|
||||
INFO_VERSION = "版本:"
|
||||
INFO_NEW = "最新:"
|
||||
LIBRARY = "库"
|
||||
elseif locale == "zhTW" then
|
||||
MSG_OUTDATED = "你的 %s %s 版本已經過期 (最新版本為 %s)。你可以透過 http://www.tukui.org 下載最新的版本"
|
||||
HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - 載入的插件 (綠色表示擁有當前版本, 紅色表示版本已經過期)"
|
||||
INFO_BY = "作者"
|
||||
INFO_VERSION = "版本:"
|
||||
INFO_NEW = "最新:"
|
||||
LIBRARY = "庫"
|
||||
end
|
||||
|
||||
local E, L
|
||||
local function checkElvUI()
|
||||
if not E then
|
||||
if ElvUI then
|
||||
E = ElvUI[1]
|
||||
L = ElvUI[2]
|
||||
end
|
||||
|
||||
assert(E, "ElvUI not found.")
|
||||
end
|
||||
end
|
||||
|
||||
function lib:RegisterPlugin(name, callback, isLib, libVersion)
|
||||
checkElvUI()
|
||||
|
||||
local plugin = {
|
||||
name = name,
|
||||
callback = callback,
|
||||
title = GetAddOnMetadata(name, "Title"),
|
||||
author = GetAddOnMetadata(name, "Author")
|
||||
}
|
||||
|
||||
if isLib then
|
||||
plugin.isLib = true
|
||||
plugin.version = libVersion or 1
|
||||
else
|
||||
plugin.version = (name == MAJOR and MINOR) or GetAddOnMetadata(name, "Version") or UNKNOWN
|
||||
end
|
||||
|
||||
lib.plugins[name] = plugin
|
||||
|
||||
if not lib.registeredPrefix then
|
||||
C_ChatInfo_RegisterAddonMessagePrefix(lib.prefix)
|
||||
lib.VCFrame:RegisterEvent("CHAT_MSG_ADDON")
|
||||
lib.VCFrame:RegisterEvent("GROUP_ROSTER_UPDATE")
|
||||
lib.VCFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
lib.registeredPrefix = true
|
||||
end
|
||||
|
||||
local loaded = IsAddOnLoaded("ElvUI_OptionsUI")
|
||||
if not loaded then
|
||||
lib.CFFrame:RegisterEvent("ADDON_LOADED")
|
||||
elseif loaded then
|
||||
if name ~= MAJOR then
|
||||
E.Options.args.plugins.args.plugins.name = lib:GeneratePluginList()
|
||||
end
|
||||
|
||||
if callback then
|
||||
callback()
|
||||
end
|
||||
end
|
||||
|
||||
return plugin
|
||||
end
|
||||
|
||||
local function SendVersionCheckMessage()
|
||||
lib:SendPluginVersionCheck(lib:GenerateVersionCheckMessage())
|
||||
end
|
||||
|
||||
function lib:DelayedSendVersionCheck(delay)
|
||||
if not E.SendPluginVersionCheck then
|
||||
E.SendPluginVersionCheck = SendVersionCheckMessage
|
||||
end
|
||||
|
||||
if not lib.SendMessageWaiting then
|
||||
lib.SendMessageWaiting = E:Delay(delay or 10, E.SendPluginVersionCheck)
|
||||
end
|
||||
end
|
||||
|
||||
function lib:OptionsUILoaded(_, addon)
|
||||
if addon == "ElvUI_OptionsUI" then
|
||||
lib:GetPluginOptions()
|
||||
|
||||
for _, plugin in pairs(lib.plugins) do
|
||||
if plugin.callback then
|
||||
plugin.callback()
|
||||
end
|
||||
end
|
||||
|
||||
lib.CFFrame:UnregisterEvent("ADDON_LOADED")
|
||||
end
|
||||
end
|
||||
|
||||
function lib:GenerateVersionCheckMessage()
|
||||
local list = ""
|
||||
for _, plugin in pairs(lib.plugins) do
|
||||
if plugin.name ~= MAJOR then
|
||||
list = list .. plugin.name .. "=" .. plugin.version .. ";"
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function lib:GetPluginOptions()
|
||||
E.Options.args.plugins = {
|
||||
order = 3,
|
||||
type = "group",
|
||||
name = L["Plugins"],
|
||||
inline = false,
|
||||
args = {
|
||||
pluginheader = E.Libs.ACH:Header(format(HDR_INFORMATION, MINOR), 1),
|
||||
plugins = {
|
||||
order = 2,
|
||||
type = "description",
|
||||
name = lib:GeneratePluginList()
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
do -- this will handle `8.1.5.0015` into `8.150015` etc
|
||||
local verStrip = function(a, b) return a..gsub(b,'%.', '') end
|
||||
function lib:StripVersion(version)
|
||||
local ver = gsub(version, '(%d-%.)([%d%.]+)', verStrip)
|
||||
return tonumber(ver)
|
||||
end
|
||||
end
|
||||
|
||||
function lib:VersionCheck(event, prefix, message, _, sender)
|
||||
if (event == "CHAT_MSG_ADDON" and prefix == lib.prefix) and (sender and message and not strmatch(message, "^%s-$")) then
|
||||
if not lib.myName then lib.myName = format('%s-%s', E.myname, E:ShortenRealm(E.myrealm)) end
|
||||
if sender == lib.myName then return end
|
||||
|
||||
if not E.pluginRecievedOutOfDateMessage then
|
||||
for name, version in gmatch(message, "([^=]+)=([%d%p]+);") do
|
||||
local plugin = (version and name) and lib.plugins[name]
|
||||
if plugin and plugin.version then
|
||||
local Pver, ver = lib:StripVersion(plugin.version), lib:StripVersion(version)
|
||||
if (ver and Pver) and (ver > Pver) then
|
||||
plugin.old, plugin.newversion = true, version
|
||||
E:Print(format(MSG_OUTDATED, plugin.title or plugin.name, plugin.version, plugin.newversion))
|
||||
E.pluginRecievedOutOfDateMessage = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif event == "GROUP_ROSTER_UPDATE" then
|
||||
local num = GetNumGroupMembers()
|
||||
if num ~= lib.groupSize then
|
||||
if num > 1 and num > lib.groupSize then
|
||||
lib:DelayedSendVersionCheck()
|
||||
end
|
||||
lib.groupSize = num
|
||||
end
|
||||
elseif event == "PLAYER_ENTERING_WORLD" then
|
||||
lib:DelayedSendVersionCheck()
|
||||
end
|
||||
end
|
||||
|
||||
function lib:GeneratePluginList()
|
||||
local list = ""
|
||||
for _, plugin in pairs(lib.plugins) do
|
||||
if plugin.name ~= MAJOR then
|
||||
local color = (plugin.old and E:RGBToHex(1, 0, 0)) or E:RGBToHex(0, 1, 0)
|
||||
list = list .. (plugin.title or plugin.name)
|
||||
if plugin.author then list = list .. " " .. INFO_BY .. " " .. plugin.author end
|
||||
list = list .. color .. (plugin.isLib and " " .. LIBRARY or " - " .. INFO_VERSION .. " " .. plugin.version)
|
||||
if plugin.old then list = list .. " (" .. INFO_NEW .. plugin.newversion .. ")" end
|
||||
list = list .. "|r\n"
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function lib:ClearSendMessageWait()
|
||||
lib.SendMessageWaiting = nil
|
||||
end
|
||||
|
||||
function lib:SendPluginVersionCheck(message)
|
||||
if (not message) or strmatch(message, "^%s-$") then
|
||||
lib.ClearSendMessageWait()
|
||||
return
|
||||
end
|
||||
|
||||
local ChatType
|
||||
if IsInRaid() then
|
||||
ChatType = (not IsInRaid(LE_PARTY_CATEGORY_HOME) and IsInRaid(LE_PARTY_CATEGORY_INSTANCE)) and "INSTANCE_CHAT" or "RAID"
|
||||
elseif IsInGroup() then
|
||||
ChatType = (not IsInGroup(LE_PARTY_CATEGORY_HOME) and IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) and "INSTANCE_CHAT" or "PARTY"
|
||||
elseif IsInGuild() then
|
||||
ChatType = "GUILD"
|
||||
end
|
||||
|
||||
if not ChatType then
|
||||
lib.ClearSendMessageWait()
|
||||
return
|
||||
end
|
||||
|
||||
local delay, maxChar, msgLength = 0, 250, strlen(message)
|
||||
if msgLength > maxChar then
|
||||
local splitMessage
|
||||
for _ = 1, ceil(msgLength / maxChar) do
|
||||
splitMessage = strmatch(strsub(message, 1, maxChar), ".+;")
|
||||
if splitMessage then -- incase the string is over 250 but doesnt contain `;`
|
||||
message = gsub(message, "^" .. E:EscapeString(splitMessage), "")
|
||||
E:Delay(delay, C_ChatInfo_SendAddonMessage, lib.prefix, splitMessage, ChatType)
|
||||
delay = delay + 1
|
||||
end
|
||||
end
|
||||
|
||||
E:Delay(delay, lib.ClearSendMessageWait)
|
||||
else
|
||||
C_ChatInfo_SendAddonMessage(lib.prefix, message, ChatType)
|
||||
lib.ClearSendMessageWait()
|
||||
end
|
||||
end
|
||||
|
||||
function lib.Initialized()
|
||||
if not lib.inits then return end
|
||||
|
||||
for _, initTbl in ipairs(lib.inits) do
|
||||
initTbl[2](initTbl[1])
|
||||
end
|
||||
|
||||
wipe(lib.inits)
|
||||
end
|
||||
|
||||
function lib:HookInitialize(tbl, func)
|
||||
if not (tbl and func) then return end
|
||||
|
||||
if type(func) == "string" then
|
||||
func = tbl[func]
|
||||
end
|
||||
|
||||
if not self.inits then
|
||||
self.inits = {}
|
||||
checkElvUI()
|
||||
hooksecurefunc(E, "Initialize", self.Initialized)
|
||||
end
|
||||
|
||||
tinsert(lib.inits, { tbl, func })
|
||||
end
|
||||
|
||||
lib.VCFrame = CreateFrame("Frame")
|
||||
lib.VCFrame:SetScript("OnEvent", lib.VersionCheck)
|
||||
|
||||
lib.CFFrame = CreateFrame("Frame")
|
||||
lib.CFFrame:SetScript("OnEvent", lib.OptionsUILoaded)
|
||||
@@ -0,0 +1,202 @@
|
||||
--[[
|
||||
Copyright 2013-2018 João Cardoso
|
||||
CustomSearch is distributed under the terms of the GNU General Public License (Version 3).
|
||||
As a special exception, the copyright holders of this library give you permission to embed it
|
||||
with independent modules to produce an addon, regardless of the license terms of these
|
||||
independent modules, and to copy and distribute the resulting software under terms of your
|
||||
choice, provided that you also meet, for each embedded independent module, the terms and
|
||||
conditions of the license of that module. Permission is not granted to modify this library.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the library. If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
This file is part of CustomSearch.
|
||||
--]]
|
||||
|
||||
local Lib = LibStub:NewLibrary('CustomSearch-1.0', 9)
|
||||
if not Lib then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
--[[ Parsing ]]--
|
||||
|
||||
function Lib:Matches(object, search, filters)
|
||||
if object then
|
||||
self.filters = filters
|
||||
self.object = object
|
||||
|
||||
return self:MatchAll(search or '')
|
||||
end
|
||||
end
|
||||
|
||||
function Lib:MatchAll(search)
|
||||
for phrase in self:Clean(search):gmatch('[^&]+') do
|
||||
if not self:MatchAny(phrase) then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function Lib:MatchAny(search)
|
||||
for phrase in search:gmatch('[^|]+') do
|
||||
if self:Match(phrase) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Lib:Match(search)
|
||||
local tag, rest = search:match('^%s*(%S+):(.*)$')
|
||||
if tag then
|
||||
tag = '^' .. tag
|
||||
search = rest
|
||||
end
|
||||
|
||||
local words = search:gmatch('%S+')
|
||||
local failed
|
||||
|
||||
for word in words do
|
||||
if word == self.OR then
|
||||
if failed then
|
||||
failed = false
|
||||
else
|
||||
break
|
||||
end
|
||||
|
||||
else
|
||||
local negate, rest = word:match('^([!~]=*)(.*)$')
|
||||
if negate or word == self.NOT_MATCH then
|
||||
word = rest and rest ~= '' and rest or words() or ''
|
||||
negate = -1
|
||||
else
|
||||
negate = 1
|
||||
end
|
||||
|
||||
local operator, rest = word:match('^(=*[<>]=*)(.*)$')
|
||||
if operator then
|
||||
word = rest ~= '' and rest or words()
|
||||
end
|
||||
|
||||
local result = self:Filter(tag, operator, word) and 1 or -1
|
||||
if result * negate ~= 1 then
|
||||
failed = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return not failed
|
||||
end
|
||||
|
||||
|
||||
--[[ Filtering ]]--
|
||||
|
||||
function Lib:Filter(tag, operator, search)
|
||||
if not search then
|
||||
return true
|
||||
end
|
||||
|
||||
if tag then
|
||||
for _, filter in pairs(self.filters) do
|
||||
for _, value in pairs(filter.tags or {}) do
|
||||
if value:find(tag) then
|
||||
return self:UseFilter(filter, operator, search)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
for _, filter in pairs(self.filters) do
|
||||
if not filter.onlyTags and self:UseFilter(filter, operator, search) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Lib:UseFilter(filter, operator, search)
|
||||
local data = {filter:canSearch(operator, search, self.object)}
|
||||
if data[1] then
|
||||
return filter:match(self.object, operator, unpack(data))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[ Utilities ]]--
|
||||
|
||||
function Lib:Find(search, ...)
|
||||
for i = 1, select('#', ...) do
|
||||
local text = select(i, ...)
|
||||
if text and self:Clean(text):find(search) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Lib:Clean(string)
|
||||
string = string:lower()
|
||||
string = string:gsub('[%(%)%.%%%+%-%*%?%[%]%^%$]', function(c) return '%'..c end)
|
||||
|
||||
for accent, char in pairs(self.ACCENTS) do
|
||||
string = string:gsub(accent, char)
|
||||
end
|
||||
|
||||
return string
|
||||
end
|
||||
|
||||
function Lib:Compare(op, a, b)
|
||||
if op then
|
||||
if op:find('<') then
|
||||
if op:find('=') then
|
||||
return a <= b
|
||||
end
|
||||
|
||||
return a < b
|
||||
end
|
||||
|
||||
if op:find('>')then
|
||||
if op:find('=') then
|
||||
return a >= b
|
||||
end
|
||||
|
||||
return a > b
|
||||
end
|
||||
end
|
||||
|
||||
return a == b
|
||||
end
|
||||
|
||||
|
||||
--[[ Localization ]]--
|
||||
|
||||
do
|
||||
local no = {enUS = 'Not', frFR = 'Pas', deDE = 'Nicht'}
|
||||
local accents = {
|
||||
a = {'à','â','ã','å'},
|
||||
e = {'è','é','ê','ê','ë'},
|
||||
i = {'ì', 'í', 'î', 'ï'},
|
||||
o = {'ó','ò','ô','õ'},
|
||||
u = {'ù', 'ú', 'û', 'ü'},
|
||||
c = {'ç'}, n = {'ñ'}
|
||||
}
|
||||
|
||||
Lib.ACCENTS = {}
|
||||
for char, accents in pairs(accents) do
|
||||
for _, accent in ipairs(accents) do
|
||||
Lib.ACCENTS[accent] = char
|
||||
end
|
||||
end
|
||||
|
||||
Lib.OR = Lib:Clean(JUST_OR)
|
||||
Lib.NOT = no[GetLocale()] or NO
|
||||
Lib.NOT_MATCH = Lib:Clean(Lib.NOT)
|
||||
setmetatable(Lib, {__call = Lib.Matches})
|
||||
end
|
||||
|
||||
return Lib
|
||||
363
Libraries/LibItemSearch-1.2/LibItemSearch-1.2.lua
Normal file
363
Libraries/LibItemSearch-1.2/LibItemSearch-1.2.lua
Normal file
@@ -0,0 +1,363 @@
|
||||
--[[
|
||||
ItemSearch
|
||||
An item text search engine of some sort
|
||||
--]]
|
||||
|
||||
local Search = LibStub('CustomSearch-1.0')
|
||||
local Unfit = LibStub('Unfit-1.0')
|
||||
local Lib = LibStub:NewLibrary('LibItemSearch-1.2-ElvUI', 9)
|
||||
if Lib then
|
||||
Lib.Scanner = LibItemSearchTooltipScanner or CreateFrame('GameTooltip', 'LibItemSearchTooltipScanner', UIParent, 'GameTooltipTemplate')
|
||||
Lib.Filters = {}
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
--[[ User API ]]--
|
||||
|
||||
function Lib:Matches(link, search)
|
||||
return Search(link, search, self.Filters)
|
||||
end
|
||||
|
||||
function Lib:Tooltip(link, search)
|
||||
return link and self.Filters.tip:match(link, nil, search)
|
||||
end
|
||||
|
||||
function Lib:TooltipPhrase(link, search)
|
||||
return link and self.Filters.tipPhrases:match(link, nil, search)
|
||||
end
|
||||
|
||||
function Lib:InSet(link, search)
|
||||
if IsEquippableItem(link) then
|
||||
local id = tonumber(link:match('item:(%-?%d+)'))
|
||||
return self:BelongsToSet(id, (search or ''):lower())
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
--[[ Internal API ]]--
|
||||
|
||||
function Lib:TooltipLine(link, line)
|
||||
self.Scanner:SetOwner(UIParent, 'ANCHOR_NONE')
|
||||
self.Scanner:SetHyperlink(link)
|
||||
return _G[self.Scanner:GetName() .. 'TextLeft' .. line]:GetText()
|
||||
end
|
||||
|
||||
|
||||
if IsAddOnLoaded('ItemRack') then
|
||||
local sameID = ItemRack.SameID
|
||||
|
||||
function Lib:BelongsToSet(id, search)
|
||||
for name, set in pairs(ItemRackUser.Sets) do
|
||||
if name:sub(1,1) ~= '' and Search:Find(search, name) then
|
||||
for _, item in pairs(set.equip) do
|
||||
if sameID(id, item) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
elseif IsAddOnLoaded('Wardrobe') then
|
||||
function Lib:BelongsToSet(id, search)
|
||||
for _, outfit in ipairs(Wardrobe.CurrentConfig.Outfit) do
|
||||
local name = outfit.OutfitName
|
||||
if Search:Find(search, name) then
|
||||
for _, item in pairs(outfit.Item) do
|
||||
if item.IsSlotUsed == 1 and item.ItemID == id then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
elseif C_EquipmentSet then
|
||||
function Lib:BelongsToSet(id, search)
|
||||
for i, setID in pairs(C_EquipmentSet.GetEquipmentSetIDs()) do
|
||||
local name = C_EquipmentSet.GetEquipmentSetInfo(setID)
|
||||
if Search:Find(search, name) then
|
||||
local items = C_EquipmentSet.GetItemIDs(setID)
|
||||
for _, item in pairs(items) do
|
||||
if id == item then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
function Lib:BelongsToSet() end
|
||||
end
|
||||
|
||||
|
||||
--[[ General Filters]]--
|
||||
|
||||
Lib.Filters.name = {
|
||||
tags = {'n', 'name'},
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and search
|
||||
end,
|
||||
|
||||
match = function(self, item, _, search)
|
||||
-- Modified: C_Item.GetItemNameByID returns nil for M+ keystones, a fallback is needed
|
||||
return Search:Find(search, C_Item.GetItemNameByID(item) or item:match('%[(.-)%]'))
|
||||
end
|
||||
}
|
||||
|
||||
Lib.Filters.type = {
|
||||
tags = {'t', 'type', 's', 'slot'},
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and search
|
||||
end,
|
||||
|
||||
match = function(self, item, _, search)
|
||||
local type, subType, _, equipSlot = select(6, GetItemInfo(item))
|
||||
return Search:Find(search, type, subType, _G[equipSlot])
|
||||
end
|
||||
}
|
||||
|
||||
Lib.Filters.level = {
|
||||
tags = {'l', 'level', 'lvl', 'ilvl'},
|
||||
|
||||
canSearch = function(self, _, search)
|
||||
return tonumber(search)
|
||||
end,
|
||||
|
||||
match = function(self, link, operator, num)
|
||||
local lvl = select(4, GetItemInfo(link))
|
||||
if lvl then
|
||||
return Search:Compare(operator, lvl, num)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
Lib.Filters.requiredlevel = {
|
||||
tags = {'r', 'req', 'rl', 'reql', 'reqlvl'},
|
||||
|
||||
canSearch = function(self, _, search)
|
||||
return tonumber(search)
|
||||
end,
|
||||
|
||||
match = function(self, link, operator, num)
|
||||
local lvl = select(5, GetItemInfo(link))
|
||||
if lvl then
|
||||
return Search:Compare(operator, lvl, num)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
Lib.Filters.sets = {
|
||||
tags = {'s', 'set'},
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and search
|
||||
end,
|
||||
|
||||
match = function(self, link, _, search)
|
||||
return Lib:InSet(link, search)
|
||||
end,
|
||||
}
|
||||
|
||||
Lib.Filters.quality = {
|
||||
tags = {'q', 'quality'},
|
||||
keywords = {},
|
||||
|
||||
canSearch = function(self, _, search)
|
||||
for quality, name in pairs(self.keywords) do
|
||||
if name:find(search) then
|
||||
return quality
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
match = function(self, link, operator, num)
|
||||
local quality = link:sub(1, 9) == 'battlepet' and tonumber(link:match('%d+:%d+:(%d+)')) or C_Item.GetItemQualityByID(link)
|
||||
return Search:Compare(operator, quality, num)
|
||||
end,
|
||||
}
|
||||
|
||||
for i = 0, #ITEM_QUALITY_COLORS do
|
||||
Lib.Filters.quality.keywords[i] = _G['ITEM_QUALITY' .. i .. '_DESC']:lower()
|
||||
end
|
||||
|
||||
|
||||
--[[ Classic Keywords ]]--
|
||||
|
||||
Lib.Filters.items = {
|
||||
keyword = ITEMS:lower(),
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and self.keyword:find(search)
|
||||
end,
|
||||
|
||||
match = function(self, link)
|
||||
return true
|
||||
end
|
||||
}
|
||||
|
||||
Lib.Filters.usable = {
|
||||
keyword = USABLE_ITEMS:lower(),
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and self.keyword:find(search)
|
||||
end,
|
||||
|
||||
match = function(self, link)
|
||||
if not Unfit:IsItemUnusable(link) then
|
||||
local lvl = select(5, GetItemInfo(link))
|
||||
return lvl and (lvl == 0 or lvl > UnitLevel('player'))
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
--[[ Retail Keywords ]]--
|
||||
|
||||
if C_ArtifactUI then
|
||||
Lib.Filters.artifact = {
|
||||
keyword1 = ITEM_QUALITY6_DESC:lower(),
|
||||
keyword2 = RELICSLOT:lower(),
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and self.keyword1:find(search) or self.keyword2:find(search)
|
||||
end,
|
||||
|
||||
match = function(self, link)
|
||||
local id = link:match('item:(%d+)')
|
||||
return id and C_ArtifactUI.GetRelicInfoByItemID(id)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
if C_AzeriteItem then
|
||||
Lib.Filters.azerite = {
|
||||
keyword = C_CurrencyInfo.GetBasicCurrencyInfo(C_CurrencyInfo.GetAzeriteCurrencyID()).name:lower(),
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and self.keyword:find(search)
|
||||
end,
|
||||
|
||||
match = function(self, link)
|
||||
return C_AzeriteItem.IsAzeriteItemByID(link) or C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItemByID(link)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
Lib.Filters.keystone = {
|
||||
keyword1 = CHALLENGES:lower(), --English: "mythic keystone" (localized)
|
||||
keyword2 = "mythic keystone", --unlocalized
|
||||
|
||||
canSearch = function(self, operator, search)
|
||||
return not operator and self.keyword1:find(search) or self.keyword2:find(search)
|
||||
end,
|
||||
|
||||
match = function(self, link)
|
||||
local id = link:match('item:(%d+)')
|
||||
return id and (select(12, GetItemInfo(id)) == 5 and select(13, GetItemInfo(id)) == 1) --itemClassID 5 and itemSubClassID 1 which translates to "Keystone"
|
||||
end
|
||||
}
|
||||
|
||||
--[[ Tooltips ]]--
|
||||
|
||||
Lib.Filters.tip = {
|
||||
tags = {'tt', 'tip', 'tooltip'},
|
||||
onlyTags = true,
|
||||
|
||||
canSearch = function(self, _, search)
|
||||
return search
|
||||
end,
|
||||
|
||||
match = function(self, link, _, search)
|
||||
if link:find('item:') then
|
||||
Lib.Scanner:SetOwner(UIParent, 'ANCHOR_NONE')
|
||||
Lib.Scanner:SetHyperlink(link)
|
||||
|
||||
for i = 1, Lib.Scanner:NumLines() do
|
||||
if Search:Find(search, _G[Lib.Scanner:GetName() .. 'TextLeft' .. i]:GetText()) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
local escapes = {
|
||||
["|c%x%x%x%x%x%x%x%x"] = "", -- color start
|
||||
["|r"] = "", -- color end
|
||||
}
|
||||
local function CleanString(str)
|
||||
for k, v in pairs(escapes) do
|
||||
str = str:gsub(k, v)
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
Lib.Filters.tipPhrases = {
|
||||
canSearch = function(self, _, search)
|
||||
if #search >= 3 then
|
||||
for key, query in pairs(self.keywords) do
|
||||
if key:find(search) then
|
||||
return query
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
match = function(self, link, _, search)
|
||||
local id = link:match('item:(%d+)')
|
||||
if not id then
|
||||
return
|
||||
end
|
||||
|
||||
local cached = self.cache[search][id]
|
||||
if cached ~= nil then
|
||||
return cached
|
||||
end
|
||||
|
||||
Lib.Scanner:SetOwner(UIParent, 'ANCHOR_NONE')
|
||||
Lib.Scanner:SetHyperlink(link)
|
||||
|
||||
local matches = false
|
||||
for i = 1, Lib.Scanner:NumLines() do
|
||||
local text = _G[Lib.Scanner:GetName() .. 'TextLeft' .. i]:GetText()
|
||||
text = CleanString(text)
|
||||
if search == text then
|
||||
matches = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
self.cache[search][id] = matches
|
||||
return matches
|
||||
end,
|
||||
|
||||
cache = setmetatable({}, {__index = function(t, k) local v = {} t[k] = v return v end}),
|
||||
keywords = {
|
||||
[ITEM_SOULBOUND:lower()] = ITEM_BIND_ON_PICKUP,
|
||||
[QUESTS_LABEL:lower()] = ITEM_BIND_QUEST,
|
||||
[GetItemClassInfo(LE_ITEM_CLASS_QUESTITEM):lower()] = ITEM_BIND_QUEST,
|
||||
[PROFESSIONS_USED_IN_COOKING:lower()] = PROFESSIONS_USED_IN_COOKING,
|
||||
[TOY:lower()] = TOY,
|
||||
|
||||
[FOLLOWERLIST_LABEL_CHAMPIONS:lower()] = Lib:TooltipLine('item:147556', 2),
|
||||
[GARRISON_FOLLOWERS:lower()] = Lib:TooltipLine('item:147556', 2),
|
||||
|
||||
['soulbound'] = ITEM_BIND_ON_PICKUP,
|
||||
['bound'] = ITEM_BIND_ON_PICKUP,
|
||||
['bop'] = ITEM_BIND_ON_PICKUP,
|
||||
['boe'] = ITEM_BIND_ON_EQUIP,
|
||||
['bou'] = ITEM_BIND_ON_USE,
|
||||
['boa'] = ITEM_BIND_TO_BNETACCOUNT,
|
||||
['quests'] = ITEM_BIND_QUEST,
|
||||
['crafting reagent'] = PROFESSIONS_USED_IN_COOKING,
|
||||
['toy'] = TOY,
|
||||
['champions'] = Lib:TooltipLine('item:147556', 2),
|
||||
['followers'] = Lib:TooltipLine('item:147556', 2),
|
||||
}
|
||||
}
|
||||
6
Libraries/LibItemSearch-1.2/LibItemSearch-1.2.xml
Normal file
6
Libraries/LibItemSearch-1.2/LibItemSearch-1.2.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<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="CustomSearch-1.0\CustomSearch-1.0.lua"/>
|
||||
<Script file="Unfit-1.0\Unfit-1.0.lua"/>
|
||||
<Script file="LibItemSearch-1.2.lua"/>
|
||||
</Ui>
|
||||
2
Libraries/LibItemSearch-1.2/Unfit-1.0/License.url
Normal file
2
Libraries/LibItemSearch-1.2/Unfit-1.0/License.url
Normal file
@@ -0,0 +1,2 @@
|
||||
[InternetShortcut]
|
||||
URL=http://www.gnu.org/licenses/gpl-3.0.txt
|
||||
124
Libraries/LibItemSearch-1.2/Unfit-1.0/Unfit-1.0.lua
Normal file
124
Libraries/LibItemSearch-1.2/Unfit-1.0/Unfit-1.0.lua
Normal file
@@ -0,0 +1,124 @@
|
||||
--[[
|
||||
Copyright 2011-2018 João Cardoso
|
||||
Unfit is distributed under the terms of the GNU General Public License (Version 3).
|
||||
As a special exception, the copyright holders of this library give you permission to embed it
|
||||
with independent modules to produce an addon, regardless of the license terms of these
|
||||
independent modules, and to copy and distribute the resulting software under terms of your
|
||||
choice, provided that you also meet, for each embedded independent module, the terms and
|
||||
conditions of the license of that module. Permission is not granted to modify this library.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
This file is part of Unfit.
|
||||
--]]
|
||||
|
||||
local Lib = LibStub:NewLibrary('Unfit-1.0', 9)
|
||||
if not Lib then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
--[[ Data ]]--
|
||||
|
||||
do
|
||||
local _, Class = UnitClass('player')
|
||||
local Unusable
|
||||
|
||||
if Class == 'DEATHKNIGHT' then
|
||||
Unusable = { -- weapon, armor, dual-wield
|
||||
{LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_STAFF,LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_DAGGER, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND},
|
||||
{LE_ITEM_ARMOR_SHIELD}
|
||||
}
|
||||
elseif Class == 'DEMONHUNTER' then
|
||||
Unusable = {
|
||||
{LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE1H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_STAFF, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND},
|
||||
{LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}
|
||||
}
|
||||
elseif Class == 'DRUID' then
|
||||
Unusable = {
|
||||
{LE_ITEM_WEAPON_AXE1H, LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_SWORD1H, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND},
|
||||
{LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD},
|
||||
true
|
||||
}
|
||||
elseif Class == 'HUNTER' then
|
||||
Unusable = {
|
||||
{LE_ITEM_WEAPON_MACE1H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_WAND},
|
||||
{LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}
|
||||
}
|
||||
elseif Class == 'MAGE' then
|
||||
Unusable = {
|
||||
{LE_ITEM_WEAPON_AXE1H, LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE1H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW},
|
||||
{LE_ITEM_ARMOR_LEATHER, LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD},
|
||||
true
|
||||
}
|
||||
elseif Class == 'MONK' then
|
||||
Unusable = {
|
||||
{LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_DAGGER, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND},
|
||||
{LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}
|
||||
}
|
||||
elseif Class == 'PALADIN' then
|
||||
Unusable = {
|
||||
{LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_STAFF, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_DAGGER, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND},
|
||||
{},
|
||||
true
|
||||
}
|
||||
elseif Class == 'PRIEST' then
|
||||
Unusable = {
|
||||
{LE_ITEM_WEAPON_AXE1H, LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD1H, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW},
|
||||
{LE_ITEM_ARMOR_LEATHER, LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD},
|
||||
true
|
||||
}
|
||||
elseif Class == 'ROGUE' then
|
||||
Unusable = {
|
||||
{LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_STAFF, LE_ITEM_WEAPON_WAND},
|
||||
{LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}
|
||||
}
|
||||
elseif Class == 'SHAMAN' then
|
||||
Unusable = {
|
||||
{LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD1H, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND},
|
||||
{LE_ITEM_ARMOR_PLATE}
|
||||
}
|
||||
elseif Class == 'WARLOCK' then
|
||||
Unusable = {
|
||||
{LE_ITEM_WEAPON_AXE1H, LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE1H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW},
|
||||
{LE_ITEM_ARMOR_LEATHER, LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD},
|
||||
true
|
||||
}
|
||||
elseif Class == 'WARRIOR' then
|
||||
Unusable = {{LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_WAND}, {}}
|
||||
else
|
||||
Unusable = {{}, {}}
|
||||
end
|
||||
|
||||
|
||||
Lib.unusable = {}
|
||||
Lib.cannotDual = Unusable[3]
|
||||
|
||||
for i, class in ipairs({LE_ITEM_CLASS_WEAPON, LE_ITEM_CLASS_ARMOR}) do
|
||||
local list = {}
|
||||
for _, subclass in ipairs(Unusable[i]) do
|
||||
list[subclass] = true
|
||||
end
|
||||
|
||||
Lib.unusable[class] = list
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[ API ]]--
|
||||
|
||||
function Lib:IsItemUnusable(...)
|
||||
if ... then
|
||||
local slot, _,_, class, subclass = select(9, GetItemInfo(...))
|
||||
return Lib:IsClassUnusable(class, subclass, slot)
|
||||
end
|
||||
end
|
||||
|
||||
function Lib:IsClassUnusable(class, subclass, slot)
|
||||
if class and subclass and Lib.unusable[class] then
|
||||
return slot ~= '' and Lib.unusable[class][subclass] or slot == 'INVTYPE_WEAPONOFFHAND' and Lib.cannotDual
|
||||
end
|
||||
end
|
||||
300
Libraries/LibSharedMedia-3.0/LibSharedMedia-3.0.lua
Normal file
300
Libraries/LibSharedMedia-3.0/LibSharedMedia-3.0.lua
Normal file
@@ -0,0 +1,300 @@
|
||||
--[[
|
||||
Name: LibSharedMedia-3.0
|
||||
Revision: $Revision: 113 $
|
||||
Author: Elkano (elkano@gmx.de)
|
||||
Inspired By: SurfaceLib by Haste/Otravi (troeks@gmail.com)
|
||||
Website: http://www.wowace.com/projects/libsharedmedia-3-0/
|
||||
Description: Shared handling of media data (fonts, sounds, textures, ...) between addons.
|
||||
Dependencies: LibStub, CallbackHandler-1.0
|
||||
License: LGPL v2.1
|
||||
]]
|
||||
|
||||
local MAJOR, MINOR = "LibSharedMedia-3.0", 8020002 -- 8.2.0 v2 / increase manually on changes
|
||||
local lib = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not lib then return end
|
||||
|
||||
local _G = getfenv(0)
|
||||
|
||||
local pairs = _G.pairs
|
||||
local type = _G.type
|
||||
|
||||
local band = _G.bit.band
|
||||
local table_sort = _G.table.sort
|
||||
|
||||
local RESTRICTED_FILE_ACCESS = not not C_RaidLocks -- starting with 8.2, some rules for file access have changed; classic still uses the old way
|
||||
|
||||
local locale = GetLocale()
|
||||
local locale_is_western
|
||||
local LOCALE_MASK = 0
|
||||
lib.LOCALE_BIT_koKR = 1
|
||||
lib.LOCALE_BIT_ruRU = 2
|
||||
lib.LOCALE_BIT_zhCN = 4
|
||||
lib.LOCALE_BIT_zhTW = 8
|
||||
lib.LOCALE_BIT_western = 128
|
||||
|
||||
local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0")
|
||||
|
||||
lib.callbacks = lib.callbacks or CallbackHandler:New(lib)
|
||||
|
||||
lib.DefaultMedia = lib.DefaultMedia or {}
|
||||
lib.MediaList = lib.MediaList or {}
|
||||
lib.MediaTable = lib.MediaTable or {}
|
||||
lib.MediaType = lib.MediaType or {}
|
||||
lib.OverrideMedia = lib.OverrideMedia or {}
|
||||
|
||||
local defaultMedia = lib.DefaultMedia
|
||||
local mediaList = lib.MediaList
|
||||
local mediaTable = lib.MediaTable
|
||||
local overrideMedia = lib.OverrideMedia
|
||||
|
||||
|
||||
-- create mediatype constants
|
||||
lib.MediaType.BACKGROUND = "background" -- background textures
|
||||
lib.MediaType.BORDER = "border" -- border textures
|
||||
lib.MediaType.FONT = "font" -- fonts
|
||||
lib.MediaType.STATUSBAR = "statusbar" -- statusbar textures
|
||||
lib.MediaType.SOUND = "sound" -- sound files
|
||||
|
||||
-- populate lib with default Blizzard data
|
||||
-- BACKGROUND
|
||||
if not lib.MediaTable.background then lib.MediaTable.background = {} end
|
||||
lib.MediaTable.background["None"] = [[]]
|
||||
lib.MediaTable.background["Blizzard Collections Background"] = [[Interface\Collections\CollectionsBackgroundTile]]
|
||||
lib.MediaTable.background["Blizzard Dialog Background"] = [[Interface\DialogFrame\UI-DialogBox-Background]]
|
||||
lib.MediaTable.background["Blizzard Dialog Background Dark"] = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]]
|
||||
lib.MediaTable.background["Blizzard Dialog Background Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Background]]
|
||||
lib.MediaTable.background["Blizzard Garrison Background"] = [[Interface\Garrison\GarrisonUIBackground]]
|
||||
lib.MediaTable.background["Blizzard Garrison Background 2"] = [[Interface\Garrison\GarrisonUIBackground2]]
|
||||
lib.MediaTable.background["Blizzard Garrison Background 3"] = [[Interface\Garrison\GarrisonMissionUIInfoBoxBackgroundTile]]
|
||||
lib.MediaTable.background["Blizzard Low Health"] = [[Interface\FullScreenTextures\LowHealth]]
|
||||
lib.MediaTable.background["Blizzard Marble"] = [[Interface\FrameGeneral\UI-Background-Marble]]
|
||||
lib.MediaTable.background["Blizzard Out of Control"] = [[Interface\FullScreenTextures\OutOfControl]]
|
||||
lib.MediaTable.background["Blizzard Parchment"] = [[Interface\AchievementFrame\UI-Achievement-Parchment-Horizontal]]
|
||||
lib.MediaTable.background["Blizzard Parchment 2"] = [[Interface\AchievementFrame\UI-GuildAchievement-Parchment-Horizontal]]
|
||||
lib.MediaTable.background["Blizzard Rock"] = [[Interface\FrameGeneral\UI-Background-Rock]]
|
||||
lib.MediaTable.background["Blizzard Tabard Background"] = [[Interface\TabardFrame\TabardFrameBackground]]
|
||||
lib.MediaTable.background["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Background]]
|
||||
lib.MediaTable.background["Solid"] = [[Interface\Buttons\WHITE8X8]]
|
||||
lib.DefaultMedia.background = "None"
|
||||
|
||||
-- BORDER
|
||||
if not lib.MediaTable.border then lib.MediaTable.border = {} end
|
||||
lib.MediaTable.border["None"] = [[]]
|
||||
lib.MediaTable.border["Blizzard Achievement Wood"] = [[Interface\AchievementFrame\UI-Achievement-WoodBorder]]
|
||||
lib.MediaTable.border["Blizzard Chat Bubble"] = [[Interface\Tooltips\ChatBubble-Backdrop]]
|
||||
lib.MediaTable.border["Blizzard Dialog"] = [[Interface\DialogFrame\UI-DialogBox-Border]]
|
||||
lib.MediaTable.border["Blizzard Dialog Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Border]]
|
||||
lib.MediaTable.border["Blizzard Party"] = [[Interface\CHARACTERFRAME\UI-Party-Border]]
|
||||
lib.MediaTable.border["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Border]]
|
||||
lib.DefaultMedia.border = "None"
|
||||
|
||||
-- FONT
|
||||
if not lib.MediaTable.font then lib.MediaTable.font = {} end
|
||||
local SML_MT_font = lib.MediaTable.font
|
||||
--[[
|
||||
All font files are currently in all clients, the following table depicts which font supports which charset as of 5.0.4
|
||||
Fonts were checked using langcover.pl from DejaVu fonts (http://sourceforge.net/projects/dejavu/) and FontForge (http://fontforge.org/)
|
||||
latin means check for: de, en, es, fr, it, pt
|
||||
|
||||
file name latin koKR ruRU zhCN zhTW
|
||||
2002.ttf 2002 X X X - -
|
||||
2002B.ttf 2002 Bold X X X - -
|
||||
ARHei.ttf AR CrystalzcuheiGBK Demibold X - X X X
|
||||
ARIALN.TTF Arial Narrow X - X - -
|
||||
ARKai_C.ttf AR ZhongkaiGBK Medium (Combat) X - X X X
|
||||
ARKai_T.ttf AR ZhongkaiGBK Medium X - X X X
|
||||
bHEI00M.ttf AR Heiti2 Medium B5 - - - - X
|
||||
bHEI01B.ttf AR Heiti2 Bold B5 - - - - X
|
||||
bKAI00M.ttf AR Kaiti Medium B5 - - - - X
|
||||
bLEI00D.ttf AR Leisu Demi B5 - - - - X
|
||||
FRIZQT__.TTF Friz Quadrata TT X - - - -
|
||||
FRIZQT___CYR.TTF FrizQuadrataCTT x - X - -
|
||||
K_Damage.TTF YDIWingsM - X X - -
|
||||
K_Pagetext.TTF MoK X X X - -
|
||||
MORPHEUS.TTF Morpheus X - - - -
|
||||
MORPHEUS_CYR.TTF Morpheus X - X - -
|
||||
NIM_____.ttf Nimrod MT X - X - -
|
||||
SKURRI.TTF Skurri X - - - -
|
||||
SKURRI_CYR.TTF Skurri X - X - -
|
||||
|
||||
WARNING: Although FRIZQT___CYR is available on western clients, it doesn't support special European characters e.g. é, ï, ö
|
||||
Due to this, we cannot use it as a replacement for FRIZQT__.TTF
|
||||
]]
|
||||
|
||||
if locale == "koKR" then
|
||||
LOCALE_MASK = lib.LOCALE_BIT_koKR
|
||||
--
|
||||
SML_MT_font["굵은 글꼴"] = [[Fonts\2002B.TTF]]
|
||||
SML_MT_font["기본 글꼴"] = [[Fonts\2002.TTF]]
|
||||
SML_MT_font["데미지 글꼴"] = [[Fonts\K_Damage.TTF]]
|
||||
SML_MT_font["퀘스트 글꼴"] = [[Fonts\K_Pagetext.TTF]]
|
||||
--
|
||||
lib.DefaultMedia["font"] = "기본 글꼴" -- someone from koKR please adjust if needed
|
||||
--
|
||||
elseif locale == "zhCN" then
|
||||
LOCALE_MASK = lib.LOCALE_BIT_zhCN
|
||||
--
|
||||
SML_MT_font["伤害数字"] = [[Fonts\ARKai_C.ttf]]
|
||||
SML_MT_font["默认"] = [[Fonts\ARKai_T.ttf]]
|
||||
SML_MT_font["聊天"] = [[Fonts\ARHei.ttf]]
|
||||
--
|
||||
lib.DefaultMedia["font"] = "默认" -- someone from zhCN please adjust if needed
|
||||
--
|
||||
elseif locale == "zhTW" then
|
||||
LOCALE_MASK = lib.LOCALE_BIT_zhTW
|
||||
--
|
||||
SML_MT_font["提示訊息"] = [[Fonts\bHEI00M.ttf]]
|
||||
SML_MT_font["聊天"] = [[Fonts\bHEI01B.ttf]]
|
||||
SML_MT_font["傷害數字"] = [[Fonts\bKAI00M.ttf]]
|
||||
SML_MT_font["預設"] = [[Fonts\bLEI00D.ttf]]
|
||||
--
|
||||
lib.DefaultMedia["font"] = "預設" -- someone from zhTW please adjust if needed
|
||||
|
||||
elseif locale == "ruRU" then
|
||||
LOCALE_MASK = lib.LOCALE_BIT_ruRU
|
||||
--
|
||||
SML_MT_font["2002"] = [[Fonts\2002.TTF]]
|
||||
SML_MT_font["2002 Bold"] = [[Fonts\2002B.TTF]]
|
||||
SML_MT_font["AR CrystalzcuheiGBK Demibold"] = [[Fonts\ARHei.TTF]]
|
||||
SML_MT_font["AR ZhongkaiGBK Medium (Combat)"] = [[Fonts\ARKai_C.TTF]]
|
||||
SML_MT_font["AR ZhongkaiGBK Medium"] = [[Fonts\ARKai_T.TTF]]
|
||||
SML_MT_font["Arial Narrow"] = [[Fonts\ARIALN.TTF]]
|
||||
SML_MT_font["Friz Quadrata TT"] = [[Fonts\FRIZQT___CYR.TTF]]
|
||||
SML_MT_font["MoK"] = [[Fonts\K_Pagetext.TTF]]
|
||||
SML_MT_font["Morpheus"] = [[Fonts\MORPHEUS_CYR.TTF]]
|
||||
SML_MT_font["Nimrod MT"] = [[Fonts\NIM_____.ttf]]
|
||||
SML_MT_font["Skurri"] = [[Fonts\SKURRI_CYR.TTF]]
|
||||
--
|
||||
lib.DefaultMedia.font = "Friz Quadrata TT"
|
||||
--
|
||||
else
|
||||
LOCALE_MASK = lib.LOCALE_BIT_western
|
||||
locale_is_western = true
|
||||
--
|
||||
SML_MT_font["2002"] = [[Fonts\2002.TTF]]
|
||||
SML_MT_font["2002 Bold"] = [[Fonts\2002B.TTF]]
|
||||
SML_MT_font["AR CrystalzcuheiGBK Demibold"] = [[Fonts\ARHei.TTF]]
|
||||
SML_MT_font["AR ZhongkaiGBK Medium (Combat)"] = [[Fonts\ARKai_C.TTF]]
|
||||
SML_MT_font["AR ZhongkaiGBK Medium"] = [[Fonts\ARKai_T.TTF]]
|
||||
SML_MT_font["Arial Narrow"] = [[Fonts\ARIALN.TTF]]
|
||||
SML_MT_font["Friz Quadrata TT"] = [[Fonts\FRIZQT__.TTF]]
|
||||
SML_MT_font["MoK"] = [[Fonts\K_Pagetext.TTF]]
|
||||
SML_MT_font["Morpheus"] = [[Fonts\MORPHEUS_CYR.TTF]]
|
||||
SML_MT_font["Nimrod MT"] = [[Fonts\NIM_____.ttf]]
|
||||
SML_MT_font["Skurri"] = [[Fonts\SKURRI_CYR.TTF]]
|
||||
--
|
||||
lib.DefaultMedia.font = "Friz Quadrata TT"
|
||||
--
|
||||
end
|
||||
|
||||
-- STATUSBAR
|
||||
if not lib.MediaTable.statusbar then lib.MediaTable.statusbar = {} end
|
||||
lib.MediaTable.statusbar["Blizzard"] = [[Interface\TargetingFrame\UI-StatusBar]]
|
||||
lib.MediaTable.statusbar["Blizzard Character Skills Bar"] = [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]]
|
||||
lib.MediaTable.statusbar["Blizzard Raid Bar"] = [[Interface\RaidFrame\Raid-Bar-Hp-Fill]]
|
||||
lib.MediaTable.statusbar["Solid"] = [[Interface\Buttons\WHITE8X8]]
|
||||
lib.DefaultMedia.statusbar = "Blizzard"
|
||||
|
||||
-- SOUND
|
||||
if not lib.MediaTable.sound then lib.MediaTable.sound = {} end
|
||||
lib.MediaTable.sound["None"] = RESTRICTED_FILE_ACCESS and 1 or [[Interface\Quiet.ogg]] -- Relies on the fact that PlaySound[File] doesn't error on these values.
|
||||
lib.DefaultMedia.sound = "None"
|
||||
|
||||
local function rebuildMediaList(mediatype)
|
||||
local mtable = mediaTable[mediatype]
|
||||
if not mtable then return end
|
||||
if not mediaList[mediatype] then mediaList[mediatype] = {} end
|
||||
local mlist = mediaList[mediatype]
|
||||
-- list can only get larger, so simply overwrite it
|
||||
local i = 0
|
||||
for k in pairs(mtable) do
|
||||
i = i + 1
|
||||
mlist[i] = k
|
||||
end
|
||||
table_sort(mlist)
|
||||
end
|
||||
|
||||
function lib:Register(mediatype, key, data, langmask)
|
||||
if type(mediatype) ~= "string" then
|
||||
error(MAJOR..":Register(mediatype, key, data, langmask) - mediatype must be string, got "..type(mediatype))
|
||||
end
|
||||
if type(key) ~= "string" then
|
||||
error(MAJOR..":Register(mediatype, key, data, langmask) - key must be string, got "..type(key))
|
||||
end
|
||||
mediatype = mediatype:lower()
|
||||
if mediatype == lib.MediaType.FONT and ((langmask and band(langmask, LOCALE_MASK) == 0) or not (langmask or locale_is_western)) then
|
||||
-- ignore fonts that aren't flagged as supporting local glyphs on non-western clients
|
||||
return false
|
||||
end
|
||||
if type(data) == "string" and (mediatype == lib.MediaType.BACKGROUND or mediatype == lib.MediaType.BORDER or mediatype == lib.MediaType.STATUSBAR or mediatype == lib.MediaType.SOUND) then
|
||||
local path = data:lower()
|
||||
if RESTRICTED_FILE_ACCESS and not path:find("^interface") then
|
||||
-- files accessed via path only allowed from interface folder
|
||||
return false
|
||||
end
|
||||
if mediatype == lib.MediaType.SOUND and not (path:find(".ogg", nil, true) or not path:find(".mp3", nil, true)) then
|
||||
-- Only ogg and mp3 are valid sounds.
|
||||
return false
|
||||
end
|
||||
end
|
||||
if not mediaTable[mediatype] then mediaTable[mediatype] = {} end
|
||||
local mtable = mediaTable[mediatype]
|
||||
if mtable[key] then return false end
|
||||
|
||||
mtable[key] = data
|
||||
rebuildMediaList(mediatype)
|
||||
self.callbacks:Fire("LibSharedMedia_Registered", mediatype, key)
|
||||
return true
|
||||
end
|
||||
|
||||
function lib:Fetch(mediatype, key, noDefault)
|
||||
local mtt = mediaTable[mediatype]
|
||||
local overridekey = overrideMedia[mediatype]
|
||||
local result = mtt and ((overridekey and mtt[overridekey] or mtt[key]) or (not noDefault and defaultMedia[mediatype] and mtt[defaultMedia[mediatype]])) or nil
|
||||
return result ~= "" and result or nil
|
||||
end
|
||||
|
||||
function lib:IsValid(mediatype, key)
|
||||
return mediaTable[mediatype] and (not key or mediaTable[mediatype][key]) and true or false
|
||||
end
|
||||
|
||||
function lib:HashTable(mediatype)
|
||||
return mediaTable[mediatype]
|
||||
end
|
||||
|
||||
function lib:List(mediatype)
|
||||
if not mediaTable[mediatype] then
|
||||
return nil
|
||||
end
|
||||
if not mediaList[mediatype] then
|
||||
rebuildMediaList(mediatype)
|
||||
end
|
||||
return mediaList[mediatype]
|
||||
end
|
||||
|
||||
function lib:GetGlobal(mediatype)
|
||||
return overrideMedia[mediatype]
|
||||
end
|
||||
|
||||
function lib:SetGlobal(mediatype, key)
|
||||
if not mediaTable[mediatype] then
|
||||
return false
|
||||
end
|
||||
overrideMedia[mediatype] = (key and mediaTable[mediatype][key]) and key or nil
|
||||
self.callbacks:Fire("LibSharedMedia_SetGlobal", mediatype, overrideMedia[mediatype])
|
||||
return true
|
||||
end
|
||||
|
||||
function lib:GetDefault(mediatype)
|
||||
return defaultMedia[mediatype]
|
||||
end
|
||||
|
||||
function lib:SetDefault(mediatype, key)
|
||||
if mediaTable[mediatype] and mediaTable[mediatype][key] and not defaultMedia[mediatype] then
|
||||
defaultMedia[mediatype] = key
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
4
Libraries/LibSharedMedia-3.0/lib.xml
Normal file
4
Libraries/LibSharedMedia-3.0/lib.xml
Normal 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="LibSharedMedia-3.0.lua" />
|
||||
</Ui>
|
||||
280
Libraries/LibSimpleSticky/LibSimpleSticky.lua
Normal file
280
Libraries/LibSimpleSticky/LibSimpleSticky.lua
Normal file
@@ -0,0 +1,280 @@
|
||||
--[[---------------------------------------------------------------------------------
|
||||
General Library providing an alternate StartMoving() that allows you to
|
||||
specify a number of frames to snap-to when moving the frame around
|
||||
|
||||
Example Usage:
|
||||
|
||||
<OnLoad>
|
||||
this:RegisterForDrag("LeftButton")
|
||||
</OnLoad>
|
||||
<OnDragStart>
|
||||
StickyFrames:StartMoving(this, {WatchDogFrame_player, WatchDogFrame_target, WatchDogFrame_party1, WatchDogFrame_party2, WatchDogFrame_party3, WatchDogFrame_party4},3,3,3,3)
|
||||
</OnDragStart>
|
||||
<OnDragStop>
|
||||
StickyFrames:StopMoving(this)
|
||||
StickyFrames:AnchorFrame(this)
|
||||
</OnDragStop>
|
||||
|
||||
------------------------------------------------------------------------------------
|
||||
This is a modified version by Elv for ElvUI
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
local MAJOR, MINOR = "LibSimpleSticky-1.0", 2
|
||||
local StickyFrames, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not StickyFrames then return end
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
Class declaration, along with a temporary table to hold any existing OnUpdate
|
||||
scripts.
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
StickyFrames.scripts = StickyFrames.scripts or {}
|
||||
StickyFrames.rangeX = 15
|
||||
StickyFrames.rangeY = 15
|
||||
StickyFrames.sticky = StickyFrames.sticky or {}
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
StickyFrames:StartMoving() - Sets a custom OnUpdate for the frame so it follows
|
||||
the mouse and snaps to the frames you specify
|
||||
|
||||
frame: The frame we want to move. Is typically "this"
|
||||
|
||||
frameList: A integer indexed list of frames that the given frame should try to
|
||||
stick to. These don't have to have anything special done to them,
|
||||
and they don't really even need to exist. You can inclue the
|
||||
moving frame in this list, it will be ignored. This helps you
|
||||
if you have a number of frames, just make ONE list to pass.
|
||||
|
||||
{WatchDogFrame_player, WatchDogFrame_party1, .. WatchDogFrame_party4}
|
||||
|
||||
left: If your frame has a tranparent border around the entire frame
|
||||
(think backdrops with borders). This can be used to fine tune the
|
||||
edges when you're stickying groups. Refers to any offset on the
|
||||
LEFT edge of the frame being moved.
|
||||
|
||||
top: same
|
||||
right: same
|
||||
bottom: same
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
function StickyFrames:StartMoving(frame, frameList, left, top, right, bottom)
|
||||
local x,y = GetCursorPosition()
|
||||
local aX,aY = frame:GetCenter()
|
||||
local aS = frame:GetEffectiveScale()
|
||||
|
||||
aX,aY = aX*aS,aY*aS
|
||||
local xoffset,yoffset = (aX - x),(aY - y)
|
||||
self.scripts[frame] = frame:GetScript("OnUpdate")
|
||||
frame:SetScript("OnUpdate", self:GetUpdateFunc(frame, frameList, xoffset, yoffset, left, top, right, bottom))
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
This stops the OnUpdate, leaving the frame at its last position. This will
|
||||
leave it anchored to UIParent. You can call StickyFrames:AnchorFrame() to
|
||||
anchor it back "TOPLEFT" , "TOPLEFT" to the parent.
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
function StickyFrames:StopMoving(frame)
|
||||
frame:SetScript("OnUpdate", self.scripts[frame])
|
||||
self.scripts[frame] = nil
|
||||
|
||||
if StickyFrames.sticky[frame] then
|
||||
local sticky = StickyFrames.sticky[frame]
|
||||
StickyFrames.sticky[frame] = nil
|
||||
return true, sticky
|
||||
else
|
||||
return false, nil
|
||||
end
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
This can be called in conjunction with StickyFrames:StopMoving() to anchor the
|
||||
frame right back to the parent, so you can manipulate its children as a group
|
||||
(This is useful in WatchDog)
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
function StickyFrames:AnchorFrame(frame)
|
||||
local xA,yA = frame:GetCenter()
|
||||
local parent = frame:GetParent() or UIParent
|
||||
local xP,yP = parent:GetCenter()
|
||||
local sA,sP = frame:GetEffectiveScale(), parent:GetEffectiveScale()
|
||||
|
||||
xP,yP = (xP*sP) / sA, (yP*sP) / sA
|
||||
|
||||
local xo,yo = (xP - xA)*-1, (yP - yA)*-1
|
||||
|
||||
frame:ClearAllPoints()
|
||||
frame:SetPoint("CENTER", parent, "CENTER", xo, yo)
|
||||
end
|
||||
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
Internal Functions -- Do not call these.
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
Returns an anonymous OnUpdate function for the frame in question. Need
|
||||
to provide the frame, frameList along with the x and y offset (difference between
|
||||
where the mouse picked up the frame, and the insets (left,top,right,bottom) in the
|
||||
case of borders, etc.w
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
function StickyFrames:GetUpdateFunc(frame, frameList, xoffset, yoffset, left, top, right, bottom)
|
||||
return function()
|
||||
local x,y = GetCursorPosition()
|
||||
local s = frame:GetEffectiveScale()
|
||||
local sticky = nil
|
||||
|
||||
x,y = x/s,y/s
|
||||
|
||||
frame:ClearAllPoints()
|
||||
frame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", x+xoffset, y+yoffset)
|
||||
|
||||
StickyFrames.sticky[frame] = nil
|
||||
for i = 1, #frameList do
|
||||
local v = frameList[i]
|
||||
if frame ~= v and frame ~= v:GetParent() and not IsShiftKeyDown() and v:IsVisible() then
|
||||
if self:SnapFrame(frame, v, left, top, right, bottom) then
|
||||
StickyFrames.sticky[frame] = v
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
Internal debug function.
|
||||
------------------------------------------------------------------------------------]]
|
||||
|
||||
function StickyFrames:debug(msg)
|
||||
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00StickyFrames: |r"..tostring(msg))
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------------------------------
|
||||
This is called when finding an overlap between two sticky frame. If frameA is near
|
||||
a sticky edge of frameB, then it will snap to that edge and return true. If there
|
||||
is no sticky edge collision, will return false so we can test other frames for
|
||||
stickyness.
|
||||
------------------------------------------------------------------------------------]]
|
||||
function StickyFrames:SnapFrame(frameA, frameB, left, top, right, bottom)
|
||||
local sA, sB = frameA:GetEffectiveScale(), frameB:GetEffectiveScale()
|
||||
local xA, yA = frameA:GetCenter()
|
||||
local xB, yB = frameB:GetCenter()
|
||||
local hA, hB = frameA:GetHeight() / 2, ((frameB:GetHeight() * sB) / sA) / 2
|
||||
local wA, wB = frameA:GetWidth() / 2, ((frameB:GetWidth() * sB) / sA) / 2
|
||||
|
||||
local newX, newY = xA, yA
|
||||
|
||||
if not left then left = 0 end
|
||||
if not top then top = 0 end
|
||||
if not right then right = 0 end
|
||||
if not bottom then bottom = 0 end
|
||||
|
||||
-- Lets translate B's coords into A's scale
|
||||
if not xB or not yB or not sB or not sA or not sB then return end
|
||||
xB, yB = (xB*sB) / sA, (yB*sB) / sA
|
||||
|
||||
local stickyAx, stickyAy = wA * 0.75, hA * 0.75
|
||||
local stickyBx, stickyBy = wB * 0.75, hB * 0.75
|
||||
|
||||
-- Grab the edges of each frame, for easier comparison
|
||||
|
||||
local lA, tA, rA, bA = frameA:GetLeft(), frameA:GetTop(), frameA:GetRight(), frameA:GetBottom()
|
||||
local lB, tB, rB, bB = frameB:GetLeft(), frameB:GetTop(), frameB:GetRight(), frameB:GetBottom()
|
||||
local snap = nil
|
||||
|
||||
-- Translate into A's scale
|
||||
lB, tB, rB, bB = (lB * sB) / sA, (tB * sB) / sA, (rB * sB) / sA, (bB * sB) / sA
|
||||
|
||||
if (bA <= tB and bB <= tA) then
|
||||
|
||||
-- Horizontal Centers
|
||||
if xA <= (xB + StickyFrames.rangeX) and xA >= (xB - StickyFrames.rangeX) then
|
||||
newX = xB
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Interior Left
|
||||
if lA <= (lB + StickyFrames.rangeX) and lA >= (lB - StickyFrames.rangeX) then
|
||||
newX = lB + wA
|
||||
if frameB == UIParent or frameB == WorldFrame or frameB == ElvUIParent then
|
||||
newX = newX + 4
|
||||
end
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Interior Right
|
||||
if rA <= (rB + StickyFrames.rangeX) and rA >= (rB - StickyFrames.rangeX) then
|
||||
newX = rB - wA
|
||||
if frameB == UIParent or frameB == WorldFrame or frameB == ElvUIParent then
|
||||
newX = newX - 4
|
||||
end
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Exterior Left to Right
|
||||
if lA <= (rB + StickyFrames.rangeX) and lA >= (rB - StickyFrames.rangeX) then
|
||||
newX = rB + (wA - left)
|
||||
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Exterior Right to Left
|
||||
if rA <= (lB + StickyFrames.rangeX) and rA >= (lB - StickyFrames.rangeX) then
|
||||
newX = lB - (wA - right)
|
||||
snap = true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if (lA <= rB and lB <= rA) then
|
||||
|
||||
-- Vertical Centers
|
||||
if yA <= (yB + StickyFrames.rangeY) and yA >= (yB - StickyFrames.rangeY) then
|
||||
newY = yB
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Interior Top
|
||||
if tA <= (tB + StickyFrames.rangeY) and tA >= (tB - StickyFrames.rangeY) then
|
||||
newY = tB - hA
|
||||
if frameB == UIParent or frameB == WorldFrame or frameB == ElvUIParent then
|
||||
newY = newY - 4
|
||||
end
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Interior Bottom
|
||||
if bA <= (bB + StickyFrames.rangeY) and bA >= (bB - StickyFrames.rangeY) then
|
||||
newY = bB + hA
|
||||
if frameB == UIParent or frameB == WorldFrame or frameB == ElvUIParent then
|
||||
newY = newY + 4
|
||||
end
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Exterior Top to Bottom
|
||||
if tA <= (bB + StickyFrames.rangeY + bottom) and tA >= (bB - StickyFrames.rangeY + bottom) then
|
||||
newY = bB - (hA - top)
|
||||
snap = true
|
||||
end
|
||||
|
||||
-- Exterior Bottom to Top
|
||||
if bA <= (tB + StickyFrames.rangeY - top) and bA >= (tB - StickyFrames.rangeY - top) then
|
||||
newY = tB + (hA - bottom)
|
||||
snap = true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if snap then
|
||||
frameA:ClearAllPoints()
|
||||
frameA:SetPoint("CENTER", UIParent, "BOTTOMLEFT", newX, newY)
|
||||
return true
|
||||
end
|
||||
end
|
||||
232
Libraries/LibSpellRange-1.0/LibSpellRange-1.0.lua
Normal file
232
Libraries/LibSpellRange-1.0/LibSpellRange-1.0.lua
Normal file
@@ -0,0 +1,232 @@
|
||||
--- = Background =
|
||||
-- Blizzard's IsSpellInRange API has always been very limited - you either must have the name of the spell, or its spell book ID. Checking directly by spellID is simply not possible.
|
||||
-- Now, in Mists of Pandaria, Blizzard changed the way that many talents and specialization spells work - instead of giving you a new spell when leaned, they replace existing spells. These replacement spells do not work with Blizzard's IsSpellInRange function whatsoever; this limitation is what prompted the creation of this lib.
|
||||
-- = Usage =
|
||||
-- **LibSpellRange-1.0** exposes an enhanced version of IsSpellInRange that:
|
||||
-- * Allows ranged checking based on both spell name and spellID.
|
||||
-- * Works correctly with replacement spells that will not work using Blizzard's IsSpellInRange method alone.
|
||||
--
|
||||
-- @class file
|
||||
-- @name LibSpellRange-1.0.lua
|
||||
|
||||
local major = "SpellRange-1.0"
|
||||
local minor = 13
|
||||
|
||||
assert(LibStub, format("%s requires LibStub.", major))
|
||||
|
||||
local Lib = LibStub:NewLibrary(major, minor)
|
||||
if not Lib then return end
|
||||
|
||||
local tonumber = _G.tonumber
|
||||
local strlower = _G.strlower
|
||||
local wipe = _G.wipe
|
||||
local type = _G.type
|
||||
|
||||
local GetSpellTabInfo = _G.GetSpellTabInfo
|
||||
local GetNumSpellTabs = _G.GetNumSpellTabs
|
||||
local GetSpellBookItemInfo = _G.GetSpellBookItemInfo
|
||||
local GetSpellBookItemName = _G.GetSpellBookItemName
|
||||
local GetSpellLink = _G.GetSpellLink
|
||||
local GetSpellInfo = _G.GetSpellInfo
|
||||
|
||||
local IsSpellInRange = _G.IsSpellInRange
|
||||
local SpellHasRange = _G.SpellHasRange
|
||||
|
||||
-- isNumber is basically a tonumber cache for maximum efficiency
|
||||
Lib.isNumber = Lib.isNumber or setmetatable({}, {
|
||||
__mode = "kv",
|
||||
__index = function(t, i)
|
||||
local o = tonumber(i) or false
|
||||
t[i] = o
|
||||
return o
|
||||
end})
|
||||
local isNumber = Lib.isNumber
|
||||
|
||||
-- strlower cache for maximum efficiency
|
||||
Lib.strlowerCache = Lib.strlowerCache or setmetatable(
|
||||
{}, {
|
||||
__index = function(t, i)
|
||||
if not i then return end
|
||||
local o
|
||||
if type(i) == "number" then
|
||||
o = i
|
||||
else
|
||||
o = strlower(i)
|
||||
end
|
||||
t[i] = o
|
||||
return o
|
||||
end,
|
||||
}) local strlowerCache = Lib.strlowerCache
|
||||
|
||||
-- Matches lowercase player spell names to their spellBookID
|
||||
Lib.spellsByName_spell = Lib.spellsByName_spell or {}
|
||||
local spellsByName_spell = Lib.spellsByName_spell
|
||||
|
||||
-- Matches player spellIDs to their spellBookID
|
||||
Lib.spellsByID_spell = Lib.spellsByID_spell or {}
|
||||
local spellsByID_spell = Lib.spellsByID_spell
|
||||
|
||||
-- Matches lowercase pet spell names to their spellBookID
|
||||
Lib.spellsByName_pet = Lib.spellsByName_pet or {}
|
||||
local spellsByName_pet = Lib.spellsByName_pet
|
||||
|
||||
-- Matches pet spellIDs to their spellBookID
|
||||
Lib.spellsByID_pet = Lib.spellsByID_pet or {}
|
||||
local spellsByID_pet = Lib.spellsByID_pet
|
||||
|
||||
-- Updates spellsByName and spellsByID
|
||||
local function UpdateBook(bookType)
|
||||
local _, _, offs, numspells = GetSpellTabInfo(3)
|
||||
local max = offs -- The offset of the next tab is the max ID of the previous tab.
|
||||
if numspells == 0 then
|
||||
-- New characters pre level 10 only have 2 tabs.
|
||||
local _, _, offs, numspells = GetSpellTabInfo(2)
|
||||
max = offs + numspells
|
||||
end
|
||||
|
||||
local spellsByName = Lib["spellsByName_" .. bookType]
|
||||
local spellsByID = Lib["spellsByID_" .. bookType]
|
||||
|
||||
wipe(spellsByName)
|
||||
wipe(spellsByID)
|
||||
|
||||
for spellBookID = 1, max do
|
||||
local type, baseSpellID = GetSpellBookItemInfo(spellBookID, bookType)
|
||||
|
||||
if type == "SPELL" or type == "PETACTION" then
|
||||
local currentSpellName = GetSpellBookItemName(spellBookID, bookType)
|
||||
local link = GetSpellLink(currentSpellName)
|
||||
local currentSpellID = tonumber(link and link:gsub("|", "||"):match("spell:(%d+)"))
|
||||
|
||||
-- For each entry we add to a table,
|
||||
-- only add it if there isn't anything there already.
|
||||
-- This prevents weird passives from overwriting real, legit spells.
|
||||
-- For example, in WoW 7.3.5 the ret paladin mastery
|
||||
-- was coming back with a base spell named "Judgement",
|
||||
-- which was overwriting the real "Judgement".
|
||||
-- Passives usually come last in the spellbook,
|
||||
-- so this should work just fine as a workaround.
|
||||
-- This issue with "Judgement" is gone in BFA because the mastery changed.
|
||||
|
||||
if currentSpellName and not spellsByName[strlower(currentSpellName)] then
|
||||
spellsByName[strlower(currentSpellName)] = spellBookID
|
||||
end
|
||||
if currentSpellID and not spellsByID[currentSpellID] then
|
||||
spellsByID[currentSpellID] = spellBookID
|
||||
end
|
||||
|
||||
if type == "SPELL" then
|
||||
-- PETACTION (pet abilities) don't return a spellID for baseSpellID,
|
||||
-- so base spells only work for proper player spells.
|
||||
local baseSpellName = GetSpellInfo(baseSpellID)
|
||||
if baseSpellName and not spellsByName[strlower(baseSpellName)] then
|
||||
spellsByName[strlower(baseSpellName)] = spellBookID
|
||||
end
|
||||
if baseSpellID and not spellsByID[baseSpellID] then
|
||||
spellsByID[baseSpellID] = spellBookID
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Handles updating spellsByName and spellsByID
|
||||
if not Lib.updaterFrame then
|
||||
Lib.updaterFrame = CreateFrame("Frame")
|
||||
end
|
||||
Lib.updaterFrame:UnregisterAllEvents()
|
||||
Lib.updaterFrame:RegisterEvent("SPELLS_CHANGED")
|
||||
|
||||
local function UpdateSpells()
|
||||
UpdateBook("spell")
|
||||
UpdateBook("pet")
|
||||
end
|
||||
|
||||
Lib.updaterFrame:SetScript("OnEvent", UpdateSpells)
|
||||
UpdateSpells()
|
||||
|
||||
--- Improved spell range checking function.
|
||||
-- @name SpellRange.IsSpellInRange
|
||||
-- @paramsig spell, unit
|
||||
-- @param spell Name or spellID of a spell that you wish to check the range of. The spell must be a spell that you have in your spellbook or your pet's spellbook.
|
||||
-- @param unit UnitID of the spell that you wish to check the range on.
|
||||
-- @return Exact same returns as http://wowprogramming.com/docs/api/IsSpellInRange
|
||||
-- @usage
|
||||
-- -- Check spell range by spell name on unit "target"
|
||||
-- local SpellRange = LibStub("SpellRange-1.0")
|
||||
-- local inRange = SpellRange.IsSpellInRange("Stormstrike", "target")
|
||||
--
|
||||
-- -- Check spell range by spellID on unit "mouseover"
|
||||
-- local SpellRange = LibStub("SpellRange-1.0")
|
||||
-- local inRange = SpellRange.IsSpellInRange(17364, "mouseover")
|
||||
function Lib.IsSpellInRange(spellInput, unit)
|
||||
if isNumber[spellInput] then
|
||||
local spell = spellsByID_spell[spellInput]
|
||||
if spell then
|
||||
return IsSpellInRange(spell, "spell", unit)
|
||||
else
|
||||
local spell = spellsByID_pet[spellInput]
|
||||
if spell then
|
||||
return IsSpellInRange(spell, "pet", unit)
|
||||
end
|
||||
end
|
||||
else
|
||||
local spellInput = strlowerCache[spellInput]
|
||||
|
||||
local spell = spellsByName_spell[spellInput]
|
||||
if spell then
|
||||
return IsSpellInRange(spell, "spell", unit)
|
||||
else
|
||||
local spell = spellsByName_pet[spellInput]
|
||||
if spell then
|
||||
return IsSpellInRange(spell, "pet", unit)
|
||||
end
|
||||
end
|
||||
|
||||
return IsSpellInRange(spellInput, unit)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Improved SpellHasRange.
|
||||
-- @name SpellRange.SpellHasRange
|
||||
-- @paramsig spell
|
||||
-- @param spell Name or spellID of a spell that you wish to check for a range. The spell must be a spell that you have in your spellbook or your pet's spellbook.
|
||||
-- @return Exact same returns as http://wowprogramming.com/docs/api/SpellHasRange
|
||||
-- @usage
|
||||
-- -- Check if a spell has a range by spell name
|
||||
-- local SpellRange = LibStub("SpellRange-1.0")
|
||||
-- local hasRange = SpellRange.SpellHasRange("Stormstrike")
|
||||
--
|
||||
-- -- Check if a spell has a range by spellID
|
||||
-- local SpellRange = LibStub("SpellRange-1.0")
|
||||
-- local hasRange = SpellRange.SpellHasRange(17364)
|
||||
function Lib.SpellHasRange(spellInput)
|
||||
if isNumber[spellInput] then
|
||||
local spell = spellsByID_spell[spellInput]
|
||||
if spell then
|
||||
return SpellHasRange(spell, "spell")
|
||||
else
|
||||
local spell = spellsByID_pet[spellInput]
|
||||
if spell then
|
||||
return SpellHasRange(spell, "pet")
|
||||
end
|
||||
end
|
||||
else
|
||||
local spellInput = strlowerCache[spellInput]
|
||||
|
||||
local spell = spellsByName_spell[spellInput]
|
||||
if spell then
|
||||
return SpellHasRange(spell, "spell")
|
||||
else
|
||||
local spell = spellsByName_pet[spellInput]
|
||||
if spell then
|
||||
return SpellHasRange(spell, "pet")
|
||||
end
|
||||
end
|
||||
|
||||
return SpellHasRange(spellInput)
|
||||
end
|
||||
|
||||
end
|
||||
3
Libraries/LibSpellRange-1.0/lib.xml
Normal file
3
Libraries/LibSpellRange-1.0/lib.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<Ui>
|
||||
<Script file="LibSpellRange-1.0.lua"/>
|
||||
</Ui>
|
||||
113
Libraries/LibTranslit-1.0/LibTranslit-1.0.lua
Normal file
113
Libraries/LibTranslit-1.0/LibTranslit-1.0.lua
Normal file
@@ -0,0 +1,113 @@
|
||||
local MAJOR_VERSION = "LibTranslit-1.0"
|
||||
local MINOR_VERSION = 3
|
||||
if not LibStub then
|
||||
error(MAJOR_VERSION .. " requires LibStub.")
|
||||
end
|
||||
local lib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
|
||||
if not lib then
|
||||
return
|
||||
end
|
||||
|
||||
local CyrToLat = {
|
||||
["А"] = "A",
|
||||
["а"] = "a",
|
||||
["Б"] = "B",
|
||||
["б"] = "b",
|
||||
["В"] = "V",
|
||||
["в"] = "v",
|
||||
["Г"] = "G",
|
||||
["г"] = "g",
|
||||
["Д"] = "D",
|
||||
["д"] = "d",
|
||||
["Е"] = "E",
|
||||
["е"] = "e",
|
||||
["Ё"] = "e",
|
||||
["ё"] = "e",
|
||||
["Ж"] = "Zh",
|
||||
["ж"] = "zh",
|
||||
["З"] = "Z",
|
||||
["з"] = "z",
|
||||
["И"] = "I",
|
||||
["и"] = "i",
|
||||
["Й"] = "Y",
|
||||
["й"] = "y",
|
||||
["К"] = "K",
|
||||
["к"] = "k",
|
||||
["Л"] = "L",
|
||||
["л"] = "l",
|
||||
["М"] = "M",
|
||||
["м"] = "m",
|
||||
["Н"] = "N",
|
||||
["н"] = "n",
|
||||
["О"] = "O",
|
||||
["о"] = "o",
|
||||
["П"] = "P",
|
||||
["п"] = "p",
|
||||
["Р"] = "R",
|
||||
["р"] = "r",
|
||||
["С"] = "S",
|
||||
["с"] = "s",
|
||||
["Т"] = "T",
|
||||
["т"] = "t",
|
||||
["У"] = "U",
|
||||
["у"] = "u",
|
||||
["Ф"] = "F",
|
||||
["ф"] = "f",
|
||||
["Х"] = "Kh",
|
||||
["х"] = "kh",
|
||||
["Ц"] = "Ts",
|
||||
["ц"] = "ts",
|
||||
["Ч"] = "Ch",
|
||||
["ч"] = "ch",
|
||||
["Ш"] = "Sh",
|
||||
["ш"] = "sh",
|
||||
["Щ"] = "Shch",
|
||||
["щ"] = "shch",
|
||||
["Ъ"] = "",
|
||||
["ъ"] = "",
|
||||
["Ы"] = "Y",
|
||||
["ы"] = "y",
|
||||
["Ь"] = "",
|
||||
["ь"] = "",
|
||||
["Э"] = "E",
|
||||
["э"] = "e",
|
||||
["Ю"] = "Yu",
|
||||
["ю"] = "yu",
|
||||
["Я"] = "Ya",
|
||||
["я"] = "ya"
|
||||
}
|
||||
|
||||
function lib:Transliterate(str, mark)
|
||||
if not str then
|
||||
return ""
|
||||
end
|
||||
|
||||
local mark = mark or ""
|
||||
local tstr = ""
|
||||
local marked = false
|
||||
local i = 1
|
||||
|
||||
while i <= string.len(str) do
|
||||
local c = str:sub(i, i)
|
||||
local b = string.byte(c)
|
||||
|
||||
if b == 208 or b == 209 then
|
||||
if marked == false then
|
||||
tstr = tstr .. mark
|
||||
marked = true
|
||||
end
|
||||
c = str:sub(i + 1, i + 1)
|
||||
tstr = tstr .. (CyrToLat[string.char(b, string.byte(c))] or string.char(b, string.byte(c)))
|
||||
|
||||
i = i + 2
|
||||
else
|
||||
if c == " " or c == "-" then
|
||||
marked = false
|
||||
end
|
||||
tstr = tstr .. c
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
return tstr
|
||||
end
|
||||
29
Libraries/Load_Libraries.xml
Normal file
29
Libraries/Load_Libraries.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<Ui xmlns='http://www.blizzard.com/wow/ui/'>
|
||||
<Script file='Ace3\LibStub\LibStub.lua'/>
|
||||
<Script file='Ace3\CallbackHandler-1.0\CallbackHandler-1.0.lua'/>
|
||||
<Include file='Ace3\AceAddon-3.0\AceAddon-3.0.xml'/>
|
||||
<Include file='Ace3\AceEvent-3.0\AceEvent-3.0.xml'/>
|
||||
<Include file='Ace3\AceConsole-3.0\AceConsole-3.0.xml'/>
|
||||
<Include file='Ace3\AceDB-3.0\AceDB-3.0.xml'/>
|
||||
<Include file='Ace3\AceLocale-3.0\AceLocale-3.0.xml'/>
|
||||
<Include file='Ace3\AceComm-3.0\AceComm-3.0.xml'/>
|
||||
<Include file='Ace3\AceSerializer-3.0\AceSerializer-3.0.xml'/>
|
||||
<Include file='Ace3\AceTimer-3.0\AceTimer-3.0.xml'/>
|
||||
<Include file='Ace3\AceHook-3.0\AceHook-3.0.xml'/>
|
||||
<Include file='LibSpellRange-1.0\lib.xml'/>
|
||||
<Include file='LibSharedMedia-3.0\lib.xml'/>
|
||||
<Script file='LibSimpleSticky\LibSimpleSticky.lua'/>
|
||||
<Include file='oUF\oUF.xml'/>
|
||||
<Include file='oUF_Plugins\oUF_Plugins.xml'/>
|
||||
<Include file='LibActionButton-1.0\LibActionButton-1.0.xml'/>
|
||||
<Script file='LibDataBroker\LibDataBroker-1.1.lua'/>
|
||||
<Script file='LibDualSpec-1.0\LibDualSpec-1.0.lua'/>
|
||||
<Script file='LibElvUIPlugin-1.0\LibElvUIPlugin-1.0.lua'/>
|
||||
<Include file='UTF8\UTF8.xml'/>
|
||||
<Include file='LibItemSearch-1.2\LibItemSearch-1.2.xml'/>
|
||||
<Include file='LibChatAnims\LibChatAnims.xml'/>
|
||||
<Include file='LibCompress\lib.xml'/>
|
||||
<Include file='LibBase64-1.0\lib.xml'/>
|
||||
<Script file='LibAnim\LibAnim.lua'/>
|
||||
<Script file='LibTranslit-1.0\LibTranslit-1.0.lua'/>
|
||||
</Ui>
|
||||
5
Libraries/UTF8/UTF8.xml
Normal file
5
Libraries/UTF8/UTF8.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<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="utf8data.lua"/>
|
||||
<Script file="utf8.lua"/>
|
||||
</Ui>
|
||||
318
Libraries/UTF8/utf8.lua
Normal file
318
Libraries/UTF8/utf8.lua
Normal file
@@ -0,0 +1,318 @@
|
||||
-- $Id: utf8.lua 179 2009-04-03 18:10:03Z pasta $
|
||||
--
|
||||
-- Provides UTF-8 aware string functions implemented in pure lua:
|
||||
-- * string.utf8len(s)
|
||||
-- * string.utf8sub(s, i, j)
|
||||
-- * string.utf8reverse(s)
|
||||
--
|
||||
-- If utf8data.lua (containing the lower<->upper case mappings) is loaded, these
|
||||
-- additional functions are available:
|
||||
-- * string.utf8upper(s)
|
||||
-- * string.utf8lower(s)
|
||||
--
|
||||
-- All functions behave as their non UTF-8 aware counterparts with the exception
|
||||
-- that UTF-8 characters are used instead of bytes for all units.
|
||||
|
||||
--[[
|
||||
Copyright (c) 2006-2007, Kyle Smith
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its contributors may be
|
||||
used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
--]]
|
||||
|
||||
-- ABNF from RFC 3629
|
||||
--
|
||||
-- UTF8-octets = *( UTF8-char )
|
||||
-- UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
|
||||
-- UTF8-1 = %x00-7F
|
||||
-- UTF8-2 = %xC2-DF UTF8-tail
|
||||
-- UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
|
||||
-- %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
|
||||
-- UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
|
||||
-- %xF4 %x80-8F 2( UTF8-tail )
|
||||
-- UTF8-tail = %x80-BF
|
||||
--
|
||||
|
||||
local strbyte, strlen, strsub, type = string.byte, string.len, string.sub, type
|
||||
|
||||
-- returns the number of bytes used by the UTF-8 character at byte i in s
|
||||
-- also doubles as a UTF-8 character validator
|
||||
local function utf8charbytes(s, i)
|
||||
-- argument defaults
|
||||
i = i or 1
|
||||
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8charbytes' (string expected, got ".. type(s).. ")")
|
||||
end
|
||||
if type(i) ~= "number" then
|
||||
error("bad argument #2 to 'utf8charbytes' (number expected, got ".. type(i).. ")")
|
||||
end
|
||||
|
||||
local c = strbyte(s, i)
|
||||
|
||||
-- determine bytes needed for character, based on RFC 3629
|
||||
-- validate byte 1
|
||||
if c > 0 and c <= 127 then
|
||||
-- UTF8-1
|
||||
return 1
|
||||
|
||||
elseif c >= 194 and c <= 223 then
|
||||
-- UTF8-2
|
||||
local c2 = strbyte(s, i + 1)
|
||||
|
||||
if not c2 then
|
||||
error("UTF-8 string terminated early")
|
||||
end
|
||||
|
||||
-- validate byte 2
|
||||
if c2 < 128 or c2 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
return 2
|
||||
|
||||
elseif c >= 224 and c <= 239 then
|
||||
-- UTF8-3
|
||||
local c2 = strbyte(s, i + 1)
|
||||
local c3 = strbyte(s, i + 2)
|
||||
|
||||
if not c2 or not c3 then
|
||||
error("UTF-8 string terminated early")
|
||||
end
|
||||
|
||||
-- validate byte 2
|
||||
if c == 224 and (c2 < 160 or c2 > 191) then
|
||||
error("Invalid UTF-8 character")
|
||||
elseif c == 237 and (c2 < 128 or c2 > 159) then
|
||||
error("Invalid UTF-8 character")
|
||||
elseif c2 < 128 or c2 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
-- validate byte 3
|
||||
if c3 < 128 or c3 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
return 3
|
||||
|
||||
elseif c >= 240 and c <= 244 then
|
||||
-- UTF8-4
|
||||
local c2 = strbyte(s, i + 1)
|
||||
local c3 = strbyte(s, i + 2)
|
||||
local c4 = strbyte(s, i + 3)
|
||||
|
||||
if not c2 or not c3 or not c4 then
|
||||
error("UTF-8 string terminated early")
|
||||
end
|
||||
|
||||
-- validate byte 2
|
||||
if c == 240 and (c2 < 144 or c2 > 191) then
|
||||
error("Invalid UTF-8 character")
|
||||
elseif c == 244 and (c2 < 128 or c2 > 143) then
|
||||
error("Invalid UTF-8 character")
|
||||
elseif c2 < 128 or c2 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
-- validate byte 3
|
||||
if c3 < 128 or c3 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
-- validate byte 4
|
||||
if c4 < 128 or c4 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
return 4
|
||||
|
||||
else
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
end
|
||||
|
||||
-- returns the number of characters in a UTF-8 string
|
||||
local function utf8len(s)
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8len' (string expected, got ".. type(s).. ")")
|
||||
end
|
||||
|
||||
local pos = 1
|
||||
local bytes = strlen(s)
|
||||
local len = 0
|
||||
|
||||
while pos <= bytes do
|
||||
len = len + 1
|
||||
pos = pos + utf8charbytes(s, pos)
|
||||
end
|
||||
|
||||
return len
|
||||
end
|
||||
|
||||
-- install in the string library
|
||||
if not string.utf8len then
|
||||
string.utf8len = utf8len
|
||||
end
|
||||
|
||||
-- functions identically to string.sub except that i and j are UTF-8 characters
|
||||
-- instead of bytes
|
||||
local function utf8sub(s, i, j)
|
||||
-- argument defaults
|
||||
j = j or -1
|
||||
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8sub' (string expected, got ".. type(s).. ")")
|
||||
end
|
||||
if type(i) ~= "number" then
|
||||
error("bad argument #2 to 'utf8sub' (number expected, got ".. type(i).. ")")
|
||||
end
|
||||
if type(j) ~= "number" then
|
||||
error("bad argument #3 to 'utf8sub' (number expected, got ".. type(j).. ")")
|
||||
end
|
||||
|
||||
local pos = 1
|
||||
local bytes = strlen(s)
|
||||
local len = 0
|
||||
|
||||
-- only set l if i or j is negative
|
||||
local l = (i >= 0 and j >= 0) or utf8len(s)
|
||||
local startChar = (i >= 0) and i or l + i + 1
|
||||
local endChar = (j >= 0) and j or l + j + 1
|
||||
|
||||
-- can't have start before end!
|
||||
if startChar > endChar then
|
||||
return ""
|
||||
end
|
||||
|
||||
-- byte offsets to pass to string.sub
|
||||
local startByte, endByte = 1, bytes
|
||||
|
||||
while pos <= bytes do
|
||||
len = len + 1
|
||||
|
||||
if len == startChar then
|
||||
startByte = pos
|
||||
end
|
||||
|
||||
pos = pos + utf8charbytes(s, pos)
|
||||
|
||||
if len == endChar then
|
||||
endByte = pos - 1
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return strsub(s, startByte, endByte)
|
||||
end
|
||||
|
||||
-- install in the string library
|
||||
if not string.utf8sub then
|
||||
string.utf8sub = utf8sub
|
||||
end
|
||||
|
||||
-- replace UTF-8 characters based on a mapping table
|
||||
local function utf8replace(s, mapping)
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8replace' (string expected, got ".. type(s).. ")")
|
||||
end
|
||||
if type(mapping) ~= "table" then
|
||||
error("bad argument #2 to 'utf8replace' (table expected, got ".. type(mapping).. ")")
|
||||
end
|
||||
|
||||
local pos = 1
|
||||
local bytes = strlen(s)
|
||||
local charbytes
|
||||
local newstr = ""
|
||||
|
||||
while pos <= bytes do
|
||||
charbytes = utf8charbytes(s, pos)
|
||||
local c = strsub(s, pos, pos + charbytes - 1)
|
||||
|
||||
newstr = newstr .. (mapping[c] or c)
|
||||
|
||||
pos = pos + charbytes
|
||||
end
|
||||
|
||||
return newstr
|
||||
end
|
||||
|
||||
-- identical to string.upper except it knows about unicode simple case conversions
|
||||
local function utf8upper(s)
|
||||
return utf8replace(s, utf8_lc_uc)
|
||||
end
|
||||
|
||||
-- install in the string library
|
||||
if not string.utf8upper and utf8_lc_uc then
|
||||
string.utf8upper = utf8upper
|
||||
end
|
||||
|
||||
-- identical to string.lower except it knows about unicode simple case conversions
|
||||
local function utf8lower(s)
|
||||
return utf8replace(s, utf8_uc_lc)
|
||||
end
|
||||
|
||||
-- install in the string library
|
||||
if not string.utf8lower and utf8_uc_lc then
|
||||
string.utf8lower = utf8lower
|
||||
end
|
||||
|
||||
-- identical to string.reverse except that it supports UTF-8
|
||||
local function utf8reverse(s)
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8reverse' (string expected, got ".. type(s).. ")")
|
||||
end
|
||||
|
||||
local bytes = strlen(s)
|
||||
local pos = bytes
|
||||
local charbytes
|
||||
local newstr = ""
|
||||
local c
|
||||
|
||||
while pos > 0 do
|
||||
c = strbyte(s, pos)
|
||||
while c >= 128 and c <= 191 do
|
||||
pos = pos - 1
|
||||
c = strbyte(pos)
|
||||
end
|
||||
|
||||
charbytes = utf8charbytes(s, pos)
|
||||
|
||||
newstr = newstr .. strsub(s, pos, pos + charbytes - 1)
|
||||
|
||||
pos = pos - 1
|
||||
end
|
||||
|
||||
return newstr
|
||||
end
|
||||
|
||||
-- install in the string library
|
||||
if not string.utf8reverse then
|
||||
string.utf8reverse = utf8reverse
|
||||
end
|
||||
1859
Libraries/UTF8/utf8data.lua
Normal file
1859
Libraries/UTF8/utf8data.lua
Normal file
File diff suppressed because it is too large
Load Diff
25
Libraries/oUF/LICENSE
Normal file
25
Libraries/oUF/LICENSE
Normal file
@@ -0,0 +1,25 @@
|
||||
Copyright (c) 2006-2020 Trond A Ekseth <troeks@gmail.com>
|
||||
Copyright (c) 2016-2020 Val Voronov <i.lightspark@gmail.com>
|
||||
Copyright (c) 2016-2020 Adrian L Lange <contact@p3lim.net>
|
||||
Copyright (c) 2016-2020 Rainrider <rainrider.wow@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
132
Libraries/oUF/blizzard.lua
Normal file
132
Libraries/oUF/blizzard.lua
Normal file
@@ -0,0 +1,132 @@
|
||||
local parent, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
-- sourced from Blizzard_ArenaUI/Blizzard_ArenaUI.lua
|
||||
local MAX_ARENA_ENEMIES = MAX_ARENA_ENEMIES or 5
|
||||
|
||||
-- sourced from FrameXML/TargetFrame.lua
|
||||
local MAX_BOSS_FRAMES = MAX_BOSS_FRAMES or 5
|
||||
|
||||
-- sourced from FrameXML/PartyMemberFrame.lua
|
||||
local MAX_PARTY_MEMBERS = MAX_PARTY_MEMBERS or 4
|
||||
|
||||
local hiddenParent = CreateFrame('Frame', nil, UIParent)
|
||||
hiddenParent:SetAllPoints()
|
||||
hiddenParent:Hide()
|
||||
|
||||
local function insecureOnShow(self)
|
||||
self:Hide()
|
||||
end
|
||||
|
||||
local function handleFrame(baseName, doNotReparent)
|
||||
local frame
|
||||
if(type(baseName) == 'string') then
|
||||
frame = _G[baseName]
|
||||
else
|
||||
frame = baseName
|
||||
end
|
||||
|
||||
if(frame) then
|
||||
frame:UnregisterAllEvents()
|
||||
frame:Hide()
|
||||
|
||||
if(not doNotReparent) then
|
||||
frame:SetParent(hiddenParent)
|
||||
end
|
||||
|
||||
local health = frame.healthBar or frame.healthbar
|
||||
if(health) then
|
||||
health:UnregisterAllEvents()
|
||||
end
|
||||
|
||||
local power = frame.manabar
|
||||
if(power) then
|
||||
power:UnregisterAllEvents()
|
||||
end
|
||||
|
||||
local spell = frame.castBar or frame.spellbar
|
||||
if(spell) then
|
||||
spell:UnregisterAllEvents()
|
||||
end
|
||||
|
||||
local altpowerbar = frame.powerBarAlt
|
||||
if(altpowerbar) then
|
||||
altpowerbar:UnregisterAllEvents()
|
||||
end
|
||||
|
||||
local buffFrame = frame.BuffFrame
|
||||
if(buffFrame) then
|
||||
buffFrame:UnregisterAllEvents()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function oUF:DisableBlizzard(unit)
|
||||
if(not unit) then return end
|
||||
|
||||
if(unit == 'player') then
|
||||
handleFrame(PlayerFrame)
|
||||
|
||||
-- For the damn vehicle support:
|
||||
PlayerFrame:RegisterEvent('PLAYER_ENTERING_WORLD')
|
||||
PlayerFrame:RegisterEvent('UNIT_ENTERING_VEHICLE')
|
||||
PlayerFrame:RegisterEvent('UNIT_ENTERED_VEHICLE')
|
||||
PlayerFrame:RegisterEvent('UNIT_EXITING_VEHICLE')
|
||||
PlayerFrame:RegisterEvent('UNIT_EXITED_VEHICLE')
|
||||
|
||||
-- User placed frames don't animate
|
||||
PlayerFrame:SetUserPlaced(true)
|
||||
PlayerFrame:SetDontSavePosition(true)
|
||||
elseif(unit == 'pet') then
|
||||
handleFrame(PetFrame)
|
||||
elseif(unit == 'target') then
|
||||
handleFrame(TargetFrame)
|
||||
handleFrame(ComboFrame)
|
||||
elseif(unit == 'focus') then
|
||||
handleFrame(FocusFrame)
|
||||
handleFrame(TargetofFocusFrame)
|
||||
elseif(unit == 'targettarget') then
|
||||
handleFrame(TargetFrameToT)
|
||||
elseif(unit:match('boss%d?$')) then
|
||||
local id = unit:match('boss(%d)')
|
||||
if(id) then
|
||||
handleFrame('Boss' .. id .. 'TargetFrame')
|
||||
else
|
||||
for i = 1, MAX_BOSS_FRAMES do
|
||||
handleFrame(string.format('Boss%dTargetFrame', i))
|
||||
end
|
||||
end
|
||||
elseif(unit:match('party%d?$')) then
|
||||
local id = unit:match('party(%d)')
|
||||
if(id) then
|
||||
handleFrame('PartyMemberFrame' .. id)
|
||||
else
|
||||
for i = 1, MAX_PARTY_MEMBERS do
|
||||
handleFrame(string.format('PartyMemberFrame%d', i))
|
||||
end
|
||||
end
|
||||
elseif(unit:match('arena%d?$')) then
|
||||
local id = unit:match('arena(%d)')
|
||||
if(id) then
|
||||
handleFrame('ArenaEnemyFrame' .. id)
|
||||
else
|
||||
for i = 1, MAX_ARENA_ENEMIES do
|
||||
handleFrame(string.format('ArenaEnemyFrame%d', i))
|
||||
end
|
||||
end
|
||||
|
||||
-- Blizzard_ArenaUI should not be loaded
|
||||
Arena_LoadUI = function() end
|
||||
SetCVar('showArenaEnemyFrames', '0', 'SHOW_ARENA_ENEMY_FRAMES_TEXT')
|
||||
elseif(unit:match('nameplate%d+$')) then
|
||||
local frame = C_NamePlate.GetNamePlateForUnit(unit)
|
||||
if(frame and frame.UnitFrame) then
|
||||
if(not frame.UnitFrame.isHooked) then
|
||||
frame.UnitFrame:HookScript('OnShow', insecureOnShow)
|
||||
frame.UnitFrame.isHooked = true
|
||||
end
|
||||
|
||||
handleFrame(frame.UnitFrame, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
272
Libraries/oUF/colors.lua
Normal file
272
Libraries/oUF/colors.lua
Normal file
@@ -0,0 +1,272 @@
|
||||
local parent, ns = ...
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local frame_metatable = Private.frame_metatable
|
||||
|
||||
local colors = {
|
||||
smooth = {
|
||||
1, 0, 0,
|
||||
1, 1, 0,
|
||||
0, 1, 0
|
||||
},
|
||||
health = {49 / 255, 207 / 255, 37 / 255},
|
||||
disconnected = {0.6, 0.6, 0.6},
|
||||
tapped = {0.6, 0.6, 0.6},
|
||||
runes = {
|
||||
{247 / 255, 65 / 255, 57 / 255}, -- blood
|
||||
{148 / 255, 203 / 255, 247 / 255}, -- frost
|
||||
{173 / 255, 235 / 255, 66 / 255}, -- unholy
|
||||
},
|
||||
selection = {
|
||||
[ 0] = {255 / 255, 0 / 255, 0 / 255}, -- HOSTILE
|
||||
[ 1] = {255 / 255, 129 / 255, 0 / 255}, -- UNFRIENDLY
|
||||
[ 2] = {255 / 255, 255 / 255, 0 / 255}, -- NEUTRAL
|
||||
[ 3] = {0 / 255, 255 / 255, 0 / 255}, -- FRIENDLY
|
||||
[ 4] = {0 / 255, 0 / 255, 255 / 255}, -- PLAYER_SIMPLE
|
||||
[ 5] = {96 / 255, 96 / 255, 255 / 255}, -- PLAYER_EXTENDED
|
||||
[ 6] = {170 / 255, 170 / 255, 255 / 255}, -- PARTY
|
||||
[ 7] = {170 / 255, 255 / 255, 170 / 255}, -- PARTY_PVP
|
||||
[ 8] = {83 / 255, 201 / 255, 255 / 255}, -- FRIEND
|
||||
[ 9] = {128 / 255, 128 / 255, 128 / 255}, -- DEAD
|
||||
-- [10] = {}, -- COMMENTATOR_TEAM_1, unavailable to players
|
||||
-- [11] = {}, -- COMMENTATOR_TEAM_2, unavailable to players
|
||||
[12] = {255 / 255, 255 / 255, 139 / 255}, -- SELF, buggy
|
||||
[13] = {0 / 255, 153 / 255, 0 / 255}, -- BATTLEGROUND_FRIENDLY_PVP
|
||||
},
|
||||
class = {},
|
||||
debuff = {},
|
||||
reaction = {},
|
||||
power = {},
|
||||
threat = {},
|
||||
}
|
||||
|
||||
-- We do this because people edit the vars directly, and changing the default
|
||||
-- globals makes SPICE FLOW!
|
||||
local function customClassColors()
|
||||
if(CUSTOM_CLASS_COLORS) then
|
||||
local function updateColors()
|
||||
for classToken, color in next, CUSTOM_CLASS_COLORS do
|
||||
colors.class[classToken] = {color.r, color.g, color.b}
|
||||
end
|
||||
|
||||
for _, obj in next, oUF.objects do
|
||||
obj:UpdateAllElements('CUSTOM_CLASS_COLORS')
|
||||
end
|
||||
end
|
||||
|
||||
updateColors()
|
||||
CUSTOM_CLASS_COLORS:RegisterCallback(updateColors)
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if(not customClassColors()) then
|
||||
for classToken, color in next, RAID_CLASS_COLORS do
|
||||
colors.class[classToken] = {color.r, color.g, color.b}
|
||||
end
|
||||
|
||||
local eventHandler = CreateFrame('Frame')
|
||||
eventHandler:RegisterEvent('ADDON_LOADED')
|
||||
eventHandler:SetScript('OnEvent', function(self)
|
||||
if(customClassColors()) then
|
||||
self:UnregisterEvent('ADDON_LOADED')
|
||||
self:SetScript('OnEvent', nil)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
for debuffType, color in next, DebuffTypeColor do
|
||||
colors.debuff[debuffType] = {color.r, color.g, color.b}
|
||||
end
|
||||
|
||||
for eclass, color in next, FACTION_BAR_COLORS do
|
||||
colors.reaction[eclass] = {color.r, color.g, color.b}
|
||||
end
|
||||
|
||||
for power, color in next, PowerBarColor do
|
||||
if (type(power) == 'string') then
|
||||
if(type(select(2, next(color))) == 'table') then
|
||||
colors.power[power] = {}
|
||||
|
||||
for index, color in next, color do
|
||||
colors.power[power][index] = {color.r, color.g, color.b}
|
||||
end
|
||||
else
|
||||
colors.power[power] = {color.r, color.g, color.b, atlas = color.atlas}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- sourced from FrameXML/Constants.lua
|
||||
colors.power[0] = colors.power.MANA
|
||||
colors.power[1] = colors.power.RAGE
|
||||
colors.power[2] = colors.power.FOCUS
|
||||
colors.power[3] = colors.power.ENERGY
|
||||
colors.power[4] = colors.power.COMBO_POINTS
|
||||
colors.power[5] = colors.power.RUNES
|
||||
colors.power[6] = colors.power.RUNIC_POWER
|
||||
colors.power[7] = colors.power.SOUL_SHARDS
|
||||
colors.power[8] = colors.power.LUNAR_POWER
|
||||
colors.power[9] = colors.power.HOLY_POWER
|
||||
colors.power[11] = colors.power.MAELSTROM
|
||||
colors.power[12] = colors.power.CHI
|
||||
colors.power[13] = colors.power.INSANITY
|
||||
colors.power[16] = colors.power.ARCANE_CHARGES
|
||||
colors.power[17] = colors.power.FURY
|
||||
colors.power[18] = colors.power.PAIN
|
||||
|
||||
-- alternate power, sourced from FrameXML/CompactUnitFrame.lua
|
||||
colors.power.ALTERNATE = {0.7, 0.7, 0.6}
|
||||
colors.power[10] = colors.power.ALTERNATE
|
||||
|
||||
for i = 0, 3 do
|
||||
colors.threat[i] = {GetThreatStatusColor(i)}
|
||||
end
|
||||
|
||||
local function colorsAndPercent(a, b, ...)
|
||||
if(a <= 0 or b == 0) then
|
||||
return nil, ...
|
||||
elseif(a >= b) then
|
||||
return nil, select(-3, ...)
|
||||
end
|
||||
|
||||
local num = select('#', ...) / 3
|
||||
local segment, relperc = math.modf((a / b) * (num - 1))
|
||||
return relperc, select((segment * 3) + 1, ...)
|
||||
end
|
||||
|
||||
-- http://www.wowwiki.com/ColorGradient
|
||||
--[[ Colors: oUF:RGBColorGradient(a, b, ...)
|
||||
Used to convert a percent value (the quotient of `a` and `b`) into a gradient from 2 or more RGB colors. If more than 2
|
||||
colors are passed, the gradient will be between the two colors which perc lies in an evenly divided range. A RGB color
|
||||
is a sequence of 3 consecutive RGB percent values (in the range [0-1]). If `a` is negative or `b` is zero then the first
|
||||
RGB color (the first 3 RGB values passed to the function) is returned. If `a` is bigger than or equal to `b`, then the
|
||||
last 3 RGB values are returned.
|
||||
|
||||
* self - the global oUF object
|
||||
* a - value used as numerator to calculate the percentage (number)
|
||||
* b - value used as denominator to calculate the percentage (number)
|
||||
* ... - a list of RGB percent values. At least 6 values should be passed (number [0-1])
|
||||
--]]
|
||||
function oUF:RGBColorGradient(...)
|
||||
local relperc, r1, g1, b1, r2, g2, b2 = colorsAndPercent(...)
|
||||
if(relperc) then
|
||||
return r1 + (r2 - r1) * relperc, g1 + (g2 - g1) * relperc, b1 + (b2 - b1) * relperc
|
||||
else
|
||||
return r1, g1, b1
|
||||
end
|
||||
end
|
||||
|
||||
-- HCY functions are based on http://www.chilliant.com/rgb2hsv.html
|
||||
local function getY(r, g, b)
|
||||
return 0.299 * r + 0.587 * g + 0.114 * b
|
||||
end
|
||||
|
||||
local function rgbToHCY(r, g, b)
|
||||
local min, max = math.min(r, g, b), math.max(r, g, b)
|
||||
local chroma = max - min
|
||||
local hue
|
||||
if(chroma > 0) then
|
||||
if(r == max) then
|
||||
hue = ((g - b) / chroma) % 6
|
||||
elseif(g == max) then
|
||||
hue = (b - r) / chroma + 2
|
||||
elseif(b == max) then
|
||||
hue = (r - g) / chroma + 4
|
||||
end
|
||||
hue = hue / 6
|
||||
end
|
||||
return hue, chroma, getY(r, g, b)
|
||||
end
|
||||
|
||||
local function hcyToRGB(hue, chroma, luma)
|
||||
local r, g, b = 0, 0, 0
|
||||
if(hue and luma > 0) then
|
||||
local h2 = hue * 6
|
||||
local x = chroma * (1 - math.abs(h2 % 2 - 1))
|
||||
if(h2 < 1) then
|
||||
r, g, b = chroma, x, 0
|
||||
elseif(h2 < 2) then
|
||||
r, g, b = x, chroma, 0
|
||||
elseif(h2 < 3) then
|
||||
r, g, b = 0, chroma, x
|
||||
elseif(h2 < 4) then
|
||||
r, g, b = 0, x, chroma
|
||||
elseif(h2 < 5) then
|
||||
r, g, b = x, 0, chroma
|
||||
else
|
||||
r, g, b = chroma, 0, x
|
||||
end
|
||||
|
||||
local y = getY(r, g, b)
|
||||
if(luma < y) then
|
||||
chroma = chroma * (luma / y)
|
||||
elseif(y < 1) then
|
||||
chroma = chroma * (1 - luma) / (1 - y)
|
||||
end
|
||||
|
||||
r = (r - y) * chroma + luma
|
||||
g = (g - y) * chroma + luma
|
||||
b = (b - y) * chroma + luma
|
||||
end
|
||||
return r, g, b
|
||||
end
|
||||
|
||||
--[[ Colors: oUF:HCYColorGradient(a, b, ...)
|
||||
Used to convert a percent value (the quotient of `a` and `b`) into a gradient from 2 or more HCY colors. If more than 2
|
||||
colors are passed, the gradient will be between the two colors which perc lies in an evenly divided range. A HCY color
|
||||
is a sequence of 3 consecutive values in the range [0-1]. If `a` is negative or `b` is zero then the first
|
||||
HCY color (the first 3 HCY values passed to the function) is returned. If `a` is bigger than or equal to `b`, then the
|
||||
last 3 HCY values are returned.
|
||||
|
||||
* self - the global oUF object
|
||||
* a - value used as numerator to calculate the percentage (number)
|
||||
* b - value used as denominator to calculate the percentage (number)
|
||||
* ... - a list of HCY color values. At least 6 values should be passed (number [0-1])
|
||||
--]]
|
||||
function oUF:HCYColorGradient(...)
|
||||
local relperc, r1, g1, b1, r2, g2, b2 = colorsAndPercent(...)
|
||||
if(not relperc) then
|
||||
return r1, g1, b1
|
||||
end
|
||||
|
||||
local h1, c1, y1 = rgbToHCY(r1, g1, b1)
|
||||
local h2, c2, y2 = rgbToHCY(r2, g2, b2)
|
||||
local c = c1 + (c2 - c1) * relperc
|
||||
local y = y1 + (y2 - y1) * relperc
|
||||
|
||||
if(h1 and h2) then
|
||||
local dh = h2 - h1
|
||||
if(dh < -0.5) then
|
||||
dh = dh + 1
|
||||
elseif(dh > 0.5) then
|
||||
dh = dh - 1
|
||||
end
|
||||
|
||||
return hcyToRGB((h1 + dh * relperc) % 1, c, y)
|
||||
else
|
||||
return hcyToRGB(h1 or h2, c, y)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[ Colors: oUF:ColorGradient(a, b, ...) or frame:ColorGradient(a, b, ...)
|
||||
Used as a proxy to call the proper gradient function depending on the user's preference. If `oUF.useHCYColorGradient` is
|
||||
set to true, `:HCYColorGradient` will be called, else `:RGBColorGradient`.
|
||||
|
||||
* self - the global oUF object or a unit frame
|
||||
* a - value used as numerator to calculate the percentage (number)
|
||||
* b - value used as denominator to calculate the percentage (number)
|
||||
* ... - a list of color values. At least 6 values should be passed (number [0-1])
|
||||
--]]
|
||||
function oUF:ColorGradient(...)
|
||||
return (oUF.useHCYColorGradient and oUF.HCYColorGradient or oUF.RGBColorGradient)(self, ...)
|
||||
end
|
||||
|
||||
oUF.colors = colors
|
||||
oUF.useHCYColorGradient = false
|
||||
|
||||
frame_metatable.__index.colors = colors
|
||||
frame_metatable.__index.ColorGradient = oUF.ColorGradient
|
||||
315
Libraries/oUF/elements/additionalpower.lua
Normal file
315
Libraries/oUF/elements/additionalpower.lua
Normal file
@@ -0,0 +1,315 @@
|
||||
--[[
|
||||
# Element: Additional Power Bar
|
||||
|
||||
Handles the visibility and updating of a status bar that displays the player's additional power, such as Mana for
|
||||
Balance druids.
|
||||
|
||||
## Widget
|
||||
|
||||
AdditionalPower - A `StatusBar` that is used to display the player's additional power.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
.bg - A `Texture` used as a background. Inherits the widget's color.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a StatusBar and doesn't have a texture set.
|
||||
|
||||
## Options
|
||||
|
||||
.frequentUpdates - Indicates whether to use UNIT_POWER_FREQUENT instead UNIT_POWER_UPDATE to update the bar (boolean)
|
||||
.displayPairs - Use to override display pairs. (table)
|
||||
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
|
||||
|
||||
The following options are listed by priority. The first check that returns true decides the color of the bar.
|
||||
|
||||
.colorPower - Use `self.colors.power[token]` to color the bar based on the player's additional power type
|
||||
(boolean)
|
||||
.colorClass - Use `self.colors.class[class]` to color the bar based on unit class. `class` is defined by the
|
||||
second return of [UnitClass](http://wowprogramming.com/docs/api/UnitClass.html) (boolean)
|
||||
.colorSmooth - Use `self.colors.smooth` to color the bar with a smooth gradient based on the player's current
|
||||
additional power percentage (boolean)
|
||||
|
||||
## Sub-Widget Options
|
||||
|
||||
.multiplier - Used to tint the background based on the widget's R, G and B values. Defaults to 1 (number)[0-1]
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local AdditionalPower = CreateFrame('StatusBar', nil, self)
|
||||
AdditionalPower:SetSize(20, 20)
|
||||
AdditionalPower:SetPoint('TOP')
|
||||
AdditionalPower:SetPoint('LEFT')
|
||||
AdditionalPower:SetPoint('RIGHT')
|
||||
|
||||
-- Add a background
|
||||
local Background = AdditionalPower:CreateTexture(nil, 'BACKGROUND')
|
||||
Background:SetAllPoints(AdditionalPower)
|
||||
Background:SetTexture(1, 1, 1, .5)
|
||||
|
||||
-- Register it with oUF
|
||||
AdditionalPower.bg = Background
|
||||
self.AdditionalPower = AdditionalPower
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local _, playerClass = UnitClass('player')
|
||||
|
||||
-- ElvUI block
|
||||
local unpack = unpack
|
||||
local CopyTable = CopyTable
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
local UnitPlayerControlled = UnitPlayerControlled
|
||||
local UnitIsTapDenied = UnitIsTapDenied
|
||||
local UnitThreatSituation = UnitThreatSituation
|
||||
local UnitIsPlayer = UnitIsPlayer
|
||||
local UnitClass = UnitClass
|
||||
local UnitSelectionType = UnitSelectionType
|
||||
local UnitReaction = UnitReaction
|
||||
local UnitPower = UnitPower
|
||||
local UnitPowerMax = UnitPowerMax
|
||||
local UnitIsConnected = UnitIsConnected
|
||||
local UnitHasVehicleUI = UnitHasVehicleUI
|
||||
local UnitPowerType = UnitPowerType
|
||||
-- end block
|
||||
|
||||
-- sourced from FrameXML/AlternatePowerBar.lua
|
||||
local ADDITIONAL_POWER_BAR_NAME = ADDITIONAL_POWER_BAR_NAME or 'MANA'
|
||||
local ADDITIONAL_POWER_BAR_INDEX = ADDITIONAL_POWER_BAR_INDEX or 0
|
||||
local ALT_MANA_BAR_PAIR_DISPLAY_INFO = ALT_MANA_BAR_PAIR_DISPLAY_INFO
|
||||
|
||||
local function UpdateColor(self, event, unit, powerType)
|
||||
if(not (unit and UnitIsUnit(unit, 'player') and powerType == ADDITIONAL_POWER_BAR_NAME)) then return end
|
||||
local element = self.AdditionalPower
|
||||
|
||||
local r, g, b, t
|
||||
if(element.colorPower) then
|
||||
t = self.colors.power[ADDITIONAL_POWER_BAR_INDEX]
|
||||
elseif(element.colorClass) then
|
||||
t = self.colors.class[playerClass]
|
||||
elseif(element.colorSmooth) then
|
||||
r, g, b = self:ColorGradient(element.cur or 1, element.max or 1, unpack(element.smoothGradient or self.colors.smooth))
|
||||
end
|
||||
|
||||
if(t) then
|
||||
r, g, b = t[1], t[2], t[3]
|
||||
end
|
||||
|
||||
if(b) then
|
||||
element:SetStatusBarColor(r, g, b)
|
||||
|
||||
local bg = element.bg
|
||||
if(bg) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Callback: AdditionalPower:PostUpdateColor(r, g, b)
|
||||
Called after the element color has been updated.
|
||||
|
||||
* self - the AdditionalPower element
|
||||
* r - the red component of the used color (number)[0-1]
|
||||
* g - the green component of the used color (number)[0-1]
|
||||
* b - the blue component of the used color (number)[0-1]
|
||||
--]]
|
||||
if(element.PostUpdateColor) then
|
||||
element:PostUpdateColor(r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function Update(self, event, unit, powerType)
|
||||
if(not (unit and UnitIsUnit(unit, 'player') and powerType == ADDITIONAL_POWER_BAR_NAME)) then return end
|
||||
local element = self.AdditionalPower
|
||||
|
||||
--[[ Callback: AdditionalPower:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the AdditionalPower element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local cur, max = UnitPower('player', ADDITIONAL_POWER_BAR_INDEX), UnitPowerMax('player', ADDITIONAL_POWER_BAR_INDEX)
|
||||
element:SetMinMaxValues(0, max)
|
||||
|
||||
element:SetValue(cur)
|
||||
|
||||
element.cur = cur
|
||||
element.max = max
|
||||
|
||||
--[[ Callback: AdditionalPower:PostUpdate(cur, max)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the AdditionalPower element
|
||||
* cur - the current value of the player's additional power (number)
|
||||
* max - the maximum value of the player's additional power (number)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(cur, max, event) -- ElvUI adds event
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: AdditionalPower.Override(self, event, unit, ...)
|
||||
Used to completely override the element's update process.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
(self.AdditionalPower.Override or Update) (self, ...);
|
||||
|
||||
--[[ Override: AdditionalPower.UpdateColor(self, event, unit, ...)
|
||||
Used to completely override the internal function for updating the widgets' colors.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
(self.AdditionalPower.UpdateColor or UpdateColor) (self, ...)
|
||||
end
|
||||
|
||||
local function ElementEnable(self)
|
||||
local element = self.AdditionalPower
|
||||
|
||||
if(element.frequentUpdates) then
|
||||
self:RegisterEvent('UNIT_POWER_FREQUENT', Path)
|
||||
else
|
||||
self:RegisterEvent('UNIT_POWER_UPDATE', Path)
|
||||
end
|
||||
|
||||
self:RegisterEvent('UNIT_MAXPOWER', Path)
|
||||
|
||||
element:Show()
|
||||
|
||||
element.__isEnabled = true
|
||||
|
||||
Path(self, 'ElementEnable', 'player', ADDITIONAL_POWER_BAR_NAME)
|
||||
end
|
||||
|
||||
local function ElementDisable(self)
|
||||
local element = self.AdditionalPower
|
||||
|
||||
self:UnregisterEvent('UNIT_MAXPOWER', Path)
|
||||
self:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
|
||||
self:UnregisterEvent('UNIT_POWER_UPDATE', Path)
|
||||
|
||||
element:Hide()
|
||||
|
||||
element.__isEnabled = false
|
||||
Path(self, 'ElementDisable', 'player', ADDITIONAL_POWER_BAR_NAME)
|
||||
end
|
||||
|
||||
local function Visibility(self, event, unit)
|
||||
local element = self.AdditionalPower
|
||||
local shouldEnable
|
||||
|
||||
if(not UnitHasVehicleUI('player')) then
|
||||
if(UnitPowerMax(unit, ADDITIONAL_POWER_BAR_INDEX) ~= 0) then
|
||||
if(element.displayPairs[playerClass]) then
|
||||
local powerType = UnitPowerType(unit)
|
||||
shouldEnable = element.displayPairs[playerClass][powerType]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local isEnabled = element.__isEnabled
|
||||
|
||||
if(shouldEnable and not isEnabled) then
|
||||
ElementEnable(self)
|
||||
|
||||
--[[ Callback: AdditionalPower:PostVisibility(isVisible)
|
||||
Called after the element's visibility has been changed.
|
||||
|
||||
* self - the AdditionalPower element
|
||||
* isVisible - the current visibility state of the element (boolean)
|
||||
--]]
|
||||
if(element.PostVisibility) then
|
||||
element:PostVisibility(true)
|
||||
end
|
||||
elseif(not shouldEnable and (isEnabled or isEnabled == nil)) then
|
||||
ElementDisable(self)
|
||||
|
||||
if(element.PostVisibility) then
|
||||
element:PostVisibility(false)
|
||||
end
|
||||
elseif(shouldEnable and isEnabled) then
|
||||
Path(self, event, unit, ADDITIONAL_POWER_BAR_NAME)
|
||||
end
|
||||
end
|
||||
|
||||
local function VisibilityPath(self, ...)
|
||||
--[[ Override: AdditionalPower.OverrideVisibility(self, event, unit)
|
||||
Used to completely override the element's visibility update process.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.AdditionalPower.OverrideVisibility or Visibility) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
--[[ Power:SetFrequentUpdates(state, isForced)
|
||||
Used to toggle frequent updates.
|
||||
|
||||
* self - the Power element
|
||||
* state - the desired state (boolean)
|
||||
* isForced - forces the event update even if the state wasn't changed (boolean)
|
||||
--]]
|
||||
local function SetFrequentUpdates(element, state, isForced)
|
||||
if(element.frequentUpdates ~= state or isForced) then
|
||||
element.frequentUpdates = state
|
||||
if(state) then
|
||||
element.__owner:UnregisterEvent('UNIT_POWER_UPDATE', Path)
|
||||
element.__owner:RegisterEvent('UNIT_POWER_FREQUENT', Path)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
|
||||
element.__owner:RegisterEvent('UNIT_POWER_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.AdditionalPower
|
||||
if(element and UnitIsUnit(unit, 'player')) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
element.SetFrequentUpdates = SetFrequentUpdates
|
||||
|
||||
self:RegisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
|
||||
|
||||
if(not element.displayPairs) then
|
||||
element.displayPairs = CopyTable(ALT_MANA_BAR_PAIR_DISPLAY_INFO)
|
||||
end
|
||||
|
||||
if(element:IsObjectType('StatusBar') and not (element:GetStatusBarTexture() or element:GetStatusBarAtlas())) then
|
||||
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.AdditionalPower
|
||||
if(element) then
|
||||
ElementDisable(self)
|
||||
|
||||
self:UnregisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('AdditionalPower', VisibilityPath, Enable, Disable)
|
||||
303
Libraries/oUF/elements/alternativepower.lua
Normal file
303
Libraries/oUF/elements/alternativepower.lua
Normal file
@@ -0,0 +1,303 @@
|
||||
--[[
|
||||
# Element: Alternative Power Bar
|
||||
|
||||
Handles the visibility and updating of a status bar that displays encounter- or quest-related power information, such as
|
||||
the number of hour glass charges during the Murozond encounter in the dungeon End Time.
|
||||
|
||||
## Widget
|
||||
|
||||
AlternativePower - A `StatusBar` used to represent the unit's alternative power.
|
||||
|
||||
## Notes
|
||||
|
||||
If mouse interactivity is enabled for the widget, `OnEnter` and/or `OnLeave` handlers will be set to display a tooltip.
|
||||
A default texture will be applied if the widget is a StatusBar and doesn't have a texture set.
|
||||
|
||||
## Options
|
||||
|
||||
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
|
||||
.considerSelectionInCombatHostile - Indicates whether selection should be considered hostile while the unit is in
|
||||
combat with the player (boolean)
|
||||
|
||||
The following options are listed by priority. The first check that returns true decides the color of the bar.
|
||||
|
||||
.colorThreat - Use `self.colors.threat[threat]` to color the bar based on the unit's threat status. `threat` is
|
||||
defined by the first return of [UnitThreatSituation](https://wow.gamepedia.com/API_UnitThreatSituation) (boolean)
|
||||
.colorPower - Use `self.colors.power[token]` to color the bar based on the unit's alternative power type
|
||||
(boolean)
|
||||
.colorClass - Use `self.colors.class[class]` to color the bar based on unit class. `class` is defined by the
|
||||
second return of [UnitClass](http://wowprogramming.com/docs/api/UnitClass.html) (boolean)
|
||||
.colorClassNPC - Use `self.colors.class[class]` to color the bar if the unit is a NPC (boolean)
|
||||
.colorSelection - Use `self.colors.selection[selection]` to color the bar based on the unit's selection color.
|
||||
`selection` is defined by the return value of Private.unitSelectionType, a wrapper function
|
||||
for [UnitSelectionType](https://wow.gamepedia.com/API_UnitSelectionType) (boolean)
|
||||
.colorReaction - Use `self.colors.reaction[reaction]` to color the bar based on the player's reaction towards the
|
||||
unit. `reaction` is defined by the return value of
|
||||
[UnitReaction](http://wowprogramming.com/docs/api/UnitReaction.html) (boolean)
|
||||
.colorSmooth - Use `self.colors.smooth` to color the bar with a smooth gradient based on the unit's current
|
||||
alternative power percentage (boolean)
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local AlternativePower = CreateFrame('StatusBar', nil, self)
|
||||
AlternativePower:SetHeight(20)
|
||||
AlternativePower:SetPoint('BOTTOM')
|
||||
AlternativePower:SetPoint('LEFT')
|
||||
AlternativePower:SetPoint('RIGHT')
|
||||
|
||||
-- Register with oUF
|
||||
self.AlternativePower = AlternativePower
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local unitSelectionType = Private.unitSelectionType
|
||||
|
||||
-- sourced from FrameXML/UnitPowerBarAlt.lua
|
||||
local ALTERNATE_POWER_INDEX = Enum.PowerType.Alternate or 10
|
||||
local ALTERNATE_POWER_NAME = 'ALTERNATE'
|
||||
local GameTooltip = GameTooltip
|
||||
|
||||
local function updateTooltip(self)
|
||||
if GameTooltip:IsForbidden() then return end
|
||||
|
||||
local name, tooltip = GetUnitPowerBarStringsByID(self.__barID)
|
||||
GameTooltip:SetText(name or '', 1, 1, 1)
|
||||
GameTooltip:AddLine(tooltip or '', nil, nil, nil, true)
|
||||
GameTooltip:Show()
|
||||
end
|
||||
|
||||
local function onEnter(self)
|
||||
if GameTooltip:IsForbidden() or not self:IsVisible() then return end
|
||||
|
||||
GameTooltip:ClearAllPoints()
|
||||
GameTooltip_SetDefaultAnchor(GameTooltip, self)
|
||||
self:UpdateTooltip()
|
||||
end
|
||||
|
||||
local function onLeave()
|
||||
if GameTooltip:IsForbidden() then return end
|
||||
|
||||
GameTooltip:Hide()
|
||||
end
|
||||
|
||||
local function UpdateColor(self, event, unit, powerType)
|
||||
if(self.unit ~= unit or powerType ~= ALTERNATE_POWER_NAME) then return end
|
||||
local element = self.AlternativePower
|
||||
|
||||
local r, g, b, t
|
||||
if(element.colorThreat and not UnitPlayerControlled(unit) and UnitThreatSituation('player', unit)) then
|
||||
t = self.colors.threat[UnitThreatSituation('player', unit)]
|
||||
elseif(element.colorPower) then
|
||||
t = self.colors.power[ALTERNATE_POWER_INDEX]
|
||||
elseif(element.colorClass and UnitIsPlayer(unit))
|
||||
or (element.colorClassNPC and not UnitIsPlayer(unit)) then
|
||||
local _, class = UnitClass(unit)
|
||||
t = self.colors.class[class]
|
||||
elseif(element.colorSelection and unitSelectionType(unit, element.considerSelectionInCombatHostile)) then
|
||||
t = self.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
|
||||
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
|
||||
t = self.colors.reaction[UnitReaction(unit, 'player')]
|
||||
elseif(element.colorSmooth) then
|
||||
local adjust = 0 - (element.min or 0)
|
||||
r, g, b = self:ColorGradient((element.cur or 1) + adjust, (element.max or 1) + adjust, unpack(element.smoothGradient or self.colors.smooth))
|
||||
end
|
||||
|
||||
if(t) then
|
||||
r, g, b = t[1], t[2], t[3]
|
||||
end
|
||||
|
||||
if(b) then
|
||||
element:SetStatusBarColor(r, g, b)
|
||||
|
||||
local bg = element.bg
|
||||
if(bg) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Callback: AlternativePower:PostUpdateColor(unit, r, g, b)
|
||||
Called after the element color has been updated.
|
||||
|
||||
* self - the AlternativePower element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* r - the red component of the used color (number)[0-1]
|
||||
* g - the green component of the used color (number)[0-1]
|
||||
* b - the blue component of the used color (number)[0-1]
|
||||
--]]
|
||||
if(element.PostUpdateColor) then
|
||||
element:PostUpdateColor(unit, r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function Update(self, event, unit, powerType)
|
||||
if(self.unit ~= unit or powerType ~= ALTERNATE_POWER_NAME) then return end
|
||||
local element = self.AlternativePower
|
||||
|
||||
--[[ Callback: AlternativePower:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the AlternativePower element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local min, max, cur = 0
|
||||
local barInfo = element.__barInfo
|
||||
if(barInfo) then
|
||||
cur = UnitPower(unit, ALTERNATE_POWER_INDEX)
|
||||
max = UnitPowerMax(unit, ALTERNATE_POWER_INDEX)
|
||||
|
||||
if barInfo.minPower then
|
||||
min = barInfo.minPower
|
||||
end
|
||||
|
||||
element:SetMinMaxValues(min, max)
|
||||
element:SetValue(cur)
|
||||
end
|
||||
|
||||
element.cur = cur
|
||||
element.min = min
|
||||
element.max = max
|
||||
|
||||
--[[ Callback: AlternativePower:PostUpdate(unit, cur, min, max)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the AlternativePower element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* cur - the current value of the unit's alternative power (number?)
|
||||
* min - the minimum value of the unit's alternative power (number?)
|
||||
* max - the maximum value of the unit's alternative power (number?)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(unit, cur, min, max)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: AlternativePower.Override(self, event, unit, ...)
|
||||
Used to completely override the element's update process.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
(self.AlternativePower.Override or Update) (self, ...);
|
||||
|
||||
--[[ Override: AlternativePower.UpdateColor(self, event, unit, ...)
|
||||
Used to completely override the internal function for updating the widgets' colors.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
(self.AlternativePower.UpdateColor or UpdateColor) (self, ...)
|
||||
end
|
||||
|
||||
local function Visibility(self, event, unit)
|
||||
if(unit ~= self.unit) then return end
|
||||
local element = self.AlternativePower
|
||||
|
||||
local barID = UnitPowerBarID(unit)
|
||||
local barInfo = GetUnitPowerBarInfoByID(barID)
|
||||
element.__barID = barID
|
||||
element.__barInfo = barInfo
|
||||
if(barInfo and (barInfo.showOnRaid and (UnitInParty(unit) or UnitInRaid(unit))
|
||||
or not barInfo.hideFromOthers
|
||||
or UnitIsUnit(unit, 'player')))
|
||||
then
|
||||
self:RegisterEvent('UNIT_POWER_UPDATE', Path)
|
||||
self:RegisterEvent('UNIT_MAXPOWER', Path)
|
||||
|
||||
element:Show()
|
||||
Path(self, event, unit, ALTERNATE_POWER_NAME)
|
||||
else
|
||||
self:UnregisterEvent('UNIT_POWER_UPDATE', Path)
|
||||
self:UnregisterEvent('UNIT_MAXPOWER', Path)
|
||||
|
||||
element:Hide()
|
||||
Path(self, event, unit, ALTERNATE_POWER_NAME)
|
||||
end
|
||||
end
|
||||
|
||||
local function VisibilityPath(self, ...)
|
||||
--[[ Override: AlternativePower.OverrideVisibility(self, event, unit)
|
||||
Used to completely override the element's visibility update process.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
return (self.AlternativePower.OverrideVisibility or Visibility) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.AlternativePower
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_POWER_BAR_SHOW', VisibilityPath)
|
||||
self:RegisterEvent('UNIT_POWER_BAR_HIDE', VisibilityPath)
|
||||
|
||||
if(element:IsObjectType('StatusBar') and not (element:GetStatusBarTexture() or element:GetStatusBarAtlas())) then
|
||||
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
|
||||
if(element:IsMouseEnabled()) then
|
||||
if(not element:GetScript('OnEnter')) then
|
||||
element:SetScript('OnEnter', onEnter)
|
||||
end
|
||||
|
||||
if(not element:GetScript('OnLeave')) then
|
||||
element:SetScript('OnLeave', onLeave)
|
||||
end
|
||||
|
||||
--[[ Override: AlternativePower:UpdateTooltip()
|
||||
Called when the mouse is over the widget. Used to populate its tooltip.
|
||||
|
||||
* self - the AlternativePower element
|
||||
--]]
|
||||
if(not element.UpdateTooltip) then
|
||||
element.UpdateTooltip = updateTooltip
|
||||
end
|
||||
end
|
||||
|
||||
if(unit == 'player') then
|
||||
PlayerPowerBarAlt:UnregisterEvent('UNIT_POWER_BAR_SHOW')
|
||||
PlayerPowerBarAlt:UnregisterEvent('UNIT_POWER_BAR_HIDE')
|
||||
PlayerPowerBarAlt:UnregisterEvent('PLAYER_ENTERING_WORLD')
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self, unit)
|
||||
local element = self.AlternativePower
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_POWER_BAR_SHOW', VisibilityPath)
|
||||
self:UnregisterEvent('UNIT_POWER_BAR_HIDE', VisibilityPath)
|
||||
|
||||
if(unit == 'player') then
|
||||
PlayerPowerBarAlt:RegisterEvent('UNIT_POWER_BAR_SHOW')
|
||||
PlayerPowerBarAlt:RegisterEvent('UNIT_POWER_BAR_HIDE')
|
||||
PlayerPowerBarAlt:RegisterEvent('PLAYER_ENTERING_WORLD')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('AlternativePower', VisibilityPath, Enable, Disable)
|
||||
99
Libraries/oUF/elements/assistantindicator.lua
Normal file
99
Libraries/oUF/elements/assistantindicator.lua
Normal file
@@ -0,0 +1,99 @@
|
||||
--[[
|
||||
# Element: Assistant Indicator
|
||||
|
||||
Toggles the visibility of an indicator based on the unit's raid assistant status.
|
||||
|
||||
## Widget
|
||||
|
||||
AssistantIndicator - Any UI widget.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local AssistantIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
AssistantIndicator:SetSize(16, 16)
|
||||
AssistantIndicator:SetPoint('TOP', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.AssistantIndicator = AssistantIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.AssistantIndicator
|
||||
local unit = self.unit
|
||||
|
||||
--[[ Callback: AssistantIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the AssistantIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local isAssistant = UnitInRaid(unit) and UnitIsGroupAssistant(unit) and not UnitIsGroupLeader(unit)
|
||||
if(isAssistant) then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: AssistantIndicator:PostUpdate(isAssistant)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the AssistantIndicator element
|
||||
* isAssistant - indicates whether the unit is a raid assistant (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(isAssistant)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: AssistantIndicator.Override(self, event, ...)
|
||||
Used to completely override the element's update process.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event (string)
|
||||
--]]
|
||||
return (self.AssistantIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.AssistantIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('GROUP_ROSTER_UPDATE', Path, true)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\GroupFrame\UI-Group-AssistantIcon]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.AssistantIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('GROUP_ROSTER_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('AssistantIndicator', Path, Enable, Disable)
|
||||
655
Libraries/oUF/elements/auras.lua
Normal file
655
Libraries/oUF/elements/auras.lua
Normal file
@@ -0,0 +1,655 @@
|
||||
--[[
|
||||
# Element: Auras
|
||||
|
||||
Handles creation and updating of aura icons.
|
||||
|
||||
## Widget
|
||||
|
||||
Auras - A Frame to hold `Button`s representing both buffs and debuffs.
|
||||
Buffs - A Frame to hold `Button`s representing buffs.
|
||||
Debuffs - A Frame to hold `Button`s representing debuffs.
|
||||
|
||||
## Notes
|
||||
|
||||
At least one of the above widgets must be present for the element to work.
|
||||
|
||||
## Options
|
||||
|
||||
.disableMouse - Disables mouse events (boolean)
|
||||
.disableCooldown - Disables the cooldown spiral (boolean)
|
||||
.size - Aura icon size. Defaults to 16 (number)
|
||||
.onlyShowPlayer - Shows only auras created by player/vehicle (boolean)
|
||||
.showStealableBuffs - Displays the stealable texture on buffs that can be stolen (boolean)
|
||||
.spacing - Spacing between each icon. Defaults to 0 (number)
|
||||
.['spacing-x'] - Horizontal spacing between each icon. Takes priority over `spacing` (number)
|
||||
.['spacing-y'] - Vertical spacing between each icon. Takes priority over `spacing` (number)
|
||||
.['growth-x'] - Horizontal growth direction. Defaults to 'RIGHT' (string)
|
||||
.['growth-y'] - Vertical growth direction. Defaults to 'UP' (string)
|
||||
.initialAnchor - Anchor point for the icons. Defaults to 'BOTTOMLEFT' (string)
|
||||
.filter - Custom filter list for auras to display. Defaults to 'HELPFUL' for buffs and 'HARMFUL' for
|
||||
debuffs (string)
|
||||
.tooltipAnchor - Anchor point for the tooltip. Defaults to 'ANCHOR_BOTTOMRIGHT', however, if a frame has anchoring
|
||||
restrictions it will be set to 'ANCHOR_CURSOR' (string)
|
||||
|
||||
## Options Auras
|
||||
|
||||
.numBuffs - The maximum number of buffs to display. Defaults to 32 (number)
|
||||
.numDebuffs - The maximum number of debuffs to display. Defaults to 40 (number)
|
||||
.numTotal - The maximum number of auras to display. Prioritizes buffs over debuffs. Defaults to the sum of
|
||||
.numBuffs and .numDebuffs (number)
|
||||
.gap - Controls the creation of an invisible icon between buffs and debuffs. Defaults to false (boolean)
|
||||
.buffFilter - Custom filter list for buffs to display. Takes priority over `filter` (string)
|
||||
.debuffFilter - Custom filter list for debuffs to display. Takes priority over `filter` (string)
|
||||
|
||||
## Options Buffs
|
||||
|
||||
.num - Number of buffs to display. Defaults to 32 (number)
|
||||
|
||||
## Options Debuffs
|
||||
|
||||
.num - Number of debuffs to display. Defaults to 40 (number)
|
||||
|
||||
## Attributes
|
||||
|
||||
button.caster - the unit who cast the aura (string)
|
||||
button.filter - the filter list used to determine the visibility of the aura (string)
|
||||
button.isDebuff - indicates if the button holds a debuff (boolean)
|
||||
button.isPlayer - indicates if the aura caster is the player or their vehicle (boolean)
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local Buffs = CreateFrame('Frame', nil, self)
|
||||
Buffs:SetPoint('RIGHT', self, 'LEFT')
|
||||
Buffs:SetSize(16 * 2, 16 * 16)
|
||||
|
||||
-- Register with oUF
|
||||
self.Buffs = Buffs
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local VISIBLE = 1
|
||||
local HIDDEN = 0
|
||||
|
||||
-- ElvUI changed block
|
||||
local CREATED = 2
|
||||
|
||||
local pcall = pcall
|
||||
local tinsert = tinsert
|
||||
local CreateFrame = CreateFrame
|
||||
local GetSpellInfo = GetSpellInfo
|
||||
local UnitAura = UnitAura
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
local GameTooltip = GameTooltip
|
||||
local floor, min = math.floor, math.min
|
||||
-- end block
|
||||
|
||||
-- ElvUI adds IsForbidden checks
|
||||
local function UpdateTooltip(self)
|
||||
if GameTooltip:IsForbidden() then return end
|
||||
|
||||
GameTooltip:SetUnitAura(self:GetParent().__owner.unit, self:GetID(), self.filter)
|
||||
end
|
||||
|
||||
local function onEnter(self)
|
||||
if GameTooltip:IsForbidden() or not self:IsVisible() then return end
|
||||
|
||||
GameTooltip:SetOwner(self, self:GetParent().tooltipAnchor)
|
||||
self:UpdateTooltip()
|
||||
end
|
||||
|
||||
local function onLeave()
|
||||
if GameTooltip:IsForbidden() then return end
|
||||
|
||||
GameTooltip:Hide()
|
||||
end
|
||||
|
||||
local function createAuraIcon(element, index)
|
||||
local button = CreateFrame('Button', element:GetName() .. 'Button' .. index, element, "BackdropTemplate")
|
||||
button:RegisterForClicks('RightButtonUp')
|
||||
|
||||
local cd = CreateFrame('Cooldown', '$parentCooldown', button, 'CooldownFrameTemplate')
|
||||
cd:SetAllPoints()
|
||||
|
||||
local icon = button:CreateTexture(nil, 'BORDER')
|
||||
icon:SetAllPoints()
|
||||
|
||||
local countFrame = CreateFrame('Frame', nil, button)
|
||||
countFrame:SetAllPoints(button)
|
||||
countFrame:SetFrameLevel(cd:GetFrameLevel() + 1)
|
||||
|
||||
local count = countFrame:CreateFontString(nil, 'OVERLAY', 'NumberFontNormal')
|
||||
count:SetPoint('BOTTOMRIGHT', countFrame, 'BOTTOMRIGHT', -1, 0)
|
||||
|
||||
local overlay = button:CreateTexture(nil, 'OVERLAY')
|
||||
overlay:SetTexture([[Interface\Buttons\UI-Debuff-Overlays]])
|
||||
overlay:SetAllPoints()
|
||||
overlay:SetTexCoord(.296875, .5703125, 0, .515625)
|
||||
button.overlay = overlay
|
||||
|
||||
local stealable = button:CreateTexture(nil, 'OVERLAY')
|
||||
stealable:SetTexture([[Interface\TargetingFrame\UI-TargetingFrame-Stealable]])
|
||||
stealable:SetPoint('TOPLEFT', -3, 3)
|
||||
stealable:SetPoint('BOTTOMRIGHT', 3, -3)
|
||||
stealable:SetBlendMode('ADD')
|
||||
button.stealable = stealable
|
||||
|
||||
button.UpdateTooltip = UpdateTooltip
|
||||
button:SetScript('OnEnter', onEnter)
|
||||
button:SetScript('OnLeave', onLeave)
|
||||
|
||||
button.icon = icon
|
||||
button.count = count
|
||||
button.cd = cd
|
||||
|
||||
--[[ Callback: Auras:PostCreateIcon(button)
|
||||
Called after a new aura button has been created.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* button - the newly created aura button (Button)
|
||||
--]]
|
||||
if(element.PostCreateIcon) then element:PostCreateIcon(button) end
|
||||
|
||||
return button
|
||||
end
|
||||
|
||||
local function customFilter(element, unit, button, name)
|
||||
if((element.onlyShowPlayer and button.isPlayer) or (not element.onlyShowPlayer and name)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function updateIcon(element, unit, index, offset, filter, isDebuff, visible)
|
||||
local name, texture, count, debuffType, duration, expiration, caster, isStealable,
|
||||
nameplateShowSelf, spellID, canApply, isBossDebuff, casterIsPlayer, nameplateShowAll,
|
||||
timeMod, effect1, effect2, effect3 = UnitAura(unit, index, filter)
|
||||
|
||||
-- ElvUI changed block
|
||||
if element.forceShow or element.forceCreate then
|
||||
spellID = 47540
|
||||
name, _, texture = GetSpellInfo(spellID)
|
||||
if element.forceShow then
|
||||
count, debuffType, duration, expiration, caster, isStealable, nameplateShowSelf, isBossDebuff = 5, "Magic", 0, 60, "player", nil, nil, nil
|
||||
end
|
||||
end
|
||||
|
||||
if isStealable then
|
||||
element.hasStealable = true -- for Style Filters
|
||||
end
|
||||
-- end Block
|
||||
|
||||
if(name) then
|
||||
local position = visible + offset + 1
|
||||
local button = element[position]
|
||||
if(not button) then
|
||||
--[[ Override: Auras:CreateIcon(position)
|
||||
Used to create the aura button at a given position.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* position - the position at which the aura button is to be created (number)
|
||||
|
||||
## Returns
|
||||
|
||||
* button - the button used to represent the aura (Button)
|
||||
--]]
|
||||
button = (element.CreateIcon or createAuraIcon) (element, position)
|
||||
|
||||
tinsert(element, button)
|
||||
element.createdIcons = element.createdIcons + 1
|
||||
end
|
||||
|
||||
button.caster = caster
|
||||
button.filter = filter
|
||||
button.isDebuff = isDebuff
|
||||
button.isPlayer = caster == 'player' or caster == 'vehicle'
|
||||
|
||||
--[[ Override: Auras:CustomFilter(unit, button, ...)
|
||||
Defines a custom filter that controls if the aura button should be shown.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* unit - the unit on which the aura is cast (string)
|
||||
* button - the button displaying the aura (Button)
|
||||
* ... - the return values from [UnitAura](http://wowprogramming.com/docs/api/UnitAura.html)
|
||||
|
||||
## Returns
|
||||
|
||||
* show - indicates whether the aura button should be shown (boolean)
|
||||
--]]
|
||||
|
||||
-- ElvUI changed block
|
||||
local show = not element.forceCreate
|
||||
if not (element.forceShow or element.forceCreate) then
|
||||
show = (element.CustomFilter or customFilter) (element, unit, button, name, texture,
|
||||
count, debuffType, duration, expiration, caster, isStealable, nameplateShowSelf, spellID,
|
||||
canApply, isBossDebuff, casterIsPlayer, nameplateShowAll,timeMod, effect1, effect2, effect3)
|
||||
end
|
||||
-- end block
|
||||
|
||||
if(show) then
|
||||
-- We might want to consider delaying the creation of an actual cooldown
|
||||
-- object to this point, but I think that will just make things needlessly
|
||||
-- complicated.
|
||||
if(button.cd and not element.disableCooldown) then
|
||||
if(duration and duration > 0) then
|
||||
button.cd:SetCooldown(expiration - duration, duration)
|
||||
button.cd:Show()
|
||||
else
|
||||
button.cd:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
if(button.overlay) then
|
||||
if((isDebuff and element.showDebuffType) or (not isDebuff and element.showBuffType) or element.showType) then
|
||||
local color = element.__owner.colors.debuff[debuffType] or element.__owner.colors.debuff.none
|
||||
|
||||
button.overlay:SetVertexColor(color[1], color[2], color[3])
|
||||
button.overlay:Show()
|
||||
else
|
||||
button.overlay:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
if(button.stealable) then
|
||||
if(not isDebuff and isStealable and element.showStealableBuffs and not UnitIsUnit('player', unit)) then
|
||||
button.stealable:Show()
|
||||
else
|
||||
button.stealable:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
if(button.icon) then button.icon:SetTexture(texture) end
|
||||
if(button.count) then button.count:SetText(count > 1 and count) end
|
||||
|
||||
local size = element.size or 16
|
||||
button:SetSize(size, size)
|
||||
|
||||
button:EnableMouse(not element.disableMouse)
|
||||
button:SetID(index)
|
||||
button:Show()
|
||||
|
||||
--[[ Callback: Auras:PostUpdateIcon(unit, button, index, position)
|
||||
Called after the aura button has been updated.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* unit - the unit on which the aura is cast (string)
|
||||
* button - the updated aura button (Button)
|
||||
* index - the index of the aura (number)
|
||||
* position - the actual position of the aura button (number)
|
||||
* duration - the aura duration in seconds (number?)
|
||||
* expiration - the point in time when the aura will expire. Comparable to GetTime() (number)
|
||||
* debuffType - the debuff type of the aura (string?)['Curse', 'Disease', 'Magic', 'Poison']
|
||||
* isStealable - whether the aura can be stolen or purged (boolean)
|
||||
--]]
|
||||
if(element.PostUpdateIcon) then
|
||||
element:PostUpdateIcon(unit, button, index, position, duration, expiration, debuffType, isStealable)
|
||||
end
|
||||
|
||||
return VISIBLE
|
||||
-- ElvUI changed block
|
||||
elseif element.forceCreate then
|
||||
local size = element.size or 16
|
||||
button:SetSize(size, size)
|
||||
button:Hide()
|
||||
|
||||
if element.PostUpdateIcon then
|
||||
element:PostUpdateIcon(unit, button, index, position, duration, expiration, debuffType, isStealable)
|
||||
end
|
||||
|
||||
return CREATED
|
||||
-- end block
|
||||
else
|
||||
return HIDDEN
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function SetPosition(element, from, to)
|
||||
local sizex = (element.size or 16) + (element['spacing-x'] or element.spacing or 0)
|
||||
local sizey = (element.size or 16) + (element['spacing-y'] or element.spacing or 0)
|
||||
local anchor = element.initialAnchor or 'BOTTOMLEFT'
|
||||
local growthx = (element['growth-x'] == 'LEFT' and -1) or 1
|
||||
local growthy = (element['growth-y'] == 'DOWN' and -1) or 1
|
||||
local cols = floor(element:GetWidth() / sizex + 0.5)
|
||||
|
||||
for i = from, to do
|
||||
local button = element[i]
|
||||
|
||||
-- Bail out if the to range is out of scope.
|
||||
if(not button) then break end
|
||||
local col = (i - 1) % cols
|
||||
local row = floor((i - 1) / cols)
|
||||
|
||||
button:ClearAllPoints()
|
||||
button:SetPoint(anchor, element, anchor, col * sizex * growthx, row * sizey * growthy)
|
||||
end
|
||||
end
|
||||
|
||||
local function filterIcons(element, unit, filter, limit, isDebuff, offset, dontHide)
|
||||
if(not offset) then offset = 0 end
|
||||
local index = 1
|
||||
local visible = 0
|
||||
local hidden = 0
|
||||
local created = 0 -- ElvUI
|
||||
element.hasStealable = nil -- ElvUI
|
||||
|
||||
while(visible < limit) do
|
||||
local result = updateIcon(element, unit, index, offset, filter, isDebuff, visible)
|
||||
if(not result) then
|
||||
break
|
||||
elseif(result == VISIBLE) then
|
||||
visible = visible + 1
|
||||
elseif(result == HIDDEN) then
|
||||
hidden = hidden + 1
|
||||
-- ElvUI changed block
|
||||
elseif result == CREATED then
|
||||
visible = visible + 1
|
||||
created = created + 1
|
||||
-- end block
|
||||
end
|
||||
|
||||
index = index + 1
|
||||
end
|
||||
|
||||
visible = visible - created -- ElvUI changed
|
||||
|
||||
if(not dontHide) then
|
||||
for i = visible + offset + 1, #element do
|
||||
element[i]:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
return visible, hidden
|
||||
end
|
||||
|
||||
local function UpdateAuras(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local auras = self.Auras
|
||||
if(auras) then
|
||||
--[[ Callback: Auras:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(auras.PreUpdate) then auras:PreUpdate(unit) end
|
||||
|
||||
local numBuffs = auras.numBuffs or 32
|
||||
local numDebuffs = auras.numDebuffs or 40
|
||||
local max = auras.numTotal or numBuffs + numDebuffs
|
||||
|
||||
local visibleBuffs = filterIcons(auras, unit, auras.buffFilter or auras.filter or 'HELPFUL', min(numBuffs, max), nil, 0, true)
|
||||
|
||||
local hasGap
|
||||
if(visibleBuffs ~= 0 and auras.gap) then
|
||||
hasGap = true
|
||||
visibleBuffs = visibleBuffs + 1
|
||||
|
||||
local button = auras[visibleBuffs]
|
||||
if(not button) then
|
||||
button = (auras.CreateIcon or createAuraIcon) (auras, visibleBuffs)
|
||||
tinsert(auras, button)
|
||||
auras.createdIcons = auras.createdIcons + 1
|
||||
end
|
||||
|
||||
-- Prevent the button from displaying anything.
|
||||
if(button.cd) then button.cd:Hide() end
|
||||
if(button.icon) then button.icon:SetTexture() end
|
||||
if(button.overlay) then button.overlay:Hide() end
|
||||
if(button.stealable) then button.stealable:Hide() end
|
||||
if(button.count) then button.count:SetText() end
|
||||
|
||||
button:EnableMouse(false)
|
||||
button:Show()
|
||||
|
||||
--[[ Callback: Auras:PostUpdateGapIcon(unit, gapButton, visibleBuffs)
|
||||
Called after an invisible aura button has been created. Only used by Auras when the `gap` option is enabled.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* unit - the unit that has the invisible aura button (string)
|
||||
* gapButton - the invisible aura button (Button)
|
||||
* visibleBuffs - the number of currently visible aura buttons (number)
|
||||
--]]
|
||||
if(auras.PostUpdateGapIcon) then
|
||||
auras:PostUpdateGapIcon(unit, button, visibleBuffs)
|
||||
end
|
||||
end
|
||||
|
||||
local visibleDebuffs = filterIcons(auras, unit, auras.debuffFilter or auras.filter or 'HARMFUL', min(numDebuffs, max - visibleBuffs), true, visibleBuffs)
|
||||
auras.visibleDebuffs = visibleDebuffs
|
||||
|
||||
if(hasGap and visibleDebuffs == 0) then
|
||||
auras[visibleBuffs]:Hide()
|
||||
visibleBuffs = visibleBuffs - 1
|
||||
end
|
||||
|
||||
auras.visibleBuffs = visibleBuffs
|
||||
auras.visibleAuras = auras.visibleBuffs + auras.visibleDebuffs
|
||||
|
||||
local fromRange, toRange
|
||||
--[[ Callback: Auras:PreSetPosition(max)
|
||||
Called before the aura buttons have been (re-)anchored.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* max - the maximum possible number of aura buttons (number)
|
||||
|
||||
## Returns
|
||||
|
||||
* from - the offset of the first aura button to be (re-)anchored (number)
|
||||
* to - the offset of the last aura button to be (re-)anchored (number)
|
||||
--]]
|
||||
if(auras.PreSetPosition) then
|
||||
fromRange, toRange = auras:PreSetPosition(max)
|
||||
end
|
||||
|
||||
if(fromRange or auras.createdIcons > auras.anchoredIcons) then
|
||||
--[[ Override: Auras:SetPosition(from, to)
|
||||
Used to (re-)anchor the aura buttons.
|
||||
Called when new aura buttons have been created or if :PreSetPosition is defined.
|
||||
|
||||
* self - the widget that holds the aura buttons
|
||||
* from - the offset of the first aura button to be (re-)anchored (number)
|
||||
* to - the offset of the last aura button to be (re-)anchored (number)
|
||||
--]]
|
||||
(auras.SetPosition or SetPosition) (auras, fromRange or auras.anchoredIcons + 1, toRange or auras.createdIcons)
|
||||
auras.anchoredIcons = auras.createdIcons
|
||||
end
|
||||
|
||||
--[[ Callback: Auras:PostUpdate(unit)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the widget holding the aura buttons
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(auras.PostUpdate) then auras:PostUpdate(unit) end
|
||||
end
|
||||
|
||||
local buffs = self.Buffs
|
||||
if(buffs) then
|
||||
if(buffs.PreUpdate) then buffs:PreUpdate(unit) end
|
||||
|
||||
local numBuffs = buffs.num or 32
|
||||
local visibleBuffs = filterIcons(buffs, unit, buffs.filter or 'HELPFUL', numBuffs)
|
||||
buffs.visibleBuffs = visibleBuffs
|
||||
|
||||
local fromRange, toRange
|
||||
if(buffs.PreSetPosition) then
|
||||
fromRange, toRange = buffs:PreSetPosition(numBuffs)
|
||||
end
|
||||
|
||||
if(fromRange or buffs.createdIcons > buffs.anchoredIcons) then
|
||||
(buffs.SetPosition or SetPosition) (buffs, fromRange or buffs.anchoredIcons + 1, toRange or buffs.createdIcons)
|
||||
buffs.anchoredIcons = buffs.createdIcons
|
||||
end
|
||||
|
||||
if(buffs.PostUpdate) then buffs:PostUpdate(unit) end
|
||||
end
|
||||
|
||||
local debuffs = self.Debuffs
|
||||
if(debuffs) then
|
||||
if(debuffs.PreUpdate) then debuffs:PreUpdate(unit) end
|
||||
|
||||
local numDebuffs = debuffs.num or 40
|
||||
local visibleDebuffs = filterIcons(debuffs, unit, debuffs.filter or 'HARMFUL', numDebuffs, true)
|
||||
debuffs.visibleDebuffs = visibleDebuffs
|
||||
|
||||
local fromRange, toRange
|
||||
if(debuffs.PreSetPosition) then
|
||||
fromRange, toRange = debuffs:PreSetPosition(numDebuffs)
|
||||
end
|
||||
|
||||
if(fromRange or debuffs.createdIcons > debuffs.anchoredIcons) then
|
||||
(debuffs.SetPosition or SetPosition) (debuffs, fromRange or debuffs.anchoredIcons + 1, toRange or debuffs.createdIcons)
|
||||
debuffs.anchoredIcons = debuffs.createdIcons
|
||||
end
|
||||
|
||||
if(debuffs.PostUpdate) then debuffs:PostUpdate(unit) end
|
||||
end
|
||||
end
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if (self.isForced and event ~= 'ElvUI_UpdateAllElements') or (self.unit ~= unit) then return end -- ElvUI changed
|
||||
|
||||
-- Assume no event means someone wants to re-anchor things. This is usually done by UpdateAllElements and :ForceUpdate.
|
||||
if not event or event == 'ForceUpdate' or event == 'ElvUI_UpdateAllElements' then -- ElvUI changed
|
||||
if self.Buffs then self.Buffs.anchoredIcons = 0 end
|
||||
if self.Debuffs then self.Debuffs.anchoredIcons = 0 end
|
||||
if self.Auras then self.Auras.anchoredIcons = 0 end
|
||||
end
|
||||
|
||||
UpdateAuras(self, event, unit)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Update(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
-- ElvUI changed block
|
||||
local onUpdateElapsed, onUpdateWait = 0, 0.25
|
||||
local function onUpdateAuras(self, elapsed)
|
||||
if onUpdateElapsed > onUpdateWait then
|
||||
Update(self.__owner, 'OnUpdate', self.__owner.unit)
|
||||
|
||||
onUpdateElapsed = 0
|
||||
else
|
||||
onUpdateElapsed = onUpdateElapsed + elapsed
|
||||
end
|
||||
end
|
||||
|
||||
local function SetAuraUpdateSpeed(self, state)
|
||||
onUpdateWait = state
|
||||
end
|
||||
|
||||
local function SetAuraUpdateMethod(self, state, force)
|
||||
if self.effectiveAura ~= state or force then
|
||||
self.effectiveAura = state
|
||||
|
||||
if state then
|
||||
self.updateAurasFrame:SetScript('OnUpdate', onUpdateAuras)
|
||||
self:UnregisterEvent('UNIT_AURA', UpdateAuras)
|
||||
else
|
||||
self.updateAurasFrame:SetScript('OnUpdate', nil)
|
||||
self:RegisterEvent('UNIT_AURA', UpdateAuras)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- end block
|
||||
|
||||
local function Enable(self)
|
||||
-- ElvUI changed block
|
||||
if not self.updateAurasFrame then
|
||||
self.updateAurasFrame = CreateFrame('Frame', nil, self)
|
||||
self.updateAurasFrame.__owner = self
|
||||
end
|
||||
-- end block
|
||||
|
||||
if(self.Buffs or self.Debuffs or self.Auras) then
|
||||
-- ElvUI changed block
|
||||
self.SetAuraUpdateSpeed = SetAuraUpdateSpeed
|
||||
self.SetAuraUpdateMethod = SetAuraUpdateMethod
|
||||
SetAuraUpdateMethod(self, self.effectiveAura, true)
|
||||
-- end block
|
||||
|
||||
local buffs = self.Buffs
|
||||
if(buffs) then
|
||||
buffs.__owner = self
|
||||
buffs.ForceUpdate = ForceUpdate
|
||||
|
||||
buffs.createdIcons = buffs.createdIcons or 0
|
||||
buffs.anchoredIcons = 0
|
||||
|
||||
-- Avoid parenting GameTooltip to frames with anchoring restrictions,
|
||||
-- otherwise it'll inherit said restrictions which will cause issues
|
||||
-- with its further positioning, clamping, etc
|
||||
if(not pcall(self.GetCenter, self)) then
|
||||
buffs.tooltipAnchor = 'ANCHOR_CURSOR'
|
||||
else
|
||||
buffs.tooltipAnchor = buffs.tooltipAnchor or 'ANCHOR_BOTTOMRIGHT'
|
||||
end
|
||||
|
||||
buffs:Show()
|
||||
end
|
||||
|
||||
local debuffs = self.Debuffs
|
||||
if(debuffs) then
|
||||
debuffs.__owner = self
|
||||
debuffs.ForceUpdate = ForceUpdate
|
||||
|
||||
debuffs.createdIcons = debuffs.createdIcons or 0
|
||||
debuffs.anchoredIcons = 0
|
||||
|
||||
-- Avoid parenting GameTooltip to frames with anchoring restrictions,
|
||||
-- otherwise it'll inherit said restrictions which will cause issues
|
||||
-- with its further positioning, clamping, etc
|
||||
if(not pcall(self.GetCenter, self)) then
|
||||
debuffs.tooltipAnchor = 'ANCHOR_CURSOR'
|
||||
else
|
||||
debuffs.tooltipAnchor = debuffs.tooltipAnchor or 'ANCHOR_BOTTOMRIGHT'
|
||||
end
|
||||
|
||||
debuffs:Show()
|
||||
end
|
||||
|
||||
local auras = self.Auras
|
||||
if(auras) then
|
||||
auras.__owner = self
|
||||
auras.ForceUpdate = ForceUpdate
|
||||
|
||||
auras.createdIcons = auras.createdIcons or 0
|
||||
auras.anchoredIcons = 0
|
||||
|
||||
-- Avoid parenting GameTooltip to frames with anchoring restrictions,
|
||||
-- otherwise it'll inherit said restrictions which will cause issues
|
||||
-- with its further positioning, clamping, etc
|
||||
if(not pcall(self.GetCenter, self)) then
|
||||
auras.tooltipAnchor = 'ANCHOR_CURSOR'
|
||||
else
|
||||
auras.tooltipAnchor = auras.tooltipAnchor or 'ANCHOR_BOTTOMRIGHT'
|
||||
end
|
||||
|
||||
auras:Show()
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
-- ElvUI changed block
|
||||
if self.updateAurasFrame then
|
||||
self.updateAurasFrame:SetScript('OnUpdate', nil)
|
||||
end
|
||||
-- end block
|
||||
|
||||
if(self.Buffs or self.Debuffs or self.Auras) then
|
||||
self:UnregisterEvent('UNIT_AURA', UpdateAuras)
|
||||
|
||||
if(self.Buffs) then self.Buffs:Hide() end
|
||||
if(self.Debuffs) then self.Debuffs:Hide() end
|
||||
if(self.Auras) then self.Auras:Hide() end
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Auras', Update, Enable, Disable)
|
||||
518
Libraries/oUF/elements/castbar.lua
Normal file
518
Libraries/oUF/elements/castbar.lua
Normal file
@@ -0,0 +1,518 @@
|
||||
--[[
|
||||
# Element: Castbar
|
||||
|
||||
Handles the visibility and updating of spell castbars.
|
||||
|
||||
## Widget
|
||||
|
||||
Castbar - A `StatusBar` to represent spell cast/channel progress.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
.Icon - A `Texture` to represent spell icon.
|
||||
.SafeZone - A `Texture` to represent latency.
|
||||
.Shield - A `Texture` to represent if it's possible to interrupt or spell steal.
|
||||
.Spark - A `Texture` to represent the castbar's edge.
|
||||
.Text - A `FontString` to represent spell name.
|
||||
.Time - A `FontString` to represent spell duration.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied to the StatusBar and Texture widgets if they don't have a texture or a color set.
|
||||
|
||||
## Options
|
||||
|
||||
.timeToHold - Indicates for how many seconds the castbar should be visible after a _FAILED or _INTERRUPTED
|
||||
event. Defaults to 0 (number)
|
||||
.hideTradeSkills - Makes the element ignore casts related to crafting professions (boolean)
|
||||
|
||||
## Attributes
|
||||
|
||||
.castID - A globally unique identifier of the currently cast spell (string?)
|
||||
.casting - Indicates whether the current spell is an ordinary cast (boolean)
|
||||
.channeling - Indicates whether the current spell is a channeled cast (boolean)
|
||||
.notInterruptible - Indicates whether the current spell is interruptible (boolean)
|
||||
.spellID - The spell identifier of the currently cast/channeled spell (number)
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local Castbar = CreateFrame('StatusBar', nil, self)
|
||||
Castbar:SetSize(20, 20)
|
||||
Castbar:SetPoint('TOP')
|
||||
Castbar:SetPoint('LEFT')
|
||||
Castbar:SetPoint('RIGHT')
|
||||
|
||||
-- Add a background
|
||||
local Background = Castbar:CreateTexture(nil, 'BACKGROUND')
|
||||
Background:SetAllPoints(Castbar)
|
||||
Background:SetTexture(1, 1, 1, .5)
|
||||
|
||||
-- Add a spark
|
||||
local Spark = Castbar:CreateTexture(nil, 'OVERLAY')
|
||||
Spark:SetSize(20, 20)
|
||||
Spark:SetBlendMode('ADD')
|
||||
Spark:SetPoint('CENTER', Castbar:GetStatusBarTexture(), 'RIGHT', 0, 0)
|
||||
|
||||
-- Add a timer
|
||||
local Time = Castbar:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
|
||||
Time:SetPoint('RIGHT', Castbar)
|
||||
|
||||
-- Add spell text
|
||||
local Text = Castbar:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
|
||||
Text:SetPoint('LEFT', Castbar)
|
||||
|
||||
-- Add spell icon
|
||||
local Icon = Castbar:CreateTexture(nil, 'OVERLAY')
|
||||
Icon:SetSize(20, 20)
|
||||
Icon:SetPoint('TOPLEFT', Castbar, 'TOPLEFT')
|
||||
|
||||
-- Add Shield
|
||||
local Shield = Castbar:CreateTexture(nil, 'OVERLAY')
|
||||
Shield:SetSize(20, 20)
|
||||
Shield:SetPoint('CENTER', Castbar)
|
||||
|
||||
-- Add safezone
|
||||
local SafeZone = Castbar:CreateTexture(nil, 'OVERLAY')
|
||||
|
||||
-- Register it with oUF
|
||||
Castbar.bg = Background
|
||||
Castbar.Spark = Spark
|
||||
Castbar.Time = Time
|
||||
Castbar.Text = Text
|
||||
Castbar.Icon = Icon
|
||||
Castbar.Shield = Shield
|
||||
Castbar.SafeZone = SafeZone
|
||||
self.Castbar = Castbar
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local FALLBACK_ICON = 136243 -- Interface\ICONS\Trade_Engineering
|
||||
|
||||
-- ElvUI block
|
||||
local select = select
|
||||
local FAILED = FAILED
|
||||
local INTERRUPTED = INTERRUPTED
|
||||
local GetNetStats = GetNetStats
|
||||
local UnitCastingInfo = UnitCastingInfo
|
||||
local UnitChannelInfo = UnitChannelInfo
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
local GetTime = GetTime
|
||||
|
||||
-- GLOBALS: PetCastingBarFrame, PetCastingBarFrame_OnLoad
|
||||
-- GLOBALS: CastingBarFrame, CastingBarFrame_OnLoad, CastingBarFrame_SetUnit
|
||||
|
||||
local tradeskillCurrent, tradeskillTotal, mergeTradeskill = 0, 0, false
|
||||
local UNIT_SPELLCAST_SENT = function (self, event, unit, target, castID, spellID)
|
||||
local castbar = self.Castbar
|
||||
castbar.curTarget = (target and target ~= "") and target or nil
|
||||
|
||||
if castbar.isTradeSkill then
|
||||
castbar.tradeSkillCastId = castID
|
||||
end
|
||||
end
|
||||
-- end block
|
||||
|
||||
local function resetAttributes(self)
|
||||
self.castID = nil
|
||||
self.casting = nil
|
||||
self.channeling = nil
|
||||
self.notInterruptible = nil
|
||||
self.spellID = nil
|
||||
self.spellName = nil -- ElvUI
|
||||
end
|
||||
|
||||
local function CastStart(self, real, unit, castGUID)
|
||||
if self.unit ~= unit then return end
|
||||
if real == 'UNIT_SPELLCAST_START' and not castGUID then return end
|
||||
|
||||
local element = self.Castbar
|
||||
local name, _, texture, startTime, endTime, isTradeSkill, castID, notInterruptible, spellID = UnitCastingInfo(unit)
|
||||
local event = 'UNIT_SPELLCAST_START'
|
||||
if(not name) then
|
||||
name, _, texture, startTime, endTime, isTradeSkill, notInterruptible, spellID = UnitChannelInfo(unit)
|
||||
event = 'UNIT_SPELLCAST_CHANNEL_START'
|
||||
end
|
||||
|
||||
if(not name or (isTradeSkill and element.hideTradeSkills)) then
|
||||
resetAttributes(element)
|
||||
element:Hide()
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
endTime = endTime / 1000
|
||||
startTime = startTime / 1000
|
||||
|
||||
element.max = endTime - startTime
|
||||
element.startTime = startTime
|
||||
element.delay = 0
|
||||
element.casting = event == 'UNIT_SPELLCAST_START'
|
||||
element.channeling = event == 'UNIT_SPELLCAST_CHANNEL_START'
|
||||
element.notInterruptible = notInterruptible
|
||||
element.holdTime = 0
|
||||
element.castID = castID
|
||||
element.spellID = spellID
|
||||
element.spellName = name -- ElvUI
|
||||
|
||||
if(element.casting) then
|
||||
element.duration = GetTime() - startTime
|
||||
else
|
||||
element.duration = endTime - GetTime()
|
||||
end
|
||||
|
||||
-- ElvUI block
|
||||
if(mergeTradeskill and isTradeSkill and UnitIsUnit(unit, "player")) then
|
||||
element.duration = element.duration + (element.max * tradeskillCurrent);
|
||||
element.max = element.max * tradeskillTotal;
|
||||
element.holdTime = 1
|
||||
|
||||
if(unit == "player") then
|
||||
tradeskillCurrent = tradeskillCurrent + 1;
|
||||
end
|
||||
end
|
||||
-- end block
|
||||
|
||||
element:SetMinMaxValues(0, element.max)
|
||||
element:SetValue(element.duration)
|
||||
|
||||
if(element.Icon) then element.Icon:SetTexture(texture or FALLBACK_ICON) end
|
||||
if(element.Shield) then element.Shield:SetShown(notInterruptible) end
|
||||
if(element.Spark) then element.Spark:Show() end
|
||||
if(element.Text) then element.Text:SetText(name) end
|
||||
if(element.Time) then element.Time:SetText() end
|
||||
|
||||
local safeZone = element.SafeZone
|
||||
if(safeZone) then
|
||||
local isHoriz = element:GetOrientation() == 'HORIZONTAL'
|
||||
|
||||
safeZone:ClearAllPoints()
|
||||
safeZone:SetPoint(isHoriz and 'TOP' or 'LEFT')
|
||||
safeZone:SetPoint(isHoriz and 'BOTTOM' or 'RIGHT')
|
||||
|
||||
if(element.casting) then
|
||||
safeZone:SetPoint(element:GetReverseFill() and (isHoriz and 'LEFT' or 'BOTTOM') or (isHoriz and 'RIGHT' or 'TOP'))
|
||||
else
|
||||
safeZone:SetPoint(element:GetReverseFill() and (isHoriz and 'RIGHT' or 'TOP') or (isHoriz and 'LEFT' or 'BOTTOM'))
|
||||
end
|
||||
|
||||
local ratio = (select(4, GetNetStats()) / 1000) / element.max
|
||||
if(ratio > 1) then
|
||||
ratio = 1
|
||||
end
|
||||
|
||||
safeZone[isHoriz and 'SetWidth' or 'SetHeight'](safeZone, element[isHoriz and 'GetWidth' or 'GetHeight'](element) * ratio)
|
||||
end
|
||||
|
||||
--[[ Callback: Castbar:PostCastStart(unit)
|
||||
Called after the element has been updated upon a spell cast or channel start.
|
||||
|
||||
* self - the Castbar widget
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PostCastStart) then
|
||||
element:PostCastStart(unit)
|
||||
end
|
||||
|
||||
element:Show()
|
||||
end
|
||||
|
||||
local function CastUpdate(self, event, unit, castID, spellID)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.Castbar
|
||||
if(not element:IsShown() or element.castID ~= castID or element.spellID ~= spellID) then
|
||||
return
|
||||
end
|
||||
|
||||
local name, startTime, endTime, _
|
||||
if(event == 'UNIT_SPELLCAST_DELAYED') then
|
||||
name, _, _, startTime, endTime = UnitCastingInfo(unit)
|
||||
else
|
||||
name, _, _, startTime, endTime = UnitChannelInfo(unit)
|
||||
end
|
||||
|
||||
if(not name) then return end
|
||||
|
||||
endTime = endTime / 1000
|
||||
startTime = startTime / 1000
|
||||
|
||||
local delta
|
||||
if(element.casting) then
|
||||
delta = startTime - element.startTime
|
||||
|
||||
element.duration = GetTime() - startTime
|
||||
else
|
||||
delta = element.startTime - startTime
|
||||
|
||||
element.duration = endTime - GetTime()
|
||||
end
|
||||
|
||||
if(delta < 0) then
|
||||
delta = 0
|
||||
end
|
||||
|
||||
element.max = endTime - startTime
|
||||
element.startTime = startTime
|
||||
element.delay = element.delay + delta
|
||||
|
||||
element:SetMinMaxValues(0, element.max)
|
||||
element:SetValue(element.duration)
|
||||
|
||||
--[[ Callback: Castbar:PostCastUpdate(unit)
|
||||
Called after the element has been updated when a spell cast or channel has been updated.
|
||||
|
||||
* self - the Castbar widget
|
||||
* unit - the unit that the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PostCastUpdate) then
|
||||
return element:PostCastUpdate(unit)
|
||||
end
|
||||
end
|
||||
|
||||
local function CastStop(self, event, unit, castID, spellID)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.Castbar
|
||||
if(not element:IsShown() or element.castID ~= castID or element.spellID ~= spellID) then
|
||||
return
|
||||
end
|
||||
|
||||
-- ElvUI block
|
||||
if mergeTradeskill and UnitIsUnit(unit, "player") then
|
||||
if tradeskillCurrent == tradeskillTotal then
|
||||
mergeTradeskill = false
|
||||
end
|
||||
end
|
||||
-- end block
|
||||
|
||||
resetAttributes(element)
|
||||
|
||||
--[[ Callback: Castbar:PostCastStop(unit, spellID)
|
||||
Called after the element has been updated when a spell cast or channel has stopped.
|
||||
|
||||
* self - the Castbar widget
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* spellID - the ID of the spell (number)
|
||||
--]]
|
||||
if(element.PostCastStop) then
|
||||
return element:PostCastStop(unit, spellID)
|
||||
end
|
||||
end
|
||||
|
||||
local function CastFail(self, event, unit, castID, spellID)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.Castbar
|
||||
if(not element:IsShown() or element.castID ~= castID or element.spellID ~= spellID) then
|
||||
return
|
||||
end
|
||||
|
||||
if(element.Text) then
|
||||
element.Text:SetText(event == 'UNIT_SPELLCAST_FAILED' and FAILED or INTERRUPTED)
|
||||
end
|
||||
|
||||
if(element.Spark) then element.Spark:Hide() end
|
||||
|
||||
element.holdTime = element.timeToHold or 0
|
||||
|
||||
-- ElvUI block
|
||||
if mergeTradeskill and UnitIsUnit(unit, "player") then
|
||||
mergeTradeskill = false
|
||||
element.tradeSkillCastId = nil
|
||||
end
|
||||
-- end block
|
||||
|
||||
resetAttributes(element)
|
||||
element:SetValue(element.max)
|
||||
|
||||
--[[ Callback: Castbar:PostCastFail(unit, spellID)
|
||||
Called after the element has been updated upon a failed or interrupted spell cast.
|
||||
|
||||
* self - the Castbar widget
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* spellID - the ID of the spell (number)
|
||||
--]]
|
||||
if(element.PostCastFail) then
|
||||
return element:PostCastFail(unit, spellID)
|
||||
end
|
||||
end
|
||||
|
||||
local function CastInterruptible(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.Castbar
|
||||
if(not element:IsShown()) then return end
|
||||
|
||||
element.notInterruptible = event == 'UNIT_SPELLCAST_NOT_INTERRUPTIBLE'
|
||||
|
||||
if(element.Shield) then element.Shield:SetShown(element.notInterruptible) end
|
||||
|
||||
--[[ Callback: Castbar:PostCastInterruptible(unit)
|
||||
Called after the element has been updated when a spell cast has become interruptible or uninterruptible.
|
||||
|
||||
* self - the Castbar widget
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PostCastInterruptible) then
|
||||
return element:PostCastInterruptible(unit)
|
||||
end
|
||||
end
|
||||
|
||||
local function onUpdate(self, elapsed)
|
||||
if(self.casting or self.channeling) then
|
||||
local isCasting = self.casting
|
||||
if(isCasting) then
|
||||
self.duration = self.duration + elapsed
|
||||
if(self.duration >= self.max) then
|
||||
local spellID = self.spellID
|
||||
|
||||
resetAttributes(self)
|
||||
self:Hide()
|
||||
|
||||
if(self.PostCastStop) then
|
||||
self:PostCastStop(self.__owner.unit, spellID)
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
else
|
||||
self.duration = self.duration - elapsed
|
||||
if(self.duration <= 0) then
|
||||
local spellID = self.spellID
|
||||
|
||||
resetAttributes(self)
|
||||
self:Hide()
|
||||
|
||||
if(self.PostCastStop) then
|
||||
self:PostCastStop(self.__owner.unit, spellID)
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if(self.Time) then
|
||||
if(self.delay ~= 0) then
|
||||
if(self.CustomDelayText) then
|
||||
self:CustomDelayText(self.duration)
|
||||
else
|
||||
self.Time:SetFormattedText('%.1f|cffff0000%s%.2f|r', self.duration, isCasting and '+' or '-', self.delay)
|
||||
end
|
||||
else
|
||||
if(self.CustomTimeText) then
|
||||
self:CustomTimeText(self.duration)
|
||||
else
|
||||
self.Time:SetFormattedText('%.1f', self.duration)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self:SetValue(self.duration)
|
||||
elseif(self.holdTime > 0) then
|
||||
self.holdTime = self.holdTime - elapsed
|
||||
else
|
||||
resetAttributes(self)
|
||||
self:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
local function Update(...)
|
||||
CastStart(...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Update(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.Castbar
|
||||
if(element and unit and not unit:match('%wtarget$')) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_SPELLCAST_START', CastStart)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_START', CastStart)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_STOP', CastStop)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_STOP', CastStop)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_DELAYED', CastUpdate)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_UPDATE', CastUpdate)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_FAILED', CastFail)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_INTERRUPTED', CastFail)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_INTERRUPTIBLE', CastInterruptible)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_NOT_INTERRUPTIBLE', CastInterruptible)
|
||||
|
||||
-- ElvUI block
|
||||
self:RegisterEvent('UNIT_SPELLCAST_SENT', UNIT_SPELLCAST_SENT, true)
|
||||
-- end block
|
||||
|
||||
element.holdTime = 0
|
||||
|
||||
element:SetScript('OnUpdate', element.OnUpdate or onUpdate)
|
||||
|
||||
if(self.unit == 'player' and not (self.hasChildren or self.isChild or self.isNamePlate)) then
|
||||
CastingBarFrame_SetUnit(CastingBarFrame, nil)
|
||||
CastingBarFrame_SetUnit(PetCastingBarFrame, nil)
|
||||
end
|
||||
|
||||
if(element:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then
|
||||
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
|
||||
local spark = element.Spark
|
||||
if(spark and spark:IsObjectType('Texture') and not spark:GetTexture()) then
|
||||
spark:SetTexture([[Interface\CastingBar\UI-CastingBar-Spark]])
|
||||
end
|
||||
|
||||
local shield = element.Shield
|
||||
if(shield and shield:IsObjectType('Texture') and not shield:GetTexture()) then
|
||||
shield:SetTexture([[Interface\CastingBar\UI-CastingBar-Small-Shield]])
|
||||
end
|
||||
|
||||
local safeZone = element.SafeZone
|
||||
if(safeZone and safeZone:IsObjectType('Texture') and not safeZone:GetTexture()) then
|
||||
safeZone:SetColorTexture(1, 0, 0)
|
||||
end
|
||||
|
||||
element:Hide()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Castbar
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_START', CastStart)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_START', CastStart)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_DELAYED', CastUpdate)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_UPDATE', CastUpdate)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_STOP', CastStop)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_STOP', CastStop)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_FAILED', CastFail)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_INTERRUPTED', CastFail)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_INTERRUPTIBLE', CastInterruptible)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_NOT_INTERRUPTIBLE', CastInterruptible)
|
||||
|
||||
element:SetScript('OnUpdate', nil)
|
||||
|
||||
if(self.unit == 'player' and not (self.hasChildren or self.isChild or self.isNamePlate)) then
|
||||
CastingBarFrame_OnLoad(CastingBarFrame, 'player', true, false)
|
||||
PetCastingBarFrame_OnLoad(PetCastingBarFrame)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ElvUI block
|
||||
hooksecurefunc(C_TradeSkillUI, "CraftRecipe", function(_, num)
|
||||
tradeskillCurrent = 0
|
||||
tradeskillTotal = num or 1
|
||||
mergeTradeskill = true
|
||||
end)
|
||||
-- end block
|
||||
|
||||
oUF:AddElement('Castbar', Update, Enable, Disable)
|
||||
357
Libraries/oUF/elements/classpower.lua
Normal file
357
Libraries/oUF/elements/classpower.lua
Normal file
@@ -0,0 +1,357 @@
|
||||
--[[
|
||||
# Element: ClassPower
|
||||
|
||||
Handles the visibility and updating of the player's class resources (like Chi Orbs or Holy Power) and combo points.
|
||||
|
||||
## Widget
|
||||
|
||||
ClassPower - An `table` consisting of as many StatusBars as the theoretical maximum return of [UnitPowerMax](http://wowprogramming.com/docs/api/UnitPowerMax.html).
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
.bg - A `Texture` used as a background. It will inherit the color of the main StatusBar.
|
||||
|
||||
## Sub-Widget Options
|
||||
|
||||
.multiplier - Used to tint the background based on the widget's R, G and B values. Defaults to 1 (number)[0-1]
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the sub-widgets are StatusBars and don't have a texture set.
|
||||
If the sub-widgets are StatusBars, their minimum and maximum values will be set to 0 and 1 respectively.
|
||||
|
||||
Supported class powers:
|
||||
- All - Combo Points
|
||||
- Mage - Arcane Charges
|
||||
- Monk - Chi Orbs
|
||||
- Paladin - Holy Power
|
||||
- Warlock - Soul Shards
|
||||
|
||||
## Examples
|
||||
|
||||
local ClassPower = {}
|
||||
for index = 1, 10 do
|
||||
local Bar = CreateFrame('StatusBar', nil, self)
|
||||
|
||||
-- Position and size.
|
||||
Bar:SetSize(16, 16)
|
||||
Bar:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', (index - 1) * Bar:GetWidth(), 0)
|
||||
|
||||
ClassPower[index] = Bar
|
||||
end
|
||||
|
||||
-- Register with oUF
|
||||
self.ClassPower = ClassPower
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local _, PlayerClass = UnitClass('player')
|
||||
|
||||
-- sourced from FrameXML/Constants.lua
|
||||
local SPEC_MAGE_ARCANE = SPEC_MAGE_ARCANE or 1
|
||||
local SPEC_MONK_WINDWALKER = SPEC_MONK_WINDWALKER or 3
|
||||
local SPEC_PALADIN_RETRIBUTION = SPEC_PALADIN_RETRIBUTION or 3
|
||||
local SPEC_WARLOCK_DESTRUCTION = SPEC_WARLOCK_DESTRUCTION or 3
|
||||
local SPELL_POWER_ENERGY = Enum.PowerType.Energy or 3
|
||||
local SPELL_POWER_COMBO_POINTS = Enum.PowerType.ComboPoints or 4
|
||||
local SPELL_POWER_SOUL_SHARDS = Enum.PowerType.SoulShards or 7
|
||||
local SPELL_POWER_HOLY_POWER = Enum.PowerType.HolyPower or 9
|
||||
local SPELL_POWER_CHI = Enum.PowerType.Chi or 12
|
||||
local SPELL_POWER_ARCANE_CHARGES = Enum.PowerType.ArcaneCharges or 16
|
||||
|
||||
-- Holds the class specific stuff.
|
||||
local ClassPowerID, ClassPowerType
|
||||
local ClassPowerEnable, ClassPowerDisable
|
||||
local RequireSpec, RequirePower, RequireSpell
|
||||
|
||||
local function UpdateColor(element, powerType)
|
||||
local color = element.__owner.colors.power[powerType]
|
||||
local r, g, b = color[1], color[2], color[3]
|
||||
for i = 1, #element do
|
||||
local bar = element[i]
|
||||
bar:SetStatusBarColor(r, g, b)
|
||||
|
||||
local bg = bar.bg
|
||||
if(bg) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Callback: ClassPower:PostUpdateColor(r, g, b)
|
||||
Called after the element color has been updated.
|
||||
|
||||
* self - the ClassPower element
|
||||
* r - the red component of the used color (number)[0-1]
|
||||
* g - the green component of the used color (number)[0-1]
|
||||
* b - the blue component of the used color (number)[0-1]
|
||||
--]]
|
||||
if(element.PostUpdateColor) then
|
||||
element:PostUpdateColor(r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function Update(self, event, unit, powerType)
|
||||
if(not (unit and (UnitIsUnit(unit, 'player') and (not powerType or powerType == ClassPowerType)
|
||||
or unit == 'vehicle' and powerType == 'COMBO_POINTS'))) then
|
||||
return
|
||||
end
|
||||
|
||||
local element = self.ClassPower
|
||||
|
||||
--[[ Callback: ClassPower:PreUpdate(event)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the ClassPower element
|
||||
]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local cur, max, mod, oldMax, chargedIndex
|
||||
if(event ~= 'ClassPowerDisable') then
|
||||
local powerID = unit == 'vehicle' and SPELL_POWER_COMBO_POINTS or ClassPowerID
|
||||
cur = UnitPower(unit, powerID, true)
|
||||
max = UnitPowerMax(unit, powerID)
|
||||
mod = UnitPowerDisplayMod(powerID)
|
||||
|
||||
-- mod should never be 0, but according to Blizz code it can actually happen
|
||||
cur = mod == 0 and 0 or cur / mod
|
||||
|
||||
-- BUG: Destruction is supposed to show partial soulshards, but Affliction and Demonology should only show full ones
|
||||
if(ClassPowerType == 'SOUL_SHARDS' and GetSpecialization() ~= SPEC_WARLOCK_DESTRUCTION) then
|
||||
cur = cur - cur % 1
|
||||
end
|
||||
|
||||
if(PlayerClass == 'ROGUE') then
|
||||
local chargedPoints = GetUnitChargedPowerPoints(unit)
|
||||
-- according to Blizzard there will only be one
|
||||
chargedIndex = chargedPoints and chargedPoints[1]
|
||||
end
|
||||
|
||||
local numActive = cur + 0.9
|
||||
for i = 1, max do
|
||||
if(i > numActive) then
|
||||
element[i]:Hide()
|
||||
element[i]:SetValue(0)
|
||||
else
|
||||
element[i]:Show()
|
||||
element[i]:SetValue(cur - i + 1)
|
||||
end
|
||||
end
|
||||
|
||||
oldMax = element.__max
|
||||
if(max ~= oldMax) then
|
||||
if(max < oldMax) then
|
||||
for i = max + 1, oldMax do
|
||||
element[i]:Hide()
|
||||
element[i]:SetValue(0)
|
||||
end
|
||||
end
|
||||
|
||||
element.__max = max
|
||||
end
|
||||
end
|
||||
--[[ Callback: ClassPower:PostUpdate(cur, max, hasMaxChanged, powerType)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the ClassPower element
|
||||
* cur - the current amount of power (number)
|
||||
* max - the maximum amount of power (number)
|
||||
* hasMaxChanged - indicates whether the maximum amount has changed since the last update (boolean)
|
||||
* powerType - the active power type (string)
|
||||
* chargedIndex - the index of the currently charged power point (number?)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(cur, max, oldMax ~= max, powerType, chargedIndex)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: ClassPower.Override(self, event, unit, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.ClassPower.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function Visibility(self, event, unit)
|
||||
local element = self.ClassPower
|
||||
local shouldEnable
|
||||
|
||||
if(UnitHasVehicleUI('player')) then
|
||||
shouldEnable = PlayerVehicleHasComboPoints()
|
||||
unit = 'vehicle'
|
||||
elseif(ClassPowerID) then
|
||||
if(not RequireSpec or RequireSpec == GetSpecialization()) then
|
||||
-- use 'player' instead of unit because 'SPELLS_CHANGED' is a unitless event
|
||||
if(not RequirePower or RequirePower == UnitPowerType('player')) then
|
||||
if(not RequireSpell or IsPlayerSpell(RequireSpell)) then
|
||||
self:UnregisterEvent('SPELLS_CHANGED', Visibility)
|
||||
shouldEnable = true
|
||||
unit = 'player'
|
||||
else
|
||||
self:RegisterEvent('SPELLS_CHANGED', Visibility, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local isEnabled = element.__isEnabled
|
||||
local powerType = unit == 'vehicle' and 'COMBO_POINTS' or ClassPowerType
|
||||
|
||||
if(shouldEnable) then
|
||||
--[[ Override: ClassPower:UpdateColor(powerType)
|
||||
Used to completely override the internal function for updating the widgets' colors.
|
||||
|
||||
* self - the ClassPower element
|
||||
* powerType - the active power type (string)
|
||||
--]]
|
||||
(element.UpdateColor or UpdateColor) (element, powerType)
|
||||
end
|
||||
|
||||
if(shouldEnable and not isEnabled) then
|
||||
ClassPowerEnable(self)
|
||||
|
||||
--[[ Callback: ClassPower:PostVisibility(isVisible)
|
||||
Called after the element's visibility has been changed.
|
||||
|
||||
* self - the ClassPower element
|
||||
* isVisible - the current visibility state of the element (boolean)
|
||||
--]]
|
||||
if(element.PostVisibility) then
|
||||
element:PostVisibility(true)
|
||||
end
|
||||
elseif(not shouldEnable and (isEnabled or isEnabled == nil)) then
|
||||
ClassPowerDisable(self)
|
||||
|
||||
if(element.PostVisibility) then
|
||||
element:PostVisibility(false)
|
||||
end
|
||||
elseif(shouldEnable and isEnabled) then
|
||||
Path(self, event, unit, powerType)
|
||||
end
|
||||
end
|
||||
|
||||
local function VisibilityPath(self, ...)
|
||||
--[[ Override: ClassPower.OverrideVisibility(self, event, unit)
|
||||
Used to completely override the internal visibility function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
return (self.ClassPower.OverrideVisibility or Visibility) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
do
|
||||
function ClassPowerEnable(self)
|
||||
self:RegisterEvent('UNIT_POWER_FREQUENT', Path)
|
||||
self:RegisterEvent('UNIT_MAXPOWER', Path)
|
||||
|
||||
if(PlayerClass == 'ROGUE') then
|
||||
self:RegisterEvent('UNIT_POWER_POINT_CHARGE', Path)
|
||||
end
|
||||
|
||||
self.ClassPower.__isEnabled = true
|
||||
|
||||
if(UnitHasVehicleUI('player')) then
|
||||
Path(self, 'ClassPowerEnable', 'vehicle', 'COMBO_POINTS')
|
||||
else
|
||||
Path(self, 'ClassPowerEnable', 'player', ClassPowerType)
|
||||
end
|
||||
end
|
||||
|
||||
function ClassPowerDisable(self)
|
||||
self:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
|
||||
self:UnregisterEvent('UNIT_MAXPOWER', Path)
|
||||
self:UnregisterEvent('UNIT_POWER_POINT_CHARGE', Path)
|
||||
|
||||
local element = self.ClassPower
|
||||
for i = 1, #element do
|
||||
element[i]:Hide()
|
||||
end
|
||||
|
||||
element.__isEnabled = false
|
||||
Path(self, 'ClassPowerDisable', 'player', ClassPowerType)
|
||||
end
|
||||
|
||||
if(PlayerClass == 'MONK') then
|
||||
ClassPowerID = SPELL_POWER_CHI
|
||||
ClassPowerType = 'CHI'
|
||||
RequireSpec = SPEC_MONK_WINDWALKER
|
||||
elseif(PlayerClass == 'PALADIN') then
|
||||
ClassPowerID = SPELL_POWER_HOLY_POWER
|
||||
ClassPowerType = 'HOLY_POWER'
|
||||
elseif(PlayerClass == 'WARLOCK') then
|
||||
ClassPowerID = SPELL_POWER_SOUL_SHARDS
|
||||
ClassPowerType = 'SOUL_SHARDS'
|
||||
elseif(PlayerClass == 'ROGUE' or PlayerClass == 'DRUID') then
|
||||
ClassPowerID = SPELL_POWER_COMBO_POINTS
|
||||
ClassPowerType = 'COMBO_POINTS'
|
||||
|
||||
if(PlayerClass == 'DRUID') then
|
||||
RequirePower = SPELL_POWER_ENERGY
|
||||
RequireSpell = 5221 -- Shred
|
||||
end
|
||||
elseif(PlayerClass == 'MAGE') then
|
||||
ClassPowerID = SPELL_POWER_ARCANE_CHARGES
|
||||
ClassPowerType = 'ARCANE_CHARGES'
|
||||
RequireSpec = SPEC_MAGE_ARCANE
|
||||
end
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.ClassPower
|
||||
if(element and UnitIsUnit(unit, 'player')) then
|
||||
element.__owner = self
|
||||
element.__max = #element
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
if(RequireSpec or RequireSpell) then
|
||||
self:RegisterEvent('PLAYER_TALENT_UPDATE', VisibilityPath, true)
|
||||
end
|
||||
|
||||
if(RequirePower) then
|
||||
self:RegisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
|
||||
end
|
||||
|
||||
element.ClassPowerEnable = ClassPowerEnable
|
||||
element.ClassPowerDisable = ClassPowerDisable
|
||||
|
||||
for i = 1, #element do
|
||||
local bar = element[i]
|
||||
if(bar:IsObjectType('StatusBar')) then
|
||||
if(not (bar:GetStatusBarTexture() or bar:GetStatusBarAtlas())) then
|
||||
bar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
|
||||
bar:SetMinMaxValues(0, 1)
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
if(self.ClassPower) then
|
||||
ClassPowerDisable(self)
|
||||
|
||||
self:UnregisterEvent('PLAYER_TALENT_UPDATE', VisibilityPath)
|
||||
self:UnregisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
|
||||
self:UnregisterEvent('SPELLS_CHANGED', Visibility)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('ClassPower', VisibilityPath, Enable, Disable)
|
||||
105
Libraries/oUF/elements/combatindicator.lua
Normal file
105
Libraries/oUF/elements/combatindicator.lua
Normal file
@@ -0,0 +1,105 @@
|
||||
--[[
|
||||
# Element: Combat Indicator
|
||||
|
||||
Toggles the visibility of an indicator based on the player's combat status.
|
||||
|
||||
## Widget
|
||||
|
||||
CombatIndicator - Any UI widget.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local CombatIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
CombatIndicator:SetSize(16, 16)
|
||||
CombatIndicator:SetPoint('TOP', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.CombatIndicator = CombatIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if not unit or self.unit ~= unit then return end
|
||||
local element = self.CombatIndicator
|
||||
|
||||
--[[ Callback: CombatIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the CombatIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local inCombat = UnitAffectingCombat(unit)
|
||||
if(inCombat) then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: CombatIndicator:PostUpdate(inCombat)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the CombatIndicator element
|
||||
* inCombat - indicates if the player is affecting combat (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(inCombat)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: CombatIndicator.Override(self, event)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
--]]
|
||||
return (self.CombatIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.CombatIndicator
|
||||
if element then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_COMBAT', Path)
|
||||
self:RegisterEvent('UNIT_FLAGS', Path)
|
||||
self:RegisterEvent('PLAYER_REGEN_DISABLED', Path, true)
|
||||
self:RegisterEvent('PLAYER_REGEN_ENABLED', Path, true)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\CharacterFrame\UI-StateIcon]])
|
||||
element:SetTexCoord(.5, 1, 0, .49)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.CombatIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_COMBAT', Path)
|
||||
self:UnregisterEvent('UNIT_FLAGS', Path)
|
||||
self:UnregisterEvent('PLAYER_REGEN_DISABLED', Path)
|
||||
self:UnregisterEvent('PLAYER_REGEN_ENABLED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('CombatIndicator', Path, Enable, Disable)
|
||||
104
Libraries/oUF/elements/grouproleindicator.lua
Normal file
104
Libraries/oUF/elements/grouproleindicator.lua
Normal file
@@ -0,0 +1,104 @@
|
||||
--[[
|
||||
# Element: Group Role Indicator
|
||||
|
||||
Toggles the visibility of an indicator based on the unit's current group role (tank, healer or damager).
|
||||
|
||||
## Widget
|
||||
|
||||
GroupRoleIndicator - A `Texture` used to display the group role icon.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local GroupRoleIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
GroupRoleIndicator:SetSize(16, 16)
|
||||
GroupRoleIndicator:SetPoint('LEFT', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.GroupRoleIndicator = GroupRoleIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.GroupRoleIndicator
|
||||
|
||||
--[[ Callback: GroupRoleIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the GroupRoleIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local role = UnitGroupRolesAssigned(self.unit)
|
||||
if(role == 'TANK' or role == 'HEALER' or role == 'DAMAGER') then
|
||||
element:SetTexCoord(GetTexCoordsForRoleSmallCircle(role))
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: GroupRoleIndicator:PostUpdate(role)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the GroupRoleIndicator element
|
||||
* role - the role as returned by [UnitGroupRolesAssigned](http://wowprogramming.com/docs/api/UnitGroupRolesAssigned.html)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(role)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: GroupRoleIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.GroupRoleIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.GroupRoleIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
if(self.unit == 'player') then
|
||||
self:RegisterEvent('PLAYER_ROLES_ASSIGNED', Path, true)
|
||||
else
|
||||
self:RegisterEvent('GROUP_ROSTER_UPDATE', Path, true)
|
||||
end
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\LFGFrame\UI-LFG-ICON-PORTRAITROLES]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.GroupRoleIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('PLAYER_ROLES_ASSIGNED', Path)
|
||||
self:UnregisterEvent('GROUP_ROSTER_UPDATE', Path, true)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('GroupRoleIndicator', Path, Enable, Disable)
|
||||
379
Libraries/oUF/elements/health.lua
Normal file
379
Libraries/oUF/elements/health.lua
Normal file
@@ -0,0 +1,379 @@
|
||||
--[[
|
||||
# Element: Health Bar
|
||||
|
||||
Handles the updating of a status bar that displays the unit's health.
|
||||
|
||||
## Widget
|
||||
|
||||
Health - A `StatusBar` used to represent the unit's health.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
.bg - A `Texture` used as a background. It will inherit the color of the main StatusBar.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a StatusBar and doesn't have a texture set.
|
||||
|
||||
## Options
|
||||
|
||||
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
|
||||
.considerSelectionInCombatHostile - Indicates whether selection should be considered hostile while the unit is in
|
||||
combat with the player (boolean)
|
||||
|
||||
The following options are listed by priority. The first check that returns true decides the color of the bar.
|
||||
|
||||
.colorDisconnected - Use `self.colors.disconnected` to color the bar if the unit is offline (boolean)
|
||||
.colorTapping - Use `self.colors.tapping` to color the bar if the unit isn't tapped by the player (boolean)
|
||||
.colorThreat - Use `self.colors.threat[threat]` to color the bar based on the unit's threat status. `threat` is
|
||||
defined by the first return of [UnitThreatSituation](https://wow.gamepedia.com/API_UnitThreatSituation) (boolean)
|
||||
.colorClass - Use `self.colors.class[class]` to color the bar based on unit class. `class` is defined by the
|
||||
second return of [UnitClass](http://wowprogramming.com/docs/api/UnitClass.html) (boolean)
|
||||
.colorClassNPC - Use `self.colors.class[class]` to color the bar if the unit is a NPC (boolean)
|
||||
.colorClassPet - Use `self.colors.class[class]` to color the bar if the unit is player controlled, but not a player
|
||||
(boolean)
|
||||
.colorSelection - Use `self.colors.selection[selection]` to color the bar based on the unit's selection color.
|
||||
`selection` is defined by the return value of Private.unitSelectionType, a wrapper function
|
||||
for [UnitSelectionType](https://wow.gamepedia.com/API_UnitSelectionType) (boolean)
|
||||
.colorReaction - Use `self.colors.reaction[reaction]` to color the bar based on the player's reaction towards the
|
||||
unit. `reaction` is defined by the return value of
|
||||
[UnitReaction](http://wowprogramming.com/docs/api/UnitReaction.html) (boolean)
|
||||
.colorSmooth - Use `smoothGradient` if present or `self.colors.smooth` to color the bar with a smooth gradient
|
||||
based on the player's current health percentage (boolean)
|
||||
.colorHealth - Use `self.colors.health` to color the bar. This flag is used to reset the bar color back to default
|
||||
if none of the above conditions are met (boolean)
|
||||
|
||||
## Sub-Widgets Options
|
||||
|
||||
.multiplier - Used to tint the background based on the main widgets R, G and B values. Defaults to 1 (number)[0-1]
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local Health = CreateFrame('StatusBar', nil, self)
|
||||
Health:SetHeight(20)
|
||||
Health:SetPoint('TOP')
|
||||
Health:SetPoint('LEFT')
|
||||
Health:SetPoint('RIGHT')
|
||||
|
||||
-- Add a background
|
||||
local Background = Health:CreateTexture(nil, 'BACKGROUND')
|
||||
Background:SetAllPoints(Health)
|
||||
Background:SetTexture(1, 1, 1, .5)
|
||||
|
||||
-- Options
|
||||
Health.colorTapping = true
|
||||
Health.colorDisconnected = true
|
||||
Health.colorClass = true
|
||||
Health.colorReaction = true
|
||||
Health.colorHealth = true
|
||||
|
||||
-- Make the background darker.
|
||||
Background.multiplier = .5
|
||||
|
||||
-- Register it with oUF
|
||||
Health.bg = Background
|
||||
self.Health = Health
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local unitSelectionType = Private.unitSelectionType
|
||||
|
||||
local function UpdateColor(self, event, unit)
|
||||
if(not unit or self.unit ~= unit) then return end
|
||||
local element = self.Health
|
||||
|
||||
local r, g, b, t
|
||||
if(element.colorDisconnected and not UnitIsConnected(unit)) then
|
||||
t = self.colors.disconnected
|
||||
elseif(element.colorTapping and not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)) then
|
||||
t = self.colors.tapped
|
||||
elseif(element.colorThreat and not UnitPlayerControlled(unit) and UnitThreatSituation('player', unit)) then
|
||||
t = self.colors.threat[UnitThreatSituation('player', unit)]
|
||||
elseif(element.colorClass and UnitIsPlayer(unit))
|
||||
or (element.colorClassNPC and not UnitIsPlayer(unit))
|
||||
or ((element.colorClassPet or element.colorPetByUnitClass) and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
|
||||
if element.colorPetByUnitClass then unit = unit == 'pet' and 'player' or gsub(unit, 'pet', '') end
|
||||
local _, class = UnitClass(unit)
|
||||
t = self.colors.class[class]
|
||||
elseif(element.colorSelection and unitSelectionType(unit, element.considerSelectionInCombatHostile)) then
|
||||
t = self.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
|
||||
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
|
||||
t = self.colors.reaction[UnitReaction(unit, 'player')]
|
||||
elseif(element.colorSmooth) then
|
||||
r, g, b = self:ColorGradient(element.cur or 1, element.max or 1, unpack(element.smoothGradient or self.colors.smooth))
|
||||
elseif(element.colorHealth) then
|
||||
t = self.colors.health
|
||||
end
|
||||
|
||||
if(t) then
|
||||
r, g, b = t[1], t[2], t[3]
|
||||
end
|
||||
|
||||
if(b) then
|
||||
element:SetStatusBarColor(r, g, b)
|
||||
|
||||
local bg = element.bg
|
||||
if(bg) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Callback: Health:PostUpdateColor(unit, r, g, b)
|
||||
Called after the element color has been updated.
|
||||
|
||||
* self - the Health element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* r - the red component of the used color (number)[0-1]
|
||||
* g - the green component of the used color (number)[0-1]
|
||||
* b - the blue component of the used color (number)[0-1]
|
||||
--]]
|
||||
if(element.PostUpdateColor) then
|
||||
element:PostUpdateColor(unit, r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function ColorPath(self, ...)
|
||||
--[[ Override: Health.UpdateColor(self, event, unit)
|
||||
Used to completely override the internal function for updating the widgets' colors.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.Health.UpdateColor or UpdateColor) (self, ...)
|
||||
end
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(not unit or self.unit ~= unit) then return end
|
||||
local element = self.Health
|
||||
|
||||
--[[ Callback: Health:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the Health element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local cur, max = UnitHealth(unit), UnitHealthMax(unit)
|
||||
element:SetMinMaxValues(0, max)
|
||||
|
||||
if(UnitIsConnected(unit)) then
|
||||
element:SetValue(cur)
|
||||
else
|
||||
element:SetValue(max)
|
||||
end
|
||||
|
||||
element.cur = cur
|
||||
element.max = max
|
||||
|
||||
--[[ Callback: Health:PostUpdate(unit, cur, max)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Health element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* cur - the unit's current health value (number)
|
||||
* max - the unit's maximum possible health value (number)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
element:PostUpdate(unit, cur, max)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, event, ...)
|
||||
if (self.isForced and event ~= 'ElvUI_UpdateAllElements') then return end -- ElvUI changed
|
||||
|
||||
--[[ Override: Health.Override(self, event, unit)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.Health.Override or Update) (self, event, ...);
|
||||
|
||||
ColorPath(self, event, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
--[[ Health:SetColorDisconnected(state, isForced)
|
||||
Used to toggle coloring if the unit is offline.
|
||||
|
||||
* self - the Health element
|
||||
* state - the desired state (boolean)
|
||||
* isForced - forces the event update even if the state wasn't changed (boolean)
|
||||
--]]
|
||||
local function SetColorDisconnected(element, state, isForced)
|
||||
if(element.colorDisconnected ~= state or isForced) then
|
||||
element.colorDisconnected = state
|
||||
if(state) then
|
||||
element.__owner:RegisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
element.__owner:RegisterEvent('PARTY_MEMBER_ENABLE', ColorPath)
|
||||
element.__owner:RegisterEvent('PARTY_MEMBER_DISABLE', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
element.__owner:UnregisterEvent('PARTY_MEMBER_ENABLE', ColorPath)
|
||||
element.__owner:UnregisterEvent('PARTY_MEMBER_DISABLE', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Health:SetColorSelection(state, isForced)
|
||||
Used to toggle coloring by the unit's selection.
|
||||
|
||||
* self - the Health element
|
||||
* state - the desired state (boolean)
|
||||
* isForced - forces the event update even if the state wasn't changed (boolean)
|
||||
--]]
|
||||
local function SetColorSelection(element, state, isForced)
|
||||
if(element.colorSelection ~= state or isForced) then
|
||||
element.colorSelection = state
|
||||
if(state) then
|
||||
element.__owner:RegisterEvent('UNIT_FLAGS', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_FLAGS', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Health:SetColorTapping(state, isForced)
|
||||
Used to toggle coloring if the unit isn't tapped by the player.
|
||||
|
||||
* self - the Health element
|
||||
* state - the desired state (boolean)
|
||||
* isForced - forces the event update even if the state wasn't changed (boolean)
|
||||
--]]
|
||||
local function SetColorTapping(element, state, isForced)
|
||||
if(element.colorTapping ~= state or isForced) then
|
||||
element.colorTapping = state
|
||||
if(state) then
|
||||
element.__owner:RegisterEvent('UNIT_FACTION', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_FACTION', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Health:SetColorThreat(state, isForced)
|
||||
Used to toggle coloring by the unit's threat status.
|
||||
|
||||
* self - the Health element
|
||||
* state - the desired state (boolean)
|
||||
* isForced - forces the event update even if the state wasn't changed (boolean)
|
||||
--]]
|
||||
local function SetColorThreat(element, state, isForced)
|
||||
if(element.colorThreat ~= state or isForced) then
|
||||
element.colorThreat = state
|
||||
if(state) then
|
||||
element.__owner:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ElvUI changed block
|
||||
local onUpdateElapsed, onUpdateWait = 0, 0.25
|
||||
local function onUpdateHealth(self, elapsed)
|
||||
if onUpdateElapsed > onUpdateWait then
|
||||
Path(self.__owner, 'OnUpdate', self.__owner.unit)
|
||||
|
||||
onUpdateElapsed = 0
|
||||
else
|
||||
onUpdateElapsed = onUpdateElapsed + elapsed
|
||||
end
|
||||
end
|
||||
|
||||
local function SetHealthUpdateSpeed(self, state)
|
||||
onUpdateWait = state
|
||||
end
|
||||
|
||||
local function SetHealthUpdateMethod(self, state, force)
|
||||
if self.effectiveHealth ~= state or force then
|
||||
self.effectiveHealth = state
|
||||
|
||||
if state then
|
||||
self.Health:SetScript('OnUpdate', onUpdateHealth)
|
||||
self:UnregisterEvent('UNIT_HEALTH', Path)
|
||||
self:UnregisterEvent('UNIT_MAXHEALTH', Path)
|
||||
else
|
||||
self.Health:SetScript('OnUpdate', nil)
|
||||
self:RegisterEvent('UNIT_HEALTH', Path)
|
||||
self:RegisterEvent('UNIT_MAXHEALTH', Path)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- end block
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.Health
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
element.SetColorDisconnected = SetColorDisconnected
|
||||
element.SetColorSelection = SetColorSelection
|
||||
element.SetColorTapping = SetColorTapping
|
||||
element.SetColorThreat = SetColorThreat
|
||||
|
||||
-- ElvUI changed block
|
||||
self.SetHealthUpdateSpeed = SetHealthUpdateSpeed
|
||||
self.SetHealthUpdateMethod = SetHealthUpdateMethod
|
||||
SetHealthUpdateMethod(self, self.effectiveHealth, true)
|
||||
-- end block
|
||||
|
||||
if(element.colorDisconnected) then
|
||||
self:RegisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
self:RegisterEvent('PARTY_MEMBER_ENABLE', ColorPath)
|
||||
self:RegisterEvent('PARTY_MEMBER_DISABLE', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorSelection) then
|
||||
self:RegisterEvent('UNIT_FLAGS', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorTapping) then
|
||||
self:RegisterEvent('UNIT_FACTION', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorThreat) then
|
||||
self:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
|
||||
if(element:IsObjectType('StatusBar') and not (element:GetStatusBarTexture() or element:GetStatusBarAtlas())) then
|
||||
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
|
||||
element:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Health
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
element:SetScript('OnUpdate', nil) -- ElvUI changed
|
||||
self:UnregisterEvent('UNIT_HEALTH', Path)
|
||||
self:UnregisterEvent('UNIT_MAXHEALTH', Path)
|
||||
self:UnregisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
self:UnregisterEvent('UNIT_FACTION', ColorPath)
|
||||
self:UnregisterEvent('UNIT_FLAGS', ColorPath)
|
||||
self:UnregisterEvent('PARTY_MEMBER_ENABLE', ColorPath)
|
||||
self:UnregisterEvent('PARTY_MEMBER_DISABLE', ColorPath)
|
||||
self:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Health', Path, Enable, Disable)
|
||||
300
Libraries/oUF/elements/healthprediction.lua
Normal file
300
Libraries/oUF/elements/healthprediction.lua
Normal file
@@ -0,0 +1,300 @@
|
||||
--[[
|
||||
# Element: Health Prediction Bars
|
||||
|
||||
Handles the visibility and updating of incoming heals and heal/damage absorbs.
|
||||
|
||||
## Widget
|
||||
|
||||
HealthPrediction - A `table` containing references to sub-widgets and options.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
myBar - A `StatusBar` used to represent incoming heals from the player.
|
||||
otherBar - A `StatusBar` used to represent incoming heals from others.
|
||||
absorbBar - A `StatusBar` used to represent damage absorbs.
|
||||
healAbsorbBar - A `StatusBar` used to represent heal absorbs.
|
||||
overAbsorb - A `Texture` used to signify that the amount of damage absorb is greater than the unit's missing health.
|
||||
overHealAbsorb - A `Texture` used to signify that the amount of heal absorb is greater than the unit's current health.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied to the StatusBar widgets if they don't have a texture set.
|
||||
A default texture will be applied to the Texture widgets if they don't have a texture or a color set.
|
||||
|
||||
## Options
|
||||
|
||||
.maxOverflow - The maximum amount of overflow past the end of the health bar. Set this to 1 to disable the overflow.
|
||||
Defaults to 1.05 (number)
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local myBar = CreateFrame('StatusBar', nil, self.Health)
|
||||
myBar:SetPoint('TOP')
|
||||
myBar:SetPoint('BOTTOM')
|
||||
myBar:SetPoint('LEFT', self.Health:GetStatusBarTexture(), 'RIGHT')
|
||||
myBar:SetWidth(200)
|
||||
|
||||
local otherBar = CreateFrame('StatusBar', nil, self.Health)
|
||||
otherBar:SetPoint('TOP')
|
||||
otherBar:SetPoint('BOTTOM')
|
||||
otherBar:SetPoint('LEFT', myBar:GetStatusBarTexture(), 'RIGHT')
|
||||
otherBar:SetWidth(200)
|
||||
|
||||
local absorbBar = CreateFrame('StatusBar', nil, self.Health)
|
||||
absorbBar:SetPoint('TOP')
|
||||
absorbBar:SetPoint('BOTTOM')
|
||||
absorbBar:SetPoint('LEFT', otherBar:GetStatusBarTexture(), 'RIGHT')
|
||||
absorbBar:SetWidth(200)
|
||||
|
||||
local healAbsorbBar = CreateFrame('StatusBar', nil, self.Health)
|
||||
healAbsorbBar:SetPoint('TOP')
|
||||
healAbsorbBar:SetPoint('BOTTOM')
|
||||
healAbsorbBar:SetPoint('RIGHT', self.Health:GetStatusBarTexture())
|
||||
healAbsorbBar:SetWidth(200)
|
||||
healAbsorbBar:SetReverseFill(true)
|
||||
|
||||
local overAbsorb = self.Health:CreateTexture(nil, "OVERLAY")
|
||||
overAbsorb:SetPoint('TOP')
|
||||
overAbsorb:SetPoint('BOTTOM')
|
||||
overAbsorb:SetPoint('LEFT', self.Health, 'RIGHT')
|
||||
overAbsorb:SetWidth(10)
|
||||
|
||||
local overHealAbsorb = self.Health:CreateTexture(nil, "OVERLAY")
|
||||
overHealAbsorb:SetPoint('TOP')
|
||||
overHealAbsorb:SetPoint('BOTTOM')
|
||||
overHealAbsorb:SetPoint('RIGHT', self.Health, 'LEFT')
|
||||
overHealAbsorb:SetWidth(10)
|
||||
|
||||
-- Register with oUF
|
||||
self.HealthPrediction = {
|
||||
myBar = myBar,
|
||||
otherBar = otherBar,
|
||||
absorbBar = absorbBar,
|
||||
healAbsorbBar = healAbsorbBar,
|
||||
overAbsorb = overAbsorb,
|
||||
overHealAbsorb = overHealAbsorb,
|
||||
maxOverflow = 1.05,
|
||||
}
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.HealthPrediction
|
||||
|
||||
--[[ Callback: HealthPrediction:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the HealthPrediction element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local myIncomingHeal = UnitGetIncomingHeals(unit, 'player') or 0
|
||||
local allIncomingHeal = UnitGetIncomingHeals(unit) or 0
|
||||
local absorb = UnitGetTotalAbsorbs(unit) or 0
|
||||
local healAbsorb = UnitGetTotalHealAbsorbs(unit) or 0
|
||||
local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit)
|
||||
local otherIncomingHeal = 0
|
||||
local hasOverHealAbsorb = false
|
||||
|
||||
if(healAbsorb > allIncomingHeal) then
|
||||
healAbsorb = healAbsorb - allIncomingHeal
|
||||
allIncomingHeal = 0
|
||||
myIncomingHeal = 0
|
||||
|
||||
if(health < healAbsorb) then
|
||||
hasOverHealAbsorb = true
|
||||
end
|
||||
else
|
||||
allIncomingHeal = allIncomingHeal - healAbsorb
|
||||
healAbsorb = 0
|
||||
|
||||
if(health + allIncomingHeal > maxHealth * element.maxOverflow) then
|
||||
allIncomingHeal = maxHealth * element.maxOverflow - health
|
||||
end
|
||||
|
||||
if(allIncomingHeal < myIncomingHeal) then
|
||||
myIncomingHeal = allIncomingHeal
|
||||
else
|
||||
otherIncomingHeal = allIncomingHeal - myIncomingHeal
|
||||
end
|
||||
end
|
||||
|
||||
local hasOverAbsorb = false
|
||||
if(health + allIncomingHeal + absorb >= maxHealth) and (absorb > 0) then
|
||||
hasOverAbsorb = true
|
||||
end
|
||||
|
||||
if(element.myBar) then
|
||||
element.myBar:SetMinMaxValues(0, maxHealth)
|
||||
element.myBar:SetValue(myIncomingHeal)
|
||||
element.myBar:Show()
|
||||
end
|
||||
|
||||
if(element.otherBar) then
|
||||
element.otherBar:SetMinMaxValues(0, maxHealth)
|
||||
element.otherBar:SetValue(otherIncomingHeal)
|
||||
element.otherBar:Show()
|
||||
end
|
||||
|
||||
if(element.absorbBar) then
|
||||
element.absorbBar:SetMinMaxValues(0, maxHealth)
|
||||
element.absorbBar:SetValue(absorb)
|
||||
element.absorbBar:Show()
|
||||
end
|
||||
|
||||
if(element.healAbsorbBar) then
|
||||
element.healAbsorbBar:SetMinMaxValues(0, maxHealth)
|
||||
element.healAbsorbBar:SetValue(healAbsorb)
|
||||
element.healAbsorbBar:Show()
|
||||
end
|
||||
|
||||
if(element.overAbsorb) then
|
||||
if(hasOverAbsorb) then
|
||||
element.overAbsorb:Show()
|
||||
else
|
||||
element.overAbsorb:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
if(element.overHealAbsorb) then
|
||||
if(hasOverHealAbsorb) then
|
||||
element.overHealAbsorb:Show()
|
||||
else
|
||||
element.overHealAbsorb:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Callback: HealthPrediction:PostUpdate(unit, myIncomingHeal, otherIncomingHeal, absorb, healAbsorb, hasOverAbsorb, hasOverHealAbsorb)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the HealthPrediction element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* myIncomingHeal - the amount of incoming healing done by the player (number)
|
||||
* otherIncomingHeal - the amount of incoming healing done by others (number)
|
||||
* absorb - the amount of damage the unit can absorb without losing health (number)
|
||||
* healAbsorb - the amount of healing the unit can absorb without gaining health (number)
|
||||
* hasOverAbsorb - indicates if the amount of damage absorb is higher than the unit's missing health (boolean)
|
||||
* hasOverHealAbsorb - indicates if the amount of heal absorb is higher than the unit's current health (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(unit, myIncomingHeal, otherIncomingHeal, absorb, healAbsorb, hasOverAbsorb, hasOverHealAbsorb, health, maxHealth)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: HealthPrediction.Override(self, event, unit)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event
|
||||
--]]
|
||||
return (self.HealthPrediction.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.HealthPrediction
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_HEALTH', Path)
|
||||
self:RegisterEvent('UNIT_MAXHEALTH', Path)
|
||||
self:RegisterEvent('UNIT_HEAL_PREDICTION', Path)
|
||||
self:RegisterEvent('UNIT_ABSORB_AMOUNT_CHANGED', Path)
|
||||
self:RegisterEvent('UNIT_HEAL_ABSORB_AMOUNT_CHANGED', Path)
|
||||
|
||||
if(not element.maxOverflow) then
|
||||
element.maxOverflow = 1.05
|
||||
end
|
||||
|
||||
if(element.myBar) then
|
||||
if(element.myBar:IsObjectType('StatusBar') and not element.myBar:GetStatusBarTexture()) then
|
||||
element.myBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
end
|
||||
|
||||
if(element.otherBar) then
|
||||
if(element.otherBar:IsObjectType('StatusBar') and not element.otherBar:GetStatusBarTexture()) then
|
||||
element.otherBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
end
|
||||
|
||||
if(element.absorbBar) then
|
||||
if(element.absorbBar:IsObjectType('StatusBar') and not element.absorbBar:GetStatusBarTexture()) then
|
||||
element.absorbBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
end
|
||||
|
||||
if(element.healAbsorbBar) then
|
||||
if(element.healAbsorbBar:IsObjectType('StatusBar') and not element.healAbsorbBar:GetStatusBarTexture()) then
|
||||
element.healAbsorbBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
end
|
||||
|
||||
if(element.overAbsorb) then
|
||||
if(element.overAbsorb:IsObjectType('Texture') and not element.overAbsorb:GetTexture()) then
|
||||
element.overAbsorb:SetTexture([[Interface\RaidFrame\Shield-Overshield]])
|
||||
element.overAbsorb:SetBlendMode('ADD')
|
||||
end
|
||||
end
|
||||
|
||||
if(element.overHealAbsorb) then
|
||||
if(element.overHealAbsorb:IsObjectType('Texture') and not element.overHealAbsorb:GetTexture()) then
|
||||
element.overHealAbsorb:SetTexture([[Interface\RaidFrame\Absorb-Overabsorb]])
|
||||
element.overHealAbsorb:SetBlendMode('ADD')
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.HealthPrediction
|
||||
if(element) then
|
||||
if(element.myBar) then
|
||||
element.myBar:Hide()
|
||||
end
|
||||
|
||||
if(element.otherBar) then
|
||||
element.otherBar:Hide()
|
||||
end
|
||||
|
||||
if(element.absorbBar) then
|
||||
element.absorbBar:Hide()
|
||||
end
|
||||
|
||||
if(element.healAbsorbBar) then
|
||||
element.healAbsorbBar:Hide()
|
||||
end
|
||||
|
||||
if(element.overAbsorb) then
|
||||
element.overAbsorb:Hide()
|
||||
end
|
||||
|
||||
if(element.overHealAbsorb) then
|
||||
element.overHealAbsorb:Hide()
|
||||
end
|
||||
|
||||
self:UnregisterEvent('UNIT_HEALTH', Path)
|
||||
self:UnregisterEvent('UNIT_MAXHEALTH', Path)
|
||||
self:UnregisterEvent('UNIT_HEAL_PREDICTION', Path)
|
||||
self:UnregisterEvent('UNIT_ABSORB_AMOUNT_CHANGED', Path)
|
||||
self:UnregisterEvent('UNIT_HEAL_ABSORB_AMOUNT_CHANGED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('HealthPrediction', Path, Enable, Disable)
|
||||
109
Libraries/oUF/elements/leaderindicator.lua
Normal file
109
Libraries/oUF/elements/leaderindicator.lua
Normal file
@@ -0,0 +1,109 @@
|
||||
--[[
|
||||
# Element: Leader Indicator
|
||||
|
||||
Toggles the visibility of an indicator based on the unit's leader status.
|
||||
|
||||
## Widget
|
||||
|
||||
LeaderIndicator - Any UI widget.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local LeaderIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
LeaderIndicator:SetSize(16, 16)
|
||||
LeaderIndicator:SetPoint('BOTTOM', self, 'TOP')
|
||||
|
||||
-- Register it with oUF
|
||||
self.LeaderIndicator = LeaderIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.LeaderIndicator
|
||||
local unit = self.unit
|
||||
|
||||
--[[ Callback: LeaderIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the LeaderIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
-- ElvUI changed block
|
||||
local isLeader
|
||||
if IsInInstance() then
|
||||
isLeader = UnitIsGroupLeader(unit)
|
||||
else
|
||||
isLeader = UnitLeadsAnyGroup(unit)
|
||||
end
|
||||
-- end block
|
||||
|
||||
if(isLeader) then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: LeaderIndicator:PostUpdate(isLeader)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the LeaderIndicator element
|
||||
* isLeader - indicates whether the element is shown (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(isLeader)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: LeaderIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.LeaderIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.LeaderIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('PARTY_LEADER_CHANGED', Path, true)
|
||||
self:RegisterEvent('GROUP_ROSTER_UPDATE', Path, true)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\GroupFrame\UI-Group-LeaderIcon]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.LeaderIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('PARTY_LEADER_CHANGED', Path)
|
||||
self:UnregisterEvent('GROUP_ROSTER_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('LeaderIndicator', Path, Enable, Disable)
|
||||
90
Libraries/oUF/elements/partyindicator.lua
Normal file
90
Libraries/oUF/elements/partyindicator.lua
Normal file
@@ -0,0 +1,90 @@
|
||||
--[[
|
||||
# Element: Party Indicator
|
||||
Toggles the visibility of an indicator based on if the player was in a group before joining the instance.
|
||||
|
||||
## Widget
|
||||
PartyIndicator - Player only widget.
|
||||
]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.PartyIndicator
|
||||
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local forced = not event or event == 'ElvUI_UpdateAllElements'
|
||||
if forced or event == 'GROUP_ROSTER_UPDATE' then
|
||||
if IsInGroup(LE_PARTY_CATEGORY_HOME) and IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
if forced or event == 'UPDATE_CHAT_COLOR' then
|
||||
local private = ChatTypeInfo.PARTY
|
||||
if private and element.HomeIcon then
|
||||
element.HomeIcon:SetVertexColor(private.r, private.g, private.b, 1)
|
||||
end
|
||||
|
||||
local public = ChatTypeInfo.INSTANCE_CHAT
|
||||
if public and element.InstanceIcon then
|
||||
element.InstanceIcon:SetVertexColor(public.r, public.g, public.b, 1)
|
||||
end
|
||||
end
|
||||
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate()
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: PartyIndicator.Override(self, event)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
--]]
|
||||
return (self.PartyIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.PartyIndicator
|
||||
if element then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UPDATE_CHAT_COLOR', Path, true)
|
||||
self:RegisterEvent('GROUP_ROSTER_UPDATE', Path, true)
|
||||
|
||||
if(element.HomeIcon and element.HomeIcon:IsObjectType('Texture') and not element.HomeIcon:GetTexture()) then
|
||||
element.HomeIcon:SetTexture([[Interface\FriendsFrame\UI-Toast-FriendOnlineIcon]])
|
||||
end
|
||||
|
||||
if(element.InstanceIcon and element.InstanceIcon:IsObjectType('Texture') and not element.InstanceIcon:GetTexture()) then
|
||||
element.InstanceIcon:SetTexture([[Interface\FriendsFrame\UI-Toast-FriendOnlineIcon]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.PartyIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UPDATE_CHAT_COLOR', Path)
|
||||
self:UnregisterEvent('GROUP_ROSTER_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('PartyIndicator', Path, Enable, Disable)
|
||||
159
Libraries/oUF/elements/phaseindicator.lua
Normal file
159
Libraries/oUF/elements/phaseindicator.lua
Normal file
@@ -0,0 +1,159 @@
|
||||
--[[
|
||||
# Element: Phasing Indicator
|
||||
|
||||
Toggles the visibility of an indicator based on the unit's phasing relative to the player.
|
||||
|
||||
## Widget
|
||||
|
||||
PhaseIndicator - Any UI widget.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
Icon - A `Texture` to represent the phased status.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
OnEnter and OnLeave script handlers will be set to display a Tooltip if the widget is mouse enabled and does not have
|
||||
OnEnter and/or OnLeave handlers.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local PhaseIndicator = CreateFrame('Frame', nil, self)
|
||||
PhaseIndicator:SetSize(16, 16)
|
||||
PhaseIndicator:SetPoint('TOPLEFT', self)
|
||||
PhaseIndicator:EnableMouse(true)
|
||||
|
||||
local Icon = PhaseIndicator:CreateTexture(nil, 'OVERLAY')
|
||||
Icon:SetAllPoints()
|
||||
PhaseIndicator.Icon = Icon
|
||||
|
||||
-- Register it with oUF
|
||||
self.PhaseIndicator = PhaseIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local GameTooltip = GameTooltip
|
||||
|
||||
--[[ Override: PhaseIndicator:UpdateTooltip()
|
||||
Used to populate the tooltip when the widget is hovered.
|
||||
|
||||
* self - the PhaseIndicator widget
|
||||
--]]
|
||||
local function UpdateTooltip(element)
|
||||
if GameTooltip:IsForbidden() then return end
|
||||
|
||||
local text = PartyUtil.GetPhasedReasonString(element.reason, element.__owner.unit)
|
||||
if(text) then
|
||||
GameTooltip:SetText(text, nil, nil, nil, nil, true)
|
||||
GameTooltip:Show()
|
||||
end
|
||||
end
|
||||
|
||||
local function onEnter(element)
|
||||
if GameTooltip:IsForbidden() or not element:IsVisible() then return end
|
||||
|
||||
if(element.reason) then
|
||||
GameTooltip:SetOwner(element, 'ANCHOR_BOTTOMRIGHT')
|
||||
element:UpdateTooltip()
|
||||
end
|
||||
end
|
||||
|
||||
local function onLeave()
|
||||
if GameTooltip:IsForbidden() then return end
|
||||
|
||||
GameTooltip:Hide()
|
||||
end
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.PhaseIndicator
|
||||
|
||||
--[[ Callback: PhaseIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the PhaseIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local phaseReason = UnitIsPlayer(unit) and UnitIsConnected(unit) and UnitPhaseReason(unit) or nil
|
||||
if(phaseReason) then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
element.reason = phaseReason
|
||||
|
||||
--[[ Callback: PhaseIndicator:PostUpdate(isInSamePhase, phaseReason)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the PhaseIndicator element
|
||||
* isInSamePhase - indicates whether the unit is in the same phase as the player (boolean)
|
||||
* phaseReason - the reason why the unit is in a different phase (number?)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(not phaseReason, phaseReason)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: PhaseIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.PhaseIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.PhaseIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_PHASE', Path)
|
||||
|
||||
local icon = (element.Icon or element)
|
||||
if(icon:IsObjectType('Texture') and not icon:GetTexture()) then
|
||||
icon:SetTexture([[Interface\TargetingFrame\UI-PhasingIcon]])
|
||||
end
|
||||
|
||||
if(element.IsMouseEnabled and element:IsMouseEnabled()) then
|
||||
if(not element:GetScript('OnEnter')) then
|
||||
element:SetScript('OnEnter', onEnter)
|
||||
end
|
||||
|
||||
if(not element:GetScript('OnLeave')) then
|
||||
element:SetScript('OnLeave', onLeave)
|
||||
end
|
||||
|
||||
element.UpdateTooltip = element.UpdateTooltip or UpdateTooltip
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.PhaseIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_PHASE', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('PhaseIndicator', Path, Enable, Disable)
|
||||
152
Libraries/oUF/elements/portrait.lua
Normal file
152
Libraries/oUF/elements/portrait.lua
Normal file
@@ -0,0 +1,152 @@
|
||||
--[[
|
||||
# Element: Portraits
|
||||
|
||||
Handles the updating of the unit's portrait.
|
||||
|
||||
## Widget
|
||||
|
||||
Portrait - A `PlayerModel` or a `Texture` used to represent the unit's portrait.
|
||||
|
||||
## Notes
|
||||
|
||||
A question mark model will be used if the widget is a PlayerModel and the client doesn't have the model information for
|
||||
the unit.
|
||||
|
||||
## Examples
|
||||
|
||||
-- 3D Portrait
|
||||
-- Position and size
|
||||
local Portrait = CreateFrame('PlayerModel', nil, self)
|
||||
Portrait:SetSize(32, 32)
|
||||
Portrait:SetPoint('RIGHT', self, 'LEFT')
|
||||
|
||||
-- Register it with oUF
|
||||
self.Portrait = Portrait
|
||||
|
||||
-- 2D Portrait
|
||||
local Portrait = self:CreateTexture(nil, 'OVERLAY')
|
||||
Portrait:SetSize(32, 32)
|
||||
Portrait:SetPoint('RIGHT', self, 'LEFT')
|
||||
|
||||
-- Register it with oUF
|
||||
self.Portrait = Portrait
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
-- ElvUI block
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
local UnitGUID = UnitGUID
|
||||
local UnitIsConnected = UnitIsConnected
|
||||
local UnitIsVisible = UnitIsVisible
|
||||
local SetPortraitTexture = SetPortraitTexture
|
||||
-- end block
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(not unit or not UnitIsUnit(self.unit, unit)) then return end
|
||||
|
||||
--[[ Callback: Portrait:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the Portrait element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
|
||||
local element = self.Portrait
|
||||
if(element.PreUpdate) then element:PreUpdate(unit) end
|
||||
|
||||
local guid = UnitGUID(unit)
|
||||
local isAvailable = UnitIsConnected(unit) and UnitIsVisible(unit)
|
||||
element.stateChanged = event ~= 'OnUpdate' or element.guid ~= guid or element.state ~= isAvailable
|
||||
if element.stateChanged then -- ElvUI changed
|
||||
element.playerModel = element:IsObjectType('PlayerModel')
|
||||
element.state = isAvailable
|
||||
element.guid = guid
|
||||
|
||||
if element.playerModel then
|
||||
if not isAvailable then
|
||||
element:SetCamDistanceScale(0.25)
|
||||
element:SetPortraitZoom(0)
|
||||
element:SetPosition(0, 0, 0.25)
|
||||
element:ClearModel()
|
||||
element:SetModel([[Interface\Buttons\TalkToMeQuestionMark.m2]])
|
||||
else
|
||||
element:SetCamDistanceScale(1)
|
||||
element:SetPortraitZoom(1)
|
||||
element:SetPosition(0, 0, 0)
|
||||
element:ClearModel()
|
||||
element:SetUnit(unit)
|
||||
end
|
||||
elseif not element.customTexture then -- ElvUI changed
|
||||
SetPortraitTexture(element, unit)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Callback: Portrait:PostUpdate(unit)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Portrait element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(unit, event)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: Portrait.Override(self, event, unit)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
return (self.Portrait.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.Portrait
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_MODEL_CHANGED', Path)
|
||||
self:RegisterEvent('UNIT_PORTRAIT_UPDATE', Path)
|
||||
self:RegisterEvent('PORTRAITS_UPDATED', Path, true)
|
||||
self:RegisterEvent('UNIT_CONNECTION', Path)
|
||||
|
||||
-- The quest log uses PARTY_MEMBER_{ENABLE,DISABLE} to handle updating of
|
||||
-- party members overlapping quests. This will probably be enough to handle
|
||||
-- model updating.
|
||||
--
|
||||
-- DISABLE isn't used as it fires when we most likely don't have the
|
||||
-- information we want.
|
||||
if(unit == 'party') then
|
||||
self:RegisterEvent('PARTY_MEMBER_ENABLE', Path)
|
||||
end
|
||||
|
||||
element:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Portrait
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_MODEL_CHANGED', Path)
|
||||
self:UnregisterEvent('UNIT_PORTRAIT_UPDATE', Path)
|
||||
self:UnregisterEvent('PORTRAITS_UPDATED', Path)
|
||||
self:UnregisterEvent('PARTY_MEMBER_ENABLE', Path)
|
||||
self:UnregisterEvent('UNIT_CONNECTION', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Portrait', Path, Enable, Disable)
|
||||
481
Libraries/oUF/elements/power.lua
Normal file
481
Libraries/oUF/elements/power.lua
Normal file
@@ -0,0 +1,481 @@
|
||||
--[[
|
||||
# Element: Power Bar
|
||||
|
||||
Handles the updating of a status bar that displays the unit's power.
|
||||
|
||||
## Widget
|
||||
|
||||
Power - A `StatusBar` used to represent the unit's power.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
.bg - A `Texture` used as a background. It will inherit the color of the main StatusBar.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a StatusBar and doesn't have a texture or a color set.
|
||||
|
||||
## Options
|
||||
|
||||
.frequentUpdates - Indicates whether to use UNIT_POWER_FREQUENT instead UNIT_POWER_UPDATE to update the
|
||||
bar (boolean)
|
||||
.displayAltPower - Use this to let the widget display alternative power, if the unit has one.
|
||||
By default, it does so only for raid and party units. If none, the display will fall
|
||||
back to the primary power (boolean)
|
||||
.useAtlas - Use this to let the widget use an atlas for its texture if an atlas is present in
|
||||
`self.colors.power` for the appropriate power type (boolean)
|
||||
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
|
||||
.considerSelectionInCombatHostile - Indicates whether selection should be considered hostile while the unit is in
|
||||
combat with the player (boolean)
|
||||
|
||||
The following options are listed by priority. The first check that returns true decides the color of the bar.
|
||||
|
||||
.colorDisconnected - Use `self.colors.disconnected` to color the bar if the unit is offline (boolean)
|
||||
.colorTapping - Use `self.colors.tapping` to color the bar if the unit isn't tapped by the player (boolean)
|
||||
.colorThreat - Use `self.colors.threat[threat]` to color the bar based on the unit's threat status. `threat` is
|
||||
defined by the first return of [UnitThreatSituation](https://wow.gamepedia.com/API_UnitThreatSituation) (boolean)
|
||||
.colorPower - Use `self.colors.power[token]` to color the bar based on the unit's power type. This method will
|
||||
fall-back to `:GetAlternativeColor()` if it can't find a color matching the token. If this function
|
||||
isn't defined, then it will attempt to color based upon the alternative power colors returned by
|
||||
[UnitPowerType](http://wowprogramming.com/docs/api/UnitPowerType.html). If these aren't
|
||||
defined, then it will attempt to color the bar based upon `self.colors.power[type]`. In case of
|
||||
failure it'll default to `self.colors.power.MANA` (boolean)
|
||||
.colorClass - Use `self.colors.class[class]` to color the bar based on unit class. `class` is defined by the
|
||||
second return of [UnitClass](http://wowprogramming.com/docs/api/UnitClass.html) (boolean)
|
||||
.colorClassNPC - Use `self.colors.class[class]` to color the bar if the unit is a NPC (boolean)
|
||||
.colorClassPet - Use `self.colors.class[class]` to color the bar if the unit is player controlled, but not a player
|
||||
(boolean)
|
||||
.colorSelection - Use `self.colors.selection[selection]` to color the bar based on the unit's selection color.
|
||||
`selection` is defined by the return value of Private.unitSelectionType, a wrapper function
|
||||
for [UnitSelectionType](https://wow.gamepedia.com/API_UnitSelectionType) (boolean)
|
||||
.colorReaction - Use `self.colors.reaction[reaction]` to color the bar based on the player's reaction towards the
|
||||
unit. `reaction` is defined by the return value of
|
||||
[UnitReaction](http://wowprogramming.com/docs/api/UnitReaction.html) (boolean)
|
||||
.colorSmooth - Use `smoothGradient` if present or `self.colors.smooth` to color the bar with a smooth gradient
|
||||
based on the player's current power percentage (boolean)
|
||||
|
||||
## Sub-Widget Options
|
||||
|
||||
.multiplier - A multiplier used to tint the background based on the main widgets R, G and B values. Defaults to 1
|
||||
(number)[0-1]
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local Power = CreateFrame('StatusBar', nil, self)
|
||||
Power:SetHeight(20)
|
||||
Power:SetPoint('BOTTOM')
|
||||
Power:SetPoint('LEFT')
|
||||
Power:SetPoint('RIGHT')
|
||||
|
||||
-- Add a background
|
||||
local Background = Power:CreateTexture(nil, 'BACKGROUND')
|
||||
Background:SetAllPoints(Power)
|
||||
Background:SetTexture(1, 1, 1, .5)
|
||||
|
||||
-- Options
|
||||
Power.frequentUpdates = true
|
||||
Power.colorTapping = true
|
||||
Power.colorDisconnected = true
|
||||
Power.colorPower = true
|
||||
Power.colorClass = true
|
||||
Power.colorReaction = true
|
||||
|
||||
-- Make the background darker.
|
||||
Background.multiplier = .5
|
||||
|
||||
-- Register it with oUF
|
||||
Power.bg = Background
|
||||
self.Power = Power
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local unitSelectionType = Private.unitSelectionType
|
||||
|
||||
-- sourced from FrameXML/UnitPowerBarAlt.lua
|
||||
local ALTERNATE_POWER_INDEX = Enum.PowerType.Alternate or 10
|
||||
|
||||
--[[ Override: Power:GetDisplayPower()
|
||||
Used to get info on the unit's alternative power, if any.
|
||||
Should return the power type index (see [Enum.PowerType.Alternate](https://wow.gamepedia.com/Enum_Unit.PowerType))
|
||||
and the minimum value for the given power type (see [info.minPower](https://wow.gamepedia.com/API_GetUnitPowerBarInfo))
|
||||
or nil if the unit has no alternative (alternate) power or it should not be
|
||||
displayed. In case of a nil return, the element defaults to the primary power
|
||||
type and zero for the minimum value.
|
||||
|
||||
* self - the Power element
|
||||
--]]
|
||||
local function GetDisplayPower(element)
|
||||
local unit = element.__owner.unit
|
||||
local barInfo = GetUnitPowerBarInfo(unit)
|
||||
if(barInfo and barInfo.showOnRaid and (UnitInParty(unit) or UnitInRaid(unit))) then
|
||||
return ALTERNATE_POWER_INDEX, barInfo.minPower
|
||||
end
|
||||
end
|
||||
|
||||
local function UpdateColor(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
local element = self.Power
|
||||
|
||||
local pType, pToken, altR, altG, altB = UnitPowerType(unit)
|
||||
|
||||
local r, g, b, t, atlas
|
||||
if(element.colorDisconnected and not UnitIsConnected(unit)) then
|
||||
t = self.colors.disconnected
|
||||
elseif(element.colorTapping and not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)) then
|
||||
t = self.colors.tapped
|
||||
elseif(element.colorThreat and not UnitPlayerControlled(unit) and UnitThreatSituation('player', unit)) then
|
||||
t = self.colors.threat[UnitThreatSituation('player', unit)]
|
||||
elseif(element.colorPower) then
|
||||
if(element.displayType ~= ALTERNATE_POWER_INDEX) then
|
||||
t = self.colors.power[pToken]
|
||||
if(not t) then
|
||||
if(element.GetAlternativeColor) then
|
||||
r, g, b = element:GetAlternativeColor(unit, pType, pToken, altR, altG, altB)
|
||||
elseif(altR) then
|
||||
r, g, b = altR, altG, altB
|
||||
if(r > 1 or g > 1 or b > 1) then
|
||||
-- BUG: As of 7.0.3, altR, altG, altB may be in 0-1 or 0-255 range.
|
||||
r, g, b = r / 255, g / 255, b / 255
|
||||
end
|
||||
else
|
||||
t = self.colors.power[pType] or self.colors.power.MANA
|
||||
end
|
||||
end
|
||||
else
|
||||
t = self.colors.power[ALTERNATE_POWER_INDEX]
|
||||
end
|
||||
|
||||
if(element.useAtlas and t and t.atlas) then
|
||||
atlas = t.atlas
|
||||
end
|
||||
elseif(element.colorClass and UnitIsPlayer(unit))
|
||||
or (element.colorClassNPC and not UnitIsPlayer(unit))
|
||||
or (element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
|
||||
local _, class = UnitClass(unit)
|
||||
t = self.colors.class[class]
|
||||
elseif(element.colorSelection and unitSelectionType(unit, element.considerSelectionInCombatHostile)) then
|
||||
t = self.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
|
||||
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
|
||||
t = self.colors.reaction[UnitReaction(unit, 'player')]
|
||||
elseif(element.colorSmooth) then
|
||||
local adjust = 0 - (element.min or 0)
|
||||
r, g, b = self:ColorGradient((element.cur or 1) + adjust, (element.max or 1) + adjust, unpack(element.smoothGradient or self.colors.smooth))
|
||||
end
|
||||
|
||||
if(t) then
|
||||
r, g, b = t[1], t[2], t[3]
|
||||
end
|
||||
|
||||
if(atlas) then
|
||||
element:SetStatusBarAtlas(atlas)
|
||||
element:SetStatusBarColor(1, 1, 1)
|
||||
elseif(b) then
|
||||
element:SetStatusBarColor(r, g, b)
|
||||
|
||||
local bg = element.bg
|
||||
if(bg) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Callback: Power:PostUpdateColor(unit, r, g, b)
|
||||
Called after the element color has been updated.
|
||||
|
||||
local bg = element.bg
|
||||
if(bg and b) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
--]]
|
||||
|
||||
if(element.PostUpdateColor) then
|
||||
element:PostUpdateColor(unit, r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function ColorPath(self, ...)
|
||||
--[[ Override: Power.UpdateColor(self, event, unit)
|
||||
Used to completely override the internal function for updating the widgets' colors.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.Power.UpdateColor or UpdateColor) (self, ...)
|
||||
end
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
local element = self.Power
|
||||
|
||||
--[[ Callback: Power:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the Power element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local displayType, min
|
||||
if(element.displayAltPower) then
|
||||
displayType, min = element:GetDisplayPower()
|
||||
end
|
||||
|
||||
local cur, max = UnitPower(unit, displayType), UnitPowerMax(unit, displayType)
|
||||
if not min then min = 0 end
|
||||
|
||||
element:SetMinMaxValues(min, max)
|
||||
|
||||
if(UnitIsConnected(unit)) then
|
||||
element:SetValue(cur)
|
||||
else
|
||||
element:SetValue(max)
|
||||
end
|
||||
|
||||
element.cur = cur
|
||||
element.min = min
|
||||
element.max = max
|
||||
element.displayType = displayType
|
||||
|
||||
--[[ Callback: Power:PostUpdate(unit, cur, min, max)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Power element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* cur - the unit's current power value (number)
|
||||
* min - the unit's minimum possible power value (number)
|
||||
* max - the unit's maximum possible power value (number)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
element:PostUpdate(unit, cur, min, max)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, event, ...)
|
||||
if (self.isForced and event ~= 'ElvUI_UpdateAllElements') then return end -- ElvUI changed
|
||||
|
||||
--[[ Override: Power.Override(self, event, unit, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
(self.Power.Override or Update) (self, event, ...);
|
||||
|
||||
ColorPath(self, event, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
--[[ Power:SetColorDisconnected(state, isForced)
|
||||
Used to toggle coloring if the unit is offline.
|
||||
|
||||
* self - the Power element
|
||||
* state - the desired state (boolean)
|
||||
* isForced - forces the event update even if the state wasn't changed (boolean)
|
||||
--]]
|
||||
local function SetColorDisconnected(element, state, isForced)
|
||||
if(element.colorDisconnected ~= state or isForced) then
|
||||
element.colorDisconnected = state
|
||||
if(state) then
|
||||
element.__owner:RegisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Power:SetColorSelection(state, isForced)
|
||||
Used to toggle coloring by the unit's selection.
|
||||
|
||||
* self - the Power element
|
||||
* state - the desired state (boolean)
|
||||
* isForced - forces the event update even if the state wasn't changed (boolean)
|
||||
--]]
|
||||
local function SetColorSelection(element, state, isForced)
|
||||
if(element.colorSelection ~= state or isForced) then
|
||||
element.colorSelection = state
|
||||
if(state) then
|
||||
element.__owner:RegisterEvent('UNIT_FLAGS', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_FLAGS', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Power:SetColorTapping(state, isForced)
|
||||
Used to toggle coloring if the unit isn't tapped by the player.
|
||||
|
||||
* self - the Power element
|
||||
* state - the desired state (boolean)
|
||||
* isForced - forces the event update even if the state wasn't changed (boolean)
|
||||
--]]
|
||||
local function SetColorTapping(element, state, isForced)
|
||||
if(element.colorTapping ~= state or isForced) then
|
||||
element.colorTapping = state
|
||||
if(state) then
|
||||
element.__owner:RegisterEvent('UNIT_FACTION', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_FACTION', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Power:SetColorThreat(state, isForced)
|
||||
Used to toggle coloring by the unit's threat status.
|
||||
|
||||
* self - the Power element
|
||||
* state - the desired state (boolean)
|
||||
* isForced - forces the event update even if the state wasn't changed (boolean)
|
||||
--]]
|
||||
local function SetColorThreat(element, state, isForced)
|
||||
if(element.colorThreat ~= state or isForced) then
|
||||
element.colorThreat = state
|
||||
if(state) then
|
||||
element.__owner:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Power:SetFrequentUpdates(state, isForced)
|
||||
Used to toggle frequent updates.
|
||||
|
||||
* self - the Power element
|
||||
* state - the desired state (boolean)
|
||||
* isForced - forces the event update even if the state wasn't changed (boolean)
|
||||
--]]
|
||||
local function SetFrequentUpdates(element, state, isForced)
|
||||
if(element.frequentUpdates ~= state or isForced) then
|
||||
element.frequentUpdates = state
|
||||
if(state) then
|
||||
element.__owner:UnregisterEvent('UNIT_POWER_UPDATE', Path)
|
||||
element.__owner:RegisterEvent('UNIT_POWER_FREQUENT', Path)
|
||||
else
|
||||
element.__owner:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
|
||||
element.__owner:RegisterEvent('UNIT_POWER_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ElvUI changed block
|
||||
local onUpdateElapsed, onUpdateWait = 0, 0.25
|
||||
local function onUpdatePower(self, elapsed)
|
||||
if onUpdateElapsed > onUpdateWait then
|
||||
Path(self.__owner, 'OnUpdate', self.__owner.unit)
|
||||
|
||||
onUpdateElapsed = 0
|
||||
else
|
||||
onUpdateElapsed = onUpdateElapsed + elapsed
|
||||
end
|
||||
end
|
||||
|
||||
local function SetPowerUpdateSpeed(self, state)
|
||||
onUpdateWait = state
|
||||
end
|
||||
|
||||
local function SetPowerUpdateMethod(self, state, force)
|
||||
if self.effectivePower ~= state or force then
|
||||
self.effectivePower = state
|
||||
|
||||
if state then
|
||||
self.Power:SetScript('OnUpdate', onUpdatePower)
|
||||
self:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
|
||||
self:UnregisterEvent('UNIT_POWER_UPDATE', Path)
|
||||
self:UnregisterEvent('UNIT_MAXPOWER', Path)
|
||||
else
|
||||
self.Power:SetScript('OnUpdate', nil)
|
||||
self:RegisterEvent('UNIT_MAXPOWER', Path)
|
||||
if self.Power.frequentUpdates then
|
||||
self:RegisterEvent('UNIT_POWER_FREQUENT', Path)
|
||||
else
|
||||
self:RegisterEvent('UNIT_POWER_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- end block
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.Power
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
element.SetColorDisconnected = SetColorDisconnected
|
||||
element.SetColorSelection = SetColorSelection
|
||||
element.SetColorTapping = SetColorTapping
|
||||
element.SetColorThreat = SetColorThreat
|
||||
element.SetFrequentUpdates = SetFrequentUpdates
|
||||
|
||||
-- ElvUI changed block
|
||||
self.SetPowerUpdateSpeed = SetPowerUpdateSpeed
|
||||
self.SetPowerUpdateMethod = SetPowerUpdateMethod
|
||||
SetPowerUpdateMethod(self, self.effectivePower, true)
|
||||
-- end block
|
||||
|
||||
if(element.colorDisconnected) then
|
||||
self:RegisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorSelection) then
|
||||
self:RegisterEvent('UNIT_FLAGS', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorTapping) then
|
||||
self:RegisterEvent('UNIT_FACTION', ColorPath)
|
||||
end
|
||||
|
||||
if(element.colorThreat) then
|
||||
self:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
|
||||
self:RegisterEvent('UNIT_DISPLAYPOWER', Path)
|
||||
self:RegisterEvent('UNIT_POWER_BAR_HIDE', Path)
|
||||
self:RegisterEvent('UNIT_POWER_BAR_SHOW', Path)
|
||||
|
||||
if(element:IsObjectType('StatusBar') and not (element:GetStatusBarTexture() or element:GetStatusBarAtlas())) then
|
||||
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
|
||||
if(not element.GetDisplayPower) then
|
||||
element.GetDisplayPower = GetDisplayPower
|
||||
end
|
||||
|
||||
element:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Power
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
element:SetScript('OnUpdate', nil) -- ElvUI changed
|
||||
self:UnregisterEvent('UNIT_DISPLAYPOWER', Path)
|
||||
self:UnregisterEvent('UNIT_MAXPOWER', Path)
|
||||
self:UnregisterEvent('UNIT_POWER_BAR_HIDE', Path)
|
||||
self:UnregisterEvent('UNIT_POWER_BAR_SHOW', Path)
|
||||
self:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
|
||||
self:UnregisterEvent('UNIT_POWER_UPDATE', Path)
|
||||
self:UnregisterEvent('UNIT_CONNECTION', ColorPath)
|
||||
self:UnregisterEvent('UNIT_FACTION', ColorPath)
|
||||
self:UnregisterEvent('UNIT_FLAGS', ColorPath)
|
||||
self:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Power', Path, Enable, Disable)
|
||||
194
Libraries/oUF/elements/powerprediction.lua
Normal file
194
Libraries/oUF/elements/powerprediction.lua
Normal file
@@ -0,0 +1,194 @@
|
||||
--[[
|
||||
# Element: Power Prediction Bar
|
||||
|
||||
Handles the visibility and updating of power cost prediction.
|
||||
|
||||
## Widget
|
||||
|
||||
PowerPrediction - A `table` containing the sub-widgets.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
mainBar - A `StatusBar` used to represent power cost of spells on top of the Power element.
|
||||
altBar - A `StatusBar` used to represent power cost of spells on top of the AdditionalPower element.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a StatusBar and doesn't have a texture set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local mainBar = CreateFrame('StatusBar', nil, self.Power)
|
||||
mainBar:SetReverseFill(true)
|
||||
mainBar:SetPoint('TOP')
|
||||
mainBar:SetPoint('BOTTOM')
|
||||
mainBar:SetPoint('RIGHT', self.Power:GetStatusBarTexture(), 'RIGHT')
|
||||
mainBar:SetWidth(200)
|
||||
|
||||
local altBar = CreateFrame('StatusBar', nil, self.AdditionalPower)
|
||||
altBar:SetReverseFill(true)
|
||||
altBar:SetPoint('TOP')
|
||||
altBar:SetPoint('BOTTOM')
|
||||
altBar:SetPoint('RIGHT', self.AdditionalPower:GetStatusBarTexture(), 'RIGHT')
|
||||
altBar:SetWidth(200)
|
||||
|
||||
-- Register with oUF
|
||||
self.PowerPrediction = {
|
||||
mainBar = mainBar,
|
||||
altBar = altBar
|
||||
}
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
-- sourced from FrameXML/AlternatePowerBar.lua
|
||||
local ADDITIONAL_POWER_BAR_INDEX = ADDITIONAL_POWER_BAR_INDEX or 0
|
||||
local ALT_MANA_BAR_PAIR_DISPLAY_INFO = ALT_MANA_BAR_PAIR_DISPLAY_INFO
|
||||
|
||||
local _, playerClass = UnitClass('player')
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.PowerPrediction
|
||||
|
||||
--[[ Callback: PowerPrediction:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the PowerPrediction element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local mainCost, altCost = 0, 0
|
||||
local mainType = UnitPowerType(unit)
|
||||
local mainMax = UnitPowerMax(unit, mainType)
|
||||
local isPlayer = UnitIsUnit('player', unit)
|
||||
local altManaInfo = isPlayer and ALT_MANA_BAR_PAIR_DISPLAY_INFO[playerClass]
|
||||
local hasAltManaBar = altManaInfo and altManaInfo[mainType]
|
||||
local _, _, _, startTime, endTime, _, _, _, spellID = UnitCastingInfo(unit)
|
||||
|
||||
if(event == 'UNIT_SPELLCAST_START' and startTime ~= endTime) then
|
||||
local costTable = GetSpellPowerCost(spellID)
|
||||
local checkRequiredAura = isPlayer and #costTable > 1
|
||||
for _, costInfo in next, costTable do
|
||||
local cost, ctype, cperc = costInfo.cost, costInfo.type, costInfo.costPercent
|
||||
local checkSpec = not checkRequiredAura or costInfo.hasRequiredAura
|
||||
if checkSpec and ctype == mainType then
|
||||
mainCost = ((isPlayer or cost < mainMax) and cost) or (mainMax * cperc) / 100
|
||||
element.mainCost = mainCost
|
||||
|
||||
break
|
||||
elseif hasAltManaBar and checkSpec and ctype == ADDITIONAL_POWER_BAR_INDEX then
|
||||
altCost = cost
|
||||
element.altCost = altCost
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
elseif(spellID) then
|
||||
-- if we try to cast a spell while casting another one we need to avoid
|
||||
-- resetting the element
|
||||
mainCost = element.mainCost or 0
|
||||
altCost = element.altCost or 0
|
||||
else
|
||||
element.mainCost = mainCost
|
||||
element.altCost = altCost
|
||||
end
|
||||
|
||||
if(element.mainBar) then
|
||||
element.mainBar:SetMinMaxValues(0, mainMax)
|
||||
element.mainBar:SetValue(mainCost)
|
||||
element.mainBar:Show()
|
||||
end
|
||||
|
||||
if(element.altBar and hasAltManaBar) then
|
||||
element.altBar:SetMinMaxValues(0, UnitPowerMax(unit, ADDITIONAL_POWER_BAR_INDEX))
|
||||
element.altBar:SetValue(altCost)
|
||||
element.altBar:Show()
|
||||
end
|
||||
|
||||
--[[ Callback: PowerPrediction:PostUpdate(unit, mainCost, altCost, hasAltManaBar)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the PowerPrediction element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* mainCost - the main power type cost of the cast ability (number)
|
||||
* altCost - the secondary power type cost of the cast ability (number)
|
||||
* hasAltManaBar - indicates if the unit has a secondary power bar (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(unit, mainCost, altCost, hasAltManaBar)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: PowerPrediction.Override(self, event, unit, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.PowerPrediction.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.PowerPrediction
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_SPELLCAST_START', Path)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_STOP', Path)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_FAILED', Path)
|
||||
self:RegisterEvent('UNIT_SPELLCAST_SUCCEEDED', Path)
|
||||
self:RegisterEvent('UNIT_DISPLAYPOWER', Path)
|
||||
|
||||
if(element.mainBar) then
|
||||
if(element.mainBar:IsObjectType('StatusBar')
|
||||
and not (element.mainBar:GetStatusBarTexture() or element.mainBar:GetStatusBarAtlas())) then
|
||||
element.mainBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
end
|
||||
|
||||
if(element.altBar) then
|
||||
if(element.altBar:IsObjectType('StatusBar')
|
||||
and not (element.altBar:GetStatusBarTexture() or element.altBar:GetStatusBarAtlas())) then
|
||||
element.altBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.PowerPrediction
|
||||
if(element) then
|
||||
if(element.mainBar) then
|
||||
element.mainBar:Hide()
|
||||
end
|
||||
|
||||
if(element.altBar) then
|
||||
element.altBar:Hide()
|
||||
end
|
||||
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_START', Path)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_STOP', Path)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_FAILED', Path)
|
||||
self:UnregisterEvent('UNIT_SPELLCAST_SUCCEEDED', Path)
|
||||
self:UnregisterEvent('UNIT_DISPLAYPOWER', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('PowerPrediction', Path, Enable, Disable)
|
||||
119
Libraries/oUF/elements/pvpclassificationindicator.lua
Normal file
119
Libraries/oUF/elements/pvpclassificationindicator.lua
Normal file
@@ -0,0 +1,119 @@
|
||||
--[[
|
||||
# Element: PvPClassificationIndicator
|
||||
|
||||
Handles the visibility and updating of an indicator based on the unit's PvP classification.
|
||||
|
||||
## Widget
|
||||
|
||||
PvPClassificationIndicator - A `Texture` used to display PvP classification.
|
||||
|
||||
## Notes
|
||||
|
||||
This element updates by changing the texture.
|
||||
|
||||
## Options
|
||||
|
||||
.useAtlasSize - Makes the element use preprogrammed atlas' size instead of its set dimensions (boolean)
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local PvPClassificationIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
PvPClassificationIndicator:SetSize(24, 24)
|
||||
PvPClassificationIndicator:SetPoint('CENTER')
|
||||
|
||||
-- Register it with oUF
|
||||
self.PvPClassificationIndicator = PvPClassificationIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
-- sourced from FrameXML/CompactUnitFrame.lua
|
||||
local ICONS = {
|
||||
[Enum.PvPUnitClassification.FlagCarrierHorde or 0] = "nameplates-icon-flag-horde",
|
||||
[Enum.PvPUnitClassification.FlagCarrierAlliance or 1] = "nameplates-icon-flag-alliance",
|
||||
[Enum.PvPUnitClassification.FlagCarrierNeutral or 2] = "nameplates-icon-flag-neutral",
|
||||
[Enum.PvPUnitClassification.CartRunnerHorde or 3] = "nameplates-icon-cart-horde",
|
||||
[Enum.PvPUnitClassification.CartRunnerAlliance or 4] = "nameplates-icon-cart-alliance",
|
||||
[Enum.PvPUnitClassification.AssassinHorde or 5] = "nameplates-icon-bounty-horde",
|
||||
[Enum.PvPUnitClassification.AssassinAlliance or 6] = "nameplates-icon-bounty-alliance",
|
||||
[Enum.PvPUnitClassification.OrbCarrierBlue or 7] = "nameplates-icon-orb-blue",
|
||||
[Enum.PvPUnitClassification.OrbCarrierGreen or 8] = "nameplates-icon-orb-green",
|
||||
[Enum.PvPUnitClassification.OrbCarrierOrange or 9] = "nameplates-icon-orb-orange",
|
||||
[Enum.PvPUnitClassification.OrbCarrierPurple or 10] = "nameplates-icon-orb-purple",
|
||||
}
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(unit ~= self.unit) then return end
|
||||
|
||||
local element = self.PvPClassificationIndicator
|
||||
|
||||
--[[ Callback: PvPClassificationIndicator:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the PvPClassificationIndicator element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local class = UnitPvpClassification(unit)
|
||||
local icon = ICONS[class]
|
||||
if(icon) then
|
||||
element:SetAtlas(icon, element.useAtlasSize)
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: PvPClassificationIndicator:PostUpdate(unit, class)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the PvPClassificationIndicator element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* class - the pvp classification of the unit (number?)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(unit, class)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[Override: PvPClassificationIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.PvPClassificationIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.PvPClassificationIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_CLASSIFICATION_CHANGED', Path)
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.PvPClassificationIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_CLASSIFICATION_CHANGED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('PvPClassificationIndicator', Path, Enable, Disable)
|
||||
151
Libraries/oUF/elements/pvpindicator.lua
Normal file
151
Libraries/oUF/elements/pvpindicator.lua
Normal file
@@ -0,0 +1,151 @@
|
||||
--[[
|
||||
# Element: PvP and Honor Level Icons
|
||||
|
||||
Handles the visibility and updating of an indicator based on the unit's PvP status and honor level.
|
||||
|
||||
## Widget
|
||||
|
||||
PvPIndicator - A `Texture` used to display faction, FFA PvP status or honor level icon.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
Badge - A `Texture` used to display the honor badge background image.
|
||||
|
||||
## Notes
|
||||
|
||||
This element updates by changing the texture.
|
||||
The `Badge` sub-widget has to be on a lower sub-layer than the `PvP` texture.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local PvPIndicator = self:CreateTexture(nil, 'ARTWORK', nil, 1)
|
||||
PvPIndicator:SetSize(30, 30)
|
||||
PvPIndicator:SetPoint('RIGHT', self, 'LEFT')
|
||||
|
||||
local Badge = self:CreateTexture(nil, 'ARTWORK')
|
||||
Badge:SetSize(50, 52)
|
||||
Badge:SetPoint('CENTER', PvPIndicator, 'CENTER')
|
||||
|
||||
-- Register it with oUF
|
||||
PvPIndicator.Badge = Badge
|
||||
self.PvPIndicator = PvPIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(unit and unit ~= self.unit) then return end
|
||||
|
||||
local element = self.PvPIndicator
|
||||
unit = unit or self.unit
|
||||
|
||||
--[[ Callback: PvPIndicator:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the PvPIndicator element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate(unit)
|
||||
end
|
||||
|
||||
local status
|
||||
local factionGroup = UnitFactionGroup(unit) or 'Neutral'
|
||||
local honorRewardInfo = C_PvP.GetHonorRewardInfo(UnitHonorLevel(unit))
|
||||
|
||||
if(UnitIsPVPFreeForAll(unit)) then
|
||||
status = 'FFA'
|
||||
elseif(factionGroup ~= 'Neutral' and UnitIsPVP(unit)) then
|
||||
if(unit == 'player' and UnitIsMercenary(unit)) then
|
||||
if(factionGroup == 'Horde') then
|
||||
factionGroup = 'Alliance'
|
||||
elseif(factionGroup == 'Alliance') then
|
||||
factionGroup = 'Horde'
|
||||
end
|
||||
end
|
||||
|
||||
status = factionGroup
|
||||
end
|
||||
|
||||
if(status) then
|
||||
element:Show()
|
||||
|
||||
if(element.Badge and honorRewardInfo) then
|
||||
element:SetTexture(honorRewardInfo.badgeFileDataID)
|
||||
element:SetTexCoord(0, 1, 0, 1)
|
||||
element.Badge:SetAtlas('honorsystem-portrait-' .. factionGroup, false)
|
||||
element.Badge:Show()
|
||||
else
|
||||
element:SetTexture([[Interface\TargetingFrame\UI-PVP-]] .. status)
|
||||
element:SetTexCoord(0, 0.65625, 0, 0.65625)
|
||||
|
||||
if(element.Badge) then
|
||||
element.Badge:Hide()
|
||||
end
|
||||
end
|
||||
else
|
||||
element:Hide()
|
||||
|
||||
if(element.Badge) then
|
||||
element.Badge:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Callback: PvPIndicator:PostUpdate(unit, status)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the PvPIndicator element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* status - the unit's current PvP status or faction accounting for mercenary mode (string)['FFA', 'Alliance',
|
||||
'Horde']
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(unit, status)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[Override: PvPIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.PvPIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.PvPIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_FACTION', Path)
|
||||
self:RegisterEvent('HONOR_LEVEL_UPDATE', Path, true)
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.PvPIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
if(element.Badge) then
|
||||
element.Badge:Hide()
|
||||
end
|
||||
|
||||
self:UnregisterEvent('UNIT_FACTION', Path)
|
||||
self:UnregisterEvent('HONOR_LEVEL_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('PvPIndicator', Path, Enable, Disable)
|
||||
100
Libraries/oUF/elements/questindicator.lua
Normal file
100
Libraries/oUF/elements/questindicator.lua
Normal file
@@ -0,0 +1,100 @@
|
||||
--[[
|
||||
# Element: Quest Indicator
|
||||
|
||||
Handles the visibility and updating of an indicator based on the unit's involvement in a quest.
|
||||
|
||||
## Widget
|
||||
|
||||
QuestIndicator - Any UI widget.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local QuestIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
QuestIndicator:SetSize(16, 16)
|
||||
QuestIndicator:SetPoint('TOPRIGHT', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.QuestIndicator = QuestIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(unit ~= self.unit) then return end
|
||||
|
||||
local element = self.QuestIndicator
|
||||
|
||||
--[[ Callback: QuestIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the QuestIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local isQuestBoss = UnitIsQuestBoss(unit)
|
||||
if(isQuestBoss) then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: QuestIndicator:PostUpdate(isQuestBoss)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the QuestIndicator element
|
||||
* isQuestBoss - indicates if the element is shown (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(isQuestBoss)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: QuestIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.QuestIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.QuestIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_CLASSIFICATION_CHANGED', Path)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\TargetingFrame\PortraitQuestBadge]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.QuestIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_CLASSIFICATION_CHANGED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('QuestIndicator', Path, Enable, Disable)
|
||||
106
Libraries/oUF/elements/raidroleindicator.lua
Normal file
106
Libraries/oUF/elements/raidroleindicator.lua
Normal file
@@ -0,0 +1,106 @@
|
||||
--[[
|
||||
# Element: Raid Role Indicator
|
||||
|
||||
Handles the visibility and updating of an indicator based on the unit's raid assignment (main tank or main assist).
|
||||
|
||||
## Widget
|
||||
|
||||
RaidRoleIndicator - A `Texture` representing the unit's raid assignment.
|
||||
|
||||
## Notes
|
||||
|
||||
This element updates by changing the texture.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local RaidRoleIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
RaidRoleIndicator:SetSize(16, 16)
|
||||
RaidRoleIndicator:SetPoint('TOPLEFT')
|
||||
|
||||
-- Register it with oUF
|
||||
self.RaidRoleIndicator = RaidRoleIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local MAINTANK_ICON = [[Interface\GROUPFRAME\UI-GROUP-MAINTANKICON]]
|
||||
local MAINASSIST_ICON = [[Interface\GROUPFRAME\UI-GROUP-MAINASSISTICON]]
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.RaidRoleIndicator
|
||||
local unit = self.unit
|
||||
|
||||
--[[ Callback: RaidRoleIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the RaidRoleIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local role, isShown
|
||||
if(UnitInRaid(unit) and not UnitHasVehicleUI(unit)) then
|
||||
if(GetPartyAssignment('MAINTANK', unit)) then
|
||||
isShown = true
|
||||
element:SetTexture(MAINTANK_ICON)
|
||||
role = 'MAINTANK'
|
||||
elseif(GetPartyAssignment('MAINASSIST', unit)) then
|
||||
isShown = true
|
||||
element:SetTexture(MAINASSIST_ICON)
|
||||
role = 'MAINASSIST'
|
||||
end
|
||||
end
|
||||
|
||||
element:SetShown(isShown)
|
||||
|
||||
--[[ Callback: RaidRoleIndicator:PostUpdate(role)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the RaidRoleIndicator element
|
||||
* role - the unit's raid assignment (string?)['MAINTANK', 'MAINASSIST']
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(role)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: RaidRoleIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.RaidRoleIndicator.Override or Update)(self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.RaidRoleIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('GROUP_ROSTER_UPDATE', Path, true)
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.RaidRoleIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('GROUP_ROSTER_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('RaidRoleIndicator', Path, Enable, Disable)
|
||||
102
Libraries/oUF/elements/raidtargetindicator.lua
Normal file
102
Libraries/oUF/elements/raidtargetindicator.lua
Normal file
@@ -0,0 +1,102 @@
|
||||
--[[
|
||||
# Element: Raid Target Indicator
|
||||
|
||||
Handles the visibility and updating of an indicator based on the unit's raid target assignment.
|
||||
|
||||
## Widget
|
||||
|
||||
RaidTargetIndicator - A `Texture` used to display the raid target icon.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local RaidTargetIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
RaidTargetIndicator:SetSize(16, 16)
|
||||
RaidTargetIndicator:SetPoint('TOPRIGHT', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.RaidTargetIndicator = RaidTargetIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local GetRaidTargetIndex = GetRaidTargetIndex
|
||||
local SetRaidTargetIconTexture = SetRaidTargetIconTexture
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.RaidTargetIndicator
|
||||
|
||||
--[[ Callback: RaidTargetIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the RaidTargetIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local index = GetRaidTargetIndex(self.unit)
|
||||
if(index) then
|
||||
SetRaidTargetIconTexture(element, index)
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: RaidTargetIndicator:PostUpdate(index)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the RaidTargetIndicator element
|
||||
* index - the index of the raid target marker (number?)[1-8]
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(index)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: RaidTargetIndicator.Override(self, event)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
--]]
|
||||
return (self.RaidTargetIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
if(not element.__owner.unit) then return end
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.RaidTargetIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('RAID_TARGET_UPDATE', Path, true)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\TargetingFrame\UI-RaidTargetingIcons]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.RaidTargetIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('RAID_TARGET_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('RaidTargetIndicator', Path, Enable, Disable)
|
||||
138
Libraries/oUF/elements/range.lua
Normal file
138
Libraries/oUF/elements/range.lua
Normal file
@@ -0,0 +1,138 @@
|
||||
--[[
|
||||
# Element: Range Fader
|
||||
|
||||
Changes the opacity of a unit frame based on whether the frame's unit is in the player's range.
|
||||
|
||||
## Widget
|
||||
|
||||
Range - A table containing opacity values.
|
||||
|
||||
## Notes
|
||||
|
||||
Offline units are handled as if they are in range.
|
||||
|
||||
## Options
|
||||
|
||||
.outsideAlpha - Opacity when the unit is out of range. Defaults to 0.55 (number)[0-1].
|
||||
.insideAlpha - Opacity when the unit is within range. Defaults to 1 (number)[0-1].
|
||||
|
||||
## Examples
|
||||
|
||||
-- Register with oUF
|
||||
self.Range = {
|
||||
insideAlpha = 1,
|
||||
outsideAlpha = 1/2,
|
||||
}
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local _FRAMES = {}
|
||||
local OnRangeFrame
|
||||
|
||||
local UnitInRange, UnitIsConnected = UnitInRange, UnitIsConnected
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.Range
|
||||
local unit = self.unit
|
||||
|
||||
--[[ Callback: Range:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the Range element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local inRange, checkedRange
|
||||
local connected = UnitIsConnected(unit)
|
||||
if(connected) then
|
||||
inRange, checkedRange = UnitInRange(unit)
|
||||
if(checkedRange and not inRange) then
|
||||
self:SetAlpha(element.outsideAlpha)
|
||||
else
|
||||
self:SetAlpha(element.insideAlpha)
|
||||
end
|
||||
else
|
||||
self:SetAlpha(element.insideAlpha)
|
||||
end
|
||||
|
||||
--[[ Callback: Range:PostUpdate(object, inRange, checkedRange, isConnected)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Range element
|
||||
* object - the parent object
|
||||
* inRange - indicates if the unit was within 40 yards of the player (boolean)
|
||||
* checkedRange - indicates if the range check was actually performed (boolean)
|
||||
* isConnected - indicates if the unit is online (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(self, inRange, checkedRange, connected)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: Range.Override(self, event)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
--]]
|
||||
return (self.Range.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
-- Internal updating method
|
||||
local timer = 0
|
||||
local function OnRangeUpdate(_, elapsed)
|
||||
timer = timer + elapsed
|
||||
|
||||
if(timer >= .20) then
|
||||
for _, object in next, _FRAMES do
|
||||
if(object:IsShown()) then
|
||||
Path(object, 'OnUpdate')
|
||||
end
|
||||
end
|
||||
|
||||
timer = 0
|
||||
end
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.Range
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.insideAlpha = element.insideAlpha or 1
|
||||
element.outsideAlpha = element.outsideAlpha or 0.55
|
||||
|
||||
if(not OnRangeFrame) then
|
||||
OnRangeFrame = CreateFrame('Frame')
|
||||
OnRangeFrame:SetScript('OnUpdate', OnRangeUpdate)
|
||||
end
|
||||
|
||||
table.insert(_FRAMES, self)
|
||||
OnRangeFrame:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Range
|
||||
if(element) then
|
||||
for index, frame in next, _FRAMES do
|
||||
if(frame == self) then
|
||||
table.remove(_FRAMES, index)
|
||||
break
|
||||
end
|
||||
end
|
||||
self:SetAlpha(element.insideAlpha)
|
||||
|
||||
if(#_FRAMES == 0) then
|
||||
OnRangeFrame:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Range', nil, Enable, Disable)
|
||||
163
Libraries/oUF/elements/readycheckindicator.lua
Normal file
163
Libraries/oUF/elements/readycheckindicator.lua
Normal file
@@ -0,0 +1,163 @@
|
||||
--[[
|
||||
# Element: Ready Check Indicator
|
||||
|
||||
Handles the visibility and updating of an indicator based on the unit's ready check status.
|
||||
|
||||
## Widget
|
||||
|
||||
ReadyCheckIndicator - A `Texture` representing ready check status.
|
||||
|
||||
## Notes
|
||||
|
||||
This element updates by changing the texture.
|
||||
Default textures will be applied if the layout does not provide custom ones. See Options.
|
||||
|
||||
## Options
|
||||
|
||||
.finishedTime - For how many seconds the icon should stick after a check has completed. Defaults to 10 (number).
|
||||
.fadeTime - For how many seconds the icon should fade away after the stick duration has completed. Defaults to
|
||||
1.5 (number).
|
||||
.readyTexture - Path to an alternate texture for the ready check 'ready' status.
|
||||
.notReadyTexture - Path to an alternate texture for the ready check 'notready' status.
|
||||
.waitingTexture - Path to an alternate texture for the ready check 'waiting' status.
|
||||
|
||||
## Attributes
|
||||
|
||||
.status - the unit's ready check status (string?)['ready', 'noready', 'waiting']
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local ReadyCheckIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
ReadyCheckIndicator:SetSize(16, 16)
|
||||
ReadyCheckIndicator:SetPoint('TOP')
|
||||
|
||||
-- Register with oUF
|
||||
self.ReadyCheckIndicator = ReadyCheckIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local unitExists = Private.unitExists
|
||||
|
||||
local function OnFinished(self)
|
||||
local element = self:GetParent()
|
||||
element:Hide()
|
||||
|
||||
--[[ Callback: ReadyCheckIndicator:PostUpdateFadeOut()
|
||||
Called after the element has been faded out.
|
||||
|
||||
* self - the ReadyCheckIndicator element
|
||||
--]]
|
||||
if(element.PostUpdateFadeOut) then
|
||||
element:PostUpdateFadeOut()
|
||||
end
|
||||
end
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.ReadyCheckIndicator
|
||||
local unit = self.unit
|
||||
|
||||
--[[ Callback: ReadyCheckIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the ReadyCheckIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local status = GetReadyCheckStatus(unit)
|
||||
if(unitExists(unit) and status) then
|
||||
if(status == 'ready') then
|
||||
element:SetTexture(element.readyTexture)
|
||||
elseif(status == 'notready') then
|
||||
element:SetTexture(element.notReadyTexture)
|
||||
else
|
||||
element:SetTexture(element.waitingTexture)
|
||||
end
|
||||
|
||||
element.status = status
|
||||
element:Show()
|
||||
elseif(event ~= 'READY_CHECK_FINISHED') then
|
||||
element.status = nil
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
if(event == 'READY_CHECK_FINISHED') then
|
||||
if(element.status == 'waiting') then
|
||||
element:SetTexture(element.notReadyTexture)
|
||||
end
|
||||
|
||||
element.Animation:Play()
|
||||
end
|
||||
|
||||
--[[ Callback: ReadyCheckIndicator:PostUpdate(status)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the ReadyCheckIndicator element
|
||||
* status - the unit's ready check status (string?)['ready', 'notready', 'waiting']
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(status)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: ReadyCheckIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.ReadyCheckIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.ReadyCheckIndicator
|
||||
unit = unit and unit:match('(%a+)%d*$')
|
||||
if(element and (unit == 'party' or unit == 'raid')) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
element.readyTexture = element.readyTexture or READY_CHECK_READY_TEXTURE
|
||||
element.notReadyTexture = element.notReadyTexture or READY_CHECK_NOT_READY_TEXTURE
|
||||
element.waitingTexture = element.waitingTexture or READY_CHECK_WAITING_TEXTURE
|
||||
|
||||
local AnimationGroup = element:CreateAnimationGroup()
|
||||
AnimationGroup:HookScript('OnFinished', OnFinished)
|
||||
element.Animation = AnimationGroup
|
||||
|
||||
local Animation = AnimationGroup:CreateAnimation('Alpha')
|
||||
Animation:SetFromAlpha(1)
|
||||
Animation:SetToAlpha(0)
|
||||
Animation:SetDuration(element.fadeTime or 1.5)
|
||||
Animation:SetStartDelay(element.finishedTime or 10)
|
||||
|
||||
self:RegisterEvent('READY_CHECK', Path, true)
|
||||
self:RegisterEvent('READY_CHECK_CONFIRM', Path, true)
|
||||
self:RegisterEvent('READY_CHECK_FINISHED', Path, true)
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.ReadyCheckIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('READY_CHECK', Path)
|
||||
self:UnregisterEvent('READY_CHECK_CONFIRM', Path)
|
||||
self:UnregisterEvent('READY_CHECK_FINISHED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('ReadyCheckIndicator', Path, Enable, Disable)
|
||||
98
Libraries/oUF/elements/restingindicator.lua
Normal file
98
Libraries/oUF/elements/restingindicator.lua
Normal file
@@ -0,0 +1,98 @@
|
||||
--[[
|
||||
# Element: Resting Indicator
|
||||
|
||||
Toggles the visibility of an indicator based on the player's resting status.
|
||||
|
||||
## Widget
|
||||
|
||||
RestingIndicator - Any UI widget.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local RestingIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
RestingIndicator:SetSize(16, 16)
|
||||
RestingIndicator:SetPoint('TOPLEFT', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.RestingIndicator = RestingIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.RestingIndicator
|
||||
|
||||
--[[ Callback: RestingIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the RestingIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local isResting = IsResting()
|
||||
if(isResting) then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: RestingIndicator:PostUpdate(isResting)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the RestingIndicator element
|
||||
* isResting - indicates if the player is resting (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(isResting)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: RestingIndicator.Override(self, event)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
--]]
|
||||
return (self.RestingIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.RestingIndicator
|
||||
if(element and UnitIsUnit(unit, 'player')) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('PLAYER_UPDATE_RESTING', Path, true)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\CharacterFrame\UI-StateIcon]])
|
||||
element:SetTexCoord(0, 0.5, 0, 0.421875)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.RestingIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('PLAYER_UPDATE_RESTING', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('RestingIndicator', Path, Enable, Disable)
|
||||
100
Libraries/oUF/elements/resurrectindicator.lua
Normal file
100
Libraries/oUF/elements/resurrectindicator.lua
Normal file
@@ -0,0 +1,100 @@
|
||||
--[[
|
||||
# Element: Resurrect Indicator
|
||||
|
||||
Handles the visibility and updating of an indicator based on the unit's incoming resurrect status.
|
||||
|
||||
## Widget
|
||||
|
||||
ResurrectIndicator - A `Texture` used to display if the unit has an incoming resurrect.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local ResurrectIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
ResurrectIndicator:SetSize(16, 16)
|
||||
ResurrectIndicator:SetPoint('TOPRIGHT', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.ResurrectIndicator = ResurrectIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.ResurrectIndicator
|
||||
|
||||
--[[ Callback: ResurrectIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the ResurrectIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local incomingResurrect = UnitHasIncomingResurrection(unit)
|
||||
if(incomingResurrect) then
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: ResurrectIndicator:PostUpdate(incomingResurrect)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the ResurrectIndicator element
|
||||
* incomingResurrect - indicates if the unit has an incoming resurrection (boolean)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(incomingResurrect)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: ResurrectIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.ResurrectIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.ResurrectIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('INCOMING_RESURRECT_CHANGED', Path)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\RaidFrame\Raid-Icon-Rez]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.ResurrectIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('INCOMING_RESURRECT_CHANGED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('ResurrectIndicator', Path, Enable, Disable)
|
||||
245
Libraries/oUF/elements/runes.lua
Normal file
245
Libraries/oUF/elements/runes.lua
Normal file
@@ -0,0 +1,245 @@
|
||||
--[[
|
||||
# Element: Runes
|
||||
|
||||
Handles the visibility and updating of Death Knight's runes.
|
||||
|
||||
## Widget
|
||||
|
||||
Runes - An `table` holding `StatusBar`s.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
.bg - A `Texture` used as a background. It will inherit the color of the main StatusBar.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the sub-widgets are StatusBars and don't have a texture set.
|
||||
|
||||
## Options
|
||||
|
||||
.colorSpec - Use `self.colors.runes[specID]` to color the bar based on player's spec. `specID` is defined by the return
|
||||
value of [GetSpecialization](http://wowprogramming.com/docs/api/GetSpecialization.html) (boolean)
|
||||
.sortOrder - Sorting order. Sorts by the remaining cooldown time, 'asc' - from the least cooldown time remaining (fully
|
||||
charged) to the most (fully depleted), 'desc' - the opposite (string?)['asc', 'desc']
|
||||
|
||||
## Sub-Widgets Options
|
||||
|
||||
.multiplier - Used to tint the background based on the main widgets R, G and B values. Defaults to 1 (number)[0-1]
|
||||
|
||||
## Examples
|
||||
|
||||
local Runes = {}
|
||||
for index = 1, 6 do
|
||||
-- Position and size of the rune bar indicators
|
||||
local Rune = CreateFrame('StatusBar', nil, self)
|
||||
Rune:SetSize(120 / 6, 20)
|
||||
Rune:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', index * 120 / 6, 0)
|
||||
|
||||
Runes[index] = Rune
|
||||
end
|
||||
|
||||
-- Register with oUF
|
||||
self.Runes = Runes
|
||||
--]]
|
||||
|
||||
if(select(2, UnitClass('player')) ~= 'DEATHKNIGHT') then return end
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local runemap = {1, 2, 3, 4, 5, 6}
|
||||
local hasSortOrder = false
|
||||
|
||||
local function onUpdate(self, elapsed)
|
||||
local duration = self.duration + elapsed
|
||||
self.duration = duration
|
||||
self:SetValue(duration)
|
||||
end
|
||||
|
||||
local function ascSort(runeAID, runeBID)
|
||||
local runeAStart, _, runeARuneReady = GetRuneCooldown(runeAID)
|
||||
local runeBStart, _, runeBRuneReady = GetRuneCooldown(runeBID)
|
||||
if(runeARuneReady ~= runeBRuneReady) then
|
||||
return runeARuneReady
|
||||
elseif(runeAStart ~= runeBStart) then
|
||||
return runeAStart < runeBStart
|
||||
else
|
||||
return runeAID < runeBID
|
||||
end
|
||||
end
|
||||
|
||||
local function descSort(runeAID, runeBID)
|
||||
local runeAStart, _, runeARuneReady = GetRuneCooldown(runeAID)
|
||||
local runeBStart, _, runeBRuneReady = GetRuneCooldown(runeBID)
|
||||
if(runeARuneReady ~= runeBRuneReady) then
|
||||
return runeBRuneReady
|
||||
elseif(runeAStart ~= runeBStart) then
|
||||
return runeAStart > runeBStart
|
||||
else
|
||||
return runeAID > runeBID
|
||||
end
|
||||
end
|
||||
|
||||
local function UpdateColor(self, event)
|
||||
local element = self.Runes
|
||||
|
||||
local spec = GetSpecialization() or 0
|
||||
|
||||
local color
|
||||
if(spec > 0 and spec < 4 and element.colorSpec) then
|
||||
color = self.colors.runes[spec]
|
||||
else
|
||||
color = self.colors.power.RUNES
|
||||
end
|
||||
|
||||
local r, g, b = color[1], color[2], color[3]
|
||||
|
||||
for index = 1, #element do
|
||||
element[index]:SetStatusBarColor(r, g, b)
|
||||
|
||||
local bg = element[index].bg
|
||||
if(bg) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Callback: Runes:PostUpdateColor(r, g, b)
|
||||
Called after the element color has been updated.
|
||||
|
||||
* self - the Runes element
|
||||
* r - the red component of the used color (number)[0-1]
|
||||
* g - the green component of the used color (number)[0-1]
|
||||
* b - the blue component of the used color (number)[0-1]
|
||||
--]]
|
||||
if(element.PostUpdateColor) then
|
||||
element:PostUpdateColor(r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function ColorPath(self, ...)
|
||||
--[[ Override: Runes.UpdateColor(self, event, ...)
|
||||
Used to completely override the internal function for updating the widgets' colors.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
(self.Runes.UpdateColor or UpdateColor) (self, ...)
|
||||
end
|
||||
|
||||
local function Update(self, event)
|
||||
local element = self.Runes
|
||||
|
||||
if(element.sortOrder == 'asc') then
|
||||
table.sort(runemap, ascSort)
|
||||
hasSortOrder = true
|
||||
elseif(element.sortOrder == 'desc') then
|
||||
table.sort(runemap, descSort)
|
||||
hasSortOrder = true
|
||||
elseif(hasSortOrder) then
|
||||
table.sort(runemap)
|
||||
hasSortOrder = false
|
||||
end
|
||||
|
||||
local rune, start, duration, runeReady
|
||||
for index, runeID in next, runemap do
|
||||
rune = element[index]
|
||||
if(not rune) then break end
|
||||
|
||||
if(UnitHasVehicleUI('player')) then
|
||||
rune:Hide()
|
||||
else
|
||||
start, duration, runeReady = GetRuneCooldown(runeID)
|
||||
if(runeReady) then
|
||||
rune:SetMinMaxValues(0, 1)
|
||||
rune:SetValue(1)
|
||||
rune:SetScript('OnUpdate', nil)
|
||||
elseif(start) then
|
||||
rune.duration = GetTime() - start
|
||||
rune:SetMinMaxValues(0, duration)
|
||||
rune:SetValue(0)
|
||||
rune:SetScript('OnUpdate', onUpdate)
|
||||
end
|
||||
|
||||
rune:Show()
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Callback: Runes:PostUpdate(runemap)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Runes element
|
||||
* runemap - the ordered list of runes' indices (table)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(runemap)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: Runes.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
(self.Runes.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function AllPath(...)
|
||||
Path(...)
|
||||
ColorPath(...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
Path(element.__owner, 'ForceUpdate')
|
||||
ColorPath(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.Runes
|
||||
if(element and UnitIsUnit(unit, 'player')) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
for i = 1, #element do
|
||||
local rune = element[i]
|
||||
if(rune:IsObjectType('StatusBar') and not (rune:GetStatusBarTexture() or rune:GetStatusBarAtlas())) then
|
||||
rune:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
end
|
||||
|
||||
-- ElvUI block
|
||||
if element.IsObjectType and element:IsObjectType("Frame") then
|
||||
element:Show()
|
||||
end
|
||||
-- end block
|
||||
|
||||
self:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED', ColorPath)
|
||||
self:RegisterEvent('RUNE_POWER_UPDATE', Path, true)
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Runes
|
||||
if(element) then
|
||||
for i = 1, #element do
|
||||
element[i]:Hide()
|
||||
end
|
||||
|
||||
-- ElvUI block
|
||||
if element.IsObjectType and element:IsObjectType("Frame") then
|
||||
element:Hide()
|
||||
end
|
||||
-- end block
|
||||
|
||||
self:UnregisterEvent('PLAYER_SPECIALIZATION_CHANGED', ColorPath)
|
||||
self:UnregisterEvent('RUNE_POWER_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Runes', AllPath, Enable, Disable)
|
||||
245
Libraries/oUF/elements/stagger.lua
Normal file
245
Libraries/oUF/elements/stagger.lua
Normal file
@@ -0,0 +1,245 @@
|
||||
--[[
|
||||
# Element: Monk Stagger Bar
|
||||
|
||||
Handles the visibility and updating of the Monk's stagger bar.
|
||||
|
||||
## Widget
|
||||
|
||||
Stagger - A `StatusBar` used to represent the current stagger level.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
.bg - A `Texture` used as a background. It will inherit the color of the main StatusBar.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a StatusBar and doesn't have a texture set.
|
||||
|
||||
## Sub-Widgets Options
|
||||
|
||||
.multiplier - Used to tint the background based on the main widgets R, G and B values. Defaults to 1 (number)[0-1]
|
||||
|
||||
## Examples
|
||||
|
||||
local Stagger = CreateFrame('StatusBar', nil, self)
|
||||
Stagger:SetSize(120, 20)
|
||||
Stagger:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, 0)
|
||||
|
||||
-- Register with oUF
|
||||
self.Stagger = Stagger
|
||||
--]]
|
||||
|
||||
if(select(2, UnitClass('player')) ~= 'MONK') then return end
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
-- ElvUI block
|
||||
local GetSpecialization = GetSpecialization
|
||||
local UnitHasVehiclePlayerFrameUI = UnitHasVehiclePlayerFrameUI
|
||||
local UnitHealthMax = UnitHealthMax
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
local UnitStagger = UnitStagger
|
||||
-- GLOBALS: MonkStaggerBar
|
||||
-- end block
|
||||
|
||||
-- sourced from FrameXML/Constants.lua
|
||||
local SPEC_MONK_BREWMASTER = SPEC_MONK_BREWMASTER or 1
|
||||
|
||||
-- sourced from FrameXML/MonkStaggerBar.lua
|
||||
local BREWMASTER_POWER_BAR_NAME = BREWMASTER_POWER_BAR_NAME or 'STAGGER'
|
||||
|
||||
-- percentages at which bar should change color
|
||||
local STAGGER_YELLOW_TRANSITION = STAGGER_YELLOW_TRANSITION or 0.3
|
||||
local STAGGER_RED_TRANSITION = STAGGER_RED_TRANSITION or 0.6
|
||||
|
||||
-- table indices of bar colors
|
||||
local STAGGER_GREEN_INDEX = STAGGER_GREEN_INDEX or 1
|
||||
local STAGGER_YELLOW_INDEX = STAGGER_YELLOW_INDEX or 2
|
||||
local STAGGER_RED_INDEX = STAGGER_RED_INDEX or 3
|
||||
|
||||
local function UpdateColor(self, event, unit)
|
||||
if(unit and unit ~= self.unit) then return end
|
||||
local element = self.Stagger
|
||||
|
||||
local colors = self.colors.power[BREWMASTER_POWER_BAR_NAME]
|
||||
local perc = (element.cur or 0) / (element.max or 1)
|
||||
|
||||
local t
|
||||
if(perc >= STAGGER_RED_TRANSITION) then
|
||||
t = colors and colors[STAGGER_RED_INDEX]
|
||||
elseif(perc > STAGGER_YELLOW_TRANSITION) then
|
||||
t = colors and colors[STAGGER_YELLOW_INDEX]
|
||||
else
|
||||
t = colors and colors[STAGGER_GREEN_INDEX]
|
||||
end
|
||||
|
||||
local r, g, b
|
||||
if(t) then
|
||||
r, g, b = t[1], t[2], t[3]
|
||||
if(b) then
|
||||
element:SetStatusBarColor(r, g, b)
|
||||
|
||||
local bg = element.bg
|
||||
if(bg and b) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Callback: Stagger:PostUpdateColor(r, g, b)
|
||||
Called after the element color has been updated.
|
||||
|
||||
* self - the Stagger element
|
||||
* r - the red component of the used color (number)[0-1]
|
||||
* g - the green component of the used color (number)[0-1]
|
||||
* b - the blue component of the used color (number)[0-1]
|
||||
--]]
|
||||
if(element.PostUpdateColor) then
|
||||
element:PostUpdateColor(r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(unit and unit ~= self.unit) then return end
|
||||
|
||||
local element = self.Stagger
|
||||
|
||||
--[[ Callback: Stagger:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the Stagger element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
-- Blizzard code has nil checks for UnitStagger return
|
||||
local cur = UnitStagger('player') or 0
|
||||
local max = UnitHealthMax('player')
|
||||
|
||||
element:SetMinMaxValues(0, max)
|
||||
element:SetValue(cur)
|
||||
|
||||
element.cur = cur
|
||||
element.max = max
|
||||
|
||||
--[[ Callback: Stagger:PostUpdate(cur, max)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Stagger element
|
||||
* cur - the amount of staggered damage (number)
|
||||
* max - the player's maximum possible health value (number)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
element:PostUpdate(cur, max)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: Stagger.Override(self, event, unit)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.Stagger.Override or Update)(self, ...);
|
||||
|
||||
--[[ Override: Stagger.UpdateColor(self, event, unit)
|
||||
Used to completely override the internal function for updating the widgets' colors.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.Stagger.UpdateColor or UpdateColor) (self, ...)
|
||||
end
|
||||
|
||||
-- ElvUI changed
|
||||
local function Visibility(self, event, unit)
|
||||
local element = self.Stagger
|
||||
local isShown = element:IsShown()
|
||||
local useClassbar = (SPEC_MONK_BREWMASTER ~= GetSpecialization()) or UnitHasVehiclePlayerFrameUI('player')
|
||||
local stateChanged = false
|
||||
|
||||
if useClassbar and isShown then
|
||||
element:Hide()
|
||||
self:UnregisterEvent('UNIT_AURA', Path)
|
||||
stateChanged = true
|
||||
elseif not useClassbar and not isShown then
|
||||
element:Show()
|
||||
self:RegisterEvent('UNIT_AURA', Path)
|
||||
stateChanged = true
|
||||
end
|
||||
|
||||
if element.PostVisibility then
|
||||
element.PostVisibility(self, event, unit, not useClassbar, stateChanged)
|
||||
end
|
||||
|
||||
if not useClassbar then
|
||||
Path(self, event, unit)
|
||||
end
|
||||
end
|
||||
-- end block
|
||||
|
||||
local function VisibilityPath(self, ...)
|
||||
--[[ Override: Stagger.OverrideVisibility(self, event, unit)
|
||||
Used to completely override the internal visibility toggling function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* unit - the unit accompanying the event (string)
|
||||
--]]
|
||||
(self.Stagger.OverrideVisibility or Visibility)(self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self, unit)
|
||||
local element = self.Stagger
|
||||
if(element and UnitIsUnit(unit, 'player')) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
|
||||
self:RegisterEvent('PLAYER_TALENT_UPDATE', VisibilityPath, true)
|
||||
|
||||
if(element:IsObjectType('StatusBar') and not (element:GetStatusBarTexture() or element:GetStatusBarAtlas())) then
|
||||
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
end
|
||||
|
||||
MonkStaggerBar:UnregisterEvent('PLAYER_ENTERING_WORLD')
|
||||
MonkStaggerBar:UnregisterEvent('PLAYER_SPECIALIZATION_CHANGED')
|
||||
MonkStaggerBar:UnregisterEvent('UNIT_DISPLAYPOWER')
|
||||
MonkStaggerBar:UnregisterEvent('UNIT_EXITED_VEHICLE')
|
||||
MonkStaggerBar:UnregisterEvent('UPDATE_VEHICLE_ACTIONBAR')
|
||||
|
||||
-- do not change this without taking Visibility into account
|
||||
element:Hide()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Stagger
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_AURA', Path)
|
||||
self:UnregisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
|
||||
self:UnregisterEvent('PLAYER_TALENT_UPDATE', VisibilityPath)
|
||||
|
||||
MonkStaggerBar:RegisterEvent('PLAYER_ENTERING_WORLD')
|
||||
MonkStaggerBar:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED')
|
||||
MonkStaggerBar:RegisterEvent('UNIT_DISPLAYPOWER')
|
||||
MonkStaggerBar:RegisterEvent('UNIT_EXITED_VEHICLE')
|
||||
MonkStaggerBar:RegisterEvent('UPDATE_VEHICLE_ACTIONBAR')
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Stagger', VisibilityPath, Enable, Disable)
|
||||
110
Libraries/oUF/elements/summonindicator.lua
Normal file
110
Libraries/oUF/elements/summonindicator.lua
Normal file
@@ -0,0 +1,110 @@
|
||||
--[[
|
||||
# Element: SummonIndicator
|
||||
|
||||
Handles the visibility and updating of an indicator based on the unit's incoming summon status.
|
||||
|
||||
## Widget
|
||||
|
||||
SummonIndicator - A `Texture` used to display if the unit has an incoming summon.
|
||||
|
||||
## Notes
|
||||
|
||||
This element updates by changing the texture.
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local SummonIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
SummonIndicator:SetSize(32, 32)
|
||||
SummonIndicator:SetPoint('TOPRIGHT', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.SummonIndicator = SummonIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
-- sourced from Blizzard_APIDocumentation/IncomingSummonDocumentation.lua
|
||||
local SUMMON_STATUS_NONE = Enum.SummonStatus.None or 0
|
||||
local SUMMON_STATUS_PENDING = Enum.SummonStatus.Pending or 1
|
||||
local SUMMON_STATUS_ACCEPTED = Enum.SummonStatus.Accepted or 2
|
||||
local SUMMON_STATUS_DECLINED = Enum.SummonStatus.Declined or 3
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.SummonIndicator
|
||||
|
||||
--[[ Callback: SummonIndicator:PreUpdate()
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the SummonIndicator element
|
||||
--]]
|
||||
if(element.PreUpdate) then
|
||||
element:PreUpdate()
|
||||
end
|
||||
|
||||
local status = C_IncomingSummon.IncomingSummonStatus(unit)
|
||||
if(status ~= SUMMON_STATUS_NONE) then
|
||||
if(status == SUMMON_STATUS_PENDING) then
|
||||
element:SetAtlas('Raid-Icon-SummonPending')
|
||||
elseif(status == SUMMON_STATUS_ACCEPTED) then
|
||||
element:SetAtlas('Raid-Icon-SummonAccepted')
|
||||
elseif(status == SUMMON_STATUS_DECLINED) then
|
||||
element:SetAtlas('Raid-Icon-SummonDeclined')
|
||||
end
|
||||
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: SummonIndicator:PostUpdate(status)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the SummonIndicator element
|
||||
* status - the unit's incoming summon status (number)[0-3]
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(status)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: SummonIndicator.Override(self, event)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.SummonIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.SummonIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('INCOMING_SUMMON_CHANGED', Path)
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.SummonIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('INCOMING_SUMMON_CHANGED', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('SummonIndicator', Path, Enable, Disable)
|
||||
977
Libraries/oUF/elements/tags.lua
Normal file
977
Libraries/oUF/elements/tags.lua
Normal file
@@ -0,0 +1,977 @@
|
||||
-- Credits: Vika, Cladhaire, Tekkub
|
||||
--[[
|
||||
# Element: Tags
|
||||
|
||||
Provides a system for text-based display of information by binding a tag string to a font string widget which in turn is
|
||||
tied to a unit frame.
|
||||
|
||||
## Widget
|
||||
|
||||
A FontString to hold a tag string. Unlike other elements, this widget must not have a preset name.
|
||||
|
||||
## Notes
|
||||
|
||||
A `Tag` is a Lua string consisting of a function name surrounded by square brackets. The tag will be replaced by the
|
||||
output of the function and displayed as text on the font string widget with that the tag has been registered.
|
||||
Literals can be pre or appended by separating them with a `>` before or `<` after the function name. The literals will be only
|
||||
displayed when the function returns a non-nil value. I.e. `"[perhp<%]"` will display the current health as a percentage
|
||||
of the maximum health followed by the % sign.
|
||||
|
||||
A `Tag String` is a Lua string consisting of one or multiple tags with optional literals between them.
|
||||
Each tag will be updated individually and the output will follow the tags order. Literals will be displayed in the
|
||||
output string regardless of whether the surrounding tag functions return a value. I.e. `"[curhp]/[maxhp]"` will resolve
|
||||
to something like `2453/5000`.
|
||||
|
||||
A `Tag Function` is used to replace a single tag in a tag string by its output. A tag function receives only two
|
||||
arguments - the unit and the realUnit of the unit frame used to register the tag (see Options for further details). The
|
||||
tag function is called when the unit frame is shown or when a specified event has fired. It the tag is registered on an
|
||||
eventless frame (i.e. one holding the unit "targettarget"), then the tag function is called in a set time interval.
|
||||
|
||||
A number of built-in tag functions exist. The layout can also define its own tag functions by adding them to the
|
||||
`oUF.Tags.Methods` table. The events upon which the function will be called are specified in a white-space separated
|
||||
list added to the `oUF.Tags.Events` table. Should an event fire without unit information, then it should also be listed
|
||||
in the `oUF.Tags.SharedEvents` table as follows: `oUF.Tags.SharedEvents.EVENT_NAME = true`.
|
||||
|
||||
## Options
|
||||
|
||||
.overrideUnit - if specified on the font string widget, the frame's realUnit will be passed as the second argument to
|
||||
every tag function whose name is contained in the relevant tag string. Otherwise the second argument
|
||||
is always nil (boolean)
|
||||
.frequentUpdates - defines how often the corresponding tag function(s) should be called. This will override the events
|
||||
for the tag(s), if any. If the value is a number, it is taken as a time interval in seconds. If the
|
||||
value is a boolean, the time interval is set to 0.5 seconds (number or boolean)
|
||||
|
||||
## Attributes
|
||||
|
||||
.parent - the unit frame on which the tag has been registered
|
||||
|
||||
## Examples
|
||||
|
||||
-- define the tag function
|
||||
oUF.Tags.Methods['mylayout:threatname'] = function(unit, realUnit)
|
||||
local color = _TAGS['threatcolor'](unit)
|
||||
local name = _TAGS['name'](unit, realUnit)
|
||||
return string.format('%s%s|r', color, name)
|
||||
end
|
||||
|
||||
-- add the events
|
||||
oUF.Tags.Events['mylayout:threatname'] = 'UNIT_NAME_UPDATE UNIT_THREAT_SITUATION_UPDATE'
|
||||
|
||||
-- create the text widget
|
||||
local info = self.Health:CreateFontString(nil, 'OVERLAY', 'GameFontNormal')
|
||||
info:SetPoint('LEFT')
|
||||
|
||||
-- register the tag on the text widget with oUF
|
||||
self:Tag(info, '[mylayout:threatname]')
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local unitExists = Private.unitExists
|
||||
|
||||
-- ElvUI block
|
||||
local _G = _G
|
||||
local CreateFrame = CreateFrame
|
||||
local hooksecurefunc = hooksecurefunc
|
||||
local setfenv, getfenv = setfenv, getfenv
|
||||
local rawget, rawset, select = rawget, rawset, select
|
||||
local format, tinsert, tremove = format, tinsert, tremove
|
||||
local next, type, pcall, unpack = next, type, pcall, unpack
|
||||
local error, assert, loadstring = error, assert, loadstring
|
||||
-- end block
|
||||
|
||||
local _PATTERN = '%[..-%]+'
|
||||
|
||||
local _ENV = {
|
||||
Hex = function(r, g, b)
|
||||
if(type(r) == 'table') then
|
||||
if(r.r) then
|
||||
r, g, b = r.r, r.g, r.b
|
||||
else
|
||||
r, g, b = unpack(r)
|
||||
end
|
||||
end
|
||||
|
||||
-- ElvUI block
|
||||
if not r or type(r) == 'string' then --wtf?
|
||||
return '|cffFFFFFF'
|
||||
end
|
||||
-- end block
|
||||
|
||||
return format('|cff%02x%02x%02x', r * 255, g * 255, b * 255)
|
||||
end,
|
||||
}
|
||||
_ENV.ColorGradient = function(...)
|
||||
return _ENV._FRAME:ColorGradient(...)
|
||||
end
|
||||
|
||||
local _PROXY = setmetatable(_ENV, {__index = _G})
|
||||
|
||||
local tagStrings = {
|
||||
['affix'] = [[function(u)
|
||||
local c = UnitClassification(u)
|
||||
if(c == 'minus') then
|
||||
return 'Affix'
|
||||
end
|
||||
end]],
|
||||
|
||||
['arcanecharges'] = [[function()
|
||||
if(GetSpecialization() == SPEC_MAGE_ARCANE) then
|
||||
local num = UnitPower('player', Enum.PowerType.ArcaneCharges)
|
||||
if(num > 0) then
|
||||
return num
|
||||
end
|
||||
end
|
||||
end]],
|
||||
|
||||
['arenaspec'] = [[function(u)
|
||||
local id = u:match('arena(%d)$')
|
||||
if(id) then
|
||||
local specID = GetArenaOpponentSpec(tonumber(id))
|
||||
if(specID and specID > 0) then
|
||||
local _, specName = GetSpecializationInfoByID(specID)
|
||||
return specName
|
||||
end
|
||||
end
|
||||
end]],
|
||||
|
||||
['chi'] = [[function()
|
||||
if(GetSpecialization() == SPEC_MONK_WINDWALKER) then
|
||||
local num = UnitPower('player', Enum.PowerType.Chi)
|
||||
if(num > 0) then
|
||||
return num
|
||||
end
|
||||
end
|
||||
end]],
|
||||
|
||||
['classification'] = [[function(u)
|
||||
local c = UnitClassification(u)
|
||||
if(c == 'rare') then
|
||||
return 'Rare'
|
||||
elseif(c == 'rareelite') then
|
||||
return 'Rare Elite'
|
||||
elseif(c == 'elite') then
|
||||
return 'Elite'
|
||||
elseif(c == 'worldboss') then
|
||||
return 'Boss'
|
||||
elseif(c == 'minus') then
|
||||
return 'Affix'
|
||||
end
|
||||
end]],
|
||||
|
||||
['cpoints'] = [[function(u)
|
||||
local cp = UnitPower(u, Enum.PowerType.ComboPoints)
|
||||
|
||||
if(cp > 0) then
|
||||
return cp
|
||||
end
|
||||
end]],
|
||||
|
||||
['creature'] = [[function(u)
|
||||
return UnitCreatureFamily(u) or UnitCreatureType(u)
|
||||
end]],
|
||||
|
||||
['curmana'] = [[function(unit)
|
||||
return UnitPower(unit, Enum.PowerType.Mana)
|
||||
end]],
|
||||
|
||||
['dead'] = [[function(u)
|
||||
if(UnitIsDead(u)) then
|
||||
return 'Dead'
|
||||
elseif(UnitIsGhost(u)) then
|
||||
return 'Ghost'
|
||||
end
|
||||
end]],
|
||||
|
||||
['deficit:name'] = [[function(u)
|
||||
local missinghp = _TAGS['missinghp'](u)
|
||||
if(missinghp) then
|
||||
return '-' .. missinghp
|
||||
else
|
||||
return _TAGS['name'](u)
|
||||
end
|
||||
end]],
|
||||
|
||||
['difficulty'] = [[function(u)
|
||||
if UnitCanAttack('player', u) then
|
||||
local l = UnitEffectiveLevel(u)
|
||||
return Hex(GetCreatureDifficultyColor((l > 0) and l or 999))
|
||||
end
|
||||
end]],
|
||||
|
||||
['group'] = [[function(unit)
|
||||
local name, server = UnitName(unit)
|
||||
if(server and server ~= '') then
|
||||
name = string.format('%s-%s', name, server)
|
||||
end
|
||||
|
||||
for i=1, GetNumGroupMembers() do
|
||||
local raidName, _, group = GetRaidRosterInfo(i)
|
||||
if( raidName == name ) then
|
||||
return group
|
||||
end
|
||||
end
|
||||
end]],
|
||||
|
||||
['holypower'] = [[function()
|
||||
if(GetSpecialization() == SPEC_PALADIN_RETRIBUTION) then
|
||||
local num = UnitPower('player', Enum.PowerType.HolyPower)
|
||||
if(num > 0) then
|
||||
return num
|
||||
end
|
||||
end
|
||||
end]],
|
||||
|
||||
['leader'] = [[function(u)
|
||||
if(UnitIsGroupLeader(u)) then
|
||||
return 'L'
|
||||
end
|
||||
end]],
|
||||
|
||||
['leaderlong'] = [[function(u)
|
||||
if(UnitIsGroupLeader(u)) then
|
||||
return 'Leader'
|
||||
end
|
||||
end]],
|
||||
|
||||
['level'] = [[function(u)
|
||||
local l = UnitEffectiveLevel(u)
|
||||
if(UnitIsWildBattlePet(u) or UnitIsBattlePetCompanion(u)) then
|
||||
l = UnitBattlePetLevel(u)
|
||||
end
|
||||
|
||||
if(l > 0) then
|
||||
return l
|
||||
else
|
||||
return '??'
|
||||
end
|
||||
end]],
|
||||
|
||||
['maxmana'] = [[function(unit)
|
||||
return UnitPowerMax(unit, Enum.PowerType.Mana)
|
||||
end]],
|
||||
|
||||
['missinghp'] = [[function(u)
|
||||
local current = UnitHealthMax(u) - UnitHealth(u)
|
||||
if(current > 0) then
|
||||
return current
|
||||
end
|
||||
end]],
|
||||
|
||||
['missingpp'] = [[function(u)
|
||||
local current = UnitPowerMax(u) - UnitPower(u)
|
||||
if(current > 0) then
|
||||
return current
|
||||
end
|
||||
end]],
|
||||
|
||||
['name'] = [[function(u, r)
|
||||
return UnitName(r or u)
|
||||
end]],
|
||||
|
||||
['offline'] = [[function(u)
|
||||
if(not UnitIsConnected(u)) then
|
||||
return 'Offline'
|
||||
end
|
||||
end]],
|
||||
|
||||
['perhp'] = [[function(u)
|
||||
local m = UnitHealthMax(u)
|
||||
if(m == 0) then
|
||||
return 0
|
||||
else
|
||||
return math.floor(UnitHealth(u) / m * 100 + .5)
|
||||
end
|
||||
end]],
|
||||
|
||||
['perpp'] = [[function(u)
|
||||
local m = UnitPowerMax(u)
|
||||
if(m == 0) then
|
||||
return 0
|
||||
else
|
||||
return math.floor(UnitPower(u) / m * 100 + .5)
|
||||
end
|
||||
end]],
|
||||
|
||||
['plus'] = [[function(u)
|
||||
local c = UnitClassification(u)
|
||||
if(c == 'elite' or c == 'rareelite') then
|
||||
return '+'
|
||||
end
|
||||
end]],
|
||||
|
||||
['powercolor'] = [[function(u)
|
||||
local pType, pToken, altR, altG, altB = UnitPowerType(u)
|
||||
local t = _COLORS.power[pToken]
|
||||
|
||||
if(not t) then
|
||||
if(altR) then
|
||||
if(altR > 1 or altG > 1 or altB > 1) then
|
||||
return Hex(altR / 255, altG / 255, altB / 255)
|
||||
else
|
||||
return Hex(altR, altG, altB)
|
||||
end
|
||||
else
|
||||
return Hex(_COLORS.power[pType] or _COLORS.power.MANA)
|
||||
end
|
||||
end
|
||||
|
||||
return Hex(t)
|
||||
end]],
|
||||
|
||||
['pvp'] = [[function(u)
|
||||
if(UnitIsPVP(u)) then
|
||||
return 'PvP'
|
||||
end
|
||||
end]],
|
||||
|
||||
['raidcolor'] = [[function(u)
|
||||
local _, class = UnitClass(u)
|
||||
if(class) then
|
||||
return Hex(_COLORS.class[class])
|
||||
else
|
||||
local id = u:match('arena(%d)$')
|
||||
if(id) then
|
||||
local specID = GetArenaOpponentSpec(tonumber(id))
|
||||
if(specID and specID > 0) then
|
||||
_, _, _, _, _, class = GetSpecializationInfoByID(specID)
|
||||
return Hex(_COLORS.class[class])
|
||||
end
|
||||
end
|
||||
end
|
||||
end]],
|
||||
|
||||
['rare'] = [[function(u)
|
||||
local c = UnitClassification(u)
|
||||
if(c == 'rare' or c == 'rareelite') then
|
||||
return 'Rare'
|
||||
end
|
||||
end]],
|
||||
|
||||
['resting'] = [[function(u)
|
||||
if(u == 'player' and IsResting()) then
|
||||
return 'zzz'
|
||||
end
|
||||
end]],
|
||||
|
||||
['runes'] = [[function()
|
||||
local amount = 0
|
||||
|
||||
for i = 1, 6 do
|
||||
local _, _, ready = GetRuneCooldown(i)
|
||||
if(ready) then
|
||||
amount = amount + 1
|
||||
end
|
||||
end
|
||||
|
||||
return amount
|
||||
end]],
|
||||
|
||||
['sex'] = [[function(u)
|
||||
local s = UnitSex(u)
|
||||
if(s == 2) then
|
||||
return 'Male'
|
||||
elseif(s == 3) then
|
||||
return 'Female'
|
||||
end
|
||||
end]],
|
||||
|
||||
['shortclassification'] = [[function(u)
|
||||
local c = UnitClassification(u)
|
||||
if(c == 'rare') then
|
||||
return 'R'
|
||||
elseif(c == 'rareelite') then
|
||||
return 'R+'
|
||||
elseif(c == 'elite') then
|
||||
return '+'
|
||||
elseif(c == 'worldboss') then
|
||||
return 'B'
|
||||
elseif(c == 'minus') then
|
||||
return '-'
|
||||
end
|
||||
end]],
|
||||
|
||||
['smartclass'] = [[function(u)
|
||||
if(UnitIsPlayer(u)) then
|
||||
return _TAGS['class'](u)
|
||||
end
|
||||
|
||||
return _TAGS['creature'](u)
|
||||
end]],
|
||||
|
||||
['smartlevel'] = [[function(u)
|
||||
local c = UnitClassification(u)
|
||||
if(c == 'worldboss') then
|
||||
return 'Boss'
|
||||
else
|
||||
local plus = _TAGS['plus'](u)
|
||||
local level = _TAGS['level'](u)
|
||||
if(plus) then
|
||||
return level .. plus
|
||||
else
|
||||
return level
|
||||
end
|
||||
end
|
||||
end]],
|
||||
|
||||
['soulshards'] = [[function()
|
||||
local num = UnitPower('player', Enum.PowerType.SoulShards)
|
||||
if(num > 0) then
|
||||
return num
|
||||
end
|
||||
end]],
|
||||
|
||||
['status'] = [[function(u)
|
||||
if(UnitIsDead(u)) then
|
||||
return 'Dead'
|
||||
elseif(UnitIsGhost(u)) then
|
||||
return 'Ghost'
|
||||
elseif(not UnitIsConnected(u)) then
|
||||
return 'Offline'
|
||||
else
|
||||
return _TAGS['resting'](u)
|
||||
end
|
||||
end]],
|
||||
|
||||
['threat'] = [[function(u)
|
||||
local s = UnitThreatSituation(u)
|
||||
if(s == 1) then
|
||||
return '++'
|
||||
elseif(s == 2) then
|
||||
return '--'
|
||||
elseif(s == 3) then
|
||||
return 'Aggro'
|
||||
end
|
||||
end]],
|
||||
|
||||
['threatcolor'] = [[function(u)
|
||||
return Hex(GetThreatStatusColor(UnitThreatSituation(u)))
|
||||
end]],
|
||||
}
|
||||
|
||||
local tags = setmetatable(
|
||||
{
|
||||
curhp = UnitHealth,
|
||||
curpp = UnitPower,
|
||||
maxhp = UnitHealthMax,
|
||||
maxpp = UnitPowerMax,
|
||||
class = UnitClass,
|
||||
faction = UnitFactionGroup,
|
||||
race = UnitRace,
|
||||
},
|
||||
{
|
||||
__index = function(self, key)
|
||||
local tagString = tagStrings[key]
|
||||
if(tagString) then
|
||||
self[key] = tagString
|
||||
tagStrings[key] = nil
|
||||
end
|
||||
|
||||
return rawget(self, key)
|
||||
end,
|
||||
__newindex = function(self, key, val)
|
||||
if(type(val) == 'string') then
|
||||
local func, err = loadstring('return ' .. val)
|
||||
if(func) then
|
||||
val = func()
|
||||
else
|
||||
error(err, 3)
|
||||
end
|
||||
end
|
||||
|
||||
assert(type(val) == 'function', 'Tag function must be a function or a string that evaluates to a function.')
|
||||
|
||||
-- We don't want to clash with any custom envs
|
||||
if(getfenv(val) == _G) then
|
||||
-- pcall is needed for cases when Blizz functions are passed as
|
||||
-- strings, for intance, 'UnitPowerMax', an attempt to set a
|
||||
-- custom env will result in an error
|
||||
pcall(setfenv, val, _PROXY)
|
||||
end
|
||||
|
||||
rawset(self, key, val)
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
_ENV._TAGS = tags
|
||||
|
||||
local vars = setmetatable({}, {
|
||||
__newindex = function(self, key, val)
|
||||
if(type(val) == 'string') then
|
||||
local func = loadstring('return ' .. val)
|
||||
if(func) then
|
||||
val = func() or val
|
||||
end
|
||||
end
|
||||
|
||||
rawset(self, key, val)
|
||||
end,
|
||||
})
|
||||
|
||||
_ENV._VARS = vars
|
||||
|
||||
-- ElvUI sets UNIT_POWER_UPDATE to UNIT_POWER_FREQUENT in tagEvents
|
||||
local tagEvents = {
|
||||
['affix'] = 'UNIT_CLASSIFICATION_CHANGED',
|
||||
['arcanecharges'] = 'UNIT_POWER_FREQUENT PLAYER_TALENT_UPDATE',
|
||||
['arenaspec'] = 'ARENA_PREP_OPPONENT_SPECIALIZATIONS',
|
||||
['chi'] = 'UNIT_POWER_FREQUENT PLAYER_TALENT_UPDATE',
|
||||
['classification'] = 'UNIT_CLASSIFICATION_CHANGED',
|
||||
['cpoints'] = 'UNIT_POWER_FREQUENT PLAYER_TARGET_CHANGED',
|
||||
['curhp'] = 'UNIT_HEALTH UNIT_MAXHEALTH',
|
||||
['curmana'] = 'UNIT_POWER_FREQUENT UNIT_MAXPOWER',
|
||||
['curpp'] = 'UNIT_POWER_FREQUENT UNIT_MAXPOWER',
|
||||
['dead'] = 'UNIT_HEALTH',
|
||||
['deficit:name'] = 'UNIT_HEALTH UNIT_MAXHEALTH UNIT_NAME_UPDATE',
|
||||
['difficulty'] = 'UNIT_FACTION',
|
||||
['faction'] = 'NEUTRAL_FACTION_SELECT_RESULT',
|
||||
['group'] = 'GROUP_ROSTER_UPDATE',
|
||||
['holypower'] = 'UNIT_POWER_FREQUENT PLAYER_TALENT_UPDATE',
|
||||
['leader'] = 'PARTY_LEADER_CHANGED',
|
||||
['leaderlong'] = 'PARTY_LEADER_CHANGED',
|
||||
['level'] = 'UNIT_LEVEL PLAYER_LEVEL_UP',
|
||||
['maxhp'] = 'UNIT_MAXHEALTH',
|
||||
['maxmana'] = 'UNIT_POWER_FREQUENT UNIT_MAXPOWER',
|
||||
['maxpp'] = 'UNIT_MAXPOWER',
|
||||
['missinghp'] = 'UNIT_HEALTH UNIT_MAXHEALTH',
|
||||
['missingpp'] = 'UNIT_MAXPOWER UNIT_POWER_FREQUENT',
|
||||
['name'] = 'UNIT_NAME_UPDATE',
|
||||
['offline'] = 'UNIT_HEALTH UNIT_CONNECTION',
|
||||
['perhp'] = 'UNIT_HEALTH UNIT_MAXHEALTH',
|
||||
['perpp'] = 'UNIT_MAXPOWER UNIT_POWER_FREQUENT',
|
||||
['plus'] = 'UNIT_CLASSIFICATION_CHANGED',
|
||||
['powercolor'] = 'UNIT_DISPLAYPOWER',
|
||||
['pvp'] = 'UNIT_FACTION',
|
||||
['rare'] = 'UNIT_CLASSIFICATION_CHANGED',
|
||||
['resting'] = 'PLAYER_UPDATE_RESTING',
|
||||
['runes'] = 'RUNE_POWER_UPDATE',
|
||||
['shortclassification'] = 'UNIT_CLASSIFICATION_CHANGED',
|
||||
['smartlevel'] = 'UNIT_LEVEL PLAYER_LEVEL_UP UNIT_CLASSIFICATION_CHANGED',
|
||||
['soulshards'] = 'UNIT_POWER_FREQUENT',
|
||||
['status'] = 'UNIT_HEALTH PLAYER_UPDATE_RESTING UNIT_CONNECTION',
|
||||
['threat'] = 'UNIT_THREAT_SITUATION_UPDATE',
|
||||
['threatcolor'] = 'UNIT_THREAT_SITUATION_UPDATE',
|
||||
}
|
||||
|
||||
local unitlessEvents = {
|
||||
ARENA_PREP_OPPONENT_SPECIALIZATIONS = true,
|
||||
GROUP_ROSTER_UPDATE = true,
|
||||
NEUTRAL_FACTION_SELECT_RESULT = true,
|
||||
PARTY_LEADER_CHANGED = true,
|
||||
PLAYER_LEVEL_UP = true,
|
||||
PLAYER_TARGET_CHANGED = true,
|
||||
PLAYER_UPDATE_RESTING = true,
|
||||
RUNE_POWER_UPDATE = true,
|
||||
}
|
||||
|
||||
local events = {}
|
||||
local eventFrame = CreateFrame('Frame')
|
||||
eventFrame:SetScript('OnEvent', function(self, event, unit)
|
||||
local strings = events[event]
|
||||
if(strings) then
|
||||
for _, fs in next, strings do
|
||||
if(fs:IsVisible() and (unitlessEvents[event] or fs.parent.unit == unit or (fs.extraUnits and fs.extraUnits[unit]))) then
|
||||
fs:UpdateTag()
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local onUpdates = {}
|
||||
local eventlessUnits = {}
|
||||
|
||||
local function createOnUpdate(timer)
|
||||
if(not onUpdates[timer]) then
|
||||
local total = timer
|
||||
local frame = CreateFrame('Frame')
|
||||
local strings = eventlessUnits[timer]
|
||||
|
||||
frame:SetScript('OnUpdate', function(self, elapsed)
|
||||
if(total >= timer) then
|
||||
for _, fs in next, strings do
|
||||
if(fs.parent:IsShown() and unitExists(fs.parent.unit)) then
|
||||
fs:UpdateTag()
|
||||
end
|
||||
end
|
||||
|
||||
total = 0
|
||||
end
|
||||
|
||||
total = total + elapsed
|
||||
end)
|
||||
|
||||
onUpdates[timer] = frame
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Tags: frame:UpdateTags()
|
||||
Used to update all tags on a frame.
|
||||
|
||||
* self - the unit frame from which to update the tags
|
||||
--]]
|
||||
local function Update(self)
|
||||
if(self.__tags) then
|
||||
for fs in next, self.__tags do
|
||||
fs:UpdateTag()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ElvUI block
|
||||
local onEnter = function(self) for fs in next, self.__mousetags do fs:SetAlpha(1) end end
|
||||
local onLeave = function(self) for fs in next, self.__mousetags do fs:SetAlpha(0) end end
|
||||
local onUpdateDelay = {}
|
||||
local escapeSequences = {
|
||||
["||c"] = "|c",
|
||||
["||r"] = "|r",
|
||||
["||T"] = "|T",
|
||||
["||t"] = "|t",
|
||||
}
|
||||
-- end block
|
||||
|
||||
local tagPool = {}
|
||||
local funcPool = {}
|
||||
local tmp = {}
|
||||
|
||||
local function getTagName(tag)
|
||||
local tagStart = tag:match('>+()') or 2
|
||||
local tagEnd = (tag:match('.-()<') or -1) - 1
|
||||
|
||||
return tag:sub(tagStart, tagEnd), tagStart, tagEnd
|
||||
end
|
||||
|
||||
local function getTagFunc(tagstr)
|
||||
local func = tagPool[tagstr]
|
||||
if(not func) then
|
||||
local frmt, numTags = tagstr:gsub('%%', '%%%%'):gsub(_PATTERN, '%%s')
|
||||
local args = {}
|
||||
|
||||
for bracket in tagstr:gmatch(_PATTERN) do
|
||||
local tagFunc = funcPool[bracket] or tags[bracket:sub(2, -2)]
|
||||
if(not tagFunc) then
|
||||
local tagName, tagStart, tagEnd = getTagName(bracket)
|
||||
|
||||
local tag = tags[tagName]
|
||||
if(tag) then
|
||||
tagStart = tagStart - 2
|
||||
tagEnd = tagEnd + 2
|
||||
|
||||
if(tagStart ~= 0 and tagEnd ~= 0) then
|
||||
local prefix = bracket:sub(2, tagStart)
|
||||
local suffix = bracket:sub(tagEnd, -2)
|
||||
|
||||
tagFunc = function(unit, realUnit)
|
||||
local str = tag(unit, realUnit)
|
||||
if(str) then
|
||||
return prefix .. str .. suffix
|
||||
end
|
||||
end
|
||||
elseif(tagStart ~= 0) then
|
||||
local prefix = bracket:sub(2, tagStart)
|
||||
|
||||
tagFunc = function(unit, realUnit)
|
||||
local str = tag(unit, realUnit)
|
||||
if(str) then
|
||||
return prefix .. str
|
||||
end
|
||||
end
|
||||
elseif(tagEnd ~= 0) then
|
||||
local suffix = bracket:sub(tagEnd, -2)
|
||||
|
||||
tagFunc = function(unit, realUnit)
|
||||
local str = tag(unit, realUnit)
|
||||
if(str) then
|
||||
return str .. suffix
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
funcPool[bracket] = tagFunc
|
||||
end
|
||||
end
|
||||
|
||||
-- ElvUI changed
|
||||
if(tagFunc) then
|
||||
tinsert(args, tagFunc)
|
||||
else
|
||||
numTags = -1
|
||||
func = function(self)
|
||||
self:SetText(bracket)
|
||||
end
|
||||
end
|
||||
-- end block
|
||||
end
|
||||
|
||||
-- ElvUI changed
|
||||
if numTags ~= -1 then
|
||||
func = function(self)
|
||||
local parent = self.parent
|
||||
local unit = parent.unit
|
||||
|
||||
local customArgs = parent.__customargs
|
||||
local realUnit = self.overrideUnit and parent.realUnit
|
||||
|
||||
_ENV._COLORS = parent.colors
|
||||
_ENV._FRAME = parent
|
||||
for i, fnc in next, args do
|
||||
tmp[i] = fnc(unit, realUnit, customArgs[self]) or ''
|
||||
end
|
||||
|
||||
-- We do 1, numTags because tmp can hold several unneeded variables.
|
||||
self:SetFormattedText(frmt, unpack(tmp, 1, numTags))
|
||||
end
|
||||
|
||||
tagPool[tagstr] = func
|
||||
end
|
||||
-- end block
|
||||
end
|
||||
|
||||
return func
|
||||
end
|
||||
|
||||
local function registerEvent(fontstr, event)
|
||||
if(not events[event]) then events[event] = {} end
|
||||
|
||||
eventFrame:RegisterEvent(event)
|
||||
tinsert(events[event], fontstr)
|
||||
end
|
||||
|
||||
local function registerEvents(fontstr, tagstr)
|
||||
for tag in tagstr:gmatch(_PATTERN) do
|
||||
tag = getTagName(tag)
|
||||
local tagevents = tagEvents[tag]
|
||||
if(tagevents) then
|
||||
for event in tagevents:gmatch('%S+') do
|
||||
registerEvent(fontstr, event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function unregisterEvents(fontstr)
|
||||
for event, data in next, events do
|
||||
for i, tagfsstr in next, data do
|
||||
if(tagfsstr == fontstr) then
|
||||
if(#data == 1) then
|
||||
eventFrame:UnregisterEvent(event)
|
||||
end
|
||||
|
||||
tremove(data, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- this bullshit is to fix texture strings not adjusting to its inherited alpha
|
||||
-- it is a blizzard issue with how texture strings are rendered
|
||||
local alphaFix = CreateFrame('Frame')
|
||||
alphaFix.fontStrings = {}
|
||||
alphaFix:SetScript('OnUpdate', function()
|
||||
local strs = alphaFix.fontStrings
|
||||
if next(strs) then
|
||||
for fs in next, strs do
|
||||
strs[fs] = nil
|
||||
|
||||
local a = fs:GetAlpha()
|
||||
fs:SetAlpha(0)
|
||||
fs:SetAlpha(a)
|
||||
end
|
||||
else
|
||||
alphaFix:Hide()
|
||||
end
|
||||
end)
|
||||
|
||||
local function fixAlpha(self)
|
||||
alphaFix.fontStrings[self] = true
|
||||
alphaFix:Show()
|
||||
end
|
||||
|
||||
local taggedFS = {}
|
||||
|
||||
--[[ Tags: frame:Tag(fs, tagstr, ...)
|
||||
Used to register a tag on a unit frame.
|
||||
|
||||
* self - the unit frame on which to register the tag
|
||||
* fs - the font string to display the tag (FontString)
|
||||
* tagstr - the tag string (string)
|
||||
* ... - additional optional unitID(s) the tag should update for
|
||||
--]]
|
||||
local function Tag(self, fs, tagstr, ...)
|
||||
if(not fs or not tagstr) then return end
|
||||
|
||||
if(not self.__tags) then
|
||||
self.__tags = {}
|
||||
self.__mousetags = {} -- ElvUI
|
||||
self.__customargs = {} -- ElvUI
|
||||
|
||||
tinsert(self.__elements, Update)
|
||||
elseif(self.__tags[fs]) then
|
||||
-- We don't need to remove it from the __tags table as Untag handles
|
||||
-- that for us.
|
||||
self:Untag(fs)
|
||||
end
|
||||
|
||||
-- ElvUI
|
||||
if not fs.__HookedAlphaFix then
|
||||
hooksecurefunc(fs, 'SetText', fixAlpha)
|
||||
hooksecurefunc(fs, 'SetFormattedText', fixAlpha)
|
||||
fs.__HookedAlphaFix = true
|
||||
end
|
||||
|
||||
for escapeSequence, replacement in next, escapeSequences do
|
||||
while tagstr:find(escapeSequence) do
|
||||
tagstr = tagstr:gsub(escapeSequence, replacement)
|
||||
end
|
||||
end
|
||||
|
||||
local customArgs = tagstr:match('{(.-)}%]')
|
||||
if customArgs then
|
||||
self.__customargs[fs] = customArgs
|
||||
tagstr = tagstr:gsub('{.-}%]', ']')
|
||||
else
|
||||
self.__customargs[fs] = nil
|
||||
end
|
||||
|
||||
if tagstr:find('%[mouseover%]') then
|
||||
self.__mousetags[fs] = true
|
||||
fs:SetAlpha(0)
|
||||
if not self.__HookFunc then
|
||||
self:HookScript('OnEnter', onEnter)
|
||||
self:HookScript('OnLeave', onLeave)
|
||||
self.__HookFunc = true;
|
||||
end
|
||||
tagstr = tagstr:gsub('%[mouseover%]', '')
|
||||
else
|
||||
for fontString in next, self.__mousetags do
|
||||
if fontString == fs then
|
||||
self.__mousetags[fontString] = nil
|
||||
fs:SetAlpha(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local containsOnUpdate
|
||||
for tag in tagstr:gmatch(_PATTERN) do
|
||||
tag = getTagName(tag)
|
||||
if not tagEvents[tag] then
|
||||
containsOnUpdate = onUpdateDelay[tag] or 0.15;
|
||||
end
|
||||
end
|
||||
-- end block
|
||||
|
||||
fs.parent = self
|
||||
fs.UpdateTag = getTagFunc(tagstr)
|
||||
|
||||
if(self.__eventless or fs.frequentUpdates) or containsOnUpdate then -- ElvUI changed
|
||||
local timer
|
||||
if(type(fs.frequentUpdates) == 'number') then
|
||||
timer = fs.frequentUpdates
|
||||
-- ElvUI added check
|
||||
elseif containsOnUpdate then
|
||||
timer = containsOnUpdate
|
||||
-- end block
|
||||
else
|
||||
timer = .5
|
||||
end
|
||||
|
||||
if(not eventlessUnits[timer]) then eventlessUnits[timer] = {} end
|
||||
tinsert(eventlessUnits[timer], fs)
|
||||
|
||||
createOnUpdate(timer)
|
||||
else
|
||||
registerEvents(fs, tagstr)
|
||||
|
||||
if(...) then
|
||||
if(not fs.extraUnits) then
|
||||
fs.extraUnits = {}
|
||||
end
|
||||
|
||||
for index = 1, select('#', ...) do
|
||||
fs.extraUnits[select(index, ...)] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
taggedFS[fs] = tagstr
|
||||
self.__tags[fs] = true
|
||||
end
|
||||
|
||||
--[[ Tags: frame:Untag(fs)
|
||||
Used to unregister a tag from a unit frame.
|
||||
|
||||
* self - the unit frame from which to unregister the tag
|
||||
* fs - the font string holding the tag (FontString)
|
||||
--]]
|
||||
local function Untag(self, fs)
|
||||
if(not fs or not self.__tags) then return end
|
||||
|
||||
unregisterEvents(fs)
|
||||
for _, timers in next, eventlessUnits do
|
||||
for i, fontstr in next, timers do
|
||||
if(fs == fontstr) then
|
||||
tremove(timers, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
fs.UpdateTag = nil
|
||||
|
||||
taggedFS[fs] = nil
|
||||
self.__tags[fs] = nil
|
||||
end
|
||||
|
||||
oUF.Tags = {
|
||||
Methods = tags,
|
||||
Events = tagEvents,
|
||||
SharedEvents = unitlessEvents,
|
||||
OnUpdateThrottle = onUpdateDelay, -- ElvUI
|
||||
Vars = vars,
|
||||
RefreshMethods = function(self, tag)
|
||||
if(not tag) then return end
|
||||
|
||||
funcPool['[' .. tag .. ']'] = nil
|
||||
|
||||
-- If a tag's name contains magic chars, there's a chance that
|
||||
-- string.match will fail to find the match.
|
||||
tag = '%[' .. tag:gsub('[%^%$%(%)%%%.%*%+%-%?]', '%%%1') .. '%]'
|
||||
for tagstr, func in next, tagPool do
|
||||
if(tagstr:gsub("%[[^%[%]]*>", "["):gsub("<[^%[%]]*%]", "]"):match(tag)) then
|
||||
tagPool[tagstr] = nil
|
||||
|
||||
for fs in next, taggedFS do
|
||||
if(fs.UpdateTag == func) then
|
||||
fs.UpdateTag = getTagFunc(tagstr)
|
||||
|
||||
if(fs:IsVisible()) then
|
||||
fs:UpdateTag()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
RefreshEvents = function(self, tag)
|
||||
if(not tag) then return end
|
||||
|
||||
-- If a tag's name contains magic chars, there's a chance that
|
||||
-- string.match will fail to find the match.
|
||||
tag = '%[' .. tag:gsub('[%^%$%(%)%%%.%*%+%-%?]', '%%%1') .. '%]'
|
||||
for tagstr in next, tagPool do
|
||||
if(tagstr:gsub("%[[^%[%]]*>", "["):gsub("<[^%[%]]*%]", "]"):match(tag)) then
|
||||
for fs, ts in next, taggedFS do
|
||||
if(ts == tagstr) then
|
||||
unregisterEvents(fs)
|
||||
registerEvents(fs, tagstr)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
oUF:RegisterMetaFunction('Tag', Tag)
|
||||
oUF:RegisterMetaFunction('Untag', Untag)
|
||||
oUF:RegisterMetaFunction('UpdateTags', Update)
|
||||
132
Libraries/oUF/elements/threatindicator.lua
Normal file
132
Libraries/oUF/elements/threatindicator.lua
Normal file
@@ -0,0 +1,132 @@
|
||||
--[[
|
||||
# Element: Threat Indicator
|
||||
|
||||
Handles the visibility and updating of an indicator based on the unit's current threat level.
|
||||
|
||||
## Widget
|
||||
|
||||
ThreatIndicator - A `Texture` used to display the current threat level.
|
||||
The element works by changing the texture's vertex color.
|
||||
|
||||
## Notes
|
||||
|
||||
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
|
||||
|
||||
## Options
|
||||
|
||||
.feedbackUnit - The unit whose threat situation is being requested. If defined, it'll be passed as the first argument to
|
||||
[UnitThreatSituation](https://wow.gamepedia.com/API_UnitThreatSituation).
|
||||
|
||||
## Examples
|
||||
|
||||
-- Position and size
|
||||
local ThreatIndicator = self:CreateTexture(nil, 'OVERLAY')
|
||||
ThreatIndicator:SetSize(16, 16)
|
||||
ThreatIndicator:SetPoint('TOPRIGHT', self)
|
||||
|
||||
-- Register it with oUF
|
||||
self.ThreatIndicator = ThreatIndicator
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local unitExists = Private.unitExists
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(unit ~= self.unit) then return end
|
||||
|
||||
local element = self.ThreatIndicator
|
||||
--[[ Callback: ThreatIndicator:PreUpdate(unit)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the ThreatIndicator element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
--]]
|
||||
if(element.PreUpdate) then element:PreUpdate(unit) end
|
||||
|
||||
local feedbackUnit = element.feedbackUnit
|
||||
unit = unit or self.unit
|
||||
|
||||
local status
|
||||
-- BUG: Non-existent '*target' or '*pet' units cause UnitThreatSituation() errors
|
||||
if(unitExists(unit)) then
|
||||
if(feedbackUnit and feedbackUnit ~= unit and unitExists(feedbackUnit)) then
|
||||
status = UnitThreatSituation(feedbackUnit, unit)
|
||||
else
|
||||
status = UnitThreatSituation(unit)
|
||||
end
|
||||
end
|
||||
|
||||
local r, g, b
|
||||
if(status and status > 0) then
|
||||
r, g, b = unpack(self.colors.threat[status])
|
||||
|
||||
if(element.SetVertexColor) then
|
||||
element:SetVertexColor(r, g, b)
|
||||
end
|
||||
|
||||
element:Show()
|
||||
else
|
||||
element:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: ThreatIndicator:PostUpdate(unit, status, r, g, b)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the ThreatIndicator element
|
||||
* unit - the unit for which the update has been triggered (string)
|
||||
* status - the unit's threat status (see [UnitThreatSituation](http://wowprogramming.com/docs/api/UnitThreatSituation.html))
|
||||
* r - the red color component based on the unit's threat status (number?)[0-1]
|
||||
* g - the green color component based on the unit's threat status (number?)[0-1]
|
||||
* b - the blue color component based on the unit's threat status (number?)[0-1]
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(unit, status, r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: ThreatIndicator.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.ThreatIndicator.Override or Update) (self, ...)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.ThreatIndicator
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
self:RegisterEvent('UNIT_THREAT_SITUATION_UPDATE', Path)
|
||||
self:RegisterEvent('UNIT_THREAT_LIST_UPDATE', Path)
|
||||
|
||||
if(element:IsObjectType('Texture') and not element:GetTexture()) then
|
||||
element:SetTexture([[Interface\RAIDFRAME\UI-RaidFrame-Threat]])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.ThreatIndicator
|
||||
if(element) then
|
||||
element:Hide()
|
||||
|
||||
self:UnregisterEvent('UNIT_THREAT_SITUATION_UPDATE', Path)
|
||||
self:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('ThreatIndicator', Path, Enable, Disable)
|
||||
190
Libraries/oUF/elements/totems.lua
Normal file
190
Libraries/oUF/elements/totems.lua
Normal file
@@ -0,0 +1,190 @@
|
||||
--[[
|
||||
# Element: Totem Indicator
|
||||
|
||||
Handles the updating and visibility of totems.
|
||||
|
||||
## Widget
|
||||
|
||||
Totems - A `table` to hold sub-widgets.
|
||||
|
||||
## Sub-Widgets
|
||||
|
||||
Totem - Any UI widget.
|
||||
|
||||
## Sub-Widget Options
|
||||
|
||||
.Icon - A `Texture` representing the totem icon.
|
||||
.Cooldown - A `Cooldown` representing the duration of the totem.
|
||||
|
||||
## Notes
|
||||
|
||||
OnEnter and OnLeave script handlers will be set to display a Tooltip if the `Totem` widget is mouse enabled.
|
||||
|
||||
## Examples
|
||||
|
||||
local Totems = {}
|
||||
for index = 1, 5 do
|
||||
-- Position and size of the totem indicator
|
||||
local Totem = CreateFrame('Button', nil, self)
|
||||
Totem:SetSize(40, 40)
|
||||
Totem:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', index * Totem:GetWidth(), 0)
|
||||
|
||||
local Icon = Totem:CreateTexture(nil, 'OVERLAY')
|
||||
Icon:SetAllPoints()
|
||||
|
||||
local Cooldown = CreateFrame('Cooldown', nil, Totem, 'CooldownFrameTemplate')
|
||||
Cooldown:SetAllPoints()
|
||||
|
||||
Totem.Icon = Icon
|
||||
Totem.Cooldown = Cooldown
|
||||
|
||||
Totems[index] = Totem
|
||||
end
|
||||
|
||||
-- Register with oUF
|
||||
self.Totems = Totems
|
||||
--]]
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local GameTooltip = GameTooltip
|
||||
|
||||
local function UpdateTooltip(self)
|
||||
if GameTooltip:IsForbidden() then return end
|
||||
|
||||
GameTooltip:SetTotem(self:GetID())
|
||||
end
|
||||
|
||||
local function OnEnter(self)
|
||||
if GameTooltip:IsForbidden() or not self:IsVisible() then return end
|
||||
|
||||
GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT')
|
||||
self:UpdateTooltip()
|
||||
end
|
||||
|
||||
local function OnLeave()
|
||||
if GameTooltip:IsForbidden() then return end
|
||||
|
||||
GameTooltip:Hide()
|
||||
end
|
||||
|
||||
local function UpdateTotem(self, event, slot)
|
||||
local element = self.Totems
|
||||
if(slot > #element) then return end
|
||||
|
||||
--[[ Callback: Totems:PreUpdate(slot)
|
||||
Called before the element has been updated.
|
||||
|
||||
* self - the Totems element
|
||||
* slot - the slot of the totem to be updated (number)
|
||||
--]]
|
||||
if(element.PreUpdate) then element:PreUpdate(slot) end
|
||||
|
||||
local totem = element[slot]
|
||||
local haveTotem, name, start, duration, icon = GetTotemInfo(slot)
|
||||
if(haveTotem and duration > 0) then
|
||||
if(totem.Icon) then
|
||||
totem.Icon:SetTexture(icon)
|
||||
end
|
||||
|
||||
if(totem.Cooldown) then
|
||||
totem.Cooldown:SetCooldown(start, duration)
|
||||
end
|
||||
|
||||
totem:Show()
|
||||
else
|
||||
totem:Hide()
|
||||
end
|
||||
|
||||
--[[ Callback: Totems:PostUpdate(slot, haveTotem, name, start, duration, icon)
|
||||
Called after the element has been updated.
|
||||
|
||||
* self - the Totems element
|
||||
* slot - the slot of the updated totem (number)
|
||||
* haveTotem - indicates if a totem is present in the given slot (boolean)
|
||||
* name - the name of the totem (string)
|
||||
* start - the value of `GetTime()` when the totem was created (number)
|
||||
* duration - the total duration for which the totem should last (number)
|
||||
* icon - the totem's icon (Texture)
|
||||
--]]
|
||||
if(element.PostUpdate) then
|
||||
return element:PostUpdate(slot, haveTotem, name, start, duration, icon)
|
||||
end
|
||||
end
|
||||
|
||||
local function Path(self, ...)
|
||||
--[[ Override: Totem.Override(self, event, ...)
|
||||
Used to completely override the internal update function.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* ... - the arguments accompanying the event
|
||||
--]]
|
||||
return (self.Totems.Override or UpdateTotem) (self, ...)
|
||||
end
|
||||
|
||||
local function Update(self, event)
|
||||
for i = 1, #self.Totems do
|
||||
Path(self, event, i)
|
||||
end
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Update(element.__owner, 'ForceUpdate')
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.Totems
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
for i = 1, #element do
|
||||
local totem = element[i]
|
||||
|
||||
totem:SetID(i)
|
||||
|
||||
if(totem:IsMouseEnabled()) then
|
||||
totem:SetScript('OnEnter', OnEnter)
|
||||
totem:SetScript('OnLeave', OnLeave)
|
||||
|
||||
--[[ Override: Totems[slot]:UpdateTooltip()
|
||||
Used to populate the tooltip when the totem is hovered.
|
||||
|
||||
* self - the widget at the given slot index
|
||||
--]]
|
||||
if(not totem.UpdateTooltip) then
|
||||
totem.UpdateTooltip = UpdateTooltip
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self:RegisterEvent('PLAYER_TOTEM_UPDATE', Path, true)
|
||||
|
||||
TotemFrame:UnregisterEvent('PLAYER_TOTEM_UPDATE')
|
||||
TotemFrame:UnregisterEvent('PLAYER_ENTERING_WORLD')
|
||||
TotemFrame:UnregisterEvent('UPDATE_SHAPESHIFT_FORM')
|
||||
TotemFrame:UnregisterEvent('PLAYER_TALENT_UPDATE')
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.Totems
|
||||
if(element) then
|
||||
for i = 1, #element do
|
||||
element[i]:Hide()
|
||||
end
|
||||
|
||||
TotemFrame:RegisterEvent('PLAYER_TOTEM_UPDATE')
|
||||
TotemFrame:RegisterEvent('PLAYER_ENTERING_WORLD')
|
||||
TotemFrame:RegisterEvent('UPDATE_SHAPESHIFT_FORM')
|
||||
TotemFrame:RegisterEvent('PLAYER_TALENT_UPDATE')
|
||||
|
||||
self:UnregisterEvent('PLAYER_TOTEM_UPDATE', Path)
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('Totems', Update, Enable, Disable)
|
||||
187
Libraries/oUF/events.lua
Normal file
187
Libraries/oUF/events.lua
Normal file
@@ -0,0 +1,187 @@
|
||||
local parent, ns = ...
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local argcheck = Private.argcheck
|
||||
local error = Private.error
|
||||
local validateUnit = Private.validateUnit
|
||||
local frame_metatable = Private.frame_metatable
|
||||
|
||||
-- Original event methods
|
||||
local registerEvent = frame_metatable.__index.RegisterEvent
|
||||
local registerUnitEvent = frame_metatable.__index.RegisterUnitEvent
|
||||
local unregisterEvent = frame_metatable.__index.UnregisterEvent
|
||||
local isEventRegistered = frame_metatable.__index.IsEventRegistered
|
||||
|
||||
-- to update unit frames correctly, some events need to be registered for
|
||||
-- a specific combination of primary and secondary units
|
||||
local secondaryUnits = {
|
||||
UNIT_ENTERED_VEHICLE = {
|
||||
pet = 'player',
|
||||
},
|
||||
UNIT_EXITED_VEHICLE = {
|
||||
pet = 'player',
|
||||
},
|
||||
UNIT_PET = {
|
||||
pet = 'player',
|
||||
},
|
||||
}
|
||||
|
||||
function Private.UpdateUnits(frame, unit, realUnit)
|
||||
if(unit == realUnit) then
|
||||
realUnit = nil
|
||||
end
|
||||
|
||||
if(frame.unit ~= unit or frame.realUnit ~= realUnit) then
|
||||
-- don't let invalid units in, otherwise unit events will end up being
|
||||
-- registered as unitless
|
||||
if(frame.unitEvents and validateUnit(unit)) then
|
||||
local resetRealUnit = false
|
||||
|
||||
for event in next, frame.unitEvents do
|
||||
if(not realUnit and secondaryUnits[event]) then
|
||||
realUnit = secondaryUnits[event][unit]
|
||||
resetRealUnit = true
|
||||
end
|
||||
|
||||
local registered, unit1, unit2 = isEventRegistered(frame, event)
|
||||
-- we don't want to re-register unitless/shared events in case
|
||||
-- someone added them by hand to the unitEvents table
|
||||
if(not registered or unit1 and (unit1 ~= unit or unit2 ~= realUnit)) then
|
||||
-- BUG: passing explicit nil units to RegisterUnitEvent
|
||||
-- makes it silently fall back to RegisterEvent, using ''
|
||||
-- instead of explicit nils doesn't cause this behaviour
|
||||
registerUnitEvent(frame, event, unit, realUnit or '')
|
||||
end
|
||||
|
||||
if(resetRealUnit) then
|
||||
realUnit = nil
|
||||
resetRealUnit = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
frame.unit = unit
|
||||
frame.realUnit = realUnit
|
||||
frame.id = unit:match('^.-(%d+)')
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function onEvent(self, event, ...)
|
||||
if(self:IsVisible()) then
|
||||
return self[event](self, event, ...)
|
||||
end
|
||||
end
|
||||
|
||||
local event_metatable = {
|
||||
__call = function(funcs, self, ...)
|
||||
for _, func in next, funcs do
|
||||
func(self, ...)
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
--[[ Events: frame:RegisterEvent(event, func, unitless)
|
||||
Used to register a frame for a game event and add an event handler. OnUpdate polled frames are prevented from
|
||||
registering events.
|
||||
|
||||
* self - frame that will be registered for the given event.
|
||||
* event - name of the event to register (string)
|
||||
* func - a function that will be executed when the event fires. Multiple functions can be added for the same frame
|
||||
and event (function)
|
||||
* unitless - indicates that the event does not fire for a specific unit, so the event arguments won't be
|
||||
matched to the frame unit(s). Obligatory for unitless event (boolean)
|
||||
--]]
|
||||
function frame_metatable.__index:RegisterEvent(event, func, unitless)
|
||||
-- Block OnUpdate polled frames from registering events except for
|
||||
-- UNIT_PORTRAIT_UPDATE and UNIT_MODEL_CHANGED which are used for
|
||||
-- portrait updates.
|
||||
if(self.__eventless and event ~= 'UNIT_PORTRAIT_UPDATE' and event ~= 'UNIT_MODEL_CHANGED') then return end
|
||||
|
||||
argcheck(event, 2, 'string')
|
||||
argcheck(func, 3, 'function')
|
||||
|
||||
local curev = self[event]
|
||||
local kind = type(curev)
|
||||
if(curev) then
|
||||
if(kind == 'function' and curev ~= func) then
|
||||
self[event] = setmetatable({curev, func}, event_metatable)
|
||||
elseif(kind == 'table') then
|
||||
for _, infunc in next, curev do
|
||||
if(infunc == func) then return end
|
||||
end
|
||||
|
||||
table.insert(curev, func)
|
||||
end
|
||||
|
||||
if(unitless or self.__eventless) then
|
||||
-- re-register the event in case we have mixed registration
|
||||
registerEvent(self, event)
|
||||
if(self.unitEvents) then
|
||||
self.unitEvents[event] = nil
|
||||
end
|
||||
end
|
||||
else
|
||||
self[event] = func
|
||||
|
||||
if(not self:GetScript('OnEvent')) then
|
||||
self:SetScript('OnEvent', onEvent)
|
||||
end
|
||||
|
||||
if(unitless or self.__eventless) then
|
||||
registerEvent(self, event)
|
||||
else
|
||||
self.unitEvents = self.unitEvents or {}
|
||||
self.unitEvents[event] = true
|
||||
-- UpdateUnits will take care of unit event registration for header
|
||||
-- units in case we don't have a valid unit yet
|
||||
local unit1, unit2 = self.unit
|
||||
if(unit1 and validateUnit(unit1)) then
|
||||
if(secondaryUnits[event]) then
|
||||
unit2 = secondaryUnits[event][unit1]
|
||||
end
|
||||
|
||||
registerUnitEvent(self, event, unit1, unit2 or '')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Events: frame:UnregisterEvent(event, func)
|
||||
Used to remove a function from the event handler list for a game event.
|
||||
|
||||
* self - the frame registered for the event
|
||||
* event - name of the registered event (string)
|
||||
* func - function to be removed from the list of event handlers. If this is the only handler for the given event, then
|
||||
the frame will be unregistered for the event (function)
|
||||
--]]
|
||||
function frame_metatable.__index:UnregisterEvent(event, func)
|
||||
argcheck(event, 2, 'string')
|
||||
|
||||
local cleanUp = false
|
||||
local curev = self[event]
|
||||
if(type(curev) == 'table' and func) then
|
||||
for k, infunc in next, curev do
|
||||
if(infunc == func) then
|
||||
curev[k] = nil
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if(not next(curev)) then
|
||||
cleanUp = true
|
||||
end
|
||||
end
|
||||
|
||||
if(cleanUp or curev == func) then
|
||||
self[event] = nil
|
||||
if(self.unitEvents) then
|
||||
self.unitEvents[event] = nil
|
||||
end
|
||||
|
||||
unregisterEvent(self, event)
|
||||
end
|
||||
end
|
||||
71
Libraries/oUF/factory.lua
Normal file
71
Libraries/oUF/factory.lua
Normal file
@@ -0,0 +1,71 @@
|
||||
local parent, ns = ...
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local argcheck = Private.argcheck
|
||||
|
||||
local queue = {}
|
||||
local factory = CreateFrame('Frame')
|
||||
factory:SetScript('OnEvent', function(self, event, ...)
|
||||
return self[event](self, event, ...)
|
||||
end)
|
||||
|
||||
factory:RegisterEvent('PLAYER_LOGIN')
|
||||
factory.active = true
|
||||
|
||||
function factory:PLAYER_LOGIN()
|
||||
if(not self.active) then return end
|
||||
|
||||
for _, func in next, queue do
|
||||
func(oUF)
|
||||
end
|
||||
|
||||
-- Avoid creating dupes.
|
||||
wipe(queue)
|
||||
end
|
||||
|
||||
--[[ Factory: oUF:Factory(func)
|
||||
Used to call a function directly if the current character is logged in and the factory is active. Else the function is
|
||||
queued up to be executed at a later time (upon PLAYER_LOGIN by default).
|
||||
|
||||
* self - the global oUF object
|
||||
* func - function to be executed or delayed (function)
|
||||
--]]
|
||||
function oUF:Factory(func)
|
||||
argcheck(func, 2, 'function')
|
||||
|
||||
-- Call the function directly if we're active and logged in.
|
||||
if(IsLoggedIn() and factory.active) then
|
||||
return func(self)
|
||||
else
|
||||
table.insert(queue, func)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Factory: oUF:EnableFactory()
|
||||
Used to enable the factory.
|
||||
|
||||
* self - the global oUF object
|
||||
--]]
|
||||
function oUF:EnableFactory()
|
||||
factory.active = true
|
||||
end
|
||||
|
||||
--[[ Factory: oUF:DisableFactory()
|
||||
Used to disable the factory.
|
||||
|
||||
* self - the global oUF object
|
||||
--]]
|
||||
function oUF:DisableFactory()
|
||||
factory.active = nil
|
||||
end
|
||||
|
||||
--[[ Factory: oUF:RunFactoryQueue()
|
||||
Used to try to execute queued up functions. The current player must be logged in and the factory must be active for
|
||||
this to succeed.
|
||||
|
||||
* self - the global oUF object
|
||||
--]]
|
||||
function oUF:RunFactoryQueue()
|
||||
factory:PLAYER_LOGIN()
|
||||
end
|
||||
4
Libraries/oUF/finalize.lua
Normal file
4
Libraries/oUF/finalize.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
local parent, ns = ...
|
||||
|
||||
-- It's named Private for a reason!
|
||||
ns.oUF.Private = nil
|
||||
6
Libraries/oUF/init.lua
Normal file
6
Libraries/oUF/init.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
local parent, ns = ...
|
||||
ns.oUF = {}
|
||||
ns.oUF.Private = {}
|
||||
|
||||
ns.oUF.isClassic = select(4, GetBuildInfo()) < 20000
|
||||
ns.oUF.isRetail = not ns.oUF.isClassic
|
||||
12
Libraries/oUF/oUF.toc
Normal file
12
Libraries/oUF/oUF.toc
Normal file
@@ -0,0 +1,12 @@
|
||||
## Interface: 90001
|
||||
## Title: oUF
|
||||
## Author: Haste, lightspark, p3lim, Rainrider
|
||||
## Version: @project-version@
|
||||
## Notes: Unit frame framework. Does nothing by itself.
|
||||
## OptionalDeps: Clique
|
||||
## X-oUF: oUF
|
||||
|
||||
## X-Curse-Project-ID: 21187
|
||||
## X-WoWI-ID: 9994
|
||||
|
||||
oUF.xml
|
||||
87
Libraries/oUF/oUF.xml
Normal file
87
Libraries/oUF/oUF.xml
Normal file
@@ -0,0 +1,87 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/">
|
||||
<Script file="init.lua"/>
|
||||
<Script file="private.lua"/>
|
||||
<Script file="ouf.lua"/>
|
||||
<Script file="events.lua"/>
|
||||
<Script file="factory.lua"/>
|
||||
<Script file="blizzard.lua"/>
|
||||
<Script file="units.lua"/>
|
||||
<Script file="colors.lua"/>
|
||||
|
||||
<Script file="elements\additionalpower.lua"/>
|
||||
<Script file="elements\alternativepower.lua"/>
|
||||
<Script file="elements\assistantindicator.lua"/>
|
||||
<Script file="elements\auras.lua"/>
|
||||
<Script file="elements\castbar.lua"/>
|
||||
<Script file="elements\classpower.lua"/>
|
||||
<Script file="elements\combatindicator.lua"/>
|
||||
<Script file="elements\grouproleindicator.lua"/>
|
||||
<Script file="elements\health.lua"/>
|
||||
<Script file="elements\healthprediction.lua"/>
|
||||
<Script file="elements\leaderindicator.lua"/>
|
||||
<Script file="elements\partyindicator.lua"/>
|
||||
<Script file="elements\phaseindicator.lua"/>
|
||||
<Script file="elements\portrait.lua"/>
|
||||
<Script file="elements\power.lua"/>
|
||||
<Script file="elements\powerprediction.lua"/>
|
||||
<Script file="elements\pvpclassificationindicator.lua"/>
|
||||
<Script file="elements\pvpindicator.lua"/>
|
||||
<Script file="elements\questindicator.lua"/>
|
||||
<Script file="elements\raidroleindicator.lua"/>
|
||||
<Script file="elements\raidtargetindicator.lua"/>
|
||||
<Script file="elements\range.lua"/>
|
||||
<Script file="elements\readycheckindicator.lua"/>
|
||||
<Script file="elements\restingindicator.lua"/>
|
||||
<Script file="elements\resurrectindicator.lua"/>
|
||||
<Script file="elements\runes.lua"/>
|
||||
<Script file="elements\stagger.lua"/>
|
||||
<Script file="elements\summonindicator.lua"/>
|
||||
<Script file="elements\tags.lua"/>
|
||||
<Script file="elements\threatindicator.lua"/>
|
||||
<Script file="elements\totems.lua"/>
|
||||
|
||||
<Script file="finalize.lua"/>
|
||||
|
||||
<!--
|
||||
Sub-object as a child of the parent unit frame:
|
||||
<Button name="oUF_HeaderTargetTemplate" inherits="SecureUnitButtonTemplate" virtual="true">
|
||||
<Frames>
|
||||
<Button name="$parentTarget" inherits="SecureUnitButtonTemplate">
|
||||
<Attributes>
|
||||
<Attribute name="unitsuffix" type="string" value="target"/>
|
||||
<Attribute name="useparent-unit" type="boolean" value="true"/>
|
||||
</Attributes>
|
||||
</Button>
|
||||
</Frames>
|
||||
</Button>
|
||||
|
||||
Separate unit template example:
|
||||
<Button name="oUF_HeaderSeparateSubOjectsTemplate" inherits="SecureUnitButtonTemplate" virtual="true">
|
||||
<Attributes>
|
||||
<Attribute name="oUF-onlyProcessChildren" type="boolean" value="true"/>
|
||||
</Attributes>
|
||||
|
||||
<Frames>
|
||||
<Button name="$parentUnit" inherits="SecureUnitButtonTemplate">
|
||||
<Attributes>
|
||||
<Attribute name="useparent-unit" type="boolean" value="true"/>
|
||||
</Attributes>
|
||||
</Button>
|
||||
|
||||
<Button name="$parentPet" inherits="SecureUnitButtonTemplate">
|
||||
<Attributes>
|
||||
<Attribute name="unitsuffix" type="string" value="pet"/>
|
||||
<Attribute name="useparent-unit" type="boolean" value="true"/>
|
||||
</Attributes>
|
||||
</Button>
|
||||
|
||||
<Button name="$parentTarget" inherits="SecureUnitButtonTemplate">
|
||||
<Attributes>
|
||||
<Attribute name="unitsuffix" type="string" value="target"/>
|
||||
<Attribute name="useparent-unit" type="boolean" value="true"/>
|
||||
</Attributes>
|
||||
</Button>
|
||||
</Frames>
|
||||
</Button>
|
||||
-->
|
||||
</Ui>
|
||||
897
Libraries/oUF/ouf.lua
Normal file
897
Libraries/oUF/ouf.lua
Normal file
@@ -0,0 +1,897 @@
|
||||
local parent, ns = ...
|
||||
local global = GetAddOnMetadata(parent, 'X-oUF')
|
||||
local _VERSION = '@project-version@'
|
||||
if(_VERSION:find('project%-version')) then
|
||||
_VERSION = 'devel'
|
||||
end
|
||||
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local argcheck = Private.argcheck
|
||||
local error = Private.error
|
||||
local print = Private.print
|
||||
local unitExists = Private.unitExists
|
||||
|
||||
local styles, style = {}
|
||||
local callback, objects, headers = {}, {}, {}
|
||||
|
||||
local elements = {}
|
||||
local activeElements = {}
|
||||
|
||||
local PetBattleFrameHider = CreateFrame('Frame', (global or parent) .. '_PetBattleFrameHider', UIParent, 'SecureHandlerStateTemplate')
|
||||
PetBattleFrameHider:SetAllPoints()
|
||||
PetBattleFrameHider:SetFrameStrata('LOW')
|
||||
RegisterStateDriver(PetBattleFrameHider, 'visibility', '[petbattle] hide; show')
|
||||
|
||||
-- updating of "invalid" units, function edited by ElvUI
|
||||
local function enableTargetUpdate(object)
|
||||
object.onUpdateFrequency = object.onUpdateFrequency or 0.1
|
||||
object.__eventless = true
|
||||
|
||||
object:SetScript('OnUpdate', function(self, elapsed)
|
||||
if not self.unit then
|
||||
return
|
||||
elseif self.elapsed and self.elapsed > self.onUpdateFrequency then
|
||||
self:UpdateAllElements('OnUpdate')
|
||||
|
||||
self.elapsed = 0
|
||||
else
|
||||
self.elapsed = (self.elapsed or 0) + elapsed
|
||||
end
|
||||
end)
|
||||
end
|
||||
Private.enableTargetUpdate = enableTargetUpdate
|
||||
|
||||
local function updateActiveUnit(self, event, unit)
|
||||
-- Calculate units to work with
|
||||
local realUnit, modUnit = SecureButton_GetUnit(self), SecureButton_GetModifiedUnit(self)
|
||||
|
||||
-- _GetUnit() doesn't rewrite playerpet -> pet like _GetModifiedUnit does.
|
||||
if(realUnit == 'playerpet') then
|
||||
realUnit = 'pet'
|
||||
elseif(realUnit == 'playertarget') then
|
||||
realUnit = 'target'
|
||||
end
|
||||
|
||||
if(modUnit == 'pet' and realUnit ~= 'pet') then
|
||||
modUnit = 'vehicle'
|
||||
end
|
||||
|
||||
if(not unitExists(modUnit)) then return end
|
||||
|
||||
-- Change the active unit and run a full update.
|
||||
if(Private.UpdateUnits(self, modUnit, realUnit)) then
|
||||
self:UpdateAllElements('RefreshUnit')
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function iterateChildren(...)
|
||||
for i = 1, select('#', ...) do
|
||||
local obj = select(i, ...)
|
||||
|
||||
if(type(obj) == 'table' and obj.isChild) then
|
||||
updateActiveUnit(obj, 'iterateChildren')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function onAttributeChanged(self, name, value)
|
||||
if(name == 'unit' and value) then
|
||||
if(self.hasChildren) then
|
||||
iterateChildren(self:GetChildren())
|
||||
end
|
||||
|
||||
if(not self:GetAttribute('oUF-onlyProcessChildren')) then
|
||||
updateActiveUnit(self, 'OnAttributeChanged')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local frame_metatable = {
|
||||
__index = CreateFrame('Button')
|
||||
}
|
||||
Private.frame_metatable = frame_metatable
|
||||
|
||||
for k, v in next, {
|
||||
--[[ frame:EnableElement(name, unit)
|
||||
Used to activate an element for the given unit frame.
|
||||
|
||||
* self - unit frame for which the element should be enabled
|
||||
* name - name of the element to be enabled (string)
|
||||
* unit - unit to be passed to the element's Enable function. Defaults to the frame's unit (string?)
|
||||
--]]
|
||||
EnableElement = function(self, name, unit)
|
||||
argcheck(name, 2, 'string')
|
||||
argcheck(unit, 3, 'string', 'nil')
|
||||
|
||||
local element = elements[name]
|
||||
if(not element or self:IsElementEnabled(name)) then return end
|
||||
|
||||
if(element.enable(self, unit or self.unit)) then
|
||||
activeElements[self][name] = true
|
||||
|
||||
if(element.update) then
|
||||
table.insert(self.__elements, element.update)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
--[[ frame:DisableElement(name)
|
||||
Used to deactivate an element for the given unit frame.
|
||||
|
||||
* self - unit frame for which the element should be disabled
|
||||
* name - name of the element to be disabled (string)
|
||||
--]]
|
||||
DisableElement = function(self, name)
|
||||
argcheck(name, 2, 'string')
|
||||
|
||||
local enabled = self:IsElementEnabled(name)
|
||||
if(not enabled) then return end
|
||||
|
||||
local update = elements[name].update
|
||||
for k, func in next, self.__elements do
|
||||
if(func == update) then
|
||||
table.remove(self.__elements, k)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
activeElements[self][name] = nil
|
||||
|
||||
return elements[name].disable(self)
|
||||
end,
|
||||
|
||||
--[[ frame:IsElementEnabled(name)
|
||||
Used to check if an element is enabled on the given frame.
|
||||
|
||||
* self - unit frame
|
||||
* name - name of the element (string)
|
||||
--]]
|
||||
IsElementEnabled = function(self, name)
|
||||
argcheck(name, 2, 'string')
|
||||
|
||||
local element = elements[name]
|
||||
if(not element) then return end
|
||||
|
||||
local active = activeElements[self]
|
||||
return active and active[name]
|
||||
end,
|
||||
|
||||
--[[ frame:Enable(asState)
|
||||
Used to toggle the visibility of a unit frame based on the existence of its unit. This is a reference to
|
||||
`RegisterUnitWatch`.
|
||||
|
||||
* self - unit frame
|
||||
* asState - if true, the frame's "state-unitexists" attribute will be set to a boolean value denoting whether the
|
||||
unit exists; if false, the frame will be shown if its unit exists, and hidden if it does not (boolean)
|
||||
--]]
|
||||
Enable = RegisterUnitWatch,
|
||||
--[[ frame:Disable()
|
||||
Used to UnregisterUnitWatch for the given frame and hide it.
|
||||
|
||||
* self - unit frame
|
||||
--]]
|
||||
Disable = function(self)
|
||||
UnregisterUnitWatch(self)
|
||||
self:Hide()
|
||||
end,
|
||||
--[[ frame:IsEnabled()
|
||||
Used to check if a unit frame is registered with the unit existence monitor. This is a reference to
|
||||
`UnitWatchRegistered`.
|
||||
|
||||
* self - unit frame
|
||||
--]]
|
||||
IsEnabled = UnitWatchRegistered,
|
||||
--[[ frame:UpdateAllElements(event)
|
||||
Used to update all enabled elements on the given frame.
|
||||
|
||||
* self - unit frame
|
||||
* event - event name to pass to the elements' update functions (string)
|
||||
--]]
|
||||
UpdateAllElements = function(self, event)
|
||||
local unit = self.unit
|
||||
if(not unitExists(unit)) then return end
|
||||
|
||||
assert(type(event) == 'string', "Invalid argument 'event' in UpdateAllElements.")
|
||||
|
||||
if(self.PreUpdate) then
|
||||
--[[ Callback: frame:PreUpdate(event)
|
||||
Fired before the frame is updated.
|
||||
|
||||
* self - the unit frame
|
||||
* event - the event triggering the update (string)
|
||||
--]]
|
||||
self:PreUpdate(event)
|
||||
end
|
||||
|
||||
for _, func in next, self.__elements do
|
||||
func(self, event, unit)
|
||||
end
|
||||
|
||||
if(self.PostUpdate) then
|
||||
--[[ Callback: frame:PostUpdate(event)
|
||||
Fired after the frame is updated.
|
||||
|
||||
* self - the unit frame
|
||||
* event - the event triggering the update (string)
|
||||
--]]
|
||||
self:PostUpdate(event)
|
||||
end
|
||||
end,
|
||||
} do
|
||||
frame_metatable.__index[k] = v
|
||||
end
|
||||
|
||||
local function onShow(self)
|
||||
if(not updateActiveUnit(self, 'OnShow')) then
|
||||
return self:UpdateAllElements('OnShow')
|
||||
end
|
||||
end
|
||||
|
||||
local function updatePet(self, event, unit)
|
||||
local petUnit
|
||||
if(unit == 'target') then
|
||||
return
|
||||
elseif(unit == 'player') then
|
||||
petUnit = 'pet'
|
||||
else
|
||||
-- Convert raid26 -> raidpet26
|
||||
petUnit = unit:gsub('^(%a+)(%d+)', '%1pet%2')
|
||||
end
|
||||
|
||||
if(self.unit ~= petUnit) then return end
|
||||
if(not updateActiveUnit(self, event)) then
|
||||
return self:UpdateAllElements(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function updateRaid(self, event)
|
||||
local unitGUID = UnitGUID(self.unit)
|
||||
if(unitGUID and unitGUID ~= self.unitGUID) then
|
||||
self.unitGUID = unitGUID
|
||||
|
||||
self:UpdateAllElements(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function initObject(unit, style, styleFunc, header, ...)
|
||||
local num = select('#', ...)
|
||||
for i = 1, num do
|
||||
local object = select(i, ...)
|
||||
local objectUnit = object:GetAttribute('oUF-guessUnit') or unit
|
||||
local suffix = object:GetAttribute('unitsuffix')
|
||||
|
||||
object.__elements = {}
|
||||
object.style = style
|
||||
object = setmetatable(object, frame_metatable)
|
||||
|
||||
-- Expose the frame through oUF.objects.
|
||||
table.insert(objects, object)
|
||||
|
||||
-- We have to force update the frames when PEW fires.
|
||||
object:RegisterEvent('PLAYER_ENTERING_WORLD', object.UpdateAllElements, true)
|
||||
|
||||
-- Handle the case where someone has modified the unitsuffix attribute in
|
||||
-- oUF-initialConfigFunction.
|
||||
if(suffix and not objectUnit:match(suffix)) then
|
||||
objectUnit = objectUnit .. suffix
|
||||
end
|
||||
|
||||
if(not (suffix == 'target' or objectUnit and objectUnit:match('target'))) then
|
||||
object:RegisterEvent('UNIT_ENTERED_VEHICLE', updateActiveUnit)
|
||||
object:RegisterEvent('UNIT_EXITED_VEHICLE', updateActiveUnit)
|
||||
|
||||
-- We don't need to register UNIT_PET for the player unit. We register it
|
||||
-- mainly because UNIT_EXITED_VEHICLE and UNIT_ENTERED_VEHICLE doesn't always
|
||||
-- have pet information when they fire for party and raid units.
|
||||
if(objectUnit ~= 'player') then
|
||||
object:RegisterEvent('UNIT_PET', updatePet)
|
||||
end
|
||||
end
|
||||
|
||||
if(not header) then
|
||||
-- No header means it's a frame created through :Spawn().
|
||||
object:SetAttribute('*type1', 'target')
|
||||
object:SetAttribute('*type2', 'togglemenu')
|
||||
|
||||
-- No need to enable this for *target frames.
|
||||
if(not (unit:match('target') or suffix == 'target')) then
|
||||
object:SetAttribute('toggleForVehicle', true)
|
||||
end
|
||||
|
||||
-- Other boss and target units are handled by :HandleUnit().
|
||||
if(suffix == 'target') then
|
||||
enableTargetUpdate(object)
|
||||
else
|
||||
oUF:HandleUnit(object)
|
||||
end
|
||||
else
|
||||
-- update the frame when its prev unit is replaced with a new one
|
||||
-- updateRaid relies on UnitGUID to detect the unit change
|
||||
object:RegisterEvent('GROUP_ROSTER_UPDATE', updateRaid, true)
|
||||
|
||||
if(num > 1) then
|
||||
if(object:GetParent() == header) then
|
||||
object.hasChildren = true
|
||||
else
|
||||
object.isChild = true
|
||||
end
|
||||
end
|
||||
|
||||
if(suffix == 'target') then
|
||||
enableTargetUpdate(object)
|
||||
end
|
||||
end
|
||||
|
||||
activeElements[object] = {} -- ElvUI: styleFunc on headers break before this is set when they try to enable elements before it's set.
|
||||
|
||||
Private.UpdateUnits(object, objectUnit)
|
||||
|
||||
styleFunc(object, objectUnit, not header)
|
||||
|
||||
object:HookScript('OnAttributeChanged', onAttributeChanged)
|
||||
|
||||
-- NAME_PLATE_UNIT_ADDED fires after the frame is shown, so there's no
|
||||
-- need to call UAE multiple times
|
||||
if(not object.isNamePlate) then
|
||||
object:SetScript('OnShow', onShow)
|
||||
end
|
||||
|
||||
for element in next, elements do
|
||||
object:EnableElement(element, objectUnit)
|
||||
end
|
||||
|
||||
for _, func in next, callback do
|
||||
func(object)
|
||||
end
|
||||
|
||||
-- Make Clique kinda happy
|
||||
if(not object.isNamePlate) then
|
||||
_G.ClickCastFrames = ClickCastFrames or {}
|
||||
ClickCastFrames[object] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function walkObject(object, unit)
|
||||
local parent = object:GetParent()
|
||||
local style = parent.style or style
|
||||
local styleFunc = styles[style]
|
||||
|
||||
local header = parent:GetAttribute('oUF-headerType') and parent
|
||||
|
||||
-- Check if we should leave the main frame blank.
|
||||
if(object:GetAttribute('oUF-onlyProcessChildren')) then
|
||||
object.hasChildren = true
|
||||
object:HookScript('OnAttributeChanged', onAttributeChanged)
|
||||
return initObject(unit, style, styleFunc, header, object:GetChildren())
|
||||
end
|
||||
|
||||
return initObject(unit, style, styleFunc, header, object, object:GetChildren())
|
||||
end
|
||||
|
||||
--[[ oUF:RegisterInitCallback(func)
|
||||
Used to add a function to a table to be executed upon unit frame/header initialization.
|
||||
|
||||
* self - the global oUF object
|
||||
* func - function to be added
|
||||
--]]
|
||||
function oUF:RegisterInitCallback(func)
|
||||
table.insert(callback, func)
|
||||
end
|
||||
|
||||
--[[ oUF:RegisterMetaFunction(name, func)
|
||||
Used to make a (table of) function(s) available to all unit frames.
|
||||
|
||||
* self - the global oUF object
|
||||
* name - unique name of the function (string)
|
||||
* func - function or a table of functions (function or table)
|
||||
--]]
|
||||
function oUF:RegisterMetaFunction(name, func)
|
||||
argcheck(name, 2, 'string')
|
||||
argcheck(func, 3, 'function', 'table')
|
||||
|
||||
if(frame_metatable.__index[name]) then
|
||||
return
|
||||
end
|
||||
|
||||
frame_metatable.__index[name] = func
|
||||
end
|
||||
|
||||
--[[ oUF:RegisterStyle(name, func)
|
||||
Used to register a style with oUF. This will also set the active style if it hasn't been set yet.
|
||||
|
||||
* self - the global oUF object
|
||||
* name - name of the style
|
||||
* func - function(s) defining the style (function or table)
|
||||
--]]
|
||||
function oUF:RegisterStyle(name, func)
|
||||
argcheck(name, 2, 'string')
|
||||
argcheck(func, 3, 'function', 'table')
|
||||
|
||||
if(styles[name]) then return error('Style [%s] already registered.', name) end
|
||||
if(not style) then style = name end
|
||||
|
||||
styles[name] = func
|
||||
end
|
||||
|
||||
--[[ oUF:SetActiveStyle(name)
|
||||
Used to set the active style.
|
||||
|
||||
* self - the global oUF object
|
||||
* name - name of the style (string)
|
||||
--]]
|
||||
function oUF:SetActiveStyle(name)
|
||||
argcheck(name, 2, 'string')
|
||||
if(not styles[name]) then return error('Style [%s] does not exist.', name) end
|
||||
|
||||
style = name
|
||||
end
|
||||
|
||||
--[[ oUF:GetActiveStyle()
|
||||
Used to get the active style.
|
||||
|
||||
* self - the global oUF object
|
||||
--]]
|
||||
function oUF:GetActiveStyle()
|
||||
return style
|
||||
end
|
||||
|
||||
do
|
||||
local function iter(_, n)
|
||||
-- don't expose the style functions.
|
||||
return (next(styles, n))
|
||||
end
|
||||
|
||||
--[[ oUF:IterateStyles()
|
||||
Returns an iterator over all registered styles.
|
||||
|
||||
* self - the global oUF object
|
||||
--]]
|
||||
function oUF.IterateStyles()
|
||||
return iter, nil, nil
|
||||
end
|
||||
end
|
||||
|
||||
local getCondition
|
||||
do
|
||||
local conditions = {
|
||||
raid40 = '[@raid26,exists] show;',
|
||||
raid25 = '[@raid11,exists] show;',
|
||||
raid10 = '[@raid6,exists] show;',
|
||||
raid = '[group:raid] show;',
|
||||
party = '[group:party,nogroup:raid] show;',
|
||||
solo = '[@player,exists,nogroup:party] show;',
|
||||
}
|
||||
|
||||
function getCondition(...)
|
||||
local cond = ''
|
||||
|
||||
for i = 1, select('#', ...) do
|
||||
local short = select(i, ...)
|
||||
|
||||
local condition = conditions[short]
|
||||
if(condition) then
|
||||
cond = cond .. condition
|
||||
end
|
||||
end
|
||||
|
||||
return cond .. 'hide'
|
||||
end
|
||||
end
|
||||
|
||||
local function generateName(unit, ...)
|
||||
local name = 'oUF_' .. style:gsub('^oUF_?', ''):gsub('[^%a%d_]+', '')
|
||||
|
||||
local raid, party, groupFilter, unitsuffix
|
||||
for i = 1, select('#', ...), 2 do
|
||||
local att, val = select(i, ...)
|
||||
if(att == 'oUF-initialConfigFunction') then
|
||||
unitsuffix = val:match('unitsuffix[%p%s]+(%a+)')
|
||||
elseif(att == 'showRaid') then
|
||||
raid = val ~= false and val ~= nil
|
||||
elseif(att == 'showParty') then
|
||||
party = val ~= false and val ~= nil
|
||||
elseif(att == 'groupFilter') then
|
||||
groupFilter = val
|
||||
end
|
||||
end
|
||||
|
||||
local append
|
||||
if(raid) then
|
||||
if(groupFilter) then
|
||||
if(type(groupFilter) == 'number' and groupFilter > 0) then
|
||||
append = 'Raid' .. groupFilter
|
||||
elseif(groupFilter:match('MAINTANK')) then
|
||||
append = 'MainTank'
|
||||
elseif(groupFilter:match('MAINASSIST')) then
|
||||
append = 'MainAssist'
|
||||
else
|
||||
local _, count = groupFilter:gsub(',', '')
|
||||
if(count == 0) then
|
||||
append = 'Raid' .. groupFilter
|
||||
else
|
||||
append = 'Raid'
|
||||
end
|
||||
end
|
||||
else
|
||||
append = 'Raid'
|
||||
end
|
||||
elseif(party) then
|
||||
append = 'Party'
|
||||
elseif(unit) then
|
||||
append = unit:gsub('^%l', string.upper)
|
||||
end
|
||||
|
||||
if(append) then
|
||||
name = name .. append .. (unitsuffix or '')
|
||||
end
|
||||
|
||||
-- Change oUF_LilyRaidRaid into oUF_LilyRaid
|
||||
name = name:gsub('(%u%l+)([%u%l]*)%1', '%1')
|
||||
-- Change oUF_LilyTargettarget into oUF_LilyTargetTarget
|
||||
name = name:gsub('t(arget)', 'T%1')
|
||||
name = name:gsub('p(et)', 'P%1')
|
||||
name = name:gsub('f(ocus)', 'F%1')
|
||||
|
||||
local base = name
|
||||
local i = 2
|
||||
while(_G[name]) do
|
||||
name = base .. i
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
return name
|
||||
end
|
||||
|
||||
do
|
||||
local function styleProxy(self, frame, ...)
|
||||
return walkObject(_G[frame])
|
||||
end
|
||||
|
||||
-- There has to be an easier way to do this.
|
||||
local initialConfigFunction = [[
|
||||
local header = self:GetParent()
|
||||
local frames = table.new()
|
||||
table.insert(frames, self)
|
||||
self:GetChildList(frames)
|
||||
for i = 1, #frames do
|
||||
local frame = frames[i]
|
||||
local unit
|
||||
-- There's no need to do anything on frames with onlyProcessChildren
|
||||
if(not frame:GetAttribute('oUF-onlyProcessChildren')) then
|
||||
RegisterUnitWatch(frame)
|
||||
|
||||
-- Attempt to guess what the header is set to spawn.
|
||||
local groupFilter = header:GetAttribute('groupFilter')
|
||||
|
||||
if(type(groupFilter) == 'string' and groupFilter:match('MAIN[AT]')) then
|
||||
local role = groupFilter:match('MAIN([AT])')
|
||||
if(role == 'T') then
|
||||
unit = 'maintank'
|
||||
else
|
||||
unit = 'mainassist'
|
||||
end
|
||||
elseif(header:GetAttribute('showRaid')) then
|
||||
unit = 'raid'
|
||||
elseif(header:GetAttribute('showParty')) then
|
||||
unit = 'party'
|
||||
end
|
||||
|
||||
local headerType = header:GetAttribute('oUF-headerType')
|
||||
local suffix = frame:GetAttribute('unitsuffix')
|
||||
if(unit and suffix) then
|
||||
if(headerType == 'pet' and suffix == 'target') then
|
||||
unit = unit .. headerType .. suffix
|
||||
else
|
||||
unit = unit .. suffix
|
||||
end
|
||||
elseif(unit and headerType == 'pet') then
|
||||
unit = unit .. headerType
|
||||
end
|
||||
|
||||
frame:SetAttribute('*type1', 'target')
|
||||
frame:SetAttribute('*type2', 'togglemenu')
|
||||
frame:SetAttribute('oUF-guessUnit', unit)
|
||||
end
|
||||
|
||||
local body = header:GetAttribute('oUF-initialConfigFunction')
|
||||
if(body) then
|
||||
frame:Run(body, unit)
|
||||
end
|
||||
end
|
||||
|
||||
header:CallMethod('styleFunction', self:GetName())
|
||||
|
||||
local clique = header:GetFrameRef('clickcast_header')
|
||||
if(clique) then
|
||||
clique:SetAttribute('clickcast_button', self)
|
||||
clique:RunAttribute('clickcast_register')
|
||||
end
|
||||
]]
|
||||
|
||||
--[[ oUF:SpawnHeader(overrideName, template, visibility, ...)
|
||||
Used to create a group header and apply the currently active style to it.
|
||||
|
||||
* self - the global oUF object
|
||||
* overrideName - unique global name to be used for the header. Defaults to an auto-generated name based on the name
|
||||
of the active style and other arguments passed to `:SpawnHeader` (string?)
|
||||
* template - name of a template to be used for creating the header. Defaults to `'SecureGroupHeaderTemplate'`
|
||||
(string?)
|
||||
* visibility - macro conditional(s) which define when to display the header (string).
|
||||
* ... - further argument pairs. Consult [Group Headers](http://wowprogramming.com/docs/secure_template/Group_Headers.html)
|
||||
for possible values.
|
||||
|
||||
In addition to the standard group headers, oUF implements some of its own attributes. These can be supplied by the
|
||||
layout, but are optional.
|
||||
|
||||
* oUF-initialConfigFunction - can contain code that will be securely run at the end of the initial secure
|
||||
configuration (string?)
|
||||
* oUF-onlyProcessChildren - can be used to force headers to only process children (boolean?)
|
||||
--]]
|
||||
function oUF:SpawnHeader(overrideName, template, visibility, ...)
|
||||
if(not style) then return error('Unable to create frame. No styles have been registered.') end
|
||||
|
||||
template = (template or 'SecureGroupHeaderTemplate')
|
||||
|
||||
local isPetHeader = template:match('PetHeader')
|
||||
local name = overrideName or generateName(nil, ...)
|
||||
local header = CreateFrame('Frame', name, PetBattleFrameHider, template)
|
||||
|
||||
header:SetAttribute('template', 'SecureUnitButtonTemplate, SecureHandlerStateTemplate, SecureHandlerEnterLeaveTemplate')
|
||||
for i = 1, select('#', ...), 2 do
|
||||
local att, val = select(i, ...)
|
||||
if(not att) then break end
|
||||
header:SetAttribute(att, val)
|
||||
end
|
||||
|
||||
header.style = style
|
||||
header.styleFunction = styleProxy
|
||||
header.visibility = visibility
|
||||
|
||||
-- Expose the header through oUF.headers.
|
||||
table.insert(headers, header)
|
||||
|
||||
-- We set it here so layouts can't directly override it.
|
||||
header:SetAttribute('initialConfigFunction', initialConfigFunction)
|
||||
header:SetAttribute('_initialAttributeNames', '_onenter,_onleave,refreshUnitChange,_onstate-vehicleui')
|
||||
header:SetAttribute('_initialAttribute-_onenter', [[
|
||||
local snippet = self:GetAttribute('clickcast_onenter')
|
||||
if(snippet) then
|
||||
self:Run(snippet)
|
||||
end
|
||||
]])
|
||||
header:SetAttribute('_initialAttribute-_onleave', [[
|
||||
local snippet = self:GetAttribute('clickcast_onleave')
|
||||
if(snippet) then
|
||||
self:Run(snippet)
|
||||
end
|
||||
]])
|
||||
header:SetAttribute('_initialAttribute-refreshUnitChange', [[
|
||||
local unit = self:GetAttribute('unit')
|
||||
if(unit) then
|
||||
RegisterStateDriver(self, 'vehicleui', '[@' .. unit .. ',unithasvehicleui]vehicle; novehicle')
|
||||
else
|
||||
UnregisterStateDriver(self, 'vehicleui')
|
||||
end
|
||||
]])
|
||||
header:SetAttribute('_initialAttribute-_onstate-vehicleui', [[
|
||||
local unit = self:GetAttribute('unit')
|
||||
if(newstate == 'vehicle' and unit and UnitPlayerOrPetInRaid(unit) and not UnitTargetsVehicleInRaidUI(unit)) then
|
||||
self:SetAttribute('toggleForVehicle', false)
|
||||
else
|
||||
self:SetAttribute('toggleForVehicle', true)
|
||||
end
|
||||
]])
|
||||
header:SetAttribute('oUF-headerType', isPetHeader and 'pet' or 'group')
|
||||
|
||||
if(Clique) then
|
||||
SecureHandlerSetFrameRef(header, 'clickcast_header', Clique.header)
|
||||
end
|
||||
|
||||
if(header:GetAttribute('showParty')) then
|
||||
self:DisableBlizzard('party')
|
||||
end
|
||||
|
||||
if(visibility) then
|
||||
local type, list = string.split(' ', visibility, 2)
|
||||
if(list and type == 'custom') then
|
||||
RegisterAttributeDriver(header, 'state-visibility', list)
|
||||
header.visibility = list
|
||||
else
|
||||
local condition = getCondition(string.split(',', visibility))
|
||||
RegisterAttributeDriver(header, 'state-visibility', condition)
|
||||
header.visibility = condition
|
||||
end
|
||||
end
|
||||
|
||||
return header
|
||||
end
|
||||
end
|
||||
|
||||
--[[ oUF:Spawn(unit, overrideName)
|
||||
Used to create a single unit frame and apply the currently active style to it.
|
||||
|
||||
* self - the global oUF object
|
||||
* unit - the frame's unit (string)
|
||||
* overrideName - unique global name to use for the unit frame. Defaults to an auto-generated name based on the unit
|
||||
(string?)
|
||||
|
||||
oUF implements some of its own attributes. These can be supplied by the layout, but are optional.
|
||||
|
||||
* oUF-enableArenaPrep - can be used to toggle arena prep support. Defaults to true (boolean)
|
||||
--]]
|
||||
function oUF:Spawn(unit, overrideName, overrideTemplate) -- ElvUI adds overrideTemplate
|
||||
argcheck(unit, 2, 'string')
|
||||
if(not style) then return error('Unable to create frame. No styles have been registered.') end
|
||||
|
||||
unit = unit:lower()
|
||||
|
||||
local name = overrideName or generateName(unit)
|
||||
local object = CreateFrame('Button', name, PetBattleFrameHider, overrideTemplate or 'SecureUnitButtonTemplate')
|
||||
Private.UpdateUnits(object, unit)
|
||||
|
||||
self:DisableBlizzard(unit)
|
||||
walkObject(object, unit)
|
||||
|
||||
object:SetAttribute('unit', unit)
|
||||
RegisterUnitWatch(object)
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
--[[ oUF:SpawnNamePlates(prefix, callback, variables)
|
||||
Used to create nameplates and apply the currently active style to them.
|
||||
|
||||
* self - the global oUF object
|
||||
* prefix - prefix for the global name of the nameplate. Defaults to an auto-generated prefix (string?)
|
||||
* callback - function to be called after a nameplate unit or the player's target has changed. The arguments passed to
|
||||
the callback are the updated nameplate, if any, the event that triggered the update, and the new unit
|
||||
(function?)
|
||||
* variables - list of console variable-value pairs to be set when the player logs in (table?)
|
||||
--]]
|
||||
function oUF:SpawnNamePlates(namePrefix, nameplateCallback, nameplateCVars)
|
||||
argcheck(nameplateCallback, 3, 'function', 'nil')
|
||||
argcheck(nameplateCVars, 4, 'table', 'nil')
|
||||
if(not style) then return error('Unable to create frame. No styles have been registered.') end
|
||||
if(oUF_NamePlateDriver) then return error('oUF nameplate driver has already been initialized.') end
|
||||
|
||||
local style = style
|
||||
local prefix = namePrefix or generateName()
|
||||
|
||||
-- Because there's no way to prevent nameplate settings updates without tainting UI,
|
||||
-- and because forbidden nameplates exist, we have to allow default nameplate
|
||||
-- driver to create, update, and remove Blizz nameplates.
|
||||
-- Disable only not forbidden nameplates.
|
||||
NamePlateDriverFrame:HookScript('OnEvent', function(_, event, unit)
|
||||
if(event == 'NAME_PLATE_UNIT_ADDED' and unit) then
|
||||
self:DisableBlizzard(unit)
|
||||
end
|
||||
end)
|
||||
|
||||
local eventHandler = CreateFrame('Frame', 'oUF_NamePlateDriver')
|
||||
eventHandler:RegisterEvent('NAME_PLATE_UNIT_ADDED')
|
||||
eventHandler:RegisterEvent('NAME_PLATE_UNIT_REMOVED')
|
||||
eventHandler:RegisterEvent('PLAYER_TARGET_CHANGED')
|
||||
eventHandler:RegisterEvent('UNIT_FACTION')
|
||||
|
||||
if(IsLoggedIn()) then
|
||||
if(nameplateCVars) then
|
||||
for cvar, value in next, nameplateCVars do
|
||||
SetCVar(cvar, value)
|
||||
end
|
||||
end
|
||||
else
|
||||
eventHandler:RegisterEvent('PLAYER_LOGIN')
|
||||
end
|
||||
|
||||
eventHandler:SetScript('OnEvent', function(_, event, unit)
|
||||
if(event == 'PLAYER_LOGIN') then
|
||||
if(nameplateCVars) then
|
||||
for cvar, value in next, nameplateCVars do
|
||||
SetCVar(cvar, value)
|
||||
end
|
||||
end
|
||||
elseif(event == 'PLAYER_TARGET_CHANGED') then
|
||||
local nameplate = C_NamePlate.GetNamePlateForUnit('target')
|
||||
if(nameplateCallback) then
|
||||
nameplateCallback(nameplate and nameplate.unitFrame, event, 'target')
|
||||
end
|
||||
|
||||
-- UAE is called after the callback to reduce the number of
|
||||
-- ForceUpdate calls layout devs have to do themselves
|
||||
if(nameplate) then
|
||||
nameplate.unitFrame:UpdateAllElements(event)
|
||||
end
|
||||
elseif(event == 'UNIT_FACTION' and unit) then
|
||||
local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
|
||||
if(not nameplate) then return end
|
||||
|
||||
if(nameplateCallback) then
|
||||
nameplateCallback(nameplate.unitFrame, event, unit)
|
||||
end
|
||||
elseif(event == 'NAME_PLATE_UNIT_ADDED' and unit) then
|
||||
local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
|
||||
if(not nameplate) then return end
|
||||
|
||||
if(not nameplate.unitFrame) then
|
||||
nameplate.style = style
|
||||
|
||||
nameplate.unitFrame = CreateFrame('Button', prefix..nameplate:GetName(), nameplate)
|
||||
nameplate.unitFrame:EnableMouse(false)
|
||||
nameplate.unitFrame.isNamePlate = true
|
||||
|
||||
Private.UpdateUnits(nameplate.unitFrame, unit)
|
||||
|
||||
walkObject(nameplate.unitFrame, unit)
|
||||
else
|
||||
Private.UpdateUnits(nameplate.unitFrame, unit)
|
||||
end
|
||||
|
||||
nameplate.unitFrame:SetAttribute('unit', unit)
|
||||
|
||||
if(nameplateCallback) then
|
||||
nameplateCallback(nameplate.unitFrame, event, unit)
|
||||
end
|
||||
|
||||
-- UAE is called after the callback to reduce the number of
|
||||
-- ForceUpdate calls layout devs have to do themselves
|
||||
nameplate.unitFrame:UpdateAllElements(event)
|
||||
elseif(event == 'NAME_PLATE_UNIT_REMOVED' and unit) then
|
||||
local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
|
||||
if(not nameplate) then return end
|
||||
|
||||
nameplate.unitFrame:SetAttribute('unit', nil)
|
||||
|
||||
if(nameplateCallback) then
|
||||
nameplateCallback(nameplate.unitFrame, event, unit)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
--[[ oUF:AddElement(name, update, enable, disable)
|
||||
Used to register an element with oUF.
|
||||
|
||||
* self - the global oUF object
|
||||
* name - unique name of the element (string)
|
||||
* update - used to update the element (function?)
|
||||
* enable - used to enable the element for a given unit frame and unit (function?)
|
||||
* disable - used to disable the element for a given unit frame (function?)
|
||||
--]]
|
||||
function oUF:AddElement(name, update, enable, disable)
|
||||
argcheck(name, 2, 'string')
|
||||
argcheck(update, 3, 'function', 'nil')
|
||||
argcheck(enable, 4, 'function', 'nil')
|
||||
argcheck(disable, 5, 'function', 'nil')
|
||||
|
||||
if(elements[name]) then return error('Element [%s] is already registered.', name) end
|
||||
elements[name] = {
|
||||
update = update;
|
||||
enable = enable;
|
||||
disable = disable;
|
||||
}
|
||||
end
|
||||
|
||||
oUF.version = _VERSION
|
||||
--[[ oUF.objects
|
||||
Array containing all unit frames created by `oUF:Spawn`.
|
||||
--]]
|
||||
oUF.objects = objects
|
||||
--[[ oUF.headers
|
||||
Array containing all group headers created by `oUF:SpawnHeader`.
|
||||
--]]
|
||||
oUF.headers = headers
|
||||
|
||||
if(global) then
|
||||
if(parent ~= 'oUF' and global == 'oUF') then
|
||||
error('%s is doing it wrong and setting its global to "oUF".', parent)
|
||||
elseif(_G[global]) then
|
||||
error('%s is setting its global to an existing name "%s".', parent, global)
|
||||
else
|
||||
_G[global] = oUF
|
||||
end
|
||||
end
|
||||
63
Libraries/oUF/private.lua
Normal file
63
Libraries/oUF/private.lua
Normal file
@@ -0,0 +1,63 @@
|
||||
local parent, ns = ...
|
||||
local Private = ns.oUF.Private
|
||||
|
||||
function Private.argcheck(value, num, ...)
|
||||
assert(type(num) == 'number', "Bad argument #2 to 'argcheck' (number expected, got " .. type(num) .. ')')
|
||||
|
||||
for i = 1, select('#', ...) do
|
||||
if(type(value) == select(i, ...)) then return end
|
||||
end
|
||||
|
||||
local types = strjoin(', ', ...)
|
||||
local name = debugstack(2,2,0):match(": in function [`<](.-)['>]")
|
||||
error(string.format("Bad argument #%d to '%s' (%s expected, got %s)", num, name, types, type(value)), 3)
|
||||
end
|
||||
|
||||
function Private.print(...)
|
||||
print('|cff33ff99oUF:|r', ...)
|
||||
end
|
||||
|
||||
function Private.error(...)
|
||||
Private.print('|cffff0000Error:|r ' .. string.format(...))
|
||||
end
|
||||
|
||||
function Private.unitExists(unit)
|
||||
return unit and (UnitExists(unit) or ShowBossFrameWhenUninteractable(unit))
|
||||
end
|
||||
|
||||
local validator = CreateFrame('Frame')
|
||||
|
||||
function Private.validateUnit(unit)
|
||||
local isOK, _ = pcall(validator.RegisterUnitEvent, validator, 'UNIT_HEALTH', unit)
|
||||
if(isOK) then
|
||||
_, unit = validator:IsEventRegistered('UNIT_HEALTH')
|
||||
validator:UnregisterEvent('UNIT_HEALTH')
|
||||
|
||||
return not not unit
|
||||
end
|
||||
end
|
||||
|
||||
local selectionTypes = {
|
||||
[ 0] = 0,
|
||||
[ 1] = 1,
|
||||
[ 2] = 2,
|
||||
[ 3] = 3,
|
||||
[ 4] = 4,
|
||||
[ 5] = 5,
|
||||
[ 6] = 6,
|
||||
[ 7] = 7,
|
||||
[ 8] = 8,
|
||||
[ 9] = 9,
|
||||
-- [10] = 10, -- unavailable to players
|
||||
-- [11] = 11, -- unavailable to players
|
||||
-- [12] = 12, -- inconsistent due to bugs and its reliance on cvars
|
||||
[13] = 13,
|
||||
}
|
||||
|
||||
function Private.unitSelectionType(unit, considerHostile)
|
||||
if(considerHostile and UnitThreatSituation('player', unit)) then
|
||||
return 0
|
||||
else
|
||||
return selectionTypes[UnitSelectionType(unit, true)]
|
||||
end
|
||||
end
|
||||
187
Libraries/oUF/units.lua
Normal file
187
Libraries/oUF/units.lua
Normal file
@@ -0,0 +1,187 @@
|
||||
local parent, ns = ...
|
||||
local oUF = ns.oUF
|
||||
local Private = oUF.Private
|
||||
|
||||
local enableTargetUpdate = Private.enableTargetUpdate
|
||||
|
||||
local function updateArenaPreparationElements(self, event, elementName, specID)
|
||||
local element = self[elementName]
|
||||
if(element and self:IsElementEnabled(elementName)) then
|
||||
if(element.OverrideArenaPreparation) then
|
||||
--[[ Override: Health.OverrideArenaPreparation(self, event, specID)
|
||||
Used to completely override the internal update function for arena preparation.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* specID - the specialization ID for the opponent (number)
|
||||
--]]
|
||||
--[[ Override: Power.OverrideArenaPreparation(self, event, specID)
|
||||
Used to completely override the internal update function for arena preparation.
|
||||
|
||||
* self - the parent object
|
||||
* event - the event triggering the update (string)
|
||||
* specID - the specialization ID for the opponent (number)
|
||||
--]]
|
||||
element.OverrideArenaPreparation(self, event, specID)
|
||||
return
|
||||
end
|
||||
|
||||
element:SetMinMaxValues(0, 1)
|
||||
element:SetValue(1)
|
||||
if(element.UpdateColorArenaPreparation) then
|
||||
--[[ Override: Health:UpdateColor(specID)
|
||||
Used to completely override the internal function for updating the widget's colors
|
||||
during arena preparation.
|
||||
|
||||
* self - the Health element
|
||||
* specID - the specialization ID for the opponent (number)
|
||||
--]]
|
||||
--[[ Override: Power:UpdateColor(specID)
|
||||
Used to completely override the internal function for updating the widget's colors
|
||||
during arena preparation.
|
||||
|
||||
* self - the Power element
|
||||
* specID - the specialization ID for the opponent (number)
|
||||
--]]
|
||||
element:UpdateColorArenaPreparation(specID)
|
||||
else
|
||||
-- this section just replicates the color options available to the Health and Power elements
|
||||
local r, g, b, t, _
|
||||
-- if(element.colorPower and elementName == 'Power') then
|
||||
-- FIXME: no idea if we can get power type here without the unit
|
||||
if(element.colorClass) then
|
||||
local _, _, _, _, _, class = GetSpecializationInfoByID(specID)
|
||||
t = self.colors.class[class]
|
||||
elseif(element.colorReaction) then
|
||||
t = self.colors.reaction[2]
|
||||
elseif(element.colorSmooth) then
|
||||
_, _, _, _, _, _, r, g, b = unpack(element.smoothGradient or self.colors.smooth)
|
||||
elseif(element.colorHealth and elementName == 'Health') then
|
||||
t = self.colors.health
|
||||
end
|
||||
|
||||
if(t) then
|
||||
r, g, b = t[1], t[2], t[3]
|
||||
end
|
||||
|
||||
if(r or g or b) then
|
||||
element:SetStatusBarColor(r, g, b)
|
||||
|
||||
local bg = element.bg
|
||||
if(bg) then
|
||||
local mu = bg.multiplier or 1
|
||||
bg:SetVertexColor(r * mu, g * mu, b * mu)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if(element.PostUpdateArenaPreparation) then
|
||||
--[[ Callback: Health:PostUpdateArenaPreparation(event, specID)
|
||||
Called after the element has been updated during arena preparation.
|
||||
|
||||
* self - the Health element
|
||||
* event - the event triggering the update (string)
|
||||
* specID - the specialization ID for the opponent (number)
|
||||
--]]
|
||||
--[[ Callback: Power:PostUpdateArenaPreparation(event, specID)
|
||||
Called after the element has been updated during arena preparation.
|
||||
|
||||
* self - the Power element
|
||||
* event - the event triggering the update (string)
|
||||
* specID - the specialization ID for the opponent (number)
|
||||
--]]
|
||||
element:PostUpdateArenaPreparation(event, specID)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function updateArenaPreparation(self, event)
|
||||
if(not self:GetAttribute('oUF-enableArenaPrep')) then
|
||||
return
|
||||
end
|
||||
|
||||
if(event == 'ARENA_OPPONENT_UPDATE' and not self:IsEnabled()) then
|
||||
self:Enable()
|
||||
self:UpdateAllElements('ArenaPreparation')
|
||||
self:UnregisterEvent(event, updateArenaPreparation)
|
||||
|
||||
-- show elements that don't handle their own visibility
|
||||
if(self:IsElementEnabled('Auras')) then
|
||||
if(self.Auras) then self.Auras:Show() end
|
||||
if(self.Buffs) then self.Buffs:Show() end
|
||||
if(self.Debuffs) then self.Debuffs:Show() end
|
||||
end
|
||||
|
||||
if(self.Portrait and self:IsElementEnabled('Portrait')) then
|
||||
self.Portrait:Show()
|
||||
end
|
||||
elseif(event == 'PLAYER_ENTERING_WORLD' and not UnitExists(self.unit)) then
|
||||
-- semi-recursive call for when the player zones into an arena
|
||||
updateArenaPreparation(self, 'ARENA_PREP_OPPONENT_SPECIALIZATIONS')
|
||||
elseif(event == 'ARENA_PREP_OPPONENT_SPECIALIZATIONS') then
|
||||
if(self.PreUpdate) then
|
||||
self:PreUpdate(event)
|
||||
end
|
||||
|
||||
local id = tonumber(self.id)
|
||||
if(not self:IsEnabled() and GetNumArenaOpponentSpecs() < id) then
|
||||
-- hide the object if the opponent leaves
|
||||
self:Hide()
|
||||
end
|
||||
|
||||
local specID = GetArenaOpponentSpec(id)
|
||||
if(specID) then
|
||||
if(self:IsEnabled()) then
|
||||
-- disable the unit watch so we can forcefully show the object ourselves
|
||||
self:Disable()
|
||||
self:RegisterEvent('ARENA_OPPONENT_UPDATE', updateArenaPreparation)
|
||||
end
|
||||
|
||||
-- update Health and Power (if available) with "fake" data
|
||||
updateArenaPreparationElements(self, event, 'Health', specID)
|
||||
updateArenaPreparationElements(self, event, 'Power', specID)
|
||||
|
||||
-- hide all other (relevant) elements (they have no effect during arena prep)
|
||||
if(self.Auras) then self.Auras:Hide() end
|
||||
if(self.Buffs) then self.Buffs:Hide() end
|
||||
if(self.Debuffs) then self.Debuffs:Hide() end
|
||||
if(self.Castbar) then self.Castbar:Hide() end
|
||||
if(self.CombatIndicator) then self.CombatIndicator:Hide() end
|
||||
if(self.PartyIndicator) then self.PartyIndicator:Hide() end
|
||||
if(self.GroupRoleIndicator) then self.GroupRoleIndicator:Hide() end
|
||||
if(self.Portrait) then self.Portrait:Hide() end
|
||||
if(self.PvPIndicator) then self.PvPIndicator:Hide() end
|
||||
if(self.RaidTargetIndicator) then self.RaidTargetIndicator:Hide() end
|
||||
|
||||
self:Show()
|
||||
self:UpdateTags()
|
||||
end
|
||||
|
||||
if(self.PostUpdate) then
|
||||
self:PostUpdate(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Handles unit specific actions.
|
||||
function oUF:HandleUnit(object, unit)
|
||||
local unit = object.unit or unit
|
||||
if(unit == 'target') then
|
||||
object:RegisterEvent('PLAYER_TARGET_CHANGED', object.UpdateAllElements, true)
|
||||
elseif(unit == 'mouseover') then
|
||||
object:RegisterEvent('UPDATE_MOUSEOVER_UNIT', object.UpdateAllElements, true)
|
||||
elseif(unit == 'focus') then
|
||||
object:RegisterEvent('PLAYER_FOCUS_CHANGED', object.UpdateAllElements, true)
|
||||
elseif(unit:match('boss%d?$')) then
|
||||
object:RegisterEvent('INSTANCE_ENCOUNTER_ENGAGE_UNIT', object.UpdateAllElements, true)
|
||||
object:RegisterEvent('UNIT_TARGETABLE_CHANGED', object.UpdateAllElements)
|
||||
elseif(unit:match('arena%d?$')) then
|
||||
object:RegisterEvent('ARENA_OPPONENT_UPDATE', object.UpdateAllElements, true)
|
||||
object:RegisterEvent('ARENA_PREP_OPPONENT_SPECIALIZATIONS', updateArenaPreparation, true)
|
||||
object:SetAttribute('oUF-enableArenaPrep', true)
|
||||
-- the event handler only fires for visible frames, so we have to hook it for arena prep
|
||||
object:HookScript('OnEvent', updateArenaPreparation)
|
||||
elseif(unit:match('%w+target')) then
|
||||
enableTargetUpdate(object)
|
||||
end
|
||||
end
|
||||
82
Libraries/oUF/utils/changelog
Normal file
82
Libraries/oUF/utils/changelog
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env lua
|
||||
|
||||
local tags = {}
|
||||
do
|
||||
for tag in io.popen('git tag'):lines() do
|
||||
local split = tag:gmatch('[^.]+')
|
||||
local release, api, bugfix = split(), split(), split() or 0
|
||||
table.insert(
|
||||
tags,
|
||||
{
|
||||
string = tag,
|
||||
release = release,
|
||||
api = api,
|
||||
bugfix = bugfix,
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
table.sort(tags, function(a,b)
|
||||
a = a.release * 1e4 + a.api * 100 + a.bugfix
|
||||
b = b.release * 1e4 + b.api * 100 + b.bugfix
|
||||
|
||||
return a > b
|
||||
end)
|
||||
end
|
||||
|
||||
local generateLog = function(prevTag, currentTag)
|
||||
local ti = table.insert
|
||||
local sf = string.format
|
||||
|
||||
local out = {}
|
||||
local i = 0
|
||||
|
||||
ti(out, sf('**Changes in %s:**\n', currentTag))
|
||||
|
||||
for line in io.popen(sf('git shortlog --no-merges --reverse %s..%s', prevTag, currentTag)):lines() do
|
||||
if(line:sub(1, 6) == ' ') then
|
||||
local offset = line:match('() ', 7)
|
||||
if(offset) then
|
||||
line = line:sub(7, offset - 1)
|
||||
else
|
||||
line = line:sub(7)
|
||||
end
|
||||
line = line:gsub('#(%d+)', '[#%1](https://github.com/oUF-wow/oUF/issues/%1)')
|
||||
|
||||
i = i + 1
|
||||
ti(out, sf(' %s. %s', i, line))
|
||||
elseif(#line ~= 0) then
|
||||
i = 0
|
||||
ti(out, sf('- _%s_', line))
|
||||
end
|
||||
end
|
||||
|
||||
local p = assert(io.popen(sf('git diff --shortstat %s..%s', prevTag, currentTag)))
|
||||
local stat = p:read'*a'
|
||||
p:close()
|
||||
|
||||
ti(out, sf('- %s\n', stat:sub(2, -2)))
|
||||
|
||||
return table.concat(out, '\n')
|
||||
end
|
||||
|
||||
local stop
|
||||
local to = ...
|
||||
if(to) then
|
||||
for i=1, #tags do
|
||||
if(tags[i].string == to) then
|
||||
stop = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
if(not stop) then stop = #tags end
|
||||
else
|
||||
stop = #tags
|
||||
end
|
||||
|
||||
for i=2, stop do
|
||||
local current, prev = tags[i -1], tags[i]
|
||||
print(generateLog(prev.string, current.string))
|
||||
end
|
||||
|
||||
-- vim: set filetype=lua :
|
||||
254
Libraries/oUF/utils/docs
Normal file
254
Libraries/oUF/utils/docs
Normal file
@@ -0,0 +1,254 @@
|
||||
#!/usr/bin/env lua
|
||||
-- docs
|
||||
-- oUF documentation generator
|
||||
--
|
||||
-- This is really just a quick and dirty way of generating documentation for
|
||||
-- oUF[1]. The syntax is inspired by TomDoc[2], but a lot of the non-oUF and
|
||||
-- non-Lua things aren't implemented.
|
||||
--
|
||||
-- Why implement my own documentation generator?
|
||||
-- It was mainly done because oUF is kind-of special, but also because the
|
||||
-- available alternatives aren't good enough or have issues I can't workaround.
|
||||
--
|
||||
-- Things that need fixing:
|
||||
-- - No highlighting of Lua code.
|
||||
-- - Doesn't validate that comments are documentation strings.
|
||||
-- - Doesn't parse its own documentation header.
|
||||
-- - Close to zero error handling.
|
||||
--
|
||||
-- Usage
|
||||
--
|
||||
-- docs [docs path] [file...]
|
||||
--
|
||||
-- Links
|
||||
--
|
||||
-- [1] https://github.com/haste/oUF
|
||||
-- [2] http://tomdoc.org/
|
||||
|
||||
local out
|
||||
local lines
|
||||
|
||||
local tisf = function(fmt, ...)
|
||||
table.insert(out, fmt:format(...))
|
||||
end
|
||||
|
||||
local trim = function(str)
|
||||
return str:match('^()%s*$') and '' or str:match('^%s*(.*%S)')
|
||||
end
|
||||
|
||||
local findNextEmpty = function(start, stop)
|
||||
for i=start, stop or #lines do
|
||||
if(lines[i] == '') then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local findNextHeader = function(offest)
|
||||
for i=offest, #lines do
|
||||
local pre, header, post = unpack(lines, i, i + 2)
|
||||
-- Single lines without punctuation are headers.
|
||||
if(pre == '' and post == '' and not header:match'%.') then
|
||||
return i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local findNextArguent = function(start, stop, padding, pattern)
|
||||
for i=start, stop do
|
||||
local match, pad = lines[i]:match(pattern)
|
||||
if(match and pad == padding) then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local replaceMarkup = function(str)
|
||||
return str
|
||||
-- `in-line code` to <code>in-line code</code>
|
||||
:gsub('`([^`]+)`', '<code>%1</code>')
|
||||
-- [Link](http://example.com) to <a href="http://example.com">Link</a>
|
||||
:gsub('%[([^%]]+)%]%(([^)]+)%)', '<a href="%2">%1</a>')
|
||||
end
|
||||
|
||||
local handleArguments = function(start, stop, pattern)
|
||||
tisf('<dl>')
|
||||
repeat
|
||||
-- Tear out the argument name and offset of where the description begins.
|
||||
local def, padding, offset = lines[start]:match(pattern)
|
||||
tisf('<dt>%s</dt>', def)
|
||||
|
||||
-- Insert the first line of the description.
|
||||
tisf('<dd>')
|
||||
tisf(lines[start]:sub(offset))
|
||||
|
||||
-- Find the next argument in the list or continue to the end of the
|
||||
-- current section.
|
||||
local nextarg = findNextArguent(start + 1, stop, padding, pattern)
|
||||
nextarg = (nextarg or stop + 1) - 1
|
||||
for i=start + 1, nextarg do
|
||||
tisf(trim(lines[i]))
|
||||
end
|
||||
tisf('</dd>')
|
||||
|
||||
start = nextarg + 1
|
||||
until start > stop
|
||||
tisf('</dl>')
|
||||
end
|
||||
|
||||
local handleExamples = function(start, stop)
|
||||
-- An extra line gets added if we don't do this.
|
||||
tisf('<pre><code>%s', lines[start]:sub(3))
|
||||
for i=start + 1, stop do
|
||||
tisf(lines[i]:sub(3))
|
||||
end
|
||||
tisf('</code></pre>')
|
||||
end
|
||||
|
||||
local handleParagraph = function(start, stop)
|
||||
tisf('<p>')
|
||||
for i=start, stop do
|
||||
tisf(trim(lines[i]))
|
||||
end
|
||||
tisf('</p>')
|
||||
end
|
||||
|
||||
local handleSection = function(start, stop)
|
||||
while(start) do
|
||||
-- Find the next empty line or continue until the end of the section.
|
||||
-- findNextEmpty() returns the position of the empty line, so we need to
|
||||
-- subtract one from it.
|
||||
local nextEmpty = findNextEmpty(start + 1, stop)
|
||||
if(nextEmpty) then
|
||||
nextEmpty = nextEmpty - 1
|
||||
else
|
||||
nextEmpty = stop
|
||||
end
|
||||
|
||||
local line = lines[start]
|
||||
if(not line) then
|
||||
return
|
||||
elseif(line:match('^%S+%s*%- ')) then
|
||||
handleArguments(start, nextEmpty, '(%S+)%s*()%- ()')
|
||||
elseif(line:sub(1, 2) == ' ') then
|
||||
handleExamples(start, nextEmpty)
|
||||
else
|
||||
handleParagraph(start, nextEmpty)
|
||||
end
|
||||
|
||||
start = findNextEmpty(nextEmpty, stop)
|
||||
if(start) then start = start + 1 end
|
||||
end
|
||||
end
|
||||
|
||||
local generateDocs = function(str, level)
|
||||
lines = {}
|
||||
out = {}
|
||||
|
||||
for line in str:gmatch('([^\n]*)\n') do
|
||||
table.insert(lines, line:gsub('\t*', ''):sub(2))
|
||||
end
|
||||
|
||||
-- The first line is always the main header.
|
||||
tisf('<h%d>%s</h%d>', level, lines[1], level)
|
||||
|
||||
-- Then comes the main description.
|
||||
local offset = findNextHeader(1)
|
||||
|
||||
-- Continue until two lines before the header or to the end of the comment.
|
||||
if(offset) then
|
||||
offset = offset - 2
|
||||
else
|
||||
offset = #lines
|
||||
end
|
||||
|
||||
local init = findNextEmpty(1) + 1
|
||||
if(init > offset) then
|
||||
init = 2
|
||||
end
|
||||
|
||||
handleSection(init, offset)
|
||||
|
||||
while(true) do
|
||||
offset = findNextHeader(offset)
|
||||
if(not offset) then break end
|
||||
|
||||
-- Every section has a header.
|
||||
tisf('<h%d>%s</h%d>', level + 1, lines[offset], level + 1)
|
||||
|
||||
-- Find out the size of the section.
|
||||
local start = findNextEmpty(offset) + 1
|
||||
if(not lines[start]) then
|
||||
-- There's no section here, only a headline.
|
||||
break
|
||||
end
|
||||
|
||||
local stop
|
||||
local nextHeader = findNextHeader(start)
|
||||
if(nextHeader) then
|
||||
stop = nextHeader - 2
|
||||
else
|
||||
local nextEmpty = findNextEmpty(start)
|
||||
if(nextEmpty) then
|
||||
stop = nextEmpty - 1
|
||||
else
|
||||
stop = #lines
|
||||
end
|
||||
end
|
||||
|
||||
handleSection(start, stop)
|
||||
offset = stop + 1
|
||||
end
|
||||
|
||||
return table.concat(out, '\n')
|
||||
end
|
||||
|
||||
local handleFile = function(path)
|
||||
local file = io.open(path, 'r')
|
||||
local content = file:read'*a'
|
||||
file:close()
|
||||
|
||||
local out = {}
|
||||
local init = 1
|
||||
repeat
|
||||
local _, comStart, depth = content:find('%-%-%[(=*)%[ ', init)
|
||||
if(comStart) then
|
||||
local comEnd = content:find('%]' .. depth .. '%]', comStart)
|
||||
local comment = content:sub(comStart, comEnd - 1)
|
||||
|
||||
-- Convert markup to html.
|
||||
comment = replaceMarkup(comment)
|
||||
|
||||
-- The first comment uses h1 and h2, while the subsequent ones uses h3
|
||||
-- and h4.
|
||||
local level = init == 1 and 1 or 3
|
||||
table.insert(out, generateDocs(comment, init == 1 and 1 or 3))
|
||||
|
||||
init = comEnd
|
||||
end
|
||||
until not comStart
|
||||
|
||||
return table.concat(out, '\n')
|
||||
end
|
||||
|
||||
local destination = (...)
|
||||
for i=2, select('#', ...) do
|
||||
local file = select(i, ...)
|
||||
local path, filename = file:match('(.+)/(.+)$')
|
||||
|
||||
if(path:sub(1,3) == '../') then
|
||||
path = path:sub(4)
|
||||
end
|
||||
|
||||
if(#path == 0) then path = nil end
|
||||
filename = filename:gsub('lua', 'html')
|
||||
|
||||
local doc = handleFile(file)
|
||||
if(doc) then
|
||||
local dfPath = string.format('%s/%s', destination, path or '')
|
||||
os.execute(string.format('mkdir -p %s', dfPath))
|
||||
local docFile = io.open(string.format('%s/%s', dfPath, filename), 'w+')
|
||||
docFile:write(doc)
|
||||
docFile:close()
|
||||
end
|
||||
end
|
||||
311
Libraries/oUF_Plugins/oUF_AuraBars/oUF_AuraBars.lua
Normal file
311
Libraries/oUF_Plugins/oUF_AuraBars/oUF_AuraBars.lua
Normal file
@@ -0,0 +1,311 @@
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local VISIBLE = 1
|
||||
local HIDDEN = 0
|
||||
|
||||
local pcall = pcall
|
||||
local floor = floor
|
||||
local format = format
|
||||
local unpack = unpack
|
||||
local tinsert = tinsert
|
||||
local infinity = math.huge
|
||||
|
||||
local _G = _G
|
||||
local GetTime = GetTime
|
||||
local UnitAura = UnitAura
|
||||
local CreateFrame = CreateFrame
|
||||
local UnitIsEnemy = UnitIsEnemy
|
||||
local UnitReaction = UnitReaction
|
||||
local GameTooltip = GameTooltip
|
||||
|
||||
local DAY, HOUR, MINUTE = 86400, 3600, 60
|
||||
local function FormatTime(s)
|
||||
if s == infinity then return end
|
||||
|
||||
if s < MINUTE then
|
||||
return format("%.1fs", s)
|
||||
elseif s < HOUR then
|
||||
return format("%dm %ds", s/60%60, s%60)
|
||||
elseif s < DAY then
|
||||
return format("%dh %dm", s/(60*60), s/60%60)
|
||||
else
|
||||
return format("%dd %dh", s/DAY, (s / HOUR) - (floor(s/DAY) * 24))
|
||||
end
|
||||
end
|
||||
|
||||
local function onEnter(self)
|
||||
if GameTooltip:IsForbidden() or not self:IsVisible() then return end
|
||||
|
||||
GameTooltip:SetOwner(self, self.tooltipAnchor)
|
||||
GameTooltip:SetUnitAura(self.unit, self.index, self.filter)
|
||||
end
|
||||
|
||||
local function onLeave()
|
||||
if GameTooltip:IsForbidden() then return end
|
||||
|
||||
GameTooltip:Hide()
|
||||
end
|
||||
|
||||
local function onUpdate(self, elapsed)
|
||||
self.elapsed = (self.elapsed or 0) + elapsed
|
||||
if self.elapsed >= 0.01 then
|
||||
if self.noTime then
|
||||
self:SetValue(1)
|
||||
self.timeText:SetText()
|
||||
self:SetScript("OnUpdate", nil)
|
||||
else
|
||||
local timeNow = GetTime()
|
||||
self:SetValue((self.expiration - timeNow) / self.duration)
|
||||
self.timeText:SetText(FormatTime(self.expiration - timeNow))
|
||||
end
|
||||
self.elapsed = 0
|
||||
end
|
||||
end
|
||||
|
||||
local function createAuraBar(element, index)
|
||||
local statusBar = CreateFrame('StatusBar', element:GetName() .. 'StatusBar' .. index, element)
|
||||
statusBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
|
||||
statusBar:SetMinMaxValues(0, 1)
|
||||
statusBar.tooltipAnchor = element.tooltipAnchor
|
||||
statusBar:SetScript('OnEnter', onEnter)
|
||||
statusBar:SetScript('OnLeave', onLeave)
|
||||
statusBar:EnableMouse(false)
|
||||
|
||||
local spark = statusBar:CreateTexture(nil, "OVERLAY", nil);
|
||||
spark:SetTexture([[Interface\CastingBar\UI-CastingBar-Spark]])
|
||||
spark:SetWidth(12)
|
||||
spark:SetBlendMode("ADD")
|
||||
spark:SetPoint('CENTER', statusBar:GetStatusBarTexture(), 'RIGHT')
|
||||
|
||||
local icon = statusBar:CreateTexture(nil, 'ARTWORK')
|
||||
icon:SetPoint('RIGHT', statusBar, 'LEFT', -(element.gap or 2), 0)
|
||||
icon:SetSize(element.height, element.height)
|
||||
|
||||
local nameText = statusBar:CreateFontString(nil, 'OVERLAY', 'NumberFontNormal')
|
||||
nameText:SetPoint('LEFT', statusBar, 'LEFT', 2, 0)
|
||||
|
||||
local timeText = statusBar:CreateFontString(nil, 'OVERLAY', 'NumberFontNormal')
|
||||
timeText:SetPoint('RIGHT', statusBar, 'RIGHT', -2, 0)
|
||||
|
||||
statusBar.icon = icon
|
||||
statusBar.nameText = nameText
|
||||
statusBar.timeText = timeText
|
||||
statusBar.spark = spark
|
||||
|
||||
if(element.PostCreateBar) then element:PostCreateBar(statusBar) end
|
||||
|
||||
return statusBar
|
||||
end
|
||||
|
||||
local function customFilter(element, unit, button, name)
|
||||
if((element.onlyShowPlayer and button.isPlayer) or (not element.onlyShowPlayer and name)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function updateBar(element, unit, index, offset, filter, isDebuff, visible)
|
||||
local name, texture, count, debuffType, duration, expiration, caster, isStealable, nameplateShowSelf, spellID, canApply, isBossDebuff, casterIsPlayer, nameplateShowAll, timeMod, effect1, effect2, effect3 = UnitAura(unit, index, filter)
|
||||
|
||||
if(name) then
|
||||
local position = visible + offset + 1
|
||||
local statusBar = element[position]
|
||||
if(not statusBar) then
|
||||
statusBar = (element.CreateBar or createAuraBar) (element, position)
|
||||
tinsert(element, statusBar)
|
||||
element.createdBars = element.createdBars + 1
|
||||
end
|
||||
|
||||
statusBar.unit = unit
|
||||
statusBar.index = index
|
||||
statusBar.caster = caster
|
||||
statusBar.filter = filter
|
||||
statusBar.isDebuff = isDebuff
|
||||
statusBar.isPlayer = caster == 'player' or caster == 'vehicle'
|
||||
|
||||
local show = (element.CustomFilter or customFilter) (element, unit, statusBar, name, texture,
|
||||
count, debuffType, duration, expiration, caster, isStealable, nameplateShowSelf, spellID,
|
||||
canApply, isBossDebuff, casterIsPlayer, nameplateShowAll, timeMod, effect1, effect2, effect3)
|
||||
|
||||
if(show) then
|
||||
statusBar.icon:SetTexture(texture)
|
||||
if count > 1 then
|
||||
statusBar.nameText:SetFormattedText('[%d] %s', count, name)
|
||||
else
|
||||
statusBar.nameText:SetText(name)
|
||||
end
|
||||
|
||||
statusBar.duration = duration
|
||||
statusBar.expiration = expiration
|
||||
statusBar.spellID = spellID
|
||||
statusBar.spell = name
|
||||
statusBar.noTime = (duration == 0 and expiration == 0)
|
||||
|
||||
if not statusBar.noTime and element.sparkEnabled then
|
||||
statusBar.spark:Show()
|
||||
else
|
||||
statusBar.spark:Hide()
|
||||
end
|
||||
|
||||
local r, g, b = .2, .6, 1
|
||||
if element.buffColor then r, g, b = unpack(element.buffColor) end
|
||||
if filter == 'HARMFUL' then
|
||||
if not debuffType or debuffType == '' then
|
||||
debuffType = 'none'
|
||||
end
|
||||
|
||||
local color = _G.DebuffTypeColor[debuffType]
|
||||
r, g, b = color.r, color.g, color.b
|
||||
end
|
||||
|
||||
statusBar:SetStatusBarColor(r, g, b)
|
||||
statusBar:SetSize(element.width, element.height)
|
||||
statusBar.icon:SetSize(element.height, element.height)
|
||||
statusBar:SetScript('OnUpdate', onUpdate)
|
||||
statusBar:SetID(index)
|
||||
statusBar:Show()
|
||||
|
||||
if(element.PostUpdateBar) then
|
||||
element:PostUpdateBar(unit, statusBar, index, position, duration, expiration, debuffType, isStealable)
|
||||
end
|
||||
|
||||
return VISIBLE
|
||||
else
|
||||
return HIDDEN
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function SetPosition(element, from, to)
|
||||
local height = element.height
|
||||
local spacing = element.spacing or 1
|
||||
local anchor = element.initialAnchor
|
||||
local growth = element.growth == 'DOWN' and -1 or 1
|
||||
|
||||
for i = from, to do
|
||||
local button = element[i]
|
||||
if(not button) then break end
|
||||
|
||||
button:ClearAllPoints()
|
||||
button:SetPoint(anchor, element, anchor, (height + element.gap), growth * (i > 1 and ((i - 1) * (height + spacing)) or 0))
|
||||
end
|
||||
end
|
||||
|
||||
local function filterBars(element, unit, filter, limit, isDebuff, offset, dontHide)
|
||||
if(not offset) then offset = 0 end
|
||||
local index = 1
|
||||
local visible = 0
|
||||
local hidden = 0
|
||||
while(visible < limit) do
|
||||
local result = updateBar(element, unit, index, offset, filter, isDebuff, visible)
|
||||
if(not result) then
|
||||
break
|
||||
elseif(result == VISIBLE) then
|
||||
visible = visible + 1
|
||||
elseif(result == HIDDEN) then
|
||||
hidden = hidden + 1
|
||||
end
|
||||
|
||||
index = index + 1
|
||||
end
|
||||
|
||||
if(not dontHide) then
|
||||
for i = visible + offset + 1, #element do
|
||||
element[i]:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
return visible, hidden
|
||||
end
|
||||
|
||||
local function UpdateAuras(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.AuraBars
|
||||
if(element) then
|
||||
if(element.PreUpdate) then element:PreUpdate(unit) end
|
||||
|
||||
local isEnemy = UnitIsEnemy('player', unit)
|
||||
local reaction = UnitReaction('player', unit)
|
||||
local filter = (not isEnemy and (not reaction or reaction > 4) and (element.friendlyAuraType or 'HELPFUL')) or element.enemyAuraType or 'HARMFUL'
|
||||
local visible, hidden = filterBars(element, unit, filter, element.maxBars, filter == 'HARMFUL', 0)
|
||||
|
||||
local fromRange, toRange
|
||||
if(element.PreSetPosition) then
|
||||
fromRange, toRange = element:PreSetPosition(element.maxBars)
|
||||
end
|
||||
|
||||
if(fromRange or element.createdBars > element.anchoredBars) then
|
||||
(element.SetPosition or SetPosition) (element, fromRange or element.anchoredBars + 1, toRange or element.createdBars)
|
||||
element.anchoredBars = element.createdBars
|
||||
end
|
||||
|
||||
if(element.PostUpdate) then element:PostUpdate(unit) end
|
||||
end
|
||||
end
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
UpdateAuras(self, event, unit)
|
||||
|
||||
-- Assume no event means someone wants to re-anchor things. This is usually
|
||||
-- done by UpdateAllElements and :ForceUpdate.
|
||||
if(event == 'ForceUpdate' or not event) then
|
||||
local element = self.AuraBars
|
||||
if(element) then
|
||||
(element.SetPosition or SetPosition) (element, 1, element.createdBars)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Update(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.AuraBars
|
||||
|
||||
if(element) then
|
||||
self:RegisterEvent('UNIT_AURA', UpdateAuras)
|
||||
|
||||
element.__owner = self
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
element.createdBars = element.createdBars or 0
|
||||
element.anchoredBars = 0
|
||||
element.width = element.width or 240
|
||||
element.height = element.height or 12
|
||||
element.sparkEnabled = element.sparkEnabled or true
|
||||
element.spacing = element.spacing or 2
|
||||
element.initialAnchor = element.initialAnchor or 'BOTTOMLEFT'
|
||||
element.growth = element.growth or 'UP'
|
||||
element.gap = element.gap or 2
|
||||
element.maxBars = element.maxBars or 32
|
||||
|
||||
-- Avoid parenting GameTooltip to frames with anchoring restrictions,
|
||||
-- otherwise it'll inherit said restrictions which will cause issues
|
||||
-- with its further positioning, clamping, etc
|
||||
|
||||
if(not pcall(self.GetCenter, self)) then
|
||||
element.tooltipAnchor = 'ANCHOR_CURSOR'
|
||||
else
|
||||
element.tooltipAnchor = element.tooltipAnchor or 'ANCHOR_BOTTOMRIGHT'
|
||||
end
|
||||
|
||||
element:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.AuraBars
|
||||
|
||||
if(element) then
|
||||
self:UnregisterEvent('UNIT_AURA', UpdateAuras)
|
||||
element:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('AuraBars', Update, Enable, Disable)
|
||||
185
Libraries/oUF_Plugins/oUF_AuraHighlight/oUF_AuraHighlight.lua
Normal file
185
Libraries/oUF_Plugins/oUF_AuraHighlight/oUF_AuraHighlight.lua
Normal file
@@ -0,0 +1,185 @@
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
if not oUF then return end
|
||||
|
||||
local UnitAura = UnitAura
|
||||
local UnitCanAssist = UnitCanAssist
|
||||
local GetSpecialization = GetSpecialization
|
||||
local GetActiveSpecGroup = GetActiveSpecGroup
|
||||
local Classic = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
|
||||
local DispelList, BlackList = {}, {}
|
||||
-- GLOBALS: DebuffTypeColor
|
||||
|
||||
--local DispellPriority = { Magic = 4, Curse = 3, Disease = 2, Poison = 1 }
|
||||
--local FilterList = {}
|
||||
|
||||
if Classic then
|
||||
DispelList.PRIEST = { Magic = true, Disease = true }
|
||||
DispelList.SHAMAN = { Poison = true, Disease = true }
|
||||
DispelList.PALADIN = { Magic = true, Poison = true, Disease = true }
|
||||
DispelList.MAGE = { Curse = true }
|
||||
DispelList.DRUID = { Curse = true, Poison = true }
|
||||
DispelList.WARLOCK = { Magic = true }
|
||||
else
|
||||
DispelList.PRIEST = { Magic = true, Disease = true }
|
||||
DispelList.SHAMAN = { Magic = false, Curse = true }
|
||||
DispelList.PALADIN = { Magic = false, Poison = true, Disease = true }
|
||||
DispelList.DRUID = { Magic = false, Curse = true, Poison = true, Disease = false }
|
||||
DispelList.MONK = { Magic = false, Poison = true, Disease = true }
|
||||
DispelList.MAGE = { Curse = true }
|
||||
end
|
||||
|
||||
local playerClass = select(2, UnitClass('player'))
|
||||
local CanDispel = DispelList[playerClass] or {}
|
||||
|
||||
if not Classic then
|
||||
BlackList[140546] = true -- Fully Mutated
|
||||
BlackList[136184] = true -- Thick Bones
|
||||
BlackList[136186] = true -- Clear mind
|
||||
BlackList[136182] = true -- Improved Synapses
|
||||
BlackList[136180] = true -- Keen Eyesight
|
||||
BlackList[105171] = true -- Deep Corruption
|
||||
BlackList[108220] = true -- Deep Corruption
|
||||
BlackList[116095] = true -- Disable, Slow
|
||||
BlackList[137637] = true -- Warbringer, Slow
|
||||
end
|
||||
|
||||
local function GetAuraType(unit, filter, filterTable)
|
||||
if not unit or not UnitCanAssist('player', unit) then return end
|
||||
|
||||
local i = 1
|
||||
while true do
|
||||
local name, texture, _, debufftype, _, _, _, _, _, spellID = UnitAura(unit, i, 'HARMFUL')
|
||||
if not texture then break end
|
||||
|
||||
local filterSpell = filterTable[spellID] or filterTable[name]
|
||||
if filterTable and filterSpell then
|
||||
if filterSpell.enable then
|
||||
return debufftype, texture, true, filterSpell.style, filterSpell.color
|
||||
end
|
||||
elseif debufftype and (not filter or (filter and CanDispel[debufftype])) and not (BlackList[name] or BlackList[spellID]) then
|
||||
return debufftype, texture
|
||||
end
|
||||
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
i = 1
|
||||
while true do
|
||||
local _, texture, _, debufftype, _, _, _, _, _, spellID = UnitAura(unit, i)
|
||||
if not texture then break end
|
||||
|
||||
local filterSpell = filterTable[spellID]
|
||||
if filterTable and filterSpell and filterSpell.enable then
|
||||
return debufftype, texture, true, filterSpell.style, filterSpell.color
|
||||
end
|
||||
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
local function FilterTable()
|
||||
local debufftype, texture, filterSpell
|
||||
return debufftype, texture, true, filterSpell.style, filterSpell.color
|
||||
end
|
||||
]]
|
||||
|
||||
local function CheckTalentTree(tree)
|
||||
local activeGroup = GetActiveSpecGroup()
|
||||
local spec = activeGroup and GetSpecialization(false, false, activeGroup)
|
||||
|
||||
if spec then
|
||||
return tree == spec
|
||||
end
|
||||
end
|
||||
|
||||
local function CheckSpec()
|
||||
if Classic then return end
|
||||
|
||||
-- Check for certain talents to see if we can dispel magic or not
|
||||
if playerClass == 'PALADIN' then
|
||||
CanDispel.Magic = CheckTalentTree(1)
|
||||
elseif playerClass == 'SHAMAN' then
|
||||
CanDispel.Magic = CheckTalentTree(3)
|
||||
elseif playerClass == 'DRUID' then
|
||||
CanDispel.Magic = CheckTalentTree(4)
|
||||
elseif playerClass == 'MONK' then
|
||||
CanDispel.Magic = CheckTalentTree(2)
|
||||
end
|
||||
end
|
||||
|
||||
local function Update(self, _, unit)
|
||||
if unit ~= self.unit then return end
|
||||
|
||||
local debuffType, texture, wasFiltered, style, color = GetAuraType(unit, self.AuraHighlightFilter, self.AuraHighlightFilterTable)
|
||||
|
||||
if wasFiltered then
|
||||
if style == 'GLOW' and self.AuraHightlightGlow then
|
||||
self.AuraHightlightGlow:Show()
|
||||
self.AuraHightlightGlow:SetBackdropBorderColor(color.r, color.g, color.b)
|
||||
elseif self.AuraHightlightGlow then
|
||||
self.AuraHightlightGlow:Hide()
|
||||
self.AuraHighlight:SetVertexColor(color.r, color.g, color.b, color.a)
|
||||
end
|
||||
elseif debuffType then
|
||||
color = DebuffTypeColor[debuffType or 'none']
|
||||
|
||||
if self.AuraHighlightBackdrop and self.AuraHightlightGlow then
|
||||
self.AuraHightlightGlow:Show()
|
||||
self.AuraHightlightGlow:SetBackdropBorderColor(color.r, color.g, color.b)
|
||||
elseif self.AuraHighlightUseTexture then
|
||||
self.AuraHighlight:SetTexture(texture)
|
||||
else
|
||||
self.AuraHighlight:SetVertexColor(color.r, color.g, color.b, color.a)
|
||||
end
|
||||
else
|
||||
if self.AuraHightlightGlow then
|
||||
self.AuraHightlightGlow:Hide()
|
||||
end
|
||||
|
||||
if self.AuraHighlightUseTexture then
|
||||
self.AuraHighlight:SetTexture(nil)
|
||||
else
|
||||
self.AuraHighlight:SetVertexColor(0, 0, 0, 0)
|
||||
end
|
||||
end
|
||||
|
||||
if self.AuraHighlight.PostUpdate then
|
||||
self.AuraHighlight:PostUpdate(self, debuffType, texture, wasFiltered, style, color)
|
||||
end
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
if self.AuraHighlight then
|
||||
self:RegisterEvent('UNIT_AURA', Update)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
local element = self.AuraHighlight
|
||||
if element then
|
||||
self:UnregisterEvent('UNIT_AURA', Update)
|
||||
|
||||
if self.AuraHightlightGlow then
|
||||
self.AuraHightlightGlow:Hide()
|
||||
end
|
||||
|
||||
if element then
|
||||
element:SetVertexColor(0, 0, 0, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local f = CreateFrame('Frame')
|
||||
f:RegisterEvent('CHARACTER_POINTS_CHANGED')
|
||||
|
||||
if not Classic then
|
||||
f:RegisterEvent('PLAYER_TALENT_UPDATE')
|
||||
f:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED')
|
||||
end
|
||||
|
||||
f:SetScript('OnEvent', CheckSpec)
|
||||
|
||||
oUF:AddElement('AuraHighlight', Update, Enable, Disable)
|
||||
304
Libraries/oUF_Plugins/oUF_AuraWatch/oUF_AuraWatch.lua
Normal file
304
Libraries/oUF_Plugins/oUF_AuraWatch/oUF_AuraWatch.lua
Normal file
@@ -0,0 +1,304 @@
|
||||
-- Original work by Astromech
|
||||
-- Rewritten based on Auras by Azilroka
|
||||
|
||||
local _, ns = ...
|
||||
local oUF = ns.oUF
|
||||
|
||||
local VISIBLE = 1
|
||||
local HIDDEN = 0
|
||||
|
||||
local min, wipe, pairs, tinsert = min, wipe, pairs, tinsert
|
||||
local CreateFrame = CreateFrame
|
||||
local UnitAura = UnitAura
|
||||
local UnitIsUnit = UnitIsUnit
|
||||
local GetSpellTexture = GetSpellTexture
|
||||
|
||||
local function createAuraIcon(element, index)
|
||||
local button = CreateFrame('Button', element:GetName() .. 'Button' .. index, element)
|
||||
button:EnableMouse(false)
|
||||
button:Hide()
|
||||
|
||||
local cd = CreateFrame('Cooldown', '$parentCooldown', button, 'CooldownFrameTemplate')
|
||||
cd:SetAllPoints()
|
||||
cd:SetReverse(true)
|
||||
cd:SetDrawBling(false)
|
||||
cd:SetDrawEdge(false)
|
||||
|
||||
local icon = button:CreateTexture(nil, 'ARTWORK')
|
||||
icon:SetAllPoints()
|
||||
|
||||
local countFrame = CreateFrame('Frame', nil, button)
|
||||
countFrame:SetAllPoints(button)
|
||||
countFrame:SetFrameLevel(cd:GetFrameLevel() + 1)
|
||||
|
||||
local count = countFrame:CreateFontString(nil, 'OVERLAY', 'NumberFontNormal')
|
||||
count:SetPoint('BOTTOMRIGHT', countFrame, 'BOTTOMRIGHT', -1, 0)
|
||||
|
||||
local overlay = button:CreateTexture(nil, 'OVERLAY')
|
||||
overlay:SetTexture([[Interface\Buttons\UI-Debuff-Overlays]])
|
||||
overlay:SetAllPoints()
|
||||
overlay:SetTexCoord(.296875, .5703125, 0, .515625)
|
||||
|
||||
button.overlay = overlay
|
||||
button.icon = icon
|
||||
button.count = count
|
||||
button.cd = cd
|
||||
|
||||
if(element.PostCreateIcon) then element:PostCreateIcon(button) end
|
||||
|
||||
return button
|
||||
end
|
||||
|
||||
local function customFilter(element, _, button, name, _, _, debuffType, _, _, caster, isStealable, _, spellID, canApply, isBossDebuff, casterIsPlayer)
|
||||
local setting = element.watched[spellID]
|
||||
if not setting then return false end
|
||||
|
||||
button.onlyShowMissing = setting.onlyShowMissing
|
||||
button.anyUnit = setting.anyUnit
|
||||
|
||||
if setting.enabled then
|
||||
if setting.onlyShowMissing and not setting.anyUnit and caster == 'player' then
|
||||
return false
|
||||
elseif setting.onlyShowMissing and setting.anyUnit and casterIsPlayer then
|
||||
return true
|
||||
elseif not setting.onlyShowMissing and setting.anyUnit and casterIsPlayer then
|
||||
return true
|
||||
elseif not setting.onlyShowMissing and not setting.anyUnit and caster == 'player' then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
local function updateIcon(element, unit, index, offset, filter, isDebuff, visible)
|
||||
local name, texture, count, debuffType, duration, expiration, caster, isStealable,
|
||||
nameplateShowSelf, spellID, canApply, isBossDebuff, casterIsPlayer, nameplateShowAll,
|
||||
timeMod, effect1, effect2, effect3 = UnitAura(unit, index, filter)
|
||||
|
||||
if(name) then
|
||||
local position = visible + offset + 1
|
||||
local button = element[position]
|
||||
if(not button) then
|
||||
button = (element.CreateIcon or createAuraIcon) (element, position)
|
||||
|
||||
tinsert(element, button)
|
||||
element.createdIcons = element.createdIcons + 1
|
||||
end
|
||||
|
||||
button.caster = caster
|
||||
button.filter = filter
|
||||
button.isDebuff = isDebuff
|
||||
button.debuffType = debuffType
|
||||
button.spellID = spellID
|
||||
button.isPlayer = caster == 'player'
|
||||
|
||||
local show = (element.CustomFilter or customFilter) (element, unit, button, name, texture,
|
||||
count, debuffType, duration, expiration, caster, isStealable, nameplateShowSelf, spellID,
|
||||
canApply, isBossDebuff, casterIsPlayer, nameplateShowAll, timeMod, effect1, effect2, effect3)
|
||||
|
||||
if(show) then
|
||||
local setting = element.watched[spellID]
|
||||
if(button.cd) then
|
||||
if(duration and duration > 0) then
|
||||
button.cd:SetCooldown(expiration - duration, duration)
|
||||
button.cd:Show()
|
||||
else
|
||||
button.cd:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
if(button.overlay) then
|
||||
if((isDebuff and element.showDebuffType) or (not isDebuff and element.showBuffType) or element.showType) then
|
||||
local color = element.__owner.colors.debuff[debuffType] or element.__owner.colors.debuff.none
|
||||
|
||||
button.overlay:SetVertexColor(color[1], color[2], color[3])
|
||||
button.overlay:Show()
|
||||
else
|
||||
button.overlay:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
if(button.stealable) then
|
||||
if(not isDebuff and isStealable and element.showStealableBuffs and not UnitIsUnit('player', unit)) then
|
||||
button.stealable:Show()
|
||||
else
|
||||
button.stealable:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
if(button.icon) then button.icon:SetTexture(texture) end
|
||||
if(button.count) then button.count:SetText(count > 1 and count) end
|
||||
|
||||
if setting.sizeOffset == 0 then
|
||||
button:SetSize(element.size, element.size)
|
||||
else
|
||||
button:SetSize(setting.sizeOffset + element.size, setting.sizeOffset + element.size)
|
||||
end
|
||||
|
||||
button:SetID(index)
|
||||
button:Show()
|
||||
button:ClearAllPoints()
|
||||
button:SetPoint(setting.point, setting.xOffset, setting.yOffset)
|
||||
|
||||
if(element.PostUpdateIcon) then
|
||||
element:PostUpdateIcon(unit, button, index, position, duration, expiration, debuffType, isStealable)
|
||||
end
|
||||
|
||||
return VISIBLE
|
||||
else
|
||||
button.isFiltered = true
|
||||
return HIDDEN
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local missing = {}
|
||||
local function onlyShowMissingIcon(element, unit, offset)
|
||||
wipe(missing)
|
||||
|
||||
for SpellID, setting in pairs(element.watched) do
|
||||
if setting.onlyShowMissing then
|
||||
missing[SpellID] = setting
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, #element do
|
||||
local button = element[i]
|
||||
if button.isFiltered and missing[button.spellID] then
|
||||
missing[button.spellID] = nil
|
||||
end
|
||||
end
|
||||
|
||||
local visible = 0
|
||||
for SpellID, setting in pairs(missing) do
|
||||
local position = visible + offset + 1
|
||||
local button = element[position]
|
||||
if(not button) then
|
||||
button = (element.CreateIcon or createAuraIcon) (element, position)
|
||||
tinsert(element, button)
|
||||
element.createdIcons = element.createdIcons + 1
|
||||
end
|
||||
|
||||
if(button.cd) then button.cd:Hide() end
|
||||
if(button.icon) then button.icon:SetTexture(GetSpellTexture(SpellID)) end
|
||||
if(button.overlay) then button.overlay:Hide() end
|
||||
|
||||
if setting.sizeOffset == 0 then
|
||||
button:SetSize(element.size, element.size)
|
||||
else
|
||||
button:SetSize(setting.sizeOffset + element.size, setting.sizeOffset + element.size)
|
||||
end
|
||||
|
||||
button:SetID(position)
|
||||
button.spellID = SpellID
|
||||
|
||||
button:Show()
|
||||
button:ClearAllPoints()
|
||||
button:SetPoint(setting.point, setting.xOffset, setting.yOffset)
|
||||
|
||||
if(element.PostUpdateIcon) then
|
||||
element:PostUpdateIcon(unit, button, nil, position)
|
||||
end
|
||||
|
||||
visible = visible + 1
|
||||
end
|
||||
|
||||
return visible
|
||||
end
|
||||
|
||||
local function filterIcons(element, unit, filter, limit, isDebuff, offset, dontHide)
|
||||
if (not offset) then offset = 0 end
|
||||
local index, visible, hidden = 1, 0, 0
|
||||
while (visible < limit) do
|
||||
local result = updateIcon(element, unit, index, offset, filter, isDebuff, visible)
|
||||
if (not result) then
|
||||
break
|
||||
elseif (result == VISIBLE) then
|
||||
visible = visible + 1
|
||||
elseif (result == HIDDEN) then
|
||||
hidden = hidden + 1
|
||||
end
|
||||
|
||||
index = index + 1
|
||||
end
|
||||
|
||||
if (not dontHide) then
|
||||
for i = visible + offset + 1, #element do
|
||||
element[i]:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
return visible, hidden
|
||||
end
|
||||
|
||||
local function UpdateAuras(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
local element = self.AuraWatch
|
||||
if(element) then
|
||||
if(element.PreUpdate) then element:PreUpdate(unit) end
|
||||
|
||||
local numBuffs = element.numBuffs or 32
|
||||
local numDebuffs = element.numDebuffs or 16
|
||||
local numAuras = element.numTotal or (numBuffs + numDebuffs)
|
||||
|
||||
for i = 1, #element do element[i].isFiltered = false end
|
||||
|
||||
local visibleBuffs, hiddenBuffs = filterIcons(element, unit, element.buffFilter or element.filter or 'HELPFUL', min(numBuffs, numAuras), nil, 0, true)
|
||||
local visibleDebuffs, hiddenDebuffs = filterIcons(element, unit, element.buffFilter or element.filter or 'HARMFUL', min(numDebuffs, numAuras - visibleBuffs), true, visibleBuffs)
|
||||
|
||||
element.visibleDebuffs = visibleDebuffs
|
||||
element.visibleBuffs = visibleBuffs
|
||||
|
||||
element.visibleAuras = visibleBuffs + visibleDebuffs
|
||||
element.allAuras = visibleBuffs + visibleDebuffs + hiddenBuffs + hiddenDebuffs
|
||||
|
||||
onlyShowMissingIcon(element, unit, element.visibleAuras)
|
||||
|
||||
if(element.PostUpdate) then element:PostUpdate(unit) end
|
||||
end
|
||||
end
|
||||
|
||||
local function Update(self, event, unit)
|
||||
if(self.unit ~= unit) then return end
|
||||
|
||||
UpdateAuras(self, event, unit)
|
||||
end
|
||||
|
||||
local function ForceUpdate(element)
|
||||
return Update(element.__owner, 'ForceUpdate', element.__owner.unit)
|
||||
end
|
||||
|
||||
local function SetNewTable(element, table)
|
||||
element.watched = table or {}
|
||||
end
|
||||
|
||||
local function Enable(self)
|
||||
local element = self.AuraWatch
|
||||
if(element) then
|
||||
element.__owner = self
|
||||
element.SetNewTable = SetNewTable
|
||||
element.ForceUpdate = ForceUpdate
|
||||
|
||||
element.watched = element.watched or {}
|
||||
element.createdIcons = element.createdIcons or 0
|
||||
element.anchoredIcons = 0
|
||||
element.size = 8
|
||||
|
||||
self:RegisterEvent('UNIT_AURA', UpdateAuras)
|
||||
element:Show()
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function Disable(self)
|
||||
if(self.AuraWatch) then
|
||||
self:UnregisterEvent('UNIT_AURA', UpdateAuras)
|
||||
|
||||
if(self.AuraWatch) then self.AuraWatch:Hide() end
|
||||
end
|
||||
end
|
||||
|
||||
oUF:AddElement('AuraWatch', Update, Enable, Disable)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user