commit from backup

This commit is contained in:
mikx 2018-01-05 06:40:15 -05:00
commit 58b08d6ae0
142 changed files with 29080 additions and 0 deletions

2
CHANGELOG Normal file
View File

@ -0,0 +1,2 @@
[0.0.10][June 11, 2017]
- Experimental Release

View File

@ -0,0 +1,20 @@
-- MxW (MxW Addon)
-- By mikx
-- https://git.mikx.ca/wow-addons/MxW_Addon
-- Licensed under the GNU General Public License 3.0
-- See included License file for more informations.
local MX = LibStub("AceAddon-3.0"):GetAddon("MxW");
local L = LibStub("AceLocale-3.0"):GetLocale("MxW");
local ENCOUNTER_LOOT_RECEIVED_Frame = CreateFrame("Frame")
ENCOUNTER_LOOT_RECEIVED_Frame:RegisterEvent("ENCOUNTER_LOOT_RECEIVED")
ENCOUNTER_LOOT_RECEIVED_Frame:SetScript("OnEvent",
function(self, event, ...)
local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 = ...
name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(arg2)
value = MX.TSM:GetItemValue(arg2, "DBMarket");
if (value ~= nil and value >= Farmer_Logic_MinAlert and quality >= 1) then
MX:SendAlert(arg2,value);
end
end)

4
Event/Load_Events.xml Normal file
View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="ENCOUNTER_LOOT_RECEIVED.lua"/>
<Script file="PLAYER_MONEY.lua"/>
</Ui>

44
Event/PLAYER_MONEY.lua Normal file
View File

@ -0,0 +1,44 @@
-- MxW (MxW Addon)
-- By mikx
-- https://git.mikx.ca/wow-addons/MxW_Addon
-- Licensed under the GNU General Public License 3.0
-- See included License file for more informations.
local MX = LibStub("AceAddon-3.0"):GetAddon("MxW");
local L = LibStub("AceLocale-3.0"):GetLocale("MxW");
local PLAYER_MONEY_Frame = CreateFrame("Frame")
PLAYER_MONEY_Frame:RegisterEvent("PLAYER_MONEY")
PLAYER_MONEY_Frame:SetScript("OnEvent", function(self, event, ...)
local tmpMoney = GetMoney()
if self.CurrentMoney then
self.DiffMoney = tmpMoney - self.CurrentMoney
else
self.DiffMoney = 0
end
self.CurrentMoney = tmpMoney
if self.DiffMoney > 0 then
-- Money Gain
-- Reset daily counter if this is a new day
local weekday, month, day, year = CalendarGetDate();
-- Reset Global Daily Counter
if (Farmer_Logic_Day ~= day) then
Farmer_Money_DayGlobal = 0;
MX:UpdateText()
Farmer_Logic_Day = day;
end
-- Reset Player Daily Counter
if (Farmer_Logic_PlayerDay ~= day) then
Farmer_Money_DayPlayer = 0;
MX:UpdateText()
Farmer_Logic_PlayerDay = day;
end
-- Write to SavedVariables
Farmer_Money_DayPlayer = Farmer_Money_DayPlayer + self.DiffMoney;
Farmer_Money_MonthPlayer = Farmer_Money_MonthPlayer + self.DiffMoney;
Farmer_Money_MonthGlobal = Farmer_Money_MonthGlobal + self.DiffMoney;
Farmer_Money_DayGlobal = Farmer_Money_DayGlobal + self.DiffMoney;
elseif self.DiffMoney < 0 then
-- Money Lost
end
end)

3
Frame/Load_Frames.xml Normal file
View File

@ -0,0 +1,3 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="MainFrame.lua"/>
</Ui>

218
Frame/MainFrame.lua Normal file
View File

@ -0,0 +1,218 @@
-- MxW (MxW Addon)
-- By mikx
-- https://git.mikx.ca/wow-addons/MxW_Addon
-- Licensed under the GNU General Public License 3.0
-- See included License file for more informations.
-- local
local MX = LibStub("AceAddon-3.0"):GetAddon("MxW");
local L = LibStub("AceLocale-3.0"):GetLocale("MxW");
local AceGUI = LibStub("AceGUI-3.0")
local GUI_LOOTCOLLECTED, GUI_SCROLLCONTAINER
local lootCollectedLastEntry = nil
--
-- main frame
local f = CreateFrame("Frame","FarmerMainFrame", UIParent)
local mxwVersion = GetAddOnMetadata("MxW", "Version")
local mainFrameWidth = 350;
-- make it draggable with the mouse
f:SetMovable(true)
f:EnableMouse(true)
f:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" and not self.isMoving then
self:StartMoving();
self.isMoving = true;
end
end)
f:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" and self.isMoving then
self:StopMovingOrSizing();
self.isMoving = false;
end
end)
f:SetScript("OnHide", function(self)
if ( self.isMoving ) then
self:StopMovingOrSizing();
self.isMoving = false;
end
end)
f:SetFrameStrata("BACKGROUND") --Set its strata
f:SetHeight(100) --Give it height
f:SetWidth(mainFrameWidth) --and width
f:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", --Set the background and border textures
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 10,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
})
f:SetBackdropColor(0, 0, 0) --Set the background colour to black
f:SetPoint("CENTER") --Put it in the centre of the parent frame (UIParent)
f.txtLogo = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text
f.txtLogo:SetFont("Fonts\\FRIZQT__.TTF", 14) --Set the font and size
f.txtLogo:SetTextColor(1, 1, 1) --Set the text colour
f.txtLogo:SetPoint("TOP", 0, -5) --Put it in the centre of the frame
f.txtLogo:SetText("MxW") --Change the displayed text
f.txtVersion = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text
f.txtVersion:SetFont("Fonts\\FRIZQT__.TTF", 9) --Set the font and size
f.txtVersion:SetTextColor(1, 1, 1) --Set the text colour
f.txtVersion:SetPoint("TOP", -(mainFrameWidth/2) + (#mxwVersion*3.0), -5) --Put it in the centre of the frame
f.txtVersion:SetText(mxwVersion) --Change the displayed text
local button = CreateFrame("Button", nil, f)
button:SetPoint("TOP", f, "TOP", (mainFrameWidth/2) - #L["MainForm_Label_Close"]*6.0, -5)
button:SetWidth(#L["MainForm_Label_Close"]*10.5)
button:SetHeight(17)
button:SetText(L["MainForm_Label_Close"])
button:SetNormalFontObject("GameFontNormal")
local ntex = button:CreateTexture()
ntex:SetTexture("Interface/Buttons/UI-Panel-Button-Up")
ntex:SetTexCoord(0, 0.625, 0, 0.6875)
ntex:SetAllPoints()
button:SetNormalTexture(ntex)
local htex = button:CreateTexture()
htex:SetTexture("Interface/Buttons/UI-Panel-Button-Highlight")
htex:SetTexCoord(0, 0.625, 0, 0.6875)
htex:SetAllPoints()
button:SetHighlightTexture(htex)
local ptex = button:CreateTexture()
ptex:SetTexture("Interface/Buttons/UI-Panel-Button-Down")
ptex:SetTexCoord(0, 0.625, 0, 0.6875)
ptex:SetAllPoints()
button:SetPushedTexture(ptex)
button:SetScript("OnClick", function(self, arg1)
f:Hide();
end)
f.txtLabTM = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text
f.txtLabTM:SetFont("Fonts\\FRIZQT__.TTF", 10) --Set the font and size
f.txtLabTM:SetTextColor(1, 1, 1) --Set the text colour
f.txtLabTM:SetPoint("TOP", 0, -20) --Put it in the centre of the frame
f.txtLabTM:SetText(format("%s / %s",L["MainForm_Label_Money_Lab_Today"],L["MainForm_Label_Money_Lab_Month"])) --Change the displayed text
f.txtPlayer = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text
f.txtPlayer:SetFont("Fonts\\FRIZQT__.TTF", 10) --Set the font and size
f.txtPlayer:SetTextColor(1, 1, 1) --Set the text colour
f.txtPlayer:SetPoint("TOPLEFT", 10, -32) --Put it in the centre of the frame
f.txtPlayer:SetText(L["MainForm_Label_Money_Player"]) --Change the displayed text
f.txtGlobal = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text
f.txtGlobal:SetFont("Fonts\\FRIZQT__.TTF", 10) --Set the font and size
f.txtGlobal:SetTextColor(1, 1, 1) --Set the text colour
f.txtGlobal:SetPoint("TOPLEFT", 10, -42) --Put it in the centre of the frame
f.txtGlobal:SetText(L["MainForm_Label_Money_Global"]) --Change the displayed text
f.txtLootLabel = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text
f.txtLootLabel:SetFont("Fonts\\FRIZQT__.TTF", 10) --Set the font and size
f.txtLootLabel:SetTextColor(1, 1, 1) --Set the text colour
f.txtLootLabel:SetPoint("TOP", 0, -56) --Put it in the centre of the frame
f.txtLootLabel:SetText(L["MainForm_Label_Loot"]) --Put it in the centre of the frame
f.txtLootLinkQty = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text
f.txtLootLinkQty:SetFont("Fonts\\FRIZQT__.TTF", 10) --Set the font and size
f.txtLootLinkQty:SetTextColor(1, 1, 1) --Set the text colour
f.txtLootLinkQty:SetPoint("TOP", 0, -66)
f.txtLast = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text
f.txtLast:SetFont("Fonts\\FRIZQT__.TTF", 10) --Set the font and size
f.txtLast:SetTextColor(1, 1, 1) --Set the text colour
f.txtLast:SetPoint("TOPLEFT", 10, -62) --Put it in the centre of the frame
local MAIN_UI = AceGUI:Create("Window")
MAIN_UI:Hide()
MAIN_UI:SetHeight(200)
MAIN_UI:SetTitle("MxW")
MAIN_UI:SetLayout("Flow")
MAIN_UI:SetWidth(300)
MAIN_UI:EnableResize(true)
GUI_SCROLLCONTAINER = AceGUI:Create("SimpleGroup")
GUI_SCROLLCONTAINER:SetFullWidth(true)
GUI_SCROLLCONTAINER:SetHeight(150)
GUI_SCROLLCONTAINER:SetLayout("Fill")
GUI_SCROLLCONTAINER.frame:SetBackdrop(backdrop)
GUI_SCROLLCONTAINER.frame:SetBackdropColor(0, 0, 0)
GUI_SCROLLCONTAINER.frame:SetBackdropBorderColor(0.4, 0.4, 0.4)
GUI_LOOTCOLLECTED = AceGUI:Create("ScrollFrame")
GUI_LOOTCOLLECTED:SetLayout("Flow")
GUI_SCROLLCONTAINER:AddChild(GUI_LOOTCOLLECTED)
MAIN_UI:AddChild(GUI_SCROLLCONTAINER)
local MainFrame_Event_ADDON_LOADED = CreateFrame("Frame")
MainFrame_Event_ADDON_LOADED:RegisterEvent("ADDON_LOADED")
MainFrame_Event_ADDON_LOADED:SetScript("OnEvent", function(self, event, ...)
MX:UpdateText()
end)
local MainFrame_Event_PLAYER_MONEY = CreateFrame("Frame")
MainFrame_Event_PLAYER_MONEY:RegisterEvent("PLAYER_MONEY")
MainFrame_Event_PLAYER_MONEY:SetScript("OnEvent", function(self, event, ...)
MX:UpdateText()
end)
local MainFrame_Event_ENCOUNTER_LOOT_RECEIVED = CreateFrame("Frame")
MainFrame_Event_ENCOUNTER_LOOT_RECEIVED:RegisterEvent("ENCOUNTER_LOOT_RECEIVED")
MainFrame_Event_ENCOUNTER_LOOT_RECEIVED:SetScript("OnEvent", function(self, event, ...)
local arg1, iid, ilink, iqty, arg5, arg6, arg7, arg8, arg9 = ...
--name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(iid);
value = MX.TSM:GetItemValue(iid, "DBMarket");
if (value ~= nil and value >= Farmer_Logic_MinAlert and quality >= 0) then
--f.txtLast:SetText(format("%s %s (%s) (%s %s)",L["MainForm_Label_Money_Last"],link,MX:FormatMoney(value),L["MainForm_Label_Money_Min"],MX:FormatMoney(Farmer_Logic_MinAlert)));
local fv = MX:FormatMoneyShort(value);
local tfv = MX:FormatMoneyShort(value*iqty);
if (iqty > 1) then
f.txtLootLinkQty:SetText(format("%sx %s (%s) (T. %s)", iqty, ilink, fv, tfv));
MX:addItem2LootCollectedList(format("%sx %s (%s) (T. %s)", iqty, ilink, fv, tfv),texture)
elseif (iqty == 1) then
f.txtLootLinkQty:SetText(format("%sx %s (%s)", iqty, ilink, fv));
MX:addItem2LootCollectedList(format("%sx %s (%s)", iqty, ilink, fv),texture)
end
end
end)
function MX:UpdateText()
f.txtPlayer:SetText(format("%s %s / %s",L["MainForm_Label_Money_Player"], MX:FormatMoney(Farmer_Money_DayPlayer), MX:FormatMoney(Farmer_Money_MonthPlayer))) --Change the displayed text
f.txtGlobal:SetText(format("%s %s / %s",L["MainForm_Label_Money_Global"], MX:FormatMoney(Farmer_Money_DayGlobal), MX:FormatMoney(Farmer_Money_MonthGlobal))) --Change the displayed text
end
function MX:ShowMain()
f:Show();
end
function MX:ShowHistory()
MAIN_UI:Show()
end
function MX:addItem2LootCollectedList(v,texture)
-- prepare text
-- item / link
local LABEL = AceGUI:Create("InteractiveLabel")
LABEL.frame:Show()
LABEL:SetText(v)
LABEL.label:SetJustifyH("LEFT")
LABEL:SetWidth(350)
LABEL:SetImage(texture)
LABEL:SetImageSize(18,18)
if lootCollectedLastEntry then
GUI_LOOTCOLLECTED:AddChild(LABEL, lootCollectedLastEntry)
else
GUI_LOOTCOLLECTED:AddChild(LABEL)
end
-- rember the created entry to add the next entry before this -> reverse list with newest entry on top
lootCollectedLastEntry = LABEL
end

88
Function/Alert.lua Normal file
View File

@ -0,0 +1,88 @@
-- MxW (MxW Addon)
-- By mikx
-- https://git.mikx.ca/wow-addons/MxW_Addon
-- Licensed under the GNU General Public License 3.0
-- See included License file for more informations.
local MX = LibStub("AceAddon-3.0"):GetAddon("MxW");
local L = LibStub("AceLocale-3.0"):GetLocale("MxW");
print("Alert.lua has been loaded.");
-- Alert Cooking
-- Based on [[ AchievementAlertFrame ]] from Blizzard
function CookAlert(frame, item, fvalue)
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(item)
if itemName == nil then return end
if itemTexture == nil then itemTexture = [[Interface\Icons\INV_Misc_PheonixPet_01]] end
local displayName = frame.Name;
local shieldPoints = frame.Shield.Points;
local shieldIcon = frame.Shield.Icon;
local unlocked = frame.Unlocked;
local oldCheevo = frame.OldAchievement;
displayName:SetText(itemName);
AchievementShield_SetPoints(0, shieldPoints, GameFontNormal, GameFontNormalSmall);
frame.oldCheevo = nil
shieldPoints:Hide();
shieldIcon:Hide();
oldCheevo:Hide();
frame.guildDisplay = nil;
frame:SetHeight(88);
local background = frame.Background;
background:SetTexture("Interface\\AchievementFrame\\UI-Achievement-Alert-Background");
background:SetTexCoord(0, 0.605, 0, 0.703);
background:SetPoint("TOPLEFT", 0, 0);
background:SetPoint("BOTTOMRIGHT", 0, 0);
local iconBorder = frame.Icon.Overlay;
iconBorder:SetTexture("Interface\\AchievementFrame\\UI-Achievement-IconFrame");
iconBorder:SetTexCoord(0, 0.5625, 0, 0.5625);
iconBorder:SetPoint("CENTER", -1, 2);
frame.Icon:SetPoint("TOPLEFT", -26, 16);
displayName:SetPoint("BOTTOMLEFT", 72, 36);
displayName:SetPoint("BOTTOMRIGHT", -60, 36);
unlocked:SetPoint("TOP", 7, -23);
unlocked:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
unlocked:SetText(fvalue);
frame.GuildName:Hide();
frame.GuildBorder:Hide();
frame.GuildBanner:Hide();
frame.glow:SetTexture("Interface\\AchievementFrame\\UI-Achievement-Alert-Glow");
frame.glow:SetTexCoord(0, 0.78125, 0, 0.66796875);
frame.shine:SetTexture("Interface\\AchievementFrame\\UI-Achievement-Alert-Glow");
frame.shine:SetTexCoord(0.78125, 0.912109375, 0, 0.28125);
frame.shine:SetPoint("BOTTOMLEFT", 0, 8);
shieldIcon:SetTexture([[Interface\AchievementFrame\UI-Achievement-Shields-NoPoints]]);
frame.Icon.Texture:SetTexture(itemTexture);
frame.id = item;
return true;
end
local FarmerAlert = AlertFrame:AddQueuedAlertFrameSubSystem("AchievementAlertFrameTemplate", CookAlert, 2, 6);
function MX:SendAlert(itemId,value)
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(itemId)
if ( not AchievementFrame ) then
AchievementFrame_LoadUI();
end
fvalue = MX:FormatMoney(value);
FarmerAlert:AddAlert(itemId,fvalue);
PlaySoundFile("Sound\\Spells\\AchievmentSound1.ogg")
end
local COLOR_GREY = "|cff888888"
local COLOR_GOLD = "|cffffcc00"
function MX:LootMsg(id, link, value, qty)
local fv = MX:FormatMoney(value);
local tfv = MX:FormatMoney(value*qty);
print("")
end

5
Function/DB.lua Normal file
View File

@ -0,0 +1,5 @@
-- MxW (MxW Addon)
-- By mikx
-- https://git.mikx.ca/wow-addons/MxW_Addon
-- Licensed under the GNU General Public License 3.0
-- See included License file for more informations.

708
Function/JSON.lua Normal file
View File

@ -0,0 +1,708 @@
-- Lub JSON Lib
local always_try_using_lpeg = false
local register_global_module_table = true
local global_module_name = 'json'
--[==[
David Kolf's JSON module for Lua 5.1/5.2
Version 2.5
For the documentation see the corresponding readme.txt or visit
<http://dkolf.de/src/dkjson-lua.fsl/>.
You can contact the author by sending an e-mail to 'david' at the
domain 'dkolf.de'.
Copyright (C) 2010-2013 David Heiko Kolf
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]==]
-- global dependencies:
-- local pairs, type, tostring, tonumber, getmetatable, setmetatable, rawset =
-- pairs, type, tostring, tonumber, getmetatable, setmetatable, rawset
-- local error, require, pcall, select = error, require, pcall, select
-- local floor, huge = math.floor, math.huge
-- local strrep, gsub, strsub, strbyte, strchar, strfind, strlen, strformat =
-- string.rep, string.gsub, string.sub, string.byte, string.char,
-- string.find, string.len, string.format
local strmatch = string.match
local concat = table.concat
local json = { version = "dkjson 2.5" }
if register_global_module_table then
_G[global_module_name] = json
end
local _ENV = nil -- blocking globals in Lua 5.2
-- pcall (function()
-- -- Enable access to blocked metatables.
-- -- Don't worry, this module doesn't change anything in them.
-- local debmeta = require "debug".getmetatable
-- if debmeta then getmetatable = debmeta end
-- end)
json.null = setmetatable ({}, {
__tojson = function () return "null" end
})
local function isarray (tbl)
local max, n, arraylen = 0, 0, 0
for k,v in pairs (tbl) do
if k == 'n' and type(v) == 'number' then
arraylen = v
if v > max then
max = v
end
else
if type(k) ~= 'number' or k < 1 or floor(k) ~= k then
return false
end
if k > max then
max = k
end
n = n + 1
end
end
if max > 10 and max > arraylen and max > n * 2 then
return false -- don't create an array with too many holes
end
return true, max
end
local escapecodes = {
["\""] = "\\\"", ["\\"] = "\\\\", ["\b"] = "\\b", ["\f"] = "\\f",
["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t"
}
local function escapeutf8 (uchar)
local value = escapecodes[uchar]
if value then
return value
end
local a, b, c, d = strbyte (uchar, 1, 4)
a, b, c, d = a or 0, b or 0, c or 0, d or 0
if a <= 0x7f then
value = a
elseif 0xc0 <= a and a <= 0xdf and b >= 0x80 then
value = (a - 0xc0) * 0x40 + b - 0x80
elseif 0xe0 <= a and a <= 0xef and b >= 0x80 and c >= 0x80 then
value = ((a - 0xe0) * 0x40 + b - 0x80) * 0x40 + c - 0x80
elseif 0xf0 <= a and a <= 0xf7 and b >= 0x80 and c >= 0x80 and d >= 0x80 then
value = (((a - 0xf0) * 0x40 + b - 0x80) * 0x40 + c - 0x80) * 0x40 + d - 0x80
else
return ""
end
if value <= 0xffff then
return strformat ("\\u%.4x", value)
elseif value <= 0x10ffff then
-- encode as UTF-16 surrogate pair
value = value - 0x10000
local highsur, lowsur = 0xD800 + floor (value/0x400), 0xDC00 + (value % 0x400)
return strformat ("\\u%.4x\\u%.4x", highsur, lowsur)
else
return ""
end
end
local function fsub (str, pattern, repl)
-- gsub always builds a new string in a buffer, even when no match
-- exists. First using find should be more efficient when most strings
-- don't contain the pattern.
if strfind (str, pattern) then
return gsub (str, pattern, repl)
else
return str
end
end
local function quotestring (value)
-- based on the regexp "escapable" in https://github.com/douglascrockford/JSON-js
value = fsub (value, "[%z\1-\31\"\\\127]", escapeutf8)
if strfind (value, "[\194\216\220\225\226\239]") then
value = fsub (value, "\194[\128-\159\173]", escapeutf8)
value = fsub (value, "\216[\128-\132]", escapeutf8)
value = fsub (value, "\220\143", escapeutf8)
value = fsub (value, "\225\158[\180\181]", escapeutf8)
value = fsub (value, "\226\128[\140-\143\168-\175]", escapeutf8)
value = fsub (value, "\226\129[\160-\175]", escapeutf8)
value = fsub (value, "\239\187\191", escapeutf8)
value = fsub (value, "\239\191[\176-\191]", escapeutf8)
end
return "\"" .. value .. "\""
end
json.quotestring = quotestring
local function replace(str, o, n)
local i, j = strfind (str, o, 1, true)
if i then
return strsub(str, 1, i-1) .. n .. strsub(str, j+1, -1)
else
return str
end
end
-- locale independent num2str and str2num functions
local decpoint, numfilter
local function updatedecpoint ()
decpoint = strmatch(tostring(0.5), "([^05+])")
-- build a filter that can be used to remove group separators
numfilter = "[^0-9%-%+eE" .. gsub(decpoint, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%0") .. "]+"
end
updatedecpoint()
local function num2str (num)
return replace(fsub(tostring(num), numfilter, ""), decpoint, ".")
end
local function str2num (str)
local num = tonumber(replace(str, ".", decpoint))
if not num then
updatedecpoint()
num = tonumber(replace(str, ".", decpoint))
end
return num
end
local function addnewline2 (level, buffer, buflen)
buffer[buflen+1] = "\n"
buffer[buflen+2] = strrep (" ", level)
buflen = buflen + 2
return buflen
end
function json.addnewline (state)
if state.indent then
state.bufferlen = addnewline2 (state.level or 0,
state.buffer, state.bufferlen or #(state.buffer))
end
end
local encode2 -- forward declaration
local function addpair (key, value, prev, indent, level, buffer, buflen, tables, globalorder, state)
local kt = type (key)
if kt ~= 'string' and kt ~= 'number' then
return nil, "type '" .. kt .. "' is not supported as a key by JSON."
end
if prev then
buflen = buflen + 1
buffer[buflen] = ","
end
if indent then
buflen = addnewline2 (level, buffer, buflen)
end
buffer[buflen+1] = quotestring (key)
buffer[buflen+2] = ":"
return encode2 (value, indent, level, buffer, buflen + 2, tables, globalorder, state)
end
local function appendcustom(res, buffer, state)
local buflen = state.bufferlen
if type (res) == 'string' then
buflen = buflen + 1
buffer[buflen] = res
end
return buflen
end
local function exception(reason, value, state, buffer, buflen, defaultmessage)
defaultmessage = defaultmessage or reason
local handler = state.exception
if not handler then
return nil, defaultmessage
else
state.bufferlen = buflen
local ret, msg = handler (reason, value, state, defaultmessage)
if not ret then return nil, msg or defaultmessage end
return appendcustom(ret, buffer, state)
end
end
function json.encodeexception(reason, value, state, defaultmessage)
return quotestring("<" .. defaultmessage .. ">")
end
encode2 = function (value, indent, level, buffer, buflen, tables, globalorder, state)
local valtype = type (value)
local valmeta = getmetatable (value)
valmeta = type (valmeta) == 'table' and valmeta -- only tables
local valtojson = valmeta and valmeta.__tojson
if valtojson then
if tables[value] then
return exception('reference cycle', value, state, buffer, buflen)
end
tables[value] = true
state.bufferlen = buflen
local ret, msg = valtojson (value, state)
if not ret then return exception('custom encoder failed', value, state, buffer, buflen, msg) end
tables[value] = nil
buflen = appendcustom(ret, buffer, state)
elseif value == nil then
buflen = buflen + 1
buffer[buflen] = "null"
elseif valtype == 'number' then
local s
if value ~= value or value >= huge or -value >= huge then
-- This is the behaviour of the original JSON implementation.
s = "null"
else
s = num2str (value)
end
buflen = buflen + 1
buffer[buflen] = s
elseif valtype == 'boolean' then
buflen = buflen + 1
buffer[buflen] = value and "true" or "false"
elseif valtype == 'string' then
buflen = buflen + 1
buffer[buflen] = quotestring (value)
elseif valtype == 'table' then
if tables[value] then
return exception('reference cycle', value, state, buffer, buflen)
end
tables[value] = true
level = level + 1
local isa, n = isarray (value)
if n == 0 and valmeta and valmeta.__jsontype == 'object' then
isa = false
end
local msg
if isa then -- JSON array
buflen = buflen + 1
buffer[buflen] = "["
for i = 1, n do
buflen, msg = encode2 (value[i], indent, level, buffer, buflen, tables, globalorder, state)
if not buflen then return nil, msg end
if i < n then
buflen = buflen + 1
buffer[buflen] = ","
end
end
buflen = buflen + 1
buffer[buflen] = "]"
else -- JSON object
local prev = false
buflen = buflen + 1
buffer[buflen] = "{"
local order = valmeta and valmeta.__jsonorder or globalorder
if order then
local used = {}
n = #order
for i = 1, n do
local k = order[i]
local v = value[k]
if v then
used[k] = true
buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state)
prev = true -- add a seperator before the next element
end
end
for k,v in pairs (value) do
if not used[k] then
buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state)
if not buflen then return nil, msg end
prev = true -- add a seperator before the next element
end
end
else -- unordered
for k,v in pairs (value) do
buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state)
if not buflen then return nil, msg end
prev = true -- add a seperator before the next element
end
end
if indent then
buflen = addnewline2 (level - 1, buffer, buflen)
end
buflen = buflen + 1
buffer[buflen] = "}"
end
tables[value] = nil
else
return exception ('unsupported type', value, state, buffer, buflen,
"type '" .. valtype .. "' is not supported by JSON.")
end
return buflen
end
function json.encode (value, state)
state = state or {}
local oldbuffer = state.buffer
local buffer = oldbuffer or {}
state.buffer = buffer
updatedecpoint()
local ret, msg = encode2 (value, state.indent, state.level or 0,
buffer, state.bufferlen or 0, state.tables or {}, state.keyorder, state)
if not ret then
error (msg, 2)
elseif oldbuffer == buffer then
state.bufferlen = ret
return true
else
state.bufferlen = nil
state.buffer = nil
return concat (buffer)
end
end
local function loc (str, where)
local line, pos, linepos = 1, 1, 0
while true do
pos = strfind (str, "\n", pos, true)
if pos and pos < where then
line = line + 1
linepos = pos
pos = pos + 1
else
break
end
end
return "line " .. line .. ", column " .. (where - linepos)
end
local function unterminated (str, what, where)
return nil, strlen (str) + 1, "unterminated " .. what .. " at " .. loc (str, where)
end
local function scanwhite (str, pos)
while true do
pos = strfind (str, "%S", pos)
if not pos then return nil end
local sub2 = strsub (str, pos, pos + 1)
if sub2 == "\239\187" and strsub (str, pos + 2, pos + 2) == "\191" then
-- UTF-8 Byte Order Mark
pos = pos + 3
elseif sub2 == "//" then
pos = strfind (str, "[\n\r]", pos + 2)
if not pos then return nil end
elseif sub2 == "/*" then
pos = strfind (str, "*/", pos + 2)
if not pos then return nil end
pos = pos + 2
else
return pos
end
end
end
local escapechars = {
["\""] = "\"", ["\\"] = "\\", ["/"] = "/", ["b"] = "\b", ["f"] = "\f",
["n"] = "\n", ["r"] = "\r", ["t"] = "\t"
}
local function unichar (value)
if value < 0 then
return nil
elseif value <= 0x007f then
return strchar (value)
elseif value <= 0x07ff then
return strchar (0xc0 + floor(value/0x40),
0x80 + (floor(value) % 0x40))
elseif value <= 0xffff then
return strchar (0xe0 + floor(value/0x1000),
0x80 + (floor(value/0x40) % 0x40),
0x80 + (floor(value) % 0x40))
elseif value <= 0x10ffff then
return strchar (0xf0 + floor(value/0x40000),
0x80 + (floor(value/0x1000) % 0x40),
0x80 + (floor(value/0x40) % 0x40),
0x80 + (floor(value) % 0x40))
else
return nil
end
end
local function scanstring (str, pos)
local lastpos = pos + 1
local buffer, n = {}, 0
while true do
local nextpos = strfind (str, "[\"\\]", lastpos)
if not nextpos then
return unterminated (str, "string", pos)
end
if nextpos > lastpos then
n = n + 1
buffer[n] = strsub (str, lastpos, nextpos - 1)
end
if strsub (str, nextpos, nextpos) == "\"" then
lastpos = nextpos + 1
break
else
local escchar = strsub (str, nextpos + 1, nextpos + 1)
local value
if escchar == "u" then
value = tonumber (strsub (str, nextpos + 2, nextpos + 5), 16)
if value then
local value2
if 0xD800 <= value and value <= 0xDBff then
-- we have the high surrogate of UTF-16. Check if there is a
-- low surrogate escaped nearby to combine them.
if strsub (str, nextpos + 6, nextpos + 7) == "\\u" then
value2 = tonumber (strsub (str, nextpos + 8, nextpos + 11), 16)
if value2 and 0xDC00 <= value2 and value2 <= 0xDFFF then
value = (value - 0xD800) * 0x400 + (value2 - 0xDC00) + 0x10000
else
value2 = nil -- in case it was out of range for a low surrogate
end
end
end
value = value and unichar (value)
if value then
if value2 then
lastpos = nextpos + 12
else
lastpos = nextpos + 6
end
end
end
end
if not value then
value = escapechars[escchar] or escchar
lastpos = nextpos + 2
end
n = n + 1
buffer[n] = value
end
end
if n == 1 then
return buffer[1], lastpos
elseif n > 1 then
return concat (buffer), lastpos
else
return "", lastpos
end
end
local scanvalue -- forward declaration
local function scantable (what, closechar, str, startpos, nullval, objectmeta, arraymeta)
local len = strlen (str)
local tbl, n = {}, 0
local pos = startpos + 1
if what == 'object' then
setmetatable (tbl, objectmeta)
else
setmetatable (tbl, arraymeta)
end
while true do
pos = scanwhite (str, pos)
if not pos then return unterminated (str, what, startpos) end
local char = strsub (str, pos, pos)
if char == closechar then
return tbl, pos + 1
end
local val1, err
val1, pos, err = scanvalue (str, pos, nullval, objectmeta, arraymeta)
if err then return nil, pos, err end
pos = scanwhite (str, pos)
if not pos then return unterminated (str, what, startpos) end
char = strsub (str, pos, pos)
if char == ":" then
if val1 == nil then
return nil, pos, "cannot use nil as table index (at " .. loc (str, pos) .. ")"
end
pos = scanwhite (str, pos + 1)
if not pos then return unterminated (str, what, startpos) end
local val2
val2, pos, err = scanvalue (str, pos, nullval, objectmeta, arraymeta)
if err then return nil, pos, err end
tbl[val1] = val2
pos = scanwhite (str, pos)
if not pos then return unterminated (str, what, startpos) end
char = strsub (str, pos, pos)
else
n = n + 1
tbl[n] = val1
end
if char == "," then
pos = pos + 1
end
end
end
scanvalue = function (str, pos, nullval, objectmeta, arraymeta)
pos = pos or 1
pos = scanwhite (str, pos)
if not pos then
return nil, strlen (str) + 1, "no valid JSON value (reached the end)"
end
local char = strsub (str, pos, pos)
if char == "{" then
return scantable ('object', "}", str, pos, nullval, objectmeta, arraymeta)
elseif char == "[" then
return scantable ('array', "]", str, pos, nullval, objectmeta, arraymeta)
elseif char == "\"" then
return scanstring (str, pos)
else
local pstart, pend = strfind (str, "^%-?[%d%.]+[eE]?[%+%-]?%d*", pos)
if pstart then
local number = str2num (strsub (str, pstart, pend))
if number then
return number, pend + 1
end
end
pstart, pend = strfind (str, "^%a%w*", pos)
if pstart then
local name = strsub (str, pstart, pend)
if name == "true" then
return true, pend + 1
elseif name == "false" then
return false, pend + 1
elseif name == "null" then
return nullval, pend + 1
end
end
return nil, pos, "no valid JSON value at " .. loc (str, pos)
end
end
local function optionalmetatables(...)
if select("#", ...) > 0 then
return ...
else
return {__jsontype = 'object'}, {__jsontype = 'array'}
end
end
function json.decode (str, pos, nullval, ...)
local objectmeta, arraymeta = optionalmetatables(...)
return scanvalue (str, pos, nullval, objectmeta, arraymeta)
end
function json.use_lpeg ()
local g = require ("lpeg")
if g.version() == "0.11" then
error "due to a bug in LPeg 0.11, it cannot be used for JSON matching"
end
local pegmatch = g.match
local P, S, R = g.P, g.S, g.R
local function ErrorCall (str, pos, msg, state)
if not state.msg then
state.msg = msg .. " at " .. loc (str, pos)
state.pos = pos
end
return false
end
local function Err (msg)
return g.Cmt (g.Cc (msg) * g.Carg (2), ErrorCall)
end
local SingleLineComment = P"//" * (1 - S"\n\r")^0
local MultiLineComment = P"/*" * (1 - P"*/")^0 * P"*/"
local Space = (S" \n\r\t" + P"\239\187\191" + SingleLineComment + MultiLineComment)^0
local PlainChar = 1 - S"\"\\\n\r"
local EscapeSequence = (P"\\" * g.C (S"\"\\/bfnrt" + Err "unsupported escape sequence")) / escapechars
local HexDigit = R("09", "af", "AF")
local function UTF16Surrogate (match, pos, high, low)
high, low = tonumber (high, 16), tonumber (low, 16)
if 0xD800 <= high and high <= 0xDBff and 0xDC00 <= low and low <= 0xDFFF then
return true, unichar ((high - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000)
else
return false
end
end
local function UTF16BMP (hex)
return unichar (tonumber (hex, 16))
end
local U16Sequence = (P"\\u" * g.C (HexDigit * HexDigit * HexDigit * HexDigit))
local UnicodeEscape = g.Cmt (U16Sequence * U16Sequence, UTF16Surrogate) + U16Sequence/UTF16BMP
local Char = UnicodeEscape + EscapeSequence + PlainChar
local String = P"\"" * g.Cs (Char ^ 0) * (P"\"" + Err "unterminated string")
local Integer = P"-"^(-1) * (P"0" + (R"19" * R"09"^0))
local Fractal = P"." * R"09"^0
local Exponent = (S"eE") * (S"+-")^(-1) * R"09"^1
local Number = (Integer * Fractal^(-1) * Exponent^(-1))/str2num
local Constant = P"true" * g.Cc (true) + P"false" * g.Cc (false) + P"null" * g.Carg (1)
local SimpleValue = Number + String + Constant
local ArrayContent, ObjectContent
-- The functions parsearray and parseobject parse only a single value/pair
-- at a time and store them directly to avoid hitting the LPeg limits.
local function parsearray (str, pos, nullval, state)
local obj, cont
local npos
local t, nt = {}, 0
repeat
obj, cont, npos = pegmatch (ArrayContent, str, pos, nullval, state)
if not npos then break end
pos = npos
nt = nt + 1
t[nt] = obj
until cont == 'last'
return pos, setmetatable (t, state.arraymeta)
end
local function parseobject (str, pos, nullval, state)
local obj, key, cont
local npos
local t = {}
repeat
key, obj, cont, npos = pegmatch (ObjectContent, str, pos, nullval, state)
if not npos then break end
pos = npos
t[key] = obj
until cont == 'last'
return pos, setmetatable (t, state.objectmeta)
end
local Array = P"[" * g.Cmt (g.Carg(1) * g.Carg(2), parsearray) * Space * (P"]" + Err "']' expected")
local Object = P"{" * g.Cmt (g.Carg(1) * g.Carg(2), parseobject) * Space * (P"}" + Err "'}' expected")
local Value = Space * (Array + Object + SimpleValue)
local ExpectedValue = Value + Space * Err "value expected"
ArrayContent = Value * Space * (P"," * g.Cc'cont' + g.Cc'last') * g.Cp()
local Pair = g.Cg (Space * String * Space * (P":" + Err "colon expected") * ExpectedValue)
ObjectContent = Pair * Space * (P"," * g.Cc'cont' + g.Cc'last') * g.Cp()
local DecodeValue = ExpectedValue * g.Cp ()
function json.decode (str, pos, nullval, ...)
local state = {}
state.objectmeta, state.arraymeta = optionalmetatables(...)
local obj, retpos = pegmatch (DecodeValue, str, pos, nullval, state)
if state.msg then
return nil, state.pos, state.msg
else
return obj, retpos
end
end
-- use this function only once:
json.use_lpeg = function () return json end
json.using_lpeg = true
return json -- so you can get the module using json = require "dkjson".use_lpeg()
end
-- End Lub JSON Lib

View File

@ -0,0 +1,8 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="Alert.lua"/>
<Script file="DB.lua"/>
<Script file="Math.lua"/>
<Script file="Money.lua"/>
<Script file="Option.lua"/>
<Script file="TSM.lua"/>
</Ui>

5
Function/Math.lua Normal file
View File

@ -0,0 +1,5 @@
-- MxW (MxW Addon)
-- By mikx
-- https://git.mikx.ca/wow-addons/MxW_Addon
-- Licensed under the GNU General Public License 3.0
-- See included License file for more informations.

41
Function/Money.lua Normal file
View File

@ -0,0 +1,41 @@
-- MxW (MxW Addon)
-- By mikx
-- https://git.mikx.ca/wow-addons/MxW_Addon
-- Licensed under the GNU General Public License 3.0
-- See included License file for more informations.
local MX = LibStub("AceAddon-3.0"):GetAddon("MxW");
local L = LibStub("AceLocale-3.0"):GetLocale("MxW");
local COLOR_COPPER = "|cffeda55f"
local COLOR_SILVER = "|cffc7c7cf"
local COLOR_GOLD = "|cffffd700"
local COLOR_WHITE = "|cffffffff"
function MX:FormatMoney(money)
local ret = ""
local gold = floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD));
local silver = floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER);
local copper = mod(money, COPPER_PER_SILVER);
if (gold == 0) then
return format("%s%02ds|r %s%02dc|r", COLOR_SILVER, silver, COLOR_COPPER, copper)
end
if (gold > 0) then
return format("%s%02dg|r %s%02ds|r %s%02dc|r", COLOR_GOLD, gold, COLOR_SILVER, silver, COLOR_COPPER, copper)
end
end
function MX:FormatMoneyShort(money)
local ret = ""
local gold = floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD));
local silver = floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER);
local copper = mod(money, COPPER_PER_SILVER);
if (gold == 0) then
return format("%s%02ds|r %s%02dc|r", COLOR_SILVER, silver, COLOR_COPPER, copper)
end
if (gold > 0) then
return format("%s%sg%s", COLOR_GOLD, gold, COLOR_WHITE)
end
end

65
Function/Option.lua Normal file
View File

@ -0,0 +1,65 @@
-- MxW (MxW Addon)
-- By mikx
-- https://git.mikx.ca/wow-addons/MxW_Addon
-- Licensed under the GNU General Public License 3.0
-- See included License file for more informations.
local MX = LibStub("AceAddon-3.0"):GetAddon("MxW");
local L = LibStub("AceLocale-3.0"):GetLocale("MxW");
function MX:OptionMinimumUIGet()
return Farmer_Logic_MinUI;
end
function MX:OptionMinimumUISet(value)
Farmer_Logic_MinUI = value;
end
function MX:OnInitialize()
LibStub("AceConfig-3.0"):RegisterOptionsTable("MxW", options)
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MxW", "MxW")
self:RegisterChatCommand("mxw", "ChatCommand")
end
function MX:ChatCommand(input)
if not input or input:trim() == "" then
MX:ShowHistory();
else
LibStub("AceConfigCmd-3.0"):HandleCommand("mxw", "MxW", input)
end
end
options = {
type = 'group',
name = "Général",
order = 1,
args = {
text = {
type = 'group',
name = "Affichage",
inline = true,
args = {
mouseheader = {
type = 'header',
name = "Général",
order = 0,
},
delaydivisor = {
type = 'range',
name = 'Text speed',
desc = "Description",
min = 5,
max = 40,
step = 5,
order = 1,
get = function(self, val)
--
end,
set = function(self, val)
--
end,
},
},
}
}
}

20
Function/TSM.lua Normal file
View File

@ -0,0 +1,20 @@
-- MxW (MxW Addon)
-- By mikx
-- https://git.mikx.ca/wow-addons/MxW_Addon
-- Licensed under the GNU General Public License 3.0
-- See included License file for more informations.
-- TSM.lua
-- TradeSkillMaster Functions
local MX = LibStub("AceAddon-3.0"):GetAddon("MxW");
local TSMVERSION = GetAddOnMetadata("TradeSkillMaster", "Version")
MX.TSM = MX.TSM or {}
-- GetItemValue(itemID, priceSource)
-- Return itemID value as a int using priceSource
function MX.TSM:GetItemValue(itemID, priceSource)
return TSMAPI:GetItemValue(itemID, priceSource)
end

674
LICENSE Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
MxW
Copyright (C) 2017 wow-addons
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
MxW Copyright (C) 2017 wow-addons
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -0,0 +1,674 @@
--- **AceAddon-3.0** provides a template for creating addon objects.
-- It'll provide you with a set of callback functions that allow you to simplify the loading
-- process of your addon.\\
-- Callbacks provided are:\\
-- * **OnInitialize**, which is called directly after the addon is fully loaded.
-- * **OnEnable** which gets called during the PLAYER_LOGIN event, when most of the data provided by the game is already present.
-- * **OnDisable**, which is only called when your addon is manually being disabled.
-- @usage
-- -- A small (but complete) addon, that doesn't do anything,
-- -- but shows usage of the callbacks.
-- local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
--
-- function MyAddon:OnInitialize()
-- -- do init tasks here, like loading the Saved Variables,
-- -- or setting up slash commands.
-- end
--
-- function MyAddon:OnEnable()
-- -- Do more initialization here, that really enables the use of your addon.
-- -- Register Events, Hook functions, Create Frames, Get information from
-- -- the game that wasn't available in OnInitialize
-- end
--
-- function MyAddon:OnDisable()
-- -- Unhook, Unregister Events, Hide frames that you created.
-- -- You would probably only use an OnDisable if you want to
-- -- build a "standby" mode, or be able to toggle modules on/off.
-- end
-- @class file
-- @name AceAddon-3.0.lua
-- @release $Id: AceAddon-3.0.lua 1084 2013-04-27 20:14:11Z nevcairiel $
local MAJOR, MINOR = "AceAddon-3.0", 12
local AceAddon, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not AceAddon then return end -- No Upgrade needed.
AceAddon.frame = AceAddon.frame or CreateFrame("Frame", "AceAddon30Frame") -- Our very own frame
AceAddon.addons = AceAddon.addons or {} -- addons in general
AceAddon.statuses = AceAddon.statuses or {} -- statuses of addon.
AceAddon.initializequeue = AceAddon.initializequeue or {} -- addons that are new and not initialized
AceAddon.enablequeue = AceAddon.enablequeue or {} -- addons that are initialized and waiting to be enabled
AceAddon.embeds = AceAddon.embeds or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end }) -- contains a list of libraries embedded in an addon
-- Lua APIs
local tinsert, tconcat, tremove = table.insert, table.concat, table.remove
local fmt, tostring = string.format, tostring
local select, pairs, next, type, unpack = select, pairs, next, type, unpack
local loadstring, assert, error = loadstring, assert, error
local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
-- List them here for Mikk's FindGlobals script
-- GLOBALS: LibStub, IsLoggedIn, geterrorhandler
--[[
xpcall safecall implementation
]]
local xpcall = xpcall
local function errorhandler(err)
return geterrorhandler()(err)
end
local function CreateDispatcher(argCount)
local code = [[
local xpcall, eh = ...
local method, ARGS
local function call() return method(ARGS) end
local function dispatch(func, ...)
method = func
if not method then return end
ARGS = ...
return xpcall(call, eh)
end
return dispatch
]]
local ARGS = {}
for i = 1, argCount do ARGS[i] = "arg"..i end
code = code:gsub("ARGS", tconcat(ARGS, ", "))
return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler)
end
local Dispatchers = setmetatable({}, {__index=function(self, argCount)
local dispatcher = CreateDispatcher(argCount)
rawset(self, argCount, dispatcher)
return dispatcher
end})
Dispatchers[0] = function(func)
return xpcall(func, errorhandler)
end
local function safecall(func, ...)
-- we check to see if the func is passed is actually a function here and don't error when it isn't
-- this safecall is used for optional functions like OnInitialize OnEnable etc. When they are not
-- present execution should continue without hinderance
if type(func) == "function" then
return Dispatchers[select('#', ...)](func, ...)
end
end
-- local functions that will be implemented further down
local Enable, Disable, EnableModule, DisableModule, Embed, NewModule, GetModule, GetName, SetDefaultModuleState, SetDefaultModuleLibraries, SetEnabledState, SetDefaultModulePrototype
-- used in the addon metatable
local function addontostring( self ) return self.name end
-- Check if the addon is queued for initialization
local function queuedForInitialization(addon)
for i = 1, #AceAddon.initializequeue do
if AceAddon.initializequeue[i] == addon then
return true
end
end
return false
end
--- Create a new AceAddon-3.0 addon.
-- Any libraries you specified will be embeded, and the addon will be scheduled for
-- its OnInitialize and OnEnable callbacks.
-- The final addon object, with all libraries embeded, will be returned.
-- @paramsig [object ,]name[, lib, ...]
-- @param object Table to use as a base for the addon (optional)
-- @param name Name of the addon object to create
-- @param lib List of libraries to embed into the addon
-- @usage
-- -- Create a simple addon object
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceEvent-3.0")
--
-- -- Create a Addon object based on the table of a frame
-- local MyFrame = CreateFrame("Frame")
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon(MyFrame, "MyAddon", "AceEvent-3.0")
function AceAddon:NewAddon(objectorname, ...)
local object,name
local i=1
if type(objectorname)=="table" then
object=objectorname
name=...
i=2
else
name=objectorname
end
if type(name)~="string" then
error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2)
end
if self.addons[name] then
error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon '%s' already exists."):format(name), 2)
end
object = object or {}
object.name = name
local addonmeta = {}
local oldmeta = getmetatable(object)
if oldmeta then
for k, v in pairs(oldmeta) do addonmeta[k] = v end
end
addonmeta.__tostring = addontostring
setmetatable( object, addonmeta )
self.addons[name] = object
object.modules = {}
object.orderedModules = {}
object.defaultModuleLibraries = {}
Embed( object ) -- embed NewModule, GetModule methods
self:EmbedLibraries(object, select(i,...))
-- add to queue of addons to be initialized upon ADDON_LOADED
tinsert(self.initializequeue, object)
return object
end
--- Get the addon object by its name from the internal AceAddon registry.
-- Throws an error if the addon object cannot be found (except if silent is set).
-- @param name unique name of the addon object
-- @param silent if true, the addon is optional, silently return nil if its not found
-- @usage
-- -- Get the Addon
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
function AceAddon:GetAddon(name, silent)
if not silent and not self.addons[name] then
error(("Usage: GetAddon(name): 'name' - Cannot find an AceAddon '%s'."):format(tostring(name)), 2)
end
return self.addons[name]
end
-- - Embed a list of libraries into the specified addon.
-- This function will try to embed all of the listed libraries into the addon
-- and error if a single one fails.
--
-- **Note:** This function is for internal use by :NewAddon/:NewModule
-- @paramsig addon, [lib, ...]
-- @param addon addon object to embed the libs in
-- @param lib List of libraries to embed into the addon
function AceAddon:EmbedLibraries(addon, ...)
for i=1,select("#", ... ) do
local libname = select(i, ...)
self:EmbedLibrary(addon, libname, false, 4)
end
end
-- - Embed a library into the addon object.
-- This function will check if the specified library is registered with LibStub
-- and if it has a :Embed function to call. It'll error if any of those conditions
-- fails.
--
-- **Note:** This function is for internal use by :EmbedLibraries
-- @paramsig addon, libname[, silent[, offset]]
-- @param addon addon object to embed the library in
-- @param libname name of the library to embed
-- @param silent marks an embed to fail silently if the library doesn't exist (optional)
-- @param offset will push the error messages back to said offset, defaults to 2 (optional)
function AceAddon:EmbedLibrary(addon, libname, silent, offset)
local lib = LibStub:GetLibrary(libname, true)
if not lib and not silent then
error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Cannot find a library instance of %q."):format(tostring(libname)), offset or 2)
elseif lib and type(lib.Embed) == "function" then
lib:Embed(addon)
tinsert(self.embeds[addon], libname)
return true
elseif lib then
error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Library '%s' is not Embed capable"):format(libname), offset or 2)
end
end
--- Return the specified module from an addon object.
-- Throws an error if the addon object cannot be found (except if silent is set)
-- @name //addon//:GetModule
-- @paramsig name[, silent]
-- @param name unique name of the module
-- @param silent if true, the module is optional, silently return nil if its not found (optional)
-- @usage
-- -- Get the Addon
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
-- -- Get the Module
-- MyModule = MyAddon:GetModule("MyModule")
function GetModule(self, name, silent)
if not self.modules[name] and not silent then
error(("Usage: GetModule(name, silent): 'name' - Cannot find module '%s'."):format(tostring(name)), 2)
end
return self.modules[name]
end
local function IsModuleTrue(self) return true end
--- Create a new module for the addon.
-- The new module can have its own embeded libraries and/or use a module prototype to be mixed into the module.\\
-- A module has the same functionality as a real addon, it can have modules of its own, and has the same API as
-- an addon object.
-- @name //addon//:NewModule
-- @paramsig name[, prototype|lib[, lib, ...]]
-- @param name unique name of the module
-- @param prototype object to derive this module from, methods and values from this table will be mixed into the module (optional)
-- @param lib List of libraries to embed into the addon
-- @usage
-- -- Create a module with some embeded libraries
-- MyModule = MyAddon:NewModule("MyModule", "AceEvent-3.0", "AceHook-3.0")
--
-- -- Create a module with a prototype
-- local prototype = { OnEnable = function(self) print("OnEnable called!") end }
-- MyModule = MyAddon:NewModule("MyModule", prototype, "AceEvent-3.0", "AceHook-3.0")
function NewModule(self, name, prototype, ...)
if type(name) ~= "string" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) end
if type(prototype) ~= "string" and type(prototype) ~= "table" and type(prototype) ~= "nil" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'prototype' - table (prototype), string (lib) or nil expected got '%s'."):format(type(prototype)), 2) end
if self.modules[name] then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - Module '%s' already exists."):format(name), 2) end
-- modules are basically addons. We treat them as such. They will be added to the initializequeue properly as well.
-- NewModule can only be called after the parent addon is present thus the modules will be initialized after their parent is.
local module = AceAddon:NewAddon(fmt("%s_%s", self.name or tostring(self), name))
module.IsModule = IsModuleTrue
module:SetEnabledState(self.defaultModuleState)
module.moduleName = name
if type(prototype) == "string" then
AceAddon:EmbedLibraries(module, prototype, ...)
else
AceAddon:EmbedLibraries(module, ...)
end
AceAddon:EmbedLibraries(module, unpack(self.defaultModuleLibraries))
if not prototype or type(prototype) == "string" then
prototype = self.defaultModulePrototype or nil
end
if type(prototype) == "table" then
local mt = getmetatable(module)
mt.__index = prototype
setmetatable(module, mt) -- More of a Base class type feel.
end
safecall(self.OnModuleCreated, self, module) -- Was in Ace2 and I think it could be a cool thing to have handy.
self.modules[name] = module
tinsert(self.orderedModules, module)
return module
end
--- Returns the real name of the addon or module, without any prefix.
-- @name //addon//:GetName
-- @paramsig
-- @usage
-- print(MyAddon:GetName())
-- -- prints "MyAddon"
function GetName(self)
return self.moduleName or self.name
end
--- Enables the Addon, if possible, return true or false depending on success.
-- This internally calls AceAddon:EnableAddon(), thus dispatching a OnEnable callback
-- and enabling all modules of the addon (unless explicitly disabled).\\
-- :Enable() also sets the internal `enableState` variable to true
-- @name //addon//:Enable
-- @paramsig
-- @usage
-- -- Enable MyModule
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
-- MyModule = MyAddon:GetModule("MyModule")
-- MyModule:Enable()
function Enable(self)
self:SetEnabledState(true)
-- nevcairiel 2013-04-27: don't enable an addon/module if its queued for init still
-- it'll be enabled after the init process
if not queuedForInitialization(self) then
return AceAddon:EnableAddon(self)
end
end
--- Disables the Addon, if possible, return true or false depending on success.
-- This internally calls AceAddon:DisableAddon(), thus dispatching a OnDisable callback
-- and disabling all modules of the addon.\\
-- :Disable() also sets the internal `enableState` variable to false
-- @name //addon//:Disable
-- @paramsig
-- @usage
-- -- Disable MyAddon
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
-- MyAddon:Disable()
function Disable(self)
self:SetEnabledState(false)
return AceAddon:DisableAddon(self)
end
--- Enables the Module, if possible, return true or false depending on success.
-- Short-hand function that retrieves the module via `:GetModule` and calls `:Enable` on the module object.
-- @name //addon//:EnableModule
-- @paramsig name
-- @usage
-- -- Enable MyModule using :GetModule
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
-- MyModule = MyAddon:GetModule("MyModule")
-- MyModule:Enable()
--
-- -- Enable MyModule using the short-hand
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
-- MyAddon:EnableModule("MyModule")
function EnableModule(self, name)
local module = self:GetModule( name )
return module:Enable()
end
--- Disables the Module, if possible, return true or false depending on success.
-- Short-hand function that retrieves the module via `:GetModule` and calls `:Disable` on the module object.
-- @name //addon//:DisableModule
-- @paramsig name
-- @usage
-- -- Disable MyModule using :GetModule
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
-- MyModule = MyAddon:GetModule("MyModule")
-- MyModule:Disable()
--
-- -- Disable MyModule using the short-hand
-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")
-- MyAddon:DisableModule("MyModule")
function DisableModule(self, name)
local module = self:GetModule( name )
return module:Disable()
end
--- Set the default libraries to be mixed into all modules created by this object.
-- Note that you can only change the default module libraries before any module is created.
-- @name //addon//:SetDefaultModuleLibraries
-- @paramsig lib[, lib, ...]
-- @param lib List of libraries to embed into the addon
-- @usage
-- -- Create the addon object
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
-- -- Configure default libraries for modules (all modules need AceEvent-3.0)
-- MyAddon:SetDefaultModuleLibraries("AceEvent-3.0")
-- -- Create a module
-- MyModule = MyAddon:NewModule("MyModule")
function SetDefaultModuleLibraries(self, ...)
if next(self.modules) then
error("Usage: SetDefaultModuleLibraries(...): cannot change the module defaults after a module has been registered.", 2)
end
self.defaultModuleLibraries = {...}
end
--- Set the default state in which new modules are being created.
-- Note that you can only change the default state before any module is created.
-- @name //addon//:SetDefaultModuleState
-- @paramsig state
-- @param state Default state for new modules, true for enabled, false for disabled
-- @usage
-- -- Create the addon object
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
-- -- Set the default state to "disabled"
-- MyAddon:SetDefaultModuleState(false)
-- -- Create a module and explicilty enable it
-- MyModule = MyAddon:NewModule("MyModule")
-- MyModule:Enable()
function SetDefaultModuleState(self, state)
if next(self.modules) then
error("Usage: SetDefaultModuleState(state): cannot change the module defaults after a module has been registered.", 2)
end
self.defaultModuleState = state
end
--- Set the default prototype to use for new modules on creation.
-- Note that you can only change the default prototype before any module is created.
-- @name //addon//:SetDefaultModulePrototype
-- @paramsig prototype
-- @param prototype Default prototype for the new modules (table)
-- @usage
-- -- Define a prototype
-- local prototype = { OnEnable = function(self) print("OnEnable called!") end }
-- -- Set the default prototype
-- MyAddon:SetDefaultModulePrototype(prototype)
-- -- Create a module and explicitly Enable it
-- MyModule = MyAddon:NewModule("MyModule")
-- MyModule:Enable()
-- -- should print "OnEnable called!" now
-- @see NewModule
function SetDefaultModulePrototype(self, prototype)
if next(self.modules) then
error("Usage: SetDefaultModulePrototype(prototype): cannot change the module defaults after a module has been registered.", 2)
end
if type(prototype) ~= "table" then
error(("Usage: SetDefaultModulePrototype(prototype): 'prototype' - table expected got '%s'."):format(type(prototype)), 2)
end
self.defaultModulePrototype = prototype
end
--- Set the state of an addon or module
-- This should only be called before any enabling actually happend, e.g. in/before OnInitialize.
-- @name //addon//:SetEnabledState
-- @paramsig state
-- @param state the state of an addon or module (enabled=true, disabled=false)
function SetEnabledState(self, state)
self.enabledState = state
end
--- Return an iterator of all modules associated to the addon.
-- @name //addon//:IterateModules
-- @paramsig
-- @usage
-- -- Enable all modules
-- for name, module in MyAddon:IterateModules() do
-- module:Enable()
-- end
local function IterateModules(self) return pairs(self.modules) end
-- Returns an iterator of all embeds in the addon
-- @name //addon//:IterateEmbeds
-- @paramsig
local function IterateEmbeds(self) return pairs(AceAddon.embeds[self]) end
--- Query the enabledState of an addon.
-- @name //addon//:IsEnabled
-- @paramsig
-- @usage
-- if MyAddon:IsEnabled() then
-- MyAddon:Disable()
-- end
local function IsEnabled(self) return self.enabledState end
local mixins = {
NewModule = NewModule,
GetModule = GetModule,
Enable = Enable,
Disable = Disable,
EnableModule = EnableModule,
DisableModule = DisableModule,
IsEnabled = IsEnabled,
SetDefaultModuleLibraries = SetDefaultModuleLibraries,
SetDefaultModuleState = SetDefaultModuleState,
SetDefaultModulePrototype = SetDefaultModulePrototype,
SetEnabledState = SetEnabledState,
IterateModules = IterateModules,
IterateEmbeds = IterateEmbeds,
GetName = GetName,
}
local function IsModule(self) return false end
local pmixins = {
defaultModuleState = true,
enabledState = true,
IsModule = IsModule,
}
-- Embed( target )
-- target (object) - target object to embed aceaddon in
--
-- this is a local function specifically since it's meant to be only called internally
function Embed(target, skipPMixins)
for k, v in pairs(mixins) do
target[k] = v
end
if not skipPMixins then
for k, v in pairs(pmixins) do
target[k] = target[k] or v
end
end
end
-- - Initialize the addon after creation.
-- This function is only used internally during the ADDON_LOADED event
-- It will call the **OnInitialize** function on the addon object (if present),
-- and the **OnEmbedInitialize** function on all embeded libraries.
--
-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing.
-- @param addon addon object to intialize
function AceAddon:InitializeAddon(addon)
safecall(addon.OnInitialize, addon)
local embeds = self.embeds[addon]
for i = 1, #embeds do
local lib = LibStub:GetLibrary(embeds[i], true)
if lib then safecall(lib.OnEmbedInitialize, lib, addon) end
end
-- we don't call InitializeAddon on modules specifically, this is handled
-- from the event handler and only done _once_
end
-- - Enable the addon after creation.
-- Note: This function is only used internally during the PLAYER_LOGIN event, or during ADDON_LOADED,
-- if IsLoggedIn() already returns true at that point, e.g. for LoD Addons.
-- It will call the **OnEnable** function on the addon object (if present),
-- and the **OnEmbedEnable** function on all embeded libraries.\\
-- This function does not toggle the enable state of the addon itself, and will return early if the addon is disabled.
--
-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing.
-- Use :Enable on the addon itself instead.
-- @param addon addon object to enable
function AceAddon:EnableAddon(addon)
if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end
if self.statuses[addon.name] or not addon.enabledState then return false end
-- set the statuses first, before calling the OnEnable. this allows for Disabling of the addon in OnEnable.
self.statuses[addon.name] = true
safecall(addon.OnEnable, addon)
-- make sure we're still enabled before continueing
if self.statuses[addon.name] then
local embeds = self.embeds[addon]
for i = 1, #embeds do
local lib = LibStub:GetLibrary(embeds[i], true)
if lib then safecall(lib.OnEmbedEnable, lib, addon) end
end
-- enable possible modules.
local modules = addon.orderedModules
for i = 1, #modules do
self:EnableAddon(modules[i])
end
end
return self.statuses[addon.name] -- return true if we're disabled
end
-- - Disable the addon
-- Note: This function is only used internally.
-- It will call the **OnDisable** function on the addon object (if present),
-- and the **OnEmbedDisable** function on all embeded libraries.\\
-- This function does not toggle the enable state of the addon itself, and will return early if the addon is still enabled.
--
-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing.
-- Use :Disable on the addon itself instead.
-- @param addon addon object to enable
function AceAddon:DisableAddon(addon)
if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end
if not self.statuses[addon.name] then return false end
-- set statuses first before calling OnDisable, this allows for aborting the disable in OnDisable.
self.statuses[addon.name] = false
safecall( addon.OnDisable, addon )
-- make sure we're still disabling...
if not self.statuses[addon.name] then
local embeds = self.embeds[addon]
for i = 1, #embeds do
local lib = LibStub:GetLibrary(embeds[i], true)
if lib then safecall(lib.OnEmbedDisable, lib, addon) end
end
-- disable possible modules.
local modules = addon.orderedModules
for i = 1, #modules do
self:DisableAddon(modules[i])
end
end
return not self.statuses[addon.name] -- return true if we're disabled
end
--- Get an iterator over all registered addons.
-- @usage
-- -- Print a list of all installed AceAddon's
-- for name, addon in AceAddon:IterateAddons() do
-- print("Addon: " .. name)
-- end
function AceAddon:IterateAddons() return pairs(self.addons) end
--- Get an iterator over the internal status registry.
-- @usage
-- -- Print a list of all enabled addons
-- for name, status in AceAddon:IterateAddonStatus() do
-- if status then
-- print("EnabledAddon: " .. name)
-- end
-- end
function AceAddon:IterateAddonStatus() return pairs(self.statuses) end
-- Following Iterators are deprecated, and their addon specific versions should be used
-- e.g. addon:IterateEmbeds() instead of :IterateEmbedsOnAddon(addon)
function AceAddon:IterateEmbedsOnAddon(addon) return pairs(self.embeds[addon]) end
function AceAddon:IterateModulesOfAddon(addon) return pairs(addon.modules) end
-- Event Handling
local function onEvent(this, event, arg1)
-- 2011-08-17 nevcairiel - ignore the load event of Blizzard_DebugTools, so a potential startup error isn't swallowed up
if (event == "ADDON_LOADED" and arg1 ~= "Blizzard_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
while(#AceAddon.initializequeue > 0) do
local addon = tremove(AceAddon.initializequeue, 1)
-- this might be an issue with recursion - TODO: validate
if event == "ADDON_LOADED" then addon.baseName = arg1 end
AceAddon:InitializeAddon(addon)
tinsert(AceAddon.enablequeue, addon)
end
if IsLoggedIn() then
while(#AceAddon.enablequeue > 0) do
local addon = tremove(AceAddon.enablequeue, 1)
AceAddon:EnableAddon(addon)
end
end
end
end
AceAddon.frame:RegisterEvent("ADDON_LOADED")
AceAddon.frame:RegisterEvent("PLAYER_LOGIN")
AceAddon.frame:SetScript("OnEvent", onEvent)
-- upgrade embeded
for name, addon in pairs(AceAddon.addons) do
Embed(addon, true)
end
-- 2010-10-27 nevcairiel - add new "orderedModules" table
if oldminor and oldminor < 10 then
for name, addon in pairs(AceAddon.addons) do
addon.orderedModules = {}
for module_name, module in pairs(addon.modules) do
tinsert(addon.orderedModules, module)
end
end
end

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="AceAddon-3.0.lua"/>
</Ui>

View File

@ -0,0 +1,302 @@
--- **AceComm-3.0** allows you to send messages of unlimited length over the addon comm channels.
-- It'll automatically split the messages into multiple parts and rebuild them on the receiving end.\\
-- **ChatThrottleLib** is of course being used to avoid being disconnected by the server.
--
-- **AceComm-3.0** can be embeded into your addon, either explicitly by calling AceComm:Embed(MyAddon) or by
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
-- and can be accessed directly, without having to explicitly call AceComm itself.\\
-- It is recommended to embed AceComm, otherwise you'll have to specify a custom `self` on all calls you
-- make into AceComm.
-- @class file
-- @name AceComm-3.0
-- @release $Id: AceComm-3.0.lua 1107 2014-02-19 16:40:32Z nevcairiel $
--[[ AceComm-3.0
TODO: Time out old data rotting around from dead senders? Not a HUGE deal since the number of possible sender names is somewhat limited.
]]
local MAJOR, MINOR = "AceComm-3.0", 9
local AceComm,oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not AceComm then return end
local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0")
local CTL = assert(ChatThrottleLib, "AceComm-3.0 requires ChatThrottleLib")
-- Lua APIs
local type, next, pairs, tostring = type, next, pairs, tostring
local strsub, strfind = string.sub, string.find
local match = string.match
local tinsert, tconcat = table.insert, table.concat
local error, assert = error, assert
-- WoW APIs
local Ambiguate = Ambiguate
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
-- List them here for Mikk's FindGlobals script
-- GLOBALS: LibStub, DEFAULT_CHAT_FRAME, geterrorhandler, RegisterAddonMessagePrefix
AceComm.embeds = AceComm.embeds or {}
-- for my sanity and yours, let's give the message type bytes some names
local MSG_MULTI_FIRST = "\001"
local MSG_MULTI_NEXT = "\002"
local MSG_MULTI_LAST = "\003"
local MSG_ESCAPE = "\004"
-- remove old structures (pre WoW 4.0)
AceComm.multipart_origprefixes = nil
AceComm.multipart_reassemblers = nil
-- the multipart message spool: indexed by a combination of sender+distribution+
AceComm.multipart_spool = AceComm.multipart_spool or {}
--- Register for Addon Traffic on a specified prefix
-- @param prefix A printable character (\032-\255) classification of the message (typically AddonName or AddonNameEvent), max 16 characters
-- @param method Callback to call on message reception: Function reference, or method name (string) to call on self. Defaults to "OnCommReceived"
function AceComm:RegisterComm(prefix, method)
if method == nil then
method = "OnCommReceived"
end
if #prefix > 16 then -- TODO: 15?
error("AceComm:RegisterComm(prefix,method): prefix length is limited to 16 characters")
end
RegisterAddonMessagePrefix(prefix)
return AceComm._RegisterComm(self, prefix, method) -- created by CallbackHandler
end
local warnedPrefix=false
--- Send a message over the Addon Channel
-- @param prefix A printable character (\032-\255) classification of the message (typically AddonName or AddonNameEvent)
-- @param text Data to send, nils (\000) not allowed. Any length.
-- @param distribution Addon channel, e.g. "RAID", "GUILD", etc; see SendAddonMessage API
-- @param target Destination for some distributions; see SendAddonMessage API
-- @param prio OPTIONAL: ChatThrottleLib priority, "BULK", "NORMAL" or "ALERT". Defaults to "NORMAL".
-- @param callbackFn OPTIONAL: callback function to be called as each chunk is sent. receives 3 args: the user supplied arg (see next), the number of bytes sent so far, and the number of bytes total to send.
-- @param callbackArg: OPTIONAL: first arg to the callback function. nil will be passed if not specified.
function AceComm:SendCommMessage(prefix, text, distribution, target, prio, callbackFn, callbackArg)
prio = prio or "NORMAL" -- pasta's reference implementation had different prio for singlepart and multipart, but that's a very bad idea since that can easily lead to out-of-sequence delivery!
if not( type(prefix)=="string" and
type(text)=="string" and
type(distribution)=="string" and
(target==nil or type(target)=="string") and
(prio=="BULK" or prio=="NORMAL" or prio=="ALERT")
) then
error('Usage: SendCommMessage(addon, "prefix", "text", "distribution"[, "target"[, "prio"[, callbackFn, callbackarg]]])', 2)
end
local textlen = #text
local maxtextlen = 255 -- Yes, the max is 255 even if the dev post said 256. I tested. Char 256+ get silently truncated. /Mikk, 20110327
local queueName = prefix..distribution..(target or "")
local ctlCallback = nil
if callbackFn then
ctlCallback = function(sent)
return callbackFn(callbackArg, sent, textlen)
end
end
local forceMultipart
if match(text, "^[\001-\009]") then -- 4.1+: see if the first character is a control character
-- we need to escape the first character with a \004
if textlen+1 > maxtextlen then -- would we go over the size limit?
forceMultipart = true -- just make it multipart, no escape problems then
else
text = "\004" .. text
end
end
if not forceMultipart and textlen <= maxtextlen then
-- fits all in one message
CTL:SendAddonMessage(prio, prefix, text, distribution, target, queueName, ctlCallback, textlen)
else
maxtextlen = maxtextlen - 1 -- 1 extra byte for part indicator in prefix(4.0)/start of message(4.1)
-- first part
local chunk = strsub(text, 1, maxtextlen)
CTL:SendAddonMessage(prio, prefix, MSG_MULTI_FIRST..chunk, distribution, target, queueName, ctlCallback, maxtextlen)
-- continuation
local pos = 1+maxtextlen
while pos+maxtextlen <= textlen do
chunk = strsub(text, pos, pos+maxtextlen-1)
CTL:SendAddonMessage(prio, prefix, MSG_MULTI_NEXT..chunk, distribution, target, queueName, ctlCallback, pos+maxtextlen-1)
pos = pos + maxtextlen
end
-- final part
chunk = strsub(text, pos)
CTL:SendAddonMessage(prio, prefix, MSG_MULTI_LAST..chunk, distribution, target, queueName, ctlCallback, textlen)
end
end
----------------------------------------
-- Message receiving
----------------------------------------
do
local compost = setmetatable({}, {__mode = "k"})
local function new()
local t = next(compost)
if t then
compost[t]=nil
for i=#t,3,-1 do -- faster than pairs loop. don't even nil out 1/2 since they'll be overwritten
t[i]=nil
end
return t
end
return {}
end
local function lostdatawarning(prefix,sender,where)
DEFAULT_CHAT_FRAME:AddMessage(MAJOR..": Warning: lost network data regarding '"..tostring(prefix).."' from '"..tostring(sender).."' (in "..where..")")
end
function AceComm:OnReceiveMultipartFirst(prefix, message, distribution, sender)
local key = prefix.."\t"..distribution.."\t"..sender -- a unique stream is defined by the prefix + distribution + sender
local spool = AceComm.multipart_spool
--[[
if spool[key] then
lostdatawarning(prefix,sender,"First")
-- continue and overwrite
end
--]]
spool[key] = message -- plain string for now
end
function AceComm:OnReceiveMultipartNext(prefix, message, distribution, sender)
local key = prefix.."\t"..distribution.."\t"..sender -- a unique stream is defined by the prefix + distribution + sender
local spool = AceComm.multipart_spool
local olddata = spool[key]
if not olddata then
--lostdatawarning(prefix,sender,"Next")
return
end
if type(olddata)~="table" then
-- ... but what we have is not a table. So make it one. (Pull a composted one if available)
local t = new()
t[1] = olddata -- add old data as first string
t[2] = message -- and new message as second string
spool[key] = t -- and put the table in the spool instead of the old string
else
tinsert(olddata, message)
end
end
function AceComm:OnReceiveMultipartLast(prefix, message, distribution, sender)
local key = prefix.."\t"..distribution.."\t"..sender -- a unique stream is defined by the prefix + distribution + sender
local spool = AceComm.multipart_spool
local olddata = spool[key]
if not olddata then
--lostdatawarning(prefix,sender,"End")
return
end
spool[key] = nil
if type(olddata) == "table" then
-- if we've received a "next", the spooled data will be a table for rapid & garbage-free tconcat
tinsert(olddata, message)
AceComm.callbacks:Fire(prefix, tconcat(olddata, ""), distribution, sender)
compost[olddata] = true
else
-- if we've only received a "first", the spooled data will still only be a string
AceComm.callbacks:Fire(prefix, olddata..message, distribution, sender)
end
end
end
----------------------------------------
-- Embed CallbackHandler
----------------------------------------
if not AceComm.callbacks then
AceComm.callbacks = CallbackHandler:New(AceComm,
"_RegisterComm",
"UnregisterComm",
"UnregisterAllComm")
end
AceComm.callbacks.OnUsed = nil
AceComm.callbacks.OnUnused = nil
local function OnEvent(self, event, prefix, message, distribution, sender)
if event == "CHAT_MSG_ADDON" then
sender = Ambiguate(sender, "none")
local control, rest = match(message, "^([\001-\009])(.*)")
if control then
if control==MSG_MULTI_FIRST then
AceComm:OnReceiveMultipartFirst(prefix, rest, distribution, sender)
elseif control==MSG_MULTI_NEXT then
AceComm:OnReceiveMultipartNext(prefix, rest, distribution, sender)
elseif control==MSG_MULTI_LAST then
AceComm:OnReceiveMultipartLast(prefix, rest, distribution, sender)
elseif control==MSG_ESCAPE then
AceComm.callbacks:Fire(prefix, rest, distribution, sender)
else
-- unknown control character, ignore SILENTLY (dont warn unnecessarily about future extensions!)
end
else
-- single part: fire it off immediately and let CallbackHandler decide if it's registered or not
AceComm.callbacks:Fire(prefix, message, distribution, sender)
end
else
assert(false, "Received "..tostring(event).." event?!")
end
end
AceComm.frame = AceComm.frame or CreateFrame("Frame", "AceComm30Frame")
AceComm.frame:SetScript("OnEvent", OnEvent)
AceComm.frame:UnregisterAllEvents()
AceComm.frame:RegisterEvent("CHAT_MSG_ADDON")
----------------------------------------
-- Base library stuff
----------------------------------------
local mixins = {
"RegisterComm",
"UnregisterComm",
"UnregisterAllComm",
"SendCommMessage",
}
-- Embeds AceComm-3.0 into the target object making the functions from the mixins list available on target:..
-- @param target target object to embed AceComm-3.0 in
function AceComm:Embed(target)
for k, v in pairs(mixins) do
target[v] = self[v]
end
self.embeds[target] = true
return target
end
function AceComm:OnEmbedDisable(target)
target:UnregisterAllComm()
end
-- Update embeds
for target, v in pairs(AceComm.embeds) do
AceComm:Embed(target)
end

View File

@ -0,0 +1,5 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="ChatThrottleLib.lua"/>
<Script file="AceComm-3.0.lua"/>
</Ui>

View File

@ -0,0 +1,524 @@
--
-- ChatThrottleLib by Mikk
--
-- Manages AddOn chat output to keep player from getting kicked off.
--
-- ChatThrottleLib:SendChatMessage/:SendAddonMessage functions that accept
-- a Priority ("BULK", "NORMAL", "ALERT") as well as prefix for SendChatMessage.
--
-- Priorities get an equal share of available bandwidth when fully loaded.
-- Communication channels are separated on extension+chattype+destination and
-- get round-robinned. (Destination only matters for whispers and channels,
-- obviously)
--
-- Will install hooks for SendChatMessage and SendAddonMessage to measure
-- bandwidth bypassing the library and use less bandwidth itself.
--
--
-- Fully embeddable library. Just copy this file into your addon directory,
-- add it to the .toc, and it's done.
--
-- Can run as a standalone addon also, but, really, just embed it! :-)
--
-- LICENSE: ChatThrottleLib is released into the Public Domain
--
local CTL_VERSION = 23
local _G = _G
if _G.ChatThrottleLib then
if _G.ChatThrottleLib.version >= CTL_VERSION then
-- There's already a newer (or same) version loaded. Buh-bye.
return
elseif not _G.ChatThrottleLib.securelyHooked then
print("ChatThrottleLib: Warning: There's an ANCIENT ChatThrottleLib.lua (pre-wow 2.0, <v16) in an addon somewhere. Get the addon updated or copy in a newer ChatThrottleLib.lua (>=v16) in it!")
-- ATTEMPT to unhook; this'll behave badly if someone else has hooked...
-- ... and if someone has securehooked, they can kiss that goodbye too... >.<
_G.SendChatMessage = _G.ChatThrottleLib.ORIG_SendChatMessage
if _G.ChatThrottleLib.ORIG_SendAddonMessage then
_G.SendAddonMessage = _G.ChatThrottleLib.ORIG_SendAddonMessage
end
end
_G.ChatThrottleLib.ORIG_SendChatMessage = nil
_G.ChatThrottleLib.ORIG_SendAddonMessage = nil
end
if not _G.ChatThrottleLib then
_G.ChatThrottleLib = {}
end
ChatThrottleLib = _G.ChatThrottleLib -- in case some addon does "local ChatThrottleLib" above us and we're copypasted (AceComm-2, sigh)
local ChatThrottleLib = _G.ChatThrottleLib
ChatThrottleLib.version = CTL_VERSION
------------------ TWEAKABLES -----------------
ChatThrottleLib.MAX_CPS = 800 -- 2000 seems to be safe if NOTHING ELSE is happening. let's call it 800.
ChatThrottleLib.MSG_OVERHEAD = 40 -- Guesstimate overhead for sending a message; source+dest+chattype+protocolstuff
ChatThrottleLib.BURST = 4000 -- WoW's server buffer seems to be about 32KB. 8KB should be safe, but seen disconnects on _some_ servers. Using 4KB now.
ChatThrottleLib.MIN_FPS = 20 -- Reduce output CPS to half (and don't burst) if FPS drops below this value
local setmetatable = setmetatable
local table_remove = table.remove
local tostring = tostring
local GetTime = GetTime
local math_min = math.min
local math_max = math.max
local next = next
local strlen = string.len
local GetFramerate = GetFramerate
local strlower = string.lower
local unpack,type,pairs,wipe = unpack,type,pairs,wipe
local UnitInRaid,UnitInParty = UnitInRaid,UnitInParty
-----------------------------------------------------------------------
-- Double-linked ring implementation
local Ring = {}
local RingMeta = { __index = Ring }
function Ring:New()
local ret = {}
setmetatable(ret, RingMeta)
return ret
end
function Ring:Add(obj) -- Append at the "far end" of the ring (aka just before the current position)
if self.pos then
obj.prev = self.pos.prev
obj.prev.next = obj
obj.next = self.pos
obj.next.prev = obj
else
obj.next = obj
obj.prev = obj
self.pos = obj
end
end
function Ring:Remove(obj)
obj.next.prev = obj.prev
obj.prev.next = obj.next
if self.pos == obj then
self.pos = obj.next
if self.pos == obj then
self.pos = nil
end
end
end
-----------------------------------------------------------------------
-- Recycling bin for pipes
-- A pipe is a plain integer-indexed queue of messages
-- Pipes normally live in Rings of pipes (3 rings total, one per priority)
ChatThrottleLib.PipeBin = nil -- pre-v19, drastically different
local PipeBin = setmetatable({}, {__mode="k"})
local function DelPipe(pipe)
PipeBin[pipe] = true
end
local function NewPipe()
local pipe = next(PipeBin)
if pipe then
wipe(pipe)
PipeBin[pipe] = nil
return pipe
end
return {}
end
-----------------------------------------------------------------------
-- Recycling bin for messages
ChatThrottleLib.MsgBin = nil -- pre-v19, drastically different
local MsgBin = setmetatable({}, {__mode="k"})
local function DelMsg(msg)
msg[1] = nil
-- there's more parameters, but they're very repetetive so the string pool doesn't suffer really, and it's faster to just not delete them.
MsgBin[msg] = true
end
local function NewMsg()
local msg = next(MsgBin)
if msg then
MsgBin[msg] = nil
return msg
end
return {}
end
-----------------------------------------------------------------------
-- ChatThrottleLib:Init
-- Initialize queues, set up frame for OnUpdate, etc
function ChatThrottleLib:Init()
-- Set up queues
if not self.Prio then
self.Prio = {}
self.Prio["ALERT"] = { ByName = {}, Ring = Ring:New(), avail = 0 }
self.Prio["NORMAL"] = { ByName = {}, Ring = Ring:New(), avail = 0 }
self.Prio["BULK"] = { ByName = {}, Ring = Ring:New(), avail = 0 }
end
-- v4: total send counters per priority
for _, Prio in pairs(self.Prio) do
Prio.nTotalSent = Prio.nTotalSent or 0
end
if not self.avail then
self.avail = 0 -- v5
end
if not self.nTotalSent then
self.nTotalSent = 0 -- v5
end
-- Set up a frame to get OnUpdate events
if not self.Frame then
self.Frame = CreateFrame("Frame")
self.Frame:Hide()
end
self.Frame:SetScript("OnUpdate", self.OnUpdate)
self.Frame:SetScript("OnEvent", self.OnEvent) -- v11: Monitor P_E_W so we can throttle hard for a few seconds
self.Frame:RegisterEvent("PLAYER_ENTERING_WORLD")
self.OnUpdateDelay = 0
self.LastAvailUpdate = GetTime()
self.HardThrottlingBeginTime = GetTime() -- v11: Throttle hard for a few seconds after startup
-- Hook SendChatMessage and SendAddonMessage so we can measure unpiped traffic and avoid overloads (v7)
if not self.securelyHooked then
-- Use secure hooks as of v16. Old regular hook support yanked out in v21.
self.securelyHooked = true
--SendChatMessage
hooksecurefunc("SendChatMessage", function(...)
return ChatThrottleLib.Hook_SendChatMessage(...)
end)
--SendAddonMessage
hooksecurefunc("SendAddonMessage", function(...)
return ChatThrottleLib.Hook_SendAddonMessage(...)
end)
end
self.nBypass = 0
end
-----------------------------------------------------------------------
-- ChatThrottleLib.Hook_SendChatMessage / .Hook_SendAddonMessage
local bMyTraffic = false
function ChatThrottleLib.Hook_SendChatMessage(text, chattype, language, destination, ...)
if bMyTraffic then
return
end
local self = ChatThrottleLib
local size = strlen(tostring(text or "")) + strlen(tostring(destination or "")) + self.MSG_OVERHEAD
self.avail = self.avail - size
self.nBypass = self.nBypass + size -- just a statistic
end
function ChatThrottleLib.Hook_SendAddonMessage(prefix, text, chattype, destination, ...)
if bMyTraffic then
return
end
local self = ChatThrottleLib
local size = tostring(text or ""):len() + tostring(prefix or ""):len();
size = size + tostring(destination or ""):len() + self.MSG_OVERHEAD
self.avail = self.avail - size
self.nBypass = self.nBypass + size -- just a statistic
end
-----------------------------------------------------------------------
-- ChatThrottleLib:UpdateAvail
-- Update self.avail with how much bandwidth is currently available
function ChatThrottleLib:UpdateAvail()
local now = GetTime()
local MAX_CPS = self.MAX_CPS;
local newavail = MAX_CPS * (now - self.LastAvailUpdate)
local avail = self.avail
if now - self.HardThrottlingBeginTime < 5 then
-- First 5 seconds after startup/zoning: VERY hard clamping to avoid irritating the server rate limiter, it seems very cranky then
avail = math_min(avail + (newavail*0.1), MAX_CPS*0.5)
self.bChoking = true
elseif GetFramerate() < self.MIN_FPS then -- GetFrameRate call takes ~0.002 secs
avail = math_min(MAX_CPS, avail + newavail*0.5)
self.bChoking = true -- just a statistic
else
avail = math_min(self.BURST, avail + newavail)
self.bChoking = false
end
avail = math_max(avail, 0-(MAX_CPS*2)) -- Can go negative when someone is eating bandwidth past the lib. but we refuse to stay silent for more than 2 seconds; if they can do it, we can.
self.avail = avail
self.LastAvailUpdate = now
return avail
end
-----------------------------------------------------------------------
-- Despooling logic
-- Reminder:
-- - We have 3 Priorities, each containing a "Ring" construct ...
-- - ... made up of N "Pipe"s (1 for each destination/pipename)
-- - and each pipe contains messages
function ChatThrottleLib:Despool(Prio)
local ring = Prio.Ring
while ring.pos and Prio.avail > ring.pos[1].nSize do
local msg = table_remove(ring.pos, 1)
if not ring.pos[1] then -- did we remove last msg in this pipe?
local pipe = Prio.Ring.pos
Prio.Ring:Remove(pipe)
Prio.ByName[pipe.name] = nil
DelPipe(pipe)
else
Prio.Ring.pos = Prio.Ring.pos.next
end
local didSend=false
local lowerDest = strlower(msg[3] or "")
if lowerDest == "raid" and not UnitInRaid("player") then
-- do nothing
elseif lowerDest == "party" and not UnitInParty("player") then
-- do nothing
else
Prio.avail = Prio.avail - msg.nSize
bMyTraffic = true
msg.f(unpack(msg, 1, msg.n))
bMyTraffic = false
Prio.nTotalSent = Prio.nTotalSent + msg.nSize
DelMsg(msg)
didSend = true
end
-- notify caller of delivery (even if we didn't send it)
if msg.callbackFn then
msg.callbackFn (msg.callbackArg, didSend)
end
-- USER CALLBACK MAY ERROR
end
end
function ChatThrottleLib.OnEvent(this,event)
-- v11: We know that the rate limiter is touchy after login. Assume that it's touchy after zoning, too.
local self = ChatThrottleLib
if event == "PLAYER_ENTERING_WORLD" then
self.HardThrottlingBeginTime = GetTime() -- Throttle hard for a few seconds after zoning
self.avail = 0
end
end
function ChatThrottleLib.OnUpdate(this,delay)
local self = ChatThrottleLib
self.OnUpdateDelay = self.OnUpdateDelay + delay
if self.OnUpdateDelay < 0.08 then
return
end
self.OnUpdateDelay = 0
self:UpdateAvail()
if self.avail < 0 then
return -- argh. some bastard is spewing stuff past the lib. just bail early to save cpu.
end
-- See how many of our priorities have queued messages (we only have 3, don't worry about the loop)
local n = 0
for prioname,Prio in pairs(self.Prio) do
if Prio.Ring.pos or Prio.avail < 0 then
n = n + 1
end
end
-- Anything queued still?
if n<1 then
-- Nope. Move spillover bandwidth to global availability gauge and clear self.bQueueing
for prioname, Prio in pairs(self.Prio) do
self.avail = self.avail + Prio.avail
Prio.avail = 0
end
self.bQueueing = false
self.Frame:Hide()
return
end
-- There's stuff queued. Hand out available bandwidth to priorities as needed and despool their queues
local avail = self.avail/n
self.avail = 0
for prioname, Prio in pairs(self.Prio) do
if Prio.Ring.pos or Prio.avail < 0 then
Prio.avail = Prio.avail + avail
if Prio.Ring.pos and Prio.avail > Prio.Ring.pos[1].nSize then
self:Despool(Prio)
-- Note: We might not get here if the user-supplied callback function errors out! Take care!
end
end
end
end
-----------------------------------------------------------------------
-- Spooling logic
function ChatThrottleLib:Enqueue(prioname, pipename, msg)
local Prio = self.Prio[prioname]
local pipe = Prio.ByName[pipename]
if not pipe then
self.Frame:Show()
pipe = NewPipe()
pipe.name = pipename
Prio.ByName[pipename] = pipe
Prio.Ring:Add(pipe)
end
pipe[#pipe + 1] = msg
self.bQueueing = true
end
function ChatThrottleLib:SendChatMessage(prio, prefix, text, chattype, language, destination, queueName, callbackFn, callbackArg)
if not self or not prio or not prefix or not text or not self.Prio[prio] then
error('Usage: ChatThrottleLib:SendChatMessage("{BULK||NORMAL||ALERT}", "prefix", "text"[, "chattype"[, "language"[, "destination"]]]', 2)
end
if callbackFn and type(callbackFn)~="function" then
error('ChatThrottleLib:ChatMessage(): callbackFn: expected function, got '..type(callbackFn), 2)
end
local nSize = text:len()
if nSize>255 then
error("ChatThrottleLib:SendChatMessage(): message length cannot exceed 255 bytes", 2)
end
nSize = nSize + self.MSG_OVERHEAD
-- Check if there's room in the global available bandwidth gauge to send directly
if not self.bQueueing and nSize < self:UpdateAvail() then
self.avail = self.avail - nSize
bMyTraffic = true
_G.SendChatMessage(text, chattype, language, destination)
bMyTraffic = false
self.Prio[prio].nTotalSent = self.Prio[prio].nTotalSent + nSize
if callbackFn then
callbackFn (callbackArg, true)
end
-- USER CALLBACK MAY ERROR
return
end
-- Message needs to be queued
local msg = NewMsg()
msg.f = _G.SendChatMessage
msg[1] = text
msg[2] = chattype or "SAY"
msg[3] = language
msg[4] = destination
msg.n = 4
msg.nSize = nSize
msg.callbackFn = callbackFn
msg.callbackArg = callbackArg
self:Enqueue(prio, queueName or (prefix..(chattype or "SAY")..(destination or "")), msg)
end
function ChatThrottleLib:SendAddonMessage(prio, prefix, text, chattype, target, queueName, callbackFn, callbackArg)
if not self or not prio or not prefix or not text or not chattype or not self.Prio[prio] then
error('Usage: ChatThrottleLib:SendAddonMessage("{BULK||NORMAL||ALERT}", "prefix", "text", "chattype"[, "target"])', 2)
end
if callbackFn and type(callbackFn)~="function" then
error('ChatThrottleLib:SendAddonMessage(): callbackFn: expected function, got '..type(callbackFn), 2)
end
local nSize = text:len();
if RegisterAddonMessagePrefix then
if nSize>255 then
error("ChatThrottleLib:SendAddonMessage(): message length cannot exceed 255 bytes", 2)
end
else
nSize = nSize + prefix:len() + 1
if nSize>255 then
error("ChatThrottleLib:SendAddonMessage(): prefix + message length cannot exceed 254 bytes", 2)
end
end
nSize = nSize + self.MSG_OVERHEAD;
-- Check if there's room in the global available bandwidth gauge to send directly
if not self.bQueueing and nSize < self:UpdateAvail() then
self.avail = self.avail - nSize
bMyTraffic = true
_G.SendAddonMessage(prefix, text, chattype, target)
bMyTraffic = false
self.Prio[prio].nTotalSent = self.Prio[prio].nTotalSent + nSize
if callbackFn then
callbackFn (callbackArg, true)
end
-- USER CALLBACK MAY ERROR
return
end
-- Message needs to be queued
local msg = NewMsg()
msg.f = _G.SendAddonMessage
msg[1] = prefix
msg[2] = text
msg[3] = chattype
msg[4] = target
msg.n = (target~=nil) and 4 or 3;
msg.nSize = nSize
msg.callbackFn = callbackFn
msg.callbackArg = callbackArg
self:Enqueue(prio, queueName or (prefix..chattype..(target or "")), msg)
end
-----------------------------------------------------------------------
-- Get the ball rolling!
ChatThrottleLib:Init()
--[[ WoWBench debugging snippet
if(WOWB_VER) then
local function SayTimer()
print("SAY: "..GetTime().." "..arg1)
end
ChatThrottleLib.Frame:SetScript("OnEvent", SayTimer)
ChatThrottleLib.Frame:RegisterEvent("CHAT_MSG_SAY")
end
]]

View File

@ -0,0 +1,57 @@
--- AceConfig-3.0 wrapper library.
-- Provides an API to register an options table with the config registry,
-- as well as associate it with a slash command.
-- @class file
-- @name AceConfig-3.0
-- @release $Id: AceConfig-3.0.lua 969 2010-10-07 02:11:48Z shefki $
--[[
AceConfig-3.0
Very light wrapper library that combines all the AceConfig subcomponents into one more easily used whole.
]]
local MAJOR, MINOR = "AceConfig-3.0", 2
local AceConfig = LibStub:NewLibrary(MAJOR, MINOR)
if not AceConfig then return end
local cfgreg = LibStub("AceConfigRegistry-3.0")
local cfgcmd = LibStub("AceConfigCmd-3.0")
--TODO: local cfgdlg = LibStub("AceConfigDialog-3.0", true)
--TODO: local cfgdrp = LibStub("AceConfigDropdown-3.0", true)
-- Lua APIs
local pcall, error, type, pairs = pcall, error, type, pairs
-- -------------------------------------------------------------------
-- :RegisterOptionsTable(appName, options, slashcmd, persist)
--
-- - appName - (string) application name
-- - options - table or function ref, see AceConfigRegistry
-- - slashcmd - slash command (string) or table with commands, or nil to NOT create a slash command
--- Register a option table with the AceConfig registry.
-- You can supply a slash command (or a table of slash commands) to register with AceConfigCmd directly.
-- @paramsig appName, options [, slashcmd]
-- @param appName The application name for the config table.
-- @param options The option table (or a function to generate one on demand). http://www.wowace.com/addons/ace3/pages/ace-config-3-0-options-tables/
-- @param slashcmd A slash command to register for the option table, or a table of slash commands.
-- @usage
-- local AceConfig = LibStub("AceConfig-3.0")
-- AceConfig:RegisterOptionsTable("MyAddon", myOptions, {"/myslash", "/my"})
function AceConfig:RegisterOptionsTable(appName, options, slashcmd)
local ok,msg = pcall(cfgreg.RegisterOptionsTable, self, appName, options)
if not ok then error(msg, 2) end
if slashcmd then
if type(slashcmd) == "table" then
for _,cmd in pairs(slashcmd) do
cfgcmd:CreateChatCommand(cmd, appName)
end
else
cfgcmd:CreateChatCommand(slashcmd, appName)
end
end
end

View File

@ -0,0 +1,8 @@
<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">
<Include file="AceConfigRegistry-3.0\AceConfigRegistry-3.0.xml"/>
<Include file="AceConfigCmd-3.0\AceConfigCmd-3.0.xml"/>
<Include file="AceConfigDialog-3.0\AceConfigDialog-3.0.xml"/>
<!--<Include file="AceConfigDropdown-3.0\AceConfigDropdown-3.0.xml"/>-->
<Script file="AceConfig-3.0.lua"/>
</Ui>

View File

@ -0,0 +1,794 @@
--- AceConfigCmd-3.0 handles access to an options table through the "command line" interface via the ChatFrames.
-- @class file
-- @name AceConfigCmd-3.0
-- @release $Id: AceConfigCmd-3.0.lua 1045 2011-12-09 17:58:40Z nevcairiel $
--[[
AceConfigCmd-3.0
Handles commandline optionstable access
REQUIRES: AceConsole-3.0 for command registration (loaded on demand)
]]
-- TODO: plugin args
local MAJOR, MINOR = "AceConfigCmd-3.0", 13
local AceConfigCmd = LibStub:NewLibrary(MAJOR, MINOR)
if not AceConfigCmd then return end
AceConfigCmd.commands = AceConfigCmd.commands or {}
local commands = AceConfigCmd.commands
local cfgreg = LibStub("AceConfigRegistry-3.0")
local AceConsole -- LoD
local AceConsoleName = "AceConsole-3.0"
-- Lua APIs
local strsub, strsplit, strlower, strmatch, strtrim = string.sub, string.split, string.lower, string.match, string.trim
local format, tonumber, tostring = string.format, tonumber, tostring
local tsort, tinsert = table.sort, table.insert
local select, pairs, next, type = select, pairs, next, type
local error, assert = error, assert
-- WoW APIs
local _G = _G
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
-- List them here for Mikk's FindGlobals script
-- GLOBALS: LibStub, SELECTED_CHAT_FRAME, DEFAULT_CHAT_FRAME
local L = setmetatable({}, { -- TODO: replace with proper locale
__index = function(self,k) return k end
})
local function print(msg)
(SELECTED_CHAT_FRAME or DEFAULT_CHAT_FRAME):AddMessage(msg)
end
-- constants used by getparam() calls below
local handlertypes = {["table"]=true}
local handlermsg = "expected a table"
local functypes = {["function"]=true, ["string"]=true}
local funcmsg = "expected function or member name"
-- pickfirstset() - picks the first non-nil value and returns it
local function pickfirstset(...)
for i=1,select("#",...) do
if select(i,...)~=nil then
return select(i,...)
end
end
end
-- err() - produce real error() regarding malformed options tables etc
local function err(info,inputpos,msg )
local cmdstr=" "..strsub(info.input, 1, inputpos-1)
error(MAJOR..": /" ..info[0] ..cmdstr ..": "..(msg or "malformed options table"), 2)
end
-- usererr() - produce chatframe message regarding bad slash syntax etc
local function usererr(info,inputpos,msg )
local cmdstr=strsub(info.input, 1, inputpos-1);
print("/" ..info[0] .. " "..cmdstr ..": "..(msg or "malformed options table"))
end
-- callmethod() - call a given named method (e.g. "get", "set") with given arguments
local function callmethod(info, inputpos, tab, methodtype, ...)
local method = info[methodtype]
if not method then
err(info, inputpos, "'"..methodtype.."': not set")
end
info.arg = tab.arg
info.option = tab
info.type = tab.type
if type(method)=="function" then
return method(info, ...)
elseif type(method)=="string" then
if type(info.handler[method])~="function" then
err(info, inputpos, "'"..methodtype.."': '"..method.."' is not a member function of "..tostring(info.handler))
end
return info.handler[method](info.handler, info, ...)
else
assert(false) -- type should have already been checked on read
end
end
-- callfunction() - call a given named function (e.g. "name", "desc") with given arguments
local function callfunction(info, tab, methodtype, ...)
local method = tab[methodtype]
info.arg = tab.arg
info.option = tab
info.type = tab.type
if type(method)=="function" then
return method(info, ...)
else
assert(false) -- type should have already been checked on read
end
end
-- do_final() - do the final step (set/execute) along with validation and confirmation
local function do_final(info, inputpos, tab, methodtype, ...)
if info.validate then
local res = callmethod(info,inputpos,tab,"validate",...)
if type(res)=="string" then
usererr(info, inputpos, "'"..strsub(info.input, inputpos).."' - "..res)
return
end
end
-- console ignores .confirm
callmethod(info,inputpos,tab,methodtype, ...)
end
-- getparam() - used by handle() to retreive and store "handler", "get", "set", etc
local function getparam(info, inputpos, tab, depth, paramname, types, errormsg)
local old,oldat = info[paramname], info[paramname.."_at"]
local val=tab[paramname]
if val~=nil then
if val==false then
val=nil
elseif not types[type(val)] then
err(info, inputpos, "'" .. paramname.. "' - "..errormsg)
end
info[paramname] = val
info[paramname.."_at"] = depth
end
return old,oldat
end
-- iterateargs(tab) - custom iterator that iterates both t.args and t.plugins.*
local dummytable={}
local function iterateargs(tab)
if not tab.plugins then
return pairs(tab.args)
end
local argtabkey,argtab=next(tab.plugins)
local v
return function(_, k)
while argtab do
k,v = next(argtab, k)
if k then return k,v end
if argtab==tab.args then
argtab=nil
else
argtabkey,argtab = next(tab.plugins, argtabkey)
if not argtabkey then
argtab=tab.args
end
end
end
end
end
local function checkhidden(info, inputpos, tab)
if tab.cmdHidden~=nil then
return tab.cmdHidden
end
local hidden = tab.hidden
if type(hidden) == "function" or type(hidden) == "string" then
info.hidden = hidden
hidden = callmethod(info, inputpos, tab, 'hidden')
info.hidden = nil
end
return hidden
end
local function showhelp(info, inputpos, tab, depth, noHead)
if not noHead then
print("|cff33ff99"..info.appName.."|r: Arguments to |cffffff78/"..info[0].."|r "..strsub(info.input,1,inputpos-1)..":")
end
local sortTbl = {} -- [1..n]=name
local refTbl = {} -- [name]=tableref
for k,v in iterateargs(tab) do
if not refTbl[k] then -- a plugin overriding something in .args
tinsert(sortTbl, k)
refTbl[k] = v
end
end
tsort(sortTbl, function(one, two)
local o1 = refTbl[one].order or 100
local o2 = refTbl[two].order or 100
if type(o1) == "function" or type(o1) == "string" then
info.order = o1
info[#info+1] = one
o1 = callmethod(info, inputpos, refTbl[one], "order")
info[#info] = nil
info.order = nil
end
if type(o2) == "function" or type(o1) == "string" then
info.order = o2
info[#info+1] = two
o2 = callmethod(info, inputpos, refTbl[two], "order")
info[#info] = nil
info.order = nil
end
if o1<0 and o2<0 then return o1<o2 end
if o2<0 then return true end
if o1<0 then return false end
if o1==o2 then return tostring(one)<tostring(two) end -- compare names
return o1<o2
end)
for i = 1, #sortTbl do
local k = sortTbl[i]
local v = refTbl[k]
if not checkhidden(info, inputpos, v) then
if v.type ~= "description" and v.type ~= "header" then
-- recursively show all inline groups
local name, desc = v.name, v.desc
if type(name) == "function" then
name = callfunction(info, v, 'name')
end
if type(desc) == "function" then
desc = callfunction(info, v, 'desc')
end
if v.type == "group" and pickfirstset(v.cmdInline, v.inline, false) then
print(" "..(desc or name)..":")
local oldhandler,oldhandler_at = getparam(info, inputpos, v, depth, "handler", handlertypes, handlermsg)
showhelp(info, inputpos, v, depth, true)
info.handler,info.handler_at = oldhandler,oldhandler_at
else
local key = k:gsub(" ", "_")
print(" |cffffff78"..key.."|r - "..(desc or name or ""))
end
end
end
end
end
local function keybindingValidateFunc(text)
if text == nil or text == "NONE" then
return nil
end
text = text:upper()
local shift, ctrl, alt
local modifier
while true do
if text == "-" then
break
end
modifier, text = strsplit('-', text, 2)
if text then
if modifier ~= "SHIFT" and modifier ~= "CTRL" and modifier ~= "ALT" then
return false
end
if modifier == "SHIFT" then
if shift then
return false
end
shift = true
end
if modifier == "CTRL" then
if ctrl then
return false
end
ctrl = true
end
if modifier == "ALT" then
if alt then
return false
end
alt = true
end
else
text = modifier
break
end
end
if text == "" then
return false
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
return false
end
local s = text
if shift then
s = "SHIFT-" .. s
end
if ctrl then
s = "CTRL-" .. s
end
if alt then
s = "ALT-" .. s
end
return s
end
-- handle() - selfrecursing function that processes input->optiontable
-- - depth - starts at 0
-- - retfalse - return false rather than produce error if a match is not found (used by inlined groups)
local function handle(info, inputpos, tab, depth, retfalse)
if not(type(tab)=="table" and type(tab.type)=="string") then err(info,inputpos) end
-------------------------------------------------------------------
-- Grab hold of handler,set,get,func,etc if set (and remember old ones)
-- Note that we do NOT validate if method names are correct at this stage,
-- the handler may change before they're actually used!
local oldhandler,oldhandler_at = getparam(info,inputpos,tab,depth,"handler",handlertypes,handlermsg)
local oldset,oldset_at = getparam(info,inputpos,tab,depth,"set",functypes,funcmsg)
local oldget,oldget_at = getparam(info,inputpos,tab,depth,"get",functypes,funcmsg)
local oldfunc,oldfunc_at = getparam(info,inputpos,tab,depth,"func",functypes,funcmsg)
local oldvalidate,oldvalidate_at = getparam(info,inputpos,tab,depth,"validate",functypes,funcmsg)
--local oldconfirm,oldconfirm_at = getparam(info,inputpos,tab,depth,"confirm",functypes,funcmsg)
-------------------------------------------------------------------
-- Act according to .type of this table
if tab.type=="group" then
------------ group --------------------------------------------
if type(tab.args)~="table" then err(info, inputpos) end
if tab.plugins and type(tab.plugins)~="table" then err(info,inputpos) end
-- grab next arg from input
local _,nextpos,arg = (info.input):find(" *([^ ]+) *", inputpos)
if not arg then
showhelp(info, inputpos, tab, depth)
return
end
nextpos=nextpos+1
-- loop .args and try to find a key with a matching name
for k,v in iterateargs(tab) do
if not(type(k)=="string" and type(v)=="table" and type(v.type)=="string") then err(info,inputpos, "options table child '"..tostring(k).."' is malformed") end
-- is this child an inline group? if so, traverse into it
if v.type=="group" and pickfirstset(v.cmdInline, v.inline, false) then
info[depth+1] = k
if handle(info, inputpos, v, depth+1, true)==false then
info[depth+1] = nil
-- wasn't found in there, but that's ok, we just keep looking down here
else
return -- done, name was found in inline group
end
-- matching name and not a inline group
elseif strlower(arg)==strlower(k:gsub(" ", "_")) then
info[depth+1] = k
return handle(info,nextpos,v,depth+1)
end
end
-- no match
if retfalse then
-- restore old infotable members and return false to indicate failure
info.handler,info.handler_at = oldhandler,oldhandler_at
info.set,info.set_at = oldset,oldset_at
info.get,info.get_at = oldget,oldget_at
info.func,info.func_at = oldfunc,oldfunc_at
info.validate,info.validate_at = oldvalidate,oldvalidate_at
--info.confirm,info.confirm_at = oldconfirm,oldconfirm_at
return false
end
-- couldn't find the command, display error
usererr(info, inputpos, "'"..arg.."' - " .. L["unknown argument"])
return
end
local str = strsub(info.input,inputpos);
if tab.type=="execute" then
------------ execute --------------------------------------------
do_final(info, inputpos, tab, "func")
elseif tab.type=="input" then
------------ input --------------------------------------------
local res = true
if tab.pattern then
if not(type(tab.pattern)=="string") then err(info, inputpos, "'pattern' - expected a string") end
if not strmatch(str, tab.pattern) then
usererr(info, inputpos, "'"..str.."' - " .. L["invalid input"])
return
end
end
do_final(info, inputpos, tab, "set", str)
elseif tab.type=="toggle" then
------------ toggle --------------------------------------------
local b
local str = strtrim(strlower(str))
if str=="" then
b = callmethod(info, inputpos, tab, "get")
if tab.tristate then
--cycle in true, nil, false order
if b then
b = nil
elseif b == nil then
b = false
else
b = true
end
else
b = not b
end
elseif str==L["on"] then
b = true
elseif str==L["off"] then
b = false
elseif tab.tristate and str==L["default"] then
b = nil
else
if tab.tristate then
usererr(info, inputpos, format(L["'%s' - expected 'on', 'off' or 'default', or no argument to toggle."], str))
else
usererr(info, inputpos, format(L["'%s' - expected 'on' or 'off', or no argument to toggle."], str))
end
return
end
do_final(info, inputpos, tab, "set", b)
elseif tab.type=="range" then
------------ range --------------------------------------------
local val = tonumber(str)
if not val then
usererr(info, inputpos, "'"..str.."' - "..L["expected number"])
return
end
if type(info.step)=="number" then
val = val- (val % info.step)
end
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)) )
return
end
if type(info.max)=="number" and val>info.max then
usererr(info, inputpos, val.." - "..format(L["must be equal to or lower than %s"], tostring(info.max)) )
return
end
do_final(info, inputpos, tab, "set", val)
elseif tab.type=="select" then
------------ select ------------------------------------
local str = strtrim(strlower(str))
local values = tab.values
if type(values) == "function" or type(values) == "string" then
info.values = values
values = callmethod(info, inputpos, tab, "values")
info.values = nil
end
if str == "" then
local b = callmethod(info, inputpos, tab, "get")
local fmt = "|cffffff78- [%s]|r %s"
local fmt_sel = "|cffffff78- [%s]|r %s |cffff0000*|r"
print(L["Options for |cffffff78"..info[#info].."|r:"])
for k, v in pairs(values) do
if b == k then
print(fmt_sel:format(k, v))
else
print(fmt:format(k, v))
end
end
return
end
local ok
for k,v in pairs(values) do
if strlower(k)==str then
str = k -- overwrite with key (in case of case mismatches)
ok = true
break
end
end
if not ok then
usererr(info, inputpos, "'"..str.."' - "..L["unknown selection"])
return
end
do_final(info, inputpos, tab, "set", str)
elseif tab.type=="multiselect" then
------------ multiselect -------------------------------------------
local str = strtrim(strlower(str))
local values = tab.values
if type(values) == "function" or type(values) == "string" then
info.values = values
values = callmethod(info, inputpos, tab, "values")
info.values = nil
end
if str == "" then
local fmt = "|cffffff78- [%s]|r %s"
local fmt_sel = "|cffffff78- [%s]|r %s |cffff0000*|r"
print(L["Options for |cffffff78"..info[#info].."|r (multiple possible):"])
for k, v in pairs(values) do
if callmethod(info, inputpos, tab, "get", k) then
print(fmt_sel:format(k, v))
else
print(fmt:format(k, v))
end
end
return
end
--build a table of the selections, checking that they exist
--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
local sels = {}
for v in str:gmatch("[^ ]+") do
--parse option=on etc
local opt, val = v:match('(.+)=(.+)')
--get option if toggling
if not opt then
opt = v
end
--check that the opt is valid
local ok
for k,v in pairs(values) do
if strlower(k)==opt then
opt = k -- overwrite with key (in case of case mismatches)
ok = true
break
end
end
if not ok then
usererr(info, inputpos, "'"..opt.."' - "..L["unknown selection"])
return
end
--check that if val was supplied it is valid
if val then
if val == L["on"] or val == L["off"] or (tab.tristate and val == L["default"]) then
--val is valid insert it
sels[opt] = val
else
if tab.tristate then
usererr(info, inputpos, format(L["'%s' '%s' - expected 'on', 'off' or 'default', or no argument to toggle."], v, val))
else
usererr(info, inputpos, format(L["'%s' '%s' - expected 'on' or 'off', or no argument to toggle."], v, val))
end
return
end
else
-- no val supplied, toggle
sels[opt] = true
end
end
for opt, val in pairs(sels) do
local newval
if (val == true) then
--toggle the option
local b = callmethod(info, inputpos, tab, "get", opt)
if tab.tristate then
--cycle in true, nil, false order
if b then
b = nil
elseif b == nil then
b = false
else
b = true
end
else
b = not b
end
newval = b
else
--set the option as specified
if val==L["on"] then
newval = true
elseif val==L["off"] then
newval = false
elseif val==L["default"] then
newval = nil
end
end
do_final(info, inputpos, tab, "set", opt, newval)
end
elseif tab.type=="color" then
------------ color --------------------------------------------
local str = strtrim(strlower(str))
if str == "" then
--TODO: Show current value
return
end
local r, g, b, a
local hasAlpha = tab.hasAlpha
if type(hasAlpha) == "function" or type(hasAlpha) == "string" then
info.hasAlpha = hasAlpha
hasAlpha = callmethod(info, inputpos, tab, 'hasAlpha')
info.hasAlpha = nil
end
if hasAlpha then
if str:len() == 8 and str:find("^%x*$") then
--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
else
--parse seperate values
r,g,b,a = str:match("^([%d%.]+) ([%d%.]+) ([%d%.]+) ([%d%.]+)$")
r,g,b,a = tonumber(r), tonumber(g), tonumber(b), tonumber(a)
end
if not (r and g and b and a) then
usererr(info, inputpos, format(L["'%s' - expected 'RRGGBBAA' or 'r g b a'."], str))
return
end
if r >= 0.0 and r <= 1.0 and g >= 0.0 and g <= 1.0 and b >= 0.0 and b <= 1.0 and a >= 0.0 and a <= 1.0 then
--values are valid
elseif r >= 0 and r <= 255 and g >= 0 and g <= 255 and b >= 0 and b <= 255 and a >= 0 and a <= 255 then
--values are valid 0..255, convert to 0..1
r = r / 255
g = g / 255
b = b / 255
a = a / 255
else
--values are invalid
usererr(info, inputpos, format(L["'%s' - values must all be either in the range 0..1 or 0..255."], str))
end
else
a = 1.0
if str:len() == 6 and str:find("^%x*$") then
--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
else
--parse seperate values
r,g,b = str:match("^([%d%.]+) ([%d%.]+) ([%d%.]+)$")
r,g,b = tonumber(r), tonumber(g), tonumber(b)
end
if not (r and g and b) then
usererr(info, inputpos, format(L["'%s' - expected 'RRGGBB' or 'r g b'."], str))
return
end
if r >= 0.0 and r <= 1.0 and g >= 0.0 and g <= 1.0 and b >= 0.0 and b <= 1.0 then
--values are valid
elseif r >= 0 and r <= 255 and g >= 0 and g <= 255 and b >= 0 and b <= 255 then
--values are valid 0..255, convert to 0..1
r = r / 255
g = g / 255
b = b / 255
else
--values are invalid
usererr(info, inputpos, format(L["'%s' - values must all be either in the range 0-1 or 0-255."], str))
end
end
do_final(info, inputpos, tab, "set", r,g,b,a)
elseif tab.type=="keybinding" then
------------ keybinding --------------------------------------------
local str = strtrim(strlower(str))
if str == "" then
--TODO: Show current value
return
end
local value = keybindingValidateFunc(str:upper())
if value == false then
usererr(info, inputpos, format(L["'%s' - Invalid Keybinding."], str))
return
end
do_final(info, inputpos, tab, "set", value)
elseif tab.type=="description" then
------------ description --------------------
-- ignore description, GUI config only
else
err(info, inputpos, "unknown options table item type '"..tostring(tab.type).."'")
end
end
--- Handle the chat command.
-- This is usually called from a chat command handler to parse the command input as operations on an aceoptions table.\\
-- AceConfigCmd uses this function internally when a slash command is registered with `:CreateChatCommand`
-- @param slashcmd The slash command WITHOUT leading slash (only used for error output)
-- @param appName The application name as given to `:RegisterOptionsTable()`
-- @param input The commandline input (as given by the WoW handler, i.e. without the command itself)
-- @usage
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceConsole-3.0")
-- -- Use AceConsole-3.0 to register a Chat Command
-- MyAddon:RegisterChatCommand("mychat", "ChatCommand")
--
-- -- Show the GUI if no input is supplied, otherwise handle the chat input.
-- function MyAddon:ChatCommand(input)
-- -- Assuming "MyOptions" is the appName of a valid options table
-- if not input or input:trim() == "" then
-- LibStub("AceConfigDialog-3.0"):Open("MyOptions")
-- else
-- LibStub("AceConfigCmd-3.0").HandleCommand(MyAddon, "mychat", "MyOptions", input)
-- end
-- end
function AceConfigCmd:HandleCommand(slashcmd, appName, input)
local optgetter = cfgreg:GetOptionsTable(appName)
if not optgetter then
error([[Usage: HandleCommand("slashcmd", "appName", "input"): 'appName' - no options table "]]..tostring(appName)..[[" has been registered]], 2)
end
local options = assert( optgetter("cmd", MAJOR) )
local info = { -- Don't try to recycle this, it gets handed off to callbacks and whatnot
[0] = slashcmd,
appName = appName,
options = options,
input = input,
self = self,
handler = self,
uiType = "cmd",
uiName = MAJOR,
}
handle(info, 1, options, 0) -- (info, inputpos, table, depth)
end
--- Utility function to create a slash command handler.
-- Also registers tab completion with AceTab
-- @param slashcmd The slash command WITHOUT leading slash (only used for error output)
-- @param appName The application name as given to `:RegisterOptionsTable()`
function AceConfigCmd:CreateChatCommand(slashcmd, appName)
if not AceConsole then
AceConsole = LibStub(AceConsoleName)
end
if AceConsole.RegisterChatCommand(self, slashcmd, function(input)
AceConfigCmd.HandleCommand(self, slashcmd, appName, input) -- upgradable
end,
true) then -- succesfully registered so lets get the command -> app table in
commands[slashcmd] = appName
end
end
--- Utility function that returns the options table that belongs to a slashcommand.
-- Designed to be used for the AceTab interface.
-- @param slashcmd The slash command WITHOUT leading slash (only used for error output)
-- @return The options table associated with the slash command (or nil if the slash command was not registered)
function AceConfigCmd:GetChatCommandOptions(slashcmd)
return commands[slashcmd]
end

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="AceConfigCmd-3.0.lua"/>
</Ui>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="AceConfigDialog-3.0.lua"/>
</Ui>

View File

@ -0,0 +1,349 @@
--- AceConfigRegistry-3.0 handles central registration of options tables in use by addons and modules.\\
-- Options tables can be registered as raw tables, OR as function refs that return a table.\\
-- Such functions receive three arguments: "uiType", "uiName", "appName". \\
-- * Valid **uiTypes**: "cmd", "dropdown", "dialog". This is verified by the library at call time. \\
-- * The **uiName** field is expected to contain the full name of the calling addon, including version, e.g. "FooBar-1.0". This is verified by the library at call time.\\
-- * The **appName** field is the options table name as given at registration time \\
--
-- :IterateOptionsTables() (and :GetOptionsTable() if only given one argument) return a function reference that the requesting config handling addon must call with valid "uiType", "uiName".
-- @class file
-- @name AceConfigRegistry-3.0
-- @release $Id: AceConfigRegistry-3.0.lua 1139 2016-07-03 07:43:51Z nevcairiel $
local MAJOR, MINOR = "AceConfigRegistry-3.0", 16
local AceConfigRegistry = LibStub:NewLibrary(MAJOR, MINOR)
if not AceConfigRegistry then return end
AceConfigRegistry.tables = AceConfigRegistry.tables or {}
local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0")
if not AceConfigRegistry.callbacks then
AceConfigRegistry.callbacks = CallbackHandler:New(AceConfigRegistry)
end
-- Lua APIs
local tinsert, tconcat = table.insert, table.concat
local strfind, strmatch = string.find, string.match
local type, tostring, select, pairs = type, tostring, select, pairs
local error, assert = error, assert
-----------------------------------------------------------------------
-- Validating options table consistency:
AceConfigRegistry.validated = {
-- list of options table names ran through :ValidateOptionsTable automatically.
-- CLEARED ON PURPOSE, since newer versions may have newer validators
cmd = {},
dropdown = {},
dialog = {},
}
local function err(msg, errlvl, ...)
local t = {}
for i=select("#",...),1,-1 do
tinsert(t, (select(i, ...)))
end
error(MAJOR..":ValidateOptionsTable(): "..tconcat(t,".")..msg, errlvl+2)
end
local isstring={["string"]=true, _="string"}
local isstringfunc={["string"]=true,["function"]=true, _="string or funcref"}
local istable={["table"]=true, _="table"}
local ismethodtable={["table"]=true,["string"]=true,["function"]=true, _="methodname, funcref or table"}
local optstring={["nil"]=true,["string"]=true, _="string"}
local optstringfunc={["nil"]=true,["string"]=true,["function"]=true, _="string or funcref"}
local optstringnumberfunc={["nil"]=true,["string"]=true,["number"]=true,["function"]=true, _="string, number or funcref"}
local optnumber={["nil"]=true,["number"]=true, _="number"}
local optmethod={["nil"]=true,["string"]=true,["function"]=true, _="methodname or funcref"}
local optmethodfalse={["nil"]=true,["string"]=true,["function"]=true,["boolean"]={[false]=true}, _="methodname, funcref or false"}
local optmethodnumber={["nil"]=true,["string"]=true,["function"]=true,["number"]=true, _="methodname, funcref or number"}
local optmethodtable={["nil"]=true,["string"]=true,["function"]=true,["table"]=true, _="methodname, funcref or table"}
local optmethodbool={["nil"]=true,["string"]=true,["function"]=true,["boolean"]=true, _="methodname, funcref or boolean"}
local opttable={["nil"]=true,["table"]=true, _="table"}
local optbool={["nil"]=true,["boolean"]=true, _="boolean"}
local optboolnumber={["nil"]=true,["boolean"]=true,["number"]=true, _="boolean or number"}
local basekeys={
type=isstring,
name=isstringfunc,
desc=optstringfunc,
descStyle=optstring,
order=optmethodnumber,
validate=optmethodfalse,
confirm=optmethodbool,
confirmText=optstring,
disabled=optmethodbool,
hidden=optmethodbool,
guiHidden=optmethodbool,
dialogHidden=optmethodbool,
dropdownHidden=optmethodbool,
cmdHidden=optmethodbool,
icon=optstringnumberfunc,
iconCoords=optmethodtable,
handler=opttable,
get=optmethodfalse,
set=optmethodfalse,
func=optmethodfalse,
arg={["*"]=true},
width=optstring,
}
local typedkeys={
header={},
description={
image=optstringnumberfunc,
imageCoords=optmethodtable,
imageHeight=optnumber,
imageWidth=optnumber,
fontSize=optstringfunc,
},
group={
args=istable,
plugins=opttable,
inline=optbool,
cmdInline=optbool,
guiInline=optbool,
dropdownInline=optbool,
dialogInline=optbool,
childGroups=optstring,
},
execute={
image=optstringnumberfunc,
imageCoords=optmethodtable,
imageHeight=optnumber,
imageWidth=optnumber,
},
input={
pattern=optstring,
usage=optstring,
control=optstring,
dialogControl=optstring,
dropdownControl=optstring,
multiline=optboolnumber,
},
toggle={
tristate=optbool,
image=optstringnumberfunc,
imageCoords=optmethodtable,
},
tristate={
},
range={
min=optnumber,
softMin=optnumber,
max=optnumber,
softMax=optnumber,
step=optnumber,
bigStep=optnumber,
isPercent=optbool,
},
select={
values=ismethodtable,
style={
["nil"]=true,
["string"]={dropdown=true,radio=true},
_="string: 'dropdown' or 'radio'"
},
control=optstring,
dialogControl=optstring,
dropdownControl=optstring,
itemControl=optstring,
},
multiselect={
values=ismethodtable,
style=optstring,
tristate=optbool,
control=optstring,
dialogControl=optstring,
dropdownControl=optstring,
},
color={
hasAlpha=optmethodbool,
},
keybinding={
-- TODO
},
}
local function validateKey(k,errlvl,...)
errlvl=(errlvl or 0)+1
if type(k)~="string" then
err("["..tostring(k).."] - key is not a string", errlvl,...)
end
if strfind(k, "[%c\127]") then
err("["..tostring(k).."] - key name contained control characters", errlvl,...)
end
end
local function validateVal(v, oktypes, errlvl,...)
errlvl=(errlvl or 0)+1
local isok=oktypes[type(v)] or oktypes["*"]
if not isok then
err(": expected a "..oktypes._..", got '"..tostring(v).."'", errlvl,...)
end
if type(isok)=="table" then -- isok was a table containing specific values to be tested for!
if not isok[v] then
err(": did not expect "..type(v).." value '"..tostring(v).."'", errlvl,...)
end
end
end
local function validate(options,errlvl,...)
errlvl=(errlvl or 0)+1
-- basic consistency
if type(options)~="table" then
err(": expected a table, got a "..type(options), errlvl,...)
end
if type(options.type)~="string" then
err(".type: expected a string, got a "..type(options.type), errlvl,...)
end
-- get type and 'typedkeys' member
local tk = typedkeys[options.type]
if not tk then
err(".type: unknown type '"..options.type.."'", errlvl,...)
end
-- make sure that all options[] are known parameters
for k,v in pairs(options) do
if not (tk[k] or basekeys[k]) then
err(": unknown parameter", errlvl,tostring(k),...)
end
end
-- verify that required params are there, and that everything is the right type
for k,oktypes in pairs(basekeys) do
validateVal(options[k], oktypes, errlvl,k,...)
end
for k,oktypes in pairs(tk) do
validateVal(options[k], oktypes, errlvl,k,...)
end
-- extra logic for groups
if options.type=="group" then
for k,v in pairs(options.args) do
validateKey(k,errlvl,"args",...)
validate(v, errlvl,k,"args",...)
end
if options.plugins then
for plugname,plugin in pairs(options.plugins) do
if type(plugin)~="table" then
err(": expected a table, got '"..tostring(plugin).."'", errlvl,tostring(plugname),"plugins",...)
end
for k,v in pairs(plugin) do
validateKey(k,errlvl,tostring(plugname),"plugins",...)
validate(v, errlvl,k,tostring(plugname),"plugins",...)
end
end
end
end
end
--- Validates basic structure and integrity of an options table \\
-- Does NOT verify that get/set etc actually exist, since they can be defined at any depth
-- @param options The table to be validated
-- @param name The name of the table to be validated (shown in any error message)
-- @param errlvl (optional number) error level offset, default 0 (=errors point to the function calling :ValidateOptionsTable)
function AceConfigRegistry:ValidateOptionsTable(options,name,errlvl)
errlvl=(errlvl or 0)+1
name = name or "Optionstable"
if not options.name then
options.name=name -- bit of a hack, the root level doesn't really need a .name :-/
end
validate(options,errlvl,name)
end
--- Fires a "ConfigTableChange" callback for those listening in on it, allowing config GUIs to refresh.
-- You should call this function if your options table changed from any outside event, like a game event
-- or a timer.
-- @param appName The application name as given to `:RegisterOptionsTable()`
function AceConfigRegistry:NotifyChange(appName)
if not AceConfigRegistry.tables[appName] then return end
AceConfigRegistry.callbacks:Fire("ConfigTableChange", appName)
end
-- -------------------------------------------------------------------
-- Registering and retreiving options tables:
-- validateGetterArgs: helper function for :GetOptionsTable (or, rather, the getter functions returned by it)
local function validateGetterArgs(uiType, uiName, errlvl)
errlvl=(errlvl or 0)+2
if uiType~="cmd" and uiType~="dropdown" and uiType~="dialog" then
error(MAJOR..": Requesting options table: 'uiType' - invalid configuration UI type, expected 'cmd', 'dropdown' or 'dialog'", errlvl)
end
if not strmatch(uiName, "[A-Za-z]%-[0-9]") then -- Expecting e.g. "MyLib-1.2"
error(MAJOR..": Requesting options table: 'uiName' - badly formatted or missing version number. Expected e.g. 'MyLib-1.2'", errlvl)
end
end
--- Register an options table with the config registry.
-- @param appName The application name as given to `:RegisterOptionsTable()`
-- @param options The options table, OR a function reference that generates it on demand. \\
-- See the top of the page for info on arguments passed to such functions.
-- @param skipValidation Skip options table validation (primarily useful for extremely huge options, with a noticeable slowdown)
function AceConfigRegistry:RegisterOptionsTable(appName, options, skipValidation)
if type(options)=="table" then
if options.type~="group" then -- quick sanity checker
error(MAJOR..": RegisterOptionsTable(appName, options): 'options' - missing type='group' member in root group", 2)
end
AceConfigRegistry.tables[appName] = function(uiType, uiName, errlvl)
errlvl=(errlvl or 0)+1
validateGetterArgs(uiType, uiName, errlvl)
if not AceConfigRegistry.validated[uiType][appName] and not skipValidation then
AceConfigRegistry:ValidateOptionsTable(options, appName, errlvl) -- upgradable
AceConfigRegistry.validated[uiType][appName] = true
end
return options
end
elseif type(options)=="function" then
AceConfigRegistry.tables[appName] = function(uiType, uiName, errlvl)
errlvl=(errlvl or 0)+1
validateGetterArgs(uiType, uiName, errlvl)
local tab = assert(options(uiType, uiName, appName))
if not AceConfigRegistry.validated[uiType][appName] and not skipValidation then
AceConfigRegistry:ValidateOptionsTable(tab, appName, errlvl) -- upgradable
AceConfigRegistry.validated[uiType][appName] = true
end
return tab
end
else
error(MAJOR..": RegisterOptionsTable(appName, options): 'options' - expected table or function reference", 2)
end
end
--- Returns an iterator of ["appName"]=funcref pairs
function AceConfigRegistry:IterateOptionsTables()
return pairs(AceConfigRegistry.tables)
end
--- Query the registry for a specific options table.
-- If only appName is given, a function is returned which you
-- can call with (uiType,uiName) to get the table.\\
-- If uiType&uiName are given, the table is returned.
-- @param appName The application name as given to `:RegisterOptionsTable()`
-- @param uiType The type of UI to get the table for, one of "cmd", "dropdown", "dialog"
-- @param uiName The name of the library/addon querying for the table, e.g. "MyLib-1.0"
function AceConfigRegistry:GetOptionsTable(appName, uiType, uiName)
local f = AceConfigRegistry.tables[appName]
if not f then
return nil
end
if uiType then
return f(uiType,uiName,1) -- get the table for us
else
return f -- return the function
end
end

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="AceConfigRegistry-3.0.lua"/>
</Ui>

View File

@ -0,0 +1,250 @@
--- **AceConsole-3.0** provides registration facilities for slash commands.
-- You can register slash commands to your custom functions and use the `GetArgs` function to parse them
-- to your addons individual needs.
--
-- **AceConsole-3.0** can be embeded into your addon, either explicitly by calling AceConsole:Embed(MyAddon) or by
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
-- and can be accessed directly, without having to explicitly call AceConsole itself.\\
-- It is recommended to embed AceConsole, otherwise you'll have to specify a custom `self` on all calls you
-- make into AceConsole.
-- @class file
-- @name AceConsole-3.0
-- @release $Id: AceConsole-3.0.lua 878 2009-11-02 18:51:58Z nevcairiel $
local MAJOR,MINOR = "AceConsole-3.0", 7
local AceConsole, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not AceConsole then return end -- No upgrade needed
AceConsole.embeds = AceConsole.embeds or {} -- table containing objects AceConsole is embedded in.
AceConsole.commands = AceConsole.commands or {} -- table containing commands registered
AceConsole.weakcommands = AceConsole.weakcommands or {} -- table containing self, command => func references for weak commands that don't persist through enable/disable
-- Lua APIs
local tconcat, tostring, select = table.concat, tostring, select
local type, pairs, error = type, pairs, error
local format, strfind, strsub = string.format, string.find, string.sub
local max = math.max
-- WoW APIs
local _G = _G
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
-- List them here for Mikk's FindGlobals script
-- GLOBALS: DEFAULT_CHAT_FRAME, SlashCmdList, hash_SlashCmdList
local tmp={}
local function Print(self,frame,...)
local n=0
if self ~= AceConsole then
n=n+1
tmp[n] = "|cff33ff99"..tostring( self ).."|r:"
end
for i=1, select("#", ...) do
n=n+1
tmp[n] = tostring(select(i, ...))
end
frame:AddMessage( tconcat(tmp," ",1,n) )
end
--- Print to DEFAULT_CHAT_FRAME or given ChatFrame (anything with an .AddMessage function)
-- @paramsig [chatframe ,] ...
-- @param chatframe Custom ChatFrame to print to (or any frame with an .AddMessage function)
-- @param ... List of any values to be printed
function AceConsole:Print(...)
local frame = ...
if type(frame) == "table" and frame.AddMessage then -- Is first argument something with an .AddMessage member?
return Print(self, frame, select(2,...))
else
return Print(self, DEFAULT_CHAT_FRAME, ...)
end
end
--- Formatted (using format()) print to DEFAULT_CHAT_FRAME or given ChatFrame (anything with an .AddMessage function)
-- @paramsig [chatframe ,] "format"[, ...]
-- @param chatframe Custom ChatFrame to print to (or any frame with an .AddMessage function)
-- @param format Format string - same syntax as standard Lua format()
-- @param ... Arguments to the format string
function AceConsole:Printf(...)
local frame = ...
if type(frame) == "table" and frame.AddMessage then -- Is first argument something with an .AddMessage member?
return Print(self, frame, format(select(2,...)))
else
return Print(self, DEFAULT_CHAT_FRAME, format(...))
end
end
--- Register a simple chat command
-- @param command Chat command to be registered WITHOUT leading "/"
-- @param func Function to call when the slash command is being used (funcref or methodname)
-- @param persist if false, the command will be soft disabled/enabled when aceconsole is used as a mixin (default: true)
function AceConsole:RegisterChatCommand( command, func, persist )
if type(command)~="string" then error([[Usage: AceConsole:RegisterChatCommand( "command", func[, persist ]): 'command' - expected a string]], 2) end
if persist==nil then persist=true end -- I'd rather have my addon's "/addon enable" around if the author screws up. Having some extra slash regged when it shouldnt be isn't as destructive. True is a better default. /Mikk
local name = "ACECONSOLE_"..command:upper()
if type( func ) == "string" then
SlashCmdList[name] = function(input, editBox)
self[func](self, input, editBox)
end
else
SlashCmdList[name] = func
end
_G["SLASH_"..name.."1"] = "/"..command:lower()
AceConsole.commands[command] = name
-- non-persisting commands are registered for enabling disabling
if not persist then
if not AceConsole.weakcommands[self] then AceConsole.weakcommands[self] = {} end
AceConsole.weakcommands[self][command] = func
end
return true
end
--- Unregister a chatcommand
-- @param command Chat command to be unregistered WITHOUT leading "/"
function AceConsole:UnregisterChatCommand( command )
local name = AceConsole.commands[command]
if name then
SlashCmdList[name] = nil
_G["SLASH_" .. name .. "1"] = nil
hash_SlashCmdList["/" .. command:upper()] = nil
AceConsole.commands[command] = nil
end
end
--- Get an iterator over all Chat Commands registered with AceConsole
-- @return Iterator (pairs) over all commands
function AceConsole:IterateChatCommands() return pairs(AceConsole.commands) end
local function nils(n, ...)
if n>1 then
return nil, nils(n-1, ...)
elseif n==1 then
return nil, ...
else
return ...
end
end
--- Retreive one or more space-separated arguments from a string.
-- Treats quoted strings and itemlinks as non-spaced.
-- @param string The raw argument string
-- @param numargs How many arguments to get (default 1)
-- @param startpos Where in the string to start scanning (default 1)
-- @return Returns arg1, arg2, ..., nextposition\\
-- Missing arguments will be returned as nils. 'nextposition' is returned as 1e9 at the end of the string.
function AceConsole:GetArgs(str, numargs, startpos)
numargs = numargs or 1
startpos = max(startpos or 1, 1)
local pos=startpos
-- find start of new arg
pos = strfind(str, "[^ ]", pos)
if not pos then -- whoops, end of string
return nils(numargs, 1e9)
end
if numargs<1 then
return pos
end
-- quoted or space separated? find out which pattern to use
local delim_or_pipe
local ch = strsub(str, pos, pos)
if ch=='"' then
pos = pos + 1
delim_or_pipe='([|"])'
elseif ch=="'" then
pos = pos + 1
delim_or_pipe="([|'])"
else
delim_or_pipe="([| ])"
end
startpos = pos
while true do
-- find delimiter or hyperlink
local ch,_
pos,_,ch = strfind(str, delim_or_pipe, pos)
if not pos then break end
if ch=="|" then
-- some kind of escape
if strsub(str,pos,pos+1)=="|H" then
-- It's a |H....|hhyper link!|h
pos=strfind(str, "|h", pos+2) -- first |h
if not pos then break end
pos=strfind(str, "|h", pos+2) -- second |h
if not pos then break end
elseif strsub(str,pos, pos+1) == "|T" then
-- It's a |T....|t texture
pos=strfind(str, "|t", pos+2)
if not pos then break end
end
pos=pos+2 -- skip past this escape (last |h if it was a hyperlink)
else
-- found delimiter, done with this arg
return strsub(str, startpos, pos-1), AceConsole:GetArgs(str, numargs-1, pos+1)
end
end
-- search aborted, we hit end of string. return it all as one argument. (yes, even if it's an unterminated quote or hyperlink)
return strsub(str, startpos), nils(numargs-1, 1e9)
end
--- embedding and embed handling
local mixins = {
"Print",
"Printf",
"RegisterChatCommand",
"UnregisterChatCommand",
"GetArgs",
}
-- Embeds AceConsole into the target object making the functions from the mixins list available on target:..
-- @param target target object to embed AceBucket in
function AceConsole:Embed( target )
for k, v in pairs( mixins ) do
target[v] = self[v]
end
self.embeds[target] = true
return target
end
function AceConsole:OnEmbedEnable( target )
if AceConsole.weakcommands[target] then
for command, func in pairs( AceConsole.weakcommands[target] ) do
target:RegisterChatCommand( command, func, false, true ) -- nonpersisting and silent registry
end
end
end
function AceConsole:OnEmbedDisable( target )
if AceConsole.weakcommands[target] then
for command, func in pairs( AceConsole.weakcommands[target] ) do
target:UnregisterChatCommand( command ) -- TODO: this could potentially unregister a command from another application in case of command conflicts. Do we care?
end
end
end
for addon in pairs(AceConsole.embeds) do
AceConsole:Embed(addon)
end

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="AceConsole-3.0.lua"/>
</Ui>

View File

@ -0,0 +1,745 @@
--- **AceDB-3.0** manages the SavedVariables of your addon.
-- It offers profile management, smart defaults and namespaces for modules.\\
-- Data can be saved in different data-types, depending on its intended usage.
-- The most common data-type is the `profile` type, which allows the user to choose
-- the active profile, and manage the profiles of all of his characters.\\
-- The following data types are available:
-- * **char** Character-specific data. Every character has its own database.
-- * **realm** Realm-specific data. All of the players characters on the same realm share this database.
-- * **class** Class-specific data. All of the players characters of the same class share this database.
-- * **race** Race-specific data. All of the players characters of the same race share this database.
-- * **faction** Faction-specific data. All of the players characters of the same faction share this database.
-- * **factionrealm** Faction and realm specific data. All of the players characters on the same realm and of the same faction share this database.
-- * **global** Global Data. All characters on the same account share this database.
-- * **profile** Profile-specific data. All characters using the same profile share this database. The user can control which profile should be used.
--
-- Creating a new Database using the `:New` function will return a new DBObject. A database will inherit all functions
-- of the DBObjectLib listed here. \\
-- If you create a new namespaced child-database (`:RegisterNamespace`), you'll get a DBObject as well, but note
-- that the child-databases cannot individually change their profile, and are linked to their parents profile - and because of that,
-- the profile related APIs are not available. Only `:RegisterDefaults` and `:ResetProfile` are available on child-databases.
--
-- For more details on how to use AceDB-3.0, see the [[AceDB-3.0 Tutorial]].
--
-- You may also be interested in [[libdualspec-1-0|LibDualSpec-1.0]] to do profile switching automatically when switching specs.
--
-- @usage
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("DBExample")
--
-- -- declare defaults to be used in the DB
-- local defaults = {
-- profile = {
-- setting = true,
-- }
-- }
--
-- function MyAddon:OnInitialize()
-- -- Assuming the .toc says ## SavedVariables: MyAddonDB
-- self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, true)
-- end
-- @class file
-- @name AceDB-3.0.lua
-- @release $Id: AceDB-3.0.lua 1124 2014-10-27 21:00:07Z funkydude $
local ACEDB_MAJOR, ACEDB_MINOR = "AceDB-3.0", 26
local AceDB, oldminor = LibStub:NewLibrary(ACEDB_MAJOR, ACEDB_MINOR)
if not AceDB then return end -- No upgrade needed
-- Lua APIs
local type, pairs, next, error = type, pairs, next, error
local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget
-- WoW APIs
local _G = _G
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
-- List them here for Mikk's FindGlobals script
-- GLOBALS: LibStub
AceDB.db_registry = AceDB.db_registry or {}
AceDB.frame = AceDB.frame or CreateFrame("Frame")
local CallbackHandler
local CallbackDummy = { Fire = function() end }
local DBObjectLib = {}
--[[-------------------------------------------------------------------------
AceDB Utility Functions
---------------------------------------------------------------------------]]
-- Simple shallow copy for copying defaults
local function copyTable(src, dest)
if type(dest) ~= "table" then dest = {} end
if type(src) == "table" then
for k,v in pairs(src) do
if type(v) == "table" then
-- try to index the key first so that the metatable creates the defaults, if set, and use that table
v = copyTable(v, dest[k])
end
dest[k] = v
end
end
return dest
end
-- Called to add defaults to a section of the database
--
-- When a ["*"] default section is indexed with a new key, a table is returned
-- and set in the host table. These tables must be cleaned up by removeDefaults
-- in order to ensure we don't write empty default tables.
local function copyDefaults(dest, src)
-- this happens if some value in the SV overwrites our default value with a non-table
--if type(dest) ~= "table" then return end
for k, v in pairs(src) do
if k == "*" or k == "**" then
if type(v) == "table" then
-- This is a metatable used for table defaults
local mt = {
-- This handles the lookup and creation of new subtables
__index = function(t,k)
if k == nil then return nil end
local tbl = {}
copyDefaults(tbl, v)
rawset(t, k, tbl)
return tbl
end,
}
setmetatable(dest, mt)
-- handle already existing tables in the SV
for dk, dv in pairs(dest) do
if not rawget(src, dk) and type(dv) == "table" then
copyDefaults(dv, v)
end
end
else
-- Values are not tables, so this is just a simple return
local mt = {__index = function(t,k) return k~=nil and v or nil end}
setmetatable(dest, mt)
end
elseif type(v) == "table" then
if not rawget(dest, k) then rawset(dest, k, {}) end
if type(dest[k]) == "table" then
copyDefaults(dest[k], v)
if src['**'] then
copyDefaults(dest[k], src['**'])
end
end
else
if rawget(dest, k) == nil then
rawset(dest, k, v)
end
end
end
end
-- Called to remove all defaults in the default table from the database
local function removeDefaults(db, defaults, blocker)
-- remove all metatables from the db, so we don't accidentally create new sub-tables through them
setmetatable(db, nil)
-- loop through the defaults and remove their content
for k,v in pairs(defaults) do
if k == "*" or k == "**" then
if type(v) == "table" then
-- Loop through all the actual k,v pairs and remove
for key, value in pairs(db) do
if type(value) == "table" then
-- if the key was not explicitly specified in the defaults table, just strip everything from * and ** tables
if defaults[key] == nil and (not blocker or blocker[key] == nil) then
removeDefaults(value, v)
-- if the table is empty afterwards, remove it
if next(value) == nil then
db[key] = nil
end
-- if it was specified, only strip ** content, but block values which were set in the key table
elseif k == "**" then
removeDefaults(value, v, defaults[key])
end
end
end
elseif k == "*" then
-- check for non-table default
for key, value in pairs(db) do
if defaults[key] == nil and v == value then
db[key] = nil
end
end
end
elseif type(v) == "table" and type(db[k]) == "table" then
-- if a blocker was set, dive into it, to allow multi-level defaults
removeDefaults(db[k], v, blocker and blocker[k])
if next(db[k]) == nil then
db[k] = nil
end
else
-- check if the current value matches the default, and that its not blocked by another defaults table
if db[k] == defaults[k] and (not blocker or blocker[k] == nil) then
db[k] = nil
end
end
end
end
-- This is called when a table section is first accessed, to set up the defaults
local function initSection(db, section, svstore, key, defaults)
local sv = rawget(db, "sv")
local tableCreated
if not sv[svstore] then sv[svstore] = {} end
if not sv[svstore][key] then
sv[svstore][key] = {}
tableCreated = true
end
local tbl = sv[svstore][key]
if defaults then
copyDefaults(tbl, defaults)
end
rawset(db, section, tbl)
return tableCreated, tbl
end
-- Metatable to handle the dynamic creation of sections and copying of sections.
local dbmt = {
__index = function(t, section)
local keys = rawget(t, "keys")
local key = keys[section]
if key then
local defaultTbl = rawget(t, "defaults")
local defaults = defaultTbl and defaultTbl[section]
if section == "profile" then
local new = initSection(t, section, "profiles", key, defaults)
if new then
-- Callback: OnNewProfile, database, newProfileKey
t.callbacks:Fire("OnNewProfile", t, key)
end
elseif section == "profiles" then
local sv = rawget(t, "sv")
if not sv.profiles then sv.profiles = {} end
rawset(t, "profiles", sv.profiles)
elseif section == "global" then
local sv = rawget(t, "sv")
if not sv.global then sv.global = {} end
if defaults then
copyDefaults(sv.global, defaults)
end
rawset(t, section, sv.global)
else
initSection(t, section, section, key, defaults)
end
end
return rawget(t, section)
end
}
local function validateDefaults(defaults, keyTbl, offset)
if not defaults then return end
offset = offset or 0
for k in pairs(defaults) do
if not keyTbl[k] or k == "profiles" then
error(("Usage: AceDBObject:RegisterDefaults(defaults): '%s' is not a valid datatype."):format(k), 3 + offset)
end
end
end
local preserve_keys = {
["callbacks"] = true,
["RegisterCallback"] = true,
["UnregisterCallback"] = true,
["UnregisterAllCallbacks"] = true,
["children"] = true,
}
local realmKey = GetRealmName()
local charKey = UnitName("player") .. " - " .. realmKey
local _, classKey = UnitClass("player")
local _, raceKey = UnitRace("player")
local factionKey = UnitFactionGroup("player")
local factionrealmKey = factionKey .. " - " .. realmKey
local localeKey = GetLocale():lower()
local regionTable = { "US", "KR", "EU", "TW", "CN" }
local regionKey = regionTable[GetCurrentRegion()]
local factionrealmregionKey = factionrealmKey .. " - " .. regionKey
-- Actual database initialization function
local function initdb(sv, defaults, defaultProfile, olddb, parent)
-- Generate the database keys for each section
-- map "true" to our "Default" profile
if defaultProfile == true then defaultProfile = "Default" end
local profileKey
if not parent then
-- Make a container for profile keys
if not sv.profileKeys then sv.profileKeys = {} end
-- Try to get the profile selected from the char db
profileKey = sv.profileKeys[charKey] or defaultProfile or charKey
-- save the selected profile for later
sv.profileKeys[charKey] = profileKey
else
-- Use the profile of the parents DB
profileKey = parent.keys.profile or defaultProfile or charKey
-- clear the profileKeys in the DB, namespaces don't need to store them
sv.profileKeys = nil
end
-- This table contains keys that enable the dynamic creation
-- of each section of the table. The 'global' and 'profiles'
-- have a key of true, since they are handled in a special case
local keyTbl= {
["char"] = charKey,
["realm"] = realmKey,
["class"] = classKey,
["race"] = raceKey,
["faction"] = factionKey,
["factionrealm"] = factionrealmKey,
["factionrealmregion"] = factionrealmregionKey,
["profile"] = profileKey,
["locale"] = localeKey,
["global"] = true,
["profiles"] = true,
}
validateDefaults(defaults, keyTbl, 1)
-- This allows us to use this function to reset an entire database
-- Clear out the old database
if olddb then
for k,v in pairs(olddb) do if not preserve_keys[k] then olddb[k] = nil end end
end
-- Give this database the metatable so it initializes dynamically
local db = setmetatable(olddb or {}, dbmt)
if not rawget(db, "callbacks") then
-- try to load CallbackHandler-1.0 if it loaded after our library
if not CallbackHandler then CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0", true) end
db.callbacks = CallbackHandler and CallbackHandler:New(db) or CallbackDummy
end
-- Copy methods locally into the database object, to avoid hitting
-- the metatable when calling methods
if not parent then
for name, func in pairs(DBObjectLib) do
db[name] = func
end
else
-- hack this one in
db.RegisterDefaults = DBObjectLib.RegisterDefaults
db.ResetProfile = DBObjectLib.ResetProfile
end
-- Set some properties in the database object
db.profiles = sv.profiles
db.keys = keyTbl
db.sv = sv
--db.sv_name = name
db.defaults = defaults
db.parent = parent
-- store the DB in the registry
AceDB.db_registry[db] = true
return db
end
-- handle PLAYER_LOGOUT
-- strip all defaults from all databases
-- and cleans up empty sections
local function logoutHandler(frame, event)
if event == "PLAYER_LOGOUT" then
for db in pairs(AceDB.db_registry) do
db.callbacks:Fire("OnDatabaseShutdown", db)
db:RegisterDefaults(nil)
-- cleanup sections that are empty without defaults
local sv = rawget(db, "sv")
for section in pairs(db.keys) do
if rawget(sv, section) then
-- global is special, all other sections have sub-entrys
-- also don't delete empty profiles on main dbs, only on namespaces
if section ~= "global" and (section ~= "profiles" or rawget(db, "parent")) then
for key in pairs(sv[section]) do
if not next(sv[section][key]) then
sv[section][key] = nil
end
end
end
if not next(sv[section]) then
sv[section] = nil
end
end
end
end
end
end
AceDB.frame:RegisterEvent("PLAYER_LOGOUT")
AceDB.frame:SetScript("OnEvent", logoutHandler)
--[[-------------------------------------------------------------------------
AceDB Object Method Definitions
---------------------------------------------------------------------------]]
--- Sets the defaults table for the given database object by clearing any
-- that are currently set, and then setting the new defaults.
-- @param defaults A table of defaults for this database
function DBObjectLib:RegisterDefaults(defaults)
if defaults and type(defaults) ~= "table" then
error("Usage: AceDBObject:RegisterDefaults(defaults): 'defaults' - table or nil expected.", 2)
end
validateDefaults(defaults, self.keys)
-- Remove any currently set defaults
if self.defaults then
for section,key in pairs(self.keys) do
if self.defaults[section] and rawget(self, section) then
removeDefaults(self[section], self.defaults[section])
end
end
end
-- Set the DBObject.defaults table
self.defaults = defaults
-- Copy in any defaults, only touching those sections already created
if defaults then
for section,key in pairs(self.keys) do
if defaults[section] and rawget(self, section) then
copyDefaults(self[section], defaults[section])
end
end
end
end
--- Changes the profile of the database and all of it's namespaces to the
-- supplied named profile
-- @param name The name of the profile to set as the current profile
function DBObjectLib:SetProfile(name)
if type(name) ~= "string" then
error("Usage: AceDBObject:SetProfile(name): 'name' - string expected.", 2)
end
-- changing to the same profile, dont do anything
if name == self.keys.profile then return end
local oldProfile = self.profile
local defaults = self.defaults and self.defaults.profile
-- Callback: OnProfileShutdown, database
self.callbacks:Fire("OnProfileShutdown", self)
if oldProfile and defaults then
-- Remove the defaults from the old profile
removeDefaults(oldProfile, defaults)
end
self.profile = nil
self.keys["profile"] = name
-- if the storage exists, save the new profile
-- this won't exist on namespaces.
if self.sv.profileKeys then
self.sv.profileKeys[charKey] = name
end
-- populate to child namespaces
if self.children then
for _, db in pairs(self.children) do
DBObjectLib.SetProfile(db, name)
end
end
-- Callback: OnProfileChanged, database, newProfileKey
self.callbacks:Fire("OnProfileChanged", self, name)
end
--- Returns a table with the names of the existing profiles in the database.
-- You can optionally supply a table to re-use for this purpose.
-- @param tbl A table to store the profile names in (optional)
function DBObjectLib:GetProfiles(tbl)
if tbl and type(tbl) ~= "table" then
error("Usage: AceDBObject:GetProfiles(tbl): 'tbl' - table or nil expected.", 2)
end
-- Clear the container table
if tbl then
for k,v in pairs(tbl) do tbl[k] = nil end
else
tbl = {}
end
local curProfile = self.keys.profile
local i = 0
for profileKey in pairs(self.profiles) do
i = i + 1
tbl[i] = profileKey
if curProfile and profileKey == curProfile then curProfile = nil end
end
-- Add the current profile, if it hasn't been created yet
if curProfile then
i = i + 1
tbl[i] = curProfile
end
return tbl, i
end
--- Returns the current profile name used by the database
function DBObjectLib:GetCurrentProfile()
return self.keys.profile
end
--- Deletes a named profile. This profile must not be the active profile.
-- @param name The name of the profile to be deleted
-- @param silent If true, do not raise an error when the profile does not exist
function DBObjectLib:DeleteProfile(name, silent)
if type(name) ~= "string" then
error("Usage: AceDBObject:DeleteProfile(name): 'name' - string expected.", 2)
end
if self.keys.profile == name then
error("Cannot delete the active profile in an AceDBObject.", 2)
end
if not rawget(self.profiles, name) and not silent then
error("Cannot delete profile '" .. name .. "'. It does not exist.", 2)
end
self.profiles[name] = nil
-- populate to child namespaces
if self.children then
for _, db in pairs(self.children) do
DBObjectLib.DeleteProfile(db, name, true)
end
end
-- switch all characters that use this profile back to the default
if self.sv.profileKeys then
for key, profile in pairs(self.sv.profileKeys) do
if profile == name then
self.sv.profileKeys[key] = nil
end
end
end
-- Callback: OnProfileDeleted, database, profileKey
self.callbacks:Fire("OnProfileDeleted", self, name)
end
--- Copies a named profile into the current profile, overwriting any conflicting
-- settings.
-- @param name The name of the profile to be copied into the current profile
-- @param silent If true, do not raise an error when the profile does not exist
function DBObjectLib:CopyProfile(name, silent)
if type(name) ~= "string" then
error("Usage: AceDBObject:CopyProfile(name): 'name' - string expected.", 2)
end
if name == self.keys.profile then
error("Cannot have the same source and destination profiles.", 2)
end
if not rawget(self.profiles, name) and not silent then
error("Cannot copy profile '" .. name .. "'. It does not exist.", 2)
end
-- Reset the profile before copying
DBObjectLib.ResetProfile(self, nil, true)
local profile = self.profile
local source = self.profiles[name]
copyTable(source, profile)
-- populate to child namespaces
if self.children then
for _, db in pairs(self.children) do
DBObjectLib.CopyProfile(db, name, true)
end
end
-- Callback: OnProfileCopied, database, sourceProfileKey
self.callbacks:Fire("OnProfileCopied", self, name)
end
--- Resets the current profile to the default values (if specified).
-- @param noChildren if set to true, the reset will not be populated to the child namespaces of this DB object
-- @param noCallbacks if set to true, won't fire the OnProfileReset callback
function DBObjectLib:ResetProfile(noChildren, noCallbacks)
local profile = self.profile
for k,v in pairs(profile) do
profile[k] = nil
end
local defaults = self.defaults and self.defaults.profile
if defaults then
copyDefaults(profile, defaults)
end
-- populate to child namespaces
if self.children and not noChildren then
for _, db in pairs(self.children) do
DBObjectLib.ResetProfile(db, nil, noCallbacks)
end
end
-- Callback: OnProfileReset, database
if not noCallbacks then
self.callbacks:Fire("OnProfileReset", self)
end
end
--- Resets the entire database, using the string defaultProfile as the new default
-- profile.
-- @param defaultProfile The profile name to use as the default
function DBObjectLib:ResetDB(defaultProfile)
if defaultProfile and type(defaultProfile) ~= "string" then
error("Usage: AceDBObject:ResetDB(defaultProfile): 'defaultProfile' - string or nil expected.", 2)
end
local sv = self.sv
for k,v in pairs(sv) do
sv[k] = nil
end
local parent = self.parent
initdb(sv, self.defaults, defaultProfile, self)
-- fix the child namespaces
if self.children then
if not sv.namespaces then sv.namespaces = {} end
for name, db in pairs(self.children) do
if not sv.namespaces[name] then sv.namespaces[name] = {} end
initdb(sv.namespaces[name], db.defaults, self.keys.profile, db, self)
end
end
-- Callback: OnDatabaseReset, database
self.callbacks:Fire("OnDatabaseReset", self)
-- Callback: OnProfileChanged, database, profileKey
self.callbacks:Fire("OnProfileChanged", self, self.keys["profile"])
return self
end
--- Creates a new database namespace, directly tied to the database. This
-- is a full scale database in it's own rights other than the fact that
-- it cannot control its profile individually
-- @param name The name of the new namespace
-- @param defaults A table of values to use as defaults
function DBObjectLib:RegisterNamespace(name, defaults)
if type(name) ~= "string" then
error("Usage: AceDBObject:RegisterNamespace(name, defaults): 'name' - string expected.", 2)
end
if defaults and type(defaults) ~= "table" then
error("Usage: AceDBObject:RegisterNamespace(name, defaults): 'defaults' - table or nil expected.", 2)
end
if self.children and self.children[name] then
error ("Usage: AceDBObject:RegisterNamespace(name, defaults): 'name' - a namespace with that name already exists.", 2)
end
local sv = self.sv
if not sv.namespaces then sv.namespaces = {} end
if not sv.namespaces[name] then
sv.namespaces[name] = {}
end
local newDB = initdb(sv.namespaces[name], defaults, self.keys.profile, nil, self)
if not self.children then self.children = {} end
self.children[name] = newDB
return newDB
end
--- Returns an already existing namespace from the database object.
-- @param name The name of the new namespace
-- @param silent if true, the addon is optional, silently return nil if its not found
-- @usage
-- local namespace = self.db:GetNamespace('namespace')
-- @return the namespace object if found
function DBObjectLib:GetNamespace(name, silent)
if type(name) ~= "string" then
error("Usage: AceDBObject:GetNamespace(name): 'name' - string expected.", 2)
end
if not silent and not (self.children and self.children[name]) then
error ("Usage: AceDBObject:GetNamespace(name): 'name' - namespace does not exist.", 2)
end
if not self.children then self.children = {} end
return self.children[name]
end
--[[-------------------------------------------------------------------------
AceDB Exposed Methods
---------------------------------------------------------------------------]]
--- Creates a new database object that can be used to handle database settings and profiles.
-- By default, an empty DB is created, using a character specific profile.
--
-- You can override the default profile used by passing any profile name as the third argument,
-- or by passing //true// as the third argument to use a globally shared profile called "Default".
--
-- Note that there is no token replacement in the default profile name, passing a defaultProfile as "char"
-- will use a profile named "char", and not a character-specific profile.
-- @param tbl The name of variable, or table to use for the database
-- @param defaults A table of database defaults
-- @param defaultProfile The name of the default profile. If not set, a character specific profile will be used as the default.
-- You can also pass //true// to use a shared global profile called "Default".
-- @usage
-- -- Create an empty DB using a character-specific default profile.
-- self.db = LibStub("AceDB-3.0"):New("MyAddonDB")
-- @usage
-- -- Create a DB using defaults and using a shared default profile
-- self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, true)
function AceDB:New(tbl, defaults, defaultProfile)
if type(tbl) == "string" then
local name = tbl
tbl = _G[name]
if not tbl then
tbl = {}
_G[name] = tbl
end
end
if type(tbl) ~= "table" then
error("Usage: AceDB:New(tbl, defaults, defaultProfile): 'tbl' - table expected.", 2)
end
if defaults and type(defaults) ~= "table" then
error("Usage: AceDB:New(tbl, defaults, defaultProfile): 'defaults' - table expected.", 2)
end
if defaultProfile and type(defaultProfile) ~= "string" and defaultProfile ~= true then
error("Usage: AceDB:New(tbl, defaults, defaultProfile): 'defaultProfile' - string or true expected.", 2)
end
return initdb(tbl, defaults, defaultProfile)
end
-- upgrade existing databases
for db in pairs(AceDB.db_registry) do
if not db.parent then
for name,func in pairs(DBObjectLib) do
db[name] = func
end
else
db.RegisterDefaults = DBObjectLib.RegisterDefaults
db.ResetProfile = DBObjectLib.ResetProfile
end
end

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="AceDB-3.0.lua"/>
</Ui>

View File

@ -0,0 +1,126 @@
--- AceEvent-3.0 provides event registration and secure dispatching.
-- All dispatching is done using **CallbackHandler-1.0**. AceEvent is a simple wrapper around
-- CallbackHandler, and dispatches all game events or addon message to the registrees.
--
-- **AceEvent-3.0** can be embeded into your addon, either explicitly by calling AceEvent:Embed(MyAddon) or by
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
-- and can be accessed directly, without having to explicitly call AceEvent itself.\\
-- It is recommended to embed AceEvent, otherwise you'll have to specify a custom `self` on all calls you
-- make into AceEvent.
-- @class file
-- @name AceEvent-3.0
-- @release $Id: AceEvent-3.0.lua 975 2010-10-23 11:26:18Z nevcairiel $
local MAJOR, MINOR = "AceEvent-3.0", 3
local AceEvent = LibStub:NewLibrary(MAJOR, MINOR)
if not AceEvent then return end
-- Lua APIs
local pairs = pairs
local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0")
AceEvent.frame = AceEvent.frame or CreateFrame("Frame", "AceEvent30Frame") -- our event frame
AceEvent.embeds = AceEvent.embeds or {} -- what objects embed this lib
-- APIs and registry for blizzard events, using CallbackHandler lib
if not AceEvent.events then
AceEvent.events = CallbackHandler:New(AceEvent,
"RegisterEvent", "UnregisterEvent", "UnregisterAllEvents")
end
function AceEvent.events:OnUsed(target, eventname)
AceEvent.frame:RegisterEvent(eventname)
end
function AceEvent.events:OnUnused(target, eventname)
AceEvent.frame:UnregisterEvent(eventname)
end
-- APIs and registry for IPC messages, using CallbackHandler lib
if not AceEvent.messages then
AceEvent.messages = CallbackHandler:New(AceEvent,
"RegisterMessage", "UnregisterMessage", "UnregisterAllMessages"
)
AceEvent.SendMessage = AceEvent.messages.Fire
end
--- embedding and embed handling
local mixins = {
"RegisterEvent", "UnregisterEvent",
"RegisterMessage", "UnregisterMessage",
"SendMessage",
"UnregisterAllEvents", "UnregisterAllMessages",
}
--- Register for a Blizzard Event.
-- The callback will be called with the optional `arg` as the first argument (if supplied), and the event name as the second (or first, if no arg was supplied)
-- Any arguments to the event will be passed on after that.
-- @name AceEvent:RegisterEvent
-- @class function
-- @paramsig event[, callback [, arg]]
-- @param event The event to register for
-- @param callback The callback function to call when the event is triggered (funcref or method, defaults to a method with the event name)
-- @param arg An optional argument to pass to the callback function
--- Unregister an event.
-- @name AceEvent:UnregisterEvent
-- @class function
-- @paramsig event
-- @param event The event to unregister
--- Register for a custom AceEvent-internal message.
-- The callback will be called with the optional `arg` as the first argument (if supplied), and the event name as the second (or first, if no arg was supplied)
-- Any arguments to the event will be passed on after that.
-- @name AceEvent:RegisterMessage
-- @class function
-- @paramsig message[, callback [, arg]]
-- @param message The message to register for
-- @param callback The callback function to call when the message is triggered (funcref or method, defaults to a method with the event name)
-- @param arg An optional argument to pass to the callback function
--- Unregister a message
-- @name AceEvent:UnregisterMessage
-- @class function
-- @paramsig message
-- @param message The message to unregister
--- Send a message over the AceEvent-3.0 internal message system to other addons registered for this message.
-- @name AceEvent:SendMessage
-- @class function
-- @paramsig message, ...
-- @param message The message to send
-- @param ... Any arguments to the message
-- Embeds AceEvent into the target object making the functions from the mixins list available on target:..
-- @param target target object to embed AceEvent in
function AceEvent:Embed(target)
for k, v in pairs(mixins) do
target[v] = self[v]
end
self.embeds[target] = true
return target
end
-- AceEvent:OnEmbedDisable( target )
-- target (object) - target object that is being disabled
--
-- Unregister all events messages etc when the target disables.
-- this method should be called by the target manually or by an addon framework
function AceEvent:OnEmbedDisable(target)
target:UnregisterAllEvents()
target:UnregisterAllMessages()
end
-- Script to fire blizzard events into the event listeners
local events = AceEvent.events
AceEvent.frame:SetScript("OnEvent", function(this, event, ...)
events:Fire(event, ...)
end)
--- Finally: upgrade our old embeds
for target, v in pairs(AceEvent.embeds) do
AceEvent:Embed(target)
end

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="AceEvent-3.0.lua"/>
</Ui>

View File

@ -0,0 +1,511 @@
--- **AceHook-3.0** offers safe Hooking/Unhooking of functions, methods and frame scripts.
-- Using AceHook-3.0 is recommended when you need to unhook your hooks again, so the hook chain isn't broken
-- when you manually restore the original function.
--
-- **AceHook-3.0** can be embeded into your addon, either explicitly by calling AceHook:Embed(MyAddon) or by
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
-- and can be accessed directly, without having to explicitly call AceHook itself.\\
-- It is recommended to embed AceHook, otherwise you'll have to specify a custom `self` on all calls you
-- make into AceHook.
-- @class file
-- @name AceHook-3.0
-- @release $Id: AceHook-3.0.lua 1118 2014-10-12 08:21:54Z nevcairiel $
local ACEHOOK_MAJOR, ACEHOOK_MINOR = "AceHook-3.0", 8
local AceHook, oldminor = LibStub:NewLibrary(ACEHOOK_MAJOR, ACEHOOK_MINOR)
if not AceHook then return end -- No upgrade needed
AceHook.embeded = AceHook.embeded or {}
AceHook.registry = AceHook.registry or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end })
AceHook.handlers = AceHook.handlers or {}
AceHook.actives = AceHook.actives or {}
AceHook.scripts = AceHook.scripts or {}
AceHook.onceSecure = AceHook.onceSecure or {}
AceHook.hooks = AceHook.hooks or {}
-- local upvalues
local registry = AceHook.registry
local handlers = AceHook.handlers
local actives = AceHook.actives
local scripts = AceHook.scripts
local onceSecure = AceHook.onceSecure
-- Lua APIs
local pairs, next, type = pairs, next, type
local format = string.format
local assert, error = assert, error
-- WoW APIs
local issecurevariable, hooksecurefunc = issecurevariable, hooksecurefunc
local _G = _G
-- functions for later definition
local donothing, createHook, hook
local protectedScripts = {
OnClick = true,
}
-- upgrading of embeded is done at the bottom of the file
local mixins = {
"Hook", "SecureHook",
"HookScript", "SecureHookScript",
"Unhook", "UnhookAll",
"IsHooked",
"RawHook", "RawHookScript"
}
-- AceHook:Embed( target )
-- target (object) - target object to embed AceHook in
--
-- Embeds AceEevent into the target object making the functions from the mixins list available on target:..
function AceHook:Embed( target )
for k, v in pairs( mixins ) do
target[v] = self[v]
end
self.embeded[target] = true
-- inject the hooks table safely
target.hooks = target.hooks or {}
return target
end
-- AceHook:OnEmbedDisable( target )
-- target (object) - target object that is being disabled
--
-- Unhooks all hooks when the target disables.
-- this method should be called by the target manually or by an addon framework
function AceHook:OnEmbedDisable( target )
target:UnhookAll()
end
function createHook(self, handler, orig, secure, failsafe)
local uid
local method = type(handler) == "string"
if failsafe and not secure then
-- failsafe hook creation
uid = function(...)
if actives[uid] then
if method then
self[handler](self, ...)
else
handler(...)
end
end
return orig(...)
end
-- /failsafe hook
else
-- all other hooks
uid = function(...)
if actives[uid] then
if method then
return self[handler](self, ...)
else
return handler(...)
end
elseif not secure then -- backup on non secure
return orig(...)
end
end
-- /hook
end
return uid
end
function donothing() end
function hook(self, obj, method, handler, script, secure, raw, forceSecure, usage)
if not handler then handler = method end
-- These asserts make sure AceHooks's devs play by the rules.
assert(not script or type(script) == "boolean")
assert(not secure or type(secure) == "boolean")
assert(not raw or type(raw) == "boolean")
assert(not forceSecure or type(forceSecure) == "boolean")
assert(usage)
-- Error checking Battery!
if obj and type(obj) ~= "table" then
error(format("%s: 'object' - nil or table expected got %s", usage, type(obj)), 3)
end
if type(method) ~= "string" then
error(format("%s: 'method' - string expected got %s", usage, type(method)), 3)
end
if type(handler) ~= "string" and type(handler) ~= "function" then
error(format("%s: 'handler' - nil, string, or function expected got %s", usage, type(handler)), 3)
end
if type(handler) == "string" and type(self[handler]) ~= "function" then
error(format("%s: 'handler' - Handler specified does not exist at self[handler]", usage), 3)
end
if script then
if not obj or not obj.GetScript or not obj:HasScript(method) then
error(format("%s: You can only hook a script on a frame object", usage), 3)
end
if not secure and obj.IsProtected and obj:IsProtected() and protectedScripts[method] then
error(format("Cannot hook secure script %q; Use SecureHookScript(obj, method, [handler]) instead.", method), 3)
end
else
local issecure
if obj then
issecure = onceSecure[obj] and onceSecure[obj][method] or issecurevariable(obj, method)
else
issecure = onceSecure[method] or issecurevariable(method)
end
if issecure then
if forceSecure then
if obj then
onceSecure[obj] = onceSecure[obj] or {}
onceSecure[obj][method] = true
else
onceSecure[method] = true
end
elseif not secure then
error(format("%s: Attempt to hook secure function %s. Use `SecureHook' or add `true' to the argument list to override.", usage, method), 3)
end
end
end
local uid
if obj then
uid = registry[self][obj] and registry[self][obj][method]
else
uid = registry[self][method]
end
if uid then
if actives[uid] then
-- Only two sane choices exist here. We either a) error 100% of the time or b) always unhook and then hook
-- choice b would likely lead to odd debuging conditions or other mysteries so we're going with a.
error(format("Attempting to rehook already active hook %s.", method))
end
if handlers[uid] == handler then -- turn on a decative hook, note enclosures break this ability, small memory leak
actives[uid] = true
return
elseif obj then -- is there any reason not to call unhook instead of doing the following several lines?
if self.hooks and self.hooks[obj] then
self.hooks[obj][method] = nil
end
registry[self][obj][method] = nil
else
if self.hooks then
self.hooks[method] = nil
end
registry[self][method] = nil
end
handlers[uid], actives[uid], scripts[uid] = nil, nil, nil
uid = nil
end
local orig
if script then
orig = obj:GetScript(method) or donothing
elseif obj then
orig = obj[method]
else
orig = _G[method]
end
if not orig then
error(format("%s: Attempting to hook a non existing target", usage), 3)
end
uid = createHook(self, handler, orig, secure, not (raw or secure))
if obj then
self.hooks[obj] = self.hooks[obj] or {}
registry[self][obj] = registry[self][obj] or {}
registry[self][obj][method] = uid
if not secure then
self.hooks[obj][method] = orig
end
if script then
if not secure then
obj:SetScript(method, uid)
else
obj:HookScript(method, uid)
end
else
if not secure then
obj[method] = uid
else
hooksecurefunc(obj, method, uid)
end
end
else
registry[self][method] = uid
if not secure then
_G[method] = uid
self.hooks[method] = orig
else
hooksecurefunc(method, uid)
end
end
actives[uid], handlers[uid], scripts[uid] = true, handler, script and true or nil
end
--- Hook a function or a method on an object.
-- The hook created will be a "safe hook", that means that your handler will be called
-- before the hooked function ("Pre-Hook"), and you don't have to call the original function yourself,
-- however you cannot stop the execution of the function, or modify any of the arguments/return values.\\
-- This type of hook is typically used if you need to know if some function got called, and don't want to modify it.
-- @paramsig [object], method, [handler], [hookSecure]
-- @param object The object to hook a method from
-- @param method If object was specified, the name of the method, or the name of the function to hook.
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function)
-- @param hookSecure If true, AceHook will allow hooking of secure functions.
-- @usage
-- -- create an addon with AceHook embeded
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0")
--
-- function MyAddon:OnEnable()
-- -- Hook ActionButton_UpdateHotkeys, overwriting the secure status
-- self:Hook("ActionButton_UpdateHotkeys", true)
-- end
--
-- function MyAddon:ActionButton_UpdateHotkeys(button, type)
-- print(button:GetName() .. " is updating its HotKey")
-- end
function AceHook:Hook(object, method, handler, hookSecure)
if type(object) == "string" then
method, handler, hookSecure, object = object, method, handler, nil
end
if handler == true then
handler, hookSecure = nil, true
end
hook(self, object, method, handler, false, false, false, hookSecure or false, "Usage: Hook([object], method, [handler], [hookSecure])")
end
--- RawHook a function or a method on an object.
-- The hook created will be a "raw hook", that means that your handler will completly replace
-- the original function, and your handler has to call the original function (or not, depending on your intentions).\\
-- The original function will be stored in `self.hooks[object][method]` or `self.hooks[functionName]` respectively.\\
-- This type of hook can be used for all purposes, and is usually the most common case when you need to modify arguments
-- or want to control execution of the original function.
-- @paramsig [object], method, [handler], [hookSecure]
-- @param object The object to hook a method from
-- @param method If object was specified, the name of the method, or the name of the function to hook.
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function)
-- @param hookSecure If true, AceHook will allow hooking of secure functions.
-- @usage
-- -- create an addon with AceHook embeded
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0")
--
-- function MyAddon:OnEnable()
-- -- Hook ActionButton_UpdateHotkeys, overwriting the secure status
-- self:RawHook("ActionButton_UpdateHotkeys", true)
-- end
--
-- function MyAddon:ActionButton_UpdateHotkeys(button, type)
-- if button:GetName() == "MyButton" then
-- -- do stuff here
-- else
-- self.hooks.ActionButton_UpdateHotkeys(button, type)
-- end
-- end
function AceHook:RawHook(object, method, handler, hookSecure)
if type(object) == "string" then
method, handler, hookSecure, object = object, method, handler, nil
end
if handler == true then
handler, hookSecure = nil, true
end
hook(self, object, method, handler, false, false, true, hookSecure or false, "Usage: RawHook([object], method, [handler], [hookSecure])")
end
--- SecureHook a function or a method on an object.
-- This function is a wrapper around the `hooksecurefunc` function in the WoW API. Using AceHook
-- extends the functionality of secure hooks, and adds the ability to unhook once the hook isn't
-- required anymore, or the addon is being disabled.\\
-- Secure Hooks should be used if the secure-status of the function is vital to its function,
-- and taint would block execution. Secure Hooks are always called after the original function was called
-- ("Post Hook"), and you cannot modify the arguments, return values or control the execution.
-- @paramsig [object], method, [handler]
-- @param object The object to hook a method from
-- @param method If object was specified, the name of the method, or the name of the function to hook.
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function)
function AceHook:SecureHook(object, method, handler)
if type(object) == "string" then
method, handler, object = object, method, nil
end
hook(self, object, method, handler, false, true, false, false, "Usage: SecureHook([object], method, [handler])")
end
--- Hook a script handler on a frame.
-- The hook created will be a "safe hook", that means that your handler will be called
-- before the hooked script ("Pre-Hook"), and you don't have to call the original function yourself,
-- however you cannot stop the execution of the function, or modify any of the arguments/return values.\\
-- This is the frame script equivalent of the :Hook safe-hook. It would typically be used to be notified
-- when a certain event happens to a frame.
-- @paramsig frame, script, [handler]
-- @param frame The Frame to hook the script on
-- @param script The script to hook
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked script)
-- @usage
-- -- create an addon with AceHook embeded
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0")
--
-- function MyAddon:OnEnable()
-- -- Hook the OnShow of FriendsFrame
-- self:HookScript(FriendsFrame, "OnShow", "FriendsFrameOnShow")
-- end
--
-- function MyAddon:FriendsFrameOnShow(frame)
-- print("The FriendsFrame was shown!")
-- end
function AceHook:HookScript(frame, script, handler)
hook(self, frame, script, handler, true, false, false, false, "Usage: HookScript(object, method, [handler])")
end
--- RawHook a script handler on a frame.
-- The hook created will be a "raw hook", that means that your handler will completly replace
-- the original script, and your handler has to call the original script (or not, depending on your intentions).\\
-- The original script will be stored in `self.hooks[frame][script]`.\\
-- This type of hook can be used for all purposes, and is usually the most common case when you need to modify arguments
-- or want to control execution of the original script.
-- @paramsig frame, script, [handler]
-- @param frame The Frame to hook the script on
-- @param script The script to hook
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked script)
-- @usage
-- -- create an addon with AceHook embeded
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0")
--
-- function MyAddon:OnEnable()
-- -- Hook the OnShow of FriendsFrame
-- self:RawHookScript(FriendsFrame, "OnShow", "FriendsFrameOnShow")
-- end
--
-- function MyAddon:FriendsFrameOnShow(frame)
-- -- Call the original function
-- self.hooks[frame].OnShow(frame)
-- -- Do our processing
-- -- .. stuff
-- end
function AceHook:RawHookScript(frame, script, handler)
hook(self, frame, script, handler, true, false, true, false, "Usage: RawHookScript(object, method, [handler])")
end
--- SecureHook a script handler on a frame.
-- This function is a wrapper around the `frame:HookScript` function in the WoW API. Using AceHook
-- extends the functionality of secure hooks, and adds the ability to unhook once the hook isn't
-- required anymore, or the addon is being disabled.\\
-- Secure Hooks should be used if the secure-status of the function is vital to its function,
-- and taint would block execution. Secure Hooks are always called after the original function was called
-- ("Post Hook"), and you cannot modify the arguments, return values or control the execution.
-- @paramsig frame, script, [handler]
-- @param frame The Frame to hook the script on
-- @param script The script to hook
-- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked script)
function AceHook:SecureHookScript(frame, script, handler)
hook(self, frame, script, handler, true, true, false, false, "Usage: SecureHookScript(object, method, [handler])")
end
--- Unhook from the specified function, method or script.
-- @paramsig [obj], method
-- @param obj The object or frame to unhook from
-- @param method The name of the method, function or script to unhook from.
function AceHook:Unhook(obj, method)
local usage = "Usage: Unhook([obj], method)"
if type(obj) == "string" then
method, obj = obj, nil
end
if obj and type(obj) ~= "table" then
error(format("%s: 'obj' - expecting nil or table got %s", usage, type(obj)), 2)
end
if type(method) ~= "string" then
error(format("%s: 'method' - expeting string got %s", usage, type(method)), 2)
end
local uid
if obj then
uid = registry[self][obj] and registry[self][obj][method]
else
uid = registry[self][method]
end
if not uid or not actives[uid] then
-- Declining to error on an unneeded unhook since the end effect is the same and this would just be annoying.
return false
end
actives[uid], handlers[uid] = nil, nil
if obj then
registry[self][obj][method] = nil
registry[self][obj] = next(registry[self][obj]) and registry[self][obj] or nil
-- if the hook reference doesnt exist, then its a secure hook, just bail out and dont do any unhooking
if not self.hooks[obj] or not self.hooks[obj][method] then return true end
if scripts[uid] and obj:GetScript(method) == uid then -- unhooks scripts
obj:SetScript(method, self.hooks[obj][method] ~= donothing and self.hooks[obj][method] or nil)
scripts[uid] = nil
elseif obj and self.hooks[obj] and self.hooks[obj][method] and obj[method] == uid then -- unhooks methods
obj[method] = self.hooks[obj][method]
end
self.hooks[obj][method] = nil
self.hooks[obj] = next(self.hooks[obj]) and self.hooks[obj] or nil
else
registry[self][method] = nil
-- if self.hooks[method] doesn't exist, then this is a SecureHook, just bail out
if not self.hooks[method] then return true end
if self.hooks[method] and _G[method] == uid then -- unhooks functions
_G[method] = self.hooks[method]
end
self.hooks[method] = nil
end
return true
end
--- Unhook all existing hooks for this addon.
function AceHook:UnhookAll()
for key, value in pairs(registry[self]) do
if type(key) == "table" then
for method in pairs(value) do
self:Unhook(key, method)
end
else
self:Unhook(key)
end
end
end
--- Check if the specific function, method or script is already hooked.
-- @paramsig [obj], method
-- @param obj The object or frame to unhook from
-- @param method The name of the method, function or script to unhook from.
function AceHook:IsHooked(obj, method)
-- we don't check if registry[self] exists, this is done by evil magicks in the metatable
if type(obj) == "string" then
if registry[self][obj] and actives[registry[self][obj]] then
return true, handlers[registry[self][obj]]
end
else
if registry[self][obj] and registry[self][obj][method] and actives[registry[self][obj][method]] then
return true, handlers[registry[self][obj][method]]
end
end
return false, nil
end
--- Upgrade our old embeded
for target, v in pairs( AceHook.embeded ) do
AceHook:Embed( target )
end

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="AceHook-3.0.lua"/>
</Ui>

View File

@ -0,0 +1,137 @@
--- **AceLocale-3.0** manages localization in addons, allowing for multiple locale to be registered with fallback to the base locale for untranslated strings.
-- @class file
-- @name AceLocale-3.0
-- @release $Id: AceLocale-3.0.lua 1035 2011-07-09 03:20:13Z kaelten $
local MAJOR,MINOR = "AceLocale-3.0", 6
local AceLocale, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not AceLocale then return end -- no upgrade needed
-- Lua APIs
local assert, tostring, error = assert, tostring, error
local getmetatable, setmetatable, rawset, rawget = getmetatable, setmetatable, rawset, rawget
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
-- List them here for Mikk's FindGlobals script
-- GLOBALS: GAME_LOCALE, geterrorhandler
local gameLocale = GetLocale()
if gameLocale == "enGB" then
gameLocale = "enUS"
end
AceLocale.apps = AceLocale.apps or {} -- array of ["AppName"]=localetableref
AceLocale.appnames = AceLocale.appnames or {} -- array of [localetableref]="AppName"
-- This metatable is used on all tables returned from GetLocale
local readmeta = {
__index = function(self, key) -- requesting totally unknown entries: fire off a nonbreaking error and return key
rawset(self, key, key) -- only need to see the warning once, really
geterrorhandler()(MAJOR..": "..tostring(AceLocale.appnames[self])..": Missing entry for '"..tostring(key).."'")
return key
end
}
-- This metatable is used on all tables returned from GetLocale if the silent flag is true, it does not issue a warning on unknown keys
local readmetasilent = {
__index = function(self, key) -- requesting totally unknown entries: return key
rawset(self, key, key) -- only need to invoke this function once
return key
end
}
-- Remember the locale table being registered right now (it gets set by :NewLocale())
-- NOTE: Do never try to register 2 locale tables at once and mix their definition.
local registering
-- local assert false function
local assertfalse = function() assert(false) end
-- This metatable proxy is used when registering nondefault locales
local writeproxy = setmetatable({}, {
__newindex = function(self, key, value)
rawset(registering, key, value == true and key or value) -- assigning values: replace 'true' with key string
end,
__index = assertfalse
})
-- This metatable proxy is used when registering the default locale.
-- It refuses to overwrite existing values
-- Reason 1: Allows loading locales in any order
-- Reason 2: If 2 modules have the same string, but only the first one to be
-- loaded has a translation for the current locale, the translation
-- doesn't get overwritten.
--
local writedefaultproxy = setmetatable({}, {
__newindex = function(self, key, value)
if not rawget(registering, key) then
rawset(registering, key, value == true and key or value)
end
end,
__index = assertfalse
})
--- Register a new locale (or extend an existing one) for the specified application.
-- :NewLocale will return a table you can fill your locale into, or nil if the locale isn't needed for the players
-- game locale.
-- @paramsig application, locale[, isDefault[, silent]]
-- @param application Unique name of addon / module
-- @param locale Name of the locale to register, e.g. "enUS", "deDE", etc.
-- @param isDefault If this is the default locale being registered (your addon is written in this language, generally enUS)
-- @param silent If true, the locale will not issue warnings for missing keys. Must be set on the first locale registered. If set to "raw", nils will be returned for unknown keys (no metatable used).
-- @usage
-- -- enUS.lua
-- local L = LibStub("AceLocale-3.0"):NewLocale("TestLocale", "enUS", true)
-- L["string1"] = true
--
-- -- deDE.lua
-- local L = LibStub("AceLocale-3.0"):NewLocale("TestLocale", "deDE")
-- if not L then return end
-- L["string1"] = "Zeichenkette1"
-- @return Locale Table to add localizations to, or nil if the current locale is not required.
function AceLocale:NewLocale(application, locale, isDefault, silent)
-- GAME_LOCALE allows translators to test translations of addons without having that wow client installed
local gameLocale = GAME_LOCALE or gameLocale
local app = AceLocale.apps[application]
if silent and app and getmetatable(app) ~= readmetasilent then
geterrorhandler()("Usage: NewLocale(application, locale[, isDefault[, silent]]): 'silent' must be specified for the first locale registered")
end
if not app then
if silent=="raw" then
app = {}
else
app = setmetatable({}, silent and readmetasilent or readmeta)
end
AceLocale.apps[application] = app
AceLocale.appnames[app] = application
end
if locale ~= gameLocale and not isDefault then
return -- nop, we don't need these translations
end
registering = app -- remember globally for writeproxy and writedefaultproxy
if isDefault then
return writedefaultproxy
end
return writeproxy
end
--- Returns localizations for the current locale (or default locale if translations are missing).
-- Errors if nothing is registered (spank developer, not just a missing translation)
-- @param application Unique name of addon / module
-- @param silent If true, the locale is optional, silently return nil if it's not found (defaults to false, optional)
-- @return The locale table for the current language.
function AceLocale:GetLocale(application, silent)
if not silent and not AceLocale.apps[application] then
error("Usage: GetLocale(application[, silent]): 'application' - No locales registered for '"..tostring(application).."'", 2)
end
return AceLocale.apps[application]
end

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="AceLocale-3.0.lua"/>
</Ui>

View File

@ -0,0 +1,283 @@
--- **AceSerializer-3.0** can serialize any variable (except functions or userdata) into a string format,
-- that can be send over the addon comm channel. AceSerializer was designed to keep all data intact, especially
-- very large numbers or floating point numbers, and table structures. The only caveat currently is, that multiple
-- references to the same table will be send individually.
--
-- **AceSerializer-3.0** can be embeded into your addon, either explicitly by calling AceSerializer:Embed(MyAddon) or by
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
-- and can be accessed directly, without having to explicitly call AceSerializer itself.\\
-- It is recommended to embed AceSerializer, otherwise you'll have to specify a custom `self` on all calls you
-- make into AceSerializer.
-- @class file
-- @name AceSerializer-3.0
-- @release $Id: AceSerializer-3.0.lua 1038 2011-10-03 01:39:58Z mikk $
local MAJOR,MINOR = "AceSerializer-3.0", 4
local AceSerializer, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not AceSerializer then return end
-- Lua APIs
local strbyte, strchar, gsub, gmatch, format = string.byte, string.char, string.gsub, string.gmatch, string.format
local assert, error, pcall = assert, error, pcall
local type, tostring, tonumber = type, tostring, tonumber
local pairs, select, frexp = pairs, select, math.frexp
local tconcat = table.concat
-- quick copies of string representations of wonky numbers
local inf = math.huge
local serNaN -- can't do this in 4.3, see ace3 ticket 268
local serInf = tostring(inf)
local serNegInf = tostring(-inf)
-- Serialization functions
local function SerializeStringHelper(ch) -- Used by SerializeValue for strings
-- We use \126 ("~") as an escape character for all nonprints plus a few more
local n = strbyte(ch)
if n==30 then -- v3 / ticket 115: catch a nonprint that ends up being "~^" when encoded... DOH
return "\126\122"
elseif n<=32 then -- nonprint + space
return "\126"..strchar(n+64)
elseif n==94 then -- value separator
return "\126\125"
elseif n==126 then -- our own escape character
return "\126\124"
elseif n==127 then -- nonprint (DEL)
return "\126\123"
else
assert(false) -- can't be reached if caller uses a sane regex
end
end
local function SerializeValue(v, res, nres)
-- We use "^" as a value separator, followed by one byte for type indicator
local t=type(v)
if t=="string" then -- ^S = string (escaped to remove nonprints, "^"s, etc)
res[nres+1] = "^S"
res[nres+2] = gsub(v,"[%c \94\126\127]", SerializeStringHelper)
nres=nres+2
elseif t=="number" then -- ^N = number (just tostring()ed) or ^F (float components)
local str = tostring(v)
if tonumber(str)==v --[[not in 4.3 or str==serNaN]] or str==serInf or str==serNegInf then
-- translates just fine, transmit as-is
res[nres+1] = "^N"
res[nres+2] = str
nres=nres+2
else
local m,e = frexp(v)
res[nres+1] = "^F"
res[nres+2] = format("%.0f",m*2^53) -- force mantissa to become integer (it's originally 0.5--0.9999)
res[nres+3] = "^f"
res[nres+4] = tostring(e-53) -- adjust exponent to counteract mantissa manipulation
nres=nres+4
end
elseif t=="table" then -- ^T...^t = table (list of key,value pairs)
nres=nres+1
res[nres] = "^T"
for k,v in pairs(v) do
nres = SerializeValue(k, res, nres)
nres = SerializeValue(v, res, nres)
end
nres=nres+1
res[nres] = "^t"
elseif t=="boolean" then -- ^B = true, ^b = false
nres=nres+1
if v then
res[nres] = "^B" -- true
else
res[nres] = "^b" -- false
end
elseif t=="nil" then -- ^Z = nil (zero, "N" was taken :P)
nres=nres+1
res[nres] = "^Z"
else
error(MAJOR..": Cannot serialize a value of type '"..t.."'") -- can't produce error on right level, this is wildly recursive
end
return nres
end
local serializeTbl = { "^1" } -- "^1" = Hi, I'm data serialized by AceSerializer protocol rev 1
--- Serialize the data passed into the function.
-- Takes a list of values (strings, numbers, booleans, nils, tables)
-- and returns it in serialized form (a string).\\
-- May throw errors on invalid data types.
-- @param ... List of values to serialize
-- @return The data in its serialized form (string)
function AceSerializer:Serialize(...)
local nres = 1
for i=1,select("#", ...) do
local v = select(i, ...)
nres = SerializeValue(v, serializeTbl, nres)
end
serializeTbl[nres+1] = "^^" -- "^^" = End of serialized data
return tconcat(serializeTbl, "", 1, nres+1)
end
-- Deserialization functions
local function DeserializeStringHelper(escape)
if escape<"~\122" then
return strchar(strbyte(escape,2,2)-64)
elseif escape=="~\122" then -- v3 / ticket 115: special case encode since 30+64=94 ("^") - OOPS.
return "\030"
elseif escape=="~\123" then
return "\127"
elseif escape=="~\124" then
return "\126"
elseif escape=="~\125" then
return "\94"
end
error("DeserializeStringHelper got called for '"..escape.."'?!?") -- can't be reached unless regex is screwed up
end
local function DeserializeNumberHelper(number)
--[[ not in 4.3 if number == serNaN then
return 0/0
else]]if number == serNegInf then
return -inf
elseif number == serInf then
return inf
else
return tonumber(number)
end
end
-- DeserializeValue: worker function for :Deserialize()
-- It works in two modes:
-- Main (top-level) mode: Deserialize a list of values and return them all
-- Recursive (table) mode: Deserialize only a single value (_may_ of course be another table with lots of subvalues in it)
--
-- The function _always_ works recursively due to having to build a list of values to return
--
-- Callers are expected to pcall(DeserializeValue) to trap errors
local function DeserializeValue(iter,single,ctl,data)
if not single then
ctl,data = iter()
end
if not ctl then
error("Supplied data misses AceSerializer terminator ('^^')")
end
if ctl=="^^" then
-- ignore extraneous data
return
end
local res
if ctl=="^S" then
res = gsub(data, "~.", DeserializeStringHelper)
elseif ctl=="^N" then
res = DeserializeNumberHelper(data)
if not res then
error("Invalid serialized number: '"..tostring(data).."'")
end
elseif ctl=="^F" then -- ^F<mantissa>^f<exponent>
local ctl2,e = iter()
if ctl2~="^f" then
error("Invalid serialized floating-point number, expected '^f', not '"..tostring(ctl2).."'")
end
local m=tonumber(data)
e=tonumber(e)
if not (m and e) then
error("Invalid serialized floating-point number, expected mantissa and exponent, got '"..tostring(m).."' and '"..tostring(e).."'")
end
res = m*(2^e)
elseif ctl=="^B" then -- yeah yeah ignore data portion
res = true
elseif ctl=="^b" then -- yeah yeah ignore data portion
res = false
elseif ctl=="^Z" then -- yeah yeah ignore data portion
res = nil
elseif ctl=="^T" then
-- ignore ^T's data, future extensibility?
res = {}
local k,v
while true do
ctl,data = iter()
if ctl=="^t" then break end -- ignore ^t's data
k = DeserializeValue(iter,true,ctl,data)
if k==nil then
error("Invalid AceSerializer table format (no table end marker)")
end
ctl,data = iter()
v = DeserializeValue(iter,true,ctl,data)
if v==nil then
error("Invalid AceSerializer table format (no table end marker)")
end
res[k]=v
end
else
error("Invalid AceSerializer control code '"..ctl.."'")
end
if not single then
return res,DeserializeValue(iter)
else
return res
end
end
--- Deserializes the data into its original values.
-- Accepts serialized data, ignoring all control characters and whitespace.
-- @param str The serialized data (from :Serialize)
-- @return true followed by a list of values, OR false followed by an error message
function AceSerializer:Deserialize(str)
str = gsub(str, "[%c ]", "") -- ignore all control characters; nice for embedding in email and stuff
local iter = gmatch(str, "(^.)([^^]*)") -- Any ^x followed by string of non-^
local ctl,data = iter()
if not ctl or ctl~="^1" then
-- we purposefully ignore the data portion of the start code, it can be used as an extension mechanism
return false, "Supplied data is not AceSerializer data (rev 1)"
end
return pcall(DeserializeValue, iter)
end
----------------------------------------
-- Base library stuff
----------------------------------------
AceSerializer.internals = { -- for test scripts
SerializeValue = SerializeValue,
SerializeStringHelper = SerializeStringHelper,
}
local mixins = {
"Serialize",
"Deserialize",
}
AceSerializer.embeds = AceSerializer.embeds or {}
function AceSerializer:Embed(target)
for k, v in pairs(mixins) do
target[v] = self[v]
end
self.embeds[target] = true
return target
end
-- Update embeds
for target, v in pairs(AceSerializer.embeds) do
AceSerializer:Embed(target)
end

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="AceSerializer-3.0.lua"/>
</Ui>

View File

@ -0,0 +1,276 @@
--- **AceTimer-3.0** provides a central facility for registering timers.
-- AceTimer supports one-shot timers and repeating timers. All timers are stored in an efficient
-- data structure that allows easy dispatching and fast rescheduling. Timers can be registered
-- or canceled at any time, even from within a running timer, without conflict or large overhead.\\
-- AceTimer is currently limited to firing timers at a frequency of 0.01s as this is what the WoW timer API
-- restricts us to.
--
-- All `:Schedule` functions will return a handle to the current timer, which you will need to store if you
-- need to cancel the timer you just registered.
--
-- **AceTimer-3.0** can be embeded into your addon, either explicitly by calling AceTimer:Embed(MyAddon) or by
-- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object
-- and can be accessed directly, without having to explicitly call AceTimer itself.\\
-- It is recommended to embed AceTimer, otherwise you'll have to specify a custom `self` on all calls you
-- make into AceTimer.
-- @class file
-- @name AceTimer-3.0
-- @release $Id: AceTimer-3.0.lua 1119 2014-10-14 17:23:29Z nevcairiel $
local MAJOR, MINOR = "AceTimer-3.0", 17 -- Bump minor on changes
local AceTimer, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not AceTimer then return end -- No upgrade needed
AceTimer.activeTimers = AceTimer.activeTimers or {} -- Active timer list
local activeTimers = AceTimer.activeTimers -- Upvalue our private data
-- Lua APIs
local type, unpack, next, error, select = type, unpack, next, error, select
-- WoW APIs
local GetTime, C_TimerAfter = GetTime, C_Timer.After
local function new(self, loop, func, delay, ...)
if delay < 0.01 then
delay = 0.01 -- Restrict to the lowest time that the C_Timer API allows us
end
local timer = {...}
timer.object = self
timer.func = func
timer.looping = loop
timer.argsCount = select("#", ...)
timer.delay = delay
timer.ends = GetTime() + delay
activeTimers[timer] = timer
-- Create new timer closure to wrap the "timer" object
timer.callback = function()
if not timer.cancelled then
if type(timer.func) == "string" then
-- We manually set the unpack count to prevent issues with an arg set that contains nil and ends with nil
-- e.g. local t = {1, 2, nil, 3, nil} print(#t) will result in 2, instead of 5. This fixes said issue.
timer.object[timer.func](timer.object, unpack(timer, 1, timer.argsCount))
else
timer.func(unpack(timer, 1, timer.argsCount))
end
if timer.looping and not timer.cancelled then
-- Compensate delay to get a perfect average delay, even if individual times don't match up perfectly
-- due to fps differences
local time = GetTime()
local delay = timer.delay - (time - timer.ends)
-- Ensure the delay doesn't go below the threshold
if delay < 0.01 then delay = 0.01 end
C_TimerAfter(delay, timer.callback)
timer.ends = time + delay
else
activeTimers[timer.handle or timer] = nil
end
end
end
C_TimerAfter(delay, timer.callback)
return timer
end
--- Schedule a new one-shot timer.
-- The timer will fire once in `delay` seconds, unless canceled before.
-- @param callback Callback function for the timer pulse (funcref or method name).
-- @param delay Delay for the timer, in seconds.
-- @param ... An optional, unlimited amount of arguments to pass to the callback function.
-- @usage
-- MyAddOn = LibStub("AceAddon-3.0"):NewAddon("MyAddOn", "AceTimer-3.0")
--
-- function MyAddOn:OnEnable()
-- self:ScheduleTimer("TimerFeedback", 5)
-- end
--
-- function MyAddOn:TimerFeedback()
-- print("5 seconds passed")
-- end
function AceTimer:ScheduleTimer(func, delay, ...)
if not func or not delay then
error(MAJOR..": ScheduleTimer(callback, delay, args...): 'callback' and 'delay' must have set values.", 2)
end
if type(func) == "string" then
if type(self) ~= "table" then
error(MAJOR..": ScheduleTimer(callback, delay, args...): 'self' - must be a table.", 2)
elseif not self[func] then
error(MAJOR..": ScheduleTimer(callback, delay, args...): Tried to register '"..func.."' as the callback, but it doesn't exist in the module.", 2)
end
end
return new(self, nil, func, delay, ...)
end
--- Schedule a repeating timer.
-- The timer will fire every `delay` seconds, until canceled.
-- @param callback Callback function for the timer pulse (funcref or method name).
-- @param delay Delay for the timer, in seconds.
-- @param ... An optional, unlimited amount of arguments to pass to the callback function.
-- @usage
-- MyAddOn = LibStub("AceAddon-3.0"):NewAddon("MyAddOn", "AceTimer-3.0")
--
-- function MyAddOn:OnEnable()
-- self.timerCount = 0
-- self.testTimer = self:ScheduleRepeatingTimer("TimerFeedback", 5)
-- end
--
-- function MyAddOn:TimerFeedback()
-- self.timerCount = self.timerCount + 1
-- print(("%d seconds passed"):format(5 * self.timerCount))
-- -- run 30 seconds in total
-- if self.timerCount == 6 then
-- self:CancelTimer(self.testTimer)
-- end
-- end
function AceTimer:ScheduleRepeatingTimer(func, delay, ...)
if not func or not delay then
error(MAJOR..": ScheduleRepeatingTimer(callback, delay, args...): 'callback' and 'delay' must have set values.", 2)
end
if type(func) == "string" then
if type(self) ~= "table" then
error(MAJOR..": ScheduleRepeatingTimer(callback, delay, args...): 'self' - must be a table.", 2)
elseif not self[func] then
error(MAJOR..": ScheduleRepeatingTimer(callback, delay, args...): Tried to register '"..func.."' as the callback, but it doesn't exist in the module.", 2)
end
end
return new(self, true, func, delay, ...)
end
--- Cancels a timer with the given id, registered by the same addon object as used for `:ScheduleTimer`
-- Both one-shot and repeating timers can be canceled with this function, as long as the `id` is valid
-- and the timer has not fired yet or was canceled before.
-- @param id The id of the timer, as returned by `:ScheduleTimer` or `:ScheduleRepeatingTimer`
function AceTimer:CancelTimer(id)
local timer = activeTimers[id]
if not timer then
return false
else
timer.cancelled = true
activeTimers[id] = nil
return true
end
end
--- Cancels all timers registered to the current addon object ('self')
function AceTimer:CancelAllTimers()
for k,v in pairs(activeTimers) do
if v.object == self then
AceTimer.CancelTimer(self, k)
end
end
end
--- Returns the time left for a timer with the given id, registered by the current addon object ('self').
-- This function will return 0 when the id is invalid.
-- @param id The id of the timer, as returned by `:ScheduleTimer` or `:ScheduleRepeatingTimer`
-- @return The time left on the timer.
function AceTimer:TimeLeft(id)
local timer = activeTimers[id]
if not timer then
return 0
else
return timer.ends - GetTime()
end
end
-- ---------------------------------------------------------------------
-- Upgrading
-- Upgrade from old hash-bucket based timers to C_Timer.After timers.
if oldminor and oldminor < 10 then
-- disable old timer logic
AceTimer.frame:SetScript("OnUpdate", nil)
AceTimer.frame:SetScript("OnEvent", nil)
AceTimer.frame:UnregisterAllEvents()
-- convert timers
for object,timers in pairs(AceTimer.selfs) do
for handle,timer in pairs(timers) do
if type(timer) == "table" and timer.callback then
local newTimer
if timer.delay then
newTimer = AceTimer.ScheduleRepeatingTimer(timer.object, timer.callback, timer.delay, timer.arg)
else
newTimer = AceTimer.ScheduleTimer(timer.object, timer.callback, timer.when - GetTime(), timer.arg)
end
-- Use the old handle for old timers
activeTimers[newTimer] = nil
activeTimers[handle] = newTimer
newTimer.handle = handle
end
end
end
AceTimer.selfs = nil
AceTimer.hash = nil
AceTimer.debug = nil
elseif oldminor and oldminor < 17 then
-- Upgrade from old animation based timers to C_Timer.After timers.
AceTimer.inactiveTimers = nil
AceTimer.frame = nil
local oldTimers = AceTimer.activeTimers
-- Clear old timer table and update upvalue
AceTimer.activeTimers = {}
activeTimers = AceTimer.activeTimers
for handle, timer in pairs(oldTimers) do
local newTimer
-- Stop the old timer animation
local duration, elapsed = timer:GetDuration(), timer:GetElapsed()
timer:GetParent():Stop()
if timer.looping then
newTimer = AceTimer.ScheduleRepeatingTimer(timer.object, timer.func, duration, unpack(timer.args, 1, timer.argsCount))
else
newTimer = AceTimer.ScheduleTimer(timer.object, timer.func, duration - elapsed, unpack(timer.args, 1, timer.argsCount))
end
-- Use the old handle for old timers
activeTimers[newTimer] = nil
activeTimers[handle] = newTimer
newTimer.handle = handle
end
-- Migrate transitional handles
if oldminor < 13 and AceTimer.hashCompatTable then
for handle, id in pairs(AceTimer.hashCompatTable) do
local t = activeTimers[id]
if t then
activeTimers[id] = nil
activeTimers[handle] = t
t.handle = handle
end
end
AceTimer.hashCompatTable = nil
end
end
-- ---------------------------------------------------------------------
-- Embed handling
AceTimer.embeds = AceTimer.embeds or {}
local mixins = {
"ScheduleTimer", "ScheduleRepeatingTimer",
"CancelTimer", "CancelAllTimers",
"TimeLeft"
}
function AceTimer:Embed(target)
AceTimer.embeds[target] = true
for _,v in pairs(mixins) do
target[v] = AceTimer[v]
end
return target
end
-- AceTimer:OnEmbedDisable(target)
-- target (object) - target object that AceTimer is embedded in.
--
-- cancel all timers registered for the object
function AceTimer:OnEmbedDisable(target)
target:CancelAllTimers()
end
for addon in pairs(AceTimer.embeds) do
AceTimer:Embed(addon)
end

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="AceTimer-3.0.lua"/>
</Ui>

View File

@ -0,0 +1,238 @@
--[[ $Id: CallbackHandler-1.0.lua 1131 2015-06-04 07:29:24Z nevcairiel $ ]]
local MAJOR, MINOR = "CallbackHandler-1.0", 6
local CallbackHandler = LibStub:NewLibrary(MAJOR, MINOR)
if not CallbackHandler then return end -- No upgrade needed
local meta = {__index = function(tbl, key) tbl[key] = {} return tbl[key] end}
-- Lua APIs
local tconcat = table.concat
local assert, error, loadstring = assert, error, loadstring
local setmetatable, rawset, rawget = setmetatable, rawset, rawget
local next, select, pairs, type, tostring = next, select, pairs, type, tostring
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
-- List them here for Mikk's FindGlobals script
-- GLOBALS: geterrorhandler
local xpcall = xpcall
local function errorhandler(err)
return geterrorhandler()(err)
end
local function CreateDispatcher(argCount)
local code = [[
local next, xpcall, eh = ...
local method, ARGS
local function call() method(ARGS) end
local function dispatch(handlers, ...)
local index
index, method = next(handlers)
if not method then return end
local OLD_ARGS = ARGS
ARGS = ...
repeat
xpcall(call, eh)
index, method = next(handlers, index)
until not method
ARGS = OLD_ARGS
end
return dispatch
]]
local ARGS, OLD_ARGS = {}, {}
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, ", "))
return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(next, xpcall, errorhandler)
end
local Dispatchers = setmetatable({}, {__index=function(self, argCount)
local dispatcher = CreateDispatcher(argCount)
rawset(self, argCount, dispatcher)
return dispatcher
end})
--------------------------------------------------------------------------
-- CallbackHandler:New
--
-- target - target object to embed public APIs in
-- RegisterName - name of the callback registration API, default "RegisterCallback"
-- UnregisterName - name of the callback unregistration API, default "UnregisterCallback"
-- UnregisterAllName - name of the API to unregister all callbacks, default "UnregisterAllCallbacks". false == don't publish this API.
function CallbackHandler:New(target, RegisterName, UnregisterName, UnregisterAllName)
RegisterName = RegisterName or "RegisterCallback"
UnregisterName = UnregisterName or "UnregisterCallback"
if UnregisterAllName==nil then -- false is used to indicate "don't want this method"
UnregisterAllName = "UnregisterAllCallbacks"
end
-- we declare all objects and exported APIs inside this closure to quickly gain access
-- to e.g. function names, the "target" parameter, etc
-- Create the registry object
local events = setmetatable({}, meta)
local registry = { recurse=0, events=events }
-- registry:Fire() - fires the given event/message into the registry
function registry:Fire(eventname, ...)
if not rawget(events, eventname) or not next(events[eventname]) then return end
local oldrecurse = registry.recurse
registry.recurse = oldrecurse + 1
Dispatchers[select('#', ...) + 1](events[eventname], eventname, ...)
registry.recurse = oldrecurse
if registry.insertQueue and oldrecurse==0 then
-- Something in one of our callbacks wanted to register more callbacks; they got queued
for eventname,callbacks in pairs(registry.insertQueue) do
local first = not rawget(events, eventname) or not next(events[eventname]) -- test for empty before. not test for one member after. that one member may have been overwritten.
for self,func in pairs(callbacks) do
events[eventname][self] = func
-- fire OnUsed callback?
if first and registry.OnUsed then
registry.OnUsed(registry, target, eventname)
first = nil
end
end
end
registry.insertQueue = nil
end
end
-- Registration of a callback, handles:
-- self["method"], leads to self["method"](self, ...)
-- self with function ref, leads to functionref(...)
-- "addonId" (instead of self) with function ref, leads to functionref(...)
-- all with an optional arg, which, if present, gets passed as first argument (after self if present)
target[RegisterName] = function(self, eventname, method, ... --[[actually just a single arg]])
if type(eventname) ~= "string" then
error("Usage: "..RegisterName.."(eventname, method[, arg]): 'eventname' - string expected.", 2)
end
method = method or eventname
local first = not rawget(events, eventname) or not next(events[eventname]) -- test for empty before. not test for one member after. that one member may have been overwritten.
if type(method) ~= "string" and type(method) ~= "function" then
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): 'methodname' - string or function expected.", 2)
end
local regfunc
if type(method) == "string" then
-- self["method"] calling style
if type(self) ~= "table" then
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): self was not a table?", 2)
elseif self==target then
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): do not use Library:"..RegisterName.."(), use your own 'self'", 2)
elseif type(self[method]) ~= "function" then
error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): 'methodname' - method '"..tostring(method).."' not found on self.", 2)
end
if select("#",...)>=1 then -- this is not the same as testing for arg==nil!
local arg=select(1,...)
regfunc = function(...) self[method](self,arg,...) end
else
regfunc = function(...) self[method](self,...) end
end
else
-- function ref with self=object or self="addonId" or self=thread
if type(self)~="table" and type(self)~="string" and type(self)~="thread" then
error("Usage: "..RegisterName.."(self or \"addonId\", eventname, method): 'self or addonId': table or string or thread expected.", 2)
end
if select("#",...)>=1 then -- this is not the same as testing for arg==nil!
local arg=select(1,...)
regfunc = function(...) method(arg,...) end
else
regfunc = method
end
end
if events[eventname][self] or registry.recurse<1 then
-- if registry.recurse<1 then
-- we're overwriting an existing entry, or not currently recursing. just set it.
events[eventname][self] = regfunc
-- fire OnUsed callback?
if registry.OnUsed and first then
registry.OnUsed(registry, target, eventname)
end
else
-- we're currently processing a callback in this registry, so delay the registration of this new entry!
-- yes, we're a bit wasteful on garbage, but this is a fringe case, so we're picking low implementation overhead over garbage efficiency
registry.insertQueue = registry.insertQueue or setmetatable({},meta)
registry.insertQueue[eventname][self] = regfunc
end
end
-- Unregister a callback
target[UnregisterName] = function(self, eventname)
if not self or self==target then
error("Usage: "..UnregisterName.."(eventname): bad 'self'", 2)
end
if type(eventname) ~= "string" then
error("Usage: "..UnregisterName.."(eventname): 'eventname' - string expected.", 2)
end
if rawget(events, eventname) and events[eventname][self] then
events[eventname][self] = nil
-- Fire OnUnused callback?
if registry.OnUnused and not next(events[eventname]) then
registry.OnUnused(registry, target, eventname)
end
end
if registry.insertQueue and rawget(registry.insertQueue, eventname) and registry.insertQueue[eventname][self] then
registry.insertQueue[eventname][self] = nil
end
end
-- OPTIONAL: Unregister all callbacks for given selfs/addonIds
if UnregisterAllName then
target[UnregisterAllName] = function(...)
if select("#",...)<1 then
error("Usage: "..UnregisterAllName.."([whatFor]): missing 'self' or \"addonId\" to unregister events for.", 2)
end
if select("#",...)==1 and ...==target then
error("Usage: "..UnregisterAllName.."([whatFor]): supply a meaningful 'self' or \"addonId\"", 2)
end
for i=1,select("#",...) do
local self = select(i,...)
if registry.insertQueue then
for eventname, callbacks in pairs(registry.insertQueue) do
if callbacks[self] then
callbacks[self] = nil
end
end
end
for eventname, callbacks in pairs(events) do
if callbacks[self] then
callbacks[self] = nil
-- Fire OnUnused callback?
if registry.OnUnused and not next(callbacks) then
registry.OnUnused(registry, target, eventname)
end
end
end
end
end
end
return registry
end
-- CallbackHandler purposefully does NOT do explicit embedding. Nor does it
-- try to upgrade old implicit embeds since the system is selfcontained and
-- relies on closures to work.

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="CallbackHandler-1.0.lua"/>
</Ui>

View File

@ -0,0 +1,8 @@
<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">
<Include file="UIDropDownMenuTemplates.xml"/>
<script file="UIDropDownMenu.lua"/>
<script file="EasyMenu.lua"/>
</Ui>

View File

@ -0,0 +1,34 @@
-- Simplified Menu Display System
-- This is a basic system for displaying a menu from a structure table.
--
-- See UIDropDownMenu.lua for the menuList details.
--
-- Args:
-- menuList - menu table
-- menuFrame - the UI frame to populate
-- anchor - where to anchor the frame (e.g. CURSOR)
-- x - x offset
-- y - y offset
-- displayMode - border type
-- autoHideDelay - how long until the menu disappears
--
--
function Lib_EasyMenu(menuList, menuFrame, anchor, x, y, displayMode, autoHideDelay )
if ( displayMode == "MENU" ) then
menuFrame.displayMode = displayMode;
end
Lib_UIDropDownMenu_Initialize(menuFrame, Lib_EasyMenu_Initialize, displayMode, nil, menuList);
Lib_ToggleDropDownMenu(1, nil, menuFrame, anchor, x, y, menuList, nil, autoHideDelay);
end
function Lib_EasyMenu_Initialize( frame, level, menuList )
for index = 1, #menuList do
local value = menuList[index]
if (value.text) then
value.index = index;
Lib_UIDropDownMenu_AddButton( value, level );
end
end
end

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,413 @@
<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">
<Button name="Lib_UIDropDownMenuButtonTemplate" virtual="true">
<Size x="100" y="16"/>
<Layers>
<Layer level="BACKGROUND">
<Texture name="$parentHighlight" file="Interface\QuestFrame\UI-QuestTitleHighlight" alphaMode="ADD" setAllPoints="true" hidden="true"/>
</Layer>
<Layer level="ARTWORK">
<Texture name="$parentCheck" file="Interface\Common\UI-DropDownRadioChecks">
<Size x="16" y="16"/>
<Anchors>
<Anchor point="LEFT">
<Offset x="0" y="0"/>
</Anchor>
</Anchors>
<TexCoords left="0" right="0.5" top="0.5" bottom="1.0"/>
</Texture>
<Texture name="$parentUnCheck" file="Interface\Common\UI-DropDownRadioChecks">
<Size x="16" y="16"/>
<Anchors>
<Anchor point="LEFT">
<Offset x="0" y="0"/>
</Anchor>
</Anchors>
<TexCoords left="0.5" right="1.0" top="0.5" bottom="1.0"/>
</Texture>
<Texture name="$parentIcon" hidden="true">
<Size>
<AbsDimension x="16" y="16"/>
</Size>
<Anchors>
<Anchor point="RIGHT">
<Offset x="0" y="0"/>
</Anchor>
</Anchors>
</Texture>
</Layer>
</Layers>
<Frames>
<Button name="$parentColorSwatch" hidden="true">
<Size>
<AbsDimension x="16" y="16"/>
</Size>
<Anchors>
<Anchor point="RIGHT">
<Offset>
<AbsDimension x="-6" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Layers>
<Layer level="BACKGROUND">
<Texture name="$parentSwatchBg">
<Size>
<AbsDimension x="14" y="14"/>
</Size>
<Anchors>
<Anchor point="CENTER">
<Offset>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Color r="1.0" g="1.0" b="1.0"/>
</Texture>
</Layer>
</Layers>
<Scripts>
<OnClick>
CloseMenus();
Lib_UIDropDownMenuButton_OpenColorPicker(self:GetParent());
</OnClick>
<OnEnter>
Lib_CloseDropDownMenus(self:GetParent():GetParent():GetID() + 1);
_G[self:GetName().."SwatchBg"]:SetVertexColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
Lib_UIDropDownMenu_StopCounting(self:GetParent():GetParent());
</OnEnter>
<OnLeave>
_G[self:GetName().."SwatchBg"]:SetVertexColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
Lib_UIDropDownMenu_StartCounting(self:GetParent():GetParent());
</OnLeave>
</Scripts>
<NormalTexture name="$parentNormalTexture" file="Interface\ChatFrame\ChatFrameColorSwatch"/>
</Button>
<Button name="$parentExpandArrow" hidden="true">
<Size>
<AbsDimension x="16" y="16"/>
</Size>
<Anchors>
<Anchor point="RIGHT">
<Offset>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnClick>
Lib_ToggleDropDownMenu(self:GetParent():GetParent():GetID() + 1, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self);
</OnClick>
<OnEnter>
local level = self:GetParent():GetParent():GetID() + 1;
local listFrame = _G["Lib_DropDownList"..level];
if ( not listFrame or not listFrame:IsShown() or select(2, listFrame:GetPoint()) ~= self ) then
Lib_ToggleDropDownMenu(level, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self);
end
Lib_UIDropDownMenu_StopCounting(self:GetParent():GetParent());
</OnEnter>
<OnLeave>
Lib_UIDropDownMenu_StartCounting(self:GetParent():GetParent());
</OnLeave>
</Scripts>
<NormalTexture file="Interface\ChatFrame\ChatFrameExpandArrow"/>
</Button>
<Button name="$parentInvisibleButton" hidden="true" parentKey="invisibleButton">
<Anchors>
<Anchor point="TOPLEFT"/>
<Anchor point="BOTTOMLEFT"/>
<Anchor point="RIGHT" relativeTo="$parentColorSwatch" relativePoint="LEFT">
<Offset>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnEnter>
Lib_UIDropDownMenu_StopCounting(self:GetParent():GetParent());
Lib_CloseDropDownMenus(self:GetParent():GetParent():GetID() + 1);
local parent = self:GetParent();
if ( parent.tooltipTitle and parent.tooltipWhileDisabled) then
if ( parent.tooltipOnButton ) then
GameTooltip:SetOwner(parent, "ANCHOR_RIGHT");
GameTooltip:AddLine(parent.tooltipTitle, 1.0, 1.0, 1.0);
GameTooltip:AddLine(parent.tooltipText, nil, nil, nil, true);
GameTooltip:Show();
else
GameTooltip_AddNewbieTip(parent, parent.tooltipTitle, 1.0, 1.0, 1.0, parent.tooltipText, 1);
end
end
</OnEnter>
<OnLeave>
Lib_UIDropDownMenu_StartCounting(self:GetParent():GetParent());
GameTooltip:Hide();
</OnLeave>
</Scripts>
</Button>
</Frames>
<Scripts>
<OnLoad>
self:SetFrameLevel(self:GetParent():GetFrameLevel()+2);
</OnLoad>
<OnClick>
Lib_UIDropDownMenuButton_OnClick(self, button, down);
</OnClick>
<OnEnter>
if ( self.hasArrow ) then
local level = self:GetParent():GetID() + 1;
local listFrame = _G["Lib_DropDownList"..level];
if ( not listFrame or not listFrame:IsShown() or select(2, listFrame:GetPoint()) ~= self ) then
Lib_ToggleDropDownMenu(self:GetParent():GetID() + 1, self.value, nil, nil, nil, nil, self.menuList, self);
end
else
Lib_CloseDropDownMenus(self:GetParent():GetID() + 1);
end
_G[self:GetName().."Highlight"]:Show();
Lib_UIDropDownMenu_StopCounting(self:GetParent());
if ( self.tooltipTitle ) then
if ( self.tooltipOnButton ) then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip:AddLine(self.tooltipTitle, 1.0, 1.0, 1.0);
GameTooltip:AddLine(self.tooltipText, nil, nil, nil, true);
GameTooltip:Show();
else
GameTooltip_AddNewbieTip(self, self.tooltipTitle, 1.0, 1.0, 1.0, self.tooltipText, 1);
end
end
</OnEnter>
<OnLeave>
_G[self:GetName().."Highlight"]:Hide();
Lib_UIDropDownMenu_StartCounting(self:GetParent());
GameTooltip:Hide();
</OnLeave>
<OnEnable>
self.invisibleButton:Hide();
</OnEnable>
<OnDisable>
self.invisibleButton:Show();
</OnDisable>
</Scripts>
<ButtonText name="$parentNormalText">
<Anchors>
<Anchor point="LEFT">
<Offset x="-5" y="0"/>
</Anchor>
</Anchors>
</ButtonText>
<NormalFont style="GameFontHighlightSmallLeft"/>
<HighlightFont style="GameFontHighlightSmallLeft"/>
<DisabledFont style="GameFontDisableSmallLeft"/>
</Button>
<Button name="Lib_UIDropDownListTemplate" hidden="true" frameStrata="DIALOG" enableMouse="true" virtual="true">
<Frames>
<Frame name="$parentBackdrop" setAllPoints="true">
<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background-Dark" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
<BackgroundInsets>
<AbsInset left="11" right="12" top="12" bottom="9"/>
</BackgroundInsets>
<TileSize>
<AbsValue val="32"/>
</TileSize>
<EdgeSize>
<AbsValue val="32"/>
</EdgeSize>
</Backdrop>
</Frame>
<Frame name="$parentMenuBackdrop" setAllPoints="true">
<Backdrop bgFile="Interface\Tooltips\UI-Tooltip-Background" edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true">
<EdgeSize>
<AbsValue val="16"/>
</EdgeSize>
<TileSize>
<AbsValue val="16"/>
</TileSize>
<BackgroundInsets>
<AbsInset left="5" right="5" top="5" bottom="4"/>
</BackgroundInsets>
</Backdrop>
<Scripts>
<OnLoad>
self:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b);
self:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b);
</OnLoad>
</Scripts>
</Frame>
<Button name="$parentButton1" inherits="Lib_UIDropDownMenuButtonTemplate" id="1"/>
<Button name="$parentButton2" inherits="Lib_UIDropDownMenuButtonTemplate" id="2"/>
<Button name="$parentButton3" inherits="Lib_UIDropDownMenuButtonTemplate" id="3"/>
<Button name="$parentButton4" inherits="Lib_UIDropDownMenuButtonTemplate" id="4"/>
<Button name="$parentButton5" inherits="Lib_UIDropDownMenuButtonTemplate" id="5"/>
<Button name="$parentButton6" inherits="Lib_UIDropDownMenuButtonTemplate" id="6"/>
<Button name="$parentButton7" inherits="Lib_UIDropDownMenuButtonTemplate" id="7"/>
<Button name="$parentButton8" inherits="Lib_UIDropDownMenuButtonTemplate" id="8"/>
</Frames>
<Scripts>
<OnClick>
self:Hide();
</OnClick>
<OnEnter>
Lib_UIDropDownMenu_StopCounting(self, motion);
</OnEnter>
<OnLeave>
Lib_UIDropDownMenu_StartCounting(self, motion);
</OnLeave>
<OnUpdate>
Lib_UIDropDownMenu_OnUpdate(self, elapsed);
</OnUpdate>
<OnShow>
for i=1, LIB_UIDROPDOWNMENU_MAXBUTTONS do
if (not self.noResize) then
_G[self:GetName().."Button"..i]:SetWidth(self.maxWidth);
end
end
if (not self.noResize) then
self:SetWidth(self.maxWidth+25);
end
self.showTimer = nil;
if ( self:GetID() > 1 ) then
self.parent = _G["Lib_DropDownList"..(self:GetID() - 1)];
end
</OnShow>
<OnHide>
Lib_UIDropDownMenu_OnHide(self);
</OnHide>
</Scripts>
</Button>
<Frame name="Lib_UIDropDownMenuTemplate" virtual="true">
<Size>
<AbsDimension x="40" y="32"/>
</Size>
<Layers>
<Layer level="ARTWORK">
<Texture name="$parentLeft" file="Interface\Glues\CharacterCreate\CharacterCreate-LabelFrame">
<Size>
<AbsDimension x="25" y="64"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT">
<Offset>
<AbsDimension x="0" y="17"/>
</Offset>
</Anchor>
</Anchors>
<TexCoords left="0" right="0.1953125" top="0" bottom="1"/>
</Texture>
<Texture name="$parentMiddle" file="Interface\Glues\CharacterCreate\CharacterCreate-LabelFrame">
<Size>
<AbsDimension x="115" y="64"/>
</Size>
<Anchors>
<Anchor point="LEFT" relativeTo="$parentLeft" relativePoint="RIGHT"/>
</Anchors>
<TexCoords left="0.1953125" right="0.8046875" top="0" bottom="1"/>
</Texture>
<Texture name="$parentRight" file="Interface\Glues\CharacterCreate\CharacterCreate-LabelFrame">
<Size>
<AbsDimension x="25" y="64"/>
</Size>
<Anchors>
<Anchor point="LEFT" relativeTo="$parentMiddle" relativePoint="RIGHT"/>
</Anchors>
<TexCoords left="0.8046875" right="1" top="0" bottom="1"/>
</Texture>
<FontString parentKey="Text" name="$parentText" inherits="GameFontHighlightSmall" wordwrap="false" justifyH="RIGHT">
<Size>
<AbsDimension x="0" y="10"/>
</Size>
<Anchors>
<Anchor point="RIGHT" relativeTo="$parentRight">
<Offset>
<AbsDimension x="-43" y="2"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
</Layer>
<Layer level="OVERLAY">
<Texture parentKey="Icon" name="$parentIcon" hidden="true">
<Size>
<AbsDimension x="16" y="16"/>
</Size>
<Anchors>
<Anchor point="LEFT">
<Offset x="30" y="2"/>
</Anchor>
</Anchors>
</Texture>
</Layer>
</Layers>
<Frames>
<Button parentKey="Button" name="$parentButton" motionScriptsWhileDisabled="true" >
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="TOPRIGHT" relativeTo="$parentRight">
<Offset>
<AbsDimension x="-16" y="-18"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnEnter>
local parent = self:GetParent();
local myscript = parent:GetScript("OnEnter");
if(myscript ~= nil) then
myscript(parent);
end
</OnEnter>
<OnLeave>
local parent = self:GetParent();
local myscript = parent:GetScript("OnLeave");
if(myscript ~= nil) then
myscript(parent);
end
</OnLeave>
<OnClick>
Lib_ToggleDropDownMenu(nil, nil, self:GetParent());
PlaySound("igMainMenuOptionCheckBoxOn");
</OnClick>
</Scripts>
<NormalTexture name="$parentNormalTexture" file="Interface\ChatFrame\UI-ChatIcon-ScrollDown-Up">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="RIGHT"/>
</Anchors>
</NormalTexture>
<PushedTexture name="$parentPushedTexture" file="Interface\ChatFrame\UI-ChatIcon-ScrollDown-Down">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="RIGHT"/>
</Anchors>
</PushedTexture>
<DisabledTexture name="$parentDisabledTexture" file="Interface\ChatFrame\UI-ChatIcon-ScrollDown-Disabled">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="RIGHT"/>
</Anchors>
</DisabledTexture>
<HighlightTexture name="$parentHighlightTexture" file="Interface\Buttons\UI-Common-MouseHilight" alphaMode="ADD">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="RIGHT"/>
</Anchors>
</HighlightTexture>
</Button>
</Frames>
<Scripts>
<OnHide>
Lib_CloseDropDownMenus();
</OnHide>
</Scripts>
</Frame>
</Ui>

View File

@ -0,0 +1,71 @@
Standard UIDropDownMenu global functions using protected frames and causing taints when used by third-party addons. But it is possible to avoid taints by using same functionality with that library.
== What is it ==
Library is standard code from Blizzard's files EasyMenu.lua, UIDropDownMenu.lua and UIDropDownMenuTemplates.xml with frames, tables, variables and functions renamed to:
* constants (typed with all CAPS): "LIB_" added at the start
* functions: "Lib_" added at the start
== Constants ==
* LIB_UIDROPDOWNMENU_MINBUTTONS
* LIB_UIDROPDOWNMENU_MAXBUTTONS
* LIB_UIDROPDOWNMENU_MAXLEVELS
* LIB_UIDROPDOWNMENU_BUTTON_HEIGHT
* LIB_UIDROPDOWNMENU_BORDER_HEIGHT
* LIB_UIDROPDOWNMENU_OPEN_MENU
* LIB_UIDROPDOWNMENU_INIT_MENU
* LIB_UIDROPDOWNMENU_MENU_LEVEL
* LIB_UIDROPDOWNMENU_MENU_VALUE
* LIB_UIDROPDOWNMENU_SHOW_TIME
* LIB_UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT
* LIB_OPEN_DROPDOWNMENUS
== Functions ==
* Lib_EasyMenu
* Lib_EasyMenu_Initialize
* Lib_UIDropDownMenuDelegate_OnAttributeChanged
* Lib_UIDropDownMenu_InitializeHelper
* Lib_UIDropDownMenu_Initialize
* Lib_UIDropDownMenu_OnUpdate
* Lib_UIDropDownMenu_StartCounting
* Lib_UIDropDownMenu_StopCounting
* Lib_UIDropDownMenu_CreateInfo
* Lib_UIDropDownMenu_CreateFrames
* Lib_UIDropDownMenu_AddButton
* Lib_UIDropDownMenu_Refresh
* Lib_UIDropDownMenu_RefreshAll
* Lib_UIDropDownMenu_SetIconImage
* Lib_UIDropDownMenu_SetSelectedName
* Lib_UIDropDownMenu_SetSelectedValue
* Lib_UIDropDownMenu_SetSelectedID
* Lib_UIDropDownMenu_GetSelectedName
* Lib_UIDropDownMenu_GetSelectedID
* Lib_UIDropDownMenu_GetSelectedValue
* Lib_UIDropDownMenuButton_OnClick
* Lib_HideDropDownMenu
* Lib_ToggleDropDownMenu
* Lib_CloseDropDownMenus
* Lib_UIDropDownMenu_OnHide
* Lib_UIDropDownMenu_SetWidth
* Lib_UIDropDownMenu_SetButtonWidth
* Lib_UIDropDownMenu_SetText
* Lib_UIDropDownMenu_GetText
* Lib_UIDropDownMenu_ClearAll
* Lib_UIDropDownMenu_JustifyText
* Lib_UIDropDownMenu_SetAnchor
* Lib_UIDropDownMenu_GetCurrentDropDown
* Lib_UIDropDownMenuButton_GetChecked
* Lib_UIDropDownMenuButton_GetName
* Lib_UIDropDownMenuButton_OpenColorPicker
* Lib_UIDropDownMenu_DisableButton
* Lib_UIDropDownMenu_EnableButton
* Lib_UIDropDownMenu_SetButtonText
* Lib_UIDropDownMenu_DisableDropDown
* Lib_UIDropDownMenu_EnableDropDown
* Lib_UIDropDownMenu_IsEnabled
* Lib_UIDropDownMenu_GetValue
== How to use it ==
* Add it to your toc.
* Like ordinal code for UIDropDownMenu with "Lib_" instead.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,5 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="LibButtonGlow-1.0\LibButtonGlow-1.0.lua"/>
<Script file="LibActionButton-1.0.lua"/>
</Ui>

View File

@ -0,0 +1,244 @@
--[[
Copyright (c) 2015, Hendrik "nevcairiel" Leppkes <h.leppkes@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the developer nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]]
local MAJOR_VERSION = "LibButtonGlow-1.0"
local MINOR_VERSION = 6
if not LibStub then error(MAJOR_VERSION .. " requires LibStub.") end
local lib, oldversion = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
if not lib then return end
local Masque = LibStub("Masque", true)
lib.unusedOverlays = lib.unusedOverlays or {}
lib.numOverlays = lib.numOverlays or 0
local tinsert, tremove, tostring = table.insert, table.remove, tostring
local function OverlayGlowAnimOutFinished(animGroup)
local overlay = animGroup:GetParent()
local frame = overlay:GetParent()
overlay:Hide()
tinsert(lib.unusedOverlays, overlay)
frame.__LBGoverlay = nil
end
local function OverlayGlow_OnHide(self)
if self.animOut:IsPlaying() then
self.animOut:Stop()
OverlayGlowAnimOutFinished(self.animOut)
end
end
local function CreateScaleAnim(group, target, order, duration, x, y, delay)
local scale = group:CreateAnimation("Scale")
scale:SetTarget(target:GetName())
scale:SetOrder(order)
scale:SetDuration(duration)
scale:SetScale(x, y)
if delay then
scale:SetStartDelay(delay)
end
end
local function CreateAlphaAnim(group, target, order, duration, fromAlpha, toAlpha, delay)
local alpha = group:CreateAnimation("Alpha")
alpha:SetTarget(target:GetName())
alpha:SetOrder(order)
alpha:SetDuration(duration)
alpha:SetFromAlpha(fromAlpha)
alpha:SetToAlpha(toAlpha)
if delay then
alpha:SetStartDelay(delay)
end
end
local function AnimIn_OnPlay(group)
local frame = group:GetParent()
local frameWidth, frameHeight = frame:GetSize()
frame.spark:SetSize(frameWidth, frameHeight)
frame.spark:SetAlpha(0.3)
frame.innerGlow:SetSize(frameWidth / 2, frameHeight / 2)
frame.innerGlow:SetAlpha(1.0)
frame.innerGlowOver:SetAlpha(1.0)
frame.outerGlow:SetSize(frameWidth * 2, frameHeight * 2)
frame.outerGlow:SetAlpha(1.0)
frame.outerGlowOver:SetAlpha(1.0)
frame.ants:SetSize(frameWidth * 0.85, frameHeight * 0.85)
frame.ants:SetAlpha(0)
frame:Show()
end
local function AnimIn_OnFinished(group)
local frame = group:GetParent()
local frameWidth, frameHeight = frame:GetSize()
frame.spark:SetAlpha(0)
frame.innerGlow:SetAlpha(0)
frame.innerGlow:SetSize(frameWidth, frameHeight)
frame.innerGlowOver:SetAlpha(0.0)
frame.outerGlow:SetSize(frameWidth, frameHeight)
frame.outerGlowOver:SetAlpha(0.0)
frame.outerGlowOver:SetSize(frameWidth, frameHeight)
frame.ants:SetAlpha(1.0)
end
local function CreateOverlayGlow()
lib.numOverlays = lib.numOverlays + 1
-- create frame and textures
local name = "ButtonGlowOverlay" .. tostring(lib.numOverlays)
local overlay = CreateFrame("Frame", name, UIParent)
-- spark
overlay.spark = overlay:CreateTexture(name .. "Spark", "BACKGROUND")
overlay.spark:SetPoint("CENTER")
overlay.spark:SetAlpha(0)
overlay.spark:SetTexture([[Interface\SpellActivationOverlay\IconAlert]])
overlay.spark:SetTexCoord(0.00781250, 0.61718750, 0.00390625, 0.26953125)
-- inner glow
overlay.innerGlow = overlay:CreateTexture(name .. "InnerGlow", "ARTWORK")
overlay.innerGlow:SetPoint("CENTER")
overlay.innerGlow:SetAlpha(0)
overlay.innerGlow:SetTexture([[Interface\SpellActivationOverlay\IconAlert]])
overlay.innerGlow:SetTexCoord(0.00781250, 0.50781250, 0.27734375, 0.52734375)
-- inner glow over
overlay.innerGlowOver = overlay:CreateTexture(name .. "InnerGlowOver", "ARTWORK")
overlay.innerGlowOver:SetPoint("TOPLEFT", overlay.innerGlow, "TOPLEFT")
overlay.innerGlowOver:SetPoint("BOTTOMRIGHT", overlay.innerGlow, "BOTTOMRIGHT")
overlay.innerGlowOver:SetAlpha(0)
overlay.innerGlowOver:SetTexture([[Interface\SpellActivationOverlay\IconAlert]])
overlay.innerGlowOver:SetTexCoord(0.00781250, 0.50781250, 0.53515625, 0.78515625)
-- outer glow
overlay.outerGlow = overlay:CreateTexture(name .. "OuterGlow", "ARTWORK")
overlay.outerGlow:SetPoint("CENTER")
overlay.outerGlow:SetAlpha(0)
overlay.outerGlow:SetTexture([[Interface\SpellActivationOverlay\IconAlert]])
overlay.outerGlow:SetTexCoord(0.00781250, 0.50781250, 0.27734375, 0.52734375)
-- outer glow over
overlay.outerGlowOver = overlay:CreateTexture(name .. "OuterGlowOver", "ARTWORK")
overlay.outerGlowOver:SetPoint("TOPLEFT", overlay.outerGlow, "TOPLEFT")
overlay.outerGlowOver:SetPoint("BOTTOMRIGHT", overlay.outerGlow, "BOTTOMRIGHT")
overlay.outerGlowOver:SetAlpha(0)
overlay.outerGlowOver:SetTexture([[Interface\SpellActivationOverlay\IconAlert]])
overlay.outerGlowOver:SetTexCoord(0.00781250, 0.50781250, 0.53515625, 0.78515625)
-- ants
overlay.ants = overlay:CreateTexture(name .. "Ants", "OVERLAY")
overlay.ants:SetPoint("CENTER")
overlay.ants:SetAlpha(0)
overlay.ants:SetTexture([[Interface\SpellActivationOverlay\IconAlertAnts]])
-- setup antimations
overlay.animIn = overlay:CreateAnimationGroup()
CreateScaleAnim(overlay.animIn, overlay.spark, 1, 0.2, 1.5, 1.5)
CreateAlphaAnim(overlay.animIn, overlay.spark, 1, 0.2, 0, 1)
CreateScaleAnim(overlay.animIn, overlay.innerGlow, 1, 0.3, 2, 2)
CreateScaleAnim(overlay.animIn, overlay.innerGlowOver, 1, 0.3, 2, 2)
CreateAlphaAnim(overlay.animIn, overlay.innerGlowOver, 1, 0.3, 1, 0)
CreateScaleAnim(overlay.animIn, overlay.outerGlow, 1, 0.3, 0.5, 0.5)
CreateScaleAnim(overlay.animIn, overlay.outerGlowOver, 1, 0.3, 0.5, 0.5)
CreateAlphaAnim(overlay.animIn, overlay.outerGlowOver, 1, 0.3, 1, 0)
CreateScaleAnim(overlay.animIn, overlay.spark, 1, 0.2, 2/3, 2/3, 0.2)
CreateAlphaAnim(overlay.animIn, overlay.spark, 1, 0.2, 1, 0, 0.2)
CreateAlphaAnim(overlay.animIn, overlay.innerGlow, 1, 0.2, 1, 0, 0.3)
CreateAlphaAnim(overlay.animIn, overlay.ants, 1, 0.2, 0, 1, 0.3)
overlay.animIn:SetScript("OnPlay", AnimIn_OnPlay)
overlay.animIn:SetScript("OnFinished", AnimIn_OnFinished)
overlay.animOut = overlay:CreateAnimationGroup()
CreateAlphaAnim(overlay.animOut, overlay.outerGlowOver, 1, 0.2, 0, 1)
CreateAlphaAnim(overlay.animOut, overlay.ants, 1, 0.2, 1, 0)
CreateAlphaAnim(overlay.animOut, overlay.outerGlowOver, 2, 0.2, 1, 0)
CreateAlphaAnim(overlay.animOut, overlay.outerGlow, 2, 0.2, 1, 0)
overlay.animOut:SetScript("OnFinished", OverlayGlowAnimOutFinished)
-- scripts
overlay:SetScript("OnUpdate", ActionButton_OverlayGlowOnUpdate)
overlay:SetScript("OnHide", OverlayGlow_OnHide)
overlay.__LBGVersion = MINOR_VERSION
return overlay
end
local function GetOverlayGlow()
local overlay = tremove(lib.unusedOverlays)
if not overlay then
overlay = CreateOverlayGlow()
end
return overlay
end
function lib.ShowOverlayGlow(frame)
if frame.__LBGoverlay then
if frame.__LBGoverlay.animOut:IsPlaying() then
frame.__LBGoverlay.animOut:Stop()
frame.__LBGoverlay.animIn:Play()
end
else
local overlay = GetOverlayGlow()
local frameWidth, frameHeight = frame:GetSize()
overlay:SetParent(frame)
overlay:SetFrameLevel(frame:GetFrameLevel() + 5)
overlay:ClearAllPoints()
--Make the height/width available before the next frame:
overlay:SetSize(frameWidth * 1.4, frameHeight * 1.4)
overlay:SetPoint("TOPLEFT", frame, "TOPLEFT", -frameWidth * 0.2, frameHeight * 0.2)
overlay:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", frameWidth * 0.2, -frameHeight * 0.2)
overlay.animIn:Play()
frame.__LBGoverlay = overlay
if Masque and Masque.UpdateSpellAlert and (not frame.overlay or not issecurevariable(frame, "overlay")) then
local old_overlay = frame.overlay
frame.overlay = overlay
Masque:UpdateSpellAlert(frame)
frame.overlay = old_overlay
end
end
end
function lib.HideOverlayGlow(frame)
if frame.__LBGoverlay then
if frame.__LBGoverlay.animIn:IsPlaying() then
frame.__LBGoverlay.animIn:Stop()
end
if frame:IsVisible() then
frame.__LBGoverlay.animOut:Play()
else
OverlayGlowAnimOutFinished(frame.__LBGoverlay.animOut)
end
end
end

View File

@ -0,0 +1,817 @@
-- LibAnim by Hydra
local Version = 2.01
if (_LibAnim and _LibAnim >= Version) then
return
end
local cos = cos
local sin = sin
local pairs = pairs
local floor = floor
local tinsert = tinsert
local tremove = tremove
local strlower = strlower
local Updater = CreateFrame("StatusBar")
local Texture = Updater:CreateTexture()
local Text = Updater:CreateFontString()
local AnimTypes = {}
local UpdateFuncs = {}
local Callbacks = {["onplay"] = {}, ["onpause"] = {}, ["onresume"] = {}, ["onstop"] = {}, ["onreset"] = {}, ["onfinished"] = {}}
-- Update all current animations
local AnimationOnUpdate = function(self, elapsed)
for i = 1, #self do
if self[i] then -- Double check the the index still exists, due to pauses/stops removing them on the fly
self[i]:Update(elapsed, i)
end
end
if (#self == 0) then
self:SetScript("OnUpdate", nil)
end
end
local StartUpdating = function(anim)
tinsert(Updater, anim)
if (not Updater:GetScript("OnUpdate")) then
Updater:SetScript("OnUpdate", AnimationOnUpdate)
end
end
local GetColor = function(p, r1, g1, b1, r2, g2, b2)
return r1 + (r2 - r1) * p, g1 + (g2 - g1) * p, b1 + (b2 - b1) * p
end
local Set = {
["backdrop"] = Updater.SetBackdropColor,
["border"] = Updater.SetBackdropBorderColor,
["statusbar"] = Updater.SetStatusBarColor,
["text"] = Text.SetTextColor,
["texture"] = Texture.SetTexture,
["vertex"] = Texture.SetVertexColor,
}
local Get = {
["backdrop"] = Updater.GetBackdropColor,
["border"] = Updater.GetBackdropBorderColor,
["statusbar"] = Updater.GetStatusBarColor,
["text"] = Text.GetTextColor,
["texture"] = Texture.GetVertexColor,
["vertex"] = Texture.GetVertexColor,
}
local Smoothing = {
["none"] = function(t, b, c, d)
return c * t / d + b
end,
["in"] = function(t, b, c, d)
t = t / d
return c * t * t + b
end,
["out"] = function(t, b, c, d)
t = t / d
return -c * t * (t - 2) + b
end,
["inout"] = function(t, b, c, d)
t = t / (d / 2)
if (t < 1) then
return c / 2 * t * t + b
end
t = t - 1
return -c / 2 * (t * (t - 2) - 1) + b
end,
["bounce"] = function(t, b, c, d)
t = t / d
if (t < (1 / 2.75)) then
return c * (7.5625 * t * t) + b
elseif (t < (2 / 2.75)) then
t = t - (1.5 / 2.75)
return c * (7.5625 * t * t + 0.75) + b
elseif (t < (2.5 / 2.75)) then
t = t - (2.25 / 2.75)
return c * (7.5625 * t * t + 0.9375) + b
else
t = t - (2.625 / 2.75)
return c * (7.5625 * (t) * t + 0.984375) + b
end
end,
["elastic"] = function(t, b, c, d)
local s, p, a = 1.70158, d * .3, c;
if t == 0 then
return b
end
t = t / d
if t == 1 then
return b + c
end
if a < math.abs(c) then
a = c
s = p / 4
else
s = p / (2 * math.pi) * math.asin(c / a)
end
return a * math.pow(2, -10 * t) * math.sin((t * d - s) * (2 * math.pi) / p) + c + b
end
}
local AnimMethods = {
All = {
Play = function(self)
if (not self.Paused) then
AnimTypes[self.Type](self)
self:Callback("OnPlay")
else
StartUpdating(self)
self:Callback("OnResume")
end
self.Playing = true
self.Paused = false
self.Stopped = false
end,
IsPlaying = function(self)
return self.Playing
end,
Pause = function(self)
for i = 1, #Updater do
if (Updater[i] == self) then
tremove(Updater, i)
break
end
end
self.Playing = false
self.Paused = true
self.Stopped = false
self:Callback("OnPause")
end,
IsPaused = function(self)
return self.Paused
end,
Stop = function(self, reset)
for i = 1, #Updater do
if (Updater[i] == self) then
tremove(Updater, i)
break
end
end
self.Playing = false
self.Paused = false
self.Stopped = true
if reset then
self:Reset()
self:Callback("OnReset")
else
self:Callback("OnStop")
end
end,
IsStopped = function(self)
return self.Stopped
end,
SetSmoothing = function(self, smoothType)
smoothType = strlower(smoothType)
self.Smoothing = Smoothing[smoothType] and smoothType or "none"
end,
GetSmoothing = function(self)
return self.Smoothing
end,
SetDuration = function(self, duration)
self.Duration = duration or 0
end,
GetDuration = function(self)
return self.Duration
end,
GetProgressByTimer = function(self)
return self.Timer
end,
SetOrder = function(self, order)
self.Order = order or 1
if (order > self.Group.MaxOrder) then
self.Group.MaxOrder = order
end
end,
GetOrder = function(self)
return self.Order
end,
GetParent = function(self)
return self.Parent
end,
SetScript = function(self, handler, func)
handler = strlower(handler)
if (not Callbacks[handler]) then
return
end
Callbacks[handler][self] = func
end,
GetScript = function(self, handler)
handler = strlower(handler)
if (Callbacks[handler] and Callbacks[handler][self]) then
return Callbacks[handler][self]
end
end,
Callback = function(self, handler)
handler = strlower(handler)
if Callbacks[handler][self] then
Callbacks[handler][self](self)
end
end,
},
move = {
SetOffset = function(self, x, y)
self.XSetting = x or 0
self.YSetting = y or 0
end,
GetOffset = function(self)
return self.XSetting, self.YSetting
end,
SetRounded = function(self, flag)
self.IsRounded = flag
end,
GetRounded = function(self)
return self.IsRounded
end,
GetProgress = function(self)
return self.XOffset, self.YOffset
end,
Reset = function(self)
self.Parent:ClearAllPoints()
self.Parent:SetPoint(self.A1, self.P, self.A2, self.StartX, self.StartY)
end,
},
fade = {
SetChange = function(self, alpha)
self.EndAlphaSetting = alpha or 0
end,
GetChange = function(self)
return self.EndAlphaSetting
end,
GetProgress = function(self)
return self.AlphaOffset
end,
Reset = function(self)
self.Parent:SetAlpha(self.StartAlpha)
end,
},
height = {
SetChange = function(self, height)
self.EndHeightSetting = height or 0
end,
GetChange = function(self)
return self.EndHeightSetting
end,
GetProgress = function(self)
return self.HeightOffset
end,
Reset = function(self)
self.Parent:SetHeight(self.StartHeight)
end,
},
width = {
SetChange = function(self, width)
self.EndWidthSetting = width or 0
end,
GetChange = function(self)
return self.EndWidthSetting
end,
GetProgress = function(self)
return self.WidthOffset
end,
Reset = function(self)
self.Parent:SetWidth(self.StartWidth)
end,
},
color = {
SetChange = function(self, r, g, b)
self.EndRSetting = r or 1
self.EndGSetting = g or 1
self.EndBSetting = b or 1
end,
GetChange = function(self)
return self.EndRSetting, self.EndGSetting, self.EndBSetting
end,
SetColorType = function(self, type)
type = strlower(type)
self.ColorType = Set[type] and type or "border"
end,
GetColorType = function(self)
return self.ColorType
end,
GetProgress = function(self)
return self.ColorOffset
end,
Reset = function(self)
Set[self.ColorType](self.Parent, self.StartR, self.StartG, self.StartB)
end,
},
progress = {
SetChange = function(self, value)
self.EndValueSetting = value or 0
end,
GetChange = function(self)
return self.EndValueSetting
end,
GetProgress = function(self)
return self.ValueOffset
end,
Reset = function(self)
self.Parent:SetValue(self.StartValue)
end,
},
number = {
SetChange = function(self, value)
self.EndNumberSetting = value or 0
end,
GetChange = function(self)
return self.EndNumberSetting
end,
SetPrefix = function(self, text)
self.Prefix = text or ""
end,
GetPrefix = function(self)
return self.Prefix
end,
SetPostfix = function(self, text)
self.Postfix = text or ""
end,
GetPostfix = function(self)
return self.Postfix
end,
GetProgress = function(self)
return self.NumberOffset
end,
Reset = function(self)
self.Parent:SetText(self.StartNumer)
end,
},
}
local GroupMethods = {
Play = function(self)
-- Play!
for i = 1, #self.Animations do
if (self.Animations[i].Order == self.Order) then
self.Animations[i]:Play()
end
end
self.Playing = true
self.Paused = false
self.Stopped = false
end,
IsPlaying = function(self)
return self.Playing
end,
Pause = function(self)
-- Only pause current order
for i = 1, #self.Animations do
if (self.Animations[i].Order == self.Order) then
self.Animations[i]:Pause()
end
end
self.Playing = false
self.Paused = true
self.Stopped = false
end,
IsPaused = function(self)
return self.Paused
end,
Stop = function(self)
for i = 1, #self.Animations do
self.Animations[i]:Stop()
end
self.Playing = false
self.Paused = false
self.Stopped = true
end,
IsStopped = function(self)
return self.Stopped
end,
SetLooping = function(self, shouldLoop)
self.Looping = shouldLoop
end,
GetLooping = function(self)
return self.Looping
end,
GetParent = function(self)
return self.Parent
end,
CheckOrder = function(self)
-- Check if we're done all animations at the current order, then proceed to the next order.
local NumAtOrder = 0
local NumDoneAtOrder = 0
for i = 1, #self.Animations do
if (self.Animations[i].Order == self.Order) then
NumAtOrder = NumAtOrder + 1
if (not self.Animations[i].Playing) then
NumDoneAtOrder = NumDoneAtOrder + 1
end
end
end
-- All the animations at x order finished, go to next order
if (NumAtOrder == NumDoneAtOrder) then
self.Order = self.Order + 1
-- We exceeded max order, reset to 1 and bail the function, or restart if we're looping
if (self.Order > self.MaxOrder) then
self.Order = 1
if (self.Stopped or not self.Looping) then
self.Playing = false
return
end
end
-- Play!
for i = 1, #self.Animations do
if (self.Animations[i].Order == self.Order) then
self.Animations[i]:Play()
end
end
end
end,
CreateAnimation = function(self, type)
type = strlower(type)
if (not AnimTypes[type]) then
return
end
local Animation = {}
-- General methods
for key, func in pairs(AnimMethods.All) do
Animation[key] = func
end
-- Animation specific methods
if AnimMethods[type] then
for key, func in pairs(AnimMethods[type]) do
Animation[key] = func
end
end
-- Set some attributes and defaults
Animation.Paused = false
Animation.Playing = false
Animation.Stopped = false
Animation.Looping = false
Animation.Type = type
Animation.Group = self
Animation.Parent = self.Parent
Animation.Order = 1
Animation.Duration = 0.3
Animation.Smoothing = "none"
Animation.Update = UpdateFuncs[type]
tinsert(self.Animations, Animation)
return Animation
end,
}
CreateAnimationGroup = function(parent)
local Group = {Animations = {}}
-- Add methods to the group
for key, func in pairs(GroupMethods) do
Group[key] = func
end
Group.Parent = parent
Group.Playing = false
Group.Paused = false
Group.Stopped = false
Group.Order = 1
Group.MaxOrder = 1
return Group
end
-- Movement
UpdateFuncs["move"] = function(self, elapsed, i)
self.Timer = self.Timer + elapsed
if self.IsRounded then
self.ModTimer = Smoothing[self.Smoothing](self.Timer, 0, self.Duration, self.Duration)
self.XOffset = self.StartX - (-1) * (self.XChange * (1 - cos(90 * self.ModTimer / self.Duration)))
self.YOffset = self.StartY + self.YChange * sin(90 * self.ModTimer / self.Duration)
else
self.XOffset = Smoothing[self.Smoothing](self.Timer, self.StartX, self.XChange, self.Duration)
self.YOffset = Smoothing[self.Smoothing](self.Timer, self.StartY, self.YChange, self.Duration)
end
self.Parent:SetPoint(self.A1, self.P, self.A2, (self.EndX ~= 0 and self.XOffset or self.StartX), (self.EndY ~= 0 and self.YOffset or self.StartY))
if (self.Timer >= self.Duration) then
tremove(Updater, i)
self.Parent:SetPoint(self.A1, self.P, self.A2, self.EndX, self.EndY)
self.Playing = false
self:Callback("OnFinished")
self.Group:CheckOrder()
end
end
AnimTypes["move"] = function(self)
if self:IsPlaying() then
return
end
local A1, P, A2, X, Y = self.Parent:GetPoint()
self.Timer = 0
self.A1 = A1
self.P = P
self.A2 = A2
self.StartX = X
self.EndX = X + self.XSetting or 0
self.StartY = Y
self.EndY = Y + self.YSetting or 0
self.XChange = self.EndX - self.StartX
self.YChange = self.EndY - self.StartY
if self.IsRounded then
if (self.XChange == 0 or self.YChange == 0) then -- Double check if we're valid to be rounded
self.IsRounded = false
else
self.ModTimer = 0
end
end
StartUpdating(self)
end
-- Fade
UpdateFuncs["fade"] = function(self, elapsed, i)
self.Timer = self.Timer + elapsed
self.AlphaOffset = Smoothing[self.Smoothing](self.Timer, self.StartAlpha, self.Change, self.Duration)
self.Parent:SetAlpha(self.AlphaOffset)
if (self.Timer >= self.Duration) then
tremove(Updater, i)
self.Parent:SetAlpha(self.EndAlpha)
self.Playing = false
self:Callback("OnFinished")
self.Group:CheckOrder()
end
end
AnimTypes["fade"] = function(self)
if self:IsPlaying() then
return
end
self.Timer = 0
self.StartAlpha = self.Parent:GetAlpha() or 1
self.EndAlpha = self.EndAlphaSetting or 0
self.Change = self.EndAlpha - self.StartAlpha
StartUpdating(self)
end
-- Height
UpdateFuncs["height"] = function(self, elapsed, i)
self.Timer = self.Timer + elapsed
self.HeightOffset = Smoothing[self.Smoothing](self.Timer, self.StartHeight, self.HeightChange, self.Duration)
self.Parent:SetHeight(self.HeightOffset)
if (self.Timer >= self.Duration) then
tremove(Updater, i)
self.Parent:SetHeight(self.EndHeight)
self.Playing = false
self:Callback("OnFinished")
self.Group:CheckOrder()
end
end
AnimTypes["height"] = function(self)
if self:IsPlaying() then
return
end
self.Timer = 0
self.StartHeight = self.Parent:GetHeight() or 0
self.EndHeight = self.EndHeightSetting or 0
self.HeightChange = self.EndHeight - self.StartHeight
StartUpdating(self)
end
-- Width
UpdateFuncs["width"] = function(self, elapsed, i)
self.Timer = self.Timer + elapsed
self.WidthOffset = Smoothing[self.Smoothing](self.Timer, self.StartWidth, self.WidthChange, self.Duration)
self.Parent:SetWidth(self.WidthOffset)
if (self.Timer >= self.Duration) then
tremove(Updater, i)
self.Parent:SetWidth(self.EndWidth)
self.Playing = false
self:Callback("OnFinished")
self.Group:CheckOrder()
end
end
AnimTypes["width"] = function(self)
if self:IsPlaying() then
return
end
self.Timer = 0
self.StartWidth = self.Parent:GetWidth() or 0
self.EndWidth = self.EndWidthSetting or 0
self.WidthChange = self.EndWidth - self.StartWidth
StartUpdating(self)
end
-- Color
UpdateFuncs["color"] = function(self, elapsed, i)
self.Timer = self.Timer + elapsed
self.ColorOffset = Smoothing[self.Smoothing](self.Timer, 0, self.Duration, self.Duration)
Set[self.ColorType](self.Parent, GetColor(self.Timer / self.Duration, self.StartR, self.StartG, self.StartB, self.EndR, self.EndG, self.EndB))
if (self.Timer >= self.Duration) then
tremove(Updater, i)
Set[self.ColorType](self.Parent, self.EndR, self.EndG, self.EndB)
self.Playing = false
self:Callback("OnFinished")
self.Group:CheckOrder()
end
end
AnimTypes["color"] = function(self)
self.Timer = 0
self.ColorType = self.ColorType or "backdrop"
self.StartR, self.StartG, self.StartB = Get[self.ColorType](self.Parent)
self.EndR = self.EndRSetting or 1
self.EndG = self.EndGSetting or 1
self.EndB = self.EndBSetting or 1
StartUpdating(self)
end
-- Progress
UpdateFuncs["progress"] = function(self, elapsed, i)
self.Timer = self.Timer + elapsed
self.ValueOffset = Smoothing[self.Smoothing](self.Timer, self.StartValue, self.ProgressChange, self.Duration)
self.Parent:SetValue(self.ValueOffset)
if (self.Timer >= self.Duration) then
tremove(Updater, i)
self.Parent:SetValue(self.EndValue)
self.Playing = false
self:Callback("OnFinished")
self.Group:CheckOrder()
end
end
AnimTypes["progress"] = function(self)
self.Timer = 0
self.StartValue = self.Parent:GetValue() or 0
self.EndValue = self.EndValueSetting or 0
self.ProgressChange = self.EndValue - self.StartValue
StartUpdating(self)
end
-- Sleep
UpdateFuncs["sleep"] = function(self, elapsed, i)
self.Timer = self.Timer + elapsed
if (self.Timer >= self.Duration) then
tremove(Updater, i)
self.Playing = false
self:Callback("OnFinished")
self.Group:CheckOrder()
end
end
AnimTypes["sleep"] = function(self)
self.Timer = 0
StartUpdating(self)
end
-- Number
UpdateFuncs["number"] = function(self, elapsed, i)
self.Timer = self.Timer + elapsed
self.NumberOffset = Smoothing[self.Smoothing](self.Timer, self.StartNumber, self.NumberChange, self.Duration)
self.Parent:SetText(self.Prefix..floor(self.NumberOffset)..self.Postfix)
if (self.Timer >= self.Duration) then
tremove(Updater, i)
self.Parent:SetText(self.Prefix..floor(self.EndNumber)..self.Postfix)
self.Playing = false
self:Callback("OnFinished")
self.Group:CheckOrder()
end
end
AnimTypes["number"] = function(self)
self.Timer = 0
self.StartNumber = tonumber(self.Parent:GetText()) or 0
self.EndNumber = self.EndNumberSetting or 0
self.NumberChange = self.EndNumberSetting - self.StartNumber
self.Prefix = self.Prefix or ""
self.Postfix = self.Postfix or ""
StartUpdating(self)
end
_G["_LibAnim"] = Version

View File

@ -0,0 +1,7 @@
## Interface: 60200
## Author: Hydra
## Version: 2.01
## Title: LibAnim
## Notes: Animations!
LibAnim.lua

View File

@ -0,0 +1,212 @@
--[[
Name: LibBase64-1.0
Author(s): ckknight (ckknight@gmail.com)
Website: http://www.wowace.com/projects/libbase64-1-0/
Description: A library to encode and decode Base64 strings
License: MIT
]]
local LibBase64 = LibStub:NewLibrary("LibBase64-1.0-ElvUI", 1)
if not LibBase64 then
return
end
local _chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
local byteToNum = {}
local numToChar = {}
for i = 1, #_chars do
numToChar[i - 1] = _chars:sub(i, i)
byteToNum[_chars:byte(i)] = i - 1
end
_chars = nil
local A_byte = ("A"):byte()
local Z_byte = ("Z"):byte()
local a_byte = ("a"):byte()
local z_byte = ("z"):byte()
local zero_byte = ("0"):byte()
local nine_byte = ("9"):byte()
local plus_byte = ("+"):byte()
local slash_byte = ("/"):byte()
local equals_byte = ("="):byte()
local whitespace = {
[(" "):byte()] = true,
[("\t"):byte()] = true,
[("\n"):byte()] = true,
[("\r"):byte()] = true,
}
local t = {}
--- Encode a normal bytestring into a Base64-encoded string
-- @param text a bytestring, can be binary data
-- @param maxLineLength This should be a multiple of 4, greater than 0 or nil. If non-nil, it will break up the output into lines no longer than the given number of characters. 76 is recommended.
-- @param lineEnding a string to end each line with. This is "\r\n" by default.
-- @usage LibBase64.Encode("Hello, how are you doing today?") == "SGVsbG8sIGhvdyBhcmUgeW91IGRvaW5nIHRvZGF5Pw=="
-- @return a Base64-encoded string
function LibBase64:Encode(text, maxLineLength, lineEnding)
if type(text) ~= "string" then
error(("Bad argument #1 to `Encode'. Expected %q, got %q"):format("string", type(text)), 2)
end
if maxLineLength == nil then
-- do nothing
elseif type(maxLineLength) ~= "number" then
error(("Bad argument #2 to `Encode'. Expected %q or %q, got %q"):format("number", "nil", type(maxLineLength)), 2)
elseif (maxLineLength % 4) ~= 0 then
error(("Bad argument #2 to `Encode'. Expected a multiple of 4, got %s"):format(maxLineLength), 2)
elseif maxLineLength <= 0 then
error(("Bad argument #2 to `Encode'. Expected a number > 0, got %s"):format(maxLineLength), 2)
end
if lineEnding == nil then
lineEnding = "\r\n"
elseif type(lineEnding) ~= "string" then
error(("Bad argument #3 to `Encode'. Expected %q, got %q"):format("string", type(lineEnding)), 2)
end
local currentLength = 0
for i = 1, #text, 3 do
local a, b, c = text:byte(i, i+2)
local nilNum = 0
if not b then
nilNum = 2
b = 0
c = 0
elseif not c then
nilNum = 1
c = 0
end
local num = a * 2^16 + b * 2^8 + c
local d = num % 2^6
num = (num - d) / 2^6
local c = num % 2^6
num = (num - c) / 2^6
local b = num % 2^6
num = (num - b) / 2^6
local a = num % 2^6
t[#t+1] = numToChar[a]
t[#t+1] = numToChar[b]
t[#t+1] = (nilNum >= 2) and "=" or numToChar[c]
t[#t+1] = (nilNum >= 1) and "=" or numToChar[d]
currentLength = currentLength + 4
if maxLineLength and (currentLength % maxLineLength) == 0 then
t[#t+1] = lineEnding
end
end
local s = table.concat(t)
for i = 1, #t do
t[i] = nil
end
return s
end
local t2 = {}
--- Decode a Base64-encoded string into a bytestring
-- this will raise an error if the data passed in is not a Base64-encoded string
-- this will ignore whitespace, but not invalid characters
-- @param text a Base64-encoded string
-- @usage LibBase64.Encode("SGVsbG8sIGhvdyBhcmUgeW91IGRvaW5nIHRvZGF5Pw==") == "Hello, how are you doing today?"
-- @return a bytestring
function LibBase64:Decode(text)
if type(text) ~= "string" then
error(("Bad argument #1 to `Decode'. Expected %q, got %q"):format("string", type(text)), 2)
end
for i = 1, #text do
local byte = text:byte(i)
if whitespace[byte] or byte == equals_byte then
-- do nothing
else
local num = byteToNum[byte]
if not num then
for i = 1, #t2 do
t2[k] = nil
end
error(("Bad argument #1 to `Decode'. Received an invalid char: %q"):format(text:sub(i, i)), 2)
end
t2[#t2+1] = num
end
end
for i = 1, #t2, 4 do
local a, b, c, d = t2[i], t2[i+1], t2[i+2], t2[i+3]
local nilNum = 0
if not c then
nilNum = 2
c = 0
d = 0
elseif not d then
nilNum = 1
d = 0
end
local num = a * 2^18 + b * 2^12 + c * 2^6 + d
local c = num % 2^8
num = (num - c) / 2^8
local b = num % 2^8
num = (num - b) / 2^8
local a = num % 2^8
t[#t+1] = string.char(a)
if nilNum < 2 then
t[#t+1] = string.char(b)
end
if nilNum < 1 then
t[#t+1] = string.char(c)
end
end
for i = 1, #t2 do
t2[i] = nil
end
local s = table.concat(t)
for i = 1, #t do
t[i] = nil
end
return s
end
function LibBase64:IsBase64(text)
if type(text) ~= "string" then
error(("Bad argument #1 to `IsBase64'. Expected %q, got %q"):format("string", type(text)), 2)
end
if #text % 4 ~= 0 then
return false
end
for i = 1, #text do
local byte = text:byte(i)
if whitespace[byte] or byte == equals_byte then
-- do nothing
else
local num = byteToNum[byte]
if not num then
return false
end
end
end
return true
end

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="LibBase64-1.0.lua" />
</Ui>

View File

@ -0,0 +1,199 @@
local MAJOR, MINOR = "LibChatAnims", 2 -- Bump minor on changes
local LCA = LibStub:NewLibrary(MAJOR, MINOR)
if not LCA then return end -- No upgrade needed
LCA.animations = LCA.animations or {} -- Animation storage
local anims = LCA.animations
----------------------------------------------------
-- Note, most of this code is simply replicated from
-- Blizzard's FloatingChatFrame.lua file.
-- The only real changes are the creation and use
-- of animations vs the use of UIFrameFlash.
--
FCFDockOverflowButton_UpdatePulseState = function(self)
local dock = self:GetParent()
local shouldPulse = false
for _, chatFrame in pairs(FCFDock_GetChatFrames(dock)) do
local chatTab = _G[chatFrame:GetName().."Tab"]
if ( not chatFrame.isStaticDocked and chatTab.alerting) then
-- Make sure the rects are valid. (Not always the case when resizing the WoW client
if ( not chatTab:GetRight() or not dock.scrollFrame:GetRight() ) then
return false
end
-- Check if it's off the screen.
local DELTA = 3 -- Chosen through experimentation
if ( chatTab:GetRight() < (dock.scrollFrame:GetLeft() + DELTA) or chatTab:GetLeft() > (dock.scrollFrame:GetRight() - DELTA) ) then
shouldPulse = true
break
end
end
end
local tex = self:GetHighlightTexture()
if shouldPulse then
if not anims[tex] then
anims[tex] = tex:CreateAnimationGroup()
local fade1 = anims[tex]:CreateAnimation("Alpha")
fade1:SetDuration(1)
fade1:SetFromAlpha(0)
fade1:SetToAlpha(1)
fade1:SetOrder(1)
local fade2 = anims[tex]:CreateAnimation("Alpha")
fade2:SetDuration(1)
fade2:SetFromAlpha(1)
fade2:SetToAlpha(0)
fade2:SetOrder(2)
end
tex:Show()
tex:SetAlpha(0)
anims[tex]:SetLooping("REPEAT")
anims[tex]:Play()
self:LockHighlight()
self.alerting = true
else
if anims[tex] then
anims[tex]:Stop()
end
self:UnlockHighlight()
tex:SetAlpha(1)
tex:Show()
self.alerting = false
end
if self.list:IsShown() then
FCFDockOverflowList_Update(self.list, dock)
end
return true
end
FCFDockOverflowListButton_SetValue = function(button, chatFrame)
local chatTab = _G[chatFrame:GetName().."Tab"]
button.chatFrame = chatFrame
button:SetText(chatFrame.name)
local colorTable = chatTab.selectedColorTable or DEFAULT_TAB_SELECTED_COLOR_TABLE
if chatTab.selectedColorTable then
button:GetFontString():SetTextColor(colorTable.r, colorTable.g, colorTable.b)
else
button:GetFontString():SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
end
button.glow:SetVertexColor(colorTable.r, colorTable.g, colorTable.b)
if chatTab.conversationIcon then
button.conversationIcon:SetVertexColor(colorTable.r, colorTable.g, colorTable.b)
button.conversationIcon:Show()
else
button.conversationIcon:Hide()
end
if chatTab.alerting then
button.alerting = true
if not anims[button.glow] then
anims[button.glow] = button.glow:CreateAnimationGroup()
local fade1 = anims[button.glow]:CreateAnimation("Alpha")
fade1:SetDuration(1)
fade1:SetFromAlpha(0)
fade1:SetToAlpha(1)
fade1:SetOrder(1)
local fade2 = anims[button.glow]:CreateAnimation("Alpha")
fade2:SetDuration(1)
fade2:SetFromAlpha(1)
fade2:SetToAlpha(0)
fade2:SetOrder(2)
end
button.glow:Show()
button.glow:SetAlpha(0)
anims[button.glow]:SetLooping("REPEAT")
anims[button.glow]:Play()
else
button.alerting = false
if anims[button.glow] then
anims[button.glow]:Stop()
end
button.glow:Hide()
end
button:Show()
end
FCF_StartAlertFlash = function(chatFrame)
local chatTab = _G[chatFrame:GetName().."Tab"]
if chatFrame.minFrame then
if not anims[chatFrame.minFrame] then
anims[chatFrame.minFrame] = chatFrame.minFrame.glow:CreateAnimationGroup()
local fade1 = anims[chatFrame.minFrame]:CreateAnimation("Alpha")
fade1:SetDuration(1)
fade1:SetFromAlpha(0)
fade1:SetToAlpha(1)
fade1:SetOrder(1)
local fade2 = anims[chatFrame.minFrame]:CreateAnimation("Alpha")
fade2:SetDuration(1)
fade2:SetFromAlpha(1)
fade2:SetToAlpha(0)
fade2:SetOrder(2)
end
chatFrame.minFrame.glow:Show()
chatFrame.minFrame.glow:SetAlpha(0)
anims[chatFrame.minFrame]:SetLooping("REPEAT")
anims[chatFrame.minFrame]:Play()
chatFrame.minFrame.alerting = true
end
if not anims[chatTab.glow] then
anims[chatTab.glow] = chatTab.glow:CreateAnimationGroup()
local fade1 = anims[chatTab.glow]:CreateAnimation("Alpha")
fade1:SetDuration(1)
fade1:SetFromAlpha(0)
fade1:SetToAlpha(1)
fade1:SetOrder(1)
local fade2 = anims[chatTab.glow]:CreateAnimation("Alpha")
fade2:SetDuration(1)
fade2:SetFromAlpha(1)
fade2:SetToAlpha(0)
fade2:SetOrder(2)
end
chatTab.glow:Show()
chatTab.glow:SetAlpha(0)
anims[chatTab.glow]:SetLooping("REPEAT")
anims[chatTab.glow]:Play()
chatTab.alerting = true
FCFTab_UpdateAlpha(chatFrame)
FCFDockOverflowButton_UpdatePulseState(GENERAL_CHAT_DOCK.overflowButton)
end
FCF_StopAlertFlash = function(chatFrame)
local chatTab = _G[chatFrame:GetName().."Tab"]
if chatFrame.minFrame then
if anims[chatFrame.minFrame] then
anims[chatFrame.minFrame]:Stop()
end
chatFrame.minFrame.glow:Hide()
chatFrame.minFrame.alerting = false
end
if anims[chatTab.glow] then
anims[chatTab.glow]:Stop()
end
chatTab.glow:Hide()
chatTab.alerting = false
FCFTab_UpdateAlpha(chatFrame)
FCFDockOverflowButton_UpdatePulseState(GENERAL_CHAT_DOCK.overflowButton)
end

View File

@ -0,0 +1,7 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<script file="LibChatAnims.lua"/>
</Ui>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="LibCompress.lua" />
</Ui>

View File

@ -0,0 +1,90 @@
assert(LibStub, "LibDataBroker-1.1 requires LibStub")
assert(LibStub:GetLibrary("CallbackHandler-1.0", true), "LibDataBroker-1.1 requires CallbackHandler-1.0")
local lib, oldminor = LibStub:NewLibrary("LibDataBroker-1.1", 4)
if not lib then return end
oldminor = oldminor or 0
lib.callbacks = lib.callbacks or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
lib.attributestorage, lib.namestorage, lib.proxystorage = lib.attributestorage or {}, lib.namestorage or {}, lib.proxystorage or {}
local attributestorage, namestorage, callbacks = lib.attributestorage, lib.namestorage, lib.callbacks
if oldminor < 2 then
lib.domt = {
__metatable = "access denied",
__index = function(self, key) return attributestorage[self] and attributestorage[self][key] end,
}
end
if oldminor < 3 then
lib.domt.__newindex = function(self, key, value)
if not attributestorage[self] then attributestorage[self] = {} end
if attributestorage[self][key] == value then return end
attributestorage[self][key] = value
local name = namestorage[self]
if not name then return end
callbacks:Fire("LibDataBroker_AttributeChanged", name, key, value, self)
callbacks:Fire("LibDataBroker_AttributeChanged_"..name, name, key, value, self)
callbacks:Fire("LibDataBroker_AttributeChanged_"..name.."_"..key, name, key, value, self)
callbacks:Fire("LibDataBroker_AttributeChanged__"..key, name, key, value, self)
end
end
if oldminor < 2 then
function lib:NewDataObject(name, dataobj)
if self.proxystorage[name] then return end
if dataobj then
assert(type(dataobj) == "table", "Invalid dataobj, must be nil or a table")
self.attributestorage[dataobj] = {}
for i,v in pairs(dataobj) do
self.attributestorage[dataobj][i] = v
dataobj[i] = nil
end
end
dataobj = setmetatable(dataobj or {}, self.domt)
self.proxystorage[name], self.namestorage[dataobj] = dataobj, name
self.callbacks:Fire("LibDataBroker_DataObjectCreated", name, dataobj)
return dataobj
end
end
if oldminor < 1 then
function lib:DataObjectIterator()
return pairs(self.proxystorage)
end
function lib:GetDataObjectByName(dataobjectname)
return self.proxystorage[dataobjectname]
end
function lib:GetNameByDataObject(dataobject)
return self.namestorage[dataobject]
end
end
if oldminor < 4 then
local next = pairs(attributestorage)
function lib:pairs(dataobject_or_name)
local t = type(dataobject_or_name)
assert(t == "string" or t == "table", "Usage: ldb:pairs('dataobjectname') or ldb:pairs(dataobject)")
local dataobj = self.proxystorage[dataobject_or_name] or dataobject_or_name
assert(attributestorage[dataobj], "Data object not found")
return next, attributestorage[dataobj], nil
end
local ipairs_iter = ipairs(attributestorage)
function lib:ipairs(dataobject_or_name)
local t = type(dataobject_or_name)
assert(t == "string" or t == "table", "Usage: ldb:ipairs('dataobjectname') or ldb:ipairs(dataobject)")
local dataobj = self.proxystorage[dataobject_or_name] or dataobject_or_name
assert(attributestorage[dataobj], "Data object not found")
return ipairs_iter, attributestorage[dataobj], 0
end
end

View File

@ -0,0 +1,437 @@
--[[
LibDualSpec-1.0 - Adds dual spec support to individual AceDB-3.0 databases
Copyright (C) 2009-2012 Adirelle
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Redistribution of a stand alone version is strictly prohibited without
prior written authorization from the LibDualSpec project manager.
* Neither the name of the LibDualSpec authors nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--]]
local MAJOR, MINOR = "LibDualSpec-1.0", 17
assert(LibStub, MAJOR.." requires LibStub")
local lib, minor = LibStub:NewLibrary(MAJOR, MINOR)
if not lib then return end
-- ----------------------------------------------------------------------------
-- Library data
-- ----------------------------------------------------------------------------
lib.eventFrame = lib.eventFrame or CreateFrame("Frame")
lib.registry = lib.registry or {}
lib.options = lib.options or {}
lib.mixin = lib.mixin or {}
lib.upgrades = lib.upgrades or {}
lib.currentSpec = lib.currentSpec or 0
if minor and minor < 15 then
lib.talentsLoaded, lib.talentGroup = nil, nil
lib.specLoaded, lib.specGroup = nil, nil
lib.eventFrame:UnregisterAllEvents()
wipe(lib.options)
end
-- ----------------------------------------------------------------------------
-- Locals
-- ----------------------------------------------------------------------------
local registry = lib.registry
local options = lib.options
local mixin = lib.mixin
local upgrades = lib.upgrades
-- "Externals"
local AceDB3 = LibStub('AceDB-3.0', true)
local AceDBOptions3 = LibStub('AceDBOptions-3.0', true)
local AceConfigRegistry3 = LibStub('AceConfigRegistry-3.0', true)
-- classId specialization functions don't require player data to be loaded
local _, _, classId = UnitClass("player")
local numSpecs = GetNumSpecializationsForClassID(classId)
-- ----------------------------------------------------------------------------
-- Localization
-- ----------------------------------------------------------------------------
local L_ENABLED = "Enable spec profiles"
local L_ENABLED_DESC = "When enabled, your profile will be set to the specified profile when you change specialization."
local L_CURRENT = "%s (Current)" -- maybe something like >> %s << and/or coloring to avoid localization?
do
local locale = GetLocale()
if locale == "frFR" then
-- L_ENABLED = "Enable spec profiles"
-- L_ENABLED_DESC = "When enabled, your profile will be set to the specified profile when you change specialization."
-- L_CURRENT = "%s (Current)"
elseif locale == "deDE" then
L_ENABLED = "Spezialisierungsprofile aktivieren"
L_ENABLED_DESC = "Falls diese Option aktiviert ist, wird dein Profil auf das angegebene Profil gesetzt, wenn du die Spezialisierung wechselst."
L_CURRENT = "%s (Momentan)"
elseif locale == "koKR" then
-- L_ENABLED = "Enable spec profiles"
-- L_ENABLED_DESC = "When enabled, your profile will be set to the specified profile when you change specialization."
-- L_CURRENT = "%s (Current)"
elseif locale == "ruRU" then
L_ENABLED = "Включить профили специализации"
L_ENABLED_DESC = "Если включено, ваш профиль будет зависеть от выбранной специализации."
L_CURRENT = "%s (Текущий)"
elseif locale == "zhCN" then
L_ENABLED = "启用专精配置文件"
L_ENABLED_DESC = "当启用后,当切换专精时配置文件将设置为专精配置文件。"
L_CURRENT = "%s当前"
elseif locale == "zhTW" then
L_ENABLED = "啟用專精設定檔"
L_ENABLED_DESC = "當啟用後,當你切換專精時設定檔會設定為專精設定檔。"
L_CURRENT = "%s (目前) "
elseif locale == "esES" or locale == "esMX" then
-- L_ENABLED = "Enable spec profiles"
-- L_ENABLED_DESC = "When enabled, your profile will be set to the specified profile when you change specialization."
-- L_CURRENT = "%s (Current)"
elseif locale == "ptBR" then
-- L_ENABLED = "Enable spec profiles"
-- L_ENABLED_DESC = "When enabled, your profile will be set to the specified profile when you change specialization."
-- L_CURRENT = "%s (Current)"
elseif locale == "itIT" then
-- L_ENABLED = "Enable spec profiles"
-- L_ENABLED_DESC = "When enabled, your profile will be set to the specified profile when you change specialization."
-- L_CURRENT = "%s (Current)"
end
end
-- ----------------------------------------------------------------------------
-- Mixin
-- ----------------------------------------------------------------------------
--- Get dual spec feature status.
-- @return (boolean) true is dual spec feature enabled.
-- @name enhancedDB:IsDualSpecEnabled
function mixin:IsDualSpecEnabled()
return registry[self].db.char.enabled
end
--- Enable/disabled dual spec feature.
-- @param enabled (boolean) true to enable dual spec feature, false to disable it.
-- @name enhancedDB:SetDualSpecEnabled
function mixin:SetDualSpecEnabled(enabled)
local db = registry[self].db.char
db.enabled = not not enabled
local currentProfile = self:GetCurrentProfile()
for i = 1, numSpecs do
-- nil out entries on disable, set nil entries to the current profile on enable
db[i] = enabled and (db[i] or currentProfile) or nil
end
self:CheckDualSpecState()
end
--- Get the profile assigned to a specialization.
-- Defaults to the current profile.
-- @param spec (number) the specialization index.
-- @return (string) the profile name.
-- @name enhancedDB:GetDualSpecProfile
function mixin:GetDualSpecProfile(spec)
return registry[self].db.char[spec or lib.currentSpec] or self:GetCurrentProfile()
end
--- Set the profile assigned to a specialization.
-- No validation are done to ensure the profile is valid.
-- @param profileName (string) the profile name to use.
-- @param spec (number) the specialization index.
-- @name enhancedDB:SetDualSpecProfile
function mixin:SetDualSpecProfile(profileName, spec)
spec = spec or lib.currentSpec
if spec < 1 or spec > numSpecs then return end
registry[self].db.char[spec] = profileName
self:CheckDualSpecState()
end
--- Check if a profile swap should occur.
-- There is normally no reason to call this method directly as LibDualSpec
-- takes care of calling it at the appropriate time.
-- @name enhancedDB:CheckDualSpecState
function mixin:CheckDualSpecState()
if not registry[self].db.char.enabled then return end
if lib.currentSpec == 0 then return end
local profileName = self:GetDualSpecProfile()
if profileName ~= self:GetCurrentProfile() then
self:SetProfile(profileName)
end
end
-- ----------------------------------------------------------------------------
-- AceDB-3.0 support
-- ----------------------------------------------------------------------------
local function EmbedMixin(target)
for k,v in next, mixin do
rawset(target, k, v)
end
end
-- Upgrade settings from current/alternate system.
-- This sets the current profile as the profile for your current spec and your
-- swapped profile as the profile for the rest of your specs.
local function UpgradeDatabase(target)
if lib.currentSpec == 0 then
upgrades[target] = true
return
end
local db = target:GetNamespace(MAJOR, true)
if db and db.char.profile then
for i = 1, numSpecs do
if i == lib.currentSpec then
db.char[i] = target:GetCurrentProfile()
else
db.char[i] = db.char.profile
end
end
db.char.profile = nil
db.char.specGroup = nil
end
end
-- Reset a spec profile to the current one if its profile is deleted.
function lib:OnProfileDeleted(event, target, profileName)
local db = registry[target].db.char
if not db.enabled then return end
for i = 1, numSpecs do
if db[i] == profileName then
db[i] = target:GetCurrentProfile()
end
end
end
-- Actually enhance the database
-- This is used on first initialization and everytime the database is reset using :ResetDB
function lib:_EnhanceDatabase(event, target)
registry[target].db = target:GetNamespace(MAJOR, true) or target:RegisterNamespace(MAJOR)
EmbedMixin(target)
target:CheckDualSpecState()
end
--- Embed dual spec feature into an existing AceDB-3.0 database.
-- LibDualSpec specific methods are added to the instance.
-- @name LibDualSpec:EnhanceDatabase
-- @param target (table) the AceDB-3.0 instance.
-- @param name (string) a user-friendly name of the database (best bet is the addon name).
function lib:EnhanceDatabase(target, name)
AceDB3 = AceDB3 or LibStub('AceDB-3.0', true)
if type(target) ~= "table" then
error("Usage: LibDualSpec:EnhanceDatabase(target, name): target should be a table.", 2)
elseif type(name) ~= "string" then
error("Usage: LibDualSpec:EnhanceDatabase(target, name): name should be a string.", 2)
elseif not AceDB3 or not AceDB3.db_registry[target] then
error("Usage: LibDualSpec:EnhanceDatabase(target, name): target should be an AceDB-3.0 database.", 2)
elseif target.parent then
error("Usage: LibDualSpec:EnhanceDatabase(target, name): cannot enhance a namespace.", 2)
elseif registry[target] then
return
end
registry[target] = { name = name }
UpgradeDatabase(target)
lib:_EnhanceDatabase("EnhanceDatabase", target)
target.RegisterCallback(lib, "OnDatabaseReset", "_EnhanceDatabase")
target.RegisterCallback(lib, "OnProfileDeleted")
end
-- ----------------------------------------------------------------------------
-- AceDBOptions-3.0 support
-- ----------------------------------------------------------------------------
local function NoDualSpec()
return UnitLevel("player") < 11
end
options.new = {
name = "New",
type = "input",
order = 30,
get = false,
set = function(info, value)
local db = info.handler.db
if db:IsDualSpecEnabled() then
db:SetDualSpecProfile(value, lib.currentSpec)
else
db:SetProfile(value)
end
end,
}
options.choose = {
name = "Existing Profiles",
type = "select",
order = 40,
get = "GetCurrentProfile",
set = "SetProfile",
values = "ListProfiles",
arg = "common",
disabled = function(info)
return info.handler.db:IsDualSpecEnabled()
end
}
options.enabled = {
name = "|cffffd200"..L_ENABLED.."|r",
desc = L_ENABLED_DESC,
descStyle = "inline",
type = "toggle",
order = 41,
width = "full",
get = function(info) return info.handler.db:IsDualSpecEnabled() end,
set = function(info, value) info.handler.db:SetDualSpecEnabled(value) end,
hidden = NoDualSpec,
}
for i = 1, numSpecs do
local _, specName = GetSpecializationInfoForClassID(classId, i)
options["specProfile" .. i] = {
type = "select",
name = function() return lib.currentSpec == i and L_CURRENT:format(specName) or specName end,
order = 42 + i,
get = function(info) return info.handler.db:GetDualSpecProfile(i) end,
set = function(info, value) info.handler.db:SetDualSpecProfile(value, i) end,
values = "ListProfiles",
arg = "common",
disabled = function(info) return not info.handler.db:IsDualSpecEnabled() end,
hidden = NoDualSpec,
}
end
--- Embed dual spec options into an existing AceDBOptions-3.0 option table.
-- @name LibDualSpec:EnhanceOptions
-- @param optionTable (table) The option table returned by AceDBOptions-3.0.
-- @param target (table) The AceDB-3.0 the options operate on.
function lib:EnhanceOptions(optionTable, target)
AceDBOptions3 = AceDBOptions3 or LibStub('AceDBOptions-3.0', true)
AceConfigRegistry3 = AceConfigRegistry3 or LibStub('AceConfigRegistry-3.0', true)
if type(optionTable) ~= "table" then
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): optionTable should be a table.", 2)
elseif type(target) ~= "table" then
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): target should be a table.", 2)
elseif not AceDBOptions3 or not AceDBOptions3.optionTables[target] then
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): optionTable is not an AceDBOptions-3.0 table.", 2)
elseif optionTable.handler.db ~= target then
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): optionTable must be the option table of target.", 2)
elseif not registry[target] then
error("Usage: LibDualSpec:EnhanceOptions(optionTable, target): EnhanceDatabase should be called before EnhanceOptions(optionTable, target).", 2)
end
-- localize our replacements
options.new.name = optionTable.args.new.name
options.new.desc = optionTable.args.new.desc
options.choose.name = optionTable.args.choose.name
options.choose.desc = optionTable.args.choose.desc
-- add our new options
if not optionTable.plugins then
optionTable.plugins = {}
end
optionTable.plugins[MAJOR] = options
end
-- ----------------------------------------------------------------------------
-- Upgrade existing
-- ----------------------------------------------------------------------------
for target in next, registry do
UpgradeDatabase(target)
EmbedMixin(target)
target:CheckDualSpecState()
local optionTable = AceDBOptions3 and AceDBOptions3.optionTables[target]
if optionTable then
lib:EnhanceOptions(optionTable, target)
end
end
-- ----------------------------------------------------------------------------
-- Inspection
-- ----------------------------------------------------------------------------
local function iterator(registry, key)
local data
key, data = next(registry, key)
if key then
return key, data.name
end
end
--- Iterate through enhanced AceDB3.0 instances.
-- The iterator returns (instance, name) pairs where instance and name are the
-- arguments that were provided to lib:EnhanceDatabase.
-- @name LibDualSpec:IterateDatabases
-- @return Values to be used in a for .. in .. do statement.
function lib:IterateDatabases()
return iterator, lib.registry
end
-- ----------------------------------------------------------------------------
-- Switching logic
-- ----------------------------------------------------------------------------
local function eventHandler(self, event)
lib.currentSpec = GetSpecialization() or 0
if event == "PLAYER_LOGIN" then
self:UnregisterEvent(event)
self:RegisterUnitEvent("PLAYER_SPECIALIZATION_CHANGED", "player")
end
if lib.currentSpec > 0 and next(upgrades) then
for target in next, upgrades do
UpgradeDatabase(target)
end
wipe(upgrades)
end
for target in next, registry do
target:CheckDualSpecState()
end
if AceConfigRegistry3 and next(registry) then
-- Update the "Current" text in options
-- We don't get the key for the actual registered options table, and we can't
-- really check for our enhanced options without walking every options table,
-- so just refresh anything.
for appName in AceConfigRegistry3:IterateOptionsTables() do
AceConfigRegistry3:NotifyChange(appName)
end
end
end
lib.eventFrame:SetScript("OnEvent", eventHandler)
if IsLoggedIn() then
eventHandler(lib.eventFrame, "PLAYER_LOGIN")
else
lib.eventFrame:RegisterEvent("PLAYER_LOGIN")
end

View File

@ -0,0 +1,227 @@
local MAJOR, MINOR = "LibElvUIPlugin-1.0", 13
local lib, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not lib then return end
--Cache global variables
--Lua functions
local pairs, tonumber = pairs, tonumber
local format, strsplit = format, strsplit
--WoW API / Variables
local CreateFrame = CreateFrame
local IsInInstance, IsInGroup, IsInRaid = IsInInstance, IsInGroup, IsInRaid
local GetAddOnMetadata = GetAddOnMetadata
local IsAddOnLoaded = IsAddOnLoaded
local RegisterAddonMessagePrefix = RegisterAddonMessagePrefix
local SendAddonMessage = SendAddonMessage
local LE_PARTY_CATEGORY_HOME = LE_PARTY_CATEGORY_HOME
local LE_PARTY_CATEGORY_INSTANCE = LE_PARTY_CATEGORY_INSTANCE
--Global variables that we don't cache, list them here for the mikk's Find Globals script
-- GLOBALS: ElvUI
lib.plugins = {}
lib.index = 0
lib.prefix = "ElvUIPluginVC"
-- MULTI Language Support (Default Language: English)
local MSG_OUTDATED = "Your version of %s is out of date (latest is version %s). You can download the latest version from http://www.tukui.org"
local HDR_CONFIG = "Plugins"
local HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - Plugins Loaded (Green means you have current version, Red means out of date)"
local INFO_BY = "by"
local INFO_VERSION = "Version:"
local INFO_NEW = "Newest:"
local LIBRARY = "Library"
if GetLocale() == "deDE" then -- German Translation
MSG_OUTDATED = "Deine Version von %s ist veraltet (akutelle Version ist %s). Du kannst die aktuelle Version von http://www.tukui.org herunterrladen."
HDR_CONFIG = "Plugins"
HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - Plugins geladen (Grün bedeutet du hast die aktuelle Version, Rot bedeutet es ist veraltet)"
INFO_BY = "von"
INFO_VERSION = "Version:"
INFO_NEW = "Neuste:"
LIBRARY = "Bibliothek"
end
if GetLocale() == "ruRU" then -- Russian Translations
MSG_OUTDATED = "Ваша версия %s устарела (последняя версия %s). Вы можете скачать последнюю версию на http://www.tukui.org"
HDR_CONFIG = "Плагины"
HDR_INFORMATION = "LibElvUIPlugin-1.0.%d - загруженные плагины (зеленый означает, что у вас последняя версия, красный - устаревшая)"
INFO_BY = "от"
INFO_VERSION = "Версия:"
INFO_NEW = "Последняя:"
LIBRARY = "Библиотека"
end
--
-- Plugin table format:
-- { name (string) - The name of the plugin,
-- version (string) - The version of the plugin,
-- optionCallback (string) - The callback to call when ElvUI_Config is loaded
-- }
--
--
-- RegisterPlugin(name,callback)
-- Registers a module with the given name and option callback, pulls version info from metadata
--
function lib:RegisterPlugin(name,callback, isLib)
local plugin = {}
plugin.name = name
plugin.version = name == MAJOR and MINOR or GetAddOnMetadata(name, "Version")
if isLib then plugin.isLib = true; plugin.version = 1 end
plugin.callback = callback
lib.plugins[name] = plugin
local loaded = IsAddOnLoaded("ElvUI_Config")
if not lib.vcframe then
RegisterAddonMessagePrefix(lib.prefix)
local f = CreateFrame('Frame')
f:RegisterEvent("GROUP_ROSTER_UPDATE")
f:RegisterEvent("CHAT_MSG_ADDON")
f:SetScript('OnEvent', lib.VersionCheck)
lib.vcframe = f
end
if not loaded then
if not lib.ConfigFrame then
local configFrame = CreateFrame("Frame")
configFrame:RegisterEvent("ADDON_LOADED")
configFrame:SetScript("OnEvent", function(self,event,addon)
if addon == "ElvUI_Config" then
for _, plugin in pairs(lib.plugins) do
if(plugin.callback) then
plugin.callback()
end
end
end
end)
lib.ConfigFrame = configFrame
end
elseif loaded then
-- Need to update plugins list
if name ~= MAJOR then
ElvUI[1].Options.args.plugins.args.plugins.name = lib:GeneratePluginList()
end
callback()
end
return plugin
end
function lib:GetPluginOptions()
ElvUI[1].Options.args.plugins = {
order = -10,
type = "group",
name = HDR_CONFIG,
guiInline = false,
args = {
pluginheader = {
order = 1,
type = "header",
name = format(HDR_INFORMATION, MINOR),
},
plugins = {
order = 2,
type = "description",
name = lib:GeneratePluginList(),
},
}
}
end
function lib:GenerateVersionCheckMessage()
local list = ""
for _, plugin in pairs(lib.plugins) do
if plugin.name ~= MAJOR then
list = list..plugin.name.."="..plugin.version..";"
end
end
return list
end
local function SendPluginVersionCheck(self)
lib:SendPluginVersionCheck(lib:GenerateVersionCheckMessage())
if self["ElvUIPluginSendMSGTimer"] then
self:CancelTimer(self["ElvUIPluginSendMSGTimer"])
self["ElvUIPluginSendMSGTimer"] = nil
end
end
function lib:VersionCheck(event, prefix, message, channel, sender)
local E = ElvUI[1]
if event == "CHAT_MSG_ADDON" then
if sender == E.myname or not sender or prefix ~= lib.prefix then return end
if not E["pluginRecievedOutOfDateMessage"] then
for _, p in pairs({strsplit(";",message)}) do
local name, version = p:match("([%w_]+)=([%d%p]+)")
if lib.plugins[name] then
local plugin = lib.plugins[name]
if plugin.version ~= 'BETA' and version ~= nil and tonumber(version) ~= nil and plugin.version ~= nil and tonumber(plugin.version) ~= nil and tonumber(version) > tonumber(plugin.version) then
plugin.old = true
plugin.newversion = tonumber(version)
local Pname = GetAddOnMetadata(plugin.name, "Title")
E:Print(format(MSG_OUTDATED,Pname,plugin.newversion))
E["pluginRecievedOutOfDateMessage"] = true
end
end
end
end
else
E.SendPluginVersionCheck = E.SendPluginVersionCheck or SendPluginVersionCheck
E["ElvUIPluginSendMSGTimer"] = E:ScheduleTimer("SendPluginVersionCheck", 2)
end
end
function lib:GeneratePluginList()
local list = ""
local E = ElvUI[1]
for _, plugin in pairs(lib.plugins) do
if plugin.name ~= MAJOR then
local author = GetAddOnMetadata(plugin.name, "Author")
local Pname = GetAddOnMetadata(plugin.name, "Title") or plugin.name
local color = plugin.old and E:RGBToHex(1,0,0) or E:RGBToHex(0,1,0)
list = list .. Pname
if author then
list = list .. " ".. INFO_BY .." " .. author
end
list = list .. color ..(plugin.isLib and " "..LIBRARY or " - " .. INFO_VERSION .." " .. plugin.version)
if plugin.old then
list = list .. INFO_NEW .. plugin.newversion .. ")"
end
list = list .. "|r\n"
end
end
return list
end
function lib:SendPluginVersionCheck(message)
local plist = {strsplit(";",message)}
local m = ""
local delay = 1
local E = ElvUI[1]
for _, p in pairs(plist) do
if(#(m .. p .. ";") < 230) then
m = m .. p .. ";"
else
local _, instanceType = IsInInstance()
if IsInRaid() then
E:Delay(delay,SendAddonMessage(lib.prefix, m, (not IsInRaid(LE_PARTY_CATEGORY_HOME) and IsInRaid(LE_PARTY_CATEGORY_INSTANCE)) and "INSTANCE_CHAT" or "RAID"))
elseif IsInGroup() then
E:Delay(delay,SendAddonMessage(lib.prefix, m, (not IsInGroup(LE_PARTY_CATEGORY_HOME) and IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) and "INSTANCE_CHAT" or "PARTY"))
end
m = p .. ";"
delay = delay + 1
end
end
-- Send the last message
local _, instanceType = IsInInstance()
if IsInRaid() then
E:Delay(delay+1,SendAddonMessage(lib.prefix, m, (not IsInRaid(LE_PARTY_CATEGORY_HOME) and IsInRaid(LE_PARTY_CATEGORY_INSTANCE)) and "INSTANCE_CHAT" or "RAID"))
elseif IsInGroup() then
E:Delay(delay+1,SendAddonMessage(lib.prefix, m, (not IsInGroup(LE_PARTY_CATEGORY_HOME) and IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) and "INSTANCE_CHAT" or "PARTY"))
end
end
lib:RegisterPlugin(MAJOR, lib.GetPluginOptions)

View File

@ -0,0 +1,202 @@
--[[
Copyright 2013 João Cardoso
CustomSearch is distributed under the terms of the GNU General Public License (Version 3).
As a special exception, the copyright holders of this library give you permission to embed it
with independent modules to produce an addon, regardless of the license terms of these
independent modules, and to copy and distribute the resulting software under terms of your
choice, provided that you also meet, for each embedded independent module, the terms and
conditions of the license of that module. Permission is not granted to modify this library.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the library. If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
This file is part of CustomSearch.
--]]
local Lib = LibStub:NewLibrary('CustomSearch-1.0', 9)
if not Lib then
return
end
--[[ Parsing ]]--
function Lib:Matches(object, search, filters)
if object then
self.filters = filters
self.object = object
return self:MatchAll(search or '')
end
end
function Lib:MatchAll(search)
for phrase in self:Clean(search):gmatch('[^&]+') do
if not self:MatchAny(phrase) then
return
end
end
return true
end
function Lib:MatchAny(search)
for phrase in search:gmatch('[^|]+') do
if self:Match(phrase) then
return true
end
end
end
function Lib:Match(search)
local tag, rest = search:match('^%s*(%S+):(.*)$')
if tag then
tag = '^' .. tag
search = rest
end
local words = search:gmatch('%S+')
local failed
for word in words do
if word == self.OR then
if failed then
failed = false
else
break
end
else
local negate, rest = word:match('^([!~]=*)(.*)$')
if negate or word == self.NOT_MATCH then
word = rest and rest ~= '' and rest or words() or ''
negate = -1
else
negate = 1
end
local operator, rest = word:match('^(=*[<>]=*)(.*)$')
if operator then
word = rest ~= '' and rest or words()
end
local result = self:Filter(tag, operator, word) and 1 or -1
if result * negate ~= 1 then
failed = true
end
end
end
return not failed
end
--[[ Filtering ]]--
function Lib:Filter(tag, operator, search)
if not search then
return true
end
if tag then
for _, filter in pairs(self.filters) do
for _, value in pairs(filter.tags or {}) do
if value:find(tag) then
return self:UseFilter(filter, operator, search)
end
end
end
else
for _, filter in pairs(self.filters) do
if not filter.onlyTags and self:UseFilter(filter, operator, search) then
return true
end
end
end
end
function Lib:UseFilter(filter, operator, search)
local data = {filter:canSearch(operator, search, self.object)}
if data[1] then
return filter:match(self.object, operator, unpack(data))
end
end
--[[ Utilities ]]--
function Lib:Find(search, ...)
for i = 1, select('#', ...) do
local text = select(i, ...)
if text and self:Clean(text):find(search) then
return true
end
end
end
function Lib:Clean(string)
string = string:lower()
string = string:gsub('[%(%)%.%%%+%-%*%?%[%]%^%$]', function(c) return '%'..c end)
for accent, char in pairs(self.ACCENTS) do
string = string:gsub(accent, char)
end
return string
end
function Lib:Compare(op, a, b)
if op then
if op:find('<') then
if op:find('=') then
return a <= b
end
return a < b
end
if op:find('>')then
if op:find('=') then
return a >= b
end
return a > b
end
end
return a == b
end
--[[ Localization ]]--
do
local no = {enUS = 'Not', frFR = 'Pas', deDE = 'Nicht'}
local accents = {
a = {'à','â','ã','å'},
e = {'è','é','ê','ê','ë'},
i = {'ì', 'í', 'î', 'ï'},
o = {'ó','ò','ô','õ'},
u = {'ù', 'ú', 'û', 'ü'},
c = {'ç'}, n = {'ñ'}
}
Lib.ACCENTS = {}
for char, accents in pairs(accents) do
for _, accent in ipairs(accents) do
Lib.ACCENTS[accent] = char
end
end
Lib.OR = Lib:Clean(JUST_OR)
Lib.NOT = no[GetLocale()] or NO
Lib.NOT_MATCH = Lib:Clean(Lib.NOT)
setmetatable(Lib, {__call = Lib.Matches})
end
return Lib

View File

@ -0,0 +1,295 @@
--[[
ItemSearch
An item text search engine of some sort
--]]
local Search = LibStub('CustomSearch-1.0')
local Unfit = LibStub('Unfit-1.0')
local Lib = LibStub:NewLibrary('LibItemSearch-1.2-ElvUI', 6)
if Lib then
Lib.Filters = {}
else
return
end
--[[ User API ]]--
function Lib:Matches(link, search)
return Search(link, search, self.Filters)
end
function Lib:Tooltip(link, search)
return link and self.Filters.tip:match(link, nil, search)
end
function Lib:TooltipPhrase(link, search, allowPartialMatch)
return link and self.Filters.tipPhrases:match(link, nil, search, allowPartialMatch)
end
function Lib:InSet(link, search)
if IsEquippableItem(link) then
local id = tonumber(link:match('item:(%-?%d+)'))
return self:BelongsToSet(id, (search or ''):lower())
end
end
--[[ Basics ]]--
Lib.Filters.name = {
tags = {'n', 'name'},
canSearch = function(self, operator, search)
return not operator and search
end,
match = function(self, item, _, search)
local name = item:match('%[(.-)%]')
return Search:Find(search, name)
end
}
Lib.Filters.type = {
tags = {'t', 'type', 's', 'slot'},
canSearch = function(self, operator, search)
return not operator and search
end,
match = function(self, item, _, search)
local type, subType, _, equipSlot = select(6, GetItemInfo(item))
return Search:Find(search, type, subType, _G[equipSlot])
end
}
Lib.Filters.level = {
tags = {'l', 'level', 'lvl', 'ilvl'},
canSearch = function(self, _, search)
return tonumber(search)
end,
match = function(self, link, operator, num)
local lvl = select(4, GetItemInfo(link))
if lvl then
return Search:Compare(operator, lvl, num)
end
end
}
Lib.Filters.requiredlevel = {
tags = {'r', 'req', 'rl', 'reql', 'reqlvl'},
canSearch = function(self, _, search)
return tonumber(search)
end,
match = function(self, link, operator, num)
local lvl = select(5, GetItemInfo(link))
if lvl then
return Search:Compare(operator, lvl, num)
end
end
}
--[[ Quality ]]--
local qualities = {}
for i = 0, #ITEM_QUALITY_COLORS do
qualities[i] = _G['ITEM_QUALITY' .. i .. '_DESC']:lower()
end
Lib.Filters.quality = {
tags = {'q', 'quality'},
canSearch = function(self, _, search)
for i, name in pairs(qualities) do
if name:find(search) then
return i
end
end
end,
match = function(self, link, operator, num)
local quality = link:sub(1, 9) == 'battlepet' and tonumber(link:match('%d+:%d+:(%d+)')) or select(3, GetItemInfo(link))
return Search:Compare(operator, quality, num)
end,
}
--[[ Usable ]]--
Lib.Filters.usable = {
tags = {},
canSearch = function(self, operator, search)
return not operator and search == 'usable'
end,
match = function(self, link)
if not Unfit:IsItemUnusable(link) then
local lvl = select(5, GetItemInfo(link))
return lvl and (lvl ~= 0 and lvl <= UnitLevel('player'))
end
end
}
--[[ Tooltip Searches ]]--
local scanner = LibItemSearchTooltipScanner or CreateFrame('GameTooltip', 'LibItemSearchTooltipScanner', UIParent, 'GameTooltipTemplate')
Lib.Filters.tip = {
tags = {'tt', 'tip', 'tooltip'},
onlyTags = true,
canSearch = function(self, _, search)
return search
end,
match = function(self, link, _, search)
if link:find('item:') then
scanner:SetOwner(UIParent, 'ANCHOR_NONE')
scanner:SetHyperlink(link)
for i = 1, scanner:NumLines() do
if Search:Find(search, _G[scanner:GetName() .. 'TextLeft' .. i]:GetText()) then
return true
end
end
end
end
}
local escapes = {
["|c%x%x%x%x%x%x%x%x"] = "", -- color start
["|r"] = "", -- color end
}
local function CleanString(str)
for k, v in pairs(escapes) do
str = str:gsub(k, v)
end
return str
end
Lib.Filters.tipPhrases = {
canSearch = function(self, _, search)
return self.keywords[search]
end,
match = function(self, link, _, search, allowPartialMatch)
local id = link:match('item:(%d+)')
if not id then
return
end
local cached = self.cache[search][id]
if cached ~= nil then
return cached
end
scanner:SetOwner(UIParent, 'ANCHOR_NONE')
scanner:SetHyperlink(link)
local matches = false
for i = 1, scanner:NumLines() do
local text = _G['LibItemSearchTooltipScannerTextLeft' .. i]:GetText()
text = CleanString(text)
if search == text or (allowPartialMatch and text:find(search)) then
matches = true
break
end
end
self.cache[search][id] = matches
return matches
end,
cache = setmetatable({}, {__index = function(t, k) local v = {} t[k] = v return v end}),
keywords = {
[ITEM_SOULBOUND:lower()] = ITEM_BIND_ON_PICKUP,
['bound'] = ITEM_BIND_ON_PICKUP,
['bop'] = ITEM_BIND_ON_PICKUP,
['boe'] = ITEM_BIND_ON_EQUIP,
['bou'] = ITEM_BIND_ON_USE,
['boa'] = ITEM_BIND_TO_BNETACCOUNT,
[GetItemClassInfo(LE_ITEM_CLASS_QUESTITEM):lower()] = ITEM_BIND_QUEST,
[QUESTS_LABEL:lower()] = ITEM_BIND_QUEST,
[TOY:lower()] = TOY,
[MINIMAP_TRACKING_VENDOR_REAGENT:lower()] = PROFESSIONS_USED_IN_COOKING,
['reagent'] = PROFESSIONS_USED_IN_COOKING,
['crafting'] = PROFESSIONS_USED_IN_COOKING,
['naval'] = 'naval equipment',
['follower'] = 'follower',
['followe'] = 'follower',
['follow'] = 'follower',
["relic"] = (GetItemSubClassInfo(LE_ITEM_CLASS_GEM, 11)),
["reli"] = (GetItemSubClassInfo(LE_ITEM_CLASS_GEM, 11)),
["rel"] = (GetItemSubClassInfo(LE_ITEM_CLASS_GEM, 11)),
["power"] = ARTIFACT_POWER,
["powe"] = ARTIFACT_POWER,
["pow"] = ARTIFACT_POWER,
}
}
--[[ Equipment Sets ]]--
if IsAddOnLoaded('ItemRack') then
local sameID = ItemRack.SameID
function Lib:BelongsToSet(id, search)
for name, set in pairs(ItemRackUser.Sets) do
if name:sub(1,1) ~= '' and Search:Find(search, name) then
for _, item in pairs(set.equip) do
if sameID(id, item) then
return true
end
end
end
end
end
elseif IsAddOnLoaded('Wardrobe') then
function Lib:BelongsToSet(id, search)
for _, outfit in ipairs(Wardrobe.CurrentConfig.Outfit) do
local name = outfit.OutfitName
if Search:Find(search, name) then
for _, item in pairs(outfit.Item) do
if item.IsSlotUsed == 1 and item.ItemID == id then
return true
end
end
end
end
end
else
function Lib:BelongsToSet(id, search)
for i = 1, GetNumEquipmentSets() do
local name = GetEquipmentSetInfo(i)
if Search:Find(search, name) or search == "matchall" then
local items = GetEquipmentSetItemIDs(name)
for _, item in pairs(items) do
if id == item then
return true
end
end
end
end
end
end
Lib.Filters.sets = {
tags = {'s', 'set'},
canSearch = function(self, operator, search)
return not operator and search
end,
match = function(self, link, _, search)
return Lib:InSet(link, search)
end,
}

View File

@ -0,0 +1,6 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="CustomSearch-1.0\CustomSearch-1.0.lua"/>
<Script file="Unfit-1.0\Unfit-1.0.lua"/>
<Script file="LibItemSearch-1.2.lua"/>
</Ui>

View File

@ -0,0 +1,127 @@
--[[
Copyright 2011-2016 João Cardoso
Unfit is distributed under the terms of the GNU General Public License (Version 3).
As a special exception, the copyright holders of this library give you permission to embed it
with independent modules to produce an addon, regardless of the license terms of these
independent modules, and to copy and distribute the resulting software under terms of your
choice, provided that you also meet, for each embedded independent module, the terms and
conditions of the license of that module. Permission is not granted to modify this library.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the library. If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
This file is part of Unfit.
--]]
local Lib = LibStub:NewLibrary('Unfit-1.0', 9)
if not Lib then
return
end
--[[ Data ]]--
do
local _, Class = UnitClass('player')
local Unusable
if Class == 'DEATHKNIGHT' then
Unusable = { -- weapon, armor, dual-wield
{LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_STAFF,LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_DAGGER, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND},
{LE_ITEM_ARMOR_SHIELD}
}
elseif Class == 'DEMONHUNTER' then
Unusable = {
{LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE1H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_STAFF, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND},
{LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}
}
elseif Class == 'DRUID' then
Unusable = {
{LE_ITEM_WEAPON_AXE1H, LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_SWORD1H, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND},
{LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD},
true
}
elseif Class == 'HUNTER' then
Unusable = {
{LE_ITEM_WEAPON_MACE1H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_WAND},
{LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}
}
elseif Class == 'MAGE' then
Unusable = {
{LE_ITEM_WEAPON_AXE1H, LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE1H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW},
{LE_ITEM_ARMOR_LEATHER, LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD},
true
}
elseif Class == 'MONK' then
Unusable = {
{LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_DAGGER, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND},
{LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}
}
elseif Class == 'PALADIN' then
Unusable = {
{LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_STAFF, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_DAGGER, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND},
{},
true
}
elseif Class == 'PRIEST' then
Unusable = {
{LE_ITEM_WEAPON_AXE1H, LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD1H, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW},
{LE_ITEM_ARMOR_LEATHER, LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD},
true
}
elseif Class == 'ROGUE' then
Unusable = {
{LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_STAFF, LE_ITEM_WEAPON_WAND},
{LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}
}
elseif Class == 'SHAMAN' then
Unusable = {
{LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD1H, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND},
{LE_ITEM_ARMOR_PLATEM}
}
elseif Class == 'WARLOCK' then
Unusable = {
{LE_ITEM_WEAPON_AXE1H, LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE1H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW},
{LE_ITEM_ARMOR_LEATHER, LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD},
true
}
elseif Class == 'WARRIOR' then
Unusable = {{LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_WAND}, {}}
else
Unusable = {{}, {}}
end
Lib.unusable = {}
Lib.cannotDual = Unusable[3]
for i, class in ipairs({LE_ITEM_CLASS_WEAPON, LE_ITEM_CLASS_ARMOR}) do
local list = {}
for _, subclass in ipairs(Unusable[i]) do
list[subclass] = true
end
Lib.unusable[class] = list
end
end
--[[ API ]]--
function Lib:IsItemUnusable(...)
if ... then
local slot, _,_, class, subclass = select(9, GetItemInfo(...))
return Lib:IsClassUnusable(class, subclass, slot)
end
end
function Lib:IsClassUnusable(class, subclass, slot)
if class and subclass and Lib.unusable[class] then
return slot ~= '' and Lib.unusable[class][subclass] or slot == 'INVTYPE_WEAPONOFFHAND' and Lib.cannotDual
end
end

View File

@ -0,0 +1,292 @@
--[[
Name: LibSharedMedia-3.0
Revision: $Revision: 91 $
Author: Elkano (elkano@gmx.de)
Inspired By: SurfaceLib by Haste/Otravi (troeks@gmail.com)
Website: http://www.wowace.com/projects/libsharedmedia-3-0/
Description: Shared handling of media data (fonts, sounds, textures, ...) between addons.
Dependencies: LibStub, CallbackHandler-1.0
License: LGPL v2.1
]]
local MAJOR, MINOR = "LibSharedMedia-3.0", 6010002 -- 6.1.0 v2 / increase manually on changes
local lib = LibStub:NewLibrary(MAJOR, MINOR)
if not lib then return end
local _G = getfenv(0)
local pairs = _G.pairs
local type = _G.type
local band = _G.bit.band
local table_insert = _G.table.insert
local table_sort = _G.table.sort
local locale = GetLocale()
local locale_is_western
local LOCALE_MASK = 0
lib.LOCALE_BIT_koKR = 1
lib.LOCALE_BIT_ruRU = 2
lib.LOCALE_BIT_zhCN = 4
lib.LOCALE_BIT_zhTW = 8
lib.LOCALE_BIT_western = 128
local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0")
lib.callbacks = lib.callbacks or CallbackHandler:New(lib)
lib.DefaultMedia = lib.DefaultMedia or {}
lib.MediaList = lib.MediaList or {}
lib.MediaTable = lib.MediaTable or {}
lib.MediaType = lib.MediaType or {}
lib.OverrideMedia = lib.OverrideMedia or {}
local defaultMedia = lib.DefaultMedia
local mediaList = lib.MediaList
local mediaTable = lib.MediaTable
local overrideMedia = lib.OverrideMedia
-- create mediatype constants
lib.MediaType.BACKGROUND = "background" -- background textures
lib.MediaType.BORDER = "border" -- border textures
lib.MediaType.FONT = "font" -- fonts
lib.MediaType.STATUSBAR = "statusbar" -- statusbar textures
lib.MediaType.SOUND = "sound" -- sound files
-- populate lib with default Blizzard data
-- BACKGROUND
if not lib.MediaTable.background then lib.MediaTable.background = {} end
lib.MediaTable.background["None"] = [[]]
lib.MediaTable.background["Blizzard Collections Background"] = [[Interface\Collections\CollectionsBackgroundTile]]
lib.MediaTable.background["Blizzard Dialog Background"] = [[Interface\DialogFrame\UI-DialogBox-Background]]
lib.MediaTable.background["Blizzard Dialog Background Dark"] = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]]
lib.MediaTable.background["Blizzard Dialog Background Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Background]]
lib.MediaTable.background["Blizzard Garrison Background"] = [[Interface\Garrison\GarrisonUIBackground]]
lib.MediaTable.background["Blizzard Garrison Background 2"] = [[Interface\Garrison\GarrisonUIBackground2]]
lib.MediaTable.background["Blizzard Garrison Background 3"] = [[Interface\Garrison\GarrisonMissionUIInfoBoxBackgroundTile]]
lib.MediaTable.background["Blizzard Low Health"] = [[Interface\FullScreenTextures\LowHealth]]
lib.MediaTable.background["Blizzard Marble"] = [[Interface\FrameGeneral\UI-Background-Marble]]
lib.MediaTable.background["Blizzard Out of Control"] = [[Interface\FullScreenTextures\OutOfControl]]
lib.MediaTable.background["Blizzard Parchment"] = [[Interface\AchievementFrame\UI-Achievement-Parchment-Horizontal]]
lib.MediaTable.background["Blizzard Parchment 2"] = [[Interface\AchievementFrame\UI-GuildAchievement-Parchment-Horizontal]]
lib.MediaTable.background["Blizzard Rock"] = [[Interface\FrameGeneral\UI-Background-Rock]]
lib.MediaTable.background["Blizzard Tabard Background"] = [[Interface\TabardFrame\TabardFrameBackground]]
lib.MediaTable.background["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Background]]
lib.MediaTable.background["Solid"] = [[Interface\Buttons\WHITE8X8]]
lib.DefaultMedia.background = "None"
-- BORDER
if not lib.MediaTable.border then lib.MediaTable.border = {} end
lib.MediaTable.border["None"] = [[]]
lib.MediaTable.border["Blizzard Achievement Wood"] = [[Interface\AchievementFrame\UI-Achievement-WoodBorder]]
lib.MediaTable.border["Blizzard Chat Bubble"] = [[Interface\Tooltips\ChatBubble-Backdrop]]
lib.MediaTable.border["Blizzard Dialog"] = [[Interface\DialogFrame\UI-DialogBox-Border]]
lib.MediaTable.border["Blizzard Dialog Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Border]]
lib.MediaTable.border["Blizzard Party"] = [[Interface\CHARACTERFRAME\UI-Party-Border]]
lib.MediaTable.border["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Border]]
lib.DefaultMedia.border = "None"
-- FONT
if not lib.MediaTable.font then lib.MediaTable.font = {} end
local SML_MT_font = lib.MediaTable.font
--[[
All font files are currently in all clients, the following table depicts which font supports which charset as of 5.0.4
Fonts were checked using langcover.pl from DejaVu fonts (http://sourceforge.net/projects/dejavu/) and FontForge (http://fontforge.org/)
latin means check for: de, en, es, fr, it, pt
file name latin koKR ruRU zhCN zhTW
2002.ttf 2002 X X X - -
2002B.ttf 2002 Bold X X X - -
ARHei.ttf AR CrystalzcuheiGBK Demibold X - X X X
ARIALN.TTF Arial Narrow X - X - -
ARKai_C.ttf AR ZhongkaiGBK Medium (Combat) X - X X X
ARKai_T.ttf AR ZhongkaiGBK Medium X - X X X
bHEI00M.ttf AR Heiti2 Medium B5 - - - - X
bHEI01B.ttf AR Heiti2 Bold B5 - - - - X
bKAI00M.ttf AR Kaiti Medium B5 - - - - X
bLEI00D.ttf AR Leisu Demi B5 - - - - X
FRIZQT__.TTF Friz Quadrata TT X - - - -
FRIZQT___CYR.TTF FrizQuadrataCTT x - X - -
K_Damage.TTF YDIWingsM - X X - -
K_Pagetext.TTF MoK X X X - -
MORPHEUS.TTF Morpheus X - - - -
MORPHEUS_CYR.TTF Morpheus X - X - -
NIM_____.ttf Nimrod MT X - X - -
SKURRI.TTF Skurri X - - - -
SKURRI_CYR.TTF Skurri X - X - -
WARNING: Although FRIZQT___CYR is available on western clients, it doesn't support special European characters e.g. é, ï, ö
Due to this, we cannot use it as a replacement for FRIZQT__.TTF
]]
if locale == "koKR" then
LOCALE_MASK = lib.LOCALE_BIT_koKR
--
SML_MT_font["굵은 글꼴"] = [[Fonts\2002B.TTF]]
SML_MT_font["기본 글꼴"] = [[Fonts\2002.TTF]]
SML_MT_font["데미지 글꼴"] = [[Fonts\K_Damage.TTF]]
SML_MT_font["퀘스트 글꼴"] = [[Fonts\K_Pagetext.TTF]]
--
lib.DefaultMedia["font"] = "기본 글꼴" -- someone from koKR please adjust if needed
--
elseif locale == "zhCN" then
LOCALE_MASK = lib.LOCALE_BIT_zhCN
--
SML_MT_font["伤害数字"] = [[Fonts\ARKai_C.ttf]]
SML_MT_font["默认"] = [[Fonts\ARKai_T.ttf]]
SML_MT_font["聊天"] = [[Fonts\ARHei.ttf]]
--
lib.DefaultMedia["font"] = "默认" -- someone from zhCN please adjust if needed
--
elseif locale == "zhTW" then
LOCALE_MASK = lib.LOCALE_BIT_zhTW
--
SML_MT_font["提示訊息"] = [[Fonts\bHEI00M.ttf]]
SML_MT_font["聊天"] = [[Fonts\bHEI01B.ttf]]
SML_MT_font["傷害數字"] = [[Fonts\bKAI00M.ttf]]
SML_MT_font["預設"] = [[Fonts\bLEI00D.ttf]]
--
lib.DefaultMedia["font"] = "預設" -- someone from zhTW please adjust if needed
elseif locale == "ruRU" then
LOCALE_MASK = lib.LOCALE_BIT_ruRU
--
SML_MT_font["2002"] = [[Fonts\2002.TTF]]
SML_MT_font["2002 Bold"] = [[Fonts\2002B.TTF]]
SML_MT_font["AR CrystalzcuheiGBK Demibold"] = [[Fonts\ARHei.TTF]]
SML_MT_font["AR ZhongkaiGBK Medium (Combat)"] = [[Fonts\ARKai_C.TTF]]
SML_MT_font["AR ZhongkaiGBK Medium"] = [[Fonts\ARKai_T.TTF]]
SML_MT_font["Arial Narrow"] = [[Fonts\ARIALN.TTF]]
SML_MT_font["Friz Quadrata TT"] = [[Fonts\FRIZQT___CYR.TTF]]
SML_MT_font["MoK"] = [[Fonts\K_Pagetext.TTF]]
SML_MT_font["Morpheus"] = [[Fonts\MORPHEUS_CYR.TTF]]
SML_MT_font["Nimrod MT"] = [[Fonts\NIM_____.ttf]]
SML_MT_font["Skurri"] = [[Fonts\SKURRI_CYR.TTF]]
--
lib.DefaultMedia.font = "Friz Quadrata TT"
--
else
LOCALE_MASK = lib.LOCALE_BIT_western
locale_is_western = true
--
SML_MT_font["2002"] = [[Fonts\2002.TTF]]
SML_MT_font["2002 Bold"] = [[Fonts\2002B.TTF]]
SML_MT_font["AR CrystalzcuheiGBK Demibold"] = [[Fonts\ARHei.TTF]]
SML_MT_font["AR ZhongkaiGBK Medium (Combat)"] = [[Fonts\ARKai_C.TTF]]
SML_MT_font["AR ZhongkaiGBK Medium"] = [[Fonts\ARKai_T.TTF]]
SML_MT_font["Arial Narrow"] = [[Fonts\ARIALN.TTF]]
SML_MT_font["Friz Quadrata TT"] = [[Fonts\FRIZQT__.TTF]]
SML_MT_font["MoK"] = [[Fonts\K_Pagetext.TTF]]
SML_MT_font["Morpheus"] = [[Fonts\MORPHEUS_CYR.TTF]]
SML_MT_font["Nimrod MT"] = [[Fonts\NIM_____.ttf]]
SML_MT_font["Skurri"] = [[Fonts\SKURRI_CYR.TTF]]
--
lib.DefaultMedia.font = "Friz Quadrata TT"
--
end
-- STATUSBAR
if not lib.MediaTable.statusbar then lib.MediaTable.statusbar = {} end
lib.MediaTable.statusbar["Blizzard"] = [[Interface\TargetingFrame\UI-StatusBar]]
lib.MediaTable.statusbar["Blizzard Character Skills Bar"] = [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]]
lib.MediaTable.statusbar["Blizzard Raid Bar"] = [[Interface\RaidFrame\Raid-Bar-Hp-Fill]]
lib.DefaultMedia.statusbar = "Blizzard"
-- SOUND
if not lib.MediaTable.sound then lib.MediaTable.sound = {} end
lib.MediaTable.sound["None"] = [[Interface\Quiet.ogg]] -- Relies on the fact that PlaySound[File] doesn't error on non-existing input.
lib.DefaultMedia.sound = "None"
local function rebuildMediaList(mediatype)
local mtable = mediaTable[mediatype]
if not mtable then return end
if not mediaList[mediatype] then mediaList[mediatype] = {} end
local mlist = mediaList[mediatype]
-- list can only get larger, so simply overwrite it
local i = 0
for k in pairs(mtable) do
i = i + 1
mlist[i] = k
end
table_sort(mlist)
end
function lib:Register(mediatype, key, data, langmask)
if type(mediatype) ~= "string" then
error(MAJOR..":Register(mediatype, key, data, langmask) - mediatype must be string, got "..type(mediatype))
end
if type(key) ~= "string" then
error(MAJOR..":Register(mediatype, key, data, langmask) - key must be string, got "..type(key))
end
mediatype = mediatype:lower()
if mediatype == lib.MediaType.FONT and ((langmask and band(langmask, LOCALE_MASK) == 0) or not (langmask or locale_is_western)) then return false end
if mediatype == lib.MediaType.SOUND and type(data) == "string" then
local path = data:lower()
-- Only ogg and mp3 are valid sounds.
if not path:find(".ogg", nil, true) and not path:find(".mp3", nil, true) then
return false
end
end
if not mediaTable[mediatype] then mediaTable[mediatype] = {} end
local mtable = mediaTable[mediatype]
if mtable[key] then return false end
mtable[key] = data
rebuildMediaList(mediatype)
self.callbacks:Fire("LibSharedMedia_Registered", mediatype, key)
return true
end
function lib:Fetch(mediatype, key, noDefault)
local mtt = mediaTable[mediatype]
local overridekey = overrideMedia[mediatype]
local result = mtt and ((overridekey and mtt[overridekey] or mtt[key]) or (not noDefault and defaultMedia[mediatype] and mtt[defaultMedia[mediatype]])) or nil
return result ~= "" and result or nil
end
function lib:IsValid(mediatype, key)
return mediaTable[mediatype] and (not key or mediaTable[mediatype][key]) and true or false
end
function lib:HashTable(mediatype)
return mediaTable[mediatype]
end
function lib:List(mediatype)
if not mediaTable[mediatype] then
return nil
end
if not mediaList[mediatype] then
rebuildMediaList(mediatype)
end
return mediaList[mediatype]
end
function lib:GetGlobal(mediatype)
return overrideMedia[mediatype]
end
function lib:SetGlobal(mediatype, key)
if not mediaTable[mediatype] then
return false
end
overrideMedia[mediatype] = (key and mediaTable[mediatype][key]) and key or nil
self.callbacks:Fire("LibSharedMedia_SetGlobal", mediatype, overrideMedia[mediatype])
return true
end
function lib:GetDefault(mediatype)
return defaultMedia[mediatype]
end
function lib:SetDefault(mediatype, key)
if mediaTable[mediatype] and mediaTable[mediatype][key] and not defaultMedia[mediatype] then
defaultMedia[mediatype] = key
return true
else
return false
end
end

View File

@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="LibSharedMedia-3.0.lua" />
</Ui>

View File

@ -0,0 +1,280 @@
--[[---------------------------------------------------------------------------------
General Library providing an alternate StartMoving() that allows you to
specify a number of frames to snap-to when moving the frame around
Example Usage:
<OnLoad>
this:RegisterForDrag("LeftButton")
</OnLoad>
<OnDragStart>
StickyFrames:StartMoving(this, {WatchDogFrame_player, WatchDogFrame_target, WatchDogFrame_party1, WatchDogFrame_party2, WatchDogFrame_party3, WatchDogFrame_party4},3,3,3,3)
</OnDragStart>
<OnDragStop>
StickyFrames:StopMoving(this)
StickyFrames:AnchorFrame(this)
</OnDragStop>
------------------------------------------------------------------------------------
This is a modified version by Elv for ElvUI
------------------------------------------------------------------------------------]]
local MAJOR, MINOR = "LibSimpleSticky-1.0", 2
local StickyFrames, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not StickyFrames then return end
--[[---------------------------------------------------------------------------------
Class declaration, along with a temporary table to hold any existing OnUpdate
scripts.
------------------------------------------------------------------------------------]]
StickyFrames.scripts = StickyFrames.scripts or {}
StickyFrames.rangeX = 15
StickyFrames.rangeY = 15
StickyFrames.sticky = StickyFrames.sticky or {}
--[[---------------------------------------------------------------------------------
StickyFrames:StartMoving() - Sets a custom OnUpdate for the frame so it follows
the mouse and snaps to the frames you specify
frame: The frame we want to move. Is typically "this"
frameList: A integer indexed list of frames that the given frame should try to
stick to. These don't have to have anything special done to them,
and they don't really even need to exist. You can inclue the
moving frame in this list, it will be ignored. This helps you
if you have a number of frames, just make ONE list to pass.
{WatchDogFrame_player, WatchDogFrame_party1, .. WatchDogFrame_party4}
left: If your frame has a tranparent border around the entire frame
(think backdrops with borders). This can be used to fine tune the
edges when you're stickying groups. Refers to any offset on the
LEFT edge of the frame being moved.
top: same
right: same
bottom: same
------------------------------------------------------------------------------------]]
function StickyFrames:StartMoving(frame, frameList, left, top, right, bottom)
local x,y = GetCursorPosition()
local aX,aY = frame:GetCenter()
local aS = frame:GetEffectiveScale()
aX,aY = aX*aS,aY*aS
local xoffset,yoffset = (aX - x),(aY - y)
self.scripts[frame] = frame:GetScript("OnUpdate")
frame:SetScript("OnUpdate", self:GetUpdateFunc(frame, frameList, xoffset, yoffset, left, top, right, bottom))
end
--[[---------------------------------------------------------------------------------
This stops the OnUpdate, leaving the frame at its last position. This will
leave it anchored to UIParent. You can call StickyFrames:AnchorFrame() to
anchor it back "TOPLEFT" , "TOPLEFT" to the parent.
------------------------------------------------------------------------------------]]
function StickyFrames:StopMoving(frame)
frame:SetScript("OnUpdate", self.scripts[frame])
self.scripts[frame] = nil
if StickyFrames.sticky[frame] then
local sticky = StickyFrames.sticky[frame]
StickyFrames.sticky[frame] = nil
return true, sticky
else
return false, nil
end
end
--[[---------------------------------------------------------------------------------
This can be called in conjunction with StickyFrames:StopMoving() to anchor the
frame right back to the parent, so you can manipulate its children as a group
(This is useful in WatchDog)
------------------------------------------------------------------------------------]]
function StickyFrames:AnchorFrame(frame)
local xA,yA = frame:GetCenter()
local parent = frame:GetParent() or UIParent
local xP,yP = parent:GetCenter()
local sA,sP = frame:GetEffectiveScale(), parent:GetEffectiveScale()
xP,yP = (xP*sP) / sA, (yP*sP) / sA
local xo,yo = (xP - xA)*-1, (yP - yA)*-1
frame:ClearAllPoints()
frame:SetPoint("CENTER", parent, "CENTER", xo, yo)
end
--[[---------------------------------------------------------------------------------
Internal Functions -- Do not call these.
------------------------------------------------------------------------------------]]
--[[---------------------------------------------------------------------------------
Returns an anonymous OnUpdate function for the frame in question. Need
to provide the frame, frameList along with the x and y offset (difference between
where the mouse picked up the frame, and the insets (left,top,right,bottom) in the
case of borders, etc.w
------------------------------------------------------------------------------------]]
function StickyFrames:GetUpdateFunc(frame, frameList, xoffset, yoffset, left, top, right, bottom)
return function()
local x,y = GetCursorPosition()
local s = frame:GetEffectiveScale()
local sticky = nil
x,y = x/s,y/s
frame:ClearAllPoints()
frame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", x+xoffset, y+yoffset)
StickyFrames.sticky[frame] = nil
for i = 1, #frameList do
local v = frameList[i]
if frame ~= v and frame ~= v:GetParent() and not IsShiftKeyDown() and v:IsVisible() then
if self:SnapFrame(frame, v, left, top, right, bottom) then
StickyFrames.sticky[frame] = v
break
end
end
end
end
end
--[[---------------------------------------------------------------------------------
Internal debug function.
------------------------------------------------------------------------------------]]
function StickyFrames:debug(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00StickyFrames: |r"..tostring(msg))
end
--[[---------------------------------------------------------------------------------
This is called when finding an overlap between two sticky frame. If frameA is near
a sticky edge of frameB, then it will snap to that edge and return true. If there
is no sticky edge collision, will return false so we can test other frames for
stickyness.
------------------------------------------------------------------------------------]]
function StickyFrames:SnapFrame(frameA, frameB, left, top, right, bottom)
local sA, sB = frameA:GetEffectiveScale(), frameB:GetEffectiveScale()
local xA, yA = frameA:GetCenter()
local xB, yB = frameB:GetCenter()
local hA, hB = frameA:GetHeight() / 2, ((frameB:GetHeight() * sB) / sA) / 2
local wA, wB = frameA:GetWidth() / 2, ((frameB:GetWidth() * sB) / sA) / 2
local newX, newY = xA, yA
if not left then left = 0 end
if not top then top = 0 end
if not right then right = 0 end
if not bottom then bottom = 0 end
-- Lets translate B's coords into A's scale
if not xB or not yB or not sB or not sA or not sB then return end
xB, yB = (xB*sB) / sA, (yB*sB) / sA
local stickyAx, stickyAy = wA * 0.75, hA * 0.75
local stickyBx, stickyBy = wB * 0.75, hB * 0.75
-- Grab the edges of each frame, for easier comparison
local lA, tA, rA, bA = frameA:GetLeft(), frameA:GetTop(), frameA:GetRight(), frameA:GetBottom()
local lB, tB, rB, bB = frameB:GetLeft(), frameB:GetTop(), frameB:GetRight(), frameB:GetBottom()
local snap = nil
-- Translate into A's scale
lB, tB, rB, bB = (lB * sB) / sA, (tB * sB) / sA, (rB * sB) / sA, (bB * sB) / sA
if (bA <= tB and bB <= tA) then
-- Horizontal Centers
if xA <= (xB + StickyFrames.rangeX) and xA >= (xB - StickyFrames.rangeX) then
newX = xB
snap = true
end
-- Interior Left
if lA <= (lB + StickyFrames.rangeX) and lA >= (lB - StickyFrames.rangeX) then
newX = lB + wA
if frameB == UIParent or frameB == WorldFrame or frameB == ElvUIParent then
newX = newX + 4
end
snap = true
end
-- Interior Right
if rA <= (rB + StickyFrames.rangeX) and rA >= (rB - StickyFrames.rangeX) then
newX = rB - wA
if frameB == UIParent or frameB == WorldFrame or frameB == ElvUIParent then
newX = newX - 4
end
snap = true
end
-- Exterior Left to Right
if lA <= (rB + StickyFrames.rangeX) and lA >= (rB - StickyFrames.rangeX) then
newX = rB + (wA - left)
snap = true
end
-- Exterior Right to Left
if rA <= (lB + StickyFrames.rangeX) and rA >= (lB - StickyFrames.rangeX) then
newX = lB - (wA - right)
snap = true
end
end
if (lA <= rB and lB <= rA) then
-- Vertical Centers
if yA <= (yB + StickyFrames.rangeY) and yA >= (yB - StickyFrames.rangeY) then
newY = yB
snap = true
end
-- Interior Top
if tA <= (tB + StickyFrames.rangeY) and tA >= (tB - StickyFrames.rangeY) then
newY = tB - hA
if frameB == UIParent or frameB == WorldFrame or frameB == ElvUIParent then
newY = newY - 4
end
snap = true
end
-- Interior Bottom
if bA <= (bB + StickyFrames.rangeY) and bA >= (bB - StickyFrames.rangeY) then
newY = bB + hA
if frameB == UIParent or frameB == WorldFrame or frameB == ElvUIParent then
newY = newY + 4
end
snap = true
end
-- Exterior Top to Bottom
if tA <= (bB + StickyFrames.rangeY + bottom) and tA >= (bB - StickyFrames.rangeY + bottom) then
newY = bB - (hA - top)
snap = true
end
-- Exterior Bottom to Top
if bA <= (tB + StickyFrames.rangeY - top) and bA >= (tB - StickyFrames.rangeY - top) then
newY = tB + (hA - bottom)
snap = true
end
end
if snap then
frameA:ClearAllPoints()
frameA:SetPoint("CENTER", UIParent, "BOTTOMLEFT", newX, newY)
return true
end
end

View File

@ -0,0 +1,219 @@
--- = Background =
-- Blizzard's IsSpellInRange API has always been very limited - you either must have the name of the spell, or its spell book ID. Checking directly by spellID is simply not possible.
-- Now, in Mists of Pandaria, Blizzard changed the way that many talents and specialization spells work - instead of giving you a new spell when leaned, they replace existing spells. These replacement spells do not work with Blizzard's IsSpellInRange function whatsoever; this limitation is what prompted the creation of this lib.
-- = Usage =
-- **LibSpellRange-1.0** exposes an enhanced version of IsSpellInRange that:
-- * Allows ranged checking based on both spell name and spellID.
-- * Works correctly with replacement spells that will not work using Blizzard's IsSpellInRange method alone.
--
-- @class file
-- @name LibSpellRange-1.0.lua
local major = "SpellRange-1.0"
local minor = 11
assert(LibStub, format("%s requires LibStub.", major))
local Lib = LibStub:NewLibrary(major, minor)
if not Lib then return end
local tonumber = _G.tonumber
local strlower = _G.strlower
local wipe = _G.wipe
local type = _G.type
local GetSpellTabInfo = _G.GetSpellTabInfo
local GetNumSpellTabs = _G.GetNumSpellTabs
local GetSpellBookItemInfo = _G.GetSpellBookItemInfo
local GetSpellBookItemName = _G.GetSpellBookItemName
local GetSpellLink = _G.GetSpellLink
local GetSpellInfo = _G.GetSpellInfo
local IsSpellInRange = _G.IsSpellInRange
local SpellHasRange = _G.SpellHasRange
-- isNumber is basically a tonumber cache for maximum efficiency
Lib.isNumber = Lib.isNumber or setmetatable({}, {
__mode = "kv",
__index = function(t, i)
local o = tonumber(i) or false
t[i] = o
return o
end})
local isNumber = Lib.isNumber
-- strlower cache for maximum efficiency
Lib.strlowerCache = Lib.strlowerCache or setmetatable(
{}, {
__index = function(t, i)
if not i then return end
local o
if type(i) == "number" then
o = i
else
o = strlower(i)
end
t[i] = o
return o
end,
}) local strlowerCache = Lib.strlowerCache
-- Matches lowercase player spell names to their spellBookID
Lib.spellsByName_spell = Lib.spellsByName_spell or {}
local spellsByName_spell = Lib.spellsByName_spell
-- Matches player spellIDs to their spellBookID
Lib.spellsByID_spell = Lib.spellsByID_spell or {}
local spellsByID_spell = Lib.spellsByID_spell
-- Matches lowercase pet spell names to their spellBookID
Lib.spellsByName_pet = Lib.spellsByName_pet or {}
local spellsByName_pet = Lib.spellsByName_pet
-- Matches pet spellIDs to their spellBookID
Lib.spellsByID_pet = Lib.spellsByID_pet or {}
local spellsByID_pet = Lib.spellsByID_pet
-- Updates spellsByName and spellsByID
local function UpdateBook(bookType)
local _, _, offs, numspells = GetSpellTabInfo(3)
local max = offs -- The offset of the next tab is the max ID of the previous tab.
if numspells == 0 then
-- New characters pre level 10 only have 2 tabs.
local _, _, offs, numspells = GetSpellTabInfo(2)
max = offs + numspells
end
local spellsByName = Lib["spellsByName_" .. bookType]
local spellsByID = Lib["spellsByID_" .. bookType]
wipe(spellsByName)
wipe(spellsByID)
for spellBookID = 1, max do
local type, baseSpellID = GetSpellBookItemInfo(spellBookID, bookType)
if type == "SPELL" then
local currentSpellName = GetSpellBookItemName(spellBookID, bookType)
local link = GetSpellLink(currentSpellName)
local currentSpellID = tonumber(link and link:gsub("|", "||"):match("spell:(%d+)"))
local baseSpellName = GetSpellInfo(baseSpellID)
if currentSpellName then
spellsByName[strlower(currentSpellName)] = spellBookID
end
if baseSpellName then
spellsByName[strlower(baseSpellName)] = spellBookID
end
if currentSpellID then
spellsByID[currentSpellID] = spellBookID
end
if baseSpellID then
spellsByID[baseSpellID] = spellBookID
end
end
end
end
-- Handles updating spellsByName and spellsByID
if not Lib.updaterFrame then
Lib.updaterFrame = CreateFrame("Frame")
end
Lib.updaterFrame:UnregisterAllEvents()
Lib.updaterFrame:RegisterEvent("SPELLS_CHANGED")
local function UpdateSpells()
UpdateBook("spell")
UpdateBook("pet")
end
Lib.updaterFrame:SetScript("OnEvent", UpdateSpells)
UpdateSpells()
--- Improved spell range checking function.
-- @name SpellRange.IsSpellInRange
-- @paramsig spell, unit
-- @param spell Name or spellID of a spell that you wish to check the range of. The spell must be a spell that you have in your spellbook or your pet's spellbook.
-- @param unit UnitID of the spell that you wish to check the range on.
-- @return Exact same returns as http://wowprogramming.com/docs/api/IsSpellInRange
-- @usage
-- -- Check spell range by spell name on unit "target"
-- local SpellRange = LibStub("SpellRange-1.0")
-- local inRange = SpellRange.IsSpellInRange("Stormstrike", "target")
--
-- -- Check spell range by spellID on unit "mouseover"
-- local SpellRange = LibStub("SpellRange-1.0")
-- local inRange = SpellRange.IsSpellInRange(17364, "mouseover")
function Lib.IsSpellInRange(spellInput, unit)
if isNumber[spellInput] then
local spell = spellsByID_spell[spellInput]
if spell then
return IsSpellInRange(spell, "spell", unit)
else
local spell = spellsByID_pet[spellInput]
if spell then
return IsSpellInRange(spell, "pet", unit)
end
end
else
local spellInput = strlowerCache[spellInput]
local spell = spellsByName_spell[spellInput]
if spell then
return IsSpellInRange(spell, "spell", unit)
else
local spell = spellsByName_pet[spellInput]
if spell then
return IsSpellInRange(spell, "pet", unit)
end
end
return IsSpellInRange(spellInput, unit)
end
end
--- Improved SpellHasRange.
-- @name SpellRange.SpellHasRange
-- @paramsig spell
-- @param spell Name or spellID of a spell that you wish to check for a range. The spell must be a spell that you have in your spellbook or your pet's spellbook.
-- @return Exact same returns as http://wowprogramming.com/docs/api/SpellHasRange
-- @usage
-- -- Check if a spell has a range by spell name
-- local SpellRange = LibStub("SpellRange-1.0")
-- local hasRange = SpellRange.SpellHasRange("Stormstrike")
--
-- -- Check if a spell has a range by spellID
-- local SpellRange = LibStub("SpellRange-1.0")
-- local hasRange = SpellRange.SpellHasRange(17364)
function Lib.SpellHasRange(spellInput)
if isNumber[spellInput] then
local spell = spellsByID_spell[spellInput]
if spell then
return SpellHasRange(spell, "spell")
else
local spell = spellsByID_pet[spellInput]
if spell then
return SpellHasRange(spell, "pet")
end
end
else
local spellInput = strlowerCache[spellInput]
local spell = spellsByName_spell[spellInput]
if spell then
return SpellHasRange(spell, "spell")
else
local spell = spellsByName_pet[spellInput]
if spell then
return SpellHasRange(spell, "pet")
end
end
return SpellHasRange(spellInput)
end
end

View File

@ -0,0 +1,3 @@
<Ui>
<Script file="LibSpellRange-1.0.lua"/>
</Ui>

View File

@ -0,0 +1,51 @@
-- $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/addons/libstub/ for more info
-- LibStub is hereby placed in the Public Domain
-- Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
local LibStub = _G[LIBSTUB_MAJOR]
-- Check to see is this version of the stub is obsolete
if not LibStub or LibStub.minor < LIBSTUB_MINOR then
LibStub = LibStub or {libs = {}, minors = {} }
_G[LIBSTUB_MAJOR] = LibStub
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)
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")
local oldminor = self.minors[major]
if oldminor and oldminor >= minor then return nil end
self.minors[major], self.libs[major] = minor, self.libs[major] or {}
return self.libs[major], oldminor
end
-- 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)
if not self.libs[major] and not silent then
error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
end
return self.libs[major], self.minors[major]
end
-- LibStub:IterateLibraries()
--
-- Returns an iterator for the currently registered libraries
function LibStub:IterateLibraries()
return pairs(self.libs)
end
setmetatable(LibStub, { __call = LibStub.GetLibrary })
end

View File

@ -0,0 +1,30 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="LibStub\LibStub.lua"/>
<Script file="CallbackHandler-1.0\CallbackHandler-1.0.lua"/>
<Include file="LibSpellRange-1.0\lib.xml"/>
<Include file="AceAddon-3.0\AceAddon-3.0.xml"/>
<Include file="AceEvent-3.0\AceEvent-3.0.xml"/>
<Include file="AceConfig-3.0\AceConfig-3.0.xml"/>
<Include file="AceConsole-3.0\AceConsole-3.0.xml"/>
<Include file="AceDB-3.0\AceDB-3.0.xml"/>
<Include file="AceLocale-3.0\AceLocale-3.0.xml"/>
<Include file="AceComm-3.0\AceComm-3.0.xml"/>
<Include file="AceSerializer-3.0\AceSerializer-3.0.xml"/>
<Include file="AceTimer-3.0\AceTimer-3.0.xml"/>
<Include file="AceHook-3.0\AceHook-3.0.xml"/>
<Include file="LibSharedMedia-3.0\lib.xml"/>
<Script file="LibSimpleSticky\LibSimpleSticky.lua"/>
<Include file='oUF\oUF.xml'/>
<Include file='oUF_Plugins\oUF_Plugins.xml'/>
<Include file="LibActionButton-1.0\LibActionButton-1.0.xml"/>
<Script file="LibDataBroker\LibDataBroker-1.1.lua"/>
<Script file="LibDualSpec-1.0\LibDualSpec-1.0.lua"/>
<Script file="LibElvUIPlugin-1.0\LibElvUIPlugin-1.0.lua"/>
<Include file="UTF8\UTF8.xml"/>
<Include file="LibItemSearch-1.2\LibItemSearch-1.2.xml"/>
<Include file="LibChatAnims\LibChatAnims.xml"/>
<Include file="LibCompress\lib.xml"/>
<Include file="LibBase64-1.0\lib.xml"/>
<Script file="LibAnim\LibAnim.lua"/>
<Include file="DropDownMenu\DropDownMenu.xml"/>
</Ui>

5
Libraries/UTF8/UTF8.xml Normal file
View File

@ -0,0 +1,5 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="utf8.lua"/>
<Script file="utf8data.lua"/>
</Ui>

318
Libraries/UTF8/utf8.lua Normal file
View File

@ -0,0 +1,318 @@
-- $Id: utf8.lua 179 2009-04-03 18:10:03Z pasta $
--
-- Provides UTF-8 aware string functions implemented in pure lua:
-- * string.utf8len(s)
-- * string.utf8sub(s, i, j)
-- * string.utf8reverse(s)
--
-- If utf8data.lua (containing the lower<->upper case mappings) is loaded, these
-- additional functions are available:
-- * string.utf8upper(s)
-- * string.utf8lower(s)
--
-- All functions behave as their non UTF-8 aware counterparts with the exception
-- that UTF-8 characters are used instead of bytes for all units.
--[[
Copyright (c) 2006-2007, Kyle Smith
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--]]
-- ABNF from RFC 3629
--
-- UTF8-octets = *( UTF8-char )
-- UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
-- UTF8-1 = %x00-7F
-- UTF8-2 = %xC2-DF UTF8-tail
-- UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
-- %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
-- UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
-- %xF4 %x80-8F 2( UTF8-tail )
-- UTF8-tail = %x80-BF
--
local strbyte, strlen, strsub, type = string.byte, string.len, string.sub, type
-- returns the number of bytes used by the UTF-8 character at byte i in s
-- also doubles as a UTF-8 character validator
local function utf8charbytes(s, i)
-- argument defaults
i = i or 1
-- argument checking
if type(s) ~= "string" then
error("bad argument #1 to 'utf8charbytes' (string expected, got ".. type(s).. ")")
end
if type(i) ~= "number" then
error("bad argument #2 to 'utf8charbytes' (number expected, got ".. type(i).. ")")
end
local c = strbyte(s, i)
-- determine bytes needed for character, based on RFC 3629
-- validate byte 1
if c > 0 and c <= 127 then
-- UTF8-1
return 1
elseif c >= 194 and c <= 223 then
-- UTF8-2
local c2 = strbyte(s, i + 1)
if not c2 then
error("UTF-8 string terminated early")
end
-- validate byte 2
if c2 < 128 or c2 > 191 then
error("Invalid UTF-8 character")
end
return 2
elseif c >= 224 and c <= 239 then
-- UTF8-3
local c2 = strbyte(s, i + 1)
local c3 = strbyte(s, i + 2)
if not c2 or not c3 then
error("UTF-8 string terminated early")
end
-- validate byte 2
if c == 224 and (c2 < 160 or c2 > 191) then
error("Invalid UTF-8 character")
elseif c == 237 and (c2 < 128 or c2 > 159) then
error("Invalid UTF-8 character")
elseif c2 < 128 or c2 > 191 then
error("Invalid UTF-8 character")
end
-- validate byte 3
if c3 < 128 or c3 > 191 then
error("Invalid UTF-8 character")
end
return 3
elseif c >= 240 and c <= 244 then
-- UTF8-4
local c2 = strbyte(s, i + 1)
local c3 = strbyte(s, i + 2)
local c4 = strbyte(s, i + 3)
if not c2 or not c3 or not c4 then
error("UTF-8 string terminated early")
end
-- validate byte 2
if c == 240 and (c2 < 144 or c2 > 191) then
error("Invalid UTF-8 character")
elseif c == 244 and (c2 < 128 or c2 > 143) then
error("Invalid UTF-8 character")
elseif c2 < 128 or c2 > 191 then
error("Invalid UTF-8 character")
end
-- validate byte 3
if c3 < 128 or c3 > 191 then
error("Invalid UTF-8 character")
end
-- validate byte 4
if c4 < 128 or c4 > 191 then
error("Invalid UTF-8 character")
end
return 4
else
error("Invalid UTF-8 character")
end
end
-- returns the number of characters in a UTF-8 string
local function utf8len(s)
-- argument checking
if type(s) ~= "string" then
error("bad argument #1 to 'utf8len' (string expected, got ".. type(s).. ")")
end
local pos = 1
local bytes = strlen(s)
local len = 0
while pos <= bytes do
len = len + 1
pos = pos + utf8charbytes(s, pos)
end
return len
end
-- install in the string library
if not string.utf8len then
string.utf8len = utf8len
end
-- functions identically to string.sub except that i and j are UTF-8 characters
-- instead of bytes
local function utf8sub(s, i, j)
-- argument defaults
j = j or -1
-- argument checking
if type(s) ~= "string" then
error("bad argument #1 to 'utf8sub' (string expected, got ".. type(s).. ")")
end
if type(i) ~= "number" then
error("bad argument #2 to 'utf8sub' (number expected, got ".. type(i).. ")")
end
if type(j) ~= "number" then
error("bad argument #3 to 'utf8sub' (number expected, got ".. type(j).. ")")
end
local pos = 1
local bytes = strlen(s)
local len = 0
-- only set l if i or j is negative
local l = (i >= 0 and j >= 0) or utf8len(s)
local startChar = (i >= 0) and i or l + i + 1
local endChar = (j >= 0) and j or l + j + 1
-- can't have start before end!
if startChar > endChar then
return ""
end
-- byte offsets to pass to string.sub
local startByte, endByte = 1, bytes
while pos <= bytes do
len = len + 1
if len == startChar then
startByte = pos
end
pos = pos + utf8charbytes(s, pos)
if len == endChar then
endByte = pos - 1
break
end
end
return strsub(s, startByte, endByte)
end
-- install in the string library
if not string.utf8sub then
string.utf8sub = utf8sub
end
-- replace UTF-8 characters based on a mapping table
local function utf8replace(s, mapping)
-- argument checking
if type(s) ~= "string" then
error("bad argument #1 to 'utf8replace' (string expected, got ".. type(s).. ")")
end
if type(mapping) ~= "table" then
error("bad argument #2 to 'utf8replace' (table expected, got ".. type(mapping).. ")")
end
local pos = 1
local bytes = strlen(s)
local charbytes
local newstr = ""
while pos <= bytes do
charbytes = utf8charbytes(s, pos)
local c = strsub(s, pos, pos + charbytes - 1)
newstr = newstr .. (mapping[c] or c)
pos = pos + charbytes
end
return newstr
end
-- identical to string.upper except it knows about unicode simple case conversions
local function utf8upper(s)
return utf8replace(s, utf8_lc_uc)
end
-- install in the string library
if not string.utf8upper and utf8_lc_uc then
string.utf8upper = utf8upper
end
-- identical to string.lower except it knows about unicode simple case conversions
local function utf8lower(s)
return utf8replace(s, utf8_uc_lc)
end
-- install in the string library
if not string.utf8lower and utf8_uc_lc then
string.utf8lower = utf8lower
end
-- identical to string.reverse except that it supports UTF-8
local function utf8reverse(s)
-- argument checking
if type(s) ~= "string" then
error("bad argument #1 to 'utf8reverse' (string expected, got ".. type(s).. ")")
end
local bytes = strlen(s)
local pos = bytes
local charbytes
local newstr = ""
local c
while pos > 0 do
c = strbyte(s, pos)
while c >= 128 and c <= 191 do
pos = pos - 1
c = strbyte(pos)
end
charbytes = utf8charbytes(s, pos)
newstr = newstr .. strsub(s, pos, pos + charbytes - 1)
pos = pos - 1
end
return newstr
end
-- install in the string library
if not string.utf8reverse then
string.utf8reverse = utf8reverse
end

1860
Libraries/UTF8/utf8data.lua Normal file

File diff suppressed because it is too large Load Diff

22
Libraries/oUF/LICENSE Normal file
View File

@ -0,0 +1,22 @@
Copyright (c) 2006-2014 Trond A Ekseth <troeks@gmail.com>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

102
Libraries/oUF/blizzard.lua Normal file
View File

@ -0,0 +1,102 @@
local parent, ns = ...
local oUF = ns.oUF
local hiddenParent = CreateFrame("Frame")
hiddenParent:Hide()
local HandleFrame = function(baseName)
local frame
if(type(baseName) == 'string') then
frame = _G[baseName]
else
frame = baseName
end
if(frame) then
frame:UnregisterAllEvents()
frame:Hide()
-- Keep frame hidden without causing taint
frame:SetParent(hiddenParent)
local health = frame.healthbar
if(health) then
health:UnregisterAllEvents()
end
local power = frame.manabar
if(power) then
power:UnregisterAllEvents()
end
local spell = frame.spellbar
if(spell) then
spell:UnregisterAllEvents()
end
local altpowerbar = frame.powerBarAlt
if(altpowerbar) then
altpowerbar:UnregisterAllEvents()
end
end
end
function oUF:DisableBlizzard(unit)
if(not unit) then return end
if(unit == 'player') then
HandleFrame(PlayerFrame)
-- For the damn vehicle support:
PlayerFrame:RegisterEvent('PLAYER_ENTERING_WORLD')
PlayerFrame:RegisterEvent('UNIT_ENTERING_VEHICLE')
PlayerFrame:RegisterEvent('UNIT_ENTERED_VEHICLE')
PlayerFrame:RegisterEvent('UNIT_EXITING_VEHICLE')
PlayerFrame:RegisterEvent('UNIT_EXITED_VEHICLE')
-- User placed frames don't animate
PlayerFrame:SetUserPlaced(true)
PlayerFrame:SetDontSavePosition(true)
elseif(unit == 'pet') then
HandleFrame(PetFrame)
elseif(unit == 'target') then
HandleFrame(TargetFrame)
HandleFrame(ComboFrame)
elseif(unit == 'focus') then
HandleFrame(FocusFrame)
HandleFrame(TargetofFocusFrame)
elseif(unit == 'targettarget') then
HandleFrame(TargetFrameToT)
elseif(unit:match'(boss)%d?$' == 'boss') then
local id = unit:match'boss(%d)'
if(id) then
HandleFrame('Boss' .. id .. 'TargetFrame')
else
for i=1, 5 do
HandleFrame(('Boss%dTargetFrame'):format(i))
end
end
elseif(unit:match'(party)%d?$' == 'party') then
local id = unit:match'party(%d)'
if(id) then
HandleFrame('PartyMemberFrame' .. id)
else
for i=1, 4 do
HandleFrame(('PartyMemberFrame%d'):format(i))
end
end
elseif(unit:match'(arena)%d?$' == 'arena') then
local id = unit:match'arena(%d)'
if(id) then
HandleFrame('ArenaEnemyFrame' .. id)
else
for i=1, 5 do
HandleFrame(('ArenaEnemyFrame%d'):format(i))
end
end
-- Blizzard_ArenaUI should not be loaded
Arena_LoadUI = function() end
SetCVar('showArenaEnemyFrames', '0', 'SHOW_ARENA_ENEMY_FRAMES_TEXT')
end
end

168
Libraries/oUF/colors.lua Normal file
View File

@ -0,0 +1,168 @@
local parent, ns = ...
local oUF = ns.oUF
local Private = oUF.Private
local frame_metatable = Private.frame_metatable
local colors = {
smooth = {
1, 0, 0,
1, 1, 0,
0, 1, 0
},
disconnected = {.6, .6, .6},
tapped = {.6,.6,.6},
class = {},
reaction = {},
}
-- We do this because people edit the vars directly, and changing the default
-- globals makes SPICE FLOW!
local customClassColors = function()
if(CUSTOM_CLASS_COLORS) then
local updateColors = function()
for eclass, color in next, CUSTOM_CLASS_COLORS do
colors.class[eclass] = {color.r, color.g, color.b}
end
for _, obj in next, oUF.objects do
obj:UpdateAllElements("CUSTOM_CLASS_COLORS")
end
end
updateColors()
CUSTOM_CLASS_COLORS:RegisterCallback(updateColors)
return true
end
end
if not customClassColors() then
for eclass, color in next, RAID_CLASS_COLORS do
colors.class[eclass] = {color.r, color.g, color.b}
end
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function()
if customClassColors() then
f:UnregisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", nil)
end
end)
end
for eclass, color in next, FACTION_BAR_COLORS do
colors.reaction[eclass] = {color.r, color.g, color.b}
end
local function ColorsAndPercent(a, b, ...)
if a <= 0 or b == 0 then
return nil, ...
elseif a >= b then
return nil, select(select('#', ...) - 2, ...)
end
local num = select('#', ...) / 3
local segment, relperc = math.modf((a/b)*(num-1))
return relperc, select((segment*3)+1, ...)
end
-- http://www.wowwiki.com/ColorGradient
local RGBColorGradient = function(...)
local relperc, r1, g1, b1, r2, g2, b2 = ColorsAndPercent(...)
if relperc then
return r1 + (r2-r1)*relperc, g1 + (g2-g1)*relperc, b1 + (b2-b1)*relperc
else
return r1, g1, b1
end
end
-- HCY functions are based on http://www.chilliant.com/rgb2hsv.html
local function GetY(r, g, b)
return 0.299 * r + 0.587 * g + 0.114 * b
end
local function RGBToHCY(r, g, b)
local min, max = min(r, g, b), max(r, g, b)
local chroma = max - min
local hue
if chroma > 0 then
if r == max then
hue = ((g - b) / chroma) % 6
elseif g == max then
hue = (b - r) / chroma + 2
elseif b == max then
hue = (r - g) / chroma + 4
end
hue = hue / 6
end
return hue, chroma, GetY(r, g, b)
end
local abs = math.abs
local function HCYtoRGB(hue, chroma, luma)
local r, g, b = 0, 0, 0
if hue and luma > 0 then
local h2 = hue * 6
local x = chroma * (1 - abs(h2 % 2 - 1))
if h2 < 1 then
r, g, b = chroma, x, 0
elseif h2 < 2 then
r, g, b = x, chroma, 0
elseif h2 < 3 then
r, g, b = 0, chroma, x
elseif h2 < 4 then
r, g, b = 0, x, chroma
elseif h2 < 5 then
r, g, b = x, 0, chroma
else
r, g, b = chroma, 0, x
end
local y = GetY(r, g, b)
if luma < y then
chroma = chroma * (luma / y)
elseif y < 1 then
chroma = chroma * (1 - luma) / (1 - y)
end
r = (r - y) * chroma + luma
g = (g - y) * chroma + luma
b = (b - y) * chroma + luma
end
return r, g, b
end
local HCYColorGradient = function(...)
local relperc, r1, g1, b1, r2, g2, b2 = ColorsAndPercent(...)
if not relperc then return r1, g1, b1 end
local h1, c1, y1 = RGBToHCY(r1, g1, b1)
local h2, c2, y2 = RGBToHCY(r2, g2, b2)
local c = c1 + (c2-c1) * relperc
local y = y1 + (y2-y1) * relperc
if h1 and h2 then
local dh = h2 - h1
if dh < -0.5 then
dh = dh + 1
elseif dh > 0.5 then
dh = dh - 1
end
return HCYtoRGB((h1 + dh * relperc) % 1, c, y)
else
return HCYtoRGB(h1 or h2, c, y)
end
end
local ColorGradient = function(...)
return (oUF.useHCYColorGradient and HCYColorGradient or RGBColorGradient)(...)
end
Private.colors = colors
oUF.colors = colors
oUF.ColorGradient = ColorGradient
oUF.RGBColorGradient = RGBColorGradient
oUF.HCYColorGradient = HCYColorGradient
oUF.useHCYColorGradient = false
frame_metatable.__index.colors = colors
frame_metatable.__index.ColorGradient = ColorGradient

View File

@ -0,0 +1,194 @@
--[[ Element: Additional Power Bar
Handles updating and visibility of a status bar displaying the player's
alternate/additional power, such as Mana for Balance druids.
Widget
AdditionalPower - A StatusBar to represent current caster mana.
Sub-Widgets
.bg - A Texture which functions as a background. It will inherit the color of
the main StatusBar.
Notes
The default StatusBar texture will be applied if the UI widget doesn't have a
status bar texture or color defined.
Options
.colorClass - Use `self.colors.class[class]` to color the bar.
.colorSmooth - Use `self.colors.smooth` to color the bar with a smooth
gradient based on the players current mana percentage.
.colorPower - Use `self.colors.power[token]` to color the bar. This will
always use MANA as token.
Sub-Widget Options
.multiplier - Defines a multiplier, which is used to tint the background based
on the main widgets R, G and B values. Defaults to 1 if not
present.
Examples
-- Position and size
local AdditionalPower = CreateFrame("StatusBar", nil, self)
AdditionalPower:SetSize(20, 20)
AdditionalPower:SetPoint('TOP')
AdditionalPower:SetPoint('LEFT')
AdditionalPower:SetPoint('RIGHT')
-- Add a background
local Background = AdditionalPower:CreateTexture(nil, 'BACKGROUND')
Background:SetAllPoints(AdditionalPower)
Background:SetTexture(1, 1, 1, .5)
-- Register it with oUF
self.AdditionalPower = AdditionalPower
self.AdditionalPower.bg = Background
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local _, ns = ...
local oUF = ns.oUF
local playerClass = select(2, UnitClass('player'))
local ADDITIONAL_POWER_BAR_NAME = ADDITIONAL_POWER_BAR_NAME
local ADDITIONAL_POWER_BAR_INDEX = ADDITIONAL_POWER_BAR_INDEX
local function Update(self, event, unit, powertype)
if(unit ~= 'player' or (powertype and powertype ~= ADDITIONAL_POWER_BAR_NAME)) then return end
local element = self.AdditionalPower
if(element.PreUpdate) then element:PreUpdate(unit) end
local cur = UnitPower('player', ADDITIONAL_POWER_BAR_INDEX)
local max = UnitPowerMax('player', ADDITIONAL_POWER_BAR_INDEX)
element:SetMinMaxValues(0, max)
element:SetValue(cur)
local r, g, b, t
if(element.colorClass) then
t = self.colors.class[playerClass]
elseif(element.colorSmooth) then
r, g, b = self.ColorGradient(cur, max, unpack(element.smoothGradient or self.colors.smooth))
elseif(element.colorPower) then
t = self.colors.power[ADDITIONAL_POWER_BAR_NAME]
end
if(t) then
r, g, b = t[1], t[2], t[3]
end
if(b) then
element:SetStatusBarColor(r, g, b)
local bg = element.bg
if(bg) then
local mu = bg.multiplier or 1
bg:SetVertexColor(r * mu, g * mu, b * mu)
end
end
if(element.PostUpdate) then
return element:PostUpdate(unit, cur, max, event)
end
end
local function Path(self, ...)
return (self.AdditionalPower.Override or Update) (self, ...)
end
local function ElementEnable(self)
self:RegisterEvent('UNIT_POWER_FREQUENT', Path)
self:RegisterEvent('UNIT_DISPLAYPOWER', Path)
self:RegisterEvent('UNIT_MAXPOWER', Path)
self.AdditionalPower:Show()
if self.AdditionalPower.PostUpdateVisibility then
self.AdditionalPower:PostUpdateVisibility(true, not self.AdditionalPower.isEnabled)
end
self.AdditionalPower.isEnabled = true
Path(self, 'ElementEnable', 'player', ADDITIONAL_POWER_BAR_NAME)
end
local function ElementDisable(self)
self:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
self:UnregisterEvent('UNIT_DISPLAYPOWER', Path)
self:UnregisterEvent('UNIT_MAXPOWER', Path)
self.AdditionalPower:Hide()
if self.AdditionalPower.PostUpdateVisibility then
self.AdditionalPower:PostUpdateVisibility(false, self.AdditionalPower.isEnabled)
end
self.AdditionalPower.isEnabled = nil
Path(self, 'ElementDisable', 'player', ADDITIONAL_POWER_BAR_NAME)
end
local function Visibility(self, event, unit)
local shouldEnable
if(not UnitHasVehicleUI('player')) then
if(UnitPowerMax(unit, ADDITIONAL_POWER_BAR_INDEX) ~= 0) then
if(ALT_MANA_BAR_PAIR_DISPLAY_INFO[playerClass]) then
local powerType = UnitPowerType(unit)
shouldEnable = ALT_MANA_BAR_PAIR_DISPLAY_INFO[playerClass][powerType]
end
end
end
if(shouldEnable) then
ElementEnable(self)
else
ElementDisable(self)
end
end
local VisibilityPath = function(self, ...)
return (self.AdditionalPower.OverrideVisibility or Visibility) (self, ...)
end
local function ForceUpdate(element)
return VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local Enable = function(self, unit)
local element = self.AdditionalPower
if(element and unit == 'player') then
element.__owner = self
element.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
if(element:IsObjectType'StatusBar' and not element:GetStatusBarTexture()) then
element:SetStatusBarTexture[[Interface\TargetingFrame\UI-StatusBar]]
end
return true
end
end
local Disable = function(self)
local element = self.AdditionalPower
if(element) then
ElementDisable(self)
self:UnregisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
end
end
oUF:AddElement('AdditionalPower', VisibilityPath, Enable, Disable)

View File

@ -0,0 +1,203 @@
--[[ Element: Alternative Power Bar
Handles visibility and updating of the alternative power bar.
This bar is used to display encounter/quest related power information, such as
the number of hour glass uses left on the end boss in End Time.
Widget
AltPowerBar - A StatusBar to represent alternative power.
Options
.colorTexture - Use the vertex color values returned by
UnitAlternatePowerTextureInfo to color the bar.
Notes
OnEnter and OnLeave handlers to display a tooltip will be set on the widget if
it is mouse enabled.
Examples
-- Position and size
local AltPowerBar = CreateFrame('StatusBar', nil, self)
AltPowerBar:SetHeight(20)
AltPowerBar:SetPoint('BOTTOM')
AltPowerBar:SetPoint('LEFT')
AltPowerBar:SetPoint('RIGHT')
-- Register with oUF
self.AltPowerBar = AltPowerBar
Callbacks
]]
local parent, ns = ...
local oUF = ns.oUF
local ALTERNATE_POWER_INDEX = ALTERNATE_POWER_INDEX
--[[ :UpdateTooltip()
The function called when the widget is hovered. Used to populate the tooltip.
Arguments
self - The AltPowerBar element.
]]
local UpdateTooltip = function(self)
GameTooltip:SetText(self.powerName, 1, 1, 1)
GameTooltip:AddLine(self.powerTooltip, nil, nil, nil, 1)
GameTooltip:Show()
end
local OnEnter = function(self)
if(not self:IsVisible()) then return end
GameTooltip_SetDefaultAnchor(GameTooltip, self)
self:UpdateTooltip()
end
local OnLeave = function()
GameTooltip:Hide()
end
local UpdatePower = function(self, event, unit, powerType)
if(self.unit ~= unit or powerType ~= 'ALTERNATE') or not unit then return end
local altpowerbar = self.AltPowerBar
--[[ :PreUpdate()
Called before the element has been updated.
Arguments
self - The AltPowerBar element.
]]
if(altpowerbar.PreUpdate) then
altpowerbar:PreUpdate()
end
local _, r, g, b
if(altpowerbar.colorTexture) then
_, r, g, b = UnitAlternatePowerTextureInfo(unit, 2)
end
local cur = UnitPower(unit, ALTERNATE_POWER_INDEX)
local max = UnitPowerMax(unit, ALTERNATE_POWER_INDEX)
local barType, min, _, _, _, _, _, _, _, _, powerName, powerTooltip = UnitAlternatePowerInfo(unit)
altpowerbar.barType = barType
altpowerbar.powerName = powerName
altpowerbar.powerTooltip = powerTooltip
altpowerbar:SetMinMaxValues(min, max)
altpowerbar:SetValue(math.min(math.max(cur, min), max))
if(b) then
altpowerbar:SetStatusBarColor(r, g, b)
end
--[[ :PostUpdate(min, cur, max)
Called after the element has been updated.
Arguments
self - The AltPowerBar element.
min - The minimum possible power value for the active type.
cur - The current power value.
max - The maximum possible power value for the active type.
]]
if(altpowerbar.PostUpdate) then
return altpowerbar:PostUpdate(min, cur, max)
end
end
--[[ Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local Path = function(self, ...)
return (self.AltPowerBar.Override or UpdatePower)(self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit, 'ALTERNATE')
end
local Toggler = function(self, event, unit)
if(unit ~= self.unit) or not unit then return end
local altpowerbar = self.AltPowerBar
local barType, _, _, _, _, hideFromOthers, showOnRaid = UnitAlternatePowerInfo(unit)
if(barType and (showOnRaid and (UnitInParty(unit) or UnitInRaid(unit)) or not hideFromOthers or unit == 'player' or self.realUnit == 'player')) then
self:RegisterEvent('UNIT_POWER', Path)
self:RegisterEvent('UNIT_MAXPOWER', Path)
ForceUpdate(altpowerbar)
altpowerbar:Show()
else
self:UnregisterEvent('UNIT_POWER', Path)
self:UnregisterEvent('UNIT_MAXPOWER', Path)
altpowerbar:Hide()
end
end
local Enable = function(self, unit)
local altpowerbar = self.AltPowerBar
if(altpowerbar) then
altpowerbar.__owner = self
altpowerbar.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_POWER_BAR_SHOW', Toggler)
self:RegisterEvent('UNIT_POWER_BAR_HIDE', Toggler)
altpowerbar:Hide()
if(altpowerbar:IsMouseEnabled()) then
if(not altpowerbar:GetScript('OnEnter')) then
altpowerbar:SetScript('OnEnter', OnEnter)
end
if(not altpowerbar:GetScript('OnLeave')) then
altpowerbar:SetScript('OnLeave', OnLeave)
end
if(not altpowerbar.UpdateTooltip) then
altpowerbar.UpdateTooltip = UpdateTooltip
end
end
if(unit == 'player') then
PlayerPowerBarAlt:UnregisterEvent'UNIT_POWER_BAR_SHOW'
PlayerPowerBarAlt:UnregisterEvent'UNIT_POWER_BAR_HIDE'
PlayerPowerBarAlt:UnregisterEvent'PLAYER_ENTERING_WORLD'
end
return true
end
end
local Disable = function(self, unit)
local altpowerbar = self.AltPowerBar
if(altpowerbar) then
altpowerbar:Hide()
self:UnregisterEvent('UNIT_POWER_BAR_SHOW', Toggler)
self:UnregisterEvent('UNIT_POWER_BAR_HIDE', Toggler)
if(unit == 'player') then
PlayerPowerBarAlt:RegisterEvent'UNIT_POWER_BAR_SHOW'
PlayerPowerBarAlt:RegisterEvent'UNIT_POWER_BAR_HIDE'
PlayerPowerBarAlt:RegisterEvent'PLAYER_ENTERING_WORLD'
end
end
end
oUF:AddElement('AltPowerBar', Toggler, Enable, Disable)

View File

@ -0,0 +1,112 @@
--[[ Element: Assistant Icon
Toggles visibility of `self.Assistant` based on the units raid officer status.
Widget
Assistant - Any UI widget.
Notes
The default assistant icon will be applied if the UI widget is a texture and
doesn't have a texture or color defined.
Examples
-- Position and size
local Assistant = self:CreateTexture(nil, "OVERLAY")
Assistant:SetSize(16, 16)
Assistant:SetPoint('TOP', self)
-- Register it with oUF
self.Assistant = Assistant
Hooks and Callbacks
]]
local parent, ns = ...
local oUF = ns.oUF
local Update = function(self, event)
if not self.unit then return; end
local assistant = self.Assistant
--[[ :PreUpdate()
Called before the element has been updated.
Arguments
self - The Assistant element.
]]
if(assistant.PreUpdate) then
assistant:PreUpdate()
end
local unit = self.unit
local isAssistant = UnitInRaid(unit) and UnitIsGroupAssistant(unit) and not UnitIsGroupLeader(unit)
if(isAssistant) then
assistant:Show()
else
assistant:Hide()
end
--[[ :PostUpdate(isAssistant)
Called after the element has been updated.
Arguments
self - The Assistant element.
isAssistant - A boolean holding whether the unit is a raid officer or not.
]]
if(assistant.PostUpdate) then
return assistant:PostUpdate(isAssistant)
end
end
local Path = function(self, ...)
--[[ :Override(self, event, ...)
Used to completely override the internal update function. Removing the
table key entry will make the element fall-back to its internal function
again.
Arguments
self - The Assistant element.
event - The UI event that fired.
... - A vararg with the arguments that accompany the event.
]]
return (self.Assistant.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate')
end
local Enable = function(self)
local assistant = self.Assistant
if(assistant) then
self:RegisterEvent("GROUP_ROSTER_UPDATE", Path, true)
if(assistant:IsObjectType"Texture" and not assistant:GetTexture()) then
assistant:SetTexture[[Interface\GroupFrame\UI-Group-AssistantIcon]]
end
assistant.__owner = self
assistant.ForceUpdate = ForceUpdate
return true
end
end
local Disable = function(self)
local assistant = self.Assistant
if(assistant) then
self:UnregisterEvent("GROUP_ROSTER_UPDATE", Path)
assistant:Hide()
end
end
oUF:AddElement('Assistant', Path, Enable, Disable)

View File

@ -0,0 +1,525 @@
--[[ Element: Auras
Handles creation and updating of aura icons.
Widget
Auras - A Frame to hold icons representing both buffs and debuffs.
Buffs - A Frame to hold icons representing buffs.
Debuffs - A Frame to hold icons representing debuffs.
Options
.disableCooldown - Disables the cooldown spiral. Defaults to false.
.size - Aura icon size. Defaults to 16.
.onlyShowPlayer - Only show auras created by player/vehicle.
.showStealableBuffs - Display the stealable texture on buffs that can be
stolen.
.spacing - Spacing between each icon. Defaults to 0.
.['spacing-x'] - Horizontal spacing between each icon. Takes priority over
`spacing`.
.['spacing-y'] - Vertical spacing between each icon. Takes priority over
`spacing`.
.['growth-x'] - Horizontal growth direction. Defaults to RIGHT.
.['growth-y'] - Vertical growth direction. Defaults to UP.
.initialAnchor - Anchor point for the icons. Defaults to BOTTOMLEFT.
.filter - Custom filter list for auras to display. Defaults to
HELPFUL on buffs and HARMFUL on debuffs.
Options Auras
.numBuffs - The maximum number of buffs to display. Defaults to 32.
.numDebuffs - The maximum number of debuffs to display. Defaults to 40.
.gap - Controls the creation of an invisible icon between buffs and
debuffs. Defaults to false.
.buffFilter - Custom filter list for buffs to display. Takes priority over
`filter`.
.debuffFilter - Custom filter list for debuffs to display. Takes priority over
`filter`.
Options Buffs
.num - Number of buffs to display. Defaults to 32.
Options Debuffs
.num - Number of debuffs to display. Defaults to 40.
Examples
-- Position and size
local Buffs = CreateFrame("Frame", nil, self)
Buffs:SetPoint("RIGHT", self, "LEFT")
Buffs:SetSize(16 * 2, 16 * 16)
-- Register with oUF
self.Buffs = Buffs
Hooks and Callbacks
]]
local parent, ns = ...
local oUF = ns.oUF
local VISIBLE = 1
local HIDDEN = 0
local UpdateTooltip = function(self)
GameTooltip:SetUnitAura(self:GetParent().__owner.unit, self:GetID(), self.filter)
end
local OnEnter = function(self)
if(not self:IsVisible()) then return end
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
self:UpdateTooltip()
end
local OnLeave = function()
GameTooltip:Hide()
end
local createAuraIcon = function(icons, index)
local button = CreateFrame("Button", icons:GetDebugName().."Button"..index, icons)
button:RegisterForClicks'RightButtonUp'
local cd = CreateFrame("Cooldown", "$parentCooldown", button, "CooldownFrameTemplate")
cd:SetAllPoints(button)
local icon = button:CreateTexture(nil, "BORDER")
icon:SetAllPoints(button)
local count = button:CreateFontString(nil, "OVERLAY")
count:SetFontObject(NumberFontNormal)
count:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -1, 0)
local overlay = button:CreateTexture(nil, "OVERLAY")
overlay:SetTexture"Interface\\Buttons\\UI-Debuff-Overlays"
overlay:SetAllPoints(button)
overlay:SetTexCoord(.296875, .5703125, 0, .515625)
button.overlay = overlay
local stealable = button:CreateTexture(nil, 'OVERLAY')
stealable:SetTexture[[Interface\TargetingFrame\UI-TargetingFrame-Stealable]]
stealable:SetPoint('TOPLEFT', -3, 3)
stealable:SetPoint('BOTTOMRIGHT', 3, -3)
stealable:SetBlendMode'ADD'
button.stealable = stealable
button.UpdateTooltip = UpdateTooltip
button:SetScript("OnEnter", OnEnter)
button:SetScript("OnLeave", OnLeave)
button.icon = icon
button.count = count
button.cd = cd
--[[ :PostCreateIcon(button)
Callback which is called after a new aura icon button has been created.
Arguments
button - The newly created aura icon button.
]]
if(icons.PostCreateIcon) then icons:PostCreateIcon(button) end
return button
end
local customFilter = function(icons, unit, icon, name)
if((icons.onlyShowPlayer and icon.isPlayer) or (not icons.onlyShowPlayer and name)) then
return true
end
end
local updateIcon = function(unit, icons, index, offset, filter, isDebuff, visible)
local name, rank, texture, count, dispelType, duration, expiration, caster, isStealable,
nameplateShowSelf, spellID, canApply, isBossDebuff, casterIsPlayer, nameplateShowAll,
timeMod, effect1, effect2, effect3 = UnitAura(unit, index, filter)
if icons.forceShow then
spellID = 47540
name, rank, texture = GetSpellInfo(spellID)
count, dispelType, duration, expiration, caster, isStealable, nameplateShowSelf, canApplyAura, isBossDebuff = 5, 'Magic', 0, 60, 'player', nil, nil, nil, nil
end
if(name) then
local n = visible + offset + 1
local icon = icons[n]
if(not icon) then
--[[ :CreateIcon(index)
A function which creates the aura icon for a given index.
Arguments
index - The offset the icon should be created at.
Returns
A button used to represent aura icons.
]]
local prev = icons.createdIcons
icon = (icons.CreateIcon or createAuraIcon) (icons, n)
-- XXX: Update the counters if the layout doesn't.
if(prev == icons.createdIcons) then
table.insert(icons, icon)
icons.createdIcons = icons.createdIcons + 1
end
end
local isPlayer
if(caster == 'player' or caster == 'vehicle') then
isPlayer = true
end
icon.owner = caster
icon.filter = filter
icon.isDebuff = isDebuff
icon.isPlayer = isPlayer
--[[ :CustomFilter(unit, icon, ...)
Defines a custom filter which controls if the aura icon should be shown
or not.
Arguments
self - The widget that holds the aura icon.
unit - The unit that has the aura.
icon - The button displaying the aura.
... - The return values from
[UnitAura](http://wowprogramming.com/docs/api/UnitAura).
Returns
A boolean value telling the aura element if it should be show the icon
or not.
]]
local show = true
if not icons.forceShow then
show = (icons.CustomFilter or customFilter) (icons, unit, icon, name, rank, texture,
count, dispelType, duration, expiration, caster, isStealable, nameplateShowSelf, spellID,
canApply, isBossDebuff, casterIsPlayer, nameplateShowAll,timeMod, effect1, effect2, effect3)
end
if(show) then
-- We might want to consider delaying the creation of an actual cooldown
-- object to this point, but I think that will just make things needlessly
-- complicated.
local cd = icon.cd
if(cd and not icons.disableCooldown) then
if(duration and duration > 0) then
cd:SetCooldown(expiration - duration, duration)
cd:Show()
else
cd:Hide()
end
end
if((isDebuff and icons.showDebuffType) or (not isDebuff and icons.showBuffType) or icons.showType) then
local color = DebuffTypeColor[dispelType] or DebuffTypeColor.none
icon.overlay:SetVertexColor(color.r, color.g, color.b)
icon.overlay:Show()
else
icon.overlay:Hide()
end
local stealable = not isDebuff and isStealable
if(stealable and icons.showStealableBuffs and not UnitIsUnit('player', unit)) then
icon.stealable:Show()
else
icon.stealable:Hide()
end
icon.icon:SetTexture(texture)
icon.count:SetText((count > 1 and count))
local size = icons.size or 16
icon:SetSize(size, size)
icon:EnableMouse(true)
icon:SetID(index)
icon:Show()
--[[ :PostUpdateIcon(unit, icon, index, offest)
Callback which is called after the aura icon was updated.
Arguments
self - The widget that holds the aura icon.
unit - The unit that has the aura.
icon - The button that was updated.
index - The index of the aura.
offset - The offset the button was created at.
]]
if(icons.PostUpdateIcon) then
icons:PostUpdateIcon(unit, icon, index, n)
end
return VISIBLE
else
return HIDDEN
end
end
end
--[[ :SetPosition(from, to)
Function used to (re-)anchor aura icons. This function is only called when
new aura icons have been created or if :PreSetPosition is defined.
Arguments
self - The widget that holds the aura icons.
from - The aura icon before the new aura icon.
to - The current number of created icons.
]]
local SetPosition = function(icons, from, to)
local sizex = (icons.size or 16) + (icons['spacing-x'] or icons.spacing or 0)
local sizey = (icons.size or 16) + (icons['spacing-y'] or icons.spacing or 0)
local anchor = icons.initialAnchor or "BOTTOMLEFT"
local growthx = (icons["growth-x"] == "LEFT" and -1) or 1
local growthy = (icons["growth-y"] == "DOWN" and -1) or 1
local cols = math.floor(icons:GetWidth() / sizex + .5)
for i = from, to do
local button = icons[i]
-- Bail out if the to range is out of scope.
if(not button) then break end
local col = (i - 1) % cols
local row = math.floor((i - 1) / cols)
button:ClearAllPoints()
button:SetPoint(anchor, icons, anchor, col * sizex * growthx, row * sizey * growthy)
end
end
local filterIcons = function(unit, icons, filter, limit, isDebuff, offset, dontHide)
if(not offset) then offset = 0 end
local index = 1
local visible = 0
local hidden = 0
while(visible < limit) do
local result = updateIcon(unit, icons, index, offset, filter, isDebuff, visible)
if(not result) then
break
elseif(result == VISIBLE) then
visible = visible + 1
elseif(result == HIDDEN) then
hidden = hidden + 1
end
index = index + 1
end
if(not dontHide) then
for i = visible + offset + 1, #icons do
icons[i]:Hide()
end
end
return visible, hidden
end
local UpdateAuras = function(self, event, unit)
if(self.unit ~= unit) then return end
local auras = self.Auras
if(auras) then
if(auras.PreUpdate) then auras:PreUpdate(unit) end
local numBuffs = auras.numBuffs or 32
local numDebuffs = auras.numDebuffs or 40
local max = numBuffs + numDebuffs
local visibleBuffs, hiddenBuffs = filterIcons(unit, auras, auras.buffFilter or auras.filter or 'HELPFUL', numBuffs, nil, 0, true)
local hasGap
if(visibleBuffs ~= 0 and auras.gap) then
hasGap = true
visibleBuffs = visibleBuffs + 1
local icon = auras[visibleBuffs]
if(not icon) then
local prev = auras.createdIcons
icon = (auras.CreateIcon or createAuraIcon) (auras, visibleBuffs)
-- XXX: Update the counters if the layout doesn't.
if(prev == auras.createdIcons) then
table.insert(auras, icon)
auras.createdIcons = auras.createdIcons + 1
end
end
-- Prevent the icon from displaying anything.
if(icon.cd) then icon.cd:Hide() end
icon:EnableMouse(false)
icon.icon:SetTexture()
icon.overlay:Hide()
icon.stealable:Hide()
icon.count:SetText()
icon:Show()
--[[ :PostUpdateGapIcon(unit, icon, visibleBuffs)
Callback which is called after an invisible aura icon has been
created. This is only used by Auras when the `gap` option is enabled.
Arguments
self - The widget that holds the aura icon.
unit - The unit that has the aura icon.
icon - The invisible aura icon / gap.
visibleBuffs - The number of currently visible buffs.
]]
if(auras.PostUpdateGapIcon) then
auras:PostUpdateGapIcon(unit, icon, visibleBuffs)
end
end
local visibleDebuffs, hiddenDebuffs = filterIcons(unit, auras, auras.debuffFilter or auras.filter or 'HARMFUL', numDebuffs, true, visibleBuffs)
auras.visibleDebuffs = visibleDebuffs
if(hasGap and visibleDebuffs == 0) then
auras[visibleBuffs]:Hide()
visibleBuffs = visibleBuffs - 1
end
auras.visibleBuffs = visibleBuffs
auras.visibleAuras = auras.visibleBuffs + auras.visibleDebuffs
local fromRange, toRange
if(auras.PreSetPosition) then
fromRange, toRange = auras:PreSetPosition(max)
end
if(fromRange or auras.createdIcons > auras.anchoredIcons) then
(auras.SetPosition or SetPosition) (auras, fromRange or auras.anchoredIcons + 1, toRange or auras.createdIcons)
auras.anchoredIcons = auras.createdIcons
end
if(auras.PostUpdate) then auras:PostUpdate(unit) end
end
local buffs = self.Buffs
if(buffs) then
if(buffs.PreUpdate) then buffs:PreUpdate(unit) end
local numBuffs = buffs.num or 32
local visibleBuffs, hiddenBuffs = filterIcons(unit, buffs, buffs.filter or 'HELPFUL', numBuffs)
buffs.visibleBuffs = visibleBuffs
local fromRange, toRange
if(buffs.PreSetPosition) then
fromRange, toRange = buffs:PreSetPosition(numBuffs)
end
if(fromRange or buffs.createdIcons > buffs.anchoredIcons) then
(buffs.SetPosition or SetPosition) (buffs, fromRange or buffs.anchoredIcons + 1, toRange or buffs.createdIcons)
buffs.anchoredIcons = buffs.createdIcons
end
if(buffs.PostUpdate) then buffs:PostUpdate(unit) end
end
local debuffs = self.Debuffs
if(debuffs) then
if(debuffs.PreUpdate) then debuffs:PreUpdate(unit) end
local numDebuffs = debuffs.num or 40
local visibleDebuffs, hiddenDebuffs = filterIcons(unit, debuffs, debuffs.filter or 'HARMFUL', numDebuffs, true)
debuffs.visibleDebuffs = visibleDebuffs
local fromRange, toRange
if(debuffs.PreSetPosition) then
fromRange, toRange = debuffs:PreSetPosition(numDebuffs)
end
if(fromRange or debuffs.createdIcons > debuffs.anchoredIcons) then
(debuffs.SetPosition or SetPosition) (debuffs, fromRange or debuffs.anchoredIcons + 1, toRange or debuffs.createdIcons)
debuffs.anchoredIcons = debuffs.createdIcons
end
if(debuffs.PostUpdate) then debuffs:PostUpdate(unit) end
end
end
local Update = function(self, event, unit)
if(self.unit ~= unit) then return end
UpdateAuras(self, event, unit)
-- Assume no event means someone wants to re-anchor things. This is usually
-- done by UpdateAllElements and :ForceUpdate.
if(event == 'ForceUpdate' or not event) then
local buffs = self.Buffs
if(buffs) then
(buffs.SetPosition or SetPosition) (buffs, 1, buffs.createdIcons)
end
local debuffs = self.Debuffs
if(debuffs) then
(debuffs.SetPosition or SetPosition) (debuffs, 1, debuffs.createdIcons)
end
local auras = self.Auras
if(auras) then
(auras.SetPosition or SetPosition) (auras, 1, auras.createdIcons)
end
end
end
local ForceUpdate = function(element)
return Update(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local Enable = function(self)
if(self.Buffs or self.Debuffs or self.Auras) then
self:RegisterEvent("UNIT_AURA", UpdateAuras)
local buffs = self.Buffs
if(buffs) then
buffs.__owner = self
buffs.ForceUpdate = ForceUpdate
buffs.createdIcons = 0
buffs.anchoredIcons = 0
end
local debuffs = self.Debuffs
if(debuffs) then
debuffs.__owner = self
debuffs.ForceUpdate = ForceUpdate
debuffs.createdIcons = 0
debuffs.anchoredIcons = 0
end
local auras = self.Auras
if(auras) then
auras.__owner = self
auras.ForceUpdate = ForceUpdate
auras.createdIcons = 0
auras.anchoredIcons = 0
end
return true
end
end
local Disable = function(self)
if(self.Buffs or self.Debuffs or self.Auras) then
self:UnregisterEvent("UNIT_AURA", UpdateAuras)
end
end
oUF:AddElement('Aura', Update, Enable, Disable)

View File

@ -0,0 +1,602 @@
--[[ Element: Castbar
Handles updating and visibility of unit castbars.
Widget
Castbar - A StatusBar to represent spell progress.
Sub-Widgets
.Text - A FontString to represent spell name.
.Icon - A Texture to represent spell icon.
.Time - A FontString to represent spell duration.
.Shield - A Texture to represent if it's possible to interrupt or spell
steal.
.SafeZone - A Texture to represent latency.
Options
.timeToHold - A Number to indicate for how many seconds the castbar should be
visible after a _FAILED or _INTERRUPTED event. Defaults to 0.
Credits
Based upon oUF_Castbar by starlon.
Notes
The default texture will be applied if the UI widget doesn't have a texture or
color defined.
Examples
-- Position and size
local Castbar = CreateFrame("StatusBar", nil, self)
Castbar:SetSize(20, 20)
Castbar:SetPoint('TOP')
Castbar:SetPoint('LEFT')
Castbar:SetPoint('RIGHT')
-- Add a background
local Background = Castbar:CreateTexture(nil, 'BACKGROUND')
Background:SetAllPoints(Castbar)
Background:SetTexture(1, 1, 1, .5)
-- Add a spark
local Spark = Castbar:CreateTexture(nil, "OVERLAY")
Spark:SetSize(20, 20)
Spark:SetBlendMode("ADD")
-- Add a timer
local Time = Castbar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
Time:SetPoint("RIGHT", Castbar)
-- Add spell text
local Text = Castbar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
Text:SetPoint("LEFT", Castbar)
-- Add spell icon
local Icon = Castbar:CreateTexture(nil, "OVERLAY")
Icon:SetSize(20, 20)
Icon:SetPoint("TOPLEFT", Castbar, "TOPLEFT")
-- Add Shield
local Shield = Castbar:CreateTexture(nil, "OVERLAY")
Shield:SetSize(20, 20)
Shield:SetPoint("CENTER", Castbar)
-- Add safezone
local SafeZone = Castbar:CreateTexture(nil, "OVERLAY")
-- Register it with oUF
self.Castbar = Castbar
self.Castbar.bg = Background
self.Castbar.Spark = Spark
self.Castbar.Time = Time
self.Castbar.Text = Text
self.Castbar.Icon = Icon
self.Castbar.SafeZone = SafeZone
Hooks and Callbacks
]]
local _, ns = ...
local oUF = ns.oUF
local GetNetStats = GetNetStats
local GetTime = GetTime
local UnitCastingInfo = UnitCastingInfo
local UnitChannelInfo = UnitChannelInfo
local tradeskillCurrent, tradeskillTotal, mergeTradeskill = 0, 0, false
local updateSafeZone = function(self)
local sz = self.SafeZone
local width = self:GetWidth()
local _, _, _, ms = GetNetStats()
-- Guard against GetNetStats returning latencies of 0.
if(ms ~= 0) then
-- MADNESS!
local safeZonePercent = (width / self.max) * (ms / 1e5)
if(safeZonePercent > 1) then safeZonePercent = 1 end
sz:SetWidth(width * safeZonePercent)
sz:Show()
else
sz:Hide()
end
end
local UNIT_SPELLCAST_SENT = function (self, event, unit, spell, rank, target, castid)
local castbar = self.Castbar
castbar.curTarget = (target and target ~= "") and target or nil
if castbar.isTradeSkill then
castbar.tradeSkillCastId = castid
end
end
local UNIT_SPELLCAST_START = function(self, event, unit)
if(self.unit ~= unit and self.realUnit ~= unit) then return end
local castbar = self.Castbar
local name, _, text, texture, startTime, endTime, isTradeSkill, castid, notInterruptible, spellid = UnitCastingInfo(unit)
if(not name) then
return castbar:Hide()
end
endTime = endTime / 1e3
startTime = startTime / 1e3
local max = endTime - startTime
castbar.castid = castid
castbar.duration = GetTime() - startTime
castbar.max = max
castbar.delay = 0
castbar.casting = true
castbar.interrupt = notInterruptible -- NOTE: deprecated; to be removed
castbar.notInterruptible = notInterruptible
castbar.holdTime = 0
castbar.isTradeSkill = isTradeSkill
if(mergeTradeskill and isTradeSkill and UnitIsUnit(unit, "player")) then
castbar.duration = castbar.duration + (castbar.max * tradeskillCurrent);
castbar.max = max * tradeskillTotal;
if(unit == "player") then
tradeskillCurrent = tradeskillCurrent + 1;
end
castbar:SetValue(castbar.duration)
else
castbar:SetValue(0)
end
castbar:SetValue(0)
castbar:SetMinMaxValues(0, castbar.max)
if(castbar.Text) then castbar.Text:SetText(text) end
if(castbar.Icon) then castbar.Icon:SetTexture(texture) end
if(castbar.Time) then castbar.Time:SetText() end
local shield = castbar.Shield
if(shield and notInterruptible) then
shield:Show()
elseif(shield) then
shield:Hide()
end
local sf = castbar.SafeZone
if(sf) then
sf:ClearAllPoints()
sf:SetPoint'RIGHT'
sf:SetPoint'TOP'
sf:SetPoint'BOTTOM'
updateSafeZone(castbar)
end
if(castbar.PostCastStart) then
castbar:PostCastStart(unit, name, castid, spellid)
end
castbar:Show()
end
local UNIT_SPELLCAST_FAILED = function(self, event, unit, spellname, _, castid, spellid)
if(self.unit ~= unit and self.realUnit ~= unit) then return end
local castbar = self.Castbar
if (castbar.castid ~= castid) and (castbar.tradeSkillCastId ~= castid) then
return
end
if(mergeTradeskill and UnitIsUnit(unit, "player")) then
mergeTradeskill = false;
castbar.tradeSkillCastId = nil
end
local text = castbar.Text
if(text) then
text:SetText(FAILED)
end
castbar.casting = nil
castbar.interrupt = nil -- NOTE: deprecated; to be removed
castbar.notInterruptible = nil
castbar.holdTime = castbar.timeToHold or 0
if(castbar.PostCastFailed) then
return castbar:PostCastFailed(unit, spellname, castid, spellid)
end
end
local UNIT_SPELLCAST_FAILED_QUIET = function(self, event, unit, spellname, _, castid)
if(self.unit ~= unit and self.realUnit ~= unit) then return end
local castbar = self.Castbar
if (castbar.castid ~= castid) and (castbar.tradeSkillCastId ~= castid) then
return
end
if(mergeTradeskill and UnitIsUnit(unit, "player")) then
mergeTradeskill = false;
castbar.tradeSkillCastId = nil
end
castbar.casting = nil
castbar.interrupt = nil -- NOTE: deprecated; to be removed
castbar.notInterruptible = nil
castbar:SetValue(0)
castbar:Hide()
end
local UNIT_SPELLCAST_INTERRUPTED = function(self, event, unit, spellname, _, castid, spellid)
if(self.unit ~= unit and self.realUnit ~= unit) then return end
local castbar = self.Castbar
if (castbar.castid ~= castid) then
return
end
local text = castbar.Text
if(text) then
text:SetText(INTERRUPTED)
end
castbar.casting = nil
castbar.channeling = nil
castbar.holdTime = castbar.timeToHold or 0
if(castbar.PostCastInterrupted) then
return castbar:PostCastInterrupted(unit, spellname, castid, spellid)
end
end
local UNIT_SPELLCAST_INTERRUPTIBLE = function(self, event, unit)
if(self.unit ~= unit and self.realUnit ~= unit) then return end
local castbar = self.Castbar
local shield = castbar.Shield
if(shield) then
shield:Hide()
end
castbar.interrupt = nil -- NOTE: deprecated; to be removed
castbar.notInterruptible = nil
if(castbar.PostCastInterruptible) then
return castbar:PostCastInterruptible(unit)
end
end
local UNIT_SPELLCAST_NOT_INTERRUPTIBLE = function(self, event, unit)
if(self.unit ~= unit and self.realUnit ~= unit) then return end
local castbar = self.Castbar
local shield = castbar.Shield
if(shield) then
shield:Show()
end
castbar.interrupt = nil -- NOTE: deprecated; to be removed
castbar.notInterruptible = nil
if(castbar.PostCastNotInterruptible) then
return castbar:PostCastNotInterruptible(unit)
end
end
local UNIT_SPELLCAST_DELAYED = function(self, event, unit, _, _, _, spellid)
if(self.unit ~= unit and self.realUnit ~= unit) then return end
local castbar = self.Castbar
local name, _, _, _, startTime, _, _, castid = UnitCastingInfo(unit)
if(not startTime or not castbar:IsShown()) then return end
local duration = GetTime() - (startTime / 1000)
if(duration < 0) then duration = 0 end
castbar.delay = castbar.delay + castbar.duration - duration
castbar.duration = duration
castbar:SetValue(duration)
if(castbar.PostCastDelayed) then
return castbar:PostCastDelayed(unit, name, castid, spellid)
end
end
local UNIT_SPELLCAST_STOP = function(self, event, unit, spellname, _, castid, spellid)
if(self.unit ~= unit and self.realUnit ~= unit) then return end
local castbar = self.Castbar
if (castbar.castid ~= castid) then
return
end
if(mergeTradeskill and UnitIsUnit(unit, "player")) then
if(tradeskillCurrent == tradeskillTotal) then
mergeTradeskill = false;
end
else
castbar.casting = nil
castbar.interrupt = nil -- NOTE: deprecated; to be removed
castbar.notInterruptible = nil
end
if(castbar.PostCastStop) then
return castbar:PostCastStop(unit, spellname, castid, spellid)
end
end
local UNIT_SPELLCAST_CHANNEL_START = function(self, event, unit, _, _, _, spellid)
if(self.unit ~= unit and self.realUnit ~= unit) then return end
local castbar = self.Castbar
local name, _, _, texture, startTime, endTime, _, notInterruptible = UnitChannelInfo(unit)
if(not name) then
return
end
endTime = endTime / 1e3
startTime = startTime / 1e3
local max = (endTime - startTime)
local duration = endTime - GetTime()
castbar.duration = duration
castbar.max = max
castbar.delay = 0
castbar.startTime = startTime
castbar.endTime = endTime
castbar.extraTickRatio = 0
castbar.channeling = true
castbar.interrupt = notInterruptible -- NOTE: deprecated; to be removed
castbar.notInterruptible = notInterruptible
castbar.holdTime = 0
-- We have to do this, as it's possible for spell casts to never have _STOP
-- executed or be fully completed by the OnUpdate handler before CHANNEL_START
-- is called.
castbar.casting = nil
castbar.castid = nil
castbar:SetMinMaxValues(0, max)
castbar:SetValue(duration)
if(castbar.Text) then castbar.Text:SetText(name) end
if(castbar.Icon) then castbar.Icon:SetTexture(texture) end
if(castbar.Time) then castbar.Time:SetText() end
local shield = castbar.Shield
if(shield and notInterruptible) then
shield:Show()
elseif(shield) then
shield:Hide()
end
local sf = castbar.SafeZone
if(sf) then
sf:ClearAllPoints()
sf:SetPoint'LEFT'
sf:SetPoint'TOP'
sf:SetPoint'BOTTOM'
updateSafeZone(castbar)
end
if(castbar.PostChannelStart) then castbar:PostChannelStart(unit, name, spellid) end
castbar:Show()
end
local UNIT_SPELLCAST_CHANNEL_UPDATE = function(self, event, unit, _, _, _, spellid)
if(self.unit ~= unit and self.realUnit ~= unit) then return end
local castbar = self.Castbar
local name, _, _, _, startTime, endTime = UnitChannelInfo(unit)
if(not name or not castbar:IsShown()) then
return
end
local duration = (endTime / 1000) - GetTime()
local startDelay = castbar.startTime - startTime / 1000
castbar.startTime = startTime / 1000
castbar.endTime = endTime / 1000
castbar.delay = castbar.delay + startDelay
castbar.duration = duration
castbar.max = (endTime - startTime) / 1000
castbar:SetMinMaxValues(0, castbar.max)
castbar:SetValue(duration)
if(castbar.PostChannelUpdate) then
return castbar:PostChannelUpdate(unit, name, spellid)
end
end
local UNIT_SPELLCAST_CHANNEL_STOP = function(self, event, unit, spellname, _, _, spellid)
if(self.unit ~= unit and self.realUnit ~= unit) then return end
local castbar = self.Castbar
if(castbar:IsShown()) then
castbar.channeling = nil
castbar.interrupt = nil -- NOTE: deprecated; to be removed
castbar.notInterruptible = nil
if(castbar.PostChannelStop) then
return castbar:PostChannelStop(unit, spellname, spellid)
end
end
end
local onUpdate = function(self, elapsed)
if(self.casting) then
local duration = self.duration + elapsed
if(duration >= self.max) then
self.casting = nil
self:Hide()
if(self.PostCastStop) then self:PostCastStop(self.__owner.unit) end
return
end
if(self.Time) then
if(self.delay ~= 0) then
if(self.CustomDelayText) then
self:CustomDelayText(duration)
else
self.Time:SetFormattedText("%.1f|cffff0000-%.1f|r", duration, self.delay)
end
else
if(self.CustomTimeText) then
self:CustomTimeText(duration)
else
self.Time:SetFormattedText("%.1f", duration)
end
end
end
self.duration = duration
self:SetValue(duration)
if(self.Spark) then
self.Spark:SetPoint("CENTER", self, "LEFT", (duration / self.max) * self:GetWidth(), 0)
end
elseif(self.channeling) then
local duration = self.duration - elapsed
if(duration <= 0) then
self.channeling = nil
self:Hide()
if(self.PostChannelStop) then self:PostChannelStop(self.__owner.unit) end
return
end
if(self.Time) then
if(self.delay ~= 0) then
if(self.CustomDelayText) then
self:CustomDelayText(duration)
else
self.Time:SetFormattedText("%.1f|cffff0000-%.1f|r", duration, self.delay)
end
else
if(self.CustomTimeText) then
self:CustomTimeText(duration)
else
self.Time:SetFormattedText("%.1f", duration)
end
end
end
self.duration = duration
self:SetValue(duration)
if(self.Spark) then
self.Spark:SetPoint("CENTER", self, "LEFT", (duration / self.max) * self:GetWidth(), 0)
end
elseif(self.holdTime > 0) then
self.holdTime = self.holdTime - elapsed
else
self.casting = nil
self.castid = nil
self.channeling = nil
self:Hide()
end
end
local Update = function(self, ...)
UNIT_SPELLCAST_START(self, ...)
return UNIT_SPELLCAST_CHANNEL_START(self, ...)
end
local ForceUpdate = function(element)
return Update(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local Enable = function(self, unit)
local castbar = self.Castbar
if(castbar) then
castbar.__owner = self
castbar.ForceUpdate = ForceUpdate
if(not (unit and unit:match'%wtarget$')) then
self:RegisterEvent("UNIT_SPELLCAST_SENT", UNIT_SPELLCAST_SENT, true)
self:RegisterEvent("UNIT_SPELLCAST_START", UNIT_SPELLCAST_START)
self:RegisterEvent("UNIT_SPELLCAST_FAILED", UNIT_SPELLCAST_FAILED)
self:RegisterEvent("UNIT_SPELLCAST_FAILED_QUIET", UNIT_SPELLCAST_FAILED_QUIET)
self:RegisterEvent("UNIT_SPELLCAST_STOP", UNIT_SPELLCAST_STOP)
self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED", UNIT_SPELLCAST_INTERRUPTED)
self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTIBLE", UNIT_SPELLCAST_INTERRUPTIBLE)
self:RegisterEvent("UNIT_SPELLCAST_NOT_INTERRUPTIBLE", UNIT_SPELLCAST_NOT_INTERRUPTIBLE)
self:RegisterEvent("UNIT_SPELLCAST_DELAYED", UNIT_SPELLCAST_DELAYED)
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START", UNIT_SPELLCAST_CHANNEL_START)
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE", UNIT_SPELLCAST_CHANNEL_UPDATE)
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP", UNIT_SPELLCAST_CHANNEL_STOP)
end
castbar.holdTime = 0
castbar:SetScript("OnUpdate", castbar.OnUpdate or onUpdate)
if(self.unit == "player") then
CastingBarFrame:UnregisterAllEvents()
CastingBarFrame.Show = CastingBarFrame.Hide
CastingBarFrame:Hide()
PetCastingBarFrame:UnregisterAllEvents()
PetCastingBarFrame.Show = PetCastingBarFrame.Hide
PetCastingBarFrame:Hide()
end
if(castbar:IsObjectType'StatusBar' and not castbar:GetStatusBarTexture()) then
castbar:SetStatusBarTexture[[Interface\TargetingFrame\UI-StatusBar]]
end
local spark = castbar.Spark
if(spark and spark:IsObjectType'Texture' and not spark:GetTexture()) then
spark:SetTexture[[Interface\CastingBar\UI-CastingBar-Spark]]
end
local shield = castbar.Shield
if(shield and shield:IsObjectType'Texture' and not shield:GetTexture()) then
shield:SetTexture[[Interface\CastingBar\UI-CastingBar-Small-Shield]]
end
local sz = castbar.SafeZone
if(sz and sz:IsObjectType'Texture' and not sz:GetTexture()) then
sz:SetColorTexture(1, 0, 0)
end
castbar:Hide()
return true
end
end
local Disable = function(self)
local castbar = self.Castbar
if(castbar) then
castbar:Hide()
self:UnregisterEvent("UNIT_SPELLCAST_SENT", UNIT_SPELLCAST_SENT)
self:UnregisterEvent("UNIT_SPELLCAST_START", UNIT_SPELLCAST_START)
self:UnregisterEvent("UNIT_SPELLCAST_FAILED", UNIT_SPELLCAST_FAILED)
self:UnregisterEvent("UNIT_SPELLCAST_FAILED_QUIET", UNIT_SPELLCAST_FAILED_QUIET)
self:UnregisterEvent("UNIT_SPELLCAST_STOP", UNIT_SPELLCAST_STOP)
self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED", UNIT_SPELLCAST_INTERRUPTED)
self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTIBLE", UNIT_SPELLCAST_INTERRUPTIBLE)
self:UnregisterEvent("UNIT_SPELLCAST_NOT_INTERRUPTIBLE", UNIT_SPELLCAST_NOT_INTERRUPTIBLE)
self:UnregisterEvent("UNIT_SPELLCAST_DELAYED", UNIT_SPELLCAST_DELAYED)
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_START", UNIT_SPELLCAST_CHANNEL_START)
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE", UNIT_SPELLCAST_CHANNEL_UPDATE)
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_STOP", UNIT_SPELLCAST_CHANNEL_STOP)
castbar:SetScript("OnUpdate", nil)
end
end
hooksecurefunc(C_TradeSkillUI, "CraftRecipe", function(_, num)
tradeskillCurrent = 0
tradeskillTotal = num or 1
mergeTradeskill = true
end)
oUF:AddElement('Castbar', Update, Enable, Disable)

View File

@ -0,0 +1,291 @@
--[[ Element: Class Icons
Toggles the visibility of icons depending on the player's class and
specialization.
Widget
ClassIcons - An array consisting of as many UI Textures as the theoretical
maximum return of `UnitPowerMax`.
Notes
All - Combo Points
Mage - Arcane Charges
Monk - Chi Orbs
Paladin - Holy Power
Warlock - Soul Shards
Examples
local ClassIcons = {}
for index = 1, 6 do
local Icon = self:CreateTexture(nil, 'BACKGROUND')
-- Position and size.
Icon:SetSize(16, 16)
Icon:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', index * Icon:GetWidth(), 0)
ClassIcons[index] = Icon
end
-- Register with oUF
self.ClassIcons = ClassIcons
Hooks
OverrideVisibility(self) - Used to completely override the internal visibility
function. Removing the table key entry will make
the element fall-back to its internal function
again.
Override(self) - Used to completely override the internal update
function. Removing the table key entry will make the
element fall-back to its internal function again.
UpdateTexture(element) - Used to completely override the internal function
for updating the power icon textures. Removing the
table key entry will make the element fall-back to
its internal function again.
]]
local parent, ns = ...
local oUF = ns.oUF
local _, PlayerClass = UnitClass'player'
-- Holds the class specific stuff.
local ClassPowerID, ClassPowerType
local ClassPowerEnable, ClassPowerDisable
local RequireSpec, RequireSpell, RequireFormID
local UpdateTexture = function(element)
local color = oUF.colors.power[ClassPowerType or 'COMBO_POINTS']
for i = 1, #element do
local icon = element[i]
if(icon.SetDesaturated) then
icon:SetDesaturated(PlayerClass ~= 'PRIEST')
end
icon:SetVertexColor(color[1], color[2], color[3])
end
end
local Update = function(self, event, unit, powerType)
if(not (unit == 'player' and powerType == ClassPowerType
or unit == 'vehicle' and powerType == 'COMBO_POINTS')) then
return
end
local element = self.ClassIcons
--[[ :PreUpdate()
Called before the element has been updated
Arguments
self - The ClassIcons element
event - The event, that the update is being triggered for
]]
if(element.PreUpdate) then
element:PreUpdate(event)
end
local cur, max, oldMax
if(event ~= 'ClassPowerDisable') then
if(unit == 'vehicle') then
-- XXX: UnitPower is bugged for vehicles, always returns 0 combo points
cur = GetComboPoints(unit)
max = MAX_COMBO_POINTS
else
cur = UnitPower('player', ClassPowerID)
max = UnitPowerMax('player', ClassPowerID)
end
for i = 1, max do
if(i <= cur) then
element[i]:Show()
else
element[i]:Hide()
end
end
oldMax = element.__max
if(max ~= oldMax) then
if(max < oldMax) then
for i = max + 1, oldMax do
element[i]:Hide()
end
end
element.__max = max
end
end
--[[ :PostUpdate(cur, max, hasMaxChanged, event)
Called after the element has been updated
Arguments
self - The ClassIcons element
cur - The current amount of power
max - The maximum amount of power
hasMaxChanged - Shows if the maximum amount has changed since the last
update
powerType - The type of power used
event - The event, which the update happened for
]]
if(element.PostUpdate) then
return element:PostUpdate(cur, max, oldMax ~= max, powerType, event)
end
end
local Path = function(self, ...)
return (self.ClassIcons.Override or Update) (self, ...)
end
local function Visibility(self, event, unit)
local element = self.ClassIcons
local shouldEnable
if(UnitHasVehicleUI('player')) then
shouldEnable = true
unit = 'vehicle'
elseif(ClassPowerID) then
if(not RequireSpec or RequireSpec == GetSpecialization()) then
if(not RequireFormID or RequireFormID == GetShapeshiftFormID()) then
if(not RequireSpell or IsPlayerSpell(RequireSpell)) then
if(not RequirePower or RequirePower == UnitPowerType('player')) then
self:UnregisterEvent('SPELLS_CHANGED', Visibility)
shouldEnable = true
else
self:RegisterEvent('SPELLS_CHANGED', Visibility, true)
end
else
self:RegisterEvent('SPELLS_CHANGED', Visibility, true)
end
end
end
end
local isEnabled = element.isEnabled
if(shouldEnable and not isEnabled) then
ClassPowerEnable(self)
elseif(not shouldEnable and (isEnabled or isEnabled == nil)) then
ClassPowerDisable(self)
elseif(shouldEnable and isEnabled) then
Path(self, event, unit, unit == 'vehicle' and 'COMBO_POINTS' or ClassPowerType)
end
end
local VisibilityPath = function(self, ...)
return (self.ClassIcons.OverrideVisibility or Visibility) (self, ...)
end
local ForceUpdate = function(element)
return VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
end
do
ClassPowerEnable = function(self)
self:RegisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
self:RegisterEvent('UNIT_POWER_FREQUENT', Path)
self:RegisterEvent('UNIT_MAXPOWER', Path)
if(UnitHasVehicleUI('player')) then
Path(self, 'ClassPowerEnable', 'vehicle', 'COMBO_POINTS')
else
Path(self, 'ClassPowerEnable', 'player', ClassPowerType)
end
self.ClassIcons.isEnabled = true
end
ClassPowerDisable = function(self)
self:UnregisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
self:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
self:UnregisterEvent('UNIT_MAXPOWER', Path)
local element = self.ClassIcons
for i = 1, #element do
element[i]:Hide()
end
Path(self, 'ClassPowerDisable', 'player', ClassPowerType)
self.ClassIcons.isEnabled = false
end
if(PlayerClass == 'MONK') then
ClassPowerID = SPELL_POWER_CHI
ClassPowerType = "CHI"
RequireSpec = SPEC_MONK_WINDWALKER
elseif(PlayerClass == 'PALADIN') then
ClassPowerID = SPELL_POWER_HOLY_POWER
ClassPowerType = "HOLY_POWER"
RequireSpec = SPEC_PALADIN_RETRIBUTION
elseif(PlayerClass == 'WARLOCK') then
ClassPowerID = SPELL_POWER_SOUL_SHARDS
ClassPowerType = "SOUL_SHARDS"
elseif(PlayerClass == 'ROGUE' or PlayerClass == 'DRUID') then
ClassPowerID = SPELL_POWER_COMBO_POINTS
ClassPowerType = 'COMBO_POINTS'
if(PlayerClass == 'DRUID') then
RequireFormID = 1 --CAT_FORM
RequireSpell = 5221 -- Shred
end
elseif(PlayerClass == 'MAGE') then
ClassPowerID = SPELL_POWER_ARCANE_CHARGES
ClassPowerType = 'ARCANE_CHARGES'
RequireSpec = SPEC_MAGE_ARCANE
end
end
local Enable = function(self, unit)
if(unit ~= 'player') then return end
local element = self.ClassIcons
if(not element) then return end
element.__owner = self
element.__max = #element
element.ForceUpdate = ForceUpdate
if(RequireSpec or RequireSpell) then
self:RegisterEvent('PLAYER_TALENT_UPDATE', VisibilityPath, true)
end
if(RequireFormID) then
self:RegisterEvent('UPDATE_SHAPESHIFT_FORM', VisibilityPath, true)
end
element.ClassPowerEnable = ClassPowerEnable
element.ClassPowerDisable = ClassPowerDisable
local isChildrenTextures
for i = 1, #element do
local icon = element[i]
if(icon:IsObjectType'Texture') then
if(not icon:GetTexture()) then
icon:SetTexCoord(0.45703125, 0.60546875, 0.44531250, 0.73437500)
icon:SetTexture([[Interface\PlayerFrame\Priest-ShadowUI]])
end
isChildrenTextures = true
end
end
if(isChildrenTextures) then
(element.UpdateTexture or UpdateTexture) (element)
end
return true
end
local Disable = function(self)
local element = self.ClassIcons
if(not element) then return end
ClassPowerDisable(self)
end
oUF:AddElement('ClassIcons', VisibilityPath, Enable, Disable)

View File

@ -0,0 +1,86 @@
--[[ Element: Combat Icon
Toggles the visibility of `self.Combat` based on the player's combat status.
Widget
Combat - Any UI widget.
Notes
The default assistant icon will be applied if the UI widget is a texture and
doesn't have a texture or color defined.
Examples
-- Position and size
local Combat = self:CreateTexture(nil, "OVERLAY")
Combat:SetSize(16, 16)
Combat:SetPoint('TOP', self)
-- Register it with oUF
self.Combat = Combat
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local parent, ns = ...
local oUF = ns.oUF
local Update = function(self, event)
local combat = self.Combat
if(combat.PreUpdate) then
combat:PreUpdate()
end
local inCombat = UnitAffectingCombat('player')
if(inCombat) then
combat:Show()
else
combat:Hide()
end
if(combat.PostUpdate) then
return combat:PostUpdate(inCombat)
end
end
local Path = function(self, ...)
return (self.Combat.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate')
end
local Enable = function(self, unit)
local combat = self.Combat
if(combat and unit == 'player') then
combat.__owner = self
combat.ForceUpdate = ForceUpdate
self:RegisterEvent("PLAYER_REGEN_DISABLED", Path, true)
self:RegisterEvent("PLAYER_REGEN_ENABLED", Path, true)
if(combat:IsObjectType"Texture" and not combat:GetTexture()) then
combat:SetTexture[[Interface\CharacterFrame\UI-StateIcon]]
combat:SetTexCoord(.5, 1, 0, .49)
end
return true
end
end
local Disable = function(self)
if(self.Combat) then
self.Combat:Hide()
self:UnregisterEvent("PLAYER_REGEN_DISABLED", Path)
self:UnregisterEvent("PLAYER_REGEN_ENABLED", Path)
end
end
oUF:AddElement('Combat', Path, Enable, Disable)

View File

@ -0,0 +1,239 @@
--[[ Element: Heal Prediction Bar
Handle updating and visibility of the heal prediction status bars.
Widget
HealPrediction - A table containing `myBar` and `otherBar`.
Sub-Widgets
myBar - A StatusBar used to represent your incoming heals.
otherBar - A StatusBar used to represent other peoples incoming heals.
absorbBar - A StatusBar used to represent total absorbs.
healAbsorbBar - A StatusBar used to represent heal absorbs.
Notes
The default StatusBar texture will be applied if the UI widget doesn't have a
status bar texture or color defined.
Options
.maxOverflow - Defines the maximum amount of overflow past the end of the
health bar.
.frequentUpdates - Update on UNIT_HEALTH_FREQUENT instead of UNIT_HEALTH. Use
this if .frequentUpdates is also set on the Health element.
Examples
-- Position and size
local myBar = CreateFrame('StatusBar', nil, self.Health)
myBar:SetPoint('TOP')
myBar:SetPoint('BOTTOM')
myBar:SetPoint('LEFT', self.Health:GetStatusBarTexture(), 'RIGHT')
myBar:SetWidth(200)
local otherBar = CreateFrame('StatusBar', nil, self.Health)
otherBar:SetPoint('TOP')
otherBar:SetPoint('BOTTOM')
otherBar:SetPoint('LEFT', self.Health:GetStatusBarTexture(), 'RIGHT')
otherBar:SetWidth(200)
local absorbBar = CreateFrame('StatusBar', nil, self.Health)
absorbBar:SetPoint('TOP')
absorbBar:SetPoint('BOTTOM')
absorbBar:SetPoint('LEFT', self.Health:GetStatusBarTexture(), 'RIGHT')
absorbBar:SetWidth(200)
local healAbsorbBar = CreateFrame('StatusBar', nil, self.Health)
healAbsorbBar:SetPoint('TOP')
healAbsorbBar:SetPoint('BOTTOM')
healAbsorbBar:SetPoint('LEFT', self.Health:GetStatusBarTexture(), 'RIGHT')
healAbsorbBar:SetWidth(200)
-- Register with oUF
self.HealPrediction = {
myBar = myBar,
otherBar = otherBar,
absorbBar = absorbBar,
healAbsorbBar = healAbsorbBar,
maxOverflow = 1.05,
frequentUpdates = true,
}
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local _, ns = ...
local oUF = ns.oUF
local function Update(self, event, unit)
if(self.unit ~= unit) or not unit then return end
local hp = self.HealPrediction
hp.parent = self
if(hp.PreUpdate) then hp:PreUpdate(unit) end
local myIncomingHeal = UnitGetIncomingHeals(unit, 'player') or 0
local allIncomingHeal = UnitGetIncomingHeals(unit) or 0
local totalAbsorb = UnitGetTotalAbsorbs(unit) or 0
local myCurrentHealAbsorb = UnitGetTotalHealAbsorbs(unit) or 0
local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit)
local overHealAbsorb = false
if(health < myCurrentHealAbsorb) then
overHealAbsorb = true
myCurrentHealAbsorb = health
end
if(health - myCurrentHealAbsorb + allIncomingHeal > maxHealth * hp.maxOverflow) then
allIncomingHeal = maxHealth * hp.maxOverflow - health + myCurrentHealAbsorb
end
local otherIncomingHeal = 0
if(allIncomingHeal < myIncomingHeal) then
myIncomingHeal = allIncomingHeal
else
otherIncomingHeal = allIncomingHeal - myIncomingHeal
end
local overAbsorb = false
if(health - myCurrentHealAbsorb + allIncomingHeal + totalAbsorb >= maxHealth or health + totalAbsorb >= maxHealth) then
if(totalAbsorb > 0) then
overAbsorb = true
end
if(allIncomingHeal > myCurrentHealAbsorb) then
totalAbsorb = max(0, maxHealth - (health - myCurrentHealAbsorb + allIncomingHeal))
else
totalAbsorb = max(0, maxHealth - health)
end
end
if(myCurrentHealAbsorb > allIncomingHeal) then
myCurrentHealAbsorb = myCurrentHealAbsorb - allIncomingHeal
else
myCurrentHealAbsorb = 0
end
if(hp.myBar) then
hp.myBar:SetMinMaxValues(0, maxHealth)
hp.myBar:SetValue(myIncomingHeal)
hp.myBar:Show()
end
if(hp.otherBar) then
hp.otherBar:SetMinMaxValues(0, maxHealth)
hp.otherBar:SetValue(otherIncomingHeal)
hp.otherBar:Show()
end
if(hp.absorbBar) then
hp.absorbBar:SetMinMaxValues(0, maxHealth)
hp.absorbBar:SetValue(totalAbsorb)
hp.absorbBar:Show()
end
if(hp.healAbsorbBar) then
hp.healAbsorbBar:SetMinMaxValues(0, maxHealth)
hp.healAbsorbBar:SetValue(myCurrentHealAbsorb)
hp.healAbsorbBar:Show()
end
if(hp.PostUpdate) then
return hp:PostUpdate(unit, myIncomingHeal, allIncomingHeal, totalAbsorb, myCurrentHealAbsorb)
end
end
local function Path(self, ...)
return (self.HealPrediction.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local function Enable(self)
local hp = self.HealPrediction
if(hp) then
hp.__owner = self
hp.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_HEAL_PREDICTION', Path)
self:RegisterEvent('UNIT_MAXHEALTH', Path)
if(hp.frequentUpdates) then
self:RegisterEvent('UNIT_HEALTH_FREQUENT', Path)
else
self:RegisterEvent('UNIT_HEALTH', Path)
end
self:RegisterEvent('UNIT_ABSORB_AMOUNT_CHANGED', Path)
self:RegisterEvent('UNIT_HEAL_ABSORB_AMOUNT_CHANGED', Path)
if(not hp.maxOverflow) then
hp.maxOverflow = 1.05
end
if(hp.myBar) then
if(hp.myBar:IsObjectType'StatusBar' and not hp.myBar:GetStatusBarTexture()) then
hp.myBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end
hp.myBar:Show()
end
if(hp.otherBar) then
if(hp.otherBar:IsObjectType'StatusBar' and not hp.otherBar:GetStatusBarTexture()) then
hp.otherBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end
hp.otherBar:Show()
end
if(hp.absorbBar) then
if(hp.absorbBar:IsObjectType'StatusBar' and not hp.absorbBar:GetStatusBarTexture()) then
hp.absorbBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end
hp.absorbBar:Show()
end
if(hp.healAbsorbBar) then
if(hp.healAbsorbBar:IsObjectType'StatusBar' and not hp.healAbsorbBar:GetStatusBarTexture()) then
hp.healAbsorbBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end
hp.healAbsorbBar:Show()
end
return true
end
end
local function Disable(self)
local hp = self.HealPrediction
if(hp) then
if(hp.myBar) then
hp.myBar:Hide()
end
if(hp.otherBar) then
hp.otherBar:Hide()
end
if(hp.absorbBar) then
hp.absorbBar:Hide()
end
if(hp.healAbsorbBar) then
hp.healAbsorbBar:Hide()
end
self:UnregisterEvent('UNIT_HEAL_PREDICTION', Path)
self:UnregisterEvent('UNIT_MAXHEALTH', Path)
self:UnregisterEvent('UNIT_HEALTH', Path)
self:UnregisterEvent('UNIT_HEALTH_FREQUENT', Path)
self:UnregisterEvent('UNIT_ABSORB_AMOUNT_CHANGED', Path)
self:UnregisterEvent('UNIT_HEAL_ABSORB_AMOUNT_CHANGED', Path)
end
end
oUF:AddElement('HealPrediction', Path, Enable, Disable)

View File

@ -0,0 +1,215 @@
--[[ Element: Health Bar
Handles updating of `self.Health` based on the units health.
Widget
Health - A StatusBar used to represent current unit health.
Sub-Widgets
.bg - A Texture which functions as a background. It will inherit the color of
the main StatusBar.
Notes
The default StatusBar texture will be applied if the UI widget doesn't have a
status bar texture or color defined.
Options
The following options are listed by priority. The first check that returns
true decides the color of the bar.
.colorTapping - Use `self.colors.tapping` to color the bar if the unit
isn't tapped by the player.
.colorDisconnected - Use `self.colors.disconnected` to color the bar if the
unit is offline.
.colorClass - Use `self.colors.class[class]` to color the bar based on
unit class. `class` is defined by the second return of
[UnitClass](http://wowprogramming.com/docs/api/UnitClass).
.colorClassNPC - Use `self.colors.class[class]` to color the bar if the
unit is a NPC.
.colorClassPet - Use `self.colors.class[class]` to color the bar if the
unit is player controlled, but not a player.
.colorReaction - Use `self.colors.reaction[reaction]` to color the bar
based on the player's reaction towards the unit.
`reaction` is defined by the return value of
[UnitReaction](http://wowprogramming.com/docs/api/UnitReaction).
.colorSmooth - Use `self.colors.smooth` to color the bar with a smooth
gradient based on the player's current health percentage.
.colorHealth - Use `self.colors.health` to color the bar. This flag is
used to reset the bar color back to default if none of the
above conditions are met.
Sub-Widgets Options
.multiplier - Defines a multiplier, which is used to tint the background based
on the main widgets R, G and B values. Defaults to 1 if not
present.
Examples
-- Position and size
local Health = CreateFrame("StatusBar", nil, self)
Health:Height(20)
Health:SetPoint('TOP')
Health:SetPoint('LEFT')
Health:SetPoint('RIGHT')
-- Add a background
local Background = Health:CreateTexture(nil, 'BACKGROUND')
Background:SetAllPoints(Health)
Background:SetTexture(1, 1, 1, .5)
-- Options
Health.frequentUpdates = true
Health.colorTapping = true
Health.colorDisconnected = true
Health.colorClass = true
Health.colorReaction = true
Health.colorHealth = true
-- Make the background darker.
Background.multiplier = .5
-- Register it with oUF
self.Health = Health
self.Health.bg = Background
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local parent, ns = ...
local oUF = ns.oUF
local updateFrequentUpdates
oUF.colors.health = {49/255, 207/255, 37/255}
local Update = function(self, event, unit)
if(not unit or self.unit ~= unit) then return end
local health = self.Health
if(health.PreUpdate) then health:PreUpdate(unit) end
local min, max = UnitHealth(unit), UnitHealthMax(unit)
local disconnected = not UnitIsConnected(unit)
health:SetMinMaxValues(0, max)
if(disconnected) then
health:SetValue(max)
else
health:SetValue(min)
end
health.disconnected = disconnected
if health.frequentUpdates ~= health.__frequentUpdates then
health.__frequentUpdates = health.frequentUpdates
updateFrequentUpdates(self)
end
local r, g, b, t
if(health.colorTapping and not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)) then
t = self.colors.tapped
elseif(health.colorDisconnected and not UnitIsConnected(unit)) then
t = self.colors.disconnected
elseif(health.colorClass and UnitIsPlayer(unit)) or
(health.colorClassNPC and not UnitIsPlayer(unit)) or
(health.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
local _, class = UnitClass(unit)
t = self.colors.class[class]
elseif(health.colorReaction and UnitReaction(unit, 'player')) then
t = self.colors.reaction[UnitReaction(unit, "player")]
elseif(health.colorSmooth) then
r, g, b = self.ColorGradient(min, max, unpack(health.smoothGradient or self.colors.smooth))
elseif(health.colorHealth) then
t = self.colors.health
end
if(t) then
r, g, b = t[1], t[2], t[3]
end
if(b) then
health:SetStatusBarColor(r, g, b)
local bg = health.bg
if(bg) then local mu = bg.multiplier or 1
bg:SetVertexColor(r * mu, g * mu, b * mu)
end
end
if(health.PostUpdate) then
return health:PostUpdate(unit, min, max)
end
end
local Path = function(self, ...)
return (self.Health.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
function updateFrequentUpdates(self)
local health = self.Health
if health.frequentUpdates and not self:IsEventRegistered("UNIT_HEALTH_FREQUENT") then
if GetCVarBool("predictedHealth") ~= true then
SetCVar("predictedHealth", "1")
end
self:RegisterEvent('UNIT_HEALTH_FREQUENT', Path)
if self:IsEventRegistered("UNIT_HEALTH") then
self:UnregisterEvent("UNIT_HEALTH", Path)
end
elseif not self:IsEventRegistered("UNIT_HEALTH") then
self:RegisterEvent('UNIT_HEALTH', Path)
if self:IsEventRegistered("UNIT_HEALTH_FREQUENT") then
self:UnregisterEvent("UNIT_HEALTH_FREQUENT", Path)
end
end
end
local Enable = function(self, unit)
local health = self.Health
if(health) then
health.__owner = self
health.ForceUpdate = ForceUpdate
health.__frequentUpdates = health.frequentUpdates
updateFrequentUpdates(self)
self:RegisterEvent("UNIT_MAXHEALTH", Path)
self:RegisterEvent('UNIT_CONNECTION', Path)
-- For tapping.
self:RegisterEvent('UNIT_FACTION', Path)
if(health:IsObjectType'StatusBar' and not health:GetStatusBarTexture()) then
health:SetStatusBarTexture[[Interface\TargetingFrame\UI-StatusBar]]
end
return true
end
end
local Disable = function(self)
local health = self.Health
if(health) then
health:Hide()
self:UnregisterEvent('UNIT_HEALTH_FREQUENT', Path)
self:UnregisterEvent('UNIT_HEALTH', Path)
self:UnregisterEvent('UNIT_MAXHEALTH', Path)
self:UnregisterEvent('UNIT_CONNECTION', Path)
self:UnregisterEvent('UNIT_FACTION', Path)
end
end
oUF:AddElement('Health', Path, Enable, Disable)

View File

@ -0,0 +1,87 @@
--[[ Element: Leader Icon
Toggles visibility based on the units leader status.
Widget
Leader - Any UI widget.
Notes
The default leader icon will be applied if the UI widget is a texture and
doesn't have a texture or color defined.
Examples
-- Position and size
local Leader = self:CreateTexture(nil, "OVERLAY")
Leader:SetSize(16, 16)
Leader:SetPoint("BOTTOM", self, "TOP")
-- Register it with oUF
self.Leader = Leadera
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local parent, ns = ...
local oUF = ns.oUF
local Update = function(self, event)
local leader = self.Leader
if(leader.PreUpdate) then
leader:PreUpdate()
end
local unit = self.unit
local isLeader = (UnitInParty(unit) or UnitInRaid(unit)) and UnitIsGroupLeader(unit)
if(isLeader) then
leader:Show()
else
leader:Hide()
end
if(leader.PostUpdate) then
return leader:PostUpdate(isLeader)
end
end
local Path = function(self, ...)
return (self.Leader.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate')
end
local Enable = function(self)
local leader = self.Leader
if(leader) then
leader.__owner = self
leader.ForceUpdate = ForceUpdate
self:RegisterEvent("PARTY_LEADER_CHANGED", Path, true)
self:RegisterEvent("GROUP_ROSTER_UPDATE", Path, true)
if(leader:IsObjectType"Texture" and not leader:GetTexture()) then
leader:SetTexture[[Interface\GroupFrame\UI-Group-LeaderIcon]]
end
return true
end
end
local Disable = function(self)
local leader = self.Leader
if(leader) then
leader:Hide()
self:UnregisterEvent("PARTY_LEADER_CHANGED", Path)
self:UnregisterEvent("GROUP_ROSTER_UPDATE", Path)
end
end
oUF:AddElement('Leader', Path, Enable, Disable)

View File

@ -0,0 +1,94 @@
--[[ Element: LFD Role Icon
Toggles visibility of the LFD role icon based upon the units current dungeon
role.
Widget
LFDRole - A Texture containing the LFD role icons at specific locations. Look
at the default LFD role icon texture for an example of this.
Alternatively you can look at the return values of
GetTexCoordsForRoleSmallCircle(role).
Notes
The default LFD role texture will be applied if the UI widget is a texture and
doesn't have a texture or color defined.
Examples
-- Position and size
local LFDRole = self:CreateTexture(nil, "OVERLAY")
LFDRole:SetSize(16, 16)
LFDRole:SetPoint("LEFT", self)
-- Register it with oUF
self.LFDRole = LFDRole
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local parent, ns = ...
local oUF = ns.oUF
local Update = function(self, event)
local lfdrole = self.LFDRole
if(lfdrole.PreUpdate) then
lfdrole:PreUpdate()
end
local role = UnitGroupRolesAssigned(self.unit)
if(role == 'TANK' or role == 'HEALER' or role == 'DAMAGER') then
lfdrole:SetTexCoord(GetTexCoordsForRoleSmallCircle(role))
lfdrole:Show()
else
lfdrole:Hide()
end
if(lfdrole.PostUpdate) then
return lfdrole:PostUpdate(role)
end
end
local Path = function(self, ...)
return (self.LFDRole.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate')
end
local Enable = function(self)
local lfdrole = self.LFDRole
if(lfdrole) then
lfdrole.__owner = self
lfdrole.ForceUpdate = ForceUpdate
if(self.unit == "player") then
self:RegisterEvent("PLAYER_ROLES_ASSIGNED", Path, true)
else
self:RegisterEvent("GROUP_ROSTER_UPDATE", Path, true)
end
if(lfdrole:IsObjectType"Texture" and not lfdrole:GetTexture()) then
lfdrole:SetTexture[[Interface\LFGFrame\UI-LFG-ICON-PORTRAITROLES]]
end
return true
end
end
local Disable = function(self)
local lfdrole = self.LFDRole
if(lfdrole) then
lfdrole:Hide()
self:UnregisterEvent("PLAYER_ROLES_ASSIGNED", Path)
self:UnregisterEvent("GROUP_ROSTER_UPDATE", Path)
end
end
oUF:AddElement('LFDRole', Path, Enable, Disable)

View File

@ -0,0 +1,106 @@
--[[ Element: Master Looter Icon
Toggles visibility of the master looter icon.
Widget
MasterLooter - Any UI widget.
Notes
The default master looter icon will be applied if the UI widget is a texture
and doesn't have a texture or color defined.
Examples
-- Position and size
local MasterLooter = self:CreateTexture(nil, 'OVERLAY')
MasterLooter:SetSize(16, 16)
MasterLooter:SetPoint('TOPRIGHT', self)
-- Register it with oUF
self.MasterLooter = MasterLooter
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local parent, ns = ...
local oUF = ns.oUF
local Update = function(self, event)
local unit = self.unit
local masterlooter = self.MasterLooter
if(not (UnitInParty(unit) or UnitInRaid(unit))) then
return masterlooter:Hide()
end
if(masterlooter.PreUpdate) then
masterlooter:PreUpdate()
end
local method, pid, rid = GetLootMethod()
if(method == 'master') then
local mlUnit
if(pid) then
if(pid == 0) then
mlUnit = 'player'
else
mlUnit = 'party'..pid
end
elseif(rid) then
mlUnit = 'raid'..rid
end
if(unit and mlUnit and UnitIsUnit(unit, mlUnit)) then
masterlooter:Show()
elseif(masterlooter:IsShown()) then
masterlooter:Hide()
end
else
masterlooter:Hide()
end
if(masterlooter.PostUpdate) then
return masterlooter:PostUpdate(masterlooter:IsShown())
end
end
local Path = function(self, ...)
return (self.MasterLooter.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate')
end
local function Enable(self, unit)
local masterlooter = self.MasterLooter
if(masterlooter) then
masterlooter.__owner = self
masterlooter.ForceUpdate = ForceUpdate
self:RegisterEvent('PARTY_LOOT_METHOD_CHANGED', Path, true)
self:RegisterEvent('GROUP_ROSTER_UPDATE', Path, true)
if(masterlooter:IsObjectType('Texture') and not masterlooter:GetTexture()) then
masterlooter:SetTexture([[Interface\GroupFrame\UI-Group-MasterLooter]])
end
return true
end
end
local function Disable(self)
if(self.MasterLooter) then
self.MasterLooter:Hide()
self:UnregisterEvent('PARTY_LOOT_METHOD_CHANGED', Path)
self:UnregisterEvent('GROUP_ROSTER_UPDATE', Path)
end
end
oUF:AddElement('MasterLooter', Path, Enable, Disable)

View File

@ -0,0 +1,85 @@
--[[ Element: Phasing Icon
Toggles visibility of the phase icon based on the units phasing compared to the
player.
Widget
PhaseIcon - Any UI widget.
Notes
The default phasing icon will be used if the UI widget is a texture and doesn't
have a texture or color defined.
Examples
-- Position and size
local PhaseIcon = self:CreateTexture(nil, 'OVERLAY')
PhaseIcon:SetSize(16, 16)
PhaseIcon:SetPoint('TOPLEFT', self)
-- Register it with oUF
self.PhaseIcon = PhaseIcon
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local parent, ns = ...
local oUF = ns.oUF
local Update = function(self, event)
local picon = self.PhaseIcon
if(picon.PreUpdate) then
picon:PreUpdate()
end
local inPhase = UnitInPhase(self.unit)
if(inPhase) then
picon:Hide()
else
picon:Show()
end
if(picon.PostUpdate) then
return picon:PostUpdate(inPhase)
end
end
local Path = function(self, ...)
return (self.PhaseIcon.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate')
end
local Enable = function(self)
local picon = self.PhaseIcon
if(picon) then
picon.__owner = self
picon.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_PHASE', Path, true)
if(picon:IsObjectType'Texture' and not picon:GetTexture()) then
picon:SetTexture[[Interface\TargetingFrame\UI-PhasingIcon]]
end
return true
end
end
local Disable = function(self)
local picon = self.PhaseIcon
if(picon) then
picon:Hide()
self:UnregisterEvent('UNIT_PHASE', Path)
end
end
oUF:AddElement('PhaseIcon', Path, Enable, Disable)

View File

@ -0,0 +1,122 @@
--[[ Element: Portraits
Handles updating of the unit's portrait.
Widget
Portrait - A PlayerModel or Texture used to represent the unit's portrait.
Notes
The quest delivery question mark will be used instead of the unit's model when
the client doesn't have the model information for the unit.
Examples
-- 3D Portrait
-- Position and size
local Portrait = CreateFrame('PlayerModel', nil, self)
Portrait:SetSize(32, 32)
Portrait:SetPoint('RIGHT', self, 'LEFT')
-- Register it with oUF
self.Portrait = Portrait
-- 2D Portrait
local Portrait = self:CreateTexture(nil, 'OVERLAY')
Portrait:SetSize(32, 32)
Portrait:SetPoint('RIGHT', self, 'LEFT')
-- Register it with oUF
self.Portrait = Portrait
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local parent, ns = ...
local oUF = ns.oUF
local Update = function(self, event, unit)
if(not unit or not UnitIsUnit(self.unit, unit)) then return end
local portrait = self.Portrait
local modelUpdated = false
if(portrait.PreUpdate) then portrait:PreUpdate(unit) end
if(portrait:IsObjectType'Model') then
local guid = UnitGUID(unit)
if(not UnitExists(unit) or not UnitIsConnected(unit) or not UnitIsVisible(unit)) then
portrait:SetCamDistanceScale(0.25)
portrait:SetPortraitZoom(0)
portrait:SetPosition(0,0,0.5)
portrait:ClearModel()
portrait:SetModel('interface\\buttons\\talktomequestionmark.m2')
portrait.guid = nil
modelUpdated = true
elseif(portrait.guid ~= guid or event == 'UNIT_MODEL_CHANGED') then
portrait:SetCamDistanceScale(1)
portrait:SetPortraitZoom(1)
portrait:SetPosition(0,0,0)
portrait:ClearModel()
portrait:SetUnit(unit)
portrait.guid = guid
modelUpdated = true
end
else
SetPortraitTexture(portrait, unit)
end
if(portrait.PostUpdate) then
return portrait:PostUpdate(unit, event, modelUpdated)
end
end
local Path = function(self, ...)
return (self.Portrait.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local Enable = function(self, unit)
local portrait = self.Portrait
if(portrait) then
portrait:Show()
portrait.__owner = self
portrait.ForceUpdate = ForceUpdate
self:RegisterEvent("UNIT_PORTRAIT_UPDATE", Path)
self:RegisterEvent("UNIT_MODEL_CHANGED", Path)
self:RegisterEvent('UNIT_CONNECTION', Path)
-- The quest log uses PARTY_MEMBER_{ENABLE,DISABLE} to handle updating of
-- party members overlapping quests. This will probably be enough to handle
-- model updating.
--
-- DISABLE isn't used as it fires when we most likely don't have the
-- information we want.
if(unit == 'party') then
self:RegisterEvent('PARTY_MEMBER_ENABLE', Path)
end
return true
end
end
local Disable = function(self)
local portrait = self.Portrait
if(portrait) then
portrait:Hide()
self:UnregisterEvent("UNIT_PORTRAIT_UPDATE", Path)
self:UnregisterEvent("UNIT_MODEL_CHANGED", Path)
self:UnregisterEvent('PARTY_MEMBER_ENABLE', Path)
self:UnregisterEvent('UNIT_CONNECTION', Path)
end
end
oUF:AddElement('Portrait', Path, Enable, Disable)

View File

@ -0,0 +1,318 @@
--[[ Element: Power Bar
Handles updating of `self.Power` based upon the units power.
Widget
Power - A StatusBar used to represent mana.
Sub-Widgets
.bg - A Texture which functions as a background. It will inherit the color of
the main StatusBar.
Notes
The default StatusBar texture will be applied if the UI widget doesn't have a
status bar texture or color defined.
Options
.displayAltPower - Use this to let the widget display alternate power if the
unit has one. If no alternate power the display will fall
back to primary power.
.useAtlas - Use this to let the widget use an atlas for its texture if
`.atlas` is defined on the widget or an atlas is present in
`self.colors.power` for the appropriate power type.
.atlas - A custom atlas
The following options are listed by priority. The first check that returns
true decides the color of the bar.
.colorTapping - Use `self.colors.tapping` to color the bar if the unit
isn't tapped by the player.
.colorDisconnected - Use `self.colors.disconnected` to color the bar if the
unit is offline.
.altPowerColor - A table containing the RGB values to use for a fixed
color if the alt power bar is being displayed instead
.colorPower - Use `self.colors.power[token]` to color the bar based on
the unit's power type. This method will fall-back to
`:GetAlternativeColor()` if it can't find a color matching
the token. If this function isn't defined, then it will
attempt to color based upon the alternative power colors
returned by [UnitPowerType](http://wowprogramming.com/docs/api/UnitPowerType).
Finally, if these aren't defined, then it will attempt to
color the bar based upon `self.colors.power[type]`.
.colorClass - Use `self.colors.class[class]` to color the bar based on
unit class. `class` is defined by the second return of
[UnitClass](http://wowprogramming.com/docs/api/UnitClass).
.colorClassNPC - Use `self.colors.class[class]` to color the bar if the
unit is a NPC.
.colorClassPet - Use `self.colors.class[class]` to color the bar if the
unit is player controlled, but not a player.
.colorReaction - Use `self.colors.reaction[reaction]` to color the bar
based on the player's reaction towards the unit.
`reaction` is defined by the return value of
[UnitReaction](http://wowprogramming.com/docs/api/UnitReaction).
.colorSmooth - Use `self.colors.smooth` to color the bar with a smooth
gradient based on the player's current health percentage.
Sub-Widget Options
.multiplier - Defines a multiplier, which is used to tint the background based
on the main widgets R, G and B values. Defaults to 1 if not
present.
Examples
-- Position and size
local Power = CreateFrame("StatusBar", nil, self)
Power:SetHeight(20)
Power:SetPoint('BOTTOM')
Power:SetPoint('LEFT')
Power:SetPoint('RIGHT')
-- Add a background
local Background = Power:CreateTexture(nil, 'BACKGROUND')
Background:SetAllPoints(Power)
Background:SetTexture(1, 1, 1, .5)
-- Options
Power.frequentUpdates = true
Power.colorTapping = true
Power.colorDisconnected = true
Power.colorPower = true
Power.colorClass = true
Power.colorReaction = true
-- Make the background darker.
Background.multiplier = .5
-- Register it with oUF
self.Power = Power
self.Power.bg = Background
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local parent, ns = ...
local oUF = ns.oUF
local updateFrequentUpdates
oUF.colors.power = {}
for power, color in next, PowerBarColor do
if (type(power) == "string") then
if(type(select(2, next(color))) == 'table') then
oUF.colors.power[power] = {}
for index, color in next, color do
oUF.colors.power[power][index] = {color.r, color.g, color.b}
end
else
oUF.colors.power[power] = {color.r, color.g, color.b, atlas = color.atlas}
end
end
end
-- sourced from FrameXML/Constants.lua
oUF.colors.power[0] = oUF.colors.power.MANA
oUF.colors.power[1] = oUF.colors.power.RAGE
oUF.colors.power[2] = oUF.colors.power.FOCUS
oUF.colors.power[3] = oUF.colors.power.ENERGY
oUF.colors.power[4] = oUF.colors.power.COMBO_POINTS
oUF.colors.power[5] = oUF.colors.power.RUNES
oUF.colors.power[6] = oUF.colors.power.RUNIC_POWER
oUF.colors.power[7] = oUF.colors.power.SOUL_SHARDS
oUF.colors.power[8] = oUF.colors.power.LUNAR_POWER
oUF.colors.power[9] = oUF.colors.power.HOLY_POWER
oUF.colors.power[11] = oUF.colors.power.MAELSTROM
oUF.colors.power[12] = oUF.colors.power.CHI
oUF.colors.power[13] = oUF.colors.power.INSANITY
oUF.colors.power[16] = oUF.colors.power.ARCANE_CHARGES
oUF.colors.power[17] = oUF.colors.power.FURY
oUF.colors.power[18] = oUF.colors.power.PAIN
local GetDisplayPower = function(unit)
if not unit then return; end
local _, min, _, _, _, _, showOnRaid = UnitAlternatePowerInfo(unit)
if(showOnRaid) then
return ALTERNATE_POWER_INDEX, min
end
end
local Update = function(self, event, unit)
if(self.unit ~= unit) or not unit then return end
local power = self.Power
if(power.PreUpdate) then power:PreUpdate(unit) end
local displayType, min
if power.displayAltPower then
displayType, min = GetDisplayPower(unit)
end
local cur, max = UnitPower(unit, displayType), UnitPowerMax(unit, displayType)
local disconnected = not UnitIsConnected(unit)
local tapped = not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)
if max == 0 then
max = 1
end
power:SetMinMaxValues(min or 0, max)
if(disconnected) then
power:SetValue(max)
else
power:SetValue(cur)
end
power.disconnected = disconnected
power.tapped = tapped
if power.frequentUpdates ~= power.__frequentUpdates then
power.__frequentUpdates = power.frequentUpdates
updateFrequentUpdates(self)
end
local ptype, ptoken, altR, altG, altB = UnitPowerType(unit)
local r, g, b, t
if(power.colorTapping and not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)) then
t = self.colors.tapped
elseif(power.colorDisconnected and disconnected) then
t = self.colors.disconnected
elseif(displayType == ALTERNATE_POWER_INDEX and power.altPowerColor) then
t = power.altPowerColor
elseif(power.colorPower) then
t = self.colors.power[ptoken]
if(not t) then
if(power.GetAlternativeColor) then
r, g, b = power:GetAlternativeColor(unit, ptype, ptoken, altR, altG, altB)
elseif(altR) then
-- As of 7.0.3, altR, altG, altB may be in 0-1 or 0-255 range.
if(altR > 1) or (altG > 1) or (altB > 1) then
r, g, b = altR / 255, altG / 255, altB / 255
else
r, g, b = altR, altG, altB
end
else
t = self.colors.power[ptype]
end
end
elseif(power.colorClass and UnitIsPlayer(unit)) or
(power.colorClassNPC and not UnitIsPlayer(unit)) or
(power.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
local _, class = UnitClass(unit)
t = self.colors.class[class]
elseif(power.colorReaction and UnitReaction(unit, 'player')) then
t = self.colors.reaction[UnitReaction(unit, "player")]
elseif(power.colorSmooth) then
local adjust = 0 - (min or 0)
r, g, b = self.ColorGradient(cur + adjust, max + adjust, unpack(power.smoothGradient or self.colors.smooth))
end
if(t) then
r, g, b = t[1], t[2], t[3]
end
t = self.colors.power[ptoken or ptype]
local atlas = power.atlas or (t and t.atlas)
if(power.useAtlas and atlas and displayType ~= ALTERNATE_POWER_INDEX) then
power:SetStatusBarAtlas(atlas)
power:SetStatusBarColor(1, 1, 1)
if(power.colorTapping or power.colorDisconnected) then
t = disconnected and self.colors.disconnected or self.colors.tapped
power:GetStatusBarTexture():SetDesaturated(disconnected or tapped)
end
if(t and b) then
r, g, b = t[1], t[2], t[3]
end
else
power:SetStatusBarTexture(power.texture)
if(b) then
power:SetStatusBarColor(r, g, b)
end
end
local bg = power.bg
if(bg and b) then
local mu = bg.multiplier or 1
bg:SetVertexColor(r * mu, g * mu, b * mu)
end
if(power.PostUpdate) then
return power:PostUpdate(unit, cur, max, min, ptoken, ptype)
end
end
local Path = function(self, ...)
return (self.Power.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
function updateFrequentUpdates(self)
local power = self.Power
if power.frequentUpdates and not self:IsEventRegistered('UNIT_POWER_FREQUENT') then
self:RegisterEvent('UNIT_POWER_FREQUENT', Path)
if self:IsEventRegistered('UNIT_POWER') then
self:UnregisterEvent('UNIT_POWER', Path)
end
elseif not self:IsEventRegistered('UNIT_POWER') then
self:RegisterEvent('UNIT_POWER', Path)
if self:IsEventRegistered('UNIT_POWER_FREQUENT') then
self:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
end
end
end
local Enable = function(self, unit)
local power = self.Power
if(power) then
power.__owner = self
power.ForceUpdate = ForceUpdate
power.__frequentUpdates = power.frequentUpdates
updateFrequentUpdates(self)
self:RegisterEvent('UNIT_POWER_BAR_SHOW', Path)
self:RegisterEvent('UNIT_POWER_BAR_HIDE', Path)
self:RegisterEvent('UNIT_DISPLAYPOWER', Path)
self:RegisterEvent('UNIT_CONNECTION', Path)
self:RegisterEvent('UNIT_MAXPOWER', Path)
-- For tapping.
self:RegisterEvent('UNIT_FACTION', Path)
if(power:IsObjectType'StatusBar') then
power.texture = power:GetStatusBarTexture() and power:GetStatusBarTexture():GetTexture() or [[Interface\TargetingFrame\UI-StatusBar]]
power:SetStatusBarTexture(power.texture)
end
return true
end
end
local Disable = function(self)
local power = self.Power
if(power) then
self:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
self:UnregisterEvent('UNIT_POWER', Path)
self:UnregisterEvent('UNIT_POWER_BAR_SHOW', Path)
self:UnregisterEvent('UNIT_POWER_BAR_HIDE', Path)
self:UnregisterEvent('UNIT_DISPLAYPOWER', Path)
self:UnregisterEvent('UNIT_CONNECTION', Path)
self:UnregisterEvent('UNIT_MAXPOWER', Path)
self:UnregisterEvent('UNIT_FACTION', Path)
end
end
oUF:AddElement('Power', Path, Enable, Disable)

View File

@ -0,0 +1,169 @@
--[[ Element: Power Prediction Bar
Handles updating and visibility of the power prediction status bars.
Widget
PowerPrediction - A table containing `mainBar` and `altBar`.
Sub-Widgets
mainBar - A StatusBar used to represent power cost of spells, that consume
your main power, e.g. mana for mages;
altBar - A StatusBar used to represent power cost of spells, that consume
your additional power, e.g. mana for balance druids.
Notes
The default StatusBar texture will be applied if the UI widget doesn't have a
status bar texture.
Examples
-- Position and size
local mainBar = CreateFrame('StatusBar', nil, self.Power)
mainBar:SetReverseFill(true)
mainBar:SetPoint('TOP')
mainBar:SetPoint('BOTTOM')
mainBar:SetPoint('RIGHT', self.Power:GetStatusBarTexture(), 'RIGHT')
mainBar:SetWidth(200)
local altBar = CreateFrame('StatusBar', nil, self.AdditionalPower)
altBar:SetReverseFill(true)
altBar:SetPoint('TOP')
altBar:SetPoint('BOTTOM')
altBar:SetPoint('RIGHT', self.AdditionalPower:GetStatusBarTexture(), 'RIGHT')
altBar:SetWidth(200)
-- Register with oUF
self.PowerPrediction = {
mainBar = mainBar,
altBar = altBar
}
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local _, ns = ...
local oUF = ns.oUF
local playerClass = select(2, UnitClass('player'))
local function Update(self, event, unit)
if(self.unit ~= unit) then return end
local pp = self.PowerPrediction
if(pp.PreUpdate) then
pp:PreUpdate(unit)
end
local _, _, _, _, startTime, endTime, _, _, _, spellID = UnitCastingInfo(unit)
local mainPowerType = UnitPowerType(unit)
local hasAltManaBar = ALT_MANA_BAR_PAIR_DISPLAY_INFO[playerClass] and ALT_MANA_BAR_PAIR_DISPLAY_INFO[playerClass][mainPowerType]
local mainCost, altCost = 0, 0
if(event == 'UNIT_SPELLCAST_START' or startTime ~= endTime) then
local costTable = GetSpellPowerCost(spellID)
for _, costInfo in pairs(costTable) do
--[[costInfo content:
-- name: string (powerToken)
-- type: number (powerType)
-- cost: number
-- costPercent: number
-- costPerSec: number
-- minCost: number
-- hasRequiredAura: boolean
-- requiredAuraID: number
]]
if(costInfo.type == mainPowerType) then
mainCost = costInfo.cost
break
elseif(costInfo.type == ADDITIONAL_POWER_BAR_INDEX) then
altCost = costInfo.cost
break
end
end
end
if(pp.mainBar) then
pp.mainBar:SetMinMaxValues(0, UnitPowerMax(unit, mainPowerType))
pp.mainBar:SetValue(mainCost)
pp.mainBar:Show()
end
if(pp.altBar and hasAltManaBar) then
pp.altBar:SetMinMaxValues(0, UnitPowerMax(unit, ADDITIONAL_POWER_BAR_INDEX))
pp.altBar:SetValue(altCost)
pp.altBar:Show()
end
if(pp.PostUpdate) then
return pp:PostUpdate(unit, mainCost, altCost, hasAltManaBar)
end
end
local function Path(self, ...)
return (self.PowerPrediction.Override or Update) (self, ...)
end
local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local function Enable(self)
local pp = self.PowerPrediction
if(pp) then
pp.__owner = self
pp.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_SPELLCAST_START', Path)
self:RegisterEvent('UNIT_SPELLCAST_STOP', Path)
self:RegisterEvent('UNIT_SPELLCAST_FAILED', Path)
self:RegisterEvent('UNIT_SPELLCAST_SUCCEEDED', Path)
self:RegisterEvent('UNIT_DISPLAYPOWER', Path)
if(pp.mainBar) then
if(pp.mainBar:IsObjectType('StatusBar') and not pp.mainBar:GetStatusBarTexture()) then
pp.mainBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end
end
if(pp.altBar) then
if(pp.altBar:IsObjectType('StatusBar') and not pp.altBar:GetStatusBarTexture()) then
pp.altBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end
end
return true
end
end
local function Disable(self)
local pp = self.PowerPrediction
if(pp) then
if(pp.mainBar) then
pp.mainBar:Hide()
end
if(pp.altBar) then
pp.altBar:Hide()
end
self:UnregisterEvent('UNIT_SPELLCAST_START', Path)
self:UnregisterEvent('UNIT_SPELLCAST_STOP', Path)
self:UnregisterEvent('UNIT_SPELLCAST_FAILED', Path)
self:UnregisterEvent('UNIT_SPELLCAST_SUCCEEDED', Path)
self:UnregisterEvent('UNIT_DISPLAYPOWER', Path)
end
end
oUF:AddElement('PowerPrediction', Path, Enable, Disable)

View File

@ -0,0 +1,160 @@
--[[ Element: PvP and Prestige Icons
Handles updating and visibility of PvP and prestige icons based on unit's PvP
status and prestige level.
Widget
PvP - A Texture used to display faction, FFA PvP status or prestige icon.
Sub-Widgets
Prestige - A Texture used to display prestige background image.
Notes
This element updates by changing the texture;
`Prestige` texture has to be on a lower sub-layer than `PvP` texture.
Examples
-- Position and size
local PvP = self:CreateTexture(nil, 'ARTWORK', nil, 1)
PvP:SetSize(30, 30)
PvP:SetPoint('RIGHT', self, 'LEFT')
local Prestige = self:CreateTexture(nil, 'ARTWORK')
Prestige:SetSize(50, 52)
Prestige:SetPoint('CENTER', PvP, 'CENTER')
-- Register it with oUF
self.PvP = PvP
self.PvP.Prestige = Prestige
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local parent, ns = ...
local oUF = ns.oUF
local function Update(self, event, unit)
if(unit ~= self.unit) then return end
local pvp = self.PvP
if(pvp.PreUpdate) then
pvp:PreUpdate(unit)
end
local status
local hasPrestige
local level = UnitPrestige(unit)
local factionGroup = UnitFactionGroup(unit)
if(UnitIsPVPFreeForAll(unit)) then
if(level > 0 and pvp.Prestige) then
pvp:SetTexture(GetPrestigeInfo(level))
pvp:SetTexCoord(0, 1, 0, 1)
pvp.Prestige:SetAtlas('honorsystem-portrait-neutral', false)
hasPrestige = true
else
pvp:SetTexture('Interface\\TargetingFrame\\UI-PVP-FFA')
pvp:SetTexCoord(0, 0.65625, 0, 0.65625)
end
status = 'ffa'
elseif(factionGroup and factionGroup ~= 'Neutral' and UnitIsPVP(unit)) then
if(UnitIsMercenary(unit)) then
if(factionGroup == 'Horde') then
factionGroup = 'Alliance'
elseif(factionGroup == 'Alliance') then
factionGroup = 'Horde'
end
end
if(level > 0 and pvp.Prestige) then
pvp:SetTexture(GetPrestigeInfo(level))
pvp:SetTexCoord(0, 1, 0, 1)
pvp.Prestige:SetAtlas('honorsystem-portrait-'..factionGroup, false)
hasPrestige = true
else
pvp:SetTexture('Interface\\TargetingFrame\\UI-PVP-'..factionGroup)
pvp:SetTexCoord(0, 0.65625, 0, 0.65625)
end
status = factionGroup
end
if(status) then
pvp:Show()
if(pvp.Prestige) then
if(hasPrestige) then
pvp.Prestige:Show()
else
pvp.Prestige:Hide()
end
end
else
pvp:Hide()
if(pvp.Prestige) then
pvp.Prestige:Hide()
end
end
if(pvp.PostUpdate) then
return pvp:PostUpdate(unit, status, hasPrestige, level)
end
end
local function Path(self, ...)
return (self.PvP.Override or Update) (self, ...)
end
local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local function Enable(self)
local pvp = self.PvP
if(pvp) then
pvp.__owner = self
pvp.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_FACTION', Path)
if(pvp.Prestige) then
self:RegisterEvent('HONOR_PRESTIGE_UPDATE', Path)
end
return true
end
end
local function Disable(self)
local pvp = self.PvP
if(pvp) then
pvp:Hide()
self:UnregisterEvent('UNIT_FACTION', Path)
if(pvp.Prestige) then
pvp.Prestige:Hide()
self:UnregisterEvent('HONOR_PRESTIGE_UPDATE', Path)
end
end
end
oUF:AddElement('PvP', Path, Enable, Disable)

View File

@ -0,0 +1,86 @@
--[[ Element: Quest Icon
Handles updating and toggles visibility based upon the units connection to a
quest.
Widget
QuestIcon - Any UI widget.
Notes
The default quest icon will be used if the UI widget is a texture and doesn't
have a texture or color defined.
Examples
-- Position and size
local QuestIcon = self:CreateTexture(nil, 'OVERLAY')
QuestIcon:SetSize(16, 16)
QuestIcon:SetPoint('TOPRIGHT', self)
-- Register it with oUF
self.QuestIcon = QuestIcon
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local parent, ns = ...
local oUF = ns.oUF
local Update = function(self, event, unit)
if(unit ~= self.unit) then return end
local qicon = self.QuestIcon
if(qicon.PreUpdate) then
qicon:PreUpdate()
end
local isQuestBoss = UnitIsQuestBoss(unit)
if(isQuestBoss) then
qicon:Show()
else
qicon:Hide()
end
if(qicon.PostUpdate) then
return qicon:PostUpdate(isQuestBoss)
end
end
local Path = function(self, ...)
return (self.QuestIcon.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local Enable = function(self)
local qicon = self.QuestIcon
if(qicon) then
qicon.__owner = self
qicon.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_CLASSIFICATION_CHANGED', Path)
if(qicon:IsObjectType'Texture' and not qicon:GetTexture()) then
qicon:SetTexture[[Interface\TargetingFrame\PortraitQuestBadge]]
end
return true
end
end
local Disable = function(self)
if(self.QuestIcon) then
self.QuestIcon:Hide()
self:UnregisterEvent('UNIT_CLASSIFICATION_CHANGED', Path)
end
end
oUF:AddElement('QuestIcon', Path, Enable, Disable)

View File

@ -0,0 +1,89 @@
--[[ Element: Raid Role Icon
Handles visibility and updating of `self.RaidRole` based upon the units
party assignment.
Widget
RaidRole - A Texture representing the units party assignment. This is can be
main tank, main assist or blank.
Notes
This element updates by changing the texture.
Examples
-- Position and size
local RaidRole = self:CreateTexture(nil, 'OVERLAY')
RaidRole:SetSize(16, 16)
RaidRole:SetPoint('TOPLEFT')
-- Register it with oUF
self.RaidRole = RaidRole
Hooks
Override(self) - Used to completely override the internal update function.
Removing the table key entry will make the element fall-back
to its internal function again.
]]
local parent, ns = ...
local oUF = ns.oUF
local Update = function(self, event)
local unit = self.unit
if(not UnitInRaid(unit)) then return end
local raidrole = self.RaidRole
if(raidrole.PreUpdate) then
raidrole:PreUpdate()
end
local inVehicle = UnitHasVehicleUI(unit)
if(GetPartyAssignment('MAINTANK', unit) and not inVehicle) then
raidrole:Show()
raidrole:SetTexture[[Interface\GROUPFRAME\UI-GROUP-MAINTANKICON]]
elseif(GetPartyAssignment('MAINASSIST', unit) and not inVehicle) then
raidrole:Show()
raidrole:SetTexture[[Interface\GROUPFRAME\UI-GROUP-MAINASSISTICON]]
else
raidrole:Hide()
end
if(raidrole.PostUpdate) then
return raidrole:PostUpdate(rinfo)
end
end
local Path = function(self, ...)
return (self.RaidRole.Override or Update)(self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate')
end
local Enable = function(self)
local raidrole = self.RaidRole
if(raidrole) then
raidrole.__owner = self
raidrole.ForceUpdate = ForceUpdate
self:RegisterEvent('GROUP_ROSTER_UPDATE', Path, true)
return true
end
end
local Disable = function(self)
local raidrole = self.RaidRole
if(raidrole) then
self:UnregisterEvent('GROUP_ROSTER_UPDATE', Path)
end
end
oUF:AddElement('RaidRole', Path, Enable, Disable)

View File

@ -0,0 +1,250 @@
local parent, ns = ...
local oUF = ns.oUF
local _FRAMES = {}
local OnRangeFrame
local UnitIsConnected = UnitIsConnected
local tinsert, tremove, twipe = table.insert, table.remove, table.wipe
local friendlySpells, resSpells, longEnemySpells, enemySpells, petSpells = {}, {}, {}, {}, {}
local addSpellRetry = {}
local SpellRange = LibStub("SpellRange-1.0")
local function AddSpell(table, spellID)
table[#table + 1] = spellID
end
local _,class = UnitClass("player")
do
if class == "PRIEST" then
AddSpell(enemySpells, 585) -- Smite (40 yards)
AddSpell(enemySpells, 589) -- Shadow Word: Pain (40 yards)
AddSpell(friendlySpells, 2061) -- Flash Heal (40 yards)
AddSpell(friendlySpells, 17) -- Power Word: Shield (40 yards)
AddSpell(resSpells, 2006) -- Resurrection (40 yards)
elseif class == "DRUID" then
AddSpell(enemySpells, 8921) -- Moonfire (40 yards, all specs, lvl 3)
AddSpell(friendlySpells, 8936) -- Regrowth (40 yards, all specs, lvl 5)
AddSpell(resSpells, 50769) -- Revive (40 yards, all specs, lvl 14)
elseif class == "PALADIN" then
AddSpell(enemySpells, 20271) -- Judgement (30 yards)
AddSpell(longEnemySpells, 20473) -- Holy Shock (40 yards)
AddSpell(friendlySpells, 19750) -- Flash of Light (40 yards)
AddSpell(resSpells, 7328) -- Redemption (40 yards)
elseif class == "SHAMAN" then
AddSpell(enemySpells, 188196) -- Lightning Bolt (Elemental) (40 yards)
AddSpell(enemySpells, 187837) -- Lightning Bolt (Enhancement) (40 yards)
AddSpell(enemySpells, 403) -- Lightning Bolt (Resto) (40 yards)
AddSpell(friendlySpells, 8004) -- Healing Surge (Resto/Elemental) (40 yards)
AddSpell(friendlySpells, 188070) -- Healing Surge (Enhancement) (40 yards)
AddSpell(resSpells, 2008) -- Ancestral Spirit (40 yards)
elseif class == "WARLOCK" then
AddSpell(enemySpells, 5782) -- Fear (30 yards)
AddSpell(longEnemySpells, 234153) -- Drain Life (40 yards)
AddSpell(longEnemySpells, 198590) --Drain Soul (40 yards)
AddSpell(longEnemySpells, 232670) --Shadow Bolt (40 yards, lvl 1 spell)
AddSpell(petSpells, 755) -- Health Funnel (45 yards)
AddSpell(friendlySpells, 20707) -- Soulstone (40 yards)
elseif class == "MAGE" then
AddSpell(enemySpells, 118) -- Polymorph (30 yards)
AddSpell(longEnemySpells, 116) -- Frostbolt (Frost) (40 yards)
AddSpell(longEnemySpells, 44425) -- Arcane Barrage (Arcane) (40 yards)
AddSpell(longEnemySpells, 133) -- Fireball (Fire) (40 yards)
AddSpell(friendlySpells, 130) -- Slow Fall (40 yards)
elseif class == "HUNTER" then
AddSpell(petSpells, 982) -- Mend Pet (45 yards)
AddSpell(enemySpells, 75) -- Auto Shot (40 yards)
elseif class == "DEATHKNIGHT" then
AddSpell(enemySpells, 49576) -- Death Grip
AddSpell(longEnemySpells, 47541) -- Death Coil (Unholy) (40 yards)
AddSpell(resSpells, 61999) -- Raise Ally (40 yards)
elseif class == "ROGUE" then
AddSpell(enemySpells, 185565) -- Poisoned Knife (Assassination) (30 yards)
AddSpell(enemySpells, 185763) -- Pistol Shot (Outlaw) (20 yards)
AddSpell(enemySpells, 114014) -- Shuriken Toss (Sublety) (30 yards)
AddSpell(enemySpells, 1725) -- Distract (30 yards)
AddSpell(friendlySpells, 57934) -- Tricks of the Trade (100 yards)
elseif class == "WARRIOR" then
AddSpell(enemySpells, 5246) -- Intimidating Shout (Arms/Fury) (8 yards)
AddSpell(enemySpells, 100) -- Charge (Arms/Fury) (8-25 yards)
AddSpell(longEnemySpells, 355) -- Taunt (30 yards)
elseif class == "MONK" then
AddSpell(enemySpells, 115546) -- Provoke (30 yards)
AddSpell(longEnemySpells, 117952) -- Crackling Jade Lightning (40 yards)
AddSpell(friendlySpells, 116694) -- Effuse (40 yards)
AddSpell(resSpells, 115178) -- Resuscitate (40 yards)
elseif class == "DEMONHUNTER" then
AddSpell(enemySpells, 183752) -- Consume Magic (20 yards)
AddSpell(longEnemySpells, 185123) -- Throw Glaive (Havoc) (30 yards)
AddSpell(longEnemySpells, 204021) -- Fiery Brand (Vengeance) (30 yards)
end
end
local function getUnit(unit)
if not unit:find("party") or not unit:find("raid") then
for i=1, 4 do
if UnitIsUnit(unit, "party"..i) then
return "party"..i
end
end
for i=1, 40 do
if UnitIsUnit(unit, "raid"..i) then
return "raid"..i
end
end
else
return unit
end
end
local function friendlyIsInRange(unit)
if CheckInteractDistance(unit, 1) and UnitInPhase(unit) then --Inspect (28 yards) and same phase as you
return true
end
if UnitIsDeadOrGhost(unit) and #resSpells > 0 then
for _, spellID in ipairs(resSpells) do
if SpellRange.IsSpellInRange(spellID, unit) == 1 then
return true
end
end
return false
end
if #friendlySpells == 0 and (UnitInRaid(unit) or UnitInParty(unit)) then
unit = getUnit(unit)
return unit and UnitInRange(unit)
else
for _, spellID in ipairs(friendlySpells) do
if SpellRange.IsSpellInRange(spellID, unit) == 1 then
return true
end
end
end
return false
end
local function petIsInRange(unit)
if CheckInteractDistance(unit, 2) then
return true
end
for _, spellID in ipairs(friendlySpells) do
if SpellRange.IsSpellInRange(spellID, unit) == 1 then
return true
end
end
for _, spellID in ipairs(petSpells) do
if SpellRange.IsSpellInRange(spellID, unit) == 1 then
return true
end
end
return false
end
local function enemyIsInRange(unit)
if CheckInteractDistance(unit, 2) then
return true
end
for _, spellID in ipairs(enemySpells) do
if SpellRange.IsSpellInRange(spellID, unit) == 1 then
return true
end
end
return false
end
local function enemyIsInLongRange(unit)
for _, spellID in ipairs(longEnemySpells) do
if SpellRange.IsSpellInRange(spellID, unit) == 1 then
return true
end
end
return false
end
-- updating of range.
local timer = 0
local OnRangeUpdate = function(self, elapsed)
timer = timer + elapsed
if(timer >= .20) then
for _, object in next, _FRAMES do
if(object:IsShown()) then
local range = object.Range
local unit = object.unit
if(unit) then
if UnitCanAttack("player", unit) then
if enemyIsInRange(unit) then
object:SetAlpha(range.insideAlpha)
elseif enemyIsInLongRange(unit) then
object:SetAlpha(range.insideAlpha)
else
object:SetAlpha(range.outsideAlpha)
end
elseif UnitIsUnit(unit, "pet") then
if petIsInRange(unit) then
object:SetAlpha(range.insideAlpha)
else
object:SetAlpha(range.outsideAlpha)
end
else
if friendlyIsInRange(unit) and UnitIsConnected(unit) then
object:SetAlpha(range.insideAlpha)
else
object:SetAlpha(range.outsideAlpha)
end
end
else
object:SetAlpha(range.insideAlpha)
end
end
end
timer = 0
end
end
local Enable = function(self)
local range = self.Range
if(range and range.insideAlpha and range.outsideAlpha) then
tinsert(_FRAMES, self)
if(not OnRangeFrame) then
OnRangeFrame = CreateFrame"Frame"
OnRangeFrame:SetScript("OnUpdate", OnRangeUpdate)
end
OnRangeFrame:Show()
return true
end
end
local Disable = function(self)
local range = self.Range
if(range) then
for k, frame in next, _FRAMES do
if(frame == self) then
tremove(_FRAMES, k)
frame:SetAlpha(1)
break
end
end
if(#_FRAMES == 0) then
OnRangeFrame:Hide()
end
end
end
oUF:AddElement('Range', nil, Enable, Disable)

Some files were not shown because too many files have changed in this diff Show More