Ace3 backport

This commit is contained in:
Pinya
2018-07-21 13:29:50 +03:00
parent 332d53e7f6
commit f0eac39bcd
43 changed files with 1071 additions and 846 deletions
+45 -34
View File
@@ -43,9 +43,9 @@ AceAddon.enablequeue = AceAddon.enablequeue or {} -- addons that are initialized
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 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 -- Lua APIs
local tinsert, tconcat, tremove = table.insert, table.concat, table.remove local tinsert, tconcat, tremove, getn = table.insert, table.concat, table.remove, table.getn
local fmt, tostring = string.format, tostring local fmt, gsub, tostring = string.format, string.gsub, tostring
local select, pairs, next, type, unpack = select, pairs, next, type, unpack local pairs, next, type, unpack = pairs, next, type, unpack
local loadstring, assert, error = loadstring, assert, error local loadstring, assert, error = loadstring, assert, error
local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget
@@ -64,14 +64,14 @@ end
local function CreateDispatcher(argCount) local function CreateDispatcher(argCount)
local code = [[ local code = [[
local xpcall, eh = ... local xpcall, eh = xpcall, function(err) return geterrorhandler()(err) end
local method, ARGS local method, ARGS
local function call() return method(ARGS) end local function call() return method(ARGS) end
local function dispatch(func, ...) local function dispatch(func, ...)
method = func method = func
if not method then return end if not method then return end
ARGS = ... ARGS = unpack(arg)
return xpcall(call, eh) return xpcall(call, eh)
end end
@@ -80,7 +80,7 @@ local function CreateDispatcher(argCount)
local ARGS = {} local ARGS = {}
for i = 1, argCount do ARGS[i] = "arg"..i end for i = 1, argCount do ARGS[i] = "arg"..i end
code = code:gsub("ARGS", tconcat(ARGS, ", ")) code = gsub(code,"ARGS", tconcat(ARGS, ", "))
return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler) return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler)
end end
@@ -98,7 +98,7 @@ local function safecall(func, ...)
-- this safecall is used for optional functions like OnInitialize OnEnable etc. When they are not -- this safecall is used for optional functions like OnInitialize OnEnable etc. When they are not
-- present execution should continue without hinderance -- present execution should continue without hinderance
if type(func) == "function" then if type(func) == "function" then
return Dispatchers[select('#', ...)](func, ...) return Dispatchers[getn(arg)](func, unpack(arg))
end end
end end
@@ -110,7 +110,7 @@ local function addontostring( self ) return self.name end
-- Check if the addon is queued for initialization -- Check if the addon is queued for initialization
local function queuedForInitialization(addon) local function queuedForInitialization(addon)
for i = 1, #AceAddon.initializequeue do for i = 1, getn(AceAddon.initializequeue) do
if AceAddon.initializequeue[i] == addon then if AceAddon.initializequeue[i] == addon then
return true return true
end end
@@ -138,16 +138,16 @@ function AceAddon:NewAddon(objectorname, ...)
local i=1 local i=1
if type(objectorname)=="table" then if type(objectorname)=="table" then
object=objectorname object=objectorname
name=... name=arg[1]
i=2 i=2
else else
name=objectorname name=objectorname
end end
if type(name)~="string" then if type(name)~="string" then
error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) error(fmt("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - string expected got '%s'.", type(name)), 2)
end end
if self.addons[name] then if self.addons[name] then
error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon '%s' already exists."):format(name), 2) error(fmt("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon '%s' already exists.", name), 2)
end end
object = object or {} object = object or {}
@@ -166,7 +166,13 @@ function AceAddon:NewAddon(objectorname, ...)
object.orderedModules = {} object.orderedModules = {}
object.defaultModuleLibraries = {} object.defaultModuleLibraries = {}
Embed( object ) -- embed NewModule, GetModule methods Embed( object ) -- embed NewModule, GetModule methods
self:EmbedLibraries(object, select(i,...))
if i == 1 then
self:EmbedLibraries(object, unpack(arg))
else
table.remove(arg, 1)
self:EmbedLibraries(object, unpack(arg))
end
-- add to queue of addons to be initialized upon ADDON_LOADED -- add to queue of addons to be initialized upon ADDON_LOADED
tinsert(self.initializequeue, object) tinsert(self.initializequeue, object)
@@ -183,7 +189,7 @@ end
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") -- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
function AceAddon:GetAddon(name, silent) function AceAddon:GetAddon(name, silent)
if not silent and not self.addons[name] then if not silent and not self.addons[name] then
error(("Usage: GetAddon(name): 'name' - Cannot find an AceAddon '%s'."):format(tostring(name)), 2) error(fmt("Usage: GetAddon(name): 'name' - Cannot find an AceAddon '%s'.", tostring(name)), 2)
end end
return self.addons[name] return self.addons[name]
end end
@@ -197,8 +203,8 @@ end
-- @param addon addon object to embed the libs in -- @param addon addon object to embed the libs in
-- @param lib List of libraries to embed into the addon -- @param lib List of libraries to embed into the addon
function AceAddon:EmbedLibraries(addon, ...) function AceAddon:EmbedLibraries(addon, ...)
for i=1,select("#", ... ) do for i=1,getn(arg) do
local libname = select(i, ...) local libname = arg[i]
self:EmbedLibrary(addon, libname, false, 4) self:EmbedLibrary(addon, libname, false, 4)
end end
end end
@@ -217,13 +223,13 @@ end
function AceAddon:EmbedLibrary(addon, libname, silent, offset) function AceAddon:EmbedLibrary(addon, libname, silent, offset)
local lib = LibStub:GetLibrary(libname, true) local lib = LibStub:GetLibrary(libname, true)
if not lib and not silent then 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) error(fmt("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Cannot find a library instance of %q.", tostring(libname)), offset or 2)
elseif lib and type(lib.Embed) == "function" then elseif lib and type(lib.Embed) == "function" then
lib:Embed(addon) lib:Embed(addon)
tinsert(self.embeds[addon], libname) tinsert(self.embeds[addon], libname)
return true return true
elseif lib then elseif lib then
error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Library '%s' is not Embed capable"):format(libname), offset or 2) error(fmt("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Library '%s' is not Embed capable", libname), offset or 2)
end end
end end
@@ -240,7 +246,7 @@ end
-- MyModule = MyAddon:GetModule("MyModule") -- MyModule = MyAddon:GetModule("MyModule")
function GetModule(self, name, silent) function GetModule(self, name, silent)
if not self.modules[name] and not silent then if not self.modules[name] and not silent then
error(("Usage: GetModule(name, silent): 'name' - Cannot find module '%s'."):format(tostring(name)), 2) error(fmt("Usage: GetModule(name, silent): 'name' - Cannot find module '%s'.", tostring(name)), 2)
end end
return self.modules[name] return self.modules[name]
end end
@@ -264,10 +270,10 @@ local function IsModuleTrue(self) return true end
-- local prototype = { OnEnable = function(self) print("OnEnable called!") end } -- local prototype = { OnEnable = function(self) print("OnEnable called!") end }
-- MyModule = MyAddon:NewModule("MyModule", prototype, "AceEvent-3.0", "AceHook-3.0") -- MyModule = MyAddon:NewModule("MyModule", prototype, "AceEvent-3.0", "AceHook-3.0")
function NewModule(self, name, prototype, ...) 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(name) ~= "string" then error(fmt("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - string expected got '%s'.", 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 type(prototype) ~= "string" and type(prototype) ~= "table" and type(prototype) ~= "nil" then error(fmt("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'prototype' - table (prototype), string (lib) or nil expected got '%s'.", 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 if self.modules[name] then error(fmt("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - Module '%s' already exists.", name), 2) end
-- modules are basically addons. We treat them as such. They will be added to the initializequeue properly as well. -- 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. -- NewModule can only be called after the parent addon is present thus the modules will be initialized after their parent is.
@@ -278,9 +284,9 @@ function NewModule(self, name, prototype, ...)
module.moduleName = name module.moduleName = name
if type(prototype) == "string" then if type(prototype) == "string" then
AceAddon:EmbedLibraries(module, prototype, ...) AceAddon:EmbedLibraries(module, prototype, unpack(arg))
else else
AceAddon:EmbedLibraries(module, ...) AceAddon:EmbedLibraries(module, unpack(arg))
end end
AceAddon:EmbedLibraries(module, unpack(self.defaultModuleLibraries)) AceAddon:EmbedLibraries(module, unpack(self.defaultModuleLibraries))
@@ -399,7 +405,7 @@ function SetDefaultModuleLibraries(self, ...)
if next(self.modules) then if next(self.modules) then
error("Usage: SetDefaultModuleLibraries(...): cannot change the module defaults after a module has been registered.", 2) error("Usage: SetDefaultModuleLibraries(...): cannot change the module defaults after a module has been registered.", 2)
end end
self.defaultModuleLibraries = {...} self.defaultModuleLibraries = arg
end end
--- Set the default state in which new modules are being created. --- Set the default state in which new modules are being created.
@@ -442,7 +448,7 @@ function SetDefaultModulePrototype(self, prototype)
error("Usage: SetDefaultModulePrototype(prototype): cannot change the module defaults after a module has been registered.", 2) error("Usage: SetDefaultModulePrototype(prototype): cannot change the module defaults after a module has been registered.", 2)
end end
if type(prototype) ~= "table" then if type(prototype) ~= "table" then
error(("Usage: SetDefaultModulePrototype(prototype): 'prototype' - table expected got '%s'."):format(type(prototype)), 2) error(fmt("Usage: SetDefaultModulePrototype(prototype): 'prototype' - table expected got '%s'.", type(prototype)), 2)
end end
self.defaultModulePrototype = prototype self.defaultModulePrototype = prototype
end end
@@ -529,7 +535,7 @@ function AceAddon:InitializeAddon(addon)
safecall(addon.OnInitialize, addon) safecall(addon.OnInitialize, addon)
local embeds = self.embeds[addon] local embeds = self.embeds[addon]
for i = 1, #embeds do for i = 1, getn(embeds) do
local lib = LibStub:GetLibrary(embeds[i], true) local lib = LibStub:GetLibrary(embeds[i], true)
if lib then safecall(lib.OnEmbedInitialize, lib, addon) end if lib then safecall(lib.OnEmbedInitialize, lib, addon) end
end end
@@ -560,14 +566,14 @@ function AceAddon:EnableAddon(addon)
-- make sure we're still enabled before continueing -- make sure we're still enabled before continueing
if self.statuses[addon.name] then if self.statuses[addon.name] then
local embeds = self.embeds[addon] local embeds = self.embeds[addon]
for i = 1, #embeds do for i = 1, getn(embeds) do
local lib = LibStub:GetLibrary(embeds[i], true) local lib = LibStub:GetLibrary(embeds[i], true)
if lib then safecall(lib.OnEmbedEnable, lib, addon) end if lib then safecall(lib.OnEmbedEnable, lib, addon) end
end end
-- enable possible modules. -- enable possible modules.
local modules = addon.orderedModules local modules = addon.orderedModules
for i = 1, #modules do for i = 1, getn(modules) do
self:EnableAddon(modules[i]) self:EnableAddon(modules[i])
end end
end end
@@ -595,13 +601,13 @@ function AceAddon:DisableAddon(addon)
-- make sure we're still disabling... -- make sure we're still disabling...
if not self.statuses[addon.name] then if not self.statuses[addon.name] then
local embeds = self.embeds[addon] local embeds = self.embeds[addon]
for i = 1, #embeds do for i = 1, getn(embeds) do
local lib = LibStub:GetLibrary(embeds[i], true) local lib = LibStub:GetLibrary(embeds[i], true)
if lib then safecall(lib.OnEmbedDisable, lib, addon) end if lib then safecall(lib.OnEmbedDisable, lib, addon) end
end end
-- disable possible modules. -- disable possible modules.
local modules = addon.orderedModules local modules = addon.orderedModules
for i = 1, #modules do for i = 1, getn(modules) do
self:DisableAddon(modules[i]) self:DisableAddon(modules[i])
end end
end end
@@ -633,11 +639,12 @@ function AceAddon:IterateEmbedsOnAddon(addon) return pairs(self.embeds[addon]) e
function AceAddon:IterateModulesOfAddon(addon) return pairs(addon.modules) end function AceAddon:IterateModulesOfAddon(addon) return pairs(addon.modules) end
-- Event Handling -- Event Handling
local function onEvent(this, event, arg1) local IsLoggedIn
local function onEvent()
-- 2011-08-17 nevcairiel - ignore the load event of !DebugTools, so a potential startup error isn't swallowed up -- 2011-08-17 nevcairiel - ignore the load event of !DebugTools, so a potential startup error isn't swallowed up
if (event == "ADDON_LOADED" and arg1 ~= "!DebugTools") or event == "PLAYER_LOGIN" then if (event == "ADDON_LOADED" and arg1 ~= "!DebugTools") 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 -- 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 while(getn(AceAddon.initializequeue) > 0) do
local addon = tremove(AceAddon.initializequeue, 1) local addon = tremove(AceAddon.initializequeue, 1)
-- this might be an issue with recursion - TODO: validate -- this might be an issue with recursion - TODO: validate
if event == "ADDON_LOADED" then addon.baseName = arg1 end if event == "ADDON_LOADED" then addon.baseName = arg1 end
@@ -645,8 +652,12 @@ local function onEvent(this, event, arg1)
tinsert(AceAddon.enablequeue, addon) tinsert(AceAddon.enablequeue, addon)
end end
if IsLoggedIn() then if event == "PLAYER_LOGIN" then
while(#AceAddon.enablequeue > 0) do IsLoggedIn = true
end
if IsLoggedIn then
while(getn(AceAddon.enablequeue) > 0) do
local addon = tremove(AceAddon.enablequeue, 1) local addon = tremove(AceAddon.enablequeue, 1)
AceAddon:EnableAddon(addon) AceAddon:EnableAddon(addon)
end end
+9 -9
View File
@@ -26,9 +26,9 @@ local AceComm,oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not AceComm then return end if not AceComm then return end
-- Lua APIs -- Lua APIs
local type, next, pairs, tostring = type, next, pairs, tostring local type, next, pairs, tostring, unpack = type, next, pairs, tostring, unpack
local strsub, strfind = string.sub, string.find local strsub, strfind, strlen = string.sub, string.find, string.len
local tinsert, tconcat = table.insert, table.concat local tinsert, tconcat, tremove = table.insert, table.concat, table.remove
local error, assert = error, assert local error, assert = error, assert
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
@@ -91,8 +91,8 @@ function AceComm:SendCommMessage(prefix, text, distribution, target, prio, callb
end end
local textlen = #text local textlen = strlen(text)
local maxtextlen = 254 - #prefix -- 254 is the max length of prefix + text that can be sent in one message local maxtextlen = 254 - strlen(prefix) -- 254 is the max length of prefix + text that can be sent in one message
local queueName = prefix..distribution..(target or "") local queueName = prefix..distribution..(target or "")
local ctlCallback = nil local ctlCallback = nil
@@ -139,8 +139,8 @@ do
local t = next(compost) local t = next(compost)
if t then if t then
compost[t]=nil 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 for i=getn(t),3,-1 do -- faster than pairs loop. don't even nil out 1/2 since they'll be overwritten
t[i]=nil tremove(t, i)
end end
return t return t
end end
@@ -253,9 +253,9 @@ function AceComm.callbacks:OnUnused(target, prefix)
AceComm.multipart_reassemblers[prefix..MSG_MULTI_LAST] = nil AceComm.multipart_reassemblers[prefix..MSG_MULTI_LAST] = nil
end end
local function OnEvent(this, event, ...) local function OnEvent()
if event == "CHAT_MSG_ADDON" then if event == "CHAT_MSG_ADDON" then
local prefix,message,distribution,sender = ... local prefix,message,distribution,sender = unpack(arg)
local reassemblername = AceComm.multipart_reassemblers[prefix] local reassemblername = AceComm.multipart_reassemblers[prefix]
if reassemblername then if reassemblername then
-- multipart: reassemble -- multipart: reassemble
+14 -13
View File
@@ -64,6 +64,7 @@ ChatThrottleLib.MIN_FPS = 20 -- Reduce output CPS to half (and don't burst) i
local setmetatable = setmetatable local setmetatable = setmetatable
local table_insert = table.insert
local table_remove = table.remove local table_remove = table.remove
local tostring = tostring local tostring = tostring
local GetTime = GetTime local GetTime = GetTime
@@ -121,7 +122,7 @@ ChatThrottleLib.PipeBin = nil -- pre-v19, drastically different
local PipeBin = setmetatable({}, {__mode="k"}) local PipeBin = setmetatable({}, {__mode="k"})
local function DelPipe(pipe) local function DelPipe(pipe)
for i = #pipe, 1, -1 do for i = getn(pipe), 1, -1 do
pipe[i] = nil pipe[i] = nil
end end
pipe.prev = nil pipe.prev = nil
@@ -209,12 +210,12 @@ function ChatThrottleLib:Init()
-- Use secure hooks as of v16. Old regular hook support yanked out in v21. -- Use secure hooks as of v16. Old regular hook support yanked out in v21.
self.securelyHooked = true self.securelyHooked = true
--SendChatMessage --SendChatMessage
hooksecurefunc("SendChatMessage", function(...) hooksecurefunc("SendChatMessage", function(text, chattype, language, destination)
return ChatThrottleLib.Hook_SendChatMessage(...) return ChatThrottleLib.Hook_SendChatMessage(text, chattype, language, destination)
end) end)
--SendAddonMessage --SendAddonMessage
hooksecurefunc("SendAddonMessage", function(...) hooksecurefunc("SendAddonMessage", function(prefix, text, chattype, destination)
return ChatThrottleLib.Hook_SendAddonMessage(...) return ChatThrottleLib.Hook_SendAddonMessage(prefix, text, chattype, destination)
end) end)
end end
self.nBypass = 0 self.nBypass = 0
@@ -240,8 +241,8 @@ function ChatThrottleLib.Hook_SendAddonMessage(prefix, text, chattype, destinati
return return
end end
local self = ChatThrottleLib local self = ChatThrottleLib
local size = tostring(text or ""):len() + tostring(prefix or ""):len(); local size = strlen(tostring(text or "")) + strlen(tostring(prefix or ""));
size = size + tostring(destination or ""):len() + self.MSG_OVERHEAD size = size + strlen(tostring(destination or "")) + self.MSG_OVERHEAD
self.avail = self.avail - size self.avail = self.avail - size
self.nBypass = self.nBypass + size -- just a statistic self.nBypass = self.nBypass + size -- just a statistic
end end
@@ -307,7 +308,7 @@ function ChatThrottleLib:Despool(Prio)
end end
function ChatThrottleLib.OnEvent(this,event) function ChatThrottleLib.OnEvent()
-- v11: We know that the rate limiter is touchy after login. Assume that it's touchy after zoning, too. -- v11: We know that the rate limiter is touchy after login. Assume that it's touchy after zoning, too.
local self = ChatThrottleLib local self = ChatThrottleLib
if event == "PLAYER_ENTERING_WORLD" then if event == "PLAYER_ENTERING_WORLD" then
@@ -317,10 +318,10 @@ function ChatThrottleLib.OnEvent(this,event)
end end
function ChatThrottleLib.OnUpdate(this,delay) function ChatThrottleLib.OnUpdate()
local self = ChatThrottleLib local self = ChatThrottleLib
self.OnUpdateDelay = self.OnUpdateDelay + delay self.OnUpdateDelay = self.OnUpdateDelay + arg1
if self.OnUpdateDelay < 0.08 then if self.OnUpdateDelay < 0.08 then
return return
end end
@@ -386,7 +387,7 @@ function ChatThrottleLib:Enqueue(prioname, pipename, msg)
Prio.Ring:Add(pipe) Prio.Ring:Add(pipe)
end end
pipe[#pipe + 1] = msg table_insert(pipe, msg)
self.bQueueing = true self.bQueueing = true
end end
@@ -401,7 +402,7 @@ function ChatThrottleLib:SendChatMessage(prio, prefix, text, chattype, languag
error('ChatThrottleLib:ChatMessage(): callbackFn: expected function, got '..type(callbackFn), 2) error('ChatThrottleLib:ChatMessage(): callbackFn: expected function, got '..type(callbackFn), 2)
end end
local nSize = text:len() local nSize = strlen(text)
if nSize>255 then if nSize>255 then
error("ChatThrottleLib:SendChatMessage(): message length cannot exceed 255 bytes", 2) error("ChatThrottleLib:SendChatMessage(): message length cannot exceed 255 bytes", 2)
@@ -446,7 +447,7 @@ function ChatThrottleLib:SendAddonMessage(prio, prefix, text, chattype, target,
error('ChatThrottleLib:SendAddonMessage(): callbackFn: expected function, got '..type(callbackFn), 2) error('ChatThrottleLib:SendAddonMessage(): callbackFn: expected function, got '..type(callbackFn), 2)
end end
local nSize = prefix:len() + 1 + text:len(); local nSize = strlen(prefix) + 1 + strlen(text);
if nSize>255 then if nSize>255 then
error("ChatThrottleLib:SendAddonMessage(): prefix + message length cannot exceed 254 bytes", 2) error("ChatThrottleLib:SendAddonMessage(): prefix + message length cannot exceed 254 bytes", 2)
@@ -21,9 +21,9 @@ AceConsole.commands = AceConsole.commands or {} -- table containing commands reg
AceConsole.weakcommands = AceConsole.weakcommands or {} -- table containing self, command => func references for weak commands that don't persist through enable/disable AceConsole.weakcommands = AceConsole.weakcommands or {} -- table containing self, command => func references for weak commands that don't persist through enable/disable
-- Lua APIs -- Lua APIs
local tconcat, tostring, select = table.concat, tostring, select local tconcat, getn, tostring = table.concat, table.getn, tostring
local type, pairs, error = type, pairs, error local type, pairs, error = type, pairs, error
local format, strfind, strsub = string.format, string.find, string.sub local format, strfind, strsub, upper, lower = string.format, string.find, string.sub, string.upper, string.lower
local max = math.max local max = math.max
-- WoW APIs -- WoW APIs
@@ -40,9 +40,9 @@ local function Print(self,frame,...)
n=n+1 n=n+1
tmp[n] = "|cff33ff99"..tostring( self ).."|r:" tmp[n] = "|cff33ff99"..tostring( self ).."|r:"
end end
for i=1, select("#", ...) do for i=1, getn(arg) do
n=n+1 n=n+1
tmp[n] = tostring(select(i, ...)) tmp[n] = tostring(arg[i])
end end
frame:AddMessage( tconcat(tmp," ",1,n) ) frame:AddMessage( tconcat(tmp," ",1,n) )
end end
@@ -52,11 +52,11 @@ end
-- @param chatframe Custom ChatFrame to print to (or any frame with an .AddMessage function) -- @param chatframe Custom ChatFrame to print to (or any frame with an .AddMessage function)
-- @param ... List of any values to be printed -- @param ... List of any values to be printed
function AceConsole:Print(...) function AceConsole:Print(...)
local frame = ... local frame = arg[1]
if type(frame) == "table" and frame.AddMessage then -- Is first argument something with an .AddMessage member? if type(frame) == "table" and frame.AddMessage then -- Is first argument something with an .AddMessage member?
return Print(self, frame, select(2,...)) return Print(self, unpack(arg))
else else
return Print(self, DEFAULT_CHAT_FRAME, ...) return Print(self, DEFAULT_CHAT_FRAME, unpack(arg))
end end
end end
@@ -67,11 +67,12 @@ end
-- @param format Format string - same syntax as standard Lua format() -- @param format Format string - same syntax as standard Lua format()
-- @param ... Arguments to the format string -- @param ... Arguments to the format string
function AceConsole:Printf(...) function AceConsole:Printf(...)
local frame = ... local frame = arg[1]
if type(frame) == "table" and frame.AddMessage then -- Is first argument something with an .AddMessage member? if type(frame) == "table" and frame.AddMessage then -- Is first argument something with an .AddMessage member?
return Print(self, frame, format(select(2,...))) tremove(arg, 1)
return Print(self, frame, format(unpack(arg)))
else else
return Print(self, DEFAULT_CHAT_FRAME, format(...)) return Print(self, DEFAULT_CHAT_FRAME, format(unpack(arg)))
end end
end end
@@ -87,7 +88,7 @@ function AceConsole:RegisterChatCommand( command, func, persist )
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 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() local name = "ACECONSOLE_"..upper(command)
if type( func ) == "string" then if type( func ) == "string" then
SlashCmdList[name] = function(input, editBox) SlashCmdList[name] = function(input, editBox)
@@ -96,7 +97,7 @@ function AceConsole:RegisterChatCommand( command, func, persist )
else else
SlashCmdList[name] = func SlashCmdList[name] = func
end end
_G["SLASH_"..name.."1"] = "/"..command:lower() _G["SLASH_"..name.."1"] = "/"..lower(command)
AceConsole.commands[command] = name AceConsole.commands[command] = name
-- non-persisting commands are registered for enabling disabling -- non-persisting commands are registered for enabling disabling
if not persist then if not persist then
@@ -113,7 +114,7 @@ function AceConsole:UnregisterChatCommand( command )
if name then if name then
SlashCmdList[name] = nil SlashCmdList[name] = nil
_G["SLASH_" .. name .. "1"] = nil _G["SLASH_" .. name .. "1"] = nil
hash_SlashCmdList["/" .. command:upper()] = nil hash_SlashCmdList["/" .. upper(command)] = nil
AceConsole.commands[command] = nil AceConsole.commands[command] = nil
end end
end end
@@ -125,11 +126,11 @@ function AceConsole:IterateChatCommands() return pairs(AceConsole.commands) end
local function nils(n, ...) local function nils(n, ...)
if n>1 then if n>1 then
return nil, nils(n-1, ...) return nil, nils(n-1, unpack(arg))
elseif n==1 then elseif n==1 then
return nil, ... return nil, unpack(arg)
else else
return ... return unpack(arg)
end end
end end
+10 -4
View File
@@ -49,6 +49,7 @@ if not AceDB then return end -- No upgrade needed
-- Lua APIs -- Lua APIs
local type, pairs, next, error = type, pairs, next, error local type, pairs, next, error = type, pairs, next, error
local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget
local format = string.format
-- WoW APIs -- WoW APIs
local _G = _G local _G = _G
@@ -74,6 +75,7 @@ local function copyTable(src, dest)
if type(dest) ~= "table" then dest = {} end if type(dest) ~= "table" then dest = {} end
if type(src) == "table" then if type(src) == "table" then
for k,v in pairs(src) do for k,v in pairs(src) do
local v = v
if type(v) == "table" then if type(v) == "table" then
-- try to index the key first so that the metatable creates the defaults, if set, and use that table -- try to index the key first so that the metatable creates the defaults, if set, and use that table
v = copyTable(v, dest[k]) v = copyTable(v, dest[k])
@@ -93,6 +95,7 @@ local function copyDefaults(dest, src)
-- this happens if some value in the SV overwrites our default value with a non-table -- this happens if some value in the SV overwrites our default value with a non-table
--if type(dest) ~= "table" then return end --if type(dest) ~= "table" then return end
for k, v in pairs(src) do for k, v in pairs(src) do
local v = v
if k == "*" or k == "**" then if k == "*" or k == "**" then
if type(v) == "table" then if type(v) == "table" then
-- This is a metatable used for table defaults -- This is a metatable used for table defaults
@@ -140,10 +143,12 @@ local function removeDefaults(db, defaults, blocker)
setmetatable(db, nil) setmetatable(db, nil)
-- loop through the defaults and remove their content -- loop through the defaults and remove their content
for k,v in pairs(defaults) do for k,v in pairs(defaults) do
local v = v
if k == "*" or k == "**" then if k == "*" or k == "**" then
if type(v) == "table" then if type(v) == "table" then
-- Loop through all the actual k,v pairs and remove -- Loop through all the actual k,v pairs and remove
for key, value in pairs(db) do for key, value in pairs(db) do
local value = value
if type(value) == "table" then if type(value) == "table" then
-- if the key was not explicitly specified in the defaults table, just strip everything from * and ** tables -- 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 if defaults[key] == nil and (not blocker or blocker[key] == nil) then
@@ -242,7 +247,7 @@ local function validateDefaults(defaults, keyTbl, offset)
offset = offset or 0 offset = offset or 0
for k in pairs(defaults) do for k in pairs(defaults) do
if not keyTbl[k] or k == "profiles" then if not keyTbl[k] or k == "profiles" then
error(("Usage: AceDBObject:RegisterDefaults(defaults): '%s' is not a valid datatype."):format(k), 3 + offset) error(format("Usage: AceDBObject:RegisterDefaults(defaults): '%s' is not a valid datatype.", k), 3 + offset)
end end
end end
end end
@@ -260,9 +265,10 @@ local charKey = UnitName("player") .. " - " .. realmKey
local _, classKey = UnitClass("player") local _, classKey = UnitClass("player")
local _, raceKey = UnitRace("player") local _, raceKey = UnitRace("player")
local factionKey = UnitFactionGroup("player") local factionKey = UnitFactionGroup("player")
factionKey = factionKey or "Others"
local factionrealmKey = factionKey .. " - " .. realmKey local factionrealmKey = factionKey .. " - " .. realmKey
local factionrealmregionKey = factionrealmKey .. " - " .. string.sub(GetCVar("realmList"), 1, 2):upper() local factionrealmregionKey = factionrealmKey .. " - " .. string.upper(string.sub(GetCVar("realmList"), 1, 2))
local localeKey = GetLocale():lower() local localeKey = string.lower(GetLocale())
-- Actual database initialization function -- Actual database initialization function
local function initdb(sv, defaults, defaultProfile, olddb, parent) local function initdb(sv, defaults, defaultProfile, olddb, parent)
@@ -353,7 +359,7 @@ end
-- handle PLAYER_LOGOUT -- handle PLAYER_LOGOUT
-- strip all defaults from all databases -- strip all defaults from all databases
-- and cleans up empty sections -- and cleans up empty sections
local function logoutHandler(frame, event) local function logoutHandler()
if event == "PLAYER_LOGOUT" then if event == "PLAYER_LOGOUT" then
for db in pairs(AceDB.db_registry) do for db in pairs(AceDB.db_registry) do
db.callbacks:Fire("OnDatabaseShutdown", db) db.callbacks:Fire("OnDatabaseShutdown", db)
@@ -116,8 +116,8 @@ end
-- Script to fire blizzard events into the event listeners -- Script to fire blizzard events into the event listeners
local events = AceEvent.events local events = AceEvent.events
AceEvent.frame:SetScript("OnEvent", function(this, event, ...) AceEvent.frame:SetScript("OnEvent", function()
events:Fire(event, ...) events:Fire(event)
end) end)
--- Finally: upgrade our old embeds --- Finally: upgrade our old embeds
+9 -8
View File
@@ -31,11 +31,12 @@ local scripts = AceHook.scripts
local onceSecure = AceHook.onceSecure local onceSecure = AceHook.onceSecure
-- Lua APIs -- Lua APIs
local pairs, next, type = pairs, next, type local pairs, next, type, unpack = pairs, next, type, unpack
local format = string.format local format = string.format
local assert, error = assert, error local assert, error = assert, error
-- WoW APIs -- WoW APIs
local HookScript = HookScript
local issecurevariable, hooksecurefunc = issecurevariable, hooksecurefunc local issecurevariable, hooksecurefunc = issecurevariable, hooksecurefunc
local _G = _G local _G = _G
@@ -87,12 +88,12 @@ function createHook(self, handler, orig, secure, failsafe)
uid = function(...) uid = function(...)
if actives[uid] then if actives[uid] then
if method then if method then
self[handler](self, ...) self[handler](self, unpack(arg))
else else
handler(...) handler(unpack(arg))
end end
end end
return orig(...) return orig(unpack(arg))
end end
-- /failsafe hook -- /failsafe hook
else else
@@ -100,12 +101,12 @@ function createHook(self, handler, orig, secure, failsafe)
uid = function(...) uid = function(...)
if actives[uid] then if actives[uid] then
if method then if method then
return self[handler](self, ...) return self[handler](self, unpack(arg))
else else
return handler(...) return handler(unpack(arg))
end end
elseif not secure then -- backup on non secure elseif not secure then -- backup on non secure
return orig(...) return orig(unpack(arg))
end end
end end
-- /hook -- /hook
@@ -226,7 +227,7 @@ function hook(self, obj, method, handler, script, secure, raw, forceSecure, usag
if not secure then if not secure then
obj:SetScript(method, uid) obj:SetScript(method, uid)
else else
obj:HookScript2(method, uid) HookScript(obj, method, uid)
end end
else else
if not secure then if not secure then
@@ -20,8 +20,8 @@ if not AceSerializer then return end
local strbyte, strchar, gsub, gmatch, format = string.byte, string.char, string.gsub, string.gmatch, string.format local strbyte, strchar, gsub, gmatch, format = string.byte, string.char, string.gsub, string.gmatch, string.format
local assert, error, pcall = assert, error, pcall local assert, error, pcall = assert, error, pcall
local type, tostring, tonumber = type, tostring, tonumber local type, tostring, tonumber = type, tostring, tonumber
local pairs, select, frexp = pairs, select, math.frexp local pairs, frexp = pairs, math.frexp
local tconcat = table.concat local tconcat, getn = table.concat, table.getn
-- quick copies of string representations of wonky numbers -- quick copies of string representations of wonky numbers
local serNaN = tostring(0/0) local serNaN = tostring(0/0)
@@ -116,8 +116,8 @@ local serializeTbl = { "^1" } -- "^1" = Hi, I'm data serialized by AceSerializer
function AceSerializer:Serialize(...) function AceSerializer:Serialize(...)
local nres = 1 local nres = 1
for i=1,select("#", ...) do for i=1,getn(arg) do
local v = select(i, ...) local v = arg[i]
nres = SerializeValue(v, serializeTbl, nres) nres = SerializeValue(v, serializeTbl, nres)
end end
+19 -18
View File
@@ -49,9 +49,10 @@ AceTimer.frame = AceTimer.frame or CreateFrame("Frame", "AceTimer30Frame")
-- Lua APIs -- Lua APIs
local assert, error, loadstring = assert, error, loadstring local assert, error, loadstring = assert, error, loadstring
local setmetatable, rawset, rawget = setmetatable, rawset, rawget local setmetatable, rawset, rawget = setmetatable, rawset, rawget
local select, pairs, type, next, tostring = select, pairs, type, next, tostring local pairs, type, next, tostring, unpack = pairs, type, next, tostring, unpack
local floor, max, min = math.floor, math.max, math.min local gsub = string.gsub
local tconcat = table.concat local floor, max, min, fmod = math.floor, math.max, math.min, math.fmod
local tconcat, getn = table.concat, table.getn
-- WoW APIs -- WoW APIs
local GetTime = GetTime local GetTime = GetTime
@@ -93,14 +94,14 @@ end
local function CreateDispatcher(argCount) local function CreateDispatcher(argCount)
local code = [[ local code = [[
local xpcall, eh = ... -- our arguments are received as unnamed values in "..." since we don't have a proper function declaration local xpcall, eh = xpcall, function(err) return geterrorhandler()(err) end -- our arguments are received as unnamed values in "..." since we don't have a proper function declaration
local method, ARGS local method, ARGS
local function call() return method(ARGS) end local function call() return method(ARGS) end
local function dispatch(func, ...) local function dispatch(func, ...)
method = func method = func
if not method then return end if not method then return end
ARGS = ... ARGS = unpack(arg)
return xpcall(call, eh) return xpcall(call, eh)
end end
@@ -109,7 +110,7 @@ local function CreateDispatcher(argCount)
local ARGS = {} local ARGS = {}
for i = 1, argCount do ARGS[i] = "arg"..i end for i = 1, argCount do ARGS[i] = "arg"..i end
code = code:gsub("ARGS", tconcat(ARGS, ", ")) code = gsub(code, "ARGS", tconcat(ARGS, ", "))
return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler) return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler)
end end
@@ -125,7 +126,7 @@ Dispatchers[0] = function(func)
end end
local function safecall(func, ...) local function safecall(func, ...)
return Dispatchers[select('#', ...)](func, ...) return Dispatchers[getn(arg)](func, unpack(arg))
end end
local lastint = floor(GetTime() * HZ) local lastint = floor(GetTime() * HZ)
@@ -147,7 +148,7 @@ local function OnUpdate()
-- Pass through each bucket at most once -- Pass through each bucket at most once
-- Happens on e.g. instance loads, but COULD happen on high local load situations also -- Happens on e.g. instance loads, but COULD happen on high local load situations also
for curint = (max(lastint, nowint - BUCKETS) + 1), nowint do -- loop until we catch up with "now", usually only 1 iteration for curint = (max(lastint, nowint - BUCKETS) + 1), nowint do -- loop until we catch up with "now", usually only 1 iteration
local curbucket = (curint % BUCKETS)+1 local curbucket = (fmod(curint, BUCKETS))+1
-- Yank the list of timers out of the bucket and empty it. This allows reinsertion in the currently-processed bucket from callbacks. -- Yank the list of timers out of the bucket and empty it. This allows reinsertion in the currently-processed bucket from callbacks.
local nexttimer = hash[curbucket] local nexttimer = hash[curbucket]
hash[curbucket] = false -- false rather than nil to prevent the array from becoming a hash hash[curbucket] = false -- false rather than nil to prevent the array from becoming a hash
@@ -184,7 +185,7 @@ local function OnUpdate()
timer.when = newtime timer.when = newtime
-- add next timer execution to the correct bucket -- add next timer execution to the correct bucket
local bucket = (floor(newtime * HZ) % BUCKETS) + 1 local bucket = (fmod(floor(newtime * HZ), BUCKETS)) + 1
timer.next = hash[bucket] timer.next = hash[bucket]
hash[bucket] = timer hash[bucket] = timer
end end
@@ -208,7 +209,7 @@ end
-- repeating(boolean) - repeating timer, or oneshot -- repeating(boolean) - repeating timer, or oneshot
-- --
-- returns the handle of the timer for later processing (canceling etc) -- returns the handle of the timer for later processing (canceling etc)
local function Reg(self, callback, delay, arg, repeating) local function Reg(self, callback, delay, argument, repeating)
if type(callback) ~= "string" and type(callback) ~= "function" then if type(callback) ~= "string" and type(callback) ~= "function" then
local error_origin = repeating and "ScheduleRepeatingTimer" or "ScheduleTimer" local error_origin = repeating and "ScheduleRepeatingTimer" or "ScheduleTimer"
error(MAJOR..": " .. error_origin .. "(callback, delay, arg): 'callback' - function or method name expected.", 3) error(MAJOR..": " .. error_origin .. "(callback, delay, arg): 'callback' - function or method name expected.", 3)
@@ -237,10 +238,10 @@ local function Reg(self, callback, delay, arg, repeating)
timer.object = self timer.object = self
timer.callback = callback timer.callback = callback
timer.delay = (repeating and delay) timer.delay = (repeating and delay)
timer.arg = arg timer.arg = argument
timer.when = now + delay timer.when = now + delay
local bucket = (floor((now+delay)*HZ) % BUCKETS) + 1 local bucket = (fmod(floor((now+delay)*HZ), BUCKETS)) + 1
timer.next = hash[bucket] timer.next = hash[bucket]
hash[bucket] = timer hash[bucket] = timer
@@ -273,8 +274,8 @@ end
-- function MyAddon:TimerFeedback() -- function MyAddon:TimerFeedback()
-- print("5 seconds passed") -- print("5 seconds passed")
-- end -- end
function AceTimer:ScheduleTimer(callback, delay, arg) function AceTimer:ScheduleTimer(callback, delay, argument)
return Reg(self, callback, delay, arg) return Reg(self, callback, delay, argument)
end end
--- Schedule a repeating timer. --- Schedule a repeating timer.
@@ -292,14 +293,14 @@ end
-- --
-- function MyAddon:TimerFeedback() -- function MyAddon:TimerFeedback()
-- self.timerCount = self.timerCount + 1 -- self.timerCount = self.timerCount + 1
-- print(("%d seconds passed"):format(5 * self.timerCount)) -- print(format("%d seconds passed", 5 * self.timerCount))
-- -- run 30 seconds in total -- -- run 30 seconds in total
-- if self.timerCount == 6 then -- if self.timerCount == 6 then
-- self:CancelTimer(self.testTimer) -- self:CancelTimer(self.testTimer)
-- end -- end
-- end -- end
function AceTimer:ScheduleRepeatingTimer(callback, delay, arg) function AceTimer:ScheduleRepeatingTimer(callback, delay, argument)
return Reg(self, callback, delay, arg, true) return Reg(self, callback, delay, argument, true)
end end
--- Cancels a timer with the given handle, registered by the same addon object as used for `:ScheduleTimer` --- Cancels a timer with the given handle, registered by the same addon object as used for `:ScheduleTimer`
@@ -384,7 +385,7 @@ end
local lastCleaned = nil local lastCleaned = nil
local function OnEvent(this, event) local function OnEvent()
if event~="PLAYER_REGEN_ENABLED" then if event~="PLAYER_REGEN_ENABLED" then
return return
end end
@@ -1,4 +1,4 @@
--[[ $Id: CallbackHandler-1.0.lua 18 2014-10-16 02:52:20Z mikk $ ]] --[[ $Id: CallbackHandler-1.0.lua 1131 2015-06-04 07:29:24Z nevcairiel $ ]]
local MAJOR, MINOR = "CallbackHandler-1.0", 6 local MAJOR, MINOR = "CallbackHandler-1.0", 6
local CallbackHandler = LibStub:NewLibrary(MAJOR, MINOR) local CallbackHandler = LibStub:NewLibrary(MAJOR, MINOR)
@@ -7,10 +7,10 @@ if not CallbackHandler then return end -- No upgrade needed
local meta = {__index = function(tbl, key) tbl[key] = {} return tbl[key] end} local meta = {__index = function(tbl, key) tbl[key] = {} return tbl[key] end}
-- Lua APIs -- Lua APIs
local tconcat = table.concat local tconcat, getn = table.concat, table.getn
local assert, error, loadstring = assert, error, loadstring local assert, error, loadstring = assert, error, loadstring
local setmetatable, rawset, rawget = setmetatable, rawset, rawget local setmetatable, rawset, rawget = setmetatable, rawset, rawget
local next, select, pairs, type, tostring = next, select, pairs, type, tostring local next, pairs, type, tostring = next, pairs, type, tostring
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
-- List them here for Mikk's FindGlobals script -- List them here for Mikk's FindGlobals script
@@ -24,7 +24,7 @@ end
local function CreateDispatcher(argCount) local function CreateDispatcher(argCount)
local code = [[ local code = [[
local next, xpcall, eh = ... local next, xpcall, eh = next, xpcall, function(err) return geterrorhandler()(err) end
local method, ARGS local method, ARGS
local function call() method(ARGS) end local function call() method(ARGS) end
@@ -34,7 +34,7 @@ local function CreateDispatcher(argCount)
index, method = next(handlers) index, method = next(handlers)
if not method then return end if not method then return end
local OLD_ARGS = ARGS local OLD_ARGS = ARGS
ARGS = ... ARGS = unpack(arg)
repeat repeat
xpcall(call, eh) xpcall(call, eh)
index, method = next(handlers, index) index, method = next(handlers, index)
@@ -47,7 +47,7 @@ local function CreateDispatcher(argCount)
local ARGS, OLD_ARGS = {}, {} local ARGS, OLD_ARGS = {}, {}
for i = 1, argCount do ARGS[i], OLD_ARGS[i] = "arg"..i, "old_arg"..i end for i = 1, argCount do ARGS[i], OLD_ARGS[i] = "arg"..i, "old_arg"..i end
code = code:gsub("OLD_ARGS", tconcat(OLD_ARGS, ", ")):gsub("ARGS", tconcat(ARGS, ", ")) code = gsub(gsub(code, "OLD_ARGS", tconcat(OLD_ARGS, ", ")), "ARGS", tconcat(ARGS, ", "))
return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(next, xpcall, errorhandler) return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(next, xpcall, errorhandler)
end end
@@ -87,7 +87,7 @@ function CallbackHandler:New(target, RegisterName, UnregisterName, UnregisterAll
local oldrecurse = registry.recurse local oldrecurse = registry.recurse
registry.recurse = oldrecurse + 1 registry.recurse = oldrecurse + 1
Dispatchers[select('#', ...) + 1](events[eventname], eventname, ...) Dispatchers[getn(arg) + 1](events[eventname], eventname, unpack(arg))
registry.recurse = oldrecurse registry.recurse = oldrecurse
@@ -138,11 +138,11 @@ function CallbackHandler:New(target, RegisterName, UnregisterName, UnregisterAll
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): 'methodname' - method '"..tostring(method).."' not found on self.", 2) error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): 'methodname' - method '"..tostring(method).."' not found on self.", 2)
end end
if select("#",...)>=1 then -- this is not the same as testing for arg==nil! if getn(arg)>=1 then -- this is not the same as testing for arg==nil!
local arg=select(1,...) local a1=arg[1]
regfunc = function(...) self[method](self,arg,...) end regfunc = function(...) self[method](self,a1,unpack(arg)) end
else else
regfunc = function(...) self[method](self,...) end regfunc = function(...) self[method](self,unpack(arg)) end
end end
else else
-- function ref with self=object or self="addonId" or self=thread -- function ref with self=object or self="addonId" or self=thread
@@ -150,9 +150,9 @@ function CallbackHandler:New(target, RegisterName, UnregisterName, UnregisterAll
error("Usage: "..RegisterName.."(self or \"addonId\", eventname, method): 'self or addonId': table or string or thread expected.", 2) error("Usage: "..RegisterName.."(self or \"addonId\", eventname, method): 'self or addonId': table or string or thread expected.", 2)
end end
if select("#",...)>=1 then -- this is not the same as testing for arg==nil! if getn(arg)>=1 then -- this is not the same as testing for arg==nil!
local arg=select(1,...) local a1=arg[1]
regfunc = function(...) method(arg,...) end regfunc = function(...) method(arg,unpack(arg)) end
else else
regfunc = method regfunc = method
end end
@@ -198,16 +198,16 @@ function CallbackHandler:New(target, RegisterName, UnregisterName, UnregisterAll
-- OPTIONAL: Unregister all callbacks for given selfs/addonIds -- OPTIONAL: Unregister all callbacks for given selfs/addonIds
if UnregisterAllName then if UnregisterAllName then
target[UnregisterAllName] = function(...) target[UnregisterAllName] = function(...)
if select("#",...)<1 then if getn(arg)<1 then
error("Usage: "..UnregisterAllName.."([whatFor]): missing 'self' or \"addonId\" to unregister events for.", 2) error("Usage: "..UnregisterAllName.."([whatFor]): missing 'self' or \"addonId\" to unregister events for.", 2)
end end
if select("#",...)==1 and ...==target then if getn(arg)==1 and arg[1]==target then
error("Usage: "..UnregisterAllName.."([whatFor]): supply a meaningful 'self' or \"addonId\"", 2) error("Usage: "..UnregisterAllName.."([whatFor]): supply a meaningful 'self' or \"addonId\"", 2)
end end
for i=1,select("#",...) do for i=1,getn(arg) do
local self = select(i,...) local self = arg[i]
if registry.insertQueue then if registry.insertQueue then
for eventname, callbacks in pairs(registry.insertQueue) do for eventname, callbacks in pairs(registry.insertQueue) do
if callbacks[self] then if callbacks[self] then
+8 -26
View File
@@ -1,25 +1,19 @@
-- $Id: LibStub.lua 103 2014-10-16 03:02:50Z mikk $ -- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/addons/libstub/ for more info -- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
-- 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_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
local _G = _G
local find, format = string.find, string.format
local LibStub = _G[LIBSTUB_MAJOR] local LibStub = _G[LIBSTUB_MAJOR]
-- Check to see is this version of the stub is obsolete
if not LibStub or LibStub.minor < LIBSTUB_MINOR then if not LibStub or LibStub.minor < LIBSTUB_MINOR then
LibStub = LibStub or {libs = {}, minors = {} } LibStub = LibStub or {libs = {}, minors = {} }
_G[LIBSTUB_MAJOR] = LibStub _G[LIBSTUB_MAJOR] = LibStub
LibStub.minor = LIBSTUB_MINOR LibStub.minor = LIBSTUB_MINOR
-- LibStub:NewLibrary(major, minor)
-- major (string) - the major version of the library
-- minor (string or number ) - the minor version of the library
--
-- returns nil if a newer or same version of the lib is already present
-- returns empty library object or old library object if upgrade is needed
function LibStub:NewLibrary(major, minor) function LibStub:NewLibrary(major, minor)
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)") 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 _, _, num = find(minor, "(%d+)")
minor = assert(tonumber(num), "Minor version must either be a number or contain a number.")
local oldminor = self.minors[major] local oldminor = self.minors[major]
if oldminor and oldminor >= minor then return nil end if oldminor and oldminor >= minor then return nil end
@@ -27,25 +21,13 @@ if not LibStub or LibStub.minor < LIBSTUB_MINOR then
return self.libs[major], oldminor return self.libs[major], oldminor
end end
-- LibStub:GetLibrary(major, [silent])
-- major (string) - the major version of the library
-- silent (boolean) - if true, library is optional, silently return nil if its not found
--
-- throws an error if the library can not be found (except silent is set)
-- returns the library object if found
function LibStub:GetLibrary(major, silent) function LibStub:GetLibrary(major, silent)
if not self.libs[major] and not silent then if not self.libs[major] and not silent then
error(("Cannot find a library instance of %q."):format(tostring(major)), 2) error(format("Cannot find a library instance of %q.", tostring(major)), 2)
end end
return self.libs[major], self.minors[major] return self.libs[major], self.minors[major]
end end
-- LibStub:IterateLibraries() function LibStub:IterateLibraries() return pairs(self.libs) end
--
-- Returns an iterator for the currently registered libraries
function LibStub:IterateLibraries()
return pairs(self.libs)
end
setmetatable(LibStub, { __call = LibStub.GetLibrary }) setmetatable(LibStub, { __call = LibStub.GetLibrary })
end end
@@ -12,10 +12,10 @@ Very light wrapper library that combines all the AceConfig subcomponents into on
]] ]]
local cfgreg = LibStub("AceConfigRegistry-3.0-ElvUI") local cfgreg = LibStub("AceConfigRegistry-3.0")
local cfgcmd = LibStub("AceConfigCmd-3.0-ElvUI") local cfgcmd = LibStub("AceConfigCmd-3.0")
local MAJOR, MINOR = "AceConfig-3.0-ElvUI", 3 local MAJOR, MINOR = "AceConfig-3.0", 3
local AceConfig = LibStub:NewLibrary(MAJOR, MINOR) local AceConfig = LibStub:NewLibrary(MAJOR, MINOR)
if not AceConfig then return end if not AceConfig then return end
@@ -14,9 +14,9 @@ REQUIRES: AceConsole-3.0 for command registration (loaded on demand)
-- TODO: plugin args -- TODO: plugin args
local cfgreg = LibStub("AceConfigRegistry-3.0-ElvUI") local cfgreg = LibStub("AceConfigRegistry-3.0")
local MAJOR, MINOR = "AceConfigCmd-3.0-ElvUI", 14 local MAJOR, MINOR = "AceConfigCmd-3.0", 14
local AceConfigCmd = LibStub:NewLibrary(MAJOR, MINOR) local AceConfigCmd = LibStub:NewLibrary(MAJOR, MINOR)
if not AceConfigCmd then return end if not AceConfigCmd then return end
@@ -29,8 +29,10 @@ local AceConsoleName = "AceConsole-3.0"
-- Lua APIs -- Lua APIs
local strsub, strsplit, strlower, strmatch, strtrim = string.sub, string.split, string.lower, string.match, string.trim local strsub, strsplit, strlower, strmatch, strtrim = string.sub, string.split, string.lower, string.match, string.trim
local strgsub, strupper, strfind, strlen, strbyte, strgmatch = string.gsub, string.upper, string.find, string.len, string.byte, string.gmatch
local format, tonumber, tostring = string.format, tonumber, tostring local format, tonumber, tostring = string.format, tonumber, tostring
local tsort, tinsert = table.sort, table.insert local tsort, tinsert, getn = table.sort, table.insert, table.getn
local fmod = math.fmod
local select, pairs, next, type = select, pairs, next, type local select, pairs, next, type = select, pairs, next, type
local error, assert = error, assert local error, assert = error, assert
@@ -64,9 +66,9 @@ local funcmsg = "expected function or member name"
-- pickfirstset() - picks the first non-nil value and returns it -- pickfirstset() - picks the first non-nil value and returns it
local function pickfirstset(...) local function pickfirstset(...)
for i=1,select("#",...) do for i=1,getn(arg) do
if select(i,...)~=nil then if arg[i]~=nil then
return select(i,...) return arg[i]
end end
end end
end end
@@ -101,12 +103,12 @@ local function callmethod(info, inputpos, tab, methodtype, ...)
info.type = tab.type info.type = tab.type
if type(method)=="function" then if type(method)=="function" then
return method(info, ...) return method(info, unpack(arg))
elseif type(method)=="string" then elseif type(method)=="string" then
if type(info.handler[method])~="function" then if type(info.handler[method])~="function" then
err(info, inputpos, "'"..methodtype.."': '"..method.."' is not a member function of "..tostring(info.handler)) err(info, inputpos, "'"..methodtype.."': '"..method.."' is not a member function of "..tostring(info.handler))
end end
return info.handler[method](info.handler, info, ...) return info.handler[method](info.handler, info, unpack(arg))
else else
assert(false) -- type should have already been checked on read assert(false) -- type should have already been checked on read
end end
@@ -122,7 +124,11 @@ local function callfunction(info, tab, methodtype, ...)
info.type = tab.type info.type = tab.type
if type(method)=="function" then if type(method)=="function" then
return method(info, ...) if getn(arg) > 0 then
return method(info, unpack(arg))
else
return method(info)
end
else else
assert(false) -- type should have already been checked on read assert(false) -- type should have already been checked on read
end end
@@ -132,7 +138,7 @@ end
local function do_final(info, inputpos, tab, methodtype, ...) local function do_final(info, inputpos, tab, methodtype, ...)
if info.validate then if info.validate then
local res = callmethod(info,inputpos,tab,"validate",...) local res = callmethod(info,inputpos,tab,"validate",unpack(arg))
if type(res)=="string" then if type(res)=="string" then
usererr(info, inputpos, "'"..strsub(info.input, inputpos).."' - "..res) usererr(info, inputpos, "'"..strsub(info.input, inputpos).."' - "..res)
return return
@@ -140,7 +146,7 @@ local function do_final(info, inputpos, tab, methodtype, ...)
end end
-- console ignores .confirm -- console ignores .confirm
callmethod(info,inputpos,tab,methodtype, ...) callmethod(info,inputpos,tab,methodtype, unpack(arg))
end end
@@ -222,16 +228,16 @@ local function showhelp(info, inputpos, tab, depth, noHead)
local o2 = refTbl[two].order or 100 local o2 = refTbl[two].order or 100
if type(o1) == "function" or type(o1) == "string" then if type(o1) == "function" or type(o1) == "string" then
info.order = o1 info.order = o1
info[#info+1] = one tinsert(info, one)
o1 = callmethod(info, inputpos, refTbl[one], "order") o1 = callmethod(info, inputpos, refTbl[one], "order")
info[#info] = nil tremove(info)
info.order = nil info.order = nil
end end
if type(o2) == "function" or type(o1) == "string" then if type(o2) == "function" or type(o1) == "string" then
info.order = o2 info.order = o2
info[#info+1] = two tinsert(info, two)
o2 = callmethod(info, inputpos, refTbl[two], "order") o2 = callmethod(info, inputpos, refTbl[two], "order")
info[#info] = nil tremove(info)
info.order = nil info.order = nil
end end
if o1<0 and o2<0 then return o1<o2 end if o1<0 and o2<0 then return o1<o2 end
@@ -241,7 +247,7 @@ local function showhelp(info, inputpos, tab, depth, noHead)
return o1<o2 return o1<o2
end) end)
for i = 1, #sortTbl do for i = 1, getn(sortTbl) do
local k = sortTbl[i] local k = sortTbl[i]
local v = refTbl[k] local v = refTbl[k]
if not checkhidden(info, inputpos, v) then if not checkhidden(info, inputpos, v) then
@@ -260,7 +266,7 @@ local function showhelp(info, inputpos, tab, depth, noHead)
showhelp(info, inputpos, v, depth, true) showhelp(info, inputpos, v, depth, true)
info.handler,info.handler_at = oldhandler,oldhandler_at info.handler,info.handler_at = oldhandler,oldhandler_at
else else
local key = k:gsub(" ", "_") local key = strgsub(k, " ", "_")
print(" |cffffff78"..key.."|r - "..(desc or name or "")) print(" |cffffff78"..key.."|r - "..(desc or name or ""))
end end
end end
@@ -273,7 +279,7 @@ local function keybindingValidateFunc(text)
if text == nil or text == "NONE" then if text == nil or text == "NONE" then
return nil return nil
end end
text = text:upper() text = strupper(text)
local shift, ctrl, alt local shift, ctrl, alt
local modifier local modifier
while true do while true do
@@ -311,7 +317,7 @@ local function keybindingValidateFunc(text)
if text == "" then if text == "" then
return false return false
end end
if not text:find("^F%d+$") and text ~= "CAPSLOCK" and text:len() ~= 1 and (text:byte() < 128 or text:len() > 4) and not _G["KEY_" .. text] then if not strfind(text,"^F%d+$") and text ~= "CAPSLOCK" and strlen(text) ~= 1 and (strbyte(text) < 128 or strlen(text) > 4) and not _G["KEY_" .. text] then
return false return false
end end
local s = text local s = text
@@ -357,7 +363,7 @@ local function handle(info, inputpos, tab, depth, retfalse)
if tab.plugins and type(tab.plugins)~="table" then err(info,inputpos) end if tab.plugins and type(tab.plugins)~="table" then err(info,inputpos) end
-- grab next arg from input -- grab next arg from input
local _,nextpos,arg = (info.input):find(" *([^ ]+) *", inputpos) local _,nextpos,arg = strfind(info.input, " *([^ ]+) *", inputpos)
if not arg then if not arg then
showhelp(info, inputpos, tab, depth) showhelp(info, inputpos, tab, depth)
return return
@@ -370,16 +376,16 @@ local function handle(info, inputpos, tab, depth, retfalse)
-- is this child an inline group? if so, traverse into it -- is this child an inline group? if so, traverse into it
if v.type=="group" and pickfirstset(v.cmdInline, v.inline, false) then if v.type=="group" and pickfirstset(v.cmdInline, v.inline, false) then
info[depth+1] = k tinsert(info,k)
if handle(info, inputpos, v, depth+1, true)==false then if handle(info, inputpos, v, depth+1, true)==false then
info[depth+1] = nil tremove(info)
-- wasn't found in there, but that's ok, we just keep looking down here -- wasn't found in there, but that's ok, we just keep looking down here
else else
return -- done, name was found in inline group return -- done, name was found in inline group
end end
-- matching name and not a inline group -- matching name and not a inline group
elseif strlower(arg)==strlower(k:gsub(" ", "_")) then elseif strlower(arg)==strlower(strgsub(k, " ", "_")) then
info[depth+1] = k tinsert(info,k)
return handle(info,nextpos,v,depth+1) return handle(info,nextpos,v,depth+1)
end end
end end
@@ -471,7 +477,7 @@ local function handle(info, inputpos, tab, depth, retfalse)
return return
end end
if type(info.step)=="number" then if type(info.step)=="number" then
val = val- (val % info.step) val = val- fmod(val, info.step)
end end
if type(info.min)=="number" and val<info.min then if type(info.min)=="number" and val<info.min then
usererr(info, inputpos, val.." - "..format(L["must be equal to or higher than %s"], tostring(info.min)) ) usererr(info, inputpos, val.." - "..format(L["must be equal to or higher than %s"], tostring(info.min)) )
@@ -500,12 +506,12 @@ local function handle(info, inputpos, tab, depth, retfalse)
local b = callmethod(info, inputpos, tab, "get") local b = callmethod(info, inputpos, tab, "get")
local fmt = "|cffffff78- [%s]|r %s" local fmt = "|cffffff78- [%s]|r %s"
local fmt_sel = "|cffffff78- [%s]|r %s |cffff0000*|r" local fmt_sel = "|cffffff78- [%s]|r %s |cffff0000*|r"
print(L["Options for |cffffff78"..info[#info].."|r:"]) print(L["Options for |cffffff78"..info[getn(info)].."|r:"])
for k, v in pairs(values) do for k, v in pairs(values) do
if b == k then if b == k then
print(fmt_sel:format(k, v)) print(format(fmt_sel, k, v))
else else
print(fmt:format(k, v)) print(format(fmt, k, v))
end end
end end
return return
@@ -540,12 +546,12 @@ local function handle(info, inputpos, tab, depth, retfalse)
if str == "" then if str == "" then
local fmt = "|cffffff78- [%s]|r %s" local fmt = "|cffffff78- [%s]|r %s"
local fmt_sel = "|cffffff78- [%s]|r %s |cffff0000*|r" local fmt_sel = "|cffffff78- [%s]|r %s |cffff0000*|r"
print(L["Options for |cffffff78"..info[#info].."|r (multiple possible):"]) print(L["Options for |cffffff78"..info[getn(info)].."|r (multiple possible):"])
for k, v in pairs(values) do for k, v in pairs(values) do
if callmethod(info, inputpos, tab, "get", k) then if callmethod(info, inputpos, tab, "get", k) then
print(fmt_sel:format(k, v)) print(format(fmt_sel, k, v))
else else
print(fmt:format(k, v)) print(format(fmt, k, v))
end end
end end
return return
@@ -555,9 +561,9 @@ local function handle(info, inputpos, tab, depth, retfalse)
--parse for =on =off =default in the process --parse for =on =off =default in the process
--table will be key = true for options that should toggle, key = [on|off|default] for options to be set --table will be key = true for options that should toggle, key = [on|off|default] for options to be set
local sels = {} local sels = {}
for v in str:gmatch("[^ ]+") do for v in strgfind(str, "[^ ]+") do
--parse option=on etc --parse option=on etc
local opt, val = v:match('(.+)=(.+)') local _, _, opt, val = strfind(v, '(.+)=(.+)')
--get option if toggling --get option if toggling
if not opt then if not opt then
opt = v opt = v
@@ -640,7 +646,7 @@ local function handle(info, inputpos, tab, depth, retfalse)
return return
end end
local r, g, b, a local _, r, g, b, a
local hasAlpha = tab.hasAlpha local hasAlpha = tab.hasAlpha
if type(hasAlpha) == "function" or type(hasAlpha) == "string" then if type(hasAlpha) == "function" or type(hasAlpha) == "string" then
@@ -650,12 +656,12 @@ local function handle(info, inputpos, tab, depth, retfalse)
end end
if hasAlpha then if hasAlpha then
if str:len() == 8 and str:find("^%x*$") then if strlen(str) == 8 and strfind(str, "^%x*$") then
--parse a hex string --parse a hex string
r,g,b,a = tonumber(str:sub(1, 2), 16) / 255, tonumber(str:sub(3, 4), 16) / 255, tonumber(str:sub(5, 6), 16) / 255, tonumber(str:sub(7, 8), 16) / 255 r,g,b,a = tonumber(strsub(str, 1, 2), 16) / 255, tonumber(strsub(str, 3, 4), 16) / 255, tonumber(strsub(str, 5, 6), 16) / 255, tonumber(strsub(str, 7, 8), 16) / 255
else else
--parse seperate values --parse seperate values
r,g,b,a = str:match("^([%d%.]+) ([%d%.]+) ([%d%.]+) ([%d%.]+)$") _,_,r,g,b,a = strfind(str, "^([%d%.]+) ([%d%.]+) ([%d%.]+) ([%d%.]+)$")
r,g,b,a = tonumber(r), tonumber(g), tonumber(b), tonumber(a) r,g,b,a = tonumber(r), tonumber(g), tonumber(b), tonumber(a)
end end
if not (r and g and b and a) then if not (r and g and b and a) then
@@ -677,12 +683,12 @@ local function handle(info, inputpos, tab, depth, retfalse)
end end
else else
a = 1.0 a = 1.0
if str:len() == 6 and str:find("^%x*$") then if strlen(str) == 6 and strfind(str, "^%x*$") then
--parse a hex string --parse a hex string
r,g,b = tonumber(str:sub(1, 2), 16) / 255, tonumber(str:sub(3, 4), 16) / 255, tonumber(str:sub(5, 6), 16) / 255 r,g,b = tonumber(strsub(str, 1, 2), 16) / 255, tonumber(strsub(str, 3, 4), 16) / 255, tonumber(strsub(str, 5, 6), 16) / 255
else else
--parse seperate values --parse seperate values
r,g,b = str:match("^([%d%.]+) ([%d%.]+) ([%d%.]+)$") _,_,r,g,b = strfind(str, "^([%d%.]+) ([%d%.]+) ([%d%.]+)$")
r,g,b = tonumber(r), tonumber(g), tonumber(b) r,g,b = tonumber(r), tonumber(g), tonumber(b)
end end
if not (r and g and b) then if not (r and g and b) then
@@ -711,7 +717,7 @@ local function handle(info, inputpos, tab, depth, retfalse)
--TODO: Show current value --TODO: Show current value
return return
end end
local value = keybindingValidateFunc(str:upper()) local value = keybindingValidateFunc(strupper(str))
if value == false then if value == false then
usererr(info, inputpos, format(L["'%s' - Invalid Keybinding."], str)) usererr(info, inputpos, format(L["'%s' - Invalid Keybinding."], str))
return return
@@ -741,7 +747,7 @@ end
-- -- Show the GUI if no input is supplied, otherwise handle the chat input. -- -- Show the GUI if no input is supplied, otherwise handle the chat input.
-- function MyAddon:ChatCommand(input) -- function MyAddon:ChatCommand(input)
-- -- Assuming "MyOptions" is the appName of a valid options table -- -- Assuming "MyOptions" is the appName of a valid options table
-- if not input or input:trim() == "" then -- if not input or trim(input) == "" then
-- LibStub("AceConfigDialog-3.0"):Open("MyOptions") -- LibStub("AceConfigDialog-3.0"):Open("MyOptions")
-- else -- else
-- LibStub("AceConfigCmd-3.0").HandleCommand(MyAddon, "mychat", "MyOptions", input) -- LibStub("AceConfigCmd-3.0").HandleCommand(MyAddon, "mychat", "MyOptions", input)
@@ -5,9 +5,9 @@
local LibStub = LibStub local LibStub = LibStub
local gui = LibStub("AceGUI-3.0") local gui = LibStub("AceGUI-3.0")
local reg = LibStub("AceConfigRegistry-3.0-ElvUI") local reg = LibStub("AceConfigRegistry-3.0")
local MAJOR, MINOR = "AceConfigDialog-3.0-ElvUI", 65 local MAJOR, MINOR = "AceConfigDialog-3.0", 65
local AceConfigDialog, oldminor = LibStub:NewLibrary(MAJOR, MINOR) local AceConfigDialog, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not AceConfigDialog then return end if not AceConfigDialog then return end
@@ -21,10 +21,10 @@ AceConfigDialog.frame.closing = AceConfigDialog.frame.closing or {}
AceConfigDialog.frame.closeAllOverride = AceConfigDialog.frame.closeAllOverride or {} AceConfigDialog.frame.closeAllOverride = AceConfigDialog.frame.closeAllOverride or {}
-- Lua APIs -- Lua APIs
local tconcat, tinsert, tsort, tremove, tsort = table.concat, table.insert, table.sort, table.remove, table.sort local tconcat, tinsert, tsort, tremove, tsort, getn, setn = table.concat, table.insert, table.sort, table.remove, table.sort, table.getn, table.setn
local strmatch, format = string.match, string.format local gsub, format, upper, find = string.gsub, string.format, string.upper, string.find
local assert, loadstring, error = assert, loadstring, error local assert, loadstring, error = assert, loadstring, error
local pairs, next, select, type, unpack, wipe, ipairs = pairs, next, select, type, unpack, wipe, ipairs local pairs, next, type, unpack, wipe, ipairs = pairs, next, type, unpack, wipe, ipairs
local rawset, tostring, tonumber = rawset, tostring, tonumber local rawset, tostring, tonumber = rawset, tostring, tonumber
local math_min, math_max, math_floor = math.min, math.max, math.floor local math_min, math_max, math_floor = math.min, math.max, math.floor
@@ -47,14 +47,14 @@ end
local function CreateDispatcher(argCount) local function CreateDispatcher(argCount)
local code = [[ local code = [[
local xpcall, eh = ... local xpcall, eh = xpcall, function(err) return geterrorhandler()(err) end
local method, ARGS local method, ARGS
local function call() return method(ARGS) end local function call() return method(ARGS) end
local function dispatch(func, ...) local function dispatch(func, ...)
method = func method = func
if not method then return end if not method then return end
ARGS = ... ARGS = unpack(arg)
return xpcall(call, eh) return xpcall(call, eh)
end end
@@ -63,7 +63,7 @@ local function CreateDispatcher(argCount)
local ARGS = {} local ARGS = {}
for i = 1, argCount do ARGS[i] = "arg"..i end for i = 1, argCount do ARGS[i] = "arg"..i end
code = code:gsub("ARGS", tconcat(ARGS, ", ")) code = gsub(code, "ARGS", tconcat(ARGS, ", "))
return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler) return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler)
end end
@@ -77,7 +77,7 @@ Dispatchers[0] = function(func)
end end
local function safecall(func, ...) local function safecall(func, ...)
return Dispatchers[select("#", ...)](func, ...) return Dispatchers[getn(arg)](func, unpack(arg))
end end
local width_multiplier = 170 local width_multiplier = 170
@@ -121,6 +121,7 @@ do
for k, v in pairs(t) do for k, v in pairs(t) do
c[k] = v c[k] = v
end end
setn(c, getn(t))
return c return c
end end
function del(t) function del(t)
@@ -139,11 +140,11 @@ end
-- picks the first non-nil value and returns it -- picks the first non-nil value and returns it
local function pickfirstset(...) local function pickfirstset(...)
for i=1,select("#",...) do for i=1,getn(arg) do
if select(i,...)~=nil then if arg[i]~=nil then
return select(i,...) return arg[i]
end end
end end
end end
--gets an option from a given group, checking plugins --gets an option from a given group, checking plugins
@@ -207,7 +208,7 @@ local function GetOptionsMemberValue(membername, option, options, path, appName,
if group[membername] ~= nil then if group[membername] ~= nil then
member = group[membername] member = group[membername]
end end
for i = 1, #path do for i = 1, getn(path) do
group = GetSubOption(group, path[i]) group = GetSubOption(group, path[i])
if group[membername] ~= nil then if group[membername] ~= nil then
member = group[membername] member = group[membername]
@@ -226,11 +227,13 @@ local function GetOptionsMemberValue(membername, option, options, path, appName,
local group = options local group = options
handler = group.handler or handler handler = group.handler or handler
for i = 1, #path do local x = getn(path)
for i = 1, x do
group = GetSubOption(group, path[i]) group = GetSubOption(group, path[i])
info[i] = path[i] info[i] = path[i]
handler = group.handler or handler handler = group.handler or handler
end end
setn(info, x)
info.options = options info.options = options
info.appName = appName info.appName = appName
@@ -242,21 +245,21 @@ local function GetOptionsMemberValue(membername, option, options, path, appName,
info.uiType = "dialog" info.uiType = "dialog"
info.uiName = MAJOR info.uiName = MAJOR
local a, b, c ,d, e, f, g, h local a, b, c ,d
--using 4 returns for the get of a color type, increase if a type needs more --using 4 returns for the get of a color type, increase if a type needs more
if type(member) == "function" then if type(member) == "function" then
--Call the function --Call the function
a,b,c,d, e, f, g, h = member(info, ...) a,b,c,d = member(info, unpack(arg))
else else
--Call the method --Call the method
if handler and handler[member] then if handler and handler[member] then
a,b,c,d,e, f, g, h = handler[member](handler, info, ...) a,b,c,d = handler[member](handler, info, unpack(arg))
else else
error(format("Method %s doesn't exist in handler for type %s", member, membername)) error(format("Method %s doesn't exist in handler for type %s", member, membername))
end end
end end
del(info) del(info)
return a,b,c,d,e, f, g, h return a,b,c,d
else else
--The value isnt a function to call, return it --The value isnt a function to call, return it
return member return member
@@ -322,7 +325,7 @@ local function compareOptions(a,b)
if OrderA == OrderB then if OrderA == OrderB then
local NameA = (type(tempNames[a]) == "string") and tempNames[a] or "" local NameA = (type(tempNames[a]) == "string") and tempNames[a] or ""
local NameB = (type(tempNames[b]) == "string") and tempNames[b] or "" local NameB = (type(tempNames[b]) == "string") and tempNames[b] or ""
return NameA:upper() < NameB:upper() return upper(NameA) < upper(NameB)
end end
if OrderA < 0 then if OrderA < 0 then
if OrderB > 0 then if OrderB > 0 then
@@ -352,10 +355,10 @@ local function BuildSortedOptionsTable(group, keySort, opts, options, path, appN
tinsert(keySort, k) tinsert(keySort, k)
opts[k] = v opts[k] = v
path[#path+1] = k tinsert(path,k)
tempOrders[k] = GetOptionsMemberValue("order", v, options, path, appName) tempOrders[k] = GetOptionsMemberValue("order", v, options, path, appName)
tempNames[k] = GetOptionsMemberValue("name", v, options, path, appName) tempNames[k] = GetOptionsMemberValue("name", v, options, path, appName)
path[#path] = nil tremove(path)
end end
end end
end end
@@ -366,10 +369,10 @@ local function BuildSortedOptionsTable(group, keySort, opts, options, path, appN
tinsert(keySort, k) tinsert(keySort, k)
opts[k] = v opts[k] = v
path[#path+1] = k tinsert(path,k)
tempOrders[k] = GetOptionsMemberValue("order", v, options, path, appName) tempOrders[k] = GetOptionsMemberValue("order", v, options, path, appName)
tempNames[k] = GetOptionsMemberValue("name", v, options, path, appName) tempNames[k] = GetOptionsMemberValue("name", v, options, path, appName)
path[#path] = nil tremove(path)
end end
end end
@@ -382,7 +385,7 @@ end
local function DelTree(tree) local function DelTree(tree)
if tree.children then if tree.children then
local childs = tree.children local childs = tree.children
for i = 1, #childs do for i = 1, getn(childs) do
DelTree(childs[i]) DelTree(childs[i])
del(childs[i]) del(childs[i])
end end
@@ -402,7 +405,7 @@ local function CleanUserData(widget, event)
local tree = user.tree local tree = user.tree
widget:SetTree(nil) widget:SetTree(nil)
if tree then if tree then
for i = 1, #tree do for i = 1, getn(tree) do
DelTree(tree[i]) DelTree(tree[i])
del(tree[i]) del(tree[i])
end end
@@ -444,7 +447,7 @@ function AceConfigDialog:GetStatusTable(appName, path)
status = status[appName] status = status[appName]
if path then if path then
for i = 1, #path do for i = 1, getn(path) do
local v = path[i] local v = path[i]
if not status.children[v] then if not status.children[v] then
status.children[v] = {} status.children[v] = {}
@@ -468,7 +471,7 @@ function AceConfigDialog:SelectGroup(appName, ...)
local app = reg:GetOptionsTable(appName) local app = reg:GetOptionsTable(appName)
if not app then if not app then
error(("%s isn't registed with AceConfigRegistry, unable to open config"):format(appName), 2) error(format("%s isn't registed with AceConfigRegistry, unable to open config", appName), 2)
end end
local options = app("dialog", MAJOR) local options = app("dialog", MAJOR)
local group = options local group = options
@@ -480,8 +483,8 @@ function AceConfigDialog:SelectGroup(appName, ...)
local treevalue local treevalue
local treestatus local treestatus
for n = 1, select("#",...) do for n = 1, getn(arg) do
local key = select(n, ...) local key = arg[n]
if group.childGroups == "tab" or group.childGroups == "select" then if group.childGroups == "tab" or group.childGroups == "select" then
--if this is a tab or select group, select the group --if this is a tab or select group, select the group
@@ -597,9 +600,11 @@ local function confirmPopup(appName, rootframe, basepath, info, message, func, .
AceConfigDialog:Open(appName, rootframe, unpack(basepath or emptyTbl)) AceConfigDialog:Open(appName, rootframe, unpack(basepath or emptyTbl))
del(info) del(info)
end end
for i = 1, select("#", ...) do local x = getn(arg)
t[i] = select(i, ...) or false for i = 1, x do
t[i] = arg[i] or false
end end
setn(t, x)
t.timeout = 0 t.timeout = 0
t.whileDead = 1 t.whileDead = 1
t.hideOnEscape = 1 t.hideOnEscape = 1
@@ -659,7 +664,8 @@ local function ActivateControl(widget, event, ...)
handler = group.handler or handler handler = group.handler or handler
confirm = group.confirm confirm = group.confirm
validate = group.validate validate = group.validate
for i = 1, #path do local x = getn(path)
for i = 1, x do
local v = path[i] local v = path[i]
group = GetSubOption(group, v) group = GetSubOption(group, v)
info[i] = v info[i] = v
@@ -674,6 +680,7 @@ local function ActivateControl(widget, event, ...)
validate = group.validate validate = group.validate
end end
end end
setn(info, x)
info.options = options info.options = options
info.appName = user.appName info.appName = user.appName
@@ -699,7 +706,7 @@ local function ActivateControl(widget, event, ...)
if option.type == "input" then if option.type == "input" then
if type(pattern)=="string" then if type(pattern)=="string" then
if not strmatch(..., pattern) then if not find(arg[1], pattern) then
validated = false validated = false
end end
end end
@@ -709,13 +716,13 @@ local function ActivateControl(widget, event, ...)
if validated and option.type ~= "execute" then if validated and option.type ~= "execute" then
if type(validate) == "string" then if type(validate) == "string" then
if handler and handler[validate] then if handler and handler[validate] then
success, validated = safecall(handler[validate], handler, info, ...) success, validated = safecall(handler[validate], handler, info, unpack(arg))
if not success then validated = false end if not success then validated = false end
else else
error(format("Method %s doesn't exist in handler for type execute", validate)) error(format("Method %s doesn't exist in handler for type execute", validate))
end end
elseif type(validate) == "function" then elseif type(validate) == "function" then
success, validated = safecall(validate, info, ...) success, validated = safecall(validate, info, unpack(arg))
if not success then validated = false end if not success then validated = false end
end end
end end
@@ -749,7 +756,7 @@ local function ActivateControl(widget, event, ...)
--call confirm func/method --call confirm func/method
if type(confirm) == "string" then if type(confirm) == "string" then
if handler and handler[confirm] then if handler and handler[confirm] then
success, confirm = safecall(handler[confirm], handler, info, ...) success, confirm = safecall(handler[confirm], handler, info, unpack(arg))
if success and type(confirm) == "string" then if success and type(confirm) == "string" then
confirmText = confirm confirmText = confirm
confirm = true confirm = true
@@ -760,7 +767,7 @@ local function ActivateControl(widget, event, ...)
error(format("Method %s doesn't exist in handler for type confirm", confirm)) error(format("Method %s doesn't exist in handler for type confirm", confirm))
end end
elseif type(confirm) == "function" then elseif type(confirm) == "function" then
success, confirm = safecall(confirm, info, ...) success, confirm = safecall(confirm, info, unpack(arg))
if success and type(confirm) == "string" then if success and type(confirm) == "string" then
confirmText = confirm confirmText = confirm
confirm = true confirm = true
@@ -795,12 +802,12 @@ local function ActivateControl(widget, event, ...)
local basepath = user.rootframe:GetUserData("basepath") local basepath = user.rootframe:GetUserData("basepath")
if type(func) == "string" then if type(func) == "string" then
if handler and handler[func] then if handler and handler[func] then
confirmPopup(user.appName, rootframe, basepath, info, confirmText, handler[func], handler, info, ...) confirmPopup(user.appName, rootframe, basepath, info, confirmText, handler[func], handler, info, unpack(arg))
else else
error(format("Method %s doesn't exist in handler for type func", func)) error(format("Method %s doesn't exist in handler for type func", func))
end end
elseif type(func) == "function" then elseif type(func) == "function" then
confirmPopup(user.appName, rootframe, basepath, info, confirmText, func, info, ...) confirmPopup(user.appName, rootframe, basepath, info, confirmText, func, info, unpack(arg))
end end
--func will be called and info deleted when the confirm dialog is responded to --func will be called and info deleted when the confirm dialog is responded to
return return
@@ -810,12 +817,12 @@ local function ActivateControl(widget, event, ...)
--call the function --call the function
if type(func) == "string" then if type(func) == "string" then
if handler and handler[func] then if handler and handler[func] then
safecall(handler[func],handler, info, ...) safecall(handler[func],handler, info, unpack(arg))
else else
error(format("Method %s doesn't exist in handler for type func", func)) error(format("Method %s doesn't exist in handler for type func", func))
end end
elseif type(func) == "function" then elseif type(func) == "function" then
safecall(func,info, ...) safecall(func,info, unpack(arg))
end end
@@ -873,7 +880,7 @@ end
--called from a checkbox that is part of an internally created multiselect group --called from a checkbox that is part of an internally created multiselect group
--this type is safe to refresh on activation of one control --this type is safe to refresh on activation of one control
local function ActivateMultiControl(widget, event, ...) local function ActivateMultiControl(widget, event, ...)
ActivateControl(widget, event, widget:GetUserData("value"), ...) ActivateControl(widget, event, widget:GetUserData("value"), unpack(arg))
local user = widget:GetUserDataTable() local user = widget:GetUserDataTable()
local iscustom = user.rootframe:GetUserData("iscustom") local iscustom = user.rootframe:GetUserData("iscustom")
local basepath = user.rootframe:GetUserData("basepath") or emptyTbl local basepath = user.rootframe:GetUserData("basepath") or emptyTbl
@@ -960,18 +967,18 @@ local function BuildSelect(group, options, path, appName)
BuildSortedOptionsTable(group, keySort, opts, options, path, appName) BuildSortedOptionsTable(group, keySort, opts, options, path, appName)
for i = 1, #keySort do for i = 1, getn(keySort) do
local k = keySort[i] local k = keySort[i]
local v = opts[k] local v = opts[k]
if v.type == "group" then if v.type == "group" then
path[#path+1] = k tinsert(path, k)
local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false) local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
local hidden = CheckOptionHidden(v, options, path, appName) local hidden = CheckOptionHidden(v, options, path, appName)
if not inline and not hidden then if not inline and not hidden then
groups[k] = GetOptionsMemberValue("name", v, options, path, appName) groups[k] = GetOptionsMemberValue("name", v, options, path, appName)
tinsert(order, k) tinsert(order, k)
end end
path[#path] = nil tremove(path)
end end
end end
@@ -987,11 +994,11 @@ local function BuildSubGroups(group, tree, options, path, appName)
BuildSortedOptionsTable(group, keySort, opts, options, path, appName) BuildSortedOptionsTable(group, keySort, opts, options, path, appName)
for i = 1, #keySort do for i = 1, getn(keySort) do
local k = keySort[i] local k = keySort[i]
local v = opts[k] local v = opts[k]
if v.type == "group" then if v.type == "group" then
path[#path+1] = k tinsert(path, k)
local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false) local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
local hidden = CheckOptionHidden(v, options, path, appName) local hidden = CheckOptionHidden(v, options, path, appName)
if not inline and not hidden then if not inline and not hidden then
@@ -1007,7 +1014,7 @@ local function BuildSubGroups(group, tree, options, path, appName)
BuildSubGroups(v,entry, options, path, appName) BuildSubGroups(v,entry, options, path, appName)
end end
end end
path[#path] = nil tremove(path)
end end
end end
@@ -1022,11 +1029,11 @@ local function BuildGroups(group, options, path, appName, recurse)
BuildSortedOptionsTable(group, keySort, opts, options, path, appName) BuildSortedOptionsTable(group, keySort, opts, options, path, appName)
for i = 1, #keySort do for i = 1, getn(keySort) do
local k = keySort[i] local k = keySort[i]
local v = opts[k] local v = opts[k]
if v.type == "group" then if v.type == "group" then
path[#path+1] = k tinsert(path,k)
local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false) local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
local hidden = CheckOptionHidden(v, options, path, appName) local hidden = CheckOptionHidden(v, options, path, appName)
if not inline and not hidden then if not inline and not hidden then
@@ -1041,7 +1048,7 @@ local function BuildGroups(group, options, path, appName, recurse)
BuildSubGroups(v,entry, options, path, appName) BuildSubGroups(v,entry, options, path, appName)
end end
end end
path[#path] = nil tremove(path)
end end
end end
del(keySort) del(keySort)
@@ -1051,9 +1058,11 @@ end
local function InjectInfo(control, options, option, path, rootframe, appName) local function InjectInfo(control, options, option, path, rootframe, appName)
local user = control:GetUserDataTable() local user = control:GetUserDataTable()
for i = 1, #path do local x = getn(path)
for i = 1, x do
user[i] = path[i] user[i] = path[i]
end end
setn(user, x)
user.rootframe = rootframe user.rootframe = rootframe
user.option = option user.option = option
user.options = options user.options = options
@@ -1078,7 +1087,7 @@ local function FeedOptions(appName, options,container,rootframe,path,group,inlin
BuildSortedOptionsTable(group, keySort, opts, options, path, appName) BuildSortedOptionsTable(group, keySort, opts, options, path, appName)
for i = 1, #keySort do for i = 1, getn(keySort) do
local k = keySort[i] local k = keySort[i]
local v = opts[k] local v = opts[k]
tinsert(path, k) tinsert(path, k)
@@ -1144,7 +1153,7 @@ local function FeedOptions(appName, options,container,rootframe,path,group,inlin
local controlType = v.dialogControl or v.control or (v.multiline and "MultiLineEditBox") or "EditBox" local controlType = v.dialogControl or v.control or (v.multiline and "MultiLineEditBox") or "EditBox"
control = gui:Create(controlType) control = gui:Create(controlType)
if not control then if not control then
geterrorhandler()(("Invalid Custom Control Type - %s"):format(tostring(controlType))) geterrorhandler()(format("Invalid Custom Control Type - %s", tostring(controlType)))
control = gui:Create(v.multiline and "MultiLineEditBox" or "EditBox") control = gui:Create(v.multiline and "MultiLineEditBox" or "EditBox")
end end
@@ -1209,7 +1218,7 @@ local function FeedOptions(appName, options,container,rootframe,path,group,inlin
local optionValue = GetOptionsMemberValue("get",v, options, path, appName) local optionValue = GetOptionsMemberValue("get",v, options, path, appName)
local t = {} local t = {}
for value, text in pairs(values) do for value, text in pairs(values) do
t[#t+1]=value tinsert(t, value)
end end
tsort(t) tsort(t)
for k, value in ipairs(t) do for k, value in ipairs(t) do
@@ -1240,12 +1249,12 @@ local function FeedOptions(appName, options,container,rootframe,path,group,inlin
local controlType = v.dialogControl or v.control or "Dropdown" local controlType = v.dialogControl or v.control or "Dropdown"
control = gui:Create(controlType) control = gui:Create(controlType)
if not control then if not control then
geterrorhandler()(("Invalid Custom Control Type - %s"):format(tostring(controlType))) geterrorhandler()(format("Invalid Custom Control Type - %s", tostring(controlType)))
control = gui:Create("Dropdown") control = gui:Create("Dropdown")
end end
local itemType = v.itemControl local itemType = v.itemControl
if itemType and not gui:GetWidgetVersion(itemType) then if itemType and not gui:GetWidgetVersion(itemType) then
geterrorhandler()(("Invalid Custom Item Type - %s"):format(tostring(itemType))) geterrorhandler()(format("Invalid Custom Item Type - %s", tostring(itemType)))
itemType = nil itemType = nil
end end
control:SetLabel(name) control:SetLabel(name)
@@ -1275,7 +1284,7 @@ local function FeedOptions(appName, options,container,rootframe,path,group,inlin
if controlType then if controlType then
control = gui:Create(controlType) control = gui:Create(controlType)
if not control then if not control then
geterrorhandler()(("Invalid Custom Control Type - %s"):format(tostring(controlType))) geterrorhandler()(format("Invalid Custom Control Type - %s", tostring(controlType)))
end end
end end
if control then if control then
@@ -1296,7 +1305,7 @@ local function FeedOptions(appName, options,container,rootframe,path,group,inlin
control:SetWidth(width_multiplier) control:SetWidth(width_multiplier)
end end
--check:SetTriState(v.tristate) --check:SetTriState(v.tristate)
for i = 1, #valuesort do for i = 1, getn(valuesort) do
local key = valuesort[i] local key = valuesort[i]
local value = GetOptionsMemberValue("get",v, options, path, appName, key) local value = GetOptionsMemberValue("get",v, options, path, appName, key)
control:SetItemValue(key,value) control:SetItemValue(key,value)
@@ -1309,7 +1318,7 @@ local function FeedOptions(appName, options,container,rootframe,path,group,inlin
control:PauseLayout() control:PauseLayout()
local width = GetOptionsMemberValue("width",v,options,path,appName) local width = GetOptionsMemberValue("width",v,options,path,appName)
for i = 1, #valuesort do for i = 1, getn(valuesort) do
local value = valuesort[i] local value = valuesort[i]
local text = values[value] local text = values[value]
local check = gui:Create("CheckBox") local check = gui:Create("CheckBox")
@@ -1341,7 +1350,7 @@ local function FeedOptions(appName, options,container,rootframe,path,group,inlin
del(valuesort) del(valuesort)
elseif v.type == "color" then elseif v.type == "color" then
control = gui:Create("ColorPicker-ElvUI") control = gui:Create("ColorPicker")
control:SetLabel(name) control:SetLabel(name)
control:SetHasAlpha(GetOptionsMemberValue("hasAlpha",v, options, path, appName)) control:SetHasAlpha(GetOptionsMemberValue("hasAlpha",v, options, path, appName))
control:SetColor(GetOptionsMemberValue("get",v, options, path, appName)) control:SetColor(GetOptionsMemberValue("get",v, options, path, appName))
@@ -1433,8 +1442,8 @@ local function FeedOptions(appName, options,container,rootframe,path,group,inlin
end end
local function BuildPath(path, ...) local function BuildPath(path, ...)
for i = 1, select("#",...) do for i = 1, getn(arg) do
tinsert(path, (select(i,...))) tinsert(path, arg[i])
end end
end end
@@ -1448,13 +1457,15 @@ local function TreeOnButtonEnter(widget, event, uniquevalue, button)
local appName = user.appName local appName = user.appName
local feedpath = new() local feedpath = new()
for i = 1, #path do local x = getn(path)
for i = 1, x do
feedpath[i] = path[i] feedpath[i] = path[i]
end end
setn(feedpath, x)
BuildPath(feedpath, ("\001"):split(uniquevalue)) BuildPath(feedpath, strsplit("\001", uniquevalue))
local group = options local group = options
for i = 1, #feedpath do for i = 1, getn(feedpath) do
if not group then return end if not group then return end
group = GetSubOption(group, feedpath[i]) group = GetSubOption(group, feedpath[i])
end end
@@ -1462,7 +1473,7 @@ local function TreeOnButtonEnter(widget, event, uniquevalue, button)
local name = GetOptionsMemberValue("name", group, options, feedpath, appName) local name = GetOptionsMemberValue("name", group, options, feedpath, appName)
local desc = GetOptionsMemberValue("desc", group, options, feedpath, appName) local desc = GetOptionsMemberValue("desc", group, options, feedpath, appName)
GameTooltip:SetOwner(button, "ANCHOR_CURSOR") GameTooltip:SetOwner(button, "ANCHOR_NONE")
if widget.type == "TabGroup" then if widget.type == "TabGroup" then
GameTooltip:SetPoint("BOTTOM",button,"TOP") GameTooltip:SetPoint("BOTTOM",button,"TOP")
else else
@@ -1488,14 +1499,16 @@ local function GroupExists(appName, options, path, uniquevalue)
local feedpath = new() local feedpath = new()
local temppath = new() local temppath = new()
for i = 1, #path do local x = getn(path)
for i = 1, x do
feedpath[i] = path[i] feedpath[i] = path[i]
end end
setn(feedpath, x)
BuildPath(feedpath, ("\001"):split(uniquevalue)) BuildPath(feedpath, strsplit("\001", uniquevalue))
local group = options local group = options
for i = 1, #feedpath do for i = 1, getn(feedpath) do
local v = feedpath[i] local v = feedpath[i]
temppath[i] = v temppath[i] = v
group = GetSubOption(group, v) group = GetSubOption(group, v)
@@ -1521,13 +1534,15 @@ local function GroupSelected(widget, event, uniquevalue)
local rootframe = user.rootframe local rootframe = user.rootframe
local feedpath = new() local feedpath = new()
for i = 1, #path do local x = getn(path)
for i = 1, x do
feedpath[i] = path[i] feedpath[i] = path[i]
end end
setn(feedpath, x)
BuildPath(feedpath, ("\001"):split(uniquevalue)) BuildPath(feedpath, strsplit("\001", uniquevalue))
local group = options local group = options
for i = 1, #feedpath do for i = 1, getn(feedpath) do
group = GetSubOption(group, feedpath[i]) group = GetSubOption(group, feedpath[i])
end end
widget:ReleaseChildren() widget:ReleaseChildren()
@@ -1561,10 +1576,10 @@ function AceConfigDialog:FeedGroup(appName,options,container,rootframe,path, isR
local grouptype, parenttype = options.childGroups, "none" local grouptype, parenttype = options.childGroups, "none"
for i = 1, #path do for i = 1, getn(path) do
local v = path[i] local v = path[i]
group = GetSubOption(group, v) group = GetSubOption(group, v)
inline = inline or pickfirstset(v.dialogInline,v.guiInline,v.inline, false) inline = inline or pickfirstset(group.dialogInline,group.guiInline,group.inline, false)
parenttype = grouptype parenttype = grouptype
grouptype = group.childGroups grouptype = group.childGroups
end end
@@ -1639,7 +1654,7 @@ function AceConfigDialog:FeedGroup(appName,options,container,rootframe,path, isR
tab:SetTabs(tabs) tab:SetTabs(tabs)
tab:SetUserData("tablist", tabs) tab:SetUserData("tablist", tabs)
for i = 1, #tabs do for i = 1, getn(tabs) do
local entry = tabs[i] local entry = tabs[i]
if not entry.disabled then if not entry.disabled then
tab:SelectTab((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or entry.value) tab:SelectTab((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or entry.value)
@@ -1699,7 +1714,7 @@ function AceConfigDialog:FeedGroup(appName,options,container,rootframe,path, isR
tree:SetTree(treedefinition) tree:SetTree(treedefinition)
tree:SetUserData("tree",treedefinition) tree:SetUserData("tree",treedefinition)
for i = 1, #treedefinition do for i = 1, getn(treedefinition) do
local entry = treedefinition[i] local entry = treedefinition[i]
if not entry.disabled then if not entry.disabled then
tree:SelectByValue((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or entry.value) tree:SelectByValue((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or entry.value)
@@ -1715,7 +1730,7 @@ end
local old_CloseSpecialWindows local old_CloseSpecialWindows
local function RefreshOnUpdate(this) local function RefreshOnUpdate()
for appName in pairs(this.closing) do for appName in pairs(this.closing) do
if AceConfigDialog.OpenFrames[appName] then if AceConfigDialog.OpenFrames[appName] then
AceConfigDialog.OpenFrames[appName]:Hide() AceConfigDialog.OpenFrames[appName]:Hide()
@@ -1819,7 +1834,7 @@ function AceConfigDialog:Open(appName, container, ...)
end end
local app = reg:GetOptionsTable(appName) local app = reg:GetOptionsTable(appName)
if not app then if not app then
error(("%s isn't registed with AceConfigRegistry, unable to open config"):format(appName), 2) error(format("%s isn't registed with AceConfigRegistry, unable to open config", appName), 2)
end end
local options = app("dialog", MAJOR) local options = app("dialog", MAJOR)
@@ -1834,13 +1849,13 @@ function AceConfigDialog:Open(appName, container, ...)
tinsert(path, container) tinsert(path, container)
container = nil container = nil
end end
for n = 1, select("#",...) do for n = 1, getn(arg) do
tinsert(path, (select(n, ...))) tinsert(path, arg[n])
end end
local option = options local option = options
if type(container) == "table" and container.type == "BlizOptionsGroup" and #path > 0 then if type(container) == "table" and container.type == "BlizOptionsGroup" and getn(path) > 0 then
for i = 1, #path do for i = 1, getn(path) do
option = options.args[path[i]] option = options.args[path[i]]
end end
name = format("%s - %s", name, GetOptionsMemberValue("name", option, options, path, appName)) name = format("%s - %s", name, GetOptionsMemberValue("name", option, options, path, appName))
@@ -1852,7 +1867,7 @@ function AceConfigDialog:Open(appName, container, ...)
f:ReleaseChildren() f:ReleaseChildren()
f:SetUserData("appName", appName) f:SetUserData("appName", appName)
f:SetUserData("iscustom", true) f:SetUserData("iscustom", true)
if #path > 0 then if getn(path) > 0 then
f:SetUserData("basepath", copy(path)) f:SetUserData("basepath", copy(path))
end end
local status = AceConfigDialog:GetStatusTable(appName) local status = AceConfigDialog:GetStatusTable(appName)
@@ -1878,7 +1893,7 @@ function AceConfigDialog:Open(appName, container, ...)
f:ReleaseChildren() f:ReleaseChildren()
f:SetCallback("OnClose", FrameOnClose) f:SetCallback("OnClose", FrameOnClose)
f:SetUserData("appName", appName) f:SetUserData("appName", appName)
if #path > 0 then if getn(path) > 0 then
f:SetUserData("basepath", copy(path)) f:SetUserData("basepath", copy(path))
end end
f:SetTitle(name or "") f:SetTitle(name or "")
@@ -1944,8 +1959,8 @@ function AceConfigDialog:AddToBlizOptions(appName, name, parent, ...)
local BlizOptions = AceConfigDialog.BlizOptions local BlizOptions = AceConfigDialog.BlizOptions
local key = appName local key = appName
for n = 1, select("#", ...) do for n = 1, getn(arg) do
key = key.."\001"..select(n, ...) key = key.."\001"..arg[n]
end end
if not BlizOptions[appName] then if not BlizOptions[appName] then
@@ -1959,10 +1974,10 @@ function AceConfigDialog:AddToBlizOptions(appName, name, parent, ...)
group:SetTitle(name or appName) group:SetTitle(name or appName)
group:SetUserData("appName", appName) group:SetUserData("appName", appName)
if select("#", ...) > 0 then if getn(arg) > 0 then
local path = {} local path = {}
for n = 1, select("#",...) do for n = 1, getn(arg) do
tinsert(path, (select(n, ...))) tinsert(path, arg[n])
end end
group:SetUserData("path", path) group:SetUserData("path", path)
end end
@@ -1971,6 +1986,6 @@ function AceConfigDialog:AddToBlizOptions(appName, name, parent, ...)
InterfaceOptions_AddCategory(group.frame) InterfaceOptions_AddCategory(group.frame)
return group.frame return group.frame
else else
error(("%s has already been added to the Blizzard Options Window with the given path"):format(appName), 2) error(format("%s has already been added to the Blizzard Options Window with the given path", appName), 2)
end end
end end
@@ -11,7 +11,7 @@
-- @release $Id: AceConfigRegistry-3.0.lua 1105 2013-12-08 22:11:58Z nevcairiel $ -- @release $Id: AceConfigRegistry-3.0.lua 1105 2013-12-08 22:11:58Z nevcairiel $
local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0") local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0")
local MAJOR, MINOR = "AceConfigRegistry-3.0-ElvUI", 17 local MAJOR, MINOR = "AceConfigRegistry-3.0", 17
local AceConfigRegistry = LibStub:NewLibrary(MAJOR, MINOR) local AceConfigRegistry = LibStub:NewLibrary(MAJOR, MINOR)
if not AceConfigRegistry then return end if not AceConfigRegistry then return end
@@ -23,9 +23,9 @@ if not AceConfigRegistry.callbacks then
end end
-- Lua APIs -- Lua APIs
local tinsert, tconcat = table.insert, table.concat local tinsert, tconcat, getn = table.insert, table.concat, table.getn
local strfind, strmatch = string.find, string.match local strfind, strmatch = string.find, string.match
local type, tostring, select, pairs = type, tostring, select, pairs local type, tostring, pairs, unpack = type, tostring, pairs, unpack
local error, assert = error, assert local error, assert = error, assert
----------------------------------------------------------------------- -----------------------------------------------------------------------
@@ -44,8 +44,8 @@ AceConfigRegistry.validated = {
local function err(msg, errlvl, ...) local function err(msg, errlvl, ...)
local t = {} local t = {}
for i=select("#",...),1,-1 do for i=getn(arg),1,-1 do
tinsert(t, (select(i, ...))) tinsert(t, arg[i])
end end
error(MAJOR..":ValidateOptionsTable(): "..tconcat(t,".")..msg, errlvl+2) error(MAJOR..":ValidateOptionsTable(): "..tconcat(t,".")..msg, errlvl+2)
end end
@@ -90,6 +90,7 @@ local basekeys={
func=optmethodfalse, func=optmethodfalse,
arg={["*"]=true}, arg={["*"]=true},
width=optstring, width=optstring,
-- below here were created by ElvUI --
buttonElvUI=optmethodbool, buttonElvUI=optmethodbool,
} }
@@ -164,7 +165,6 @@ local typedkeys={
}, },
color={ color={
hasAlpha=optmethodbool, hasAlpha=optmethodbool,
reset=opttable,
}, },
keybinding={ keybinding={
-- TODO -- TODO
@@ -174,10 +174,10 @@ local typedkeys={
local function validateKey(k,errlvl,...) local function validateKey(k,errlvl,...)
errlvl=(errlvl or 0)+1 errlvl=(errlvl or 0)+1
if type(k)~="string" then if type(k)~="string" then
err("["..tostring(k).."] - key is not a string", errlvl,...) err("["..tostring(k).."] - key is not a string", errlvl,unpack(arg))
end end
if strfind(k, "[%c\127]") then if strfind(k, "[%c\127]") then
err("["..tostring(k).."] - key name contained control characters", errlvl,...) err("["..tostring(k).."] - key name contained control characters", errlvl,unpack(arg))
end end
end end
@@ -186,11 +186,11 @@ local function validateVal(v, oktypes, errlvl,...)
local isok=oktypes[type(v)] or oktypes["*"] local isok=oktypes[type(v)] or oktypes["*"]
if not isok then if not isok then
err(": expected a "..oktypes._..", got '"..tostring(v).."'", errlvl,...) err(": expected a "..oktypes._..", got '"..tostring(v).."'", errlvl,unpack(arg))
end end
if type(isok)=="table" then -- isok was a table containing specific values to be tested for! if type(isok)=="table" then -- isok was a table containing specific values to be tested for!
if not isok[v] then if not isok[v] then
err(": did not expect "..type(v).." value '"..tostring(v).."'", errlvl,...) err(": did not expect "..type(v).." value '"..tostring(v).."'", errlvl,unpack(arg))
end end
end end
end end
@@ -199,47 +199,47 @@ local function validate(options,errlvl,...)
errlvl=(errlvl or 0)+1 errlvl=(errlvl or 0)+1
-- basic consistency -- basic consistency
if type(options)~="table" then if type(options)~="table" then
err(": expected a table, got a "..type(options), errlvl,...) err(": expected a table, got a "..type(options), errlvl,unpack(arg))
end end
if type(options.type)~="string" then if type(options.type)~="string" then
err(".type: expected a string, got a "..type(options.type), errlvl,...) err(".type: expected a string, got a "..type(options.type), errlvl,unpack(arg))
end end
-- get type and 'typedkeys' member -- get type and 'typedkeys' member
local tk = typedkeys[options.type] local tk = typedkeys[options.type]
if not tk then if not tk then
err(".type: unknown type '"..options.type.."'", errlvl,...) err(".type: unknown type '"..options.type.."'", errlvl,unpack(arg))
end end
-- make sure that all options[] are known parameters -- make sure that all options[] are known parameters
for k,v in pairs(options) do for k,v in pairs(options) do
if not (tk[k] or basekeys[k]) then if not (tk[k] or basekeys[k]) then
err(": unknown parameter", errlvl,tostring(k),...) err(": unknown parameter", errlvl,tostring(k),unpack(arg))
end end
end end
-- verify that required params are there, and that everything is the right type -- verify that required params are there, and that everything is the right type
for k,oktypes in pairs(basekeys) do for k,oktypes in pairs(basekeys) do
validateVal(options[k], oktypes, errlvl,k,...) validateVal(options[k], oktypes, errlvl,k,unpack(arg))
end end
for k,oktypes in pairs(tk) do for k,oktypes in pairs(tk) do
validateVal(options[k], oktypes, errlvl,k,...) validateVal(options[k], oktypes, errlvl,k,unpack(arg))
end end
-- extra logic for groups -- extra logic for groups
if options.type=="group" then if options.type=="group" then
for k,v in pairs(options.args) do for k,v in pairs(options.args) do
validateKey(k,errlvl,"args",...) validateKey(k,errlvl,"args",unpack(arg))
validate(v, errlvl,k,"args",...) validate(v, errlvl,k,"args",unpack(arg))
end end
if options.plugins then if options.plugins then
for plugname,plugin in pairs(options.plugins) do for plugname,plugin in pairs(options.plugins) do
if type(plugin)~="table" then if type(plugin)~="table" then
err(": expected a table, got '"..tostring(plugin).."'", errlvl,tostring(plugname),"plugins",...) err(": expected a table, got '"..tostring(plugin).."'", errlvl,tostring(plugname),"plugins",unpack(arg))
end end
for k,v in pairs(plugin) do for k,v in pairs(plugin) do
validateKey(k,errlvl,tostring(plugname),"plugins",...) validateKey(k,errlvl,tostring(plugname),"plugins",unpack(arg))
validate(v, errlvl,k,tostring(plugname),"plugins",...) validate(v, errlvl,k,tostring(plugname),"plugins",unpack(arg))
end end
end end
end end
@@ -6,6 +6,10 @@ local Media = LibStub("LibSharedMedia-3.0")
local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0") local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0")
local next, ipairs, pairs = next, ipairs, pairs
local upper = string.upper
local tinsert, tremove, sort = table.insert, table.remove, table.sort
do do
local widgetType = "LSM30_Background" local widgetType = "LSM30_Background"
local widgetVersion = 11 local widgetVersion = 11
@@ -15,10 +19,10 @@ do
self:ClearAllPoints() self:ClearAllPoints()
self:Hide() self:Hide()
self.check:Hide() self.check:Hide()
table.insert(contentFrameCache, self) tinsert(contentFrameCache, self)
end end
local function ContentOnClick(this, button) local function ContentOnClick()
local self = this.obj local self = this.obj
self:Fire("OnValueChanged", this.text:GetText()) self:Fire("OnValueChanged", this.text:GetText())
if self.dropdown then if self.dropdown then
@@ -26,7 +30,7 @@ do
end end
end end
local function ContentOnEnter(this, button) local function ContentOnEnter()
local self = this.obj local self = this.obj
local text = this.text:GetText() local text = this.text:GetText()
local background = self.list[text] ~= text and self.list[text] or Media:Fetch('background',text) local background = self.list[text] ~= text and self.list[text] or Media:Fetch('background',text)
@@ -36,7 +40,7 @@ do
local function GetContentLine() local function GetContentLine()
local frame local frame
if next(contentFrameCache) then if next(contentFrameCache) then
frame = table.remove(contentFrameCache) frame = tremove(contentFrameCache)
else else
frame = CreateFrame("Button", nil, UIParent) frame = CreateFrame("Button", nil, UIParent)
--frame:SetWidth(200) --frame:SetWidth(200)
@@ -140,7 +144,7 @@ do
end end
local function textSort(a,b) local function textSort(a,b)
return string.upper(a) < string.upper(b) return upper(a) < upper(b)
end end
local sortedlist = {} local sortedlist = {}
@@ -156,9 +160,9 @@ do
self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT") self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0) self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0)
for k, v in pairs(self.list) do for k, v in pairs(self.list) do
sortedlist[#sortedlist+1] = k tinsert(sortedlist, k)
end end
table.sort(sortedlist, textSort) sort(sortedlist, textSort)
for i, k in ipairs(sortedlist) do for i, k in ipairs(sortedlist) do
local f = GetContentLine() local f = GetContentLine()
f.text:SetText(k) f.text:SetText(k)
@@ -180,18 +184,18 @@ do
end end
end end
local function OnHide(this) local function OnHide()
local self = this.obj local self = this.obj
if self.dropdown then if self.dropdown then
self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown) self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
end end
end end
local function Drop_OnEnter(this) local function Drop_OnEnter()
this.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Drop_OnLeave(this) local function Drop_OnLeave()
this.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
@@ -6,6 +6,10 @@ local Media = LibStub("LibSharedMedia-3.0")
local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0") local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0")
local next, ipairs, pairs = next, ipairs, pairs
local upper = string.upper
local tinsert, tremove, sort = table.insert, table.remove, table.sort
do do
local widgetType = "LSM30_Border" local widgetType = "LSM30_Border"
local widgetVersion = 11 local widgetVersion = 11
@@ -15,7 +19,7 @@ do
self:ClearAllPoints() self:ClearAllPoints()
self:Hide() self:Hide()
self.check:Hide() self.check:Hide()
table.insert(contentFrameCache, self) tinsert(contentFrameCache, self)
end end
local function ContentOnClick(this, button) local function ContentOnClick(this, button)
@@ -39,7 +43,7 @@ do
local function GetContentLine() local function GetContentLine()
local frame local frame
if next(contentFrameCache) then if next(contentFrameCache) then
frame = table.remove(contentFrameCache) frame = tremove(contentFrameCache)
else else
frame = CreateFrame("Button", nil, UIParent) frame = CreateFrame("Button", nil, UIParent)
--frame:SetWidth(200) --frame:SetWidth(200)
@@ -135,7 +139,7 @@ do
end end
local function textSort(a,b) local function textSort(a,b)
return string.upper(a) < string.upper(b) return upper(a) < upper(b)
end end
local sortedlist = {} local sortedlist = {}
@@ -151,9 +155,9 @@ do
self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT") self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0) self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0)
for k, v in pairs(self.list) do for k, v in pairs(self.list) do
sortedlist[#sortedlist+1] = k tinsert(sortedlist, k)
end end
table.sort(sortedlist, textSort) sort(sortedlist, textSort)
for i, k in ipairs(sortedlist) do for i, k in ipairs(sortedlist) do
local f = GetContentLine() local f = GetContentLine()
f.text:SetText(k) f.text:SetText(k)
@@ -6,6 +6,10 @@ local Media = LibStub("LibSharedMedia-3.0")
local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0") local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0")
local next, ipairs, pairs = next, ipairs, pairs
local upper = string.upper
local tinsert, tremove, sort = table.insert, table.remove, table.sort
do do
local widgetType = "LSM30_Font" local widgetType = "LSM30_Font"
local widgetVersion = 11 local widgetVersion = 11
@@ -15,10 +19,10 @@ do
self:ClearAllPoints() self:ClearAllPoints()
self:Hide() self:Hide()
self.check:Hide() self.check:Hide()
table.insert(contentFrameCache, self) tinsert(contentFrameCache, self)
end end
local function ContentOnClick(this, button) local function ContentOnClick()
local self = this.obj local self = this.obj
self:Fire("OnValueChanged", this.text:GetText()) self:Fire("OnValueChanged", this.text:GetText())
if self.dropdown then if self.dropdown then
@@ -29,7 +33,7 @@ do
local function GetContentLine() local function GetContentLine()
local frame local frame
if next(contentFrameCache) then if next(contentFrameCache) then
frame = table.remove(contentFrameCache) frame = tremove(contentFrameCache)
else else
frame = CreateFrame("Button", nil, UIParent) frame = CreateFrame("Button", nil, UIParent)
--frame:SetWidth(200) --frame:SetWidth(200)
@@ -120,11 +124,11 @@ do
end end
local function textSort(a,b) local function textSort(a,b)
return string.upper(a) < string.upper(b) return upper(a) < upper(b)
end end
local sortedlist = {} local sortedlist = {}
local function ToggleDrop(this) local function ToggleDrop()
local self = this.obj local self = this.obj
if self.dropdown then if self.dropdown then
self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown) self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
@@ -136,9 +140,9 @@ do
self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT") self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0) self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0)
for k, v in pairs(self.list) do for k, v in pairs(self.list) do
sortedlist[#sortedlist+1] = k tinsert(sortedlist, k)
end end
table.sort(sortedlist, textSort) sort(sortedlist, textSort)
for i, k in ipairs(sortedlist) do for i, k in ipairs(sortedlist) do
local f = GetContentLine() local f = GetContentLine()
local _, size, outline= f.text:GetFont() local _, size, outline= f.text:GetFont()
@@ -161,18 +165,18 @@ do
end end
end end
local function OnHide(this) local function OnHide()
local self = this.obj local self = this.obj
if self.dropdown then if self.dropdown then
self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown) self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
end end
end end
local function Drop_OnEnter(this) local function Drop_OnEnter()
this.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Drop_OnLeave(this) local function Drop_OnLeave()
this.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
@@ -6,6 +6,10 @@ local Media = LibStub("LibSharedMedia-3.0")
local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0") local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0")
local next, ipairs, pairs = next, ipairs, pairs
local upper = string.upper
local tinsert, tremove, sort = table.insert, table.remove, table.sort
do do
local widgetType = "LSM30_Sound" local widgetType = "LSM30_Sound"
local widgetVersion = 11 local widgetVersion = 11
@@ -15,10 +19,10 @@ do
self:ClearAllPoints() self:ClearAllPoints()
self:Hide() self:Hide()
self.check:Hide() self.check:Hide()
table.insert(contentFrameCache, self) tinsert(contentFrameCache, self)
end end
local function ContentOnClick(this, button) local function ContentOnClick()
local self = this.obj local self = this.obj
self:Fire("OnValueChanged", this.text:GetText()) self:Fire("OnValueChanged", this.text:GetText())
if self.dropdown then if self.dropdown then
@@ -26,7 +30,7 @@ do
end end
end end
local function ContentSpeakerOnClick(this, button) local function ContentSpeakerOnClick()
local self = this.frame.obj local self = this.frame.obj
local sound = this.frame.text:GetText() local sound = this.frame.text:GetText()
PlaySoundFile(self.list[sound] ~= sound and self.list[sound] or Media:Fetch('sound',sound), "Master") PlaySoundFile(self.list[sound] ~= sound and self.list[sound] or Media:Fetch('sound',sound), "Master")
@@ -35,7 +39,7 @@ do
local function GetContentLine() local function GetContentLine()
local frame local frame
if next(contentFrameCache) then if next(contentFrameCache) then
frame = table.remove(contentFrameCache) frame = tremove(contentFrameCache)
else else
frame = CreateFrame("Button", nil, UIParent) frame = CreateFrame("Button", nil, UIParent)
--frame:SetWidth(200) --frame:SetWidth(200)
@@ -145,11 +149,11 @@ do
end end
local function textSort(a,b) local function textSort(a,b)
return string.upper(a) < string.upper(b) return upper(a) < upper(b)
end end
local sortedlist = {} local sortedlist = {}
local function ToggleDrop(this) local function ToggleDrop()
local self = this.obj local self = this.obj
if self.dropdown then if self.dropdown then
self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown) self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
@@ -161,9 +165,9 @@ do
self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT") self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0) self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0)
for k, v in pairs(self.list) do for k, v in pairs(self.list) do
sortedlist[#sortedlist+1] = k tinsert(sortedlist, k)
end end
table.sort(sortedlist, textSort) sort(sortedlist, textSort)
for i, k in ipairs(sortedlist) do for i, k in ipairs(sortedlist) do
local f = GetContentLine() local f = GetContentLine()
f.text:SetText(k) f.text:SetText(k)
@@ -183,22 +187,22 @@ do
end end
end end
local function OnHide(this) local function OnHide()
local self = this.obj local self = this.obj
if self.dropdown then if self.dropdown then
self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown) self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
end end
end end
local function Drop_OnEnter(this) local function Drop_OnEnter()
this.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Drop_OnLeave(this) local function Drop_OnLeave()
this.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
local function WidgetPlaySound(this) local function WidgetPlaySound()
local self = this.obj local self = this.obj
local sound = self.frame.text:GetText() local sound = self.frame.text:GetText()
PlaySoundFile(self.list[sound] ~= sound and self.list[sound] or Media:Fetch('sound',sound), "Master") PlaySoundFile(self.list[sound] ~= sound and self.list[sound] or Media:Fetch('sound',sound), "Master")
@@ -6,6 +6,10 @@ local Media = LibStub("LibSharedMedia-3.0")
local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0") local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0")
local next, ipairs, pairs = next, ipairs, pairs
local upper = string.upper
local tinsert, tremove, sort = table.insert, table.remove, table.sort
do do
local widgetType = "LSM30_Statusbar" local widgetType = "LSM30_Statusbar"
local widgetVersion = 11 local widgetVersion = 11
@@ -15,10 +19,10 @@ do
self:ClearAllPoints() self:ClearAllPoints()
self:Hide() self:Hide()
self.check:Hide() self.check:Hide()
table.insert(contentFrameCache, self) tinsert(contentFrameCache, self)
end end
local function ContentOnClick(this, button) local function ContentOnClick()
local self = this.obj local self = this.obj
self:Fire("OnValueChanged", this.text:GetText()) self:Fire("OnValueChanged", this.text:GetText())
if self.dropdown then if self.dropdown then
@@ -29,7 +33,7 @@ do
local function GetContentLine() local function GetContentLine()
local frame local frame
if next(contentFrameCache) then if next(contentFrameCache) then
frame = table.remove(contentFrameCache) frame = tremove(contentFrameCache)
else else
frame = CreateFrame("Button", nil, UIParent) frame = CreateFrame("Button", nil, UIParent)
--frame:SetWidth(200) --frame:SetWidth(200)
@@ -129,11 +133,11 @@ do
end end
local function textSort(a,b) local function textSort(a,b)
return string.upper(a) < string.upper(b) return upper(a) < upper(b)
end end
local sortedlist = {} local sortedlist = {}
local function ToggleDrop(this) local function ToggleDrop()
local self = this.obj local self = this.obj
if self.dropdown then if self.dropdown then
self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown) self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
@@ -145,9 +149,9 @@ do
self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT") self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0) self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0)
for k, v in pairs(self.list) do for k, v in pairs(self.list) do
sortedlist[#sortedlist+1] = k tinsert(sortedlist, k)
end end
table.sort(sortedlist, textSort) sort(sortedlist, textSort)
for i, k in ipairs(sortedlist) do for i, k in ipairs(sortedlist) do
local f = GetContentLine() local f = GetContentLine()
f.text:SetText(k) f.text:SetText(k)
@@ -172,18 +176,18 @@ do
end end
end end
local function OnHide(this) local function OnHide()
local self = this.obj local self = this.obj
if self.dropdown then if self.dropdown then
self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown) self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
end end
end end
local function Drop_OnEnter(this) local function Drop_OnEnter()
this.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Drop_OnLeave(this) local function Drop_OnLeave()
this.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
@@ -16,6 +16,11 @@ local Media = LibStub("LibSharedMedia-3.0")
AGSMW = AGSMW or {} AGSMW = AGSMW or {}
local next, ipairs = next, ipairs
local tinsert, tremove = table.insert, table.remove
local GetScreenHeight = GetScreenHeight
AceGUIWidgetLSMlists = { AceGUIWidgetLSMlists = {
['font'] = Media:HashTable("font"), ['font'] = Media:HashTable("font"),
['sound'] = Media:HashTable("sound"), ['sound'] = Media:HashTable("sound"),
@@ -156,8 +161,8 @@ do
insets = { left = 11, right = 12, top = 12, bottom = 9 }, insets = { left = 11, right = 12, top = 12, bottom = 9 },
} }
local function OnMouseWheel(self, dir) local function OnMouseWheel()
self.slider:SetValue(self.slider:GetValue()+(15*dir*-1)) this.slider:SetValue(this.slider:GetValue()+(15*arg1*-1))
end end
local function AddFrame(self, frame) local function AddFrame(self, frame)
@@ -166,20 +171,19 @@ do
frame:SetFrameLevel(self:GetFrameLevel() + 100) frame:SetFrameLevel(self:GetFrameLevel() + 100)
if next(self.contentRepo) then if next(self.contentRepo) then
frame:SetPoint("TOPLEFT", self.contentRepo[#self.contentRepo], "BOTTOMLEFT", 0, 0) frame:SetPoint("TOPLEFT", self.contentRepo[getn(self.contentRepo)], "BOTTOMLEFT", 0, 0)
frame:SetPoint("RIGHT", self.contentframe, "RIGHT", 0, 0) frame:SetPoint("RIGHT", self.contentframe, "RIGHT", 0, 0)
self.contentframe:SetHeight(self.contentframe:GetHeight() + frame:GetHeight()) self.contentframe:SetHeight(self.contentframe:GetHeight() + frame:GetHeight())
self.contentRepo[#self.contentRepo+1] = frame
else else
self.contentframe:SetHeight(frame:GetHeight()) self.contentframe:SetHeight(frame:GetHeight())
frame:SetPoint("TOPLEFT", self.contentframe, "TOPLEFT", 0, 0) frame:SetPoint("TOPLEFT", self.contentframe, "TOPLEFT", 0, 0)
frame:SetPoint("RIGHT", self.contentframe, "RIGHT", 0, 0) frame:SetPoint("RIGHT", self.contentframe, "RIGHT", 0, 0)
self.contentRepo[1] = frame
end end
tinsert(self.contentRepo, frame)
if self.contentframe:GetHeight() > UIParent:GetHeight()*2/5 - 20 then if self.contentframe:GetHeight() > GetScreenHeight()*2/5 - 20 then
self.scrollframe:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -28, 12) self.scrollframe:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -28, 12)
self:SetHeight(UIParent:GetHeight()*2/5) self:SetHeight(GetScreenHeight()*2/5)
self.slider:Show() self.slider:Show()
self:SetScript("OnMouseWheel", OnMouseWheel) self:SetScript("OnMouseWheel", OnMouseWheel)
self.scrollframe:UpdateScrollChildRect() self.scrollframe:UpdateScrollChildRect()
@@ -202,15 +206,15 @@ do
end end
end end
local function slider_OnValueChanged(self, value) local function slider_OnValueChanged()
self.frame.scrollframe:SetVerticalScroll(value) this.frame.scrollframe:SetVerticalScroll(arg1)
end end
local DropDownCache = {} local DropDownCache = {}
function AGSMW:GetDropDownFrame() function AGSMW:GetDropDownFrame()
local frame local frame
if next(DropDownCache) then if next(DropDownCache) then
frame = table.remove(DropDownCache) frame = tremove(DropDownCache)
else else
frame = CreateFrame("Frame", nil, UIParent) frame = CreateFrame("Frame", nil, UIParent)
frame:SetClampedToScreen(true) frame:SetClampedToScreen(true)
@@ -255,7 +259,7 @@ do
slider:SetScript("OnValueChanged", slider_OnValueChanged) slider:SetScript("OnValueChanged", slider_OnValueChanged)
frame.slider = slider frame.slider = slider
end end
frame:SetHeight(UIParent:GetHeight()*2/5) frame:SetHeight(GetScreenHeight()*2/5)
frame.slider:SetValue(0) frame.slider:SetValue(0)
frame:Show() frame:Show()
return frame return frame
@@ -267,7 +271,7 @@ do
frame:Hide() frame:Hide()
frame:SetBackdrop(frameBackdrop) frame:SetBackdrop(frameBackdrop)
frame.bgTex:SetTexture(nil) frame.bgTex:SetTexture(nil)
table.insert(DropDownCache, frame) tinsert(DropDownCache, frame)
return nil return nil
end end
end end
@@ -31,8 +31,9 @@ local AceGUI, oldminor = LibStub:NewLibrary(ACEGUI_MAJOR, ACEGUI_MINOR)
if not AceGUI then return end -- No upgrade needed if not AceGUI then return end -- No upgrade needed
-- Lua APIs -- Lua APIs
local tconcat, tremove, tinsert = table.concat, table.remove, table.insert local tconcat, tremove, tinsert, getn = table.concat, table.remove, table.insert, table.getn
local select, pairs, next, type = select, pairs, next, type local format, gsub, upper = string.format, string.gsub, string.upper
local pairs, next, type, unpack = pairs, next, type, unpack
local error, assert, loadstring = error, assert, loadstring local error, assert, loadstring = error, assert, loadstring
local setmetatable, rawget, rawset = setmetatable, rawget, rawset local setmetatable, rawget, rawset = setmetatable, rawget, rawset
local math_max = math.max local math_max = math.max
@@ -68,14 +69,14 @@ end
local function CreateDispatcher(argCount) local function CreateDispatcher(argCount)
local code = [[ local code = [[
local xpcall, eh = ... local xpcall, eh = xpcall, function(err) return geterrorhandler()(err) end
local method, ARGS local method, ARGS
local function call() return method(ARGS) end local function call() return method(ARGS) end
local function dispatch(func, ...) local function dispatch(func, ...)
method = func method = func
if not method then return end if not method then return end
ARGS = ... ARGS = unpack(arg)
return xpcall(call, eh) return xpcall(call, eh)
end end
@@ -84,7 +85,7 @@ local function CreateDispatcher(argCount)
local ARGS = {} local ARGS = {}
for i = 1, argCount do ARGS[i] = "arg"..i end for i = 1, argCount do ARGS[i] = "arg"..i end
code = code:gsub("ARGS", tconcat(ARGS, ", ")) code = gsub(code, "ARGS", tconcat(ARGS, ", "))
return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler) return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler)
end end
@@ -98,7 +99,7 @@ Dispatchers[0] = function(func)
end end
local function safecall(func, ...) local function safecall(func, ...)
return Dispatchers[select("#", ...)](func, ...) return Dispatchers[getn(arg)](func, unpack(arg))
end end
-- Recycling functions -- Recycling functions
@@ -158,6 +159,18 @@ do
end end
local function fixlevels(parent)
local child
local childList = {parent:GetChildren()}
local level = parent:GetFrameLevel() + 1
for i = 1, getn(childList) do
child = childList[i]
child:SetFrameLevel(level)
fixlevels(child)
end
end
------------------- -------------------
-- API Functions -- -- API Functions --
------------------- -------------------
@@ -189,7 +202,7 @@ function AceGUI:Create(type)
if widget.OnAcquire then if widget.OnAcquire then
widget:OnAcquire() widget:OnAcquire()
else else
error(("Widget type %s doesn't supply an OnAcquire Function"):format(type)) error(format("Widget type %s doesn't supply an OnAcquire Function", type))
end end
-- Set the default Layout ("List") -- Set the default Layout ("List")
safecall(widget.SetLayout, widget, "List") safecall(widget.SetLayout, widget, "List")
@@ -211,7 +224,7 @@ function AceGUI:Release(widget)
if widget.OnRelease then if widget.OnRelease then
widget:OnRelease() widget:OnRelease()
-- else -- else
-- error(("Widget type %s doesn't supply an OnRelease Function"):format(widget.type)) -- error(format("Widget type %s doesn't supply an OnRelease Function", widget.type))
end end
for k in pairs(widget.userdata) do for k in pairs(widget.userdata) do
widget.userdata[k] = nil widget.userdata[k] = nil
@@ -301,6 +314,7 @@ do
frame:SetParent(nil) frame:SetParent(nil)
frame:SetParent(parent.content) frame:SetParent(parent.content)
self.parent = parent self.parent = parent
fixlevels(frame)
end end
WidgetBase.SetCallback = function(self, name, func) WidgetBase.SetCallback = function(self, name, func)
@@ -311,7 +325,7 @@ do
WidgetBase.Fire = function(self, name, ...) WidgetBase.Fire = function(self, name, ...)
if self.events[name] then if self.events[name] then
local success, ret = safecall(self.events[name], self, name, ...) local success, ret = safecall(self.events[name], self, name, unpack(arg))
if success then if success then
return ret return ret
end end
@@ -363,7 +377,7 @@ do
end end
WidgetBase.SetPoint = function(self, ...) WidgetBase.SetPoint = function(self, ...)
return self.frame:SetPoint(...) return self.frame:SetPoint(unpack(arg))
end end
WidgetBase.ClearAllPoints = function(self) WidgetBase.ClearAllPoints = function(self)
@@ -375,7 +389,7 @@ do
end end
WidgetBase.GetPoint = function(self, ...) WidgetBase.GetPoint = function(self, ...)
return self.frame:GetPoint(...) return self.frame:GetPoint(unpack(arg))
end end
WidgetBase.GetUserDataTable = function(self) WidgetBase.GetUserDataTable = function(self)
@@ -463,8 +477,8 @@ do
end end
WidgetContainerBase.AddChildren = function(self, ...) WidgetContainerBase.AddChildren = function(self, ...)
for i = 1, select("#", ...) do for i = 1, getn(arg) do
local child = select(i, ...) local child = arg[i]
tinsert(self.children, child) tinsert(self.children, child)
child:SetParent(self) child:SetParent(self)
child.frame:Show() child.frame:Show()
@@ -474,9 +488,20 @@ do
WidgetContainerBase.ReleaseChildren = function(self) WidgetContainerBase.ReleaseChildren = function(self)
local children = self.children local children = self.children
for i = 1,#children do for i = 1,getn(children) do
AceGUI:Release(children[i]) AceGUI:Release(tremove(children))
children[i] = nil end
end
WidgetContainerBase.SetParent = function(self, parent)
WidgetBase.SetParent(self, parent)
local level = self.frame:GetFrameLevel()
self.content:SetFrameLevel(level + 1)
local children = self.children
for i = 1,getn(children) do
local child = children[i]
child:SetParent(self)
end end
end end
@@ -492,7 +517,7 @@ do
end end
end end
local function FrameResize(this) local function FrameResize()
local self = this.obj local self = this.obj
if this:GetWidth() and this:GetHeight() then if this:GetWidth() and this:GetHeight() then
if self.OnWidthSet then if self.OnWidthSet then
@@ -504,7 +529,7 @@ do
end end
end end
local function ContentResize(this) local function ContentResize()
if this:GetWidth() and this:GetHeight() then if this:GetWidth() and this:GetHeight() then
this.width = this:GetWidth() this.width = this:GetWidth()
this.height = this:GetHeight() this.height = this:GetHeight()
@@ -573,7 +598,7 @@ end
function AceGUI:RegisterLayout(Name, LayoutFunc) function AceGUI:RegisterLayout(Name, LayoutFunc)
assert(type(LayoutFunc) == "function") assert(type(LayoutFunc) == "function")
if type(Name) == "string" then if type(Name) == "string" then
Name = Name:upper() Name = upper(Name)
end end
LayoutRegistry[Name] = LayoutFunc LayoutRegistry[Name] = LayoutFunc
end end
@@ -582,7 +607,7 @@ end
-- @param Name The name of the layout -- @param Name The name of the layout
function AceGUI:GetLayout(Name) function AceGUI:GetLayout(Name)
if type(Name) == "string" then if type(Name) == "string" then
Name = Name:upper() Name = upper(Name)
end end
return LayoutRegistry[Name] return LayoutRegistry[Name]
end end
@@ -629,7 +654,7 @@ AceGUI:RegisterLayout("List",
function(content, children) function(content, children)
local height = 0 local height = 0
local width = content.width or content:GetWidth() or 0 local width = content.width or content:GetWidth() or 0
for i = 1, #children do for i = 1, getn(children) do
local child = children[i] local child = children[i]
local frame = child.frame local frame = child.frame
@@ -676,7 +701,7 @@ AceGUI:RegisterLayout("Fill",
local layoutrecursionblock = nil local layoutrecursionblock = nil
local function safelayoutcall(object, func, ...) local function safelayoutcall(object, func, ...)
layoutrecursionblock = true layoutrecursionblock = true
object[func](object, ...) object[func](object, unpack(arg))
layoutrecursionblock = nil layoutrecursionblock = nil
end end
@@ -703,7 +728,7 @@ AceGUI:RegisterLayout("Flow",
local frameoffset local frameoffset
local lastframeoffset local lastframeoffset
local oversize local oversize
for i = 1, #children do for i = 1, getn(children) do
local child = children[i] local child = children[i]
oversize = nil oversize = nil
local frame = child.frame local frame = child.frame
@@ -1,29 +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/ <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"> ..\FrameXML\UI.xsd">
<Script file="AceGUI-3.0.lua"/> <Script file="AceGUI-3.0.lua"/>
<!-- Container -->
<Script file="widgets\AceGUIContainer-BlizOptionsGroup.lua"/>
<Script file="widgets\AceGUIContainer-DropDownGroup.lua"/>
<Script file="widgets\AceGUIContainer-Frame.lua"/>
<Script file="widgets\AceGUIContainer-InlineGroup.lua"/>
<Script file="widgets\AceGUIContainer-ScrollFrame.lua"/>
<Script file="widgets\AceGUIContainer-SimpleGroup.lua"/>
<Script file="widgets\AceGUIContainer-TabGroup.lua"/>
<Script file="widgets\AceGUIContainer-TreeGroup.lua"/>
<Script file="widgets\AceGUIContainer-Window.lua"/>
<!-- Widgets -->
<Script file="widgets\AceGUIWidget-Button.lua"/>
<Script file="widgets\AceGUIWidget-Button-ElvUI.lua"/>
<Script file="widgets\AceGUIWidget-CheckBox.lua"/>
<Script file="widgets\AceGUIWidget-ColorPicker.lua"/>
<Script file="widgets\AceGUIWidget-DropDown.lua"/>
<Script file="widgets\AceGUIWidget-DropDown-Items.lua"/>
<Script file="widgets\AceGUIWidget-EditBox.lua"/>
<Script file="widgets\AceGUIWidget-Heading.lua"/>
<Script file="widgets\AceGUIWidget-Icon.lua"/>
<Script file="widgets\AceGUIWidget-InteractiveLabel.lua"/>
<Script file="widgets\AceGUIWidget-Keybinding.lua"/>
<Script file="widgets\AceGUIWidget-Label.lua"/>
<Script file="widgets\AceGUIWidget-MultiLineEditBox.lua"/>
<Script file="widgets\AceGUIWidget-Slider.lua"/>
</Ui> </Ui>
@@ -20,30 +20,30 @@ local CreateFrame, UIParent = CreateFrame, UIParent
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Button_OnClick(frame) local function Button_OnClick()
PlaySound("gsTitleOptionExit") PlaySound("gsTitleOptionExit")
frame.obj:Hide() this.obj:Hide()
end end
local function Frame_OnShow(frame) local function Frame_OnShow()
frame.obj:Fire("OnShow") this.obj:Fire("OnShow")
end end
local function Frame_OnClose(frame) local function Frame_OnClose()
frame.obj:Fire("OnClose") this.obj:Fire("OnClose")
end end
local function Frame_OnMouseDown(frame) local function Frame_OnMouseDown()
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function Title_OnMouseDown(frame) local function Title_OnMouseDown()
frame:GetParent():StartMoving() this:GetParent():StartMoving()
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function MoverSizer_OnMouseUp(mover) local function MoverSizer_OnMouseUp()
local frame = mover:GetParent() local frame = this:GetParent()
frame:StopMovingOrSizing() frame:StopMovingOrSizing()
local self = frame.obj local self = frame.obj
local status = self.status or self.localstatus local status = self.status or self.localstatus
@@ -53,27 +53,27 @@ local function MoverSizer_OnMouseUp(mover)
status.left = frame:GetLeft() status.left = frame:GetLeft()
end end
local function SizerSE_OnMouseDown(frame) local function SizerSE_OnMouseDown()
frame:GetParent():StartSizing("BOTTOMRIGHT") this:GetParent():StartSizing("BOTTOMRIGHT")
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function SizerS_OnMouseDown(frame) local function SizerS_OnMouseDown()
frame:GetParent():StartSizing("BOTTOM") this:GetParent():StartSizing("BOTTOM")
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function SizerE_OnMouseDown(frame) local function SizerE_OnMouseDown()
frame:GetParent():StartSizing("RIGHT") this:GetParent():StartSizing("RIGHT")
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function StatusBar_OnEnter(frame) local function StatusBar_OnEnter()
frame.obj:Fire("OnEnterStatusBar") this.obj:Fire("OnEnterStatusBar")
end end
local function StatusBar_OnLeave(frame) local function StatusBar_OnLeave()
frame.obj:Fire("OnLeaveStatusBar") this.obj:Fire("OnLeaveStatusBar")
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
@@ -156,7 +156,7 @@ local methods = {
frame:SetPoint("TOP", UIParent, "BOTTOM", 0, status.top) frame:SetPoint("TOP", UIParent, "BOTTOM", 0, status.top)
frame:SetPoint("LEFT", UIParent, "LEFT", status.left, 0) frame:SetPoint("LEFT", UIParent, "LEFT", status.left, 0)
else else
frame:SetPoint("CENTER") frame:SetPoint("CENTER", 0, 0)
end end
end end
} }
@@ -249,7 +249,7 @@ local function Constructor()
titlebg_r:SetHeight(40) titlebg_r:SetHeight(40)
local sizer_se = CreateFrame("Frame", nil, frame) local sizer_se = CreateFrame("Frame", nil, frame)
sizer_se:SetPoint("BOTTOMRIGHT") sizer_se:SetPoint("BOTTOMRIGHT", 0, 0)
sizer_se:SetWidth(25) sizer_se:SetWidth(25)
sizer_se:SetHeight(25) sizer_se:SetHeight(25)
sizer_se:EnableMouse() sizer_se:EnableMouse()
@@ -274,7 +274,7 @@ local function Constructor()
local sizer_s = CreateFrame("Frame", nil, frame) local sizer_s = CreateFrame("Frame", nil, frame)
sizer_s:SetPoint("BOTTOMRIGHT", -25, 0) sizer_s:SetPoint("BOTTOMRIGHT", -25, 0)
sizer_s:SetPoint("BOTTOMLEFT") sizer_s:SetPoint("BOTTOMLEFT", 0, 0)
sizer_s:SetHeight(25) sizer_s:SetHeight(25)
sizer_s:EnableMouse(true) sizer_s:EnableMouse(true)
sizer_s:SetScript("OnMouseDown", SizerS_OnMouseDown) sizer_s:SetScript("OnMouseDown", SizerS_OnMouseDown)
@@ -282,7 +282,7 @@ local function Constructor()
local sizer_e = CreateFrame("Frame", nil, frame) local sizer_e = CreateFrame("Frame", nil, frame)
sizer_e:SetPoint("BOTTOMRIGHT", 0, 25) sizer_e:SetPoint("BOTTOMRIGHT", 0, 25)
sizer_e:SetPoint("TOPRIGHT") sizer_e:SetPoint("TOPRIGHT", 0, 0)
sizer_e:SetWidth(25) sizer_e:SetWidth(25)
sizer_e:EnableMouse(true) sizer_e:EnableMouse(true)
sizer_e:SetScript("OnMouseDown", SizerE_OnMouseDown) sizer_e:SetScript("OnMouseDown", SizerE_OnMouseDown)
@@ -9,6 +9,7 @@ if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs -- Lua APIs
local pairs, assert, type = pairs, assert, type local pairs, assert, type = pairs, assert, type
local min, max, floor, abs = math.min, math.max, math.floor, math.abs local min, max, floor, abs = math.min, math.max, math.floor, math.abs
local format = string.format
-- WoW APIs -- WoW APIs
local CreateFrame, UIParent = CreateFrame, UIParent local CreateFrame, UIParent = CreateFrame, UIParent
@@ -16,24 +17,24 @@ local CreateFrame, UIParent = CreateFrame, UIParent
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Support functions Support functions
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function FixScrollOnUpdate(frame) local function FixScrollOnUpdate()
frame:SetScript("OnUpdate", nil) this:SetScript("OnUpdate", nil)
frame.obj:FixScroll() this.obj:FixScroll()
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function ScrollFrame_OnMouseWheel(frame, value) local function ScrollFrame_OnMouseWheel()
frame.obj:MoveScroll(value) this.obj:MoveScroll(arg1)
end end
local function ScrollFrame_OnSizeChanged(frame) local function ScrollFrame_OnSizeChanged()
frame:SetScript("OnUpdate", FixScrollOnUpdate) this:SetScript("OnUpdate", FixScrollOnUpdate)
end end
local function ScrollBar_OnScrollValueChanged(frame, value) local function ScrollBar_OnScrollValueChanged()
frame.obj:SetScroll(value) this.obj:SetScroll(arg1)
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
@@ -50,7 +51,7 @@ local methods = {
for k in pairs(self.localstatus) do for k in pairs(self.localstatus) do
self.localstatus[k] = nil self.localstatus[k] = nil
end end
self.scrollframe:SetPoint("BOTTOMRIGHT") self.scrollframe:SetPoint("BOTTOMRIGHT", 0, 0)
self.scrollbar:Hide() self.scrollbar:Hide()
self.scrollBarShown = nil self.scrollBarShown = nil
self.content.height, self.content.width = nil, nil self.content.height, self.content.width = nil, nil
@@ -102,7 +103,7 @@ local methods = {
self.scrollBarShown = nil self.scrollBarShown = nil
self.scrollbar:Hide() self.scrollbar:Hide()
self.scrollbar:SetValue(0) self.scrollbar:SetValue(0)
self.scrollframe:SetPoint("BOTTOMRIGHT") self.scrollframe:SetPoint("BOTTOMRIGHT", 0, 0)
self:DoLayout() self:DoLayout()
end end
else else
@@ -157,13 +158,13 @@ local function Constructor()
local num = AceGUI:GetNextWidgetNum(Type) local num = AceGUI:GetNextWidgetNum(Type)
local scrollframe = CreateFrame("ScrollFrame", nil, frame) local scrollframe = CreateFrame("ScrollFrame", nil, frame)
scrollframe:SetPoint("TOPLEFT") scrollframe:SetPoint("TOPLEFT", 0, 0)
scrollframe:SetPoint("BOTTOMRIGHT") scrollframe:SetPoint("BOTTOMRIGHT", 0, 0)
scrollframe:EnableMouseWheel(true) scrollframe:EnableMouseWheel(true)
scrollframe:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel) scrollframe:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel)
scrollframe:SetScript("OnSizeChanged", ScrollFrame_OnSizeChanged) scrollframe:SetScript("OnSizeChanged", ScrollFrame_OnSizeChanged)
local scrollbar = CreateFrame("Slider", ("AceConfigDialogScrollFrame%dScrollBar"):format(num), scrollframe, "UIPanelScrollBarTemplate") local scrollbar = CreateFrame("Slider", format("AceConfigDialogScrollFrame%dScrollBar", num), scrollframe, "UIPanelScrollBarTemplate")
scrollbar:SetPoint("TOPLEFT", scrollframe, "TOPRIGHT", 4, -16) scrollbar:SetPoint("TOPLEFT", scrollframe, "TOPRIGHT", 4, -16)
scrollbar:SetPoint("BOTTOMLEFT", scrollframe, "BOTTOMRIGHT", 4, 16) scrollbar:SetPoint("BOTTOMLEFT", scrollframe, "BOTTOMRIGHT", 4, 16)
scrollbar:SetMinMaxValues(0, 1000) scrollbar:SetMinMaxValues(0, 1000)
@@ -180,8 +181,8 @@ local function Constructor()
--Container Support --Container Support
local content = CreateFrame("Frame", nil, scrollframe) local content = CreateFrame("Frame", nil, scrollframe)
content:SetPoint("TOPLEFT") content:SetPoint("TOPLEFT", 0, 0)
content:SetPoint("TOPRIGHT") content:SetPoint("TOPRIGHT", 0, 0)
content:SetHeight(400) content:SetHeight(400)
scrollframe:SetScrollChild(content) scrollframe:SetScrollChild(content)
@@ -8,6 +8,8 @@ if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs -- Lua APIs
local pairs, ipairs, assert, type, wipe = pairs, ipairs, assert, type, wipe local pairs, ipairs, assert, type, wipe = pairs, ipairs, assert, type, wipe
local format = string.format
local getn = table.getn
-- WoW APIs -- WoW APIs
local PlaySound = PlaySound local PlaySound = PlaySound
@@ -52,34 +54,34 @@ local function Tab_SetDisabled(frame, disabled)
UpdateTabLook(frame) UpdateTabLook(frame)
end end
local function BuildTabsOnUpdate(frame) local function BuildTabsOnUpdate()
local self = frame.obj local self = this.obj
self:BuildTabs() self:BuildTabs()
frame:SetScript("OnUpdate", nil) this:SetScript("OnUpdate", nil)
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Tab_OnClick(frame) local function Tab_OnClick()
if not (frame.selected or frame.disabled) then if not (this.selected or this.disabled) then
PlaySound("igCharacterInfoTab") PlaySound("igCharacterInfoTab")
frame.obj:SelectTab(frame.value) this.obj:SelectTab(this.value)
end end
end end
local function Tab_OnEnter(frame) local function Tab_OnEnter()
local self = frame.obj local self = this.obj
self:Fire("OnTabEnter", self.tabs[frame.id].value, frame) self:Fire("OnTabEnter", self.tabs[this.id].value, this)
end end
local function Tab_OnLeave(frame) local function Tab_OnLeave()
local self = frame.obj local self = this.obj
self:Fire("OnTabLeave", self.tabs[frame.id].value, frame) self:Fire("OnTabLeave", self.tabs[this.id].value, this)
end end
local function Tab_OnShow(frame) local function Tab_OnShow()
_G[frame:GetName().."HighlightTexture"]:SetWidth(frame:GetTextWidth() + 30) _G[this:GetName().."HighlightTexture"]:SetWidth(this:GetTextWidth() + 30)
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
@@ -102,10 +104,32 @@ local methods = {
end, end,
["CreateTab"] = function(self, id) ["CreateTab"] = function(self, id)
local tabname = ("AceGUITabGroup%dTab%d"):format(self.num, id) local tabname = format("AceGUITabGroup%dTab%d", self.num, id)
local tab = CreateFrame("Button", tabname, self.border, "OptionsFrameTabButtonTemplate") local tab = CreateFrame("Button", tabname, self.border, "TabButtonTemplate")
tab.obj = self tab.obj = self
tab.id = id tab.id = id
tab:SetHeight(24)
-- Normal texture
local texture = _G[tabname.."Left"]
texture:ClearAllPoints()
texture:SetPoint("BOTTOMLEFT", tab,"BOTTOMLEFT")
texture:SetPoint("TOPLEFT", tab,"TOPLEFT")
texture:SetTexture("Interface\\ChatFrame\\ChatFrameTab")
texture = _G[tabname.."Middle"]
texture:SetTexture("Interface\\ChatFrame\\ChatFrameTab")
texture = _G[tabname.."Right"]
texture:SetTexture("Interface\\ChatFrame\\ChatFrameTab")
-- Disabled texture
texture = _G[tabname.."LeftDisabled"]
texture:ClearAllPoints()
texture:SetPoint("BOTTOMLEFT", tab,"BOTTOMLEFT")
texture:SetPoint("TOPLEFT", tab,"TOPLEFT")
texture:SetTexture("Interface\\ChatFrame\\ChatFrameTab")
texture = _G[tabname.."MiddleDisabled"]
texture:SetTexture("Interface\\ChatFrame\\ChatFrameTab")
texture = _G[tabname.."RightDisabled"]
texture:SetTexture("Interface\\ChatFrame\\ChatFrameTab")
tab.text = _G[tabname .. "Text"] tab.text = _G[tabname .. "Text"]
tab.text:ClearAllPoints() tab.text:ClearAllPoints()
@@ -186,23 +210,28 @@ local methods = {
end end
tab:Show() tab:Show()
tab:SetText(v.text) if type(v) == "table" then
tab:SetDisabled(v.disabled) tab:SetText(v.text)
tab.value = v.value tab:SetDisabled(v.disabled)
tab.value = v.value
elseif type(v) == "string" then
tab:SetText(v)
tab.value = v
end
widths[i] = tab:GetWidth() - 6 --tabs are anchored 10 pixels from the right side of the previous one to reduce spacing, but add a fixed 4px padding for the text widths[i] = tab:GetWidth() - 6 --tabs are anchored 10 pixels from the right side of the previous one to reduce spacing, but add a fixed 4px padding for the text
end end
for i = (#tablist)+1, #tabs, 1 do for i = getn(tablist)+1, getn(tabs), 1 do
tabs[i]:Hide() tabs[i]:Hide()
end end
--First pass, find the minimum number of rows needed to hold all tabs and the initial tab layout --First pass, find the minimum number of rows needed to hold all tabs and the initial tab layout
local numtabs = #tablist local numtabs = getn(tablist)
local numrows = 1 local numrows = 1
local usedwidth = 0 local usedwidth = 0
for i = 1, #tablist do for i = 1, numtabs do
--If this is not the first tab of a row and there isn't room for it --If this is not the first tab of a row and there isn't room for it
if usedwidth ~= 0 and (width - usedwidth - widths[i]) < 0 then if usedwidth ~= 0 and (width - usedwidth - widths[i]) < 0 then
rowwidths[numrows] = usedwidth + 10 --first tab in each row takes up an extra 10px rowwidths[numrows] = usedwidth + 10 --first tab in each row takes up an extra 10px
@@ -213,7 +242,7 @@ local methods = {
usedwidth = usedwidth + widths[i] usedwidth = usedwidth + widths[i]
end end
rowwidths[numrows] = usedwidth + 10 --first tab in each row takes up an extra 10px rowwidths[numrows] = usedwidth + 10 --first tab in each row takes up an extra 10px
rowends[numrows] = #tablist rowends[numrows] = numtabs
--Fix for single tabs being left on the last row, move a tab from the row above if applicable --Fix for single tabs being left on the last row, move a tab from the row above if applicable
if numrows > 1 then if numrows > 1 then
@@ -9,7 +9,8 @@ if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs -- Lua APIs
local next, pairs, ipairs, assert, type = next, pairs, ipairs, assert, type local next, pairs, ipairs, assert, type = next, pairs, ipairs, assert, type
local math_min, math_max, floor = math.min, math.max, floor local math_min, math_max, floor = math.min, math.max, floor
local select, tremove, unpack, tconcat = select, table.remove, unpack, table.concat local tremove, unpack, tconcat, getn = table.remove, unpack, table.concat, getn
local format, split = string.format, string.split
-- WoW APIs -- WoW APIs
local CreateFrame, UIParent = CreateFrame, UIParent local CreateFrame, UIParent = CreateFrame, UIParent
@@ -80,11 +81,11 @@ local function UpdateButton(button, treeline, selected, canExpand, isExpanded)
local line = button.line local line = button.line
button.level = level button.level = level
if ( level == 1 ) then if ( level == 1 ) then
button:SetTextFontObject("GameFontNormal") button.text:SetFontObject("GameFontNormal")
button:SetHighlightFontObject("GameFontHighlight") button:SetHighlightFontObject("GameFontHighlight")
button.text:SetPoint("LEFT", (icon and 16 or 0) + 8, 2) button.text:SetPoint("LEFT", (icon and 16 or 0) + 8, 2)
else else
button:SetTextFontObject("GameFontHighlightSmall") button.text:SetFontObject("GameFontHighlightSmall")
button:SetHighlightFontObject("GameFontHighlightSmall") button:SetHighlightFontObject("GameFontHighlightSmall")
button.text:SetPoint("LEFT", (icon and 16 or 0) + 8 * level, 2) button.text:SetPoint("LEFT", (icon and 16 or 0) + 8 * level, 2)
end end
@@ -154,120 +155,115 @@ local function addLine(self, v, tree, level, parent)
else else
line.hasChildren = nil line.hasChildren = nil
end end
self.lines[#self.lines+1] = line tinsert(self.lines, line)
return line return line
end end
--fire an update after one frame to catch the treeframes height --fire an update after one frame to catch the treeframes height
local function FirstFrameUpdate(frame) local function FirstFrameUpdate()
local self = frame.obj local self = this.obj
frame:SetScript("OnUpdate", nil) this:SetScript("OnUpdate", nil)
self:RefreshTree() self:RefreshTree()
end end
local function BuildUniqueValue(...) local function BuildUniqueValue(...)
local n = select('#', ...) return tconcat(arg, "\001", 1, getn(arg))
if n == 1 then
return ...
else
return (...).."\001"..BuildUniqueValue(select(2,...))
end
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Expand_OnClick(frame) local function Expand_OnClick()
local button = frame.button local button = this.button
local self = button.obj local self = button.obj
local status = (self.status or self.localstatus).groups local status = (self.status or self.localstatus).groups
status[button.uniquevalue] = not status[button.uniquevalue] status[button.uniquevalue] = not status[button.uniquevalue]
self:RefreshTree() self:RefreshTree()
end end
local function Button_OnClick(frame) local function Button_OnClick()
local self = frame.obj local self = this.obj
self:Fire("OnClick", frame.uniquevalue, frame.selected) self:Fire("OnClick", this.uniquevalue, this.selected)
if not frame.selected then if not this.selected then
self:SetSelected(frame.uniquevalue) self:SetSelected(this.uniquevalue)
frame.selected = true this.selected = true
frame:LockHighlight() this:LockHighlight()
self:RefreshTree() self:RefreshTree()
end end
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function Button_OnDoubleClick(button) local function Button_OnDoubleClick()
local self = button.obj local self = this.obj
local status = self.status or self.localstatus local status = self.status or self.localstatus
local status = (self.status or self.localstatus).groups local status = (self.status or self.localstatus).groups
status[button.uniquevalue] = not status[button.uniquevalue] status[this.uniquevalue] = not status[this.uniquevalue]
self:RefreshTree() self:RefreshTree()
end end
local function Button_OnEnter(frame) local function Button_OnEnter()
local self = frame.obj local self = this.obj
self:Fire("OnButtonEnter", frame.uniquevalue, frame) self:Fire("OnButtonEnter", this.uniquevalue, this)
if self.enabletooltips then if self.enabletooltips then
GameTooltip:SetOwner(frame, "ANCHOR_NONE") GameTooltip:SetOwner(this, "ANCHOR_NONE")
GameTooltip:SetPoint("LEFT",frame,"RIGHT") GameTooltip:SetPoint("LEFT",this,"RIGHT")
GameTooltip:SetText(frame.text:GetText() or "", 1, .82, 0, 1) GameTooltip:SetText(this.text:GetText() or "", 1, .82, 0, 1)
GameTooltip:Show() GameTooltip:Show()
end end
end end
local function Button_OnLeave(frame) local function Button_OnLeave()
local self = frame.obj local self = this.obj
self:Fire("OnButtonLeave", frame.uniquevalue, frame) self:Fire("OnButtonLeave", this.uniquevalue, this)
if self.enabletooltips then if self.enabletooltips then
GameTooltip:Hide() GameTooltip:Hide()
end end
end end
local function OnScrollValueChanged(frame, value) local function OnScrollValueChanged()
if frame.obj.noupdate then return end if this.obj.noupdate then return end
local self = frame.obj local self = this.obj
local status = self.status or self.localstatus local status = self.status or self.localstatus
status.scrollvalue = value status.scrollvalue = arg1
self:RefreshTree() self:RefreshTree()
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function Tree_OnSizeChanged(frame) local function Tree_OnSizeChanged()
frame.obj:RefreshTree() this.obj:RefreshTree()
end end
local function Tree_OnMouseWheel(frame, delta) local function Tree_OnMouseWheel()
local self = frame.obj local self = this.obj
if self.showscroll then if self.showscroll then
local scrollbar = self.scrollbar local scrollbar = self.scrollbar
local min, max = scrollbar:GetMinMaxValues() local min, max = scrollbar:GetMinMaxValues()
local value = scrollbar:GetValue() local value = scrollbar:GetValue()
local newvalue = math_min(max,math_max(min,value - delta)) local newvalue = math_min(max,math_max(min,value - arg1))
if value ~= newvalue then if value ~= newvalue then
scrollbar:SetValue(newvalue) scrollbar:SetValue(newvalue)
end end
end end
end end
local function Dragger_OnLeave(frame) local function Dragger_OnLeave()
frame:SetBackdropColor(1, 1, 1, 0) this:SetBackdropColor(1, 1, 1, 0)
end end
local function Dragger_OnEnter(frame) local function Dragger_OnEnter()
frame:SetBackdropColor(1, 1, 1, 0.8) this:SetBackdropColor(1, 1, 1, 0.8)
end end
local function Dragger_OnMouseDown(frame) local function Dragger_OnMouseDown()
local treeframe = frame:GetParent() local treeframe = this:GetParent()
treeframe:StartSizing("RIGHT") treeframe:StartSizing("RIGHT")
end end
local function Dragger_OnMouseUp(frame) local function Dragger_OnMouseUp()
local treeframe = frame:GetParent() local treeframe = this:GetParent()
local self = treeframe.obj local self = treeframe.obj
local frame = treeframe:GetParent() local frame = treeframe:GetParent()
treeframe:StopMovingOrSizing() treeframe:StopMovingOrSizing()
@@ -319,9 +315,39 @@ local methods = {
["CreateButton"] = function(self) ["CreateButton"] = function(self)
local num = AceGUI:GetNextWidgetNum("TreeGroupButton") local num = AceGUI:GetNextWidgetNum("TreeGroupButton")
local button = CreateFrame("Button", ("AceGUI30TreeButton%d"):format(num), self.treeframe, "InterfaceOptionsButtonTemplate") local button = CreateFrame("Button", format("AceGUI30TreeButton%d", num), self.treeframe)
button.obj = self button.obj = self
button:SetWidth(175)
button:SetHeight(18)
local toggle = CreateFrame("Button", nil, button)
toggle:SetWidth(14)
toggle:SetHeight(14)
toggle:ClearAllPoints()
toggle:SetPoint("TOPRIGHT", button, "TOPRIGHT", -6, -1)
toggle:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-UP")
toggle:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-DOWN")
toggle:SetHighlightTexture("Interface\Buttons\UI-PlusButton-Hilight", "ADD")
toggle:SetScript("OnClick", Button_OnClick)
button.toggle = toggle
toggle.obj = button
local text = button:CreateFontString()
text:SetFontObject(GameFontNormal)
text:SetPoint("RIGHT", toggle, "LEFT", -2, 0)
text:SetJustifyH("LEFT")
button:SetHighlightFontObject(GameFontHighlight)
button.text = text
local highlight = button:CreateTexture(nil, "HIGHLIGHT")
highlight:SetPoint("TOPLEFT", 0, 1)
highlight:SetPoint("BOTTOMRIGHT", 0, 1)
highlight:SetTexture("Interface\\QuestFrame\\UI-QuestLogTitleHighlight")
highlight:SetBlendMode("ADD")
highlight:SetVertexColor(.196, .388, .8)
button.highlight = highlight
local icon = button:CreateTexture(nil, "OVERLAY") local icon = button:CreateTexture(nil, "OVERLAY")
icon:SetWidth(14) icon:SetWidth(14)
icon:SetHeight(14) icon:SetHeight(14)
@@ -414,7 +440,7 @@ local methods = {
self:BuildLevel(tree, 1) self:BuildLevel(tree, 1)
local numlines = #lines local numlines = getn(lines)
local maxlines = (floor(((self.treeframe:GetHeight()or 0) - 20 ) / 18)) local maxlines = (floor(((self.treeframe:GetHeight()or 0) - 20 ) / 18))
if maxlines <= 0 then return end if maxlines <= 0 then return end
@@ -511,9 +537,8 @@ local methods = {
self.filter = false self.filter = false
local status = self.status or self.localstatus local status = self.status or self.localstatus
local groups = status.groups local groups = status.groups
local path = {...} for i = 1, getn(arg) do
for i = 1, #path do groups[tconcat(arg, "\001", 1, i)] = true
groups[tconcat(path, "\001", 1, i)] = true
end end
status.selected = uniquevalue status.selected = uniquevalue
self:RefreshTree(true) self:RefreshTree(true)
@@ -521,11 +546,11 @@ local methods = {
end, end,
["SelectByPath"] = function(self, ...) ["SelectByPath"] = function(self, ...)
self:Select(BuildUniqueValue(...), ...) self:Select(BuildUniqueValue(unpack(arg)), unpack(arg))
end, end,
["SelectByValue"] = function(self, uniquevalue) ["SelectByValue"] = function(self, uniquevalue)
self:Select(uniquevalue, ("\001"):split(uniquevalue)) self:Select(uniquevalue, split("\001", uniquevalue))
end, end,
["ShowScroll"] = function(self, show) ["ShowScroll"] = function(self, show)
@@ -632,8 +657,8 @@ local function Constructor()
local frame = CreateFrame("Frame", nil, UIParent) local frame = CreateFrame("Frame", nil, UIParent)
local treeframe = CreateFrame("Frame", nil, frame) local treeframe = CreateFrame("Frame", nil, frame)
treeframe:SetPoint("TOPLEFT") treeframe:SetPoint("TOPLEFT", 0, 0)
treeframe:SetPoint("BOTTOMLEFT") treeframe:SetPoint("BOTTOMLEFT", 0, 0)
treeframe:SetWidth(DEFAULT_TREE_WIDTH) treeframe:SetWidth(DEFAULT_TREE_WIDTH)
treeframe:EnableMouseWheel(true) treeframe:EnableMouseWheel(true)
treeframe:SetBackdrop(PaneBackdrop) treeframe:SetBackdrop(PaneBackdrop)
@@ -657,7 +682,7 @@ local function Constructor()
dragger:SetScript("OnMouseDown", Dragger_OnMouseDown) dragger:SetScript("OnMouseDown", Dragger_OnMouseDown)
dragger:SetScript("OnMouseUp", Dragger_OnMouseUp) dragger:SetScript("OnMouseUp", Dragger_OnMouseUp)
local scrollbar = CreateFrame("Slider", ("AceConfigDialogTreeGroup%dScrollBar"):format(num), treeframe, "UIPanelScrollBarTemplate") local scrollbar = CreateFrame("Slider", format("AceConfigDialogTreeGroup%dScrollBar", num), treeframe, "UIPanelScrollBarTemplate")
scrollbar:SetScript("OnValueChanged", nil) scrollbar:SetScript("OnValueChanged", nil)
scrollbar:SetPoint("TOPRIGHT", -10, -26) scrollbar:SetPoint("TOPRIGHT", -10, -26)
scrollbar:SetPoint("BOTTOMRIGHT", -10, 26) scrollbar:SetPoint("BOTTOMRIGHT", -10, 26)
@@ -673,7 +698,7 @@ local function Constructor()
local border = CreateFrame("Frame",nil,frame) local border = CreateFrame("Frame",nil,frame)
border:SetPoint("TOPLEFT", treeframe, "TOPRIGHT") border:SetPoint("TOPLEFT", treeframe, "TOPRIGHT")
border:SetPoint("BOTTOMRIGHT") border:SetPoint("BOTTOMRIGHT", 0, 0)
border:SetBackdrop(PaneBackdrop) border:SetBackdrop(PaneBackdrop)
border:SetBackdropColor(0.1, 0.1, 0.1, 0.5) border:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
border:SetBackdropBorderColor(0.4, 0.4, 0.4) border:SetBackdropBorderColor(0.4, 0.4, 0.4)
@@ -23,29 +23,29 @@ do
local Type = "Window" local Type = "Window"
local Version = 5 local Version = 5
local function frameOnShow(this) local function frameOnShow()
this.obj:Fire("OnShow") this.obj:Fire("OnShow")
end end
local function frameOnClose(this) local function frameOnClose()
this.obj:Fire("OnClose") this.obj:Fire("OnClose")
end end
local function closeOnClick(this) local function closeOnClick()
PlaySound("gsTitleOptionExit") PlaySound("gsTitleOptionExit")
this.obj:Hide() this.obj:Hide()
end end
local function frameOnMouseDown(this) local function frameOnMouseDown()
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function titleOnMouseDown(this) local function titleOnMouseDown()
this:GetParent():StartMoving() this:GetParent():StartMoving()
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function frameOnMouseUp(this) local function frameOnMouseUp()
local frame = this:GetParent() local frame = this:GetParent()
frame:StopMovingOrSizing() frame:StopMovingOrSizing()
local self = frame.obj local self = frame.obj
@@ -56,22 +56,22 @@ do
status.left = frame:GetLeft() status.left = frame:GetLeft()
end end
local function sizerseOnMouseDown(this) local function sizerseOnMouseDown()
this:GetParent():StartSizing("BOTTOMRIGHT") this:GetParent():StartSizing("BOTTOMRIGHT")
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function sizersOnMouseDown(this) local function sizersOnMouseDown()
this:GetParent():StartSizing("BOTTOM") this:GetParent():StartSizing("BOTTOM")
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function sizereOnMouseDown(this) local function sizereOnMouseDown()
this:GetParent():StartSizing("RIGHT") this:GetParent():StartSizing("RIGHT")
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function sizerOnMouseUp(this) local function sizerOnMouseUp()
this:GetParent():StopMovingOrSizing() this:GetParent():StopMovingOrSizing()
end end
@@ -2,32 +2,92 @@
Button Widget (Modified to change text color on SetDisabled method) Button Widget (Modified to change text color on SetDisabled method)
Graphical Button. Graphical Button.
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local Type, Version = "Button-ElvUI", 23 local Type, Version = "Button-ElvUI", 2
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs -- Lua APIs
local pairs = pairs local pairs, unpack = pairs, unpack
-- WoW APIs -- WoW APIs
local _G = _G local _G = _G
local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent
local IsShiftKeyDown = IsShiftKeyDown
-- GLOBALS: GameTooltip, ElvUI
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Button_OnClick(frame, ...) local dragdropButton
local function lockTooltip()
GameTooltip:SetOwner(UIParent, "ANCHOR_CURSOR")
GameTooltip:SetText(" ")
GameTooltip:Show()
end
local function dragdrop_OnMouseDown(...)
if this.obj.dragOnMouseDown then
dragdropButton.mouseDownFrame = this
dragdropButton:SetText(this.obj.value or "Unknown")
dragdropButton:SetWidth(this:GetWidth())
dragdropButton:SetHeight(this:SetHeight())
this.obj.dragOnMouseDown(this, unpack(arg))
end
end
local function dragdrop_OnMouseUp(...)
if this.obj.dragOnMouseUp then
this:SetAlpha(1)
GameTooltip:Hide()
dragdropButton:Hide()
if dragdropButton.enteredFrame and dragdropButton.enteredFrame ~= this and dragdropButton.enteredFrame:IsMouseOver() then
this.obj.dragOnMouseUp(this, unpack(arg))
this.obj.ActivateMultiControl(this.obj, unpack(arg))
end
dragdropButton.enteredFrame = nil
dragdropButton.mouseDownFrame = nil
end
end
local function dragdrop_OnLeave(...)
if this.obj.dragOnLeave then
if dragdropButton.mouseDownFrame then
lockTooltip()
end
if this == dragdropButton.mouseDownFrame then
this:SetAlpha(0)
dragdropButton:Show()
this.obj.dragOnLeave(this, unpack(arg))
end
end
end
local function dragdrop_OnEnter(...)
if this.obj.dragOnEnter and dragdropButton:IsShown() then
dragdropButton.enteredFrame = this
lockTooltip()
this.obj.dragOnEnter(this, unpack(arg))
end
end
local function dragdrop_OnClick()
local button = arg1
if this.obj.dragOnClick and button == "RightButton" then
this.obj.dragOnClick(this, button)
this.obj.ActivateMultiControl(this.obj, button)
elseif this.obj.stateSwitchOnClick and (button == "LeftButton") and IsShiftKeyDown() then
this.obj.stateSwitchOnClick(this, button)
this.obj.ActivateMultiControl(this.obj, button)
end
end
local function Button_OnClick()
AceGUI:ClearFocus() AceGUI:ClearFocus()
PlaySound("igMainMenuOption") PlaySound("igMainMenuOption")
frame.obj:Fire("OnClick", ...) this.obj:Fire("OnClick", 2, arg1)
end end
local function Control_OnEnter(frame) local function Control_OnEnter()
frame.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Control_OnLeave(frame) local function Control_OnLeave()
frame.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
@@ -76,14 +136,28 @@ Constructor
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Constructor() local function Constructor()
local name = "AceGUI30Button" .. AceGUI:GetNextWidgetNum(Type) local name = "AceGUI30Button" .. AceGUI:GetNextWidgetNum(Type)
local frame = CreateFrame("Button", name, UIParent, "UIPanelButtonTemplate2") local frame = CreateFrame("Button", name, UIParent, "UIPanelButtonTemplate")
frame:Hide() frame:Hide()
frame:EnableMouse(true) frame:EnableMouse(true)
frame:SetScript("OnClick", Button_OnClick) frame:SetScript("OnClick", Button_OnClick)
frame:SetScript("OnEnter", Control_OnEnter) frame:SetScript("OnEnter", Control_OnEnter)
frame:SetScript("OnLeave", Control_OnLeave) frame:SetScript("OnLeave", Control_OnLeave)
-- dragdrop
if not dragdropButton then
dragdropButton = CreateFrame("Button", "ElvUIAceGUI30DragDropButton", UIParent, "UIPanelButtonTemplate")
dragdropButton:SetFrameStrata("TOOLTIP")
dragdropButton:SetFrameLevel(5)
dragdropButton:SetPoint('BOTTOM', GameTooltip, "BOTTOM", 0, 10)
dragdropButton:Hide()
ElvUI[1]:GetModule('Skins'):HandleButton(dragdropButton)
end
HookScript(frame, "OnClick", dragdrop_OnClick)
HookScript(frame, "OnEnter", dragdrop_OnEnter)
HookScript(frame, "OnLeave", dragdrop_OnLeave)
HookScript(frame, "OnMouseUp", dragdrop_OnMouseUp)
HookScript(frame, "OnMouseDown", dragdrop_OnMouseDown)
local text = frame:GetFontString() local text = frame:GetFontString()
text:ClearAllPoints() text:ClearAllPoints()
text:SetPoint("TOPLEFT", 15, -1) text:SetPoint("TOPLEFT", 15, -1)
@@ -16,18 +16,18 @@ local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Button_OnClick(frame, ...) local function Button_OnClick()
AceGUI:ClearFocus() AceGUI:ClearFocus()
PlaySound("igMainMenuOption") PlaySound("igMainMenuOption")
frame.obj:Fire("OnClick", ...) this.obj:Fire("OnClick", arg1)
end end
local function Control_OnEnter(frame) local function Control_OnEnter()
frame.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Control_OnLeave(frame) local function Control_OnLeave()
frame.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
@@ -6,7 +6,9 @@ local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs -- Lua APIs
local select, pairs = select, pairs local pairs = pairs
local unpack = unpack
local getn = table.getn
-- WoW APIs -- WoW APIs
local PlaySound = PlaySound local PlaySound = PlaySound
@@ -24,26 +26,26 @@ local function AlignImage(self)
self.text:ClearAllPoints() self.text:ClearAllPoints()
if not img then if not img then
self.text:SetPoint("LEFT", self.checkbg, "RIGHT") self.text:SetPoint("LEFT", self.checkbg, "RIGHT")
self.text:SetPoint("RIGHT") self.text:SetPoint("RIGHT", 0, 0)
else else
self.text:SetPoint("LEFT", self.image,"RIGHT", 1, 0) self.text:SetPoint("LEFT", self.image,"RIGHT", 1, 0)
self.text:SetPoint("RIGHT") self.text:SetPoint("RIGHT", 0, 0)
end end
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Control_OnEnter(frame) local function Control_OnEnter()
frame.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Control_OnLeave(frame) local function Control_OnLeave()
frame.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
local function CheckBox_OnMouseDown(frame) local function CheckBox_OnMouseDown()
local self = frame.obj local self = this.obj
if not self.disabled then if not self.disabled then
if self.image:GetTexture() then if self.image:GetTexture() then
self.text:SetPoint("LEFT", self.image,"RIGHT", 2, -1) self.text:SetPoint("LEFT", self.image,"RIGHT", 2, -1)
@@ -54,8 +56,8 @@ local function CheckBox_OnMouseDown(frame)
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function CheckBox_OnMouseUp(frame) local function CheckBox_OnMouseUp()
local self = frame.obj local self = this.obj
if not self.disabled then if not self.disabled then
self:ToggleChecked() self:ToggleChecked()
@@ -226,9 +228,9 @@ local methods = {
image:SetTexture(path) image:SetTexture(path)
if image:GetTexture() then if image:GetTexture() then
local n = select("#", ...) local n = getn(arg)
if n == 4 or n == 8 then if n == 4 or n == 8 then
image:SetTexCoord(...) image:SetTexCoord(unpack(arg))
else else
image:SetTexCoord(0, 1, 0, 1) image:SetTexCoord(0, 1, 0, 1)
end end
@@ -253,7 +255,7 @@ local function Constructor()
local checkbg = frame:CreateTexture(nil, "ARTWORK") local checkbg = frame:CreateTexture(nil, "ARTWORK")
checkbg:SetWidth(24) checkbg:SetWidth(24)
checkbg:SetHeight(24) checkbg:SetHeight(24)
checkbg:SetPoint("TOPLEFT") checkbg:SetPoint("TOPLEFT", 0, 0)
checkbg:SetTexture("Interface\\Buttons\\UI-CheckBox-Up") checkbg:SetTexture("Interface\\Buttons\\UI-CheckBox-Up")
local check = frame:CreateTexture(nil, "OVERLAY") local check = frame:CreateTexture(nil, "OVERLAY")
@@ -264,7 +266,7 @@ local function Constructor()
text:SetJustifyH("LEFT") text:SetJustifyH("LEFT")
text:SetHeight(18) text:SetHeight(18)
text:SetPoint("LEFT", checkbg, "RIGHT") text:SetPoint("LEFT", checkbg, "RIGHT")
text:SetPoint("RIGHT") text:SetPoint("RIGHT", 0, 0)
local highlight = frame:CreateTexture(nil, "HIGHLIGHT") local highlight = frame:CreateTexture(nil, "HIGHLIGHT")
highlight:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight") highlight:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight")
@@ -1,7 +1,7 @@
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
ColorPicker Widget ColorPicker Widget
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local Type, Version = "ColorPicker-ElvUI", 22 local Type, Version = "ColorPicker", 22
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
@@ -38,20 +38,20 @@ end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Control_OnEnter(frame) local function Control_OnEnter()
frame.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Control_OnLeave(frame) local function Control_OnLeave()
frame.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
local function ColorSwatch_OnClick(frame) local function ColorSwatch_OnClick()
HideUIPanel(ColorPickerFrame) HideUIPanel(ColorPickerFrame)
local self = frame.obj local self = this.obj
if not self.disabled then if not self.disabled then
ColorPickerFrame:SetFrameStrata("FULLSCREEN_DIALOG") ColorPickerFrame:SetFrameStrata("FULLSCREEN_DIALOG")
ColorPickerFrame:SetFrameLevel(frame:GetFrameLevel() + 10) ColorPickerFrame:SetFrameLevel(this:GetFrameLevel() + 10)
ColorPickerFrame:SetClampedToScreen(true) ColorPickerFrame:SetClampedToScreen(true)
ColorPickerFrame.func = function() ColorPickerFrame.func = function()
@@ -67,20 +67,12 @@ local function ColorSwatch_OnClick(frame)
ColorCallback(self, r, g, b, a, true) ColorCallback(self, r, g, b, a, true)
end end
local r, g, b, a, dR, dG, dB, dA = self.r, self.g, self.b, self.a, self.dR, self.dG, self.dB, self.dA local r, g, b, a = self.r, self.g, self.b, self.a
if self.HasAlpha then if self.HasAlpha then
ColorPickerFrame.opacity = 1 - (a or 0) ColorPickerFrame.opacity = 1 - (a or 0)
end end
ColorPickerFrame:SetColorRGB(r, g, b) ColorPickerFrame:SetColorRGB(r, g, b)
if(ColorPPDefault and self.dR and self.dG and self.dB) then
local alpha = 1
if(self.dA) then
alpha = 1 - self.dA
end
ColorPPDefault.colors = {r = self.dR, g = self.dG, b = self.dB, a = alpha}
end
ColorPickerFrame.cancelFunc = function() ColorPickerFrame.cancelFunc = function()
ColorCallback(self, r, g, b, a, true) ColorCallback(self, r, g, b, a, true)
end end
@@ -109,15 +101,11 @@ local methods = {
self.text:SetText(text) self.text:SetText(text)
end, end,
["SetColor"] = function(self, r, g, b, a, defaultR, defaultG, defaultB, defaultA) ["SetColor"] = function(self, r, g, b, a)
self.r = r self.r = r
self.g = g self.g = g
self.b = b self.b = b
self.a = a or 1 self.a = a or 1
self.dR = defaultR
self.dG = defaultG
self.dB = defaultB
self.dA = defaultA
self.colorSwatch:SetVertexColor(r, g, b, a) self.colorSwatch:SetVertexColor(r, g, b, a)
end, end,
@@ -153,7 +141,7 @@ local function Constructor()
colorSwatch:SetWidth(19) colorSwatch:SetWidth(19)
colorSwatch:SetHeight(19) colorSwatch:SetHeight(19)
colorSwatch:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch") colorSwatch:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch")
colorSwatch:SetPoint("LEFT") colorSwatch:SetPoint("LEFT", 0, 0)
local texture = frame:CreateTexture(nil, "BACKGROUND") local texture = frame:CreateTexture(nil, "BACKGROUND")
texture:SetWidth(16) texture:SetWidth(16)
@@ -177,7 +165,7 @@ local function Constructor()
text:SetJustifyH("LEFT") text:SetJustifyH("LEFT")
text:SetTextColor(1, 1, 1) text:SetTextColor(1, 1, 1)
text:SetPoint("LEFT", colorSwatch, "RIGHT", 2, 0) text:SetPoint("LEFT", colorSwatch, "RIGHT", 2, 0)
text:SetPoint("RIGHT") text:SetPoint("RIGHT", 0, 0)
--local highlight = frame:CreateTexture(nil, "HIGHLIGHT") --local highlight = frame:CreateTexture(nil, "HIGHLIGHT")
--highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") --highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
@@ -3,31 +3,31 @@
local AceGUI = LibStub("AceGUI-3.0") local AceGUI = LibStub("AceGUI-3.0")
-- Lua APIs -- Lua APIs
local select, assert = select, assert local assert, unpack = assert, unpack
local getn = table.getn
-- WoW APIs -- WoW APIs
local PlaySound = PlaySound local PlaySound = PlaySound
local CreateFrame = CreateFrame local CreateFrame = CreateFrame
local function fixlevels(parent,...) local function fixlevels(parent, ...)
local i = 1 local child
local child = select(i, ...) local level = parent:GetFrameLevel() + 1
while child do
child:SetFrameLevel(parent:GetFrameLevel()+1) for i = 1, getn(arg) do
fixlevels(child, child:GetChildren()) child = arg[i]
i = i + 1 child:SetFrameLevel(level)
child = select(i, ...) fixlevels(child)
end end
end end
local function fixstrata(strata, parent, ...) local function fixstrata(strata, parent, ...)
local i = 1 local child
local child = select(i, ...)
parent:SetFrameStrata(strata) parent:SetFrameStrata(strata)
while child do
fixstrata(strata, child, child:GetChildren()) for i = 1, getn(arg) do
i = i + 1 child = arg[i]
child = select(i, ...) fixstrata(strata, child)
end end
end end
@@ -45,7 +45,7 @@ local ItemBase = {
counter = 0, counter = 0,
} }
function ItemBase.Frame_OnEnter(this) function ItemBase.Frame_OnEnter()
local self = this.obj local self = this.obj
if self.useHighlight then if self.useHighlight then
@@ -58,7 +58,7 @@ function ItemBase.Frame_OnEnter(this)
end end
end end
function ItemBase.Frame_OnLeave(this) function ItemBase.Frame_OnLeave()
local self = this.obj local self = this.obj
self.highlight:Hide() self.highlight:Hide()
@@ -108,7 +108,7 @@ end
-- exported -- exported
function ItemBase.SetPoint(self, ...) function ItemBase.SetPoint(self, ...)
self.frame:SetPoint(...) self.frame:SetPoint(unpack(arg))
end end
-- exported -- exported
@@ -248,7 +248,7 @@ do
local widgetType = "Dropdown-Item-Header" local widgetType = "Dropdown-Item-Header"
local widgetVersion = 1 local widgetVersion = 1
local function OnEnter(this) local function OnEnter()
local self = this.obj local self = this.obj
self:Fire("OnEnter") self:Fire("OnEnter")
@@ -257,7 +257,7 @@ do
end end
end end
local function OnLeave(this) local function OnLeave()
local self = this.obj local self = this.obj
self:Fire("OnLeave") self:Fire("OnLeave")
@@ -297,7 +297,7 @@ do
local widgetType = "Dropdown-Item-Execute" local widgetType = "Dropdown-Item-Execute"
local widgetVersion = 1 local widgetVersion = 1
local function Frame_OnClick(this, button) local function Frame_OnClick()
local self = this.obj local self = this.obj
if self.disabled then return end if self.disabled then return end
self:Fire("OnClick") self:Fire("OnClick")
@@ -338,7 +338,7 @@ do
self:SetValue(nil) self:SetValue(nil)
end end
local function Frame_OnClick(this, button) local function Frame_OnClick()
local self = this.obj local self = this.obj
if self.disabled then return end if self.disabled then return end
self.value = not self.value self.value = not self.value
@@ -385,7 +385,7 @@ do
local widgetType = "Dropdown-Item-Menu" local widgetType = "Dropdown-Item-Menu"
local widgetVersion = 2 local widgetVersion = 2
local function OnEnter(this) local function OnEnter()
local self = this.obj local self = this.obj
self:Fire("OnEnter") self:Fire("OnEnter")
@@ -400,7 +400,7 @@ do
end end
end end
local function OnHide(this) local function OnHide()
local self = this.obj local self = this.obj
if self.submenu then if self.submenu then
self.submenu:Close() self.submenu:Close()
@@ -3,8 +3,9 @@ local AceGUI = LibStub("AceGUI-3.0")
-- Lua APIs -- Lua APIs
local min, max, floor = math.min, math.max, math.floor local min, max, floor = math.min, math.max, math.floor
local select, pairs, ipairs, type = select, pairs, ipairs, type local pairs, ipairs, type = pairs, ipairs, type
local tsort = table.sort local tsort, tinsert, getn, setn = table.sort, table.insert, table.getn, table.setn
local format = string.format
-- WoW APIs -- WoW APIs
local PlaySound = PlaySound local PlaySound = PlaySound
@@ -15,25 +16,24 @@ local _G = _G
-- List them here for Mikk's FindGlobals script -- List them here for Mikk's FindGlobals script
-- GLOBALS: CLOSE -- GLOBALS: CLOSE
local function fixlevels(parent,...) local function fixlevels(parent, ...)
local i = 1 local child
local child = select(i, ...) local level = parent:GetFrameLevel() + 1
while child do
child:SetFrameLevel(parent:GetFrameLevel()+1) for i = 1, getn(arg) do
fixlevels(child, child:GetChildren()) child = arg[i]
i = i + 1 child:SetFrameLevel(level)
child = select(i, ...) fixlevels(child)
end end
end end
local function fixstrata(strata, parent, ...) local function fixstrata(strata, parent, ...)
local i = 1 local child
local child = select(i, ...)
parent:SetFrameStrata(strata) parent:SetFrameStrata(strata)
while child do
fixstrata(strata, child, child:GetChildren()) for i = 1, getn(arg) do
i = i + 1 child = arg[i]
child = select(i, ...) fixstrata(strata, child)
end end
end end
@@ -76,15 +76,15 @@ do
end end
-- See the note in Constructor() for each scroll related function -- See the note in Constructor() for each scroll related function
local function OnMouseWheel(this, value) local function OnMouseWheel()
this.obj:MoveScroll(value) this.obj:MoveScroll(arg1)
end end
local function OnScrollValueChanged(this, value) local function OnScrollValueChanged()
this.obj:SetScroll(value) this.obj:SetScroll(arg1)
end end
local function OnSizeChanged(this) local function OnSizeChanged()
this.obj:FixScroll() this.obj:FixScroll()
end end
@@ -169,9 +169,9 @@ do
-- exported -- exported
local function AddItem(self, item) local function AddItem(self, item)
self.items[#self.items + 1] = item tinsert(self.items, item)
local h = #self.items * 16 local h = getn(self.items) * 16
self.itemFrame:SetHeight(h) self.itemFrame:SetHeight(h)
self.frame:SetHeight(min(h + 34, self.maxHeight)) -- +34: 20 for scrollFrame placement (10 offset) and +14 for item placement self.frame:SetHeight(min(h + 34, self.maxHeight)) -- +34: 20 for scrollFrame placement (10 offset) and +14 for item placement
@@ -222,6 +222,7 @@ do
AceGUI:Release(item) AceGUI:Release(item)
items[i] = nil items[i] = nil
end end
setn(items, 0)
end end
-- exported -- exported
@@ -362,24 +363,24 @@ do
--[[ UI event handler ]]-- --[[ UI event handler ]]--
local function Control_OnEnter(this) local function Control_OnEnter()
this.obj.button:LockHighlight() this.obj.button:LockHighlight()
this.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Control_OnLeave(this) local function Control_OnLeave()
this.obj.button:UnlockHighlight() this.obj.button:UnlockHighlight()
this.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
local function Dropdown_OnHide(this) local function Dropdown_OnHide()
local self = this.obj local self = this.obj
if self.open then if self.open then
self.pullout:Close() self.pullout:Close()
end end
end end
local function Dropdown_TogglePullout(this) local function Dropdown_TogglePullout()
local self = this.obj local self = this.obj
PlaySound("igMainMenuOptionCheckBoxOn") -- missleading name, but the Blizzard code uses this sound PlaySound("igMainMenuOptionCheckBoxOn") -- missleading name, but the Blizzard code uses this sound
if self.open then if self.open then
@@ -571,7 +572,7 @@ do
local function AddListItem(self, value, text, itemType) local function AddListItem(self, value, text, itemType)
if not itemType then itemType = "Dropdown-Item-Toggle" end if not itemType then itemType = "Dropdown-Item-Toggle" end
local exists = AceGUI:GetWidgetVersion(itemType) local exists = AceGUI:GetWidgetVersion(itemType)
if not exists then error(("The given item type, %q, does not exist within AceGUI-3.0"):format(tostring(itemType)), 2) end if not exists then error(format("The given item type, %q, does not exist within AceGUI-3.0", tostring(itemType)), 2) end
local item = AceGUI:Create(itemType) local item = AceGUI:Create(itemType)
item:SetText(text) item:SetText(text)
@@ -600,7 +601,7 @@ do
if type(order) ~= "table" then if type(order) ~= "table" then
for v in pairs(list) do for v in pairs(list) do
sortlist[#sortlist + 1] = v tinsert(sortlist, v)
end end
tsort(sortlist) tsort(sortlist)
@@ -608,6 +609,7 @@ do
AddListItem(self, key, list[key], itemType) AddListItem(self, key, list[key], itemType)
sortlist[i] = nil sortlist[i] = nil
end end
setn(sortlist, 0)
else else
for i, key in ipairs(order) do for i, key in ipairs(order) do
AddListItem(self, key, list[key], itemType) AddListItem(self, key, list[key], itemType)
@@ -10,7 +10,7 @@ local tostring, pairs = tostring, pairs
-- WoW APIs -- WoW APIs
local PlaySound = PlaySound local PlaySound = PlaySound
local GetCursorInfo, ClearCursor, GetSpellInfo = GetCursorInfo, ClearCursor, GetSpellInfo local GetCursorInfo, ClearCursor, GetSpellName = GetCursorInfo, ClearCursor, GetSpellName
local CreateFrame, UIParent = CreateFrame, UIParent local CreateFrame, UIParent = CreateFrame, UIParent
local _G = _G local _G = _G
@@ -23,13 +23,12 @@ Support functions
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
if not AceGUIEditBoxInsertLink then if not AceGUIEditBoxInsertLink then
-- upgradeable hook -- upgradeable hook
hooksecurefunc("ChatEdit_InsertLink", function(...) return _G.AceGUIEditBoxInsertLink(...) end)
end end
function _G.AceGUIEditBoxInsertLink(text) function _G.AceGUIEditBoxInsertLink(text)
for i = 1, AceGUI:GetWidgetCount(Type) do for i = 1, AceGUI:GetWidgetCount(Type) do
local editbox = _G["AceGUI-3.0EditBox"..i] local editbox = _G["AceGUI-3.0EditBox"..i]
if editbox and editbox:IsVisible() and editbox:HasFocus() then if editbox and editbox:IsVisible() and editbox.hasfocus then
editbox:Insert(text) editbox:Insert(text)
return true return true
end end
@@ -51,26 +50,26 @@ end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Control_OnEnter(frame) local function Control_OnEnter()
frame.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Control_OnLeave(frame) local function Control_OnLeave()
frame.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
local function Frame_OnShowFocus(frame) local function Frame_OnShowFocus()
frame.obj.editbox:SetFocus() this.obj.editbox:SetFocus()
frame:SetScript("OnShow", nil) this:SetScript("OnShow", nil)
end end
local function EditBox_OnEscapePressed(frame) local function EditBox_OnEscapePressed()
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function EditBox_OnEnterPressed(frame) local function EditBox_OnEnterPressed()
local self = frame.obj local self = this.obj
local value = frame:GetText() local value = this:GetText()
local cancel = self:Fire("OnEnterPressed", value) local cancel = self:Fire("OnEnterPressed", value)
if not cancel then if not cancel then
PlaySound("igMainMenuOptionCheckBoxOn") PlaySound("igMainMenuOptionCheckBoxOn")
@@ -78,15 +77,20 @@ local function EditBox_OnEnterPressed(frame)
end end
end end
local function EditBox_OnReceiveDrag(frame) local function EditBox_OnReceiveDrag()
local self = frame.obj if not GetCursorInfo then print("TODO GetCursorInfo") return end -- TODO
local self = this.obj
local type, id, info = GetCursorInfo() local type, id, info = GetCursorInfo()
if type == "item" then if type == "item" then
self:SetText(info) self:SetText(info)
self:Fire("OnEnterPressed", info) self:Fire("OnEnterPressed", info)
ClearCursor() ClearCursor()
elseif type == "spell" then elseif type == "spell" then
local name = GetSpellInfo(id, info) local name, rank = GetSpellName(id, info)
if rank ~= "" then
name = name.."("..rank..")"
end
self:SetText(name) self:SetText(name)
self:Fire("OnEnterPressed", name) self:Fire("OnEnterPressed", name)
ClearCursor() ClearCursor()
@@ -100,9 +104,9 @@ local function EditBox_OnReceiveDrag(frame)
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function EditBox_OnTextChanged(frame) local function EditBox_OnTextChanged()
local self = frame.obj local self = this.obj
local value = frame:GetText() local value = this:GetText()
if tostring(value) ~= tostring(self.lasttext) then if tostring(value) ~= tostring(self.lasttext) then
self:Fire("OnTextChanged", value) self:Fire("OnTextChanged", value)
self.lasttext = value self.lasttext = value
@@ -110,14 +114,20 @@ local function EditBox_OnTextChanged(frame)
end end
end end
local function EditBox_OnFocusGained(frame) local function EditBox_OnFocusGained()
AceGUI:SetFocus(frame.obj) this.hasfocus = true
AceGUI:SetFocus(this.obj)
end end
local function Button_OnClick(frame) local function EditBox_OnFocusLost()
local editbox = frame.obj.editbox this.hasfocus = nil
end
local function Button_OnClick()
local editbox = this.obj.editbox
editbox:ClearFocus() editbox:ClearFocus()
EditBox_OnEnterPressed(editbox) this = editbox
EditBox_OnEnterPressed()
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
@@ -155,7 +165,7 @@ local methods = {
["SetText"] = function(self, text) ["SetText"] = function(self, text)
self.lasttext = text or "" self.lasttext = text or ""
self.editbox:SetText(text or "") self.editbox:SetText(text or "")
self.editbox:SetCursorPosition(0) EditBoxSetCursorPosition(self.editbox, 0)
HideButton(self) HideButton(self)
end, end,
@@ -226,10 +236,11 @@ local function Constructor()
editbox:SetScript("OnReceiveDrag", EditBox_OnReceiveDrag) editbox:SetScript("OnReceiveDrag", EditBox_OnReceiveDrag)
editbox:SetScript("OnMouseDown", EditBox_OnReceiveDrag) editbox:SetScript("OnMouseDown", EditBox_OnReceiveDrag)
editbox:SetScript("OnEditFocusGained", EditBox_OnFocusGained) editbox:SetScript("OnEditFocusGained", EditBox_OnFocusGained)
editbox:SetScript("OnEditFocusLost", EditBox_OnFocusLost)
editbox:SetTextInsets(0, 0, 3, 3) editbox:SetTextInsets(0, 0, 3, 3)
editbox:SetMaxLetters(256) editbox:SetMaxLetters(256)
editbox:SetPoint("BOTTOMLEFT", 6, 0) editbox:SetPoint("BOTTOMLEFT", 6, 0)
editbox:SetPoint("BOTTOMRIGHT") editbox:SetPoint("BOTTOMRIGHT", 0, 0)
editbox:SetHeight(19) editbox:SetHeight(19)
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
@@ -43,8 +43,8 @@ local function Constructor()
frame:Hide() frame:Hide()
local label = frame:CreateFontString(nil, "BACKGROUND", "GameFontNormal") local label = frame:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
label:SetPoint("TOP") label:SetPoint("TOP", 0, 0)
label:SetPoint("BOTTOM") label:SetPoint("BOTTOM", 0, 0)
label:SetJustifyH("CENTER") label:SetJustifyH("CENTER")
local left = frame:CreateTexture(nil, "BACKGROUND") local left = frame:CreateTexture(nil, "BACKGROUND")
@@ -6,7 +6,8 @@ local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs -- Lua APIs
local select, pairs, print = select, pairs, print local pairs, print, unpack = pairs, print, unpack
local getn = table.getn
-- WoW APIs -- WoW APIs
local CreateFrame, UIParent = CreateFrame, UIParent local CreateFrame, UIParent = CreateFrame, UIParent
@@ -14,16 +15,16 @@ local CreateFrame, UIParent = CreateFrame, UIParent
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Control_OnEnter(frame) local function Control_OnEnter()
frame.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Control_OnLeave(frame) local function Control_OnLeave()
frame.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
local function Button_OnClick(frame, button) local function Button_OnClick()
frame.obj:Fire("OnClick", button) this.obj:Fire("OnClick", arg1)
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
@@ -58,9 +59,9 @@ local methods = {
image:SetTexture(path) image:SetTexture(path)
if image:GetTexture() then if image:GetTexture() then
local n = select("#", ...) local n = getn(arg)
if n == 4 or n == 8 then if n == 4 or n == 8 then
image:SetTexCoord(...) image:SetTexCoord(unpack(arg))
else else
image:SetTexCoord(0, 1, 0, 1) image:SetTexCoord(0, 1, 0, 1)
end end
@@ -6,7 +6,8 @@ local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs -- Lua APIs
local select, pairs = select, pairs local pairs, unpack = pairs, unpack
local getn = table.getn
-- WoW APIs -- WoW APIs
local CreateFrame, UIParent = CreateFrame, UIParent local CreateFrame, UIParent = CreateFrame, UIParent
@@ -18,16 +19,16 @@ local CreateFrame, UIParent = CreateFrame, UIParent
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Control_OnEnter(frame) local function Control_OnEnter()
frame.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Control_OnLeave(frame) local function Control_OnLeave()
frame.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
local function Label_OnClick(frame, button) local function Label_OnClick()
frame.obj:Fire("OnClick", button) this.obj:Fire("OnClick", arg1)
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
@@ -45,13 +46,13 @@ local methods = {
-- ["OnRelease"] = nil, -- ["OnRelease"] = nil,
["SetHighlight"] = function(self, ...) ["SetHighlight"] = function(self, ...)
self.highlight:SetTexture(...) self.highlight:SetTexture(unpack(arg))
end, end,
["SetHighlightTexCoord"] = function(self, ...) ["SetHighlightTexCoord"] = function(self, ...)
local c = select("#", ...) local c = getn(arg)
if c == 4 or c == 8 then if c == 4 or c == 8 then
self.highlight:SetTexCoord(...) self.highlight:SetTexCoord(unpack(arg))
else else
self.highlight:SetTexCoord(0, 1, 0, 1) self.highlight:SetTexCoord(0, 1, 0, 1)
end end
@@ -21,33 +21,35 @@ local CreateFrame, UIParent = CreateFrame, UIParent
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Control_OnEnter(frame) local function Control_OnEnter()
frame.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Control_OnLeave(frame) local function Control_OnLeave()
frame.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
local function Keybinding_OnClick(frame, button) --[[
if button == "LeftButton" or button == "RightButton" then local function Keybinding_OnClick()
local self = frame.obj if arg1 == "LeftButton" or arg1 == "RightButton" then
local self = this.obj
if self.waitingForKey then if self.waitingForKey then
frame:EnableKeyboard(false) this:EnableKeyboard(false)
frame:EnableMouseWheel(false) this:EnableMouseWheel(false)
self.msgframe:Hide() self.msgframe:Hide()
frame:UnlockHighlight() this:UnlockHighlight()
self.waitingForKey = nil self.waitingForKey = nil
else else
frame:EnableKeyboard(true) this:EnableKeyboard(true)
frame:EnableMouseWheel(true) this:EnableMouseWheel(true)
self.msgframe:Show() self.msgframe:Show()
frame:LockHighlight() this:LockHighlight()
self.waitingForKey = true self.waitingForKey = true
end end
end end
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
]]
local ignoreKeys = { local ignoreKeys = {
["BUTTON1"] = true, ["BUTTON2"] = true, ["BUTTON1"] = true, ["BUTTON2"] = true,
@@ -55,10 +57,10 @@ local ignoreKeys = {
["LSHIFT"] = true, ["LCTRL"] = true, ["LALT"] = true, ["LSHIFT"] = true, ["LCTRL"] = true, ["LALT"] = true,
["RSHIFT"] = true, ["RCTRL"] = true, ["RALT"] = true, ["RSHIFT"] = true, ["RCTRL"] = true, ["RALT"] = true,
} }
local function Keybinding_OnKeyDown(frame, key) local function Keybinding_OnKeyDown()
local self = frame.obj local self = this.obj
if self.waitingForKey then if self.waitingForKey then
local keyPressed = key local keyPressed = arg1
if keyPressed == "ESCAPE" then if keyPressed == "ESCAPE" then
keyPressed = "" keyPressed = ""
else else
@@ -74,10 +76,10 @@ local function Keybinding_OnKeyDown(frame, key)
end end
end end
frame:EnableKeyboard(false) this:EnableKeyboard(false)
frame:EnableMouseWheel(false) this:EnableMouseWheel(false)
self.msgframe:Hide() self.msgframe:Hide()
frame:UnlockHighlight() this:UnlockHighlight()
self.waitingForKey = nil self.waitingForKey = nil
if not self.disabled then if not self.disabled then
@@ -87,27 +89,49 @@ local function Keybinding_OnKeyDown(frame, key)
end end
end end
local function Keybinding_OnMouseDown(frame, button) local function Keybinding_OnMouseUp()
if button == "LeftButton" or button == "RightButton" then if MouseIsOver(this) and not self.disabled then
return local self = this.obj
elseif button == "MiddleButton" then if self.waitingForKey then
button = "BUTTON3" if arg1 ~= "LeftButton" and arg1 ~= "RightButton" then
elseif button == "Button4" then Keybinding_OnKeyDown()
button = "BUTTON4" end
elseif button == "Button5" then this:EnableKeyboard(false)
button = "BUTTON5" this:EnableMouseWheel(false)
self.msgframe:Hide()
this:UnlockHighlight()
self.waitingForKey = nil
else
this:EnableKeyboard(true)
this:EnableMouseWheel(true)
self.msgframe:Show()
this:LockHighlight()
self.waitingForKey = true
end
end end
Keybinding_OnKeyDown(frame, button) AceGUI:ClearFocus()
end end
local function Keybinding_OnMouseWheel(frame, direction) local function Keybinding_OnMouseDown()
local button if arg1 == "LeftButton" or arg1 == "RightButton" then
if direction >= 0 then return
button = "MOUSEWHEELUP" elseif arg1 == "MiddleButton" then
else arg1 = "BUTTON3"
button = "MOUSEWHEELDOWN" elseif arg1 == "Button4" then
arg1 = "BUTTON4"
elseif arg1 == "Button5" then
arg1 = "BUTTON5"
end end
Keybinding_OnKeyDown(frame, button) Keybinding_OnKeyDown()
end
local function Keybinding_OnMouseWheel()
if arg1 >= 0 then
arg1 = "MOUSEWHEELUP"
else
arg1 = "MOUSEWHEELDOWN"
end
Keybinding_OnKeyDown()
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
@@ -141,10 +165,10 @@ local methods = {
["SetKey"] = function(self, key) ["SetKey"] = function(self, key)
if (key or "") == "" then if (key or "") == "" then
self.button:SetText(NOT_BOUND) self.button:SetText(NOT_BOUND)
self.button:SetNormalFontObject("GameFontNormal") self.text:SetFontObject("GameFontNormal")
else else
self.button:SetText(key) self.button:SetText(key)
self.button:SetNormalFontObject("GameFontHighlight") self.text:SetFontObject("GameFontHighlight")
end end
end, end,
@@ -179,9 +203,9 @@ local ControlBackdrop = {
insets = { left = 3, right = 3, top = 3, bottom = 3 } insets = { left = 3, right = 3, top = 3, bottom = 3 }
} }
local function keybindingMsgFixWidth(frame) local function keybindingMsgFixWidth()
frame:SetWidth(frame.msg:GetWidth() + 10) this:SetWidth(this.msg:GetWidth() + 10)
frame:SetScript("OnUpdate", nil) this:SetScript("OnUpdate", nil)
end end
local function Constructor() local function Constructor()
@@ -195,12 +219,13 @@ local function Constructor()
button:RegisterForClicks("AnyDown") button:RegisterForClicks("AnyDown")
button:SetScript("OnEnter", Control_OnEnter) button:SetScript("OnEnter", Control_OnEnter)
button:SetScript("OnLeave", Control_OnLeave) button:SetScript("OnLeave", Control_OnLeave)
button:SetScript("OnClick", Keybinding_OnClick) -- button:SetScript("OnClick", Keybinding_OnClick)
button:SetScript("OnMouseUp", Keybinding_OnMouseUp)
button:SetScript("OnKeyDown", Keybinding_OnKeyDown) button:SetScript("OnKeyDown", Keybinding_OnKeyDown)
button:SetScript("OnMouseDown", Keybinding_OnMouseDown) button:SetScript("OnMouseDown", Keybinding_OnMouseDown)
button:SetScript("OnMouseWheel", Keybinding_OnMouseWheel) button:SetScript("OnMouseWheel", Keybinding_OnMouseWheel)
button:SetPoint("BOTTOMLEFT") button:SetPoint("BOTTOMLEFT", 0, 0)
button:SetPoint("BOTTOMRIGHT") button:SetPoint("BOTTOMRIGHT", 0, 0)
button:SetHeight(24) button:SetHeight(24)
button:EnableKeyboard(false) button:EnableKeyboard(false)
@@ -209,8 +234,8 @@ local function Constructor()
text:SetPoint("RIGHT", -7, 0) text:SetPoint("RIGHT", -7, 0)
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight") local label = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
label:SetPoint("TOPLEFT") label:SetPoint("TOPLEFT", 0, 0)
label:SetPoint("TOPRIGHT") label:SetPoint("TOPRIGHT", 0, 0)
label:SetJustifyH("CENTER") label:SetJustifyH("CENTER")
label:SetHeight(18) label:SetHeight(18)
@@ -236,7 +261,8 @@ local function Constructor()
msgframe = msgframe, msgframe = msgframe,
frame = frame, frame = frame,
alignoffset = 30, alignoffset = 30,
type = Type type = Type,
text = text
} }
for method, func in pairs(methods) do for method, func in pairs(methods) do
widget[method] = func widget[method] = func
@@ -7,7 +7,8 @@ local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs -- Lua APIs
local max, select, pairs = math.max, select, pairs local max, pairs, unpack = math.max, pairs, unpack
local getn = table.getn
-- WoW APIs -- WoW APIs
local CreateFrame, UIParent = CreateFrame, UIParent local CreateFrame, UIParent = CreateFrame, UIParent
@@ -35,14 +36,14 @@ local function UpdateImageAnchor(self)
local imagewidth = image:GetWidth() local imagewidth = image:GetWidth()
if (width - imagewidth) < 200 or (label:GetText() or "") == "" then if (width - imagewidth) < 200 or (label:GetText() or "") == "" then
-- image goes on top centered when less than 200 width for the text, or if there is no text -- image goes on top centered when less than 200 width for the text, or if there is no text
image:SetPoint("TOP") image:SetPoint("TOP", 0, 0)
label:SetPoint("TOP", image, "BOTTOM") label:SetPoint("TOP", image, "BOTTOM")
label:SetPoint("LEFT") label:SetPoint("LEFT", 0, 0)
label:SetWidth(width) label:SetWidth(width)
height = image:GetHeight() + label:GetHeight() height = image:GetHeight() + label:GetHeight()
else else
-- image on the left -- image on the left
image:SetPoint("TOPLEFT") image:SetPoint("TOPLEFT", 0, 0)
if image:GetHeight() > label:GetHeight() then if image:GetHeight() > label:GetHeight() then
label:SetPoint("LEFT", image, "RIGHT", 4, 0) label:SetPoint("LEFT", image, "RIGHT", 4, 0)
else else
@@ -53,7 +54,7 @@ local function UpdateImageAnchor(self)
end end
else else
-- no image shown -- no image shown
label:SetPoint("TOPLEFT") label:SetPoint("TOPLEFT", 0, 0)
label:SetWidth(width) label:SetWidth(width)
height = label:GetHeight() height = label:GetHeight()
end end
@@ -111,9 +112,9 @@ local methods = {
if image:GetTexture() then if image:GetTexture() then
self.imageshown = true self.imageshown = true
local n = select("#", ...) local n = getn(arg)
if n == 4 or n == 8 then if n == 4 or n == 8 then
image:SetTexCoord(...) image:SetTexCoord(unpack(arg))
else else
image:SetTexCoord(0, 1, 0, 1) image:SetTexCoord(0, 1, 0, 1)
end end
@@ -4,9 +4,10 @@ if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs -- Lua APIs
local pairs = pairs local pairs = pairs
local format = string.format
-- WoW APIs -- WoW APIs
local GetCursorInfo, GetSpellInfo, ClearCursor = GetCursorInfo, GetSpellInfo, ClearCursor local GetCursorInfo, GetSpellName, ClearCursor = GetCursorInfo, GetSpellName, ClearCursor
local CreateFrame, UIParent = CreateFrame, UIParent local CreateFrame, UIParent = CreateFrame, UIParent
local _G = _G local _G = _G
@@ -20,13 +21,12 @@ Support functions
if not AceGUIMultiLineEditBoxInsertLink then if not AceGUIMultiLineEditBoxInsertLink then
-- upgradeable hook -- upgradeable hook
hooksecurefunc("ChatEdit_InsertLink", function(...) return _G.AceGUIMultiLineEditBoxInsertLink(...) end)
end end
function _G.AceGUIMultiLineEditBoxInsertLink(text) function _G.AceGUIMultiLineEditBoxInsertLink(text)
for i = 1, AceGUI:GetWidgetCount(Type) do for i = 1, AceGUI:GetWidgetCount(Type) do
local editbox = _G[("MultiLineEditBox%uEdit"):format(i)] local editbox = _G[format("MultiLineEditBox%uEdit",i)]
if editbox and editbox:IsVisible() and editbox:HasFocus() then if editbox and editbox:IsVisible() and editbox.hasfocus then
editbox:Insert(text) editbox:Insert(text)
return true return true
end end
@@ -55,78 +55,88 @@ end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function OnClick(self) -- Button local function OnClick() -- Button
self = self.obj local self = this.obj
self.editBox:ClearFocus() self.editBox:ClearFocus()
if not self:Fire("OnEnterPressed", self.editBox:GetText()) then if not self:Fire("OnEnterPressed", self.editBox:GetText()) then
self.button:Disable() self.button:Disable()
end end
end end
local function OnCursorChanged(self, _, y, _, cursorHeight) -- EditBox local function OnCursorChanged() -- EditBox
self, y = self.obj.scrollFrame, -y local self, y = this.obj.scrollFrame, -arg2
local offset = self:GetVerticalScroll() local offset = self:GetVerticalScroll()
if y < offset then if y < offset then
self:SetVerticalScroll(y) self:SetVerticalScroll(y)
else else
y = y + cursorHeight - self:GetHeight() y = y + arg4 - self:GetHeight()
if y > offset then if y > offset then
self:SetVerticalScroll(y) self:SetVerticalScroll(y)
end end
end end
end end
local function OnEditFocusLost(self) -- EditBox local function OnEditFocusLost() -- EditBox
self:HighlightText(0, 0) this.hasfocus = nil
self.obj:Fire("OnEditFocusLost") this:HighlightText(0, 0)
this.obj:Fire("OnEditFocusLost")
end end
local function OnEnter(self) -- EditBox / ScrollFrame local function OnEnter() -- EditBox / ScrollFrame
self = self.obj local self = this.obj
if not self.entered then if not self.entered then
self.entered = true self.entered = true
self:Fire("OnEnter") self:Fire("OnEnter")
end end
end end
local function OnLeave(self) -- EditBox / ScrollFrame local function OnLeave() -- EditBox / ScrollFrame
self = self.obj local self = this.obj
if self.entered then if self.entered then
self.entered = nil self.entered = nil
self:Fire("OnLeave") self:Fire("OnLeave")
end end
end end
local function OnMouseUp(self) -- ScrollFrame local function OnMouseUp() -- ScrollFrame
self = self.obj.editBox local self = this.obj.editBox
self:SetFocus() self:SetFocus()
self:SetCursorPosition(self:GetNumLetters()) EditBoxSetCursorPosition(self, self:GetNumLetters())
end end
local function OnReceiveDrag(self) -- EditBox / ScrollFrame local function OnReceiveDrag() -- EditBox / ScrollFrame
if not GetCursorInfo then print("TODO GetCursorInfo") return end -- TODO
local type, id, info = GetCursorInfo() local type, id, info = GetCursorInfo()
if type == "spell" then if type == "spell" then
info = GetSpellInfo(id, info) local name, rank = GetSpellName(id, info)
if rank ~= "" then
name = name.."("..rank..")"
end
info = name
elseif type ~= "item" then elseif type ~= "item" then
return return
end end
ClearCursor() ClearCursor()
self = self.obj local self = this.obj
local editBox = self.editBox local editBox = self.editBox
if not editBox:HasFocus() then if not this.hasfocus then
this.hasfocus = true
editBox:SetFocus() editBox:SetFocus()
editBox:SetCursorPosition(editBox:GetNumLetters()) EditBoxSetCursorPosition(editBox, editBox:GetNumLetters())
end end
editBox:Insert(info) editBox:Insert(info)
self.button:Enable() self.button:Enable()
end end
local function OnSizeChanged(self, width, height) -- ScrollFrame local function OnSizeChanged() -- ScrollFrame
self.obj.editBox:SetWidth(width) this:UpdateScrollChildRect()
this:SetVerticalScroll(this:GetHeight())
this.obj.editBox:SetWidth(arg1)
end end
local function OnTextChanged(self) -- EditBox local function OnTextChanged() -- EditBox
self = self.obj local self = this.obj
local value = self.editBox:GetText() local value = self.editBox:GetText()
if not self.lastText or value ~= self.lastText then if not self.lastText or value ~= self.lastText then
self:Fire("OnTextChanged", value) self:Fire("OnTextChanged", value)
@@ -138,26 +148,31 @@ local function OnTextChanged(self)
end end
end end
local function OnTextSet(self) -- EditBox local function OnTextSet() -- EditBox
self:HighlightText(0, 0) this:HighlightText(0, 0)
self:SetCursorPosition(self:GetNumLetters()) EditBoxSetCursorPosition(this, this:GetNumLetters())
self:SetCursorPosition(0) EditBoxSetCursorPosition(this, 0)
self.obj.button:Disable() this.obj.button:Disable()
end end
local function OnVerticalScroll(self, offset) -- ScrollFrame local function OnVerticalScroll() -- ScrollFrame
local editBox = self.obj.editBox local editBox = this.obj.editBox
editBox:SetHitRectInsets(0, 0, offset, editBox:GetHeight() - offset - self:GetHeight()) editBox:SetHitRectInsets(0, 0, arg1, editBox:GetHeight() - arg1 - this:GetHeight())
end end
local function OnShowFocus(frame) local function OnShowFocus()
frame.obj.editBox:SetFocus() this.obj.editBox:SetFocus()
frame:SetScript("OnShow", nil) this:SetScript("OnShow", nil)
end end
local function OnEditFocusGained(frame) local function OnEditFocusGained()
AceGUI:SetFocus(frame.obj) this.hasfocus = true
frame.obj:Fire("OnEditFocusGained") AceGUI:SetFocus(this.obj)
this.obj:Fire("OnEditFocusGained")
end
local function OnEscapePressed()
AceGUI:ClearFocus()
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
@@ -257,11 +272,11 @@ local methods = {
end, end,
["GetCursorPosition"] = function(self) ["GetCursorPosition"] = function(self)
return self.editBox:GetCursorPosition() return EditBoxGetCursorPosition(self.editBox)
end, end,
["SetCursorPosition"] = function(self, ...) ["SetCursorPosition"] = function(self, pos)
return self.editBox:SetCursorPosition(...) return EditBoxSetCursorPosition(self.editBox, pos)
end, end,
@@ -289,7 +304,7 @@ local function Constructor()
label:SetText(ACCEPT) label:SetText(ACCEPT)
label:SetHeight(10) label:SetHeight(10)
local button = CreateFrame("Button", ("%s%dButton"):format(Type, widgetNum), frame, "UIPanelButtonTemplate2") local button = CreateFrame("Button", format("%s%dButton", Type, widgetNum), frame, "UIPanelButtonTemplate")
button:SetPoint("BOTTOMLEFT", 0, 4) button:SetPoint("BOTTOMLEFT", 0, 4)
button:SetHeight(22) button:SetHeight(22)
button:SetWidth(label:GetStringWidth() + 24) button:SetWidth(label:GetStringWidth() + 24)
@@ -308,7 +323,7 @@ local function Constructor()
scrollBG:SetBackdropColor(0, 0, 0) scrollBG:SetBackdropColor(0, 0, 0)
scrollBG:SetBackdropBorderColor(0.4, 0.4, 0.4) scrollBG:SetBackdropBorderColor(0.4, 0.4, 0.4)
local scrollFrame = CreateFrame("ScrollFrame", ("%s%dScrollFrame"):format(Type, widgetNum), frame, "UIPanelScrollFrameTemplate") local scrollFrame = CreateFrame("ScrollFrame", format("%s%dScrollFrame", Type, widgetNum), frame, "UIPanelScrollFrameTemplate")
local scrollBar = _G[scrollFrame:GetName() .. "ScrollBar"] local scrollBar = _G[scrollFrame:GetName() .. "ScrollBar"]
scrollBar:ClearAllPoints() scrollBar:ClearAllPoints()
@@ -326,10 +341,9 @@ local function Constructor()
scrollFrame:SetScript("OnMouseUp", OnMouseUp) scrollFrame:SetScript("OnMouseUp", OnMouseUp)
scrollFrame:SetScript("OnReceiveDrag", OnReceiveDrag) scrollFrame:SetScript("OnReceiveDrag", OnReceiveDrag)
scrollFrame:SetScript("OnSizeChanged", OnSizeChanged) scrollFrame:SetScript("OnSizeChanged", OnSizeChanged)
scrollFrame:HookScript("OnVerticalScroll", OnVerticalScroll) HookScript(scrollFrame, "OnVerticalScroll", OnVerticalScroll)
local editBox = CreateFrame("EditBox", ("%s%dEdit"):format(Type, widgetNum), scrollFrame) local editBox = CreateFrame("EditBox", format("%s%dEdit", Type, widgetNum), scrollFrame)
editBox:SetAllPoints()
editBox:SetFontObject(ChatFontNormal) editBox:SetFontObject(ChatFontNormal)
editBox:SetMultiLine(true) editBox:SetMultiLine(true)
editBox:EnableMouse(true) editBox:EnableMouse(true)
@@ -337,7 +351,7 @@ local function Constructor()
editBox:SetScript("OnCursorChanged", OnCursorChanged) editBox:SetScript("OnCursorChanged", OnCursorChanged)
editBox:SetScript("OnEditFocusLost", OnEditFocusLost) editBox:SetScript("OnEditFocusLost", OnEditFocusLost)
editBox:SetScript("OnEnter", OnEnter) editBox:SetScript("OnEnter", OnEnter)
editBox:SetScript("OnEscapePressed", editBox.ClearFocus) editBox:SetScript("OnEscapePressed", OnEscapePressed)
editBox:SetScript("OnLeave", OnLeave) editBox:SetScript("OnLeave", OnLeave)
editBox:SetScript("OnMouseDown", OnReceiveDrag) editBox:SetScript("OnMouseDown", OnReceiveDrag)
editBox:SetScript("OnReceiveDrag", OnReceiveDrag) editBox:SetScript("OnReceiveDrag", OnReceiveDrag)
@@ -347,6 +361,7 @@ local function Constructor()
scrollFrame:SetScrollChild(editBox) scrollFrame:SetScrollChild(editBox)
editBox:SetAllPoints()
local widget = { local widget = {
button = button, button = button,
@@ -9,6 +9,7 @@ if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs -- Lua APIs
local min, max, floor = math.min, math.max, math.floor local min, max, floor = math.min, math.max, math.floor
local tonumber, pairs = tonumber, pairs local tonumber, pairs = tonumber, pairs
local format, gsub = string.format, string.gsub
-- WoW APIs -- WoW APIs
local PlaySound = PlaySound local PlaySound = PlaySound
@@ -24,7 +25,7 @@ Support functions
local function UpdateText(self) local function UpdateText(self)
local value = self.value or 0 local value = self.value or 0
if self.ispercent then if self.ispercent then
self.editbox:SetText(("%s%%"):format(floor(value * 1000 + 0.5) / 10)) self.editbox:SetText(format("%s%%", floor(value * 1000 + 0.5) / 10))
else else
self.editbox:SetText(floor(value * 100 + 0.5) / 100) self.editbox:SetText(floor(value * 100 + 0.5) / 100)
end end
@@ -33,8 +34,8 @@ end
local function UpdateLabels(self) local function UpdateLabels(self)
local min, max = (self.min or 0), (self.max or 100) local min, max = (self.min or 0), (self.max or 100)
if self.ispercent then if self.ispercent then
self.lowtext:SetFormattedText("%s%%", (min * 100)) self.lowtext:SetText(format("%s%%", (min * 100)))
self.hightext:SetFormattedText("%s%%", (max * 100)) self.hightext:SetText(format("%s%%", (max * 100)))
else else
self.lowtext:SetText(min) self.lowtext:SetText(min)
self.hightext:SetText(max) self.hightext:SetText(max)
@@ -44,23 +45,23 @@ end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
Scripts Scripts
-------------------------------------------------------------------------------]] -------------------------------------------------------------------------------]]
local function Control_OnEnter(frame) local function Control_OnEnter()
frame.obj:Fire("OnEnter") this.obj:Fire("OnEnter")
end end
local function Control_OnLeave(frame) local function Control_OnLeave()
frame.obj:Fire("OnLeave") this.obj:Fire("OnLeave")
end end
local function Frame_OnMouseDown(frame) local function Frame_OnMouseDown()
frame.obj.slider:EnableMouseWheel(true) this.obj.slider:EnableMouseWheel(true)
AceGUI:ClearFocus() AceGUI:ClearFocus()
end end
local function Slider_OnValueChanged(frame) local function Slider_OnValueChanged()
local self = frame.obj local self = this.obj
if not frame.setup then if not this.setup then
local newvalue = frame:GetValue() local newvalue = this:GetValue()
if newvalue ~= self.value and not self.disabled then if newvalue ~= self.value and not self.disabled then
self.value = newvalue self.value = newvalue
self:Fire("OnValueChanged", newvalue) self:Fire("OnValueChanged", newvalue)
@@ -71,16 +72,16 @@ local function Slider_OnValueChanged(frame)
end end
end end
local function Slider_OnMouseUp(frame) local function Slider_OnMouseUp()
local self = frame.obj local self = this.obj
self:Fire("OnMouseUp", self.value) self:Fire("OnMouseUp", self.value)
end end
local function Slider_OnMouseWheel(frame, v) local function Slider_OnMouseWheel()
local self = frame.obj local self = this.obj
if not self.disabled then if not self.disabled then
local value = self.value local value = self.value
if v > 0 then if arg1 > 0 then
value = min(value + (self.step or 1), self.max) value = min(value + (self.step or 1), self.max)
else else
value = max(value - (self.step or 1), self.min) value = max(value - (self.step or 1), self.min)
@@ -89,15 +90,15 @@ local function Slider_OnMouseWheel(frame, v)
end end
end end
local function EditBox_OnEscapePressed(frame) local function EditBox_OnEscapePressed()
frame:ClearFocus() this:ClearFocus()
end end
local function EditBox_OnEnterPressed(frame) local function EditBox_OnEnterPressed()
local self = frame.obj local self = this.obj
local value = frame:GetText() local value = this:GetText()
if self.ispercent then if self.ispercent then
value = value:gsub('%%', '') value = gsub(value, '%%', '')
value = tonumber(value) / 100 value = tonumber(value) / 100
else else
value = tonumber(value) value = tonumber(value)
@@ -110,12 +111,12 @@ local function EditBox_OnEnterPressed(frame)
end end
end end
local function EditBox_OnEnter(frame) local function EditBox_OnEnter()
frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1) this:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
end end
local function EditBox_OnLeave(frame) local function EditBox_OnLeave()
frame:SetBackdropBorderColor(0.3, 0.3, 0.3, 0.8) this:SetBackdropBorderColor(0.3, 0.3, 0.3, 0.8)
end end
--[[----------------------------------------------------------------------------- --[[-----------------------------------------------------------------------------
@@ -217,8 +218,8 @@ local function Constructor()
frame:SetScript("OnMouseDown", Frame_OnMouseDown) frame:SetScript("OnMouseDown", Frame_OnMouseDown)
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal") local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("TOPLEFT") label:SetPoint("TOPLEFT", 0, 0)
label:SetPoint("TOPRIGHT") label:SetPoint("TOPRIGHT", 0, 0)
label:SetJustifyH("CENTER") label:SetJustifyH("CENTER")
label:SetHeight(15) label:SetHeight(15)
+1 -1
View File
@@ -1 +1 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/"> <Include file="AceGUI-3.0\AceGUI-3.0.xml"/> <Include file="AceConfig-3.0\AceConfig-3.0.xml"/> <Include file="AceDBOptions-3.0\AceDBOptions-3.0.xml"/> <Include file="AceGUI-3.0-SharedMediaWidgets\widget.xml"/> </Ui> <Ui xmlns="http://www.blizzard.com/wow/ui/"> <Include file="AceGUI-3.0\AceGUI-3.0.xml"/> <Include file="AceGUI-3.0\widgets\widgets.xml"/> <Include file="AceConfig-3.0\AceConfig-3.0.xml"/> <Include file="AceDBOptions-3.0\AceDBOptions-3.0.xml"/> <Include file="AceGUI-3.0-SharedMediaWidgets\widget.xml"/> </Ui>